]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.4.7-201208021520.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.4.7-201208021520.patch
CommitLineData
40c4f134
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b4a898f..781c7ad 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,7 @@ oui.c*
149 page-types
150 parse.c
151 parse.h
152+parse-events*
153 patches*
154 pca200e.bin
155 pca200e_ecd.bin2
156@@ -197,6 +217,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160+pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164@@ -207,6 +228,7 @@ r300_reg_safe.h
165 r420_reg_safe.h
166 r600_reg_safe.h
167 recordmcount
168+regdb.c
169 relocs
170 rlim_names.h
171 rn50_reg_safe.h
172@@ -216,7 +238,9 @@ series
173 setup
174 setup.bin
175 setup.elf
176+size_overflow_hash.h
177 sImage
178+slabinfo
179 sm_tbl*
180 split-include
181 syscalltab.h
182@@ -227,6 +251,7 @@ tftpboot.img
183 timeconst.h
184 times.h*
185 trix_boot.h
186+user_constants.h
187 utsrelease.h*
188 vdso-syms.lds
189 vdso.lds
190@@ -238,13 +263,17 @@ vdso32.lds
191 vdso32.so.dbg
192 vdso64.lds
193 vdso64.so.dbg
194+vdsox32.lds
195+vdsox32-syms.lds
196 version.h*
197 vmImage
198 vmlinux
199 vmlinux-*
200 vmlinux.aout
201 vmlinux.bin.all
202+vmlinux.bin.bz2
203 vmlinux.lds
204+vmlinux.relocs
205 vmlinuz
206 voffset.h
207 vsyscall.lds
208@@ -252,9 +281,11 @@ vsyscall_32.lds
209 wanxlfw.inc
210 uImage
211 unifdef
212+utsrelease.h
213 wakeup.bin
214 wakeup.elf
215 wakeup.lds
216 zImage*
217 zconf.hash.c
218+zconf.lex.c
219 zoffset.h
220diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
221index c1601e5..08557ce 100644
222--- a/Documentation/kernel-parameters.txt
223+++ b/Documentation/kernel-parameters.txt
224@@ -2021,6 +2021,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
225 the specified number of seconds. This is to be used if
226 your oopses keep scrolling off the screen.
227
228+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
229+ virtualization environments that don't cope well with the
230+ expand down segment used by UDEREF on X86-32 or the frequent
231+ page table updates on X86-64.
232+
233+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
234+
235 pcbit= [HW,ISDN]
236
237 pcd. [PARIDE]
238diff --git a/Documentation/sysctl/fs.txt b/Documentation/sysctl/fs.txt
239index 88fd7f5..b318a78 100644
240--- a/Documentation/sysctl/fs.txt
241+++ b/Documentation/sysctl/fs.txt
242@@ -163,16 +163,22 @@ This value can be used to query and set the core dump mode for setuid
243 or otherwise protected/tainted binaries. The modes are
244
245 0 - (default) - traditional behaviour. Any process which has changed
246- privilege levels or is execute only will not be dumped
247+ privilege levels or is execute only will not be dumped.
248 1 - (debug) - all processes dump core when possible. The core dump is
249 owned by the current user and no security is applied. This is
250 intended for system debugging situations only. Ptrace is unchecked.
251+ This is insecure as it allows regular users to examine the memory
252+ contents of privileged processes.
253 2 - (suidsafe) - any binary which normally would not be dumped is dumped
254- readable by root only. This allows the end user to remove
255- such a dump but not access it directly. For security reasons
256- core dumps in this mode will not overwrite one another or
257- other files. This mode is appropriate when administrators are
258- attempting to debug problems in a normal environment.
259+ anyway, but only if the "core_pattern" kernel sysctl is set to
260+ either a pipe handler or a fully qualified path. (For more details
261+ on this limitation, see CVE-2006-2451.) This mode is appropriate
262+ when administrators are attempting to debug problems in a normal
263+ environment, and either have a core dump pipe handler that knows
264+ to treat privileged core dumps with care, or specific directory
265+ defined for catching core dumps. If a core dump happens without
266+ a pipe handler or fully qualifid path, a message will be emitted
267+ to syslog warning about the lack of a correct setting.
268
269 ==============================================================
270
271diff --git a/Makefile b/Makefile
272index e17a98c..e3197fa 100644
273--- a/Makefile
274+++ b/Makefile
275@@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
276
277 HOSTCC = gcc
278 HOSTCXX = g++
279-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
280-HOSTCXXFLAGS = -O2
281+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
282+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
283+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
284
285 # Decide whether to build built-in, modular, or both.
286 # Normally, just do built-in.
287@@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
288 # Rules shared between *config targets and build targets
289
290 # Basic helpers built in scripts/
291-PHONY += scripts_basic
292-scripts_basic:
293+PHONY += scripts_basic gcc-plugins
294+scripts_basic: gcc-plugins
295 $(Q)$(MAKE) $(build)=scripts/basic
296 $(Q)rm -f .tmp_quiet_recordmcount
297
298@@ -564,6 +565,60 @@ else
299 KBUILD_CFLAGS += -O2
300 endif
301
302+ifndef DISABLE_PAX_PLUGINS
303+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
304+ifneq ($(PLUGINCC),)
305+ifndef DISABLE_PAX_CONSTIFY_PLUGIN
306+ifndef CONFIG_UML
307+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
308+endif
309+endif
310+ifdef CONFIG_PAX_MEMORY_STACKLEAK
311+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
312+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
313+endif
314+ifdef CONFIG_KALLOCSTAT_PLUGIN
315+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
316+endif
317+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
318+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
319+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
320+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
321+endif
322+ifdef CONFIG_CHECKER_PLUGIN
323+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
324+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
325+endif
326+endif
327+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
328+ifdef CONFIG_PAX_SIZE_OVERFLOW
329+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
330+endif
331+ifdef CONFIG_PAX_LATENT_ENTROPY
332+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
333+endif
334+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
335+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
336+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
337+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
338+export PLUGINCC CONSTIFY_PLUGIN
339+ifeq ($(KBUILD_EXTMOD),)
340+gcc-plugins:
341+ $(Q)$(MAKE) $(build)=tools/gcc
342+else
343+gcc-plugins: ;
344+endif
345+else
346+gcc-plugins:
347+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
348+ $(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.))
349+else
350+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
351+endif
352+ $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
353+endif
354+endif
355+
356 include $(srctree)/arch/$(SRCARCH)/Makefile
357
358 ifneq ($(CONFIG_FRAME_WARN),0)
359@@ -708,7 +763,7 @@ export mod_strip_cmd
360
361
362 ifeq ($(KBUILD_EXTMOD),)
363-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
364+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
365
366 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
367 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
368@@ -932,6 +987,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
369
370 # The actual objects are generated when descending,
371 # make sure no implicit rule kicks in
372+$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
373+$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
374 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
375
376 # Handle descending into subdirectories listed in $(vmlinux-dirs)
377@@ -941,7 +998,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
378 # Error messages still appears in the original language
379
380 PHONY += $(vmlinux-dirs)
381-$(vmlinux-dirs): prepare scripts
382+$(vmlinux-dirs): gcc-plugins prepare scripts
383 $(Q)$(MAKE) $(build)=$@
384
385 # Store (new) KERNELRELASE string in include/config/kernel.release
386@@ -985,6 +1042,7 @@ prepare0: archprepare FORCE
387 $(Q)$(MAKE) $(build)=.
388
389 # All the preparing..
390+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
391 prepare: prepare0
392
393 # Generate some files
394@@ -1092,6 +1150,8 @@ all: modules
395 # using awk while concatenating to the final file.
396
397 PHONY += modules
398+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
399+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
400 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
401 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
402 @$(kecho) ' Building modules, stage 2.';
403@@ -1107,7 +1167,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
404
405 # Target to prepare building external modules
406 PHONY += modules_prepare
407-modules_prepare: prepare scripts
408+modules_prepare: gcc-plugins prepare scripts
409
410 # Target to install modules
411 PHONY += modules_install
412@@ -1166,7 +1226,7 @@ CLEAN_FILES += vmlinux System.map \
413 MRPROPER_DIRS += include/config usr/include include/generated \
414 arch/*/include/generated
415 MRPROPER_FILES += .config .config.old .version .old_version \
416- include/linux/version.h \
417+ include/linux/version.h tools/gcc/size_overflow_hash.h\
418 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
419
420 # clean - Delete most, but leave enough to build external modules
421@@ -1204,6 +1264,7 @@ distclean: mrproper
422 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
423 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
424 -o -name '.*.rej' \
425+ -o -name '.*.rej' -o -name '*.so' \
426 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
427 -type f -print | xargs rm -f
428
429@@ -1364,6 +1425,8 @@ PHONY += $(module-dirs) modules
430 $(module-dirs): crmodverdir $(objtree)/Module.symvers
431 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
432
433+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
434+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
435 modules: $(module-dirs)
436 @$(kecho) ' Building modules, stage 2.';
437 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
438@@ -1490,17 +1553,21 @@ else
439 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
440 endif
441
442-%.s: %.c prepare scripts FORCE
443+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
444+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
445+%.s: %.c gcc-plugins prepare scripts FORCE
446 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
447 %.i: %.c prepare scripts FORCE
448 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
449-%.o: %.c prepare scripts FORCE
450+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
451+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
452+%.o: %.c gcc-plugins prepare scripts FORCE
453 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
454 %.lst: %.c prepare scripts FORCE
455 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
456-%.s: %.S prepare scripts FORCE
457+%.s: %.S gcc-plugins prepare scripts FORCE
458 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
459-%.o: %.S prepare scripts FORCE
460+%.o: %.S gcc-plugins prepare scripts FORCE
461 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
462 %.symtypes: %.c prepare scripts FORCE
463 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
464@@ -1510,11 +1577,15 @@ endif
465 $(cmd_crmodverdir)
466 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
467 $(build)=$(build-dir)
468-%/: prepare scripts FORCE
469+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
470+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
471+%/: gcc-plugins prepare scripts FORCE
472 $(cmd_crmodverdir)
473 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
474 $(build)=$(build-dir)
475-%.ko: prepare scripts FORCE
476+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
477+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
478+%.ko: gcc-plugins prepare scripts FORCE
479 $(cmd_crmodverdir)
480 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
481 $(build)=$(build-dir) $(@:.ko=.o)
482diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
483index 3bb7ffe..347a54c 100644
484--- a/arch/alpha/include/asm/atomic.h
485+++ b/arch/alpha/include/asm/atomic.h
486@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
487 #define atomic_dec(v) atomic_sub(1,(v))
488 #define atomic64_dec(v) atomic64_sub(1,(v))
489
490+#define atomic64_read_unchecked(v) atomic64_read(v)
491+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
492+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
493+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
494+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
495+#define atomic64_inc_unchecked(v) atomic64_inc(v)
496+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
497+#define atomic64_dec_unchecked(v) atomic64_dec(v)
498+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
499+
500 #define smp_mb__before_atomic_dec() smp_mb()
501 #define smp_mb__after_atomic_dec() smp_mb()
502 #define smp_mb__before_atomic_inc() smp_mb()
503diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
504index ad368a9..fbe0f25 100644
505--- a/arch/alpha/include/asm/cache.h
506+++ b/arch/alpha/include/asm/cache.h
507@@ -4,19 +4,19 @@
508 #ifndef __ARCH_ALPHA_CACHE_H
509 #define __ARCH_ALPHA_CACHE_H
510
511+#include <linux/const.h>
512
513 /* Bytes per L1 (data) cache line. */
514 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
515-# define L1_CACHE_BYTES 64
516 # define L1_CACHE_SHIFT 6
517 #else
518 /* Both EV4 and EV5 are write-through, read-allocate,
519 direct-mapped, physical.
520 */
521-# define L1_CACHE_BYTES 32
522 # define L1_CACHE_SHIFT 5
523 #endif
524
525+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
526 #define SMP_CACHE_BYTES L1_CACHE_BYTES
527
528 #endif
529diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
530index 968d999..d36b2df 100644
531--- a/arch/alpha/include/asm/elf.h
532+++ b/arch/alpha/include/asm/elf.h
533@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
534
535 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
536
537+#ifdef CONFIG_PAX_ASLR
538+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
539+
540+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
541+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
542+#endif
543+
544 /* $0 is set by ld.so to a pointer to a function which might be
545 registered using atexit. This provides a mean for the dynamic
546 linker to call DT_FINI functions for shared libraries that have
547diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
548index bc2a0da..8ad11ee 100644
549--- a/arch/alpha/include/asm/pgalloc.h
550+++ b/arch/alpha/include/asm/pgalloc.h
551@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
552 pgd_set(pgd, pmd);
553 }
554
555+static inline void
556+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
557+{
558+ pgd_populate(mm, pgd, pmd);
559+}
560+
561 extern pgd_t *pgd_alloc(struct mm_struct *mm);
562
563 static inline void
564diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
565index 81a4342..348b927 100644
566--- a/arch/alpha/include/asm/pgtable.h
567+++ b/arch/alpha/include/asm/pgtable.h
568@@ -102,6 +102,17 @@ struct vm_area_struct;
569 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
570 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
571 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
572+
573+#ifdef CONFIG_PAX_PAGEEXEC
574+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
575+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
576+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
577+#else
578+# define PAGE_SHARED_NOEXEC PAGE_SHARED
579+# define PAGE_COPY_NOEXEC PAGE_COPY
580+# define PAGE_READONLY_NOEXEC PAGE_READONLY
581+#endif
582+
583 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
584
585 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
586diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
587index 2fd00b7..cfd5069 100644
588--- a/arch/alpha/kernel/module.c
589+++ b/arch/alpha/kernel/module.c
590@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
591
592 /* The small sections were sorted to the end of the segment.
593 The following should definitely cover them. */
594- gp = (u64)me->module_core + me->core_size - 0x8000;
595+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
596 got = sechdrs[me->arch.gotsecindex].sh_addr;
597
598 for (i = 0; i < n; i++) {
599diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
600index 49ee319..9ee7d14 100644
601--- a/arch/alpha/kernel/osf_sys.c
602+++ b/arch/alpha/kernel/osf_sys.c
603@@ -1146,7 +1146,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
604 /* At this point: (!vma || addr < vma->vm_end). */
605 if (limit - len < addr)
606 return -ENOMEM;
607- if (!vma || addr + len <= vma->vm_start)
608+ if (check_heap_stack_gap(vma, addr, len))
609 return addr;
610 addr = vma->vm_end;
611 vma = vma->vm_next;
612@@ -1182,6 +1182,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
613 merely specific addresses, but regions of memory -- perhaps
614 this feature should be incorporated into all ports? */
615
616+#ifdef CONFIG_PAX_RANDMMAP
617+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
618+#endif
619+
620 if (addr) {
621 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
622 if (addr != (unsigned long) -ENOMEM)
623@@ -1189,8 +1193,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
624 }
625
626 /* Next, try allocating at TASK_UNMAPPED_BASE. */
627- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
628- len, limit);
629+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
630+
631 if (addr != (unsigned long) -ENOMEM)
632 return addr;
633
634diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
635index 5eecab1..609abc0 100644
636--- a/arch/alpha/mm/fault.c
637+++ b/arch/alpha/mm/fault.c
638@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
639 __reload_thread(pcb);
640 }
641
642+#ifdef CONFIG_PAX_PAGEEXEC
643+/*
644+ * PaX: decide what to do with offenders (regs->pc = fault address)
645+ *
646+ * returns 1 when task should be killed
647+ * 2 when patched PLT trampoline was detected
648+ * 3 when unpatched PLT trampoline was detected
649+ */
650+static int pax_handle_fetch_fault(struct pt_regs *regs)
651+{
652+
653+#ifdef CONFIG_PAX_EMUPLT
654+ int err;
655+
656+ do { /* PaX: patched PLT emulation #1 */
657+ unsigned int ldah, ldq, jmp;
658+
659+ err = get_user(ldah, (unsigned int *)regs->pc);
660+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
661+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
662+
663+ if (err)
664+ break;
665+
666+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
667+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
668+ jmp == 0x6BFB0000U)
669+ {
670+ unsigned long r27, addr;
671+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
672+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
673+
674+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
675+ err = get_user(r27, (unsigned long *)addr);
676+ if (err)
677+ break;
678+
679+ regs->r27 = r27;
680+ regs->pc = r27;
681+ return 2;
682+ }
683+ } while (0);
684+
685+ do { /* PaX: patched PLT emulation #2 */
686+ unsigned int ldah, lda, br;
687+
688+ err = get_user(ldah, (unsigned int *)regs->pc);
689+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
690+ err |= get_user(br, (unsigned int *)(regs->pc+8));
691+
692+ if (err)
693+ break;
694+
695+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
696+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
697+ (br & 0xFFE00000U) == 0xC3E00000U)
698+ {
699+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
700+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
701+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
702+
703+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
704+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
705+ return 2;
706+ }
707+ } while (0);
708+
709+ do { /* PaX: unpatched PLT emulation */
710+ unsigned int br;
711+
712+ err = get_user(br, (unsigned int *)regs->pc);
713+
714+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
715+ unsigned int br2, ldq, nop, jmp;
716+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
717+
718+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
719+ err = get_user(br2, (unsigned int *)addr);
720+ err |= get_user(ldq, (unsigned int *)(addr+4));
721+ err |= get_user(nop, (unsigned int *)(addr+8));
722+ err |= get_user(jmp, (unsigned int *)(addr+12));
723+ err |= get_user(resolver, (unsigned long *)(addr+16));
724+
725+ if (err)
726+ break;
727+
728+ if (br2 == 0xC3600000U &&
729+ ldq == 0xA77B000CU &&
730+ nop == 0x47FF041FU &&
731+ jmp == 0x6B7B0000U)
732+ {
733+ regs->r28 = regs->pc+4;
734+ regs->r27 = addr+16;
735+ regs->pc = resolver;
736+ return 3;
737+ }
738+ }
739+ } while (0);
740+#endif
741+
742+ return 1;
743+}
744+
745+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
746+{
747+ unsigned long i;
748+
749+ printk(KERN_ERR "PAX: bytes at PC: ");
750+ for (i = 0; i < 5; i++) {
751+ unsigned int c;
752+ if (get_user(c, (unsigned int *)pc+i))
753+ printk(KERN_CONT "???????? ");
754+ else
755+ printk(KERN_CONT "%08x ", c);
756+ }
757+ printk("\n");
758+}
759+#endif
760
761 /*
762 * This routine handles page faults. It determines the address,
763@@ -130,8 +248,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
764 good_area:
765 si_code = SEGV_ACCERR;
766 if (cause < 0) {
767- if (!(vma->vm_flags & VM_EXEC))
768+ if (!(vma->vm_flags & VM_EXEC)) {
769+
770+#ifdef CONFIG_PAX_PAGEEXEC
771+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
772+ goto bad_area;
773+
774+ up_read(&mm->mmap_sem);
775+ switch (pax_handle_fetch_fault(regs)) {
776+
777+#ifdef CONFIG_PAX_EMUPLT
778+ case 2:
779+ case 3:
780+ return;
781+#endif
782+
783+ }
784+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
785+ do_group_exit(SIGKILL);
786+#else
787 goto bad_area;
788+#endif
789+
790+ }
791 } else if (!cause) {
792 /* Allow reads even for write-only mappings */
793 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
794diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
795index 68374ba..cff7196 100644
796--- a/arch/arm/include/asm/atomic.h
797+++ b/arch/arm/include/asm/atomic.h
798@@ -17,17 +17,35 @@
799 #include <asm/barrier.h>
800 #include <asm/cmpxchg.h>
801
802+#ifdef CONFIG_GENERIC_ATOMIC64
803+#include <asm-generic/atomic64.h>
804+#endif
805+
806 #define ATOMIC_INIT(i) { (i) }
807
808 #ifdef __KERNEL__
809
810+#define _ASM_EXTABLE(from, to) \
811+" .pushsection __ex_table,\"a\"\n"\
812+" .align 3\n" \
813+" .long " #from ", " #to"\n" \
814+" .popsection"
815+
816 /*
817 * On ARM, ordinary assignment (str instruction) doesn't clear the local
818 * strex/ldrex monitor on some implementations. The reason we can use it for
819 * atomic_set() is the clrex or dummy strex done on every exception return.
820 */
821 #define atomic_read(v) (*(volatile int *)&(v)->counter)
822+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
823+{
824+ return v->counter;
825+}
826 #define atomic_set(v,i) (((v)->counter) = (i))
827+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
828+{
829+ v->counter = i;
830+}
831
832 #if __LINUX_ARM_ARCH__ >= 6
833
834@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
835 int result;
836
837 __asm__ __volatile__("@ atomic_add\n"
838+"1: ldrex %1, [%3]\n"
839+" adds %0, %1, %4\n"
840+
841+#ifdef CONFIG_PAX_REFCOUNT
842+" bvc 3f\n"
843+"2: bkpt 0xf103\n"
844+"3:\n"
845+#endif
846+
847+" strex %1, %0, [%3]\n"
848+" teq %1, #0\n"
849+" bne 1b"
850+
851+#ifdef CONFIG_PAX_REFCOUNT
852+"\n4:\n"
853+ _ASM_EXTABLE(2b, 4b)
854+#endif
855+
856+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
857+ : "r" (&v->counter), "Ir" (i)
858+ : "cc");
859+}
860+
861+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
862+{
863+ unsigned long tmp;
864+ int result;
865+
866+ __asm__ __volatile__("@ atomic_add_unchecked\n"
867 "1: ldrex %0, [%3]\n"
868 " add %0, %0, %4\n"
869 " strex %1, %0, [%3]\n"
870@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
871 smp_mb();
872
873 __asm__ __volatile__("@ atomic_add_return\n"
874+"1: ldrex %1, [%3]\n"
875+" adds %0, %1, %4\n"
876+
877+#ifdef CONFIG_PAX_REFCOUNT
878+" bvc 3f\n"
879+" mov %0, %1\n"
880+"2: bkpt 0xf103\n"
881+"3:\n"
882+#endif
883+
884+" strex %1, %0, [%3]\n"
885+" teq %1, #0\n"
886+" bne 1b"
887+
888+#ifdef CONFIG_PAX_REFCOUNT
889+"\n4:\n"
890+ _ASM_EXTABLE(2b, 4b)
891+#endif
892+
893+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
894+ : "r" (&v->counter), "Ir" (i)
895+ : "cc");
896+
897+ smp_mb();
898+
899+ return result;
900+}
901+
902+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
903+{
904+ unsigned long tmp;
905+ int result;
906+
907+ smp_mb();
908+
909+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
910 "1: ldrex %0, [%3]\n"
911 " add %0, %0, %4\n"
912 " strex %1, %0, [%3]\n"
913@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
914 int result;
915
916 __asm__ __volatile__("@ atomic_sub\n"
917+"1: ldrex %1, [%3]\n"
918+" subs %0, %1, %4\n"
919+
920+#ifdef CONFIG_PAX_REFCOUNT
921+" bvc 3f\n"
922+"2: bkpt 0xf103\n"
923+"3:\n"
924+#endif
925+
926+" strex %1, %0, [%3]\n"
927+" teq %1, #0\n"
928+" bne 1b"
929+
930+#ifdef CONFIG_PAX_REFCOUNT
931+"\n4:\n"
932+ _ASM_EXTABLE(2b, 4b)
933+#endif
934+
935+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
936+ : "r" (&v->counter), "Ir" (i)
937+ : "cc");
938+}
939+
940+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
941+{
942+ unsigned long tmp;
943+ int result;
944+
945+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
946 "1: ldrex %0, [%3]\n"
947 " sub %0, %0, %4\n"
948 " strex %1, %0, [%3]\n"
949@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
950 smp_mb();
951
952 __asm__ __volatile__("@ atomic_sub_return\n"
953-"1: ldrex %0, [%3]\n"
954-" sub %0, %0, %4\n"
955+"1: ldrex %1, [%3]\n"
956+" sub %0, %1, %4\n"
957+
958+#ifdef CONFIG_PAX_REFCOUNT
959+" bvc 3f\n"
960+" mov %0, %1\n"
961+"2: bkpt 0xf103\n"
962+"3:\n"
963+#endif
964+
965 " strex %1, %0, [%3]\n"
966 " teq %1, #0\n"
967 " bne 1b"
968+
969+#ifdef CONFIG_PAX_REFCOUNT
970+"\n4:\n"
971+ _ASM_EXTABLE(2b, 4b)
972+#endif
973+
974 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
975 : "r" (&v->counter), "Ir" (i)
976 : "cc");
977@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
978 return oldval;
979 }
980
981+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
982+{
983+ unsigned long oldval, res;
984+
985+ smp_mb();
986+
987+ do {
988+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
989+ "ldrex %1, [%3]\n"
990+ "mov %0, #0\n"
991+ "teq %1, %4\n"
992+ "strexeq %0, %5, [%3]\n"
993+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
994+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
995+ : "cc");
996+ } while (res);
997+
998+ smp_mb();
999+
1000+ return oldval;
1001+}
1002+
1003 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1004 {
1005 unsigned long tmp, tmp2;
1006@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1007
1008 return val;
1009 }
1010+
1011+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1012+{
1013+ return atomic_add_return(i, v);
1014+}
1015+
1016 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1017+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1018+{
1019+ (void) atomic_add_return(i, v);
1020+}
1021
1022 static inline int atomic_sub_return(int i, atomic_t *v)
1023 {
1024@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1025 return val;
1026 }
1027 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1028+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1029+{
1030+ (void) atomic_sub_return(i, v);
1031+}
1032
1033 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1034 {
1035@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1036 return ret;
1037 }
1038
1039+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1040+{
1041+ return atomic_cmpxchg(v, old, new);
1042+}
1043+
1044 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1045 {
1046 unsigned long flags;
1047@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1048 #endif /* __LINUX_ARM_ARCH__ */
1049
1050 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1051+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1052+{
1053+ return xchg(&v->counter, new);
1054+}
1055
1056 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1057 {
1058@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1059 }
1060
1061 #define atomic_inc(v) atomic_add(1, v)
1062+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1063+{
1064+ atomic_add_unchecked(1, v);
1065+}
1066 #define atomic_dec(v) atomic_sub(1, v)
1067+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1068+{
1069+ atomic_sub_unchecked(1, v);
1070+}
1071
1072 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1073+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1074+{
1075+ return atomic_add_return_unchecked(1, v) == 0;
1076+}
1077 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1078 #define atomic_inc_return(v) (atomic_add_return(1, v))
1079+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1080+{
1081+ return atomic_add_return_unchecked(1, v);
1082+}
1083 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1084 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1085
1086@@ -241,6 +428,14 @@ typedef struct {
1087 u64 __aligned(8) counter;
1088 } atomic64_t;
1089
1090+#ifdef CONFIG_PAX_REFCOUNT
1091+typedef struct {
1092+ u64 __aligned(8) counter;
1093+} atomic64_unchecked_t;
1094+#else
1095+typedef atomic64_t atomic64_unchecked_t;
1096+#endif
1097+
1098 #define ATOMIC64_INIT(i) { (i) }
1099
1100 static inline u64 atomic64_read(atomic64_t *v)
1101@@ -256,6 +451,19 @@ static inline u64 atomic64_read(atomic64_t *v)
1102 return result;
1103 }
1104
1105+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1106+{
1107+ u64 result;
1108+
1109+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1110+" ldrexd %0, %H0, [%1]"
1111+ : "=&r" (result)
1112+ : "r" (&v->counter), "Qo" (v->counter)
1113+ );
1114+
1115+ return result;
1116+}
1117+
1118 static inline void atomic64_set(atomic64_t *v, u64 i)
1119 {
1120 u64 tmp;
1121@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1122 : "cc");
1123 }
1124
1125+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1126+{
1127+ u64 tmp;
1128+
1129+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1130+"1: ldrexd %0, %H0, [%2]\n"
1131+" strexd %0, %3, %H3, [%2]\n"
1132+" teq %0, #0\n"
1133+" bne 1b"
1134+ : "=&r" (tmp), "=Qo" (v->counter)
1135+ : "r" (&v->counter), "r" (i)
1136+ : "cc");
1137+}
1138+
1139 static inline void atomic64_add(u64 i, atomic64_t *v)
1140 {
1141 u64 result;
1142@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1143 __asm__ __volatile__("@ atomic64_add\n"
1144 "1: ldrexd %0, %H0, [%3]\n"
1145 " adds %0, %0, %4\n"
1146+" adcs %H0, %H0, %H4\n"
1147+
1148+#ifdef CONFIG_PAX_REFCOUNT
1149+" bvc 3f\n"
1150+"2: bkpt 0xf103\n"
1151+"3:\n"
1152+#endif
1153+
1154+" strexd %1, %0, %H0, [%3]\n"
1155+" teq %1, #0\n"
1156+" bne 1b"
1157+
1158+#ifdef CONFIG_PAX_REFCOUNT
1159+"\n4:\n"
1160+ _ASM_EXTABLE(2b, 4b)
1161+#endif
1162+
1163+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1164+ : "r" (&v->counter), "r" (i)
1165+ : "cc");
1166+}
1167+
1168+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1169+{
1170+ u64 result;
1171+ unsigned long tmp;
1172+
1173+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1174+"1: ldrexd %0, %H0, [%3]\n"
1175+" adds %0, %0, %4\n"
1176 " adc %H0, %H0, %H4\n"
1177 " strexd %1, %0, %H0, [%3]\n"
1178 " teq %1, #0\n"
1179@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1180
1181 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1182 {
1183- u64 result;
1184- unsigned long tmp;
1185+ u64 result, tmp;
1186
1187 smp_mb();
1188
1189 __asm__ __volatile__("@ atomic64_add_return\n"
1190+"1: ldrexd %1, %H1, [%3]\n"
1191+" adds %0, %1, %4\n"
1192+" adcs %H0, %H1, %H4\n"
1193+
1194+#ifdef CONFIG_PAX_REFCOUNT
1195+" bvc 3f\n"
1196+" mov %0, %1\n"
1197+" mov %H0, %H1\n"
1198+"2: bkpt 0xf103\n"
1199+"3:\n"
1200+#endif
1201+
1202+" strexd %1, %0, %H0, [%3]\n"
1203+" teq %1, #0\n"
1204+" bne 1b"
1205+
1206+#ifdef CONFIG_PAX_REFCOUNT
1207+"\n4:\n"
1208+ _ASM_EXTABLE(2b, 4b)
1209+#endif
1210+
1211+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1212+ : "r" (&v->counter), "r" (i)
1213+ : "cc");
1214+
1215+ smp_mb();
1216+
1217+ return result;
1218+}
1219+
1220+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1221+{
1222+ u64 result;
1223+ unsigned long tmp;
1224+
1225+ smp_mb();
1226+
1227+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1228 "1: ldrexd %0, %H0, [%3]\n"
1229 " adds %0, %0, %4\n"
1230 " adc %H0, %H0, %H4\n"
1231@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1232 __asm__ __volatile__("@ atomic64_sub\n"
1233 "1: ldrexd %0, %H0, [%3]\n"
1234 " subs %0, %0, %4\n"
1235+" sbcs %H0, %H0, %H4\n"
1236+
1237+#ifdef CONFIG_PAX_REFCOUNT
1238+" bvc 3f\n"
1239+"2: bkpt 0xf103\n"
1240+"3:\n"
1241+#endif
1242+
1243+" strexd %1, %0, %H0, [%3]\n"
1244+" teq %1, #0\n"
1245+" bne 1b"
1246+
1247+#ifdef CONFIG_PAX_REFCOUNT
1248+"\n4:\n"
1249+ _ASM_EXTABLE(2b, 4b)
1250+#endif
1251+
1252+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1253+ : "r" (&v->counter), "r" (i)
1254+ : "cc");
1255+}
1256+
1257+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1258+{
1259+ u64 result;
1260+ unsigned long tmp;
1261+
1262+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1263+"1: ldrexd %0, %H0, [%3]\n"
1264+" subs %0, %0, %4\n"
1265 " sbc %H0, %H0, %H4\n"
1266 " strexd %1, %0, %H0, [%3]\n"
1267 " teq %1, #0\n"
1268@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1269
1270 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1271 {
1272- u64 result;
1273- unsigned long tmp;
1274+ u64 result, tmp;
1275
1276 smp_mb();
1277
1278 __asm__ __volatile__("@ atomic64_sub_return\n"
1279-"1: ldrexd %0, %H0, [%3]\n"
1280-" subs %0, %0, %4\n"
1281-" sbc %H0, %H0, %H4\n"
1282+"1: ldrexd %1, %H1, [%3]\n"
1283+" subs %0, %1, %4\n"
1284+" sbc %H0, %H1, %H4\n"
1285+
1286+#ifdef CONFIG_PAX_REFCOUNT
1287+" bvc 3f\n"
1288+" mov %0, %1\n"
1289+" mov %H0, %H1\n"
1290+"2: bkpt 0xf103\n"
1291+"3:\n"
1292+#endif
1293+
1294 " strexd %1, %0, %H0, [%3]\n"
1295 " teq %1, #0\n"
1296 " bne 1b"
1297+
1298+#ifdef CONFIG_PAX_REFCOUNT
1299+"\n4:\n"
1300+ _ASM_EXTABLE(2b, 4b)
1301+#endif
1302+
1303 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1304 : "r" (&v->counter), "r" (i)
1305 : "cc");
1306@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1307 return oldval;
1308 }
1309
1310+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1311+{
1312+ u64 oldval;
1313+ unsigned long res;
1314+
1315+ smp_mb();
1316+
1317+ do {
1318+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1319+ "ldrexd %1, %H1, [%3]\n"
1320+ "mov %0, #0\n"
1321+ "teq %1, %4\n"
1322+ "teqeq %H1, %H4\n"
1323+ "strexdeq %0, %5, %H5, [%3]"
1324+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1325+ : "r" (&ptr->counter), "r" (old), "r" (new)
1326+ : "cc");
1327+ } while (res);
1328+
1329+ smp_mb();
1330+
1331+ return oldval;
1332+}
1333+
1334 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1335 {
1336 u64 result;
1337@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1338
1339 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1340 {
1341- u64 result;
1342- unsigned long tmp;
1343+ u64 result, tmp;
1344
1345 smp_mb();
1346
1347 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1348-"1: ldrexd %0, %H0, [%3]\n"
1349-" subs %0, %0, #1\n"
1350-" sbc %H0, %H0, #0\n"
1351+"1: ldrexd %1, %H1, [%3]\n"
1352+" subs %0, %1, #1\n"
1353+" sbc %H0, %H1, #0\n"
1354+
1355+#ifdef CONFIG_PAX_REFCOUNT
1356+" bvc 3f\n"
1357+" mov %0, %1\n"
1358+" mov %H0, %H1\n"
1359+"2: bkpt 0xf103\n"
1360+"3:\n"
1361+#endif
1362+
1363 " teq %H0, #0\n"
1364-" bmi 2f\n"
1365+" bmi 4f\n"
1366 " strexd %1, %0, %H0, [%3]\n"
1367 " teq %1, #0\n"
1368 " bne 1b\n"
1369-"2:"
1370+"4:\n"
1371+
1372+#ifdef CONFIG_PAX_REFCOUNT
1373+ _ASM_EXTABLE(2b, 4b)
1374+#endif
1375+
1376 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1377 : "r" (&v->counter)
1378 : "cc");
1379@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1380 " teq %0, %5\n"
1381 " teqeq %H0, %H5\n"
1382 " moveq %1, #0\n"
1383-" beq 2f\n"
1384+" beq 4f\n"
1385 " adds %0, %0, %6\n"
1386 " adc %H0, %H0, %H6\n"
1387+
1388+#ifdef CONFIG_PAX_REFCOUNT
1389+" bvc 3f\n"
1390+"2: bkpt 0xf103\n"
1391+"3:\n"
1392+#endif
1393+
1394 " strexd %2, %0, %H0, [%4]\n"
1395 " teq %2, #0\n"
1396 " bne 1b\n"
1397-"2:"
1398+"4:\n"
1399+
1400+#ifdef CONFIG_PAX_REFCOUNT
1401+ _ASM_EXTABLE(2b, 4b)
1402+#endif
1403+
1404 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1405 : "r" (&v->counter), "r" (u), "r" (a)
1406 : "cc");
1407@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1408
1409 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1410 #define atomic64_inc(v) atomic64_add(1LL, (v))
1411+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1412 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1413+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1414 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1415 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1416 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1417+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1418 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1419 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1420 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1421diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1422index 75fe66b..2255c86 100644
1423--- a/arch/arm/include/asm/cache.h
1424+++ b/arch/arm/include/asm/cache.h
1425@@ -4,8 +4,10 @@
1426 #ifndef __ASMARM_CACHE_H
1427 #define __ASMARM_CACHE_H
1428
1429+#include <linux/const.h>
1430+
1431 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1432-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1433+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1434
1435 /*
1436 * Memory returned by kmalloc() may be used for DMA, so we must make
1437diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1438index 1252a26..9dc17b5 100644
1439--- a/arch/arm/include/asm/cacheflush.h
1440+++ b/arch/arm/include/asm/cacheflush.h
1441@@ -108,7 +108,7 @@ struct cpu_cache_fns {
1442 void (*dma_unmap_area)(const void *, size_t, int);
1443
1444 void (*dma_flush_range)(const void *, const void *);
1445-};
1446+} __no_const;
1447
1448 /*
1449 * Select the calling method
1450diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1451index d41d7cb..9bea5e0 100644
1452--- a/arch/arm/include/asm/cmpxchg.h
1453+++ b/arch/arm/include/asm/cmpxchg.h
1454@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1455
1456 #define xchg(ptr,x) \
1457 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1458+#define xchg_unchecked(ptr,x) \
1459+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1460
1461 #include <asm-generic/cmpxchg-local.h>
1462
1463diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1464index 38050b1..9d90e8b 100644
1465--- a/arch/arm/include/asm/elf.h
1466+++ b/arch/arm/include/asm/elf.h
1467@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1468 the loader. We need to make sure that it is out of the way of the program
1469 that it will "exec", and that there is sufficient room for the brk. */
1470
1471-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1472+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1473+
1474+#ifdef CONFIG_PAX_ASLR
1475+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1476+
1477+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1478+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1479+#endif
1480
1481 /* When the program starts, a1 contains a pointer to a function to be
1482 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1483@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1484 extern void elf_set_personality(const struct elf32_hdr *);
1485 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1486
1487-struct mm_struct;
1488-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1489-#define arch_randomize_brk arch_randomize_brk
1490-
1491 #endif
1492diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1493index e51b1e8..32a3113 100644
1494--- a/arch/arm/include/asm/kmap_types.h
1495+++ b/arch/arm/include/asm/kmap_types.h
1496@@ -21,6 +21,7 @@ enum km_type {
1497 KM_L1_CACHE,
1498 KM_L2_CACHE,
1499 KM_KDB,
1500+ KM_CLEARPAGE,
1501 KM_TYPE_NR
1502 };
1503
1504diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1505index 53426c6..c7baff3 100644
1506--- a/arch/arm/include/asm/outercache.h
1507+++ b/arch/arm/include/asm/outercache.h
1508@@ -35,7 +35,7 @@ struct outer_cache_fns {
1509 #endif
1510 void (*set_debug)(unsigned long);
1511 void (*resume)(void);
1512-};
1513+} __no_const;
1514
1515 #ifdef CONFIG_OUTER_CACHE
1516
1517diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1518index 5838361..da6e813 100644
1519--- a/arch/arm/include/asm/page.h
1520+++ b/arch/arm/include/asm/page.h
1521@@ -123,7 +123,7 @@ struct cpu_user_fns {
1522 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1523 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1524 unsigned long vaddr, struct vm_area_struct *vma);
1525-};
1526+} __no_const;
1527
1528 #ifdef MULTI_USER
1529 extern struct cpu_user_fns cpu_user;
1530diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1531index 943504f..bf8d667 100644
1532--- a/arch/arm/include/asm/pgalloc.h
1533+++ b/arch/arm/include/asm/pgalloc.h
1534@@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1535 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1536 }
1537
1538+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1539+{
1540+ pud_populate(mm, pud, pmd);
1541+}
1542+
1543 #else /* !CONFIG_ARM_LPAE */
1544
1545 /*
1546@@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1547 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1548 #define pmd_free(mm, pmd) do { } while (0)
1549 #define pud_populate(mm,pmd,pte) BUG()
1550+#define pud_populate_kernel(mm,pmd,pte) BUG()
1551
1552 #endif /* CONFIG_ARM_LPAE */
1553
1554diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1555index 0f04d84..2be5648 100644
1556--- a/arch/arm/include/asm/thread_info.h
1557+++ b/arch/arm/include/asm/thread_info.h
1558@@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1559 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1560 #define TIF_SYSCALL_TRACE 8
1561 #define TIF_SYSCALL_AUDIT 9
1562+
1563+/* within 8 bits of TIF_SYSCALL_TRACE
1564+ to meet flexible second operand requirements
1565+*/
1566+#define TIF_GRSEC_SETXID 10
1567+
1568 #define TIF_POLLING_NRFLAG 16
1569 #define TIF_USING_IWMMXT 17
1570 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1571@@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1572 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1573 #define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
1574 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1575+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1576
1577 /* Checks for any syscall work in entry-common.S */
1578-#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1579+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1580+ _TIF_GRSEC_SETXID)
1581
1582 /*
1583 * Change these and you break ASM code in entry-common.S
1584diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1585index 71f6536..602f279 100644
1586--- a/arch/arm/include/asm/uaccess.h
1587+++ b/arch/arm/include/asm/uaccess.h
1588@@ -22,6 +22,8 @@
1589 #define VERIFY_READ 0
1590 #define VERIFY_WRITE 1
1591
1592+extern void check_object_size(const void *ptr, unsigned long n, bool to);
1593+
1594 /*
1595 * The exception table consists of pairs of addresses: the first is the
1596 * address of an instruction that is allowed to fault, and the second is
1597@@ -387,8 +389,23 @@ do { \
1598
1599
1600 #ifdef CONFIG_MMU
1601-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1602-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1603+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1604+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1605+
1606+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1607+{
1608+ if (!__builtin_constant_p(n))
1609+ check_object_size(to, n, false);
1610+ return ___copy_from_user(to, from, n);
1611+}
1612+
1613+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1614+{
1615+ if (!__builtin_constant_p(n))
1616+ check_object_size(from, n, true);
1617+ return ___copy_to_user(to, from, n);
1618+}
1619+
1620 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1621 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1622 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1623@@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1624
1625 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1626 {
1627+ if ((long)n < 0)
1628+ return n;
1629+
1630 if (access_ok(VERIFY_READ, from, n))
1631 n = __copy_from_user(to, from, n);
1632 else /* security hole - plug it */
1633@@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1634
1635 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1636 {
1637+ if ((long)n < 0)
1638+ return n;
1639+
1640 if (access_ok(VERIFY_WRITE, to, n))
1641 n = __copy_to_user(to, from, n);
1642 return n;
1643diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1644index b57c75e..ed2d6b2 100644
1645--- a/arch/arm/kernel/armksyms.c
1646+++ b/arch/arm/kernel/armksyms.c
1647@@ -94,8 +94,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1648 #ifdef CONFIG_MMU
1649 EXPORT_SYMBOL(copy_page);
1650
1651-EXPORT_SYMBOL(__copy_from_user);
1652-EXPORT_SYMBOL(__copy_to_user);
1653+EXPORT_SYMBOL(___copy_from_user);
1654+EXPORT_SYMBOL(___copy_to_user);
1655 EXPORT_SYMBOL(__clear_user);
1656
1657 EXPORT_SYMBOL(__get_user_1);
1658diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1659index 2b7b017..c380fa2 100644
1660--- a/arch/arm/kernel/process.c
1661+++ b/arch/arm/kernel/process.c
1662@@ -28,7 +28,6 @@
1663 #include <linux/tick.h>
1664 #include <linux/utsname.h>
1665 #include <linux/uaccess.h>
1666-#include <linux/random.h>
1667 #include <linux/hw_breakpoint.h>
1668 #include <linux/cpuidle.h>
1669
1670@@ -275,9 +274,10 @@ void machine_power_off(void)
1671 machine_shutdown();
1672 if (pm_power_off)
1673 pm_power_off();
1674+ BUG();
1675 }
1676
1677-void machine_restart(char *cmd)
1678+__noreturn void machine_restart(char *cmd)
1679 {
1680 machine_shutdown();
1681
1682@@ -519,12 +519,6 @@ unsigned long get_wchan(struct task_struct *p)
1683 return 0;
1684 }
1685
1686-unsigned long arch_randomize_brk(struct mm_struct *mm)
1687-{
1688- unsigned long range_end = mm->brk + 0x02000000;
1689- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1690-}
1691-
1692 #ifdef CONFIG_MMU
1693 /*
1694 * The vectors page is always readable from user space for the
1695diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1696index 9650c14..ae30cdd 100644
1697--- a/arch/arm/kernel/ptrace.c
1698+++ b/arch/arm/kernel/ptrace.c
1699@@ -906,10 +906,19 @@ long arch_ptrace(struct task_struct *child, long request,
1700 return ret;
1701 }
1702
1703+#ifdef CONFIG_GRKERNSEC_SETXID
1704+extern void gr_delayed_cred_worker(void);
1705+#endif
1706+
1707 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1708 {
1709 unsigned long ip;
1710
1711+#ifdef CONFIG_GRKERNSEC_SETXID
1712+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1713+ gr_delayed_cred_worker();
1714+#endif
1715+
1716 if (why)
1717 audit_syscall_exit(regs);
1718 else
1719diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1720index ebfac78..cbea9c0 100644
1721--- a/arch/arm/kernel/setup.c
1722+++ b/arch/arm/kernel/setup.c
1723@@ -111,13 +111,13 @@ struct processor processor __read_mostly;
1724 struct cpu_tlb_fns cpu_tlb __read_mostly;
1725 #endif
1726 #ifdef MULTI_USER
1727-struct cpu_user_fns cpu_user __read_mostly;
1728+struct cpu_user_fns cpu_user __read_only;
1729 #endif
1730 #ifdef MULTI_CACHE
1731-struct cpu_cache_fns cpu_cache __read_mostly;
1732+struct cpu_cache_fns cpu_cache __read_only;
1733 #endif
1734 #ifdef CONFIG_OUTER_CACHE
1735-struct outer_cache_fns outer_cache __read_mostly;
1736+struct outer_cache_fns outer_cache __read_only;
1737 EXPORT_SYMBOL(outer_cache);
1738 #endif
1739
1740diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1741index 63d402f..db1d714 100644
1742--- a/arch/arm/kernel/traps.c
1743+++ b/arch/arm/kernel/traps.c
1744@@ -264,6 +264,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1745
1746 static DEFINE_RAW_SPINLOCK(die_lock);
1747
1748+extern void gr_handle_kernel_exploit(void);
1749+
1750 /*
1751 * This function is protected against re-entrancy.
1752 */
1753@@ -296,6 +298,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1754 panic("Fatal exception in interrupt");
1755 if (panic_on_oops)
1756 panic("Fatal exception");
1757+
1758+ gr_handle_kernel_exploit();
1759+
1760 if (ret != NOTIFY_STOP)
1761 do_exit(SIGSEGV);
1762 }
1763diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1764index 66a477a..bee61d3 100644
1765--- a/arch/arm/lib/copy_from_user.S
1766+++ b/arch/arm/lib/copy_from_user.S
1767@@ -16,7 +16,7 @@
1768 /*
1769 * Prototype:
1770 *
1771- * size_t __copy_from_user(void *to, const void *from, size_t n)
1772+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
1773 *
1774 * Purpose:
1775 *
1776@@ -84,11 +84,11 @@
1777
1778 .text
1779
1780-ENTRY(__copy_from_user)
1781+ENTRY(___copy_from_user)
1782
1783 #include "copy_template.S"
1784
1785-ENDPROC(__copy_from_user)
1786+ENDPROC(___copy_from_user)
1787
1788 .pushsection .fixup,"ax"
1789 .align 0
1790diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1791index 6ee2f67..d1cce76 100644
1792--- a/arch/arm/lib/copy_page.S
1793+++ b/arch/arm/lib/copy_page.S
1794@@ -10,6 +10,7 @@
1795 * ASM optimised string functions
1796 */
1797 #include <linux/linkage.h>
1798+#include <linux/const.h>
1799 #include <asm/assembler.h>
1800 #include <asm/asm-offsets.h>
1801 #include <asm/cache.h>
1802diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1803index d066df6..df28194 100644
1804--- a/arch/arm/lib/copy_to_user.S
1805+++ b/arch/arm/lib/copy_to_user.S
1806@@ -16,7 +16,7 @@
1807 /*
1808 * Prototype:
1809 *
1810- * size_t __copy_to_user(void *to, const void *from, size_t n)
1811+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
1812 *
1813 * Purpose:
1814 *
1815@@ -88,11 +88,11 @@
1816 .text
1817
1818 ENTRY(__copy_to_user_std)
1819-WEAK(__copy_to_user)
1820+WEAK(___copy_to_user)
1821
1822 #include "copy_template.S"
1823
1824-ENDPROC(__copy_to_user)
1825+ENDPROC(___copy_to_user)
1826 ENDPROC(__copy_to_user_std)
1827
1828 .pushsection .fixup,"ax"
1829diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1830index 5c908b1..e712687 100644
1831--- a/arch/arm/lib/uaccess.S
1832+++ b/arch/arm/lib/uaccess.S
1833@@ -20,7 +20,7 @@
1834
1835 #define PAGE_SHIFT 12
1836
1837-/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1838+/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1839 * Purpose : copy a block to user memory from kernel memory
1840 * Params : to - user memory
1841 * : from - kernel memory
1842@@ -40,7 +40,7 @@ USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1843 sub r2, r2, ip
1844 b .Lc2u_dest_aligned
1845
1846-ENTRY(__copy_to_user)
1847+ENTRY(___copy_to_user)
1848 stmfd sp!, {r2, r4 - r7, lr}
1849 cmp r2, #4
1850 blt .Lc2u_not_enough
1851@@ -278,14 +278,14 @@ USER( TUSER( strgeb) r3, [r0], #1) @ May fault
1852 ldrgtb r3, [r1], #0
1853 USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1854 b .Lc2u_finished
1855-ENDPROC(__copy_to_user)
1856+ENDPROC(___copy_to_user)
1857
1858 .pushsection .fixup,"ax"
1859 .align 0
1860 9001: ldmfd sp!, {r0, r4 - r7, pc}
1861 .popsection
1862
1863-/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1864+/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1865 * Purpose : copy a block from user memory to kernel memory
1866 * Params : to - kernel memory
1867 * : from - user memory
1868@@ -304,7 +304,7 @@ USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1869 sub r2, r2, ip
1870 b .Lcfu_dest_aligned
1871
1872-ENTRY(__copy_from_user)
1873+ENTRY(___copy_from_user)
1874 stmfd sp!, {r0, r2, r4 - r7, lr}
1875 cmp r2, #4
1876 blt .Lcfu_not_enough
1877@@ -544,7 +544,7 @@ USER( TUSER( ldrgeb) r3, [r1], #1) @ May fault
1878 USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1879 strgtb r3, [r0], #1
1880 b .Lcfu_finished
1881-ENDPROC(__copy_from_user)
1882+ENDPROC(___copy_from_user)
1883
1884 .pushsection .fixup,"ax"
1885 .align 0
1886diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1887index 025f742..8432b08 100644
1888--- a/arch/arm/lib/uaccess_with_memcpy.c
1889+++ b/arch/arm/lib/uaccess_with_memcpy.c
1890@@ -104,7 +104,7 @@ out:
1891 }
1892
1893 unsigned long
1894-__copy_to_user(void __user *to, const void *from, unsigned long n)
1895+___copy_to_user(void __user *to, const void *from, unsigned long n)
1896 {
1897 /*
1898 * This test is stubbed out of the main function above to keep
1899diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1900index 518091c..eae9a76 100644
1901--- a/arch/arm/mach-omap2/board-n8x0.c
1902+++ b/arch/arm/mach-omap2/board-n8x0.c
1903@@ -596,7 +596,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1904 }
1905 #endif
1906
1907-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1908+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1909 .late_init = n8x0_menelaus_late_init,
1910 };
1911
1912diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1913index 5bb4835..4760f68 100644
1914--- a/arch/arm/mm/fault.c
1915+++ b/arch/arm/mm/fault.c
1916@@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1917 }
1918 #endif
1919
1920+#ifdef CONFIG_PAX_PAGEEXEC
1921+ if (fsr & FSR_LNX_PF) {
1922+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1923+ do_group_exit(SIGKILL);
1924+ }
1925+#endif
1926+
1927 tsk->thread.address = addr;
1928 tsk->thread.error_code = fsr;
1929 tsk->thread.trap_no = 14;
1930@@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1931 }
1932 #endif /* CONFIG_MMU */
1933
1934+#ifdef CONFIG_PAX_PAGEEXEC
1935+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1936+{
1937+ long i;
1938+
1939+ printk(KERN_ERR "PAX: bytes at PC: ");
1940+ for (i = 0; i < 20; i++) {
1941+ unsigned char c;
1942+ if (get_user(c, (__force unsigned char __user *)pc+i))
1943+ printk(KERN_CONT "?? ");
1944+ else
1945+ printk(KERN_CONT "%02x ", c);
1946+ }
1947+ printk("\n");
1948+
1949+ printk(KERN_ERR "PAX: bytes at SP-4: ");
1950+ for (i = -1; i < 20; i++) {
1951+ unsigned long c;
1952+ if (get_user(c, (__force unsigned long __user *)sp+i))
1953+ printk(KERN_CONT "???????? ");
1954+ else
1955+ printk(KERN_CONT "%08lx ", c);
1956+ }
1957+ printk("\n");
1958+}
1959+#endif
1960+
1961 /*
1962 * First Level Translation Fault Handler
1963 *
1964@@ -577,6 +611,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1965 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1966 struct siginfo info;
1967
1968+#ifdef CONFIG_PAX_REFCOUNT
1969+ if (fsr_fs(ifsr) == 2) {
1970+ unsigned int bkpt;
1971+
1972+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1973+ current->thread.error_code = ifsr;
1974+ current->thread.trap_no = 0;
1975+ pax_report_refcount_overflow(regs);
1976+ fixup_exception(regs);
1977+ return;
1978+ }
1979+ }
1980+#endif
1981+
1982 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1983 return;
1984
1985diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1986index ce8cb19..3ec539d 100644
1987--- a/arch/arm/mm/mmap.c
1988+++ b/arch/arm/mm/mmap.c
1989@@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1990 if (len > TASK_SIZE)
1991 return -ENOMEM;
1992
1993+#ifdef CONFIG_PAX_RANDMMAP
1994+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1995+#endif
1996+
1997 if (addr) {
1998 if (do_align)
1999 addr = COLOUR_ALIGN(addr, pgoff);
2000@@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2001 addr = PAGE_ALIGN(addr);
2002
2003 vma = find_vma(mm, addr);
2004- if (TASK_SIZE - len >= addr &&
2005- (!vma || addr + len <= vma->vm_start))
2006+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2007 return addr;
2008 }
2009 if (len > mm->cached_hole_size) {
2010- start_addr = addr = mm->free_area_cache;
2011+ start_addr = addr = mm->free_area_cache;
2012 } else {
2013- start_addr = addr = mm->mmap_base;
2014- mm->cached_hole_size = 0;
2015+ start_addr = addr = mm->mmap_base;
2016+ mm->cached_hole_size = 0;
2017 }
2018
2019 full_search:
2020@@ -124,14 +127,14 @@ full_search:
2021 * Start a new search - just in case we missed
2022 * some holes.
2023 */
2024- if (start_addr != TASK_UNMAPPED_BASE) {
2025- start_addr = addr = TASK_UNMAPPED_BASE;
2026+ if (start_addr != mm->mmap_base) {
2027+ start_addr = addr = mm->mmap_base;
2028 mm->cached_hole_size = 0;
2029 goto full_search;
2030 }
2031 return -ENOMEM;
2032 }
2033- if (!vma || addr + len <= vma->vm_start) {
2034+ if (check_heap_stack_gap(vma, addr, len)) {
2035 /*
2036 * Remember the place where we stopped the search:
2037 */
2038@@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2039
2040 if (mmap_is_legacy()) {
2041 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2042+
2043+#ifdef CONFIG_PAX_RANDMMAP
2044+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2045+ mm->mmap_base += mm->delta_mmap;
2046+#endif
2047+
2048 mm->get_unmapped_area = arch_get_unmapped_area;
2049 mm->unmap_area = arch_unmap_area;
2050 } else {
2051 mm->mmap_base = mmap_base(random_factor);
2052+
2053+#ifdef CONFIG_PAX_RANDMMAP
2054+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2055+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2056+#endif
2057+
2058 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2059 mm->unmap_area = arch_unmap_area_topdown;
2060 }
2061diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2062index fd556f7..af2e7d2 100644
2063--- a/arch/arm/plat-orion/include/plat/addr-map.h
2064+++ b/arch/arm/plat-orion/include/plat/addr-map.h
2065@@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2066 value in bridge_virt_base */
2067 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2068 const int win);
2069-};
2070+} __no_const;
2071
2072 /*
2073 * Information needed to setup one address mapping.
2074diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2075index 71a6827..e7fbc23 100644
2076--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2077+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2078@@ -43,7 +43,7 @@ struct samsung_dma_ops {
2079 int (*started)(unsigned ch);
2080 int (*flush)(unsigned ch);
2081 int (*stop)(unsigned ch);
2082-};
2083+} __no_const;
2084
2085 extern void *samsung_dmadev_get_ops(void);
2086 extern void *s3c_dma_get_ops(void);
2087diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2088index 5f28cae..3d23723 100644
2089--- a/arch/arm/plat-samsung/include/plat/ehci.h
2090+++ b/arch/arm/plat-samsung/include/plat/ehci.h
2091@@ -14,7 +14,7 @@
2092 struct s5p_ehci_platdata {
2093 int (*phy_init)(struct platform_device *pdev, int type);
2094 int (*phy_exit)(struct platform_device *pdev, int type);
2095-};
2096+} __no_const;
2097
2098 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2099
2100diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2101index c3a58a1..78fbf54 100644
2102--- a/arch/avr32/include/asm/cache.h
2103+++ b/arch/avr32/include/asm/cache.h
2104@@ -1,8 +1,10 @@
2105 #ifndef __ASM_AVR32_CACHE_H
2106 #define __ASM_AVR32_CACHE_H
2107
2108+#include <linux/const.h>
2109+
2110 #define L1_CACHE_SHIFT 5
2111-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2112+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2113
2114 /*
2115 * Memory returned by kmalloc() may be used for DMA, so we must make
2116diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2117index 3b3159b..425ea94 100644
2118--- a/arch/avr32/include/asm/elf.h
2119+++ b/arch/avr32/include/asm/elf.h
2120@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2121 the loader. We need to make sure that it is out of the way of the program
2122 that it will "exec", and that there is sufficient room for the brk. */
2123
2124-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2125+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2126
2127+#ifdef CONFIG_PAX_ASLR
2128+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2129+
2130+#define PAX_DELTA_MMAP_LEN 15
2131+#define PAX_DELTA_STACK_LEN 15
2132+#endif
2133
2134 /* This yields a mask that user programs can use to figure out what
2135 instruction set this CPU supports. This could be done in user space,
2136diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2137index b7f5c68..556135c 100644
2138--- a/arch/avr32/include/asm/kmap_types.h
2139+++ b/arch/avr32/include/asm/kmap_types.h
2140@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2141 D(11) KM_IRQ1,
2142 D(12) KM_SOFTIRQ0,
2143 D(13) KM_SOFTIRQ1,
2144-D(14) KM_TYPE_NR
2145+D(14) KM_CLEARPAGE,
2146+D(15) KM_TYPE_NR
2147 };
2148
2149 #undef D
2150diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2151index f7040a1..db9f300 100644
2152--- a/arch/avr32/mm/fault.c
2153+++ b/arch/avr32/mm/fault.c
2154@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2155
2156 int exception_trace = 1;
2157
2158+#ifdef CONFIG_PAX_PAGEEXEC
2159+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2160+{
2161+ unsigned long i;
2162+
2163+ printk(KERN_ERR "PAX: bytes at PC: ");
2164+ for (i = 0; i < 20; i++) {
2165+ unsigned char c;
2166+ if (get_user(c, (unsigned char *)pc+i))
2167+ printk(KERN_CONT "???????? ");
2168+ else
2169+ printk(KERN_CONT "%02x ", c);
2170+ }
2171+ printk("\n");
2172+}
2173+#endif
2174+
2175 /*
2176 * This routine handles page faults. It determines the address and the
2177 * problem, and then passes it off to one of the appropriate routines.
2178@@ -156,6 +173,16 @@ bad_area:
2179 up_read(&mm->mmap_sem);
2180
2181 if (user_mode(regs)) {
2182+
2183+#ifdef CONFIG_PAX_PAGEEXEC
2184+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2185+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2186+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2187+ do_group_exit(SIGKILL);
2188+ }
2189+ }
2190+#endif
2191+
2192 if (exception_trace && printk_ratelimit())
2193 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2194 "sp %08lx ecr %lu\n",
2195diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2196index 568885a..f8008df 100644
2197--- a/arch/blackfin/include/asm/cache.h
2198+++ b/arch/blackfin/include/asm/cache.h
2199@@ -7,6 +7,7 @@
2200 #ifndef __ARCH_BLACKFIN_CACHE_H
2201 #define __ARCH_BLACKFIN_CACHE_H
2202
2203+#include <linux/const.h>
2204 #include <linux/linkage.h> /* for asmlinkage */
2205
2206 /*
2207@@ -14,7 +15,7 @@
2208 * Blackfin loads 32 bytes for cache
2209 */
2210 #define L1_CACHE_SHIFT 5
2211-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2212+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2213 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2214
2215 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2216diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2217index aea2718..3639a60 100644
2218--- a/arch/cris/include/arch-v10/arch/cache.h
2219+++ b/arch/cris/include/arch-v10/arch/cache.h
2220@@ -1,8 +1,9 @@
2221 #ifndef _ASM_ARCH_CACHE_H
2222 #define _ASM_ARCH_CACHE_H
2223
2224+#include <linux/const.h>
2225 /* Etrax 100LX have 32-byte cache-lines. */
2226-#define L1_CACHE_BYTES 32
2227 #define L1_CACHE_SHIFT 5
2228+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2229
2230 #endif /* _ASM_ARCH_CACHE_H */
2231diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2232index 1de779f..336fad3 100644
2233--- a/arch/cris/include/arch-v32/arch/cache.h
2234+++ b/arch/cris/include/arch-v32/arch/cache.h
2235@@ -1,11 +1,12 @@
2236 #ifndef _ASM_CRIS_ARCH_CACHE_H
2237 #define _ASM_CRIS_ARCH_CACHE_H
2238
2239+#include <linux/const.h>
2240 #include <arch/hwregs/dma.h>
2241
2242 /* A cache-line is 32 bytes. */
2243-#define L1_CACHE_BYTES 32
2244 #define L1_CACHE_SHIFT 5
2245+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2246
2247 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2248
2249diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2250index b86329d..6709906 100644
2251--- a/arch/frv/include/asm/atomic.h
2252+++ b/arch/frv/include/asm/atomic.h
2253@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2254 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2255 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2256
2257+#define atomic64_read_unchecked(v) atomic64_read(v)
2258+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2259+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2260+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2261+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2262+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2263+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2264+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2265+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2266+
2267 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2268 {
2269 int c, old;
2270diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2271index 2797163..c2a401d 100644
2272--- a/arch/frv/include/asm/cache.h
2273+++ b/arch/frv/include/asm/cache.h
2274@@ -12,10 +12,11 @@
2275 #ifndef __ASM_CACHE_H
2276 #define __ASM_CACHE_H
2277
2278+#include <linux/const.h>
2279
2280 /* bytes per L1 cache line */
2281 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2282-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2283+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2284
2285 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2286 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2287diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2288index f8e16b2..c73ff79 100644
2289--- a/arch/frv/include/asm/kmap_types.h
2290+++ b/arch/frv/include/asm/kmap_types.h
2291@@ -23,6 +23,7 @@ enum km_type {
2292 KM_IRQ1,
2293 KM_SOFTIRQ0,
2294 KM_SOFTIRQ1,
2295+ KM_CLEARPAGE,
2296 KM_TYPE_NR
2297 };
2298
2299diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2300index 385fd30..6c3d97e 100644
2301--- a/arch/frv/mm/elf-fdpic.c
2302+++ b/arch/frv/mm/elf-fdpic.c
2303@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2304 if (addr) {
2305 addr = PAGE_ALIGN(addr);
2306 vma = find_vma(current->mm, addr);
2307- if (TASK_SIZE - len >= addr &&
2308- (!vma || addr + len <= vma->vm_start))
2309+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2310 goto success;
2311 }
2312
2313@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2314 for (; vma; vma = vma->vm_next) {
2315 if (addr > limit)
2316 break;
2317- if (addr + len <= vma->vm_start)
2318+ if (check_heap_stack_gap(vma, addr, len))
2319 goto success;
2320 addr = vma->vm_end;
2321 }
2322@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2323 for (; vma; vma = vma->vm_next) {
2324 if (addr > limit)
2325 break;
2326- if (addr + len <= vma->vm_start)
2327+ if (check_heap_stack_gap(vma, addr, len))
2328 goto success;
2329 addr = vma->vm_end;
2330 }
2331diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2332index c635028..6d9445a 100644
2333--- a/arch/h8300/include/asm/cache.h
2334+++ b/arch/h8300/include/asm/cache.h
2335@@ -1,8 +1,10 @@
2336 #ifndef __ARCH_H8300_CACHE_H
2337 #define __ARCH_H8300_CACHE_H
2338
2339+#include <linux/const.h>
2340+
2341 /* bytes per L1 cache line */
2342-#define L1_CACHE_BYTES 4
2343+#define L1_CACHE_BYTES _AC(4,UL)
2344
2345 /* m68k-elf-gcc 2.95.2 doesn't like these */
2346
2347diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2348index 0f01de2..d37d309 100644
2349--- a/arch/hexagon/include/asm/cache.h
2350+++ b/arch/hexagon/include/asm/cache.h
2351@@ -21,9 +21,11 @@
2352 #ifndef __ASM_CACHE_H
2353 #define __ASM_CACHE_H
2354
2355+#include <linux/const.h>
2356+
2357 /* Bytes per L1 cache line */
2358-#define L1_CACHE_SHIFT (5)
2359-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2360+#define L1_CACHE_SHIFT 5
2361+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2362
2363 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2364 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2365diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2366index 7d91166..88ab87e 100644
2367--- a/arch/ia64/include/asm/atomic.h
2368+++ b/arch/ia64/include/asm/atomic.h
2369@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2370 #define atomic64_inc(v) atomic64_add(1, (v))
2371 #define atomic64_dec(v) atomic64_sub(1, (v))
2372
2373+#define atomic64_read_unchecked(v) atomic64_read(v)
2374+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2375+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2376+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2377+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2378+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2379+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2380+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2381+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2382+
2383 /* Atomic operations are already serializing */
2384 #define smp_mb__before_atomic_dec() barrier()
2385 #define smp_mb__after_atomic_dec() barrier()
2386diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2387index 988254a..e1ee885 100644
2388--- a/arch/ia64/include/asm/cache.h
2389+++ b/arch/ia64/include/asm/cache.h
2390@@ -1,6 +1,7 @@
2391 #ifndef _ASM_IA64_CACHE_H
2392 #define _ASM_IA64_CACHE_H
2393
2394+#include <linux/const.h>
2395
2396 /*
2397 * Copyright (C) 1998-2000 Hewlett-Packard Co
2398@@ -9,7 +10,7 @@
2399
2400 /* Bytes per L1 (data) cache line. */
2401 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2402-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2403+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2404
2405 #ifdef CONFIG_SMP
2406 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2407diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2408index b5298eb..67c6e62 100644
2409--- a/arch/ia64/include/asm/elf.h
2410+++ b/arch/ia64/include/asm/elf.h
2411@@ -42,6 +42,13 @@
2412 */
2413 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2414
2415+#ifdef CONFIG_PAX_ASLR
2416+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2417+
2418+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2419+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2420+#endif
2421+
2422 #define PT_IA_64_UNWIND 0x70000001
2423
2424 /* IA-64 relocations: */
2425diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2426index 96a8d92..617a1cf 100644
2427--- a/arch/ia64/include/asm/pgalloc.h
2428+++ b/arch/ia64/include/asm/pgalloc.h
2429@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2430 pgd_val(*pgd_entry) = __pa(pud);
2431 }
2432
2433+static inline void
2434+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2435+{
2436+ pgd_populate(mm, pgd_entry, pud);
2437+}
2438+
2439 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2440 {
2441 return quicklist_alloc(0, GFP_KERNEL, NULL);
2442@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2443 pud_val(*pud_entry) = __pa(pmd);
2444 }
2445
2446+static inline void
2447+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2448+{
2449+ pud_populate(mm, pud_entry, pmd);
2450+}
2451+
2452 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2453 {
2454 return quicklist_alloc(0, GFP_KERNEL, NULL);
2455diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2456index 815810c..d60bd4c 100644
2457--- a/arch/ia64/include/asm/pgtable.h
2458+++ b/arch/ia64/include/asm/pgtable.h
2459@@ -12,7 +12,7 @@
2460 * David Mosberger-Tang <davidm@hpl.hp.com>
2461 */
2462
2463-
2464+#include <linux/const.h>
2465 #include <asm/mman.h>
2466 #include <asm/page.h>
2467 #include <asm/processor.h>
2468@@ -142,6 +142,17 @@
2469 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2470 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2471 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2472+
2473+#ifdef CONFIG_PAX_PAGEEXEC
2474+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2475+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2476+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2477+#else
2478+# define PAGE_SHARED_NOEXEC PAGE_SHARED
2479+# define PAGE_READONLY_NOEXEC PAGE_READONLY
2480+# define PAGE_COPY_NOEXEC PAGE_COPY
2481+#endif
2482+
2483 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2484 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2485 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2486diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2487index 54ff557..70c88b7 100644
2488--- a/arch/ia64/include/asm/spinlock.h
2489+++ b/arch/ia64/include/asm/spinlock.h
2490@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2491 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2492
2493 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2494- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2495+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2496 }
2497
2498 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2499diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2500index 449c8c0..432a3d2 100644
2501--- a/arch/ia64/include/asm/uaccess.h
2502+++ b/arch/ia64/include/asm/uaccess.h
2503@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2504 const void *__cu_from = (from); \
2505 long __cu_len = (n); \
2506 \
2507- if (__access_ok(__cu_to, __cu_len, get_fs())) \
2508+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2509 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2510 __cu_len; \
2511 })
2512@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2513 long __cu_len = (n); \
2514 \
2515 __chk_user_ptr(__cu_from); \
2516- if (__access_ok(__cu_from, __cu_len, get_fs())) \
2517+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2518 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2519 __cu_len; \
2520 })
2521diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2522index 24603be..948052d 100644
2523--- a/arch/ia64/kernel/module.c
2524+++ b/arch/ia64/kernel/module.c
2525@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2526 void
2527 module_free (struct module *mod, void *module_region)
2528 {
2529- if (mod && mod->arch.init_unw_table &&
2530- module_region == mod->module_init) {
2531+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2532 unw_remove_unwind_table(mod->arch.init_unw_table);
2533 mod->arch.init_unw_table = NULL;
2534 }
2535@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2536 }
2537
2538 static inline int
2539+in_init_rx (const struct module *mod, uint64_t addr)
2540+{
2541+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2542+}
2543+
2544+static inline int
2545+in_init_rw (const struct module *mod, uint64_t addr)
2546+{
2547+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2548+}
2549+
2550+static inline int
2551 in_init (const struct module *mod, uint64_t addr)
2552 {
2553- return addr - (uint64_t) mod->module_init < mod->init_size;
2554+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2555+}
2556+
2557+static inline int
2558+in_core_rx (const struct module *mod, uint64_t addr)
2559+{
2560+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2561+}
2562+
2563+static inline int
2564+in_core_rw (const struct module *mod, uint64_t addr)
2565+{
2566+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2567 }
2568
2569 static inline int
2570 in_core (const struct module *mod, uint64_t addr)
2571 {
2572- return addr - (uint64_t) mod->module_core < mod->core_size;
2573+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2574 }
2575
2576 static inline int
2577@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2578 break;
2579
2580 case RV_BDREL:
2581- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2582+ if (in_init_rx(mod, val))
2583+ val -= (uint64_t) mod->module_init_rx;
2584+ else if (in_init_rw(mod, val))
2585+ val -= (uint64_t) mod->module_init_rw;
2586+ else if (in_core_rx(mod, val))
2587+ val -= (uint64_t) mod->module_core_rx;
2588+ else if (in_core_rw(mod, val))
2589+ val -= (uint64_t) mod->module_core_rw;
2590 break;
2591
2592 case RV_LTV:
2593@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2594 * addresses have been selected...
2595 */
2596 uint64_t gp;
2597- if (mod->core_size > MAX_LTOFF)
2598+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2599 /*
2600 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2601 * at the end of the module.
2602 */
2603- gp = mod->core_size - MAX_LTOFF / 2;
2604+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2605 else
2606- gp = mod->core_size / 2;
2607- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2608+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2609+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2610 mod->arch.gp = gp;
2611 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2612 }
2613diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2614index 609d500..7dde2a8 100644
2615--- a/arch/ia64/kernel/sys_ia64.c
2616+++ b/arch/ia64/kernel/sys_ia64.c
2617@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2618 if (REGION_NUMBER(addr) == RGN_HPAGE)
2619 addr = 0;
2620 #endif
2621+
2622+#ifdef CONFIG_PAX_RANDMMAP
2623+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2624+ addr = mm->free_area_cache;
2625+ else
2626+#endif
2627+
2628 if (!addr)
2629 addr = mm->free_area_cache;
2630
2631@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2632 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2633 /* At this point: (!vma || addr < vma->vm_end). */
2634 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2635- if (start_addr != TASK_UNMAPPED_BASE) {
2636+ if (start_addr != mm->mmap_base) {
2637 /* Start a new search --- just in case we missed some holes. */
2638- addr = TASK_UNMAPPED_BASE;
2639+ addr = mm->mmap_base;
2640 goto full_search;
2641 }
2642 return -ENOMEM;
2643 }
2644- if (!vma || addr + len <= vma->vm_start) {
2645+ if (check_heap_stack_gap(vma, addr, len)) {
2646 /* Remember the address where we stopped this search: */
2647 mm->free_area_cache = addr + len;
2648 return addr;
2649diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2650index 0ccb28f..8992469 100644
2651--- a/arch/ia64/kernel/vmlinux.lds.S
2652+++ b/arch/ia64/kernel/vmlinux.lds.S
2653@@ -198,7 +198,7 @@ SECTIONS {
2654 /* Per-cpu data: */
2655 . = ALIGN(PERCPU_PAGE_SIZE);
2656 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2657- __phys_per_cpu_start = __per_cpu_load;
2658+ __phys_per_cpu_start = per_cpu_load;
2659 /*
2660 * ensure percpu data fits
2661 * into percpu page size
2662diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2663index 02d29c2..ea893df 100644
2664--- a/arch/ia64/mm/fault.c
2665+++ b/arch/ia64/mm/fault.c
2666@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2667 return pte_present(pte);
2668 }
2669
2670+#ifdef CONFIG_PAX_PAGEEXEC
2671+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2672+{
2673+ unsigned long i;
2674+
2675+ printk(KERN_ERR "PAX: bytes at PC: ");
2676+ for (i = 0; i < 8; i++) {
2677+ unsigned int c;
2678+ if (get_user(c, (unsigned int *)pc+i))
2679+ printk(KERN_CONT "???????? ");
2680+ else
2681+ printk(KERN_CONT "%08x ", c);
2682+ }
2683+ printk("\n");
2684+}
2685+#endif
2686+
2687 void __kprobes
2688 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2689 {
2690@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2691 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2692 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2693
2694- if ((vma->vm_flags & mask) != mask)
2695+ if ((vma->vm_flags & mask) != mask) {
2696+
2697+#ifdef CONFIG_PAX_PAGEEXEC
2698+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2699+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2700+ goto bad_area;
2701+
2702+ up_read(&mm->mmap_sem);
2703+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2704+ do_group_exit(SIGKILL);
2705+ }
2706+#endif
2707+
2708 goto bad_area;
2709
2710+ }
2711+
2712 /*
2713 * If for any reason at all we couldn't handle the fault, make
2714 * sure we exit gracefully rather than endlessly redo the
2715diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2716index 5ca674b..e0e1b70 100644
2717--- a/arch/ia64/mm/hugetlbpage.c
2718+++ b/arch/ia64/mm/hugetlbpage.c
2719@@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2720 /* At this point: (!vmm || addr < vmm->vm_end). */
2721 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2722 return -ENOMEM;
2723- if (!vmm || (addr + len) <= vmm->vm_start)
2724+ if (check_heap_stack_gap(vmm, addr, len))
2725 return addr;
2726 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2727 }
2728diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2729index 0eab454..bd794f2 100644
2730--- a/arch/ia64/mm/init.c
2731+++ b/arch/ia64/mm/init.c
2732@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2733 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2734 vma->vm_end = vma->vm_start + PAGE_SIZE;
2735 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2736+
2737+#ifdef CONFIG_PAX_PAGEEXEC
2738+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2739+ vma->vm_flags &= ~VM_EXEC;
2740+
2741+#ifdef CONFIG_PAX_MPROTECT
2742+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
2743+ vma->vm_flags &= ~VM_MAYEXEC;
2744+#endif
2745+
2746+ }
2747+#endif
2748+
2749 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2750 down_write(&current->mm->mmap_sem);
2751 if (insert_vm_struct(current->mm, vma)) {
2752diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2753index 40b3ee9..8c2c112 100644
2754--- a/arch/m32r/include/asm/cache.h
2755+++ b/arch/m32r/include/asm/cache.h
2756@@ -1,8 +1,10 @@
2757 #ifndef _ASM_M32R_CACHE_H
2758 #define _ASM_M32R_CACHE_H
2759
2760+#include <linux/const.h>
2761+
2762 /* L1 cache line size */
2763 #define L1_CACHE_SHIFT 4
2764-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2765+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2766
2767 #endif /* _ASM_M32R_CACHE_H */
2768diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2769index 82abd15..d95ae5d 100644
2770--- a/arch/m32r/lib/usercopy.c
2771+++ b/arch/m32r/lib/usercopy.c
2772@@ -14,6 +14,9 @@
2773 unsigned long
2774 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2775 {
2776+ if ((long)n < 0)
2777+ return n;
2778+
2779 prefetch(from);
2780 if (access_ok(VERIFY_WRITE, to, n))
2781 __copy_user(to,from,n);
2782@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2783 unsigned long
2784 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2785 {
2786+ if ((long)n < 0)
2787+ return n;
2788+
2789 prefetchw(to);
2790 if (access_ok(VERIFY_READ, from, n))
2791 __copy_user_zeroing(to,from,n);
2792diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2793index 0395c51..5f26031 100644
2794--- a/arch/m68k/include/asm/cache.h
2795+++ b/arch/m68k/include/asm/cache.h
2796@@ -4,9 +4,11 @@
2797 #ifndef __ARCH_M68K_CACHE_H
2798 #define __ARCH_M68K_CACHE_H
2799
2800+#include <linux/const.h>
2801+
2802 /* bytes per L1 cache line */
2803 #define L1_CACHE_SHIFT 4
2804-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2805+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2806
2807 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2808
2809diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2810index 4efe96a..60e8699 100644
2811--- a/arch/microblaze/include/asm/cache.h
2812+++ b/arch/microblaze/include/asm/cache.h
2813@@ -13,11 +13,12 @@
2814 #ifndef _ASM_MICROBLAZE_CACHE_H
2815 #define _ASM_MICROBLAZE_CACHE_H
2816
2817+#include <linux/const.h>
2818 #include <asm/registers.h>
2819
2820 #define L1_CACHE_SHIFT 5
2821 /* word-granular cache in microblaze */
2822-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2823+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2824
2825 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2826
2827diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2828index 3f4c5cb..3439c6e 100644
2829--- a/arch/mips/include/asm/atomic.h
2830+++ b/arch/mips/include/asm/atomic.h
2831@@ -21,6 +21,10 @@
2832 #include <asm/cmpxchg.h>
2833 #include <asm/war.h>
2834
2835+#ifdef CONFIG_GENERIC_ATOMIC64
2836+#include <asm-generic/atomic64.h>
2837+#endif
2838+
2839 #define ATOMIC_INIT(i) { (i) }
2840
2841 /*
2842@@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2843 */
2844 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2845
2846+#define atomic64_read_unchecked(v) atomic64_read(v)
2847+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2848+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2849+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2850+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2851+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2852+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2853+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2854+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2855+
2856 #endif /* CONFIG_64BIT */
2857
2858 /*
2859diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2860index b4db69f..8f3b093 100644
2861--- a/arch/mips/include/asm/cache.h
2862+++ b/arch/mips/include/asm/cache.h
2863@@ -9,10 +9,11 @@
2864 #ifndef _ASM_CACHE_H
2865 #define _ASM_CACHE_H
2866
2867+#include <linux/const.h>
2868 #include <kmalloc.h>
2869
2870 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2871-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2872+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2873
2874 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2875 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2876diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2877index 455c0ac..ad65fbe 100644
2878--- a/arch/mips/include/asm/elf.h
2879+++ b/arch/mips/include/asm/elf.h
2880@@ -372,13 +372,16 @@ extern const char *__elf_platform;
2881 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2882 #endif
2883
2884+#ifdef CONFIG_PAX_ASLR
2885+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2886+
2887+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2888+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2889+#endif
2890+
2891 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2892 struct linux_binprm;
2893 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2894 int uses_interp);
2895
2896-struct mm_struct;
2897-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2898-#define arch_randomize_brk arch_randomize_brk
2899-
2900 #endif /* _ASM_ELF_H */
2901diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2902index c1f6afa..38cc6e9 100644
2903--- a/arch/mips/include/asm/exec.h
2904+++ b/arch/mips/include/asm/exec.h
2905@@ -12,6 +12,6 @@
2906 #ifndef _ASM_EXEC_H
2907 #define _ASM_EXEC_H
2908
2909-extern unsigned long arch_align_stack(unsigned long sp);
2910+#define arch_align_stack(x) ((x) & ~0xfUL)
2911
2912 #endif /* _ASM_EXEC_H */
2913diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2914index da9bd7d..91aa7ab 100644
2915--- a/arch/mips/include/asm/page.h
2916+++ b/arch/mips/include/asm/page.h
2917@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2918 #ifdef CONFIG_CPU_MIPS32
2919 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2920 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2921- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2922+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2923 #else
2924 typedef struct { unsigned long long pte; } pte_t;
2925 #define pte_val(x) ((x).pte)
2926diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2927index 881d18b..cea38bc 100644
2928--- a/arch/mips/include/asm/pgalloc.h
2929+++ b/arch/mips/include/asm/pgalloc.h
2930@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2931 {
2932 set_pud(pud, __pud((unsigned long)pmd));
2933 }
2934+
2935+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2936+{
2937+ pud_populate(mm, pud, pmd);
2938+}
2939 #endif
2940
2941 /*
2942diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2943index abb13e8..cd2d702 100644
2944--- a/arch/mips/include/asm/thread_info.h
2945+++ b/arch/mips/include/asm/thread_info.h
2946@@ -123,6 +123,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2947 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2948 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2949 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2950+/* li takes a 32bit immediate */
2951+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2952 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2953
2954 #ifdef CONFIG_MIPS32_O32
2955@@ -146,15 +148,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2956 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2957 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2958 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2959+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2960+
2961+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2962
2963 /* work to do in syscall_trace_leave() */
2964-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2965+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2966
2967 /* work to do on interrupt/exception return */
2968 #define _TIF_WORK_MASK (0x0000ffef & \
2969 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2970 /* work to do on any return to u-space */
2971-#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2972+#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2973
2974 #endif /* __KERNEL__ */
2975
2976diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2977index 9fdd8bc..4bd7f1a 100644
2978--- a/arch/mips/kernel/binfmt_elfn32.c
2979+++ b/arch/mips/kernel/binfmt_elfn32.c
2980@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2981 #undef ELF_ET_DYN_BASE
2982 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2983
2984+#ifdef CONFIG_PAX_ASLR
2985+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2986+
2987+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2988+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2989+#endif
2990+
2991 #include <asm/processor.h>
2992 #include <linux/module.h>
2993 #include <linux/elfcore.h>
2994diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2995index ff44823..97f8906 100644
2996--- a/arch/mips/kernel/binfmt_elfo32.c
2997+++ b/arch/mips/kernel/binfmt_elfo32.c
2998@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2999 #undef ELF_ET_DYN_BASE
3000 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3001
3002+#ifdef CONFIG_PAX_ASLR
3003+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3004+
3005+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3006+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3007+#endif
3008+
3009 #include <asm/processor.h>
3010
3011 /*
3012diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
3013index e9a5fd7..378809a 100644
3014--- a/arch/mips/kernel/process.c
3015+++ b/arch/mips/kernel/process.c
3016@@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
3017 out:
3018 return pc;
3019 }
3020-
3021-/*
3022- * Don't forget that the stack pointer must be aligned on a 8 bytes
3023- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
3024- */
3025-unsigned long arch_align_stack(unsigned long sp)
3026-{
3027- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3028- sp -= get_random_int() & ~PAGE_MASK;
3029-
3030- return sp & ALMASK;
3031-}
3032diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3033index 7c24c29..e2f1981 100644
3034--- a/arch/mips/kernel/ptrace.c
3035+++ b/arch/mips/kernel/ptrace.c
3036@@ -528,6 +528,10 @@ static inline int audit_arch(void)
3037 return arch;
3038 }
3039
3040+#ifdef CONFIG_GRKERNSEC_SETXID
3041+extern void gr_delayed_cred_worker(void);
3042+#endif
3043+
3044 /*
3045 * Notification of system call entry/exit
3046 * - triggered by current->work.syscall_trace
3047@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3048 /* do the secure computing check first */
3049 secure_computing(regs->regs[2]);
3050
3051+#ifdef CONFIG_GRKERNSEC_SETXID
3052+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3053+ gr_delayed_cred_worker();
3054+#endif
3055+
3056 if (!(current->ptrace & PT_PTRACED))
3057 goto out;
3058
3059diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3060index a632bc1..0b77c7c 100644
3061--- a/arch/mips/kernel/scall32-o32.S
3062+++ b/arch/mips/kernel/scall32-o32.S
3063@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3064
3065 stack_done:
3066 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3067- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3068+ li t1, _TIF_SYSCALL_WORK
3069 and t0, t1
3070 bnez t0, syscall_trace_entry # -> yes
3071
3072diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3073index 3b5a5e9..e1ee86d 100644
3074--- a/arch/mips/kernel/scall64-64.S
3075+++ b/arch/mips/kernel/scall64-64.S
3076@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3077
3078 sd a3, PT_R26(sp) # save a3 for syscall restarting
3079
3080- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3081+ li t1, _TIF_SYSCALL_WORK
3082 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3083 and t0, t1, t0
3084 bnez t0, syscall_trace_entry
3085diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3086index 6be6f70..1859577 100644
3087--- a/arch/mips/kernel/scall64-n32.S
3088+++ b/arch/mips/kernel/scall64-n32.S
3089@@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3090
3091 sd a3, PT_R26(sp) # save a3 for syscall restarting
3092
3093- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3094+ li t1, _TIF_SYSCALL_WORK
3095 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3096 and t0, t1, t0
3097 bnez t0, n32_syscall_trace_entry
3098diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3099index 5422855..74e63a3 100644
3100--- a/arch/mips/kernel/scall64-o32.S
3101+++ b/arch/mips/kernel/scall64-o32.S
3102@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3103 PTR 4b, bad_stack
3104 .previous
3105
3106- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3107+ li t1, _TIF_SYSCALL_WORK
3108 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3109 and t0, t1, t0
3110 bnez t0, trace_a_syscall
3111diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3112index c14f6df..537e729 100644
3113--- a/arch/mips/mm/fault.c
3114+++ b/arch/mips/mm/fault.c
3115@@ -27,6 +27,23 @@
3116 #include <asm/highmem.h> /* For VMALLOC_END */
3117 #include <linux/kdebug.h>
3118
3119+#ifdef CONFIG_PAX_PAGEEXEC
3120+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3121+{
3122+ unsigned long i;
3123+
3124+ printk(KERN_ERR "PAX: bytes at PC: ");
3125+ for (i = 0; i < 5; i++) {
3126+ unsigned int c;
3127+ if (get_user(c, (unsigned int *)pc+i))
3128+ printk(KERN_CONT "???????? ");
3129+ else
3130+ printk(KERN_CONT "%08x ", c);
3131+ }
3132+ printk("\n");
3133+}
3134+#endif
3135+
3136 /*
3137 * This routine handles page faults. It determines the address,
3138 * and the problem, and then passes it off to one of the appropriate
3139diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3140index 302d779..7d35bf8 100644
3141--- a/arch/mips/mm/mmap.c
3142+++ b/arch/mips/mm/mmap.c
3143@@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3144 do_color_align = 1;
3145
3146 /* requesting a specific address */
3147+
3148+#ifdef CONFIG_PAX_RANDMMAP
3149+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3150+#endif
3151+
3152 if (addr) {
3153 if (do_color_align)
3154 addr = COLOUR_ALIGN(addr, pgoff);
3155@@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3156 addr = PAGE_ALIGN(addr);
3157
3158 vma = find_vma(mm, addr);
3159- if (TASK_SIZE - len >= addr &&
3160- (!vma || addr + len <= vma->vm_start))
3161+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3162 return addr;
3163 }
3164
3165@@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3166 /* At this point: (!vma || addr < vma->vm_end). */
3167 if (TASK_SIZE - len < addr)
3168 return -ENOMEM;
3169- if (!vma || addr + len <= vma->vm_start)
3170+ if (check_heap_stack_gap(vmm, addr, len))
3171 return addr;
3172 addr = vma->vm_end;
3173 if (do_color_align)
3174@@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3175 /* make sure it can fit in the remaining address space */
3176 if (likely(addr > len)) {
3177 vma = find_vma(mm, addr - len);
3178- if (!vma || addr <= vma->vm_start) {
3179+ if (check_heap_stack_gap(vmm, addr - len, len))
3180 /* cache the address as a hint for next time */
3181 return mm->free_area_cache = addr - len;
3182 }
3183@@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3184 * return with success:
3185 */
3186 vma = find_vma(mm, addr);
3187- if (likely(!vma || addr + len <= vma->vm_start)) {
3188+ if (check_heap_stack_gap(vmm, addr, len)) {
3189 /* cache the address as a hint for next time */
3190 return mm->free_area_cache = addr;
3191 }
3192@@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3193 mm->unmap_area = arch_unmap_area_topdown;
3194 }
3195 }
3196-
3197-static inline unsigned long brk_rnd(void)
3198-{
3199- unsigned long rnd = get_random_int();
3200-
3201- rnd = rnd << PAGE_SHIFT;
3202- /* 8MB for 32bit, 256MB for 64bit */
3203- if (TASK_IS_32BIT_ADDR)
3204- rnd = rnd & 0x7ffffful;
3205- else
3206- rnd = rnd & 0xffffffful;
3207-
3208- return rnd;
3209-}
3210-
3211-unsigned long arch_randomize_brk(struct mm_struct *mm)
3212-{
3213- unsigned long base = mm->brk;
3214- unsigned long ret;
3215-
3216- ret = PAGE_ALIGN(base + brk_rnd());
3217-
3218- if (ret < mm->brk)
3219- return mm->brk;
3220-
3221- return ret;
3222-}
3223diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3224index 967d144..db12197 100644
3225--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3226+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3227@@ -11,12 +11,14 @@
3228 #ifndef _ASM_PROC_CACHE_H
3229 #define _ASM_PROC_CACHE_H
3230
3231+#include <linux/const.h>
3232+
3233 /* L1 cache */
3234
3235 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3236 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3237-#define L1_CACHE_BYTES 16 /* bytes per entry */
3238 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3239+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3240 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3241
3242 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3243diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3244index bcb5df2..84fabd2 100644
3245--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3246+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3247@@ -16,13 +16,15 @@
3248 #ifndef _ASM_PROC_CACHE_H
3249 #define _ASM_PROC_CACHE_H
3250
3251+#include <linux/const.h>
3252+
3253 /*
3254 * L1 cache
3255 */
3256 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3257 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3258-#define L1_CACHE_BYTES 32 /* bytes per entry */
3259 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3260+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3261 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3262
3263 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3264diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3265index 4ce7a01..449202a 100644
3266--- a/arch/openrisc/include/asm/cache.h
3267+++ b/arch/openrisc/include/asm/cache.h
3268@@ -19,11 +19,13 @@
3269 #ifndef __ASM_OPENRISC_CACHE_H
3270 #define __ASM_OPENRISC_CACHE_H
3271
3272+#include <linux/const.h>
3273+
3274 /* FIXME: How can we replace these with values from the CPU...
3275 * they shouldn't be hard-coded!
3276 */
3277
3278-#define L1_CACHE_BYTES 16
3279 #define L1_CACHE_SHIFT 4
3280+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3281
3282 #endif /* __ASM_OPENRISC_CACHE_H */
3283diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3284index 6c6defc..d30653d 100644
3285--- a/arch/parisc/include/asm/atomic.h
3286+++ b/arch/parisc/include/asm/atomic.h
3287@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3288
3289 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3290
3291+#define atomic64_read_unchecked(v) atomic64_read(v)
3292+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3293+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3294+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3295+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3296+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3297+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3298+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3299+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3300+
3301 #endif /* !CONFIG_64BIT */
3302
3303
3304diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3305index 47f11c7..3420df2 100644
3306--- a/arch/parisc/include/asm/cache.h
3307+++ b/arch/parisc/include/asm/cache.h
3308@@ -5,6 +5,7 @@
3309 #ifndef __ARCH_PARISC_CACHE_H
3310 #define __ARCH_PARISC_CACHE_H
3311
3312+#include <linux/const.h>
3313
3314 /*
3315 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3316@@ -15,13 +16,13 @@
3317 * just ruin performance.
3318 */
3319 #ifdef CONFIG_PA20
3320-#define L1_CACHE_BYTES 64
3321 #define L1_CACHE_SHIFT 6
3322 #else
3323-#define L1_CACHE_BYTES 32
3324 #define L1_CACHE_SHIFT 5
3325 #endif
3326
3327+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3328+
3329 #ifndef __ASSEMBLY__
3330
3331 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3332diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3333index 19f6cb1..6c78cf2 100644
3334--- a/arch/parisc/include/asm/elf.h
3335+++ b/arch/parisc/include/asm/elf.h
3336@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3337
3338 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3339
3340+#ifdef CONFIG_PAX_ASLR
3341+#define PAX_ELF_ET_DYN_BASE 0x10000UL
3342+
3343+#define PAX_DELTA_MMAP_LEN 16
3344+#define PAX_DELTA_STACK_LEN 16
3345+#endif
3346+
3347 /* This yields a mask that user programs can use to figure out what
3348 instruction set this CPU supports. This could be done in user space,
3349 but it's not easy, and we've already done it here. */
3350diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3351index fc987a1..6e068ef 100644
3352--- a/arch/parisc/include/asm/pgalloc.h
3353+++ b/arch/parisc/include/asm/pgalloc.h
3354@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3355 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3356 }
3357
3358+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3359+{
3360+ pgd_populate(mm, pgd, pmd);
3361+}
3362+
3363 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3364 {
3365 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3366@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3367 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3368 #define pmd_free(mm, x) do { } while (0)
3369 #define pgd_populate(mm, pmd, pte) BUG()
3370+#define pgd_populate_kernel(mm, pmd, pte) BUG()
3371
3372 #endif
3373
3374diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3375index ee99f23..802b0a1 100644
3376--- a/arch/parisc/include/asm/pgtable.h
3377+++ b/arch/parisc/include/asm/pgtable.h
3378@@ -212,6 +212,17 @@ struct vm_area_struct;
3379 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3380 #define PAGE_COPY PAGE_EXECREAD
3381 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3382+
3383+#ifdef CONFIG_PAX_PAGEEXEC
3384+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3385+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3386+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3387+#else
3388+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3389+# define PAGE_COPY_NOEXEC PAGE_COPY
3390+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3391+#endif
3392+
3393 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3394 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3395 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3396diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3397index 9ac0660..6ed15c4 100644
3398--- a/arch/parisc/include/asm/uaccess.h
3399+++ b/arch/parisc/include/asm/uaccess.h
3400@@ -252,10 +252,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3401 const void __user *from,
3402 unsigned long n)
3403 {
3404- int sz = __compiletime_object_size(to);
3405+ size_t sz = __compiletime_object_size(to);
3406 int ret = -EFAULT;
3407
3408- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3409+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3410 ret = __copy_from_user(to, from, n);
3411 else
3412 copy_from_user_overflow();
3413diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3414index 5e34ccf..672bc9c 100644
3415--- a/arch/parisc/kernel/module.c
3416+++ b/arch/parisc/kernel/module.c
3417@@ -98,16 +98,38 @@
3418
3419 /* three functions to determine where in the module core
3420 * or init pieces the location is */
3421+static inline int in_init_rx(struct module *me, void *loc)
3422+{
3423+ return (loc >= me->module_init_rx &&
3424+ loc < (me->module_init_rx + me->init_size_rx));
3425+}
3426+
3427+static inline int in_init_rw(struct module *me, void *loc)
3428+{
3429+ return (loc >= me->module_init_rw &&
3430+ loc < (me->module_init_rw + me->init_size_rw));
3431+}
3432+
3433 static inline int in_init(struct module *me, void *loc)
3434 {
3435- return (loc >= me->module_init &&
3436- loc <= (me->module_init + me->init_size));
3437+ return in_init_rx(me, loc) || in_init_rw(me, loc);
3438+}
3439+
3440+static inline int in_core_rx(struct module *me, void *loc)
3441+{
3442+ return (loc >= me->module_core_rx &&
3443+ loc < (me->module_core_rx + me->core_size_rx));
3444+}
3445+
3446+static inline int in_core_rw(struct module *me, void *loc)
3447+{
3448+ return (loc >= me->module_core_rw &&
3449+ loc < (me->module_core_rw + me->core_size_rw));
3450 }
3451
3452 static inline int in_core(struct module *me, void *loc)
3453 {
3454- return (loc >= me->module_core &&
3455- loc <= (me->module_core + me->core_size));
3456+ return in_core_rx(me, loc) || in_core_rw(me, loc);
3457 }
3458
3459 static inline int in_local(struct module *me, void *loc)
3460@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3461 }
3462
3463 /* align things a bit */
3464- me->core_size = ALIGN(me->core_size, 16);
3465- me->arch.got_offset = me->core_size;
3466- me->core_size += gots * sizeof(struct got_entry);
3467+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3468+ me->arch.got_offset = me->core_size_rw;
3469+ me->core_size_rw += gots * sizeof(struct got_entry);
3470
3471- me->core_size = ALIGN(me->core_size, 16);
3472- me->arch.fdesc_offset = me->core_size;
3473- me->core_size += fdescs * sizeof(Elf_Fdesc);
3474+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3475+ me->arch.fdesc_offset = me->core_size_rw;
3476+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3477
3478 me->arch.got_max = gots;
3479 me->arch.fdesc_max = fdescs;
3480@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3481
3482 BUG_ON(value == 0);
3483
3484- got = me->module_core + me->arch.got_offset;
3485+ got = me->module_core_rw + me->arch.got_offset;
3486 for (i = 0; got[i].addr; i++)
3487 if (got[i].addr == value)
3488 goto out;
3489@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3490 #ifdef CONFIG_64BIT
3491 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3492 {
3493- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3494+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3495
3496 if (!value) {
3497 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3498@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3499
3500 /* Create new one */
3501 fdesc->addr = value;
3502- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3503+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3504 return (Elf_Addr)fdesc;
3505 }
3506 #endif /* CONFIG_64BIT */
3507@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3508
3509 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3510 end = table + sechdrs[me->arch.unwind_section].sh_size;
3511- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3512+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3513
3514 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3515 me->arch.unwind_section, table, end, gp);
3516diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3517index c9b9322..02d8940 100644
3518--- a/arch/parisc/kernel/sys_parisc.c
3519+++ b/arch/parisc/kernel/sys_parisc.c
3520@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3521 /* At this point: (!vma || addr < vma->vm_end). */
3522 if (TASK_SIZE - len < addr)
3523 return -ENOMEM;
3524- if (!vma || addr + len <= vma->vm_start)
3525+ if (check_heap_stack_gap(vma, addr, len))
3526 return addr;
3527 addr = vma->vm_end;
3528 }
3529@@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3530 /* At this point: (!vma || addr < vma->vm_end). */
3531 if (TASK_SIZE - len < addr)
3532 return -ENOMEM;
3533- if (!vma || addr + len <= vma->vm_start)
3534+ if (check_heap_stack_gap(vma, addr, len))
3535 return addr;
3536 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3537 if (addr < vma->vm_end) /* handle wraparound */
3538@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3539 if (flags & MAP_FIXED)
3540 return addr;
3541 if (!addr)
3542- addr = TASK_UNMAPPED_BASE;
3543+ addr = current->mm->mmap_base;
3544
3545 if (filp) {
3546 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3547diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3548index 45ba99f..8e22c33 100644
3549--- a/arch/parisc/kernel/traps.c
3550+++ b/arch/parisc/kernel/traps.c
3551@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3552
3553 down_read(&current->mm->mmap_sem);
3554 vma = find_vma(current->mm,regs->iaoq[0]);
3555- if (vma && (regs->iaoq[0] >= vma->vm_start)
3556- && (vma->vm_flags & VM_EXEC)) {
3557-
3558+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3559 fault_address = regs->iaoq[0];
3560 fault_space = regs->iasq[0];
3561
3562diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3563index 18162ce..94de376 100644
3564--- a/arch/parisc/mm/fault.c
3565+++ b/arch/parisc/mm/fault.c
3566@@ -15,6 +15,7 @@
3567 #include <linux/sched.h>
3568 #include <linux/interrupt.h>
3569 #include <linux/module.h>
3570+#include <linux/unistd.h>
3571
3572 #include <asm/uaccess.h>
3573 #include <asm/traps.h>
3574@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3575 static unsigned long
3576 parisc_acctyp(unsigned long code, unsigned int inst)
3577 {
3578- if (code == 6 || code == 16)
3579+ if (code == 6 || code == 7 || code == 16)
3580 return VM_EXEC;
3581
3582 switch (inst & 0xf0000000) {
3583@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3584 }
3585 #endif
3586
3587+#ifdef CONFIG_PAX_PAGEEXEC
3588+/*
3589+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3590+ *
3591+ * returns 1 when task should be killed
3592+ * 2 when rt_sigreturn trampoline was detected
3593+ * 3 when unpatched PLT trampoline was detected
3594+ */
3595+static int pax_handle_fetch_fault(struct pt_regs *regs)
3596+{
3597+
3598+#ifdef CONFIG_PAX_EMUPLT
3599+ int err;
3600+
3601+ do { /* PaX: unpatched PLT emulation */
3602+ unsigned int bl, depwi;
3603+
3604+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3605+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3606+
3607+ if (err)
3608+ break;
3609+
3610+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3611+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3612+
3613+ err = get_user(ldw, (unsigned int *)addr);
3614+ err |= get_user(bv, (unsigned int *)(addr+4));
3615+ err |= get_user(ldw2, (unsigned int *)(addr+8));
3616+
3617+ if (err)
3618+ break;
3619+
3620+ if (ldw == 0x0E801096U &&
3621+ bv == 0xEAC0C000U &&
3622+ ldw2 == 0x0E881095U)
3623+ {
3624+ unsigned int resolver, map;
3625+
3626+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3627+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3628+ if (err)
3629+ break;
3630+
3631+ regs->gr[20] = instruction_pointer(regs)+8;
3632+ regs->gr[21] = map;
3633+ regs->gr[22] = resolver;
3634+ regs->iaoq[0] = resolver | 3UL;
3635+ regs->iaoq[1] = regs->iaoq[0] + 4;
3636+ return 3;
3637+ }
3638+ }
3639+ } while (0);
3640+#endif
3641+
3642+#ifdef CONFIG_PAX_EMUTRAMP
3643+
3644+#ifndef CONFIG_PAX_EMUSIGRT
3645+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3646+ return 1;
3647+#endif
3648+
3649+ do { /* PaX: rt_sigreturn emulation */
3650+ unsigned int ldi1, ldi2, bel, nop;
3651+
3652+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3653+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3654+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3655+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3656+
3657+ if (err)
3658+ break;
3659+
3660+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3661+ ldi2 == 0x3414015AU &&
3662+ bel == 0xE4008200U &&
3663+ nop == 0x08000240U)
3664+ {
3665+ regs->gr[25] = (ldi1 & 2) >> 1;
3666+ regs->gr[20] = __NR_rt_sigreturn;
3667+ regs->gr[31] = regs->iaoq[1] + 16;
3668+ regs->sr[0] = regs->iasq[1];
3669+ regs->iaoq[0] = 0x100UL;
3670+ regs->iaoq[1] = regs->iaoq[0] + 4;
3671+ regs->iasq[0] = regs->sr[2];
3672+ regs->iasq[1] = regs->sr[2];
3673+ return 2;
3674+ }
3675+ } while (0);
3676+#endif
3677+
3678+ return 1;
3679+}
3680+
3681+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3682+{
3683+ unsigned long i;
3684+
3685+ printk(KERN_ERR "PAX: bytes at PC: ");
3686+ for (i = 0; i < 5; i++) {
3687+ unsigned int c;
3688+ if (get_user(c, (unsigned int *)pc+i))
3689+ printk(KERN_CONT "???????? ");
3690+ else
3691+ printk(KERN_CONT "%08x ", c);
3692+ }
3693+ printk("\n");
3694+}
3695+#endif
3696+
3697 int fixup_exception(struct pt_regs *regs)
3698 {
3699 const struct exception_table_entry *fix;
3700@@ -192,8 +303,33 @@ good_area:
3701
3702 acc_type = parisc_acctyp(code,regs->iir);
3703
3704- if ((vma->vm_flags & acc_type) != acc_type)
3705+ if ((vma->vm_flags & acc_type) != acc_type) {
3706+
3707+#ifdef CONFIG_PAX_PAGEEXEC
3708+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3709+ (address & ~3UL) == instruction_pointer(regs))
3710+ {
3711+ up_read(&mm->mmap_sem);
3712+ switch (pax_handle_fetch_fault(regs)) {
3713+
3714+#ifdef CONFIG_PAX_EMUPLT
3715+ case 3:
3716+ return;
3717+#endif
3718+
3719+#ifdef CONFIG_PAX_EMUTRAMP
3720+ case 2:
3721+ return;
3722+#endif
3723+
3724+ }
3725+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3726+ do_group_exit(SIGKILL);
3727+ }
3728+#endif
3729+
3730 goto bad_area;
3731+ }
3732
3733 /*
3734 * If for any reason at all we couldn't handle the fault, make
3735diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3736index da29032..f76c24c 100644
3737--- a/arch/powerpc/include/asm/atomic.h
3738+++ b/arch/powerpc/include/asm/atomic.h
3739@@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3740 return t1;
3741 }
3742
3743+#define atomic64_read_unchecked(v) atomic64_read(v)
3744+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3745+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3746+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3747+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3748+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3749+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3750+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3751+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3752+
3753 #endif /* __powerpc64__ */
3754
3755 #endif /* __KERNEL__ */
3756diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3757index 9e495c9..b6878e5 100644
3758--- a/arch/powerpc/include/asm/cache.h
3759+++ b/arch/powerpc/include/asm/cache.h
3760@@ -3,6 +3,7 @@
3761
3762 #ifdef __KERNEL__
3763
3764+#include <linux/const.h>
3765
3766 /* bytes per L1 cache line */
3767 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3768@@ -22,7 +23,7 @@
3769 #define L1_CACHE_SHIFT 7
3770 #endif
3771
3772-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3773+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3774
3775 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3776
3777diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3778index 3bf9cca..e7457d0 100644
3779--- a/arch/powerpc/include/asm/elf.h
3780+++ b/arch/powerpc/include/asm/elf.h
3781@@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3782 the loader. We need to make sure that it is out of the way of the program
3783 that it will "exec", and that there is sufficient room for the brk. */
3784
3785-extern unsigned long randomize_et_dyn(unsigned long base);
3786-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3787+#define ELF_ET_DYN_BASE (0x20000000)
3788+
3789+#ifdef CONFIG_PAX_ASLR
3790+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3791+
3792+#ifdef __powerpc64__
3793+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3794+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3795+#else
3796+#define PAX_DELTA_MMAP_LEN 15
3797+#define PAX_DELTA_STACK_LEN 15
3798+#endif
3799+#endif
3800
3801 /*
3802 * Our registers are always unsigned longs, whether we're a 32 bit
3803@@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3804 (0x7ff >> (PAGE_SHIFT - 12)) : \
3805 (0x3ffff >> (PAGE_SHIFT - 12)))
3806
3807-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3808-#define arch_randomize_brk arch_randomize_brk
3809-
3810 #endif /* __KERNEL__ */
3811
3812 /*
3813diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3814index 8196e9c..d83a9f3 100644
3815--- a/arch/powerpc/include/asm/exec.h
3816+++ b/arch/powerpc/include/asm/exec.h
3817@@ -4,6 +4,6 @@
3818 #ifndef _ASM_POWERPC_EXEC_H
3819 #define _ASM_POWERPC_EXEC_H
3820
3821-extern unsigned long arch_align_stack(unsigned long sp);
3822+#define arch_align_stack(x) ((x) & ~0xfUL)
3823
3824 #endif /* _ASM_POWERPC_EXEC_H */
3825diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3826index bca8fdc..61e9580 100644
3827--- a/arch/powerpc/include/asm/kmap_types.h
3828+++ b/arch/powerpc/include/asm/kmap_types.h
3829@@ -27,6 +27,7 @@ enum km_type {
3830 KM_PPC_SYNC_PAGE,
3831 KM_PPC_SYNC_ICACHE,
3832 KM_KDB,
3833+ KM_CLEARPAGE,
3834 KM_TYPE_NR
3835 };
3836
3837diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3838index d4a7f64..451de1c 100644
3839--- a/arch/powerpc/include/asm/mman.h
3840+++ b/arch/powerpc/include/asm/mman.h
3841@@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3842 }
3843 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3844
3845-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3846+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3847 {
3848 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3849 }
3850diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3851index f072e97..b436dee 100644
3852--- a/arch/powerpc/include/asm/page.h
3853+++ b/arch/powerpc/include/asm/page.h
3854@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3855 * and needs to be executable. This means the whole heap ends
3856 * up being executable.
3857 */
3858-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3859- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3860+#define VM_DATA_DEFAULT_FLAGS32 \
3861+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3862+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3863
3864 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3865 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3866@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3867 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3868 #endif
3869
3870+#define ktla_ktva(addr) (addr)
3871+#define ktva_ktla(addr) (addr)
3872+
3873 /*
3874 * Use the top bit of the higher-level page table entries to indicate whether
3875 * the entries we point to contain hugepages. This works because we know that
3876diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3877index fed85e6..da5c71b 100644
3878--- a/arch/powerpc/include/asm/page_64.h
3879+++ b/arch/powerpc/include/asm/page_64.h
3880@@ -146,15 +146,18 @@ do { \
3881 * stack by default, so in the absence of a PT_GNU_STACK program header
3882 * we turn execute permission off.
3883 */
3884-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3885- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3886+#define VM_STACK_DEFAULT_FLAGS32 \
3887+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3888+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3889
3890 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3891 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3892
3893+#ifndef CONFIG_PAX_PAGEEXEC
3894 #define VM_STACK_DEFAULT_FLAGS \
3895 (is_32bit_task() ? \
3896 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3897+#endif
3898
3899 #include <asm-generic/getorder.h>
3900
3901diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3902index 292725c..f87ae14 100644
3903--- a/arch/powerpc/include/asm/pgalloc-64.h
3904+++ b/arch/powerpc/include/asm/pgalloc-64.h
3905@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3906 #ifndef CONFIG_PPC_64K_PAGES
3907
3908 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3909+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3910
3911 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3912 {
3913@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3914 pud_set(pud, (unsigned long)pmd);
3915 }
3916
3917+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3918+{
3919+ pud_populate(mm, pud, pmd);
3920+}
3921+
3922 #define pmd_populate(mm, pmd, pte_page) \
3923 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3924 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3925@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3926 #else /* CONFIG_PPC_64K_PAGES */
3927
3928 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3929+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3930
3931 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3932 pte_t *pte)
3933diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3934index 2e0e411..7899c68 100644
3935--- a/arch/powerpc/include/asm/pgtable.h
3936+++ b/arch/powerpc/include/asm/pgtable.h
3937@@ -2,6 +2,7 @@
3938 #define _ASM_POWERPC_PGTABLE_H
3939 #ifdef __KERNEL__
3940
3941+#include <linux/const.h>
3942 #ifndef __ASSEMBLY__
3943 #include <asm/processor.h> /* For TASK_SIZE */
3944 #include <asm/mmu.h>
3945diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3946index 4aad413..85d86bf 100644
3947--- a/arch/powerpc/include/asm/pte-hash32.h
3948+++ b/arch/powerpc/include/asm/pte-hash32.h
3949@@ -21,6 +21,7 @@
3950 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3951 #define _PAGE_USER 0x004 /* usermode access allowed */
3952 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3953+#define _PAGE_EXEC _PAGE_GUARDED
3954 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3955 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3956 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3957diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3958index 9d7f0fb..a28fe69 100644
3959--- a/arch/powerpc/include/asm/reg.h
3960+++ b/arch/powerpc/include/asm/reg.h
3961@@ -212,6 +212,7 @@
3962 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3963 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3964 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3965+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3966 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3967 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3968 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3969diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3970index 4a741c7..c8162227b 100644
3971--- a/arch/powerpc/include/asm/thread_info.h
3972+++ b/arch/powerpc/include/asm/thread_info.h
3973@@ -104,12 +104,14 @@ static inline struct thread_info *current_thread_info(void)
3974 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3975 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3976 #define TIF_SINGLESTEP 8 /* singlestepping active */
3977-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3978 #define TIF_SECCOMP 10 /* secure computing */
3979 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3980 #define TIF_NOERROR 12 /* Force successful syscall return */
3981 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3982 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3983+#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3984+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3985+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3986
3987 /* as above, but as bit values */
3988 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3989@@ -127,8 +129,11 @@ static inline struct thread_info *current_thread_info(void)
3990 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3991 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3992 #define _TIF_RUNLATCH (1<<TIF_RUNLATCH)
3993+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3994+
3995 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3996- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3997+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT \
3998+ _TIF_GRSEC_SETXID)
3999
4000 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
4001 _TIF_NOTIFY_RESUME)
4002diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
4003index bd0fb84..a42a14b 100644
4004--- a/arch/powerpc/include/asm/uaccess.h
4005+++ b/arch/powerpc/include/asm/uaccess.h
4006@@ -13,6 +13,8 @@
4007 #define VERIFY_READ 0
4008 #define VERIFY_WRITE 1
4009
4010+extern void check_object_size(const void *ptr, unsigned long n, bool to);
4011+
4012 /*
4013 * The fs value determines whether argument validity checking should be
4014 * performed or not. If get_fs() == USER_DS, checking is performed, with
4015@@ -327,52 +329,6 @@ do { \
4016 extern unsigned long __copy_tofrom_user(void __user *to,
4017 const void __user *from, unsigned long size);
4018
4019-#ifndef __powerpc64__
4020-
4021-static inline unsigned long copy_from_user(void *to,
4022- const void __user *from, unsigned long n)
4023-{
4024- unsigned long over;
4025-
4026- if (access_ok(VERIFY_READ, from, n))
4027- return __copy_tofrom_user((__force void __user *)to, from, n);
4028- if ((unsigned long)from < TASK_SIZE) {
4029- over = (unsigned long)from + n - TASK_SIZE;
4030- return __copy_tofrom_user((__force void __user *)to, from,
4031- n - over) + over;
4032- }
4033- return n;
4034-}
4035-
4036-static inline unsigned long copy_to_user(void __user *to,
4037- const void *from, unsigned long n)
4038-{
4039- unsigned long over;
4040-
4041- if (access_ok(VERIFY_WRITE, to, n))
4042- return __copy_tofrom_user(to, (__force void __user *)from, n);
4043- if ((unsigned long)to < TASK_SIZE) {
4044- over = (unsigned long)to + n - TASK_SIZE;
4045- return __copy_tofrom_user(to, (__force void __user *)from,
4046- n - over) + over;
4047- }
4048- return n;
4049-}
4050-
4051-#else /* __powerpc64__ */
4052-
4053-#define __copy_in_user(to, from, size) \
4054- __copy_tofrom_user((to), (from), (size))
4055-
4056-extern unsigned long copy_from_user(void *to, const void __user *from,
4057- unsigned long n);
4058-extern unsigned long copy_to_user(void __user *to, const void *from,
4059- unsigned long n);
4060-extern unsigned long copy_in_user(void __user *to, const void __user *from,
4061- unsigned long n);
4062-
4063-#endif /* __powerpc64__ */
4064-
4065 static inline unsigned long __copy_from_user_inatomic(void *to,
4066 const void __user *from, unsigned long n)
4067 {
4068@@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4069 if (ret == 0)
4070 return 0;
4071 }
4072+
4073+ if (!__builtin_constant_p(n))
4074+ check_object_size(to, n, false);
4075+
4076 return __copy_tofrom_user((__force void __user *)to, from, n);
4077 }
4078
4079@@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4080 if (ret == 0)
4081 return 0;
4082 }
4083+
4084+ if (!__builtin_constant_p(n))
4085+ check_object_size(from, n, true);
4086+
4087 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4088 }
4089
4090@@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4091 return __copy_to_user_inatomic(to, from, size);
4092 }
4093
4094+#ifndef __powerpc64__
4095+
4096+static inline unsigned long __must_check copy_from_user(void *to,
4097+ const void __user *from, unsigned long n)
4098+{
4099+ unsigned long over;
4100+
4101+ if ((long)n < 0)
4102+ return n;
4103+
4104+ if (access_ok(VERIFY_READ, from, n)) {
4105+ if (!__builtin_constant_p(n))
4106+ check_object_size(to, n, false);
4107+ return __copy_tofrom_user((__force void __user *)to, from, n);
4108+ }
4109+ if ((unsigned long)from < TASK_SIZE) {
4110+ over = (unsigned long)from + n - TASK_SIZE;
4111+ if (!__builtin_constant_p(n - over))
4112+ check_object_size(to, n - over, false);
4113+ return __copy_tofrom_user((__force void __user *)to, from,
4114+ n - over) + over;
4115+ }
4116+ return n;
4117+}
4118+
4119+static inline unsigned long __must_check copy_to_user(void __user *to,
4120+ const void *from, unsigned long n)
4121+{
4122+ unsigned long over;
4123+
4124+ if ((long)n < 0)
4125+ return n;
4126+
4127+ if (access_ok(VERIFY_WRITE, to, n)) {
4128+ if (!__builtin_constant_p(n))
4129+ check_object_size(from, n, true);
4130+ return __copy_tofrom_user(to, (__force void __user *)from, n);
4131+ }
4132+ if ((unsigned long)to < TASK_SIZE) {
4133+ over = (unsigned long)to + n - TASK_SIZE;
4134+ if (!__builtin_constant_p(n))
4135+ check_object_size(from, n - over, true);
4136+ return __copy_tofrom_user(to, (__force void __user *)from,
4137+ n - over) + over;
4138+ }
4139+ return n;
4140+}
4141+
4142+#else /* __powerpc64__ */
4143+
4144+#define __copy_in_user(to, from, size) \
4145+ __copy_tofrom_user((to), (from), (size))
4146+
4147+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4148+{
4149+ if ((long)n < 0 || n > INT_MAX)
4150+ return n;
4151+
4152+ if (!__builtin_constant_p(n))
4153+ check_object_size(to, n, false);
4154+
4155+ if (likely(access_ok(VERIFY_READ, from, n)))
4156+ n = __copy_from_user(to, from, n);
4157+ else
4158+ memset(to, 0, n);
4159+ return n;
4160+}
4161+
4162+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4163+{
4164+ if ((long)n < 0 || n > INT_MAX)
4165+ return n;
4166+
4167+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
4168+ if (!__builtin_constant_p(n))
4169+ check_object_size(from, n, true);
4170+ n = __copy_to_user(to, from, n);
4171+ }
4172+ return n;
4173+}
4174+
4175+extern unsigned long copy_in_user(void __user *to, const void __user *from,
4176+ unsigned long n);
4177+
4178+#endif /* __powerpc64__ */
4179+
4180 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4181
4182 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4183diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4184index 7215cc2..a9730c1 100644
4185--- a/arch/powerpc/kernel/exceptions-64e.S
4186+++ b/arch/powerpc/kernel/exceptions-64e.S
4187@@ -661,6 +661,7 @@ storage_fault_common:
4188 std r14,_DAR(r1)
4189 std r15,_DSISR(r1)
4190 addi r3,r1,STACK_FRAME_OVERHEAD
4191+ bl .save_nvgprs
4192 mr r4,r14
4193 mr r5,r15
4194 ld r14,PACA_EXGEN+EX_R14(r13)
4195@@ -669,8 +670,7 @@ storage_fault_common:
4196 cmpdi r3,0
4197 bne- 1f
4198 b .ret_from_except_lite
4199-1: bl .save_nvgprs
4200- mr r5,r3
4201+1: mr r5,r3
4202 addi r3,r1,STACK_FRAME_OVERHEAD
4203 ld r4,_DAR(r1)
4204 bl .bad_page_fault
4205diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4206index 8f880bc..c5bd2f3 100644
4207--- a/arch/powerpc/kernel/exceptions-64s.S
4208+++ b/arch/powerpc/kernel/exceptions-64s.S
4209@@ -890,10 +890,10 @@ handle_page_fault:
4210 11: ld r4,_DAR(r1)
4211 ld r5,_DSISR(r1)
4212 addi r3,r1,STACK_FRAME_OVERHEAD
4213+ bl .save_nvgprs
4214 bl .do_page_fault
4215 cmpdi r3,0
4216 beq+ 12f
4217- bl .save_nvgprs
4218 mr r5,r3
4219 addi r3,r1,STACK_FRAME_OVERHEAD
4220 lwz r4,_DAR(r1)
4221diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4222index 2e3200c..72095ce 100644
4223--- a/arch/powerpc/kernel/module_32.c
4224+++ b/arch/powerpc/kernel/module_32.c
4225@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4226 me->arch.core_plt_section = i;
4227 }
4228 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4229- printk("Module doesn't contain .plt or .init.plt sections.\n");
4230+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4231 return -ENOEXEC;
4232 }
4233
4234@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4235
4236 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4237 /* Init, or core PLT? */
4238- if (location >= mod->module_core
4239- && location < mod->module_core + mod->core_size)
4240+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4241+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4242 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4243- else
4244+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4245+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4246 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4247+ else {
4248+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4249+ return ~0UL;
4250+ }
4251
4252 /* Find this entry, or if that fails, the next avail. entry */
4253 while (entry->jump[0]) {
4254diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4255index 4937c96..70714b7 100644
4256--- a/arch/powerpc/kernel/process.c
4257+++ b/arch/powerpc/kernel/process.c
4258@@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4259 * Lookup NIP late so we have the best change of getting the
4260 * above info out without failing
4261 */
4262- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4263- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4264+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4265+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4266 #endif
4267 show_stack(current, (unsigned long *) regs->gpr[1]);
4268 if (!user_mode(regs))
4269@@ -1186,10 +1186,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4270 newsp = stack[0];
4271 ip = stack[STACK_FRAME_LR_SAVE];
4272 if (!firstframe || ip != lr) {
4273- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4274+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4275 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4276 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4277- printk(" (%pS)",
4278+ printk(" (%pA)",
4279 (void *)current->ret_stack[curr_frame].ret);
4280 curr_frame--;
4281 }
4282@@ -1209,7 +1209,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4283 struct pt_regs *regs = (struct pt_regs *)
4284 (sp + STACK_FRAME_OVERHEAD);
4285 lr = regs->link;
4286- printk("--- Exception: %lx at %pS\n LR = %pS\n",
4287+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
4288 regs->trap, (void *)regs->nip, (void *)lr);
4289 firstframe = 1;
4290 }
4291@@ -1282,58 +1282,3 @@ void thread_info_cache_init(void)
4292 }
4293
4294 #endif /* THREAD_SHIFT < PAGE_SHIFT */
4295-
4296-unsigned long arch_align_stack(unsigned long sp)
4297-{
4298- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4299- sp -= get_random_int() & ~PAGE_MASK;
4300- return sp & ~0xf;
4301-}
4302-
4303-static inline unsigned long brk_rnd(void)
4304-{
4305- unsigned long rnd = 0;
4306-
4307- /* 8MB for 32bit, 1GB for 64bit */
4308- if (is_32bit_task())
4309- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4310- else
4311- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4312-
4313- return rnd << PAGE_SHIFT;
4314-}
4315-
4316-unsigned long arch_randomize_brk(struct mm_struct *mm)
4317-{
4318- unsigned long base = mm->brk;
4319- unsigned long ret;
4320-
4321-#ifdef CONFIG_PPC_STD_MMU_64
4322- /*
4323- * If we are using 1TB segments and we are allowed to randomise
4324- * the heap, we can put it above 1TB so it is backed by a 1TB
4325- * segment. Otherwise the heap will be in the bottom 1TB
4326- * which always uses 256MB segments and this may result in a
4327- * performance penalty.
4328- */
4329- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4330- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4331-#endif
4332-
4333- ret = PAGE_ALIGN(base + brk_rnd());
4334-
4335- if (ret < mm->brk)
4336- return mm->brk;
4337-
4338- return ret;
4339-}
4340-
4341-unsigned long randomize_et_dyn(unsigned long base)
4342-{
4343- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4344-
4345- if (ret < base)
4346- return base;
4347-
4348- return ret;
4349-}
4350diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4351index 8d8e028..c2aeb50 100644
4352--- a/arch/powerpc/kernel/ptrace.c
4353+++ b/arch/powerpc/kernel/ptrace.c
4354@@ -1702,6 +1702,10 @@ long arch_ptrace(struct task_struct *child, long request,
4355 return ret;
4356 }
4357
4358+#ifdef CONFIG_GRKERNSEC_SETXID
4359+extern void gr_delayed_cred_worker(void);
4360+#endif
4361+
4362 /*
4363 * We must return the syscall number to actually look up in the table.
4364 * This can be -1L to skip running any syscall at all.
4365@@ -1712,6 +1716,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4366
4367 secure_computing(regs->gpr[0]);
4368
4369+#ifdef CONFIG_GRKERNSEC_SETXID
4370+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4371+ gr_delayed_cred_worker();
4372+#endif
4373+
4374 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4375 tracehook_report_syscall_entry(regs))
4376 /*
4377@@ -1746,6 +1755,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4378 {
4379 int step;
4380
4381+#ifdef CONFIG_GRKERNSEC_SETXID
4382+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4383+ gr_delayed_cred_worker();
4384+#endif
4385+
4386 audit_syscall_exit(regs);
4387
4388 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4389diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4390index 45eb998..0cb36bc 100644
4391--- a/arch/powerpc/kernel/signal_32.c
4392+++ b/arch/powerpc/kernel/signal_32.c
4393@@ -861,7 +861,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4394 /* Save user registers on the stack */
4395 frame = &rt_sf->uc.uc_mcontext;
4396 addr = frame;
4397- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4398+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4399 if (save_user_regs(regs, frame, 0, 1))
4400 goto badframe;
4401 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4402diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4403index 2692efd..6673d2e 100644
4404--- a/arch/powerpc/kernel/signal_64.c
4405+++ b/arch/powerpc/kernel/signal_64.c
4406@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4407 current->thread.fpscr.val = 0;
4408
4409 /* Set up to return from userspace. */
4410- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4411+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4412 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4413 } else {
4414 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4415diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4416index 1589723..cefe690 100644
4417--- a/arch/powerpc/kernel/traps.c
4418+++ b/arch/powerpc/kernel/traps.c
4419@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4420 return flags;
4421 }
4422
4423+extern void gr_handle_kernel_exploit(void);
4424+
4425 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4426 int signr)
4427 {
4428@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4429 panic("Fatal exception in interrupt");
4430 if (panic_on_oops)
4431 panic("Fatal exception");
4432+
4433+ gr_handle_kernel_exploit();
4434+
4435 do_exit(signr);
4436 }
4437
4438diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4439index 9eb5b9b..e45498a 100644
4440--- a/arch/powerpc/kernel/vdso.c
4441+++ b/arch/powerpc/kernel/vdso.c
4442@@ -34,6 +34,7 @@
4443 #include <asm/firmware.h>
4444 #include <asm/vdso.h>
4445 #include <asm/vdso_datapage.h>
4446+#include <asm/mman.h>
4447
4448 #include "setup.h"
4449
4450@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4451 vdso_base = VDSO32_MBASE;
4452 #endif
4453
4454- current->mm->context.vdso_base = 0;
4455+ current->mm->context.vdso_base = ~0UL;
4456
4457 /* vDSO has a problem and was disabled, just don't "enable" it for the
4458 * process
4459@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4460 vdso_base = get_unmapped_area(NULL, vdso_base,
4461 (vdso_pages << PAGE_SHIFT) +
4462 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4463- 0, 0);
4464+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
4465 if (IS_ERR_VALUE(vdso_base)) {
4466 rc = vdso_base;
4467 goto fail_mmapsem;
4468diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4469index 5eea6f3..5d10396 100644
4470--- a/arch/powerpc/lib/usercopy_64.c
4471+++ b/arch/powerpc/lib/usercopy_64.c
4472@@ -9,22 +9,6 @@
4473 #include <linux/module.h>
4474 #include <asm/uaccess.h>
4475
4476-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4477-{
4478- if (likely(access_ok(VERIFY_READ, from, n)))
4479- n = __copy_from_user(to, from, n);
4480- else
4481- memset(to, 0, n);
4482- return n;
4483-}
4484-
4485-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4486-{
4487- if (likely(access_ok(VERIFY_WRITE, to, n)))
4488- n = __copy_to_user(to, from, n);
4489- return n;
4490-}
4491-
4492 unsigned long copy_in_user(void __user *to, const void __user *from,
4493 unsigned long n)
4494 {
4495@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4496 return n;
4497 }
4498
4499-EXPORT_SYMBOL(copy_from_user);
4500-EXPORT_SYMBOL(copy_to_user);
4501 EXPORT_SYMBOL(copy_in_user);
4502
4503diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4504index 08ffcf5..a0ab912 100644
4505--- a/arch/powerpc/mm/fault.c
4506+++ b/arch/powerpc/mm/fault.c
4507@@ -32,6 +32,10 @@
4508 #include <linux/perf_event.h>
4509 #include <linux/magic.h>
4510 #include <linux/ratelimit.h>
4511+#include <linux/slab.h>
4512+#include <linux/pagemap.h>
4513+#include <linux/compiler.h>
4514+#include <linux/unistd.h>
4515
4516 #include <asm/firmware.h>
4517 #include <asm/page.h>
4518@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4519 }
4520 #endif
4521
4522+#ifdef CONFIG_PAX_PAGEEXEC
4523+/*
4524+ * PaX: decide what to do with offenders (regs->nip = fault address)
4525+ *
4526+ * returns 1 when task should be killed
4527+ */
4528+static int pax_handle_fetch_fault(struct pt_regs *regs)
4529+{
4530+ return 1;
4531+}
4532+
4533+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4534+{
4535+ unsigned long i;
4536+
4537+ printk(KERN_ERR "PAX: bytes at PC: ");
4538+ for (i = 0; i < 5; i++) {
4539+ unsigned int c;
4540+ if (get_user(c, (unsigned int __user *)pc+i))
4541+ printk(KERN_CONT "???????? ");
4542+ else
4543+ printk(KERN_CONT "%08x ", c);
4544+ }
4545+ printk("\n");
4546+}
4547+#endif
4548+
4549 /*
4550 * Check whether the instruction at regs->nip is a store using
4551 * an update addressing form which will update r1.
4552@@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4553 * indicate errors in DSISR but can validly be set in SRR1.
4554 */
4555 if (trap == 0x400)
4556- error_code &= 0x48200000;
4557+ error_code &= 0x58200000;
4558 else
4559 is_write = error_code & DSISR_ISSTORE;
4560 #else
4561@@ -366,7 +397,7 @@ good_area:
4562 * "undefined". Of those that can be set, this is the only
4563 * one which seems bad.
4564 */
4565- if (error_code & 0x10000000)
4566+ if (error_code & DSISR_GUARDED)
4567 /* Guarded storage error. */
4568 goto bad_area;
4569 #endif /* CONFIG_8xx */
4570@@ -381,7 +412,7 @@ good_area:
4571 * processors use the same I/D cache coherency mechanism
4572 * as embedded.
4573 */
4574- if (error_code & DSISR_PROTFAULT)
4575+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4576 goto bad_area;
4577 #endif /* CONFIG_PPC_STD_MMU */
4578
4579@@ -463,6 +494,23 @@ bad_area:
4580 bad_area_nosemaphore:
4581 /* User mode accesses cause a SIGSEGV */
4582 if (user_mode(regs)) {
4583+
4584+#ifdef CONFIG_PAX_PAGEEXEC
4585+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4586+#ifdef CONFIG_PPC_STD_MMU
4587+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4588+#else
4589+ if (is_exec && regs->nip == address) {
4590+#endif
4591+ switch (pax_handle_fetch_fault(regs)) {
4592+ }
4593+
4594+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4595+ do_group_exit(SIGKILL);
4596+ }
4597+ }
4598+#endif
4599+
4600 _exception(SIGSEGV, regs, code, address);
4601 return 0;
4602 }
4603diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4604index 67a42ed..1c7210c 100644
4605--- a/arch/powerpc/mm/mmap_64.c
4606+++ b/arch/powerpc/mm/mmap_64.c
4607@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4608 */
4609 if (mmap_is_legacy()) {
4610 mm->mmap_base = TASK_UNMAPPED_BASE;
4611+
4612+#ifdef CONFIG_PAX_RANDMMAP
4613+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4614+ mm->mmap_base += mm->delta_mmap;
4615+#endif
4616+
4617 mm->get_unmapped_area = arch_get_unmapped_area;
4618 mm->unmap_area = arch_unmap_area;
4619 } else {
4620 mm->mmap_base = mmap_base();
4621+
4622+#ifdef CONFIG_PAX_RANDMMAP
4623+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4624+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4625+#endif
4626+
4627 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4628 mm->unmap_area = arch_unmap_area_topdown;
4629 }
4630diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4631index 73709f7..6b90313 100644
4632--- a/arch/powerpc/mm/slice.c
4633+++ b/arch/powerpc/mm/slice.c
4634@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4635 if ((mm->task_size - len) < addr)
4636 return 0;
4637 vma = find_vma(mm, addr);
4638- return (!vma || (addr + len) <= vma->vm_start);
4639+ return check_heap_stack_gap(vma, addr, len);
4640 }
4641
4642 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4643@@ -256,7 +256,7 @@ full_search:
4644 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4645 continue;
4646 }
4647- if (!vma || addr + len <= vma->vm_start) {
4648+ if (check_heap_stack_gap(vma, addr, len)) {
4649 /*
4650 * Remember the place where we stopped the search:
4651 */
4652@@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4653 }
4654 }
4655
4656- addr = mm->mmap_base;
4657- while (addr > len) {
4658+ if (mm->mmap_base < len)
4659+ addr = -ENOMEM;
4660+ else
4661+ addr = mm->mmap_base - len;
4662+
4663+ while (!IS_ERR_VALUE(addr)) {
4664 /* Go down by chunk size */
4665- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4666+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
4667
4668 /* Check for hit with different page size */
4669 mask = slice_range_to_mask(addr, len);
4670@@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4671 * return with success:
4672 */
4673 vma = find_vma(mm, addr);
4674- if (!vma || (addr + len) <= vma->vm_start) {
4675+ if (check_heap_stack_gap(vma, addr, len)) {
4676 /* remember the address as a hint for next time */
4677 if (use_cache)
4678 mm->free_area_cache = addr;
4679@@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4680 mm->cached_hole_size = vma->vm_start - addr;
4681
4682 /* try just below the current vma->vm_start */
4683- addr = vma->vm_start;
4684+ addr = skip_heap_stack_gap(vma, len);
4685 }
4686
4687 /*
4688@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4689 if (fixed && addr > (mm->task_size - len))
4690 return -EINVAL;
4691
4692+#ifdef CONFIG_PAX_RANDMMAP
4693+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4694+ addr = 0;
4695+#endif
4696+
4697 /* If hint, make sure it matches our alignment restrictions */
4698 if (!fixed && addr) {
4699 addr = _ALIGN_UP(addr, 1ul << pshift);
4700diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4701index 748347b..81bc6c7 100644
4702--- a/arch/s390/include/asm/atomic.h
4703+++ b/arch/s390/include/asm/atomic.h
4704@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4705 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4706 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4707
4708+#define atomic64_read_unchecked(v) atomic64_read(v)
4709+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4710+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4711+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4712+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4713+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4714+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4715+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4716+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4717+
4718 #define smp_mb__before_atomic_dec() smp_mb()
4719 #define smp_mb__after_atomic_dec() smp_mb()
4720 #define smp_mb__before_atomic_inc() smp_mb()
4721diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4722index 2a30d5a..5e5586f 100644
4723--- a/arch/s390/include/asm/cache.h
4724+++ b/arch/s390/include/asm/cache.h
4725@@ -11,8 +11,10 @@
4726 #ifndef __ARCH_S390_CACHE_H
4727 #define __ARCH_S390_CACHE_H
4728
4729-#define L1_CACHE_BYTES 256
4730+#include <linux/const.h>
4731+
4732 #define L1_CACHE_SHIFT 8
4733+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4734 #define NET_SKB_PAD 32
4735
4736 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4737diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4738index c4ee39f..352881b 100644
4739--- a/arch/s390/include/asm/elf.h
4740+++ b/arch/s390/include/asm/elf.h
4741@@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4742 the loader. We need to make sure that it is out of the way of the program
4743 that it will "exec", and that there is sufficient room for the brk. */
4744
4745-extern unsigned long randomize_et_dyn(unsigned long base);
4746-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4747+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4748+
4749+#ifdef CONFIG_PAX_ASLR
4750+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4751+
4752+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4753+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4754+#endif
4755
4756 /* This yields a mask that user programs can use to figure out what
4757 instruction set this CPU supports. */
4758@@ -210,7 +216,4 @@ struct linux_binprm;
4759 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4760 int arch_setup_additional_pages(struct linux_binprm *, int);
4761
4762-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4763-#define arch_randomize_brk arch_randomize_brk
4764-
4765 #endif
4766diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4767index c4a93d6..4d2a9b4 100644
4768--- a/arch/s390/include/asm/exec.h
4769+++ b/arch/s390/include/asm/exec.h
4770@@ -7,6 +7,6 @@
4771 #ifndef __ASM_EXEC_H
4772 #define __ASM_EXEC_H
4773
4774-extern unsigned long arch_align_stack(unsigned long sp);
4775+#define arch_align_stack(x) ((x) & ~0xfUL)
4776
4777 #endif /* __ASM_EXEC_H */
4778diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4779index 8f2cada..43072c1 100644
4780--- a/arch/s390/include/asm/uaccess.h
4781+++ b/arch/s390/include/asm/uaccess.h
4782@@ -236,6 +236,10 @@ static inline unsigned long __must_check
4783 copy_to_user(void __user *to, const void *from, unsigned long n)
4784 {
4785 might_fault();
4786+
4787+ if ((long)n < 0)
4788+ return n;
4789+
4790 if (access_ok(VERIFY_WRITE, to, n))
4791 n = __copy_to_user(to, from, n);
4792 return n;
4793@@ -261,6 +265,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4794 static inline unsigned long __must_check
4795 __copy_from_user(void *to, const void __user *from, unsigned long n)
4796 {
4797+ if ((long)n < 0)
4798+ return n;
4799+
4800 if (__builtin_constant_p(n) && (n <= 256))
4801 return uaccess.copy_from_user_small(n, from, to);
4802 else
4803@@ -292,10 +299,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4804 static inline unsigned long __must_check
4805 copy_from_user(void *to, const void __user *from, unsigned long n)
4806 {
4807- unsigned int sz = __compiletime_object_size(to);
4808+ size_t sz = __compiletime_object_size(to);
4809
4810 might_fault();
4811- if (unlikely(sz != -1 && sz < n)) {
4812+
4813+ if ((long)n < 0)
4814+ return n;
4815+
4816+ if (unlikely(sz != (size_t)-1 && sz < n)) {
4817 copy_from_user_overflow();
4818 return n;
4819 }
4820diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4821index dfcb343..eda788a 100644
4822--- a/arch/s390/kernel/module.c
4823+++ b/arch/s390/kernel/module.c
4824@@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4825
4826 /* Increase core size by size of got & plt and set start
4827 offsets for got and plt. */
4828- me->core_size = ALIGN(me->core_size, 4);
4829- me->arch.got_offset = me->core_size;
4830- me->core_size += me->arch.got_size;
4831- me->arch.plt_offset = me->core_size;
4832- me->core_size += me->arch.plt_size;
4833+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
4834+ me->arch.got_offset = me->core_size_rw;
4835+ me->core_size_rw += me->arch.got_size;
4836+ me->arch.plt_offset = me->core_size_rx;
4837+ me->core_size_rx += me->arch.plt_size;
4838 return 0;
4839 }
4840
4841@@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4842 if (info->got_initialized == 0) {
4843 Elf_Addr *gotent;
4844
4845- gotent = me->module_core + me->arch.got_offset +
4846+ gotent = me->module_core_rw + me->arch.got_offset +
4847 info->got_offset;
4848 *gotent = val;
4849 info->got_initialized = 1;
4850@@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4851 else if (r_type == R_390_GOTENT ||
4852 r_type == R_390_GOTPLTENT)
4853 *(unsigned int *) loc =
4854- (val + (Elf_Addr) me->module_core - loc) >> 1;
4855+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4856 else if (r_type == R_390_GOT64 ||
4857 r_type == R_390_GOTPLT64)
4858 *(unsigned long *) loc = val;
4859@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4860 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4861 if (info->plt_initialized == 0) {
4862 unsigned int *ip;
4863- ip = me->module_core + me->arch.plt_offset +
4864+ ip = me->module_core_rx + me->arch.plt_offset +
4865 info->plt_offset;
4866 #ifndef CONFIG_64BIT
4867 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4868@@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4869 val - loc + 0xffffUL < 0x1ffffeUL) ||
4870 (r_type == R_390_PLT32DBL &&
4871 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4872- val = (Elf_Addr) me->module_core +
4873+ val = (Elf_Addr) me->module_core_rx +
4874 me->arch.plt_offset +
4875 info->plt_offset;
4876 val += rela->r_addend - loc;
4877@@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4878 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4879 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4880 val = val + rela->r_addend -
4881- ((Elf_Addr) me->module_core + me->arch.got_offset);
4882+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4883 if (r_type == R_390_GOTOFF16)
4884 *(unsigned short *) loc = val;
4885 else if (r_type == R_390_GOTOFF32)
4886@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4887 break;
4888 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4889 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4890- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4891+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4892 rela->r_addend - loc;
4893 if (r_type == R_390_GOTPC)
4894 *(unsigned int *) loc = val;
4895diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4896index 60055ce..ee4b252 100644
4897--- a/arch/s390/kernel/process.c
4898+++ b/arch/s390/kernel/process.c
4899@@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4900 }
4901 return 0;
4902 }
4903-
4904-unsigned long arch_align_stack(unsigned long sp)
4905-{
4906- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4907- sp -= get_random_int() & ~PAGE_MASK;
4908- return sp & ~0xf;
4909-}
4910-
4911-static inline unsigned long brk_rnd(void)
4912-{
4913- /* 8MB for 32bit, 1GB for 64bit */
4914- if (is_32bit_task())
4915- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4916- else
4917- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4918-}
4919-
4920-unsigned long arch_randomize_brk(struct mm_struct *mm)
4921-{
4922- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4923-
4924- if (ret < mm->brk)
4925- return mm->brk;
4926- return ret;
4927-}
4928-
4929-unsigned long randomize_et_dyn(unsigned long base)
4930-{
4931- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4932-
4933- if (!(current->flags & PF_RANDOMIZE))
4934- return base;
4935- if (ret < base)
4936- return base;
4937- return ret;
4938-}
4939diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4940index 2857c48..d047481 100644
4941--- a/arch/s390/mm/mmap.c
4942+++ b/arch/s390/mm/mmap.c
4943@@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4944 */
4945 if (mmap_is_legacy()) {
4946 mm->mmap_base = TASK_UNMAPPED_BASE;
4947+
4948+#ifdef CONFIG_PAX_RANDMMAP
4949+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4950+ mm->mmap_base += mm->delta_mmap;
4951+#endif
4952+
4953 mm->get_unmapped_area = arch_get_unmapped_area;
4954 mm->unmap_area = arch_unmap_area;
4955 } else {
4956 mm->mmap_base = mmap_base();
4957+
4958+#ifdef CONFIG_PAX_RANDMMAP
4959+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4960+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4961+#endif
4962+
4963 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4964 mm->unmap_area = arch_unmap_area_topdown;
4965 }
4966@@ -166,10 +178,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4967 */
4968 if (mmap_is_legacy()) {
4969 mm->mmap_base = TASK_UNMAPPED_BASE;
4970+
4971+#ifdef CONFIG_PAX_RANDMMAP
4972+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4973+ mm->mmap_base += mm->delta_mmap;
4974+#endif
4975+
4976 mm->get_unmapped_area = s390_get_unmapped_area;
4977 mm->unmap_area = arch_unmap_area;
4978 } else {
4979 mm->mmap_base = mmap_base();
4980+
4981+#ifdef CONFIG_PAX_RANDMMAP
4982+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4983+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4984+#endif
4985+
4986 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4987 mm->unmap_area = arch_unmap_area_topdown;
4988 }
4989diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4990index ae3d59f..f65f075 100644
4991--- a/arch/score/include/asm/cache.h
4992+++ b/arch/score/include/asm/cache.h
4993@@ -1,7 +1,9 @@
4994 #ifndef _ASM_SCORE_CACHE_H
4995 #define _ASM_SCORE_CACHE_H
4996
4997+#include <linux/const.h>
4998+
4999 #define L1_CACHE_SHIFT 4
5000-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5001+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5002
5003 #endif /* _ASM_SCORE_CACHE_H */
5004diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
5005index f9f3cd5..58ff438 100644
5006--- a/arch/score/include/asm/exec.h
5007+++ b/arch/score/include/asm/exec.h
5008@@ -1,6 +1,6 @@
5009 #ifndef _ASM_SCORE_EXEC_H
5010 #define _ASM_SCORE_EXEC_H
5011
5012-extern unsigned long arch_align_stack(unsigned long sp);
5013+#define arch_align_stack(x) (x)
5014
5015 #endif /* _ASM_SCORE_EXEC_H */
5016diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
5017index 2707023..1c2a3b7 100644
5018--- a/arch/score/kernel/process.c
5019+++ b/arch/score/kernel/process.c
5020@@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
5021
5022 return task_pt_regs(task)->cp0_epc;
5023 }
5024-
5025-unsigned long arch_align_stack(unsigned long sp)
5026-{
5027- return sp;
5028-}
5029diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
5030index ef9e555..331bd29 100644
5031--- a/arch/sh/include/asm/cache.h
5032+++ b/arch/sh/include/asm/cache.h
5033@@ -9,10 +9,11 @@
5034 #define __ASM_SH_CACHE_H
5035 #ifdef __KERNEL__
5036
5037+#include <linux/const.h>
5038 #include <linux/init.h>
5039 #include <cpu/cache.h>
5040
5041-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5042+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5043
5044 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5045
5046diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5047index afeb710..d1d1289 100644
5048--- a/arch/sh/mm/mmap.c
5049+++ b/arch/sh/mm/mmap.c
5050@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5051 addr = PAGE_ALIGN(addr);
5052
5053 vma = find_vma(mm, addr);
5054- if (TASK_SIZE - len >= addr &&
5055- (!vma || addr + len <= vma->vm_start))
5056+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5057 return addr;
5058 }
5059
5060@@ -106,7 +105,7 @@ full_search:
5061 }
5062 return -ENOMEM;
5063 }
5064- if (likely(!vma || addr + len <= vma->vm_start)) {
5065+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5066 /*
5067 * Remember the place where we stopped the search:
5068 */
5069@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5070 addr = PAGE_ALIGN(addr);
5071
5072 vma = find_vma(mm, addr);
5073- if (TASK_SIZE - len >= addr &&
5074- (!vma || addr + len <= vma->vm_start))
5075+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5076 return addr;
5077 }
5078
5079@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5080 /* make sure it can fit in the remaining address space */
5081 if (likely(addr > len)) {
5082 vma = find_vma(mm, addr-len);
5083- if (!vma || addr <= vma->vm_start) {
5084+ if (check_heap_stack_gap(vma, addr - len, len)) {
5085 /* remember the address as a hint for next time */
5086 return (mm->free_area_cache = addr-len);
5087 }
5088@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5089 if (unlikely(mm->mmap_base < len))
5090 goto bottomup;
5091
5092- addr = mm->mmap_base-len;
5093- if (do_colour_align)
5094- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5095+ addr = mm->mmap_base - len;
5096
5097 do {
5098+ if (do_colour_align)
5099+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5100 /*
5101 * Lookup failure means no vma is above this address,
5102 * else if new region fits below vma->vm_start,
5103 * return with success:
5104 */
5105 vma = find_vma(mm, addr);
5106- if (likely(!vma || addr+len <= vma->vm_start)) {
5107+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5108 /* remember the address as a hint for next time */
5109 return (mm->free_area_cache = addr);
5110 }
5111@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5112 mm->cached_hole_size = vma->vm_start - addr;
5113
5114 /* try just below the current vma->vm_start */
5115- addr = vma->vm_start-len;
5116- if (do_colour_align)
5117- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5118- } while (likely(len < vma->vm_start));
5119+ addr = skip_heap_stack_gap(vma, len);
5120+ } while (!IS_ERR_VALUE(addr));
5121
5122 bottomup:
5123 /*
5124diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
5125index eddcfb3..b117d90 100644
5126--- a/arch/sparc/Makefile
5127+++ b/arch/sparc/Makefile
5128@@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
5129 # Export what is needed by arch/sparc/boot/Makefile
5130 export VMLINUX_INIT VMLINUX_MAIN
5131 VMLINUX_INIT := $(head-y) $(init-y)
5132-VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
5133+VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
5134 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
5135 VMLINUX_MAIN += $(drivers-y) $(net-y)
5136
5137diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5138index ce35a1c..2e7b8f9 100644
5139--- a/arch/sparc/include/asm/atomic_64.h
5140+++ b/arch/sparc/include/asm/atomic_64.h
5141@@ -14,18 +14,40 @@
5142 #define ATOMIC64_INIT(i) { (i) }
5143
5144 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5145+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5146+{
5147+ return v->counter;
5148+}
5149 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5150+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5151+{
5152+ return v->counter;
5153+}
5154
5155 #define atomic_set(v, i) (((v)->counter) = i)
5156+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5157+{
5158+ v->counter = i;
5159+}
5160 #define atomic64_set(v, i) (((v)->counter) = i)
5161+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5162+{
5163+ v->counter = i;
5164+}
5165
5166 extern void atomic_add(int, atomic_t *);
5167+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5168 extern void atomic64_add(long, atomic64_t *);
5169+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5170 extern void atomic_sub(int, atomic_t *);
5171+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5172 extern void atomic64_sub(long, atomic64_t *);
5173+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5174
5175 extern int atomic_add_ret(int, atomic_t *);
5176+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5177 extern long atomic64_add_ret(long, atomic64_t *);
5178+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5179 extern int atomic_sub_ret(int, atomic_t *);
5180 extern long atomic64_sub_ret(long, atomic64_t *);
5181
5182@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5183 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5184
5185 #define atomic_inc_return(v) atomic_add_ret(1, v)
5186+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5187+{
5188+ return atomic_add_ret_unchecked(1, v);
5189+}
5190 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5191+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5192+{
5193+ return atomic64_add_ret_unchecked(1, v);
5194+}
5195
5196 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5197 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5198
5199 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5200+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5201+{
5202+ return atomic_add_ret_unchecked(i, v);
5203+}
5204 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5205+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5206+{
5207+ return atomic64_add_ret_unchecked(i, v);
5208+}
5209
5210 /*
5211 * atomic_inc_and_test - increment and test
5212@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5213 * other cases.
5214 */
5215 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5216+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5217+{
5218+ return atomic_inc_return_unchecked(v) == 0;
5219+}
5220 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5221
5222 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5223@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5224 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5225
5226 #define atomic_inc(v) atomic_add(1, v)
5227+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5228+{
5229+ atomic_add_unchecked(1, v);
5230+}
5231 #define atomic64_inc(v) atomic64_add(1, v)
5232+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5233+{
5234+ atomic64_add_unchecked(1, v);
5235+}
5236
5237 #define atomic_dec(v) atomic_sub(1, v)
5238+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5239+{
5240+ atomic_sub_unchecked(1, v);
5241+}
5242 #define atomic64_dec(v) atomic64_sub(1, v)
5243+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5244+{
5245+ atomic64_sub_unchecked(1, v);
5246+}
5247
5248 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5249 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5250
5251 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5252+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5253+{
5254+ return cmpxchg(&v->counter, old, new);
5255+}
5256 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5257+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5258+{
5259+ return xchg(&v->counter, new);
5260+}
5261
5262 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5263 {
5264- int c, old;
5265+ int c, old, new;
5266 c = atomic_read(v);
5267 for (;;) {
5268- if (unlikely(c == (u)))
5269+ if (unlikely(c == u))
5270 break;
5271- old = atomic_cmpxchg((v), c, c + (a));
5272+
5273+ asm volatile("addcc %2, %0, %0\n"
5274+
5275+#ifdef CONFIG_PAX_REFCOUNT
5276+ "tvs %%icc, 6\n"
5277+#endif
5278+
5279+ : "=r" (new)
5280+ : "0" (c), "ir" (a)
5281+ : "cc");
5282+
5283+ old = atomic_cmpxchg(v, c, new);
5284 if (likely(old == c))
5285 break;
5286 c = old;
5287@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5288 #define atomic64_cmpxchg(v, o, n) \
5289 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5290 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5291+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5292+{
5293+ return xchg(&v->counter, new);
5294+}
5295
5296 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5297 {
5298- long c, old;
5299+ long c, old, new;
5300 c = atomic64_read(v);
5301 for (;;) {
5302- if (unlikely(c == (u)))
5303+ if (unlikely(c == u))
5304 break;
5305- old = atomic64_cmpxchg((v), c, c + (a));
5306+
5307+ asm volatile("addcc %2, %0, %0\n"
5308+
5309+#ifdef CONFIG_PAX_REFCOUNT
5310+ "tvs %%xcc, 6\n"
5311+#endif
5312+
5313+ : "=r" (new)
5314+ : "0" (c), "ir" (a)
5315+ : "cc");
5316+
5317+ old = atomic64_cmpxchg(v, c, new);
5318 if (likely(old == c))
5319 break;
5320 c = old;
5321 }
5322- return c != (u);
5323+ return c != u;
5324 }
5325
5326 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5327diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5328index 69358b5..9d0d492 100644
5329--- a/arch/sparc/include/asm/cache.h
5330+++ b/arch/sparc/include/asm/cache.h
5331@@ -7,10 +7,12 @@
5332 #ifndef _SPARC_CACHE_H
5333 #define _SPARC_CACHE_H
5334
5335+#include <linux/const.h>
5336+
5337 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5338
5339 #define L1_CACHE_SHIFT 5
5340-#define L1_CACHE_BYTES 32
5341+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5342
5343 #ifdef CONFIG_SPARC32
5344 #define SMP_CACHE_BYTES_SHIFT 5
5345diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5346index 4269ca6..e3da77f 100644
5347--- a/arch/sparc/include/asm/elf_32.h
5348+++ b/arch/sparc/include/asm/elf_32.h
5349@@ -114,6 +114,13 @@ typedef struct {
5350
5351 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5352
5353+#ifdef CONFIG_PAX_ASLR
5354+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5355+
5356+#define PAX_DELTA_MMAP_LEN 16
5357+#define PAX_DELTA_STACK_LEN 16
5358+#endif
5359+
5360 /* This yields a mask that user programs can use to figure out what
5361 instruction set this cpu supports. This can NOT be done in userspace
5362 on Sparc. */
5363diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5364index 7df8b7f..4946269 100644
5365--- a/arch/sparc/include/asm/elf_64.h
5366+++ b/arch/sparc/include/asm/elf_64.h
5367@@ -180,6 +180,13 @@ typedef struct {
5368 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5369 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5370
5371+#ifdef CONFIG_PAX_ASLR
5372+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5373+
5374+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5375+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5376+#endif
5377+
5378 extern unsigned long sparc64_elf_hwcap;
5379 #define ELF_HWCAP sparc64_elf_hwcap
5380
5381diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5382index ca2b344..c6084f89 100644
5383--- a/arch/sparc/include/asm/pgalloc_32.h
5384+++ b/arch/sparc/include/asm/pgalloc_32.h
5385@@ -37,6 +37,7 @@ BTFIXUPDEF_CALL(void, free_pgd_fast, pgd_t *)
5386 BTFIXUPDEF_CALL(void, pgd_set, pgd_t *, pmd_t *)
5387 #define pgd_set(pgdp,pmdp) BTFIXUP_CALL(pgd_set)(pgdp,pmdp)
5388 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5389+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5390
5391 BTFIXUPDEF_CALL(pmd_t *, pmd_alloc_one, struct mm_struct *, unsigned long)
5392 #define pmd_alloc_one(mm, address) BTFIXUP_CALL(pmd_alloc_one)(mm, address)
5393diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5394index 40b2d7a..22a665b 100644
5395--- a/arch/sparc/include/asm/pgalloc_64.h
5396+++ b/arch/sparc/include/asm/pgalloc_64.h
5397@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5398 }
5399
5400 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5401+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5402
5403 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5404 {
5405diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5406index 3d71018..48a11c5 100644
5407--- a/arch/sparc/include/asm/pgtable_32.h
5408+++ b/arch/sparc/include/asm/pgtable_32.h
5409@@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
5410 BTFIXUPDEF_INT(page_none)
5411 BTFIXUPDEF_INT(page_copy)
5412 BTFIXUPDEF_INT(page_readonly)
5413+
5414+#ifdef CONFIG_PAX_PAGEEXEC
5415+BTFIXUPDEF_INT(page_shared_noexec)
5416+BTFIXUPDEF_INT(page_copy_noexec)
5417+BTFIXUPDEF_INT(page_readonly_noexec)
5418+#endif
5419+
5420 BTFIXUPDEF_INT(page_kernel)
5421
5422 #define PMD_SHIFT SUN4C_PMD_SHIFT
5423@@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
5424 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
5425 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
5426
5427+#ifdef CONFIG_PAX_PAGEEXEC
5428+extern pgprot_t PAGE_SHARED_NOEXEC;
5429+# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
5430+# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
5431+#else
5432+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5433+# define PAGE_COPY_NOEXEC PAGE_COPY
5434+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5435+#endif
5436+
5437 extern unsigned long page_kernel;
5438
5439 #ifdef MODULE
5440diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5441index f6ae2b2..b03ffc7 100644
5442--- a/arch/sparc/include/asm/pgtsrmmu.h
5443+++ b/arch/sparc/include/asm/pgtsrmmu.h
5444@@ -115,6 +115,13 @@
5445 SRMMU_EXEC | SRMMU_REF)
5446 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5447 SRMMU_EXEC | SRMMU_REF)
5448+
5449+#ifdef CONFIG_PAX_PAGEEXEC
5450+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5451+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5452+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5453+#endif
5454+
5455 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5456 SRMMU_DIRTY | SRMMU_REF)
5457
5458diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5459index 9689176..63c18ea 100644
5460--- a/arch/sparc/include/asm/spinlock_64.h
5461+++ b/arch/sparc/include/asm/spinlock_64.h
5462@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5463
5464 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5465
5466-static void inline arch_read_lock(arch_rwlock_t *lock)
5467+static inline void arch_read_lock(arch_rwlock_t *lock)
5468 {
5469 unsigned long tmp1, tmp2;
5470
5471 __asm__ __volatile__ (
5472 "1: ldsw [%2], %0\n"
5473 " brlz,pn %0, 2f\n"
5474-"4: add %0, 1, %1\n"
5475+"4: addcc %0, 1, %1\n"
5476+
5477+#ifdef CONFIG_PAX_REFCOUNT
5478+" tvs %%icc, 6\n"
5479+#endif
5480+
5481 " cas [%2], %0, %1\n"
5482 " cmp %0, %1\n"
5483 " bne,pn %%icc, 1b\n"
5484@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5485 " .previous"
5486 : "=&r" (tmp1), "=&r" (tmp2)
5487 : "r" (lock)
5488- : "memory");
5489+ : "memory", "cc");
5490 }
5491
5492-static int inline arch_read_trylock(arch_rwlock_t *lock)
5493+static inline int arch_read_trylock(arch_rwlock_t *lock)
5494 {
5495 int tmp1, tmp2;
5496
5497@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5498 "1: ldsw [%2], %0\n"
5499 " brlz,a,pn %0, 2f\n"
5500 " mov 0, %0\n"
5501-" add %0, 1, %1\n"
5502+" addcc %0, 1, %1\n"
5503+
5504+#ifdef CONFIG_PAX_REFCOUNT
5505+" tvs %%icc, 6\n"
5506+#endif
5507+
5508 " cas [%2], %0, %1\n"
5509 " cmp %0, %1\n"
5510 " bne,pn %%icc, 1b\n"
5511@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5512 return tmp1;
5513 }
5514
5515-static void inline arch_read_unlock(arch_rwlock_t *lock)
5516+static inline void arch_read_unlock(arch_rwlock_t *lock)
5517 {
5518 unsigned long tmp1, tmp2;
5519
5520 __asm__ __volatile__(
5521 "1: lduw [%2], %0\n"
5522-" sub %0, 1, %1\n"
5523+" subcc %0, 1, %1\n"
5524+
5525+#ifdef CONFIG_PAX_REFCOUNT
5526+" tvs %%icc, 6\n"
5527+#endif
5528+
5529 " cas [%2], %0, %1\n"
5530 " cmp %0, %1\n"
5531 " bne,pn %%xcc, 1b\n"
5532@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5533 : "memory");
5534 }
5535
5536-static void inline arch_write_lock(arch_rwlock_t *lock)
5537+static inline void arch_write_lock(arch_rwlock_t *lock)
5538 {
5539 unsigned long mask, tmp1, tmp2;
5540
5541@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5542 : "memory");
5543 }
5544
5545-static void inline arch_write_unlock(arch_rwlock_t *lock)
5546+static inline void arch_write_unlock(arch_rwlock_t *lock)
5547 {
5548 __asm__ __volatile__(
5549 " stw %%g0, [%0]"
5550@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5551 : "memory");
5552 }
5553
5554-static int inline arch_write_trylock(arch_rwlock_t *lock)
5555+static inline int arch_write_trylock(arch_rwlock_t *lock)
5556 {
5557 unsigned long mask, tmp1, tmp2, result;
5558
5559diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5560index c2a1080..21ed218 100644
5561--- a/arch/sparc/include/asm/thread_info_32.h
5562+++ b/arch/sparc/include/asm/thread_info_32.h
5563@@ -50,6 +50,8 @@ struct thread_info {
5564 unsigned long w_saved;
5565
5566 struct restart_block restart_block;
5567+
5568+ unsigned long lowest_stack;
5569 };
5570
5571 /*
5572diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5573index 01d057f..13a7d2f 100644
5574--- a/arch/sparc/include/asm/thread_info_64.h
5575+++ b/arch/sparc/include/asm/thread_info_64.h
5576@@ -63,6 +63,8 @@ struct thread_info {
5577 struct pt_regs *kern_una_regs;
5578 unsigned int kern_una_insn;
5579
5580+ unsigned long lowest_stack;
5581+
5582 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5583 };
5584
5585@@ -214,10 +216,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5586 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5587 /* flag bit 6 is available */
5588 #define TIF_32BIT 7 /* 32-bit binary */
5589-/* flag bit 8 is available */
5590+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5591 #define TIF_SECCOMP 9 /* secure computing */
5592 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5593 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5594+
5595 /* NOTE: Thread flags >= 12 should be ones we have no interest
5596 * in using in assembly, else we can't use the mask as
5597 * an immediate value in instructions such as andcc.
5598@@ -236,12 +239,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5599 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5600 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5601 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5602+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5603
5604 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5605 _TIF_DO_NOTIFY_RESUME_MASK | \
5606 _TIF_NEED_RESCHED)
5607 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5608
5609+#define _TIF_WORK_SYSCALL \
5610+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5611+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5612+
5613+
5614 /*
5615 * Thread-synchronous status.
5616 *
5617diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5618index e88fbe5..96b0ce5 100644
5619--- a/arch/sparc/include/asm/uaccess.h
5620+++ b/arch/sparc/include/asm/uaccess.h
5621@@ -1,5 +1,13 @@
5622 #ifndef ___ASM_SPARC_UACCESS_H
5623 #define ___ASM_SPARC_UACCESS_H
5624+
5625+#ifdef __KERNEL__
5626+#ifndef __ASSEMBLY__
5627+#include <linux/types.h>
5628+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5629+#endif
5630+#endif
5631+
5632 #if defined(__sparc__) && defined(__arch64__)
5633 #include <asm/uaccess_64.h>
5634 #else
5635diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5636index 8303ac4..07f333d 100644
5637--- a/arch/sparc/include/asm/uaccess_32.h
5638+++ b/arch/sparc/include/asm/uaccess_32.h
5639@@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5640
5641 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5642 {
5643- if (n && __access_ok((unsigned long) to, n))
5644+ if ((long)n < 0)
5645+ return n;
5646+
5647+ if (n && __access_ok((unsigned long) to, n)) {
5648+ if (!__builtin_constant_p(n))
5649+ check_object_size(from, n, true);
5650 return __copy_user(to, (__force void __user *) from, n);
5651- else
5652+ } else
5653 return n;
5654 }
5655
5656 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5657 {
5658+ if ((long)n < 0)
5659+ return n;
5660+
5661+ if (!__builtin_constant_p(n))
5662+ check_object_size(from, n, true);
5663+
5664 return __copy_user(to, (__force void __user *) from, n);
5665 }
5666
5667 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5668 {
5669- if (n && __access_ok((unsigned long) from, n))
5670+ if ((long)n < 0)
5671+ return n;
5672+
5673+ if (n && __access_ok((unsigned long) from, n)) {
5674+ if (!__builtin_constant_p(n))
5675+ check_object_size(to, n, false);
5676 return __copy_user((__force void __user *) to, from, n);
5677- else
5678+ } else
5679 return n;
5680 }
5681
5682 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5683 {
5684+ if ((long)n < 0)
5685+ return n;
5686+
5687 return __copy_user((__force void __user *) to, from, n);
5688 }
5689
5690diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5691index a1091afb..380228e 100644
5692--- a/arch/sparc/include/asm/uaccess_64.h
5693+++ b/arch/sparc/include/asm/uaccess_64.h
5694@@ -10,6 +10,7 @@
5695 #include <linux/compiler.h>
5696 #include <linux/string.h>
5697 #include <linux/thread_info.h>
5698+#include <linux/kernel.h>
5699 #include <asm/asi.h>
5700 #include <asm/spitfire.h>
5701 #include <asm-generic/uaccess-unaligned.h>
5702@@ -212,8 +213,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5703 static inline unsigned long __must_check
5704 copy_from_user(void *to, const void __user *from, unsigned long size)
5705 {
5706- unsigned long ret = ___copy_from_user(to, from, size);
5707+ unsigned long ret;
5708
5709+ if ((long)size < 0 || size > INT_MAX)
5710+ return size;
5711+
5712+ if (!__builtin_constant_p(size))
5713+ check_object_size(to, size, false);
5714+
5715+ ret = ___copy_from_user(to, from, size);
5716 if (unlikely(ret))
5717 ret = copy_from_user_fixup(to, from, size);
5718
5719@@ -229,8 +237,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5720 static inline unsigned long __must_check
5721 copy_to_user(void __user *to, const void *from, unsigned long size)
5722 {
5723- unsigned long ret = ___copy_to_user(to, from, size);
5724+ unsigned long ret;
5725
5726+ if ((long)size < 0 || size > INT_MAX)
5727+ return size;
5728+
5729+ if (!__builtin_constant_p(size))
5730+ check_object_size(from, size, true);
5731+
5732+ ret = ___copy_to_user(to, from, size);
5733 if (unlikely(ret))
5734 ret = copy_to_user_fixup(to, from, size);
5735 return ret;
5736diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5737index cb85458..e063f17 100644
5738--- a/arch/sparc/kernel/Makefile
5739+++ b/arch/sparc/kernel/Makefile
5740@@ -3,7 +3,7 @@
5741 #
5742
5743 asflags-y := -ansi
5744-ccflags-y := -Werror
5745+#ccflags-y := -Werror
5746
5747 extra-y := head_$(BITS).o
5748 extra-y += init_task.o
5749diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5750index efa0754..74b03fe 100644
5751--- a/arch/sparc/kernel/process_32.c
5752+++ b/arch/sparc/kernel/process_32.c
5753@@ -200,7 +200,7 @@ void __show_backtrace(unsigned long fp)
5754 rw->ins[4], rw->ins[5],
5755 rw->ins[6],
5756 rw->ins[7]);
5757- printk("%pS\n", (void *) rw->ins[7]);
5758+ printk("%pA\n", (void *) rw->ins[7]);
5759 rw = (struct reg_window32 *) rw->ins[6];
5760 }
5761 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5762@@ -267,14 +267,14 @@ void show_regs(struct pt_regs *r)
5763
5764 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5765 r->psr, r->pc, r->npc, r->y, print_tainted());
5766- printk("PC: <%pS>\n", (void *) r->pc);
5767+ printk("PC: <%pA>\n", (void *) r->pc);
5768 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5769 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5770 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5771 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5772 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5773 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5774- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5775+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5776
5777 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5778 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5779@@ -309,7 +309,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5780 rw = (struct reg_window32 *) fp;
5781 pc = rw->ins[7];
5782 printk("[%08lx : ", pc);
5783- printk("%pS ] ", (void *) pc);
5784+ printk("%pA ] ", (void *) pc);
5785 fp = rw->ins[6];
5786 } while (++count < 16);
5787 printk("\n");
5788diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5789index aff0c72..9067b39 100644
5790--- a/arch/sparc/kernel/process_64.c
5791+++ b/arch/sparc/kernel/process_64.c
5792@@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5793 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5794 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5795 if (regs->tstate & TSTATE_PRIV)
5796- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5797+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5798 }
5799
5800 void show_regs(struct pt_regs *regs)
5801 {
5802 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5803 regs->tpc, regs->tnpc, regs->y, print_tainted());
5804- printk("TPC: <%pS>\n", (void *) regs->tpc);
5805+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5806 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5807 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5808 regs->u_regs[3]);
5809@@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5810 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5811 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5812 regs->u_regs[15]);
5813- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5814+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5815 show_regwindow(regs);
5816 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5817 }
5818@@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5819 ((tp && tp->task) ? tp->task->pid : -1));
5820
5821 if (gp->tstate & TSTATE_PRIV) {
5822- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5823+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5824 (void *) gp->tpc,
5825 (void *) gp->o7,
5826 (void *) gp->i7,
5827diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5828index 6f97c07..b1300ec 100644
5829--- a/arch/sparc/kernel/ptrace_64.c
5830+++ b/arch/sparc/kernel/ptrace_64.c
5831@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5832 return ret;
5833 }
5834
5835+#ifdef CONFIG_GRKERNSEC_SETXID
5836+extern void gr_delayed_cred_worker(void);
5837+#endif
5838+
5839 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5840 {
5841 int ret = 0;
5842@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5843 /* do the secure computing check first */
5844 secure_computing(regs->u_regs[UREG_G1]);
5845
5846+#ifdef CONFIG_GRKERNSEC_SETXID
5847+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5848+ gr_delayed_cred_worker();
5849+#endif
5850+
5851 if (test_thread_flag(TIF_SYSCALL_TRACE))
5852 ret = tracehook_report_syscall_entry(regs);
5853
5854@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5855
5856 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5857 {
5858+#ifdef CONFIG_GRKERNSEC_SETXID
5859+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5860+ gr_delayed_cred_worker();
5861+#endif
5862+
5863 audit_syscall_exit(regs);
5864
5865 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5866diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5867index 42b282f..28ce9f2 100644
5868--- a/arch/sparc/kernel/sys_sparc_32.c
5869+++ b/arch/sparc/kernel/sys_sparc_32.c
5870@@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5871 if (ARCH_SUN4C && len > 0x20000000)
5872 return -ENOMEM;
5873 if (!addr)
5874- addr = TASK_UNMAPPED_BASE;
5875+ addr = current->mm->mmap_base;
5876
5877 if (flags & MAP_SHARED)
5878 addr = COLOUR_ALIGN(addr);
5879@@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5880 }
5881 if (TASK_SIZE - PAGE_SIZE - len < addr)
5882 return -ENOMEM;
5883- if (!vmm || addr + len <= vmm->vm_start)
5884+ if (check_heap_stack_gap(vmm, addr, len))
5885 return addr;
5886 addr = vmm->vm_end;
5887 if (flags & MAP_SHARED)
5888diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5889index 3ee51f1..2ba4913 100644
5890--- a/arch/sparc/kernel/sys_sparc_64.c
5891+++ b/arch/sparc/kernel/sys_sparc_64.c
5892@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5893 /* We do not accept a shared mapping if it would violate
5894 * cache aliasing constraints.
5895 */
5896- if ((flags & MAP_SHARED) &&
5897+ if ((filp || (flags & MAP_SHARED)) &&
5898 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5899 return -EINVAL;
5900 return addr;
5901@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5902 if (filp || (flags & MAP_SHARED))
5903 do_color_align = 1;
5904
5905+#ifdef CONFIG_PAX_RANDMMAP
5906+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5907+#endif
5908+
5909 if (addr) {
5910 if (do_color_align)
5911 addr = COLOUR_ALIGN(addr, pgoff);
5912@@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5913 addr = PAGE_ALIGN(addr);
5914
5915 vma = find_vma(mm, addr);
5916- if (task_size - len >= addr &&
5917- (!vma || addr + len <= vma->vm_start))
5918+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5919 return addr;
5920 }
5921
5922 if (len > mm->cached_hole_size) {
5923- start_addr = addr = mm->free_area_cache;
5924+ start_addr = addr = mm->free_area_cache;
5925 } else {
5926- start_addr = addr = TASK_UNMAPPED_BASE;
5927+ start_addr = addr = mm->mmap_base;
5928 mm->cached_hole_size = 0;
5929 }
5930
5931@@ -174,14 +177,14 @@ full_search:
5932 vma = find_vma(mm, VA_EXCLUDE_END);
5933 }
5934 if (unlikely(task_size < addr)) {
5935- if (start_addr != TASK_UNMAPPED_BASE) {
5936- start_addr = addr = TASK_UNMAPPED_BASE;
5937+ if (start_addr != mm->mmap_base) {
5938+ start_addr = addr = mm->mmap_base;
5939 mm->cached_hole_size = 0;
5940 goto full_search;
5941 }
5942 return -ENOMEM;
5943 }
5944- if (likely(!vma || addr + len <= vma->vm_start)) {
5945+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5946 /*
5947 * Remember the place where we stopped the search:
5948 */
5949@@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5950 /* We do not accept a shared mapping if it would violate
5951 * cache aliasing constraints.
5952 */
5953- if ((flags & MAP_SHARED) &&
5954+ if ((filp || (flags & MAP_SHARED)) &&
5955 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5956 return -EINVAL;
5957 return addr;
5958@@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5959 addr = PAGE_ALIGN(addr);
5960
5961 vma = find_vma(mm, addr);
5962- if (task_size - len >= addr &&
5963- (!vma || addr + len <= vma->vm_start))
5964+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5965 return addr;
5966 }
5967
5968@@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5969 /* make sure it can fit in the remaining address space */
5970 if (likely(addr > len)) {
5971 vma = find_vma(mm, addr-len);
5972- if (!vma || addr <= vma->vm_start) {
5973+ if (check_heap_stack_gap(vma, addr - len, len)) {
5974 /* remember the address as a hint for next time */
5975 return (mm->free_area_cache = addr-len);
5976 }
5977@@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5978 if (unlikely(mm->mmap_base < len))
5979 goto bottomup;
5980
5981- addr = mm->mmap_base-len;
5982- if (do_color_align)
5983- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5984+ addr = mm->mmap_base - len;
5985
5986 do {
5987+ if (do_color_align)
5988+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5989 /*
5990 * Lookup failure means no vma is above this address,
5991 * else if new region fits below vma->vm_start,
5992 * return with success:
5993 */
5994 vma = find_vma(mm, addr);
5995- if (likely(!vma || addr+len <= vma->vm_start)) {
5996+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5997 /* remember the address as a hint for next time */
5998 return (mm->free_area_cache = addr);
5999 }
6000@@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6001 mm->cached_hole_size = vma->vm_start - addr;
6002
6003 /* try just below the current vma->vm_start */
6004- addr = vma->vm_start-len;
6005- if (do_color_align)
6006- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6007- } while (likely(len < vma->vm_start));
6008+ addr = skip_heap_stack_gap(vma, len);
6009+ } while (!IS_ERR_VALUE(addr));
6010
6011 bottomup:
6012 /*
6013@@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6014 gap == RLIM_INFINITY ||
6015 sysctl_legacy_va_layout) {
6016 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6017+
6018+#ifdef CONFIG_PAX_RANDMMAP
6019+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6020+ mm->mmap_base += mm->delta_mmap;
6021+#endif
6022+
6023 mm->get_unmapped_area = arch_get_unmapped_area;
6024 mm->unmap_area = arch_unmap_area;
6025 } else {
6026@@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6027 gap = (task_size / 6 * 5);
6028
6029 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6030+
6031+#ifdef CONFIG_PAX_RANDMMAP
6032+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6033+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6034+#endif
6035+
6036 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6037 mm->unmap_area = arch_unmap_area_topdown;
6038 }
6039diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
6040index 1d7e274..b39c527 100644
6041--- a/arch/sparc/kernel/syscalls.S
6042+++ b/arch/sparc/kernel/syscalls.S
6043@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6044 #endif
6045 .align 32
6046 1: ldx [%g6 + TI_FLAGS], %l5
6047- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6048+ andcc %l5, _TIF_WORK_SYSCALL, %g0
6049 be,pt %icc, rtrap
6050 nop
6051 call syscall_trace_leave
6052@@ -179,7 +179,7 @@ linux_sparc_syscall32:
6053
6054 srl %i5, 0, %o5 ! IEU1
6055 srl %i2, 0, %o2 ! IEU0 Group
6056- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6057+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6058 bne,pn %icc, linux_syscall_trace32 ! CTI
6059 mov %i0, %l5 ! IEU1
6060 call %l7 ! CTI Group brk forced
6061@@ -202,7 +202,7 @@ linux_sparc_syscall:
6062
6063 mov %i3, %o3 ! IEU1
6064 mov %i4, %o4 ! IEU0 Group
6065- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6066+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6067 bne,pn %icc, linux_syscall_trace ! CTI Group
6068 mov %i0, %l5 ! IEU0
6069 2: call %l7 ! CTI Group brk forced
6070@@ -226,7 +226,7 @@ ret_sys_call:
6071
6072 cmp %o0, -ERESTART_RESTARTBLOCK
6073 bgeu,pn %xcc, 1f
6074- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6075+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6076 80:
6077 /* System call success, clear Carry condition code. */
6078 andn %g3, %g2, %g3
6079@@ -241,7 +241,7 @@ ret_sys_call:
6080 /* System call failure, set Carry condition code.
6081 * Also, get abs(errno) to return to the process.
6082 */
6083- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6084+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6085 sub %g0, %o0, %o0
6086 or %g3, %g2, %g3
6087 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6088diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6089index d2de213..6b22bc3 100644
6090--- a/arch/sparc/kernel/traps_32.c
6091+++ b/arch/sparc/kernel/traps_32.c
6092@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6093 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6094 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6095
6096+extern void gr_handle_kernel_exploit(void);
6097+
6098 void die_if_kernel(char *str, struct pt_regs *regs)
6099 {
6100 static int die_counter;
6101@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6102 count++ < 30 &&
6103 (((unsigned long) rw) >= PAGE_OFFSET) &&
6104 !(((unsigned long) rw) & 0x7)) {
6105- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6106+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6107 (void *) rw->ins[7]);
6108 rw = (struct reg_window32 *)rw->ins[6];
6109 }
6110 }
6111 printk("Instruction DUMP:");
6112 instruction_dump ((unsigned long *) regs->pc);
6113- if(regs->psr & PSR_PS)
6114+ if(regs->psr & PSR_PS) {
6115+ gr_handle_kernel_exploit();
6116 do_exit(SIGKILL);
6117+ }
6118 do_exit(SIGSEGV);
6119 }
6120
6121diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6122index c72fdf5..743a344 100644
6123--- a/arch/sparc/kernel/traps_64.c
6124+++ b/arch/sparc/kernel/traps_64.c
6125@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6126 i + 1,
6127 p->trapstack[i].tstate, p->trapstack[i].tpc,
6128 p->trapstack[i].tnpc, p->trapstack[i].tt);
6129- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6130+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6131 }
6132 }
6133
6134@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6135
6136 lvl -= 0x100;
6137 if (regs->tstate & TSTATE_PRIV) {
6138+
6139+#ifdef CONFIG_PAX_REFCOUNT
6140+ if (lvl == 6)
6141+ pax_report_refcount_overflow(regs);
6142+#endif
6143+
6144 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6145 die_if_kernel(buffer, regs);
6146 }
6147@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6148 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6149 {
6150 char buffer[32];
6151-
6152+
6153 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6154 0, lvl, SIGTRAP) == NOTIFY_STOP)
6155 return;
6156
6157+#ifdef CONFIG_PAX_REFCOUNT
6158+ if (lvl == 6)
6159+ pax_report_refcount_overflow(regs);
6160+#endif
6161+
6162 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6163
6164 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6165@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6166 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6167 printk("%s" "ERROR(%d): ",
6168 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6169- printk("TPC<%pS>\n", (void *) regs->tpc);
6170+ printk("TPC<%pA>\n", (void *) regs->tpc);
6171 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6172 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6173 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6174@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6175 smp_processor_id(),
6176 (type & 0x1) ? 'I' : 'D',
6177 regs->tpc);
6178- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6179+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6180 panic("Irrecoverable Cheetah+ parity error.");
6181 }
6182
6183@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6184 smp_processor_id(),
6185 (type & 0x1) ? 'I' : 'D',
6186 regs->tpc);
6187- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6188+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6189 }
6190
6191 struct sun4v_error_entry {
6192@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6193
6194 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6195 regs->tpc, tl);
6196- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6197+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6198 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6199- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6200+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6201 (void *) regs->u_regs[UREG_I7]);
6202 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6203 "pte[%lx] error[%lx]\n",
6204@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6205
6206 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6207 regs->tpc, tl);
6208- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6209+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6210 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6211- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6212+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6213 (void *) regs->u_regs[UREG_I7]);
6214 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6215 "pte[%lx] error[%lx]\n",
6216@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6217 fp = (unsigned long)sf->fp + STACK_BIAS;
6218 }
6219
6220- printk(" [%016lx] %pS\n", pc, (void *) pc);
6221+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6222 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6223 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6224 int index = tsk->curr_ret_stack;
6225 if (tsk->ret_stack && index >= graph) {
6226 pc = tsk->ret_stack[index - graph].ret;
6227- printk(" [%016lx] %pS\n", pc, (void *) pc);
6228+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6229 graph++;
6230 }
6231 }
6232@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6233 return (struct reg_window *) (fp + STACK_BIAS);
6234 }
6235
6236+extern void gr_handle_kernel_exploit(void);
6237+
6238 void die_if_kernel(char *str, struct pt_regs *regs)
6239 {
6240 static int die_counter;
6241@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6242 while (rw &&
6243 count++ < 30 &&
6244 kstack_valid(tp, (unsigned long) rw)) {
6245- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6246+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6247 (void *) rw->ins[7]);
6248
6249 rw = kernel_stack_up(rw);
6250@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6251 }
6252 user_instruction_dump ((unsigned int __user *) regs->tpc);
6253 }
6254- if (regs->tstate & TSTATE_PRIV)
6255+ if (regs->tstate & TSTATE_PRIV) {
6256+ gr_handle_kernel_exploit();
6257 do_exit(SIGKILL);
6258+ }
6259 do_exit(SIGSEGV);
6260 }
6261 EXPORT_SYMBOL(die_if_kernel);
6262diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6263index dae85bc..af1e19d 100644
6264--- a/arch/sparc/kernel/unaligned_64.c
6265+++ b/arch/sparc/kernel/unaligned_64.c
6266@@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
6267 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6268
6269 if (__ratelimit(&ratelimit)) {
6270- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6271+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6272 regs->tpc, (void *) regs->tpc);
6273 }
6274 }
6275diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6276index a3fc437..fea9957 100644
6277--- a/arch/sparc/lib/Makefile
6278+++ b/arch/sparc/lib/Makefile
6279@@ -2,7 +2,7 @@
6280 #
6281
6282 asflags-y := -ansi -DST_DIV0=0x02
6283-ccflags-y := -Werror
6284+#ccflags-y := -Werror
6285
6286 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
6287 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6288diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6289index 59186e0..f747d7a 100644
6290--- a/arch/sparc/lib/atomic_64.S
6291+++ b/arch/sparc/lib/atomic_64.S
6292@@ -18,7 +18,12 @@
6293 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6294 BACKOFF_SETUP(%o2)
6295 1: lduw [%o1], %g1
6296- add %g1, %o0, %g7
6297+ addcc %g1, %o0, %g7
6298+
6299+#ifdef CONFIG_PAX_REFCOUNT
6300+ tvs %icc, 6
6301+#endif
6302+
6303 cas [%o1], %g1, %g7
6304 cmp %g1, %g7
6305 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6306@@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6307 2: BACKOFF_SPIN(%o2, %o3, 1b)
6308 .size atomic_add, .-atomic_add
6309
6310+ .globl atomic_add_unchecked
6311+ .type atomic_add_unchecked,#function
6312+atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6313+ BACKOFF_SETUP(%o2)
6314+1: lduw [%o1], %g1
6315+ add %g1, %o0, %g7
6316+ cas [%o1], %g1, %g7
6317+ cmp %g1, %g7
6318+ bne,pn %icc, 2f
6319+ nop
6320+ retl
6321+ nop
6322+2: BACKOFF_SPIN(%o2, %o3, 1b)
6323+ .size atomic_add_unchecked, .-atomic_add_unchecked
6324+
6325 .globl atomic_sub
6326 .type atomic_sub,#function
6327 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6328 BACKOFF_SETUP(%o2)
6329 1: lduw [%o1], %g1
6330- sub %g1, %o0, %g7
6331+ subcc %g1, %o0, %g7
6332+
6333+#ifdef CONFIG_PAX_REFCOUNT
6334+ tvs %icc, 6
6335+#endif
6336+
6337 cas [%o1], %g1, %g7
6338 cmp %g1, %g7
6339 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6340@@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6341 2: BACKOFF_SPIN(%o2, %o3, 1b)
6342 .size atomic_sub, .-atomic_sub
6343
6344+ .globl atomic_sub_unchecked
6345+ .type atomic_sub_unchecked,#function
6346+atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6347+ BACKOFF_SETUP(%o2)
6348+1: lduw [%o1], %g1
6349+ sub %g1, %o0, %g7
6350+ cas [%o1], %g1, %g7
6351+ cmp %g1, %g7
6352+ bne,pn %icc, 2f
6353+ nop
6354+ retl
6355+ nop
6356+2: BACKOFF_SPIN(%o2, %o3, 1b)
6357+ .size atomic_sub_unchecked, .-atomic_sub_unchecked
6358+
6359 .globl atomic_add_ret
6360 .type atomic_add_ret,#function
6361 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6362 BACKOFF_SETUP(%o2)
6363 1: lduw [%o1], %g1
6364- add %g1, %o0, %g7
6365+ addcc %g1, %o0, %g7
6366+
6367+#ifdef CONFIG_PAX_REFCOUNT
6368+ tvs %icc, 6
6369+#endif
6370+
6371 cas [%o1], %g1, %g7
6372 cmp %g1, %g7
6373 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6374@@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6375 2: BACKOFF_SPIN(%o2, %o3, 1b)
6376 .size atomic_add_ret, .-atomic_add_ret
6377
6378+ .globl atomic_add_ret_unchecked
6379+ .type atomic_add_ret_unchecked,#function
6380+atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6381+ BACKOFF_SETUP(%o2)
6382+1: lduw [%o1], %g1
6383+ addcc %g1, %o0, %g7
6384+ cas [%o1], %g1, %g7
6385+ cmp %g1, %g7
6386+ bne,pn %icc, 2f
6387+ add %g7, %o0, %g7
6388+ sra %g7, 0, %o0
6389+ retl
6390+ nop
6391+2: BACKOFF_SPIN(%o2, %o3, 1b)
6392+ .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
6393+
6394 .globl atomic_sub_ret
6395 .type atomic_sub_ret,#function
6396 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6397 BACKOFF_SETUP(%o2)
6398 1: lduw [%o1], %g1
6399- sub %g1, %o0, %g7
6400+ subcc %g1, %o0, %g7
6401+
6402+#ifdef CONFIG_PAX_REFCOUNT
6403+ tvs %icc, 6
6404+#endif
6405+
6406 cas [%o1], %g1, %g7
6407 cmp %g1, %g7
6408 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6409@@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6410 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6411 BACKOFF_SETUP(%o2)
6412 1: ldx [%o1], %g1
6413- add %g1, %o0, %g7
6414+ addcc %g1, %o0, %g7
6415+
6416+#ifdef CONFIG_PAX_REFCOUNT
6417+ tvs %xcc, 6
6418+#endif
6419+
6420 casx [%o1], %g1, %g7
6421 cmp %g1, %g7
6422 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6423@@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6424 2: BACKOFF_SPIN(%o2, %o3, 1b)
6425 .size atomic64_add, .-atomic64_add
6426
6427+ .globl atomic64_add_unchecked
6428+ .type atomic64_add_unchecked,#function
6429+atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6430+ BACKOFF_SETUP(%o2)
6431+1: ldx [%o1], %g1
6432+ addcc %g1, %o0, %g7
6433+ casx [%o1], %g1, %g7
6434+ cmp %g1, %g7
6435+ bne,pn %xcc, 2f
6436+ nop
6437+ retl
6438+ nop
6439+2: BACKOFF_SPIN(%o2, %o3, 1b)
6440+ .size atomic64_add_unchecked, .-atomic64_add_unchecked
6441+
6442 .globl atomic64_sub
6443 .type atomic64_sub,#function
6444 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6445 BACKOFF_SETUP(%o2)
6446 1: ldx [%o1], %g1
6447- sub %g1, %o0, %g7
6448+ subcc %g1, %o0, %g7
6449+
6450+#ifdef CONFIG_PAX_REFCOUNT
6451+ tvs %xcc, 6
6452+#endif
6453+
6454 casx [%o1], %g1, %g7
6455 cmp %g1, %g7
6456 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6457@@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6458 2: BACKOFF_SPIN(%o2, %o3, 1b)
6459 .size atomic64_sub, .-atomic64_sub
6460
6461+ .globl atomic64_sub_unchecked
6462+ .type atomic64_sub_unchecked,#function
6463+atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6464+ BACKOFF_SETUP(%o2)
6465+1: ldx [%o1], %g1
6466+ subcc %g1, %o0, %g7
6467+ casx [%o1], %g1, %g7
6468+ cmp %g1, %g7
6469+ bne,pn %xcc, 2f
6470+ nop
6471+ retl
6472+ nop
6473+2: BACKOFF_SPIN(%o2, %o3, 1b)
6474+ .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6475+
6476 .globl atomic64_add_ret
6477 .type atomic64_add_ret,#function
6478 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6479 BACKOFF_SETUP(%o2)
6480 1: ldx [%o1], %g1
6481- add %g1, %o0, %g7
6482+ addcc %g1, %o0, %g7
6483+
6484+#ifdef CONFIG_PAX_REFCOUNT
6485+ tvs %xcc, 6
6486+#endif
6487+
6488 casx [%o1], %g1, %g7
6489 cmp %g1, %g7
6490 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6491@@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6492 2: BACKOFF_SPIN(%o2, %o3, 1b)
6493 .size atomic64_add_ret, .-atomic64_add_ret
6494
6495+ .globl atomic64_add_ret_unchecked
6496+ .type atomic64_add_ret_unchecked,#function
6497+atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6498+ BACKOFF_SETUP(%o2)
6499+1: ldx [%o1], %g1
6500+ addcc %g1, %o0, %g7
6501+ casx [%o1], %g1, %g7
6502+ cmp %g1, %g7
6503+ bne,pn %xcc, 2f
6504+ add %g7, %o0, %g7
6505+ mov %g7, %o0
6506+ retl
6507+ nop
6508+2: BACKOFF_SPIN(%o2, %o3, 1b)
6509+ .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6510+
6511 .globl atomic64_sub_ret
6512 .type atomic64_sub_ret,#function
6513 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6514 BACKOFF_SETUP(%o2)
6515 1: ldx [%o1], %g1
6516- sub %g1, %o0, %g7
6517+ subcc %g1, %o0, %g7
6518+
6519+#ifdef CONFIG_PAX_REFCOUNT
6520+ tvs %xcc, 6
6521+#endif
6522+
6523 casx [%o1], %g1, %g7
6524 cmp %g1, %g7
6525 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6526diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6527index f73c224..662af10 100644
6528--- a/arch/sparc/lib/ksyms.c
6529+++ b/arch/sparc/lib/ksyms.c
6530@@ -136,12 +136,18 @@ EXPORT_SYMBOL(__downgrade_write);
6531
6532 /* Atomic counter implementation. */
6533 EXPORT_SYMBOL(atomic_add);
6534+EXPORT_SYMBOL(atomic_add_unchecked);
6535 EXPORT_SYMBOL(atomic_add_ret);
6536+EXPORT_SYMBOL(atomic_add_ret_unchecked);
6537 EXPORT_SYMBOL(atomic_sub);
6538+EXPORT_SYMBOL(atomic_sub_unchecked);
6539 EXPORT_SYMBOL(atomic_sub_ret);
6540 EXPORT_SYMBOL(atomic64_add);
6541+EXPORT_SYMBOL(atomic64_add_unchecked);
6542 EXPORT_SYMBOL(atomic64_add_ret);
6543+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6544 EXPORT_SYMBOL(atomic64_sub);
6545+EXPORT_SYMBOL(atomic64_sub_unchecked);
6546 EXPORT_SYMBOL(atomic64_sub_ret);
6547
6548 /* Atomic bit operations. */
6549diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6550index 301421c..e2535d1 100644
6551--- a/arch/sparc/mm/Makefile
6552+++ b/arch/sparc/mm/Makefile
6553@@ -2,7 +2,7 @@
6554 #
6555
6556 asflags-y := -ansi
6557-ccflags-y := -Werror
6558+#ccflags-y := -Werror
6559
6560 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6561 obj-y += fault_$(BITS).o
6562diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6563index df3155a..b6e32fa 100644
6564--- a/arch/sparc/mm/fault_32.c
6565+++ b/arch/sparc/mm/fault_32.c
6566@@ -21,6 +21,9 @@
6567 #include <linux/perf_event.h>
6568 #include <linux/interrupt.h>
6569 #include <linux/kdebug.h>
6570+#include <linux/slab.h>
6571+#include <linux/pagemap.h>
6572+#include <linux/compiler.h>
6573
6574 #include <asm/page.h>
6575 #include <asm/pgtable.h>
6576@@ -207,6 +210,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6577 return safe_compute_effective_address(regs, insn);
6578 }
6579
6580+#ifdef CONFIG_PAX_PAGEEXEC
6581+#ifdef CONFIG_PAX_DLRESOLVE
6582+static void pax_emuplt_close(struct vm_area_struct *vma)
6583+{
6584+ vma->vm_mm->call_dl_resolve = 0UL;
6585+}
6586+
6587+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6588+{
6589+ unsigned int *kaddr;
6590+
6591+ vmf->page = alloc_page(GFP_HIGHUSER);
6592+ if (!vmf->page)
6593+ return VM_FAULT_OOM;
6594+
6595+ kaddr = kmap(vmf->page);
6596+ memset(kaddr, 0, PAGE_SIZE);
6597+ kaddr[0] = 0x9DE3BFA8U; /* save */
6598+ flush_dcache_page(vmf->page);
6599+ kunmap(vmf->page);
6600+ return VM_FAULT_MAJOR;
6601+}
6602+
6603+static const struct vm_operations_struct pax_vm_ops = {
6604+ .close = pax_emuplt_close,
6605+ .fault = pax_emuplt_fault
6606+};
6607+
6608+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6609+{
6610+ int ret;
6611+
6612+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6613+ vma->vm_mm = current->mm;
6614+ vma->vm_start = addr;
6615+ vma->vm_end = addr + PAGE_SIZE;
6616+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6617+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6618+ vma->vm_ops = &pax_vm_ops;
6619+
6620+ ret = insert_vm_struct(current->mm, vma);
6621+ if (ret)
6622+ return ret;
6623+
6624+ ++current->mm->total_vm;
6625+ return 0;
6626+}
6627+#endif
6628+
6629+/*
6630+ * PaX: decide what to do with offenders (regs->pc = fault address)
6631+ *
6632+ * returns 1 when task should be killed
6633+ * 2 when patched PLT trampoline was detected
6634+ * 3 when unpatched PLT trampoline was detected
6635+ */
6636+static int pax_handle_fetch_fault(struct pt_regs *regs)
6637+{
6638+
6639+#ifdef CONFIG_PAX_EMUPLT
6640+ int err;
6641+
6642+ do { /* PaX: patched PLT emulation #1 */
6643+ unsigned int sethi1, sethi2, jmpl;
6644+
6645+ err = get_user(sethi1, (unsigned int *)regs->pc);
6646+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6647+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6648+
6649+ if (err)
6650+ break;
6651+
6652+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6653+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6654+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6655+ {
6656+ unsigned int addr;
6657+
6658+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6659+ addr = regs->u_regs[UREG_G1];
6660+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6661+ regs->pc = addr;
6662+ regs->npc = addr+4;
6663+ return 2;
6664+ }
6665+ } while (0);
6666+
6667+ do { /* PaX: patched PLT emulation #2 */
6668+ unsigned int ba;
6669+
6670+ err = get_user(ba, (unsigned int *)regs->pc);
6671+
6672+ if (err)
6673+ break;
6674+
6675+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6676+ unsigned int addr;
6677+
6678+ if ((ba & 0xFFC00000U) == 0x30800000U)
6679+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6680+ else
6681+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6682+ regs->pc = addr;
6683+ regs->npc = addr+4;
6684+ return 2;
6685+ }
6686+ } while (0);
6687+
6688+ do { /* PaX: patched PLT emulation #3 */
6689+ unsigned int sethi, bajmpl, nop;
6690+
6691+ err = get_user(sethi, (unsigned int *)regs->pc);
6692+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6693+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6694+
6695+ if (err)
6696+ break;
6697+
6698+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6699+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6700+ nop == 0x01000000U)
6701+ {
6702+ unsigned int addr;
6703+
6704+ addr = (sethi & 0x003FFFFFU) << 10;
6705+ regs->u_regs[UREG_G1] = addr;
6706+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6707+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6708+ else
6709+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6710+ regs->pc = addr;
6711+ regs->npc = addr+4;
6712+ return 2;
6713+ }
6714+ } while (0);
6715+
6716+ do { /* PaX: unpatched PLT emulation step 1 */
6717+ unsigned int sethi, ba, nop;
6718+
6719+ err = get_user(sethi, (unsigned int *)regs->pc);
6720+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6721+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6722+
6723+ if (err)
6724+ break;
6725+
6726+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6727+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6728+ nop == 0x01000000U)
6729+ {
6730+ unsigned int addr, save, call;
6731+
6732+ if ((ba & 0xFFC00000U) == 0x30800000U)
6733+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6734+ else
6735+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6736+
6737+ err = get_user(save, (unsigned int *)addr);
6738+ err |= get_user(call, (unsigned int *)(addr+4));
6739+ err |= get_user(nop, (unsigned int *)(addr+8));
6740+ if (err)
6741+ break;
6742+
6743+#ifdef CONFIG_PAX_DLRESOLVE
6744+ if (save == 0x9DE3BFA8U &&
6745+ (call & 0xC0000000U) == 0x40000000U &&
6746+ nop == 0x01000000U)
6747+ {
6748+ struct vm_area_struct *vma;
6749+ unsigned long call_dl_resolve;
6750+
6751+ down_read(&current->mm->mmap_sem);
6752+ call_dl_resolve = current->mm->call_dl_resolve;
6753+ up_read(&current->mm->mmap_sem);
6754+ if (likely(call_dl_resolve))
6755+ goto emulate;
6756+
6757+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6758+
6759+ down_write(&current->mm->mmap_sem);
6760+ if (current->mm->call_dl_resolve) {
6761+ call_dl_resolve = current->mm->call_dl_resolve;
6762+ up_write(&current->mm->mmap_sem);
6763+ if (vma)
6764+ kmem_cache_free(vm_area_cachep, vma);
6765+ goto emulate;
6766+ }
6767+
6768+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6769+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6770+ up_write(&current->mm->mmap_sem);
6771+ if (vma)
6772+ kmem_cache_free(vm_area_cachep, vma);
6773+ return 1;
6774+ }
6775+
6776+ if (pax_insert_vma(vma, call_dl_resolve)) {
6777+ up_write(&current->mm->mmap_sem);
6778+ kmem_cache_free(vm_area_cachep, vma);
6779+ return 1;
6780+ }
6781+
6782+ current->mm->call_dl_resolve = call_dl_resolve;
6783+ up_write(&current->mm->mmap_sem);
6784+
6785+emulate:
6786+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6787+ regs->pc = call_dl_resolve;
6788+ regs->npc = addr+4;
6789+ return 3;
6790+ }
6791+#endif
6792+
6793+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6794+ if ((save & 0xFFC00000U) == 0x05000000U &&
6795+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6796+ nop == 0x01000000U)
6797+ {
6798+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6799+ regs->u_regs[UREG_G2] = addr + 4;
6800+ addr = (save & 0x003FFFFFU) << 10;
6801+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6802+ regs->pc = addr;
6803+ regs->npc = addr+4;
6804+ return 3;
6805+ }
6806+ }
6807+ } while (0);
6808+
6809+ do { /* PaX: unpatched PLT emulation step 2 */
6810+ unsigned int save, call, nop;
6811+
6812+ err = get_user(save, (unsigned int *)(regs->pc-4));
6813+ err |= get_user(call, (unsigned int *)regs->pc);
6814+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6815+ if (err)
6816+ break;
6817+
6818+ if (save == 0x9DE3BFA8U &&
6819+ (call & 0xC0000000U) == 0x40000000U &&
6820+ nop == 0x01000000U)
6821+ {
6822+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6823+
6824+ regs->u_regs[UREG_RETPC] = regs->pc;
6825+ regs->pc = dl_resolve;
6826+ regs->npc = dl_resolve+4;
6827+ return 3;
6828+ }
6829+ } while (0);
6830+#endif
6831+
6832+ return 1;
6833+}
6834+
6835+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6836+{
6837+ unsigned long i;
6838+
6839+ printk(KERN_ERR "PAX: bytes at PC: ");
6840+ for (i = 0; i < 8; i++) {
6841+ unsigned int c;
6842+ if (get_user(c, (unsigned int *)pc+i))
6843+ printk(KERN_CONT "???????? ");
6844+ else
6845+ printk(KERN_CONT "%08x ", c);
6846+ }
6847+ printk("\n");
6848+}
6849+#endif
6850+
6851 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6852 int text_fault)
6853 {
6854@@ -282,6 +556,24 @@ good_area:
6855 if(!(vma->vm_flags & VM_WRITE))
6856 goto bad_area;
6857 } else {
6858+
6859+#ifdef CONFIG_PAX_PAGEEXEC
6860+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6861+ up_read(&mm->mmap_sem);
6862+ switch (pax_handle_fetch_fault(regs)) {
6863+
6864+#ifdef CONFIG_PAX_EMUPLT
6865+ case 2:
6866+ case 3:
6867+ return;
6868+#endif
6869+
6870+ }
6871+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6872+ do_group_exit(SIGKILL);
6873+ }
6874+#endif
6875+
6876 /* Allow reads even for write-only mappings */
6877 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6878 goto bad_area;
6879diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6880index 1fe0429..8dd5dd5 100644
6881--- a/arch/sparc/mm/fault_64.c
6882+++ b/arch/sparc/mm/fault_64.c
6883@@ -21,6 +21,9 @@
6884 #include <linux/kprobes.h>
6885 #include <linux/kdebug.h>
6886 #include <linux/percpu.h>
6887+#include <linux/slab.h>
6888+#include <linux/pagemap.h>
6889+#include <linux/compiler.h>
6890
6891 #include <asm/page.h>
6892 #include <asm/pgtable.h>
6893@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6894 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6895 regs->tpc);
6896 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6897- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6898+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6899 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6900 dump_stack();
6901 unhandled_fault(regs->tpc, current, regs);
6902@@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6903 show_regs(regs);
6904 }
6905
6906+#ifdef CONFIG_PAX_PAGEEXEC
6907+#ifdef CONFIG_PAX_DLRESOLVE
6908+static void pax_emuplt_close(struct vm_area_struct *vma)
6909+{
6910+ vma->vm_mm->call_dl_resolve = 0UL;
6911+}
6912+
6913+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6914+{
6915+ unsigned int *kaddr;
6916+
6917+ vmf->page = alloc_page(GFP_HIGHUSER);
6918+ if (!vmf->page)
6919+ return VM_FAULT_OOM;
6920+
6921+ kaddr = kmap(vmf->page);
6922+ memset(kaddr, 0, PAGE_SIZE);
6923+ kaddr[0] = 0x9DE3BFA8U; /* save */
6924+ flush_dcache_page(vmf->page);
6925+ kunmap(vmf->page);
6926+ return VM_FAULT_MAJOR;
6927+}
6928+
6929+static const struct vm_operations_struct pax_vm_ops = {
6930+ .close = pax_emuplt_close,
6931+ .fault = pax_emuplt_fault
6932+};
6933+
6934+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6935+{
6936+ int ret;
6937+
6938+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6939+ vma->vm_mm = current->mm;
6940+ vma->vm_start = addr;
6941+ vma->vm_end = addr + PAGE_SIZE;
6942+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6943+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6944+ vma->vm_ops = &pax_vm_ops;
6945+
6946+ ret = insert_vm_struct(current->mm, vma);
6947+ if (ret)
6948+ return ret;
6949+
6950+ ++current->mm->total_vm;
6951+ return 0;
6952+}
6953+#endif
6954+
6955+/*
6956+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6957+ *
6958+ * returns 1 when task should be killed
6959+ * 2 when patched PLT trampoline was detected
6960+ * 3 when unpatched PLT trampoline was detected
6961+ */
6962+static int pax_handle_fetch_fault(struct pt_regs *regs)
6963+{
6964+
6965+#ifdef CONFIG_PAX_EMUPLT
6966+ int err;
6967+
6968+ do { /* PaX: patched PLT emulation #1 */
6969+ unsigned int sethi1, sethi2, jmpl;
6970+
6971+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6972+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6973+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6974+
6975+ if (err)
6976+ break;
6977+
6978+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6979+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6980+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6981+ {
6982+ unsigned long addr;
6983+
6984+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6985+ addr = regs->u_regs[UREG_G1];
6986+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6987+
6988+ if (test_thread_flag(TIF_32BIT))
6989+ addr &= 0xFFFFFFFFUL;
6990+
6991+ regs->tpc = addr;
6992+ regs->tnpc = addr+4;
6993+ return 2;
6994+ }
6995+ } while (0);
6996+
6997+ do { /* PaX: patched PLT emulation #2 */
6998+ unsigned int ba;
6999+
7000+ err = get_user(ba, (unsigned int *)regs->tpc);
7001+
7002+ if (err)
7003+ break;
7004+
7005+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7006+ unsigned long addr;
7007+
7008+ if ((ba & 0xFFC00000U) == 0x30800000U)
7009+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7010+ else
7011+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 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 #3 */
7023+ unsigned int sethi, bajmpl, nop;
7024+
7025+ err = get_user(sethi, (unsigned int *)regs->tpc);
7026+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
7027+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7028+
7029+ if (err)
7030+ break;
7031+
7032+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7033+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7034+ nop == 0x01000000U)
7035+ {
7036+ unsigned long addr;
7037+
7038+ addr = (sethi & 0x003FFFFFU) << 10;
7039+ regs->u_regs[UREG_G1] = addr;
7040+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7041+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7042+ else
7043+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7044+
7045+ if (test_thread_flag(TIF_32BIT))
7046+ addr &= 0xFFFFFFFFUL;
7047+
7048+ regs->tpc = addr;
7049+ regs->tnpc = addr+4;
7050+ return 2;
7051+ }
7052+ } while (0);
7053+
7054+ do { /* PaX: patched PLT emulation #4 */
7055+ unsigned int sethi, mov1, call, mov2;
7056+
7057+ err = get_user(sethi, (unsigned int *)regs->tpc);
7058+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
7059+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
7060+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
7061+
7062+ if (err)
7063+ break;
7064+
7065+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7066+ mov1 == 0x8210000FU &&
7067+ (call & 0xC0000000U) == 0x40000000U &&
7068+ mov2 == 0x9E100001U)
7069+ {
7070+ unsigned long addr;
7071+
7072+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7073+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7074+
7075+ if (test_thread_flag(TIF_32BIT))
7076+ addr &= 0xFFFFFFFFUL;
7077+
7078+ regs->tpc = addr;
7079+ regs->tnpc = addr+4;
7080+ return 2;
7081+ }
7082+ } while (0);
7083+
7084+ do { /* PaX: patched PLT emulation #5 */
7085+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7086+
7087+ err = get_user(sethi, (unsigned int *)regs->tpc);
7088+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7089+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7090+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7091+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7092+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7093+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7094+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7095+
7096+ if (err)
7097+ break;
7098+
7099+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7100+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7101+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7102+ (or1 & 0xFFFFE000U) == 0x82106000U &&
7103+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7104+ sllx == 0x83287020U &&
7105+ jmpl == 0x81C04005U &&
7106+ nop == 0x01000000U)
7107+ {
7108+ unsigned long addr;
7109+
7110+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7111+ regs->u_regs[UREG_G1] <<= 32;
7112+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7113+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7114+ regs->tpc = addr;
7115+ regs->tnpc = addr+4;
7116+ return 2;
7117+ }
7118+ } while (0);
7119+
7120+ do { /* PaX: patched PLT emulation #6 */
7121+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7122+
7123+ err = get_user(sethi, (unsigned int *)regs->tpc);
7124+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7125+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7126+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7127+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7128+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7129+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7130+
7131+ if (err)
7132+ break;
7133+
7134+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7135+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7136+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7137+ sllx == 0x83287020U &&
7138+ (or & 0xFFFFE000U) == 0x8A116000U &&
7139+ jmpl == 0x81C04005U &&
7140+ nop == 0x01000000U)
7141+ {
7142+ unsigned long addr;
7143+
7144+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7145+ regs->u_regs[UREG_G1] <<= 32;
7146+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7147+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7148+ regs->tpc = addr;
7149+ regs->tnpc = addr+4;
7150+ return 2;
7151+ }
7152+ } while (0);
7153+
7154+ do { /* PaX: unpatched PLT emulation step 1 */
7155+ unsigned int sethi, ba, nop;
7156+
7157+ err = get_user(sethi, (unsigned int *)regs->tpc);
7158+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7159+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7160+
7161+ if (err)
7162+ break;
7163+
7164+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7165+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7166+ nop == 0x01000000U)
7167+ {
7168+ unsigned long addr;
7169+ unsigned int save, call;
7170+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7171+
7172+ if ((ba & 0xFFC00000U) == 0x30800000U)
7173+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7174+ else
7175+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7176+
7177+ if (test_thread_flag(TIF_32BIT))
7178+ addr &= 0xFFFFFFFFUL;
7179+
7180+ err = get_user(save, (unsigned int *)addr);
7181+ err |= get_user(call, (unsigned int *)(addr+4));
7182+ err |= get_user(nop, (unsigned int *)(addr+8));
7183+ if (err)
7184+ break;
7185+
7186+#ifdef CONFIG_PAX_DLRESOLVE
7187+ if (save == 0x9DE3BFA8U &&
7188+ (call & 0xC0000000U) == 0x40000000U &&
7189+ nop == 0x01000000U)
7190+ {
7191+ struct vm_area_struct *vma;
7192+ unsigned long call_dl_resolve;
7193+
7194+ down_read(&current->mm->mmap_sem);
7195+ call_dl_resolve = current->mm->call_dl_resolve;
7196+ up_read(&current->mm->mmap_sem);
7197+ if (likely(call_dl_resolve))
7198+ goto emulate;
7199+
7200+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7201+
7202+ down_write(&current->mm->mmap_sem);
7203+ if (current->mm->call_dl_resolve) {
7204+ call_dl_resolve = current->mm->call_dl_resolve;
7205+ up_write(&current->mm->mmap_sem);
7206+ if (vma)
7207+ kmem_cache_free(vm_area_cachep, vma);
7208+ goto emulate;
7209+ }
7210+
7211+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7212+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7213+ up_write(&current->mm->mmap_sem);
7214+ if (vma)
7215+ kmem_cache_free(vm_area_cachep, vma);
7216+ return 1;
7217+ }
7218+
7219+ if (pax_insert_vma(vma, call_dl_resolve)) {
7220+ up_write(&current->mm->mmap_sem);
7221+ kmem_cache_free(vm_area_cachep, vma);
7222+ return 1;
7223+ }
7224+
7225+ current->mm->call_dl_resolve = call_dl_resolve;
7226+ up_write(&current->mm->mmap_sem);
7227+
7228+emulate:
7229+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7230+ regs->tpc = call_dl_resolve;
7231+ regs->tnpc = addr+4;
7232+ return 3;
7233+ }
7234+#endif
7235+
7236+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7237+ if ((save & 0xFFC00000U) == 0x05000000U &&
7238+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7239+ nop == 0x01000000U)
7240+ {
7241+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7242+ regs->u_regs[UREG_G2] = addr + 4;
7243+ addr = (save & 0x003FFFFFU) << 10;
7244+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7245+
7246+ if (test_thread_flag(TIF_32BIT))
7247+ addr &= 0xFFFFFFFFUL;
7248+
7249+ regs->tpc = addr;
7250+ regs->tnpc = addr+4;
7251+ return 3;
7252+ }
7253+
7254+ /* PaX: 64-bit PLT stub */
7255+ err = get_user(sethi1, (unsigned int *)addr);
7256+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7257+ err |= get_user(or1, (unsigned int *)(addr+8));
7258+ err |= get_user(or2, (unsigned int *)(addr+12));
7259+ err |= get_user(sllx, (unsigned int *)(addr+16));
7260+ err |= get_user(add, (unsigned int *)(addr+20));
7261+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7262+ err |= get_user(nop, (unsigned int *)(addr+28));
7263+ if (err)
7264+ break;
7265+
7266+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7267+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7268+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7269+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7270+ sllx == 0x89293020U &&
7271+ add == 0x8A010005U &&
7272+ jmpl == 0x89C14000U &&
7273+ nop == 0x01000000U)
7274+ {
7275+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7276+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7277+ regs->u_regs[UREG_G4] <<= 32;
7278+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7279+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7280+ regs->u_regs[UREG_G4] = addr + 24;
7281+ addr = regs->u_regs[UREG_G5];
7282+ regs->tpc = addr;
7283+ regs->tnpc = addr+4;
7284+ return 3;
7285+ }
7286+ }
7287+ } while (0);
7288+
7289+#ifdef CONFIG_PAX_DLRESOLVE
7290+ do { /* PaX: unpatched PLT emulation step 2 */
7291+ unsigned int save, call, nop;
7292+
7293+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7294+ err |= get_user(call, (unsigned int *)regs->tpc);
7295+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7296+ if (err)
7297+ break;
7298+
7299+ if (save == 0x9DE3BFA8U &&
7300+ (call & 0xC0000000U) == 0x40000000U &&
7301+ nop == 0x01000000U)
7302+ {
7303+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7304+
7305+ if (test_thread_flag(TIF_32BIT))
7306+ dl_resolve &= 0xFFFFFFFFUL;
7307+
7308+ regs->u_regs[UREG_RETPC] = regs->tpc;
7309+ regs->tpc = dl_resolve;
7310+ regs->tnpc = dl_resolve+4;
7311+ return 3;
7312+ }
7313+ } while (0);
7314+#endif
7315+
7316+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7317+ unsigned int sethi, ba, nop;
7318+
7319+ err = get_user(sethi, (unsigned int *)regs->tpc);
7320+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7321+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7322+
7323+ if (err)
7324+ break;
7325+
7326+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7327+ (ba & 0xFFF00000U) == 0x30600000U &&
7328+ nop == 0x01000000U)
7329+ {
7330+ unsigned long addr;
7331+
7332+ addr = (sethi & 0x003FFFFFU) << 10;
7333+ regs->u_regs[UREG_G1] = addr;
7334+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7335+
7336+ if (test_thread_flag(TIF_32BIT))
7337+ addr &= 0xFFFFFFFFUL;
7338+
7339+ regs->tpc = addr;
7340+ regs->tnpc = addr+4;
7341+ return 2;
7342+ }
7343+ } while (0);
7344+
7345+#endif
7346+
7347+ return 1;
7348+}
7349+
7350+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7351+{
7352+ unsigned long i;
7353+
7354+ printk(KERN_ERR "PAX: bytes at PC: ");
7355+ for (i = 0; i < 8; i++) {
7356+ unsigned int c;
7357+ if (get_user(c, (unsigned int *)pc+i))
7358+ printk(KERN_CONT "???????? ");
7359+ else
7360+ printk(KERN_CONT "%08x ", c);
7361+ }
7362+ printk("\n");
7363+}
7364+#endif
7365+
7366 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7367 {
7368 struct mm_struct *mm = current->mm;
7369@@ -343,6 +806,29 @@ retry:
7370 if (!vma)
7371 goto bad_area;
7372
7373+#ifdef CONFIG_PAX_PAGEEXEC
7374+ /* PaX: detect ITLB misses on non-exec pages */
7375+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7376+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7377+ {
7378+ if (address != regs->tpc)
7379+ goto good_area;
7380+
7381+ up_read(&mm->mmap_sem);
7382+ switch (pax_handle_fetch_fault(regs)) {
7383+
7384+#ifdef CONFIG_PAX_EMUPLT
7385+ case 2:
7386+ case 3:
7387+ return;
7388+#endif
7389+
7390+ }
7391+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7392+ do_group_exit(SIGKILL);
7393+ }
7394+#endif
7395+
7396 /* Pure DTLB misses do not tell us whether the fault causing
7397 * load/store/atomic was a write or not, it only says that there
7398 * was no match. So in such a case we (carefully) read the
7399diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7400index 07e1453..0a7d9e9 100644
7401--- a/arch/sparc/mm/hugetlbpage.c
7402+++ b/arch/sparc/mm/hugetlbpage.c
7403@@ -67,7 +67,7 @@ full_search:
7404 }
7405 return -ENOMEM;
7406 }
7407- if (likely(!vma || addr + len <= vma->vm_start)) {
7408+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7409 /*
7410 * Remember the place where we stopped the search:
7411 */
7412@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7413 /* make sure it can fit in the remaining address space */
7414 if (likely(addr > len)) {
7415 vma = find_vma(mm, addr-len);
7416- if (!vma || addr <= vma->vm_start) {
7417+ if (check_heap_stack_gap(vma, addr - len, len)) {
7418 /* remember the address as a hint for next time */
7419 return (mm->free_area_cache = addr-len);
7420 }
7421@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7422 if (unlikely(mm->mmap_base < len))
7423 goto bottomup;
7424
7425- addr = (mm->mmap_base-len) & HPAGE_MASK;
7426+ addr = mm->mmap_base - len;
7427
7428 do {
7429+ addr &= HPAGE_MASK;
7430 /*
7431 * Lookup failure means no vma is above this address,
7432 * else if new region fits below vma->vm_start,
7433 * return with success:
7434 */
7435 vma = find_vma(mm, addr);
7436- if (likely(!vma || addr+len <= vma->vm_start)) {
7437+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7438 /* remember the address as a hint for next time */
7439 return (mm->free_area_cache = addr);
7440 }
7441@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7442 mm->cached_hole_size = vma->vm_start - addr;
7443
7444 /* try just below the current vma->vm_start */
7445- addr = (vma->vm_start-len) & HPAGE_MASK;
7446- } while (likely(len < vma->vm_start));
7447+ addr = skip_heap_stack_gap(vma, len);
7448+ } while (!IS_ERR_VALUE(addr));
7449
7450 bottomup:
7451 /*
7452@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7453 if (addr) {
7454 addr = ALIGN(addr, HPAGE_SIZE);
7455 vma = find_vma(mm, addr);
7456- if (task_size - len >= addr &&
7457- (!vma || addr + len <= vma->vm_start))
7458+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7459 return addr;
7460 }
7461 if (mm->get_unmapped_area == arch_get_unmapped_area)
7462diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
7463index c5f9021..7591bae 100644
7464--- a/arch/sparc/mm/init_32.c
7465+++ b/arch/sparc/mm/init_32.c
7466@@ -315,6 +315,9 @@ extern void device_scan(void);
7467 pgprot_t PAGE_SHARED __read_mostly;
7468 EXPORT_SYMBOL(PAGE_SHARED);
7469
7470+pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7471+EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7472+
7473 void __init paging_init(void)
7474 {
7475 switch(sparc_cpu_model) {
7476@@ -343,17 +346,17 @@ void __init paging_init(void)
7477
7478 /* Initialize the protection map with non-constant, MMU dependent values. */
7479 protection_map[0] = PAGE_NONE;
7480- protection_map[1] = PAGE_READONLY;
7481- protection_map[2] = PAGE_COPY;
7482- protection_map[3] = PAGE_COPY;
7483+ protection_map[1] = PAGE_READONLY_NOEXEC;
7484+ protection_map[2] = PAGE_COPY_NOEXEC;
7485+ protection_map[3] = PAGE_COPY_NOEXEC;
7486 protection_map[4] = PAGE_READONLY;
7487 protection_map[5] = PAGE_READONLY;
7488 protection_map[6] = PAGE_COPY;
7489 protection_map[7] = PAGE_COPY;
7490 protection_map[8] = PAGE_NONE;
7491- protection_map[9] = PAGE_READONLY;
7492- protection_map[10] = PAGE_SHARED;
7493- protection_map[11] = PAGE_SHARED;
7494+ protection_map[9] = PAGE_READONLY_NOEXEC;
7495+ protection_map[10] = PAGE_SHARED_NOEXEC;
7496+ protection_map[11] = PAGE_SHARED_NOEXEC;
7497 protection_map[12] = PAGE_READONLY;
7498 protection_map[13] = PAGE_READONLY;
7499 protection_map[14] = PAGE_SHARED;
7500diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
7501index cbef74e..c38fead 100644
7502--- a/arch/sparc/mm/srmmu.c
7503+++ b/arch/sparc/mm/srmmu.c
7504@@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7505 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7506 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7507 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7508+
7509+#ifdef CONFIG_PAX_PAGEEXEC
7510+ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7511+ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7512+ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7513+#endif
7514+
7515 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7516 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7517
7518diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7519index f4500c6..889656c 100644
7520--- a/arch/tile/include/asm/atomic_64.h
7521+++ b/arch/tile/include/asm/atomic_64.h
7522@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7523
7524 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7525
7526+#define atomic64_read_unchecked(v) atomic64_read(v)
7527+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7528+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7529+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7530+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7531+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7532+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7533+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7534+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7535+
7536 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7537 #define smp_mb__before_atomic_dec() smp_mb()
7538 #define smp_mb__after_atomic_dec() smp_mb()
7539diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7540index 392e533..536b092 100644
7541--- a/arch/tile/include/asm/cache.h
7542+++ b/arch/tile/include/asm/cache.h
7543@@ -15,11 +15,12 @@
7544 #ifndef _ASM_TILE_CACHE_H
7545 #define _ASM_TILE_CACHE_H
7546
7547+#include <linux/const.h>
7548 #include <arch/chip.h>
7549
7550 /* bytes per L1 data cache line */
7551 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7552-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7553+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7554
7555 /* bytes per L2 cache line */
7556 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7557diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7558index ef34d2c..d6ce60c 100644
7559--- a/arch/tile/include/asm/uaccess.h
7560+++ b/arch/tile/include/asm/uaccess.h
7561@@ -361,9 +361,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7562 const void __user *from,
7563 unsigned long n)
7564 {
7565- int sz = __compiletime_object_size(to);
7566+ size_t sz = __compiletime_object_size(to);
7567
7568- if (likely(sz == -1 || sz >= n))
7569+ if (likely(sz == (size_t)-1 || sz >= n))
7570 n = _copy_from_user(to, from, n);
7571 else
7572 copy_from_user_overflow();
7573diff --git a/arch/um/Makefile b/arch/um/Makefile
7574index 55c0661..86ad413 100644
7575--- a/arch/um/Makefile
7576+++ b/arch/um/Makefile
7577@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7578 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7579 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7580
7581+ifdef CONSTIFY_PLUGIN
7582+USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7583+endif
7584+
7585 #This will adjust *FLAGS accordingly to the platform.
7586 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7587
7588diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7589index 19e1bdd..3665b77 100644
7590--- a/arch/um/include/asm/cache.h
7591+++ b/arch/um/include/asm/cache.h
7592@@ -1,6 +1,7 @@
7593 #ifndef __UM_CACHE_H
7594 #define __UM_CACHE_H
7595
7596+#include <linux/const.h>
7597
7598 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7599 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7600@@ -12,6 +13,6 @@
7601 # define L1_CACHE_SHIFT 5
7602 #endif
7603
7604-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7605+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7606
7607 #endif
7608diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7609index 6c03acd..a5e0215 100644
7610--- a/arch/um/include/asm/kmap_types.h
7611+++ b/arch/um/include/asm/kmap_types.h
7612@@ -23,6 +23,7 @@ enum km_type {
7613 KM_IRQ1,
7614 KM_SOFTIRQ0,
7615 KM_SOFTIRQ1,
7616+ KM_CLEARPAGE,
7617 KM_TYPE_NR
7618 };
7619
7620diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7621index 7cfc3ce..cbd1a58 100644
7622--- a/arch/um/include/asm/page.h
7623+++ b/arch/um/include/asm/page.h
7624@@ -14,6 +14,9 @@
7625 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7626 #define PAGE_MASK (~(PAGE_SIZE-1))
7627
7628+#define ktla_ktva(addr) (addr)
7629+#define ktva_ktla(addr) (addr)
7630+
7631 #ifndef __ASSEMBLY__
7632
7633 struct page;
7634diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7635index 0032f92..cd151e0 100644
7636--- a/arch/um/include/asm/pgtable-3level.h
7637+++ b/arch/um/include/asm/pgtable-3level.h
7638@@ -58,6 +58,7 @@
7639 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7640 #define pud_populate(mm, pud, pmd) \
7641 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7642+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7643
7644 #ifdef CONFIG_64BIT
7645 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7646diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7647index 2b73ded..804f540 100644
7648--- a/arch/um/kernel/process.c
7649+++ b/arch/um/kernel/process.c
7650@@ -404,22 +404,6 @@ int singlestepping(void * t)
7651 return 2;
7652 }
7653
7654-/*
7655- * Only x86 and x86_64 have an arch_align_stack().
7656- * All other arches have "#define arch_align_stack(x) (x)"
7657- * in their asm/system.h
7658- * As this is included in UML from asm-um/system-generic.h,
7659- * we can use it to behave as the subarch does.
7660- */
7661-#ifndef arch_align_stack
7662-unsigned long arch_align_stack(unsigned long sp)
7663-{
7664- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7665- sp -= get_random_int() % 8192;
7666- return sp & ~0xf;
7667-}
7668-#endif
7669-
7670 unsigned long get_wchan(struct task_struct *p)
7671 {
7672 unsigned long stack_page, sp, ip;
7673diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7674index ad8f795..2c7eec6 100644
7675--- a/arch/unicore32/include/asm/cache.h
7676+++ b/arch/unicore32/include/asm/cache.h
7677@@ -12,8 +12,10 @@
7678 #ifndef __UNICORE_CACHE_H__
7679 #define __UNICORE_CACHE_H__
7680
7681-#define L1_CACHE_SHIFT (5)
7682-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7683+#include <linux/const.h>
7684+
7685+#define L1_CACHE_SHIFT 5
7686+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7687
7688 /*
7689 * Memory returned by kmalloc() may be used for DMA, so we must make
7690diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7691index c9866b0..fe53aef 100644
7692--- a/arch/x86/Kconfig
7693+++ b/arch/x86/Kconfig
7694@@ -229,7 +229,7 @@ config X86_HT
7695
7696 config X86_32_LAZY_GS
7697 def_bool y
7698- depends on X86_32 && !CC_STACKPROTECTOR
7699+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7700
7701 config ARCH_HWEIGHT_CFLAGS
7702 string
7703@@ -1042,7 +1042,7 @@ choice
7704
7705 config NOHIGHMEM
7706 bool "off"
7707- depends on !X86_NUMAQ
7708+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7709 ---help---
7710 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7711 However, the address space of 32-bit x86 processors is only 4
7712@@ -1079,7 +1079,7 @@ config NOHIGHMEM
7713
7714 config HIGHMEM4G
7715 bool "4GB"
7716- depends on !X86_NUMAQ
7717+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7718 ---help---
7719 Select this if you have a 32-bit processor and between 1 and 4
7720 gigabytes of physical RAM.
7721@@ -1133,7 +1133,7 @@ config PAGE_OFFSET
7722 hex
7723 default 0xB0000000 if VMSPLIT_3G_OPT
7724 default 0x80000000 if VMSPLIT_2G
7725- default 0x78000000 if VMSPLIT_2G_OPT
7726+ default 0x70000000 if VMSPLIT_2G_OPT
7727 default 0x40000000 if VMSPLIT_1G
7728 default 0xC0000000
7729 depends on X86_32
7730@@ -1523,6 +1523,7 @@ config SECCOMP
7731
7732 config CC_STACKPROTECTOR
7733 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7734+ depends on X86_64 || !PAX_MEMORY_UDEREF
7735 ---help---
7736 This option turns on the -fstack-protector GCC feature. This
7737 feature puts, at the beginning of functions, a canary value on
7738@@ -1580,6 +1581,7 @@ config KEXEC_JUMP
7739 config PHYSICAL_START
7740 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7741 default "0x1000000"
7742+ range 0x400000 0x40000000
7743 ---help---
7744 This gives the physical address where the kernel is loaded.
7745
7746@@ -1643,6 +1645,7 @@ config X86_NEED_RELOCS
7747 config PHYSICAL_ALIGN
7748 hex "Alignment value to which kernel should be aligned" if X86_32
7749 default "0x1000000"
7750+ range 0x400000 0x1000000 if PAX_KERNEXEC
7751 range 0x2000 0x1000000
7752 ---help---
7753 This value puts the alignment restrictions on physical address
7754@@ -1674,9 +1677,10 @@ config HOTPLUG_CPU
7755 Say N if you want to disable CPU hotplug.
7756
7757 config COMPAT_VDSO
7758- def_bool y
7759+ def_bool n
7760 prompt "Compat VDSO support"
7761 depends on X86_32 || IA32_EMULATION
7762+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7763 ---help---
7764 Map the 32-bit VDSO to the predictable old-style address too.
7765
7766diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7767index 706e12e..62e4feb 100644
7768--- a/arch/x86/Kconfig.cpu
7769+++ b/arch/x86/Kconfig.cpu
7770@@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7771
7772 config X86_F00F_BUG
7773 def_bool y
7774- depends on M586MMX || M586TSC || M586 || M486 || M386
7775+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7776
7777 config X86_INVD_BUG
7778 def_bool y
7779@@ -358,7 +358,7 @@ config X86_POPAD_OK
7780
7781 config X86_ALIGNMENT_16
7782 def_bool y
7783- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7784+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7785
7786 config X86_INTEL_USERCOPY
7787 def_bool y
7788@@ -404,7 +404,7 @@ config X86_CMPXCHG64
7789 # generates cmov.
7790 config X86_CMOV
7791 def_bool y
7792- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7793+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7794
7795 config X86_MINIMUM_CPU_FAMILY
7796 int
7797diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7798index e46c214..ab62fd1 100644
7799--- a/arch/x86/Kconfig.debug
7800+++ b/arch/x86/Kconfig.debug
7801@@ -84,7 +84,7 @@ config X86_PTDUMP
7802 config DEBUG_RODATA
7803 bool "Write protect kernel read-only data structures"
7804 default y
7805- depends on DEBUG_KERNEL
7806+ depends on DEBUG_KERNEL && BROKEN
7807 ---help---
7808 Mark the kernel read-only data as write-protected in the pagetables,
7809 in order to catch accidental (and incorrect) writes to such const
7810@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7811
7812 config DEBUG_SET_MODULE_RONX
7813 bool "Set loadable kernel module data as NX and text as RO"
7814- depends on MODULES
7815+ depends on MODULES && BROKEN
7816 ---help---
7817 This option helps catch unintended modifications to loadable
7818 kernel module's text and read-only data. It also prevents execution
7819@@ -275,7 +275,7 @@ config OPTIMIZE_INLINING
7820
7821 config DEBUG_STRICT_USER_COPY_CHECKS
7822 bool "Strict copy size checks"
7823- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7824+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7825 ---help---
7826 Enabling this option turns a certain set of sanity checks for user
7827 copy operations into compile time failures.
7828diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7829index b1c611e..2c1a823 100644
7830--- a/arch/x86/Makefile
7831+++ b/arch/x86/Makefile
7832@@ -46,6 +46,7 @@ else
7833 UTS_MACHINE := x86_64
7834 CHECKFLAGS += -D__x86_64__ -m64
7835
7836+ biarch := $(call cc-option,-m64)
7837 KBUILD_AFLAGS += -m64
7838 KBUILD_CFLAGS += -m64
7839
7840@@ -222,3 +223,12 @@ define archhelp
7841 echo ' FDARGS="..." arguments for the booted kernel'
7842 echo ' FDINITRD=file initrd for the booted kernel'
7843 endef
7844+
7845+define OLD_LD
7846+
7847+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7848+*** Please upgrade your binutils to 2.18 or newer
7849+endef
7850+
7851+archprepare:
7852+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7853diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7854index 5a747dd..ff7b12c 100644
7855--- a/arch/x86/boot/Makefile
7856+++ b/arch/x86/boot/Makefile
7857@@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7858 $(call cc-option, -fno-stack-protector) \
7859 $(call cc-option, -mpreferred-stack-boundary=2)
7860 KBUILD_CFLAGS += $(call cc-option, -m32)
7861+ifdef CONSTIFY_PLUGIN
7862+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7863+endif
7864 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7865 GCOV_PROFILE := n
7866
7867diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7868index 878e4b9..20537ab 100644
7869--- a/arch/x86/boot/bitops.h
7870+++ b/arch/x86/boot/bitops.h
7871@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7872 u8 v;
7873 const u32 *p = (const u32 *)addr;
7874
7875- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7876+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7877 return v;
7878 }
7879
7880@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7881
7882 static inline void set_bit(int nr, void *addr)
7883 {
7884- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7885+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7886 }
7887
7888 #endif /* BOOT_BITOPS_H */
7889diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7890index 18997e5..83d9c67 100644
7891--- a/arch/x86/boot/boot.h
7892+++ b/arch/x86/boot/boot.h
7893@@ -85,7 +85,7 @@ static inline void io_delay(void)
7894 static inline u16 ds(void)
7895 {
7896 u16 seg;
7897- asm("movw %%ds,%0" : "=rm" (seg));
7898+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7899 return seg;
7900 }
7901
7902@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7903 static inline int memcmp(const void *s1, const void *s2, size_t len)
7904 {
7905 u8 diff;
7906- asm("repe; cmpsb; setnz %0"
7907+ asm volatile("repe; cmpsb; setnz %0"
7908 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7909 return diff;
7910 }
7911diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7912index e398bb5..3a382ca 100644
7913--- a/arch/x86/boot/compressed/Makefile
7914+++ b/arch/x86/boot/compressed/Makefile
7915@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7916 KBUILD_CFLAGS += $(cflags-y)
7917 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7918 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7919+ifdef CONSTIFY_PLUGIN
7920+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7921+endif
7922
7923 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7924 GCOV_PROFILE := n
7925diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7926index 0cdfc0d..6e79437 100644
7927--- a/arch/x86/boot/compressed/eboot.c
7928+++ b/arch/x86/boot/compressed/eboot.c
7929@@ -122,7 +122,6 @@ again:
7930 *addr = max_addr;
7931 }
7932
7933-free_pool:
7934 efi_call_phys1(sys_table->boottime->free_pool, map);
7935
7936 fail:
7937@@ -186,7 +185,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7938 if (i == map_size / desc_size)
7939 status = EFI_NOT_FOUND;
7940
7941-free_pool:
7942 efi_call_phys1(sys_table->boottime->free_pool, map);
7943 fail:
7944 return status;
7945diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7946index c85e3ac..6f5aa80 100644
7947--- a/arch/x86/boot/compressed/head_32.S
7948+++ b/arch/x86/boot/compressed/head_32.S
7949@@ -106,7 +106,7 @@ preferred_addr:
7950 notl %eax
7951 andl %eax, %ebx
7952 #else
7953- movl $LOAD_PHYSICAL_ADDR, %ebx
7954+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7955 #endif
7956
7957 /* Target address to relocate to for decompression */
7958@@ -192,7 +192,7 @@ relocated:
7959 * and where it was actually loaded.
7960 */
7961 movl %ebp, %ebx
7962- subl $LOAD_PHYSICAL_ADDR, %ebx
7963+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7964 jz 2f /* Nothing to be done if loaded at compiled addr. */
7965 /*
7966 * Process relocations.
7967@@ -200,8 +200,7 @@ relocated:
7968
7969 1: subl $4, %edi
7970 movl (%edi), %ecx
7971- testl %ecx, %ecx
7972- jz 2f
7973+ jecxz 2f
7974 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7975 jmp 1b
7976 2:
7977diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7978index 87e03a1..0d94c76 100644
7979--- a/arch/x86/boot/compressed/head_64.S
7980+++ b/arch/x86/boot/compressed/head_64.S
7981@@ -91,7 +91,7 @@ ENTRY(startup_32)
7982 notl %eax
7983 andl %eax, %ebx
7984 #else
7985- movl $LOAD_PHYSICAL_ADDR, %ebx
7986+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7987 #endif
7988
7989 /* Target address to relocate to for decompression */
7990@@ -263,7 +263,7 @@ preferred_addr:
7991 notq %rax
7992 andq %rax, %rbp
7993 #else
7994- movq $LOAD_PHYSICAL_ADDR, %rbp
7995+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7996 #endif
7997
7998 /* Target address to relocate to for decompression */
7999diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
8000index 7116dcb..d9ae1d7 100644
8001--- a/arch/x86/boot/compressed/misc.c
8002+++ b/arch/x86/boot/compressed/misc.c
8003@@ -310,7 +310,7 @@ static void parse_elf(void *output)
8004 case PT_LOAD:
8005 #ifdef CONFIG_RELOCATABLE
8006 dest = output;
8007- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
8008+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
8009 #else
8010 dest = (void *)(phdr->p_paddr);
8011 #endif
8012@@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
8013 error("Destination address too large");
8014 #endif
8015 #ifndef CONFIG_RELOCATABLE
8016- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
8017+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
8018 error("Wrong destination address");
8019 #endif
8020
8021diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
8022index 4d3ff03..e4972ff 100644
8023--- a/arch/x86/boot/cpucheck.c
8024+++ b/arch/x86/boot/cpucheck.c
8025@@ -74,7 +74,7 @@ static int has_fpu(void)
8026 u16 fcw = -1, fsw = -1;
8027 u32 cr0;
8028
8029- asm("movl %%cr0,%0" : "=r" (cr0));
8030+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
8031 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
8032 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
8033 asm volatile("movl %0,%%cr0" : : "r" (cr0));
8034@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
8035 {
8036 u32 f0, f1;
8037
8038- asm("pushfl ; "
8039+ asm volatile("pushfl ; "
8040 "pushfl ; "
8041 "popl %0 ; "
8042 "movl %0,%1 ; "
8043@@ -115,7 +115,7 @@ static void get_flags(void)
8044 set_bit(X86_FEATURE_FPU, cpu.flags);
8045
8046 if (has_eflag(X86_EFLAGS_ID)) {
8047- asm("cpuid"
8048+ asm volatile("cpuid"
8049 : "=a" (max_intel_level),
8050 "=b" (cpu_vendor[0]),
8051 "=d" (cpu_vendor[1]),
8052@@ -124,7 +124,7 @@ static void get_flags(void)
8053
8054 if (max_intel_level >= 0x00000001 &&
8055 max_intel_level <= 0x0000ffff) {
8056- asm("cpuid"
8057+ asm volatile("cpuid"
8058 : "=a" (tfms),
8059 "=c" (cpu.flags[4]),
8060 "=d" (cpu.flags[0])
8061@@ -136,7 +136,7 @@ static void get_flags(void)
8062 cpu.model += ((tfms >> 16) & 0xf) << 4;
8063 }
8064
8065- asm("cpuid"
8066+ asm volatile("cpuid"
8067 : "=a" (max_amd_level)
8068 : "a" (0x80000000)
8069 : "ebx", "ecx", "edx");
8070@@ -144,7 +144,7 @@ static void get_flags(void)
8071 if (max_amd_level >= 0x80000001 &&
8072 max_amd_level <= 0x8000ffff) {
8073 u32 eax = 0x80000001;
8074- asm("cpuid"
8075+ asm volatile("cpuid"
8076 : "+a" (eax),
8077 "=c" (cpu.flags[6]),
8078 "=d" (cpu.flags[1])
8079@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8080 u32 ecx = MSR_K7_HWCR;
8081 u32 eax, edx;
8082
8083- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8084+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8085 eax &= ~(1 << 15);
8086- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8087+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8088
8089 get_flags(); /* Make sure it really did something */
8090 err = check_flags();
8091@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8092 u32 ecx = MSR_VIA_FCR;
8093 u32 eax, edx;
8094
8095- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8096+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8097 eax |= (1<<1)|(1<<7);
8098- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8099+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8100
8101 set_bit(X86_FEATURE_CX8, cpu.flags);
8102 err = check_flags();
8103@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8104 u32 eax, edx;
8105 u32 level = 1;
8106
8107- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8108- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8109- asm("cpuid"
8110+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8111+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8112+ asm volatile("cpuid"
8113 : "+a" (level), "=d" (cpu.flags[0])
8114 : : "ecx", "ebx");
8115- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8116+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8117
8118 err = check_flags();
8119 }
8120diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8121index f1bbeeb..aff09cb 100644
8122--- a/arch/x86/boot/header.S
8123+++ b/arch/x86/boot/header.S
8124@@ -372,7 +372,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
8125 # single linked list of
8126 # struct setup_data
8127
8128-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8129+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8130
8131 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8132 #define VO_INIT_SIZE (VO__end - VO__text)
8133diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8134index db75d07..8e6d0af 100644
8135--- a/arch/x86/boot/memory.c
8136+++ b/arch/x86/boot/memory.c
8137@@ -19,7 +19,7 @@
8138
8139 static int detect_memory_e820(void)
8140 {
8141- int count = 0;
8142+ unsigned int count = 0;
8143 struct biosregs ireg, oreg;
8144 struct e820entry *desc = boot_params.e820_map;
8145 static struct e820entry buf; /* static so it is zeroed */
8146diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8147index 11e8c6e..fdbb1ed 100644
8148--- a/arch/x86/boot/video-vesa.c
8149+++ b/arch/x86/boot/video-vesa.c
8150@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8151
8152 boot_params.screen_info.vesapm_seg = oreg.es;
8153 boot_params.screen_info.vesapm_off = oreg.di;
8154+ boot_params.screen_info.vesapm_size = oreg.cx;
8155 }
8156
8157 /*
8158diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8159index 43eda28..5ab5fdb 100644
8160--- a/arch/x86/boot/video.c
8161+++ b/arch/x86/boot/video.c
8162@@ -96,7 +96,7 @@ static void store_mode_params(void)
8163 static unsigned int get_entry(void)
8164 {
8165 char entry_buf[4];
8166- int i, len = 0;
8167+ unsigned int i, len = 0;
8168 int key;
8169 unsigned int v;
8170
8171diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8172index 5b577d5..3c1fed4 100644
8173--- a/arch/x86/crypto/aes-x86_64-asm_64.S
8174+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8175@@ -8,6 +8,8 @@
8176 * including this sentence is retained in full.
8177 */
8178
8179+#include <asm/alternative-asm.h>
8180+
8181 .extern crypto_ft_tab
8182 .extern crypto_it_tab
8183 .extern crypto_fl_tab
8184@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8185 je B192; \
8186 leaq 32(r9),r9;
8187
8188+#define ret pax_force_retaddr 0, 1; ret
8189+
8190 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8191 movq r1,r2; \
8192 movq r3,r4; \
8193diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8194index 3470624..201259d 100644
8195--- a/arch/x86/crypto/aesni-intel_asm.S
8196+++ b/arch/x86/crypto/aesni-intel_asm.S
8197@@ -31,6 +31,7 @@
8198
8199 #include <linux/linkage.h>
8200 #include <asm/inst.h>
8201+#include <asm/alternative-asm.h>
8202
8203 #ifdef __x86_64__
8204 .data
8205@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8206 pop %r14
8207 pop %r13
8208 pop %r12
8209+ pax_force_retaddr 0, 1
8210 ret
8211+ENDPROC(aesni_gcm_dec)
8212
8213
8214 /*****************************************************************************
8215@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8216 pop %r14
8217 pop %r13
8218 pop %r12
8219+ pax_force_retaddr 0, 1
8220 ret
8221+ENDPROC(aesni_gcm_enc)
8222
8223 #endif
8224
8225@@ -1714,6 +1719,7 @@ _key_expansion_256a:
8226 pxor %xmm1, %xmm0
8227 movaps %xmm0, (TKEYP)
8228 add $0x10, TKEYP
8229+ pax_force_retaddr_bts
8230 ret
8231
8232 .align 4
8233@@ -1738,6 +1744,7 @@ _key_expansion_192a:
8234 shufps $0b01001110, %xmm2, %xmm1
8235 movaps %xmm1, 0x10(TKEYP)
8236 add $0x20, TKEYP
8237+ pax_force_retaddr_bts
8238 ret
8239
8240 .align 4
8241@@ -1757,6 +1764,7 @@ _key_expansion_192b:
8242
8243 movaps %xmm0, (TKEYP)
8244 add $0x10, TKEYP
8245+ pax_force_retaddr_bts
8246 ret
8247
8248 .align 4
8249@@ -1769,6 +1777,7 @@ _key_expansion_256b:
8250 pxor %xmm1, %xmm2
8251 movaps %xmm2, (TKEYP)
8252 add $0x10, TKEYP
8253+ pax_force_retaddr_bts
8254 ret
8255
8256 /*
8257@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8258 #ifndef __x86_64__
8259 popl KEYP
8260 #endif
8261+ pax_force_retaddr 0, 1
8262 ret
8263+ENDPROC(aesni_set_key)
8264
8265 /*
8266 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8267@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8268 popl KLEN
8269 popl KEYP
8270 #endif
8271+ pax_force_retaddr 0, 1
8272 ret
8273+ENDPROC(aesni_enc)
8274
8275 /*
8276 * _aesni_enc1: internal ABI
8277@@ -1959,6 +1972,7 @@ _aesni_enc1:
8278 AESENC KEY STATE
8279 movaps 0x70(TKEYP), KEY
8280 AESENCLAST KEY STATE
8281+ pax_force_retaddr_bts
8282 ret
8283
8284 /*
8285@@ -2067,6 +2081,7 @@ _aesni_enc4:
8286 AESENCLAST KEY STATE2
8287 AESENCLAST KEY STATE3
8288 AESENCLAST KEY STATE4
8289+ pax_force_retaddr_bts
8290 ret
8291
8292 /*
8293@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8294 popl KLEN
8295 popl KEYP
8296 #endif
8297+ pax_force_retaddr 0, 1
8298 ret
8299+ENDPROC(aesni_dec)
8300
8301 /*
8302 * _aesni_dec1: internal ABI
8303@@ -2146,6 +2163,7 @@ _aesni_dec1:
8304 AESDEC KEY STATE
8305 movaps 0x70(TKEYP), KEY
8306 AESDECLAST KEY STATE
8307+ pax_force_retaddr_bts
8308 ret
8309
8310 /*
8311@@ -2254,6 +2272,7 @@ _aesni_dec4:
8312 AESDECLAST KEY STATE2
8313 AESDECLAST KEY STATE3
8314 AESDECLAST KEY STATE4
8315+ pax_force_retaddr_bts
8316 ret
8317
8318 /*
8319@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8320 popl KEYP
8321 popl LEN
8322 #endif
8323+ pax_force_retaddr 0, 1
8324 ret
8325+ENDPROC(aesni_ecb_enc)
8326
8327 /*
8328 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8329@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8330 popl KEYP
8331 popl LEN
8332 #endif
8333+ pax_force_retaddr 0, 1
8334 ret
8335+ENDPROC(aesni_ecb_dec)
8336
8337 /*
8338 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8339@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8340 popl LEN
8341 popl IVP
8342 #endif
8343+ pax_force_retaddr 0, 1
8344 ret
8345+ENDPROC(aesni_cbc_enc)
8346
8347 /*
8348 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8349@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8350 popl LEN
8351 popl IVP
8352 #endif
8353+ pax_force_retaddr 0, 1
8354 ret
8355+ENDPROC(aesni_cbc_dec)
8356
8357 #ifdef __x86_64__
8358 .align 16
8359@@ -2526,6 +2553,7 @@ _aesni_inc_init:
8360 mov $1, TCTR_LOW
8361 MOVQ_R64_XMM TCTR_LOW INC
8362 MOVQ_R64_XMM CTR TCTR_LOW
8363+ pax_force_retaddr_bts
8364 ret
8365
8366 /*
8367@@ -2554,6 +2582,7 @@ _aesni_inc:
8368 .Linc_low:
8369 movaps CTR, IV
8370 PSHUFB_XMM BSWAP_MASK IV
8371+ pax_force_retaddr_bts
8372 ret
8373
8374 /*
8375@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8376 .Lctr_enc_ret:
8377 movups IV, (IVP)
8378 .Lctr_enc_just_ret:
8379+ pax_force_retaddr 0, 1
8380 ret
8381+ENDPROC(aesni_ctr_enc)
8382 #endif
8383diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8384index 391d245..67f35c2 100644
8385--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8386+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8387@@ -20,6 +20,8 @@
8388 *
8389 */
8390
8391+#include <asm/alternative-asm.h>
8392+
8393 .file "blowfish-x86_64-asm.S"
8394 .text
8395
8396@@ -151,9 +153,11 @@ __blowfish_enc_blk:
8397 jnz __enc_xor;
8398
8399 write_block();
8400+ pax_force_retaddr 0, 1
8401 ret;
8402 __enc_xor:
8403 xor_block();
8404+ pax_force_retaddr 0, 1
8405 ret;
8406
8407 .align 8
8408@@ -188,6 +192,7 @@ blowfish_dec_blk:
8409
8410 movq %r11, %rbp;
8411
8412+ pax_force_retaddr 0, 1
8413 ret;
8414
8415 /**********************************************************************
8416@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8417
8418 popq %rbx;
8419 popq %rbp;
8420+ pax_force_retaddr 0, 1
8421 ret;
8422
8423 __enc_xor4:
8424@@ -349,6 +355,7 @@ __enc_xor4:
8425
8426 popq %rbx;
8427 popq %rbp;
8428+ pax_force_retaddr 0, 1
8429 ret;
8430
8431 .align 8
8432@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8433 popq %rbx;
8434 popq %rbp;
8435
8436+ pax_force_retaddr 0, 1
8437 ret;
8438
8439diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8440index 0b33743..7a56206 100644
8441--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8442+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8443@@ -20,6 +20,8 @@
8444 *
8445 */
8446
8447+#include <asm/alternative-asm.h>
8448+
8449 .file "camellia-x86_64-asm_64.S"
8450 .text
8451
8452@@ -229,12 +231,14 @@ __enc_done:
8453 enc_outunpack(mov, RT1);
8454
8455 movq RRBP, %rbp;
8456+ pax_force_retaddr 0, 1
8457 ret;
8458
8459 __enc_xor:
8460 enc_outunpack(xor, RT1);
8461
8462 movq RRBP, %rbp;
8463+ pax_force_retaddr 0, 1
8464 ret;
8465
8466 .global camellia_dec_blk;
8467@@ -275,6 +279,7 @@ __dec_rounds16:
8468 dec_outunpack();
8469
8470 movq RRBP, %rbp;
8471+ pax_force_retaddr 0, 1
8472 ret;
8473
8474 /**********************************************************************
8475@@ -468,6 +473,7 @@ __enc2_done:
8476
8477 movq RRBP, %rbp;
8478 popq %rbx;
8479+ pax_force_retaddr 0, 1
8480 ret;
8481
8482 __enc2_xor:
8483@@ -475,6 +481,7 @@ __enc2_xor:
8484
8485 movq RRBP, %rbp;
8486 popq %rbx;
8487+ pax_force_retaddr 0, 1
8488 ret;
8489
8490 .global camellia_dec_blk_2way;
8491@@ -517,4 +524,5 @@ __dec2_rounds16:
8492
8493 movq RRBP, %rbp;
8494 movq RXOR, %rbx;
8495+ pax_force_retaddr 0, 1
8496 ret;
8497diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8498index 6214a9b..1f4fc9a 100644
8499--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8500+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8501@@ -1,3 +1,5 @@
8502+#include <asm/alternative-asm.h>
8503+
8504 # enter ECRYPT_encrypt_bytes
8505 .text
8506 .p2align 5
8507@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8508 add %r11,%rsp
8509 mov %rdi,%rax
8510 mov %rsi,%rdx
8511+ pax_force_retaddr 0, 1
8512 ret
8513 # bytesatleast65:
8514 ._bytesatleast65:
8515@@ -891,6 +894,7 @@ ECRYPT_keysetup:
8516 add %r11,%rsp
8517 mov %rdi,%rax
8518 mov %rsi,%rdx
8519+ pax_force_retaddr
8520 ret
8521 # enter ECRYPT_ivsetup
8522 .text
8523@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8524 add %r11,%rsp
8525 mov %rdi,%rax
8526 mov %rsi,%rdx
8527+ pax_force_retaddr
8528 ret
8529diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8530index 3ee1ff0..cbc568b 100644
8531--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8532+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8533@@ -24,6 +24,8 @@
8534 *
8535 */
8536
8537+#include <asm/alternative-asm.h>
8538+
8539 .file "serpent-sse2-x86_64-asm_64.S"
8540 .text
8541
8542@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8543 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8544 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8545
8546+ pax_force_retaddr
8547 ret;
8548
8549 __enc_xor8:
8550 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8551 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8552
8553+ pax_force_retaddr
8554 ret;
8555
8556 .align 8
8557@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8558 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8559 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8560
8561+ pax_force_retaddr
8562 ret;
8563diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8564index b2c2f57..8470cab 100644
8565--- a/arch/x86/crypto/sha1_ssse3_asm.S
8566+++ b/arch/x86/crypto/sha1_ssse3_asm.S
8567@@ -28,6 +28,8 @@
8568 * (at your option) any later version.
8569 */
8570
8571+#include <asm/alternative-asm.h>
8572+
8573 #define CTX %rdi // arg1
8574 #define BUF %rsi // arg2
8575 #define CNT %rdx // arg3
8576@@ -104,6 +106,7 @@
8577 pop %r12
8578 pop %rbp
8579 pop %rbx
8580+ pax_force_retaddr 0, 1
8581 ret
8582
8583 .size \name, .-\name
8584diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8585index 5b012a2..36d5364 100644
8586--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8587+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8588@@ -20,6 +20,8 @@
8589 *
8590 */
8591
8592+#include <asm/alternative-asm.h>
8593+
8594 .file "twofish-x86_64-asm-3way.S"
8595 .text
8596
8597@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8598 popq %r13;
8599 popq %r14;
8600 popq %r15;
8601+ pax_force_retaddr 0, 1
8602 ret;
8603
8604 __enc_xor3:
8605@@ -271,6 +274,7 @@ __enc_xor3:
8606 popq %r13;
8607 popq %r14;
8608 popq %r15;
8609+ pax_force_retaddr 0, 1
8610 ret;
8611
8612 .global twofish_dec_blk_3way
8613@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8614 popq %r13;
8615 popq %r14;
8616 popq %r15;
8617+ pax_force_retaddr 0, 1
8618 ret;
8619
8620diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8621index 7bcf3fc..f53832f 100644
8622--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8623+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8624@@ -21,6 +21,7 @@
8625 .text
8626
8627 #include <asm/asm-offsets.h>
8628+#include <asm/alternative-asm.h>
8629
8630 #define a_offset 0
8631 #define b_offset 4
8632@@ -268,6 +269,7 @@ twofish_enc_blk:
8633
8634 popq R1
8635 movq $1,%rax
8636+ pax_force_retaddr 0, 1
8637 ret
8638
8639 twofish_dec_blk:
8640@@ -319,4 +321,5 @@ twofish_dec_blk:
8641
8642 popq R1
8643 movq $1,%rax
8644+ pax_force_retaddr 0, 1
8645 ret
8646diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8647index 07b3a68..bd2a388 100644
8648--- a/arch/x86/ia32/ia32_aout.c
8649+++ b/arch/x86/ia32/ia32_aout.c
8650@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8651 unsigned long dump_start, dump_size;
8652 struct user32 dump;
8653
8654+ memset(&dump, 0, sizeof(dump));
8655+
8656 fs = get_fs();
8657 set_fs(KERNEL_DS);
8658 has_dumped = 1;
8659diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8660index 4f5bfac..e1ef0d3 100644
8661--- a/arch/x86/ia32/ia32_signal.c
8662+++ b/arch/x86/ia32/ia32_signal.c
8663@@ -168,7 +168,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8664 }
8665 seg = get_fs();
8666 set_fs(KERNEL_DS);
8667- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8668+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8669 set_fs(seg);
8670 if (ret >= 0 && uoss_ptr) {
8671 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8672@@ -369,7 +369,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8673 */
8674 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8675 size_t frame_size,
8676- void **fpstate)
8677+ void __user **fpstate)
8678 {
8679 unsigned long sp;
8680
8681@@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8682
8683 if (used_math()) {
8684 sp = sp - sig_xstate_ia32_size;
8685- *fpstate = (struct _fpstate_ia32 *) sp;
8686+ *fpstate = (struct _fpstate_ia32 __user *) sp;
8687 if (save_i387_xstate_ia32(*fpstate) < 0)
8688 return (void __user *) -1L;
8689 }
8690@@ -398,7 +398,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8691 sp -= frame_size;
8692 /* Align the stack pointer according to the i386 ABI,
8693 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8694- sp = ((sp + 4) & -16ul) - 4;
8695+ sp = ((sp - 12) & -16ul) - 4;
8696 return (void __user *) sp;
8697 }
8698
8699@@ -456,7 +456,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8700 * These are actually not used anymore, but left because some
8701 * gdb versions depend on them as a marker.
8702 */
8703- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8704+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8705 } put_user_catch(err);
8706
8707 if (err)
8708@@ -498,7 +498,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8709 0xb8,
8710 __NR_ia32_rt_sigreturn,
8711 0x80cd,
8712- 0,
8713+ 0
8714 };
8715
8716 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8717@@ -528,16 +528,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8718
8719 if (ka->sa.sa_flags & SA_RESTORER)
8720 restorer = ka->sa.sa_restorer;
8721+ else if (current->mm->context.vdso)
8722+ /* Return stub is in 32bit vsyscall page */
8723+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8724 else
8725- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8726- rt_sigreturn);
8727+ restorer = &frame->retcode;
8728 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8729
8730 /*
8731 * Not actually used anymore, but left because some gdb
8732 * versions need it.
8733 */
8734- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8735+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8736 } put_user_catch(err);
8737
8738 if (err)
8739diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8740index e3e7340..05ed805 100644
8741--- a/arch/x86/ia32/ia32entry.S
8742+++ b/arch/x86/ia32/ia32entry.S
8743@@ -13,8 +13,10 @@
8744 #include <asm/thread_info.h>
8745 #include <asm/segment.h>
8746 #include <asm/irqflags.h>
8747+#include <asm/pgtable.h>
8748 #include <linux/linkage.h>
8749 #include <linux/err.h>
8750+#include <asm/alternative-asm.h>
8751
8752 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8753 #include <linux/elf-em.h>
8754@@ -94,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8755 ENDPROC(native_irq_enable_sysexit)
8756 #endif
8757
8758+ .macro pax_enter_kernel_user
8759+ pax_set_fptr_mask
8760+#ifdef CONFIG_PAX_MEMORY_UDEREF
8761+ call pax_enter_kernel_user
8762+#endif
8763+ .endm
8764+
8765+ .macro pax_exit_kernel_user
8766+#ifdef CONFIG_PAX_MEMORY_UDEREF
8767+ call pax_exit_kernel_user
8768+#endif
8769+#ifdef CONFIG_PAX_RANDKSTACK
8770+ pushq %rax
8771+ pushq %r11
8772+ call pax_randomize_kstack
8773+ popq %r11
8774+ popq %rax
8775+#endif
8776+ .endm
8777+
8778+.macro pax_erase_kstack
8779+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8780+ call pax_erase_kstack
8781+#endif
8782+.endm
8783+
8784 /*
8785 * 32bit SYSENTER instruction entry.
8786 *
8787@@ -120,12 +148,6 @@ ENTRY(ia32_sysenter_target)
8788 CFI_REGISTER rsp,rbp
8789 SWAPGS_UNSAFE_STACK
8790 movq PER_CPU_VAR(kernel_stack), %rsp
8791- addq $(KERNEL_STACK_OFFSET),%rsp
8792- /*
8793- * No need to follow this irqs on/off section: the syscall
8794- * disabled irqs, here we enable it straight after entry:
8795- */
8796- ENABLE_INTERRUPTS(CLBR_NONE)
8797 movl %ebp,%ebp /* zero extension */
8798 pushq_cfi $__USER32_DS
8799 /*CFI_REL_OFFSET ss,0*/
8800@@ -133,24 +155,39 @@ ENTRY(ia32_sysenter_target)
8801 CFI_REL_OFFSET rsp,0
8802 pushfq_cfi
8803 /*CFI_REL_OFFSET rflags,0*/
8804- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8805- CFI_REGISTER rip,r10
8806+ orl $X86_EFLAGS_IF,(%rsp)
8807+ GET_THREAD_INFO(%r11)
8808+ movl TI_sysenter_return(%r11), %r11d
8809+ CFI_REGISTER rip,r11
8810 pushq_cfi $__USER32_CS
8811 /*CFI_REL_OFFSET cs,0*/
8812 movl %eax, %eax
8813- pushq_cfi %r10
8814+ pushq_cfi %r11
8815 CFI_REL_OFFSET rip,0
8816 pushq_cfi %rax
8817 cld
8818 SAVE_ARGS 0,1,0
8819+ pax_enter_kernel_user
8820+ /*
8821+ * No need to follow this irqs on/off section: the syscall
8822+ * disabled irqs, here we enable it straight after entry:
8823+ */
8824+ ENABLE_INTERRUPTS(CLBR_NONE)
8825 /* no need to do an access_ok check here because rbp has been
8826 32bit zero extended */
8827+
8828+#ifdef CONFIG_PAX_MEMORY_UDEREF
8829+ mov $PAX_USER_SHADOW_BASE,%r11
8830+ add %r11,%rbp
8831+#endif
8832+
8833 1: movl (%rbp),%ebp
8834 .section __ex_table,"a"
8835 .quad 1b,ia32_badarg
8836 .previous
8837- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8838- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8839+ GET_THREAD_INFO(%r11)
8840+ orl $TS_COMPAT,TI_status(%r11)
8841+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8842 CFI_REMEMBER_STATE
8843 jnz sysenter_tracesys
8844 cmpq $(IA32_NR_syscalls-1),%rax
8845@@ -160,12 +197,15 @@ sysenter_do_call:
8846 sysenter_dispatch:
8847 call *ia32_sys_call_table(,%rax,8)
8848 movq %rax,RAX-ARGOFFSET(%rsp)
8849+ GET_THREAD_INFO(%r11)
8850 DISABLE_INTERRUPTS(CLBR_NONE)
8851 TRACE_IRQS_OFF
8852- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8853+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8854 jnz sysexit_audit
8855 sysexit_from_sys_call:
8856- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8857+ pax_exit_kernel_user
8858+ pax_erase_kstack
8859+ andl $~TS_COMPAT,TI_status(%r11)
8860 /* clear IF, that popfq doesn't enable interrupts early */
8861 andl $~0x200,EFLAGS-R11(%rsp)
8862 movl RIP-R11(%rsp),%edx /* User %eip */
8863@@ -191,6 +231,9 @@ sysexit_from_sys_call:
8864 movl %eax,%esi /* 2nd arg: syscall number */
8865 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8866 call __audit_syscall_entry
8867+
8868+ pax_erase_kstack
8869+
8870 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8871 cmpq $(IA32_NR_syscalls-1),%rax
8872 ja ia32_badsys
8873@@ -202,7 +245,7 @@ sysexit_from_sys_call:
8874 .endm
8875
8876 .macro auditsys_exit exit
8877- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8878+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8879 jnz ia32_ret_from_sys_call
8880 TRACE_IRQS_ON
8881 sti
8882@@ -213,11 +256,12 @@ sysexit_from_sys_call:
8883 1: setbe %al /* 1 if error, 0 if not */
8884 movzbl %al,%edi /* zero-extend that into %edi */
8885 call __audit_syscall_exit
8886+ GET_THREAD_INFO(%r11)
8887 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8888 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8889 cli
8890 TRACE_IRQS_OFF
8891- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8892+ testl %edi,TI_flags(%r11)
8893 jz \exit
8894 CLEAR_RREGS -ARGOFFSET
8895 jmp int_with_check
8896@@ -235,7 +279,7 @@ sysexit_audit:
8897
8898 sysenter_tracesys:
8899 #ifdef CONFIG_AUDITSYSCALL
8900- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8901+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8902 jz sysenter_auditsys
8903 #endif
8904 SAVE_REST
8905@@ -243,6 +287,9 @@ sysenter_tracesys:
8906 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8907 movq %rsp,%rdi /* &pt_regs -> arg1 */
8908 call syscall_trace_enter
8909+
8910+ pax_erase_kstack
8911+
8912 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8913 RESTORE_REST
8914 cmpq $(IA32_NR_syscalls-1),%rax
8915@@ -274,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8916 ENTRY(ia32_cstar_target)
8917 CFI_STARTPROC32 simple
8918 CFI_SIGNAL_FRAME
8919- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8920+ CFI_DEF_CFA rsp,0
8921 CFI_REGISTER rip,rcx
8922 /*CFI_REGISTER rflags,r11*/
8923 SWAPGS_UNSAFE_STACK
8924 movl %esp,%r8d
8925 CFI_REGISTER rsp,r8
8926 movq PER_CPU_VAR(kernel_stack),%rsp
8927+ SAVE_ARGS 8*6,0,0
8928+ pax_enter_kernel_user
8929 /*
8930 * No need to follow this irqs on/off section: the syscall
8931 * disabled irqs and here we enable it straight after entry:
8932 */
8933 ENABLE_INTERRUPTS(CLBR_NONE)
8934- SAVE_ARGS 8,0,0
8935 movl %eax,%eax /* zero extension */
8936 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8937 movq %rcx,RIP-ARGOFFSET(%rsp)
8938@@ -302,12 +350,19 @@ ENTRY(ia32_cstar_target)
8939 /* no need to do an access_ok check here because r8 has been
8940 32bit zero extended */
8941 /* hardware stack frame is complete now */
8942+
8943+#ifdef CONFIG_PAX_MEMORY_UDEREF
8944+ mov $PAX_USER_SHADOW_BASE,%r11
8945+ add %r11,%r8
8946+#endif
8947+
8948 1: movl (%r8),%r9d
8949 .section __ex_table,"a"
8950 .quad 1b,ia32_badarg
8951 .previous
8952- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8953- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8954+ GET_THREAD_INFO(%r11)
8955+ orl $TS_COMPAT,TI_status(%r11)
8956+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8957 CFI_REMEMBER_STATE
8958 jnz cstar_tracesys
8959 cmpq $IA32_NR_syscalls-1,%rax
8960@@ -317,12 +372,15 @@ cstar_do_call:
8961 cstar_dispatch:
8962 call *ia32_sys_call_table(,%rax,8)
8963 movq %rax,RAX-ARGOFFSET(%rsp)
8964+ GET_THREAD_INFO(%r11)
8965 DISABLE_INTERRUPTS(CLBR_NONE)
8966 TRACE_IRQS_OFF
8967- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8968+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8969 jnz sysretl_audit
8970 sysretl_from_sys_call:
8971- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8972+ pax_exit_kernel_user
8973+ pax_erase_kstack
8974+ andl $~TS_COMPAT,TI_status(%r11)
8975 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8976 movl RIP-ARGOFFSET(%rsp),%ecx
8977 CFI_REGISTER rip,rcx
8978@@ -350,7 +408,7 @@ sysretl_audit:
8979
8980 cstar_tracesys:
8981 #ifdef CONFIG_AUDITSYSCALL
8982- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8983+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8984 jz cstar_auditsys
8985 #endif
8986 xchgl %r9d,%ebp
8987@@ -359,6 +417,9 @@ cstar_tracesys:
8988 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8989 movq %rsp,%rdi /* &pt_regs -> arg1 */
8990 call syscall_trace_enter
8991+
8992+ pax_erase_kstack
8993+
8994 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8995 RESTORE_REST
8996 xchgl %ebp,%r9d
8997@@ -404,19 +465,21 @@ ENTRY(ia32_syscall)
8998 CFI_REL_OFFSET rip,RIP-RIP
8999 PARAVIRT_ADJUST_EXCEPTION_FRAME
9000 SWAPGS
9001- /*
9002- * No need to follow this irqs on/off section: the syscall
9003- * disabled irqs and here we enable it straight after entry:
9004- */
9005- ENABLE_INTERRUPTS(CLBR_NONE)
9006 movl %eax,%eax
9007 pushq_cfi %rax
9008 cld
9009 /* note the registers are not zero extended to the sf.
9010 this could be a problem. */
9011 SAVE_ARGS 0,1,0
9012- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9013- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9014+ pax_enter_kernel_user
9015+ /*
9016+ * No need to follow this irqs on/off section: the syscall
9017+ * disabled irqs and here we enable it straight after entry:
9018+ */
9019+ ENABLE_INTERRUPTS(CLBR_NONE)
9020+ GET_THREAD_INFO(%r11)
9021+ orl $TS_COMPAT,TI_status(%r11)
9022+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9023 jnz ia32_tracesys
9024 cmpq $(IA32_NR_syscalls-1),%rax
9025 ja ia32_badsys
9026@@ -435,6 +498,9 @@ ia32_tracesys:
9027 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
9028 movq %rsp,%rdi /* &pt_regs -> arg1 */
9029 call syscall_trace_enter
9030+
9031+ pax_erase_kstack
9032+
9033 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
9034 RESTORE_REST
9035 cmpq $(IA32_NR_syscalls-1),%rax
9036diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
9037index aec2202..f76174e 100644
9038--- a/arch/x86/ia32/sys_ia32.c
9039+++ b/arch/x86/ia32/sys_ia32.c
9040@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
9041 */
9042 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
9043 {
9044- typeof(ubuf->st_uid) uid = 0;
9045- typeof(ubuf->st_gid) gid = 0;
9046+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
9047+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
9048 SET_UID(uid, stat->uid);
9049 SET_GID(gid, stat->gid);
9050 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
9051@@ -292,7 +292,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
9052 return alarm_setitimer(seconds);
9053 }
9054
9055-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
9056+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
9057 int options)
9058 {
9059 return compat_sys_wait4(pid, stat_addr, options, NULL);
9060@@ -313,7 +313,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
9061 mm_segment_t old_fs = get_fs();
9062
9063 set_fs(KERNEL_DS);
9064- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9065+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9066 set_fs(old_fs);
9067 if (put_compat_timespec(&t, interval))
9068 return -EFAULT;
9069@@ -329,7 +329,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9070 mm_segment_t old_fs = get_fs();
9071
9072 set_fs(KERNEL_DS);
9073- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9074+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9075 set_fs(old_fs);
9076 if (!ret) {
9077 switch (_NSIG_WORDS) {
9078@@ -354,7 +354,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9079 if (copy_siginfo_from_user32(&info, uinfo))
9080 return -EFAULT;
9081 set_fs(KERNEL_DS);
9082- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9083+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9084 set_fs(old_fs);
9085 return ret;
9086 }
9087@@ -399,7 +399,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9088 return -EFAULT;
9089
9090 set_fs(KERNEL_DS);
9091- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9092+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9093 count);
9094 set_fs(old_fs);
9095
9096diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9097index 952bd01..7692c6f 100644
9098--- a/arch/x86/include/asm/alternative-asm.h
9099+++ b/arch/x86/include/asm/alternative-asm.h
9100@@ -15,6 +15,45 @@
9101 .endm
9102 #endif
9103
9104+#ifdef KERNEXEC_PLUGIN
9105+ .macro pax_force_retaddr_bts rip=0
9106+ btsq $63,\rip(%rsp)
9107+ .endm
9108+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9109+ .macro pax_force_retaddr rip=0, reload=0
9110+ btsq $63,\rip(%rsp)
9111+ .endm
9112+ .macro pax_force_fptr ptr
9113+ btsq $63,\ptr
9114+ .endm
9115+ .macro pax_set_fptr_mask
9116+ .endm
9117+#endif
9118+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9119+ .macro pax_force_retaddr rip=0, reload=0
9120+ .if \reload
9121+ pax_set_fptr_mask
9122+ .endif
9123+ orq %r10,\rip(%rsp)
9124+ .endm
9125+ .macro pax_force_fptr ptr
9126+ orq %r10,\ptr
9127+ .endm
9128+ .macro pax_set_fptr_mask
9129+ movabs $0x8000000000000000,%r10
9130+ .endm
9131+#endif
9132+#else
9133+ .macro pax_force_retaddr rip=0, reload=0
9134+ .endm
9135+ .macro pax_force_fptr ptr
9136+ .endm
9137+ .macro pax_force_retaddr_bts rip=0
9138+ .endm
9139+ .macro pax_set_fptr_mask
9140+ .endm
9141+#endif
9142+
9143 .macro altinstruction_entry orig alt feature orig_len alt_len
9144 .long \orig - .
9145 .long \alt - .
9146diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9147index 49331be..9706065 100644
9148--- a/arch/x86/include/asm/alternative.h
9149+++ b/arch/x86/include/asm/alternative.h
9150@@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9151 ".section .discard,\"aw\",@progbits\n" \
9152 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9153 ".previous\n" \
9154- ".section .altinstr_replacement, \"ax\"\n" \
9155+ ".section .altinstr_replacement, \"a\"\n" \
9156 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9157 ".previous"
9158
9159diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9160index d854101..f6ea947 100644
9161--- a/arch/x86/include/asm/apic.h
9162+++ b/arch/x86/include/asm/apic.h
9163@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9164
9165 #ifdef CONFIG_X86_LOCAL_APIC
9166
9167-extern unsigned int apic_verbosity;
9168+extern int apic_verbosity;
9169 extern int local_apic_timer_c2_ok;
9170
9171 extern int disable_apic;
9172diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9173index 20370c6..a2eb9b0 100644
9174--- a/arch/x86/include/asm/apm.h
9175+++ b/arch/x86/include/asm/apm.h
9176@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9177 __asm__ __volatile__(APM_DO_ZERO_SEGS
9178 "pushl %%edi\n\t"
9179 "pushl %%ebp\n\t"
9180- "lcall *%%cs:apm_bios_entry\n\t"
9181+ "lcall *%%ss:apm_bios_entry\n\t"
9182 "setc %%al\n\t"
9183 "popl %%ebp\n\t"
9184 "popl %%edi\n\t"
9185@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9186 __asm__ __volatile__(APM_DO_ZERO_SEGS
9187 "pushl %%edi\n\t"
9188 "pushl %%ebp\n\t"
9189- "lcall *%%cs:apm_bios_entry\n\t"
9190+ "lcall *%%ss:apm_bios_entry\n\t"
9191 "setc %%bl\n\t"
9192 "popl %%ebp\n\t"
9193 "popl %%edi\n\t"
9194diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9195index 58cb6d4..a4b806c 100644
9196--- a/arch/x86/include/asm/atomic.h
9197+++ b/arch/x86/include/asm/atomic.h
9198@@ -22,7 +22,18 @@
9199 */
9200 static inline int atomic_read(const atomic_t *v)
9201 {
9202- return (*(volatile int *)&(v)->counter);
9203+ return (*(volatile const int *)&(v)->counter);
9204+}
9205+
9206+/**
9207+ * atomic_read_unchecked - read atomic variable
9208+ * @v: pointer of type atomic_unchecked_t
9209+ *
9210+ * Atomically reads the value of @v.
9211+ */
9212+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9213+{
9214+ return (*(volatile const int *)&(v)->counter);
9215 }
9216
9217 /**
9218@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9219 }
9220
9221 /**
9222+ * atomic_set_unchecked - set atomic variable
9223+ * @v: pointer of type atomic_unchecked_t
9224+ * @i: required value
9225+ *
9226+ * Atomically sets the value of @v to @i.
9227+ */
9228+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9229+{
9230+ v->counter = i;
9231+}
9232+
9233+/**
9234 * atomic_add - add integer to atomic variable
9235 * @i: integer value to add
9236 * @v: pointer of type atomic_t
9237@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9238 */
9239 static inline void atomic_add(int i, atomic_t *v)
9240 {
9241- asm volatile(LOCK_PREFIX "addl %1,%0"
9242+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9243+
9244+#ifdef CONFIG_PAX_REFCOUNT
9245+ "jno 0f\n"
9246+ LOCK_PREFIX "subl %1,%0\n"
9247+ "int $4\n0:\n"
9248+ _ASM_EXTABLE(0b, 0b)
9249+#endif
9250+
9251+ : "+m" (v->counter)
9252+ : "ir" (i));
9253+}
9254+
9255+/**
9256+ * atomic_add_unchecked - add integer to atomic variable
9257+ * @i: integer value to add
9258+ * @v: pointer of type atomic_unchecked_t
9259+ *
9260+ * Atomically adds @i to @v.
9261+ */
9262+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9263+{
9264+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9265 : "+m" (v->counter)
9266 : "ir" (i));
9267 }
9268@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9269 */
9270 static inline void atomic_sub(int i, atomic_t *v)
9271 {
9272- asm volatile(LOCK_PREFIX "subl %1,%0"
9273+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9274+
9275+#ifdef CONFIG_PAX_REFCOUNT
9276+ "jno 0f\n"
9277+ LOCK_PREFIX "addl %1,%0\n"
9278+ "int $4\n0:\n"
9279+ _ASM_EXTABLE(0b, 0b)
9280+#endif
9281+
9282+ : "+m" (v->counter)
9283+ : "ir" (i));
9284+}
9285+
9286+/**
9287+ * atomic_sub_unchecked - subtract integer from atomic variable
9288+ * @i: integer value to subtract
9289+ * @v: pointer of type atomic_unchecked_t
9290+ *
9291+ * Atomically subtracts @i from @v.
9292+ */
9293+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9294+{
9295+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9296 : "+m" (v->counter)
9297 : "ir" (i));
9298 }
9299@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9300 {
9301 unsigned char c;
9302
9303- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9304+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
9305+
9306+#ifdef CONFIG_PAX_REFCOUNT
9307+ "jno 0f\n"
9308+ LOCK_PREFIX "addl %2,%0\n"
9309+ "int $4\n0:\n"
9310+ _ASM_EXTABLE(0b, 0b)
9311+#endif
9312+
9313+ "sete %1\n"
9314 : "+m" (v->counter), "=qm" (c)
9315 : "ir" (i) : "memory");
9316 return c;
9317@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9318 */
9319 static inline void atomic_inc(atomic_t *v)
9320 {
9321- asm volatile(LOCK_PREFIX "incl %0"
9322+ asm volatile(LOCK_PREFIX "incl %0\n"
9323+
9324+#ifdef CONFIG_PAX_REFCOUNT
9325+ "jno 0f\n"
9326+ LOCK_PREFIX "decl %0\n"
9327+ "int $4\n0:\n"
9328+ _ASM_EXTABLE(0b, 0b)
9329+#endif
9330+
9331+ : "+m" (v->counter));
9332+}
9333+
9334+/**
9335+ * atomic_inc_unchecked - increment atomic variable
9336+ * @v: pointer of type atomic_unchecked_t
9337+ *
9338+ * Atomically increments @v by 1.
9339+ */
9340+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9341+{
9342+ asm volatile(LOCK_PREFIX "incl %0\n"
9343 : "+m" (v->counter));
9344 }
9345
9346@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9347 */
9348 static inline void atomic_dec(atomic_t *v)
9349 {
9350- asm volatile(LOCK_PREFIX "decl %0"
9351+ asm volatile(LOCK_PREFIX "decl %0\n"
9352+
9353+#ifdef CONFIG_PAX_REFCOUNT
9354+ "jno 0f\n"
9355+ LOCK_PREFIX "incl %0\n"
9356+ "int $4\n0:\n"
9357+ _ASM_EXTABLE(0b, 0b)
9358+#endif
9359+
9360+ : "+m" (v->counter));
9361+}
9362+
9363+/**
9364+ * atomic_dec_unchecked - decrement atomic variable
9365+ * @v: pointer of type atomic_unchecked_t
9366+ *
9367+ * Atomically decrements @v by 1.
9368+ */
9369+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9370+{
9371+ asm volatile(LOCK_PREFIX "decl %0\n"
9372 : "+m" (v->counter));
9373 }
9374
9375@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9376 {
9377 unsigned char c;
9378
9379- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9380+ asm volatile(LOCK_PREFIX "decl %0\n"
9381+
9382+#ifdef CONFIG_PAX_REFCOUNT
9383+ "jno 0f\n"
9384+ LOCK_PREFIX "incl %0\n"
9385+ "int $4\n0:\n"
9386+ _ASM_EXTABLE(0b, 0b)
9387+#endif
9388+
9389+ "sete %1\n"
9390 : "+m" (v->counter), "=qm" (c)
9391 : : "memory");
9392 return c != 0;
9393@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9394 {
9395 unsigned char c;
9396
9397- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9398+ asm volatile(LOCK_PREFIX "incl %0\n"
9399+
9400+#ifdef CONFIG_PAX_REFCOUNT
9401+ "jno 0f\n"
9402+ LOCK_PREFIX "decl %0\n"
9403+ "int $4\n0:\n"
9404+ _ASM_EXTABLE(0b, 0b)
9405+#endif
9406+
9407+ "sete %1\n"
9408+ : "+m" (v->counter), "=qm" (c)
9409+ : : "memory");
9410+ return c != 0;
9411+}
9412+
9413+/**
9414+ * atomic_inc_and_test_unchecked - increment and test
9415+ * @v: pointer of type atomic_unchecked_t
9416+ *
9417+ * Atomically increments @v by 1
9418+ * and returns true if the result is zero, or false for all
9419+ * other cases.
9420+ */
9421+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9422+{
9423+ unsigned char c;
9424+
9425+ asm volatile(LOCK_PREFIX "incl %0\n"
9426+ "sete %1\n"
9427 : "+m" (v->counter), "=qm" (c)
9428 : : "memory");
9429 return c != 0;
9430@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9431 {
9432 unsigned char c;
9433
9434- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9435+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9436+
9437+#ifdef CONFIG_PAX_REFCOUNT
9438+ "jno 0f\n"
9439+ LOCK_PREFIX "subl %2,%0\n"
9440+ "int $4\n0:\n"
9441+ _ASM_EXTABLE(0b, 0b)
9442+#endif
9443+
9444+ "sets %1\n"
9445 : "+m" (v->counter), "=qm" (c)
9446 : "ir" (i) : "memory");
9447 return c;
9448@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9449 goto no_xadd;
9450 #endif
9451 /* Modern 486+ processor */
9452- return i + xadd(&v->counter, i);
9453+ return i + xadd_check_overflow(&v->counter, i);
9454
9455 #ifdef CONFIG_M386
9456 no_xadd: /* Legacy 386 processor */
9457@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9458 }
9459
9460 /**
9461+ * atomic_add_return_unchecked - add integer and return
9462+ * @i: integer value to add
9463+ * @v: pointer of type atomic_unchecked_t
9464+ *
9465+ * Atomically adds @i to @v and returns @i + @v
9466+ */
9467+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9468+{
9469+#ifdef CONFIG_M386
9470+ int __i;
9471+ unsigned long flags;
9472+ if (unlikely(boot_cpu_data.x86 <= 3))
9473+ goto no_xadd;
9474+#endif
9475+ /* Modern 486+ processor */
9476+ return i + xadd(&v->counter, i);
9477+
9478+#ifdef CONFIG_M386
9479+no_xadd: /* Legacy 386 processor */
9480+ raw_local_irq_save(flags);
9481+ __i = atomic_read_unchecked(v);
9482+ atomic_set_unchecked(v, i + __i);
9483+ raw_local_irq_restore(flags);
9484+ return i + __i;
9485+#endif
9486+}
9487+
9488+/**
9489 * atomic_sub_return - subtract integer and return
9490 * @v: pointer of type atomic_t
9491 * @i: integer value to subtract
9492@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9493 }
9494
9495 #define atomic_inc_return(v) (atomic_add_return(1, v))
9496+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9497+{
9498+ return atomic_add_return_unchecked(1, v);
9499+}
9500 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9501
9502 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9503@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9504 return cmpxchg(&v->counter, old, new);
9505 }
9506
9507+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9508+{
9509+ return cmpxchg(&v->counter, old, new);
9510+}
9511+
9512 static inline int atomic_xchg(atomic_t *v, int new)
9513 {
9514 return xchg(&v->counter, new);
9515 }
9516
9517+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9518+{
9519+ return xchg(&v->counter, new);
9520+}
9521+
9522 /**
9523 * __atomic_add_unless - add unless the number is already a given value
9524 * @v: pointer of type atomic_t
9525@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9526 */
9527 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9528 {
9529- int c, old;
9530+ int c, old, new;
9531 c = atomic_read(v);
9532 for (;;) {
9533- if (unlikely(c == (u)))
9534+ if (unlikely(c == u))
9535 break;
9536- old = atomic_cmpxchg((v), c, c + (a));
9537+
9538+ asm volatile("addl %2,%0\n"
9539+
9540+#ifdef CONFIG_PAX_REFCOUNT
9541+ "jno 0f\n"
9542+ "subl %2,%0\n"
9543+ "int $4\n0:\n"
9544+ _ASM_EXTABLE(0b, 0b)
9545+#endif
9546+
9547+ : "=r" (new)
9548+ : "0" (c), "ir" (a));
9549+
9550+ old = atomic_cmpxchg(v, c, new);
9551 if (likely(old == c))
9552 break;
9553 c = old;
9554@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9555 return c;
9556 }
9557
9558+/**
9559+ * atomic_inc_not_zero_hint - increment if not null
9560+ * @v: pointer of type atomic_t
9561+ * @hint: probable value of the atomic before the increment
9562+ *
9563+ * This version of atomic_inc_not_zero() gives a hint of probable
9564+ * value of the atomic. This helps processor to not read the memory
9565+ * before doing the atomic read/modify/write cycle, lowering
9566+ * number of bus transactions on some arches.
9567+ *
9568+ * Returns: 0 if increment was not done, 1 otherwise.
9569+ */
9570+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9571+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9572+{
9573+ int val, c = hint, new;
9574+
9575+ /* sanity test, should be removed by compiler if hint is a constant */
9576+ if (!hint)
9577+ return __atomic_add_unless(v, 1, 0);
9578+
9579+ do {
9580+ asm volatile("incl %0\n"
9581+
9582+#ifdef CONFIG_PAX_REFCOUNT
9583+ "jno 0f\n"
9584+ "decl %0\n"
9585+ "int $4\n0:\n"
9586+ _ASM_EXTABLE(0b, 0b)
9587+#endif
9588+
9589+ : "=r" (new)
9590+ : "0" (c));
9591+
9592+ val = atomic_cmpxchg(v, c, new);
9593+ if (val == c)
9594+ return 1;
9595+ c = val;
9596+ } while (c);
9597+
9598+ return 0;
9599+}
9600
9601 /*
9602 * atomic_dec_if_positive - decrement by 1 if old value positive
9603@@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9604 #endif
9605
9606 /* These are x86-specific, used by some header files */
9607-#define atomic_clear_mask(mask, addr) \
9608- asm volatile(LOCK_PREFIX "andl %0,%1" \
9609- : : "r" (~(mask)), "m" (*(addr)) : "memory")
9610+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9611+{
9612+ asm volatile(LOCK_PREFIX "andl %1,%0"
9613+ : "+m" (v->counter)
9614+ : "r" (~(mask))
9615+ : "memory");
9616+}
9617
9618-#define atomic_set_mask(mask, addr) \
9619- asm volatile(LOCK_PREFIX "orl %0,%1" \
9620- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9621- : "memory")
9622+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9623+{
9624+ asm volatile(LOCK_PREFIX "andl %1,%0"
9625+ : "+m" (v->counter)
9626+ : "r" (~(mask))
9627+ : "memory");
9628+}
9629+
9630+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9631+{
9632+ asm volatile(LOCK_PREFIX "orl %1,%0"
9633+ : "+m" (v->counter)
9634+ : "r" (mask)
9635+ : "memory");
9636+}
9637+
9638+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9639+{
9640+ asm volatile(LOCK_PREFIX "orl %1,%0"
9641+ : "+m" (v->counter)
9642+ : "r" (mask)
9643+ : "memory");
9644+}
9645
9646 /* Atomic operations are already serializing on x86 */
9647 #define smp_mb__before_atomic_dec() barrier()
9648diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9649index 1981199..36b9dfb 100644
9650--- a/arch/x86/include/asm/atomic64_32.h
9651+++ b/arch/x86/include/asm/atomic64_32.h
9652@@ -12,6 +12,14 @@ typedef struct {
9653 u64 __aligned(8) counter;
9654 } atomic64_t;
9655
9656+#ifdef CONFIG_PAX_REFCOUNT
9657+typedef struct {
9658+ u64 __aligned(8) counter;
9659+} atomic64_unchecked_t;
9660+#else
9661+typedef atomic64_t atomic64_unchecked_t;
9662+#endif
9663+
9664 #define ATOMIC64_INIT(val) { (val) }
9665
9666 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9667@@ -37,21 +45,31 @@ typedef struct {
9668 ATOMIC64_DECL_ONE(sym##_386)
9669
9670 ATOMIC64_DECL_ONE(add_386);
9671+ATOMIC64_DECL_ONE(add_unchecked_386);
9672 ATOMIC64_DECL_ONE(sub_386);
9673+ATOMIC64_DECL_ONE(sub_unchecked_386);
9674 ATOMIC64_DECL_ONE(inc_386);
9675+ATOMIC64_DECL_ONE(inc_unchecked_386);
9676 ATOMIC64_DECL_ONE(dec_386);
9677+ATOMIC64_DECL_ONE(dec_unchecked_386);
9678 #endif
9679
9680 #define alternative_atomic64(f, out, in...) \
9681 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9682
9683 ATOMIC64_DECL(read);
9684+ATOMIC64_DECL(read_unchecked);
9685 ATOMIC64_DECL(set);
9686+ATOMIC64_DECL(set_unchecked);
9687 ATOMIC64_DECL(xchg);
9688 ATOMIC64_DECL(add_return);
9689+ATOMIC64_DECL(add_return_unchecked);
9690 ATOMIC64_DECL(sub_return);
9691+ATOMIC64_DECL(sub_return_unchecked);
9692 ATOMIC64_DECL(inc_return);
9693+ATOMIC64_DECL(inc_return_unchecked);
9694 ATOMIC64_DECL(dec_return);
9695+ATOMIC64_DECL(dec_return_unchecked);
9696 ATOMIC64_DECL(dec_if_positive);
9697 ATOMIC64_DECL(inc_not_zero);
9698 ATOMIC64_DECL(add_unless);
9699@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9700 }
9701
9702 /**
9703+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9704+ * @p: pointer to type atomic64_unchecked_t
9705+ * @o: expected value
9706+ * @n: new value
9707+ *
9708+ * Atomically sets @v to @n if it was equal to @o and returns
9709+ * the old value.
9710+ */
9711+
9712+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9713+{
9714+ return cmpxchg64(&v->counter, o, n);
9715+}
9716+
9717+/**
9718 * atomic64_xchg - xchg atomic64 variable
9719 * @v: pointer to type atomic64_t
9720 * @n: value to assign
9721@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9722 }
9723
9724 /**
9725+ * atomic64_set_unchecked - set atomic64 variable
9726+ * @v: pointer to type atomic64_unchecked_t
9727+ * @n: value to assign
9728+ *
9729+ * Atomically sets the value of @v to @n.
9730+ */
9731+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9732+{
9733+ unsigned high = (unsigned)(i >> 32);
9734+ unsigned low = (unsigned)i;
9735+ alternative_atomic64(set, /* no output */,
9736+ "S" (v), "b" (low), "c" (high)
9737+ : "eax", "edx", "memory");
9738+}
9739+
9740+/**
9741 * atomic64_read - read atomic64 variable
9742 * @v: pointer to type atomic64_t
9743 *
9744@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9745 }
9746
9747 /**
9748+ * atomic64_read_unchecked - read atomic64 variable
9749+ * @v: pointer to type atomic64_unchecked_t
9750+ *
9751+ * Atomically reads the value of @v and returns it.
9752+ */
9753+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9754+{
9755+ long long r;
9756+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9757+ return r;
9758+ }
9759+
9760+/**
9761 * atomic64_add_return - add and return
9762 * @i: integer value to add
9763 * @v: pointer to type atomic64_t
9764@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9765 return i;
9766 }
9767
9768+/**
9769+ * atomic64_add_return_unchecked - add and return
9770+ * @i: integer value to add
9771+ * @v: pointer to type atomic64_unchecked_t
9772+ *
9773+ * Atomically adds @i to @v and returns @i + *@v
9774+ */
9775+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9776+{
9777+ alternative_atomic64(add_return_unchecked,
9778+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9779+ ASM_NO_INPUT_CLOBBER("memory"));
9780+ return i;
9781+}
9782+
9783 /*
9784 * Other variants with different arithmetic operators:
9785 */
9786@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9787 return a;
9788 }
9789
9790+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9791+{
9792+ long long a;
9793+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
9794+ "S" (v) : "memory", "ecx");
9795+ return a;
9796+}
9797+
9798 static inline long long atomic64_dec_return(atomic64_t *v)
9799 {
9800 long long a;
9801@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9802 }
9803
9804 /**
9805+ * atomic64_add_unchecked - add integer to atomic64 variable
9806+ * @i: integer value to add
9807+ * @v: pointer to type atomic64_unchecked_t
9808+ *
9809+ * Atomically adds @i to @v.
9810+ */
9811+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9812+{
9813+ __alternative_atomic64(add_unchecked, add_return_unchecked,
9814+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9815+ ASM_NO_INPUT_CLOBBER("memory"));
9816+ return i;
9817+}
9818+
9819+/**
9820 * atomic64_sub - subtract the atomic64 variable
9821 * @i: integer value to subtract
9822 * @v: pointer to type atomic64_t
9823diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9824index 0e1cbfc..5623683 100644
9825--- a/arch/x86/include/asm/atomic64_64.h
9826+++ b/arch/x86/include/asm/atomic64_64.h
9827@@ -18,7 +18,19 @@
9828 */
9829 static inline long atomic64_read(const atomic64_t *v)
9830 {
9831- return (*(volatile long *)&(v)->counter);
9832+ return (*(volatile const long *)&(v)->counter);
9833+}
9834+
9835+/**
9836+ * atomic64_read_unchecked - read atomic64 variable
9837+ * @v: pointer of type atomic64_unchecked_t
9838+ *
9839+ * Atomically reads the value of @v.
9840+ * Doesn't imply a read memory barrier.
9841+ */
9842+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9843+{
9844+ return (*(volatile const long *)&(v)->counter);
9845 }
9846
9847 /**
9848@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9849 }
9850
9851 /**
9852+ * atomic64_set_unchecked - set atomic64 variable
9853+ * @v: pointer to type atomic64_unchecked_t
9854+ * @i: required value
9855+ *
9856+ * Atomically sets the value of @v to @i.
9857+ */
9858+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9859+{
9860+ v->counter = i;
9861+}
9862+
9863+/**
9864 * atomic64_add - add integer to atomic64 variable
9865 * @i: integer value to add
9866 * @v: pointer to type atomic64_t
9867@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9868 */
9869 static inline void atomic64_add(long i, atomic64_t *v)
9870 {
9871+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9872+
9873+#ifdef CONFIG_PAX_REFCOUNT
9874+ "jno 0f\n"
9875+ LOCK_PREFIX "subq %1,%0\n"
9876+ "int $4\n0:\n"
9877+ _ASM_EXTABLE(0b, 0b)
9878+#endif
9879+
9880+ : "=m" (v->counter)
9881+ : "er" (i), "m" (v->counter));
9882+}
9883+
9884+/**
9885+ * atomic64_add_unchecked - add integer to atomic64 variable
9886+ * @i: integer value to add
9887+ * @v: pointer to type atomic64_unchecked_t
9888+ *
9889+ * Atomically adds @i to @v.
9890+ */
9891+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9892+{
9893 asm volatile(LOCK_PREFIX "addq %1,%0"
9894 : "=m" (v->counter)
9895 : "er" (i), "m" (v->counter));
9896@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9897 */
9898 static inline void atomic64_sub(long i, atomic64_t *v)
9899 {
9900- asm volatile(LOCK_PREFIX "subq %1,%0"
9901+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9902+
9903+#ifdef CONFIG_PAX_REFCOUNT
9904+ "jno 0f\n"
9905+ LOCK_PREFIX "addq %1,%0\n"
9906+ "int $4\n0:\n"
9907+ _ASM_EXTABLE(0b, 0b)
9908+#endif
9909+
9910+ : "=m" (v->counter)
9911+ : "er" (i), "m" (v->counter));
9912+}
9913+
9914+/**
9915+ * atomic64_sub_unchecked - subtract the atomic64 variable
9916+ * @i: integer value to subtract
9917+ * @v: pointer to type atomic64_unchecked_t
9918+ *
9919+ * Atomically subtracts @i from @v.
9920+ */
9921+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9922+{
9923+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9924 : "=m" (v->counter)
9925 : "er" (i), "m" (v->counter));
9926 }
9927@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9928 {
9929 unsigned char c;
9930
9931- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9932+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9933+
9934+#ifdef CONFIG_PAX_REFCOUNT
9935+ "jno 0f\n"
9936+ LOCK_PREFIX "addq %2,%0\n"
9937+ "int $4\n0:\n"
9938+ _ASM_EXTABLE(0b, 0b)
9939+#endif
9940+
9941+ "sete %1\n"
9942 : "=m" (v->counter), "=qm" (c)
9943 : "er" (i), "m" (v->counter) : "memory");
9944 return c;
9945@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9946 */
9947 static inline void atomic64_inc(atomic64_t *v)
9948 {
9949+ asm volatile(LOCK_PREFIX "incq %0\n"
9950+
9951+#ifdef CONFIG_PAX_REFCOUNT
9952+ "jno 0f\n"
9953+ LOCK_PREFIX "decq %0\n"
9954+ "int $4\n0:\n"
9955+ _ASM_EXTABLE(0b, 0b)
9956+#endif
9957+
9958+ : "=m" (v->counter)
9959+ : "m" (v->counter));
9960+}
9961+
9962+/**
9963+ * atomic64_inc_unchecked - increment atomic64 variable
9964+ * @v: pointer to type atomic64_unchecked_t
9965+ *
9966+ * Atomically increments @v by 1.
9967+ */
9968+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9969+{
9970 asm volatile(LOCK_PREFIX "incq %0"
9971 : "=m" (v->counter)
9972 : "m" (v->counter));
9973@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9974 */
9975 static inline void atomic64_dec(atomic64_t *v)
9976 {
9977- asm volatile(LOCK_PREFIX "decq %0"
9978+ asm volatile(LOCK_PREFIX "decq %0\n"
9979+
9980+#ifdef CONFIG_PAX_REFCOUNT
9981+ "jno 0f\n"
9982+ LOCK_PREFIX "incq %0\n"
9983+ "int $4\n0:\n"
9984+ _ASM_EXTABLE(0b, 0b)
9985+#endif
9986+
9987+ : "=m" (v->counter)
9988+ : "m" (v->counter));
9989+}
9990+
9991+/**
9992+ * atomic64_dec_unchecked - decrement atomic64 variable
9993+ * @v: pointer to type atomic64_t
9994+ *
9995+ * Atomically decrements @v by 1.
9996+ */
9997+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9998+{
9999+ asm volatile(LOCK_PREFIX "decq %0\n"
10000 : "=m" (v->counter)
10001 : "m" (v->counter));
10002 }
10003@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
10004 {
10005 unsigned char c;
10006
10007- asm volatile(LOCK_PREFIX "decq %0; sete %1"
10008+ asm volatile(LOCK_PREFIX "decq %0\n"
10009+
10010+#ifdef CONFIG_PAX_REFCOUNT
10011+ "jno 0f\n"
10012+ LOCK_PREFIX "incq %0\n"
10013+ "int $4\n0:\n"
10014+ _ASM_EXTABLE(0b, 0b)
10015+#endif
10016+
10017+ "sete %1\n"
10018 : "=m" (v->counter), "=qm" (c)
10019 : "m" (v->counter) : "memory");
10020 return c != 0;
10021@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
10022 {
10023 unsigned char c;
10024
10025- asm volatile(LOCK_PREFIX "incq %0; sete %1"
10026+ asm volatile(LOCK_PREFIX "incq %0\n"
10027+
10028+#ifdef CONFIG_PAX_REFCOUNT
10029+ "jno 0f\n"
10030+ LOCK_PREFIX "decq %0\n"
10031+ "int $4\n0:\n"
10032+ _ASM_EXTABLE(0b, 0b)
10033+#endif
10034+
10035+ "sete %1\n"
10036 : "=m" (v->counter), "=qm" (c)
10037 : "m" (v->counter) : "memory");
10038 return c != 0;
10039@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10040 {
10041 unsigned char c;
10042
10043- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
10044+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
10045+
10046+#ifdef CONFIG_PAX_REFCOUNT
10047+ "jno 0f\n"
10048+ LOCK_PREFIX "subq %2,%0\n"
10049+ "int $4\n0:\n"
10050+ _ASM_EXTABLE(0b, 0b)
10051+#endif
10052+
10053+ "sets %1\n"
10054 : "=m" (v->counter), "=qm" (c)
10055 : "er" (i), "m" (v->counter) : "memory");
10056 return c;
10057@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10058 */
10059 static inline long atomic64_add_return(long i, atomic64_t *v)
10060 {
10061+ return i + xadd_check_overflow(&v->counter, i);
10062+}
10063+
10064+/**
10065+ * atomic64_add_return_unchecked - add and return
10066+ * @i: integer value to add
10067+ * @v: pointer to type atomic64_unchecked_t
10068+ *
10069+ * Atomically adds @i to @v and returns @i + @v
10070+ */
10071+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10072+{
10073 return i + xadd(&v->counter, i);
10074 }
10075
10076@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10077 }
10078
10079 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10080+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10081+{
10082+ return atomic64_add_return_unchecked(1, v);
10083+}
10084 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10085
10086 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10087@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10088 return cmpxchg(&v->counter, old, new);
10089 }
10090
10091+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10092+{
10093+ return cmpxchg(&v->counter, old, new);
10094+}
10095+
10096 static inline long atomic64_xchg(atomic64_t *v, long new)
10097 {
10098 return xchg(&v->counter, new);
10099@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10100 */
10101 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10102 {
10103- long c, old;
10104+ long c, old, new;
10105 c = atomic64_read(v);
10106 for (;;) {
10107- if (unlikely(c == (u)))
10108+ if (unlikely(c == u))
10109 break;
10110- old = atomic64_cmpxchg((v), c, c + (a));
10111+
10112+ asm volatile("add %2,%0\n"
10113+
10114+#ifdef CONFIG_PAX_REFCOUNT
10115+ "jno 0f\n"
10116+ "sub %2,%0\n"
10117+ "int $4\n0:\n"
10118+ _ASM_EXTABLE(0b, 0b)
10119+#endif
10120+
10121+ : "=r" (new)
10122+ : "0" (c), "ir" (a));
10123+
10124+ old = atomic64_cmpxchg(v, c, new);
10125 if (likely(old == c))
10126 break;
10127 c = old;
10128 }
10129- return c != (u);
10130+ return c != u;
10131 }
10132
10133 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10134diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10135index b97596e..9bd48b06 100644
10136--- a/arch/x86/include/asm/bitops.h
10137+++ b/arch/x86/include/asm/bitops.h
10138@@ -38,7 +38,7 @@
10139 * a mask operation on a byte.
10140 */
10141 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10142-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10143+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10144 #define CONST_MASK(nr) (1 << ((nr) & 7))
10145
10146 /**
10147diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10148index 5e1a2ee..c9f9533 100644
10149--- a/arch/x86/include/asm/boot.h
10150+++ b/arch/x86/include/asm/boot.h
10151@@ -11,10 +11,15 @@
10152 #include <asm/pgtable_types.h>
10153
10154 /* Physical address where kernel should be loaded. */
10155-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10156+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10157 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10158 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10159
10160+#ifndef __ASSEMBLY__
10161+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10162+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10163+#endif
10164+
10165 /* Minimum kernel alignment, as a power of two */
10166 #ifdef CONFIG_X86_64
10167 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10168diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10169index 48f99f1..d78ebf9 100644
10170--- a/arch/x86/include/asm/cache.h
10171+++ b/arch/x86/include/asm/cache.h
10172@@ -5,12 +5,13 @@
10173
10174 /* L1 cache line size */
10175 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10176-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10177+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10178
10179 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10180+#define __read_only __attribute__((__section__(".data..read_only")))
10181
10182 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10183-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10184+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10185
10186 #ifdef CONFIG_X86_VSMP
10187 #ifdef CONFIG_SMP
10188diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10189index 9863ee3..4a1f8e1 100644
10190--- a/arch/x86/include/asm/cacheflush.h
10191+++ b/arch/x86/include/asm/cacheflush.h
10192@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10193 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10194
10195 if (pg_flags == _PGMT_DEFAULT)
10196- return -1;
10197+ return ~0UL;
10198 else if (pg_flags == _PGMT_WC)
10199 return _PAGE_CACHE_WC;
10200 else if (pg_flags == _PGMT_UC_MINUS)
10201diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10202index 46fc474..b02b0f9 100644
10203--- a/arch/x86/include/asm/checksum_32.h
10204+++ b/arch/x86/include/asm/checksum_32.h
10205@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10206 int len, __wsum sum,
10207 int *src_err_ptr, int *dst_err_ptr);
10208
10209+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10210+ int len, __wsum sum,
10211+ int *src_err_ptr, int *dst_err_ptr);
10212+
10213+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10214+ int len, __wsum sum,
10215+ int *src_err_ptr, int *dst_err_ptr);
10216+
10217 /*
10218 * Note: when you get a NULL pointer exception here this means someone
10219 * passed in an incorrect kernel address to one of these functions.
10220@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10221 int *err_ptr)
10222 {
10223 might_sleep();
10224- return csum_partial_copy_generic((__force void *)src, dst,
10225+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
10226 len, sum, err_ptr, NULL);
10227 }
10228
10229@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10230 {
10231 might_sleep();
10232 if (access_ok(VERIFY_WRITE, dst, len))
10233- return csum_partial_copy_generic(src, (__force void *)dst,
10234+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10235 len, sum, NULL, err_ptr);
10236
10237 if (len)
10238diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10239index 99480e5..d81165b 100644
10240--- a/arch/x86/include/asm/cmpxchg.h
10241+++ b/arch/x86/include/asm/cmpxchg.h
10242@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10243 __compiletime_error("Bad argument size for cmpxchg");
10244 extern void __xadd_wrong_size(void)
10245 __compiletime_error("Bad argument size for xadd");
10246+extern void __xadd_check_overflow_wrong_size(void)
10247+ __compiletime_error("Bad argument size for xadd_check_overflow");
10248 extern void __add_wrong_size(void)
10249 __compiletime_error("Bad argument size for add");
10250+extern void __add_check_overflow_wrong_size(void)
10251+ __compiletime_error("Bad argument size for add_check_overflow");
10252
10253 /*
10254 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10255@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10256 __ret; \
10257 })
10258
10259+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10260+ ({ \
10261+ __typeof__ (*(ptr)) __ret = (arg); \
10262+ switch (sizeof(*(ptr))) { \
10263+ case __X86_CASE_L: \
10264+ asm volatile (lock #op "l %0, %1\n" \
10265+ "jno 0f\n" \
10266+ "mov %0,%1\n" \
10267+ "int $4\n0:\n" \
10268+ _ASM_EXTABLE(0b, 0b) \
10269+ : "+r" (__ret), "+m" (*(ptr)) \
10270+ : : "memory", "cc"); \
10271+ break; \
10272+ case __X86_CASE_Q: \
10273+ asm volatile (lock #op "q %q0, %1\n" \
10274+ "jno 0f\n" \
10275+ "mov %0,%1\n" \
10276+ "int $4\n0:\n" \
10277+ _ASM_EXTABLE(0b, 0b) \
10278+ : "+r" (__ret), "+m" (*(ptr)) \
10279+ : : "memory", "cc"); \
10280+ break; \
10281+ default: \
10282+ __ ## op ## _check_overflow_wrong_size(); \
10283+ } \
10284+ __ret; \
10285+ })
10286+
10287 /*
10288 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10289 * Since this is generally used to protect other memory information, we
10290@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10291 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10292 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10293
10294+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10295+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10296+
10297 #define __add(ptr, inc, lock) \
10298 ({ \
10299 __typeof__ (*(ptr)) __ret = (inc); \
10300diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10301index f91e80f..7f9bd27 100644
10302--- a/arch/x86/include/asm/cpufeature.h
10303+++ b/arch/x86/include/asm/cpufeature.h
10304@@ -371,7 +371,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10305 ".section .discard,\"aw\",@progbits\n"
10306 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10307 ".previous\n"
10308- ".section .altinstr_replacement,\"ax\"\n"
10309+ ".section .altinstr_replacement,\"a\"\n"
10310 "3: movb $1,%0\n"
10311 "4:\n"
10312 ".previous\n"
10313diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10314index e95822d..a90010e 100644
10315--- a/arch/x86/include/asm/desc.h
10316+++ b/arch/x86/include/asm/desc.h
10317@@ -4,6 +4,7 @@
10318 #include <asm/desc_defs.h>
10319 #include <asm/ldt.h>
10320 #include <asm/mmu.h>
10321+#include <asm/pgtable.h>
10322
10323 #include <linux/smp.h>
10324
10325@@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10326
10327 desc->type = (info->read_exec_only ^ 1) << 1;
10328 desc->type |= info->contents << 2;
10329+ desc->type |= info->seg_not_present ^ 1;
10330
10331 desc->s = 1;
10332 desc->dpl = 0x3;
10333@@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10334 }
10335
10336 extern struct desc_ptr idt_descr;
10337-extern gate_desc idt_table[];
10338 extern struct desc_ptr nmi_idt_descr;
10339-extern gate_desc nmi_idt_table[];
10340-
10341-struct gdt_page {
10342- struct desc_struct gdt[GDT_ENTRIES];
10343-} __attribute__((aligned(PAGE_SIZE)));
10344-
10345-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10346+extern gate_desc idt_table[256];
10347+extern gate_desc nmi_idt_table[256];
10348
10349+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10350 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10351 {
10352- return per_cpu(gdt_page, cpu).gdt;
10353+ return cpu_gdt_table[cpu];
10354 }
10355
10356 #ifdef CONFIG_X86_64
10357@@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10358 unsigned long base, unsigned dpl, unsigned flags,
10359 unsigned short seg)
10360 {
10361- gate->a = (seg << 16) | (base & 0xffff);
10362- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10363+ gate->gate.offset_low = base;
10364+ gate->gate.seg = seg;
10365+ gate->gate.reserved = 0;
10366+ gate->gate.type = type;
10367+ gate->gate.s = 0;
10368+ gate->gate.dpl = dpl;
10369+ gate->gate.p = 1;
10370+ gate->gate.offset_high = base >> 16;
10371 }
10372
10373 #endif
10374@@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10375
10376 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10377 {
10378+ pax_open_kernel();
10379 memcpy(&idt[entry], gate, sizeof(*gate));
10380+ pax_close_kernel();
10381 }
10382
10383 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10384 {
10385+ pax_open_kernel();
10386 memcpy(&ldt[entry], desc, 8);
10387+ pax_close_kernel();
10388 }
10389
10390 static inline void
10391@@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10392 default: size = sizeof(*gdt); break;
10393 }
10394
10395+ pax_open_kernel();
10396 memcpy(&gdt[entry], desc, size);
10397+ pax_close_kernel();
10398 }
10399
10400 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10401@@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10402
10403 static inline void native_load_tr_desc(void)
10404 {
10405+ pax_open_kernel();
10406 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10407+ pax_close_kernel();
10408 }
10409
10410 static inline void native_load_gdt(const struct desc_ptr *dtr)
10411@@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10412 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10413 unsigned int i;
10414
10415+ pax_open_kernel();
10416 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10417 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10418+ pax_close_kernel();
10419 }
10420
10421 #define _LDT_empty(info) \
10422@@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10423 }
10424
10425 #ifdef CONFIG_X86_64
10426-static inline void set_nmi_gate(int gate, void *addr)
10427+static inline void set_nmi_gate(int gate, const void *addr)
10428 {
10429 gate_desc s;
10430
10431@@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10432 }
10433 #endif
10434
10435-static inline void _set_gate(int gate, unsigned type, void *addr,
10436+static inline void _set_gate(int gate, unsigned type, const void *addr,
10437 unsigned dpl, unsigned ist, unsigned seg)
10438 {
10439 gate_desc s;
10440@@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10441 * Pentium F0 0F bugfix can have resulted in the mapped
10442 * IDT being write-protected.
10443 */
10444-static inline void set_intr_gate(unsigned int n, void *addr)
10445+static inline void set_intr_gate(unsigned int n, const void *addr)
10446 {
10447 BUG_ON((unsigned)n > 0xFF);
10448 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10449@@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10450 /*
10451 * This routine sets up an interrupt gate at directory privilege level 3.
10452 */
10453-static inline void set_system_intr_gate(unsigned int n, void *addr)
10454+static inline void set_system_intr_gate(unsigned int n, const void *addr)
10455 {
10456 BUG_ON((unsigned)n > 0xFF);
10457 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10458 }
10459
10460-static inline void set_system_trap_gate(unsigned int n, void *addr)
10461+static inline void set_system_trap_gate(unsigned int n, const void *addr)
10462 {
10463 BUG_ON((unsigned)n > 0xFF);
10464 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10465 }
10466
10467-static inline void set_trap_gate(unsigned int n, void *addr)
10468+static inline void set_trap_gate(unsigned int n, const void *addr)
10469 {
10470 BUG_ON((unsigned)n > 0xFF);
10471 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10472@@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10473 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10474 {
10475 BUG_ON((unsigned)n > 0xFF);
10476- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10477+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10478 }
10479
10480-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10481+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10482 {
10483 BUG_ON((unsigned)n > 0xFF);
10484 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10485 }
10486
10487-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10488+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10489 {
10490 BUG_ON((unsigned)n > 0xFF);
10491 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10492 }
10493
10494+#ifdef CONFIG_X86_32
10495+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10496+{
10497+ struct desc_struct d;
10498+
10499+ if (likely(limit))
10500+ limit = (limit - 1UL) >> PAGE_SHIFT;
10501+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
10502+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10503+}
10504+#endif
10505+
10506 #endif /* _ASM_X86_DESC_H */
10507diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10508index 278441f..b95a174 100644
10509--- a/arch/x86/include/asm/desc_defs.h
10510+++ b/arch/x86/include/asm/desc_defs.h
10511@@ -31,6 +31,12 @@ struct desc_struct {
10512 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10513 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10514 };
10515+ struct {
10516+ u16 offset_low;
10517+ u16 seg;
10518+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10519+ unsigned offset_high: 16;
10520+ } gate;
10521 };
10522 } __attribute__((packed));
10523
10524diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10525index 3778256..c5d4fce 100644
10526--- a/arch/x86/include/asm/e820.h
10527+++ b/arch/x86/include/asm/e820.h
10528@@ -69,7 +69,7 @@ struct e820map {
10529 #define ISA_START_ADDRESS 0xa0000
10530 #define ISA_END_ADDRESS 0x100000
10531
10532-#define BIOS_BEGIN 0x000a0000
10533+#define BIOS_BEGIN 0x000c0000
10534 #define BIOS_END 0x00100000
10535
10536 #define BIOS_ROM_BASE 0xffe00000
10537diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10538index 5939f44..f8845f6 100644
10539--- a/arch/x86/include/asm/elf.h
10540+++ b/arch/x86/include/asm/elf.h
10541@@ -243,7 +243,25 @@ extern int force_personality32;
10542 the loader. We need to make sure that it is out of the way of the program
10543 that it will "exec", and that there is sufficient room for the brk. */
10544
10545+#ifdef CONFIG_PAX_SEGMEXEC
10546+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10547+#else
10548 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10549+#endif
10550+
10551+#ifdef CONFIG_PAX_ASLR
10552+#ifdef CONFIG_X86_32
10553+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10554+
10555+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10556+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10557+#else
10558+#define PAX_ELF_ET_DYN_BASE 0x400000UL
10559+
10560+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10561+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10562+#endif
10563+#endif
10564
10565 /* This yields a mask that user programs can use to figure out what
10566 instruction set this CPU supports. This could be done in user space,
10567@@ -296,16 +314,12 @@ do { \
10568
10569 #define ARCH_DLINFO \
10570 do { \
10571- if (vdso_enabled) \
10572- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10573- (unsigned long)current->mm->context.vdso); \
10574+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10575 } while (0)
10576
10577 #define ARCH_DLINFO_X32 \
10578 do { \
10579- if (vdso_enabled) \
10580- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10581- (unsigned long)current->mm->context.vdso); \
10582+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10583 } while (0)
10584
10585 #define AT_SYSINFO 32
10586@@ -320,7 +334,7 @@ else \
10587
10588 #endif /* !CONFIG_X86_32 */
10589
10590-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10591+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10592
10593 #define VDSO_ENTRY \
10594 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10595@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10596 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10597 #define compat_arch_setup_additional_pages syscall32_setup_pages
10598
10599-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10600-#define arch_randomize_brk arch_randomize_brk
10601-
10602 /*
10603 * True on X86_32 or when emulating IA32 on X86_64
10604 */
10605diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10606index cc70c1c..d96d011 100644
10607--- a/arch/x86/include/asm/emergency-restart.h
10608+++ b/arch/x86/include/asm/emergency-restart.h
10609@@ -15,6 +15,6 @@ enum reboot_type {
10610
10611 extern enum reboot_type reboot_type;
10612
10613-extern void machine_emergency_restart(void);
10614+extern void machine_emergency_restart(void) __noreturn;
10615
10616 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10617diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10618index 4fa8815..71b121a 100644
10619--- a/arch/x86/include/asm/fpu-internal.h
10620+++ b/arch/x86/include/asm/fpu-internal.h
10621@@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10622 {
10623 int err;
10624
10625+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10626+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10627+ fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10628+#endif
10629+
10630 /* See comment in fxsave() below. */
10631 #ifdef CONFIG_AS_FXSAVEQ
10632 asm volatile("1: fxrstorq %[fx]\n\t"
10633@@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10634 {
10635 int err;
10636
10637+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10638+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10639+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10640+#endif
10641+
10642 /*
10643 * Clear the bytes not touched by the fxsave and reserved
10644 * for the SW usage.
10645@@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10646 "emms\n\t" /* clear stack tags */
10647 "fildl %P[addr]", /* set F?P to defined value */
10648 X86_FEATURE_FXSAVE_LEAK,
10649- [addr] "m" (tsk->thread.fpu.has_fpu));
10650+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10651
10652 return fpu_restore_checking(&tsk->thread.fpu);
10653 }
10654diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10655index 71ecbcb..bac10b7 100644
10656--- a/arch/x86/include/asm/futex.h
10657+++ b/arch/x86/include/asm/futex.h
10658@@ -11,16 +11,18 @@
10659 #include <asm/processor.h>
10660
10661 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10662+ typecheck(u32 __user *, uaddr); \
10663 asm volatile("1:\t" insn "\n" \
10664 "2:\t.section .fixup,\"ax\"\n" \
10665 "3:\tmov\t%3, %1\n" \
10666 "\tjmp\t2b\n" \
10667 "\t.previous\n" \
10668 _ASM_EXTABLE(1b, 3b) \
10669- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10670+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10671 : "i" (-EFAULT), "0" (oparg), "1" (0))
10672
10673 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10674+ typecheck(u32 __user *, uaddr); \
10675 asm volatile("1:\tmovl %2, %0\n" \
10676 "\tmovl\t%0, %3\n" \
10677 "\t" insn "\n" \
10678@@ -33,7 +35,7 @@
10679 _ASM_EXTABLE(1b, 4b) \
10680 _ASM_EXTABLE(2b, 4b) \
10681 : "=&a" (oldval), "=&r" (ret), \
10682- "+m" (*uaddr), "=&r" (tem) \
10683+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10684 : "r" (oparg), "i" (-EFAULT), "1" (0))
10685
10686 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10687@@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10688
10689 switch (op) {
10690 case FUTEX_OP_SET:
10691- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10692+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10693 break;
10694 case FUTEX_OP_ADD:
10695- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10696+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10697 uaddr, oparg);
10698 break;
10699 case FUTEX_OP_OR:
10700@@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10701 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10702 return -EFAULT;
10703
10704- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10705+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10706 "2:\t.section .fixup, \"ax\"\n"
10707 "3:\tmov %3, %0\n"
10708 "\tjmp 2b\n"
10709 "\t.previous\n"
10710 _ASM_EXTABLE(1b, 3b)
10711- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10712+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10713 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10714 : "memory"
10715 );
10716diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10717index eb92a6e..b98b2f4 100644
10718--- a/arch/x86/include/asm/hw_irq.h
10719+++ b/arch/x86/include/asm/hw_irq.h
10720@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10721 extern void enable_IO_APIC(void);
10722
10723 /* Statistics */
10724-extern atomic_t irq_err_count;
10725-extern atomic_t irq_mis_count;
10726+extern atomic_unchecked_t irq_err_count;
10727+extern atomic_unchecked_t irq_mis_count;
10728
10729 /* EISA */
10730 extern void eisa_set_level_irq(unsigned int irq);
10731diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10732index d8e8eef..99f81ae 100644
10733--- a/arch/x86/include/asm/io.h
10734+++ b/arch/x86/include/asm/io.h
10735@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10736
10737 #include <linux/vmalloc.h>
10738
10739+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10740+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10741+{
10742+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10743+}
10744+
10745+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10746+{
10747+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10748+}
10749+
10750 /*
10751 * Convert a virtual cached pointer to an uncached pointer
10752 */
10753diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10754index bba3cf8..06bc8da 100644
10755--- a/arch/x86/include/asm/irqflags.h
10756+++ b/arch/x86/include/asm/irqflags.h
10757@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10758 sti; \
10759 sysexit
10760
10761+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10762+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10763+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10764+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10765+
10766 #else
10767 #define INTERRUPT_RETURN iret
10768 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10769diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10770index 5478825..839e88c 100644
10771--- a/arch/x86/include/asm/kprobes.h
10772+++ b/arch/x86/include/asm/kprobes.h
10773@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10774 #define RELATIVEJUMP_SIZE 5
10775 #define RELATIVECALL_OPCODE 0xe8
10776 #define RELATIVE_ADDR_SIZE 4
10777-#define MAX_STACK_SIZE 64
10778-#define MIN_STACK_SIZE(ADDR) \
10779- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10780- THREAD_SIZE - (unsigned long)(ADDR))) \
10781- ? (MAX_STACK_SIZE) \
10782- : (((unsigned long)current_thread_info()) + \
10783- THREAD_SIZE - (unsigned long)(ADDR)))
10784+#define MAX_STACK_SIZE 64UL
10785+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10786
10787 #define flush_insn_slot(p) do { } while (0)
10788
10789diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10790index e216ba0..453f6ec 100644
10791--- a/arch/x86/include/asm/kvm_host.h
10792+++ b/arch/x86/include/asm/kvm_host.h
10793@@ -679,7 +679,7 @@ struct kvm_x86_ops {
10794 int (*check_intercept)(struct kvm_vcpu *vcpu,
10795 struct x86_instruction_info *info,
10796 enum x86_intercept_stage stage);
10797-};
10798+} __do_const;
10799
10800 struct kvm_arch_async_pf {
10801 u32 token;
10802diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10803index c8bed0d..e5721fa 100644
10804--- a/arch/x86/include/asm/local.h
10805+++ b/arch/x86/include/asm/local.h
10806@@ -17,26 +17,58 @@ typedef struct {
10807
10808 static inline void local_inc(local_t *l)
10809 {
10810- asm volatile(_ASM_INC "%0"
10811+ asm volatile(_ASM_INC "%0\n"
10812+
10813+#ifdef CONFIG_PAX_REFCOUNT
10814+ "jno 0f\n"
10815+ _ASM_DEC "%0\n"
10816+ "int $4\n0:\n"
10817+ _ASM_EXTABLE(0b, 0b)
10818+#endif
10819+
10820 : "+m" (l->a.counter));
10821 }
10822
10823 static inline void local_dec(local_t *l)
10824 {
10825- asm volatile(_ASM_DEC "%0"
10826+ asm volatile(_ASM_DEC "%0\n"
10827+
10828+#ifdef CONFIG_PAX_REFCOUNT
10829+ "jno 0f\n"
10830+ _ASM_INC "%0\n"
10831+ "int $4\n0:\n"
10832+ _ASM_EXTABLE(0b, 0b)
10833+#endif
10834+
10835 : "+m" (l->a.counter));
10836 }
10837
10838 static inline void local_add(long i, local_t *l)
10839 {
10840- asm volatile(_ASM_ADD "%1,%0"
10841+ asm volatile(_ASM_ADD "%1,%0\n"
10842+
10843+#ifdef CONFIG_PAX_REFCOUNT
10844+ "jno 0f\n"
10845+ _ASM_SUB "%1,%0\n"
10846+ "int $4\n0:\n"
10847+ _ASM_EXTABLE(0b, 0b)
10848+#endif
10849+
10850 : "+m" (l->a.counter)
10851 : "ir" (i));
10852 }
10853
10854 static inline void local_sub(long i, local_t *l)
10855 {
10856- asm volatile(_ASM_SUB "%1,%0"
10857+ asm volatile(_ASM_SUB "%1,%0\n"
10858+
10859+#ifdef CONFIG_PAX_REFCOUNT
10860+ "jno 0f\n"
10861+ _ASM_ADD "%1,%0\n"
10862+ "int $4\n0:\n"
10863+ _ASM_EXTABLE(0b, 0b)
10864+#endif
10865+
10866 : "+m" (l->a.counter)
10867 : "ir" (i));
10868 }
10869@@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10870 {
10871 unsigned char c;
10872
10873- asm volatile(_ASM_SUB "%2,%0; sete %1"
10874+ asm volatile(_ASM_SUB "%2,%0\n"
10875+
10876+#ifdef CONFIG_PAX_REFCOUNT
10877+ "jno 0f\n"
10878+ _ASM_ADD "%2,%0\n"
10879+ "int $4\n0:\n"
10880+ _ASM_EXTABLE(0b, 0b)
10881+#endif
10882+
10883+ "sete %1\n"
10884 : "+m" (l->a.counter), "=qm" (c)
10885 : "ir" (i) : "memory");
10886 return c;
10887@@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10888 {
10889 unsigned char c;
10890
10891- asm volatile(_ASM_DEC "%0; sete %1"
10892+ asm volatile(_ASM_DEC "%0\n"
10893+
10894+#ifdef CONFIG_PAX_REFCOUNT
10895+ "jno 0f\n"
10896+ _ASM_INC "%0\n"
10897+ "int $4\n0:\n"
10898+ _ASM_EXTABLE(0b, 0b)
10899+#endif
10900+
10901+ "sete %1\n"
10902 : "+m" (l->a.counter), "=qm" (c)
10903 : : "memory");
10904 return c != 0;
10905@@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10906 {
10907 unsigned char c;
10908
10909- asm volatile(_ASM_INC "%0; sete %1"
10910+ asm volatile(_ASM_INC "%0\n"
10911+
10912+#ifdef CONFIG_PAX_REFCOUNT
10913+ "jno 0f\n"
10914+ _ASM_DEC "%0\n"
10915+ "int $4\n0:\n"
10916+ _ASM_EXTABLE(0b, 0b)
10917+#endif
10918+
10919+ "sete %1\n"
10920 : "+m" (l->a.counter), "=qm" (c)
10921 : : "memory");
10922 return c != 0;
10923@@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10924 {
10925 unsigned char c;
10926
10927- asm volatile(_ASM_ADD "%2,%0; sets %1"
10928+ asm volatile(_ASM_ADD "%2,%0\n"
10929+
10930+#ifdef CONFIG_PAX_REFCOUNT
10931+ "jno 0f\n"
10932+ _ASM_SUB "%2,%0\n"
10933+ "int $4\n0:\n"
10934+ _ASM_EXTABLE(0b, 0b)
10935+#endif
10936+
10937+ "sets %1\n"
10938 : "+m" (l->a.counter), "=qm" (c)
10939 : "ir" (i) : "memory");
10940 return c;
10941@@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10942 #endif
10943 /* Modern 486+ processor */
10944 __i = i;
10945- asm volatile(_ASM_XADD "%0, %1;"
10946+ asm volatile(_ASM_XADD "%0, %1\n"
10947+
10948+#ifdef CONFIG_PAX_REFCOUNT
10949+ "jno 0f\n"
10950+ _ASM_MOV "%0,%1\n"
10951+ "int $4\n0:\n"
10952+ _ASM_EXTABLE(0b, 0b)
10953+#endif
10954+
10955 : "+r" (i), "+m" (l->a.counter)
10956 : : "memory");
10957 return i + __i;
10958diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10959index 593e51d..fa69c9a 100644
10960--- a/arch/x86/include/asm/mman.h
10961+++ b/arch/x86/include/asm/mman.h
10962@@ -5,4 +5,14 @@
10963
10964 #include <asm-generic/mman.h>
10965
10966+#ifdef __KERNEL__
10967+#ifndef __ASSEMBLY__
10968+#ifdef CONFIG_X86_32
10969+#define arch_mmap_check i386_mmap_check
10970+int i386_mmap_check(unsigned long addr, unsigned long len,
10971+ unsigned long flags);
10972+#endif
10973+#endif
10974+#endif
10975+
10976 #endif /* _ASM_X86_MMAN_H */
10977diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10978index 5f55e69..e20bfb1 100644
10979--- a/arch/x86/include/asm/mmu.h
10980+++ b/arch/x86/include/asm/mmu.h
10981@@ -9,7 +9,7 @@
10982 * we put the segment information here.
10983 */
10984 typedef struct {
10985- void *ldt;
10986+ struct desc_struct *ldt;
10987 int size;
10988
10989 #ifdef CONFIG_X86_64
10990@@ -18,7 +18,19 @@ typedef struct {
10991 #endif
10992
10993 struct mutex lock;
10994- void *vdso;
10995+ unsigned long vdso;
10996+
10997+#ifdef CONFIG_X86_32
10998+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10999+ unsigned long user_cs_base;
11000+ unsigned long user_cs_limit;
11001+
11002+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11003+ cpumask_t cpu_user_cs_mask;
11004+#endif
11005+
11006+#endif
11007+#endif
11008 } mm_context_t;
11009
11010 #ifdef CONFIG_SMP
11011diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
11012index 6902152..da4283a 100644
11013--- a/arch/x86/include/asm/mmu_context.h
11014+++ b/arch/x86/include/asm/mmu_context.h
11015@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
11016
11017 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11018 {
11019+
11020+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11021+ unsigned int i;
11022+ pgd_t *pgd;
11023+
11024+ pax_open_kernel();
11025+ pgd = get_cpu_pgd(smp_processor_id());
11026+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
11027+ set_pgd_batched(pgd+i, native_make_pgd(0));
11028+ pax_close_kernel();
11029+#endif
11030+
11031 #ifdef CONFIG_SMP
11032 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
11033 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
11034@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11035 struct task_struct *tsk)
11036 {
11037 unsigned cpu = smp_processor_id();
11038+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11039+ int tlbstate = TLBSTATE_OK;
11040+#endif
11041
11042 if (likely(prev != next)) {
11043 #ifdef CONFIG_SMP
11044+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11045+ tlbstate = percpu_read(cpu_tlbstate.state);
11046+#endif
11047 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11048 percpu_write(cpu_tlbstate.active_mm, next);
11049 #endif
11050 cpumask_set_cpu(cpu, mm_cpumask(next));
11051
11052 /* Re-load page tables */
11053+#ifdef CONFIG_PAX_PER_CPU_PGD
11054+ pax_open_kernel();
11055+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11056+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11057+ pax_close_kernel();
11058+ load_cr3(get_cpu_pgd(cpu));
11059+#else
11060 load_cr3(next->pgd);
11061+#endif
11062
11063 /* stop flush ipis for the previous mm */
11064 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11065@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11066 */
11067 if (unlikely(prev->context.ldt != next->context.ldt))
11068 load_LDT_nolock(&next->context);
11069- }
11070+
11071+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11072+ if (!(__supported_pte_mask & _PAGE_NX)) {
11073+ smp_mb__before_clear_bit();
11074+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11075+ smp_mb__after_clear_bit();
11076+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11077+ }
11078+#endif
11079+
11080+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11081+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11082+ prev->context.user_cs_limit != next->context.user_cs_limit))
11083+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11084 #ifdef CONFIG_SMP
11085+ else if (unlikely(tlbstate != TLBSTATE_OK))
11086+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11087+#endif
11088+#endif
11089+
11090+ }
11091 else {
11092+
11093+#ifdef CONFIG_PAX_PER_CPU_PGD
11094+ pax_open_kernel();
11095+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11096+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11097+ pax_close_kernel();
11098+ load_cr3(get_cpu_pgd(cpu));
11099+#endif
11100+
11101+#ifdef CONFIG_SMP
11102 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11103 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
11104
11105@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11106 * tlb flush IPI delivery. We must reload CR3
11107 * to make sure to use no freed page tables.
11108 */
11109+
11110+#ifndef CONFIG_PAX_PER_CPU_PGD
11111 load_cr3(next->pgd);
11112+#endif
11113+
11114 load_LDT_nolock(&next->context);
11115+
11116+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11117+ if (!(__supported_pte_mask & _PAGE_NX))
11118+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11119+#endif
11120+
11121+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11122+#ifdef CONFIG_PAX_PAGEEXEC
11123+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11124+#endif
11125+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11126+#endif
11127+
11128 }
11129+#endif
11130 }
11131-#endif
11132 }
11133
11134 #define activate_mm(prev, next) \
11135diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11136index 9eae775..c914fea 100644
11137--- a/arch/x86/include/asm/module.h
11138+++ b/arch/x86/include/asm/module.h
11139@@ -5,6 +5,7 @@
11140
11141 #ifdef CONFIG_X86_64
11142 /* X86_64 does not define MODULE_PROC_FAMILY */
11143+#define MODULE_PROC_FAMILY ""
11144 #elif defined CONFIG_M386
11145 #define MODULE_PROC_FAMILY "386 "
11146 #elif defined CONFIG_M486
11147@@ -59,8 +60,20 @@
11148 #error unknown processor family
11149 #endif
11150
11151-#ifdef CONFIG_X86_32
11152-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11153+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11154+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11155+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11156+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11157+#else
11158+#define MODULE_PAX_KERNEXEC ""
11159 #endif
11160
11161+#ifdef CONFIG_PAX_MEMORY_UDEREF
11162+#define MODULE_PAX_UDEREF "UDEREF "
11163+#else
11164+#define MODULE_PAX_UDEREF ""
11165+#endif
11166+
11167+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11168+
11169 #endif /* _ASM_X86_MODULE_H */
11170diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11171index 7639dbf..e08a58c 100644
11172--- a/arch/x86/include/asm/page_64_types.h
11173+++ b/arch/x86/include/asm/page_64_types.h
11174@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11175
11176 /* duplicated to the one in bootmem.h */
11177 extern unsigned long max_pfn;
11178-extern unsigned long phys_base;
11179+extern const unsigned long phys_base;
11180
11181 extern unsigned long __phys_addr(unsigned long);
11182 #define __phys_reloc_hide(x) (x)
11183diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11184index aa0f913..0c5bc6a 100644
11185--- a/arch/x86/include/asm/paravirt.h
11186+++ b/arch/x86/include/asm/paravirt.h
11187@@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11188 val);
11189 }
11190
11191+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11192+{
11193+ pgdval_t val = native_pgd_val(pgd);
11194+
11195+ if (sizeof(pgdval_t) > sizeof(long))
11196+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11197+ val, (u64)val >> 32);
11198+ else
11199+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11200+ val);
11201+}
11202+
11203 static inline void pgd_clear(pgd_t *pgdp)
11204 {
11205 set_pgd(pgdp, __pgd(0));
11206@@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11207 pv_mmu_ops.set_fixmap(idx, phys, flags);
11208 }
11209
11210+#ifdef CONFIG_PAX_KERNEXEC
11211+static inline unsigned long pax_open_kernel(void)
11212+{
11213+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11214+}
11215+
11216+static inline unsigned long pax_close_kernel(void)
11217+{
11218+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11219+}
11220+#else
11221+static inline unsigned long pax_open_kernel(void) { return 0; }
11222+static inline unsigned long pax_close_kernel(void) { return 0; }
11223+#endif
11224+
11225 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11226
11227 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11228@@ -965,7 +992,7 @@ extern void default_banner(void);
11229
11230 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11231 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11232-#define PARA_INDIRECT(addr) *%cs:addr
11233+#define PARA_INDIRECT(addr) *%ss:addr
11234 #endif
11235
11236 #define INTERRUPT_RETURN \
11237@@ -1042,6 +1069,21 @@ extern void default_banner(void);
11238 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11239 CLBR_NONE, \
11240 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11241+
11242+#define GET_CR0_INTO_RDI \
11243+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11244+ mov %rax,%rdi
11245+
11246+#define SET_RDI_INTO_CR0 \
11247+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11248+
11249+#define GET_CR3_INTO_RDI \
11250+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11251+ mov %rax,%rdi
11252+
11253+#define SET_RDI_INTO_CR3 \
11254+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11255+
11256 #endif /* CONFIG_X86_32 */
11257
11258 #endif /* __ASSEMBLY__ */
11259diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11260index 8e8b9a4..f07d725 100644
11261--- a/arch/x86/include/asm/paravirt_types.h
11262+++ b/arch/x86/include/asm/paravirt_types.h
11263@@ -84,20 +84,20 @@ struct pv_init_ops {
11264 */
11265 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11266 unsigned long addr, unsigned len);
11267-};
11268+} __no_const;
11269
11270
11271 struct pv_lazy_ops {
11272 /* Set deferred update mode, used for batching operations. */
11273 void (*enter)(void);
11274 void (*leave)(void);
11275-};
11276+} __no_const;
11277
11278 struct pv_time_ops {
11279 unsigned long long (*sched_clock)(void);
11280 unsigned long long (*steal_clock)(int cpu);
11281 unsigned long (*get_tsc_khz)(void);
11282-};
11283+} __no_const;
11284
11285 struct pv_cpu_ops {
11286 /* hooks for various privileged instructions */
11287@@ -193,7 +193,7 @@ struct pv_cpu_ops {
11288
11289 void (*start_context_switch)(struct task_struct *prev);
11290 void (*end_context_switch)(struct task_struct *next);
11291-};
11292+} __no_const;
11293
11294 struct pv_irq_ops {
11295 /*
11296@@ -224,7 +224,7 @@ struct pv_apic_ops {
11297 unsigned long start_eip,
11298 unsigned long start_esp);
11299 #endif
11300-};
11301+} __no_const;
11302
11303 struct pv_mmu_ops {
11304 unsigned long (*read_cr2)(void);
11305@@ -313,6 +313,7 @@ struct pv_mmu_ops {
11306 struct paravirt_callee_save make_pud;
11307
11308 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11309+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11310 #endif /* PAGETABLE_LEVELS == 4 */
11311 #endif /* PAGETABLE_LEVELS >= 3 */
11312
11313@@ -324,6 +325,12 @@ struct pv_mmu_ops {
11314 an mfn. We can tell which is which from the index. */
11315 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11316 phys_addr_t phys, pgprot_t flags);
11317+
11318+#ifdef CONFIG_PAX_KERNEXEC
11319+ unsigned long (*pax_open_kernel)(void);
11320+ unsigned long (*pax_close_kernel)(void);
11321+#endif
11322+
11323 };
11324
11325 struct arch_spinlock;
11326@@ -334,7 +341,7 @@ struct pv_lock_ops {
11327 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11328 int (*spin_trylock)(struct arch_spinlock *lock);
11329 void (*spin_unlock)(struct arch_spinlock *lock);
11330-};
11331+} __no_const;
11332
11333 /* This contains all the paravirt structures: we get a convenient
11334 * number for each function using the offset which we use to indicate
11335diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11336index b4389a4..7024269 100644
11337--- a/arch/x86/include/asm/pgalloc.h
11338+++ b/arch/x86/include/asm/pgalloc.h
11339@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11340 pmd_t *pmd, pte_t *pte)
11341 {
11342 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11343+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11344+}
11345+
11346+static inline void pmd_populate_user(struct mm_struct *mm,
11347+ pmd_t *pmd, pte_t *pte)
11348+{
11349+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11350 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11351 }
11352
11353@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11354
11355 #ifdef CONFIG_X86_PAE
11356 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11357+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11358+{
11359+ pud_populate(mm, pudp, pmd);
11360+}
11361 #else /* !CONFIG_X86_PAE */
11362 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11363 {
11364 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11365 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11366 }
11367+
11368+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11369+{
11370+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11371+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11372+}
11373 #endif /* CONFIG_X86_PAE */
11374
11375 #if PAGETABLE_LEVELS > 3
11376@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11377 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11378 }
11379
11380+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11381+{
11382+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11383+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11384+}
11385+
11386 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11387 {
11388 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11389diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11390index 98391db..8f6984e 100644
11391--- a/arch/x86/include/asm/pgtable-2level.h
11392+++ b/arch/x86/include/asm/pgtable-2level.h
11393@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11394
11395 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11396 {
11397+ pax_open_kernel();
11398 *pmdp = pmd;
11399+ pax_close_kernel();
11400 }
11401
11402 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11403diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11404index cb00ccc..17e9054 100644
11405--- a/arch/x86/include/asm/pgtable-3level.h
11406+++ b/arch/x86/include/asm/pgtable-3level.h
11407@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11408
11409 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11410 {
11411+ pax_open_kernel();
11412 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11413+ pax_close_kernel();
11414 }
11415
11416 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11417 {
11418+ pax_open_kernel();
11419 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11420+ pax_close_kernel();
11421 }
11422
11423 /*
11424diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11425index 49afb3f..91a8c63 100644
11426--- a/arch/x86/include/asm/pgtable.h
11427+++ b/arch/x86/include/asm/pgtable.h
11428@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11429
11430 #ifndef __PAGETABLE_PUD_FOLDED
11431 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11432+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11433 #define pgd_clear(pgd) native_pgd_clear(pgd)
11434 #endif
11435
11436@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11437
11438 #define arch_end_context_switch(prev) do {} while(0)
11439
11440+#define pax_open_kernel() native_pax_open_kernel()
11441+#define pax_close_kernel() native_pax_close_kernel()
11442 #endif /* CONFIG_PARAVIRT */
11443
11444+#define __HAVE_ARCH_PAX_OPEN_KERNEL
11445+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11446+
11447+#ifdef CONFIG_PAX_KERNEXEC
11448+static inline unsigned long native_pax_open_kernel(void)
11449+{
11450+ unsigned long cr0;
11451+
11452+ preempt_disable();
11453+ barrier();
11454+ cr0 = read_cr0() ^ X86_CR0_WP;
11455+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11456+ write_cr0(cr0);
11457+ return cr0 ^ X86_CR0_WP;
11458+}
11459+
11460+static inline unsigned long native_pax_close_kernel(void)
11461+{
11462+ unsigned long cr0;
11463+
11464+ cr0 = read_cr0() ^ X86_CR0_WP;
11465+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11466+ write_cr0(cr0);
11467+ barrier();
11468+ preempt_enable_no_resched();
11469+ return cr0 ^ X86_CR0_WP;
11470+}
11471+#else
11472+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11473+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11474+#endif
11475+
11476 /*
11477 * The following only work if pte_present() is true.
11478 * Undefined behaviour if not..
11479 */
11480+static inline int pte_user(pte_t pte)
11481+{
11482+ return pte_val(pte) & _PAGE_USER;
11483+}
11484+
11485 static inline int pte_dirty(pte_t pte)
11486 {
11487 return pte_flags(pte) & _PAGE_DIRTY;
11488@@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11489 return pte_clear_flags(pte, _PAGE_RW);
11490 }
11491
11492+static inline pte_t pte_mkread(pte_t pte)
11493+{
11494+ return __pte(pte_val(pte) | _PAGE_USER);
11495+}
11496+
11497 static inline pte_t pte_mkexec(pte_t pte)
11498 {
11499- return pte_clear_flags(pte, _PAGE_NX);
11500+#ifdef CONFIG_X86_PAE
11501+ if (__supported_pte_mask & _PAGE_NX)
11502+ return pte_clear_flags(pte, _PAGE_NX);
11503+ else
11504+#endif
11505+ return pte_set_flags(pte, _PAGE_USER);
11506+}
11507+
11508+static inline pte_t pte_exprotect(pte_t pte)
11509+{
11510+#ifdef CONFIG_X86_PAE
11511+ if (__supported_pte_mask & _PAGE_NX)
11512+ return pte_set_flags(pte, _PAGE_NX);
11513+ else
11514+#endif
11515+ return pte_clear_flags(pte, _PAGE_USER);
11516 }
11517
11518 static inline pte_t pte_mkdirty(pte_t pte)
11519@@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11520 #endif
11521
11522 #ifndef __ASSEMBLY__
11523+
11524+#ifdef CONFIG_PAX_PER_CPU_PGD
11525+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11526+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11527+{
11528+ return cpu_pgd[cpu];
11529+}
11530+#endif
11531+
11532 #include <linux/mm_types.h>
11533
11534 static inline int pte_none(pte_t pte)
11535@@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11536
11537 static inline int pgd_bad(pgd_t pgd)
11538 {
11539- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11540+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11541 }
11542
11543 static inline int pgd_none(pgd_t pgd)
11544@@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11545 * pgd_offset() returns a (pgd_t *)
11546 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11547 */
11548-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11549+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11550+
11551+#ifdef CONFIG_PAX_PER_CPU_PGD
11552+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11553+#endif
11554+
11555 /*
11556 * a shortcut which implies the use of the kernel's pgd, instead
11557 * of a process's
11558@@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11559 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11560 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11561
11562+#ifdef CONFIG_X86_32
11563+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11564+#else
11565+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11566+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11567+
11568+#ifdef CONFIG_PAX_MEMORY_UDEREF
11569+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11570+#else
11571+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11572+#endif
11573+
11574+#endif
11575+
11576 #ifndef __ASSEMBLY__
11577
11578 extern int direct_gbpages;
11579@@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11580 * dst and src can be on the same page, but the range must not overlap,
11581 * and must not cross a page boundary.
11582 */
11583-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11584+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11585 {
11586- memcpy(dst, src, count * sizeof(pgd_t));
11587+ pax_open_kernel();
11588+ while (count--)
11589+ *dst++ = *src++;
11590+ pax_close_kernel();
11591 }
11592
11593+#ifdef CONFIG_PAX_PER_CPU_PGD
11594+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11595+#endif
11596+
11597+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11598+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11599+#else
11600+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11601+#endif
11602
11603 #include <asm-generic/pgtable.h>
11604 #endif /* __ASSEMBLY__ */
11605diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11606index 0c92113..34a77c6 100644
11607--- a/arch/x86/include/asm/pgtable_32.h
11608+++ b/arch/x86/include/asm/pgtable_32.h
11609@@ -25,9 +25,6 @@
11610 struct mm_struct;
11611 struct vm_area_struct;
11612
11613-extern pgd_t swapper_pg_dir[1024];
11614-extern pgd_t initial_page_table[1024];
11615-
11616 static inline void pgtable_cache_init(void) { }
11617 static inline void check_pgt_cache(void) { }
11618 void paging_init(void);
11619@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11620 # include <asm/pgtable-2level.h>
11621 #endif
11622
11623+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11624+extern pgd_t initial_page_table[PTRS_PER_PGD];
11625+#ifdef CONFIG_X86_PAE
11626+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11627+#endif
11628+
11629 #if defined(CONFIG_HIGHPTE)
11630 #define pte_offset_map(dir, address) \
11631 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11632@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11633 /* Clear a kernel PTE and flush it from the TLB */
11634 #define kpte_clear_flush(ptep, vaddr) \
11635 do { \
11636+ pax_open_kernel(); \
11637 pte_clear(&init_mm, (vaddr), (ptep)); \
11638+ pax_close_kernel(); \
11639 __flush_tlb_one((vaddr)); \
11640 } while (0)
11641
11642@@ -74,6 +79,9 @@ do { \
11643
11644 #endif /* !__ASSEMBLY__ */
11645
11646+#define HAVE_ARCH_UNMAPPED_AREA
11647+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11648+
11649 /*
11650 * kern_addr_valid() is (1) for FLATMEM and (0) for
11651 * SPARSEMEM and DISCONTIGMEM
11652diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11653index ed5903b..c7fe163 100644
11654--- a/arch/x86/include/asm/pgtable_32_types.h
11655+++ b/arch/x86/include/asm/pgtable_32_types.h
11656@@ -8,7 +8,7 @@
11657 */
11658 #ifdef CONFIG_X86_PAE
11659 # include <asm/pgtable-3level_types.h>
11660-# define PMD_SIZE (1UL << PMD_SHIFT)
11661+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11662 # define PMD_MASK (~(PMD_SIZE - 1))
11663 #else
11664 # include <asm/pgtable-2level_types.h>
11665@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11666 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11667 #endif
11668
11669+#ifdef CONFIG_PAX_KERNEXEC
11670+#ifndef __ASSEMBLY__
11671+extern unsigned char MODULES_EXEC_VADDR[];
11672+extern unsigned char MODULES_EXEC_END[];
11673+#endif
11674+#include <asm/boot.h>
11675+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11676+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11677+#else
11678+#define ktla_ktva(addr) (addr)
11679+#define ktva_ktla(addr) (addr)
11680+#endif
11681+
11682 #define MODULES_VADDR VMALLOC_START
11683 #define MODULES_END VMALLOC_END
11684 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11685diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11686index 975f709..9f779c9 100644
11687--- a/arch/x86/include/asm/pgtable_64.h
11688+++ b/arch/x86/include/asm/pgtable_64.h
11689@@ -16,10 +16,14 @@
11690
11691 extern pud_t level3_kernel_pgt[512];
11692 extern pud_t level3_ident_pgt[512];
11693+extern pud_t level3_vmalloc_start_pgt[512];
11694+extern pud_t level3_vmalloc_end_pgt[512];
11695+extern pud_t level3_vmemmap_pgt[512];
11696+extern pud_t level2_vmemmap_pgt[512];
11697 extern pmd_t level2_kernel_pgt[512];
11698 extern pmd_t level2_fixmap_pgt[512];
11699-extern pmd_t level2_ident_pgt[512];
11700-extern pgd_t init_level4_pgt[];
11701+extern pmd_t level2_ident_pgt[512*2];
11702+extern pgd_t init_level4_pgt[512];
11703
11704 #define swapper_pg_dir init_level4_pgt
11705
11706@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11707
11708 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11709 {
11710+ pax_open_kernel();
11711 *pmdp = pmd;
11712+ pax_close_kernel();
11713 }
11714
11715 static inline void native_pmd_clear(pmd_t *pmd)
11716@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11717
11718 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11719 {
11720+ pax_open_kernel();
11721 *pudp = pud;
11722+ pax_close_kernel();
11723 }
11724
11725 static inline void native_pud_clear(pud_t *pud)
11726@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11727
11728 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11729 {
11730+ pax_open_kernel();
11731+ *pgdp = pgd;
11732+ pax_close_kernel();
11733+}
11734+
11735+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11736+{
11737 *pgdp = pgd;
11738 }
11739
11740diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11741index 766ea16..5b96cb3 100644
11742--- a/arch/x86/include/asm/pgtable_64_types.h
11743+++ b/arch/x86/include/asm/pgtable_64_types.h
11744@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11745 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11746 #define MODULES_END _AC(0xffffffffff000000, UL)
11747 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11748+#define MODULES_EXEC_VADDR MODULES_VADDR
11749+#define MODULES_EXEC_END MODULES_END
11750+
11751+#define ktla_ktva(addr) (addr)
11752+#define ktva_ktla(addr) (addr)
11753
11754 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11755diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11756index 013286a..8b42f4f 100644
11757--- a/arch/x86/include/asm/pgtable_types.h
11758+++ b/arch/x86/include/asm/pgtable_types.h
11759@@ -16,13 +16,12 @@
11760 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11761 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11762 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11763-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11764+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11765 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11766 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11767 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11768-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11769-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11770-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11771+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11772+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11773 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11774
11775 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11776@@ -40,7 +39,6 @@
11777 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11778 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11779 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11780-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11781 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11782 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11783 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11784@@ -57,8 +55,10 @@
11785
11786 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11787 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11788-#else
11789+#elif defined(CONFIG_KMEMCHECK)
11790 #define _PAGE_NX (_AT(pteval_t, 0))
11791+#else
11792+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11793 #endif
11794
11795 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11796@@ -96,6 +96,9 @@
11797 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11798 _PAGE_ACCESSED)
11799
11800+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11801+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11802+
11803 #define __PAGE_KERNEL_EXEC \
11804 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11805 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11806@@ -106,7 +109,7 @@
11807 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11808 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11809 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11810-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11811+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11812 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11813 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11814 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11815@@ -168,8 +171,8 @@
11816 * bits are combined, this will alow user to access the high address mapped
11817 * VDSO in the presence of CONFIG_COMPAT_VDSO
11818 */
11819-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11820-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11821+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11822+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11823 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11824 #endif
11825
11826@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11827 {
11828 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11829 }
11830+#endif
11831
11832+#if PAGETABLE_LEVELS == 3
11833+#include <asm-generic/pgtable-nopud.h>
11834+#endif
11835+
11836+#if PAGETABLE_LEVELS == 2
11837+#include <asm-generic/pgtable-nopmd.h>
11838+#endif
11839+
11840+#ifndef __ASSEMBLY__
11841 #if PAGETABLE_LEVELS > 3
11842 typedef struct { pudval_t pud; } pud_t;
11843
11844@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11845 return pud.pud;
11846 }
11847 #else
11848-#include <asm-generic/pgtable-nopud.h>
11849-
11850 static inline pudval_t native_pud_val(pud_t pud)
11851 {
11852 return native_pgd_val(pud.pgd);
11853@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11854 return pmd.pmd;
11855 }
11856 #else
11857-#include <asm-generic/pgtable-nopmd.h>
11858-
11859 static inline pmdval_t native_pmd_val(pmd_t pmd)
11860 {
11861 return native_pgd_val(pmd.pud.pgd);
11862@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11863
11864 extern pteval_t __supported_pte_mask;
11865 extern void set_nx(void);
11866-extern int nx_enabled;
11867
11868 #define pgprot_writecombine pgprot_writecombine
11869 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11870diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11871index 4fa7dcc..764e33a 100644
11872--- a/arch/x86/include/asm/processor.h
11873+++ b/arch/x86/include/asm/processor.h
11874@@ -276,7 +276,7 @@ struct tss_struct {
11875
11876 } ____cacheline_aligned;
11877
11878-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11879+extern struct tss_struct init_tss[NR_CPUS];
11880
11881 /*
11882 * Save the original ist values for checking stack pointers during debugging
11883@@ -807,11 +807,18 @@ static inline void spin_lock_prefetch(const void *x)
11884 */
11885 #define TASK_SIZE PAGE_OFFSET
11886 #define TASK_SIZE_MAX TASK_SIZE
11887+
11888+#ifdef CONFIG_PAX_SEGMEXEC
11889+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11890+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11891+#else
11892 #define STACK_TOP TASK_SIZE
11893-#define STACK_TOP_MAX STACK_TOP
11894+#endif
11895+
11896+#define STACK_TOP_MAX TASK_SIZE
11897
11898 #define INIT_THREAD { \
11899- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11900+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11901 .vm86_info = NULL, \
11902 .sysenter_cs = __KERNEL_CS, \
11903 .io_bitmap_ptr = NULL, \
11904@@ -825,7 +832,7 @@ static inline void spin_lock_prefetch(const void *x)
11905 */
11906 #define INIT_TSS { \
11907 .x86_tss = { \
11908- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11909+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11910 .ss0 = __KERNEL_DS, \
11911 .ss1 = __KERNEL_CS, \
11912 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11913@@ -836,11 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
11914 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11915
11916 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11917-#define KSTK_TOP(info) \
11918-({ \
11919- unsigned long *__ptr = (unsigned long *)(info); \
11920- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11921-})
11922+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11923
11924 /*
11925 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11926@@ -855,7 +858,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11927 #define task_pt_regs(task) \
11928 ({ \
11929 struct pt_regs *__regs__; \
11930- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11931+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11932 __regs__ - 1; \
11933 })
11934
11935@@ -865,13 +868,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11936 /*
11937 * User space process size. 47bits minus one guard page.
11938 */
11939-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11940+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11941
11942 /* This decides where the kernel will search for a free chunk of vm
11943 * space during mmap's.
11944 */
11945 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11946- 0xc0000000 : 0xFFFFe000)
11947+ 0xc0000000 : 0xFFFFf000)
11948
11949 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11950 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11951@@ -882,11 +885,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11952 #define STACK_TOP_MAX TASK_SIZE_MAX
11953
11954 #define INIT_THREAD { \
11955- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11956+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11957 }
11958
11959 #define INIT_TSS { \
11960- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11961+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11962 }
11963
11964 /*
11965@@ -914,6 +917,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11966 */
11967 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11968
11969+#ifdef CONFIG_PAX_SEGMEXEC
11970+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11971+#endif
11972+
11973 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11974
11975 /* Get/set a process' ability to use the timestamp counter instruction */
11976@@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11977
11978 void cpu_idle_wait(void);
11979
11980-extern unsigned long arch_align_stack(unsigned long sp);
11981+#define arch_align_stack(x) ((x) & ~0xfUL)
11982 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11983
11984 void default_idle(void);
11985 bool set_pm_idle_to_default(void);
11986
11987-void stop_this_cpu(void *dummy);
11988+void stop_this_cpu(void *dummy) __noreturn;
11989
11990 #endif /* _ASM_X86_PROCESSOR_H */
11991diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11992index dcfde52..dbfea06 100644
11993--- a/arch/x86/include/asm/ptrace.h
11994+++ b/arch/x86/include/asm/ptrace.h
11995@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11996 }
11997
11998 /*
11999- * user_mode_vm(regs) determines whether a register set came from user mode.
12000+ * user_mode(regs) determines whether a register set came from user mode.
12001 * This is true if V8086 mode was enabled OR if the register set was from
12002 * protected mode with RPL-3 CS value. This tricky test checks that with
12003 * one comparison. Many places in the kernel can bypass this full check
12004- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
12005+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
12006+ * be used.
12007 */
12008-static inline int user_mode(struct pt_regs *regs)
12009+static inline int user_mode_novm(struct pt_regs *regs)
12010 {
12011 #ifdef CONFIG_X86_32
12012 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
12013 #else
12014- return !!(regs->cs & 3);
12015+ return !!(regs->cs & SEGMENT_RPL_MASK);
12016 #endif
12017 }
12018
12019-static inline int user_mode_vm(struct pt_regs *regs)
12020+static inline int user_mode(struct pt_regs *regs)
12021 {
12022 #ifdef CONFIG_X86_32
12023 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12024 USER_RPL;
12025 #else
12026- return user_mode(regs);
12027+ return user_mode_novm(regs);
12028 #endif
12029 }
12030
12031@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12032 #ifdef CONFIG_X86_64
12033 static inline bool user_64bit_mode(struct pt_regs *regs)
12034 {
12035+ unsigned long cs = regs->cs & 0xffff;
12036 #ifndef CONFIG_PARAVIRT
12037 /*
12038 * On non-paravirt systems, this is the only long mode CPL 3
12039 * selector. We do not allow long mode selectors in the LDT.
12040 */
12041- return regs->cs == __USER_CS;
12042+ return cs == __USER_CS;
12043 #else
12044 /* Headers are too twisted for this to go in paravirt.h. */
12045- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12046+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12047 #endif
12048 }
12049 #endif
12050diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12051index 92f29706..a79cbbb 100644
12052--- a/arch/x86/include/asm/reboot.h
12053+++ b/arch/x86/include/asm/reboot.h
12054@@ -6,19 +6,19 @@
12055 struct pt_regs;
12056
12057 struct machine_ops {
12058- void (*restart)(char *cmd);
12059- void (*halt)(void);
12060- void (*power_off)(void);
12061+ void (* __noreturn restart)(char *cmd);
12062+ void (* __noreturn halt)(void);
12063+ void (* __noreturn power_off)(void);
12064 void (*shutdown)(void);
12065 void (*crash_shutdown)(struct pt_regs *);
12066- void (*emergency_restart)(void);
12067-};
12068+ void (* __noreturn emergency_restart)(void);
12069+} __no_const;
12070
12071 extern struct machine_ops machine_ops;
12072
12073 void native_machine_crash_shutdown(struct pt_regs *regs);
12074 void native_machine_shutdown(void);
12075-void machine_real_restart(unsigned int type);
12076+void machine_real_restart(unsigned int type) __noreturn;
12077 /* These must match dispatch_table in reboot_32.S */
12078 #define MRR_BIOS 0
12079 #define MRR_APM 1
12080diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12081index 2dbe4a7..ce1db00 100644
12082--- a/arch/x86/include/asm/rwsem.h
12083+++ b/arch/x86/include/asm/rwsem.h
12084@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12085 {
12086 asm volatile("# beginning down_read\n\t"
12087 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12088+
12089+#ifdef CONFIG_PAX_REFCOUNT
12090+ "jno 0f\n"
12091+ LOCK_PREFIX _ASM_DEC "(%1)\n"
12092+ "int $4\n0:\n"
12093+ _ASM_EXTABLE(0b, 0b)
12094+#endif
12095+
12096 /* adds 0x00000001 */
12097 " jns 1f\n"
12098 " call call_rwsem_down_read_failed\n"
12099@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12100 "1:\n\t"
12101 " mov %1,%2\n\t"
12102 " add %3,%2\n\t"
12103+
12104+#ifdef CONFIG_PAX_REFCOUNT
12105+ "jno 0f\n"
12106+ "sub %3,%2\n"
12107+ "int $4\n0:\n"
12108+ _ASM_EXTABLE(0b, 0b)
12109+#endif
12110+
12111 " jle 2f\n\t"
12112 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12113 " jnz 1b\n\t"
12114@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12115 long tmp;
12116 asm volatile("# beginning down_write\n\t"
12117 LOCK_PREFIX " xadd %1,(%2)\n\t"
12118+
12119+#ifdef CONFIG_PAX_REFCOUNT
12120+ "jno 0f\n"
12121+ "mov %1,(%2)\n"
12122+ "int $4\n0:\n"
12123+ _ASM_EXTABLE(0b, 0b)
12124+#endif
12125+
12126 /* adds 0xffff0001, returns the old value */
12127 " test %1,%1\n\t"
12128 /* was the count 0 before? */
12129@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12130 long tmp;
12131 asm volatile("# beginning __up_read\n\t"
12132 LOCK_PREFIX " xadd %1,(%2)\n\t"
12133+
12134+#ifdef CONFIG_PAX_REFCOUNT
12135+ "jno 0f\n"
12136+ "mov %1,(%2)\n"
12137+ "int $4\n0:\n"
12138+ _ASM_EXTABLE(0b, 0b)
12139+#endif
12140+
12141 /* subtracts 1, returns the old value */
12142 " jns 1f\n\t"
12143 " call call_rwsem_wake\n" /* expects old value in %edx */
12144@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12145 long tmp;
12146 asm volatile("# beginning __up_write\n\t"
12147 LOCK_PREFIX " xadd %1,(%2)\n\t"
12148+
12149+#ifdef CONFIG_PAX_REFCOUNT
12150+ "jno 0f\n"
12151+ "mov %1,(%2)\n"
12152+ "int $4\n0:\n"
12153+ _ASM_EXTABLE(0b, 0b)
12154+#endif
12155+
12156 /* subtracts 0xffff0001, returns the old value */
12157 " jns 1f\n\t"
12158 " call call_rwsem_wake\n" /* expects old value in %edx */
12159@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12160 {
12161 asm volatile("# beginning __downgrade_write\n\t"
12162 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12163+
12164+#ifdef CONFIG_PAX_REFCOUNT
12165+ "jno 0f\n"
12166+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12167+ "int $4\n0:\n"
12168+ _ASM_EXTABLE(0b, 0b)
12169+#endif
12170+
12171 /*
12172 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12173 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12174@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12175 */
12176 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12177 {
12178- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12179+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12180+
12181+#ifdef CONFIG_PAX_REFCOUNT
12182+ "jno 0f\n"
12183+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
12184+ "int $4\n0:\n"
12185+ _ASM_EXTABLE(0b, 0b)
12186+#endif
12187+
12188 : "+m" (sem->count)
12189 : "er" (delta));
12190 }
12191@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12192 */
12193 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12194 {
12195- return delta + xadd(&sem->count, delta);
12196+ return delta + xadd_check_overflow(&sem->count, delta);
12197 }
12198
12199 #endif /* __KERNEL__ */
12200diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12201index 1654662..5af4157 100644
12202--- a/arch/x86/include/asm/segment.h
12203+++ b/arch/x86/include/asm/segment.h
12204@@ -64,10 +64,15 @@
12205 * 26 - ESPFIX small SS
12206 * 27 - per-cpu [ offset to per-cpu data area ]
12207 * 28 - stack_canary-20 [ for stack protector ]
12208- * 29 - unused
12209- * 30 - unused
12210+ * 29 - PCI BIOS CS
12211+ * 30 - PCI BIOS DS
12212 * 31 - TSS for double fault handler
12213 */
12214+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12215+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12216+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12217+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12218+
12219 #define GDT_ENTRY_TLS_MIN 6
12220 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12221
12222@@ -79,6 +84,8 @@
12223
12224 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12225
12226+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12227+
12228 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12229
12230 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12231@@ -104,6 +111,12 @@
12232 #define __KERNEL_STACK_CANARY 0
12233 #endif
12234
12235+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12236+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12237+
12238+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12239+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12240+
12241 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12242
12243 /*
12244@@ -141,7 +154,7 @@
12245 */
12246
12247 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12248-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12249+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12250
12251
12252 #else
12253@@ -165,6 +178,8 @@
12254 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12255 #define __USER32_DS __USER_DS
12256
12257+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12258+
12259 #define GDT_ENTRY_TSS 8 /* needs two entries */
12260 #define GDT_ENTRY_LDT 10 /* needs two entries */
12261 #define GDT_ENTRY_TLS_MIN 12
12262@@ -185,6 +200,7 @@
12263 #endif
12264
12265 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12266+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12267 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12268 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12269 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12270@@ -263,7 +279,7 @@ static inline unsigned long get_limit(unsigned long segment)
12271 {
12272 unsigned long __limit;
12273 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12274- return __limit + 1;
12275+ return __limit;
12276 }
12277
12278 #endif /* !__ASSEMBLY__ */
12279diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12280index 0434c40..1714bf0 100644
12281--- a/arch/x86/include/asm/smp.h
12282+++ b/arch/x86/include/asm/smp.h
12283@@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12284 /* cpus sharing the last level cache: */
12285 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12286 DECLARE_PER_CPU(u16, cpu_llc_id);
12287-DECLARE_PER_CPU(int, cpu_number);
12288+DECLARE_PER_CPU(unsigned int, cpu_number);
12289
12290 static inline struct cpumask *cpu_sibling_mask(int cpu)
12291 {
12292@@ -77,7 +77,7 @@ struct smp_ops {
12293
12294 void (*send_call_func_ipi)(const struct cpumask *mask);
12295 void (*send_call_func_single_ipi)(int cpu);
12296-};
12297+} __no_const;
12298
12299 /* Globals due to paravirt */
12300 extern void set_cpu_sibling_map(int cpu);
12301@@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12302 extern int safe_smp_processor_id(void);
12303
12304 #elif defined(CONFIG_X86_64_SMP)
12305-#define raw_smp_processor_id() (percpu_read(cpu_number))
12306-
12307-#define stack_smp_processor_id() \
12308-({ \
12309- struct thread_info *ti; \
12310- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12311- ti->cpu; \
12312-})
12313+#define raw_smp_processor_id() (percpu_read(cpu_number))
12314+#define stack_smp_processor_id() raw_smp_processor_id()
12315 #define safe_smp_processor_id() smp_processor_id()
12316
12317 #endif
12318diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12319index 76bfa2c..12d3fe7 100644
12320--- a/arch/x86/include/asm/spinlock.h
12321+++ b/arch/x86/include/asm/spinlock.h
12322@@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12323 static inline void arch_read_lock(arch_rwlock_t *rw)
12324 {
12325 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12326+
12327+#ifdef CONFIG_PAX_REFCOUNT
12328+ "jno 0f\n"
12329+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12330+ "int $4\n0:\n"
12331+ _ASM_EXTABLE(0b, 0b)
12332+#endif
12333+
12334 "jns 1f\n"
12335 "call __read_lock_failed\n\t"
12336 "1:\n"
12337@@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12338 static inline void arch_write_lock(arch_rwlock_t *rw)
12339 {
12340 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12341+
12342+#ifdef CONFIG_PAX_REFCOUNT
12343+ "jno 0f\n"
12344+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12345+ "int $4\n0:\n"
12346+ _ASM_EXTABLE(0b, 0b)
12347+#endif
12348+
12349 "jz 1f\n"
12350 "call __write_lock_failed\n\t"
12351 "1:\n"
12352@@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12353
12354 static inline void arch_read_unlock(arch_rwlock_t *rw)
12355 {
12356- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12357+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12358+
12359+#ifdef CONFIG_PAX_REFCOUNT
12360+ "jno 0f\n"
12361+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12362+ "int $4\n0:\n"
12363+ _ASM_EXTABLE(0b, 0b)
12364+#endif
12365+
12366 :"+m" (rw->lock) : : "memory");
12367 }
12368
12369 static inline void arch_write_unlock(arch_rwlock_t *rw)
12370 {
12371- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12372+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12373+
12374+#ifdef CONFIG_PAX_REFCOUNT
12375+ "jno 0f\n"
12376+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12377+ "int $4\n0:\n"
12378+ _ASM_EXTABLE(0b, 0b)
12379+#endif
12380+
12381 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12382 }
12383
12384diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12385index b5d9533..41655fa 100644
12386--- a/arch/x86/include/asm/stackprotector.h
12387+++ b/arch/x86/include/asm/stackprotector.h
12388@@ -47,7 +47,7 @@
12389 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12390 */
12391 #define GDT_STACK_CANARY_INIT \
12392- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12393+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12394
12395 /*
12396 * Initialize the stackprotector canary value.
12397@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12398
12399 static inline void load_stack_canary_segment(void)
12400 {
12401-#ifdef CONFIG_X86_32
12402+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12403 asm volatile ("mov %0, %%gs" : : "r" (0));
12404 #endif
12405 }
12406diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12407index 70bbe39..4ae2bd4 100644
12408--- a/arch/x86/include/asm/stacktrace.h
12409+++ b/arch/x86/include/asm/stacktrace.h
12410@@ -11,28 +11,20 @@
12411
12412 extern int kstack_depth_to_print;
12413
12414-struct thread_info;
12415+struct task_struct;
12416 struct stacktrace_ops;
12417
12418-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12419- unsigned long *stack,
12420- unsigned long bp,
12421- const struct stacktrace_ops *ops,
12422- void *data,
12423- unsigned long *end,
12424- int *graph);
12425+typedef unsigned long walk_stack_t(struct task_struct *task,
12426+ void *stack_start,
12427+ unsigned long *stack,
12428+ unsigned long bp,
12429+ const struct stacktrace_ops *ops,
12430+ void *data,
12431+ unsigned long *end,
12432+ int *graph);
12433
12434-extern unsigned long
12435-print_context_stack(struct thread_info *tinfo,
12436- unsigned long *stack, unsigned long bp,
12437- const struct stacktrace_ops *ops, void *data,
12438- unsigned long *end, int *graph);
12439-
12440-extern unsigned long
12441-print_context_stack_bp(struct thread_info *tinfo,
12442- unsigned long *stack, unsigned long bp,
12443- const struct stacktrace_ops *ops, void *data,
12444- unsigned long *end, int *graph);
12445+extern walk_stack_t print_context_stack;
12446+extern walk_stack_t print_context_stack_bp;
12447
12448 /* Generic stack tracer with callbacks */
12449
12450@@ -40,7 +32,7 @@ struct stacktrace_ops {
12451 void (*address)(void *data, unsigned long address, int reliable);
12452 /* On negative return stop dumping */
12453 int (*stack)(void *data, char *name);
12454- walk_stack_t walk_stack;
12455+ walk_stack_t *walk_stack;
12456 };
12457
12458 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12459diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12460index 4ec45b3..a4f0a8a 100644
12461--- a/arch/x86/include/asm/switch_to.h
12462+++ b/arch/x86/include/asm/switch_to.h
12463@@ -108,7 +108,7 @@ do { \
12464 "call __switch_to\n\t" \
12465 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12466 __switch_canary \
12467- "movq %P[thread_info](%%rsi),%%r8\n\t" \
12468+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12469 "movq %%rax,%%rdi\n\t" \
12470 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12471 "jnz ret_from_fork\n\t" \
12472@@ -119,7 +119,7 @@ do { \
12473 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12474 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12475 [_tif_fork] "i" (_TIF_FORK), \
12476- [thread_info] "i" (offsetof(struct task_struct, stack)), \
12477+ [thread_info] "m" (current_tinfo), \
12478 [current_task] "m" (current_task) \
12479 __switch_canary_iparam \
12480 : "memory", "cc" __EXTRA_CLOBBER)
12481diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12482index 3fda9db4..4ca1c61 100644
12483--- a/arch/x86/include/asm/sys_ia32.h
12484+++ b/arch/x86/include/asm/sys_ia32.h
12485@@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12486 struct old_sigaction32 __user *);
12487 asmlinkage long sys32_alarm(unsigned int);
12488
12489-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12490+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12491 asmlinkage long sys32_sysfs(int, u32, u32);
12492
12493 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12494diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12495index ad6df8c..5e0cf6e 100644
12496--- a/arch/x86/include/asm/thread_info.h
12497+++ b/arch/x86/include/asm/thread_info.h
12498@@ -10,6 +10,7 @@
12499 #include <linux/compiler.h>
12500 #include <asm/page.h>
12501 #include <asm/types.h>
12502+#include <asm/percpu.h>
12503
12504 /*
12505 * low level task data that entry.S needs immediate access to
12506@@ -24,7 +25,6 @@ struct exec_domain;
12507 #include <linux/atomic.h>
12508
12509 struct thread_info {
12510- struct task_struct *task; /* main task structure */
12511 struct exec_domain *exec_domain; /* execution domain */
12512 __u32 flags; /* low level flags */
12513 __u32 status; /* thread synchronous flags */
12514@@ -34,19 +34,13 @@ struct thread_info {
12515 mm_segment_t addr_limit;
12516 struct restart_block restart_block;
12517 void __user *sysenter_return;
12518-#ifdef CONFIG_X86_32
12519- unsigned long previous_esp; /* ESP of the previous stack in
12520- case of nested (IRQ) stacks
12521- */
12522- __u8 supervisor_stack[0];
12523-#endif
12524+ unsigned long lowest_stack;
12525 unsigned int sig_on_uaccess_error:1;
12526 unsigned int uaccess_err:1; /* uaccess failed */
12527 };
12528
12529-#define INIT_THREAD_INFO(tsk) \
12530+#define INIT_THREAD_INFO \
12531 { \
12532- .task = &tsk, \
12533 .exec_domain = &default_exec_domain, \
12534 .flags = 0, \
12535 .cpu = 0, \
12536@@ -57,7 +51,7 @@ struct thread_info {
12537 }, \
12538 }
12539
12540-#define init_thread_info (init_thread_union.thread_info)
12541+#define init_thread_info (init_thread_union.stack)
12542 #define init_stack (init_thread_union.stack)
12543
12544 #else /* !__ASSEMBLY__ */
12545@@ -97,6 +91,7 @@ struct thread_info {
12546 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12547 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12548 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12549+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12550
12551 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12552 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12553@@ -120,16 +115,18 @@ struct thread_info {
12554 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12555 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12556 #define _TIF_X32 (1 << TIF_X32)
12557+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12558
12559 /* work to do in syscall_trace_enter() */
12560 #define _TIF_WORK_SYSCALL_ENTRY \
12561 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12562- _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12563+ _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12564+ _TIF_GRSEC_SETXID)
12565
12566 /* work to do in syscall_trace_leave() */
12567 #define _TIF_WORK_SYSCALL_EXIT \
12568 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12569- _TIF_SYSCALL_TRACEPOINT)
12570+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12571
12572 /* work to do on interrupt/exception return */
12573 #define _TIF_WORK_MASK \
12574@@ -139,7 +136,8 @@ struct thread_info {
12575
12576 /* work to do on any return to user space */
12577 #define _TIF_ALLWORK_MASK \
12578- ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12579+ ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12580+ _TIF_GRSEC_SETXID)
12581
12582 /* Only used for 64 bit */
12583 #define _TIF_DO_NOTIFY_MASK \
12584@@ -173,45 +171,40 @@ struct thread_info {
12585 ret; \
12586 })
12587
12588-#ifdef CONFIG_X86_32
12589-
12590-#define STACK_WARN (THREAD_SIZE/8)
12591-/*
12592- * macros/functions for gaining access to the thread information structure
12593- *
12594- * preempt_count needs to be 1 initially, until the scheduler is functional.
12595- */
12596-#ifndef __ASSEMBLY__
12597-
12598-
12599-/* how to get the current stack pointer from C */
12600-register unsigned long current_stack_pointer asm("esp") __used;
12601-
12602-/* how to get the thread information struct from C */
12603-static inline struct thread_info *current_thread_info(void)
12604-{
12605- return (struct thread_info *)
12606- (current_stack_pointer & ~(THREAD_SIZE - 1));
12607-}
12608-
12609-#else /* !__ASSEMBLY__ */
12610-
12611+#ifdef __ASSEMBLY__
12612 /* how to get the thread information struct from ASM */
12613 #define GET_THREAD_INFO(reg) \
12614- movl $-THREAD_SIZE, reg; \
12615- andl %esp, reg
12616+ mov PER_CPU_VAR(current_tinfo), reg
12617
12618 /* use this one if reg already contains %esp */
12619-#define GET_THREAD_INFO_WITH_ESP(reg) \
12620- andl $-THREAD_SIZE, reg
12621+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12622+#else
12623+/* how to get the thread information struct from C */
12624+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12625+
12626+static __always_inline struct thread_info *current_thread_info(void)
12627+{
12628+ return percpu_read_stable(current_tinfo);
12629+}
12630+#endif
12631+
12632+#ifdef CONFIG_X86_32
12633+
12634+#define STACK_WARN (THREAD_SIZE/8)
12635+/*
12636+ * macros/functions for gaining access to the thread information structure
12637+ *
12638+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12639+ */
12640+#ifndef __ASSEMBLY__
12641+
12642+/* how to get the current stack pointer from C */
12643+register unsigned long current_stack_pointer asm("esp") __used;
12644
12645 #endif
12646
12647 #else /* X86_32 */
12648
12649-#include <asm/percpu.h>
12650-#define KERNEL_STACK_OFFSET (5*8)
12651-
12652 /*
12653 * macros/functions for gaining access to the thread information structure
12654 * preempt_count needs to be 1 initially, until the scheduler is functional.
12655@@ -219,27 +212,8 @@ static inline struct thread_info *current_thread_info(void)
12656 #ifndef __ASSEMBLY__
12657 DECLARE_PER_CPU(unsigned long, kernel_stack);
12658
12659-static inline struct thread_info *current_thread_info(void)
12660-{
12661- struct thread_info *ti;
12662- ti = (void *)(percpu_read_stable(kernel_stack) +
12663- KERNEL_STACK_OFFSET - THREAD_SIZE);
12664- return ti;
12665-}
12666-
12667-#else /* !__ASSEMBLY__ */
12668-
12669-/* how to get the thread information struct from ASM */
12670-#define GET_THREAD_INFO(reg) \
12671- movq PER_CPU_VAR(kernel_stack),reg ; \
12672- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12673-
12674-/*
12675- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12676- * a certain register (to be used in assembler memory operands).
12677- */
12678-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12679-
12680+/* how to get the current stack pointer from C */
12681+register unsigned long current_stack_pointer asm("rsp") __used;
12682 #endif
12683
12684 #endif /* !X86_32 */
12685@@ -285,5 +259,16 @@ extern void arch_task_cache_init(void);
12686 extern void free_thread_info(struct thread_info *ti);
12687 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12688 #define arch_task_cache_init arch_task_cache_init
12689+
12690+#define __HAVE_THREAD_FUNCTIONS
12691+#define task_thread_info(task) (&(task)->tinfo)
12692+#define task_stack_page(task) ((task)->stack)
12693+#define setup_thread_stack(p, org) do {} while (0)
12694+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12695+
12696+#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12697+extern struct task_struct *alloc_task_struct_node(int node);
12698+extern void free_task_struct(struct task_struct *);
12699+
12700 #endif
12701 #endif /* _ASM_X86_THREAD_INFO_H */
12702diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12703index e054459..14bc8a7 100644
12704--- a/arch/x86/include/asm/uaccess.h
12705+++ b/arch/x86/include/asm/uaccess.h
12706@@ -7,12 +7,15 @@
12707 #include <linux/compiler.h>
12708 #include <linux/thread_info.h>
12709 #include <linux/string.h>
12710+#include <linux/sched.h>
12711 #include <asm/asm.h>
12712 #include <asm/page.h>
12713
12714 #define VERIFY_READ 0
12715 #define VERIFY_WRITE 1
12716
12717+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12718+
12719 /*
12720 * The fs value determines whether argument validity checking should be
12721 * performed or not. If get_fs() == USER_DS, checking is performed, with
12722@@ -28,7 +31,12 @@
12723
12724 #define get_ds() (KERNEL_DS)
12725 #define get_fs() (current_thread_info()->addr_limit)
12726+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12727+void __set_fs(mm_segment_t x);
12728+void set_fs(mm_segment_t x);
12729+#else
12730 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12731+#endif
12732
12733 #define segment_eq(a, b) ((a).seg == (b).seg)
12734
12735@@ -76,7 +84,33 @@
12736 * checks that the pointer is in the user space range - after calling
12737 * this function, memory access functions may still return -EFAULT.
12738 */
12739-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12740+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12741+#define access_ok(type, addr, size) \
12742+({ \
12743+ long __size = size; \
12744+ unsigned long __addr = (unsigned long)addr; \
12745+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12746+ unsigned long __end_ao = __addr + __size - 1; \
12747+ bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12748+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12749+ while(__addr_ao <= __end_ao) { \
12750+ char __c_ao; \
12751+ __addr_ao += PAGE_SIZE; \
12752+ if (__size > PAGE_SIZE) \
12753+ cond_resched(); \
12754+ if (__get_user(__c_ao, (char __user *)__addr)) \
12755+ break; \
12756+ if (type != VERIFY_WRITE) { \
12757+ __addr = __addr_ao; \
12758+ continue; \
12759+ } \
12760+ if (__put_user(__c_ao, (char __user *)__addr)) \
12761+ break; \
12762+ __addr = __addr_ao; \
12763+ } \
12764+ } \
12765+ __ret_ao; \
12766+})
12767
12768 /*
12769 * The exception table consists of pairs of addresses: the first is the
12770@@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12771 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12772 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12773
12774-
12775+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12776+#define __copyuser_seg "gs;"
12777+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12778+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12779+#else
12780+#define __copyuser_seg
12781+#define __COPYUSER_SET_ES
12782+#define __COPYUSER_RESTORE_ES
12783+#endif
12784
12785 #ifdef CONFIG_X86_32
12786 #define __put_user_asm_u64(x, addr, err, errret) \
12787- asm volatile("1: movl %%eax,0(%2)\n" \
12788- "2: movl %%edx,4(%2)\n" \
12789+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12790+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12791 "3:\n" \
12792 ".section .fixup,\"ax\"\n" \
12793 "4: movl %3,%0\n" \
12794@@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12795 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12796
12797 #define __put_user_asm_ex_u64(x, addr) \
12798- asm volatile("1: movl %%eax,0(%1)\n" \
12799- "2: movl %%edx,4(%1)\n" \
12800+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12801+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12802 "3:\n" \
12803 _ASM_EXTABLE(1b, 2b - 1b) \
12804 _ASM_EXTABLE(2b, 3b - 2b) \
12805@@ -252,7 +294,7 @@ extern void __put_user_8(void);
12806 __typeof__(*(ptr)) __pu_val; \
12807 __chk_user_ptr(ptr); \
12808 might_fault(); \
12809- __pu_val = x; \
12810+ __pu_val = (x); \
12811 switch (sizeof(*(ptr))) { \
12812 case 1: \
12813 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12814@@ -373,7 +415,7 @@ do { \
12815 } while (0)
12816
12817 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12818- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12819+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12820 "2:\n" \
12821 ".section .fixup,\"ax\"\n" \
12822 "3: mov %3,%0\n" \
12823@@ -381,7 +423,7 @@ do { \
12824 " jmp 2b\n" \
12825 ".previous\n" \
12826 _ASM_EXTABLE(1b, 3b) \
12827- : "=r" (err), ltype(x) \
12828+ : "=r" (err), ltype (x) \
12829 : "m" (__m(addr)), "i" (errret), "0" (err))
12830
12831 #define __get_user_size_ex(x, ptr, size) \
12832@@ -406,7 +448,7 @@ do { \
12833 } while (0)
12834
12835 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12836- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12837+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12838 "2:\n" \
12839 _ASM_EXTABLE(1b, 2b - 1b) \
12840 : ltype(x) : "m" (__m(addr)))
12841@@ -423,13 +465,24 @@ do { \
12842 int __gu_err; \
12843 unsigned long __gu_val; \
12844 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12845- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12846+ (x) = (__typeof__(*(ptr)))__gu_val; \
12847 __gu_err; \
12848 })
12849
12850 /* FIXME: this hack is definitely wrong -AK */
12851 struct __large_struct { unsigned long buf[100]; };
12852-#define __m(x) (*(struct __large_struct __user *)(x))
12853+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12854+#define ____m(x) \
12855+({ \
12856+ unsigned long ____x = (unsigned long)(x); \
12857+ if (____x < PAX_USER_SHADOW_BASE) \
12858+ ____x += PAX_USER_SHADOW_BASE; \
12859+ (void __user *)____x; \
12860+})
12861+#else
12862+#define ____m(x) (x)
12863+#endif
12864+#define __m(x) (*(struct __large_struct __user *)____m(x))
12865
12866 /*
12867 * Tell gcc we read from memory instead of writing: this is because
12868@@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12869 * aliasing issues.
12870 */
12871 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12872- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12873+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12874 "2:\n" \
12875 ".section .fixup,\"ax\"\n" \
12876 "3: mov %3,%0\n" \
12877@@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12878 ".previous\n" \
12879 _ASM_EXTABLE(1b, 3b) \
12880 : "=r"(err) \
12881- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12882+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12883
12884 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12885- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12886+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12887 "2:\n" \
12888 _ASM_EXTABLE(1b, 2b - 1b) \
12889 : : ltype(x), "m" (__m(addr)))
12890@@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12891 * On error, the variable @x is set to zero.
12892 */
12893
12894+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12895+#define __get_user(x, ptr) get_user((x), (ptr))
12896+#else
12897 #define __get_user(x, ptr) \
12898 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12899+#endif
12900
12901 /**
12902 * __put_user: - Write a simple value into user space, with less checking.
12903@@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12904 * Returns zero on success, or -EFAULT on error.
12905 */
12906
12907+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12908+#define __put_user(x, ptr) put_user((x), (ptr))
12909+#else
12910 #define __put_user(x, ptr) \
12911 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12912+#endif
12913
12914 #define __get_user_unaligned __get_user
12915 #define __put_user_unaligned __put_user
12916@@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12917 #define get_user_ex(x, ptr) do { \
12918 unsigned long __gue_val; \
12919 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12920- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12921+ (x) = (__typeof__(*(ptr)))__gue_val; \
12922 } while (0)
12923
12924 #ifdef CONFIG_X86_WP_WORKS_OK
12925diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12926index 8084bc7..3d6ec37 100644
12927--- a/arch/x86/include/asm/uaccess_32.h
12928+++ b/arch/x86/include/asm/uaccess_32.h
12929@@ -11,15 +11,15 @@
12930 #include <asm/page.h>
12931
12932 unsigned long __must_check __copy_to_user_ll
12933- (void __user *to, const void *from, unsigned long n);
12934+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12935 unsigned long __must_check __copy_from_user_ll
12936- (void *to, const void __user *from, unsigned long n);
12937+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12938 unsigned long __must_check __copy_from_user_ll_nozero
12939- (void *to, const void __user *from, unsigned long n);
12940+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12941 unsigned long __must_check __copy_from_user_ll_nocache
12942- (void *to, const void __user *from, unsigned long n);
12943+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12944 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12945- (void *to, const void __user *from, unsigned long n);
12946+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12947
12948 /**
12949 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12950@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12951 static __always_inline unsigned long __must_check
12952 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12953 {
12954+ if ((long)n < 0)
12955+ return n;
12956+
12957 if (__builtin_constant_p(n)) {
12958 unsigned long ret;
12959
12960@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12961 return ret;
12962 }
12963 }
12964+ if (!__builtin_constant_p(n))
12965+ check_object_size(from, n, true);
12966 return __copy_to_user_ll(to, from, n);
12967 }
12968
12969@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12970 __copy_to_user(void __user *to, const void *from, unsigned long n)
12971 {
12972 might_fault();
12973+
12974 return __copy_to_user_inatomic(to, from, n);
12975 }
12976
12977 static __always_inline unsigned long
12978 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12979 {
12980+ if ((long)n < 0)
12981+ return n;
12982+
12983 /* Avoid zeroing the tail if the copy fails..
12984 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12985 * but as the zeroing behaviour is only significant when n is not
12986@@ -137,6 +146,10 @@ static __always_inline unsigned long
12987 __copy_from_user(void *to, const void __user *from, unsigned long n)
12988 {
12989 might_fault();
12990+
12991+ if ((long)n < 0)
12992+ return n;
12993+
12994 if (__builtin_constant_p(n)) {
12995 unsigned long ret;
12996
12997@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12998 return ret;
12999 }
13000 }
13001+ if (!__builtin_constant_p(n))
13002+ check_object_size(to, n, false);
13003 return __copy_from_user_ll(to, from, n);
13004 }
13005
13006@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
13007 const void __user *from, unsigned long n)
13008 {
13009 might_fault();
13010+
13011+ if ((long)n < 0)
13012+ return n;
13013+
13014 if (__builtin_constant_p(n)) {
13015 unsigned long ret;
13016
13017@@ -181,15 +200,19 @@ static __always_inline unsigned long
13018 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13019 unsigned long n)
13020 {
13021- return __copy_from_user_ll_nocache_nozero(to, from, n);
13022+ if ((long)n < 0)
13023+ return n;
13024+
13025+ return __copy_from_user_ll_nocache_nozero(to, from, n);
13026 }
13027
13028-unsigned long __must_check copy_to_user(void __user *to,
13029- const void *from, unsigned long n);
13030-unsigned long __must_check _copy_from_user(void *to,
13031- const void __user *from,
13032- unsigned long n);
13033-
13034+extern void copy_to_user_overflow(void)
13035+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13036+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13037+#else
13038+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13039+#endif
13040+;
13041
13042 extern void copy_from_user_overflow(void)
13043 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13044@@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
13045 #endif
13046 ;
13047
13048-static inline unsigned long __must_check copy_from_user(void *to,
13049- const void __user *from,
13050- unsigned long n)
13051+/**
13052+ * copy_to_user: - Copy a block of data into user space.
13053+ * @to: Destination address, in user space.
13054+ * @from: Source address, in kernel space.
13055+ * @n: Number of bytes to copy.
13056+ *
13057+ * Context: User context only. This function may sleep.
13058+ *
13059+ * Copy data from kernel space to user space.
13060+ *
13061+ * Returns number of bytes that could not be copied.
13062+ * On success, this will be zero.
13063+ */
13064+static inline unsigned long __must_check
13065+copy_to_user(void __user *to, const void *from, unsigned long n)
13066 {
13067- int sz = __compiletime_object_size(to);
13068+ size_t sz = __compiletime_object_size(from);
13069
13070- if (likely(sz == -1 || sz >= n))
13071- n = _copy_from_user(to, from, n);
13072- else
13073+ if (unlikely(sz != (size_t)-1 && sz < n))
13074+ copy_to_user_overflow();
13075+ else if (access_ok(VERIFY_WRITE, to, n))
13076+ n = __copy_to_user(to, from, n);
13077+ return n;
13078+}
13079+
13080+/**
13081+ * copy_from_user: - Copy a block of data from user space.
13082+ * @to: Destination address, in kernel space.
13083+ * @from: Source address, in user space.
13084+ * @n: Number of bytes to copy.
13085+ *
13086+ * Context: User context only. This function may sleep.
13087+ *
13088+ * Copy data from user space to kernel space.
13089+ *
13090+ * Returns number of bytes that could not be copied.
13091+ * On success, this will be zero.
13092+ *
13093+ * If some data could not be copied, this function will pad the copied
13094+ * data to the requested size using zero bytes.
13095+ */
13096+static inline unsigned long __must_check
13097+copy_from_user(void *to, const void __user *from, unsigned long n)
13098+{
13099+ size_t sz = __compiletime_object_size(to);
13100+
13101+ if (unlikely(sz != (size_t)-1 && sz < n))
13102 copy_from_user_overflow();
13103-
13104+ else if (access_ok(VERIFY_READ, from, n))
13105+ n = __copy_from_user(to, from, n);
13106+ else if ((long)n > 0) {
13107+ if (!__builtin_constant_p(n))
13108+ check_object_size(to, n, false);
13109+ memset(to, 0, n);
13110+ }
13111 return n;
13112 }
13113
13114@@ -230,7 +297,7 @@ static inline unsigned long __must_check copy_from_user(void *to,
13115 #define strlen_user(str) strnlen_user(str, LONG_MAX)
13116
13117 long strnlen_user(const char __user *str, long n);
13118-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13119-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13120+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13121+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13122
13123 #endif /* _ASM_X86_UACCESS_32_H */
13124diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13125index fcd4b6f..ef04f8f 100644
13126--- a/arch/x86/include/asm/uaccess_64.h
13127+++ b/arch/x86/include/asm/uaccess_64.h
13128@@ -10,6 +10,9 @@
13129 #include <asm/alternative.h>
13130 #include <asm/cpufeature.h>
13131 #include <asm/page.h>
13132+#include <asm/pgtable.h>
13133+
13134+#define set_fs(x) (current_thread_info()->addr_limit = (x))
13135
13136 /*
13137 * Copy To/From Userspace
13138@@ -17,12 +20,14 @@
13139
13140 /* Handles exceptions in both to and from, but doesn't do access_ok */
13141 __must_check unsigned long
13142-copy_user_generic_string(void *to, const void *from, unsigned len);
13143+copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13144 __must_check unsigned long
13145-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13146+copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13147
13148 static __always_inline __must_check unsigned long
13149-copy_user_generic(void *to, const void *from, unsigned len)
13150+copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13151+static __always_inline __must_check unsigned long
13152+copy_user_generic(void *to, const void *from, unsigned long len)
13153 {
13154 unsigned ret;
13155
13156@@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13157 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13158 "=d" (len)),
13159 "1" (to), "2" (from), "3" (len)
13160- : "memory", "rcx", "r8", "r9", "r10", "r11");
13161+ : "memory", "rcx", "r8", "r9", "r11");
13162 return ret;
13163 }
13164
13165+static __always_inline __must_check unsigned long
13166+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13167+static __always_inline __must_check unsigned long
13168+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13169 __must_check unsigned long
13170-_copy_to_user(void __user *to, const void *from, unsigned len);
13171-__must_check unsigned long
13172-_copy_from_user(void *to, const void __user *from, unsigned len);
13173-__must_check unsigned long
13174-copy_in_user(void __user *to, const void __user *from, unsigned len);
13175+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13176+
13177+extern void copy_to_user_overflow(void)
13178+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13179+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13180+#else
13181+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13182+#endif
13183+;
13184+
13185+extern void copy_from_user_overflow(void)
13186+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13187+ __compiletime_error("copy_from_user() buffer size is not provably correct")
13188+#else
13189+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
13190+#endif
13191+;
13192
13193 static inline unsigned long __must_check copy_from_user(void *to,
13194 const void __user *from,
13195 unsigned long n)
13196 {
13197- int sz = __compiletime_object_size(to);
13198-
13199 might_fault();
13200- if (likely(sz == -1 || sz >= n))
13201- n = _copy_from_user(to, from, n);
13202-#ifdef CONFIG_DEBUG_VM
13203- else
13204- WARN(1, "Buffer overflow detected!\n");
13205-#endif
13206+
13207+ if (access_ok(VERIFY_READ, from, n))
13208+ n = __copy_from_user(to, from, n);
13209+ else if (n < INT_MAX) {
13210+ if (!__builtin_constant_p(n))
13211+ check_object_size(to, n, false);
13212+ memset(to, 0, n);
13213+ }
13214 return n;
13215 }
13216
13217 static __always_inline __must_check
13218-int copy_to_user(void __user *dst, const void *src, unsigned size)
13219+int copy_to_user(void __user *dst, const void *src, unsigned long size)
13220 {
13221 might_fault();
13222
13223- return _copy_to_user(dst, src, size);
13224+ if (access_ok(VERIFY_WRITE, dst, size))
13225+ size = __copy_to_user(dst, src, size);
13226+ return size;
13227 }
13228
13229 static __always_inline __must_check
13230-int __copy_from_user(void *dst, const void __user *src, unsigned size)
13231+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13232 {
13233- int ret = 0;
13234+ size_t sz = __compiletime_object_size(dst);
13235+ unsigned ret = 0;
13236
13237 might_fault();
13238- if (!__builtin_constant_p(size))
13239- return copy_user_generic(dst, (__force void *)src, size);
13240+
13241+ if (size > INT_MAX)
13242+ return size;
13243+
13244+#ifdef CONFIG_PAX_MEMORY_UDEREF
13245+ if (!__access_ok(VERIFY_READ, src, size))
13246+ return size;
13247+#endif
13248+
13249+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13250+ copy_from_user_overflow();
13251+ return size;
13252+ }
13253+
13254+ if (!__builtin_constant_p(size)) {
13255+ check_object_size(dst, size, false);
13256+
13257+#ifdef CONFIG_PAX_MEMORY_UDEREF
13258+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13259+ src += PAX_USER_SHADOW_BASE;
13260+#endif
13261+
13262+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13263+ }
13264 switch (size) {
13265- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13266+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13267 ret, "b", "b", "=q", 1);
13268 return ret;
13269- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13270+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13271 ret, "w", "w", "=r", 2);
13272 return ret;
13273- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13274+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13275 ret, "l", "k", "=r", 4);
13276 return ret;
13277- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13278+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13279 ret, "q", "", "=r", 8);
13280 return ret;
13281 case 10:
13282- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13283+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13284 ret, "q", "", "=r", 10);
13285 if (unlikely(ret))
13286 return ret;
13287 __get_user_asm(*(u16 *)(8 + (char *)dst),
13288- (u16 __user *)(8 + (char __user *)src),
13289+ (const u16 __user *)(8 + (const char __user *)src),
13290 ret, "w", "w", "=r", 2);
13291 return ret;
13292 case 16:
13293- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13294+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13295 ret, "q", "", "=r", 16);
13296 if (unlikely(ret))
13297 return ret;
13298 __get_user_asm(*(u64 *)(8 + (char *)dst),
13299- (u64 __user *)(8 + (char __user *)src),
13300+ (const u64 __user *)(8 + (const char __user *)src),
13301 ret, "q", "", "=r", 8);
13302 return ret;
13303 default:
13304- return copy_user_generic(dst, (__force void *)src, size);
13305+
13306+#ifdef CONFIG_PAX_MEMORY_UDEREF
13307+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13308+ src += PAX_USER_SHADOW_BASE;
13309+#endif
13310+
13311+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13312 }
13313 }
13314
13315 static __always_inline __must_check
13316-int __copy_to_user(void __user *dst, const void *src, unsigned size)
13317+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13318 {
13319- int ret = 0;
13320+ size_t sz = __compiletime_object_size(src);
13321+ unsigned ret = 0;
13322
13323 might_fault();
13324- if (!__builtin_constant_p(size))
13325- return copy_user_generic((__force void *)dst, src, size);
13326+
13327+ if (size > INT_MAX)
13328+ return size;
13329+
13330+#ifdef CONFIG_PAX_MEMORY_UDEREF
13331+ if (!__access_ok(VERIFY_WRITE, dst, size))
13332+ return size;
13333+#endif
13334+
13335+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13336+ copy_to_user_overflow();
13337+ return size;
13338+ }
13339+
13340+ if (!__builtin_constant_p(size)) {
13341+ check_object_size(src, size, true);
13342+
13343+#ifdef CONFIG_PAX_MEMORY_UDEREF
13344+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13345+ dst += PAX_USER_SHADOW_BASE;
13346+#endif
13347+
13348+ return copy_user_generic((__force_kernel void *)dst, src, size);
13349+ }
13350 switch (size) {
13351- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13352+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13353 ret, "b", "b", "iq", 1);
13354 return ret;
13355- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13356+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13357 ret, "w", "w", "ir", 2);
13358 return ret;
13359- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13360+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13361 ret, "l", "k", "ir", 4);
13362 return ret;
13363- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13364+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13365 ret, "q", "", "er", 8);
13366 return ret;
13367 case 10:
13368- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13369+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13370 ret, "q", "", "er", 10);
13371 if (unlikely(ret))
13372 return ret;
13373 asm("":::"memory");
13374- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13375+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13376 ret, "w", "w", "ir", 2);
13377 return ret;
13378 case 16:
13379- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13380+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13381 ret, "q", "", "er", 16);
13382 if (unlikely(ret))
13383 return ret;
13384 asm("":::"memory");
13385- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13386+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13387 ret, "q", "", "er", 8);
13388 return ret;
13389 default:
13390- return copy_user_generic((__force void *)dst, src, size);
13391+
13392+#ifdef CONFIG_PAX_MEMORY_UDEREF
13393+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13394+ dst += PAX_USER_SHADOW_BASE;
13395+#endif
13396+
13397+ return copy_user_generic((__force_kernel void *)dst, src, size);
13398 }
13399 }
13400
13401 static __always_inline __must_check
13402-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13403+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13404 {
13405- int ret = 0;
13406+ unsigned ret = 0;
13407
13408 might_fault();
13409- if (!__builtin_constant_p(size))
13410- return copy_user_generic((__force void *)dst,
13411- (__force void *)src, size);
13412+
13413+ if (size > INT_MAX)
13414+ return size;
13415+
13416+#ifdef CONFIG_PAX_MEMORY_UDEREF
13417+ if (!__access_ok(VERIFY_READ, src, size))
13418+ return size;
13419+ if (!__access_ok(VERIFY_WRITE, dst, size))
13420+ return size;
13421+#endif
13422+
13423+ if (!__builtin_constant_p(size)) {
13424+
13425+#ifdef CONFIG_PAX_MEMORY_UDEREF
13426+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13427+ src += PAX_USER_SHADOW_BASE;
13428+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13429+ dst += PAX_USER_SHADOW_BASE;
13430+#endif
13431+
13432+ return copy_user_generic((__force_kernel void *)dst,
13433+ (__force_kernel const void *)src, size);
13434+ }
13435 switch (size) {
13436 case 1: {
13437 u8 tmp;
13438- __get_user_asm(tmp, (u8 __user *)src,
13439+ __get_user_asm(tmp, (const u8 __user *)src,
13440 ret, "b", "b", "=q", 1);
13441 if (likely(!ret))
13442 __put_user_asm(tmp, (u8 __user *)dst,
13443@@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13444 }
13445 case 2: {
13446 u16 tmp;
13447- __get_user_asm(tmp, (u16 __user *)src,
13448+ __get_user_asm(tmp, (const u16 __user *)src,
13449 ret, "w", "w", "=r", 2);
13450 if (likely(!ret))
13451 __put_user_asm(tmp, (u16 __user *)dst,
13452@@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13453
13454 case 4: {
13455 u32 tmp;
13456- __get_user_asm(tmp, (u32 __user *)src,
13457+ __get_user_asm(tmp, (const u32 __user *)src,
13458 ret, "l", "k", "=r", 4);
13459 if (likely(!ret))
13460 __put_user_asm(tmp, (u32 __user *)dst,
13461@@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13462 }
13463 case 8: {
13464 u64 tmp;
13465- __get_user_asm(tmp, (u64 __user *)src,
13466+ __get_user_asm(tmp, (const u64 __user *)src,
13467 ret, "q", "", "=r", 8);
13468 if (likely(!ret))
13469 __put_user_asm(tmp, (u64 __user *)dst,
13470@@ -203,47 +304,92 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13471 return ret;
13472 }
13473 default:
13474- return copy_user_generic((__force void *)dst,
13475- (__force void *)src, size);
13476+
13477+#ifdef CONFIG_PAX_MEMORY_UDEREF
13478+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13479+ src += PAX_USER_SHADOW_BASE;
13480+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13481+ dst += PAX_USER_SHADOW_BASE;
13482+#endif
13483+
13484+ return copy_user_generic((__force_kernel void *)dst,
13485+ (__force_kernel const void *)src, size);
13486 }
13487 }
13488
13489 __must_check long strnlen_user(const char __user *str, long n);
13490 __must_check long __strnlen_user(const char __user *str, long n);
13491 __must_check long strlen_user(const char __user *str);
13492-__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13493-__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13494+__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13495+__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13496
13497 static __must_check __always_inline int
13498-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13499+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13500 {
13501- return copy_user_generic(dst, (__force const void *)src, size);
13502+ if (size > INT_MAX)
13503+ return size;
13504+
13505+#ifdef CONFIG_PAX_MEMORY_UDEREF
13506+ if (!__access_ok(VERIFY_READ, src, size))
13507+ return size;
13508+
13509+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13510+ src += PAX_USER_SHADOW_BASE;
13511+#endif
13512+
13513+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13514 }
13515
13516-static __must_check __always_inline int
13517-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13518+static __must_check __always_inline unsigned long
13519+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13520 {
13521- return copy_user_generic((__force void *)dst, src, size);
13522+ if (size > INT_MAX)
13523+ return size;
13524+
13525+#ifdef CONFIG_PAX_MEMORY_UDEREF
13526+ if (!__access_ok(VERIFY_WRITE, dst, size))
13527+ return size;
13528+
13529+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13530+ dst += PAX_USER_SHADOW_BASE;
13531+#endif
13532+
13533+ return copy_user_generic((__force_kernel void *)dst, src, size);
13534 }
13535
13536-extern long __copy_user_nocache(void *dst, const void __user *src,
13537- unsigned size, int zerorest);
13538+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13539+ unsigned long size, int zerorest) __size_overflow(3);
13540
13541-static inline int
13542-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13543+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13544 {
13545 might_sleep();
13546+
13547+ if (size > INT_MAX)
13548+ return size;
13549+
13550+#ifdef CONFIG_PAX_MEMORY_UDEREF
13551+ if (!__access_ok(VERIFY_READ, src, size))
13552+ return size;
13553+#endif
13554+
13555 return __copy_user_nocache(dst, src, size, 1);
13556 }
13557
13558-static inline int
13559-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13560- unsigned size)
13561+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13562+ unsigned long size)
13563 {
13564+ if (size > INT_MAX)
13565+ return size;
13566+
13567+#ifdef CONFIG_PAX_MEMORY_UDEREF
13568+ if (!__access_ok(VERIFY_READ, src, size))
13569+ return size;
13570+#endif
13571+
13572 return __copy_user_nocache(dst, src, size, 0);
13573 }
13574
13575-unsigned long
13576-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13577+extern unsigned long
13578+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13579
13580 #endif /* _ASM_X86_UACCESS_64_H */
13581diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13582index bb05228..d763d5b 100644
13583--- a/arch/x86/include/asm/vdso.h
13584+++ b/arch/x86/include/asm/vdso.h
13585@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13586 #define VDSO32_SYMBOL(base, name) \
13587 ({ \
13588 extern const char VDSO32_##name[]; \
13589- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13590+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13591 })
13592 #endif
13593
13594diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13595index 764b66a..ad3cfc8 100644
13596--- a/arch/x86/include/asm/x86_init.h
13597+++ b/arch/x86/include/asm/x86_init.h
13598@@ -29,7 +29,7 @@ struct x86_init_mpparse {
13599 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13600 void (*find_smp_config)(void);
13601 void (*get_smp_config)(unsigned int early);
13602-};
13603+} __no_const;
13604
13605 /**
13606 * struct x86_init_resources - platform specific resource related ops
13607@@ -43,7 +43,7 @@ struct x86_init_resources {
13608 void (*probe_roms)(void);
13609 void (*reserve_resources)(void);
13610 char *(*memory_setup)(void);
13611-};
13612+} __no_const;
13613
13614 /**
13615 * struct x86_init_irqs - platform specific interrupt setup
13616@@ -56,7 +56,7 @@ struct x86_init_irqs {
13617 void (*pre_vector_init)(void);
13618 void (*intr_init)(void);
13619 void (*trap_init)(void);
13620-};
13621+} __no_const;
13622
13623 /**
13624 * struct x86_init_oem - oem platform specific customizing functions
13625@@ -66,7 +66,7 @@ struct x86_init_irqs {
13626 struct x86_init_oem {
13627 void (*arch_setup)(void);
13628 void (*banner)(void);
13629-};
13630+} __no_const;
13631
13632 /**
13633 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13634@@ -77,7 +77,7 @@ struct x86_init_oem {
13635 */
13636 struct x86_init_mapping {
13637 void (*pagetable_reserve)(u64 start, u64 end);
13638-};
13639+} __no_const;
13640
13641 /**
13642 * struct x86_init_paging - platform specific paging functions
13643@@ -87,7 +87,7 @@ struct x86_init_mapping {
13644 struct x86_init_paging {
13645 void (*pagetable_setup_start)(pgd_t *base);
13646 void (*pagetable_setup_done)(pgd_t *base);
13647-};
13648+} __no_const;
13649
13650 /**
13651 * struct x86_init_timers - platform specific timer setup
13652@@ -102,7 +102,7 @@ struct x86_init_timers {
13653 void (*tsc_pre_init)(void);
13654 void (*timer_init)(void);
13655 void (*wallclock_init)(void);
13656-};
13657+} __no_const;
13658
13659 /**
13660 * struct x86_init_iommu - platform specific iommu setup
13661@@ -110,7 +110,7 @@ struct x86_init_timers {
13662 */
13663 struct x86_init_iommu {
13664 int (*iommu_init)(void);
13665-};
13666+} __no_const;
13667
13668 /**
13669 * struct x86_init_pci - platform specific pci init functions
13670@@ -124,7 +124,7 @@ struct x86_init_pci {
13671 int (*init)(void);
13672 void (*init_irq)(void);
13673 void (*fixup_irqs)(void);
13674-};
13675+} __no_const;
13676
13677 /**
13678 * struct x86_init_ops - functions for platform specific setup
13679@@ -140,7 +140,7 @@ struct x86_init_ops {
13680 struct x86_init_timers timers;
13681 struct x86_init_iommu iommu;
13682 struct x86_init_pci pci;
13683-};
13684+} __no_const;
13685
13686 /**
13687 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13688@@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13689 void (*setup_percpu_clockev)(void);
13690 void (*early_percpu_clock_init)(void);
13691 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13692-};
13693+} __no_const;
13694
13695 /**
13696 * struct x86_platform_ops - platform specific runtime functions
13697@@ -177,7 +177,7 @@ struct x86_platform_ops {
13698 int (*i8042_detect)(void);
13699 void (*save_sched_clock_state)(void);
13700 void (*restore_sched_clock_state)(void);
13701-};
13702+} __no_const;
13703
13704 struct pci_dev;
13705
13706@@ -186,7 +186,7 @@ struct x86_msi_ops {
13707 void (*teardown_msi_irq)(unsigned int irq);
13708 void (*teardown_msi_irqs)(struct pci_dev *dev);
13709 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13710-};
13711+} __no_const;
13712
13713 extern struct x86_init_ops x86_init;
13714 extern struct x86_cpuinit_ops x86_cpuinit;
13715diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13716index c6ce245..ffbdab7 100644
13717--- a/arch/x86/include/asm/xsave.h
13718+++ b/arch/x86/include/asm/xsave.h
13719@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13720 {
13721 int err;
13722
13723+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13724+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13725+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13726+#endif
13727+
13728 /*
13729 * Clear the xsave header first, so that reserved fields are
13730 * initialized to zero.
13731@@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13732 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13733 {
13734 int err;
13735- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13736+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13737 u32 lmask = mask;
13738 u32 hmask = mask >> 32;
13739
13740+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13741+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13742+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13743+#endif
13744+
13745 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13746 "2:\n"
13747 ".section .fixup,\"ax\"\n"
13748diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13749index 6a564ac..9b1340c 100644
13750--- a/arch/x86/kernel/acpi/realmode/Makefile
13751+++ b/arch/x86/kernel/acpi/realmode/Makefile
13752@@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13753 $(call cc-option, -fno-stack-protector) \
13754 $(call cc-option, -mpreferred-stack-boundary=2)
13755 KBUILD_CFLAGS += $(call cc-option, -m32)
13756+ifdef CONSTIFY_PLUGIN
13757+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13758+endif
13759 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13760 GCOV_PROFILE := n
13761
13762diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13763index b4fd836..4358fe3 100644
13764--- a/arch/x86/kernel/acpi/realmode/wakeup.S
13765+++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13766@@ -108,6 +108,9 @@ wakeup_code:
13767 /* Do any other stuff... */
13768
13769 #ifndef CONFIG_64BIT
13770+ /* Recheck NX bit overrides (64bit path does this in trampoline */
13771+ call verify_cpu
13772+
13773 /* This could also be done in C code... */
13774 movl pmode_cr3, %eax
13775 movl %eax, %cr3
13776@@ -131,6 +134,7 @@ wakeup_code:
13777 movl pmode_cr0, %eax
13778 movl %eax, %cr0
13779 jmp pmode_return
13780+# include "../../verify_cpu.S"
13781 #else
13782 pushw $0
13783 pushw trampoline_segment
13784diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13785index 146a49c..1b5338b 100644
13786--- a/arch/x86/kernel/acpi/sleep.c
13787+++ b/arch/x86/kernel/acpi/sleep.c
13788@@ -98,8 +98,12 @@ int acpi_suspend_lowlevel(void)
13789 header->trampoline_segment = trampoline_address() >> 4;
13790 #ifdef CONFIG_SMP
13791 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13792+
13793+ pax_open_kernel();
13794 early_gdt_descr.address =
13795 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13796+ pax_close_kernel();
13797+
13798 initial_gs = per_cpu_offset(smp_processor_id());
13799 #endif
13800 initial_code = (unsigned long)wakeup_long64;
13801diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13802index 7261083..5c12053 100644
13803--- a/arch/x86/kernel/acpi/wakeup_32.S
13804+++ b/arch/x86/kernel/acpi/wakeup_32.S
13805@@ -30,13 +30,11 @@ wakeup_pmode_return:
13806 # and restore the stack ... but you need gdt for this to work
13807 movl saved_context_esp, %esp
13808
13809- movl %cs:saved_magic, %eax
13810- cmpl $0x12345678, %eax
13811+ cmpl $0x12345678, saved_magic
13812 jne bogus_magic
13813
13814 # jump to place where we left off
13815- movl saved_eip, %eax
13816- jmp *%eax
13817+ jmp *(saved_eip)
13818
13819 bogus_magic:
13820 jmp bogus_magic
13821diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13822index 1f84794..e23f862 100644
13823--- a/arch/x86/kernel/alternative.c
13824+++ b/arch/x86/kernel/alternative.c
13825@@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13826 */
13827 for (a = start; a < end; a++) {
13828 instr = (u8 *)&a->instr_offset + a->instr_offset;
13829+
13830+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13831+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13832+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13833+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13834+#endif
13835+
13836 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13837 BUG_ON(a->replacementlen > a->instrlen);
13838 BUG_ON(a->instrlen > sizeof(insnbuf));
13839@@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13840 for (poff = start; poff < end; poff++) {
13841 u8 *ptr = (u8 *)poff + *poff;
13842
13843+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13844+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13845+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13846+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13847+#endif
13848+
13849 if (!*poff || ptr < text || ptr >= text_end)
13850 continue;
13851 /* turn DS segment override prefix into lock prefix */
13852- if (*ptr == 0x3e)
13853+ if (*ktla_ktva(ptr) == 0x3e)
13854 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13855 };
13856 mutex_unlock(&text_mutex);
13857@@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13858 for (poff = start; poff < end; poff++) {
13859 u8 *ptr = (u8 *)poff + *poff;
13860
13861+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13862+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13863+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13864+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13865+#endif
13866+
13867 if (!*poff || ptr < text || ptr >= text_end)
13868 continue;
13869 /* turn lock prefix into DS segment override prefix */
13870- if (*ptr == 0xf0)
13871+ if (*ktla_ktva(ptr) == 0xf0)
13872 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13873 };
13874 mutex_unlock(&text_mutex);
13875@@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13876
13877 BUG_ON(p->len > MAX_PATCH_LEN);
13878 /* prep the buffer with the original instructions */
13879- memcpy(insnbuf, p->instr, p->len);
13880+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13881 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13882 (unsigned long)p->instr, p->len);
13883
13884@@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13885 if (smp_alt_once)
13886 free_init_pages("SMP alternatives",
13887 (unsigned long)__smp_locks,
13888- (unsigned long)__smp_locks_end);
13889+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13890
13891 restart_nmi();
13892 }
13893@@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13894 * instructions. And on the local CPU you need to be protected again NMI or MCE
13895 * handlers seeing an inconsistent instruction while you patch.
13896 */
13897-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13898+void *__kprobes text_poke_early(void *addr, const void *opcode,
13899 size_t len)
13900 {
13901 unsigned long flags;
13902 local_irq_save(flags);
13903- memcpy(addr, opcode, len);
13904+
13905+ pax_open_kernel();
13906+ memcpy(ktla_ktva(addr), opcode, len);
13907 sync_core();
13908+ pax_close_kernel();
13909+
13910 local_irq_restore(flags);
13911 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13912 that causes hangs on some VIA CPUs. */
13913@@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13914 */
13915 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13916 {
13917- unsigned long flags;
13918- char *vaddr;
13919+ unsigned char *vaddr = ktla_ktva(addr);
13920 struct page *pages[2];
13921- int i;
13922+ size_t i;
13923
13924 if (!core_kernel_text((unsigned long)addr)) {
13925- pages[0] = vmalloc_to_page(addr);
13926- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13927+ pages[0] = vmalloc_to_page(vaddr);
13928+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13929 } else {
13930- pages[0] = virt_to_page(addr);
13931+ pages[0] = virt_to_page(vaddr);
13932 WARN_ON(!PageReserved(pages[0]));
13933- pages[1] = virt_to_page(addr + PAGE_SIZE);
13934+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13935 }
13936 BUG_ON(!pages[0]);
13937- local_irq_save(flags);
13938- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13939- if (pages[1])
13940- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13941- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13942- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13943- clear_fixmap(FIX_TEXT_POKE0);
13944- if (pages[1])
13945- clear_fixmap(FIX_TEXT_POKE1);
13946- local_flush_tlb();
13947- sync_core();
13948- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13949- that causes hangs on some VIA CPUs. */
13950+ text_poke_early(addr, opcode, len);
13951 for (i = 0; i < len; i++)
13952- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13953- local_irq_restore(flags);
13954+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13955 return addr;
13956 }
13957
13958diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13959index edc2448..553e7c5 100644
13960--- a/arch/x86/kernel/apic/apic.c
13961+++ b/arch/x86/kernel/apic/apic.c
13962@@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13963 /*
13964 * Debug level, exported for io_apic.c
13965 */
13966-unsigned int apic_verbosity;
13967+int apic_verbosity;
13968
13969 int pic_mode;
13970
13971@@ -1917,7 +1917,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13972 apic_write(APIC_ESR, 0);
13973 v1 = apic_read(APIC_ESR);
13974 ack_APIC_irq();
13975- atomic_inc(&irq_err_count);
13976+ atomic_inc_unchecked(&irq_err_count);
13977
13978 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13979 smp_processor_id(), v0 , v1);
13980diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13981index e88300d..cd5a87a 100644
13982--- a/arch/x86/kernel/apic/io_apic.c
13983+++ b/arch/x86/kernel/apic/io_apic.c
13984@@ -83,7 +83,9 @@ static struct io_apic_ops io_apic_ops = {
13985
13986 void __init set_io_apic_ops(const struct io_apic_ops *ops)
13987 {
13988- io_apic_ops = *ops;
13989+ pax_open_kernel();
13990+ memcpy((void*)&io_apic_ops, ops, sizeof io_apic_ops);
13991+ pax_close_kernel();
13992 }
13993
13994 /*
13995@@ -1135,7 +1137,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13996 }
13997 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13998
13999-void lock_vector_lock(void)
14000+void lock_vector_lock(void) __acquires(vector_lock)
14001 {
14002 /* Used to the online set of cpus does not change
14003 * during assign_irq_vector.
14004@@ -1143,7 +1145,7 @@ void lock_vector_lock(void)
14005 raw_spin_lock(&vector_lock);
14006 }
14007
14008-void unlock_vector_lock(void)
14009+void unlock_vector_lock(void) __releases(vector_lock)
14010 {
14011 raw_spin_unlock(&vector_lock);
14012 }
14013@@ -2549,7 +2551,7 @@ static void ack_apic_edge(struct irq_data *data)
14014 ack_APIC_irq();
14015 }
14016
14017-atomic_t irq_mis_count;
14018+atomic_unchecked_t irq_mis_count;
14019
14020 #ifdef CONFIG_GENERIC_PENDING_IRQ
14021 static inline bool ioapic_irqd_mask(struct irq_data *data, struct irq_cfg *cfg)
14022@@ -2667,7 +2669,7 @@ static void ack_apic_level(struct irq_data *data)
14023 * at the cpu.
14024 */
14025 if (!(v & (1 << (i & 0x1f)))) {
14026- atomic_inc(&irq_mis_count);
14027+ atomic_inc_unchecked(&irq_mis_count);
14028
14029 eoi_ioapic_irq(irq, cfg);
14030 }
14031diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14032index 459e78c..f037006 100644
14033--- a/arch/x86/kernel/apm_32.c
14034+++ b/arch/x86/kernel/apm_32.c
14035@@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
14036 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14037 * even though they are called in protected mode.
14038 */
14039-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14040+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14041 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14042
14043 static const char driver_version[] = "1.16ac"; /* no spaces */
14044@@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
14045 BUG_ON(cpu != 0);
14046 gdt = get_cpu_gdt_table(cpu);
14047 save_desc_40 = gdt[0x40 / 8];
14048+
14049+ pax_open_kernel();
14050 gdt[0x40 / 8] = bad_bios_desc;
14051+ pax_close_kernel();
14052
14053 apm_irq_save(flags);
14054 APM_DO_SAVE_SEGS;
14055@@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
14056 &call->esi);
14057 APM_DO_RESTORE_SEGS;
14058 apm_irq_restore(flags);
14059+
14060+ pax_open_kernel();
14061 gdt[0x40 / 8] = save_desc_40;
14062+ pax_close_kernel();
14063+
14064 put_cpu();
14065
14066 return call->eax & 0xff;
14067@@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
14068 BUG_ON(cpu != 0);
14069 gdt = get_cpu_gdt_table(cpu);
14070 save_desc_40 = gdt[0x40 / 8];
14071+
14072+ pax_open_kernel();
14073 gdt[0x40 / 8] = bad_bios_desc;
14074+ pax_close_kernel();
14075
14076 apm_irq_save(flags);
14077 APM_DO_SAVE_SEGS;
14078@@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
14079 &call->eax);
14080 APM_DO_RESTORE_SEGS;
14081 apm_irq_restore(flags);
14082+
14083+ pax_open_kernel();
14084 gdt[0x40 / 8] = save_desc_40;
14085+ pax_close_kernel();
14086+
14087 put_cpu();
14088 return error;
14089 }
14090@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14091 * code to that CPU.
14092 */
14093 gdt = get_cpu_gdt_table(0);
14094+
14095+ pax_open_kernel();
14096 set_desc_base(&gdt[APM_CS >> 3],
14097 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14098 set_desc_base(&gdt[APM_CS_16 >> 3],
14099 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14100 set_desc_base(&gdt[APM_DS >> 3],
14101 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14102+ pax_close_kernel();
14103
14104 proc_create("apm", 0, NULL, &apm_file_ops);
14105
14106diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14107index 68de2dc..1f3c720 100644
14108--- a/arch/x86/kernel/asm-offsets.c
14109+++ b/arch/x86/kernel/asm-offsets.c
14110@@ -33,6 +33,8 @@ void common(void) {
14111 OFFSET(TI_status, thread_info, status);
14112 OFFSET(TI_addr_limit, thread_info, addr_limit);
14113 OFFSET(TI_preempt_count, thread_info, preempt_count);
14114+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14115+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14116
14117 BLANK();
14118 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14119@@ -53,8 +55,26 @@ void common(void) {
14120 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14121 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14122 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14123+
14124+#ifdef CONFIG_PAX_KERNEXEC
14125+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14126 #endif
14127
14128+#ifdef CONFIG_PAX_MEMORY_UDEREF
14129+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14130+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14131+#ifdef CONFIG_X86_64
14132+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14133+#endif
14134+#endif
14135+
14136+#endif
14137+
14138+ BLANK();
14139+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14140+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14141+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14142+
14143 #ifdef CONFIG_XEN
14144 BLANK();
14145 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14146diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14147index 1b4754f..fbb4227 100644
14148--- a/arch/x86/kernel/asm-offsets_64.c
14149+++ b/arch/x86/kernel/asm-offsets_64.c
14150@@ -76,6 +76,7 @@ int main(void)
14151 BLANK();
14152 #undef ENTRY
14153
14154+ DEFINE(TSS_size, sizeof(struct tss_struct));
14155 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14156 BLANK();
14157
14158diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14159index 6ab6aa2..8f71507 100644
14160--- a/arch/x86/kernel/cpu/Makefile
14161+++ b/arch/x86/kernel/cpu/Makefile
14162@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14163 CFLAGS_REMOVE_perf_event.o = -pg
14164 endif
14165
14166-# Make sure load_percpu_segment has no stackprotector
14167-nostackp := $(call cc-option, -fno-stack-protector)
14168-CFLAGS_common.o := $(nostackp)
14169-
14170 obj-y := intel_cacheinfo.o scattered.o topology.o
14171 obj-y += proc.o capflags.o powerflags.o common.o
14172 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14173diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14174index 146bb62..ac9c74a 100644
14175--- a/arch/x86/kernel/cpu/amd.c
14176+++ b/arch/x86/kernel/cpu/amd.c
14177@@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14178 unsigned int size)
14179 {
14180 /* AMD errata T13 (order #21922) */
14181- if ((c->x86 == 6)) {
14182+ if (c->x86 == 6) {
14183 /* Duron Rev A0 */
14184 if (c->x86_model == 3 && c->x86_mask == 0)
14185 size = 64;
14186diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14187index cf79302..b1b28ae 100644
14188--- a/arch/x86/kernel/cpu/common.c
14189+++ b/arch/x86/kernel/cpu/common.c
14190@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14191
14192 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14193
14194-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14195-#ifdef CONFIG_X86_64
14196- /*
14197- * We need valid kernel segments for data and code in long mode too
14198- * IRET will check the segment types kkeil 2000/10/28
14199- * Also sysret mandates a special GDT layout
14200- *
14201- * TLS descriptors are currently at a different place compared to i386.
14202- * Hopefully nobody expects them at a fixed place (Wine?)
14203- */
14204- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14205- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14206- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14207- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14208- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14209- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14210-#else
14211- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14212- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14213- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14214- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14215- /*
14216- * Segments used for calling PnP BIOS have byte granularity.
14217- * They code segments and data segments have fixed 64k limits,
14218- * the transfer segment sizes are set at run time.
14219- */
14220- /* 32-bit code */
14221- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14222- /* 16-bit code */
14223- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14224- /* 16-bit data */
14225- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14226- /* 16-bit data */
14227- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14228- /* 16-bit data */
14229- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14230- /*
14231- * The APM segments have byte granularity and their bases
14232- * are set at run time. All have 64k limits.
14233- */
14234- /* 32-bit code */
14235- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14236- /* 16-bit code */
14237- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14238- /* data */
14239- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14240-
14241- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14242- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14243- GDT_STACK_CANARY_INIT
14244-#endif
14245-} };
14246-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14247-
14248 static int __init x86_xsave_setup(char *s)
14249 {
14250 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14251@@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14252 {
14253 struct desc_ptr gdt_descr;
14254
14255- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14256+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14257 gdt_descr.size = GDT_SIZE - 1;
14258 load_gdt(&gdt_descr);
14259 /* Reload the per-cpu base */
14260@@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14261 /* Filter out anything that depends on CPUID levels we don't have */
14262 filter_cpuid_features(c, true);
14263
14264+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14265+ setup_clear_cpu_cap(X86_FEATURE_SEP);
14266+#endif
14267+
14268 /* If the model name is still unset, do table lookup. */
14269 if (!c->x86_model_id[0]) {
14270 const char *p;
14271@@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14272 }
14273 __setup("clearcpuid=", setup_disablecpuid);
14274
14275+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14276+EXPORT_PER_CPU_SYMBOL(current_tinfo);
14277+
14278 #ifdef CONFIG_X86_64
14279 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14280-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14281- (unsigned long) nmi_idt_table };
14282+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14283
14284 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14285 irq_stack_union) __aligned(PAGE_SIZE);
14286@@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14287 EXPORT_PER_CPU_SYMBOL(current_task);
14288
14289 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14290- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14291+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14292 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14293
14294 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14295@@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14296 {
14297 memset(regs, 0, sizeof(struct pt_regs));
14298 regs->fs = __KERNEL_PERCPU;
14299- regs->gs = __KERNEL_STACK_CANARY;
14300+ savesegment(gs, regs->gs);
14301
14302 return regs;
14303 }
14304@@ -1181,7 +1133,7 @@ void __cpuinit cpu_init(void)
14305 int i;
14306
14307 cpu = stack_smp_processor_id();
14308- t = &per_cpu(init_tss, cpu);
14309+ t = init_tss + cpu;
14310 oist = &per_cpu(orig_ist, cpu);
14311
14312 #ifdef CONFIG_NUMA
14313@@ -1207,7 +1159,7 @@ void __cpuinit cpu_init(void)
14314 switch_to_new_gdt(cpu);
14315 loadsegment(fs, 0);
14316
14317- load_idt((const struct desc_ptr *)&idt_descr);
14318+ load_idt(&idt_descr);
14319
14320 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14321 syscall_init();
14322@@ -1216,7 +1168,6 @@ void __cpuinit cpu_init(void)
14323 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14324 barrier();
14325
14326- x86_configure_nx();
14327 if (cpu != 0)
14328 enable_x2apic();
14329
14330@@ -1272,7 +1223,7 @@ void __cpuinit cpu_init(void)
14331 {
14332 int cpu = smp_processor_id();
14333 struct task_struct *curr = current;
14334- struct tss_struct *t = &per_cpu(init_tss, cpu);
14335+ struct tss_struct *t = init_tss + cpu;
14336 struct thread_struct *thread = &curr->thread;
14337
14338 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14339diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14340index 3e6ff6c..54b4992 100644
14341--- a/arch/x86/kernel/cpu/intel.c
14342+++ b/arch/x86/kernel/cpu/intel.c
14343@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14344 * Update the IDT descriptor and reload the IDT so that
14345 * it uses the read-only mapped virtual address.
14346 */
14347- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14348+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14349 load_idt(&idt_descr);
14350 }
14351 #endif
14352diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14353index 61604ae..98250a5 100644
14354--- a/arch/x86/kernel/cpu/mcheck/mce.c
14355+++ b/arch/x86/kernel/cpu/mcheck/mce.c
14356@@ -42,6 +42,7 @@
14357 #include <asm/processor.h>
14358 #include <asm/mce.h>
14359 #include <asm/msr.h>
14360+#include <asm/local.h>
14361
14362 #include "mce-internal.h"
14363
14364@@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14365 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14366 m->cs, m->ip);
14367
14368- if (m->cs == __KERNEL_CS)
14369+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14370 print_symbol("{%s}", m->ip);
14371 pr_cont("\n");
14372 }
14373@@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14374
14375 #define PANIC_TIMEOUT 5 /* 5 seconds */
14376
14377-static atomic_t mce_paniced;
14378+static atomic_unchecked_t mce_paniced;
14379
14380 static int fake_panic;
14381-static atomic_t mce_fake_paniced;
14382+static atomic_unchecked_t mce_fake_paniced;
14383
14384 /* Panic in progress. Enable interrupts and wait for final IPI */
14385 static void wait_for_panic(void)
14386@@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14387 /*
14388 * Make sure only one CPU runs in machine check panic
14389 */
14390- if (atomic_inc_return(&mce_paniced) > 1)
14391+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14392 wait_for_panic();
14393 barrier();
14394
14395@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14396 console_verbose();
14397 } else {
14398 /* Don't log too much for fake panic */
14399- if (atomic_inc_return(&mce_fake_paniced) > 1)
14400+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14401 return;
14402 }
14403 /* First print corrected ones that are still unlogged */
14404@@ -684,7 +685,7 @@ static int mce_timed_out(u64 *t)
14405 * might have been modified by someone else.
14406 */
14407 rmb();
14408- if (atomic_read(&mce_paniced))
14409+ if (atomic_read_unchecked(&mce_paniced))
14410 wait_for_panic();
14411 if (!monarch_timeout)
14412 goto out;
14413@@ -1535,7 +1536,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14414 }
14415
14416 /* Call the installed machine check handler for this CPU setup. */
14417-void (*machine_check_vector)(struct pt_regs *, long error_code) =
14418+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14419 unexpected_machine_check;
14420
14421 /*
14422@@ -1558,7 +1559,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14423 return;
14424 }
14425
14426+ pax_open_kernel();
14427 machine_check_vector = do_machine_check;
14428+ pax_close_kernel();
14429
14430 __mcheck_cpu_init_generic();
14431 __mcheck_cpu_init_vendor(c);
14432@@ -1572,7 +1575,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14433 */
14434
14435 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14436-static int mce_chrdev_open_count; /* #times opened */
14437+static local_t mce_chrdev_open_count; /* #times opened */
14438 static int mce_chrdev_open_exclu; /* already open exclusive? */
14439
14440 static int mce_chrdev_open(struct inode *inode, struct file *file)
14441@@ -1580,7 +1583,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14442 spin_lock(&mce_chrdev_state_lock);
14443
14444 if (mce_chrdev_open_exclu ||
14445- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14446+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14447 spin_unlock(&mce_chrdev_state_lock);
14448
14449 return -EBUSY;
14450@@ -1588,7 +1591,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14451
14452 if (file->f_flags & O_EXCL)
14453 mce_chrdev_open_exclu = 1;
14454- mce_chrdev_open_count++;
14455+ local_inc(&mce_chrdev_open_count);
14456
14457 spin_unlock(&mce_chrdev_state_lock);
14458
14459@@ -1599,7 +1602,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14460 {
14461 spin_lock(&mce_chrdev_state_lock);
14462
14463- mce_chrdev_open_count--;
14464+ local_dec(&mce_chrdev_open_count);
14465 mce_chrdev_open_exclu = 0;
14466
14467 spin_unlock(&mce_chrdev_state_lock);
14468@@ -2324,7 +2327,7 @@ struct dentry *mce_get_debugfs_dir(void)
14469 static void mce_reset(void)
14470 {
14471 cpu_missing = 0;
14472- atomic_set(&mce_fake_paniced, 0);
14473+ atomic_set_unchecked(&mce_fake_paniced, 0);
14474 atomic_set(&mce_executing, 0);
14475 atomic_set(&mce_callin, 0);
14476 atomic_set(&global_nwo, 0);
14477diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14478index 2d5454c..51987eb 100644
14479--- a/arch/x86/kernel/cpu/mcheck/p5.c
14480+++ b/arch/x86/kernel/cpu/mcheck/p5.c
14481@@ -11,6 +11,7 @@
14482 #include <asm/processor.h>
14483 #include <asm/mce.h>
14484 #include <asm/msr.h>
14485+#include <asm/pgtable.h>
14486
14487 /* By default disabled */
14488 int mce_p5_enabled __read_mostly;
14489@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14490 if (!cpu_has(c, X86_FEATURE_MCE))
14491 return;
14492
14493+ pax_open_kernel();
14494 machine_check_vector = pentium_machine_check;
14495+ pax_close_kernel();
14496 /* Make sure the vector pointer is visible before we enable MCEs: */
14497 wmb();
14498
14499diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14500index 2d7998f..17c9de1 100644
14501--- a/arch/x86/kernel/cpu/mcheck/winchip.c
14502+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14503@@ -10,6 +10,7 @@
14504 #include <asm/processor.h>
14505 #include <asm/mce.h>
14506 #include <asm/msr.h>
14507+#include <asm/pgtable.h>
14508
14509 /* Machine check handler for WinChip C6: */
14510 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14511@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14512 {
14513 u32 lo, hi;
14514
14515+ pax_open_kernel();
14516 machine_check_vector = winchip_machine_check;
14517+ pax_close_kernel();
14518 /* Make sure the vector pointer is visible before we enable MCEs: */
14519 wmb();
14520
14521diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14522index 6b96110..0da73eb 100644
14523--- a/arch/x86/kernel/cpu/mtrr/main.c
14524+++ b/arch/x86/kernel/cpu/mtrr/main.c
14525@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14526 u64 size_or_mask, size_and_mask;
14527 static bool mtrr_aps_delayed_init;
14528
14529-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14530+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14531
14532 const struct mtrr_ops *mtrr_if;
14533
14534diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14535index df5e41f..816c719 100644
14536--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14537+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14538@@ -25,7 +25,7 @@ struct mtrr_ops {
14539 int (*validate_add_page)(unsigned long base, unsigned long size,
14540 unsigned int type);
14541 int (*have_wrcomb)(void);
14542-};
14543+} __do_const;
14544
14545 extern int generic_get_free_region(unsigned long base, unsigned long size,
14546 int replace_reg);
14547diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14548index bb8e034..fb9020b 100644
14549--- a/arch/x86/kernel/cpu/perf_event.c
14550+++ b/arch/x86/kernel/cpu/perf_event.c
14551@@ -1835,7 +1835,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14552 break;
14553
14554 perf_callchain_store(entry, frame.return_address);
14555- fp = frame.next_frame;
14556+ fp = (const void __force_user *)frame.next_frame;
14557 }
14558 }
14559
14560diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14561index 13ad899..f642b9a 100644
14562--- a/arch/x86/kernel/crash.c
14563+++ b/arch/x86/kernel/crash.c
14564@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14565 {
14566 #ifdef CONFIG_X86_32
14567 struct pt_regs fixed_regs;
14568-#endif
14569
14570-#ifdef CONFIG_X86_32
14571- if (!user_mode_vm(regs)) {
14572+ if (!user_mode(regs)) {
14573 crash_fixup_ss_esp(&fixed_regs, regs);
14574 regs = &fixed_regs;
14575 }
14576diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14577index 37250fe..bf2ec74 100644
14578--- a/arch/x86/kernel/doublefault_32.c
14579+++ b/arch/x86/kernel/doublefault_32.c
14580@@ -11,7 +11,7 @@
14581
14582 #define DOUBLEFAULT_STACKSIZE (1024)
14583 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14584-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14585+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14586
14587 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14588
14589@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14590 unsigned long gdt, tss;
14591
14592 store_gdt(&gdt_desc);
14593- gdt = gdt_desc.address;
14594+ gdt = (unsigned long)gdt_desc.address;
14595
14596 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14597
14598@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14599 /* 0x2 bit is always set */
14600 .flags = X86_EFLAGS_SF | 0x2,
14601 .sp = STACK_START,
14602- .es = __USER_DS,
14603+ .es = __KERNEL_DS,
14604 .cs = __KERNEL_CS,
14605 .ss = __KERNEL_DS,
14606- .ds = __USER_DS,
14607+ .ds = __KERNEL_DS,
14608 .fs = __KERNEL_PERCPU,
14609
14610 .__cr3 = __pa_nodebug(swapper_pg_dir),
14611diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14612index 1b81839..0b4e7b0 100644
14613--- a/arch/x86/kernel/dumpstack.c
14614+++ b/arch/x86/kernel/dumpstack.c
14615@@ -2,6 +2,9 @@
14616 * Copyright (C) 1991, 1992 Linus Torvalds
14617 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14618 */
14619+#ifdef CONFIG_GRKERNSEC_HIDESYM
14620+#define __INCLUDED_BY_HIDESYM 1
14621+#endif
14622 #include <linux/kallsyms.h>
14623 #include <linux/kprobes.h>
14624 #include <linux/uaccess.h>
14625@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14626 static void
14627 print_ftrace_graph_addr(unsigned long addr, void *data,
14628 const struct stacktrace_ops *ops,
14629- struct thread_info *tinfo, int *graph)
14630+ struct task_struct *task, int *graph)
14631 {
14632- struct task_struct *task;
14633 unsigned long ret_addr;
14634 int index;
14635
14636 if (addr != (unsigned long)return_to_handler)
14637 return;
14638
14639- task = tinfo->task;
14640 index = task->curr_ret_stack;
14641
14642 if (!task->ret_stack || index < *graph)
14643@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14644 static inline void
14645 print_ftrace_graph_addr(unsigned long addr, void *data,
14646 const struct stacktrace_ops *ops,
14647- struct thread_info *tinfo, int *graph)
14648+ struct task_struct *task, int *graph)
14649 { }
14650 #endif
14651
14652@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14653 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14654 */
14655
14656-static inline int valid_stack_ptr(struct thread_info *tinfo,
14657- void *p, unsigned int size, void *end)
14658+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14659 {
14660- void *t = tinfo;
14661 if (end) {
14662 if (p < end && p >= (end-THREAD_SIZE))
14663 return 1;
14664@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14665 }
14666
14667 unsigned long
14668-print_context_stack(struct thread_info *tinfo,
14669+print_context_stack(struct task_struct *task, void *stack_start,
14670 unsigned long *stack, unsigned long bp,
14671 const struct stacktrace_ops *ops, void *data,
14672 unsigned long *end, int *graph)
14673 {
14674 struct stack_frame *frame = (struct stack_frame *)bp;
14675
14676- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14677+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14678 unsigned long addr;
14679
14680 addr = *stack;
14681@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14682 } else {
14683 ops->address(data, addr, 0);
14684 }
14685- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14686+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14687 }
14688 stack++;
14689 }
14690@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14691 EXPORT_SYMBOL_GPL(print_context_stack);
14692
14693 unsigned long
14694-print_context_stack_bp(struct thread_info *tinfo,
14695+print_context_stack_bp(struct task_struct *task, void *stack_start,
14696 unsigned long *stack, unsigned long bp,
14697 const struct stacktrace_ops *ops, void *data,
14698 unsigned long *end, int *graph)
14699@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14700 struct stack_frame *frame = (struct stack_frame *)bp;
14701 unsigned long *ret_addr = &frame->return_address;
14702
14703- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14704+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14705 unsigned long addr = *ret_addr;
14706
14707 if (!__kernel_text_address(addr))
14708@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14709 ops->address(data, addr, 1);
14710 frame = frame->next_frame;
14711 ret_addr = &frame->return_address;
14712- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14713+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14714 }
14715
14716 return (unsigned long)frame;
14717@@ -189,7 +188,7 @@ void dump_stack(void)
14718
14719 bp = stack_frame(current, NULL);
14720 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14721- current->pid, current->comm, print_tainted(),
14722+ task_pid_nr(current), current->comm, print_tainted(),
14723 init_utsname()->release,
14724 (int)strcspn(init_utsname()->version, " "),
14725 init_utsname()->version);
14726@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14727 }
14728 EXPORT_SYMBOL_GPL(oops_begin);
14729
14730+extern void gr_handle_kernel_exploit(void);
14731+
14732 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14733 {
14734 if (regs && kexec_should_crash(current))
14735@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14736 panic("Fatal exception in interrupt");
14737 if (panic_on_oops)
14738 panic("Fatal exception");
14739- do_exit(signr);
14740+
14741+ gr_handle_kernel_exploit();
14742+
14743+ do_group_exit(signr);
14744 }
14745
14746 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14747@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14748
14749 show_registers(regs);
14750 #ifdef CONFIG_X86_32
14751- if (user_mode_vm(regs)) {
14752+ if (user_mode(regs)) {
14753 sp = regs->sp;
14754 ss = regs->ss & 0xffff;
14755 } else {
14756@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14757 unsigned long flags = oops_begin();
14758 int sig = SIGSEGV;
14759
14760- if (!user_mode_vm(regs))
14761+ if (!user_mode(regs))
14762 report_bug(regs->ip, regs);
14763
14764 if (__die(str, regs, err))
14765diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14766index 88ec912..e95e935 100644
14767--- a/arch/x86/kernel/dumpstack_32.c
14768+++ b/arch/x86/kernel/dumpstack_32.c
14769@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14770 bp = stack_frame(task, regs);
14771
14772 for (;;) {
14773- struct thread_info *context;
14774+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14775
14776- context = (struct thread_info *)
14777- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14778- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14779+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14780
14781- stack = (unsigned long *)context->previous_esp;
14782- if (!stack)
14783+ if (stack_start == task_stack_page(task))
14784 break;
14785+ stack = *(unsigned long **)stack_start;
14786 if (ops->stack(data, "IRQ") < 0)
14787 break;
14788 touch_nmi_watchdog();
14789@@ -87,7 +85,7 @@ void show_registers(struct pt_regs *regs)
14790 int i;
14791
14792 print_modules();
14793- __show_regs(regs, !user_mode_vm(regs));
14794+ __show_regs(regs, !user_mode(regs));
14795
14796 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14797 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14798@@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14799 * When in-kernel, we also print out the stack and code at the
14800 * time of the fault..
14801 */
14802- if (!user_mode_vm(regs)) {
14803+ if (!user_mode(regs)) {
14804 unsigned int code_prologue = code_bytes * 43 / 64;
14805 unsigned int code_len = code_bytes;
14806 unsigned char c;
14807 u8 *ip;
14808+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14809
14810 printk(KERN_EMERG "Stack:\n");
14811 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14812
14813 printk(KERN_EMERG "Code: ");
14814
14815- ip = (u8 *)regs->ip - code_prologue;
14816+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14817 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14818 /* try starting at IP */
14819- ip = (u8 *)regs->ip;
14820+ ip = (u8 *)regs->ip + cs_base;
14821 code_len = code_len - code_prologue + 1;
14822 }
14823 for (i = 0; i < code_len; i++, ip++) {
14824@@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14825 printk(KERN_CONT " Bad EIP value.");
14826 break;
14827 }
14828- if (ip == (u8 *)regs->ip)
14829+ if (ip == (u8 *)regs->ip + cs_base)
14830 printk(KERN_CONT "<%02x> ", c);
14831 else
14832 printk(KERN_CONT "%02x ", c);
14833@@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14834 {
14835 unsigned short ud2;
14836
14837+ ip = ktla_ktva(ip);
14838 if (ip < PAGE_OFFSET)
14839 return 0;
14840 if (probe_kernel_address((unsigned short *)ip, ud2))
14841@@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14842
14843 return ud2 == 0x0b0f;
14844 }
14845+
14846+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14847+void pax_check_alloca(unsigned long size)
14848+{
14849+ unsigned long sp = (unsigned long)&sp, stack_left;
14850+
14851+ /* all kernel stacks are of the same size */
14852+ stack_left = sp & (THREAD_SIZE - 1);
14853+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14854+}
14855+EXPORT_SYMBOL(pax_check_alloca);
14856+#endif
14857diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14858index 17107bd..9623722 100644
14859--- a/arch/x86/kernel/dumpstack_64.c
14860+++ b/arch/x86/kernel/dumpstack_64.c
14861@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14862 unsigned long *irq_stack_end =
14863 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14864 unsigned used = 0;
14865- struct thread_info *tinfo;
14866 int graph = 0;
14867 unsigned long dummy;
14868+ void *stack_start;
14869
14870 if (!task)
14871 task = current;
14872@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14873 * current stack address. If the stacks consist of nested
14874 * exceptions
14875 */
14876- tinfo = task_thread_info(task);
14877 for (;;) {
14878 char *id;
14879 unsigned long *estack_end;
14880+
14881 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14882 &used, &id);
14883
14884@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14885 if (ops->stack(data, id) < 0)
14886 break;
14887
14888- bp = ops->walk_stack(tinfo, stack, bp, ops,
14889+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14890 data, estack_end, &graph);
14891 ops->stack(data, "<EOE>");
14892 /*
14893@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14894 * second-to-last pointer (index -2 to end) in the
14895 * exception stack:
14896 */
14897+ if ((u16)estack_end[-1] != __KERNEL_DS)
14898+ goto out;
14899 stack = (unsigned long *) estack_end[-2];
14900 continue;
14901 }
14902@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14903 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14904 if (ops->stack(data, "IRQ") < 0)
14905 break;
14906- bp = ops->walk_stack(tinfo, stack, bp,
14907+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14908 ops, data, irq_stack_end, &graph);
14909 /*
14910 * We link to the next stack (which would be
14911@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14912 /*
14913 * This handles the process stack:
14914 */
14915- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14916+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14917+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14918+out:
14919 put_cpu();
14920 }
14921 EXPORT_SYMBOL(dump_trace);
14922@@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14923
14924 return ud2 == 0x0b0f;
14925 }
14926+
14927+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14928+void pax_check_alloca(unsigned long size)
14929+{
14930+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14931+ unsigned cpu, used;
14932+ char *id;
14933+
14934+ /* check the process stack first */
14935+ stack_start = (unsigned long)task_stack_page(current);
14936+ stack_end = stack_start + THREAD_SIZE;
14937+ if (likely(stack_start <= sp && sp < stack_end)) {
14938+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14939+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14940+ return;
14941+ }
14942+
14943+ cpu = get_cpu();
14944+
14945+ /* check the irq stacks */
14946+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14947+ stack_start = stack_end - IRQ_STACK_SIZE;
14948+ if (stack_start <= sp && sp < stack_end) {
14949+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14950+ put_cpu();
14951+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14952+ return;
14953+ }
14954+
14955+ /* check the exception stacks */
14956+ used = 0;
14957+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14958+ stack_start = stack_end - EXCEPTION_STKSZ;
14959+ if (stack_end && stack_start <= sp && sp < stack_end) {
14960+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14961+ put_cpu();
14962+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14963+ return;
14964+ }
14965+
14966+ put_cpu();
14967+
14968+ /* unknown stack */
14969+ BUG();
14970+}
14971+EXPORT_SYMBOL(pax_check_alloca);
14972+#endif
14973diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14974index 9b9f18b..9fcaa04 100644
14975--- a/arch/x86/kernel/early_printk.c
14976+++ b/arch/x86/kernel/early_printk.c
14977@@ -7,6 +7,7 @@
14978 #include <linux/pci_regs.h>
14979 #include <linux/pci_ids.h>
14980 #include <linux/errno.h>
14981+#include <linux/sched.h>
14982 #include <asm/io.h>
14983 #include <asm/processor.h>
14984 #include <asm/fcntl.h>
14985diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14986index 7b784f4..db6b628 100644
14987--- a/arch/x86/kernel/entry_32.S
14988+++ b/arch/x86/kernel/entry_32.S
14989@@ -179,13 +179,146 @@
14990 /*CFI_REL_OFFSET gs, PT_GS*/
14991 .endm
14992 .macro SET_KERNEL_GS reg
14993+
14994+#ifdef CONFIG_CC_STACKPROTECTOR
14995 movl $(__KERNEL_STACK_CANARY), \reg
14996+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14997+ movl $(__USER_DS), \reg
14998+#else
14999+ xorl \reg, \reg
15000+#endif
15001+
15002 movl \reg, %gs
15003 .endm
15004
15005 #endif /* CONFIG_X86_32_LAZY_GS */
15006
15007-.macro SAVE_ALL
15008+.macro pax_enter_kernel
15009+#ifdef CONFIG_PAX_KERNEXEC
15010+ call pax_enter_kernel
15011+#endif
15012+.endm
15013+
15014+.macro pax_exit_kernel
15015+#ifdef CONFIG_PAX_KERNEXEC
15016+ call pax_exit_kernel
15017+#endif
15018+.endm
15019+
15020+#ifdef CONFIG_PAX_KERNEXEC
15021+ENTRY(pax_enter_kernel)
15022+#ifdef CONFIG_PARAVIRT
15023+ pushl %eax
15024+ pushl %ecx
15025+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15026+ mov %eax, %esi
15027+#else
15028+ mov %cr0, %esi
15029+#endif
15030+ bts $16, %esi
15031+ jnc 1f
15032+ mov %cs, %esi
15033+ cmp $__KERNEL_CS, %esi
15034+ jz 3f
15035+ ljmp $__KERNEL_CS, $3f
15036+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15037+2:
15038+#ifdef CONFIG_PARAVIRT
15039+ mov %esi, %eax
15040+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15041+#else
15042+ mov %esi, %cr0
15043+#endif
15044+3:
15045+#ifdef CONFIG_PARAVIRT
15046+ popl %ecx
15047+ popl %eax
15048+#endif
15049+ ret
15050+ENDPROC(pax_enter_kernel)
15051+
15052+ENTRY(pax_exit_kernel)
15053+#ifdef CONFIG_PARAVIRT
15054+ pushl %eax
15055+ pushl %ecx
15056+#endif
15057+ mov %cs, %esi
15058+ cmp $__KERNEXEC_KERNEL_CS, %esi
15059+ jnz 2f
15060+#ifdef CONFIG_PARAVIRT
15061+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15062+ mov %eax, %esi
15063+#else
15064+ mov %cr0, %esi
15065+#endif
15066+ btr $16, %esi
15067+ ljmp $__KERNEL_CS, $1f
15068+1:
15069+#ifdef CONFIG_PARAVIRT
15070+ mov %esi, %eax
15071+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15072+#else
15073+ mov %esi, %cr0
15074+#endif
15075+2:
15076+#ifdef CONFIG_PARAVIRT
15077+ popl %ecx
15078+ popl %eax
15079+#endif
15080+ ret
15081+ENDPROC(pax_exit_kernel)
15082+#endif
15083+
15084+.macro pax_erase_kstack
15085+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15086+ call pax_erase_kstack
15087+#endif
15088+.endm
15089+
15090+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15091+/*
15092+ * ebp: thread_info
15093+ * ecx, edx: can be clobbered
15094+ */
15095+ENTRY(pax_erase_kstack)
15096+ pushl %edi
15097+ pushl %eax
15098+
15099+ mov TI_lowest_stack(%ebp), %edi
15100+ mov $-0xBEEF, %eax
15101+ std
15102+
15103+1: mov %edi, %ecx
15104+ and $THREAD_SIZE_asm - 1, %ecx
15105+ shr $2, %ecx
15106+ repne scasl
15107+ jecxz 2f
15108+
15109+ cmp $2*16, %ecx
15110+ jc 2f
15111+
15112+ mov $2*16, %ecx
15113+ repe scasl
15114+ jecxz 2f
15115+ jne 1b
15116+
15117+2: cld
15118+ mov %esp, %ecx
15119+ sub %edi, %ecx
15120+ shr $2, %ecx
15121+ rep stosl
15122+
15123+ mov TI_task_thread_sp0(%ebp), %edi
15124+ sub $128, %edi
15125+ mov %edi, TI_lowest_stack(%ebp)
15126+
15127+ popl %eax
15128+ popl %edi
15129+ ret
15130+ENDPROC(pax_erase_kstack)
15131+#endif
15132+
15133+.macro __SAVE_ALL _DS
15134 cld
15135 PUSH_GS
15136 pushl_cfi %fs
15137@@ -208,7 +341,7 @@
15138 CFI_REL_OFFSET ecx, 0
15139 pushl_cfi %ebx
15140 CFI_REL_OFFSET ebx, 0
15141- movl $(__USER_DS), %edx
15142+ movl $\_DS, %edx
15143 movl %edx, %ds
15144 movl %edx, %es
15145 movl $(__KERNEL_PERCPU), %edx
15146@@ -216,6 +349,15 @@
15147 SET_KERNEL_GS %edx
15148 .endm
15149
15150+.macro SAVE_ALL
15151+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15152+ __SAVE_ALL __KERNEL_DS
15153+ pax_enter_kernel
15154+#else
15155+ __SAVE_ALL __USER_DS
15156+#endif
15157+.endm
15158+
15159 .macro RESTORE_INT_REGS
15160 popl_cfi %ebx
15161 CFI_RESTORE ebx
15162@@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
15163 popfl_cfi
15164 jmp syscall_exit
15165 CFI_ENDPROC
15166-END(ret_from_fork)
15167+ENDPROC(ret_from_fork)
15168
15169 /*
15170 * Interrupt exit functions should be protected against kprobes
15171@@ -335,7 +477,15 @@ resume_userspace_sig:
15172 andl $SEGMENT_RPL_MASK, %eax
15173 #endif
15174 cmpl $USER_RPL, %eax
15175+
15176+#ifdef CONFIG_PAX_KERNEXEC
15177+ jae resume_userspace
15178+
15179+ pax_exit_kernel
15180+ jmp resume_kernel
15181+#else
15182 jb resume_kernel # not returning to v8086 or userspace
15183+#endif
15184
15185 ENTRY(resume_userspace)
15186 LOCKDEP_SYS_EXIT
15187@@ -347,8 +497,8 @@ ENTRY(resume_userspace)
15188 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15189 # int/exception return?
15190 jne work_pending
15191- jmp restore_all
15192-END(ret_from_exception)
15193+ jmp restore_all_pax
15194+ENDPROC(ret_from_exception)
15195
15196 #ifdef CONFIG_PREEMPT
15197 ENTRY(resume_kernel)
15198@@ -363,7 +513,7 @@ need_resched:
15199 jz restore_all
15200 call preempt_schedule_irq
15201 jmp need_resched
15202-END(resume_kernel)
15203+ENDPROC(resume_kernel)
15204 #endif
15205 CFI_ENDPROC
15206 /*
15207@@ -397,23 +547,34 @@ sysenter_past_esp:
15208 /*CFI_REL_OFFSET cs, 0*/
15209 /*
15210 * Push current_thread_info()->sysenter_return to the stack.
15211- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15212- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15213 */
15214- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15215+ pushl_cfi $0
15216 CFI_REL_OFFSET eip, 0
15217
15218 pushl_cfi %eax
15219 SAVE_ALL
15220+ GET_THREAD_INFO(%ebp)
15221+ movl TI_sysenter_return(%ebp),%ebp
15222+ movl %ebp,PT_EIP(%esp)
15223 ENABLE_INTERRUPTS(CLBR_NONE)
15224
15225 /*
15226 * Load the potential sixth argument from user stack.
15227 * Careful about security.
15228 */
15229+ movl PT_OLDESP(%esp),%ebp
15230+
15231+#ifdef CONFIG_PAX_MEMORY_UDEREF
15232+ mov PT_OLDSS(%esp),%ds
15233+1: movl %ds:(%ebp),%ebp
15234+ push %ss
15235+ pop %ds
15236+#else
15237 cmpl $__PAGE_OFFSET-3,%ebp
15238 jae syscall_fault
15239 1: movl (%ebp),%ebp
15240+#endif
15241+
15242 movl %ebp,PT_EBP(%esp)
15243 .section __ex_table,"a"
15244 .align 4
15245@@ -436,12 +597,24 @@ sysenter_do_call:
15246 testl $_TIF_ALLWORK_MASK, %ecx
15247 jne sysexit_audit
15248 sysenter_exit:
15249+
15250+#ifdef CONFIG_PAX_RANDKSTACK
15251+ pushl_cfi %eax
15252+ movl %esp, %eax
15253+ call pax_randomize_kstack
15254+ popl_cfi %eax
15255+#endif
15256+
15257+ pax_erase_kstack
15258+
15259 /* if something modifies registers it must also disable sysexit */
15260 movl PT_EIP(%esp), %edx
15261 movl PT_OLDESP(%esp), %ecx
15262 xorl %ebp,%ebp
15263 TRACE_IRQS_ON
15264 1: mov PT_FS(%esp), %fs
15265+2: mov PT_DS(%esp), %ds
15266+3: mov PT_ES(%esp), %es
15267 PTGS_TO_GS
15268 ENABLE_INTERRUPTS_SYSEXIT
15269
15270@@ -458,6 +631,9 @@ sysenter_audit:
15271 movl %eax,%edx /* 2nd arg: syscall number */
15272 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15273 call __audit_syscall_entry
15274+
15275+ pax_erase_kstack
15276+
15277 pushl_cfi %ebx
15278 movl PT_EAX(%esp),%eax /* reload syscall number */
15279 jmp sysenter_do_call
15280@@ -483,11 +659,17 @@ sysexit_audit:
15281
15282 CFI_ENDPROC
15283 .pushsection .fixup,"ax"
15284-2: movl $0,PT_FS(%esp)
15285+4: movl $0,PT_FS(%esp)
15286+ jmp 1b
15287+5: movl $0,PT_DS(%esp)
15288+ jmp 1b
15289+6: movl $0,PT_ES(%esp)
15290 jmp 1b
15291 .section __ex_table,"a"
15292 .align 4
15293- .long 1b,2b
15294+ .long 1b,4b
15295+ .long 2b,5b
15296+ .long 3b,6b
15297 .popsection
15298 PTGS_TO_GS_EX
15299 ENDPROC(ia32_sysenter_target)
15300@@ -520,6 +702,15 @@ syscall_exit:
15301 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15302 jne syscall_exit_work
15303
15304+restore_all_pax:
15305+
15306+#ifdef CONFIG_PAX_RANDKSTACK
15307+ movl %esp, %eax
15308+ call pax_randomize_kstack
15309+#endif
15310+
15311+ pax_erase_kstack
15312+
15313 restore_all:
15314 TRACE_IRQS_IRET
15315 restore_all_notrace:
15316@@ -579,14 +770,34 @@ ldt_ss:
15317 * compensating for the offset by changing to the ESPFIX segment with
15318 * a base address that matches for the difference.
15319 */
15320-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15321+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15322 mov %esp, %edx /* load kernel esp */
15323 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15324 mov %dx, %ax /* eax: new kernel esp */
15325 sub %eax, %edx /* offset (low word is 0) */
15326+#ifdef CONFIG_SMP
15327+ movl PER_CPU_VAR(cpu_number), %ebx
15328+ shll $PAGE_SHIFT_asm, %ebx
15329+ addl $cpu_gdt_table, %ebx
15330+#else
15331+ movl $cpu_gdt_table, %ebx
15332+#endif
15333 shr $16, %edx
15334- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15335- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15336+
15337+#ifdef CONFIG_PAX_KERNEXEC
15338+ mov %cr0, %esi
15339+ btr $16, %esi
15340+ mov %esi, %cr0
15341+#endif
15342+
15343+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15344+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15345+
15346+#ifdef CONFIG_PAX_KERNEXEC
15347+ bts $16, %esi
15348+ mov %esi, %cr0
15349+#endif
15350+
15351 pushl_cfi $__ESPFIX_SS
15352 pushl_cfi %eax /* new kernel esp */
15353 /* Disable interrupts, but do not irqtrace this section: we
15354@@ -615,38 +826,30 @@ work_resched:
15355 movl TI_flags(%ebp), %ecx
15356 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15357 # than syscall tracing?
15358- jz restore_all
15359+ jz restore_all_pax
15360 testb $_TIF_NEED_RESCHED, %cl
15361 jnz work_resched
15362
15363 work_notifysig: # deal with pending signals and
15364 # notify-resume requests
15365+ movl %esp, %eax
15366 #ifdef CONFIG_VM86
15367 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15368- movl %esp, %eax
15369- jne work_notifysig_v86 # returning to kernel-space or
15370+ jz 1f # returning to kernel-space or
15371 # vm86-space
15372- TRACE_IRQS_ON
15373- ENABLE_INTERRUPTS(CLBR_NONE)
15374- xorl %edx, %edx
15375- call do_notify_resume
15376- jmp resume_userspace_sig
15377
15378- ALIGN
15379-work_notifysig_v86:
15380 pushl_cfi %ecx # save ti_flags for do_notify_resume
15381 call save_v86_state # %eax contains pt_regs pointer
15382 popl_cfi %ecx
15383 movl %eax, %esp
15384-#else
15385- movl %esp, %eax
15386+1:
15387 #endif
15388 TRACE_IRQS_ON
15389 ENABLE_INTERRUPTS(CLBR_NONE)
15390 xorl %edx, %edx
15391 call do_notify_resume
15392 jmp resume_userspace_sig
15393-END(work_pending)
15394+ENDPROC(work_pending)
15395
15396 # perform syscall exit tracing
15397 ALIGN
15398@@ -654,11 +857,14 @@ syscall_trace_entry:
15399 movl $-ENOSYS,PT_EAX(%esp)
15400 movl %esp, %eax
15401 call syscall_trace_enter
15402+
15403+ pax_erase_kstack
15404+
15405 /* What it returned is what we'll actually use. */
15406 cmpl $(NR_syscalls), %eax
15407 jnae syscall_call
15408 jmp syscall_exit
15409-END(syscall_trace_entry)
15410+ENDPROC(syscall_trace_entry)
15411
15412 # perform syscall exit tracing
15413 ALIGN
15414@@ -671,20 +877,24 @@ syscall_exit_work:
15415 movl %esp, %eax
15416 call syscall_trace_leave
15417 jmp resume_userspace
15418-END(syscall_exit_work)
15419+ENDPROC(syscall_exit_work)
15420 CFI_ENDPROC
15421
15422 RING0_INT_FRAME # can't unwind into user space anyway
15423 syscall_fault:
15424+#ifdef CONFIG_PAX_MEMORY_UDEREF
15425+ push %ss
15426+ pop %ds
15427+#endif
15428 GET_THREAD_INFO(%ebp)
15429 movl $-EFAULT,PT_EAX(%esp)
15430 jmp resume_userspace
15431-END(syscall_fault)
15432+ENDPROC(syscall_fault)
15433
15434 syscall_badsys:
15435 movl $-ENOSYS,PT_EAX(%esp)
15436 jmp resume_userspace
15437-END(syscall_badsys)
15438+ENDPROC(syscall_badsys)
15439 CFI_ENDPROC
15440 /*
15441 * End of kprobes section
15442@@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
15443 CFI_ENDPROC
15444 ENDPROC(ptregs_clone)
15445
15446+ ALIGN;
15447+ENTRY(kernel_execve)
15448+ CFI_STARTPROC
15449+ pushl_cfi %ebp
15450+ sub $PT_OLDSS+4,%esp
15451+ pushl_cfi %edi
15452+ pushl_cfi %ecx
15453+ pushl_cfi %eax
15454+ lea 3*4(%esp),%edi
15455+ mov $PT_OLDSS/4+1,%ecx
15456+ xorl %eax,%eax
15457+ rep stosl
15458+ popl_cfi %eax
15459+ popl_cfi %ecx
15460+ popl_cfi %edi
15461+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15462+ pushl_cfi %esp
15463+ call sys_execve
15464+ add $4,%esp
15465+ CFI_ADJUST_CFA_OFFSET -4
15466+ GET_THREAD_INFO(%ebp)
15467+ test %eax,%eax
15468+ jz syscall_exit
15469+ add $PT_OLDSS+4,%esp
15470+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15471+ popl_cfi %ebp
15472+ ret
15473+ CFI_ENDPROC
15474+ENDPROC(kernel_execve)
15475+
15476 .macro FIXUP_ESPFIX_STACK
15477 /*
15478 * Switch back for ESPFIX stack to the normal zerobased stack
15479@@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
15480 * normal stack and adjusts ESP with the matching offset.
15481 */
15482 /* fixup the stack */
15483- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15484- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15485+#ifdef CONFIG_SMP
15486+ movl PER_CPU_VAR(cpu_number), %ebx
15487+ shll $PAGE_SHIFT_asm, %ebx
15488+ addl $cpu_gdt_table, %ebx
15489+#else
15490+ movl $cpu_gdt_table, %ebx
15491+#endif
15492+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15493+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15494 shl $16, %eax
15495 addl %esp, %eax /* the adjusted stack pointer */
15496 pushl_cfi $__KERNEL_DS
15497@@ -819,7 +1066,7 @@ vector=vector+1
15498 .endr
15499 2: jmp common_interrupt
15500 .endr
15501-END(irq_entries_start)
15502+ENDPROC(irq_entries_start)
15503
15504 .previous
15505 END(interrupt)
15506@@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
15507 pushl_cfi $do_coprocessor_error
15508 jmp error_code
15509 CFI_ENDPROC
15510-END(coprocessor_error)
15511+ENDPROC(coprocessor_error)
15512
15513 ENTRY(simd_coprocessor_error)
15514 RING0_INT_FRAME
15515@@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
15516 #endif
15517 jmp error_code
15518 CFI_ENDPROC
15519-END(simd_coprocessor_error)
15520+ENDPROC(simd_coprocessor_error)
15521
15522 ENTRY(device_not_available)
15523 RING0_INT_FRAME
15524@@ -896,7 +1143,7 @@ ENTRY(device_not_available)
15525 pushl_cfi $do_device_not_available
15526 jmp error_code
15527 CFI_ENDPROC
15528-END(device_not_available)
15529+ENDPROC(device_not_available)
15530
15531 #ifdef CONFIG_PARAVIRT
15532 ENTRY(native_iret)
15533@@ -905,12 +1152,12 @@ ENTRY(native_iret)
15534 .align 4
15535 .long native_iret, iret_exc
15536 .previous
15537-END(native_iret)
15538+ENDPROC(native_iret)
15539
15540 ENTRY(native_irq_enable_sysexit)
15541 sti
15542 sysexit
15543-END(native_irq_enable_sysexit)
15544+ENDPROC(native_irq_enable_sysexit)
15545 #endif
15546
15547 ENTRY(overflow)
15548@@ -919,7 +1166,7 @@ ENTRY(overflow)
15549 pushl_cfi $do_overflow
15550 jmp error_code
15551 CFI_ENDPROC
15552-END(overflow)
15553+ENDPROC(overflow)
15554
15555 ENTRY(bounds)
15556 RING0_INT_FRAME
15557@@ -927,7 +1174,7 @@ ENTRY(bounds)
15558 pushl_cfi $do_bounds
15559 jmp error_code
15560 CFI_ENDPROC
15561-END(bounds)
15562+ENDPROC(bounds)
15563
15564 ENTRY(invalid_op)
15565 RING0_INT_FRAME
15566@@ -935,7 +1182,7 @@ ENTRY(invalid_op)
15567 pushl_cfi $do_invalid_op
15568 jmp error_code
15569 CFI_ENDPROC
15570-END(invalid_op)
15571+ENDPROC(invalid_op)
15572
15573 ENTRY(coprocessor_segment_overrun)
15574 RING0_INT_FRAME
15575@@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
15576 pushl_cfi $do_coprocessor_segment_overrun
15577 jmp error_code
15578 CFI_ENDPROC
15579-END(coprocessor_segment_overrun)
15580+ENDPROC(coprocessor_segment_overrun)
15581
15582 ENTRY(invalid_TSS)
15583 RING0_EC_FRAME
15584 pushl_cfi $do_invalid_TSS
15585 jmp error_code
15586 CFI_ENDPROC
15587-END(invalid_TSS)
15588+ENDPROC(invalid_TSS)
15589
15590 ENTRY(segment_not_present)
15591 RING0_EC_FRAME
15592 pushl_cfi $do_segment_not_present
15593 jmp error_code
15594 CFI_ENDPROC
15595-END(segment_not_present)
15596+ENDPROC(segment_not_present)
15597
15598 ENTRY(stack_segment)
15599 RING0_EC_FRAME
15600 pushl_cfi $do_stack_segment
15601 jmp error_code
15602 CFI_ENDPROC
15603-END(stack_segment)
15604+ENDPROC(stack_segment)
15605
15606 ENTRY(alignment_check)
15607 RING0_EC_FRAME
15608 pushl_cfi $do_alignment_check
15609 jmp error_code
15610 CFI_ENDPROC
15611-END(alignment_check)
15612+ENDPROC(alignment_check)
15613
15614 ENTRY(divide_error)
15615 RING0_INT_FRAME
15616@@ -979,7 +1226,7 @@ ENTRY(divide_error)
15617 pushl_cfi $do_divide_error
15618 jmp error_code
15619 CFI_ENDPROC
15620-END(divide_error)
15621+ENDPROC(divide_error)
15622
15623 #ifdef CONFIG_X86_MCE
15624 ENTRY(machine_check)
15625@@ -988,7 +1235,7 @@ ENTRY(machine_check)
15626 pushl_cfi machine_check_vector
15627 jmp error_code
15628 CFI_ENDPROC
15629-END(machine_check)
15630+ENDPROC(machine_check)
15631 #endif
15632
15633 ENTRY(spurious_interrupt_bug)
15634@@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15635 pushl_cfi $do_spurious_interrupt_bug
15636 jmp error_code
15637 CFI_ENDPROC
15638-END(spurious_interrupt_bug)
15639+ENDPROC(spurious_interrupt_bug)
15640 /*
15641 * End of kprobes section
15642 */
15643@@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15644
15645 ENTRY(mcount)
15646 ret
15647-END(mcount)
15648+ENDPROC(mcount)
15649
15650 ENTRY(ftrace_caller)
15651 cmpl $0, function_trace_stop
15652@@ -1141,7 +1388,7 @@ ftrace_graph_call:
15653 .globl ftrace_stub
15654 ftrace_stub:
15655 ret
15656-END(ftrace_caller)
15657+ENDPROC(ftrace_caller)
15658
15659 #else /* ! CONFIG_DYNAMIC_FTRACE */
15660
15661@@ -1177,7 +1424,7 @@ trace:
15662 popl %ecx
15663 popl %eax
15664 jmp ftrace_stub
15665-END(mcount)
15666+ENDPROC(mcount)
15667 #endif /* CONFIG_DYNAMIC_FTRACE */
15668 #endif /* CONFIG_FUNCTION_TRACER */
15669
15670@@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15671 popl %ecx
15672 popl %eax
15673 ret
15674-END(ftrace_graph_caller)
15675+ENDPROC(ftrace_graph_caller)
15676
15677 .globl return_to_handler
15678 return_to_handler:
15679@@ -1253,15 +1500,18 @@ error_code:
15680 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15681 REG_TO_PTGS %ecx
15682 SET_KERNEL_GS %ecx
15683- movl $(__USER_DS), %ecx
15684+ movl $(__KERNEL_DS), %ecx
15685 movl %ecx, %ds
15686 movl %ecx, %es
15687+
15688+ pax_enter_kernel
15689+
15690 TRACE_IRQS_OFF
15691 movl %esp,%eax # pt_regs pointer
15692 call *%edi
15693 jmp ret_from_exception
15694 CFI_ENDPROC
15695-END(page_fault)
15696+ENDPROC(page_fault)
15697
15698 /*
15699 * Debug traps and NMI can happen at the one SYSENTER instruction
15700@@ -1303,7 +1553,7 @@ debug_stack_correct:
15701 call do_debug
15702 jmp ret_from_exception
15703 CFI_ENDPROC
15704-END(debug)
15705+ENDPROC(debug)
15706
15707 /*
15708 * NMI is doubly nasty. It can happen _while_ we're handling
15709@@ -1340,6 +1590,9 @@ nmi_stack_correct:
15710 xorl %edx,%edx # zero error code
15711 movl %esp,%eax # pt_regs pointer
15712 call do_nmi
15713+
15714+ pax_exit_kernel
15715+
15716 jmp restore_all_notrace
15717 CFI_ENDPROC
15718
15719@@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15720 FIXUP_ESPFIX_STACK # %eax == %esp
15721 xorl %edx,%edx # zero error code
15722 call do_nmi
15723+
15724+ pax_exit_kernel
15725+
15726 RESTORE_REGS
15727 lss 12+4(%esp), %esp # back to espfix stack
15728 CFI_ADJUST_CFA_OFFSET -24
15729 jmp irq_return
15730 CFI_ENDPROC
15731-END(nmi)
15732+ENDPROC(nmi)
15733
15734 ENTRY(int3)
15735 RING0_INT_FRAME
15736@@ -1393,14 +1649,14 @@ ENTRY(int3)
15737 call do_int3
15738 jmp ret_from_exception
15739 CFI_ENDPROC
15740-END(int3)
15741+ENDPROC(int3)
15742
15743 ENTRY(general_protection)
15744 RING0_EC_FRAME
15745 pushl_cfi $do_general_protection
15746 jmp error_code
15747 CFI_ENDPROC
15748-END(general_protection)
15749+ENDPROC(general_protection)
15750
15751 #ifdef CONFIG_KVM_GUEST
15752 ENTRY(async_page_fault)
15753@@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15754 pushl_cfi $do_async_page_fault
15755 jmp error_code
15756 CFI_ENDPROC
15757-END(async_page_fault)
15758+ENDPROC(async_page_fault)
15759 #endif
15760
15761 /*
15762diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15763index cdc79b5..4710a75 100644
15764--- a/arch/x86/kernel/entry_64.S
15765+++ b/arch/x86/kernel/entry_64.S
15766@@ -56,6 +56,8 @@
15767 #include <asm/ftrace.h>
15768 #include <asm/percpu.h>
15769 #include <linux/err.h>
15770+#include <asm/pgtable.h>
15771+#include <asm/alternative-asm.h>
15772
15773 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15774 #include <linux/elf-em.h>
15775@@ -69,8 +71,9 @@
15776 #ifdef CONFIG_FUNCTION_TRACER
15777 #ifdef CONFIG_DYNAMIC_FTRACE
15778 ENTRY(mcount)
15779+ pax_force_retaddr
15780 retq
15781-END(mcount)
15782+ENDPROC(mcount)
15783
15784 ENTRY(ftrace_caller)
15785 cmpl $0, function_trace_stop
15786@@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15787 #endif
15788
15789 GLOBAL(ftrace_stub)
15790+ pax_force_retaddr
15791 retq
15792-END(ftrace_caller)
15793+ENDPROC(ftrace_caller)
15794
15795 #else /* ! CONFIG_DYNAMIC_FTRACE */
15796 ENTRY(mcount)
15797@@ -113,6 +117,7 @@ ENTRY(mcount)
15798 #endif
15799
15800 GLOBAL(ftrace_stub)
15801+ pax_force_retaddr
15802 retq
15803
15804 trace:
15805@@ -122,12 +127,13 @@ trace:
15806 movq 8(%rbp), %rsi
15807 subq $MCOUNT_INSN_SIZE, %rdi
15808
15809+ pax_force_fptr ftrace_trace_function
15810 call *ftrace_trace_function
15811
15812 MCOUNT_RESTORE_FRAME
15813
15814 jmp ftrace_stub
15815-END(mcount)
15816+ENDPROC(mcount)
15817 #endif /* CONFIG_DYNAMIC_FTRACE */
15818 #endif /* CONFIG_FUNCTION_TRACER */
15819
15820@@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15821
15822 MCOUNT_RESTORE_FRAME
15823
15824+ pax_force_retaddr
15825 retq
15826-END(ftrace_graph_caller)
15827+ENDPROC(ftrace_graph_caller)
15828
15829 GLOBAL(return_to_handler)
15830 subq $24, %rsp
15831@@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15832 movq 8(%rsp), %rdx
15833 movq (%rsp), %rax
15834 addq $24, %rsp
15835+ pax_force_fptr %rdi
15836 jmp *%rdi
15837 #endif
15838
15839@@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15840 ENDPROC(native_usergs_sysret64)
15841 #endif /* CONFIG_PARAVIRT */
15842
15843+ .macro ljmpq sel, off
15844+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15845+ .byte 0x48; ljmp *1234f(%rip)
15846+ .pushsection .rodata
15847+ .align 16
15848+ 1234: .quad \off; .word \sel
15849+ .popsection
15850+#else
15851+ pushq $\sel
15852+ pushq $\off
15853+ lretq
15854+#endif
15855+ .endm
15856+
15857+ .macro pax_enter_kernel
15858+ pax_set_fptr_mask
15859+#ifdef CONFIG_PAX_KERNEXEC
15860+ call pax_enter_kernel
15861+#endif
15862+ .endm
15863+
15864+ .macro pax_exit_kernel
15865+#ifdef CONFIG_PAX_KERNEXEC
15866+ call pax_exit_kernel
15867+#endif
15868+ .endm
15869+
15870+#ifdef CONFIG_PAX_KERNEXEC
15871+ENTRY(pax_enter_kernel)
15872+ pushq %rdi
15873+
15874+#ifdef CONFIG_PARAVIRT
15875+ PV_SAVE_REGS(CLBR_RDI)
15876+#endif
15877+
15878+ GET_CR0_INTO_RDI
15879+ bts $16,%rdi
15880+ jnc 3f
15881+ mov %cs,%edi
15882+ cmp $__KERNEL_CS,%edi
15883+ jnz 2f
15884+1:
15885+
15886+#ifdef CONFIG_PARAVIRT
15887+ PV_RESTORE_REGS(CLBR_RDI)
15888+#endif
15889+
15890+ popq %rdi
15891+ pax_force_retaddr
15892+ retq
15893+
15894+2: ljmpq __KERNEL_CS,1f
15895+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15896+4: SET_RDI_INTO_CR0
15897+ jmp 1b
15898+ENDPROC(pax_enter_kernel)
15899+
15900+ENTRY(pax_exit_kernel)
15901+ pushq %rdi
15902+
15903+#ifdef CONFIG_PARAVIRT
15904+ PV_SAVE_REGS(CLBR_RDI)
15905+#endif
15906+
15907+ mov %cs,%rdi
15908+ cmp $__KERNEXEC_KERNEL_CS,%edi
15909+ jz 2f
15910+1:
15911+
15912+#ifdef CONFIG_PARAVIRT
15913+ PV_RESTORE_REGS(CLBR_RDI);
15914+#endif
15915+
15916+ popq %rdi
15917+ pax_force_retaddr
15918+ retq
15919+
15920+2: GET_CR0_INTO_RDI
15921+ btr $16,%rdi
15922+ ljmpq __KERNEL_CS,3f
15923+3: SET_RDI_INTO_CR0
15924+ jmp 1b
15925+#ifdef CONFIG_PARAVIRT
15926+ PV_RESTORE_REGS(CLBR_RDI);
15927+#endif
15928+
15929+ popq %rdi
15930+ pax_force_retaddr
15931+ retq
15932+ENDPROC(pax_exit_kernel)
15933+#endif
15934+
15935+ .macro pax_enter_kernel_user
15936+ pax_set_fptr_mask
15937+#ifdef CONFIG_PAX_MEMORY_UDEREF
15938+ call pax_enter_kernel_user
15939+#endif
15940+ .endm
15941+
15942+ .macro pax_exit_kernel_user
15943+#ifdef CONFIG_PAX_MEMORY_UDEREF
15944+ call pax_exit_kernel_user
15945+#endif
15946+#ifdef CONFIG_PAX_RANDKSTACK
15947+ pushq %rax
15948+ call pax_randomize_kstack
15949+ popq %rax
15950+#endif
15951+ .endm
15952+
15953+#ifdef CONFIG_PAX_MEMORY_UDEREF
15954+ENTRY(pax_enter_kernel_user)
15955+ pushq %rdi
15956+ pushq %rbx
15957+
15958+#ifdef CONFIG_PARAVIRT
15959+ PV_SAVE_REGS(CLBR_RDI)
15960+#endif
15961+
15962+ GET_CR3_INTO_RDI
15963+ mov %rdi,%rbx
15964+ add $__START_KERNEL_map,%rbx
15965+ sub phys_base(%rip),%rbx
15966+
15967+#ifdef CONFIG_PARAVIRT
15968+ pushq %rdi
15969+ cmpl $0, pv_info+PARAVIRT_enabled
15970+ jz 1f
15971+ i = 0
15972+ .rept USER_PGD_PTRS
15973+ mov i*8(%rbx),%rsi
15974+ mov $0,%sil
15975+ lea i*8(%rbx),%rdi
15976+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15977+ i = i + 1
15978+ .endr
15979+ jmp 2f
15980+1:
15981+#endif
15982+
15983+ i = 0
15984+ .rept USER_PGD_PTRS
15985+ movb $0,i*8(%rbx)
15986+ i = i + 1
15987+ .endr
15988+
15989+#ifdef CONFIG_PARAVIRT
15990+2: popq %rdi
15991+#endif
15992+ SET_RDI_INTO_CR3
15993+
15994+#ifdef CONFIG_PAX_KERNEXEC
15995+ GET_CR0_INTO_RDI
15996+ bts $16,%rdi
15997+ SET_RDI_INTO_CR0
15998+#endif
15999+
16000+#ifdef CONFIG_PARAVIRT
16001+ PV_RESTORE_REGS(CLBR_RDI)
16002+#endif
16003+
16004+ popq %rbx
16005+ popq %rdi
16006+ pax_force_retaddr
16007+ retq
16008+ENDPROC(pax_enter_kernel_user)
16009+
16010+ENTRY(pax_exit_kernel_user)
16011+ push %rdi
16012+
16013+#ifdef CONFIG_PARAVIRT
16014+ pushq %rbx
16015+ PV_SAVE_REGS(CLBR_RDI)
16016+#endif
16017+
16018+#ifdef CONFIG_PAX_KERNEXEC
16019+ GET_CR0_INTO_RDI
16020+ btr $16,%rdi
16021+ SET_RDI_INTO_CR0
16022+#endif
16023+
16024+ GET_CR3_INTO_RDI
16025+ add $__START_KERNEL_map,%rdi
16026+ sub phys_base(%rip),%rdi
16027+
16028+#ifdef CONFIG_PARAVIRT
16029+ cmpl $0, pv_info+PARAVIRT_enabled
16030+ jz 1f
16031+ mov %rdi,%rbx
16032+ i = 0
16033+ .rept USER_PGD_PTRS
16034+ mov i*8(%rbx),%rsi
16035+ mov $0x67,%sil
16036+ lea i*8(%rbx),%rdi
16037+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16038+ i = i + 1
16039+ .endr
16040+ jmp 2f
16041+1:
16042+#endif
16043+
16044+ i = 0
16045+ .rept USER_PGD_PTRS
16046+ movb $0x67,i*8(%rdi)
16047+ i = i + 1
16048+ .endr
16049+
16050+#ifdef CONFIG_PARAVIRT
16051+2: PV_RESTORE_REGS(CLBR_RDI)
16052+ popq %rbx
16053+#endif
16054+
16055+ popq %rdi
16056+ pax_force_retaddr
16057+ retq
16058+ENDPROC(pax_exit_kernel_user)
16059+#endif
16060+
16061+.macro pax_erase_kstack
16062+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16063+ call pax_erase_kstack
16064+#endif
16065+.endm
16066+
16067+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16068+/*
16069+ * r11: thread_info
16070+ * rcx, rdx: can be clobbered
16071+ */
16072+ENTRY(pax_erase_kstack)
16073+ pushq %rdi
16074+ pushq %rax
16075+ pushq %r11
16076+
16077+ GET_THREAD_INFO(%r11)
16078+ mov TI_lowest_stack(%r11), %rdi
16079+ mov $-0xBEEF, %rax
16080+ std
16081+
16082+1: mov %edi, %ecx
16083+ and $THREAD_SIZE_asm - 1, %ecx
16084+ shr $3, %ecx
16085+ repne scasq
16086+ jecxz 2f
16087+
16088+ cmp $2*8, %ecx
16089+ jc 2f
16090+
16091+ mov $2*8, %ecx
16092+ repe scasq
16093+ jecxz 2f
16094+ jne 1b
16095+
16096+2: cld
16097+ mov %esp, %ecx
16098+ sub %edi, %ecx
16099+
16100+ cmp $THREAD_SIZE_asm, %rcx
16101+ jb 3f
16102+ ud2
16103+3:
16104+
16105+ shr $3, %ecx
16106+ rep stosq
16107+
16108+ mov TI_task_thread_sp0(%r11), %rdi
16109+ sub $256, %rdi
16110+ mov %rdi, TI_lowest_stack(%r11)
16111+
16112+ popq %r11
16113+ popq %rax
16114+ popq %rdi
16115+ pax_force_retaddr
16116+ ret
16117+ENDPROC(pax_erase_kstack)
16118+#endif
16119
16120 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16121 #ifdef CONFIG_TRACE_IRQFLAGS
16122@@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
16123 .endm
16124
16125 .macro UNFAKE_STACK_FRAME
16126- addq $8*6, %rsp
16127- CFI_ADJUST_CFA_OFFSET -(6*8)
16128+ addq $8*6 + ARG_SKIP, %rsp
16129+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16130 .endm
16131
16132 /*
16133@@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
16134 movq %rsp, %rsi
16135
16136 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16137- testl $3, CS-RBP(%rsi)
16138+ testb $3, CS-RBP(%rsi)
16139 je 1f
16140 SWAPGS
16141 /*
16142@@ -355,9 +639,10 @@ ENTRY(save_rest)
16143 movq_cfi r15, R15+16
16144 movq %r11, 8(%rsp) /* return address */
16145 FIXUP_TOP_OF_STACK %r11, 16
16146+ pax_force_retaddr
16147 ret
16148 CFI_ENDPROC
16149-END(save_rest)
16150+ENDPROC(save_rest)
16151
16152 /* save complete stack frame */
16153 .pushsection .kprobes.text, "ax"
16154@@ -386,9 +671,10 @@ ENTRY(save_paranoid)
16155 js 1f /* negative -> in kernel */
16156 SWAPGS
16157 xorl %ebx,%ebx
16158-1: ret
16159+1: pax_force_retaddr_bts
16160+ ret
16161 CFI_ENDPROC
16162-END(save_paranoid)
16163+ENDPROC(save_paranoid)
16164 .popsection
16165
16166 /*
16167@@ -410,7 +696,7 @@ ENTRY(ret_from_fork)
16168
16169 RESTORE_REST
16170
16171- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16172+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16173 jz retint_restore_args
16174
16175 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16176@@ -420,7 +706,7 @@ ENTRY(ret_from_fork)
16177 jmp ret_from_sys_call # go to the SYSRET fastpath
16178
16179 CFI_ENDPROC
16180-END(ret_from_fork)
16181+ENDPROC(ret_from_fork)
16182
16183 /*
16184 * System call entry. Up to 6 arguments in registers are supported.
16185@@ -456,7 +742,7 @@ END(ret_from_fork)
16186 ENTRY(system_call)
16187 CFI_STARTPROC simple
16188 CFI_SIGNAL_FRAME
16189- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16190+ CFI_DEF_CFA rsp,0
16191 CFI_REGISTER rip,rcx
16192 /*CFI_REGISTER rflags,r11*/
16193 SWAPGS_UNSAFE_STACK
16194@@ -469,16 +755,18 @@ GLOBAL(system_call_after_swapgs)
16195
16196 movq %rsp,PER_CPU_VAR(old_rsp)
16197 movq PER_CPU_VAR(kernel_stack),%rsp
16198+ SAVE_ARGS 8*6,0
16199+ pax_enter_kernel_user
16200 /*
16201 * No need to follow this irqs off/on section - it's straight
16202 * and short:
16203 */
16204 ENABLE_INTERRUPTS(CLBR_NONE)
16205- SAVE_ARGS 8,0
16206 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16207 movq %rcx,RIP-ARGOFFSET(%rsp)
16208 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16209- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16210+ GET_THREAD_INFO(%rcx)
16211+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16212 jnz tracesys
16213 system_call_fastpath:
16214 #if __SYSCALL_MASK == ~0
16215@@ -488,7 +776,7 @@ system_call_fastpath:
16216 cmpl $__NR_syscall_max,%eax
16217 #endif
16218 ja badsys
16219- movq %r10,%rcx
16220+ movq R10-ARGOFFSET(%rsp),%rcx
16221 call *sys_call_table(,%rax,8) # XXX: rip relative
16222 movq %rax,RAX-ARGOFFSET(%rsp)
16223 /*
16224@@ -502,10 +790,13 @@ sysret_check:
16225 LOCKDEP_SYS_EXIT
16226 DISABLE_INTERRUPTS(CLBR_NONE)
16227 TRACE_IRQS_OFF
16228- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16229+ GET_THREAD_INFO(%rcx)
16230+ movl TI_flags(%rcx),%edx
16231 andl %edi,%edx
16232 jnz sysret_careful
16233 CFI_REMEMBER_STATE
16234+ pax_exit_kernel_user
16235+ pax_erase_kstack
16236 /*
16237 * sysretq will re-enable interrupts:
16238 */
16239@@ -557,14 +848,18 @@ badsys:
16240 * jump back to the normal fast path.
16241 */
16242 auditsys:
16243- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16244+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16245 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16246 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16247 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16248 movq %rax,%rsi /* 2nd arg: syscall number */
16249 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16250 call __audit_syscall_entry
16251+
16252+ pax_erase_kstack
16253+
16254 LOAD_ARGS 0 /* reload call-clobbered registers */
16255+ pax_set_fptr_mask
16256 jmp system_call_fastpath
16257
16258 /*
16259@@ -585,7 +880,7 @@ sysret_audit:
16260 /* Do syscall tracing */
16261 tracesys:
16262 #ifdef CONFIG_AUDITSYSCALL
16263- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16264+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16265 jz auditsys
16266 #endif
16267 SAVE_REST
16268@@ -593,12 +888,16 @@ tracesys:
16269 FIXUP_TOP_OF_STACK %rdi
16270 movq %rsp,%rdi
16271 call syscall_trace_enter
16272+
16273+ pax_erase_kstack
16274+
16275 /*
16276 * Reload arg registers from stack in case ptrace changed them.
16277 * We don't reload %rax because syscall_trace_enter() returned
16278 * the value it wants us to use in the table lookup.
16279 */
16280 LOAD_ARGS ARGOFFSET, 1
16281+ pax_set_fptr_mask
16282 RESTORE_REST
16283 #if __SYSCALL_MASK == ~0
16284 cmpq $__NR_syscall_max,%rax
16285@@ -607,7 +906,7 @@ tracesys:
16286 cmpl $__NR_syscall_max,%eax
16287 #endif
16288 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16289- movq %r10,%rcx /* fixup for C */
16290+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16291 call *sys_call_table(,%rax,8)
16292 movq %rax,RAX-ARGOFFSET(%rsp)
16293 /* Use IRET because user could have changed frame */
16294@@ -628,6 +927,7 @@ GLOBAL(int_with_check)
16295 andl %edi,%edx
16296 jnz int_careful
16297 andl $~TS_COMPAT,TI_status(%rcx)
16298+ pax_erase_kstack
16299 jmp retint_swapgs
16300
16301 /* Either reschedule or signal or syscall exit tracking needed. */
16302@@ -674,7 +974,7 @@ int_restore_rest:
16303 TRACE_IRQS_OFF
16304 jmp int_with_check
16305 CFI_ENDPROC
16306-END(system_call)
16307+ENDPROC(system_call)
16308
16309 /*
16310 * Certain special system calls that need to save a complete full stack frame.
16311@@ -690,7 +990,7 @@ ENTRY(\label)
16312 call \func
16313 jmp ptregscall_common
16314 CFI_ENDPROC
16315-END(\label)
16316+ENDPROC(\label)
16317 .endm
16318
16319 PTREGSCALL stub_clone, sys_clone, %r8
16320@@ -708,9 +1008,10 @@ ENTRY(ptregscall_common)
16321 movq_cfi_restore R12+8, r12
16322 movq_cfi_restore RBP+8, rbp
16323 movq_cfi_restore RBX+8, rbx
16324+ pax_force_retaddr
16325 ret $REST_SKIP /* pop extended registers */
16326 CFI_ENDPROC
16327-END(ptregscall_common)
16328+ENDPROC(ptregscall_common)
16329
16330 ENTRY(stub_execve)
16331 CFI_STARTPROC
16332@@ -725,7 +1026,7 @@ ENTRY(stub_execve)
16333 RESTORE_REST
16334 jmp int_ret_from_sys_call
16335 CFI_ENDPROC
16336-END(stub_execve)
16337+ENDPROC(stub_execve)
16338
16339 /*
16340 * sigreturn is special because it needs to restore all registers on return.
16341@@ -743,7 +1044,7 @@ ENTRY(stub_rt_sigreturn)
16342 RESTORE_REST
16343 jmp int_ret_from_sys_call
16344 CFI_ENDPROC
16345-END(stub_rt_sigreturn)
16346+ENDPROC(stub_rt_sigreturn)
16347
16348 #ifdef CONFIG_X86_X32_ABI
16349 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16350@@ -812,7 +1113,7 @@ vector=vector+1
16351 2: jmp common_interrupt
16352 .endr
16353 CFI_ENDPROC
16354-END(irq_entries_start)
16355+ENDPROC(irq_entries_start)
16356
16357 .previous
16358 END(interrupt)
16359@@ -832,6 +1133,16 @@ END(interrupt)
16360 subq $ORIG_RAX-RBP, %rsp
16361 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16362 SAVE_ARGS_IRQ
16363+#ifdef CONFIG_PAX_MEMORY_UDEREF
16364+ testb $3, CS(%rdi)
16365+ jnz 1f
16366+ pax_enter_kernel
16367+ jmp 2f
16368+1: pax_enter_kernel_user
16369+2:
16370+#else
16371+ pax_enter_kernel
16372+#endif
16373 call \func
16374 .endm
16375
16376@@ -863,7 +1174,7 @@ ret_from_intr:
16377
16378 exit_intr:
16379 GET_THREAD_INFO(%rcx)
16380- testl $3,CS-ARGOFFSET(%rsp)
16381+ testb $3,CS-ARGOFFSET(%rsp)
16382 je retint_kernel
16383
16384 /* Interrupt came from user space */
16385@@ -885,12 +1196,15 @@ retint_swapgs: /* return to user-space */
16386 * The iretq could re-enable interrupts:
16387 */
16388 DISABLE_INTERRUPTS(CLBR_ANY)
16389+ pax_exit_kernel_user
16390 TRACE_IRQS_IRETQ
16391 SWAPGS
16392 jmp restore_args
16393
16394 retint_restore_args: /* return to kernel space */
16395 DISABLE_INTERRUPTS(CLBR_ANY)
16396+ pax_exit_kernel
16397+ pax_force_retaddr RIP-ARGOFFSET
16398 /*
16399 * The iretq could re-enable interrupts:
16400 */
16401@@ -979,7 +1293,7 @@ ENTRY(retint_kernel)
16402 #endif
16403
16404 CFI_ENDPROC
16405-END(common_interrupt)
16406+ENDPROC(common_interrupt)
16407 /*
16408 * End of kprobes section
16409 */
16410@@ -996,7 +1310,7 @@ ENTRY(\sym)
16411 interrupt \do_sym
16412 jmp ret_from_intr
16413 CFI_ENDPROC
16414-END(\sym)
16415+ENDPROC(\sym)
16416 .endm
16417
16418 #ifdef CONFIG_SMP
16419@@ -1069,12 +1383,22 @@ ENTRY(\sym)
16420 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16421 call error_entry
16422 DEFAULT_FRAME 0
16423+#ifdef CONFIG_PAX_MEMORY_UDEREF
16424+ testb $3, CS(%rsp)
16425+ jnz 1f
16426+ pax_enter_kernel
16427+ jmp 2f
16428+1: pax_enter_kernel_user
16429+2:
16430+#else
16431+ pax_enter_kernel
16432+#endif
16433 movq %rsp,%rdi /* pt_regs pointer */
16434 xorl %esi,%esi /* no error code */
16435 call \do_sym
16436 jmp error_exit /* %ebx: no swapgs flag */
16437 CFI_ENDPROC
16438-END(\sym)
16439+ENDPROC(\sym)
16440 .endm
16441
16442 .macro paranoidzeroentry sym do_sym
16443@@ -1086,15 +1410,25 @@ ENTRY(\sym)
16444 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16445 call save_paranoid
16446 TRACE_IRQS_OFF
16447+#ifdef CONFIG_PAX_MEMORY_UDEREF
16448+ testb $3, CS(%rsp)
16449+ jnz 1f
16450+ pax_enter_kernel
16451+ jmp 2f
16452+1: pax_enter_kernel_user
16453+2:
16454+#else
16455+ pax_enter_kernel
16456+#endif
16457 movq %rsp,%rdi /* pt_regs pointer */
16458 xorl %esi,%esi /* no error code */
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-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16467+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16468 .macro paranoidzeroentry_ist sym do_sym ist
16469 ENTRY(\sym)
16470 INTR_FRAME
16471@@ -1104,14 +1438,30 @@ ENTRY(\sym)
16472 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16473 call save_paranoid
16474 TRACE_IRQS_OFF
16475+#ifdef CONFIG_PAX_MEMORY_UDEREF
16476+ testb $3, CS(%rsp)
16477+ jnz 1f
16478+ pax_enter_kernel
16479+ jmp 2f
16480+1: pax_enter_kernel_user
16481+2:
16482+#else
16483+ pax_enter_kernel
16484+#endif
16485 movq %rsp,%rdi /* pt_regs pointer */
16486 xorl %esi,%esi /* no error code */
16487+#ifdef CONFIG_SMP
16488+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16489+ lea init_tss(%r12), %r12
16490+#else
16491+ lea init_tss(%rip), %r12
16492+#endif
16493 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16494 call \do_sym
16495 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16496 jmp paranoid_exit /* %ebx: no swapgs flag */
16497 CFI_ENDPROC
16498-END(\sym)
16499+ENDPROC(\sym)
16500 .endm
16501
16502 .macro errorentry sym do_sym
16503@@ -1122,13 +1472,23 @@ ENTRY(\sym)
16504 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16505 call error_entry
16506 DEFAULT_FRAME 0
16507+#ifdef CONFIG_PAX_MEMORY_UDEREF
16508+ testb $3, CS(%rsp)
16509+ jnz 1f
16510+ pax_enter_kernel
16511+ jmp 2f
16512+1: pax_enter_kernel_user
16513+2:
16514+#else
16515+ pax_enter_kernel
16516+#endif
16517 movq %rsp,%rdi /* pt_regs pointer */
16518 movq ORIG_RAX(%rsp),%rsi /* get error code */
16519 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16520 call \do_sym
16521 jmp error_exit /* %ebx: no swapgs flag */
16522 CFI_ENDPROC
16523-END(\sym)
16524+ENDPROC(\sym)
16525 .endm
16526
16527 /* error code is on the stack already */
16528@@ -1141,13 +1501,23 @@ ENTRY(\sym)
16529 call save_paranoid
16530 DEFAULT_FRAME 0
16531 TRACE_IRQS_OFF
16532+#ifdef CONFIG_PAX_MEMORY_UDEREF
16533+ testb $3, CS(%rsp)
16534+ jnz 1f
16535+ pax_enter_kernel
16536+ jmp 2f
16537+1: pax_enter_kernel_user
16538+2:
16539+#else
16540+ pax_enter_kernel
16541+#endif
16542 movq %rsp,%rdi /* pt_regs pointer */
16543 movq ORIG_RAX(%rsp),%rsi /* get error code */
16544 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16545 call \do_sym
16546 jmp paranoid_exit /* %ebx: no swapgs flag */
16547 CFI_ENDPROC
16548-END(\sym)
16549+ENDPROC(\sym)
16550 .endm
16551
16552 zeroentry divide_error do_divide_error
16553@@ -1177,9 +1547,10 @@ gs_change:
16554 2: mfence /* workaround */
16555 SWAPGS
16556 popfq_cfi
16557+ pax_force_retaddr
16558 ret
16559 CFI_ENDPROC
16560-END(native_load_gs_index)
16561+ENDPROC(native_load_gs_index)
16562
16563 .section __ex_table,"a"
16564 .align 8
16565@@ -1201,13 +1572,14 @@ ENTRY(kernel_thread_helper)
16566 * Here we are in the child and the registers are set as they were
16567 * at kernel_thread() invocation in the parent.
16568 */
16569+ pax_force_fptr %rsi
16570 call *%rsi
16571 # exit
16572 mov %eax, %edi
16573 call do_exit
16574 ud2 # padding for call trace
16575 CFI_ENDPROC
16576-END(kernel_thread_helper)
16577+ENDPROC(kernel_thread_helper)
16578
16579 /*
16580 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16581@@ -1234,11 +1606,11 @@ ENTRY(kernel_execve)
16582 RESTORE_REST
16583 testq %rax,%rax
16584 je int_ret_from_sys_call
16585- RESTORE_ARGS
16586 UNFAKE_STACK_FRAME
16587+ pax_force_retaddr
16588 ret
16589 CFI_ENDPROC
16590-END(kernel_execve)
16591+ENDPROC(kernel_execve)
16592
16593 /* Call softirq on interrupt stack. Interrupts are off. */
16594 ENTRY(call_softirq)
16595@@ -1256,9 +1628,10 @@ ENTRY(call_softirq)
16596 CFI_DEF_CFA_REGISTER rsp
16597 CFI_ADJUST_CFA_OFFSET -8
16598 decl PER_CPU_VAR(irq_count)
16599+ pax_force_retaddr
16600 ret
16601 CFI_ENDPROC
16602-END(call_softirq)
16603+ENDPROC(call_softirq)
16604
16605 #ifdef CONFIG_XEN
16606 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16607@@ -1296,7 +1669,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16608 decl PER_CPU_VAR(irq_count)
16609 jmp error_exit
16610 CFI_ENDPROC
16611-END(xen_do_hypervisor_callback)
16612+ENDPROC(xen_do_hypervisor_callback)
16613
16614 /*
16615 * Hypervisor uses this for application faults while it executes.
16616@@ -1355,7 +1728,7 @@ ENTRY(xen_failsafe_callback)
16617 SAVE_ALL
16618 jmp error_exit
16619 CFI_ENDPROC
16620-END(xen_failsafe_callback)
16621+ENDPROC(xen_failsafe_callback)
16622
16623 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16624 xen_hvm_callback_vector xen_evtchn_do_upcall
16625@@ -1404,16 +1777,31 @@ ENTRY(paranoid_exit)
16626 TRACE_IRQS_OFF
16627 testl %ebx,%ebx /* swapgs needed? */
16628 jnz paranoid_restore
16629- testl $3,CS(%rsp)
16630+ testb $3,CS(%rsp)
16631 jnz paranoid_userspace
16632+#ifdef CONFIG_PAX_MEMORY_UDEREF
16633+ pax_exit_kernel
16634+ TRACE_IRQS_IRETQ 0
16635+ SWAPGS_UNSAFE_STACK
16636+ RESTORE_ALL 8
16637+ pax_force_retaddr_bts
16638+ jmp irq_return
16639+#endif
16640 paranoid_swapgs:
16641+#ifdef CONFIG_PAX_MEMORY_UDEREF
16642+ pax_exit_kernel_user
16643+#else
16644+ pax_exit_kernel
16645+#endif
16646 TRACE_IRQS_IRETQ 0
16647 SWAPGS_UNSAFE_STACK
16648 RESTORE_ALL 8
16649 jmp irq_return
16650 paranoid_restore:
16651+ pax_exit_kernel
16652 TRACE_IRQS_IRETQ 0
16653 RESTORE_ALL 8
16654+ pax_force_retaddr_bts
16655 jmp irq_return
16656 paranoid_userspace:
16657 GET_THREAD_INFO(%rcx)
16658@@ -1442,7 +1830,7 @@ paranoid_schedule:
16659 TRACE_IRQS_OFF
16660 jmp paranoid_userspace
16661 CFI_ENDPROC
16662-END(paranoid_exit)
16663+ENDPROC(paranoid_exit)
16664
16665 /*
16666 * Exception entry point. This expects an error code/orig_rax on the stack.
16667@@ -1469,12 +1857,13 @@ ENTRY(error_entry)
16668 movq_cfi r14, R14+8
16669 movq_cfi r15, R15+8
16670 xorl %ebx,%ebx
16671- testl $3,CS+8(%rsp)
16672+ testb $3,CS+8(%rsp)
16673 je error_kernelspace
16674 error_swapgs:
16675 SWAPGS
16676 error_sti:
16677 TRACE_IRQS_OFF
16678+ pax_force_retaddr_bts
16679 ret
16680
16681 /*
16682@@ -1501,7 +1890,7 @@ bstep_iret:
16683 movq %rcx,RIP+8(%rsp)
16684 jmp error_swapgs
16685 CFI_ENDPROC
16686-END(error_entry)
16687+ENDPROC(error_entry)
16688
16689
16690 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16691@@ -1521,7 +1910,7 @@ ENTRY(error_exit)
16692 jnz retint_careful
16693 jmp retint_swapgs
16694 CFI_ENDPROC
16695-END(error_exit)
16696+ENDPROC(error_exit)
16697
16698 /*
16699 * Test if a given stack is an NMI stack or not.
16700@@ -1579,9 +1968,11 @@ ENTRY(nmi)
16701 * If %cs was not the kernel segment, then the NMI triggered in user
16702 * space, which means it is definitely not nested.
16703 */
16704+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16705+ je 1f
16706 cmpl $__KERNEL_CS, 16(%rsp)
16707 jne first_nmi
16708-
16709+1:
16710 /*
16711 * Check the special variable on the stack to see if NMIs are
16712 * executing.
16713@@ -1728,6 +2119,16 @@ end_repeat_nmi:
16714 */
16715 call save_paranoid
16716 DEFAULT_FRAME 0
16717+#ifdef CONFIG_PAX_MEMORY_UDEREF
16718+ testb $3, CS(%rsp)
16719+ jnz 1f
16720+ pax_enter_kernel
16721+ jmp 2f
16722+1: pax_enter_kernel_user
16723+2:
16724+#else
16725+ pax_enter_kernel
16726+#endif
16727 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16728 movq %rsp,%rdi
16729 movq $-1,%rsi
16730@@ -1735,21 +2136,32 @@ end_repeat_nmi:
16731 testl %ebx,%ebx /* swapgs needed? */
16732 jnz nmi_restore
16733 nmi_swapgs:
16734+#ifdef CONFIG_PAX_MEMORY_UDEREF
16735+ pax_exit_kernel_user
16736+#else
16737+ pax_exit_kernel
16738+#endif
16739 SWAPGS_UNSAFE_STACK
16740+ RESTORE_ALL 8
16741+ /* Clear the NMI executing stack variable */
16742+ movq $0, 10*8(%rsp)
16743+ jmp irq_return
16744 nmi_restore:
16745+ pax_exit_kernel
16746 RESTORE_ALL 8
16747+ pax_force_retaddr_bts
16748 /* Clear the NMI executing stack variable */
16749 movq $0, 10*8(%rsp)
16750 jmp irq_return
16751 CFI_ENDPROC
16752-END(nmi)
16753+ENDPROC(nmi)
16754
16755 ENTRY(ignore_sysret)
16756 CFI_STARTPROC
16757 mov $-ENOSYS,%eax
16758 sysret
16759 CFI_ENDPROC
16760-END(ignore_sysret)
16761+ENDPROC(ignore_sysret)
16762
16763 /*
16764 * End of kprobes section
16765diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16766index c9a281f..ce2f317 100644
16767--- a/arch/x86/kernel/ftrace.c
16768+++ b/arch/x86/kernel/ftrace.c
16769@@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16770 static const void *mod_code_newcode; /* holds the text to write to the IP */
16771
16772 static unsigned nmi_wait_count;
16773-static atomic_t nmi_update_count = ATOMIC_INIT(0);
16774+static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16775
16776 int ftrace_arch_read_dyn_info(char *buf, int size)
16777 {
16778@@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16779
16780 r = snprintf(buf, size, "%u %u",
16781 nmi_wait_count,
16782- atomic_read(&nmi_update_count));
16783+ atomic_read_unchecked(&nmi_update_count));
16784 return r;
16785 }
16786
16787@@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16788
16789 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16790 smp_rmb();
16791+ pax_open_kernel();
16792 ftrace_mod_code();
16793- atomic_inc(&nmi_update_count);
16794+ pax_close_kernel();
16795+ atomic_inc_unchecked(&nmi_update_count);
16796 }
16797 /* Must have previous changes seen before executions */
16798 smp_mb();
16799@@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16800 {
16801 unsigned char replaced[MCOUNT_INSN_SIZE];
16802
16803+ ip = ktla_ktva(ip);
16804+
16805 /*
16806 * Note: Due to modules and __init, code can
16807 * disappear and change, we need to protect against faulting
16808@@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16809 unsigned char old[MCOUNT_INSN_SIZE], *new;
16810 int ret;
16811
16812- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16813+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16814 new = ftrace_call_replace(ip, (unsigned long)func);
16815 ret = ftrace_modify_code(ip, old, new);
16816
16817@@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16818 {
16819 unsigned char code[MCOUNT_INSN_SIZE];
16820
16821+ ip = ktla_ktva(ip);
16822+
16823 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16824 return -EFAULT;
16825
16826diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16827index 51ff186..9e77418 100644
16828--- a/arch/x86/kernel/head32.c
16829+++ b/arch/x86/kernel/head32.c
16830@@ -19,6 +19,7 @@
16831 #include <asm/io_apic.h>
16832 #include <asm/bios_ebda.h>
16833 #include <asm/tlbflush.h>
16834+#include <asm/boot.h>
16835
16836 static void __init i386_default_early_setup(void)
16837 {
16838@@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16839
16840 void __init i386_start_kernel(void)
16841 {
16842- memblock_reserve(__pa_symbol(&_text),
16843- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16844+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16845
16846 #ifdef CONFIG_BLK_DEV_INITRD
16847 /* Reserve INITRD */
16848diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16849index ce0be7c..c41476e 100644
16850--- a/arch/x86/kernel/head_32.S
16851+++ b/arch/x86/kernel/head_32.S
16852@@ -25,6 +25,12 @@
16853 /* Physical address */
16854 #define pa(X) ((X) - __PAGE_OFFSET)
16855
16856+#ifdef CONFIG_PAX_KERNEXEC
16857+#define ta(X) (X)
16858+#else
16859+#define ta(X) ((X) - __PAGE_OFFSET)
16860+#endif
16861+
16862 /*
16863 * References to members of the new_cpu_data structure.
16864 */
16865@@ -54,11 +60,7 @@
16866 * and small than max_low_pfn, otherwise will waste some page table entries
16867 */
16868
16869-#if PTRS_PER_PMD > 1
16870-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16871-#else
16872-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16873-#endif
16874+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16875
16876 /* Number of possible pages in the lowmem region */
16877 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16878@@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16879 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16880
16881 /*
16882+ * Real beginning of normal "text" segment
16883+ */
16884+ENTRY(stext)
16885+ENTRY(_stext)
16886+
16887+/*
16888 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16889 * %esi points to the real-mode code as a 32-bit pointer.
16890 * CS and DS must be 4 GB flat segments, but we don't depend on
16891@@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16892 * can.
16893 */
16894 __HEAD
16895+
16896+#ifdef CONFIG_PAX_KERNEXEC
16897+ jmp startup_32
16898+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16899+.fill PAGE_SIZE-5,1,0xcc
16900+#endif
16901+
16902 ENTRY(startup_32)
16903 movl pa(stack_start),%ecx
16904
16905@@ -105,6 +120,57 @@ ENTRY(startup_32)
16906 2:
16907 leal -__PAGE_OFFSET(%ecx),%esp
16908
16909+#ifdef CONFIG_SMP
16910+ movl $pa(cpu_gdt_table),%edi
16911+ movl $__per_cpu_load,%eax
16912+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16913+ rorl $16,%eax
16914+ movb %al,__KERNEL_PERCPU + 4(%edi)
16915+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16916+ movl $__per_cpu_end - 1,%eax
16917+ subl $__per_cpu_start,%eax
16918+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16919+#endif
16920+
16921+#ifdef CONFIG_PAX_MEMORY_UDEREF
16922+ movl $NR_CPUS,%ecx
16923+ movl $pa(cpu_gdt_table),%edi
16924+1:
16925+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16926+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16927+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16928+ addl $PAGE_SIZE_asm,%edi
16929+ loop 1b
16930+#endif
16931+
16932+#ifdef CONFIG_PAX_KERNEXEC
16933+ movl $pa(boot_gdt),%edi
16934+ movl $__LOAD_PHYSICAL_ADDR,%eax
16935+ movw %ax,__BOOT_CS + 2(%edi)
16936+ rorl $16,%eax
16937+ movb %al,__BOOT_CS + 4(%edi)
16938+ movb %ah,__BOOT_CS + 7(%edi)
16939+ rorl $16,%eax
16940+
16941+ ljmp $(__BOOT_CS),$1f
16942+1:
16943+
16944+ movl $NR_CPUS,%ecx
16945+ movl $pa(cpu_gdt_table),%edi
16946+ addl $__PAGE_OFFSET,%eax
16947+1:
16948+ movw %ax,__KERNEL_CS + 2(%edi)
16949+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16950+ rorl $16,%eax
16951+ movb %al,__KERNEL_CS + 4(%edi)
16952+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16953+ movb %ah,__KERNEL_CS + 7(%edi)
16954+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16955+ rorl $16,%eax
16956+ addl $PAGE_SIZE_asm,%edi
16957+ loop 1b
16958+#endif
16959+
16960 /*
16961 * Clear BSS first so that there are no surprises...
16962 */
16963@@ -195,8 +261,11 @@ ENTRY(startup_32)
16964 movl %eax, pa(max_pfn_mapped)
16965
16966 /* Do early initialization of the fixmap area */
16967- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16968- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16969+#ifdef CONFIG_COMPAT_VDSO
16970+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16971+#else
16972+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16973+#endif
16974 #else /* Not PAE */
16975
16976 page_pde_offset = (__PAGE_OFFSET >> 20);
16977@@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16978 movl %eax, pa(max_pfn_mapped)
16979
16980 /* Do early initialization of the fixmap area */
16981- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16982- movl %eax,pa(initial_page_table+0xffc)
16983+#ifdef CONFIG_COMPAT_VDSO
16984+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16985+#else
16986+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16987+#endif
16988 #endif
16989
16990 #ifdef CONFIG_PARAVIRT
16991@@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16992 cmpl $num_subarch_entries, %eax
16993 jae bad_subarch
16994
16995- movl pa(subarch_entries)(,%eax,4), %eax
16996- subl $__PAGE_OFFSET, %eax
16997- jmp *%eax
16998+ jmp *pa(subarch_entries)(,%eax,4)
16999
17000 bad_subarch:
17001 WEAK(lguest_entry)
17002@@ -255,10 +325,10 @@ WEAK(xen_entry)
17003 __INITDATA
17004
17005 subarch_entries:
17006- .long default_entry /* normal x86/PC */
17007- .long lguest_entry /* lguest hypervisor */
17008- .long xen_entry /* Xen hypervisor */
17009- .long default_entry /* Moorestown MID */
17010+ .long ta(default_entry) /* normal x86/PC */
17011+ .long ta(lguest_entry) /* lguest hypervisor */
17012+ .long ta(xen_entry) /* Xen hypervisor */
17013+ .long ta(default_entry) /* Moorestown MID */
17014 num_subarch_entries = (. - subarch_entries) / 4
17015 .previous
17016 #else
17017@@ -312,6 +382,7 @@ default_entry:
17018 orl %edx,%eax
17019 movl %eax,%cr4
17020
17021+#ifdef CONFIG_X86_PAE
17022 testb $X86_CR4_PAE, %al # check if PAE is enabled
17023 jz 6f
17024
17025@@ -340,6 +411,9 @@ default_entry:
17026 /* Make changes effective */
17027 wrmsr
17028
17029+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17030+#endif
17031+
17032 6:
17033
17034 /*
17035@@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
17036 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17037 movl %eax,%ss # after changing gdt.
17038
17039- movl $(__USER_DS),%eax # DS/ES contains default USER segment
17040+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17041 movl %eax,%ds
17042 movl %eax,%es
17043
17044@@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
17045 */
17046 cmpb $0,ready
17047 jne 1f
17048- movl $gdt_page,%eax
17049+ movl $cpu_gdt_table,%eax
17050 movl $stack_canary,%ecx
17051+#ifdef CONFIG_SMP
17052+ addl $__per_cpu_load,%ecx
17053+#endif
17054 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17055 shrl $16, %ecx
17056 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17057 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
17058 1:
17059-#endif
17060 movl $(__KERNEL_STACK_CANARY),%eax
17061+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17062+ movl $(__USER_DS),%eax
17063+#else
17064+ xorl %eax,%eax
17065+#endif
17066 movl %eax,%gs
17067
17068 xorl %eax,%eax # Clear LDT
17069@@ -558,22 +639,22 @@ early_page_fault:
17070 jmp early_fault
17071
17072 early_fault:
17073- cld
17074 #ifdef CONFIG_PRINTK
17075+ cmpl $1,%ss:early_recursion_flag
17076+ je hlt_loop
17077+ incl %ss:early_recursion_flag
17078+ cld
17079 pusha
17080 movl $(__KERNEL_DS),%eax
17081 movl %eax,%ds
17082 movl %eax,%es
17083- cmpl $2,early_recursion_flag
17084- je hlt_loop
17085- incl early_recursion_flag
17086 movl %cr2,%eax
17087 pushl %eax
17088 pushl %edx /* trapno */
17089 pushl $fault_msg
17090 call printk
17091+; call dump_stack
17092 #endif
17093- call dump_stack
17094 hlt_loop:
17095 hlt
17096 jmp hlt_loop
17097@@ -581,8 +662,11 @@ hlt_loop:
17098 /* This is the default interrupt "handler" :-) */
17099 ALIGN
17100 ignore_int:
17101- cld
17102 #ifdef CONFIG_PRINTK
17103+ cmpl $2,%ss:early_recursion_flag
17104+ je hlt_loop
17105+ incl %ss:early_recursion_flag
17106+ cld
17107 pushl %eax
17108 pushl %ecx
17109 pushl %edx
17110@@ -591,9 +675,6 @@ ignore_int:
17111 movl $(__KERNEL_DS),%eax
17112 movl %eax,%ds
17113 movl %eax,%es
17114- cmpl $2,early_recursion_flag
17115- je hlt_loop
17116- incl early_recursion_flag
17117 pushl 16(%esp)
17118 pushl 24(%esp)
17119 pushl 32(%esp)
17120@@ -622,29 +703,43 @@ ENTRY(initial_code)
17121 /*
17122 * BSS section
17123 */
17124-__PAGE_ALIGNED_BSS
17125- .align PAGE_SIZE
17126 #ifdef CONFIG_X86_PAE
17127+.section .initial_pg_pmd,"a",@progbits
17128 initial_pg_pmd:
17129 .fill 1024*KPMDS,4,0
17130 #else
17131+.section .initial_page_table,"a",@progbits
17132 ENTRY(initial_page_table)
17133 .fill 1024,4,0
17134 #endif
17135+.section .initial_pg_fixmap,"a",@progbits
17136 initial_pg_fixmap:
17137 .fill 1024,4,0
17138+.section .empty_zero_page,"a",@progbits
17139 ENTRY(empty_zero_page)
17140 .fill 4096,1,0
17141+.section .swapper_pg_dir,"a",@progbits
17142 ENTRY(swapper_pg_dir)
17143+#ifdef CONFIG_X86_PAE
17144+ .fill 4,8,0
17145+#else
17146 .fill 1024,4,0
17147+#endif
17148+
17149+/*
17150+ * The IDT has to be page-aligned to simplify the Pentium
17151+ * F0 0F bug workaround.. We have a special link segment
17152+ * for this.
17153+ */
17154+.section .idt,"a",@progbits
17155+ENTRY(idt_table)
17156+ .fill 256,8,0
17157
17158 /*
17159 * This starts the data section.
17160 */
17161 #ifdef CONFIG_X86_PAE
17162-__PAGE_ALIGNED_DATA
17163- /* Page-aligned for the benefit of paravirt? */
17164- .align PAGE_SIZE
17165+.section .initial_page_table,"a",@progbits
17166 ENTRY(initial_page_table)
17167 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17168 # if KPMDS == 3
17169@@ -663,18 +758,27 @@ ENTRY(initial_page_table)
17170 # error "Kernel PMDs should be 1, 2 or 3"
17171 # endif
17172 .align PAGE_SIZE /* needs to be page-sized too */
17173+
17174+#ifdef CONFIG_PAX_PER_CPU_PGD
17175+ENTRY(cpu_pgd)
17176+ .rept NR_CPUS
17177+ .fill 4,8,0
17178+ .endr
17179+#endif
17180+
17181 #endif
17182
17183 .data
17184 .balign 4
17185 ENTRY(stack_start)
17186- .long init_thread_union+THREAD_SIZE
17187+ .long init_thread_union+THREAD_SIZE-8
17188
17189+ready: .byte 0
17190+
17191+.section .rodata,"a",@progbits
17192 early_recursion_flag:
17193 .long 0
17194
17195-ready: .byte 0
17196-
17197 int_msg:
17198 .asciz "Unknown interrupt or fault at: %p %p %p\n"
17199
17200@@ -707,7 +811,7 @@ fault_msg:
17201 .word 0 # 32 bit align gdt_desc.address
17202 boot_gdt_descr:
17203 .word __BOOT_DS+7
17204- .long boot_gdt - __PAGE_OFFSET
17205+ .long pa(boot_gdt)
17206
17207 .word 0 # 32-bit align idt_desc.address
17208 idt_descr:
17209@@ -718,7 +822,7 @@ idt_descr:
17210 .word 0 # 32 bit align gdt_desc.address
17211 ENTRY(early_gdt_descr)
17212 .word GDT_ENTRIES*8-1
17213- .long gdt_page /* Overwritten for secondary CPUs */
17214+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17215
17216 /*
17217 * The boot_gdt must mirror the equivalent in setup.S and is
17218@@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
17219 .align L1_CACHE_BYTES
17220 ENTRY(boot_gdt)
17221 .fill GDT_ENTRY_BOOT_CS,8,0
17222- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17223- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17224+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17225+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17226+
17227+ .align PAGE_SIZE_asm
17228+ENTRY(cpu_gdt_table)
17229+ .rept NR_CPUS
17230+ .quad 0x0000000000000000 /* NULL descriptor */
17231+ .quad 0x0000000000000000 /* 0x0b reserved */
17232+ .quad 0x0000000000000000 /* 0x13 reserved */
17233+ .quad 0x0000000000000000 /* 0x1b reserved */
17234+
17235+#ifdef CONFIG_PAX_KERNEXEC
17236+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17237+#else
17238+ .quad 0x0000000000000000 /* 0x20 unused */
17239+#endif
17240+
17241+ .quad 0x0000000000000000 /* 0x28 unused */
17242+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17243+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17244+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17245+ .quad 0x0000000000000000 /* 0x4b reserved */
17246+ .quad 0x0000000000000000 /* 0x53 reserved */
17247+ .quad 0x0000000000000000 /* 0x5b reserved */
17248+
17249+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17250+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17251+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17252+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17253+
17254+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17255+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17256+
17257+ /*
17258+ * Segments used for calling PnP BIOS have byte granularity.
17259+ * The code segments and data segments have fixed 64k limits,
17260+ * the transfer segment sizes are set at run time.
17261+ */
17262+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17263+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17264+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17265+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17266+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17267+
17268+ /*
17269+ * The APM segments have byte granularity and their bases
17270+ * are set at run time. All have 64k limits.
17271+ */
17272+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17273+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17274+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17275+
17276+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17277+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17278+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17279+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17280+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17281+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17282+
17283+ /* Be sure this is zeroed to avoid false validations in Xen */
17284+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17285+ .endr
17286diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17287index 40f4eb3..6d24d9d 100644
17288--- a/arch/x86/kernel/head_64.S
17289+++ b/arch/x86/kernel/head_64.S
17290@@ -19,6 +19,8 @@
17291 #include <asm/cache.h>
17292 #include <asm/processor-flags.h>
17293 #include <asm/percpu.h>
17294+#include <asm/cpufeature.h>
17295+#include <asm/alternative-asm.h>
17296
17297 #ifdef CONFIG_PARAVIRT
17298 #include <asm/asm-offsets.h>
17299@@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17300 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17301 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17302 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17303+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17304+L3_VMALLOC_START = pud_index(VMALLOC_START)
17305+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17306+L3_VMALLOC_END = pud_index(VMALLOC_END)
17307+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17308+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17309
17310 .text
17311 __HEAD
17312@@ -85,35 +93,23 @@ startup_64:
17313 */
17314 addq %rbp, init_level4_pgt + 0(%rip)
17315 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17316+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17317+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17318+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17319 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17320
17321 addq %rbp, level3_ident_pgt + 0(%rip)
17322+#ifndef CONFIG_XEN
17323+ addq %rbp, level3_ident_pgt + 8(%rip)
17324+#endif
17325
17326- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17327- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17328+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17329+
17330+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17331+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17332
17333 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17334-
17335- /* Add an Identity mapping if I am above 1G */
17336- leaq _text(%rip), %rdi
17337- andq $PMD_PAGE_MASK, %rdi
17338-
17339- movq %rdi, %rax
17340- shrq $PUD_SHIFT, %rax
17341- andq $(PTRS_PER_PUD - 1), %rax
17342- jz ident_complete
17343-
17344- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17345- leaq level3_ident_pgt(%rip), %rbx
17346- movq %rdx, 0(%rbx, %rax, 8)
17347-
17348- movq %rdi, %rax
17349- shrq $PMD_SHIFT, %rax
17350- andq $(PTRS_PER_PMD - 1), %rax
17351- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17352- leaq level2_spare_pgt(%rip), %rbx
17353- movq %rdx, 0(%rbx, %rax, 8)
17354-ident_complete:
17355+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17356
17357 /*
17358 * Fixup the kernel text+data virtual addresses. Note that
17359@@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
17360 * after the boot processor executes this code.
17361 */
17362
17363- /* Enable PAE mode and PGE */
17364- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17365+ /* Enable PAE mode and PSE/PGE */
17366+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17367 movq %rax, %cr4
17368
17369 /* Setup early boot stage 4 level pagetables. */
17370@@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
17371 movl $MSR_EFER, %ecx
17372 rdmsr
17373 btsl $_EFER_SCE, %eax /* Enable System Call */
17374- btl $20,%edi /* No Execute supported? */
17375+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17376 jnc 1f
17377 btsl $_EFER_NX, %eax
17378+ leaq init_level4_pgt(%rip), %rdi
17379+#ifndef CONFIG_EFI
17380+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17381+#endif
17382+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17383+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17384+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17385+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17386 1: wrmsr /* Make changes effective */
17387
17388 /* Setup cr0 */
17389@@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
17390 * jump. In addition we need to ensure %cs is set so we make this
17391 * a far return.
17392 */
17393+ pax_set_fptr_mask
17394 movq initial_code(%rip),%rax
17395 pushq $0 # fake return address to stop unwinder
17396 pushq $__KERNEL_CS # set correct cs
17397@@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
17398 bad_address:
17399 jmp bad_address
17400
17401- .section ".init.text","ax"
17402+ __INIT
17403 #ifdef CONFIG_EARLY_PRINTK
17404 .globl early_idt_handlers
17405 early_idt_handlers:
17406@@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
17407 #endif /* EARLY_PRINTK */
17408 1: hlt
17409 jmp 1b
17410+ .previous
17411
17412 #ifdef CONFIG_EARLY_PRINTK
17413+ __INITDATA
17414 early_recursion_flag:
17415 .long 0
17416+ .previous
17417
17418+ .section .rodata,"a",@progbits
17419 early_idt_msg:
17420 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17421 early_idt_ripmsg:
17422 .asciz "RIP %s\n"
17423+ .previous
17424 #endif /* CONFIG_EARLY_PRINTK */
17425- .previous
17426
17427+ .section .rodata,"a",@progbits
17428 #define NEXT_PAGE(name) \
17429 .balign PAGE_SIZE; \
17430 ENTRY(name)
17431@@ -338,7 +348,6 @@ ENTRY(name)
17432 i = i + 1 ; \
17433 .endr
17434
17435- .data
17436 /*
17437 * This default setting generates an ident mapping at address 0x100000
17438 * and a mapping for the kernel that precisely maps virtual address
17439@@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
17440 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17441 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17442 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17443+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17444+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17445+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17446+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17447+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17448+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17449 .org init_level4_pgt + L4_START_KERNEL*8, 0
17450 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17451 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17452
17453+#ifdef CONFIG_PAX_PER_CPU_PGD
17454+NEXT_PAGE(cpu_pgd)
17455+ .rept NR_CPUS
17456+ .fill 512,8,0
17457+ .endr
17458+#endif
17459+
17460 NEXT_PAGE(level3_ident_pgt)
17461 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17462+#ifdef CONFIG_XEN
17463 .fill 511,8,0
17464+#else
17465+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17466+ .fill 510,8,0
17467+#endif
17468+
17469+NEXT_PAGE(level3_vmalloc_start_pgt)
17470+ .fill 512,8,0
17471+
17472+NEXT_PAGE(level3_vmalloc_end_pgt)
17473+ .fill 512,8,0
17474+
17475+NEXT_PAGE(level3_vmemmap_pgt)
17476+ .fill L3_VMEMMAP_START,8,0
17477+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17478
17479 NEXT_PAGE(level3_kernel_pgt)
17480 .fill L3_START_KERNEL,8,0
17481@@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
17482 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17483 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17484
17485+NEXT_PAGE(level2_vmemmap_pgt)
17486+ .fill 512,8,0
17487+
17488 NEXT_PAGE(level2_fixmap_pgt)
17489- .fill 506,8,0
17490- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17491- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17492- .fill 5,8,0
17493+ .fill 507,8,0
17494+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17495+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17496+ .fill 4,8,0
17497
17498-NEXT_PAGE(level1_fixmap_pgt)
17499+NEXT_PAGE(level1_vsyscall_pgt)
17500 .fill 512,8,0
17501
17502-NEXT_PAGE(level2_ident_pgt)
17503- /* Since I easily can, map the first 1G.
17504+ /* Since I easily can, map the first 2G.
17505 * Don't set NX because code runs from these pages.
17506 */
17507- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17508+NEXT_PAGE(level2_ident_pgt)
17509+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17510
17511 NEXT_PAGE(level2_kernel_pgt)
17512 /*
17513@@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
17514 * If you want to increase this then increase MODULES_VADDR
17515 * too.)
17516 */
17517- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17518- KERNEL_IMAGE_SIZE/PMD_SIZE)
17519-
17520-NEXT_PAGE(level2_spare_pgt)
17521- .fill 512, 8, 0
17522+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17523
17524 #undef PMDS
17525 #undef NEXT_PAGE
17526
17527- .data
17528+ .align PAGE_SIZE
17529+ENTRY(cpu_gdt_table)
17530+ .rept NR_CPUS
17531+ .quad 0x0000000000000000 /* NULL descriptor */
17532+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17533+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17534+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17535+ .quad 0x00cffb000000ffff /* __USER32_CS */
17536+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17537+ .quad 0x00affb000000ffff /* __USER_CS */
17538+
17539+#ifdef CONFIG_PAX_KERNEXEC
17540+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17541+#else
17542+ .quad 0x0 /* unused */
17543+#endif
17544+
17545+ .quad 0,0 /* TSS */
17546+ .quad 0,0 /* LDT */
17547+ .quad 0,0,0 /* three TLS descriptors */
17548+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17549+ /* asm/segment.h:GDT_ENTRIES must match this */
17550+
17551+ /* zero the remaining page */
17552+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17553+ .endr
17554+
17555 .align 16
17556 .globl early_gdt_descr
17557 early_gdt_descr:
17558 .word GDT_ENTRIES*8-1
17559 early_gdt_descr_base:
17560- .quad INIT_PER_CPU_VAR(gdt_page)
17561+ .quad cpu_gdt_table
17562
17563 ENTRY(phys_base)
17564 /* This must match the first entry in level2_kernel_pgt */
17565 .quad 0x0000000000000000
17566
17567 #include "../../x86/xen/xen-head.S"
17568-
17569- .section .bss, "aw", @nobits
17570+
17571+ .section .rodata,"a",@progbits
17572 .align L1_CACHE_BYTES
17573 ENTRY(idt_table)
17574- .skip IDT_ENTRIES * 16
17575+ .fill 512,8,0
17576
17577 .align L1_CACHE_BYTES
17578 ENTRY(nmi_idt_table)
17579- .skip IDT_ENTRIES * 16
17580+ .fill 512,8,0
17581
17582 __PAGE_ALIGNED_BSS
17583 .align PAGE_SIZE
17584diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17585index 9c3bd4a..e1d9b35 100644
17586--- a/arch/x86/kernel/i386_ksyms_32.c
17587+++ b/arch/x86/kernel/i386_ksyms_32.c
17588@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17589 EXPORT_SYMBOL(cmpxchg8b_emu);
17590 #endif
17591
17592+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17593+
17594 /* Networking helper routines. */
17595 EXPORT_SYMBOL(csum_partial_copy_generic);
17596+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17597+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17598
17599 EXPORT_SYMBOL(__get_user_1);
17600 EXPORT_SYMBOL(__get_user_2);
17601@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17602
17603 EXPORT_SYMBOL(csum_partial);
17604 EXPORT_SYMBOL(empty_zero_page);
17605+
17606+#ifdef CONFIG_PAX_KERNEXEC
17607+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17608+#endif
17609diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17610index 2d6e649..df6e1af 100644
17611--- a/arch/x86/kernel/i387.c
17612+++ b/arch/x86/kernel/i387.c
17613@@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17614 static inline bool interrupted_user_mode(void)
17615 {
17616 struct pt_regs *regs = get_irq_regs();
17617- return regs && user_mode_vm(regs);
17618+ return regs && user_mode(regs);
17619 }
17620
17621 /*
17622diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17623index 36d1853..bf25736 100644
17624--- a/arch/x86/kernel/i8259.c
17625+++ b/arch/x86/kernel/i8259.c
17626@@ -209,7 +209,7 @@ spurious_8259A_irq:
17627 "spurious 8259A interrupt: IRQ%d.\n", irq);
17628 spurious_irq_mask |= irqmask;
17629 }
17630- atomic_inc(&irq_err_count);
17631+ atomic_inc_unchecked(&irq_err_count);
17632 /*
17633 * Theoretically we do not have to handle this IRQ,
17634 * but in Linux this does not cause problems and is
17635diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17636index 43e9ccf..44ccf6f 100644
17637--- a/arch/x86/kernel/init_task.c
17638+++ b/arch/x86/kernel/init_task.c
17639@@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17640 * way process stacks are handled. This is done by having a special
17641 * "init_task" linker map entry..
17642 */
17643-union thread_union init_thread_union __init_task_data =
17644- { INIT_THREAD_INFO(init_task) };
17645+union thread_union init_thread_union __init_task_data;
17646
17647 /*
17648 * Initial task structure.
17649@@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17650 * section. Since TSS's are completely CPU-local, we want them
17651 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17652 */
17653-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17654-
17655+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17656+EXPORT_SYMBOL(init_tss);
17657diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17658index 8c96897..be66bfa 100644
17659--- a/arch/x86/kernel/ioport.c
17660+++ b/arch/x86/kernel/ioport.c
17661@@ -6,6 +6,7 @@
17662 #include <linux/sched.h>
17663 #include <linux/kernel.h>
17664 #include <linux/capability.h>
17665+#include <linux/security.h>
17666 #include <linux/errno.h>
17667 #include <linux/types.h>
17668 #include <linux/ioport.h>
17669@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17670
17671 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17672 return -EINVAL;
17673+#ifdef CONFIG_GRKERNSEC_IO
17674+ if (turn_on && grsec_disable_privio) {
17675+ gr_handle_ioperm();
17676+ return -EPERM;
17677+ }
17678+#endif
17679 if (turn_on && !capable(CAP_SYS_RAWIO))
17680 return -EPERM;
17681
17682@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17683 * because the ->io_bitmap_max value must match the bitmap
17684 * contents:
17685 */
17686- tss = &per_cpu(init_tss, get_cpu());
17687+ tss = init_tss + get_cpu();
17688
17689 if (turn_on)
17690 bitmap_clear(t->io_bitmap_ptr, from, num);
17691@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17692 return -EINVAL;
17693 /* Trying to gain more privileges? */
17694 if (level > old) {
17695+#ifdef CONFIG_GRKERNSEC_IO
17696+ if (grsec_disable_privio) {
17697+ gr_handle_iopl();
17698+ return -EPERM;
17699+ }
17700+#endif
17701 if (!capable(CAP_SYS_RAWIO))
17702 return -EPERM;
17703 }
17704diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17705index 3dafc60..aa8e9c4 100644
17706--- a/arch/x86/kernel/irq.c
17707+++ b/arch/x86/kernel/irq.c
17708@@ -18,7 +18,7 @@
17709 #include <asm/mce.h>
17710 #include <asm/hw_irq.h>
17711
17712-atomic_t irq_err_count;
17713+atomic_unchecked_t irq_err_count;
17714
17715 /* Function pointer for generic interrupt vector handling */
17716 void (*x86_platform_ipi_callback)(void) = NULL;
17717@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17718 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17719 seq_printf(p, " Machine check polls\n");
17720 #endif
17721- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17722+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17723 #if defined(CONFIG_X86_IO_APIC)
17724- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17725+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17726 #endif
17727 return 0;
17728 }
17729@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17730
17731 u64 arch_irq_stat(void)
17732 {
17733- u64 sum = atomic_read(&irq_err_count);
17734+ u64 sum = atomic_read_unchecked(&irq_err_count);
17735
17736 #ifdef CONFIG_X86_IO_APIC
17737- sum += atomic_read(&irq_mis_count);
17738+ sum += atomic_read_unchecked(&irq_mis_count);
17739 #endif
17740 return sum;
17741 }
17742diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17743index 58b7f27..e112d08 100644
17744--- a/arch/x86/kernel/irq_32.c
17745+++ b/arch/x86/kernel/irq_32.c
17746@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17747 __asm__ __volatile__("andl %%esp,%0" :
17748 "=r" (sp) : "0" (THREAD_SIZE - 1));
17749
17750- return sp < (sizeof(struct thread_info) + STACK_WARN);
17751+ return sp < STACK_WARN;
17752 }
17753
17754 static void print_stack_overflow(void)
17755@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17756 * per-CPU IRQ handling contexts (thread information and stack)
17757 */
17758 union irq_ctx {
17759- struct thread_info tinfo;
17760- u32 stack[THREAD_SIZE/sizeof(u32)];
17761+ unsigned long previous_esp;
17762+ u32 stack[THREAD_SIZE/sizeof(u32)];
17763 } __attribute__((aligned(THREAD_SIZE)));
17764
17765 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17766@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17767 static inline int
17768 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17769 {
17770- union irq_ctx *curctx, *irqctx;
17771+ union irq_ctx *irqctx;
17772 u32 *isp, arg1, arg2;
17773
17774- curctx = (union irq_ctx *) current_thread_info();
17775 irqctx = __this_cpu_read(hardirq_ctx);
17776
17777 /*
17778@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17779 * handler) we can't do that and just have to keep using the
17780 * current stack (which is the irq stack already after all)
17781 */
17782- if (unlikely(curctx == irqctx))
17783+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17784 return 0;
17785
17786 /* build the stack frame on the IRQ stack */
17787- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17788- irqctx->tinfo.task = curctx->tinfo.task;
17789- irqctx->tinfo.previous_esp = current_stack_pointer;
17790+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17791+ irqctx->previous_esp = current_stack_pointer;
17792
17793- /* Copy the preempt_count so that the [soft]irq checks work. */
17794- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17795+#ifdef CONFIG_PAX_MEMORY_UDEREF
17796+ __set_fs(MAKE_MM_SEG(0));
17797+#endif
17798
17799 if (unlikely(overflow))
17800 call_on_stack(print_stack_overflow, isp);
17801@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17802 : "0" (irq), "1" (desc), "2" (isp),
17803 "D" (desc->handle_irq)
17804 : "memory", "cc", "ecx");
17805+
17806+#ifdef CONFIG_PAX_MEMORY_UDEREF
17807+ __set_fs(current_thread_info()->addr_limit);
17808+#endif
17809+
17810 return 1;
17811 }
17812
17813@@ -121,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17814 */
17815 void __cpuinit irq_ctx_init(int cpu)
17816 {
17817- union irq_ctx *irqctx;
17818-
17819 if (per_cpu(hardirq_ctx, cpu))
17820 return;
17821
17822- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17823- THREAD_FLAGS,
17824- THREAD_ORDER));
17825- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17826- irqctx->tinfo.cpu = cpu;
17827- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17828- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17829-
17830- per_cpu(hardirq_ctx, cpu) = irqctx;
17831-
17832- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17833- THREAD_FLAGS,
17834- THREAD_ORDER));
17835- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17836- irqctx->tinfo.cpu = cpu;
17837- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17838-
17839- per_cpu(softirq_ctx, cpu) = irqctx;
17840+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17841+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17842
17843 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17844 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17845@@ -152,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17846 asmlinkage void do_softirq(void)
17847 {
17848 unsigned long flags;
17849- struct thread_info *curctx;
17850 union irq_ctx *irqctx;
17851 u32 *isp;
17852
17853@@ -162,15 +147,22 @@ asmlinkage void do_softirq(void)
17854 local_irq_save(flags);
17855
17856 if (local_softirq_pending()) {
17857- curctx = current_thread_info();
17858 irqctx = __this_cpu_read(softirq_ctx);
17859- irqctx->tinfo.task = curctx->task;
17860- irqctx->tinfo.previous_esp = current_stack_pointer;
17861+ irqctx->previous_esp = current_stack_pointer;
17862
17863 /* build the stack frame on the softirq stack */
17864- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17865+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17866+
17867+#ifdef CONFIG_PAX_MEMORY_UDEREF
17868+ __set_fs(MAKE_MM_SEG(0));
17869+#endif
17870
17871 call_on_stack(__do_softirq, isp);
17872+
17873+#ifdef CONFIG_PAX_MEMORY_UDEREF
17874+ __set_fs(current_thread_info()->addr_limit);
17875+#endif
17876+
17877 /*
17878 * Shouldn't happen, we returned above if in_interrupt():
17879 */
17880@@ -191,7 +183,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17881 if (unlikely(!desc))
17882 return false;
17883
17884- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17885+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17886 if (unlikely(overflow))
17887 print_stack_overflow();
17888 desc->handle_irq(irq, desc);
17889diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17890index d04d3ec..ea4b374 100644
17891--- a/arch/x86/kernel/irq_64.c
17892+++ b/arch/x86/kernel/irq_64.c
17893@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17894 u64 estack_top, estack_bottom;
17895 u64 curbase = (u64)task_stack_page(current);
17896
17897- if (user_mode_vm(regs))
17898+ if (user_mode(regs))
17899 return;
17900
17901 if (regs->sp >= curbase + sizeof(struct thread_info) +
17902diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17903index 1d5d31e..ab846ed 100644
17904--- a/arch/x86/kernel/kdebugfs.c
17905+++ b/arch/x86/kernel/kdebugfs.c
17906@@ -28,6 +28,8 @@ struct setup_data_node {
17907 };
17908
17909 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17910+ size_t count, loff_t *ppos) __size_overflow(3);
17911+static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17912 size_t count, loff_t *ppos)
17913 {
17914 struct setup_data_node *node = file->private_data;
17915diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17916index 8bfb614..2b3b35f 100644
17917--- a/arch/x86/kernel/kgdb.c
17918+++ b/arch/x86/kernel/kgdb.c
17919@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17920 #ifdef CONFIG_X86_32
17921 switch (regno) {
17922 case GDB_SS:
17923- if (!user_mode_vm(regs))
17924+ if (!user_mode(regs))
17925 *(unsigned long *)mem = __KERNEL_DS;
17926 break;
17927 case GDB_SP:
17928- if (!user_mode_vm(regs))
17929+ if (!user_mode(regs))
17930 *(unsigned long *)mem = kernel_stack_pointer(regs);
17931 break;
17932 case GDB_GS:
17933@@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17934 case 'k':
17935 /* clear the trace bit */
17936 linux_regs->flags &= ~X86_EFLAGS_TF;
17937- atomic_set(&kgdb_cpu_doing_single_step, -1);
17938+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17939
17940 /* set the trace bit if we're stepping */
17941 if (remcomInBuffer[0] == 's') {
17942 linux_regs->flags |= X86_EFLAGS_TF;
17943- atomic_set(&kgdb_cpu_doing_single_step,
17944+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17945 raw_smp_processor_id());
17946 }
17947
17948@@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17949
17950 switch (cmd) {
17951 case DIE_DEBUG:
17952- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17953+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17954 if (user_mode(regs))
17955 return single_step_cont(regs, args);
17956 break;
17957diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17958index c5e410e..da6aaf9 100644
17959--- a/arch/x86/kernel/kprobes-opt.c
17960+++ b/arch/x86/kernel/kprobes-opt.c
17961@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17962 * Verify if the address gap is in 2GB range, because this uses
17963 * a relative jump.
17964 */
17965- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17966+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17967 if (abs(rel) > 0x7fffffff)
17968 return -ERANGE;
17969
17970@@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17971 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17972
17973 /* Set probe function call */
17974- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17975+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17976
17977 /* Set returning jmp instruction at the tail of out-of-line buffer */
17978 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17979- (u8 *)op->kp.addr + op->optinsn.size);
17980+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17981
17982 flush_icache_range((unsigned long) buf,
17983 (unsigned long) buf + TMPL_END_IDX +
17984@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17985 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17986
17987 /* Backup instructions which will be replaced by jump address */
17988- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17989+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17990 RELATIVE_ADDR_SIZE);
17991
17992 insn_buf[0] = RELATIVEJUMP_OPCODE;
17993diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17994index e213fc8..d783ba4 100644
17995--- a/arch/x86/kernel/kprobes.c
17996+++ b/arch/x86/kernel/kprobes.c
17997@@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17998 } __attribute__((packed)) *insn;
17999
18000 insn = (struct __arch_relative_insn *)from;
18001+
18002+ pax_open_kernel();
18003 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
18004 insn->op = op;
18005+ pax_close_kernel();
18006 }
18007
18008 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
18009@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
18010 kprobe_opcode_t opcode;
18011 kprobe_opcode_t *orig_opcodes = opcodes;
18012
18013- if (search_exception_tables((unsigned long)opcodes))
18014+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
18015 return 0; /* Page fault may occur on this address. */
18016
18017 retry:
18018@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18019 /* Another subsystem puts a breakpoint, failed to recover */
18020 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
18021 return 0;
18022+ pax_open_kernel();
18023 memcpy(dest, insn.kaddr, insn.length);
18024+ pax_close_kernel();
18025
18026 #ifdef CONFIG_X86_64
18027 if (insn_rip_relative(&insn)) {
18028@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18029 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
18030 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18031 disp = (u8 *) dest + insn_offset_displacement(&insn);
18032+ pax_open_kernel();
18033 *(s32 *) disp = (s32) newdisp;
18034+ pax_close_kernel();
18035 }
18036 #endif
18037 return insn.length;
18038@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18039 * nor set current_kprobe, because it doesn't use single
18040 * stepping.
18041 */
18042- regs->ip = (unsigned long)p->ainsn.insn;
18043+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18044 preempt_enable_no_resched();
18045 return;
18046 }
18047@@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18048 if (p->opcode == BREAKPOINT_INSTRUCTION)
18049 regs->ip = (unsigned long)p->addr;
18050 else
18051- regs->ip = (unsigned long)p->ainsn.insn;
18052+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18053 }
18054
18055 /*
18056@@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18057 setup_singlestep(p, regs, kcb, 0);
18058 return 1;
18059 }
18060- } else if (*addr != BREAKPOINT_INSTRUCTION) {
18061+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18062 /*
18063 * The breakpoint instruction was removed right
18064 * after we hit it. Another cpu has removed
18065@@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18066 " movq %rax, 152(%rsp)\n"
18067 RESTORE_REGS_STRING
18068 " popfq\n"
18069+#ifdef KERNEXEC_PLUGIN
18070+ " btsq $63,(%rsp)\n"
18071+#endif
18072 #else
18073 " pushf\n"
18074 SAVE_REGS_STRING
18075@@ -765,7 +775,7 @@ static void __kprobes
18076 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18077 {
18078 unsigned long *tos = stack_addr(regs);
18079- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18080+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18081 unsigned long orig_ip = (unsigned long)p->addr;
18082 kprobe_opcode_t *insn = p->ainsn.insn;
18083
18084@@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18085 struct die_args *args = data;
18086 int ret = NOTIFY_DONE;
18087
18088- if (args->regs && user_mode_vm(args->regs))
18089+ if (args->regs && user_mode(args->regs))
18090 return ret;
18091
18092 switch (val) {
18093diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18094index ebc9873..1b9724b 100644
18095--- a/arch/x86/kernel/ldt.c
18096+++ b/arch/x86/kernel/ldt.c
18097@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18098 if (reload) {
18099 #ifdef CONFIG_SMP
18100 preempt_disable();
18101- load_LDT(pc);
18102+ load_LDT_nolock(pc);
18103 if (!cpumask_equal(mm_cpumask(current->mm),
18104 cpumask_of(smp_processor_id())))
18105 smp_call_function(flush_ldt, current->mm, 1);
18106 preempt_enable();
18107 #else
18108- load_LDT(pc);
18109+ load_LDT_nolock(pc);
18110 #endif
18111 }
18112 if (oldsize) {
18113@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18114 return err;
18115
18116 for (i = 0; i < old->size; i++)
18117- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18118+ write_ldt_entry(new->ldt, i, old->ldt + i);
18119 return 0;
18120 }
18121
18122@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18123 retval = copy_ldt(&mm->context, &old_mm->context);
18124 mutex_unlock(&old_mm->context.lock);
18125 }
18126+
18127+ if (tsk == current) {
18128+ mm->context.vdso = 0;
18129+
18130+#ifdef CONFIG_X86_32
18131+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18132+ mm->context.user_cs_base = 0UL;
18133+ mm->context.user_cs_limit = ~0UL;
18134+
18135+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18136+ cpus_clear(mm->context.cpu_user_cs_mask);
18137+#endif
18138+
18139+#endif
18140+#endif
18141+
18142+ }
18143+
18144 return retval;
18145 }
18146
18147@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18148 }
18149 }
18150
18151+#ifdef CONFIG_PAX_SEGMEXEC
18152+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18153+ error = -EINVAL;
18154+ goto out_unlock;
18155+ }
18156+#endif
18157+
18158 fill_ldt(&ldt, &ldt_info);
18159 if (oldmode)
18160 ldt.avl = 0;
18161diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18162index 5b19e4d..6476a76 100644
18163--- a/arch/x86/kernel/machine_kexec_32.c
18164+++ b/arch/x86/kernel/machine_kexec_32.c
18165@@ -26,7 +26,7 @@
18166 #include <asm/cacheflush.h>
18167 #include <asm/debugreg.h>
18168
18169-static void set_idt(void *newidt, __u16 limit)
18170+static void set_idt(struct desc_struct *newidt, __u16 limit)
18171 {
18172 struct desc_ptr curidt;
18173
18174@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18175 }
18176
18177
18178-static void set_gdt(void *newgdt, __u16 limit)
18179+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18180 {
18181 struct desc_ptr curgdt;
18182
18183@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18184 }
18185
18186 control_page = page_address(image->control_code_page);
18187- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18188+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18189
18190 relocate_kernel_ptr = control_page;
18191 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18192diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18193index 0327e2b..e43737b 100644
18194--- a/arch/x86/kernel/microcode_intel.c
18195+++ b/arch/x86/kernel/microcode_intel.c
18196@@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18197
18198 static int get_ucode_user(void *to, const void *from, size_t n)
18199 {
18200- return copy_from_user(to, from, n);
18201+ return copy_from_user(to, (const void __force_user *)from, n);
18202 }
18203
18204 static enum ucode_state
18205 request_microcode_user(int cpu, const void __user *buf, size_t size)
18206 {
18207- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18208+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18209 }
18210
18211 static void microcode_fini_cpu(int cpu)
18212diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18213index f21fd94..61565cd 100644
18214--- a/arch/x86/kernel/module.c
18215+++ b/arch/x86/kernel/module.c
18216@@ -35,15 +35,60 @@
18217 #define DEBUGP(fmt...)
18218 #endif
18219
18220-void *module_alloc(unsigned long size)
18221+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18222 {
18223- if (PAGE_ALIGN(size) > MODULES_LEN)
18224+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18225 return NULL;
18226 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18227- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18228+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18229 -1, __builtin_return_address(0));
18230 }
18231
18232+void *module_alloc(unsigned long size)
18233+{
18234+
18235+#ifdef CONFIG_PAX_KERNEXEC
18236+ return __module_alloc(size, PAGE_KERNEL);
18237+#else
18238+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18239+#endif
18240+
18241+}
18242+
18243+#ifdef CONFIG_PAX_KERNEXEC
18244+#ifdef CONFIG_X86_32
18245+void *module_alloc_exec(unsigned long size)
18246+{
18247+ struct vm_struct *area;
18248+
18249+ if (size == 0)
18250+ return NULL;
18251+
18252+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18253+ return area ? area->addr : NULL;
18254+}
18255+EXPORT_SYMBOL(module_alloc_exec);
18256+
18257+void module_free_exec(struct module *mod, void *module_region)
18258+{
18259+ vunmap(module_region);
18260+}
18261+EXPORT_SYMBOL(module_free_exec);
18262+#else
18263+void module_free_exec(struct module *mod, void *module_region)
18264+{
18265+ module_free(mod, module_region);
18266+}
18267+EXPORT_SYMBOL(module_free_exec);
18268+
18269+void *module_alloc_exec(unsigned long size)
18270+{
18271+ return __module_alloc(size, PAGE_KERNEL_RX);
18272+}
18273+EXPORT_SYMBOL(module_alloc_exec);
18274+#endif
18275+#endif
18276+
18277 #ifdef CONFIG_X86_32
18278 int apply_relocate(Elf32_Shdr *sechdrs,
18279 const char *strtab,
18280@@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18281 unsigned int i;
18282 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18283 Elf32_Sym *sym;
18284- uint32_t *location;
18285+ uint32_t *plocation, location;
18286
18287 DEBUGP("Applying relocate section %u to %u\n", relsec,
18288 sechdrs[relsec].sh_info);
18289 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18290 /* This is where to make the change */
18291- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18292- + rel[i].r_offset;
18293+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18294+ location = (uint32_t)plocation;
18295+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18296+ plocation = ktla_ktva((void *)plocation);
18297 /* This is the symbol it is referring to. Note that all
18298 undefined symbols have been resolved. */
18299 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18300@@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18301 switch (ELF32_R_TYPE(rel[i].r_info)) {
18302 case R_386_32:
18303 /* We add the value into the location given */
18304- *location += sym->st_value;
18305+ pax_open_kernel();
18306+ *plocation += sym->st_value;
18307+ pax_close_kernel();
18308 break;
18309 case R_386_PC32:
18310 /* Add the value, subtract its postition */
18311- *location += sym->st_value - (uint32_t)location;
18312+ pax_open_kernel();
18313+ *plocation += sym->st_value - location;
18314+ pax_close_kernel();
18315 break;
18316 default:
18317 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18318@@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18319 case R_X86_64_NONE:
18320 break;
18321 case R_X86_64_64:
18322+ pax_open_kernel();
18323 *(u64 *)loc = val;
18324+ pax_close_kernel();
18325 break;
18326 case R_X86_64_32:
18327+ pax_open_kernel();
18328 *(u32 *)loc = val;
18329+ pax_close_kernel();
18330 if (val != *(u32 *)loc)
18331 goto overflow;
18332 break;
18333 case R_X86_64_32S:
18334+ pax_open_kernel();
18335 *(s32 *)loc = val;
18336+ pax_close_kernel();
18337 if ((s64)val != *(s32 *)loc)
18338 goto overflow;
18339 break;
18340 case R_X86_64_PC32:
18341 val -= (u64)loc;
18342+ pax_open_kernel();
18343 *(u32 *)loc = val;
18344+ pax_close_kernel();
18345+
18346 #if 0
18347 if ((s64)val != *(s32 *)loc)
18348 goto overflow;
18349diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18350index 32856fa..ce95eaa 100644
18351--- a/arch/x86/kernel/nmi.c
18352+++ b/arch/x86/kernel/nmi.c
18353@@ -507,6 +507,17 @@ static inline void nmi_nesting_postprocess(void)
18354 dotraplinkage notrace __kprobes void
18355 do_nmi(struct pt_regs *regs, long error_code)
18356 {
18357+
18358+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18359+ if (!user_mode(regs)) {
18360+ unsigned long cs = regs->cs & 0xFFFF;
18361+ unsigned long ip = ktva_ktla(regs->ip);
18362+
18363+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18364+ regs->ip = ip;
18365+ }
18366+#endif
18367+
18368 nmi_nesting_preprocess(regs);
18369
18370 nmi_enter();
18371diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18372index 676b8c7..870ba04 100644
18373--- a/arch/x86/kernel/paravirt-spinlocks.c
18374+++ b/arch/x86/kernel/paravirt-spinlocks.c
18375@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18376 arch_spin_lock(lock);
18377 }
18378
18379-struct pv_lock_ops pv_lock_ops = {
18380+struct pv_lock_ops pv_lock_ops __read_only = {
18381 #ifdef CONFIG_SMP
18382 .spin_is_locked = __ticket_spin_is_locked,
18383 .spin_is_contended = __ticket_spin_is_contended,
18384diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18385index ab13760..01218e0 100644
18386--- a/arch/x86/kernel/paravirt.c
18387+++ b/arch/x86/kernel/paravirt.c
18388@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18389 {
18390 return x;
18391 }
18392+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18393+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18394+#endif
18395
18396 void __init default_banner(void)
18397 {
18398@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18399 if (opfunc == NULL)
18400 /* If there's no function, patch it with a ud2a (BUG) */
18401 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18402- else if (opfunc == _paravirt_nop)
18403+ else if (opfunc == (void *)_paravirt_nop)
18404 /* If the operation is a nop, then nop the callsite */
18405 ret = paravirt_patch_nop();
18406
18407 /* identity functions just return their single argument */
18408- else if (opfunc == _paravirt_ident_32)
18409+ else if (opfunc == (void *)_paravirt_ident_32)
18410 ret = paravirt_patch_ident_32(insnbuf, len);
18411- else if (opfunc == _paravirt_ident_64)
18412+ else if (opfunc == (void *)_paravirt_ident_64)
18413 ret = paravirt_patch_ident_64(insnbuf, len);
18414+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18415+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18416+ ret = paravirt_patch_ident_64(insnbuf, len);
18417+#endif
18418
18419 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18420 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18421@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18422 if (insn_len > len || start == NULL)
18423 insn_len = len;
18424 else
18425- memcpy(insnbuf, start, insn_len);
18426+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18427
18428 return insn_len;
18429 }
18430@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18431 preempt_enable();
18432 }
18433
18434-struct pv_info pv_info = {
18435+struct pv_info pv_info __read_only = {
18436 .name = "bare hardware",
18437 .paravirt_enabled = 0,
18438 .kernel_rpl = 0,
18439@@ -315,16 +322,16 @@ struct pv_info pv_info = {
18440 #endif
18441 };
18442
18443-struct pv_init_ops pv_init_ops = {
18444+struct pv_init_ops pv_init_ops __read_only = {
18445 .patch = native_patch,
18446 };
18447
18448-struct pv_time_ops pv_time_ops = {
18449+struct pv_time_ops pv_time_ops __read_only = {
18450 .sched_clock = native_sched_clock,
18451 .steal_clock = native_steal_clock,
18452 };
18453
18454-struct pv_irq_ops pv_irq_ops = {
18455+struct pv_irq_ops pv_irq_ops __read_only = {
18456 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18457 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18458 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18459@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18460 #endif
18461 };
18462
18463-struct pv_cpu_ops pv_cpu_ops = {
18464+struct pv_cpu_ops pv_cpu_ops __read_only = {
18465 .cpuid = native_cpuid,
18466 .get_debugreg = native_get_debugreg,
18467 .set_debugreg = native_set_debugreg,
18468@@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18469 .end_context_switch = paravirt_nop,
18470 };
18471
18472-struct pv_apic_ops pv_apic_ops = {
18473+struct pv_apic_ops pv_apic_ops __read_only = {
18474 #ifdef CONFIG_X86_LOCAL_APIC
18475 .startup_ipi_hook = paravirt_nop,
18476 #endif
18477 };
18478
18479-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18480+#ifdef CONFIG_X86_32
18481+#ifdef CONFIG_X86_PAE
18482+/* 64-bit pagetable entries */
18483+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18484+#else
18485 /* 32-bit pagetable entries */
18486 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18487+#endif
18488 #else
18489 /* 64-bit pagetable entries */
18490 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18491 #endif
18492
18493-struct pv_mmu_ops pv_mmu_ops = {
18494+struct pv_mmu_ops pv_mmu_ops __read_only = {
18495
18496 .read_cr2 = native_read_cr2,
18497 .write_cr2 = native_write_cr2,
18498@@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18499 .make_pud = PTE_IDENT,
18500
18501 .set_pgd = native_set_pgd,
18502+ .set_pgd_batched = native_set_pgd_batched,
18503 #endif
18504 #endif /* PAGETABLE_LEVELS >= 3 */
18505
18506@@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18507 },
18508
18509 .set_fixmap = native_set_fixmap,
18510+
18511+#ifdef CONFIG_PAX_KERNEXEC
18512+ .pax_open_kernel = native_pax_open_kernel,
18513+ .pax_close_kernel = native_pax_close_kernel,
18514+#endif
18515+
18516 };
18517
18518 EXPORT_SYMBOL_GPL(pv_time_ops);
18519diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18520index 35ccf75..7a15747 100644
18521--- a/arch/x86/kernel/pci-iommu_table.c
18522+++ b/arch/x86/kernel/pci-iommu_table.c
18523@@ -2,7 +2,7 @@
18524 #include <asm/iommu_table.h>
18525 #include <linux/string.h>
18526 #include <linux/kallsyms.h>
18527-
18528+#include <linux/sched.h>
18529
18530 #define DEBUG 1
18531
18532diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18533index 1d92a5a..7bc8c29 100644
18534--- a/arch/x86/kernel/process.c
18535+++ b/arch/x86/kernel/process.c
18536@@ -69,16 +69,33 @@ void free_thread_xstate(struct task_struct *tsk)
18537
18538 void free_thread_info(struct thread_info *ti)
18539 {
18540- free_thread_xstate(ti->task);
18541 free_pages((unsigned long)ti, THREAD_ORDER);
18542 }
18543
18544+static struct kmem_cache *task_struct_cachep;
18545+
18546 void arch_task_cache_init(void)
18547 {
18548- task_xstate_cachep =
18549- kmem_cache_create("task_xstate", xstate_size,
18550+ /* create a slab on which task_structs can be allocated */
18551+ task_struct_cachep =
18552+ kmem_cache_create("task_struct", sizeof(struct task_struct),
18553+ ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18554+
18555+ task_xstate_cachep =
18556+ kmem_cache_create("task_xstate", xstate_size,
18557 __alignof__(union thread_xstate),
18558- SLAB_PANIC | SLAB_NOTRACK, NULL);
18559+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18560+}
18561+
18562+struct task_struct *alloc_task_struct_node(int node)
18563+{
18564+ return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18565+}
18566+
18567+void free_task_struct(struct task_struct *task)
18568+{
18569+ free_thread_xstate(task);
18570+ kmem_cache_free(task_struct_cachep, task);
18571 }
18572
18573 /*
18574@@ -91,7 +108,7 @@ void exit_thread(void)
18575 unsigned long *bp = t->io_bitmap_ptr;
18576
18577 if (bp) {
18578- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18579+ struct tss_struct *tss = init_tss + get_cpu();
18580
18581 t->io_bitmap_ptr = NULL;
18582 clear_thread_flag(TIF_IO_BITMAP);
18583@@ -127,7 +144,7 @@ void show_regs_common(void)
18584
18585 printk(KERN_CONT "\n");
18586 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18587- current->pid, current->comm, print_tainted(),
18588+ task_pid_nr(current), current->comm, print_tainted(),
18589 init_utsname()->release,
18590 (int)strcspn(init_utsname()->version, " "),
18591 init_utsname()->version);
18592@@ -141,6 +158,9 @@ void flush_thread(void)
18593 {
18594 struct task_struct *tsk = current;
18595
18596+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18597+ loadsegment(gs, 0);
18598+#endif
18599 flush_ptrace_hw_breakpoint(tsk);
18600 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18601 /*
18602@@ -303,10 +323,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18603 regs.di = (unsigned long) arg;
18604
18605 #ifdef CONFIG_X86_32
18606- regs.ds = __USER_DS;
18607- regs.es = __USER_DS;
18608+ regs.ds = __KERNEL_DS;
18609+ regs.es = __KERNEL_DS;
18610 regs.fs = __KERNEL_PERCPU;
18611- regs.gs = __KERNEL_STACK_CANARY;
18612+ savesegment(gs, regs.gs);
18613 #else
18614 regs.ss = __KERNEL_DS;
18615 #endif
18616@@ -392,7 +412,7 @@ static void __exit_idle(void)
18617 void exit_idle(void)
18618 {
18619 /* idle loop has pid 0 */
18620- if (current->pid)
18621+ if (task_pid_nr(current))
18622 return;
18623 __exit_idle();
18624 }
18625@@ -501,7 +521,7 @@ bool set_pm_idle_to_default(void)
18626
18627 return ret;
18628 }
18629-void stop_this_cpu(void *dummy)
18630+__noreturn void stop_this_cpu(void *dummy)
18631 {
18632 local_irq_disable();
18633 /*
18634@@ -743,16 +763,37 @@ static int __init idle_setup(char *str)
18635 }
18636 early_param("idle", idle_setup);
18637
18638-unsigned long arch_align_stack(unsigned long sp)
18639+#ifdef CONFIG_PAX_RANDKSTACK
18640+void pax_randomize_kstack(struct pt_regs *regs)
18641 {
18642- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18643- sp -= get_random_int() % 8192;
18644- return sp & ~0xf;
18645-}
18646+ struct thread_struct *thread = &current->thread;
18647+ unsigned long time;
18648
18649-unsigned long arch_randomize_brk(struct mm_struct *mm)
18650-{
18651- unsigned long range_end = mm->brk + 0x02000000;
18652- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18653-}
18654+ if (!randomize_va_space)
18655+ return;
18656+
18657+ if (v8086_mode(regs))
18658+ return;
18659
18660+ rdtscl(time);
18661+
18662+ /* P4 seems to return a 0 LSB, ignore it */
18663+#ifdef CONFIG_MPENTIUM4
18664+ time &= 0x3EUL;
18665+ time <<= 2;
18666+#elif defined(CONFIG_X86_64)
18667+ time &= 0xFUL;
18668+ time <<= 4;
18669+#else
18670+ time &= 0x1FUL;
18671+ time <<= 3;
18672+#endif
18673+
18674+ thread->sp0 ^= time;
18675+ load_sp0(init_tss + smp_processor_id(), thread);
18676+
18677+#ifdef CONFIG_X86_64
18678+ percpu_write(kernel_stack, thread->sp0);
18679+#endif
18680+}
18681+#endif
18682diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18683index ae68473..7b0bb71 100644
18684--- a/arch/x86/kernel/process_32.c
18685+++ b/arch/x86/kernel/process_32.c
18686@@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18687 unsigned long thread_saved_pc(struct task_struct *tsk)
18688 {
18689 return ((unsigned long *)tsk->thread.sp)[3];
18690+//XXX return tsk->thread.eip;
18691 }
18692
18693 void __show_regs(struct pt_regs *regs, int all)
18694@@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18695 unsigned long sp;
18696 unsigned short ss, gs;
18697
18698- if (user_mode_vm(regs)) {
18699+ if (user_mode(regs)) {
18700 sp = regs->sp;
18701 ss = regs->ss & 0xffff;
18702- gs = get_user_gs(regs);
18703 } else {
18704 sp = kernel_stack_pointer(regs);
18705 savesegment(ss, ss);
18706- savesegment(gs, gs);
18707 }
18708+ gs = get_user_gs(regs);
18709
18710 show_regs_common();
18711
18712@@ -143,13 +143,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18713 struct task_struct *tsk;
18714 int err;
18715
18716- childregs = task_pt_regs(p);
18717+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18718 *childregs = *regs;
18719 childregs->ax = 0;
18720 childregs->sp = sp;
18721
18722 p->thread.sp = (unsigned long) childregs;
18723 p->thread.sp0 = (unsigned long) (childregs+1);
18724+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18725
18726 p->thread.ip = (unsigned long) ret_from_fork;
18727
18728@@ -240,7 +241,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18729 struct thread_struct *prev = &prev_p->thread,
18730 *next = &next_p->thread;
18731 int cpu = smp_processor_id();
18732- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18733+ struct tss_struct *tss = init_tss + cpu;
18734 fpu_switch_t fpu;
18735
18736 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18737@@ -264,6 +265,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18738 */
18739 lazy_save_gs(prev->gs);
18740
18741+#ifdef CONFIG_PAX_MEMORY_UDEREF
18742+ __set_fs(task_thread_info(next_p)->addr_limit);
18743+#endif
18744+
18745 /*
18746 * Load the per-thread Thread-Local Storage descriptor.
18747 */
18748@@ -294,6 +299,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18749 */
18750 arch_end_context_switch(next_p);
18751
18752+ percpu_write(current_task, next_p);
18753+ percpu_write(current_tinfo, &next_p->tinfo);
18754+
18755 /*
18756 * Restore %gs if needed (which is common)
18757 */
18758@@ -302,8 +310,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18759
18760 switch_fpu_finish(next_p, fpu);
18761
18762- percpu_write(current_task, next_p);
18763-
18764 return prev_p;
18765 }
18766
18767@@ -333,4 +339,3 @@ unsigned long get_wchan(struct task_struct *p)
18768 } while (count++ < 16);
18769 return 0;
18770 }
18771-
18772diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18773index 43d8b48..c45d566 100644
18774--- a/arch/x86/kernel/process_64.c
18775+++ b/arch/x86/kernel/process_64.c
18776@@ -162,8 +162,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18777 struct pt_regs *childregs;
18778 struct task_struct *me = current;
18779
18780- childregs = ((struct pt_regs *)
18781- (THREAD_SIZE + task_stack_page(p))) - 1;
18782+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18783 *childregs = *regs;
18784
18785 childregs->ax = 0;
18786@@ -175,6 +174,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18787 p->thread.sp = (unsigned long) childregs;
18788 p->thread.sp0 = (unsigned long) (childregs+1);
18789 p->thread.usersp = me->thread.usersp;
18790+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18791
18792 set_tsk_thread_flag(p, TIF_FORK);
18793
18794@@ -280,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18795 struct thread_struct *prev = &prev_p->thread;
18796 struct thread_struct *next = &next_p->thread;
18797 int cpu = smp_processor_id();
18798- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18799+ struct tss_struct *tss = init_tss + cpu;
18800 unsigned fsindex, gsindex;
18801 fpu_switch_t fpu;
18802
18803@@ -362,10 +362,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18804 prev->usersp = percpu_read(old_rsp);
18805 percpu_write(old_rsp, next->usersp);
18806 percpu_write(current_task, next_p);
18807+ percpu_write(current_tinfo, &next_p->tinfo);
18808
18809- percpu_write(kernel_stack,
18810- (unsigned long)task_stack_page(next_p) +
18811- THREAD_SIZE - KERNEL_STACK_OFFSET);
18812+ percpu_write(kernel_stack, next->sp0);
18813
18814 /*
18815 * Now maybe reload the debug registers and handle I/O bitmaps
18816@@ -434,12 +433,11 @@ unsigned long get_wchan(struct task_struct *p)
18817 if (!p || p == current || p->state == TASK_RUNNING)
18818 return 0;
18819 stack = (unsigned long)task_stack_page(p);
18820- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18821+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18822 return 0;
18823 fp = *(u64 *)(p->thread.sp);
18824 do {
18825- if (fp < (unsigned long)stack ||
18826- fp >= (unsigned long)stack+THREAD_SIZE)
18827+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18828 return 0;
18829 ip = *(u64 *)(fp+8);
18830 if (!in_sched_functions(ip))
18831diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18832index cf11783..e7ce551 100644
18833--- a/arch/x86/kernel/ptrace.c
18834+++ b/arch/x86/kernel/ptrace.c
18835@@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18836 unsigned long addr, unsigned long data)
18837 {
18838 int ret;
18839- unsigned long __user *datap = (unsigned long __user *)data;
18840+ unsigned long __user *datap = (__force unsigned long __user *)data;
18841
18842 switch (request) {
18843 /* read the word at location addr in the USER area. */
18844@@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18845 if ((int) addr < 0)
18846 return -EIO;
18847 ret = do_get_thread_area(child, addr,
18848- (struct user_desc __user *)data);
18849+ (__force struct user_desc __user *) data);
18850 break;
18851
18852 case PTRACE_SET_THREAD_AREA:
18853 if ((int) addr < 0)
18854 return -EIO;
18855 ret = do_set_thread_area(child, addr,
18856- (struct user_desc __user *)data, 0);
18857+ (__force struct user_desc __user *) data, 0);
18858 break;
18859 #endif
18860
18861@@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18862 memset(info, 0, sizeof(*info));
18863 info->si_signo = SIGTRAP;
18864 info->si_code = si_code;
18865- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18866+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18867 }
18868
18869 void user_single_step_siginfo(struct task_struct *tsk,
18870@@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18871 # define IS_IA32 0
18872 #endif
18873
18874+#ifdef CONFIG_GRKERNSEC_SETXID
18875+extern void gr_delayed_cred_worker(void);
18876+#endif
18877+
18878 /*
18879 * We must return the syscall number to actually look up in the table.
18880 * This can be -1L to skip running any syscall at all.
18881@@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18882 {
18883 long ret = 0;
18884
18885+#ifdef CONFIG_GRKERNSEC_SETXID
18886+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18887+ gr_delayed_cred_worker();
18888+#endif
18889+
18890 /*
18891 * If we stepped into a sysenter/syscall insn, it trapped in
18892 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18893@@ -1506,6 +1515,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18894 {
18895 bool step;
18896
18897+#ifdef CONFIG_GRKERNSEC_SETXID
18898+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18899+ gr_delayed_cred_worker();
18900+#endif
18901+
18902 audit_syscall_exit(regs);
18903
18904 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18905diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18906index 42eb330..139955c 100644
18907--- a/arch/x86/kernel/pvclock.c
18908+++ b/arch/x86/kernel/pvclock.c
18909@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18910 return pv_tsc_khz;
18911 }
18912
18913-static atomic64_t last_value = ATOMIC64_INIT(0);
18914+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18915
18916 void pvclock_resume(void)
18917 {
18918- atomic64_set(&last_value, 0);
18919+ atomic64_set_unchecked(&last_value, 0);
18920 }
18921
18922 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18923@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18924 * updating at the same time, and one of them could be slightly behind,
18925 * making the assumption that last_value always go forward fail to hold.
18926 */
18927- last = atomic64_read(&last_value);
18928+ last = atomic64_read_unchecked(&last_value);
18929 do {
18930 if (ret < last)
18931 return last;
18932- last = atomic64_cmpxchg(&last_value, last, ret);
18933+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18934 } while (unlikely(last != ret));
18935
18936 return ret;
18937diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18938index 3034ee5..7cfbfa6 100644
18939--- a/arch/x86/kernel/reboot.c
18940+++ b/arch/x86/kernel/reboot.c
18941@@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18942 EXPORT_SYMBOL(pm_power_off);
18943
18944 static const struct desc_ptr no_idt = {};
18945-static int reboot_mode;
18946+static unsigned short reboot_mode;
18947 enum reboot_type reboot_type = BOOT_ACPI;
18948 int reboot_force;
18949
18950@@ -335,13 +335,17 @@ core_initcall(reboot_init);
18951 extern const unsigned char machine_real_restart_asm[];
18952 extern const u64 machine_real_restart_gdt[3];
18953
18954-void machine_real_restart(unsigned int type)
18955+__noreturn void machine_real_restart(unsigned int type)
18956 {
18957 void *restart_va;
18958 unsigned long restart_pa;
18959- void (*restart_lowmem)(unsigned int);
18960+ void (* __noreturn restart_lowmem)(unsigned int);
18961 u64 *lowmem_gdt;
18962
18963+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18964+ struct desc_struct *gdt;
18965+#endif
18966+
18967 local_irq_disable();
18968
18969 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18970@@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18971 boot)". This seems like a fairly standard thing that gets set by
18972 REBOOT.COM programs, and the previous reset routine did this
18973 too. */
18974- *((unsigned short *)0x472) = reboot_mode;
18975+ *(unsigned short *)(__va(0x472)) = reboot_mode;
18976
18977 /* Patch the GDT in the low memory trampoline */
18978 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18979
18980 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18981 restart_pa = virt_to_phys(restart_va);
18982- restart_lowmem = (void (*)(unsigned int))restart_pa;
18983+ restart_lowmem = (void *)restart_pa;
18984
18985 /* GDT[0]: GDT self-pointer */
18986 lowmem_gdt[0] =
18987@@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18988 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18989
18990 /* Jump to the identity-mapped low memory code */
18991+
18992+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18993+ gdt = get_cpu_gdt_table(smp_processor_id());
18994+ pax_open_kernel();
18995+#ifdef CONFIG_PAX_MEMORY_UDEREF
18996+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18997+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18998+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18999+#endif
19000+#ifdef CONFIG_PAX_KERNEXEC
19001+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
19002+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
19003+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
19004+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
19005+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
19006+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
19007+#endif
19008+ pax_close_kernel();
19009+#endif
19010+
19011+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19012+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
19013+ unreachable();
19014+#else
19015 restart_lowmem(type);
19016+#endif
19017+
19018 }
19019 #ifdef CONFIG_APM_MODULE
19020 EXPORT_SYMBOL(machine_real_restart);
19021@@ -564,7 +594,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
19022 * try to force a triple fault and then cycle between hitting the keyboard
19023 * controller and doing that
19024 */
19025-static void native_machine_emergency_restart(void)
19026+__noreturn static void native_machine_emergency_restart(void)
19027 {
19028 int i;
19029 int attempt = 0;
19030@@ -688,13 +718,13 @@ void native_machine_shutdown(void)
19031 #endif
19032 }
19033
19034-static void __machine_emergency_restart(int emergency)
19035+static __noreturn void __machine_emergency_restart(int emergency)
19036 {
19037 reboot_emergency = emergency;
19038 machine_ops.emergency_restart();
19039 }
19040
19041-static void native_machine_restart(char *__unused)
19042+static __noreturn void native_machine_restart(char *__unused)
19043 {
19044 printk("machine restart\n");
19045
19046@@ -703,7 +733,7 @@ static void native_machine_restart(char *__unused)
19047 __machine_emergency_restart(0);
19048 }
19049
19050-static void native_machine_halt(void)
19051+static __noreturn void native_machine_halt(void)
19052 {
19053 /* stop other cpus and apics */
19054 machine_shutdown();
19055@@ -714,7 +744,7 @@ static void native_machine_halt(void)
19056 stop_this_cpu(NULL);
19057 }
19058
19059-static void native_machine_power_off(void)
19060+__noreturn static void native_machine_power_off(void)
19061 {
19062 if (pm_power_off) {
19063 if (!reboot_force)
19064@@ -723,6 +753,7 @@ static void native_machine_power_off(void)
19065 }
19066 /* a fallback in case there is no PM info available */
19067 tboot_shutdown(TB_SHUTDOWN_HALT);
19068+ unreachable();
19069 }
19070
19071 struct machine_ops machine_ops = {
19072diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19073index 7a6f3b3..bed145d7 100644
19074--- a/arch/x86/kernel/relocate_kernel_64.S
19075+++ b/arch/x86/kernel/relocate_kernel_64.S
19076@@ -11,6 +11,7 @@
19077 #include <asm/kexec.h>
19078 #include <asm/processor-flags.h>
19079 #include <asm/pgtable_types.h>
19080+#include <asm/alternative-asm.h>
19081
19082 /*
19083 * Must be relocatable PIC code callable as a C function
19084@@ -160,13 +161,14 @@ identity_mapped:
19085 xorq %rbp, %rbp
19086 xorq %r8, %r8
19087 xorq %r9, %r9
19088- xorq %r10, %r9
19089+ xorq %r10, %r10
19090 xorq %r11, %r11
19091 xorq %r12, %r12
19092 xorq %r13, %r13
19093 xorq %r14, %r14
19094 xorq %r15, %r15
19095
19096+ pax_force_retaddr 0, 1
19097 ret
19098
19099 1:
19100diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19101index 1a29015..712f324 100644
19102--- a/arch/x86/kernel/setup.c
19103+++ b/arch/x86/kernel/setup.c
19104@@ -447,7 +447,7 @@ static void __init parse_setup_data(void)
19105
19106 switch (data->type) {
19107 case SETUP_E820_EXT:
19108- parse_e820_ext(data);
19109+ parse_e820_ext((struct setup_data __force_kernel *)data);
19110 break;
19111 case SETUP_DTB:
19112 add_dtb(pa_data);
19113@@ -639,7 +639,7 @@ static void __init trim_bios_range(void)
19114 * area (640->1Mb) as ram even though it is not.
19115 * take them out.
19116 */
19117- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19118+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19119 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19120 }
19121
19122@@ -763,14 +763,14 @@ void __init setup_arch(char **cmdline_p)
19123
19124 if (!boot_params.hdr.root_flags)
19125 root_mountflags &= ~MS_RDONLY;
19126- init_mm.start_code = (unsigned long) _text;
19127- init_mm.end_code = (unsigned long) _etext;
19128+ init_mm.start_code = ktla_ktva((unsigned long) _text);
19129+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
19130 init_mm.end_data = (unsigned long) _edata;
19131 init_mm.brk = _brk_end;
19132
19133- code_resource.start = virt_to_phys(_text);
19134- code_resource.end = virt_to_phys(_etext)-1;
19135- data_resource.start = virt_to_phys(_etext);
19136+ code_resource.start = virt_to_phys(ktla_ktva(_text));
19137+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19138+ data_resource.start = virt_to_phys(_sdata);
19139 data_resource.end = virt_to_phys(_edata)-1;
19140 bss_resource.start = virt_to_phys(&__bss_start);
19141 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19142diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19143index 5a98aa2..2f9288d 100644
19144--- a/arch/x86/kernel/setup_percpu.c
19145+++ b/arch/x86/kernel/setup_percpu.c
19146@@ -21,19 +21,17 @@
19147 #include <asm/cpu.h>
19148 #include <asm/stackprotector.h>
19149
19150-DEFINE_PER_CPU(int, cpu_number);
19151+#ifdef CONFIG_SMP
19152+DEFINE_PER_CPU(unsigned int, cpu_number);
19153 EXPORT_PER_CPU_SYMBOL(cpu_number);
19154+#endif
19155
19156-#ifdef CONFIG_X86_64
19157 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19158-#else
19159-#define BOOT_PERCPU_OFFSET 0
19160-#endif
19161
19162 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19163 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19164
19165-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19166+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19167 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19168 };
19169 EXPORT_SYMBOL(__per_cpu_offset);
19170@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19171 {
19172 #ifdef CONFIG_X86_32
19173 struct desc_struct gdt;
19174+ unsigned long base = per_cpu_offset(cpu);
19175
19176- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19177- 0x2 | DESCTYPE_S, 0x8);
19178- gdt.s = 1;
19179+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19180+ 0x83 | DESCTYPE_S, 0xC);
19181 write_gdt_entry(get_cpu_gdt_table(cpu),
19182 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19183 #endif
19184@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19185 /* alrighty, percpu areas up and running */
19186 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19187 for_each_possible_cpu(cpu) {
19188+#ifdef CONFIG_CC_STACKPROTECTOR
19189+#ifdef CONFIG_X86_32
19190+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
19191+#endif
19192+#endif
19193 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19194 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19195 per_cpu(cpu_number, cpu) = cpu;
19196@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19197 */
19198 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19199 #endif
19200+#ifdef CONFIG_CC_STACKPROTECTOR
19201+#ifdef CONFIG_X86_32
19202+ if (!cpu)
19203+ per_cpu(stack_canary.canary, cpu) = canary;
19204+#endif
19205+#endif
19206 /*
19207 * Up to this point, the boot CPU has been using .init.data
19208 * area. Reload any changed state for the boot CPU.
19209diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19210index 115eac4..c0591d5 100644
19211--- a/arch/x86/kernel/signal.c
19212+++ b/arch/x86/kernel/signal.c
19213@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
19214 * Align the stack pointer according to the i386 ABI,
19215 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19216 */
19217- sp = ((sp + 4) & -16ul) - 4;
19218+ sp = ((sp - 12) & -16ul) - 4;
19219 #else /* !CONFIG_X86_32 */
19220 sp = round_down(sp, 16) - 8;
19221 #endif
19222@@ -241,11 +241,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19223 * Return an always-bogus address instead so we will die with SIGSEGV.
19224 */
19225 if (onsigstack && !likely(on_sig_stack(sp)))
19226- return (void __user *)-1L;
19227+ return (__force void __user *)-1L;
19228
19229 /* save i387 state */
19230 if (used_math() && save_i387_xstate(*fpstate) < 0)
19231- return (void __user *)-1L;
19232+ return (__force void __user *)-1L;
19233
19234 return (void __user *)sp;
19235 }
19236@@ -300,9 +300,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19237 }
19238
19239 if (current->mm->context.vdso)
19240- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19241+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19242 else
19243- restorer = &frame->retcode;
19244+ restorer = (void __user *)&frame->retcode;
19245 if (ka->sa.sa_flags & SA_RESTORER)
19246 restorer = ka->sa.sa_restorer;
19247
19248@@ -316,7 +316,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19249 * reasons and because gdb uses it as a signature to notice
19250 * signal handler stack frames.
19251 */
19252- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19253+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19254
19255 if (err)
19256 return -EFAULT;
19257@@ -370,7 +370,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19258 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19259
19260 /* Set up to return from userspace. */
19261- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19262+ if (current->mm->context.vdso)
19263+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19264+ else
19265+ restorer = (void __user *)&frame->retcode;
19266 if (ka->sa.sa_flags & SA_RESTORER)
19267 restorer = ka->sa.sa_restorer;
19268 put_user_ex(restorer, &frame->pretcode);
19269@@ -382,7 +385,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19270 * reasons and because gdb uses it as a signature to notice
19271 * signal handler stack frames.
19272 */
19273- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19274+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19275 } put_user_catch(err);
19276
19277 if (err)
19278@@ -773,7 +776,7 @@ static void do_signal(struct pt_regs *regs)
19279 * X86_32: vm86 regs switched out by assembly code before reaching
19280 * here, so testing against kernel CS suffices.
19281 */
19282- if (!user_mode(regs))
19283+ if (!user_mode_novm(regs))
19284 return;
19285
19286 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
19287diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19288index 6e1e406..edfb7cb 100644
19289--- a/arch/x86/kernel/smpboot.c
19290+++ b/arch/x86/kernel/smpboot.c
19291@@ -699,17 +699,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
19292 set_idle_for_cpu(cpu, c_idle.idle);
19293 do_rest:
19294 per_cpu(current_task, cpu) = c_idle.idle;
19295+ per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
19296 #ifdef CONFIG_X86_32
19297 /* Stack for startup_32 can be just as for start_secondary onwards */
19298 irq_ctx_init(cpu);
19299 #else
19300 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
19301 initial_gs = per_cpu_offset(cpu);
19302- per_cpu(kernel_stack, cpu) =
19303- (unsigned long)task_stack_page(c_idle.idle) -
19304- KERNEL_STACK_OFFSET + THREAD_SIZE;
19305+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
19306 #endif
19307+
19308+ pax_open_kernel();
19309 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19310+ pax_close_kernel();
19311+
19312 initial_code = (unsigned long)start_secondary;
19313 stack_start = c_idle.idle->thread.sp;
19314
19315@@ -851,6 +854,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
19316
19317 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19318
19319+#ifdef CONFIG_PAX_PER_CPU_PGD
19320+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19321+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19322+ KERNEL_PGD_PTRS);
19323+#endif
19324+
19325 err = do_boot_cpu(apicid, cpu);
19326 if (err) {
19327 pr_debug("do_boot_cpu failed %d\n", err);
19328diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19329index c346d11..d43b163 100644
19330--- a/arch/x86/kernel/step.c
19331+++ b/arch/x86/kernel/step.c
19332@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19333 struct desc_struct *desc;
19334 unsigned long base;
19335
19336- seg &= ~7UL;
19337+ seg >>= 3;
19338
19339 mutex_lock(&child->mm->context.lock);
19340- if (unlikely((seg >> 3) >= child->mm->context.size))
19341+ if (unlikely(seg >= child->mm->context.size))
19342 addr = -1L; /* bogus selector, access would fault */
19343 else {
19344 desc = child->mm->context.ldt + seg;
19345@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19346 addr += base;
19347 }
19348 mutex_unlock(&child->mm->context.lock);
19349- }
19350+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19351+ addr = ktla_ktva(addr);
19352
19353 return addr;
19354 }
19355@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19356 unsigned char opcode[15];
19357 unsigned long addr = convert_ip_to_linear(child, regs);
19358
19359+ if (addr == -EINVAL)
19360+ return 0;
19361+
19362 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19363 for (i = 0; i < copied; i++) {
19364 switch (opcode[i]) {
19365diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19366index 0b0cb5f..db6b9ed 100644
19367--- a/arch/x86/kernel/sys_i386_32.c
19368+++ b/arch/x86/kernel/sys_i386_32.c
19369@@ -24,17 +24,224 @@
19370
19371 #include <asm/syscalls.h>
19372
19373-/*
19374- * Do a system call from kernel instead of calling sys_execve so we
19375- * end up with proper pt_regs.
19376- */
19377-int kernel_execve(const char *filename,
19378- const char *const argv[],
19379- const char *const envp[])
19380+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19381 {
19382- long __res;
19383- asm volatile ("int $0x80"
19384- : "=a" (__res)
19385- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19386- return __res;
19387+ unsigned long pax_task_size = TASK_SIZE;
19388+
19389+#ifdef CONFIG_PAX_SEGMEXEC
19390+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19391+ pax_task_size = SEGMEXEC_TASK_SIZE;
19392+#endif
19393+
19394+ if (len > pax_task_size || addr > pax_task_size - len)
19395+ return -EINVAL;
19396+
19397+ return 0;
19398+}
19399+
19400+unsigned long
19401+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19402+ unsigned long len, unsigned long pgoff, unsigned long flags)
19403+{
19404+ struct mm_struct *mm = current->mm;
19405+ struct vm_area_struct *vma;
19406+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19407+
19408+#ifdef CONFIG_PAX_SEGMEXEC
19409+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19410+ pax_task_size = SEGMEXEC_TASK_SIZE;
19411+#endif
19412+
19413+ pax_task_size -= PAGE_SIZE;
19414+
19415+ if (len > pax_task_size)
19416+ return -ENOMEM;
19417+
19418+ if (flags & MAP_FIXED)
19419+ return addr;
19420+
19421+#ifdef CONFIG_PAX_RANDMMAP
19422+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19423+#endif
19424+
19425+ if (addr) {
19426+ addr = PAGE_ALIGN(addr);
19427+ if (pax_task_size - len >= addr) {
19428+ vma = find_vma(mm, addr);
19429+ if (check_heap_stack_gap(vma, addr, len))
19430+ return addr;
19431+ }
19432+ }
19433+ if (len > mm->cached_hole_size) {
19434+ start_addr = addr = mm->free_area_cache;
19435+ } else {
19436+ start_addr = addr = mm->mmap_base;
19437+ mm->cached_hole_size = 0;
19438+ }
19439+
19440+#ifdef CONFIG_PAX_PAGEEXEC
19441+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19442+ start_addr = 0x00110000UL;
19443+
19444+#ifdef CONFIG_PAX_RANDMMAP
19445+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19446+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19447+#endif
19448+
19449+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19450+ start_addr = addr = mm->mmap_base;
19451+ else
19452+ addr = start_addr;
19453+ }
19454+#endif
19455+
19456+full_search:
19457+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19458+ /* At this point: (!vma || addr < vma->vm_end). */
19459+ if (pax_task_size - len < addr) {
19460+ /*
19461+ * Start a new search - just in case we missed
19462+ * some holes.
19463+ */
19464+ if (start_addr != mm->mmap_base) {
19465+ start_addr = addr = mm->mmap_base;
19466+ mm->cached_hole_size = 0;
19467+ goto full_search;
19468+ }
19469+ return -ENOMEM;
19470+ }
19471+ if (check_heap_stack_gap(vma, addr, len))
19472+ break;
19473+ if (addr + mm->cached_hole_size < vma->vm_start)
19474+ mm->cached_hole_size = vma->vm_start - addr;
19475+ addr = vma->vm_end;
19476+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19477+ start_addr = addr = mm->mmap_base;
19478+ mm->cached_hole_size = 0;
19479+ goto full_search;
19480+ }
19481+ }
19482+
19483+ /*
19484+ * Remember the place where we stopped the search:
19485+ */
19486+ mm->free_area_cache = addr + len;
19487+ return addr;
19488+}
19489+
19490+unsigned long
19491+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19492+ const unsigned long len, const unsigned long pgoff,
19493+ const unsigned long flags)
19494+{
19495+ struct vm_area_struct *vma;
19496+ struct mm_struct *mm = current->mm;
19497+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19498+
19499+#ifdef CONFIG_PAX_SEGMEXEC
19500+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19501+ pax_task_size = SEGMEXEC_TASK_SIZE;
19502+#endif
19503+
19504+ pax_task_size -= PAGE_SIZE;
19505+
19506+ /* requested length too big for entire address space */
19507+ if (len > pax_task_size)
19508+ return -ENOMEM;
19509+
19510+ if (flags & MAP_FIXED)
19511+ return addr;
19512+
19513+#ifdef CONFIG_PAX_PAGEEXEC
19514+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19515+ goto bottomup;
19516+#endif
19517+
19518+#ifdef CONFIG_PAX_RANDMMAP
19519+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19520+#endif
19521+
19522+ /* requesting a specific address */
19523+ if (addr) {
19524+ addr = PAGE_ALIGN(addr);
19525+ if (pax_task_size - len >= addr) {
19526+ vma = find_vma(mm, addr);
19527+ if (check_heap_stack_gap(vma, addr, len))
19528+ return addr;
19529+ }
19530+ }
19531+
19532+ /* check if free_area_cache is useful for us */
19533+ if (len <= mm->cached_hole_size) {
19534+ mm->cached_hole_size = 0;
19535+ mm->free_area_cache = mm->mmap_base;
19536+ }
19537+
19538+ /* either no address requested or can't fit in requested address hole */
19539+ addr = mm->free_area_cache;
19540+
19541+ /* make sure it can fit in the remaining address space */
19542+ if (addr > len) {
19543+ vma = find_vma(mm, addr-len);
19544+ if (check_heap_stack_gap(vma, addr - len, len))
19545+ /* remember the address as a hint for next time */
19546+ return (mm->free_area_cache = addr-len);
19547+ }
19548+
19549+ if (mm->mmap_base < len)
19550+ goto bottomup;
19551+
19552+ addr = mm->mmap_base-len;
19553+
19554+ do {
19555+ /*
19556+ * Lookup failure means no vma is above this address,
19557+ * else if new region fits below vma->vm_start,
19558+ * return with success:
19559+ */
19560+ vma = find_vma(mm, addr);
19561+ if (check_heap_stack_gap(vma, addr, len))
19562+ /* remember the address as a hint for next time */
19563+ return (mm->free_area_cache = addr);
19564+
19565+ /* remember the largest hole we saw so far */
19566+ if (addr + mm->cached_hole_size < vma->vm_start)
19567+ mm->cached_hole_size = vma->vm_start - addr;
19568+
19569+ /* try just below the current vma->vm_start */
19570+ addr = skip_heap_stack_gap(vma, len);
19571+ } while (!IS_ERR_VALUE(addr));
19572+
19573+bottomup:
19574+ /*
19575+ * A failed mmap() very likely causes application failure,
19576+ * so fall back to the bottom-up function here. This scenario
19577+ * can happen with large stack limits and large mmap()
19578+ * allocations.
19579+ */
19580+
19581+#ifdef CONFIG_PAX_SEGMEXEC
19582+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19583+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19584+ else
19585+#endif
19586+
19587+ mm->mmap_base = TASK_UNMAPPED_BASE;
19588+
19589+#ifdef CONFIG_PAX_RANDMMAP
19590+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19591+ mm->mmap_base += mm->delta_mmap;
19592+#endif
19593+
19594+ mm->free_area_cache = mm->mmap_base;
19595+ mm->cached_hole_size = ~0UL;
19596+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19597+ /*
19598+ * Restore the topdown base:
19599+ */
19600+ mm->mmap_base = base;
19601+ mm->free_area_cache = base;
19602+ mm->cached_hole_size = ~0UL;
19603+
19604+ return addr;
19605 }
19606diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19607index b4d3c39..82bb73b 100644
19608--- a/arch/x86/kernel/sys_x86_64.c
19609+++ b/arch/x86/kernel/sys_x86_64.c
19610@@ -95,8 +95,8 @@ out:
19611 return error;
19612 }
19613
19614-static void find_start_end(unsigned long flags, unsigned long *begin,
19615- unsigned long *end)
19616+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19617+ unsigned long *begin, unsigned long *end)
19618 {
19619 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19620 unsigned long new_begin;
19621@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19622 *begin = new_begin;
19623 }
19624 } else {
19625- *begin = TASK_UNMAPPED_BASE;
19626+ *begin = mm->mmap_base;
19627 *end = TASK_SIZE;
19628 }
19629 }
19630@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19631 if (flags & MAP_FIXED)
19632 return addr;
19633
19634- find_start_end(flags, &begin, &end);
19635+ find_start_end(mm, flags, &begin, &end);
19636
19637 if (len > end)
19638 return -ENOMEM;
19639
19640+#ifdef CONFIG_PAX_RANDMMAP
19641+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19642+#endif
19643+
19644 if (addr) {
19645 addr = PAGE_ALIGN(addr);
19646 vma = find_vma(mm, addr);
19647- if (end - len >= addr &&
19648- (!vma || addr + len <= vma->vm_start))
19649+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19650 return addr;
19651 }
19652 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19653@@ -172,7 +175,7 @@ full_search:
19654 }
19655 return -ENOMEM;
19656 }
19657- if (!vma || addr + len <= vma->vm_start) {
19658+ if (check_heap_stack_gap(vma, addr, len)) {
19659 /*
19660 * Remember the place where we stopped the search:
19661 */
19662@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19663 {
19664 struct vm_area_struct *vma;
19665 struct mm_struct *mm = current->mm;
19666- unsigned long addr = addr0, start_addr;
19667+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19668
19669 /* requested length too big for entire address space */
19670 if (len > TASK_SIZE)
19671@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19672 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19673 goto bottomup;
19674
19675+#ifdef CONFIG_PAX_RANDMMAP
19676+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19677+#endif
19678+
19679 /* requesting a specific address */
19680 if (addr) {
19681 addr = PAGE_ALIGN(addr);
19682- vma = find_vma(mm, addr);
19683- if (TASK_SIZE - len >= addr &&
19684- (!vma || addr + len <= vma->vm_start))
19685- return addr;
19686+ if (TASK_SIZE - len >= addr) {
19687+ vma = find_vma(mm, addr);
19688+ if (check_heap_stack_gap(vma, addr, len))
19689+ return addr;
19690+ }
19691 }
19692
19693 /* check if free_area_cache is useful for us */
19694@@ -240,7 +248,7 @@ try_again:
19695 * return with success:
19696 */
19697 vma = find_vma(mm, addr);
19698- if (!vma || addr+len <= vma->vm_start)
19699+ if (check_heap_stack_gap(vma, addr, len))
19700 /* remember the address as a hint for next time */
19701 return mm->free_area_cache = addr;
19702
19703@@ -249,8 +257,8 @@ try_again:
19704 mm->cached_hole_size = vma->vm_start - addr;
19705
19706 /* try just below the current vma->vm_start */
19707- addr = vma->vm_start-len;
19708- } while (len < vma->vm_start);
19709+ addr = skip_heap_stack_gap(vma, len);
19710+ } while (!IS_ERR_VALUE(addr));
19711
19712 fail:
19713 /*
19714@@ -270,13 +278,21 @@ bottomup:
19715 * can happen with large stack limits and large mmap()
19716 * allocations.
19717 */
19718+ mm->mmap_base = TASK_UNMAPPED_BASE;
19719+
19720+#ifdef CONFIG_PAX_RANDMMAP
19721+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19722+ mm->mmap_base += mm->delta_mmap;
19723+#endif
19724+
19725+ mm->free_area_cache = mm->mmap_base;
19726 mm->cached_hole_size = ~0UL;
19727- mm->free_area_cache = TASK_UNMAPPED_BASE;
19728 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19729 /*
19730 * Restore the topdown base:
19731 */
19732- mm->free_area_cache = mm->mmap_base;
19733+ mm->mmap_base = base;
19734+ mm->free_area_cache = base;
19735 mm->cached_hole_size = ~0UL;
19736
19737 return addr;
19738diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19739index 6410744..79758f0 100644
19740--- a/arch/x86/kernel/tboot.c
19741+++ b/arch/x86/kernel/tboot.c
19742@@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19743
19744 void tboot_shutdown(u32 shutdown_type)
19745 {
19746- void (*shutdown)(void);
19747+ void (* __noreturn shutdown)(void);
19748
19749 if (!tboot_enabled())
19750 return;
19751@@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19752
19753 switch_to_tboot_pt();
19754
19755- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19756+ shutdown = (void *)tboot->shutdown_entry;
19757 shutdown();
19758
19759 /* should not reach here */
19760@@ -299,7 +299,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19761 return 0;
19762 }
19763
19764-static atomic_t ap_wfs_count;
19765+static atomic_unchecked_t ap_wfs_count;
19766
19767 static int tboot_wait_for_aps(int num_aps)
19768 {
19769@@ -323,9 +323,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19770 {
19771 switch (action) {
19772 case CPU_DYING:
19773- atomic_inc(&ap_wfs_count);
19774+ atomic_inc_unchecked(&ap_wfs_count);
19775 if (num_online_cpus() == 1)
19776- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19777+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19778 return NOTIFY_BAD;
19779 break;
19780 }
19781@@ -344,7 +344,7 @@ static __init int tboot_late_init(void)
19782
19783 tboot_create_trampoline();
19784
19785- atomic_set(&ap_wfs_count, 0);
19786+ atomic_set_unchecked(&ap_wfs_count, 0);
19787 register_hotcpu_notifier(&tboot_cpu_notifier);
19788
19789 acpi_os_set_prepare_sleep(&tboot_sleep);
19790diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19791index c6eba2b..3303326 100644
19792--- a/arch/x86/kernel/time.c
19793+++ b/arch/x86/kernel/time.c
19794@@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19795 {
19796 unsigned long pc = instruction_pointer(regs);
19797
19798- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19799+ if (!user_mode(regs) && in_lock_functions(pc)) {
19800 #ifdef CONFIG_FRAME_POINTER
19801- return *(unsigned long *)(regs->bp + sizeof(long));
19802+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19803 #else
19804 unsigned long *sp =
19805 (unsigned long *)kernel_stack_pointer(regs);
19806@@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19807 * or above a saved flags. Eflags has bits 22-31 zero,
19808 * kernel addresses don't.
19809 */
19810+
19811+#ifdef CONFIG_PAX_KERNEXEC
19812+ return ktla_ktva(sp[0]);
19813+#else
19814 if (sp[0] >> 22)
19815 return sp[0];
19816 if (sp[1] >> 22)
19817 return sp[1];
19818 #endif
19819+
19820+#endif
19821 }
19822 return pc;
19823 }
19824diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19825index 9d9d2f9..ed344e4 100644
19826--- a/arch/x86/kernel/tls.c
19827+++ b/arch/x86/kernel/tls.c
19828@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19829 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19830 return -EINVAL;
19831
19832+#ifdef CONFIG_PAX_SEGMEXEC
19833+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19834+ return -EINVAL;
19835+#endif
19836+
19837 set_tls_desc(p, idx, &info, 1);
19838
19839 return 0;
19840diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19841index 451c0a7..e57f551 100644
19842--- a/arch/x86/kernel/trampoline_32.S
19843+++ b/arch/x86/kernel/trampoline_32.S
19844@@ -32,6 +32,12 @@
19845 #include <asm/segment.h>
19846 #include <asm/page_types.h>
19847
19848+#ifdef CONFIG_PAX_KERNEXEC
19849+#define ta(X) (X)
19850+#else
19851+#define ta(X) ((X) - __PAGE_OFFSET)
19852+#endif
19853+
19854 #ifdef CONFIG_SMP
19855
19856 .section ".x86_trampoline","a"
19857@@ -62,7 +68,7 @@ r_base = .
19858 inc %ax # protected mode (PE) bit
19859 lmsw %ax # into protected mode
19860 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19861- ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19862+ ljmpl $__BOOT_CS, $ta(startup_32_smp)
19863
19864 # These need to be in the same 64K segment as the above;
19865 # hence we don't use the boot_gdt_descr defined in head.S
19866diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19867index 09ff517..df19fbff 100644
19868--- a/arch/x86/kernel/trampoline_64.S
19869+++ b/arch/x86/kernel/trampoline_64.S
19870@@ -90,7 +90,7 @@ startup_32:
19871 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19872 movl %eax, %ds
19873
19874- movl $X86_CR4_PAE, %eax
19875+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19876 movl %eax, %cr4 # Enable PAE mode
19877
19878 # Setup trampoline 4 level pagetables
19879@@ -138,7 +138,7 @@ tidt:
19880 # so the kernel can live anywhere
19881 .balign 4
19882 tgdt:
19883- .short tgdt_end - tgdt # gdt limit
19884+ .short tgdt_end - tgdt - 1 # gdt limit
19885 .long tgdt - r_base
19886 .short 0
19887 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19888diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19889index ff9281f1..30cb4ac 100644
19890--- a/arch/x86/kernel/traps.c
19891+++ b/arch/x86/kernel/traps.c
19892@@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19893
19894 /* Do we ignore FPU interrupts ? */
19895 char ignore_fpu_irq;
19896-
19897-/*
19898- * The IDT has to be page-aligned to simplify the Pentium
19899- * F0 0F bug workaround.
19900- */
19901-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19902 #endif
19903
19904 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19905@@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19906 }
19907
19908 static void __kprobes
19909-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19910+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19911 long error_code, siginfo_t *info)
19912 {
19913 struct task_struct *tsk = current;
19914
19915 #ifdef CONFIG_X86_32
19916- if (regs->flags & X86_VM_MASK) {
19917+ if (v8086_mode(regs)) {
19918 /*
19919 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19920 * On nmi (interrupt 2), do_trap should not be called.
19921@@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19922 }
19923 #endif
19924
19925- if (!user_mode(regs))
19926+ if (!user_mode_novm(regs))
19927 goto kernel_trap;
19928
19929 #ifdef CONFIG_X86_32
19930@@ -148,7 +142,7 @@ trap_signal:
19931 printk_ratelimit()) {
19932 printk(KERN_INFO
19933 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19934- tsk->comm, tsk->pid, str,
19935+ tsk->comm, task_pid_nr(tsk), str,
19936 regs->ip, regs->sp, error_code);
19937 print_vma_addr(" in ", regs->ip);
19938 printk("\n");
19939@@ -165,8 +159,20 @@ kernel_trap:
19940 if (!fixup_exception(regs)) {
19941 tsk->thread.error_code = error_code;
19942 tsk->thread.trap_nr = trapnr;
19943+
19944+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19945+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19946+ str = "PAX: suspicious stack segment fault";
19947+#endif
19948+
19949 die(str, regs, error_code);
19950 }
19951+
19952+#ifdef CONFIG_PAX_REFCOUNT
19953+ if (trapnr == 4)
19954+ pax_report_refcount_overflow(regs);
19955+#endif
19956+
19957 return;
19958
19959 #ifdef CONFIG_X86_32
19960@@ -259,14 +265,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19961 conditional_sti(regs);
19962
19963 #ifdef CONFIG_X86_32
19964- if (regs->flags & X86_VM_MASK)
19965+ if (v8086_mode(regs))
19966 goto gp_in_vm86;
19967 #endif
19968
19969 tsk = current;
19970- if (!user_mode(regs))
19971+ if (!user_mode_novm(regs))
19972 goto gp_in_kernel;
19973
19974+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19975+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19976+ struct mm_struct *mm = tsk->mm;
19977+ unsigned long limit;
19978+
19979+ down_write(&mm->mmap_sem);
19980+ limit = mm->context.user_cs_limit;
19981+ if (limit < TASK_SIZE) {
19982+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19983+ up_write(&mm->mmap_sem);
19984+ return;
19985+ }
19986+ up_write(&mm->mmap_sem);
19987+ }
19988+#endif
19989+
19990 tsk->thread.error_code = error_code;
19991 tsk->thread.trap_nr = X86_TRAP_GP;
19992
19993@@ -299,6 +321,13 @@ gp_in_kernel:
19994 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19995 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19996 return;
19997+
19998+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19999+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
20000+ die("PAX: suspicious general protection fault", regs, error_code);
20001+ else
20002+#endif
20003+
20004 die("general protection fault", regs, error_code);
20005 }
20006
20007@@ -425,7 +454,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20008 /* It's safe to allow irq's after DR6 has been saved */
20009 preempt_conditional_sti(regs);
20010
20011- if (regs->flags & X86_VM_MASK) {
20012+ if (v8086_mode(regs)) {
20013 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
20014 X86_TRAP_DB);
20015 preempt_conditional_cli(regs);
20016@@ -440,7 +469,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20017 * We already checked v86 mode above, so we can check for kernel mode
20018 * by just checking the CPL of CS.
20019 */
20020- if ((dr6 & DR_STEP) && !user_mode(regs)) {
20021+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
20022 tsk->thread.debugreg6 &= ~DR_STEP;
20023 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
20024 regs->flags &= ~X86_EFLAGS_TF;
20025@@ -471,7 +500,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
20026 return;
20027 conditional_sti(regs);
20028
20029- if (!user_mode_vm(regs))
20030+ if (!user_mode(regs))
20031 {
20032 if (!fixup_exception(regs)) {
20033 task->thread.error_code = error_code;
20034diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
20035index b9242ba..50c5edd 100644
20036--- a/arch/x86/kernel/verify_cpu.S
20037+++ b/arch/x86/kernel/verify_cpu.S
20038@@ -20,6 +20,7 @@
20039 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
20040 * arch/x86/kernel/trampoline_64.S: secondary processor verification
20041 * arch/x86/kernel/head_32.S: processor startup
20042+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
20043 *
20044 * verify_cpu, returns the status of longmode and SSE in register %eax.
20045 * 0: Success 1: Failure
20046diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
20047index 255f58a..5e91150 100644
20048--- a/arch/x86/kernel/vm86_32.c
20049+++ b/arch/x86/kernel/vm86_32.c
20050@@ -41,6 +41,7 @@
20051 #include <linux/ptrace.h>
20052 #include <linux/audit.h>
20053 #include <linux/stddef.h>
20054+#include <linux/grsecurity.h>
20055
20056 #include <asm/uaccess.h>
20057 #include <asm/io.h>
20058@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
20059 do_exit(SIGSEGV);
20060 }
20061
20062- tss = &per_cpu(init_tss, get_cpu());
20063+ tss = init_tss + get_cpu();
20064 current->thread.sp0 = current->thread.saved_sp0;
20065 current->thread.sysenter_cs = __KERNEL_CS;
20066 load_sp0(tss, &current->thread);
20067@@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
20068 struct task_struct *tsk;
20069 int tmp, ret = -EPERM;
20070
20071+#ifdef CONFIG_GRKERNSEC_VM86
20072+ if (!capable(CAP_SYS_RAWIO)) {
20073+ gr_handle_vm86();
20074+ goto out;
20075+ }
20076+#endif
20077+
20078 tsk = current;
20079 if (tsk->thread.saved_sp0)
20080 goto out;
20081@@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
20082 int tmp, ret;
20083 struct vm86plus_struct __user *v86;
20084
20085+#ifdef CONFIG_GRKERNSEC_VM86
20086+ if (!capable(CAP_SYS_RAWIO)) {
20087+ gr_handle_vm86();
20088+ ret = -EPERM;
20089+ goto out;
20090+ }
20091+#endif
20092+
20093 tsk = current;
20094 switch (cmd) {
20095 case VM86_REQUEST_IRQ:
20096@@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20097 tsk->thread.saved_fs = info->regs32->fs;
20098 tsk->thread.saved_gs = get_user_gs(info->regs32);
20099
20100- tss = &per_cpu(init_tss, get_cpu());
20101+ tss = init_tss + get_cpu();
20102 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20103 if (cpu_has_sep)
20104 tsk->thread.sysenter_cs = 0;
20105@@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20106 goto cannot_handle;
20107 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20108 goto cannot_handle;
20109- intr_ptr = (unsigned long __user *) (i << 2);
20110+ intr_ptr = (__force unsigned long __user *) (i << 2);
20111 if (get_user(segoffs, intr_ptr))
20112 goto cannot_handle;
20113 if ((segoffs >> 16) == BIOSSEG)
20114diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20115index 0f703f1..3b426f3 100644
20116--- a/arch/x86/kernel/vmlinux.lds.S
20117+++ b/arch/x86/kernel/vmlinux.lds.S
20118@@ -26,6 +26,13 @@
20119 #include <asm/page_types.h>
20120 #include <asm/cache.h>
20121 #include <asm/boot.h>
20122+#include <asm/segment.h>
20123+
20124+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20125+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20126+#else
20127+#define __KERNEL_TEXT_OFFSET 0
20128+#endif
20129
20130 #undef i386 /* in case the preprocessor is a 32bit one */
20131
20132@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20133
20134 PHDRS {
20135 text PT_LOAD FLAGS(5); /* R_E */
20136+#ifdef CONFIG_X86_32
20137+ module PT_LOAD FLAGS(5); /* R_E */
20138+#endif
20139+#ifdef CONFIG_XEN
20140+ rodata PT_LOAD FLAGS(5); /* R_E */
20141+#else
20142+ rodata PT_LOAD FLAGS(4); /* R__ */
20143+#endif
20144 data PT_LOAD FLAGS(6); /* RW_ */
20145-#ifdef CONFIG_X86_64
20146+ init.begin PT_LOAD FLAGS(6); /* RW_ */
20147 #ifdef CONFIG_SMP
20148 percpu PT_LOAD FLAGS(6); /* RW_ */
20149 #endif
20150+ text.init PT_LOAD FLAGS(5); /* R_E */
20151+ text.exit PT_LOAD FLAGS(5); /* R_E */
20152 init PT_LOAD FLAGS(7); /* RWE */
20153-#endif
20154 note PT_NOTE FLAGS(0); /* ___ */
20155 }
20156
20157 SECTIONS
20158 {
20159 #ifdef CONFIG_X86_32
20160- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20161- phys_startup_32 = startup_32 - LOAD_OFFSET;
20162+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20163 #else
20164- . = __START_KERNEL;
20165- phys_startup_64 = startup_64 - LOAD_OFFSET;
20166+ . = __START_KERNEL;
20167 #endif
20168
20169 /* Text and read-only data */
20170- .text : AT(ADDR(.text) - LOAD_OFFSET) {
20171- _text = .;
20172+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20173 /* bootstrapping code */
20174+#ifdef CONFIG_X86_32
20175+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20176+#else
20177+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20178+#endif
20179+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20180+ _text = .;
20181 HEAD_TEXT
20182 #ifdef CONFIG_X86_32
20183 . = ALIGN(PAGE_SIZE);
20184@@ -108,13 +128,48 @@ SECTIONS
20185 IRQENTRY_TEXT
20186 *(.fixup)
20187 *(.gnu.warning)
20188- /* End of text section */
20189- _etext = .;
20190 } :text = 0x9090
20191
20192- NOTES :text :note
20193+ . += __KERNEL_TEXT_OFFSET;
20194
20195- EXCEPTION_TABLE(16) :text = 0x9090
20196+#ifdef CONFIG_X86_32
20197+ . = ALIGN(PAGE_SIZE);
20198+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20199+
20200+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20201+ MODULES_EXEC_VADDR = .;
20202+ BYTE(0)
20203+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20204+ . = ALIGN(HPAGE_SIZE) - 1;
20205+ MODULES_EXEC_END = .;
20206+#endif
20207+
20208+ } :module
20209+#endif
20210+
20211+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20212+ /* End of text section */
20213+ BYTE(0)
20214+ _etext = . - __KERNEL_TEXT_OFFSET;
20215+ }
20216+
20217+#ifdef CONFIG_X86_32
20218+ . = ALIGN(PAGE_SIZE);
20219+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20220+ *(.idt)
20221+ . = ALIGN(PAGE_SIZE);
20222+ *(.empty_zero_page)
20223+ *(.initial_pg_fixmap)
20224+ *(.initial_pg_pmd)
20225+ *(.initial_page_table)
20226+ *(.swapper_pg_dir)
20227+ } :rodata
20228+#endif
20229+
20230+ . = ALIGN(PAGE_SIZE);
20231+ NOTES :rodata :note
20232+
20233+ EXCEPTION_TABLE(16) :rodata
20234
20235 #if defined(CONFIG_DEBUG_RODATA)
20236 /* .text should occupy whole number of pages */
20237@@ -126,16 +181,20 @@ SECTIONS
20238
20239 /* Data */
20240 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20241+
20242+#ifdef CONFIG_PAX_KERNEXEC
20243+ . = ALIGN(HPAGE_SIZE);
20244+#else
20245+ . = ALIGN(PAGE_SIZE);
20246+#endif
20247+
20248 /* Start of data section */
20249 _sdata = .;
20250
20251 /* init_task */
20252 INIT_TASK_DATA(THREAD_SIZE)
20253
20254-#ifdef CONFIG_X86_32
20255- /* 32 bit has nosave before _edata */
20256 NOSAVE_DATA
20257-#endif
20258
20259 PAGE_ALIGNED_DATA(PAGE_SIZE)
20260
20261@@ -176,12 +235,19 @@ SECTIONS
20262 #endif /* CONFIG_X86_64 */
20263
20264 /* Init code and data - will be freed after init */
20265- . = ALIGN(PAGE_SIZE);
20266 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20267+ BYTE(0)
20268+
20269+#ifdef CONFIG_PAX_KERNEXEC
20270+ . = ALIGN(HPAGE_SIZE);
20271+#else
20272+ . = ALIGN(PAGE_SIZE);
20273+#endif
20274+
20275 __init_begin = .; /* paired with __init_end */
20276- }
20277+ } :init.begin
20278
20279-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20280+#ifdef CONFIG_SMP
20281 /*
20282 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20283 * output PHDR, so the next output section - .init.text - should
20284@@ -190,12 +256,27 @@ SECTIONS
20285 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20286 #endif
20287
20288- INIT_TEXT_SECTION(PAGE_SIZE)
20289-#ifdef CONFIG_X86_64
20290- :init
20291-#endif
20292+ . = ALIGN(PAGE_SIZE);
20293+ init_begin = .;
20294+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20295+ VMLINUX_SYMBOL(_sinittext) = .;
20296+ INIT_TEXT
20297+ VMLINUX_SYMBOL(_einittext) = .;
20298+ . = ALIGN(PAGE_SIZE);
20299+ } :text.init
20300
20301- INIT_DATA_SECTION(16)
20302+ /*
20303+ * .exit.text is discard at runtime, not link time, to deal with
20304+ * references from .altinstructions and .eh_frame
20305+ */
20306+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20307+ EXIT_TEXT
20308+ . = ALIGN(16);
20309+ } :text.exit
20310+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20311+
20312+ . = ALIGN(PAGE_SIZE);
20313+ INIT_DATA_SECTION(16) :init
20314
20315 /*
20316 * Code and data for a variety of lowlevel trampolines, to be
20317@@ -269,19 +350,12 @@ SECTIONS
20318 }
20319
20320 . = ALIGN(8);
20321- /*
20322- * .exit.text is discard at runtime, not link time, to deal with
20323- * references from .altinstructions and .eh_frame
20324- */
20325- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20326- EXIT_TEXT
20327- }
20328
20329 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20330 EXIT_DATA
20331 }
20332
20333-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20334+#ifndef CONFIG_SMP
20335 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20336 #endif
20337
20338@@ -300,16 +374,10 @@ SECTIONS
20339 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20340 __smp_locks = .;
20341 *(.smp_locks)
20342- . = ALIGN(PAGE_SIZE);
20343 __smp_locks_end = .;
20344+ . = ALIGN(PAGE_SIZE);
20345 }
20346
20347-#ifdef CONFIG_X86_64
20348- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20349- NOSAVE_DATA
20350- }
20351-#endif
20352-
20353 /* BSS */
20354 . = ALIGN(PAGE_SIZE);
20355 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20356@@ -325,6 +393,7 @@ SECTIONS
20357 __brk_base = .;
20358 . += 64 * 1024; /* 64k alignment slop space */
20359 *(.brk_reservation) /* areas brk users have reserved */
20360+ . = ALIGN(HPAGE_SIZE);
20361 __brk_limit = .;
20362 }
20363
20364@@ -351,13 +420,12 @@ SECTIONS
20365 * for the boot processor.
20366 */
20367 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20368-INIT_PER_CPU(gdt_page);
20369 INIT_PER_CPU(irq_stack_union);
20370
20371 /*
20372 * Build-time check on the image size:
20373 */
20374-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20375+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20376 "kernel image bigger than KERNEL_IMAGE_SIZE");
20377
20378 #ifdef CONFIG_SMP
20379diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20380index 7515cf0..331a1a0 100644
20381--- a/arch/x86/kernel/vsyscall_64.c
20382+++ b/arch/x86/kernel/vsyscall_64.c
20383@@ -54,15 +54,13 @@
20384 DEFINE_VVAR(int, vgetcpu_mode);
20385 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20386
20387-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20388+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20389
20390 static int __init vsyscall_setup(char *str)
20391 {
20392 if (str) {
20393 if (!strcmp("emulate", str))
20394 vsyscall_mode = EMULATE;
20395- else if (!strcmp("native", str))
20396- vsyscall_mode = NATIVE;
20397 else if (!strcmp("none", str))
20398 vsyscall_mode = NONE;
20399 else
20400@@ -206,7 +204,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20401
20402 tsk = current;
20403 if (seccomp_mode(&tsk->seccomp))
20404- do_exit(SIGKILL);
20405+ do_group_exit(SIGKILL);
20406
20407 /*
20408 * With a real vsyscall, page faults cause SIGSEGV. We want to
20409@@ -278,8 +276,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20410 return true;
20411
20412 sigsegv:
20413- force_sig(SIGSEGV, current);
20414- return true;
20415+ do_group_exit(SIGKILL);
20416 }
20417
20418 /*
20419@@ -332,10 +329,7 @@ void __init map_vsyscall(void)
20420 extern char __vvar_page;
20421 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20422
20423- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20424- vsyscall_mode == NATIVE
20425- ? PAGE_KERNEL_VSYSCALL
20426- : PAGE_KERNEL_VVAR);
20427+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20428 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20429 (unsigned long)VSYSCALL_START);
20430
20431diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20432index 9796c2f..f686fbf 100644
20433--- a/arch/x86/kernel/x8664_ksyms_64.c
20434+++ b/arch/x86/kernel/x8664_ksyms_64.c
20435@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20436 EXPORT_SYMBOL(copy_user_generic_string);
20437 EXPORT_SYMBOL(copy_user_generic_unrolled);
20438 EXPORT_SYMBOL(__copy_user_nocache);
20439-EXPORT_SYMBOL(_copy_from_user);
20440-EXPORT_SYMBOL(_copy_to_user);
20441
20442 EXPORT_SYMBOL(copy_page);
20443 EXPORT_SYMBOL(clear_page);
20444diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20445index e62728e..5fc3a07 100644
20446--- a/arch/x86/kernel/xsave.c
20447+++ b/arch/x86/kernel/xsave.c
20448@@ -131,7 +131,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20449 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20450 return -EINVAL;
20451
20452- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20453+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20454 fx_sw_user->extended_size -
20455 FP_XSTATE_MAGIC2_SIZE));
20456 if (err)
20457@@ -267,7 +267,7 @@ fx_only:
20458 * the other extended state.
20459 */
20460 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20461- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20462+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20463 }
20464
20465 /*
20466@@ -296,7 +296,7 @@ int restore_i387_xstate(void __user *buf)
20467 if (use_xsave())
20468 err = restore_user_xstate(buf);
20469 else
20470- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20471+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20472 buf);
20473 if (unlikely(err)) {
20474 /*
20475diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20476index 9fed5be..18fd595 100644
20477--- a/arch/x86/kvm/cpuid.c
20478+++ b/arch/x86/kvm/cpuid.c
20479@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20480 struct kvm_cpuid2 *cpuid,
20481 struct kvm_cpuid_entry2 __user *entries)
20482 {
20483- int r;
20484+ int r, i;
20485
20486 r = -E2BIG;
20487 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20488 goto out;
20489 r = -EFAULT;
20490- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20491- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20492+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20493 goto out;
20494+ for (i = 0; i < cpuid->nent; ++i) {
20495+ struct kvm_cpuid_entry2 cpuid_entry;
20496+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20497+ goto out;
20498+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20499+ }
20500 vcpu->arch.cpuid_nent = cpuid->nent;
20501 kvm_apic_set_version(vcpu);
20502 kvm_x86_ops->cpuid_update(vcpu);
20503@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20504 struct kvm_cpuid2 *cpuid,
20505 struct kvm_cpuid_entry2 __user *entries)
20506 {
20507- int r;
20508+ int r, i;
20509
20510 r = -E2BIG;
20511 if (cpuid->nent < vcpu->arch.cpuid_nent)
20512 goto out;
20513 r = -EFAULT;
20514- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20515- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20516+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20517 goto out;
20518+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20519+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20520+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20521+ goto out;
20522+ }
20523 return 0;
20524
20525 out:
20526diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20527index 8375622..b7bca1a 100644
20528--- a/arch/x86/kvm/emulate.c
20529+++ b/arch/x86/kvm/emulate.c
20530@@ -252,6 +252,7 @@ struct gprefix {
20531
20532 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20533 do { \
20534+ unsigned long _tmp; \
20535 __asm__ __volatile__ ( \
20536 _PRE_EFLAGS("0", "4", "2") \
20537 _op _suffix " %"_x"3,%1; " \
20538@@ -266,8 +267,6 @@ struct gprefix {
20539 /* Raw emulation: instruction has two explicit operands. */
20540 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20541 do { \
20542- unsigned long _tmp; \
20543- \
20544 switch ((ctxt)->dst.bytes) { \
20545 case 2: \
20546 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20547@@ -283,7 +282,6 @@ struct gprefix {
20548
20549 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20550 do { \
20551- unsigned long _tmp; \
20552 switch ((ctxt)->dst.bytes) { \
20553 case 1: \
20554 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20555diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20556index 8584322..17d5955 100644
20557--- a/arch/x86/kvm/lapic.c
20558+++ b/arch/x86/kvm/lapic.c
20559@@ -54,7 +54,7 @@
20560 #define APIC_BUS_CYCLE_NS 1
20561
20562 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20563-#define apic_debug(fmt, arg...)
20564+#define apic_debug(fmt, arg...) do {} while (0)
20565
20566 #define APIC_LVT_NUM 6
20567 /* 14 is the version for Xeon and Pentium 8.4.8*/
20568diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20569index df5a703..63748a7 100644
20570--- a/arch/x86/kvm/paging_tmpl.h
20571+++ b/arch/x86/kvm/paging_tmpl.h
20572@@ -197,7 +197,7 @@ retry_walk:
20573 if (unlikely(kvm_is_error_hva(host_addr)))
20574 goto error;
20575
20576- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20577+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20578 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20579 goto error;
20580
20581diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20582index e334389..6839087 100644
20583--- a/arch/x86/kvm/svm.c
20584+++ b/arch/x86/kvm/svm.c
20585@@ -3509,7 +3509,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20586 int cpu = raw_smp_processor_id();
20587
20588 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20589+
20590+ pax_open_kernel();
20591 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20592+ pax_close_kernel();
20593+
20594 load_TR_desc();
20595 }
20596
20597@@ -3887,6 +3891,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20598 #endif
20599 #endif
20600
20601+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20602+ __set_fs(current_thread_info()->addr_limit);
20603+#endif
20604+
20605 reload_tss(vcpu);
20606
20607 local_irq_disable();
20608diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20609index 4ff0ab9..2ff68d3 100644
20610--- a/arch/x86/kvm/vmx.c
20611+++ b/arch/x86/kvm/vmx.c
20612@@ -1303,7 +1303,11 @@ static void reload_tss(void)
20613 struct desc_struct *descs;
20614
20615 descs = (void *)gdt->address;
20616+
20617+ pax_open_kernel();
20618 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20619+ pax_close_kernel();
20620+
20621 load_TR_desc();
20622 }
20623
20624@@ -2625,8 +2629,11 @@ static __init int hardware_setup(void)
20625 if (!cpu_has_vmx_flexpriority())
20626 flexpriority_enabled = 0;
20627
20628- if (!cpu_has_vmx_tpr_shadow())
20629- kvm_x86_ops->update_cr8_intercept = NULL;
20630+ if (!cpu_has_vmx_tpr_shadow()) {
20631+ pax_open_kernel();
20632+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20633+ pax_close_kernel();
20634+ }
20635
20636 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20637 kvm_disable_largepages();
20638@@ -3642,7 +3649,7 @@ static void vmx_set_constant_host_state(void)
20639 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20640
20641 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20642- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20643+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20644
20645 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20646 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20647@@ -6180,6 +6187,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20648 "jmp .Lkvm_vmx_return \n\t"
20649 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20650 ".Lkvm_vmx_return: "
20651+
20652+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20653+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20654+ ".Lkvm_vmx_return2: "
20655+#endif
20656+
20657 /* Save guest registers, load host registers, keep flags */
20658 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20659 "pop %0 \n\t"
20660@@ -6228,6 +6241,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20661 #endif
20662 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20663 [wordsize]"i"(sizeof(ulong))
20664+
20665+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20666+ ,[cs]"i"(__KERNEL_CS)
20667+#endif
20668+
20669 : "cc", "memory"
20670 , R"ax", R"bx", R"di", R"si"
20671 #ifdef CONFIG_X86_64
20672@@ -6256,7 +6274,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20673 }
20674 }
20675
20676- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20677+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20678+
20679+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20680+ loadsegment(fs, __KERNEL_PERCPU);
20681+#endif
20682+
20683+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20684+ __set_fs(current_thread_info()->addr_limit);
20685+#endif
20686+
20687 vmx->loaded_vmcs->launched = 1;
20688
20689 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20690diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20691index 185a2b8..866d2a6 100644
20692--- a/arch/x86/kvm/x86.c
20693+++ b/arch/x86/kvm/x86.c
20694@@ -1357,8 +1357,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20695 {
20696 struct kvm *kvm = vcpu->kvm;
20697 int lm = is_long_mode(vcpu);
20698- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20699- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20700+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20701+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20702 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20703 : kvm->arch.xen_hvm_config.blob_size_32;
20704 u32 page_num = data & ~PAGE_MASK;
20705@@ -2213,6 +2213,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20706 if (n < msr_list.nmsrs)
20707 goto out;
20708 r = -EFAULT;
20709+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20710+ goto out;
20711 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20712 num_msrs_to_save * sizeof(u32)))
20713 goto out;
20714@@ -2338,7 +2340,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20715 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20716 struct kvm_interrupt *irq)
20717 {
20718- if (irq->irq < 0 || irq->irq >= 256)
20719+ if (irq->irq >= 256)
20720 return -EINVAL;
20721 if (irqchip_in_kernel(vcpu->kvm))
20722 return -ENXIO;
20723@@ -4860,7 +4862,7 @@ static void kvm_set_mmio_spte_mask(void)
20724 kvm_mmu_set_mmio_spte_mask(mask);
20725 }
20726
20727-int kvm_arch_init(void *opaque)
20728+int kvm_arch_init(const void *opaque)
20729 {
20730 int r;
20731 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20732diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20733index 642d880..44e0f3f 100644
20734--- a/arch/x86/lguest/boot.c
20735+++ b/arch/x86/lguest/boot.c
20736@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20737 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20738 * Launcher to reboot us.
20739 */
20740-static void lguest_restart(char *reason)
20741+static __noreturn void lguest_restart(char *reason)
20742 {
20743 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20744+ BUG();
20745 }
20746
20747 /*G:050
20748diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20749index 00933d5..3a64af9 100644
20750--- a/arch/x86/lib/atomic64_386_32.S
20751+++ b/arch/x86/lib/atomic64_386_32.S
20752@@ -48,6 +48,10 @@ BEGIN(read)
20753 movl (v), %eax
20754 movl 4(v), %edx
20755 RET_ENDP
20756+BEGIN(read_unchecked)
20757+ movl (v), %eax
20758+ movl 4(v), %edx
20759+RET_ENDP
20760 #undef v
20761
20762 #define v %esi
20763@@ -55,6 +59,10 @@ BEGIN(set)
20764 movl %ebx, (v)
20765 movl %ecx, 4(v)
20766 RET_ENDP
20767+BEGIN(set_unchecked)
20768+ movl %ebx, (v)
20769+ movl %ecx, 4(v)
20770+RET_ENDP
20771 #undef v
20772
20773 #define v %esi
20774@@ -70,6 +78,20 @@ RET_ENDP
20775 BEGIN(add)
20776 addl %eax, (v)
20777 adcl %edx, 4(v)
20778+
20779+#ifdef CONFIG_PAX_REFCOUNT
20780+ jno 0f
20781+ subl %eax, (v)
20782+ sbbl %edx, 4(v)
20783+ int $4
20784+0:
20785+ _ASM_EXTABLE(0b, 0b)
20786+#endif
20787+
20788+RET_ENDP
20789+BEGIN(add_unchecked)
20790+ addl %eax, (v)
20791+ adcl %edx, 4(v)
20792 RET_ENDP
20793 #undef v
20794
20795@@ -77,6 +99,24 @@ RET_ENDP
20796 BEGIN(add_return)
20797 addl (v), %eax
20798 adcl 4(v), %edx
20799+
20800+#ifdef CONFIG_PAX_REFCOUNT
20801+ into
20802+1234:
20803+ _ASM_EXTABLE(1234b, 2f)
20804+#endif
20805+
20806+ movl %eax, (v)
20807+ movl %edx, 4(v)
20808+
20809+#ifdef CONFIG_PAX_REFCOUNT
20810+2:
20811+#endif
20812+
20813+RET_ENDP
20814+BEGIN(add_return_unchecked)
20815+ addl (v), %eax
20816+ adcl 4(v), %edx
20817 movl %eax, (v)
20818 movl %edx, 4(v)
20819 RET_ENDP
20820@@ -86,6 +126,20 @@ RET_ENDP
20821 BEGIN(sub)
20822 subl %eax, (v)
20823 sbbl %edx, 4(v)
20824+
20825+#ifdef CONFIG_PAX_REFCOUNT
20826+ jno 0f
20827+ addl %eax, (v)
20828+ adcl %edx, 4(v)
20829+ int $4
20830+0:
20831+ _ASM_EXTABLE(0b, 0b)
20832+#endif
20833+
20834+RET_ENDP
20835+BEGIN(sub_unchecked)
20836+ subl %eax, (v)
20837+ sbbl %edx, 4(v)
20838 RET_ENDP
20839 #undef v
20840
20841@@ -96,6 +150,27 @@ BEGIN(sub_return)
20842 sbbl $0, %edx
20843 addl (v), %eax
20844 adcl 4(v), %edx
20845+
20846+#ifdef CONFIG_PAX_REFCOUNT
20847+ into
20848+1234:
20849+ _ASM_EXTABLE(1234b, 2f)
20850+#endif
20851+
20852+ movl %eax, (v)
20853+ movl %edx, 4(v)
20854+
20855+#ifdef CONFIG_PAX_REFCOUNT
20856+2:
20857+#endif
20858+
20859+RET_ENDP
20860+BEGIN(sub_return_unchecked)
20861+ negl %edx
20862+ negl %eax
20863+ sbbl $0, %edx
20864+ addl (v), %eax
20865+ adcl 4(v), %edx
20866 movl %eax, (v)
20867 movl %edx, 4(v)
20868 RET_ENDP
20869@@ -105,6 +180,20 @@ RET_ENDP
20870 BEGIN(inc)
20871 addl $1, (v)
20872 adcl $0, 4(v)
20873+
20874+#ifdef CONFIG_PAX_REFCOUNT
20875+ jno 0f
20876+ subl $1, (v)
20877+ sbbl $0, 4(v)
20878+ int $4
20879+0:
20880+ _ASM_EXTABLE(0b, 0b)
20881+#endif
20882+
20883+RET_ENDP
20884+BEGIN(inc_unchecked)
20885+ addl $1, (v)
20886+ adcl $0, 4(v)
20887 RET_ENDP
20888 #undef v
20889
20890@@ -114,6 +203,26 @@ BEGIN(inc_return)
20891 movl 4(v), %edx
20892 addl $1, %eax
20893 adcl $0, %edx
20894+
20895+#ifdef CONFIG_PAX_REFCOUNT
20896+ into
20897+1234:
20898+ _ASM_EXTABLE(1234b, 2f)
20899+#endif
20900+
20901+ movl %eax, (v)
20902+ movl %edx, 4(v)
20903+
20904+#ifdef CONFIG_PAX_REFCOUNT
20905+2:
20906+#endif
20907+
20908+RET_ENDP
20909+BEGIN(inc_return_unchecked)
20910+ movl (v), %eax
20911+ movl 4(v), %edx
20912+ addl $1, %eax
20913+ adcl $0, %edx
20914 movl %eax, (v)
20915 movl %edx, 4(v)
20916 RET_ENDP
20917@@ -123,6 +232,20 @@ RET_ENDP
20918 BEGIN(dec)
20919 subl $1, (v)
20920 sbbl $0, 4(v)
20921+
20922+#ifdef CONFIG_PAX_REFCOUNT
20923+ jno 0f
20924+ addl $1, (v)
20925+ adcl $0, 4(v)
20926+ int $4
20927+0:
20928+ _ASM_EXTABLE(0b, 0b)
20929+#endif
20930+
20931+RET_ENDP
20932+BEGIN(dec_unchecked)
20933+ subl $1, (v)
20934+ sbbl $0, 4(v)
20935 RET_ENDP
20936 #undef v
20937
20938@@ -132,6 +255,26 @@ BEGIN(dec_return)
20939 movl 4(v), %edx
20940 subl $1, %eax
20941 sbbl $0, %edx
20942+
20943+#ifdef CONFIG_PAX_REFCOUNT
20944+ into
20945+1234:
20946+ _ASM_EXTABLE(1234b, 2f)
20947+#endif
20948+
20949+ movl %eax, (v)
20950+ movl %edx, 4(v)
20951+
20952+#ifdef CONFIG_PAX_REFCOUNT
20953+2:
20954+#endif
20955+
20956+RET_ENDP
20957+BEGIN(dec_return_unchecked)
20958+ movl (v), %eax
20959+ movl 4(v), %edx
20960+ subl $1, %eax
20961+ sbbl $0, %edx
20962 movl %eax, (v)
20963 movl %edx, 4(v)
20964 RET_ENDP
20965@@ -143,6 +286,13 @@ BEGIN(add_unless)
20966 adcl %edx, %edi
20967 addl (v), %eax
20968 adcl 4(v), %edx
20969+
20970+#ifdef CONFIG_PAX_REFCOUNT
20971+ into
20972+1234:
20973+ _ASM_EXTABLE(1234b, 2f)
20974+#endif
20975+
20976 cmpl %eax, %ecx
20977 je 3f
20978 1:
20979@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20980 1:
20981 addl $1, %eax
20982 adcl $0, %edx
20983+
20984+#ifdef CONFIG_PAX_REFCOUNT
20985+ into
20986+1234:
20987+ _ASM_EXTABLE(1234b, 2f)
20988+#endif
20989+
20990 movl %eax, (v)
20991 movl %edx, 4(v)
20992 movl $1, %eax
20993@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20994 movl 4(v), %edx
20995 subl $1, %eax
20996 sbbl $0, %edx
20997+
20998+#ifdef CONFIG_PAX_REFCOUNT
20999+ into
21000+1234:
21001+ _ASM_EXTABLE(1234b, 1f)
21002+#endif
21003+
21004 js 1f
21005 movl %eax, (v)
21006 movl %edx, 4(v)
21007diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
21008index f5cc9eb..51fa319 100644
21009--- a/arch/x86/lib/atomic64_cx8_32.S
21010+++ b/arch/x86/lib/atomic64_cx8_32.S
21011@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
21012 CFI_STARTPROC
21013
21014 read64 %ecx
21015+ pax_force_retaddr
21016 ret
21017 CFI_ENDPROC
21018 ENDPROC(atomic64_read_cx8)
21019
21020+ENTRY(atomic64_read_unchecked_cx8)
21021+ CFI_STARTPROC
21022+
21023+ read64 %ecx
21024+ pax_force_retaddr
21025+ ret
21026+ CFI_ENDPROC
21027+ENDPROC(atomic64_read_unchecked_cx8)
21028+
21029 ENTRY(atomic64_set_cx8)
21030 CFI_STARTPROC
21031
21032@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
21033 cmpxchg8b (%esi)
21034 jne 1b
21035
21036+ pax_force_retaddr
21037 ret
21038 CFI_ENDPROC
21039 ENDPROC(atomic64_set_cx8)
21040
21041+ENTRY(atomic64_set_unchecked_cx8)
21042+ CFI_STARTPROC
21043+
21044+1:
21045+/* we don't need LOCK_PREFIX since aligned 64-bit writes
21046+ * are atomic on 586 and newer */
21047+ cmpxchg8b (%esi)
21048+ jne 1b
21049+
21050+ pax_force_retaddr
21051+ ret
21052+ CFI_ENDPROC
21053+ENDPROC(atomic64_set_unchecked_cx8)
21054+
21055 ENTRY(atomic64_xchg_cx8)
21056 CFI_STARTPROC
21057
21058@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21059 cmpxchg8b (%esi)
21060 jne 1b
21061
21062+ pax_force_retaddr
21063 ret
21064 CFI_ENDPROC
21065 ENDPROC(atomic64_xchg_cx8)
21066
21067-.macro addsub_return func ins insc
21068-ENTRY(atomic64_\func\()_return_cx8)
21069+.macro addsub_return func ins insc unchecked=""
21070+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21071 CFI_STARTPROC
21072 SAVE ebp
21073 SAVE ebx
21074@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21075 movl %edx, %ecx
21076 \ins\()l %esi, %ebx
21077 \insc\()l %edi, %ecx
21078+
21079+.ifb \unchecked
21080+#ifdef CONFIG_PAX_REFCOUNT
21081+ into
21082+2:
21083+ _ASM_EXTABLE(2b, 3f)
21084+#endif
21085+.endif
21086+
21087 LOCK_PREFIX
21088 cmpxchg8b (%ebp)
21089 jne 1b
21090-
21091-10:
21092 movl %ebx, %eax
21093 movl %ecx, %edx
21094+
21095+.ifb \unchecked
21096+#ifdef CONFIG_PAX_REFCOUNT
21097+3:
21098+#endif
21099+.endif
21100+
21101 RESTORE edi
21102 RESTORE esi
21103 RESTORE ebx
21104 RESTORE ebp
21105+ pax_force_retaddr
21106 ret
21107 CFI_ENDPROC
21108-ENDPROC(atomic64_\func\()_return_cx8)
21109+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21110 .endm
21111
21112 addsub_return add add adc
21113 addsub_return sub sub sbb
21114+addsub_return add add adc _unchecked
21115+addsub_return sub sub sbb _unchecked
21116
21117-.macro incdec_return func ins insc
21118-ENTRY(atomic64_\func\()_return_cx8)
21119+.macro incdec_return func ins insc unchecked=""
21120+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21121 CFI_STARTPROC
21122 SAVE ebx
21123
21124@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21125 movl %edx, %ecx
21126 \ins\()l $1, %ebx
21127 \insc\()l $0, %ecx
21128+
21129+.ifb \unchecked
21130+#ifdef CONFIG_PAX_REFCOUNT
21131+ into
21132+2:
21133+ _ASM_EXTABLE(2b, 3f)
21134+#endif
21135+.endif
21136+
21137 LOCK_PREFIX
21138 cmpxchg8b (%esi)
21139 jne 1b
21140
21141-10:
21142 movl %ebx, %eax
21143 movl %ecx, %edx
21144+
21145+.ifb \unchecked
21146+#ifdef CONFIG_PAX_REFCOUNT
21147+3:
21148+#endif
21149+.endif
21150+
21151 RESTORE ebx
21152+ pax_force_retaddr
21153 ret
21154 CFI_ENDPROC
21155-ENDPROC(atomic64_\func\()_return_cx8)
21156+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21157 .endm
21158
21159 incdec_return inc add adc
21160 incdec_return dec sub sbb
21161+incdec_return inc add adc _unchecked
21162+incdec_return dec sub sbb _unchecked
21163
21164 ENTRY(atomic64_dec_if_positive_cx8)
21165 CFI_STARTPROC
21166@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21167 movl %edx, %ecx
21168 subl $1, %ebx
21169 sbb $0, %ecx
21170+
21171+#ifdef CONFIG_PAX_REFCOUNT
21172+ into
21173+1234:
21174+ _ASM_EXTABLE(1234b, 2f)
21175+#endif
21176+
21177 js 2f
21178 LOCK_PREFIX
21179 cmpxchg8b (%esi)
21180@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21181 movl %ebx, %eax
21182 movl %ecx, %edx
21183 RESTORE ebx
21184+ pax_force_retaddr
21185 ret
21186 CFI_ENDPROC
21187 ENDPROC(atomic64_dec_if_positive_cx8)
21188@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21189 movl %edx, %ecx
21190 addl %ebp, %ebx
21191 adcl %edi, %ecx
21192+
21193+#ifdef CONFIG_PAX_REFCOUNT
21194+ into
21195+1234:
21196+ _ASM_EXTABLE(1234b, 3f)
21197+#endif
21198+
21199 LOCK_PREFIX
21200 cmpxchg8b (%esi)
21201 jne 1b
21202@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21203 CFI_ADJUST_CFA_OFFSET -8
21204 RESTORE ebx
21205 RESTORE ebp
21206+ pax_force_retaddr
21207 ret
21208 4:
21209 cmpl %edx, 4(%esp)
21210@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21211 xorl %ecx, %ecx
21212 addl $1, %ebx
21213 adcl %edx, %ecx
21214+
21215+#ifdef CONFIG_PAX_REFCOUNT
21216+ into
21217+1234:
21218+ _ASM_EXTABLE(1234b, 3f)
21219+#endif
21220+
21221 LOCK_PREFIX
21222 cmpxchg8b (%esi)
21223 jne 1b
21224@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21225 movl $1, %eax
21226 3:
21227 RESTORE ebx
21228+ pax_force_retaddr
21229 ret
21230 CFI_ENDPROC
21231 ENDPROC(atomic64_inc_not_zero_cx8)
21232diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21233index 78d16a5..fbcf666 100644
21234--- a/arch/x86/lib/checksum_32.S
21235+++ b/arch/x86/lib/checksum_32.S
21236@@ -28,7 +28,8 @@
21237 #include <linux/linkage.h>
21238 #include <asm/dwarf2.h>
21239 #include <asm/errno.h>
21240-
21241+#include <asm/segment.h>
21242+
21243 /*
21244 * computes a partial checksum, e.g. for TCP/UDP fragments
21245 */
21246@@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21247
21248 #define ARGBASE 16
21249 #define FP 12
21250-
21251-ENTRY(csum_partial_copy_generic)
21252+
21253+ENTRY(csum_partial_copy_generic_to_user)
21254 CFI_STARTPROC
21255+
21256+#ifdef CONFIG_PAX_MEMORY_UDEREF
21257+ pushl_cfi %gs
21258+ popl_cfi %es
21259+ jmp csum_partial_copy_generic
21260+#endif
21261+
21262+ENTRY(csum_partial_copy_generic_from_user)
21263+
21264+#ifdef CONFIG_PAX_MEMORY_UDEREF
21265+ pushl_cfi %gs
21266+ popl_cfi %ds
21267+#endif
21268+
21269+ENTRY(csum_partial_copy_generic)
21270 subl $4,%esp
21271 CFI_ADJUST_CFA_OFFSET 4
21272 pushl_cfi %edi
21273@@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
21274 jmp 4f
21275 SRC(1: movw (%esi), %bx )
21276 addl $2, %esi
21277-DST( movw %bx, (%edi) )
21278+DST( movw %bx, %es:(%edi) )
21279 addl $2, %edi
21280 addw %bx, %ax
21281 adcl $0, %eax
21282@@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
21283 SRC(1: movl (%esi), %ebx )
21284 SRC( movl 4(%esi), %edx )
21285 adcl %ebx, %eax
21286-DST( movl %ebx, (%edi) )
21287+DST( movl %ebx, %es:(%edi) )
21288 adcl %edx, %eax
21289-DST( movl %edx, 4(%edi) )
21290+DST( movl %edx, %es:4(%edi) )
21291
21292 SRC( movl 8(%esi), %ebx )
21293 SRC( movl 12(%esi), %edx )
21294 adcl %ebx, %eax
21295-DST( movl %ebx, 8(%edi) )
21296+DST( movl %ebx, %es:8(%edi) )
21297 adcl %edx, %eax
21298-DST( movl %edx, 12(%edi) )
21299+DST( movl %edx, %es:12(%edi) )
21300
21301 SRC( movl 16(%esi), %ebx )
21302 SRC( movl 20(%esi), %edx )
21303 adcl %ebx, %eax
21304-DST( movl %ebx, 16(%edi) )
21305+DST( movl %ebx, %es:16(%edi) )
21306 adcl %edx, %eax
21307-DST( movl %edx, 20(%edi) )
21308+DST( movl %edx, %es:20(%edi) )
21309
21310 SRC( movl 24(%esi), %ebx )
21311 SRC( movl 28(%esi), %edx )
21312 adcl %ebx, %eax
21313-DST( movl %ebx, 24(%edi) )
21314+DST( movl %ebx, %es:24(%edi) )
21315 adcl %edx, %eax
21316-DST( movl %edx, 28(%edi) )
21317+DST( movl %edx, %es:28(%edi) )
21318
21319 lea 32(%esi), %esi
21320 lea 32(%edi), %edi
21321@@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21322 shrl $2, %edx # This clears CF
21323 SRC(3: movl (%esi), %ebx )
21324 adcl %ebx, %eax
21325-DST( movl %ebx, (%edi) )
21326+DST( movl %ebx, %es:(%edi) )
21327 lea 4(%esi), %esi
21328 lea 4(%edi), %edi
21329 dec %edx
21330@@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21331 jb 5f
21332 SRC( movw (%esi), %cx )
21333 leal 2(%esi), %esi
21334-DST( movw %cx, (%edi) )
21335+DST( movw %cx, %es:(%edi) )
21336 leal 2(%edi), %edi
21337 je 6f
21338 shll $16,%ecx
21339 SRC(5: movb (%esi), %cl )
21340-DST( movb %cl, (%edi) )
21341+DST( movb %cl, %es:(%edi) )
21342 6: addl %ecx, %eax
21343 adcl $0, %eax
21344 7:
21345@@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21346
21347 6001:
21348 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21349- movl $-EFAULT, (%ebx)
21350+ movl $-EFAULT, %ss:(%ebx)
21351
21352 # zero the complete destination - computing the rest
21353 # is too much work
21354@@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21355
21356 6002:
21357 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21358- movl $-EFAULT,(%ebx)
21359+ movl $-EFAULT,%ss:(%ebx)
21360 jmp 5000b
21361
21362 .previous
21363
21364+ pushl_cfi %ss
21365+ popl_cfi %ds
21366+ pushl_cfi %ss
21367+ popl_cfi %es
21368 popl_cfi %ebx
21369 CFI_RESTORE ebx
21370 popl_cfi %esi
21371@@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21372 popl_cfi %ecx # equivalent to addl $4,%esp
21373 ret
21374 CFI_ENDPROC
21375-ENDPROC(csum_partial_copy_generic)
21376+ENDPROC(csum_partial_copy_generic_to_user)
21377
21378 #else
21379
21380 /* Version for PentiumII/PPro */
21381
21382 #define ROUND1(x) \
21383+ nop; nop; nop; \
21384 SRC(movl x(%esi), %ebx ) ; \
21385 addl %ebx, %eax ; \
21386- DST(movl %ebx, x(%edi) ) ;
21387+ DST(movl %ebx, %es:x(%edi)) ;
21388
21389 #define ROUND(x) \
21390+ nop; nop; nop; \
21391 SRC(movl x(%esi), %ebx ) ; \
21392 adcl %ebx, %eax ; \
21393- DST(movl %ebx, x(%edi) ) ;
21394+ DST(movl %ebx, %es:x(%edi)) ;
21395
21396 #define ARGBASE 12
21397-
21398-ENTRY(csum_partial_copy_generic)
21399+
21400+ENTRY(csum_partial_copy_generic_to_user)
21401 CFI_STARTPROC
21402+
21403+#ifdef CONFIG_PAX_MEMORY_UDEREF
21404+ pushl_cfi %gs
21405+ popl_cfi %es
21406+ jmp csum_partial_copy_generic
21407+#endif
21408+
21409+ENTRY(csum_partial_copy_generic_from_user)
21410+
21411+#ifdef CONFIG_PAX_MEMORY_UDEREF
21412+ pushl_cfi %gs
21413+ popl_cfi %ds
21414+#endif
21415+
21416+ENTRY(csum_partial_copy_generic)
21417 pushl_cfi %ebx
21418 CFI_REL_OFFSET ebx, 0
21419 pushl_cfi %edi
21420@@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21421 subl %ebx, %edi
21422 lea -1(%esi),%edx
21423 andl $-32,%edx
21424- lea 3f(%ebx,%ebx), %ebx
21425+ lea 3f(%ebx,%ebx,2), %ebx
21426 testl %esi, %esi
21427 jmp *%ebx
21428 1: addl $64,%esi
21429@@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21430 jb 5f
21431 SRC( movw (%esi), %dx )
21432 leal 2(%esi), %esi
21433-DST( movw %dx, (%edi) )
21434+DST( movw %dx, %es:(%edi) )
21435 leal 2(%edi), %edi
21436 je 6f
21437 shll $16,%edx
21438 5:
21439 SRC( movb (%esi), %dl )
21440-DST( movb %dl, (%edi) )
21441+DST( movb %dl, %es:(%edi) )
21442 6: addl %edx, %eax
21443 adcl $0, %eax
21444 7:
21445 .section .fixup, "ax"
21446 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21447- movl $-EFAULT, (%ebx)
21448+ movl $-EFAULT, %ss:(%ebx)
21449 # zero the complete destination (computing the rest is too much work)
21450 movl ARGBASE+8(%esp),%edi # dst
21451 movl ARGBASE+12(%esp),%ecx # len
21452@@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21453 rep; stosb
21454 jmp 7b
21455 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21456- movl $-EFAULT, (%ebx)
21457+ movl $-EFAULT, %ss:(%ebx)
21458 jmp 7b
21459 .previous
21460
21461+#ifdef CONFIG_PAX_MEMORY_UDEREF
21462+ pushl_cfi %ss
21463+ popl_cfi %ds
21464+ pushl_cfi %ss
21465+ popl_cfi %es
21466+#endif
21467+
21468 popl_cfi %esi
21469 CFI_RESTORE esi
21470 popl_cfi %edi
21471@@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21472 CFI_RESTORE ebx
21473 ret
21474 CFI_ENDPROC
21475-ENDPROC(csum_partial_copy_generic)
21476+ENDPROC(csum_partial_copy_generic_to_user)
21477
21478 #undef ROUND
21479 #undef ROUND1
21480diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21481index f2145cf..cea889d 100644
21482--- a/arch/x86/lib/clear_page_64.S
21483+++ b/arch/x86/lib/clear_page_64.S
21484@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21485 movl $4096/8,%ecx
21486 xorl %eax,%eax
21487 rep stosq
21488+ pax_force_retaddr
21489 ret
21490 CFI_ENDPROC
21491 ENDPROC(clear_page_c)
21492@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21493 movl $4096,%ecx
21494 xorl %eax,%eax
21495 rep stosb
21496+ pax_force_retaddr
21497 ret
21498 CFI_ENDPROC
21499 ENDPROC(clear_page_c_e)
21500@@ -43,6 +45,7 @@ ENTRY(clear_page)
21501 leaq 64(%rdi),%rdi
21502 jnz .Lloop
21503 nop
21504+ pax_force_retaddr
21505 ret
21506 CFI_ENDPROC
21507 .Lclear_page_end:
21508@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21509
21510 #include <asm/cpufeature.h>
21511
21512- .section .altinstr_replacement,"ax"
21513+ .section .altinstr_replacement,"a"
21514 1: .byte 0xeb /* jmp <disp8> */
21515 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21516 2: .byte 0xeb /* jmp <disp8> */
21517diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21518index 1e572c5..2a162cd 100644
21519--- a/arch/x86/lib/cmpxchg16b_emu.S
21520+++ b/arch/x86/lib/cmpxchg16b_emu.S
21521@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21522
21523 popf
21524 mov $1, %al
21525+ pax_force_retaddr
21526 ret
21527
21528 not_same:
21529 popf
21530 xor %al,%al
21531+ pax_force_retaddr
21532 ret
21533
21534 CFI_ENDPROC
21535diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21536index 6b34d04..dccb07f 100644
21537--- a/arch/x86/lib/copy_page_64.S
21538+++ b/arch/x86/lib/copy_page_64.S
21539@@ -9,6 +9,7 @@ copy_page_c:
21540 CFI_STARTPROC
21541 movl $4096/8,%ecx
21542 rep movsq
21543+ pax_force_retaddr
21544 ret
21545 CFI_ENDPROC
21546 ENDPROC(copy_page_c)
21547@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21548
21549 ENTRY(copy_page)
21550 CFI_STARTPROC
21551- subq $2*8,%rsp
21552- CFI_ADJUST_CFA_OFFSET 2*8
21553+ subq $3*8,%rsp
21554+ CFI_ADJUST_CFA_OFFSET 3*8
21555 movq %rbx,(%rsp)
21556 CFI_REL_OFFSET rbx, 0
21557 movq %r12,1*8(%rsp)
21558 CFI_REL_OFFSET r12, 1*8
21559+ movq %r13,2*8(%rsp)
21560+ CFI_REL_OFFSET r13, 2*8
21561
21562 movl $(4096/64)-5,%ecx
21563 .p2align 4
21564@@ -37,7 +40,7 @@ ENTRY(copy_page)
21565 movq 16 (%rsi), %rdx
21566 movq 24 (%rsi), %r8
21567 movq 32 (%rsi), %r9
21568- movq 40 (%rsi), %r10
21569+ movq 40 (%rsi), %r13
21570 movq 48 (%rsi), %r11
21571 movq 56 (%rsi), %r12
21572
21573@@ -48,7 +51,7 @@ ENTRY(copy_page)
21574 movq %rdx, 16 (%rdi)
21575 movq %r8, 24 (%rdi)
21576 movq %r9, 32 (%rdi)
21577- movq %r10, 40 (%rdi)
21578+ movq %r13, 40 (%rdi)
21579 movq %r11, 48 (%rdi)
21580 movq %r12, 56 (%rdi)
21581
21582@@ -67,7 +70,7 @@ ENTRY(copy_page)
21583 movq 16 (%rsi), %rdx
21584 movq 24 (%rsi), %r8
21585 movq 32 (%rsi), %r9
21586- movq 40 (%rsi), %r10
21587+ movq 40 (%rsi), %r13
21588 movq 48 (%rsi), %r11
21589 movq 56 (%rsi), %r12
21590
21591@@ -76,7 +79,7 @@ ENTRY(copy_page)
21592 movq %rdx, 16 (%rdi)
21593 movq %r8, 24 (%rdi)
21594 movq %r9, 32 (%rdi)
21595- movq %r10, 40 (%rdi)
21596+ movq %r13, 40 (%rdi)
21597 movq %r11, 48 (%rdi)
21598 movq %r12, 56 (%rdi)
21599
21600@@ -89,8 +92,11 @@ ENTRY(copy_page)
21601 CFI_RESTORE rbx
21602 movq 1*8(%rsp),%r12
21603 CFI_RESTORE r12
21604- addq $2*8,%rsp
21605- CFI_ADJUST_CFA_OFFSET -2*8
21606+ movq 2*8(%rsp),%r13
21607+ CFI_RESTORE r13
21608+ addq $3*8,%rsp
21609+ CFI_ADJUST_CFA_OFFSET -3*8
21610+ pax_force_retaddr
21611 ret
21612 .Lcopy_page_end:
21613 CFI_ENDPROC
21614@@ -101,7 +107,7 @@ ENDPROC(copy_page)
21615
21616 #include <asm/cpufeature.h>
21617
21618- .section .altinstr_replacement,"ax"
21619+ .section .altinstr_replacement,"a"
21620 1: .byte 0xeb /* jmp <disp8> */
21621 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21622 2:
21623diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21624index 0248402..821c786 100644
21625--- a/arch/x86/lib/copy_user_64.S
21626+++ b/arch/x86/lib/copy_user_64.S
21627@@ -16,6 +16,7 @@
21628 #include <asm/thread_info.h>
21629 #include <asm/cpufeature.h>
21630 #include <asm/alternative-asm.h>
21631+#include <asm/pgtable.h>
21632
21633 /*
21634 * By placing feature2 after feature1 in altinstructions section, we logically
21635@@ -29,7 +30,7 @@
21636 .byte 0xe9 /* 32bit jump */
21637 .long \orig-1f /* by default jump to orig */
21638 1:
21639- .section .altinstr_replacement,"ax"
21640+ .section .altinstr_replacement,"a"
21641 2: .byte 0xe9 /* near jump with 32bit immediate */
21642 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21643 3: .byte 0xe9 /* near jump with 32bit immediate */
21644@@ -71,47 +72,20 @@
21645 #endif
21646 .endm
21647
21648-/* Standard copy_to_user with segment limit checking */
21649-ENTRY(_copy_to_user)
21650- CFI_STARTPROC
21651- GET_THREAD_INFO(%rax)
21652- movq %rdi,%rcx
21653- addq %rdx,%rcx
21654- jc bad_to_user
21655- cmpq TI_addr_limit(%rax),%rcx
21656- ja bad_to_user
21657- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21658- copy_user_generic_unrolled,copy_user_generic_string, \
21659- copy_user_enhanced_fast_string
21660- CFI_ENDPROC
21661-ENDPROC(_copy_to_user)
21662-
21663-/* Standard copy_from_user with segment limit checking */
21664-ENTRY(_copy_from_user)
21665- CFI_STARTPROC
21666- GET_THREAD_INFO(%rax)
21667- movq %rsi,%rcx
21668- addq %rdx,%rcx
21669- jc bad_from_user
21670- cmpq TI_addr_limit(%rax),%rcx
21671- ja bad_from_user
21672- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21673- copy_user_generic_unrolled,copy_user_generic_string, \
21674- copy_user_enhanced_fast_string
21675- CFI_ENDPROC
21676-ENDPROC(_copy_from_user)
21677-
21678 .section .fixup,"ax"
21679 /* must zero dest */
21680 ENTRY(bad_from_user)
21681 bad_from_user:
21682 CFI_STARTPROC
21683+ testl %edx,%edx
21684+ js bad_to_user
21685 movl %edx,%ecx
21686 xorl %eax,%eax
21687 rep
21688 stosb
21689 bad_to_user:
21690 movl %edx,%eax
21691+ pax_force_retaddr
21692 ret
21693 CFI_ENDPROC
21694 ENDPROC(bad_from_user)
21695@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21696 jz 17f
21697 1: movq (%rsi),%r8
21698 2: movq 1*8(%rsi),%r9
21699-3: movq 2*8(%rsi),%r10
21700+3: movq 2*8(%rsi),%rax
21701 4: movq 3*8(%rsi),%r11
21702 5: movq %r8,(%rdi)
21703 6: movq %r9,1*8(%rdi)
21704-7: movq %r10,2*8(%rdi)
21705+7: movq %rax,2*8(%rdi)
21706 8: movq %r11,3*8(%rdi)
21707 9: movq 4*8(%rsi),%r8
21708 10: movq 5*8(%rsi),%r9
21709-11: movq 6*8(%rsi),%r10
21710+11: movq 6*8(%rsi),%rax
21711 12: movq 7*8(%rsi),%r11
21712 13: movq %r8,4*8(%rdi)
21713 14: movq %r9,5*8(%rdi)
21714-15: movq %r10,6*8(%rdi)
21715+15: movq %rax,6*8(%rdi)
21716 16: movq %r11,7*8(%rdi)
21717 leaq 64(%rsi),%rsi
21718 leaq 64(%rdi),%rdi
21719@@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21720 decl %ecx
21721 jnz 21b
21722 23: xor %eax,%eax
21723+ pax_force_retaddr
21724 ret
21725
21726 .section .fixup,"ax"
21727@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21728 3: rep
21729 movsb
21730 4: xorl %eax,%eax
21731+ pax_force_retaddr
21732 ret
21733
21734 .section .fixup,"ax"
21735@@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21736 1: rep
21737 movsb
21738 2: xorl %eax,%eax
21739+ pax_force_retaddr
21740 ret
21741
21742 .section .fixup,"ax"
21743diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21744index cb0c112..e3a6895 100644
21745--- a/arch/x86/lib/copy_user_nocache_64.S
21746+++ b/arch/x86/lib/copy_user_nocache_64.S
21747@@ -8,12 +8,14 @@
21748
21749 #include <linux/linkage.h>
21750 #include <asm/dwarf2.h>
21751+#include <asm/alternative-asm.h>
21752
21753 #define FIX_ALIGNMENT 1
21754
21755 #include <asm/current.h>
21756 #include <asm/asm-offsets.h>
21757 #include <asm/thread_info.h>
21758+#include <asm/pgtable.h>
21759
21760 .macro ALIGN_DESTINATION
21761 #ifdef FIX_ALIGNMENT
21762@@ -50,6 +52,15 @@
21763 */
21764 ENTRY(__copy_user_nocache)
21765 CFI_STARTPROC
21766+
21767+#ifdef CONFIG_PAX_MEMORY_UDEREF
21768+ mov $PAX_USER_SHADOW_BASE,%rcx
21769+ cmp %rcx,%rsi
21770+ jae 1f
21771+ add %rcx,%rsi
21772+1:
21773+#endif
21774+
21775 cmpl $8,%edx
21776 jb 20f /* less then 8 bytes, go to byte copy loop */
21777 ALIGN_DESTINATION
21778@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21779 jz 17f
21780 1: movq (%rsi),%r8
21781 2: movq 1*8(%rsi),%r9
21782-3: movq 2*8(%rsi),%r10
21783+3: movq 2*8(%rsi),%rax
21784 4: movq 3*8(%rsi),%r11
21785 5: movnti %r8,(%rdi)
21786 6: movnti %r9,1*8(%rdi)
21787-7: movnti %r10,2*8(%rdi)
21788+7: movnti %rax,2*8(%rdi)
21789 8: movnti %r11,3*8(%rdi)
21790 9: movq 4*8(%rsi),%r8
21791 10: movq 5*8(%rsi),%r9
21792-11: movq 6*8(%rsi),%r10
21793+11: movq 6*8(%rsi),%rax
21794 12: movq 7*8(%rsi),%r11
21795 13: movnti %r8,4*8(%rdi)
21796 14: movnti %r9,5*8(%rdi)
21797-15: movnti %r10,6*8(%rdi)
21798+15: movnti %rax,6*8(%rdi)
21799 16: movnti %r11,7*8(%rdi)
21800 leaq 64(%rsi),%rsi
21801 leaq 64(%rdi),%rdi
21802@@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21803 jnz 21b
21804 23: xorl %eax,%eax
21805 sfence
21806+ pax_force_retaddr
21807 ret
21808
21809 .section .fixup,"ax"
21810diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21811index fb903b7..c92b7f7 100644
21812--- a/arch/x86/lib/csum-copy_64.S
21813+++ b/arch/x86/lib/csum-copy_64.S
21814@@ -8,6 +8,7 @@
21815 #include <linux/linkage.h>
21816 #include <asm/dwarf2.h>
21817 #include <asm/errno.h>
21818+#include <asm/alternative-asm.h>
21819
21820 /*
21821 * Checksum copy with exception handling.
21822@@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21823 CFI_RESTORE rbp
21824 addq $7*8, %rsp
21825 CFI_ADJUST_CFA_OFFSET -7*8
21826+ pax_force_retaddr 0, 1
21827 ret
21828 CFI_RESTORE_STATE
21829
21830diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21831index 459b58a..9570bc7 100644
21832--- a/arch/x86/lib/csum-wrappers_64.c
21833+++ b/arch/x86/lib/csum-wrappers_64.c
21834@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21835 len -= 2;
21836 }
21837 }
21838- isum = csum_partial_copy_generic((__force const void *)src,
21839+
21840+#ifdef CONFIG_PAX_MEMORY_UDEREF
21841+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21842+ src += PAX_USER_SHADOW_BASE;
21843+#endif
21844+
21845+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21846 dst, len, isum, errp, NULL);
21847 if (unlikely(*errp))
21848 goto out_err;
21849@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21850 }
21851
21852 *errp = 0;
21853- return csum_partial_copy_generic(src, (void __force *)dst,
21854+
21855+#ifdef CONFIG_PAX_MEMORY_UDEREF
21856+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21857+ dst += PAX_USER_SHADOW_BASE;
21858+#endif
21859+
21860+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21861 len, isum, NULL, errp);
21862 }
21863 EXPORT_SYMBOL(csum_partial_copy_to_user);
21864diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21865index 51f1504..ddac4c1 100644
21866--- a/arch/x86/lib/getuser.S
21867+++ b/arch/x86/lib/getuser.S
21868@@ -33,15 +33,38 @@
21869 #include <asm/asm-offsets.h>
21870 #include <asm/thread_info.h>
21871 #include <asm/asm.h>
21872+#include <asm/segment.h>
21873+#include <asm/pgtable.h>
21874+#include <asm/alternative-asm.h>
21875+
21876+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21877+#define __copyuser_seg gs;
21878+#else
21879+#define __copyuser_seg
21880+#endif
21881
21882 .text
21883 ENTRY(__get_user_1)
21884 CFI_STARTPROC
21885+
21886+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21887 GET_THREAD_INFO(%_ASM_DX)
21888 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21889 jae bad_get_user
21890-1: movzb (%_ASM_AX),%edx
21891+
21892+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21893+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21894+ cmp %_ASM_DX,%_ASM_AX
21895+ jae 1234f
21896+ add %_ASM_DX,%_ASM_AX
21897+1234:
21898+#endif
21899+
21900+#endif
21901+
21902+1: __copyuser_seg movzb (%_ASM_AX),%edx
21903 xor %eax,%eax
21904+ pax_force_retaddr
21905 ret
21906 CFI_ENDPROC
21907 ENDPROC(__get_user_1)
21908@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21909 ENTRY(__get_user_2)
21910 CFI_STARTPROC
21911 add $1,%_ASM_AX
21912+
21913+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21914 jc bad_get_user
21915 GET_THREAD_INFO(%_ASM_DX)
21916 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21917 jae bad_get_user
21918-2: movzwl -1(%_ASM_AX),%edx
21919+
21920+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21921+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21922+ cmp %_ASM_DX,%_ASM_AX
21923+ jae 1234f
21924+ add %_ASM_DX,%_ASM_AX
21925+1234:
21926+#endif
21927+
21928+#endif
21929+
21930+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21931 xor %eax,%eax
21932+ pax_force_retaddr
21933 ret
21934 CFI_ENDPROC
21935 ENDPROC(__get_user_2)
21936@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21937 ENTRY(__get_user_4)
21938 CFI_STARTPROC
21939 add $3,%_ASM_AX
21940+
21941+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21942 jc bad_get_user
21943 GET_THREAD_INFO(%_ASM_DX)
21944 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21945 jae bad_get_user
21946-3: mov -3(%_ASM_AX),%edx
21947+
21948+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21949+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21950+ cmp %_ASM_DX,%_ASM_AX
21951+ jae 1234f
21952+ add %_ASM_DX,%_ASM_AX
21953+1234:
21954+#endif
21955+
21956+#endif
21957+
21958+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21959 xor %eax,%eax
21960+ pax_force_retaddr
21961 ret
21962 CFI_ENDPROC
21963 ENDPROC(__get_user_4)
21964@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21965 GET_THREAD_INFO(%_ASM_DX)
21966 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21967 jae bad_get_user
21968+
21969+#ifdef CONFIG_PAX_MEMORY_UDEREF
21970+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21971+ cmp %_ASM_DX,%_ASM_AX
21972+ jae 1234f
21973+ add %_ASM_DX,%_ASM_AX
21974+1234:
21975+#endif
21976+
21977 4: movq -7(%_ASM_AX),%_ASM_DX
21978 xor %eax,%eax
21979+ pax_force_retaddr
21980 ret
21981 CFI_ENDPROC
21982 ENDPROC(__get_user_8)
21983@@ -91,6 +152,7 @@ bad_get_user:
21984 CFI_STARTPROC
21985 xor %edx,%edx
21986 mov $(-EFAULT),%_ASM_AX
21987+ pax_force_retaddr
21988 ret
21989 CFI_ENDPROC
21990 END(bad_get_user)
21991diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21992index b1e6c4b..21ae8fc 100644
21993--- a/arch/x86/lib/insn.c
21994+++ b/arch/x86/lib/insn.c
21995@@ -21,6 +21,11 @@
21996 #include <linux/string.h>
21997 #include <asm/inat.h>
21998 #include <asm/insn.h>
21999+#ifdef __KERNEL__
22000+#include <asm/pgtable_types.h>
22001+#else
22002+#define ktla_ktva(addr) addr
22003+#endif
22004
22005 /* Verify next sizeof(t) bytes can be on the same instruction */
22006 #define validate_next(t, insn, n) \
22007@@ -49,8 +54,8 @@
22008 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
22009 {
22010 memset(insn, 0, sizeof(*insn));
22011- insn->kaddr = kaddr;
22012- insn->next_byte = kaddr;
22013+ insn->kaddr = ktla_ktva(kaddr);
22014+ insn->next_byte = ktla_ktva(kaddr);
22015 insn->x86_64 = x86_64 ? 1 : 0;
22016 insn->opnd_bytes = 4;
22017 if (x86_64)
22018diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22019index 05a95e7..326f2fa 100644
22020--- a/arch/x86/lib/iomap_copy_64.S
22021+++ b/arch/x86/lib/iomap_copy_64.S
22022@@ -17,6 +17,7 @@
22023
22024 #include <linux/linkage.h>
22025 #include <asm/dwarf2.h>
22026+#include <asm/alternative-asm.h>
22027
22028 /*
22029 * override generic version in lib/iomap_copy.c
22030@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22031 CFI_STARTPROC
22032 movl %edx,%ecx
22033 rep movsd
22034+ pax_force_retaddr
22035 ret
22036 CFI_ENDPROC
22037 ENDPROC(__iowrite32_copy)
22038diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22039index 1c273be..da9cc0e 100644
22040--- a/arch/x86/lib/memcpy_64.S
22041+++ b/arch/x86/lib/memcpy_64.S
22042@@ -33,6 +33,7 @@
22043 rep movsq
22044 movl %edx, %ecx
22045 rep movsb
22046+ pax_force_retaddr
22047 ret
22048 .Lmemcpy_e:
22049 .previous
22050@@ -49,6 +50,7 @@
22051 movq %rdi, %rax
22052 movq %rdx, %rcx
22053 rep movsb
22054+ pax_force_retaddr
22055 ret
22056 .Lmemcpy_e_e:
22057 .previous
22058@@ -76,13 +78,13 @@ ENTRY(memcpy)
22059 */
22060 movq 0*8(%rsi), %r8
22061 movq 1*8(%rsi), %r9
22062- movq 2*8(%rsi), %r10
22063+ movq 2*8(%rsi), %rcx
22064 movq 3*8(%rsi), %r11
22065 leaq 4*8(%rsi), %rsi
22066
22067 movq %r8, 0*8(%rdi)
22068 movq %r9, 1*8(%rdi)
22069- movq %r10, 2*8(%rdi)
22070+ movq %rcx, 2*8(%rdi)
22071 movq %r11, 3*8(%rdi)
22072 leaq 4*8(%rdi), %rdi
22073 jae .Lcopy_forward_loop
22074@@ -105,12 +107,12 @@ ENTRY(memcpy)
22075 subq $0x20, %rdx
22076 movq -1*8(%rsi), %r8
22077 movq -2*8(%rsi), %r9
22078- movq -3*8(%rsi), %r10
22079+ movq -3*8(%rsi), %rcx
22080 movq -4*8(%rsi), %r11
22081 leaq -4*8(%rsi), %rsi
22082 movq %r8, -1*8(%rdi)
22083 movq %r9, -2*8(%rdi)
22084- movq %r10, -3*8(%rdi)
22085+ movq %rcx, -3*8(%rdi)
22086 movq %r11, -4*8(%rdi)
22087 leaq -4*8(%rdi), %rdi
22088 jae .Lcopy_backward_loop
22089@@ -130,12 +132,13 @@ ENTRY(memcpy)
22090 */
22091 movq 0*8(%rsi), %r8
22092 movq 1*8(%rsi), %r9
22093- movq -2*8(%rsi, %rdx), %r10
22094+ movq -2*8(%rsi, %rdx), %rcx
22095 movq -1*8(%rsi, %rdx), %r11
22096 movq %r8, 0*8(%rdi)
22097 movq %r9, 1*8(%rdi)
22098- movq %r10, -2*8(%rdi, %rdx)
22099+ movq %rcx, -2*8(%rdi, %rdx)
22100 movq %r11, -1*8(%rdi, %rdx)
22101+ pax_force_retaddr
22102 retq
22103 .p2align 4
22104 .Lless_16bytes:
22105@@ -148,6 +151,7 @@ ENTRY(memcpy)
22106 movq -1*8(%rsi, %rdx), %r9
22107 movq %r8, 0*8(%rdi)
22108 movq %r9, -1*8(%rdi, %rdx)
22109+ pax_force_retaddr
22110 retq
22111 .p2align 4
22112 .Lless_8bytes:
22113@@ -161,6 +165,7 @@ ENTRY(memcpy)
22114 movl -4(%rsi, %rdx), %r8d
22115 movl %ecx, (%rdi)
22116 movl %r8d, -4(%rdi, %rdx)
22117+ pax_force_retaddr
22118 retq
22119 .p2align 4
22120 .Lless_3bytes:
22121@@ -179,6 +184,7 @@ ENTRY(memcpy)
22122 movb %cl, (%rdi)
22123
22124 .Lend:
22125+ pax_force_retaddr
22126 retq
22127 CFI_ENDPROC
22128 ENDPROC(memcpy)
22129diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22130index ee16461..c39c199 100644
22131--- a/arch/x86/lib/memmove_64.S
22132+++ b/arch/x86/lib/memmove_64.S
22133@@ -61,13 +61,13 @@ ENTRY(memmove)
22134 5:
22135 sub $0x20, %rdx
22136 movq 0*8(%rsi), %r11
22137- movq 1*8(%rsi), %r10
22138+ movq 1*8(%rsi), %rcx
22139 movq 2*8(%rsi), %r9
22140 movq 3*8(%rsi), %r8
22141 leaq 4*8(%rsi), %rsi
22142
22143 movq %r11, 0*8(%rdi)
22144- movq %r10, 1*8(%rdi)
22145+ movq %rcx, 1*8(%rdi)
22146 movq %r9, 2*8(%rdi)
22147 movq %r8, 3*8(%rdi)
22148 leaq 4*8(%rdi), %rdi
22149@@ -81,10 +81,10 @@ ENTRY(memmove)
22150 4:
22151 movq %rdx, %rcx
22152 movq -8(%rsi, %rdx), %r11
22153- lea -8(%rdi, %rdx), %r10
22154+ lea -8(%rdi, %rdx), %r9
22155 shrq $3, %rcx
22156 rep movsq
22157- movq %r11, (%r10)
22158+ movq %r11, (%r9)
22159 jmp 13f
22160 .Lmemmove_end_forward:
22161
22162@@ -95,14 +95,14 @@ ENTRY(memmove)
22163 7:
22164 movq %rdx, %rcx
22165 movq (%rsi), %r11
22166- movq %rdi, %r10
22167+ movq %rdi, %r9
22168 leaq -8(%rsi, %rdx), %rsi
22169 leaq -8(%rdi, %rdx), %rdi
22170 shrq $3, %rcx
22171 std
22172 rep movsq
22173 cld
22174- movq %r11, (%r10)
22175+ movq %r11, (%r9)
22176 jmp 13f
22177
22178 /*
22179@@ -127,13 +127,13 @@ ENTRY(memmove)
22180 8:
22181 subq $0x20, %rdx
22182 movq -1*8(%rsi), %r11
22183- movq -2*8(%rsi), %r10
22184+ movq -2*8(%rsi), %rcx
22185 movq -3*8(%rsi), %r9
22186 movq -4*8(%rsi), %r8
22187 leaq -4*8(%rsi), %rsi
22188
22189 movq %r11, -1*8(%rdi)
22190- movq %r10, -2*8(%rdi)
22191+ movq %rcx, -2*8(%rdi)
22192 movq %r9, -3*8(%rdi)
22193 movq %r8, -4*8(%rdi)
22194 leaq -4*8(%rdi), %rdi
22195@@ -151,11 +151,11 @@ ENTRY(memmove)
22196 * Move data from 16 bytes to 31 bytes.
22197 */
22198 movq 0*8(%rsi), %r11
22199- movq 1*8(%rsi), %r10
22200+ movq 1*8(%rsi), %rcx
22201 movq -2*8(%rsi, %rdx), %r9
22202 movq -1*8(%rsi, %rdx), %r8
22203 movq %r11, 0*8(%rdi)
22204- movq %r10, 1*8(%rdi)
22205+ movq %rcx, 1*8(%rdi)
22206 movq %r9, -2*8(%rdi, %rdx)
22207 movq %r8, -1*8(%rdi, %rdx)
22208 jmp 13f
22209@@ -167,9 +167,9 @@ ENTRY(memmove)
22210 * Move data from 8 bytes to 15 bytes.
22211 */
22212 movq 0*8(%rsi), %r11
22213- movq -1*8(%rsi, %rdx), %r10
22214+ movq -1*8(%rsi, %rdx), %r9
22215 movq %r11, 0*8(%rdi)
22216- movq %r10, -1*8(%rdi, %rdx)
22217+ movq %r9, -1*8(%rdi, %rdx)
22218 jmp 13f
22219 10:
22220 cmpq $4, %rdx
22221@@ -178,9 +178,9 @@ ENTRY(memmove)
22222 * Move data from 4 bytes to 7 bytes.
22223 */
22224 movl (%rsi), %r11d
22225- movl -4(%rsi, %rdx), %r10d
22226+ movl -4(%rsi, %rdx), %r9d
22227 movl %r11d, (%rdi)
22228- movl %r10d, -4(%rdi, %rdx)
22229+ movl %r9d, -4(%rdi, %rdx)
22230 jmp 13f
22231 11:
22232 cmp $2, %rdx
22233@@ -189,9 +189,9 @@ ENTRY(memmove)
22234 * Move data from 2 bytes to 3 bytes.
22235 */
22236 movw (%rsi), %r11w
22237- movw -2(%rsi, %rdx), %r10w
22238+ movw -2(%rsi, %rdx), %r9w
22239 movw %r11w, (%rdi)
22240- movw %r10w, -2(%rdi, %rdx)
22241+ movw %r9w, -2(%rdi, %rdx)
22242 jmp 13f
22243 12:
22244 cmp $1, %rdx
22245@@ -202,6 +202,7 @@ ENTRY(memmove)
22246 movb (%rsi), %r11b
22247 movb %r11b, (%rdi)
22248 13:
22249+ pax_force_retaddr
22250 retq
22251 CFI_ENDPROC
22252
22253@@ -210,6 +211,7 @@ ENTRY(memmove)
22254 /* Forward moving data. */
22255 movq %rdx, %rcx
22256 rep movsb
22257+ pax_force_retaddr
22258 retq
22259 .Lmemmove_end_forward_efs:
22260 .previous
22261diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22262index 2dcb380..963660a 100644
22263--- a/arch/x86/lib/memset_64.S
22264+++ b/arch/x86/lib/memset_64.S
22265@@ -30,6 +30,7 @@
22266 movl %edx,%ecx
22267 rep stosb
22268 movq %r9,%rax
22269+ pax_force_retaddr
22270 ret
22271 .Lmemset_e:
22272 .previous
22273@@ -52,6 +53,7 @@
22274 movq %rdx,%rcx
22275 rep stosb
22276 movq %r9,%rax
22277+ pax_force_retaddr
22278 ret
22279 .Lmemset_e_e:
22280 .previous
22281@@ -59,7 +61,7 @@
22282 ENTRY(memset)
22283 ENTRY(__memset)
22284 CFI_STARTPROC
22285- movq %rdi,%r10
22286+ movq %rdi,%r11
22287
22288 /* expand byte value */
22289 movzbl %sil,%ecx
22290@@ -117,7 +119,8 @@ ENTRY(__memset)
22291 jnz .Lloop_1
22292
22293 .Lende:
22294- movq %r10,%rax
22295+ movq %r11,%rax
22296+ pax_force_retaddr
22297 ret
22298
22299 CFI_RESTORE_STATE
22300diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22301index c9f2d9b..e7fd2c0 100644
22302--- a/arch/x86/lib/mmx_32.c
22303+++ b/arch/x86/lib/mmx_32.c
22304@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22305 {
22306 void *p;
22307 int i;
22308+ unsigned long cr0;
22309
22310 if (unlikely(in_interrupt()))
22311 return __memcpy(to, from, len);
22312@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22313 kernel_fpu_begin();
22314
22315 __asm__ __volatile__ (
22316- "1: prefetch (%0)\n" /* This set is 28 bytes */
22317- " prefetch 64(%0)\n"
22318- " prefetch 128(%0)\n"
22319- " prefetch 192(%0)\n"
22320- " prefetch 256(%0)\n"
22321+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22322+ " prefetch 64(%1)\n"
22323+ " prefetch 128(%1)\n"
22324+ " prefetch 192(%1)\n"
22325+ " prefetch 256(%1)\n"
22326 "2: \n"
22327 ".section .fixup, \"ax\"\n"
22328- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22329+ "3: \n"
22330+
22331+#ifdef CONFIG_PAX_KERNEXEC
22332+ " movl %%cr0, %0\n"
22333+ " movl %0, %%eax\n"
22334+ " andl $0xFFFEFFFF, %%eax\n"
22335+ " movl %%eax, %%cr0\n"
22336+#endif
22337+
22338+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22339+
22340+#ifdef CONFIG_PAX_KERNEXEC
22341+ " movl %0, %%cr0\n"
22342+#endif
22343+
22344 " jmp 2b\n"
22345 ".previous\n"
22346 _ASM_EXTABLE(1b, 3b)
22347- : : "r" (from));
22348+ : "=&r" (cr0) : "r" (from) : "ax");
22349
22350 for ( ; i > 5; i--) {
22351 __asm__ __volatile__ (
22352- "1: prefetch 320(%0)\n"
22353- "2: movq (%0), %%mm0\n"
22354- " movq 8(%0), %%mm1\n"
22355- " movq 16(%0), %%mm2\n"
22356- " movq 24(%0), %%mm3\n"
22357- " movq %%mm0, (%1)\n"
22358- " movq %%mm1, 8(%1)\n"
22359- " movq %%mm2, 16(%1)\n"
22360- " movq %%mm3, 24(%1)\n"
22361- " movq 32(%0), %%mm0\n"
22362- " movq 40(%0), %%mm1\n"
22363- " movq 48(%0), %%mm2\n"
22364- " movq 56(%0), %%mm3\n"
22365- " movq %%mm0, 32(%1)\n"
22366- " movq %%mm1, 40(%1)\n"
22367- " movq %%mm2, 48(%1)\n"
22368- " movq %%mm3, 56(%1)\n"
22369+ "1: prefetch 320(%1)\n"
22370+ "2: movq (%1), %%mm0\n"
22371+ " movq 8(%1), %%mm1\n"
22372+ " movq 16(%1), %%mm2\n"
22373+ " movq 24(%1), %%mm3\n"
22374+ " movq %%mm0, (%2)\n"
22375+ " movq %%mm1, 8(%2)\n"
22376+ " movq %%mm2, 16(%2)\n"
22377+ " movq %%mm3, 24(%2)\n"
22378+ " movq 32(%1), %%mm0\n"
22379+ " movq 40(%1), %%mm1\n"
22380+ " movq 48(%1), %%mm2\n"
22381+ " movq 56(%1), %%mm3\n"
22382+ " movq %%mm0, 32(%2)\n"
22383+ " movq %%mm1, 40(%2)\n"
22384+ " movq %%mm2, 48(%2)\n"
22385+ " movq %%mm3, 56(%2)\n"
22386 ".section .fixup, \"ax\"\n"
22387- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22388+ "3:\n"
22389+
22390+#ifdef CONFIG_PAX_KERNEXEC
22391+ " movl %%cr0, %0\n"
22392+ " movl %0, %%eax\n"
22393+ " andl $0xFFFEFFFF, %%eax\n"
22394+ " movl %%eax, %%cr0\n"
22395+#endif
22396+
22397+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22398+
22399+#ifdef CONFIG_PAX_KERNEXEC
22400+ " movl %0, %%cr0\n"
22401+#endif
22402+
22403 " jmp 2b\n"
22404 ".previous\n"
22405 _ASM_EXTABLE(1b, 3b)
22406- : : "r" (from), "r" (to) : "memory");
22407+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22408
22409 from += 64;
22410 to += 64;
22411@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22412 static void fast_copy_page(void *to, void *from)
22413 {
22414 int i;
22415+ unsigned long cr0;
22416
22417 kernel_fpu_begin();
22418
22419@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22420 * but that is for later. -AV
22421 */
22422 __asm__ __volatile__(
22423- "1: prefetch (%0)\n"
22424- " prefetch 64(%0)\n"
22425- " prefetch 128(%0)\n"
22426- " prefetch 192(%0)\n"
22427- " prefetch 256(%0)\n"
22428+ "1: prefetch (%1)\n"
22429+ " prefetch 64(%1)\n"
22430+ " prefetch 128(%1)\n"
22431+ " prefetch 192(%1)\n"
22432+ " prefetch 256(%1)\n"
22433 "2: \n"
22434 ".section .fixup, \"ax\"\n"
22435- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22436+ "3: \n"
22437+
22438+#ifdef CONFIG_PAX_KERNEXEC
22439+ " movl %%cr0, %0\n"
22440+ " movl %0, %%eax\n"
22441+ " andl $0xFFFEFFFF, %%eax\n"
22442+ " movl %%eax, %%cr0\n"
22443+#endif
22444+
22445+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22446+
22447+#ifdef CONFIG_PAX_KERNEXEC
22448+ " movl %0, %%cr0\n"
22449+#endif
22450+
22451 " jmp 2b\n"
22452 ".previous\n"
22453- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22454+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22455
22456 for (i = 0; i < (4096-320)/64; i++) {
22457 __asm__ __volatile__ (
22458- "1: prefetch 320(%0)\n"
22459- "2: movq (%0), %%mm0\n"
22460- " movntq %%mm0, (%1)\n"
22461- " movq 8(%0), %%mm1\n"
22462- " movntq %%mm1, 8(%1)\n"
22463- " movq 16(%0), %%mm2\n"
22464- " movntq %%mm2, 16(%1)\n"
22465- " movq 24(%0), %%mm3\n"
22466- " movntq %%mm3, 24(%1)\n"
22467- " movq 32(%0), %%mm4\n"
22468- " movntq %%mm4, 32(%1)\n"
22469- " movq 40(%0), %%mm5\n"
22470- " movntq %%mm5, 40(%1)\n"
22471- " movq 48(%0), %%mm6\n"
22472- " movntq %%mm6, 48(%1)\n"
22473- " movq 56(%0), %%mm7\n"
22474- " movntq %%mm7, 56(%1)\n"
22475+ "1: prefetch 320(%1)\n"
22476+ "2: movq (%1), %%mm0\n"
22477+ " movntq %%mm0, (%2)\n"
22478+ " movq 8(%1), %%mm1\n"
22479+ " movntq %%mm1, 8(%2)\n"
22480+ " movq 16(%1), %%mm2\n"
22481+ " movntq %%mm2, 16(%2)\n"
22482+ " movq 24(%1), %%mm3\n"
22483+ " movntq %%mm3, 24(%2)\n"
22484+ " movq 32(%1), %%mm4\n"
22485+ " movntq %%mm4, 32(%2)\n"
22486+ " movq 40(%1), %%mm5\n"
22487+ " movntq %%mm5, 40(%2)\n"
22488+ " movq 48(%1), %%mm6\n"
22489+ " movntq %%mm6, 48(%2)\n"
22490+ " movq 56(%1), %%mm7\n"
22491+ " movntq %%mm7, 56(%2)\n"
22492 ".section .fixup, \"ax\"\n"
22493- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22494+ "3:\n"
22495+
22496+#ifdef CONFIG_PAX_KERNEXEC
22497+ " movl %%cr0, %0\n"
22498+ " movl %0, %%eax\n"
22499+ " andl $0xFFFEFFFF, %%eax\n"
22500+ " movl %%eax, %%cr0\n"
22501+#endif
22502+
22503+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22504+
22505+#ifdef CONFIG_PAX_KERNEXEC
22506+ " movl %0, %%cr0\n"
22507+#endif
22508+
22509 " jmp 2b\n"
22510 ".previous\n"
22511- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22512+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22513
22514 from += 64;
22515 to += 64;
22516@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22517 static void fast_copy_page(void *to, void *from)
22518 {
22519 int i;
22520+ unsigned long cr0;
22521
22522 kernel_fpu_begin();
22523
22524 __asm__ __volatile__ (
22525- "1: prefetch (%0)\n"
22526- " prefetch 64(%0)\n"
22527- " prefetch 128(%0)\n"
22528- " prefetch 192(%0)\n"
22529- " prefetch 256(%0)\n"
22530+ "1: prefetch (%1)\n"
22531+ " prefetch 64(%1)\n"
22532+ " prefetch 128(%1)\n"
22533+ " prefetch 192(%1)\n"
22534+ " prefetch 256(%1)\n"
22535 "2: \n"
22536 ".section .fixup, \"ax\"\n"
22537- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22538+ "3: \n"
22539+
22540+#ifdef CONFIG_PAX_KERNEXEC
22541+ " movl %%cr0, %0\n"
22542+ " movl %0, %%eax\n"
22543+ " andl $0xFFFEFFFF, %%eax\n"
22544+ " movl %%eax, %%cr0\n"
22545+#endif
22546+
22547+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22548+
22549+#ifdef CONFIG_PAX_KERNEXEC
22550+ " movl %0, %%cr0\n"
22551+#endif
22552+
22553 " jmp 2b\n"
22554 ".previous\n"
22555- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22556+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22557
22558 for (i = 0; i < 4096/64; i++) {
22559 __asm__ __volatile__ (
22560- "1: prefetch 320(%0)\n"
22561- "2: movq (%0), %%mm0\n"
22562- " movq 8(%0), %%mm1\n"
22563- " movq 16(%0), %%mm2\n"
22564- " movq 24(%0), %%mm3\n"
22565- " movq %%mm0, (%1)\n"
22566- " movq %%mm1, 8(%1)\n"
22567- " movq %%mm2, 16(%1)\n"
22568- " movq %%mm3, 24(%1)\n"
22569- " movq 32(%0), %%mm0\n"
22570- " movq 40(%0), %%mm1\n"
22571- " movq 48(%0), %%mm2\n"
22572- " movq 56(%0), %%mm3\n"
22573- " movq %%mm0, 32(%1)\n"
22574- " movq %%mm1, 40(%1)\n"
22575- " movq %%mm2, 48(%1)\n"
22576- " movq %%mm3, 56(%1)\n"
22577+ "1: prefetch 320(%1)\n"
22578+ "2: movq (%1), %%mm0\n"
22579+ " movq 8(%1), %%mm1\n"
22580+ " movq 16(%1), %%mm2\n"
22581+ " movq 24(%1), %%mm3\n"
22582+ " movq %%mm0, (%2)\n"
22583+ " movq %%mm1, 8(%2)\n"
22584+ " movq %%mm2, 16(%2)\n"
22585+ " movq %%mm3, 24(%2)\n"
22586+ " movq 32(%1), %%mm0\n"
22587+ " movq 40(%1), %%mm1\n"
22588+ " movq 48(%1), %%mm2\n"
22589+ " movq 56(%1), %%mm3\n"
22590+ " movq %%mm0, 32(%2)\n"
22591+ " movq %%mm1, 40(%2)\n"
22592+ " movq %%mm2, 48(%2)\n"
22593+ " movq %%mm3, 56(%2)\n"
22594 ".section .fixup, \"ax\"\n"
22595- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22596+ "3:\n"
22597+
22598+#ifdef CONFIG_PAX_KERNEXEC
22599+ " movl %%cr0, %0\n"
22600+ " movl %0, %%eax\n"
22601+ " andl $0xFFFEFFFF, %%eax\n"
22602+ " movl %%eax, %%cr0\n"
22603+#endif
22604+
22605+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22606+
22607+#ifdef CONFIG_PAX_KERNEXEC
22608+ " movl %0, %%cr0\n"
22609+#endif
22610+
22611 " jmp 2b\n"
22612 ".previous\n"
22613 _ASM_EXTABLE(1b, 3b)
22614- : : "r" (from), "r" (to) : "memory");
22615+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22616
22617 from += 64;
22618 to += 64;
22619diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22620index 69fa106..adda88b 100644
22621--- a/arch/x86/lib/msr-reg.S
22622+++ b/arch/x86/lib/msr-reg.S
22623@@ -3,6 +3,7 @@
22624 #include <asm/dwarf2.h>
22625 #include <asm/asm.h>
22626 #include <asm/msr.h>
22627+#include <asm/alternative-asm.h>
22628
22629 #ifdef CONFIG_X86_64
22630 /*
22631@@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22632 CFI_STARTPROC
22633 pushq_cfi %rbx
22634 pushq_cfi %rbp
22635- movq %rdi, %r10 /* Save pointer */
22636+ movq %rdi, %r9 /* Save pointer */
22637 xorl %r11d, %r11d /* Return value */
22638 movl (%rdi), %eax
22639 movl 4(%rdi), %ecx
22640@@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22641 movl 28(%rdi), %edi
22642 CFI_REMEMBER_STATE
22643 1: \op
22644-2: movl %eax, (%r10)
22645+2: movl %eax, (%r9)
22646 movl %r11d, %eax /* Return value */
22647- movl %ecx, 4(%r10)
22648- movl %edx, 8(%r10)
22649- movl %ebx, 12(%r10)
22650- movl %ebp, 20(%r10)
22651- movl %esi, 24(%r10)
22652- movl %edi, 28(%r10)
22653+ movl %ecx, 4(%r9)
22654+ movl %edx, 8(%r9)
22655+ movl %ebx, 12(%r9)
22656+ movl %ebp, 20(%r9)
22657+ movl %esi, 24(%r9)
22658+ movl %edi, 28(%r9)
22659 popq_cfi %rbp
22660 popq_cfi %rbx
22661+ pax_force_retaddr
22662 ret
22663 3:
22664 CFI_RESTORE_STATE
22665diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22666index 36b0d15..d381858 100644
22667--- a/arch/x86/lib/putuser.S
22668+++ b/arch/x86/lib/putuser.S
22669@@ -15,7 +15,9 @@
22670 #include <asm/thread_info.h>
22671 #include <asm/errno.h>
22672 #include <asm/asm.h>
22673-
22674+#include <asm/segment.h>
22675+#include <asm/pgtable.h>
22676+#include <asm/alternative-asm.h>
22677
22678 /*
22679 * __put_user_X
22680@@ -29,52 +31,119 @@
22681 * as they get called from within inline assembly.
22682 */
22683
22684-#define ENTER CFI_STARTPROC ; \
22685- GET_THREAD_INFO(%_ASM_BX)
22686-#define EXIT ret ; \
22687+#define ENTER CFI_STARTPROC
22688+#define EXIT pax_force_retaddr; ret ; \
22689 CFI_ENDPROC
22690
22691+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22692+#define _DEST %_ASM_CX,%_ASM_BX
22693+#else
22694+#define _DEST %_ASM_CX
22695+#endif
22696+
22697+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22698+#define __copyuser_seg gs;
22699+#else
22700+#define __copyuser_seg
22701+#endif
22702+
22703 .text
22704 ENTRY(__put_user_1)
22705 ENTER
22706+
22707+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22708+ GET_THREAD_INFO(%_ASM_BX)
22709 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22710 jae bad_put_user
22711-1: movb %al,(%_ASM_CX)
22712+
22713+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22714+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22715+ cmp %_ASM_BX,%_ASM_CX
22716+ jb 1234f
22717+ xor %ebx,%ebx
22718+1234:
22719+#endif
22720+
22721+#endif
22722+
22723+1: __copyuser_seg movb %al,(_DEST)
22724 xor %eax,%eax
22725 EXIT
22726 ENDPROC(__put_user_1)
22727
22728 ENTRY(__put_user_2)
22729 ENTER
22730+
22731+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22732+ GET_THREAD_INFO(%_ASM_BX)
22733 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22734 sub $1,%_ASM_BX
22735 cmp %_ASM_BX,%_ASM_CX
22736 jae bad_put_user
22737-2: movw %ax,(%_ASM_CX)
22738+
22739+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22740+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22741+ cmp %_ASM_BX,%_ASM_CX
22742+ jb 1234f
22743+ xor %ebx,%ebx
22744+1234:
22745+#endif
22746+
22747+#endif
22748+
22749+2: __copyuser_seg movw %ax,(_DEST)
22750 xor %eax,%eax
22751 EXIT
22752 ENDPROC(__put_user_2)
22753
22754 ENTRY(__put_user_4)
22755 ENTER
22756+
22757+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22758+ GET_THREAD_INFO(%_ASM_BX)
22759 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22760 sub $3,%_ASM_BX
22761 cmp %_ASM_BX,%_ASM_CX
22762 jae bad_put_user
22763-3: movl %eax,(%_ASM_CX)
22764+
22765+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22766+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22767+ cmp %_ASM_BX,%_ASM_CX
22768+ jb 1234f
22769+ xor %ebx,%ebx
22770+1234:
22771+#endif
22772+
22773+#endif
22774+
22775+3: __copyuser_seg movl %eax,(_DEST)
22776 xor %eax,%eax
22777 EXIT
22778 ENDPROC(__put_user_4)
22779
22780 ENTRY(__put_user_8)
22781 ENTER
22782+
22783+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22784+ GET_THREAD_INFO(%_ASM_BX)
22785 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22786 sub $7,%_ASM_BX
22787 cmp %_ASM_BX,%_ASM_CX
22788 jae bad_put_user
22789-4: mov %_ASM_AX,(%_ASM_CX)
22790+
22791+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22792+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22793+ cmp %_ASM_BX,%_ASM_CX
22794+ jb 1234f
22795+ xor %ebx,%ebx
22796+1234:
22797+#endif
22798+
22799+#endif
22800+
22801+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22802 #ifdef CONFIG_X86_32
22803-5: movl %edx,4(%_ASM_CX)
22804+5: __copyuser_seg movl %edx,4(_DEST)
22805 #endif
22806 xor %eax,%eax
22807 EXIT
22808diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22809index 1cad221..de671ee 100644
22810--- a/arch/x86/lib/rwlock.S
22811+++ b/arch/x86/lib/rwlock.S
22812@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22813 FRAME
22814 0: LOCK_PREFIX
22815 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22816+
22817+#ifdef CONFIG_PAX_REFCOUNT
22818+ jno 1234f
22819+ LOCK_PREFIX
22820+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22821+ int $4
22822+1234:
22823+ _ASM_EXTABLE(1234b, 1234b)
22824+#endif
22825+
22826 1: rep; nop
22827 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22828 jne 1b
22829 LOCK_PREFIX
22830 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22831+
22832+#ifdef CONFIG_PAX_REFCOUNT
22833+ jno 1234f
22834+ LOCK_PREFIX
22835+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22836+ int $4
22837+1234:
22838+ _ASM_EXTABLE(1234b, 1234b)
22839+#endif
22840+
22841 jnz 0b
22842 ENDFRAME
22843+ pax_force_retaddr
22844 ret
22845 CFI_ENDPROC
22846 END(__write_lock_failed)
22847@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22848 FRAME
22849 0: LOCK_PREFIX
22850 READ_LOCK_SIZE(inc) (%__lock_ptr)
22851+
22852+#ifdef CONFIG_PAX_REFCOUNT
22853+ jno 1234f
22854+ LOCK_PREFIX
22855+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22856+ int $4
22857+1234:
22858+ _ASM_EXTABLE(1234b, 1234b)
22859+#endif
22860+
22861 1: rep; nop
22862 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22863 js 1b
22864 LOCK_PREFIX
22865 READ_LOCK_SIZE(dec) (%__lock_ptr)
22866+
22867+#ifdef CONFIG_PAX_REFCOUNT
22868+ jno 1234f
22869+ LOCK_PREFIX
22870+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22871+ int $4
22872+1234:
22873+ _ASM_EXTABLE(1234b, 1234b)
22874+#endif
22875+
22876 js 0b
22877 ENDFRAME
22878+ pax_force_retaddr
22879 ret
22880 CFI_ENDPROC
22881 END(__read_lock_failed)
22882diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22883index 5dff5f0..cadebf4 100644
22884--- a/arch/x86/lib/rwsem.S
22885+++ b/arch/x86/lib/rwsem.S
22886@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22887 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22888 CFI_RESTORE __ASM_REG(dx)
22889 restore_common_regs
22890+ pax_force_retaddr
22891 ret
22892 CFI_ENDPROC
22893 ENDPROC(call_rwsem_down_read_failed)
22894@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22895 movq %rax,%rdi
22896 call rwsem_down_write_failed
22897 restore_common_regs
22898+ pax_force_retaddr
22899 ret
22900 CFI_ENDPROC
22901 ENDPROC(call_rwsem_down_write_failed)
22902@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22903 movq %rax,%rdi
22904 call rwsem_wake
22905 restore_common_regs
22906-1: ret
22907+1: pax_force_retaddr
22908+ ret
22909 CFI_ENDPROC
22910 ENDPROC(call_rwsem_wake)
22911
22912@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22913 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22914 CFI_RESTORE __ASM_REG(dx)
22915 restore_common_regs
22916+ pax_force_retaddr
22917 ret
22918 CFI_ENDPROC
22919 ENDPROC(call_rwsem_downgrade_wake)
22920diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22921index a63efd6..ccecad8 100644
22922--- a/arch/x86/lib/thunk_64.S
22923+++ b/arch/x86/lib/thunk_64.S
22924@@ -8,6 +8,7 @@
22925 #include <linux/linkage.h>
22926 #include <asm/dwarf2.h>
22927 #include <asm/calling.h>
22928+#include <asm/alternative-asm.h>
22929
22930 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22931 .macro THUNK name, func, put_ret_addr_in_rdi=0
22932@@ -41,5 +42,6 @@
22933 SAVE_ARGS
22934 restore:
22935 RESTORE_ARGS
22936+ pax_force_retaddr
22937 ret
22938 CFI_ENDPROC
22939diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22940index ef2a6a5..3b28862 100644
22941--- a/arch/x86/lib/usercopy_32.c
22942+++ b/arch/x86/lib/usercopy_32.c
22943@@ -41,10 +41,12 @@ do { \
22944 int __d0; \
22945 might_fault(); \
22946 __asm__ __volatile__( \
22947+ __COPYUSER_SET_ES \
22948 "0: rep; stosl\n" \
22949 " movl %2,%0\n" \
22950 "1: rep; stosb\n" \
22951 "2:\n" \
22952+ __COPYUSER_RESTORE_ES \
22953 ".section .fixup,\"ax\"\n" \
22954 "3: lea 0(%2,%0,4),%0\n" \
22955 " jmp 2b\n" \
22956@@ -113,6 +115,7 @@ long strnlen_user(const char __user *s, long n)
22957 might_fault();
22958
22959 __asm__ __volatile__(
22960+ __COPYUSER_SET_ES
22961 " testl %0, %0\n"
22962 " jz 3f\n"
22963 " andl %0,%%ecx\n"
22964@@ -121,6 +124,7 @@ long strnlen_user(const char __user *s, long n)
22965 " subl %%ecx,%0\n"
22966 " addl %0,%%eax\n"
22967 "1:\n"
22968+ __COPYUSER_RESTORE_ES
22969 ".section .fixup,\"ax\"\n"
22970 "2: xorl %%eax,%%eax\n"
22971 " jmp 1b\n"
22972@@ -140,7 +144,7 @@ EXPORT_SYMBOL(strnlen_user);
22973
22974 #ifdef CONFIG_X86_INTEL_USERCOPY
22975 static unsigned long
22976-__copy_user_intel(void __user *to, const void *from, unsigned long size)
22977+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22978 {
22979 int d0, d1;
22980 __asm__ __volatile__(
22981@@ -152,36 +156,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22982 " .align 2,0x90\n"
22983 "3: movl 0(%4), %%eax\n"
22984 "4: movl 4(%4), %%edx\n"
22985- "5: movl %%eax, 0(%3)\n"
22986- "6: movl %%edx, 4(%3)\n"
22987+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22988+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22989 "7: movl 8(%4), %%eax\n"
22990 "8: movl 12(%4),%%edx\n"
22991- "9: movl %%eax, 8(%3)\n"
22992- "10: movl %%edx, 12(%3)\n"
22993+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22994+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22995 "11: movl 16(%4), %%eax\n"
22996 "12: movl 20(%4), %%edx\n"
22997- "13: movl %%eax, 16(%3)\n"
22998- "14: movl %%edx, 20(%3)\n"
22999+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
23000+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
23001 "15: movl 24(%4), %%eax\n"
23002 "16: movl 28(%4), %%edx\n"
23003- "17: movl %%eax, 24(%3)\n"
23004- "18: movl %%edx, 28(%3)\n"
23005+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
23006+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
23007 "19: movl 32(%4), %%eax\n"
23008 "20: movl 36(%4), %%edx\n"
23009- "21: movl %%eax, 32(%3)\n"
23010- "22: movl %%edx, 36(%3)\n"
23011+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
23012+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
23013 "23: movl 40(%4), %%eax\n"
23014 "24: movl 44(%4), %%edx\n"
23015- "25: movl %%eax, 40(%3)\n"
23016- "26: movl %%edx, 44(%3)\n"
23017+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
23018+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
23019 "27: movl 48(%4), %%eax\n"
23020 "28: movl 52(%4), %%edx\n"
23021- "29: movl %%eax, 48(%3)\n"
23022- "30: movl %%edx, 52(%3)\n"
23023+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23024+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23025 "31: movl 56(%4), %%eax\n"
23026 "32: movl 60(%4), %%edx\n"
23027- "33: movl %%eax, 56(%3)\n"
23028- "34: movl %%edx, 60(%3)\n"
23029+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23030+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23031 " addl $-64, %0\n"
23032 " addl $64, %4\n"
23033 " addl $64, %3\n"
23034@@ -191,10 +195,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23035 " shrl $2, %0\n"
23036 " andl $3, %%eax\n"
23037 " cld\n"
23038+ __COPYUSER_SET_ES
23039 "99: rep; movsl\n"
23040 "36: movl %%eax, %0\n"
23041 "37: rep; movsb\n"
23042 "100:\n"
23043+ __COPYUSER_RESTORE_ES
23044 ".section .fixup,\"ax\"\n"
23045 "101: lea 0(%%eax,%0,4),%0\n"
23046 " jmp 100b\n"
23047@@ -247,46 +253,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23048 }
23049
23050 static unsigned long
23051+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23052+{
23053+ int d0, d1;
23054+ __asm__ __volatile__(
23055+ " .align 2,0x90\n"
23056+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23057+ " cmpl $67, %0\n"
23058+ " jbe 3f\n"
23059+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23060+ " .align 2,0x90\n"
23061+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23062+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23063+ "5: movl %%eax, 0(%3)\n"
23064+ "6: movl %%edx, 4(%3)\n"
23065+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23066+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23067+ "9: movl %%eax, 8(%3)\n"
23068+ "10: movl %%edx, 12(%3)\n"
23069+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23070+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23071+ "13: movl %%eax, 16(%3)\n"
23072+ "14: movl %%edx, 20(%3)\n"
23073+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23074+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23075+ "17: movl %%eax, 24(%3)\n"
23076+ "18: movl %%edx, 28(%3)\n"
23077+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23078+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23079+ "21: movl %%eax, 32(%3)\n"
23080+ "22: movl %%edx, 36(%3)\n"
23081+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23082+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23083+ "25: movl %%eax, 40(%3)\n"
23084+ "26: movl %%edx, 44(%3)\n"
23085+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23086+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23087+ "29: movl %%eax, 48(%3)\n"
23088+ "30: movl %%edx, 52(%3)\n"
23089+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23090+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23091+ "33: movl %%eax, 56(%3)\n"
23092+ "34: movl %%edx, 60(%3)\n"
23093+ " addl $-64, %0\n"
23094+ " addl $64, %4\n"
23095+ " addl $64, %3\n"
23096+ " cmpl $63, %0\n"
23097+ " ja 1b\n"
23098+ "35: movl %0, %%eax\n"
23099+ " shrl $2, %0\n"
23100+ " andl $3, %%eax\n"
23101+ " cld\n"
23102+ "99: rep; "__copyuser_seg" movsl\n"
23103+ "36: movl %%eax, %0\n"
23104+ "37: rep; "__copyuser_seg" movsb\n"
23105+ "100:\n"
23106+ ".section .fixup,\"ax\"\n"
23107+ "101: lea 0(%%eax,%0,4),%0\n"
23108+ " jmp 100b\n"
23109+ ".previous\n"
23110+ ".section __ex_table,\"a\"\n"
23111+ " .align 4\n"
23112+ " .long 1b,100b\n"
23113+ " .long 2b,100b\n"
23114+ " .long 3b,100b\n"
23115+ " .long 4b,100b\n"
23116+ " .long 5b,100b\n"
23117+ " .long 6b,100b\n"
23118+ " .long 7b,100b\n"
23119+ " .long 8b,100b\n"
23120+ " .long 9b,100b\n"
23121+ " .long 10b,100b\n"
23122+ " .long 11b,100b\n"
23123+ " .long 12b,100b\n"
23124+ " .long 13b,100b\n"
23125+ " .long 14b,100b\n"
23126+ " .long 15b,100b\n"
23127+ " .long 16b,100b\n"
23128+ " .long 17b,100b\n"
23129+ " .long 18b,100b\n"
23130+ " .long 19b,100b\n"
23131+ " .long 20b,100b\n"
23132+ " .long 21b,100b\n"
23133+ " .long 22b,100b\n"
23134+ " .long 23b,100b\n"
23135+ " .long 24b,100b\n"
23136+ " .long 25b,100b\n"
23137+ " .long 26b,100b\n"
23138+ " .long 27b,100b\n"
23139+ " .long 28b,100b\n"
23140+ " .long 29b,100b\n"
23141+ " .long 30b,100b\n"
23142+ " .long 31b,100b\n"
23143+ " .long 32b,100b\n"
23144+ " .long 33b,100b\n"
23145+ " .long 34b,100b\n"
23146+ " .long 35b,100b\n"
23147+ " .long 36b,100b\n"
23148+ " .long 37b,100b\n"
23149+ " .long 99b,101b\n"
23150+ ".previous"
23151+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
23152+ : "1"(to), "2"(from), "0"(size)
23153+ : "eax", "edx", "memory");
23154+ return size;
23155+}
23156+
23157+static unsigned long
23158+__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
23159+static unsigned long
23160 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23161 {
23162 int d0, d1;
23163 __asm__ __volatile__(
23164 " .align 2,0x90\n"
23165- "0: movl 32(%4), %%eax\n"
23166+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23167 " cmpl $67, %0\n"
23168 " jbe 2f\n"
23169- "1: movl 64(%4), %%eax\n"
23170+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23171 " .align 2,0x90\n"
23172- "2: movl 0(%4), %%eax\n"
23173- "21: movl 4(%4), %%edx\n"
23174+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23175+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23176 " movl %%eax, 0(%3)\n"
23177 " movl %%edx, 4(%3)\n"
23178- "3: movl 8(%4), %%eax\n"
23179- "31: movl 12(%4),%%edx\n"
23180+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23181+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23182 " movl %%eax, 8(%3)\n"
23183 " movl %%edx, 12(%3)\n"
23184- "4: movl 16(%4), %%eax\n"
23185- "41: movl 20(%4), %%edx\n"
23186+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23187+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23188 " movl %%eax, 16(%3)\n"
23189 " movl %%edx, 20(%3)\n"
23190- "10: movl 24(%4), %%eax\n"
23191- "51: movl 28(%4), %%edx\n"
23192+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23193+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23194 " movl %%eax, 24(%3)\n"
23195 " movl %%edx, 28(%3)\n"
23196- "11: movl 32(%4), %%eax\n"
23197- "61: movl 36(%4), %%edx\n"
23198+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23199+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23200 " movl %%eax, 32(%3)\n"
23201 " movl %%edx, 36(%3)\n"
23202- "12: movl 40(%4), %%eax\n"
23203- "71: movl 44(%4), %%edx\n"
23204+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23205+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23206 " movl %%eax, 40(%3)\n"
23207 " movl %%edx, 44(%3)\n"
23208- "13: movl 48(%4), %%eax\n"
23209- "81: movl 52(%4), %%edx\n"
23210+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23211+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23212 " movl %%eax, 48(%3)\n"
23213 " movl %%edx, 52(%3)\n"
23214- "14: movl 56(%4), %%eax\n"
23215- "91: movl 60(%4), %%edx\n"
23216+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23217+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23218 " movl %%eax, 56(%3)\n"
23219 " movl %%edx, 60(%3)\n"
23220 " addl $-64, %0\n"
23221@@ -298,9 +413,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23222 " shrl $2, %0\n"
23223 " andl $3, %%eax\n"
23224 " cld\n"
23225- "6: rep; movsl\n"
23226+ "6: rep; "__copyuser_seg" movsl\n"
23227 " movl %%eax,%0\n"
23228- "7: rep; movsb\n"
23229+ "7: rep; "__copyuser_seg" movsb\n"
23230 "8:\n"
23231 ".section .fixup,\"ax\"\n"
23232 "9: lea 0(%%eax,%0,4),%0\n"
23233@@ -347,47 +462,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23234 */
23235
23236 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23237+ const void __user *from, unsigned long size) __size_overflow(3);
23238+static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23239 const void __user *from, unsigned long size)
23240 {
23241 int d0, d1;
23242
23243 __asm__ __volatile__(
23244 " .align 2,0x90\n"
23245- "0: movl 32(%4), %%eax\n"
23246+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23247 " cmpl $67, %0\n"
23248 " jbe 2f\n"
23249- "1: movl 64(%4), %%eax\n"
23250+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23251 " .align 2,0x90\n"
23252- "2: movl 0(%4), %%eax\n"
23253- "21: movl 4(%4), %%edx\n"
23254+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23255+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23256 " movnti %%eax, 0(%3)\n"
23257 " movnti %%edx, 4(%3)\n"
23258- "3: movl 8(%4), %%eax\n"
23259- "31: movl 12(%4),%%edx\n"
23260+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23261+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23262 " movnti %%eax, 8(%3)\n"
23263 " movnti %%edx, 12(%3)\n"
23264- "4: movl 16(%4), %%eax\n"
23265- "41: movl 20(%4), %%edx\n"
23266+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23267+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23268 " movnti %%eax, 16(%3)\n"
23269 " movnti %%edx, 20(%3)\n"
23270- "10: movl 24(%4), %%eax\n"
23271- "51: movl 28(%4), %%edx\n"
23272+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23273+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23274 " movnti %%eax, 24(%3)\n"
23275 " movnti %%edx, 28(%3)\n"
23276- "11: movl 32(%4), %%eax\n"
23277- "61: movl 36(%4), %%edx\n"
23278+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23279+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23280 " movnti %%eax, 32(%3)\n"
23281 " movnti %%edx, 36(%3)\n"
23282- "12: movl 40(%4), %%eax\n"
23283- "71: movl 44(%4), %%edx\n"
23284+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23285+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23286 " movnti %%eax, 40(%3)\n"
23287 " movnti %%edx, 44(%3)\n"
23288- "13: movl 48(%4), %%eax\n"
23289- "81: movl 52(%4), %%edx\n"
23290+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23291+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23292 " movnti %%eax, 48(%3)\n"
23293 " movnti %%edx, 52(%3)\n"
23294- "14: movl 56(%4), %%eax\n"
23295- "91: movl 60(%4), %%edx\n"
23296+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23297+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23298 " movnti %%eax, 56(%3)\n"
23299 " movnti %%edx, 60(%3)\n"
23300 " addl $-64, %0\n"
23301@@ -400,9 +517,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23302 " shrl $2, %0\n"
23303 " andl $3, %%eax\n"
23304 " cld\n"
23305- "6: rep; movsl\n"
23306+ "6: rep; "__copyuser_seg" movsl\n"
23307 " movl %%eax,%0\n"
23308- "7: rep; movsb\n"
23309+ "7: rep; "__copyuser_seg" movsb\n"
23310 "8:\n"
23311 ".section .fixup,\"ax\"\n"
23312 "9: lea 0(%%eax,%0,4),%0\n"
23313@@ -444,47 +561,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23314 }
23315
23316 static unsigned long __copy_user_intel_nocache(void *to,
23317+ const void __user *from, unsigned long size) __size_overflow(3);
23318+static unsigned long __copy_user_intel_nocache(void *to,
23319 const void __user *from, unsigned long size)
23320 {
23321 int d0, d1;
23322
23323 __asm__ __volatile__(
23324 " .align 2,0x90\n"
23325- "0: movl 32(%4), %%eax\n"
23326+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23327 " cmpl $67, %0\n"
23328 " jbe 2f\n"
23329- "1: movl 64(%4), %%eax\n"
23330+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23331 " .align 2,0x90\n"
23332- "2: movl 0(%4), %%eax\n"
23333- "21: movl 4(%4), %%edx\n"
23334+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23335+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23336 " movnti %%eax, 0(%3)\n"
23337 " movnti %%edx, 4(%3)\n"
23338- "3: movl 8(%4), %%eax\n"
23339- "31: movl 12(%4),%%edx\n"
23340+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23341+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23342 " movnti %%eax, 8(%3)\n"
23343 " movnti %%edx, 12(%3)\n"
23344- "4: movl 16(%4), %%eax\n"
23345- "41: movl 20(%4), %%edx\n"
23346+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23347+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23348 " movnti %%eax, 16(%3)\n"
23349 " movnti %%edx, 20(%3)\n"
23350- "10: movl 24(%4), %%eax\n"
23351- "51: movl 28(%4), %%edx\n"
23352+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23353+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23354 " movnti %%eax, 24(%3)\n"
23355 " movnti %%edx, 28(%3)\n"
23356- "11: movl 32(%4), %%eax\n"
23357- "61: movl 36(%4), %%edx\n"
23358+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23359+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23360 " movnti %%eax, 32(%3)\n"
23361 " movnti %%edx, 36(%3)\n"
23362- "12: movl 40(%4), %%eax\n"
23363- "71: movl 44(%4), %%edx\n"
23364+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23365+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23366 " movnti %%eax, 40(%3)\n"
23367 " movnti %%edx, 44(%3)\n"
23368- "13: movl 48(%4), %%eax\n"
23369- "81: movl 52(%4), %%edx\n"
23370+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23371+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23372 " movnti %%eax, 48(%3)\n"
23373 " movnti %%edx, 52(%3)\n"
23374- "14: movl 56(%4), %%eax\n"
23375- "91: movl 60(%4), %%edx\n"
23376+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23377+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23378 " movnti %%eax, 56(%3)\n"
23379 " movnti %%edx, 60(%3)\n"
23380 " addl $-64, %0\n"
23381@@ -497,9 +616,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23382 " shrl $2, %0\n"
23383 " andl $3, %%eax\n"
23384 " cld\n"
23385- "6: rep; movsl\n"
23386+ "6: rep; "__copyuser_seg" movsl\n"
23387 " movl %%eax,%0\n"
23388- "7: rep; movsb\n"
23389+ "7: rep; "__copyuser_seg" movsb\n"
23390 "8:\n"
23391 ".section .fixup,\"ax\"\n"
23392 "9: lea 0(%%eax,%0,4),%0\n"
23393@@ -542,32 +661,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23394 */
23395 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23396 unsigned long size);
23397-unsigned long __copy_user_intel(void __user *to, const void *from,
23398+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23399+ unsigned long size);
23400+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23401 unsigned long size);
23402 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23403 const void __user *from, unsigned long size);
23404 #endif /* CONFIG_X86_INTEL_USERCOPY */
23405
23406 /* Generic arbitrary sized copy. */
23407-#define __copy_user(to, from, size) \
23408+#define __copy_user(to, from, size, prefix, set, restore) \
23409 do { \
23410 int __d0, __d1, __d2; \
23411 __asm__ __volatile__( \
23412+ set \
23413 " cmp $7,%0\n" \
23414 " jbe 1f\n" \
23415 " movl %1,%0\n" \
23416 " negl %0\n" \
23417 " andl $7,%0\n" \
23418 " subl %0,%3\n" \
23419- "4: rep; movsb\n" \
23420+ "4: rep; "prefix"movsb\n" \
23421 " movl %3,%0\n" \
23422 " shrl $2,%0\n" \
23423 " andl $3,%3\n" \
23424 " .align 2,0x90\n" \
23425- "0: rep; movsl\n" \
23426+ "0: rep; "prefix"movsl\n" \
23427 " movl %3,%0\n" \
23428- "1: rep; movsb\n" \
23429+ "1: rep; "prefix"movsb\n" \
23430 "2:\n" \
23431+ restore \
23432 ".section .fixup,\"ax\"\n" \
23433 "5: addl %3,%0\n" \
23434 " jmp 2b\n" \
23435@@ -595,14 +718,14 @@ do { \
23436 " negl %0\n" \
23437 " andl $7,%0\n" \
23438 " subl %0,%3\n" \
23439- "4: rep; movsb\n" \
23440+ "4: rep; "__copyuser_seg"movsb\n" \
23441 " movl %3,%0\n" \
23442 " shrl $2,%0\n" \
23443 " andl $3,%3\n" \
23444 " .align 2,0x90\n" \
23445- "0: rep; movsl\n" \
23446+ "0: rep; "__copyuser_seg"movsl\n" \
23447 " movl %3,%0\n" \
23448- "1: rep; movsb\n" \
23449+ "1: rep; "__copyuser_seg"movsb\n" \
23450 "2:\n" \
23451 ".section .fixup,\"ax\"\n" \
23452 "5: addl %3,%0\n" \
23453@@ -688,9 +811,9 @@ survive:
23454 }
23455 #endif
23456 if (movsl_is_ok(to, from, n))
23457- __copy_user(to, from, n);
23458+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23459 else
23460- n = __copy_user_intel(to, from, n);
23461+ n = __generic_copy_to_user_intel(to, from, n);
23462 return n;
23463 }
23464 EXPORT_SYMBOL(__copy_to_user_ll);
23465@@ -710,10 +833,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23466 unsigned long n)
23467 {
23468 if (movsl_is_ok(to, from, n))
23469- __copy_user(to, from, n);
23470+ __copy_user(to, from, n, __copyuser_seg, "", "");
23471 else
23472- n = __copy_user_intel((void __user *)to,
23473- (const void *)from, n);
23474+ n = __generic_copy_from_user_intel(to, from, n);
23475 return n;
23476 }
23477 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23478@@ -740,65 +862,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23479 if (n > 64 && cpu_has_xmm2)
23480 n = __copy_user_intel_nocache(to, from, n);
23481 else
23482- __copy_user(to, from, n);
23483+ __copy_user(to, from, n, __copyuser_seg, "", "");
23484 #else
23485- __copy_user(to, from, n);
23486+ __copy_user(to, from, n, __copyuser_seg, "", "");
23487 #endif
23488 return n;
23489 }
23490 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23491
23492-/**
23493- * copy_to_user: - Copy a block of data into user space.
23494- * @to: Destination address, in user space.
23495- * @from: Source address, in kernel space.
23496- * @n: Number of bytes to copy.
23497- *
23498- * Context: User context only. This function may sleep.
23499- *
23500- * Copy data from kernel space to user space.
23501- *
23502- * Returns number of bytes that could not be copied.
23503- * On success, this will be zero.
23504- */
23505-unsigned long
23506-copy_to_user(void __user *to, const void *from, unsigned long n)
23507-{
23508- if (access_ok(VERIFY_WRITE, to, n))
23509- n = __copy_to_user(to, from, n);
23510- return n;
23511-}
23512-EXPORT_SYMBOL(copy_to_user);
23513-
23514-/**
23515- * copy_from_user: - Copy a block of data from user space.
23516- * @to: Destination address, in kernel space.
23517- * @from: Source address, in user space.
23518- * @n: Number of bytes to copy.
23519- *
23520- * Context: User context only. This function may sleep.
23521- *
23522- * Copy data from user space to kernel space.
23523- *
23524- * Returns number of bytes that could not be copied.
23525- * On success, this will be zero.
23526- *
23527- * If some data could not be copied, this function will pad the copied
23528- * data to the requested size using zero bytes.
23529- */
23530-unsigned long
23531-_copy_from_user(void *to, const void __user *from, unsigned long n)
23532-{
23533- if (access_ok(VERIFY_READ, from, n))
23534- n = __copy_from_user(to, from, n);
23535- else
23536- memset(to, 0, n);
23537- return n;
23538-}
23539-EXPORT_SYMBOL(_copy_from_user);
23540-
23541 void copy_from_user_overflow(void)
23542 {
23543 WARN(1, "Buffer overflow detected!\n");
23544 }
23545 EXPORT_SYMBOL(copy_from_user_overflow);
23546+
23547+void copy_to_user_overflow(void)
23548+{
23549+ WARN(1, "Buffer overflow detected!\n");
23550+}
23551+EXPORT_SYMBOL(copy_to_user_overflow);
23552+
23553+#ifdef CONFIG_PAX_MEMORY_UDEREF
23554+void __set_fs(mm_segment_t x)
23555+{
23556+ switch (x.seg) {
23557+ case 0:
23558+ loadsegment(gs, 0);
23559+ break;
23560+ case TASK_SIZE_MAX:
23561+ loadsegment(gs, __USER_DS);
23562+ break;
23563+ case -1UL:
23564+ loadsegment(gs, __KERNEL_DS);
23565+ break;
23566+ default:
23567+ BUG();
23568+ }
23569+ return;
23570+}
23571+EXPORT_SYMBOL(__set_fs);
23572+
23573+void set_fs(mm_segment_t x)
23574+{
23575+ current_thread_info()->addr_limit = x;
23576+ __set_fs(x);
23577+}
23578+EXPORT_SYMBOL(set_fs);
23579+#endif
23580diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23581index 0d0326f..6a6155b 100644
23582--- a/arch/x86/lib/usercopy_64.c
23583+++ b/arch/x86/lib/usercopy_64.c
23584@@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23585 {
23586 long __d0;
23587 might_fault();
23588+
23589+#ifdef CONFIG_PAX_MEMORY_UDEREF
23590+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23591+ addr += PAX_USER_SHADOW_BASE;
23592+#endif
23593+
23594 /* no memory constraint because it doesn't change any memory gcc knows
23595 about */
23596 asm volatile(
23597@@ -100,12 +106,20 @@ long strlen_user(const char __user *s)
23598 }
23599 EXPORT_SYMBOL(strlen_user);
23600
23601-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23602+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23603 {
23604- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23605- return copy_user_generic((__force void *)to, (__force void *)from, len);
23606- }
23607- return len;
23608+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23609+
23610+#ifdef CONFIG_PAX_MEMORY_UDEREF
23611+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23612+ to += PAX_USER_SHADOW_BASE;
23613+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23614+ from += PAX_USER_SHADOW_BASE;
23615+#endif
23616+
23617+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23618+ }
23619+ return len;
23620 }
23621 EXPORT_SYMBOL(copy_in_user);
23622
23623@@ -115,7 +129,7 @@ EXPORT_SYMBOL(copy_in_user);
23624 * it is not necessary to optimize tail handling.
23625 */
23626 unsigned long
23627-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23628+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23629 {
23630 char c;
23631 unsigned zero_len;
23632@@ -132,3 +146,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23633 break;
23634 return len;
23635 }
23636+
23637+void copy_from_user_overflow(void)
23638+{
23639+ WARN(1, "Buffer overflow detected!\n");
23640+}
23641+EXPORT_SYMBOL(copy_from_user_overflow);
23642+
23643+void copy_to_user_overflow(void)
23644+{
23645+ WARN(1, "Buffer overflow detected!\n");
23646+}
23647+EXPORT_SYMBOL(copy_to_user_overflow);
23648diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23649index 1fb85db..8b3540b 100644
23650--- a/arch/x86/mm/extable.c
23651+++ b/arch/x86/mm/extable.c
23652@@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
23653 const struct exception_table_entry *fixup;
23654
23655 #ifdef CONFIG_PNPBIOS
23656- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23657+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23658 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23659 extern u32 pnp_bios_is_utter_crap;
23660 pnp_bios_is_utter_crap = 1;
23661diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23662index 3ecfd1a..304d554 100644
23663--- a/arch/x86/mm/fault.c
23664+++ b/arch/x86/mm/fault.c
23665@@ -13,11 +13,18 @@
23666 #include <linux/perf_event.h> /* perf_sw_event */
23667 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23668 #include <linux/prefetch.h> /* prefetchw */
23669+#include <linux/unistd.h>
23670+#include <linux/compiler.h>
23671
23672 #include <asm/traps.h> /* dotraplinkage, ... */
23673 #include <asm/pgalloc.h> /* pgd_*(), ... */
23674 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23675 #include <asm/fixmap.h> /* VSYSCALL_START */
23676+#include <asm/tlbflush.h>
23677+
23678+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23679+#include <asm/stacktrace.h>
23680+#endif
23681
23682 /*
23683 * Page fault error code bits:
23684@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23685 int ret = 0;
23686
23687 /* kprobe_running() needs smp_processor_id() */
23688- if (kprobes_built_in() && !user_mode_vm(regs)) {
23689+ if (kprobes_built_in() && !user_mode(regs)) {
23690 preempt_disable();
23691 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23692 ret = 1;
23693@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23694 return !instr_lo || (instr_lo>>1) == 1;
23695 case 0x00:
23696 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23697- if (probe_kernel_address(instr, opcode))
23698+ if (user_mode(regs)) {
23699+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23700+ return 0;
23701+ } else if (probe_kernel_address(instr, opcode))
23702 return 0;
23703
23704 *prefetch = (instr_lo == 0xF) &&
23705@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23706 while (instr < max_instr) {
23707 unsigned char opcode;
23708
23709- if (probe_kernel_address(instr, opcode))
23710+ if (user_mode(regs)) {
23711+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23712+ break;
23713+ } else if (probe_kernel_address(instr, opcode))
23714 break;
23715
23716 instr++;
23717@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23718 force_sig_info(si_signo, &info, tsk);
23719 }
23720
23721+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23722+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23723+#endif
23724+
23725+#ifdef CONFIG_PAX_EMUTRAMP
23726+static int pax_handle_fetch_fault(struct pt_regs *regs);
23727+#endif
23728+
23729+#ifdef CONFIG_PAX_PAGEEXEC
23730+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23731+{
23732+ pgd_t *pgd;
23733+ pud_t *pud;
23734+ pmd_t *pmd;
23735+
23736+ pgd = pgd_offset(mm, address);
23737+ if (!pgd_present(*pgd))
23738+ return NULL;
23739+ pud = pud_offset(pgd, address);
23740+ if (!pud_present(*pud))
23741+ return NULL;
23742+ pmd = pmd_offset(pud, address);
23743+ if (!pmd_present(*pmd))
23744+ return NULL;
23745+ return pmd;
23746+}
23747+#endif
23748+
23749 DEFINE_SPINLOCK(pgd_lock);
23750 LIST_HEAD(pgd_list);
23751
23752@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23753 for (address = VMALLOC_START & PMD_MASK;
23754 address >= TASK_SIZE && address < FIXADDR_TOP;
23755 address += PMD_SIZE) {
23756+
23757+#ifdef CONFIG_PAX_PER_CPU_PGD
23758+ unsigned long cpu;
23759+#else
23760 struct page *page;
23761+#endif
23762
23763 spin_lock(&pgd_lock);
23764+
23765+#ifdef CONFIG_PAX_PER_CPU_PGD
23766+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23767+ pgd_t *pgd = get_cpu_pgd(cpu);
23768+ pmd_t *ret;
23769+#else
23770 list_for_each_entry(page, &pgd_list, lru) {
23771+ pgd_t *pgd = page_address(page);
23772 spinlock_t *pgt_lock;
23773 pmd_t *ret;
23774
23775@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23776 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23777
23778 spin_lock(pgt_lock);
23779- ret = vmalloc_sync_one(page_address(page), address);
23780+#endif
23781+
23782+ ret = vmalloc_sync_one(pgd, address);
23783+
23784+#ifndef CONFIG_PAX_PER_CPU_PGD
23785 spin_unlock(pgt_lock);
23786+#endif
23787
23788 if (!ret)
23789 break;
23790@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23791 * an interrupt in the middle of a task switch..
23792 */
23793 pgd_paddr = read_cr3();
23794+
23795+#ifdef CONFIG_PAX_PER_CPU_PGD
23796+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23797+#endif
23798+
23799 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23800 if (!pmd_k)
23801 return -1;
23802@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23803 * happen within a race in page table update. In the later
23804 * case just flush:
23805 */
23806+
23807+#ifdef CONFIG_PAX_PER_CPU_PGD
23808+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23809+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23810+#else
23811 pgd = pgd_offset(current->active_mm, address);
23812+#endif
23813+
23814 pgd_ref = pgd_offset_k(address);
23815 if (pgd_none(*pgd_ref))
23816 return -1;
23817@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23818 static int is_errata100(struct pt_regs *regs, unsigned long address)
23819 {
23820 #ifdef CONFIG_X86_64
23821- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23822+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23823 return 1;
23824 #endif
23825 return 0;
23826@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23827 }
23828
23829 static const char nx_warning[] = KERN_CRIT
23830-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23831+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23832
23833 static void
23834 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23835@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23836 if (!oops_may_print())
23837 return;
23838
23839- if (error_code & PF_INSTR) {
23840+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23841 unsigned int level;
23842
23843 pte_t *pte = lookup_address(address, &level);
23844
23845 if (pte && pte_present(*pte) && !pte_exec(*pte))
23846- printk(nx_warning, current_uid());
23847+ printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23848 }
23849
23850+#ifdef CONFIG_PAX_KERNEXEC
23851+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23852+ if (current->signal->curr_ip)
23853+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23854+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23855+ else
23856+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23857+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23858+ }
23859+#endif
23860+
23861 printk(KERN_ALERT "BUG: unable to handle kernel ");
23862 if (address < PAGE_SIZE)
23863 printk(KERN_CONT "NULL pointer dereference");
23864@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23865 }
23866 #endif
23867
23868+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23869+ if (pax_is_fetch_fault(regs, error_code, address)) {
23870+
23871+#ifdef CONFIG_PAX_EMUTRAMP
23872+ switch (pax_handle_fetch_fault(regs)) {
23873+ case 2:
23874+ return;
23875+ }
23876+#endif
23877+
23878+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23879+ do_group_exit(SIGKILL);
23880+ }
23881+#endif
23882+
23883 if (unlikely(show_unhandled_signals))
23884 show_signal_msg(regs, error_code, address, tsk);
23885
23886@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23887 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23888 printk(KERN_ERR
23889 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23890- tsk->comm, tsk->pid, address);
23891+ tsk->comm, task_pid_nr(tsk), address);
23892 code = BUS_MCEERR_AR;
23893 }
23894 #endif
23895@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23896 return 1;
23897 }
23898
23899+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23900+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23901+{
23902+ pte_t *pte;
23903+ pmd_t *pmd;
23904+ spinlock_t *ptl;
23905+ unsigned char pte_mask;
23906+
23907+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23908+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23909+ return 0;
23910+
23911+ /* PaX: it's our fault, let's handle it if we can */
23912+
23913+ /* PaX: take a look at read faults before acquiring any locks */
23914+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23915+ /* instruction fetch attempt from a protected page in user mode */
23916+ up_read(&mm->mmap_sem);
23917+
23918+#ifdef CONFIG_PAX_EMUTRAMP
23919+ switch (pax_handle_fetch_fault(regs)) {
23920+ case 2:
23921+ return 1;
23922+ }
23923+#endif
23924+
23925+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23926+ do_group_exit(SIGKILL);
23927+ }
23928+
23929+ pmd = pax_get_pmd(mm, address);
23930+ if (unlikely(!pmd))
23931+ return 0;
23932+
23933+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23934+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23935+ pte_unmap_unlock(pte, ptl);
23936+ return 0;
23937+ }
23938+
23939+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23940+ /* write attempt to a protected page in user mode */
23941+ pte_unmap_unlock(pte, ptl);
23942+ return 0;
23943+ }
23944+
23945+#ifdef CONFIG_SMP
23946+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23947+#else
23948+ if (likely(address > get_limit(regs->cs)))
23949+#endif
23950+ {
23951+ set_pte(pte, pte_mkread(*pte));
23952+ __flush_tlb_one(address);
23953+ pte_unmap_unlock(pte, ptl);
23954+ up_read(&mm->mmap_sem);
23955+ return 1;
23956+ }
23957+
23958+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23959+
23960+ /*
23961+ * PaX: fill DTLB with user rights and retry
23962+ */
23963+ __asm__ __volatile__ (
23964+ "orb %2,(%1)\n"
23965+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23966+/*
23967+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23968+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23969+ * page fault when examined during a TLB load attempt. this is true not only
23970+ * for PTEs holding a non-present entry but also present entries that will
23971+ * raise a page fault (such as those set up by PaX, or the copy-on-write
23972+ * mechanism). in effect it means that we do *not* need to flush the TLBs
23973+ * for our target pages since their PTEs are simply not in the TLBs at all.
23974+
23975+ * the best thing in omitting it is that we gain around 15-20% speed in the
23976+ * fast path of the page fault handler and can get rid of tracing since we
23977+ * can no longer flush unintended entries.
23978+ */
23979+ "invlpg (%0)\n"
23980+#endif
23981+ __copyuser_seg"testb $0,(%0)\n"
23982+ "xorb %3,(%1)\n"
23983+ :
23984+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23985+ : "memory", "cc");
23986+ pte_unmap_unlock(pte, ptl);
23987+ up_read(&mm->mmap_sem);
23988+ return 1;
23989+}
23990+#endif
23991+
23992 /*
23993 * Handle a spurious fault caused by a stale TLB entry.
23994 *
23995@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23996 static inline int
23997 access_error(unsigned long error_code, struct vm_area_struct *vma)
23998 {
23999+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24000+ return 1;
24001+
24002 if (error_code & PF_WRITE) {
24003 /* write, present and write, not present: */
24004 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24005@@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24006 {
24007 struct vm_area_struct *vma;
24008 struct task_struct *tsk;
24009- unsigned long address;
24010 struct mm_struct *mm;
24011 int fault;
24012 int write = error_code & PF_WRITE;
24013 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
24014 (write ? FAULT_FLAG_WRITE : 0);
24015
24016- tsk = current;
24017- mm = tsk->mm;
24018-
24019 /* Get the faulting address: */
24020- address = read_cr2();
24021+ unsigned long address = read_cr2();
24022+
24023+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24024+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24025+ if (!search_exception_tables(regs->ip)) {
24026+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24027+ bad_area_nosemaphore(regs, error_code, address);
24028+ return;
24029+ }
24030+ if (address < PAX_USER_SHADOW_BASE) {
24031+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24032+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24033+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24034+ } else
24035+ address -= PAX_USER_SHADOW_BASE;
24036+ }
24037+#endif
24038+
24039+ tsk = current;
24040+ mm = tsk->mm;
24041
24042 /*
24043 * Detect and handle instructions that would cause a page fault for
24044@@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24045 * User-mode registers count as a user access even for any
24046 * potential system fault or CPU buglet:
24047 */
24048- if (user_mode_vm(regs)) {
24049+ if (user_mode(regs)) {
24050 local_irq_enable();
24051 error_code |= PF_USER;
24052 } else {
24053@@ -1132,6 +1339,11 @@ retry:
24054 might_sleep();
24055 }
24056
24057+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24058+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24059+ return;
24060+#endif
24061+
24062 vma = find_vma(mm, address);
24063 if (unlikely(!vma)) {
24064 bad_area(regs, error_code, address);
24065@@ -1143,18 +1355,24 @@ retry:
24066 bad_area(regs, error_code, address);
24067 return;
24068 }
24069- if (error_code & PF_USER) {
24070- /*
24071- * Accessing the stack below %sp is always a bug.
24072- * The large cushion allows instructions like enter
24073- * and pusha to work. ("enter $65535, $31" pushes
24074- * 32 pointers and then decrements %sp by 65535.)
24075- */
24076- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24077- bad_area(regs, error_code, address);
24078- return;
24079- }
24080+ /*
24081+ * Accessing the stack below %sp is always a bug.
24082+ * The large cushion allows instructions like enter
24083+ * and pusha to work. ("enter $65535, $31" pushes
24084+ * 32 pointers and then decrements %sp by 65535.)
24085+ */
24086+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24087+ bad_area(regs, error_code, address);
24088+ return;
24089 }
24090+
24091+#ifdef CONFIG_PAX_SEGMEXEC
24092+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24093+ bad_area(regs, error_code, address);
24094+ return;
24095+ }
24096+#endif
24097+
24098 if (unlikely(expand_stack(vma, address))) {
24099 bad_area(regs, error_code, address);
24100 return;
24101@@ -1209,3 +1427,292 @@ good_area:
24102
24103 up_read(&mm->mmap_sem);
24104 }
24105+
24106+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24107+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24108+{
24109+ struct mm_struct *mm = current->mm;
24110+ unsigned long ip = regs->ip;
24111+
24112+ if (v8086_mode(regs))
24113+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24114+
24115+#ifdef CONFIG_PAX_PAGEEXEC
24116+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24117+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24118+ return true;
24119+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24120+ return true;
24121+ return false;
24122+ }
24123+#endif
24124+
24125+#ifdef CONFIG_PAX_SEGMEXEC
24126+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24127+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24128+ return true;
24129+ return false;
24130+ }
24131+#endif
24132+
24133+ return false;
24134+}
24135+#endif
24136+
24137+#ifdef CONFIG_PAX_EMUTRAMP
24138+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24139+{
24140+ int err;
24141+
24142+ do { /* PaX: libffi trampoline emulation */
24143+ unsigned char mov, jmp;
24144+ unsigned int addr1, addr2;
24145+
24146+#ifdef CONFIG_X86_64
24147+ if ((regs->ip + 9) >> 32)
24148+ break;
24149+#endif
24150+
24151+ err = get_user(mov, (unsigned char __user *)regs->ip);
24152+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24153+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24154+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24155+
24156+ if (err)
24157+ break;
24158+
24159+ if (mov == 0xB8 && jmp == 0xE9) {
24160+ regs->ax = addr1;
24161+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24162+ return 2;
24163+ }
24164+ } while (0);
24165+
24166+ do { /* PaX: gcc trampoline emulation #1 */
24167+ unsigned char mov1, mov2;
24168+ unsigned short jmp;
24169+ unsigned int addr1, addr2;
24170+
24171+#ifdef CONFIG_X86_64
24172+ if ((regs->ip + 11) >> 32)
24173+ break;
24174+#endif
24175+
24176+ err = get_user(mov1, (unsigned char __user *)regs->ip);
24177+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24178+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24179+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24180+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24181+
24182+ if (err)
24183+ break;
24184+
24185+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24186+ regs->cx = addr1;
24187+ regs->ax = addr2;
24188+ regs->ip = addr2;
24189+ return 2;
24190+ }
24191+ } while (0);
24192+
24193+ do { /* PaX: gcc trampoline emulation #2 */
24194+ unsigned char mov, jmp;
24195+ unsigned int addr1, addr2;
24196+
24197+#ifdef CONFIG_X86_64
24198+ if ((regs->ip + 9) >> 32)
24199+ break;
24200+#endif
24201+
24202+ err = get_user(mov, (unsigned char __user *)regs->ip);
24203+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24204+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24205+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24206+
24207+ if (err)
24208+ break;
24209+
24210+ if (mov == 0xB9 && jmp == 0xE9) {
24211+ regs->cx = addr1;
24212+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24213+ return 2;
24214+ }
24215+ } while (0);
24216+
24217+ return 1; /* PaX in action */
24218+}
24219+
24220+#ifdef CONFIG_X86_64
24221+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24222+{
24223+ int err;
24224+
24225+ do { /* PaX: libffi trampoline emulation */
24226+ unsigned short mov1, mov2, jmp1;
24227+ unsigned char stcclc, jmp2;
24228+ unsigned long addr1, addr2;
24229+
24230+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24231+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24232+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24233+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24234+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24235+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24236+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24237+
24238+ if (err)
24239+ break;
24240+
24241+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24242+ regs->r11 = addr1;
24243+ regs->r10 = addr2;
24244+ if (stcclc == 0xF8)
24245+ regs->flags &= ~X86_EFLAGS_CF;
24246+ else
24247+ regs->flags |= X86_EFLAGS_CF;
24248+ regs->ip = addr1;
24249+ return 2;
24250+ }
24251+ } while (0);
24252+
24253+ do { /* PaX: gcc trampoline emulation #1 */
24254+ unsigned short mov1, mov2, jmp1;
24255+ unsigned char jmp2;
24256+ unsigned int addr1;
24257+ unsigned long addr2;
24258+
24259+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24260+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24261+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24262+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24263+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24264+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24265+
24266+ if (err)
24267+ break;
24268+
24269+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24270+ regs->r11 = addr1;
24271+ regs->r10 = addr2;
24272+ regs->ip = addr1;
24273+ return 2;
24274+ }
24275+ } while (0);
24276+
24277+ do { /* PaX: gcc trampoline emulation #2 */
24278+ unsigned short mov1, mov2, jmp1;
24279+ unsigned char jmp2;
24280+ unsigned long addr1, addr2;
24281+
24282+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24283+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24284+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24285+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24286+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24287+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24288+
24289+ if (err)
24290+ break;
24291+
24292+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24293+ regs->r11 = addr1;
24294+ regs->r10 = addr2;
24295+ regs->ip = addr1;
24296+ return 2;
24297+ }
24298+ } while (0);
24299+
24300+ return 1; /* PaX in action */
24301+}
24302+#endif
24303+
24304+/*
24305+ * PaX: decide what to do with offenders (regs->ip = fault address)
24306+ *
24307+ * returns 1 when task should be killed
24308+ * 2 when gcc trampoline was detected
24309+ */
24310+static int pax_handle_fetch_fault(struct pt_regs *regs)
24311+{
24312+ if (v8086_mode(regs))
24313+ return 1;
24314+
24315+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24316+ return 1;
24317+
24318+#ifdef CONFIG_X86_32
24319+ return pax_handle_fetch_fault_32(regs);
24320+#else
24321+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24322+ return pax_handle_fetch_fault_32(regs);
24323+ else
24324+ return pax_handle_fetch_fault_64(regs);
24325+#endif
24326+}
24327+#endif
24328+
24329+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24330+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24331+{
24332+ long i;
24333+
24334+ printk(KERN_ERR "PAX: bytes at PC: ");
24335+ for (i = 0; i < 20; i++) {
24336+ unsigned char c;
24337+ if (get_user(c, (unsigned char __force_user *)pc+i))
24338+ printk(KERN_CONT "?? ");
24339+ else
24340+ printk(KERN_CONT "%02x ", c);
24341+ }
24342+ printk("\n");
24343+
24344+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24345+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24346+ unsigned long c;
24347+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24348+#ifdef CONFIG_X86_32
24349+ printk(KERN_CONT "???????? ");
24350+#else
24351+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24352+ printk(KERN_CONT "???????? ???????? ");
24353+ else
24354+ printk(KERN_CONT "???????????????? ");
24355+#endif
24356+ } else {
24357+#ifdef CONFIG_X86_64
24358+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24359+ printk(KERN_CONT "%08x ", (unsigned int)c);
24360+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24361+ } else
24362+#endif
24363+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24364+ }
24365+ }
24366+ printk("\n");
24367+}
24368+#endif
24369+
24370+/**
24371+ * probe_kernel_write(): safely attempt to write to a location
24372+ * @dst: address to write to
24373+ * @src: pointer to the data that shall be written
24374+ * @size: size of the data chunk
24375+ *
24376+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24377+ * happens, handle that and return -EFAULT.
24378+ */
24379+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24380+{
24381+ long ret;
24382+ mm_segment_t old_fs = get_fs();
24383+
24384+ set_fs(KERNEL_DS);
24385+ pagefault_disable();
24386+ pax_open_kernel();
24387+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24388+ pax_close_kernel();
24389+ pagefault_enable();
24390+ set_fs(old_fs);
24391+
24392+ return ret ? -EFAULT : 0;
24393+}
24394diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24395index dd74e46..7d26398 100644
24396--- a/arch/x86/mm/gup.c
24397+++ b/arch/x86/mm/gup.c
24398@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24399 addr = start;
24400 len = (unsigned long) nr_pages << PAGE_SHIFT;
24401 end = start + len;
24402- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24403+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24404 (void __user *)start, len)))
24405 return 0;
24406
24407diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24408index 6f31ee5..8ee4164 100644
24409--- a/arch/x86/mm/highmem_32.c
24410+++ b/arch/x86/mm/highmem_32.c
24411@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24412 idx = type + KM_TYPE_NR*smp_processor_id();
24413 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24414 BUG_ON(!pte_none(*(kmap_pte-idx)));
24415+
24416+ pax_open_kernel();
24417 set_pte(kmap_pte-idx, mk_pte(page, prot));
24418+ pax_close_kernel();
24419+
24420 arch_flush_lazy_mmu_mode();
24421
24422 return (void *)vaddr;
24423diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24424index f6679a7..8f795a3 100644
24425--- a/arch/x86/mm/hugetlbpage.c
24426+++ b/arch/x86/mm/hugetlbpage.c
24427@@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24428 struct hstate *h = hstate_file(file);
24429 struct mm_struct *mm = current->mm;
24430 struct vm_area_struct *vma;
24431- unsigned long start_addr;
24432+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24433+
24434+#ifdef CONFIG_PAX_SEGMEXEC
24435+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24436+ pax_task_size = SEGMEXEC_TASK_SIZE;
24437+#endif
24438+
24439+ pax_task_size -= PAGE_SIZE;
24440
24441 if (len > mm->cached_hole_size) {
24442- start_addr = mm->free_area_cache;
24443+ start_addr = mm->free_area_cache;
24444 } else {
24445- start_addr = TASK_UNMAPPED_BASE;
24446- mm->cached_hole_size = 0;
24447+ start_addr = mm->mmap_base;
24448+ mm->cached_hole_size = 0;
24449 }
24450
24451 full_search:
24452@@ -280,26 +287,27 @@ full_search:
24453
24454 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24455 /* At this point: (!vma || addr < vma->vm_end). */
24456- if (TASK_SIZE - len < addr) {
24457+ if (pax_task_size - len < addr) {
24458 /*
24459 * Start a new search - just in case we missed
24460 * some holes.
24461 */
24462- if (start_addr != TASK_UNMAPPED_BASE) {
24463- start_addr = TASK_UNMAPPED_BASE;
24464+ if (start_addr != mm->mmap_base) {
24465+ start_addr = mm->mmap_base;
24466 mm->cached_hole_size = 0;
24467 goto full_search;
24468 }
24469 return -ENOMEM;
24470 }
24471- if (!vma || addr + len <= vma->vm_start) {
24472- mm->free_area_cache = addr + len;
24473- return addr;
24474- }
24475+ if (check_heap_stack_gap(vma, addr, len))
24476+ break;
24477 if (addr + mm->cached_hole_size < vma->vm_start)
24478 mm->cached_hole_size = vma->vm_start - addr;
24479 addr = ALIGN(vma->vm_end, huge_page_size(h));
24480 }
24481+
24482+ mm->free_area_cache = addr + len;
24483+ return addr;
24484 }
24485
24486 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24487@@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24488 struct mm_struct *mm = current->mm;
24489 struct vm_area_struct *vma;
24490 unsigned long base = mm->mmap_base;
24491- unsigned long addr = addr0;
24492+ unsigned long addr;
24493 unsigned long largest_hole = mm->cached_hole_size;
24494- unsigned long start_addr;
24495
24496 /* don't allow allocations above current base */
24497 if (mm->free_area_cache > base)
24498@@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24499 largest_hole = 0;
24500 mm->free_area_cache = base;
24501 }
24502-try_again:
24503- start_addr = mm->free_area_cache;
24504
24505 /* make sure it can fit in the remaining address space */
24506 if (mm->free_area_cache < len)
24507 goto fail;
24508
24509 /* either no address requested or can't fit in requested address hole */
24510- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24511+ addr = mm->free_area_cache - len;
24512 do {
24513+ addr &= huge_page_mask(h);
24514 /*
24515 * Lookup failure means no vma is above this address,
24516 * i.e. return with success:
24517@@ -340,10 +346,10 @@ try_again:
24518 if (!vma)
24519 return addr;
24520
24521- if (addr + len <= vma->vm_start) {
24522+ if (check_heap_stack_gap(vma, addr, len)) {
24523 /* remember the address as a hint for next time */
24524- mm->cached_hole_size = largest_hole;
24525- return (mm->free_area_cache = addr);
24526+ mm->cached_hole_size = largest_hole;
24527+ return (mm->free_area_cache = addr);
24528 } else if (mm->free_area_cache == vma->vm_end) {
24529 /* pull free_area_cache down to the first hole */
24530 mm->free_area_cache = vma->vm_start;
24531@@ -352,29 +358,34 @@ try_again:
24532
24533 /* remember the largest hole we saw so far */
24534 if (addr + largest_hole < vma->vm_start)
24535- largest_hole = vma->vm_start - addr;
24536+ largest_hole = vma->vm_start - addr;
24537
24538 /* try just below the current vma->vm_start */
24539- addr = (vma->vm_start - len) & huge_page_mask(h);
24540- } while (len <= vma->vm_start);
24541+ addr = skip_heap_stack_gap(vma, len);
24542+ } while (!IS_ERR_VALUE(addr));
24543
24544 fail:
24545 /*
24546- * if hint left us with no space for the requested
24547- * mapping then try again:
24548- */
24549- if (start_addr != base) {
24550- mm->free_area_cache = base;
24551- largest_hole = 0;
24552- goto try_again;
24553- }
24554- /*
24555 * A failed mmap() very likely causes application failure,
24556 * so fall back to the bottom-up function here. This scenario
24557 * can happen with large stack limits and large mmap()
24558 * allocations.
24559 */
24560- mm->free_area_cache = TASK_UNMAPPED_BASE;
24561+
24562+#ifdef CONFIG_PAX_SEGMEXEC
24563+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24564+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24565+ else
24566+#endif
24567+
24568+ mm->mmap_base = TASK_UNMAPPED_BASE;
24569+
24570+#ifdef CONFIG_PAX_RANDMMAP
24571+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24572+ mm->mmap_base += mm->delta_mmap;
24573+#endif
24574+
24575+ mm->free_area_cache = mm->mmap_base;
24576 mm->cached_hole_size = ~0UL;
24577 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24578 len, pgoff, flags);
24579@@ -382,6 +393,7 @@ fail:
24580 /*
24581 * Restore the topdown base:
24582 */
24583+ mm->mmap_base = base;
24584 mm->free_area_cache = base;
24585 mm->cached_hole_size = ~0UL;
24586
24587@@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24588 struct hstate *h = hstate_file(file);
24589 struct mm_struct *mm = current->mm;
24590 struct vm_area_struct *vma;
24591+ unsigned long pax_task_size = TASK_SIZE;
24592
24593 if (len & ~huge_page_mask(h))
24594 return -EINVAL;
24595- if (len > TASK_SIZE)
24596+
24597+#ifdef CONFIG_PAX_SEGMEXEC
24598+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24599+ pax_task_size = SEGMEXEC_TASK_SIZE;
24600+#endif
24601+
24602+ pax_task_size -= PAGE_SIZE;
24603+
24604+ if (len > pax_task_size)
24605 return -ENOMEM;
24606
24607 if (flags & MAP_FIXED) {
24608@@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24609 if (addr) {
24610 addr = ALIGN(addr, huge_page_size(h));
24611 vma = find_vma(mm, addr);
24612- if (TASK_SIZE - len >= addr &&
24613- (!vma || addr + len <= vma->vm_start))
24614+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24615 return addr;
24616 }
24617 if (mm->get_unmapped_area == arch_get_unmapped_area)
24618diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24619index 4f0cec7..00976ce 100644
24620--- a/arch/x86/mm/init.c
24621+++ b/arch/x86/mm/init.c
24622@@ -16,6 +16,8 @@
24623 #include <asm/tlb.h>
24624 #include <asm/proto.h>
24625 #include <asm/dma.h> /* for MAX_DMA_PFN */
24626+#include <asm/desc.h>
24627+#include <asm/bios_ebda.h>
24628
24629 unsigned long __initdata pgt_buf_start;
24630 unsigned long __meminitdata pgt_buf_end;
24631@@ -32,7 +34,7 @@ int direct_gbpages
24632 static void __init find_early_table_space(unsigned long end, int use_pse,
24633 int use_gbpages)
24634 {
24635- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24636+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24637 phys_addr_t base;
24638
24639 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24640@@ -311,10 +313,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24641 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24642 * mmio resources as well as potential bios/acpi data regions.
24643 */
24644+
24645+#ifdef CONFIG_GRKERNSEC_KMEM
24646+static unsigned int ebda_start __read_only;
24647+static unsigned int ebda_end __read_only;
24648+#endif
24649+
24650 int devmem_is_allowed(unsigned long pagenr)
24651 {
24652+#ifdef CONFIG_GRKERNSEC_KMEM
24653+ /* allow BDA */
24654+ if (!pagenr)
24655+ return 1;
24656+ /* allow EBDA */
24657+ if (pagenr >= ebda_start && pagenr < ebda_end)
24658+ return 1;
24659+#else
24660+ if (!pagenr)
24661+ return 1;
24662+#ifdef CONFIG_VM86
24663+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24664+ return 1;
24665+#endif
24666+#endif
24667+
24668+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24669+ return 1;
24670+#ifdef CONFIG_GRKERNSEC_KMEM
24671+ /* throw out everything else below 1MB */
24672 if (pagenr <= 256)
24673- return 1;
24674+ return 0;
24675+#endif
24676 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24677 return 0;
24678 if (!page_is_ram(pagenr))
24679@@ -371,8 +400,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24680 #endif
24681 }
24682
24683+#ifdef CONFIG_GRKERNSEC_KMEM
24684+static inline void gr_init_ebda(void)
24685+{
24686+ unsigned int ebda_addr;
24687+ unsigned int ebda_size = 0;
24688+
24689+ ebda_addr = get_bios_ebda();
24690+ if (ebda_addr) {
24691+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24692+ ebda_size <<= 10;
24693+ }
24694+ if (ebda_addr && ebda_size) {
24695+ ebda_start = ebda_addr >> PAGE_SHIFT;
24696+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24697+ } else {
24698+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24699+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24700+ }
24701+}
24702+#else
24703+static inline void gr_init_ebda(void) { }
24704+#endif
24705+
24706 void free_initmem(void)
24707 {
24708+#ifdef CONFIG_PAX_KERNEXEC
24709+#ifdef CONFIG_X86_32
24710+ /* PaX: limit KERNEL_CS to actual size */
24711+ unsigned long addr, limit;
24712+ struct desc_struct d;
24713+ int cpu;
24714+#else
24715+ pgd_t *pgd;
24716+ pud_t *pud;
24717+ pmd_t *pmd;
24718+ unsigned long addr, end;
24719+#endif
24720+#endif
24721+
24722+ gr_init_ebda();
24723+
24724+#ifdef CONFIG_PAX_KERNEXEC
24725+#ifdef CONFIG_X86_32
24726+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24727+ limit = (limit - 1UL) >> PAGE_SHIFT;
24728+
24729+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24730+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24731+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24732+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24733+ }
24734+
24735+ /* PaX: make KERNEL_CS read-only */
24736+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24737+ if (!paravirt_enabled())
24738+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24739+/*
24740+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24741+ pgd = pgd_offset_k(addr);
24742+ pud = pud_offset(pgd, addr);
24743+ pmd = pmd_offset(pud, addr);
24744+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24745+ }
24746+*/
24747+#ifdef CONFIG_X86_PAE
24748+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24749+/*
24750+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24751+ pgd = pgd_offset_k(addr);
24752+ pud = pud_offset(pgd, addr);
24753+ pmd = pmd_offset(pud, addr);
24754+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24755+ }
24756+*/
24757+#endif
24758+
24759+#ifdef CONFIG_MODULES
24760+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24761+#endif
24762+
24763+#else
24764+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24765+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24766+ pgd = pgd_offset_k(addr);
24767+ pud = pud_offset(pgd, addr);
24768+ pmd = pmd_offset(pud, addr);
24769+ if (!pmd_present(*pmd))
24770+ continue;
24771+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24772+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24773+ else
24774+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24775+ }
24776+
24777+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24778+ end = addr + KERNEL_IMAGE_SIZE;
24779+ for (; addr < end; addr += PMD_SIZE) {
24780+ pgd = pgd_offset_k(addr);
24781+ pud = pud_offset(pgd, addr);
24782+ pmd = pmd_offset(pud, addr);
24783+ if (!pmd_present(*pmd))
24784+ continue;
24785+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24786+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24787+ }
24788+#endif
24789+
24790+ flush_tlb_all();
24791+#endif
24792+
24793 free_init_pages("unused kernel memory",
24794 (unsigned long)(&__init_begin),
24795 (unsigned long)(&__init_end));
24796diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24797index 575d86f..4987469 100644
24798--- a/arch/x86/mm/init_32.c
24799+++ b/arch/x86/mm/init_32.c
24800@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24801 }
24802
24803 /*
24804- * Creates a middle page table and puts a pointer to it in the
24805- * given global directory entry. This only returns the gd entry
24806- * in non-PAE compilation mode, since the middle layer is folded.
24807- */
24808-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24809-{
24810- pud_t *pud;
24811- pmd_t *pmd_table;
24812-
24813-#ifdef CONFIG_X86_PAE
24814- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24815- if (after_bootmem)
24816- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24817- else
24818- pmd_table = (pmd_t *)alloc_low_page();
24819- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24820- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24821- pud = pud_offset(pgd, 0);
24822- BUG_ON(pmd_table != pmd_offset(pud, 0));
24823-
24824- return pmd_table;
24825- }
24826-#endif
24827- pud = pud_offset(pgd, 0);
24828- pmd_table = pmd_offset(pud, 0);
24829-
24830- return pmd_table;
24831-}
24832-
24833-/*
24834 * Create a page table and place a pointer to it in a middle page
24835 * directory entry:
24836 */
24837@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24838 page_table = (pte_t *)alloc_low_page();
24839
24840 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24841+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24842+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24843+#else
24844 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24845+#endif
24846 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24847 }
24848
24849 return pte_offset_kernel(pmd, 0);
24850 }
24851
24852+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24853+{
24854+ pud_t *pud;
24855+ pmd_t *pmd_table;
24856+
24857+ pud = pud_offset(pgd, 0);
24858+ pmd_table = pmd_offset(pud, 0);
24859+
24860+ return pmd_table;
24861+}
24862+
24863 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24864 {
24865 int pgd_idx = pgd_index(vaddr);
24866@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24867 int pgd_idx, pmd_idx;
24868 unsigned long vaddr;
24869 pgd_t *pgd;
24870+ pud_t *pud;
24871 pmd_t *pmd;
24872 pte_t *pte = NULL;
24873
24874@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24875 pgd = pgd_base + pgd_idx;
24876
24877 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24878- pmd = one_md_table_init(pgd);
24879- pmd = pmd + pmd_index(vaddr);
24880+ pud = pud_offset(pgd, vaddr);
24881+ pmd = pmd_offset(pud, vaddr);
24882+
24883+#ifdef CONFIG_X86_PAE
24884+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24885+#endif
24886+
24887 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24888 pmd++, pmd_idx++) {
24889 pte = page_table_kmap_check(one_page_table_init(pmd),
24890@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24891 }
24892 }
24893
24894-static inline int is_kernel_text(unsigned long addr)
24895+static inline int is_kernel_text(unsigned long start, unsigned long end)
24896 {
24897- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24898- return 1;
24899- return 0;
24900+ if ((start > ktla_ktva((unsigned long)_etext) ||
24901+ end <= ktla_ktva((unsigned long)_stext)) &&
24902+ (start > ktla_ktva((unsigned long)_einittext) ||
24903+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24904+
24905+#ifdef CONFIG_ACPI_SLEEP
24906+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24907+#endif
24908+
24909+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24910+ return 0;
24911+ return 1;
24912 }
24913
24914 /*
24915@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24916 unsigned long last_map_addr = end;
24917 unsigned long start_pfn, end_pfn;
24918 pgd_t *pgd_base = swapper_pg_dir;
24919- int pgd_idx, pmd_idx, pte_ofs;
24920+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24921 unsigned long pfn;
24922 pgd_t *pgd;
24923+ pud_t *pud;
24924 pmd_t *pmd;
24925 pte_t *pte;
24926 unsigned pages_2m, pages_4k;
24927@@ -280,8 +281,13 @@ repeat:
24928 pfn = start_pfn;
24929 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24930 pgd = pgd_base + pgd_idx;
24931- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24932- pmd = one_md_table_init(pgd);
24933+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24934+ pud = pud_offset(pgd, 0);
24935+ pmd = pmd_offset(pud, 0);
24936+
24937+#ifdef CONFIG_X86_PAE
24938+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24939+#endif
24940
24941 if (pfn >= end_pfn)
24942 continue;
24943@@ -293,14 +299,13 @@ repeat:
24944 #endif
24945 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24946 pmd++, pmd_idx++) {
24947- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24948+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24949
24950 /*
24951 * Map with big pages if possible, otherwise
24952 * create normal page tables:
24953 */
24954 if (use_pse) {
24955- unsigned int addr2;
24956 pgprot_t prot = PAGE_KERNEL_LARGE;
24957 /*
24958 * first pass will use the same initial
24959@@ -310,11 +315,7 @@ repeat:
24960 __pgprot(PTE_IDENT_ATTR |
24961 _PAGE_PSE);
24962
24963- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24964- PAGE_OFFSET + PAGE_SIZE-1;
24965-
24966- if (is_kernel_text(addr) ||
24967- is_kernel_text(addr2))
24968+ if (is_kernel_text(address, address + PMD_SIZE))
24969 prot = PAGE_KERNEL_LARGE_EXEC;
24970
24971 pages_2m++;
24972@@ -331,7 +332,7 @@ repeat:
24973 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24974 pte += pte_ofs;
24975 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24976- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24977+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24978 pgprot_t prot = PAGE_KERNEL;
24979 /*
24980 * first pass will use the same initial
24981@@ -339,7 +340,7 @@ repeat:
24982 */
24983 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24984
24985- if (is_kernel_text(addr))
24986+ if (is_kernel_text(address, address + PAGE_SIZE))
24987 prot = PAGE_KERNEL_EXEC;
24988
24989 pages_4k++;
24990@@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24991
24992 pud = pud_offset(pgd, va);
24993 pmd = pmd_offset(pud, va);
24994- if (!pmd_present(*pmd))
24995+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
24996 break;
24997
24998 pte = pte_offset_kernel(pmd, va);
24999@@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
25000
25001 static void __init pagetable_init(void)
25002 {
25003- pgd_t *pgd_base = swapper_pg_dir;
25004-
25005- permanent_kmaps_init(pgd_base);
25006+ permanent_kmaps_init(swapper_pg_dir);
25007 }
25008
25009-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25010+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25011 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25012
25013 /* user-defined highmem size */
25014@@ -734,6 +733,12 @@ void __init mem_init(void)
25015
25016 pci_iommu_alloc();
25017
25018+#ifdef CONFIG_PAX_PER_CPU_PGD
25019+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25020+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25021+ KERNEL_PGD_PTRS);
25022+#endif
25023+
25024 #ifdef CONFIG_FLATMEM
25025 BUG_ON(!mem_map);
25026 #endif
25027@@ -760,7 +765,7 @@ void __init mem_init(void)
25028 reservedpages++;
25029
25030 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25031- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25032+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25033 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25034
25035 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25036@@ -801,10 +806,10 @@ void __init mem_init(void)
25037 ((unsigned long)&__init_end -
25038 (unsigned long)&__init_begin) >> 10,
25039
25040- (unsigned long)&_etext, (unsigned long)&_edata,
25041- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25042+ (unsigned long)&_sdata, (unsigned long)&_edata,
25043+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25044
25045- (unsigned long)&_text, (unsigned long)&_etext,
25046+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25047 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25048
25049 /*
25050@@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25051 if (!kernel_set_to_readonly)
25052 return;
25053
25054+ start = ktla_ktva(start);
25055 pr_debug("Set kernel text: %lx - %lx for read write\n",
25056 start, start+size);
25057
25058@@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25059 if (!kernel_set_to_readonly)
25060 return;
25061
25062+ start = ktla_ktva(start);
25063 pr_debug("Set kernel text: %lx - %lx for read only\n",
25064 start, start+size);
25065
25066@@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25067 unsigned long start = PFN_ALIGN(_text);
25068 unsigned long size = PFN_ALIGN(_etext) - start;
25069
25070+ start = ktla_ktva(start);
25071 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25072 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25073 size >> 10);
25074diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25075index fc18be0..e539653 100644
25076--- a/arch/x86/mm/init_64.c
25077+++ b/arch/x86/mm/init_64.c
25078@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25079 * around without checking the pgd every time.
25080 */
25081
25082-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25083+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25084 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25085
25086 int force_personality32;
25087@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25088
25089 for (address = start; address <= end; address += PGDIR_SIZE) {
25090 const pgd_t *pgd_ref = pgd_offset_k(address);
25091+
25092+#ifdef CONFIG_PAX_PER_CPU_PGD
25093+ unsigned long cpu;
25094+#else
25095 struct page *page;
25096+#endif
25097
25098 if (pgd_none(*pgd_ref))
25099 continue;
25100
25101 spin_lock(&pgd_lock);
25102+
25103+#ifdef CONFIG_PAX_PER_CPU_PGD
25104+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25105+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
25106+#else
25107 list_for_each_entry(page, &pgd_list, lru) {
25108 pgd_t *pgd;
25109 spinlock_t *pgt_lock;
25110@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25111 /* the pgt_lock only for Xen */
25112 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25113 spin_lock(pgt_lock);
25114+#endif
25115
25116 if (pgd_none(*pgd))
25117 set_pgd(pgd, *pgd_ref);
25118@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25119 BUG_ON(pgd_page_vaddr(*pgd)
25120 != pgd_page_vaddr(*pgd_ref));
25121
25122+#ifndef CONFIG_PAX_PER_CPU_PGD
25123 spin_unlock(pgt_lock);
25124+#endif
25125+
25126 }
25127 spin_unlock(&pgd_lock);
25128 }
25129@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25130 {
25131 if (pgd_none(*pgd)) {
25132 pud_t *pud = (pud_t *)spp_getpage();
25133- pgd_populate(&init_mm, pgd, pud);
25134+ pgd_populate_kernel(&init_mm, pgd, pud);
25135 if (pud != pud_offset(pgd, 0))
25136 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25137 pud, pud_offset(pgd, 0));
25138@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25139 {
25140 if (pud_none(*pud)) {
25141 pmd_t *pmd = (pmd_t *) spp_getpage();
25142- pud_populate(&init_mm, pud, pmd);
25143+ pud_populate_kernel(&init_mm, pud, pmd);
25144 if (pmd != pmd_offset(pud, 0))
25145 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25146 pmd, pmd_offset(pud, 0));
25147@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25148 pmd = fill_pmd(pud, vaddr);
25149 pte = fill_pte(pmd, vaddr);
25150
25151+ pax_open_kernel();
25152 set_pte(pte, new_pte);
25153+ pax_close_kernel();
25154
25155 /*
25156 * It's enough to flush this one mapping.
25157@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25158 pgd = pgd_offset_k((unsigned long)__va(phys));
25159 if (pgd_none(*pgd)) {
25160 pud = (pud_t *) spp_getpage();
25161- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25162- _PAGE_USER));
25163+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25164 }
25165 pud = pud_offset(pgd, (unsigned long)__va(phys));
25166 if (pud_none(*pud)) {
25167 pmd = (pmd_t *) spp_getpage();
25168- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25169- _PAGE_USER));
25170+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25171 }
25172 pmd = pmd_offset(pud, phys);
25173 BUG_ON(!pmd_none(*pmd));
25174@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25175 if (pfn >= pgt_buf_top)
25176 panic("alloc_low_page: ran out of memory");
25177
25178- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25179+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25180 clear_page(adr);
25181 *phys = pfn * PAGE_SIZE;
25182 return adr;
25183@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25184
25185 phys = __pa(virt);
25186 left = phys & (PAGE_SIZE - 1);
25187- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25188+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25189 adr = (void *)(((unsigned long)adr) | left);
25190
25191 return adr;
25192@@ -545,7 +559,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25193 unmap_low_page(pmd);
25194
25195 spin_lock(&init_mm.page_table_lock);
25196- pud_populate(&init_mm, pud, __va(pmd_phys));
25197+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25198 spin_unlock(&init_mm.page_table_lock);
25199 }
25200 __flush_tlb_all();
25201@@ -591,7 +605,7 @@ kernel_physical_mapping_init(unsigned long start,
25202 unmap_low_page(pud);
25203
25204 spin_lock(&init_mm.page_table_lock);
25205- pgd_populate(&init_mm, pgd, __va(pud_phys));
25206+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25207 spin_unlock(&init_mm.page_table_lock);
25208 pgd_changed = true;
25209 }
25210@@ -683,6 +697,12 @@ void __init mem_init(void)
25211
25212 pci_iommu_alloc();
25213
25214+#ifdef CONFIG_PAX_PER_CPU_PGD
25215+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25216+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25217+ KERNEL_PGD_PTRS);
25218+#endif
25219+
25220 /* clear_bss() already clear the empty_zero_page */
25221
25222 reservedpages = 0;
25223@@ -843,8 +863,8 @@ int kern_addr_valid(unsigned long addr)
25224 static struct vm_area_struct gate_vma = {
25225 .vm_start = VSYSCALL_START,
25226 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25227- .vm_page_prot = PAGE_READONLY_EXEC,
25228- .vm_flags = VM_READ | VM_EXEC
25229+ .vm_page_prot = PAGE_READONLY,
25230+ .vm_flags = VM_READ
25231 };
25232
25233 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25234@@ -878,7 +898,7 @@ int in_gate_area_no_mm(unsigned long addr)
25235
25236 const char *arch_vma_name(struct vm_area_struct *vma)
25237 {
25238- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25239+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25240 return "[vdso]";
25241 if (vma == &gate_vma)
25242 return "[vsyscall]";
25243diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25244index 7b179b4..6bd1777 100644
25245--- a/arch/x86/mm/iomap_32.c
25246+++ b/arch/x86/mm/iomap_32.c
25247@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25248 type = kmap_atomic_idx_push();
25249 idx = type + KM_TYPE_NR * smp_processor_id();
25250 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25251+
25252+ pax_open_kernel();
25253 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25254+ pax_close_kernel();
25255+
25256 arch_flush_lazy_mmu_mode();
25257
25258 return (void *)vaddr;
25259diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25260index be1ef57..55f0160 100644
25261--- a/arch/x86/mm/ioremap.c
25262+++ b/arch/x86/mm/ioremap.c
25263@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25264 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25265 int is_ram = page_is_ram(pfn);
25266
25267- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25268+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25269 return NULL;
25270 WARN_ON_ONCE(is_ram);
25271 }
25272@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25273
25274 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25275 if (page_is_ram(start >> PAGE_SHIFT))
25276+#ifdef CONFIG_HIGHMEM
25277+ if ((start >> PAGE_SHIFT) < max_low_pfn)
25278+#endif
25279 return __va(phys);
25280
25281 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25282@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25283 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25284
25285 static __initdata int after_paging_init;
25286-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25287+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25288
25289 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25290 {
25291@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25292 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25293
25294 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25295- memset(bm_pte, 0, sizeof(bm_pte));
25296- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25297+ pmd_populate_user(&init_mm, pmd, bm_pte);
25298
25299 /*
25300 * The boot-ioremap range spans multiple pmds, for which
25301diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25302index d87dd6d..bf3fa66 100644
25303--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25304+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25305@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25306 * memory (e.g. tracked pages)? For now, we need this to avoid
25307 * invoking kmemcheck for PnP BIOS calls.
25308 */
25309- if (regs->flags & X86_VM_MASK)
25310+ if (v8086_mode(regs))
25311 return false;
25312- if (regs->cs != __KERNEL_CS)
25313+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25314 return false;
25315
25316 pte = kmemcheck_pte_lookup(address);
25317diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25318index 845df68..1d8d29f 100644
25319--- a/arch/x86/mm/mmap.c
25320+++ b/arch/x86/mm/mmap.c
25321@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25322 * Leave an at least ~128 MB hole with possible stack randomization.
25323 */
25324 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25325-#define MAX_GAP (TASK_SIZE/6*5)
25326+#define MAX_GAP (pax_task_size/6*5)
25327
25328 static int mmap_is_legacy(void)
25329 {
25330@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25331 return rnd << PAGE_SHIFT;
25332 }
25333
25334-static unsigned long mmap_base(void)
25335+static unsigned long mmap_base(struct mm_struct *mm)
25336 {
25337 unsigned long gap = rlimit(RLIMIT_STACK);
25338+ unsigned long pax_task_size = TASK_SIZE;
25339+
25340+#ifdef CONFIG_PAX_SEGMEXEC
25341+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25342+ pax_task_size = SEGMEXEC_TASK_SIZE;
25343+#endif
25344
25345 if (gap < MIN_GAP)
25346 gap = MIN_GAP;
25347 else if (gap > MAX_GAP)
25348 gap = MAX_GAP;
25349
25350- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25351+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25352 }
25353
25354 /*
25355 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25356 * does, but not when emulating X86_32
25357 */
25358-static unsigned long mmap_legacy_base(void)
25359+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25360 {
25361- if (mmap_is_ia32())
25362+ if (mmap_is_ia32()) {
25363+
25364+#ifdef CONFIG_PAX_SEGMEXEC
25365+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25366+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25367+ else
25368+#endif
25369+
25370 return TASK_UNMAPPED_BASE;
25371- else
25372+ } else
25373 return TASK_UNMAPPED_BASE + mmap_rnd();
25374 }
25375
25376@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25377 void arch_pick_mmap_layout(struct mm_struct *mm)
25378 {
25379 if (mmap_is_legacy()) {
25380- mm->mmap_base = mmap_legacy_base();
25381+ mm->mmap_base = mmap_legacy_base(mm);
25382+
25383+#ifdef CONFIG_PAX_RANDMMAP
25384+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25385+ mm->mmap_base += mm->delta_mmap;
25386+#endif
25387+
25388 mm->get_unmapped_area = arch_get_unmapped_area;
25389 mm->unmap_area = arch_unmap_area;
25390 } else {
25391- mm->mmap_base = mmap_base();
25392+ mm->mmap_base = mmap_base(mm);
25393+
25394+#ifdef CONFIG_PAX_RANDMMAP
25395+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25396+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25397+#endif
25398+
25399 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25400 mm->unmap_area = arch_unmap_area_topdown;
25401 }
25402diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25403index dc0b727..dc9d71a 100644
25404--- a/arch/x86/mm/mmio-mod.c
25405+++ b/arch/x86/mm/mmio-mod.c
25406@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25407 break;
25408 default:
25409 {
25410- unsigned char *ip = (unsigned char *)instptr;
25411+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25412 my_trace->opcode = MMIO_UNKNOWN_OP;
25413 my_trace->width = 0;
25414 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25415@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25416 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25417 void __iomem *addr)
25418 {
25419- static atomic_t next_id;
25420+ static atomic_unchecked_t next_id;
25421 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25422 /* These are page-unaligned. */
25423 struct mmiotrace_map map = {
25424@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25425 .private = trace
25426 },
25427 .phys = offset,
25428- .id = atomic_inc_return(&next_id)
25429+ .id = atomic_inc_return_unchecked(&next_id)
25430 };
25431 map.map_id = trace->id;
25432
25433diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25434index b008656..773eac2 100644
25435--- a/arch/x86/mm/pageattr-test.c
25436+++ b/arch/x86/mm/pageattr-test.c
25437@@ -36,7 +36,7 @@ enum {
25438
25439 static int pte_testbit(pte_t pte)
25440 {
25441- return pte_flags(pte) & _PAGE_UNUSED1;
25442+ return pte_flags(pte) & _PAGE_CPA_TEST;
25443 }
25444
25445 struct split_state {
25446diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25447index e1ebde3..b1e1db38 100644
25448--- a/arch/x86/mm/pageattr.c
25449+++ b/arch/x86/mm/pageattr.c
25450@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25451 */
25452 #ifdef CONFIG_PCI_BIOS
25453 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25454- pgprot_val(forbidden) |= _PAGE_NX;
25455+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25456 #endif
25457
25458 /*
25459@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25460 * Does not cover __inittext since that is gone later on. On
25461 * 64bit we do not enforce !NX on the low mapping
25462 */
25463- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25464- pgprot_val(forbidden) |= _PAGE_NX;
25465+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25466+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25467
25468+#ifdef CONFIG_DEBUG_RODATA
25469 /*
25470 * The .rodata section needs to be read-only. Using the pfn
25471 * catches all aliases.
25472@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25473 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25474 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25475 pgprot_val(forbidden) |= _PAGE_RW;
25476+#endif
25477
25478 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25479 /*
25480@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25481 }
25482 #endif
25483
25484+#ifdef CONFIG_PAX_KERNEXEC
25485+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25486+ pgprot_val(forbidden) |= _PAGE_RW;
25487+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25488+ }
25489+#endif
25490+
25491 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25492
25493 return prot;
25494@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25495 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25496 {
25497 /* change init_mm */
25498+ pax_open_kernel();
25499 set_pte_atomic(kpte, pte);
25500+
25501 #ifdef CONFIG_X86_32
25502 if (!SHARED_KERNEL_PMD) {
25503+
25504+#ifdef CONFIG_PAX_PER_CPU_PGD
25505+ unsigned long cpu;
25506+#else
25507 struct page *page;
25508+#endif
25509
25510+#ifdef CONFIG_PAX_PER_CPU_PGD
25511+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25512+ pgd_t *pgd = get_cpu_pgd(cpu);
25513+#else
25514 list_for_each_entry(page, &pgd_list, lru) {
25515- pgd_t *pgd;
25516+ pgd_t *pgd = (pgd_t *)page_address(page);
25517+#endif
25518+
25519 pud_t *pud;
25520 pmd_t *pmd;
25521
25522- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25523+ pgd += pgd_index(address);
25524 pud = pud_offset(pgd, address);
25525 pmd = pmd_offset(pud, address);
25526 set_pte_atomic((pte_t *)pmd, pte);
25527 }
25528 }
25529 #endif
25530+ pax_close_kernel();
25531 }
25532
25533 static int
25534diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25535index f6ff57b..481690f 100644
25536--- a/arch/x86/mm/pat.c
25537+++ b/arch/x86/mm/pat.c
25538@@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25539
25540 if (!entry) {
25541 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25542- current->comm, current->pid, start, end);
25543+ current->comm, task_pid_nr(current), start, end);
25544 return -EINVAL;
25545 }
25546
25547@@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25548 while (cursor < to) {
25549 if (!devmem_is_allowed(pfn)) {
25550 printk(KERN_INFO
25551- "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25552- current->comm, from, to);
25553+ "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25554+ current->comm, from, to, cursor);
25555 return 0;
25556 }
25557 cursor += PAGE_SIZE;
25558@@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25559 printk(KERN_INFO
25560 "%s:%d ioremap_change_attr failed %s "
25561 "for %Lx-%Lx\n",
25562- current->comm, current->pid,
25563+ current->comm, task_pid_nr(current),
25564 cattr_name(flags),
25565 base, (unsigned long long)(base + size));
25566 return -EINVAL;
25567@@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25568 if (want_flags != flags) {
25569 printk(KERN_WARNING
25570 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25571- current->comm, current->pid,
25572+ current->comm, task_pid_nr(current),
25573 cattr_name(want_flags),
25574 (unsigned long long)paddr,
25575 (unsigned long long)(paddr + size),
25576@@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25577 free_memtype(paddr, paddr + size);
25578 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25579 " for %Lx-%Lx, got %s\n",
25580- current->comm, current->pid,
25581+ current->comm, task_pid_nr(current),
25582 cattr_name(want_flags),
25583 (unsigned long long)paddr,
25584 (unsigned long long)(paddr + size),
25585diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25586index 9f0614d..92ae64a 100644
25587--- a/arch/x86/mm/pf_in.c
25588+++ b/arch/x86/mm/pf_in.c
25589@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25590 int i;
25591 enum reason_type rv = OTHERS;
25592
25593- p = (unsigned char *)ins_addr;
25594+ p = (unsigned char *)ktla_ktva(ins_addr);
25595 p += skip_prefix(p, &prf);
25596 p += get_opcode(p, &opcode);
25597
25598@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25599 struct prefix_bits prf;
25600 int i;
25601
25602- p = (unsigned char *)ins_addr;
25603+ p = (unsigned char *)ktla_ktva(ins_addr);
25604 p += skip_prefix(p, &prf);
25605 p += get_opcode(p, &opcode);
25606
25607@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25608 struct prefix_bits prf;
25609 int i;
25610
25611- p = (unsigned char *)ins_addr;
25612+ p = (unsigned char *)ktla_ktva(ins_addr);
25613 p += skip_prefix(p, &prf);
25614 p += get_opcode(p, &opcode);
25615
25616@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25617 struct prefix_bits prf;
25618 int i;
25619
25620- p = (unsigned char *)ins_addr;
25621+ p = (unsigned char *)ktla_ktva(ins_addr);
25622 p += skip_prefix(p, &prf);
25623 p += get_opcode(p, &opcode);
25624 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25625@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25626 struct prefix_bits prf;
25627 int i;
25628
25629- p = (unsigned char *)ins_addr;
25630+ p = (unsigned char *)ktla_ktva(ins_addr);
25631 p += skip_prefix(p, &prf);
25632 p += get_opcode(p, &opcode);
25633 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25634diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25635index 8573b83..4f3ed7e 100644
25636--- a/arch/x86/mm/pgtable.c
25637+++ b/arch/x86/mm/pgtable.c
25638@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25639 list_del(&page->lru);
25640 }
25641
25642-#define UNSHARED_PTRS_PER_PGD \
25643- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25644+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25645+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25646
25647+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25648+{
25649+ unsigned int count = USER_PGD_PTRS;
25650
25651+ while (count--)
25652+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25653+}
25654+#endif
25655+
25656+#ifdef CONFIG_PAX_PER_CPU_PGD
25657+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25658+{
25659+ unsigned int count = USER_PGD_PTRS;
25660+
25661+ while (count--) {
25662+ pgd_t pgd;
25663+
25664+#ifdef CONFIG_X86_64
25665+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25666+#else
25667+ pgd = *src++;
25668+#endif
25669+
25670+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25671+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25672+#endif
25673+
25674+ *dst++ = pgd;
25675+ }
25676+
25677+}
25678+#endif
25679+
25680+#ifdef CONFIG_X86_64
25681+#define pxd_t pud_t
25682+#define pyd_t pgd_t
25683+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25684+#define pxd_free(mm, pud) pud_free((mm), (pud))
25685+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25686+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25687+#define PYD_SIZE PGDIR_SIZE
25688+#else
25689+#define pxd_t pmd_t
25690+#define pyd_t pud_t
25691+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25692+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25693+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25694+#define pyd_offset(mm, address) pud_offset((mm), (address))
25695+#define PYD_SIZE PUD_SIZE
25696+#endif
25697+
25698+#ifdef CONFIG_PAX_PER_CPU_PGD
25699+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25700+static inline void pgd_dtor(pgd_t *pgd) {}
25701+#else
25702 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25703 {
25704 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25705@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25706 pgd_list_del(pgd);
25707 spin_unlock(&pgd_lock);
25708 }
25709+#endif
25710
25711 /*
25712 * List of all pgd's needed for non-PAE so it can invalidate entries
25713@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25714 * -- wli
25715 */
25716
25717-#ifdef CONFIG_X86_PAE
25718+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25719 /*
25720 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25721 * updating the top-level pagetable entries to guarantee the
25722@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25723 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25724 * and initialize the kernel pmds here.
25725 */
25726-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25727+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25728
25729 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25730 {
25731@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25732 */
25733 flush_tlb_mm(mm);
25734 }
25735+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25736+#define PREALLOCATED_PXDS USER_PGD_PTRS
25737 #else /* !CONFIG_X86_PAE */
25738
25739 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25740-#define PREALLOCATED_PMDS 0
25741+#define PREALLOCATED_PXDS 0
25742
25743 #endif /* CONFIG_X86_PAE */
25744
25745-static void free_pmds(pmd_t *pmds[])
25746+static void free_pxds(pxd_t *pxds[])
25747 {
25748 int i;
25749
25750- for(i = 0; i < PREALLOCATED_PMDS; i++)
25751- if (pmds[i])
25752- free_page((unsigned long)pmds[i]);
25753+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25754+ if (pxds[i])
25755+ free_page((unsigned long)pxds[i]);
25756 }
25757
25758-static int preallocate_pmds(pmd_t *pmds[])
25759+static int preallocate_pxds(pxd_t *pxds[])
25760 {
25761 int i;
25762 bool failed = false;
25763
25764- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25765- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25766- if (pmd == NULL)
25767+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25768+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25769+ if (pxd == NULL)
25770 failed = true;
25771- pmds[i] = pmd;
25772+ pxds[i] = pxd;
25773 }
25774
25775 if (failed) {
25776- free_pmds(pmds);
25777+ free_pxds(pxds);
25778 return -ENOMEM;
25779 }
25780
25781@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25782 * preallocate which never got a corresponding vma will need to be
25783 * freed manually.
25784 */
25785-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25786+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25787 {
25788 int i;
25789
25790- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25791+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25792 pgd_t pgd = pgdp[i];
25793
25794 if (pgd_val(pgd) != 0) {
25795- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25796+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25797
25798- pgdp[i] = native_make_pgd(0);
25799+ set_pgd(pgdp + i, native_make_pgd(0));
25800
25801- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25802- pmd_free(mm, pmd);
25803+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25804+ pxd_free(mm, pxd);
25805 }
25806 }
25807 }
25808
25809-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25810+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25811 {
25812- pud_t *pud;
25813+ pyd_t *pyd;
25814 unsigned long addr;
25815 int i;
25816
25817- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25818+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25819 return;
25820
25821- pud = pud_offset(pgd, 0);
25822+#ifdef CONFIG_X86_64
25823+ pyd = pyd_offset(mm, 0L);
25824+#else
25825+ pyd = pyd_offset(pgd, 0L);
25826+#endif
25827
25828- for (addr = i = 0; i < PREALLOCATED_PMDS;
25829- i++, pud++, addr += PUD_SIZE) {
25830- pmd_t *pmd = pmds[i];
25831+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25832+ i++, pyd++, addr += PYD_SIZE) {
25833+ pxd_t *pxd = pxds[i];
25834
25835 if (i >= KERNEL_PGD_BOUNDARY)
25836- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25837- sizeof(pmd_t) * PTRS_PER_PMD);
25838+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25839+ sizeof(pxd_t) * PTRS_PER_PMD);
25840
25841- pud_populate(mm, pud, pmd);
25842+ pyd_populate(mm, pyd, pxd);
25843 }
25844 }
25845
25846 pgd_t *pgd_alloc(struct mm_struct *mm)
25847 {
25848 pgd_t *pgd;
25849- pmd_t *pmds[PREALLOCATED_PMDS];
25850+ pxd_t *pxds[PREALLOCATED_PXDS];
25851
25852 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25853
25854@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25855
25856 mm->pgd = pgd;
25857
25858- if (preallocate_pmds(pmds) != 0)
25859+ if (preallocate_pxds(pxds) != 0)
25860 goto out_free_pgd;
25861
25862 if (paravirt_pgd_alloc(mm) != 0)
25863- goto out_free_pmds;
25864+ goto out_free_pxds;
25865
25866 /*
25867 * Make sure that pre-populating the pmds is atomic with
25868@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25869 spin_lock(&pgd_lock);
25870
25871 pgd_ctor(mm, pgd);
25872- pgd_prepopulate_pmd(mm, pgd, pmds);
25873+ pgd_prepopulate_pxd(mm, pgd, pxds);
25874
25875 spin_unlock(&pgd_lock);
25876
25877 return pgd;
25878
25879-out_free_pmds:
25880- free_pmds(pmds);
25881+out_free_pxds:
25882+ free_pxds(pxds);
25883 out_free_pgd:
25884 free_page((unsigned long)pgd);
25885 out:
25886@@ -295,7 +356,7 @@ out:
25887
25888 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25889 {
25890- pgd_mop_up_pmds(mm, pgd);
25891+ pgd_mop_up_pxds(mm, pgd);
25892 pgd_dtor(pgd);
25893 paravirt_pgd_free(mm, pgd);
25894 free_page((unsigned long)pgd);
25895diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25896index a69bcb8..19068ab 100644
25897--- a/arch/x86/mm/pgtable_32.c
25898+++ b/arch/x86/mm/pgtable_32.c
25899@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25900 return;
25901 }
25902 pte = pte_offset_kernel(pmd, vaddr);
25903+
25904+ pax_open_kernel();
25905 if (pte_val(pteval))
25906 set_pte_at(&init_mm, vaddr, pte, pteval);
25907 else
25908 pte_clear(&init_mm, vaddr, pte);
25909+ pax_close_kernel();
25910
25911 /*
25912 * It's enough to flush this one mapping.
25913diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25914index 410531d..0f16030 100644
25915--- a/arch/x86/mm/setup_nx.c
25916+++ b/arch/x86/mm/setup_nx.c
25917@@ -5,8 +5,10 @@
25918 #include <asm/pgtable.h>
25919 #include <asm/proto.h>
25920
25921+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25922 static int disable_nx __cpuinitdata;
25923
25924+#ifndef CONFIG_PAX_PAGEEXEC
25925 /*
25926 * noexec = on|off
25927 *
25928@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25929 return 0;
25930 }
25931 early_param("noexec", noexec_setup);
25932+#endif
25933+
25934+#endif
25935
25936 void __cpuinit x86_configure_nx(void)
25937 {
25938+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25939 if (cpu_has_nx && !disable_nx)
25940 __supported_pte_mask |= _PAGE_NX;
25941 else
25942+#endif
25943 __supported_pte_mask &= ~_PAGE_NX;
25944 }
25945
25946diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25947index d6c0418..06a0ad5 100644
25948--- a/arch/x86/mm/tlb.c
25949+++ b/arch/x86/mm/tlb.c
25950@@ -65,7 +65,11 @@ void leave_mm(int cpu)
25951 BUG();
25952 cpumask_clear_cpu(cpu,
25953 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25954+
25955+#ifndef CONFIG_PAX_PER_CPU_PGD
25956 load_cr3(swapper_pg_dir);
25957+#endif
25958+
25959 }
25960 EXPORT_SYMBOL_GPL(leave_mm);
25961
25962diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25963index 877b9a1..a8ecf42 100644
25964--- a/arch/x86/net/bpf_jit.S
25965+++ b/arch/x86/net/bpf_jit.S
25966@@ -9,6 +9,7 @@
25967 */
25968 #include <linux/linkage.h>
25969 #include <asm/dwarf2.h>
25970+#include <asm/alternative-asm.h>
25971
25972 /*
25973 * Calling convention :
25974@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25975 jle bpf_slow_path_word
25976 mov (SKBDATA,%rsi),%eax
25977 bswap %eax /* ntohl() */
25978+ pax_force_retaddr
25979 ret
25980
25981 sk_load_half:
25982@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25983 jle bpf_slow_path_half
25984 movzwl (SKBDATA,%rsi),%eax
25985 rol $8,%ax # ntohs()
25986+ pax_force_retaddr
25987 ret
25988
25989 sk_load_byte:
25990@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25991 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25992 jle bpf_slow_path_byte
25993 movzbl (SKBDATA,%rsi),%eax
25994+ pax_force_retaddr
25995 ret
25996
25997 /**
25998@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25999 movzbl (SKBDATA,%rsi),%ebx
26000 and $15,%bl
26001 shl $2,%bl
26002+ pax_force_retaddr
26003 ret
26004
26005 /* rsi contains offset and can be scratched */
26006@@ -109,6 +114,7 @@ bpf_slow_path_word:
26007 js bpf_error
26008 mov -12(%rbp),%eax
26009 bswap %eax
26010+ pax_force_retaddr
26011 ret
26012
26013 bpf_slow_path_half:
26014@@ -117,12 +123,14 @@ bpf_slow_path_half:
26015 mov -12(%rbp),%ax
26016 rol $8,%ax
26017 movzwl %ax,%eax
26018+ pax_force_retaddr
26019 ret
26020
26021 bpf_slow_path_byte:
26022 bpf_slow_path_common(1)
26023 js bpf_error
26024 movzbl -12(%rbp),%eax
26025+ pax_force_retaddr
26026 ret
26027
26028 bpf_slow_path_byte_msh:
26029@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
26030 and $15,%al
26031 shl $2,%al
26032 xchg %eax,%ebx
26033+ pax_force_retaddr
26034 ret
26035
26036 #define sk_negative_common(SIZE) \
26037@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26038 sk_negative_common(4)
26039 mov (%rax), %eax
26040 bswap %eax
26041+ pax_force_retaddr
26042 ret
26043
26044 bpf_slow_path_half_neg:
26045@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26046 mov (%rax),%ax
26047 rol $8,%ax
26048 movzwl %ax,%eax
26049+ pax_force_retaddr
26050 ret
26051
26052 bpf_slow_path_byte_neg:
26053@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26054 .globl sk_load_byte_negative_offset
26055 sk_negative_common(1)
26056 movzbl (%rax), %eax
26057+ pax_force_retaddr
26058 ret
26059
26060 bpf_slow_path_byte_msh_neg:
26061@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26062 and $15,%al
26063 shl $2,%al
26064 xchg %eax,%ebx
26065+ pax_force_retaddr
26066 ret
26067
26068 bpf_error:
26069@@ -197,4 +210,5 @@ bpf_error:
26070 xor %eax,%eax
26071 mov -8(%rbp),%rbx
26072 leaveq
26073+ pax_force_retaddr
26074 ret
26075diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26076index 0597f95..a12c36e 100644
26077--- a/arch/x86/net/bpf_jit_comp.c
26078+++ b/arch/x86/net/bpf_jit_comp.c
26079@@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26080 set_fs(old_fs);
26081 }
26082
26083+struct bpf_jit_work {
26084+ struct work_struct work;
26085+ void *image;
26086+};
26087+
26088 #define CHOOSE_LOAD_FUNC(K, func) \
26089 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26090
26091@@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26092 if (addrs == NULL)
26093 return;
26094
26095+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26096+ if (!fp->work)
26097+ goto out;
26098+
26099 /* Before first pass, make a rough estimation of addrs[]
26100 * each bpf instruction is translated to less than 64 bytes
26101 */
26102@@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26103 break;
26104 default:
26105 /* hmm, too complex filter, give up with jit compiler */
26106- goto out;
26107+ goto error;
26108 }
26109 ilen = prog - temp;
26110 if (image) {
26111 if (unlikely(proglen + ilen > oldproglen)) {
26112 pr_err("bpb_jit_compile fatal error\n");
26113- kfree(addrs);
26114- module_free(NULL, image);
26115- return;
26116+ module_free_exec(NULL, image);
26117+ goto error;
26118 }
26119+ pax_open_kernel();
26120 memcpy(image + proglen, temp, ilen);
26121+ pax_close_kernel();
26122 }
26123 proglen += ilen;
26124 addrs[i] = proglen;
26125@@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26126 break;
26127 }
26128 if (proglen == oldproglen) {
26129- image = module_alloc(max_t(unsigned int,
26130- proglen,
26131- sizeof(struct work_struct)));
26132+ image = module_alloc_exec(proglen);
26133 if (!image)
26134- goto out;
26135+ goto error;
26136 }
26137 oldproglen = proglen;
26138 }
26139@@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26140 bpf_flush_icache(image, image + proglen);
26141
26142 fp->bpf_func = (void *)image;
26143- }
26144+ } else
26145+error:
26146+ kfree(fp->work);
26147+
26148 out:
26149 kfree(addrs);
26150 return;
26151@@ -648,18 +659,20 @@ out:
26152
26153 static void jit_free_defer(struct work_struct *arg)
26154 {
26155- module_free(NULL, arg);
26156+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26157+ kfree(arg);
26158 }
26159
26160 /* run from softirq, we must use a work_struct to call
26161- * module_free() from process context
26162+ * module_free_exec() from process context
26163 */
26164 void bpf_jit_free(struct sk_filter *fp)
26165 {
26166 if (fp->bpf_func != sk_run_filter) {
26167- struct work_struct *work = (struct work_struct *)fp->bpf_func;
26168+ struct work_struct *work = &fp->work->work;
26169
26170 INIT_WORK(work, jit_free_defer);
26171+ fp->work->image = fp->bpf_func;
26172 schedule_work(work);
26173 }
26174 }
26175diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26176index d6aa6e8..266395a 100644
26177--- a/arch/x86/oprofile/backtrace.c
26178+++ b/arch/x86/oprofile/backtrace.c
26179@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26180 struct stack_frame_ia32 *fp;
26181 unsigned long bytes;
26182
26183- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26184+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26185 if (bytes != sizeof(bufhead))
26186 return NULL;
26187
26188- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26189+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26190
26191 oprofile_add_trace(bufhead[0].return_address);
26192
26193@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26194 struct stack_frame bufhead[2];
26195 unsigned long bytes;
26196
26197- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26198+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26199 if (bytes != sizeof(bufhead))
26200 return NULL;
26201
26202@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26203 {
26204 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26205
26206- if (!user_mode_vm(regs)) {
26207+ if (!user_mode(regs)) {
26208 unsigned long stack = kernel_stack_pointer(regs);
26209 if (depth)
26210 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26211diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26212index 140942f..8a5cc55 100644
26213--- a/arch/x86/pci/mrst.c
26214+++ b/arch/x86/pci/mrst.c
26215@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26216 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26217 pci_mmcfg_late_init();
26218 pcibios_enable_irq = mrst_pci_irq_enable;
26219- pci_root_ops = pci_mrst_ops;
26220+ pax_open_kernel();
26221+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26222+ pax_close_kernel();
26223 pci_soc_mode = 1;
26224 /* Continue with standard init */
26225 return 1;
26226diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26227index da8fe05..7ee6704 100644
26228--- a/arch/x86/pci/pcbios.c
26229+++ b/arch/x86/pci/pcbios.c
26230@@ -79,50 +79,93 @@ union bios32 {
26231 static struct {
26232 unsigned long address;
26233 unsigned short segment;
26234-} bios32_indirect = { 0, __KERNEL_CS };
26235+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26236
26237 /*
26238 * Returns the entry point for the given service, NULL on error
26239 */
26240
26241-static unsigned long bios32_service(unsigned long service)
26242+static unsigned long __devinit bios32_service(unsigned long service)
26243 {
26244 unsigned char return_code; /* %al */
26245 unsigned long address; /* %ebx */
26246 unsigned long length; /* %ecx */
26247 unsigned long entry; /* %edx */
26248 unsigned long flags;
26249+ struct desc_struct d, *gdt;
26250
26251 local_irq_save(flags);
26252- __asm__("lcall *(%%edi); cld"
26253+
26254+ gdt = get_cpu_gdt_table(smp_processor_id());
26255+
26256+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26257+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26258+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26259+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26260+
26261+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26262 : "=a" (return_code),
26263 "=b" (address),
26264 "=c" (length),
26265 "=d" (entry)
26266 : "0" (service),
26267 "1" (0),
26268- "D" (&bios32_indirect));
26269+ "D" (&bios32_indirect),
26270+ "r"(__PCIBIOS_DS)
26271+ : "memory");
26272+
26273+ pax_open_kernel();
26274+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26275+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26276+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26277+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26278+ pax_close_kernel();
26279+
26280 local_irq_restore(flags);
26281
26282 switch (return_code) {
26283- case 0:
26284- return address + entry;
26285- case 0x80: /* Not present */
26286- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26287- return 0;
26288- default: /* Shouldn't happen */
26289- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26290- service, return_code);
26291+ case 0: {
26292+ int cpu;
26293+ unsigned char flags;
26294+
26295+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26296+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26297+ printk(KERN_WARNING "bios32_service: not valid\n");
26298 return 0;
26299+ }
26300+ address = address + PAGE_OFFSET;
26301+ length += 16UL; /* some BIOSs underreport this... */
26302+ flags = 4;
26303+ if (length >= 64*1024*1024) {
26304+ length >>= PAGE_SHIFT;
26305+ flags |= 8;
26306+ }
26307+
26308+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26309+ gdt = get_cpu_gdt_table(cpu);
26310+ pack_descriptor(&d, address, length, 0x9b, flags);
26311+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26312+ pack_descriptor(&d, address, length, 0x93, flags);
26313+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26314+ }
26315+ return entry;
26316+ }
26317+ case 0x80: /* Not present */
26318+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26319+ return 0;
26320+ default: /* Shouldn't happen */
26321+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26322+ service, return_code);
26323+ return 0;
26324 }
26325 }
26326
26327 static struct {
26328 unsigned long address;
26329 unsigned short segment;
26330-} pci_indirect = { 0, __KERNEL_CS };
26331+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26332
26333-static int pci_bios_present;
26334+static int pci_bios_present __read_only;
26335
26336 static int __devinit check_pcibios(void)
26337 {
26338@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26339 unsigned long flags, pcibios_entry;
26340
26341 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26342- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26343+ pci_indirect.address = pcibios_entry;
26344
26345 local_irq_save(flags);
26346- __asm__(
26347- "lcall *(%%edi); cld\n\t"
26348+ __asm__("movw %w6, %%ds\n\t"
26349+ "lcall *%%ss:(%%edi); cld\n\t"
26350+ "push %%ss\n\t"
26351+ "pop %%ds\n\t"
26352 "jc 1f\n\t"
26353 "xor %%ah, %%ah\n"
26354 "1:"
26355@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26356 "=b" (ebx),
26357 "=c" (ecx)
26358 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26359- "D" (&pci_indirect)
26360+ "D" (&pci_indirect),
26361+ "r" (__PCIBIOS_DS)
26362 : "memory");
26363 local_irq_restore(flags);
26364
26365@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26366
26367 switch (len) {
26368 case 1:
26369- __asm__("lcall *(%%esi); cld\n\t"
26370+ __asm__("movw %w6, %%ds\n\t"
26371+ "lcall *%%ss:(%%esi); cld\n\t"
26372+ "push %%ss\n\t"
26373+ "pop %%ds\n\t"
26374 "jc 1f\n\t"
26375 "xor %%ah, %%ah\n"
26376 "1:"
26377@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26378 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26379 "b" (bx),
26380 "D" ((long)reg),
26381- "S" (&pci_indirect));
26382+ "S" (&pci_indirect),
26383+ "r" (__PCIBIOS_DS));
26384 /*
26385 * Zero-extend the result beyond 8 bits, do not trust the
26386 * BIOS having done it:
26387@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26388 *value &= 0xff;
26389 break;
26390 case 2:
26391- __asm__("lcall *(%%esi); cld\n\t"
26392+ __asm__("movw %w6, %%ds\n\t"
26393+ "lcall *%%ss:(%%esi); cld\n\t"
26394+ "push %%ss\n\t"
26395+ "pop %%ds\n\t"
26396 "jc 1f\n\t"
26397 "xor %%ah, %%ah\n"
26398 "1:"
26399@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26400 : "1" (PCIBIOS_READ_CONFIG_WORD),
26401 "b" (bx),
26402 "D" ((long)reg),
26403- "S" (&pci_indirect));
26404+ "S" (&pci_indirect),
26405+ "r" (__PCIBIOS_DS));
26406 /*
26407 * Zero-extend the result beyond 16 bits, do not trust the
26408 * BIOS having done it:
26409@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26410 *value &= 0xffff;
26411 break;
26412 case 4:
26413- __asm__("lcall *(%%esi); cld\n\t"
26414+ __asm__("movw %w6, %%ds\n\t"
26415+ "lcall *%%ss:(%%esi); cld\n\t"
26416+ "push %%ss\n\t"
26417+ "pop %%ds\n\t"
26418 "jc 1f\n\t"
26419 "xor %%ah, %%ah\n"
26420 "1:"
26421@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26422 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26423 "b" (bx),
26424 "D" ((long)reg),
26425- "S" (&pci_indirect));
26426+ "S" (&pci_indirect),
26427+ "r" (__PCIBIOS_DS));
26428 break;
26429 }
26430
26431@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26432
26433 switch (len) {
26434 case 1:
26435- __asm__("lcall *(%%esi); cld\n\t"
26436+ __asm__("movw %w6, %%ds\n\t"
26437+ "lcall *%%ss:(%%esi); cld\n\t"
26438+ "push %%ss\n\t"
26439+ "pop %%ds\n\t"
26440 "jc 1f\n\t"
26441 "xor %%ah, %%ah\n"
26442 "1:"
26443@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26444 "c" (value),
26445 "b" (bx),
26446 "D" ((long)reg),
26447- "S" (&pci_indirect));
26448+ "S" (&pci_indirect),
26449+ "r" (__PCIBIOS_DS));
26450 break;
26451 case 2:
26452- __asm__("lcall *(%%esi); cld\n\t"
26453+ __asm__("movw %w6, %%ds\n\t"
26454+ "lcall *%%ss:(%%esi); cld\n\t"
26455+ "push %%ss\n\t"
26456+ "pop %%ds\n\t"
26457 "jc 1f\n\t"
26458 "xor %%ah, %%ah\n"
26459 "1:"
26460@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26461 "c" (value),
26462 "b" (bx),
26463 "D" ((long)reg),
26464- "S" (&pci_indirect));
26465+ "S" (&pci_indirect),
26466+ "r" (__PCIBIOS_DS));
26467 break;
26468 case 4:
26469- __asm__("lcall *(%%esi); cld\n\t"
26470+ __asm__("movw %w6, %%ds\n\t"
26471+ "lcall *%%ss:(%%esi); cld\n\t"
26472+ "push %%ss\n\t"
26473+ "pop %%ds\n\t"
26474 "jc 1f\n\t"
26475 "xor %%ah, %%ah\n"
26476 "1:"
26477@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26478 "c" (value),
26479 "b" (bx),
26480 "D" ((long)reg),
26481- "S" (&pci_indirect));
26482+ "S" (&pci_indirect),
26483+ "r" (__PCIBIOS_DS));
26484 break;
26485 }
26486
26487@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26488
26489 DBG("PCI: Fetching IRQ routing table... ");
26490 __asm__("push %%es\n\t"
26491+ "movw %w8, %%ds\n\t"
26492 "push %%ds\n\t"
26493 "pop %%es\n\t"
26494- "lcall *(%%esi); cld\n\t"
26495+ "lcall *%%ss:(%%esi); cld\n\t"
26496 "pop %%es\n\t"
26497+ "push %%ss\n\t"
26498+ "pop %%ds\n"
26499 "jc 1f\n\t"
26500 "xor %%ah, %%ah\n"
26501 "1:"
26502@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26503 "1" (0),
26504 "D" ((long) &opt),
26505 "S" (&pci_indirect),
26506- "m" (opt)
26507+ "m" (opt),
26508+ "r" (__PCIBIOS_DS)
26509 : "memory");
26510 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26511 if (ret & 0xff00)
26512@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26513 {
26514 int ret;
26515
26516- __asm__("lcall *(%%esi); cld\n\t"
26517+ __asm__("movw %w5, %%ds\n\t"
26518+ "lcall *%%ss:(%%esi); cld\n\t"
26519+ "push %%ss\n\t"
26520+ "pop %%ds\n"
26521 "jc 1f\n\t"
26522 "xor %%ah, %%ah\n"
26523 "1:"
26524@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26525 : "0" (PCIBIOS_SET_PCI_HW_INT),
26526 "b" ((dev->bus->number << 8) | dev->devfn),
26527 "c" ((irq << 8) | (pin + 10)),
26528- "S" (&pci_indirect));
26529+ "S" (&pci_indirect),
26530+ "r" (__PCIBIOS_DS));
26531 return !(ret & 0xff00);
26532 }
26533 EXPORT_SYMBOL(pcibios_set_irq_routing);
26534diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26535index 40e4469..1ab536e 100644
26536--- a/arch/x86/platform/efi/efi_32.c
26537+++ b/arch/x86/platform/efi/efi_32.c
26538@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26539 {
26540 struct desc_ptr gdt_descr;
26541
26542+#ifdef CONFIG_PAX_KERNEXEC
26543+ struct desc_struct d;
26544+#endif
26545+
26546 local_irq_save(efi_rt_eflags);
26547
26548 load_cr3(initial_page_table);
26549 __flush_tlb_all();
26550
26551+#ifdef CONFIG_PAX_KERNEXEC
26552+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26553+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26554+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26555+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26556+#endif
26557+
26558 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26559 gdt_descr.size = GDT_SIZE - 1;
26560 load_gdt(&gdt_descr);
26561@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26562 {
26563 struct desc_ptr gdt_descr;
26564
26565+#ifdef CONFIG_PAX_KERNEXEC
26566+ struct desc_struct d;
26567+
26568+ memset(&d, 0, sizeof d);
26569+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26570+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26571+#endif
26572+
26573 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26574 gdt_descr.size = GDT_SIZE - 1;
26575 load_gdt(&gdt_descr);
26576diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26577index fbe66e6..c5c0dd2 100644
26578--- a/arch/x86/platform/efi/efi_stub_32.S
26579+++ b/arch/x86/platform/efi/efi_stub_32.S
26580@@ -6,7 +6,9 @@
26581 */
26582
26583 #include <linux/linkage.h>
26584+#include <linux/init.h>
26585 #include <asm/page_types.h>
26586+#include <asm/segment.h>
26587
26588 /*
26589 * efi_call_phys(void *, ...) is a function with variable parameters.
26590@@ -20,7 +22,7 @@
26591 * service functions will comply with gcc calling convention, too.
26592 */
26593
26594-.text
26595+__INIT
26596 ENTRY(efi_call_phys)
26597 /*
26598 * 0. The function can only be called in Linux kernel. So CS has been
26599@@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26600 * The mapping of lower virtual memory has been created in prelog and
26601 * epilog.
26602 */
26603- movl $1f, %edx
26604- subl $__PAGE_OFFSET, %edx
26605- jmp *%edx
26606+ movl $(__KERNEXEC_EFI_DS), %edx
26607+ mov %edx, %ds
26608+ mov %edx, %es
26609+ mov %edx, %ss
26610+ ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26611 1:
26612
26613 /*
26614@@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26615 * parameter 2, ..., param n. To make things easy, we save the return
26616 * address of efi_call_phys in a global variable.
26617 */
26618- popl %edx
26619- movl %edx, saved_return_addr
26620- /* get the function pointer into ECX*/
26621- popl %ecx
26622- movl %ecx, efi_rt_function_ptr
26623- movl $2f, %edx
26624- subl $__PAGE_OFFSET, %edx
26625- pushl %edx
26626+ popl (saved_return_addr)
26627+ popl (efi_rt_function_ptr)
26628
26629 /*
26630 * 3. Clear PG bit in %CR0.
26631@@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26632 /*
26633 * 5. Call the physical function.
26634 */
26635- jmp *%ecx
26636+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26637
26638-2:
26639 /*
26640 * 6. After EFI runtime service returns, control will return to
26641 * following instruction. We'd better readjust stack pointer first.
26642@@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26643 movl %cr0, %edx
26644 orl $0x80000000, %edx
26645 movl %edx, %cr0
26646- jmp 1f
26647-1:
26648+
26649 /*
26650 * 8. Now restore the virtual mode from flat mode by
26651 * adding EIP with PAGE_OFFSET.
26652 */
26653- movl $1f, %edx
26654- jmp *%edx
26655+ ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26656 1:
26657+ movl $(__KERNEL_DS), %edx
26658+ mov %edx, %ds
26659+ mov %edx, %es
26660+ mov %edx, %ss
26661
26662 /*
26663 * 9. Balance the stack. And because EAX contain the return value,
26664 * we'd better not clobber it.
26665 */
26666- leal efi_rt_function_ptr, %edx
26667- movl (%edx), %ecx
26668- pushl %ecx
26669+ pushl (efi_rt_function_ptr)
26670
26671 /*
26672- * 10. Push the saved return address onto the stack and return.
26673+ * 10. Return to the saved return address.
26674 */
26675- leal saved_return_addr, %edx
26676- movl (%edx), %ecx
26677- pushl %ecx
26678- ret
26679+ jmpl *(saved_return_addr)
26680 ENDPROC(efi_call_phys)
26681 .previous
26682
26683-.data
26684+__INITDATA
26685 saved_return_addr:
26686 .long 0
26687 efi_rt_function_ptr:
26688diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26689index 4c07cca..2c8427d 100644
26690--- a/arch/x86/platform/efi/efi_stub_64.S
26691+++ b/arch/x86/platform/efi/efi_stub_64.S
26692@@ -7,6 +7,7 @@
26693 */
26694
26695 #include <linux/linkage.h>
26696+#include <asm/alternative-asm.h>
26697
26698 #define SAVE_XMM \
26699 mov %rsp, %rax; \
26700@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26701 call *%rdi
26702 addq $32, %rsp
26703 RESTORE_XMM
26704+ pax_force_retaddr 0, 1
26705 ret
26706 ENDPROC(efi_call0)
26707
26708@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26709 call *%rdi
26710 addq $32, %rsp
26711 RESTORE_XMM
26712+ pax_force_retaddr 0, 1
26713 ret
26714 ENDPROC(efi_call1)
26715
26716@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26717 call *%rdi
26718 addq $32, %rsp
26719 RESTORE_XMM
26720+ pax_force_retaddr 0, 1
26721 ret
26722 ENDPROC(efi_call2)
26723
26724@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26725 call *%rdi
26726 addq $32, %rsp
26727 RESTORE_XMM
26728+ pax_force_retaddr 0, 1
26729 ret
26730 ENDPROC(efi_call3)
26731
26732@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26733 call *%rdi
26734 addq $32, %rsp
26735 RESTORE_XMM
26736+ pax_force_retaddr 0, 1
26737 ret
26738 ENDPROC(efi_call4)
26739
26740@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26741 call *%rdi
26742 addq $48, %rsp
26743 RESTORE_XMM
26744+ pax_force_retaddr 0, 1
26745 ret
26746 ENDPROC(efi_call5)
26747
26748@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26749 call *%rdi
26750 addq $48, %rsp
26751 RESTORE_XMM
26752+ pax_force_retaddr 0, 1
26753 ret
26754 ENDPROC(efi_call6)
26755diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26756index e31bcd8..f12dc46 100644
26757--- a/arch/x86/platform/mrst/mrst.c
26758+++ b/arch/x86/platform/mrst/mrst.c
26759@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26760 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26761 int sfi_mrtc_num;
26762
26763-static void mrst_power_off(void)
26764+static __noreturn void mrst_power_off(void)
26765 {
26766+ BUG();
26767 }
26768
26769-static void mrst_reboot(void)
26770+static __noreturn void mrst_reboot(void)
26771 {
26772 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26773+ BUG();
26774 }
26775
26776 /* parse all the mtimer info to a static mtimer array */
26777diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26778index 218cdb1..fd55c08 100644
26779--- a/arch/x86/power/cpu.c
26780+++ b/arch/x86/power/cpu.c
26781@@ -132,7 +132,7 @@ static void do_fpu_end(void)
26782 static void fix_processor_context(void)
26783 {
26784 int cpu = smp_processor_id();
26785- struct tss_struct *t = &per_cpu(init_tss, cpu);
26786+ struct tss_struct *t = init_tss + cpu;
26787
26788 set_tss_desc(cpu, t); /*
26789 * This just modifies memory; should not be
26790@@ -142,7 +142,9 @@ static void fix_processor_context(void)
26791 */
26792
26793 #ifdef CONFIG_X86_64
26794+ pax_open_kernel();
26795 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26796+ pax_close_kernel();
26797
26798 syscall_init(); /* This sets MSR_*STAR and related */
26799 #endif
26800diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26801index b685296..4ac6aaa 100644
26802--- a/arch/x86/tools/relocs.c
26803+++ b/arch/x86/tools/relocs.c
26804@@ -12,10 +12,13 @@
26805 #include <regex.h>
26806 #include <tools/le_byteshift.h>
26807
26808+#include "../../../include/generated/autoconf.h"
26809+
26810 static void die(char *fmt, ...);
26811
26812 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26813 static Elf32_Ehdr ehdr;
26814+static Elf32_Phdr *phdr;
26815 static unsigned long reloc_count, reloc_idx;
26816 static unsigned long *relocs;
26817 static unsigned long reloc16_count, reloc16_idx;
26818@@ -323,9 +326,39 @@ static void read_ehdr(FILE *fp)
26819 }
26820 }
26821
26822+static void read_phdrs(FILE *fp)
26823+{
26824+ unsigned int i;
26825+
26826+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26827+ if (!phdr) {
26828+ die("Unable to allocate %d program headers\n",
26829+ ehdr.e_phnum);
26830+ }
26831+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26832+ die("Seek to %d failed: %s\n",
26833+ ehdr.e_phoff, strerror(errno));
26834+ }
26835+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26836+ die("Cannot read ELF program headers: %s\n",
26837+ strerror(errno));
26838+ }
26839+ for(i = 0; i < ehdr.e_phnum; i++) {
26840+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26841+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26842+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26843+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26844+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26845+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26846+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26847+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26848+ }
26849+
26850+}
26851+
26852 static void read_shdrs(FILE *fp)
26853 {
26854- int i;
26855+ unsigned int i;
26856 Elf32_Shdr shdr;
26857
26858 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26859@@ -360,7 +393,7 @@ static void read_shdrs(FILE *fp)
26860
26861 static void read_strtabs(FILE *fp)
26862 {
26863- int i;
26864+ unsigned int i;
26865 for (i = 0; i < ehdr.e_shnum; i++) {
26866 struct section *sec = &secs[i];
26867 if (sec->shdr.sh_type != SHT_STRTAB) {
26868@@ -385,7 +418,7 @@ static void read_strtabs(FILE *fp)
26869
26870 static void read_symtabs(FILE *fp)
26871 {
26872- int i,j;
26873+ unsigned int i,j;
26874 for (i = 0; i < ehdr.e_shnum; i++) {
26875 struct section *sec = &secs[i];
26876 if (sec->shdr.sh_type != SHT_SYMTAB) {
26877@@ -418,7 +451,9 @@ static void read_symtabs(FILE *fp)
26878
26879 static void read_relocs(FILE *fp)
26880 {
26881- int i,j;
26882+ unsigned int i,j;
26883+ uint32_t base;
26884+
26885 for (i = 0; i < ehdr.e_shnum; i++) {
26886 struct section *sec = &secs[i];
26887 if (sec->shdr.sh_type != SHT_REL) {
26888@@ -438,9 +473,22 @@ static void read_relocs(FILE *fp)
26889 die("Cannot read symbol table: %s\n",
26890 strerror(errno));
26891 }
26892+ base = 0;
26893+
26894+#ifdef CONFIG_X86_32
26895+ for (j = 0; j < ehdr.e_phnum; j++) {
26896+ if (phdr[j].p_type != PT_LOAD )
26897+ continue;
26898+ 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)
26899+ continue;
26900+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26901+ break;
26902+ }
26903+#endif
26904+
26905 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26906 Elf32_Rel *rel = &sec->reltab[j];
26907- rel->r_offset = elf32_to_cpu(rel->r_offset);
26908+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26909 rel->r_info = elf32_to_cpu(rel->r_info);
26910 }
26911 }
26912@@ -449,13 +497,13 @@ static void read_relocs(FILE *fp)
26913
26914 static void print_absolute_symbols(void)
26915 {
26916- int i;
26917+ unsigned int i;
26918 printf("Absolute symbols\n");
26919 printf(" Num: Value Size Type Bind Visibility Name\n");
26920 for (i = 0; i < ehdr.e_shnum; i++) {
26921 struct section *sec = &secs[i];
26922 char *sym_strtab;
26923- int j;
26924+ unsigned int j;
26925
26926 if (sec->shdr.sh_type != SHT_SYMTAB) {
26927 continue;
26928@@ -482,14 +530,14 @@ static void print_absolute_symbols(void)
26929
26930 static void print_absolute_relocs(void)
26931 {
26932- int i, printed = 0;
26933+ unsigned int i, printed = 0;
26934
26935 for (i = 0; i < ehdr.e_shnum; i++) {
26936 struct section *sec = &secs[i];
26937 struct section *sec_applies, *sec_symtab;
26938 char *sym_strtab;
26939 Elf32_Sym *sh_symtab;
26940- int j;
26941+ unsigned int j;
26942 if (sec->shdr.sh_type != SHT_REL) {
26943 continue;
26944 }
26945@@ -551,13 +599,13 @@ static void print_absolute_relocs(void)
26946 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26947 int use_real_mode)
26948 {
26949- int i;
26950+ unsigned int i;
26951 /* Walk through the relocations */
26952 for (i = 0; i < ehdr.e_shnum; i++) {
26953 char *sym_strtab;
26954 Elf32_Sym *sh_symtab;
26955 struct section *sec_applies, *sec_symtab;
26956- int j;
26957+ unsigned int j;
26958 struct section *sec = &secs[i];
26959
26960 if (sec->shdr.sh_type != SHT_REL) {
26961@@ -581,6 +629,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26962 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26963 r_type = ELF32_R_TYPE(rel->r_info);
26964
26965+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26966+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26967+ continue;
26968+
26969+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26970+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26971+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26972+ continue;
26973+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26974+ continue;
26975+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26976+ continue;
26977+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26978+ continue;
26979+#endif
26980+
26981 shn_abs = sym->st_shndx == SHN_ABS;
26982
26983 switch (r_type) {
26984@@ -674,7 +738,7 @@ static int write32(unsigned int v, FILE *f)
26985
26986 static void emit_relocs(int as_text, int use_real_mode)
26987 {
26988- int i;
26989+ unsigned int i;
26990 /* Count how many relocations I have and allocate space for them. */
26991 reloc_count = 0;
26992 walk_relocs(count_reloc, use_real_mode);
26993@@ -801,6 +865,7 @@ int main(int argc, char **argv)
26994 fname, strerror(errno));
26995 }
26996 read_ehdr(fp);
26997+ read_phdrs(fp);
26998 read_shdrs(fp);
26999 read_strtabs(fp);
27000 read_symtabs(fp);
27001diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27002index fd14be1..e3c79c0 100644
27003--- a/arch/x86/vdso/Makefile
27004+++ b/arch/x86/vdso/Makefile
27005@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27006 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27007 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27008
27009-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27010+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27011 GCOV_PROFILE := n
27012
27013 #
27014diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27015index 66e6d93..587f435 100644
27016--- a/arch/x86/vdso/vdso32-setup.c
27017+++ b/arch/x86/vdso/vdso32-setup.c
27018@@ -25,6 +25,7 @@
27019 #include <asm/tlbflush.h>
27020 #include <asm/vdso.h>
27021 #include <asm/proto.h>
27022+#include <asm/mman.h>
27023
27024 enum {
27025 VDSO_DISABLED = 0,
27026@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27027 void enable_sep_cpu(void)
27028 {
27029 int cpu = get_cpu();
27030- struct tss_struct *tss = &per_cpu(init_tss, cpu);
27031+ struct tss_struct *tss = init_tss + cpu;
27032
27033 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27034 put_cpu();
27035@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27036 gate_vma.vm_start = FIXADDR_USER_START;
27037 gate_vma.vm_end = FIXADDR_USER_END;
27038 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27039- gate_vma.vm_page_prot = __P101;
27040+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27041
27042 return 0;
27043 }
27044@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27045 if (compat)
27046 addr = VDSO_HIGH_BASE;
27047 else {
27048- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27049+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27050 if (IS_ERR_VALUE(addr)) {
27051 ret = addr;
27052 goto up_fail;
27053 }
27054 }
27055
27056- current->mm->context.vdso = (void *)addr;
27057+ current->mm->context.vdso = addr;
27058
27059 if (compat_uses_vma || !compat) {
27060 /*
27061@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27062 }
27063
27064 current_thread_info()->sysenter_return =
27065- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27066+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27067
27068 up_fail:
27069 if (ret)
27070- current->mm->context.vdso = NULL;
27071+ current->mm->context.vdso = 0;
27072
27073 up_write(&mm->mmap_sem);
27074
27075@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27076
27077 const char *arch_vma_name(struct vm_area_struct *vma)
27078 {
27079- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27080+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27081 return "[vdso]";
27082+
27083+#ifdef CONFIG_PAX_SEGMEXEC
27084+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27085+ return "[vdso]";
27086+#endif
27087+
27088 return NULL;
27089 }
27090
27091@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27092 * Check to see if the corresponding task was created in compat vdso
27093 * mode.
27094 */
27095- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27096+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27097 return &gate_vma;
27098 return NULL;
27099 }
27100diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27101index 00aaf04..4a26505 100644
27102--- a/arch/x86/vdso/vma.c
27103+++ b/arch/x86/vdso/vma.c
27104@@ -16,8 +16,6 @@
27105 #include <asm/vdso.h>
27106 #include <asm/page.h>
27107
27108-unsigned int __read_mostly vdso_enabled = 1;
27109-
27110 extern char vdso_start[], vdso_end[];
27111 extern unsigned short vdso_sync_cpuid;
27112
27113@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27114 * unaligned here as a result of stack start randomization.
27115 */
27116 addr = PAGE_ALIGN(addr);
27117- addr = align_addr(addr, NULL, ALIGN_VDSO);
27118
27119 return addr;
27120 }
27121@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27122 unsigned size)
27123 {
27124 struct mm_struct *mm = current->mm;
27125- unsigned long addr;
27126+ unsigned long addr = 0;
27127 int ret;
27128
27129- if (!vdso_enabled)
27130- return 0;
27131-
27132 down_write(&mm->mmap_sem);
27133+
27134+#ifdef CONFIG_PAX_RANDMMAP
27135+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27136+#endif
27137+
27138 addr = vdso_addr(mm->start_stack, size);
27139+ addr = align_addr(addr, NULL, ALIGN_VDSO);
27140 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27141 if (IS_ERR_VALUE(addr)) {
27142 ret = addr;
27143 goto up_fail;
27144 }
27145
27146- current->mm->context.vdso = (void *)addr;
27147+ mm->context.vdso = addr;
27148
27149 ret = install_special_mapping(mm, addr, size,
27150 VM_READ|VM_EXEC|
27151 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27152 pages);
27153- if (ret) {
27154- current->mm->context.vdso = NULL;
27155- goto up_fail;
27156- }
27157+ if (ret)
27158+ mm->context.vdso = 0;
27159
27160 up_fail:
27161 up_write(&mm->mmap_sem);
27162@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27163 vdsox32_size);
27164 }
27165 #endif
27166-
27167-static __init int vdso_setup(char *s)
27168-{
27169- vdso_enabled = simple_strtoul(s, NULL, 0);
27170- return 0;
27171-}
27172-__setup("vdso=", vdso_setup);
27173diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27174index 40edfc3..b4d80ac 100644
27175--- a/arch/x86/xen/enlighten.c
27176+++ b/arch/x86/xen/enlighten.c
27177@@ -95,8 +95,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27178
27179 struct shared_info xen_dummy_shared_info;
27180
27181-void *xen_initial_gdt;
27182-
27183 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27184 __read_mostly int xen_have_vector_callback;
27185 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27186@@ -1165,30 +1163,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27187 #endif
27188 };
27189
27190-static void xen_reboot(int reason)
27191+static __noreturn void xen_reboot(int reason)
27192 {
27193 struct sched_shutdown r = { .reason = reason };
27194
27195- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27196- BUG();
27197+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27198+ BUG();
27199 }
27200
27201-static void xen_restart(char *msg)
27202+static __noreturn void xen_restart(char *msg)
27203 {
27204 xen_reboot(SHUTDOWN_reboot);
27205 }
27206
27207-static void xen_emergency_restart(void)
27208+static __noreturn void xen_emergency_restart(void)
27209 {
27210 xen_reboot(SHUTDOWN_reboot);
27211 }
27212
27213-static void xen_machine_halt(void)
27214+static __noreturn void xen_machine_halt(void)
27215 {
27216 xen_reboot(SHUTDOWN_poweroff);
27217 }
27218
27219-static void xen_machine_power_off(void)
27220+static __noreturn void xen_machine_power_off(void)
27221 {
27222 if (pm_power_off)
27223 pm_power_off();
27224@@ -1291,7 +1289,17 @@ asmlinkage void __init xen_start_kernel(void)
27225 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27226
27227 /* Work out if we support NX */
27228- x86_configure_nx();
27229+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27230+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27231+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27232+ unsigned l, h;
27233+
27234+ __supported_pte_mask |= _PAGE_NX;
27235+ rdmsr(MSR_EFER, l, h);
27236+ l |= EFER_NX;
27237+ wrmsr(MSR_EFER, l, h);
27238+ }
27239+#endif
27240
27241 xen_setup_features();
27242
27243@@ -1322,13 +1330,6 @@ asmlinkage void __init xen_start_kernel(void)
27244
27245 machine_ops = xen_machine_ops;
27246
27247- /*
27248- * The only reliable way to retain the initial address of the
27249- * percpu gdt_page is to remember it here, so we can go and
27250- * mark it RW later, when the initial percpu area is freed.
27251- */
27252- xen_initial_gdt = &per_cpu(gdt_page, 0);
27253-
27254 xen_smp_init();
27255
27256 #ifdef CONFIG_ACPI_NUMA
27257diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27258index 69f5857..0699dc5 100644
27259--- a/arch/x86/xen/mmu.c
27260+++ b/arch/x86/xen/mmu.c
27261@@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27262 convert_pfn_mfn(init_level4_pgt);
27263 convert_pfn_mfn(level3_ident_pgt);
27264 convert_pfn_mfn(level3_kernel_pgt);
27265+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27266+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27267+ convert_pfn_mfn(level3_vmemmap_pgt);
27268
27269 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27270 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27271@@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27272 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27273 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27274 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27275+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27276+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27277+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27278 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27279+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27280 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27281 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27282
27283@@ -1964,6 +1971,7 @@ static void __init xen_post_allocator_init(void)
27284 pv_mmu_ops.set_pud = xen_set_pud;
27285 #if PAGETABLE_LEVELS == 4
27286 pv_mmu_ops.set_pgd = xen_set_pgd;
27287+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27288 #endif
27289
27290 /* This will work as long as patching hasn't happened yet
27291@@ -2045,6 +2053,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27292 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27293 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27294 .set_pgd = xen_set_pgd_hyper,
27295+ .set_pgd_batched = xen_set_pgd_hyper,
27296
27297 .alloc_pud = xen_alloc_pmd_init,
27298 .release_pud = xen_release_pmd_init,
27299diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27300index 0503c0c..ceb2d16 100644
27301--- a/arch/x86/xen/smp.c
27302+++ b/arch/x86/xen/smp.c
27303@@ -215,11 +215,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27304 {
27305 BUG_ON(smp_processor_id() != 0);
27306 native_smp_prepare_boot_cpu();
27307-
27308- /* We've switched to the "real" per-cpu gdt, so make sure the
27309- old memory can be recycled */
27310- make_lowmem_page_readwrite(xen_initial_gdt);
27311-
27312 xen_filter_cpu_maps();
27313 xen_setup_vcpu_info_placement();
27314 }
27315@@ -296,12 +291,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27316 gdt = get_cpu_gdt_table(cpu);
27317
27318 ctxt->flags = VGCF_IN_KERNEL;
27319- ctxt->user_regs.ds = __USER_DS;
27320- ctxt->user_regs.es = __USER_DS;
27321+ ctxt->user_regs.ds = __KERNEL_DS;
27322+ ctxt->user_regs.es = __KERNEL_DS;
27323 ctxt->user_regs.ss = __KERNEL_DS;
27324 #ifdef CONFIG_X86_32
27325 ctxt->user_regs.fs = __KERNEL_PERCPU;
27326- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27327+ savesegment(gs, ctxt->user_regs.gs);
27328 #else
27329 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27330 #endif
27331@@ -352,13 +347,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
27332 int rc;
27333
27334 per_cpu(current_task, cpu) = idle;
27335+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27336 #ifdef CONFIG_X86_32
27337 irq_ctx_init(cpu);
27338 #else
27339 clear_tsk_thread_flag(idle, TIF_FORK);
27340- per_cpu(kernel_stack, cpu) =
27341- (unsigned long)task_stack_page(idle) -
27342- KERNEL_STACK_OFFSET + THREAD_SIZE;
27343+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27344 #endif
27345 xen_setup_runstate_info(cpu);
27346 xen_setup_timer(cpu);
27347diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27348index b040b0e..8cc4fe0 100644
27349--- a/arch/x86/xen/xen-asm_32.S
27350+++ b/arch/x86/xen/xen-asm_32.S
27351@@ -83,14 +83,14 @@ ENTRY(xen_iret)
27352 ESP_OFFSET=4 # bytes pushed onto stack
27353
27354 /*
27355- * Store vcpu_info pointer for easy access. Do it this way to
27356- * avoid having to reload %fs
27357+ * Store vcpu_info pointer for easy access.
27358 */
27359 #ifdef CONFIG_SMP
27360- GET_THREAD_INFO(%eax)
27361- movl TI_cpu(%eax), %eax
27362- movl __per_cpu_offset(,%eax,4), %eax
27363- mov xen_vcpu(%eax), %eax
27364+ push %fs
27365+ mov $(__KERNEL_PERCPU), %eax
27366+ mov %eax, %fs
27367+ mov PER_CPU_VAR(xen_vcpu), %eax
27368+ pop %fs
27369 #else
27370 movl xen_vcpu, %eax
27371 #endif
27372diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27373index aaa7291..3f77960 100644
27374--- a/arch/x86/xen/xen-head.S
27375+++ b/arch/x86/xen/xen-head.S
27376@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27377 #ifdef CONFIG_X86_32
27378 mov %esi,xen_start_info
27379 mov $init_thread_union+THREAD_SIZE,%esp
27380+#ifdef CONFIG_SMP
27381+ movl $cpu_gdt_table,%edi
27382+ movl $__per_cpu_load,%eax
27383+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27384+ rorl $16,%eax
27385+ movb %al,__KERNEL_PERCPU + 4(%edi)
27386+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27387+ movl $__per_cpu_end - 1,%eax
27388+ subl $__per_cpu_start,%eax
27389+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27390+#endif
27391 #else
27392 mov %rsi,xen_start_info
27393 mov $init_thread_union+THREAD_SIZE,%rsp
27394diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27395index b095739..8c17bcd 100644
27396--- a/arch/x86/xen/xen-ops.h
27397+++ b/arch/x86/xen/xen-ops.h
27398@@ -10,8 +10,6 @@
27399 extern const char xen_hypervisor_callback[];
27400 extern const char xen_failsafe_callback[];
27401
27402-extern void *xen_initial_gdt;
27403-
27404 struct trap_info;
27405 void xen_copy_trap_info(struct trap_info *traps);
27406
27407diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27408index 525bd3d..ef888b1 100644
27409--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27410+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27411@@ -119,9 +119,9 @@
27412 ----------------------------------------------------------------------*/
27413
27414 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27415-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27416 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27417 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27418+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27419
27420 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27421 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27422diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27423index 2f33760..835e50a 100644
27424--- a/arch/xtensa/variants/fsf/include/variant/core.h
27425+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27426@@ -11,6 +11,7 @@
27427 #ifndef _XTENSA_CORE_H
27428 #define _XTENSA_CORE_H
27429
27430+#include <linux/const.h>
27431
27432 /****************************************************************************
27433 Parameters Useful for Any Code, USER or PRIVILEGED
27434@@ -112,9 +113,9 @@
27435 ----------------------------------------------------------------------*/
27436
27437 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27438-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27439 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27440 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27441+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27442
27443 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27444 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27445diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27446index af00795..2bb8105 100644
27447--- a/arch/xtensa/variants/s6000/include/variant/core.h
27448+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27449@@ -11,6 +11,7 @@
27450 #ifndef _XTENSA_CORE_CONFIGURATION_H
27451 #define _XTENSA_CORE_CONFIGURATION_H
27452
27453+#include <linux/const.h>
27454
27455 /****************************************************************************
27456 Parameters Useful for Any Code, USER or PRIVILEGED
27457@@ -118,9 +119,9 @@
27458 ----------------------------------------------------------------------*/
27459
27460 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27461-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27462 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27463 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27464+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27465
27466 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27467 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27468diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27469index 58916af..9cb880b 100644
27470--- a/block/blk-iopoll.c
27471+++ b/block/blk-iopoll.c
27472@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27473 }
27474 EXPORT_SYMBOL(blk_iopoll_complete);
27475
27476-static void blk_iopoll_softirq(struct softirq_action *h)
27477+static void blk_iopoll_softirq(void)
27478 {
27479 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27480 int rearm = 0, budget = blk_iopoll_budget;
27481diff --git a/block/blk-map.c b/block/blk-map.c
27482index 623e1cd..ca1e109 100644
27483--- a/block/blk-map.c
27484+++ b/block/blk-map.c
27485@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27486 if (!len || !kbuf)
27487 return -EINVAL;
27488
27489- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27490+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27491 if (do_copy)
27492 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27493 else
27494diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27495index 467c8de..4bddc6d 100644
27496--- a/block/blk-softirq.c
27497+++ b/block/blk-softirq.c
27498@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27499 * Softirq action handler - move entries to local list and loop over them
27500 * while passing them to the queue registered handler.
27501 */
27502-static void blk_done_softirq(struct softirq_action *h)
27503+static void blk_done_softirq(void)
27504 {
27505 struct list_head *cpu_list, local_list;
27506
27507diff --git a/block/bsg.c b/block/bsg.c
27508index ff64ae3..593560c 100644
27509--- a/block/bsg.c
27510+++ b/block/bsg.c
27511@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27512 struct sg_io_v4 *hdr, struct bsg_device *bd,
27513 fmode_t has_write_perm)
27514 {
27515+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27516+ unsigned char *cmdptr;
27517+
27518 if (hdr->request_len > BLK_MAX_CDB) {
27519 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27520 if (!rq->cmd)
27521 return -ENOMEM;
27522- }
27523+ cmdptr = rq->cmd;
27524+ } else
27525+ cmdptr = tmpcmd;
27526
27527- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27528+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27529 hdr->request_len))
27530 return -EFAULT;
27531
27532+ if (cmdptr != rq->cmd)
27533+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27534+
27535 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27536 if (blk_verify_command(rq->cmd, has_write_perm))
27537 return -EPERM;
27538diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27539index 7c668c8..db3521c 100644
27540--- a/block/compat_ioctl.c
27541+++ b/block/compat_ioctl.c
27542@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27543 err |= __get_user(f->spec1, &uf->spec1);
27544 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27545 err |= __get_user(name, &uf->name);
27546- f->name = compat_ptr(name);
27547+ f->name = (void __force_kernel *)compat_ptr(name);
27548 if (err) {
27549 err = -EFAULT;
27550 goto out;
27551diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27552index 6296b40..417c00f 100644
27553--- a/block/partitions/efi.c
27554+++ b/block/partitions/efi.c
27555@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27556 if (!gpt)
27557 return NULL;
27558
27559+ if (!le32_to_cpu(gpt->num_partition_entries))
27560+ return NULL;
27561+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27562+ if (!pte)
27563+ return NULL;
27564+
27565 count = le32_to_cpu(gpt->num_partition_entries) *
27566 le32_to_cpu(gpt->sizeof_partition_entry);
27567- if (!count)
27568- return NULL;
27569- pte = kzalloc(count, GFP_KERNEL);
27570- if (!pte)
27571- return NULL;
27572-
27573 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27574 (u8 *) pte,
27575 count) < count) {
27576diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27577index 260fa80..e8f3caf 100644
27578--- a/block/scsi_ioctl.c
27579+++ b/block/scsi_ioctl.c
27580@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27581 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27582 struct sg_io_hdr *hdr, fmode_t mode)
27583 {
27584- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27585+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27586+ unsigned char *cmdptr;
27587+
27588+ if (rq->cmd != rq->__cmd)
27589+ cmdptr = rq->cmd;
27590+ else
27591+ cmdptr = tmpcmd;
27592+
27593+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27594 return -EFAULT;
27595+
27596+ if (cmdptr != rq->cmd)
27597+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27598+
27599 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27600 return -EPERM;
27601
27602@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27603 int err;
27604 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27605 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27606+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27607+ unsigned char *cmdptr;
27608
27609 if (!sic)
27610 return -EINVAL;
27611@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27612 */
27613 err = -EFAULT;
27614 rq->cmd_len = cmdlen;
27615- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27616+
27617+ if (rq->cmd != rq->__cmd)
27618+ cmdptr = rq->cmd;
27619+ else
27620+ cmdptr = tmpcmd;
27621+
27622+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27623 goto error;
27624
27625+ if (rq->cmd != cmdptr)
27626+ memcpy(rq->cmd, cmdptr, cmdlen);
27627+
27628 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27629 goto error;
27630
27631diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27632index 671d4d6..5f24030 100644
27633--- a/crypto/cryptd.c
27634+++ b/crypto/cryptd.c
27635@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27636
27637 struct cryptd_blkcipher_request_ctx {
27638 crypto_completion_t complete;
27639-};
27640+} __no_const;
27641
27642 struct cryptd_hash_ctx {
27643 struct crypto_shash *child;
27644@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27645
27646 struct cryptd_aead_request_ctx {
27647 crypto_completion_t complete;
27648-};
27649+} __no_const;
27650
27651 static void cryptd_queue_worker(struct work_struct *work);
27652
27653diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27654index e6defd8..c26a225 100644
27655--- a/drivers/acpi/apei/cper.c
27656+++ b/drivers/acpi/apei/cper.c
27657@@ -38,12 +38,12 @@
27658 */
27659 u64 cper_next_record_id(void)
27660 {
27661- static atomic64_t seq;
27662+ static atomic64_unchecked_t seq;
27663
27664- if (!atomic64_read(&seq))
27665- atomic64_set(&seq, ((u64)get_seconds()) << 32);
27666+ if (!atomic64_read_unchecked(&seq))
27667+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27668
27669- return atomic64_inc_return(&seq);
27670+ return atomic64_inc_return_unchecked(&seq);
27671 }
27672 EXPORT_SYMBOL_GPL(cper_next_record_id);
27673
27674diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27675index 7586544..636a2f0 100644
27676--- a/drivers/acpi/ec_sys.c
27677+++ b/drivers/acpi/ec_sys.c
27678@@ -12,6 +12,7 @@
27679 #include <linux/acpi.h>
27680 #include <linux/debugfs.h>
27681 #include <linux/module.h>
27682+#include <linux/uaccess.h>
27683 #include "internal.h"
27684
27685 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27686@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27687 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27688 */
27689 unsigned int size = EC_SPACE_SIZE;
27690- u8 *data = (u8 *) buf;
27691+ u8 data;
27692 loff_t init_off = *off;
27693 int err = 0;
27694
27695@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27696 size = count;
27697
27698 while (size) {
27699- err = ec_read(*off, &data[*off - init_off]);
27700+ err = ec_read(*off, &data);
27701 if (err)
27702 return err;
27703+ if (put_user(data, &buf[*off - init_off]))
27704+ return -EFAULT;
27705 *off += 1;
27706 size--;
27707 }
27708@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27709
27710 unsigned int size = count;
27711 loff_t init_off = *off;
27712- u8 *data = (u8 *) buf;
27713 int err = 0;
27714
27715 if (*off >= EC_SPACE_SIZE)
27716@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27717 }
27718
27719 while (size) {
27720- u8 byte_write = data[*off - init_off];
27721+ u8 byte_write;
27722+ if (get_user(byte_write, &buf[*off - init_off]))
27723+ return -EFAULT;
27724 err = ec_write(*off, byte_write);
27725 if (err)
27726 return err;
27727diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27728index 251c7b62..000462d 100644
27729--- a/drivers/acpi/proc.c
27730+++ b/drivers/acpi/proc.c
27731@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27732 size_t count, loff_t * ppos)
27733 {
27734 struct list_head *node, *next;
27735- char strbuf[5];
27736- char str[5] = "";
27737- unsigned int len = count;
27738+ char strbuf[5] = {0};
27739
27740- if (len > 4)
27741- len = 4;
27742- if (len < 0)
27743+ if (count > 4)
27744+ count = 4;
27745+ if (copy_from_user(strbuf, buffer, count))
27746 return -EFAULT;
27747-
27748- if (copy_from_user(strbuf, buffer, len))
27749- return -EFAULT;
27750- strbuf[len] = '\0';
27751- sscanf(strbuf, "%s", str);
27752+ strbuf[count] = '\0';
27753
27754 mutex_lock(&acpi_device_lock);
27755 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27756@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27757 if (!dev->wakeup.flags.valid)
27758 continue;
27759
27760- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27761+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27762 if (device_can_wakeup(&dev->dev)) {
27763 bool enable = !device_may_wakeup(&dev->dev);
27764 device_set_wakeup_enable(&dev->dev, enable);
27765diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27766index 0734086..3ad3e4c 100644
27767--- a/drivers/acpi/processor_driver.c
27768+++ b/drivers/acpi/processor_driver.c
27769@@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27770 return 0;
27771 #endif
27772
27773- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27774+ BUG_ON(pr->id >= nr_cpu_ids);
27775
27776 /*
27777 * Buggy BIOS check
27778diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27779index d31ee55..8363a8b 100644
27780--- a/drivers/ata/libata-core.c
27781+++ b/drivers/ata/libata-core.c
27782@@ -4742,7 +4742,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27783 struct ata_port *ap;
27784 unsigned int tag;
27785
27786- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27787+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27788 ap = qc->ap;
27789
27790 qc->flags = 0;
27791@@ -4758,7 +4758,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27792 struct ata_port *ap;
27793 struct ata_link *link;
27794
27795- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27796+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27797 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27798 ap = qc->ap;
27799 link = qc->dev->link;
27800@@ -5822,6 +5822,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27801 return;
27802
27803 spin_lock(&lock);
27804+ pax_open_kernel();
27805
27806 for (cur = ops->inherits; cur; cur = cur->inherits) {
27807 void **inherit = (void **)cur;
27808@@ -5835,8 +5836,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27809 if (IS_ERR(*pp))
27810 *pp = NULL;
27811
27812- ops->inherits = NULL;
27813+ *(struct ata_port_operations **)&ops->inherits = NULL;
27814
27815+ pax_close_kernel();
27816 spin_unlock(&lock);
27817 }
27818
27819diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27820index 3239517..343b5f6 100644
27821--- a/drivers/ata/pata_arasan_cf.c
27822+++ b/drivers/ata/pata_arasan_cf.c
27823@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27824 /* Handle platform specific quirks */
27825 if (pdata->quirk) {
27826 if (pdata->quirk & CF_BROKEN_PIO) {
27827- ap->ops->set_piomode = NULL;
27828+ pax_open_kernel();
27829+ *(void **)&ap->ops->set_piomode = NULL;
27830+ pax_close_kernel();
27831 ap->pio_mask = 0;
27832 }
27833 if (pdata->quirk & CF_BROKEN_MWDMA)
27834diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27835index f9b983a..887b9d8 100644
27836--- a/drivers/atm/adummy.c
27837+++ b/drivers/atm/adummy.c
27838@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27839 vcc->pop(vcc, skb);
27840 else
27841 dev_kfree_skb_any(skb);
27842- atomic_inc(&vcc->stats->tx);
27843+ atomic_inc_unchecked(&vcc->stats->tx);
27844
27845 return 0;
27846 }
27847diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27848index f8f41e0..1f987dd 100644
27849--- a/drivers/atm/ambassador.c
27850+++ b/drivers/atm/ambassador.c
27851@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27852 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27853
27854 // VC layer stats
27855- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27856+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27857
27858 // free the descriptor
27859 kfree (tx_descr);
27860@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27861 dump_skb ("<<<", vc, skb);
27862
27863 // VC layer stats
27864- atomic_inc(&atm_vcc->stats->rx);
27865+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27866 __net_timestamp(skb);
27867 // end of our responsibility
27868 atm_vcc->push (atm_vcc, skb);
27869@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27870 } else {
27871 PRINTK (KERN_INFO, "dropped over-size frame");
27872 // should we count this?
27873- atomic_inc(&atm_vcc->stats->rx_drop);
27874+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27875 }
27876
27877 } else {
27878@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27879 }
27880
27881 if (check_area (skb->data, skb->len)) {
27882- atomic_inc(&atm_vcc->stats->tx_err);
27883+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27884 return -ENOMEM; // ?
27885 }
27886
27887diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27888index b22d71c..d6e1049 100644
27889--- a/drivers/atm/atmtcp.c
27890+++ b/drivers/atm/atmtcp.c
27891@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27892 if (vcc->pop) vcc->pop(vcc,skb);
27893 else dev_kfree_skb(skb);
27894 if (dev_data) return 0;
27895- atomic_inc(&vcc->stats->tx_err);
27896+ atomic_inc_unchecked(&vcc->stats->tx_err);
27897 return -ENOLINK;
27898 }
27899 size = skb->len+sizeof(struct atmtcp_hdr);
27900@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27901 if (!new_skb) {
27902 if (vcc->pop) vcc->pop(vcc,skb);
27903 else dev_kfree_skb(skb);
27904- atomic_inc(&vcc->stats->tx_err);
27905+ atomic_inc_unchecked(&vcc->stats->tx_err);
27906 return -ENOBUFS;
27907 }
27908 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27909@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27910 if (vcc->pop) vcc->pop(vcc,skb);
27911 else dev_kfree_skb(skb);
27912 out_vcc->push(out_vcc,new_skb);
27913- atomic_inc(&vcc->stats->tx);
27914- atomic_inc(&out_vcc->stats->rx);
27915+ atomic_inc_unchecked(&vcc->stats->tx);
27916+ atomic_inc_unchecked(&out_vcc->stats->rx);
27917 return 0;
27918 }
27919
27920@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27921 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27922 read_unlock(&vcc_sklist_lock);
27923 if (!out_vcc) {
27924- atomic_inc(&vcc->stats->tx_err);
27925+ atomic_inc_unchecked(&vcc->stats->tx_err);
27926 goto done;
27927 }
27928 skb_pull(skb,sizeof(struct atmtcp_hdr));
27929@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27930 __net_timestamp(new_skb);
27931 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27932 out_vcc->push(out_vcc,new_skb);
27933- atomic_inc(&vcc->stats->tx);
27934- atomic_inc(&out_vcc->stats->rx);
27935+ atomic_inc_unchecked(&vcc->stats->tx);
27936+ atomic_inc_unchecked(&out_vcc->stats->rx);
27937 done:
27938 if (vcc->pop) vcc->pop(vcc,skb);
27939 else dev_kfree_skb(skb);
27940diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27941index 2059ee4..faf51c7 100644
27942--- a/drivers/atm/eni.c
27943+++ b/drivers/atm/eni.c
27944@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27945 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27946 vcc->dev->number);
27947 length = 0;
27948- atomic_inc(&vcc->stats->rx_err);
27949+ atomic_inc_unchecked(&vcc->stats->rx_err);
27950 }
27951 else {
27952 length = ATM_CELL_SIZE-1; /* no HEC */
27953@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27954 size);
27955 }
27956 eff = length = 0;
27957- atomic_inc(&vcc->stats->rx_err);
27958+ atomic_inc_unchecked(&vcc->stats->rx_err);
27959 }
27960 else {
27961 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27962@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27963 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27964 vcc->dev->number,vcc->vci,length,size << 2,descr);
27965 length = eff = 0;
27966- atomic_inc(&vcc->stats->rx_err);
27967+ atomic_inc_unchecked(&vcc->stats->rx_err);
27968 }
27969 }
27970 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27971@@ -767,7 +767,7 @@ rx_dequeued++;
27972 vcc->push(vcc,skb);
27973 pushed++;
27974 }
27975- atomic_inc(&vcc->stats->rx);
27976+ atomic_inc_unchecked(&vcc->stats->rx);
27977 }
27978 wake_up(&eni_dev->rx_wait);
27979 }
27980@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27981 PCI_DMA_TODEVICE);
27982 if (vcc->pop) vcc->pop(vcc,skb);
27983 else dev_kfree_skb_irq(skb);
27984- atomic_inc(&vcc->stats->tx);
27985+ atomic_inc_unchecked(&vcc->stats->tx);
27986 wake_up(&eni_dev->tx_wait);
27987 dma_complete++;
27988 }
27989@@ -1567,7 +1567,7 @@ tx_complete++;
27990 /*--------------------------------- entries ---------------------------------*/
27991
27992
27993-static const char *media_name[] __devinitdata = {
27994+static const char *media_name[] __devinitconst = {
27995 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27996 "UTP", "05?", "06?", "07?", /* 4- 7 */
27997 "TAXI","09?", "10?", "11?", /* 8-11 */
27998diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27999index 86fed1b..6dc4721 100644
28000--- a/drivers/atm/firestream.c
28001+++ b/drivers/atm/firestream.c
28002@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28003 }
28004 }
28005
28006- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28007+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28008
28009 fs_dprintk (FS_DEBUG_TXMEM, "i");
28010 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28011@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28012 #endif
28013 skb_put (skb, qe->p1 & 0xffff);
28014 ATM_SKB(skb)->vcc = atm_vcc;
28015- atomic_inc(&atm_vcc->stats->rx);
28016+ atomic_inc_unchecked(&atm_vcc->stats->rx);
28017 __net_timestamp(skb);
28018 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28019 atm_vcc->push (atm_vcc, skb);
28020@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28021 kfree (pe);
28022 }
28023 if (atm_vcc)
28024- atomic_inc(&atm_vcc->stats->rx_drop);
28025+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28026 break;
28027 case 0x1f: /* Reassembly abort: no buffers. */
28028 /* Silently increment error counter. */
28029 if (atm_vcc)
28030- atomic_inc(&atm_vcc->stats->rx_drop);
28031+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28032 break;
28033 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28034 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28035diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28036index 361f5ae..7fc552d 100644
28037--- a/drivers/atm/fore200e.c
28038+++ b/drivers/atm/fore200e.c
28039@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28040 #endif
28041 /* check error condition */
28042 if (*entry->status & STATUS_ERROR)
28043- atomic_inc(&vcc->stats->tx_err);
28044+ atomic_inc_unchecked(&vcc->stats->tx_err);
28045 else
28046- atomic_inc(&vcc->stats->tx);
28047+ atomic_inc_unchecked(&vcc->stats->tx);
28048 }
28049 }
28050
28051@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28052 if (skb == NULL) {
28053 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28054
28055- atomic_inc(&vcc->stats->rx_drop);
28056+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28057 return -ENOMEM;
28058 }
28059
28060@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28061
28062 dev_kfree_skb_any(skb);
28063
28064- atomic_inc(&vcc->stats->rx_drop);
28065+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28066 return -ENOMEM;
28067 }
28068
28069 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28070
28071 vcc->push(vcc, skb);
28072- atomic_inc(&vcc->stats->rx);
28073+ atomic_inc_unchecked(&vcc->stats->rx);
28074
28075 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28076
28077@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28078 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28079 fore200e->atm_dev->number,
28080 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28081- atomic_inc(&vcc->stats->rx_err);
28082+ atomic_inc_unchecked(&vcc->stats->rx_err);
28083 }
28084 }
28085
28086@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28087 goto retry_here;
28088 }
28089
28090- atomic_inc(&vcc->stats->tx_err);
28091+ atomic_inc_unchecked(&vcc->stats->tx_err);
28092
28093 fore200e->tx_sat++;
28094 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28095diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28096index b182c2f..1c6fa8a 100644
28097--- a/drivers/atm/he.c
28098+++ b/drivers/atm/he.c
28099@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28100
28101 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28102 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28103- atomic_inc(&vcc->stats->rx_drop);
28104+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28105 goto return_host_buffers;
28106 }
28107
28108@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28109 RBRQ_LEN_ERR(he_dev->rbrq_head)
28110 ? "LEN_ERR" : "",
28111 vcc->vpi, vcc->vci);
28112- atomic_inc(&vcc->stats->rx_err);
28113+ atomic_inc_unchecked(&vcc->stats->rx_err);
28114 goto return_host_buffers;
28115 }
28116
28117@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28118 vcc->push(vcc, skb);
28119 spin_lock(&he_dev->global_lock);
28120
28121- atomic_inc(&vcc->stats->rx);
28122+ atomic_inc_unchecked(&vcc->stats->rx);
28123
28124 return_host_buffers:
28125 ++pdus_assembled;
28126@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28127 tpd->vcc->pop(tpd->vcc, tpd->skb);
28128 else
28129 dev_kfree_skb_any(tpd->skb);
28130- atomic_inc(&tpd->vcc->stats->tx_err);
28131+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28132 }
28133 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28134 return;
28135@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28136 vcc->pop(vcc, skb);
28137 else
28138 dev_kfree_skb_any(skb);
28139- atomic_inc(&vcc->stats->tx_err);
28140+ atomic_inc_unchecked(&vcc->stats->tx_err);
28141 return -EINVAL;
28142 }
28143
28144@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28145 vcc->pop(vcc, skb);
28146 else
28147 dev_kfree_skb_any(skb);
28148- atomic_inc(&vcc->stats->tx_err);
28149+ atomic_inc_unchecked(&vcc->stats->tx_err);
28150 return -EINVAL;
28151 }
28152 #endif
28153@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28154 vcc->pop(vcc, skb);
28155 else
28156 dev_kfree_skb_any(skb);
28157- atomic_inc(&vcc->stats->tx_err);
28158+ atomic_inc_unchecked(&vcc->stats->tx_err);
28159 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28160 return -ENOMEM;
28161 }
28162@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28163 vcc->pop(vcc, skb);
28164 else
28165 dev_kfree_skb_any(skb);
28166- atomic_inc(&vcc->stats->tx_err);
28167+ atomic_inc_unchecked(&vcc->stats->tx_err);
28168 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28169 return -ENOMEM;
28170 }
28171@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28172 __enqueue_tpd(he_dev, tpd, cid);
28173 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28174
28175- atomic_inc(&vcc->stats->tx);
28176+ atomic_inc_unchecked(&vcc->stats->tx);
28177
28178 return 0;
28179 }
28180diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28181index 75fd691..2d20b14 100644
28182--- a/drivers/atm/horizon.c
28183+++ b/drivers/atm/horizon.c
28184@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28185 {
28186 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28187 // VC layer stats
28188- atomic_inc(&vcc->stats->rx);
28189+ atomic_inc_unchecked(&vcc->stats->rx);
28190 __net_timestamp(skb);
28191 // end of our responsibility
28192 vcc->push (vcc, skb);
28193@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28194 dev->tx_iovec = NULL;
28195
28196 // VC layer stats
28197- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28198+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28199
28200 // free the skb
28201 hrz_kfree_skb (skb);
28202diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28203index 1c05212..c28e200 100644
28204--- a/drivers/atm/idt77252.c
28205+++ b/drivers/atm/idt77252.c
28206@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28207 else
28208 dev_kfree_skb(skb);
28209
28210- atomic_inc(&vcc->stats->tx);
28211+ atomic_inc_unchecked(&vcc->stats->tx);
28212 }
28213
28214 atomic_dec(&scq->used);
28215@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28216 if ((sb = dev_alloc_skb(64)) == NULL) {
28217 printk("%s: Can't allocate buffers for aal0.\n",
28218 card->name);
28219- atomic_add(i, &vcc->stats->rx_drop);
28220+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28221 break;
28222 }
28223 if (!atm_charge(vcc, sb->truesize)) {
28224 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28225 card->name);
28226- atomic_add(i - 1, &vcc->stats->rx_drop);
28227+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28228 dev_kfree_skb(sb);
28229 break;
28230 }
28231@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28232 ATM_SKB(sb)->vcc = vcc;
28233 __net_timestamp(sb);
28234 vcc->push(vcc, sb);
28235- atomic_inc(&vcc->stats->rx);
28236+ atomic_inc_unchecked(&vcc->stats->rx);
28237
28238 cell += ATM_CELL_PAYLOAD;
28239 }
28240@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28241 "(CDC: %08x)\n",
28242 card->name, len, rpp->len, readl(SAR_REG_CDC));
28243 recycle_rx_pool_skb(card, rpp);
28244- atomic_inc(&vcc->stats->rx_err);
28245+ atomic_inc_unchecked(&vcc->stats->rx_err);
28246 return;
28247 }
28248 if (stat & SAR_RSQE_CRC) {
28249 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28250 recycle_rx_pool_skb(card, rpp);
28251- atomic_inc(&vcc->stats->rx_err);
28252+ atomic_inc_unchecked(&vcc->stats->rx_err);
28253 return;
28254 }
28255 if (skb_queue_len(&rpp->queue) > 1) {
28256@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28257 RXPRINTK("%s: Can't alloc RX skb.\n",
28258 card->name);
28259 recycle_rx_pool_skb(card, rpp);
28260- atomic_inc(&vcc->stats->rx_err);
28261+ atomic_inc_unchecked(&vcc->stats->rx_err);
28262 return;
28263 }
28264 if (!atm_charge(vcc, skb->truesize)) {
28265@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28266 __net_timestamp(skb);
28267
28268 vcc->push(vcc, skb);
28269- atomic_inc(&vcc->stats->rx);
28270+ atomic_inc_unchecked(&vcc->stats->rx);
28271
28272 return;
28273 }
28274@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28275 __net_timestamp(skb);
28276
28277 vcc->push(vcc, skb);
28278- atomic_inc(&vcc->stats->rx);
28279+ atomic_inc_unchecked(&vcc->stats->rx);
28280
28281 if (skb->truesize > SAR_FB_SIZE_3)
28282 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28283@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28284 if (vcc->qos.aal != ATM_AAL0) {
28285 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28286 card->name, vpi, vci);
28287- atomic_inc(&vcc->stats->rx_drop);
28288+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28289 goto drop;
28290 }
28291
28292 if ((sb = dev_alloc_skb(64)) == NULL) {
28293 printk("%s: Can't allocate buffers for AAL0.\n",
28294 card->name);
28295- atomic_inc(&vcc->stats->rx_err);
28296+ atomic_inc_unchecked(&vcc->stats->rx_err);
28297 goto drop;
28298 }
28299
28300@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28301 ATM_SKB(sb)->vcc = vcc;
28302 __net_timestamp(sb);
28303 vcc->push(vcc, sb);
28304- atomic_inc(&vcc->stats->rx);
28305+ atomic_inc_unchecked(&vcc->stats->rx);
28306
28307 drop:
28308 skb_pull(queue, 64);
28309@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28310
28311 if (vc == NULL) {
28312 printk("%s: NULL connection in send().\n", card->name);
28313- atomic_inc(&vcc->stats->tx_err);
28314+ atomic_inc_unchecked(&vcc->stats->tx_err);
28315 dev_kfree_skb(skb);
28316 return -EINVAL;
28317 }
28318 if (!test_bit(VCF_TX, &vc->flags)) {
28319 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28320- atomic_inc(&vcc->stats->tx_err);
28321+ atomic_inc_unchecked(&vcc->stats->tx_err);
28322 dev_kfree_skb(skb);
28323 return -EINVAL;
28324 }
28325@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28326 break;
28327 default:
28328 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28329- atomic_inc(&vcc->stats->tx_err);
28330+ atomic_inc_unchecked(&vcc->stats->tx_err);
28331 dev_kfree_skb(skb);
28332 return -EINVAL;
28333 }
28334
28335 if (skb_shinfo(skb)->nr_frags != 0) {
28336 printk("%s: No scatter-gather yet.\n", card->name);
28337- atomic_inc(&vcc->stats->tx_err);
28338+ atomic_inc_unchecked(&vcc->stats->tx_err);
28339 dev_kfree_skb(skb);
28340 return -EINVAL;
28341 }
28342@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28343
28344 err = queue_skb(card, vc, skb, oam);
28345 if (err) {
28346- atomic_inc(&vcc->stats->tx_err);
28347+ atomic_inc_unchecked(&vcc->stats->tx_err);
28348 dev_kfree_skb(skb);
28349 return err;
28350 }
28351@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28352 skb = dev_alloc_skb(64);
28353 if (!skb) {
28354 printk("%s: Out of memory in send_oam().\n", card->name);
28355- atomic_inc(&vcc->stats->tx_err);
28356+ atomic_inc_unchecked(&vcc->stats->tx_err);
28357 return -ENOMEM;
28358 }
28359 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28360diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28361index d438601..8b98495 100644
28362--- a/drivers/atm/iphase.c
28363+++ b/drivers/atm/iphase.c
28364@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28365 status = (u_short) (buf_desc_ptr->desc_mode);
28366 if (status & (RX_CER | RX_PTE | RX_OFL))
28367 {
28368- atomic_inc(&vcc->stats->rx_err);
28369+ atomic_inc_unchecked(&vcc->stats->rx_err);
28370 IF_ERR(printk("IA: bad packet, dropping it");)
28371 if (status & RX_CER) {
28372 IF_ERR(printk(" cause: packet CRC error\n");)
28373@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28374 len = dma_addr - buf_addr;
28375 if (len > iadev->rx_buf_sz) {
28376 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28377- atomic_inc(&vcc->stats->rx_err);
28378+ atomic_inc_unchecked(&vcc->stats->rx_err);
28379 goto out_free_desc;
28380 }
28381
28382@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28383 ia_vcc = INPH_IA_VCC(vcc);
28384 if (ia_vcc == NULL)
28385 {
28386- atomic_inc(&vcc->stats->rx_err);
28387+ atomic_inc_unchecked(&vcc->stats->rx_err);
28388 atm_return(vcc, skb->truesize);
28389 dev_kfree_skb_any(skb);
28390 goto INCR_DLE;
28391@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28392 if ((length > iadev->rx_buf_sz) || (length >
28393 (skb->len - sizeof(struct cpcs_trailer))))
28394 {
28395- atomic_inc(&vcc->stats->rx_err);
28396+ atomic_inc_unchecked(&vcc->stats->rx_err);
28397 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28398 length, skb->len);)
28399 atm_return(vcc, skb->truesize);
28400@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28401
28402 IF_RX(printk("rx_dle_intr: skb push");)
28403 vcc->push(vcc,skb);
28404- atomic_inc(&vcc->stats->rx);
28405+ atomic_inc_unchecked(&vcc->stats->rx);
28406 iadev->rx_pkt_cnt++;
28407 }
28408 INCR_DLE:
28409@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28410 {
28411 struct k_sonet_stats *stats;
28412 stats = &PRIV(_ia_dev[board])->sonet_stats;
28413- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28414- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28415- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28416- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28417- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28418- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28419- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28420- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28421- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28422+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28423+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28424+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28425+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28426+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28427+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28428+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28429+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28430+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28431 }
28432 ia_cmds.status = 0;
28433 break;
28434@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28435 if ((desc == 0) || (desc > iadev->num_tx_desc))
28436 {
28437 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28438- atomic_inc(&vcc->stats->tx);
28439+ atomic_inc_unchecked(&vcc->stats->tx);
28440 if (vcc->pop)
28441 vcc->pop(vcc, skb);
28442 else
28443@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28444 ATM_DESC(skb) = vcc->vci;
28445 skb_queue_tail(&iadev->tx_dma_q, skb);
28446
28447- atomic_inc(&vcc->stats->tx);
28448+ atomic_inc_unchecked(&vcc->stats->tx);
28449 iadev->tx_pkt_cnt++;
28450 /* Increment transaction counter */
28451 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28452
28453 #if 0
28454 /* add flow control logic */
28455- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28456+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28457 if (iavcc->vc_desc_cnt > 10) {
28458 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28459 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28460diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28461index 68c7588..7036683 100644
28462--- a/drivers/atm/lanai.c
28463+++ b/drivers/atm/lanai.c
28464@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28465 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28466 lanai_endtx(lanai, lvcc);
28467 lanai_free_skb(lvcc->tx.atmvcc, skb);
28468- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28469+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28470 }
28471
28472 /* Try to fill the buffer - don't call unless there is backlog */
28473@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28474 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28475 __net_timestamp(skb);
28476 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28477- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28478+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28479 out:
28480 lvcc->rx.buf.ptr = end;
28481 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28482@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28483 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28484 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28485 lanai->stats.service_rxnotaal5++;
28486- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28487+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28488 return 0;
28489 }
28490 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28491@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28492 int bytes;
28493 read_unlock(&vcc_sklist_lock);
28494 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28495- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28496+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28497 lvcc->stats.x.aal5.service_trash++;
28498 bytes = (SERVICE_GET_END(s) * 16) -
28499 (((unsigned long) lvcc->rx.buf.ptr) -
28500@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28501 }
28502 if (s & SERVICE_STREAM) {
28503 read_unlock(&vcc_sklist_lock);
28504- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28505+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28506 lvcc->stats.x.aal5.service_stream++;
28507 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28508 "PDU on VCI %d!\n", lanai->number, vci);
28509@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28510 return 0;
28511 }
28512 DPRINTK("got rx crc error on vci %d\n", vci);
28513- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28514+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28515 lvcc->stats.x.aal5.service_rxcrc++;
28516 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28517 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28518diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28519index 1c70c45..300718d 100644
28520--- a/drivers/atm/nicstar.c
28521+++ b/drivers/atm/nicstar.c
28522@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28523 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28524 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28525 card->index);
28526- atomic_inc(&vcc->stats->tx_err);
28527+ atomic_inc_unchecked(&vcc->stats->tx_err);
28528 dev_kfree_skb_any(skb);
28529 return -EINVAL;
28530 }
28531@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28532 if (!vc->tx) {
28533 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28534 card->index);
28535- atomic_inc(&vcc->stats->tx_err);
28536+ atomic_inc_unchecked(&vcc->stats->tx_err);
28537 dev_kfree_skb_any(skb);
28538 return -EINVAL;
28539 }
28540@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28541 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28542 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28543 card->index);
28544- atomic_inc(&vcc->stats->tx_err);
28545+ atomic_inc_unchecked(&vcc->stats->tx_err);
28546 dev_kfree_skb_any(skb);
28547 return -EINVAL;
28548 }
28549
28550 if (skb_shinfo(skb)->nr_frags != 0) {
28551 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28552- atomic_inc(&vcc->stats->tx_err);
28553+ atomic_inc_unchecked(&vcc->stats->tx_err);
28554 dev_kfree_skb_any(skb);
28555 return -EINVAL;
28556 }
28557@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28558 }
28559
28560 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28561- atomic_inc(&vcc->stats->tx_err);
28562+ atomic_inc_unchecked(&vcc->stats->tx_err);
28563 dev_kfree_skb_any(skb);
28564 return -EIO;
28565 }
28566- atomic_inc(&vcc->stats->tx);
28567+ atomic_inc_unchecked(&vcc->stats->tx);
28568
28569 return 0;
28570 }
28571@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28572 printk
28573 ("nicstar%d: Can't allocate buffers for aal0.\n",
28574 card->index);
28575- atomic_add(i, &vcc->stats->rx_drop);
28576+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28577 break;
28578 }
28579 if (!atm_charge(vcc, sb->truesize)) {
28580 RXPRINTK
28581 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28582 card->index);
28583- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28584+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28585 dev_kfree_skb_any(sb);
28586 break;
28587 }
28588@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28589 ATM_SKB(sb)->vcc = vcc;
28590 __net_timestamp(sb);
28591 vcc->push(vcc, sb);
28592- atomic_inc(&vcc->stats->rx);
28593+ atomic_inc_unchecked(&vcc->stats->rx);
28594 cell += ATM_CELL_PAYLOAD;
28595 }
28596
28597@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28598 if (iovb == NULL) {
28599 printk("nicstar%d: Out of iovec buffers.\n",
28600 card->index);
28601- atomic_inc(&vcc->stats->rx_drop);
28602+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28603 recycle_rx_buf(card, skb);
28604 return;
28605 }
28606@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28607 small or large buffer itself. */
28608 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28609 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28610- atomic_inc(&vcc->stats->rx_err);
28611+ atomic_inc_unchecked(&vcc->stats->rx_err);
28612 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28613 NS_MAX_IOVECS);
28614 NS_PRV_IOVCNT(iovb) = 0;
28615@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28616 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28617 card->index);
28618 which_list(card, skb);
28619- atomic_inc(&vcc->stats->rx_err);
28620+ atomic_inc_unchecked(&vcc->stats->rx_err);
28621 recycle_rx_buf(card, skb);
28622 vc->rx_iov = NULL;
28623 recycle_iov_buf(card, iovb);
28624@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28625 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28626 card->index);
28627 which_list(card, skb);
28628- atomic_inc(&vcc->stats->rx_err);
28629+ atomic_inc_unchecked(&vcc->stats->rx_err);
28630 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28631 NS_PRV_IOVCNT(iovb));
28632 vc->rx_iov = NULL;
28633@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28634 printk(" - PDU size mismatch.\n");
28635 else
28636 printk(".\n");
28637- atomic_inc(&vcc->stats->rx_err);
28638+ atomic_inc_unchecked(&vcc->stats->rx_err);
28639 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28640 NS_PRV_IOVCNT(iovb));
28641 vc->rx_iov = NULL;
28642@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28643 /* skb points to a small buffer */
28644 if (!atm_charge(vcc, skb->truesize)) {
28645 push_rxbufs(card, skb);
28646- atomic_inc(&vcc->stats->rx_drop);
28647+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28648 } else {
28649 skb_put(skb, len);
28650 dequeue_sm_buf(card, skb);
28651@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28652 ATM_SKB(skb)->vcc = vcc;
28653 __net_timestamp(skb);
28654 vcc->push(vcc, skb);
28655- atomic_inc(&vcc->stats->rx);
28656+ atomic_inc_unchecked(&vcc->stats->rx);
28657 }
28658 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28659 struct sk_buff *sb;
28660@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28661 if (len <= NS_SMBUFSIZE) {
28662 if (!atm_charge(vcc, sb->truesize)) {
28663 push_rxbufs(card, sb);
28664- atomic_inc(&vcc->stats->rx_drop);
28665+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28666 } else {
28667 skb_put(sb, len);
28668 dequeue_sm_buf(card, sb);
28669@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28670 ATM_SKB(sb)->vcc = vcc;
28671 __net_timestamp(sb);
28672 vcc->push(vcc, sb);
28673- atomic_inc(&vcc->stats->rx);
28674+ atomic_inc_unchecked(&vcc->stats->rx);
28675 }
28676
28677 push_rxbufs(card, skb);
28678@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28679
28680 if (!atm_charge(vcc, skb->truesize)) {
28681 push_rxbufs(card, skb);
28682- atomic_inc(&vcc->stats->rx_drop);
28683+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28684 } else {
28685 dequeue_lg_buf(card, skb);
28686 #ifdef NS_USE_DESTRUCTORS
28687@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28688 ATM_SKB(skb)->vcc = vcc;
28689 __net_timestamp(skb);
28690 vcc->push(vcc, skb);
28691- atomic_inc(&vcc->stats->rx);
28692+ atomic_inc_unchecked(&vcc->stats->rx);
28693 }
28694
28695 push_rxbufs(card, sb);
28696@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28697 printk
28698 ("nicstar%d: Out of huge buffers.\n",
28699 card->index);
28700- atomic_inc(&vcc->stats->rx_drop);
28701+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28702 recycle_iovec_rx_bufs(card,
28703 (struct iovec *)
28704 iovb->data,
28705@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28706 card->hbpool.count++;
28707 } else
28708 dev_kfree_skb_any(hb);
28709- atomic_inc(&vcc->stats->rx_drop);
28710+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28711 } else {
28712 /* Copy the small buffer to the huge buffer */
28713 sb = (struct sk_buff *)iov->iov_base;
28714@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28715 #endif /* NS_USE_DESTRUCTORS */
28716 __net_timestamp(hb);
28717 vcc->push(vcc, hb);
28718- atomic_inc(&vcc->stats->rx);
28719+ atomic_inc_unchecked(&vcc->stats->rx);
28720 }
28721 }
28722
28723diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28724index 9851093..adb2b1e 100644
28725--- a/drivers/atm/solos-pci.c
28726+++ b/drivers/atm/solos-pci.c
28727@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28728 }
28729 atm_charge(vcc, skb->truesize);
28730 vcc->push(vcc, skb);
28731- atomic_inc(&vcc->stats->rx);
28732+ atomic_inc_unchecked(&vcc->stats->rx);
28733 break;
28734
28735 case PKT_STATUS:
28736@@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28737 vcc = SKB_CB(oldskb)->vcc;
28738
28739 if (vcc) {
28740- atomic_inc(&vcc->stats->tx);
28741+ atomic_inc_unchecked(&vcc->stats->tx);
28742 solos_pop(vcc, oldskb);
28743 } else
28744 dev_kfree_skb_irq(oldskb);
28745diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28746index 0215934..ce9f5b1 100644
28747--- a/drivers/atm/suni.c
28748+++ b/drivers/atm/suni.c
28749@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28750
28751
28752 #define ADD_LIMITED(s,v) \
28753- atomic_add((v),&stats->s); \
28754- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28755+ atomic_add_unchecked((v),&stats->s); \
28756+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28757
28758
28759 static void suni_hz(unsigned long from_timer)
28760diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28761index 5120a96..e2572bd 100644
28762--- a/drivers/atm/uPD98402.c
28763+++ b/drivers/atm/uPD98402.c
28764@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28765 struct sonet_stats tmp;
28766 int error = 0;
28767
28768- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28769+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28770 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28771 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28772 if (zero && !error) {
28773@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28774
28775
28776 #define ADD_LIMITED(s,v) \
28777- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28778- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28779- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28780+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28781+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28782+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28783
28784
28785 static void stat_event(struct atm_dev *dev)
28786@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28787 if (reason & uPD98402_INT_PFM) stat_event(dev);
28788 if (reason & uPD98402_INT_PCO) {
28789 (void) GET(PCOCR); /* clear interrupt cause */
28790- atomic_add(GET(HECCT),
28791+ atomic_add_unchecked(GET(HECCT),
28792 &PRIV(dev)->sonet_stats.uncorr_hcs);
28793 }
28794 if ((reason & uPD98402_INT_RFO) &&
28795@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28796 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28797 uPD98402_INT_LOS),PIMR); /* enable them */
28798 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28799- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28800- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28801- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28802+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28803+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28804+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28805 return 0;
28806 }
28807
28808diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28809index abe4e20..83c4727 100644
28810--- a/drivers/atm/zatm.c
28811+++ b/drivers/atm/zatm.c
28812@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28813 }
28814 if (!size) {
28815 dev_kfree_skb_irq(skb);
28816- if (vcc) atomic_inc(&vcc->stats->rx_err);
28817+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28818 continue;
28819 }
28820 if (!atm_charge(vcc,skb->truesize)) {
28821@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28822 skb->len = size;
28823 ATM_SKB(skb)->vcc = vcc;
28824 vcc->push(vcc,skb);
28825- atomic_inc(&vcc->stats->rx);
28826+ atomic_inc_unchecked(&vcc->stats->rx);
28827 }
28828 zout(pos & 0xffff,MTA(mbx));
28829 #if 0 /* probably a stupid idea */
28830@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28831 skb_queue_head(&zatm_vcc->backlog,skb);
28832 break;
28833 }
28834- atomic_inc(&vcc->stats->tx);
28835+ atomic_inc_unchecked(&vcc->stats->tx);
28836 wake_up(&zatm_vcc->tx_wait);
28837 }
28838
28839diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28840index 8493536..31adee0 100644
28841--- a/drivers/base/devtmpfs.c
28842+++ b/drivers/base/devtmpfs.c
28843@@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28844 if (!thread)
28845 return 0;
28846
28847- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28848+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28849 if (err)
28850 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28851 else
28852diff --git a/drivers/base/node.c b/drivers/base/node.c
28853index 90aa2a1..af1a177 100644
28854--- a/drivers/base/node.c
28855+++ b/drivers/base/node.c
28856@@ -592,11 +592,9 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
28857 {
28858 int n;
28859
28860- n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
28861- if (n > 0 && PAGE_SIZE > n + 1) {
28862- *(buf + n++) = '\n';
28863- *(buf + n++) = '\0';
28864- }
28865+ n = nodelist_scnprintf(buf, PAGE_SIZE-2, node_states[state]);
28866+ buf[n++] = '\n';
28867+ buf[n] = '\0';
28868 return n;
28869 }
28870
28871diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28872index 2a3e581..3d6a73f 100644
28873--- a/drivers/base/power/wakeup.c
28874+++ b/drivers/base/power/wakeup.c
28875@@ -30,14 +30,14 @@ bool events_check_enabled;
28876 * They need to be modified together atomically, so it's better to use one
28877 * atomic variable to hold them both.
28878 */
28879-static atomic_t combined_event_count = ATOMIC_INIT(0);
28880+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28881
28882 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28883 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28884
28885 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28886 {
28887- unsigned int comb = atomic_read(&combined_event_count);
28888+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
28889
28890 *cnt = (comb >> IN_PROGRESS_BITS);
28891 *inpr = comb & MAX_IN_PROGRESS;
28892@@ -379,7 +379,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28893 ws->last_time = ktime_get();
28894
28895 /* Increment the counter of events in progress. */
28896- atomic_inc(&combined_event_count);
28897+ atomic_inc_unchecked(&combined_event_count);
28898 }
28899
28900 /**
28901@@ -475,7 +475,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28902 * Increment the counter of registered wakeup events and decrement the
28903 * couter of wakeup events in progress simultaneously.
28904 */
28905- atomic_add(MAX_IN_PROGRESS, &combined_event_count);
28906+ atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28907 }
28908
28909 /**
28910diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28911index b0f553b..77b928b 100644
28912--- a/drivers/block/cciss.c
28913+++ b/drivers/block/cciss.c
28914@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28915 int err;
28916 u32 cp;
28917
28918+ memset(&arg64, 0, sizeof(arg64));
28919+
28920 err = 0;
28921 err |=
28922 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28923@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28924 while (!list_empty(&h->reqQ)) {
28925 c = list_entry(h->reqQ.next, CommandList_struct, list);
28926 /* can't do anything if fifo is full */
28927- if ((h->access.fifo_full(h))) {
28928+ if ((h->access->fifo_full(h))) {
28929 dev_warn(&h->pdev->dev, "fifo full\n");
28930 break;
28931 }
28932@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28933 h->Qdepth--;
28934
28935 /* Tell the controller execute command */
28936- h->access.submit_command(h, c);
28937+ h->access->submit_command(h, c);
28938
28939 /* Put job onto the completed Q */
28940 addQ(&h->cmpQ, c);
28941@@ -3443,17 +3445,17 @@ startio:
28942
28943 static inline unsigned long get_next_completion(ctlr_info_t *h)
28944 {
28945- return h->access.command_completed(h);
28946+ return h->access->command_completed(h);
28947 }
28948
28949 static inline int interrupt_pending(ctlr_info_t *h)
28950 {
28951- return h->access.intr_pending(h);
28952+ return h->access->intr_pending(h);
28953 }
28954
28955 static inline long interrupt_not_for_us(ctlr_info_t *h)
28956 {
28957- return ((h->access.intr_pending(h) == 0) ||
28958+ return ((h->access->intr_pending(h) == 0) ||
28959 (h->interrupts_enabled == 0));
28960 }
28961
28962@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28963 u32 a;
28964
28965 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28966- return h->access.command_completed(h);
28967+ return h->access->command_completed(h);
28968
28969 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28970 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28971@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28972 trans_support & CFGTBL_Trans_use_short_tags);
28973
28974 /* Change the access methods to the performant access methods */
28975- h->access = SA5_performant_access;
28976+ h->access = &SA5_performant_access;
28977 h->transMethod = CFGTBL_Trans_Performant;
28978
28979 return;
28980@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28981 if (prod_index < 0)
28982 return -ENODEV;
28983 h->product_name = products[prod_index].product_name;
28984- h->access = *(products[prod_index].access);
28985+ h->access = products[prod_index].access;
28986
28987 if (cciss_board_disabled(h)) {
28988 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28989@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28990 }
28991
28992 /* make sure the board interrupts are off */
28993- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28994+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28995 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28996 if (rc)
28997 goto clean2;
28998@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28999 * fake ones to scoop up any residual completions.
29000 */
29001 spin_lock_irqsave(&h->lock, flags);
29002- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29003+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29004 spin_unlock_irqrestore(&h->lock, flags);
29005 free_irq(h->intr[h->intr_mode], h);
29006 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29007@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29008 dev_info(&h->pdev->dev, "Board READY.\n");
29009 dev_info(&h->pdev->dev,
29010 "Waiting for stale completions to drain.\n");
29011- h->access.set_intr_mask(h, CCISS_INTR_ON);
29012+ h->access->set_intr_mask(h, CCISS_INTR_ON);
29013 msleep(10000);
29014- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29015+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29016
29017 rc = controller_reset_failed(h->cfgtable);
29018 if (rc)
29019@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29020 cciss_scsi_setup(h);
29021
29022 /* Turn the interrupts on so we can service requests */
29023- h->access.set_intr_mask(h, CCISS_INTR_ON);
29024+ h->access->set_intr_mask(h, CCISS_INTR_ON);
29025
29026 /* Get the firmware version */
29027 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29028@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29029 kfree(flush_buf);
29030 if (return_code != IO_OK)
29031 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29032- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29033+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29034 free_irq(h->intr[h->intr_mode], h);
29035 }
29036
29037diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29038index 7fda30e..eb5dfe0 100644
29039--- a/drivers/block/cciss.h
29040+++ b/drivers/block/cciss.h
29041@@ -101,7 +101,7 @@ struct ctlr_info
29042 /* information about each logical volume */
29043 drive_info_struct *drv[CISS_MAX_LUN];
29044
29045- struct access_method access;
29046+ struct access_method *access;
29047
29048 /* queue and queue Info */
29049 struct list_head reqQ;
29050diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29051index 9125bbe..eede5c8 100644
29052--- a/drivers/block/cpqarray.c
29053+++ b/drivers/block/cpqarray.c
29054@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29055 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29056 goto Enomem4;
29057 }
29058- hba[i]->access.set_intr_mask(hba[i], 0);
29059+ hba[i]->access->set_intr_mask(hba[i], 0);
29060 if (request_irq(hba[i]->intr, do_ida_intr,
29061 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29062 {
29063@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29064 add_timer(&hba[i]->timer);
29065
29066 /* Enable IRQ now that spinlock and rate limit timer are set up */
29067- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29068+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29069
29070 for(j=0; j<NWD; j++) {
29071 struct gendisk *disk = ida_gendisk[i][j];
29072@@ -694,7 +694,7 @@ DBGINFO(
29073 for(i=0; i<NR_PRODUCTS; i++) {
29074 if (board_id == products[i].board_id) {
29075 c->product_name = products[i].product_name;
29076- c->access = *(products[i].access);
29077+ c->access = products[i].access;
29078 break;
29079 }
29080 }
29081@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29082 hba[ctlr]->intr = intr;
29083 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29084 hba[ctlr]->product_name = products[j].product_name;
29085- hba[ctlr]->access = *(products[j].access);
29086+ hba[ctlr]->access = products[j].access;
29087 hba[ctlr]->ctlr = ctlr;
29088 hba[ctlr]->board_id = board_id;
29089 hba[ctlr]->pci_dev = NULL; /* not PCI */
29090@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29091
29092 while((c = h->reqQ) != NULL) {
29093 /* Can't do anything if we're busy */
29094- if (h->access.fifo_full(h) == 0)
29095+ if (h->access->fifo_full(h) == 0)
29096 return;
29097
29098 /* Get the first entry from the request Q */
29099@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29100 h->Qdepth--;
29101
29102 /* Tell the controller to do our bidding */
29103- h->access.submit_command(h, c);
29104+ h->access->submit_command(h, c);
29105
29106 /* Get onto the completion Q */
29107 addQ(&h->cmpQ, c);
29108@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29109 unsigned long flags;
29110 __u32 a,a1;
29111
29112- istat = h->access.intr_pending(h);
29113+ istat = h->access->intr_pending(h);
29114 /* Is this interrupt for us? */
29115 if (istat == 0)
29116 return IRQ_NONE;
29117@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29118 */
29119 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29120 if (istat & FIFO_NOT_EMPTY) {
29121- while((a = h->access.command_completed(h))) {
29122+ while((a = h->access->command_completed(h))) {
29123 a1 = a; a &= ~3;
29124 if ((c = h->cmpQ) == NULL)
29125 {
29126@@ -1449,11 +1449,11 @@ static int sendcmd(
29127 /*
29128 * Disable interrupt
29129 */
29130- info_p->access.set_intr_mask(info_p, 0);
29131+ info_p->access->set_intr_mask(info_p, 0);
29132 /* Make sure there is room in the command FIFO */
29133 /* Actually it should be completely empty at this time. */
29134 for (i = 200000; i > 0; i--) {
29135- temp = info_p->access.fifo_full(info_p);
29136+ temp = info_p->access->fifo_full(info_p);
29137 if (temp != 0) {
29138 break;
29139 }
29140@@ -1466,7 +1466,7 @@ DBG(
29141 /*
29142 * Send the cmd
29143 */
29144- info_p->access.submit_command(info_p, c);
29145+ info_p->access->submit_command(info_p, c);
29146 complete = pollcomplete(ctlr);
29147
29148 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29149@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29150 * we check the new geometry. Then turn interrupts back on when
29151 * we're done.
29152 */
29153- host->access.set_intr_mask(host, 0);
29154+ host->access->set_intr_mask(host, 0);
29155 getgeometry(ctlr);
29156- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29157+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29158
29159 for(i=0; i<NWD; i++) {
29160 struct gendisk *disk = ida_gendisk[ctlr][i];
29161@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29162 /* Wait (up to 2 seconds) for a command to complete */
29163
29164 for (i = 200000; i > 0; i--) {
29165- done = hba[ctlr]->access.command_completed(hba[ctlr]);
29166+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
29167 if (done == 0) {
29168 udelay(10); /* a short fixed delay */
29169 } else
29170diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29171index be73e9d..7fbf140 100644
29172--- a/drivers/block/cpqarray.h
29173+++ b/drivers/block/cpqarray.h
29174@@ -99,7 +99,7 @@ struct ctlr_info {
29175 drv_info_t drv[NWD];
29176 struct proc_dir_entry *proc;
29177
29178- struct access_method access;
29179+ struct access_method *access;
29180
29181 cmdlist_t *reqQ;
29182 cmdlist_t *cmpQ;
29183diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29184index 8d68056..e67050f 100644
29185--- a/drivers/block/drbd/drbd_int.h
29186+++ b/drivers/block/drbd/drbd_int.h
29187@@ -736,7 +736,7 @@ struct drbd_request;
29188 struct drbd_epoch {
29189 struct list_head list;
29190 unsigned int barrier_nr;
29191- atomic_t epoch_size; /* increased on every request added. */
29192+ atomic_unchecked_t epoch_size; /* increased on every request added. */
29193 atomic_t active; /* increased on every req. added, and dec on every finished. */
29194 unsigned long flags;
29195 };
29196@@ -1108,7 +1108,7 @@ struct drbd_conf {
29197 void *int_dig_in;
29198 void *int_dig_vv;
29199 wait_queue_head_t seq_wait;
29200- atomic_t packet_seq;
29201+ atomic_unchecked_t packet_seq;
29202 unsigned int peer_seq;
29203 spinlock_t peer_seq_lock;
29204 unsigned int minor;
29205@@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29206
29207 static inline void drbd_tcp_cork(struct socket *sock)
29208 {
29209- int __user val = 1;
29210+ int val = 1;
29211 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29212- (char __user *)&val, sizeof(val));
29213+ (char __force_user *)&val, sizeof(val));
29214 }
29215
29216 static inline void drbd_tcp_uncork(struct socket *sock)
29217 {
29218- int __user val = 0;
29219+ int val = 0;
29220 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29221- (char __user *)&val, sizeof(val));
29222+ (char __force_user *)&val, sizeof(val));
29223 }
29224
29225 static inline void drbd_tcp_nodelay(struct socket *sock)
29226 {
29227- int __user val = 1;
29228+ int val = 1;
29229 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29230- (char __user *)&val, sizeof(val));
29231+ (char __force_user *)&val, sizeof(val));
29232 }
29233
29234 static inline void drbd_tcp_quickack(struct socket *sock)
29235 {
29236- int __user val = 2;
29237+ int val = 2;
29238 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29239- (char __user *)&val, sizeof(val));
29240+ (char __force_user *)&val, sizeof(val));
29241 }
29242
29243 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29244diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29245index 211fc44..c5116f1 100644
29246--- a/drivers/block/drbd/drbd_main.c
29247+++ b/drivers/block/drbd/drbd_main.c
29248@@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29249 p.sector = sector;
29250 p.block_id = block_id;
29251 p.blksize = blksize;
29252- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29253+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29254
29255 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29256 return false;
29257@@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29258 p.sector = cpu_to_be64(req->sector);
29259 p.block_id = (unsigned long)req;
29260 p.seq_num = cpu_to_be32(req->seq_num =
29261- atomic_add_return(1, &mdev->packet_seq));
29262+ atomic_add_return_unchecked(1, &mdev->packet_seq));
29263
29264 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29265
29266@@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29267 atomic_set(&mdev->unacked_cnt, 0);
29268 atomic_set(&mdev->local_cnt, 0);
29269 atomic_set(&mdev->net_cnt, 0);
29270- atomic_set(&mdev->packet_seq, 0);
29271+ atomic_set_unchecked(&mdev->packet_seq, 0);
29272 atomic_set(&mdev->pp_in_use, 0);
29273 atomic_set(&mdev->pp_in_use_by_net, 0);
29274 atomic_set(&mdev->rs_sect_in, 0);
29275@@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29276 mdev->receiver.t_state);
29277
29278 /* no need to lock it, I'm the only thread alive */
29279- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29280- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29281+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29282+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29283 mdev->al_writ_cnt =
29284 mdev->bm_writ_cnt =
29285 mdev->read_cnt =
29286diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29287index 946166e..356b39a 100644
29288--- a/drivers/block/drbd/drbd_nl.c
29289+++ b/drivers/block/drbd/drbd_nl.c
29290@@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29291 module_put(THIS_MODULE);
29292 }
29293
29294-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29295+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29296
29297 static unsigned short *
29298 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29299@@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29300 cn_reply->id.idx = CN_IDX_DRBD;
29301 cn_reply->id.val = CN_VAL_DRBD;
29302
29303- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29304+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29305 cn_reply->ack = 0; /* not used here. */
29306 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29307 (int)((char *)tl - (char *)reply->tag_list);
29308@@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29309 cn_reply->id.idx = CN_IDX_DRBD;
29310 cn_reply->id.val = CN_VAL_DRBD;
29311
29312- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29313+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29314 cn_reply->ack = 0; /* not used here. */
29315 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29316 (int)((char *)tl - (char *)reply->tag_list);
29317@@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29318 cn_reply->id.idx = CN_IDX_DRBD;
29319 cn_reply->id.val = CN_VAL_DRBD;
29320
29321- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29322+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29323 cn_reply->ack = 0; // not used here.
29324 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29325 (int)((char*)tl - (char*)reply->tag_list);
29326@@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29327 cn_reply->id.idx = CN_IDX_DRBD;
29328 cn_reply->id.val = CN_VAL_DRBD;
29329
29330- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29331+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29332 cn_reply->ack = 0; /* not used here. */
29333 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29334 (int)((char *)tl - (char *)reply->tag_list);
29335diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29336index 43beaca..4a5b1dd 100644
29337--- a/drivers/block/drbd/drbd_receiver.c
29338+++ b/drivers/block/drbd/drbd_receiver.c
29339@@ -894,7 +894,7 @@ retry:
29340 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29341 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29342
29343- atomic_set(&mdev->packet_seq, 0);
29344+ atomic_set_unchecked(&mdev->packet_seq, 0);
29345 mdev->peer_seq = 0;
29346
29347 drbd_thread_start(&mdev->asender);
29348@@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29349 do {
29350 next_epoch = NULL;
29351
29352- epoch_size = atomic_read(&epoch->epoch_size);
29353+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29354
29355 switch (ev & ~EV_CLEANUP) {
29356 case EV_PUT:
29357@@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29358 rv = FE_DESTROYED;
29359 } else {
29360 epoch->flags = 0;
29361- atomic_set(&epoch->epoch_size, 0);
29362+ atomic_set_unchecked(&epoch->epoch_size, 0);
29363 /* atomic_set(&epoch->active, 0); is already zero */
29364 if (rv == FE_STILL_LIVE)
29365 rv = FE_RECYCLED;
29366@@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29367 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29368 drbd_flush(mdev);
29369
29370- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29371+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29372 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29373 if (epoch)
29374 break;
29375 }
29376
29377 epoch = mdev->current_epoch;
29378- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29379+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29380
29381 D_ASSERT(atomic_read(&epoch->active) == 0);
29382 D_ASSERT(epoch->flags == 0);
29383@@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29384 }
29385
29386 epoch->flags = 0;
29387- atomic_set(&epoch->epoch_size, 0);
29388+ atomic_set_unchecked(&epoch->epoch_size, 0);
29389 atomic_set(&epoch->active, 0);
29390
29391 spin_lock(&mdev->epoch_lock);
29392- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29393+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29394 list_add(&epoch->list, &mdev->current_epoch->list);
29395 mdev->current_epoch = epoch;
29396 mdev->epochs++;
29397@@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29398 spin_unlock(&mdev->peer_seq_lock);
29399
29400 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29401- atomic_inc(&mdev->current_epoch->epoch_size);
29402+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29403 return drbd_drain_block(mdev, data_size);
29404 }
29405
29406@@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29407
29408 spin_lock(&mdev->epoch_lock);
29409 e->epoch = mdev->current_epoch;
29410- atomic_inc(&e->epoch->epoch_size);
29411+ atomic_inc_unchecked(&e->epoch->epoch_size);
29412 atomic_inc(&e->epoch->active);
29413 spin_unlock(&mdev->epoch_lock);
29414
29415@@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29416 D_ASSERT(list_empty(&mdev->done_ee));
29417
29418 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29419- atomic_set(&mdev->current_epoch->epoch_size, 0);
29420+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29421 D_ASSERT(list_empty(&mdev->current_epoch->list));
29422 }
29423
29424diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29425index bbca966..65e37dd 100644
29426--- a/drivers/block/loop.c
29427+++ b/drivers/block/loop.c
29428@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29429 mm_segment_t old_fs = get_fs();
29430
29431 set_fs(get_ds());
29432- bw = file->f_op->write(file, buf, len, &pos);
29433+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29434 set_fs(old_fs);
29435 if (likely(bw == len))
29436 return 0;
29437diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29438index ee94686..3e09ad3 100644
29439--- a/drivers/char/Kconfig
29440+++ b/drivers/char/Kconfig
29441@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29442
29443 config DEVKMEM
29444 bool "/dev/kmem virtual device support"
29445- default y
29446+ default n
29447+ depends on !GRKERNSEC_KMEM
29448 help
29449 Say Y here if you want to support the /dev/kmem device. The
29450 /dev/kmem device is rarely used, but can be used for certain
29451@@ -581,6 +582,7 @@ config DEVPORT
29452 bool
29453 depends on !M68K
29454 depends on ISA || PCI
29455+ depends on !GRKERNSEC_KMEM
29456 default y
29457
29458 source "drivers/s390/char/Kconfig"
29459diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29460index 2e04433..22afc64 100644
29461--- a/drivers/char/agp/frontend.c
29462+++ b/drivers/char/agp/frontend.c
29463@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29464 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29465 return -EFAULT;
29466
29467- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29468+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29469 return -EFAULT;
29470
29471 client = agp_find_client_by_pid(reserve.pid);
29472diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29473index 21cb980..f15107c 100644
29474--- a/drivers/char/genrtc.c
29475+++ b/drivers/char/genrtc.c
29476@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29477 switch (cmd) {
29478
29479 case RTC_PLL_GET:
29480+ memset(&pll, 0, sizeof(pll));
29481 if (get_rtc_pll(&pll))
29482 return -EINVAL;
29483 else
29484diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29485index dfd7876..c0b0885 100644
29486--- a/drivers/char/hpet.c
29487+++ b/drivers/char/hpet.c
29488@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29489 }
29490
29491 static int
29492-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29493+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29494 struct hpet_info *info)
29495 {
29496 struct hpet_timer __iomem *timer;
29497diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29498index 2c29942..604c5ba 100644
29499--- a/drivers/char/ipmi/ipmi_msghandler.c
29500+++ b/drivers/char/ipmi/ipmi_msghandler.c
29501@@ -420,7 +420,7 @@ struct ipmi_smi {
29502 struct proc_dir_entry *proc_dir;
29503 char proc_dir_name[10];
29504
29505- atomic_t stats[IPMI_NUM_STATS];
29506+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29507
29508 /*
29509 * run_to_completion duplicate of smb_info, smi_info
29510@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29511
29512
29513 #define ipmi_inc_stat(intf, stat) \
29514- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29515+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29516 #define ipmi_get_stat(intf, stat) \
29517- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29518+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29519
29520 static int is_lan_addr(struct ipmi_addr *addr)
29521 {
29522@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29523 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29524 init_waitqueue_head(&intf->waitq);
29525 for (i = 0; i < IPMI_NUM_STATS; i++)
29526- atomic_set(&intf->stats[i], 0);
29527+ atomic_set_unchecked(&intf->stats[i], 0);
29528
29529 intf->proc_dir = NULL;
29530
29531diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29532index 1e638ff..a869ef5 100644
29533--- a/drivers/char/ipmi/ipmi_si_intf.c
29534+++ b/drivers/char/ipmi/ipmi_si_intf.c
29535@@ -275,7 +275,7 @@ struct smi_info {
29536 unsigned char slave_addr;
29537
29538 /* Counters and things for the proc filesystem. */
29539- atomic_t stats[SI_NUM_STATS];
29540+ atomic_unchecked_t stats[SI_NUM_STATS];
29541
29542 struct task_struct *thread;
29543
29544@@ -284,9 +284,9 @@ struct smi_info {
29545 };
29546
29547 #define smi_inc_stat(smi, stat) \
29548- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29549+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29550 #define smi_get_stat(smi, stat) \
29551- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29552+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29553
29554 #define SI_MAX_PARMS 4
29555
29556@@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29557 atomic_set(&new_smi->req_events, 0);
29558 new_smi->run_to_completion = 0;
29559 for (i = 0; i < SI_NUM_STATS; i++)
29560- atomic_set(&new_smi->stats[i], 0);
29561+ atomic_set_unchecked(&new_smi->stats[i], 0);
29562
29563 new_smi->interrupt_disabled = 1;
29564 atomic_set(&new_smi->stop_operation, 0);
29565diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29566index 47ff7e4..0c7d340 100644
29567--- a/drivers/char/mbcs.c
29568+++ b/drivers/char/mbcs.c
29569@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29570 return 0;
29571 }
29572
29573-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29574+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29575 {
29576 .part_num = MBCS_PART_NUM,
29577 .mfg_num = MBCS_MFG_NUM,
29578diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29579index d6e9d08..0c314bf 100644
29580--- a/drivers/char/mem.c
29581+++ b/drivers/char/mem.c
29582@@ -18,6 +18,7 @@
29583 #include <linux/raw.h>
29584 #include <linux/tty.h>
29585 #include <linux/capability.h>
29586+#include <linux/security.h>
29587 #include <linux/ptrace.h>
29588 #include <linux/device.h>
29589 #include <linux/highmem.h>
29590@@ -35,6 +36,10 @@
29591 # include <linux/efi.h>
29592 #endif
29593
29594+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29595+extern const struct file_operations grsec_fops;
29596+#endif
29597+
29598 static inline unsigned long size_inside_page(unsigned long start,
29599 unsigned long size)
29600 {
29601@@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29602
29603 while (cursor < to) {
29604 if (!devmem_is_allowed(pfn)) {
29605+#ifdef CONFIG_GRKERNSEC_KMEM
29606+ gr_handle_mem_readwrite(from, to);
29607+#else
29608 printk(KERN_INFO
29609 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29610 current->comm, from, to);
29611+#endif
29612 return 0;
29613 }
29614 cursor += PAGE_SIZE;
29615@@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29616 }
29617 return 1;
29618 }
29619+#elif defined(CONFIG_GRKERNSEC_KMEM)
29620+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29621+{
29622+ return 0;
29623+}
29624 #else
29625 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29626 {
29627@@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29628
29629 while (count > 0) {
29630 unsigned long remaining;
29631+ char *temp;
29632
29633 sz = size_inside_page(p, count);
29634
29635@@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29636 if (!ptr)
29637 return -EFAULT;
29638
29639- remaining = copy_to_user(buf, ptr, sz);
29640+#ifdef CONFIG_PAX_USERCOPY
29641+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29642+ if (!temp) {
29643+ unxlate_dev_mem_ptr(p, ptr);
29644+ return -ENOMEM;
29645+ }
29646+ memcpy(temp, ptr, sz);
29647+#else
29648+ temp = ptr;
29649+#endif
29650+
29651+ remaining = copy_to_user(buf, temp, sz);
29652+
29653+#ifdef CONFIG_PAX_USERCOPY
29654+ kfree(temp);
29655+#endif
29656+
29657 unxlate_dev_mem_ptr(p, ptr);
29658 if (remaining)
29659 return -EFAULT;
29660@@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29661 size_t count, loff_t *ppos)
29662 {
29663 unsigned long p = *ppos;
29664- ssize_t low_count, read, sz;
29665+ ssize_t low_count, read, sz, err = 0;
29666 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29667- int err = 0;
29668
29669 read = 0;
29670 if (p < (unsigned long) high_memory) {
29671@@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29672 }
29673 #endif
29674 while (low_count > 0) {
29675+ char *temp;
29676+
29677 sz = size_inside_page(p, low_count);
29678
29679 /*
29680@@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29681 */
29682 kbuf = xlate_dev_kmem_ptr((char *)p);
29683
29684- if (copy_to_user(buf, kbuf, sz))
29685+#ifdef CONFIG_PAX_USERCOPY
29686+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29687+ if (!temp)
29688+ return -ENOMEM;
29689+ memcpy(temp, kbuf, sz);
29690+#else
29691+ temp = kbuf;
29692+#endif
29693+
29694+ err = copy_to_user(buf, temp, sz);
29695+
29696+#ifdef CONFIG_PAX_USERCOPY
29697+ kfree(temp);
29698+#endif
29699+
29700+ if (err)
29701 return -EFAULT;
29702 buf += sz;
29703 p += sz;
29704@@ -867,6 +914,9 @@ static const struct memdev {
29705 #ifdef CONFIG_CRASH_DUMP
29706 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29707 #endif
29708+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29709+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29710+#endif
29711 };
29712
29713 static int memory_open(struct inode *inode, struct file *filp)
29714diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29715index 9df78e2..01ba9ae 100644
29716--- a/drivers/char/nvram.c
29717+++ b/drivers/char/nvram.c
29718@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29719
29720 spin_unlock_irq(&rtc_lock);
29721
29722- if (copy_to_user(buf, contents, tmp - contents))
29723+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29724 return -EFAULT;
29725
29726 *ppos = i;
29727diff --git a/drivers/char/random.c b/drivers/char/random.c
29728index 4ec04a7..9918387 100644
29729--- a/drivers/char/random.c
29730+++ b/drivers/char/random.c
29731@@ -261,8 +261,13 @@
29732 /*
29733 * Configuration information
29734 */
29735+#ifdef CONFIG_GRKERNSEC_RANDNET
29736+#define INPUT_POOL_WORDS 512
29737+#define OUTPUT_POOL_WORDS 128
29738+#else
29739 #define INPUT_POOL_WORDS 128
29740 #define OUTPUT_POOL_WORDS 32
29741+#endif
29742 #define SEC_XFER_SIZE 512
29743 #define EXTRACT_SIZE 10
29744
29745@@ -300,10 +305,17 @@ static struct poolinfo {
29746 int poolwords;
29747 int tap1, tap2, tap3, tap4, tap5;
29748 } poolinfo_table[] = {
29749+#ifdef CONFIG_GRKERNSEC_RANDNET
29750+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29751+ { 512, 411, 308, 208, 104, 1 },
29752+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29753+ { 128, 103, 76, 51, 25, 1 },
29754+#else
29755 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29756 { 128, 103, 76, 51, 25, 1 },
29757 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29758 { 32, 26, 20, 14, 7, 1 },
29759+#endif
29760 #if 0
29761 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29762 { 2048, 1638, 1231, 819, 411, 1 },
29763@@ -726,6 +738,17 @@ void add_disk_randomness(struct gendisk *disk)
29764 }
29765 #endif
29766
29767+#ifdef CONFIG_PAX_LATENT_ENTROPY
29768+u64 latent_entropy;
29769+
29770+__init void transfer_latent_entropy(void)
29771+{
29772+ mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy));
29773+ mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy));
29774+// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29775+}
29776+#endif
29777+
29778 /*********************************************************************
29779 *
29780 * Entropy extraction routines
29781@@ -913,7 +936,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29782
29783 extract_buf(r, tmp);
29784 i = min_t(int, nbytes, EXTRACT_SIZE);
29785- if (copy_to_user(buf, tmp, i)) {
29786+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29787 ret = -EFAULT;
29788 break;
29789 }
29790@@ -1238,7 +1261,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29791 #include <linux/sysctl.h>
29792
29793 static int min_read_thresh = 8, min_write_thresh;
29794-static int max_read_thresh = INPUT_POOL_WORDS * 32;
29795+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29796 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29797 static char sysctl_bootid[16];
29798
29799diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29800index 45713f0..8286d21 100644
29801--- a/drivers/char/sonypi.c
29802+++ b/drivers/char/sonypi.c
29803@@ -54,6 +54,7 @@
29804
29805 #include <asm/uaccess.h>
29806 #include <asm/io.h>
29807+#include <asm/local.h>
29808
29809 #include <linux/sonypi.h>
29810
29811@@ -490,7 +491,7 @@ static struct sonypi_device {
29812 spinlock_t fifo_lock;
29813 wait_queue_head_t fifo_proc_list;
29814 struct fasync_struct *fifo_async;
29815- int open_count;
29816+ local_t open_count;
29817 int model;
29818 struct input_dev *input_jog_dev;
29819 struct input_dev *input_key_dev;
29820@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29821 static int sonypi_misc_release(struct inode *inode, struct file *file)
29822 {
29823 mutex_lock(&sonypi_device.lock);
29824- sonypi_device.open_count--;
29825+ local_dec(&sonypi_device.open_count);
29826 mutex_unlock(&sonypi_device.lock);
29827 return 0;
29828 }
29829@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29830 {
29831 mutex_lock(&sonypi_device.lock);
29832 /* Flush input queue on first open */
29833- if (!sonypi_device.open_count)
29834+ if (!local_read(&sonypi_device.open_count))
29835 kfifo_reset(&sonypi_device.fifo);
29836- sonypi_device.open_count++;
29837+ local_inc(&sonypi_device.open_count);
29838 mutex_unlock(&sonypi_device.lock);
29839
29840 return 0;
29841diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29842index ad7c732..5aa8054 100644
29843--- a/drivers/char/tpm/tpm.c
29844+++ b/drivers/char/tpm/tpm.c
29845@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29846 chip->vendor.req_complete_val)
29847 goto out_recv;
29848
29849- if ((status == chip->vendor.req_canceled)) {
29850+ if (status == chip->vendor.req_canceled) {
29851 dev_err(chip->dev, "Operation Canceled\n");
29852 rc = -ECANCELED;
29853 goto out;
29854diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29855index 0636520..169c1d0 100644
29856--- a/drivers/char/tpm/tpm_bios.c
29857+++ b/drivers/char/tpm/tpm_bios.c
29858@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29859 event = addr;
29860
29861 if ((event->event_type == 0 && event->event_size == 0) ||
29862- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29863+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29864 return NULL;
29865
29866 return addr;
29867@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29868 return NULL;
29869
29870 if ((event->event_type == 0 && event->event_size == 0) ||
29871- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29872+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29873 return NULL;
29874
29875 (*pos)++;
29876@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29877 int i;
29878
29879 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29880- seq_putc(m, data[i]);
29881+ if (!seq_putc(m, data[i]))
29882+ return -EFAULT;
29883
29884 return 0;
29885 }
29886@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29887 log->bios_event_log_end = log->bios_event_log + len;
29888
29889 virt = acpi_os_map_memory(start, len);
29890+ if (!virt) {
29891+ kfree(log->bios_event_log);
29892+ log->bios_event_log = NULL;
29893+ return -EFAULT;
29894+ }
29895
29896- memcpy(log->bios_event_log, virt, len);
29897+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29898
29899 acpi_os_unmap_memory(virt, len);
29900 return 0;
29901diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29902index cdf2f54..e55c197 100644
29903--- a/drivers/char/virtio_console.c
29904+++ b/drivers/char/virtio_console.c
29905@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29906 if (to_user) {
29907 ssize_t ret;
29908
29909- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29910+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29911 if (ret)
29912 return -EFAULT;
29913 } else {
29914@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29915 if (!port_has_data(port) && !port->host_connected)
29916 return 0;
29917
29918- return fill_readbuf(port, ubuf, count, true);
29919+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29920 }
29921
29922 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29923diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29924index 97f5064..202b6e6 100644
29925--- a/drivers/edac/edac_pci_sysfs.c
29926+++ b/drivers/edac/edac_pci_sysfs.c
29927@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29928 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29929 static int edac_pci_poll_msec = 1000; /* one second workq period */
29930
29931-static atomic_t pci_parity_count = ATOMIC_INIT(0);
29932-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29933+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29934+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29935
29936 static struct kobject *edac_pci_top_main_kobj;
29937 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29938@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29939 edac_printk(KERN_CRIT, EDAC_PCI,
29940 "Signaled System Error on %s\n",
29941 pci_name(dev));
29942- atomic_inc(&pci_nonparity_count);
29943+ atomic_inc_unchecked(&pci_nonparity_count);
29944 }
29945
29946 if (status & (PCI_STATUS_PARITY)) {
29947@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29948 "Master Data Parity Error on %s\n",
29949 pci_name(dev));
29950
29951- atomic_inc(&pci_parity_count);
29952+ atomic_inc_unchecked(&pci_parity_count);
29953 }
29954
29955 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29956@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29957 "Detected Parity Error on %s\n",
29958 pci_name(dev));
29959
29960- atomic_inc(&pci_parity_count);
29961+ atomic_inc_unchecked(&pci_parity_count);
29962 }
29963 }
29964
29965@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29966 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29967 "Signaled System Error on %s\n",
29968 pci_name(dev));
29969- atomic_inc(&pci_nonparity_count);
29970+ atomic_inc_unchecked(&pci_nonparity_count);
29971 }
29972
29973 if (status & (PCI_STATUS_PARITY)) {
29974@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29975 "Master Data Parity Error on "
29976 "%s\n", pci_name(dev));
29977
29978- atomic_inc(&pci_parity_count);
29979+ atomic_inc_unchecked(&pci_parity_count);
29980 }
29981
29982 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29983@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29984 "Detected Parity Error on %s\n",
29985 pci_name(dev));
29986
29987- atomic_inc(&pci_parity_count);
29988+ atomic_inc_unchecked(&pci_parity_count);
29989 }
29990 }
29991 }
29992@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29993 if (!check_pci_errors)
29994 return;
29995
29996- before_count = atomic_read(&pci_parity_count);
29997+ before_count = atomic_read_unchecked(&pci_parity_count);
29998
29999 /* scan all PCI devices looking for a Parity Error on devices and
30000 * bridges.
30001@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
30002 /* Only if operator has selected panic on PCI Error */
30003 if (edac_pci_get_panic_on_pe()) {
30004 /* If the count is different 'after' from 'before' */
30005- if (before_count != atomic_read(&pci_parity_count))
30006+ if (before_count != atomic_read_unchecked(&pci_parity_count))
30007 panic("EDAC: PCI Parity Error");
30008 }
30009 }
30010diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30011index c6074c5..88a9e2e 100644
30012--- a/drivers/edac/mce_amd.h
30013+++ b/drivers/edac/mce_amd.h
30014@@ -82,7 +82,7 @@ extern const char * const ii_msgs[];
30015 struct amd_decoder_ops {
30016 bool (*dc_mce)(u16, u8);
30017 bool (*ic_mce)(u16, u8);
30018-};
30019+} __no_const;
30020
30021 void amd_report_gart_errors(bool);
30022 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30023diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30024index cc595eb..4ec702a 100644
30025--- a/drivers/firewire/core-card.c
30026+++ b/drivers/firewire/core-card.c
30027@@ -679,7 +679,7 @@ void fw_card_release(struct kref *kref)
30028
30029 void fw_core_remove_card(struct fw_card *card)
30030 {
30031- struct fw_card_driver dummy_driver = dummy_driver_template;
30032+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
30033
30034 card->driver->update_phy_reg(card, 4,
30035 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30036diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30037index 2e6b245..c3857d9 100644
30038--- a/drivers/firewire/core-cdev.c
30039+++ b/drivers/firewire/core-cdev.c
30040@@ -1341,8 +1341,7 @@ static int init_iso_resource(struct client *client,
30041 int ret;
30042
30043 if ((request->channels == 0 && request->bandwidth == 0) ||
30044- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30045- request->bandwidth < 0)
30046+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30047 return -EINVAL;
30048
30049 r = kmalloc(sizeof(*r), GFP_KERNEL);
30050diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30051index dea2dcc..a4fb978 100644
30052--- a/drivers/firewire/core-transaction.c
30053+++ b/drivers/firewire/core-transaction.c
30054@@ -37,6 +37,7 @@
30055 #include <linux/timer.h>
30056 #include <linux/types.h>
30057 #include <linux/workqueue.h>
30058+#include <linux/sched.h>
30059
30060 #include <asm/byteorder.h>
30061
30062diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30063index 9047f55..e47c7ff 100644
30064--- a/drivers/firewire/core.h
30065+++ b/drivers/firewire/core.h
30066@@ -110,6 +110,7 @@ struct fw_card_driver {
30067
30068 int (*stop_iso)(struct fw_iso_context *ctx);
30069 };
30070+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30071
30072 void fw_card_initialize(struct fw_card *card,
30073 const struct fw_card_driver *driver, struct device *device);
30074diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30075index 153980b..4b4d046 100644
30076--- a/drivers/firmware/dmi_scan.c
30077+++ b/drivers/firmware/dmi_scan.c
30078@@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
30079 }
30080 }
30081 else {
30082- /*
30083- * no iounmap() for that ioremap(); it would be a no-op, but
30084- * it's so early in setup that sucker gets confused into doing
30085- * what it shouldn't if we actually call it.
30086- */
30087 p = dmi_ioremap(0xF0000, 0x10000);
30088 if (p == NULL)
30089 goto error;
30090@@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30091 if (buf == NULL)
30092 return -1;
30093
30094- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30095+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30096
30097 iounmap(buf);
30098 return 0;
30099diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30100index 82d5c20..44a7177 100644
30101--- a/drivers/gpio/gpio-vr41xx.c
30102+++ b/drivers/gpio/gpio-vr41xx.c
30103@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30104 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30105 maskl, pendl, maskh, pendh);
30106
30107- atomic_inc(&irq_err_count);
30108+ atomic_inc_unchecked(&irq_err_count);
30109
30110 return -EINVAL;
30111 }
30112diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30113index 8111889..367b253 100644
30114--- a/drivers/gpu/drm/drm_crtc_helper.c
30115+++ b/drivers/gpu/drm/drm_crtc_helper.c
30116@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30117 struct drm_crtc *tmp;
30118 int crtc_mask = 1;
30119
30120- WARN(!crtc, "checking null crtc?\n");
30121+ BUG_ON(!crtc);
30122
30123 dev = crtc->dev;
30124
30125diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30126index 6116e3b..c29dd16 100644
30127--- a/drivers/gpu/drm/drm_drv.c
30128+++ b/drivers/gpu/drm/drm_drv.c
30129@@ -316,7 +316,7 @@ module_exit(drm_core_exit);
30130 /**
30131 * Copy and IOCTL return string to user space
30132 */
30133-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30134+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30135 {
30136 int len;
30137
30138@@ -399,7 +399,7 @@ long drm_ioctl(struct file *filp,
30139 return -ENODEV;
30140
30141 atomic_inc(&dev->ioctl_count);
30142- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30143+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30144 ++file_priv->ioctl_count;
30145
30146 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30147diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30148index 123de28..43a0897 100644
30149--- a/drivers/gpu/drm/drm_fops.c
30150+++ b/drivers/gpu/drm/drm_fops.c
30151@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30152 }
30153
30154 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30155- atomic_set(&dev->counts[i], 0);
30156+ atomic_set_unchecked(&dev->counts[i], 0);
30157
30158 dev->sigdata.lock = NULL;
30159
30160@@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30161
30162 retcode = drm_open_helper(inode, filp, dev);
30163 if (!retcode) {
30164- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30165- if (!dev->open_count++)
30166+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30167+ if (local_inc_return(&dev->open_count) == 1)
30168 retcode = drm_setup(dev);
30169 }
30170 if (!retcode) {
30171@@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30172
30173 mutex_lock(&drm_global_mutex);
30174
30175- DRM_DEBUG("open_count = %d\n", dev->open_count);
30176+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30177
30178 if (dev->driver->preclose)
30179 dev->driver->preclose(dev, file_priv);
30180@@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30181 * Begin inline drm_release
30182 */
30183
30184- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30185+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30186 task_pid_nr(current),
30187 (long)old_encode_dev(file_priv->minor->device),
30188- dev->open_count);
30189+ local_read(&dev->open_count));
30190
30191 /* Release any auth tokens that might point to this file_priv,
30192 (do that under the drm_global_mutex) */
30193@@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30194 * End inline drm_release
30195 */
30196
30197- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30198- if (!--dev->open_count) {
30199+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30200+ if (local_dec_and_test(&dev->open_count)) {
30201 if (atomic_read(&dev->ioctl_count)) {
30202 DRM_ERROR("Device busy: %d\n",
30203 atomic_read(&dev->ioctl_count));
30204diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30205index c87dc96..326055d 100644
30206--- a/drivers/gpu/drm/drm_global.c
30207+++ b/drivers/gpu/drm/drm_global.c
30208@@ -36,7 +36,7 @@
30209 struct drm_global_item {
30210 struct mutex mutex;
30211 void *object;
30212- int refcount;
30213+ atomic_t refcount;
30214 };
30215
30216 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30217@@ -49,7 +49,7 @@ void drm_global_init(void)
30218 struct drm_global_item *item = &glob[i];
30219 mutex_init(&item->mutex);
30220 item->object = NULL;
30221- item->refcount = 0;
30222+ atomic_set(&item->refcount, 0);
30223 }
30224 }
30225
30226@@ -59,7 +59,7 @@ void drm_global_release(void)
30227 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30228 struct drm_global_item *item = &glob[i];
30229 BUG_ON(item->object != NULL);
30230- BUG_ON(item->refcount != 0);
30231+ BUG_ON(atomic_read(&item->refcount) != 0);
30232 }
30233 }
30234
30235@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30236 void *object;
30237
30238 mutex_lock(&item->mutex);
30239- if (item->refcount == 0) {
30240+ if (atomic_read(&item->refcount) == 0) {
30241 item->object = kzalloc(ref->size, GFP_KERNEL);
30242 if (unlikely(item->object == NULL)) {
30243 ret = -ENOMEM;
30244@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30245 goto out_err;
30246
30247 }
30248- ++item->refcount;
30249+ atomic_inc(&item->refcount);
30250 ref->object = item->object;
30251 object = item->object;
30252 mutex_unlock(&item->mutex);
30253@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30254 struct drm_global_item *item = &glob[ref->global_type];
30255
30256 mutex_lock(&item->mutex);
30257- BUG_ON(item->refcount == 0);
30258+ BUG_ON(atomic_read(&item->refcount) == 0);
30259 BUG_ON(ref->object != item->object);
30260- if (--item->refcount == 0) {
30261+ if (atomic_dec_and_test(&item->refcount)) {
30262 ref->release(ref);
30263 item->object = NULL;
30264 }
30265diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30266index ab1162d..42587b2 100644
30267--- a/drivers/gpu/drm/drm_info.c
30268+++ b/drivers/gpu/drm/drm_info.c
30269@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30270 struct drm_local_map *map;
30271 struct drm_map_list *r_list;
30272
30273- /* Hardcoded from _DRM_FRAME_BUFFER,
30274- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30275- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30276- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30277+ static const char * const types[] = {
30278+ [_DRM_FRAME_BUFFER] = "FB",
30279+ [_DRM_REGISTERS] = "REG",
30280+ [_DRM_SHM] = "SHM",
30281+ [_DRM_AGP] = "AGP",
30282+ [_DRM_SCATTER_GATHER] = "SG",
30283+ [_DRM_CONSISTENT] = "PCI",
30284+ [_DRM_GEM] = "GEM" };
30285 const char *type;
30286 int i;
30287
30288@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30289 map = r_list->map;
30290 if (!map)
30291 continue;
30292- if (map->type < 0 || map->type > 5)
30293+ if (map->type >= ARRAY_SIZE(types))
30294 type = "??";
30295 else
30296 type = types[map->type];
30297@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30298 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30299 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30300 vma->vm_flags & VM_IO ? 'i' : '-',
30301+#ifdef CONFIG_GRKERNSEC_HIDESYM
30302+ 0);
30303+#else
30304 vma->vm_pgoff);
30305+#endif
30306
30307 #if defined(__i386__)
30308 pgprot = pgprot_val(vma->vm_page_prot);
30309diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30310index 637fcc3..e890b33 100644
30311--- a/drivers/gpu/drm/drm_ioc32.c
30312+++ b/drivers/gpu/drm/drm_ioc32.c
30313@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30314 request = compat_alloc_user_space(nbytes);
30315 if (!access_ok(VERIFY_WRITE, request, nbytes))
30316 return -EFAULT;
30317- list = (struct drm_buf_desc *) (request + 1);
30318+ list = (struct drm_buf_desc __user *) (request + 1);
30319
30320 if (__put_user(count, &request->count)
30321 || __put_user(list, &request->list))
30322@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30323 request = compat_alloc_user_space(nbytes);
30324 if (!access_ok(VERIFY_WRITE, request, nbytes))
30325 return -EFAULT;
30326- list = (struct drm_buf_pub *) (request + 1);
30327+ list = (struct drm_buf_pub __user *) (request + 1);
30328
30329 if (__put_user(count, &request->count)
30330 || __put_user(list, &request->list))
30331diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30332index cf85155..f2665cb 100644
30333--- a/drivers/gpu/drm/drm_ioctl.c
30334+++ b/drivers/gpu/drm/drm_ioctl.c
30335@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30336 stats->data[i].value =
30337 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30338 else
30339- stats->data[i].value = atomic_read(&dev->counts[i]);
30340+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30341 stats->data[i].type = dev->types[i];
30342 }
30343
30344diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30345index c79c713..2048588 100644
30346--- a/drivers/gpu/drm/drm_lock.c
30347+++ b/drivers/gpu/drm/drm_lock.c
30348@@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30349 if (drm_lock_take(&master->lock, lock->context)) {
30350 master->lock.file_priv = file_priv;
30351 master->lock.lock_time = jiffies;
30352- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30353+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30354 break; /* Got lock */
30355 }
30356
30357@@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30358 return -EINVAL;
30359 }
30360
30361- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30362+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30363
30364 if (drm_lock_free(&master->lock, lock->context)) {
30365 /* FIXME: Should really bail out here. */
30366diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30367index aa454f8..6d38580 100644
30368--- a/drivers/gpu/drm/drm_stub.c
30369+++ b/drivers/gpu/drm/drm_stub.c
30370@@ -512,7 +512,7 @@ void drm_unplug_dev(struct drm_device *dev)
30371
30372 drm_device_set_unplugged(dev);
30373
30374- if (dev->open_count == 0) {
30375+ if (local_read(&dev->open_count) == 0) {
30376 drm_put_dev(dev);
30377 }
30378 mutex_unlock(&drm_global_mutex);
30379diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30380index f920fb5..001c52d 100644
30381--- a/drivers/gpu/drm/i810/i810_dma.c
30382+++ b/drivers/gpu/drm/i810/i810_dma.c
30383@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30384 dma->buflist[vertex->idx],
30385 vertex->discard, vertex->used);
30386
30387- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30388- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30389+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30390+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30391 sarea_priv->last_enqueue = dev_priv->counter - 1;
30392 sarea_priv->last_dispatch = (int)hw_status[5];
30393
30394@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30395 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30396 mc->last_render);
30397
30398- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30399- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30400+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30401+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30402 sarea_priv->last_enqueue = dev_priv->counter - 1;
30403 sarea_priv->last_dispatch = (int)hw_status[5];
30404
30405diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30406index c9339f4..f5e1b9d 100644
30407--- a/drivers/gpu/drm/i810/i810_drv.h
30408+++ b/drivers/gpu/drm/i810/i810_drv.h
30409@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30410 int page_flipping;
30411
30412 wait_queue_head_t irq_queue;
30413- atomic_t irq_received;
30414- atomic_t irq_emitted;
30415+ atomic_unchecked_t irq_received;
30416+ atomic_unchecked_t irq_emitted;
30417
30418 int front_offset;
30419 } drm_i810_private_t;
30420diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30421index e6162a1..b2ff486 100644
30422--- a/drivers/gpu/drm/i915/i915_debugfs.c
30423+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30424@@ -500,7 +500,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30425 I915_READ(GTIMR));
30426 }
30427 seq_printf(m, "Interrupts received: %d\n",
30428- atomic_read(&dev_priv->irq_received));
30429+ atomic_read_unchecked(&dev_priv->irq_received));
30430 for (i = 0; i < I915_NUM_RINGS; i++) {
30431 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30432 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30433@@ -1313,7 +1313,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30434 return ret;
30435
30436 if (opregion->header)
30437- seq_write(m, opregion->header, OPREGION_SIZE);
30438+ seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30439
30440 mutex_unlock(&dev->struct_mutex);
30441
30442diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30443index ba60f3c..e2dff7f 100644
30444--- a/drivers/gpu/drm/i915/i915_dma.c
30445+++ b/drivers/gpu/drm/i915/i915_dma.c
30446@@ -1178,7 +1178,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30447 bool can_switch;
30448
30449 spin_lock(&dev->count_lock);
30450- can_switch = (dev->open_count == 0);
30451+ can_switch = (local_read(&dev->open_count) == 0);
30452 spin_unlock(&dev->count_lock);
30453 return can_switch;
30454 }
30455diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30456index 5fabc6c..0b08aa1 100644
30457--- a/drivers/gpu/drm/i915/i915_drv.h
30458+++ b/drivers/gpu/drm/i915/i915_drv.h
30459@@ -240,7 +240,7 @@ struct drm_i915_display_funcs {
30460 /* render clock increase/decrease */
30461 /* display clock increase/decrease */
30462 /* pll clock increase/decrease */
30463-};
30464+} __no_const;
30465
30466 struct intel_device_info {
30467 u8 gen;
30468@@ -350,7 +350,7 @@ typedef struct drm_i915_private {
30469 int current_page;
30470 int page_flipping;
30471
30472- atomic_t irq_received;
30473+ atomic_unchecked_t irq_received;
30474
30475 /* protects the irq masks */
30476 spinlock_t irq_lock;
30477@@ -937,7 +937,7 @@ struct drm_i915_gem_object {
30478 * will be page flipped away on the next vblank. When it
30479 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30480 */
30481- atomic_t pending_flip;
30482+ atomic_unchecked_t pending_flip;
30483 };
30484
30485 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30486@@ -1359,7 +1359,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30487 extern void intel_teardown_gmbus(struct drm_device *dev);
30488 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30489 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30490-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30491+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30492 {
30493 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30494 }
30495diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30496index de43194..a14c4cc 100644
30497--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30498+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30499@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30500 i915_gem_clflush_object(obj);
30501
30502 if (obj->base.pending_write_domain)
30503- cd->flips |= atomic_read(&obj->pending_flip);
30504+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30505
30506 /* The actual obj->write_domain will be updated with
30507 * pending_write_domain after we emit the accumulated flush for all
30508@@ -933,9 +933,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30509
30510 static int
30511 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30512- int count)
30513+ unsigned int count)
30514 {
30515- int i;
30516+ unsigned int i;
30517
30518 for (i = 0; i < count; i++) {
30519 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30520diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30521index 26c67a7..8d4cbcb 100644
30522--- a/drivers/gpu/drm/i915/i915_irq.c
30523+++ b/drivers/gpu/drm/i915/i915_irq.c
30524@@ -496,7 +496,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30525 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30526 struct drm_i915_master_private *master_priv;
30527
30528- atomic_inc(&dev_priv->irq_received);
30529+ atomic_inc_unchecked(&dev_priv->irq_received);
30530
30531 /* disable master interrupt before clearing iir */
30532 de_ier = I915_READ(DEIER);
30533@@ -579,7 +579,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30534 struct drm_i915_master_private *master_priv;
30535 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30536
30537- atomic_inc(&dev_priv->irq_received);
30538+ atomic_inc_unchecked(&dev_priv->irq_received);
30539
30540 if (IS_GEN6(dev))
30541 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30542@@ -1291,7 +1291,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30543 int ret = IRQ_NONE, pipe;
30544 bool blc_event = false;
30545
30546- atomic_inc(&dev_priv->irq_received);
30547+ atomic_inc_unchecked(&dev_priv->irq_received);
30548
30549 iir = I915_READ(IIR);
30550
30551@@ -1802,7 +1802,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30552 {
30553 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30554
30555- atomic_set(&dev_priv->irq_received, 0);
30556+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30557
30558 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30559 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30560@@ -1979,7 +1979,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30561 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30562 int pipe;
30563
30564- atomic_set(&dev_priv->irq_received, 0);
30565+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30566
30567 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30568 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30569diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30570index d4d162f..b49a04e 100644
30571--- a/drivers/gpu/drm/i915/intel_display.c
30572+++ b/drivers/gpu/drm/i915/intel_display.c
30573@@ -2254,7 +2254,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30574
30575 wait_event(dev_priv->pending_flip_queue,
30576 atomic_read(&dev_priv->mm.wedged) ||
30577- atomic_read(&obj->pending_flip) == 0);
30578+ atomic_read_unchecked(&obj->pending_flip) == 0);
30579
30580 /* Big Hammer, we also need to ensure that any pending
30581 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30582@@ -2919,7 +2919,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30583 obj = to_intel_framebuffer(crtc->fb)->obj;
30584 dev_priv = crtc->dev->dev_private;
30585 wait_event(dev_priv->pending_flip_queue,
30586- atomic_read(&obj->pending_flip) == 0);
30587+ atomic_read_unchecked(&obj->pending_flip) == 0);
30588 }
30589
30590 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30591@@ -7284,9 +7284,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30592
30593 obj = work->old_fb_obj;
30594
30595- atomic_clear_mask(1 << intel_crtc->plane,
30596- &obj->pending_flip.counter);
30597- if (atomic_read(&obj->pending_flip) == 0)
30598+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30599+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
30600 wake_up(&dev_priv->pending_flip_queue);
30601
30602 schedule_work(&work->work);
30603@@ -7582,7 +7581,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30604 /* Block clients from rendering to the new back buffer until
30605 * the flip occurs and the object is no longer visible.
30606 */
30607- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30608+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30609
30610 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30611 if (ret)
30612@@ -7596,7 +7595,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30613 return 0;
30614
30615 cleanup_pending:
30616- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30617+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30618 drm_gem_object_unreference(&work->old_fb_obj->base);
30619 drm_gem_object_unreference(&obj->base);
30620 mutex_unlock(&dev->struct_mutex);
30621diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30622index 54558a0..2d97005 100644
30623--- a/drivers/gpu/drm/mga/mga_drv.h
30624+++ b/drivers/gpu/drm/mga/mga_drv.h
30625@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30626 u32 clear_cmd;
30627 u32 maccess;
30628
30629- atomic_t vbl_received; /**< Number of vblanks received. */
30630+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30631 wait_queue_head_t fence_queue;
30632- atomic_t last_fence_retired;
30633+ atomic_unchecked_t last_fence_retired;
30634 u32 next_fence_to_post;
30635
30636 unsigned int fb_cpp;
30637diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30638index 2581202..f230a8d9 100644
30639--- a/drivers/gpu/drm/mga/mga_irq.c
30640+++ b/drivers/gpu/drm/mga/mga_irq.c
30641@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30642 if (crtc != 0)
30643 return 0;
30644
30645- return atomic_read(&dev_priv->vbl_received);
30646+ return atomic_read_unchecked(&dev_priv->vbl_received);
30647 }
30648
30649
30650@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30651 /* VBLANK interrupt */
30652 if (status & MGA_VLINEPEN) {
30653 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30654- atomic_inc(&dev_priv->vbl_received);
30655+ atomic_inc_unchecked(&dev_priv->vbl_received);
30656 drm_handle_vblank(dev, 0);
30657 handled = 1;
30658 }
30659@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30660 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30661 MGA_WRITE(MGA_PRIMEND, prim_end);
30662
30663- atomic_inc(&dev_priv->last_fence_retired);
30664+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
30665 DRM_WAKEUP(&dev_priv->fence_queue);
30666 handled = 1;
30667 }
30668@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30669 * using fences.
30670 */
30671 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30672- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30673+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30674 - *sequence) <= (1 << 23)));
30675
30676 *sequence = cur_fence;
30677diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30678index 0be4a81..7464804 100644
30679--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30680+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30681@@ -5329,7 +5329,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30682 struct bit_table {
30683 const char id;
30684 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30685-};
30686+} __no_const;
30687
30688 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30689
30690diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30691index 3aef353..0ad1322 100644
30692--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30693+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30694@@ -240,7 +240,7 @@ struct nouveau_channel {
30695 struct list_head pending;
30696 uint32_t sequence;
30697 uint32_t sequence_ack;
30698- atomic_t last_sequence_irq;
30699+ atomic_unchecked_t last_sequence_irq;
30700 struct nouveau_vma vma;
30701 } fence;
30702
30703@@ -321,7 +321,7 @@ struct nouveau_exec_engine {
30704 u32 handle, u16 class);
30705 void (*set_tile_region)(struct drm_device *dev, int i);
30706 void (*tlb_flush)(struct drm_device *, int engine);
30707-};
30708+} __no_const;
30709
30710 struct nouveau_instmem_engine {
30711 void *priv;
30712@@ -343,13 +343,13 @@ struct nouveau_instmem_engine {
30713 struct nouveau_mc_engine {
30714 int (*init)(struct drm_device *dev);
30715 void (*takedown)(struct drm_device *dev);
30716-};
30717+} __no_const;
30718
30719 struct nouveau_timer_engine {
30720 int (*init)(struct drm_device *dev);
30721 void (*takedown)(struct drm_device *dev);
30722 uint64_t (*read)(struct drm_device *dev);
30723-};
30724+} __no_const;
30725
30726 struct nouveau_fb_engine {
30727 int num_tiles;
30728@@ -590,7 +590,7 @@ struct nouveau_vram_engine {
30729 void (*put)(struct drm_device *, struct nouveau_mem **);
30730
30731 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30732-};
30733+} __no_const;
30734
30735 struct nouveau_engine {
30736 struct nouveau_instmem_engine instmem;
30737@@ -739,7 +739,7 @@ struct drm_nouveau_private {
30738 struct drm_global_reference mem_global_ref;
30739 struct ttm_bo_global_ref bo_global_ref;
30740 struct ttm_bo_device bdev;
30741- atomic_t validate_sequence;
30742+ atomic_unchecked_t validate_sequence;
30743 } ttm;
30744
30745 struct {
30746diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30747index c1dc20f..4df673c 100644
30748--- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30749+++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30750@@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30751 if (USE_REFCNT(dev))
30752 sequence = nvchan_rd32(chan, 0x48);
30753 else
30754- sequence = atomic_read(&chan->fence.last_sequence_irq);
30755+ sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30756
30757 if (chan->fence.sequence_ack == sequence)
30758 goto out;
30759@@ -538,7 +538,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30760 return ret;
30761 }
30762
30763- atomic_set(&chan->fence.last_sequence_irq, 0);
30764+ atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30765 return 0;
30766 }
30767
30768diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30769index ed52a6f..484acdc 100644
30770--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30771+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30772@@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30773 int trycnt = 0;
30774 int ret, i;
30775
30776- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30777+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30778 retry:
30779 if (++trycnt > 100000) {
30780 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30781diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30782index c2a8511..4b996f9 100644
30783--- a/drivers/gpu/drm/nouveau/nouveau_state.c
30784+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30785@@ -588,7 +588,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30786 bool can_switch;
30787
30788 spin_lock(&dev->count_lock);
30789- can_switch = (dev->open_count == 0);
30790+ can_switch = (local_read(&dev->open_count) == 0);
30791 spin_unlock(&dev->count_lock);
30792 return can_switch;
30793 }
30794diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30795index dbdea8e..cd6eeeb 100644
30796--- a/drivers/gpu/drm/nouveau/nv04_graph.c
30797+++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30798@@ -554,7 +554,7 @@ static int
30799 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30800 u32 class, u32 mthd, u32 data)
30801 {
30802- atomic_set(&chan->fence.last_sequence_irq, data);
30803+ atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30804 return 0;
30805 }
30806
30807diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30808index 2746402..c8dc4a4 100644
30809--- a/drivers/gpu/drm/nouveau/nv50_sor.c
30810+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30811@@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30812 }
30813
30814 if (nv_encoder->dcb->type == OUTPUT_DP) {
30815- struct dp_train_func func = {
30816+ static struct dp_train_func func = {
30817 .link_set = nv50_sor_dp_link_set,
30818 .train_set = nv50_sor_dp_train_set,
30819 .train_adj = nv50_sor_dp_train_adj
30820diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30821index 0247250..d2f6aaf 100644
30822--- a/drivers/gpu/drm/nouveau/nvd0_display.c
30823+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30824@@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30825 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30826
30827 if (nv_encoder->dcb->type == OUTPUT_DP) {
30828- struct dp_train_func func = {
30829+ static struct dp_train_func func = {
30830 .link_set = nvd0_sor_dp_link_set,
30831 .train_set = nvd0_sor_dp_train_set,
30832 .train_adj = nvd0_sor_dp_train_adj
30833diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30834index bcac90b..53bfc76 100644
30835--- a/drivers/gpu/drm/r128/r128_cce.c
30836+++ b/drivers/gpu/drm/r128/r128_cce.c
30837@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30838
30839 /* GH: Simple idle check.
30840 */
30841- atomic_set(&dev_priv->idle_count, 0);
30842+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30843
30844 /* We don't support anything other than bus-mastering ring mode,
30845 * but the ring can be in either AGP or PCI space for the ring
30846diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30847index 930c71b..499aded 100644
30848--- a/drivers/gpu/drm/r128/r128_drv.h
30849+++ b/drivers/gpu/drm/r128/r128_drv.h
30850@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30851 int is_pci;
30852 unsigned long cce_buffers_offset;
30853
30854- atomic_t idle_count;
30855+ atomic_unchecked_t idle_count;
30856
30857 int page_flipping;
30858 int current_page;
30859 u32 crtc_offset;
30860 u32 crtc_offset_cntl;
30861
30862- atomic_t vbl_received;
30863+ atomic_unchecked_t vbl_received;
30864
30865 u32 color_fmt;
30866 unsigned int front_offset;
30867diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30868index 429d5a0..7e899ed 100644
30869--- a/drivers/gpu/drm/r128/r128_irq.c
30870+++ b/drivers/gpu/drm/r128/r128_irq.c
30871@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30872 if (crtc != 0)
30873 return 0;
30874
30875- return atomic_read(&dev_priv->vbl_received);
30876+ return atomic_read_unchecked(&dev_priv->vbl_received);
30877 }
30878
30879 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30880@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30881 /* VBLANK interrupt */
30882 if (status & R128_CRTC_VBLANK_INT) {
30883 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30884- atomic_inc(&dev_priv->vbl_received);
30885+ atomic_inc_unchecked(&dev_priv->vbl_received);
30886 drm_handle_vblank(dev, 0);
30887 return IRQ_HANDLED;
30888 }
30889diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30890index a9e33ce..09edd4b 100644
30891--- a/drivers/gpu/drm/r128/r128_state.c
30892+++ b/drivers/gpu/drm/r128/r128_state.c
30893@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30894
30895 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30896 {
30897- if (atomic_read(&dev_priv->idle_count) == 0)
30898+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30899 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30900 else
30901- atomic_set(&dev_priv->idle_count, 0);
30902+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30903 }
30904
30905 #endif
30906diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30907index 5a82b6b..9e69c73 100644
30908--- a/drivers/gpu/drm/radeon/mkregtable.c
30909+++ b/drivers/gpu/drm/radeon/mkregtable.c
30910@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30911 regex_t mask_rex;
30912 regmatch_t match[4];
30913 char buf[1024];
30914- size_t end;
30915+ long end;
30916 int len;
30917 int done = 0;
30918 int r;
30919 unsigned o;
30920 struct offset *offset;
30921 char last_reg_s[10];
30922- int last_reg;
30923+ unsigned long last_reg;
30924
30925 if (regcomp
30926 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30927diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30928index 138b952..d74f9cb 100644
30929--- a/drivers/gpu/drm/radeon/radeon.h
30930+++ b/drivers/gpu/drm/radeon/radeon.h
30931@@ -253,7 +253,7 @@ struct radeon_fence_driver {
30932 uint32_t scratch_reg;
30933 uint64_t gpu_addr;
30934 volatile uint32_t *cpu_addr;
30935- atomic_t seq;
30936+ atomic_unchecked_t seq;
30937 uint32_t last_seq;
30938 unsigned long last_jiffies;
30939 unsigned long last_timeout;
30940@@ -753,7 +753,7 @@ struct r600_blit_cp_primitives {
30941 int x2, int y2);
30942 void (*draw_auto)(struct radeon_device *rdev);
30943 void (*set_default_state)(struct radeon_device *rdev);
30944-};
30945+} __no_const;
30946
30947 struct r600_blit {
30948 struct mutex mutex;
30949@@ -1246,7 +1246,7 @@ struct radeon_asic {
30950 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30951 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30952 } pflip;
30953-};
30954+} __no_const;
30955
30956 /*
30957 * Asic structures
30958diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30959index 5992502..c19c633 100644
30960--- a/drivers/gpu/drm/radeon/radeon_device.c
30961+++ b/drivers/gpu/drm/radeon/radeon_device.c
30962@@ -691,7 +691,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30963 bool can_switch;
30964
30965 spin_lock(&dev->count_lock);
30966- can_switch = (dev->open_count == 0);
30967+ can_switch = (local_read(&dev->open_count) == 0);
30968 spin_unlock(&dev->count_lock);
30969 return can_switch;
30970 }
30971diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30972index a1b59ca..86f2d44 100644
30973--- a/drivers/gpu/drm/radeon/radeon_drv.h
30974+++ b/drivers/gpu/drm/radeon/radeon_drv.h
30975@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30976
30977 /* SW interrupt */
30978 wait_queue_head_t swi_queue;
30979- atomic_t swi_emitted;
30980+ atomic_unchecked_t swi_emitted;
30981 int vblank_crtc;
30982 uint32_t irq_enable_reg;
30983 uint32_t r500_disp_irq_reg;
30984diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
30985index 4bd36a3..e66fe9c 100644
30986--- a/drivers/gpu/drm/radeon/radeon_fence.c
30987+++ b/drivers/gpu/drm/radeon/radeon_fence.c
30988@@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
30989 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
30990 return 0;
30991 }
30992- fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
30993+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
30994 if (!rdev->ring[fence->ring].ready)
30995 /* FIXME: cp is not running assume everythings is done right
30996 * away
30997@@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
30998 }
30999 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
31000 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
31001- radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
31002+ radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
31003 rdev->fence_drv[ring].initialized = true;
31004 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
31005 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
31006@@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
31007 rdev->fence_drv[ring].scratch_reg = -1;
31008 rdev->fence_drv[ring].cpu_addr = NULL;
31009 rdev->fence_drv[ring].gpu_addr = 0;
31010- atomic_set(&rdev->fence_drv[ring].seq, 0);
31011+ atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
31012 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
31013 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
31014 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
31015diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31016index 48b7cea..342236f 100644
31017--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31018+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31019@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31020 request = compat_alloc_user_space(sizeof(*request));
31021 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31022 || __put_user(req32.param, &request->param)
31023- || __put_user((void __user *)(unsigned long)req32.value,
31024+ || __put_user((unsigned long)req32.value,
31025 &request->value))
31026 return -EFAULT;
31027
31028diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31029index 00da384..32f972d 100644
31030--- a/drivers/gpu/drm/radeon/radeon_irq.c
31031+++ b/drivers/gpu/drm/radeon/radeon_irq.c
31032@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31033 unsigned int ret;
31034 RING_LOCALS;
31035
31036- atomic_inc(&dev_priv->swi_emitted);
31037- ret = atomic_read(&dev_priv->swi_emitted);
31038+ atomic_inc_unchecked(&dev_priv->swi_emitted);
31039+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31040
31041 BEGIN_RING(4);
31042 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31043@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31044 drm_radeon_private_t *dev_priv =
31045 (drm_radeon_private_t *) dev->dev_private;
31046
31047- atomic_set(&dev_priv->swi_emitted, 0);
31048+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31049 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31050
31051 dev->max_vblank_count = 0x001fffff;
31052diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31053index e8422ae..d22d4a8 100644
31054--- a/drivers/gpu/drm/radeon/radeon_state.c
31055+++ b/drivers/gpu/drm/radeon/radeon_state.c
31056@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31057 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31058 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31059
31060- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31061+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31062 sarea_priv->nbox * sizeof(depth_boxes[0])))
31063 return -EFAULT;
31064
31065@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31066 {
31067 drm_radeon_private_t *dev_priv = dev->dev_private;
31068 drm_radeon_getparam_t *param = data;
31069- int value;
31070+ int value = 0;
31071
31072 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31073
31074diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31075index f493c64..524ab6b 100644
31076--- a/drivers/gpu/drm/radeon/radeon_ttm.c
31077+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31078@@ -843,8 +843,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31079 }
31080 if (unlikely(ttm_vm_ops == NULL)) {
31081 ttm_vm_ops = vma->vm_ops;
31082- radeon_ttm_vm_ops = *ttm_vm_ops;
31083- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31084+ pax_open_kernel();
31085+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31086+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31087+ pax_close_kernel();
31088 }
31089 vma->vm_ops = &radeon_ttm_vm_ops;
31090 return 0;
31091diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31092index f2c3b9d..d5a376b 100644
31093--- a/drivers/gpu/drm/radeon/rs690.c
31094+++ b/drivers/gpu/drm/radeon/rs690.c
31095@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31096 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31097 rdev->pm.sideport_bandwidth.full)
31098 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31099- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31100+ read_delay_latency.full = dfixed_const(800 * 1000);
31101 read_delay_latency.full = dfixed_div(read_delay_latency,
31102 rdev->pm.igp_sideport_mclk);
31103+ a.full = dfixed_const(370);
31104+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31105 } else {
31106 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31107 rdev->pm.k8_bandwidth.full)
31108diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31109index ebc6fac..a8313ed 100644
31110--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31111+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31112@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31113 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31114 struct shrink_control *sc)
31115 {
31116- static atomic_t start_pool = ATOMIC_INIT(0);
31117+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31118 unsigned i;
31119- unsigned pool_offset = atomic_add_return(1, &start_pool);
31120+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31121 struct ttm_page_pool *pool;
31122 int shrink_pages = sc->nr_to_scan;
31123
31124diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31125index 88edacc..1e5412b 100644
31126--- a/drivers/gpu/drm/via/via_drv.h
31127+++ b/drivers/gpu/drm/via/via_drv.h
31128@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31129 typedef uint32_t maskarray_t[5];
31130
31131 typedef struct drm_via_irq {
31132- atomic_t irq_received;
31133+ atomic_unchecked_t irq_received;
31134 uint32_t pending_mask;
31135 uint32_t enable_mask;
31136 wait_queue_head_t irq_queue;
31137@@ -75,7 +75,7 @@ typedef struct drm_via_private {
31138 struct timeval last_vblank;
31139 int last_vblank_valid;
31140 unsigned usec_per_vblank;
31141- atomic_t vbl_received;
31142+ atomic_unchecked_t vbl_received;
31143 drm_via_state_t hc_state;
31144 char pci_buf[VIA_PCI_BUF_SIZE];
31145 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31146diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31147index d391f48..10c8ca3 100644
31148--- a/drivers/gpu/drm/via/via_irq.c
31149+++ b/drivers/gpu/drm/via/via_irq.c
31150@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31151 if (crtc != 0)
31152 return 0;
31153
31154- return atomic_read(&dev_priv->vbl_received);
31155+ return atomic_read_unchecked(&dev_priv->vbl_received);
31156 }
31157
31158 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31159@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31160
31161 status = VIA_READ(VIA_REG_INTERRUPT);
31162 if (status & VIA_IRQ_VBLANK_PENDING) {
31163- atomic_inc(&dev_priv->vbl_received);
31164- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31165+ atomic_inc_unchecked(&dev_priv->vbl_received);
31166+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31167 do_gettimeofday(&cur_vblank);
31168 if (dev_priv->last_vblank_valid) {
31169 dev_priv->usec_per_vblank =
31170@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31171 dev_priv->last_vblank = cur_vblank;
31172 dev_priv->last_vblank_valid = 1;
31173 }
31174- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31175+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31176 DRM_DEBUG("US per vblank is: %u\n",
31177 dev_priv->usec_per_vblank);
31178 }
31179@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31180
31181 for (i = 0; i < dev_priv->num_irqs; ++i) {
31182 if (status & cur_irq->pending_mask) {
31183- atomic_inc(&cur_irq->irq_received);
31184+ atomic_inc_unchecked(&cur_irq->irq_received);
31185 DRM_WAKEUP(&cur_irq->irq_queue);
31186 handled = 1;
31187 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31188@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31189 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31190 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31191 masks[irq][4]));
31192- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31193+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31194 } else {
31195 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31196 (((cur_irq_sequence =
31197- atomic_read(&cur_irq->irq_received)) -
31198+ atomic_read_unchecked(&cur_irq->irq_received)) -
31199 *sequence) <= (1 << 23)));
31200 }
31201 *sequence = cur_irq_sequence;
31202@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31203 }
31204
31205 for (i = 0; i < dev_priv->num_irqs; ++i) {
31206- atomic_set(&cur_irq->irq_received, 0);
31207+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31208 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31209 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31210 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31211@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31212 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31213 case VIA_IRQ_RELATIVE:
31214 irqwait->request.sequence +=
31215- atomic_read(&cur_irq->irq_received);
31216+ atomic_read_unchecked(&cur_irq->irq_received);
31217 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31218 case VIA_IRQ_ABSOLUTE:
31219 break;
31220diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31221index d0f2c07..9ebd9c3 100644
31222--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31223+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31224@@ -263,7 +263,7 @@ struct vmw_private {
31225 * Fencing and IRQs.
31226 */
31227
31228- atomic_t marker_seq;
31229+ atomic_unchecked_t marker_seq;
31230 wait_queue_head_t fence_queue;
31231 wait_queue_head_t fifo_queue;
31232 int fence_queue_waiters; /* Protected by hw_mutex */
31233diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31234index a0c2f12..68ae6cb 100644
31235--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31236+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31237@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31238 (unsigned int) min,
31239 (unsigned int) fifo->capabilities);
31240
31241- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31242+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31243 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31244 vmw_marker_queue_init(&fifo->marker_queue);
31245 return vmw_fifo_send_fence(dev_priv, &dummy);
31246@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31247 if (reserveable)
31248 iowrite32(bytes, fifo_mem +
31249 SVGA_FIFO_RESERVED);
31250- return fifo_mem + (next_cmd >> 2);
31251+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31252 } else {
31253 need_bounce = true;
31254 }
31255@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31256
31257 fm = vmw_fifo_reserve(dev_priv, bytes);
31258 if (unlikely(fm == NULL)) {
31259- *seqno = atomic_read(&dev_priv->marker_seq);
31260+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31261 ret = -ENOMEM;
31262 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31263 false, 3*HZ);
31264@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31265 }
31266
31267 do {
31268- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31269+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31270 } while (*seqno == 0);
31271
31272 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31273diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31274index cabc95f..14b3d77 100644
31275--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31276+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31277@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31278 * emitted. Then the fence is stale and signaled.
31279 */
31280
31281- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31282+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31283 > VMW_FENCE_WRAP);
31284
31285 return ret;
31286@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31287
31288 if (fifo_idle)
31289 down_read(&fifo_state->rwsem);
31290- signal_seq = atomic_read(&dev_priv->marker_seq);
31291+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31292 ret = 0;
31293
31294 for (;;) {
31295diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31296index 8a8725c..afed796 100644
31297--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31298+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31299@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31300 while (!vmw_lag_lt(queue, us)) {
31301 spin_lock(&queue->lock);
31302 if (list_empty(&queue->head))
31303- seqno = atomic_read(&dev_priv->marker_seq);
31304+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31305 else {
31306 marker = list_first_entry(&queue->head,
31307 struct vmw_marker, head);
31308diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31309index 973c238..981f5ed 100644
31310--- a/drivers/hid/hid-core.c
31311+++ b/drivers/hid/hid-core.c
31312@@ -2071,7 +2071,7 @@ static bool hid_ignore(struct hid_device *hdev)
31313
31314 int hid_add_device(struct hid_device *hdev)
31315 {
31316- static atomic_t id = ATOMIC_INIT(0);
31317+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31318 int ret;
31319
31320 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31321@@ -2086,7 +2086,7 @@ int hid_add_device(struct hid_device *hdev)
31322 /* XXX hack, any other cleaner solution after the driver core
31323 * is converted to allow more than 20 bytes as the device name? */
31324 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31325- hdev->vendor, hdev->product, atomic_inc_return(&id));
31326+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31327
31328 hid_debug_register(hdev, dev_name(&hdev->dev));
31329 ret = device_add(&hdev->dev);
31330diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31331index eec3291..8ed706b 100644
31332--- a/drivers/hid/hid-wiimote-debug.c
31333+++ b/drivers/hid/hid-wiimote-debug.c
31334@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31335 else if (size == 0)
31336 return -EIO;
31337
31338- if (copy_to_user(u, buf, size))
31339+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
31340 return -EFAULT;
31341
31342 *off += size;
31343diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31344index b1ec0e2..c295a61 100644
31345--- a/drivers/hid/usbhid/hiddev.c
31346+++ b/drivers/hid/usbhid/hiddev.c
31347@@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31348 break;
31349
31350 case HIDIOCAPPLICATION:
31351- if (arg < 0 || arg >= hid->maxapplication)
31352+ if (arg >= hid->maxapplication)
31353 break;
31354
31355 for (i = 0; i < hid->maxcollection; i++)
31356diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31357index 4065374..10ed7dc 100644
31358--- a/drivers/hv/channel.c
31359+++ b/drivers/hv/channel.c
31360@@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31361 int ret = 0;
31362 int t;
31363
31364- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31365- atomic_inc(&vmbus_connection.next_gpadl_handle);
31366+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31367+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31368
31369 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31370 if (ret)
31371diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31372index 15956bd..ea34398 100644
31373--- a/drivers/hv/hv.c
31374+++ b/drivers/hv/hv.c
31375@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31376 u64 output_address = (output) ? virt_to_phys(output) : 0;
31377 u32 output_address_hi = output_address >> 32;
31378 u32 output_address_lo = output_address & 0xFFFFFFFF;
31379- void *hypercall_page = hv_context.hypercall_page;
31380+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31381
31382 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31383 "=a"(hv_status_lo) : "d" (control_hi),
31384diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31385index 699f0d8..f4f19250 100644
31386--- a/drivers/hv/hyperv_vmbus.h
31387+++ b/drivers/hv/hyperv_vmbus.h
31388@@ -555,7 +555,7 @@ enum vmbus_connect_state {
31389 struct vmbus_connection {
31390 enum vmbus_connect_state conn_state;
31391
31392- atomic_t next_gpadl_handle;
31393+ atomic_unchecked_t next_gpadl_handle;
31394
31395 /*
31396 * Represents channel interrupts. Each bit position represents a
31397diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31398index a220e57..428f54d 100644
31399--- a/drivers/hv/vmbus_drv.c
31400+++ b/drivers/hv/vmbus_drv.c
31401@@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31402 {
31403 int ret = 0;
31404
31405- static atomic_t device_num = ATOMIC_INIT(0);
31406+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31407
31408 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31409- atomic_inc_return(&device_num));
31410+ atomic_inc_return_unchecked(&device_num));
31411
31412 child_device_obj->device.bus = &hv_bus;
31413 child_device_obj->device.parent = &hv_acpi_dev->dev;
31414diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31415index 9140236..ceaef4e 100644
31416--- a/drivers/hwmon/acpi_power_meter.c
31417+++ b/drivers/hwmon/acpi_power_meter.c
31418@@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31419 return res;
31420
31421 temp /= 1000;
31422- if (temp < 0)
31423- return -EINVAL;
31424
31425 mutex_lock(&resource->lock);
31426 resource->trip[attr->index - 7] = temp;
31427diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31428index 8b011d0..3de24a1 100644
31429--- a/drivers/hwmon/sht15.c
31430+++ b/drivers/hwmon/sht15.c
31431@@ -166,7 +166,7 @@ struct sht15_data {
31432 int supply_uV;
31433 bool supply_uV_valid;
31434 struct work_struct update_supply_work;
31435- atomic_t interrupt_handled;
31436+ atomic_unchecked_t interrupt_handled;
31437 };
31438
31439 /**
31440@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31441 return ret;
31442
31443 gpio_direction_input(data->pdata->gpio_data);
31444- atomic_set(&data->interrupt_handled, 0);
31445+ atomic_set_unchecked(&data->interrupt_handled, 0);
31446
31447 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31448 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31449 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31450 /* Only relevant if the interrupt hasn't occurred. */
31451- if (!atomic_read(&data->interrupt_handled))
31452+ if (!atomic_read_unchecked(&data->interrupt_handled))
31453 schedule_work(&data->read_work);
31454 }
31455 ret = wait_event_timeout(data->wait_queue,
31456@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31457
31458 /* First disable the interrupt */
31459 disable_irq_nosync(irq);
31460- atomic_inc(&data->interrupt_handled);
31461+ atomic_inc_unchecked(&data->interrupt_handled);
31462 /* Then schedule a reading work struct */
31463 if (data->state != SHT15_READING_NOTHING)
31464 schedule_work(&data->read_work);
31465@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31466 * If not, then start the interrupt again - care here as could
31467 * have gone low in meantime so verify it hasn't!
31468 */
31469- atomic_set(&data->interrupt_handled, 0);
31470+ atomic_set_unchecked(&data->interrupt_handled, 0);
31471 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31472 /* If still not occurred or another handler was scheduled */
31473 if (gpio_get_value(data->pdata->gpio_data)
31474- || atomic_read(&data->interrupt_handled))
31475+ || atomic_read_unchecked(&data->interrupt_handled))
31476 return;
31477 }
31478
31479diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31480index 378fcb5..5e91fa8 100644
31481--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31482+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31483@@ -43,7 +43,7 @@
31484 extern struct i2c_adapter amd756_smbus;
31485
31486 static struct i2c_adapter *s4882_adapter;
31487-static struct i2c_algorithm *s4882_algo;
31488+static i2c_algorithm_no_const *s4882_algo;
31489
31490 /* Wrapper access functions for multiplexed SMBus */
31491 static DEFINE_MUTEX(amd756_lock);
31492diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31493index 29015eb..af2d8e9 100644
31494--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31495+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31496@@ -41,7 +41,7 @@
31497 extern struct i2c_adapter *nforce2_smbus;
31498
31499 static struct i2c_adapter *s4985_adapter;
31500-static struct i2c_algorithm *s4985_algo;
31501+static i2c_algorithm_no_const *s4985_algo;
31502
31503 /* Wrapper access functions for multiplexed SMBus */
31504 static DEFINE_MUTEX(nforce2_lock);
31505diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31506index d7a4833..7fae376 100644
31507--- a/drivers/i2c/i2c-mux.c
31508+++ b/drivers/i2c/i2c-mux.c
31509@@ -28,7 +28,7 @@
31510 /* multiplexer per channel data */
31511 struct i2c_mux_priv {
31512 struct i2c_adapter adap;
31513- struct i2c_algorithm algo;
31514+ i2c_algorithm_no_const algo;
31515
31516 struct i2c_adapter *parent;
31517 void *mux_dev; /* the mux chip/device */
31518diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31519index 57d00ca..0145194 100644
31520--- a/drivers/ide/aec62xx.c
31521+++ b/drivers/ide/aec62xx.c
31522@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31523 .cable_detect = atp86x_cable_detect,
31524 };
31525
31526-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31527+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31528 { /* 0: AEC6210 */
31529 .name = DRV_NAME,
31530 .init_chipset = init_chipset_aec62xx,
31531diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31532index 2c8016a..911a27c 100644
31533--- a/drivers/ide/alim15x3.c
31534+++ b/drivers/ide/alim15x3.c
31535@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31536 .dma_sff_read_status = ide_dma_sff_read_status,
31537 };
31538
31539-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31540+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31541 .name = DRV_NAME,
31542 .init_chipset = init_chipset_ali15x3,
31543 .init_hwif = init_hwif_ali15x3,
31544diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31545index 3747b25..56fc995 100644
31546--- a/drivers/ide/amd74xx.c
31547+++ b/drivers/ide/amd74xx.c
31548@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31549 .udma_mask = udma, \
31550 }
31551
31552-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31553+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31554 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31555 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31556 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31557diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31558index 15f0ead..cb43480 100644
31559--- a/drivers/ide/atiixp.c
31560+++ b/drivers/ide/atiixp.c
31561@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31562 .cable_detect = atiixp_cable_detect,
31563 };
31564
31565-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31566+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31567 { /* 0: IXP200/300/400/700 */
31568 .name = DRV_NAME,
31569 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31570diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31571index 5f80312..d1fc438 100644
31572--- a/drivers/ide/cmd64x.c
31573+++ b/drivers/ide/cmd64x.c
31574@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31575 .dma_sff_read_status = ide_dma_sff_read_status,
31576 };
31577
31578-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31579+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31580 { /* 0: CMD643 */
31581 .name = DRV_NAME,
31582 .init_chipset = init_chipset_cmd64x,
31583diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31584index 2c1e5f7..1444762 100644
31585--- a/drivers/ide/cs5520.c
31586+++ b/drivers/ide/cs5520.c
31587@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31588 .set_dma_mode = cs5520_set_dma_mode,
31589 };
31590
31591-static const struct ide_port_info cyrix_chipset __devinitdata = {
31592+static const struct ide_port_info cyrix_chipset __devinitconst = {
31593 .name = DRV_NAME,
31594 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31595 .port_ops = &cs5520_port_ops,
31596diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31597index 4dc4eb9..49b40ad 100644
31598--- a/drivers/ide/cs5530.c
31599+++ b/drivers/ide/cs5530.c
31600@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31601 .udma_filter = cs5530_udma_filter,
31602 };
31603
31604-static const struct ide_port_info cs5530_chipset __devinitdata = {
31605+static const struct ide_port_info cs5530_chipset __devinitconst = {
31606 .name = DRV_NAME,
31607 .init_chipset = init_chipset_cs5530,
31608 .init_hwif = init_hwif_cs5530,
31609diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31610index 5059faf..18d4c85 100644
31611--- a/drivers/ide/cs5535.c
31612+++ b/drivers/ide/cs5535.c
31613@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31614 .cable_detect = cs5535_cable_detect,
31615 };
31616
31617-static const struct ide_port_info cs5535_chipset __devinitdata = {
31618+static const struct ide_port_info cs5535_chipset __devinitconst = {
31619 .name = DRV_NAME,
31620 .port_ops = &cs5535_port_ops,
31621 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31622diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31623index 847553f..3ffb49d 100644
31624--- a/drivers/ide/cy82c693.c
31625+++ b/drivers/ide/cy82c693.c
31626@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31627 .set_dma_mode = cy82c693_set_dma_mode,
31628 };
31629
31630-static const struct ide_port_info cy82c693_chipset __devinitdata = {
31631+static const struct ide_port_info cy82c693_chipset __devinitconst = {
31632 .name = DRV_NAME,
31633 .init_iops = init_iops_cy82c693,
31634 .port_ops = &cy82c693_port_ops,
31635diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31636index 58c51cd..4aec3b8 100644
31637--- a/drivers/ide/hpt366.c
31638+++ b/drivers/ide/hpt366.c
31639@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31640 }
31641 };
31642
31643-static const struct hpt_info hpt36x __devinitdata = {
31644+static const struct hpt_info hpt36x __devinitconst = {
31645 .chip_name = "HPT36x",
31646 .chip_type = HPT36x,
31647 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31648@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31649 .timings = &hpt36x_timings
31650 };
31651
31652-static const struct hpt_info hpt370 __devinitdata = {
31653+static const struct hpt_info hpt370 __devinitconst = {
31654 .chip_name = "HPT370",
31655 .chip_type = HPT370,
31656 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31657@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31658 .timings = &hpt37x_timings
31659 };
31660
31661-static const struct hpt_info hpt370a __devinitdata = {
31662+static const struct hpt_info hpt370a __devinitconst = {
31663 .chip_name = "HPT370A",
31664 .chip_type = HPT370A,
31665 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31666@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31667 .timings = &hpt37x_timings
31668 };
31669
31670-static const struct hpt_info hpt374 __devinitdata = {
31671+static const struct hpt_info hpt374 __devinitconst = {
31672 .chip_name = "HPT374",
31673 .chip_type = HPT374,
31674 .udma_mask = ATA_UDMA5,
31675@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31676 .timings = &hpt37x_timings
31677 };
31678
31679-static const struct hpt_info hpt372 __devinitdata = {
31680+static const struct hpt_info hpt372 __devinitconst = {
31681 .chip_name = "HPT372",
31682 .chip_type = HPT372,
31683 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31684@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31685 .timings = &hpt37x_timings
31686 };
31687
31688-static const struct hpt_info hpt372a __devinitdata = {
31689+static const struct hpt_info hpt372a __devinitconst = {
31690 .chip_name = "HPT372A",
31691 .chip_type = HPT372A,
31692 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31693@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31694 .timings = &hpt37x_timings
31695 };
31696
31697-static const struct hpt_info hpt302 __devinitdata = {
31698+static const struct hpt_info hpt302 __devinitconst = {
31699 .chip_name = "HPT302",
31700 .chip_type = HPT302,
31701 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31702@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31703 .timings = &hpt37x_timings
31704 };
31705
31706-static const struct hpt_info hpt371 __devinitdata = {
31707+static const struct hpt_info hpt371 __devinitconst = {
31708 .chip_name = "HPT371",
31709 .chip_type = HPT371,
31710 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31711@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31712 .timings = &hpt37x_timings
31713 };
31714
31715-static const struct hpt_info hpt372n __devinitdata = {
31716+static const struct hpt_info hpt372n __devinitconst = {
31717 .chip_name = "HPT372N",
31718 .chip_type = HPT372N,
31719 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31720@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31721 .timings = &hpt37x_timings
31722 };
31723
31724-static const struct hpt_info hpt302n __devinitdata = {
31725+static const struct hpt_info hpt302n __devinitconst = {
31726 .chip_name = "HPT302N",
31727 .chip_type = HPT302N,
31728 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31729@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31730 .timings = &hpt37x_timings
31731 };
31732
31733-static const struct hpt_info hpt371n __devinitdata = {
31734+static const struct hpt_info hpt371n __devinitconst = {
31735 .chip_name = "HPT371N",
31736 .chip_type = HPT371N,
31737 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31738@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31739 .dma_sff_read_status = ide_dma_sff_read_status,
31740 };
31741
31742-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31743+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31744 { /* 0: HPT36x */
31745 .name = DRV_NAME,
31746 .init_chipset = init_chipset_hpt366,
31747diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31748index 8126824..55a2798 100644
31749--- a/drivers/ide/ide-cd.c
31750+++ b/drivers/ide/ide-cd.c
31751@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31752 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31753 if ((unsigned long)buf & alignment
31754 || blk_rq_bytes(rq) & q->dma_pad_mask
31755- || object_is_on_stack(buf))
31756+ || object_starts_on_stack(buf))
31757 drive->dma = 0;
31758 }
31759 }
31760diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31761index 7f56b73..dab5b67 100644
31762--- a/drivers/ide/ide-pci-generic.c
31763+++ b/drivers/ide/ide-pci-generic.c
31764@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31765 .udma_mask = ATA_UDMA6, \
31766 }
31767
31768-static const struct ide_port_info generic_chipsets[] __devinitdata = {
31769+static const struct ide_port_info generic_chipsets[] __devinitconst = {
31770 /* 0: Unknown */
31771 DECLARE_GENERIC_PCI_DEV(0),
31772
31773diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31774index 560e66d..d5dd180 100644
31775--- a/drivers/ide/it8172.c
31776+++ b/drivers/ide/it8172.c
31777@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31778 .set_dma_mode = it8172_set_dma_mode,
31779 };
31780
31781-static const struct ide_port_info it8172_port_info __devinitdata = {
31782+static const struct ide_port_info it8172_port_info __devinitconst = {
31783 .name = DRV_NAME,
31784 .port_ops = &it8172_port_ops,
31785 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31786diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31787index 46816ba..1847aeb 100644
31788--- a/drivers/ide/it8213.c
31789+++ b/drivers/ide/it8213.c
31790@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31791 .cable_detect = it8213_cable_detect,
31792 };
31793
31794-static const struct ide_port_info it8213_chipset __devinitdata = {
31795+static const struct ide_port_info it8213_chipset __devinitconst = {
31796 .name = DRV_NAME,
31797 .enablebits = { {0x41, 0x80, 0x80} },
31798 .port_ops = &it8213_port_ops,
31799diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31800index 2e3169f..c5611db 100644
31801--- a/drivers/ide/it821x.c
31802+++ b/drivers/ide/it821x.c
31803@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31804 .cable_detect = it821x_cable_detect,
31805 };
31806
31807-static const struct ide_port_info it821x_chipset __devinitdata = {
31808+static const struct ide_port_info it821x_chipset __devinitconst = {
31809 .name = DRV_NAME,
31810 .init_chipset = init_chipset_it821x,
31811 .init_hwif = init_hwif_it821x,
31812diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31813index 74c2c4a..efddd7d 100644
31814--- a/drivers/ide/jmicron.c
31815+++ b/drivers/ide/jmicron.c
31816@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31817 .cable_detect = jmicron_cable_detect,
31818 };
31819
31820-static const struct ide_port_info jmicron_chipset __devinitdata = {
31821+static const struct ide_port_info jmicron_chipset __devinitconst = {
31822 .name = DRV_NAME,
31823 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31824 .port_ops = &jmicron_port_ops,
31825diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31826index 95327a2..73f78d8 100644
31827--- a/drivers/ide/ns87415.c
31828+++ b/drivers/ide/ns87415.c
31829@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31830 .dma_sff_read_status = superio_dma_sff_read_status,
31831 };
31832
31833-static const struct ide_port_info ns87415_chipset __devinitdata = {
31834+static const struct ide_port_info ns87415_chipset __devinitconst = {
31835 .name = DRV_NAME,
31836 .init_hwif = init_hwif_ns87415,
31837 .tp_ops = &ns87415_tp_ops,
31838diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31839index 1a53a4c..39edc66 100644
31840--- a/drivers/ide/opti621.c
31841+++ b/drivers/ide/opti621.c
31842@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31843 .set_pio_mode = opti621_set_pio_mode,
31844 };
31845
31846-static const struct ide_port_info opti621_chipset __devinitdata = {
31847+static const struct ide_port_info opti621_chipset __devinitconst = {
31848 .name = DRV_NAME,
31849 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31850 .port_ops = &opti621_port_ops,
31851diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31852index 9546fe2..2e5ceb6 100644
31853--- a/drivers/ide/pdc202xx_new.c
31854+++ b/drivers/ide/pdc202xx_new.c
31855@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31856 .udma_mask = udma, \
31857 }
31858
31859-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31860+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31861 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31862 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31863 };
31864diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31865index 3a35ec6..5634510 100644
31866--- a/drivers/ide/pdc202xx_old.c
31867+++ b/drivers/ide/pdc202xx_old.c
31868@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31869 .max_sectors = sectors, \
31870 }
31871
31872-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31873+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31874 { /* 0: PDC20246 */
31875 .name = DRV_NAME,
31876 .init_chipset = init_chipset_pdc202xx,
31877diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31878index 1892e81..fe0fd60 100644
31879--- a/drivers/ide/piix.c
31880+++ b/drivers/ide/piix.c
31881@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31882 .udma_mask = udma, \
31883 }
31884
31885-static const struct ide_port_info piix_pci_info[] __devinitdata = {
31886+static const struct ide_port_info piix_pci_info[] __devinitconst = {
31887 /* 0: MPIIX */
31888 { /*
31889 * MPIIX actually has only a single IDE channel mapped to
31890diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31891index a6414a8..c04173e 100644
31892--- a/drivers/ide/rz1000.c
31893+++ b/drivers/ide/rz1000.c
31894@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31895 }
31896 }
31897
31898-static const struct ide_port_info rz1000_chipset __devinitdata = {
31899+static const struct ide_port_info rz1000_chipset __devinitconst = {
31900 .name = DRV_NAME,
31901 .host_flags = IDE_HFLAG_NO_DMA,
31902 };
31903diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31904index 356b9b5..d4758eb 100644
31905--- a/drivers/ide/sc1200.c
31906+++ b/drivers/ide/sc1200.c
31907@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31908 .dma_sff_read_status = ide_dma_sff_read_status,
31909 };
31910
31911-static const struct ide_port_info sc1200_chipset __devinitdata = {
31912+static const struct ide_port_info sc1200_chipset __devinitconst = {
31913 .name = DRV_NAME,
31914 .port_ops = &sc1200_port_ops,
31915 .dma_ops = &sc1200_dma_ops,
31916diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31917index b7f5b0c..9701038 100644
31918--- a/drivers/ide/scc_pata.c
31919+++ b/drivers/ide/scc_pata.c
31920@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31921 .dma_sff_read_status = scc_dma_sff_read_status,
31922 };
31923
31924-static const struct ide_port_info scc_chipset __devinitdata = {
31925+static const struct ide_port_info scc_chipset __devinitconst = {
31926 .name = "sccIDE",
31927 .init_iops = init_iops_scc,
31928 .init_dma = scc_init_dma,
31929diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31930index 35fb8da..24d72ef 100644
31931--- a/drivers/ide/serverworks.c
31932+++ b/drivers/ide/serverworks.c
31933@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31934 .cable_detect = svwks_cable_detect,
31935 };
31936
31937-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31938+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31939 { /* 0: OSB4 */
31940 .name = DRV_NAME,
31941 .init_chipset = init_chipset_svwks,
31942diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31943index ddeda44..46f7e30 100644
31944--- a/drivers/ide/siimage.c
31945+++ b/drivers/ide/siimage.c
31946@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31947 .udma_mask = ATA_UDMA6, \
31948 }
31949
31950-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31951+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31952 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31953 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31954 };
31955diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31956index 4a00225..09e61b4 100644
31957--- a/drivers/ide/sis5513.c
31958+++ b/drivers/ide/sis5513.c
31959@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31960 .cable_detect = sis_cable_detect,
31961 };
31962
31963-static const struct ide_port_info sis5513_chipset __devinitdata = {
31964+static const struct ide_port_info sis5513_chipset __devinitconst = {
31965 .name = DRV_NAME,
31966 .init_chipset = init_chipset_sis5513,
31967 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31968diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31969index f21dc2a..d051cd2 100644
31970--- a/drivers/ide/sl82c105.c
31971+++ b/drivers/ide/sl82c105.c
31972@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31973 .dma_sff_read_status = ide_dma_sff_read_status,
31974 };
31975
31976-static const struct ide_port_info sl82c105_chipset __devinitdata = {
31977+static const struct ide_port_info sl82c105_chipset __devinitconst = {
31978 .name = DRV_NAME,
31979 .init_chipset = init_chipset_sl82c105,
31980 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31981diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31982index 864ffe0..863a5e9 100644
31983--- a/drivers/ide/slc90e66.c
31984+++ b/drivers/ide/slc90e66.c
31985@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31986 .cable_detect = slc90e66_cable_detect,
31987 };
31988
31989-static const struct ide_port_info slc90e66_chipset __devinitdata = {
31990+static const struct ide_port_info slc90e66_chipset __devinitconst = {
31991 .name = DRV_NAME,
31992 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31993 .port_ops = &slc90e66_port_ops,
31994diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31995index 4799d5c..1794678 100644
31996--- a/drivers/ide/tc86c001.c
31997+++ b/drivers/ide/tc86c001.c
31998@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31999 .dma_sff_read_status = ide_dma_sff_read_status,
32000 };
32001
32002-static const struct ide_port_info tc86c001_chipset __devinitdata = {
32003+static const struct ide_port_info tc86c001_chipset __devinitconst = {
32004 .name = DRV_NAME,
32005 .init_hwif = init_hwif_tc86c001,
32006 .port_ops = &tc86c001_port_ops,
32007diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32008index 281c914..55ce1b8 100644
32009--- a/drivers/ide/triflex.c
32010+++ b/drivers/ide/triflex.c
32011@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32012 .set_dma_mode = triflex_set_mode,
32013 };
32014
32015-static const struct ide_port_info triflex_device __devinitdata = {
32016+static const struct ide_port_info triflex_device __devinitconst = {
32017 .name = DRV_NAME,
32018 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32019 .port_ops = &triflex_port_ops,
32020diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32021index 4b42ca0..e494a98 100644
32022--- a/drivers/ide/trm290.c
32023+++ b/drivers/ide/trm290.c
32024@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32025 .dma_check = trm290_dma_check,
32026 };
32027
32028-static const struct ide_port_info trm290_chipset __devinitdata = {
32029+static const struct ide_port_info trm290_chipset __devinitconst = {
32030 .name = DRV_NAME,
32031 .init_hwif = init_hwif_trm290,
32032 .tp_ops = &trm290_tp_ops,
32033diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32034index f46f49c..eb77678 100644
32035--- a/drivers/ide/via82cxxx.c
32036+++ b/drivers/ide/via82cxxx.c
32037@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32038 .cable_detect = via82cxxx_cable_detect,
32039 };
32040
32041-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32042+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32043 .name = DRV_NAME,
32044 .init_chipset = init_chipset_via82cxxx,
32045 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32046diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32047index 73d4531..c90cd2d 100644
32048--- a/drivers/ieee802154/fakehard.c
32049+++ b/drivers/ieee802154/fakehard.c
32050@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32051 phy->transmit_power = 0xbf;
32052
32053 dev->netdev_ops = &fake_ops;
32054- dev->ml_priv = &fake_mlme;
32055+ dev->ml_priv = (void *)&fake_mlme;
32056
32057 priv = netdev_priv(dev);
32058 priv->phy = phy;
32059diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32060index c889aae..6cf5aa7 100644
32061--- a/drivers/infiniband/core/cm.c
32062+++ b/drivers/infiniband/core/cm.c
32063@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32064
32065 struct cm_counter_group {
32066 struct kobject obj;
32067- atomic_long_t counter[CM_ATTR_COUNT];
32068+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32069 };
32070
32071 struct cm_counter_attribute {
32072@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32073 struct ib_mad_send_buf *msg = NULL;
32074 int ret;
32075
32076- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32077+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32078 counter[CM_REQ_COUNTER]);
32079
32080 /* Quick state check to discard duplicate REQs. */
32081@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32082 if (!cm_id_priv)
32083 return;
32084
32085- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32086+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32087 counter[CM_REP_COUNTER]);
32088 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32089 if (ret)
32090@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32091 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32092 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32093 spin_unlock_irq(&cm_id_priv->lock);
32094- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32095+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32096 counter[CM_RTU_COUNTER]);
32097 goto out;
32098 }
32099@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32100 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32101 dreq_msg->local_comm_id);
32102 if (!cm_id_priv) {
32103- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32104+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32105 counter[CM_DREQ_COUNTER]);
32106 cm_issue_drep(work->port, work->mad_recv_wc);
32107 return -EINVAL;
32108@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32109 case IB_CM_MRA_REP_RCVD:
32110 break;
32111 case IB_CM_TIMEWAIT:
32112- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32113+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32114 counter[CM_DREQ_COUNTER]);
32115 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32116 goto unlock;
32117@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32118 cm_free_msg(msg);
32119 goto deref;
32120 case IB_CM_DREQ_RCVD:
32121- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32122+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32123 counter[CM_DREQ_COUNTER]);
32124 goto unlock;
32125 default:
32126@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32127 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32128 cm_id_priv->msg, timeout)) {
32129 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32130- atomic_long_inc(&work->port->
32131+ atomic_long_inc_unchecked(&work->port->
32132 counter_group[CM_RECV_DUPLICATES].
32133 counter[CM_MRA_COUNTER]);
32134 goto out;
32135@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32136 break;
32137 case IB_CM_MRA_REQ_RCVD:
32138 case IB_CM_MRA_REP_RCVD:
32139- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32140+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32141 counter[CM_MRA_COUNTER]);
32142 /* fall through */
32143 default:
32144@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32145 case IB_CM_LAP_IDLE:
32146 break;
32147 case IB_CM_MRA_LAP_SENT:
32148- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32149+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32150 counter[CM_LAP_COUNTER]);
32151 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32152 goto unlock;
32153@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32154 cm_free_msg(msg);
32155 goto deref;
32156 case IB_CM_LAP_RCVD:
32157- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32158+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32159 counter[CM_LAP_COUNTER]);
32160 goto unlock;
32161 default:
32162@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32163 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32164 if (cur_cm_id_priv) {
32165 spin_unlock_irq(&cm.lock);
32166- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32167+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32168 counter[CM_SIDR_REQ_COUNTER]);
32169 goto out; /* Duplicate message. */
32170 }
32171@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32172 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32173 msg->retries = 1;
32174
32175- atomic_long_add(1 + msg->retries,
32176+ atomic_long_add_unchecked(1 + msg->retries,
32177 &port->counter_group[CM_XMIT].counter[attr_index]);
32178 if (msg->retries)
32179- atomic_long_add(msg->retries,
32180+ atomic_long_add_unchecked(msg->retries,
32181 &port->counter_group[CM_XMIT_RETRIES].
32182 counter[attr_index]);
32183
32184@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32185 }
32186
32187 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32188- atomic_long_inc(&port->counter_group[CM_RECV].
32189+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32190 counter[attr_id - CM_ATTR_ID_OFFSET]);
32191
32192 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32193@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32194 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32195
32196 return sprintf(buf, "%ld\n",
32197- atomic_long_read(&group->counter[cm_attr->index]));
32198+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32199 }
32200
32201 static const struct sysfs_ops cm_counter_ops = {
32202diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32203index 176c8f9..2627b62 100644
32204--- a/drivers/infiniband/core/fmr_pool.c
32205+++ b/drivers/infiniband/core/fmr_pool.c
32206@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32207
32208 struct task_struct *thread;
32209
32210- atomic_t req_ser;
32211- atomic_t flush_ser;
32212+ atomic_unchecked_t req_ser;
32213+ atomic_unchecked_t flush_ser;
32214
32215 wait_queue_head_t force_wait;
32216 };
32217@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32218 struct ib_fmr_pool *pool = pool_ptr;
32219
32220 do {
32221- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32222+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32223 ib_fmr_batch_release(pool);
32224
32225- atomic_inc(&pool->flush_ser);
32226+ atomic_inc_unchecked(&pool->flush_ser);
32227 wake_up_interruptible(&pool->force_wait);
32228
32229 if (pool->flush_function)
32230@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32231 }
32232
32233 set_current_state(TASK_INTERRUPTIBLE);
32234- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32235+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32236 !kthread_should_stop())
32237 schedule();
32238 __set_current_state(TASK_RUNNING);
32239@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32240 pool->dirty_watermark = params->dirty_watermark;
32241 pool->dirty_len = 0;
32242 spin_lock_init(&pool->pool_lock);
32243- atomic_set(&pool->req_ser, 0);
32244- atomic_set(&pool->flush_ser, 0);
32245+ atomic_set_unchecked(&pool->req_ser, 0);
32246+ atomic_set_unchecked(&pool->flush_ser, 0);
32247 init_waitqueue_head(&pool->force_wait);
32248
32249 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32250@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32251 }
32252 spin_unlock_irq(&pool->pool_lock);
32253
32254- serial = atomic_inc_return(&pool->req_ser);
32255+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32256 wake_up_process(pool->thread);
32257
32258 if (wait_event_interruptible(pool->force_wait,
32259- atomic_read(&pool->flush_ser) - serial >= 0))
32260+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32261 return -EINTR;
32262
32263 return 0;
32264@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32265 } else {
32266 list_add_tail(&fmr->list, &pool->dirty_list);
32267 if (++pool->dirty_len >= pool->dirty_watermark) {
32268- atomic_inc(&pool->req_ser);
32269+ atomic_inc_unchecked(&pool->req_ser);
32270 wake_up_process(pool->thread);
32271 }
32272 }
32273diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32274index 40c8353..946b0e4 100644
32275--- a/drivers/infiniband/hw/cxgb4/mem.c
32276+++ b/drivers/infiniband/hw/cxgb4/mem.c
32277@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32278 int err;
32279 struct fw_ri_tpte tpt;
32280 u32 stag_idx;
32281- static atomic_t key;
32282+ static atomic_unchecked_t key;
32283
32284 if (c4iw_fatal_error(rdev))
32285 return -EIO;
32286@@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32287 &rdev->resource.tpt_fifo_lock);
32288 if (!stag_idx)
32289 return -ENOMEM;
32290- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32291+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32292 }
32293 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32294 __func__, stag_state, type, pdid, stag_idx);
32295diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32296index 79b3dbc..96e5fcc 100644
32297--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32298+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32299@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32300 struct ib_atomic_eth *ateth;
32301 struct ipath_ack_entry *e;
32302 u64 vaddr;
32303- atomic64_t *maddr;
32304+ atomic64_unchecked_t *maddr;
32305 u64 sdata;
32306 u32 rkey;
32307 u8 next;
32308@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32309 IB_ACCESS_REMOTE_ATOMIC)))
32310 goto nack_acc_unlck;
32311 /* Perform atomic OP and save result. */
32312- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32313+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32314 sdata = be64_to_cpu(ateth->swap_data);
32315 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32316 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32317- (u64) atomic64_add_return(sdata, maddr) - sdata :
32318+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32319 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32320 be64_to_cpu(ateth->compare_data),
32321 sdata);
32322diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32323index 1f95bba..9530f87 100644
32324--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32325+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32326@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32327 unsigned long flags;
32328 struct ib_wc wc;
32329 u64 sdata;
32330- atomic64_t *maddr;
32331+ atomic64_unchecked_t *maddr;
32332 enum ib_wc_status send_status;
32333
32334 /*
32335@@ -382,11 +382,11 @@ again:
32336 IB_ACCESS_REMOTE_ATOMIC)))
32337 goto acc_err;
32338 /* Perform atomic OP and save result. */
32339- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32340+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32341 sdata = wqe->wr.wr.atomic.compare_add;
32342 *(u64 *) sqp->s_sge.sge.vaddr =
32343 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32344- (u64) atomic64_add_return(sdata, maddr) - sdata :
32345+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32346 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32347 sdata, wqe->wr.wr.atomic.swap);
32348 goto send_comp;
32349diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32350index 7140199..da60063 100644
32351--- a/drivers/infiniband/hw/nes/nes.c
32352+++ b/drivers/infiniband/hw/nes/nes.c
32353@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32354 LIST_HEAD(nes_adapter_list);
32355 static LIST_HEAD(nes_dev_list);
32356
32357-atomic_t qps_destroyed;
32358+atomic_unchecked_t qps_destroyed;
32359
32360 static unsigned int ee_flsh_adapter;
32361 static unsigned int sysfs_nonidx_addr;
32362@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32363 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32364 struct nes_adapter *nesadapter = nesdev->nesadapter;
32365
32366- atomic_inc(&qps_destroyed);
32367+ atomic_inc_unchecked(&qps_destroyed);
32368
32369 /* Free the control structures */
32370
32371diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32372index c438e46..ca30356 100644
32373--- a/drivers/infiniband/hw/nes/nes.h
32374+++ b/drivers/infiniband/hw/nes/nes.h
32375@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32376 extern unsigned int wqm_quanta;
32377 extern struct list_head nes_adapter_list;
32378
32379-extern atomic_t cm_connects;
32380-extern atomic_t cm_accepts;
32381-extern atomic_t cm_disconnects;
32382-extern atomic_t cm_closes;
32383-extern atomic_t cm_connecteds;
32384-extern atomic_t cm_connect_reqs;
32385-extern atomic_t cm_rejects;
32386-extern atomic_t mod_qp_timouts;
32387-extern atomic_t qps_created;
32388-extern atomic_t qps_destroyed;
32389-extern atomic_t sw_qps_destroyed;
32390+extern atomic_unchecked_t cm_connects;
32391+extern atomic_unchecked_t cm_accepts;
32392+extern atomic_unchecked_t cm_disconnects;
32393+extern atomic_unchecked_t cm_closes;
32394+extern atomic_unchecked_t cm_connecteds;
32395+extern atomic_unchecked_t cm_connect_reqs;
32396+extern atomic_unchecked_t cm_rejects;
32397+extern atomic_unchecked_t mod_qp_timouts;
32398+extern atomic_unchecked_t qps_created;
32399+extern atomic_unchecked_t qps_destroyed;
32400+extern atomic_unchecked_t sw_qps_destroyed;
32401 extern u32 mh_detected;
32402 extern u32 mh_pauses_sent;
32403 extern u32 cm_packets_sent;
32404@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32405 extern u32 cm_packets_received;
32406 extern u32 cm_packets_dropped;
32407 extern u32 cm_packets_retrans;
32408-extern atomic_t cm_listens_created;
32409-extern atomic_t cm_listens_destroyed;
32410+extern atomic_unchecked_t cm_listens_created;
32411+extern atomic_unchecked_t cm_listens_destroyed;
32412 extern u32 cm_backlog_drops;
32413-extern atomic_t cm_loopbacks;
32414-extern atomic_t cm_nodes_created;
32415-extern atomic_t cm_nodes_destroyed;
32416-extern atomic_t cm_accel_dropped_pkts;
32417-extern atomic_t cm_resets_recvd;
32418-extern atomic_t pau_qps_created;
32419-extern atomic_t pau_qps_destroyed;
32420+extern atomic_unchecked_t cm_loopbacks;
32421+extern atomic_unchecked_t cm_nodes_created;
32422+extern atomic_unchecked_t cm_nodes_destroyed;
32423+extern atomic_unchecked_t cm_accel_dropped_pkts;
32424+extern atomic_unchecked_t cm_resets_recvd;
32425+extern atomic_unchecked_t pau_qps_created;
32426+extern atomic_unchecked_t pau_qps_destroyed;
32427
32428 extern u32 int_mod_timer_init;
32429 extern u32 int_mod_cq_depth_256;
32430diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32431index 71edfbb..15b62ae 100644
32432--- a/drivers/infiniband/hw/nes/nes_cm.c
32433+++ b/drivers/infiniband/hw/nes/nes_cm.c
32434@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32435 u32 cm_packets_retrans;
32436 u32 cm_packets_created;
32437 u32 cm_packets_received;
32438-atomic_t cm_listens_created;
32439-atomic_t cm_listens_destroyed;
32440+atomic_unchecked_t cm_listens_created;
32441+atomic_unchecked_t cm_listens_destroyed;
32442 u32 cm_backlog_drops;
32443-atomic_t cm_loopbacks;
32444-atomic_t cm_nodes_created;
32445-atomic_t cm_nodes_destroyed;
32446-atomic_t cm_accel_dropped_pkts;
32447-atomic_t cm_resets_recvd;
32448+atomic_unchecked_t cm_loopbacks;
32449+atomic_unchecked_t cm_nodes_created;
32450+atomic_unchecked_t cm_nodes_destroyed;
32451+atomic_unchecked_t cm_accel_dropped_pkts;
32452+atomic_unchecked_t cm_resets_recvd;
32453
32454 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32455 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32456@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32457
32458 static struct nes_cm_core *g_cm_core;
32459
32460-atomic_t cm_connects;
32461-atomic_t cm_accepts;
32462-atomic_t cm_disconnects;
32463-atomic_t cm_closes;
32464-atomic_t cm_connecteds;
32465-atomic_t cm_connect_reqs;
32466-atomic_t cm_rejects;
32467+atomic_unchecked_t cm_connects;
32468+atomic_unchecked_t cm_accepts;
32469+atomic_unchecked_t cm_disconnects;
32470+atomic_unchecked_t cm_closes;
32471+atomic_unchecked_t cm_connecteds;
32472+atomic_unchecked_t cm_connect_reqs;
32473+atomic_unchecked_t cm_rejects;
32474
32475 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32476 {
32477@@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32478 kfree(listener);
32479 listener = NULL;
32480 ret = 0;
32481- atomic_inc(&cm_listens_destroyed);
32482+ atomic_inc_unchecked(&cm_listens_destroyed);
32483 } else {
32484 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32485 }
32486@@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32487 cm_node->rem_mac);
32488
32489 add_hte_node(cm_core, cm_node);
32490- atomic_inc(&cm_nodes_created);
32491+ atomic_inc_unchecked(&cm_nodes_created);
32492
32493 return cm_node;
32494 }
32495@@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32496 }
32497
32498 atomic_dec(&cm_core->node_cnt);
32499- atomic_inc(&cm_nodes_destroyed);
32500+ atomic_inc_unchecked(&cm_nodes_destroyed);
32501 nesqp = cm_node->nesqp;
32502 if (nesqp) {
32503 nesqp->cm_node = NULL;
32504@@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32505
32506 static void drop_packet(struct sk_buff *skb)
32507 {
32508- atomic_inc(&cm_accel_dropped_pkts);
32509+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32510 dev_kfree_skb_any(skb);
32511 }
32512
32513@@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32514 {
32515
32516 int reset = 0; /* whether to send reset in case of err.. */
32517- atomic_inc(&cm_resets_recvd);
32518+ atomic_inc_unchecked(&cm_resets_recvd);
32519 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32520 " refcnt=%d\n", cm_node, cm_node->state,
32521 atomic_read(&cm_node->ref_count));
32522@@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32523 rem_ref_cm_node(cm_node->cm_core, cm_node);
32524 return NULL;
32525 }
32526- atomic_inc(&cm_loopbacks);
32527+ atomic_inc_unchecked(&cm_loopbacks);
32528 loopbackremotenode->loopbackpartner = cm_node;
32529 loopbackremotenode->tcp_cntxt.rcv_wscale =
32530 NES_CM_DEFAULT_RCV_WND_SCALE;
32531@@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32532 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32533 else {
32534 rem_ref_cm_node(cm_core, cm_node);
32535- atomic_inc(&cm_accel_dropped_pkts);
32536+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32537 dev_kfree_skb_any(skb);
32538 }
32539 break;
32540@@ -2890,7 +2890,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32541
32542 if ((cm_id) && (cm_id->event_handler)) {
32543 if (issue_disconn) {
32544- atomic_inc(&cm_disconnects);
32545+ atomic_inc_unchecked(&cm_disconnects);
32546 cm_event.event = IW_CM_EVENT_DISCONNECT;
32547 cm_event.status = disconn_status;
32548 cm_event.local_addr = cm_id->local_addr;
32549@@ -2912,7 +2912,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32550 }
32551
32552 if (issue_close) {
32553- atomic_inc(&cm_closes);
32554+ atomic_inc_unchecked(&cm_closes);
32555 nes_disconnect(nesqp, 1);
32556
32557 cm_id->provider_data = nesqp;
32558@@ -3048,7 +3048,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32559
32560 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32561 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32562- atomic_inc(&cm_accepts);
32563+ atomic_inc_unchecked(&cm_accepts);
32564
32565 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32566 netdev_refcnt_read(nesvnic->netdev));
32567@@ -3250,7 +3250,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32568 struct nes_cm_core *cm_core;
32569 u8 *start_buff;
32570
32571- atomic_inc(&cm_rejects);
32572+ atomic_inc_unchecked(&cm_rejects);
32573 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32574 loopback = cm_node->loopbackpartner;
32575 cm_core = cm_node->cm_core;
32576@@ -3310,7 +3310,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32577 ntohl(cm_id->local_addr.sin_addr.s_addr),
32578 ntohs(cm_id->local_addr.sin_port));
32579
32580- atomic_inc(&cm_connects);
32581+ atomic_inc_unchecked(&cm_connects);
32582 nesqp->active_conn = 1;
32583
32584 /* cache the cm_id in the qp */
32585@@ -3416,7 +3416,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32586 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32587 return err;
32588 }
32589- atomic_inc(&cm_listens_created);
32590+ atomic_inc_unchecked(&cm_listens_created);
32591 }
32592
32593 cm_id->add_ref(cm_id);
32594@@ -3517,7 +3517,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32595
32596 if (nesqp->destroyed)
32597 return;
32598- atomic_inc(&cm_connecteds);
32599+ atomic_inc_unchecked(&cm_connecteds);
32600 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32601 " local port 0x%04X. jiffies = %lu.\n",
32602 nesqp->hwqp.qp_id,
32603@@ -3704,7 +3704,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32604
32605 cm_id->add_ref(cm_id);
32606 ret = cm_id->event_handler(cm_id, &cm_event);
32607- atomic_inc(&cm_closes);
32608+ atomic_inc_unchecked(&cm_closes);
32609 cm_event.event = IW_CM_EVENT_CLOSE;
32610 cm_event.status = 0;
32611 cm_event.provider_data = cm_id->provider_data;
32612@@ -3740,7 +3740,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32613 return;
32614 cm_id = cm_node->cm_id;
32615
32616- atomic_inc(&cm_connect_reqs);
32617+ atomic_inc_unchecked(&cm_connect_reqs);
32618 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32619 cm_node, cm_id, jiffies);
32620
32621@@ -3780,7 +3780,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32622 return;
32623 cm_id = cm_node->cm_id;
32624
32625- atomic_inc(&cm_connect_reqs);
32626+ atomic_inc_unchecked(&cm_connect_reqs);
32627 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32628 cm_node, cm_id, jiffies);
32629
32630diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32631index 3ba7be3..c81f6ff 100644
32632--- a/drivers/infiniband/hw/nes/nes_mgt.c
32633+++ b/drivers/infiniband/hw/nes/nes_mgt.c
32634@@ -40,8 +40,8 @@
32635 #include "nes.h"
32636 #include "nes_mgt.h"
32637
32638-atomic_t pau_qps_created;
32639-atomic_t pau_qps_destroyed;
32640+atomic_unchecked_t pau_qps_created;
32641+atomic_unchecked_t pau_qps_destroyed;
32642
32643 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32644 {
32645@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32646 {
32647 struct sk_buff *skb;
32648 unsigned long flags;
32649- atomic_inc(&pau_qps_destroyed);
32650+ atomic_inc_unchecked(&pau_qps_destroyed);
32651
32652 /* Free packets that have not yet been forwarded */
32653 /* Lock is acquired by skb_dequeue when removing the skb */
32654@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32655 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32656 skb_queue_head_init(&nesqp->pau_list);
32657 spin_lock_init(&nesqp->pau_lock);
32658- atomic_inc(&pau_qps_created);
32659+ atomic_inc_unchecked(&pau_qps_created);
32660 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32661 }
32662
32663diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32664index f3a3ecf..57d311d 100644
32665--- a/drivers/infiniband/hw/nes/nes_nic.c
32666+++ b/drivers/infiniband/hw/nes/nes_nic.c
32667@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32668 target_stat_values[++index] = mh_detected;
32669 target_stat_values[++index] = mh_pauses_sent;
32670 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32671- target_stat_values[++index] = atomic_read(&cm_connects);
32672- target_stat_values[++index] = atomic_read(&cm_accepts);
32673- target_stat_values[++index] = atomic_read(&cm_disconnects);
32674- target_stat_values[++index] = atomic_read(&cm_connecteds);
32675- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32676- target_stat_values[++index] = atomic_read(&cm_rejects);
32677- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32678- target_stat_values[++index] = atomic_read(&qps_created);
32679- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32680- target_stat_values[++index] = atomic_read(&qps_destroyed);
32681- target_stat_values[++index] = atomic_read(&cm_closes);
32682+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32683+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32684+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32685+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32686+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32687+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32688+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32689+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32690+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32691+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32692+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32693 target_stat_values[++index] = cm_packets_sent;
32694 target_stat_values[++index] = cm_packets_bounced;
32695 target_stat_values[++index] = cm_packets_created;
32696 target_stat_values[++index] = cm_packets_received;
32697 target_stat_values[++index] = cm_packets_dropped;
32698 target_stat_values[++index] = cm_packets_retrans;
32699- target_stat_values[++index] = atomic_read(&cm_listens_created);
32700- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32701+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32702+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32703 target_stat_values[++index] = cm_backlog_drops;
32704- target_stat_values[++index] = atomic_read(&cm_loopbacks);
32705- target_stat_values[++index] = atomic_read(&cm_nodes_created);
32706- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32707- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32708- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32709+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32710+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32711+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32712+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32713+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32714 target_stat_values[++index] = nesadapter->free_4kpbl;
32715 target_stat_values[++index] = nesadapter->free_256pbl;
32716 target_stat_values[++index] = int_mod_timer_init;
32717 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32718 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32719 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32720- target_stat_values[++index] = atomic_read(&pau_qps_created);
32721- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32722+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32723+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32724 }
32725
32726 /**
32727diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32728index 8b8812d..a5e1133 100644
32729--- a/drivers/infiniband/hw/nes/nes_verbs.c
32730+++ b/drivers/infiniband/hw/nes/nes_verbs.c
32731@@ -46,9 +46,9 @@
32732
32733 #include <rdma/ib_umem.h>
32734
32735-atomic_t mod_qp_timouts;
32736-atomic_t qps_created;
32737-atomic_t sw_qps_destroyed;
32738+atomic_unchecked_t mod_qp_timouts;
32739+atomic_unchecked_t qps_created;
32740+atomic_unchecked_t sw_qps_destroyed;
32741
32742 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32743
32744@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32745 if (init_attr->create_flags)
32746 return ERR_PTR(-EINVAL);
32747
32748- atomic_inc(&qps_created);
32749+ atomic_inc_unchecked(&qps_created);
32750 switch (init_attr->qp_type) {
32751 case IB_QPT_RC:
32752 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32753@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32754 struct iw_cm_event cm_event;
32755 int ret = 0;
32756
32757- atomic_inc(&sw_qps_destroyed);
32758+ atomic_inc_unchecked(&sw_qps_destroyed);
32759 nesqp->destroyed = 1;
32760
32761 /* Blow away the connection if it exists. */
32762diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32763index 6b811e3..f8acf88 100644
32764--- a/drivers/infiniband/hw/qib/qib.h
32765+++ b/drivers/infiniband/hw/qib/qib.h
32766@@ -51,6 +51,7 @@
32767 #include <linux/completion.h>
32768 #include <linux/kref.h>
32769 #include <linux/sched.h>
32770+#include <linux/slab.h>
32771
32772 #include "qib_common.h"
32773 #include "qib_verbs.h"
32774diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32775index da739d9..da1c7f4 100644
32776--- a/drivers/input/gameport/gameport.c
32777+++ b/drivers/input/gameport/gameport.c
32778@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32779 */
32780 static void gameport_init_port(struct gameport *gameport)
32781 {
32782- static atomic_t gameport_no = ATOMIC_INIT(0);
32783+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32784
32785 __module_get(THIS_MODULE);
32786
32787 mutex_init(&gameport->drv_mutex);
32788 device_initialize(&gameport->dev);
32789 dev_set_name(&gameport->dev, "gameport%lu",
32790- (unsigned long)atomic_inc_return(&gameport_no) - 1);
32791+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32792 gameport->dev.bus = &gameport_bus;
32793 gameport->dev.release = gameport_release_port;
32794 if (gameport->parent)
32795diff --git a/drivers/input/input.c b/drivers/input/input.c
32796index 8921c61..f5cd63d 100644
32797--- a/drivers/input/input.c
32798+++ b/drivers/input/input.c
32799@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32800 */
32801 int input_register_device(struct input_dev *dev)
32802 {
32803- static atomic_t input_no = ATOMIC_INIT(0);
32804+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32805 struct input_handler *handler;
32806 const char *path;
32807 int error;
32808@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32809 dev->setkeycode = input_default_setkeycode;
32810
32811 dev_set_name(&dev->dev, "input%ld",
32812- (unsigned long) atomic_inc_return(&input_no) - 1);
32813+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32814
32815 error = device_add(&dev->dev);
32816 if (error)
32817diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32818index b8d8611..7a4a04b 100644
32819--- a/drivers/input/joystick/sidewinder.c
32820+++ b/drivers/input/joystick/sidewinder.c
32821@@ -30,6 +30,7 @@
32822 #include <linux/kernel.h>
32823 #include <linux/module.h>
32824 #include <linux/slab.h>
32825+#include <linux/sched.h>
32826 #include <linux/init.h>
32827 #include <linux/input.h>
32828 #include <linux/gameport.h>
32829diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32830index 42f7b25..09fcf46 100644
32831--- a/drivers/input/joystick/xpad.c
32832+++ b/drivers/input/joystick/xpad.c
32833@@ -714,7 +714,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32834
32835 static int xpad_led_probe(struct usb_xpad *xpad)
32836 {
32837- static atomic_t led_seq = ATOMIC_INIT(0);
32838+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32839 long led_no;
32840 struct xpad_led *led;
32841 struct led_classdev *led_cdev;
32842@@ -727,7 +727,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32843 if (!led)
32844 return -ENOMEM;
32845
32846- led_no = (long)atomic_inc_return(&led_seq) - 1;
32847+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32848
32849 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32850 led->xpad = xpad;
32851diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32852index 0110b5a..d3ad144 100644
32853--- a/drivers/input/mousedev.c
32854+++ b/drivers/input/mousedev.c
32855@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32856
32857 spin_unlock_irq(&client->packet_lock);
32858
32859- if (copy_to_user(buffer, data, count))
32860+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
32861 return -EFAULT;
32862
32863 return count;
32864diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32865index d0f7533..fb8215b 100644
32866--- a/drivers/input/serio/serio.c
32867+++ b/drivers/input/serio/serio.c
32868@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32869 */
32870 static void serio_init_port(struct serio *serio)
32871 {
32872- static atomic_t serio_no = ATOMIC_INIT(0);
32873+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32874
32875 __module_get(THIS_MODULE);
32876
32877@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32878 mutex_init(&serio->drv_mutex);
32879 device_initialize(&serio->dev);
32880 dev_set_name(&serio->dev, "serio%ld",
32881- (long)atomic_inc_return(&serio_no) - 1);
32882+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
32883 serio->dev.bus = &serio_bus;
32884 serio->dev.release = serio_release_port;
32885 serio->dev.groups = serio_device_attr_groups;
32886diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32887index b902794..fc7b85b 100644
32888--- a/drivers/isdn/capi/capi.c
32889+++ b/drivers/isdn/capi/capi.c
32890@@ -83,8 +83,8 @@ struct capiminor {
32891
32892 struct capi20_appl *ap;
32893 u32 ncci;
32894- atomic_t datahandle;
32895- atomic_t msgid;
32896+ atomic_unchecked_t datahandle;
32897+ atomic_unchecked_t msgid;
32898
32899 struct tty_port port;
32900 int ttyinstop;
32901@@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32902 capimsg_setu16(s, 2, mp->ap->applid);
32903 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32904 capimsg_setu8 (s, 5, CAPI_RESP);
32905- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32906+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32907 capimsg_setu32(s, 8, mp->ncci);
32908 capimsg_setu16(s, 12, datahandle);
32909 }
32910@@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32911 mp->outbytes -= len;
32912 spin_unlock_bh(&mp->outlock);
32913
32914- datahandle = atomic_inc_return(&mp->datahandle);
32915+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32916 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32917 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32918 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32919 capimsg_setu16(skb->data, 2, mp->ap->applid);
32920 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32921 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32922- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32923+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32924 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32925 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32926 capimsg_setu16(skb->data, 16, len); /* Data length */
32927diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32928index 821f7ac..28d4030 100644
32929--- a/drivers/isdn/hardware/avm/b1.c
32930+++ b/drivers/isdn/hardware/avm/b1.c
32931@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32932 }
32933 if (left) {
32934 if (t4file->user) {
32935- if (copy_from_user(buf, dp, left))
32936+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32937 return -EFAULT;
32938 } else {
32939 memcpy(buf, dp, left);
32940@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32941 }
32942 if (left) {
32943 if (config->user) {
32944- if (copy_from_user(buf, dp, left))
32945+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32946 return -EFAULT;
32947 } else {
32948 memcpy(buf, dp, left);
32949diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32950index dd6b53a..19d9ee6 100644
32951--- a/drivers/isdn/hardware/eicon/divasync.h
32952+++ b/drivers/isdn/hardware/eicon/divasync.h
32953@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32954 } diva_didd_add_adapter_t;
32955 typedef struct _diva_didd_remove_adapter {
32956 IDI_CALL p_request;
32957-} diva_didd_remove_adapter_t;
32958+} __no_const diva_didd_remove_adapter_t;
32959 typedef struct _diva_didd_read_adapter_array {
32960 void *buffer;
32961 dword length;
32962diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32963index d303e65..28bcb7b 100644
32964--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32965+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32966@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32967 typedef struct _diva_os_idi_adapter_interface {
32968 diva_init_card_proc_t cleanup_adapter_proc;
32969 diva_cmd_card_proc_t cmd_proc;
32970-} diva_os_idi_adapter_interface_t;
32971+} __no_const diva_os_idi_adapter_interface_t;
32972
32973 typedef struct _diva_os_xdi_adapter {
32974 struct list_head link;
32975diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32976index e74df7c..03a03ba 100644
32977--- a/drivers/isdn/icn/icn.c
32978+++ b/drivers/isdn/icn/icn.c
32979@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
32980 if (count > len)
32981 count = len;
32982 if (user) {
32983- if (copy_from_user(msg, buf, count))
32984+ if (count > sizeof msg || copy_from_user(msg, buf, count))
32985 return -EFAULT;
32986 } else
32987 memcpy(msg, buf, count);
32988diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
32989index 8bc4915..4cc6a2e 100644
32990--- a/drivers/leds/leds-mc13783.c
32991+++ b/drivers/leds/leds-mc13783.c
32992@@ -280,7 +280,7 @@ static int __devinit mc13783_led_probe(struct platform_device *pdev)
32993 return -EINVAL;
32994 }
32995
32996- led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
32997+ led = kcalloc(pdata->num_leds, sizeof(*led), GFP_KERNEL);
32998 if (led == NULL) {
32999 dev_err(&pdev->dev, "failed to alloc memory\n");
33000 return -ENOMEM;
33001diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33002index b5fdcb7..5b6c59f 100644
33003--- a/drivers/lguest/core.c
33004+++ b/drivers/lguest/core.c
33005@@ -92,9 +92,17 @@ static __init int map_switcher(void)
33006 * it's worked so far. The end address needs +1 because __get_vm_area
33007 * allocates an extra guard page, so we need space for that.
33008 */
33009+
33010+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33011+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33012+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33013+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33014+#else
33015 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33016 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33017 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33018+#endif
33019+
33020 if (!switcher_vma) {
33021 err = -ENOMEM;
33022 printk("lguest: could not map switcher pages high\n");
33023@@ -119,7 +127,7 @@ static __init int map_switcher(void)
33024 * Now the Switcher is mapped at the right address, we can't fail!
33025 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33026 */
33027- memcpy(switcher_vma->addr, start_switcher_text,
33028+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33029 end_switcher_text - start_switcher_text);
33030
33031 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33032diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33033index 39809035..ce25c5e 100644
33034--- a/drivers/lguest/x86/core.c
33035+++ b/drivers/lguest/x86/core.c
33036@@ -59,7 +59,7 @@ static struct {
33037 /* Offset from where switcher.S was compiled to where we've copied it */
33038 static unsigned long switcher_offset(void)
33039 {
33040- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33041+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33042 }
33043
33044 /* This cpu's struct lguest_pages. */
33045@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33046 * These copies are pretty cheap, so we do them unconditionally: */
33047 /* Save the current Host top-level page directory.
33048 */
33049+
33050+#ifdef CONFIG_PAX_PER_CPU_PGD
33051+ pages->state.host_cr3 = read_cr3();
33052+#else
33053 pages->state.host_cr3 = __pa(current->mm->pgd);
33054+#endif
33055+
33056 /*
33057 * Set up the Guest's page tables to see this CPU's pages (and no
33058 * other CPU's pages).
33059@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33060 * compiled-in switcher code and the high-mapped copy we just made.
33061 */
33062 for (i = 0; i < IDT_ENTRIES; i++)
33063- default_idt_entries[i] += switcher_offset();
33064+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33065
33066 /*
33067 * Set up the Switcher's per-cpu areas.
33068@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33069 * it will be undisturbed when we switch. To change %cs and jump we
33070 * need this structure to feed to Intel's "lcall" instruction.
33071 */
33072- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33073+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33074 lguest_entry.segment = LGUEST_CS;
33075
33076 /*
33077diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33078index 40634b0..4f5855e 100644
33079--- a/drivers/lguest/x86/switcher_32.S
33080+++ b/drivers/lguest/x86/switcher_32.S
33081@@ -87,6 +87,7 @@
33082 #include <asm/page.h>
33083 #include <asm/segment.h>
33084 #include <asm/lguest.h>
33085+#include <asm/processor-flags.h>
33086
33087 // We mark the start of the code to copy
33088 // It's placed in .text tho it's never run here
33089@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33090 // Changes type when we load it: damn Intel!
33091 // For after we switch over our page tables
33092 // That entry will be read-only: we'd crash.
33093+
33094+#ifdef CONFIG_PAX_KERNEXEC
33095+ mov %cr0, %edx
33096+ xor $X86_CR0_WP, %edx
33097+ mov %edx, %cr0
33098+#endif
33099+
33100 movl $(GDT_ENTRY_TSS*8), %edx
33101 ltr %dx
33102
33103@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33104 // Let's clear it again for our return.
33105 // The GDT descriptor of the Host
33106 // Points to the table after two "size" bytes
33107- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33108+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33109 // Clear "used" from type field (byte 5, bit 2)
33110- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33111+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33112+
33113+#ifdef CONFIG_PAX_KERNEXEC
33114+ mov %cr0, %eax
33115+ xor $X86_CR0_WP, %eax
33116+ mov %eax, %cr0
33117+#endif
33118
33119 // Once our page table's switched, the Guest is live!
33120 // The Host fades as we run this final step.
33121@@ -295,13 +309,12 @@ deliver_to_host:
33122 // I consulted gcc, and it gave
33123 // These instructions, which I gladly credit:
33124 leal (%edx,%ebx,8), %eax
33125- movzwl (%eax),%edx
33126- movl 4(%eax), %eax
33127- xorw %ax, %ax
33128- orl %eax, %edx
33129+ movl 4(%eax), %edx
33130+ movw (%eax), %dx
33131 // Now the address of the handler's in %edx
33132 // We call it now: its "iret" drops us home.
33133- jmp *%edx
33134+ ljmp $__KERNEL_CS, $1f
33135+1: jmp *%edx
33136
33137 // Every interrupt can come to us here
33138 // But we must truly tell each apart.
33139diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33140index 20e5c2c..9e849a9 100644
33141--- a/drivers/macintosh/macio_asic.c
33142+++ b/drivers/macintosh/macio_asic.c
33143@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33144 * MacIO is matched against any Apple ID, it's probe() function
33145 * will then decide wether it applies or not
33146 */
33147-static const struct pci_device_id __devinitdata pci_ids [] = { {
33148+static const struct pci_device_id __devinitconst pci_ids [] = { {
33149 .vendor = PCI_VENDOR_ID_APPLE,
33150 .device = PCI_ANY_ID,
33151 .subvendor = PCI_ANY_ID,
33152diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33153index 17e2b47..bcbeec4 100644
33154--- a/drivers/md/bitmap.c
33155+++ b/drivers/md/bitmap.c
33156@@ -1823,7 +1823,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33157 chunk_kb ? "KB" : "B");
33158 if (bitmap->file) {
33159 seq_printf(seq, ", file: ");
33160- seq_path(seq, &bitmap->file->f_path, " \t\n");
33161+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33162 }
33163
33164 seq_printf(seq, "\n");
33165diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33166index a1a3e6d..1918bfc 100644
33167--- a/drivers/md/dm-ioctl.c
33168+++ b/drivers/md/dm-ioctl.c
33169@@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33170 cmd == DM_LIST_VERSIONS_CMD)
33171 return 0;
33172
33173- if ((cmd == DM_DEV_CREATE_CMD)) {
33174+ if (cmd == DM_DEV_CREATE_CMD) {
33175 if (!*param->name) {
33176 DMWARN("name not supplied when creating device");
33177 return -EINVAL;
33178diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33179index b58b7a3..8018b19 100644
33180--- a/drivers/md/dm-raid1.c
33181+++ b/drivers/md/dm-raid1.c
33182@@ -40,7 +40,7 @@ enum dm_raid1_error {
33183
33184 struct mirror {
33185 struct mirror_set *ms;
33186- atomic_t error_count;
33187+ atomic_unchecked_t error_count;
33188 unsigned long error_type;
33189 struct dm_dev *dev;
33190 sector_t offset;
33191@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33192 struct mirror *m;
33193
33194 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33195- if (!atomic_read(&m->error_count))
33196+ if (!atomic_read_unchecked(&m->error_count))
33197 return m;
33198
33199 return NULL;
33200@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33201 * simple way to tell if a device has encountered
33202 * errors.
33203 */
33204- atomic_inc(&m->error_count);
33205+ atomic_inc_unchecked(&m->error_count);
33206
33207 if (test_and_set_bit(error_type, &m->error_type))
33208 return;
33209@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33210 struct mirror *m = get_default_mirror(ms);
33211
33212 do {
33213- if (likely(!atomic_read(&m->error_count)))
33214+ if (likely(!atomic_read_unchecked(&m->error_count)))
33215 return m;
33216
33217 if (m-- == ms->mirror)
33218@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33219 {
33220 struct mirror *default_mirror = get_default_mirror(m->ms);
33221
33222- return !atomic_read(&default_mirror->error_count);
33223+ return !atomic_read_unchecked(&default_mirror->error_count);
33224 }
33225
33226 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33227@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33228 */
33229 if (likely(region_in_sync(ms, region, 1)))
33230 m = choose_mirror(ms, bio->bi_sector);
33231- else if (m && atomic_read(&m->error_count))
33232+ else if (m && atomic_read_unchecked(&m->error_count))
33233 m = NULL;
33234
33235 if (likely(m))
33236@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33237 }
33238
33239 ms->mirror[mirror].ms = ms;
33240- atomic_set(&(ms->mirror[mirror].error_count), 0);
33241+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33242 ms->mirror[mirror].error_type = 0;
33243 ms->mirror[mirror].offset = offset;
33244
33245@@ -1352,7 +1352,7 @@ static void mirror_resume(struct dm_target *ti)
33246 */
33247 static char device_status_char(struct mirror *m)
33248 {
33249- if (!atomic_read(&(m->error_count)))
33250+ if (!atomic_read_unchecked(&(m->error_count)))
33251 return 'A';
33252
33253 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33254diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33255index 35c94ff..20d4c17 100644
33256--- a/drivers/md/dm-stripe.c
33257+++ b/drivers/md/dm-stripe.c
33258@@ -20,7 +20,7 @@ struct stripe {
33259 struct dm_dev *dev;
33260 sector_t physical_start;
33261
33262- atomic_t error_count;
33263+ atomic_unchecked_t error_count;
33264 };
33265
33266 struct stripe_c {
33267@@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33268 kfree(sc);
33269 return r;
33270 }
33271- atomic_set(&(sc->stripe[i].error_count), 0);
33272+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33273 }
33274
33275 ti->private = sc;
33276@@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33277 DMEMIT("%d ", sc->stripes);
33278 for (i = 0; i < sc->stripes; i++) {
33279 DMEMIT("%s ", sc->stripe[i].dev->name);
33280- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33281+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33282 'D' : 'A';
33283 }
33284 buffer[i] = '\0';
33285@@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33286 */
33287 for (i = 0; i < sc->stripes; i++)
33288 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33289- atomic_inc(&(sc->stripe[i].error_count));
33290- if (atomic_read(&(sc->stripe[i].error_count)) <
33291+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33292+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33293 DM_IO_ERROR_THRESHOLD)
33294 schedule_work(&sc->trigger_event);
33295 }
33296diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33297index 2e227fb..44ead1f 100644
33298--- a/drivers/md/dm-table.c
33299+++ b/drivers/md/dm-table.c
33300@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33301 if (!dev_size)
33302 return 0;
33303
33304- if ((start >= dev_size) || (start + len > dev_size)) {
33305+ if ((start >= dev_size) || (len > dev_size - start)) {
33306 DMWARN("%s: %s too small for target: "
33307 "start=%llu, len=%llu, dev_size=%llu",
33308 dm_device_name(ti->table->md), bdevname(bdev, b),
33309diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33310index 737d388..811ad5a 100644
33311--- a/drivers/md/dm-thin-metadata.c
33312+++ b/drivers/md/dm-thin-metadata.c
33313@@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33314
33315 pmd->info.tm = tm;
33316 pmd->info.levels = 2;
33317- pmd->info.value_type.context = pmd->data_sm;
33318+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33319 pmd->info.value_type.size = sizeof(__le64);
33320 pmd->info.value_type.inc = data_block_inc;
33321 pmd->info.value_type.dec = data_block_dec;
33322@@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33323
33324 pmd->bl_info.tm = tm;
33325 pmd->bl_info.levels = 1;
33326- pmd->bl_info.value_type.context = pmd->data_sm;
33327+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33328 pmd->bl_info.value_type.size = sizeof(__le64);
33329 pmd->bl_info.value_type.inc = data_block_inc;
33330 pmd->bl_info.value_type.dec = data_block_dec;
33331diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33332index e24143c..ce2f21a1 100644
33333--- a/drivers/md/dm.c
33334+++ b/drivers/md/dm.c
33335@@ -176,9 +176,9 @@ struct mapped_device {
33336 /*
33337 * Event handling.
33338 */
33339- atomic_t event_nr;
33340+ atomic_unchecked_t event_nr;
33341 wait_queue_head_t eventq;
33342- atomic_t uevent_seq;
33343+ atomic_unchecked_t uevent_seq;
33344 struct list_head uevent_list;
33345 spinlock_t uevent_lock; /* Protect access to uevent_list */
33346
33347@@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33348 rwlock_init(&md->map_lock);
33349 atomic_set(&md->holders, 1);
33350 atomic_set(&md->open_count, 0);
33351- atomic_set(&md->event_nr, 0);
33352- atomic_set(&md->uevent_seq, 0);
33353+ atomic_set_unchecked(&md->event_nr, 0);
33354+ atomic_set_unchecked(&md->uevent_seq, 0);
33355 INIT_LIST_HEAD(&md->uevent_list);
33356 spin_lock_init(&md->uevent_lock);
33357
33358@@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33359
33360 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33361
33362- atomic_inc(&md->event_nr);
33363+ atomic_inc_unchecked(&md->event_nr);
33364 wake_up(&md->eventq);
33365 }
33366
33367@@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33368
33369 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33370 {
33371- return atomic_add_return(1, &md->uevent_seq);
33372+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33373 }
33374
33375 uint32_t dm_get_event_nr(struct mapped_device *md)
33376 {
33377- return atomic_read(&md->event_nr);
33378+ return atomic_read_unchecked(&md->event_nr);
33379 }
33380
33381 int dm_wait_event(struct mapped_device *md, int event_nr)
33382 {
33383 return wait_event_interruptible(md->eventq,
33384- (event_nr != atomic_read(&md->event_nr)));
33385+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33386 }
33387
33388 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33389diff --git a/drivers/md/md.c b/drivers/md/md.c
33390index 9ee8ce3..362b519 100644
33391--- a/drivers/md/md.c
33392+++ b/drivers/md/md.c
33393@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33394 * start build, activate spare
33395 */
33396 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33397-static atomic_t md_event_count;
33398+static atomic_unchecked_t md_event_count;
33399 void md_new_event(struct mddev *mddev)
33400 {
33401- atomic_inc(&md_event_count);
33402+ atomic_inc_unchecked(&md_event_count);
33403 wake_up(&md_event_waiters);
33404 }
33405 EXPORT_SYMBOL_GPL(md_new_event);
33406@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33407 */
33408 static void md_new_event_inintr(struct mddev *mddev)
33409 {
33410- atomic_inc(&md_event_count);
33411+ atomic_inc_unchecked(&md_event_count);
33412 wake_up(&md_event_waiters);
33413 }
33414
33415@@ -1526,7 +1526,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33416
33417 rdev->preferred_minor = 0xffff;
33418 rdev->data_offset = le64_to_cpu(sb->data_offset);
33419- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33420+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33421
33422 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33423 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33424@@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33425 else
33426 sb->resync_offset = cpu_to_le64(0);
33427
33428- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33429+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33430
33431 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33432 sb->size = cpu_to_le64(mddev->dev_sectors);
33433@@ -2691,7 +2691,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33434 static ssize_t
33435 errors_show(struct md_rdev *rdev, char *page)
33436 {
33437- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33438+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33439 }
33440
33441 static ssize_t
33442@@ -2700,7 +2700,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33443 char *e;
33444 unsigned long n = simple_strtoul(buf, &e, 10);
33445 if (*buf && (*e == 0 || *e == '\n')) {
33446- atomic_set(&rdev->corrected_errors, n);
33447+ atomic_set_unchecked(&rdev->corrected_errors, n);
33448 return len;
33449 }
33450 return -EINVAL;
33451@@ -3086,8 +3086,8 @@ int md_rdev_init(struct md_rdev *rdev)
33452 rdev->sb_loaded = 0;
33453 rdev->bb_page = NULL;
33454 atomic_set(&rdev->nr_pending, 0);
33455- atomic_set(&rdev->read_errors, 0);
33456- atomic_set(&rdev->corrected_errors, 0);
33457+ atomic_set_unchecked(&rdev->read_errors, 0);
33458+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33459
33460 INIT_LIST_HEAD(&rdev->same_set);
33461 init_waitqueue_head(&rdev->blocked_wait);
33462@@ -6748,7 +6748,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33463
33464 spin_unlock(&pers_lock);
33465 seq_printf(seq, "\n");
33466- seq->poll_event = atomic_read(&md_event_count);
33467+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33468 return 0;
33469 }
33470 if (v == (void*)2) {
33471@@ -6851,7 +6851,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33472 return error;
33473
33474 seq = file->private_data;
33475- seq->poll_event = atomic_read(&md_event_count);
33476+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33477 return error;
33478 }
33479
33480@@ -6865,7 +6865,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33481 /* always allow read */
33482 mask = POLLIN | POLLRDNORM;
33483
33484- if (seq->poll_event != atomic_read(&md_event_count))
33485+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33486 mask |= POLLERR | POLLPRI;
33487 return mask;
33488 }
33489@@ -6909,7 +6909,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33490 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33491 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33492 (int)part_stat_read(&disk->part0, sectors[1]) -
33493- atomic_read(&disk->sync_io);
33494+ atomic_read_unchecked(&disk->sync_io);
33495 /* sync IO will cause sync_io to increase before the disk_stats
33496 * as sync_io is counted when a request starts, and
33497 * disk_stats is counted when it completes.
33498diff --git a/drivers/md/md.h b/drivers/md/md.h
33499index 1c2063c..9639970 100644
33500--- a/drivers/md/md.h
33501+++ b/drivers/md/md.h
33502@@ -93,13 +93,13 @@ struct md_rdev {
33503 * only maintained for arrays that
33504 * support hot removal
33505 */
33506- atomic_t read_errors; /* number of consecutive read errors that
33507+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
33508 * we have tried to ignore.
33509 */
33510 struct timespec last_read_error; /* monotonic time since our
33511 * last read error
33512 */
33513- atomic_t corrected_errors; /* number of corrected read errors,
33514+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33515 * for reporting to userspace and storing
33516 * in superblock.
33517 */
33518@@ -429,7 +429,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33519
33520 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33521 {
33522- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33523+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33524 }
33525
33526 struct md_personality
33527diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33528index fc90c11..c8cd9a9 100644
33529--- a/drivers/md/persistent-data/dm-space-map-checker.c
33530+++ b/drivers/md/persistent-data/dm-space-map-checker.c
33531@@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33532 /*----------------------------------------------------------------*/
33533
33534 struct sm_checker {
33535- struct dm_space_map sm;
33536+ dm_space_map_no_const sm;
33537
33538 struct count_array old_counts;
33539 struct count_array counts;
33540diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33541index 3d0ed53..35dc592 100644
33542--- a/drivers/md/persistent-data/dm-space-map-disk.c
33543+++ b/drivers/md/persistent-data/dm-space-map-disk.c
33544@@ -23,7 +23,7 @@
33545 * Space map interface.
33546 */
33547 struct sm_disk {
33548- struct dm_space_map sm;
33549+ dm_space_map_no_const sm;
33550
33551 struct ll_disk ll;
33552 struct ll_disk old_ll;
33553diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33554index e89ae5e..062e4c2 100644
33555--- a/drivers/md/persistent-data/dm-space-map-metadata.c
33556+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33557@@ -43,7 +43,7 @@ struct block_op {
33558 };
33559
33560 struct sm_metadata {
33561- struct dm_space_map sm;
33562+ dm_space_map_no_const sm;
33563
33564 struct ll_disk ll;
33565 struct ll_disk old_ll;
33566diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33567index 1cbfc6b..56e1dbb 100644
33568--- a/drivers/md/persistent-data/dm-space-map.h
33569+++ b/drivers/md/persistent-data/dm-space-map.h
33570@@ -60,6 +60,7 @@ struct dm_space_map {
33571 int (*root_size)(struct dm_space_map *sm, size_t *result);
33572 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33573 };
33574+typedef struct dm_space_map __no_const dm_space_map_no_const;
33575
33576 /*----------------------------------------------------------------*/
33577
33578diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33579index d7add9d..68e3dde 100644
33580--- a/drivers/md/raid1.c
33581+++ b/drivers/md/raid1.c
33582@@ -1688,7 +1688,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33583 if (r1_sync_page_io(rdev, sect, s,
33584 bio->bi_io_vec[idx].bv_page,
33585 READ) != 0)
33586- atomic_add(s, &rdev->corrected_errors);
33587+ atomic_add_unchecked(s, &rdev->corrected_errors);
33588 }
33589 sectors -= s;
33590 sect += s;
33591@@ -1908,7 +1908,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33592 test_bit(In_sync, &rdev->flags)) {
33593 if (r1_sync_page_io(rdev, sect, s,
33594 conf->tmppage, READ)) {
33595- atomic_add(s, &rdev->corrected_errors);
33596+ atomic_add_unchecked(s, &rdev->corrected_errors);
33597 printk(KERN_INFO
33598 "md/raid1:%s: read error corrected "
33599 "(%d sectors at %llu on %s)\n",
33600diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33601index a954c95..6e7a21c 100644
33602--- a/drivers/md/raid10.c
33603+++ b/drivers/md/raid10.c
33604@@ -1684,7 +1684,7 @@ static void end_sync_read(struct bio *bio, int error)
33605 /* The write handler will notice the lack of
33606 * R10BIO_Uptodate and record any errors etc
33607 */
33608- atomic_add(r10_bio->sectors,
33609+ atomic_add_unchecked(r10_bio->sectors,
33610 &conf->mirrors[d].rdev->corrected_errors);
33611
33612 /* for reconstruct, we always reschedule after a read.
33613@@ -2033,7 +2033,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33614 {
33615 struct timespec cur_time_mon;
33616 unsigned long hours_since_last;
33617- unsigned int read_errors = atomic_read(&rdev->read_errors);
33618+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33619
33620 ktime_get_ts(&cur_time_mon);
33621
33622@@ -2055,9 +2055,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33623 * overflowing the shift of read_errors by hours_since_last.
33624 */
33625 if (hours_since_last >= 8 * sizeof(read_errors))
33626- atomic_set(&rdev->read_errors, 0);
33627+ atomic_set_unchecked(&rdev->read_errors, 0);
33628 else
33629- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33630+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33631 }
33632
33633 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33634@@ -2111,8 +2111,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33635 return;
33636
33637 check_decay_read_errors(mddev, rdev);
33638- atomic_inc(&rdev->read_errors);
33639- if (atomic_read(&rdev->read_errors) > max_read_errors) {
33640+ atomic_inc_unchecked(&rdev->read_errors);
33641+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33642 char b[BDEVNAME_SIZE];
33643 bdevname(rdev->bdev, b);
33644
33645@@ -2120,7 +2120,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33646 "md/raid10:%s: %s: Raid device exceeded "
33647 "read_error threshold [cur %d:max %d]\n",
33648 mdname(mddev), b,
33649- atomic_read(&rdev->read_errors), max_read_errors);
33650+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33651 printk(KERN_NOTICE
33652 "md/raid10:%s: %s: Failing raid device\n",
33653 mdname(mddev), b);
33654@@ -2271,7 +2271,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33655 (unsigned long long)(
33656 sect + rdev->data_offset),
33657 bdevname(rdev->bdev, b));
33658- atomic_add(s, &rdev->corrected_errors);
33659+ atomic_add_unchecked(s, &rdev->corrected_errors);
33660 }
33661
33662 rdev_dec_pending(rdev, mddev);
33663diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33664index 73a5800..2b0e3b1 100644
33665--- a/drivers/md/raid5.c
33666+++ b/drivers/md/raid5.c
33667@@ -1694,18 +1694,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
33668 (unsigned long long)(sh->sector
33669 + rdev->data_offset),
33670 bdevname(rdev->bdev, b));
33671- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33672+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33673 clear_bit(R5_ReadError, &sh->dev[i].flags);
33674 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33675 }
33676- if (atomic_read(&rdev->read_errors))
33677- atomic_set(&rdev->read_errors, 0);
33678+ if (atomic_read_unchecked(&rdev->read_errors))
33679+ atomic_set_unchecked(&rdev->read_errors, 0);
33680 } else {
33681 const char *bdn = bdevname(rdev->bdev, b);
33682 int retry = 0;
33683
33684 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33685- atomic_inc(&rdev->read_errors);
33686+ atomic_inc_unchecked(&rdev->read_errors);
33687 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33688 printk_ratelimited(
33689 KERN_WARNING
33690@@ -1734,7 +1734,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33691 (unsigned long long)(sh->sector
33692 + rdev->data_offset),
33693 bdn);
33694- else if (atomic_read(&rdev->read_errors)
33695+ else if (atomic_read_unchecked(&rdev->read_errors)
33696 > conf->max_nr_stripes)
33697 printk(KERN_WARNING
33698 "md/raid:%s: Too many read errors, failing device %s.\n",
33699diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33700index d88c4aa..17c80b1 100644
33701--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33702+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33703@@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33704 .subvendor = _subvend, .subdevice = _subdev, \
33705 .driver_data = (unsigned long)&_driverdata }
33706
33707-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33708+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33709 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33710 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33711 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33712diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33713index a7d876f..8c21b61 100644
33714--- a/drivers/media/dvb/dvb-core/dvb_demux.h
33715+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33716@@ -73,7 +73,7 @@ struct dvb_demux_feed {
33717 union {
33718 dmx_ts_cb ts;
33719 dmx_section_cb sec;
33720- } cb;
33721+ } __no_const cb;
33722
33723 struct dvb_demux *demux;
33724 void *priv;
33725diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33726index 39eab73..60033e7 100644
33727--- a/drivers/media/dvb/dvb-core/dvbdev.c
33728+++ b/drivers/media/dvb/dvb-core/dvbdev.c
33729@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33730 const struct dvb_device *template, void *priv, int type)
33731 {
33732 struct dvb_device *dvbdev;
33733- struct file_operations *dvbdevfops;
33734+ file_operations_no_const *dvbdevfops;
33735 struct device *clsdev;
33736 int minor;
33737 int id;
33738diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33739index 3940bb0..fb3952a 100644
33740--- a/drivers/media/dvb/dvb-usb/cxusb.c
33741+++ b/drivers/media/dvb/dvb-usb/cxusb.c
33742@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33743
33744 struct dib0700_adapter_state {
33745 int (*set_param_save) (struct dvb_frontend *);
33746-};
33747+} __no_const;
33748
33749 static int dib7070_set_param_override(struct dvb_frontend *fe)
33750 {
33751diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33752index 451c5a7..649f711 100644
33753--- a/drivers/media/dvb/dvb-usb/dw2102.c
33754+++ b/drivers/media/dvb/dvb-usb/dw2102.c
33755@@ -95,7 +95,7 @@ struct su3000_state {
33756
33757 struct s6x0_state {
33758 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33759-};
33760+} __no_const;
33761
33762 /* debug */
33763 static int dvb_usb_dw2102_debug;
33764diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33765index 404f63a..4796533 100644
33766--- a/drivers/media/dvb/frontends/dib3000.h
33767+++ b/drivers/media/dvb/frontends/dib3000.h
33768@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33769 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33770 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33771 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33772-};
33773+} __no_const;
33774
33775 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33776 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33777diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33778index 7539a5d..06531a6 100644
33779--- a/drivers/media/dvb/ngene/ngene-cards.c
33780+++ b/drivers/media/dvb/ngene/ngene-cards.c
33781@@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33782
33783 /****************************************************************************/
33784
33785-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33786+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33787 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33788 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33789 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33790diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33791index 16a089f..1661b11 100644
33792--- a/drivers/media/radio/radio-cadet.c
33793+++ b/drivers/media/radio/radio-cadet.c
33794@@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33795 unsigned char readbuf[RDS_BUFFER];
33796 int i = 0;
33797
33798+ if (count > RDS_BUFFER)
33799+ return -EFAULT;
33800 mutex_lock(&dev->lock);
33801 if (dev->rdsstat == 0) {
33802 dev->rdsstat = 1;
33803@@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33804 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33805 mutex_unlock(&dev->lock);
33806
33807- if (copy_to_user(data, readbuf, i))
33808+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33809 return -EFAULT;
33810 return i;
33811 }
33812diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33813index 9cde353..8c6a1c3 100644
33814--- a/drivers/media/video/au0828/au0828.h
33815+++ b/drivers/media/video/au0828/au0828.h
33816@@ -191,7 +191,7 @@ struct au0828_dev {
33817
33818 /* I2C */
33819 struct i2c_adapter i2c_adap;
33820- struct i2c_algorithm i2c_algo;
33821+ i2c_algorithm_no_const i2c_algo;
33822 struct i2c_client i2c_client;
33823 u32 i2c_rc;
33824
33825diff --git a/drivers/media/video/cx25821/cx25821-core.c b/drivers/media/video/cx25821/cx25821-core.c
33826index 7930ca5..235bf7d 100644
33827--- a/drivers/media/video/cx25821/cx25821-core.c
33828+++ b/drivers/media/video/cx25821/cx25821-core.c
33829@@ -912,9 +912,6 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
33830 list_add_tail(&dev->devlist, &cx25821_devlist);
33831 mutex_unlock(&cx25821_devlist_mutex);
33832
33833- strcpy(cx25821_boards[UNKNOWN_BOARD].name, "unknown");
33834- strcpy(cx25821_boards[CX25821_BOARD].name, "cx25821");
33835-
33836 if (dev->pci->device != 0x8210) {
33837 pr_info("%s(): Exiting. Incorrect Hardware device = 0x%02x\n",
33838 __func__, dev->pci->device);
33839diff --git a/drivers/media/video/cx25821/cx25821.h b/drivers/media/video/cx25821/cx25821.h
33840index b9aa801..029f293 100644
33841--- a/drivers/media/video/cx25821/cx25821.h
33842+++ b/drivers/media/video/cx25821/cx25821.h
33843@@ -187,7 +187,7 @@ enum port {
33844 };
33845
33846 struct cx25821_board {
33847- char *name;
33848+ const char *name;
33849 enum port porta;
33850 enum port portb;
33851 enum port portc;
33852diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33853index 04bf662..e0ac026 100644
33854--- a/drivers/media/video/cx88/cx88-alsa.c
33855+++ b/drivers/media/video/cx88/cx88-alsa.c
33856@@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33857 * Only boards with eeprom and byte 1 at eeprom=1 have it
33858 */
33859
33860-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33861+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33862 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33863 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33864 {0, }
33865diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33866index 88cf9d9..bbc4b2c 100644
33867--- a/drivers/media/video/omap/omap_vout.c
33868+++ b/drivers/media/video/omap/omap_vout.c
33869@@ -64,7 +64,6 @@ enum omap_vout_channels {
33870 OMAP_VIDEO2,
33871 };
33872
33873-static struct videobuf_queue_ops video_vbq_ops;
33874 /* Variables configurable through module params*/
33875 static u32 video1_numbuffers = 3;
33876 static u32 video2_numbuffers = 3;
33877@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33878 {
33879 struct videobuf_queue *q;
33880 struct omap_vout_device *vout = NULL;
33881+ static struct videobuf_queue_ops video_vbq_ops = {
33882+ .buf_setup = omap_vout_buffer_setup,
33883+ .buf_prepare = omap_vout_buffer_prepare,
33884+ .buf_release = omap_vout_buffer_release,
33885+ .buf_queue = omap_vout_buffer_queue,
33886+ };
33887
33888 vout = video_drvdata(file);
33889 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33890@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33891 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33892
33893 q = &vout->vbq;
33894- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33895- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33896- video_vbq_ops.buf_release = omap_vout_buffer_release;
33897- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33898 spin_lock_init(&vout->vbq_lock);
33899
33900 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33901diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33902index 305e6aa..0143317 100644
33903--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33904+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33905@@ -196,7 +196,7 @@ struct pvr2_hdw {
33906
33907 /* I2C stuff */
33908 struct i2c_adapter i2c_adap;
33909- struct i2c_algorithm i2c_algo;
33910+ i2c_algorithm_no_const i2c_algo;
33911 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33912 int i2c_cx25840_hack_state;
33913 int i2c_linked;
33914diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33915index 02194c0..091733b 100644
33916--- a/drivers/media/video/timblogiw.c
33917+++ b/drivers/media/video/timblogiw.c
33918@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33919
33920 /* Platform device functions */
33921
33922-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33923+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33924 .vidioc_querycap = timblogiw_querycap,
33925 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33926 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33927@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33928 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33929 };
33930
33931-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33932+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33933 .owner = THIS_MODULE,
33934 .open = timblogiw_open,
33935 .release = timblogiw_close,
33936diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33937index a5c591f..db692a3 100644
33938--- a/drivers/message/fusion/mptbase.c
33939+++ b/drivers/message/fusion/mptbase.c
33940@@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33941 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33942 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33943
33944+#ifdef CONFIG_GRKERNSEC_HIDESYM
33945+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33946+#else
33947 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33948 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33949+#endif
33950+
33951 /*
33952 * Rounding UP to nearest 4-kB boundary here...
33953 */
33954diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33955index 551262e..7551198 100644
33956--- a/drivers/message/fusion/mptsas.c
33957+++ b/drivers/message/fusion/mptsas.c
33958@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33959 return 0;
33960 }
33961
33962+static inline void
33963+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33964+{
33965+ if (phy_info->port_details) {
33966+ phy_info->port_details->rphy = rphy;
33967+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33968+ ioc->name, rphy));
33969+ }
33970+
33971+ if (rphy) {
33972+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33973+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33974+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33975+ ioc->name, rphy, rphy->dev.release));
33976+ }
33977+}
33978+
33979 /* no mutex */
33980 static void
33981 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33982@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33983 return NULL;
33984 }
33985
33986-static inline void
33987-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33988-{
33989- if (phy_info->port_details) {
33990- phy_info->port_details->rphy = rphy;
33991- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33992- ioc->name, rphy));
33993- }
33994-
33995- if (rphy) {
33996- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33997- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33998- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33999- ioc->name, rphy, rphy->dev.release));
34000- }
34001-}
34002-
34003 static inline struct sas_port *
34004 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34005 {
34006diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34007index 0c3ced7..1fe34ec 100644
34008--- a/drivers/message/fusion/mptscsih.c
34009+++ b/drivers/message/fusion/mptscsih.c
34010@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34011
34012 h = shost_priv(SChost);
34013
34014- if (h) {
34015- if (h->info_kbuf == NULL)
34016- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34017- return h->info_kbuf;
34018- h->info_kbuf[0] = '\0';
34019+ if (!h)
34020+ return NULL;
34021
34022- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34023- h->info_kbuf[size-1] = '\0';
34024- }
34025+ if (h->info_kbuf == NULL)
34026+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34027+ return h->info_kbuf;
34028+ h->info_kbuf[0] = '\0';
34029+
34030+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34031+ h->info_kbuf[size-1] = '\0';
34032
34033 return h->info_kbuf;
34034 }
34035diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34036index 6d115c7..58ff7fd 100644
34037--- a/drivers/message/i2o/i2o_proc.c
34038+++ b/drivers/message/i2o/i2o_proc.c
34039@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34040 "Array Controller Device"
34041 };
34042
34043-static char *chtostr(u8 * chars, int n)
34044-{
34045- char tmp[256];
34046- tmp[0] = 0;
34047- return strncat(tmp, (char *)chars, n);
34048-}
34049-
34050 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34051 char *group)
34052 {
34053@@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34054
34055 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34056 seq_printf(seq, "%-#8x", ddm_table.module_id);
34057- seq_printf(seq, "%-29s",
34058- chtostr(ddm_table.module_name_version, 28));
34059+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34060 seq_printf(seq, "%9d ", ddm_table.data_size);
34061 seq_printf(seq, "%8d", ddm_table.code_size);
34062
34063@@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34064
34065 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34066 seq_printf(seq, "%-#8x", dst->module_id);
34067- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34068- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34069+ seq_printf(seq, "%-.28s", dst->module_name_version);
34070+ seq_printf(seq, "%-.8s", dst->date);
34071 seq_printf(seq, "%8d ", dst->module_size);
34072 seq_printf(seq, "%8d ", dst->mpb_size);
34073 seq_printf(seq, "0x%04x", dst->module_flags);
34074@@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34075 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34076 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34077 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34078- seq_printf(seq, "Vendor info : %s\n",
34079- chtostr((u8 *) (work32 + 2), 16));
34080- seq_printf(seq, "Product info : %s\n",
34081- chtostr((u8 *) (work32 + 6), 16));
34082- seq_printf(seq, "Description : %s\n",
34083- chtostr((u8 *) (work32 + 10), 16));
34084- seq_printf(seq, "Product rev. : %s\n",
34085- chtostr((u8 *) (work32 + 14), 8));
34086+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34087+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34088+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34089+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34090
34091 seq_printf(seq, "Serial number : ");
34092 print_serial_number(seq, (u8 *) (work32 + 16),
34093@@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34094 }
34095
34096 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34097- seq_printf(seq, "Module name : %s\n",
34098- chtostr(result.module_name, 24));
34099- seq_printf(seq, "Module revision : %s\n",
34100- chtostr(result.module_rev, 8));
34101+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
34102+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34103
34104 seq_printf(seq, "Serial number : ");
34105 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34106@@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34107 return 0;
34108 }
34109
34110- seq_printf(seq, "Device name : %s\n",
34111- chtostr(result.device_name, 64));
34112- seq_printf(seq, "Service name : %s\n",
34113- chtostr(result.service_name, 64));
34114- seq_printf(seq, "Physical name : %s\n",
34115- chtostr(result.physical_location, 64));
34116- seq_printf(seq, "Instance number : %s\n",
34117- chtostr(result.instance_number, 4));
34118+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34119+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34120+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34121+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34122
34123 return 0;
34124 }
34125diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34126index a8c08f3..155fe3d 100644
34127--- a/drivers/message/i2o/iop.c
34128+++ b/drivers/message/i2o/iop.c
34129@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34130
34131 spin_lock_irqsave(&c->context_list_lock, flags);
34132
34133- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34134- atomic_inc(&c->context_list_counter);
34135+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34136+ atomic_inc_unchecked(&c->context_list_counter);
34137
34138- entry->context = atomic_read(&c->context_list_counter);
34139+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34140
34141 list_add(&entry->list, &c->context_list);
34142
34143@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34144
34145 #if BITS_PER_LONG == 64
34146 spin_lock_init(&c->context_list_lock);
34147- atomic_set(&c->context_list_counter, 0);
34148+ atomic_set_unchecked(&c->context_list_counter, 0);
34149 INIT_LIST_HEAD(&c->context_list);
34150 #endif
34151
34152diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34153index 7ce65f4..e66e9bc 100644
34154--- a/drivers/mfd/abx500-core.c
34155+++ b/drivers/mfd/abx500-core.c
34156@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34157
34158 struct abx500_device_entry {
34159 struct list_head list;
34160- struct abx500_ops ops;
34161+ abx500_ops_no_const ops;
34162 struct device *dev;
34163 };
34164
34165diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34166index a9223ed..4127b13 100644
34167--- a/drivers/mfd/janz-cmodio.c
34168+++ b/drivers/mfd/janz-cmodio.c
34169@@ -13,6 +13,7 @@
34170
34171 #include <linux/kernel.h>
34172 #include <linux/module.h>
34173+#include <linux/slab.h>
34174 #include <linux/init.h>
34175 #include <linux/pci.h>
34176 #include <linux/interrupt.h>
34177diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34178index a981e2a..5ca0c8b 100644
34179--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34180+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34181@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34182 * the lid is closed. This leads to interrupts as soon as a little move
34183 * is done.
34184 */
34185- atomic_inc(&lis3->count);
34186+ atomic_inc_unchecked(&lis3->count);
34187
34188 wake_up_interruptible(&lis3->misc_wait);
34189 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34190@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34191 if (lis3->pm_dev)
34192 pm_runtime_get_sync(lis3->pm_dev);
34193
34194- atomic_set(&lis3->count, 0);
34195+ atomic_set_unchecked(&lis3->count, 0);
34196 return 0;
34197 }
34198
34199@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34200 add_wait_queue(&lis3->misc_wait, &wait);
34201 while (true) {
34202 set_current_state(TASK_INTERRUPTIBLE);
34203- data = atomic_xchg(&lis3->count, 0);
34204+ data = atomic_xchg_unchecked(&lis3->count, 0);
34205 if (data)
34206 break;
34207
34208@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34209 struct lis3lv02d, miscdev);
34210
34211 poll_wait(file, &lis3->misc_wait, wait);
34212- if (atomic_read(&lis3->count))
34213+ if (atomic_read_unchecked(&lis3->count))
34214 return POLLIN | POLLRDNORM;
34215 return 0;
34216 }
34217diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34218index 2b1482a..5d33616 100644
34219--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34220+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34221@@ -266,7 +266,7 @@ struct lis3lv02d {
34222 struct input_polled_dev *idev; /* input device */
34223 struct platform_device *pdev; /* platform device */
34224 struct regulator_bulk_data regulators[2];
34225- atomic_t count; /* interrupt count after last read */
34226+ atomic_unchecked_t count; /* interrupt count after last read */
34227 union axis_conversion ac; /* hw -> logical axis */
34228 int mapped_btns[3];
34229
34230diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
34231index 28adefe..08aad69 100644
34232--- a/drivers/misc/lkdtm.c
34233+++ b/drivers/misc/lkdtm.c
34234@@ -477,6 +477,8 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
34235 int i, n, out;
34236
34237 buf = (char *)__get_free_page(GFP_KERNEL);
34238+ if (buf == NULL)
34239+ return -ENOMEM;
34240
34241 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
34242 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
34243diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34244index 2f30bad..c4c13d0 100644
34245--- a/drivers/misc/sgi-gru/gruhandles.c
34246+++ b/drivers/misc/sgi-gru/gruhandles.c
34247@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34248 unsigned long nsec;
34249
34250 nsec = CLKS2NSEC(clks);
34251- atomic_long_inc(&mcs_op_statistics[op].count);
34252- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34253+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34254+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34255 if (mcs_op_statistics[op].max < nsec)
34256 mcs_op_statistics[op].max = nsec;
34257 }
34258diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34259index 950dbe9..eeef0f8 100644
34260--- a/drivers/misc/sgi-gru/gruprocfs.c
34261+++ b/drivers/misc/sgi-gru/gruprocfs.c
34262@@ -32,9 +32,9 @@
34263
34264 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34265
34266-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34267+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34268 {
34269- unsigned long val = atomic_long_read(v);
34270+ unsigned long val = atomic_long_read_unchecked(v);
34271
34272 seq_printf(s, "%16lu %s\n", val, id);
34273 }
34274@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34275
34276 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34277 for (op = 0; op < mcsop_last; op++) {
34278- count = atomic_long_read(&mcs_op_statistics[op].count);
34279- total = atomic_long_read(&mcs_op_statistics[op].total);
34280+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34281+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34282 max = mcs_op_statistics[op].max;
34283 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34284 count ? total / count : 0, max);
34285diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34286index 5c3ce24..4915ccb 100644
34287--- a/drivers/misc/sgi-gru/grutables.h
34288+++ b/drivers/misc/sgi-gru/grutables.h
34289@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34290 * GRU statistics.
34291 */
34292 struct gru_stats_s {
34293- atomic_long_t vdata_alloc;
34294- atomic_long_t vdata_free;
34295- atomic_long_t gts_alloc;
34296- atomic_long_t gts_free;
34297- atomic_long_t gms_alloc;
34298- atomic_long_t gms_free;
34299- atomic_long_t gts_double_allocate;
34300- atomic_long_t assign_context;
34301- atomic_long_t assign_context_failed;
34302- atomic_long_t free_context;
34303- atomic_long_t load_user_context;
34304- atomic_long_t load_kernel_context;
34305- atomic_long_t lock_kernel_context;
34306- atomic_long_t unlock_kernel_context;
34307- atomic_long_t steal_user_context;
34308- atomic_long_t steal_kernel_context;
34309- atomic_long_t steal_context_failed;
34310- atomic_long_t nopfn;
34311- atomic_long_t asid_new;
34312- atomic_long_t asid_next;
34313- atomic_long_t asid_wrap;
34314- atomic_long_t asid_reuse;
34315- atomic_long_t intr;
34316- atomic_long_t intr_cbr;
34317- atomic_long_t intr_tfh;
34318- atomic_long_t intr_spurious;
34319- atomic_long_t intr_mm_lock_failed;
34320- atomic_long_t call_os;
34321- atomic_long_t call_os_wait_queue;
34322- atomic_long_t user_flush_tlb;
34323- atomic_long_t user_unload_context;
34324- atomic_long_t user_exception;
34325- atomic_long_t set_context_option;
34326- atomic_long_t check_context_retarget_intr;
34327- atomic_long_t check_context_unload;
34328- atomic_long_t tlb_dropin;
34329- atomic_long_t tlb_preload_page;
34330- atomic_long_t tlb_dropin_fail_no_asid;
34331- atomic_long_t tlb_dropin_fail_upm;
34332- atomic_long_t tlb_dropin_fail_invalid;
34333- atomic_long_t tlb_dropin_fail_range_active;
34334- atomic_long_t tlb_dropin_fail_idle;
34335- atomic_long_t tlb_dropin_fail_fmm;
34336- atomic_long_t tlb_dropin_fail_no_exception;
34337- atomic_long_t tfh_stale_on_fault;
34338- atomic_long_t mmu_invalidate_range;
34339- atomic_long_t mmu_invalidate_page;
34340- atomic_long_t flush_tlb;
34341- atomic_long_t flush_tlb_gru;
34342- atomic_long_t flush_tlb_gru_tgh;
34343- atomic_long_t flush_tlb_gru_zero_asid;
34344+ atomic_long_unchecked_t vdata_alloc;
34345+ atomic_long_unchecked_t vdata_free;
34346+ atomic_long_unchecked_t gts_alloc;
34347+ atomic_long_unchecked_t gts_free;
34348+ atomic_long_unchecked_t gms_alloc;
34349+ atomic_long_unchecked_t gms_free;
34350+ atomic_long_unchecked_t gts_double_allocate;
34351+ atomic_long_unchecked_t assign_context;
34352+ atomic_long_unchecked_t assign_context_failed;
34353+ atomic_long_unchecked_t free_context;
34354+ atomic_long_unchecked_t load_user_context;
34355+ atomic_long_unchecked_t load_kernel_context;
34356+ atomic_long_unchecked_t lock_kernel_context;
34357+ atomic_long_unchecked_t unlock_kernel_context;
34358+ atomic_long_unchecked_t steal_user_context;
34359+ atomic_long_unchecked_t steal_kernel_context;
34360+ atomic_long_unchecked_t steal_context_failed;
34361+ atomic_long_unchecked_t nopfn;
34362+ atomic_long_unchecked_t asid_new;
34363+ atomic_long_unchecked_t asid_next;
34364+ atomic_long_unchecked_t asid_wrap;
34365+ atomic_long_unchecked_t asid_reuse;
34366+ atomic_long_unchecked_t intr;
34367+ atomic_long_unchecked_t intr_cbr;
34368+ atomic_long_unchecked_t intr_tfh;
34369+ atomic_long_unchecked_t intr_spurious;
34370+ atomic_long_unchecked_t intr_mm_lock_failed;
34371+ atomic_long_unchecked_t call_os;
34372+ atomic_long_unchecked_t call_os_wait_queue;
34373+ atomic_long_unchecked_t user_flush_tlb;
34374+ atomic_long_unchecked_t user_unload_context;
34375+ atomic_long_unchecked_t user_exception;
34376+ atomic_long_unchecked_t set_context_option;
34377+ atomic_long_unchecked_t check_context_retarget_intr;
34378+ atomic_long_unchecked_t check_context_unload;
34379+ atomic_long_unchecked_t tlb_dropin;
34380+ atomic_long_unchecked_t tlb_preload_page;
34381+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34382+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34383+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34384+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34385+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34386+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34387+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34388+ atomic_long_unchecked_t tfh_stale_on_fault;
34389+ atomic_long_unchecked_t mmu_invalidate_range;
34390+ atomic_long_unchecked_t mmu_invalidate_page;
34391+ atomic_long_unchecked_t flush_tlb;
34392+ atomic_long_unchecked_t flush_tlb_gru;
34393+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34394+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34395
34396- atomic_long_t copy_gpa;
34397- atomic_long_t read_gpa;
34398+ atomic_long_unchecked_t copy_gpa;
34399+ atomic_long_unchecked_t read_gpa;
34400
34401- atomic_long_t mesq_receive;
34402- atomic_long_t mesq_receive_none;
34403- atomic_long_t mesq_send;
34404- atomic_long_t mesq_send_failed;
34405- atomic_long_t mesq_noop;
34406- atomic_long_t mesq_send_unexpected_error;
34407- atomic_long_t mesq_send_lb_overflow;
34408- atomic_long_t mesq_send_qlimit_reached;
34409- atomic_long_t mesq_send_amo_nacked;
34410- atomic_long_t mesq_send_put_nacked;
34411- atomic_long_t mesq_page_overflow;
34412- atomic_long_t mesq_qf_locked;
34413- atomic_long_t mesq_qf_noop_not_full;
34414- atomic_long_t mesq_qf_switch_head_failed;
34415- atomic_long_t mesq_qf_unexpected_error;
34416- atomic_long_t mesq_noop_unexpected_error;
34417- atomic_long_t mesq_noop_lb_overflow;
34418- atomic_long_t mesq_noop_qlimit_reached;
34419- atomic_long_t mesq_noop_amo_nacked;
34420- atomic_long_t mesq_noop_put_nacked;
34421- atomic_long_t mesq_noop_page_overflow;
34422+ atomic_long_unchecked_t mesq_receive;
34423+ atomic_long_unchecked_t mesq_receive_none;
34424+ atomic_long_unchecked_t mesq_send;
34425+ atomic_long_unchecked_t mesq_send_failed;
34426+ atomic_long_unchecked_t mesq_noop;
34427+ atomic_long_unchecked_t mesq_send_unexpected_error;
34428+ atomic_long_unchecked_t mesq_send_lb_overflow;
34429+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34430+ atomic_long_unchecked_t mesq_send_amo_nacked;
34431+ atomic_long_unchecked_t mesq_send_put_nacked;
34432+ atomic_long_unchecked_t mesq_page_overflow;
34433+ atomic_long_unchecked_t mesq_qf_locked;
34434+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34435+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34436+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34437+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34438+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34439+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34440+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34441+ atomic_long_unchecked_t mesq_noop_put_nacked;
34442+ atomic_long_unchecked_t mesq_noop_page_overflow;
34443
34444 };
34445
34446@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34447 tghop_invalidate, mcsop_last};
34448
34449 struct mcs_op_statistic {
34450- atomic_long_t count;
34451- atomic_long_t total;
34452+ atomic_long_unchecked_t count;
34453+ atomic_long_unchecked_t total;
34454 unsigned long max;
34455 };
34456
34457@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34458
34459 #define STAT(id) do { \
34460 if (gru_options & OPT_STATS) \
34461- atomic_long_inc(&gru_stats.id); \
34462+ atomic_long_inc_unchecked(&gru_stats.id); \
34463 } while (0)
34464
34465 #ifdef CONFIG_SGI_GRU_DEBUG
34466diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34467index c862cd4..0d176fe 100644
34468--- a/drivers/misc/sgi-xp/xp.h
34469+++ b/drivers/misc/sgi-xp/xp.h
34470@@ -288,7 +288,7 @@ struct xpc_interface {
34471 xpc_notify_func, void *);
34472 void (*received) (short, int, void *);
34473 enum xp_retval (*partid_to_nasids) (short, void *);
34474-};
34475+} __no_const;
34476
34477 extern struct xpc_interface xpc_interface;
34478
34479diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34480index b94d5f7..7f494c5 100644
34481--- a/drivers/misc/sgi-xp/xpc.h
34482+++ b/drivers/misc/sgi-xp/xpc.h
34483@@ -835,6 +835,7 @@ struct xpc_arch_operations {
34484 void (*received_payload) (struct xpc_channel *, void *);
34485 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34486 };
34487+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34488
34489 /* struct xpc_partition act_state values (for XPC HB) */
34490
34491@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34492 /* found in xpc_main.c */
34493 extern struct device *xpc_part;
34494 extern struct device *xpc_chan;
34495-extern struct xpc_arch_operations xpc_arch_ops;
34496+extern xpc_arch_operations_no_const xpc_arch_ops;
34497 extern int xpc_disengage_timelimit;
34498 extern int xpc_disengage_timedout;
34499 extern int xpc_activate_IRQ_rcvd;
34500diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34501index 8d082b4..aa749ae 100644
34502--- a/drivers/misc/sgi-xp/xpc_main.c
34503+++ b/drivers/misc/sgi-xp/xpc_main.c
34504@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34505 .notifier_call = xpc_system_die,
34506 };
34507
34508-struct xpc_arch_operations xpc_arch_ops;
34509+xpc_arch_operations_no_const xpc_arch_ops;
34510
34511 /*
34512 * Timer function to enforce the timelimit on the partition disengage.
34513diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
34514index 2b62232..acfaeeb 100644
34515--- a/drivers/misc/ti-st/st_core.c
34516+++ b/drivers/misc/ti-st/st_core.c
34517@@ -349,6 +349,11 @@ void st_int_recv(void *disc_data,
34518 st_gdata->rx_skb = alloc_skb(
34519 st_gdata->list[type]->max_frame_size,
34520 GFP_ATOMIC);
34521+ if (st_gdata->rx_skb == NULL) {
34522+ pr_err("out of memory: dropping\n");
34523+ goto done;
34524+ }
34525+
34526 skb_reserve(st_gdata->rx_skb,
34527 st_gdata->list[type]->reserve);
34528 /* next 2 required for BT only */
34529diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34530index 69ef0be..f3ef91e 100644
34531--- a/drivers/mmc/host/sdhci-pci.c
34532+++ b/drivers/mmc/host/sdhci-pci.c
34533@@ -652,7 +652,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34534 .probe = via_probe,
34535 };
34536
34537-static const struct pci_device_id pci_ids[] __devinitdata = {
34538+static const struct pci_device_id pci_ids[] __devinitconst = {
34539 {
34540 .vendor = PCI_VENDOR_ID_RICOH,
34541 .device = PCI_DEVICE_ID_RICOH_R5C822,
34542diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34543index a4eb8b5..8c0628f 100644
34544--- a/drivers/mtd/devices/doc2000.c
34545+++ b/drivers/mtd/devices/doc2000.c
34546@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34547
34548 /* The ECC will not be calculated correctly if less than 512 is written */
34549 /* DBB-
34550- if (len != 0x200 && eccbuf)
34551+ if (len != 0x200)
34552 printk(KERN_WARNING
34553 "ECC needs a full sector write (adr: %lx size %lx)\n",
34554 (long) to, (long) len);
34555diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34556index a9e57d6..c6d8731 100644
34557--- a/drivers/mtd/nand/denali.c
34558+++ b/drivers/mtd/nand/denali.c
34559@@ -26,6 +26,7 @@
34560 #include <linux/pci.h>
34561 #include <linux/mtd/mtd.h>
34562 #include <linux/module.h>
34563+#include <linux/slab.h>
34564
34565 #include "denali.h"
34566
34567diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34568index 51b9d6a..52af9a7 100644
34569--- a/drivers/mtd/nftlmount.c
34570+++ b/drivers/mtd/nftlmount.c
34571@@ -24,6 +24,7 @@
34572 #include <asm/errno.h>
34573 #include <linux/delay.h>
34574 #include <linux/slab.h>
34575+#include <linux/sched.h>
34576 #include <linux/mtd/mtd.h>
34577 #include <linux/mtd/nand.h>
34578 #include <linux/mtd/nftl.h>
34579diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34580index 6762dc4..9956862 100644
34581--- a/drivers/net/ethernet/atheros/atlx/atl2.c
34582+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34583@@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34584 */
34585
34586 #define ATL2_PARAM(X, desc) \
34587- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34588+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34589 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34590 MODULE_PARM_DESC(X, desc);
34591 #else
34592diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34593index 61a7670..7da6e34 100644
34594--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34595+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34596@@ -483,7 +483,7 @@ struct bnx2x_rx_mode_obj {
34597
34598 int (*wait_comp)(struct bnx2x *bp,
34599 struct bnx2x_rx_mode_ramrod_params *p);
34600-};
34601+} __no_const;
34602
34603 /********************** Set multicast group ***********************************/
34604
34605diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34606index 93865f8..5448741 100644
34607--- a/drivers/net/ethernet/broadcom/tg3.h
34608+++ b/drivers/net/ethernet/broadcom/tg3.h
34609@@ -140,6 +140,7 @@
34610 #define CHIPREV_ID_5750_A0 0x4000
34611 #define CHIPREV_ID_5750_A1 0x4001
34612 #define CHIPREV_ID_5750_A3 0x4003
34613+#define CHIPREV_ID_5750_C1 0x4201
34614 #define CHIPREV_ID_5750_C2 0x4202
34615 #define CHIPREV_ID_5752_A0_HW 0x5000
34616 #define CHIPREV_ID_5752_A0 0x6000
34617diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34618index c4e8643..0979484 100644
34619--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34620+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34621@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34622 */
34623 struct l2t_skb_cb {
34624 arp_failure_handler_func arp_failure_handler;
34625-};
34626+} __no_const;
34627
34628 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34629
34630diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34631index 18b106c..2b38d36 100644
34632--- a/drivers/net/ethernet/dec/tulip/de4x5.c
34633+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34634@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34635 for (i=0; i<ETH_ALEN; i++) {
34636 tmp.addr[i] = dev->dev_addr[i];
34637 }
34638- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34639+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34640 break;
34641
34642 case DE4X5_SET_HWADDR: /* Set the hardware address */
34643@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34644 spin_lock_irqsave(&lp->lock, flags);
34645 memcpy(&statbuf, &lp->pktStats, ioc->len);
34646 spin_unlock_irqrestore(&lp->lock, flags);
34647- if (copy_to_user(ioc->data, &statbuf, ioc->len))
34648+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34649 return -EFAULT;
34650 break;
34651 }
34652diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34653index ed7d1dc..d426748 100644
34654--- a/drivers/net/ethernet/dec/tulip/eeprom.c
34655+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34656@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34657 {NULL}};
34658
34659
34660-static const char *block_name[] __devinitdata = {
34661+static const char *block_name[] __devinitconst = {
34662 "21140 non-MII",
34663 "21140 MII PHY",
34664 "21142 Serial PHY",
34665diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34666index 2ac6fff..2d127d0 100644
34667--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34668+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34669@@ -236,7 +236,7 @@ struct pci_id_info {
34670 int drv_flags; /* Driver use, intended as capability flags. */
34671 };
34672
34673-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34674+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34675 { /* Sometime a Level-One switch card. */
34676 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34677 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34678diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34679index d783f4f..97fa1b0 100644
34680--- a/drivers/net/ethernet/dlink/sundance.c
34681+++ b/drivers/net/ethernet/dlink/sundance.c
34682@@ -218,7 +218,7 @@ enum {
34683 struct pci_id_info {
34684 const char *name;
34685 };
34686-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34687+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34688 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34689 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34690 {"D-Link DFE-580TX 4 port Server Adapter"},
34691diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34692index 1bbf6b3..430dcd0 100644
34693--- a/drivers/net/ethernet/emulex/benet/be_main.c
34694+++ b/drivers/net/ethernet/emulex/benet/be_main.c
34695@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34696
34697 if (wrapped)
34698 newacc += 65536;
34699- ACCESS_ONCE(*acc) = newacc;
34700+ ACCESS_ONCE_RW(*acc) = newacc;
34701 }
34702
34703 void be_parse_stats(struct be_adapter *adapter)
34704diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34705index 16b0704..d2c07d7 100644
34706--- a/drivers/net/ethernet/faraday/ftgmac100.c
34707+++ b/drivers/net/ethernet/faraday/ftgmac100.c
34708@@ -31,6 +31,8 @@
34709 #include <linux/netdevice.h>
34710 #include <linux/phy.h>
34711 #include <linux/platform_device.h>
34712+#include <linux/interrupt.h>
34713+#include <linux/irqreturn.h>
34714 #include <net/ip.h>
34715
34716 #include "ftgmac100.h"
34717diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34718index 829b109..4ae5f6a 100644
34719--- a/drivers/net/ethernet/faraday/ftmac100.c
34720+++ b/drivers/net/ethernet/faraday/ftmac100.c
34721@@ -31,6 +31,8 @@
34722 #include <linux/module.h>
34723 #include <linux/netdevice.h>
34724 #include <linux/platform_device.h>
34725+#include <linux/interrupt.h>
34726+#include <linux/irqreturn.h>
34727
34728 #include "ftmac100.h"
34729
34730diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34731index 1637b98..c42f87b 100644
34732--- a/drivers/net/ethernet/fealnx.c
34733+++ b/drivers/net/ethernet/fealnx.c
34734@@ -150,7 +150,7 @@ struct chip_info {
34735 int flags;
34736 };
34737
34738-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34739+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34740 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34741 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34742 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34743diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34744index b83897f..b2d970f 100644
34745--- a/drivers/net/ethernet/intel/e1000e/e1000.h
34746+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34747@@ -181,7 +181,7 @@ struct e1000_info;
34748 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34749 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34750 E1000_TXDCTL_COUNT_DESC | \
34751- (5 << 16) | /* wthresh must be +1 more than desired */\
34752+ (1 << 16) | /* wthresh must be +1 more than desired */\
34753 (1 << 8) | /* hthresh */ \
34754 0x1f) /* pthresh */
34755
34756diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34757index f82ecf5..7d59ecb 100644
34758--- a/drivers/net/ethernet/intel/e1000e/hw.h
34759+++ b/drivers/net/ethernet/intel/e1000e/hw.h
34760@@ -784,6 +784,7 @@ struct e1000_mac_operations {
34761 void (*config_collision_dist)(struct e1000_hw *);
34762 s32 (*read_mac_addr)(struct e1000_hw *);
34763 };
34764+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34765
34766 /*
34767 * When to use various PHY register access functions:
34768@@ -824,6 +825,7 @@ struct e1000_phy_operations {
34769 void (*power_up)(struct e1000_hw *);
34770 void (*power_down)(struct e1000_hw *);
34771 };
34772+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34773
34774 /* Function pointers for the NVM. */
34775 struct e1000_nvm_operations {
34776@@ -836,9 +838,10 @@ struct e1000_nvm_operations {
34777 s32 (*validate)(struct e1000_hw *);
34778 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34779 };
34780+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34781
34782 struct e1000_mac_info {
34783- struct e1000_mac_operations ops;
34784+ e1000_mac_operations_no_const ops;
34785 u8 addr[ETH_ALEN];
34786 u8 perm_addr[ETH_ALEN];
34787
34788@@ -879,7 +882,7 @@ struct e1000_mac_info {
34789 };
34790
34791 struct e1000_phy_info {
34792- struct e1000_phy_operations ops;
34793+ e1000_phy_operations_no_const ops;
34794
34795 enum e1000_phy_type type;
34796
34797@@ -913,7 +916,7 @@ struct e1000_phy_info {
34798 };
34799
34800 struct e1000_nvm_info {
34801- struct e1000_nvm_operations ops;
34802+ e1000_nvm_operations_no_const ops;
34803
34804 enum e1000_nvm_type type;
34805 enum e1000_nvm_override override;
34806diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34807index f67cbd3..cef9e3d 100644
34808--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34809+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34810@@ -314,6 +314,7 @@ struct e1000_mac_operations {
34811 s32 (*read_mac_addr)(struct e1000_hw *);
34812 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
34813 };
34814+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34815
34816 struct e1000_phy_operations {
34817 s32 (*acquire)(struct e1000_hw *);
34818@@ -330,6 +331,7 @@ struct e1000_phy_operations {
34819 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34820 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34821 };
34822+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34823
34824 struct e1000_nvm_operations {
34825 s32 (*acquire)(struct e1000_hw *);
34826@@ -339,6 +341,7 @@ struct e1000_nvm_operations {
34827 s32 (*update)(struct e1000_hw *);
34828 s32 (*validate)(struct e1000_hw *);
34829 };
34830+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34831
34832 struct e1000_info {
34833 s32 (*get_invariants)(struct e1000_hw *);
34834@@ -350,7 +353,7 @@ struct e1000_info {
34835 extern const struct e1000_info e1000_82575_info;
34836
34837 struct e1000_mac_info {
34838- struct e1000_mac_operations ops;
34839+ e1000_mac_operations_no_const ops;
34840
34841 u8 addr[6];
34842 u8 perm_addr[6];
34843@@ -388,7 +391,7 @@ struct e1000_mac_info {
34844 };
34845
34846 struct e1000_phy_info {
34847- struct e1000_phy_operations ops;
34848+ e1000_phy_operations_no_const ops;
34849
34850 enum e1000_phy_type type;
34851
34852@@ -423,7 +426,7 @@ struct e1000_phy_info {
34853 };
34854
34855 struct e1000_nvm_info {
34856- struct e1000_nvm_operations ops;
34857+ e1000_nvm_operations_no_const ops;
34858 enum e1000_nvm_type type;
34859 enum e1000_nvm_override override;
34860
34861@@ -468,6 +471,7 @@ struct e1000_mbx_operations {
34862 s32 (*check_for_ack)(struct e1000_hw *, u16);
34863 s32 (*check_for_rst)(struct e1000_hw *, u16);
34864 };
34865+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34866
34867 struct e1000_mbx_stats {
34868 u32 msgs_tx;
34869@@ -479,7 +483,7 @@ struct e1000_mbx_stats {
34870 };
34871
34872 struct e1000_mbx_info {
34873- struct e1000_mbx_operations ops;
34874+ e1000_mbx_operations_no_const ops;
34875 struct e1000_mbx_stats stats;
34876 u32 timeout;
34877 u32 usec_delay;
34878diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34879index 57db3c6..aa825fc 100644
34880--- a/drivers/net/ethernet/intel/igbvf/vf.h
34881+++ b/drivers/net/ethernet/intel/igbvf/vf.h
34882@@ -189,9 +189,10 @@ struct e1000_mac_operations {
34883 s32 (*read_mac_addr)(struct e1000_hw *);
34884 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34885 };
34886+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34887
34888 struct e1000_mac_info {
34889- struct e1000_mac_operations ops;
34890+ e1000_mac_operations_no_const ops;
34891 u8 addr[6];
34892 u8 perm_addr[6];
34893
34894@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34895 s32 (*check_for_ack)(struct e1000_hw *);
34896 s32 (*check_for_rst)(struct e1000_hw *);
34897 };
34898+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34899
34900 struct e1000_mbx_stats {
34901 u32 msgs_tx;
34902@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34903 };
34904
34905 struct e1000_mbx_info {
34906- struct e1000_mbx_operations ops;
34907+ e1000_mbx_operations_no_const ops;
34908 struct e1000_mbx_stats stats;
34909 u32 timeout;
34910 u32 usec_delay;
34911diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34912index 8636e83..ab9bbc3 100644
34913--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34914+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34915@@ -2710,6 +2710,7 @@ struct ixgbe_eeprom_operations {
34916 s32 (*update_checksum)(struct ixgbe_hw *);
34917 u16 (*calc_checksum)(struct ixgbe_hw *);
34918 };
34919+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34920
34921 struct ixgbe_mac_operations {
34922 s32 (*init_hw)(struct ixgbe_hw *);
34923@@ -2773,6 +2774,7 @@ struct ixgbe_mac_operations {
34924 /* Manageability interface */
34925 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
34926 };
34927+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34928
34929 struct ixgbe_phy_operations {
34930 s32 (*identify)(struct ixgbe_hw *);
34931@@ -2792,9 +2794,10 @@ struct ixgbe_phy_operations {
34932 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34933 s32 (*check_overtemp)(struct ixgbe_hw *);
34934 };
34935+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34936
34937 struct ixgbe_eeprom_info {
34938- struct ixgbe_eeprom_operations ops;
34939+ ixgbe_eeprom_operations_no_const ops;
34940 enum ixgbe_eeprom_type type;
34941 u32 semaphore_delay;
34942 u16 word_size;
34943@@ -2804,7 +2807,7 @@ struct ixgbe_eeprom_info {
34944
34945 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34946 struct ixgbe_mac_info {
34947- struct ixgbe_mac_operations ops;
34948+ ixgbe_mac_operations_no_const ops;
34949 enum ixgbe_mac_type type;
34950 u8 addr[ETH_ALEN];
34951 u8 perm_addr[ETH_ALEN];
34952@@ -2832,7 +2835,7 @@ struct ixgbe_mac_info {
34953 };
34954
34955 struct ixgbe_phy_info {
34956- struct ixgbe_phy_operations ops;
34957+ ixgbe_phy_operations_no_const ops;
34958 struct mdio_if_info mdio;
34959 enum ixgbe_phy_type type;
34960 u32 id;
34961@@ -2860,6 +2863,7 @@ struct ixgbe_mbx_operations {
34962 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34963 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34964 };
34965+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34966
34967 struct ixgbe_mbx_stats {
34968 u32 msgs_tx;
34969@@ -2871,7 +2875,7 @@ struct ixgbe_mbx_stats {
34970 };
34971
34972 struct ixgbe_mbx_info {
34973- struct ixgbe_mbx_operations ops;
34974+ ixgbe_mbx_operations_no_const ops;
34975 struct ixgbe_mbx_stats stats;
34976 u32 timeout;
34977 u32 usec_delay;
34978diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
34979index 307611a..d8e4562 100644
34980--- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
34981+++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
34982@@ -969,8 +969,6 @@ static irqreturn_t ixgbevf_msix_clean_tx(int irq, void *data)
34983 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
34984 for (i = 0; i < q_vector->txr_count; i++) {
34985 tx_ring = &(adapter->tx_ring[r_idx]);
34986- tx_ring->total_bytes = 0;
34987- tx_ring->total_packets = 0;
34988 ixgbevf_clean_tx_irq(adapter, tx_ring);
34989 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
34990 r_idx + 1);
34991@@ -994,16 +992,6 @@ static irqreturn_t ixgbevf_msix_clean_rx(int irq, void *data)
34992 struct ixgbe_hw *hw = &adapter->hw;
34993 struct ixgbevf_ring *rx_ring;
34994 int r_idx;
34995- int i;
34996-
34997- r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
34998- for (i = 0; i < q_vector->rxr_count; i++) {
34999- rx_ring = &(adapter->rx_ring[r_idx]);
35000- rx_ring->total_bytes = 0;
35001- rx_ring->total_packets = 0;
35002- r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
35003- r_idx + 1);
35004- }
35005
35006 if (!q_vector->rxr_count)
35007 return IRQ_HANDLED;
35008diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35009index 25c951d..cc7cf33 100644
35010--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35011+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35012@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35013 s32 (*clear_vfta)(struct ixgbe_hw *);
35014 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35015 };
35016+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35017
35018 enum ixgbe_mac_type {
35019 ixgbe_mac_unknown = 0,
35020@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35021 };
35022
35023 struct ixgbe_mac_info {
35024- struct ixgbe_mac_operations ops;
35025+ ixgbe_mac_operations_no_const ops;
35026 u8 addr[6];
35027 u8 perm_addr[6];
35028
35029@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35030 s32 (*check_for_ack)(struct ixgbe_hw *);
35031 s32 (*check_for_rst)(struct ixgbe_hw *);
35032 };
35033+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35034
35035 struct ixgbe_mbx_stats {
35036 u32 msgs_tx;
35037@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35038 };
35039
35040 struct ixgbe_mbx_info {
35041- struct ixgbe_mbx_operations ops;
35042+ ixgbe_mbx_operations_no_const ops;
35043 struct ixgbe_mbx_stats stats;
35044 u32 timeout;
35045 u32 udelay;
35046diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35047index 8bb05b4..074796f 100644
35048--- a/drivers/net/ethernet/mellanox/mlx4/main.c
35049+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35050@@ -41,6 +41,7 @@
35051 #include <linux/slab.h>
35052 #include <linux/io-mapping.h>
35053 #include <linux/delay.h>
35054+#include <linux/sched.h>
35055
35056 #include <linux/mlx4/device.h>
35057 #include <linux/mlx4/doorbell.h>
35058diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35059index 5046a64..71ca936 100644
35060--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35061+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35062@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35063 void (*link_down)(struct __vxge_hw_device *devh);
35064 void (*crit_err)(struct __vxge_hw_device *devh,
35065 enum vxge_hw_event type, u64 ext_data);
35066-};
35067+} __no_const;
35068
35069 /*
35070 * struct __vxge_hw_blockpool_entry - Block private data structure
35071diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35072index 4a518a3..936b334 100644
35073--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35074+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35075@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35076 struct vxge_hw_mempool_dma *dma_object,
35077 u32 index,
35078 u32 is_last);
35079-};
35080+} __no_const;
35081
35082 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35083 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35084diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35085index 161e045..0bb5b86 100644
35086--- a/drivers/net/ethernet/realtek/r8169.c
35087+++ b/drivers/net/ethernet/realtek/r8169.c
35088@@ -708,17 +708,17 @@ struct rtl8169_private {
35089 struct mdio_ops {
35090 void (*write)(void __iomem *, int, int);
35091 int (*read)(void __iomem *, int);
35092- } mdio_ops;
35093+ } __no_const mdio_ops;
35094
35095 struct pll_power_ops {
35096 void (*down)(struct rtl8169_private *);
35097 void (*up)(struct rtl8169_private *);
35098- } pll_power_ops;
35099+ } __no_const pll_power_ops;
35100
35101 struct jumbo_ops {
35102 void (*enable)(struct rtl8169_private *);
35103 void (*disable)(struct rtl8169_private *);
35104- } jumbo_ops;
35105+ } __no_const jumbo_ops;
35106
35107 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35108 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35109diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35110index a9deda8..5507c31 100644
35111--- a/drivers/net/ethernet/sis/sis190.c
35112+++ b/drivers/net/ethernet/sis/sis190.c
35113@@ -1620,7 +1620,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35114 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35115 struct net_device *dev)
35116 {
35117- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35118+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35119 struct sis190_private *tp = netdev_priv(dev);
35120 struct pci_dev *isa_bridge;
35121 u8 reg, tmp8;
35122diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35123index c07cfe9..81cbf7e 100644
35124--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35125+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35126@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35127
35128 writel(value, ioaddr + MMC_CNTRL);
35129
35130- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35131- MMC_CNTRL, value);
35132+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35133+// MMC_CNTRL, value);
35134 }
35135
35136 /* To mask all all interrupts.*/
35137diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35138index 9bdfaba..3d8f8d4 100644
35139--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35140+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35141@@ -1587,7 +1587,7 @@ static const struct file_operations stmmac_rings_status_fops = {
35142 .open = stmmac_sysfs_ring_open,
35143 .read = seq_read,
35144 .llseek = seq_lseek,
35145- .release = seq_release,
35146+ .release = single_release,
35147 };
35148
35149 static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
35150@@ -1659,7 +1659,7 @@ static const struct file_operations stmmac_dma_cap_fops = {
35151 .open = stmmac_sysfs_dma_cap_open,
35152 .read = seq_read,
35153 .llseek = seq_lseek,
35154- .release = seq_release,
35155+ .release = single_release,
35156 };
35157
35158 static int stmmac_init_fs(struct net_device *dev)
35159diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35160index c358245..8c1de63 100644
35161--- a/drivers/net/hyperv/hyperv_net.h
35162+++ b/drivers/net/hyperv/hyperv_net.h
35163@@ -98,7 +98,7 @@ struct rndis_device {
35164
35165 enum rndis_device_state state;
35166 bool link_state;
35167- atomic_t new_req_id;
35168+ atomic_unchecked_t new_req_id;
35169
35170 spinlock_t request_lock;
35171 struct list_head req_list;
35172diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35173index d6be64b..5d97e3b 100644
35174--- a/drivers/net/hyperv/rndis_filter.c
35175+++ b/drivers/net/hyperv/rndis_filter.c
35176@@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35177 * template
35178 */
35179 set = &rndis_msg->msg.set_req;
35180- set->req_id = atomic_inc_return(&dev->new_req_id);
35181+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35182
35183 /* Add to the request list */
35184 spin_lock_irqsave(&dev->request_lock, flags);
35185@@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35186
35187 /* Setup the rndis set */
35188 halt = &request->request_msg.msg.halt_req;
35189- halt->req_id = atomic_inc_return(&dev->new_req_id);
35190+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35191
35192 /* Ignore return since this msg is optional. */
35193 rndis_filter_send_request(dev, request);
35194diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35195index 21d7151..8034208 100644
35196--- a/drivers/net/ppp/ppp_generic.c
35197+++ b/drivers/net/ppp/ppp_generic.c
35198@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35199 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35200 struct ppp_stats stats;
35201 struct ppp_comp_stats cstats;
35202- char *vers;
35203
35204 switch (cmd) {
35205 case SIOCGPPPSTATS:
35206@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35207 break;
35208
35209 case SIOCGPPPVER:
35210- vers = PPP_VERSION;
35211- if (copy_to_user(addr, vers, strlen(vers) + 1))
35212+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35213 break;
35214 err = 0;
35215 break;
35216diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35217index b715e6b..6d2490f 100644
35218--- a/drivers/net/tokenring/abyss.c
35219+++ b/drivers/net/tokenring/abyss.c
35220@@ -450,10 +450,12 @@ static struct pci_driver abyss_driver = {
35221
35222 static int __init abyss_init (void)
35223 {
35224- abyss_netdev_ops = tms380tr_netdev_ops;
35225+ pax_open_kernel();
35226+ memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35227
35228- abyss_netdev_ops.ndo_open = abyss_open;
35229- abyss_netdev_ops.ndo_stop = abyss_close;
35230+ *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35231+ *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35232+ pax_close_kernel();
35233
35234 return pci_register_driver(&abyss_driver);
35235 }
35236diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35237index 28adcdf..ae82f35 100644
35238--- a/drivers/net/tokenring/madgemc.c
35239+++ b/drivers/net/tokenring/madgemc.c
35240@@ -742,9 +742,11 @@ static struct mca_driver madgemc_driver = {
35241
35242 static int __init madgemc_init (void)
35243 {
35244- madgemc_netdev_ops = tms380tr_netdev_ops;
35245- madgemc_netdev_ops.ndo_open = madgemc_open;
35246- madgemc_netdev_ops.ndo_stop = madgemc_close;
35247+ pax_open_kernel();
35248+ memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35249+ *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35250+ *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35251+ pax_close_kernel();
35252
35253 return mca_register_driver (&madgemc_driver);
35254 }
35255diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35256index 62d90e4..9d84237 100644
35257--- a/drivers/net/tokenring/proteon.c
35258+++ b/drivers/net/tokenring/proteon.c
35259@@ -352,9 +352,11 @@ static int __init proteon_init(void)
35260 struct platform_device *pdev;
35261 int i, num = 0, err = 0;
35262
35263- proteon_netdev_ops = tms380tr_netdev_ops;
35264- proteon_netdev_ops.ndo_open = proteon_open;
35265- proteon_netdev_ops.ndo_stop = tms380tr_close;
35266+ pax_open_kernel();
35267+ memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35268+ *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35269+ *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35270+ pax_close_kernel();
35271
35272 err = platform_driver_register(&proteon_driver);
35273 if (err)
35274diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35275index ee11e93..c8f19c7 100644
35276--- a/drivers/net/tokenring/skisa.c
35277+++ b/drivers/net/tokenring/skisa.c
35278@@ -362,9 +362,11 @@ static int __init sk_isa_init(void)
35279 struct platform_device *pdev;
35280 int i, num = 0, err = 0;
35281
35282- sk_isa_netdev_ops = tms380tr_netdev_ops;
35283- sk_isa_netdev_ops.ndo_open = sk_isa_open;
35284- sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35285+ pax_open_kernel();
35286+ memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35287+ *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35288+ *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35289+ pax_close_kernel();
35290
35291 err = platform_driver_register(&sk_isa_driver);
35292 if (err)
35293diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35294index 2d2a688..35f2372 100644
35295--- a/drivers/net/usb/hso.c
35296+++ b/drivers/net/usb/hso.c
35297@@ -71,7 +71,7 @@
35298 #include <asm/byteorder.h>
35299 #include <linux/serial_core.h>
35300 #include <linux/serial.h>
35301-
35302+#include <asm/local.h>
35303
35304 #define MOD_AUTHOR "Option Wireless"
35305 #define MOD_DESCRIPTION "USB High Speed Option driver"
35306@@ -257,7 +257,7 @@ struct hso_serial {
35307
35308 /* from usb_serial_port */
35309 struct tty_struct *tty;
35310- int open_count;
35311+ local_t open_count;
35312 spinlock_t serial_lock;
35313
35314 int (*write_data) (struct hso_serial *serial);
35315@@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35316 struct urb *urb;
35317
35318 urb = serial->rx_urb[0];
35319- if (serial->open_count > 0) {
35320+ if (local_read(&serial->open_count) > 0) {
35321 count = put_rxbuf_data(urb, serial);
35322 if (count == -1)
35323 return;
35324@@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35325 DUMP1(urb->transfer_buffer, urb->actual_length);
35326
35327 /* Anyone listening? */
35328- if (serial->open_count == 0)
35329+ if (local_read(&serial->open_count) == 0)
35330 return;
35331
35332 if (status == 0) {
35333@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35334 spin_unlock_irq(&serial->serial_lock);
35335
35336 /* check for port already opened, if not set the termios */
35337- serial->open_count++;
35338- if (serial->open_count == 1) {
35339+ if (local_inc_return(&serial->open_count) == 1) {
35340 serial->rx_state = RX_IDLE;
35341 /* Force default termio settings */
35342 _hso_serial_set_termios(tty, NULL);
35343@@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35344 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35345 if (result) {
35346 hso_stop_serial_device(serial->parent);
35347- serial->open_count--;
35348+ local_dec(&serial->open_count);
35349 kref_put(&serial->parent->ref, hso_serial_ref_free);
35350 }
35351 } else {
35352@@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35353
35354 /* reset the rts and dtr */
35355 /* do the actual close */
35356- serial->open_count--;
35357+ local_dec(&serial->open_count);
35358
35359- if (serial->open_count <= 0) {
35360- serial->open_count = 0;
35361+ if (local_read(&serial->open_count) <= 0) {
35362+ local_set(&serial->open_count, 0);
35363 spin_lock_irq(&serial->serial_lock);
35364 if (serial->tty == tty) {
35365 serial->tty->driver_data = NULL;
35366@@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35367
35368 /* the actual setup */
35369 spin_lock_irqsave(&serial->serial_lock, flags);
35370- if (serial->open_count)
35371+ if (local_read(&serial->open_count))
35372 _hso_serial_set_termios(tty, old);
35373 else
35374 tty->termios = old;
35375@@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35376 D1("Pending read interrupt on port %d\n", i);
35377 spin_lock(&serial->serial_lock);
35378 if (serial->rx_state == RX_IDLE &&
35379- serial->open_count > 0) {
35380+ local_read(&serial->open_count) > 0) {
35381 /* Setup and send a ctrl req read on
35382 * port i */
35383 if (!serial->rx_urb_filled[0]) {
35384@@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35385 /* Start all serial ports */
35386 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35387 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35388- if (dev2ser(serial_table[i])->open_count) {
35389+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
35390 result =
35391 hso_start_serial_device(serial_table[i], GFP_NOIO);
35392 hso_kick_transmit(dev2ser(serial_table[i]));
35393diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35394index 420d69b..74f90a2 100644
35395--- a/drivers/net/wireless/ath/ath.h
35396+++ b/drivers/net/wireless/ath/ath.h
35397@@ -119,6 +119,7 @@ struct ath_ops {
35398 void (*write_flush) (void *);
35399 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35400 };
35401+typedef struct ath_ops __no_const ath_ops_no_const;
35402
35403 struct ath_common;
35404 struct ath_bus_ops;
35405diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35406index aa2abaf..5f5152d 100644
35407--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35408+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35409@@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35410 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35411 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35412
35413- ACCESS_ONCE(ads->ds_link) = i->link;
35414- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35415+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35416+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35417
35418 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35419 ctl6 = SM(i->keytype, AR_EncrType);
35420@@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35421
35422 if ((i->is_first || i->is_last) &&
35423 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35424- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35425+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35426 | set11nTries(i->rates, 1)
35427 | set11nTries(i->rates, 2)
35428 | set11nTries(i->rates, 3)
35429 | (i->dur_update ? AR_DurUpdateEna : 0)
35430 | SM(0, AR_BurstDur);
35431
35432- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35433+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35434 | set11nRate(i->rates, 1)
35435 | set11nRate(i->rates, 2)
35436 | set11nRate(i->rates, 3);
35437 } else {
35438- ACCESS_ONCE(ads->ds_ctl2) = 0;
35439- ACCESS_ONCE(ads->ds_ctl3) = 0;
35440+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35441+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35442 }
35443
35444 if (!i->is_first) {
35445- ACCESS_ONCE(ads->ds_ctl0) = 0;
35446- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35447- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35448+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35449+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35450+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35451 return;
35452 }
35453
35454@@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35455 break;
35456 }
35457
35458- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35459+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35460 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35461 | SM(i->txpower, AR_XmitPower)
35462 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35463@@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35464 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35465 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35466
35467- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35468- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35469+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35470+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35471
35472 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35473 return;
35474
35475- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35476+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35477 | set11nPktDurRTSCTS(i->rates, 1);
35478
35479- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35480+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35481 | set11nPktDurRTSCTS(i->rates, 3);
35482
35483- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35484+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35485 | set11nRateFlags(i->rates, 1)
35486 | set11nRateFlags(i->rates, 2)
35487 | set11nRateFlags(i->rates, 3)
35488diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35489index a66a13b..0ef399e 100644
35490--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35491+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35492@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35493 (i->qcu << AR_TxQcuNum_S) | desc_len;
35494
35495 checksum += val;
35496- ACCESS_ONCE(ads->info) = val;
35497+ ACCESS_ONCE_RW(ads->info) = val;
35498
35499 checksum += i->link;
35500- ACCESS_ONCE(ads->link) = i->link;
35501+ ACCESS_ONCE_RW(ads->link) = i->link;
35502
35503 checksum += i->buf_addr[0];
35504- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35505+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35506 checksum += i->buf_addr[1];
35507- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35508+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35509 checksum += i->buf_addr[2];
35510- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35511+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35512 checksum += i->buf_addr[3];
35513- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35514+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35515
35516 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35517- ACCESS_ONCE(ads->ctl3) = val;
35518+ ACCESS_ONCE_RW(ads->ctl3) = val;
35519 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35520- ACCESS_ONCE(ads->ctl5) = val;
35521+ ACCESS_ONCE_RW(ads->ctl5) = val;
35522 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35523- ACCESS_ONCE(ads->ctl7) = val;
35524+ ACCESS_ONCE_RW(ads->ctl7) = val;
35525 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35526- ACCESS_ONCE(ads->ctl9) = val;
35527+ ACCESS_ONCE_RW(ads->ctl9) = val;
35528
35529 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35530- ACCESS_ONCE(ads->ctl10) = checksum;
35531+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
35532
35533 if (i->is_first || i->is_last) {
35534- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35535+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35536 | set11nTries(i->rates, 1)
35537 | set11nTries(i->rates, 2)
35538 | set11nTries(i->rates, 3)
35539 | (i->dur_update ? AR_DurUpdateEna : 0)
35540 | SM(0, AR_BurstDur);
35541
35542- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35543+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35544 | set11nRate(i->rates, 1)
35545 | set11nRate(i->rates, 2)
35546 | set11nRate(i->rates, 3);
35547 } else {
35548- ACCESS_ONCE(ads->ctl13) = 0;
35549- ACCESS_ONCE(ads->ctl14) = 0;
35550+ ACCESS_ONCE_RW(ads->ctl13) = 0;
35551+ ACCESS_ONCE_RW(ads->ctl14) = 0;
35552 }
35553
35554 ads->ctl20 = 0;
35555@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35556
35557 ctl17 = SM(i->keytype, AR_EncrType);
35558 if (!i->is_first) {
35559- ACCESS_ONCE(ads->ctl11) = 0;
35560- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35561- ACCESS_ONCE(ads->ctl15) = 0;
35562- ACCESS_ONCE(ads->ctl16) = 0;
35563- ACCESS_ONCE(ads->ctl17) = ctl17;
35564- ACCESS_ONCE(ads->ctl18) = 0;
35565- ACCESS_ONCE(ads->ctl19) = 0;
35566+ ACCESS_ONCE_RW(ads->ctl11) = 0;
35567+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35568+ ACCESS_ONCE_RW(ads->ctl15) = 0;
35569+ ACCESS_ONCE_RW(ads->ctl16) = 0;
35570+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35571+ ACCESS_ONCE_RW(ads->ctl18) = 0;
35572+ ACCESS_ONCE_RW(ads->ctl19) = 0;
35573 return;
35574 }
35575
35576- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35577+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35578 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35579 | SM(i->txpower, AR_XmitPower)
35580 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35581@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35582 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35583 ctl12 |= SM(val, AR_PAPRDChainMask);
35584
35585- ACCESS_ONCE(ads->ctl12) = ctl12;
35586- ACCESS_ONCE(ads->ctl17) = ctl17;
35587+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35588+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35589
35590- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35591+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35592 | set11nPktDurRTSCTS(i->rates, 1);
35593
35594- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35595+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35596 | set11nPktDurRTSCTS(i->rates, 3);
35597
35598- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35599+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35600 | set11nRateFlags(i->rates, 1)
35601 | set11nRateFlags(i->rates, 2)
35602 | set11nRateFlags(i->rates, 3)
35603 | SM(i->rtscts_rate, AR_RTSCTSRate);
35604
35605- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35606+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35607 }
35608
35609 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35610diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35611index e88f182..4e57f5d 100644
35612--- a/drivers/net/wireless/ath/ath9k/hw.h
35613+++ b/drivers/net/wireless/ath/ath9k/hw.h
35614@@ -614,7 +614,7 @@ struct ath_hw_private_ops {
35615
35616 /* ANI */
35617 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35618-};
35619+} __no_const;
35620
35621 /**
35622 * struct ath_hw_ops - callbacks used by hardware code and driver code
35623@@ -644,7 +644,7 @@ struct ath_hw_ops {
35624 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35625 struct ath_hw_antcomb_conf *antconf);
35626
35627-};
35628+} __no_const;
35629
35630 struct ath_nf_limits {
35631 s16 max;
35632@@ -664,7 +664,7 @@ enum ath_cal_list {
35633 #define AH_FASTCC 0x4
35634
35635 struct ath_hw {
35636- struct ath_ops reg_ops;
35637+ ath_ops_no_const reg_ops;
35638
35639 struct ieee80211_hw *hw;
35640 struct ath_common common;
35641diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35642index af00e2c..ab04d34 100644
35643--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35644+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35645@@ -545,7 +545,7 @@ struct phy_func_ptr {
35646 void (*carrsuppr)(struct brcms_phy *);
35647 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35648 void (*detach)(struct brcms_phy *);
35649-};
35650+} __no_const;
35651
35652 struct brcms_phy {
35653 struct brcms_phy_pub pubpi_ro;
35654diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35655index faec404..a5277f1 100644
35656--- a/drivers/net/wireless/iwlegacy/3945-mac.c
35657+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35658@@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35659 */
35660 if (il3945_mod_params.disable_hw_scan) {
35661 D_INFO("Disabling hw_scan\n");
35662- il3945_mac_ops.hw_scan = NULL;
35663+ pax_open_kernel();
35664+ *(void **)&il3945_mac_ops.hw_scan = NULL;
35665+ pax_close_kernel();
35666 }
35667
35668 D_INFO("*** LOAD DRIVER ***\n");
35669diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35670index b7ce6a6..5649756 100644
35671--- a/drivers/net/wireless/mac80211_hwsim.c
35672+++ b/drivers/net/wireless/mac80211_hwsim.c
35673@@ -1721,9 +1721,11 @@ static int __init init_mac80211_hwsim(void)
35674 return -EINVAL;
35675
35676 if (fake_hw_scan) {
35677- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35678- mac80211_hwsim_ops.sw_scan_start = NULL;
35679- mac80211_hwsim_ops.sw_scan_complete = NULL;
35680+ pax_open_kernel();
35681+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35682+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35683+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35684+ pax_close_kernel();
35685 }
35686
35687 spin_lock_init(&hwsim_radio_lock);
35688diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35689index 35225e9..95e6bf9 100644
35690--- a/drivers/net/wireless/mwifiex/main.h
35691+++ b/drivers/net/wireless/mwifiex/main.h
35692@@ -537,7 +537,7 @@ struct mwifiex_if_ops {
35693 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35694 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35695 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35696-};
35697+} __no_const;
35698
35699 struct mwifiex_adapter {
35700 u8 iface_type;
35701diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35702index d66e298..55b0a89 100644
35703--- a/drivers/net/wireless/rndis_wlan.c
35704+++ b/drivers/net/wireless/rndis_wlan.c
35705@@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35706
35707 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35708
35709- if (rts_threshold < 0 || rts_threshold > 2347)
35710+ if (rts_threshold > 2347)
35711 rts_threshold = 2347;
35712
35713 tmp = cpu_to_le32(rts_threshold);
35714diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35715index c264dfa..08ee30e 100644
35716--- a/drivers/net/wireless/rt2x00/rt2x00.h
35717+++ b/drivers/net/wireless/rt2x00/rt2x00.h
35718@@ -396,7 +396,7 @@ struct rt2x00_intf {
35719 * for hardware which doesn't support hardware
35720 * sequence counting.
35721 */
35722- atomic_t seqno;
35723+ atomic_unchecked_t seqno;
35724 };
35725
35726 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35727diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35728index 50f92d5..f3afc41 100644
35729--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35730+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35731@@ -229,9 +229,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35732 * sequence counter given by mac80211.
35733 */
35734 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35735- seqno = atomic_add_return(0x10, &intf->seqno);
35736+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35737 else
35738- seqno = atomic_read(&intf->seqno);
35739+ seqno = atomic_read_unchecked(&intf->seqno);
35740
35741 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35742 hdr->seq_ctrl |= cpu_to_le16(seqno);
35743diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35744index 9d8f581..0f6589e 100644
35745--- a/drivers/net/wireless/wl1251/wl1251.h
35746+++ b/drivers/net/wireless/wl1251/wl1251.h
35747@@ -266,7 +266,7 @@ struct wl1251_if_operations {
35748 void (*reset)(struct wl1251 *wl);
35749 void (*enable_irq)(struct wl1251 *wl);
35750 void (*disable_irq)(struct wl1251 *wl);
35751-};
35752+} __no_const;
35753
35754 struct wl1251 {
35755 struct ieee80211_hw *hw;
35756diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35757index f34b5b2..b5abb9f 100644
35758--- a/drivers/oprofile/buffer_sync.c
35759+++ b/drivers/oprofile/buffer_sync.c
35760@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35761 if (cookie == NO_COOKIE)
35762 offset = pc;
35763 if (cookie == INVALID_COOKIE) {
35764- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35765+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35766 offset = pc;
35767 }
35768 if (cookie != last_cookie) {
35769@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35770 /* add userspace sample */
35771
35772 if (!mm) {
35773- atomic_inc(&oprofile_stats.sample_lost_no_mm);
35774+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35775 return 0;
35776 }
35777
35778 cookie = lookup_dcookie(mm, s->eip, &offset);
35779
35780 if (cookie == INVALID_COOKIE) {
35781- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35782+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35783 return 0;
35784 }
35785
35786@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35787 /* ignore backtraces if failed to add a sample */
35788 if (state == sb_bt_start) {
35789 state = sb_bt_ignore;
35790- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35791+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35792 }
35793 }
35794 release_mm(mm);
35795diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35796index c0cc4e7..44d4e54 100644
35797--- a/drivers/oprofile/event_buffer.c
35798+++ b/drivers/oprofile/event_buffer.c
35799@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35800 }
35801
35802 if (buffer_pos == buffer_size) {
35803- atomic_inc(&oprofile_stats.event_lost_overflow);
35804+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35805 return;
35806 }
35807
35808diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35809index ed2c3ec..deda85a 100644
35810--- a/drivers/oprofile/oprof.c
35811+++ b/drivers/oprofile/oprof.c
35812@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35813 if (oprofile_ops.switch_events())
35814 return;
35815
35816- atomic_inc(&oprofile_stats.multiplex_counter);
35817+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35818 start_switch_worker();
35819 }
35820
35821diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35822index 917d28e..d62d981 100644
35823--- a/drivers/oprofile/oprofile_stats.c
35824+++ b/drivers/oprofile/oprofile_stats.c
35825@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35826 cpu_buf->sample_invalid_eip = 0;
35827 }
35828
35829- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35830- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35831- atomic_set(&oprofile_stats.event_lost_overflow, 0);
35832- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35833- atomic_set(&oprofile_stats.multiplex_counter, 0);
35834+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35835+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35836+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35837+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35838+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35839 }
35840
35841
35842diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35843index 38b6fc0..b5cbfce 100644
35844--- a/drivers/oprofile/oprofile_stats.h
35845+++ b/drivers/oprofile/oprofile_stats.h
35846@@ -13,11 +13,11 @@
35847 #include <linux/atomic.h>
35848
35849 struct oprofile_stat_struct {
35850- atomic_t sample_lost_no_mm;
35851- atomic_t sample_lost_no_mapping;
35852- atomic_t bt_lost_no_mapping;
35853- atomic_t event_lost_overflow;
35854- atomic_t multiplex_counter;
35855+ atomic_unchecked_t sample_lost_no_mm;
35856+ atomic_unchecked_t sample_lost_no_mapping;
35857+ atomic_unchecked_t bt_lost_no_mapping;
35858+ atomic_unchecked_t event_lost_overflow;
35859+ atomic_unchecked_t multiplex_counter;
35860 };
35861
35862 extern struct oprofile_stat_struct oprofile_stats;
35863diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35864index 849357c..b83c1e0 100644
35865--- a/drivers/oprofile/oprofilefs.c
35866+++ b/drivers/oprofile/oprofilefs.c
35867@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35868
35869
35870 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35871- char const *name, atomic_t *val)
35872+ char const *name, atomic_unchecked_t *val)
35873 {
35874 return __oprofilefs_create_file(sb, root, name,
35875 &atomic_ro_fops, 0444, val);
35876diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35877index 3f56bc0..707d642 100644
35878--- a/drivers/parport/procfs.c
35879+++ b/drivers/parport/procfs.c
35880@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35881
35882 *ppos += len;
35883
35884- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35885+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35886 }
35887
35888 #ifdef CONFIG_PARPORT_1284
35889@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35890
35891 *ppos += len;
35892
35893- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35894+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35895 }
35896 #endif /* IEEE1284.3 support. */
35897
35898diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35899index 9fff878..ad0ad53 100644
35900--- a/drivers/pci/hotplug/cpci_hotplug.h
35901+++ b/drivers/pci/hotplug/cpci_hotplug.h
35902@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35903 int (*hardware_test) (struct slot* slot, u32 value);
35904 u8 (*get_power) (struct slot* slot);
35905 int (*set_power) (struct slot* slot, int value);
35906-};
35907+} __no_const;
35908
35909 struct cpci_hp_controller {
35910 unsigned int irq;
35911diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35912index 76ba8a1..20ca857 100644
35913--- a/drivers/pci/hotplug/cpqphp_nvram.c
35914+++ b/drivers/pci/hotplug/cpqphp_nvram.c
35915@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35916
35917 void compaq_nvram_init (void __iomem *rom_start)
35918 {
35919+
35920+#ifndef CONFIG_PAX_KERNEXEC
35921 if (rom_start) {
35922 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35923 }
35924+#endif
35925+
35926 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35927
35928 /* initialize our int15 lock */
35929diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35930index b500840..d7159d3 100644
35931--- a/drivers/pci/pcie/aspm.c
35932+++ b/drivers/pci/pcie/aspm.c
35933@@ -27,9 +27,9 @@
35934 #define MODULE_PARAM_PREFIX "pcie_aspm."
35935
35936 /* Note: those are not register definitions */
35937-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35938-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35939-#define ASPM_STATE_L1 (4) /* L1 state */
35940+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35941+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35942+#define ASPM_STATE_L1 (4U) /* L1 state */
35943 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35944 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35945
35946diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35947index 5e1ca3c..08082fe 100644
35948--- a/drivers/pci/probe.c
35949+++ b/drivers/pci/probe.c
35950@@ -215,7 +215,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35951 u16 orig_cmd;
35952 struct pci_bus_region region;
35953
35954- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35955+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35956
35957 if (!dev->mmio_always_on) {
35958 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35959diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35960index 27911b5..5b6db88 100644
35961--- a/drivers/pci/proc.c
35962+++ b/drivers/pci/proc.c
35963@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35964 static int __init pci_proc_init(void)
35965 {
35966 struct pci_dev *dev = NULL;
35967+
35968+#ifdef CONFIG_GRKERNSEC_PROC_ADD
35969+#ifdef CONFIG_GRKERNSEC_PROC_USER
35970+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35971+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35972+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35973+#endif
35974+#else
35975 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35976+#endif
35977 proc_create("devices", 0, proc_bus_pci_dir,
35978 &proc_bus_pci_dev_operations);
35979 proc_initialized = 1;
35980diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35981index d68c000..f6094ca 100644
35982--- a/drivers/platform/x86/thinkpad_acpi.c
35983+++ b/drivers/platform/x86/thinkpad_acpi.c
35984@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35985 return 0;
35986 }
35987
35988-void static hotkey_mask_warn_incomplete_mask(void)
35989+static void hotkey_mask_warn_incomplete_mask(void)
35990 {
35991 /* log only what the user can fix... */
35992 const u32 wantedmask = hotkey_driver_mask &
35993@@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35994 }
35995 }
35996
35997-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35998- struct tp_nvram_state *newn,
35999- const u32 event_mask)
36000-{
36001-
36002 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36003 do { \
36004 if ((event_mask & (1 << __scancode)) && \
36005@@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36006 tpacpi_hotkey_send_key(__scancode); \
36007 } while (0)
36008
36009- void issue_volchange(const unsigned int oldvol,
36010- const unsigned int newvol)
36011- {
36012- unsigned int i = oldvol;
36013+static void issue_volchange(const unsigned int oldvol,
36014+ const unsigned int newvol,
36015+ const u32 event_mask)
36016+{
36017+ unsigned int i = oldvol;
36018
36019- while (i > newvol) {
36020- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36021- i--;
36022- }
36023- while (i < newvol) {
36024- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36025- i++;
36026- }
36027+ while (i > newvol) {
36028+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36029+ i--;
36030 }
36031+ while (i < newvol) {
36032+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36033+ i++;
36034+ }
36035+}
36036
36037- void issue_brightnesschange(const unsigned int oldbrt,
36038- const unsigned int newbrt)
36039- {
36040- unsigned int i = oldbrt;
36041+static void issue_brightnesschange(const unsigned int oldbrt,
36042+ const unsigned int newbrt,
36043+ const u32 event_mask)
36044+{
36045+ unsigned int i = oldbrt;
36046
36047- while (i > newbrt) {
36048- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36049- i--;
36050- }
36051- while (i < newbrt) {
36052- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36053- i++;
36054- }
36055+ while (i > newbrt) {
36056+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36057+ i--;
36058+ }
36059+ while (i < newbrt) {
36060+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36061+ i++;
36062 }
36063+}
36064
36065+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36066+ struct tp_nvram_state *newn,
36067+ const u32 event_mask)
36068+{
36069 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36070 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36071 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36072@@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36073 oldn->volume_level != newn->volume_level) {
36074 /* recently muted, or repeated mute keypress, or
36075 * multiple presses ending in mute */
36076- issue_volchange(oldn->volume_level, newn->volume_level);
36077+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36078 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36079 }
36080 } else {
36081@@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36082 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36083 }
36084 if (oldn->volume_level != newn->volume_level) {
36085- issue_volchange(oldn->volume_level, newn->volume_level);
36086+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36087 } else if (oldn->volume_toggle != newn->volume_toggle) {
36088 /* repeated vol up/down keypress at end of scale ? */
36089 if (newn->volume_level == 0)
36090@@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36091 /* handle brightness */
36092 if (oldn->brightness_level != newn->brightness_level) {
36093 issue_brightnesschange(oldn->brightness_level,
36094- newn->brightness_level);
36095+ newn->brightness_level,
36096+ event_mask);
36097 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36098 /* repeated key presses that didn't change state */
36099 if (newn->brightness_level == 0)
36100@@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36101 && !tp_features.bright_unkfw)
36102 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36103 }
36104+}
36105
36106 #undef TPACPI_COMPARE_KEY
36107 #undef TPACPI_MAY_SEND_KEY
36108-}
36109
36110 /*
36111 * Polling driver
36112diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36113index 769d265..a3a05ca 100644
36114--- a/drivers/pnp/pnpbios/bioscalls.c
36115+++ b/drivers/pnp/pnpbios/bioscalls.c
36116@@ -58,7 +58,7 @@ do { \
36117 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36118 } while(0)
36119
36120-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36121+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36122 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36123
36124 /*
36125@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36126
36127 cpu = get_cpu();
36128 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36129+
36130+ pax_open_kernel();
36131 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36132+ pax_close_kernel();
36133
36134 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36135 spin_lock_irqsave(&pnp_bios_lock, flags);
36136@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36137 :"memory");
36138 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36139
36140+ pax_open_kernel();
36141 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36142+ pax_close_kernel();
36143+
36144 put_cpu();
36145
36146 /* If we get here and this is set then the PnP BIOS faulted on us. */
36147@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36148 return status;
36149 }
36150
36151-void pnpbios_calls_init(union pnp_bios_install_struct *header)
36152+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36153 {
36154 int i;
36155
36156@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36157 pnp_bios_callpoint.offset = header->fields.pm16offset;
36158 pnp_bios_callpoint.segment = PNP_CS16;
36159
36160+ pax_open_kernel();
36161+
36162 for_each_possible_cpu(i) {
36163 struct desc_struct *gdt = get_cpu_gdt_table(i);
36164 if (!gdt)
36165@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36166 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36167 (unsigned long)__va(header->fields.pm16dseg));
36168 }
36169+
36170+ pax_close_kernel();
36171 }
36172diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36173index b0ecacb..7c9da2e 100644
36174--- a/drivers/pnp/resource.c
36175+++ b/drivers/pnp/resource.c
36176@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36177 return 1;
36178
36179 /* check if the resource is valid */
36180- if (*irq < 0 || *irq > 15)
36181+ if (*irq > 15)
36182 return 0;
36183
36184 /* check if the resource is reserved */
36185@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36186 return 1;
36187
36188 /* check if the resource is valid */
36189- if (*dma < 0 || *dma == 4 || *dma > 7)
36190+ if (*dma == 4 || *dma > 7)
36191 return 0;
36192
36193 /* check if the resource is reserved */
36194diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36195index 222ccd8..6275fa5 100644
36196--- a/drivers/power/bq27x00_battery.c
36197+++ b/drivers/power/bq27x00_battery.c
36198@@ -72,7 +72,7 @@
36199 struct bq27x00_device_info;
36200 struct bq27x00_access_methods {
36201 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36202-};
36203+} __no_const;
36204
36205 enum bq27x00_chip { BQ27000, BQ27500 };
36206
36207diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36208index 4c5b053..104263e 100644
36209--- a/drivers/regulator/max8660.c
36210+++ b/drivers/regulator/max8660.c
36211@@ -385,8 +385,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36212 max8660->shadow_regs[MAX8660_OVER1] = 5;
36213 } else {
36214 /* Otherwise devices can be toggled via software */
36215- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36216- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36217+ pax_open_kernel();
36218+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36219+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36220+ pax_close_kernel();
36221 }
36222
36223 /*
36224diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36225index 845aa22..99ec402 100644
36226--- a/drivers/regulator/mc13892-regulator.c
36227+++ b/drivers/regulator/mc13892-regulator.c
36228@@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36229 }
36230 mc13xxx_unlock(mc13892);
36231
36232- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36233+ pax_open_kernel();
36234+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36235 = mc13892_vcam_set_mode;
36236- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36237+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36238 = mc13892_vcam_get_mode;
36239+ pax_close_kernel();
36240
36241 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36242 ARRAY_SIZE(mc13892_regulators));
36243diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36244index cace6d3..f623fda 100644
36245--- a/drivers/rtc/rtc-dev.c
36246+++ b/drivers/rtc/rtc-dev.c
36247@@ -14,6 +14,7 @@
36248 #include <linux/module.h>
36249 #include <linux/rtc.h>
36250 #include <linux/sched.h>
36251+#include <linux/grsecurity.h>
36252 #include "rtc-core.h"
36253
36254 static dev_t rtc_devt;
36255@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36256 if (copy_from_user(&tm, uarg, sizeof(tm)))
36257 return -EFAULT;
36258
36259+ gr_log_timechange();
36260+
36261 return rtc_set_time(rtc, &tm);
36262
36263 case RTC_PIE_ON:
36264diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36265index 3fcf627..f334910 100644
36266--- a/drivers/scsi/aacraid/aacraid.h
36267+++ b/drivers/scsi/aacraid/aacraid.h
36268@@ -492,7 +492,7 @@ struct adapter_ops
36269 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36270 /* Administrative operations */
36271 int (*adapter_comm)(struct aac_dev * dev, int comm);
36272-};
36273+} __no_const;
36274
36275 /*
36276 * Define which interrupt handler needs to be installed
36277diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36278index 0d279c44..3d25a97 100644
36279--- a/drivers/scsi/aacraid/linit.c
36280+++ b/drivers/scsi/aacraid/linit.c
36281@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36282 #elif defined(__devinitconst)
36283 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36284 #else
36285-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36286+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36287 #endif
36288 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36289 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36290diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36291index ff80552..1c4120c 100644
36292--- a/drivers/scsi/aic94xx/aic94xx_init.c
36293+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36294@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36295 .lldd_ata_set_dmamode = asd_set_dmamode,
36296 };
36297
36298-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36299+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36300 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36301 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36302 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36303diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36304index 4ad7e36..d004679 100644
36305--- a/drivers/scsi/bfa/bfa.h
36306+++ b/drivers/scsi/bfa/bfa.h
36307@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36308 u32 *end);
36309 int cpe_vec_q0;
36310 int rme_vec_q0;
36311-};
36312+} __no_const;
36313 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36314
36315 struct bfa_faa_cbfn_s {
36316diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36317index f0f80e2..8ec946b 100644
36318--- a/drivers/scsi/bfa/bfa_fcpim.c
36319+++ b/drivers/scsi/bfa/bfa_fcpim.c
36320@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36321
36322 bfa_iotag_attach(fcp);
36323
36324- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36325+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36326 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36327 (fcp->num_itns * sizeof(struct bfa_itn_s));
36328 memset(fcp->itn_arr, 0,
36329@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36330 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36331 {
36332 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36333- struct bfa_itn_s *itn;
36334+ bfa_itn_s_no_const *itn;
36335
36336 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36337 itn->isr = isr;
36338diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36339index 36f26da..38a34a8 100644
36340--- a/drivers/scsi/bfa/bfa_fcpim.h
36341+++ b/drivers/scsi/bfa/bfa_fcpim.h
36342@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36343 struct bfa_itn_s {
36344 bfa_isr_func_t isr;
36345 };
36346+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36347
36348 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36349 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36350@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36351 struct list_head iotag_tio_free_q; /* free IO resources */
36352 struct list_head iotag_unused_q; /* unused IO resources*/
36353 struct bfa_iotag_s *iotag_arr;
36354- struct bfa_itn_s *itn_arr;
36355+ bfa_itn_s_no_const *itn_arr;
36356 int num_ioim_reqs;
36357 int num_fwtio_reqs;
36358 int num_itns;
36359diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36360index 1a99d4b..e85d64b 100644
36361--- a/drivers/scsi/bfa/bfa_ioc.h
36362+++ b/drivers/scsi/bfa/bfa_ioc.h
36363@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36364 bfa_ioc_disable_cbfn_t disable_cbfn;
36365 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36366 bfa_ioc_reset_cbfn_t reset_cbfn;
36367-};
36368+} __no_const;
36369
36370 /*
36371 * IOC event notification mechanism.
36372@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36373 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36374 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36375 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36376-};
36377+} __no_const;
36378
36379 /*
36380 * Queue element to wait for room in request queue. FIFO order is
36381diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36382index a3a056a..b9bbc2f 100644
36383--- a/drivers/scsi/hosts.c
36384+++ b/drivers/scsi/hosts.c
36385@@ -42,7 +42,7 @@
36386 #include "scsi_logging.h"
36387
36388
36389-static atomic_t scsi_host_next_hn; /* host_no for next new host */
36390+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36391
36392
36393 static void scsi_host_cls_release(struct device *dev)
36394@@ -360,7 +360,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36395 * subtract one because we increment first then return, but we need to
36396 * know what the next host number was before increment
36397 */
36398- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36399+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36400 shost->dma_channel = 0xff;
36401
36402 /* These three are default values which can be overridden */
36403diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36404index 500e20d..ebd3059 100644
36405--- a/drivers/scsi/hpsa.c
36406+++ b/drivers/scsi/hpsa.c
36407@@ -521,7 +521,7 @@ static inline u32 next_command(struct ctlr_info *h)
36408 u32 a;
36409
36410 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36411- return h->access.command_completed(h);
36412+ return h->access->command_completed(h);
36413
36414 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36415 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36416@@ -3002,7 +3002,7 @@ static void start_io(struct ctlr_info *h)
36417 while (!list_empty(&h->reqQ)) {
36418 c = list_entry(h->reqQ.next, struct CommandList, list);
36419 /* can't do anything if fifo is full */
36420- if ((h->access.fifo_full(h))) {
36421+ if ((h->access->fifo_full(h))) {
36422 dev_warn(&h->pdev->dev, "fifo full\n");
36423 break;
36424 }
36425@@ -3012,7 +3012,7 @@ static void start_io(struct ctlr_info *h)
36426 h->Qdepth--;
36427
36428 /* Tell the controller execute command */
36429- h->access.submit_command(h, c);
36430+ h->access->submit_command(h, c);
36431
36432 /* Put job onto the completed Q */
36433 addQ(&h->cmpQ, c);
36434@@ -3021,17 +3021,17 @@ static void start_io(struct ctlr_info *h)
36435
36436 static inline unsigned long get_next_completion(struct ctlr_info *h)
36437 {
36438- return h->access.command_completed(h);
36439+ return h->access->command_completed(h);
36440 }
36441
36442 static inline bool interrupt_pending(struct ctlr_info *h)
36443 {
36444- return h->access.intr_pending(h);
36445+ return h->access->intr_pending(h);
36446 }
36447
36448 static inline long interrupt_not_for_us(struct ctlr_info *h)
36449 {
36450- return (h->access.intr_pending(h) == 0) ||
36451+ return (h->access->intr_pending(h) == 0) ||
36452 (h->interrupts_enabled == 0);
36453 }
36454
36455@@ -3930,7 +3930,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36456 if (prod_index < 0)
36457 return -ENODEV;
36458 h->product_name = products[prod_index].product_name;
36459- h->access = *(products[prod_index].access);
36460+ h->access = products[prod_index].access;
36461
36462 if (hpsa_board_disabled(h->pdev)) {
36463 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36464@@ -4175,7 +4175,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36465
36466 assert_spin_locked(&lockup_detector_lock);
36467 remove_ctlr_from_lockup_detector_list(h);
36468- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36469+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36470 spin_lock_irqsave(&h->lock, flags);
36471 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36472 spin_unlock_irqrestore(&h->lock, flags);
36473@@ -4355,7 +4355,7 @@ reinit_after_soft_reset:
36474 }
36475
36476 /* make sure the board interrupts are off */
36477- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36478+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36479
36480 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36481 goto clean2;
36482@@ -4389,7 +4389,7 @@ reinit_after_soft_reset:
36483 * fake ones to scoop up any residual completions.
36484 */
36485 spin_lock_irqsave(&h->lock, flags);
36486- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36487+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36488 spin_unlock_irqrestore(&h->lock, flags);
36489 free_irq(h->intr[h->intr_mode], h);
36490 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36491@@ -4408,9 +4408,9 @@ reinit_after_soft_reset:
36492 dev_info(&h->pdev->dev, "Board READY.\n");
36493 dev_info(&h->pdev->dev,
36494 "Waiting for stale completions to drain.\n");
36495- h->access.set_intr_mask(h, HPSA_INTR_ON);
36496+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36497 msleep(10000);
36498- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36499+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36500
36501 rc = controller_reset_failed(h->cfgtable);
36502 if (rc)
36503@@ -4431,7 +4431,7 @@ reinit_after_soft_reset:
36504 }
36505
36506 /* Turn the interrupts on so we can service requests */
36507- h->access.set_intr_mask(h, HPSA_INTR_ON);
36508+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36509
36510 hpsa_hba_inquiry(h);
36511 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36512@@ -4483,7 +4483,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36513 * To write all data in the battery backed cache to disks
36514 */
36515 hpsa_flush_cache(h);
36516- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36517+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36518 free_irq(h->intr[h->intr_mode], h);
36519 #ifdef CONFIG_PCI_MSI
36520 if (h->msix_vector)
36521@@ -4657,7 +4657,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36522 return;
36523 }
36524 /* Change the access methods to the performant access methods */
36525- h->access = SA5_performant_access;
36526+ h->access = &SA5_performant_access;
36527 h->transMethod = CFGTBL_Trans_Performant;
36528 }
36529
36530diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36531index 7b28d54..952f23a 100644
36532--- a/drivers/scsi/hpsa.h
36533+++ b/drivers/scsi/hpsa.h
36534@@ -72,7 +72,7 @@ struct ctlr_info {
36535 unsigned int msix_vector;
36536 unsigned int msi_vector;
36537 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36538- struct access_method access;
36539+ struct access_method *access;
36540
36541 /* queue and queue Info */
36542 struct list_head reqQ;
36543diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36544index f2df059..a3a9930 100644
36545--- a/drivers/scsi/ips.h
36546+++ b/drivers/scsi/ips.h
36547@@ -1027,7 +1027,7 @@ typedef struct {
36548 int (*intr)(struct ips_ha *);
36549 void (*enableint)(struct ips_ha *);
36550 uint32_t (*statupd)(struct ips_ha *);
36551-} ips_hw_func_t;
36552+} __no_const ips_hw_func_t;
36553
36554 typedef struct ips_ha {
36555 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36556diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36557index aceffad..c35c08d 100644
36558--- a/drivers/scsi/libfc/fc_exch.c
36559+++ b/drivers/scsi/libfc/fc_exch.c
36560@@ -105,12 +105,12 @@ struct fc_exch_mgr {
36561 * all together if not used XXX
36562 */
36563 struct {
36564- atomic_t no_free_exch;
36565- atomic_t no_free_exch_xid;
36566- atomic_t xid_not_found;
36567- atomic_t xid_busy;
36568- atomic_t seq_not_found;
36569- atomic_t non_bls_resp;
36570+ atomic_unchecked_t no_free_exch;
36571+ atomic_unchecked_t no_free_exch_xid;
36572+ atomic_unchecked_t xid_not_found;
36573+ atomic_unchecked_t xid_busy;
36574+ atomic_unchecked_t seq_not_found;
36575+ atomic_unchecked_t non_bls_resp;
36576 } stats;
36577 };
36578
36579@@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36580 /* allocate memory for exchange */
36581 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36582 if (!ep) {
36583- atomic_inc(&mp->stats.no_free_exch);
36584+ atomic_inc_unchecked(&mp->stats.no_free_exch);
36585 goto out;
36586 }
36587 memset(ep, 0, sizeof(*ep));
36588@@ -780,7 +780,7 @@ out:
36589 return ep;
36590 err:
36591 spin_unlock_bh(&pool->lock);
36592- atomic_inc(&mp->stats.no_free_exch_xid);
36593+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36594 mempool_free(ep, mp->ep_pool);
36595 return NULL;
36596 }
36597@@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36598 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36599 ep = fc_exch_find(mp, xid);
36600 if (!ep) {
36601- atomic_inc(&mp->stats.xid_not_found);
36602+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36603 reject = FC_RJT_OX_ID;
36604 goto out;
36605 }
36606@@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36607 ep = fc_exch_find(mp, xid);
36608 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36609 if (ep) {
36610- atomic_inc(&mp->stats.xid_busy);
36611+ atomic_inc_unchecked(&mp->stats.xid_busy);
36612 reject = FC_RJT_RX_ID;
36613 goto rel;
36614 }
36615@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36616 }
36617 xid = ep->xid; /* get our XID */
36618 } else if (!ep) {
36619- atomic_inc(&mp->stats.xid_not_found);
36620+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36621 reject = FC_RJT_RX_ID; /* XID not found */
36622 goto out;
36623 }
36624@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36625 } else {
36626 sp = &ep->seq;
36627 if (sp->id != fh->fh_seq_id) {
36628- atomic_inc(&mp->stats.seq_not_found);
36629+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36630 if (f_ctl & FC_FC_END_SEQ) {
36631 /*
36632 * Update sequence_id based on incoming last
36633@@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36634
36635 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36636 if (!ep) {
36637- atomic_inc(&mp->stats.xid_not_found);
36638+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36639 goto out;
36640 }
36641 if (ep->esb_stat & ESB_ST_COMPLETE) {
36642- atomic_inc(&mp->stats.xid_not_found);
36643+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36644 goto rel;
36645 }
36646 if (ep->rxid == FC_XID_UNKNOWN)
36647 ep->rxid = ntohs(fh->fh_rx_id);
36648 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36649- atomic_inc(&mp->stats.xid_not_found);
36650+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36651 goto rel;
36652 }
36653 if (ep->did != ntoh24(fh->fh_s_id) &&
36654 ep->did != FC_FID_FLOGI) {
36655- atomic_inc(&mp->stats.xid_not_found);
36656+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36657 goto rel;
36658 }
36659 sof = fr_sof(fp);
36660@@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36661 sp->ssb_stat |= SSB_ST_RESP;
36662 sp->id = fh->fh_seq_id;
36663 } else if (sp->id != fh->fh_seq_id) {
36664- atomic_inc(&mp->stats.seq_not_found);
36665+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36666 goto rel;
36667 }
36668
36669@@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36670 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36671
36672 if (!sp)
36673- atomic_inc(&mp->stats.xid_not_found);
36674+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36675 else
36676- atomic_inc(&mp->stats.non_bls_resp);
36677+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
36678
36679 fc_frame_free(fp);
36680 }
36681diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36682index d109cc3..09f4e7d 100644
36683--- a/drivers/scsi/libsas/sas_ata.c
36684+++ b/drivers/scsi/libsas/sas_ata.c
36685@@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36686 .postreset = ata_std_postreset,
36687 .error_handler = ata_std_error_handler,
36688 .post_internal_cmd = sas_ata_post_internal,
36689- .qc_defer = ata_std_qc_defer,
36690+ .qc_defer = ata_std_qc_defer,
36691 .qc_prep = ata_noop_qc_prep,
36692 .qc_issue = sas_ata_qc_issue,
36693 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36694diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36695index 3a1ffdd..8eb7c71 100644
36696--- a/drivers/scsi/lpfc/lpfc.h
36697+++ b/drivers/scsi/lpfc/lpfc.h
36698@@ -413,7 +413,7 @@ struct lpfc_vport {
36699 struct dentry *debug_nodelist;
36700 struct dentry *vport_debugfs_root;
36701 struct lpfc_debugfs_trc *disc_trc;
36702- atomic_t disc_trc_cnt;
36703+ atomic_unchecked_t disc_trc_cnt;
36704 #endif
36705 uint8_t stat_data_enabled;
36706 uint8_t stat_data_blocked;
36707@@ -826,8 +826,8 @@ struct lpfc_hba {
36708 struct timer_list fabric_block_timer;
36709 unsigned long bit_flags;
36710 #define FABRIC_COMANDS_BLOCKED 0
36711- atomic_t num_rsrc_err;
36712- atomic_t num_cmd_success;
36713+ atomic_unchecked_t num_rsrc_err;
36714+ atomic_unchecked_t num_cmd_success;
36715 unsigned long last_rsrc_error_time;
36716 unsigned long last_ramp_down_time;
36717 unsigned long last_ramp_up_time;
36718@@ -863,7 +863,7 @@ struct lpfc_hba {
36719
36720 struct dentry *debug_slow_ring_trc;
36721 struct lpfc_debugfs_trc *slow_ring_trc;
36722- atomic_t slow_ring_trc_cnt;
36723+ atomic_unchecked_t slow_ring_trc_cnt;
36724 /* iDiag debugfs sub-directory */
36725 struct dentry *idiag_root;
36726 struct dentry *idiag_pci_cfg;
36727diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36728index af04b0d..8f1a97e 100644
36729--- a/drivers/scsi/lpfc/lpfc_debugfs.c
36730+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36731@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36732
36733 #include <linux/debugfs.h>
36734
36735-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36736+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36737 static unsigned long lpfc_debugfs_start_time = 0L;
36738
36739 /* iDiag */
36740@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36741 lpfc_debugfs_enable = 0;
36742
36743 len = 0;
36744- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36745+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36746 (lpfc_debugfs_max_disc_trc - 1);
36747 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36748 dtp = vport->disc_trc + i;
36749@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36750 lpfc_debugfs_enable = 0;
36751
36752 len = 0;
36753- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36754+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36755 (lpfc_debugfs_max_slow_ring_trc - 1);
36756 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36757 dtp = phba->slow_ring_trc + i;
36758@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36759 !vport || !vport->disc_trc)
36760 return;
36761
36762- index = atomic_inc_return(&vport->disc_trc_cnt) &
36763+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36764 (lpfc_debugfs_max_disc_trc - 1);
36765 dtp = vport->disc_trc + index;
36766 dtp->fmt = fmt;
36767 dtp->data1 = data1;
36768 dtp->data2 = data2;
36769 dtp->data3 = data3;
36770- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36771+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36772 dtp->jif = jiffies;
36773 #endif
36774 return;
36775@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36776 !phba || !phba->slow_ring_trc)
36777 return;
36778
36779- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36780+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36781 (lpfc_debugfs_max_slow_ring_trc - 1);
36782 dtp = phba->slow_ring_trc + index;
36783 dtp->fmt = fmt;
36784 dtp->data1 = data1;
36785 dtp->data2 = data2;
36786 dtp->data3 = data3;
36787- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36788+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36789 dtp->jif = jiffies;
36790 #endif
36791 return;
36792@@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36793 "slow_ring buffer\n");
36794 goto debug_failed;
36795 }
36796- atomic_set(&phba->slow_ring_trc_cnt, 0);
36797+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36798 memset(phba->slow_ring_trc, 0,
36799 (sizeof(struct lpfc_debugfs_trc) *
36800 lpfc_debugfs_max_slow_ring_trc));
36801@@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36802 "buffer\n");
36803 goto debug_failed;
36804 }
36805- atomic_set(&vport->disc_trc_cnt, 0);
36806+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36807
36808 snprintf(name, sizeof(name), "discovery_trace");
36809 vport->debug_disc_trc =
36810diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36811index 9598fdc..7e9f3d9 100644
36812--- a/drivers/scsi/lpfc/lpfc_init.c
36813+++ b/drivers/scsi/lpfc/lpfc_init.c
36814@@ -10266,8 +10266,10 @@ lpfc_init(void)
36815 "misc_register returned with status %d", error);
36816
36817 if (lpfc_enable_npiv) {
36818- lpfc_transport_functions.vport_create = lpfc_vport_create;
36819- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36820+ pax_open_kernel();
36821+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36822+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36823+ pax_close_kernel();
36824 }
36825 lpfc_transport_template =
36826 fc_attach_transport(&lpfc_transport_functions);
36827diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36828index 88f3a83..686d3fa 100644
36829--- a/drivers/scsi/lpfc/lpfc_scsi.c
36830+++ b/drivers/scsi/lpfc/lpfc_scsi.c
36831@@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36832 uint32_t evt_posted;
36833
36834 spin_lock_irqsave(&phba->hbalock, flags);
36835- atomic_inc(&phba->num_rsrc_err);
36836+ atomic_inc_unchecked(&phba->num_rsrc_err);
36837 phba->last_rsrc_error_time = jiffies;
36838
36839 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36840@@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36841 unsigned long flags;
36842 struct lpfc_hba *phba = vport->phba;
36843 uint32_t evt_posted;
36844- atomic_inc(&phba->num_cmd_success);
36845+ atomic_inc_unchecked(&phba->num_cmd_success);
36846
36847 if (vport->cfg_lun_queue_depth <= queue_depth)
36848 return;
36849@@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36850 unsigned long num_rsrc_err, num_cmd_success;
36851 int i;
36852
36853- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36854- num_cmd_success = atomic_read(&phba->num_cmd_success);
36855+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36856+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36857
36858 vports = lpfc_create_vport_work_array(phba);
36859 if (vports != NULL)
36860@@ -417,8 +417,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36861 }
36862 }
36863 lpfc_destroy_vport_work_array(phba, vports);
36864- atomic_set(&phba->num_rsrc_err, 0);
36865- atomic_set(&phba->num_cmd_success, 0);
36866+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36867+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36868 }
36869
36870 /**
36871@@ -452,8 +452,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36872 }
36873 }
36874 lpfc_destroy_vport_work_array(phba, vports);
36875- atomic_set(&phba->num_rsrc_err, 0);
36876- atomic_set(&phba->num_cmd_success, 0);
36877+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36878+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36879 }
36880
36881 /**
36882diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36883index ea8a0b4..812a124 100644
36884--- a/drivers/scsi/pmcraid.c
36885+++ b/drivers/scsi/pmcraid.c
36886@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36887 res->scsi_dev = scsi_dev;
36888 scsi_dev->hostdata = res;
36889 res->change_detected = 0;
36890- atomic_set(&res->read_failures, 0);
36891- atomic_set(&res->write_failures, 0);
36892+ atomic_set_unchecked(&res->read_failures, 0);
36893+ atomic_set_unchecked(&res->write_failures, 0);
36894 rc = 0;
36895 }
36896 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36897@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36898
36899 /* If this was a SCSI read/write command keep count of errors */
36900 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36901- atomic_inc(&res->read_failures);
36902+ atomic_inc_unchecked(&res->read_failures);
36903 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36904- atomic_inc(&res->write_failures);
36905+ atomic_inc_unchecked(&res->write_failures);
36906
36907 if (!RES_IS_GSCSI(res->cfg_entry) &&
36908 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36909@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36910 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36911 * hrrq_id assigned here in queuecommand
36912 */
36913- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36914+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36915 pinstance->num_hrrq;
36916 cmd->cmd_done = pmcraid_io_done;
36917
36918@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36919 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36920 * hrrq_id assigned here in queuecommand
36921 */
36922- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36923+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36924 pinstance->num_hrrq;
36925
36926 if (request_size) {
36927@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36928
36929 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36930 /* add resources only after host is added into system */
36931- if (!atomic_read(&pinstance->expose_resources))
36932+ if (!atomic_read_unchecked(&pinstance->expose_resources))
36933 return;
36934
36935 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36936@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36937 init_waitqueue_head(&pinstance->reset_wait_q);
36938
36939 atomic_set(&pinstance->outstanding_cmds, 0);
36940- atomic_set(&pinstance->last_message_id, 0);
36941- atomic_set(&pinstance->expose_resources, 0);
36942+ atomic_set_unchecked(&pinstance->last_message_id, 0);
36943+ atomic_set_unchecked(&pinstance->expose_resources, 0);
36944
36945 INIT_LIST_HEAD(&pinstance->free_res_q);
36946 INIT_LIST_HEAD(&pinstance->used_res_q);
36947@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36948 /* Schedule worker thread to handle CCN and take care of adding and
36949 * removing devices to OS
36950 */
36951- atomic_set(&pinstance->expose_resources, 1);
36952+ atomic_set_unchecked(&pinstance->expose_resources, 1);
36953 schedule_work(&pinstance->worker_q);
36954 return rc;
36955
36956diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36957index e1d150f..6c6df44 100644
36958--- a/drivers/scsi/pmcraid.h
36959+++ b/drivers/scsi/pmcraid.h
36960@@ -748,7 +748,7 @@ struct pmcraid_instance {
36961 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36962
36963 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36964- atomic_t last_message_id;
36965+ atomic_unchecked_t last_message_id;
36966
36967 /* configuration table */
36968 struct pmcraid_config_table *cfg_table;
36969@@ -777,7 +777,7 @@ struct pmcraid_instance {
36970 atomic_t outstanding_cmds;
36971
36972 /* should add/delete resources to mid-layer now ?*/
36973- atomic_t expose_resources;
36974+ atomic_unchecked_t expose_resources;
36975
36976
36977
36978@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36979 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36980 };
36981 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36982- atomic_t read_failures; /* count of failed READ commands */
36983- atomic_t write_failures; /* count of failed WRITE commands */
36984+ atomic_unchecked_t read_failures; /* count of failed READ commands */
36985+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36986
36987 /* To indicate add/delete/modify during CCN */
36988 u8 change_detected;
36989diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36990index a244303..6015eb7 100644
36991--- a/drivers/scsi/qla2xxx/qla_def.h
36992+++ b/drivers/scsi/qla2xxx/qla_def.h
36993@@ -2264,7 +2264,7 @@ struct isp_operations {
36994 int (*start_scsi) (srb_t *);
36995 int (*abort_isp) (struct scsi_qla_host *);
36996 int (*iospace_config)(struct qla_hw_data*);
36997-};
36998+} __no_const;
36999
37000 /* MSI-X Support *************************************************************/
37001
37002diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37003index 7f2492e..5113877 100644
37004--- a/drivers/scsi/qla4xxx/ql4_def.h
37005+++ b/drivers/scsi/qla4xxx/ql4_def.h
37006@@ -268,7 +268,7 @@ struct ddb_entry {
37007 * (4000 only) */
37008 atomic_t relogin_timer; /* Max Time to wait for
37009 * relogin to complete */
37010- atomic_t relogin_retry_count; /* Num of times relogin has been
37011+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37012 * retried */
37013 uint32_t default_time2wait; /* Default Min time between
37014 * relogins (+aens) */
37015diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37016index ee47820..a83b1f4 100644
37017--- a/drivers/scsi/qla4xxx/ql4_os.c
37018+++ b/drivers/scsi/qla4xxx/ql4_os.c
37019@@ -2551,12 +2551,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37020 */
37021 if (!iscsi_is_session_online(cls_sess)) {
37022 /* Reset retry relogin timer */
37023- atomic_inc(&ddb_entry->relogin_retry_count);
37024+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37025 DEBUG2(ql4_printk(KERN_INFO, ha,
37026 "%s: index[%d] relogin timed out-retrying"
37027 " relogin (%d), retry (%d)\n", __func__,
37028 ddb_entry->fw_ddb_index,
37029- atomic_read(&ddb_entry->relogin_retry_count),
37030+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37031 ddb_entry->default_time2wait + 4));
37032 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37033 atomic_set(&ddb_entry->retry_relogin_timer,
37034@@ -4453,7 +4453,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37035
37036 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37037 atomic_set(&ddb_entry->relogin_timer, 0);
37038- atomic_set(&ddb_entry->relogin_retry_count, 0);
37039+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37040 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37041 ddb_entry->default_relogin_timeout =
37042 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37043diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37044index 07322ec..91ccc23 100644
37045--- a/drivers/scsi/scsi.c
37046+++ b/drivers/scsi/scsi.c
37047@@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37048 unsigned long timeout;
37049 int rtn = 0;
37050
37051- atomic_inc(&cmd->device->iorequest_cnt);
37052+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37053
37054 /* check if the device is still usable */
37055 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37056diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37057index 4037fd5..a19fcc7 100644
37058--- a/drivers/scsi/scsi_lib.c
37059+++ b/drivers/scsi/scsi_lib.c
37060@@ -1415,7 +1415,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37061 shost = sdev->host;
37062 scsi_init_cmd_errh(cmd);
37063 cmd->result = DID_NO_CONNECT << 16;
37064- atomic_inc(&cmd->device->iorequest_cnt);
37065+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37066
37067 /*
37068 * SCSI request completion path will do scsi_device_unbusy(),
37069@@ -1441,9 +1441,9 @@ static void scsi_softirq_done(struct request *rq)
37070
37071 INIT_LIST_HEAD(&cmd->eh_entry);
37072
37073- atomic_inc(&cmd->device->iodone_cnt);
37074+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
37075 if (cmd->result)
37076- atomic_inc(&cmd->device->ioerr_cnt);
37077+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37078
37079 disposition = scsi_decide_disposition(cmd);
37080 if (disposition != SUCCESS &&
37081diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37082index 04c2a27..9d8bd66 100644
37083--- a/drivers/scsi/scsi_sysfs.c
37084+++ b/drivers/scsi/scsi_sysfs.c
37085@@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37086 char *buf) \
37087 { \
37088 struct scsi_device *sdev = to_scsi_device(dev); \
37089- unsigned long long count = atomic_read(&sdev->field); \
37090+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
37091 return snprintf(buf, 20, "0x%llx\n", count); \
37092 } \
37093 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37094diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37095index 84a1fdf..693b0d6 100644
37096--- a/drivers/scsi/scsi_tgt_lib.c
37097+++ b/drivers/scsi/scsi_tgt_lib.c
37098@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37099 int err;
37100
37101 dprintk("%lx %u\n", uaddr, len);
37102- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37103+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37104 if (err) {
37105 /*
37106 * TODO: need to fixup sg_tablesize, max_segment_size,
37107diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37108index 80fbe2a..efa223b 100644
37109--- a/drivers/scsi/scsi_transport_fc.c
37110+++ b/drivers/scsi/scsi_transport_fc.c
37111@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37112 * Netlink Infrastructure
37113 */
37114
37115-static atomic_t fc_event_seq;
37116+static atomic_unchecked_t fc_event_seq;
37117
37118 /**
37119 * fc_get_event_number - Obtain the next sequential FC event number
37120@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37121 u32
37122 fc_get_event_number(void)
37123 {
37124- return atomic_add_return(1, &fc_event_seq);
37125+ return atomic_add_return_unchecked(1, &fc_event_seq);
37126 }
37127 EXPORT_SYMBOL(fc_get_event_number);
37128
37129@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37130 {
37131 int error;
37132
37133- atomic_set(&fc_event_seq, 0);
37134+ atomic_set_unchecked(&fc_event_seq, 0);
37135
37136 error = transport_class_register(&fc_host_class);
37137 if (error)
37138@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37139 char *cp;
37140
37141 *val = simple_strtoul(buf, &cp, 0);
37142- if ((*cp && (*cp != '\n')) || (*val < 0))
37143+ if (*cp && (*cp != '\n'))
37144 return -EINVAL;
37145 /*
37146 * Check for overflow; dev_loss_tmo is u32
37147diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37148index 1cf640e..78e9014 100644
37149--- a/drivers/scsi/scsi_transport_iscsi.c
37150+++ b/drivers/scsi/scsi_transport_iscsi.c
37151@@ -79,7 +79,7 @@ struct iscsi_internal {
37152 struct transport_container session_cont;
37153 };
37154
37155-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37156+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37157 static struct workqueue_struct *iscsi_eh_timer_workq;
37158
37159 static DEFINE_IDA(iscsi_sess_ida);
37160@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37161 int err;
37162
37163 ihost = shost->shost_data;
37164- session->sid = atomic_add_return(1, &iscsi_session_nr);
37165+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37166
37167 if (target_id == ISCSI_MAX_TARGET) {
37168 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37169@@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37170 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37171 ISCSI_TRANSPORT_VERSION);
37172
37173- atomic_set(&iscsi_session_nr, 0);
37174+ atomic_set_unchecked(&iscsi_session_nr, 0);
37175
37176 err = class_register(&iscsi_transport_class);
37177 if (err)
37178diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37179index 21a045e..ec89e03 100644
37180--- a/drivers/scsi/scsi_transport_srp.c
37181+++ b/drivers/scsi/scsi_transport_srp.c
37182@@ -33,7 +33,7 @@
37183 #include "scsi_transport_srp_internal.h"
37184
37185 struct srp_host_attrs {
37186- atomic_t next_port_id;
37187+ atomic_unchecked_t next_port_id;
37188 };
37189 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37190
37191@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37192 struct Scsi_Host *shost = dev_to_shost(dev);
37193 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37194
37195- atomic_set(&srp_host->next_port_id, 0);
37196+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37197 return 0;
37198 }
37199
37200@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37201 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37202 rport->roles = ids->roles;
37203
37204- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37205+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37206 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37207
37208 transport_setup_device(&rport->dev);
37209diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37210index eacd46b..e3f4d62 100644
37211--- a/drivers/scsi/sg.c
37212+++ b/drivers/scsi/sg.c
37213@@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37214 sdp->disk->disk_name,
37215 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37216 NULL,
37217- (char *)arg);
37218+ (char __user *)arg);
37219 case BLKTRACESTART:
37220 return blk_trace_startstop(sdp->device->request_queue, 1);
37221 case BLKTRACESTOP:
37222@@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37223 const struct file_operations * fops;
37224 };
37225
37226-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37227+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37228 {"allow_dio", &adio_fops},
37229 {"debug", &debug_fops},
37230 {"def_reserved_size", &dressz_fops},
37231@@ -2332,7 +2332,7 @@ sg_proc_init(void)
37232 if (!sg_proc_sgp)
37233 return 1;
37234 for (k = 0; k < num_leaves; ++k) {
37235- struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37236+ const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37237 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
37238 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
37239 }
37240diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37241index 3d8f662..070f1a5 100644
37242--- a/drivers/spi/spi.c
37243+++ b/drivers/spi/spi.c
37244@@ -1361,7 +1361,7 @@ int spi_bus_unlock(struct spi_master *master)
37245 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37246
37247 /* portable code must never pass more than 32 bytes */
37248-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37249+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37250
37251 static u8 *buf;
37252
37253diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37254index d91751f..a3a9e36 100644
37255--- a/drivers/staging/octeon/ethernet-rx.c
37256+++ b/drivers/staging/octeon/ethernet-rx.c
37257@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37258 /* Increment RX stats for virtual ports */
37259 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37260 #ifdef CONFIG_64BIT
37261- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37262- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37263+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37264+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37265 #else
37266- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37267- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37268+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37269+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37270 #endif
37271 }
37272 netif_receive_skb(skb);
37273@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37274 dev->name);
37275 */
37276 #ifdef CONFIG_64BIT
37277- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37278+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37279 #else
37280- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37281+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37282 #endif
37283 dev_kfree_skb_irq(skb);
37284 }
37285diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37286index 60cba81..71eb239 100644
37287--- a/drivers/staging/octeon/ethernet.c
37288+++ b/drivers/staging/octeon/ethernet.c
37289@@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37290 * since the RX tasklet also increments it.
37291 */
37292 #ifdef CONFIG_64BIT
37293- atomic64_add(rx_status.dropped_packets,
37294- (atomic64_t *)&priv->stats.rx_dropped);
37295+ atomic64_add_unchecked(rx_status.dropped_packets,
37296+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37297 #else
37298- atomic_add(rx_status.dropped_packets,
37299- (atomic_t *)&priv->stats.rx_dropped);
37300+ atomic_add_unchecked(rx_status.dropped_packets,
37301+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37302 #endif
37303 }
37304
37305diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37306index d3d8727..f9327bb8 100644
37307--- a/drivers/staging/rtl8712/rtl871x_io.h
37308+++ b/drivers/staging/rtl8712/rtl871x_io.h
37309@@ -108,7 +108,7 @@ struct _io_ops {
37310 u8 *pmem);
37311 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37312 u8 *pmem);
37313-};
37314+} __no_const;
37315
37316 struct io_req {
37317 struct list_head list;
37318diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37319index c7b5e8b..783d6cb 100644
37320--- a/drivers/staging/sbe-2t3e3/netdev.c
37321+++ b/drivers/staging/sbe-2t3e3/netdev.c
37322@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37323 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37324
37325 if (rlen)
37326- if (copy_to_user(data, &resp, rlen))
37327+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37328 return -EFAULT;
37329
37330 return 0;
37331diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37332index 42cdafe..2769103 100644
37333--- a/drivers/staging/speakup/speakup_soft.c
37334+++ b/drivers/staging/speakup/speakup_soft.c
37335@@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37336 break;
37337 } else if (!initialized) {
37338 if (*init) {
37339- ch = *init;
37340 init++;
37341 } else {
37342 initialized = 1;
37343 }
37344+ ch = *init;
37345 } else {
37346 ch = synth_buffer_getc();
37347 }
37348diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37349index c7b888c..c94be93 100644
37350--- a/drivers/staging/usbip/usbip_common.h
37351+++ b/drivers/staging/usbip/usbip_common.h
37352@@ -289,7 +289,7 @@ struct usbip_device {
37353 void (*shutdown)(struct usbip_device *);
37354 void (*reset)(struct usbip_device *);
37355 void (*unusable)(struct usbip_device *);
37356- } eh_ops;
37357+ } __no_const eh_ops;
37358 };
37359
37360 /* usbip_common.c */
37361diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37362index 88b3298..3783eee 100644
37363--- a/drivers/staging/usbip/vhci.h
37364+++ b/drivers/staging/usbip/vhci.h
37365@@ -88,7 +88,7 @@ struct vhci_hcd {
37366 unsigned resuming:1;
37367 unsigned long re_timeout;
37368
37369- atomic_t seqnum;
37370+ atomic_unchecked_t seqnum;
37371
37372 /*
37373 * NOTE:
37374diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37375index dca9bf1..80735c9 100644
37376--- a/drivers/staging/usbip/vhci_hcd.c
37377+++ b/drivers/staging/usbip/vhci_hcd.c
37378@@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37379 return;
37380 }
37381
37382- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37383+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37384 if (priv->seqnum == 0xffff)
37385 dev_info(&urb->dev->dev, "seqnum max\n");
37386
37387@@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37388 return -ENOMEM;
37389 }
37390
37391- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37392+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37393 if (unlink->seqnum == 0xffff)
37394 pr_info("seqnum max\n");
37395
37396@@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37397 vdev->rhport = rhport;
37398 }
37399
37400- atomic_set(&vhci->seqnum, 0);
37401+ atomic_set_unchecked(&vhci->seqnum, 0);
37402 spin_lock_init(&vhci->lock);
37403
37404 hcd->power_budget = 0; /* no limit */
37405diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37406index f5fba732..210a16c 100644
37407--- a/drivers/staging/usbip/vhci_rx.c
37408+++ b/drivers/staging/usbip/vhci_rx.c
37409@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37410 if (!urb) {
37411 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37412 pr_info("max seqnum %d\n",
37413- atomic_read(&the_controller->seqnum));
37414+ atomic_read_unchecked(&the_controller->seqnum));
37415 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37416 return;
37417 }
37418diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37419index 7735027..30eed13 100644
37420--- a/drivers/staging/vt6655/hostap.c
37421+++ b/drivers/staging/vt6655/hostap.c
37422@@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37423 *
37424 */
37425
37426+static net_device_ops_no_const apdev_netdev_ops;
37427+
37428 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37429 {
37430 PSDevice apdev_priv;
37431 struct net_device *dev = pDevice->dev;
37432 int ret;
37433- const struct net_device_ops apdev_netdev_ops = {
37434- .ndo_start_xmit = pDevice->tx_80211,
37435- };
37436
37437 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37438
37439@@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37440 *apdev_priv = *pDevice;
37441 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37442
37443+ /* only half broken now */
37444+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37445 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37446
37447 pDevice->apdev->type = ARPHRD_IEEE80211;
37448diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37449index 51b5adf..098e320 100644
37450--- a/drivers/staging/vt6656/hostap.c
37451+++ b/drivers/staging/vt6656/hostap.c
37452@@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37453 *
37454 */
37455
37456+static net_device_ops_no_const apdev_netdev_ops;
37457+
37458 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37459 {
37460 PSDevice apdev_priv;
37461 struct net_device *dev = pDevice->dev;
37462 int ret;
37463- const struct net_device_ops apdev_netdev_ops = {
37464- .ndo_start_xmit = pDevice->tx_80211,
37465- };
37466
37467 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37468
37469@@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37470 *apdev_priv = *pDevice;
37471 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37472
37473+ /* only half broken now */
37474+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37475 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37476
37477 pDevice->apdev->type = ARPHRD_IEEE80211;
37478diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37479index 7843dfd..3db105f 100644
37480--- a/drivers/staging/wlan-ng/hfa384x_usb.c
37481+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37482@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37483
37484 struct usbctlx_completor {
37485 int (*complete) (struct usbctlx_completor *);
37486-};
37487+} __no_const;
37488
37489 static int
37490 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37491diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37492index 1ca66ea..76f1343 100644
37493--- a/drivers/staging/zcache/tmem.c
37494+++ b/drivers/staging/zcache/tmem.c
37495@@ -39,7 +39,7 @@
37496 * A tmem host implementation must use this function to register callbacks
37497 * for memory allocation.
37498 */
37499-static struct tmem_hostops tmem_hostops;
37500+static tmem_hostops_no_const tmem_hostops;
37501
37502 static void tmem_objnode_tree_init(void);
37503
37504@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37505 * A tmem host implementation must use this function to register
37506 * callbacks for a page-accessible memory (PAM) implementation
37507 */
37508-static struct tmem_pamops tmem_pamops;
37509+static tmem_pamops_no_const tmem_pamops;
37510
37511 void tmem_register_pamops(struct tmem_pamops *m)
37512 {
37513diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37514index 0d4aa82..f7832d4 100644
37515--- a/drivers/staging/zcache/tmem.h
37516+++ b/drivers/staging/zcache/tmem.h
37517@@ -180,6 +180,7 @@ struct tmem_pamops {
37518 void (*new_obj)(struct tmem_obj *);
37519 int (*replace_in_obj)(void *, struct tmem_obj *);
37520 };
37521+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37522 extern void tmem_register_pamops(struct tmem_pamops *m);
37523
37524 /* memory allocation methods provided by the host implementation */
37525@@ -189,6 +190,7 @@ struct tmem_hostops {
37526 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37527 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37528 };
37529+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37530 extern void tmem_register_hostops(struct tmem_hostops *m);
37531
37532 /* core tmem accessor functions */
37533diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37534index f015839..b15dfc4 100644
37535--- a/drivers/target/target_core_tmr.c
37536+++ b/drivers/target/target_core_tmr.c
37537@@ -327,7 +327,7 @@ static void core_tmr_drain_task_list(
37538 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37539 cmd->t_task_list_num,
37540 atomic_read(&cmd->t_task_cdbs_left),
37541- atomic_read(&cmd->t_task_cdbs_sent),
37542+ atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37543 (cmd->transport_state & CMD_T_ACTIVE) != 0,
37544 (cmd->transport_state & CMD_T_STOP) != 0,
37545 (cmd->transport_state & CMD_T_SENT) != 0);
37546diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37547index 443704f..92d3517 100644
37548--- a/drivers/target/target_core_transport.c
37549+++ b/drivers/target/target_core_transport.c
37550@@ -1355,7 +1355,7 @@ struct se_device *transport_add_device_to_core_hba(
37551 spin_lock_init(&dev->se_port_lock);
37552 spin_lock_init(&dev->se_tmr_lock);
37553 spin_lock_init(&dev->qf_cmd_lock);
37554- atomic_set(&dev->dev_ordered_id, 0);
37555+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
37556
37557 se_dev_set_default_attribs(dev, dev_limits);
37558
37559@@ -1542,7 +1542,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37560 * Used to determine when ORDERED commands should go from
37561 * Dormant to Active status.
37562 */
37563- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37564+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37565 smp_mb__after_atomic_inc();
37566 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37567 cmd->se_ordered_id, cmd->sam_task_attr,
37568@@ -1956,7 +1956,7 @@ void transport_generic_request_failure(struct se_cmd *cmd)
37569 " CMD_T_ACTIVE: %d CMD_T_STOP: %d CMD_T_SENT: %d\n",
37570 cmd->t_task_list_num,
37571 atomic_read(&cmd->t_task_cdbs_left),
37572- atomic_read(&cmd->t_task_cdbs_sent),
37573+ atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37574 atomic_read(&cmd->t_task_cdbs_ex_left),
37575 (cmd->transport_state & CMD_T_ACTIVE) != 0,
37576 (cmd->transport_state & CMD_T_STOP) != 0,
37577@@ -2216,9 +2216,9 @@ check_depth:
37578 cmd = task->task_se_cmd;
37579 spin_lock_irqsave(&cmd->t_state_lock, flags);
37580 task->task_flags |= (TF_ACTIVE | TF_SENT);
37581- atomic_inc(&cmd->t_task_cdbs_sent);
37582+ atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37583
37584- if (atomic_read(&cmd->t_task_cdbs_sent) ==
37585+ if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37586 cmd->t_task_list_num)
37587 cmd->transport_state |= CMD_T_SENT;
37588
37589diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37590index 3436436..772237b 100644
37591--- a/drivers/tty/hvc/hvcs.c
37592+++ b/drivers/tty/hvc/hvcs.c
37593@@ -83,6 +83,7 @@
37594 #include <asm/hvcserver.h>
37595 #include <asm/uaccess.h>
37596 #include <asm/vio.h>
37597+#include <asm/local.h>
37598
37599 /*
37600 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37601@@ -270,7 +271,7 @@ struct hvcs_struct {
37602 unsigned int index;
37603
37604 struct tty_struct *tty;
37605- int open_count;
37606+ local_t open_count;
37607
37608 /*
37609 * Used to tell the driver kernel_thread what operations need to take
37610@@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37611
37612 spin_lock_irqsave(&hvcsd->lock, flags);
37613
37614- if (hvcsd->open_count > 0) {
37615+ if (local_read(&hvcsd->open_count) > 0) {
37616 spin_unlock_irqrestore(&hvcsd->lock, flags);
37617 printk(KERN_INFO "HVCS: vterm state unchanged. "
37618 "The hvcs device node is still in use.\n");
37619@@ -1138,7 +1139,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37620 if ((retval = hvcs_partner_connect(hvcsd)))
37621 goto error_release;
37622
37623- hvcsd->open_count = 1;
37624+ local_set(&hvcsd->open_count, 1);
37625 hvcsd->tty = tty;
37626 tty->driver_data = hvcsd;
37627
37628@@ -1172,7 +1173,7 @@ fast_open:
37629
37630 spin_lock_irqsave(&hvcsd->lock, flags);
37631 kref_get(&hvcsd->kref);
37632- hvcsd->open_count++;
37633+ local_inc(&hvcsd->open_count);
37634 hvcsd->todo_mask |= HVCS_SCHED_READ;
37635 spin_unlock_irqrestore(&hvcsd->lock, flags);
37636
37637@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37638 hvcsd = tty->driver_data;
37639
37640 spin_lock_irqsave(&hvcsd->lock, flags);
37641- if (--hvcsd->open_count == 0) {
37642+ if (local_dec_and_test(&hvcsd->open_count)) {
37643
37644 vio_disable_interrupts(hvcsd->vdev);
37645
37646@@ -1242,10 +1243,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37647 free_irq(irq, hvcsd);
37648 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37649 return;
37650- } else if (hvcsd->open_count < 0) {
37651+ } else if (local_read(&hvcsd->open_count) < 0) {
37652 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37653 " is missmanaged.\n",
37654- hvcsd->vdev->unit_address, hvcsd->open_count);
37655+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37656 }
37657
37658 spin_unlock_irqrestore(&hvcsd->lock, flags);
37659@@ -1261,7 +1262,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37660
37661 spin_lock_irqsave(&hvcsd->lock, flags);
37662 /* Preserve this so that we know how many kref refs to put */
37663- temp_open_count = hvcsd->open_count;
37664+ temp_open_count = local_read(&hvcsd->open_count);
37665
37666 /*
37667 * Don't kref put inside the spinlock because the destruction
37668@@ -1276,7 +1277,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37669 hvcsd->tty->driver_data = NULL;
37670 hvcsd->tty = NULL;
37671
37672- hvcsd->open_count = 0;
37673+ local_set(&hvcsd->open_count, 0);
37674
37675 /* This will drop any buffered data on the floor which is OK in a hangup
37676 * scenario. */
37677@@ -1347,7 +1348,7 @@ static int hvcs_write(struct tty_struct *tty,
37678 * the middle of a write operation? This is a crummy place to do this
37679 * but we want to keep it all in the spinlock.
37680 */
37681- if (hvcsd->open_count <= 0) {
37682+ if (local_read(&hvcsd->open_count) <= 0) {
37683 spin_unlock_irqrestore(&hvcsd->lock, flags);
37684 return -ENODEV;
37685 }
37686@@ -1421,7 +1422,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37687 {
37688 struct hvcs_struct *hvcsd = tty->driver_data;
37689
37690- if (!hvcsd || hvcsd->open_count <= 0)
37691+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
37692 return 0;
37693
37694 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37695diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37696index 4daf962..b4a2281 100644
37697--- a/drivers/tty/ipwireless/tty.c
37698+++ b/drivers/tty/ipwireless/tty.c
37699@@ -29,6 +29,7 @@
37700 #include <linux/tty_driver.h>
37701 #include <linux/tty_flip.h>
37702 #include <linux/uaccess.h>
37703+#include <asm/local.h>
37704
37705 #include "tty.h"
37706 #include "network.h"
37707@@ -51,7 +52,7 @@ struct ipw_tty {
37708 int tty_type;
37709 struct ipw_network *network;
37710 struct tty_struct *linux_tty;
37711- int open_count;
37712+ local_t open_count;
37713 unsigned int control_lines;
37714 struct mutex ipw_tty_mutex;
37715 int tx_bytes_queued;
37716@@ -117,10 +118,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37717 mutex_unlock(&tty->ipw_tty_mutex);
37718 return -ENODEV;
37719 }
37720- if (tty->open_count == 0)
37721+ if (local_read(&tty->open_count) == 0)
37722 tty->tx_bytes_queued = 0;
37723
37724- tty->open_count++;
37725+ local_inc(&tty->open_count);
37726
37727 tty->linux_tty = linux_tty;
37728 linux_tty->driver_data = tty;
37729@@ -136,9 +137,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37730
37731 static void do_ipw_close(struct ipw_tty *tty)
37732 {
37733- tty->open_count--;
37734-
37735- if (tty->open_count == 0) {
37736+ if (local_dec_return(&tty->open_count) == 0) {
37737 struct tty_struct *linux_tty = tty->linux_tty;
37738
37739 if (linux_tty != NULL) {
37740@@ -159,7 +158,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37741 return;
37742
37743 mutex_lock(&tty->ipw_tty_mutex);
37744- if (tty->open_count == 0) {
37745+ if (local_read(&tty->open_count) == 0) {
37746 mutex_unlock(&tty->ipw_tty_mutex);
37747 return;
37748 }
37749@@ -188,7 +187,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37750 return;
37751 }
37752
37753- if (!tty->open_count) {
37754+ if (!local_read(&tty->open_count)) {
37755 mutex_unlock(&tty->ipw_tty_mutex);
37756 return;
37757 }
37758@@ -230,7 +229,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37759 return -ENODEV;
37760
37761 mutex_lock(&tty->ipw_tty_mutex);
37762- if (!tty->open_count) {
37763+ if (!local_read(&tty->open_count)) {
37764 mutex_unlock(&tty->ipw_tty_mutex);
37765 return -EINVAL;
37766 }
37767@@ -270,7 +269,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37768 if (!tty)
37769 return -ENODEV;
37770
37771- if (!tty->open_count)
37772+ if (!local_read(&tty->open_count))
37773 return -EINVAL;
37774
37775 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37776@@ -312,7 +311,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37777 if (!tty)
37778 return 0;
37779
37780- if (!tty->open_count)
37781+ if (!local_read(&tty->open_count))
37782 return 0;
37783
37784 return tty->tx_bytes_queued;
37785@@ -393,7 +392,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37786 if (!tty)
37787 return -ENODEV;
37788
37789- if (!tty->open_count)
37790+ if (!local_read(&tty->open_count))
37791 return -EINVAL;
37792
37793 return get_control_lines(tty);
37794@@ -409,7 +408,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37795 if (!tty)
37796 return -ENODEV;
37797
37798- if (!tty->open_count)
37799+ if (!local_read(&tty->open_count))
37800 return -EINVAL;
37801
37802 return set_control_lines(tty, set, clear);
37803@@ -423,7 +422,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37804 if (!tty)
37805 return -ENODEV;
37806
37807- if (!tty->open_count)
37808+ if (!local_read(&tty->open_count))
37809 return -EINVAL;
37810
37811 /* FIXME: Exactly how is the tty object locked here .. */
37812@@ -572,7 +571,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37813 against a parallel ioctl etc */
37814 mutex_lock(&ttyj->ipw_tty_mutex);
37815 }
37816- while (ttyj->open_count)
37817+ while (local_read(&ttyj->open_count))
37818 do_ipw_close(ttyj);
37819 ipwireless_disassociate_network_ttys(network,
37820 ttyj->channel_idx);
37821diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37822index c43b683..0a88f1c 100644
37823--- a/drivers/tty/n_gsm.c
37824+++ b/drivers/tty/n_gsm.c
37825@@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37826 kref_init(&dlci->ref);
37827 mutex_init(&dlci->mutex);
37828 dlci->fifo = &dlci->_fifo;
37829- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37830+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37831 kfree(dlci);
37832 return NULL;
37833 }
37834diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37835index 94b6eda..15f7cec 100644
37836--- a/drivers/tty/n_tty.c
37837+++ b/drivers/tty/n_tty.c
37838@@ -2122,6 +2122,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37839 {
37840 *ops = tty_ldisc_N_TTY;
37841 ops->owner = NULL;
37842- ops->refcount = ops->flags = 0;
37843+ atomic_set(&ops->refcount, 0);
37844+ ops->flags = 0;
37845 }
37846 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37847diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37848index eeae7fa..177a743 100644
37849--- a/drivers/tty/pty.c
37850+++ b/drivers/tty/pty.c
37851@@ -707,8 +707,10 @@ static void __init unix98_pty_init(void)
37852 panic("Couldn't register Unix98 pts driver");
37853
37854 /* Now create the /dev/ptmx special device */
37855+ pax_open_kernel();
37856 tty_default_fops(&ptmx_fops);
37857- ptmx_fops.open = ptmx_open;
37858+ *(void **)&ptmx_fops.open = ptmx_open;
37859+ pax_close_kernel();
37860
37861 cdev_init(&ptmx_cdev, &ptmx_fops);
37862 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37863diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37864index 2b42a01..32a2ed3 100644
37865--- a/drivers/tty/serial/kgdboc.c
37866+++ b/drivers/tty/serial/kgdboc.c
37867@@ -24,8 +24,9 @@
37868 #define MAX_CONFIG_LEN 40
37869
37870 static struct kgdb_io kgdboc_io_ops;
37871+static struct kgdb_io kgdboc_io_ops_console;
37872
37873-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37874+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37875 static int configured = -1;
37876
37877 static char config[MAX_CONFIG_LEN];
37878@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37879 kgdboc_unregister_kbd();
37880 if (configured == 1)
37881 kgdb_unregister_io_module(&kgdboc_io_ops);
37882+ else if (configured == 2)
37883+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
37884 }
37885
37886 static int configure_kgdboc(void)
37887@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37888 int err;
37889 char *cptr = config;
37890 struct console *cons;
37891+ int is_console = 0;
37892
37893 err = kgdboc_option_setup(config);
37894 if (err || !strlen(config) || isspace(config[0]))
37895 goto noconfig;
37896
37897 err = -ENODEV;
37898- kgdboc_io_ops.is_console = 0;
37899 kgdb_tty_driver = NULL;
37900
37901 kgdboc_use_kms = 0;
37902@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37903 int idx;
37904 if (cons->device && cons->device(cons, &idx) == p &&
37905 idx == tty_line) {
37906- kgdboc_io_ops.is_console = 1;
37907+ is_console = 1;
37908 break;
37909 }
37910 cons = cons->next;
37911@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37912 kgdb_tty_line = tty_line;
37913
37914 do_register:
37915- err = kgdb_register_io_module(&kgdboc_io_ops);
37916+ if (is_console) {
37917+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
37918+ configured = 2;
37919+ } else {
37920+ err = kgdb_register_io_module(&kgdboc_io_ops);
37921+ configured = 1;
37922+ }
37923 if (err)
37924 goto noconfig;
37925
37926- configured = 1;
37927-
37928 return 0;
37929
37930 noconfig:
37931@@ -213,7 +220,7 @@ noconfig:
37932 static int __init init_kgdboc(void)
37933 {
37934 /* Already configured? */
37935- if (configured == 1)
37936+ if (configured >= 1)
37937 return 0;
37938
37939 return configure_kgdboc();
37940@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37941 if (config[len - 1] == '\n')
37942 config[len - 1] = '\0';
37943
37944- if (configured == 1)
37945+ if (configured >= 1)
37946 cleanup_kgdboc();
37947
37948 /* Go and configure with the new params. */
37949@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37950 .post_exception = kgdboc_post_exp_handler,
37951 };
37952
37953+static struct kgdb_io kgdboc_io_ops_console = {
37954+ .name = "kgdboc",
37955+ .read_char = kgdboc_get_char,
37956+ .write_char = kgdboc_put_char,
37957+ .pre_exception = kgdboc_pre_exp_handler,
37958+ .post_exception = kgdboc_post_exp_handler,
37959+ .is_console = 1
37960+};
37961+
37962 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37963 /* This is only available if kgdboc is a built in for early debugging */
37964 static int __init kgdboc_early_init(char *opt)
37965diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
37966index 05728894..b9d44c6 100644
37967--- a/drivers/tty/sysrq.c
37968+++ b/drivers/tty/sysrq.c
37969@@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
37970 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
37971 size_t count, loff_t *ppos)
37972 {
37973- if (count) {
37974+ if (count && capable(CAP_SYS_ADMIN)) {
37975 char c;
37976
37977 if (get_user(c, buf))
37978diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
37979index d939bd7..33d92cd 100644
37980--- a/drivers/tty/tty_io.c
37981+++ b/drivers/tty/tty_io.c
37982@@ -3278,7 +3278,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
37983
37984 void tty_default_fops(struct file_operations *fops)
37985 {
37986- *fops = tty_fops;
37987+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
37988 }
37989
37990 /*
37991diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
37992index 24b95db..9c078d0 100644
37993--- a/drivers/tty/tty_ldisc.c
37994+++ b/drivers/tty/tty_ldisc.c
37995@@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
37996 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
37997 struct tty_ldisc_ops *ldo = ld->ops;
37998
37999- ldo->refcount--;
38000+ atomic_dec(&ldo->refcount);
38001 module_put(ldo->owner);
38002 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38003
38004@@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38005 spin_lock_irqsave(&tty_ldisc_lock, flags);
38006 tty_ldiscs[disc] = new_ldisc;
38007 new_ldisc->num = disc;
38008- new_ldisc->refcount = 0;
38009+ atomic_set(&new_ldisc->refcount, 0);
38010 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38011
38012 return ret;
38013@@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
38014 return -EINVAL;
38015
38016 spin_lock_irqsave(&tty_ldisc_lock, flags);
38017- if (tty_ldiscs[disc]->refcount)
38018+ if (atomic_read(&tty_ldiscs[disc]->refcount))
38019 ret = -EBUSY;
38020 else
38021 tty_ldiscs[disc] = NULL;
38022@@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38023 if (ldops) {
38024 ret = ERR_PTR(-EAGAIN);
38025 if (try_module_get(ldops->owner)) {
38026- ldops->refcount++;
38027+ atomic_inc(&ldops->refcount);
38028 ret = ldops;
38029 }
38030 }
38031@@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38032 unsigned long flags;
38033
38034 spin_lock_irqsave(&tty_ldisc_lock, flags);
38035- ldops->refcount--;
38036+ atomic_dec(&ldops->refcount);
38037 module_put(ldops->owner);
38038 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38039 }
38040diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38041index 3b0c4e3..f98a992 100644
38042--- a/drivers/tty/vt/keyboard.c
38043+++ b/drivers/tty/vt/keyboard.c
38044@@ -663,6 +663,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38045 kbd->kbdmode == VC_OFF) &&
38046 value != KVAL(K_SAK))
38047 return; /* SAK is allowed even in raw mode */
38048+
38049+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38050+ {
38051+ void *func = fn_handler[value];
38052+ if (func == fn_show_state || func == fn_show_ptregs ||
38053+ func == fn_show_mem)
38054+ return;
38055+ }
38056+#endif
38057+
38058 fn_handler[value](vc);
38059 }
38060
38061@@ -1812,9 +1822,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38062 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38063 return -EFAULT;
38064
38065- if (!capable(CAP_SYS_TTY_CONFIG))
38066- perm = 0;
38067-
38068 switch (cmd) {
38069 case KDGKBENT:
38070 /* Ensure another thread doesn't free it under us */
38071@@ -1829,6 +1836,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38072 spin_unlock_irqrestore(&kbd_event_lock, flags);
38073 return put_user(val, &user_kbe->kb_value);
38074 case KDSKBENT:
38075+ if (!capable(CAP_SYS_TTY_CONFIG))
38076+ perm = 0;
38077+
38078 if (!perm)
38079 return -EPERM;
38080 if (!i && v == K_NOSUCHMAP) {
38081@@ -1919,9 +1929,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38082 int i, j, k;
38083 int ret;
38084
38085- if (!capable(CAP_SYS_TTY_CONFIG))
38086- perm = 0;
38087-
38088 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38089 if (!kbs) {
38090 ret = -ENOMEM;
38091@@ -1955,6 +1962,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38092 kfree(kbs);
38093 return ((p && *p) ? -EOVERFLOW : 0);
38094 case KDSKBSENT:
38095+ if (!capable(CAP_SYS_TTY_CONFIG))
38096+ perm = 0;
38097+
38098 if (!perm) {
38099 ret = -EPERM;
38100 goto reterr;
38101diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38102index a783d53..cb30d94 100644
38103--- a/drivers/uio/uio.c
38104+++ b/drivers/uio/uio.c
38105@@ -25,6 +25,7 @@
38106 #include <linux/kobject.h>
38107 #include <linux/cdev.h>
38108 #include <linux/uio_driver.h>
38109+#include <asm/local.h>
38110
38111 #define UIO_MAX_DEVICES (1U << MINORBITS)
38112
38113@@ -32,10 +33,10 @@ struct uio_device {
38114 struct module *owner;
38115 struct device *dev;
38116 int minor;
38117- atomic_t event;
38118+ atomic_unchecked_t event;
38119 struct fasync_struct *async_queue;
38120 wait_queue_head_t wait;
38121- int vma_count;
38122+ local_t vma_count;
38123 struct uio_info *info;
38124 struct kobject *map_dir;
38125 struct kobject *portio_dir;
38126@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38127 struct device_attribute *attr, char *buf)
38128 {
38129 struct uio_device *idev = dev_get_drvdata(dev);
38130- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38131+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38132 }
38133
38134 static struct device_attribute uio_class_attributes[] = {
38135@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38136 {
38137 struct uio_device *idev = info->uio_dev;
38138
38139- atomic_inc(&idev->event);
38140+ atomic_inc_unchecked(&idev->event);
38141 wake_up_interruptible(&idev->wait);
38142 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38143 }
38144@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38145 }
38146
38147 listener->dev = idev;
38148- listener->event_count = atomic_read(&idev->event);
38149+ listener->event_count = atomic_read_unchecked(&idev->event);
38150 filep->private_data = listener;
38151
38152 if (idev->info->open) {
38153@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38154 return -EIO;
38155
38156 poll_wait(filep, &idev->wait, wait);
38157- if (listener->event_count != atomic_read(&idev->event))
38158+ if (listener->event_count != atomic_read_unchecked(&idev->event))
38159 return POLLIN | POLLRDNORM;
38160 return 0;
38161 }
38162@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38163 do {
38164 set_current_state(TASK_INTERRUPTIBLE);
38165
38166- event_count = atomic_read(&idev->event);
38167+ event_count = atomic_read_unchecked(&idev->event);
38168 if (event_count != listener->event_count) {
38169 if (copy_to_user(buf, &event_count, count))
38170 retval = -EFAULT;
38171@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38172 static void uio_vma_open(struct vm_area_struct *vma)
38173 {
38174 struct uio_device *idev = vma->vm_private_data;
38175- idev->vma_count++;
38176+ local_inc(&idev->vma_count);
38177 }
38178
38179 static void uio_vma_close(struct vm_area_struct *vma)
38180 {
38181 struct uio_device *idev = vma->vm_private_data;
38182- idev->vma_count--;
38183+ local_dec(&idev->vma_count);
38184 }
38185
38186 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38187@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38188 idev->owner = owner;
38189 idev->info = info;
38190 init_waitqueue_head(&idev->wait);
38191- atomic_set(&idev->event, 0);
38192+ atomic_set_unchecked(&idev->event, 0);
38193
38194 ret = uio_get_minor(idev);
38195 if (ret)
38196diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38197index 98b89fe..aff824e 100644
38198--- a/drivers/usb/atm/cxacru.c
38199+++ b/drivers/usb/atm/cxacru.c
38200@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38201 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38202 if (ret < 2)
38203 return -EINVAL;
38204- if (index < 0 || index > 0x7f)
38205+ if (index > 0x7f)
38206 return -EINVAL;
38207 pos += tmp;
38208
38209diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38210index d3448ca..d2864ca 100644
38211--- a/drivers/usb/atm/usbatm.c
38212+++ b/drivers/usb/atm/usbatm.c
38213@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38214 if (printk_ratelimit())
38215 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38216 __func__, vpi, vci);
38217- atomic_inc(&vcc->stats->rx_err);
38218+ atomic_inc_unchecked(&vcc->stats->rx_err);
38219 return;
38220 }
38221
38222@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38223 if (length > ATM_MAX_AAL5_PDU) {
38224 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38225 __func__, length, vcc);
38226- atomic_inc(&vcc->stats->rx_err);
38227+ atomic_inc_unchecked(&vcc->stats->rx_err);
38228 goto out;
38229 }
38230
38231@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38232 if (sarb->len < pdu_length) {
38233 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38234 __func__, pdu_length, sarb->len, vcc);
38235- atomic_inc(&vcc->stats->rx_err);
38236+ atomic_inc_unchecked(&vcc->stats->rx_err);
38237 goto out;
38238 }
38239
38240 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38241 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38242 __func__, vcc);
38243- atomic_inc(&vcc->stats->rx_err);
38244+ atomic_inc_unchecked(&vcc->stats->rx_err);
38245 goto out;
38246 }
38247
38248@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38249 if (printk_ratelimit())
38250 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38251 __func__, length);
38252- atomic_inc(&vcc->stats->rx_drop);
38253+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38254 goto out;
38255 }
38256
38257@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38258
38259 vcc->push(vcc, skb);
38260
38261- atomic_inc(&vcc->stats->rx);
38262+ atomic_inc_unchecked(&vcc->stats->rx);
38263 out:
38264 skb_trim(sarb, 0);
38265 }
38266@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38267 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38268
38269 usbatm_pop(vcc, skb);
38270- atomic_inc(&vcc->stats->tx);
38271+ atomic_inc_unchecked(&vcc->stats->tx);
38272
38273 skb = skb_dequeue(&instance->sndqueue);
38274 }
38275@@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38276 if (!left--)
38277 return sprintf(page,
38278 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38279- atomic_read(&atm_dev->stats.aal5.tx),
38280- atomic_read(&atm_dev->stats.aal5.tx_err),
38281- atomic_read(&atm_dev->stats.aal5.rx),
38282- atomic_read(&atm_dev->stats.aal5.rx_err),
38283- atomic_read(&atm_dev->stats.aal5.rx_drop));
38284+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38285+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38286+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38287+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38288+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38289
38290 if (!left--) {
38291 if (instance->disconnected)
38292diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38293index d956965..4179a77 100644
38294--- a/drivers/usb/core/devices.c
38295+++ b/drivers/usb/core/devices.c
38296@@ -126,7 +126,7 @@ static const char format_endpt[] =
38297 * time it gets called.
38298 */
38299 static struct device_connect_event {
38300- atomic_t count;
38301+ atomic_unchecked_t count;
38302 wait_queue_head_t wait;
38303 } device_event = {
38304 .count = ATOMIC_INIT(1),
38305@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38306
38307 void usbfs_conn_disc_event(void)
38308 {
38309- atomic_add(2, &device_event.count);
38310+ atomic_add_unchecked(2, &device_event.count);
38311 wake_up(&device_event.wait);
38312 }
38313
38314@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38315
38316 poll_wait(file, &device_event.wait, wait);
38317
38318- event_count = atomic_read(&device_event.count);
38319+ event_count = atomic_read_unchecked(&device_event.count);
38320 if (file->f_version != event_count) {
38321 file->f_version = event_count;
38322 return POLLIN | POLLRDNORM;
38323diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38324index 1fc8f12..20647c1 100644
38325--- a/drivers/usb/early/ehci-dbgp.c
38326+++ b/drivers/usb/early/ehci-dbgp.c
38327@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38328
38329 #ifdef CONFIG_KGDB
38330 static struct kgdb_io kgdbdbgp_io_ops;
38331-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38332+static struct kgdb_io kgdbdbgp_io_ops_console;
38333+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38334 #else
38335 #define dbgp_kgdb_mode (0)
38336 #endif
38337@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38338 .write_char = kgdbdbgp_write_char,
38339 };
38340
38341+static struct kgdb_io kgdbdbgp_io_ops_console = {
38342+ .name = "kgdbdbgp",
38343+ .read_char = kgdbdbgp_read_char,
38344+ .write_char = kgdbdbgp_write_char,
38345+ .is_console = 1
38346+};
38347+
38348 static int kgdbdbgp_wait_time;
38349
38350 static int __init kgdbdbgp_parse_config(char *str)
38351@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38352 ptr++;
38353 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38354 }
38355- kgdb_register_io_module(&kgdbdbgp_io_ops);
38356- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38357+ if (early_dbgp_console.index != -1)
38358+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38359+ else
38360+ kgdb_register_io_module(&kgdbdbgp_io_ops);
38361
38362 return 0;
38363 }
38364diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38365index d6bea3e..60b250e 100644
38366--- a/drivers/usb/wusbcore/wa-hc.h
38367+++ b/drivers/usb/wusbcore/wa-hc.h
38368@@ -192,7 +192,7 @@ struct wahc {
38369 struct list_head xfer_delayed_list;
38370 spinlock_t xfer_list_lock;
38371 struct work_struct xfer_work;
38372- atomic_t xfer_id_count;
38373+ atomic_unchecked_t xfer_id_count;
38374 };
38375
38376
38377@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38378 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38379 spin_lock_init(&wa->xfer_list_lock);
38380 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38381- atomic_set(&wa->xfer_id_count, 1);
38382+ atomic_set_unchecked(&wa->xfer_id_count, 1);
38383 }
38384
38385 /**
38386diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38387index 57c01ab..8a05959 100644
38388--- a/drivers/usb/wusbcore/wa-xfer.c
38389+++ b/drivers/usb/wusbcore/wa-xfer.c
38390@@ -296,7 +296,7 @@ out:
38391 */
38392 static void wa_xfer_id_init(struct wa_xfer *xfer)
38393 {
38394- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38395+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38396 }
38397
38398 /*
38399diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38400index 51e4c1e..9d87e2a 100644
38401--- a/drivers/vhost/vhost.c
38402+++ b/drivers/vhost/vhost.c
38403@@ -632,7 +632,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38404 return 0;
38405 }
38406
38407-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38408+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38409 {
38410 struct file *eventfp, *filep = NULL,
38411 *pollstart = NULL, *pollstop = NULL;
38412diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38413index b0b2ac3..89a4399 100644
38414--- a/drivers/video/aty/aty128fb.c
38415+++ b/drivers/video/aty/aty128fb.c
38416@@ -148,7 +148,7 @@ enum {
38417 };
38418
38419 /* Must match above enum */
38420-static const char *r128_family[] __devinitdata = {
38421+static const char *r128_family[] __devinitconst = {
38422 "AGP",
38423 "PCI",
38424 "PRO AGP",
38425diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38426index 5c3960d..15cf8fc 100644
38427--- a/drivers/video/fbcmap.c
38428+++ b/drivers/video/fbcmap.c
38429@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38430 rc = -ENODEV;
38431 goto out;
38432 }
38433- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38434- !info->fbops->fb_setcmap)) {
38435+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38436 rc = -EINVAL;
38437 goto out1;
38438 }
38439diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38440index c6ce416..3b9b642 100644
38441--- a/drivers/video/fbmem.c
38442+++ b/drivers/video/fbmem.c
38443@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38444 image->dx += image->width + 8;
38445 }
38446 } else if (rotate == FB_ROTATE_UD) {
38447- for (x = 0; x < num && image->dx >= 0; x++) {
38448+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38449 info->fbops->fb_imageblit(info, image);
38450 image->dx -= image->width + 8;
38451 }
38452@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38453 image->dy += image->height + 8;
38454 }
38455 } else if (rotate == FB_ROTATE_CCW) {
38456- for (x = 0; x < num && image->dy >= 0; x++) {
38457+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38458 info->fbops->fb_imageblit(info, image);
38459 image->dy -= image->height + 8;
38460 }
38461@@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38462 return -EFAULT;
38463 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38464 return -EINVAL;
38465- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38466+ if (con2fb.framebuffer >= FB_MAX)
38467 return -EINVAL;
38468 if (!registered_fb[con2fb.framebuffer])
38469 request_module("fb%d", con2fb.framebuffer);
38470diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38471index 5a5d092..265c5ed 100644
38472--- a/drivers/video/geode/gx1fb_core.c
38473+++ b/drivers/video/geode/gx1fb_core.c
38474@@ -29,7 +29,7 @@ static int crt_option = 1;
38475 static char panel_option[32] = "";
38476
38477 /* Modes relevant to the GX1 (taken from modedb.c) */
38478-static const struct fb_videomode __devinitdata gx1_modedb[] = {
38479+static const struct fb_videomode __devinitconst gx1_modedb[] = {
38480 /* 640x480-60 VESA */
38481 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38482 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38483diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38484index 0fad23f..0e9afa4 100644
38485--- a/drivers/video/gxt4500.c
38486+++ b/drivers/video/gxt4500.c
38487@@ -156,7 +156,7 @@ struct gxt4500_par {
38488 static char *mode_option;
38489
38490 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38491-static const struct fb_videomode defaultmode __devinitdata = {
38492+static const struct fb_videomode defaultmode __devinitconst = {
38493 .refresh = 60,
38494 .xres = 1280,
38495 .yres = 1024,
38496@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38497 return 0;
38498 }
38499
38500-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38501+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38502 .id = "IBM GXT4500P",
38503 .type = FB_TYPE_PACKED_PIXELS,
38504 .visual = FB_VISUAL_PSEUDOCOLOR,
38505diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38506index 7672d2e..b56437f 100644
38507--- a/drivers/video/i810/i810_accel.c
38508+++ b/drivers/video/i810/i810_accel.c
38509@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38510 }
38511 }
38512 printk("ringbuffer lockup!!!\n");
38513+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38514 i810_report_error(mmio);
38515 par->dev_flags |= LOCKUP;
38516 info->pixmap.scan_align = 1;
38517diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38518index b83f361..2b05a91 100644
38519--- a/drivers/video/i810/i810_main.c
38520+++ b/drivers/video/i810/i810_main.c
38521@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38522 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38523
38524 /* PCI */
38525-static const char *i810_pci_list[] __devinitdata = {
38526+static const char *i810_pci_list[] __devinitconst = {
38527 "Intel(R) 810 Framebuffer Device" ,
38528 "Intel(R) 810-DC100 Framebuffer Device" ,
38529 "Intel(R) 810E Framebuffer Device" ,
38530diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38531index de36693..3c63fc2 100644
38532--- a/drivers/video/jz4740_fb.c
38533+++ b/drivers/video/jz4740_fb.c
38534@@ -136,7 +136,7 @@ struct jzfb {
38535 uint32_t pseudo_palette[16];
38536 };
38537
38538-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38539+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38540 .id = "JZ4740 FB",
38541 .type = FB_TYPE_PACKED_PIXELS,
38542 .visual = FB_VISUAL_TRUECOLOR,
38543diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38544index 3c14e43..eafa544 100644
38545--- a/drivers/video/logo/logo_linux_clut224.ppm
38546+++ b/drivers/video/logo/logo_linux_clut224.ppm
38547@@ -1,1604 +1,1123 @@
38548 P3
38549-# Standard 224-color Linux logo
38550 80 80
38551 255
38552- 0 0 0 0 0 0 0 0 0 0 0 0
38553- 0 0 0 0 0 0 0 0 0 0 0 0
38554- 0 0 0 0 0 0 0 0 0 0 0 0
38555- 0 0 0 0 0 0 0 0 0 0 0 0
38556- 0 0 0 0 0 0 0 0 0 0 0 0
38557- 0 0 0 0 0 0 0 0 0 0 0 0
38558- 0 0 0 0 0 0 0 0 0 0 0 0
38559- 0 0 0 0 0 0 0 0 0 0 0 0
38560- 0 0 0 0 0 0 0 0 0 0 0 0
38561- 6 6 6 6 6 6 10 10 10 10 10 10
38562- 10 10 10 6 6 6 6 6 6 6 6 6
38563- 0 0 0 0 0 0 0 0 0 0 0 0
38564- 0 0 0 0 0 0 0 0 0 0 0 0
38565- 0 0 0 0 0 0 0 0 0 0 0 0
38566- 0 0 0 0 0 0 0 0 0 0 0 0
38567- 0 0 0 0 0 0 0 0 0 0 0 0
38568- 0 0 0 0 0 0 0 0 0 0 0 0
38569- 0 0 0 0 0 0 0 0 0 0 0 0
38570- 0 0 0 0 0 0 0 0 0 0 0 0
38571- 0 0 0 0 0 0 0 0 0 0 0 0
38572- 0 0 0 0 0 0 0 0 0 0 0 0
38573- 0 0 0 0 0 0 0 0 0 0 0 0
38574- 0 0 0 0 0 0 0 0 0 0 0 0
38575- 0 0 0 0 0 0 0 0 0 0 0 0
38576- 0 0 0 0 0 0 0 0 0 0 0 0
38577- 0 0 0 0 0 0 0 0 0 0 0 0
38578- 0 0 0 0 0 0 0 0 0 0 0 0
38579- 0 0 0 0 0 0 0 0 0 0 0 0
38580- 0 0 0 6 6 6 10 10 10 14 14 14
38581- 22 22 22 26 26 26 30 30 30 34 34 34
38582- 30 30 30 30 30 30 26 26 26 18 18 18
38583- 14 14 14 10 10 10 6 6 6 0 0 0
38584- 0 0 0 0 0 0 0 0 0 0 0 0
38585- 0 0 0 0 0 0 0 0 0 0 0 0
38586- 0 0 0 0 0 0 0 0 0 0 0 0
38587- 0 0 0 0 0 0 0 0 0 0 0 0
38588- 0 0 0 0 0 0 0 0 0 0 0 0
38589- 0 0 0 0 0 0 0 0 0 0 0 0
38590- 0 0 0 0 0 0 0 0 0 0 0 0
38591- 0 0 0 0 0 0 0 0 0 0 0 0
38592- 0 0 0 0 0 0 0 0 0 0 0 0
38593- 0 0 0 0 0 1 0 0 1 0 0 0
38594- 0 0 0 0 0 0 0 0 0 0 0 0
38595- 0 0 0 0 0 0 0 0 0 0 0 0
38596- 0 0 0 0 0 0 0 0 0 0 0 0
38597- 0 0 0 0 0 0 0 0 0 0 0 0
38598- 0 0 0 0 0 0 0 0 0 0 0 0
38599- 0 0 0 0 0 0 0 0 0 0 0 0
38600- 6 6 6 14 14 14 26 26 26 42 42 42
38601- 54 54 54 66 66 66 78 78 78 78 78 78
38602- 78 78 78 74 74 74 66 66 66 54 54 54
38603- 42 42 42 26 26 26 18 18 18 10 10 10
38604- 6 6 6 0 0 0 0 0 0 0 0 0
38605- 0 0 0 0 0 0 0 0 0 0 0 0
38606- 0 0 0 0 0 0 0 0 0 0 0 0
38607- 0 0 0 0 0 0 0 0 0 0 0 0
38608- 0 0 0 0 0 0 0 0 0 0 0 0
38609- 0 0 0 0 0 0 0 0 0 0 0 0
38610- 0 0 0 0 0 0 0 0 0 0 0 0
38611- 0 0 0 0 0 0 0 0 0 0 0 0
38612- 0 0 0 0 0 0 0 0 0 0 0 0
38613- 0 0 1 0 0 0 0 0 0 0 0 0
38614- 0 0 0 0 0 0 0 0 0 0 0 0
38615- 0 0 0 0 0 0 0 0 0 0 0 0
38616- 0 0 0 0 0 0 0 0 0 0 0 0
38617- 0 0 0 0 0 0 0 0 0 0 0 0
38618- 0 0 0 0 0 0 0 0 0 0 0 0
38619- 0 0 0 0 0 0 0 0 0 10 10 10
38620- 22 22 22 42 42 42 66 66 66 86 86 86
38621- 66 66 66 38 38 38 38 38 38 22 22 22
38622- 26 26 26 34 34 34 54 54 54 66 66 66
38623- 86 86 86 70 70 70 46 46 46 26 26 26
38624- 14 14 14 6 6 6 0 0 0 0 0 0
38625- 0 0 0 0 0 0 0 0 0 0 0 0
38626- 0 0 0 0 0 0 0 0 0 0 0 0
38627- 0 0 0 0 0 0 0 0 0 0 0 0
38628- 0 0 0 0 0 0 0 0 0 0 0 0
38629- 0 0 0 0 0 0 0 0 0 0 0 0
38630- 0 0 0 0 0 0 0 0 0 0 0 0
38631- 0 0 0 0 0 0 0 0 0 0 0 0
38632- 0 0 0 0 0 0 0 0 0 0 0 0
38633- 0 0 1 0 0 1 0 0 1 0 0 0
38634- 0 0 0 0 0 0 0 0 0 0 0 0
38635- 0 0 0 0 0 0 0 0 0 0 0 0
38636- 0 0 0 0 0 0 0 0 0 0 0 0
38637- 0 0 0 0 0 0 0 0 0 0 0 0
38638- 0 0 0 0 0 0 0 0 0 0 0 0
38639- 0 0 0 0 0 0 10 10 10 26 26 26
38640- 50 50 50 82 82 82 58 58 58 6 6 6
38641- 2 2 6 2 2 6 2 2 6 2 2 6
38642- 2 2 6 2 2 6 2 2 6 2 2 6
38643- 6 6 6 54 54 54 86 86 86 66 66 66
38644- 38 38 38 18 18 18 6 6 6 0 0 0
38645- 0 0 0 0 0 0 0 0 0 0 0 0
38646- 0 0 0 0 0 0 0 0 0 0 0 0
38647- 0 0 0 0 0 0 0 0 0 0 0 0
38648- 0 0 0 0 0 0 0 0 0 0 0 0
38649- 0 0 0 0 0 0 0 0 0 0 0 0
38650- 0 0 0 0 0 0 0 0 0 0 0 0
38651- 0 0 0 0 0 0 0 0 0 0 0 0
38652- 0 0 0 0 0 0 0 0 0 0 0 0
38653- 0 0 0 0 0 0 0 0 0 0 0 0
38654- 0 0 0 0 0 0 0 0 0 0 0 0
38655- 0 0 0 0 0 0 0 0 0 0 0 0
38656- 0 0 0 0 0 0 0 0 0 0 0 0
38657- 0 0 0 0 0 0 0 0 0 0 0 0
38658- 0 0 0 0 0 0 0 0 0 0 0 0
38659- 0 0 0 6 6 6 22 22 22 50 50 50
38660- 78 78 78 34 34 34 2 2 6 2 2 6
38661- 2 2 6 2 2 6 2 2 6 2 2 6
38662- 2 2 6 2 2 6 2 2 6 2 2 6
38663- 2 2 6 2 2 6 6 6 6 70 70 70
38664- 78 78 78 46 46 46 22 22 22 6 6 6
38665- 0 0 0 0 0 0 0 0 0 0 0 0
38666- 0 0 0 0 0 0 0 0 0 0 0 0
38667- 0 0 0 0 0 0 0 0 0 0 0 0
38668- 0 0 0 0 0 0 0 0 0 0 0 0
38669- 0 0 0 0 0 0 0 0 0 0 0 0
38670- 0 0 0 0 0 0 0 0 0 0 0 0
38671- 0 0 0 0 0 0 0 0 0 0 0 0
38672- 0 0 0 0 0 0 0 0 0 0 0 0
38673- 0 0 1 0 0 1 0 0 1 0 0 0
38674- 0 0 0 0 0 0 0 0 0 0 0 0
38675- 0 0 0 0 0 0 0 0 0 0 0 0
38676- 0 0 0 0 0 0 0 0 0 0 0 0
38677- 0 0 0 0 0 0 0 0 0 0 0 0
38678- 0 0 0 0 0 0 0 0 0 0 0 0
38679- 6 6 6 18 18 18 42 42 42 82 82 82
38680- 26 26 26 2 2 6 2 2 6 2 2 6
38681- 2 2 6 2 2 6 2 2 6 2 2 6
38682- 2 2 6 2 2 6 2 2 6 14 14 14
38683- 46 46 46 34 34 34 6 6 6 2 2 6
38684- 42 42 42 78 78 78 42 42 42 18 18 18
38685- 6 6 6 0 0 0 0 0 0 0 0 0
38686- 0 0 0 0 0 0 0 0 0 0 0 0
38687- 0 0 0 0 0 0 0 0 0 0 0 0
38688- 0 0 0 0 0 0 0 0 0 0 0 0
38689- 0 0 0 0 0 0 0 0 0 0 0 0
38690- 0 0 0 0 0 0 0 0 0 0 0 0
38691- 0 0 0 0 0 0 0 0 0 0 0 0
38692- 0 0 0 0 0 0 0 0 0 0 0 0
38693- 0 0 1 0 0 0 0 0 1 0 0 0
38694- 0 0 0 0 0 0 0 0 0 0 0 0
38695- 0 0 0 0 0 0 0 0 0 0 0 0
38696- 0 0 0 0 0 0 0 0 0 0 0 0
38697- 0 0 0 0 0 0 0 0 0 0 0 0
38698- 0 0 0 0 0 0 0 0 0 0 0 0
38699- 10 10 10 30 30 30 66 66 66 58 58 58
38700- 2 2 6 2 2 6 2 2 6 2 2 6
38701- 2 2 6 2 2 6 2 2 6 2 2 6
38702- 2 2 6 2 2 6 2 2 6 26 26 26
38703- 86 86 86 101 101 101 46 46 46 10 10 10
38704- 2 2 6 58 58 58 70 70 70 34 34 34
38705- 10 10 10 0 0 0 0 0 0 0 0 0
38706- 0 0 0 0 0 0 0 0 0 0 0 0
38707- 0 0 0 0 0 0 0 0 0 0 0 0
38708- 0 0 0 0 0 0 0 0 0 0 0 0
38709- 0 0 0 0 0 0 0 0 0 0 0 0
38710- 0 0 0 0 0 0 0 0 0 0 0 0
38711- 0 0 0 0 0 0 0 0 0 0 0 0
38712- 0 0 0 0 0 0 0 0 0 0 0 0
38713- 0 0 1 0 0 1 0 0 1 0 0 0
38714- 0 0 0 0 0 0 0 0 0 0 0 0
38715- 0 0 0 0 0 0 0 0 0 0 0 0
38716- 0 0 0 0 0 0 0 0 0 0 0 0
38717- 0 0 0 0 0 0 0 0 0 0 0 0
38718- 0 0 0 0 0 0 0 0 0 0 0 0
38719- 14 14 14 42 42 42 86 86 86 10 10 10
38720- 2 2 6 2 2 6 2 2 6 2 2 6
38721- 2 2 6 2 2 6 2 2 6 2 2 6
38722- 2 2 6 2 2 6 2 2 6 30 30 30
38723- 94 94 94 94 94 94 58 58 58 26 26 26
38724- 2 2 6 6 6 6 78 78 78 54 54 54
38725- 22 22 22 6 6 6 0 0 0 0 0 0
38726- 0 0 0 0 0 0 0 0 0 0 0 0
38727- 0 0 0 0 0 0 0 0 0 0 0 0
38728- 0 0 0 0 0 0 0 0 0 0 0 0
38729- 0 0 0 0 0 0 0 0 0 0 0 0
38730- 0 0 0 0 0 0 0 0 0 0 0 0
38731- 0 0 0 0 0 0 0 0 0 0 0 0
38732- 0 0 0 0 0 0 0 0 0 0 0 0
38733- 0 0 0 0 0 0 0 0 0 0 0 0
38734- 0 0 0 0 0 0 0 0 0 0 0 0
38735- 0 0 0 0 0 0 0 0 0 0 0 0
38736- 0 0 0 0 0 0 0 0 0 0 0 0
38737- 0 0 0 0 0 0 0 0 0 0 0 0
38738- 0 0 0 0 0 0 0 0 0 6 6 6
38739- 22 22 22 62 62 62 62 62 62 2 2 6
38740- 2 2 6 2 2 6 2 2 6 2 2 6
38741- 2 2 6 2 2 6 2 2 6 2 2 6
38742- 2 2 6 2 2 6 2 2 6 26 26 26
38743- 54 54 54 38 38 38 18 18 18 10 10 10
38744- 2 2 6 2 2 6 34 34 34 82 82 82
38745- 38 38 38 14 14 14 0 0 0 0 0 0
38746- 0 0 0 0 0 0 0 0 0 0 0 0
38747- 0 0 0 0 0 0 0 0 0 0 0 0
38748- 0 0 0 0 0 0 0 0 0 0 0 0
38749- 0 0 0 0 0 0 0 0 0 0 0 0
38750- 0 0 0 0 0 0 0 0 0 0 0 0
38751- 0 0 0 0 0 0 0 0 0 0 0 0
38752- 0 0 0 0 0 0 0 0 0 0 0 0
38753- 0 0 0 0 0 1 0 0 1 0 0 0
38754- 0 0 0 0 0 0 0 0 0 0 0 0
38755- 0 0 0 0 0 0 0 0 0 0 0 0
38756- 0 0 0 0 0 0 0 0 0 0 0 0
38757- 0 0 0 0 0 0 0 0 0 0 0 0
38758- 0 0 0 0 0 0 0 0 0 6 6 6
38759- 30 30 30 78 78 78 30 30 30 2 2 6
38760- 2 2 6 2 2 6 2 2 6 2 2 6
38761- 2 2 6 2 2 6 2 2 6 2 2 6
38762- 2 2 6 2 2 6 2 2 6 10 10 10
38763- 10 10 10 2 2 6 2 2 6 2 2 6
38764- 2 2 6 2 2 6 2 2 6 78 78 78
38765- 50 50 50 18 18 18 6 6 6 0 0 0
38766- 0 0 0 0 0 0 0 0 0 0 0 0
38767- 0 0 0 0 0 0 0 0 0 0 0 0
38768- 0 0 0 0 0 0 0 0 0 0 0 0
38769- 0 0 0 0 0 0 0 0 0 0 0 0
38770- 0 0 0 0 0 0 0 0 0 0 0 0
38771- 0 0 0 0 0 0 0 0 0 0 0 0
38772- 0 0 0 0 0 0 0 0 0 0 0 0
38773- 0 0 1 0 0 0 0 0 0 0 0 0
38774- 0 0 0 0 0 0 0 0 0 0 0 0
38775- 0 0 0 0 0 0 0 0 0 0 0 0
38776- 0 0 0 0 0 0 0 0 0 0 0 0
38777- 0 0 0 0 0 0 0 0 0 0 0 0
38778- 0 0 0 0 0 0 0 0 0 10 10 10
38779- 38 38 38 86 86 86 14 14 14 2 2 6
38780- 2 2 6 2 2 6 2 2 6 2 2 6
38781- 2 2 6 2 2 6 2 2 6 2 2 6
38782- 2 2 6 2 2 6 2 2 6 2 2 6
38783- 2 2 6 2 2 6 2 2 6 2 2 6
38784- 2 2 6 2 2 6 2 2 6 54 54 54
38785- 66 66 66 26 26 26 6 6 6 0 0 0
38786- 0 0 0 0 0 0 0 0 0 0 0 0
38787- 0 0 0 0 0 0 0 0 0 0 0 0
38788- 0 0 0 0 0 0 0 0 0 0 0 0
38789- 0 0 0 0 0 0 0 0 0 0 0 0
38790- 0 0 0 0 0 0 0 0 0 0 0 0
38791- 0 0 0 0 0 0 0 0 0 0 0 0
38792- 0 0 0 0 0 0 0 0 0 0 0 0
38793- 0 0 0 0 0 1 0 0 1 0 0 0
38794- 0 0 0 0 0 0 0 0 0 0 0 0
38795- 0 0 0 0 0 0 0 0 0 0 0 0
38796- 0 0 0 0 0 0 0 0 0 0 0 0
38797- 0 0 0 0 0 0 0 0 0 0 0 0
38798- 0 0 0 0 0 0 0 0 0 14 14 14
38799- 42 42 42 82 82 82 2 2 6 2 2 6
38800- 2 2 6 6 6 6 10 10 10 2 2 6
38801- 2 2 6 2 2 6 2 2 6 2 2 6
38802- 2 2 6 2 2 6 2 2 6 6 6 6
38803- 14 14 14 10 10 10 2 2 6 2 2 6
38804- 2 2 6 2 2 6 2 2 6 18 18 18
38805- 82 82 82 34 34 34 10 10 10 0 0 0
38806- 0 0 0 0 0 0 0 0 0 0 0 0
38807- 0 0 0 0 0 0 0 0 0 0 0 0
38808- 0 0 0 0 0 0 0 0 0 0 0 0
38809- 0 0 0 0 0 0 0 0 0 0 0 0
38810- 0 0 0 0 0 0 0 0 0 0 0 0
38811- 0 0 0 0 0 0 0 0 0 0 0 0
38812- 0 0 0 0 0 0 0 0 0 0 0 0
38813- 0 0 1 0 0 0 0 0 0 0 0 0
38814- 0 0 0 0 0 0 0 0 0 0 0 0
38815- 0 0 0 0 0 0 0 0 0 0 0 0
38816- 0 0 0 0 0 0 0 0 0 0 0 0
38817- 0 0 0 0 0 0 0 0 0 0 0 0
38818- 0 0 0 0 0 0 0 0 0 14 14 14
38819- 46 46 46 86 86 86 2 2 6 2 2 6
38820- 6 6 6 6 6 6 22 22 22 34 34 34
38821- 6 6 6 2 2 6 2 2 6 2 2 6
38822- 2 2 6 2 2 6 18 18 18 34 34 34
38823- 10 10 10 50 50 50 22 22 22 2 2 6
38824- 2 2 6 2 2 6 2 2 6 10 10 10
38825- 86 86 86 42 42 42 14 14 14 0 0 0
38826- 0 0 0 0 0 0 0 0 0 0 0 0
38827- 0 0 0 0 0 0 0 0 0 0 0 0
38828- 0 0 0 0 0 0 0 0 0 0 0 0
38829- 0 0 0 0 0 0 0 0 0 0 0 0
38830- 0 0 0 0 0 0 0 0 0 0 0 0
38831- 0 0 0 0 0 0 0 0 0 0 0 0
38832- 0 0 0 0 0 0 0 0 0 0 0 0
38833- 0 0 1 0 0 1 0 0 1 0 0 0
38834- 0 0 0 0 0 0 0 0 0 0 0 0
38835- 0 0 0 0 0 0 0 0 0 0 0 0
38836- 0 0 0 0 0 0 0 0 0 0 0 0
38837- 0 0 0 0 0 0 0 0 0 0 0 0
38838- 0 0 0 0 0 0 0 0 0 14 14 14
38839- 46 46 46 86 86 86 2 2 6 2 2 6
38840- 38 38 38 116 116 116 94 94 94 22 22 22
38841- 22 22 22 2 2 6 2 2 6 2 2 6
38842- 14 14 14 86 86 86 138 138 138 162 162 162
38843-154 154 154 38 38 38 26 26 26 6 6 6
38844- 2 2 6 2 2 6 2 2 6 2 2 6
38845- 86 86 86 46 46 46 14 14 14 0 0 0
38846- 0 0 0 0 0 0 0 0 0 0 0 0
38847- 0 0 0 0 0 0 0 0 0 0 0 0
38848- 0 0 0 0 0 0 0 0 0 0 0 0
38849- 0 0 0 0 0 0 0 0 0 0 0 0
38850- 0 0 0 0 0 0 0 0 0 0 0 0
38851- 0 0 0 0 0 0 0 0 0 0 0 0
38852- 0 0 0 0 0 0 0 0 0 0 0 0
38853- 0 0 0 0 0 0 0 0 0 0 0 0
38854- 0 0 0 0 0 0 0 0 0 0 0 0
38855- 0 0 0 0 0 0 0 0 0 0 0 0
38856- 0 0 0 0 0 0 0 0 0 0 0 0
38857- 0 0 0 0 0 0 0 0 0 0 0 0
38858- 0 0 0 0 0 0 0 0 0 14 14 14
38859- 46 46 46 86 86 86 2 2 6 14 14 14
38860-134 134 134 198 198 198 195 195 195 116 116 116
38861- 10 10 10 2 2 6 2 2 6 6 6 6
38862-101 98 89 187 187 187 210 210 210 218 218 218
38863-214 214 214 134 134 134 14 14 14 6 6 6
38864- 2 2 6 2 2 6 2 2 6 2 2 6
38865- 86 86 86 50 50 50 18 18 18 6 6 6
38866- 0 0 0 0 0 0 0 0 0 0 0 0
38867- 0 0 0 0 0 0 0 0 0 0 0 0
38868- 0 0 0 0 0 0 0 0 0 0 0 0
38869- 0 0 0 0 0 0 0 0 0 0 0 0
38870- 0 0 0 0 0 0 0 0 0 0 0 0
38871- 0 0 0 0 0 0 0 0 0 0 0 0
38872- 0 0 0 0 0 0 0 0 1 0 0 0
38873- 0 0 1 0 0 1 0 0 1 0 0 0
38874- 0 0 0 0 0 0 0 0 0 0 0 0
38875- 0 0 0 0 0 0 0 0 0 0 0 0
38876- 0 0 0 0 0 0 0 0 0 0 0 0
38877- 0 0 0 0 0 0 0 0 0 0 0 0
38878- 0 0 0 0 0 0 0 0 0 14 14 14
38879- 46 46 46 86 86 86 2 2 6 54 54 54
38880-218 218 218 195 195 195 226 226 226 246 246 246
38881- 58 58 58 2 2 6 2 2 6 30 30 30
38882-210 210 210 253 253 253 174 174 174 123 123 123
38883-221 221 221 234 234 234 74 74 74 2 2 6
38884- 2 2 6 2 2 6 2 2 6 2 2 6
38885- 70 70 70 58 58 58 22 22 22 6 6 6
38886- 0 0 0 0 0 0 0 0 0 0 0 0
38887- 0 0 0 0 0 0 0 0 0 0 0 0
38888- 0 0 0 0 0 0 0 0 0 0 0 0
38889- 0 0 0 0 0 0 0 0 0 0 0 0
38890- 0 0 0 0 0 0 0 0 0 0 0 0
38891- 0 0 0 0 0 0 0 0 0 0 0 0
38892- 0 0 0 0 0 0 0 0 0 0 0 0
38893- 0 0 0 0 0 0 0 0 0 0 0 0
38894- 0 0 0 0 0 0 0 0 0 0 0 0
38895- 0 0 0 0 0 0 0 0 0 0 0 0
38896- 0 0 0 0 0 0 0 0 0 0 0 0
38897- 0 0 0 0 0 0 0 0 0 0 0 0
38898- 0 0 0 0 0 0 0 0 0 14 14 14
38899- 46 46 46 82 82 82 2 2 6 106 106 106
38900-170 170 170 26 26 26 86 86 86 226 226 226
38901-123 123 123 10 10 10 14 14 14 46 46 46
38902-231 231 231 190 190 190 6 6 6 70 70 70
38903- 90 90 90 238 238 238 158 158 158 2 2 6
38904- 2 2 6 2 2 6 2 2 6 2 2 6
38905- 70 70 70 58 58 58 22 22 22 6 6 6
38906- 0 0 0 0 0 0 0 0 0 0 0 0
38907- 0 0 0 0 0 0 0 0 0 0 0 0
38908- 0 0 0 0 0 0 0 0 0 0 0 0
38909- 0 0 0 0 0 0 0 0 0 0 0 0
38910- 0 0 0 0 0 0 0 0 0 0 0 0
38911- 0 0 0 0 0 0 0 0 0 0 0 0
38912- 0 0 0 0 0 0 0 0 1 0 0 0
38913- 0 0 1 0 0 1 0 0 1 0 0 0
38914- 0 0 0 0 0 0 0 0 0 0 0 0
38915- 0 0 0 0 0 0 0 0 0 0 0 0
38916- 0 0 0 0 0 0 0 0 0 0 0 0
38917- 0 0 0 0 0 0 0 0 0 0 0 0
38918- 0 0 0 0 0 0 0 0 0 14 14 14
38919- 42 42 42 86 86 86 6 6 6 116 116 116
38920-106 106 106 6 6 6 70 70 70 149 149 149
38921-128 128 128 18 18 18 38 38 38 54 54 54
38922-221 221 221 106 106 106 2 2 6 14 14 14
38923- 46 46 46 190 190 190 198 198 198 2 2 6
38924- 2 2 6 2 2 6 2 2 6 2 2 6
38925- 74 74 74 62 62 62 22 22 22 6 6 6
38926- 0 0 0 0 0 0 0 0 0 0 0 0
38927- 0 0 0 0 0 0 0 0 0 0 0 0
38928- 0 0 0 0 0 0 0 0 0 0 0 0
38929- 0 0 0 0 0 0 0 0 0 0 0 0
38930- 0 0 0 0 0 0 0 0 0 0 0 0
38931- 0 0 0 0 0 0 0 0 0 0 0 0
38932- 0 0 0 0 0 0 0 0 1 0 0 0
38933- 0 0 1 0 0 0 0 0 1 0 0 0
38934- 0 0 0 0 0 0 0 0 0 0 0 0
38935- 0 0 0 0 0 0 0 0 0 0 0 0
38936- 0 0 0 0 0 0 0 0 0 0 0 0
38937- 0 0 0 0 0 0 0 0 0 0 0 0
38938- 0 0 0 0 0 0 0 0 0 14 14 14
38939- 42 42 42 94 94 94 14 14 14 101 101 101
38940-128 128 128 2 2 6 18 18 18 116 116 116
38941-118 98 46 121 92 8 121 92 8 98 78 10
38942-162 162 162 106 106 106 2 2 6 2 2 6
38943- 2 2 6 195 195 195 195 195 195 6 6 6
38944- 2 2 6 2 2 6 2 2 6 2 2 6
38945- 74 74 74 62 62 62 22 22 22 6 6 6
38946- 0 0 0 0 0 0 0 0 0 0 0 0
38947- 0 0 0 0 0 0 0 0 0 0 0 0
38948- 0 0 0 0 0 0 0 0 0 0 0 0
38949- 0 0 0 0 0 0 0 0 0 0 0 0
38950- 0 0 0 0 0 0 0 0 0 0 0 0
38951- 0 0 0 0 0 0 0 0 0 0 0 0
38952- 0 0 0 0 0 0 0 0 1 0 0 1
38953- 0 0 1 0 0 0 0 0 1 0 0 0
38954- 0 0 0 0 0 0 0 0 0 0 0 0
38955- 0 0 0 0 0 0 0 0 0 0 0 0
38956- 0 0 0 0 0 0 0 0 0 0 0 0
38957- 0 0 0 0 0 0 0 0 0 0 0 0
38958- 0 0 0 0 0 0 0 0 0 10 10 10
38959- 38 38 38 90 90 90 14 14 14 58 58 58
38960-210 210 210 26 26 26 54 38 6 154 114 10
38961-226 170 11 236 186 11 225 175 15 184 144 12
38962-215 174 15 175 146 61 37 26 9 2 2 6
38963- 70 70 70 246 246 246 138 138 138 2 2 6
38964- 2 2 6 2 2 6 2 2 6 2 2 6
38965- 70 70 70 66 66 66 26 26 26 6 6 6
38966- 0 0 0 0 0 0 0 0 0 0 0 0
38967- 0 0 0 0 0 0 0 0 0 0 0 0
38968- 0 0 0 0 0 0 0 0 0 0 0 0
38969- 0 0 0 0 0 0 0 0 0 0 0 0
38970- 0 0 0 0 0 0 0 0 0 0 0 0
38971- 0 0 0 0 0 0 0 0 0 0 0 0
38972- 0 0 0 0 0 0 0 0 0 0 0 0
38973- 0 0 0 0 0 0 0 0 0 0 0 0
38974- 0 0 0 0 0 0 0 0 0 0 0 0
38975- 0 0 0 0 0 0 0 0 0 0 0 0
38976- 0 0 0 0 0 0 0 0 0 0 0 0
38977- 0 0 0 0 0 0 0 0 0 0 0 0
38978- 0 0 0 0 0 0 0 0 0 10 10 10
38979- 38 38 38 86 86 86 14 14 14 10 10 10
38980-195 195 195 188 164 115 192 133 9 225 175 15
38981-239 182 13 234 190 10 232 195 16 232 200 30
38982-245 207 45 241 208 19 232 195 16 184 144 12
38983-218 194 134 211 206 186 42 42 42 2 2 6
38984- 2 2 6 2 2 6 2 2 6 2 2 6
38985- 50 50 50 74 74 74 30 30 30 6 6 6
38986- 0 0 0 0 0 0 0 0 0 0 0 0
38987- 0 0 0 0 0 0 0 0 0 0 0 0
38988- 0 0 0 0 0 0 0 0 0 0 0 0
38989- 0 0 0 0 0 0 0 0 0 0 0 0
38990- 0 0 0 0 0 0 0 0 0 0 0 0
38991- 0 0 0 0 0 0 0 0 0 0 0 0
38992- 0 0 0 0 0 0 0 0 0 0 0 0
38993- 0 0 0 0 0 0 0 0 0 0 0 0
38994- 0 0 0 0 0 0 0 0 0 0 0 0
38995- 0 0 0 0 0 0 0 0 0 0 0 0
38996- 0 0 0 0 0 0 0 0 0 0 0 0
38997- 0 0 0 0 0 0 0 0 0 0 0 0
38998- 0 0 0 0 0 0 0 0 0 10 10 10
38999- 34 34 34 86 86 86 14 14 14 2 2 6
39000-121 87 25 192 133 9 219 162 10 239 182 13
39001-236 186 11 232 195 16 241 208 19 244 214 54
39002-246 218 60 246 218 38 246 215 20 241 208 19
39003-241 208 19 226 184 13 121 87 25 2 2 6
39004- 2 2 6 2 2 6 2 2 6 2 2 6
39005- 50 50 50 82 82 82 34 34 34 10 10 10
39006- 0 0 0 0 0 0 0 0 0 0 0 0
39007- 0 0 0 0 0 0 0 0 0 0 0 0
39008- 0 0 0 0 0 0 0 0 0 0 0 0
39009- 0 0 0 0 0 0 0 0 0 0 0 0
39010- 0 0 0 0 0 0 0 0 0 0 0 0
39011- 0 0 0 0 0 0 0 0 0 0 0 0
39012- 0 0 0 0 0 0 0 0 0 0 0 0
39013- 0 0 0 0 0 0 0 0 0 0 0 0
39014- 0 0 0 0 0 0 0 0 0 0 0 0
39015- 0 0 0 0 0 0 0 0 0 0 0 0
39016- 0 0 0 0 0 0 0 0 0 0 0 0
39017- 0 0 0 0 0 0 0 0 0 0 0 0
39018- 0 0 0 0 0 0 0 0 0 10 10 10
39019- 34 34 34 82 82 82 30 30 30 61 42 6
39020-180 123 7 206 145 10 230 174 11 239 182 13
39021-234 190 10 238 202 15 241 208 19 246 218 74
39022-246 218 38 246 215 20 246 215 20 246 215 20
39023-226 184 13 215 174 15 184 144 12 6 6 6
39024- 2 2 6 2 2 6 2 2 6 2 2 6
39025- 26 26 26 94 94 94 42 42 42 14 14 14
39026- 0 0 0 0 0 0 0 0 0 0 0 0
39027- 0 0 0 0 0 0 0 0 0 0 0 0
39028- 0 0 0 0 0 0 0 0 0 0 0 0
39029- 0 0 0 0 0 0 0 0 0 0 0 0
39030- 0 0 0 0 0 0 0 0 0 0 0 0
39031- 0 0 0 0 0 0 0 0 0 0 0 0
39032- 0 0 0 0 0 0 0 0 0 0 0 0
39033- 0 0 0 0 0 0 0 0 0 0 0 0
39034- 0 0 0 0 0 0 0 0 0 0 0 0
39035- 0 0 0 0 0 0 0 0 0 0 0 0
39036- 0 0 0 0 0 0 0 0 0 0 0 0
39037- 0 0 0 0 0 0 0 0 0 0 0 0
39038- 0 0 0 0 0 0 0 0 0 10 10 10
39039- 30 30 30 78 78 78 50 50 50 104 69 6
39040-192 133 9 216 158 10 236 178 12 236 186 11
39041-232 195 16 241 208 19 244 214 54 245 215 43
39042-246 215 20 246 215 20 241 208 19 198 155 10
39043-200 144 11 216 158 10 156 118 10 2 2 6
39044- 2 2 6 2 2 6 2 2 6 2 2 6
39045- 6 6 6 90 90 90 54 54 54 18 18 18
39046- 6 6 6 0 0 0 0 0 0 0 0 0
39047- 0 0 0 0 0 0 0 0 0 0 0 0
39048- 0 0 0 0 0 0 0 0 0 0 0 0
39049- 0 0 0 0 0 0 0 0 0 0 0 0
39050- 0 0 0 0 0 0 0 0 0 0 0 0
39051- 0 0 0 0 0 0 0 0 0 0 0 0
39052- 0 0 0 0 0 0 0 0 0 0 0 0
39053- 0 0 0 0 0 0 0 0 0 0 0 0
39054- 0 0 0 0 0 0 0 0 0 0 0 0
39055- 0 0 0 0 0 0 0 0 0 0 0 0
39056- 0 0 0 0 0 0 0 0 0 0 0 0
39057- 0 0 0 0 0 0 0 0 0 0 0 0
39058- 0 0 0 0 0 0 0 0 0 10 10 10
39059- 30 30 30 78 78 78 46 46 46 22 22 22
39060-137 92 6 210 162 10 239 182 13 238 190 10
39061-238 202 15 241 208 19 246 215 20 246 215 20
39062-241 208 19 203 166 17 185 133 11 210 150 10
39063-216 158 10 210 150 10 102 78 10 2 2 6
39064- 6 6 6 54 54 54 14 14 14 2 2 6
39065- 2 2 6 62 62 62 74 74 74 30 30 30
39066- 10 10 10 0 0 0 0 0 0 0 0 0
39067- 0 0 0 0 0 0 0 0 0 0 0 0
39068- 0 0 0 0 0 0 0 0 0 0 0 0
39069- 0 0 0 0 0 0 0 0 0 0 0 0
39070- 0 0 0 0 0 0 0 0 0 0 0 0
39071- 0 0 0 0 0 0 0 0 0 0 0 0
39072- 0 0 0 0 0 0 0 0 0 0 0 0
39073- 0 0 0 0 0 0 0 0 0 0 0 0
39074- 0 0 0 0 0 0 0 0 0 0 0 0
39075- 0 0 0 0 0 0 0 0 0 0 0 0
39076- 0 0 0 0 0 0 0 0 0 0 0 0
39077- 0 0 0 0 0 0 0 0 0 0 0 0
39078- 0 0 0 0 0 0 0 0 0 10 10 10
39079- 34 34 34 78 78 78 50 50 50 6 6 6
39080- 94 70 30 139 102 15 190 146 13 226 184 13
39081-232 200 30 232 195 16 215 174 15 190 146 13
39082-168 122 10 192 133 9 210 150 10 213 154 11
39083-202 150 34 182 157 106 101 98 89 2 2 6
39084- 2 2 6 78 78 78 116 116 116 58 58 58
39085- 2 2 6 22 22 22 90 90 90 46 46 46
39086- 18 18 18 6 6 6 0 0 0 0 0 0
39087- 0 0 0 0 0 0 0 0 0 0 0 0
39088- 0 0 0 0 0 0 0 0 0 0 0 0
39089- 0 0 0 0 0 0 0 0 0 0 0 0
39090- 0 0 0 0 0 0 0 0 0 0 0 0
39091- 0 0 0 0 0 0 0 0 0 0 0 0
39092- 0 0 0 0 0 0 0 0 0 0 0 0
39093- 0 0 0 0 0 0 0 0 0 0 0 0
39094- 0 0 0 0 0 0 0 0 0 0 0 0
39095- 0 0 0 0 0 0 0 0 0 0 0 0
39096- 0 0 0 0 0 0 0 0 0 0 0 0
39097- 0 0 0 0 0 0 0 0 0 0 0 0
39098- 0 0 0 0 0 0 0 0 0 10 10 10
39099- 38 38 38 86 86 86 50 50 50 6 6 6
39100-128 128 128 174 154 114 156 107 11 168 122 10
39101-198 155 10 184 144 12 197 138 11 200 144 11
39102-206 145 10 206 145 10 197 138 11 188 164 115
39103-195 195 195 198 198 198 174 174 174 14 14 14
39104- 2 2 6 22 22 22 116 116 116 116 116 116
39105- 22 22 22 2 2 6 74 74 74 70 70 70
39106- 30 30 30 10 10 10 0 0 0 0 0 0
39107- 0 0 0 0 0 0 0 0 0 0 0 0
39108- 0 0 0 0 0 0 0 0 0 0 0 0
39109- 0 0 0 0 0 0 0 0 0 0 0 0
39110- 0 0 0 0 0 0 0 0 0 0 0 0
39111- 0 0 0 0 0 0 0 0 0 0 0 0
39112- 0 0 0 0 0 0 0 0 0 0 0 0
39113- 0 0 0 0 0 0 0 0 0 0 0 0
39114- 0 0 0 0 0 0 0 0 0 0 0 0
39115- 0 0 0 0 0 0 0 0 0 0 0 0
39116- 0 0 0 0 0 0 0 0 0 0 0 0
39117- 0 0 0 0 0 0 0 0 0 0 0 0
39118- 0 0 0 0 0 0 6 6 6 18 18 18
39119- 50 50 50 101 101 101 26 26 26 10 10 10
39120-138 138 138 190 190 190 174 154 114 156 107 11
39121-197 138 11 200 144 11 197 138 11 192 133 9
39122-180 123 7 190 142 34 190 178 144 187 187 187
39123-202 202 202 221 221 221 214 214 214 66 66 66
39124- 2 2 6 2 2 6 50 50 50 62 62 62
39125- 6 6 6 2 2 6 10 10 10 90 90 90
39126- 50 50 50 18 18 18 6 6 6 0 0 0
39127- 0 0 0 0 0 0 0 0 0 0 0 0
39128- 0 0 0 0 0 0 0 0 0 0 0 0
39129- 0 0 0 0 0 0 0 0 0 0 0 0
39130- 0 0 0 0 0 0 0 0 0 0 0 0
39131- 0 0 0 0 0 0 0 0 0 0 0 0
39132- 0 0 0 0 0 0 0 0 0 0 0 0
39133- 0 0 0 0 0 0 0 0 0 0 0 0
39134- 0 0 0 0 0 0 0 0 0 0 0 0
39135- 0 0 0 0 0 0 0 0 0 0 0 0
39136- 0 0 0 0 0 0 0 0 0 0 0 0
39137- 0 0 0 0 0 0 0 0 0 0 0 0
39138- 0 0 0 0 0 0 10 10 10 34 34 34
39139- 74 74 74 74 74 74 2 2 6 6 6 6
39140-144 144 144 198 198 198 190 190 190 178 166 146
39141-154 121 60 156 107 11 156 107 11 168 124 44
39142-174 154 114 187 187 187 190 190 190 210 210 210
39143-246 246 246 253 253 253 253 253 253 182 182 182
39144- 6 6 6 2 2 6 2 2 6 2 2 6
39145- 2 2 6 2 2 6 2 2 6 62 62 62
39146- 74 74 74 34 34 34 14 14 14 0 0 0
39147- 0 0 0 0 0 0 0 0 0 0 0 0
39148- 0 0 0 0 0 0 0 0 0 0 0 0
39149- 0 0 0 0 0 0 0 0 0 0 0 0
39150- 0 0 0 0 0 0 0 0 0 0 0 0
39151- 0 0 0 0 0 0 0 0 0 0 0 0
39152- 0 0 0 0 0 0 0 0 0 0 0 0
39153- 0 0 0 0 0 0 0 0 0 0 0 0
39154- 0 0 0 0 0 0 0 0 0 0 0 0
39155- 0 0 0 0 0 0 0 0 0 0 0 0
39156- 0 0 0 0 0 0 0 0 0 0 0 0
39157- 0 0 0 0 0 0 0 0 0 0 0 0
39158- 0 0 0 10 10 10 22 22 22 54 54 54
39159- 94 94 94 18 18 18 2 2 6 46 46 46
39160-234 234 234 221 221 221 190 190 190 190 190 190
39161-190 190 190 187 187 187 187 187 187 190 190 190
39162-190 190 190 195 195 195 214 214 214 242 242 242
39163-253 253 253 253 253 253 253 253 253 253 253 253
39164- 82 82 82 2 2 6 2 2 6 2 2 6
39165- 2 2 6 2 2 6 2 2 6 14 14 14
39166- 86 86 86 54 54 54 22 22 22 6 6 6
39167- 0 0 0 0 0 0 0 0 0 0 0 0
39168- 0 0 0 0 0 0 0 0 0 0 0 0
39169- 0 0 0 0 0 0 0 0 0 0 0 0
39170- 0 0 0 0 0 0 0 0 0 0 0 0
39171- 0 0 0 0 0 0 0 0 0 0 0 0
39172- 0 0 0 0 0 0 0 0 0 0 0 0
39173- 0 0 0 0 0 0 0 0 0 0 0 0
39174- 0 0 0 0 0 0 0 0 0 0 0 0
39175- 0 0 0 0 0 0 0 0 0 0 0 0
39176- 0 0 0 0 0 0 0 0 0 0 0 0
39177- 0 0 0 0 0 0 0 0 0 0 0 0
39178- 6 6 6 18 18 18 46 46 46 90 90 90
39179- 46 46 46 18 18 18 6 6 6 182 182 182
39180-253 253 253 246 246 246 206 206 206 190 190 190
39181-190 190 190 190 190 190 190 190 190 190 190 190
39182-206 206 206 231 231 231 250 250 250 253 253 253
39183-253 253 253 253 253 253 253 253 253 253 253 253
39184-202 202 202 14 14 14 2 2 6 2 2 6
39185- 2 2 6 2 2 6 2 2 6 2 2 6
39186- 42 42 42 86 86 86 42 42 42 18 18 18
39187- 6 6 6 0 0 0 0 0 0 0 0 0
39188- 0 0 0 0 0 0 0 0 0 0 0 0
39189- 0 0 0 0 0 0 0 0 0 0 0 0
39190- 0 0 0 0 0 0 0 0 0 0 0 0
39191- 0 0 0 0 0 0 0 0 0 0 0 0
39192- 0 0 0 0 0 0 0 0 0 0 0 0
39193- 0 0 0 0 0 0 0 0 0 0 0 0
39194- 0 0 0 0 0 0 0 0 0 0 0 0
39195- 0 0 0 0 0 0 0 0 0 0 0 0
39196- 0 0 0 0 0 0 0 0 0 0 0 0
39197- 0 0 0 0 0 0 0 0 0 6 6 6
39198- 14 14 14 38 38 38 74 74 74 66 66 66
39199- 2 2 6 6 6 6 90 90 90 250 250 250
39200-253 253 253 253 253 253 238 238 238 198 198 198
39201-190 190 190 190 190 190 195 195 195 221 221 221
39202-246 246 246 253 253 253 253 253 253 253 253 253
39203-253 253 253 253 253 253 253 253 253 253 253 253
39204-253 253 253 82 82 82 2 2 6 2 2 6
39205- 2 2 6 2 2 6 2 2 6 2 2 6
39206- 2 2 6 78 78 78 70 70 70 34 34 34
39207- 14 14 14 6 6 6 0 0 0 0 0 0
39208- 0 0 0 0 0 0 0 0 0 0 0 0
39209- 0 0 0 0 0 0 0 0 0 0 0 0
39210- 0 0 0 0 0 0 0 0 0 0 0 0
39211- 0 0 0 0 0 0 0 0 0 0 0 0
39212- 0 0 0 0 0 0 0 0 0 0 0 0
39213- 0 0 0 0 0 0 0 0 0 0 0 0
39214- 0 0 0 0 0 0 0 0 0 0 0 0
39215- 0 0 0 0 0 0 0 0 0 0 0 0
39216- 0 0 0 0 0 0 0 0 0 0 0 0
39217- 0 0 0 0 0 0 0 0 0 14 14 14
39218- 34 34 34 66 66 66 78 78 78 6 6 6
39219- 2 2 6 18 18 18 218 218 218 253 253 253
39220-253 253 253 253 253 253 253 253 253 246 246 246
39221-226 226 226 231 231 231 246 246 246 253 253 253
39222-253 253 253 253 253 253 253 253 253 253 253 253
39223-253 253 253 253 253 253 253 253 253 253 253 253
39224-253 253 253 178 178 178 2 2 6 2 2 6
39225- 2 2 6 2 2 6 2 2 6 2 2 6
39226- 2 2 6 18 18 18 90 90 90 62 62 62
39227- 30 30 30 10 10 10 0 0 0 0 0 0
39228- 0 0 0 0 0 0 0 0 0 0 0 0
39229- 0 0 0 0 0 0 0 0 0 0 0 0
39230- 0 0 0 0 0 0 0 0 0 0 0 0
39231- 0 0 0 0 0 0 0 0 0 0 0 0
39232- 0 0 0 0 0 0 0 0 0 0 0 0
39233- 0 0 0 0 0 0 0 0 0 0 0 0
39234- 0 0 0 0 0 0 0 0 0 0 0 0
39235- 0 0 0 0 0 0 0 0 0 0 0 0
39236- 0 0 0 0 0 0 0 0 0 0 0 0
39237- 0 0 0 0 0 0 10 10 10 26 26 26
39238- 58 58 58 90 90 90 18 18 18 2 2 6
39239- 2 2 6 110 110 110 253 253 253 253 253 253
39240-253 253 253 253 253 253 253 253 253 253 253 253
39241-250 250 250 253 253 253 253 253 253 253 253 253
39242-253 253 253 253 253 253 253 253 253 253 253 253
39243-253 253 253 253 253 253 253 253 253 253 253 253
39244-253 253 253 231 231 231 18 18 18 2 2 6
39245- 2 2 6 2 2 6 2 2 6 2 2 6
39246- 2 2 6 2 2 6 18 18 18 94 94 94
39247- 54 54 54 26 26 26 10 10 10 0 0 0
39248- 0 0 0 0 0 0 0 0 0 0 0 0
39249- 0 0 0 0 0 0 0 0 0 0 0 0
39250- 0 0 0 0 0 0 0 0 0 0 0 0
39251- 0 0 0 0 0 0 0 0 0 0 0 0
39252- 0 0 0 0 0 0 0 0 0 0 0 0
39253- 0 0 0 0 0 0 0 0 0 0 0 0
39254- 0 0 0 0 0 0 0 0 0 0 0 0
39255- 0 0 0 0 0 0 0 0 0 0 0 0
39256- 0 0 0 0 0 0 0 0 0 0 0 0
39257- 0 0 0 6 6 6 22 22 22 50 50 50
39258- 90 90 90 26 26 26 2 2 6 2 2 6
39259- 14 14 14 195 195 195 250 250 250 253 253 253
39260-253 253 253 253 253 253 253 253 253 253 253 253
39261-253 253 253 253 253 253 253 253 253 253 253 253
39262-253 253 253 253 253 253 253 253 253 253 253 253
39263-253 253 253 253 253 253 253 253 253 253 253 253
39264-250 250 250 242 242 242 54 54 54 2 2 6
39265- 2 2 6 2 2 6 2 2 6 2 2 6
39266- 2 2 6 2 2 6 2 2 6 38 38 38
39267- 86 86 86 50 50 50 22 22 22 6 6 6
39268- 0 0 0 0 0 0 0 0 0 0 0 0
39269- 0 0 0 0 0 0 0 0 0 0 0 0
39270- 0 0 0 0 0 0 0 0 0 0 0 0
39271- 0 0 0 0 0 0 0 0 0 0 0 0
39272- 0 0 0 0 0 0 0 0 0 0 0 0
39273- 0 0 0 0 0 0 0 0 0 0 0 0
39274- 0 0 0 0 0 0 0 0 0 0 0 0
39275- 0 0 0 0 0 0 0 0 0 0 0 0
39276- 0 0 0 0 0 0 0 0 0 0 0 0
39277- 6 6 6 14 14 14 38 38 38 82 82 82
39278- 34 34 34 2 2 6 2 2 6 2 2 6
39279- 42 42 42 195 195 195 246 246 246 253 253 253
39280-253 253 253 253 253 253 253 253 253 250 250 250
39281-242 242 242 242 242 242 250 250 250 253 253 253
39282-253 253 253 253 253 253 253 253 253 253 253 253
39283-253 253 253 250 250 250 246 246 246 238 238 238
39284-226 226 226 231 231 231 101 101 101 6 6 6
39285- 2 2 6 2 2 6 2 2 6 2 2 6
39286- 2 2 6 2 2 6 2 2 6 2 2 6
39287- 38 38 38 82 82 82 42 42 42 14 14 14
39288- 6 6 6 0 0 0 0 0 0 0 0 0
39289- 0 0 0 0 0 0 0 0 0 0 0 0
39290- 0 0 0 0 0 0 0 0 0 0 0 0
39291- 0 0 0 0 0 0 0 0 0 0 0 0
39292- 0 0 0 0 0 0 0 0 0 0 0 0
39293- 0 0 0 0 0 0 0 0 0 0 0 0
39294- 0 0 0 0 0 0 0 0 0 0 0 0
39295- 0 0 0 0 0 0 0 0 0 0 0 0
39296- 0 0 0 0 0 0 0 0 0 0 0 0
39297- 10 10 10 26 26 26 62 62 62 66 66 66
39298- 2 2 6 2 2 6 2 2 6 6 6 6
39299- 70 70 70 170 170 170 206 206 206 234 234 234
39300-246 246 246 250 250 250 250 250 250 238 238 238
39301-226 226 226 231 231 231 238 238 238 250 250 250
39302-250 250 250 250 250 250 246 246 246 231 231 231
39303-214 214 214 206 206 206 202 202 202 202 202 202
39304-198 198 198 202 202 202 182 182 182 18 18 18
39305- 2 2 6 2 2 6 2 2 6 2 2 6
39306- 2 2 6 2 2 6 2 2 6 2 2 6
39307- 2 2 6 62 62 62 66 66 66 30 30 30
39308- 10 10 10 0 0 0 0 0 0 0 0 0
39309- 0 0 0 0 0 0 0 0 0 0 0 0
39310- 0 0 0 0 0 0 0 0 0 0 0 0
39311- 0 0 0 0 0 0 0 0 0 0 0 0
39312- 0 0 0 0 0 0 0 0 0 0 0 0
39313- 0 0 0 0 0 0 0 0 0 0 0 0
39314- 0 0 0 0 0 0 0 0 0 0 0 0
39315- 0 0 0 0 0 0 0 0 0 0 0 0
39316- 0 0 0 0 0 0 0 0 0 0 0 0
39317- 14 14 14 42 42 42 82 82 82 18 18 18
39318- 2 2 6 2 2 6 2 2 6 10 10 10
39319- 94 94 94 182 182 182 218 218 218 242 242 242
39320-250 250 250 253 253 253 253 253 253 250 250 250
39321-234 234 234 253 253 253 253 253 253 253 253 253
39322-253 253 253 253 253 253 253 253 253 246 246 246
39323-238 238 238 226 226 226 210 210 210 202 202 202
39324-195 195 195 195 195 195 210 210 210 158 158 158
39325- 6 6 6 14 14 14 50 50 50 14 14 14
39326- 2 2 6 2 2 6 2 2 6 2 2 6
39327- 2 2 6 6 6 6 86 86 86 46 46 46
39328- 18 18 18 6 6 6 0 0 0 0 0 0
39329- 0 0 0 0 0 0 0 0 0 0 0 0
39330- 0 0 0 0 0 0 0 0 0 0 0 0
39331- 0 0 0 0 0 0 0 0 0 0 0 0
39332- 0 0 0 0 0 0 0 0 0 0 0 0
39333- 0 0 0 0 0 0 0 0 0 0 0 0
39334- 0 0 0 0 0 0 0 0 0 0 0 0
39335- 0 0 0 0 0 0 0 0 0 0 0 0
39336- 0 0 0 0 0 0 0 0 0 6 6 6
39337- 22 22 22 54 54 54 70 70 70 2 2 6
39338- 2 2 6 10 10 10 2 2 6 22 22 22
39339-166 166 166 231 231 231 250 250 250 253 253 253
39340-253 253 253 253 253 253 253 253 253 250 250 250
39341-242 242 242 253 253 253 253 253 253 253 253 253
39342-253 253 253 253 253 253 253 253 253 253 253 253
39343-253 253 253 253 253 253 253 253 253 246 246 246
39344-231 231 231 206 206 206 198 198 198 226 226 226
39345- 94 94 94 2 2 6 6 6 6 38 38 38
39346- 30 30 30 2 2 6 2 2 6 2 2 6
39347- 2 2 6 2 2 6 62 62 62 66 66 66
39348- 26 26 26 10 10 10 0 0 0 0 0 0
39349- 0 0 0 0 0 0 0 0 0 0 0 0
39350- 0 0 0 0 0 0 0 0 0 0 0 0
39351- 0 0 0 0 0 0 0 0 0 0 0 0
39352- 0 0 0 0 0 0 0 0 0 0 0 0
39353- 0 0 0 0 0 0 0 0 0 0 0 0
39354- 0 0 0 0 0 0 0 0 0 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 10 10 10
39357- 30 30 30 74 74 74 50 50 50 2 2 6
39358- 26 26 26 26 26 26 2 2 6 106 106 106
39359-238 238 238 253 253 253 253 253 253 253 253 253
39360-253 253 253 253 253 253 253 253 253 253 253 253
39361-253 253 253 253 253 253 253 253 253 253 253 253
39362-253 253 253 253 253 253 253 253 253 253 253 253
39363-253 253 253 253 253 253 253 253 253 253 253 253
39364-253 253 253 246 246 246 218 218 218 202 202 202
39365-210 210 210 14 14 14 2 2 6 2 2 6
39366- 30 30 30 22 22 22 2 2 6 2 2 6
39367- 2 2 6 2 2 6 18 18 18 86 86 86
39368- 42 42 42 14 14 14 0 0 0 0 0 0
39369- 0 0 0 0 0 0 0 0 0 0 0 0
39370- 0 0 0 0 0 0 0 0 0 0 0 0
39371- 0 0 0 0 0 0 0 0 0 0 0 0
39372- 0 0 0 0 0 0 0 0 0 0 0 0
39373- 0 0 0 0 0 0 0 0 0 0 0 0
39374- 0 0 0 0 0 0 0 0 0 0 0 0
39375- 0 0 0 0 0 0 0 0 0 0 0 0
39376- 0 0 0 0 0 0 0 0 0 14 14 14
39377- 42 42 42 90 90 90 22 22 22 2 2 6
39378- 42 42 42 2 2 6 18 18 18 218 218 218
39379-253 253 253 253 253 253 253 253 253 253 253 253
39380-253 253 253 253 253 253 253 253 253 253 253 253
39381-253 253 253 253 253 253 253 253 253 253 253 253
39382-253 253 253 253 253 253 253 253 253 253 253 253
39383-253 253 253 253 253 253 253 253 253 253 253 253
39384-253 253 253 253 253 253 250 250 250 221 221 221
39385-218 218 218 101 101 101 2 2 6 14 14 14
39386- 18 18 18 38 38 38 10 10 10 2 2 6
39387- 2 2 6 2 2 6 2 2 6 78 78 78
39388- 58 58 58 22 22 22 6 6 6 0 0 0
39389- 0 0 0 0 0 0 0 0 0 0 0 0
39390- 0 0 0 0 0 0 0 0 0 0 0 0
39391- 0 0 0 0 0 0 0 0 0 0 0 0
39392- 0 0 0 0 0 0 0 0 0 0 0 0
39393- 0 0 0 0 0 0 0 0 0 0 0 0
39394- 0 0 0 0 0 0 0 0 0 0 0 0
39395- 0 0 0 0 0 0 0 0 0 0 0 0
39396- 0 0 0 0 0 0 6 6 6 18 18 18
39397- 54 54 54 82 82 82 2 2 6 26 26 26
39398- 22 22 22 2 2 6 123 123 123 253 253 253
39399-253 253 253 253 253 253 253 253 253 253 253 253
39400-253 253 253 253 253 253 253 253 253 253 253 253
39401-253 253 253 253 253 253 253 253 253 253 253 253
39402-253 253 253 253 253 253 253 253 253 253 253 253
39403-253 253 253 253 253 253 253 253 253 253 253 253
39404-253 253 253 253 253 253 253 253 253 250 250 250
39405-238 238 238 198 198 198 6 6 6 38 38 38
39406- 58 58 58 26 26 26 38 38 38 2 2 6
39407- 2 2 6 2 2 6 2 2 6 46 46 46
39408- 78 78 78 30 30 30 10 10 10 0 0 0
39409- 0 0 0 0 0 0 0 0 0 0 0 0
39410- 0 0 0 0 0 0 0 0 0 0 0 0
39411- 0 0 0 0 0 0 0 0 0 0 0 0
39412- 0 0 0 0 0 0 0 0 0 0 0 0
39413- 0 0 0 0 0 0 0 0 0 0 0 0
39414- 0 0 0 0 0 0 0 0 0 0 0 0
39415- 0 0 0 0 0 0 0 0 0 0 0 0
39416- 0 0 0 0 0 0 10 10 10 30 30 30
39417- 74 74 74 58 58 58 2 2 6 42 42 42
39418- 2 2 6 22 22 22 231 231 231 253 253 253
39419-253 253 253 253 253 253 253 253 253 253 253 253
39420-253 253 253 253 253 253 253 253 253 250 250 250
39421-253 253 253 253 253 253 253 253 253 253 253 253
39422-253 253 253 253 253 253 253 253 253 253 253 253
39423-253 253 253 253 253 253 253 253 253 253 253 253
39424-253 253 253 253 253 253 253 253 253 253 253 253
39425-253 253 253 246 246 246 46 46 46 38 38 38
39426- 42 42 42 14 14 14 38 38 38 14 14 14
39427- 2 2 6 2 2 6 2 2 6 6 6 6
39428- 86 86 86 46 46 46 14 14 14 0 0 0
39429- 0 0 0 0 0 0 0 0 0 0 0 0
39430- 0 0 0 0 0 0 0 0 0 0 0 0
39431- 0 0 0 0 0 0 0 0 0 0 0 0
39432- 0 0 0 0 0 0 0 0 0 0 0 0
39433- 0 0 0 0 0 0 0 0 0 0 0 0
39434- 0 0 0 0 0 0 0 0 0 0 0 0
39435- 0 0 0 0 0 0 0 0 0 0 0 0
39436- 0 0 0 6 6 6 14 14 14 42 42 42
39437- 90 90 90 18 18 18 18 18 18 26 26 26
39438- 2 2 6 116 116 116 253 253 253 253 253 253
39439-253 253 253 253 253 253 253 253 253 253 253 253
39440-253 253 253 253 253 253 250 250 250 238 238 238
39441-253 253 253 253 253 253 253 253 253 253 253 253
39442-253 253 253 253 253 253 253 253 253 253 253 253
39443-253 253 253 253 253 253 253 253 253 253 253 253
39444-253 253 253 253 253 253 253 253 253 253 253 253
39445-253 253 253 253 253 253 94 94 94 6 6 6
39446- 2 2 6 2 2 6 10 10 10 34 34 34
39447- 2 2 6 2 2 6 2 2 6 2 2 6
39448- 74 74 74 58 58 58 22 22 22 6 6 6
39449- 0 0 0 0 0 0 0 0 0 0 0 0
39450- 0 0 0 0 0 0 0 0 0 0 0 0
39451- 0 0 0 0 0 0 0 0 0 0 0 0
39452- 0 0 0 0 0 0 0 0 0 0 0 0
39453- 0 0 0 0 0 0 0 0 0 0 0 0
39454- 0 0 0 0 0 0 0 0 0 0 0 0
39455- 0 0 0 0 0 0 0 0 0 0 0 0
39456- 0 0 0 10 10 10 26 26 26 66 66 66
39457- 82 82 82 2 2 6 38 38 38 6 6 6
39458- 14 14 14 210 210 210 253 253 253 253 253 253
39459-253 253 253 253 253 253 253 253 253 253 253 253
39460-253 253 253 253 253 253 246 246 246 242 242 242
39461-253 253 253 253 253 253 253 253 253 253 253 253
39462-253 253 253 253 253 253 253 253 253 253 253 253
39463-253 253 253 253 253 253 253 253 253 253 253 253
39464-253 253 253 253 253 253 253 253 253 253 253 253
39465-253 253 253 253 253 253 144 144 144 2 2 6
39466- 2 2 6 2 2 6 2 2 6 46 46 46
39467- 2 2 6 2 2 6 2 2 6 2 2 6
39468- 42 42 42 74 74 74 30 30 30 10 10 10
39469- 0 0 0 0 0 0 0 0 0 0 0 0
39470- 0 0 0 0 0 0 0 0 0 0 0 0
39471- 0 0 0 0 0 0 0 0 0 0 0 0
39472- 0 0 0 0 0 0 0 0 0 0 0 0
39473- 0 0 0 0 0 0 0 0 0 0 0 0
39474- 0 0 0 0 0 0 0 0 0 0 0 0
39475- 0 0 0 0 0 0 0 0 0 0 0 0
39476- 6 6 6 14 14 14 42 42 42 90 90 90
39477- 26 26 26 6 6 6 42 42 42 2 2 6
39478- 74 74 74 250 250 250 253 253 253 253 253 253
39479-253 253 253 253 253 253 253 253 253 253 253 253
39480-253 253 253 253 253 253 242 242 242 242 242 242
39481-253 253 253 253 253 253 253 253 253 253 253 253
39482-253 253 253 253 253 253 253 253 253 253 253 253
39483-253 253 253 253 253 253 253 253 253 253 253 253
39484-253 253 253 253 253 253 253 253 253 253 253 253
39485-253 253 253 253 253 253 182 182 182 2 2 6
39486- 2 2 6 2 2 6 2 2 6 46 46 46
39487- 2 2 6 2 2 6 2 2 6 2 2 6
39488- 10 10 10 86 86 86 38 38 38 10 10 10
39489- 0 0 0 0 0 0 0 0 0 0 0 0
39490- 0 0 0 0 0 0 0 0 0 0 0 0
39491- 0 0 0 0 0 0 0 0 0 0 0 0
39492- 0 0 0 0 0 0 0 0 0 0 0 0
39493- 0 0 0 0 0 0 0 0 0 0 0 0
39494- 0 0 0 0 0 0 0 0 0 0 0 0
39495- 0 0 0 0 0 0 0 0 0 0 0 0
39496- 10 10 10 26 26 26 66 66 66 82 82 82
39497- 2 2 6 22 22 22 18 18 18 2 2 6
39498-149 149 149 253 253 253 253 253 253 253 253 253
39499-253 253 253 253 253 253 253 253 253 253 253 253
39500-253 253 253 253 253 253 234 234 234 242 242 242
39501-253 253 253 253 253 253 253 253 253 253 253 253
39502-253 253 253 253 253 253 253 253 253 253 253 253
39503-253 253 253 253 253 253 253 253 253 253 253 253
39504-253 253 253 253 253 253 253 253 253 253 253 253
39505-253 253 253 253 253 253 206 206 206 2 2 6
39506- 2 2 6 2 2 6 2 2 6 38 38 38
39507- 2 2 6 2 2 6 2 2 6 2 2 6
39508- 6 6 6 86 86 86 46 46 46 14 14 14
39509- 0 0 0 0 0 0 0 0 0 0 0 0
39510- 0 0 0 0 0 0 0 0 0 0 0 0
39511- 0 0 0 0 0 0 0 0 0 0 0 0
39512- 0 0 0 0 0 0 0 0 0 0 0 0
39513- 0 0 0 0 0 0 0 0 0 0 0 0
39514- 0 0 0 0 0 0 0 0 0 0 0 0
39515- 0 0 0 0 0 0 0 0 0 6 6 6
39516- 18 18 18 46 46 46 86 86 86 18 18 18
39517- 2 2 6 34 34 34 10 10 10 6 6 6
39518-210 210 210 253 253 253 253 253 253 253 253 253
39519-253 253 253 253 253 253 253 253 253 253 253 253
39520-253 253 253 253 253 253 234 234 234 242 242 242
39521-253 253 253 253 253 253 253 253 253 253 253 253
39522-253 253 253 253 253 253 253 253 253 253 253 253
39523-253 253 253 253 253 253 253 253 253 253 253 253
39524-253 253 253 253 253 253 253 253 253 253 253 253
39525-253 253 253 253 253 253 221 221 221 6 6 6
39526- 2 2 6 2 2 6 6 6 6 30 30 30
39527- 2 2 6 2 2 6 2 2 6 2 2 6
39528- 2 2 6 82 82 82 54 54 54 18 18 18
39529- 6 6 6 0 0 0 0 0 0 0 0 0
39530- 0 0 0 0 0 0 0 0 0 0 0 0
39531- 0 0 0 0 0 0 0 0 0 0 0 0
39532- 0 0 0 0 0 0 0 0 0 0 0 0
39533- 0 0 0 0 0 0 0 0 0 0 0 0
39534- 0 0 0 0 0 0 0 0 0 0 0 0
39535- 0 0 0 0 0 0 0 0 0 10 10 10
39536- 26 26 26 66 66 66 62 62 62 2 2 6
39537- 2 2 6 38 38 38 10 10 10 26 26 26
39538-238 238 238 253 253 253 253 253 253 253 253 253
39539-253 253 253 253 253 253 253 253 253 253 253 253
39540-253 253 253 253 253 253 231 231 231 238 238 238
39541-253 253 253 253 253 253 253 253 253 253 253 253
39542-253 253 253 253 253 253 253 253 253 253 253 253
39543-253 253 253 253 253 253 253 253 253 253 253 253
39544-253 253 253 253 253 253 253 253 253 253 253 253
39545-253 253 253 253 253 253 231 231 231 6 6 6
39546- 2 2 6 2 2 6 10 10 10 30 30 30
39547- 2 2 6 2 2 6 2 2 6 2 2 6
39548- 2 2 6 66 66 66 58 58 58 22 22 22
39549- 6 6 6 0 0 0 0 0 0 0 0 0
39550- 0 0 0 0 0 0 0 0 0 0 0 0
39551- 0 0 0 0 0 0 0 0 0 0 0 0
39552- 0 0 0 0 0 0 0 0 0 0 0 0
39553- 0 0 0 0 0 0 0 0 0 0 0 0
39554- 0 0 0 0 0 0 0 0 0 0 0 0
39555- 0 0 0 0 0 0 0 0 0 10 10 10
39556- 38 38 38 78 78 78 6 6 6 2 2 6
39557- 2 2 6 46 46 46 14 14 14 42 42 42
39558-246 246 246 253 253 253 253 253 253 253 253 253
39559-253 253 253 253 253 253 253 253 253 253 253 253
39560-253 253 253 253 253 253 231 231 231 242 242 242
39561-253 253 253 253 253 253 253 253 253 253 253 253
39562-253 253 253 253 253 253 253 253 253 253 253 253
39563-253 253 253 253 253 253 253 253 253 253 253 253
39564-253 253 253 253 253 253 253 253 253 253 253 253
39565-253 253 253 253 253 253 234 234 234 10 10 10
39566- 2 2 6 2 2 6 22 22 22 14 14 14
39567- 2 2 6 2 2 6 2 2 6 2 2 6
39568- 2 2 6 66 66 66 62 62 62 22 22 22
39569- 6 6 6 0 0 0 0 0 0 0 0 0
39570- 0 0 0 0 0 0 0 0 0 0 0 0
39571- 0 0 0 0 0 0 0 0 0 0 0 0
39572- 0 0 0 0 0 0 0 0 0 0 0 0
39573- 0 0 0 0 0 0 0 0 0 0 0 0
39574- 0 0 0 0 0 0 0 0 0 0 0 0
39575- 0 0 0 0 0 0 6 6 6 18 18 18
39576- 50 50 50 74 74 74 2 2 6 2 2 6
39577- 14 14 14 70 70 70 34 34 34 62 62 62
39578-250 250 250 253 253 253 253 253 253 253 253 253
39579-253 253 253 253 253 253 253 253 253 253 253 253
39580-253 253 253 253 253 253 231 231 231 246 246 246
39581-253 253 253 253 253 253 253 253 253 253 253 253
39582-253 253 253 253 253 253 253 253 253 253 253 253
39583-253 253 253 253 253 253 253 253 253 253 253 253
39584-253 253 253 253 253 253 253 253 253 253 253 253
39585-253 253 253 253 253 253 234 234 234 14 14 14
39586- 2 2 6 2 2 6 30 30 30 2 2 6
39587- 2 2 6 2 2 6 2 2 6 2 2 6
39588- 2 2 6 66 66 66 62 62 62 22 22 22
39589- 6 6 6 0 0 0 0 0 0 0 0 0
39590- 0 0 0 0 0 0 0 0 0 0 0 0
39591- 0 0 0 0 0 0 0 0 0 0 0 0
39592- 0 0 0 0 0 0 0 0 0 0 0 0
39593- 0 0 0 0 0 0 0 0 0 0 0 0
39594- 0 0 0 0 0 0 0 0 0 0 0 0
39595- 0 0 0 0 0 0 6 6 6 18 18 18
39596- 54 54 54 62 62 62 2 2 6 2 2 6
39597- 2 2 6 30 30 30 46 46 46 70 70 70
39598-250 250 250 253 253 253 253 253 253 253 253 253
39599-253 253 253 253 253 253 253 253 253 253 253 253
39600-253 253 253 253 253 253 231 231 231 246 246 246
39601-253 253 253 253 253 253 253 253 253 253 253 253
39602-253 253 253 253 253 253 253 253 253 253 253 253
39603-253 253 253 253 253 253 253 253 253 253 253 253
39604-253 253 253 253 253 253 253 253 253 253 253 253
39605-253 253 253 253 253 253 226 226 226 10 10 10
39606- 2 2 6 6 6 6 30 30 30 2 2 6
39607- 2 2 6 2 2 6 2 2 6 2 2 6
39608- 2 2 6 66 66 66 58 58 58 22 22 22
39609- 6 6 6 0 0 0 0 0 0 0 0 0
39610- 0 0 0 0 0 0 0 0 0 0 0 0
39611- 0 0 0 0 0 0 0 0 0 0 0 0
39612- 0 0 0 0 0 0 0 0 0 0 0 0
39613- 0 0 0 0 0 0 0 0 0 0 0 0
39614- 0 0 0 0 0 0 0 0 0 0 0 0
39615- 0 0 0 0 0 0 6 6 6 22 22 22
39616- 58 58 58 62 62 62 2 2 6 2 2 6
39617- 2 2 6 2 2 6 30 30 30 78 78 78
39618-250 250 250 253 253 253 253 253 253 253 253 253
39619-253 253 253 253 253 253 253 253 253 253 253 253
39620-253 253 253 253 253 253 231 231 231 246 246 246
39621-253 253 253 253 253 253 253 253 253 253 253 253
39622-253 253 253 253 253 253 253 253 253 253 253 253
39623-253 253 253 253 253 253 253 253 253 253 253 253
39624-253 253 253 253 253 253 253 253 253 253 253 253
39625-253 253 253 253 253 253 206 206 206 2 2 6
39626- 22 22 22 34 34 34 18 14 6 22 22 22
39627- 26 26 26 18 18 18 6 6 6 2 2 6
39628- 2 2 6 82 82 82 54 54 54 18 18 18
39629- 6 6 6 0 0 0 0 0 0 0 0 0
39630- 0 0 0 0 0 0 0 0 0 0 0 0
39631- 0 0 0 0 0 0 0 0 0 0 0 0
39632- 0 0 0 0 0 0 0 0 0 0 0 0
39633- 0 0 0 0 0 0 0 0 0 0 0 0
39634- 0 0 0 0 0 0 0 0 0 0 0 0
39635- 0 0 0 0 0 0 6 6 6 26 26 26
39636- 62 62 62 106 106 106 74 54 14 185 133 11
39637-210 162 10 121 92 8 6 6 6 62 62 62
39638-238 238 238 253 253 253 253 253 253 253 253 253
39639-253 253 253 253 253 253 253 253 253 253 253 253
39640-253 253 253 253 253 253 231 231 231 246 246 246
39641-253 253 253 253 253 253 253 253 253 253 253 253
39642-253 253 253 253 253 253 253 253 253 253 253 253
39643-253 253 253 253 253 253 253 253 253 253 253 253
39644-253 253 253 253 253 253 253 253 253 253 253 253
39645-253 253 253 253 253 253 158 158 158 18 18 18
39646- 14 14 14 2 2 6 2 2 6 2 2 6
39647- 6 6 6 18 18 18 66 66 66 38 38 38
39648- 6 6 6 94 94 94 50 50 50 18 18 18
39649- 6 6 6 0 0 0 0 0 0 0 0 0
39650- 0 0 0 0 0 0 0 0 0 0 0 0
39651- 0 0 0 0 0 0 0 0 0 0 0 0
39652- 0 0 0 0 0 0 0 0 0 0 0 0
39653- 0 0 0 0 0 0 0 0 0 0 0 0
39654- 0 0 0 0 0 0 0 0 0 6 6 6
39655- 10 10 10 10 10 10 18 18 18 38 38 38
39656- 78 78 78 142 134 106 216 158 10 242 186 14
39657-246 190 14 246 190 14 156 118 10 10 10 10
39658- 90 90 90 238 238 238 253 253 253 253 253 253
39659-253 253 253 253 253 253 253 253 253 253 253 253
39660-253 253 253 253 253 253 231 231 231 250 250 250
39661-253 253 253 253 253 253 253 253 253 253 253 253
39662-253 253 253 253 253 253 253 253 253 253 253 253
39663-253 253 253 253 253 253 253 253 253 253 253 253
39664-253 253 253 253 253 253 253 253 253 246 230 190
39665-238 204 91 238 204 91 181 142 44 37 26 9
39666- 2 2 6 2 2 6 2 2 6 2 2 6
39667- 2 2 6 2 2 6 38 38 38 46 46 46
39668- 26 26 26 106 106 106 54 54 54 18 18 18
39669- 6 6 6 0 0 0 0 0 0 0 0 0
39670- 0 0 0 0 0 0 0 0 0 0 0 0
39671- 0 0 0 0 0 0 0 0 0 0 0 0
39672- 0 0 0 0 0 0 0 0 0 0 0 0
39673- 0 0 0 0 0 0 0 0 0 0 0 0
39674- 0 0 0 6 6 6 14 14 14 22 22 22
39675- 30 30 30 38 38 38 50 50 50 70 70 70
39676-106 106 106 190 142 34 226 170 11 242 186 14
39677-246 190 14 246 190 14 246 190 14 154 114 10
39678- 6 6 6 74 74 74 226 226 226 253 253 253
39679-253 253 253 253 253 253 253 253 253 253 253 253
39680-253 253 253 253 253 253 231 231 231 250 250 250
39681-253 253 253 253 253 253 253 253 253 253 253 253
39682-253 253 253 253 253 253 253 253 253 253 253 253
39683-253 253 253 253 253 253 253 253 253 253 253 253
39684-253 253 253 253 253 253 253 253 253 228 184 62
39685-241 196 14 241 208 19 232 195 16 38 30 10
39686- 2 2 6 2 2 6 2 2 6 2 2 6
39687- 2 2 6 6 6 6 30 30 30 26 26 26
39688-203 166 17 154 142 90 66 66 66 26 26 26
39689- 6 6 6 0 0 0 0 0 0 0 0 0
39690- 0 0 0 0 0 0 0 0 0 0 0 0
39691- 0 0 0 0 0 0 0 0 0 0 0 0
39692- 0 0 0 0 0 0 0 0 0 0 0 0
39693- 0 0 0 0 0 0 0 0 0 0 0 0
39694- 6 6 6 18 18 18 38 38 38 58 58 58
39695- 78 78 78 86 86 86 101 101 101 123 123 123
39696-175 146 61 210 150 10 234 174 13 246 186 14
39697-246 190 14 246 190 14 246 190 14 238 190 10
39698-102 78 10 2 2 6 46 46 46 198 198 198
39699-253 253 253 253 253 253 253 253 253 253 253 253
39700-253 253 253 253 253 253 234 234 234 242 242 242
39701-253 253 253 253 253 253 253 253 253 253 253 253
39702-253 253 253 253 253 253 253 253 253 253 253 253
39703-253 253 253 253 253 253 253 253 253 253 253 253
39704-253 253 253 253 253 253 253 253 253 224 178 62
39705-242 186 14 241 196 14 210 166 10 22 18 6
39706- 2 2 6 2 2 6 2 2 6 2 2 6
39707- 2 2 6 2 2 6 6 6 6 121 92 8
39708-238 202 15 232 195 16 82 82 82 34 34 34
39709- 10 10 10 0 0 0 0 0 0 0 0 0
39710- 0 0 0 0 0 0 0 0 0 0 0 0
39711- 0 0 0 0 0 0 0 0 0 0 0 0
39712- 0 0 0 0 0 0 0 0 0 0 0 0
39713- 0 0 0 0 0 0 0 0 0 0 0 0
39714- 14 14 14 38 38 38 70 70 70 154 122 46
39715-190 142 34 200 144 11 197 138 11 197 138 11
39716-213 154 11 226 170 11 242 186 14 246 190 14
39717-246 190 14 246 190 14 246 190 14 246 190 14
39718-225 175 15 46 32 6 2 2 6 22 22 22
39719-158 158 158 250 250 250 253 253 253 253 253 253
39720-253 253 253 253 253 253 253 253 253 253 253 253
39721-253 253 253 253 253 253 253 253 253 253 253 253
39722-253 253 253 253 253 253 253 253 253 253 253 253
39723-253 253 253 253 253 253 253 253 253 253 253 253
39724-253 253 253 250 250 250 242 242 242 224 178 62
39725-239 182 13 236 186 11 213 154 11 46 32 6
39726- 2 2 6 2 2 6 2 2 6 2 2 6
39727- 2 2 6 2 2 6 61 42 6 225 175 15
39728-238 190 10 236 186 11 112 100 78 42 42 42
39729- 14 14 14 0 0 0 0 0 0 0 0 0
39730- 0 0 0 0 0 0 0 0 0 0 0 0
39731- 0 0 0 0 0 0 0 0 0 0 0 0
39732- 0 0 0 0 0 0 0 0 0 0 0 0
39733- 0 0 0 0 0 0 0 0 0 6 6 6
39734- 22 22 22 54 54 54 154 122 46 213 154 11
39735-226 170 11 230 174 11 226 170 11 226 170 11
39736-236 178 12 242 186 14 246 190 14 246 190 14
39737-246 190 14 246 190 14 246 190 14 246 190 14
39738-241 196 14 184 144 12 10 10 10 2 2 6
39739- 6 6 6 116 116 116 242 242 242 253 253 253
39740-253 253 253 253 253 253 253 253 253 253 253 253
39741-253 253 253 253 253 253 253 253 253 253 253 253
39742-253 253 253 253 253 253 253 253 253 253 253 253
39743-253 253 253 253 253 253 253 253 253 253 253 253
39744-253 253 253 231 231 231 198 198 198 214 170 54
39745-236 178 12 236 178 12 210 150 10 137 92 6
39746- 18 14 6 2 2 6 2 2 6 2 2 6
39747- 6 6 6 70 47 6 200 144 11 236 178 12
39748-239 182 13 239 182 13 124 112 88 58 58 58
39749- 22 22 22 6 6 6 0 0 0 0 0 0
39750- 0 0 0 0 0 0 0 0 0 0 0 0
39751- 0 0 0 0 0 0 0 0 0 0 0 0
39752- 0 0 0 0 0 0 0 0 0 0 0 0
39753- 0 0 0 0 0 0 0 0 0 10 10 10
39754- 30 30 30 70 70 70 180 133 36 226 170 11
39755-239 182 13 242 186 14 242 186 14 246 186 14
39756-246 190 14 246 190 14 246 190 14 246 190 14
39757-246 190 14 246 190 14 246 190 14 246 190 14
39758-246 190 14 232 195 16 98 70 6 2 2 6
39759- 2 2 6 2 2 6 66 66 66 221 221 221
39760-253 253 253 253 253 253 253 253 253 253 253 253
39761-253 253 253 253 253 253 253 253 253 253 253 253
39762-253 253 253 253 253 253 253 253 253 253 253 253
39763-253 253 253 253 253 253 253 253 253 253 253 253
39764-253 253 253 206 206 206 198 198 198 214 166 58
39765-230 174 11 230 174 11 216 158 10 192 133 9
39766-163 110 8 116 81 8 102 78 10 116 81 8
39767-167 114 7 197 138 11 226 170 11 239 182 13
39768-242 186 14 242 186 14 162 146 94 78 78 78
39769- 34 34 34 14 14 14 6 6 6 0 0 0
39770- 0 0 0 0 0 0 0 0 0 0 0 0
39771- 0 0 0 0 0 0 0 0 0 0 0 0
39772- 0 0 0 0 0 0 0 0 0 0 0 0
39773- 0 0 0 0 0 0 0 0 0 6 6 6
39774- 30 30 30 78 78 78 190 142 34 226 170 11
39775-239 182 13 246 190 14 246 190 14 246 190 14
39776-246 190 14 246 190 14 246 190 14 246 190 14
39777-246 190 14 246 190 14 246 190 14 246 190 14
39778-246 190 14 241 196 14 203 166 17 22 18 6
39779- 2 2 6 2 2 6 2 2 6 38 38 38
39780-218 218 218 253 253 253 253 253 253 253 253 253
39781-253 253 253 253 253 253 253 253 253 253 253 253
39782-253 253 253 253 253 253 253 253 253 253 253 253
39783-253 253 253 253 253 253 253 253 253 253 253 253
39784-250 250 250 206 206 206 198 198 198 202 162 69
39785-226 170 11 236 178 12 224 166 10 210 150 10
39786-200 144 11 197 138 11 192 133 9 197 138 11
39787-210 150 10 226 170 11 242 186 14 246 190 14
39788-246 190 14 246 186 14 225 175 15 124 112 88
39789- 62 62 62 30 30 30 14 14 14 6 6 6
39790- 0 0 0 0 0 0 0 0 0 0 0 0
39791- 0 0 0 0 0 0 0 0 0 0 0 0
39792- 0 0 0 0 0 0 0 0 0 0 0 0
39793- 0 0 0 0 0 0 0 0 0 10 10 10
39794- 30 30 30 78 78 78 174 135 50 224 166 10
39795-239 182 13 246 190 14 246 190 14 246 190 14
39796-246 190 14 246 190 14 246 190 14 246 190 14
39797-246 190 14 246 190 14 246 190 14 246 190 14
39798-246 190 14 246 190 14 241 196 14 139 102 15
39799- 2 2 6 2 2 6 2 2 6 2 2 6
39800- 78 78 78 250 250 250 253 253 253 253 253 253
39801-253 253 253 253 253 253 253 253 253 253 253 253
39802-253 253 253 253 253 253 253 253 253 253 253 253
39803-253 253 253 253 253 253 253 253 253 253 253 253
39804-250 250 250 214 214 214 198 198 198 190 150 46
39805-219 162 10 236 178 12 234 174 13 224 166 10
39806-216 158 10 213 154 11 213 154 11 216 158 10
39807-226 170 11 239 182 13 246 190 14 246 190 14
39808-246 190 14 246 190 14 242 186 14 206 162 42
39809-101 101 101 58 58 58 30 30 30 14 14 14
39810- 6 6 6 0 0 0 0 0 0 0 0 0
39811- 0 0 0 0 0 0 0 0 0 0 0 0
39812- 0 0 0 0 0 0 0 0 0 0 0 0
39813- 0 0 0 0 0 0 0 0 0 10 10 10
39814- 30 30 30 74 74 74 174 135 50 216 158 10
39815-236 178 12 246 190 14 246 190 14 246 190 14
39816-246 190 14 246 190 14 246 190 14 246 190 14
39817-246 190 14 246 190 14 246 190 14 246 190 14
39818-246 190 14 246 190 14 241 196 14 226 184 13
39819- 61 42 6 2 2 6 2 2 6 2 2 6
39820- 22 22 22 238 238 238 253 253 253 253 253 253
39821-253 253 253 253 253 253 253 253 253 253 253 253
39822-253 253 253 253 253 253 253 253 253 253 253 253
39823-253 253 253 253 253 253 253 253 253 253 253 253
39824-253 253 253 226 226 226 187 187 187 180 133 36
39825-216 158 10 236 178 12 239 182 13 236 178 12
39826-230 174 11 226 170 11 226 170 11 230 174 11
39827-236 178 12 242 186 14 246 190 14 246 190 14
39828-246 190 14 246 190 14 246 186 14 239 182 13
39829-206 162 42 106 106 106 66 66 66 34 34 34
39830- 14 14 14 6 6 6 0 0 0 0 0 0
39831- 0 0 0 0 0 0 0 0 0 0 0 0
39832- 0 0 0 0 0 0 0 0 0 0 0 0
39833- 0 0 0 0 0 0 0 0 0 6 6 6
39834- 26 26 26 70 70 70 163 133 67 213 154 11
39835-236 178 12 246 190 14 246 190 14 246 190 14
39836-246 190 14 246 190 14 246 190 14 246 190 14
39837-246 190 14 246 190 14 246 190 14 246 190 14
39838-246 190 14 246 190 14 246 190 14 241 196 14
39839-190 146 13 18 14 6 2 2 6 2 2 6
39840- 46 46 46 246 246 246 253 253 253 253 253 253
39841-253 253 253 253 253 253 253 253 253 253 253 253
39842-253 253 253 253 253 253 253 253 253 253 253 253
39843-253 253 253 253 253 253 253 253 253 253 253 253
39844-253 253 253 221 221 221 86 86 86 156 107 11
39845-216 158 10 236 178 12 242 186 14 246 186 14
39846-242 186 14 239 182 13 239 182 13 242 186 14
39847-242 186 14 246 186 14 246 190 14 246 190 14
39848-246 190 14 246 190 14 246 190 14 246 190 14
39849-242 186 14 225 175 15 142 122 72 66 66 66
39850- 30 30 30 10 10 10 0 0 0 0 0 0
39851- 0 0 0 0 0 0 0 0 0 0 0 0
39852- 0 0 0 0 0 0 0 0 0 0 0 0
39853- 0 0 0 0 0 0 0 0 0 6 6 6
39854- 26 26 26 70 70 70 163 133 67 210 150 10
39855-236 178 12 246 190 14 246 190 14 246 190 14
39856-246 190 14 246 190 14 246 190 14 246 190 14
39857-246 190 14 246 190 14 246 190 14 246 190 14
39858-246 190 14 246 190 14 246 190 14 246 190 14
39859-232 195 16 121 92 8 34 34 34 106 106 106
39860-221 221 221 253 253 253 253 253 253 253 253 253
39861-253 253 253 253 253 253 253 253 253 253 253 253
39862-253 253 253 253 253 253 253 253 253 253 253 253
39863-253 253 253 253 253 253 253 253 253 253 253 253
39864-242 242 242 82 82 82 18 14 6 163 110 8
39865-216 158 10 236 178 12 242 186 14 246 190 14
39866-246 190 14 246 190 14 246 190 14 246 190 14
39867-246 190 14 246 190 14 246 190 14 246 190 14
39868-246 190 14 246 190 14 246 190 14 246 190 14
39869-246 190 14 246 190 14 242 186 14 163 133 67
39870- 46 46 46 18 18 18 6 6 6 0 0 0
39871- 0 0 0 0 0 0 0 0 0 0 0 0
39872- 0 0 0 0 0 0 0 0 0 0 0 0
39873- 0 0 0 0 0 0 0 0 0 10 10 10
39874- 30 30 30 78 78 78 163 133 67 210 150 10
39875-236 178 12 246 186 14 246 190 14 246 190 14
39876-246 190 14 246 190 14 246 190 14 246 190 14
39877-246 190 14 246 190 14 246 190 14 246 190 14
39878-246 190 14 246 190 14 246 190 14 246 190 14
39879-241 196 14 215 174 15 190 178 144 253 253 253
39880-253 253 253 253 253 253 253 253 253 253 253 253
39881-253 253 253 253 253 253 253 253 253 253 253 253
39882-253 253 253 253 253 253 253 253 253 253 253 253
39883-253 253 253 253 253 253 253 253 253 218 218 218
39884- 58 58 58 2 2 6 22 18 6 167 114 7
39885-216 158 10 236 178 12 246 186 14 246 190 14
39886-246 190 14 246 190 14 246 190 14 246 190 14
39887-246 190 14 246 190 14 246 190 14 246 190 14
39888-246 190 14 246 190 14 246 190 14 246 190 14
39889-246 190 14 246 186 14 242 186 14 190 150 46
39890- 54 54 54 22 22 22 6 6 6 0 0 0
39891- 0 0 0 0 0 0 0 0 0 0 0 0
39892- 0 0 0 0 0 0 0 0 0 0 0 0
39893- 0 0 0 0 0 0 0 0 0 14 14 14
39894- 38 38 38 86 86 86 180 133 36 213 154 11
39895-236 178 12 246 186 14 246 190 14 246 190 14
39896-246 190 14 246 190 14 246 190 14 246 190 14
39897-246 190 14 246 190 14 246 190 14 246 190 14
39898-246 190 14 246 190 14 246 190 14 246 190 14
39899-246 190 14 232 195 16 190 146 13 214 214 214
39900-253 253 253 253 253 253 253 253 253 253 253 253
39901-253 253 253 253 253 253 253 253 253 253 253 253
39902-253 253 253 253 253 253 253 253 253 253 253 253
39903-253 253 253 250 250 250 170 170 170 26 26 26
39904- 2 2 6 2 2 6 37 26 9 163 110 8
39905-219 162 10 239 182 13 246 186 14 246 190 14
39906-246 190 14 246 190 14 246 190 14 246 190 14
39907-246 190 14 246 190 14 246 190 14 246 190 14
39908-246 190 14 246 190 14 246 190 14 246 190 14
39909-246 186 14 236 178 12 224 166 10 142 122 72
39910- 46 46 46 18 18 18 6 6 6 0 0 0
39911- 0 0 0 0 0 0 0 0 0 0 0 0
39912- 0 0 0 0 0 0 0 0 0 0 0 0
39913- 0 0 0 0 0 0 6 6 6 18 18 18
39914- 50 50 50 109 106 95 192 133 9 224 166 10
39915-242 186 14 246 190 14 246 190 14 246 190 14
39916-246 190 14 246 190 14 246 190 14 246 190 14
39917-246 190 14 246 190 14 246 190 14 246 190 14
39918-246 190 14 246 190 14 246 190 14 246 190 14
39919-242 186 14 226 184 13 210 162 10 142 110 46
39920-226 226 226 253 253 253 253 253 253 253 253 253
39921-253 253 253 253 253 253 253 253 253 253 253 253
39922-253 253 253 253 253 253 253 253 253 253 253 253
39923-198 198 198 66 66 66 2 2 6 2 2 6
39924- 2 2 6 2 2 6 50 34 6 156 107 11
39925-219 162 10 239 182 13 246 186 14 246 190 14
39926-246 190 14 246 190 14 246 190 14 246 190 14
39927-246 190 14 246 190 14 246 190 14 246 190 14
39928-246 190 14 246 190 14 246 190 14 242 186 14
39929-234 174 13 213 154 11 154 122 46 66 66 66
39930- 30 30 30 10 10 10 0 0 0 0 0 0
39931- 0 0 0 0 0 0 0 0 0 0 0 0
39932- 0 0 0 0 0 0 0 0 0 0 0 0
39933- 0 0 0 0 0 0 6 6 6 22 22 22
39934- 58 58 58 154 121 60 206 145 10 234 174 13
39935-242 186 14 246 186 14 246 190 14 246 190 14
39936-246 190 14 246 190 14 246 190 14 246 190 14
39937-246 190 14 246 190 14 246 190 14 246 190 14
39938-246 190 14 246 190 14 246 190 14 246 190 14
39939-246 186 14 236 178 12 210 162 10 163 110 8
39940- 61 42 6 138 138 138 218 218 218 250 250 250
39941-253 253 253 253 253 253 253 253 253 250 250 250
39942-242 242 242 210 210 210 144 144 144 66 66 66
39943- 6 6 6 2 2 6 2 2 6 2 2 6
39944- 2 2 6 2 2 6 61 42 6 163 110 8
39945-216 158 10 236 178 12 246 190 14 246 190 14
39946-246 190 14 246 190 14 246 190 14 246 190 14
39947-246 190 14 246 190 14 246 190 14 246 190 14
39948-246 190 14 239 182 13 230 174 11 216 158 10
39949-190 142 34 124 112 88 70 70 70 38 38 38
39950- 18 18 18 6 6 6 0 0 0 0 0 0
39951- 0 0 0 0 0 0 0 0 0 0 0 0
39952- 0 0 0 0 0 0 0 0 0 0 0 0
39953- 0 0 0 0 0 0 6 6 6 22 22 22
39954- 62 62 62 168 124 44 206 145 10 224 166 10
39955-236 178 12 239 182 13 242 186 14 242 186 14
39956-246 186 14 246 190 14 246 190 14 246 190 14
39957-246 190 14 246 190 14 246 190 14 246 190 14
39958-246 190 14 246 190 14 246 190 14 246 190 14
39959-246 190 14 236 178 12 216 158 10 175 118 6
39960- 80 54 7 2 2 6 6 6 6 30 30 30
39961- 54 54 54 62 62 62 50 50 50 38 38 38
39962- 14 14 14 2 2 6 2 2 6 2 2 6
39963- 2 2 6 2 2 6 2 2 6 2 2 6
39964- 2 2 6 6 6 6 80 54 7 167 114 7
39965-213 154 11 236 178 12 246 190 14 246 190 14
39966-246 190 14 246 190 14 246 190 14 246 190 14
39967-246 190 14 242 186 14 239 182 13 239 182 13
39968-230 174 11 210 150 10 174 135 50 124 112 88
39969- 82 82 82 54 54 54 34 34 34 18 18 18
39970- 6 6 6 0 0 0 0 0 0 0 0 0
39971- 0 0 0 0 0 0 0 0 0 0 0 0
39972- 0 0 0 0 0 0 0 0 0 0 0 0
39973- 0 0 0 0 0 0 6 6 6 18 18 18
39974- 50 50 50 158 118 36 192 133 9 200 144 11
39975-216 158 10 219 162 10 224 166 10 226 170 11
39976-230 174 11 236 178 12 239 182 13 239 182 13
39977-242 186 14 246 186 14 246 190 14 246 190 14
39978-246 190 14 246 190 14 246 190 14 246 190 14
39979-246 186 14 230 174 11 210 150 10 163 110 8
39980-104 69 6 10 10 10 2 2 6 2 2 6
39981- 2 2 6 2 2 6 2 2 6 2 2 6
39982- 2 2 6 2 2 6 2 2 6 2 2 6
39983- 2 2 6 2 2 6 2 2 6 2 2 6
39984- 2 2 6 6 6 6 91 60 6 167 114 7
39985-206 145 10 230 174 11 242 186 14 246 190 14
39986-246 190 14 246 190 14 246 186 14 242 186 14
39987-239 182 13 230 174 11 224 166 10 213 154 11
39988-180 133 36 124 112 88 86 86 86 58 58 58
39989- 38 38 38 22 22 22 10 10 10 6 6 6
39990- 0 0 0 0 0 0 0 0 0 0 0 0
39991- 0 0 0 0 0 0 0 0 0 0 0 0
39992- 0 0 0 0 0 0 0 0 0 0 0 0
39993- 0 0 0 0 0 0 0 0 0 14 14 14
39994- 34 34 34 70 70 70 138 110 50 158 118 36
39995-167 114 7 180 123 7 192 133 9 197 138 11
39996-200 144 11 206 145 10 213 154 11 219 162 10
39997-224 166 10 230 174 11 239 182 13 242 186 14
39998-246 186 14 246 186 14 246 186 14 246 186 14
39999-239 182 13 216 158 10 185 133 11 152 99 6
40000-104 69 6 18 14 6 2 2 6 2 2 6
40001- 2 2 6 2 2 6 2 2 6 2 2 6
40002- 2 2 6 2 2 6 2 2 6 2 2 6
40003- 2 2 6 2 2 6 2 2 6 2 2 6
40004- 2 2 6 6 6 6 80 54 7 152 99 6
40005-192 133 9 219 162 10 236 178 12 239 182 13
40006-246 186 14 242 186 14 239 182 13 236 178 12
40007-224 166 10 206 145 10 192 133 9 154 121 60
40008- 94 94 94 62 62 62 42 42 42 22 22 22
40009- 14 14 14 6 6 6 0 0 0 0 0 0
40010- 0 0 0 0 0 0 0 0 0 0 0 0
40011- 0 0 0 0 0 0 0 0 0 0 0 0
40012- 0 0 0 0 0 0 0 0 0 0 0 0
40013- 0 0 0 0 0 0 0 0 0 6 6 6
40014- 18 18 18 34 34 34 58 58 58 78 78 78
40015-101 98 89 124 112 88 142 110 46 156 107 11
40016-163 110 8 167 114 7 175 118 6 180 123 7
40017-185 133 11 197 138 11 210 150 10 219 162 10
40018-226 170 11 236 178 12 236 178 12 234 174 13
40019-219 162 10 197 138 11 163 110 8 130 83 6
40020- 91 60 6 10 10 10 2 2 6 2 2 6
40021- 18 18 18 38 38 38 38 38 38 38 38 38
40022- 38 38 38 38 38 38 38 38 38 38 38 38
40023- 38 38 38 38 38 38 26 26 26 2 2 6
40024- 2 2 6 6 6 6 70 47 6 137 92 6
40025-175 118 6 200 144 11 219 162 10 230 174 11
40026-234 174 13 230 174 11 219 162 10 210 150 10
40027-192 133 9 163 110 8 124 112 88 82 82 82
40028- 50 50 50 30 30 30 14 14 14 6 6 6
40029- 0 0 0 0 0 0 0 0 0 0 0 0
40030- 0 0 0 0 0 0 0 0 0 0 0 0
40031- 0 0 0 0 0 0 0 0 0 0 0 0
40032- 0 0 0 0 0 0 0 0 0 0 0 0
40033- 0 0 0 0 0 0 0 0 0 0 0 0
40034- 6 6 6 14 14 14 22 22 22 34 34 34
40035- 42 42 42 58 58 58 74 74 74 86 86 86
40036-101 98 89 122 102 70 130 98 46 121 87 25
40037-137 92 6 152 99 6 163 110 8 180 123 7
40038-185 133 11 197 138 11 206 145 10 200 144 11
40039-180 123 7 156 107 11 130 83 6 104 69 6
40040- 50 34 6 54 54 54 110 110 110 101 98 89
40041- 86 86 86 82 82 82 78 78 78 78 78 78
40042- 78 78 78 78 78 78 78 78 78 78 78 78
40043- 78 78 78 82 82 82 86 86 86 94 94 94
40044-106 106 106 101 101 101 86 66 34 124 80 6
40045-156 107 11 180 123 7 192 133 9 200 144 11
40046-206 145 10 200 144 11 192 133 9 175 118 6
40047-139 102 15 109 106 95 70 70 70 42 42 42
40048- 22 22 22 10 10 10 0 0 0 0 0 0
40049- 0 0 0 0 0 0 0 0 0 0 0 0
40050- 0 0 0 0 0 0 0 0 0 0 0 0
40051- 0 0 0 0 0 0 0 0 0 0 0 0
40052- 0 0 0 0 0 0 0 0 0 0 0 0
40053- 0 0 0 0 0 0 0 0 0 0 0 0
40054- 0 0 0 0 0 0 6 6 6 10 10 10
40055- 14 14 14 22 22 22 30 30 30 38 38 38
40056- 50 50 50 62 62 62 74 74 74 90 90 90
40057-101 98 89 112 100 78 121 87 25 124 80 6
40058-137 92 6 152 99 6 152 99 6 152 99 6
40059-138 86 6 124 80 6 98 70 6 86 66 30
40060-101 98 89 82 82 82 58 58 58 46 46 46
40061- 38 38 38 34 34 34 34 34 34 34 34 34
40062- 34 34 34 34 34 34 34 34 34 34 34 34
40063- 34 34 34 34 34 34 38 38 38 42 42 42
40064- 54 54 54 82 82 82 94 86 76 91 60 6
40065-134 86 6 156 107 11 167 114 7 175 118 6
40066-175 118 6 167 114 7 152 99 6 121 87 25
40067-101 98 89 62 62 62 34 34 34 18 18 18
40068- 6 6 6 0 0 0 0 0 0 0 0 0
40069- 0 0 0 0 0 0 0 0 0 0 0 0
40070- 0 0 0 0 0 0 0 0 0 0 0 0
40071- 0 0 0 0 0 0 0 0 0 0 0 0
40072- 0 0 0 0 0 0 0 0 0 0 0 0
40073- 0 0 0 0 0 0 0 0 0 0 0 0
40074- 0 0 0 0 0 0 0 0 0 0 0 0
40075- 0 0 0 6 6 6 6 6 6 10 10 10
40076- 18 18 18 22 22 22 30 30 30 42 42 42
40077- 50 50 50 66 66 66 86 86 86 101 98 89
40078-106 86 58 98 70 6 104 69 6 104 69 6
40079-104 69 6 91 60 6 82 62 34 90 90 90
40080- 62 62 62 38 38 38 22 22 22 14 14 14
40081- 10 10 10 10 10 10 10 10 10 10 10 10
40082- 10 10 10 10 10 10 6 6 6 10 10 10
40083- 10 10 10 10 10 10 10 10 10 14 14 14
40084- 22 22 22 42 42 42 70 70 70 89 81 66
40085- 80 54 7 104 69 6 124 80 6 137 92 6
40086-134 86 6 116 81 8 100 82 52 86 86 86
40087- 58 58 58 30 30 30 14 14 14 6 6 6
40088- 0 0 0 0 0 0 0 0 0 0 0 0
40089- 0 0 0 0 0 0 0 0 0 0 0 0
40090- 0 0 0 0 0 0 0 0 0 0 0 0
40091- 0 0 0 0 0 0 0 0 0 0 0 0
40092- 0 0 0 0 0 0 0 0 0 0 0 0
40093- 0 0 0 0 0 0 0 0 0 0 0 0
40094- 0 0 0 0 0 0 0 0 0 0 0 0
40095- 0 0 0 0 0 0 0 0 0 0 0 0
40096- 0 0 0 6 6 6 10 10 10 14 14 14
40097- 18 18 18 26 26 26 38 38 38 54 54 54
40098- 70 70 70 86 86 86 94 86 76 89 81 66
40099- 89 81 66 86 86 86 74 74 74 50 50 50
40100- 30 30 30 14 14 14 6 6 6 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- 6 6 6 18 18 18 34 34 34 58 58 58
40105- 82 82 82 89 81 66 89 81 66 89 81 66
40106- 94 86 66 94 86 76 74 74 74 50 50 50
40107- 26 26 26 14 14 14 6 6 6 0 0 0
40108- 0 0 0 0 0 0 0 0 0 0 0 0
40109- 0 0 0 0 0 0 0 0 0 0 0 0
40110- 0 0 0 0 0 0 0 0 0 0 0 0
40111- 0 0 0 0 0 0 0 0 0 0 0 0
40112- 0 0 0 0 0 0 0 0 0 0 0 0
40113- 0 0 0 0 0 0 0 0 0 0 0 0
40114- 0 0 0 0 0 0 0 0 0 0 0 0
40115- 0 0 0 0 0 0 0 0 0 0 0 0
40116- 0 0 0 0 0 0 0 0 0 0 0 0
40117- 6 6 6 6 6 6 14 14 14 18 18 18
40118- 30 30 30 38 38 38 46 46 46 54 54 54
40119- 50 50 50 42 42 42 30 30 30 18 18 18
40120- 10 10 10 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 6 6 6 14 14 14 26 26 26
40125- 38 38 38 50 50 50 58 58 58 58 58 58
40126- 54 54 54 42 42 42 30 30 30 18 18 18
40127- 10 10 10 0 0 0 0 0 0 0 0 0
40128- 0 0 0 0 0 0 0 0 0 0 0 0
40129- 0 0 0 0 0 0 0 0 0 0 0 0
40130- 0 0 0 0 0 0 0 0 0 0 0 0
40131- 0 0 0 0 0 0 0 0 0 0 0 0
40132- 0 0 0 0 0 0 0 0 0 0 0 0
40133- 0 0 0 0 0 0 0 0 0 0 0 0
40134- 0 0 0 0 0 0 0 0 0 0 0 0
40135- 0 0 0 0 0 0 0 0 0 0 0 0
40136- 0 0 0 0 0 0 0 0 0 0 0 0
40137- 0 0 0 0 0 0 0 0 0 6 6 6
40138- 6 6 6 10 10 10 14 14 14 18 18 18
40139- 18 18 18 14 14 14 10 10 10 6 6 6
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- 14 14 14 18 18 18 22 22 22 22 22 22
40146- 18 18 18 14 14 14 10 10 10 6 6 6
40147- 0 0 0 0 0 0 0 0 0 0 0 0
40148- 0 0 0 0 0 0 0 0 0 0 0 0
40149- 0 0 0 0 0 0 0 0 0 0 0 0
40150- 0 0 0 0 0 0 0 0 0 0 0 0
40151- 0 0 0 0 0 0 0 0 0 0 0 0
40152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40165+4 4 4 4 4 4
40166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40179+4 4 4 4 4 4
40180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40193+4 4 4 4 4 4
40194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40207+4 4 4 4 4 4
40208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40221+4 4 4 4 4 4
40222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40228+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40235+4 4 4 4 4 4
40236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40240+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40241+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40245+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40246+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40247+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40249+4 4 4 4 4 4
40250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40254+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40255+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40256+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40259+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40260+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40261+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40262+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40263+4 4 4 4 4 4
40264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40268+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40269+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40270+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40273+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40274+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40275+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40276+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40277+4 4 4 4 4 4
40278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40281+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40282+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40283+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40284+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40286+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40287+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40288+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40289+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40290+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40291+4 4 4 4 4 4
40292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40295+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40296+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40297+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40298+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40299+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40300+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40301+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40302+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40303+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40304+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40305+4 4 4 4 4 4
40306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40309+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40310+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40311+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40312+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40313+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40314+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40315+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40316+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40317+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40318+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40319+4 4 4 4 4 4
40320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40322+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40323+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40324+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40325+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40326+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40327+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40328+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40329+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40330+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40331+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40332+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40333+4 4 4 4 4 4
40334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40336+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40337+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40338+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40339+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40340+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40341+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40342+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40343+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40344+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40345+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40346+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40347+4 4 4 4 4 4
40348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40350+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40351+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40352+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40353+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40354+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40355+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40356+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40357+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40358+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40359+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40360+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40361+4 4 4 4 4 4
40362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40364+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40365+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40366+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40367+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40368+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40369+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40370+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40371+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40372+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40373+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40374+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40375+4 4 4 4 4 4
40376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40377+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40378+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40379+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40380+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40381+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40382+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40383+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40384+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40385+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40386+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40387+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40388+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40389+4 4 4 4 4 4
40390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40391+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40392+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40393+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40394+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40395+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40396+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40397+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40398+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40399+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40400+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40401+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40402+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40403+0 0 0 4 4 4
40404+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40405+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40406+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40407+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40408+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40409+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40410+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40411+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40412+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40413+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40414+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40415+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40416+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40417+2 0 0 0 0 0
40418+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40419+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40420+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40421+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40422+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40423+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40424+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40425+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40426+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40427+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40428+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40429+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40430+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40431+37 38 37 0 0 0
40432+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40433+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40434+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40435+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40436+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40437+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40438+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40439+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40440+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40441+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40442+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40443+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40444+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40445+85 115 134 4 0 0
40446+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40447+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40448+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40449+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40450+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40451+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40452+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40453+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40454+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40455+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40456+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40457+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40458+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40459+60 73 81 4 0 0
40460+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40461+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40462+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40463+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40464+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40465+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40466+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40467+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40468+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40469+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40470+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40471+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40472+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40473+16 19 21 4 0 0
40474+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40475+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40476+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40477+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40478+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40479+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40480+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40481+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40482+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40483+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40484+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40485+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40486+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40487+4 0 0 4 3 3
40488+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40489+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40490+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40492+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40493+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40494+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40495+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40496+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40497+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40498+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40499+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40500+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40501+3 2 2 4 4 4
40502+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40503+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40504+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40505+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40506+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40507+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40508+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40509+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40510+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40511+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40512+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40513+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40514+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40515+4 4 4 4 4 4
40516+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40517+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40518+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40519+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40520+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40521+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40522+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40523+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40524+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40525+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40526+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40527+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40528+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40529+4 4 4 4 4 4
40530+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40531+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40532+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40533+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40534+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40535+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40536+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40537+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40538+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40539+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40540+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40541+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40542+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40543+5 5 5 5 5 5
40544+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40545+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40546+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40547+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40548+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40549+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40550+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40551+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40552+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40553+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40554+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40555+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40556+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40557+5 5 5 4 4 4
40558+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40559+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40560+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40561+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40562+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40563+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40564+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40565+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40566+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40567+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40568+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40569+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40571+4 4 4 4 4 4
40572+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40573+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40574+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40575+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40576+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40577+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40578+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40579+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40580+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40581+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40582+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40583+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
40584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40585+4 4 4 4 4 4
40586+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40587+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40588+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40589+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40590+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40591+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40592+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40593+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40594+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40595+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40596+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
40597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40599+4 4 4 4 4 4
40600+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40601+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40602+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40603+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40604+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40605+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40606+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40607+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40608+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40609+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40610+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
40611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40613+4 4 4 4 4 4
40614+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40615+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40616+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40617+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40618+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40619+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40620+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40621+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40622+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40623+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40624+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40627+4 4 4 4 4 4
40628+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
40629+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40630+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40631+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40632+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40633+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40634+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40635+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40636+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40637+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40638+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
40639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40641+4 4 4 4 4 4
40642+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40643+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40644+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40645+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40646+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40647+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40648+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40649+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40650+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40651+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40652+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
40653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40655+4 4 4 4 4 4
40656+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40657+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40658+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40659+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40660+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40661+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40662+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40663+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40664+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40665+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40666+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40669+4 4 4 4 4 4
40670+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40671+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40672+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40673+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40674+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40675+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
40676+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
40677+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
40678+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
40679+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
40680+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40683+4 4 4 4 4 4
40684+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
40685+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
40686+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40687+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40688+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40689+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
40690+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
40691+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
40692+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
40693+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
40694+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40697+4 4 4 4 4 4
40698+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
40699+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
40700+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40701+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40702+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40703+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
40704+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
40705+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
40706+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40707+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40708+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40711+4 4 4 4 4 4
40712+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40713+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
40714+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40715+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
40716+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
40717+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
40718+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
40719+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
40720+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40721+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40722+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40725+4 4 4 4 4 4
40726+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40727+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
40728+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40729+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
40730+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40731+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
40732+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
40733+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
40734+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40735+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40736+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40739+4 4 4 4 4 4
40740+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
40741+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
40742+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40743+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
40744+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
40745+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
40746+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
40747+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
40748+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40749+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40750+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40753+4 4 4 4 4 4
40754+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
40755+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
40756+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40757+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
40758+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
40759+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
40760+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
40761+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
40762+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40763+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40764+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40767+4 4 4 4 4 4
40768+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40769+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
40770+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40771+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
40772+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
40773+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
40774+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
40775+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
40776+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40777+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40778+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40781+4 4 4 4 4 4
40782+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
40783+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
40784+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40785+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
40786+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
40787+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
40788+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
40789+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
40790+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
40791+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40792+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40795+4 4 4 4 4 4
40796+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40797+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
40798+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
40799+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
40800+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
40801+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
40802+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
40803+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
40804+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40805+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40806+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40809+4 4 4 4 4 4
40810+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40811+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
40812+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40813+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
40814+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
40815+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
40816+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
40817+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
40818+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40819+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40820+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40823+4 4 4 4 4 4
40824+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40825+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
40826+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
40827+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
40828+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
40829+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
40830+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40831+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
40832+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40833+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40834+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40837+4 4 4 4 4 4
40838+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40839+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
40840+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
40841+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40842+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
40843+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
40844+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40845+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
40846+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40847+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40848+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40851+4 4 4 4 4 4
40852+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40853+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
40854+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
40855+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
40856+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
40857+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
40858+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
40859+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
40860+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
40861+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40862+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
40865+4 4 4 4 4 4
40866+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40867+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
40868+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
40869+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
40870+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
40871+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
40872+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
40873+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
40874+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
40875+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40876+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40879+4 4 4 4 4 4
40880+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
40881+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
40882+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
40883+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
40884+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40885+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
40886+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
40887+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
40888+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
40889+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40890+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40893+4 4 4 4 4 4
40894+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40895+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
40896+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
40897+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
40898+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
40899+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
40900+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
40901+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
40902+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
40903+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40904+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40907+4 4 4 4 4 4
40908+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
40909+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
40910+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
40911+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
40912+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
40913+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
40914+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
40915+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
40916+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
40917+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
40918+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40921+4 4 4 4 4 4
40922+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
40923+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40924+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
40925+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
40926+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
40927+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
40928+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
40929+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
40930+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
40931+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
40932+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40935+4 4 4 4 4 4
40936+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
40937+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40938+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
40939+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
40940+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
40941+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
40942+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40943+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
40944+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
40945+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
40946+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40949+4 4 4 4 4 4
40950+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
40951+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
40952+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
40953+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
40954+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
40955+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
40956+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
40957+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
40958+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
40959+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
40960+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40963+4 4 4 4 4 4
40964+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
40965+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
40966+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40967+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
40968+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
40969+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
40970+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
40971+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
40972+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
40973+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
40974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40977+4 4 4 4 4 4
40978+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40979+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
40980+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
40981+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
40982+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
40983+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
40984+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
40985+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
40986+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
40987+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40991+4 4 4 4 4 4
40992+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
40993+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
40994+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
40995+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
40996+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
40997+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
40998+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
40999+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41000+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41001+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41005+4 4 4 4 4 4
41006+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41007+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41008+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41009+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41010+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41011+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41012+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41013+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41014+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41015+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41019+4 4 4 4 4 4
41020+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41021+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41022+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41023+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41024+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41025+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41026+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41027+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41028+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41033+4 4 4 4 4 4
41034+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41035+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41036+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41037+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41038+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41039+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41040+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41041+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41042+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41047+4 4 4 4 4 4
41048+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41049+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41050+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41051+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41052+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41053+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41054+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41055+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41056+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41061+4 4 4 4 4 4
41062+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41063+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41064+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41065+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41066+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41067+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41068+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41069+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41075+4 4 4 4 4 4
41076+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41077+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41078+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41079+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41080+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41081+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41082+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41083+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41089+4 4 4 4 4 4
41090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41091+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41092+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41093+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41094+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41095+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41096+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41097+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41103+4 4 4 4 4 4
41104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41105+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41106+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41107+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41108+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41109+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41110+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41111+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41117+4 4 4 4 4 4
41118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41119+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41120+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41121+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41122+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41123+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41124+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41125+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41131+4 4 4 4 4 4
41132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41134+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41135+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41136+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41137+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41138+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41139+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41145+4 4 4 4 4 4
41146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41149+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41150+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41151+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41152+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41159+4 4 4 4 4 4
41160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41163+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41164+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41165+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41166+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41173+4 4 4 4 4 4
41174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41177+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41178+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41179+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41180+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41187+4 4 4 4 4 4
41188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41191+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41192+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41193+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41194+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41198+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41201+4 4 4 4 4 4
41202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41206+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41207+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41208+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41212+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41215+4 4 4 4 4 4
41216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41220+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41221+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41222+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41226+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41229+4 4 4 4 4 4
41230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41234+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41235+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41236+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41240+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41243+4 4 4 4 4 4
41244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41248+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41249+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41254+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41257+4 4 4 4 4 4
41258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41262+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41263+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41268+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41271+4 4 4 4 4 4
41272diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41273index a159b63..4ab532d 100644
41274--- a/drivers/video/udlfb.c
41275+++ b/drivers/video/udlfb.c
41276@@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41277 dlfb_urb_completion(urb);
41278
41279 error:
41280- atomic_add(bytes_sent, &dev->bytes_sent);
41281- atomic_add(bytes_identical, &dev->bytes_identical);
41282- atomic_add(width*height*2, &dev->bytes_rendered);
41283+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41284+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41285+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41286 end_cycles = get_cycles();
41287- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41288+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41289 >> 10)), /* Kcycles */
41290 &dev->cpu_kcycles_used);
41291
41292@@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41293 dlfb_urb_completion(urb);
41294
41295 error:
41296- atomic_add(bytes_sent, &dev->bytes_sent);
41297- atomic_add(bytes_identical, &dev->bytes_identical);
41298- atomic_add(bytes_rendered, &dev->bytes_rendered);
41299+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41300+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41301+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41302 end_cycles = get_cycles();
41303- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41304+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41305 >> 10)), /* Kcycles */
41306 &dev->cpu_kcycles_used);
41307 }
41308@@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41309 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41310 struct dlfb_data *dev = fb_info->par;
41311 return snprintf(buf, PAGE_SIZE, "%u\n",
41312- atomic_read(&dev->bytes_rendered));
41313+ atomic_read_unchecked(&dev->bytes_rendered));
41314 }
41315
41316 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41317@@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41318 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41319 struct dlfb_data *dev = fb_info->par;
41320 return snprintf(buf, PAGE_SIZE, "%u\n",
41321- atomic_read(&dev->bytes_identical));
41322+ atomic_read_unchecked(&dev->bytes_identical));
41323 }
41324
41325 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41326@@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41327 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41328 struct dlfb_data *dev = fb_info->par;
41329 return snprintf(buf, PAGE_SIZE, "%u\n",
41330- atomic_read(&dev->bytes_sent));
41331+ atomic_read_unchecked(&dev->bytes_sent));
41332 }
41333
41334 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41335@@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41336 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41337 struct dlfb_data *dev = fb_info->par;
41338 return snprintf(buf, PAGE_SIZE, "%u\n",
41339- atomic_read(&dev->cpu_kcycles_used));
41340+ atomic_read_unchecked(&dev->cpu_kcycles_used));
41341 }
41342
41343 static ssize_t edid_show(
41344@@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41345 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41346 struct dlfb_data *dev = fb_info->par;
41347
41348- atomic_set(&dev->bytes_rendered, 0);
41349- atomic_set(&dev->bytes_identical, 0);
41350- atomic_set(&dev->bytes_sent, 0);
41351- atomic_set(&dev->cpu_kcycles_used, 0);
41352+ atomic_set_unchecked(&dev->bytes_rendered, 0);
41353+ atomic_set_unchecked(&dev->bytes_identical, 0);
41354+ atomic_set_unchecked(&dev->bytes_sent, 0);
41355+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41356
41357 return count;
41358 }
41359diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41360index b0e2a42..e2df3ad 100644
41361--- a/drivers/video/uvesafb.c
41362+++ b/drivers/video/uvesafb.c
41363@@ -19,6 +19,7 @@
41364 #include <linux/io.h>
41365 #include <linux/mutex.h>
41366 #include <linux/slab.h>
41367+#include <linux/moduleloader.h>
41368 #include <video/edid.h>
41369 #include <video/uvesafb.h>
41370 #ifdef CONFIG_X86
41371@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41372 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41373 par->pmi_setpal = par->ypan = 0;
41374 } else {
41375+
41376+#ifdef CONFIG_PAX_KERNEXEC
41377+#ifdef CONFIG_MODULES
41378+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41379+#endif
41380+ if (!par->pmi_code) {
41381+ par->pmi_setpal = par->ypan = 0;
41382+ return 0;
41383+ }
41384+#endif
41385+
41386 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41387 + task->t.regs.edi);
41388+
41389+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41390+ pax_open_kernel();
41391+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41392+ pax_close_kernel();
41393+
41394+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41395+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41396+#else
41397 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41398 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41399+#endif
41400+
41401 printk(KERN_INFO "uvesafb: protected mode interface info at "
41402 "%04x:%04x\n",
41403 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41404@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41405 par->ypan = ypan;
41406
41407 if (par->pmi_setpal || par->ypan) {
41408+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41409 if (__supported_pte_mask & _PAGE_NX) {
41410 par->pmi_setpal = par->ypan = 0;
41411 printk(KERN_WARNING "uvesafb: NX protection is actively."
41412 "We have better not to use the PMI.\n");
41413- } else {
41414+ } else
41415+#endif
41416 uvesafb_vbe_getpmi(task, par);
41417- }
41418 }
41419 #else
41420 /* The protected mode interface is not available on non-x86. */
41421@@ -1836,6 +1860,11 @@ out:
41422 if (par->vbe_modes)
41423 kfree(par->vbe_modes);
41424
41425+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41426+ if (par->pmi_code)
41427+ module_free_exec(NULL, par->pmi_code);
41428+#endif
41429+
41430 framebuffer_release(info);
41431 return err;
41432 }
41433@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
41434 kfree(par->vbe_state_orig);
41435 if (par->vbe_state_saved)
41436 kfree(par->vbe_state_saved);
41437+
41438+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41439+ if (par->pmi_code)
41440+ module_free_exec(NULL, par->pmi_code);
41441+#endif
41442+
41443 }
41444
41445 framebuffer_release(info);
41446diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41447index 501b340..86bd4cf 100644
41448--- a/drivers/video/vesafb.c
41449+++ b/drivers/video/vesafb.c
41450@@ -9,6 +9,7 @@
41451 */
41452
41453 #include <linux/module.h>
41454+#include <linux/moduleloader.h>
41455 #include <linux/kernel.h>
41456 #include <linux/errno.h>
41457 #include <linux/string.h>
41458@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41459 static int vram_total __initdata; /* Set total amount of memory */
41460 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41461 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41462-static void (*pmi_start)(void) __read_mostly;
41463-static void (*pmi_pal) (void) __read_mostly;
41464+static void (*pmi_start)(void) __read_only;
41465+static void (*pmi_pal) (void) __read_only;
41466 static int depth __read_mostly;
41467 static int vga_compat __read_mostly;
41468 /* --------------------------------------------------------------------- */
41469@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41470 unsigned int size_vmode;
41471 unsigned int size_remap;
41472 unsigned int size_total;
41473+ void *pmi_code = NULL;
41474
41475 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41476 return -ENODEV;
41477@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41478 size_remap = size_total;
41479 vesafb_fix.smem_len = size_remap;
41480
41481-#ifndef __i386__
41482- screen_info.vesapm_seg = 0;
41483-#endif
41484-
41485 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41486 printk(KERN_WARNING
41487 "vesafb: cannot reserve video memory at 0x%lx\n",
41488@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41489 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41490 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41491
41492+#ifdef __i386__
41493+
41494+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41495+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
41496+ if (!pmi_code)
41497+#elif !defined(CONFIG_PAX_KERNEXEC)
41498+ if (0)
41499+#endif
41500+
41501+#endif
41502+ screen_info.vesapm_seg = 0;
41503+
41504 if (screen_info.vesapm_seg) {
41505- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41506- screen_info.vesapm_seg,screen_info.vesapm_off);
41507+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41508+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41509 }
41510
41511 if (screen_info.vesapm_seg < 0xc000)
41512@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41513
41514 if (ypan || pmi_setpal) {
41515 unsigned short *pmi_base;
41516+
41517 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41518- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41519- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41520+
41521+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41522+ pax_open_kernel();
41523+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41524+#else
41525+ pmi_code = pmi_base;
41526+#endif
41527+
41528+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41529+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41530+
41531+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41532+ pmi_start = ktva_ktla(pmi_start);
41533+ pmi_pal = ktva_ktla(pmi_pal);
41534+ pax_close_kernel();
41535+#endif
41536+
41537 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41538 if (pmi_base[3]) {
41539 printk(KERN_INFO "vesafb: pmi: ports = ");
41540@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41541 info->node, info->fix.id);
41542 return 0;
41543 err:
41544+
41545+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41546+ module_free_exec(NULL, pmi_code);
41547+#endif
41548+
41549 if (info->screen_base)
41550 iounmap(info->screen_base);
41551 framebuffer_release(info);
41552diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41553index 88714ae..16c2e11 100644
41554--- a/drivers/video/via/via_clock.h
41555+++ b/drivers/video/via/via_clock.h
41556@@ -56,7 +56,7 @@ struct via_clock {
41557
41558 void (*set_engine_pll_state)(u8 state);
41559 void (*set_engine_pll)(struct via_pll_config config);
41560-};
41561+} __no_const;
41562
41563
41564 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41565diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41566index e56c934..fc22f4b 100644
41567--- a/drivers/xen/xen-pciback/conf_space.h
41568+++ b/drivers/xen/xen-pciback/conf_space.h
41569@@ -44,15 +44,15 @@ struct config_field {
41570 struct {
41571 conf_dword_write write;
41572 conf_dword_read read;
41573- } dw;
41574+ } __no_const dw;
41575 struct {
41576 conf_word_write write;
41577 conf_word_read read;
41578- } w;
41579+ } __no_const w;
41580 struct {
41581 conf_byte_write write;
41582 conf_byte_read read;
41583- } b;
41584+ } __no_const b;
41585 } u;
41586 struct list_head list;
41587 };
41588diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41589index 014c8dd..6f3dfe6 100644
41590--- a/fs/9p/vfs_inode.c
41591+++ b/fs/9p/vfs_inode.c
41592@@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41593 void
41594 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41595 {
41596- char *s = nd_get_link(nd);
41597+ const char *s = nd_get_link(nd);
41598
41599 p9_debug(P9_DEBUG_VFS, " %s %s\n",
41600 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
41601diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41602index e95d1b6..3454244 100644
41603--- a/fs/Kconfig.binfmt
41604+++ b/fs/Kconfig.binfmt
41605@@ -89,7 +89,7 @@ config HAVE_AOUT
41606
41607 config BINFMT_AOUT
41608 tristate "Kernel support for a.out and ECOFF binaries"
41609- depends on HAVE_AOUT
41610+ depends on HAVE_AOUT && BROKEN
41611 ---help---
41612 A.out (Assembler.OUTput) is a set of formats for libraries and
41613 executables used in the earliest versions of UNIX. Linux used
41614diff --git a/fs/aio.c b/fs/aio.c
41615index e7f2fad..15ad8a4 100644
41616--- a/fs/aio.c
41617+++ b/fs/aio.c
41618@@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41619 size += sizeof(struct io_event) * nr_events;
41620 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41621
41622- if (nr_pages < 0)
41623+ if (nr_pages <= 0)
41624 return -EINVAL;
41625
41626 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41627@@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41628 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41629 {
41630 ssize_t ret;
41631+ struct iovec iovstack;
41632
41633 #ifdef CONFIG_COMPAT
41634 if (compat)
41635 ret = compat_rw_copy_check_uvector(type,
41636 (struct compat_iovec __user *)kiocb->ki_buf,
41637- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41638+ kiocb->ki_nbytes, 1, &iovstack,
41639 &kiocb->ki_iovec, 1);
41640 else
41641 #endif
41642 ret = rw_copy_check_uvector(type,
41643 (struct iovec __user *)kiocb->ki_buf,
41644- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41645+ kiocb->ki_nbytes, 1, &iovstack,
41646 &kiocb->ki_iovec, 1);
41647 if (ret < 0)
41648 goto out;
41649@@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41650 if (ret < 0)
41651 goto out;
41652
41653+ if (kiocb->ki_iovec == &iovstack) {
41654+ kiocb->ki_inline_vec = iovstack;
41655+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
41656+ }
41657 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41658 kiocb->ki_cur_seg = 0;
41659 /* ki_nbytes/left now reflect bytes instead of segs */
41660diff --git a/fs/attr.c b/fs/attr.c
41661index d94d1b6..f9bccd6 100644
41662--- a/fs/attr.c
41663+++ b/fs/attr.c
41664@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
41665 unsigned long limit;
41666
41667 limit = rlimit(RLIMIT_FSIZE);
41668+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
41669 if (limit != RLIM_INFINITY && offset > limit)
41670 goto out_sig;
41671 if (offset > inode->i_sb->s_maxbytes)
41672diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
41673index da8876d..9f3e6d8 100644
41674--- a/fs/autofs4/waitq.c
41675+++ b/fs/autofs4/waitq.c
41676@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
41677 {
41678 unsigned long sigpipe, flags;
41679 mm_segment_t fs;
41680- const char *data = (const char *)addr;
41681+ const char __user *data = (const char __force_user *)addr;
41682 ssize_t wr = 0;
41683
41684 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
41685diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
41686index e18da23..affc30e 100644
41687--- a/fs/befs/linuxvfs.c
41688+++ b/fs/befs/linuxvfs.c
41689@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41690 {
41691 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
41692 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
41693- char *link = nd_get_link(nd);
41694+ const char *link = nd_get_link(nd);
41695 if (!IS_ERR(link))
41696 kfree(link);
41697 }
41698diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
41699index d146e18..12d1bd1 100644
41700--- a/fs/binfmt_aout.c
41701+++ b/fs/binfmt_aout.c
41702@@ -16,6 +16,7 @@
41703 #include <linux/string.h>
41704 #include <linux/fs.h>
41705 #include <linux/file.h>
41706+#include <linux/security.h>
41707 #include <linux/stat.h>
41708 #include <linux/fcntl.h>
41709 #include <linux/ptrace.h>
41710@@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
41711 #endif
41712 # define START_STACK(u) ((void __user *)u.start_stack)
41713
41714+ memset(&dump, 0, sizeof(dump));
41715+
41716 fs = get_fs();
41717 set_fs(KERNEL_DS);
41718 has_dumped = 1;
41719@@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
41720
41721 /* If the size of the dump file exceeds the rlimit, then see what would happen
41722 if we wrote the stack, but not the data area. */
41723+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
41724 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
41725 dump.u_dsize = 0;
41726
41727 /* Make sure we have enough room to write the stack and data areas. */
41728+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
41729 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
41730 dump.u_ssize = 0;
41731
41732@@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41733 rlim = rlimit(RLIMIT_DATA);
41734 if (rlim >= RLIM_INFINITY)
41735 rlim = ~0;
41736+
41737+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
41738 if (ex.a_data + ex.a_bss > rlim)
41739 return -ENOMEM;
41740
41741@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41742
41743 install_exec_creds(bprm);
41744
41745+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41746+ current->mm->pax_flags = 0UL;
41747+#endif
41748+
41749+#ifdef CONFIG_PAX_PAGEEXEC
41750+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
41751+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
41752+
41753+#ifdef CONFIG_PAX_EMUTRAMP
41754+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
41755+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
41756+#endif
41757+
41758+#ifdef CONFIG_PAX_MPROTECT
41759+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
41760+ current->mm->pax_flags |= MF_PAX_MPROTECT;
41761+#endif
41762+
41763+ }
41764+#endif
41765+
41766 if (N_MAGIC(ex) == OMAGIC) {
41767 unsigned long text_addr, map_size;
41768 loff_t pos;
41769@@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41770 }
41771
41772 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
41773- PROT_READ | PROT_WRITE | PROT_EXEC,
41774+ PROT_READ | PROT_WRITE,
41775 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
41776 fd_offset + ex.a_text);
41777 if (error != N_DATADDR(ex)) {
41778diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
41779index 16f7354..7cc1e24 100644
41780--- a/fs/binfmt_elf.c
41781+++ b/fs/binfmt_elf.c
41782@@ -32,6 +32,7 @@
41783 #include <linux/elf.h>
41784 #include <linux/utsname.h>
41785 #include <linux/coredump.h>
41786+#include <linux/xattr.h>
41787 #include <asm/uaccess.h>
41788 #include <asm/param.h>
41789 #include <asm/page.h>
41790@@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
41791 #define elf_core_dump NULL
41792 #endif
41793
41794+#ifdef CONFIG_PAX_MPROTECT
41795+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
41796+#endif
41797+
41798 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
41799 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
41800 #else
41801@@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
41802 .load_binary = load_elf_binary,
41803 .load_shlib = load_elf_library,
41804 .core_dump = elf_core_dump,
41805+
41806+#ifdef CONFIG_PAX_MPROTECT
41807+ .handle_mprotect= elf_handle_mprotect,
41808+#endif
41809+
41810 .min_coredump = ELF_EXEC_PAGESIZE,
41811 };
41812
41813@@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
41814
41815 static int set_brk(unsigned long start, unsigned long end)
41816 {
41817+ unsigned long e = end;
41818+
41819 start = ELF_PAGEALIGN(start);
41820 end = ELF_PAGEALIGN(end);
41821 if (end > start) {
41822@@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
41823 if (BAD_ADDR(addr))
41824 return addr;
41825 }
41826- current->mm->start_brk = current->mm->brk = end;
41827+ current->mm->start_brk = current->mm->brk = e;
41828 return 0;
41829 }
41830
41831@@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41832 elf_addr_t __user *u_rand_bytes;
41833 const char *k_platform = ELF_PLATFORM;
41834 const char *k_base_platform = ELF_BASE_PLATFORM;
41835- unsigned char k_rand_bytes[16];
41836+ u32 k_rand_bytes[4];
41837 int items;
41838 elf_addr_t *elf_info;
41839 int ei_index = 0;
41840 const struct cred *cred = current_cred();
41841 struct vm_area_struct *vma;
41842+ unsigned long saved_auxv[AT_VECTOR_SIZE];
41843
41844 /*
41845 * In some cases (e.g. Hyper-Threading), we want to avoid L1
41846@@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41847 * Generate 16 random bytes for userspace PRNG seeding.
41848 */
41849 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
41850- u_rand_bytes = (elf_addr_t __user *)
41851- STACK_ALLOC(p, sizeof(k_rand_bytes));
41852+ srandom32(k_rand_bytes[0] ^ random32());
41853+ srandom32(k_rand_bytes[1] ^ random32());
41854+ srandom32(k_rand_bytes[2] ^ random32());
41855+ srandom32(k_rand_bytes[3] ^ random32());
41856+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
41857+ u_rand_bytes = (elf_addr_t __user *) p;
41858 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
41859 return -EFAULT;
41860
41861@@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41862 return -EFAULT;
41863 current->mm->env_end = p;
41864
41865+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
41866+
41867 /* Put the elf_info on the stack in the right place. */
41868 sp = (elf_addr_t __user *)envp + 1;
41869- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
41870+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
41871 return -EFAULT;
41872 return 0;
41873 }
41874@@ -380,10 +399,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41875 {
41876 struct elf_phdr *elf_phdata;
41877 struct elf_phdr *eppnt;
41878- unsigned long load_addr = 0;
41879+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
41880 int load_addr_set = 0;
41881 unsigned long last_bss = 0, elf_bss = 0;
41882- unsigned long error = ~0UL;
41883+ unsigned long error = -EINVAL;
41884 unsigned long total_size;
41885 int retval, i, size;
41886
41887@@ -429,6 +448,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41888 goto out_close;
41889 }
41890
41891+#ifdef CONFIG_PAX_SEGMEXEC
41892+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
41893+ pax_task_size = SEGMEXEC_TASK_SIZE;
41894+#endif
41895+
41896 eppnt = elf_phdata;
41897 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
41898 if (eppnt->p_type == PT_LOAD) {
41899@@ -472,8 +496,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41900 k = load_addr + eppnt->p_vaddr;
41901 if (BAD_ADDR(k) ||
41902 eppnt->p_filesz > eppnt->p_memsz ||
41903- eppnt->p_memsz > TASK_SIZE ||
41904- TASK_SIZE - eppnt->p_memsz < k) {
41905+ eppnt->p_memsz > pax_task_size ||
41906+ pax_task_size - eppnt->p_memsz < k) {
41907 error = -ENOMEM;
41908 goto out_close;
41909 }
41910@@ -525,6 +549,311 @@ out:
41911 return error;
41912 }
41913
41914+#ifdef CONFIG_PAX_PT_PAX_FLAGS
41915+#ifdef CONFIG_PAX_SOFTMODE
41916+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
41917+{
41918+ unsigned long pax_flags = 0UL;
41919+
41920+#ifdef CONFIG_PAX_PAGEEXEC
41921+ if (elf_phdata->p_flags & PF_PAGEEXEC)
41922+ pax_flags |= MF_PAX_PAGEEXEC;
41923+#endif
41924+
41925+#ifdef CONFIG_PAX_SEGMEXEC
41926+ if (elf_phdata->p_flags & PF_SEGMEXEC)
41927+ pax_flags |= MF_PAX_SEGMEXEC;
41928+#endif
41929+
41930+#ifdef CONFIG_PAX_EMUTRAMP
41931+ if (elf_phdata->p_flags & PF_EMUTRAMP)
41932+ pax_flags |= MF_PAX_EMUTRAMP;
41933+#endif
41934+
41935+#ifdef CONFIG_PAX_MPROTECT
41936+ if (elf_phdata->p_flags & PF_MPROTECT)
41937+ pax_flags |= MF_PAX_MPROTECT;
41938+#endif
41939+
41940+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41941+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
41942+ pax_flags |= MF_PAX_RANDMMAP;
41943+#endif
41944+
41945+ return pax_flags;
41946+}
41947+#endif
41948+
41949+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
41950+{
41951+ unsigned long pax_flags = 0UL;
41952+
41953+#ifdef CONFIG_PAX_PAGEEXEC
41954+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
41955+ pax_flags |= MF_PAX_PAGEEXEC;
41956+#endif
41957+
41958+#ifdef CONFIG_PAX_SEGMEXEC
41959+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
41960+ pax_flags |= MF_PAX_SEGMEXEC;
41961+#endif
41962+
41963+#ifdef CONFIG_PAX_EMUTRAMP
41964+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
41965+ pax_flags |= MF_PAX_EMUTRAMP;
41966+#endif
41967+
41968+#ifdef CONFIG_PAX_MPROTECT
41969+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
41970+ pax_flags |= MF_PAX_MPROTECT;
41971+#endif
41972+
41973+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41974+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
41975+ pax_flags |= MF_PAX_RANDMMAP;
41976+#endif
41977+
41978+ return pax_flags;
41979+}
41980+#endif
41981+
41982+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
41983+#ifdef CONFIG_PAX_SOFTMODE
41984+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
41985+{
41986+ unsigned long pax_flags = 0UL;
41987+
41988+#ifdef CONFIG_PAX_PAGEEXEC
41989+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
41990+ pax_flags |= MF_PAX_PAGEEXEC;
41991+#endif
41992+
41993+#ifdef CONFIG_PAX_SEGMEXEC
41994+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
41995+ pax_flags |= MF_PAX_SEGMEXEC;
41996+#endif
41997+
41998+#ifdef CONFIG_PAX_EMUTRAMP
41999+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42000+ pax_flags |= MF_PAX_EMUTRAMP;
42001+#endif
42002+
42003+#ifdef CONFIG_PAX_MPROTECT
42004+ if (pax_flags_softmode & MF_PAX_MPROTECT)
42005+ pax_flags |= MF_PAX_MPROTECT;
42006+#endif
42007+
42008+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42009+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42010+ pax_flags |= MF_PAX_RANDMMAP;
42011+#endif
42012+
42013+ return pax_flags;
42014+}
42015+#endif
42016+
42017+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42018+{
42019+ unsigned long pax_flags = 0UL;
42020+
42021+#ifdef CONFIG_PAX_PAGEEXEC
42022+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42023+ pax_flags |= MF_PAX_PAGEEXEC;
42024+#endif
42025+
42026+#ifdef CONFIG_PAX_SEGMEXEC
42027+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42028+ pax_flags |= MF_PAX_SEGMEXEC;
42029+#endif
42030+
42031+#ifdef CONFIG_PAX_EMUTRAMP
42032+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42033+ pax_flags |= MF_PAX_EMUTRAMP;
42034+#endif
42035+
42036+#ifdef CONFIG_PAX_MPROTECT
42037+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42038+ pax_flags |= MF_PAX_MPROTECT;
42039+#endif
42040+
42041+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42042+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42043+ pax_flags |= MF_PAX_RANDMMAP;
42044+#endif
42045+
42046+ return pax_flags;
42047+}
42048+#endif
42049+
42050+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42051+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42052+{
42053+ unsigned long pax_flags = 0UL;
42054+
42055+#ifdef CONFIG_PAX_EI_PAX
42056+
42057+#ifdef CONFIG_PAX_PAGEEXEC
42058+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42059+ pax_flags |= MF_PAX_PAGEEXEC;
42060+#endif
42061+
42062+#ifdef CONFIG_PAX_SEGMEXEC
42063+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42064+ pax_flags |= MF_PAX_SEGMEXEC;
42065+#endif
42066+
42067+#ifdef CONFIG_PAX_EMUTRAMP
42068+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42069+ pax_flags |= MF_PAX_EMUTRAMP;
42070+#endif
42071+
42072+#ifdef CONFIG_PAX_MPROTECT
42073+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42074+ pax_flags |= MF_PAX_MPROTECT;
42075+#endif
42076+
42077+#ifdef CONFIG_PAX_ASLR
42078+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42079+ pax_flags |= MF_PAX_RANDMMAP;
42080+#endif
42081+
42082+#else
42083+
42084+#ifdef CONFIG_PAX_PAGEEXEC
42085+ pax_flags |= MF_PAX_PAGEEXEC;
42086+#endif
42087+
42088+#ifdef CONFIG_PAX_SEGMEXEC
42089+ pax_flags |= MF_PAX_SEGMEXEC;
42090+#endif
42091+
42092+#ifdef CONFIG_PAX_MPROTECT
42093+ pax_flags |= MF_PAX_MPROTECT;
42094+#endif
42095+
42096+#ifdef CONFIG_PAX_RANDMMAP
42097+ if (randomize_va_space)
42098+ pax_flags |= MF_PAX_RANDMMAP;
42099+#endif
42100+
42101+#endif
42102+
42103+ return pax_flags;
42104+}
42105+
42106+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42107+{
42108+
42109+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42110+ unsigned long i;
42111+
42112+ for (i = 0UL; i < elf_ex->e_phnum; i++)
42113+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42114+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42115+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42116+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42117+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42118+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42119+ return ~0UL;
42120+
42121+#ifdef CONFIG_PAX_SOFTMODE
42122+ if (pax_softmode)
42123+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42124+ else
42125+#endif
42126+
42127+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42128+ break;
42129+ }
42130+#endif
42131+
42132+ return ~0UL;
42133+}
42134+
42135+static unsigned long pax_parse_xattr_pax(struct file * const file)
42136+{
42137+
42138+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42139+ ssize_t xattr_size, i;
42140+ unsigned char xattr_value[5];
42141+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42142+
42143+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42144+ if (xattr_size <= 0)
42145+ return ~0UL;
42146+
42147+ for (i = 0; i < xattr_size; i++)
42148+ switch (xattr_value[i]) {
42149+ default:
42150+ return ~0UL;
42151+
42152+#define parse_flag(option1, option2, flag) \
42153+ case option1: \
42154+ pax_flags_hardmode |= MF_PAX_##flag; \
42155+ break; \
42156+ case option2: \
42157+ pax_flags_softmode |= MF_PAX_##flag; \
42158+ break;
42159+
42160+ parse_flag('p', 'P', PAGEEXEC);
42161+ parse_flag('e', 'E', EMUTRAMP);
42162+ parse_flag('m', 'M', MPROTECT);
42163+ parse_flag('r', 'R', RANDMMAP);
42164+ parse_flag('s', 'S', SEGMEXEC);
42165+
42166+#undef parse_flag
42167+ }
42168+
42169+ if (pax_flags_hardmode & pax_flags_softmode)
42170+ return ~0UL;
42171+
42172+#ifdef CONFIG_PAX_SOFTMODE
42173+ if (pax_softmode)
42174+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42175+ else
42176+#endif
42177+
42178+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42179+#else
42180+ return ~0UL;
42181+#endif
42182+
42183+}
42184+
42185+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42186+{
42187+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42188+
42189+ pax_flags = pax_parse_ei_pax(elf_ex);
42190+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42191+ xattr_pax_flags = pax_parse_xattr_pax(file);
42192+
42193+ if (pt_pax_flags == ~0UL)
42194+ pt_pax_flags = xattr_pax_flags;
42195+ else if (xattr_pax_flags == ~0UL)
42196+ xattr_pax_flags = pt_pax_flags;
42197+ if (pt_pax_flags != xattr_pax_flags)
42198+ return -EINVAL;
42199+ if (pt_pax_flags != ~0UL)
42200+ pax_flags = pt_pax_flags;
42201+
42202+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42203+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42204+ if ((__supported_pte_mask & _PAGE_NX))
42205+ pax_flags &= ~MF_PAX_SEGMEXEC;
42206+ else
42207+ pax_flags &= ~MF_PAX_PAGEEXEC;
42208+ }
42209+#endif
42210+
42211+ if (0 > pax_check_flags(&pax_flags))
42212+ return -EINVAL;
42213+
42214+ current->mm->pax_flags = pax_flags;
42215+ return 0;
42216+}
42217+#endif
42218+
42219 /*
42220 * These are the functions used to load ELF style executables and shared
42221 * libraries. There is no binary dependent code anywhere else.
42222@@ -541,6 +870,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42223 {
42224 unsigned int random_variable = 0;
42225
42226+#ifdef CONFIG_PAX_RANDUSTACK
42227+ if (randomize_va_space)
42228+ return stack_top - current->mm->delta_stack;
42229+#endif
42230+
42231 if ((current->flags & PF_RANDOMIZE) &&
42232 !(current->personality & ADDR_NO_RANDOMIZE)) {
42233 random_variable = get_random_int() & STACK_RND_MASK;
42234@@ -559,7 +893,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42235 unsigned long load_addr = 0, load_bias = 0;
42236 int load_addr_set = 0;
42237 char * elf_interpreter = NULL;
42238- unsigned long error;
42239+ unsigned long error = 0;
42240 struct elf_phdr *elf_ppnt, *elf_phdata;
42241 unsigned long elf_bss, elf_brk;
42242 int retval, i;
42243@@ -569,11 +903,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42244 unsigned long start_code, end_code, start_data, end_data;
42245 unsigned long reloc_func_desc __maybe_unused = 0;
42246 int executable_stack = EXSTACK_DEFAULT;
42247- unsigned long def_flags = 0;
42248 struct {
42249 struct elfhdr elf_ex;
42250 struct elfhdr interp_elf_ex;
42251 } *loc;
42252+ unsigned long pax_task_size = TASK_SIZE;
42253
42254 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42255 if (!loc) {
42256@@ -709,11 +1043,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42257 goto out_free_dentry;
42258
42259 /* OK, This is the point of no return */
42260- current->mm->def_flags = def_flags;
42261+
42262+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42263+ current->mm->pax_flags = 0UL;
42264+#endif
42265+
42266+#ifdef CONFIG_PAX_DLRESOLVE
42267+ current->mm->call_dl_resolve = 0UL;
42268+#endif
42269+
42270+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42271+ current->mm->call_syscall = 0UL;
42272+#endif
42273+
42274+#ifdef CONFIG_PAX_ASLR
42275+ current->mm->delta_mmap = 0UL;
42276+ current->mm->delta_stack = 0UL;
42277+#endif
42278+
42279+ current->mm->def_flags = 0;
42280+
42281+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42282+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42283+ send_sig(SIGKILL, current, 0);
42284+ goto out_free_dentry;
42285+ }
42286+#endif
42287+
42288+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42289+ pax_set_initial_flags(bprm);
42290+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42291+ if (pax_set_initial_flags_func)
42292+ (pax_set_initial_flags_func)(bprm);
42293+#endif
42294+
42295+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42296+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42297+ current->mm->context.user_cs_limit = PAGE_SIZE;
42298+ current->mm->def_flags |= VM_PAGEEXEC;
42299+ }
42300+#endif
42301+
42302+#ifdef CONFIG_PAX_SEGMEXEC
42303+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42304+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42305+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42306+ pax_task_size = SEGMEXEC_TASK_SIZE;
42307+ current->mm->def_flags |= VM_NOHUGEPAGE;
42308+ }
42309+#endif
42310+
42311+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42312+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42313+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42314+ put_cpu();
42315+ }
42316+#endif
42317
42318 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42319 may depend on the personality. */
42320 SET_PERSONALITY(loc->elf_ex);
42321+
42322+#ifdef CONFIG_PAX_ASLR
42323+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42324+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42325+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42326+ }
42327+#endif
42328+
42329+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42330+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42331+ executable_stack = EXSTACK_DISABLE_X;
42332+ current->personality &= ~READ_IMPLIES_EXEC;
42333+ } else
42334+#endif
42335+
42336 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42337 current->personality |= READ_IMPLIES_EXEC;
42338
42339@@ -804,6 +1208,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42340 #else
42341 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42342 #endif
42343+
42344+#ifdef CONFIG_PAX_RANDMMAP
42345+ /* PaX: randomize base address at the default exe base if requested */
42346+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42347+#ifdef CONFIG_SPARC64
42348+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42349+#else
42350+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42351+#endif
42352+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42353+ elf_flags |= MAP_FIXED;
42354+ }
42355+#endif
42356+
42357 }
42358
42359 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42360@@ -836,9 +1254,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42361 * allowed task size. Note that p_filesz must always be
42362 * <= p_memsz so it is only necessary to check p_memsz.
42363 */
42364- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42365- elf_ppnt->p_memsz > TASK_SIZE ||
42366- TASK_SIZE - elf_ppnt->p_memsz < k) {
42367+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42368+ elf_ppnt->p_memsz > pax_task_size ||
42369+ pax_task_size - elf_ppnt->p_memsz < k) {
42370 /* set_brk can never work. Avoid overflows. */
42371 send_sig(SIGKILL, current, 0);
42372 retval = -EINVAL;
42373@@ -877,11 +1295,40 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42374 goto out_free_dentry;
42375 }
42376 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42377- send_sig(SIGSEGV, current, 0);
42378- retval = -EFAULT; /* Nobody gets to see this, but.. */
42379- goto out_free_dentry;
42380+ /*
42381+ * This bss-zeroing can fail if the ELF
42382+ * file specifies odd protections. So
42383+ * we don't check the return value
42384+ */
42385 }
42386
42387+#ifdef CONFIG_PAX_RANDMMAP
42388+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42389+ unsigned long start, size;
42390+
42391+ start = ELF_PAGEALIGN(elf_brk);
42392+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42393+ down_write(&current->mm->mmap_sem);
42394+ retval = -ENOMEM;
42395+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42396+ unsigned long prot = PROT_NONE;
42397+
42398+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42399+// if (current->personality & ADDR_NO_RANDOMIZE)
42400+// prot = PROT_READ;
42401+ start = do_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42402+ retval = IS_ERR_VALUE(start) ? start : 0;
42403+ }
42404+ up_write(&current->mm->mmap_sem);
42405+ if (retval == 0)
42406+ retval = set_brk(start + size, start + size + PAGE_SIZE);
42407+ if (retval < 0) {
42408+ send_sig(SIGKILL, current, 0);
42409+ goto out_free_dentry;
42410+ }
42411+ }
42412+#endif
42413+
42414 if (elf_interpreter) {
42415 unsigned long uninitialized_var(interp_map_addr);
42416
42417@@ -1109,7 +1556,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
42418 * Decide what to dump of a segment, part, all or none.
42419 */
42420 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42421- unsigned long mm_flags)
42422+ unsigned long mm_flags, long signr)
42423 {
42424 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42425
42426@@ -1146,7 +1593,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42427 if (vma->vm_file == NULL)
42428 return 0;
42429
42430- if (FILTER(MAPPED_PRIVATE))
42431+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42432 goto whole;
42433
42434 /*
42435@@ -1368,9 +1815,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42436 {
42437 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42438 int i = 0;
42439- do
42440+ do {
42441 i += 2;
42442- while (auxv[i - 2] != AT_NULL);
42443+ } while (auxv[i - 2] != AT_NULL);
42444 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42445 }
42446
42447@@ -1892,14 +2339,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42448 }
42449
42450 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42451- unsigned long mm_flags)
42452+ struct coredump_params *cprm)
42453 {
42454 struct vm_area_struct *vma;
42455 size_t size = 0;
42456
42457 for (vma = first_vma(current, gate_vma); vma != NULL;
42458 vma = next_vma(vma, gate_vma))
42459- size += vma_dump_size(vma, mm_flags);
42460+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42461 return size;
42462 }
42463
42464@@ -1993,7 +2440,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42465
42466 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42467
42468- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42469+ offset += elf_core_vma_data_size(gate_vma, cprm);
42470 offset += elf_core_extra_data_size();
42471 e_shoff = offset;
42472
42473@@ -2007,10 +2454,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42474 offset = dataoff;
42475
42476 size += sizeof(*elf);
42477+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42478 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42479 goto end_coredump;
42480
42481 size += sizeof(*phdr4note);
42482+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42483 if (size > cprm->limit
42484 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42485 goto end_coredump;
42486@@ -2024,7 +2473,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42487 phdr.p_offset = offset;
42488 phdr.p_vaddr = vma->vm_start;
42489 phdr.p_paddr = 0;
42490- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42491+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42492 phdr.p_memsz = vma->vm_end - vma->vm_start;
42493 offset += phdr.p_filesz;
42494 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42495@@ -2035,6 +2484,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42496 phdr.p_align = ELF_EXEC_PAGESIZE;
42497
42498 size += sizeof(phdr);
42499+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42500 if (size > cprm->limit
42501 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42502 goto end_coredump;
42503@@ -2059,7 +2509,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42504 unsigned long addr;
42505 unsigned long end;
42506
42507- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42508+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42509
42510 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42511 struct page *page;
42512@@ -2068,6 +2518,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42513 page = get_dump_page(addr);
42514 if (page) {
42515 void *kaddr = kmap(page);
42516+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42517 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42518 !dump_write(cprm->file, kaddr,
42519 PAGE_SIZE);
42520@@ -2085,6 +2536,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42521
42522 if (e_phnum == PN_XNUM) {
42523 size += sizeof(*shdr4extnum);
42524+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42525 if (size > cprm->limit
42526 || !dump_write(cprm->file, shdr4extnum,
42527 sizeof(*shdr4extnum)))
42528@@ -2105,6 +2557,97 @@ out:
42529
42530 #endif /* CONFIG_ELF_CORE */
42531
42532+#ifdef CONFIG_PAX_MPROTECT
42533+/* PaX: non-PIC ELF libraries need relocations on their executable segments
42534+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42535+ * we'll remove VM_MAYWRITE for good on RELRO segments.
42536+ *
42537+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42538+ * basis because we want to allow the common case and not the special ones.
42539+ */
42540+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42541+{
42542+ struct elfhdr elf_h;
42543+ struct elf_phdr elf_p;
42544+ unsigned long i;
42545+ unsigned long oldflags;
42546+ bool is_textrel_rw, is_textrel_rx, is_relro;
42547+
42548+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42549+ return;
42550+
42551+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42552+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42553+
42554+#ifdef CONFIG_PAX_ELFRELOCS
42555+ /* possible TEXTREL */
42556+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42557+ 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);
42558+#else
42559+ is_textrel_rw = false;
42560+ is_textrel_rx = false;
42561+#endif
42562+
42563+ /* possible RELRO */
42564+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42565+
42566+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42567+ return;
42568+
42569+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42570+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42571+
42572+#ifdef CONFIG_PAX_ETEXECRELOCS
42573+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42574+#else
42575+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42576+#endif
42577+
42578+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42579+ !elf_check_arch(&elf_h) ||
42580+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42581+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42582+ return;
42583+
42584+ for (i = 0UL; i < elf_h.e_phnum; i++) {
42585+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42586+ return;
42587+ switch (elf_p.p_type) {
42588+ case PT_DYNAMIC:
42589+ if (!is_textrel_rw && !is_textrel_rx)
42590+ continue;
42591+ i = 0UL;
42592+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42593+ elf_dyn dyn;
42594+
42595+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42596+ return;
42597+ if (dyn.d_tag == DT_NULL)
42598+ return;
42599+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42600+ gr_log_textrel(vma);
42601+ if (is_textrel_rw)
42602+ vma->vm_flags |= VM_MAYWRITE;
42603+ else
42604+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42605+ vma->vm_flags &= ~VM_MAYWRITE;
42606+ return;
42607+ }
42608+ i++;
42609+ }
42610+ return;
42611+
42612+ case PT_GNU_RELRO:
42613+ if (!is_relro)
42614+ continue;
42615+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42616+ vma->vm_flags &= ~VM_MAYWRITE;
42617+ return;
42618+ }
42619+ }
42620+}
42621+#endif
42622+
42623 static int __init init_elf_binfmt(void)
42624 {
42625 register_binfmt(&elf_format);
42626diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
42627index 6b2daf9..a70dccb 100644
42628--- a/fs/binfmt_flat.c
42629+++ b/fs/binfmt_flat.c
42630@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
42631 realdatastart = (unsigned long) -ENOMEM;
42632 printk("Unable to allocate RAM for process data, errno %d\n",
42633 (int)-realdatastart);
42634+ down_write(&current->mm->mmap_sem);
42635 do_munmap(current->mm, textpos, text_len);
42636+ up_write(&current->mm->mmap_sem);
42637 ret = realdatastart;
42638 goto err;
42639 }
42640@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42641 }
42642 if (IS_ERR_VALUE(result)) {
42643 printk("Unable to read data+bss, errno %d\n", (int)-result);
42644+ down_write(&current->mm->mmap_sem);
42645 do_munmap(current->mm, textpos, text_len);
42646 do_munmap(current->mm, realdatastart, len);
42647+ up_write(&current->mm->mmap_sem);
42648 ret = result;
42649 goto err;
42650 }
42651@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42652 }
42653 if (IS_ERR_VALUE(result)) {
42654 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
42655+ down_write(&current->mm->mmap_sem);
42656 do_munmap(current->mm, textpos, text_len + data_len + extra +
42657 MAX_SHARED_LIBS * sizeof(unsigned long));
42658+ up_write(&current->mm->mmap_sem);
42659 ret = result;
42660 goto err;
42661 }
42662diff --git a/fs/bio.c b/fs/bio.c
42663index 84da885..bac1d48 100644
42664--- a/fs/bio.c
42665+++ b/fs/bio.c
42666@@ -838,7 +838,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
42667 /*
42668 * Overflow, abort
42669 */
42670- if (end < start)
42671+ if (end < start || end - start > INT_MAX - nr_pages)
42672 return ERR_PTR(-EINVAL);
42673
42674 nr_pages += end - start;
42675@@ -972,7 +972,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
42676 /*
42677 * Overflow, abort
42678 */
42679- if (end < start)
42680+ if (end < start || end - start > INT_MAX - nr_pages)
42681 return ERR_PTR(-EINVAL);
42682
42683 nr_pages += end - start;
42684@@ -1234,7 +1234,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
42685 const int read = bio_data_dir(bio) == READ;
42686 struct bio_map_data *bmd = bio->bi_private;
42687 int i;
42688- char *p = bmd->sgvecs[0].iov_base;
42689+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
42690
42691 __bio_for_each_segment(bvec, bio, i, 0) {
42692 char *addr = page_address(bvec->bv_page);
42693diff --git a/fs/block_dev.c b/fs/block_dev.c
42694index ba11c30..623d736 100644
42695--- a/fs/block_dev.c
42696+++ b/fs/block_dev.c
42697@@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
42698 else if (bdev->bd_contains == bdev)
42699 return true; /* is a whole device which isn't held */
42700
42701- else if (whole->bd_holder == bd_may_claim)
42702+ else if (whole->bd_holder == (void *)bd_may_claim)
42703 return true; /* is a partition of a device that is being partitioned */
42704 else if (whole->bd_holder != NULL)
42705 return false; /* is a partition of a held device */
42706diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
42707index c053e90..e5f1afc 100644
42708--- a/fs/btrfs/check-integrity.c
42709+++ b/fs/btrfs/check-integrity.c
42710@@ -156,7 +156,7 @@ struct btrfsic_block {
42711 union {
42712 bio_end_io_t *bio;
42713 bh_end_io_t *bh;
42714- } orig_bio_bh_end_io;
42715+ } __no_const orig_bio_bh_end_io;
42716 int submit_bio_bh_rw;
42717 u64 flush_gen; /* only valid if !never_written */
42718 };
42719diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
42720index 4106264..8157ede 100644
42721--- a/fs/btrfs/ctree.c
42722+++ b/fs/btrfs/ctree.c
42723@@ -513,9 +513,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
42724 free_extent_buffer(buf);
42725 add_root_to_dirty_list(root);
42726 } else {
42727- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
42728- parent_start = parent->start;
42729- else
42730+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
42731+ if (parent)
42732+ parent_start = parent->start;
42733+ else
42734+ parent_start = 0;
42735+ } else
42736 parent_start = 0;
42737
42738 WARN_ON(trans->transid != btrfs_header_generation(parent));
42739diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
42740index 0df0d1f..4bdcbfe 100644
42741--- a/fs/btrfs/inode.c
42742+++ b/fs/btrfs/inode.c
42743@@ -7074,7 +7074,7 @@ fail:
42744 return -ENOMEM;
42745 }
42746
42747-static int btrfs_getattr(struct vfsmount *mnt,
42748+int btrfs_getattr(struct vfsmount *mnt,
42749 struct dentry *dentry, struct kstat *stat)
42750 {
42751 struct inode *inode = dentry->d_inode;
42752@@ -7088,6 +7088,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
42753 return 0;
42754 }
42755
42756+EXPORT_SYMBOL(btrfs_getattr);
42757+
42758+dev_t get_btrfs_dev_from_inode(struct inode *inode)
42759+{
42760+ return BTRFS_I(inode)->root->anon_dev;
42761+}
42762+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
42763+
42764 /*
42765 * If a file is moved, it will inherit the cow and compression flags of the new
42766 * directory.
42767diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
42768index 14f8e1f..ab8d81f 100644
42769--- a/fs/btrfs/ioctl.c
42770+++ b/fs/btrfs/ioctl.c
42771@@ -2882,9 +2882,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42772 for (i = 0; i < num_types; i++) {
42773 struct btrfs_space_info *tmp;
42774
42775+ /* Don't copy in more than we allocated */
42776 if (!slot_count)
42777 break;
42778
42779+ slot_count--;
42780+
42781 info = NULL;
42782 rcu_read_lock();
42783 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
42784@@ -2906,15 +2909,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42785 memcpy(dest, &space, sizeof(space));
42786 dest++;
42787 space_args.total_spaces++;
42788- slot_count--;
42789 }
42790- if (!slot_count)
42791- break;
42792 }
42793 up_read(&info->groups_sem);
42794 }
42795
42796- user_dest = (struct btrfs_ioctl_space_info *)
42797+ user_dest = (struct btrfs_ioctl_space_info __user *)
42798 (arg + sizeof(struct btrfs_ioctl_space_args));
42799
42800 if (copy_to_user(user_dest, dest_orig, alloc_size))
42801diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
42802index 646ee21..f020f87 100644
42803--- a/fs/btrfs/relocation.c
42804+++ b/fs/btrfs/relocation.c
42805@@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
42806 }
42807 spin_unlock(&rc->reloc_root_tree.lock);
42808
42809- BUG_ON((struct btrfs_root *)node->data != root);
42810+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
42811
42812 if (!del) {
42813 spin_lock(&rc->reloc_root_tree.lock);
42814diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
42815index 622f469..e8d2d55 100644
42816--- a/fs/cachefiles/bind.c
42817+++ b/fs/cachefiles/bind.c
42818@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
42819 args);
42820
42821 /* start by checking things over */
42822- ASSERT(cache->fstop_percent >= 0 &&
42823- cache->fstop_percent < cache->fcull_percent &&
42824+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
42825 cache->fcull_percent < cache->frun_percent &&
42826 cache->frun_percent < 100);
42827
42828- ASSERT(cache->bstop_percent >= 0 &&
42829- cache->bstop_percent < cache->bcull_percent &&
42830+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
42831 cache->bcull_percent < cache->brun_percent &&
42832 cache->brun_percent < 100);
42833
42834diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
42835index 0a1467b..6a53245 100644
42836--- a/fs/cachefiles/daemon.c
42837+++ b/fs/cachefiles/daemon.c
42838@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
42839 if (n > buflen)
42840 return -EMSGSIZE;
42841
42842- if (copy_to_user(_buffer, buffer, n) != 0)
42843+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
42844 return -EFAULT;
42845
42846 return n;
42847@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
42848 if (test_bit(CACHEFILES_DEAD, &cache->flags))
42849 return -EIO;
42850
42851- if (datalen < 0 || datalen > PAGE_SIZE - 1)
42852+ if (datalen > PAGE_SIZE - 1)
42853 return -EOPNOTSUPP;
42854
42855 /* drag the command string into the kernel so we can parse it */
42856@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
42857 if (args[0] != '%' || args[1] != '\0')
42858 return -EINVAL;
42859
42860- if (fstop < 0 || fstop >= cache->fcull_percent)
42861+ if (fstop >= cache->fcull_percent)
42862 return cachefiles_daemon_range_error(cache, args);
42863
42864 cache->fstop_percent = fstop;
42865@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
42866 if (args[0] != '%' || args[1] != '\0')
42867 return -EINVAL;
42868
42869- if (bstop < 0 || bstop >= cache->bcull_percent)
42870+ if (bstop >= cache->bcull_percent)
42871 return cachefiles_daemon_range_error(cache, args);
42872
42873 cache->bstop_percent = bstop;
42874diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
42875index bd6bc1b..b627b53 100644
42876--- a/fs/cachefiles/internal.h
42877+++ b/fs/cachefiles/internal.h
42878@@ -57,7 +57,7 @@ struct cachefiles_cache {
42879 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
42880 struct rb_root active_nodes; /* active nodes (can't be culled) */
42881 rwlock_t active_lock; /* lock for active_nodes */
42882- atomic_t gravecounter; /* graveyard uniquifier */
42883+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
42884 unsigned frun_percent; /* when to stop culling (% files) */
42885 unsigned fcull_percent; /* when to start culling (% files) */
42886 unsigned fstop_percent; /* when to stop allocating (% files) */
42887@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
42888 * proc.c
42889 */
42890 #ifdef CONFIG_CACHEFILES_HISTOGRAM
42891-extern atomic_t cachefiles_lookup_histogram[HZ];
42892-extern atomic_t cachefiles_mkdir_histogram[HZ];
42893-extern atomic_t cachefiles_create_histogram[HZ];
42894+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42895+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42896+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
42897
42898 extern int __init cachefiles_proc_init(void);
42899 extern void cachefiles_proc_cleanup(void);
42900 static inline
42901-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
42902+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
42903 {
42904 unsigned long jif = jiffies - start_jif;
42905 if (jif >= HZ)
42906 jif = HZ - 1;
42907- atomic_inc(&histogram[jif]);
42908+ atomic_inc_unchecked(&histogram[jif]);
42909 }
42910
42911 #else
42912diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
42913index 7f0771d..87d4f36 100644
42914--- a/fs/cachefiles/namei.c
42915+++ b/fs/cachefiles/namei.c
42916@@ -318,7 +318,7 @@ try_again:
42917 /* first step is to make up a grave dentry in the graveyard */
42918 sprintf(nbuffer, "%08x%08x",
42919 (uint32_t) get_seconds(),
42920- (uint32_t) atomic_inc_return(&cache->gravecounter));
42921+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
42922
42923 /* do the multiway lock magic */
42924 trap = lock_rename(cache->graveyard, dir);
42925diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
42926index eccd339..4c1d995 100644
42927--- a/fs/cachefiles/proc.c
42928+++ b/fs/cachefiles/proc.c
42929@@ -14,9 +14,9 @@
42930 #include <linux/seq_file.h>
42931 #include "internal.h"
42932
42933-atomic_t cachefiles_lookup_histogram[HZ];
42934-atomic_t cachefiles_mkdir_histogram[HZ];
42935-atomic_t cachefiles_create_histogram[HZ];
42936+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42937+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42938+atomic_unchecked_t cachefiles_create_histogram[HZ];
42939
42940 /*
42941 * display the latency histogram
42942@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
42943 return 0;
42944 default:
42945 index = (unsigned long) v - 3;
42946- x = atomic_read(&cachefiles_lookup_histogram[index]);
42947- y = atomic_read(&cachefiles_mkdir_histogram[index]);
42948- z = atomic_read(&cachefiles_create_histogram[index]);
42949+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
42950+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
42951+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
42952 if (x == 0 && y == 0 && z == 0)
42953 return 0;
42954
42955diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
42956index 0e3c092..818480e 100644
42957--- a/fs/cachefiles/rdwr.c
42958+++ b/fs/cachefiles/rdwr.c
42959@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
42960 old_fs = get_fs();
42961 set_fs(KERNEL_DS);
42962 ret = file->f_op->write(
42963- file, (const void __user *) data, len, &pos);
42964+ file, (const void __force_user *) data, len, &pos);
42965 set_fs(old_fs);
42966 kunmap(page);
42967 if (ret != len)
42968diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
42969index 3e8094b..cb3ff3d 100644
42970--- a/fs/ceph/dir.c
42971+++ b/fs/ceph/dir.c
42972@@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
42973 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
42974 struct ceph_mds_client *mdsc = fsc->mdsc;
42975 unsigned frag = fpos_frag(filp->f_pos);
42976- int off = fpos_off(filp->f_pos);
42977+ unsigned int off = fpos_off(filp->f_pos);
42978 int err;
42979 u32 ftype;
42980 struct ceph_mds_reply_info_parsed *rinfo;
42981@@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
42982 if (nd &&
42983 (nd->flags & LOOKUP_OPEN) &&
42984 !(nd->intent.open.flags & O_CREAT)) {
42985- int mode = nd->intent.open.create_mode & ~current->fs->umask;
42986+ int mode = nd->intent.open.create_mode & ~current_umask();
42987 return ceph_lookup_open(dir, dentry, nd, mode, 1);
42988 }
42989
42990diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
42991index 2704646..c581c91 100644
42992--- a/fs/cifs/cifs_debug.c
42993+++ b/fs/cifs/cifs_debug.c
42994@@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42995
42996 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
42997 #ifdef CONFIG_CIFS_STATS2
42998- atomic_set(&totBufAllocCount, 0);
42999- atomic_set(&totSmBufAllocCount, 0);
43000+ atomic_set_unchecked(&totBufAllocCount, 0);
43001+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43002 #endif /* CONFIG_CIFS_STATS2 */
43003 spin_lock(&cifs_tcp_ses_lock);
43004 list_for_each(tmp1, &cifs_tcp_ses_list) {
43005@@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43006 tcon = list_entry(tmp3,
43007 struct cifs_tcon,
43008 tcon_list);
43009- atomic_set(&tcon->num_smbs_sent, 0);
43010- atomic_set(&tcon->num_writes, 0);
43011- atomic_set(&tcon->num_reads, 0);
43012- atomic_set(&tcon->num_oplock_brks, 0);
43013- atomic_set(&tcon->num_opens, 0);
43014- atomic_set(&tcon->num_posixopens, 0);
43015- atomic_set(&tcon->num_posixmkdirs, 0);
43016- atomic_set(&tcon->num_closes, 0);
43017- atomic_set(&tcon->num_deletes, 0);
43018- atomic_set(&tcon->num_mkdirs, 0);
43019- atomic_set(&tcon->num_rmdirs, 0);
43020- atomic_set(&tcon->num_renames, 0);
43021- atomic_set(&tcon->num_t2renames, 0);
43022- atomic_set(&tcon->num_ffirst, 0);
43023- atomic_set(&tcon->num_fnext, 0);
43024- atomic_set(&tcon->num_fclose, 0);
43025- atomic_set(&tcon->num_hardlinks, 0);
43026- atomic_set(&tcon->num_symlinks, 0);
43027- atomic_set(&tcon->num_locks, 0);
43028+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43029+ atomic_set_unchecked(&tcon->num_writes, 0);
43030+ atomic_set_unchecked(&tcon->num_reads, 0);
43031+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43032+ atomic_set_unchecked(&tcon->num_opens, 0);
43033+ atomic_set_unchecked(&tcon->num_posixopens, 0);
43034+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43035+ atomic_set_unchecked(&tcon->num_closes, 0);
43036+ atomic_set_unchecked(&tcon->num_deletes, 0);
43037+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
43038+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
43039+ atomic_set_unchecked(&tcon->num_renames, 0);
43040+ atomic_set_unchecked(&tcon->num_t2renames, 0);
43041+ atomic_set_unchecked(&tcon->num_ffirst, 0);
43042+ atomic_set_unchecked(&tcon->num_fnext, 0);
43043+ atomic_set_unchecked(&tcon->num_fclose, 0);
43044+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
43045+ atomic_set_unchecked(&tcon->num_symlinks, 0);
43046+ atomic_set_unchecked(&tcon->num_locks, 0);
43047 }
43048 }
43049 }
43050@@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43051 smBufAllocCount.counter, cifs_min_small);
43052 #ifdef CONFIG_CIFS_STATS2
43053 seq_printf(m, "Total Large %d Small %d Allocations\n",
43054- atomic_read(&totBufAllocCount),
43055- atomic_read(&totSmBufAllocCount));
43056+ atomic_read_unchecked(&totBufAllocCount),
43057+ atomic_read_unchecked(&totSmBufAllocCount));
43058 #endif /* CONFIG_CIFS_STATS2 */
43059
43060 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43061@@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43062 if (tcon->need_reconnect)
43063 seq_puts(m, "\tDISCONNECTED ");
43064 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43065- atomic_read(&tcon->num_smbs_sent),
43066- atomic_read(&tcon->num_oplock_brks));
43067+ atomic_read_unchecked(&tcon->num_smbs_sent),
43068+ atomic_read_unchecked(&tcon->num_oplock_brks));
43069 seq_printf(m, "\nReads: %d Bytes: %lld",
43070- atomic_read(&tcon->num_reads),
43071+ atomic_read_unchecked(&tcon->num_reads),
43072 (long long)(tcon->bytes_read));
43073 seq_printf(m, "\nWrites: %d Bytes: %lld",
43074- atomic_read(&tcon->num_writes),
43075+ atomic_read_unchecked(&tcon->num_writes),
43076 (long long)(tcon->bytes_written));
43077 seq_printf(m, "\nFlushes: %d",
43078- atomic_read(&tcon->num_flushes));
43079+ atomic_read_unchecked(&tcon->num_flushes));
43080 seq_printf(m, "\nLocks: %d HardLinks: %d "
43081 "Symlinks: %d",
43082- atomic_read(&tcon->num_locks),
43083- atomic_read(&tcon->num_hardlinks),
43084- atomic_read(&tcon->num_symlinks));
43085+ atomic_read_unchecked(&tcon->num_locks),
43086+ atomic_read_unchecked(&tcon->num_hardlinks),
43087+ atomic_read_unchecked(&tcon->num_symlinks));
43088 seq_printf(m, "\nOpens: %d Closes: %d "
43089 "Deletes: %d",
43090- atomic_read(&tcon->num_opens),
43091- atomic_read(&tcon->num_closes),
43092- atomic_read(&tcon->num_deletes));
43093+ atomic_read_unchecked(&tcon->num_opens),
43094+ atomic_read_unchecked(&tcon->num_closes),
43095+ atomic_read_unchecked(&tcon->num_deletes));
43096 seq_printf(m, "\nPosix Opens: %d "
43097 "Posix Mkdirs: %d",
43098- atomic_read(&tcon->num_posixopens),
43099- atomic_read(&tcon->num_posixmkdirs));
43100+ atomic_read_unchecked(&tcon->num_posixopens),
43101+ atomic_read_unchecked(&tcon->num_posixmkdirs));
43102 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43103- atomic_read(&tcon->num_mkdirs),
43104- atomic_read(&tcon->num_rmdirs));
43105+ atomic_read_unchecked(&tcon->num_mkdirs),
43106+ atomic_read_unchecked(&tcon->num_rmdirs));
43107 seq_printf(m, "\nRenames: %d T2 Renames %d",
43108- atomic_read(&tcon->num_renames),
43109- atomic_read(&tcon->num_t2renames));
43110+ atomic_read_unchecked(&tcon->num_renames),
43111+ atomic_read_unchecked(&tcon->num_t2renames));
43112 seq_printf(m, "\nFindFirst: %d FNext %d "
43113 "FClose %d",
43114- atomic_read(&tcon->num_ffirst),
43115- atomic_read(&tcon->num_fnext),
43116- atomic_read(&tcon->num_fclose));
43117+ atomic_read_unchecked(&tcon->num_ffirst),
43118+ atomic_read_unchecked(&tcon->num_fnext),
43119+ atomic_read_unchecked(&tcon->num_fclose));
43120 }
43121 }
43122 }
43123diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43124index 541ef81..a78deb8 100644
43125--- a/fs/cifs/cifsfs.c
43126+++ b/fs/cifs/cifsfs.c
43127@@ -985,7 +985,7 @@ cifs_init_request_bufs(void)
43128 cifs_req_cachep = kmem_cache_create("cifs_request",
43129 CIFSMaxBufSize +
43130 MAX_CIFS_HDR_SIZE, 0,
43131- SLAB_HWCACHE_ALIGN, NULL);
43132+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43133 if (cifs_req_cachep == NULL)
43134 return -ENOMEM;
43135
43136@@ -1012,7 +1012,7 @@ cifs_init_request_bufs(void)
43137 efficient to alloc 1 per page off the slab compared to 17K (5page)
43138 alloc of large cifs buffers even when page debugging is on */
43139 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43140- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43141+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43142 NULL);
43143 if (cifs_sm_req_cachep == NULL) {
43144 mempool_destroy(cifs_req_poolp);
43145@@ -1097,8 +1097,8 @@ init_cifs(void)
43146 atomic_set(&bufAllocCount, 0);
43147 atomic_set(&smBufAllocCount, 0);
43148 #ifdef CONFIG_CIFS_STATS2
43149- atomic_set(&totBufAllocCount, 0);
43150- atomic_set(&totSmBufAllocCount, 0);
43151+ atomic_set_unchecked(&totBufAllocCount, 0);
43152+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43153 #endif /* CONFIG_CIFS_STATS2 */
43154
43155 atomic_set(&midCount, 0);
43156diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43157index 73fea28..b996b84 100644
43158--- a/fs/cifs/cifsglob.h
43159+++ b/fs/cifs/cifsglob.h
43160@@ -439,28 +439,28 @@ struct cifs_tcon {
43161 __u16 Flags; /* optional support bits */
43162 enum statusEnum tidStatus;
43163 #ifdef CONFIG_CIFS_STATS
43164- atomic_t num_smbs_sent;
43165- atomic_t num_writes;
43166- atomic_t num_reads;
43167- atomic_t num_flushes;
43168- atomic_t num_oplock_brks;
43169- atomic_t num_opens;
43170- atomic_t num_closes;
43171- atomic_t num_deletes;
43172- atomic_t num_mkdirs;
43173- atomic_t num_posixopens;
43174- atomic_t num_posixmkdirs;
43175- atomic_t num_rmdirs;
43176- atomic_t num_renames;
43177- atomic_t num_t2renames;
43178- atomic_t num_ffirst;
43179- atomic_t num_fnext;
43180- atomic_t num_fclose;
43181- atomic_t num_hardlinks;
43182- atomic_t num_symlinks;
43183- atomic_t num_locks;
43184- atomic_t num_acl_get;
43185- atomic_t num_acl_set;
43186+ atomic_unchecked_t num_smbs_sent;
43187+ atomic_unchecked_t num_writes;
43188+ atomic_unchecked_t num_reads;
43189+ atomic_unchecked_t num_flushes;
43190+ atomic_unchecked_t num_oplock_brks;
43191+ atomic_unchecked_t num_opens;
43192+ atomic_unchecked_t num_closes;
43193+ atomic_unchecked_t num_deletes;
43194+ atomic_unchecked_t num_mkdirs;
43195+ atomic_unchecked_t num_posixopens;
43196+ atomic_unchecked_t num_posixmkdirs;
43197+ atomic_unchecked_t num_rmdirs;
43198+ atomic_unchecked_t num_renames;
43199+ atomic_unchecked_t num_t2renames;
43200+ atomic_unchecked_t num_ffirst;
43201+ atomic_unchecked_t num_fnext;
43202+ atomic_unchecked_t num_fclose;
43203+ atomic_unchecked_t num_hardlinks;
43204+ atomic_unchecked_t num_symlinks;
43205+ atomic_unchecked_t num_locks;
43206+ atomic_unchecked_t num_acl_get;
43207+ atomic_unchecked_t num_acl_set;
43208 #ifdef CONFIG_CIFS_STATS2
43209 unsigned long long time_writes;
43210 unsigned long long time_reads;
43211@@ -677,7 +677,7 @@ convert_delimiter(char *path, char delim)
43212 }
43213
43214 #ifdef CONFIG_CIFS_STATS
43215-#define cifs_stats_inc atomic_inc
43216+#define cifs_stats_inc atomic_inc_unchecked
43217
43218 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43219 unsigned int bytes)
43220@@ -1036,8 +1036,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43221 /* Various Debug counters */
43222 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43223 #ifdef CONFIG_CIFS_STATS2
43224-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43225-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43226+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43227+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43228 #endif
43229 GLOBAL_EXTERN atomic_t smBufAllocCount;
43230 GLOBAL_EXTERN atomic_t midCount;
43231diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43232index 6b0e064..94e6c3c 100644
43233--- a/fs/cifs/link.c
43234+++ b/fs/cifs/link.c
43235@@ -600,7 +600,7 @@ symlink_exit:
43236
43237 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43238 {
43239- char *p = nd_get_link(nd);
43240+ const char *p = nd_get_link(nd);
43241 if (!IS_ERR(p))
43242 kfree(p);
43243 }
43244diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43245index c29d1aa..58018da 100644
43246--- a/fs/cifs/misc.c
43247+++ b/fs/cifs/misc.c
43248@@ -156,7 +156,7 @@ cifs_buf_get(void)
43249 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43250 atomic_inc(&bufAllocCount);
43251 #ifdef CONFIG_CIFS_STATS2
43252- atomic_inc(&totBufAllocCount);
43253+ atomic_inc_unchecked(&totBufAllocCount);
43254 #endif /* CONFIG_CIFS_STATS2 */
43255 }
43256
43257@@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43258 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43259 atomic_inc(&smBufAllocCount);
43260 #ifdef CONFIG_CIFS_STATS2
43261- atomic_inc(&totSmBufAllocCount);
43262+ atomic_inc_unchecked(&totSmBufAllocCount);
43263 #endif /* CONFIG_CIFS_STATS2 */
43264
43265 }
43266diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43267index 6901578..d402eb5 100644
43268--- a/fs/coda/cache.c
43269+++ b/fs/coda/cache.c
43270@@ -24,7 +24,7 @@
43271 #include "coda_linux.h"
43272 #include "coda_cache.h"
43273
43274-static atomic_t permission_epoch = ATOMIC_INIT(0);
43275+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43276
43277 /* replace or extend an acl cache hit */
43278 void coda_cache_enter(struct inode *inode, int mask)
43279@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43280 struct coda_inode_info *cii = ITOC(inode);
43281
43282 spin_lock(&cii->c_lock);
43283- cii->c_cached_epoch = atomic_read(&permission_epoch);
43284+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43285 if (cii->c_uid != current_fsuid()) {
43286 cii->c_uid = current_fsuid();
43287 cii->c_cached_perm = mask;
43288@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43289 {
43290 struct coda_inode_info *cii = ITOC(inode);
43291 spin_lock(&cii->c_lock);
43292- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43293+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43294 spin_unlock(&cii->c_lock);
43295 }
43296
43297 /* remove all acl caches */
43298 void coda_cache_clear_all(struct super_block *sb)
43299 {
43300- atomic_inc(&permission_epoch);
43301+ atomic_inc_unchecked(&permission_epoch);
43302 }
43303
43304
43305@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43306 spin_lock(&cii->c_lock);
43307 hit = (mask & cii->c_cached_perm) == mask &&
43308 cii->c_uid == current_fsuid() &&
43309- cii->c_cached_epoch == atomic_read(&permission_epoch);
43310+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43311 spin_unlock(&cii->c_lock);
43312
43313 return hit;
43314diff --git a/fs/compat.c b/fs/compat.c
43315index f2944ac..62845d2 100644
43316--- a/fs/compat.c
43317+++ b/fs/compat.c
43318@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43319
43320 set_fs(KERNEL_DS);
43321 /* The __user pointer cast is valid because of the set_fs() */
43322- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43323+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43324 set_fs(oldfs);
43325 /* truncating is ok because it's a user address */
43326 if (!ret)
43327@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43328 goto out;
43329
43330 ret = -EINVAL;
43331- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43332+ if (nr_segs > UIO_MAXIOV)
43333 goto out;
43334 if (nr_segs > fast_segs) {
43335 ret = -ENOMEM;
43336@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
43337
43338 struct compat_readdir_callback {
43339 struct compat_old_linux_dirent __user *dirent;
43340+ struct file * file;
43341 int result;
43342 };
43343
43344@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43345 buf->result = -EOVERFLOW;
43346 return -EOVERFLOW;
43347 }
43348+
43349+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43350+ return 0;
43351+
43352 buf->result++;
43353 dirent = buf->dirent;
43354 if (!access_ok(VERIFY_WRITE, dirent,
43355@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43356
43357 buf.result = 0;
43358 buf.dirent = dirent;
43359+ buf.file = file;
43360
43361 error = vfs_readdir(file, compat_fillonedir, &buf);
43362 if (buf.result)
43363@@ -900,6 +906,7 @@ struct compat_linux_dirent {
43364 struct compat_getdents_callback {
43365 struct compat_linux_dirent __user *current_dir;
43366 struct compat_linux_dirent __user *previous;
43367+ struct file * file;
43368 int count;
43369 int error;
43370 };
43371@@ -921,6 +928,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43372 buf->error = -EOVERFLOW;
43373 return -EOVERFLOW;
43374 }
43375+
43376+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43377+ return 0;
43378+
43379 dirent = buf->previous;
43380 if (dirent) {
43381 if (__put_user(offset, &dirent->d_off))
43382@@ -968,6 +979,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43383 buf.previous = NULL;
43384 buf.count = count;
43385 buf.error = 0;
43386+ buf.file = file;
43387
43388 error = vfs_readdir(file, compat_filldir, &buf);
43389 if (error >= 0)
43390@@ -989,6 +1001,7 @@ out:
43391 struct compat_getdents_callback64 {
43392 struct linux_dirent64 __user *current_dir;
43393 struct linux_dirent64 __user *previous;
43394+ struct file * file;
43395 int count;
43396 int error;
43397 };
43398@@ -1005,6 +1018,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43399 buf->error = -EINVAL; /* only used if we fail.. */
43400 if (reclen > buf->count)
43401 return -EINVAL;
43402+
43403+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43404+ return 0;
43405+
43406 dirent = buf->previous;
43407
43408 if (dirent) {
43409@@ -1056,13 +1073,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43410 buf.previous = NULL;
43411 buf.count = count;
43412 buf.error = 0;
43413+ buf.file = file;
43414
43415 error = vfs_readdir(file, compat_filldir64, &buf);
43416 if (error >= 0)
43417 error = buf.error;
43418 lastdirent = buf.previous;
43419 if (lastdirent) {
43420- typeof(lastdirent->d_off) d_off = file->f_pos;
43421+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43422 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43423 error = -EFAULT;
43424 else
43425diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43426index 112e45a..b59845b 100644
43427--- a/fs/compat_binfmt_elf.c
43428+++ b/fs/compat_binfmt_elf.c
43429@@ -30,11 +30,13 @@
43430 #undef elf_phdr
43431 #undef elf_shdr
43432 #undef elf_note
43433+#undef elf_dyn
43434 #undef elf_addr_t
43435 #define elfhdr elf32_hdr
43436 #define elf_phdr elf32_phdr
43437 #define elf_shdr elf32_shdr
43438 #define elf_note elf32_note
43439+#define elf_dyn Elf32_Dyn
43440 #define elf_addr_t Elf32_Addr
43441
43442 /*
43443diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43444index debdfe0..75d31d4 100644
43445--- a/fs/compat_ioctl.c
43446+++ b/fs/compat_ioctl.c
43447@@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43448
43449 err = get_user(palp, &up->palette);
43450 err |= get_user(length, &up->length);
43451+ if (err)
43452+ return -EFAULT;
43453
43454 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43455 err = put_user(compat_ptr(palp), &up_native->palette);
43456@@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43457 return -EFAULT;
43458 if (__get_user(udata, &ss32->iomem_base))
43459 return -EFAULT;
43460- ss.iomem_base = compat_ptr(udata);
43461+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43462 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43463 __get_user(ss.port_high, &ss32->port_high))
43464 return -EFAULT;
43465@@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
43466 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43467 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43468 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43469- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43470+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43471 return -EFAULT;
43472
43473 return ioctl_preallocate(file, p);
43474@@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43475 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43476 {
43477 unsigned int a, b;
43478- a = *(unsigned int *)p;
43479- b = *(unsigned int *)q;
43480+ a = *(const unsigned int *)p;
43481+ b = *(const unsigned int *)q;
43482 if (a > b)
43483 return 1;
43484 if (a < b)
43485diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43486index 7e6c52d..94bc756 100644
43487--- a/fs/configfs/dir.c
43488+++ b/fs/configfs/dir.c
43489@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43490 }
43491 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43492 struct configfs_dirent *next;
43493- const char * name;
43494+ const unsigned char * name;
43495+ char d_name[sizeof(next->s_dentry->d_iname)];
43496 int len;
43497 struct inode *inode = NULL;
43498
43499@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43500 continue;
43501
43502 name = configfs_get_name(next);
43503- len = strlen(name);
43504+ if (next->s_dentry && name == next->s_dentry->d_iname) {
43505+ len = next->s_dentry->d_name.len;
43506+ memcpy(d_name, name, len);
43507+ name = d_name;
43508+ } else
43509+ len = strlen(name);
43510
43511 /*
43512 * We'll have a dentry and an inode for
43513diff --git a/fs/dcache.c b/fs/dcache.c
43514index b80531c..8ca7e2d 100644
43515--- a/fs/dcache.c
43516+++ b/fs/dcache.c
43517@@ -3084,7 +3084,7 @@ void __init vfs_caches_init(unsigned long mempages)
43518 mempages -= reserve;
43519
43520 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43521- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43522+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43523
43524 dcache_init();
43525 inode_init();
43526diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43527index b80bc84..0d46d1a 100644
43528--- a/fs/debugfs/inode.c
43529+++ b/fs/debugfs/inode.c
43530@@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43531 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43532 {
43533 return debugfs_create_file(name,
43534+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43535+ S_IFDIR | S_IRWXU,
43536+#else
43537 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43538+#endif
43539 parent, NULL, NULL);
43540 }
43541 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43542diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43543index ab35b11..b30af66 100644
43544--- a/fs/ecryptfs/inode.c
43545+++ b/fs/ecryptfs/inode.c
43546@@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43547 old_fs = get_fs();
43548 set_fs(get_ds());
43549 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43550- (char __user *)lower_buf,
43551+ (char __force_user *)lower_buf,
43552 lower_bufsiz);
43553 set_fs(old_fs);
43554 if (rc < 0)
43555@@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43556 }
43557 old_fs = get_fs();
43558 set_fs(get_ds());
43559- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43560+ rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43561 set_fs(old_fs);
43562 if (rc < 0) {
43563 kfree(buf);
43564@@ -733,7 +733,7 @@ out:
43565 static void
43566 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43567 {
43568- char *buf = nd_get_link(nd);
43569+ const char *buf = nd_get_link(nd);
43570 if (!IS_ERR(buf)) {
43571 /* Free the char* */
43572 kfree(buf);
43573diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43574index c0038f6..47ab347 100644
43575--- a/fs/ecryptfs/miscdev.c
43576+++ b/fs/ecryptfs/miscdev.c
43577@@ -355,7 +355,7 @@ check_list:
43578 goto out_unlock_msg_ctx;
43579 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
43580 if (msg_ctx->msg) {
43581- if (copy_to_user(&buf[i], packet_length, packet_length_size))
43582+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43583 goto out_unlock_msg_ctx;
43584 i += packet_length_size;
43585 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43586diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43587index b2a34a1..162fa69 100644
43588--- a/fs/ecryptfs/read_write.c
43589+++ b/fs/ecryptfs/read_write.c
43590@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43591 return -EIO;
43592 fs_save = get_fs();
43593 set_fs(get_ds());
43594- rc = vfs_write(lower_file, data, size, &offset);
43595+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43596 set_fs(fs_save);
43597 mark_inode_dirty_sync(ecryptfs_inode);
43598 return rc;
43599@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43600 return -EIO;
43601 fs_save = get_fs();
43602 set_fs(get_ds());
43603- rc = vfs_read(lower_file, data, size, &offset);
43604+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43605 set_fs(fs_save);
43606 return rc;
43607 }
43608diff --git a/fs/exec.c b/fs/exec.c
43609index 29e5f84..7acfbdb 100644
43610--- a/fs/exec.c
43611+++ b/fs/exec.c
43612@@ -55,6 +55,15 @@
43613 #include <linux/pipe_fs_i.h>
43614 #include <linux/oom.h>
43615 #include <linux/compat.h>
43616+#include <linux/random.h>
43617+#include <linux/seq_file.h>
43618+
43619+#ifdef CONFIG_PAX_REFCOUNT
43620+#include <linux/kallsyms.h>
43621+#include <linux/kdebug.h>
43622+#endif
43623+
43624+#include <trace/events/fs.h>
43625
43626 #include <asm/uaccess.h>
43627 #include <asm/mmu_context.h>
43628@@ -66,6 +75,18 @@
43629
43630 #include <trace/events/sched.h>
43631
43632+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43633+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
43634+{
43635+ 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");
43636+}
43637+#endif
43638+
43639+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
43640+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
43641+EXPORT_SYMBOL(pax_set_initial_flags_func);
43642+#endif
43643+
43644 int core_uses_pid;
43645 char core_pattern[CORENAME_MAX_SIZE] = "core";
43646 unsigned int core_pipe_limit;
43647@@ -75,7 +96,7 @@ struct core_name {
43648 char *corename;
43649 int used, size;
43650 };
43651-static atomic_t call_count = ATOMIC_INIT(1);
43652+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
43653
43654 /* The maximal length of core_pattern is also specified in sysctl.c */
43655
43656@@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43657 int write)
43658 {
43659 struct page *page;
43660- int ret;
43661
43662-#ifdef CONFIG_STACK_GROWSUP
43663- if (write) {
43664- ret = expand_downwards(bprm->vma, pos);
43665- if (ret < 0)
43666- return NULL;
43667- }
43668-#endif
43669- ret = get_user_pages(current, bprm->mm, pos,
43670- 1, write, 1, &page, NULL);
43671- if (ret <= 0)
43672+ if (0 > expand_downwards(bprm->vma, pos))
43673+ return NULL;
43674+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
43675 return NULL;
43676
43677 if (write) {
43678@@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43679 if (size <= ARG_MAX)
43680 return page;
43681
43682+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43683+ // only allow 512KB for argv+env on suid/sgid binaries
43684+ // to prevent easy ASLR exhaustion
43685+ if (((bprm->cred->euid != current_euid()) ||
43686+ (bprm->cred->egid != current_egid())) &&
43687+ (size > (512 * 1024))) {
43688+ put_page(page);
43689+ return NULL;
43690+ }
43691+#endif
43692+
43693 /*
43694 * Limit to 1/4-th the stack size for the argv+env strings.
43695 * This ensures that:
43696@@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43697 vma->vm_end = STACK_TOP_MAX;
43698 vma->vm_start = vma->vm_end - PAGE_SIZE;
43699 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
43700+
43701+#ifdef CONFIG_PAX_SEGMEXEC
43702+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
43703+#endif
43704+
43705 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
43706 INIT_LIST_HEAD(&vma->anon_vma_chain);
43707
43708@@ -291,6 +320,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43709 mm->stack_vm = mm->total_vm = 1;
43710 up_write(&mm->mmap_sem);
43711 bprm->p = vma->vm_end - sizeof(void *);
43712+
43713+#ifdef CONFIG_PAX_RANDUSTACK
43714+ if (randomize_va_space)
43715+ bprm->p ^= random32() & ~PAGE_MASK;
43716+#endif
43717+
43718 return 0;
43719 err:
43720 up_write(&mm->mmap_sem);
43721@@ -399,19 +434,7 @@ err:
43722 return err;
43723 }
43724
43725-struct user_arg_ptr {
43726-#ifdef CONFIG_COMPAT
43727- bool is_compat;
43728-#endif
43729- union {
43730- const char __user *const __user *native;
43731-#ifdef CONFIG_COMPAT
43732- compat_uptr_t __user *compat;
43733-#endif
43734- } ptr;
43735-};
43736-
43737-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43738+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43739 {
43740 const char __user *native;
43741
43742@@ -420,14 +443,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43743 compat_uptr_t compat;
43744
43745 if (get_user(compat, argv.ptr.compat + nr))
43746- return ERR_PTR(-EFAULT);
43747+ return (const char __force_user *)ERR_PTR(-EFAULT);
43748
43749 return compat_ptr(compat);
43750 }
43751 #endif
43752
43753 if (get_user(native, argv.ptr.native + nr))
43754- return ERR_PTR(-EFAULT);
43755+ return (const char __force_user *)ERR_PTR(-EFAULT);
43756
43757 return native;
43758 }
43759@@ -446,7 +469,7 @@ static int count(struct user_arg_ptr argv, int max)
43760 if (!p)
43761 break;
43762
43763- if (IS_ERR(p))
43764+ if (IS_ERR((const char __force_kernel *)p))
43765 return -EFAULT;
43766
43767 if (i++ >= max)
43768@@ -480,7 +503,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
43769
43770 ret = -EFAULT;
43771 str = get_user_arg_ptr(argv, argc);
43772- if (IS_ERR(str))
43773+ if (IS_ERR((const char __force_kernel *)str))
43774 goto out;
43775
43776 len = strnlen_user(str, MAX_ARG_STRLEN);
43777@@ -562,7 +585,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
43778 int r;
43779 mm_segment_t oldfs = get_fs();
43780 struct user_arg_ptr argv = {
43781- .ptr.native = (const char __user *const __user *)__argv,
43782+ .ptr.native = (const char __force_user *const __force_user *)__argv,
43783 };
43784
43785 set_fs(KERNEL_DS);
43786@@ -597,7 +620,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43787 unsigned long new_end = old_end - shift;
43788 struct mmu_gather tlb;
43789
43790- BUG_ON(new_start > new_end);
43791+ if (new_start >= new_end || new_start < mmap_min_addr)
43792+ return -ENOMEM;
43793
43794 /*
43795 * ensure there are no vmas between where we want to go
43796@@ -606,6 +630,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43797 if (vma != find_vma(mm, new_start))
43798 return -EFAULT;
43799
43800+#ifdef CONFIG_PAX_SEGMEXEC
43801+ BUG_ON(pax_find_mirror_vma(vma));
43802+#endif
43803+
43804 /*
43805 * cover the whole range: [new_start, old_end)
43806 */
43807@@ -686,10 +714,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43808 stack_top = arch_align_stack(stack_top);
43809 stack_top = PAGE_ALIGN(stack_top);
43810
43811- if (unlikely(stack_top < mmap_min_addr) ||
43812- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
43813- return -ENOMEM;
43814-
43815 stack_shift = vma->vm_end - stack_top;
43816
43817 bprm->p -= stack_shift;
43818@@ -701,8 +725,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
43819 bprm->exec -= stack_shift;
43820
43821 down_write(&mm->mmap_sem);
43822+
43823+ /* Move stack pages down in memory. */
43824+ if (stack_shift) {
43825+ ret = shift_arg_pages(vma, stack_shift);
43826+ if (ret)
43827+ goto out_unlock;
43828+ }
43829+
43830 vm_flags = VM_STACK_FLAGS;
43831
43832+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43833+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43834+ vm_flags &= ~VM_EXEC;
43835+
43836+#ifdef CONFIG_PAX_MPROTECT
43837+ if (mm->pax_flags & MF_PAX_MPROTECT)
43838+ vm_flags &= ~VM_MAYEXEC;
43839+#endif
43840+
43841+ }
43842+#endif
43843+
43844 /*
43845 * Adjust stack execute permissions; explicitly enable for
43846 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
43847@@ -721,13 +765,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43848 goto out_unlock;
43849 BUG_ON(prev != vma);
43850
43851- /* Move stack pages down in memory. */
43852- if (stack_shift) {
43853- ret = shift_arg_pages(vma, stack_shift);
43854- if (ret)
43855- goto out_unlock;
43856- }
43857-
43858 /* mprotect_fixup is overkill to remove the temporary stack flags */
43859 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
43860
43861@@ -785,6 +822,8 @@ struct file *open_exec(const char *name)
43862
43863 fsnotify_open(file);
43864
43865+ trace_open_exec(name);
43866+
43867 err = deny_write_access(file);
43868 if (err)
43869 goto exit;
43870@@ -808,7 +847,7 @@ int kernel_read(struct file *file, loff_t offset,
43871 old_fs = get_fs();
43872 set_fs(get_ds());
43873 /* The cast to a user pointer is valid due to the set_fs() */
43874- result = vfs_read(file, (void __user *)addr, count, &pos);
43875+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
43876 set_fs(old_fs);
43877 return result;
43878 }
43879@@ -1254,7 +1293,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
43880 }
43881 rcu_read_unlock();
43882
43883- if (p->fs->users > n_fs) {
43884+ if (atomic_read(&p->fs->users) > n_fs) {
43885 bprm->unsafe |= LSM_UNSAFE_SHARE;
43886 } else {
43887 res = -EAGAIN;
43888@@ -1451,6 +1490,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
43889
43890 EXPORT_SYMBOL(search_binary_handler);
43891
43892+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43893+static DEFINE_PER_CPU(u64, exec_counter);
43894+static int __init init_exec_counters(void)
43895+{
43896+ unsigned int cpu;
43897+
43898+ for_each_possible_cpu(cpu) {
43899+ per_cpu(exec_counter, cpu) = (u64)cpu;
43900+ }
43901+
43902+ return 0;
43903+}
43904+early_initcall(init_exec_counters);
43905+static inline void increment_exec_counter(void)
43906+{
43907+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
43908+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
43909+}
43910+#else
43911+static inline void increment_exec_counter(void) {}
43912+#endif
43913+
43914 /*
43915 * sys_execve() executes a new program.
43916 */
43917@@ -1459,6 +1520,11 @@ static int do_execve_common(const char *filename,
43918 struct user_arg_ptr envp,
43919 struct pt_regs *regs)
43920 {
43921+#ifdef CONFIG_GRKERNSEC
43922+ struct file *old_exec_file;
43923+ struct acl_subject_label *old_acl;
43924+ struct rlimit old_rlim[RLIM_NLIMITS];
43925+#endif
43926 struct linux_binprm *bprm;
43927 struct file *file;
43928 struct files_struct *displaced;
43929@@ -1466,6 +1532,8 @@ static int do_execve_common(const char *filename,
43930 int retval;
43931 const struct cred *cred = current_cred();
43932
43933+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
43934+
43935 /*
43936 * We move the actual failure in case of RLIMIT_NPROC excess from
43937 * set*uid() to execve() because too many poorly written programs
43938@@ -1506,12 +1574,27 @@ static int do_execve_common(const char *filename,
43939 if (IS_ERR(file))
43940 goto out_unmark;
43941
43942+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
43943+ retval = -EPERM;
43944+ goto out_file;
43945+ }
43946+
43947 sched_exec();
43948
43949 bprm->file = file;
43950 bprm->filename = filename;
43951 bprm->interp = filename;
43952
43953+ if (gr_process_user_ban()) {
43954+ retval = -EPERM;
43955+ goto out_file;
43956+ }
43957+
43958+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
43959+ retval = -EACCES;
43960+ goto out_file;
43961+ }
43962+
43963 retval = bprm_mm_init(bprm);
43964 if (retval)
43965 goto out_file;
43966@@ -1528,24 +1611,65 @@ static int do_execve_common(const char *filename,
43967 if (retval < 0)
43968 goto out;
43969
43970+#ifdef CONFIG_GRKERNSEC
43971+ old_acl = current->acl;
43972+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
43973+ old_exec_file = current->exec_file;
43974+ get_file(file);
43975+ current->exec_file = file;
43976+#endif
43977+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43978+ /* limit suid stack to 8MB
43979+ we saved the old limits above and will restore them if this exec fails
43980+ */
43981+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
43982+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
43983+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
43984+#endif
43985+
43986+ if (!gr_tpe_allow(file)) {
43987+ retval = -EACCES;
43988+ goto out_fail;
43989+ }
43990+
43991+ if (gr_check_crash_exec(file)) {
43992+ retval = -EACCES;
43993+ goto out_fail;
43994+ }
43995+
43996+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
43997+ bprm->unsafe);
43998+ if (retval < 0)
43999+ goto out_fail;
44000+
44001 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44002 if (retval < 0)
44003- goto out;
44004+ goto out_fail;
44005
44006 bprm->exec = bprm->p;
44007 retval = copy_strings(bprm->envc, envp, bprm);
44008 if (retval < 0)
44009- goto out;
44010+ goto out_fail;
44011
44012 retval = copy_strings(bprm->argc, argv, bprm);
44013 if (retval < 0)
44014- goto out;
44015+ goto out_fail;
44016+
44017+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44018+
44019+ gr_handle_exec_args(bprm, argv);
44020
44021 retval = search_binary_handler(bprm,regs);
44022 if (retval < 0)
44023- goto out;
44024+ goto out_fail;
44025+#ifdef CONFIG_GRKERNSEC
44026+ if (old_exec_file)
44027+ fput(old_exec_file);
44028+#endif
44029
44030 /* execve succeeded */
44031+
44032+ increment_exec_counter();
44033 current->fs->in_exec = 0;
44034 current->in_execve = 0;
44035 acct_update_integrals(current);
44036@@ -1554,6 +1678,14 @@ static int do_execve_common(const char *filename,
44037 put_files_struct(displaced);
44038 return retval;
44039
44040+out_fail:
44041+#ifdef CONFIG_GRKERNSEC
44042+ current->acl = old_acl;
44043+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44044+ fput(current->exec_file);
44045+ current->exec_file = old_exec_file;
44046+#endif
44047+
44048 out:
44049 if (bprm->mm) {
44050 acct_arg_size(bprm, 0);
44051@@ -1627,7 +1759,7 @@ static int expand_corename(struct core_name *cn)
44052 {
44053 char *old_corename = cn->corename;
44054
44055- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44056+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44057 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44058
44059 if (!cn->corename) {
44060@@ -1724,7 +1856,7 @@ static int format_corename(struct core_name *cn, long signr)
44061 int pid_in_pattern = 0;
44062 int err = 0;
44063
44064- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44065+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44066 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44067 cn->used = 0;
44068
44069@@ -1821,6 +1953,250 @@ out:
44070 return ispipe;
44071 }
44072
44073+int pax_check_flags(unsigned long *flags)
44074+{
44075+ int retval = 0;
44076+
44077+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44078+ if (*flags & MF_PAX_SEGMEXEC)
44079+ {
44080+ *flags &= ~MF_PAX_SEGMEXEC;
44081+ retval = -EINVAL;
44082+ }
44083+#endif
44084+
44085+ if ((*flags & MF_PAX_PAGEEXEC)
44086+
44087+#ifdef CONFIG_PAX_PAGEEXEC
44088+ && (*flags & MF_PAX_SEGMEXEC)
44089+#endif
44090+
44091+ )
44092+ {
44093+ *flags &= ~MF_PAX_PAGEEXEC;
44094+ retval = -EINVAL;
44095+ }
44096+
44097+ if ((*flags & MF_PAX_MPROTECT)
44098+
44099+#ifdef CONFIG_PAX_MPROTECT
44100+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44101+#endif
44102+
44103+ )
44104+ {
44105+ *flags &= ~MF_PAX_MPROTECT;
44106+ retval = -EINVAL;
44107+ }
44108+
44109+ if ((*flags & MF_PAX_EMUTRAMP)
44110+
44111+#ifdef CONFIG_PAX_EMUTRAMP
44112+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44113+#endif
44114+
44115+ )
44116+ {
44117+ *flags &= ~MF_PAX_EMUTRAMP;
44118+ retval = -EINVAL;
44119+ }
44120+
44121+ return retval;
44122+}
44123+
44124+EXPORT_SYMBOL(pax_check_flags);
44125+
44126+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44127+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44128+{
44129+ struct task_struct *tsk = current;
44130+ struct mm_struct *mm = current->mm;
44131+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44132+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44133+ char *path_exec = NULL;
44134+ char *path_fault = NULL;
44135+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
44136+
44137+ if (buffer_exec && buffer_fault) {
44138+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44139+
44140+ down_read(&mm->mmap_sem);
44141+ vma = mm->mmap;
44142+ while (vma && (!vma_exec || !vma_fault)) {
44143+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44144+ vma_exec = vma;
44145+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44146+ vma_fault = vma;
44147+ vma = vma->vm_next;
44148+ }
44149+ if (vma_exec) {
44150+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44151+ if (IS_ERR(path_exec))
44152+ path_exec = "<path too long>";
44153+ else {
44154+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44155+ if (path_exec) {
44156+ *path_exec = 0;
44157+ path_exec = buffer_exec;
44158+ } else
44159+ path_exec = "<path too long>";
44160+ }
44161+ }
44162+ if (vma_fault) {
44163+ start = vma_fault->vm_start;
44164+ end = vma_fault->vm_end;
44165+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44166+ if (vma_fault->vm_file) {
44167+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44168+ if (IS_ERR(path_fault))
44169+ path_fault = "<path too long>";
44170+ else {
44171+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44172+ if (path_fault) {
44173+ *path_fault = 0;
44174+ path_fault = buffer_fault;
44175+ } else
44176+ path_fault = "<path too long>";
44177+ }
44178+ } else
44179+ path_fault = "<anonymous mapping>";
44180+ }
44181+ up_read(&mm->mmap_sem);
44182+ }
44183+ if (tsk->signal->curr_ip)
44184+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44185+ else
44186+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44187+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44188+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44189+ task_uid(tsk), task_euid(tsk), pc, sp);
44190+ free_page((unsigned long)buffer_exec);
44191+ free_page((unsigned long)buffer_fault);
44192+ pax_report_insns(regs, pc, sp);
44193+ do_coredump(SIGKILL, SIGKILL, regs);
44194+}
44195+#endif
44196+
44197+#ifdef CONFIG_PAX_REFCOUNT
44198+void pax_report_refcount_overflow(struct pt_regs *regs)
44199+{
44200+ if (current->signal->curr_ip)
44201+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44202+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44203+ else
44204+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44205+ current->comm, task_pid_nr(current), current_uid(), current_euid());
44206+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44207+ show_regs(regs);
44208+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44209+}
44210+#endif
44211+
44212+#ifdef CONFIG_PAX_USERCOPY
44213+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44214+static noinline int check_stack_object(const void *obj, unsigned long len)
44215+{
44216+ const void * const stack = task_stack_page(current);
44217+ const void * const stackend = stack + THREAD_SIZE;
44218+
44219+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44220+ const void *frame = NULL;
44221+ const void *oldframe;
44222+#endif
44223+
44224+ if (obj + len < obj)
44225+ return -1;
44226+
44227+ if (obj + len <= stack || stackend <= obj)
44228+ return 0;
44229+
44230+ if (obj < stack || stackend < obj + len)
44231+ return -1;
44232+
44233+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44234+ oldframe = __builtin_frame_address(1);
44235+ if (oldframe)
44236+ frame = __builtin_frame_address(2);
44237+ /*
44238+ low ----------------------------------------------> high
44239+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
44240+ ^----------------^
44241+ allow copies only within here
44242+ */
44243+ while (stack <= frame && frame < stackend) {
44244+ /* if obj + len extends past the last frame, this
44245+ check won't pass and the next frame will be 0,
44246+ causing us to bail out and correctly report
44247+ the copy as invalid
44248+ */
44249+ if (obj + len <= frame)
44250+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44251+ oldframe = frame;
44252+ frame = *(const void * const *)frame;
44253+ }
44254+ return -1;
44255+#else
44256+ return 1;
44257+#endif
44258+}
44259+
44260+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44261+{
44262+ if (current->signal->curr_ip)
44263+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44264+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44265+ else
44266+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44267+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44268+ dump_stack();
44269+ gr_handle_kernel_exploit();
44270+ do_group_exit(SIGKILL);
44271+}
44272+#endif
44273+
44274+void check_object_size(const void *ptr, unsigned long n, bool to)
44275+{
44276+
44277+#ifdef CONFIG_PAX_USERCOPY
44278+ const char *type;
44279+
44280+ if (!n)
44281+ return;
44282+
44283+ type = check_heap_object(ptr, n, to);
44284+ if (!type) {
44285+ if (check_stack_object(ptr, n) != -1)
44286+ return;
44287+ type = "<process stack>";
44288+ }
44289+
44290+ pax_report_usercopy(ptr, n, to, type);
44291+#endif
44292+
44293+}
44294+EXPORT_SYMBOL(check_object_size);
44295+
44296+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44297+void pax_track_stack(void)
44298+{
44299+ unsigned long sp = (unsigned long)&sp;
44300+ if (sp < current_thread_info()->lowest_stack &&
44301+ sp > (unsigned long)task_stack_page(current))
44302+ current_thread_info()->lowest_stack = sp;
44303+}
44304+EXPORT_SYMBOL(pax_track_stack);
44305+#endif
44306+
44307+#ifdef CONFIG_PAX_SIZE_OVERFLOW
44308+void report_size_overflow(const char *file, unsigned int line, const char *func)
44309+{
44310+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44311+ dump_stack();
44312+ do_group_exit(SIGKILL);
44313+}
44314+EXPORT_SYMBOL(report_size_overflow);
44315+#endif
44316+
44317 static int zap_process(struct task_struct *start, int exit_code)
44318 {
44319 struct task_struct *t;
44320@@ -1980,17 +2356,17 @@ static void coredump_finish(struct mm_struct *mm)
44321 void set_dumpable(struct mm_struct *mm, int value)
44322 {
44323 switch (value) {
44324- case 0:
44325+ case SUID_DUMPABLE_DISABLED:
44326 clear_bit(MMF_DUMPABLE, &mm->flags);
44327 smp_wmb();
44328 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44329 break;
44330- case 1:
44331+ case SUID_DUMPABLE_ENABLED:
44332 set_bit(MMF_DUMPABLE, &mm->flags);
44333 smp_wmb();
44334 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44335 break;
44336- case 2:
44337+ case SUID_DUMPABLE_SAFE:
44338 set_bit(MMF_DUMP_SECURELY, &mm->flags);
44339 smp_wmb();
44340 set_bit(MMF_DUMPABLE, &mm->flags);
44341@@ -2003,7 +2379,7 @@ static int __get_dumpable(unsigned long mm_flags)
44342 int ret;
44343
44344 ret = mm_flags & MMF_DUMPABLE_MASK;
44345- return (ret >= 2) ? 2 : ret;
44346+ return (ret > SUID_DUMPABLE_ENABLED) ? SUID_DUMPABLE_SAFE : ret;
44347 }
44348
44349 int get_dumpable(struct mm_struct *mm)
44350@@ -2018,17 +2394,17 @@ static void wait_for_dump_helpers(struct file *file)
44351 pipe = file->f_path.dentry->d_inode->i_pipe;
44352
44353 pipe_lock(pipe);
44354- pipe->readers++;
44355- pipe->writers--;
44356+ atomic_inc(&pipe->readers);
44357+ atomic_dec(&pipe->writers);
44358
44359- while ((pipe->readers > 1) && (!signal_pending(current))) {
44360+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44361 wake_up_interruptible_sync(&pipe->wait);
44362 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44363 pipe_wait(pipe);
44364 }
44365
44366- pipe->readers--;
44367- pipe->writers++;
44368+ atomic_dec(&pipe->readers);
44369+ atomic_inc(&pipe->writers);
44370 pipe_unlock(pipe);
44371
44372 }
44373@@ -2089,7 +2465,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44374 int retval = 0;
44375 int flag = 0;
44376 int ispipe;
44377- static atomic_t core_dump_count = ATOMIC_INIT(0);
44378+ bool need_nonrelative = false;
44379+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44380 struct coredump_params cprm = {
44381 .signr = signr,
44382 .regs = regs,
44383@@ -2104,6 +2481,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44384
44385 audit_core_dumps(signr);
44386
44387+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44388+ gr_handle_brute_attach(current, cprm.mm_flags);
44389+
44390 binfmt = mm->binfmt;
44391 if (!binfmt || !binfmt->core_dump)
44392 goto fail;
44393@@ -2114,14 +2494,16 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44394 if (!cred)
44395 goto fail;
44396 /*
44397- * We cannot trust fsuid as being the "true" uid of the
44398- * process nor do we know its entire history. We only know it
44399- * was tainted so we dump it as root in mode 2.
44400+ * We cannot trust fsuid as being the "true" uid of the process
44401+ * nor do we know its entire history. We only know it was tainted
44402+ * so we dump it as root in mode 2, and only into a controlled
44403+ * environment (pipe handler or fully qualified path).
44404 */
44405- if (__get_dumpable(cprm.mm_flags) == 2) {
44406+ if (__get_dumpable(cprm.mm_flags) == SUID_DUMPABLE_SAFE) {
44407 /* Setuid core dump mode */
44408 flag = O_EXCL; /* Stop rewrite attacks */
44409 cred->fsuid = 0; /* Dump root private */
44410+ need_nonrelative = true;
44411 }
44412
44413 retval = coredump_wait(exit_code, &core_state);
44414@@ -2171,7 +2553,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44415 }
44416 cprm.limit = RLIM_INFINITY;
44417
44418- dump_count = atomic_inc_return(&core_dump_count);
44419+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
44420 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44421 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44422 task_tgid_vnr(current), current->comm);
44423@@ -2198,9 +2580,19 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44424 } else {
44425 struct inode *inode;
44426
44427+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44428+
44429 if (cprm.limit < binfmt->min_coredump)
44430 goto fail_unlock;
44431
44432+ if (need_nonrelative && cn.corename[0] != '/') {
44433+ printk(KERN_WARNING "Pid %d(%s) can only dump core "\
44434+ "to fully qualified path!\n",
44435+ task_tgid_vnr(current), current->comm);
44436+ printk(KERN_WARNING "Skipping core dump\n");
44437+ goto fail_unlock;
44438+ }
44439+
44440 cprm.file = filp_open(cn.corename,
44441 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
44442 0600);
44443@@ -2241,7 +2633,7 @@ close_fail:
44444 filp_close(cprm.file, NULL);
44445 fail_dropcount:
44446 if (ispipe)
44447- atomic_dec(&core_dump_count);
44448+ atomic_dec_unchecked(&core_dump_count);
44449 fail_unlock:
44450 kfree(cn.corename);
44451 fail_corename:
44452@@ -2260,7 +2652,7 @@ fail:
44453 */
44454 int dump_write(struct file *file, const void *addr, int nr)
44455 {
44456- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44457+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44458 }
44459 EXPORT_SYMBOL(dump_write);
44460
44461diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44462index a8cbe1b..fed04cb 100644
44463--- a/fs/ext2/balloc.c
44464+++ b/fs/ext2/balloc.c
44465@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44466
44467 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44468 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44469- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44470+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44471 sbi->s_resuid != current_fsuid() &&
44472 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44473 return 0;
44474diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44475index baac1b1..1499b62 100644
44476--- a/fs/ext3/balloc.c
44477+++ b/fs/ext3/balloc.c
44478@@ -1438,9 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44479
44480 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44481 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44482- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44483+ if (free_blocks < root_blocks + 1 &&
44484 !use_reservation && sbi->s_resuid != current_fsuid() &&
44485- (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44486+ (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
44487+ !capable_nolog(CAP_SYS_RESOURCE)) {
44488 return 0;
44489 }
44490 return 1;
44491diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44492index 8da837b..ed3835b 100644
44493--- a/fs/ext4/balloc.c
44494+++ b/fs/ext4/balloc.c
44495@@ -463,8 +463,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
44496 /* Hm, nope. Are (enough) root reserved clusters available? */
44497 if (sbi->s_resuid == current_fsuid() ||
44498 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44499- capable(CAP_SYS_RESOURCE) ||
44500- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44501+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44502+ capable_nolog(CAP_SYS_RESOURCE)) {
44503
44504 if (free_clusters >= (nclusters + dirty_clusters))
44505 return 1;
44506diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44507index 0e01e90..ae2bd5e 100644
44508--- a/fs/ext4/ext4.h
44509+++ b/fs/ext4/ext4.h
44510@@ -1225,19 +1225,19 @@ struct ext4_sb_info {
44511 unsigned long s_mb_last_start;
44512
44513 /* stats for buddy allocator */
44514- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44515- atomic_t s_bal_success; /* we found long enough chunks */
44516- atomic_t s_bal_allocated; /* in blocks */
44517- atomic_t s_bal_ex_scanned; /* total extents scanned */
44518- atomic_t s_bal_goals; /* goal hits */
44519- atomic_t s_bal_breaks; /* too long searches */
44520- atomic_t s_bal_2orders; /* 2^order hits */
44521+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44522+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44523+ atomic_unchecked_t s_bal_allocated; /* in blocks */
44524+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44525+ atomic_unchecked_t s_bal_goals; /* goal hits */
44526+ atomic_unchecked_t s_bal_breaks; /* too long searches */
44527+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44528 spinlock_t s_bal_lock;
44529 unsigned long s_mb_buddies_generated;
44530 unsigned long long s_mb_generation_time;
44531- atomic_t s_mb_lost_chunks;
44532- atomic_t s_mb_preallocated;
44533- atomic_t s_mb_discarded;
44534+ atomic_unchecked_t s_mb_lost_chunks;
44535+ atomic_unchecked_t s_mb_preallocated;
44536+ atomic_unchecked_t s_mb_discarded;
44537 atomic_t s_lock_busy;
44538
44539 /* locality groups */
44540diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44541index 6b0a57e..1955a44 100644
44542--- a/fs/ext4/mballoc.c
44543+++ b/fs/ext4/mballoc.c
44544@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44545 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44546
44547 if (EXT4_SB(sb)->s_mb_stats)
44548- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44549+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44550
44551 break;
44552 }
44553@@ -2041,7 +2041,7 @@ repeat:
44554 ac->ac_status = AC_STATUS_CONTINUE;
44555 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44556 cr = 3;
44557- atomic_inc(&sbi->s_mb_lost_chunks);
44558+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44559 goto repeat;
44560 }
44561 }
44562@@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
44563 if (sbi->s_mb_stats) {
44564 ext4_msg(sb, KERN_INFO,
44565 "mballoc: %u blocks %u reqs (%u success)",
44566- atomic_read(&sbi->s_bal_allocated),
44567- atomic_read(&sbi->s_bal_reqs),
44568- atomic_read(&sbi->s_bal_success));
44569+ atomic_read_unchecked(&sbi->s_bal_allocated),
44570+ atomic_read_unchecked(&sbi->s_bal_reqs),
44571+ atomic_read_unchecked(&sbi->s_bal_success));
44572 ext4_msg(sb, KERN_INFO,
44573 "mballoc: %u extents scanned, %u goal hits, "
44574 "%u 2^N hits, %u breaks, %u lost",
44575- atomic_read(&sbi->s_bal_ex_scanned),
44576- atomic_read(&sbi->s_bal_goals),
44577- atomic_read(&sbi->s_bal_2orders),
44578- atomic_read(&sbi->s_bal_breaks),
44579- atomic_read(&sbi->s_mb_lost_chunks));
44580+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44581+ atomic_read_unchecked(&sbi->s_bal_goals),
44582+ atomic_read_unchecked(&sbi->s_bal_2orders),
44583+ atomic_read_unchecked(&sbi->s_bal_breaks),
44584+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44585 ext4_msg(sb, KERN_INFO,
44586 "mballoc: %lu generated and it took %Lu",
44587 sbi->s_mb_buddies_generated,
44588 sbi->s_mb_generation_time);
44589 ext4_msg(sb, KERN_INFO,
44590 "mballoc: %u preallocated, %u discarded",
44591- atomic_read(&sbi->s_mb_preallocated),
44592- atomic_read(&sbi->s_mb_discarded));
44593+ atomic_read_unchecked(&sbi->s_mb_preallocated),
44594+ atomic_read_unchecked(&sbi->s_mb_discarded));
44595 }
44596
44597 free_percpu(sbi->s_locality_groups);
44598@@ -3045,16 +3045,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44599 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44600
44601 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44602- atomic_inc(&sbi->s_bal_reqs);
44603- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44604+ atomic_inc_unchecked(&sbi->s_bal_reqs);
44605+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44606 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44607- atomic_inc(&sbi->s_bal_success);
44608- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44609+ atomic_inc_unchecked(&sbi->s_bal_success);
44610+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44611 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44612 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44613- atomic_inc(&sbi->s_bal_goals);
44614+ atomic_inc_unchecked(&sbi->s_bal_goals);
44615 if (ac->ac_found > sbi->s_mb_max_to_scan)
44616- atomic_inc(&sbi->s_bal_breaks);
44617+ atomic_inc_unchecked(&sbi->s_bal_breaks);
44618 }
44619
44620 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44621@@ -3458,7 +3458,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44622 trace_ext4_mb_new_inode_pa(ac, pa);
44623
44624 ext4_mb_use_inode_pa(ac, pa);
44625- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
44626+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
44627
44628 ei = EXT4_I(ac->ac_inode);
44629 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44630@@ -3518,7 +3518,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44631 trace_ext4_mb_new_group_pa(ac, pa);
44632
44633 ext4_mb_use_group_pa(ac, pa);
44634- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44635+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44636
44637 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44638 lg = ac->ac_lg;
44639@@ -3607,7 +3607,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44640 * from the bitmap and continue.
44641 */
44642 }
44643- atomic_add(free, &sbi->s_mb_discarded);
44644+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
44645
44646 return err;
44647 }
44648@@ -3625,7 +3625,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44649 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44650 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44651 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44652- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44653+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44654 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44655
44656 return 0;
44657diff --git a/fs/fcntl.c b/fs/fcntl.c
44658index 75e7c1f..1eb3e4d 100644
44659--- a/fs/fcntl.c
44660+++ b/fs/fcntl.c
44661@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44662 if (err)
44663 return err;
44664
44665+ if (gr_handle_chroot_fowner(pid, type))
44666+ return -ENOENT;
44667+ if (gr_check_protected_task_fowner(pid, type))
44668+ return -EACCES;
44669+
44670 f_modown(filp, pid, type, force);
44671 return 0;
44672 }
44673@@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44674
44675 static int f_setown_ex(struct file *filp, unsigned long arg)
44676 {
44677- struct f_owner_ex * __user owner_p = (void * __user)arg;
44678+ struct f_owner_ex __user *owner_p = (void __user *)arg;
44679 struct f_owner_ex owner;
44680 struct pid *pid;
44681 int type;
44682@@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44683
44684 static int f_getown_ex(struct file *filp, unsigned long arg)
44685 {
44686- struct f_owner_ex * __user owner_p = (void * __user)arg;
44687+ struct f_owner_ex __user *owner_p = (void __user *)arg;
44688 struct f_owner_ex owner;
44689 int ret = 0;
44690
44691@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44692 switch (cmd) {
44693 case F_DUPFD:
44694 case F_DUPFD_CLOEXEC:
44695+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44696 if (arg >= rlimit(RLIMIT_NOFILE))
44697 break;
44698 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44699diff --git a/fs/fifo.c b/fs/fifo.c
44700index cf6f434..3d7942c 100644
44701--- a/fs/fifo.c
44702+++ b/fs/fifo.c
44703@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44704 */
44705 filp->f_op = &read_pipefifo_fops;
44706 pipe->r_counter++;
44707- if (pipe->readers++ == 0)
44708+ if (atomic_inc_return(&pipe->readers) == 1)
44709 wake_up_partner(inode);
44710
44711- if (!pipe->writers) {
44712+ if (!atomic_read(&pipe->writers)) {
44713 if ((filp->f_flags & O_NONBLOCK)) {
44714 /* suppress POLLHUP until we have
44715 * seen a writer */
44716@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44717 * errno=ENXIO when there is no process reading the FIFO.
44718 */
44719 ret = -ENXIO;
44720- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44721+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44722 goto err;
44723
44724 filp->f_op = &write_pipefifo_fops;
44725 pipe->w_counter++;
44726- if (!pipe->writers++)
44727+ if (atomic_inc_return(&pipe->writers) == 1)
44728 wake_up_partner(inode);
44729
44730- if (!pipe->readers) {
44731+ if (!atomic_read(&pipe->readers)) {
44732 if (wait_for_partner(inode, &pipe->r_counter))
44733 goto err_wr;
44734 }
44735@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44736 */
44737 filp->f_op = &rdwr_pipefifo_fops;
44738
44739- pipe->readers++;
44740- pipe->writers++;
44741+ atomic_inc(&pipe->readers);
44742+ atomic_inc(&pipe->writers);
44743 pipe->r_counter++;
44744 pipe->w_counter++;
44745- if (pipe->readers == 1 || pipe->writers == 1)
44746+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
44747 wake_up_partner(inode);
44748 break;
44749
44750@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
44751 return 0;
44752
44753 err_rd:
44754- if (!--pipe->readers)
44755+ if (atomic_dec_and_test(&pipe->readers))
44756 wake_up_interruptible(&pipe->wait);
44757 ret = -ERESTARTSYS;
44758 goto err;
44759
44760 err_wr:
44761- if (!--pipe->writers)
44762+ if (atomic_dec_and_test(&pipe->writers))
44763 wake_up_interruptible(&pipe->wait);
44764 ret = -ERESTARTSYS;
44765 goto err;
44766
44767 err:
44768- if (!pipe->readers && !pipe->writers)
44769+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
44770 free_pipe_info(inode);
44771
44772 err_nocleanup:
44773diff --git a/fs/file.c b/fs/file.c
44774index ba3f605..fade102 100644
44775--- a/fs/file.c
44776+++ b/fs/file.c
44777@@ -15,6 +15,7 @@
44778 #include <linux/slab.h>
44779 #include <linux/vmalloc.h>
44780 #include <linux/file.h>
44781+#include <linux/security.h>
44782 #include <linux/fdtable.h>
44783 #include <linux/bitops.h>
44784 #include <linux/interrupt.h>
44785@@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
44786 * N.B. For clone tasks sharing a files structure, this test
44787 * will limit the total number of files that can be opened.
44788 */
44789+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
44790 if (nr >= rlimit(RLIMIT_NOFILE))
44791 return -EMFILE;
44792
44793diff --git a/fs/filesystems.c b/fs/filesystems.c
44794index 96f2428..f5eeb8e 100644
44795--- a/fs/filesystems.c
44796+++ b/fs/filesystems.c
44797@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
44798 int len = dot ? dot - name : strlen(name);
44799
44800 fs = __get_fs_type(name, len);
44801+
44802+#ifdef CONFIG_GRKERNSEC_MODHARDEN
44803+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
44804+#else
44805 if (!fs && (request_module("%.*s", len, name) == 0))
44806+#endif
44807 fs = __get_fs_type(name, len);
44808
44809 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
44810diff --git a/fs/fs_struct.c b/fs/fs_struct.c
44811index e159e68..e7d2a6f 100644
44812--- a/fs/fs_struct.c
44813+++ b/fs/fs_struct.c
44814@@ -4,6 +4,7 @@
44815 #include <linux/path.h>
44816 #include <linux/slab.h>
44817 #include <linux/fs_struct.h>
44818+#include <linux/grsecurity.h>
44819 #include "internal.h"
44820
44821 static inline void path_get_longterm(struct path *path)
44822@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
44823 write_seqcount_begin(&fs->seq);
44824 old_root = fs->root;
44825 fs->root = *path;
44826+ gr_set_chroot_entries(current, path);
44827 write_seqcount_end(&fs->seq);
44828 spin_unlock(&fs->lock);
44829 if (old_root.dentry)
44830@@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
44831 return 1;
44832 }
44833
44834+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
44835+{
44836+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
44837+ return 0;
44838+ *p = *new;
44839+
44840+ gr_set_chroot_entries(task, new);
44841+
44842+ return 1;
44843+}
44844+
44845 void chroot_fs_refs(struct path *old_root, struct path *new_root)
44846 {
44847 struct task_struct *g, *p;
44848@@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
44849 int hits = 0;
44850 spin_lock(&fs->lock);
44851 write_seqcount_begin(&fs->seq);
44852- hits += replace_path(&fs->root, old_root, new_root);
44853+ hits += replace_root_path(p, &fs->root, old_root, new_root);
44854 hits += replace_path(&fs->pwd, old_root, new_root);
44855 write_seqcount_end(&fs->seq);
44856 while (hits--) {
44857@@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
44858 task_lock(tsk);
44859 spin_lock(&fs->lock);
44860 tsk->fs = NULL;
44861- kill = !--fs->users;
44862+ gr_clear_chroot_entries(tsk);
44863+ kill = !atomic_dec_return(&fs->users);
44864 spin_unlock(&fs->lock);
44865 task_unlock(tsk);
44866 if (kill)
44867@@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44868 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
44869 /* We don't need to lock fs - think why ;-) */
44870 if (fs) {
44871- fs->users = 1;
44872+ atomic_set(&fs->users, 1);
44873 fs->in_exec = 0;
44874 spin_lock_init(&fs->lock);
44875 seqcount_init(&fs->seq);
44876@@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44877 spin_lock(&old->lock);
44878 fs->root = old->root;
44879 path_get_longterm(&fs->root);
44880+ /* instead of calling gr_set_chroot_entries here,
44881+ we call it from every caller of this function
44882+ */
44883 fs->pwd = old->pwd;
44884 path_get_longterm(&fs->pwd);
44885 spin_unlock(&old->lock);
44886@@ -151,8 +168,9 @@ int unshare_fs_struct(void)
44887
44888 task_lock(current);
44889 spin_lock(&fs->lock);
44890- kill = !--fs->users;
44891+ kill = !atomic_dec_return(&fs->users);
44892 current->fs = new_fs;
44893+ gr_set_chroot_entries(current, &new_fs->root);
44894 spin_unlock(&fs->lock);
44895 task_unlock(current);
44896
44897@@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
44898
44899 int current_umask(void)
44900 {
44901- return current->fs->umask;
44902+ return current->fs->umask | gr_acl_umask();
44903 }
44904 EXPORT_SYMBOL(current_umask);
44905
44906 /* to be mentioned only in INIT_TASK */
44907 struct fs_struct init_fs = {
44908- .users = 1,
44909+ .users = ATOMIC_INIT(1),
44910 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
44911 .seq = SEQCNT_ZERO,
44912 .umask = 0022,
44913@@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
44914 task_lock(current);
44915
44916 spin_lock(&init_fs.lock);
44917- init_fs.users++;
44918+ atomic_inc(&init_fs.users);
44919 spin_unlock(&init_fs.lock);
44920
44921 spin_lock(&fs->lock);
44922 current->fs = &init_fs;
44923- kill = !--fs->users;
44924+ gr_set_chroot_entries(current, &current->fs->root);
44925+ kill = !atomic_dec_return(&fs->users);
44926 spin_unlock(&fs->lock);
44927
44928 task_unlock(current);
44929diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
44930index 9905350..02eaec4 100644
44931--- a/fs/fscache/cookie.c
44932+++ b/fs/fscache/cookie.c
44933@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
44934 parent ? (char *) parent->def->name : "<no-parent>",
44935 def->name, netfs_data);
44936
44937- fscache_stat(&fscache_n_acquires);
44938+ fscache_stat_unchecked(&fscache_n_acquires);
44939
44940 /* if there's no parent cookie, then we don't create one here either */
44941 if (!parent) {
44942- fscache_stat(&fscache_n_acquires_null);
44943+ fscache_stat_unchecked(&fscache_n_acquires_null);
44944 _leave(" [no parent]");
44945 return NULL;
44946 }
44947@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
44948 /* allocate and initialise a cookie */
44949 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
44950 if (!cookie) {
44951- fscache_stat(&fscache_n_acquires_oom);
44952+ fscache_stat_unchecked(&fscache_n_acquires_oom);
44953 _leave(" [ENOMEM]");
44954 return NULL;
44955 }
44956@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44957
44958 switch (cookie->def->type) {
44959 case FSCACHE_COOKIE_TYPE_INDEX:
44960- fscache_stat(&fscache_n_cookie_index);
44961+ fscache_stat_unchecked(&fscache_n_cookie_index);
44962 break;
44963 case FSCACHE_COOKIE_TYPE_DATAFILE:
44964- fscache_stat(&fscache_n_cookie_data);
44965+ fscache_stat_unchecked(&fscache_n_cookie_data);
44966 break;
44967 default:
44968- fscache_stat(&fscache_n_cookie_special);
44969+ fscache_stat_unchecked(&fscache_n_cookie_special);
44970 break;
44971 }
44972
44973@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44974 if (fscache_acquire_non_index_cookie(cookie) < 0) {
44975 atomic_dec(&parent->n_children);
44976 __fscache_cookie_put(cookie);
44977- fscache_stat(&fscache_n_acquires_nobufs);
44978+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
44979 _leave(" = NULL");
44980 return NULL;
44981 }
44982 }
44983
44984- fscache_stat(&fscache_n_acquires_ok);
44985+ fscache_stat_unchecked(&fscache_n_acquires_ok);
44986 _leave(" = %p", cookie);
44987 return cookie;
44988 }
44989@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
44990 cache = fscache_select_cache_for_object(cookie->parent);
44991 if (!cache) {
44992 up_read(&fscache_addremove_sem);
44993- fscache_stat(&fscache_n_acquires_no_cache);
44994+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
44995 _leave(" = -ENOMEDIUM [no cache]");
44996 return -ENOMEDIUM;
44997 }
44998@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
44999 object = cache->ops->alloc_object(cache, cookie);
45000 fscache_stat_d(&fscache_n_cop_alloc_object);
45001 if (IS_ERR(object)) {
45002- fscache_stat(&fscache_n_object_no_alloc);
45003+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
45004 ret = PTR_ERR(object);
45005 goto error;
45006 }
45007
45008- fscache_stat(&fscache_n_object_alloc);
45009+ fscache_stat_unchecked(&fscache_n_object_alloc);
45010
45011 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45012
45013@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45014 struct fscache_object *object;
45015 struct hlist_node *_p;
45016
45017- fscache_stat(&fscache_n_updates);
45018+ fscache_stat_unchecked(&fscache_n_updates);
45019
45020 if (!cookie) {
45021- fscache_stat(&fscache_n_updates_null);
45022+ fscache_stat_unchecked(&fscache_n_updates_null);
45023 _leave(" [no cookie]");
45024 return;
45025 }
45026@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45027 struct fscache_object *object;
45028 unsigned long event;
45029
45030- fscache_stat(&fscache_n_relinquishes);
45031+ fscache_stat_unchecked(&fscache_n_relinquishes);
45032 if (retire)
45033- fscache_stat(&fscache_n_relinquishes_retire);
45034+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45035
45036 if (!cookie) {
45037- fscache_stat(&fscache_n_relinquishes_null);
45038+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
45039 _leave(" [no cookie]");
45040 return;
45041 }
45042@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45043
45044 /* wait for the cookie to finish being instantiated (or to fail) */
45045 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45046- fscache_stat(&fscache_n_relinquishes_waitcrt);
45047+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45048 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45049 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45050 }
45051diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45052index f6aad48..88dcf26 100644
45053--- a/fs/fscache/internal.h
45054+++ b/fs/fscache/internal.h
45055@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45056 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45057 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45058
45059-extern atomic_t fscache_n_op_pend;
45060-extern atomic_t fscache_n_op_run;
45061-extern atomic_t fscache_n_op_enqueue;
45062-extern atomic_t fscache_n_op_deferred_release;
45063-extern atomic_t fscache_n_op_release;
45064-extern atomic_t fscache_n_op_gc;
45065-extern atomic_t fscache_n_op_cancelled;
45066-extern atomic_t fscache_n_op_rejected;
45067+extern atomic_unchecked_t fscache_n_op_pend;
45068+extern atomic_unchecked_t fscache_n_op_run;
45069+extern atomic_unchecked_t fscache_n_op_enqueue;
45070+extern atomic_unchecked_t fscache_n_op_deferred_release;
45071+extern atomic_unchecked_t fscache_n_op_release;
45072+extern atomic_unchecked_t fscache_n_op_gc;
45073+extern atomic_unchecked_t fscache_n_op_cancelled;
45074+extern atomic_unchecked_t fscache_n_op_rejected;
45075
45076-extern atomic_t fscache_n_attr_changed;
45077-extern atomic_t fscache_n_attr_changed_ok;
45078-extern atomic_t fscache_n_attr_changed_nobufs;
45079-extern atomic_t fscache_n_attr_changed_nomem;
45080-extern atomic_t fscache_n_attr_changed_calls;
45081+extern atomic_unchecked_t fscache_n_attr_changed;
45082+extern atomic_unchecked_t fscache_n_attr_changed_ok;
45083+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45084+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45085+extern atomic_unchecked_t fscache_n_attr_changed_calls;
45086
45087-extern atomic_t fscache_n_allocs;
45088-extern atomic_t fscache_n_allocs_ok;
45089-extern atomic_t fscache_n_allocs_wait;
45090-extern atomic_t fscache_n_allocs_nobufs;
45091-extern atomic_t fscache_n_allocs_intr;
45092-extern atomic_t fscache_n_allocs_object_dead;
45093-extern atomic_t fscache_n_alloc_ops;
45094-extern atomic_t fscache_n_alloc_op_waits;
45095+extern atomic_unchecked_t fscache_n_allocs;
45096+extern atomic_unchecked_t fscache_n_allocs_ok;
45097+extern atomic_unchecked_t fscache_n_allocs_wait;
45098+extern atomic_unchecked_t fscache_n_allocs_nobufs;
45099+extern atomic_unchecked_t fscache_n_allocs_intr;
45100+extern atomic_unchecked_t fscache_n_allocs_object_dead;
45101+extern atomic_unchecked_t fscache_n_alloc_ops;
45102+extern atomic_unchecked_t fscache_n_alloc_op_waits;
45103
45104-extern atomic_t fscache_n_retrievals;
45105-extern atomic_t fscache_n_retrievals_ok;
45106-extern atomic_t fscache_n_retrievals_wait;
45107-extern atomic_t fscache_n_retrievals_nodata;
45108-extern atomic_t fscache_n_retrievals_nobufs;
45109-extern atomic_t fscache_n_retrievals_intr;
45110-extern atomic_t fscache_n_retrievals_nomem;
45111-extern atomic_t fscache_n_retrievals_object_dead;
45112-extern atomic_t fscache_n_retrieval_ops;
45113-extern atomic_t fscache_n_retrieval_op_waits;
45114+extern atomic_unchecked_t fscache_n_retrievals;
45115+extern atomic_unchecked_t fscache_n_retrievals_ok;
45116+extern atomic_unchecked_t fscache_n_retrievals_wait;
45117+extern atomic_unchecked_t fscache_n_retrievals_nodata;
45118+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45119+extern atomic_unchecked_t fscache_n_retrievals_intr;
45120+extern atomic_unchecked_t fscache_n_retrievals_nomem;
45121+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45122+extern atomic_unchecked_t fscache_n_retrieval_ops;
45123+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45124
45125-extern atomic_t fscache_n_stores;
45126-extern atomic_t fscache_n_stores_ok;
45127-extern atomic_t fscache_n_stores_again;
45128-extern atomic_t fscache_n_stores_nobufs;
45129-extern atomic_t fscache_n_stores_oom;
45130-extern atomic_t fscache_n_store_ops;
45131-extern atomic_t fscache_n_store_calls;
45132-extern atomic_t fscache_n_store_pages;
45133-extern atomic_t fscache_n_store_radix_deletes;
45134-extern atomic_t fscache_n_store_pages_over_limit;
45135+extern atomic_unchecked_t fscache_n_stores;
45136+extern atomic_unchecked_t fscache_n_stores_ok;
45137+extern atomic_unchecked_t fscache_n_stores_again;
45138+extern atomic_unchecked_t fscache_n_stores_nobufs;
45139+extern atomic_unchecked_t fscache_n_stores_oom;
45140+extern atomic_unchecked_t fscache_n_store_ops;
45141+extern atomic_unchecked_t fscache_n_store_calls;
45142+extern atomic_unchecked_t fscache_n_store_pages;
45143+extern atomic_unchecked_t fscache_n_store_radix_deletes;
45144+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45145
45146-extern atomic_t fscache_n_store_vmscan_not_storing;
45147-extern atomic_t fscache_n_store_vmscan_gone;
45148-extern atomic_t fscache_n_store_vmscan_busy;
45149-extern atomic_t fscache_n_store_vmscan_cancelled;
45150+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45151+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45152+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45153+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45154
45155-extern atomic_t fscache_n_marks;
45156-extern atomic_t fscache_n_uncaches;
45157+extern atomic_unchecked_t fscache_n_marks;
45158+extern atomic_unchecked_t fscache_n_uncaches;
45159
45160-extern atomic_t fscache_n_acquires;
45161-extern atomic_t fscache_n_acquires_null;
45162-extern atomic_t fscache_n_acquires_no_cache;
45163-extern atomic_t fscache_n_acquires_ok;
45164-extern atomic_t fscache_n_acquires_nobufs;
45165-extern atomic_t fscache_n_acquires_oom;
45166+extern atomic_unchecked_t fscache_n_acquires;
45167+extern atomic_unchecked_t fscache_n_acquires_null;
45168+extern atomic_unchecked_t fscache_n_acquires_no_cache;
45169+extern atomic_unchecked_t fscache_n_acquires_ok;
45170+extern atomic_unchecked_t fscache_n_acquires_nobufs;
45171+extern atomic_unchecked_t fscache_n_acquires_oom;
45172
45173-extern atomic_t fscache_n_updates;
45174-extern atomic_t fscache_n_updates_null;
45175-extern atomic_t fscache_n_updates_run;
45176+extern atomic_unchecked_t fscache_n_updates;
45177+extern atomic_unchecked_t fscache_n_updates_null;
45178+extern atomic_unchecked_t fscache_n_updates_run;
45179
45180-extern atomic_t fscache_n_relinquishes;
45181-extern atomic_t fscache_n_relinquishes_null;
45182-extern atomic_t fscache_n_relinquishes_waitcrt;
45183-extern atomic_t fscache_n_relinquishes_retire;
45184+extern atomic_unchecked_t fscache_n_relinquishes;
45185+extern atomic_unchecked_t fscache_n_relinquishes_null;
45186+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45187+extern atomic_unchecked_t fscache_n_relinquishes_retire;
45188
45189-extern atomic_t fscache_n_cookie_index;
45190-extern atomic_t fscache_n_cookie_data;
45191-extern atomic_t fscache_n_cookie_special;
45192+extern atomic_unchecked_t fscache_n_cookie_index;
45193+extern atomic_unchecked_t fscache_n_cookie_data;
45194+extern atomic_unchecked_t fscache_n_cookie_special;
45195
45196-extern atomic_t fscache_n_object_alloc;
45197-extern atomic_t fscache_n_object_no_alloc;
45198-extern atomic_t fscache_n_object_lookups;
45199-extern atomic_t fscache_n_object_lookups_negative;
45200-extern atomic_t fscache_n_object_lookups_positive;
45201-extern atomic_t fscache_n_object_lookups_timed_out;
45202-extern atomic_t fscache_n_object_created;
45203-extern atomic_t fscache_n_object_avail;
45204-extern atomic_t fscache_n_object_dead;
45205+extern atomic_unchecked_t fscache_n_object_alloc;
45206+extern atomic_unchecked_t fscache_n_object_no_alloc;
45207+extern atomic_unchecked_t fscache_n_object_lookups;
45208+extern atomic_unchecked_t fscache_n_object_lookups_negative;
45209+extern atomic_unchecked_t fscache_n_object_lookups_positive;
45210+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45211+extern atomic_unchecked_t fscache_n_object_created;
45212+extern atomic_unchecked_t fscache_n_object_avail;
45213+extern atomic_unchecked_t fscache_n_object_dead;
45214
45215-extern atomic_t fscache_n_checkaux_none;
45216-extern atomic_t fscache_n_checkaux_okay;
45217-extern atomic_t fscache_n_checkaux_update;
45218-extern atomic_t fscache_n_checkaux_obsolete;
45219+extern atomic_unchecked_t fscache_n_checkaux_none;
45220+extern atomic_unchecked_t fscache_n_checkaux_okay;
45221+extern atomic_unchecked_t fscache_n_checkaux_update;
45222+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45223
45224 extern atomic_t fscache_n_cop_alloc_object;
45225 extern atomic_t fscache_n_cop_lookup_object;
45226@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45227 atomic_inc(stat);
45228 }
45229
45230+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45231+{
45232+ atomic_inc_unchecked(stat);
45233+}
45234+
45235 static inline void fscache_stat_d(atomic_t *stat)
45236 {
45237 atomic_dec(stat);
45238@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45239
45240 #define __fscache_stat(stat) (NULL)
45241 #define fscache_stat(stat) do {} while (0)
45242+#define fscache_stat_unchecked(stat) do {} while (0)
45243 #define fscache_stat_d(stat) do {} while (0)
45244 #endif
45245
45246diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45247index b6b897c..0ffff9c 100644
45248--- a/fs/fscache/object.c
45249+++ b/fs/fscache/object.c
45250@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45251 /* update the object metadata on disk */
45252 case FSCACHE_OBJECT_UPDATING:
45253 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45254- fscache_stat(&fscache_n_updates_run);
45255+ fscache_stat_unchecked(&fscache_n_updates_run);
45256 fscache_stat(&fscache_n_cop_update_object);
45257 object->cache->ops->update_object(object);
45258 fscache_stat_d(&fscache_n_cop_update_object);
45259@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45260 spin_lock(&object->lock);
45261 object->state = FSCACHE_OBJECT_DEAD;
45262 spin_unlock(&object->lock);
45263- fscache_stat(&fscache_n_object_dead);
45264+ fscache_stat_unchecked(&fscache_n_object_dead);
45265 goto terminal_transit;
45266
45267 /* handle the parent cache of this object being withdrawn from
45268@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45269 spin_lock(&object->lock);
45270 object->state = FSCACHE_OBJECT_DEAD;
45271 spin_unlock(&object->lock);
45272- fscache_stat(&fscache_n_object_dead);
45273+ fscache_stat_unchecked(&fscache_n_object_dead);
45274 goto terminal_transit;
45275
45276 /* complain about the object being woken up once it is
45277@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45278 parent->cookie->def->name, cookie->def->name,
45279 object->cache->tag->name);
45280
45281- fscache_stat(&fscache_n_object_lookups);
45282+ fscache_stat_unchecked(&fscache_n_object_lookups);
45283 fscache_stat(&fscache_n_cop_lookup_object);
45284 ret = object->cache->ops->lookup_object(object);
45285 fscache_stat_d(&fscache_n_cop_lookup_object);
45286@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45287 if (ret == -ETIMEDOUT) {
45288 /* probably stuck behind another object, so move this one to
45289 * the back of the queue */
45290- fscache_stat(&fscache_n_object_lookups_timed_out);
45291+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45292 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45293 }
45294
45295@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45296
45297 spin_lock(&object->lock);
45298 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45299- fscache_stat(&fscache_n_object_lookups_negative);
45300+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45301
45302 /* transit here to allow write requests to begin stacking up
45303 * and read requests to begin returning ENODATA */
45304@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45305 * result, in which case there may be data available */
45306 spin_lock(&object->lock);
45307 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45308- fscache_stat(&fscache_n_object_lookups_positive);
45309+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45310
45311 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45312
45313@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45314 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45315 } else {
45316 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45317- fscache_stat(&fscache_n_object_created);
45318+ fscache_stat_unchecked(&fscache_n_object_created);
45319
45320 object->state = FSCACHE_OBJECT_AVAILABLE;
45321 spin_unlock(&object->lock);
45322@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45323 fscache_enqueue_dependents(object);
45324
45325 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45326- fscache_stat(&fscache_n_object_avail);
45327+ fscache_stat_unchecked(&fscache_n_object_avail);
45328
45329 _leave("");
45330 }
45331@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45332 enum fscache_checkaux result;
45333
45334 if (!object->cookie->def->check_aux) {
45335- fscache_stat(&fscache_n_checkaux_none);
45336+ fscache_stat_unchecked(&fscache_n_checkaux_none);
45337 return FSCACHE_CHECKAUX_OKAY;
45338 }
45339
45340@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45341 switch (result) {
45342 /* entry okay as is */
45343 case FSCACHE_CHECKAUX_OKAY:
45344- fscache_stat(&fscache_n_checkaux_okay);
45345+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
45346 break;
45347
45348 /* entry requires update */
45349 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45350- fscache_stat(&fscache_n_checkaux_update);
45351+ fscache_stat_unchecked(&fscache_n_checkaux_update);
45352 break;
45353
45354 /* entry requires deletion */
45355 case FSCACHE_CHECKAUX_OBSOLETE:
45356- fscache_stat(&fscache_n_checkaux_obsolete);
45357+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45358 break;
45359
45360 default:
45361diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45362index 30afdfa..2256596 100644
45363--- a/fs/fscache/operation.c
45364+++ b/fs/fscache/operation.c
45365@@ -17,7 +17,7 @@
45366 #include <linux/slab.h>
45367 #include "internal.h"
45368
45369-atomic_t fscache_op_debug_id;
45370+atomic_unchecked_t fscache_op_debug_id;
45371 EXPORT_SYMBOL(fscache_op_debug_id);
45372
45373 /**
45374@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45375 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45376 ASSERTCMP(atomic_read(&op->usage), >, 0);
45377
45378- fscache_stat(&fscache_n_op_enqueue);
45379+ fscache_stat_unchecked(&fscache_n_op_enqueue);
45380 switch (op->flags & FSCACHE_OP_TYPE) {
45381 case FSCACHE_OP_ASYNC:
45382 _debug("queue async");
45383@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45384 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45385 if (op->processor)
45386 fscache_enqueue_operation(op);
45387- fscache_stat(&fscache_n_op_run);
45388+ fscache_stat_unchecked(&fscache_n_op_run);
45389 }
45390
45391 /*
45392@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45393 if (object->n_ops > 1) {
45394 atomic_inc(&op->usage);
45395 list_add_tail(&op->pend_link, &object->pending_ops);
45396- fscache_stat(&fscache_n_op_pend);
45397+ fscache_stat_unchecked(&fscache_n_op_pend);
45398 } else if (!list_empty(&object->pending_ops)) {
45399 atomic_inc(&op->usage);
45400 list_add_tail(&op->pend_link, &object->pending_ops);
45401- fscache_stat(&fscache_n_op_pend);
45402+ fscache_stat_unchecked(&fscache_n_op_pend);
45403 fscache_start_operations(object);
45404 } else {
45405 ASSERTCMP(object->n_in_progress, ==, 0);
45406@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45407 object->n_exclusive++; /* reads and writes must wait */
45408 atomic_inc(&op->usage);
45409 list_add_tail(&op->pend_link, &object->pending_ops);
45410- fscache_stat(&fscache_n_op_pend);
45411+ fscache_stat_unchecked(&fscache_n_op_pend);
45412 ret = 0;
45413 } else {
45414 /* not allowed to submit ops in any other state */
45415@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45416 if (object->n_exclusive > 0) {
45417 atomic_inc(&op->usage);
45418 list_add_tail(&op->pend_link, &object->pending_ops);
45419- fscache_stat(&fscache_n_op_pend);
45420+ fscache_stat_unchecked(&fscache_n_op_pend);
45421 } else if (!list_empty(&object->pending_ops)) {
45422 atomic_inc(&op->usage);
45423 list_add_tail(&op->pend_link, &object->pending_ops);
45424- fscache_stat(&fscache_n_op_pend);
45425+ fscache_stat_unchecked(&fscache_n_op_pend);
45426 fscache_start_operations(object);
45427 } else {
45428 ASSERTCMP(object->n_exclusive, ==, 0);
45429@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45430 object->n_ops++;
45431 atomic_inc(&op->usage);
45432 list_add_tail(&op->pend_link, &object->pending_ops);
45433- fscache_stat(&fscache_n_op_pend);
45434+ fscache_stat_unchecked(&fscache_n_op_pend);
45435 ret = 0;
45436 } else if (object->state == FSCACHE_OBJECT_DYING ||
45437 object->state == FSCACHE_OBJECT_LC_DYING ||
45438 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45439- fscache_stat(&fscache_n_op_rejected);
45440+ fscache_stat_unchecked(&fscache_n_op_rejected);
45441 ret = -ENOBUFS;
45442 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45443 fscache_report_unexpected_submission(object, op, ostate);
45444@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45445
45446 ret = -EBUSY;
45447 if (!list_empty(&op->pend_link)) {
45448- fscache_stat(&fscache_n_op_cancelled);
45449+ fscache_stat_unchecked(&fscache_n_op_cancelled);
45450 list_del_init(&op->pend_link);
45451 object->n_ops--;
45452 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45453@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45454 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45455 BUG();
45456
45457- fscache_stat(&fscache_n_op_release);
45458+ fscache_stat_unchecked(&fscache_n_op_release);
45459
45460 if (op->release) {
45461 op->release(op);
45462@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45463 * lock, and defer it otherwise */
45464 if (!spin_trylock(&object->lock)) {
45465 _debug("defer put");
45466- fscache_stat(&fscache_n_op_deferred_release);
45467+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
45468
45469 cache = object->cache;
45470 spin_lock(&cache->op_gc_list_lock);
45471@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45472
45473 _debug("GC DEFERRED REL OBJ%x OP%x",
45474 object->debug_id, op->debug_id);
45475- fscache_stat(&fscache_n_op_gc);
45476+ fscache_stat_unchecked(&fscache_n_op_gc);
45477
45478 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45479
45480diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45481index 3f7a59b..cf196cc 100644
45482--- a/fs/fscache/page.c
45483+++ b/fs/fscache/page.c
45484@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45485 val = radix_tree_lookup(&cookie->stores, page->index);
45486 if (!val) {
45487 rcu_read_unlock();
45488- fscache_stat(&fscache_n_store_vmscan_not_storing);
45489+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45490 __fscache_uncache_page(cookie, page);
45491 return true;
45492 }
45493@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45494 spin_unlock(&cookie->stores_lock);
45495
45496 if (xpage) {
45497- fscache_stat(&fscache_n_store_vmscan_cancelled);
45498- fscache_stat(&fscache_n_store_radix_deletes);
45499+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45500+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45501 ASSERTCMP(xpage, ==, page);
45502 } else {
45503- fscache_stat(&fscache_n_store_vmscan_gone);
45504+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45505 }
45506
45507 wake_up_bit(&cookie->flags, 0);
45508@@ -107,7 +107,7 @@ page_busy:
45509 /* we might want to wait here, but that could deadlock the allocator as
45510 * the work threads writing to the cache may all end up sleeping
45511 * on memory allocation */
45512- fscache_stat(&fscache_n_store_vmscan_busy);
45513+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45514 return false;
45515 }
45516 EXPORT_SYMBOL(__fscache_maybe_release_page);
45517@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45518 FSCACHE_COOKIE_STORING_TAG);
45519 if (!radix_tree_tag_get(&cookie->stores, page->index,
45520 FSCACHE_COOKIE_PENDING_TAG)) {
45521- fscache_stat(&fscache_n_store_radix_deletes);
45522+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45523 xpage = radix_tree_delete(&cookie->stores, page->index);
45524 }
45525 spin_unlock(&cookie->stores_lock);
45526@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45527
45528 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45529
45530- fscache_stat(&fscache_n_attr_changed_calls);
45531+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45532
45533 if (fscache_object_is_active(object)) {
45534 fscache_stat(&fscache_n_cop_attr_changed);
45535@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45536
45537 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45538
45539- fscache_stat(&fscache_n_attr_changed);
45540+ fscache_stat_unchecked(&fscache_n_attr_changed);
45541
45542 op = kzalloc(sizeof(*op), GFP_KERNEL);
45543 if (!op) {
45544- fscache_stat(&fscache_n_attr_changed_nomem);
45545+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45546 _leave(" = -ENOMEM");
45547 return -ENOMEM;
45548 }
45549@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45550 if (fscache_submit_exclusive_op(object, op) < 0)
45551 goto nobufs;
45552 spin_unlock(&cookie->lock);
45553- fscache_stat(&fscache_n_attr_changed_ok);
45554+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45555 fscache_put_operation(op);
45556 _leave(" = 0");
45557 return 0;
45558@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45559 nobufs:
45560 spin_unlock(&cookie->lock);
45561 kfree(op);
45562- fscache_stat(&fscache_n_attr_changed_nobufs);
45563+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45564 _leave(" = %d", -ENOBUFS);
45565 return -ENOBUFS;
45566 }
45567@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45568 /* allocate a retrieval operation and attempt to submit it */
45569 op = kzalloc(sizeof(*op), GFP_NOIO);
45570 if (!op) {
45571- fscache_stat(&fscache_n_retrievals_nomem);
45572+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45573 return NULL;
45574 }
45575
45576@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45577 return 0;
45578 }
45579
45580- fscache_stat(&fscache_n_retrievals_wait);
45581+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
45582
45583 jif = jiffies;
45584 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45585 fscache_wait_bit_interruptible,
45586 TASK_INTERRUPTIBLE) != 0) {
45587- fscache_stat(&fscache_n_retrievals_intr);
45588+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45589 _leave(" = -ERESTARTSYS");
45590 return -ERESTARTSYS;
45591 }
45592@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45593 */
45594 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45595 struct fscache_retrieval *op,
45596- atomic_t *stat_op_waits,
45597- atomic_t *stat_object_dead)
45598+ atomic_unchecked_t *stat_op_waits,
45599+ atomic_unchecked_t *stat_object_dead)
45600 {
45601 int ret;
45602
45603@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45604 goto check_if_dead;
45605
45606 _debug(">>> WT");
45607- fscache_stat(stat_op_waits);
45608+ fscache_stat_unchecked(stat_op_waits);
45609 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45610 fscache_wait_bit_interruptible,
45611 TASK_INTERRUPTIBLE) < 0) {
45612@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45613
45614 check_if_dead:
45615 if (unlikely(fscache_object_is_dead(object))) {
45616- fscache_stat(stat_object_dead);
45617+ fscache_stat_unchecked(stat_object_dead);
45618 return -ENOBUFS;
45619 }
45620 return 0;
45621@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45622
45623 _enter("%p,%p,,,", cookie, page);
45624
45625- fscache_stat(&fscache_n_retrievals);
45626+ fscache_stat_unchecked(&fscache_n_retrievals);
45627
45628 if (hlist_empty(&cookie->backing_objects))
45629 goto nobufs;
45630@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45631 goto nobufs_unlock;
45632 spin_unlock(&cookie->lock);
45633
45634- fscache_stat(&fscache_n_retrieval_ops);
45635+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
45636
45637 /* pin the netfs read context in case we need to do the actual netfs
45638 * read because we've encountered a cache read failure */
45639@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45640
45641 error:
45642 if (ret == -ENOMEM)
45643- fscache_stat(&fscache_n_retrievals_nomem);
45644+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45645 else if (ret == -ERESTARTSYS)
45646- fscache_stat(&fscache_n_retrievals_intr);
45647+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45648 else if (ret == -ENODATA)
45649- fscache_stat(&fscache_n_retrievals_nodata);
45650+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45651 else if (ret < 0)
45652- fscache_stat(&fscache_n_retrievals_nobufs);
45653+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45654 else
45655- fscache_stat(&fscache_n_retrievals_ok);
45656+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
45657
45658 fscache_put_retrieval(op);
45659 _leave(" = %d", ret);
45660@@ -429,7 +429,7 @@ nobufs_unlock:
45661 spin_unlock(&cookie->lock);
45662 kfree(op);
45663 nobufs:
45664- fscache_stat(&fscache_n_retrievals_nobufs);
45665+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45666 _leave(" = -ENOBUFS");
45667 return -ENOBUFS;
45668 }
45669@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45670
45671 _enter("%p,,%d,,,", cookie, *nr_pages);
45672
45673- fscache_stat(&fscache_n_retrievals);
45674+ fscache_stat_unchecked(&fscache_n_retrievals);
45675
45676 if (hlist_empty(&cookie->backing_objects))
45677 goto nobufs;
45678@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45679 goto nobufs_unlock;
45680 spin_unlock(&cookie->lock);
45681
45682- fscache_stat(&fscache_n_retrieval_ops);
45683+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
45684
45685 /* pin the netfs read context in case we need to do the actual netfs
45686 * read because we've encountered a cache read failure */
45687@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45688
45689 error:
45690 if (ret == -ENOMEM)
45691- fscache_stat(&fscache_n_retrievals_nomem);
45692+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45693 else if (ret == -ERESTARTSYS)
45694- fscache_stat(&fscache_n_retrievals_intr);
45695+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45696 else if (ret == -ENODATA)
45697- fscache_stat(&fscache_n_retrievals_nodata);
45698+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45699 else if (ret < 0)
45700- fscache_stat(&fscache_n_retrievals_nobufs);
45701+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45702 else
45703- fscache_stat(&fscache_n_retrievals_ok);
45704+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
45705
45706 fscache_put_retrieval(op);
45707 _leave(" = %d", ret);
45708@@ -545,7 +545,7 @@ nobufs_unlock:
45709 spin_unlock(&cookie->lock);
45710 kfree(op);
45711 nobufs:
45712- fscache_stat(&fscache_n_retrievals_nobufs);
45713+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45714 _leave(" = -ENOBUFS");
45715 return -ENOBUFS;
45716 }
45717@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45718
45719 _enter("%p,%p,,,", cookie, page);
45720
45721- fscache_stat(&fscache_n_allocs);
45722+ fscache_stat_unchecked(&fscache_n_allocs);
45723
45724 if (hlist_empty(&cookie->backing_objects))
45725 goto nobufs;
45726@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45727 goto nobufs_unlock;
45728 spin_unlock(&cookie->lock);
45729
45730- fscache_stat(&fscache_n_alloc_ops);
45731+ fscache_stat_unchecked(&fscache_n_alloc_ops);
45732
45733 ret = fscache_wait_for_retrieval_activation(
45734 object, op,
45735@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45736
45737 error:
45738 if (ret == -ERESTARTSYS)
45739- fscache_stat(&fscache_n_allocs_intr);
45740+ fscache_stat_unchecked(&fscache_n_allocs_intr);
45741 else if (ret < 0)
45742- fscache_stat(&fscache_n_allocs_nobufs);
45743+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45744 else
45745- fscache_stat(&fscache_n_allocs_ok);
45746+ fscache_stat_unchecked(&fscache_n_allocs_ok);
45747
45748 fscache_put_retrieval(op);
45749 _leave(" = %d", ret);
45750@@ -625,7 +625,7 @@ nobufs_unlock:
45751 spin_unlock(&cookie->lock);
45752 kfree(op);
45753 nobufs:
45754- fscache_stat(&fscache_n_allocs_nobufs);
45755+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45756 _leave(" = -ENOBUFS");
45757 return -ENOBUFS;
45758 }
45759@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45760
45761 spin_lock(&cookie->stores_lock);
45762
45763- fscache_stat(&fscache_n_store_calls);
45764+ fscache_stat_unchecked(&fscache_n_store_calls);
45765
45766 /* find a page to store */
45767 page = NULL;
45768@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45769 page = results[0];
45770 _debug("gang %d [%lx]", n, page->index);
45771 if (page->index > op->store_limit) {
45772- fscache_stat(&fscache_n_store_pages_over_limit);
45773+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
45774 goto superseded;
45775 }
45776
45777@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45778 spin_unlock(&cookie->stores_lock);
45779 spin_unlock(&object->lock);
45780
45781- fscache_stat(&fscache_n_store_pages);
45782+ fscache_stat_unchecked(&fscache_n_store_pages);
45783 fscache_stat(&fscache_n_cop_write_page);
45784 ret = object->cache->ops->write_page(op, page);
45785 fscache_stat_d(&fscache_n_cop_write_page);
45786@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45787 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45788 ASSERT(PageFsCache(page));
45789
45790- fscache_stat(&fscache_n_stores);
45791+ fscache_stat_unchecked(&fscache_n_stores);
45792
45793 op = kzalloc(sizeof(*op), GFP_NOIO);
45794 if (!op)
45795@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45796 spin_unlock(&cookie->stores_lock);
45797 spin_unlock(&object->lock);
45798
45799- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
45800+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
45801 op->store_limit = object->store_limit;
45802
45803 if (fscache_submit_op(object, &op->op) < 0)
45804@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45805
45806 spin_unlock(&cookie->lock);
45807 radix_tree_preload_end();
45808- fscache_stat(&fscache_n_store_ops);
45809- fscache_stat(&fscache_n_stores_ok);
45810+ fscache_stat_unchecked(&fscache_n_store_ops);
45811+ fscache_stat_unchecked(&fscache_n_stores_ok);
45812
45813 /* the work queue now carries its own ref on the object */
45814 fscache_put_operation(&op->op);
45815@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45816 return 0;
45817
45818 already_queued:
45819- fscache_stat(&fscache_n_stores_again);
45820+ fscache_stat_unchecked(&fscache_n_stores_again);
45821 already_pending:
45822 spin_unlock(&cookie->stores_lock);
45823 spin_unlock(&object->lock);
45824 spin_unlock(&cookie->lock);
45825 radix_tree_preload_end();
45826 kfree(op);
45827- fscache_stat(&fscache_n_stores_ok);
45828+ fscache_stat_unchecked(&fscache_n_stores_ok);
45829 _leave(" = 0");
45830 return 0;
45831
45832@@ -851,14 +851,14 @@ nobufs:
45833 spin_unlock(&cookie->lock);
45834 radix_tree_preload_end();
45835 kfree(op);
45836- fscache_stat(&fscache_n_stores_nobufs);
45837+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
45838 _leave(" = -ENOBUFS");
45839 return -ENOBUFS;
45840
45841 nomem_free:
45842 kfree(op);
45843 nomem:
45844- fscache_stat(&fscache_n_stores_oom);
45845+ fscache_stat_unchecked(&fscache_n_stores_oom);
45846 _leave(" = -ENOMEM");
45847 return -ENOMEM;
45848 }
45849@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
45850 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45851 ASSERTCMP(page, !=, NULL);
45852
45853- fscache_stat(&fscache_n_uncaches);
45854+ fscache_stat_unchecked(&fscache_n_uncaches);
45855
45856 /* cache withdrawal may beat us to it */
45857 if (!PageFsCache(page))
45858@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
45859 unsigned long loop;
45860
45861 #ifdef CONFIG_FSCACHE_STATS
45862- atomic_add(pagevec->nr, &fscache_n_marks);
45863+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
45864 #endif
45865
45866 for (loop = 0; loop < pagevec->nr; loop++) {
45867diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
45868index 4765190..2a067f2 100644
45869--- a/fs/fscache/stats.c
45870+++ b/fs/fscache/stats.c
45871@@ -18,95 +18,95 @@
45872 /*
45873 * operation counters
45874 */
45875-atomic_t fscache_n_op_pend;
45876-atomic_t fscache_n_op_run;
45877-atomic_t fscache_n_op_enqueue;
45878-atomic_t fscache_n_op_requeue;
45879-atomic_t fscache_n_op_deferred_release;
45880-atomic_t fscache_n_op_release;
45881-atomic_t fscache_n_op_gc;
45882-atomic_t fscache_n_op_cancelled;
45883-atomic_t fscache_n_op_rejected;
45884+atomic_unchecked_t fscache_n_op_pend;
45885+atomic_unchecked_t fscache_n_op_run;
45886+atomic_unchecked_t fscache_n_op_enqueue;
45887+atomic_unchecked_t fscache_n_op_requeue;
45888+atomic_unchecked_t fscache_n_op_deferred_release;
45889+atomic_unchecked_t fscache_n_op_release;
45890+atomic_unchecked_t fscache_n_op_gc;
45891+atomic_unchecked_t fscache_n_op_cancelled;
45892+atomic_unchecked_t fscache_n_op_rejected;
45893
45894-atomic_t fscache_n_attr_changed;
45895-atomic_t fscache_n_attr_changed_ok;
45896-atomic_t fscache_n_attr_changed_nobufs;
45897-atomic_t fscache_n_attr_changed_nomem;
45898-atomic_t fscache_n_attr_changed_calls;
45899+atomic_unchecked_t fscache_n_attr_changed;
45900+atomic_unchecked_t fscache_n_attr_changed_ok;
45901+atomic_unchecked_t fscache_n_attr_changed_nobufs;
45902+atomic_unchecked_t fscache_n_attr_changed_nomem;
45903+atomic_unchecked_t fscache_n_attr_changed_calls;
45904
45905-atomic_t fscache_n_allocs;
45906-atomic_t fscache_n_allocs_ok;
45907-atomic_t fscache_n_allocs_wait;
45908-atomic_t fscache_n_allocs_nobufs;
45909-atomic_t fscache_n_allocs_intr;
45910-atomic_t fscache_n_allocs_object_dead;
45911-atomic_t fscache_n_alloc_ops;
45912-atomic_t fscache_n_alloc_op_waits;
45913+atomic_unchecked_t fscache_n_allocs;
45914+atomic_unchecked_t fscache_n_allocs_ok;
45915+atomic_unchecked_t fscache_n_allocs_wait;
45916+atomic_unchecked_t fscache_n_allocs_nobufs;
45917+atomic_unchecked_t fscache_n_allocs_intr;
45918+atomic_unchecked_t fscache_n_allocs_object_dead;
45919+atomic_unchecked_t fscache_n_alloc_ops;
45920+atomic_unchecked_t fscache_n_alloc_op_waits;
45921
45922-atomic_t fscache_n_retrievals;
45923-atomic_t fscache_n_retrievals_ok;
45924-atomic_t fscache_n_retrievals_wait;
45925-atomic_t fscache_n_retrievals_nodata;
45926-atomic_t fscache_n_retrievals_nobufs;
45927-atomic_t fscache_n_retrievals_intr;
45928-atomic_t fscache_n_retrievals_nomem;
45929-atomic_t fscache_n_retrievals_object_dead;
45930-atomic_t fscache_n_retrieval_ops;
45931-atomic_t fscache_n_retrieval_op_waits;
45932+atomic_unchecked_t fscache_n_retrievals;
45933+atomic_unchecked_t fscache_n_retrievals_ok;
45934+atomic_unchecked_t fscache_n_retrievals_wait;
45935+atomic_unchecked_t fscache_n_retrievals_nodata;
45936+atomic_unchecked_t fscache_n_retrievals_nobufs;
45937+atomic_unchecked_t fscache_n_retrievals_intr;
45938+atomic_unchecked_t fscache_n_retrievals_nomem;
45939+atomic_unchecked_t fscache_n_retrievals_object_dead;
45940+atomic_unchecked_t fscache_n_retrieval_ops;
45941+atomic_unchecked_t fscache_n_retrieval_op_waits;
45942
45943-atomic_t fscache_n_stores;
45944-atomic_t fscache_n_stores_ok;
45945-atomic_t fscache_n_stores_again;
45946-atomic_t fscache_n_stores_nobufs;
45947-atomic_t fscache_n_stores_oom;
45948-atomic_t fscache_n_store_ops;
45949-atomic_t fscache_n_store_calls;
45950-atomic_t fscache_n_store_pages;
45951-atomic_t fscache_n_store_radix_deletes;
45952-atomic_t fscache_n_store_pages_over_limit;
45953+atomic_unchecked_t fscache_n_stores;
45954+atomic_unchecked_t fscache_n_stores_ok;
45955+atomic_unchecked_t fscache_n_stores_again;
45956+atomic_unchecked_t fscache_n_stores_nobufs;
45957+atomic_unchecked_t fscache_n_stores_oom;
45958+atomic_unchecked_t fscache_n_store_ops;
45959+atomic_unchecked_t fscache_n_store_calls;
45960+atomic_unchecked_t fscache_n_store_pages;
45961+atomic_unchecked_t fscache_n_store_radix_deletes;
45962+atomic_unchecked_t fscache_n_store_pages_over_limit;
45963
45964-atomic_t fscache_n_store_vmscan_not_storing;
45965-atomic_t fscache_n_store_vmscan_gone;
45966-atomic_t fscache_n_store_vmscan_busy;
45967-atomic_t fscache_n_store_vmscan_cancelled;
45968+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45969+atomic_unchecked_t fscache_n_store_vmscan_gone;
45970+atomic_unchecked_t fscache_n_store_vmscan_busy;
45971+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45972
45973-atomic_t fscache_n_marks;
45974-atomic_t fscache_n_uncaches;
45975+atomic_unchecked_t fscache_n_marks;
45976+atomic_unchecked_t fscache_n_uncaches;
45977
45978-atomic_t fscache_n_acquires;
45979-atomic_t fscache_n_acquires_null;
45980-atomic_t fscache_n_acquires_no_cache;
45981-atomic_t fscache_n_acquires_ok;
45982-atomic_t fscache_n_acquires_nobufs;
45983-atomic_t fscache_n_acquires_oom;
45984+atomic_unchecked_t fscache_n_acquires;
45985+atomic_unchecked_t fscache_n_acquires_null;
45986+atomic_unchecked_t fscache_n_acquires_no_cache;
45987+atomic_unchecked_t fscache_n_acquires_ok;
45988+atomic_unchecked_t fscache_n_acquires_nobufs;
45989+atomic_unchecked_t fscache_n_acquires_oom;
45990
45991-atomic_t fscache_n_updates;
45992-atomic_t fscache_n_updates_null;
45993-atomic_t fscache_n_updates_run;
45994+atomic_unchecked_t fscache_n_updates;
45995+atomic_unchecked_t fscache_n_updates_null;
45996+atomic_unchecked_t fscache_n_updates_run;
45997
45998-atomic_t fscache_n_relinquishes;
45999-atomic_t fscache_n_relinquishes_null;
46000-atomic_t fscache_n_relinquishes_waitcrt;
46001-atomic_t fscache_n_relinquishes_retire;
46002+atomic_unchecked_t fscache_n_relinquishes;
46003+atomic_unchecked_t fscache_n_relinquishes_null;
46004+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46005+atomic_unchecked_t fscache_n_relinquishes_retire;
46006
46007-atomic_t fscache_n_cookie_index;
46008-atomic_t fscache_n_cookie_data;
46009-atomic_t fscache_n_cookie_special;
46010+atomic_unchecked_t fscache_n_cookie_index;
46011+atomic_unchecked_t fscache_n_cookie_data;
46012+atomic_unchecked_t fscache_n_cookie_special;
46013
46014-atomic_t fscache_n_object_alloc;
46015-atomic_t fscache_n_object_no_alloc;
46016-atomic_t fscache_n_object_lookups;
46017-atomic_t fscache_n_object_lookups_negative;
46018-atomic_t fscache_n_object_lookups_positive;
46019-atomic_t fscache_n_object_lookups_timed_out;
46020-atomic_t fscache_n_object_created;
46021-atomic_t fscache_n_object_avail;
46022-atomic_t fscache_n_object_dead;
46023+atomic_unchecked_t fscache_n_object_alloc;
46024+atomic_unchecked_t fscache_n_object_no_alloc;
46025+atomic_unchecked_t fscache_n_object_lookups;
46026+atomic_unchecked_t fscache_n_object_lookups_negative;
46027+atomic_unchecked_t fscache_n_object_lookups_positive;
46028+atomic_unchecked_t fscache_n_object_lookups_timed_out;
46029+atomic_unchecked_t fscache_n_object_created;
46030+atomic_unchecked_t fscache_n_object_avail;
46031+atomic_unchecked_t fscache_n_object_dead;
46032
46033-atomic_t fscache_n_checkaux_none;
46034-atomic_t fscache_n_checkaux_okay;
46035-atomic_t fscache_n_checkaux_update;
46036-atomic_t fscache_n_checkaux_obsolete;
46037+atomic_unchecked_t fscache_n_checkaux_none;
46038+atomic_unchecked_t fscache_n_checkaux_okay;
46039+atomic_unchecked_t fscache_n_checkaux_update;
46040+atomic_unchecked_t fscache_n_checkaux_obsolete;
46041
46042 atomic_t fscache_n_cop_alloc_object;
46043 atomic_t fscache_n_cop_lookup_object;
46044@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46045 seq_puts(m, "FS-Cache statistics\n");
46046
46047 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46048- atomic_read(&fscache_n_cookie_index),
46049- atomic_read(&fscache_n_cookie_data),
46050- atomic_read(&fscache_n_cookie_special));
46051+ atomic_read_unchecked(&fscache_n_cookie_index),
46052+ atomic_read_unchecked(&fscache_n_cookie_data),
46053+ atomic_read_unchecked(&fscache_n_cookie_special));
46054
46055 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46056- atomic_read(&fscache_n_object_alloc),
46057- atomic_read(&fscache_n_object_no_alloc),
46058- atomic_read(&fscache_n_object_avail),
46059- atomic_read(&fscache_n_object_dead));
46060+ atomic_read_unchecked(&fscache_n_object_alloc),
46061+ atomic_read_unchecked(&fscache_n_object_no_alloc),
46062+ atomic_read_unchecked(&fscache_n_object_avail),
46063+ atomic_read_unchecked(&fscache_n_object_dead));
46064 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46065- atomic_read(&fscache_n_checkaux_none),
46066- atomic_read(&fscache_n_checkaux_okay),
46067- atomic_read(&fscache_n_checkaux_update),
46068- atomic_read(&fscache_n_checkaux_obsolete));
46069+ atomic_read_unchecked(&fscache_n_checkaux_none),
46070+ atomic_read_unchecked(&fscache_n_checkaux_okay),
46071+ atomic_read_unchecked(&fscache_n_checkaux_update),
46072+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46073
46074 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46075- atomic_read(&fscache_n_marks),
46076- atomic_read(&fscache_n_uncaches));
46077+ atomic_read_unchecked(&fscache_n_marks),
46078+ atomic_read_unchecked(&fscache_n_uncaches));
46079
46080 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46081 " oom=%u\n",
46082- atomic_read(&fscache_n_acquires),
46083- atomic_read(&fscache_n_acquires_null),
46084- atomic_read(&fscache_n_acquires_no_cache),
46085- atomic_read(&fscache_n_acquires_ok),
46086- atomic_read(&fscache_n_acquires_nobufs),
46087- atomic_read(&fscache_n_acquires_oom));
46088+ atomic_read_unchecked(&fscache_n_acquires),
46089+ atomic_read_unchecked(&fscache_n_acquires_null),
46090+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
46091+ atomic_read_unchecked(&fscache_n_acquires_ok),
46092+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
46093+ atomic_read_unchecked(&fscache_n_acquires_oom));
46094
46095 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46096- atomic_read(&fscache_n_object_lookups),
46097- atomic_read(&fscache_n_object_lookups_negative),
46098- atomic_read(&fscache_n_object_lookups_positive),
46099- atomic_read(&fscache_n_object_created),
46100- atomic_read(&fscache_n_object_lookups_timed_out));
46101+ atomic_read_unchecked(&fscache_n_object_lookups),
46102+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
46103+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
46104+ atomic_read_unchecked(&fscache_n_object_created),
46105+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46106
46107 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46108- atomic_read(&fscache_n_updates),
46109- atomic_read(&fscache_n_updates_null),
46110- atomic_read(&fscache_n_updates_run));
46111+ atomic_read_unchecked(&fscache_n_updates),
46112+ atomic_read_unchecked(&fscache_n_updates_null),
46113+ atomic_read_unchecked(&fscache_n_updates_run));
46114
46115 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46116- atomic_read(&fscache_n_relinquishes),
46117- atomic_read(&fscache_n_relinquishes_null),
46118- atomic_read(&fscache_n_relinquishes_waitcrt),
46119- atomic_read(&fscache_n_relinquishes_retire));
46120+ atomic_read_unchecked(&fscache_n_relinquishes),
46121+ atomic_read_unchecked(&fscache_n_relinquishes_null),
46122+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46123+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
46124
46125 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46126- atomic_read(&fscache_n_attr_changed),
46127- atomic_read(&fscache_n_attr_changed_ok),
46128- atomic_read(&fscache_n_attr_changed_nobufs),
46129- atomic_read(&fscache_n_attr_changed_nomem),
46130- atomic_read(&fscache_n_attr_changed_calls));
46131+ atomic_read_unchecked(&fscache_n_attr_changed),
46132+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
46133+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46134+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46135+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
46136
46137 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46138- atomic_read(&fscache_n_allocs),
46139- atomic_read(&fscache_n_allocs_ok),
46140- atomic_read(&fscache_n_allocs_wait),
46141- atomic_read(&fscache_n_allocs_nobufs),
46142- atomic_read(&fscache_n_allocs_intr));
46143+ atomic_read_unchecked(&fscache_n_allocs),
46144+ atomic_read_unchecked(&fscache_n_allocs_ok),
46145+ atomic_read_unchecked(&fscache_n_allocs_wait),
46146+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
46147+ atomic_read_unchecked(&fscache_n_allocs_intr));
46148 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46149- atomic_read(&fscache_n_alloc_ops),
46150- atomic_read(&fscache_n_alloc_op_waits),
46151- atomic_read(&fscache_n_allocs_object_dead));
46152+ atomic_read_unchecked(&fscache_n_alloc_ops),
46153+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
46154+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
46155
46156 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46157 " int=%u oom=%u\n",
46158- atomic_read(&fscache_n_retrievals),
46159- atomic_read(&fscache_n_retrievals_ok),
46160- atomic_read(&fscache_n_retrievals_wait),
46161- atomic_read(&fscache_n_retrievals_nodata),
46162- atomic_read(&fscache_n_retrievals_nobufs),
46163- atomic_read(&fscache_n_retrievals_intr),
46164- atomic_read(&fscache_n_retrievals_nomem));
46165+ atomic_read_unchecked(&fscache_n_retrievals),
46166+ atomic_read_unchecked(&fscache_n_retrievals_ok),
46167+ atomic_read_unchecked(&fscache_n_retrievals_wait),
46168+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
46169+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46170+ atomic_read_unchecked(&fscache_n_retrievals_intr),
46171+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
46172 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46173- atomic_read(&fscache_n_retrieval_ops),
46174- atomic_read(&fscache_n_retrieval_op_waits),
46175- atomic_read(&fscache_n_retrievals_object_dead));
46176+ atomic_read_unchecked(&fscache_n_retrieval_ops),
46177+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46178+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46179
46180 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46181- atomic_read(&fscache_n_stores),
46182- atomic_read(&fscache_n_stores_ok),
46183- atomic_read(&fscache_n_stores_again),
46184- atomic_read(&fscache_n_stores_nobufs),
46185- atomic_read(&fscache_n_stores_oom));
46186+ atomic_read_unchecked(&fscache_n_stores),
46187+ atomic_read_unchecked(&fscache_n_stores_ok),
46188+ atomic_read_unchecked(&fscache_n_stores_again),
46189+ atomic_read_unchecked(&fscache_n_stores_nobufs),
46190+ atomic_read_unchecked(&fscache_n_stores_oom));
46191 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46192- atomic_read(&fscache_n_store_ops),
46193- atomic_read(&fscache_n_store_calls),
46194- atomic_read(&fscache_n_store_pages),
46195- atomic_read(&fscache_n_store_radix_deletes),
46196- atomic_read(&fscache_n_store_pages_over_limit));
46197+ atomic_read_unchecked(&fscache_n_store_ops),
46198+ atomic_read_unchecked(&fscache_n_store_calls),
46199+ atomic_read_unchecked(&fscache_n_store_pages),
46200+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
46201+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46202
46203 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46204- atomic_read(&fscache_n_store_vmscan_not_storing),
46205- atomic_read(&fscache_n_store_vmscan_gone),
46206- atomic_read(&fscache_n_store_vmscan_busy),
46207- atomic_read(&fscache_n_store_vmscan_cancelled));
46208+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46209+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46210+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46211+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46212
46213 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46214- atomic_read(&fscache_n_op_pend),
46215- atomic_read(&fscache_n_op_run),
46216- atomic_read(&fscache_n_op_enqueue),
46217- atomic_read(&fscache_n_op_cancelled),
46218- atomic_read(&fscache_n_op_rejected));
46219+ atomic_read_unchecked(&fscache_n_op_pend),
46220+ atomic_read_unchecked(&fscache_n_op_run),
46221+ atomic_read_unchecked(&fscache_n_op_enqueue),
46222+ atomic_read_unchecked(&fscache_n_op_cancelled),
46223+ atomic_read_unchecked(&fscache_n_op_rejected));
46224 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46225- atomic_read(&fscache_n_op_deferred_release),
46226- atomic_read(&fscache_n_op_release),
46227- atomic_read(&fscache_n_op_gc));
46228+ atomic_read_unchecked(&fscache_n_op_deferred_release),
46229+ atomic_read_unchecked(&fscache_n_op_release),
46230+ atomic_read_unchecked(&fscache_n_op_gc));
46231
46232 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46233 atomic_read(&fscache_n_cop_alloc_object),
46234diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46235index 3426521..3b75162 100644
46236--- a/fs/fuse/cuse.c
46237+++ b/fs/fuse/cuse.c
46238@@ -587,10 +587,12 @@ static int __init cuse_init(void)
46239 INIT_LIST_HEAD(&cuse_conntbl[i]);
46240
46241 /* inherit and extend fuse_dev_operations */
46242- cuse_channel_fops = fuse_dev_operations;
46243- cuse_channel_fops.owner = THIS_MODULE;
46244- cuse_channel_fops.open = cuse_channel_open;
46245- cuse_channel_fops.release = cuse_channel_release;
46246+ pax_open_kernel();
46247+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46248+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46249+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
46250+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
46251+ pax_close_kernel();
46252
46253 cuse_class = class_create(THIS_MODULE, "cuse");
46254 if (IS_ERR(cuse_class))
46255diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46256index 7df2b5e..5804aa7 100644
46257--- a/fs/fuse/dev.c
46258+++ b/fs/fuse/dev.c
46259@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46260 ret = 0;
46261 pipe_lock(pipe);
46262
46263- if (!pipe->readers) {
46264+ if (!atomic_read(&pipe->readers)) {
46265 send_sig(SIGPIPE, current, 0);
46266 if (!ret)
46267 ret = -EPIPE;
46268diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46269index bc43832..0cfe5a6 100644
46270--- a/fs/fuse/dir.c
46271+++ b/fs/fuse/dir.c
46272@@ -1181,7 +1181,7 @@ static char *read_link(struct dentry *dentry)
46273 return link;
46274 }
46275
46276-static void free_link(char *link)
46277+static void free_link(const char *link)
46278 {
46279 if (!IS_ERR(link))
46280 free_page((unsigned long) link);
46281diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46282index a9ba244..d9df391 100644
46283--- a/fs/gfs2/inode.c
46284+++ b/fs/gfs2/inode.c
46285@@ -1496,7 +1496,7 @@ out:
46286
46287 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46288 {
46289- char *s = nd_get_link(nd);
46290+ const char *s = nd_get_link(nd);
46291 if (!IS_ERR(s))
46292 kfree(s);
46293 }
46294diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46295index 001ef01..f7d5f07 100644
46296--- a/fs/hugetlbfs/inode.c
46297+++ b/fs/hugetlbfs/inode.c
46298@@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46299 .kill_sb = kill_litter_super,
46300 };
46301
46302-static struct vfsmount *hugetlbfs_vfsmount;
46303+struct vfsmount *hugetlbfs_vfsmount;
46304
46305 static int can_do_hugetlb_shm(void)
46306 {
46307diff --git a/fs/inode.c b/fs/inode.c
46308index 9f4f5fe..6214688 100644
46309--- a/fs/inode.c
46310+++ b/fs/inode.c
46311@@ -860,8 +860,8 @@ unsigned int get_next_ino(void)
46312
46313 #ifdef CONFIG_SMP
46314 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46315- static atomic_t shared_last_ino;
46316- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46317+ static atomic_unchecked_t shared_last_ino;
46318+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46319
46320 res = next - LAST_INO_BATCH;
46321 }
46322diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46323index 4a6cf28..d3a29d3 100644
46324--- a/fs/jffs2/erase.c
46325+++ b/fs/jffs2/erase.c
46326@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46327 struct jffs2_unknown_node marker = {
46328 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46329 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46330- .totlen = cpu_to_je32(c->cleanmarker_size)
46331+ .totlen = cpu_to_je32(c->cleanmarker_size),
46332+ .hdr_crc = cpu_to_je32(0)
46333 };
46334
46335 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46336diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46337index 74d9be1..d5dd140 100644
46338--- a/fs/jffs2/wbuf.c
46339+++ b/fs/jffs2/wbuf.c
46340@@ -1022,7 +1022,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46341 {
46342 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46343 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46344- .totlen = constant_cpu_to_je32(8)
46345+ .totlen = constant_cpu_to_je32(8),
46346+ .hdr_crc = constant_cpu_to_je32(0)
46347 };
46348
46349 /*
46350diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46351index 4a82950..bcaa0cb 100644
46352--- a/fs/jfs/super.c
46353+++ b/fs/jfs/super.c
46354@@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46355
46356 jfs_inode_cachep =
46357 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46358- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46359+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46360 init_once);
46361 if (jfs_inode_cachep == NULL)
46362 return -ENOMEM;
46363diff --git a/fs/libfs.c b/fs/libfs.c
46364index 18d08f5..fe3dc64 100644
46365--- a/fs/libfs.c
46366+++ b/fs/libfs.c
46367@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46368
46369 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46370 struct dentry *next;
46371+ char d_name[sizeof(next->d_iname)];
46372+ const unsigned char *name;
46373+
46374 next = list_entry(p, struct dentry, d_u.d_child);
46375 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46376 if (!simple_positive(next)) {
46377@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46378
46379 spin_unlock(&next->d_lock);
46380 spin_unlock(&dentry->d_lock);
46381- if (filldir(dirent, next->d_name.name,
46382+ name = next->d_name.name;
46383+ if (name == next->d_iname) {
46384+ memcpy(d_name, name, next->d_name.len);
46385+ name = d_name;
46386+ }
46387+ if (filldir(dirent, name,
46388 next->d_name.len, filp->f_pos,
46389 next->d_inode->i_ino,
46390 dt_type(next->d_inode)) < 0)
46391diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46392index 8392cb8..80d6193 100644
46393--- a/fs/lockd/clntproc.c
46394+++ b/fs/lockd/clntproc.c
46395@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46396 /*
46397 * Cookie counter for NLM requests
46398 */
46399-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46400+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46401
46402 void nlmclnt_next_cookie(struct nlm_cookie *c)
46403 {
46404- u32 cookie = atomic_inc_return(&nlm_cookie);
46405+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46406
46407 memcpy(c->data, &cookie, 4);
46408 c->len=4;
46409diff --git a/fs/locks.c b/fs/locks.c
46410index 6a64f15..c3dacf2 100644
46411--- a/fs/locks.c
46412+++ b/fs/locks.c
46413@@ -308,7 +308,7 @@ static int flock_make_lock(struct file *filp, struct file_lock **lock,
46414 return 0;
46415 }
46416
46417-static int assign_type(struct file_lock *fl, int type)
46418+static int assign_type(struct file_lock *fl, long type)
46419 {
46420 switch (type) {
46421 case F_RDLCK:
46422@@ -445,7 +445,7 @@ static const struct lock_manager_operations lease_manager_ops = {
46423 /*
46424 * Initialize a lease, use the default lock manager operations
46425 */
46426-static int lease_init(struct file *filp, int type, struct file_lock *fl)
46427+static int lease_init(struct file *filp, long type, struct file_lock *fl)
46428 {
46429 if (assign_type(fl, type) != 0)
46430 return -EINVAL;
46431@@ -463,7 +463,7 @@ static int lease_init(struct file *filp, int type, struct file_lock *fl)
46432 }
46433
46434 /* Allocate a file_lock initialised to this type of lease */
46435-static struct file_lock *lease_alloc(struct file *filp, int type)
46436+static struct file_lock *lease_alloc(struct file *filp, long type)
46437 {
46438 struct file_lock *fl = locks_alloc_lock();
46439 int error = -ENOMEM;
46440@@ -2075,16 +2075,16 @@ void locks_remove_flock(struct file *filp)
46441 return;
46442
46443 if (filp->f_op && filp->f_op->flock) {
46444- struct file_lock fl = {
46445+ struct file_lock flock = {
46446 .fl_pid = current->tgid,
46447 .fl_file = filp,
46448 .fl_flags = FL_FLOCK,
46449 .fl_type = F_UNLCK,
46450 .fl_end = OFFSET_MAX,
46451 };
46452- filp->f_op->flock(filp, F_SETLKW, &fl);
46453- if (fl.fl_ops && fl.fl_ops->fl_release_private)
46454- fl.fl_ops->fl_release_private(&fl);
46455+ filp->f_op->flock(filp, F_SETLKW, &flock);
46456+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
46457+ flock.fl_ops->fl_release_private(&flock);
46458 }
46459
46460 lock_flocks();
46461diff --git a/fs/namei.c b/fs/namei.c
46462index c427919..232326c 100644
46463--- a/fs/namei.c
46464+++ b/fs/namei.c
46465@@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
46466 if (ret != -EACCES)
46467 return ret;
46468
46469+#ifdef CONFIG_GRKERNSEC
46470+ /* we'll block if we have to log due to a denied capability use */
46471+ if (mask & MAY_NOT_BLOCK)
46472+ return -ECHILD;
46473+#endif
46474+
46475 if (S_ISDIR(inode->i_mode)) {
46476 /* DACs are overridable for directories */
46477- if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46478- return 0;
46479 if (!(mask & MAY_WRITE))
46480- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46481+ if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46482+ ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46483 return 0;
46484+ if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46485+ return 0;
46486 return -EACCES;
46487 }
46488 /*
46489+ * Searching includes executable on directories, else just read.
46490+ */
46491+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46492+ if (mask == MAY_READ)
46493+ if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46494+ ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46495+ return 0;
46496+
46497+ /*
46498 * Read/write DACs are always overridable.
46499 * Executable DACs are overridable when there is
46500 * at least one exec bit set.
46501@@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
46502 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46503 return 0;
46504
46505- /*
46506- * Searching includes executable on directories, else just read.
46507- */
46508- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46509- if (mask == MAY_READ)
46510- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46511- return 0;
46512-
46513 return -EACCES;
46514 }
46515
46516@@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46517 return error;
46518 }
46519
46520+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
46521+ dentry->d_inode, dentry, nd->path.mnt)) {
46522+ error = -EACCES;
46523+ *p = ERR_PTR(error); /* no ->put_link(), please */
46524+ path_put(&nd->path);
46525+ return error;
46526+ }
46527+
46528 nd->last_type = LAST_BIND;
46529 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46530 error = PTR_ERR(*p);
46531 if (!IS_ERR(*p)) {
46532- char *s = nd_get_link(nd);
46533+ const char *s = nd_get_link(nd);
46534 error = 0;
46535 if (s)
46536 error = __vfs_follow_link(nd, s);
46537@@ -1355,6 +1371,9 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
46538 if (!res)
46539 res = walk_component(nd, path, &nd->last,
46540 nd->last_type, LOOKUP_FOLLOW);
46541+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode)) {
46542+ res = -EACCES;
46543+ }
46544 put_link(nd, &link, cookie);
46545 } while (res > 0);
46546
46547@@ -1746,6 +1765,9 @@ static int path_lookupat(int dfd, const char *name,
46548 err = follow_link(&link, nd, &cookie);
46549 if (!err)
46550 err = lookup_last(nd, &path);
46551+ if (!err && gr_handle_symlink_owner(&link, nd->inode)) {
46552+ err = -EACCES;
46553+ }
46554 put_link(nd, &link, cookie);
46555 }
46556 }
46557@@ -1753,6 +1775,21 @@ static int path_lookupat(int dfd, const char *name,
46558 if (!err)
46559 err = complete_walk(nd);
46560
46561+ if (!(nd->flags & LOOKUP_PARENT)) {
46562+#ifdef CONFIG_GRKERNSEC
46563+ if (flags & LOOKUP_RCU) {
46564+ if (!err)
46565+ path_put(&nd->path);
46566+ err = -ECHILD;
46567+ } else
46568+#endif
46569+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46570+ if (!err)
46571+ path_put(&nd->path);
46572+ err = -ENOENT;
46573+ }
46574+ }
46575+
46576 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46577 if (!nd->inode->i_op->lookup) {
46578 path_put(&nd->path);
46579@@ -1780,6 +1817,15 @@ static int do_path_lookup(int dfd, const char *name,
46580 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46581
46582 if (likely(!retval)) {
46583+ if (*name != '/' && nd->path.dentry && nd->inode) {
46584+#ifdef CONFIG_GRKERNSEC
46585+ if (flags & LOOKUP_RCU)
46586+ return -ECHILD;
46587+#endif
46588+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46589+ return -ENOENT;
46590+ }
46591+
46592 if (unlikely(!audit_dummy_context())) {
46593 if (nd->path.dentry && nd->inode)
46594 audit_inode(name, nd->path.dentry);
46595@@ -2126,6 +2172,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
46596 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
46597 return -EPERM;
46598
46599+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
46600+ return -EPERM;
46601+ if (gr_handle_rawio(inode))
46602+ return -EPERM;
46603+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
46604+ return -EACCES;
46605+
46606 return 0;
46607 }
46608
46609@@ -2187,6 +2240,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46610 error = complete_walk(nd);
46611 if (error)
46612 return ERR_PTR(error);
46613+#ifdef CONFIG_GRKERNSEC
46614+ if (nd->flags & LOOKUP_RCU) {
46615+ error = -ECHILD;
46616+ goto exit;
46617+ }
46618+#endif
46619+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46620+ error = -ENOENT;
46621+ goto exit;
46622+ }
46623 audit_inode(pathname, nd->path.dentry);
46624 if (open_flag & O_CREAT) {
46625 error = -EISDIR;
46626@@ -2197,6 +2260,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46627 error = complete_walk(nd);
46628 if (error)
46629 return ERR_PTR(error);
46630+#ifdef CONFIG_GRKERNSEC
46631+ if (nd->flags & LOOKUP_RCU) {
46632+ error = -ECHILD;
46633+ goto exit;
46634+ }
46635+#endif
46636+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46637+ error = -ENOENT;
46638+ goto exit;
46639+ }
46640 audit_inode(pathname, dir);
46641 goto ok;
46642 }
46643@@ -2218,6 +2291,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46644 error = complete_walk(nd);
46645 if (error)
46646 return ERR_PTR(error);
46647+#ifdef CONFIG_GRKERNSEC
46648+ if (nd->flags & LOOKUP_RCU) {
46649+ error = -ECHILD;
46650+ goto exit;
46651+ }
46652+#endif
46653+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46654+ error = -ENOENT;
46655+ goto exit;
46656+ }
46657
46658 error = -ENOTDIR;
46659 if (nd->flags & LOOKUP_DIRECTORY) {
46660@@ -2258,6 +2341,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46661 /* Negative dentry, just create the file */
46662 if (!dentry->d_inode) {
46663 umode_t mode = op->mode;
46664+
46665+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46666+ error = -EACCES;
46667+ goto exit_mutex_unlock;
46668+ }
46669+
46670 if (!IS_POSIXACL(dir->d_inode))
46671 mode &= ~current_umask();
46672 /*
46673@@ -2281,6 +2370,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46674 error = vfs_create(dir->d_inode, dentry, mode, nd);
46675 if (error)
46676 goto exit_mutex_unlock;
46677+ else
46678+ gr_handle_create(path->dentry, path->mnt);
46679 mutex_unlock(&dir->d_inode->i_mutex);
46680 dput(nd->path.dentry);
46681 nd->path.dentry = dentry;
46682@@ -2290,6 +2381,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46683 /*
46684 * It already exists.
46685 */
46686+
46687+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46688+ error = -ENOENT;
46689+ goto exit_mutex_unlock;
46690+ }
46691+
46692+ /* only check if O_CREAT is specified, all other checks need to go
46693+ into may_open */
46694+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46695+ error = -EACCES;
46696+ goto exit_mutex_unlock;
46697+ }
46698+
46699 mutex_unlock(&dir->d_inode->i_mutex);
46700 audit_inode(pathname, path->dentry);
46701
46702@@ -2407,8 +2511,14 @@ static struct file *path_openat(int dfd, const char *pathname,
46703 error = follow_link(&link, nd, &cookie);
46704 if (unlikely(error))
46705 filp = ERR_PTR(error);
46706- else
46707+ else {
46708 filp = do_last(nd, &path, op, pathname);
46709+ if (!IS_ERR(filp) && gr_handle_symlink_owner(&link, nd->inode)) {
46710+ if (filp)
46711+ fput(filp);
46712+ filp = ERR_PTR(-EACCES);
46713+ }
46714+ }
46715 put_link(nd, &link, cookie);
46716 }
46717 out:
46718@@ -2502,6 +2612,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46719 *path = nd.path;
46720 return dentry;
46721 eexist:
46722+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46723+ dput(dentry);
46724+ dentry = ERR_PTR(-ENOENT);
46725+ goto fail;
46726+ }
46727 dput(dentry);
46728 dentry = ERR_PTR(-EEXIST);
46729 fail:
46730@@ -2524,6 +2639,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
46731 }
46732 EXPORT_SYMBOL(user_path_create);
46733
46734+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
46735+{
46736+ char *tmp = getname(pathname);
46737+ struct dentry *res;
46738+ if (IS_ERR(tmp))
46739+ return ERR_CAST(tmp);
46740+ res = kern_path_create(dfd, tmp, path, is_dir);
46741+ if (IS_ERR(res))
46742+ putname(tmp);
46743+ else
46744+ *to = tmp;
46745+ return res;
46746+}
46747+
46748 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
46749 {
46750 int error = may_create(dir, dentry);
46751@@ -2591,6 +2720,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46752 error = mnt_want_write(path.mnt);
46753 if (error)
46754 goto out_dput;
46755+
46756+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
46757+ error = -EPERM;
46758+ goto out_drop_write;
46759+ }
46760+
46761+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
46762+ error = -EACCES;
46763+ goto out_drop_write;
46764+ }
46765+
46766 error = security_path_mknod(&path, dentry, mode, dev);
46767 if (error)
46768 goto out_drop_write;
46769@@ -2608,6 +2748,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46770 }
46771 out_drop_write:
46772 mnt_drop_write(path.mnt);
46773+
46774+ if (!error)
46775+ gr_handle_create(dentry, path.mnt);
46776 out_dput:
46777 dput(dentry);
46778 mutex_unlock(&path.dentry->d_inode->i_mutex);
46779@@ -2661,12 +2804,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
46780 error = mnt_want_write(path.mnt);
46781 if (error)
46782 goto out_dput;
46783+
46784+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
46785+ error = -EACCES;
46786+ goto out_drop_write;
46787+ }
46788+
46789 error = security_path_mkdir(&path, dentry, mode);
46790 if (error)
46791 goto out_drop_write;
46792 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
46793 out_drop_write:
46794 mnt_drop_write(path.mnt);
46795+
46796+ if (!error)
46797+ gr_handle_create(dentry, path.mnt);
46798 out_dput:
46799 dput(dentry);
46800 mutex_unlock(&path.dentry->d_inode->i_mutex);
46801@@ -2746,6 +2898,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46802 char * name;
46803 struct dentry *dentry;
46804 struct nameidata nd;
46805+ ino_t saved_ino = 0;
46806+ dev_t saved_dev = 0;
46807
46808 error = user_path_parent(dfd, pathname, &nd, &name);
46809 if (error)
46810@@ -2774,6 +2928,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
46811 error = -ENOENT;
46812 goto exit3;
46813 }
46814+
46815+ saved_ino = dentry->d_inode->i_ino;
46816+ saved_dev = gr_get_dev_from_dentry(dentry);
46817+
46818+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
46819+ error = -EACCES;
46820+ goto exit3;
46821+ }
46822+
46823 error = mnt_want_write(nd.path.mnt);
46824 if (error)
46825 goto exit3;
46826@@ -2781,6 +2944,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46827 if (error)
46828 goto exit4;
46829 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
46830+ if (!error && (saved_dev || saved_ino))
46831+ gr_handle_delete(saved_ino, saved_dev);
46832 exit4:
46833 mnt_drop_write(nd.path.mnt);
46834 exit3:
46835@@ -2843,6 +3008,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46836 struct dentry *dentry;
46837 struct nameidata nd;
46838 struct inode *inode = NULL;
46839+ ino_t saved_ino = 0;
46840+ dev_t saved_dev = 0;
46841
46842 error = user_path_parent(dfd, pathname, &nd, &name);
46843 if (error)
46844@@ -2865,6 +3032,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46845 if (!inode)
46846 goto slashes;
46847 ihold(inode);
46848+
46849+ if (inode->i_nlink <= 1) {
46850+ saved_ino = inode->i_ino;
46851+ saved_dev = gr_get_dev_from_dentry(dentry);
46852+ }
46853+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
46854+ error = -EACCES;
46855+ goto exit2;
46856+ }
46857+
46858 error = mnt_want_write(nd.path.mnt);
46859 if (error)
46860 goto exit2;
46861@@ -2872,6 +3049,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46862 if (error)
46863 goto exit3;
46864 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
46865+ if (!error && (saved_ino || saved_dev))
46866+ gr_handle_delete(saved_ino, saved_dev);
46867 exit3:
46868 mnt_drop_write(nd.path.mnt);
46869 exit2:
46870@@ -2947,10 +3126,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
46871 error = mnt_want_write(path.mnt);
46872 if (error)
46873 goto out_dput;
46874+
46875+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
46876+ error = -EACCES;
46877+ goto out_drop_write;
46878+ }
46879+
46880 error = security_path_symlink(&path, dentry, from);
46881 if (error)
46882 goto out_drop_write;
46883 error = vfs_symlink(path.dentry->d_inode, dentry, from);
46884+ if (!error)
46885+ gr_handle_create(dentry, path.mnt);
46886 out_drop_write:
46887 mnt_drop_write(path.mnt);
46888 out_dput:
46889@@ -3025,6 +3212,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46890 {
46891 struct dentry *new_dentry;
46892 struct path old_path, new_path;
46893+ char *to = NULL;
46894 int how = 0;
46895 int error;
46896
46897@@ -3048,7 +3236,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46898 if (error)
46899 return error;
46900
46901- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
46902+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
46903 error = PTR_ERR(new_dentry);
46904 if (IS_ERR(new_dentry))
46905 goto out;
46906@@ -3059,13 +3247,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46907 error = mnt_want_write(new_path.mnt);
46908 if (error)
46909 goto out_dput;
46910+
46911+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
46912+ old_path.dentry->d_inode,
46913+ old_path.dentry->d_inode->i_mode, to)) {
46914+ error = -EACCES;
46915+ goto out_drop_write;
46916+ }
46917+
46918+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
46919+ old_path.dentry, old_path.mnt, to)) {
46920+ error = -EACCES;
46921+ goto out_drop_write;
46922+ }
46923+
46924 error = security_path_link(old_path.dentry, &new_path, new_dentry);
46925 if (error)
46926 goto out_drop_write;
46927 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
46928+ if (!error)
46929+ gr_handle_create(new_dentry, new_path.mnt);
46930 out_drop_write:
46931 mnt_drop_write(new_path.mnt);
46932 out_dput:
46933+ putname(to);
46934 dput(new_dentry);
46935 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
46936 path_put(&new_path);
46937@@ -3299,6 +3504,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46938 if (new_dentry == trap)
46939 goto exit5;
46940
46941+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
46942+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
46943+ to);
46944+ if (error)
46945+ goto exit5;
46946+
46947 error = mnt_want_write(oldnd.path.mnt);
46948 if (error)
46949 goto exit5;
46950@@ -3308,6 +3519,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46951 goto exit6;
46952 error = vfs_rename(old_dir->d_inode, old_dentry,
46953 new_dir->d_inode, new_dentry);
46954+ if (!error)
46955+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
46956+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
46957 exit6:
46958 mnt_drop_write(oldnd.path.mnt);
46959 exit5:
46960@@ -3333,6 +3547,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
46961
46962 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
46963 {
46964+ char tmpbuf[64];
46965+ const char *newlink;
46966 int len;
46967
46968 len = PTR_ERR(link);
46969@@ -3342,7 +3558,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
46970 len = strlen(link);
46971 if (len > (unsigned) buflen)
46972 len = buflen;
46973- if (copy_to_user(buffer, link, len))
46974+
46975+ if (len < sizeof(tmpbuf)) {
46976+ memcpy(tmpbuf, link, len);
46977+ newlink = tmpbuf;
46978+ } else
46979+ newlink = link;
46980+
46981+ if (copy_to_user(buffer, newlink, len))
46982 len = -EFAULT;
46983 out:
46984 return len;
46985diff --git a/fs/namespace.c b/fs/namespace.c
46986index 4e46539..b28253c 100644
46987--- a/fs/namespace.c
46988+++ b/fs/namespace.c
46989@@ -1156,6 +1156,9 @@ static int do_umount(struct mount *mnt, int flags)
46990 if (!(sb->s_flags & MS_RDONLY))
46991 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
46992 up_write(&sb->s_umount);
46993+
46994+ gr_log_remount(mnt->mnt_devname, retval);
46995+
46996 return retval;
46997 }
46998
46999@@ -1175,6 +1178,9 @@ static int do_umount(struct mount *mnt, int flags)
47000 br_write_unlock(vfsmount_lock);
47001 up_write(&namespace_sem);
47002 release_mounts(&umount_list);
47003+
47004+ gr_log_unmount(mnt->mnt_devname, retval);
47005+
47006 return retval;
47007 }
47008
47009@@ -2176,6 +2182,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47010 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47011 MS_STRICTATIME);
47012
47013+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47014+ retval = -EPERM;
47015+ goto dput_out;
47016+ }
47017+
47018+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47019+ retval = -EPERM;
47020+ goto dput_out;
47021+ }
47022+
47023 if (flags & MS_REMOUNT)
47024 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47025 data_page);
47026@@ -2190,6 +2206,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47027 dev_name, data_page);
47028 dput_out:
47029 path_put(&path);
47030+
47031+ gr_log_mount(dev_name, dir_name, retval);
47032+
47033 return retval;
47034 }
47035
47036@@ -2471,6 +2490,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47037 if (error)
47038 goto out2;
47039
47040+ if (gr_handle_chroot_pivot()) {
47041+ error = -EPERM;
47042+ goto out2;
47043+ }
47044+
47045 get_fs_root(current->fs, &root);
47046 error = lock_mount(&old);
47047 if (error)
47048diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47049index e8bbfa5..864f936 100644
47050--- a/fs/nfs/inode.c
47051+++ b/fs/nfs/inode.c
47052@@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47053 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47054 nfsi->attrtimeo_timestamp = jiffies;
47055
47056- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47057+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47058 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47059 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47060 else
47061@@ -1005,16 +1005,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47062 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47063 }
47064
47065-static atomic_long_t nfs_attr_generation_counter;
47066+static atomic_long_unchecked_t nfs_attr_generation_counter;
47067
47068 static unsigned long nfs_read_attr_generation_counter(void)
47069 {
47070- return atomic_long_read(&nfs_attr_generation_counter);
47071+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47072 }
47073
47074 unsigned long nfs_inc_attr_generation_counter(void)
47075 {
47076- return atomic_long_inc_return(&nfs_attr_generation_counter);
47077+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47078 }
47079
47080 void nfs_fattr_init(struct nfs_fattr *fattr)
47081diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47082index 5686661..80a9a3a 100644
47083--- a/fs/nfsd/vfs.c
47084+++ b/fs/nfsd/vfs.c
47085@@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47086 } else {
47087 oldfs = get_fs();
47088 set_fs(KERNEL_DS);
47089- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47090+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47091 set_fs(oldfs);
47092 }
47093
47094@@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47095
47096 /* Write the data. */
47097 oldfs = get_fs(); set_fs(KERNEL_DS);
47098- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47099+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47100 set_fs(oldfs);
47101 if (host_err < 0)
47102 goto out_nfserr;
47103@@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47104 */
47105
47106 oldfs = get_fs(); set_fs(KERNEL_DS);
47107- host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
47108+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
47109 set_fs(oldfs);
47110
47111 if (host_err < 0)
47112diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47113index 3568c8a..e0240d8 100644
47114--- a/fs/notify/fanotify/fanotify_user.c
47115+++ b/fs/notify/fanotify/fanotify_user.c
47116@@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47117 goto out_close_fd;
47118
47119 ret = -EFAULT;
47120- if (copy_to_user(buf, &fanotify_event_metadata,
47121+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47122+ copy_to_user(buf, &fanotify_event_metadata,
47123 fanotify_event_metadata.event_len))
47124 goto out_kill_access_response;
47125
47126diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47127index c887b13..0fdf472 100644
47128--- a/fs/notify/notification.c
47129+++ b/fs/notify/notification.c
47130@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47131 * get set to 0 so it will never get 'freed'
47132 */
47133 static struct fsnotify_event *q_overflow_event;
47134-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47135+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47136
47137 /**
47138 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47139@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47140 */
47141 u32 fsnotify_get_cookie(void)
47142 {
47143- return atomic_inc_return(&fsnotify_sync_cookie);
47144+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47145 }
47146 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47147
47148diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47149index 99e3610..02c1068 100644
47150--- a/fs/ntfs/dir.c
47151+++ b/fs/ntfs/dir.c
47152@@ -1329,7 +1329,7 @@ find_next_index_buffer:
47153 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47154 ~(s64)(ndir->itype.index.block_size - 1)));
47155 /* Bounds checks. */
47156- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47157+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47158 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47159 "inode 0x%lx or driver bug.", vdir->i_ino);
47160 goto err_out;
47161diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47162index 8639169..76697aa 100644
47163--- a/fs/ntfs/file.c
47164+++ b/fs/ntfs/file.c
47165@@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47166 #endif /* NTFS_RW */
47167 };
47168
47169-const struct file_operations ntfs_empty_file_ops = {};
47170+const struct file_operations ntfs_empty_file_ops __read_only;
47171
47172-const struct inode_operations ntfs_empty_inode_ops = {};
47173+const struct inode_operations ntfs_empty_inode_ops __read_only;
47174diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47175index 210c352..a174f83 100644
47176--- a/fs/ocfs2/localalloc.c
47177+++ b/fs/ocfs2/localalloc.c
47178@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47179 goto bail;
47180 }
47181
47182- atomic_inc(&osb->alloc_stats.moves);
47183+ atomic_inc_unchecked(&osb->alloc_stats.moves);
47184
47185 bail:
47186 if (handle)
47187diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47188index d355e6e..578d905 100644
47189--- a/fs/ocfs2/ocfs2.h
47190+++ b/fs/ocfs2/ocfs2.h
47191@@ -235,11 +235,11 @@ enum ocfs2_vol_state
47192
47193 struct ocfs2_alloc_stats
47194 {
47195- atomic_t moves;
47196- atomic_t local_data;
47197- atomic_t bitmap_data;
47198- atomic_t bg_allocs;
47199- atomic_t bg_extends;
47200+ atomic_unchecked_t moves;
47201+ atomic_unchecked_t local_data;
47202+ atomic_unchecked_t bitmap_data;
47203+ atomic_unchecked_t bg_allocs;
47204+ atomic_unchecked_t bg_extends;
47205 };
47206
47207 enum ocfs2_local_alloc_state
47208diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47209index f169da4..9112253 100644
47210--- a/fs/ocfs2/suballoc.c
47211+++ b/fs/ocfs2/suballoc.c
47212@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47213 mlog_errno(status);
47214 goto bail;
47215 }
47216- atomic_inc(&osb->alloc_stats.bg_extends);
47217+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47218
47219 /* You should never ask for this much metadata */
47220 BUG_ON(bits_wanted >
47221@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47222 mlog_errno(status);
47223 goto bail;
47224 }
47225- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47226+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47227
47228 *suballoc_loc = res.sr_bg_blkno;
47229 *suballoc_bit_start = res.sr_bit_offset;
47230@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47231 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47232 res->sr_bits);
47233
47234- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47235+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47236
47237 BUG_ON(res->sr_bits != 1);
47238
47239@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47240 mlog_errno(status);
47241 goto bail;
47242 }
47243- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47244+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47245
47246 BUG_ON(res.sr_bits != 1);
47247
47248@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47249 cluster_start,
47250 num_clusters);
47251 if (!status)
47252- atomic_inc(&osb->alloc_stats.local_data);
47253+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
47254 } else {
47255 if (min_clusters > (osb->bitmap_cpg - 1)) {
47256 /* The only paths asking for contiguousness
47257@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47258 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47259 res.sr_bg_blkno,
47260 res.sr_bit_offset);
47261- atomic_inc(&osb->alloc_stats.bitmap_data);
47262+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47263 *num_clusters = res.sr_bits;
47264 }
47265 }
47266diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47267index 68f4541..89cfe6a 100644
47268--- a/fs/ocfs2/super.c
47269+++ b/fs/ocfs2/super.c
47270@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47271 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47272 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47273 "Stats",
47274- atomic_read(&osb->alloc_stats.bitmap_data),
47275- atomic_read(&osb->alloc_stats.local_data),
47276- atomic_read(&osb->alloc_stats.bg_allocs),
47277- atomic_read(&osb->alloc_stats.moves),
47278- atomic_read(&osb->alloc_stats.bg_extends));
47279+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47280+ atomic_read_unchecked(&osb->alloc_stats.local_data),
47281+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47282+ atomic_read_unchecked(&osb->alloc_stats.moves),
47283+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47284
47285 out += snprintf(buf + out, len - out,
47286 "%10s => State: %u Descriptor: %llu Size: %u bits "
47287@@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47288 spin_lock_init(&osb->osb_xattr_lock);
47289 ocfs2_init_steal_slots(osb);
47290
47291- atomic_set(&osb->alloc_stats.moves, 0);
47292- atomic_set(&osb->alloc_stats.local_data, 0);
47293- atomic_set(&osb->alloc_stats.bitmap_data, 0);
47294- atomic_set(&osb->alloc_stats.bg_allocs, 0);
47295- atomic_set(&osb->alloc_stats.bg_extends, 0);
47296+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47297+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47298+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47299+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47300+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47301
47302 /* Copy the blockcheck stats from the superblock probe */
47303 osb->osb_ecc_stats = *stats;
47304diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47305index 5d22872..523db20 100644
47306--- a/fs/ocfs2/symlink.c
47307+++ b/fs/ocfs2/symlink.c
47308@@ -142,7 +142,7 @@ bail:
47309
47310 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47311 {
47312- char *link = nd_get_link(nd);
47313+ const char *link = nd_get_link(nd);
47314 if (!IS_ERR(link))
47315 kfree(link);
47316 }
47317diff --git a/fs/open.c b/fs/open.c
47318index 3f1108b..822d7f7 100644
47319--- a/fs/open.c
47320+++ b/fs/open.c
47321@@ -31,6 +31,8 @@
47322 #include <linux/ima.h>
47323 #include <linux/dnotify.h>
47324
47325+#define CREATE_TRACE_POINTS
47326+#include <trace/events/fs.h>
47327 #include "internal.h"
47328
47329 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
47330@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47331 error = locks_verify_truncate(inode, NULL, length);
47332 if (!error)
47333 error = security_path_truncate(&path);
47334+
47335+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47336+ error = -EACCES;
47337+
47338 if (!error)
47339 error = do_truncate(path.dentry, length, 0, NULL);
47340
47341@@ -358,6 +364,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47342 if (__mnt_is_readonly(path.mnt))
47343 res = -EROFS;
47344
47345+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47346+ res = -EACCES;
47347+
47348 out_path_release:
47349 path_put(&path);
47350 out:
47351@@ -384,6 +393,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47352 if (error)
47353 goto dput_and_out;
47354
47355+ gr_log_chdir(path.dentry, path.mnt);
47356+
47357 set_fs_pwd(current->fs, &path);
47358
47359 dput_and_out:
47360@@ -410,6 +421,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47361 goto out_putf;
47362
47363 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47364+
47365+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47366+ error = -EPERM;
47367+
47368+ if (!error)
47369+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47370+
47371 if (!error)
47372 set_fs_pwd(current->fs, &file->f_path);
47373 out_putf:
47374@@ -438,7 +456,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47375 if (error)
47376 goto dput_and_out;
47377
47378+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47379+ goto dput_and_out;
47380+
47381 set_fs_root(current->fs, &path);
47382+
47383+ gr_handle_chroot_chdir(&path);
47384+
47385 error = 0;
47386 dput_and_out:
47387 path_put(&path);
47388@@ -456,6 +480,16 @@ static int chmod_common(struct path *path, umode_t mode)
47389 if (error)
47390 return error;
47391 mutex_lock(&inode->i_mutex);
47392+
47393+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47394+ error = -EACCES;
47395+ goto out_unlock;
47396+ }
47397+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47398+ error = -EACCES;
47399+ goto out_unlock;
47400+ }
47401+
47402 error = security_path_chmod(path, mode);
47403 if (error)
47404 goto out_unlock;
47405@@ -506,6 +540,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47406 int error;
47407 struct iattr newattrs;
47408
47409+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
47410+ return -EACCES;
47411+
47412 newattrs.ia_valid = ATTR_CTIME;
47413 if (user != (uid_t) -1) {
47414 newattrs.ia_valid |= ATTR_UID;
47415@@ -987,6 +1024,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
47416 } else {
47417 fsnotify_open(f);
47418 fd_install(fd, f);
47419+ trace_do_sys_open(tmp, flags, mode);
47420 }
47421 }
47422 putname(tmp);
47423diff --git a/fs/pipe.c b/fs/pipe.c
47424index fec5e4a..f4210f9 100644
47425--- a/fs/pipe.c
47426+++ b/fs/pipe.c
47427@@ -438,9 +438,9 @@ redo:
47428 }
47429 if (bufs) /* More to do? */
47430 continue;
47431- if (!pipe->writers)
47432+ if (!atomic_read(&pipe->writers))
47433 break;
47434- if (!pipe->waiting_writers) {
47435+ if (!atomic_read(&pipe->waiting_writers)) {
47436 /* syscall merging: Usually we must not sleep
47437 * if O_NONBLOCK is set, or if we got some data.
47438 * But if a writer sleeps in kernel space, then
47439@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47440 mutex_lock(&inode->i_mutex);
47441 pipe = inode->i_pipe;
47442
47443- if (!pipe->readers) {
47444+ if (!atomic_read(&pipe->readers)) {
47445 send_sig(SIGPIPE, current, 0);
47446 ret = -EPIPE;
47447 goto out;
47448@@ -553,7 +553,7 @@ redo1:
47449 for (;;) {
47450 int bufs;
47451
47452- if (!pipe->readers) {
47453+ if (!atomic_read(&pipe->readers)) {
47454 send_sig(SIGPIPE, current, 0);
47455 if (!ret)
47456 ret = -EPIPE;
47457@@ -644,9 +644,9 @@ redo2:
47458 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47459 do_wakeup = 0;
47460 }
47461- pipe->waiting_writers++;
47462+ atomic_inc(&pipe->waiting_writers);
47463 pipe_wait(pipe);
47464- pipe->waiting_writers--;
47465+ atomic_dec(&pipe->waiting_writers);
47466 }
47467 out:
47468 mutex_unlock(&inode->i_mutex);
47469@@ -713,7 +713,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47470 mask = 0;
47471 if (filp->f_mode & FMODE_READ) {
47472 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47473- if (!pipe->writers && filp->f_version != pipe->w_counter)
47474+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47475 mask |= POLLHUP;
47476 }
47477
47478@@ -723,7 +723,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47479 * Most Unices do not set POLLERR for FIFOs but on Linux they
47480 * behave exactly like pipes for poll().
47481 */
47482- if (!pipe->readers)
47483+ if (!atomic_read(&pipe->readers))
47484 mask |= POLLERR;
47485 }
47486
47487@@ -737,10 +737,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47488
47489 mutex_lock(&inode->i_mutex);
47490 pipe = inode->i_pipe;
47491- pipe->readers -= decr;
47492- pipe->writers -= decw;
47493+ atomic_sub(decr, &pipe->readers);
47494+ atomic_sub(decw, &pipe->writers);
47495
47496- if (!pipe->readers && !pipe->writers) {
47497+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47498 free_pipe_info(inode);
47499 } else {
47500 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47501@@ -830,7 +830,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47502
47503 if (inode->i_pipe) {
47504 ret = 0;
47505- inode->i_pipe->readers++;
47506+ atomic_inc(&inode->i_pipe->readers);
47507 }
47508
47509 mutex_unlock(&inode->i_mutex);
47510@@ -847,7 +847,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47511
47512 if (inode->i_pipe) {
47513 ret = 0;
47514- inode->i_pipe->writers++;
47515+ atomic_inc(&inode->i_pipe->writers);
47516 }
47517
47518 mutex_unlock(&inode->i_mutex);
47519@@ -865,9 +865,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47520 if (inode->i_pipe) {
47521 ret = 0;
47522 if (filp->f_mode & FMODE_READ)
47523- inode->i_pipe->readers++;
47524+ atomic_inc(&inode->i_pipe->readers);
47525 if (filp->f_mode & FMODE_WRITE)
47526- inode->i_pipe->writers++;
47527+ atomic_inc(&inode->i_pipe->writers);
47528 }
47529
47530 mutex_unlock(&inode->i_mutex);
47531@@ -959,7 +959,7 @@ void free_pipe_info(struct inode *inode)
47532 inode->i_pipe = NULL;
47533 }
47534
47535-static struct vfsmount *pipe_mnt __read_mostly;
47536+struct vfsmount *pipe_mnt __read_mostly;
47537
47538 /*
47539 * pipefs_dname() is called from d_path().
47540@@ -989,7 +989,8 @@ static struct inode * get_pipe_inode(void)
47541 goto fail_iput;
47542 inode->i_pipe = pipe;
47543
47544- pipe->readers = pipe->writers = 1;
47545+ atomic_set(&pipe->readers, 1);
47546+ atomic_set(&pipe->writers, 1);
47547 inode->i_fop = &rdwr_pipefifo_fops;
47548
47549 /*
47550diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47551index 15af622..0e9f4467 100644
47552--- a/fs/proc/Kconfig
47553+++ b/fs/proc/Kconfig
47554@@ -30,12 +30,12 @@ config PROC_FS
47555
47556 config PROC_KCORE
47557 bool "/proc/kcore support" if !ARM
47558- depends on PROC_FS && MMU
47559+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47560
47561 config PROC_VMCORE
47562 bool "/proc/vmcore support"
47563- depends on PROC_FS && CRASH_DUMP
47564- default y
47565+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47566+ default n
47567 help
47568 Exports the dump image of crashed kernel in ELF format.
47569
47570@@ -59,8 +59,8 @@ config PROC_SYSCTL
47571 limited in memory.
47572
47573 config PROC_PAGE_MONITOR
47574- default y
47575- depends on PROC_FS && MMU
47576+ default n
47577+ depends on PROC_FS && MMU && !GRKERNSEC
47578 bool "Enable /proc page monitoring" if EXPERT
47579 help
47580 Various /proc files exist to monitor process memory utilization:
47581diff --git a/fs/proc/array.c b/fs/proc/array.c
47582index f9bd395..acb7847 100644
47583--- a/fs/proc/array.c
47584+++ b/fs/proc/array.c
47585@@ -60,6 +60,7 @@
47586 #include <linux/tty.h>
47587 #include <linux/string.h>
47588 #include <linux/mman.h>
47589+#include <linux/grsecurity.h>
47590 #include <linux/proc_fs.h>
47591 #include <linux/ioport.h>
47592 #include <linux/uaccess.h>
47593@@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
47594 seq_putc(m, '\n');
47595 }
47596
47597+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47598+static inline void task_pax(struct seq_file *m, struct task_struct *p)
47599+{
47600+ if (p->mm)
47601+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
47602+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
47603+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
47604+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
47605+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
47606+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
47607+ else
47608+ seq_printf(m, "PaX:\t-----\n");
47609+}
47610+#endif
47611+
47612 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47613 struct pid *pid, struct task_struct *task)
47614 {
47615@@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47616 task_cpus_allowed(m, task);
47617 cpuset_task_status_allowed(m, task);
47618 task_context_switch_counts(m, task);
47619+
47620+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47621+ task_pax(m, task);
47622+#endif
47623+
47624+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
47625+ task_grsec_rbac(m, task);
47626+#endif
47627+
47628 return 0;
47629 }
47630
47631+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47632+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47633+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
47634+ _mm->pax_flags & MF_PAX_SEGMEXEC))
47635+#endif
47636+
47637 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47638 struct pid *pid, struct task_struct *task, int whole)
47639 {
47640@@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47641 char tcomm[sizeof(task->comm)];
47642 unsigned long flags;
47643
47644+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47645+ if (current->exec_id != m->exec_id) {
47646+ gr_log_badprocpid("stat");
47647+ return 0;
47648+ }
47649+#endif
47650+
47651 state = *get_task_state(task);
47652 vsize = eip = esp = 0;
47653 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47654@@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47655 gtime = task->gtime;
47656 }
47657
47658+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47659+ if (PAX_RAND_FLAGS(mm)) {
47660+ eip = 0;
47661+ esp = 0;
47662+ wchan = 0;
47663+ }
47664+#endif
47665+#ifdef CONFIG_GRKERNSEC_HIDESYM
47666+ wchan = 0;
47667+ eip =0;
47668+ esp =0;
47669+#endif
47670+
47671 /* scale priority and nice values from timeslices to -20..20 */
47672 /* to make it look like a "normal" Unix priority/nice value */
47673 priority = task_prio(task);
47674@@ -485,9 +536,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47675 seq_put_decimal_ull(m, ' ', vsize);
47676 seq_put_decimal_ll(m, ' ', mm ? get_mm_rss(mm) : 0);
47677 seq_put_decimal_ull(m, ' ', rsslim);
47678+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47679+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
47680+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
47681+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
47682+#else
47683 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
47684 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
47685 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
47686+#endif
47687 seq_put_decimal_ull(m, ' ', esp);
47688 seq_put_decimal_ull(m, ' ', eip);
47689 /* The signal information here is obsolete.
47690@@ -508,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47691 seq_put_decimal_ull(m, ' ', delayacct_blkio_ticks(task));
47692 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
47693 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
47694+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47695+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->start_data : 0));
47696+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->end_data : 0));
47697+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->start_brk : 0));
47698+#else
47699 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_data : 0);
47700 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->end_data : 0);
47701 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_brk : 0);
47702+#endif
47703 seq_putc(m, '\n');
47704 if (mm)
47705 mmput(mm);
47706@@ -533,8 +596,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47707 struct pid *pid, struct task_struct *task)
47708 {
47709 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
47710- struct mm_struct *mm = get_task_mm(task);
47711+ struct mm_struct *mm;
47712
47713+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47714+ if (current->exec_id != m->exec_id) {
47715+ gr_log_badprocpid("statm");
47716+ return 0;
47717+ }
47718+#endif
47719+ mm = get_task_mm(task);
47720 if (mm) {
47721 size = task_statm(mm, &shared, &text, &data, &resident);
47722 mmput(mm);
47723@@ -556,3 +626,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47724
47725 return 0;
47726 }
47727+
47728+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47729+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
47730+{
47731+ u32 curr_ip = 0;
47732+ unsigned long flags;
47733+
47734+ if (lock_task_sighand(task, &flags)) {
47735+ curr_ip = task->signal->curr_ip;
47736+ unlock_task_sighand(task, &flags);
47737+ }
47738+
47739+ return sprintf(buffer, "%pI4\n", &curr_ip);
47740+}
47741+#endif
47742diff --git a/fs/proc/base.c b/fs/proc/base.c
47743index 9fc77b4..4877d08 100644
47744--- a/fs/proc/base.c
47745+++ b/fs/proc/base.c
47746@@ -109,6 +109,14 @@ struct pid_entry {
47747 union proc_op op;
47748 };
47749
47750+struct getdents_callback {
47751+ struct linux_dirent __user * current_dir;
47752+ struct linux_dirent __user * previous;
47753+ struct file * file;
47754+ int count;
47755+ int error;
47756+};
47757+
47758 #define NOD(NAME, MODE, IOP, FOP, OP) { \
47759 .name = (NAME), \
47760 .len = sizeof(NAME) - 1, \
47761@@ -198,11 +206,6 @@ static int proc_root_link(struct dentry *dentry, struct path *path)
47762 return result;
47763 }
47764
47765-struct mm_struct *mm_for_maps(struct task_struct *task)
47766-{
47767- return mm_access(task, PTRACE_MODE_READ);
47768-}
47769-
47770 static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47771 {
47772 int res = 0;
47773@@ -213,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47774 if (!mm->arg_end)
47775 goto out_mm; /* Shh! No looking before we're done */
47776
47777+ if (gr_acl_handle_procpidmem(task))
47778+ goto out_mm;
47779+
47780 len = mm->arg_end - mm->arg_start;
47781
47782 if (len > PAGE_SIZE)
47783@@ -240,12 +246,28 @@ out:
47784 return res;
47785 }
47786
47787+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47788+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47789+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
47790+ _mm->pax_flags & MF_PAX_SEGMEXEC))
47791+#endif
47792+
47793 static int proc_pid_auxv(struct task_struct *task, char *buffer)
47794 {
47795- struct mm_struct *mm = mm_for_maps(task);
47796+ struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
47797 int res = PTR_ERR(mm);
47798 if (mm && !IS_ERR(mm)) {
47799 unsigned int nwords = 0;
47800+
47801+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47802+ /* allow if we're currently ptracing this task */
47803+ if (PAX_RAND_FLAGS(mm) &&
47804+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
47805+ mmput(mm);
47806+ return 0;
47807+ }
47808+#endif
47809+
47810 do {
47811 nwords += 2;
47812 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
47813@@ -259,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
47814 }
47815
47816
47817-#ifdef CONFIG_KALLSYMS
47818+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47819 /*
47820 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
47821 * Returns the resolved symbol. If that fails, simply return the address.
47822@@ -298,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
47823 mutex_unlock(&task->signal->cred_guard_mutex);
47824 }
47825
47826-#ifdef CONFIG_STACKTRACE
47827+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47828
47829 #define MAX_STACK_TRACE_DEPTH 64
47830
47831@@ -489,7 +511,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
47832 return count;
47833 }
47834
47835-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47836+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47837 static int proc_pid_syscall(struct task_struct *task, char *buffer)
47838 {
47839 long nr;
47840@@ -518,7 +540,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
47841 /************************************************************************/
47842
47843 /* permission checks */
47844-static int proc_fd_access_allowed(struct inode *inode)
47845+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
47846 {
47847 struct task_struct *task;
47848 int allowed = 0;
47849@@ -528,7 +550,10 @@ static int proc_fd_access_allowed(struct inode *inode)
47850 */
47851 task = get_proc_task(inode);
47852 if (task) {
47853- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47854+ if (log)
47855+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47856+ else
47857+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47858 put_task_struct(task);
47859 }
47860 return allowed;
47861@@ -566,10 +591,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
47862 struct task_struct *task,
47863 int hide_pid_min)
47864 {
47865+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47866+ return false;
47867+
47868+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47869+ rcu_read_lock();
47870+ {
47871+ const struct cred *tmpcred = current_cred();
47872+ const struct cred *cred = __task_cred(task);
47873+
47874+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
47875+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47876+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
47877+#endif
47878+ ) {
47879+ rcu_read_unlock();
47880+ return true;
47881+ }
47882+ }
47883+ rcu_read_unlock();
47884+
47885+ if (!pid->hide_pid)
47886+ return false;
47887+#endif
47888+
47889 if (pid->hide_pid < hide_pid_min)
47890 return true;
47891 if (in_group_p(pid->pid_gid))
47892 return true;
47893+
47894 return ptrace_may_access(task, PTRACE_MODE_READ);
47895 }
47896
47897@@ -587,7 +637,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
47898 put_task_struct(task);
47899
47900 if (!has_perms) {
47901+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47902+ {
47903+#else
47904 if (pid->hide_pid == 2) {
47905+#endif
47906 /*
47907 * Let's make getdents(), stat(), and open()
47908 * consistent with each other. If a process
47909@@ -677,7 +731,7 @@ static const struct file_operations proc_single_file_operations = {
47910 .release = single_release,
47911 };
47912
47913-static int mem_open(struct inode* inode, struct file* file)
47914+static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
47915 {
47916 struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
47917 struct mm_struct *mm;
47918@@ -685,7 +739,12 @@ static int mem_open(struct inode* inode, struct file* file)
47919 if (!task)
47920 return -ESRCH;
47921
47922- mm = mm_access(task, PTRACE_MODE_ATTACH);
47923+ if (gr_acl_handle_procpidmem(task)) {
47924+ put_task_struct(task);
47925+ return -EPERM;
47926+ }
47927+
47928+ mm = mm_access(task, mode);
47929 put_task_struct(task);
47930
47931 if (IS_ERR(mm))
47932@@ -698,11 +757,24 @@ static int mem_open(struct inode* inode, struct file* file)
47933 mmput(mm);
47934 }
47935
47936+ file->private_data = mm;
47937+
47938+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47939+ file->f_version = current->exec_id;
47940+#endif
47941+
47942+ return 0;
47943+}
47944+
47945+static int mem_open(struct inode *inode, struct file *file)
47946+{
47947+ int ret;
47948+ ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);
47949+
47950 /* OK to pass negative loff_t, we can catch out-of-range */
47951 file->f_mode |= FMODE_UNSIGNED_OFFSET;
47952- file->private_data = mm;
47953
47954- return 0;
47955+ return ret;
47956 }
47957
47958 static ssize_t mem_rw(struct file *file, char __user *buf,
47959@@ -713,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
47960 ssize_t copied;
47961 char *page;
47962
47963+#ifdef CONFIG_GRKERNSEC
47964+ if (write)
47965+ return -EPERM;
47966+#endif
47967+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47968+ if (file->f_version != current->exec_id) {
47969+ gr_log_badprocpid("mem");
47970+ return 0;
47971+ }
47972+#endif
47973+
47974 if (!mm)
47975 return 0;
47976
47977@@ -801,42 +884,49 @@ static const struct file_operations proc_mem_operations = {
47978 .release = mem_release,
47979 };
47980
47981+static int environ_open(struct inode *inode, struct file *file)
47982+{
47983+ return __mem_open(inode, file, PTRACE_MODE_READ);
47984+}
47985+
47986 static ssize_t environ_read(struct file *file, char __user *buf,
47987 size_t count, loff_t *ppos)
47988 {
47989- struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
47990 char *page;
47991 unsigned long src = *ppos;
47992- int ret = -ESRCH;
47993- struct mm_struct *mm;
47994+ int ret = 0;
47995+ struct mm_struct *mm = file->private_data;
47996
47997- if (!task)
47998- goto out_no_task;
47999+ if (!mm)
48000+ return 0;
48001+
48002+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48003+ if (file->f_version != current->exec_id) {
48004+ gr_log_badprocpid("environ");
48005+ return 0;
48006+ }
48007+#endif
48008
48009- ret = -ENOMEM;
48010 page = (char *)__get_free_page(GFP_TEMPORARY);
48011 if (!page)
48012- goto out;
48013-
48014-
48015- mm = mm_for_maps(task);
48016- ret = PTR_ERR(mm);
48017- if (!mm || IS_ERR(mm))
48018- goto out_free;
48019+ return -ENOMEM;
48020
48021 ret = 0;
48022+ if (!atomic_inc_not_zero(&mm->mm_users))
48023+ goto free;
48024 while (count > 0) {
48025- int this_len, retval, max_len;
48026+ size_t this_len, max_len;
48027+ int retval;
48028+
48029+ if (src >= (mm->env_end - mm->env_start))
48030+ break;
48031
48032 this_len = mm->env_end - (mm->env_start + src);
48033
48034- if (this_len <= 0)
48035- break;
48036+ max_len = min_t(size_t, PAGE_SIZE, count);
48037+ this_len = min(max_len, this_len);
48038
48039- max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
48040- this_len = (this_len > max_len) ? max_len : this_len;
48041-
48042- retval = access_process_vm(task, (mm->env_start + src),
48043+ retval = access_remote_vm(mm, (mm->env_start + src),
48044 page, this_len, 0);
48045
48046 if (retval <= 0) {
48047@@ -855,19 +945,18 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48048 count -= retval;
48049 }
48050 *ppos = src;
48051-
48052 mmput(mm);
48053-out_free:
48054+
48055+free:
48056 free_page((unsigned long) page);
48057-out:
48058- put_task_struct(task);
48059-out_no_task:
48060 return ret;
48061 }
48062
48063 static const struct file_operations proc_environ_operations = {
48064+ .open = environ_open,
48065 .read = environ_read,
48066 .llseek = generic_file_llseek,
48067+ .release = mem_release,
48068 };
48069
48070 static ssize_t oom_adjust_read(struct file *file, char __user *buf,
48071@@ -1433,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48072 path_put(&nd->path);
48073
48074 /* Are we allowed to snoop on the tasks file descriptors? */
48075- if (!proc_fd_access_allowed(inode))
48076+ if (!proc_fd_access_allowed(inode, 0))
48077 goto out;
48078
48079 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48080@@ -1472,8 +1561,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48081 struct path path;
48082
48083 /* Are we allowed to snoop on the tasks file descriptors? */
48084- if (!proc_fd_access_allowed(inode))
48085- goto out;
48086+ /* logging this is needed for learning on chromium to work properly,
48087+ but we don't want to flood the logs from 'ps' which does a readlink
48088+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48089+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
48090+ */
48091+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48092+ if (!proc_fd_access_allowed(inode,0))
48093+ goto out;
48094+ } else {
48095+ if (!proc_fd_access_allowed(inode,1))
48096+ goto out;
48097+ }
48098
48099 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48100 if (error)
48101@@ -1538,7 +1637,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48102 rcu_read_lock();
48103 cred = __task_cred(task);
48104 inode->i_uid = cred->euid;
48105+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48106+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48107+#else
48108 inode->i_gid = cred->egid;
48109+#endif
48110 rcu_read_unlock();
48111 }
48112 security_task_to_inode(task, inode);
48113@@ -1574,10 +1677,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48114 return -ENOENT;
48115 }
48116 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48117+#ifdef CONFIG_GRKERNSEC_PROC_USER
48118+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48119+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48120+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48121+#endif
48122 task_dumpable(task)) {
48123 cred = __task_cred(task);
48124 stat->uid = cred->euid;
48125+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48126+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48127+#else
48128 stat->gid = cred->egid;
48129+#endif
48130 }
48131 }
48132 rcu_read_unlock();
48133@@ -1615,11 +1727,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48134
48135 if (task) {
48136 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48137+#ifdef CONFIG_GRKERNSEC_PROC_USER
48138+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48139+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48140+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48141+#endif
48142 task_dumpable(task)) {
48143 rcu_read_lock();
48144 cred = __task_cred(task);
48145 inode->i_uid = cred->euid;
48146+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48147+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48148+#else
48149 inode->i_gid = cred->egid;
48150+#endif
48151 rcu_read_unlock();
48152 } else {
48153 inode->i_uid = 0;
48154@@ -1737,7 +1858,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48155 int fd = proc_fd(inode);
48156
48157 if (task) {
48158- files = get_files_struct(task);
48159+ if (!gr_acl_handle_procpidmem(task))
48160+ files = get_files_struct(task);
48161 put_task_struct(task);
48162 }
48163 if (files) {
48164@@ -2025,11 +2147,8 @@ static int map_files_d_revalidate(struct dentry *dentry, struct nameidata *nd)
48165 if (!task)
48166 goto out_notask;
48167
48168- if (!ptrace_may_access(task, PTRACE_MODE_READ))
48169- goto out;
48170-
48171- mm = get_task_mm(task);
48172- if (!mm)
48173+ mm = mm_access(task, PTRACE_MODE_READ);
48174+ if (IS_ERR_OR_NULL(mm))
48175 goto out;
48176
48177 if (!dname_to_vma_addr(dentry, &vm_start, &vm_end)) {
48178@@ -2338,11 +2457,21 @@ static const struct file_operations proc_map_files_operations = {
48179 */
48180 static int proc_fd_permission(struct inode *inode, int mask)
48181 {
48182+ struct task_struct *task;
48183 int rv = generic_permission(inode, mask);
48184- if (rv == 0)
48185- return 0;
48186+
48187 if (task_pid(current) == proc_pid(inode))
48188 rv = 0;
48189+
48190+ task = get_proc_task(inode);
48191+ if (task == NULL)
48192+ return rv;
48193+
48194+ if (gr_acl_handle_procpidmem(task))
48195+ rv = -EACCES;
48196+
48197+ put_task_struct(task);
48198+
48199 return rv;
48200 }
48201
48202@@ -2452,6 +2581,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48203 if (!task)
48204 goto out_no_task;
48205
48206+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48207+ goto out;
48208+
48209 /*
48210 * Yes, it does not scale. And it should not. Don't add
48211 * new entries into /proc/<tgid>/ without very good reasons.
48212@@ -2496,6 +2628,9 @@ static int proc_pident_readdir(struct file *filp,
48213 if (!task)
48214 goto out_no_task;
48215
48216+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48217+ goto out;
48218+
48219 ret = 0;
48220 i = filp->f_pos;
48221 switch (i) {
48222@@ -2766,7 +2901,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48223 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48224 void *cookie)
48225 {
48226- char *s = nd_get_link(nd);
48227+ const char *s = nd_get_link(nd);
48228 if (!IS_ERR(s))
48229 __putname(s);
48230 }
48231@@ -2967,7 +3102,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48232 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48233 #endif
48234 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48235-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48236+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48237 INF("syscall", S_IRUGO, proc_pid_syscall),
48238 #endif
48239 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48240@@ -2992,10 +3127,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48241 #ifdef CONFIG_SECURITY
48242 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48243 #endif
48244-#ifdef CONFIG_KALLSYMS
48245+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48246 INF("wchan", S_IRUGO, proc_pid_wchan),
48247 #endif
48248-#ifdef CONFIG_STACKTRACE
48249+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48250 ONE("stack", S_IRUGO, proc_pid_stack),
48251 #endif
48252 #ifdef CONFIG_SCHEDSTATS
48253@@ -3029,6 +3164,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48254 #ifdef CONFIG_HARDWALL
48255 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48256 #endif
48257+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48258+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48259+#endif
48260 };
48261
48262 static int proc_tgid_base_readdir(struct file * filp,
48263@@ -3155,7 +3293,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48264 if (!inode)
48265 goto out;
48266
48267+#ifdef CONFIG_GRKERNSEC_PROC_USER
48268+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48269+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48270+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48271+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48272+#else
48273 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48274+#endif
48275 inode->i_op = &proc_tgid_base_inode_operations;
48276 inode->i_fop = &proc_tgid_base_operations;
48277 inode->i_flags|=S_IMMUTABLE;
48278@@ -3197,7 +3342,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48279 if (!task)
48280 goto out;
48281
48282+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48283+ goto out_put_task;
48284+
48285 result = proc_pid_instantiate(dir, dentry, task, NULL);
48286+out_put_task:
48287 put_task_struct(task);
48288 out:
48289 return result;
48290@@ -3260,6 +3409,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48291 static int fake_filldir(void *buf, const char *name, int namelen,
48292 loff_t offset, u64 ino, unsigned d_type)
48293 {
48294+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
48295+ __buf->error = -EINVAL;
48296 return 0;
48297 }
48298
48299@@ -3326,7 +3477,7 @@ static const struct pid_entry tid_base_stuff[] = {
48300 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48301 #endif
48302 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48303-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48304+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48305 INF("syscall", S_IRUGO, proc_pid_syscall),
48306 #endif
48307 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48308@@ -3350,10 +3501,10 @@ static const struct pid_entry tid_base_stuff[] = {
48309 #ifdef CONFIG_SECURITY
48310 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48311 #endif
48312-#ifdef CONFIG_KALLSYMS
48313+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48314 INF("wchan", S_IRUGO, proc_pid_wchan),
48315 #endif
48316-#ifdef CONFIG_STACKTRACE
48317+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48318 ONE("stack", S_IRUGO, proc_pid_stack),
48319 #endif
48320 #ifdef CONFIG_SCHEDSTATS
48321diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48322index 82676e3..5f8518a 100644
48323--- a/fs/proc/cmdline.c
48324+++ b/fs/proc/cmdline.c
48325@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48326
48327 static int __init proc_cmdline_init(void)
48328 {
48329+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48330+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48331+#else
48332 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48333+#endif
48334 return 0;
48335 }
48336 module_init(proc_cmdline_init);
48337diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48338index b143471..bb105e5 100644
48339--- a/fs/proc/devices.c
48340+++ b/fs/proc/devices.c
48341@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48342
48343 static int __init proc_devices_init(void)
48344 {
48345+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48346+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48347+#else
48348 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48349+#endif
48350 return 0;
48351 }
48352 module_init(proc_devices_init);
48353diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48354index 205c922..2ee4c57 100644
48355--- a/fs/proc/inode.c
48356+++ b/fs/proc/inode.c
48357@@ -21,11 +21,17 @@
48358 #include <linux/seq_file.h>
48359 #include <linux/slab.h>
48360 #include <linux/mount.h>
48361+#include <linux/grsecurity.h>
48362
48363 #include <asm/uaccess.h>
48364
48365 #include "internal.h"
48366
48367+#ifdef CONFIG_PROC_SYSCTL
48368+extern const struct inode_operations proc_sys_inode_operations;
48369+extern const struct inode_operations proc_sys_dir_operations;
48370+#endif
48371+
48372 static void proc_evict_inode(struct inode *inode)
48373 {
48374 struct proc_dir_entry *de;
48375@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
48376 ns_ops = PROC_I(inode)->ns_ops;
48377 if (ns_ops && ns_ops->put)
48378 ns_ops->put(PROC_I(inode)->ns);
48379+
48380+#ifdef CONFIG_PROC_SYSCTL
48381+ if (inode->i_op == &proc_sys_inode_operations ||
48382+ inode->i_op == &proc_sys_dir_operations)
48383+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48384+#endif
48385+
48386 }
48387
48388 static struct kmem_cache * proc_inode_cachep;
48389@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48390 if (de->mode) {
48391 inode->i_mode = de->mode;
48392 inode->i_uid = de->uid;
48393+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48394+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48395+#else
48396 inode->i_gid = de->gid;
48397+#endif
48398 }
48399 if (de->size)
48400 inode->i_size = de->size;
48401diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48402index 5f79bb8..e9ab85d 100644
48403--- a/fs/proc/internal.h
48404+++ b/fs/proc/internal.h
48405@@ -31,8 +31,6 @@ struct vmalloc_info {
48406 unsigned long largest_chunk;
48407 };
48408
48409-extern struct mm_struct *mm_for_maps(struct task_struct *);
48410-
48411 #ifdef CONFIG_MMU
48412 #define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START)
48413 extern void get_vmalloc_info(struct vmalloc_info *vmi);
48414@@ -54,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48415 struct pid *pid, struct task_struct *task);
48416 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48417 struct pid *pid, struct task_struct *task);
48418+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48419+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48420+#endif
48421 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48422
48423 extern const struct file_operations proc_pid_maps_operations;
48424diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48425index 86c67ee..cdca321 100644
48426--- a/fs/proc/kcore.c
48427+++ b/fs/proc/kcore.c
48428@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48429 * the addresses in the elf_phdr on our list.
48430 */
48431 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48432- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48433+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48434+ if (tsz > buflen)
48435 tsz = buflen;
48436-
48437+
48438 while (buflen) {
48439 struct kcore_list *m;
48440
48441@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48442 kfree(elf_buf);
48443 } else {
48444 if (kern_addr_valid(start)) {
48445- unsigned long n;
48446+ char *elf_buf;
48447+ mm_segment_t oldfs;
48448
48449- n = copy_to_user(buffer, (char *)start, tsz);
48450- /*
48451- * We cannot distinguish between fault on source
48452- * and fault on destination. When this happens
48453- * we clear too and hope it will trigger the
48454- * EFAULT again.
48455- */
48456- if (n) {
48457- if (clear_user(buffer + tsz - n,
48458- n))
48459+ elf_buf = kmalloc(tsz, GFP_KERNEL);
48460+ if (!elf_buf)
48461+ return -ENOMEM;
48462+ oldfs = get_fs();
48463+ set_fs(KERNEL_DS);
48464+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48465+ set_fs(oldfs);
48466+ if (copy_to_user(buffer, elf_buf, tsz)) {
48467+ kfree(elf_buf);
48468 return -EFAULT;
48469+ }
48470 }
48471+ set_fs(oldfs);
48472+ kfree(elf_buf);
48473 } else {
48474 if (clear_user(buffer, tsz))
48475 return -EFAULT;
48476@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48477
48478 static int open_kcore(struct inode *inode, struct file *filp)
48479 {
48480+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48481+ return -EPERM;
48482+#endif
48483 if (!capable(CAP_SYS_RAWIO))
48484 return -EPERM;
48485 if (kcore_need_update)
48486diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48487index 80e4645..53e5fcf 100644
48488--- a/fs/proc/meminfo.c
48489+++ b/fs/proc/meminfo.c
48490@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48491 vmi.used >> 10,
48492 vmi.largest_chunk >> 10
48493 #ifdef CONFIG_MEMORY_FAILURE
48494- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48495+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48496 #endif
48497 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48498 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48499diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48500index b1822dd..df622cb 100644
48501--- a/fs/proc/nommu.c
48502+++ b/fs/proc/nommu.c
48503@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48504 if (len < 1)
48505 len = 1;
48506 seq_printf(m, "%*c", len, ' ');
48507- seq_path(m, &file->f_path, "");
48508+ seq_path(m, &file->f_path, "\n\\");
48509 }
48510
48511 seq_putc(m, '\n');
48512diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48513index 06e1cc1..177cd98 100644
48514--- a/fs/proc/proc_net.c
48515+++ b/fs/proc/proc_net.c
48516@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48517 struct task_struct *task;
48518 struct nsproxy *ns;
48519 struct net *net = NULL;
48520+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48521+ const struct cred *cred = current_cred();
48522+#endif
48523+
48524+#ifdef CONFIG_GRKERNSEC_PROC_USER
48525+ if (cred->fsuid)
48526+ return net;
48527+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48528+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48529+ return net;
48530+#endif
48531
48532 rcu_read_lock();
48533 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48534diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48535index 21d836f..bebf3ee 100644
48536--- a/fs/proc/proc_sysctl.c
48537+++ b/fs/proc/proc_sysctl.c
48538@@ -12,11 +12,15 @@
48539 #include <linux/module.h>
48540 #include "internal.h"
48541
48542+extern int gr_handle_chroot_sysctl(const int op);
48543+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
48544+ const int op);
48545+
48546 static const struct dentry_operations proc_sys_dentry_operations;
48547 static const struct file_operations proc_sys_file_operations;
48548-static const struct inode_operations proc_sys_inode_operations;
48549+const struct inode_operations proc_sys_inode_operations;
48550 static const struct file_operations proc_sys_dir_file_operations;
48551-static const struct inode_operations proc_sys_dir_operations;
48552+const struct inode_operations proc_sys_dir_operations;
48553
48554 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48555 {
48556@@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48557
48558 err = NULL;
48559 d_set_d_op(dentry, &proc_sys_dentry_operations);
48560+
48561+ gr_handle_proc_create(dentry, inode);
48562+
48563 d_add(dentry, inode);
48564
48565+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
48566+ err = ERR_PTR(-ENOENT);
48567+
48568 out:
48569 sysctl_head_finish(head);
48570 return err;
48571@@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48572 struct inode *inode = filp->f_path.dentry->d_inode;
48573 struct ctl_table_header *head = grab_header(inode);
48574 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
48575+ int op = write ? MAY_WRITE : MAY_READ;
48576 ssize_t error;
48577 size_t res;
48578
48579 if (IS_ERR(head))
48580 return PTR_ERR(head);
48581
48582+
48583 /*
48584 * At this point we know that the sysctl was not unregistered
48585 * and won't be until we finish.
48586 */
48587 error = -EPERM;
48588- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
48589+ if (sysctl_perm(head->root, table, op))
48590 goto out;
48591
48592 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
48593@@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48594 if (!table->proc_handler)
48595 goto out;
48596
48597+#ifdef CONFIG_GRKERNSEC
48598+ error = -EPERM;
48599+ if (gr_handle_chroot_sysctl(op))
48600+ goto out;
48601+ dget(filp->f_path.dentry);
48602+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
48603+ dput(filp->f_path.dentry);
48604+ goto out;
48605+ }
48606+ dput(filp->f_path.dentry);
48607+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
48608+ goto out;
48609+ if (write && !capable(CAP_SYS_ADMIN))
48610+ goto out;
48611+#endif
48612+
48613 /* careful: calling conventions are nasty here */
48614 res = count;
48615 error = table->proc_handler(table, write, buf, &res, ppos);
48616@@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48617 return -ENOMEM;
48618 } else {
48619 d_set_d_op(child, &proc_sys_dentry_operations);
48620+
48621+ gr_handle_proc_create(child, inode);
48622+
48623 d_add(child, inode);
48624 }
48625 } else {
48626@@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48627 if ((*pos)++ < file->f_pos)
48628 return 0;
48629
48630+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
48631+ return 0;
48632+
48633 if (unlikely(S_ISLNK(table->mode)))
48634 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
48635 else
48636@@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48637 if (IS_ERR(head))
48638 return PTR_ERR(head);
48639
48640+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
48641+ return -ENOENT;
48642+
48643 generic_fillattr(inode, stat);
48644 if (table)
48645 stat->mode = (stat->mode & S_IFMT) | table->mode;
48646@@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48647 .llseek = generic_file_llseek,
48648 };
48649
48650-static const struct inode_operations proc_sys_inode_operations = {
48651+const struct inode_operations proc_sys_inode_operations = {
48652 .permission = proc_sys_permission,
48653 .setattr = proc_sys_setattr,
48654 .getattr = proc_sys_getattr,
48655 };
48656
48657-static const struct inode_operations proc_sys_dir_operations = {
48658+const struct inode_operations proc_sys_dir_operations = {
48659 .lookup = proc_sys_lookup,
48660 .permission = proc_sys_permission,
48661 .setattr = proc_sys_setattr,
48662diff --git a/fs/proc/root.c b/fs/proc/root.c
48663index eed44bf..abeb499 100644
48664--- a/fs/proc/root.c
48665+++ b/fs/proc/root.c
48666@@ -188,7 +188,15 @@ void __init proc_root_init(void)
48667 #ifdef CONFIG_PROC_DEVICETREE
48668 proc_device_tree_init();
48669 #endif
48670+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48671+#ifdef CONFIG_GRKERNSEC_PROC_USER
48672+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48673+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48674+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48675+#endif
48676+#else
48677 proc_mkdir("bus", NULL);
48678+#endif
48679 proc_sys_init();
48680 }
48681
48682diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48683index 7faaf2a..7793015 100644
48684--- a/fs/proc/task_mmu.c
48685+++ b/fs/proc/task_mmu.c
48686@@ -11,12 +11,19 @@
48687 #include <linux/rmap.h>
48688 #include <linux/swap.h>
48689 #include <linux/swapops.h>
48690+#include <linux/grsecurity.h>
48691
48692 #include <asm/elf.h>
48693 #include <asm/uaccess.h>
48694 #include <asm/tlbflush.h>
48695 #include "internal.h"
48696
48697+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48698+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48699+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48700+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48701+#endif
48702+
48703 void task_mem(struct seq_file *m, struct mm_struct *mm)
48704 {
48705 unsigned long data, text, lib, swap;
48706@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48707 "VmExe:\t%8lu kB\n"
48708 "VmLib:\t%8lu kB\n"
48709 "VmPTE:\t%8lu kB\n"
48710- "VmSwap:\t%8lu kB\n",
48711- hiwater_vm << (PAGE_SHIFT-10),
48712+ "VmSwap:\t%8lu kB\n"
48713+
48714+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48715+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48716+#endif
48717+
48718+ ,hiwater_vm << (PAGE_SHIFT-10),
48719 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48720 mm->locked_vm << (PAGE_SHIFT-10),
48721 mm->pinned_vm << (PAGE_SHIFT-10),
48722@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48723 data << (PAGE_SHIFT-10),
48724 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48725 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48726- swap << (PAGE_SHIFT-10));
48727+ swap << (PAGE_SHIFT-10)
48728+
48729+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48730+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48731+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
48732+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
48733+#else
48734+ , mm->context.user_cs_base
48735+ , mm->context.user_cs_limit
48736+#endif
48737+#endif
48738+
48739+ );
48740 }
48741
48742 unsigned long task_vsize(struct mm_struct *mm)
48743@@ -125,7 +149,7 @@ static void *m_start(struct seq_file *m, loff_t *pos)
48744 if (!priv->task)
48745 return ERR_PTR(-ESRCH);
48746
48747- mm = mm_for_maps(priv->task);
48748+ mm = mm_access(priv->task, PTRACE_MODE_READ);
48749 if (!mm || IS_ERR(mm))
48750 return mm;
48751 down_read(&mm->mmap_sem);
48752@@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48753 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
48754 }
48755
48756- /* We don't show the stack guard page in /proc/maps */
48757+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48758+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
48759+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
48760+#else
48761 start = vma->vm_start;
48762- if (stack_guard_page_start(vma, start))
48763- start += PAGE_SIZE;
48764 end = vma->vm_end;
48765- if (stack_guard_page_end(vma, end))
48766- end -= PAGE_SIZE;
48767+#endif
48768
48769 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48770 start,
48771@@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48772 flags & VM_WRITE ? 'w' : '-',
48773 flags & VM_EXEC ? 'x' : '-',
48774 flags & VM_MAYSHARE ? 's' : 'p',
48775+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48776+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48777+#else
48778 pgoff,
48779+#endif
48780 MAJOR(dev), MINOR(dev), ino, &len);
48781
48782 /*
48783@@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48784 */
48785 if (file) {
48786 pad_len_spaces(m, len);
48787- seq_path(m, &file->f_path, "\n");
48788+ seq_path(m, &file->f_path, "\n\\");
48789 goto done;
48790 }
48791
48792@@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48793 * Thread stack in /proc/PID/task/TID/maps or
48794 * the main process stack.
48795 */
48796- if (!is_pid || (vma->vm_start <= mm->start_stack &&
48797- vma->vm_end >= mm->start_stack)) {
48798+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48799+ (vma->vm_start <= mm->start_stack &&
48800+ vma->vm_end >= mm->start_stack)) {
48801 name = "[stack]";
48802 } else {
48803 /* Thread stack in /proc/PID/maps */
48804@@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
48805 struct proc_maps_private *priv = m->private;
48806 struct task_struct *task = priv->task;
48807
48808+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48809+ if (current->exec_id != m->exec_id) {
48810+ gr_log_badprocpid("maps");
48811+ return 0;
48812+ }
48813+#endif
48814+
48815 show_map_vma(m, vma, is_pid);
48816
48817 if (m->count < m->size) /* vma is copied successfully */
48818@@ -482,12 +518,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
48819 .private = &mss,
48820 };
48821
48822+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48823+ if (current->exec_id != m->exec_id) {
48824+ gr_log_badprocpid("smaps");
48825+ return 0;
48826+ }
48827+#endif
48828 memset(&mss, 0, sizeof mss);
48829- mss.vma = vma;
48830- /* mmap_sem is held in m_start */
48831- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48832- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48833-
48834+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48835+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
48836+#endif
48837+ mss.vma = vma;
48838+ /* mmap_sem is held in m_start */
48839+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48840+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48841+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48842+ }
48843+#endif
48844 show_map_vma(m, vma, is_pid);
48845
48846 seq_printf(m,
48847@@ -505,7 +552,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
48848 "KernelPageSize: %8lu kB\n"
48849 "MMUPageSize: %8lu kB\n"
48850 "Locked: %8lu kB\n",
48851+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48852+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
48853+#else
48854 (vma->vm_end - vma->vm_start) >> 10,
48855+#endif
48856 mss.resident >> 10,
48857 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
48858 mss.shared_clean >> 10,
48859@@ -919,7 +970,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
48860 if (!pm.buffer)
48861 goto out_task;
48862
48863- mm = mm_for_maps(task);
48864+ mm = mm_access(task, PTRACE_MODE_READ);
48865 ret = PTR_ERR(mm);
48866 if (!mm || IS_ERR(mm))
48867 goto out_free;
48868@@ -1138,6 +1189,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
48869 int n;
48870 char buffer[50];
48871
48872+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48873+ if (current->exec_id != m->exec_id) {
48874+ gr_log_badprocpid("numa_maps");
48875+ return 0;
48876+ }
48877+#endif
48878+
48879 if (!mm)
48880 return 0;
48881
48882@@ -1155,11 +1213,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
48883 mpol_to_str(buffer, sizeof(buffer), pol, 0);
48884 mpol_cond_put(pol);
48885
48886+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48887+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
48888+#else
48889 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
48890+#endif
48891
48892 if (file) {
48893 seq_printf(m, " file=");
48894- seq_path(m, &file->f_path, "\n\t= ");
48895+ seq_path(m, &file->f_path, "\n\t\\= ");
48896 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
48897 seq_printf(m, " heap");
48898 } else {
48899diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
48900index 74fe164..0848f95 100644
48901--- a/fs/proc/task_nommu.c
48902+++ b/fs/proc/task_nommu.c
48903@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48904 else
48905 bytes += kobjsize(mm);
48906
48907- if (current->fs && current->fs->users > 1)
48908+ if (current->fs && atomic_read(&current->fs->users) > 1)
48909 sbytes += kobjsize(current->fs);
48910 else
48911 bytes += kobjsize(current->fs);
48912@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
48913
48914 if (file) {
48915 pad_len_spaces(m, len);
48916- seq_path(m, &file->f_path, "");
48917+ seq_path(m, &file->f_path, "\n\\");
48918 } else if (mm) {
48919 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
48920
48921@@ -223,7 +223,7 @@ static void *m_start(struct seq_file *m, loff_t *pos)
48922 if (!priv->task)
48923 return ERR_PTR(-ESRCH);
48924
48925- mm = mm_for_maps(priv->task);
48926+ mm = mm_access(priv->task, PTRACE_MODE_READ);
48927 if (!mm || IS_ERR(mm)) {
48928 put_task_struct(priv->task);
48929 priv->task = NULL;
48930diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
48931index d67908b..d13f6a6 100644
48932--- a/fs/quota/netlink.c
48933+++ b/fs/quota/netlink.c
48934@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
48935 void quota_send_warning(short type, unsigned int id, dev_t dev,
48936 const char warntype)
48937 {
48938- static atomic_t seq;
48939+ static atomic_unchecked_t seq;
48940 struct sk_buff *skb;
48941 void *msg_head;
48942 int ret;
48943@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
48944 "VFS: Not enough memory to send quota warning.\n");
48945 return;
48946 }
48947- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
48948+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
48949 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
48950 if (!msg_head) {
48951 printk(KERN_ERR
48952diff --git a/fs/readdir.c b/fs/readdir.c
48953index cc0a822..43cb195 100644
48954--- a/fs/readdir.c
48955+++ b/fs/readdir.c
48956@@ -17,6 +17,7 @@
48957 #include <linux/security.h>
48958 #include <linux/syscalls.h>
48959 #include <linux/unistd.h>
48960+#include <linux/namei.h>
48961
48962 #include <asm/uaccess.h>
48963
48964@@ -67,6 +68,7 @@ struct old_linux_dirent {
48965
48966 struct readdir_callback {
48967 struct old_linux_dirent __user * dirent;
48968+ struct file * file;
48969 int result;
48970 };
48971
48972@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
48973 buf->result = -EOVERFLOW;
48974 return -EOVERFLOW;
48975 }
48976+
48977+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48978+ return 0;
48979+
48980 buf->result++;
48981 dirent = buf->dirent;
48982 if (!access_ok(VERIFY_WRITE, dirent,
48983@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
48984
48985 buf.result = 0;
48986 buf.dirent = dirent;
48987+ buf.file = file;
48988
48989 error = vfs_readdir(file, fillonedir, &buf);
48990 if (buf.result)
48991@@ -142,6 +149,7 @@ struct linux_dirent {
48992 struct getdents_callback {
48993 struct linux_dirent __user * current_dir;
48994 struct linux_dirent __user * previous;
48995+ struct file * file;
48996 int count;
48997 int error;
48998 };
48999@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49000 buf->error = -EOVERFLOW;
49001 return -EOVERFLOW;
49002 }
49003+
49004+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49005+ return 0;
49006+
49007 dirent = buf->previous;
49008 if (dirent) {
49009 if (__put_user(offset, &dirent->d_off))
49010@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49011 buf.previous = NULL;
49012 buf.count = count;
49013 buf.error = 0;
49014+ buf.file = file;
49015
49016 error = vfs_readdir(file, filldir, &buf);
49017 if (error >= 0)
49018@@ -229,6 +242,7 @@ out:
49019 struct getdents_callback64 {
49020 struct linux_dirent64 __user * current_dir;
49021 struct linux_dirent64 __user * previous;
49022+ struct file *file;
49023 int count;
49024 int error;
49025 };
49026@@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49027 buf->error = -EINVAL; /* only used if we fail.. */
49028 if (reclen > buf->count)
49029 return -EINVAL;
49030+
49031+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49032+ return 0;
49033+
49034 dirent = buf->previous;
49035 if (dirent) {
49036 if (__put_user(offset, &dirent->d_off))
49037@@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49038
49039 buf.current_dir = dirent;
49040 buf.previous = NULL;
49041+ buf.file = file;
49042 buf.count = count;
49043 buf.error = 0;
49044
49045@@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49046 error = buf.error;
49047 lastdirent = buf.previous;
49048 if (lastdirent) {
49049- typeof(lastdirent->d_off) d_off = file->f_pos;
49050+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49051 if (__put_user(d_off, &lastdirent->d_off))
49052 error = -EFAULT;
49053 else
49054diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49055index 2b7882b..1c5ef48 100644
49056--- a/fs/reiserfs/do_balan.c
49057+++ b/fs/reiserfs/do_balan.c
49058@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49059 return;
49060 }
49061
49062- atomic_inc(&(fs_generation(tb->tb_sb)));
49063+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49064 do_balance_starts(tb);
49065
49066 /* balance leaf returns 0 except if combining L R and S into
49067diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49068index 2c1ade6..8c59d8d 100644
49069--- a/fs/reiserfs/procfs.c
49070+++ b/fs/reiserfs/procfs.c
49071@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49072 "SMALL_TAILS " : "NO_TAILS ",
49073 replay_only(sb) ? "REPLAY_ONLY " : "",
49074 convert_reiserfs(sb) ? "CONV " : "",
49075- atomic_read(&r->s_generation_counter),
49076+ atomic_read_unchecked(&r->s_generation_counter),
49077 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49078 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49079 SF(s_good_search_by_key_reada), SF(s_bmaps),
49080diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
49081index a59d271..e12d1cf 100644
49082--- a/fs/reiserfs/reiserfs.h
49083+++ b/fs/reiserfs/reiserfs.h
49084@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
49085 /* Comment? -Hans */
49086 wait_queue_head_t s_wait;
49087 /* To be obsoleted soon by per buffer seals.. -Hans */
49088- atomic_t s_generation_counter; // increased by one every time the
49089+ atomic_unchecked_t s_generation_counter; // increased by one every time the
49090 // tree gets re-balanced
49091 unsigned long s_properties; /* File system properties. Currently holds
49092 on-disk FS format */
49093@@ -1973,7 +1973,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
49094 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
49095
49096 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
49097-#define get_generation(s) atomic_read (&fs_generation(s))
49098+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
49099 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
49100 #define __fs_changed(gen,s) (gen != get_generation (s))
49101 #define fs_changed(gen,s) \
49102diff --git a/fs/select.c b/fs/select.c
49103index 17d33d0..da0bf5c 100644
49104--- a/fs/select.c
49105+++ b/fs/select.c
49106@@ -20,6 +20,7 @@
49107 #include <linux/export.h>
49108 #include <linux/slab.h>
49109 #include <linux/poll.h>
49110+#include <linux/security.h>
49111 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49112 #include <linux/file.h>
49113 #include <linux/fdtable.h>
49114@@ -833,6 +834,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49115 struct poll_list *walk = head;
49116 unsigned long todo = nfds;
49117
49118+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49119 if (nfds > rlimit(RLIMIT_NOFILE))
49120 return -EINVAL;
49121
49122diff --git a/fs/seq_file.c b/fs/seq_file.c
49123index 0cbd049..64e705c 100644
49124--- a/fs/seq_file.c
49125+++ b/fs/seq_file.c
49126@@ -9,6 +9,7 @@
49127 #include <linux/export.h>
49128 #include <linux/seq_file.h>
49129 #include <linux/slab.h>
49130+#include <linux/sched.h>
49131
49132 #include <asm/uaccess.h>
49133 #include <asm/page.h>
49134@@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49135 memset(p, 0, sizeof(*p));
49136 mutex_init(&p->lock);
49137 p->op = op;
49138+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49139+ p->exec_id = current->exec_id;
49140+#endif
49141
49142 /*
49143 * Wrappers around seq_open(e.g. swaps_open) need to be
49144@@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49145 return 0;
49146 }
49147 if (!m->buf) {
49148- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49149+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49150 if (!m->buf)
49151 return -ENOMEM;
49152 }
49153@@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49154 Eoverflow:
49155 m->op->stop(m, p);
49156 kfree(m->buf);
49157- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49158+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49159 return !m->buf ? -ENOMEM : -EAGAIN;
49160 }
49161
49162@@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49163
49164 /* grab buffer if we didn't have one */
49165 if (!m->buf) {
49166- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49167+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49168 if (!m->buf)
49169 goto Enomem;
49170 }
49171@@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49172 goto Fill;
49173 m->op->stop(m, p);
49174 kfree(m->buf);
49175- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49176+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49177 if (!m->buf)
49178 goto Enomem;
49179 m->count = 0;
49180@@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
49181 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49182 void *data)
49183 {
49184- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49185+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49186 int res = -ENOMEM;
49187
49188 if (op) {
49189diff --git a/fs/splice.c b/fs/splice.c
49190index 5cac690..f833a99 100644
49191--- a/fs/splice.c
49192+++ b/fs/splice.c
49193@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49194 pipe_lock(pipe);
49195
49196 for (;;) {
49197- if (!pipe->readers) {
49198+ if (!atomic_read(&pipe->readers)) {
49199 send_sig(SIGPIPE, current, 0);
49200 if (!ret)
49201 ret = -EPIPE;
49202@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49203 do_wakeup = 0;
49204 }
49205
49206- pipe->waiting_writers++;
49207+ atomic_inc(&pipe->waiting_writers);
49208 pipe_wait(pipe);
49209- pipe->waiting_writers--;
49210+ atomic_dec(&pipe->waiting_writers);
49211 }
49212
49213 pipe_unlock(pipe);
49214@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49215 old_fs = get_fs();
49216 set_fs(get_ds());
49217 /* The cast to a user pointer is valid due to the set_fs() */
49218- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49219+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49220 set_fs(old_fs);
49221
49222 return res;
49223@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49224 old_fs = get_fs();
49225 set_fs(get_ds());
49226 /* The cast to a user pointer is valid due to the set_fs() */
49227- res = vfs_write(file, (const char __user *)buf, count, &pos);
49228+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49229 set_fs(old_fs);
49230
49231 return res;
49232@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49233 goto err;
49234
49235 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49236- vec[i].iov_base = (void __user *) page_address(page);
49237+ vec[i].iov_base = (void __force_user *) page_address(page);
49238 vec[i].iov_len = this_len;
49239 spd.pages[i] = page;
49240 spd.nr_pages++;
49241@@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49242 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49243 {
49244 while (!pipe->nrbufs) {
49245- if (!pipe->writers)
49246+ if (!atomic_read(&pipe->writers))
49247 return 0;
49248
49249- if (!pipe->waiting_writers && sd->num_spliced)
49250+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49251 return 0;
49252
49253 if (sd->flags & SPLICE_F_NONBLOCK)
49254@@ -1185,7 +1185,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49255 * out of the pipe right after the splice_to_pipe(). So set
49256 * PIPE_READERS appropriately.
49257 */
49258- pipe->readers = 1;
49259+ atomic_set(&pipe->readers, 1);
49260
49261 current->splice_pipe = pipe;
49262 }
49263@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49264 ret = -ERESTARTSYS;
49265 break;
49266 }
49267- if (!pipe->writers)
49268+ if (!atomic_read(&pipe->writers))
49269 break;
49270- if (!pipe->waiting_writers) {
49271+ if (!atomic_read(&pipe->waiting_writers)) {
49272 if (flags & SPLICE_F_NONBLOCK) {
49273 ret = -EAGAIN;
49274 break;
49275@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49276 pipe_lock(pipe);
49277
49278 while (pipe->nrbufs >= pipe->buffers) {
49279- if (!pipe->readers) {
49280+ if (!atomic_read(&pipe->readers)) {
49281 send_sig(SIGPIPE, current, 0);
49282 ret = -EPIPE;
49283 break;
49284@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49285 ret = -ERESTARTSYS;
49286 break;
49287 }
49288- pipe->waiting_writers++;
49289+ atomic_inc(&pipe->waiting_writers);
49290 pipe_wait(pipe);
49291- pipe->waiting_writers--;
49292+ atomic_dec(&pipe->waiting_writers);
49293 }
49294
49295 pipe_unlock(pipe);
49296@@ -1823,14 +1823,14 @@ retry:
49297 pipe_double_lock(ipipe, opipe);
49298
49299 do {
49300- if (!opipe->readers) {
49301+ if (!atomic_read(&opipe->readers)) {
49302 send_sig(SIGPIPE, current, 0);
49303 if (!ret)
49304 ret = -EPIPE;
49305 break;
49306 }
49307
49308- if (!ipipe->nrbufs && !ipipe->writers)
49309+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49310 break;
49311
49312 /*
49313@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49314 pipe_double_lock(ipipe, opipe);
49315
49316 do {
49317- if (!opipe->readers) {
49318+ if (!atomic_read(&opipe->readers)) {
49319 send_sig(SIGPIPE, current, 0);
49320 if (!ret)
49321 ret = -EPIPE;
49322@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49323 * return EAGAIN if we have the potential of some data in the
49324 * future, otherwise just return 0
49325 */
49326- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49327+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49328 ret = -EAGAIN;
49329
49330 pipe_unlock(ipipe);
49331diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49332index 35a36d3..23424b2 100644
49333--- a/fs/sysfs/dir.c
49334+++ b/fs/sysfs/dir.c
49335@@ -657,6 +657,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49336 struct sysfs_dirent *sd;
49337 int rc;
49338
49339+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49340+ const char *parent_name = parent_sd->s_name;
49341+
49342+ mode = S_IFDIR | S_IRWXU;
49343+
49344+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49345+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49346+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49347+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49348+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49349+#endif
49350+
49351 /* allocate */
49352 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49353 if (!sd)
49354diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49355index 00012e3..8392349 100644
49356--- a/fs/sysfs/file.c
49357+++ b/fs/sysfs/file.c
49358@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49359
49360 struct sysfs_open_dirent {
49361 atomic_t refcnt;
49362- atomic_t event;
49363+ atomic_unchecked_t event;
49364 wait_queue_head_t poll;
49365 struct list_head buffers; /* goes through sysfs_buffer.list */
49366 };
49367@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49368 if (!sysfs_get_active(attr_sd))
49369 return -ENODEV;
49370
49371- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49372+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49373 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49374
49375 sysfs_put_active(attr_sd);
49376@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49377 return -ENOMEM;
49378
49379 atomic_set(&new_od->refcnt, 0);
49380- atomic_set(&new_od->event, 1);
49381+ atomic_set_unchecked(&new_od->event, 1);
49382 init_waitqueue_head(&new_od->poll);
49383 INIT_LIST_HEAD(&new_od->buffers);
49384 goto retry;
49385@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49386
49387 sysfs_put_active(attr_sd);
49388
49389- if (buffer->event != atomic_read(&od->event))
49390+ if (buffer->event != atomic_read_unchecked(&od->event))
49391 goto trigger;
49392
49393 return DEFAULT_POLLMASK;
49394@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49395
49396 od = sd->s_attr.open;
49397 if (od) {
49398- atomic_inc(&od->event);
49399+ atomic_inc_unchecked(&od->event);
49400 wake_up_interruptible(&od->poll);
49401 }
49402
49403diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49404index a7ac78f..02158e1 100644
49405--- a/fs/sysfs/symlink.c
49406+++ b/fs/sysfs/symlink.c
49407@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49408
49409 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49410 {
49411- char *page = nd_get_link(nd);
49412+ const char *page = nd_get_link(nd);
49413 if (!IS_ERR(page))
49414 free_page((unsigned long)page);
49415 }
49416diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49417index c175b4d..8f36a16 100644
49418--- a/fs/udf/misc.c
49419+++ b/fs/udf/misc.c
49420@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49421
49422 u8 udf_tag_checksum(const struct tag *t)
49423 {
49424- u8 *data = (u8 *)t;
49425+ const u8 *data = (const u8 *)t;
49426 u8 checksum = 0;
49427 int i;
49428 for (i = 0; i < sizeof(struct tag); ++i)
49429diff --git a/fs/utimes.c b/fs/utimes.c
49430index ba653f3..06ea4b1 100644
49431--- a/fs/utimes.c
49432+++ b/fs/utimes.c
49433@@ -1,6 +1,7 @@
49434 #include <linux/compiler.h>
49435 #include <linux/file.h>
49436 #include <linux/fs.h>
49437+#include <linux/security.h>
49438 #include <linux/linkage.h>
49439 #include <linux/mount.h>
49440 #include <linux/namei.h>
49441@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49442 goto mnt_drop_write_and_out;
49443 }
49444 }
49445+
49446+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49447+ error = -EACCES;
49448+ goto mnt_drop_write_and_out;
49449+ }
49450+
49451 mutex_lock(&inode->i_mutex);
49452 error = notify_change(path->dentry, &newattrs);
49453 mutex_unlock(&inode->i_mutex);
49454diff --git a/fs/xattr.c b/fs/xattr.c
49455index 3c8c1cc..a83c398 100644
49456--- a/fs/xattr.c
49457+++ b/fs/xattr.c
49458@@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49459 * Extended attribute SET operations
49460 */
49461 static long
49462-setxattr(struct dentry *d, const char __user *name, const void __user *value,
49463+setxattr(struct path *path, const char __user *name, const void __user *value,
49464 size_t size, int flags)
49465 {
49466 int error;
49467@@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49468 }
49469 }
49470
49471- error = vfs_setxattr(d, kname, kvalue, size, flags);
49472+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49473+ error = -EACCES;
49474+ goto out;
49475+ }
49476+
49477+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49478 out:
49479 if (vvalue)
49480 vfree(vvalue);
49481@@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49482 return error;
49483 error = mnt_want_write(path.mnt);
49484 if (!error) {
49485- error = setxattr(path.dentry, name, value, size, flags);
49486+ error = setxattr(&path, name, value, size, flags);
49487 mnt_drop_write(path.mnt);
49488 }
49489 path_put(&path);
49490@@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49491 return error;
49492 error = mnt_want_write(path.mnt);
49493 if (!error) {
49494- error = setxattr(path.dentry, name, value, size, flags);
49495+ error = setxattr(&path, name, value, size, flags);
49496 mnt_drop_write(path.mnt);
49497 }
49498 path_put(&path);
49499@@ -400,17 +405,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49500 const void __user *,value, size_t, size, int, flags)
49501 {
49502 struct file *f;
49503- struct dentry *dentry;
49504 int error = -EBADF;
49505
49506 f = fget(fd);
49507 if (!f)
49508 return error;
49509- dentry = f->f_path.dentry;
49510- audit_inode(NULL, dentry);
49511+ audit_inode(NULL, f->f_path.dentry);
49512 error = mnt_want_write_file(f);
49513 if (!error) {
49514- error = setxattr(dentry, name, value, size, flags);
49515+ error = setxattr(&f->f_path, name, value, size, flags);
49516 mnt_drop_write_file(f);
49517 }
49518 fput(f);
49519diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49520index 69d06b0..c0996e5 100644
49521--- a/fs/xattr_acl.c
49522+++ b/fs/xattr_acl.c
49523@@ -17,8 +17,8 @@
49524 struct posix_acl *
49525 posix_acl_from_xattr(const void *value, size_t size)
49526 {
49527- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49528- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49529+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49530+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49531 int count;
49532 struct posix_acl *acl;
49533 struct posix_acl_entry *acl_e;
49534diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49535index 85e7e32..5344e52 100644
49536--- a/fs/xfs/xfs_bmap.c
49537+++ b/fs/xfs/xfs_bmap.c
49538@@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49539 int nmap,
49540 int ret_nmap);
49541 #else
49542-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49543+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49544 #endif /* DEBUG */
49545
49546 STATIC int
49547diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49548index 79d05e8..e3e5861 100644
49549--- a/fs/xfs/xfs_dir2_sf.c
49550+++ b/fs/xfs/xfs_dir2_sf.c
49551@@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49552 }
49553
49554 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49555- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49556+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49557+ char name[sfep->namelen];
49558+ memcpy(name, sfep->name, sfep->namelen);
49559+ if (filldir(dirent, name, sfep->namelen,
49560+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
49561+ *offset = off & 0x7fffffff;
49562+ return 0;
49563+ }
49564+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49565 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49566 *offset = off & 0x7fffffff;
49567 return 0;
49568diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49569index 91f8ff5..0ce68f9 100644
49570--- a/fs/xfs/xfs_ioctl.c
49571+++ b/fs/xfs/xfs_ioctl.c
49572@@ -128,7 +128,7 @@ xfs_find_handle(
49573 }
49574
49575 error = -EFAULT;
49576- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49577+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49578 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49579 goto out_put;
49580
49581diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49582index 3011b87..1ab03e9 100644
49583--- a/fs/xfs/xfs_iops.c
49584+++ b/fs/xfs/xfs_iops.c
49585@@ -397,7 +397,7 @@ xfs_vn_put_link(
49586 struct nameidata *nd,
49587 void *p)
49588 {
49589- char *s = nd_get_link(nd);
49590+ const char *s = nd_get_link(nd);
49591
49592 if (!IS_ERR(s))
49593 kfree(s);
49594diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49595new file mode 100644
49596index 0000000..4d533f1
49597--- /dev/null
49598+++ b/grsecurity/Kconfig
49599@@ -0,0 +1,941 @@
49600+#
49601+# grecurity configuration
49602+#
49603+menu "Memory Protections"
49604+depends on GRKERNSEC
49605+
49606+config GRKERNSEC_KMEM
49607+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49608+ default y if GRKERNSEC_CONFIG_AUTO
49609+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49610+ help
49611+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49612+ be written to or read from to modify or leak the contents of the running
49613+ kernel. /dev/port will also not be allowed to be opened. If you have module
49614+ support disabled, enabling this will close up four ways that are
49615+ currently used to insert malicious code into the running kernel.
49616+ Even with all these features enabled, we still highly recommend that
49617+ you use the RBAC system, as it is still possible for an attacker to
49618+ modify the running kernel through privileged I/O granted by ioperm/iopl.
49619+ If you are not using XFree86, you may be able to stop this additional
49620+ case by enabling the 'Disable privileged I/O' option. Though nothing
49621+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49622+ but only to video memory, which is the only writing we allow in this
49623+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49624+ not be allowed to mprotect it with PROT_WRITE later.
49625+ It is highly recommended that you say Y here if you meet all the
49626+ conditions above.
49627+
49628+config GRKERNSEC_VM86
49629+ bool "Restrict VM86 mode"
49630+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
49631+ depends on X86_32
49632+
49633+ help
49634+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49635+ make use of a special execution mode on 32bit x86 processors called
49636+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
49637+ video cards and will still work with this option enabled. The purpose
49638+ of the option is to prevent exploitation of emulation errors in
49639+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
49640+ Nearly all users should be able to enable this option.
49641+
49642+config GRKERNSEC_IO
49643+ bool "Disable privileged I/O"
49644+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
49645+ depends on X86
49646+ select RTC_CLASS
49647+ select RTC_INTF_DEV
49648+ select RTC_DRV_CMOS
49649+
49650+ help
49651+ If you say Y here, all ioperm and iopl calls will return an error.
49652+ Ioperm and iopl can be used to modify the running kernel.
49653+ Unfortunately, some programs need this access to operate properly,
49654+ the most notable of which are XFree86 and hwclock. hwclock can be
49655+ remedied by having RTC support in the kernel, so real-time
49656+ clock support is enabled if this option is enabled, to ensure
49657+ that hwclock operates correctly. XFree86 still will not
49658+ operate correctly with this option enabled, so DO NOT CHOOSE Y
49659+ IF YOU USE XFree86. If you use XFree86 and you still want to
49660+ protect your kernel against modification, use the RBAC system.
49661+
49662+config GRKERNSEC_PROC_MEMMAP
49663+ bool "Harden ASLR against information leaks and entropy reduction"
49664+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
49665+ depends on PAX_NOEXEC || PAX_ASLR
49666+ help
49667+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
49668+ give no information about the addresses of its mappings if
49669+ PaX features that rely on random addresses are enabled on the task.
49670+ In addition to sanitizing this information and disabling other
49671+ dangerous sources of information, this option causes reads of sensitive
49672+ /proc/<pid> entries where the file descriptor was opened in a different
49673+ task than the one performing the read. Such attempts are logged.
49674+ This option also limits argv/env strings for suid/sgid binaries
49675+ to 512KB to prevent a complete exhaustion of the stack entropy provided
49676+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
49677+ binaries to prevent alternative mmap layouts from being abused.
49678+
49679+ If you use PaX it is essential that you say Y here as it closes up
49680+ several holes that make full ASLR useless locally.
49681+
49682+config GRKERNSEC_BRUTE
49683+ bool "Deter exploit bruteforcing"
49684+ default y if GRKERNSEC_CONFIG_AUTO
49685+ help
49686+ If you say Y here, attempts to bruteforce exploits against forking
49687+ daemons such as apache or sshd, as well as against suid/sgid binaries
49688+ will be deterred. When a child of a forking daemon is killed by PaX
49689+ or crashes due to an illegal instruction or other suspicious signal,
49690+ the parent process will be delayed 30 seconds upon every subsequent
49691+ fork until the administrator is able to assess the situation and
49692+ restart the daemon.
49693+ In the suid/sgid case, the attempt is logged, the user has all their
49694+ processes terminated, and they are prevented from executing any further
49695+ processes for 15 minutes.
49696+ It is recommended that you also enable signal logging in the auditing
49697+ section so that logs are generated when a process triggers a suspicious
49698+ signal.
49699+ If the sysctl option is enabled, a sysctl option with name
49700+ "deter_bruteforce" is created.
49701+
49702+
49703+config GRKERNSEC_MODHARDEN
49704+ bool "Harden module auto-loading"
49705+ default y if GRKERNSEC_CONFIG_AUTO
49706+ depends on MODULES
49707+ help
49708+ If you say Y here, module auto-loading in response to use of some
49709+ feature implemented by an unloaded module will be restricted to
49710+ root users. Enabling this option helps defend against attacks
49711+ by unprivileged users who abuse the auto-loading behavior to
49712+ cause a vulnerable module to load that is then exploited.
49713+
49714+ If this option prevents a legitimate use of auto-loading for a
49715+ non-root user, the administrator can execute modprobe manually
49716+ with the exact name of the module mentioned in the alert log.
49717+ Alternatively, the administrator can add the module to the list
49718+ of modules loaded at boot by modifying init scripts.
49719+
49720+ Modification of init scripts will most likely be needed on
49721+ Ubuntu servers with encrypted home directory support enabled,
49722+ as the first non-root user logging in will cause the ecb(aes),
49723+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
49724+
49725+config GRKERNSEC_HIDESYM
49726+ bool "Hide kernel symbols"
49727+ default y if GRKERNSEC_CONFIG_AUTO
49728+ select PAX_USERCOPY_SLABS
49729+ help
49730+ If you say Y here, getting information on loaded modules, and
49731+ displaying all kernel symbols through a syscall will be restricted
49732+ to users with CAP_SYS_MODULE. For software compatibility reasons,
49733+ /proc/kallsyms will be restricted to the root user. The RBAC
49734+ system can hide that entry even from root.
49735+
49736+ This option also prevents leaking of kernel addresses through
49737+ several /proc entries.
49738+
49739+ Note that this option is only effective provided the following
49740+ conditions are met:
49741+ 1) The kernel using grsecurity is not precompiled by some distribution
49742+ 2) You have also enabled GRKERNSEC_DMESG
49743+ 3) You are using the RBAC system and hiding other files such as your
49744+ kernel image and System.map. Alternatively, enabling this option
49745+ causes the permissions on /boot, /lib/modules, and the kernel
49746+ source directory to change at compile time to prevent
49747+ reading by non-root users.
49748+ If the above conditions are met, this option will aid in providing a
49749+ useful protection against local kernel exploitation of overflows
49750+ and arbitrary read/write vulnerabilities.
49751+
49752+config GRKERNSEC_KERN_LOCKOUT
49753+ bool "Active kernel exploit response"
49754+ default y if GRKERNSEC_CONFIG_AUTO
49755+ depends on X86 || ARM || PPC || SPARC
49756+ help
49757+ If you say Y here, when a PaX alert is triggered due to suspicious
49758+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
49759+ or an OOPS occurs due to bad memory accesses, instead of just
49760+ terminating the offending process (and potentially allowing
49761+ a subsequent exploit from the same user), we will take one of two
49762+ actions:
49763+ If the user was root, we will panic the system
49764+ If the user was non-root, we will log the attempt, terminate
49765+ all processes owned by the user, then prevent them from creating
49766+ any new processes until the system is restarted
49767+ This deters repeated kernel exploitation/bruteforcing attempts
49768+ and is useful for later forensics.
49769+
49770+endmenu
49771+menu "Role Based Access Control Options"
49772+depends on GRKERNSEC
49773+
49774+config GRKERNSEC_RBAC_DEBUG
49775+ bool
49776+
49777+config GRKERNSEC_NO_RBAC
49778+ bool "Disable RBAC system"
49779+ help
49780+ If you say Y here, the /dev/grsec device will be removed from the kernel,
49781+ preventing the RBAC system from being enabled. You should only say Y
49782+ here if you have no intention of using the RBAC system, so as to prevent
49783+ an attacker with root access from misusing the RBAC system to hide files
49784+ and processes when loadable module support and /dev/[k]mem have been
49785+ locked down.
49786+
49787+config GRKERNSEC_ACL_HIDEKERN
49788+ bool "Hide kernel processes"
49789+ help
49790+ If you say Y here, all kernel threads will be hidden to all
49791+ processes but those whose subject has the "view hidden processes"
49792+ flag.
49793+
49794+config GRKERNSEC_ACL_MAXTRIES
49795+ int "Maximum tries before password lockout"
49796+ default 3
49797+ help
49798+ This option enforces the maximum number of times a user can attempt
49799+ to authorize themselves with the grsecurity RBAC system before being
49800+ denied the ability to attempt authorization again for a specified time.
49801+ The lower the number, the harder it will be to brute-force a password.
49802+
49803+config GRKERNSEC_ACL_TIMEOUT
49804+ int "Time to wait after max password tries, in seconds"
49805+ default 30
49806+ help
49807+ This option specifies the time the user must wait after attempting to
49808+ authorize to the RBAC system with the maximum number of invalid
49809+ passwords. The higher the number, the harder it will be to brute-force
49810+ a password.
49811+
49812+endmenu
49813+menu "Filesystem Protections"
49814+depends on GRKERNSEC
49815+
49816+config GRKERNSEC_PROC
49817+ bool "Proc restrictions"
49818+ default y if GRKERNSEC_CONFIG_AUTO
49819+ help
49820+ If you say Y here, the permissions of the /proc filesystem
49821+ will be altered to enhance system security and privacy. You MUST
49822+ choose either a user only restriction or a user and group restriction.
49823+ Depending upon the option you choose, you can either restrict users to
49824+ see only the processes they themselves run, or choose a group that can
49825+ view all processes and files normally restricted to root if you choose
49826+ the "restrict to user only" option. NOTE: If you're running identd or
49827+ ntpd as a non-root user, you will have to run it as the group you
49828+ specify here.
49829+
49830+config GRKERNSEC_PROC_USER
49831+ bool "Restrict /proc to user only"
49832+ depends on GRKERNSEC_PROC
49833+ help
49834+ If you say Y here, non-root users will only be able to view their own
49835+ processes, and restricts them from viewing network-related information,
49836+ and viewing kernel symbol and module information.
49837+
49838+config GRKERNSEC_PROC_USERGROUP
49839+ bool "Allow special group"
49840+ default y if GRKERNSEC_CONFIG_AUTO
49841+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
49842+ help
49843+ If you say Y here, you will be able to select a group that will be
49844+ able to view all processes and network-related information. If you've
49845+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
49846+ remain hidden. This option is useful if you want to run identd as
49847+ a non-root user.
49848+
49849+config GRKERNSEC_PROC_GID
49850+ int "GID for special group"
49851+ depends on GRKERNSEC_PROC_USERGROUP
49852+ default 1001
49853+
49854+config GRKERNSEC_PROC_ADD
49855+ bool "Additional restrictions"
49856+ default y if GRKERNSEC_CONFIG_AUTO
49857+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
49858+ help
49859+ If you say Y here, additional restrictions will be placed on
49860+ /proc that keep normal users from viewing device information and
49861+ slabinfo information that could be useful for exploits.
49862+
49863+config GRKERNSEC_LINK
49864+ bool "Linking restrictions"
49865+ default y if GRKERNSEC_CONFIG_AUTO
49866+ help
49867+ If you say Y here, /tmp race exploits will be prevented, since users
49868+ will no longer be able to follow symlinks owned by other users in
49869+ world-writable +t directories (e.g. /tmp), unless the owner of the
49870+ symlink is the owner of the directory. users will also not be
49871+ able to hardlink to files they do not own. If the sysctl option is
49872+ enabled, a sysctl option with name "linking_restrictions" is created.
49873+
49874+config GRKERNSEC_SYMLINKOWN
49875+ bool "Kernel-enforced SymlinksIfOwnerMatch"
49876+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
49877+ help
49878+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
49879+ that prevents it from being used as a security feature. As Apache
49880+ verifies the symlink by performing a stat() against the target of
49881+ the symlink before it is followed, an attacker can setup a symlink
49882+ to point to a same-owned file, then replace the symlink with one
49883+ that targets another user's file just after Apache "validates" the
49884+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
49885+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
49886+ will be in place for the group you specify. If the sysctl option
49887+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
49888+ created.
49889+
49890+config GRKERNSEC_SYMLINKOWN_GID
49891+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
49892+ depends on GRKERNSEC_SYMLINKOWN
49893+ default 1006
49894+ help
49895+ Setting this GID determines what group kernel-enforced
49896+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
49897+ is enabled, a sysctl option with name "symlinkown_gid" is created.
49898+
49899+config GRKERNSEC_FIFO
49900+ bool "FIFO restrictions"
49901+ default y if GRKERNSEC_CONFIG_AUTO
49902+ help
49903+ If you say Y here, users will not be able to write to FIFOs they don't
49904+ own in world-writable +t directories (e.g. /tmp), unless the owner of
49905+ the FIFO is the same owner of the directory it's held in. If the sysctl
49906+ option is enabled, a sysctl option with name "fifo_restrictions" is
49907+ created.
49908+
49909+config GRKERNSEC_SYSFS_RESTRICT
49910+ bool "Sysfs/debugfs restriction"
49911+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
49912+ depends on SYSFS
49913+ help
49914+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
49915+ any filesystem normally mounted under it (e.g. debugfs) will be
49916+ mostly accessible only by root. These filesystems generally provide access
49917+ to hardware and debug information that isn't appropriate for unprivileged
49918+ users of the system. Sysfs and debugfs have also become a large source
49919+ of new vulnerabilities, ranging from infoleaks to local compromise.
49920+ There has been very little oversight with an eye toward security involved
49921+ in adding new exporters of information to these filesystems, so their
49922+ use is discouraged.
49923+ For reasons of compatibility, a few directories have been whitelisted
49924+ for access by non-root users:
49925+ /sys/fs/selinux
49926+ /sys/fs/fuse
49927+ /sys/devices/system/cpu
49928+
49929+config GRKERNSEC_ROFS
49930+ bool "Runtime read-only mount protection"
49931+ help
49932+ If you say Y here, a sysctl option with name "romount_protect" will
49933+ be created. By setting this option to 1 at runtime, filesystems
49934+ will be protected in the following ways:
49935+ * No new writable mounts will be allowed
49936+ * Existing read-only mounts won't be able to be remounted read/write
49937+ * Write operations will be denied on all block devices
49938+ This option acts independently of grsec_lock: once it is set to 1,
49939+ it cannot be turned off. Therefore, please be mindful of the resulting
49940+ behavior if this option is enabled in an init script on a read-only
49941+ filesystem. This feature is mainly intended for secure embedded systems.
49942+
49943+config GRKERNSEC_CHROOT
49944+ bool "Chroot jail restrictions"
49945+ default y if GRKERNSEC_CONFIG_AUTO
49946+ help
49947+ If you say Y here, you will be able to choose several options that will
49948+ make breaking out of a chrooted jail much more difficult. If you
49949+ encounter no software incompatibilities with the following options, it
49950+ is recommended that you enable each one.
49951+
49952+config GRKERNSEC_CHROOT_MOUNT
49953+ bool "Deny mounts"
49954+ default y if GRKERNSEC_CONFIG_AUTO
49955+ depends on GRKERNSEC_CHROOT
49956+ help
49957+ If you say Y here, processes inside a chroot will not be able to
49958+ mount or remount filesystems. If the sysctl option is enabled, a
49959+ sysctl option with name "chroot_deny_mount" is created.
49960+
49961+config GRKERNSEC_CHROOT_DOUBLE
49962+ bool "Deny double-chroots"
49963+ default y if GRKERNSEC_CONFIG_AUTO
49964+ depends on GRKERNSEC_CHROOT
49965+ help
49966+ If you say Y here, processes inside a chroot will not be able to chroot
49967+ again outside the chroot. This is a widely used method of breaking
49968+ out of a chroot jail and should not be allowed. If the sysctl
49969+ option is enabled, a sysctl option with name
49970+ "chroot_deny_chroot" is created.
49971+
49972+config GRKERNSEC_CHROOT_PIVOT
49973+ bool "Deny pivot_root in chroot"
49974+ default y if GRKERNSEC_CONFIG_AUTO
49975+ depends on GRKERNSEC_CHROOT
49976+ help
49977+ If you say Y here, processes inside a chroot will not be able to use
49978+ a function called pivot_root() that was introduced in Linux 2.3.41. It
49979+ works similar to chroot in that it changes the root filesystem. This
49980+ function could be misused in a chrooted process to attempt to break out
49981+ of the chroot, and therefore should not be allowed. If the sysctl
49982+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
49983+ created.
49984+
49985+config GRKERNSEC_CHROOT_CHDIR
49986+ bool "Enforce chdir(\"/\") on all chroots"
49987+ default y if GRKERNSEC_CONFIG_AUTO
49988+ depends on GRKERNSEC_CHROOT
49989+ help
49990+ If you say Y here, the current working directory of all newly-chrooted
49991+ applications will be set to the the root directory of the chroot.
49992+ The man page on chroot(2) states:
49993+ Note that this call does not change the current working
49994+ directory, so that `.' can be outside the tree rooted at
49995+ `/'. In particular, the super-user can escape from a
49996+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
49997+
49998+ It is recommended that you say Y here, since it's not known to break
49999+ any software. If the sysctl option is enabled, a sysctl option with
50000+ name "chroot_enforce_chdir" is created.
50001+
50002+config GRKERNSEC_CHROOT_CHMOD
50003+ bool "Deny (f)chmod +s"
50004+ default y if GRKERNSEC_CONFIG_AUTO
50005+ depends on GRKERNSEC_CHROOT
50006+ help
50007+ If you say Y here, processes inside a chroot will not be able to chmod
50008+ or fchmod files to make them have suid or sgid bits. This protects
50009+ against another published method of breaking a chroot. If the sysctl
50010+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
50011+ created.
50012+
50013+config GRKERNSEC_CHROOT_FCHDIR
50014+ bool "Deny fchdir out of chroot"
50015+ default y if GRKERNSEC_CONFIG_AUTO
50016+ depends on GRKERNSEC_CHROOT
50017+ help
50018+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
50019+ to a file descriptor of the chrooting process that points to a directory
50020+ outside the filesystem will be stopped. If the sysctl option
50021+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50022+
50023+config GRKERNSEC_CHROOT_MKNOD
50024+ bool "Deny mknod"
50025+ default y if GRKERNSEC_CONFIG_AUTO
50026+ depends on GRKERNSEC_CHROOT
50027+ help
50028+ If you say Y here, processes inside a chroot will not be allowed to
50029+ mknod. The problem with using mknod inside a chroot is that it
50030+ would allow an attacker to create a device entry that is the same
50031+ as one on the physical root of your system, which could range from
50032+ anything from the console device to a device for your harddrive (which
50033+ they could then use to wipe the drive or steal data). It is recommended
50034+ that you say Y here, unless you run into software incompatibilities.
50035+ If the sysctl option is enabled, a sysctl option with name
50036+ "chroot_deny_mknod" is created.
50037+
50038+config GRKERNSEC_CHROOT_SHMAT
50039+ bool "Deny shmat() out of chroot"
50040+ default y if GRKERNSEC_CONFIG_AUTO
50041+ depends on GRKERNSEC_CHROOT
50042+ help
50043+ If you say Y here, processes inside a chroot will not be able to attach
50044+ to shared memory segments that were created outside of the chroot jail.
50045+ It is recommended that you say Y here. If the sysctl option is enabled,
50046+ a sysctl option with name "chroot_deny_shmat" is created.
50047+
50048+config GRKERNSEC_CHROOT_UNIX
50049+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
50050+ default y if GRKERNSEC_CONFIG_AUTO
50051+ depends on GRKERNSEC_CHROOT
50052+ help
50053+ If you say Y here, processes inside a chroot will not be able to
50054+ connect to abstract (meaning not belonging to a filesystem) Unix
50055+ domain sockets that were bound outside of a chroot. It is recommended
50056+ that you say Y here. If the sysctl option is enabled, a sysctl option
50057+ with name "chroot_deny_unix" is created.
50058+
50059+config GRKERNSEC_CHROOT_FINDTASK
50060+ bool "Protect outside processes"
50061+ default y if GRKERNSEC_CONFIG_AUTO
50062+ depends on GRKERNSEC_CHROOT
50063+ help
50064+ If you say Y here, processes inside a chroot will not be able to
50065+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50066+ getsid, or view any process outside of the chroot. If the sysctl
50067+ option is enabled, a sysctl option with name "chroot_findtask" is
50068+ created.
50069+
50070+config GRKERNSEC_CHROOT_NICE
50071+ bool "Restrict priority changes"
50072+ default y if GRKERNSEC_CONFIG_AUTO
50073+ depends on GRKERNSEC_CHROOT
50074+ help
50075+ If you say Y here, processes inside a chroot will not be able to raise
50076+ the priority of processes in the chroot, or alter the priority of
50077+ processes outside the chroot. This provides more security than simply
50078+ removing CAP_SYS_NICE from the process' capability set. If the
50079+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50080+ is created.
50081+
50082+config GRKERNSEC_CHROOT_SYSCTL
50083+ bool "Deny sysctl writes"
50084+ default y if GRKERNSEC_CONFIG_AUTO
50085+ depends on GRKERNSEC_CHROOT
50086+ help
50087+ If you say Y here, an attacker in a chroot will not be able to
50088+ write to sysctl entries, either by sysctl(2) or through a /proc
50089+ interface. It is strongly recommended that you say Y here. If the
50090+ sysctl option is enabled, a sysctl option with name
50091+ "chroot_deny_sysctl" is created.
50092+
50093+config GRKERNSEC_CHROOT_CAPS
50094+ bool "Capability restrictions"
50095+ default y if GRKERNSEC_CONFIG_AUTO
50096+ depends on GRKERNSEC_CHROOT
50097+ help
50098+ If you say Y here, the capabilities on all processes within a
50099+ chroot jail will be lowered to stop module insertion, raw i/o,
50100+ system and net admin tasks, rebooting the system, modifying immutable
50101+ files, modifying IPC owned by another, and changing the system time.
50102+ This is left an option because it can break some apps. Disable this
50103+ if your chrooted apps are having problems performing those kinds of
50104+ tasks. If the sysctl option is enabled, a sysctl option with
50105+ name "chroot_caps" is created.
50106+
50107+endmenu
50108+menu "Kernel Auditing"
50109+depends on GRKERNSEC
50110+
50111+config GRKERNSEC_AUDIT_GROUP
50112+ bool "Single group for auditing"
50113+ help
50114+ If you say Y here, the exec, chdir, and (un)mount logging features
50115+ will only operate on a group you specify. This option is recommended
50116+ if you only want to watch certain users instead of having a large
50117+ amount of logs from the entire system. If the sysctl option is enabled,
50118+ a sysctl option with name "audit_group" is created.
50119+
50120+config GRKERNSEC_AUDIT_GID
50121+ int "GID for auditing"
50122+ depends on GRKERNSEC_AUDIT_GROUP
50123+ default 1007
50124+
50125+config GRKERNSEC_EXECLOG
50126+ bool "Exec logging"
50127+ help
50128+ If you say Y here, all execve() calls will be logged (since the
50129+ other exec*() calls are frontends to execve(), all execution
50130+ will be logged). Useful for shell-servers that like to keep track
50131+ of their users. If the sysctl option is enabled, a sysctl option with
50132+ name "exec_logging" is created.
50133+ WARNING: This option when enabled will produce a LOT of logs, especially
50134+ on an active system.
50135+
50136+config GRKERNSEC_RESLOG
50137+ bool "Resource logging"
50138+ default y if GRKERNSEC_CONFIG_AUTO
50139+ help
50140+ If you say Y here, all attempts to overstep resource limits will
50141+ be logged with the resource name, the requested size, and the current
50142+ limit. It is highly recommended that you say Y here. If the sysctl
50143+ option is enabled, a sysctl option with name "resource_logging" is
50144+ created. If the RBAC system is enabled, the sysctl value is ignored.
50145+
50146+config GRKERNSEC_CHROOT_EXECLOG
50147+ bool "Log execs within chroot"
50148+ help
50149+ If you say Y here, all executions inside a chroot jail will be logged
50150+ to syslog. This can cause a large amount of logs if certain
50151+ applications (eg. djb's daemontools) are installed on the system, and
50152+ is therefore left as an option. If the sysctl option is enabled, a
50153+ sysctl option with name "chroot_execlog" is created.
50154+
50155+config GRKERNSEC_AUDIT_PTRACE
50156+ bool "Ptrace logging"
50157+ help
50158+ If you say Y here, all attempts to attach to a process via ptrace
50159+ will be logged. If the sysctl option is enabled, a sysctl option
50160+ with name "audit_ptrace" is created.
50161+
50162+config GRKERNSEC_AUDIT_CHDIR
50163+ bool "Chdir logging"
50164+ help
50165+ If you say Y here, all chdir() calls will be logged. If the sysctl
50166+ option is enabled, a sysctl option with name "audit_chdir" is created.
50167+
50168+config GRKERNSEC_AUDIT_MOUNT
50169+ bool "(Un)Mount logging"
50170+ help
50171+ If you say Y here, all mounts and unmounts will be logged. If the
50172+ sysctl option is enabled, a sysctl option with name "audit_mount" is
50173+ created.
50174+
50175+config GRKERNSEC_SIGNAL
50176+ bool "Signal logging"
50177+ default y if GRKERNSEC_CONFIG_AUTO
50178+ help
50179+ If you say Y here, certain important signals will be logged, such as
50180+ SIGSEGV, which will as a result inform you of when a error in a program
50181+ occurred, which in some cases could mean a possible exploit attempt.
50182+ If the sysctl option is enabled, a sysctl option with name
50183+ "signal_logging" is created.
50184+
50185+config GRKERNSEC_FORKFAIL
50186+ bool "Fork failure logging"
50187+ help
50188+ If you say Y here, all failed fork() attempts will be logged.
50189+ This could suggest a fork bomb, or someone attempting to overstep
50190+ their process limit. If the sysctl option is enabled, a sysctl option
50191+ with name "forkfail_logging" is created.
50192+
50193+config GRKERNSEC_TIME
50194+ bool "Time change logging"
50195+ default y if GRKERNSEC_CONFIG_AUTO
50196+ help
50197+ If you say Y here, any changes of the system clock will be logged.
50198+ If the sysctl option is enabled, a sysctl option with name
50199+ "timechange_logging" is created.
50200+
50201+config GRKERNSEC_PROC_IPADDR
50202+ bool "/proc/<pid>/ipaddr support"
50203+ default y if GRKERNSEC_CONFIG_AUTO
50204+ help
50205+ If you say Y here, a new entry will be added to each /proc/<pid>
50206+ directory that contains the IP address of the person using the task.
50207+ The IP is carried across local TCP and AF_UNIX stream sockets.
50208+ This information can be useful for IDS/IPSes to perform remote response
50209+ to a local attack. The entry is readable by only the owner of the
50210+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50211+ the RBAC system), and thus does not create privacy concerns.
50212+
50213+config GRKERNSEC_RWXMAP_LOG
50214+ bool 'Denied RWX mmap/mprotect logging'
50215+ default y if GRKERNSEC_CONFIG_AUTO
50216+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50217+ help
50218+ If you say Y here, calls to mmap() and mprotect() with explicit
50219+ usage of PROT_WRITE and PROT_EXEC together will be logged when
50220+ denied by the PAX_MPROTECT feature. If the sysctl option is
50221+ enabled, a sysctl option with name "rwxmap_logging" is created.
50222+
50223+config GRKERNSEC_AUDIT_TEXTREL
50224+ bool 'ELF text relocations logging (READ HELP)'
50225+ depends on PAX_MPROTECT
50226+ help
50227+ If you say Y here, text relocations will be logged with the filename
50228+ of the offending library or binary. The purpose of the feature is
50229+ to help Linux distribution developers get rid of libraries and
50230+ binaries that need text relocations which hinder the future progress
50231+ of PaX. Only Linux distribution developers should say Y here, and
50232+ never on a production machine, as this option creates an information
50233+ leak that could aid an attacker in defeating the randomization of
50234+ a single memory region. If the sysctl option is enabled, a sysctl
50235+ option with name "audit_textrel" is created.
50236+
50237+endmenu
50238+
50239+menu "Executable Protections"
50240+depends on GRKERNSEC
50241+
50242+config GRKERNSEC_DMESG
50243+ bool "Dmesg(8) restriction"
50244+ default y if GRKERNSEC_CONFIG_AUTO
50245+ help
50246+ If you say Y here, non-root users will not be able to use dmesg(8)
50247+ to view up to the last 4kb of messages in the kernel's log buffer.
50248+ The kernel's log buffer often contains kernel addresses and other
50249+ identifying information useful to an attacker in fingerprinting a
50250+ system for a targeted exploit.
50251+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
50252+ created.
50253+
50254+config GRKERNSEC_HARDEN_PTRACE
50255+ bool "Deter ptrace-based process snooping"
50256+ default y if GRKERNSEC_CONFIG_AUTO
50257+ help
50258+ If you say Y here, TTY sniffers and other malicious monitoring
50259+ programs implemented through ptrace will be defeated. If you
50260+ have been using the RBAC system, this option has already been
50261+ enabled for several years for all users, with the ability to make
50262+ fine-grained exceptions.
50263+
50264+ This option only affects the ability of non-root users to ptrace
50265+ processes that are not a descendent of the ptracing process.
50266+ This means that strace ./binary and gdb ./binary will still work,
50267+ but attaching to arbitrary processes will not. If the sysctl
50268+ option is enabled, a sysctl option with name "harden_ptrace" is
50269+ created.
50270+
50271+config GRKERNSEC_PTRACE_READEXEC
50272+ bool "Require read access to ptrace sensitive binaries"
50273+ default y if GRKERNSEC_CONFIG_AUTO
50274+ help
50275+ If you say Y here, unprivileged users will not be able to ptrace unreadable
50276+ binaries. This option is useful in environments that
50277+ remove the read bits (e.g. file mode 4711) from suid binaries to
50278+ prevent infoleaking of their contents. This option adds
50279+ consistency to the use of that file mode, as the binary could normally
50280+ be read out when run without privileges while ptracing.
50281+
50282+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50283+ is created.
50284+
50285+config GRKERNSEC_SETXID
50286+ bool "Enforce consistent multithreaded privileges"
50287+ default y if GRKERNSEC_CONFIG_AUTO
50288+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50289+ help
50290+ If you say Y here, a change from a root uid to a non-root uid
50291+ in a multithreaded application will cause the resulting uids,
50292+ gids, supplementary groups, and capabilities in that thread
50293+ to be propagated to the other threads of the process. In most
50294+ cases this is unnecessary, as glibc will emulate this behavior
50295+ on behalf of the application. Other libcs do not act in the
50296+ same way, allowing the other threads of the process to continue
50297+ running with root privileges. If the sysctl option is enabled,
50298+ a sysctl option with name "consistent_setxid" is created.
50299+
50300+config GRKERNSEC_TPE
50301+ bool "Trusted Path Execution (TPE)"
50302+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50303+ help
50304+ If you say Y here, you will be able to choose a gid to add to the
50305+ supplementary groups of users you want to mark as "untrusted."
50306+ These users will not be able to execute any files that are not in
50307+ root-owned directories writable only by root. If the sysctl option
50308+ is enabled, a sysctl option with name "tpe" is created.
50309+
50310+config GRKERNSEC_TPE_ALL
50311+ bool "Partially restrict all non-root users"
50312+ depends on GRKERNSEC_TPE
50313+ help
50314+ If you say Y here, all non-root users will be covered under
50315+ a weaker TPE restriction. This is separate from, and in addition to,
50316+ the main TPE options that you have selected elsewhere. Thus, if a
50317+ "trusted" GID is chosen, this restriction applies to even that GID.
50318+ Under this restriction, all non-root users will only be allowed to
50319+ execute files in directories they own that are not group or
50320+ world-writable, or in directories owned by root and writable only by
50321+ root. If the sysctl option is enabled, a sysctl option with name
50322+ "tpe_restrict_all" is created.
50323+
50324+config GRKERNSEC_TPE_INVERT
50325+ bool "Invert GID option"
50326+ depends on GRKERNSEC_TPE
50327+ help
50328+ If you say Y here, the group you specify in the TPE configuration will
50329+ decide what group TPE restrictions will be *disabled* for. This
50330+ option is useful if you want TPE restrictions to be applied to most
50331+ users on the system. If the sysctl option is enabled, a sysctl option
50332+ with name "tpe_invert" is created. Unlike other sysctl options, this
50333+ entry will default to on for backward-compatibility.
50334+
50335+config GRKERNSEC_TPE_GID
50336+ int "GID for untrusted users"
50337+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50338+ default 1005
50339+ help
50340+ Setting this GID determines what group TPE restrictions will be
50341+ *enabled* for. If the sysctl option is enabled, a sysctl option
50342+ with name "tpe_gid" is created.
50343+
50344+config GRKERNSEC_TPE_GID
50345+ int "GID for trusted users"
50346+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50347+ default 1005
50348+ help
50349+ Setting this GID determines what group TPE restrictions will be
50350+ *disabled* for. If the sysctl option is enabled, a sysctl option
50351+ with name "tpe_gid" is created.
50352+
50353+endmenu
50354+menu "Network Protections"
50355+depends on GRKERNSEC
50356+
50357+config GRKERNSEC_RANDNET
50358+ bool "Larger entropy pools"
50359+ default y if GRKERNSEC_CONFIG_AUTO
50360+ help
50361+ If you say Y here, the entropy pools used for many features of Linux
50362+ and grsecurity will be doubled in size. Since several grsecurity
50363+ features use additional randomness, it is recommended that you say Y
50364+ here. Saying Y here has a similar effect as modifying
50365+ /proc/sys/kernel/random/poolsize.
50366+
50367+config GRKERNSEC_BLACKHOLE
50368+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50369+ default y if GRKERNSEC_CONFIG_AUTO
50370+ depends on NET
50371+ help
50372+ If you say Y here, neither TCP resets nor ICMP
50373+ destination-unreachable packets will be sent in response to packets
50374+ sent to ports for which no associated listening process exists.
50375+ This feature supports both IPV4 and IPV6 and exempts the
50376+ loopback interface from blackholing. Enabling this feature
50377+ makes a host more resilient to DoS attacks and reduces network
50378+ visibility against scanners.
50379+
50380+ The blackhole feature as-implemented is equivalent to the FreeBSD
50381+ blackhole feature, as it prevents RST responses to all packets, not
50382+ just SYNs. Under most application behavior this causes no
50383+ problems, but applications (like haproxy) may not close certain
50384+ connections in a way that cleanly terminates them on the remote
50385+ end, leaving the remote host in LAST_ACK state. Because of this
50386+ side-effect and to prevent intentional LAST_ACK DoSes, this
50387+ feature also adds automatic mitigation against such attacks.
50388+ The mitigation drastically reduces the amount of time a socket
50389+ can spend in LAST_ACK state. If you're using haproxy and not
50390+ all servers it connects to have this option enabled, consider
50391+ disabling this feature on the haproxy host.
50392+
50393+ If the sysctl option is enabled, two sysctl options with names
50394+ "ip_blackhole" and "lastack_retries" will be created.
50395+ While "ip_blackhole" takes the standard zero/non-zero on/off
50396+ toggle, "lastack_retries" uses the same kinds of values as
50397+ "tcp_retries1" and "tcp_retries2". The default value of 4
50398+ prevents a socket from lasting more than 45 seconds in LAST_ACK
50399+ state.
50400+
50401+config GRKERNSEC_SOCKET
50402+ bool "Socket restrictions"
50403+ depends on NET
50404+ help
50405+ If you say Y here, you will be able to choose from several options.
50406+ If you assign a GID on your system and add it to the supplementary
50407+ groups of users you want to restrict socket access to, this patch
50408+ will perform up to three things, based on the option(s) you choose.
50409+
50410+config GRKERNSEC_SOCKET_ALL
50411+ bool "Deny any sockets to group"
50412+ depends on GRKERNSEC_SOCKET
50413+ help
50414+ If you say Y here, you will be able to choose a GID of whose users will
50415+ be unable to connect to other hosts from your machine or run server
50416+ applications from your machine. If the sysctl option is enabled, a
50417+ sysctl option with name "socket_all" is created.
50418+
50419+config GRKERNSEC_SOCKET_ALL_GID
50420+ int "GID to deny all sockets for"
50421+ depends on GRKERNSEC_SOCKET_ALL
50422+ default 1004
50423+ help
50424+ Here you can choose the GID to disable socket access for. Remember to
50425+ add the users you want socket access disabled for to the GID
50426+ specified here. If the sysctl option is enabled, a sysctl option
50427+ with name "socket_all_gid" is created.
50428+
50429+config GRKERNSEC_SOCKET_CLIENT
50430+ bool "Deny client sockets to group"
50431+ depends on GRKERNSEC_SOCKET
50432+ help
50433+ If you say Y here, you will be able to choose a GID of whose users will
50434+ be unable to connect to other hosts from your machine, but will be
50435+ able to run servers. If this option is enabled, all users in the group
50436+ you specify will have to use passive mode when initiating ftp transfers
50437+ from the shell on your machine. If the sysctl option is enabled, a
50438+ sysctl option with name "socket_client" is created.
50439+
50440+config GRKERNSEC_SOCKET_CLIENT_GID
50441+ int "GID to deny client sockets for"
50442+ depends on GRKERNSEC_SOCKET_CLIENT
50443+ default 1003
50444+ help
50445+ Here you can choose the GID to disable client socket access for.
50446+ Remember to add the users you want client socket access disabled for to
50447+ the GID specified here. If the sysctl option is enabled, a sysctl
50448+ option with name "socket_client_gid" is created.
50449+
50450+config GRKERNSEC_SOCKET_SERVER
50451+ bool "Deny server sockets to group"
50452+ depends on GRKERNSEC_SOCKET
50453+ help
50454+ If you say Y here, you will be able to choose a GID of whose users will
50455+ be unable to run server applications from your machine. If the sysctl
50456+ option is enabled, a sysctl option with name "socket_server" is created.
50457+
50458+config GRKERNSEC_SOCKET_SERVER_GID
50459+ int "GID to deny server sockets for"
50460+ depends on GRKERNSEC_SOCKET_SERVER
50461+ default 1002
50462+ help
50463+ Here you can choose the GID to disable server socket access for.
50464+ Remember to add the users you want server socket access disabled for to
50465+ the GID specified here. If the sysctl option is enabled, a sysctl
50466+ option with name "socket_server_gid" is created.
50467+
50468+endmenu
50469+menu "Sysctl Support"
50470+depends on GRKERNSEC && SYSCTL
50471+
50472+config GRKERNSEC_SYSCTL
50473+ bool "Sysctl support"
50474+ default y if GRKERNSEC_CONFIG_AUTO
50475+ help
50476+ If you say Y here, you will be able to change the options that
50477+ grsecurity runs with at bootup, without having to recompile your
50478+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50479+ to enable (1) or disable (0) various features. All the sysctl entries
50480+ are mutable until the "grsec_lock" entry is set to a non-zero value.
50481+ All features enabled in the kernel configuration are disabled at boot
50482+ if you do not say Y to the "Turn on features by default" option.
50483+ All options should be set at startup, and the grsec_lock entry should
50484+ be set to a non-zero value after all the options are set.
50485+ *THIS IS EXTREMELY IMPORTANT*
50486+
50487+config GRKERNSEC_SYSCTL_DISTRO
50488+ bool "Extra sysctl support for distro makers (READ HELP)"
50489+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50490+ help
50491+ If you say Y here, additional sysctl options will be created
50492+ for features that affect processes running as root. Therefore,
50493+ it is critical when using this option that the grsec_lock entry be
50494+ enabled after boot. Only distros with prebuilt kernel packages
50495+ with this option enabled that can ensure grsec_lock is enabled
50496+ after boot should use this option.
50497+ *Failure to set grsec_lock after boot makes all grsec features
50498+ this option covers useless*
50499+
50500+ Currently this option creates the following sysctl entries:
50501+ "Disable Privileged I/O": "disable_priv_io"
50502+
50503+config GRKERNSEC_SYSCTL_ON
50504+ bool "Turn on features by default"
50505+ default y if GRKERNSEC_CONFIG_AUTO
50506+ depends on GRKERNSEC_SYSCTL
50507+ help
50508+ If you say Y here, instead of having all features enabled in the
50509+ kernel configuration disabled at boot time, the features will be
50510+ enabled at boot time. It is recommended you say Y here unless
50511+ there is some reason you would want all sysctl-tunable features to
50512+ be disabled by default. As mentioned elsewhere, it is important
50513+ to enable the grsec_lock entry once you have finished modifying
50514+ the sysctl entries.
50515+
50516+endmenu
50517+menu "Logging Options"
50518+depends on GRKERNSEC
50519+
50520+config GRKERNSEC_FLOODTIME
50521+ int "Seconds in between log messages (minimum)"
50522+ default 10
50523+ help
50524+ This option allows you to enforce the number of seconds between
50525+ grsecurity log messages. The default should be suitable for most
50526+ people, however, if you choose to change it, choose a value small enough
50527+ to allow informative logs to be produced, but large enough to
50528+ prevent flooding.
50529+
50530+config GRKERNSEC_FLOODBURST
50531+ int "Number of messages in a burst (maximum)"
50532+ default 6
50533+ help
50534+ This option allows you to choose the maximum number of messages allowed
50535+ within the flood time interval you chose in a separate option. The
50536+ default should be suitable for most people, however if you find that
50537+ many of your logs are being interpreted as flooding, you may want to
50538+ raise this value.
50539+
50540+endmenu
50541diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50542new file mode 100644
50543index 0000000..1b9afa9
50544--- /dev/null
50545+++ b/grsecurity/Makefile
50546@@ -0,0 +1,38 @@
50547+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50548+# during 2001-2009 it has been completely redesigned by Brad Spengler
50549+# into an RBAC system
50550+#
50551+# All code in this directory and various hooks inserted throughout the kernel
50552+# are copyright Brad Spengler - Open Source Security, Inc., and released
50553+# under the GPL v2 or higher
50554+
50555+KBUILD_CFLAGS += -Werror
50556+
50557+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50558+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
50559+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50560+
50561+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50562+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50563+ gracl_learn.o grsec_log.o
50564+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50565+
50566+ifdef CONFIG_NET
50567+obj-y += grsec_sock.o
50568+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50569+endif
50570+
50571+ifndef CONFIG_GRKERNSEC
50572+obj-y += grsec_disabled.o
50573+endif
50574+
50575+ifdef CONFIG_GRKERNSEC_HIDESYM
50576+extra-y := grsec_hidesym.o
50577+$(obj)/grsec_hidesym.o:
50578+ @-chmod -f 500 /boot
50579+ @-chmod -f 500 /lib/modules
50580+ @-chmod -f 500 /lib64/modules
50581+ @-chmod -f 500 /lib32/modules
50582+ @-chmod -f 700 .
50583+ @echo ' grsec: protected kernel image paths'
50584+endif
50585diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50586new file mode 100644
50587index 0000000..7a5922f
50588--- /dev/null
50589+++ b/grsecurity/gracl.c
50590@@ -0,0 +1,4016 @@
50591+#include <linux/kernel.h>
50592+#include <linux/module.h>
50593+#include <linux/sched.h>
50594+#include <linux/mm.h>
50595+#include <linux/file.h>
50596+#include <linux/fs.h>
50597+#include <linux/namei.h>
50598+#include <linux/mount.h>
50599+#include <linux/tty.h>
50600+#include <linux/proc_fs.h>
50601+#include <linux/lglock.h>
50602+#include <linux/slab.h>
50603+#include <linux/vmalloc.h>
50604+#include <linux/types.h>
50605+#include <linux/sysctl.h>
50606+#include <linux/netdevice.h>
50607+#include <linux/ptrace.h>
50608+#include <linux/gracl.h>
50609+#include <linux/gralloc.h>
50610+#include <linux/security.h>
50611+#include <linux/grinternal.h>
50612+#include <linux/pid_namespace.h>
50613+#include <linux/stop_machine.h>
50614+#include <linux/fdtable.h>
50615+#include <linux/percpu.h>
50616+#include "../fs/mount.h"
50617+
50618+#include <asm/uaccess.h>
50619+#include <asm/errno.h>
50620+#include <asm/mman.h>
50621+
50622+static struct acl_role_db acl_role_set;
50623+static struct name_db name_set;
50624+static struct inodev_db inodev_set;
50625+
50626+/* for keeping track of userspace pointers used for subjects, so we
50627+ can share references in the kernel as well
50628+*/
50629+
50630+static struct path real_root;
50631+
50632+static struct acl_subj_map_db subj_map_set;
50633+
50634+static struct acl_role_label *default_role;
50635+
50636+static struct acl_role_label *role_list;
50637+
50638+static u16 acl_sp_role_value;
50639+
50640+extern char *gr_shared_page[4];
50641+static DEFINE_MUTEX(gr_dev_mutex);
50642+DEFINE_RWLOCK(gr_inode_lock);
50643+
50644+struct gr_arg *gr_usermode;
50645+
50646+static unsigned int gr_status __read_only = GR_STATUS_INIT;
50647+
50648+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
50649+extern void gr_clear_learn_entries(void);
50650+
50651+#ifdef CONFIG_GRKERNSEC_RESLOG
50652+extern void gr_log_resource(const struct task_struct *task,
50653+ const int res, const unsigned long wanted, const int gt);
50654+#endif
50655+
50656+unsigned char *gr_system_salt;
50657+unsigned char *gr_system_sum;
50658+
50659+static struct sprole_pw **acl_special_roles = NULL;
50660+static __u16 num_sprole_pws = 0;
50661+
50662+static struct acl_role_label *kernel_role = NULL;
50663+
50664+static unsigned int gr_auth_attempts = 0;
50665+static unsigned long gr_auth_expires = 0UL;
50666+
50667+#ifdef CONFIG_NET
50668+extern struct vfsmount *sock_mnt;
50669+#endif
50670+
50671+extern struct vfsmount *pipe_mnt;
50672+extern struct vfsmount *shm_mnt;
50673+#ifdef CONFIG_HUGETLBFS
50674+extern struct vfsmount *hugetlbfs_vfsmount;
50675+#endif
50676+
50677+static struct acl_object_label *fakefs_obj_rw;
50678+static struct acl_object_label *fakefs_obj_rwx;
50679+
50680+extern int gr_init_uidset(void);
50681+extern void gr_free_uidset(void);
50682+extern void gr_remove_uid(uid_t uid);
50683+extern int gr_find_uid(uid_t uid);
50684+
50685+DECLARE_BRLOCK(vfsmount_lock);
50686+
50687+__inline__ int
50688+gr_acl_is_enabled(void)
50689+{
50690+ return (gr_status & GR_READY);
50691+}
50692+
50693+#ifdef CONFIG_BTRFS_FS
50694+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
50695+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
50696+#endif
50697+
50698+static inline dev_t __get_dev(const struct dentry *dentry)
50699+{
50700+#ifdef CONFIG_BTRFS_FS
50701+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
50702+ return get_btrfs_dev_from_inode(dentry->d_inode);
50703+ else
50704+#endif
50705+ return dentry->d_inode->i_sb->s_dev;
50706+}
50707+
50708+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50709+{
50710+ return __get_dev(dentry);
50711+}
50712+
50713+static char gr_task_roletype_to_char(struct task_struct *task)
50714+{
50715+ switch (task->role->roletype &
50716+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
50717+ GR_ROLE_SPECIAL)) {
50718+ case GR_ROLE_DEFAULT:
50719+ return 'D';
50720+ case GR_ROLE_USER:
50721+ return 'U';
50722+ case GR_ROLE_GROUP:
50723+ return 'G';
50724+ case GR_ROLE_SPECIAL:
50725+ return 'S';
50726+ }
50727+
50728+ return 'X';
50729+}
50730+
50731+char gr_roletype_to_char(void)
50732+{
50733+ return gr_task_roletype_to_char(current);
50734+}
50735+
50736+__inline__ int
50737+gr_acl_tpe_check(void)
50738+{
50739+ if (unlikely(!(gr_status & GR_READY)))
50740+ return 0;
50741+ if (current->role->roletype & GR_ROLE_TPE)
50742+ return 1;
50743+ else
50744+ return 0;
50745+}
50746+
50747+int
50748+gr_handle_rawio(const struct inode *inode)
50749+{
50750+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50751+ if (inode && S_ISBLK(inode->i_mode) &&
50752+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
50753+ !capable(CAP_SYS_RAWIO))
50754+ return 1;
50755+#endif
50756+ return 0;
50757+}
50758+
50759+static int
50760+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
50761+{
50762+ if (likely(lena != lenb))
50763+ return 0;
50764+
50765+ return !memcmp(a, b, lena);
50766+}
50767+
50768+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
50769+{
50770+ *buflen -= namelen;
50771+ if (*buflen < 0)
50772+ return -ENAMETOOLONG;
50773+ *buffer -= namelen;
50774+ memcpy(*buffer, str, namelen);
50775+ return 0;
50776+}
50777+
50778+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
50779+{
50780+ return prepend(buffer, buflen, name->name, name->len);
50781+}
50782+
50783+static int prepend_path(const struct path *path, struct path *root,
50784+ char **buffer, int *buflen)
50785+{
50786+ struct dentry *dentry = path->dentry;
50787+ struct vfsmount *vfsmnt = path->mnt;
50788+ struct mount *mnt = real_mount(vfsmnt);
50789+ bool slash = false;
50790+ int error = 0;
50791+
50792+ while (dentry != root->dentry || vfsmnt != root->mnt) {
50793+ struct dentry * parent;
50794+
50795+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
50796+ /* Global root? */
50797+ if (!mnt_has_parent(mnt)) {
50798+ goto out;
50799+ }
50800+ dentry = mnt->mnt_mountpoint;
50801+ mnt = mnt->mnt_parent;
50802+ vfsmnt = &mnt->mnt;
50803+ continue;
50804+ }
50805+ parent = dentry->d_parent;
50806+ prefetch(parent);
50807+ spin_lock(&dentry->d_lock);
50808+ error = prepend_name(buffer, buflen, &dentry->d_name);
50809+ spin_unlock(&dentry->d_lock);
50810+ if (!error)
50811+ error = prepend(buffer, buflen, "/", 1);
50812+ if (error)
50813+ break;
50814+
50815+ slash = true;
50816+ dentry = parent;
50817+ }
50818+
50819+out:
50820+ if (!error && !slash)
50821+ error = prepend(buffer, buflen, "/", 1);
50822+
50823+ return error;
50824+}
50825+
50826+/* this must be called with vfsmount_lock and rename_lock held */
50827+
50828+static char *__our_d_path(const struct path *path, struct path *root,
50829+ char *buf, int buflen)
50830+{
50831+ char *res = buf + buflen;
50832+ int error;
50833+
50834+ prepend(&res, &buflen, "\0", 1);
50835+ error = prepend_path(path, root, &res, &buflen);
50836+ if (error)
50837+ return ERR_PTR(error);
50838+
50839+ return res;
50840+}
50841+
50842+static char *
50843+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
50844+{
50845+ char *retval;
50846+
50847+ retval = __our_d_path(path, root, buf, buflen);
50848+ if (unlikely(IS_ERR(retval)))
50849+ retval = strcpy(buf, "<path too long>");
50850+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
50851+ retval[1] = '\0';
50852+
50853+ return retval;
50854+}
50855+
50856+static char *
50857+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50858+ char *buf, int buflen)
50859+{
50860+ struct path path;
50861+ char *res;
50862+
50863+ path.dentry = (struct dentry *)dentry;
50864+ path.mnt = (struct vfsmount *)vfsmnt;
50865+
50866+ /* we can use real_root.dentry, real_root.mnt, because this is only called
50867+ by the RBAC system */
50868+ res = gen_full_path(&path, &real_root, buf, buflen);
50869+
50870+ return res;
50871+}
50872+
50873+static char *
50874+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50875+ char *buf, int buflen)
50876+{
50877+ char *res;
50878+ struct path path;
50879+ struct path root;
50880+ struct task_struct *reaper = init_pid_ns.child_reaper;
50881+
50882+ path.dentry = (struct dentry *)dentry;
50883+ path.mnt = (struct vfsmount *)vfsmnt;
50884+
50885+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
50886+ get_fs_root(reaper->fs, &root);
50887+
50888+ write_seqlock(&rename_lock);
50889+ br_read_lock(vfsmount_lock);
50890+ res = gen_full_path(&path, &root, buf, buflen);
50891+ br_read_unlock(vfsmount_lock);
50892+ write_sequnlock(&rename_lock);
50893+
50894+ path_put(&root);
50895+ return res;
50896+}
50897+
50898+static char *
50899+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50900+{
50901+ char *ret;
50902+ write_seqlock(&rename_lock);
50903+ br_read_lock(vfsmount_lock);
50904+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50905+ PAGE_SIZE);
50906+ br_read_unlock(vfsmount_lock);
50907+ write_sequnlock(&rename_lock);
50908+ return ret;
50909+}
50910+
50911+static char *
50912+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50913+{
50914+ char *ret;
50915+ char *buf;
50916+ int buflen;
50917+
50918+ write_seqlock(&rename_lock);
50919+ br_read_lock(vfsmount_lock);
50920+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50921+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
50922+ buflen = (int)(ret - buf);
50923+ if (buflen >= 5)
50924+ prepend(&ret, &buflen, "/proc", 5);
50925+ else
50926+ ret = strcpy(buf, "<path too long>");
50927+ br_read_unlock(vfsmount_lock);
50928+ write_sequnlock(&rename_lock);
50929+ return ret;
50930+}
50931+
50932+char *
50933+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
50934+{
50935+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50936+ PAGE_SIZE);
50937+}
50938+
50939+char *
50940+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
50941+{
50942+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
50943+ PAGE_SIZE);
50944+}
50945+
50946+char *
50947+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
50948+{
50949+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
50950+ PAGE_SIZE);
50951+}
50952+
50953+char *
50954+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
50955+{
50956+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
50957+ PAGE_SIZE);
50958+}
50959+
50960+char *
50961+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
50962+{
50963+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
50964+ PAGE_SIZE);
50965+}
50966+
50967+__inline__ __u32
50968+to_gr_audit(const __u32 reqmode)
50969+{
50970+ /* masks off auditable permission flags, then shifts them to create
50971+ auditing flags, and adds the special case of append auditing if
50972+ we're requesting write */
50973+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
50974+}
50975+
50976+struct acl_subject_label *
50977+lookup_subject_map(const struct acl_subject_label *userp)
50978+{
50979+ unsigned int index = shash(userp, subj_map_set.s_size);
50980+ struct subject_map *match;
50981+
50982+ match = subj_map_set.s_hash[index];
50983+
50984+ while (match && match->user != userp)
50985+ match = match->next;
50986+
50987+ if (match != NULL)
50988+ return match->kernel;
50989+ else
50990+ return NULL;
50991+}
50992+
50993+static void
50994+insert_subj_map_entry(struct subject_map *subjmap)
50995+{
50996+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
50997+ struct subject_map **curr;
50998+
50999+ subjmap->prev = NULL;
51000+
51001+ curr = &subj_map_set.s_hash[index];
51002+ if (*curr != NULL)
51003+ (*curr)->prev = subjmap;
51004+
51005+ subjmap->next = *curr;
51006+ *curr = subjmap;
51007+
51008+ return;
51009+}
51010+
51011+static struct acl_role_label *
51012+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51013+ const gid_t gid)
51014+{
51015+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51016+ struct acl_role_label *match;
51017+ struct role_allowed_ip *ipp;
51018+ unsigned int x;
51019+ u32 curr_ip = task->signal->curr_ip;
51020+
51021+ task->signal->saved_ip = curr_ip;
51022+
51023+ match = acl_role_set.r_hash[index];
51024+
51025+ while (match) {
51026+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51027+ for (x = 0; x < match->domain_child_num; x++) {
51028+ if (match->domain_children[x] == uid)
51029+ goto found;
51030+ }
51031+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51032+ break;
51033+ match = match->next;
51034+ }
51035+found:
51036+ if (match == NULL) {
51037+ try_group:
51038+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51039+ match = acl_role_set.r_hash[index];
51040+
51041+ while (match) {
51042+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51043+ for (x = 0; x < match->domain_child_num; x++) {
51044+ if (match->domain_children[x] == gid)
51045+ goto found2;
51046+ }
51047+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51048+ break;
51049+ match = match->next;
51050+ }
51051+found2:
51052+ if (match == NULL)
51053+ match = default_role;
51054+ if (match->allowed_ips == NULL)
51055+ return match;
51056+ else {
51057+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51058+ if (likely
51059+ ((ntohl(curr_ip) & ipp->netmask) ==
51060+ (ntohl(ipp->addr) & ipp->netmask)))
51061+ return match;
51062+ }
51063+ match = default_role;
51064+ }
51065+ } else if (match->allowed_ips == NULL) {
51066+ return match;
51067+ } else {
51068+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51069+ if (likely
51070+ ((ntohl(curr_ip) & ipp->netmask) ==
51071+ (ntohl(ipp->addr) & ipp->netmask)))
51072+ return match;
51073+ }
51074+ goto try_group;
51075+ }
51076+
51077+ return match;
51078+}
51079+
51080+struct acl_subject_label *
51081+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51082+ const struct acl_role_label *role)
51083+{
51084+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51085+ struct acl_subject_label *match;
51086+
51087+ match = role->subj_hash[index];
51088+
51089+ while (match && (match->inode != ino || match->device != dev ||
51090+ (match->mode & GR_DELETED))) {
51091+ match = match->next;
51092+ }
51093+
51094+ if (match && !(match->mode & GR_DELETED))
51095+ return match;
51096+ else
51097+ return NULL;
51098+}
51099+
51100+struct acl_subject_label *
51101+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51102+ const struct acl_role_label *role)
51103+{
51104+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51105+ struct acl_subject_label *match;
51106+
51107+ match = role->subj_hash[index];
51108+
51109+ while (match && (match->inode != ino || match->device != dev ||
51110+ !(match->mode & GR_DELETED))) {
51111+ match = match->next;
51112+ }
51113+
51114+ if (match && (match->mode & GR_DELETED))
51115+ return match;
51116+ else
51117+ return NULL;
51118+}
51119+
51120+static struct acl_object_label *
51121+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51122+ const struct acl_subject_label *subj)
51123+{
51124+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51125+ struct acl_object_label *match;
51126+
51127+ match = subj->obj_hash[index];
51128+
51129+ while (match && (match->inode != ino || match->device != dev ||
51130+ (match->mode & GR_DELETED))) {
51131+ match = match->next;
51132+ }
51133+
51134+ if (match && !(match->mode & GR_DELETED))
51135+ return match;
51136+ else
51137+ return NULL;
51138+}
51139+
51140+static struct acl_object_label *
51141+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51142+ const struct acl_subject_label *subj)
51143+{
51144+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51145+ struct acl_object_label *match;
51146+
51147+ match = subj->obj_hash[index];
51148+
51149+ while (match && (match->inode != ino || match->device != dev ||
51150+ !(match->mode & GR_DELETED))) {
51151+ match = match->next;
51152+ }
51153+
51154+ if (match && (match->mode & GR_DELETED))
51155+ return match;
51156+
51157+ match = subj->obj_hash[index];
51158+
51159+ while (match && (match->inode != ino || match->device != dev ||
51160+ (match->mode & GR_DELETED))) {
51161+ match = match->next;
51162+ }
51163+
51164+ if (match && !(match->mode & GR_DELETED))
51165+ return match;
51166+ else
51167+ return NULL;
51168+}
51169+
51170+static struct name_entry *
51171+lookup_name_entry(const char *name)
51172+{
51173+ unsigned int len = strlen(name);
51174+ unsigned int key = full_name_hash(name, len);
51175+ unsigned int index = key % name_set.n_size;
51176+ struct name_entry *match;
51177+
51178+ match = name_set.n_hash[index];
51179+
51180+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51181+ match = match->next;
51182+
51183+ return match;
51184+}
51185+
51186+static struct name_entry *
51187+lookup_name_entry_create(const char *name)
51188+{
51189+ unsigned int len = strlen(name);
51190+ unsigned int key = full_name_hash(name, len);
51191+ unsigned int index = key % name_set.n_size;
51192+ struct name_entry *match;
51193+
51194+ match = name_set.n_hash[index];
51195+
51196+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51197+ !match->deleted))
51198+ match = match->next;
51199+
51200+ if (match && match->deleted)
51201+ return match;
51202+
51203+ match = name_set.n_hash[index];
51204+
51205+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51206+ match->deleted))
51207+ match = match->next;
51208+
51209+ if (match && !match->deleted)
51210+ return match;
51211+ else
51212+ return NULL;
51213+}
51214+
51215+static struct inodev_entry *
51216+lookup_inodev_entry(const ino_t ino, const dev_t dev)
51217+{
51218+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
51219+ struct inodev_entry *match;
51220+
51221+ match = inodev_set.i_hash[index];
51222+
51223+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51224+ match = match->next;
51225+
51226+ return match;
51227+}
51228+
51229+static void
51230+insert_inodev_entry(struct inodev_entry *entry)
51231+{
51232+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51233+ inodev_set.i_size);
51234+ struct inodev_entry **curr;
51235+
51236+ entry->prev = NULL;
51237+
51238+ curr = &inodev_set.i_hash[index];
51239+ if (*curr != NULL)
51240+ (*curr)->prev = entry;
51241+
51242+ entry->next = *curr;
51243+ *curr = entry;
51244+
51245+ return;
51246+}
51247+
51248+static void
51249+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51250+{
51251+ unsigned int index =
51252+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51253+ struct acl_role_label **curr;
51254+ struct acl_role_label *tmp, *tmp2;
51255+
51256+ curr = &acl_role_set.r_hash[index];
51257+
51258+ /* simple case, slot is empty, just set it to our role */
51259+ if (*curr == NULL) {
51260+ *curr = role;
51261+ } else {
51262+ /* example:
51263+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
51264+ 2 -> 3
51265+ */
51266+ /* first check to see if we can already be reached via this slot */
51267+ tmp = *curr;
51268+ while (tmp && tmp != role)
51269+ tmp = tmp->next;
51270+ if (tmp == role) {
51271+ /* we don't need to add ourselves to this slot's chain */
51272+ return;
51273+ }
51274+ /* we need to add ourselves to this chain, two cases */
51275+ if (role->next == NULL) {
51276+ /* simple case, append the current chain to our role */
51277+ role->next = *curr;
51278+ *curr = role;
51279+ } else {
51280+ /* 1 -> 2 -> 3 -> 4
51281+ 2 -> 3 -> 4
51282+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51283+ */
51284+ /* trickier case: walk our role's chain until we find
51285+ the role for the start of the current slot's chain */
51286+ tmp = role;
51287+ tmp2 = *curr;
51288+ while (tmp->next && tmp->next != tmp2)
51289+ tmp = tmp->next;
51290+ if (tmp->next == tmp2) {
51291+ /* from example above, we found 3, so just
51292+ replace this slot's chain with ours */
51293+ *curr = role;
51294+ } else {
51295+ /* we didn't find a subset of our role's chain
51296+ in the current slot's chain, so append their
51297+ chain to ours, and set us as the first role in
51298+ the slot's chain
51299+
51300+ we could fold this case with the case above,
51301+ but making it explicit for clarity
51302+ */
51303+ tmp->next = tmp2;
51304+ *curr = role;
51305+ }
51306+ }
51307+ }
51308+
51309+ return;
51310+}
51311+
51312+static void
51313+insert_acl_role_label(struct acl_role_label *role)
51314+{
51315+ int i;
51316+
51317+ if (role_list == NULL) {
51318+ role_list = role;
51319+ role->prev = NULL;
51320+ } else {
51321+ role->prev = role_list;
51322+ role_list = role;
51323+ }
51324+
51325+ /* used for hash chains */
51326+ role->next = NULL;
51327+
51328+ if (role->roletype & GR_ROLE_DOMAIN) {
51329+ for (i = 0; i < role->domain_child_num; i++)
51330+ __insert_acl_role_label(role, role->domain_children[i]);
51331+ } else
51332+ __insert_acl_role_label(role, role->uidgid);
51333+}
51334+
51335+static int
51336+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51337+{
51338+ struct name_entry **curr, *nentry;
51339+ struct inodev_entry *ientry;
51340+ unsigned int len = strlen(name);
51341+ unsigned int key = full_name_hash(name, len);
51342+ unsigned int index = key % name_set.n_size;
51343+
51344+ curr = &name_set.n_hash[index];
51345+
51346+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51347+ curr = &((*curr)->next);
51348+
51349+ if (*curr != NULL)
51350+ return 1;
51351+
51352+ nentry = acl_alloc(sizeof (struct name_entry));
51353+ if (nentry == NULL)
51354+ return 0;
51355+ ientry = acl_alloc(sizeof (struct inodev_entry));
51356+ if (ientry == NULL)
51357+ return 0;
51358+ ientry->nentry = nentry;
51359+
51360+ nentry->key = key;
51361+ nentry->name = name;
51362+ nentry->inode = inode;
51363+ nentry->device = device;
51364+ nentry->len = len;
51365+ nentry->deleted = deleted;
51366+
51367+ nentry->prev = NULL;
51368+ curr = &name_set.n_hash[index];
51369+ if (*curr != NULL)
51370+ (*curr)->prev = nentry;
51371+ nentry->next = *curr;
51372+ *curr = nentry;
51373+
51374+ /* insert us into the table searchable by inode/dev */
51375+ insert_inodev_entry(ientry);
51376+
51377+ return 1;
51378+}
51379+
51380+static void
51381+insert_acl_obj_label(struct acl_object_label *obj,
51382+ struct acl_subject_label *subj)
51383+{
51384+ unsigned int index =
51385+ fhash(obj->inode, obj->device, subj->obj_hash_size);
51386+ struct acl_object_label **curr;
51387+
51388+
51389+ obj->prev = NULL;
51390+
51391+ curr = &subj->obj_hash[index];
51392+ if (*curr != NULL)
51393+ (*curr)->prev = obj;
51394+
51395+ obj->next = *curr;
51396+ *curr = obj;
51397+
51398+ return;
51399+}
51400+
51401+static void
51402+insert_acl_subj_label(struct acl_subject_label *obj,
51403+ struct acl_role_label *role)
51404+{
51405+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51406+ struct acl_subject_label **curr;
51407+
51408+ obj->prev = NULL;
51409+
51410+ curr = &role->subj_hash[index];
51411+ if (*curr != NULL)
51412+ (*curr)->prev = obj;
51413+
51414+ obj->next = *curr;
51415+ *curr = obj;
51416+
51417+ return;
51418+}
51419+
51420+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51421+
51422+static void *
51423+create_table(__u32 * len, int elementsize)
51424+{
51425+ unsigned int table_sizes[] = {
51426+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51427+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51428+ 4194301, 8388593, 16777213, 33554393, 67108859
51429+ };
51430+ void *newtable = NULL;
51431+ unsigned int pwr = 0;
51432+
51433+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51434+ table_sizes[pwr] <= *len)
51435+ pwr++;
51436+
51437+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51438+ return newtable;
51439+
51440+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51441+ newtable =
51442+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51443+ else
51444+ newtable = vmalloc(table_sizes[pwr] * elementsize);
51445+
51446+ *len = table_sizes[pwr];
51447+
51448+ return newtable;
51449+}
51450+
51451+static int
51452+init_variables(const struct gr_arg *arg)
51453+{
51454+ struct task_struct *reaper = init_pid_ns.child_reaper;
51455+ unsigned int stacksize;
51456+
51457+ subj_map_set.s_size = arg->role_db.num_subjects;
51458+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51459+ name_set.n_size = arg->role_db.num_objects;
51460+ inodev_set.i_size = arg->role_db.num_objects;
51461+
51462+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
51463+ !name_set.n_size || !inodev_set.i_size)
51464+ return 1;
51465+
51466+ if (!gr_init_uidset())
51467+ return 1;
51468+
51469+ /* set up the stack that holds allocation info */
51470+
51471+ stacksize = arg->role_db.num_pointers + 5;
51472+
51473+ if (!acl_alloc_stack_init(stacksize))
51474+ return 1;
51475+
51476+ /* grab reference for the real root dentry and vfsmount */
51477+ get_fs_root(reaper->fs, &real_root);
51478+
51479+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51480+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51481+#endif
51482+
51483+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51484+ if (fakefs_obj_rw == NULL)
51485+ return 1;
51486+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51487+
51488+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51489+ if (fakefs_obj_rwx == NULL)
51490+ return 1;
51491+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51492+
51493+ subj_map_set.s_hash =
51494+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51495+ acl_role_set.r_hash =
51496+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51497+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51498+ inodev_set.i_hash =
51499+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51500+
51501+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51502+ !name_set.n_hash || !inodev_set.i_hash)
51503+ return 1;
51504+
51505+ memset(subj_map_set.s_hash, 0,
51506+ sizeof(struct subject_map *) * subj_map_set.s_size);
51507+ memset(acl_role_set.r_hash, 0,
51508+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
51509+ memset(name_set.n_hash, 0,
51510+ sizeof (struct name_entry *) * name_set.n_size);
51511+ memset(inodev_set.i_hash, 0,
51512+ sizeof (struct inodev_entry *) * inodev_set.i_size);
51513+
51514+ return 0;
51515+}
51516+
51517+/* free information not needed after startup
51518+ currently contains user->kernel pointer mappings for subjects
51519+*/
51520+
51521+static void
51522+free_init_variables(void)
51523+{
51524+ __u32 i;
51525+
51526+ if (subj_map_set.s_hash) {
51527+ for (i = 0; i < subj_map_set.s_size; i++) {
51528+ if (subj_map_set.s_hash[i]) {
51529+ kfree(subj_map_set.s_hash[i]);
51530+ subj_map_set.s_hash[i] = NULL;
51531+ }
51532+ }
51533+
51534+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51535+ PAGE_SIZE)
51536+ kfree(subj_map_set.s_hash);
51537+ else
51538+ vfree(subj_map_set.s_hash);
51539+ }
51540+
51541+ return;
51542+}
51543+
51544+static void
51545+free_variables(void)
51546+{
51547+ struct acl_subject_label *s;
51548+ struct acl_role_label *r;
51549+ struct task_struct *task, *task2;
51550+ unsigned int x;
51551+
51552+ gr_clear_learn_entries();
51553+
51554+ read_lock(&tasklist_lock);
51555+ do_each_thread(task2, task) {
51556+ task->acl_sp_role = 0;
51557+ task->acl_role_id = 0;
51558+ task->acl = NULL;
51559+ task->role = NULL;
51560+ } while_each_thread(task2, task);
51561+ read_unlock(&tasklist_lock);
51562+
51563+ /* release the reference to the real root dentry and vfsmount */
51564+ path_put(&real_root);
51565+ memset(&real_root, 0, sizeof(real_root));
51566+
51567+ /* free all object hash tables */
51568+
51569+ FOR_EACH_ROLE_START(r)
51570+ if (r->subj_hash == NULL)
51571+ goto next_role;
51572+ FOR_EACH_SUBJECT_START(r, s, x)
51573+ if (s->obj_hash == NULL)
51574+ break;
51575+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51576+ kfree(s->obj_hash);
51577+ else
51578+ vfree(s->obj_hash);
51579+ FOR_EACH_SUBJECT_END(s, x)
51580+ FOR_EACH_NESTED_SUBJECT_START(r, s)
51581+ if (s->obj_hash == NULL)
51582+ break;
51583+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51584+ kfree(s->obj_hash);
51585+ else
51586+ vfree(s->obj_hash);
51587+ FOR_EACH_NESTED_SUBJECT_END(s)
51588+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51589+ kfree(r->subj_hash);
51590+ else
51591+ vfree(r->subj_hash);
51592+ r->subj_hash = NULL;
51593+next_role:
51594+ FOR_EACH_ROLE_END(r)
51595+
51596+ acl_free_all();
51597+
51598+ if (acl_role_set.r_hash) {
51599+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51600+ PAGE_SIZE)
51601+ kfree(acl_role_set.r_hash);
51602+ else
51603+ vfree(acl_role_set.r_hash);
51604+ }
51605+ if (name_set.n_hash) {
51606+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
51607+ PAGE_SIZE)
51608+ kfree(name_set.n_hash);
51609+ else
51610+ vfree(name_set.n_hash);
51611+ }
51612+
51613+ if (inodev_set.i_hash) {
51614+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51615+ PAGE_SIZE)
51616+ kfree(inodev_set.i_hash);
51617+ else
51618+ vfree(inodev_set.i_hash);
51619+ }
51620+
51621+ gr_free_uidset();
51622+
51623+ memset(&name_set, 0, sizeof (struct name_db));
51624+ memset(&inodev_set, 0, sizeof (struct inodev_db));
51625+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51626+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51627+
51628+ default_role = NULL;
51629+ kernel_role = NULL;
51630+ role_list = NULL;
51631+
51632+ return;
51633+}
51634+
51635+static __u32
51636+count_user_objs(struct acl_object_label *userp)
51637+{
51638+ struct acl_object_label o_tmp;
51639+ __u32 num = 0;
51640+
51641+ while (userp) {
51642+ if (copy_from_user(&o_tmp, userp,
51643+ sizeof (struct acl_object_label)))
51644+ break;
51645+
51646+ userp = o_tmp.prev;
51647+ num++;
51648+ }
51649+
51650+ return num;
51651+}
51652+
51653+static struct acl_subject_label *
51654+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51655+
51656+static int
51657+copy_user_glob(struct acl_object_label *obj)
51658+{
51659+ struct acl_object_label *g_tmp, **guser;
51660+ unsigned int len;
51661+ char *tmp;
51662+
51663+ if (obj->globbed == NULL)
51664+ return 0;
51665+
51666+ guser = &obj->globbed;
51667+ while (*guser) {
51668+ g_tmp = (struct acl_object_label *)
51669+ acl_alloc(sizeof (struct acl_object_label));
51670+ if (g_tmp == NULL)
51671+ return -ENOMEM;
51672+
51673+ if (copy_from_user(g_tmp, *guser,
51674+ sizeof (struct acl_object_label)))
51675+ return -EFAULT;
51676+
51677+ len = strnlen_user(g_tmp->filename, PATH_MAX);
51678+
51679+ if (!len || len >= PATH_MAX)
51680+ return -EINVAL;
51681+
51682+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51683+ return -ENOMEM;
51684+
51685+ if (copy_from_user(tmp, g_tmp->filename, len))
51686+ return -EFAULT;
51687+ tmp[len-1] = '\0';
51688+ g_tmp->filename = tmp;
51689+
51690+ *guser = g_tmp;
51691+ guser = &(g_tmp->next);
51692+ }
51693+
51694+ return 0;
51695+}
51696+
51697+static int
51698+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
51699+ struct acl_role_label *role)
51700+{
51701+ struct acl_object_label *o_tmp;
51702+ unsigned int len;
51703+ int ret;
51704+ char *tmp;
51705+
51706+ while (userp) {
51707+ if ((o_tmp = (struct acl_object_label *)
51708+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
51709+ return -ENOMEM;
51710+
51711+ if (copy_from_user(o_tmp, userp,
51712+ sizeof (struct acl_object_label)))
51713+ return -EFAULT;
51714+
51715+ userp = o_tmp->prev;
51716+
51717+ len = strnlen_user(o_tmp->filename, PATH_MAX);
51718+
51719+ if (!len || len >= PATH_MAX)
51720+ return -EINVAL;
51721+
51722+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51723+ return -ENOMEM;
51724+
51725+ if (copy_from_user(tmp, o_tmp->filename, len))
51726+ return -EFAULT;
51727+ tmp[len-1] = '\0';
51728+ o_tmp->filename = tmp;
51729+
51730+ insert_acl_obj_label(o_tmp, subj);
51731+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
51732+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
51733+ return -ENOMEM;
51734+
51735+ ret = copy_user_glob(o_tmp);
51736+ if (ret)
51737+ return ret;
51738+
51739+ if (o_tmp->nested) {
51740+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
51741+ if (IS_ERR(o_tmp->nested))
51742+ return PTR_ERR(o_tmp->nested);
51743+
51744+ /* insert into nested subject list */
51745+ o_tmp->nested->next = role->hash->first;
51746+ role->hash->first = o_tmp->nested;
51747+ }
51748+ }
51749+
51750+ return 0;
51751+}
51752+
51753+static __u32
51754+count_user_subjs(struct acl_subject_label *userp)
51755+{
51756+ struct acl_subject_label s_tmp;
51757+ __u32 num = 0;
51758+
51759+ while (userp) {
51760+ if (copy_from_user(&s_tmp, userp,
51761+ sizeof (struct acl_subject_label)))
51762+ break;
51763+
51764+ userp = s_tmp.prev;
51765+ /* do not count nested subjects against this count, since
51766+ they are not included in the hash table, but are
51767+ attached to objects. We have already counted
51768+ the subjects in userspace for the allocation
51769+ stack
51770+ */
51771+ if (!(s_tmp.mode & GR_NESTED))
51772+ num++;
51773+ }
51774+
51775+ return num;
51776+}
51777+
51778+static int
51779+copy_user_allowedips(struct acl_role_label *rolep)
51780+{
51781+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
51782+
51783+ ruserip = rolep->allowed_ips;
51784+
51785+ while (ruserip) {
51786+ rlast = rtmp;
51787+
51788+ if ((rtmp = (struct role_allowed_ip *)
51789+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
51790+ return -ENOMEM;
51791+
51792+ if (copy_from_user(rtmp, ruserip,
51793+ sizeof (struct role_allowed_ip)))
51794+ return -EFAULT;
51795+
51796+ ruserip = rtmp->prev;
51797+
51798+ if (!rlast) {
51799+ rtmp->prev = NULL;
51800+ rolep->allowed_ips = rtmp;
51801+ } else {
51802+ rlast->next = rtmp;
51803+ rtmp->prev = rlast;
51804+ }
51805+
51806+ if (!ruserip)
51807+ rtmp->next = NULL;
51808+ }
51809+
51810+ return 0;
51811+}
51812+
51813+static int
51814+copy_user_transitions(struct acl_role_label *rolep)
51815+{
51816+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
51817+
51818+ unsigned int len;
51819+ char *tmp;
51820+
51821+ rusertp = rolep->transitions;
51822+
51823+ while (rusertp) {
51824+ rlast = rtmp;
51825+
51826+ if ((rtmp = (struct role_transition *)
51827+ acl_alloc(sizeof (struct role_transition))) == NULL)
51828+ return -ENOMEM;
51829+
51830+ if (copy_from_user(rtmp, rusertp,
51831+ sizeof (struct role_transition)))
51832+ return -EFAULT;
51833+
51834+ rusertp = rtmp->prev;
51835+
51836+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
51837+
51838+ if (!len || len >= GR_SPROLE_LEN)
51839+ return -EINVAL;
51840+
51841+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51842+ return -ENOMEM;
51843+
51844+ if (copy_from_user(tmp, rtmp->rolename, len))
51845+ return -EFAULT;
51846+ tmp[len-1] = '\0';
51847+ rtmp->rolename = tmp;
51848+
51849+ if (!rlast) {
51850+ rtmp->prev = NULL;
51851+ rolep->transitions = rtmp;
51852+ } else {
51853+ rlast->next = rtmp;
51854+ rtmp->prev = rlast;
51855+ }
51856+
51857+ if (!rusertp)
51858+ rtmp->next = NULL;
51859+ }
51860+
51861+ return 0;
51862+}
51863+
51864+static struct acl_subject_label *
51865+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
51866+{
51867+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
51868+ unsigned int len;
51869+ char *tmp;
51870+ __u32 num_objs;
51871+ struct acl_ip_label **i_tmp, *i_utmp2;
51872+ struct gr_hash_struct ghash;
51873+ struct subject_map *subjmap;
51874+ unsigned int i_num;
51875+ int err;
51876+
51877+ s_tmp = lookup_subject_map(userp);
51878+
51879+ /* we've already copied this subject into the kernel, just return
51880+ the reference to it, and don't copy it over again
51881+ */
51882+ if (s_tmp)
51883+ return(s_tmp);
51884+
51885+ if ((s_tmp = (struct acl_subject_label *)
51886+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
51887+ return ERR_PTR(-ENOMEM);
51888+
51889+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
51890+ if (subjmap == NULL)
51891+ return ERR_PTR(-ENOMEM);
51892+
51893+ subjmap->user = userp;
51894+ subjmap->kernel = s_tmp;
51895+ insert_subj_map_entry(subjmap);
51896+
51897+ if (copy_from_user(s_tmp, userp,
51898+ sizeof (struct acl_subject_label)))
51899+ return ERR_PTR(-EFAULT);
51900+
51901+ len = strnlen_user(s_tmp->filename, PATH_MAX);
51902+
51903+ if (!len || len >= PATH_MAX)
51904+ return ERR_PTR(-EINVAL);
51905+
51906+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51907+ return ERR_PTR(-ENOMEM);
51908+
51909+ if (copy_from_user(tmp, s_tmp->filename, len))
51910+ return ERR_PTR(-EFAULT);
51911+ tmp[len-1] = '\0';
51912+ s_tmp->filename = tmp;
51913+
51914+ if (!strcmp(s_tmp->filename, "/"))
51915+ role->root_label = s_tmp;
51916+
51917+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
51918+ return ERR_PTR(-EFAULT);
51919+
51920+ /* copy user and group transition tables */
51921+
51922+ if (s_tmp->user_trans_num) {
51923+ uid_t *uidlist;
51924+
51925+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
51926+ if (uidlist == NULL)
51927+ return ERR_PTR(-ENOMEM);
51928+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
51929+ return ERR_PTR(-EFAULT);
51930+
51931+ s_tmp->user_transitions = uidlist;
51932+ }
51933+
51934+ if (s_tmp->group_trans_num) {
51935+ gid_t *gidlist;
51936+
51937+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
51938+ if (gidlist == NULL)
51939+ return ERR_PTR(-ENOMEM);
51940+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
51941+ return ERR_PTR(-EFAULT);
51942+
51943+ s_tmp->group_transitions = gidlist;
51944+ }
51945+
51946+ /* set up object hash table */
51947+ num_objs = count_user_objs(ghash.first);
51948+
51949+ s_tmp->obj_hash_size = num_objs;
51950+ s_tmp->obj_hash =
51951+ (struct acl_object_label **)
51952+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
51953+
51954+ if (!s_tmp->obj_hash)
51955+ return ERR_PTR(-ENOMEM);
51956+
51957+ memset(s_tmp->obj_hash, 0,
51958+ s_tmp->obj_hash_size *
51959+ sizeof (struct acl_object_label *));
51960+
51961+ /* add in objects */
51962+ err = copy_user_objs(ghash.first, s_tmp, role);
51963+
51964+ if (err)
51965+ return ERR_PTR(err);
51966+
51967+ /* set pointer for parent subject */
51968+ if (s_tmp->parent_subject) {
51969+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
51970+
51971+ if (IS_ERR(s_tmp2))
51972+ return s_tmp2;
51973+
51974+ s_tmp->parent_subject = s_tmp2;
51975+ }
51976+
51977+ /* add in ip acls */
51978+
51979+ if (!s_tmp->ip_num) {
51980+ s_tmp->ips = NULL;
51981+ goto insert;
51982+ }
51983+
51984+ i_tmp =
51985+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
51986+ sizeof (struct acl_ip_label *));
51987+
51988+ if (!i_tmp)
51989+ return ERR_PTR(-ENOMEM);
51990+
51991+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
51992+ *(i_tmp + i_num) =
51993+ (struct acl_ip_label *)
51994+ acl_alloc(sizeof (struct acl_ip_label));
51995+ if (!*(i_tmp + i_num))
51996+ return ERR_PTR(-ENOMEM);
51997+
51998+ if (copy_from_user
51999+ (&i_utmp2, s_tmp->ips + i_num,
52000+ sizeof (struct acl_ip_label *)))
52001+ return ERR_PTR(-EFAULT);
52002+
52003+ if (copy_from_user
52004+ (*(i_tmp + i_num), i_utmp2,
52005+ sizeof (struct acl_ip_label)))
52006+ return ERR_PTR(-EFAULT);
52007+
52008+ if ((*(i_tmp + i_num))->iface == NULL)
52009+ continue;
52010+
52011+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52012+ if (!len || len >= IFNAMSIZ)
52013+ return ERR_PTR(-EINVAL);
52014+ tmp = acl_alloc(len);
52015+ if (tmp == NULL)
52016+ return ERR_PTR(-ENOMEM);
52017+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52018+ return ERR_PTR(-EFAULT);
52019+ (*(i_tmp + i_num))->iface = tmp;
52020+ }
52021+
52022+ s_tmp->ips = i_tmp;
52023+
52024+insert:
52025+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52026+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52027+ return ERR_PTR(-ENOMEM);
52028+
52029+ return s_tmp;
52030+}
52031+
52032+static int
52033+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52034+{
52035+ struct acl_subject_label s_pre;
52036+ struct acl_subject_label * ret;
52037+ int err;
52038+
52039+ while (userp) {
52040+ if (copy_from_user(&s_pre, userp,
52041+ sizeof (struct acl_subject_label)))
52042+ return -EFAULT;
52043+
52044+ /* do not add nested subjects here, add
52045+ while parsing objects
52046+ */
52047+
52048+ if (s_pre.mode & GR_NESTED) {
52049+ userp = s_pre.prev;
52050+ continue;
52051+ }
52052+
52053+ ret = do_copy_user_subj(userp, role);
52054+
52055+ err = PTR_ERR(ret);
52056+ if (IS_ERR(ret))
52057+ return err;
52058+
52059+ insert_acl_subj_label(ret, role);
52060+
52061+ userp = s_pre.prev;
52062+ }
52063+
52064+ return 0;
52065+}
52066+
52067+static int
52068+copy_user_acl(struct gr_arg *arg)
52069+{
52070+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52071+ struct sprole_pw *sptmp;
52072+ struct gr_hash_struct *ghash;
52073+ uid_t *domainlist;
52074+ unsigned int r_num;
52075+ unsigned int len;
52076+ char *tmp;
52077+ int err = 0;
52078+ __u16 i;
52079+ __u32 num_subjs;
52080+
52081+ /* we need a default and kernel role */
52082+ if (arg->role_db.num_roles < 2)
52083+ return -EINVAL;
52084+
52085+ /* copy special role authentication info from userspace */
52086+
52087+ num_sprole_pws = arg->num_sprole_pws;
52088+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52089+
52090+ if (!acl_special_roles && num_sprole_pws)
52091+ return -ENOMEM;
52092+
52093+ for (i = 0; i < num_sprole_pws; i++) {
52094+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52095+ if (!sptmp)
52096+ return -ENOMEM;
52097+ if (copy_from_user(sptmp, arg->sprole_pws + i,
52098+ sizeof (struct sprole_pw)))
52099+ return -EFAULT;
52100+
52101+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52102+
52103+ if (!len || len >= GR_SPROLE_LEN)
52104+ return -EINVAL;
52105+
52106+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52107+ return -ENOMEM;
52108+
52109+ if (copy_from_user(tmp, sptmp->rolename, len))
52110+ return -EFAULT;
52111+
52112+ tmp[len-1] = '\0';
52113+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52114+ printk(KERN_ALERT "Copying special role %s\n", tmp);
52115+#endif
52116+ sptmp->rolename = tmp;
52117+ acl_special_roles[i] = sptmp;
52118+ }
52119+
52120+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52121+
52122+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52123+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
52124+
52125+ if (!r_tmp)
52126+ return -ENOMEM;
52127+
52128+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
52129+ sizeof (struct acl_role_label *)))
52130+ return -EFAULT;
52131+
52132+ if (copy_from_user(r_tmp, r_utmp2,
52133+ sizeof (struct acl_role_label)))
52134+ return -EFAULT;
52135+
52136+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52137+
52138+ if (!len || len >= PATH_MAX)
52139+ return -EINVAL;
52140+
52141+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52142+ return -ENOMEM;
52143+
52144+ if (copy_from_user(tmp, r_tmp->rolename, len))
52145+ return -EFAULT;
52146+
52147+ tmp[len-1] = '\0';
52148+ r_tmp->rolename = tmp;
52149+
52150+ if (!strcmp(r_tmp->rolename, "default")
52151+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52152+ default_role = r_tmp;
52153+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52154+ kernel_role = r_tmp;
52155+ }
52156+
52157+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52158+ return -ENOMEM;
52159+
52160+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52161+ return -EFAULT;
52162+
52163+ r_tmp->hash = ghash;
52164+
52165+ num_subjs = count_user_subjs(r_tmp->hash->first);
52166+
52167+ r_tmp->subj_hash_size = num_subjs;
52168+ r_tmp->subj_hash =
52169+ (struct acl_subject_label **)
52170+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52171+
52172+ if (!r_tmp->subj_hash)
52173+ return -ENOMEM;
52174+
52175+ err = copy_user_allowedips(r_tmp);
52176+ if (err)
52177+ return err;
52178+
52179+ /* copy domain info */
52180+ if (r_tmp->domain_children != NULL) {
52181+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52182+ if (domainlist == NULL)
52183+ return -ENOMEM;
52184+
52185+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52186+ return -EFAULT;
52187+
52188+ r_tmp->domain_children = domainlist;
52189+ }
52190+
52191+ err = copy_user_transitions(r_tmp);
52192+ if (err)
52193+ return err;
52194+
52195+ memset(r_tmp->subj_hash, 0,
52196+ r_tmp->subj_hash_size *
52197+ sizeof (struct acl_subject_label *));
52198+
52199+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52200+
52201+ if (err)
52202+ return err;
52203+
52204+ /* set nested subject list to null */
52205+ r_tmp->hash->first = NULL;
52206+
52207+ insert_acl_role_label(r_tmp);
52208+ }
52209+
52210+ if (default_role == NULL || kernel_role == NULL)
52211+ return -EINVAL;
52212+
52213+ return err;
52214+}
52215+
52216+static int
52217+gracl_init(struct gr_arg *args)
52218+{
52219+ int error = 0;
52220+
52221+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52222+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52223+
52224+ if (init_variables(args)) {
52225+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52226+ error = -ENOMEM;
52227+ free_variables();
52228+ goto out;
52229+ }
52230+
52231+ error = copy_user_acl(args);
52232+ free_init_variables();
52233+ if (error) {
52234+ free_variables();
52235+ goto out;
52236+ }
52237+
52238+ if ((error = gr_set_acls(0))) {
52239+ free_variables();
52240+ goto out;
52241+ }
52242+
52243+ pax_open_kernel();
52244+ gr_status |= GR_READY;
52245+ pax_close_kernel();
52246+
52247+ out:
52248+ return error;
52249+}
52250+
52251+/* derived from glibc fnmatch() 0: match, 1: no match*/
52252+
52253+static int
52254+glob_match(const char *p, const char *n)
52255+{
52256+ char c;
52257+
52258+ while ((c = *p++) != '\0') {
52259+ switch (c) {
52260+ case '?':
52261+ if (*n == '\0')
52262+ return 1;
52263+ else if (*n == '/')
52264+ return 1;
52265+ break;
52266+ case '\\':
52267+ if (*n != c)
52268+ return 1;
52269+ break;
52270+ case '*':
52271+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
52272+ if (*n == '/')
52273+ return 1;
52274+ else if (c == '?') {
52275+ if (*n == '\0')
52276+ return 1;
52277+ else
52278+ ++n;
52279+ }
52280+ }
52281+ if (c == '\0') {
52282+ return 0;
52283+ } else {
52284+ const char *endp;
52285+
52286+ if ((endp = strchr(n, '/')) == NULL)
52287+ endp = n + strlen(n);
52288+
52289+ if (c == '[') {
52290+ for (--p; n < endp; ++n)
52291+ if (!glob_match(p, n))
52292+ return 0;
52293+ } else if (c == '/') {
52294+ while (*n != '\0' && *n != '/')
52295+ ++n;
52296+ if (*n == '/' && !glob_match(p, n + 1))
52297+ return 0;
52298+ } else {
52299+ for (--p; n < endp; ++n)
52300+ if (*n == c && !glob_match(p, n))
52301+ return 0;
52302+ }
52303+
52304+ return 1;
52305+ }
52306+ case '[':
52307+ {
52308+ int not;
52309+ char cold;
52310+
52311+ if (*n == '\0' || *n == '/')
52312+ return 1;
52313+
52314+ not = (*p == '!' || *p == '^');
52315+ if (not)
52316+ ++p;
52317+
52318+ c = *p++;
52319+ for (;;) {
52320+ unsigned char fn = (unsigned char)*n;
52321+
52322+ if (c == '\0')
52323+ return 1;
52324+ else {
52325+ if (c == fn)
52326+ goto matched;
52327+ cold = c;
52328+ c = *p++;
52329+
52330+ if (c == '-' && *p != ']') {
52331+ unsigned char cend = *p++;
52332+
52333+ if (cend == '\0')
52334+ return 1;
52335+
52336+ if (cold <= fn && fn <= cend)
52337+ goto matched;
52338+
52339+ c = *p++;
52340+ }
52341+ }
52342+
52343+ if (c == ']')
52344+ break;
52345+ }
52346+ if (!not)
52347+ return 1;
52348+ break;
52349+ matched:
52350+ while (c != ']') {
52351+ if (c == '\0')
52352+ return 1;
52353+
52354+ c = *p++;
52355+ }
52356+ if (not)
52357+ return 1;
52358+ }
52359+ break;
52360+ default:
52361+ if (c != *n)
52362+ return 1;
52363+ }
52364+
52365+ ++n;
52366+ }
52367+
52368+ if (*n == '\0')
52369+ return 0;
52370+
52371+ if (*n == '/')
52372+ return 0;
52373+
52374+ return 1;
52375+}
52376+
52377+static struct acl_object_label *
52378+chk_glob_label(struct acl_object_label *globbed,
52379+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52380+{
52381+ struct acl_object_label *tmp;
52382+
52383+ if (*path == NULL)
52384+ *path = gr_to_filename_nolock(dentry, mnt);
52385+
52386+ tmp = globbed;
52387+
52388+ while (tmp) {
52389+ if (!glob_match(tmp->filename, *path))
52390+ return tmp;
52391+ tmp = tmp->next;
52392+ }
52393+
52394+ return NULL;
52395+}
52396+
52397+static struct acl_object_label *
52398+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52399+ const ino_t curr_ino, const dev_t curr_dev,
52400+ const struct acl_subject_label *subj, char **path, const int checkglob)
52401+{
52402+ struct acl_subject_label *tmpsubj;
52403+ struct acl_object_label *retval;
52404+ struct acl_object_label *retval2;
52405+
52406+ tmpsubj = (struct acl_subject_label *) subj;
52407+ read_lock(&gr_inode_lock);
52408+ do {
52409+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52410+ if (retval) {
52411+ if (checkglob && retval->globbed) {
52412+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52413+ if (retval2)
52414+ retval = retval2;
52415+ }
52416+ break;
52417+ }
52418+ } while ((tmpsubj = tmpsubj->parent_subject));
52419+ read_unlock(&gr_inode_lock);
52420+
52421+ return retval;
52422+}
52423+
52424+static __inline__ struct acl_object_label *
52425+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52426+ struct dentry *curr_dentry,
52427+ const struct acl_subject_label *subj, char **path, const int checkglob)
52428+{
52429+ int newglob = checkglob;
52430+ ino_t inode;
52431+ dev_t device;
52432+
52433+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52434+ as we don't want a / * rule to match instead of the / object
52435+ don't do this for create lookups that call this function though, since they're looking up
52436+ on the parent and thus need globbing checks on all paths
52437+ */
52438+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52439+ newglob = GR_NO_GLOB;
52440+
52441+ spin_lock(&curr_dentry->d_lock);
52442+ inode = curr_dentry->d_inode->i_ino;
52443+ device = __get_dev(curr_dentry);
52444+ spin_unlock(&curr_dentry->d_lock);
52445+
52446+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52447+}
52448+
52449+static struct acl_object_label *
52450+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52451+ const struct acl_subject_label *subj, char *path, const int checkglob)
52452+{
52453+ struct dentry *dentry = (struct dentry *) l_dentry;
52454+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52455+ struct mount *real_mnt = real_mount(mnt);
52456+ struct acl_object_label *retval;
52457+ struct dentry *parent;
52458+
52459+ write_seqlock(&rename_lock);
52460+ br_read_lock(vfsmount_lock);
52461+
52462+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52463+#ifdef CONFIG_NET
52464+ mnt == sock_mnt ||
52465+#endif
52466+#ifdef CONFIG_HUGETLBFS
52467+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52468+#endif
52469+ /* ignore Eric Biederman */
52470+ IS_PRIVATE(l_dentry->d_inode))) {
52471+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52472+ goto out;
52473+ }
52474+
52475+ for (;;) {
52476+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52477+ break;
52478+
52479+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52480+ if (!mnt_has_parent(real_mnt))
52481+ break;
52482+
52483+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52484+ if (retval != NULL)
52485+ goto out;
52486+
52487+ dentry = real_mnt->mnt_mountpoint;
52488+ real_mnt = real_mnt->mnt_parent;
52489+ mnt = &real_mnt->mnt;
52490+ continue;
52491+ }
52492+
52493+ parent = dentry->d_parent;
52494+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52495+ if (retval != NULL)
52496+ goto out;
52497+
52498+ dentry = parent;
52499+ }
52500+
52501+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52502+
52503+ /* real_root is pinned so we don't have to hold a reference */
52504+ if (retval == NULL)
52505+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52506+out:
52507+ br_read_unlock(vfsmount_lock);
52508+ write_sequnlock(&rename_lock);
52509+
52510+ BUG_ON(retval == NULL);
52511+
52512+ return retval;
52513+}
52514+
52515+static __inline__ struct acl_object_label *
52516+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52517+ const struct acl_subject_label *subj)
52518+{
52519+ char *path = NULL;
52520+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52521+}
52522+
52523+static __inline__ struct acl_object_label *
52524+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52525+ const struct acl_subject_label *subj)
52526+{
52527+ char *path = NULL;
52528+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52529+}
52530+
52531+static __inline__ struct acl_object_label *
52532+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52533+ const struct acl_subject_label *subj, char *path)
52534+{
52535+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52536+}
52537+
52538+static struct acl_subject_label *
52539+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52540+ const struct acl_role_label *role)
52541+{
52542+ struct dentry *dentry = (struct dentry *) l_dentry;
52543+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52544+ struct mount *real_mnt = real_mount(mnt);
52545+ struct acl_subject_label *retval;
52546+ struct dentry *parent;
52547+
52548+ write_seqlock(&rename_lock);
52549+ br_read_lock(vfsmount_lock);
52550+
52551+ for (;;) {
52552+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52553+ break;
52554+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52555+ if (!mnt_has_parent(real_mnt))
52556+ break;
52557+
52558+ spin_lock(&dentry->d_lock);
52559+ read_lock(&gr_inode_lock);
52560+ retval =
52561+ lookup_acl_subj_label(dentry->d_inode->i_ino,
52562+ __get_dev(dentry), role);
52563+ read_unlock(&gr_inode_lock);
52564+ spin_unlock(&dentry->d_lock);
52565+ if (retval != NULL)
52566+ goto out;
52567+
52568+ dentry = real_mnt->mnt_mountpoint;
52569+ real_mnt = real_mnt->mnt_parent;
52570+ mnt = &real_mnt->mnt;
52571+ continue;
52572+ }
52573+
52574+ spin_lock(&dentry->d_lock);
52575+ read_lock(&gr_inode_lock);
52576+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52577+ __get_dev(dentry), role);
52578+ read_unlock(&gr_inode_lock);
52579+ parent = dentry->d_parent;
52580+ spin_unlock(&dentry->d_lock);
52581+
52582+ if (retval != NULL)
52583+ goto out;
52584+
52585+ dentry = parent;
52586+ }
52587+
52588+ spin_lock(&dentry->d_lock);
52589+ read_lock(&gr_inode_lock);
52590+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52591+ __get_dev(dentry), role);
52592+ read_unlock(&gr_inode_lock);
52593+ spin_unlock(&dentry->d_lock);
52594+
52595+ if (unlikely(retval == NULL)) {
52596+ /* real_root is pinned, we don't need to hold a reference */
52597+ read_lock(&gr_inode_lock);
52598+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52599+ __get_dev(real_root.dentry), role);
52600+ read_unlock(&gr_inode_lock);
52601+ }
52602+out:
52603+ br_read_unlock(vfsmount_lock);
52604+ write_sequnlock(&rename_lock);
52605+
52606+ BUG_ON(retval == NULL);
52607+
52608+ return retval;
52609+}
52610+
52611+static void
52612+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52613+{
52614+ struct task_struct *task = current;
52615+ const struct cred *cred = current_cred();
52616+
52617+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52618+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52619+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52620+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52621+
52622+ return;
52623+}
52624+
52625+static void
52626+gr_log_learn_id_change(const char type, const unsigned int real,
52627+ const unsigned int effective, const unsigned int fs)
52628+{
52629+ struct task_struct *task = current;
52630+ const struct cred *cred = current_cred();
52631+
52632+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52633+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52634+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52635+ type, real, effective, fs, &task->signal->saved_ip);
52636+
52637+ return;
52638+}
52639+
52640+__u32
52641+gr_search_file(const struct dentry * dentry, const __u32 mode,
52642+ const struct vfsmount * mnt)
52643+{
52644+ __u32 retval = mode;
52645+ struct acl_subject_label *curracl;
52646+ struct acl_object_label *currobj;
52647+
52648+ if (unlikely(!(gr_status & GR_READY)))
52649+ return (mode & ~GR_AUDITS);
52650+
52651+ curracl = current->acl;
52652+
52653+ currobj = chk_obj_label(dentry, mnt, curracl);
52654+ retval = currobj->mode & mode;
52655+
52656+ /* if we're opening a specified transfer file for writing
52657+ (e.g. /dev/initctl), then transfer our role to init
52658+ */
52659+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
52660+ current->role->roletype & GR_ROLE_PERSIST)) {
52661+ struct task_struct *task = init_pid_ns.child_reaper;
52662+
52663+ if (task->role != current->role) {
52664+ task->acl_sp_role = 0;
52665+ task->acl_role_id = current->acl_role_id;
52666+ task->role = current->role;
52667+ rcu_read_lock();
52668+ read_lock(&grsec_exec_file_lock);
52669+ gr_apply_subject_to_task(task);
52670+ read_unlock(&grsec_exec_file_lock);
52671+ rcu_read_unlock();
52672+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
52673+ }
52674+ }
52675+
52676+ if (unlikely
52677+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
52678+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
52679+ __u32 new_mode = mode;
52680+
52681+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52682+
52683+ retval = new_mode;
52684+
52685+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
52686+ new_mode |= GR_INHERIT;
52687+
52688+ if (!(mode & GR_NOLEARN))
52689+ gr_log_learn(dentry, mnt, new_mode);
52690+ }
52691+
52692+ return retval;
52693+}
52694+
52695+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
52696+ const struct dentry *parent,
52697+ const struct vfsmount *mnt)
52698+{
52699+ struct name_entry *match;
52700+ struct acl_object_label *matchpo;
52701+ struct acl_subject_label *curracl;
52702+ char *path;
52703+
52704+ if (unlikely(!(gr_status & GR_READY)))
52705+ return NULL;
52706+
52707+ preempt_disable();
52708+ path = gr_to_filename_rbac(new_dentry, mnt);
52709+ match = lookup_name_entry_create(path);
52710+
52711+ curracl = current->acl;
52712+
52713+ if (match) {
52714+ read_lock(&gr_inode_lock);
52715+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
52716+ read_unlock(&gr_inode_lock);
52717+
52718+ if (matchpo) {
52719+ preempt_enable();
52720+ return matchpo;
52721+ }
52722+ }
52723+
52724+ // lookup parent
52725+
52726+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
52727+
52728+ preempt_enable();
52729+ return matchpo;
52730+}
52731+
52732+__u32
52733+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
52734+ const struct vfsmount * mnt, const __u32 mode)
52735+{
52736+ struct acl_object_label *matchpo;
52737+ __u32 retval;
52738+
52739+ if (unlikely(!(gr_status & GR_READY)))
52740+ return (mode & ~GR_AUDITS);
52741+
52742+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
52743+
52744+ retval = matchpo->mode & mode;
52745+
52746+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
52747+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52748+ __u32 new_mode = mode;
52749+
52750+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52751+
52752+ gr_log_learn(new_dentry, mnt, new_mode);
52753+ return new_mode;
52754+ }
52755+
52756+ return retval;
52757+}
52758+
52759+__u32
52760+gr_check_link(const struct dentry * new_dentry,
52761+ const struct dentry * parent_dentry,
52762+ const struct vfsmount * parent_mnt,
52763+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
52764+{
52765+ struct acl_object_label *obj;
52766+ __u32 oldmode, newmode;
52767+ __u32 needmode;
52768+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
52769+ GR_DELETE | GR_INHERIT;
52770+
52771+ if (unlikely(!(gr_status & GR_READY)))
52772+ return (GR_CREATE | GR_LINK);
52773+
52774+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
52775+ oldmode = obj->mode;
52776+
52777+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
52778+ newmode = obj->mode;
52779+
52780+ needmode = newmode & checkmodes;
52781+
52782+ // old name for hardlink must have at least the permissions of the new name
52783+ if ((oldmode & needmode) != needmode)
52784+ goto bad;
52785+
52786+ // if old name had restrictions/auditing, make sure the new name does as well
52787+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
52788+
52789+ // don't allow hardlinking of suid/sgid files without permission
52790+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52791+ needmode |= GR_SETID;
52792+
52793+ if ((newmode & needmode) != needmode)
52794+ goto bad;
52795+
52796+ // enforce minimum permissions
52797+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
52798+ return newmode;
52799+bad:
52800+ needmode = oldmode;
52801+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52802+ needmode |= GR_SETID;
52803+
52804+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
52805+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
52806+ return (GR_CREATE | GR_LINK);
52807+ } else if (newmode & GR_SUPPRESS)
52808+ return GR_SUPPRESS;
52809+ else
52810+ return 0;
52811+}
52812+
52813+int
52814+gr_check_hidden_task(const struct task_struct *task)
52815+{
52816+ if (unlikely(!(gr_status & GR_READY)))
52817+ return 0;
52818+
52819+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
52820+ return 1;
52821+
52822+ return 0;
52823+}
52824+
52825+int
52826+gr_check_protected_task(const struct task_struct *task)
52827+{
52828+ if (unlikely(!(gr_status & GR_READY) || !task))
52829+ return 0;
52830+
52831+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52832+ task->acl != current->acl)
52833+ return 1;
52834+
52835+ return 0;
52836+}
52837+
52838+int
52839+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
52840+{
52841+ struct task_struct *p;
52842+ int ret = 0;
52843+
52844+ if (unlikely(!(gr_status & GR_READY) || !pid))
52845+ return ret;
52846+
52847+ read_lock(&tasklist_lock);
52848+ do_each_pid_task(pid, type, p) {
52849+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52850+ p->acl != current->acl) {
52851+ ret = 1;
52852+ goto out;
52853+ }
52854+ } while_each_pid_task(pid, type, p);
52855+out:
52856+ read_unlock(&tasklist_lock);
52857+
52858+ return ret;
52859+}
52860+
52861+void
52862+gr_copy_label(struct task_struct *tsk)
52863+{
52864+ tsk->signal->used_accept = 0;
52865+ tsk->acl_sp_role = 0;
52866+ tsk->acl_role_id = current->acl_role_id;
52867+ tsk->acl = current->acl;
52868+ tsk->role = current->role;
52869+ tsk->signal->curr_ip = current->signal->curr_ip;
52870+ tsk->signal->saved_ip = current->signal->saved_ip;
52871+ if (current->exec_file)
52872+ get_file(current->exec_file);
52873+ tsk->exec_file = current->exec_file;
52874+ tsk->is_writable = current->is_writable;
52875+ if (unlikely(current->signal->used_accept)) {
52876+ current->signal->curr_ip = 0;
52877+ current->signal->saved_ip = 0;
52878+ }
52879+
52880+ return;
52881+}
52882+
52883+static void
52884+gr_set_proc_res(struct task_struct *task)
52885+{
52886+ struct acl_subject_label *proc;
52887+ unsigned short i;
52888+
52889+ proc = task->acl;
52890+
52891+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
52892+ return;
52893+
52894+ for (i = 0; i < RLIM_NLIMITS; i++) {
52895+ if (!(proc->resmask & (1 << i)))
52896+ continue;
52897+
52898+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
52899+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
52900+ }
52901+
52902+ return;
52903+}
52904+
52905+extern int __gr_process_user_ban(struct user_struct *user);
52906+
52907+int
52908+gr_check_user_change(int real, int effective, int fs)
52909+{
52910+ unsigned int i;
52911+ __u16 num;
52912+ uid_t *uidlist;
52913+ int curuid;
52914+ int realok = 0;
52915+ int effectiveok = 0;
52916+ int fsok = 0;
52917+
52918+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
52919+ struct user_struct *user;
52920+
52921+ if (real == -1)
52922+ goto skipit;
52923+
52924+ user = find_user(real);
52925+ if (user == NULL)
52926+ goto skipit;
52927+
52928+ if (__gr_process_user_ban(user)) {
52929+ /* for find_user */
52930+ free_uid(user);
52931+ return 1;
52932+ }
52933+
52934+ /* for find_user */
52935+ free_uid(user);
52936+
52937+skipit:
52938+#endif
52939+
52940+ if (unlikely(!(gr_status & GR_READY)))
52941+ return 0;
52942+
52943+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52944+ gr_log_learn_id_change('u', real, effective, fs);
52945+
52946+ num = current->acl->user_trans_num;
52947+ uidlist = current->acl->user_transitions;
52948+
52949+ if (uidlist == NULL)
52950+ return 0;
52951+
52952+ if (real == -1)
52953+ realok = 1;
52954+ if (effective == -1)
52955+ effectiveok = 1;
52956+ if (fs == -1)
52957+ fsok = 1;
52958+
52959+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
52960+ for (i = 0; i < num; i++) {
52961+ curuid = (int)uidlist[i];
52962+ if (real == curuid)
52963+ realok = 1;
52964+ if (effective == curuid)
52965+ effectiveok = 1;
52966+ if (fs == curuid)
52967+ fsok = 1;
52968+ }
52969+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
52970+ for (i = 0; i < num; i++) {
52971+ curuid = (int)uidlist[i];
52972+ if (real == curuid)
52973+ break;
52974+ if (effective == curuid)
52975+ break;
52976+ if (fs == curuid)
52977+ break;
52978+ }
52979+ /* not in deny list */
52980+ if (i == num) {
52981+ realok = 1;
52982+ effectiveok = 1;
52983+ fsok = 1;
52984+ }
52985+ }
52986+
52987+ if (realok && effectiveok && fsok)
52988+ return 0;
52989+ else {
52990+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52991+ return 1;
52992+ }
52993+}
52994+
52995+int
52996+gr_check_group_change(int real, int effective, int fs)
52997+{
52998+ unsigned int i;
52999+ __u16 num;
53000+ gid_t *gidlist;
53001+ int curgid;
53002+ int realok = 0;
53003+ int effectiveok = 0;
53004+ int fsok = 0;
53005+
53006+ if (unlikely(!(gr_status & GR_READY)))
53007+ return 0;
53008+
53009+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53010+ gr_log_learn_id_change('g', real, effective, fs);
53011+
53012+ num = current->acl->group_trans_num;
53013+ gidlist = current->acl->group_transitions;
53014+
53015+ if (gidlist == NULL)
53016+ return 0;
53017+
53018+ if (real == -1)
53019+ realok = 1;
53020+ if (effective == -1)
53021+ effectiveok = 1;
53022+ if (fs == -1)
53023+ fsok = 1;
53024+
53025+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
53026+ for (i = 0; i < num; i++) {
53027+ curgid = (int)gidlist[i];
53028+ if (real == curgid)
53029+ realok = 1;
53030+ if (effective == curgid)
53031+ effectiveok = 1;
53032+ if (fs == curgid)
53033+ fsok = 1;
53034+ }
53035+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
53036+ for (i = 0; i < num; i++) {
53037+ curgid = (int)gidlist[i];
53038+ if (real == curgid)
53039+ break;
53040+ if (effective == curgid)
53041+ break;
53042+ if (fs == curgid)
53043+ break;
53044+ }
53045+ /* not in deny list */
53046+ if (i == num) {
53047+ realok = 1;
53048+ effectiveok = 1;
53049+ fsok = 1;
53050+ }
53051+ }
53052+
53053+ if (realok && effectiveok && fsok)
53054+ return 0;
53055+ else {
53056+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53057+ return 1;
53058+ }
53059+}
53060+
53061+extern int gr_acl_is_capable(const int cap);
53062+
53063+void
53064+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53065+{
53066+ struct acl_role_label *role = task->role;
53067+ struct acl_subject_label *subj = NULL;
53068+ struct acl_object_label *obj;
53069+ struct file *filp;
53070+
53071+ if (unlikely(!(gr_status & GR_READY)))
53072+ return;
53073+
53074+ filp = task->exec_file;
53075+
53076+ /* kernel process, we'll give them the kernel role */
53077+ if (unlikely(!filp)) {
53078+ task->role = kernel_role;
53079+ task->acl = kernel_role->root_label;
53080+ return;
53081+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53082+ role = lookup_acl_role_label(task, uid, gid);
53083+
53084+ /* don't change the role if we're not a privileged process */
53085+ if (role && task->role != role &&
53086+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53087+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53088+ return;
53089+
53090+ /* perform subject lookup in possibly new role
53091+ we can use this result below in the case where role == task->role
53092+ */
53093+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53094+
53095+ /* if we changed uid/gid, but result in the same role
53096+ and are using inheritance, don't lose the inherited subject
53097+ if current subject is other than what normal lookup
53098+ would result in, we arrived via inheritance, don't
53099+ lose subject
53100+ */
53101+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53102+ (subj == task->acl)))
53103+ task->acl = subj;
53104+
53105+ task->role = role;
53106+
53107+ task->is_writable = 0;
53108+
53109+ /* ignore additional mmap checks for processes that are writable
53110+ by the default ACL */
53111+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53112+ if (unlikely(obj->mode & GR_WRITE))
53113+ task->is_writable = 1;
53114+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53115+ if (unlikely(obj->mode & GR_WRITE))
53116+ task->is_writable = 1;
53117+
53118+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53119+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53120+#endif
53121+
53122+ gr_set_proc_res(task);
53123+
53124+ return;
53125+}
53126+
53127+int
53128+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53129+ const int unsafe_flags)
53130+{
53131+ struct task_struct *task = current;
53132+ struct acl_subject_label *newacl;
53133+ struct acl_object_label *obj;
53134+ __u32 retmode;
53135+
53136+ if (unlikely(!(gr_status & GR_READY)))
53137+ return 0;
53138+
53139+ newacl = chk_subj_label(dentry, mnt, task->role);
53140+
53141+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53142+ did an exec
53143+ */
53144+ rcu_read_lock();
53145+ read_lock(&tasklist_lock);
53146+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53147+ (task->parent->acl->mode & GR_POVERRIDE))) {
53148+ read_unlock(&tasklist_lock);
53149+ rcu_read_unlock();
53150+ goto skip_check;
53151+ }
53152+ read_unlock(&tasklist_lock);
53153+ rcu_read_unlock();
53154+
53155+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53156+ !(task->role->roletype & GR_ROLE_GOD) &&
53157+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53158+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53159+ if (unsafe_flags & LSM_UNSAFE_SHARE)
53160+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53161+ else
53162+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53163+ return -EACCES;
53164+ }
53165+
53166+skip_check:
53167+
53168+ obj = chk_obj_label(dentry, mnt, task->acl);
53169+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53170+
53171+ if (!(task->acl->mode & GR_INHERITLEARN) &&
53172+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53173+ if (obj->nested)
53174+ task->acl = obj->nested;
53175+ else
53176+ task->acl = newacl;
53177+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53178+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53179+
53180+ task->is_writable = 0;
53181+
53182+ /* ignore additional mmap checks for processes that are writable
53183+ by the default ACL */
53184+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
53185+ if (unlikely(obj->mode & GR_WRITE))
53186+ task->is_writable = 1;
53187+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
53188+ if (unlikely(obj->mode & GR_WRITE))
53189+ task->is_writable = 1;
53190+
53191+ gr_set_proc_res(task);
53192+
53193+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53194+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53195+#endif
53196+ return 0;
53197+}
53198+
53199+/* always called with valid inodev ptr */
53200+static void
53201+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53202+{
53203+ struct acl_object_label *matchpo;
53204+ struct acl_subject_label *matchps;
53205+ struct acl_subject_label *subj;
53206+ struct acl_role_label *role;
53207+ unsigned int x;
53208+
53209+ FOR_EACH_ROLE_START(role)
53210+ FOR_EACH_SUBJECT_START(role, subj, x)
53211+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53212+ matchpo->mode |= GR_DELETED;
53213+ FOR_EACH_SUBJECT_END(subj,x)
53214+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53215+ if (subj->inode == ino && subj->device == dev)
53216+ subj->mode |= GR_DELETED;
53217+ FOR_EACH_NESTED_SUBJECT_END(subj)
53218+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53219+ matchps->mode |= GR_DELETED;
53220+ FOR_EACH_ROLE_END(role)
53221+
53222+ inodev->nentry->deleted = 1;
53223+
53224+ return;
53225+}
53226+
53227+void
53228+gr_handle_delete(const ino_t ino, const dev_t dev)
53229+{
53230+ struct inodev_entry *inodev;
53231+
53232+ if (unlikely(!(gr_status & GR_READY)))
53233+ return;
53234+
53235+ write_lock(&gr_inode_lock);
53236+ inodev = lookup_inodev_entry(ino, dev);
53237+ if (inodev != NULL)
53238+ do_handle_delete(inodev, ino, dev);
53239+ write_unlock(&gr_inode_lock);
53240+
53241+ return;
53242+}
53243+
53244+static void
53245+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53246+ const ino_t newinode, const dev_t newdevice,
53247+ struct acl_subject_label *subj)
53248+{
53249+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53250+ struct acl_object_label *match;
53251+
53252+ match = subj->obj_hash[index];
53253+
53254+ while (match && (match->inode != oldinode ||
53255+ match->device != olddevice ||
53256+ !(match->mode & GR_DELETED)))
53257+ match = match->next;
53258+
53259+ if (match && (match->inode == oldinode)
53260+ && (match->device == olddevice)
53261+ && (match->mode & GR_DELETED)) {
53262+ if (match->prev == NULL) {
53263+ subj->obj_hash[index] = match->next;
53264+ if (match->next != NULL)
53265+ match->next->prev = NULL;
53266+ } else {
53267+ match->prev->next = match->next;
53268+ if (match->next != NULL)
53269+ match->next->prev = match->prev;
53270+ }
53271+ match->prev = NULL;
53272+ match->next = NULL;
53273+ match->inode = newinode;
53274+ match->device = newdevice;
53275+ match->mode &= ~GR_DELETED;
53276+
53277+ insert_acl_obj_label(match, subj);
53278+ }
53279+
53280+ return;
53281+}
53282+
53283+static void
53284+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53285+ const ino_t newinode, const dev_t newdevice,
53286+ struct acl_role_label *role)
53287+{
53288+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53289+ struct acl_subject_label *match;
53290+
53291+ match = role->subj_hash[index];
53292+
53293+ while (match && (match->inode != oldinode ||
53294+ match->device != olddevice ||
53295+ !(match->mode & GR_DELETED)))
53296+ match = match->next;
53297+
53298+ if (match && (match->inode == oldinode)
53299+ && (match->device == olddevice)
53300+ && (match->mode & GR_DELETED)) {
53301+ if (match->prev == NULL) {
53302+ role->subj_hash[index] = match->next;
53303+ if (match->next != NULL)
53304+ match->next->prev = NULL;
53305+ } else {
53306+ match->prev->next = match->next;
53307+ if (match->next != NULL)
53308+ match->next->prev = match->prev;
53309+ }
53310+ match->prev = NULL;
53311+ match->next = NULL;
53312+ match->inode = newinode;
53313+ match->device = newdevice;
53314+ match->mode &= ~GR_DELETED;
53315+
53316+ insert_acl_subj_label(match, role);
53317+ }
53318+
53319+ return;
53320+}
53321+
53322+static void
53323+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53324+ const ino_t newinode, const dev_t newdevice)
53325+{
53326+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53327+ struct inodev_entry *match;
53328+
53329+ match = inodev_set.i_hash[index];
53330+
53331+ while (match && (match->nentry->inode != oldinode ||
53332+ match->nentry->device != olddevice || !match->nentry->deleted))
53333+ match = match->next;
53334+
53335+ if (match && (match->nentry->inode == oldinode)
53336+ && (match->nentry->device == olddevice) &&
53337+ match->nentry->deleted) {
53338+ if (match->prev == NULL) {
53339+ inodev_set.i_hash[index] = match->next;
53340+ if (match->next != NULL)
53341+ match->next->prev = NULL;
53342+ } else {
53343+ match->prev->next = match->next;
53344+ if (match->next != NULL)
53345+ match->next->prev = match->prev;
53346+ }
53347+ match->prev = NULL;
53348+ match->next = NULL;
53349+ match->nentry->inode = newinode;
53350+ match->nentry->device = newdevice;
53351+ match->nentry->deleted = 0;
53352+
53353+ insert_inodev_entry(match);
53354+ }
53355+
53356+ return;
53357+}
53358+
53359+static void
53360+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53361+{
53362+ struct acl_subject_label *subj;
53363+ struct acl_role_label *role;
53364+ unsigned int x;
53365+
53366+ FOR_EACH_ROLE_START(role)
53367+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53368+
53369+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53370+ if ((subj->inode == ino) && (subj->device == dev)) {
53371+ subj->inode = ino;
53372+ subj->device = dev;
53373+ }
53374+ FOR_EACH_NESTED_SUBJECT_END(subj)
53375+ FOR_EACH_SUBJECT_START(role, subj, x)
53376+ update_acl_obj_label(matchn->inode, matchn->device,
53377+ ino, dev, subj);
53378+ FOR_EACH_SUBJECT_END(subj,x)
53379+ FOR_EACH_ROLE_END(role)
53380+
53381+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53382+
53383+ return;
53384+}
53385+
53386+static void
53387+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53388+ const struct vfsmount *mnt)
53389+{
53390+ ino_t ino = dentry->d_inode->i_ino;
53391+ dev_t dev = __get_dev(dentry);
53392+
53393+ __do_handle_create(matchn, ino, dev);
53394+
53395+ return;
53396+}
53397+
53398+void
53399+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53400+{
53401+ struct name_entry *matchn;
53402+
53403+ if (unlikely(!(gr_status & GR_READY)))
53404+ return;
53405+
53406+ preempt_disable();
53407+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53408+
53409+ if (unlikely((unsigned long)matchn)) {
53410+ write_lock(&gr_inode_lock);
53411+ do_handle_create(matchn, dentry, mnt);
53412+ write_unlock(&gr_inode_lock);
53413+ }
53414+ preempt_enable();
53415+
53416+ return;
53417+}
53418+
53419+void
53420+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53421+{
53422+ struct name_entry *matchn;
53423+
53424+ if (unlikely(!(gr_status & GR_READY)))
53425+ return;
53426+
53427+ preempt_disable();
53428+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53429+
53430+ if (unlikely((unsigned long)matchn)) {
53431+ write_lock(&gr_inode_lock);
53432+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53433+ write_unlock(&gr_inode_lock);
53434+ }
53435+ preempt_enable();
53436+
53437+ return;
53438+}
53439+
53440+void
53441+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53442+ struct dentry *old_dentry,
53443+ struct dentry *new_dentry,
53444+ struct vfsmount *mnt, const __u8 replace)
53445+{
53446+ struct name_entry *matchn;
53447+ struct inodev_entry *inodev;
53448+ struct inode *inode = new_dentry->d_inode;
53449+ ino_t old_ino = old_dentry->d_inode->i_ino;
53450+ dev_t old_dev = __get_dev(old_dentry);
53451+
53452+ /* vfs_rename swaps the name and parent link for old_dentry and
53453+ new_dentry
53454+ at this point, old_dentry has the new name, parent link, and inode
53455+ for the renamed file
53456+ if a file is being replaced by a rename, new_dentry has the inode
53457+ and name for the replaced file
53458+ */
53459+
53460+ if (unlikely(!(gr_status & GR_READY)))
53461+ return;
53462+
53463+ preempt_disable();
53464+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53465+
53466+ /* we wouldn't have to check d_inode if it weren't for
53467+ NFS silly-renaming
53468+ */
53469+
53470+ write_lock(&gr_inode_lock);
53471+ if (unlikely(replace && inode)) {
53472+ ino_t new_ino = inode->i_ino;
53473+ dev_t new_dev = __get_dev(new_dentry);
53474+
53475+ inodev = lookup_inodev_entry(new_ino, new_dev);
53476+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53477+ do_handle_delete(inodev, new_ino, new_dev);
53478+ }
53479+
53480+ inodev = lookup_inodev_entry(old_ino, old_dev);
53481+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53482+ do_handle_delete(inodev, old_ino, old_dev);
53483+
53484+ if (unlikely((unsigned long)matchn))
53485+ do_handle_create(matchn, old_dentry, mnt);
53486+
53487+ write_unlock(&gr_inode_lock);
53488+ preempt_enable();
53489+
53490+ return;
53491+}
53492+
53493+static int
53494+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53495+ unsigned char **sum)
53496+{
53497+ struct acl_role_label *r;
53498+ struct role_allowed_ip *ipp;
53499+ struct role_transition *trans;
53500+ unsigned int i;
53501+ int found = 0;
53502+ u32 curr_ip = current->signal->curr_ip;
53503+
53504+ current->signal->saved_ip = curr_ip;
53505+
53506+ /* check transition table */
53507+
53508+ for (trans = current->role->transitions; trans; trans = trans->next) {
53509+ if (!strcmp(rolename, trans->rolename)) {
53510+ found = 1;
53511+ break;
53512+ }
53513+ }
53514+
53515+ if (!found)
53516+ return 0;
53517+
53518+ /* handle special roles that do not require authentication
53519+ and check ip */
53520+
53521+ FOR_EACH_ROLE_START(r)
53522+ if (!strcmp(rolename, r->rolename) &&
53523+ (r->roletype & GR_ROLE_SPECIAL)) {
53524+ found = 0;
53525+ if (r->allowed_ips != NULL) {
53526+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53527+ if ((ntohl(curr_ip) & ipp->netmask) ==
53528+ (ntohl(ipp->addr) & ipp->netmask))
53529+ found = 1;
53530+ }
53531+ } else
53532+ found = 2;
53533+ if (!found)
53534+ return 0;
53535+
53536+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53537+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53538+ *salt = NULL;
53539+ *sum = NULL;
53540+ return 1;
53541+ }
53542+ }
53543+ FOR_EACH_ROLE_END(r)
53544+
53545+ for (i = 0; i < num_sprole_pws; i++) {
53546+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53547+ *salt = acl_special_roles[i]->salt;
53548+ *sum = acl_special_roles[i]->sum;
53549+ return 1;
53550+ }
53551+ }
53552+
53553+ return 0;
53554+}
53555+
53556+static void
53557+assign_special_role(char *rolename)
53558+{
53559+ struct acl_object_label *obj;
53560+ struct acl_role_label *r;
53561+ struct acl_role_label *assigned = NULL;
53562+ struct task_struct *tsk;
53563+ struct file *filp;
53564+
53565+ FOR_EACH_ROLE_START(r)
53566+ if (!strcmp(rolename, r->rolename) &&
53567+ (r->roletype & GR_ROLE_SPECIAL)) {
53568+ assigned = r;
53569+ break;
53570+ }
53571+ FOR_EACH_ROLE_END(r)
53572+
53573+ if (!assigned)
53574+ return;
53575+
53576+ read_lock(&tasklist_lock);
53577+ read_lock(&grsec_exec_file_lock);
53578+
53579+ tsk = current->real_parent;
53580+ if (tsk == NULL)
53581+ goto out_unlock;
53582+
53583+ filp = tsk->exec_file;
53584+ if (filp == NULL)
53585+ goto out_unlock;
53586+
53587+ tsk->is_writable = 0;
53588+
53589+ tsk->acl_sp_role = 1;
53590+ tsk->acl_role_id = ++acl_sp_role_value;
53591+ tsk->role = assigned;
53592+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53593+
53594+ /* ignore additional mmap checks for processes that are writable
53595+ by the default ACL */
53596+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53597+ if (unlikely(obj->mode & GR_WRITE))
53598+ tsk->is_writable = 1;
53599+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53600+ if (unlikely(obj->mode & GR_WRITE))
53601+ tsk->is_writable = 1;
53602+
53603+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53604+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53605+#endif
53606+
53607+out_unlock:
53608+ read_unlock(&grsec_exec_file_lock);
53609+ read_unlock(&tasklist_lock);
53610+ return;
53611+}
53612+
53613+int gr_check_secure_terminal(struct task_struct *task)
53614+{
53615+ struct task_struct *p, *p2, *p3;
53616+ struct files_struct *files;
53617+ struct fdtable *fdt;
53618+ struct file *our_file = NULL, *file;
53619+ int i;
53620+
53621+ if (task->signal->tty == NULL)
53622+ return 1;
53623+
53624+ files = get_files_struct(task);
53625+ if (files != NULL) {
53626+ rcu_read_lock();
53627+ fdt = files_fdtable(files);
53628+ for (i=0; i < fdt->max_fds; i++) {
53629+ file = fcheck_files(files, i);
53630+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53631+ get_file(file);
53632+ our_file = file;
53633+ }
53634+ }
53635+ rcu_read_unlock();
53636+ put_files_struct(files);
53637+ }
53638+
53639+ if (our_file == NULL)
53640+ return 1;
53641+
53642+ read_lock(&tasklist_lock);
53643+ do_each_thread(p2, p) {
53644+ files = get_files_struct(p);
53645+ if (files == NULL ||
53646+ (p->signal && p->signal->tty == task->signal->tty)) {
53647+ if (files != NULL)
53648+ put_files_struct(files);
53649+ continue;
53650+ }
53651+ rcu_read_lock();
53652+ fdt = files_fdtable(files);
53653+ for (i=0; i < fdt->max_fds; i++) {
53654+ file = fcheck_files(files, i);
53655+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
53656+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
53657+ p3 = task;
53658+ while (p3->pid > 0) {
53659+ if (p3 == p)
53660+ break;
53661+ p3 = p3->real_parent;
53662+ }
53663+ if (p3 == p)
53664+ break;
53665+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
53666+ gr_handle_alertkill(p);
53667+ rcu_read_unlock();
53668+ put_files_struct(files);
53669+ read_unlock(&tasklist_lock);
53670+ fput(our_file);
53671+ return 0;
53672+ }
53673+ }
53674+ rcu_read_unlock();
53675+ put_files_struct(files);
53676+ } while_each_thread(p2, p);
53677+ read_unlock(&tasklist_lock);
53678+
53679+ fput(our_file);
53680+ return 1;
53681+}
53682+
53683+static int gr_rbac_disable(void *unused)
53684+{
53685+ pax_open_kernel();
53686+ gr_status &= ~GR_READY;
53687+ pax_close_kernel();
53688+
53689+ return 0;
53690+}
53691+
53692+ssize_t
53693+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
53694+{
53695+ struct gr_arg_wrapper uwrap;
53696+ unsigned char *sprole_salt = NULL;
53697+ unsigned char *sprole_sum = NULL;
53698+ int error = sizeof (struct gr_arg_wrapper);
53699+ int error2 = 0;
53700+
53701+ mutex_lock(&gr_dev_mutex);
53702+
53703+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
53704+ error = -EPERM;
53705+ goto out;
53706+ }
53707+
53708+ if (count != sizeof (struct gr_arg_wrapper)) {
53709+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
53710+ error = -EINVAL;
53711+ goto out;
53712+ }
53713+
53714+
53715+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
53716+ gr_auth_expires = 0;
53717+ gr_auth_attempts = 0;
53718+ }
53719+
53720+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
53721+ error = -EFAULT;
53722+ goto out;
53723+ }
53724+
53725+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
53726+ error = -EINVAL;
53727+ goto out;
53728+ }
53729+
53730+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
53731+ error = -EFAULT;
53732+ goto out;
53733+ }
53734+
53735+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53736+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53737+ time_after(gr_auth_expires, get_seconds())) {
53738+ error = -EBUSY;
53739+ goto out;
53740+ }
53741+
53742+ /* if non-root trying to do anything other than use a special role,
53743+ do not attempt authentication, do not count towards authentication
53744+ locking
53745+ */
53746+
53747+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
53748+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53749+ current_uid()) {
53750+ error = -EPERM;
53751+ goto out;
53752+ }
53753+
53754+ /* ensure pw and special role name are null terminated */
53755+
53756+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
53757+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
53758+
53759+ /* Okay.
53760+ * We have our enough of the argument structure..(we have yet
53761+ * to copy_from_user the tables themselves) . Copy the tables
53762+ * only if we need them, i.e. for loading operations. */
53763+
53764+ switch (gr_usermode->mode) {
53765+ case GR_STATUS:
53766+ if (gr_status & GR_READY) {
53767+ error = 1;
53768+ if (!gr_check_secure_terminal(current))
53769+ error = 3;
53770+ } else
53771+ error = 2;
53772+ goto out;
53773+ case GR_SHUTDOWN:
53774+ if ((gr_status & GR_READY)
53775+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53776+ stop_machine(gr_rbac_disable, NULL, NULL);
53777+ free_variables();
53778+ memset(gr_usermode, 0, sizeof (struct gr_arg));
53779+ memset(gr_system_salt, 0, GR_SALT_LEN);
53780+ memset(gr_system_sum, 0, GR_SHA_LEN);
53781+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
53782+ } else if (gr_status & GR_READY) {
53783+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
53784+ error = -EPERM;
53785+ } else {
53786+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
53787+ error = -EAGAIN;
53788+ }
53789+ break;
53790+ case GR_ENABLE:
53791+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
53792+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
53793+ else {
53794+ if (gr_status & GR_READY)
53795+ error = -EAGAIN;
53796+ else
53797+ error = error2;
53798+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
53799+ }
53800+ break;
53801+ case GR_RELOAD:
53802+ if (!(gr_status & GR_READY)) {
53803+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
53804+ error = -EAGAIN;
53805+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53806+ stop_machine(gr_rbac_disable, NULL, NULL);
53807+ free_variables();
53808+ error2 = gracl_init(gr_usermode);
53809+ if (!error2)
53810+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
53811+ else {
53812+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53813+ error = error2;
53814+ }
53815+ } else {
53816+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53817+ error = -EPERM;
53818+ }
53819+ break;
53820+ case GR_SEGVMOD:
53821+ if (unlikely(!(gr_status & GR_READY))) {
53822+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
53823+ error = -EAGAIN;
53824+ break;
53825+ }
53826+
53827+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53828+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
53829+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
53830+ struct acl_subject_label *segvacl;
53831+ segvacl =
53832+ lookup_acl_subj_label(gr_usermode->segv_inode,
53833+ gr_usermode->segv_device,
53834+ current->role);
53835+ if (segvacl) {
53836+ segvacl->crashes = 0;
53837+ segvacl->expires = 0;
53838+ }
53839+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
53840+ gr_remove_uid(gr_usermode->segv_uid);
53841+ }
53842+ } else {
53843+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
53844+ error = -EPERM;
53845+ }
53846+ break;
53847+ case GR_SPROLE:
53848+ case GR_SPROLEPAM:
53849+ if (unlikely(!(gr_status & GR_READY))) {
53850+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
53851+ error = -EAGAIN;
53852+ break;
53853+ }
53854+
53855+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
53856+ current->role->expires = 0;
53857+ current->role->auth_attempts = 0;
53858+ }
53859+
53860+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53861+ time_after(current->role->expires, get_seconds())) {
53862+ error = -EBUSY;
53863+ goto out;
53864+ }
53865+
53866+ if (lookup_special_role_auth
53867+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
53868+ && ((!sprole_salt && !sprole_sum)
53869+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
53870+ char *p = "";
53871+ assign_special_role(gr_usermode->sp_role);
53872+ read_lock(&tasklist_lock);
53873+ if (current->real_parent)
53874+ p = current->real_parent->role->rolename;
53875+ read_unlock(&tasklist_lock);
53876+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
53877+ p, acl_sp_role_value);
53878+ } else {
53879+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
53880+ error = -EPERM;
53881+ if(!(current->role->auth_attempts++))
53882+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53883+
53884+ goto out;
53885+ }
53886+ break;
53887+ case GR_UNSPROLE:
53888+ if (unlikely(!(gr_status & GR_READY))) {
53889+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
53890+ error = -EAGAIN;
53891+ break;
53892+ }
53893+
53894+ if (current->role->roletype & GR_ROLE_SPECIAL) {
53895+ char *p = "";
53896+ int i = 0;
53897+
53898+ read_lock(&tasklist_lock);
53899+ if (current->real_parent) {
53900+ p = current->real_parent->role->rolename;
53901+ i = current->real_parent->acl_role_id;
53902+ }
53903+ read_unlock(&tasklist_lock);
53904+
53905+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
53906+ gr_set_acls(1);
53907+ } else {
53908+ error = -EPERM;
53909+ goto out;
53910+ }
53911+ break;
53912+ default:
53913+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
53914+ error = -EINVAL;
53915+ break;
53916+ }
53917+
53918+ if (error != -EPERM)
53919+ goto out;
53920+
53921+ if(!(gr_auth_attempts++))
53922+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53923+
53924+ out:
53925+ mutex_unlock(&gr_dev_mutex);
53926+ return error;
53927+}
53928+
53929+/* must be called with
53930+ rcu_read_lock();
53931+ read_lock(&tasklist_lock);
53932+ read_lock(&grsec_exec_file_lock);
53933+*/
53934+int gr_apply_subject_to_task(struct task_struct *task)
53935+{
53936+ struct acl_object_label *obj;
53937+ char *tmpname;
53938+ struct acl_subject_label *tmpsubj;
53939+ struct file *filp;
53940+ struct name_entry *nmatch;
53941+
53942+ filp = task->exec_file;
53943+ if (filp == NULL)
53944+ return 0;
53945+
53946+ /* the following is to apply the correct subject
53947+ on binaries running when the RBAC system
53948+ is enabled, when the binaries have been
53949+ replaced or deleted since their execution
53950+ -----
53951+ when the RBAC system starts, the inode/dev
53952+ from exec_file will be one the RBAC system
53953+ is unaware of. It only knows the inode/dev
53954+ of the present file on disk, or the absence
53955+ of it.
53956+ */
53957+ preempt_disable();
53958+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
53959+
53960+ nmatch = lookup_name_entry(tmpname);
53961+ preempt_enable();
53962+ tmpsubj = NULL;
53963+ if (nmatch) {
53964+ if (nmatch->deleted)
53965+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
53966+ else
53967+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
53968+ if (tmpsubj != NULL)
53969+ task->acl = tmpsubj;
53970+ }
53971+ if (tmpsubj == NULL)
53972+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
53973+ task->role);
53974+ if (task->acl) {
53975+ task->is_writable = 0;
53976+ /* ignore additional mmap checks for processes that are writable
53977+ by the default ACL */
53978+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53979+ if (unlikely(obj->mode & GR_WRITE))
53980+ task->is_writable = 1;
53981+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53982+ if (unlikely(obj->mode & GR_WRITE))
53983+ task->is_writable = 1;
53984+
53985+ gr_set_proc_res(task);
53986+
53987+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53988+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53989+#endif
53990+ } else {
53991+ return 1;
53992+ }
53993+
53994+ return 0;
53995+}
53996+
53997+int
53998+gr_set_acls(const int type)
53999+{
54000+ struct task_struct *task, *task2;
54001+ struct acl_role_label *role = current->role;
54002+ __u16 acl_role_id = current->acl_role_id;
54003+ const struct cred *cred;
54004+ int ret;
54005+
54006+ rcu_read_lock();
54007+ read_lock(&tasklist_lock);
54008+ read_lock(&grsec_exec_file_lock);
54009+ do_each_thread(task2, task) {
54010+ /* check to see if we're called from the exit handler,
54011+ if so, only replace ACLs that have inherited the admin
54012+ ACL */
54013+
54014+ if (type && (task->role != role ||
54015+ task->acl_role_id != acl_role_id))
54016+ continue;
54017+
54018+ task->acl_role_id = 0;
54019+ task->acl_sp_role = 0;
54020+
54021+ if (task->exec_file) {
54022+ cred = __task_cred(task);
54023+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54024+ ret = gr_apply_subject_to_task(task);
54025+ if (ret) {
54026+ read_unlock(&grsec_exec_file_lock);
54027+ read_unlock(&tasklist_lock);
54028+ rcu_read_unlock();
54029+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54030+ return ret;
54031+ }
54032+ } else {
54033+ // it's a kernel process
54034+ task->role = kernel_role;
54035+ task->acl = kernel_role->root_label;
54036+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54037+ task->acl->mode &= ~GR_PROCFIND;
54038+#endif
54039+ }
54040+ } while_each_thread(task2, task);
54041+ read_unlock(&grsec_exec_file_lock);
54042+ read_unlock(&tasklist_lock);
54043+ rcu_read_unlock();
54044+
54045+ return 0;
54046+}
54047+
54048+void
54049+gr_learn_resource(const struct task_struct *task,
54050+ const int res, const unsigned long wanted, const int gt)
54051+{
54052+ struct acl_subject_label *acl;
54053+ const struct cred *cred;
54054+
54055+ if (unlikely((gr_status & GR_READY) &&
54056+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54057+ goto skip_reslog;
54058+
54059+#ifdef CONFIG_GRKERNSEC_RESLOG
54060+ gr_log_resource(task, res, wanted, gt);
54061+#endif
54062+ skip_reslog:
54063+
54064+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54065+ return;
54066+
54067+ acl = task->acl;
54068+
54069+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54070+ !(acl->resmask & (1 << (unsigned short) res))))
54071+ return;
54072+
54073+ if (wanted >= acl->res[res].rlim_cur) {
54074+ unsigned long res_add;
54075+
54076+ res_add = wanted;
54077+ switch (res) {
54078+ case RLIMIT_CPU:
54079+ res_add += GR_RLIM_CPU_BUMP;
54080+ break;
54081+ case RLIMIT_FSIZE:
54082+ res_add += GR_RLIM_FSIZE_BUMP;
54083+ break;
54084+ case RLIMIT_DATA:
54085+ res_add += GR_RLIM_DATA_BUMP;
54086+ break;
54087+ case RLIMIT_STACK:
54088+ res_add += GR_RLIM_STACK_BUMP;
54089+ break;
54090+ case RLIMIT_CORE:
54091+ res_add += GR_RLIM_CORE_BUMP;
54092+ break;
54093+ case RLIMIT_RSS:
54094+ res_add += GR_RLIM_RSS_BUMP;
54095+ break;
54096+ case RLIMIT_NPROC:
54097+ res_add += GR_RLIM_NPROC_BUMP;
54098+ break;
54099+ case RLIMIT_NOFILE:
54100+ res_add += GR_RLIM_NOFILE_BUMP;
54101+ break;
54102+ case RLIMIT_MEMLOCK:
54103+ res_add += GR_RLIM_MEMLOCK_BUMP;
54104+ break;
54105+ case RLIMIT_AS:
54106+ res_add += GR_RLIM_AS_BUMP;
54107+ break;
54108+ case RLIMIT_LOCKS:
54109+ res_add += GR_RLIM_LOCKS_BUMP;
54110+ break;
54111+ case RLIMIT_SIGPENDING:
54112+ res_add += GR_RLIM_SIGPENDING_BUMP;
54113+ break;
54114+ case RLIMIT_MSGQUEUE:
54115+ res_add += GR_RLIM_MSGQUEUE_BUMP;
54116+ break;
54117+ case RLIMIT_NICE:
54118+ res_add += GR_RLIM_NICE_BUMP;
54119+ break;
54120+ case RLIMIT_RTPRIO:
54121+ res_add += GR_RLIM_RTPRIO_BUMP;
54122+ break;
54123+ case RLIMIT_RTTIME:
54124+ res_add += GR_RLIM_RTTIME_BUMP;
54125+ break;
54126+ }
54127+
54128+ acl->res[res].rlim_cur = res_add;
54129+
54130+ if (wanted > acl->res[res].rlim_max)
54131+ acl->res[res].rlim_max = res_add;
54132+
54133+ /* only log the subject filename, since resource logging is supported for
54134+ single-subject learning only */
54135+ rcu_read_lock();
54136+ cred = __task_cred(task);
54137+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54138+ task->role->roletype, cred->uid, cred->gid, acl->filename,
54139+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54140+ "", (unsigned long) res, &task->signal->saved_ip);
54141+ rcu_read_unlock();
54142+ }
54143+
54144+ return;
54145+}
54146+
54147+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54148+void
54149+pax_set_initial_flags(struct linux_binprm *bprm)
54150+{
54151+ struct task_struct *task = current;
54152+ struct acl_subject_label *proc;
54153+ unsigned long flags;
54154+
54155+ if (unlikely(!(gr_status & GR_READY)))
54156+ return;
54157+
54158+ flags = pax_get_flags(task);
54159+
54160+ proc = task->acl;
54161+
54162+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54163+ flags &= ~MF_PAX_PAGEEXEC;
54164+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54165+ flags &= ~MF_PAX_SEGMEXEC;
54166+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54167+ flags &= ~MF_PAX_RANDMMAP;
54168+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54169+ flags &= ~MF_PAX_EMUTRAMP;
54170+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54171+ flags &= ~MF_PAX_MPROTECT;
54172+
54173+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54174+ flags |= MF_PAX_PAGEEXEC;
54175+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54176+ flags |= MF_PAX_SEGMEXEC;
54177+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54178+ flags |= MF_PAX_RANDMMAP;
54179+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54180+ flags |= MF_PAX_EMUTRAMP;
54181+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54182+ flags |= MF_PAX_MPROTECT;
54183+
54184+ pax_set_flags(task, flags);
54185+
54186+ return;
54187+}
54188+#endif
54189+
54190+int
54191+gr_handle_proc_ptrace(struct task_struct *task)
54192+{
54193+ struct file *filp;
54194+ struct task_struct *tmp = task;
54195+ struct task_struct *curtemp = current;
54196+ __u32 retmode;
54197+
54198+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54199+ if (unlikely(!(gr_status & GR_READY)))
54200+ return 0;
54201+#endif
54202+
54203+ read_lock(&tasklist_lock);
54204+ read_lock(&grsec_exec_file_lock);
54205+ filp = task->exec_file;
54206+
54207+ while (tmp->pid > 0) {
54208+ if (tmp == curtemp)
54209+ break;
54210+ tmp = tmp->real_parent;
54211+ }
54212+
54213+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54214+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54215+ read_unlock(&grsec_exec_file_lock);
54216+ read_unlock(&tasklist_lock);
54217+ return 1;
54218+ }
54219+
54220+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54221+ if (!(gr_status & GR_READY)) {
54222+ read_unlock(&grsec_exec_file_lock);
54223+ read_unlock(&tasklist_lock);
54224+ return 0;
54225+ }
54226+#endif
54227+
54228+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54229+ read_unlock(&grsec_exec_file_lock);
54230+ read_unlock(&tasklist_lock);
54231+
54232+ if (retmode & GR_NOPTRACE)
54233+ return 1;
54234+
54235+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54236+ && (current->acl != task->acl || (current->acl != current->role->root_label
54237+ && current->pid != task->pid)))
54238+ return 1;
54239+
54240+ return 0;
54241+}
54242+
54243+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54244+{
54245+ if (unlikely(!(gr_status & GR_READY)))
54246+ return;
54247+
54248+ if (!(current->role->roletype & GR_ROLE_GOD))
54249+ return;
54250+
54251+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54252+ p->role->rolename, gr_task_roletype_to_char(p),
54253+ p->acl->filename);
54254+}
54255+
54256+int
54257+gr_handle_ptrace(struct task_struct *task, const long request)
54258+{
54259+ struct task_struct *tmp = task;
54260+ struct task_struct *curtemp = current;
54261+ __u32 retmode;
54262+
54263+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54264+ if (unlikely(!(gr_status & GR_READY)))
54265+ return 0;
54266+#endif
54267+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54268+ read_lock(&tasklist_lock);
54269+ while (tmp->pid > 0) {
54270+ if (tmp == curtemp)
54271+ break;
54272+ tmp = tmp->real_parent;
54273+ }
54274+
54275+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54276+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54277+ read_unlock(&tasklist_lock);
54278+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54279+ return 1;
54280+ }
54281+ read_unlock(&tasklist_lock);
54282+ }
54283+
54284+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54285+ if (!(gr_status & GR_READY))
54286+ return 0;
54287+#endif
54288+
54289+ read_lock(&grsec_exec_file_lock);
54290+ if (unlikely(!task->exec_file)) {
54291+ read_unlock(&grsec_exec_file_lock);
54292+ return 0;
54293+ }
54294+
54295+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54296+ read_unlock(&grsec_exec_file_lock);
54297+
54298+ if (retmode & GR_NOPTRACE) {
54299+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54300+ return 1;
54301+ }
54302+
54303+ if (retmode & GR_PTRACERD) {
54304+ switch (request) {
54305+ case PTRACE_SEIZE:
54306+ case PTRACE_POKETEXT:
54307+ case PTRACE_POKEDATA:
54308+ case PTRACE_POKEUSR:
54309+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54310+ case PTRACE_SETREGS:
54311+ case PTRACE_SETFPREGS:
54312+#endif
54313+#ifdef CONFIG_X86
54314+ case PTRACE_SETFPXREGS:
54315+#endif
54316+#ifdef CONFIG_ALTIVEC
54317+ case PTRACE_SETVRREGS:
54318+#endif
54319+ return 1;
54320+ default:
54321+ return 0;
54322+ }
54323+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
54324+ !(current->role->roletype & GR_ROLE_GOD) &&
54325+ (current->acl != task->acl)) {
54326+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54327+ return 1;
54328+ }
54329+
54330+ return 0;
54331+}
54332+
54333+static int is_writable_mmap(const struct file *filp)
54334+{
54335+ struct task_struct *task = current;
54336+ struct acl_object_label *obj, *obj2;
54337+
54338+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54339+ !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))) {
54340+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54341+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54342+ task->role->root_label);
54343+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54344+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54345+ return 1;
54346+ }
54347+ }
54348+ return 0;
54349+}
54350+
54351+int
54352+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54353+{
54354+ __u32 mode;
54355+
54356+ if (unlikely(!file || !(prot & PROT_EXEC)))
54357+ return 1;
54358+
54359+ if (is_writable_mmap(file))
54360+ return 0;
54361+
54362+ mode =
54363+ gr_search_file(file->f_path.dentry,
54364+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54365+ file->f_path.mnt);
54366+
54367+ if (!gr_tpe_allow(file))
54368+ return 0;
54369+
54370+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54371+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54372+ return 0;
54373+ } else if (unlikely(!(mode & GR_EXEC))) {
54374+ return 0;
54375+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54376+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54377+ return 1;
54378+ }
54379+
54380+ return 1;
54381+}
54382+
54383+int
54384+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54385+{
54386+ __u32 mode;
54387+
54388+ if (unlikely(!file || !(prot & PROT_EXEC)))
54389+ return 1;
54390+
54391+ if (is_writable_mmap(file))
54392+ return 0;
54393+
54394+ mode =
54395+ gr_search_file(file->f_path.dentry,
54396+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54397+ file->f_path.mnt);
54398+
54399+ if (!gr_tpe_allow(file))
54400+ return 0;
54401+
54402+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54403+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54404+ return 0;
54405+ } else if (unlikely(!(mode & GR_EXEC))) {
54406+ return 0;
54407+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54408+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54409+ return 1;
54410+ }
54411+
54412+ return 1;
54413+}
54414+
54415+void
54416+gr_acl_handle_psacct(struct task_struct *task, const long code)
54417+{
54418+ unsigned long runtime;
54419+ unsigned long cputime;
54420+ unsigned int wday, cday;
54421+ __u8 whr, chr;
54422+ __u8 wmin, cmin;
54423+ __u8 wsec, csec;
54424+ struct timespec timeval;
54425+
54426+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54427+ !(task->acl->mode & GR_PROCACCT)))
54428+ return;
54429+
54430+ do_posix_clock_monotonic_gettime(&timeval);
54431+ runtime = timeval.tv_sec - task->start_time.tv_sec;
54432+ wday = runtime / (3600 * 24);
54433+ runtime -= wday * (3600 * 24);
54434+ whr = runtime / 3600;
54435+ runtime -= whr * 3600;
54436+ wmin = runtime / 60;
54437+ runtime -= wmin * 60;
54438+ wsec = runtime;
54439+
54440+ cputime = (task->utime + task->stime) / HZ;
54441+ cday = cputime / (3600 * 24);
54442+ cputime -= cday * (3600 * 24);
54443+ chr = cputime / 3600;
54444+ cputime -= chr * 3600;
54445+ cmin = cputime / 60;
54446+ cputime -= cmin * 60;
54447+ csec = cputime;
54448+
54449+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54450+
54451+ return;
54452+}
54453+
54454+void gr_set_kernel_label(struct task_struct *task)
54455+{
54456+ if (gr_status & GR_READY) {
54457+ task->role = kernel_role;
54458+ task->acl = kernel_role->root_label;
54459+ }
54460+ return;
54461+}
54462+
54463+#ifdef CONFIG_TASKSTATS
54464+int gr_is_taskstats_denied(int pid)
54465+{
54466+ struct task_struct *task;
54467+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54468+ const struct cred *cred;
54469+#endif
54470+ int ret = 0;
54471+
54472+ /* restrict taskstats viewing to un-chrooted root users
54473+ who have the 'view' subject flag if the RBAC system is enabled
54474+ */
54475+
54476+ rcu_read_lock();
54477+ read_lock(&tasklist_lock);
54478+ task = find_task_by_vpid(pid);
54479+ if (task) {
54480+#ifdef CONFIG_GRKERNSEC_CHROOT
54481+ if (proc_is_chrooted(task))
54482+ ret = -EACCES;
54483+#endif
54484+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54485+ cred = __task_cred(task);
54486+#ifdef CONFIG_GRKERNSEC_PROC_USER
54487+ if (cred->uid != 0)
54488+ ret = -EACCES;
54489+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54490+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54491+ ret = -EACCES;
54492+#endif
54493+#endif
54494+ if (gr_status & GR_READY) {
54495+ if (!(task->acl->mode & GR_VIEW))
54496+ ret = -EACCES;
54497+ }
54498+ } else
54499+ ret = -ENOENT;
54500+
54501+ read_unlock(&tasklist_lock);
54502+ rcu_read_unlock();
54503+
54504+ return ret;
54505+}
54506+#endif
54507+
54508+/* AUXV entries are filled via a descendant of search_binary_handler
54509+ after we've already applied the subject for the target
54510+*/
54511+int gr_acl_enable_at_secure(void)
54512+{
54513+ if (unlikely(!(gr_status & GR_READY)))
54514+ return 0;
54515+
54516+ if (current->acl->mode & GR_ATSECURE)
54517+ return 1;
54518+
54519+ return 0;
54520+}
54521+
54522+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54523+{
54524+ struct task_struct *task = current;
54525+ struct dentry *dentry = file->f_path.dentry;
54526+ struct vfsmount *mnt = file->f_path.mnt;
54527+ struct acl_object_label *obj, *tmp;
54528+ struct acl_subject_label *subj;
54529+ unsigned int bufsize;
54530+ int is_not_root;
54531+ char *path;
54532+ dev_t dev = __get_dev(dentry);
54533+
54534+ if (unlikely(!(gr_status & GR_READY)))
54535+ return 1;
54536+
54537+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54538+ return 1;
54539+
54540+ /* ignore Eric Biederman */
54541+ if (IS_PRIVATE(dentry->d_inode))
54542+ return 1;
54543+
54544+ subj = task->acl;
54545+ read_lock(&gr_inode_lock);
54546+ do {
54547+ obj = lookup_acl_obj_label(ino, dev, subj);
54548+ if (obj != NULL) {
54549+ read_unlock(&gr_inode_lock);
54550+ return (obj->mode & GR_FIND) ? 1 : 0;
54551+ }
54552+ } while ((subj = subj->parent_subject));
54553+ read_unlock(&gr_inode_lock);
54554+
54555+ /* this is purely an optimization since we're looking for an object
54556+ for the directory we're doing a readdir on
54557+ if it's possible for any globbed object to match the entry we're
54558+ filling into the directory, then the object we find here will be
54559+ an anchor point with attached globbed objects
54560+ */
54561+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54562+ if (obj->globbed == NULL)
54563+ return (obj->mode & GR_FIND) ? 1 : 0;
54564+
54565+ is_not_root = ((obj->filename[0] == '/') &&
54566+ (obj->filename[1] == '\0')) ? 0 : 1;
54567+ bufsize = PAGE_SIZE - namelen - is_not_root;
54568+
54569+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
54570+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54571+ return 1;
54572+
54573+ preempt_disable();
54574+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54575+ bufsize);
54576+
54577+ bufsize = strlen(path);
54578+
54579+ /* if base is "/", don't append an additional slash */
54580+ if (is_not_root)
54581+ *(path + bufsize) = '/';
54582+ memcpy(path + bufsize + is_not_root, name, namelen);
54583+ *(path + bufsize + namelen + is_not_root) = '\0';
54584+
54585+ tmp = obj->globbed;
54586+ while (tmp) {
54587+ if (!glob_match(tmp->filename, path)) {
54588+ preempt_enable();
54589+ return (tmp->mode & GR_FIND) ? 1 : 0;
54590+ }
54591+ tmp = tmp->next;
54592+ }
54593+ preempt_enable();
54594+ return (obj->mode & GR_FIND) ? 1 : 0;
54595+}
54596+
54597+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54598+EXPORT_SYMBOL(gr_acl_is_enabled);
54599+#endif
54600+EXPORT_SYMBOL(gr_learn_resource);
54601+EXPORT_SYMBOL(gr_set_kernel_label);
54602+#ifdef CONFIG_SECURITY
54603+EXPORT_SYMBOL(gr_check_user_change);
54604+EXPORT_SYMBOL(gr_check_group_change);
54605+#endif
54606+
54607diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54608new file mode 100644
54609index 0000000..34fefda
54610--- /dev/null
54611+++ b/grsecurity/gracl_alloc.c
54612@@ -0,0 +1,105 @@
54613+#include <linux/kernel.h>
54614+#include <linux/mm.h>
54615+#include <linux/slab.h>
54616+#include <linux/vmalloc.h>
54617+#include <linux/gracl.h>
54618+#include <linux/grsecurity.h>
54619+
54620+static unsigned long alloc_stack_next = 1;
54621+static unsigned long alloc_stack_size = 1;
54622+static void **alloc_stack;
54623+
54624+static __inline__ int
54625+alloc_pop(void)
54626+{
54627+ if (alloc_stack_next == 1)
54628+ return 0;
54629+
54630+ kfree(alloc_stack[alloc_stack_next - 2]);
54631+
54632+ alloc_stack_next--;
54633+
54634+ return 1;
54635+}
54636+
54637+static __inline__ int
54638+alloc_push(void *buf)
54639+{
54640+ if (alloc_stack_next >= alloc_stack_size)
54641+ return 1;
54642+
54643+ alloc_stack[alloc_stack_next - 1] = buf;
54644+
54645+ alloc_stack_next++;
54646+
54647+ return 0;
54648+}
54649+
54650+void *
54651+acl_alloc(unsigned long len)
54652+{
54653+ void *ret = NULL;
54654+
54655+ if (!len || len > PAGE_SIZE)
54656+ goto out;
54657+
54658+ ret = kmalloc(len, GFP_KERNEL);
54659+
54660+ if (ret) {
54661+ if (alloc_push(ret)) {
54662+ kfree(ret);
54663+ ret = NULL;
54664+ }
54665+ }
54666+
54667+out:
54668+ return ret;
54669+}
54670+
54671+void *
54672+acl_alloc_num(unsigned long num, unsigned long len)
54673+{
54674+ if (!len || (num > (PAGE_SIZE / len)))
54675+ return NULL;
54676+
54677+ return acl_alloc(num * len);
54678+}
54679+
54680+void
54681+acl_free_all(void)
54682+{
54683+ if (gr_acl_is_enabled() || !alloc_stack)
54684+ return;
54685+
54686+ while (alloc_pop()) ;
54687+
54688+ if (alloc_stack) {
54689+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
54690+ kfree(alloc_stack);
54691+ else
54692+ vfree(alloc_stack);
54693+ }
54694+
54695+ alloc_stack = NULL;
54696+ alloc_stack_size = 1;
54697+ alloc_stack_next = 1;
54698+
54699+ return;
54700+}
54701+
54702+int
54703+acl_alloc_stack_init(unsigned long size)
54704+{
54705+ if ((size * sizeof (void *)) <= PAGE_SIZE)
54706+ alloc_stack =
54707+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
54708+ else
54709+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
54710+
54711+ alloc_stack_size = size;
54712+
54713+ if (!alloc_stack)
54714+ return 0;
54715+ else
54716+ return 1;
54717+}
54718diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
54719new file mode 100644
54720index 0000000..6d21049
54721--- /dev/null
54722+++ b/grsecurity/gracl_cap.c
54723@@ -0,0 +1,110 @@
54724+#include <linux/kernel.h>
54725+#include <linux/module.h>
54726+#include <linux/sched.h>
54727+#include <linux/gracl.h>
54728+#include <linux/grsecurity.h>
54729+#include <linux/grinternal.h>
54730+
54731+extern const char *captab_log[];
54732+extern int captab_log_entries;
54733+
54734+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
54735+{
54736+ struct acl_subject_label *curracl;
54737+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54738+ kernel_cap_t cap_audit = __cap_empty_set;
54739+
54740+ if (!gr_acl_is_enabled())
54741+ return 1;
54742+
54743+ curracl = task->acl;
54744+
54745+ cap_drop = curracl->cap_lower;
54746+ cap_mask = curracl->cap_mask;
54747+ cap_audit = curracl->cap_invert_audit;
54748+
54749+ while ((curracl = curracl->parent_subject)) {
54750+ /* if the cap isn't specified in the current computed mask but is specified in the
54751+ current level subject, and is lowered in the current level subject, then add
54752+ it to the set of dropped capabilities
54753+ otherwise, add the current level subject's mask to the current computed mask
54754+ */
54755+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54756+ cap_raise(cap_mask, cap);
54757+ if (cap_raised(curracl->cap_lower, cap))
54758+ cap_raise(cap_drop, cap);
54759+ if (cap_raised(curracl->cap_invert_audit, cap))
54760+ cap_raise(cap_audit, cap);
54761+ }
54762+ }
54763+
54764+ if (!cap_raised(cap_drop, cap)) {
54765+ if (cap_raised(cap_audit, cap))
54766+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
54767+ return 1;
54768+ }
54769+
54770+ curracl = task->acl;
54771+
54772+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
54773+ && cap_raised(cred->cap_effective, cap)) {
54774+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54775+ task->role->roletype, cred->uid,
54776+ cred->gid, task->exec_file ?
54777+ gr_to_filename(task->exec_file->f_path.dentry,
54778+ task->exec_file->f_path.mnt) : curracl->filename,
54779+ curracl->filename, 0UL,
54780+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
54781+ return 1;
54782+ }
54783+
54784+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
54785+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
54786+
54787+ return 0;
54788+}
54789+
54790+int
54791+gr_acl_is_capable(const int cap)
54792+{
54793+ return gr_task_acl_is_capable(current, current_cred(), cap);
54794+}
54795+
54796+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
54797+{
54798+ struct acl_subject_label *curracl;
54799+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54800+
54801+ if (!gr_acl_is_enabled())
54802+ return 1;
54803+
54804+ curracl = task->acl;
54805+
54806+ cap_drop = curracl->cap_lower;
54807+ cap_mask = curracl->cap_mask;
54808+
54809+ while ((curracl = curracl->parent_subject)) {
54810+ /* if the cap isn't specified in the current computed mask but is specified in the
54811+ current level subject, and is lowered in the current level subject, then add
54812+ it to the set of dropped capabilities
54813+ otherwise, add the current level subject's mask to the current computed mask
54814+ */
54815+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54816+ cap_raise(cap_mask, cap);
54817+ if (cap_raised(curracl->cap_lower, cap))
54818+ cap_raise(cap_drop, cap);
54819+ }
54820+ }
54821+
54822+ if (!cap_raised(cap_drop, cap))
54823+ return 1;
54824+
54825+ return 0;
54826+}
54827+
54828+int
54829+gr_acl_is_capable_nolog(const int cap)
54830+{
54831+ return gr_task_acl_is_capable_nolog(current, cap);
54832+}
54833+
54834diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
54835new file mode 100644
54836index 0000000..88d0e87
54837--- /dev/null
54838+++ b/grsecurity/gracl_fs.c
54839@@ -0,0 +1,435 @@
54840+#include <linux/kernel.h>
54841+#include <linux/sched.h>
54842+#include <linux/types.h>
54843+#include <linux/fs.h>
54844+#include <linux/file.h>
54845+#include <linux/stat.h>
54846+#include <linux/grsecurity.h>
54847+#include <linux/grinternal.h>
54848+#include <linux/gracl.h>
54849+
54850+umode_t
54851+gr_acl_umask(void)
54852+{
54853+ if (unlikely(!gr_acl_is_enabled()))
54854+ return 0;
54855+
54856+ return current->role->umask;
54857+}
54858+
54859+__u32
54860+gr_acl_handle_hidden_file(const struct dentry * dentry,
54861+ const struct vfsmount * mnt)
54862+{
54863+ __u32 mode;
54864+
54865+ if (unlikely(!dentry->d_inode))
54866+ return GR_FIND;
54867+
54868+ mode =
54869+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
54870+
54871+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
54872+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54873+ return mode;
54874+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
54875+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54876+ return 0;
54877+ } else if (unlikely(!(mode & GR_FIND)))
54878+ return 0;
54879+
54880+ return GR_FIND;
54881+}
54882+
54883+__u32
54884+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
54885+ int acc_mode)
54886+{
54887+ __u32 reqmode = GR_FIND;
54888+ __u32 mode;
54889+
54890+ if (unlikely(!dentry->d_inode))
54891+ return reqmode;
54892+
54893+ if (acc_mode & MAY_APPEND)
54894+ reqmode |= GR_APPEND;
54895+ else if (acc_mode & MAY_WRITE)
54896+ reqmode |= GR_WRITE;
54897+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
54898+ reqmode |= GR_READ;
54899+
54900+ mode =
54901+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54902+ mnt);
54903+
54904+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54905+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54906+ reqmode & GR_READ ? " reading" : "",
54907+ reqmode & GR_WRITE ? " writing" : reqmode &
54908+ GR_APPEND ? " appending" : "");
54909+ return reqmode;
54910+ } else
54911+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54912+ {
54913+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54914+ reqmode & GR_READ ? " reading" : "",
54915+ reqmode & GR_WRITE ? " writing" : reqmode &
54916+ GR_APPEND ? " appending" : "");
54917+ return 0;
54918+ } else if (unlikely((mode & reqmode) != reqmode))
54919+ return 0;
54920+
54921+ return reqmode;
54922+}
54923+
54924+__u32
54925+gr_acl_handle_creat(const struct dentry * dentry,
54926+ const struct dentry * p_dentry,
54927+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
54928+ const int imode)
54929+{
54930+ __u32 reqmode = GR_WRITE | GR_CREATE;
54931+ __u32 mode;
54932+
54933+ if (acc_mode & MAY_APPEND)
54934+ reqmode |= GR_APPEND;
54935+ // if a directory was required or the directory already exists, then
54936+ // don't count this open as a read
54937+ if ((acc_mode & MAY_READ) &&
54938+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
54939+ reqmode |= GR_READ;
54940+ if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
54941+ reqmode |= GR_SETID;
54942+
54943+ mode =
54944+ gr_check_create(dentry, p_dentry, p_mnt,
54945+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54946+
54947+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54948+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54949+ reqmode & GR_READ ? " reading" : "",
54950+ reqmode & GR_WRITE ? " writing" : reqmode &
54951+ GR_APPEND ? " appending" : "");
54952+ return reqmode;
54953+ } else
54954+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54955+ {
54956+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54957+ reqmode & GR_READ ? " reading" : "",
54958+ reqmode & GR_WRITE ? " writing" : reqmode &
54959+ GR_APPEND ? " appending" : "");
54960+ return 0;
54961+ } else if (unlikely((mode & reqmode) != reqmode))
54962+ return 0;
54963+
54964+ return reqmode;
54965+}
54966+
54967+__u32
54968+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
54969+ const int fmode)
54970+{
54971+ __u32 mode, reqmode = GR_FIND;
54972+
54973+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
54974+ reqmode |= GR_EXEC;
54975+ if (fmode & S_IWOTH)
54976+ reqmode |= GR_WRITE;
54977+ if (fmode & S_IROTH)
54978+ reqmode |= GR_READ;
54979+
54980+ mode =
54981+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54982+ mnt);
54983+
54984+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54985+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54986+ reqmode & GR_READ ? " reading" : "",
54987+ reqmode & GR_WRITE ? " writing" : "",
54988+ reqmode & GR_EXEC ? " executing" : "");
54989+ return reqmode;
54990+ } else
54991+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54992+ {
54993+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54994+ reqmode & GR_READ ? " reading" : "",
54995+ reqmode & GR_WRITE ? " writing" : "",
54996+ reqmode & GR_EXEC ? " executing" : "");
54997+ return 0;
54998+ } else if (unlikely((mode & reqmode) != reqmode))
54999+ return 0;
55000+
55001+ return reqmode;
55002+}
55003+
55004+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55005+{
55006+ __u32 mode;
55007+
55008+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55009+
55010+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55011+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55012+ return mode;
55013+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55014+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55015+ return 0;
55016+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55017+ return 0;
55018+
55019+ return (reqmode);
55020+}
55021+
55022+__u32
55023+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55024+{
55025+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55026+}
55027+
55028+__u32
55029+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55030+{
55031+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55032+}
55033+
55034+__u32
55035+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55036+{
55037+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55038+}
55039+
55040+__u32
55041+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55042+{
55043+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55044+}
55045+
55046+__u32
55047+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55048+ umode_t *modeptr)
55049+{
55050+ umode_t mode;
55051+
55052+ *modeptr &= ~gr_acl_umask();
55053+ mode = *modeptr;
55054+
55055+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55056+ return 1;
55057+
55058+ if (unlikely(mode & (S_ISUID | S_ISGID))) {
55059+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55060+ GR_CHMOD_ACL_MSG);
55061+ } else {
55062+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55063+ }
55064+}
55065+
55066+__u32
55067+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55068+{
55069+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55070+}
55071+
55072+__u32
55073+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55074+{
55075+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55076+}
55077+
55078+__u32
55079+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55080+{
55081+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55082+}
55083+
55084+__u32
55085+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55086+{
55087+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55088+ GR_UNIXCONNECT_ACL_MSG);
55089+}
55090+
55091+/* hardlinks require at minimum create and link permission,
55092+ any additional privilege required is based on the
55093+ privilege of the file being linked to
55094+*/
55095+__u32
55096+gr_acl_handle_link(const struct dentry * new_dentry,
55097+ const struct dentry * parent_dentry,
55098+ const struct vfsmount * parent_mnt,
55099+ const struct dentry * old_dentry,
55100+ const struct vfsmount * old_mnt, const char *to)
55101+{
55102+ __u32 mode;
55103+ __u32 needmode = GR_CREATE | GR_LINK;
55104+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55105+
55106+ mode =
55107+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55108+ old_mnt);
55109+
55110+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55111+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55112+ return mode;
55113+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55114+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55115+ return 0;
55116+ } else if (unlikely((mode & needmode) != needmode))
55117+ return 0;
55118+
55119+ return 1;
55120+}
55121+
55122+__u32
55123+gr_acl_handle_symlink(const struct dentry * new_dentry,
55124+ const struct dentry * parent_dentry,
55125+ const struct vfsmount * parent_mnt, const char *from)
55126+{
55127+ __u32 needmode = GR_WRITE | GR_CREATE;
55128+ __u32 mode;
55129+
55130+ mode =
55131+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
55132+ GR_CREATE | GR_AUDIT_CREATE |
55133+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55134+
55135+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55136+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55137+ return mode;
55138+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55139+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55140+ return 0;
55141+ } else if (unlikely((mode & needmode) != needmode))
55142+ return 0;
55143+
55144+ return (GR_WRITE | GR_CREATE);
55145+}
55146+
55147+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)
55148+{
55149+ __u32 mode;
55150+
55151+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55152+
55153+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55154+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55155+ return mode;
55156+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55157+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55158+ return 0;
55159+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55160+ return 0;
55161+
55162+ return (reqmode);
55163+}
55164+
55165+__u32
55166+gr_acl_handle_mknod(const struct dentry * new_dentry,
55167+ const struct dentry * parent_dentry,
55168+ const struct vfsmount * parent_mnt,
55169+ const int mode)
55170+{
55171+ __u32 reqmode = GR_WRITE | GR_CREATE;
55172+ if (unlikely(mode & (S_ISUID | S_ISGID)))
55173+ reqmode |= GR_SETID;
55174+
55175+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55176+ reqmode, GR_MKNOD_ACL_MSG);
55177+}
55178+
55179+__u32
55180+gr_acl_handle_mkdir(const struct dentry *new_dentry,
55181+ const struct dentry *parent_dentry,
55182+ const struct vfsmount *parent_mnt)
55183+{
55184+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55185+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55186+}
55187+
55188+#define RENAME_CHECK_SUCCESS(old, new) \
55189+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55190+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55191+
55192+int
55193+gr_acl_handle_rename(struct dentry *new_dentry,
55194+ struct dentry *parent_dentry,
55195+ const struct vfsmount *parent_mnt,
55196+ struct dentry *old_dentry,
55197+ struct inode *old_parent_inode,
55198+ struct vfsmount *old_mnt, const char *newname)
55199+{
55200+ __u32 comp1, comp2;
55201+ int error = 0;
55202+
55203+ if (unlikely(!gr_acl_is_enabled()))
55204+ return 0;
55205+
55206+ if (!new_dentry->d_inode) {
55207+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55208+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55209+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55210+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55211+ GR_DELETE | GR_AUDIT_DELETE |
55212+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55213+ GR_SUPPRESS, old_mnt);
55214+ } else {
55215+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55216+ GR_CREATE | GR_DELETE |
55217+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55218+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55219+ GR_SUPPRESS, parent_mnt);
55220+ comp2 =
55221+ gr_search_file(old_dentry,
55222+ GR_READ | GR_WRITE | GR_AUDIT_READ |
55223+ GR_DELETE | GR_AUDIT_DELETE |
55224+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55225+ }
55226+
55227+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55228+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55229+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55230+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55231+ && !(comp2 & GR_SUPPRESS)) {
55232+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55233+ error = -EACCES;
55234+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55235+ error = -EACCES;
55236+
55237+ return error;
55238+}
55239+
55240+void
55241+gr_acl_handle_exit(void)
55242+{
55243+ u16 id;
55244+ char *rolename;
55245+ struct file *exec_file;
55246+
55247+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55248+ !(current->role->roletype & GR_ROLE_PERSIST))) {
55249+ id = current->acl_role_id;
55250+ rolename = current->role->rolename;
55251+ gr_set_acls(1);
55252+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55253+ }
55254+
55255+ write_lock(&grsec_exec_file_lock);
55256+ exec_file = current->exec_file;
55257+ current->exec_file = NULL;
55258+ write_unlock(&grsec_exec_file_lock);
55259+
55260+ if (exec_file)
55261+ fput(exec_file);
55262+}
55263+
55264+int
55265+gr_acl_handle_procpidmem(const struct task_struct *task)
55266+{
55267+ if (unlikely(!gr_acl_is_enabled()))
55268+ return 0;
55269+
55270+ if (task != current && task->acl->mode & GR_PROTPROCFD)
55271+ return -EACCES;
55272+
55273+ return 0;
55274+}
55275diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55276new file mode 100644
55277index 0000000..58800a7
55278--- /dev/null
55279+++ b/grsecurity/gracl_ip.c
55280@@ -0,0 +1,384 @@
55281+#include <linux/kernel.h>
55282+#include <asm/uaccess.h>
55283+#include <asm/errno.h>
55284+#include <net/sock.h>
55285+#include <linux/file.h>
55286+#include <linux/fs.h>
55287+#include <linux/net.h>
55288+#include <linux/in.h>
55289+#include <linux/skbuff.h>
55290+#include <linux/ip.h>
55291+#include <linux/udp.h>
55292+#include <linux/types.h>
55293+#include <linux/sched.h>
55294+#include <linux/netdevice.h>
55295+#include <linux/inetdevice.h>
55296+#include <linux/gracl.h>
55297+#include <linux/grsecurity.h>
55298+#include <linux/grinternal.h>
55299+
55300+#define GR_BIND 0x01
55301+#define GR_CONNECT 0x02
55302+#define GR_INVERT 0x04
55303+#define GR_BINDOVERRIDE 0x08
55304+#define GR_CONNECTOVERRIDE 0x10
55305+#define GR_SOCK_FAMILY 0x20
55306+
55307+static const char * gr_protocols[IPPROTO_MAX] = {
55308+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55309+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55310+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55311+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55312+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55313+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55314+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55315+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55316+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55317+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55318+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55319+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55320+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55321+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55322+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55323+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55324+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55325+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55326+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55327+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55328+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55329+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55330+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55331+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55332+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55333+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55334+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55335+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55336+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55337+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55338+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55339+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55340+ };
55341+
55342+static const char * gr_socktypes[SOCK_MAX] = {
55343+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55344+ "unknown:7", "unknown:8", "unknown:9", "packet"
55345+ };
55346+
55347+static const char * gr_sockfamilies[AF_MAX+1] = {
55348+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55349+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55350+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55351+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55352+ };
55353+
55354+const char *
55355+gr_proto_to_name(unsigned char proto)
55356+{
55357+ return gr_protocols[proto];
55358+}
55359+
55360+const char *
55361+gr_socktype_to_name(unsigned char type)
55362+{
55363+ return gr_socktypes[type];
55364+}
55365+
55366+const char *
55367+gr_sockfamily_to_name(unsigned char family)
55368+{
55369+ return gr_sockfamilies[family];
55370+}
55371+
55372+int
55373+gr_search_socket(const int domain, const int type, const int protocol)
55374+{
55375+ struct acl_subject_label *curr;
55376+ const struct cred *cred = current_cred();
55377+
55378+ if (unlikely(!gr_acl_is_enabled()))
55379+ goto exit;
55380+
55381+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
55382+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55383+ goto exit; // let the kernel handle it
55384+
55385+ curr = current->acl;
55386+
55387+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55388+ /* the family is allowed, if this is PF_INET allow it only if
55389+ the extra sock type/protocol checks pass */
55390+ if (domain == PF_INET)
55391+ goto inet_check;
55392+ goto exit;
55393+ } else {
55394+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55395+ __u32 fakeip = 0;
55396+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55397+ current->role->roletype, cred->uid,
55398+ cred->gid, current->exec_file ?
55399+ gr_to_filename(current->exec_file->f_path.dentry,
55400+ current->exec_file->f_path.mnt) :
55401+ curr->filename, curr->filename,
55402+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55403+ &current->signal->saved_ip);
55404+ goto exit;
55405+ }
55406+ goto exit_fail;
55407+ }
55408+
55409+inet_check:
55410+ /* the rest of this checking is for IPv4 only */
55411+ if (!curr->ips)
55412+ goto exit;
55413+
55414+ if ((curr->ip_type & (1 << type)) &&
55415+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55416+ goto exit;
55417+
55418+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55419+ /* we don't place acls on raw sockets , and sometimes
55420+ dgram/ip sockets are opened for ioctl and not
55421+ bind/connect, so we'll fake a bind learn log */
55422+ if (type == SOCK_RAW || type == SOCK_PACKET) {
55423+ __u32 fakeip = 0;
55424+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55425+ current->role->roletype, cred->uid,
55426+ cred->gid, current->exec_file ?
55427+ gr_to_filename(current->exec_file->f_path.dentry,
55428+ current->exec_file->f_path.mnt) :
55429+ curr->filename, curr->filename,
55430+ &fakeip, 0, type,
55431+ protocol, GR_CONNECT, &current->signal->saved_ip);
55432+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55433+ __u32 fakeip = 0;
55434+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55435+ current->role->roletype, cred->uid,
55436+ cred->gid, current->exec_file ?
55437+ gr_to_filename(current->exec_file->f_path.dentry,
55438+ current->exec_file->f_path.mnt) :
55439+ curr->filename, curr->filename,
55440+ &fakeip, 0, type,
55441+ protocol, GR_BIND, &current->signal->saved_ip);
55442+ }
55443+ /* we'll log when they use connect or bind */
55444+ goto exit;
55445+ }
55446+
55447+exit_fail:
55448+ if (domain == PF_INET)
55449+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55450+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
55451+ else
55452+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55453+ gr_socktype_to_name(type), protocol);
55454+
55455+ return 0;
55456+exit:
55457+ return 1;
55458+}
55459+
55460+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)
55461+{
55462+ if ((ip->mode & mode) &&
55463+ (ip_port >= ip->low) &&
55464+ (ip_port <= ip->high) &&
55465+ ((ntohl(ip_addr) & our_netmask) ==
55466+ (ntohl(our_addr) & our_netmask))
55467+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55468+ && (ip->type & (1 << type))) {
55469+ if (ip->mode & GR_INVERT)
55470+ return 2; // specifically denied
55471+ else
55472+ return 1; // allowed
55473+ }
55474+
55475+ return 0; // not specifically allowed, may continue parsing
55476+}
55477+
55478+static int
55479+gr_search_connectbind(const int full_mode, struct sock *sk,
55480+ struct sockaddr_in *addr, const int type)
55481+{
55482+ char iface[IFNAMSIZ] = {0};
55483+ struct acl_subject_label *curr;
55484+ struct acl_ip_label *ip;
55485+ struct inet_sock *isk;
55486+ struct net_device *dev;
55487+ struct in_device *idev;
55488+ unsigned long i;
55489+ int ret;
55490+ int mode = full_mode & (GR_BIND | GR_CONNECT);
55491+ __u32 ip_addr = 0;
55492+ __u32 our_addr;
55493+ __u32 our_netmask;
55494+ char *p;
55495+ __u16 ip_port = 0;
55496+ const struct cred *cred = current_cred();
55497+
55498+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55499+ return 0;
55500+
55501+ curr = current->acl;
55502+ isk = inet_sk(sk);
55503+
55504+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55505+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55506+ addr->sin_addr.s_addr = curr->inaddr_any_override;
55507+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55508+ struct sockaddr_in saddr;
55509+ int err;
55510+
55511+ saddr.sin_family = AF_INET;
55512+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
55513+ saddr.sin_port = isk->inet_sport;
55514+
55515+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55516+ if (err)
55517+ return err;
55518+
55519+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55520+ if (err)
55521+ return err;
55522+ }
55523+
55524+ if (!curr->ips)
55525+ return 0;
55526+
55527+ ip_addr = addr->sin_addr.s_addr;
55528+ ip_port = ntohs(addr->sin_port);
55529+
55530+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55531+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55532+ current->role->roletype, cred->uid,
55533+ cred->gid, current->exec_file ?
55534+ gr_to_filename(current->exec_file->f_path.dentry,
55535+ current->exec_file->f_path.mnt) :
55536+ curr->filename, curr->filename,
55537+ &ip_addr, ip_port, type,
55538+ sk->sk_protocol, mode, &current->signal->saved_ip);
55539+ return 0;
55540+ }
55541+
55542+ for (i = 0; i < curr->ip_num; i++) {
55543+ ip = *(curr->ips + i);
55544+ if (ip->iface != NULL) {
55545+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
55546+ p = strchr(iface, ':');
55547+ if (p != NULL)
55548+ *p = '\0';
55549+ dev = dev_get_by_name(sock_net(sk), iface);
55550+ if (dev == NULL)
55551+ continue;
55552+ idev = in_dev_get(dev);
55553+ if (idev == NULL) {
55554+ dev_put(dev);
55555+ continue;
55556+ }
55557+ rcu_read_lock();
55558+ for_ifa(idev) {
55559+ if (!strcmp(ip->iface, ifa->ifa_label)) {
55560+ our_addr = ifa->ifa_address;
55561+ our_netmask = 0xffffffff;
55562+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55563+ if (ret == 1) {
55564+ rcu_read_unlock();
55565+ in_dev_put(idev);
55566+ dev_put(dev);
55567+ return 0;
55568+ } else if (ret == 2) {
55569+ rcu_read_unlock();
55570+ in_dev_put(idev);
55571+ dev_put(dev);
55572+ goto denied;
55573+ }
55574+ }
55575+ } endfor_ifa(idev);
55576+ rcu_read_unlock();
55577+ in_dev_put(idev);
55578+ dev_put(dev);
55579+ } else {
55580+ our_addr = ip->addr;
55581+ our_netmask = ip->netmask;
55582+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55583+ if (ret == 1)
55584+ return 0;
55585+ else if (ret == 2)
55586+ goto denied;
55587+ }
55588+ }
55589+
55590+denied:
55591+ if (mode == GR_BIND)
55592+ 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));
55593+ else if (mode == GR_CONNECT)
55594+ 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));
55595+
55596+ return -EACCES;
55597+}
55598+
55599+int
55600+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55601+{
55602+ /* always allow disconnection of dgram sockets with connect */
55603+ if (addr->sin_family == AF_UNSPEC)
55604+ return 0;
55605+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55606+}
55607+
55608+int
55609+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55610+{
55611+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55612+}
55613+
55614+int gr_search_listen(struct socket *sock)
55615+{
55616+ struct sock *sk = sock->sk;
55617+ struct sockaddr_in addr;
55618+
55619+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55620+ addr.sin_port = inet_sk(sk)->inet_sport;
55621+
55622+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55623+}
55624+
55625+int gr_search_accept(struct socket *sock)
55626+{
55627+ struct sock *sk = sock->sk;
55628+ struct sockaddr_in addr;
55629+
55630+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55631+ addr.sin_port = inet_sk(sk)->inet_sport;
55632+
55633+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55634+}
55635+
55636+int
55637+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
55638+{
55639+ if (addr)
55640+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
55641+ else {
55642+ struct sockaddr_in sin;
55643+ const struct inet_sock *inet = inet_sk(sk);
55644+
55645+ sin.sin_addr.s_addr = inet->inet_daddr;
55646+ sin.sin_port = inet->inet_dport;
55647+
55648+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55649+ }
55650+}
55651+
55652+int
55653+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
55654+{
55655+ struct sockaddr_in sin;
55656+
55657+ if (unlikely(skb->len < sizeof (struct udphdr)))
55658+ return 0; // skip this packet
55659+
55660+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
55661+ sin.sin_port = udp_hdr(skb)->source;
55662+
55663+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55664+}
55665diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
55666new file mode 100644
55667index 0000000..25f54ef
55668--- /dev/null
55669+++ b/grsecurity/gracl_learn.c
55670@@ -0,0 +1,207 @@
55671+#include <linux/kernel.h>
55672+#include <linux/mm.h>
55673+#include <linux/sched.h>
55674+#include <linux/poll.h>
55675+#include <linux/string.h>
55676+#include <linux/file.h>
55677+#include <linux/types.h>
55678+#include <linux/vmalloc.h>
55679+#include <linux/grinternal.h>
55680+
55681+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
55682+ size_t count, loff_t *ppos);
55683+extern int gr_acl_is_enabled(void);
55684+
55685+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
55686+static int gr_learn_attached;
55687+
55688+/* use a 512k buffer */
55689+#define LEARN_BUFFER_SIZE (512 * 1024)
55690+
55691+static DEFINE_SPINLOCK(gr_learn_lock);
55692+static DEFINE_MUTEX(gr_learn_user_mutex);
55693+
55694+/* we need to maintain two buffers, so that the kernel context of grlearn
55695+ uses a semaphore around the userspace copying, and the other kernel contexts
55696+ use a spinlock when copying into the buffer, since they cannot sleep
55697+*/
55698+static char *learn_buffer;
55699+static char *learn_buffer_user;
55700+static int learn_buffer_len;
55701+static int learn_buffer_user_len;
55702+
55703+static ssize_t
55704+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
55705+{
55706+ DECLARE_WAITQUEUE(wait, current);
55707+ ssize_t retval = 0;
55708+
55709+ add_wait_queue(&learn_wait, &wait);
55710+ set_current_state(TASK_INTERRUPTIBLE);
55711+ do {
55712+ mutex_lock(&gr_learn_user_mutex);
55713+ spin_lock(&gr_learn_lock);
55714+ if (learn_buffer_len)
55715+ break;
55716+ spin_unlock(&gr_learn_lock);
55717+ mutex_unlock(&gr_learn_user_mutex);
55718+ if (file->f_flags & O_NONBLOCK) {
55719+ retval = -EAGAIN;
55720+ goto out;
55721+ }
55722+ if (signal_pending(current)) {
55723+ retval = -ERESTARTSYS;
55724+ goto out;
55725+ }
55726+
55727+ schedule();
55728+ } while (1);
55729+
55730+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
55731+ learn_buffer_user_len = learn_buffer_len;
55732+ retval = learn_buffer_len;
55733+ learn_buffer_len = 0;
55734+
55735+ spin_unlock(&gr_learn_lock);
55736+
55737+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
55738+ retval = -EFAULT;
55739+
55740+ mutex_unlock(&gr_learn_user_mutex);
55741+out:
55742+ set_current_state(TASK_RUNNING);
55743+ remove_wait_queue(&learn_wait, &wait);
55744+ return retval;
55745+}
55746+
55747+static unsigned int
55748+poll_learn(struct file * file, poll_table * wait)
55749+{
55750+ poll_wait(file, &learn_wait, wait);
55751+
55752+ if (learn_buffer_len)
55753+ return (POLLIN | POLLRDNORM);
55754+
55755+ return 0;
55756+}
55757+
55758+void
55759+gr_clear_learn_entries(void)
55760+{
55761+ char *tmp;
55762+
55763+ mutex_lock(&gr_learn_user_mutex);
55764+ spin_lock(&gr_learn_lock);
55765+ tmp = learn_buffer;
55766+ learn_buffer = NULL;
55767+ spin_unlock(&gr_learn_lock);
55768+ if (tmp)
55769+ vfree(tmp);
55770+ if (learn_buffer_user != NULL) {
55771+ vfree(learn_buffer_user);
55772+ learn_buffer_user = NULL;
55773+ }
55774+ learn_buffer_len = 0;
55775+ mutex_unlock(&gr_learn_user_mutex);
55776+
55777+ return;
55778+}
55779+
55780+void
55781+gr_add_learn_entry(const char *fmt, ...)
55782+{
55783+ va_list args;
55784+ unsigned int len;
55785+
55786+ if (!gr_learn_attached)
55787+ return;
55788+
55789+ spin_lock(&gr_learn_lock);
55790+
55791+ /* leave a gap at the end so we know when it's "full" but don't have to
55792+ compute the exact length of the string we're trying to append
55793+ */
55794+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
55795+ spin_unlock(&gr_learn_lock);
55796+ wake_up_interruptible(&learn_wait);
55797+ return;
55798+ }
55799+ if (learn_buffer == NULL) {
55800+ spin_unlock(&gr_learn_lock);
55801+ return;
55802+ }
55803+
55804+ va_start(args, fmt);
55805+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
55806+ va_end(args);
55807+
55808+ learn_buffer_len += len + 1;
55809+
55810+ spin_unlock(&gr_learn_lock);
55811+ wake_up_interruptible(&learn_wait);
55812+
55813+ return;
55814+}
55815+
55816+static int
55817+open_learn(struct inode *inode, struct file *file)
55818+{
55819+ if (file->f_mode & FMODE_READ && gr_learn_attached)
55820+ return -EBUSY;
55821+ if (file->f_mode & FMODE_READ) {
55822+ int retval = 0;
55823+ mutex_lock(&gr_learn_user_mutex);
55824+ if (learn_buffer == NULL)
55825+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
55826+ if (learn_buffer_user == NULL)
55827+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
55828+ if (learn_buffer == NULL) {
55829+ retval = -ENOMEM;
55830+ goto out_error;
55831+ }
55832+ if (learn_buffer_user == NULL) {
55833+ retval = -ENOMEM;
55834+ goto out_error;
55835+ }
55836+ learn_buffer_len = 0;
55837+ learn_buffer_user_len = 0;
55838+ gr_learn_attached = 1;
55839+out_error:
55840+ mutex_unlock(&gr_learn_user_mutex);
55841+ return retval;
55842+ }
55843+ return 0;
55844+}
55845+
55846+static int
55847+close_learn(struct inode *inode, struct file *file)
55848+{
55849+ if (file->f_mode & FMODE_READ) {
55850+ char *tmp = NULL;
55851+ mutex_lock(&gr_learn_user_mutex);
55852+ spin_lock(&gr_learn_lock);
55853+ tmp = learn_buffer;
55854+ learn_buffer = NULL;
55855+ spin_unlock(&gr_learn_lock);
55856+ if (tmp)
55857+ vfree(tmp);
55858+ if (learn_buffer_user != NULL) {
55859+ vfree(learn_buffer_user);
55860+ learn_buffer_user = NULL;
55861+ }
55862+ learn_buffer_len = 0;
55863+ learn_buffer_user_len = 0;
55864+ gr_learn_attached = 0;
55865+ mutex_unlock(&gr_learn_user_mutex);
55866+ }
55867+
55868+ return 0;
55869+}
55870+
55871+const struct file_operations grsec_fops = {
55872+ .read = read_learn,
55873+ .write = write_grsec_handler,
55874+ .open = open_learn,
55875+ .release = close_learn,
55876+ .poll = poll_learn,
55877+};
55878diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
55879new file mode 100644
55880index 0000000..39645c9
55881--- /dev/null
55882+++ b/grsecurity/gracl_res.c
55883@@ -0,0 +1,68 @@
55884+#include <linux/kernel.h>
55885+#include <linux/sched.h>
55886+#include <linux/gracl.h>
55887+#include <linux/grinternal.h>
55888+
55889+static const char *restab_log[] = {
55890+ [RLIMIT_CPU] = "RLIMIT_CPU",
55891+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
55892+ [RLIMIT_DATA] = "RLIMIT_DATA",
55893+ [RLIMIT_STACK] = "RLIMIT_STACK",
55894+ [RLIMIT_CORE] = "RLIMIT_CORE",
55895+ [RLIMIT_RSS] = "RLIMIT_RSS",
55896+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
55897+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
55898+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
55899+ [RLIMIT_AS] = "RLIMIT_AS",
55900+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
55901+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
55902+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
55903+ [RLIMIT_NICE] = "RLIMIT_NICE",
55904+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
55905+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
55906+ [GR_CRASH_RES] = "RLIMIT_CRASH"
55907+};
55908+
55909+void
55910+gr_log_resource(const struct task_struct *task,
55911+ const int res, const unsigned long wanted, const int gt)
55912+{
55913+ const struct cred *cred;
55914+ unsigned long rlim;
55915+
55916+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
55917+ return;
55918+
55919+ // not yet supported resource
55920+ if (unlikely(!restab_log[res]))
55921+ return;
55922+
55923+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
55924+ rlim = task_rlimit_max(task, res);
55925+ else
55926+ rlim = task_rlimit(task, res);
55927+
55928+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
55929+ return;
55930+
55931+ rcu_read_lock();
55932+ cred = __task_cred(task);
55933+
55934+ if (res == RLIMIT_NPROC &&
55935+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
55936+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
55937+ goto out_rcu_unlock;
55938+ else if (res == RLIMIT_MEMLOCK &&
55939+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
55940+ goto out_rcu_unlock;
55941+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
55942+ goto out_rcu_unlock;
55943+ rcu_read_unlock();
55944+
55945+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
55946+
55947+ return;
55948+out_rcu_unlock:
55949+ rcu_read_unlock();
55950+ return;
55951+}
55952diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
55953new file mode 100644
55954index 0000000..5556be3
55955--- /dev/null
55956+++ b/grsecurity/gracl_segv.c
55957@@ -0,0 +1,299 @@
55958+#include <linux/kernel.h>
55959+#include <linux/mm.h>
55960+#include <asm/uaccess.h>
55961+#include <asm/errno.h>
55962+#include <asm/mman.h>
55963+#include <net/sock.h>
55964+#include <linux/file.h>
55965+#include <linux/fs.h>
55966+#include <linux/net.h>
55967+#include <linux/in.h>
55968+#include <linux/slab.h>
55969+#include <linux/types.h>
55970+#include <linux/sched.h>
55971+#include <linux/timer.h>
55972+#include <linux/gracl.h>
55973+#include <linux/grsecurity.h>
55974+#include <linux/grinternal.h>
55975+
55976+static struct crash_uid *uid_set;
55977+static unsigned short uid_used;
55978+static DEFINE_SPINLOCK(gr_uid_lock);
55979+extern rwlock_t gr_inode_lock;
55980+extern struct acl_subject_label *
55981+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
55982+ struct acl_role_label *role);
55983+
55984+#ifdef CONFIG_BTRFS_FS
55985+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55986+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55987+#endif
55988+
55989+static inline dev_t __get_dev(const struct dentry *dentry)
55990+{
55991+#ifdef CONFIG_BTRFS_FS
55992+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55993+ return get_btrfs_dev_from_inode(dentry->d_inode);
55994+ else
55995+#endif
55996+ return dentry->d_inode->i_sb->s_dev;
55997+}
55998+
55999+int
56000+gr_init_uidset(void)
56001+{
56002+ uid_set =
56003+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56004+ uid_used = 0;
56005+
56006+ return uid_set ? 1 : 0;
56007+}
56008+
56009+void
56010+gr_free_uidset(void)
56011+{
56012+ if (uid_set)
56013+ kfree(uid_set);
56014+
56015+ return;
56016+}
56017+
56018+int
56019+gr_find_uid(const uid_t uid)
56020+{
56021+ struct crash_uid *tmp = uid_set;
56022+ uid_t buid;
56023+ int low = 0, high = uid_used - 1, mid;
56024+
56025+ while (high >= low) {
56026+ mid = (low + high) >> 1;
56027+ buid = tmp[mid].uid;
56028+ if (buid == uid)
56029+ return mid;
56030+ if (buid > uid)
56031+ high = mid - 1;
56032+ if (buid < uid)
56033+ low = mid + 1;
56034+ }
56035+
56036+ return -1;
56037+}
56038+
56039+static __inline__ void
56040+gr_insertsort(void)
56041+{
56042+ unsigned short i, j;
56043+ struct crash_uid index;
56044+
56045+ for (i = 1; i < uid_used; i++) {
56046+ index = uid_set[i];
56047+ j = i;
56048+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56049+ uid_set[j] = uid_set[j - 1];
56050+ j--;
56051+ }
56052+ uid_set[j] = index;
56053+ }
56054+
56055+ return;
56056+}
56057+
56058+static __inline__ void
56059+gr_insert_uid(const uid_t uid, const unsigned long expires)
56060+{
56061+ int loc;
56062+
56063+ if (uid_used == GR_UIDTABLE_MAX)
56064+ return;
56065+
56066+ loc = gr_find_uid(uid);
56067+
56068+ if (loc >= 0) {
56069+ uid_set[loc].expires = expires;
56070+ return;
56071+ }
56072+
56073+ uid_set[uid_used].uid = uid;
56074+ uid_set[uid_used].expires = expires;
56075+ uid_used++;
56076+
56077+ gr_insertsort();
56078+
56079+ return;
56080+}
56081+
56082+void
56083+gr_remove_uid(const unsigned short loc)
56084+{
56085+ unsigned short i;
56086+
56087+ for (i = loc + 1; i < uid_used; i++)
56088+ uid_set[i - 1] = uid_set[i];
56089+
56090+ uid_used--;
56091+
56092+ return;
56093+}
56094+
56095+int
56096+gr_check_crash_uid(const uid_t uid)
56097+{
56098+ int loc;
56099+ int ret = 0;
56100+
56101+ if (unlikely(!gr_acl_is_enabled()))
56102+ return 0;
56103+
56104+ spin_lock(&gr_uid_lock);
56105+ loc = gr_find_uid(uid);
56106+
56107+ if (loc < 0)
56108+ goto out_unlock;
56109+
56110+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
56111+ gr_remove_uid(loc);
56112+ else
56113+ ret = 1;
56114+
56115+out_unlock:
56116+ spin_unlock(&gr_uid_lock);
56117+ return ret;
56118+}
56119+
56120+static __inline__ int
56121+proc_is_setxid(const struct cred *cred)
56122+{
56123+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
56124+ cred->uid != cred->fsuid)
56125+ return 1;
56126+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56127+ cred->gid != cred->fsgid)
56128+ return 1;
56129+
56130+ return 0;
56131+}
56132+
56133+extern int gr_fake_force_sig(int sig, struct task_struct *t);
56134+
56135+void
56136+gr_handle_crash(struct task_struct *task, const int sig)
56137+{
56138+ struct acl_subject_label *curr;
56139+ struct task_struct *tsk, *tsk2;
56140+ const struct cred *cred;
56141+ const struct cred *cred2;
56142+
56143+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56144+ return;
56145+
56146+ if (unlikely(!gr_acl_is_enabled()))
56147+ return;
56148+
56149+ curr = task->acl;
56150+
56151+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
56152+ return;
56153+
56154+ if (time_before_eq(curr->expires, get_seconds())) {
56155+ curr->expires = 0;
56156+ curr->crashes = 0;
56157+ }
56158+
56159+ curr->crashes++;
56160+
56161+ if (!curr->expires)
56162+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56163+
56164+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56165+ time_after(curr->expires, get_seconds())) {
56166+ rcu_read_lock();
56167+ cred = __task_cred(task);
56168+ if (cred->uid && proc_is_setxid(cred)) {
56169+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56170+ spin_lock(&gr_uid_lock);
56171+ gr_insert_uid(cred->uid, curr->expires);
56172+ spin_unlock(&gr_uid_lock);
56173+ curr->expires = 0;
56174+ curr->crashes = 0;
56175+ read_lock(&tasklist_lock);
56176+ do_each_thread(tsk2, tsk) {
56177+ cred2 = __task_cred(tsk);
56178+ if (tsk != task && cred2->uid == cred->uid)
56179+ gr_fake_force_sig(SIGKILL, tsk);
56180+ } while_each_thread(tsk2, tsk);
56181+ read_unlock(&tasklist_lock);
56182+ } else {
56183+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56184+ read_lock(&tasklist_lock);
56185+ read_lock(&grsec_exec_file_lock);
56186+ do_each_thread(tsk2, tsk) {
56187+ if (likely(tsk != task)) {
56188+ // if this thread has the same subject as the one that triggered
56189+ // RES_CRASH and it's the same binary, kill it
56190+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56191+ gr_fake_force_sig(SIGKILL, tsk);
56192+ }
56193+ } while_each_thread(tsk2, tsk);
56194+ read_unlock(&grsec_exec_file_lock);
56195+ read_unlock(&tasklist_lock);
56196+ }
56197+ rcu_read_unlock();
56198+ }
56199+
56200+ return;
56201+}
56202+
56203+int
56204+gr_check_crash_exec(const struct file *filp)
56205+{
56206+ struct acl_subject_label *curr;
56207+
56208+ if (unlikely(!gr_acl_is_enabled()))
56209+ return 0;
56210+
56211+ read_lock(&gr_inode_lock);
56212+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56213+ __get_dev(filp->f_path.dentry),
56214+ current->role);
56215+ read_unlock(&gr_inode_lock);
56216+
56217+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56218+ (!curr->crashes && !curr->expires))
56219+ return 0;
56220+
56221+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56222+ time_after(curr->expires, get_seconds()))
56223+ return 1;
56224+ else if (time_before_eq(curr->expires, get_seconds())) {
56225+ curr->crashes = 0;
56226+ curr->expires = 0;
56227+ }
56228+
56229+ return 0;
56230+}
56231+
56232+void
56233+gr_handle_alertkill(struct task_struct *task)
56234+{
56235+ struct acl_subject_label *curracl;
56236+ __u32 curr_ip;
56237+ struct task_struct *p, *p2;
56238+
56239+ if (unlikely(!gr_acl_is_enabled()))
56240+ return;
56241+
56242+ curracl = task->acl;
56243+ curr_ip = task->signal->curr_ip;
56244+
56245+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56246+ read_lock(&tasklist_lock);
56247+ do_each_thread(p2, p) {
56248+ if (p->signal->curr_ip == curr_ip)
56249+ gr_fake_force_sig(SIGKILL, p);
56250+ } while_each_thread(p2, p);
56251+ read_unlock(&tasklist_lock);
56252+ } else if (curracl->mode & GR_KILLPROC)
56253+ gr_fake_force_sig(SIGKILL, task);
56254+
56255+ return;
56256+}
56257diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56258new file mode 100644
56259index 0000000..9d83a69
56260--- /dev/null
56261+++ b/grsecurity/gracl_shm.c
56262@@ -0,0 +1,40 @@
56263+#include <linux/kernel.h>
56264+#include <linux/mm.h>
56265+#include <linux/sched.h>
56266+#include <linux/file.h>
56267+#include <linux/ipc.h>
56268+#include <linux/gracl.h>
56269+#include <linux/grsecurity.h>
56270+#include <linux/grinternal.h>
56271+
56272+int
56273+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56274+ const time_t shm_createtime, const uid_t cuid, const int shmid)
56275+{
56276+ struct task_struct *task;
56277+
56278+ if (!gr_acl_is_enabled())
56279+ return 1;
56280+
56281+ rcu_read_lock();
56282+ read_lock(&tasklist_lock);
56283+
56284+ task = find_task_by_vpid(shm_cprid);
56285+
56286+ if (unlikely(!task))
56287+ task = find_task_by_vpid(shm_lapid);
56288+
56289+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56290+ (task->pid == shm_lapid)) &&
56291+ (task->acl->mode & GR_PROTSHM) &&
56292+ (task->acl != current->acl))) {
56293+ read_unlock(&tasklist_lock);
56294+ rcu_read_unlock();
56295+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56296+ return 0;
56297+ }
56298+ read_unlock(&tasklist_lock);
56299+ rcu_read_unlock();
56300+
56301+ return 1;
56302+}
56303diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56304new file mode 100644
56305index 0000000..bc0be01
56306--- /dev/null
56307+++ b/grsecurity/grsec_chdir.c
56308@@ -0,0 +1,19 @@
56309+#include <linux/kernel.h>
56310+#include <linux/sched.h>
56311+#include <linux/fs.h>
56312+#include <linux/file.h>
56313+#include <linux/grsecurity.h>
56314+#include <linux/grinternal.h>
56315+
56316+void
56317+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56318+{
56319+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56320+ if ((grsec_enable_chdir && grsec_enable_group &&
56321+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56322+ !grsec_enable_group)) {
56323+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56324+ }
56325+#endif
56326+ return;
56327+}
56328diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56329new file mode 100644
56330index 0000000..9807ee2
56331--- /dev/null
56332+++ b/grsecurity/grsec_chroot.c
56333@@ -0,0 +1,368 @@
56334+#include <linux/kernel.h>
56335+#include <linux/module.h>
56336+#include <linux/sched.h>
56337+#include <linux/file.h>
56338+#include <linux/fs.h>
56339+#include <linux/mount.h>
56340+#include <linux/types.h>
56341+#include "../fs/mount.h"
56342+#include <linux/grsecurity.h>
56343+#include <linux/grinternal.h>
56344+
56345+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56346+{
56347+#ifdef CONFIG_GRKERNSEC
56348+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56349+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56350+ task->gr_is_chrooted = 1;
56351+ else
56352+ task->gr_is_chrooted = 0;
56353+
56354+ task->gr_chroot_dentry = path->dentry;
56355+#endif
56356+ return;
56357+}
56358+
56359+void gr_clear_chroot_entries(struct task_struct *task)
56360+{
56361+#ifdef CONFIG_GRKERNSEC
56362+ task->gr_is_chrooted = 0;
56363+ task->gr_chroot_dentry = NULL;
56364+#endif
56365+ return;
56366+}
56367+
56368+int
56369+gr_handle_chroot_unix(const pid_t pid)
56370+{
56371+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56372+ struct task_struct *p;
56373+
56374+ if (unlikely(!grsec_enable_chroot_unix))
56375+ return 1;
56376+
56377+ if (likely(!proc_is_chrooted(current)))
56378+ return 1;
56379+
56380+ rcu_read_lock();
56381+ read_lock(&tasklist_lock);
56382+ p = find_task_by_vpid_unrestricted(pid);
56383+ if (unlikely(p && !have_same_root(current, p))) {
56384+ read_unlock(&tasklist_lock);
56385+ rcu_read_unlock();
56386+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56387+ return 0;
56388+ }
56389+ read_unlock(&tasklist_lock);
56390+ rcu_read_unlock();
56391+#endif
56392+ return 1;
56393+}
56394+
56395+int
56396+gr_handle_chroot_nice(void)
56397+{
56398+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56399+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56400+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56401+ return -EPERM;
56402+ }
56403+#endif
56404+ return 0;
56405+}
56406+
56407+int
56408+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56409+{
56410+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56411+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56412+ && proc_is_chrooted(current)) {
56413+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56414+ return -EACCES;
56415+ }
56416+#endif
56417+ return 0;
56418+}
56419+
56420+int
56421+gr_handle_chroot_rawio(const struct inode *inode)
56422+{
56423+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56424+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56425+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56426+ return 1;
56427+#endif
56428+ return 0;
56429+}
56430+
56431+int
56432+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56433+{
56434+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56435+ struct task_struct *p;
56436+ int ret = 0;
56437+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56438+ return ret;
56439+
56440+ read_lock(&tasklist_lock);
56441+ do_each_pid_task(pid, type, p) {
56442+ if (!have_same_root(current, p)) {
56443+ ret = 1;
56444+ goto out;
56445+ }
56446+ } while_each_pid_task(pid, type, p);
56447+out:
56448+ read_unlock(&tasklist_lock);
56449+ return ret;
56450+#endif
56451+ return 0;
56452+}
56453+
56454+int
56455+gr_pid_is_chrooted(struct task_struct *p)
56456+{
56457+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56458+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56459+ return 0;
56460+
56461+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56462+ !have_same_root(current, p)) {
56463+ return 1;
56464+ }
56465+#endif
56466+ return 0;
56467+}
56468+
56469+EXPORT_SYMBOL(gr_pid_is_chrooted);
56470+
56471+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56472+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56473+{
56474+ struct path path, currentroot;
56475+ int ret = 0;
56476+
56477+ path.dentry = (struct dentry *)u_dentry;
56478+ path.mnt = (struct vfsmount *)u_mnt;
56479+ get_fs_root(current->fs, &currentroot);
56480+ if (path_is_under(&path, &currentroot))
56481+ ret = 1;
56482+ path_put(&currentroot);
56483+
56484+ return ret;
56485+}
56486+#endif
56487+
56488+int
56489+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56490+{
56491+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56492+ if (!grsec_enable_chroot_fchdir)
56493+ return 1;
56494+
56495+ if (!proc_is_chrooted(current))
56496+ return 1;
56497+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56498+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56499+ return 0;
56500+ }
56501+#endif
56502+ return 1;
56503+}
56504+
56505+int
56506+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56507+ const time_t shm_createtime)
56508+{
56509+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56510+ struct task_struct *p;
56511+ time_t starttime;
56512+
56513+ if (unlikely(!grsec_enable_chroot_shmat))
56514+ return 1;
56515+
56516+ if (likely(!proc_is_chrooted(current)))
56517+ return 1;
56518+
56519+ rcu_read_lock();
56520+ read_lock(&tasklist_lock);
56521+
56522+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56523+ starttime = p->start_time.tv_sec;
56524+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56525+ if (have_same_root(current, p)) {
56526+ goto allow;
56527+ } else {
56528+ read_unlock(&tasklist_lock);
56529+ rcu_read_unlock();
56530+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56531+ return 0;
56532+ }
56533+ }
56534+ /* creator exited, pid reuse, fall through to next check */
56535+ }
56536+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56537+ if (unlikely(!have_same_root(current, p))) {
56538+ read_unlock(&tasklist_lock);
56539+ rcu_read_unlock();
56540+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56541+ return 0;
56542+ }
56543+ }
56544+
56545+allow:
56546+ read_unlock(&tasklist_lock);
56547+ rcu_read_unlock();
56548+#endif
56549+ return 1;
56550+}
56551+
56552+void
56553+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56554+{
56555+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56556+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56557+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56558+#endif
56559+ return;
56560+}
56561+
56562+int
56563+gr_handle_chroot_mknod(const struct dentry *dentry,
56564+ const struct vfsmount *mnt, const int mode)
56565+{
56566+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56567+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56568+ proc_is_chrooted(current)) {
56569+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56570+ return -EPERM;
56571+ }
56572+#endif
56573+ return 0;
56574+}
56575+
56576+int
56577+gr_handle_chroot_mount(const struct dentry *dentry,
56578+ const struct vfsmount *mnt, const char *dev_name)
56579+{
56580+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56581+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56582+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56583+ return -EPERM;
56584+ }
56585+#endif
56586+ return 0;
56587+}
56588+
56589+int
56590+gr_handle_chroot_pivot(void)
56591+{
56592+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56593+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56594+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56595+ return -EPERM;
56596+ }
56597+#endif
56598+ return 0;
56599+}
56600+
56601+int
56602+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56603+{
56604+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56605+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56606+ !gr_is_outside_chroot(dentry, mnt)) {
56607+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56608+ return -EPERM;
56609+ }
56610+#endif
56611+ return 0;
56612+}
56613+
56614+extern const char *captab_log[];
56615+extern int captab_log_entries;
56616+
56617+int
56618+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56619+{
56620+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56621+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56622+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56623+ if (cap_raised(chroot_caps, cap)) {
56624+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
56625+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
56626+ }
56627+ return 0;
56628+ }
56629+ }
56630+#endif
56631+ return 1;
56632+}
56633+
56634+int
56635+gr_chroot_is_capable(const int cap)
56636+{
56637+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56638+ return gr_task_chroot_is_capable(current, current_cred(), cap);
56639+#endif
56640+ return 1;
56641+}
56642+
56643+int
56644+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
56645+{
56646+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56647+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56648+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56649+ if (cap_raised(chroot_caps, cap)) {
56650+ return 0;
56651+ }
56652+ }
56653+#endif
56654+ return 1;
56655+}
56656+
56657+int
56658+gr_chroot_is_capable_nolog(const int cap)
56659+{
56660+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56661+ return gr_task_chroot_is_capable_nolog(current, cap);
56662+#endif
56663+ return 1;
56664+}
56665+
56666+int
56667+gr_handle_chroot_sysctl(const int op)
56668+{
56669+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56670+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
56671+ proc_is_chrooted(current))
56672+ return -EACCES;
56673+#endif
56674+ return 0;
56675+}
56676+
56677+void
56678+gr_handle_chroot_chdir(struct path *path)
56679+{
56680+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56681+ if (grsec_enable_chroot_chdir)
56682+ set_fs_pwd(current->fs, path);
56683+#endif
56684+ return;
56685+}
56686+
56687+int
56688+gr_handle_chroot_chmod(const struct dentry *dentry,
56689+ const struct vfsmount *mnt, const int mode)
56690+{
56691+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56692+ /* allow chmod +s on directories, but not files */
56693+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
56694+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
56695+ proc_is_chrooted(current)) {
56696+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
56697+ return -EPERM;
56698+ }
56699+#endif
56700+ return 0;
56701+}
56702diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
56703new file mode 100644
56704index 0000000..213ad8b
56705--- /dev/null
56706+++ b/grsecurity/grsec_disabled.c
56707@@ -0,0 +1,437 @@
56708+#include <linux/kernel.h>
56709+#include <linux/module.h>
56710+#include <linux/sched.h>
56711+#include <linux/file.h>
56712+#include <linux/fs.h>
56713+#include <linux/kdev_t.h>
56714+#include <linux/net.h>
56715+#include <linux/in.h>
56716+#include <linux/ip.h>
56717+#include <linux/skbuff.h>
56718+#include <linux/sysctl.h>
56719+
56720+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56721+void
56722+pax_set_initial_flags(struct linux_binprm *bprm)
56723+{
56724+ return;
56725+}
56726+#endif
56727+
56728+#ifdef CONFIG_SYSCTL
56729+__u32
56730+gr_handle_sysctl(const struct ctl_table * table, const int op)
56731+{
56732+ return 0;
56733+}
56734+#endif
56735+
56736+#ifdef CONFIG_TASKSTATS
56737+int gr_is_taskstats_denied(int pid)
56738+{
56739+ return 0;
56740+}
56741+#endif
56742+
56743+int
56744+gr_acl_is_enabled(void)
56745+{
56746+ return 0;
56747+}
56748+
56749+void
56750+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56751+{
56752+ return;
56753+}
56754+
56755+int
56756+gr_handle_rawio(const struct inode *inode)
56757+{
56758+ return 0;
56759+}
56760+
56761+void
56762+gr_acl_handle_psacct(struct task_struct *task, const long code)
56763+{
56764+ return;
56765+}
56766+
56767+int
56768+gr_handle_ptrace(struct task_struct *task, const long request)
56769+{
56770+ return 0;
56771+}
56772+
56773+int
56774+gr_handle_proc_ptrace(struct task_struct *task)
56775+{
56776+ return 0;
56777+}
56778+
56779+void
56780+gr_learn_resource(const struct task_struct *task,
56781+ const int res, const unsigned long wanted, const int gt)
56782+{
56783+ return;
56784+}
56785+
56786+int
56787+gr_set_acls(const int type)
56788+{
56789+ return 0;
56790+}
56791+
56792+int
56793+gr_check_hidden_task(const struct task_struct *tsk)
56794+{
56795+ return 0;
56796+}
56797+
56798+int
56799+gr_check_protected_task(const struct task_struct *task)
56800+{
56801+ return 0;
56802+}
56803+
56804+int
56805+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56806+{
56807+ return 0;
56808+}
56809+
56810+void
56811+gr_copy_label(struct task_struct *tsk)
56812+{
56813+ return;
56814+}
56815+
56816+void
56817+gr_set_pax_flags(struct task_struct *task)
56818+{
56819+ return;
56820+}
56821+
56822+int
56823+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56824+ const int unsafe_share)
56825+{
56826+ return 0;
56827+}
56828+
56829+void
56830+gr_handle_delete(const ino_t ino, const dev_t dev)
56831+{
56832+ return;
56833+}
56834+
56835+void
56836+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56837+{
56838+ return;
56839+}
56840+
56841+void
56842+gr_handle_crash(struct task_struct *task, const int sig)
56843+{
56844+ return;
56845+}
56846+
56847+int
56848+gr_check_crash_exec(const struct file *filp)
56849+{
56850+ return 0;
56851+}
56852+
56853+int
56854+gr_check_crash_uid(const uid_t uid)
56855+{
56856+ return 0;
56857+}
56858+
56859+void
56860+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56861+ struct dentry *old_dentry,
56862+ struct dentry *new_dentry,
56863+ struct vfsmount *mnt, const __u8 replace)
56864+{
56865+ return;
56866+}
56867+
56868+int
56869+gr_search_socket(const int family, const int type, const int protocol)
56870+{
56871+ return 1;
56872+}
56873+
56874+int
56875+gr_search_connectbind(const int mode, const struct socket *sock,
56876+ const struct sockaddr_in *addr)
56877+{
56878+ return 0;
56879+}
56880+
56881+void
56882+gr_handle_alertkill(struct task_struct *task)
56883+{
56884+ return;
56885+}
56886+
56887+__u32
56888+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
56889+{
56890+ return 1;
56891+}
56892+
56893+__u32
56894+gr_acl_handle_hidden_file(const struct dentry * dentry,
56895+ const struct vfsmount * mnt)
56896+{
56897+ return 1;
56898+}
56899+
56900+__u32
56901+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56902+ int acc_mode)
56903+{
56904+ return 1;
56905+}
56906+
56907+__u32
56908+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56909+{
56910+ return 1;
56911+}
56912+
56913+__u32
56914+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
56915+{
56916+ return 1;
56917+}
56918+
56919+int
56920+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
56921+ unsigned int *vm_flags)
56922+{
56923+ return 1;
56924+}
56925+
56926+__u32
56927+gr_acl_handle_truncate(const struct dentry * dentry,
56928+ const struct vfsmount * mnt)
56929+{
56930+ return 1;
56931+}
56932+
56933+__u32
56934+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
56935+{
56936+ return 1;
56937+}
56938+
56939+__u32
56940+gr_acl_handle_access(const struct dentry * dentry,
56941+ const struct vfsmount * mnt, const int fmode)
56942+{
56943+ return 1;
56944+}
56945+
56946+__u32
56947+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
56948+ umode_t *mode)
56949+{
56950+ return 1;
56951+}
56952+
56953+__u32
56954+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
56955+{
56956+ return 1;
56957+}
56958+
56959+__u32
56960+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
56961+{
56962+ return 1;
56963+}
56964+
56965+void
56966+grsecurity_init(void)
56967+{
56968+ return;
56969+}
56970+
56971+umode_t gr_acl_umask(void)
56972+{
56973+ return 0;
56974+}
56975+
56976+__u32
56977+gr_acl_handle_mknod(const struct dentry * new_dentry,
56978+ const struct dentry * parent_dentry,
56979+ const struct vfsmount * parent_mnt,
56980+ const int mode)
56981+{
56982+ return 1;
56983+}
56984+
56985+__u32
56986+gr_acl_handle_mkdir(const struct dentry * new_dentry,
56987+ const struct dentry * parent_dentry,
56988+ const struct vfsmount * parent_mnt)
56989+{
56990+ return 1;
56991+}
56992+
56993+__u32
56994+gr_acl_handle_symlink(const struct dentry * new_dentry,
56995+ const struct dentry * parent_dentry,
56996+ const struct vfsmount * parent_mnt, const char *from)
56997+{
56998+ return 1;
56999+}
57000+
57001+__u32
57002+gr_acl_handle_link(const struct dentry * new_dentry,
57003+ const struct dentry * parent_dentry,
57004+ const struct vfsmount * parent_mnt,
57005+ const struct dentry * old_dentry,
57006+ const struct vfsmount * old_mnt, const char *to)
57007+{
57008+ return 1;
57009+}
57010+
57011+int
57012+gr_acl_handle_rename(const struct dentry *new_dentry,
57013+ const struct dentry *parent_dentry,
57014+ const struct vfsmount *parent_mnt,
57015+ const struct dentry *old_dentry,
57016+ const struct inode *old_parent_inode,
57017+ const struct vfsmount *old_mnt, const char *newname)
57018+{
57019+ return 0;
57020+}
57021+
57022+int
57023+gr_acl_handle_filldir(const struct file *file, const char *name,
57024+ const int namelen, const ino_t ino)
57025+{
57026+ return 1;
57027+}
57028+
57029+int
57030+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57031+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57032+{
57033+ return 1;
57034+}
57035+
57036+int
57037+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57038+{
57039+ return 0;
57040+}
57041+
57042+int
57043+gr_search_accept(const struct socket *sock)
57044+{
57045+ return 0;
57046+}
57047+
57048+int
57049+gr_search_listen(const struct socket *sock)
57050+{
57051+ return 0;
57052+}
57053+
57054+int
57055+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57056+{
57057+ return 0;
57058+}
57059+
57060+__u32
57061+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57062+{
57063+ return 1;
57064+}
57065+
57066+__u32
57067+gr_acl_handle_creat(const struct dentry * dentry,
57068+ const struct dentry * p_dentry,
57069+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57070+ const int imode)
57071+{
57072+ return 1;
57073+}
57074+
57075+void
57076+gr_acl_handle_exit(void)
57077+{
57078+ return;
57079+}
57080+
57081+int
57082+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57083+{
57084+ return 1;
57085+}
57086+
57087+void
57088+gr_set_role_label(const uid_t uid, const gid_t gid)
57089+{
57090+ return;
57091+}
57092+
57093+int
57094+gr_acl_handle_procpidmem(const struct task_struct *task)
57095+{
57096+ return 0;
57097+}
57098+
57099+int
57100+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57101+{
57102+ return 0;
57103+}
57104+
57105+int
57106+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57107+{
57108+ return 0;
57109+}
57110+
57111+void
57112+gr_set_kernel_label(struct task_struct *task)
57113+{
57114+ return;
57115+}
57116+
57117+int
57118+gr_check_user_change(int real, int effective, int fs)
57119+{
57120+ return 0;
57121+}
57122+
57123+int
57124+gr_check_group_change(int real, int effective, int fs)
57125+{
57126+ return 0;
57127+}
57128+
57129+int gr_acl_enable_at_secure(void)
57130+{
57131+ return 0;
57132+}
57133+
57134+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57135+{
57136+ return dentry->d_inode->i_sb->s_dev;
57137+}
57138+
57139+EXPORT_SYMBOL(gr_learn_resource);
57140+EXPORT_SYMBOL(gr_set_kernel_label);
57141+#ifdef CONFIG_SECURITY
57142+EXPORT_SYMBOL(gr_check_user_change);
57143+EXPORT_SYMBOL(gr_check_group_change);
57144+#endif
57145diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57146new file mode 100644
57147index 0000000..abfa971
57148--- /dev/null
57149+++ b/grsecurity/grsec_exec.c
57150@@ -0,0 +1,174 @@
57151+#include <linux/kernel.h>
57152+#include <linux/sched.h>
57153+#include <linux/file.h>
57154+#include <linux/binfmts.h>
57155+#include <linux/fs.h>
57156+#include <linux/types.h>
57157+#include <linux/grdefs.h>
57158+#include <linux/grsecurity.h>
57159+#include <linux/grinternal.h>
57160+#include <linux/capability.h>
57161+#include <linux/module.h>
57162+
57163+#include <asm/uaccess.h>
57164+
57165+#ifdef CONFIG_GRKERNSEC_EXECLOG
57166+static char gr_exec_arg_buf[132];
57167+static DEFINE_MUTEX(gr_exec_arg_mutex);
57168+#endif
57169+
57170+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57171+
57172+void
57173+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57174+{
57175+#ifdef CONFIG_GRKERNSEC_EXECLOG
57176+ char *grarg = gr_exec_arg_buf;
57177+ unsigned int i, x, execlen = 0;
57178+ char c;
57179+
57180+ if (!((grsec_enable_execlog && grsec_enable_group &&
57181+ in_group_p(grsec_audit_gid))
57182+ || (grsec_enable_execlog && !grsec_enable_group)))
57183+ return;
57184+
57185+ mutex_lock(&gr_exec_arg_mutex);
57186+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
57187+
57188+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
57189+ const char __user *p;
57190+ unsigned int len;
57191+
57192+ p = get_user_arg_ptr(argv, i);
57193+ if (IS_ERR(p))
57194+ goto log;
57195+
57196+ len = strnlen_user(p, 128 - execlen);
57197+ if (len > 128 - execlen)
57198+ len = 128 - execlen;
57199+ else if (len > 0)
57200+ len--;
57201+ if (copy_from_user(grarg + execlen, p, len))
57202+ goto log;
57203+
57204+ /* rewrite unprintable characters */
57205+ for (x = 0; x < len; x++) {
57206+ c = *(grarg + execlen + x);
57207+ if (c < 32 || c > 126)
57208+ *(grarg + execlen + x) = ' ';
57209+ }
57210+
57211+ execlen += len;
57212+ *(grarg + execlen) = ' ';
57213+ *(grarg + execlen + 1) = '\0';
57214+ execlen++;
57215+ }
57216+
57217+ log:
57218+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57219+ bprm->file->f_path.mnt, grarg);
57220+ mutex_unlock(&gr_exec_arg_mutex);
57221+#endif
57222+ return;
57223+}
57224+
57225+#ifdef CONFIG_GRKERNSEC
57226+extern int gr_acl_is_capable(const int cap);
57227+extern int gr_acl_is_capable_nolog(const int cap);
57228+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57229+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57230+extern int gr_chroot_is_capable(const int cap);
57231+extern int gr_chroot_is_capable_nolog(const int cap);
57232+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57233+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57234+#endif
57235+
57236+const char *captab_log[] = {
57237+ "CAP_CHOWN",
57238+ "CAP_DAC_OVERRIDE",
57239+ "CAP_DAC_READ_SEARCH",
57240+ "CAP_FOWNER",
57241+ "CAP_FSETID",
57242+ "CAP_KILL",
57243+ "CAP_SETGID",
57244+ "CAP_SETUID",
57245+ "CAP_SETPCAP",
57246+ "CAP_LINUX_IMMUTABLE",
57247+ "CAP_NET_BIND_SERVICE",
57248+ "CAP_NET_BROADCAST",
57249+ "CAP_NET_ADMIN",
57250+ "CAP_NET_RAW",
57251+ "CAP_IPC_LOCK",
57252+ "CAP_IPC_OWNER",
57253+ "CAP_SYS_MODULE",
57254+ "CAP_SYS_RAWIO",
57255+ "CAP_SYS_CHROOT",
57256+ "CAP_SYS_PTRACE",
57257+ "CAP_SYS_PACCT",
57258+ "CAP_SYS_ADMIN",
57259+ "CAP_SYS_BOOT",
57260+ "CAP_SYS_NICE",
57261+ "CAP_SYS_RESOURCE",
57262+ "CAP_SYS_TIME",
57263+ "CAP_SYS_TTY_CONFIG",
57264+ "CAP_MKNOD",
57265+ "CAP_LEASE",
57266+ "CAP_AUDIT_WRITE",
57267+ "CAP_AUDIT_CONTROL",
57268+ "CAP_SETFCAP",
57269+ "CAP_MAC_OVERRIDE",
57270+ "CAP_MAC_ADMIN",
57271+ "CAP_SYSLOG",
57272+ "CAP_WAKE_ALARM"
57273+};
57274+
57275+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57276+
57277+int gr_is_capable(const int cap)
57278+{
57279+#ifdef CONFIG_GRKERNSEC
57280+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57281+ return 1;
57282+ return 0;
57283+#else
57284+ return 1;
57285+#endif
57286+}
57287+
57288+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57289+{
57290+#ifdef CONFIG_GRKERNSEC
57291+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57292+ return 1;
57293+ return 0;
57294+#else
57295+ return 1;
57296+#endif
57297+}
57298+
57299+int gr_is_capable_nolog(const int cap)
57300+{
57301+#ifdef CONFIG_GRKERNSEC
57302+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57303+ return 1;
57304+ return 0;
57305+#else
57306+ return 1;
57307+#endif
57308+}
57309+
57310+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57311+{
57312+#ifdef CONFIG_GRKERNSEC
57313+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57314+ return 1;
57315+ return 0;
57316+#else
57317+ return 1;
57318+#endif
57319+}
57320+
57321+EXPORT_SYMBOL(gr_is_capable);
57322+EXPORT_SYMBOL(gr_is_capable_nolog);
57323+EXPORT_SYMBOL(gr_task_is_capable);
57324+EXPORT_SYMBOL(gr_task_is_capable_nolog);
57325diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57326new file mode 100644
57327index 0000000..d3ee748
57328--- /dev/null
57329+++ b/grsecurity/grsec_fifo.c
57330@@ -0,0 +1,24 @@
57331+#include <linux/kernel.h>
57332+#include <linux/sched.h>
57333+#include <linux/fs.h>
57334+#include <linux/file.h>
57335+#include <linux/grinternal.h>
57336+
57337+int
57338+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57339+ const struct dentry *dir, const int flag, const int acc_mode)
57340+{
57341+#ifdef CONFIG_GRKERNSEC_FIFO
57342+ const struct cred *cred = current_cred();
57343+
57344+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57345+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57346+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57347+ (cred->fsuid != dentry->d_inode->i_uid)) {
57348+ if (!inode_permission(dentry->d_inode, acc_mode))
57349+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57350+ return -EACCES;
57351+ }
57352+#endif
57353+ return 0;
57354+}
57355diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57356new file mode 100644
57357index 0000000..8ca18bf
57358--- /dev/null
57359+++ b/grsecurity/grsec_fork.c
57360@@ -0,0 +1,23 @@
57361+#include <linux/kernel.h>
57362+#include <linux/sched.h>
57363+#include <linux/grsecurity.h>
57364+#include <linux/grinternal.h>
57365+#include <linux/errno.h>
57366+
57367+void
57368+gr_log_forkfail(const int retval)
57369+{
57370+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57371+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57372+ switch (retval) {
57373+ case -EAGAIN:
57374+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57375+ break;
57376+ case -ENOMEM:
57377+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57378+ break;
57379+ }
57380+ }
57381+#endif
57382+ return;
57383+}
57384diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57385new file mode 100644
57386index 0000000..05a6015
57387--- /dev/null
57388+++ b/grsecurity/grsec_init.c
57389@@ -0,0 +1,283 @@
57390+#include <linux/kernel.h>
57391+#include <linux/sched.h>
57392+#include <linux/mm.h>
57393+#include <linux/gracl.h>
57394+#include <linux/slab.h>
57395+#include <linux/vmalloc.h>
57396+#include <linux/percpu.h>
57397+#include <linux/module.h>
57398+
57399+int grsec_enable_ptrace_readexec;
57400+int grsec_enable_setxid;
57401+int grsec_enable_symlinkown;
57402+int grsec_symlinkown_gid;
57403+int grsec_enable_brute;
57404+int grsec_enable_link;
57405+int grsec_enable_dmesg;
57406+int grsec_enable_harden_ptrace;
57407+int grsec_enable_fifo;
57408+int grsec_enable_execlog;
57409+int grsec_enable_signal;
57410+int grsec_enable_forkfail;
57411+int grsec_enable_audit_ptrace;
57412+int grsec_enable_time;
57413+int grsec_enable_audit_textrel;
57414+int grsec_enable_group;
57415+int grsec_audit_gid;
57416+int grsec_enable_chdir;
57417+int grsec_enable_mount;
57418+int grsec_enable_rofs;
57419+int grsec_enable_chroot_findtask;
57420+int grsec_enable_chroot_mount;
57421+int grsec_enable_chroot_shmat;
57422+int grsec_enable_chroot_fchdir;
57423+int grsec_enable_chroot_double;
57424+int grsec_enable_chroot_pivot;
57425+int grsec_enable_chroot_chdir;
57426+int grsec_enable_chroot_chmod;
57427+int grsec_enable_chroot_mknod;
57428+int grsec_enable_chroot_nice;
57429+int grsec_enable_chroot_execlog;
57430+int grsec_enable_chroot_caps;
57431+int grsec_enable_chroot_sysctl;
57432+int grsec_enable_chroot_unix;
57433+int grsec_enable_tpe;
57434+int grsec_tpe_gid;
57435+int grsec_enable_blackhole;
57436+#ifdef CONFIG_IPV6_MODULE
57437+EXPORT_SYMBOL(grsec_enable_blackhole);
57438+#endif
57439+int grsec_lastack_retries;
57440+int grsec_enable_tpe_all;
57441+int grsec_enable_tpe_invert;
57442+int grsec_enable_socket_all;
57443+int grsec_socket_all_gid;
57444+int grsec_enable_socket_client;
57445+int grsec_socket_client_gid;
57446+int grsec_enable_socket_server;
57447+int grsec_socket_server_gid;
57448+int grsec_resource_logging;
57449+int grsec_disable_privio;
57450+int grsec_enable_log_rwxmaps;
57451+int grsec_lock;
57452+
57453+DEFINE_SPINLOCK(grsec_alert_lock);
57454+unsigned long grsec_alert_wtime = 0;
57455+unsigned long grsec_alert_fyet = 0;
57456+
57457+DEFINE_SPINLOCK(grsec_audit_lock);
57458+
57459+DEFINE_RWLOCK(grsec_exec_file_lock);
57460+
57461+char *gr_shared_page[4];
57462+
57463+char *gr_alert_log_fmt;
57464+char *gr_audit_log_fmt;
57465+char *gr_alert_log_buf;
57466+char *gr_audit_log_buf;
57467+
57468+extern struct gr_arg *gr_usermode;
57469+extern unsigned char *gr_system_salt;
57470+extern unsigned char *gr_system_sum;
57471+
57472+void __init
57473+grsecurity_init(void)
57474+{
57475+ int j;
57476+ /* create the per-cpu shared pages */
57477+
57478+#ifdef CONFIG_X86
57479+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57480+#endif
57481+
57482+ for (j = 0; j < 4; j++) {
57483+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57484+ if (gr_shared_page[j] == NULL) {
57485+ panic("Unable to allocate grsecurity shared page");
57486+ return;
57487+ }
57488+ }
57489+
57490+ /* allocate log buffers */
57491+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57492+ if (!gr_alert_log_fmt) {
57493+ panic("Unable to allocate grsecurity alert log format buffer");
57494+ return;
57495+ }
57496+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57497+ if (!gr_audit_log_fmt) {
57498+ panic("Unable to allocate grsecurity audit log format buffer");
57499+ return;
57500+ }
57501+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57502+ if (!gr_alert_log_buf) {
57503+ panic("Unable to allocate grsecurity alert log buffer");
57504+ return;
57505+ }
57506+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57507+ if (!gr_audit_log_buf) {
57508+ panic("Unable to allocate grsecurity audit log buffer");
57509+ return;
57510+ }
57511+
57512+ /* allocate memory for authentication structure */
57513+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57514+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57515+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57516+
57517+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57518+ panic("Unable to allocate grsecurity authentication structure");
57519+ return;
57520+ }
57521+
57522+
57523+#ifdef CONFIG_GRKERNSEC_IO
57524+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57525+ grsec_disable_privio = 1;
57526+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57527+ grsec_disable_privio = 1;
57528+#else
57529+ grsec_disable_privio = 0;
57530+#endif
57531+#endif
57532+
57533+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57534+ /* for backward compatibility, tpe_invert always defaults to on if
57535+ enabled in the kernel
57536+ */
57537+ grsec_enable_tpe_invert = 1;
57538+#endif
57539+
57540+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57541+#ifndef CONFIG_GRKERNSEC_SYSCTL
57542+ grsec_lock = 1;
57543+#endif
57544+
57545+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57546+ grsec_enable_audit_textrel = 1;
57547+#endif
57548+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57549+ grsec_enable_log_rwxmaps = 1;
57550+#endif
57551+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57552+ grsec_enable_group = 1;
57553+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57554+#endif
57555+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57556+ grsec_enable_ptrace_readexec = 1;
57557+#endif
57558+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57559+ grsec_enable_chdir = 1;
57560+#endif
57561+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57562+ grsec_enable_harden_ptrace = 1;
57563+#endif
57564+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57565+ grsec_enable_mount = 1;
57566+#endif
57567+#ifdef CONFIG_GRKERNSEC_LINK
57568+ grsec_enable_link = 1;
57569+#endif
57570+#ifdef CONFIG_GRKERNSEC_BRUTE
57571+ grsec_enable_brute = 1;
57572+#endif
57573+#ifdef CONFIG_GRKERNSEC_DMESG
57574+ grsec_enable_dmesg = 1;
57575+#endif
57576+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57577+ grsec_enable_blackhole = 1;
57578+ grsec_lastack_retries = 4;
57579+#endif
57580+#ifdef CONFIG_GRKERNSEC_FIFO
57581+ grsec_enable_fifo = 1;
57582+#endif
57583+#ifdef CONFIG_GRKERNSEC_EXECLOG
57584+ grsec_enable_execlog = 1;
57585+#endif
57586+#ifdef CONFIG_GRKERNSEC_SETXID
57587+ grsec_enable_setxid = 1;
57588+#endif
57589+#ifdef CONFIG_GRKERNSEC_SIGNAL
57590+ grsec_enable_signal = 1;
57591+#endif
57592+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57593+ grsec_enable_forkfail = 1;
57594+#endif
57595+#ifdef CONFIG_GRKERNSEC_TIME
57596+ grsec_enable_time = 1;
57597+#endif
57598+#ifdef CONFIG_GRKERNSEC_RESLOG
57599+ grsec_resource_logging = 1;
57600+#endif
57601+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57602+ grsec_enable_chroot_findtask = 1;
57603+#endif
57604+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57605+ grsec_enable_chroot_unix = 1;
57606+#endif
57607+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57608+ grsec_enable_chroot_mount = 1;
57609+#endif
57610+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57611+ grsec_enable_chroot_fchdir = 1;
57612+#endif
57613+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57614+ grsec_enable_chroot_shmat = 1;
57615+#endif
57616+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57617+ grsec_enable_audit_ptrace = 1;
57618+#endif
57619+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57620+ grsec_enable_chroot_double = 1;
57621+#endif
57622+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57623+ grsec_enable_chroot_pivot = 1;
57624+#endif
57625+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57626+ grsec_enable_chroot_chdir = 1;
57627+#endif
57628+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57629+ grsec_enable_chroot_chmod = 1;
57630+#endif
57631+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57632+ grsec_enable_chroot_mknod = 1;
57633+#endif
57634+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57635+ grsec_enable_chroot_nice = 1;
57636+#endif
57637+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57638+ grsec_enable_chroot_execlog = 1;
57639+#endif
57640+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57641+ grsec_enable_chroot_caps = 1;
57642+#endif
57643+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57644+ grsec_enable_chroot_sysctl = 1;
57645+#endif
57646+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
57647+ grsec_enable_symlinkown = 1;
57648+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
57649+#endif
57650+#ifdef CONFIG_GRKERNSEC_TPE
57651+ grsec_enable_tpe = 1;
57652+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
57653+#ifdef CONFIG_GRKERNSEC_TPE_ALL
57654+ grsec_enable_tpe_all = 1;
57655+#endif
57656+#endif
57657+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57658+ grsec_enable_socket_all = 1;
57659+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
57660+#endif
57661+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57662+ grsec_enable_socket_client = 1;
57663+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
57664+#endif
57665+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57666+ grsec_enable_socket_server = 1;
57667+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
57668+#endif
57669+#endif
57670+
57671+ return;
57672+}
57673diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
57674new file mode 100644
57675index 0000000..35a96d1
57676--- /dev/null
57677+++ b/grsecurity/grsec_link.c
57678@@ -0,0 +1,59 @@
57679+#include <linux/kernel.h>
57680+#include <linux/sched.h>
57681+#include <linux/fs.h>
57682+#include <linux/file.h>
57683+#include <linux/grinternal.h>
57684+
57685+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
57686+{
57687+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
57688+ const struct inode *link_inode = link->dentry->d_inode;
57689+
57690+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
57691+ /* ignore root-owned links, e.g. /proc/self */
57692+ link_inode->i_uid &&
57693+ link_inode->i_uid != target->i_uid) {
57694+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
57695+ return 1;
57696+ }
57697+#endif
57698+ return 0;
57699+}
57700+
57701+int
57702+gr_handle_follow_link(const struct inode *parent,
57703+ const struct inode *inode,
57704+ const struct dentry *dentry, const struct vfsmount *mnt)
57705+{
57706+#ifdef CONFIG_GRKERNSEC_LINK
57707+ const struct cred *cred = current_cred();
57708+
57709+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
57710+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
57711+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
57712+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
57713+ return -EACCES;
57714+ }
57715+#endif
57716+ return 0;
57717+}
57718+
57719+int
57720+gr_handle_hardlink(const struct dentry *dentry,
57721+ const struct vfsmount *mnt,
57722+ struct inode *inode, const int mode, const char *to)
57723+{
57724+#ifdef CONFIG_GRKERNSEC_LINK
57725+ const struct cred *cred = current_cred();
57726+
57727+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
57728+ (!S_ISREG(mode) || (mode & S_ISUID) ||
57729+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
57730+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
57731+ !capable(CAP_FOWNER) && cred->uid) {
57732+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
57733+ return -EPERM;
57734+ }
57735+#endif
57736+ return 0;
57737+}
57738diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
57739new file mode 100644
57740index 0000000..a45d2e9
57741--- /dev/null
57742+++ b/grsecurity/grsec_log.c
57743@@ -0,0 +1,322 @@
57744+#include <linux/kernel.h>
57745+#include <linux/sched.h>
57746+#include <linux/file.h>
57747+#include <linux/tty.h>
57748+#include <linux/fs.h>
57749+#include <linux/grinternal.h>
57750+
57751+#ifdef CONFIG_TREE_PREEMPT_RCU
57752+#define DISABLE_PREEMPT() preempt_disable()
57753+#define ENABLE_PREEMPT() preempt_enable()
57754+#else
57755+#define DISABLE_PREEMPT()
57756+#define ENABLE_PREEMPT()
57757+#endif
57758+
57759+#define BEGIN_LOCKS(x) \
57760+ DISABLE_PREEMPT(); \
57761+ rcu_read_lock(); \
57762+ read_lock(&tasklist_lock); \
57763+ read_lock(&grsec_exec_file_lock); \
57764+ if (x != GR_DO_AUDIT) \
57765+ spin_lock(&grsec_alert_lock); \
57766+ else \
57767+ spin_lock(&grsec_audit_lock)
57768+
57769+#define END_LOCKS(x) \
57770+ if (x != GR_DO_AUDIT) \
57771+ spin_unlock(&grsec_alert_lock); \
57772+ else \
57773+ spin_unlock(&grsec_audit_lock); \
57774+ read_unlock(&grsec_exec_file_lock); \
57775+ read_unlock(&tasklist_lock); \
57776+ rcu_read_unlock(); \
57777+ ENABLE_PREEMPT(); \
57778+ if (x == GR_DONT_AUDIT) \
57779+ gr_handle_alertkill(current)
57780+
57781+enum {
57782+ FLOODING,
57783+ NO_FLOODING
57784+};
57785+
57786+extern char *gr_alert_log_fmt;
57787+extern char *gr_audit_log_fmt;
57788+extern char *gr_alert_log_buf;
57789+extern char *gr_audit_log_buf;
57790+
57791+static int gr_log_start(int audit)
57792+{
57793+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
57794+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
57795+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57796+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
57797+ unsigned long curr_secs = get_seconds();
57798+
57799+ if (audit == GR_DO_AUDIT)
57800+ goto set_fmt;
57801+
57802+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
57803+ grsec_alert_wtime = curr_secs;
57804+ grsec_alert_fyet = 0;
57805+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
57806+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
57807+ grsec_alert_fyet++;
57808+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
57809+ grsec_alert_wtime = curr_secs;
57810+ grsec_alert_fyet++;
57811+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
57812+ return FLOODING;
57813+ }
57814+ else return FLOODING;
57815+
57816+set_fmt:
57817+#endif
57818+ memset(buf, 0, PAGE_SIZE);
57819+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
57820+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
57821+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57822+ } else if (current->signal->curr_ip) {
57823+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
57824+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
57825+ } else if (gr_acl_is_enabled()) {
57826+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
57827+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57828+ } else {
57829+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
57830+ strcpy(buf, fmt);
57831+ }
57832+
57833+ return NO_FLOODING;
57834+}
57835+
57836+static void gr_log_middle(int audit, const char *msg, va_list ap)
57837+ __attribute__ ((format (printf, 2, 0)));
57838+
57839+static void gr_log_middle(int audit, const char *msg, va_list ap)
57840+{
57841+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57842+ unsigned int len = strlen(buf);
57843+
57844+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57845+
57846+ return;
57847+}
57848+
57849+static void gr_log_middle_varargs(int audit, const char *msg, ...)
57850+ __attribute__ ((format (printf, 2, 3)));
57851+
57852+static void gr_log_middle_varargs(int audit, const char *msg, ...)
57853+{
57854+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57855+ unsigned int len = strlen(buf);
57856+ va_list ap;
57857+
57858+ va_start(ap, msg);
57859+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57860+ va_end(ap);
57861+
57862+ return;
57863+}
57864+
57865+static void gr_log_end(int audit, int append_default)
57866+{
57867+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57868+
57869+ if (append_default) {
57870+ unsigned int len = strlen(buf);
57871+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
57872+ }
57873+
57874+ printk("%s\n", buf);
57875+
57876+ return;
57877+}
57878+
57879+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
57880+{
57881+ int logtype;
57882+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
57883+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
57884+ void *voidptr = NULL;
57885+ int num1 = 0, num2 = 0;
57886+ unsigned long ulong1 = 0, ulong2 = 0;
57887+ struct dentry *dentry = NULL;
57888+ struct vfsmount *mnt = NULL;
57889+ struct file *file = NULL;
57890+ struct task_struct *task = NULL;
57891+ const struct cred *cred, *pcred;
57892+ va_list ap;
57893+
57894+ BEGIN_LOCKS(audit);
57895+ logtype = gr_log_start(audit);
57896+ if (logtype == FLOODING) {
57897+ END_LOCKS(audit);
57898+ return;
57899+ }
57900+ va_start(ap, argtypes);
57901+ switch (argtypes) {
57902+ case GR_TTYSNIFF:
57903+ task = va_arg(ap, struct task_struct *);
57904+ 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);
57905+ break;
57906+ case GR_SYSCTL_HIDDEN:
57907+ str1 = va_arg(ap, char *);
57908+ gr_log_middle_varargs(audit, msg, result, str1);
57909+ break;
57910+ case GR_RBAC:
57911+ dentry = va_arg(ap, struct dentry *);
57912+ mnt = va_arg(ap, struct vfsmount *);
57913+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
57914+ break;
57915+ case GR_RBAC_STR:
57916+ dentry = va_arg(ap, struct dentry *);
57917+ mnt = va_arg(ap, struct vfsmount *);
57918+ str1 = va_arg(ap, char *);
57919+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
57920+ break;
57921+ case GR_STR_RBAC:
57922+ str1 = va_arg(ap, char *);
57923+ dentry = va_arg(ap, struct dentry *);
57924+ mnt = va_arg(ap, struct vfsmount *);
57925+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
57926+ break;
57927+ case GR_RBAC_MODE2:
57928+ dentry = va_arg(ap, struct dentry *);
57929+ mnt = va_arg(ap, struct vfsmount *);
57930+ str1 = va_arg(ap, char *);
57931+ str2 = va_arg(ap, char *);
57932+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
57933+ break;
57934+ case GR_RBAC_MODE3:
57935+ dentry = va_arg(ap, struct dentry *);
57936+ mnt = va_arg(ap, struct vfsmount *);
57937+ str1 = va_arg(ap, char *);
57938+ str2 = va_arg(ap, char *);
57939+ str3 = va_arg(ap, char *);
57940+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
57941+ break;
57942+ case GR_FILENAME:
57943+ dentry = va_arg(ap, struct dentry *);
57944+ mnt = va_arg(ap, struct vfsmount *);
57945+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
57946+ break;
57947+ case GR_STR_FILENAME:
57948+ str1 = va_arg(ap, char *);
57949+ dentry = va_arg(ap, struct dentry *);
57950+ mnt = va_arg(ap, struct vfsmount *);
57951+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
57952+ break;
57953+ case GR_FILENAME_STR:
57954+ dentry = va_arg(ap, struct dentry *);
57955+ mnt = va_arg(ap, struct vfsmount *);
57956+ str1 = va_arg(ap, char *);
57957+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
57958+ break;
57959+ case GR_FILENAME_TWO_INT:
57960+ dentry = va_arg(ap, struct dentry *);
57961+ mnt = va_arg(ap, struct vfsmount *);
57962+ num1 = va_arg(ap, int);
57963+ num2 = va_arg(ap, int);
57964+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
57965+ break;
57966+ case GR_FILENAME_TWO_INT_STR:
57967+ dentry = va_arg(ap, struct dentry *);
57968+ mnt = va_arg(ap, struct vfsmount *);
57969+ num1 = va_arg(ap, int);
57970+ num2 = va_arg(ap, int);
57971+ str1 = va_arg(ap, char *);
57972+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
57973+ break;
57974+ case GR_TEXTREL:
57975+ file = va_arg(ap, struct file *);
57976+ ulong1 = va_arg(ap, unsigned long);
57977+ ulong2 = va_arg(ap, unsigned long);
57978+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
57979+ break;
57980+ case GR_PTRACE:
57981+ task = va_arg(ap, struct task_struct *);
57982+ 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);
57983+ break;
57984+ case GR_RESOURCE:
57985+ task = va_arg(ap, struct task_struct *);
57986+ cred = __task_cred(task);
57987+ pcred = __task_cred(task->real_parent);
57988+ ulong1 = va_arg(ap, unsigned long);
57989+ str1 = va_arg(ap, char *);
57990+ ulong2 = va_arg(ap, unsigned long);
57991+ 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);
57992+ break;
57993+ case GR_CAP:
57994+ task = va_arg(ap, struct task_struct *);
57995+ cred = __task_cred(task);
57996+ pcred = __task_cred(task->real_parent);
57997+ str1 = va_arg(ap, char *);
57998+ 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);
57999+ break;
58000+ case GR_SIG:
58001+ str1 = va_arg(ap, char *);
58002+ voidptr = va_arg(ap, void *);
58003+ gr_log_middle_varargs(audit, msg, str1, voidptr);
58004+ break;
58005+ case GR_SIG2:
58006+ task = va_arg(ap, struct task_struct *);
58007+ cred = __task_cred(task);
58008+ pcred = __task_cred(task->real_parent);
58009+ num1 = va_arg(ap, int);
58010+ 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);
58011+ break;
58012+ case GR_CRASH1:
58013+ task = va_arg(ap, struct task_struct *);
58014+ cred = __task_cred(task);
58015+ pcred = __task_cred(task->real_parent);
58016+ ulong1 = va_arg(ap, unsigned long);
58017+ 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);
58018+ break;
58019+ case GR_CRASH2:
58020+ task = va_arg(ap, struct task_struct *);
58021+ cred = __task_cred(task);
58022+ pcred = __task_cred(task->real_parent);
58023+ ulong1 = va_arg(ap, unsigned long);
58024+ 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);
58025+ break;
58026+ case GR_RWXMAP:
58027+ file = va_arg(ap, struct file *);
58028+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58029+ break;
58030+ case GR_PSACCT:
58031+ {
58032+ unsigned int wday, cday;
58033+ __u8 whr, chr;
58034+ __u8 wmin, cmin;
58035+ __u8 wsec, csec;
58036+ char cur_tty[64] = { 0 };
58037+ char parent_tty[64] = { 0 };
58038+
58039+ task = va_arg(ap, struct task_struct *);
58040+ wday = va_arg(ap, unsigned int);
58041+ cday = va_arg(ap, unsigned int);
58042+ whr = va_arg(ap, int);
58043+ chr = va_arg(ap, int);
58044+ wmin = va_arg(ap, int);
58045+ cmin = va_arg(ap, int);
58046+ wsec = va_arg(ap, int);
58047+ csec = va_arg(ap, int);
58048+ ulong1 = va_arg(ap, unsigned long);
58049+ cred = __task_cred(task);
58050+ pcred = __task_cred(task->real_parent);
58051+
58052+ 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);
58053+ }
58054+ break;
58055+ default:
58056+ gr_log_middle(audit, msg, ap);
58057+ }
58058+ va_end(ap);
58059+ // these don't need DEFAULTSECARGS printed on the end
58060+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58061+ gr_log_end(audit, 0);
58062+ else
58063+ gr_log_end(audit, 1);
58064+ END_LOCKS(audit);
58065+}
58066diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58067new file mode 100644
58068index 0000000..f536303
58069--- /dev/null
58070+++ b/grsecurity/grsec_mem.c
58071@@ -0,0 +1,40 @@
58072+#include <linux/kernel.h>
58073+#include <linux/sched.h>
58074+#include <linux/mm.h>
58075+#include <linux/mman.h>
58076+#include <linux/grinternal.h>
58077+
58078+void
58079+gr_handle_ioperm(void)
58080+{
58081+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58082+ return;
58083+}
58084+
58085+void
58086+gr_handle_iopl(void)
58087+{
58088+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58089+ return;
58090+}
58091+
58092+void
58093+gr_handle_mem_readwrite(u64 from, u64 to)
58094+{
58095+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58096+ return;
58097+}
58098+
58099+void
58100+gr_handle_vm86(void)
58101+{
58102+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58103+ return;
58104+}
58105+
58106+void
58107+gr_log_badprocpid(const char *entry)
58108+{
58109+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58110+ return;
58111+}
58112diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58113new file mode 100644
58114index 0000000..2131422
58115--- /dev/null
58116+++ b/grsecurity/grsec_mount.c
58117@@ -0,0 +1,62 @@
58118+#include <linux/kernel.h>
58119+#include <linux/sched.h>
58120+#include <linux/mount.h>
58121+#include <linux/grsecurity.h>
58122+#include <linux/grinternal.h>
58123+
58124+void
58125+gr_log_remount(const char *devname, const int retval)
58126+{
58127+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58128+ if (grsec_enable_mount && (retval >= 0))
58129+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58130+#endif
58131+ return;
58132+}
58133+
58134+void
58135+gr_log_unmount(const char *devname, const int retval)
58136+{
58137+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58138+ if (grsec_enable_mount && (retval >= 0))
58139+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58140+#endif
58141+ return;
58142+}
58143+
58144+void
58145+gr_log_mount(const char *from, const char *to, const int retval)
58146+{
58147+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58148+ if (grsec_enable_mount && (retval >= 0))
58149+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58150+#endif
58151+ return;
58152+}
58153+
58154+int
58155+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58156+{
58157+#ifdef CONFIG_GRKERNSEC_ROFS
58158+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58159+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58160+ return -EPERM;
58161+ } else
58162+ return 0;
58163+#endif
58164+ return 0;
58165+}
58166+
58167+int
58168+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58169+{
58170+#ifdef CONFIG_GRKERNSEC_ROFS
58171+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58172+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58173+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58174+ return -EPERM;
58175+ } else
58176+ return 0;
58177+#endif
58178+ return 0;
58179+}
58180diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58181new file mode 100644
58182index 0000000..a3b12a0
58183--- /dev/null
58184+++ b/grsecurity/grsec_pax.c
58185@@ -0,0 +1,36 @@
58186+#include <linux/kernel.h>
58187+#include <linux/sched.h>
58188+#include <linux/mm.h>
58189+#include <linux/file.h>
58190+#include <linux/grinternal.h>
58191+#include <linux/grsecurity.h>
58192+
58193+void
58194+gr_log_textrel(struct vm_area_struct * vma)
58195+{
58196+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58197+ if (grsec_enable_audit_textrel)
58198+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58199+#endif
58200+ return;
58201+}
58202+
58203+void
58204+gr_log_rwxmmap(struct file *file)
58205+{
58206+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58207+ if (grsec_enable_log_rwxmaps)
58208+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58209+#endif
58210+ return;
58211+}
58212+
58213+void
58214+gr_log_rwxmprotect(struct file *file)
58215+{
58216+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58217+ if (grsec_enable_log_rwxmaps)
58218+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58219+#endif
58220+ return;
58221+}
58222diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58223new file mode 100644
58224index 0000000..f7f29aa
58225--- /dev/null
58226+++ b/grsecurity/grsec_ptrace.c
58227@@ -0,0 +1,30 @@
58228+#include <linux/kernel.h>
58229+#include <linux/sched.h>
58230+#include <linux/grinternal.h>
58231+#include <linux/security.h>
58232+
58233+void
58234+gr_audit_ptrace(struct task_struct *task)
58235+{
58236+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58237+ if (grsec_enable_audit_ptrace)
58238+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58239+#endif
58240+ return;
58241+}
58242+
58243+int
58244+gr_ptrace_readexec(struct file *file, int unsafe_flags)
58245+{
58246+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58247+ const struct dentry *dentry = file->f_path.dentry;
58248+ const struct vfsmount *mnt = file->f_path.mnt;
58249+
58250+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58251+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58252+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58253+ return -EACCES;
58254+ }
58255+#endif
58256+ return 0;
58257+}
58258diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58259new file mode 100644
58260index 0000000..7a5b2de
58261--- /dev/null
58262+++ b/grsecurity/grsec_sig.c
58263@@ -0,0 +1,207 @@
58264+#include <linux/kernel.h>
58265+#include <linux/sched.h>
58266+#include <linux/delay.h>
58267+#include <linux/grsecurity.h>
58268+#include <linux/grinternal.h>
58269+#include <linux/hardirq.h>
58270+
58271+char *signames[] = {
58272+ [SIGSEGV] = "Segmentation fault",
58273+ [SIGILL] = "Illegal instruction",
58274+ [SIGABRT] = "Abort",
58275+ [SIGBUS] = "Invalid alignment/Bus error"
58276+};
58277+
58278+void
58279+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58280+{
58281+#ifdef CONFIG_GRKERNSEC_SIGNAL
58282+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58283+ (sig == SIGABRT) || (sig == SIGBUS))) {
58284+ if (t->pid == current->pid) {
58285+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58286+ } else {
58287+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58288+ }
58289+ }
58290+#endif
58291+ return;
58292+}
58293+
58294+int
58295+gr_handle_signal(const struct task_struct *p, const int sig)
58296+{
58297+#ifdef CONFIG_GRKERNSEC
58298+ /* ignore the 0 signal for protected task checks */
58299+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58300+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58301+ return -EPERM;
58302+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58303+ return -EPERM;
58304+ }
58305+#endif
58306+ return 0;
58307+}
58308+
58309+#ifdef CONFIG_GRKERNSEC
58310+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58311+
58312+int gr_fake_force_sig(int sig, struct task_struct *t)
58313+{
58314+ unsigned long int flags;
58315+ int ret, blocked, ignored;
58316+ struct k_sigaction *action;
58317+
58318+ spin_lock_irqsave(&t->sighand->siglock, flags);
58319+ action = &t->sighand->action[sig-1];
58320+ ignored = action->sa.sa_handler == SIG_IGN;
58321+ blocked = sigismember(&t->blocked, sig);
58322+ if (blocked || ignored) {
58323+ action->sa.sa_handler = SIG_DFL;
58324+ if (blocked) {
58325+ sigdelset(&t->blocked, sig);
58326+ recalc_sigpending_and_wake(t);
58327+ }
58328+ }
58329+ if (action->sa.sa_handler == SIG_DFL)
58330+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
58331+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58332+
58333+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
58334+
58335+ return ret;
58336+}
58337+#endif
58338+
58339+#ifdef CONFIG_GRKERNSEC_BRUTE
58340+#define GR_USER_BAN_TIME (15 * 60)
58341+
58342+static int __get_dumpable(unsigned long mm_flags)
58343+{
58344+ int ret;
58345+
58346+ ret = mm_flags & MMF_DUMPABLE_MASK;
58347+ return (ret >= 2) ? 2 : ret;
58348+}
58349+#endif
58350+
58351+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58352+{
58353+#ifdef CONFIG_GRKERNSEC_BRUTE
58354+ uid_t uid = 0;
58355+
58356+ if (!grsec_enable_brute)
58357+ return;
58358+
58359+ rcu_read_lock();
58360+ read_lock(&tasklist_lock);
58361+ read_lock(&grsec_exec_file_lock);
58362+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58363+ p->real_parent->brute = 1;
58364+ else {
58365+ const struct cred *cred = __task_cred(p), *cred2;
58366+ struct task_struct *tsk, *tsk2;
58367+
58368+ if (!__get_dumpable(mm_flags) && cred->uid) {
58369+ struct user_struct *user;
58370+
58371+ uid = cred->uid;
58372+
58373+ /* this is put upon execution past expiration */
58374+ user = find_user(uid);
58375+ if (user == NULL)
58376+ goto unlock;
58377+ user->banned = 1;
58378+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58379+ if (user->ban_expires == ~0UL)
58380+ user->ban_expires--;
58381+
58382+ do_each_thread(tsk2, tsk) {
58383+ cred2 = __task_cred(tsk);
58384+ if (tsk != p && cred2->uid == uid)
58385+ gr_fake_force_sig(SIGKILL, tsk);
58386+ } while_each_thread(tsk2, tsk);
58387+ }
58388+ }
58389+unlock:
58390+ read_unlock(&grsec_exec_file_lock);
58391+ read_unlock(&tasklist_lock);
58392+ rcu_read_unlock();
58393+
58394+ if (uid)
58395+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58396+
58397+#endif
58398+ return;
58399+}
58400+
58401+void gr_handle_brute_check(void)
58402+{
58403+#ifdef CONFIG_GRKERNSEC_BRUTE
58404+ if (current->brute)
58405+ msleep(30 * 1000);
58406+#endif
58407+ return;
58408+}
58409+
58410+void gr_handle_kernel_exploit(void)
58411+{
58412+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58413+ const struct cred *cred;
58414+ struct task_struct *tsk, *tsk2;
58415+ struct user_struct *user;
58416+ uid_t uid;
58417+
58418+ if (in_irq() || in_serving_softirq() || in_nmi())
58419+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58420+
58421+ uid = current_uid();
58422+
58423+ if (uid == 0)
58424+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
58425+ else {
58426+ /* kill all the processes of this user, hold a reference
58427+ to their creds struct, and prevent them from creating
58428+ another process until system reset
58429+ */
58430+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58431+ /* we intentionally leak this ref */
58432+ user = get_uid(current->cred->user);
58433+ if (user) {
58434+ user->banned = 1;
58435+ user->ban_expires = ~0UL;
58436+ }
58437+
58438+ read_lock(&tasklist_lock);
58439+ do_each_thread(tsk2, tsk) {
58440+ cred = __task_cred(tsk);
58441+ if (cred->uid == uid)
58442+ gr_fake_force_sig(SIGKILL, tsk);
58443+ } while_each_thread(tsk2, tsk);
58444+ read_unlock(&tasklist_lock);
58445+ }
58446+#endif
58447+}
58448+
58449+int __gr_process_user_ban(struct user_struct *user)
58450+{
58451+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58452+ if (unlikely(user->banned)) {
58453+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58454+ user->banned = 0;
58455+ user->ban_expires = 0;
58456+ free_uid(user);
58457+ } else
58458+ return -EPERM;
58459+ }
58460+#endif
58461+ return 0;
58462+}
58463+
58464+int gr_process_user_ban(void)
58465+{
58466+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58467+ return __gr_process_user_ban(current->cred->user);
58468+#endif
58469+ return 0;
58470+}
58471diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58472new file mode 100644
58473index 0000000..4030d57
58474--- /dev/null
58475+++ b/grsecurity/grsec_sock.c
58476@@ -0,0 +1,244 @@
58477+#include <linux/kernel.h>
58478+#include <linux/module.h>
58479+#include <linux/sched.h>
58480+#include <linux/file.h>
58481+#include <linux/net.h>
58482+#include <linux/in.h>
58483+#include <linux/ip.h>
58484+#include <net/sock.h>
58485+#include <net/inet_sock.h>
58486+#include <linux/grsecurity.h>
58487+#include <linux/grinternal.h>
58488+#include <linux/gracl.h>
58489+
58490+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58491+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58492+
58493+EXPORT_SYMBOL(gr_search_udp_recvmsg);
58494+EXPORT_SYMBOL(gr_search_udp_sendmsg);
58495+
58496+#ifdef CONFIG_UNIX_MODULE
58497+EXPORT_SYMBOL(gr_acl_handle_unix);
58498+EXPORT_SYMBOL(gr_acl_handle_mknod);
58499+EXPORT_SYMBOL(gr_handle_chroot_unix);
58500+EXPORT_SYMBOL(gr_handle_create);
58501+#endif
58502+
58503+#ifdef CONFIG_GRKERNSEC
58504+#define gr_conn_table_size 32749
58505+struct conn_table_entry {
58506+ struct conn_table_entry *next;
58507+ struct signal_struct *sig;
58508+};
58509+
58510+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58511+DEFINE_SPINLOCK(gr_conn_table_lock);
58512+
58513+extern const char * gr_socktype_to_name(unsigned char type);
58514+extern const char * gr_proto_to_name(unsigned char proto);
58515+extern const char * gr_sockfamily_to_name(unsigned char family);
58516+
58517+static __inline__ int
58518+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58519+{
58520+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58521+}
58522+
58523+static __inline__ int
58524+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58525+ __u16 sport, __u16 dport)
58526+{
58527+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58528+ sig->gr_sport == sport && sig->gr_dport == dport))
58529+ return 1;
58530+ else
58531+ return 0;
58532+}
58533+
58534+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58535+{
58536+ struct conn_table_entry **match;
58537+ unsigned int index;
58538+
58539+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58540+ sig->gr_sport, sig->gr_dport,
58541+ gr_conn_table_size);
58542+
58543+ newent->sig = sig;
58544+
58545+ match = &gr_conn_table[index];
58546+ newent->next = *match;
58547+ *match = newent;
58548+
58549+ return;
58550+}
58551+
58552+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58553+{
58554+ struct conn_table_entry *match, *last = NULL;
58555+ unsigned int index;
58556+
58557+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58558+ sig->gr_sport, sig->gr_dport,
58559+ gr_conn_table_size);
58560+
58561+ match = gr_conn_table[index];
58562+ while (match && !conn_match(match->sig,
58563+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58564+ sig->gr_dport)) {
58565+ last = match;
58566+ match = match->next;
58567+ }
58568+
58569+ if (match) {
58570+ if (last)
58571+ last->next = match->next;
58572+ else
58573+ gr_conn_table[index] = NULL;
58574+ kfree(match);
58575+ }
58576+
58577+ return;
58578+}
58579+
58580+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58581+ __u16 sport, __u16 dport)
58582+{
58583+ struct conn_table_entry *match;
58584+ unsigned int index;
58585+
58586+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58587+
58588+ match = gr_conn_table[index];
58589+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58590+ match = match->next;
58591+
58592+ if (match)
58593+ return match->sig;
58594+ else
58595+ return NULL;
58596+}
58597+
58598+#endif
58599+
58600+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58601+{
58602+#ifdef CONFIG_GRKERNSEC
58603+ struct signal_struct *sig = task->signal;
58604+ struct conn_table_entry *newent;
58605+
58606+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58607+ if (newent == NULL)
58608+ return;
58609+ /* no bh lock needed since we are called with bh disabled */
58610+ spin_lock(&gr_conn_table_lock);
58611+ gr_del_task_from_ip_table_nolock(sig);
58612+ sig->gr_saddr = inet->inet_rcv_saddr;
58613+ sig->gr_daddr = inet->inet_daddr;
58614+ sig->gr_sport = inet->inet_sport;
58615+ sig->gr_dport = inet->inet_dport;
58616+ gr_add_to_task_ip_table_nolock(sig, newent);
58617+ spin_unlock(&gr_conn_table_lock);
58618+#endif
58619+ return;
58620+}
58621+
58622+void gr_del_task_from_ip_table(struct task_struct *task)
58623+{
58624+#ifdef CONFIG_GRKERNSEC
58625+ spin_lock_bh(&gr_conn_table_lock);
58626+ gr_del_task_from_ip_table_nolock(task->signal);
58627+ spin_unlock_bh(&gr_conn_table_lock);
58628+#endif
58629+ return;
58630+}
58631+
58632+void
58633+gr_attach_curr_ip(const struct sock *sk)
58634+{
58635+#ifdef CONFIG_GRKERNSEC
58636+ struct signal_struct *p, *set;
58637+ const struct inet_sock *inet = inet_sk(sk);
58638+
58639+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
58640+ return;
58641+
58642+ set = current->signal;
58643+
58644+ spin_lock_bh(&gr_conn_table_lock);
58645+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
58646+ inet->inet_dport, inet->inet_sport);
58647+ if (unlikely(p != NULL)) {
58648+ set->curr_ip = p->curr_ip;
58649+ set->used_accept = 1;
58650+ gr_del_task_from_ip_table_nolock(p);
58651+ spin_unlock_bh(&gr_conn_table_lock);
58652+ return;
58653+ }
58654+ spin_unlock_bh(&gr_conn_table_lock);
58655+
58656+ set->curr_ip = inet->inet_daddr;
58657+ set->used_accept = 1;
58658+#endif
58659+ return;
58660+}
58661+
58662+int
58663+gr_handle_sock_all(const int family, const int type, const int protocol)
58664+{
58665+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58666+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
58667+ (family != AF_UNIX)) {
58668+ if (family == AF_INET)
58669+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
58670+ else
58671+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
58672+ return -EACCES;
58673+ }
58674+#endif
58675+ return 0;
58676+}
58677+
58678+int
58679+gr_handle_sock_server(const struct sockaddr *sck)
58680+{
58681+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58682+ if (grsec_enable_socket_server &&
58683+ in_group_p(grsec_socket_server_gid) &&
58684+ sck && (sck->sa_family != AF_UNIX) &&
58685+ (sck->sa_family != AF_LOCAL)) {
58686+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58687+ return -EACCES;
58688+ }
58689+#endif
58690+ return 0;
58691+}
58692+
58693+int
58694+gr_handle_sock_server_other(const struct sock *sck)
58695+{
58696+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58697+ if (grsec_enable_socket_server &&
58698+ in_group_p(grsec_socket_server_gid) &&
58699+ sck && (sck->sk_family != AF_UNIX) &&
58700+ (sck->sk_family != AF_LOCAL)) {
58701+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58702+ return -EACCES;
58703+ }
58704+#endif
58705+ return 0;
58706+}
58707+
58708+int
58709+gr_handle_sock_client(const struct sockaddr *sck)
58710+{
58711+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58712+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
58713+ sck && (sck->sa_family != AF_UNIX) &&
58714+ (sck->sa_family != AF_LOCAL)) {
58715+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
58716+ return -EACCES;
58717+ }
58718+#endif
58719+ return 0;
58720+}
58721diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
58722new file mode 100644
58723index 0000000..f55ef0f
58724--- /dev/null
58725+++ b/grsecurity/grsec_sysctl.c
58726@@ -0,0 +1,469 @@
58727+#include <linux/kernel.h>
58728+#include <linux/sched.h>
58729+#include <linux/sysctl.h>
58730+#include <linux/grsecurity.h>
58731+#include <linux/grinternal.h>
58732+
58733+int
58734+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
58735+{
58736+#ifdef CONFIG_GRKERNSEC_SYSCTL
58737+ if (dirname == NULL || name == NULL)
58738+ return 0;
58739+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
58740+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
58741+ return -EACCES;
58742+ }
58743+#endif
58744+ return 0;
58745+}
58746+
58747+#ifdef CONFIG_GRKERNSEC_ROFS
58748+static int __maybe_unused one = 1;
58749+#endif
58750+
58751+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
58752+struct ctl_table grsecurity_table[] = {
58753+#ifdef CONFIG_GRKERNSEC_SYSCTL
58754+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
58755+#ifdef CONFIG_GRKERNSEC_IO
58756+ {
58757+ .procname = "disable_priv_io",
58758+ .data = &grsec_disable_privio,
58759+ .maxlen = sizeof(int),
58760+ .mode = 0600,
58761+ .proc_handler = &proc_dointvec,
58762+ },
58763+#endif
58764+#endif
58765+#ifdef CONFIG_GRKERNSEC_LINK
58766+ {
58767+ .procname = "linking_restrictions",
58768+ .data = &grsec_enable_link,
58769+ .maxlen = sizeof(int),
58770+ .mode = 0600,
58771+ .proc_handler = &proc_dointvec,
58772+ },
58773+#endif
58774+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58775+ {
58776+ .procname = "enforce_symlinksifowner",
58777+ .data = &grsec_enable_symlinkown,
58778+ .maxlen = sizeof(int),
58779+ .mode = 0600,
58780+ .proc_handler = &proc_dointvec,
58781+ },
58782+ {
58783+ .procname = "symlinkown_gid",
58784+ .data = &grsec_symlinkown_gid,
58785+ .maxlen = sizeof(int),
58786+ .mode = 0600,
58787+ .proc_handler = &proc_dointvec,
58788+ },
58789+#endif
58790+#ifdef CONFIG_GRKERNSEC_BRUTE
58791+ {
58792+ .procname = "deter_bruteforce",
58793+ .data = &grsec_enable_brute,
58794+ .maxlen = sizeof(int),
58795+ .mode = 0600,
58796+ .proc_handler = &proc_dointvec,
58797+ },
58798+#endif
58799+#ifdef CONFIG_GRKERNSEC_FIFO
58800+ {
58801+ .procname = "fifo_restrictions",
58802+ .data = &grsec_enable_fifo,
58803+ .maxlen = sizeof(int),
58804+ .mode = 0600,
58805+ .proc_handler = &proc_dointvec,
58806+ },
58807+#endif
58808+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58809+ {
58810+ .procname = "ptrace_readexec",
58811+ .data = &grsec_enable_ptrace_readexec,
58812+ .maxlen = sizeof(int),
58813+ .mode = 0600,
58814+ .proc_handler = &proc_dointvec,
58815+ },
58816+#endif
58817+#ifdef CONFIG_GRKERNSEC_SETXID
58818+ {
58819+ .procname = "consistent_setxid",
58820+ .data = &grsec_enable_setxid,
58821+ .maxlen = sizeof(int),
58822+ .mode = 0600,
58823+ .proc_handler = &proc_dointvec,
58824+ },
58825+#endif
58826+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58827+ {
58828+ .procname = "ip_blackhole",
58829+ .data = &grsec_enable_blackhole,
58830+ .maxlen = sizeof(int),
58831+ .mode = 0600,
58832+ .proc_handler = &proc_dointvec,
58833+ },
58834+ {
58835+ .procname = "lastack_retries",
58836+ .data = &grsec_lastack_retries,
58837+ .maxlen = sizeof(int),
58838+ .mode = 0600,
58839+ .proc_handler = &proc_dointvec,
58840+ },
58841+#endif
58842+#ifdef CONFIG_GRKERNSEC_EXECLOG
58843+ {
58844+ .procname = "exec_logging",
58845+ .data = &grsec_enable_execlog,
58846+ .maxlen = sizeof(int),
58847+ .mode = 0600,
58848+ .proc_handler = &proc_dointvec,
58849+ },
58850+#endif
58851+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58852+ {
58853+ .procname = "rwxmap_logging",
58854+ .data = &grsec_enable_log_rwxmaps,
58855+ .maxlen = sizeof(int),
58856+ .mode = 0600,
58857+ .proc_handler = &proc_dointvec,
58858+ },
58859+#endif
58860+#ifdef CONFIG_GRKERNSEC_SIGNAL
58861+ {
58862+ .procname = "signal_logging",
58863+ .data = &grsec_enable_signal,
58864+ .maxlen = sizeof(int),
58865+ .mode = 0600,
58866+ .proc_handler = &proc_dointvec,
58867+ },
58868+#endif
58869+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58870+ {
58871+ .procname = "forkfail_logging",
58872+ .data = &grsec_enable_forkfail,
58873+ .maxlen = sizeof(int),
58874+ .mode = 0600,
58875+ .proc_handler = &proc_dointvec,
58876+ },
58877+#endif
58878+#ifdef CONFIG_GRKERNSEC_TIME
58879+ {
58880+ .procname = "timechange_logging",
58881+ .data = &grsec_enable_time,
58882+ .maxlen = sizeof(int),
58883+ .mode = 0600,
58884+ .proc_handler = &proc_dointvec,
58885+ },
58886+#endif
58887+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58888+ {
58889+ .procname = "chroot_deny_shmat",
58890+ .data = &grsec_enable_chroot_shmat,
58891+ .maxlen = sizeof(int),
58892+ .mode = 0600,
58893+ .proc_handler = &proc_dointvec,
58894+ },
58895+#endif
58896+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58897+ {
58898+ .procname = "chroot_deny_unix",
58899+ .data = &grsec_enable_chroot_unix,
58900+ .maxlen = sizeof(int),
58901+ .mode = 0600,
58902+ .proc_handler = &proc_dointvec,
58903+ },
58904+#endif
58905+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58906+ {
58907+ .procname = "chroot_deny_mount",
58908+ .data = &grsec_enable_chroot_mount,
58909+ .maxlen = sizeof(int),
58910+ .mode = 0600,
58911+ .proc_handler = &proc_dointvec,
58912+ },
58913+#endif
58914+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58915+ {
58916+ .procname = "chroot_deny_fchdir",
58917+ .data = &grsec_enable_chroot_fchdir,
58918+ .maxlen = sizeof(int),
58919+ .mode = 0600,
58920+ .proc_handler = &proc_dointvec,
58921+ },
58922+#endif
58923+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58924+ {
58925+ .procname = "chroot_deny_chroot",
58926+ .data = &grsec_enable_chroot_double,
58927+ .maxlen = sizeof(int),
58928+ .mode = 0600,
58929+ .proc_handler = &proc_dointvec,
58930+ },
58931+#endif
58932+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58933+ {
58934+ .procname = "chroot_deny_pivot",
58935+ .data = &grsec_enable_chroot_pivot,
58936+ .maxlen = sizeof(int),
58937+ .mode = 0600,
58938+ .proc_handler = &proc_dointvec,
58939+ },
58940+#endif
58941+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58942+ {
58943+ .procname = "chroot_enforce_chdir",
58944+ .data = &grsec_enable_chroot_chdir,
58945+ .maxlen = sizeof(int),
58946+ .mode = 0600,
58947+ .proc_handler = &proc_dointvec,
58948+ },
58949+#endif
58950+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58951+ {
58952+ .procname = "chroot_deny_chmod",
58953+ .data = &grsec_enable_chroot_chmod,
58954+ .maxlen = sizeof(int),
58955+ .mode = 0600,
58956+ .proc_handler = &proc_dointvec,
58957+ },
58958+#endif
58959+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58960+ {
58961+ .procname = "chroot_deny_mknod",
58962+ .data = &grsec_enable_chroot_mknod,
58963+ .maxlen = sizeof(int),
58964+ .mode = 0600,
58965+ .proc_handler = &proc_dointvec,
58966+ },
58967+#endif
58968+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58969+ {
58970+ .procname = "chroot_restrict_nice",
58971+ .data = &grsec_enable_chroot_nice,
58972+ .maxlen = sizeof(int),
58973+ .mode = 0600,
58974+ .proc_handler = &proc_dointvec,
58975+ },
58976+#endif
58977+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58978+ {
58979+ .procname = "chroot_execlog",
58980+ .data = &grsec_enable_chroot_execlog,
58981+ .maxlen = sizeof(int),
58982+ .mode = 0600,
58983+ .proc_handler = &proc_dointvec,
58984+ },
58985+#endif
58986+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58987+ {
58988+ .procname = "chroot_caps",
58989+ .data = &grsec_enable_chroot_caps,
58990+ .maxlen = sizeof(int),
58991+ .mode = 0600,
58992+ .proc_handler = &proc_dointvec,
58993+ },
58994+#endif
58995+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58996+ {
58997+ .procname = "chroot_deny_sysctl",
58998+ .data = &grsec_enable_chroot_sysctl,
58999+ .maxlen = sizeof(int),
59000+ .mode = 0600,
59001+ .proc_handler = &proc_dointvec,
59002+ },
59003+#endif
59004+#ifdef CONFIG_GRKERNSEC_TPE
59005+ {
59006+ .procname = "tpe",
59007+ .data = &grsec_enable_tpe,
59008+ .maxlen = sizeof(int),
59009+ .mode = 0600,
59010+ .proc_handler = &proc_dointvec,
59011+ },
59012+ {
59013+ .procname = "tpe_gid",
59014+ .data = &grsec_tpe_gid,
59015+ .maxlen = sizeof(int),
59016+ .mode = 0600,
59017+ .proc_handler = &proc_dointvec,
59018+ },
59019+#endif
59020+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59021+ {
59022+ .procname = "tpe_invert",
59023+ .data = &grsec_enable_tpe_invert,
59024+ .maxlen = sizeof(int),
59025+ .mode = 0600,
59026+ .proc_handler = &proc_dointvec,
59027+ },
59028+#endif
59029+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59030+ {
59031+ .procname = "tpe_restrict_all",
59032+ .data = &grsec_enable_tpe_all,
59033+ .maxlen = sizeof(int),
59034+ .mode = 0600,
59035+ .proc_handler = &proc_dointvec,
59036+ },
59037+#endif
59038+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59039+ {
59040+ .procname = "socket_all",
59041+ .data = &grsec_enable_socket_all,
59042+ .maxlen = sizeof(int),
59043+ .mode = 0600,
59044+ .proc_handler = &proc_dointvec,
59045+ },
59046+ {
59047+ .procname = "socket_all_gid",
59048+ .data = &grsec_socket_all_gid,
59049+ .maxlen = sizeof(int),
59050+ .mode = 0600,
59051+ .proc_handler = &proc_dointvec,
59052+ },
59053+#endif
59054+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59055+ {
59056+ .procname = "socket_client",
59057+ .data = &grsec_enable_socket_client,
59058+ .maxlen = sizeof(int),
59059+ .mode = 0600,
59060+ .proc_handler = &proc_dointvec,
59061+ },
59062+ {
59063+ .procname = "socket_client_gid",
59064+ .data = &grsec_socket_client_gid,
59065+ .maxlen = sizeof(int),
59066+ .mode = 0600,
59067+ .proc_handler = &proc_dointvec,
59068+ },
59069+#endif
59070+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59071+ {
59072+ .procname = "socket_server",
59073+ .data = &grsec_enable_socket_server,
59074+ .maxlen = sizeof(int),
59075+ .mode = 0600,
59076+ .proc_handler = &proc_dointvec,
59077+ },
59078+ {
59079+ .procname = "socket_server_gid",
59080+ .data = &grsec_socket_server_gid,
59081+ .maxlen = sizeof(int),
59082+ .mode = 0600,
59083+ .proc_handler = &proc_dointvec,
59084+ },
59085+#endif
59086+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59087+ {
59088+ .procname = "audit_group",
59089+ .data = &grsec_enable_group,
59090+ .maxlen = sizeof(int),
59091+ .mode = 0600,
59092+ .proc_handler = &proc_dointvec,
59093+ },
59094+ {
59095+ .procname = "audit_gid",
59096+ .data = &grsec_audit_gid,
59097+ .maxlen = sizeof(int),
59098+ .mode = 0600,
59099+ .proc_handler = &proc_dointvec,
59100+ },
59101+#endif
59102+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59103+ {
59104+ .procname = "audit_chdir",
59105+ .data = &grsec_enable_chdir,
59106+ .maxlen = sizeof(int),
59107+ .mode = 0600,
59108+ .proc_handler = &proc_dointvec,
59109+ },
59110+#endif
59111+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59112+ {
59113+ .procname = "audit_mount",
59114+ .data = &grsec_enable_mount,
59115+ .maxlen = sizeof(int),
59116+ .mode = 0600,
59117+ .proc_handler = &proc_dointvec,
59118+ },
59119+#endif
59120+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59121+ {
59122+ .procname = "audit_textrel",
59123+ .data = &grsec_enable_audit_textrel,
59124+ .maxlen = sizeof(int),
59125+ .mode = 0600,
59126+ .proc_handler = &proc_dointvec,
59127+ },
59128+#endif
59129+#ifdef CONFIG_GRKERNSEC_DMESG
59130+ {
59131+ .procname = "dmesg",
59132+ .data = &grsec_enable_dmesg,
59133+ .maxlen = sizeof(int),
59134+ .mode = 0600,
59135+ .proc_handler = &proc_dointvec,
59136+ },
59137+#endif
59138+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59139+ {
59140+ .procname = "chroot_findtask",
59141+ .data = &grsec_enable_chroot_findtask,
59142+ .maxlen = sizeof(int),
59143+ .mode = 0600,
59144+ .proc_handler = &proc_dointvec,
59145+ },
59146+#endif
59147+#ifdef CONFIG_GRKERNSEC_RESLOG
59148+ {
59149+ .procname = "resource_logging",
59150+ .data = &grsec_resource_logging,
59151+ .maxlen = sizeof(int),
59152+ .mode = 0600,
59153+ .proc_handler = &proc_dointvec,
59154+ },
59155+#endif
59156+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59157+ {
59158+ .procname = "audit_ptrace",
59159+ .data = &grsec_enable_audit_ptrace,
59160+ .maxlen = sizeof(int),
59161+ .mode = 0600,
59162+ .proc_handler = &proc_dointvec,
59163+ },
59164+#endif
59165+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59166+ {
59167+ .procname = "harden_ptrace",
59168+ .data = &grsec_enable_harden_ptrace,
59169+ .maxlen = sizeof(int),
59170+ .mode = 0600,
59171+ .proc_handler = &proc_dointvec,
59172+ },
59173+#endif
59174+ {
59175+ .procname = "grsec_lock",
59176+ .data = &grsec_lock,
59177+ .maxlen = sizeof(int),
59178+ .mode = 0600,
59179+ .proc_handler = &proc_dointvec,
59180+ },
59181+#endif
59182+#ifdef CONFIG_GRKERNSEC_ROFS
59183+ {
59184+ .procname = "romount_protect",
59185+ .data = &grsec_enable_rofs,
59186+ .maxlen = sizeof(int),
59187+ .mode = 0600,
59188+ .proc_handler = &proc_dointvec_minmax,
59189+ .extra1 = &one,
59190+ .extra2 = &one,
59191+ },
59192+#endif
59193+ { }
59194+};
59195+#endif
59196diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59197new file mode 100644
59198index 0000000..0dc13c3
59199--- /dev/null
59200+++ b/grsecurity/grsec_time.c
59201@@ -0,0 +1,16 @@
59202+#include <linux/kernel.h>
59203+#include <linux/sched.h>
59204+#include <linux/grinternal.h>
59205+#include <linux/module.h>
59206+
59207+void
59208+gr_log_timechange(void)
59209+{
59210+#ifdef CONFIG_GRKERNSEC_TIME
59211+ if (grsec_enable_time)
59212+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59213+#endif
59214+ return;
59215+}
59216+
59217+EXPORT_SYMBOL(gr_log_timechange);
59218diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59219new file mode 100644
59220index 0000000..07e0dc0
59221--- /dev/null
59222+++ b/grsecurity/grsec_tpe.c
59223@@ -0,0 +1,73 @@
59224+#include <linux/kernel.h>
59225+#include <linux/sched.h>
59226+#include <linux/file.h>
59227+#include <linux/fs.h>
59228+#include <linux/grinternal.h>
59229+
59230+extern int gr_acl_tpe_check(void);
59231+
59232+int
59233+gr_tpe_allow(const struct file *file)
59234+{
59235+#ifdef CONFIG_GRKERNSEC
59236+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59237+ const struct cred *cred = current_cred();
59238+ char *msg = NULL;
59239+ char *msg2 = NULL;
59240+
59241+ // never restrict root
59242+ if (!cred->uid)
59243+ return 1;
59244+
59245+ if (grsec_enable_tpe) {
59246+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59247+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59248+ msg = "not being in trusted group";
59249+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59250+ msg = "being in untrusted group";
59251+#else
59252+ if (in_group_p(grsec_tpe_gid))
59253+ msg = "being in untrusted group";
59254+#endif
59255+ }
59256+ if (!msg && gr_acl_tpe_check())
59257+ msg = "being in untrusted role";
59258+
59259+ // not in any affected group/role
59260+ if (!msg)
59261+ goto next_check;
59262+
59263+ if (inode->i_uid)
59264+ msg2 = "file in non-root-owned directory";
59265+ else if (inode->i_mode & S_IWOTH)
59266+ msg2 = "file in world-writable directory";
59267+ else if (inode->i_mode & S_IWGRP)
59268+ msg2 = "file in group-writable directory";
59269+
59270+ if (msg && msg2) {
59271+ char fullmsg[70] = {0};
59272+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59273+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59274+ return 0;
59275+ }
59276+ msg = NULL;
59277+next_check:
59278+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59279+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59280+ return 1;
59281+
59282+ if (inode->i_uid && (inode->i_uid != cred->uid))
59283+ msg = "directory not owned by user";
59284+ else if (inode->i_mode & S_IWOTH)
59285+ msg = "file in world-writable directory";
59286+ else if (inode->i_mode & S_IWGRP)
59287+ msg = "file in group-writable directory";
59288+
59289+ if (msg) {
59290+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59291+ return 0;
59292+ }
59293+#endif
59294+#endif
59295+ return 1;
59296+}
59297diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59298new file mode 100644
59299index 0000000..9f7b1ac
59300--- /dev/null
59301+++ b/grsecurity/grsum.c
59302@@ -0,0 +1,61 @@
59303+#include <linux/err.h>
59304+#include <linux/kernel.h>
59305+#include <linux/sched.h>
59306+#include <linux/mm.h>
59307+#include <linux/scatterlist.h>
59308+#include <linux/crypto.h>
59309+#include <linux/gracl.h>
59310+
59311+
59312+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59313+#error "crypto and sha256 must be built into the kernel"
59314+#endif
59315+
59316+int
59317+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59318+{
59319+ char *p;
59320+ struct crypto_hash *tfm;
59321+ struct hash_desc desc;
59322+ struct scatterlist sg;
59323+ unsigned char temp_sum[GR_SHA_LEN];
59324+ volatile int retval = 0;
59325+ volatile int dummy = 0;
59326+ unsigned int i;
59327+
59328+ sg_init_table(&sg, 1);
59329+
59330+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59331+ if (IS_ERR(tfm)) {
59332+ /* should never happen, since sha256 should be built in */
59333+ return 1;
59334+ }
59335+
59336+ desc.tfm = tfm;
59337+ desc.flags = 0;
59338+
59339+ crypto_hash_init(&desc);
59340+
59341+ p = salt;
59342+ sg_set_buf(&sg, p, GR_SALT_LEN);
59343+ crypto_hash_update(&desc, &sg, sg.length);
59344+
59345+ p = entry->pw;
59346+ sg_set_buf(&sg, p, strlen(p));
59347+
59348+ crypto_hash_update(&desc, &sg, sg.length);
59349+
59350+ crypto_hash_final(&desc, temp_sum);
59351+
59352+ memset(entry->pw, 0, GR_PW_LEN);
59353+
59354+ for (i = 0; i < GR_SHA_LEN; i++)
59355+ if (sum[i] != temp_sum[i])
59356+ retval = 1;
59357+ else
59358+ dummy = 1; // waste a cycle
59359+
59360+ crypto_free_hash(tfm);
59361+
59362+ return retval;
59363+}
59364diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59365index f1c8ca6..b5c1cc7 100644
59366--- a/include/acpi/acpi_bus.h
59367+++ b/include/acpi/acpi_bus.h
59368@@ -107,7 +107,7 @@ struct acpi_device_ops {
59369 acpi_op_bind bind;
59370 acpi_op_unbind unbind;
59371 acpi_op_notify notify;
59372-};
59373+} __no_const;
59374
59375 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59376
59377diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59378index b7babf0..3ba8aee 100644
59379--- a/include/asm-generic/atomic-long.h
59380+++ b/include/asm-generic/atomic-long.h
59381@@ -22,6 +22,12 @@
59382
59383 typedef atomic64_t atomic_long_t;
59384
59385+#ifdef CONFIG_PAX_REFCOUNT
59386+typedef atomic64_unchecked_t atomic_long_unchecked_t;
59387+#else
59388+typedef atomic64_t atomic_long_unchecked_t;
59389+#endif
59390+
59391 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59392
59393 static inline long atomic_long_read(atomic_long_t *l)
59394@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59395 return (long)atomic64_read(v);
59396 }
59397
59398+#ifdef CONFIG_PAX_REFCOUNT
59399+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59400+{
59401+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59402+
59403+ return (long)atomic64_read_unchecked(v);
59404+}
59405+#endif
59406+
59407 static inline void atomic_long_set(atomic_long_t *l, long i)
59408 {
59409 atomic64_t *v = (atomic64_t *)l;
59410@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59411 atomic64_set(v, i);
59412 }
59413
59414+#ifdef CONFIG_PAX_REFCOUNT
59415+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59416+{
59417+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59418+
59419+ atomic64_set_unchecked(v, i);
59420+}
59421+#endif
59422+
59423 static inline void atomic_long_inc(atomic_long_t *l)
59424 {
59425 atomic64_t *v = (atomic64_t *)l;
59426@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59427 atomic64_inc(v);
59428 }
59429
59430+#ifdef CONFIG_PAX_REFCOUNT
59431+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59432+{
59433+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59434+
59435+ atomic64_inc_unchecked(v);
59436+}
59437+#endif
59438+
59439 static inline void atomic_long_dec(atomic_long_t *l)
59440 {
59441 atomic64_t *v = (atomic64_t *)l;
59442@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59443 atomic64_dec(v);
59444 }
59445
59446+#ifdef CONFIG_PAX_REFCOUNT
59447+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59448+{
59449+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59450+
59451+ atomic64_dec_unchecked(v);
59452+}
59453+#endif
59454+
59455 static inline void atomic_long_add(long i, atomic_long_t *l)
59456 {
59457 atomic64_t *v = (atomic64_t *)l;
59458@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59459 atomic64_add(i, v);
59460 }
59461
59462+#ifdef CONFIG_PAX_REFCOUNT
59463+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59464+{
59465+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59466+
59467+ atomic64_add_unchecked(i, v);
59468+}
59469+#endif
59470+
59471 static inline void atomic_long_sub(long i, atomic_long_t *l)
59472 {
59473 atomic64_t *v = (atomic64_t *)l;
59474@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59475 atomic64_sub(i, v);
59476 }
59477
59478+#ifdef CONFIG_PAX_REFCOUNT
59479+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59480+{
59481+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59482+
59483+ atomic64_sub_unchecked(i, v);
59484+}
59485+#endif
59486+
59487 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59488 {
59489 atomic64_t *v = (atomic64_t *)l;
59490@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59491 return (long)atomic64_inc_return(v);
59492 }
59493
59494+#ifdef CONFIG_PAX_REFCOUNT
59495+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59496+{
59497+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59498+
59499+ return (long)atomic64_inc_return_unchecked(v);
59500+}
59501+#endif
59502+
59503 static inline long atomic_long_dec_return(atomic_long_t *l)
59504 {
59505 atomic64_t *v = (atomic64_t *)l;
59506@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59507
59508 typedef atomic_t atomic_long_t;
59509
59510+#ifdef CONFIG_PAX_REFCOUNT
59511+typedef atomic_unchecked_t atomic_long_unchecked_t;
59512+#else
59513+typedef atomic_t atomic_long_unchecked_t;
59514+#endif
59515+
59516 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59517 static inline long atomic_long_read(atomic_long_t *l)
59518 {
59519@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59520 return (long)atomic_read(v);
59521 }
59522
59523+#ifdef CONFIG_PAX_REFCOUNT
59524+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59525+{
59526+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59527+
59528+ return (long)atomic_read_unchecked(v);
59529+}
59530+#endif
59531+
59532 static inline void atomic_long_set(atomic_long_t *l, long i)
59533 {
59534 atomic_t *v = (atomic_t *)l;
59535@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59536 atomic_set(v, i);
59537 }
59538
59539+#ifdef CONFIG_PAX_REFCOUNT
59540+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59541+{
59542+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59543+
59544+ atomic_set_unchecked(v, i);
59545+}
59546+#endif
59547+
59548 static inline void atomic_long_inc(atomic_long_t *l)
59549 {
59550 atomic_t *v = (atomic_t *)l;
59551@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59552 atomic_inc(v);
59553 }
59554
59555+#ifdef CONFIG_PAX_REFCOUNT
59556+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59557+{
59558+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59559+
59560+ atomic_inc_unchecked(v);
59561+}
59562+#endif
59563+
59564 static inline void atomic_long_dec(atomic_long_t *l)
59565 {
59566 atomic_t *v = (atomic_t *)l;
59567@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59568 atomic_dec(v);
59569 }
59570
59571+#ifdef CONFIG_PAX_REFCOUNT
59572+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59573+{
59574+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59575+
59576+ atomic_dec_unchecked(v);
59577+}
59578+#endif
59579+
59580 static inline void atomic_long_add(long i, atomic_long_t *l)
59581 {
59582 atomic_t *v = (atomic_t *)l;
59583@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59584 atomic_add(i, v);
59585 }
59586
59587+#ifdef CONFIG_PAX_REFCOUNT
59588+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59589+{
59590+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59591+
59592+ atomic_add_unchecked(i, v);
59593+}
59594+#endif
59595+
59596 static inline void atomic_long_sub(long i, atomic_long_t *l)
59597 {
59598 atomic_t *v = (atomic_t *)l;
59599@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59600 atomic_sub(i, v);
59601 }
59602
59603+#ifdef CONFIG_PAX_REFCOUNT
59604+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59605+{
59606+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59607+
59608+ atomic_sub_unchecked(i, v);
59609+}
59610+#endif
59611+
59612 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59613 {
59614 atomic_t *v = (atomic_t *)l;
59615@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59616 return (long)atomic_inc_return(v);
59617 }
59618
59619+#ifdef CONFIG_PAX_REFCOUNT
59620+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59621+{
59622+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59623+
59624+ return (long)atomic_inc_return_unchecked(v);
59625+}
59626+#endif
59627+
59628 static inline long atomic_long_dec_return(atomic_long_t *l)
59629 {
59630 atomic_t *v = (atomic_t *)l;
59631@@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59632
59633 #endif /* BITS_PER_LONG == 64 */
59634
59635+#ifdef CONFIG_PAX_REFCOUNT
59636+static inline void pax_refcount_needs_these_functions(void)
59637+{
59638+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
59639+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59640+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59641+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59642+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59643+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59644+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59645+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59646+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59647+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59648+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59649+#ifdef CONFIG_X86
59650+ atomic_clear_mask_unchecked(0, NULL);
59651+ atomic_set_mask_unchecked(0, NULL);
59652+#endif
59653+
59654+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59655+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59656+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59657+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59658+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59659+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59660+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59661+}
59662+#else
59663+#define atomic_read_unchecked(v) atomic_read(v)
59664+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
59665+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
59666+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
59667+#define atomic_inc_unchecked(v) atomic_inc(v)
59668+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
59669+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
59670+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
59671+#define atomic_dec_unchecked(v) atomic_dec(v)
59672+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
59673+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
59674+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
59675+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
59676+
59677+#define atomic_long_read_unchecked(v) atomic_long_read(v)
59678+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
59679+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
59680+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
59681+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
59682+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
59683+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
59684+#endif
59685+
59686 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
59687diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
59688index 1ced641..c896ee8 100644
59689--- a/include/asm-generic/atomic.h
59690+++ b/include/asm-generic/atomic.h
59691@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
59692 * Atomically clears the bits set in @mask from @v
59693 */
59694 #ifndef atomic_clear_mask
59695-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
59696+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
59697 {
59698 unsigned long flags;
59699
59700diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
59701index b18ce4f..2ee2843 100644
59702--- a/include/asm-generic/atomic64.h
59703+++ b/include/asm-generic/atomic64.h
59704@@ -16,6 +16,8 @@ typedef struct {
59705 long long counter;
59706 } atomic64_t;
59707
59708+typedef atomic64_t atomic64_unchecked_t;
59709+
59710 #define ATOMIC64_INIT(i) { (i) }
59711
59712 extern long long atomic64_read(const atomic64_t *v);
59713@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
59714 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
59715 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
59716
59717+#define atomic64_read_unchecked(v) atomic64_read(v)
59718+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
59719+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
59720+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
59721+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
59722+#define atomic64_inc_unchecked(v) atomic64_inc(v)
59723+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
59724+#define atomic64_dec_unchecked(v) atomic64_dec(v)
59725+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
59726+
59727 #endif /* _ASM_GENERIC_ATOMIC64_H */
59728diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
59729index 1bfcfe5..e04c5c9 100644
59730--- a/include/asm-generic/cache.h
59731+++ b/include/asm-generic/cache.h
59732@@ -6,7 +6,7 @@
59733 * cache lines need to provide their own cache.h.
59734 */
59735
59736-#define L1_CACHE_SHIFT 5
59737-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
59738+#define L1_CACHE_SHIFT 5UL
59739+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
59740
59741 #endif /* __ASM_GENERIC_CACHE_H */
59742diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
59743index 0d68a1e..b74a761 100644
59744--- a/include/asm-generic/emergency-restart.h
59745+++ b/include/asm-generic/emergency-restart.h
59746@@ -1,7 +1,7 @@
59747 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
59748 #define _ASM_GENERIC_EMERGENCY_RESTART_H
59749
59750-static inline void machine_emergency_restart(void)
59751+static inline __noreturn void machine_emergency_restart(void)
59752 {
59753 machine_restart(NULL);
59754 }
59755diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
59756index 0232ccb..13d9165 100644
59757--- a/include/asm-generic/kmap_types.h
59758+++ b/include/asm-generic/kmap_types.h
59759@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
59760 KMAP_D(17) KM_NMI,
59761 KMAP_D(18) KM_NMI_PTE,
59762 KMAP_D(19) KM_KDB,
59763+KMAP_D(20) KM_CLEARPAGE,
59764 /*
59765 * Remember to update debug_kmap_atomic() when adding new kmap types!
59766 */
59767-KMAP_D(20) KM_TYPE_NR
59768+KMAP_D(21) KM_TYPE_NR
59769 };
59770
59771 #undef KMAP_D
59772diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
59773index 9ceb03b..2efbcbd 100644
59774--- a/include/asm-generic/local.h
59775+++ b/include/asm-generic/local.h
59776@@ -39,6 +39,7 @@ typedef struct
59777 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
59778 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
59779 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
59780+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
59781
59782 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
59783 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
59784diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
59785index 725612b..9cc513a 100644
59786--- a/include/asm-generic/pgtable-nopmd.h
59787+++ b/include/asm-generic/pgtable-nopmd.h
59788@@ -1,14 +1,19 @@
59789 #ifndef _PGTABLE_NOPMD_H
59790 #define _PGTABLE_NOPMD_H
59791
59792-#ifndef __ASSEMBLY__
59793-
59794 #include <asm-generic/pgtable-nopud.h>
59795
59796-struct mm_struct;
59797-
59798 #define __PAGETABLE_PMD_FOLDED
59799
59800+#define PMD_SHIFT PUD_SHIFT
59801+#define PTRS_PER_PMD 1
59802+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
59803+#define PMD_MASK (~(PMD_SIZE-1))
59804+
59805+#ifndef __ASSEMBLY__
59806+
59807+struct mm_struct;
59808+
59809 /*
59810 * Having the pmd type consist of a pud gets the size right, and allows
59811 * us to conceptually access the pud entry that this pmd is folded into
59812@@ -16,11 +21,6 @@ struct mm_struct;
59813 */
59814 typedef struct { pud_t pud; } pmd_t;
59815
59816-#define PMD_SHIFT PUD_SHIFT
59817-#define PTRS_PER_PMD 1
59818-#define PMD_SIZE (1UL << PMD_SHIFT)
59819-#define PMD_MASK (~(PMD_SIZE-1))
59820-
59821 /*
59822 * The "pud_xxx()" functions here are trivial for a folded two-level
59823 * setup: the pmd is never bad, and a pmd always exists (as it's folded
59824diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
59825index 810431d..0ec4804f 100644
59826--- a/include/asm-generic/pgtable-nopud.h
59827+++ b/include/asm-generic/pgtable-nopud.h
59828@@ -1,10 +1,15 @@
59829 #ifndef _PGTABLE_NOPUD_H
59830 #define _PGTABLE_NOPUD_H
59831
59832-#ifndef __ASSEMBLY__
59833-
59834 #define __PAGETABLE_PUD_FOLDED
59835
59836+#define PUD_SHIFT PGDIR_SHIFT
59837+#define PTRS_PER_PUD 1
59838+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
59839+#define PUD_MASK (~(PUD_SIZE-1))
59840+
59841+#ifndef __ASSEMBLY__
59842+
59843 /*
59844 * Having the pud type consist of a pgd gets the size right, and allows
59845 * us to conceptually access the pgd entry that this pud is folded into
59846@@ -12,11 +17,6 @@
59847 */
59848 typedef struct { pgd_t pgd; } pud_t;
59849
59850-#define PUD_SHIFT PGDIR_SHIFT
59851-#define PTRS_PER_PUD 1
59852-#define PUD_SIZE (1UL << PUD_SHIFT)
59853-#define PUD_MASK (~(PUD_SIZE-1))
59854-
59855 /*
59856 * The "pgd_xxx()" functions here are trivial for a folded two-level
59857 * setup: the pud is never bad, and a pud always exists (as it's folded
59858@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
59859 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
59860
59861 #define pgd_populate(mm, pgd, pud) do { } while (0)
59862+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
59863 /*
59864 * (puds are folded into pgds so this doesn't get actually called,
59865 * but the define is needed for a generic inline function.)
59866diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
59867index c7ec2cd..909d125 100644
59868--- a/include/asm-generic/pgtable.h
59869+++ b/include/asm-generic/pgtable.h
59870@@ -531,6 +531,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
59871 #endif
59872 }
59873
59874+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
59875+static inline unsigned long pax_open_kernel(void) { return 0; }
59876+#endif
59877+
59878+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
59879+static inline unsigned long pax_close_kernel(void) { return 0; }
59880+#endif
59881+
59882 #endif /* CONFIG_MMU */
59883
59884 #endif /* !__ASSEMBLY__ */
59885diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
59886index 8aeadf6..f1dc019 100644
59887--- a/include/asm-generic/vmlinux.lds.h
59888+++ b/include/asm-generic/vmlinux.lds.h
59889@@ -218,6 +218,7 @@
59890 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
59891 VMLINUX_SYMBOL(__start_rodata) = .; \
59892 *(.rodata) *(.rodata.*) \
59893+ *(.data..read_only) \
59894 *(__vermagic) /* Kernel version magic */ \
59895 . = ALIGN(8); \
59896 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
59897@@ -716,17 +717,18 @@
59898 * section in the linker script will go there too. @phdr should have
59899 * a leading colon.
59900 *
59901- * Note that this macros defines __per_cpu_load as an absolute symbol.
59902+ * Note that this macros defines per_cpu_load as an absolute symbol.
59903 * If there is no need to put the percpu section at a predetermined
59904 * address, use PERCPU_SECTION.
59905 */
59906 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
59907- VMLINUX_SYMBOL(__per_cpu_load) = .; \
59908- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
59909+ per_cpu_load = .; \
59910+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
59911 - LOAD_OFFSET) { \
59912+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
59913 PERCPU_INPUT(cacheline) \
59914 } phdr \
59915- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
59916+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
59917
59918 /**
59919 * PERCPU_SECTION - define output section for percpu area, simple version
59920diff --git a/include/drm/drmP.h b/include/drm/drmP.h
59921index dd73104..fde86bd 100644
59922--- a/include/drm/drmP.h
59923+++ b/include/drm/drmP.h
59924@@ -72,6 +72,7 @@
59925 #include <linux/workqueue.h>
59926 #include <linux/poll.h>
59927 #include <asm/pgalloc.h>
59928+#include <asm/local.h>
59929 #include "drm.h"
59930
59931 #include <linux/idr.h>
59932@@ -1074,7 +1075,7 @@ struct drm_device {
59933
59934 /** \name Usage Counters */
59935 /*@{ */
59936- int open_count; /**< Outstanding files open */
59937+ local_t open_count; /**< Outstanding files open */
59938 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
59939 atomic_t vma_count; /**< Outstanding vma areas open */
59940 int buf_use; /**< Buffers in use -- cannot alloc */
59941@@ -1085,7 +1086,7 @@ struct drm_device {
59942 /*@{ */
59943 unsigned long counters;
59944 enum drm_stat_type types[15];
59945- atomic_t counts[15];
59946+ atomic_unchecked_t counts[15];
59947 /*@} */
59948
59949 struct list_head filelist;
59950diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
59951index 37515d1..34fa8b0 100644
59952--- a/include/drm/drm_crtc_helper.h
59953+++ b/include/drm/drm_crtc_helper.h
59954@@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
59955
59956 /* disable crtc when not in use - more explicit than dpms off */
59957 void (*disable)(struct drm_crtc *crtc);
59958-};
59959+} __no_const;
59960
59961 struct drm_encoder_helper_funcs {
59962 void (*dpms)(struct drm_encoder *encoder, int mode);
59963@@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
59964 struct drm_connector *connector);
59965 /* disable encoder when not in use - more explicit than dpms off */
59966 void (*disable)(struct drm_encoder *encoder);
59967-};
59968+} __no_const;
59969
59970 struct drm_connector_helper_funcs {
59971 int (*get_modes)(struct drm_connector *connector);
59972diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
59973index d6d1da4..fdd1ac5 100644
59974--- a/include/drm/ttm/ttm_memory.h
59975+++ b/include/drm/ttm/ttm_memory.h
59976@@ -48,7 +48,7 @@
59977
59978 struct ttm_mem_shrink {
59979 int (*do_shrink) (struct ttm_mem_shrink *);
59980-};
59981+} __no_const;
59982
59983 /**
59984 * struct ttm_mem_global - Global memory accounting structure.
59985diff --git a/include/linux/a.out.h b/include/linux/a.out.h
59986index e86dfca..40cc55f 100644
59987--- a/include/linux/a.out.h
59988+++ b/include/linux/a.out.h
59989@@ -39,6 +39,14 @@ enum machine_type {
59990 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
59991 };
59992
59993+/* Constants for the N_FLAGS field */
59994+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59995+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
59996+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
59997+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
59998+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59999+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60000+
60001 #if !defined (N_MAGIC)
60002 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60003 #endif
60004diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60005index 06fd4bb..1caec0d 100644
60006--- a/include/linux/atmdev.h
60007+++ b/include/linux/atmdev.h
60008@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60009 #endif
60010
60011 struct k_atm_aal_stats {
60012-#define __HANDLE_ITEM(i) atomic_t i
60013+#define __HANDLE_ITEM(i) atomic_unchecked_t i
60014 __AAL_STAT_ITEMS
60015 #undef __HANDLE_ITEM
60016 };
60017diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60018index 366422b..1fa7f84 100644
60019--- a/include/linux/binfmts.h
60020+++ b/include/linux/binfmts.h
60021@@ -89,6 +89,7 @@ struct linux_binfmt {
60022 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60023 int (*load_shlib)(struct file *);
60024 int (*core_dump)(struct coredump_params *cprm);
60025+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60026 unsigned long min_coredump; /* minimal dump size */
60027 };
60028
60029diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60030index 4d4ac24..2c3ccce 100644
60031--- a/include/linux/blkdev.h
60032+++ b/include/linux/blkdev.h
60033@@ -1376,7 +1376,7 @@ struct block_device_operations {
60034 /* this callback is with swap_lock and sometimes page table lock held */
60035 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60036 struct module *owner;
60037-};
60038+} __do_const;
60039
60040 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60041 unsigned long);
60042diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60043index 4d1a074..88f929a 100644
60044--- a/include/linux/blktrace_api.h
60045+++ b/include/linux/blktrace_api.h
60046@@ -162,7 +162,7 @@ struct blk_trace {
60047 struct dentry *dir;
60048 struct dentry *dropped_file;
60049 struct dentry *msg_file;
60050- atomic_t dropped;
60051+ atomic_unchecked_t dropped;
60052 };
60053
60054 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60055diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60056index 83195fb..0b0f77d 100644
60057--- a/include/linux/byteorder/little_endian.h
60058+++ b/include/linux/byteorder/little_endian.h
60059@@ -42,51 +42,51 @@
60060
60061 static inline __le64 __cpu_to_le64p(const __u64 *p)
60062 {
60063- return (__force __le64)*p;
60064+ return (__force const __le64)*p;
60065 }
60066 static inline __u64 __le64_to_cpup(const __le64 *p)
60067 {
60068- return (__force __u64)*p;
60069+ return (__force const __u64)*p;
60070 }
60071 static inline __le32 __cpu_to_le32p(const __u32 *p)
60072 {
60073- return (__force __le32)*p;
60074+ return (__force const __le32)*p;
60075 }
60076 static inline __u32 __le32_to_cpup(const __le32 *p)
60077 {
60078- return (__force __u32)*p;
60079+ return (__force const __u32)*p;
60080 }
60081 static inline __le16 __cpu_to_le16p(const __u16 *p)
60082 {
60083- return (__force __le16)*p;
60084+ return (__force const __le16)*p;
60085 }
60086 static inline __u16 __le16_to_cpup(const __le16 *p)
60087 {
60088- return (__force __u16)*p;
60089+ return (__force const __u16)*p;
60090 }
60091 static inline __be64 __cpu_to_be64p(const __u64 *p)
60092 {
60093- return (__force __be64)__swab64p(p);
60094+ return (__force const __be64)__swab64p(p);
60095 }
60096 static inline __u64 __be64_to_cpup(const __be64 *p)
60097 {
60098- return __swab64p((__u64 *)p);
60099+ return __swab64p((const __u64 *)p);
60100 }
60101 static inline __be32 __cpu_to_be32p(const __u32 *p)
60102 {
60103- return (__force __be32)__swab32p(p);
60104+ return (__force const __be32)__swab32p(p);
60105 }
60106 static inline __u32 __be32_to_cpup(const __be32 *p)
60107 {
60108- return __swab32p((__u32 *)p);
60109+ return __swab32p((const __u32 *)p);
60110 }
60111 static inline __be16 __cpu_to_be16p(const __u16 *p)
60112 {
60113- return (__force __be16)__swab16p(p);
60114+ return (__force const __be16)__swab16p(p);
60115 }
60116 static inline __u16 __be16_to_cpup(const __be16 *p)
60117 {
60118- return __swab16p((__u16 *)p);
60119+ return __swab16p((const __u16 *)p);
60120 }
60121 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60122 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60123diff --git a/include/linux/cache.h b/include/linux/cache.h
60124index 4c57065..4307975 100644
60125--- a/include/linux/cache.h
60126+++ b/include/linux/cache.h
60127@@ -16,6 +16,10 @@
60128 #define __read_mostly
60129 #endif
60130
60131+#ifndef __read_only
60132+#define __read_only __read_mostly
60133+#endif
60134+
60135 #ifndef ____cacheline_aligned
60136 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60137 #endif
60138diff --git a/include/linux/capability.h b/include/linux/capability.h
60139index 12d52de..b5f7fa7 100644
60140--- a/include/linux/capability.h
60141+++ b/include/linux/capability.h
60142@@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
60143 extern bool capable(int cap);
60144 extern bool ns_capable(struct user_namespace *ns, int cap);
60145 extern bool nsown_capable(int cap);
60146+extern bool capable_nolog(int cap);
60147+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60148
60149 /* audit system wants to get cap info from files as well */
60150 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60151diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60152index 42e55de..1cd0e66 100644
60153--- a/include/linux/cleancache.h
60154+++ b/include/linux/cleancache.h
60155@@ -31,7 +31,7 @@ struct cleancache_ops {
60156 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
60157 void (*invalidate_inode)(int, struct cleancache_filekey);
60158 void (*invalidate_fs)(int);
60159-};
60160+} __no_const;
60161
60162 extern struct cleancache_ops
60163 cleancache_register_ops(struct cleancache_ops *ops);
60164diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60165index 2f40791..9c9e13c 100644
60166--- a/include/linux/compiler-gcc4.h
60167+++ b/include/linux/compiler-gcc4.h
60168@@ -32,6 +32,20 @@
60169 #define __linktime_error(message) __attribute__((__error__(message)))
60170
60171 #if __GNUC_MINOR__ >= 5
60172+
60173+#ifdef CONSTIFY_PLUGIN
60174+#define __no_const __attribute__((no_const))
60175+#define __do_const __attribute__((do_const))
60176+#endif
60177+
60178+#ifdef SIZE_OVERFLOW_PLUGIN
60179+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60180+#endif
60181+
60182+#ifdef LATENT_ENTROPY_PLUGIN
60183+#define __latent_entropy __attribute__((latent_entropy))
60184+#endif
60185+
60186 /*
60187 * Mark a position in code as unreachable. This can be used to
60188 * suppress control flow warnings after asm blocks that transfer
60189@@ -47,6 +61,11 @@
60190 #define __noclone __attribute__((__noclone__))
60191
60192 #endif
60193+
60194+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60195+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60196+#define __bos0(ptr) __bos((ptr), 0)
60197+#define __bos1(ptr) __bos((ptr), 1)
60198 #endif
60199
60200 #if __GNUC_MINOR__ > 0
60201diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60202index 923d093..1fef491 100644
60203--- a/include/linux/compiler.h
60204+++ b/include/linux/compiler.h
60205@@ -5,31 +5,62 @@
60206
60207 #ifdef __CHECKER__
60208 # define __user __attribute__((noderef, address_space(1)))
60209+# define __force_user __force __user
60210 # define __kernel __attribute__((address_space(0)))
60211+# define __force_kernel __force __kernel
60212 # define __safe __attribute__((safe))
60213 # define __force __attribute__((force))
60214 # define __nocast __attribute__((nocast))
60215 # define __iomem __attribute__((noderef, address_space(2)))
60216+# define __force_iomem __force __iomem
60217 # define __acquires(x) __attribute__((context(x,0,1)))
60218 # define __releases(x) __attribute__((context(x,1,0)))
60219 # define __acquire(x) __context__(x,1)
60220 # define __release(x) __context__(x,-1)
60221 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60222 # define __percpu __attribute__((noderef, address_space(3)))
60223+# define __force_percpu __force __percpu
60224 #ifdef CONFIG_SPARSE_RCU_POINTER
60225 # define __rcu __attribute__((noderef, address_space(4)))
60226+# define __force_rcu __force __rcu
60227 #else
60228 # define __rcu
60229+# define __force_rcu
60230 #endif
60231 extern void __chk_user_ptr(const volatile void __user *);
60232 extern void __chk_io_ptr(const volatile void __iomem *);
60233+#elif defined(CHECKER_PLUGIN)
60234+//# define __user
60235+//# define __force_user
60236+//# define __kernel
60237+//# define __force_kernel
60238+# define __safe
60239+# define __force
60240+# define __nocast
60241+# define __iomem
60242+# define __force_iomem
60243+# define __chk_user_ptr(x) (void)0
60244+# define __chk_io_ptr(x) (void)0
60245+# define __builtin_warning(x, y...) (1)
60246+# define __acquires(x)
60247+# define __releases(x)
60248+# define __acquire(x) (void)0
60249+# define __release(x) (void)0
60250+# define __cond_lock(x,c) (c)
60251+# define __percpu
60252+# define __force_percpu
60253+# define __rcu
60254+# define __force_rcu
60255 #else
60256 # define __user
60257+# define __force_user
60258 # define __kernel
60259+# define __force_kernel
60260 # define __safe
60261 # define __force
60262 # define __nocast
60263 # define __iomem
60264+# define __force_iomem
60265 # define __chk_user_ptr(x) (void)0
60266 # define __chk_io_ptr(x) (void)0
60267 # define __builtin_warning(x, y...) (1)
60268@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60269 # define __release(x) (void)0
60270 # define __cond_lock(x,c) (c)
60271 # define __percpu
60272+# define __force_percpu
60273 # define __rcu
60274+# define __force_rcu
60275 #endif
60276
60277 #ifdef __KERNEL__
60278@@ -264,6 +297,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60279 # define __attribute_const__ /* unimplemented */
60280 #endif
60281
60282+#ifndef __no_const
60283+# define __no_const
60284+#endif
60285+
60286+#ifndef __do_const
60287+# define __do_const
60288+#endif
60289+
60290+#ifndef __size_overflow
60291+# define __size_overflow(...)
60292+#endif
60293+
60294+#ifndef __latent_entropy
60295+# define __latent_entropy
60296+#endif
60297+
60298 /*
60299 * Tell gcc if a function is cold. The compiler will assume any path
60300 * directly leading to the call is unlikely.
60301@@ -273,6 +322,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60302 #define __cold
60303 #endif
60304
60305+#ifndef __alloc_size
60306+#define __alloc_size(...)
60307+#endif
60308+
60309+#ifndef __bos
60310+#define __bos(ptr, arg)
60311+#endif
60312+
60313+#ifndef __bos0
60314+#define __bos0(ptr)
60315+#endif
60316+
60317+#ifndef __bos1
60318+#define __bos1(ptr)
60319+#endif
60320+
60321 /* Simple shorthand for a section definition */
60322 #ifndef __section
60323 # define __section(S) __attribute__ ((__section__(#S)))
60324@@ -308,6 +373,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60325 * use is to mediate communication between process-level code and irq/NMI
60326 * handlers, all running on the same CPU.
60327 */
60328-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60329+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60330+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60331
60332 #endif /* __LINUX_COMPILER_H */
60333diff --git a/include/linux/cred.h b/include/linux/cred.h
60334index adadf71..6af5560 100644
60335--- a/include/linux/cred.h
60336+++ b/include/linux/cred.h
60337@@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60338 static inline void validate_process_creds(void)
60339 {
60340 }
60341+static inline void validate_task_creds(struct task_struct *task)
60342+{
60343+}
60344 #endif
60345
60346 /**
60347diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60348index b92eadf..b4ecdc1 100644
60349--- a/include/linux/crypto.h
60350+++ b/include/linux/crypto.h
60351@@ -373,7 +373,7 @@ struct cipher_tfm {
60352 const u8 *key, unsigned int keylen);
60353 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60354 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60355-};
60356+} __no_const;
60357
60358 struct hash_tfm {
60359 int (*init)(struct hash_desc *desc);
60360@@ -394,13 +394,13 @@ struct compress_tfm {
60361 int (*cot_decompress)(struct crypto_tfm *tfm,
60362 const u8 *src, unsigned int slen,
60363 u8 *dst, unsigned int *dlen);
60364-};
60365+} __no_const;
60366
60367 struct rng_tfm {
60368 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60369 unsigned int dlen);
60370 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60371-};
60372+} __no_const;
60373
60374 #define crt_ablkcipher crt_u.ablkcipher
60375 #define crt_aead crt_u.aead
60376diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60377index 7925bf0..d5143d2 100644
60378--- a/include/linux/decompress/mm.h
60379+++ b/include/linux/decompress/mm.h
60380@@ -77,7 +77,7 @@ static void free(void *where)
60381 * warnings when not needed (indeed large_malloc / large_free are not
60382 * needed by inflate */
60383
60384-#define malloc(a) kmalloc(a, GFP_KERNEL)
60385+#define malloc(a) kmalloc((a), GFP_KERNEL)
60386 #define free(a) kfree(a)
60387
60388 #define large_malloc(a) vmalloc(a)
60389diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60390index dfc099e..e583e66 100644
60391--- a/include/linux/dma-mapping.h
60392+++ b/include/linux/dma-mapping.h
60393@@ -51,7 +51,7 @@ struct dma_map_ops {
60394 u64 (*get_required_mask)(struct device *dev);
60395 #endif
60396 int is_phys;
60397-};
60398+} __do_const;
60399
60400 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60401
60402diff --git a/include/linux/efi.h b/include/linux/efi.h
60403index ec45ccd..9923c32 100644
60404--- a/include/linux/efi.h
60405+++ b/include/linux/efi.h
60406@@ -635,7 +635,7 @@ struct efivar_operations {
60407 efi_get_variable_t *get_variable;
60408 efi_get_next_variable_t *get_next_variable;
60409 efi_set_variable_t *set_variable;
60410-};
60411+} __no_const;
60412
60413 struct efivars {
60414 /*
60415diff --git a/include/linux/elf.h b/include/linux/elf.h
60416index 999b4f5..57753b4 100644
60417--- a/include/linux/elf.h
60418+++ b/include/linux/elf.h
60419@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60420 #define PT_GNU_EH_FRAME 0x6474e550
60421
60422 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60423+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60424+
60425+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60426+
60427+/* Constants for the e_flags field */
60428+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60429+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60430+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60431+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60432+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60433+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60434
60435 /*
60436 * Extended Numbering
60437@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60438 #define DT_DEBUG 21
60439 #define DT_TEXTREL 22
60440 #define DT_JMPREL 23
60441+#define DT_FLAGS 30
60442+ #define DF_TEXTREL 0x00000004
60443 #define DT_ENCODING 32
60444 #define OLD_DT_LOOS 0x60000000
60445 #define DT_LOOS 0x6000000d
60446@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60447 #define PF_W 0x2
60448 #define PF_X 0x1
60449
60450+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60451+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60452+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60453+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60454+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60455+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60456+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60457+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60458+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60459+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60460+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60461+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60462+
60463 typedef struct elf32_phdr{
60464 Elf32_Word p_type;
60465 Elf32_Off p_offset;
60466@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60467 #define EI_OSABI 7
60468 #define EI_PAD 8
60469
60470+#define EI_PAX 14
60471+
60472 #define ELFMAG0 0x7f /* EI_MAG */
60473 #define ELFMAG1 'E'
60474 #define ELFMAG2 'L'
60475@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60476 #define elf_note elf32_note
60477 #define elf_addr_t Elf32_Off
60478 #define Elf_Half Elf32_Half
60479+#define elf_dyn Elf32_Dyn
60480
60481 #else
60482
60483@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60484 #define elf_note elf64_note
60485 #define elf_addr_t Elf64_Off
60486 #define Elf_Half Elf64_Half
60487+#define elf_dyn Elf64_Dyn
60488
60489 #endif
60490
60491diff --git a/include/linux/filter.h b/include/linux/filter.h
60492index 8eeb205..d59bfa2 100644
60493--- a/include/linux/filter.h
60494+++ b/include/linux/filter.h
60495@@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60496
60497 struct sk_buff;
60498 struct sock;
60499+struct bpf_jit_work;
60500
60501 struct sk_filter
60502 {
60503@@ -141,6 +142,9 @@ struct sk_filter
60504 unsigned int len; /* Number of filter blocks */
60505 unsigned int (*bpf_func)(const struct sk_buff *skb,
60506 const struct sock_filter *filter);
60507+#ifdef CONFIG_BPF_JIT
60508+ struct bpf_jit_work *work;
60509+#endif
60510 struct rcu_head rcu;
60511 struct sock_filter insns[0];
60512 };
60513diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60514index cdc9b71..ce69fb5 100644
60515--- a/include/linux/firewire.h
60516+++ b/include/linux/firewire.h
60517@@ -413,7 +413,7 @@ struct fw_iso_context {
60518 union {
60519 fw_iso_callback_t sc;
60520 fw_iso_mc_callback_t mc;
60521- } callback;
60522+ } __no_const callback;
60523 void *callback_data;
60524 };
60525
60526diff --git a/include/linux/fs.h b/include/linux/fs.h
60527index 25c40b9..1bfd4f4 100644
60528--- a/include/linux/fs.h
60529+++ b/include/linux/fs.h
60530@@ -1634,7 +1634,8 @@ struct file_operations {
60531 int (*setlease)(struct file *, long, struct file_lock **);
60532 long (*fallocate)(struct file *file, int mode, loff_t offset,
60533 loff_t len);
60534-};
60535+} __do_const;
60536+typedef struct file_operations __no_const file_operations_no_const;
60537
60538 struct inode_operations {
60539 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60540diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60541index 003dc0f..3c4ea97 100644
60542--- a/include/linux/fs_struct.h
60543+++ b/include/linux/fs_struct.h
60544@@ -6,7 +6,7 @@
60545 #include <linux/seqlock.h>
60546
60547 struct fs_struct {
60548- int users;
60549+ atomic_t users;
60550 spinlock_t lock;
60551 seqcount_t seq;
60552 int umask;
60553diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60554index ce31408..b1ad003 100644
60555--- a/include/linux/fscache-cache.h
60556+++ b/include/linux/fscache-cache.h
60557@@ -102,7 +102,7 @@ struct fscache_operation {
60558 fscache_operation_release_t release;
60559 };
60560
60561-extern atomic_t fscache_op_debug_id;
60562+extern atomic_unchecked_t fscache_op_debug_id;
60563 extern void fscache_op_work_func(struct work_struct *work);
60564
60565 extern void fscache_enqueue_operation(struct fscache_operation *);
60566@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60567 {
60568 INIT_WORK(&op->work, fscache_op_work_func);
60569 atomic_set(&op->usage, 1);
60570- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60571+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60572 op->processor = processor;
60573 op->release = release;
60574 INIT_LIST_HEAD(&op->pend_link);
60575diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60576index a6dfe69..569586df 100644
60577--- a/include/linux/fsnotify.h
60578+++ b/include/linux/fsnotify.h
60579@@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60580 */
60581 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60582 {
60583- return kstrdup(name, GFP_KERNEL);
60584+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60585 }
60586
60587 /*
60588diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60589index 91d0e0a3..035666b 100644
60590--- a/include/linux/fsnotify_backend.h
60591+++ b/include/linux/fsnotify_backend.h
60592@@ -105,6 +105,7 @@ struct fsnotify_ops {
60593 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60594 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60595 };
60596+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60597
60598 /*
60599 * A group is a "thing" that wants to receive notification about filesystem
60600diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60601index 176a939..1462211 100644
60602--- a/include/linux/ftrace_event.h
60603+++ b/include/linux/ftrace_event.h
60604@@ -97,7 +97,7 @@ struct trace_event_functions {
60605 trace_print_func raw;
60606 trace_print_func hex;
60607 trace_print_func binary;
60608-};
60609+} __no_const;
60610
60611 struct trace_event {
60612 struct hlist_node node;
60613@@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60614 extern int trace_add_event_call(struct ftrace_event_call *call);
60615 extern void trace_remove_event_call(struct ftrace_event_call *call);
60616
60617-#define is_signed_type(type) (((type)(-1)) < 0)
60618+#define is_signed_type(type) (((type)(-1)) < (type)1)
60619
60620 int trace_set_clr_event(const char *system, const char *event, int set);
60621
60622diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60623index 017a7fb..33a8507 100644
60624--- a/include/linux/genhd.h
60625+++ b/include/linux/genhd.h
60626@@ -185,7 +185,7 @@ struct gendisk {
60627 struct kobject *slave_dir;
60628
60629 struct timer_rand_state *random;
60630- atomic_t sync_io; /* RAID */
60631+ atomic_unchecked_t sync_io; /* RAID */
60632 struct disk_events *ev;
60633 #ifdef CONFIG_BLK_DEV_INTEGRITY
60634 struct blk_integrity *integrity;
60635diff --git a/include/linux/gfp.h b/include/linux/gfp.h
60636index 581e74b..8c34a24 100644
60637--- a/include/linux/gfp.h
60638+++ b/include/linux/gfp.h
60639@@ -38,6 +38,12 @@ struct vm_area_struct;
60640 #define ___GFP_OTHER_NODE 0x800000u
60641 #define ___GFP_WRITE 0x1000000u
60642
60643+#ifdef CONFIG_PAX_USERCOPY_SLABS
60644+#define ___GFP_USERCOPY 0x2000000u
60645+#else
60646+#define ___GFP_USERCOPY 0
60647+#endif
60648+
60649 /*
60650 * GFP bitmasks..
60651 *
60652@@ -87,6 +93,7 @@ struct vm_area_struct;
60653 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
60654 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
60655 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
60656+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
60657
60658 /*
60659 * This may seem redundant, but it's a way of annotating false positives vs.
60660@@ -94,7 +101,7 @@ struct vm_area_struct;
60661 */
60662 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
60663
60664-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
60665+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
60666 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
60667
60668 /* This equals 0, but use constants in case they ever change */
60669@@ -148,6 +155,8 @@ struct vm_area_struct;
60670 /* 4GB DMA on some platforms */
60671 #define GFP_DMA32 __GFP_DMA32
60672
60673+#define GFP_USERCOPY __GFP_USERCOPY
60674+
60675 /* Convert GFP flags to their corresponding migrate type */
60676 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
60677 {
60678diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60679new file mode 100644
60680index 0000000..c938b1f
60681--- /dev/null
60682+++ b/include/linux/gracl.h
60683@@ -0,0 +1,319 @@
60684+#ifndef GR_ACL_H
60685+#define GR_ACL_H
60686+
60687+#include <linux/grdefs.h>
60688+#include <linux/resource.h>
60689+#include <linux/capability.h>
60690+#include <linux/dcache.h>
60691+#include <asm/resource.h>
60692+
60693+/* Major status information */
60694+
60695+#define GR_VERSION "grsecurity 2.9.1"
60696+#define GRSECURITY_VERSION 0x2901
60697+
60698+enum {
60699+ GR_SHUTDOWN = 0,
60700+ GR_ENABLE = 1,
60701+ GR_SPROLE = 2,
60702+ GR_RELOAD = 3,
60703+ GR_SEGVMOD = 4,
60704+ GR_STATUS = 5,
60705+ GR_UNSPROLE = 6,
60706+ GR_PASSSET = 7,
60707+ GR_SPROLEPAM = 8,
60708+};
60709+
60710+/* Password setup definitions
60711+ * kernel/grhash.c */
60712+enum {
60713+ GR_PW_LEN = 128,
60714+ GR_SALT_LEN = 16,
60715+ GR_SHA_LEN = 32,
60716+};
60717+
60718+enum {
60719+ GR_SPROLE_LEN = 64,
60720+};
60721+
60722+enum {
60723+ GR_NO_GLOB = 0,
60724+ GR_REG_GLOB,
60725+ GR_CREATE_GLOB
60726+};
60727+
60728+#define GR_NLIMITS 32
60729+
60730+/* Begin Data Structures */
60731+
60732+struct sprole_pw {
60733+ unsigned char *rolename;
60734+ unsigned char salt[GR_SALT_LEN];
60735+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
60736+};
60737+
60738+struct name_entry {
60739+ __u32 key;
60740+ ino_t inode;
60741+ dev_t device;
60742+ char *name;
60743+ __u16 len;
60744+ __u8 deleted;
60745+ struct name_entry *prev;
60746+ struct name_entry *next;
60747+};
60748+
60749+struct inodev_entry {
60750+ struct name_entry *nentry;
60751+ struct inodev_entry *prev;
60752+ struct inodev_entry *next;
60753+};
60754+
60755+struct acl_role_db {
60756+ struct acl_role_label **r_hash;
60757+ __u32 r_size;
60758+};
60759+
60760+struct inodev_db {
60761+ struct inodev_entry **i_hash;
60762+ __u32 i_size;
60763+};
60764+
60765+struct name_db {
60766+ struct name_entry **n_hash;
60767+ __u32 n_size;
60768+};
60769+
60770+struct crash_uid {
60771+ uid_t uid;
60772+ unsigned long expires;
60773+};
60774+
60775+struct gr_hash_struct {
60776+ void **table;
60777+ void **nametable;
60778+ void *first;
60779+ __u32 table_size;
60780+ __u32 used_size;
60781+ int type;
60782+};
60783+
60784+/* Userspace Grsecurity ACL data structures */
60785+
60786+struct acl_subject_label {
60787+ char *filename;
60788+ ino_t inode;
60789+ dev_t device;
60790+ __u32 mode;
60791+ kernel_cap_t cap_mask;
60792+ kernel_cap_t cap_lower;
60793+ kernel_cap_t cap_invert_audit;
60794+
60795+ struct rlimit res[GR_NLIMITS];
60796+ __u32 resmask;
60797+
60798+ __u8 user_trans_type;
60799+ __u8 group_trans_type;
60800+ uid_t *user_transitions;
60801+ gid_t *group_transitions;
60802+ __u16 user_trans_num;
60803+ __u16 group_trans_num;
60804+
60805+ __u32 sock_families[2];
60806+ __u32 ip_proto[8];
60807+ __u32 ip_type;
60808+ struct acl_ip_label **ips;
60809+ __u32 ip_num;
60810+ __u32 inaddr_any_override;
60811+
60812+ __u32 crashes;
60813+ unsigned long expires;
60814+
60815+ struct acl_subject_label *parent_subject;
60816+ struct gr_hash_struct *hash;
60817+ struct acl_subject_label *prev;
60818+ struct acl_subject_label *next;
60819+
60820+ struct acl_object_label **obj_hash;
60821+ __u32 obj_hash_size;
60822+ __u16 pax_flags;
60823+};
60824+
60825+struct role_allowed_ip {
60826+ __u32 addr;
60827+ __u32 netmask;
60828+
60829+ struct role_allowed_ip *prev;
60830+ struct role_allowed_ip *next;
60831+};
60832+
60833+struct role_transition {
60834+ char *rolename;
60835+
60836+ struct role_transition *prev;
60837+ struct role_transition *next;
60838+};
60839+
60840+struct acl_role_label {
60841+ char *rolename;
60842+ uid_t uidgid;
60843+ __u16 roletype;
60844+
60845+ __u16 auth_attempts;
60846+ unsigned long expires;
60847+
60848+ struct acl_subject_label *root_label;
60849+ struct gr_hash_struct *hash;
60850+
60851+ struct acl_role_label *prev;
60852+ struct acl_role_label *next;
60853+
60854+ struct role_transition *transitions;
60855+ struct role_allowed_ip *allowed_ips;
60856+ uid_t *domain_children;
60857+ __u16 domain_child_num;
60858+
60859+ umode_t umask;
60860+
60861+ struct acl_subject_label **subj_hash;
60862+ __u32 subj_hash_size;
60863+};
60864+
60865+struct user_acl_role_db {
60866+ struct acl_role_label **r_table;
60867+ __u32 num_pointers; /* Number of allocations to track */
60868+ __u32 num_roles; /* Number of roles */
60869+ __u32 num_domain_children; /* Number of domain children */
60870+ __u32 num_subjects; /* Number of subjects */
60871+ __u32 num_objects; /* Number of objects */
60872+};
60873+
60874+struct acl_object_label {
60875+ char *filename;
60876+ ino_t inode;
60877+ dev_t device;
60878+ __u32 mode;
60879+
60880+ struct acl_subject_label *nested;
60881+ struct acl_object_label *globbed;
60882+
60883+ /* next two structures not used */
60884+
60885+ struct acl_object_label *prev;
60886+ struct acl_object_label *next;
60887+};
60888+
60889+struct acl_ip_label {
60890+ char *iface;
60891+ __u32 addr;
60892+ __u32 netmask;
60893+ __u16 low, high;
60894+ __u8 mode;
60895+ __u32 type;
60896+ __u32 proto[8];
60897+
60898+ /* next two structures not used */
60899+
60900+ struct acl_ip_label *prev;
60901+ struct acl_ip_label *next;
60902+};
60903+
60904+struct gr_arg {
60905+ struct user_acl_role_db role_db;
60906+ unsigned char pw[GR_PW_LEN];
60907+ unsigned char salt[GR_SALT_LEN];
60908+ unsigned char sum[GR_SHA_LEN];
60909+ unsigned char sp_role[GR_SPROLE_LEN];
60910+ struct sprole_pw *sprole_pws;
60911+ dev_t segv_device;
60912+ ino_t segv_inode;
60913+ uid_t segv_uid;
60914+ __u16 num_sprole_pws;
60915+ __u16 mode;
60916+};
60917+
60918+struct gr_arg_wrapper {
60919+ struct gr_arg *arg;
60920+ __u32 version;
60921+ __u32 size;
60922+};
60923+
60924+struct subject_map {
60925+ struct acl_subject_label *user;
60926+ struct acl_subject_label *kernel;
60927+ struct subject_map *prev;
60928+ struct subject_map *next;
60929+};
60930+
60931+struct acl_subj_map_db {
60932+ struct subject_map **s_hash;
60933+ __u32 s_size;
60934+};
60935+
60936+/* End Data Structures Section */
60937+
60938+/* Hash functions generated by empirical testing by Brad Spengler
60939+ Makes good use of the low bits of the inode. Generally 0-1 times
60940+ in loop for successful match. 0-3 for unsuccessful match.
60941+ Shift/add algorithm with modulus of table size and an XOR*/
60942+
60943+static __inline__ unsigned int
60944+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
60945+{
60946+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
60947+}
60948+
60949+ static __inline__ unsigned int
60950+shash(const struct acl_subject_label *userp, const unsigned int sz)
60951+{
60952+ return ((const unsigned long)userp % sz);
60953+}
60954+
60955+static __inline__ unsigned int
60956+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
60957+{
60958+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
60959+}
60960+
60961+static __inline__ unsigned int
60962+nhash(const char *name, const __u16 len, const unsigned int sz)
60963+{
60964+ return full_name_hash((const unsigned char *)name, len) % sz;
60965+}
60966+
60967+#define FOR_EACH_ROLE_START(role) \
60968+ role = role_list; \
60969+ while (role) {
60970+
60971+#define FOR_EACH_ROLE_END(role) \
60972+ role = role->prev; \
60973+ }
60974+
60975+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
60976+ subj = NULL; \
60977+ iter = 0; \
60978+ while (iter < role->subj_hash_size) { \
60979+ if (subj == NULL) \
60980+ subj = role->subj_hash[iter]; \
60981+ if (subj == NULL) { \
60982+ iter++; \
60983+ continue; \
60984+ }
60985+
60986+#define FOR_EACH_SUBJECT_END(subj,iter) \
60987+ subj = subj->next; \
60988+ if (subj == NULL) \
60989+ iter++; \
60990+ }
60991+
60992+
60993+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
60994+ subj = role->hash->first; \
60995+ while (subj != NULL) {
60996+
60997+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
60998+ subj = subj->next; \
60999+ }
61000+
61001+#endif
61002+
61003diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61004new file mode 100644
61005index 0000000..323ecf2
61006--- /dev/null
61007+++ b/include/linux/gralloc.h
61008@@ -0,0 +1,9 @@
61009+#ifndef __GRALLOC_H
61010+#define __GRALLOC_H
61011+
61012+void acl_free_all(void);
61013+int acl_alloc_stack_init(unsigned long size);
61014+void *acl_alloc(unsigned long len);
61015+void *acl_alloc_num(unsigned long num, unsigned long len);
61016+
61017+#endif
61018diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61019new file mode 100644
61020index 0000000..b30e9bc
61021--- /dev/null
61022+++ b/include/linux/grdefs.h
61023@@ -0,0 +1,140 @@
61024+#ifndef GRDEFS_H
61025+#define GRDEFS_H
61026+
61027+/* Begin grsecurity status declarations */
61028+
61029+enum {
61030+ GR_READY = 0x01,
61031+ GR_STATUS_INIT = 0x00 // disabled state
61032+};
61033+
61034+/* Begin ACL declarations */
61035+
61036+/* Role flags */
61037+
61038+enum {
61039+ GR_ROLE_USER = 0x0001,
61040+ GR_ROLE_GROUP = 0x0002,
61041+ GR_ROLE_DEFAULT = 0x0004,
61042+ GR_ROLE_SPECIAL = 0x0008,
61043+ GR_ROLE_AUTH = 0x0010,
61044+ GR_ROLE_NOPW = 0x0020,
61045+ GR_ROLE_GOD = 0x0040,
61046+ GR_ROLE_LEARN = 0x0080,
61047+ GR_ROLE_TPE = 0x0100,
61048+ GR_ROLE_DOMAIN = 0x0200,
61049+ GR_ROLE_PAM = 0x0400,
61050+ GR_ROLE_PERSIST = 0x0800
61051+};
61052+
61053+/* ACL Subject and Object mode flags */
61054+enum {
61055+ GR_DELETED = 0x80000000
61056+};
61057+
61058+/* ACL Object-only mode flags */
61059+enum {
61060+ GR_READ = 0x00000001,
61061+ GR_APPEND = 0x00000002,
61062+ GR_WRITE = 0x00000004,
61063+ GR_EXEC = 0x00000008,
61064+ GR_FIND = 0x00000010,
61065+ GR_INHERIT = 0x00000020,
61066+ GR_SETID = 0x00000040,
61067+ GR_CREATE = 0x00000080,
61068+ GR_DELETE = 0x00000100,
61069+ GR_LINK = 0x00000200,
61070+ GR_AUDIT_READ = 0x00000400,
61071+ GR_AUDIT_APPEND = 0x00000800,
61072+ GR_AUDIT_WRITE = 0x00001000,
61073+ GR_AUDIT_EXEC = 0x00002000,
61074+ GR_AUDIT_FIND = 0x00004000,
61075+ GR_AUDIT_INHERIT= 0x00008000,
61076+ GR_AUDIT_SETID = 0x00010000,
61077+ GR_AUDIT_CREATE = 0x00020000,
61078+ GR_AUDIT_DELETE = 0x00040000,
61079+ GR_AUDIT_LINK = 0x00080000,
61080+ GR_PTRACERD = 0x00100000,
61081+ GR_NOPTRACE = 0x00200000,
61082+ GR_SUPPRESS = 0x00400000,
61083+ GR_NOLEARN = 0x00800000,
61084+ GR_INIT_TRANSFER= 0x01000000
61085+};
61086+
61087+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61088+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61089+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61090+
61091+/* ACL subject-only mode flags */
61092+enum {
61093+ GR_KILL = 0x00000001,
61094+ GR_VIEW = 0x00000002,
61095+ GR_PROTECTED = 0x00000004,
61096+ GR_LEARN = 0x00000008,
61097+ GR_OVERRIDE = 0x00000010,
61098+ /* just a placeholder, this mode is only used in userspace */
61099+ GR_DUMMY = 0x00000020,
61100+ GR_PROTSHM = 0x00000040,
61101+ GR_KILLPROC = 0x00000080,
61102+ GR_KILLIPPROC = 0x00000100,
61103+ /* just a placeholder, this mode is only used in userspace */
61104+ GR_NOTROJAN = 0x00000200,
61105+ GR_PROTPROCFD = 0x00000400,
61106+ GR_PROCACCT = 0x00000800,
61107+ GR_RELAXPTRACE = 0x00001000,
61108+ GR_NESTED = 0x00002000,
61109+ GR_INHERITLEARN = 0x00004000,
61110+ GR_PROCFIND = 0x00008000,
61111+ GR_POVERRIDE = 0x00010000,
61112+ GR_KERNELAUTH = 0x00020000,
61113+ GR_ATSECURE = 0x00040000,
61114+ GR_SHMEXEC = 0x00080000
61115+};
61116+
61117+enum {
61118+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61119+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61120+ GR_PAX_ENABLE_MPROTECT = 0x0004,
61121+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
61122+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61123+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61124+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61125+ GR_PAX_DISABLE_MPROTECT = 0x0400,
61126+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
61127+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61128+};
61129+
61130+enum {
61131+ GR_ID_USER = 0x01,
61132+ GR_ID_GROUP = 0x02,
61133+};
61134+
61135+enum {
61136+ GR_ID_ALLOW = 0x01,
61137+ GR_ID_DENY = 0x02,
61138+};
61139+
61140+#define GR_CRASH_RES 31
61141+#define GR_UIDTABLE_MAX 500
61142+
61143+/* begin resource learning section */
61144+enum {
61145+ GR_RLIM_CPU_BUMP = 60,
61146+ GR_RLIM_FSIZE_BUMP = 50000,
61147+ GR_RLIM_DATA_BUMP = 10000,
61148+ GR_RLIM_STACK_BUMP = 1000,
61149+ GR_RLIM_CORE_BUMP = 10000,
61150+ GR_RLIM_RSS_BUMP = 500000,
61151+ GR_RLIM_NPROC_BUMP = 1,
61152+ GR_RLIM_NOFILE_BUMP = 5,
61153+ GR_RLIM_MEMLOCK_BUMP = 50000,
61154+ GR_RLIM_AS_BUMP = 500000,
61155+ GR_RLIM_LOCKS_BUMP = 2,
61156+ GR_RLIM_SIGPENDING_BUMP = 5,
61157+ GR_RLIM_MSGQUEUE_BUMP = 10000,
61158+ GR_RLIM_NICE_BUMP = 1,
61159+ GR_RLIM_RTPRIO_BUMP = 1,
61160+ GR_RLIM_RTTIME_BUMP = 1000000
61161+};
61162+
61163+#endif
61164diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61165new file mode 100644
61166index 0000000..c9292f7
61167--- /dev/null
61168+++ b/include/linux/grinternal.h
61169@@ -0,0 +1,223 @@
61170+#ifndef __GRINTERNAL_H
61171+#define __GRINTERNAL_H
61172+
61173+#ifdef CONFIG_GRKERNSEC
61174+
61175+#include <linux/fs.h>
61176+#include <linux/mnt_namespace.h>
61177+#include <linux/nsproxy.h>
61178+#include <linux/gracl.h>
61179+#include <linux/grdefs.h>
61180+#include <linux/grmsg.h>
61181+
61182+void gr_add_learn_entry(const char *fmt, ...)
61183+ __attribute__ ((format (printf, 1, 2)));
61184+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61185+ const struct vfsmount *mnt);
61186+__u32 gr_check_create(const struct dentry *new_dentry,
61187+ const struct dentry *parent,
61188+ const struct vfsmount *mnt, const __u32 mode);
61189+int gr_check_protected_task(const struct task_struct *task);
61190+__u32 to_gr_audit(const __u32 reqmode);
61191+int gr_set_acls(const int type);
61192+int gr_apply_subject_to_task(struct task_struct *task);
61193+int gr_acl_is_enabled(void);
61194+char gr_roletype_to_char(void);
61195+
61196+void gr_handle_alertkill(struct task_struct *task);
61197+char *gr_to_filename(const struct dentry *dentry,
61198+ const struct vfsmount *mnt);
61199+char *gr_to_filename1(const struct dentry *dentry,
61200+ const struct vfsmount *mnt);
61201+char *gr_to_filename2(const struct dentry *dentry,
61202+ const struct vfsmount *mnt);
61203+char *gr_to_filename3(const struct dentry *dentry,
61204+ const struct vfsmount *mnt);
61205+
61206+extern int grsec_enable_ptrace_readexec;
61207+extern int grsec_enable_harden_ptrace;
61208+extern int grsec_enable_link;
61209+extern int grsec_enable_fifo;
61210+extern int grsec_enable_execve;
61211+extern int grsec_enable_shm;
61212+extern int grsec_enable_execlog;
61213+extern int grsec_enable_signal;
61214+extern int grsec_enable_audit_ptrace;
61215+extern int grsec_enable_forkfail;
61216+extern int grsec_enable_time;
61217+extern int grsec_enable_rofs;
61218+extern int grsec_enable_chroot_shmat;
61219+extern int grsec_enable_chroot_mount;
61220+extern int grsec_enable_chroot_double;
61221+extern int grsec_enable_chroot_pivot;
61222+extern int grsec_enable_chroot_chdir;
61223+extern int grsec_enable_chroot_chmod;
61224+extern int grsec_enable_chroot_mknod;
61225+extern int grsec_enable_chroot_fchdir;
61226+extern int grsec_enable_chroot_nice;
61227+extern int grsec_enable_chroot_execlog;
61228+extern int grsec_enable_chroot_caps;
61229+extern int grsec_enable_chroot_sysctl;
61230+extern int grsec_enable_chroot_unix;
61231+extern int grsec_enable_symlinkown;
61232+extern int grsec_symlinkown_gid;
61233+extern int grsec_enable_tpe;
61234+extern int grsec_tpe_gid;
61235+extern int grsec_enable_tpe_all;
61236+extern int grsec_enable_tpe_invert;
61237+extern int grsec_enable_socket_all;
61238+extern int grsec_socket_all_gid;
61239+extern int grsec_enable_socket_client;
61240+extern int grsec_socket_client_gid;
61241+extern int grsec_enable_socket_server;
61242+extern int grsec_socket_server_gid;
61243+extern int grsec_audit_gid;
61244+extern int grsec_enable_group;
61245+extern int grsec_enable_audit_textrel;
61246+extern int grsec_enable_log_rwxmaps;
61247+extern int grsec_enable_mount;
61248+extern int grsec_enable_chdir;
61249+extern int grsec_resource_logging;
61250+extern int grsec_enable_blackhole;
61251+extern int grsec_lastack_retries;
61252+extern int grsec_enable_brute;
61253+extern int grsec_lock;
61254+
61255+extern spinlock_t grsec_alert_lock;
61256+extern unsigned long grsec_alert_wtime;
61257+extern unsigned long grsec_alert_fyet;
61258+
61259+extern spinlock_t grsec_audit_lock;
61260+
61261+extern rwlock_t grsec_exec_file_lock;
61262+
61263+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61264+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61265+ (tsk)->exec_file->f_vfsmnt) : "/")
61266+
61267+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61268+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61269+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61270+
61271+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61272+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
61273+ (tsk)->exec_file->f_vfsmnt) : "/")
61274+
61275+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61276+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61277+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61278+
61279+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61280+
61281+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61282+
61283+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61284+ (task)->pid, (cred)->uid, \
61285+ (cred)->euid, (cred)->gid, (cred)->egid, \
61286+ gr_parent_task_fullpath(task), \
61287+ (task)->real_parent->comm, (task)->real_parent->pid, \
61288+ (pcred)->uid, (pcred)->euid, \
61289+ (pcred)->gid, (pcred)->egid
61290+
61291+#define GR_CHROOT_CAPS {{ \
61292+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61293+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61294+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61295+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61296+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61297+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61298+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61299+
61300+#define security_learn(normal_msg,args...) \
61301+({ \
61302+ read_lock(&grsec_exec_file_lock); \
61303+ gr_add_learn_entry(normal_msg "\n", ## args); \
61304+ read_unlock(&grsec_exec_file_lock); \
61305+})
61306+
61307+enum {
61308+ GR_DO_AUDIT,
61309+ GR_DONT_AUDIT,
61310+ /* used for non-audit messages that we shouldn't kill the task on */
61311+ GR_DONT_AUDIT_GOOD
61312+};
61313+
61314+enum {
61315+ GR_TTYSNIFF,
61316+ GR_RBAC,
61317+ GR_RBAC_STR,
61318+ GR_STR_RBAC,
61319+ GR_RBAC_MODE2,
61320+ GR_RBAC_MODE3,
61321+ GR_FILENAME,
61322+ GR_SYSCTL_HIDDEN,
61323+ GR_NOARGS,
61324+ GR_ONE_INT,
61325+ GR_ONE_INT_TWO_STR,
61326+ GR_ONE_STR,
61327+ GR_STR_INT,
61328+ GR_TWO_STR_INT,
61329+ GR_TWO_INT,
61330+ GR_TWO_U64,
61331+ GR_THREE_INT,
61332+ GR_FIVE_INT_TWO_STR,
61333+ GR_TWO_STR,
61334+ GR_THREE_STR,
61335+ GR_FOUR_STR,
61336+ GR_STR_FILENAME,
61337+ GR_FILENAME_STR,
61338+ GR_FILENAME_TWO_INT,
61339+ GR_FILENAME_TWO_INT_STR,
61340+ GR_TEXTREL,
61341+ GR_PTRACE,
61342+ GR_RESOURCE,
61343+ GR_CAP,
61344+ GR_SIG,
61345+ GR_SIG2,
61346+ GR_CRASH1,
61347+ GR_CRASH2,
61348+ GR_PSACCT,
61349+ GR_RWXMAP
61350+};
61351+
61352+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61353+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61354+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61355+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61356+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61357+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61358+#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)
61359+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61360+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61361+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61362+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61363+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61364+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61365+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61366+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61367+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61368+#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)
61369+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61370+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61371+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61372+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61373+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61374+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61375+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61376+#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)
61377+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61378+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61379+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61380+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61381+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61382+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61383+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61384+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61385+#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)
61386+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61387+
61388+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61389+
61390+#endif
61391+
61392+#endif
61393diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61394new file mode 100644
61395index 0000000..54f4e85
61396--- /dev/null
61397+++ b/include/linux/grmsg.h
61398@@ -0,0 +1,110 @@
61399+#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"
61400+#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"
61401+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61402+#define GR_STOPMOD_MSG "denied modification of module state by "
61403+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61404+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61405+#define GR_IOPERM_MSG "denied use of ioperm() by "
61406+#define GR_IOPL_MSG "denied use of iopl() by "
61407+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61408+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61409+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61410+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61411+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61412+#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"
61413+#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"
61414+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61415+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61416+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61417+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61418+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61419+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61420+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61421+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61422+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61423+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61424+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61425+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61426+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61427+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61428+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61429+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61430+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61431+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61432+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61433+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61434+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61435+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61436+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61437+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61438+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61439+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61440+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61441+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61442+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61443+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61444+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61445+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61446+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61447+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61448+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61449+#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"
61450+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61451+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61452+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61453+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61454+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61455+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61456+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61457+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61458+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61459+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61460+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61461+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61462+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61463+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61464+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61465+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61466+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61467+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61468+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61469+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61470+#define GR_FAILFORK_MSG "failed fork with errno %s by "
61471+#define GR_NICE_CHROOT_MSG "denied priority change by "
61472+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61473+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61474+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61475+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61476+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61477+#define GR_TIME_MSG "time set by "
61478+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61479+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61480+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61481+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61482+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61483+#define GR_BIND_MSG "denied bind() by "
61484+#define GR_CONNECT_MSG "denied connect() by "
61485+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61486+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61487+#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"
61488+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61489+#define GR_CAP_ACL_MSG "use of %s denied for "
61490+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61491+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61492+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61493+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61494+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61495+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61496+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61497+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61498+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61499+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61500+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61501+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61502+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61503+#define GR_VM86_MSG "denied use of vm86 by "
61504+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61505+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61506+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61507+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61508+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
61509diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61510new file mode 100644
61511index 0000000..38bfb04
61512--- /dev/null
61513+++ b/include/linux/grsecurity.h
61514@@ -0,0 +1,233 @@
61515+#ifndef GR_SECURITY_H
61516+#define GR_SECURITY_H
61517+#include <linux/fs.h>
61518+#include <linux/fs_struct.h>
61519+#include <linux/binfmts.h>
61520+#include <linux/gracl.h>
61521+
61522+/* notify of brain-dead configs */
61523+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61524+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61525+#endif
61526+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61527+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61528+#endif
61529+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61530+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61531+#endif
61532+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61533+#error "CONFIG_PAX enabled, but no PaX options are enabled."
61534+#endif
61535+
61536+#include <linux/compat.h>
61537+
61538+struct user_arg_ptr {
61539+#ifdef CONFIG_COMPAT
61540+ bool is_compat;
61541+#endif
61542+ union {
61543+ const char __user *const __user *native;
61544+#ifdef CONFIG_COMPAT
61545+ compat_uptr_t __user *compat;
61546+#endif
61547+ } ptr;
61548+};
61549+
61550+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61551+void gr_handle_brute_check(void);
61552+void gr_handle_kernel_exploit(void);
61553+int gr_process_user_ban(void);
61554+
61555+char gr_roletype_to_char(void);
61556+
61557+int gr_acl_enable_at_secure(void);
61558+
61559+int gr_check_user_change(int real, int effective, int fs);
61560+int gr_check_group_change(int real, int effective, int fs);
61561+
61562+void gr_del_task_from_ip_table(struct task_struct *p);
61563+
61564+int gr_pid_is_chrooted(struct task_struct *p);
61565+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61566+int gr_handle_chroot_nice(void);
61567+int gr_handle_chroot_sysctl(const int op);
61568+int gr_handle_chroot_setpriority(struct task_struct *p,
61569+ const int niceval);
61570+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61571+int gr_handle_chroot_chroot(const struct dentry *dentry,
61572+ const struct vfsmount *mnt);
61573+void gr_handle_chroot_chdir(struct path *path);
61574+int gr_handle_chroot_chmod(const struct dentry *dentry,
61575+ const struct vfsmount *mnt, const int mode);
61576+int gr_handle_chroot_mknod(const struct dentry *dentry,
61577+ const struct vfsmount *mnt, const int mode);
61578+int gr_handle_chroot_mount(const struct dentry *dentry,
61579+ const struct vfsmount *mnt,
61580+ const char *dev_name);
61581+int gr_handle_chroot_pivot(void);
61582+int gr_handle_chroot_unix(const pid_t pid);
61583+
61584+int gr_handle_rawio(const struct inode *inode);
61585+
61586+void gr_handle_ioperm(void);
61587+void gr_handle_iopl(void);
61588+
61589+umode_t gr_acl_umask(void);
61590+
61591+int gr_tpe_allow(const struct file *file);
61592+
61593+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61594+void gr_clear_chroot_entries(struct task_struct *task);
61595+
61596+void gr_log_forkfail(const int retval);
61597+void gr_log_timechange(void);
61598+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61599+void gr_log_chdir(const struct dentry *dentry,
61600+ const struct vfsmount *mnt);
61601+void gr_log_chroot_exec(const struct dentry *dentry,
61602+ const struct vfsmount *mnt);
61603+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61604+void gr_log_remount(const char *devname, const int retval);
61605+void gr_log_unmount(const char *devname, const int retval);
61606+void gr_log_mount(const char *from, const char *to, const int retval);
61607+void gr_log_textrel(struct vm_area_struct *vma);
61608+void gr_log_rwxmmap(struct file *file);
61609+void gr_log_rwxmprotect(struct file *file);
61610+
61611+int gr_handle_follow_link(const struct inode *parent,
61612+ const struct inode *inode,
61613+ const struct dentry *dentry,
61614+ const struct vfsmount *mnt);
61615+int gr_handle_fifo(const struct dentry *dentry,
61616+ const struct vfsmount *mnt,
61617+ const struct dentry *dir, const int flag,
61618+ const int acc_mode);
61619+int gr_handle_hardlink(const struct dentry *dentry,
61620+ const struct vfsmount *mnt,
61621+ struct inode *inode,
61622+ const int mode, const char *to);
61623+
61624+int gr_is_capable(const int cap);
61625+int gr_is_capable_nolog(const int cap);
61626+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61627+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
61628+
61629+void gr_learn_resource(const struct task_struct *task, const int limit,
61630+ const unsigned long wanted, const int gt);
61631+void gr_copy_label(struct task_struct *tsk);
61632+void gr_handle_crash(struct task_struct *task, const int sig);
61633+int gr_handle_signal(const struct task_struct *p, const int sig);
61634+int gr_check_crash_uid(const uid_t uid);
61635+int gr_check_protected_task(const struct task_struct *task);
61636+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
61637+int gr_acl_handle_mmap(const struct file *file,
61638+ const unsigned long prot);
61639+int gr_acl_handle_mprotect(const struct file *file,
61640+ const unsigned long prot);
61641+int gr_check_hidden_task(const struct task_struct *tsk);
61642+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
61643+ const struct vfsmount *mnt);
61644+__u32 gr_acl_handle_utime(const struct dentry *dentry,
61645+ const struct vfsmount *mnt);
61646+__u32 gr_acl_handle_access(const struct dentry *dentry,
61647+ const struct vfsmount *mnt, const int fmode);
61648+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61649+ const struct vfsmount *mnt, umode_t *mode);
61650+__u32 gr_acl_handle_chown(const struct dentry *dentry,
61651+ const struct vfsmount *mnt);
61652+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61653+ const struct vfsmount *mnt);
61654+int gr_handle_ptrace(struct task_struct *task, const long request);
61655+int gr_handle_proc_ptrace(struct task_struct *task);
61656+__u32 gr_acl_handle_execve(const struct dentry *dentry,
61657+ const struct vfsmount *mnt);
61658+int gr_check_crash_exec(const struct file *filp);
61659+int gr_acl_is_enabled(void);
61660+void gr_set_kernel_label(struct task_struct *task);
61661+void gr_set_role_label(struct task_struct *task, const uid_t uid,
61662+ const gid_t gid);
61663+int gr_set_proc_label(const struct dentry *dentry,
61664+ const struct vfsmount *mnt,
61665+ const int unsafe_flags);
61666+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61667+ const struct vfsmount *mnt);
61668+__u32 gr_acl_handle_open(const struct dentry *dentry,
61669+ const struct vfsmount *mnt, int acc_mode);
61670+__u32 gr_acl_handle_creat(const struct dentry *dentry,
61671+ const struct dentry *p_dentry,
61672+ const struct vfsmount *p_mnt,
61673+ int open_flags, int acc_mode, const int imode);
61674+void gr_handle_create(const struct dentry *dentry,
61675+ const struct vfsmount *mnt);
61676+void gr_handle_proc_create(const struct dentry *dentry,
61677+ const struct inode *inode);
61678+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61679+ const struct dentry *parent_dentry,
61680+ const struct vfsmount *parent_mnt,
61681+ const int mode);
61682+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61683+ const struct dentry *parent_dentry,
61684+ const struct vfsmount *parent_mnt);
61685+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61686+ const struct vfsmount *mnt);
61687+void gr_handle_delete(const ino_t ino, const dev_t dev);
61688+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61689+ const struct vfsmount *mnt);
61690+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61691+ const struct dentry *parent_dentry,
61692+ const struct vfsmount *parent_mnt,
61693+ const char *from);
61694+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61695+ const struct dentry *parent_dentry,
61696+ const struct vfsmount *parent_mnt,
61697+ const struct dentry *old_dentry,
61698+ const struct vfsmount *old_mnt, const char *to);
61699+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
61700+int gr_acl_handle_rename(struct dentry *new_dentry,
61701+ struct dentry *parent_dentry,
61702+ const struct vfsmount *parent_mnt,
61703+ struct dentry *old_dentry,
61704+ struct inode *old_parent_inode,
61705+ struct vfsmount *old_mnt, const char *newname);
61706+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61707+ struct dentry *old_dentry,
61708+ struct dentry *new_dentry,
61709+ struct vfsmount *mnt, const __u8 replace);
61710+__u32 gr_check_link(const struct dentry *new_dentry,
61711+ const struct dentry *parent_dentry,
61712+ const struct vfsmount *parent_mnt,
61713+ const struct dentry *old_dentry,
61714+ const struct vfsmount *old_mnt);
61715+int gr_acl_handle_filldir(const struct file *file, const char *name,
61716+ const unsigned int namelen, const ino_t ino);
61717+
61718+__u32 gr_acl_handle_unix(const struct dentry *dentry,
61719+ const struct vfsmount *mnt);
61720+void gr_acl_handle_exit(void);
61721+void gr_acl_handle_psacct(struct task_struct *task, const long code);
61722+int gr_acl_handle_procpidmem(const struct task_struct *task);
61723+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
61724+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
61725+void gr_audit_ptrace(struct task_struct *task);
61726+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
61727+
61728+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
61729+
61730+#ifdef CONFIG_GRKERNSEC
61731+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
61732+void gr_handle_vm86(void);
61733+void gr_handle_mem_readwrite(u64 from, u64 to);
61734+
61735+void gr_log_badprocpid(const char *entry);
61736+
61737+extern int grsec_enable_dmesg;
61738+extern int grsec_disable_privio;
61739+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61740+extern int grsec_enable_chroot_findtask;
61741+#endif
61742+#ifdef CONFIG_GRKERNSEC_SETXID
61743+extern int grsec_enable_setxid;
61744+#endif
61745+#endif
61746+
61747+#endif
61748diff --git a/include/linux/grsock.h b/include/linux/grsock.h
61749new file mode 100644
61750index 0000000..e7ffaaf
61751--- /dev/null
61752+++ b/include/linux/grsock.h
61753@@ -0,0 +1,19 @@
61754+#ifndef __GRSOCK_H
61755+#define __GRSOCK_H
61756+
61757+extern void gr_attach_curr_ip(const struct sock *sk);
61758+extern int gr_handle_sock_all(const int family, const int type,
61759+ const int protocol);
61760+extern int gr_handle_sock_server(const struct sockaddr *sck);
61761+extern int gr_handle_sock_server_other(const struct sock *sck);
61762+extern int gr_handle_sock_client(const struct sockaddr *sck);
61763+extern int gr_search_connect(struct socket * sock,
61764+ struct sockaddr_in * addr);
61765+extern int gr_search_bind(struct socket * sock,
61766+ struct sockaddr_in * addr);
61767+extern int gr_search_listen(struct socket * sock);
61768+extern int gr_search_accept(struct socket * sock);
61769+extern int gr_search_socket(const int domain, const int type,
61770+ const int protocol);
61771+
61772+#endif
61773diff --git a/include/linux/hid.h b/include/linux/hid.h
61774index 3a95da6..51986f1 100644
61775--- a/include/linux/hid.h
61776+++ b/include/linux/hid.h
61777@@ -696,7 +696,7 @@ struct hid_ll_driver {
61778 unsigned int code, int value);
61779
61780 int (*parse)(struct hid_device *hdev);
61781-};
61782+} __no_const;
61783
61784 #define PM_HINT_FULLON 1<<5
61785 #define PM_HINT_NORMAL 1<<1
61786diff --git a/include/linux/highmem.h b/include/linux/highmem.h
61787index d3999b4..1304cb4 100644
61788--- a/include/linux/highmem.h
61789+++ b/include/linux/highmem.h
61790@@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
61791 kunmap_atomic(kaddr);
61792 }
61793
61794+static inline void sanitize_highpage(struct page *page)
61795+{
61796+ void *kaddr;
61797+ unsigned long flags;
61798+
61799+ local_irq_save(flags);
61800+ kaddr = kmap_atomic(page);
61801+ clear_page(kaddr);
61802+ kunmap_atomic(kaddr);
61803+ local_irq_restore(flags);
61804+}
61805+
61806 static inline void zero_user_segments(struct page *page,
61807 unsigned start1, unsigned end1,
61808 unsigned start2, unsigned end2)
61809diff --git a/include/linux/i2c.h b/include/linux/i2c.h
61810index 195d8b3..e20cfab 100644
61811--- a/include/linux/i2c.h
61812+++ b/include/linux/i2c.h
61813@@ -365,6 +365,7 @@ struct i2c_algorithm {
61814 /* To determine what the adapter supports */
61815 u32 (*functionality) (struct i2c_adapter *);
61816 };
61817+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
61818
61819 /*
61820 * i2c_adapter is the structure used to identify a physical i2c bus along
61821diff --git a/include/linux/i2o.h b/include/linux/i2o.h
61822index d23c3c2..eb63c81 100644
61823--- a/include/linux/i2o.h
61824+++ b/include/linux/i2o.h
61825@@ -565,7 +565,7 @@ struct i2o_controller {
61826 struct i2o_device *exec; /* Executive */
61827 #if BITS_PER_LONG == 64
61828 spinlock_t context_list_lock; /* lock for context_list */
61829- atomic_t context_list_counter; /* needed for unique contexts */
61830+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
61831 struct list_head context_list; /* list of context id's
61832 and pointers */
61833 #endif
61834diff --git a/include/linux/if_team.h b/include/linux/if_team.h
61835index 58404b0..439ed95 100644
61836--- a/include/linux/if_team.h
61837+++ b/include/linux/if_team.h
61838@@ -64,6 +64,7 @@ struct team_mode_ops {
61839 void (*port_leave)(struct team *team, struct team_port *port);
61840 void (*port_change_mac)(struct team *team, struct team_port *port);
61841 };
61842+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
61843
61844 enum team_option_type {
61845 TEAM_OPTION_TYPE_U32,
61846@@ -112,7 +113,7 @@ struct team {
61847 struct list_head option_list;
61848
61849 const struct team_mode *mode;
61850- struct team_mode_ops ops;
61851+ team_mode_ops_no_const ops;
61852 long mode_priv[TEAM_MODE_PRIV_LONGS];
61853 };
61854
61855diff --git a/include/linux/init.h b/include/linux/init.h
61856index 6b95109..bcbdd68 100644
61857--- a/include/linux/init.h
61858+++ b/include/linux/init.h
61859@@ -39,9 +39,15 @@
61860 * Also note, that this data cannot be "const".
61861 */
61862
61863+#ifdef MODULE
61864+#define add_latent_entropy
61865+#else
61866+#define add_latent_entropy __latent_entropy
61867+#endif
61868+
61869 /* These are for everybody (although not all archs will actually
61870 discard it in modules) */
61871-#define __init __section(.init.text) __cold notrace
61872+#define __init __section(.init.text) __cold notrace add_latent_entropy
61873 #define __initdata __section(.init.data)
61874 #define __initconst __section(.init.rodata)
61875 #define __exitdata __section(.exit.data)
61876@@ -83,7 +89,7 @@
61877 #define __exit __section(.exit.text) __exitused __cold notrace
61878
61879 /* Used for HOTPLUG */
61880-#define __devinit __section(.devinit.text) __cold notrace
61881+#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
61882 #define __devinitdata __section(.devinit.data)
61883 #define __devinitconst __section(.devinit.rodata)
61884 #define __devexit __section(.devexit.text) __exitused __cold notrace
61885@@ -91,7 +97,7 @@
61886 #define __devexitconst __section(.devexit.rodata)
61887
61888 /* Used for HOTPLUG_CPU */
61889-#define __cpuinit __section(.cpuinit.text) __cold notrace
61890+#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
61891 #define __cpuinitdata __section(.cpuinit.data)
61892 #define __cpuinitconst __section(.cpuinit.rodata)
61893 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
61894@@ -99,7 +105,7 @@
61895 #define __cpuexitconst __section(.cpuexit.rodata)
61896
61897 /* Used for MEMORY_HOTPLUG */
61898-#define __meminit __section(.meminit.text) __cold notrace
61899+#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
61900 #define __meminitdata __section(.meminit.data)
61901 #define __meminitconst __section(.meminit.rodata)
61902 #define __memexit __section(.memexit.text) __exitused __cold notrace
61903@@ -294,13 +300,13 @@ void __init parse_early_options(char *cmdline);
61904
61905 /* Each module must use one module_init(). */
61906 #define module_init(initfn) \
61907- static inline initcall_t __inittest(void) \
61908+ static inline __used initcall_t __inittest(void) \
61909 { return initfn; } \
61910 int init_module(void) __attribute__((alias(#initfn)));
61911
61912 /* This is only required if you want to be unloadable. */
61913 #define module_exit(exitfn) \
61914- static inline exitcall_t __exittest(void) \
61915+ static inline __used exitcall_t __exittest(void) \
61916 { return exitfn; } \
61917 void cleanup_module(void) __attribute__((alias(#exitfn)));
61918
61919diff --git a/include/linux/init_task.h b/include/linux/init_task.h
61920index e4baff5..83bb175 100644
61921--- a/include/linux/init_task.h
61922+++ b/include/linux/init_task.h
61923@@ -134,6 +134,12 @@ extern struct cred init_cred;
61924
61925 #define INIT_TASK_COMM "swapper"
61926
61927+#ifdef CONFIG_X86
61928+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
61929+#else
61930+#define INIT_TASK_THREAD_INFO
61931+#endif
61932+
61933 /*
61934 * INIT_TASK is used to set up the first task table, touch at
61935 * your own risk!. Base=0, limit=0x1fffff (=2MB)
61936@@ -172,6 +178,7 @@ extern struct cred init_cred;
61937 RCU_INIT_POINTER(.cred, &init_cred), \
61938 .comm = INIT_TASK_COMM, \
61939 .thread = INIT_THREAD, \
61940+ INIT_TASK_THREAD_INFO \
61941 .fs = &init_fs, \
61942 .files = &init_files, \
61943 .signal = &init_signals, \
61944diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
61945index e6ca56d..8583707 100644
61946--- a/include/linux/intel-iommu.h
61947+++ b/include/linux/intel-iommu.h
61948@@ -296,7 +296,7 @@ struct iommu_flush {
61949 u8 fm, u64 type);
61950 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
61951 unsigned int size_order, u64 type);
61952-};
61953+} __no_const;
61954
61955 enum {
61956 SR_DMAR_FECTL_REG,
61957diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
61958index 2aea5d2..0b82f0c 100644
61959--- a/include/linux/interrupt.h
61960+++ b/include/linux/interrupt.h
61961@@ -439,7 +439,7 @@ enum
61962 /* map softirq index to softirq name. update 'softirq_to_name' in
61963 * kernel/softirq.c when adding a new softirq.
61964 */
61965-extern char *softirq_to_name[NR_SOFTIRQS];
61966+extern const char * const softirq_to_name[NR_SOFTIRQS];
61967
61968 /* softirq mask and active fields moved to irq_cpustat_t in
61969 * asm/hardirq.h to get better cache usage. KAO
61970@@ -447,12 +447,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
61971
61972 struct softirq_action
61973 {
61974- void (*action)(struct softirq_action *);
61975+ void (*action)(void);
61976 };
61977
61978 asmlinkage void do_softirq(void);
61979 asmlinkage void __do_softirq(void);
61980-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
61981+extern void open_softirq(int nr, void (*action)(void));
61982 extern void softirq_init(void);
61983 extern void __raise_softirq_irqoff(unsigned int nr);
61984
61985diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
61986index 3875719..4cd454c 100644
61987--- a/include/linux/kallsyms.h
61988+++ b/include/linux/kallsyms.h
61989@@ -15,7 +15,8 @@
61990
61991 struct module;
61992
61993-#ifdef CONFIG_KALLSYMS
61994+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
61995+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61996 /* Lookup the address for a symbol. Returns 0 if not found. */
61997 unsigned long kallsyms_lookup_name(const char *name);
61998
61999@@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62000 /* Stupid that this does nothing, but I didn't create this mess. */
62001 #define __print_symbol(fmt, addr)
62002 #endif /*CONFIG_KALLSYMS*/
62003+#else /* when included by kallsyms.c, vsnprintf.c, or
62004+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62005+extern void __print_symbol(const char *fmt, unsigned long address);
62006+extern int sprint_backtrace(char *buffer, unsigned long address);
62007+extern int sprint_symbol(char *buffer, unsigned long address);
62008+const char *kallsyms_lookup(unsigned long addr,
62009+ unsigned long *symbolsize,
62010+ unsigned long *offset,
62011+ char **modname, char *namebuf);
62012+#endif
62013
62014 /* This macro allows us to keep printk typechecking */
62015 static __printf(1, 2)
62016diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62017index c4d2fc1..5df9c19 100644
62018--- a/include/linux/kgdb.h
62019+++ b/include/linux/kgdb.h
62020@@ -53,7 +53,7 @@ extern int kgdb_connected;
62021 extern int kgdb_io_module_registered;
62022
62023 extern atomic_t kgdb_setting_breakpoint;
62024-extern atomic_t kgdb_cpu_doing_single_step;
62025+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62026
62027 extern struct task_struct *kgdb_usethread;
62028 extern struct task_struct *kgdb_contthread;
62029@@ -252,7 +252,7 @@ struct kgdb_arch {
62030 void (*disable_hw_break)(struct pt_regs *regs);
62031 void (*remove_all_hw_break)(void);
62032 void (*correct_hw_break)(void);
62033-};
62034+} __do_const;
62035
62036 /**
62037 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62038@@ -277,7 +277,7 @@ struct kgdb_io {
62039 void (*pre_exception) (void);
62040 void (*post_exception) (void);
62041 int is_console;
62042-};
62043+} __do_const;
62044
62045 extern struct kgdb_arch arch_kgdb_ops;
62046
62047diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62048index dd99c32..da06047 100644
62049--- a/include/linux/kmod.h
62050+++ b/include/linux/kmod.h
62051@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62052 * usually useless though. */
62053 extern __printf(2, 3)
62054 int __request_module(bool wait, const char *name, ...);
62055+extern __printf(3, 4)
62056+int ___request_module(bool wait, char *param_name, const char *name, ...);
62057 #define request_module(mod...) __request_module(true, mod)
62058 #define request_module_nowait(mod...) __request_module(false, mod)
62059 #define try_then_request_module(x, mod...) \
62060diff --git a/include/linux/kref.h b/include/linux/kref.h
62061index 9c07dce..a92fa71 100644
62062--- a/include/linux/kref.h
62063+++ b/include/linux/kref.h
62064@@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62065 static inline int kref_sub(struct kref *kref, unsigned int count,
62066 void (*release)(struct kref *kref))
62067 {
62068- WARN_ON(release == NULL);
62069+ BUG_ON(release == NULL);
62070
62071 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62072 release(kref);
62073diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62074index 72cbf08..dd0201d 100644
62075--- a/include/linux/kvm_host.h
62076+++ b/include/linux/kvm_host.h
62077@@ -322,7 +322,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62078 void vcpu_load(struct kvm_vcpu *vcpu);
62079 void vcpu_put(struct kvm_vcpu *vcpu);
62080
62081-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62082+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62083 struct module *module);
62084 void kvm_exit(void);
62085
62086@@ -486,7 +486,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62087 struct kvm_guest_debug *dbg);
62088 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62089
62090-int kvm_arch_init(void *opaque);
62091+int kvm_arch_init(const void *opaque);
62092 void kvm_arch_exit(void);
62093
62094 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62095diff --git a/include/linux/libata.h b/include/linux/libata.h
62096index 6e887c7..4539601 100644
62097--- a/include/linux/libata.h
62098+++ b/include/linux/libata.h
62099@@ -910,7 +910,7 @@ struct ata_port_operations {
62100 * fields must be pointers.
62101 */
62102 const struct ata_port_operations *inherits;
62103-};
62104+} __do_const;
62105
62106 struct ata_port_info {
62107 unsigned long flags;
62108diff --git a/include/linux/mca.h b/include/linux/mca.h
62109index 3797270..7765ede 100644
62110--- a/include/linux/mca.h
62111+++ b/include/linux/mca.h
62112@@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
62113 int region);
62114 void * (*mca_transform_memory)(struct mca_device *,
62115 void *memory);
62116-};
62117+} __no_const;
62118
62119 struct mca_bus {
62120 u64 default_dma_mask;
62121diff --git a/include/linux/memory.h b/include/linux/memory.h
62122index 1ac7f6e..a5794d0 100644
62123--- a/include/linux/memory.h
62124+++ b/include/linux/memory.h
62125@@ -143,7 +143,7 @@ struct memory_accessor {
62126 size_t count);
62127 ssize_t (*write)(struct memory_accessor *, const char *buf,
62128 off_t offset, size_t count);
62129-};
62130+} __no_const;
62131
62132 /*
62133 * Kernel text modification mutex, used for code patching. Users of this lock
62134diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62135index ee96cd5..7823c3a 100644
62136--- a/include/linux/mfd/abx500.h
62137+++ b/include/linux/mfd/abx500.h
62138@@ -455,6 +455,7 @@ struct abx500_ops {
62139 int (*event_registers_startup_state_get) (struct device *, u8 *);
62140 int (*startup_irq_enabled) (struct device *, unsigned int);
62141 };
62142+typedef struct abx500_ops __no_const abx500_ops_no_const;
62143
62144 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62145 void abx500_remove_ops(struct device *dev);
62146diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
62147index 9b07725..3d55001 100644
62148--- a/include/linux/mfd/abx500/ux500_chargalg.h
62149+++ b/include/linux/mfd/abx500/ux500_chargalg.h
62150@@ -19,7 +19,7 @@ struct ux500_charger_ops {
62151 int (*enable) (struct ux500_charger *, int, int, int);
62152 int (*kick_wd) (struct ux500_charger *);
62153 int (*update_curr) (struct ux500_charger *, int);
62154-};
62155+} __no_const;
62156
62157 /**
62158 * struct ux500_charger - power supply ux500 charger sub class
62159diff --git a/include/linux/mm.h b/include/linux/mm.h
62160index 74aa71b..4ae97ba 100644
62161--- a/include/linux/mm.h
62162+++ b/include/linux/mm.h
62163@@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
62164
62165 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62166 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62167+
62168+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62169+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62170+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62171+#else
62172 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62173+#endif
62174+
62175 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62176 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62177
62178@@ -1013,34 +1020,6 @@ int set_page_dirty(struct page *page);
62179 int set_page_dirty_lock(struct page *page);
62180 int clear_page_dirty_for_io(struct page *page);
62181
62182-/* Is the vma a continuation of the stack vma above it? */
62183-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62184-{
62185- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62186-}
62187-
62188-static inline int stack_guard_page_start(struct vm_area_struct *vma,
62189- unsigned long addr)
62190-{
62191- return (vma->vm_flags & VM_GROWSDOWN) &&
62192- (vma->vm_start == addr) &&
62193- !vma_growsdown(vma->vm_prev, addr);
62194-}
62195-
62196-/* Is the vma a continuation of the stack vma below it? */
62197-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62198-{
62199- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62200-}
62201-
62202-static inline int stack_guard_page_end(struct vm_area_struct *vma,
62203- unsigned long addr)
62204-{
62205- return (vma->vm_flags & VM_GROWSUP) &&
62206- (vma->vm_end == addr) &&
62207- !vma_growsup(vma->vm_next, addr);
62208-}
62209-
62210 extern pid_t
62211 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
62212
62213@@ -1139,6 +1118,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
62214 }
62215 #endif
62216
62217+#ifdef CONFIG_MMU
62218+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62219+#else
62220+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62221+{
62222+ return __pgprot(0);
62223+}
62224+#endif
62225+
62226 int vma_wants_writenotify(struct vm_area_struct *vma);
62227
62228 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62229@@ -1157,8 +1145,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62230 {
62231 return 0;
62232 }
62233+
62234+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62235+ unsigned long address)
62236+{
62237+ return 0;
62238+}
62239 #else
62240 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62241+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62242 #endif
62243
62244 #ifdef __PAGETABLE_PMD_FOLDED
62245@@ -1167,8 +1162,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62246 {
62247 return 0;
62248 }
62249+
62250+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62251+ unsigned long address)
62252+{
62253+ return 0;
62254+}
62255 #else
62256 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62257+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62258 #endif
62259
62260 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62261@@ -1186,11 +1188,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62262 NULL: pud_offset(pgd, address);
62263 }
62264
62265+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62266+{
62267+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62268+ NULL: pud_offset(pgd, address);
62269+}
62270+
62271 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62272 {
62273 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62274 NULL: pmd_offset(pud, address);
62275 }
62276+
62277+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62278+{
62279+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62280+ NULL: pmd_offset(pud, address);
62281+}
62282 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62283
62284 #if USE_SPLIT_PTLOCKS
62285@@ -1400,6 +1414,7 @@ extern unsigned long do_mmap(struct file *, unsigned long,
62286 unsigned long, unsigned long,
62287 unsigned long, unsigned long);
62288 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62289+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62290
62291 /* These take the mm semaphore themselves */
62292 extern unsigned long vm_brk(unsigned long, unsigned long);
62293@@ -1462,6 +1477,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62294 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62295 struct vm_area_struct **pprev);
62296
62297+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62298+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62299+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62300+
62301 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62302 NULL if none. Assume start_addr < end_addr. */
62303 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62304@@ -1490,15 +1509,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62305 return vma;
62306 }
62307
62308-#ifdef CONFIG_MMU
62309-pgprot_t vm_get_page_prot(unsigned long vm_flags);
62310-#else
62311-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62312-{
62313- return __pgprot(0);
62314-}
62315-#endif
62316-
62317 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62318 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62319 unsigned long pfn, unsigned long size, pgprot_t);
62320@@ -1602,7 +1612,7 @@ extern int unpoison_memory(unsigned long pfn);
62321 extern int sysctl_memory_failure_early_kill;
62322 extern int sysctl_memory_failure_recovery;
62323 extern void shake_page(struct page *p, int access);
62324-extern atomic_long_t mce_bad_pages;
62325+extern atomic_long_unchecked_t mce_bad_pages;
62326 extern int soft_offline_page(struct page *page, int flags);
62327
62328 extern void dump_page(struct page *page);
62329@@ -1633,5 +1643,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62330 static inline bool page_is_guard(struct page *page) { return false; }
62331 #endif /* CONFIG_DEBUG_PAGEALLOC */
62332
62333+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62334+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62335+#else
62336+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62337+#endif
62338+
62339 #endif /* __KERNEL__ */
62340 #endif /* _LINUX_MM_H */
62341diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62342index b35752f..41075a0 100644
62343--- a/include/linux/mm_types.h
62344+++ b/include/linux/mm_types.h
62345@@ -262,6 +262,8 @@ struct vm_area_struct {
62346 #ifdef CONFIG_NUMA
62347 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62348 #endif
62349+
62350+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62351 };
62352
62353 struct core_thread {
62354@@ -336,7 +338,7 @@ struct mm_struct {
62355 unsigned long def_flags;
62356 unsigned long nr_ptes; /* Page table pages */
62357 unsigned long start_code, end_code, start_data, end_data;
62358- unsigned long start_brk, brk, start_stack;
62359+ unsigned long brk_gap, start_brk, brk, start_stack;
62360 unsigned long arg_start, arg_end, env_start, env_end;
62361
62362 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62363@@ -398,6 +400,24 @@ struct mm_struct {
62364 #ifdef CONFIG_CPUMASK_OFFSTACK
62365 struct cpumask cpumask_allocation;
62366 #endif
62367+
62368+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS) || defined(CONFIG_PAX_HAVE_ACL_FLAGS) || defined(CONFIG_PAX_HOOK_ACL_FLAGS)
62369+ unsigned long pax_flags;
62370+#endif
62371+
62372+#ifdef CONFIG_PAX_DLRESOLVE
62373+ unsigned long call_dl_resolve;
62374+#endif
62375+
62376+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62377+ unsigned long call_syscall;
62378+#endif
62379+
62380+#ifdef CONFIG_PAX_ASLR
62381+ unsigned long delta_mmap; /* randomized offset */
62382+ unsigned long delta_stack; /* randomized offset */
62383+#endif
62384+
62385 };
62386
62387 static inline void mm_init_cpumask(struct mm_struct *mm)
62388diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62389index 1d1b1e1..2a13c78 100644
62390--- a/include/linux/mmu_notifier.h
62391+++ b/include/linux/mmu_notifier.h
62392@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62393 */
62394 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62395 ({ \
62396- pte_t __pte; \
62397+ pte_t ___pte; \
62398 struct vm_area_struct *___vma = __vma; \
62399 unsigned long ___address = __address; \
62400- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62401+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62402 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62403- __pte; \
62404+ ___pte; \
62405 })
62406
62407 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62408diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62409index 5f6806b..49db2b2 100644
62410--- a/include/linux/mmzone.h
62411+++ b/include/linux/mmzone.h
62412@@ -380,7 +380,7 @@ struct zone {
62413 unsigned long flags; /* zone flags, see below */
62414
62415 /* Zone statistics */
62416- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62417+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62418
62419 /*
62420 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62421diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62422index 501da4c..ba79bb4 100644
62423--- a/include/linux/mod_devicetable.h
62424+++ b/include/linux/mod_devicetable.h
62425@@ -12,7 +12,7 @@
62426 typedef unsigned long kernel_ulong_t;
62427 #endif
62428
62429-#define PCI_ANY_ID (~0)
62430+#define PCI_ANY_ID ((__u16)~0)
62431
62432 struct pci_device_id {
62433 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62434@@ -131,7 +131,7 @@ struct usb_device_id {
62435 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62436 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62437
62438-#define HID_ANY_ID (~0)
62439+#define HID_ANY_ID (~0U)
62440
62441 struct hid_device_id {
62442 __u16 bus;
62443diff --git a/include/linux/module.h b/include/linux/module.h
62444index fbcafe2..e5d9587 100644
62445--- a/include/linux/module.h
62446+++ b/include/linux/module.h
62447@@ -17,6 +17,7 @@
62448 #include <linux/moduleparam.h>
62449 #include <linux/tracepoint.h>
62450 #include <linux/export.h>
62451+#include <linux/fs.h>
62452
62453 #include <linux/percpu.h>
62454 #include <asm/module.h>
62455@@ -273,19 +274,16 @@ struct module
62456 int (*init)(void);
62457
62458 /* If this is non-NULL, vfree after init() returns */
62459- void *module_init;
62460+ void *module_init_rx, *module_init_rw;
62461
62462 /* Here is the actual code + data, vfree'd on unload. */
62463- void *module_core;
62464+ void *module_core_rx, *module_core_rw;
62465
62466 /* Here are the sizes of the init and core sections */
62467- unsigned int init_size, core_size;
62468+ unsigned int init_size_rw, core_size_rw;
62469
62470 /* The size of the executable code in each section. */
62471- unsigned int init_text_size, core_text_size;
62472-
62473- /* Size of RO sections of the module (text+rodata) */
62474- unsigned int init_ro_size, core_ro_size;
62475+ unsigned int init_size_rx, core_size_rx;
62476
62477 /* Arch-specific module values */
62478 struct mod_arch_specific arch;
62479@@ -341,6 +339,10 @@ struct module
62480 #ifdef CONFIG_EVENT_TRACING
62481 struct ftrace_event_call **trace_events;
62482 unsigned int num_trace_events;
62483+ struct file_operations trace_id;
62484+ struct file_operations trace_enable;
62485+ struct file_operations trace_format;
62486+ struct file_operations trace_filter;
62487 #endif
62488 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62489 unsigned int num_ftrace_callsites;
62490@@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
62491 bool is_module_percpu_address(unsigned long addr);
62492 bool is_module_text_address(unsigned long addr);
62493
62494+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62495+{
62496+
62497+#ifdef CONFIG_PAX_KERNEXEC
62498+ if (ktla_ktva(addr) >= (unsigned long)start &&
62499+ ktla_ktva(addr) < (unsigned long)start + size)
62500+ return 1;
62501+#endif
62502+
62503+ return ((void *)addr >= start && (void *)addr < start + size);
62504+}
62505+
62506+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62507+{
62508+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62509+}
62510+
62511+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62512+{
62513+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62514+}
62515+
62516+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62517+{
62518+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62519+}
62520+
62521+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62522+{
62523+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62524+}
62525+
62526 static inline int within_module_core(unsigned long addr, struct module *mod)
62527 {
62528- return (unsigned long)mod->module_core <= addr &&
62529- addr < (unsigned long)mod->module_core + mod->core_size;
62530+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62531 }
62532
62533 static inline int within_module_init(unsigned long addr, struct module *mod)
62534 {
62535- return (unsigned long)mod->module_init <= addr &&
62536- addr < (unsigned long)mod->module_init + mod->init_size;
62537+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62538 }
62539
62540 /* Search for module by name: must hold module_mutex. */
62541diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62542index b2be02e..72d2f78 100644
62543--- a/include/linux/moduleloader.h
62544+++ b/include/linux/moduleloader.h
62545@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62546
62547 /* Allocator used for allocating struct module, core sections and init
62548 sections. Returns NULL on failure. */
62549-void *module_alloc(unsigned long size);
62550+void *module_alloc(unsigned long size) __size_overflow(1);
62551+
62552+#ifdef CONFIG_PAX_KERNEXEC
62553+void *module_alloc_exec(unsigned long size) __size_overflow(1);
62554+#else
62555+#define module_alloc_exec(x) module_alloc(x)
62556+#endif
62557
62558 /* Free memory returned from module_alloc. */
62559 void module_free(struct module *mod, void *module_region);
62560
62561+#ifdef CONFIG_PAX_KERNEXEC
62562+void module_free_exec(struct module *mod, void *module_region);
62563+#else
62564+#define module_free_exec(x, y) module_free((x), (y))
62565+#endif
62566+
62567 /* Apply the given relocation to the (simplified) ELF. Return -error
62568 or 0. */
62569 int apply_relocate(Elf_Shdr *sechdrs,
62570diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62571index 944bc18..042d291 100644
62572--- a/include/linux/moduleparam.h
62573+++ b/include/linux/moduleparam.h
62574@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
62575 * @len is usually just sizeof(string).
62576 */
62577 #define module_param_string(name, string, len, perm) \
62578- static const struct kparam_string __param_string_##name \
62579+ static const struct kparam_string __param_string_##name __used \
62580 = { len, string }; \
62581 __module_param_call(MODULE_PARAM_PREFIX, name, \
62582 &param_ops_string, \
62583@@ -424,7 +424,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62584 */
62585 #define module_param_array_named(name, array, type, nump, perm) \
62586 param_check_##type(name, &(array)[0]); \
62587- static const struct kparam_array __param_arr_##name \
62588+ static const struct kparam_array __param_arr_##name __used \
62589 = { .max = ARRAY_SIZE(array), .num = nump, \
62590 .ops = &param_ops_##type, \
62591 .elemsize = sizeof(array[0]), .elem = array }; \
62592diff --git a/include/linux/namei.h b/include/linux/namei.h
62593index ffc0213..2c1f2cb 100644
62594--- a/include/linux/namei.h
62595+++ b/include/linux/namei.h
62596@@ -24,7 +24,7 @@ struct nameidata {
62597 unsigned seq;
62598 int last_type;
62599 unsigned depth;
62600- char *saved_names[MAX_NESTED_LINKS + 1];
62601+ const char *saved_names[MAX_NESTED_LINKS + 1];
62602
62603 /* Intent data */
62604 union {
62605@@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62606 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62607 extern void unlock_rename(struct dentry *, struct dentry *);
62608
62609-static inline void nd_set_link(struct nameidata *nd, char *path)
62610+static inline void nd_set_link(struct nameidata *nd, const char *path)
62611 {
62612 nd->saved_names[nd->depth] = path;
62613 }
62614
62615-static inline char *nd_get_link(struct nameidata *nd)
62616+static inline const char *nd_get_link(const struct nameidata *nd)
62617 {
62618 return nd->saved_names[nd->depth];
62619 }
62620diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62621index 33900a5..2072000 100644
62622--- a/include/linux/netdevice.h
62623+++ b/include/linux/netdevice.h
62624@@ -1003,6 +1003,7 @@ struct net_device_ops {
62625 int (*ndo_neigh_construct)(struct neighbour *n);
62626 void (*ndo_neigh_destroy)(struct neighbour *n);
62627 };
62628+typedef struct net_device_ops __no_const net_device_ops_no_const;
62629
62630 /*
62631 * The DEVICE structure.
62632@@ -1064,7 +1065,7 @@ struct net_device {
62633 int iflink;
62634
62635 struct net_device_stats stats;
62636- atomic_long_t rx_dropped; /* dropped packets by core network
62637+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
62638 * Do not use this in drivers.
62639 */
62640
62641diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62642new file mode 100644
62643index 0000000..33f4af8
62644--- /dev/null
62645+++ b/include/linux/netfilter/xt_gradm.h
62646@@ -0,0 +1,9 @@
62647+#ifndef _LINUX_NETFILTER_XT_GRADM_H
62648+#define _LINUX_NETFILTER_XT_GRADM_H 1
62649+
62650+struct xt_gradm_mtinfo {
62651+ __u16 flags;
62652+ __u16 invflags;
62653+};
62654+
62655+#endif
62656diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62657index c65a18a..0c05f3a 100644
62658--- a/include/linux/of_pdt.h
62659+++ b/include/linux/of_pdt.h
62660@@ -32,7 +32,7 @@ struct of_pdt_ops {
62661
62662 /* return 0 on success; fill in 'len' with number of bytes in path */
62663 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62664-};
62665+} __no_const;
62666
62667 extern void *prom_early_alloc(unsigned long size);
62668
62669diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62670index a4c5624..79d6d88 100644
62671--- a/include/linux/oprofile.h
62672+++ b/include/linux/oprofile.h
62673@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62674 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62675 char const * name, ulong * val);
62676
62677-/** Create a file for read-only access to an atomic_t. */
62678+/** Create a file for read-only access to an atomic_unchecked_t. */
62679 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62680- char const * name, atomic_t * val);
62681+ char const * name, atomic_unchecked_t * val);
62682
62683 /** create a directory */
62684 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62685diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
62686index ddbb6a9..be1680e 100644
62687--- a/include/linux/perf_event.h
62688+++ b/include/linux/perf_event.h
62689@@ -879,8 +879,8 @@ struct perf_event {
62690
62691 enum perf_event_active_state state;
62692 unsigned int attach_state;
62693- local64_t count;
62694- atomic64_t child_count;
62695+ local64_t count; /* PaX: fix it one day */
62696+ atomic64_unchecked_t child_count;
62697
62698 /*
62699 * These are the total time in nanoseconds that the event
62700@@ -931,8 +931,8 @@ struct perf_event {
62701 * These accumulate total time (in nanoseconds) that children
62702 * events have been enabled and running, respectively.
62703 */
62704- atomic64_t child_total_time_enabled;
62705- atomic64_t child_total_time_running;
62706+ atomic64_unchecked_t child_total_time_enabled;
62707+ atomic64_unchecked_t child_total_time_running;
62708
62709 /*
62710 * Protect attach/detach and child_list:
62711diff --git a/include/linux/personality.h b/include/linux/personality.h
62712index 8fc7dd1a..c19d89e 100644
62713--- a/include/linux/personality.h
62714+++ b/include/linux/personality.h
62715@@ -44,6 +44,7 @@ enum {
62716 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
62717 ADDR_NO_RANDOMIZE | \
62718 ADDR_COMPAT_LAYOUT | \
62719+ ADDR_LIMIT_3GB | \
62720 MMAP_PAGE_ZERO)
62721
62722 /*
62723diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
62724index e1ac1ce..0675fed 100644
62725--- a/include/linux/pipe_fs_i.h
62726+++ b/include/linux/pipe_fs_i.h
62727@@ -45,9 +45,9 @@ struct pipe_buffer {
62728 struct pipe_inode_info {
62729 wait_queue_head_t wait;
62730 unsigned int nrbufs, curbuf, buffers;
62731- unsigned int readers;
62732- unsigned int writers;
62733- unsigned int waiting_writers;
62734+ atomic_t readers;
62735+ atomic_t writers;
62736+ atomic_t waiting_writers;
62737 unsigned int r_counter;
62738 unsigned int w_counter;
62739 struct page *tmp_page;
62740diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
62741index 609daae..5392427 100644
62742--- a/include/linux/pm_runtime.h
62743+++ b/include/linux/pm_runtime.h
62744@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
62745
62746 static inline void pm_runtime_mark_last_busy(struct device *dev)
62747 {
62748- ACCESS_ONCE(dev->power.last_busy) = jiffies;
62749+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
62750 }
62751
62752 #else /* !CONFIG_PM_RUNTIME */
62753diff --git a/include/linux/poison.h b/include/linux/poison.h
62754index 2110a81..13a11bb 100644
62755--- a/include/linux/poison.h
62756+++ b/include/linux/poison.h
62757@@ -19,8 +19,8 @@
62758 * under normal circumstances, used to verify that nobody uses
62759 * non-initialized list entries.
62760 */
62761-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
62762-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
62763+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
62764+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
62765
62766 /********** include/linux/timer.h **********/
62767 /*
62768diff --git a/include/linux/preempt.h b/include/linux/preempt.h
62769index 5a710b9..0b0dab9 100644
62770--- a/include/linux/preempt.h
62771+++ b/include/linux/preempt.h
62772@@ -126,7 +126,7 @@ struct preempt_ops {
62773 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
62774 void (*sched_out)(struct preempt_notifier *notifier,
62775 struct task_struct *next);
62776-};
62777+} __no_const;
62778
62779 /**
62780 * preempt_notifier - key for installing preemption notifiers
62781diff --git a/include/linux/printk.h b/include/linux/printk.h
62782index 0525927..a5388b6 100644
62783--- a/include/linux/printk.h
62784+++ b/include/linux/printk.h
62785@@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
62786 extern int printk_needs_cpu(int cpu);
62787 extern void printk_tick(void);
62788
62789+extern int kptr_restrict;
62790+
62791 #ifdef CONFIG_PRINTK
62792 asmlinkage __printf(1, 0)
62793 int vprintk(const char *fmt, va_list args);
62794@@ -117,7 +119,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
62795
62796 extern int printk_delay_msec;
62797 extern int dmesg_restrict;
62798-extern int kptr_restrict;
62799
62800 void log_buf_kexec_setup(void);
62801 void __init setup_log_buf(int early);
62802diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
62803index 85c5073..51fac8b 100644
62804--- a/include/linux/proc_fs.h
62805+++ b/include/linux/proc_fs.h
62806@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
62807 return proc_create_data(name, mode, parent, proc_fops, NULL);
62808 }
62809
62810+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
62811+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62812+{
62813+#ifdef CONFIG_GRKERNSEC_PROC_USER
62814+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62815+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62816+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62817+#else
62818+ return proc_create_data(name, mode, parent, proc_fops, NULL);
62819+#endif
62820+}
62821+
62822 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62823 umode_t mode, struct proc_dir_entry *base,
62824 read_proc_t *read_proc, void * data)
62825@@ -258,7 +270,7 @@ union proc_op {
62826 int (*proc_show)(struct seq_file *m,
62827 struct pid_namespace *ns, struct pid *pid,
62828 struct task_struct *task);
62829-};
62830+} __no_const;
62831
62832 struct ctl_table_header;
62833 struct ctl_table;
62834diff --git a/include/linux/random.h b/include/linux/random.h
62835index 8f74538..de61694 100644
62836--- a/include/linux/random.h
62837+++ b/include/linux/random.h
62838@@ -54,6 +54,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
62839 unsigned int value);
62840 extern void add_interrupt_randomness(int irq);
62841
62842+#ifdef CONFIG_PAX_LATENT_ENTROPY
62843+extern void transfer_latent_entropy(void);
62844+#endif
62845+
62846 extern void get_random_bytes(void *buf, int nbytes);
62847 void generate_random_uuid(unsigned char uuid_out[16]);
62848
62849@@ -69,12 +73,17 @@ void srandom32(u32 seed);
62850
62851 u32 prandom32(struct rnd_state *);
62852
62853+static inline unsigned long pax_get_random_long(void)
62854+{
62855+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
62856+}
62857+
62858 /*
62859 * Handle minimum values for seeds
62860 */
62861 static inline u32 __seed(u32 x, u32 m)
62862 {
62863- return (x < m) ? x + m : x;
62864+ return (x <= m) ? x + m + 1 : x;
62865 }
62866
62867 /**
62868diff --git a/include/linux/reboot.h b/include/linux/reboot.h
62869index e0879a7..a12f962 100644
62870--- a/include/linux/reboot.h
62871+++ b/include/linux/reboot.h
62872@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
62873 * Architecture-specific implementations of sys_reboot commands.
62874 */
62875
62876-extern void machine_restart(char *cmd);
62877-extern void machine_halt(void);
62878-extern void machine_power_off(void);
62879+extern void machine_restart(char *cmd) __noreturn;
62880+extern void machine_halt(void) __noreturn;
62881+extern void machine_power_off(void) __noreturn;
62882
62883 extern void machine_shutdown(void);
62884 struct pt_regs;
62885@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
62886 */
62887
62888 extern void kernel_restart_prepare(char *cmd);
62889-extern void kernel_restart(char *cmd);
62890-extern void kernel_halt(void);
62891-extern void kernel_power_off(void);
62892+extern void kernel_restart(char *cmd) __noreturn;
62893+extern void kernel_halt(void) __noreturn;
62894+extern void kernel_power_off(void) __noreturn;
62895
62896 extern int C_A_D; /* for sysctl */
62897 void ctrl_alt_del(void);
62898@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
62899 * Emergency restart, callable from an interrupt handler.
62900 */
62901
62902-extern void emergency_restart(void);
62903+extern void emergency_restart(void) __noreturn;
62904 #include <asm/emergency-restart.h>
62905
62906 #endif
62907diff --git a/include/linux/relay.h b/include/linux/relay.h
62908index 91cacc3..b55ff74 100644
62909--- a/include/linux/relay.h
62910+++ b/include/linux/relay.h
62911@@ -160,7 +160,7 @@ struct rchan_callbacks
62912 * The callback should return 0 if successful, negative if not.
62913 */
62914 int (*remove_buf_file)(struct dentry *dentry);
62915-};
62916+} __no_const;
62917
62918 /*
62919 * CONFIG_RELAY kernel API, kernel/relay.c
62920diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
62921index 6fdf027..ff72610 100644
62922--- a/include/linux/rfkill.h
62923+++ b/include/linux/rfkill.h
62924@@ -147,6 +147,7 @@ struct rfkill_ops {
62925 void (*query)(struct rfkill *rfkill, void *data);
62926 int (*set_block)(void *data, bool blocked);
62927 };
62928+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
62929
62930 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
62931 /**
62932diff --git a/include/linux/rio.h b/include/linux/rio.h
62933index 4d50611..c6858a2 100644
62934--- a/include/linux/rio.h
62935+++ b/include/linux/rio.h
62936@@ -315,7 +315,7 @@ struct rio_ops {
62937 int mbox, void *buffer, size_t len);
62938 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
62939 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
62940-};
62941+} __no_const;
62942
62943 #define RIO_RESOURCE_MEM 0x00000100
62944 #define RIO_RESOURCE_DOORBELL 0x00000200
62945diff --git a/include/linux/rmap.h b/include/linux/rmap.h
62946index fd07c45..4676b8e 100644
62947--- a/include/linux/rmap.h
62948+++ b/include/linux/rmap.h
62949@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
62950 void anon_vma_init(void); /* create anon_vma_cachep */
62951 int anon_vma_prepare(struct vm_area_struct *);
62952 void unlink_anon_vmas(struct vm_area_struct *);
62953-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
62954+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
62955 void anon_vma_moveto_tail(struct vm_area_struct *);
62956-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
62957+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
62958
62959 static inline void anon_vma_merge(struct vm_area_struct *vma,
62960 struct vm_area_struct *next)
62961diff --git a/include/linux/sched.h b/include/linux/sched.h
62962index 7b06169..eb46ae3 100644
62963--- a/include/linux/sched.h
62964+++ b/include/linux/sched.h
62965@@ -100,6 +100,7 @@ struct bio_list;
62966 struct fs_struct;
62967 struct perf_event_context;
62968 struct blk_plug;
62969+struct linux_binprm;
62970
62971 /*
62972 * List of flags we want to share for kernel threads,
62973@@ -382,10 +383,13 @@ struct user_namespace;
62974 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
62975
62976 extern int sysctl_max_map_count;
62977+extern unsigned long sysctl_heap_stack_gap;
62978
62979 #include <linux/aio.h>
62980
62981 #ifdef CONFIG_MMU
62982+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
62983+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
62984 extern void arch_pick_mmap_layout(struct mm_struct *mm);
62985 extern unsigned long
62986 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
62987@@ -404,6 +408,11 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
62988 extern void set_dumpable(struct mm_struct *mm, int value);
62989 extern int get_dumpable(struct mm_struct *mm);
62990
62991+/* get/set_dumpable() values */
62992+#define SUID_DUMPABLE_DISABLED 0
62993+#define SUID_DUMPABLE_ENABLED 1
62994+#define SUID_DUMPABLE_SAFE 2
62995+
62996 /* mm flags */
62997 /* dumpable bits */
62998 #define MMF_DUMPABLE 0 /* core dump is permitted */
62999@@ -643,6 +652,17 @@ struct signal_struct {
63000 #ifdef CONFIG_TASKSTATS
63001 struct taskstats *stats;
63002 #endif
63003+
63004+#ifdef CONFIG_GRKERNSEC
63005+ u32 curr_ip;
63006+ u32 saved_ip;
63007+ u32 gr_saddr;
63008+ u32 gr_daddr;
63009+ u16 gr_sport;
63010+ u16 gr_dport;
63011+ u8 used_accept:1;
63012+#endif
63013+
63014 #ifdef CONFIG_AUDIT
63015 unsigned audit_tty;
63016 struct tty_audit_buf *tty_audit_buf;
63017@@ -726,6 +746,11 @@ struct user_struct {
63018 struct key *session_keyring; /* UID's default session keyring */
63019 #endif
63020
63021+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63022+ unsigned int banned;
63023+ unsigned long ban_expires;
63024+#endif
63025+
63026 /* Hash table maintenance information */
63027 struct hlist_node uidhash_node;
63028 uid_t uid;
63029@@ -1386,8 +1411,8 @@ struct task_struct {
63030 struct list_head thread_group;
63031
63032 struct completion *vfork_done; /* for vfork() */
63033- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63034- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63035+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63036+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63037
63038 cputime_t utime, stime, utimescaled, stimescaled;
63039 cputime_t gtime;
63040@@ -1403,13 +1428,6 @@ struct task_struct {
63041 struct task_cputime cputime_expires;
63042 struct list_head cpu_timers[3];
63043
63044-/* process credentials */
63045- const struct cred __rcu *real_cred; /* objective and real subjective task
63046- * credentials (COW) */
63047- const struct cred __rcu *cred; /* effective (overridable) subjective task
63048- * credentials (COW) */
63049- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63050-
63051 char comm[TASK_COMM_LEN]; /* executable name excluding path
63052 - access with [gs]et_task_comm (which lock
63053 it with task_lock())
63054@@ -1426,8 +1444,16 @@ struct task_struct {
63055 #endif
63056 /* CPU-specific state of this task */
63057 struct thread_struct thread;
63058+/* thread_info moved to task_struct */
63059+#ifdef CONFIG_X86
63060+ struct thread_info tinfo;
63061+#endif
63062 /* filesystem information */
63063 struct fs_struct *fs;
63064+
63065+ const struct cred __rcu *cred; /* effective (overridable) subjective task
63066+ * credentials (COW) */
63067+
63068 /* open file information */
63069 struct files_struct *files;
63070 /* namespaces */
63071@@ -1469,6 +1495,11 @@ struct task_struct {
63072 struct rt_mutex_waiter *pi_blocked_on;
63073 #endif
63074
63075+/* process credentials */
63076+ const struct cred __rcu *real_cred; /* objective and real subjective task
63077+ * credentials (COW) */
63078+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63079+
63080 #ifdef CONFIG_DEBUG_MUTEXES
63081 /* mutex deadlock detection */
63082 struct mutex_waiter *blocked_on;
63083@@ -1585,6 +1616,27 @@ struct task_struct {
63084 unsigned long default_timer_slack_ns;
63085
63086 struct list_head *scm_work_list;
63087+
63088+#ifdef CONFIG_GRKERNSEC
63089+ /* grsecurity */
63090+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63091+ u64 exec_id;
63092+#endif
63093+#ifdef CONFIG_GRKERNSEC_SETXID
63094+ const struct cred *delayed_cred;
63095+#endif
63096+ struct dentry *gr_chroot_dentry;
63097+ struct acl_subject_label *acl;
63098+ struct acl_role_label *role;
63099+ struct file *exec_file;
63100+ u16 acl_role_id;
63101+ /* is this the task that authenticated to the special role */
63102+ u8 acl_sp_role;
63103+ u8 is_writable;
63104+ u8 brute;
63105+ u8 gr_is_chrooted;
63106+#endif
63107+
63108 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63109 /* Index of current stored address in ret_stack */
63110 int curr_ret_stack;
63111@@ -1619,6 +1671,51 @@ struct task_struct {
63112 #endif
63113 };
63114
63115+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63116+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63117+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63118+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63119+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63120+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63121+
63122+#ifdef CONFIG_PAX_SOFTMODE
63123+extern int pax_softmode;
63124+#endif
63125+
63126+extern int pax_check_flags(unsigned long *);
63127+
63128+/* if tsk != current then task_lock must be held on it */
63129+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63130+static inline unsigned long pax_get_flags(struct task_struct *tsk)
63131+{
63132+ if (likely(tsk->mm))
63133+ return tsk->mm->pax_flags;
63134+ else
63135+ return 0UL;
63136+}
63137+
63138+/* if tsk != current then task_lock must be held on it */
63139+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63140+{
63141+ if (likely(tsk->mm)) {
63142+ tsk->mm->pax_flags = flags;
63143+ return 0;
63144+ }
63145+ return -EINVAL;
63146+}
63147+#endif
63148+
63149+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63150+extern void pax_set_initial_flags(struct linux_binprm *bprm);
63151+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63152+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63153+#endif
63154+
63155+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63156+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63157+extern void pax_report_refcount_overflow(struct pt_regs *regs);
63158+extern void check_object_size(const void *ptr, unsigned long n, bool to);
63159+
63160 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63161 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63162
63163@@ -2146,7 +2243,9 @@ void yield(void);
63164 extern struct exec_domain default_exec_domain;
63165
63166 union thread_union {
63167+#ifndef CONFIG_X86
63168 struct thread_info thread_info;
63169+#endif
63170 unsigned long stack[THREAD_SIZE/sizeof(long)];
63171 };
63172
63173@@ -2179,6 +2278,7 @@ extern struct pid_namespace init_pid_ns;
63174 */
63175
63176 extern struct task_struct *find_task_by_vpid(pid_t nr);
63177+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63178 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63179 struct pid_namespace *ns);
63180
63181@@ -2322,7 +2422,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63182 extern void exit_itimers(struct signal_struct *);
63183 extern void flush_itimer_signals(void);
63184
63185-extern void do_group_exit(int);
63186+extern __noreturn void do_group_exit(int);
63187
63188 extern void daemonize(const char *, ...);
63189 extern int allow_signal(int);
63190@@ -2523,9 +2623,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63191
63192 #endif
63193
63194-static inline int object_is_on_stack(void *obj)
63195+static inline int object_starts_on_stack(void *obj)
63196 {
63197- void *stack = task_stack_page(current);
63198+ const void *stack = task_stack_page(current);
63199
63200 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63201 }
63202diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63203index 899fbb4..1cb4138 100644
63204--- a/include/linux/screen_info.h
63205+++ b/include/linux/screen_info.h
63206@@ -43,7 +43,8 @@ struct screen_info {
63207 __u16 pages; /* 0x32 */
63208 __u16 vesa_attributes; /* 0x34 */
63209 __u32 capabilities; /* 0x36 */
63210- __u8 _reserved[6]; /* 0x3a */
63211+ __u16 vesapm_size; /* 0x3a */
63212+ __u8 _reserved[4]; /* 0x3c */
63213 } __attribute__((packed));
63214
63215 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63216diff --git a/include/linux/security.h b/include/linux/security.h
63217index 673afbb..2b7454b 100644
63218--- a/include/linux/security.h
63219+++ b/include/linux/security.h
63220@@ -26,6 +26,7 @@
63221 #include <linux/capability.h>
63222 #include <linux/slab.h>
63223 #include <linux/err.h>
63224+#include <linux/grsecurity.h>
63225
63226 struct linux_binprm;
63227 struct cred;
63228diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63229index fc61854..d7c490b 100644
63230--- a/include/linux/seq_file.h
63231+++ b/include/linux/seq_file.h
63232@@ -25,6 +25,9 @@ struct seq_file {
63233 struct mutex lock;
63234 const struct seq_operations *op;
63235 int poll_event;
63236+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63237+ u64 exec_id;
63238+#endif
63239 void *private;
63240 };
63241
63242@@ -34,6 +37,7 @@ struct seq_operations {
63243 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63244 int (*show) (struct seq_file *m, void *v);
63245 };
63246+typedef struct seq_operations __no_const seq_operations_no_const;
63247
63248 #define SEQ_SKIP 1
63249
63250diff --git a/include/linux/shm.h b/include/linux/shm.h
63251index 92808b8..c28cac4 100644
63252--- a/include/linux/shm.h
63253+++ b/include/linux/shm.h
63254@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63255
63256 /* The task created the shm object. NULL if the task is dead. */
63257 struct task_struct *shm_creator;
63258+#ifdef CONFIG_GRKERNSEC
63259+ time_t shm_createtime;
63260+ pid_t shm_lapid;
63261+#endif
63262 };
63263
63264 /* shm_mode upper byte flags */
63265diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63266index c1bae8d..2dbcd31 100644
63267--- a/include/linux/skbuff.h
63268+++ b/include/linux/skbuff.h
63269@@ -663,7 +663,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63270 */
63271 static inline int skb_queue_empty(const struct sk_buff_head *list)
63272 {
63273- return list->next == (struct sk_buff *)list;
63274+ return list->next == (const struct sk_buff *)list;
63275 }
63276
63277 /**
63278@@ -676,7 +676,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63279 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63280 const struct sk_buff *skb)
63281 {
63282- return skb->next == (struct sk_buff *)list;
63283+ return skb->next == (const struct sk_buff *)list;
63284 }
63285
63286 /**
63287@@ -689,7 +689,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63288 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63289 const struct sk_buff *skb)
63290 {
63291- return skb->prev == (struct sk_buff *)list;
63292+ return skb->prev == (const struct sk_buff *)list;
63293 }
63294
63295 /**
63296@@ -1584,7 +1584,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63297 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63298 */
63299 #ifndef NET_SKB_PAD
63300-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63301+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63302 #endif
63303
63304 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63305diff --git a/include/linux/slab.h b/include/linux/slab.h
63306index a595dce..dfab0d2 100644
63307--- a/include/linux/slab.h
63308+++ b/include/linux/slab.h
63309@@ -11,12 +11,20 @@
63310
63311 #include <linux/gfp.h>
63312 #include <linux/types.h>
63313+#include <linux/err.h>
63314
63315 /*
63316 * Flags to pass to kmem_cache_create().
63317 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63318 */
63319 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63320+
63321+#ifdef CONFIG_PAX_USERCOPY_SLABS
63322+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63323+#else
63324+#define SLAB_USERCOPY 0x00000000UL
63325+#endif
63326+
63327 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63328 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63329 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63330@@ -87,10 +95,13 @@
63331 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63332 * Both make kfree a no-op.
63333 */
63334-#define ZERO_SIZE_PTR ((void *)16)
63335+#define ZERO_SIZE_PTR \
63336+({ \
63337+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63338+ (void *)(-MAX_ERRNO-1L); \
63339+})
63340
63341-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63342- (unsigned long)ZERO_SIZE_PTR)
63343+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63344
63345 /*
63346 * struct kmem_cache related prototypes
63347@@ -161,6 +172,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
63348 void kfree(const void *);
63349 void kzfree(const void *);
63350 size_t ksize(const void *);
63351+const char *check_heap_object(const void *ptr, unsigned long n, bool to);
63352+bool is_usercopy_object(const void *ptr);
63353
63354 /*
63355 * Allocator specific definitions. These are mainly used to establish optimized
63356@@ -240,6 +253,7 @@ size_t ksize(const void *);
63357 * for general use, and so are not documented here. For a full list of
63358 * potential flags, always refer to linux/gfp.h.
63359 */
63360+static void *kmalloc_array(size_t n, size_t size, gfp_t flags) __size_overflow(1, 2);
63361 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
63362 {
63363 if (size != 0 && n > ULONG_MAX / size)
63364@@ -298,7 +312,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63365 */
63366 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63367 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63368-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63369+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63370 #define kmalloc_track_caller(size, flags) \
63371 __kmalloc_track_caller(size, flags, _RET_IP_)
63372 #else
63373@@ -317,7 +331,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63374 */
63375 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63376 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63377-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63378+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63379 #define kmalloc_node_track_caller(size, flags, node) \
63380 __kmalloc_node_track_caller(size, flags, node, \
63381 _RET_IP_)
63382diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63383index fbd1117..0a3d314 100644
63384--- a/include/linux/slab_def.h
63385+++ b/include/linux/slab_def.h
63386@@ -66,10 +66,10 @@ struct kmem_cache {
63387 unsigned long node_allocs;
63388 unsigned long node_frees;
63389 unsigned long node_overflow;
63390- atomic_t allochit;
63391- atomic_t allocmiss;
63392- atomic_t freehit;
63393- atomic_t freemiss;
63394+ atomic_unchecked_t allochit;
63395+ atomic_unchecked_t allocmiss;
63396+ atomic_unchecked_t freehit;
63397+ atomic_unchecked_t freemiss;
63398
63399 /*
63400 * If debugging is enabled, then the allocator can add additional
63401@@ -103,11 +103,16 @@ struct cache_sizes {
63402 #ifdef CONFIG_ZONE_DMA
63403 struct kmem_cache *cs_dmacachep;
63404 #endif
63405+
63406+#ifdef CONFIG_PAX_USERCOPY_SLABS
63407+ struct kmem_cache *cs_usercopycachep;
63408+#endif
63409+
63410 };
63411 extern struct cache_sizes malloc_sizes[];
63412
63413 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63414-void *__kmalloc(size_t size, gfp_t flags);
63415+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63416
63417 #ifdef CONFIG_TRACING
63418 extern void *kmem_cache_alloc_trace(size_t size,
63419@@ -150,6 +155,13 @@ found:
63420 cachep = malloc_sizes[i].cs_dmacachep;
63421 else
63422 #endif
63423+
63424+#ifdef CONFIG_PAX_USERCOPY_SLABS
63425+ if (flags & GFP_USERCOPY)
63426+ cachep = malloc_sizes[i].cs_usercopycachep;
63427+ else
63428+#endif
63429+
63430 cachep = malloc_sizes[i].cs_cachep;
63431
63432 ret = kmem_cache_alloc_trace(size, cachep, flags);
63433@@ -160,7 +172,7 @@ found:
63434 }
63435
63436 #ifdef CONFIG_NUMA
63437-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63438+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63439 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63440
63441 #ifdef CONFIG_TRACING
63442@@ -203,6 +215,13 @@ found:
63443 cachep = malloc_sizes[i].cs_dmacachep;
63444 else
63445 #endif
63446+
63447+#ifdef CONFIG_PAX_USERCOPY_SLABS
63448+ if (flags & GFP_USERCOPY)
63449+ cachep = malloc_sizes[i].cs_usercopycachep;
63450+ else
63451+#endif
63452+
63453 cachep = malloc_sizes[i].cs_cachep;
63454
63455 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
63456diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63457index 0ec00b3..39cb7fc 100644
63458--- a/include/linux/slob_def.h
63459+++ b/include/linux/slob_def.h
63460@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63461 return kmem_cache_alloc_node(cachep, flags, -1);
63462 }
63463
63464-void *__kmalloc_node(size_t size, gfp_t flags, int node);
63465+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63466
63467 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63468 {
63469@@ -29,6 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63470 return __kmalloc_node(size, flags, -1);
63471 }
63472
63473+static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63474 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63475 {
63476 return kmalloc(size, flags);
63477diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63478index c2f8c8b..be9e036 100644
63479--- a/include/linux/slub_def.h
63480+++ b/include/linux/slub_def.h
63481@@ -92,7 +92,7 @@ struct kmem_cache {
63482 struct kmem_cache_order_objects max;
63483 struct kmem_cache_order_objects min;
63484 gfp_t allocflags; /* gfp flags to use on each alloc */
63485- int refcount; /* Refcount for slab cache destroy */
63486+ atomic_t refcount; /* Refcount for slab cache destroy */
63487 void (*ctor)(void *);
63488 int inuse; /* Offset to metadata */
63489 int align; /* Alignment */
63490@@ -153,6 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
63491 * Sorry that the following has to be that ugly but some versions of GCC
63492 * have trouble with constant propagation and loops.
63493 */
63494+static __always_inline int kmalloc_index(size_t size) __size_overflow(1);
63495 static __always_inline int kmalloc_index(size_t size)
63496 {
63497 if (!size)
63498@@ -218,7 +219,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63499 }
63500
63501 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63502-void *__kmalloc(size_t size, gfp_t flags);
63503+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63504
63505 static __always_inline void *
63506 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63507@@ -259,6 +260,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63508 }
63509 #endif
63510
63511+static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
63512 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63513 {
63514 unsigned int order = get_order(size);
63515@@ -284,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63516 }
63517
63518 #ifdef CONFIG_NUMA
63519-void *__kmalloc_node(size_t size, gfp_t flags, int node);
63520+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63521 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63522
63523 #ifdef CONFIG_TRACING
63524diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63525index de8832d..0147b46 100644
63526--- a/include/linux/sonet.h
63527+++ b/include/linux/sonet.h
63528@@ -61,7 +61,7 @@ struct sonet_stats {
63529 #include <linux/atomic.h>
63530
63531 struct k_sonet_stats {
63532-#define __HANDLE_ITEM(i) atomic_t i
63533+#define __HANDLE_ITEM(i) atomic_unchecked_t i
63534 __SONET_ITEMS
63535 #undef __HANDLE_ITEM
63536 };
63537diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63538index 523547e..2cb7140 100644
63539--- a/include/linux/sunrpc/clnt.h
63540+++ b/include/linux/sunrpc/clnt.h
63541@@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63542 {
63543 switch (sap->sa_family) {
63544 case AF_INET:
63545- return ntohs(((struct sockaddr_in *)sap)->sin_port);
63546+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63547 case AF_INET6:
63548- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63549+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63550 }
63551 return 0;
63552 }
63553@@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63554 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63555 const struct sockaddr *src)
63556 {
63557- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63558+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63559 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63560
63561 dsin->sin_family = ssin->sin_family;
63562@@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63563 if (sa->sa_family != AF_INET6)
63564 return 0;
63565
63566- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63567+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63568 }
63569
63570 #endif /* __KERNEL__ */
63571diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63572index dc0c3cc..8503fb6 100644
63573--- a/include/linux/sunrpc/sched.h
63574+++ b/include/linux/sunrpc/sched.h
63575@@ -106,6 +106,7 @@ struct rpc_call_ops {
63576 void (*rpc_count_stats)(struct rpc_task *, void *);
63577 void (*rpc_release)(void *);
63578 };
63579+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63580
63581 struct rpc_task_setup {
63582 struct rpc_task *task;
63583diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63584index 0b8e3e6..33e0a01 100644
63585--- a/include/linux/sunrpc/svc_rdma.h
63586+++ b/include/linux/sunrpc/svc_rdma.h
63587@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63588 extern unsigned int svcrdma_max_requests;
63589 extern unsigned int svcrdma_max_req_size;
63590
63591-extern atomic_t rdma_stat_recv;
63592-extern atomic_t rdma_stat_read;
63593-extern atomic_t rdma_stat_write;
63594-extern atomic_t rdma_stat_sq_starve;
63595-extern atomic_t rdma_stat_rq_starve;
63596-extern atomic_t rdma_stat_rq_poll;
63597-extern atomic_t rdma_stat_rq_prod;
63598-extern atomic_t rdma_stat_sq_poll;
63599-extern atomic_t rdma_stat_sq_prod;
63600+extern atomic_unchecked_t rdma_stat_recv;
63601+extern atomic_unchecked_t rdma_stat_read;
63602+extern atomic_unchecked_t rdma_stat_write;
63603+extern atomic_unchecked_t rdma_stat_sq_starve;
63604+extern atomic_unchecked_t rdma_stat_rq_starve;
63605+extern atomic_unchecked_t rdma_stat_rq_poll;
63606+extern atomic_unchecked_t rdma_stat_rq_prod;
63607+extern atomic_unchecked_t rdma_stat_sq_poll;
63608+extern atomic_unchecked_t rdma_stat_sq_prod;
63609
63610 #define RPCRDMA_VERSION 1
63611
63612diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63613index c34b4c8..a65b67d 100644
63614--- a/include/linux/sysctl.h
63615+++ b/include/linux/sysctl.h
63616@@ -155,7 +155,11 @@ enum
63617 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63618 };
63619
63620-
63621+#ifdef CONFIG_PAX_SOFTMODE
63622+enum {
63623+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63624+};
63625+#endif
63626
63627 /* CTL_VM names: */
63628 enum
63629@@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63630
63631 extern int proc_dostring(struct ctl_table *, int,
63632 void __user *, size_t *, loff_t *);
63633+extern int proc_dostring_modpriv(struct ctl_table *, int,
63634+ void __user *, size_t *, loff_t *);
63635 extern int proc_dointvec(struct ctl_table *, int,
63636 void __user *, size_t *, loff_t *);
63637 extern int proc_dointvec_minmax(struct ctl_table *, int,
63638diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63639index ff7dc08..893e1bd 100644
63640--- a/include/linux/tty_ldisc.h
63641+++ b/include/linux/tty_ldisc.h
63642@@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63643
63644 struct module *owner;
63645
63646- int refcount;
63647+ atomic_t refcount;
63648 };
63649
63650 struct tty_ldisc {
63651diff --git a/include/linux/types.h b/include/linux/types.h
63652index 7f480db..175c256 100644
63653--- a/include/linux/types.h
63654+++ b/include/linux/types.h
63655@@ -220,10 +220,26 @@ typedef struct {
63656 int counter;
63657 } atomic_t;
63658
63659+#ifdef CONFIG_PAX_REFCOUNT
63660+typedef struct {
63661+ int counter;
63662+} atomic_unchecked_t;
63663+#else
63664+typedef atomic_t atomic_unchecked_t;
63665+#endif
63666+
63667 #ifdef CONFIG_64BIT
63668 typedef struct {
63669 long counter;
63670 } atomic64_t;
63671+
63672+#ifdef CONFIG_PAX_REFCOUNT
63673+typedef struct {
63674+ long counter;
63675+} atomic64_unchecked_t;
63676+#else
63677+typedef atomic64_t atomic64_unchecked_t;
63678+#endif
63679 #endif
63680
63681 struct list_head {
63682diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63683index 5ca0951..ab496a5 100644
63684--- a/include/linux/uaccess.h
63685+++ b/include/linux/uaccess.h
63686@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63687 long ret; \
63688 mm_segment_t old_fs = get_fs(); \
63689 \
63690- set_fs(KERNEL_DS); \
63691 pagefault_disable(); \
63692- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63693- pagefault_enable(); \
63694+ set_fs(KERNEL_DS); \
63695+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63696 set_fs(old_fs); \
63697+ pagefault_enable(); \
63698 ret; \
63699 })
63700
63701diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63702index 99c1b4d..bb94261 100644
63703--- a/include/linux/unaligned/access_ok.h
63704+++ b/include/linux/unaligned/access_ok.h
63705@@ -6,32 +6,32 @@
63706
63707 static inline u16 get_unaligned_le16(const void *p)
63708 {
63709- return le16_to_cpup((__le16 *)p);
63710+ return le16_to_cpup((const __le16 *)p);
63711 }
63712
63713 static inline u32 get_unaligned_le32(const void *p)
63714 {
63715- return le32_to_cpup((__le32 *)p);
63716+ return le32_to_cpup((const __le32 *)p);
63717 }
63718
63719 static inline u64 get_unaligned_le64(const void *p)
63720 {
63721- return le64_to_cpup((__le64 *)p);
63722+ return le64_to_cpup((const __le64 *)p);
63723 }
63724
63725 static inline u16 get_unaligned_be16(const void *p)
63726 {
63727- return be16_to_cpup((__be16 *)p);
63728+ return be16_to_cpup((const __be16 *)p);
63729 }
63730
63731 static inline u32 get_unaligned_be32(const void *p)
63732 {
63733- return be32_to_cpup((__be32 *)p);
63734+ return be32_to_cpup((const __be32 *)p);
63735 }
63736
63737 static inline u64 get_unaligned_be64(const void *p)
63738 {
63739- return be64_to_cpup((__be64 *)p);
63740+ return be64_to_cpup((const __be64 *)p);
63741 }
63742
63743 static inline void put_unaligned_le16(u16 val, void *p)
63744diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
63745index 547e59c..db6ad19 100644
63746--- a/include/linux/usb/renesas_usbhs.h
63747+++ b/include/linux/usb/renesas_usbhs.h
63748@@ -39,7 +39,7 @@ enum {
63749 */
63750 struct renesas_usbhs_driver_callback {
63751 int (*notify_hotplug)(struct platform_device *pdev);
63752-};
63753+} __no_const;
63754
63755 /*
63756 * callback functions for platform
63757@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
63758 * VBUS control is needed for Host
63759 */
63760 int (*set_vbus)(struct platform_device *pdev, int enable);
63761-};
63762+} __no_const;
63763
63764 /*
63765 * parameters for renesas usbhs
63766diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
63767index 6f8fbcf..8259001 100644
63768--- a/include/linux/vermagic.h
63769+++ b/include/linux/vermagic.h
63770@@ -25,9 +25,35 @@
63771 #define MODULE_ARCH_VERMAGIC ""
63772 #endif
63773
63774+#ifdef CONFIG_PAX_REFCOUNT
63775+#define MODULE_PAX_REFCOUNT "REFCOUNT "
63776+#else
63777+#define MODULE_PAX_REFCOUNT ""
63778+#endif
63779+
63780+#ifdef CONSTIFY_PLUGIN
63781+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
63782+#else
63783+#define MODULE_CONSTIFY_PLUGIN ""
63784+#endif
63785+
63786+#ifdef STACKLEAK_PLUGIN
63787+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
63788+#else
63789+#define MODULE_STACKLEAK_PLUGIN ""
63790+#endif
63791+
63792+#ifdef CONFIG_GRKERNSEC
63793+#define MODULE_GRSEC "GRSEC "
63794+#else
63795+#define MODULE_GRSEC ""
63796+#endif
63797+
63798 #define VERMAGIC_STRING \
63799 UTS_RELEASE " " \
63800 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
63801 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
63802- MODULE_ARCH_VERMAGIC
63803+ MODULE_ARCH_VERMAGIC \
63804+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
63805+ MODULE_GRSEC
63806
63807diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
63808index dcdfc2b..ec79ab5 100644
63809--- a/include/linux/vmalloc.h
63810+++ b/include/linux/vmalloc.h
63811@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
63812 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
63813 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
63814 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
63815+
63816+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
63817+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
63818+#endif
63819+
63820 /* bits [20..32] reserved for arch specific ioremap internals */
63821
63822 /*
63823@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
63824 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
63825 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
63826 unsigned long start, unsigned long end, gfp_t gfp_mask,
63827- pgprot_t prot, int node, void *caller);
63828+ pgprot_t prot, int node, void *caller) __size_overflow(1);
63829 extern void vfree(const void *addr);
63830
63831 extern void *vmap(struct page **pages, unsigned int count,
63832@@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
63833 extern void free_vm_area(struct vm_struct *area);
63834
63835 /* for /dev/kmem */
63836-extern long vread(char *buf, char *addr, unsigned long count);
63837-extern long vwrite(char *buf, char *addr, unsigned long count);
63838+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
63839+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
63840
63841 /*
63842 * Internals. Dont't use..
63843diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
63844index 65efb92..137adbb 100644
63845--- a/include/linux/vmstat.h
63846+++ b/include/linux/vmstat.h
63847@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
63848 /*
63849 * Zone based page accounting with per cpu differentials.
63850 */
63851-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63852+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63853
63854 static inline void zone_page_state_add(long x, struct zone *zone,
63855 enum zone_stat_item item)
63856 {
63857- atomic_long_add(x, &zone->vm_stat[item]);
63858- atomic_long_add(x, &vm_stat[item]);
63859+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
63860+ atomic_long_add_unchecked(x, &vm_stat[item]);
63861 }
63862
63863 static inline unsigned long global_page_state(enum zone_stat_item item)
63864 {
63865- long x = atomic_long_read(&vm_stat[item]);
63866+ long x = atomic_long_read_unchecked(&vm_stat[item]);
63867 #ifdef CONFIG_SMP
63868 if (x < 0)
63869 x = 0;
63870@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
63871 static inline unsigned long zone_page_state(struct zone *zone,
63872 enum zone_stat_item item)
63873 {
63874- long x = atomic_long_read(&zone->vm_stat[item]);
63875+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63876 #ifdef CONFIG_SMP
63877 if (x < 0)
63878 x = 0;
63879@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
63880 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
63881 enum zone_stat_item item)
63882 {
63883- long x = atomic_long_read(&zone->vm_stat[item]);
63884+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63885
63886 #ifdef CONFIG_SMP
63887 int cpu;
63888@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
63889
63890 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
63891 {
63892- atomic_long_inc(&zone->vm_stat[item]);
63893- atomic_long_inc(&vm_stat[item]);
63894+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
63895+ atomic_long_inc_unchecked(&vm_stat[item]);
63896 }
63897
63898 static inline void __inc_zone_page_state(struct page *page,
63899@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
63900
63901 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
63902 {
63903- atomic_long_dec(&zone->vm_stat[item]);
63904- atomic_long_dec(&vm_stat[item]);
63905+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
63906+ atomic_long_dec_unchecked(&vm_stat[item]);
63907 }
63908
63909 static inline void __dec_zone_page_state(struct page *page,
63910diff --git a/include/linux/xattr.h b/include/linux/xattr.h
63911index e5d1220..ef6e406 100644
63912--- a/include/linux/xattr.h
63913+++ b/include/linux/xattr.h
63914@@ -57,6 +57,11 @@
63915 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
63916 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
63917
63918+/* User namespace */
63919+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
63920+#define XATTR_PAX_FLAGS_SUFFIX "flags"
63921+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
63922+
63923 #ifdef __KERNEL__
63924
63925 #include <linux/types.h>
63926diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
63927index 4aeff96..b378cdc 100644
63928--- a/include/media/saa7146_vv.h
63929+++ b/include/media/saa7146_vv.h
63930@@ -163,7 +163,7 @@ struct saa7146_ext_vv
63931 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
63932
63933 /* the extension can override this */
63934- struct v4l2_ioctl_ops ops;
63935+ v4l2_ioctl_ops_no_const ops;
63936 /* pointer to the saa7146 core ops */
63937 const struct v4l2_ioctl_ops *core_ops;
63938
63939diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
63940index 96d2221..2292f89 100644
63941--- a/include/media/v4l2-dev.h
63942+++ b/include/media/v4l2-dev.h
63943@@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
63944
63945
63946 struct v4l2_file_operations {
63947- struct module *owner;
63948+ struct module * const owner;
63949 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
63950 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
63951 unsigned int (*poll) (struct file *, struct poll_table_struct *);
63952@@ -71,6 +71,7 @@ struct v4l2_file_operations {
63953 int (*open) (struct file *);
63954 int (*release) (struct file *);
63955 };
63956+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
63957
63958 /*
63959 * Newer version of video_device, handled by videodev2.c
63960diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
63961index 3cb939c..f23c6bb 100644
63962--- a/include/media/v4l2-ioctl.h
63963+++ b/include/media/v4l2-ioctl.h
63964@@ -281,7 +281,7 @@ struct v4l2_ioctl_ops {
63965 long (*vidioc_default) (struct file *file, void *fh,
63966 bool valid_prio, int cmd, void *arg);
63967 };
63968-
63969+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
63970
63971 /* v4l debugging and diagnostics */
63972
63973diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
63974index 6db8ecf..8c23861 100644
63975--- a/include/net/caif/caif_hsi.h
63976+++ b/include/net/caif/caif_hsi.h
63977@@ -98,7 +98,7 @@ struct cfhsi_drv {
63978 void (*rx_done_cb) (struct cfhsi_drv *drv);
63979 void (*wake_up_cb) (struct cfhsi_drv *drv);
63980 void (*wake_down_cb) (struct cfhsi_drv *drv);
63981-};
63982+} __no_const;
63983
63984 /* Structure implemented by HSI device. */
63985 struct cfhsi_dev {
63986diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
63987index 9e5425b..8136ffc 100644
63988--- a/include/net/caif/cfctrl.h
63989+++ b/include/net/caif/cfctrl.h
63990@@ -52,7 +52,7 @@ struct cfctrl_rsp {
63991 void (*radioset_rsp)(void);
63992 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
63993 struct cflayer *client_layer);
63994-};
63995+} __no_const;
63996
63997 /* Link Setup Parameters for CAIF-Links. */
63998 struct cfctrl_link_param {
63999@@ -101,8 +101,8 @@ struct cfctrl_request_info {
64000 struct cfctrl {
64001 struct cfsrvl serv;
64002 struct cfctrl_rsp res;
64003- atomic_t req_seq_no;
64004- atomic_t rsp_seq_no;
64005+ atomic_unchecked_t req_seq_no;
64006+ atomic_unchecked_t rsp_seq_no;
64007 struct list_head list;
64008 /* Protects from simultaneous access to first_req list */
64009 spinlock_t info_list_lock;
64010diff --git a/include/net/flow.h b/include/net/flow.h
64011index 6c469db..7743b8e 100644
64012--- a/include/net/flow.h
64013+++ b/include/net/flow.h
64014@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64015
64016 extern void flow_cache_flush(void);
64017 extern void flow_cache_flush_deferred(void);
64018-extern atomic_t flow_cache_genid;
64019+extern atomic_unchecked_t flow_cache_genid;
64020
64021 #endif
64022diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64023index 2040bff..f4c0733 100644
64024--- a/include/net/inetpeer.h
64025+++ b/include/net/inetpeer.h
64026@@ -51,8 +51,8 @@ struct inet_peer {
64027 */
64028 union {
64029 struct {
64030- atomic_t rid; /* Frag reception counter */
64031- atomic_t ip_id_count; /* IP ID for the next packet */
64032+ atomic_unchecked_t rid; /* Frag reception counter */
64033+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64034 __u32 tcp_ts;
64035 __u32 tcp_ts_stamp;
64036 };
64037@@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64038 more++;
64039 inet_peer_refcheck(p);
64040 do {
64041- old = atomic_read(&p->ip_id_count);
64042+ old = atomic_read_unchecked(&p->ip_id_count);
64043 new = old + more;
64044 if (!new)
64045 new = 1;
64046- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64047+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64048 return new;
64049 }
64050
64051diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64052index 10422ef..662570f 100644
64053--- a/include/net/ip_fib.h
64054+++ b/include/net/ip_fib.h
64055@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64056
64057 #define FIB_RES_SADDR(net, res) \
64058 ((FIB_RES_NH(res).nh_saddr_genid == \
64059- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64060+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64061 FIB_RES_NH(res).nh_saddr : \
64062 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64063 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64064diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64065index 72522f0..2965e05 100644
64066--- a/include/net/ip_vs.h
64067+++ b/include/net/ip_vs.h
64068@@ -510,7 +510,7 @@ struct ip_vs_conn {
64069 struct ip_vs_conn *control; /* Master control connection */
64070 atomic_t n_control; /* Number of controlled ones */
64071 struct ip_vs_dest *dest; /* real server */
64072- atomic_t in_pkts; /* incoming packet counter */
64073+ atomic_unchecked_t in_pkts; /* incoming packet counter */
64074
64075 /* packet transmitter for different forwarding methods. If it
64076 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64077@@ -648,7 +648,7 @@ struct ip_vs_dest {
64078 __be16 port; /* port number of the server */
64079 union nf_inet_addr addr; /* IP address of the server */
64080 volatile unsigned flags; /* dest status flags */
64081- atomic_t conn_flags; /* flags to copy to conn */
64082+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
64083 atomic_t weight; /* server weight */
64084
64085 atomic_t refcnt; /* reference counter */
64086@@ -1356,7 +1356,7 @@ static inline void ip_vs_notrack(struct sk_buff *skb)
64087 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
64088
64089 if (!ct || !nf_ct_is_untracked(ct)) {
64090- nf_reset(skb);
64091+ nf_conntrack_put(skb->nfct);
64092 skb->nfct = &nf_ct_untracked_get()->ct_general;
64093 skb->nfctinfo = IP_CT_NEW;
64094 nf_conntrack_get(skb->nfct);
64095diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64096index 69b610a..fe3962c 100644
64097--- a/include/net/irda/ircomm_core.h
64098+++ b/include/net/irda/ircomm_core.h
64099@@ -51,7 +51,7 @@ typedef struct {
64100 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64101 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64102 struct ircomm_info *);
64103-} call_t;
64104+} __no_const call_t;
64105
64106 struct ircomm_cb {
64107 irda_queue_t queue;
64108diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64109index 59ba38bc..d515662 100644
64110--- a/include/net/irda/ircomm_tty.h
64111+++ b/include/net/irda/ircomm_tty.h
64112@@ -35,6 +35,7 @@
64113 #include <linux/termios.h>
64114 #include <linux/timer.h>
64115 #include <linux/tty.h> /* struct tty_struct */
64116+#include <asm/local.h>
64117
64118 #include <net/irda/irias_object.h>
64119 #include <net/irda/ircomm_core.h>
64120@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64121 unsigned short close_delay;
64122 unsigned short closing_wait; /* time to wait before closing */
64123
64124- int open_count;
64125- int blocked_open; /* # of blocked opens */
64126+ local_t open_count;
64127+ local_t blocked_open; /* # of blocked opens */
64128
64129 /* Protect concurent access to :
64130 * o self->open_count
64131diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64132index cc7c197..9f2da2a 100644
64133--- a/include/net/iucv/af_iucv.h
64134+++ b/include/net/iucv/af_iucv.h
64135@@ -141,7 +141,7 @@ struct iucv_sock {
64136 struct iucv_sock_list {
64137 struct hlist_head head;
64138 rwlock_t lock;
64139- atomic_t autobind_name;
64140+ atomic_unchecked_t autobind_name;
64141 };
64142
64143 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64144diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64145index 34c996f..bb3b4d4 100644
64146--- a/include/net/neighbour.h
64147+++ b/include/net/neighbour.h
64148@@ -123,7 +123,7 @@ struct neigh_ops {
64149 void (*error_report)(struct neighbour *, struct sk_buff *);
64150 int (*output)(struct neighbour *, struct sk_buff *);
64151 int (*connected_output)(struct neighbour *, struct sk_buff *);
64152-};
64153+} __do_const;
64154
64155 struct pneigh_entry {
64156 struct pneigh_entry *next;
64157diff --git a/include/net/netlink.h b/include/net/netlink.h
64158index f394fe5..fd073f9 100644
64159--- a/include/net/netlink.h
64160+++ b/include/net/netlink.h
64161@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64162 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64163 {
64164 if (mark)
64165- skb_trim(skb, (unsigned char *) mark - skb->data);
64166+ skb_trim(skb, (const unsigned char *) mark - skb->data);
64167 }
64168
64169 /**
64170diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64171index bbd023a..97c6d0d 100644
64172--- a/include/net/netns/ipv4.h
64173+++ b/include/net/netns/ipv4.h
64174@@ -57,8 +57,8 @@ struct netns_ipv4 {
64175 unsigned int sysctl_ping_group_range[2];
64176 long sysctl_tcp_mem[3];
64177
64178- atomic_t rt_genid;
64179- atomic_t dev_addr_genid;
64180+ atomic_unchecked_t rt_genid;
64181+ atomic_unchecked_t dev_addr_genid;
64182
64183 #ifdef CONFIG_IP_MROUTE
64184 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64185diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64186index a2ef814..31a8e3f 100644
64187--- a/include/net/sctp/sctp.h
64188+++ b/include/net/sctp/sctp.h
64189@@ -318,9 +318,9 @@ do { \
64190
64191 #else /* SCTP_DEBUG */
64192
64193-#define SCTP_DEBUG_PRINTK(whatever...)
64194-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64195-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64196+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64197+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64198+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64199 #define SCTP_ENABLE_DEBUG
64200 #define SCTP_DISABLE_DEBUG
64201 #define SCTP_ASSERT(expr, str, func)
64202diff --git a/include/net/sock.h b/include/net/sock.h
64203index 5a0a58a..2e3d4d0 100644
64204--- a/include/net/sock.h
64205+++ b/include/net/sock.h
64206@@ -302,7 +302,7 @@ struct sock {
64207 #ifdef CONFIG_RPS
64208 __u32 sk_rxhash;
64209 #endif
64210- atomic_t sk_drops;
64211+ atomic_unchecked_t sk_drops;
64212 int sk_rcvbuf;
64213
64214 struct sk_filter __rcu *sk_filter;
64215@@ -1691,7 +1691,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64216 }
64217
64218 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64219- char __user *from, char *to,
64220+ char __user *from, unsigned char *to,
64221 int copy, int offset)
64222 {
64223 if (skb->ip_summed == CHECKSUM_NONE) {
64224diff --git a/include/net/tcp.h b/include/net/tcp.h
64225index f75a04d..702cf06 100644
64226--- a/include/net/tcp.h
64227+++ b/include/net/tcp.h
64228@@ -1425,7 +1425,7 @@ struct tcp_seq_afinfo {
64229 char *name;
64230 sa_family_t family;
64231 const struct file_operations *seq_fops;
64232- struct seq_operations seq_ops;
64233+ seq_operations_no_const seq_ops;
64234 };
64235
64236 struct tcp_iter_state {
64237diff --git a/include/net/udp.h b/include/net/udp.h
64238index 5d606d9..e879f7b 100644
64239--- a/include/net/udp.h
64240+++ b/include/net/udp.h
64241@@ -244,7 +244,7 @@ struct udp_seq_afinfo {
64242 sa_family_t family;
64243 struct udp_table *udp_table;
64244 const struct file_operations *seq_fops;
64245- struct seq_operations seq_ops;
64246+ seq_operations_no_const seq_ops;
64247 };
64248
64249 struct udp_iter_state {
64250diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64251index 96239e7..c85b032 100644
64252--- a/include/net/xfrm.h
64253+++ b/include/net/xfrm.h
64254@@ -505,7 +505,7 @@ struct xfrm_policy {
64255 struct timer_list timer;
64256
64257 struct flow_cache_object flo;
64258- atomic_t genid;
64259+ atomic_unchecked_t genid;
64260 u32 priority;
64261 u32 index;
64262 struct xfrm_mark mark;
64263diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64264index 1a046b1..ee0bef0 100644
64265--- a/include/rdma/iw_cm.h
64266+++ b/include/rdma/iw_cm.h
64267@@ -122,7 +122,7 @@ struct iw_cm_verbs {
64268 int backlog);
64269
64270 int (*destroy_listen)(struct iw_cm_id *cm_id);
64271-};
64272+} __no_const;
64273
64274 /**
64275 * iw_create_cm_id - Create an IW CM identifier.
64276diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64277index 8f9dfba..610ab6c 100644
64278--- a/include/scsi/libfc.h
64279+++ b/include/scsi/libfc.h
64280@@ -756,6 +756,7 @@ struct libfc_function_template {
64281 */
64282 void (*disc_stop_final) (struct fc_lport *);
64283 };
64284+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64285
64286 /**
64287 * struct fc_disc - Discovery context
64288@@ -861,7 +862,7 @@ struct fc_lport {
64289 struct fc_vport *vport;
64290
64291 /* Operational Information */
64292- struct libfc_function_template tt;
64293+ libfc_function_template_no_const tt;
64294 u8 link_up;
64295 u8 qfull;
64296 enum fc_lport_state state;
64297diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64298index ba96988..ecf2eb9 100644
64299--- a/include/scsi/scsi_device.h
64300+++ b/include/scsi/scsi_device.h
64301@@ -163,9 +163,9 @@ struct scsi_device {
64302 unsigned int max_device_blocked; /* what device_blocked counts down from */
64303 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64304
64305- atomic_t iorequest_cnt;
64306- atomic_t iodone_cnt;
64307- atomic_t ioerr_cnt;
64308+ atomic_unchecked_t iorequest_cnt;
64309+ atomic_unchecked_t iodone_cnt;
64310+ atomic_unchecked_t ioerr_cnt;
64311
64312 struct device sdev_gendev,
64313 sdev_dev;
64314diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64315index 719faf1..d1154d4 100644
64316--- a/include/scsi/scsi_transport_fc.h
64317+++ b/include/scsi/scsi_transport_fc.h
64318@@ -739,7 +739,7 @@ struct fc_function_template {
64319 unsigned long show_host_system_hostname:1;
64320
64321 unsigned long disable_target_scan:1;
64322-};
64323+} __do_const;
64324
64325
64326 /**
64327diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64328index 030b87c..98a6954 100644
64329--- a/include/sound/ak4xxx-adda.h
64330+++ b/include/sound/ak4xxx-adda.h
64331@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64332 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64333 unsigned char val);
64334 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64335-};
64336+} __no_const;
64337
64338 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64339
64340diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64341index 8c05e47..2b5df97 100644
64342--- a/include/sound/hwdep.h
64343+++ b/include/sound/hwdep.h
64344@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64345 struct snd_hwdep_dsp_status *status);
64346 int (*dsp_load)(struct snd_hwdep *hw,
64347 struct snd_hwdep_dsp_image *image);
64348-};
64349+} __no_const;
64350
64351 struct snd_hwdep {
64352 struct snd_card *card;
64353diff --git a/include/sound/info.h b/include/sound/info.h
64354index 9ca1a49..aba1728 100644
64355--- a/include/sound/info.h
64356+++ b/include/sound/info.h
64357@@ -44,7 +44,7 @@ struct snd_info_entry_text {
64358 struct snd_info_buffer *buffer);
64359 void (*write)(struct snd_info_entry *entry,
64360 struct snd_info_buffer *buffer);
64361-};
64362+} __no_const;
64363
64364 struct snd_info_entry_ops {
64365 int (*open)(struct snd_info_entry *entry,
64366diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64367index 0d11128..814178e 100644
64368--- a/include/sound/pcm.h
64369+++ b/include/sound/pcm.h
64370@@ -81,6 +81,7 @@ struct snd_pcm_ops {
64371 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64372 int (*ack)(struct snd_pcm_substream *substream);
64373 };
64374+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64375
64376 /*
64377 *
64378diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64379index af1b49e..a5d55a5 100644
64380--- a/include/sound/sb16_csp.h
64381+++ b/include/sound/sb16_csp.h
64382@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64383 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64384 int (*csp_stop) (struct snd_sb_csp * p);
64385 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64386-};
64387+} __no_const;
64388
64389 /*
64390 * CSP private data
64391diff --git a/include/sound/soc.h b/include/sound/soc.h
64392index 2ebf787..0276839 100644
64393--- a/include/sound/soc.h
64394+++ b/include/sound/soc.h
64395@@ -711,7 +711,7 @@ struct snd_soc_platform_driver {
64396 /* platform IO - used for platform DAPM */
64397 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64398 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64399-};
64400+} __do_const;
64401
64402 struct snd_soc_platform {
64403 const char *name;
64404@@ -887,7 +887,7 @@ struct snd_soc_pcm_runtime {
64405 struct snd_soc_dai_link *dai_link;
64406 struct mutex pcm_mutex;
64407 enum snd_soc_pcm_subclass pcm_subclass;
64408- struct snd_pcm_ops ops;
64409+ snd_pcm_ops_no_const ops;
64410
64411 unsigned int complete:1;
64412 unsigned int dev_registered:1;
64413diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64414index 4119966..1a4671c 100644
64415--- a/include/sound/ymfpci.h
64416+++ b/include/sound/ymfpci.h
64417@@ -358,7 +358,7 @@ struct snd_ymfpci {
64418 spinlock_t reg_lock;
64419 spinlock_t voice_lock;
64420 wait_queue_head_t interrupt_sleep;
64421- atomic_t interrupt_sleep_count;
64422+ atomic_unchecked_t interrupt_sleep_count;
64423 struct snd_info_entry *proc_entry;
64424 const struct firmware *dsp_microcode;
64425 const struct firmware *controller_microcode;
64426diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64427index aaccc5f..092d568 100644
64428--- a/include/target/target_core_base.h
64429+++ b/include/target/target_core_base.h
64430@@ -447,7 +447,7 @@ struct t10_reservation_ops {
64431 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64432 int (*t10_pr_register)(struct se_cmd *);
64433 int (*t10_pr_clear)(struct se_cmd *);
64434-};
64435+} __no_const;
64436
64437 struct t10_reservation {
64438 /* Reservation effects all target ports */
64439@@ -576,7 +576,7 @@ struct se_cmd {
64440 atomic_t t_se_count;
64441 atomic_t t_task_cdbs_left;
64442 atomic_t t_task_cdbs_ex_left;
64443- atomic_t t_task_cdbs_sent;
64444+ atomic_unchecked_t t_task_cdbs_sent;
64445 unsigned int transport_state;
64446 #define CMD_T_ABORTED (1 << 0)
64447 #define CMD_T_ACTIVE (1 << 1)
64448@@ -802,7 +802,7 @@ struct se_device {
64449 spinlock_t stats_lock;
64450 /* Active commands on this virtual SE device */
64451 atomic_t simple_cmds;
64452- atomic_t dev_ordered_id;
64453+ atomic_unchecked_t dev_ordered_id;
64454 atomic_t execute_tasks;
64455 atomic_t dev_ordered_sync;
64456 atomic_t dev_qf_count;
64457diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
64458new file mode 100644
64459index 0000000..2efe49d
64460--- /dev/null
64461+++ b/include/trace/events/fs.h
64462@@ -0,0 +1,53 @@
64463+#undef TRACE_SYSTEM
64464+#define TRACE_SYSTEM fs
64465+
64466+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
64467+#define _TRACE_FS_H
64468+
64469+#include <linux/fs.h>
64470+#include <linux/tracepoint.h>
64471+
64472+TRACE_EVENT(do_sys_open,
64473+
64474+ TP_PROTO(char *filename, int flags, int mode),
64475+
64476+ TP_ARGS(filename, flags, mode),
64477+
64478+ TP_STRUCT__entry(
64479+ __string( filename, filename )
64480+ __field( int, flags )
64481+ __field( int, mode )
64482+ ),
64483+
64484+ TP_fast_assign(
64485+ __assign_str(filename, filename);
64486+ __entry->flags = flags;
64487+ __entry->mode = mode;
64488+ ),
64489+
64490+ TP_printk("\"%s\" %x %o",
64491+ __get_str(filename), __entry->flags, __entry->mode)
64492+);
64493+
64494+TRACE_EVENT(open_exec,
64495+
64496+ TP_PROTO(const char *filename),
64497+
64498+ TP_ARGS(filename),
64499+
64500+ TP_STRUCT__entry(
64501+ __string( filename, filename )
64502+ ),
64503+
64504+ TP_fast_assign(
64505+ __assign_str(filename, filename);
64506+ ),
64507+
64508+ TP_printk("\"%s\"",
64509+ __get_str(filename))
64510+);
64511+
64512+#endif /* _TRACE_FS_H */
64513+
64514+/* This part must be outside protection */
64515+#include <trace/define_trace.h>
64516diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64517index 1c09820..7f5ec79 100644
64518--- a/include/trace/events/irq.h
64519+++ b/include/trace/events/irq.h
64520@@ -36,7 +36,7 @@ struct softirq_action;
64521 */
64522 TRACE_EVENT(irq_handler_entry,
64523
64524- TP_PROTO(int irq, struct irqaction *action),
64525+ TP_PROTO(int irq, const struct irqaction *action),
64526
64527 TP_ARGS(irq, action),
64528
64529@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64530 */
64531 TRACE_EVENT(irq_handler_exit,
64532
64533- TP_PROTO(int irq, struct irqaction *action, int ret),
64534+ TP_PROTO(int irq, const struct irqaction *action, int ret),
64535
64536 TP_ARGS(irq, action, ret),
64537
64538diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64539index f9466fa..f4e2b81 100644
64540--- a/include/video/udlfb.h
64541+++ b/include/video/udlfb.h
64542@@ -53,10 +53,10 @@ struct dlfb_data {
64543 u32 pseudo_palette[256];
64544 int blank_mode; /*one of FB_BLANK_ */
64545 /* blit-only rendering path metrics, exposed through sysfs */
64546- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64547- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64548- atomic_t bytes_sent; /* to usb, after compression including overhead */
64549- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64550+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64551+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64552+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64553+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64554 };
64555
64556 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64557diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64558index 0993a22..32ba2fe 100644
64559--- a/include/video/uvesafb.h
64560+++ b/include/video/uvesafb.h
64561@@ -177,6 +177,7 @@ struct uvesafb_par {
64562 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64563 u8 pmi_setpal; /* PMI for palette changes */
64564 u16 *pmi_base; /* protected mode interface location */
64565+ u8 *pmi_code; /* protected mode code location */
64566 void *pmi_start;
64567 void *pmi_pal;
64568 u8 *vbe_state_orig; /*
64569diff --git a/init/Kconfig b/init/Kconfig
64570index 6cfd71d..16006e6 100644
64571--- a/init/Kconfig
64572+++ b/init/Kconfig
64573@@ -790,6 +790,7 @@ endif # CGROUPS
64574
64575 config CHECKPOINT_RESTORE
64576 bool "Checkpoint/restore support" if EXPERT
64577+ depends on !GRKERNSEC
64578 default n
64579 help
64580 Enables additional kernel features in a sake of checkpoint/restore.
64581@@ -1240,7 +1241,7 @@ config SLUB_DEBUG
64582
64583 config COMPAT_BRK
64584 bool "Disable heap randomization"
64585- default y
64586+ default n
64587 help
64588 Randomizing heap placement makes heap exploits harder, but it
64589 also breaks ancient binaries (including anything libc5 based).
64590@@ -1423,7 +1424,7 @@ config INIT_ALL_POSSIBLE
64591 config STOP_MACHINE
64592 bool
64593 default y
64594- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
64595+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
64596 help
64597 Need stop_machine() primitive.
64598
64599diff --git a/init/do_mounts.c b/init/do_mounts.c
64600index 42b0707..c06eef4 100644
64601--- a/init/do_mounts.c
64602+++ b/init/do_mounts.c
64603@@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
64604 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64605 {
64606 struct super_block *s;
64607- int err = sys_mount(name, "/root", fs, flags, data);
64608+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64609 if (err)
64610 return err;
64611
64612- sys_chdir((const char __user __force *)"/root");
64613+ sys_chdir((const char __force_user *)"/root");
64614 s = current->fs->pwd.dentry->d_sb;
64615 ROOT_DEV = s->s_dev;
64616 printk(KERN_INFO
64617@@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
64618 va_start(args, fmt);
64619 vsprintf(buf, fmt, args);
64620 va_end(args);
64621- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64622+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64623 if (fd >= 0) {
64624 sys_ioctl(fd, FDEJECT, 0);
64625 sys_close(fd);
64626 }
64627 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64628- fd = sys_open("/dev/console", O_RDWR, 0);
64629+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64630 if (fd >= 0) {
64631 sys_ioctl(fd, TCGETS, (long)&termios);
64632 termios.c_lflag &= ~ICANON;
64633 sys_ioctl(fd, TCSETSF, (long)&termios);
64634- sys_read(fd, &c, 1);
64635+ sys_read(fd, (char __user *)&c, 1);
64636 termios.c_lflag |= ICANON;
64637 sys_ioctl(fd, TCSETSF, (long)&termios);
64638 sys_close(fd);
64639@@ -555,6 +555,6 @@ void __init prepare_namespace(void)
64640 mount_root();
64641 out:
64642 devtmpfs_mount("dev");
64643- sys_mount(".", "/", NULL, MS_MOVE, NULL);
64644- sys_chroot((const char __user __force *)".");
64645+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64646+ sys_chroot((const char __force_user *)".");
64647 }
64648diff --git a/init/do_mounts.h b/init/do_mounts.h
64649index f5b978a..69dbfe8 100644
64650--- a/init/do_mounts.h
64651+++ b/init/do_mounts.h
64652@@ -15,15 +15,15 @@ extern int root_mountflags;
64653
64654 static inline int create_dev(char *name, dev_t dev)
64655 {
64656- sys_unlink(name);
64657- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64658+ sys_unlink((char __force_user *)name);
64659+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64660 }
64661
64662 #if BITS_PER_LONG == 32
64663 static inline u32 bstat(char *name)
64664 {
64665 struct stat64 stat;
64666- if (sys_stat64(name, &stat) != 0)
64667+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64668 return 0;
64669 if (!S_ISBLK(stat.st_mode))
64670 return 0;
64671@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64672 static inline u32 bstat(char *name)
64673 {
64674 struct stat stat;
64675- if (sys_newstat(name, &stat) != 0)
64676+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64677 return 0;
64678 if (!S_ISBLK(stat.st_mode))
64679 return 0;
64680diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64681index 9047330..de0d1fb 100644
64682--- a/init/do_mounts_initrd.c
64683+++ b/init/do_mounts_initrd.c
64684@@ -43,13 +43,13 @@ static void __init handle_initrd(void)
64685 create_dev("/dev/root.old", Root_RAM0);
64686 /* mount initrd on rootfs' /root */
64687 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64688- sys_mkdir("/old", 0700);
64689- root_fd = sys_open("/", 0, 0);
64690- old_fd = sys_open("/old", 0, 0);
64691+ sys_mkdir((const char __force_user *)"/old", 0700);
64692+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
64693+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64694 /* move initrd over / and chdir/chroot in initrd root */
64695- sys_chdir("/root");
64696- sys_mount(".", "/", NULL, MS_MOVE, NULL);
64697- sys_chroot(".");
64698+ sys_chdir((const char __force_user *)"/root");
64699+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64700+ sys_chroot((const char __force_user *)".");
64701
64702 /*
64703 * In case that a resume from disk is carried out by linuxrc or one of
64704@@ -66,15 +66,15 @@ static void __init handle_initrd(void)
64705
64706 /* move initrd to rootfs' /old */
64707 sys_fchdir(old_fd);
64708- sys_mount("/", ".", NULL, MS_MOVE, NULL);
64709+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64710 /* switch root and cwd back to / of rootfs */
64711 sys_fchdir(root_fd);
64712- sys_chroot(".");
64713+ sys_chroot((const char __force_user *)".");
64714 sys_close(old_fd);
64715 sys_close(root_fd);
64716
64717 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64718- sys_chdir("/old");
64719+ sys_chdir((const char __force_user *)"/old");
64720 return;
64721 }
64722
64723@@ -82,17 +82,17 @@ static void __init handle_initrd(void)
64724 mount_root();
64725
64726 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64727- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64728+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64729 if (!error)
64730 printk("okay\n");
64731 else {
64732- int fd = sys_open("/dev/root.old", O_RDWR, 0);
64733+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64734 if (error == -ENOENT)
64735 printk("/initrd does not exist. Ignored.\n");
64736 else
64737 printk("failed\n");
64738 printk(KERN_NOTICE "Unmounting old root\n");
64739- sys_umount("/old", MNT_DETACH);
64740+ sys_umount((char __force_user *)"/old", MNT_DETACH);
64741 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64742 if (fd < 0) {
64743 error = fd;
64744@@ -115,11 +115,11 @@ int __init initrd_load(void)
64745 * mounted in the normal path.
64746 */
64747 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
64748- sys_unlink("/initrd.image");
64749+ sys_unlink((const char __force_user *)"/initrd.image");
64750 handle_initrd();
64751 return 1;
64752 }
64753 }
64754- sys_unlink("/initrd.image");
64755+ sys_unlink((const char __force_user *)"/initrd.image");
64756 return 0;
64757 }
64758diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
64759index 32c4799..c27ee74 100644
64760--- a/init/do_mounts_md.c
64761+++ b/init/do_mounts_md.c
64762@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
64763 partitioned ? "_d" : "", minor,
64764 md_setup_args[ent].device_names);
64765
64766- fd = sys_open(name, 0, 0);
64767+ fd = sys_open((char __force_user *)name, 0, 0);
64768 if (fd < 0) {
64769 printk(KERN_ERR "md: open failed - cannot start "
64770 "array %s\n", name);
64771@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
64772 * array without it
64773 */
64774 sys_close(fd);
64775- fd = sys_open(name, 0, 0);
64776+ fd = sys_open((char __force_user *)name, 0, 0);
64777 sys_ioctl(fd, BLKRRPART, 0);
64778 }
64779 sys_close(fd);
64780@@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
64781
64782 wait_for_device_probe();
64783
64784- fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
64785+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
64786 if (fd >= 0) {
64787 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
64788 sys_close(fd);
64789diff --git a/init/initramfs.c b/init/initramfs.c
64790index 8216c30..25e8e32 100644
64791--- a/init/initramfs.c
64792+++ b/init/initramfs.c
64793@@ -74,7 +74,7 @@ static void __init free_hash(void)
64794 }
64795 }
64796
64797-static long __init do_utime(char __user *filename, time_t mtime)
64798+static long __init do_utime(__force char __user *filename, time_t mtime)
64799 {
64800 struct timespec t[2];
64801
64802@@ -109,7 +109,7 @@ static void __init dir_utime(void)
64803 struct dir_entry *de, *tmp;
64804 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64805 list_del(&de->list);
64806- do_utime(de->name, de->mtime);
64807+ do_utime((char __force_user *)de->name, de->mtime);
64808 kfree(de->name);
64809 kfree(de);
64810 }
64811@@ -271,7 +271,7 @@ static int __init maybe_link(void)
64812 if (nlink >= 2) {
64813 char *old = find_link(major, minor, ino, mode, collected);
64814 if (old)
64815- return (sys_link(old, collected) < 0) ? -1 : 1;
64816+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
64817 }
64818 return 0;
64819 }
64820@@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
64821 {
64822 struct stat st;
64823
64824- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
64825+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
64826 if (S_ISDIR(st.st_mode))
64827- sys_rmdir(path);
64828+ sys_rmdir((char __force_user *)path);
64829 else
64830- sys_unlink(path);
64831+ sys_unlink((char __force_user *)path);
64832 }
64833 }
64834
64835@@ -305,7 +305,7 @@ static int __init do_name(void)
64836 int openflags = O_WRONLY|O_CREAT;
64837 if (ml != 1)
64838 openflags |= O_TRUNC;
64839- wfd = sys_open(collected, openflags, mode);
64840+ wfd = sys_open((char __force_user *)collected, openflags, mode);
64841
64842 if (wfd >= 0) {
64843 sys_fchown(wfd, uid, gid);
64844@@ -317,17 +317,17 @@ static int __init do_name(void)
64845 }
64846 }
64847 } else if (S_ISDIR(mode)) {
64848- sys_mkdir(collected, mode);
64849- sys_chown(collected, uid, gid);
64850- sys_chmod(collected, mode);
64851+ sys_mkdir((char __force_user *)collected, mode);
64852+ sys_chown((char __force_user *)collected, uid, gid);
64853+ sys_chmod((char __force_user *)collected, mode);
64854 dir_add(collected, mtime);
64855 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
64856 S_ISFIFO(mode) || S_ISSOCK(mode)) {
64857 if (maybe_link() == 0) {
64858- sys_mknod(collected, mode, rdev);
64859- sys_chown(collected, uid, gid);
64860- sys_chmod(collected, mode);
64861- do_utime(collected, mtime);
64862+ sys_mknod((char __force_user *)collected, mode, rdev);
64863+ sys_chown((char __force_user *)collected, uid, gid);
64864+ sys_chmod((char __force_user *)collected, mode);
64865+ do_utime((char __force_user *)collected, mtime);
64866 }
64867 }
64868 return 0;
64869@@ -336,15 +336,15 @@ static int __init do_name(void)
64870 static int __init do_copy(void)
64871 {
64872 if (count >= body_len) {
64873- sys_write(wfd, victim, body_len);
64874+ sys_write(wfd, (char __force_user *)victim, body_len);
64875 sys_close(wfd);
64876- do_utime(vcollected, mtime);
64877+ do_utime((char __force_user *)vcollected, mtime);
64878 kfree(vcollected);
64879 eat(body_len);
64880 state = SkipIt;
64881 return 0;
64882 } else {
64883- sys_write(wfd, victim, count);
64884+ sys_write(wfd, (char __force_user *)victim, count);
64885 body_len -= count;
64886 eat(count);
64887 return 1;
64888@@ -355,9 +355,9 @@ static int __init do_symlink(void)
64889 {
64890 collected[N_ALIGN(name_len) + body_len] = '\0';
64891 clean_path(collected, 0);
64892- sys_symlink(collected + N_ALIGN(name_len), collected);
64893- sys_lchown(collected, uid, gid);
64894- do_utime(collected, mtime);
64895+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
64896+ sys_lchown((char __force_user *)collected, uid, gid);
64897+ do_utime((char __force_user *)collected, mtime);
64898 state = SkipIt;
64899 next_state = Reset;
64900 return 0;
64901diff --git a/init/main.c b/init/main.c
64902index b08c5f7..bf65a52 100644
64903--- a/init/main.c
64904+++ b/init/main.c
64905@@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
64906 extern void tc_init(void);
64907 #endif
64908
64909+extern void grsecurity_init(void);
64910+
64911 /*
64912 * Debug helper: via this flag we know that we are in 'early bootup code'
64913 * where only the boot processor is running with IRQ disabled. This means
64914@@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
64915
64916 __setup("reset_devices", set_reset_devices);
64917
64918+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
64919+extern char pax_enter_kernel_user[];
64920+extern char pax_exit_kernel_user[];
64921+extern pgdval_t clone_pgd_mask;
64922+#endif
64923+
64924+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
64925+static int __init setup_pax_nouderef(char *str)
64926+{
64927+#ifdef CONFIG_X86_32
64928+ unsigned int cpu;
64929+ struct desc_struct *gdt;
64930+
64931+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
64932+ gdt = get_cpu_gdt_table(cpu);
64933+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
64934+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
64935+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
64936+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
64937+ }
64938+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
64939+#else
64940+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
64941+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
64942+ clone_pgd_mask = ~(pgdval_t)0UL;
64943+#endif
64944+
64945+ return 0;
64946+}
64947+early_param("pax_nouderef", setup_pax_nouderef);
64948+#endif
64949+
64950+#ifdef CONFIG_PAX_SOFTMODE
64951+int pax_softmode;
64952+
64953+static int __init setup_pax_softmode(char *str)
64954+{
64955+ get_option(&str, &pax_softmode);
64956+ return 1;
64957+}
64958+__setup("pax_softmode=", setup_pax_softmode);
64959+#endif
64960+
64961 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
64962 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
64963 static const char *panic_later, *panic_param;
64964@@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
64965 {
64966 int count = preempt_count();
64967 int ret;
64968+ const char *msg1 = "", *msg2 = "";
64969
64970 if (initcall_debug)
64971 ret = do_one_initcall_debug(fn);
64972@@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
64973 sprintf(msgbuf, "error code %d ", ret);
64974
64975 if (preempt_count() != count) {
64976- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
64977+ msg1 = " preemption imbalance";
64978 preempt_count() = count;
64979 }
64980 if (irqs_disabled()) {
64981- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
64982+ msg2 = " disabled interrupts";
64983 local_irq_enable();
64984 }
64985- if (msgbuf[0]) {
64986- printk("initcall %pF returned with %s\n", fn, msgbuf);
64987+ if (msgbuf[0] || *msg1 || *msg2) {
64988+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
64989 }
64990
64991 return ret;
64992@@ -747,8 +793,14 @@ static void __init do_initcall_level(int level)
64993 level, level,
64994 repair_env_string);
64995
64996- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
64997+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
64998 do_one_initcall(*fn);
64999+
65000+#ifdef CONFIG_PAX_LATENT_ENTROPY
65001+ transfer_latent_entropy();
65002+#endif
65003+
65004+ }
65005 }
65006
65007 static void __init do_initcalls(void)
65008@@ -782,8 +834,14 @@ static void __init do_pre_smp_initcalls(void)
65009 {
65010 initcall_t *fn;
65011
65012- for (fn = __initcall_start; fn < __initcall0_start; fn++)
65013+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
65014 do_one_initcall(*fn);
65015+
65016+#ifdef CONFIG_PAX_LATENT_ENTROPY
65017+ transfer_latent_entropy();
65018+#endif
65019+
65020+ }
65021 }
65022
65023 static void run_init_process(const char *init_filename)
65024@@ -865,7 +923,7 @@ static int __init kernel_init(void * unused)
65025 do_basic_setup();
65026
65027 /* Open the /dev/console on the rootfs, this should never fail */
65028- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65029+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65030 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65031
65032 (void) sys_dup(0);
65033@@ -878,11 +936,13 @@ static int __init kernel_init(void * unused)
65034 if (!ramdisk_execute_command)
65035 ramdisk_execute_command = "/init";
65036
65037- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65038+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65039 ramdisk_execute_command = NULL;
65040 prepare_namespace();
65041 }
65042
65043+ grsecurity_init();
65044+
65045 /*
65046 * Ok, we have completed the initial bootup, and
65047 * we're essentially up and running. Get rid of the
65048diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65049index 28bd64d..c66b72a 100644
65050--- a/ipc/mqueue.c
65051+++ b/ipc/mqueue.c
65052@@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65053 mq_bytes = (mq_msg_tblsz +
65054 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
65055
65056+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65057 spin_lock(&mq_lock);
65058 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65059 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65060diff --git a/ipc/msg.c b/ipc/msg.c
65061index 7385de2..a8180e08 100644
65062--- a/ipc/msg.c
65063+++ b/ipc/msg.c
65064@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65065 return security_msg_queue_associate(msq, msgflg);
65066 }
65067
65068+static struct ipc_ops msg_ops = {
65069+ .getnew = newque,
65070+ .associate = msg_security,
65071+ .more_checks = NULL
65072+};
65073+
65074 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65075 {
65076 struct ipc_namespace *ns;
65077- struct ipc_ops msg_ops;
65078 struct ipc_params msg_params;
65079
65080 ns = current->nsproxy->ipc_ns;
65081
65082- msg_ops.getnew = newque;
65083- msg_ops.associate = msg_security;
65084- msg_ops.more_checks = NULL;
65085-
65086 msg_params.key = key;
65087 msg_params.flg = msgflg;
65088
65089diff --git a/ipc/sem.c b/ipc/sem.c
65090index 5215a81..cfc0cac 100644
65091--- a/ipc/sem.c
65092+++ b/ipc/sem.c
65093@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65094 return 0;
65095 }
65096
65097+static struct ipc_ops sem_ops = {
65098+ .getnew = newary,
65099+ .associate = sem_security,
65100+ .more_checks = sem_more_checks
65101+};
65102+
65103 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65104 {
65105 struct ipc_namespace *ns;
65106- struct ipc_ops sem_ops;
65107 struct ipc_params sem_params;
65108
65109 ns = current->nsproxy->ipc_ns;
65110@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65111 if (nsems < 0 || nsems > ns->sc_semmsl)
65112 return -EINVAL;
65113
65114- sem_ops.getnew = newary;
65115- sem_ops.associate = sem_security;
65116- sem_ops.more_checks = sem_more_checks;
65117-
65118 sem_params.key = key;
65119 sem_params.flg = semflg;
65120 sem_params.u.nsems = nsems;
65121diff --git a/ipc/shm.c b/ipc/shm.c
65122index 406c5b2..bc66d67 100644
65123--- a/ipc/shm.c
65124+++ b/ipc/shm.c
65125@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65126 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65127 #endif
65128
65129+#ifdef CONFIG_GRKERNSEC
65130+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65131+ const time_t shm_createtime, const uid_t cuid,
65132+ const int shmid);
65133+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65134+ const time_t shm_createtime);
65135+#endif
65136+
65137 void shm_init_ns(struct ipc_namespace *ns)
65138 {
65139 ns->shm_ctlmax = SHMMAX;
65140@@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65141 shp->shm_lprid = 0;
65142 shp->shm_atim = shp->shm_dtim = 0;
65143 shp->shm_ctim = get_seconds();
65144+#ifdef CONFIG_GRKERNSEC
65145+ {
65146+ struct timespec timeval;
65147+ do_posix_clock_monotonic_gettime(&timeval);
65148+
65149+ shp->shm_createtime = timeval.tv_sec;
65150+ }
65151+#endif
65152 shp->shm_segsz = size;
65153 shp->shm_nattch = 0;
65154 shp->shm_file = file;
65155@@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65156 return 0;
65157 }
65158
65159+static struct ipc_ops shm_ops = {
65160+ .getnew = newseg,
65161+ .associate = shm_security,
65162+ .more_checks = shm_more_checks
65163+};
65164+
65165 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65166 {
65167 struct ipc_namespace *ns;
65168- struct ipc_ops shm_ops;
65169 struct ipc_params shm_params;
65170
65171 ns = current->nsproxy->ipc_ns;
65172
65173- shm_ops.getnew = newseg;
65174- shm_ops.associate = shm_security;
65175- shm_ops.more_checks = shm_more_checks;
65176-
65177 shm_params.key = key;
65178 shm_params.flg = shmflg;
65179 shm_params.u.size = size;
65180@@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65181 f_mode = FMODE_READ | FMODE_WRITE;
65182 }
65183 if (shmflg & SHM_EXEC) {
65184+
65185+#ifdef CONFIG_PAX_MPROTECT
65186+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
65187+ goto out;
65188+#endif
65189+
65190 prot |= PROT_EXEC;
65191 acc_mode |= S_IXUGO;
65192 }
65193@@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65194 if (err)
65195 goto out_unlock;
65196
65197+#ifdef CONFIG_GRKERNSEC
65198+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65199+ shp->shm_perm.cuid, shmid) ||
65200+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65201+ err = -EACCES;
65202+ goto out_unlock;
65203+ }
65204+#endif
65205+
65206 path = shp->shm_file->f_path;
65207 path_get(&path);
65208 shp->shm_nattch++;
65209+#ifdef CONFIG_GRKERNSEC
65210+ shp->shm_lapid = current->pid;
65211+#endif
65212 size = i_size_read(path.dentry->d_inode);
65213 shm_unlock(shp);
65214
65215diff --git a/kernel/acct.c b/kernel/acct.c
65216index 02e6167..54824f7 100644
65217--- a/kernel/acct.c
65218+++ b/kernel/acct.c
65219@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65220 */
65221 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65222 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65223- file->f_op->write(file, (char *)&ac,
65224+ file->f_op->write(file, (char __force_user *)&ac,
65225 sizeof(acct_t), &file->f_pos);
65226 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65227 set_fs(fs);
65228diff --git a/kernel/audit.c b/kernel/audit.c
65229index 1c7f2c6..9ba5359 100644
65230--- a/kernel/audit.c
65231+++ b/kernel/audit.c
65232@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65233 3) suppressed due to audit_rate_limit
65234 4) suppressed due to audit_backlog_limit
65235 */
65236-static atomic_t audit_lost = ATOMIC_INIT(0);
65237+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65238
65239 /* The netlink socket. */
65240 static struct sock *audit_sock;
65241@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65242 unsigned long now;
65243 int print;
65244
65245- atomic_inc(&audit_lost);
65246+ atomic_inc_unchecked(&audit_lost);
65247
65248 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65249
65250@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65251 printk(KERN_WARNING
65252 "audit: audit_lost=%d audit_rate_limit=%d "
65253 "audit_backlog_limit=%d\n",
65254- atomic_read(&audit_lost),
65255+ atomic_read_unchecked(&audit_lost),
65256 audit_rate_limit,
65257 audit_backlog_limit);
65258 audit_panic(message);
65259@@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65260 status_set.pid = audit_pid;
65261 status_set.rate_limit = audit_rate_limit;
65262 status_set.backlog_limit = audit_backlog_limit;
65263- status_set.lost = atomic_read(&audit_lost);
65264+ status_set.lost = atomic_read_unchecked(&audit_lost);
65265 status_set.backlog = skb_queue_len(&audit_skb_queue);
65266 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65267 &status_set, sizeof(status_set));
65268diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65269index af1de0f..06dfe57 100644
65270--- a/kernel/auditsc.c
65271+++ b/kernel/auditsc.c
65272@@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65273 }
65274
65275 /* global counter which is incremented every time something logs in */
65276-static atomic_t session_id = ATOMIC_INIT(0);
65277+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65278
65279 /**
65280 * audit_set_loginuid - set current task's audit_context loginuid
65281@@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
65282 return -EPERM;
65283 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65284
65285- sessionid = atomic_inc_return(&session_id);
65286+ sessionid = atomic_inc_return_unchecked(&session_id);
65287 if (context && context->in_syscall) {
65288 struct audit_buffer *ab;
65289
65290diff --git a/kernel/capability.c b/kernel/capability.c
65291index 3f1adb6..c564db0 100644
65292--- a/kernel/capability.c
65293+++ b/kernel/capability.c
65294@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65295 * before modification is attempted and the application
65296 * fails.
65297 */
65298+ if (tocopy > ARRAY_SIZE(kdata))
65299+ return -EFAULT;
65300+
65301 if (copy_to_user(dataptr, kdata, tocopy
65302 * sizeof(struct __user_cap_data_struct))) {
65303 return -EFAULT;
65304@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65305 int ret;
65306
65307 rcu_read_lock();
65308- ret = security_capable(__task_cred(t), ns, cap);
65309+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65310+ gr_task_is_capable(t, __task_cred(t), cap);
65311 rcu_read_unlock();
65312
65313- return (ret == 0);
65314+ return ret;
65315 }
65316
65317 /**
65318@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65319 int ret;
65320
65321 rcu_read_lock();
65322- ret = security_capable_noaudit(__task_cred(t), ns, cap);
65323+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65324 rcu_read_unlock();
65325
65326- return (ret == 0);
65327+ return ret;
65328 }
65329
65330 /**
65331@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65332 BUG();
65333 }
65334
65335- if (security_capable(current_cred(), ns, cap) == 0) {
65336+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65337 current->flags |= PF_SUPERPRIV;
65338 return true;
65339 }
65340@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65341 }
65342 EXPORT_SYMBOL(ns_capable);
65343
65344+bool ns_capable_nolog(struct user_namespace *ns, int cap)
65345+{
65346+ if (unlikely(!cap_valid(cap))) {
65347+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65348+ BUG();
65349+ }
65350+
65351+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65352+ current->flags |= PF_SUPERPRIV;
65353+ return true;
65354+ }
65355+ return false;
65356+}
65357+EXPORT_SYMBOL(ns_capable_nolog);
65358+
65359 /**
65360 * capable - Determine if the current task has a superior capability in effect
65361 * @cap: The capability to be tested for
65362@@ -408,6 +427,12 @@ bool capable(int cap)
65363 }
65364 EXPORT_SYMBOL(capable);
65365
65366+bool capable_nolog(int cap)
65367+{
65368+ return ns_capable_nolog(&init_user_ns, cap);
65369+}
65370+EXPORT_SYMBOL(capable_nolog);
65371+
65372 /**
65373 * nsown_capable - Check superior capability to one's own user_ns
65374 * @cap: The capability in question
65375diff --git a/kernel/compat.c b/kernel/compat.c
65376index d2c67aa..a629b2e 100644
65377--- a/kernel/compat.c
65378+++ b/kernel/compat.c
65379@@ -13,6 +13,7 @@
65380
65381 #include <linux/linkage.h>
65382 #include <linux/compat.h>
65383+#include <linux/module.h>
65384 #include <linux/errno.h>
65385 #include <linux/time.h>
65386 #include <linux/signal.h>
65387@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65388 mm_segment_t oldfs;
65389 long ret;
65390
65391- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65392+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65393 oldfs = get_fs();
65394 set_fs(KERNEL_DS);
65395 ret = hrtimer_nanosleep_restart(restart);
65396@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65397 oldfs = get_fs();
65398 set_fs(KERNEL_DS);
65399 ret = hrtimer_nanosleep(&tu,
65400- rmtp ? (struct timespec __user *)&rmt : NULL,
65401+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
65402 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65403 set_fs(oldfs);
65404
65405@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65406 mm_segment_t old_fs = get_fs();
65407
65408 set_fs(KERNEL_DS);
65409- ret = sys_sigpending((old_sigset_t __user *) &s);
65410+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
65411 set_fs(old_fs);
65412 if (ret == 0)
65413 ret = put_user(s, set);
65414@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65415 mm_segment_t old_fs = get_fs();
65416
65417 set_fs(KERNEL_DS);
65418- ret = sys_old_getrlimit(resource, &r);
65419+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65420 set_fs(old_fs);
65421
65422 if (!ret) {
65423@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65424 mm_segment_t old_fs = get_fs();
65425
65426 set_fs(KERNEL_DS);
65427- ret = sys_getrusage(who, (struct rusage __user *) &r);
65428+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65429 set_fs(old_fs);
65430
65431 if (ret)
65432@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65433 set_fs (KERNEL_DS);
65434 ret = sys_wait4(pid,
65435 (stat_addr ?
65436- (unsigned int __user *) &status : NULL),
65437- options, (struct rusage __user *) &r);
65438+ (unsigned int __force_user *) &status : NULL),
65439+ options, (struct rusage __force_user *) &r);
65440 set_fs (old_fs);
65441
65442 if (ret > 0) {
65443@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65444 memset(&info, 0, sizeof(info));
65445
65446 set_fs(KERNEL_DS);
65447- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65448- uru ? (struct rusage __user *)&ru : NULL);
65449+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65450+ uru ? (struct rusage __force_user *)&ru : NULL);
65451 set_fs(old_fs);
65452
65453 if ((ret < 0) || (info.si_signo == 0))
65454@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65455 oldfs = get_fs();
65456 set_fs(KERNEL_DS);
65457 err = sys_timer_settime(timer_id, flags,
65458- (struct itimerspec __user *) &newts,
65459- (struct itimerspec __user *) &oldts);
65460+ (struct itimerspec __force_user *) &newts,
65461+ (struct itimerspec __force_user *) &oldts);
65462 set_fs(oldfs);
65463 if (!err && old && put_compat_itimerspec(old, &oldts))
65464 return -EFAULT;
65465@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65466 oldfs = get_fs();
65467 set_fs(KERNEL_DS);
65468 err = sys_timer_gettime(timer_id,
65469- (struct itimerspec __user *) &ts);
65470+ (struct itimerspec __force_user *) &ts);
65471 set_fs(oldfs);
65472 if (!err && put_compat_itimerspec(setting, &ts))
65473 return -EFAULT;
65474@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65475 oldfs = get_fs();
65476 set_fs(KERNEL_DS);
65477 err = sys_clock_settime(which_clock,
65478- (struct timespec __user *) &ts);
65479+ (struct timespec __force_user *) &ts);
65480 set_fs(oldfs);
65481 return err;
65482 }
65483@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65484 oldfs = get_fs();
65485 set_fs(KERNEL_DS);
65486 err = sys_clock_gettime(which_clock,
65487- (struct timespec __user *) &ts);
65488+ (struct timespec __force_user *) &ts);
65489 set_fs(oldfs);
65490 if (!err && put_compat_timespec(&ts, tp))
65491 return -EFAULT;
65492@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65493
65494 oldfs = get_fs();
65495 set_fs(KERNEL_DS);
65496- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65497+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65498 set_fs(oldfs);
65499
65500 err = compat_put_timex(utp, &txc);
65501@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65502 oldfs = get_fs();
65503 set_fs(KERNEL_DS);
65504 err = sys_clock_getres(which_clock,
65505- (struct timespec __user *) &ts);
65506+ (struct timespec __force_user *) &ts);
65507 set_fs(oldfs);
65508 if (!err && tp && put_compat_timespec(&ts, tp))
65509 return -EFAULT;
65510@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65511 long err;
65512 mm_segment_t oldfs;
65513 struct timespec tu;
65514- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65515+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65516
65517- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65518+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65519 oldfs = get_fs();
65520 set_fs(KERNEL_DS);
65521 err = clock_nanosleep_restart(restart);
65522@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65523 oldfs = get_fs();
65524 set_fs(KERNEL_DS);
65525 err = sys_clock_nanosleep(which_clock, flags,
65526- (struct timespec __user *) &in,
65527- (struct timespec __user *) &out);
65528+ (struct timespec __force_user *) &in,
65529+ (struct timespec __force_user *) &out);
65530 set_fs(oldfs);
65531
65532 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65533diff --git a/kernel/configs.c b/kernel/configs.c
65534index 42e8fa0..9e7406b 100644
65535--- a/kernel/configs.c
65536+++ b/kernel/configs.c
65537@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65538 struct proc_dir_entry *entry;
65539
65540 /* create the current config file */
65541+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65542+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65543+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65544+ &ikconfig_file_ops);
65545+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65546+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65547+ &ikconfig_file_ops);
65548+#endif
65549+#else
65550 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65551 &ikconfig_file_ops);
65552+#endif
65553+
65554 if (!entry)
65555 return -ENOMEM;
65556
65557diff --git a/kernel/cred.c b/kernel/cred.c
65558index e70683d..27761b6 100644
65559--- a/kernel/cred.c
65560+++ b/kernel/cred.c
65561@@ -205,6 +205,15 @@ void exit_creds(struct task_struct *tsk)
65562 validate_creds(cred);
65563 put_cred(cred);
65564 }
65565+
65566+#ifdef CONFIG_GRKERNSEC_SETXID
65567+ cred = (struct cred *) tsk->delayed_cred;
65568+ if (cred) {
65569+ tsk->delayed_cred = NULL;
65570+ validate_creds(cred);
65571+ put_cred(cred);
65572+ }
65573+#endif
65574 }
65575
65576 /**
65577@@ -473,7 +482,7 @@ error_put:
65578 * Always returns 0 thus allowing this function to be tail-called at the end
65579 * of, say, sys_setgid().
65580 */
65581-int commit_creds(struct cred *new)
65582+static int __commit_creds(struct cred *new)
65583 {
65584 struct task_struct *task = current;
65585 const struct cred *old = task->real_cred;
65586@@ -492,6 +501,8 @@ int commit_creds(struct cred *new)
65587
65588 get_cred(new); /* we will require a ref for the subj creds too */
65589
65590+ gr_set_role_label(task, new->uid, new->gid);
65591+
65592 /* dumpability changes */
65593 if (old->euid != new->euid ||
65594 old->egid != new->egid ||
65595@@ -541,6 +552,101 @@ int commit_creds(struct cred *new)
65596 put_cred(old);
65597 return 0;
65598 }
65599+#ifdef CONFIG_GRKERNSEC_SETXID
65600+extern int set_user(struct cred *new);
65601+
65602+void gr_delayed_cred_worker(void)
65603+{
65604+ const struct cred *new = current->delayed_cred;
65605+ struct cred *ncred;
65606+
65607+ current->delayed_cred = NULL;
65608+
65609+ if (current_uid() && new != NULL) {
65610+ // from doing get_cred on it when queueing this
65611+ put_cred(new);
65612+ return;
65613+ } else if (new == NULL)
65614+ return;
65615+
65616+ ncred = prepare_creds();
65617+ if (!ncred)
65618+ goto die;
65619+ // uids
65620+ ncred->uid = new->uid;
65621+ ncred->euid = new->euid;
65622+ ncred->suid = new->suid;
65623+ ncred->fsuid = new->fsuid;
65624+ // gids
65625+ ncred->gid = new->gid;
65626+ ncred->egid = new->egid;
65627+ ncred->sgid = new->sgid;
65628+ ncred->fsgid = new->fsgid;
65629+ // groups
65630+ if (set_groups(ncred, new->group_info) < 0) {
65631+ abort_creds(ncred);
65632+ goto die;
65633+ }
65634+ // caps
65635+ ncred->securebits = new->securebits;
65636+ ncred->cap_inheritable = new->cap_inheritable;
65637+ ncred->cap_permitted = new->cap_permitted;
65638+ ncred->cap_effective = new->cap_effective;
65639+ ncred->cap_bset = new->cap_bset;
65640+
65641+ if (set_user(ncred)) {
65642+ abort_creds(ncred);
65643+ goto die;
65644+ }
65645+
65646+ // from doing get_cred on it when queueing this
65647+ put_cred(new);
65648+
65649+ __commit_creds(ncred);
65650+ return;
65651+die:
65652+ // from doing get_cred on it when queueing this
65653+ put_cred(new);
65654+ do_group_exit(SIGKILL);
65655+}
65656+#endif
65657+
65658+int commit_creds(struct cred *new)
65659+{
65660+#ifdef CONFIG_GRKERNSEC_SETXID
65661+ int ret;
65662+ int schedule_it = 0;
65663+ struct task_struct *t;
65664+
65665+ /* we won't get called with tasklist_lock held for writing
65666+ and interrupts disabled as the cred struct in that case is
65667+ init_cred
65668+ */
65669+ if (grsec_enable_setxid && !current_is_single_threaded() &&
65670+ !current_uid() && new->uid) {
65671+ schedule_it = 1;
65672+ }
65673+ ret = __commit_creds(new);
65674+ if (schedule_it) {
65675+ rcu_read_lock();
65676+ read_lock(&tasklist_lock);
65677+ for (t = next_thread(current); t != current;
65678+ t = next_thread(t)) {
65679+ if (t->delayed_cred == NULL) {
65680+ t->delayed_cred = get_cred(new);
65681+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
65682+ set_tsk_need_resched(t);
65683+ }
65684+ }
65685+ read_unlock(&tasklist_lock);
65686+ rcu_read_unlock();
65687+ }
65688+ return ret;
65689+#else
65690+ return __commit_creds(new);
65691+#endif
65692+}
65693+
65694 EXPORT_SYMBOL(commit_creds);
65695
65696 /**
65697diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
65698index 0557f24..1a00d9a 100644
65699--- a/kernel/debug/debug_core.c
65700+++ b/kernel/debug/debug_core.c
65701@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
65702 */
65703 static atomic_t masters_in_kgdb;
65704 static atomic_t slaves_in_kgdb;
65705-static atomic_t kgdb_break_tasklet_var;
65706+static atomic_unchecked_t kgdb_break_tasklet_var;
65707 atomic_t kgdb_setting_breakpoint;
65708
65709 struct task_struct *kgdb_usethread;
65710@@ -132,7 +132,7 @@ int kgdb_single_step;
65711 static pid_t kgdb_sstep_pid;
65712
65713 /* to keep track of the CPU which is doing the single stepping*/
65714-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65715+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65716
65717 /*
65718 * If you are debugging a problem where roundup (the collection of
65719@@ -540,7 +540,7 @@ return_normal:
65720 * kernel will only try for the value of sstep_tries before
65721 * giving up and continuing on.
65722 */
65723- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
65724+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
65725 (kgdb_info[cpu].task &&
65726 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
65727 atomic_set(&kgdb_active, -1);
65728@@ -634,8 +634,8 @@ cpu_master_loop:
65729 }
65730
65731 kgdb_restore:
65732- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
65733- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
65734+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
65735+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
65736 if (kgdb_info[sstep_cpu].task)
65737 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
65738 else
65739@@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
65740 static void kgdb_tasklet_bpt(unsigned long ing)
65741 {
65742 kgdb_breakpoint();
65743- atomic_set(&kgdb_break_tasklet_var, 0);
65744+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
65745 }
65746
65747 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
65748
65749 void kgdb_schedule_breakpoint(void)
65750 {
65751- if (atomic_read(&kgdb_break_tasklet_var) ||
65752+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
65753 atomic_read(&kgdb_active) != -1 ||
65754 atomic_read(&kgdb_setting_breakpoint))
65755 return;
65756- atomic_inc(&kgdb_break_tasklet_var);
65757+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
65758 tasklet_schedule(&kgdb_tasklet_breakpoint);
65759 }
65760 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
65761diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
65762index 67b847d..93834dd 100644
65763--- a/kernel/debug/kdb/kdb_main.c
65764+++ b/kernel/debug/kdb/kdb_main.c
65765@@ -1983,7 +1983,7 @@ static int kdb_lsmod(int argc, const char **argv)
65766 list_for_each_entry(mod, kdb_modules, list) {
65767
65768 kdb_printf("%-20s%8u 0x%p ", mod->name,
65769- mod->core_size, (void *)mod);
65770+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
65771 #ifdef CONFIG_MODULE_UNLOAD
65772 kdb_printf("%4ld ", module_refcount(mod));
65773 #endif
65774@@ -1993,7 +1993,7 @@ static int kdb_lsmod(int argc, const char **argv)
65775 kdb_printf(" (Loading)");
65776 else
65777 kdb_printf(" (Live)");
65778- kdb_printf(" 0x%p", mod->module_core);
65779+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
65780
65781 #ifdef CONFIG_MODULE_UNLOAD
65782 {
65783diff --git a/kernel/events/core.c b/kernel/events/core.c
65784index fd126f8..70b755b 100644
65785--- a/kernel/events/core.c
65786+++ b/kernel/events/core.c
65787@@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
65788 return 0;
65789 }
65790
65791-static atomic64_t perf_event_id;
65792+static atomic64_unchecked_t perf_event_id;
65793
65794 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
65795 enum event_type_t event_type);
65796@@ -2659,7 +2659,7 @@ static void __perf_event_read(void *info)
65797
65798 static inline u64 perf_event_count(struct perf_event *event)
65799 {
65800- return local64_read(&event->count) + atomic64_read(&event->child_count);
65801+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
65802 }
65803
65804 static u64 perf_event_read(struct perf_event *event)
65805@@ -2983,9 +2983,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
65806 mutex_lock(&event->child_mutex);
65807 total += perf_event_read(event);
65808 *enabled += event->total_time_enabled +
65809- atomic64_read(&event->child_total_time_enabled);
65810+ atomic64_read_unchecked(&event->child_total_time_enabled);
65811 *running += event->total_time_running +
65812- atomic64_read(&event->child_total_time_running);
65813+ atomic64_read_unchecked(&event->child_total_time_running);
65814
65815 list_for_each_entry(child, &event->child_list, child_list) {
65816 total += perf_event_read(child);
65817@@ -3393,10 +3393,10 @@ void perf_event_update_userpage(struct perf_event *event)
65818 userpg->offset -= local64_read(&event->hw.prev_count);
65819
65820 userpg->time_enabled = enabled +
65821- atomic64_read(&event->child_total_time_enabled);
65822+ atomic64_read_unchecked(&event->child_total_time_enabled);
65823
65824 userpg->time_running = running +
65825- atomic64_read(&event->child_total_time_running);
65826+ atomic64_read_unchecked(&event->child_total_time_running);
65827
65828 arch_perf_update_userpage(userpg, now);
65829
65830@@ -3829,11 +3829,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65831 values[n++] = perf_event_count(event);
65832 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65833 values[n++] = enabled +
65834- atomic64_read(&event->child_total_time_enabled);
65835+ atomic64_read_unchecked(&event->child_total_time_enabled);
65836 }
65837 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65838 values[n++] = running +
65839- atomic64_read(&event->child_total_time_running);
65840+ atomic64_read_unchecked(&event->child_total_time_running);
65841 }
65842 if (read_format & PERF_FORMAT_ID)
65843 values[n++] = primary_event_id(event);
65844@@ -4511,12 +4511,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
65845 * need to add enough zero bytes after the string to handle
65846 * the 64bit alignment we do later.
65847 */
65848- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
65849+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
65850 if (!buf) {
65851 name = strncpy(tmp, "//enomem", sizeof(tmp));
65852 goto got_name;
65853 }
65854- name = d_path(&file->f_path, buf, PATH_MAX);
65855+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
65856 if (IS_ERR(name)) {
65857 name = strncpy(tmp, "//toolong", sizeof(tmp));
65858 goto got_name;
65859@@ -5929,7 +5929,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
65860 event->parent = parent_event;
65861
65862 event->ns = get_pid_ns(current->nsproxy->pid_ns);
65863- event->id = atomic64_inc_return(&perf_event_id);
65864+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
65865
65866 event->state = PERF_EVENT_STATE_INACTIVE;
65867
65868@@ -6491,10 +6491,10 @@ static void sync_child_event(struct perf_event *child_event,
65869 /*
65870 * Add back the child's count to the parent's count:
65871 */
65872- atomic64_add(child_val, &parent_event->child_count);
65873- atomic64_add(child_event->total_time_enabled,
65874+ atomic64_add_unchecked(child_val, &parent_event->child_count);
65875+ atomic64_add_unchecked(child_event->total_time_enabled,
65876 &parent_event->child_total_time_enabled);
65877- atomic64_add(child_event->total_time_running,
65878+ atomic64_add_unchecked(child_event->total_time_running,
65879 &parent_event->child_total_time_running);
65880
65881 /*
65882diff --git a/kernel/exit.c b/kernel/exit.c
65883index 9d81012..d7911f1 100644
65884--- a/kernel/exit.c
65885+++ b/kernel/exit.c
65886@@ -59,6 +59,10 @@
65887 #include <asm/pgtable.h>
65888 #include <asm/mmu_context.h>
65889
65890+#ifdef CONFIG_GRKERNSEC
65891+extern rwlock_t grsec_exec_file_lock;
65892+#endif
65893+
65894 static void exit_mm(struct task_struct * tsk);
65895
65896 static void __unhash_process(struct task_struct *p, bool group_dead)
65897@@ -170,6 +174,10 @@ void release_task(struct task_struct * p)
65898 struct task_struct *leader;
65899 int zap_leader;
65900 repeat:
65901+#ifdef CONFIG_NET
65902+ gr_del_task_from_ip_table(p);
65903+#endif
65904+
65905 /* don't need to get the RCU readlock here - the process is dead and
65906 * can't be modifying its own credentials. But shut RCU-lockdep up */
65907 rcu_read_lock();
65908@@ -382,7 +390,7 @@ int allow_signal(int sig)
65909 * know it'll be handled, so that they don't get converted to
65910 * SIGKILL or just silently dropped.
65911 */
65912- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
65913+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
65914 recalc_sigpending();
65915 spin_unlock_irq(&current->sighand->siglock);
65916 return 0;
65917@@ -418,6 +426,17 @@ void daemonize(const char *name, ...)
65918 vsnprintf(current->comm, sizeof(current->comm), name, args);
65919 va_end(args);
65920
65921+#ifdef CONFIG_GRKERNSEC
65922+ write_lock(&grsec_exec_file_lock);
65923+ if (current->exec_file) {
65924+ fput(current->exec_file);
65925+ current->exec_file = NULL;
65926+ }
65927+ write_unlock(&grsec_exec_file_lock);
65928+#endif
65929+
65930+ gr_set_kernel_label(current);
65931+
65932 /*
65933 * If we were started as result of loading a module, close all of the
65934 * user space pages. We don't need them, and if we didn't close them
65935@@ -901,6 +920,8 @@ void do_exit(long code)
65936 struct task_struct *tsk = current;
65937 int group_dead;
65938
65939+ set_fs(USER_DS);
65940+
65941 profile_task_exit(tsk);
65942
65943 WARN_ON(blk_needs_flush_plug(tsk));
65944@@ -917,7 +938,6 @@ void do_exit(long code)
65945 * mm_release()->clear_child_tid() from writing to a user-controlled
65946 * kernel address.
65947 */
65948- set_fs(USER_DS);
65949
65950 ptrace_event(PTRACE_EVENT_EXIT, code);
65951
65952@@ -978,6 +998,9 @@ void do_exit(long code)
65953 tsk->exit_code = code;
65954 taskstats_exit(tsk, group_dead);
65955
65956+ gr_acl_handle_psacct(tsk, code);
65957+ gr_acl_handle_exit();
65958+
65959 exit_mm(tsk);
65960
65961 if (group_dead)
65962@@ -1094,7 +1117,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
65963 * Take down every thread in the group. This is called by fatal signals
65964 * as well as by sys_exit_group (below).
65965 */
65966-void
65967+__noreturn void
65968 do_group_exit(int exit_code)
65969 {
65970 struct signal_struct *sig = current->signal;
65971diff --git a/kernel/fork.c b/kernel/fork.c
65972index 8163333..aee97f3 100644
65973--- a/kernel/fork.c
65974+++ b/kernel/fork.c
65975@@ -274,19 +274,24 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
65976 }
65977
65978 err = arch_dup_task_struct(tsk, orig);
65979- if (err)
65980- goto out;
65981
65982+ /*
65983+ * We defer looking at err, because we will need this setup
65984+ * for the clean up path to work correctly.
65985+ */
65986 tsk->stack = ti;
65987-
65988 setup_thread_stack(tsk, orig);
65989+
65990+ if (err)
65991+ goto out;
65992+
65993 clear_user_return_notifier(tsk);
65994 clear_tsk_need_resched(tsk);
65995 stackend = end_of_stack(tsk);
65996 *stackend = STACK_END_MAGIC; /* for overflow detection */
65997
65998 #ifdef CONFIG_CC_STACKPROTECTOR
65999- tsk->stack_canary = get_random_int();
66000+ tsk->stack_canary = pax_get_random_long();
66001 #endif
66002
66003 /*
66004@@ -310,13 +315,78 @@ out:
66005 }
66006
66007 #ifdef CONFIG_MMU
66008+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
66009+{
66010+ struct vm_area_struct *tmp;
66011+ unsigned long charge;
66012+ struct mempolicy *pol;
66013+ struct file *file;
66014+
66015+ charge = 0;
66016+ if (mpnt->vm_flags & VM_ACCOUNT) {
66017+ unsigned long len;
66018+ len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66019+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66020+ goto fail_nomem;
66021+ charge = len;
66022+ }
66023+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66024+ if (!tmp)
66025+ goto fail_nomem;
66026+ *tmp = *mpnt;
66027+ tmp->vm_mm = mm;
66028+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
66029+ pol = mpol_dup(vma_policy(mpnt));
66030+ if (IS_ERR(pol))
66031+ goto fail_nomem_policy;
66032+ vma_set_policy(tmp, pol);
66033+ if (anon_vma_fork(tmp, mpnt))
66034+ goto fail_nomem_anon_vma_fork;
66035+ tmp->vm_flags &= ~VM_LOCKED;
66036+ tmp->vm_next = tmp->vm_prev = NULL;
66037+ tmp->vm_mirror = NULL;
66038+ file = tmp->vm_file;
66039+ if (file) {
66040+ struct inode *inode = file->f_path.dentry->d_inode;
66041+ struct address_space *mapping = file->f_mapping;
66042+
66043+ get_file(file);
66044+ if (tmp->vm_flags & VM_DENYWRITE)
66045+ atomic_dec(&inode->i_writecount);
66046+ mutex_lock(&mapping->i_mmap_mutex);
66047+ if (tmp->vm_flags & VM_SHARED)
66048+ mapping->i_mmap_writable++;
66049+ flush_dcache_mmap_lock(mapping);
66050+ /* insert tmp into the share list, just after mpnt */
66051+ vma_prio_tree_add(tmp, mpnt);
66052+ flush_dcache_mmap_unlock(mapping);
66053+ mutex_unlock(&mapping->i_mmap_mutex);
66054+ }
66055+
66056+ /*
66057+ * Clear hugetlb-related page reserves for children. This only
66058+ * affects MAP_PRIVATE mappings. Faults generated by the child
66059+ * are not guaranteed to succeed, even if read-only
66060+ */
66061+ if (is_vm_hugetlb_page(tmp))
66062+ reset_vma_resv_huge_pages(tmp);
66063+
66064+ return tmp;
66065+
66066+fail_nomem_anon_vma_fork:
66067+ mpol_put(pol);
66068+fail_nomem_policy:
66069+ kmem_cache_free(vm_area_cachep, tmp);
66070+fail_nomem:
66071+ vm_unacct_memory(charge);
66072+ return NULL;
66073+}
66074+
66075 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66076 {
66077 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66078 struct rb_node **rb_link, *rb_parent;
66079 int retval;
66080- unsigned long charge;
66081- struct mempolicy *pol;
66082
66083 down_write(&oldmm->mmap_sem);
66084 flush_cache_dup_mm(oldmm);
66085@@ -328,8 +398,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66086 mm->locked_vm = 0;
66087 mm->mmap = NULL;
66088 mm->mmap_cache = NULL;
66089- mm->free_area_cache = oldmm->mmap_base;
66090- mm->cached_hole_size = ~0UL;
66091+ mm->free_area_cache = oldmm->free_area_cache;
66092+ mm->cached_hole_size = oldmm->cached_hole_size;
66093 mm->map_count = 0;
66094 cpumask_clear(mm_cpumask(mm));
66095 mm->mm_rb = RB_ROOT;
66096@@ -345,8 +415,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66097
66098 prev = NULL;
66099 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66100- struct file *file;
66101-
66102 if (mpnt->vm_flags & VM_DONTCOPY) {
66103 long pages = vma_pages(mpnt);
66104 mm->total_vm -= pages;
66105@@ -354,54 +422,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66106 -pages);
66107 continue;
66108 }
66109- charge = 0;
66110- if (mpnt->vm_flags & VM_ACCOUNT) {
66111- unsigned long len;
66112- len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66113- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66114- goto fail_nomem;
66115- charge = len;
66116+ tmp = dup_vma(mm, oldmm, mpnt);
66117+ if (!tmp) {
66118+ retval = -ENOMEM;
66119+ goto out;
66120 }
66121- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66122- if (!tmp)
66123- goto fail_nomem;
66124- *tmp = *mpnt;
66125- INIT_LIST_HEAD(&tmp->anon_vma_chain);
66126- pol = mpol_dup(vma_policy(mpnt));
66127- retval = PTR_ERR(pol);
66128- if (IS_ERR(pol))
66129- goto fail_nomem_policy;
66130- vma_set_policy(tmp, pol);
66131- tmp->vm_mm = mm;
66132- if (anon_vma_fork(tmp, mpnt))
66133- goto fail_nomem_anon_vma_fork;
66134- tmp->vm_flags &= ~VM_LOCKED;
66135- tmp->vm_next = tmp->vm_prev = NULL;
66136- file = tmp->vm_file;
66137- if (file) {
66138- struct inode *inode = file->f_path.dentry->d_inode;
66139- struct address_space *mapping = file->f_mapping;
66140-
66141- get_file(file);
66142- if (tmp->vm_flags & VM_DENYWRITE)
66143- atomic_dec(&inode->i_writecount);
66144- mutex_lock(&mapping->i_mmap_mutex);
66145- if (tmp->vm_flags & VM_SHARED)
66146- mapping->i_mmap_writable++;
66147- flush_dcache_mmap_lock(mapping);
66148- /* insert tmp into the share list, just after mpnt */
66149- vma_prio_tree_add(tmp, mpnt);
66150- flush_dcache_mmap_unlock(mapping);
66151- mutex_unlock(&mapping->i_mmap_mutex);
66152- }
66153-
66154- /*
66155- * Clear hugetlb-related page reserves for children. This only
66156- * affects MAP_PRIVATE mappings. Faults generated by the child
66157- * are not guaranteed to succeed, even if read-only
66158- */
66159- if (is_vm_hugetlb_page(tmp))
66160- reset_vma_resv_huge_pages(tmp);
66161
66162 /*
66163 * Link in the new vma and copy the page table entries.
66164@@ -424,6 +449,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66165 if (retval)
66166 goto out;
66167 }
66168+
66169+#ifdef CONFIG_PAX_SEGMEXEC
66170+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66171+ struct vm_area_struct *mpnt_m;
66172+
66173+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66174+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66175+
66176+ if (!mpnt->vm_mirror)
66177+ continue;
66178+
66179+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66180+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66181+ mpnt->vm_mirror = mpnt_m;
66182+ } else {
66183+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66184+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66185+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66186+ mpnt->vm_mirror->vm_mirror = mpnt;
66187+ }
66188+ }
66189+ BUG_ON(mpnt_m);
66190+ }
66191+#endif
66192+
66193 /* a new mm has just been created */
66194 arch_dup_mmap(oldmm, mm);
66195 retval = 0;
66196@@ -432,14 +482,6 @@ out:
66197 flush_tlb_mm(oldmm);
66198 up_write(&oldmm->mmap_sem);
66199 return retval;
66200-fail_nomem_anon_vma_fork:
66201- mpol_put(pol);
66202-fail_nomem_policy:
66203- kmem_cache_free(vm_area_cachep, tmp);
66204-fail_nomem:
66205- retval = -ENOMEM;
66206- vm_unacct_memory(charge);
66207- goto out;
66208 }
66209
66210 static inline int mm_alloc_pgd(struct mm_struct *mm)
66211@@ -676,8 +718,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66212 return ERR_PTR(err);
66213
66214 mm = get_task_mm(task);
66215- if (mm && mm != current->mm &&
66216- !ptrace_may_access(task, mode)) {
66217+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66218+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66219 mmput(mm);
66220 mm = ERR_PTR(-EACCES);
66221 }
66222@@ -899,13 +941,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66223 spin_unlock(&fs->lock);
66224 return -EAGAIN;
66225 }
66226- fs->users++;
66227+ atomic_inc(&fs->users);
66228 spin_unlock(&fs->lock);
66229 return 0;
66230 }
66231 tsk->fs = copy_fs_struct(fs);
66232 if (!tsk->fs)
66233 return -ENOMEM;
66234+ gr_set_chroot_entries(tsk, &tsk->fs->root);
66235 return 0;
66236 }
66237
66238@@ -1172,6 +1215,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66239 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66240 #endif
66241 retval = -EAGAIN;
66242+
66243+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66244+
66245 if (atomic_read(&p->real_cred->user->processes) >=
66246 task_rlimit(p, RLIMIT_NPROC)) {
66247 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66248@@ -1392,6 +1438,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66249 /* Need tasklist lock for parent etc handling! */
66250 write_lock_irq(&tasklist_lock);
66251
66252+ /* synchronizes with gr_set_acls() */
66253+ gr_copy_label(p);
66254+
66255 /* CLONE_PARENT re-uses the old parent */
66256 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
66257 p->real_parent = current->real_parent;
66258@@ -1502,6 +1551,8 @@ bad_fork_cleanup_count:
66259 bad_fork_free:
66260 free_task(p);
66261 fork_out:
66262+ gr_log_forkfail(retval);
66263+
66264 return ERR_PTR(retval);
66265 }
66266
66267@@ -1602,6 +1653,8 @@ long do_fork(unsigned long clone_flags,
66268 if (clone_flags & CLONE_PARENT_SETTID)
66269 put_user(nr, parent_tidptr);
66270
66271+ gr_handle_brute_check();
66272+
66273 if (clone_flags & CLONE_VFORK) {
66274 p->vfork_done = &vfork;
66275 init_completion(&vfork);
66276@@ -1700,7 +1753,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66277 return 0;
66278
66279 /* don't need lock here; in the worst case we'll do useless copy */
66280- if (fs->users == 1)
66281+ if (atomic_read(&fs->users) == 1)
66282 return 0;
66283
66284 *new_fsp = copy_fs_struct(fs);
66285@@ -1789,7 +1842,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66286 fs = current->fs;
66287 spin_lock(&fs->lock);
66288 current->fs = new_fs;
66289- if (--fs->users)
66290+ gr_set_chroot_entries(current, &current->fs->root);
66291+ if (atomic_dec_return(&fs->users))
66292 new_fs = NULL;
66293 else
66294 new_fs = fs;
66295diff --git a/kernel/futex.c b/kernel/futex.c
66296index e2b0fb9..db818ac 100644
66297--- a/kernel/futex.c
66298+++ b/kernel/futex.c
66299@@ -54,6 +54,7 @@
66300 #include <linux/mount.h>
66301 #include <linux/pagemap.h>
66302 #include <linux/syscalls.h>
66303+#include <linux/ptrace.h>
66304 #include <linux/signal.h>
66305 #include <linux/export.h>
66306 #include <linux/magic.h>
66307@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66308 struct page *page, *page_head;
66309 int err, ro = 0;
66310
66311+#ifdef CONFIG_PAX_SEGMEXEC
66312+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66313+ return -EFAULT;
66314+#endif
66315+
66316 /*
66317 * The futex address must be "naturally" aligned.
66318 */
66319@@ -2711,6 +2717,7 @@ static int __init futex_init(void)
66320 {
66321 u32 curval;
66322 int i;
66323+ mm_segment_t oldfs;
66324
66325 /*
66326 * This will fail and we want it. Some arch implementations do
66327@@ -2722,8 +2729,11 @@ static int __init futex_init(void)
66328 * implementation, the non-functional ones will return
66329 * -ENOSYS.
66330 */
66331+ oldfs = get_fs();
66332+ set_fs(USER_DS);
66333 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66334 futex_cmpxchg_enabled = 1;
66335+ set_fs(oldfs);
66336
66337 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66338 plist_head_init(&futex_queues[i].chain);
66339diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66340index 9b22d03..6295b62 100644
66341--- a/kernel/gcov/base.c
66342+++ b/kernel/gcov/base.c
66343@@ -102,11 +102,6 @@ void gcov_enable_events(void)
66344 }
66345
66346 #ifdef CONFIG_MODULES
66347-static inline int within(void *addr, void *start, unsigned long size)
66348-{
66349- return ((addr >= start) && (addr < start + size));
66350-}
66351-
66352 /* Update list and generate events when modules are unloaded. */
66353 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66354 void *data)
66355@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66356 prev = NULL;
66357 /* Remove entries located in module from linked list. */
66358 for (info = gcov_info_head; info; info = info->next) {
66359- if (within(info, mod->module_core, mod->core_size)) {
66360+ if (within_module_core_rw((unsigned long)info, mod)) {
66361 if (prev)
66362 prev->next = info->next;
66363 else
66364diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66365index 6db7a5e..25b6648 100644
66366--- a/kernel/hrtimer.c
66367+++ b/kernel/hrtimer.c
66368@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
66369 local_irq_restore(flags);
66370 }
66371
66372-static void run_hrtimer_softirq(struct softirq_action *h)
66373+static void run_hrtimer_softirq(void)
66374 {
66375 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
66376
66377diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66378index 4304919..408c4c0 100644
66379--- a/kernel/jump_label.c
66380+++ b/kernel/jump_label.c
66381@@ -13,6 +13,7 @@
66382 #include <linux/sort.h>
66383 #include <linux/err.h>
66384 #include <linux/static_key.h>
66385+#include <linux/mm.h>
66386
66387 #ifdef HAVE_JUMP_LABEL
66388
66389@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66390
66391 size = (((unsigned long)stop - (unsigned long)start)
66392 / sizeof(struct jump_entry));
66393+ pax_open_kernel();
66394 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66395+ pax_close_kernel();
66396 }
66397
66398 static void jump_label_update(struct static_key *key, int enable);
66399@@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66400 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66401 struct jump_entry *iter;
66402
66403+ pax_open_kernel();
66404 for (iter = iter_start; iter < iter_stop; iter++) {
66405 if (within_module_init(iter->code, mod))
66406 iter->code = 0;
66407 }
66408+ pax_close_kernel();
66409 }
66410
66411 static int
66412diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66413index 079f1d3..4e80e69 100644
66414--- a/kernel/kallsyms.c
66415+++ b/kernel/kallsyms.c
66416@@ -11,6 +11,9 @@
66417 * Changed the compression method from stem compression to "table lookup"
66418 * compression (see scripts/kallsyms.c for a more complete description)
66419 */
66420+#ifdef CONFIG_GRKERNSEC_HIDESYM
66421+#define __INCLUDED_BY_HIDESYM 1
66422+#endif
66423 #include <linux/kallsyms.h>
66424 #include <linux/module.h>
66425 #include <linux/init.h>
66426@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66427
66428 static inline int is_kernel_inittext(unsigned long addr)
66429 {
66430+ if (system_state != SYSTEM_BOOTING)
66431+ return 0;
66432+
66433 if (addr >= (unsigned long)_sinittext
66434 && addr <= (unsigned long)_einittext)
66435 return 1;
66436 return 0;
66437 }
66438
66439+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66440+#ifdef CONFIG_MODULES
66441+static inline int is_module_text(unsigned long addr)
66442+{
66443+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66444+ return 1;
66445+
66446+ addr = ktla_ktva(addr);
66447+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66448+}
66449+#else
66450+static inline int is_module_text(unsigned long addr)
66451+{
66452+ return 0;
66453+}
66454+#endif
66455+#endif
66456+
66457 static inline int is_kernel_text(unsigned long addr)
66458 {
66459 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66460@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66461
66462 static inline int is_kernel(unsigned long addr)
66463 {
66464+
66465+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66466+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
66467+ return 1;
66468+
66469+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66470+#else
66471 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66472+#endif
66473+
66474 return 1;
66475 return in_gate_area_no_mm(addr);
66476 }
66477
66478 static int is_ksym_addr(unsigned long addr)
66479 {
66480+
66481+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66482+ if (is_module_text(addr))
66483+ return 0;
66484+#endif
66485+
66486 if (all_var)
66487 return is_kernel(addr);
66488
66489@@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66490
66491 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66492 {
66493- iter->name[0] = '\0';
66494 iter->nameoff = get_symbol_offset(new_pos);
66495 iter->pos = new_pos;
66496 }
66497@@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
66498 {
66499 struct kallsym_iter *iter = m->private;
66500
66501+#ifdef CONFIG_GRKERNSEC_HIDESYM
66502+ if (current_uid())
66503+ return 0;
66504+#endif
66505+
66506 /* Some debugging symbols have no name. Ignore them. */
66507 if (!iter->name[0])
66508 return 0;
66509@@ -515,11 +558,22 @@ static int s_show(struct seq_file *m, void *p)
66510 */
66511 type = iter->exported ? toupper(iter->type) :
66512 tolower(iter->type);
66513+
66514+#ifdef CONFIG_GRKERNSEC_HIDESYM
66515+ seq_printf(m, "%pP %c %s\t[%s]\n", (void *)iter->value,
66516+ type, iter->name, iter->module_name);
66517+#else
66518 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
66519 type, iter->name, iter->module_name);
66520+#endif
66521 } else
66522+#ifdef CONFIG_GRKERNSEC_HIDESYM
66523+ seq_printf(m, "%pP %c %s\n", (void *)iter->value,
66524+ iter->type, iter->name);
66525+#else
66526 seq_printf(m, "%pK %c %s\n", (void *)iter->value,
66527 iter->type, iter->name);
66528+#endif
66529 return 0;
66530 }
66531
66532@@ -540,7 +594,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66533 struct kallsym_iter *iter;
66534 int ret;
66535
66536- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66537+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66538 if (!iter)
66539 return -ENOMEM;
66540 reset_iter(iter, 0);
66541diff --git a/kernel/kexec.c b/kernel/kexec.c
66542index 4e2e472..cd0c7ae 100644
66543--- a/kernel/kexec.c
66544+++ b/kernel/kexec.c
66545@@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66546 unsigned long flags)
66547 {
66548 struct compat_kexec_segment in;
66549- struct kexec_segment out, __user *ksegments;
66550+ struct kexec_segment out;
66551+ struct kexec_segment __user *ksegments;
66552 unsigned long i, result;
66553
66554 /* Don't allow clients that don't understand the native
66555diff --git a/kernel/kmod.c b/kernel/kmod.c
66556index 05698a7..a4c1e3a 100644
66557--- a/kernel/kmod.c
66558+++ b/kernel/kmod.c
66559@@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
66560 kfree(info->argv);
66561 }
66562
66563-static int call_modprobe(char *module_name, int wait)
66564+static int call_modprobe(char *module_name, char *module_param, int wait)
66565 {
66566 static char *envp[] = {
66567 "HOME=/",
66568@@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
66569 NULL
66570 };
66571
66572- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
66573+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
66574 if (!argv)
66575 goto out;
66576
66577@@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
66578 argv[1] = "-q";
66579 argv[2] = "--";
66580 argv[3] = module_name; /* check free_modprobe_argv() */
66581- argv[4] = NULL;
66582+ argv[4] = module_param;
66583+ argv[5] = NULL;
66584
66585 return call_usermodehelper_fns(modprobe_path, argv, envp,
66586 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
66587@@ -112,9 +113,8 @@ out:
66588 * If module auto-loading support is disabled then this function
66589 * becomes a no-operation.
66590 */
66591-int __request_module(bool wait, const char *fmt, ...)
66592+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
66593 {
66594- va_list args;
66595 char module_name[MODULE_NAME_LEN];
66596 unsigned int max_modprobes;
66597 int ret;
66598@@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
66599 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
66600 static int kmod_loop_msg;
66601
66602- va_start(args, fmt);
66603- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
66604- va_end(args);
66605+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
66606 if (ret >= MODULE_NAME_LEN)
66607 return -ENAMETOOLONG;
66608
66609@@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
66610 if (ret)
66611 return ret;
66612
66613+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66614+ if (!current_uid()) {
66615+ /* hack to workaround consolekit/udisks stupidity */
66616+ read_lock(&tasklist_lock);
66617+ if (!strcmp(current->comm, "mount") &&
66618+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
66619+ read_unlock(&tasklist_lock);
66620+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
66621+ return -EPERM;
66622+ }
66623+ read_unlock(&tasklist_lock);
66624+ }
66625+#endif
66626+
66627 /* If modprobe needs a service that is in a module, we get a recursive
66628 * loop. Limit the number of running kmod threads to max_threads/2 or
66629 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
66630@@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
66631
66632 trace_module_request(module_name, wait, _RET_IP_);
66633
66634- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
66635+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
66636
66637 atomic_dec(&kmod_concurrent);
66638 return ret;
66639 }
66640+
66641+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
66642+{
66643+ va_list args;
66644+ int ret;
66645+
66646+ va_start(args, fmt);
66647+ ret = ____request_module(wait, module_param, fmt, args);
66648+ va_end(args);
66649+
66650+ return ret;
66651+}
66652+
66653+int __request_module(bool wait, const char *fmt, ...)
66654+{
66655+ va_list args;
66656+ int ret;
66657+
66658+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66659+ if (current_uid()) {
66660+ char module_param[MODULE_NAME_LEN];
66661+
66662+ memset(module_param, 0, sizeof(module_param));
66663+
66664+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
66665+
66666+ va_start(args, fmt);
66667+ ret = ____request_module(wait, module_param, fmt, args);
66668+ va_end(args);
66669+
66670+ return ret;
66671+ }
66672+#endif
66673+
66674+ va_start(args, fmt);
66675+ ret = ____request_module(wait, NULL, fmt, args);
66676+ va_end(args);
66677+
66678+ return ret;
66679+}
66680+
66681 EXPORT_SYMBOL(__request_module);
66682 #endif /* CONFIG_MODULES */
66683
66684@@ -267,7 +320,7 @@ static int wait_for_helper(void *data)
66685 *
66686 * Thus the __user pointer cast is valid here.
66687 */
66688- sys_wait4(pid, (int __user *)&ret, 0, NULL);
66689+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
66690
66691 /*
66692 * If ret is 0, either ____call_usermodehelper failed and the
66693diff --git a/kernel/kprobes.c b/kernel/kprobes.c
66694index c62b854..cb67968 100644
66695--- a/kernel/kprobes.c
66696+++ b/kernel/kprobes.c
66697@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66698 * kernel image and loaded module images reside. This is required
66699 * so x86_64 can correctly handle the %rip-relative fixups.
66700 */
66701- kip->insns = module_alloc(PAGE_SIZE);
66702+ kip->insns = module_alloc_exec(PAGE_SIZE);
66703 if (!kip->insns) {
66704 kfree(kip);
66705 return NULL;
66706@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66707 */
66708 if (!list_is_singular(&kip->list)) {
66709 list_del(&kip->list);
66710- module_free(NULL, kip->insns);
66711+ module_free_exec(NULL, kip->insns);
66712 kfree(kip);
66713 }
66714 return 1;
66715@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
66716 {
66717 int i, err = 0;
66718 unsigned long offset = 0, size = 0;
66719- char *modname, namebuf[128];
66720+ char *modname, namebuf[KSYM_NAME_LEN];
66721 const char *symbol_name;
66722 void *addr;
66723 struct kprobe_blackpoint *kb;
66724@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
66725 const char *sym = NULL;
66726 unsigned int i = *(loff_t *) v;
66727 unsigned long offset = 0;
66728- char *modname, namebuf[128];
66729+ char *modname, namebuf[KSYM_NAME_LEN];
66730
66731 head = &kprobe_table[i];
66732 preempt_disable();
66733diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
66734index 4e316e1..5501eef 100644
66735--- a/kernel/ksysfs.c
66736+++ b/kernel/ksysfs.c
66737@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
66738 {
66739 if (count+1 > UEVENT_HELPER_PATH_LEN)
66740 return -ENOENT;
66741+ if (!capable(CAP_SYS_ADMIN))
66742+ return -EPERM;
66743 memcpy(uevent_helper, buf, count);
66744 uevent_helper[count] = '\0';
66745 if (count && uevent_helper[count-1] == '\n')
66746diff --git a/kernel/lockdep.c b/kernel/lockdep.c
66747index ea9ee45..67ebc8f 100644
66748--- a/kernel/lockdep.c
66749+++ b/kernel/lockdep.c
66750@@ -590,6 +590,10 @@ static int static_obj(void *obj)
66751 end = (unsigned long) &_end,
66752 addr = (unsigned long) obj;
66753
66754+#ifdef CONFIG_PAX_KERNEXEC
66755+ start = ktla_ktva(start);
66756+#endif
66757+
66758 /*
66759 * static variable?
66760 */
66761@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
66762 if (!static_obj(lock->key)) {
66763 debug_locks_off();
66764 printk("INFO: trying to register non-static key.\n");
66765+ printk("lock:%pS key:%pS.\n", lock, lock->key);
66766 printk("the code is fine but needs lockdep annotation.\n");
66767 printk("turning off the locking correctness validator.\n");
66768 dump_stack();
66769@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
66770 if (!class)
66771 return 0;
66772 }
66773- atomic_inc((atomic_t *)&class->ops);
66774+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
66775 if (very_verbose(class)) {
66776 printk("\nacquire class [%p] %s", class->key, class->name);
66777 if (class->name_version > 1)
66778diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
66779index 91c32a0..b2c71c5 100644
66780--- a/kernel/lockdep_proc.c
66781+++ b/kernel/lockdep_proc.c
66782@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
66783
66784 static void print_name(struct seq_file *m, struct lock_class *class)
66785 {
66786- char str[128];
66787+ char str[KSYM_NAME_LEN];
66788 const char *name = class->name;
66789
66790 if (!name) {
66791diff --git a/kernel/module.c b/kernel/module.c
66792index 78ac6ec..e87db0e 100644
66793--- a/kernel/module.c
66794+++ b/kernel/module.c
66795@@ -58,6 +58,7 @@
66796 #include <linux/jump_label.h>
66797 #include <linux/pfn.h>
66798 #include <linux/bsearch.h>
66799+#include <linux/grsecurity.h>
66800
66801 #define CREATE_TRACE_POINTS
66802 #include <trace/events/module.h>
66803@@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
66804
66805 /* Bounds of module allocation, for speeding __module_address.
66806 * Protected by module_mutex. */
66807-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
66808+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
66809+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
66810
66811 int register_module_notifier(struct notifier_block * nb)
66812 {
66813@@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66814 return true;
66815
66816 list_for_each_entry_rcu(mod, &modules, list) {
66817- struct symsearch arr[] = {
66818+ struct symsearch modarr[] = {
66819 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
66820 NOT_GPL_ONLY, false },
66821 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
66822@@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66823 #endif
66824 };
66825
66826- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
66827+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
66828 return true;
66829 }
66830 return false;
66831@@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
66832 static int percpu_modalloc(struct module *mod,
66833 unsigned long size, unsigned long align)
66834 {
66835- if (align > PAGE_SIZE) {
66836+ if (align-1 >= PAGE_SIZE) {
66837 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
66838 mod->name, align, PAGE_SIZE);
66839 align = PAGE_SIZE;
66840@@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
66841 static ssize_t show_coresize(struct module_attribute *mattr,
66842 struct module_kobject *mk, char *buffer)
66843 {
66844- return sprintf(buffer, "%u\n", mk->mod->core_size);
66845+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
66846 }
66847
66848 static struct module_attribute modinfo_coresize =
66849@@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
66850 static ssize_t show_initsize(struct module_attribute *mattr,
66851 struct module_kobject *mk, char *buffer)
66852 {
66853- return sprintf(buffer, "%u\n", mk->mod->init_size);
66854+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
66855 }
66856
66857 static struct module_attribute modinfo_initsize =
66858@@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
66859 */
66860 #ifdef CONFIG_SYSFS
66861
66862-#ifdef CONFIG_KALLSYMS
66863+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66864 static inline bool sect_empty(const Elf_Shdr *sect)
66865 {
66866 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
66867@@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
66868
66869 static void unset_module_core_ro_nx(struct module *mod)
66870 {
66871- set_page_attributes(mod->module_core + mod->core_text_size,
66872- mod->module_core + mod->core_size,
66873+ set_page_attributes(mod->module_core_rw,
66874+ mod->module_core_rw + mod->core_size_rw,
66875 set_memory_x);
66876- set_page_attributes(mod->module_core,
66877- mod->module_core + mod->core_ro_size,
66878+ set_page_attributes(mod->module_core_rx,
66879+ mod->module_core_rx + mod->core_size_rx,
66880 set_memory_rw);
66881 }
66882
66883 static void unset_module_init_ro_nx(struct module *mod)
66884 {
66885- set_page_attributes(mod->module_init + mod->init_text_size,
66886- mod->module_init + mod->init_size,
66887+ set_page_attributes(mod->module_init_rw,
66888+ mod->module_init_rw + mod->init_size_rw,
66889 set_memory_x);
66890- set_page_attributes(mod->module_init,
66891- mod->module_init + mod->init_ro_size,
66892+ set_page_attributes(mod->module_init_rx,
66893+ mod->module_init_rx + mod->init_size_rx,
66894 set_memory_rw);
66895 }
66896
66897@@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
66898
66899 mutex_lock(&module_mutex);
66900 list_for_each_entry_rcu(mod, &modules, list) {
66901- if ((mod->module_core) && (mod->core_text_size)) {
66902- set_page_attributes(mod->module_core,
66903- mod->module_core + mod->core_text_size,
66904+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
66905+ set_page_attributes(mod->module_core_rx,
66906+ mod->module_core_rx + mod->core_size_rx,
66907 set_memory_rw);
66908 }
66909- if ((mod->module_init) && (mod->init_text_size)) {
66910- set_page_attributes(mod->module_init,
66911- mod->module_init + mod->init_text_size,
66912+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
66913+ set_page_attributes(mod->module_init_rx,
66914+ mod->module_init_rx + mod->init_size_rx,
66915 set_memory_rw);
66916 }
66917 }
66918@@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
66919
66920 mutex_lock(&module_mutex);
66921 list_for_each_entry_rcu(mod, &modules, list) {
66922- if ((mod->module_core) && (mod->core_text_size)) {
66923- set_page_attributes(mod->module_core,
66924- mod->module_core + mod->core_text_size,
66925+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
66926+ set_page_attributes(mod->module_core_rx,
66927+ mod->module_core_rx + mod->core_size_rx,
66928 set_memory_ro);
66929 }
66930- if ((mod->module_init) && (mod->init_text_size)) {
66931- set_page_attributes(mod->module_init,
66932- mod->module_init + mod->init_text_size,
66933+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
66934+ set_page_attributes(mod->module_init_rx,
66935+ mod->module_init_rx + mod->init_size_rx,
66936 set_memory_ro);
66937 }
66938 }
66939@@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
66940
66941 /* This may be NULL, but that's OK */
66942 unset_module_init_ro_nx(mod);
66943- module_free(mod, mod->module_init);
66944+ module_free(mod, mod->module_init_rw);
66945+ module_free_exec(mod, mod->module_init_rx);
66946 kfree(mod->args);
66947 percpu_modfree(mod);
66948
66949 /* Free lock-classes: */
66950- lockdep_free_key_range(mod->module_core, mod->core_size);
66951+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
66952+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
66953
66954 /* Finally, free the core (containing the module structure) */
66955 unset_module_core_ro_nx(mod);
66956- module_free(mod, mod->module_core);
66957+ module_free_exec(mod, mod->module_core_rx);
66958+ module_free(mod, mod->module_core_rw);
66959
66960 #ifdef CONFIG_MPU
66961 update_protections(current->mm);
66962@@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66963 int ret = 0;
66964 const struct kernel_symbol *ksym;
66965
66966+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66967+ int is_fs_load = 0;
66968+ int register_filesystem_found = 0;
66969+ char *p;
66970+
66971+ p = strstr(mod->args, "grsec_modharden_fs");
66972+ if (p) {
66973+ char *endptr = p + strlen("grsec_modharden_fs");
66974+ /* copy \0 as well */
66975+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
66976+ is_fs_load = 1;
66977+ }
66978+#endif
66979+
66980 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
66981 const char *name = info->strtab + sym[i].st_name;
66982
66983+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66984+ /* it's a real shame this will never get ripped and copied
66985+ upstream! ;(
66986+ */
66987+ if (is_fs_load && !strcmp(name, "register_filesystem"))
66988+ register_filesystem_found = 1;
66989+#endif
66990+
66991 switch (sym[i].st_shndx) {
66992 case SHN_COMMON:
66993 /* We compiled with -fno-common. These are not
66994@@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66995 ksym = resolve_symbol_wait(mod, info, name);
66996 /* Ok if resolved. */
66997 if (ksym && !IS_ERR(ksym)) {
66998+ pax_open_kernel();
66999 sym[i].st_value = ksym->value;
67000+ pax_close_kernel();
67001 break;
67002 }
67003
67004@@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67005 secbase = (unsigned long)mod_percpu(mod);
67006 else
67007 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67008+ pax_open_kernel();
67009 sym[i].st_value += secbase;
67010+ pax_close_kernel();
67011 break;
67012 }
67013 }
67014
67015+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67016+ if (is_fs_load && !register_filesystem_found) {
67017+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67018+ ret = -EPERM;
67019+ }
67020+#endif
67021+
67022 return ret;
67023 }
67024
67025@@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67026 || s->sh_entsize != ~0UL
67027 || strstarts(sname, ".init"))
67028 continue;
67029- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67030+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67031+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67032+ else
67033+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67034 pr_debug("\t%s\n", sname);
67035 }
67036- switch (m) {
67037- case 0: /* executable */
67038- mod->core_size = debug_align(mod->core_size);
67039- mod->core_text_size = mod->core_size;
67040- break;
67041- case 1: /* RO: text and ro-data */
67042- mod->core_size = debug_align(mod->core_size);
67043- mod->core_ro_size = mod->core_size;
67044- break;
67045- case 3: /* whole core */
67046- mod->core_size = debug_align(mod->core_size);
67047- break;
67048- }
67049 }
67050
67051 pr_debug("Init section allocation order:\n");
67052@@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67053 || s->sh_entsize != ~0UL
67054 || !strstarts(sname, ".init"))
67055 continue;
67056- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67057- | INIT_OFFSET_MASK);
67058+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67059+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67060+ else
67061+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67062+ s->sh_entsize |= INIT_OFFSET_MASK;
67063 pr_debug("\t%s\n", sname);
67064 }
67065- switch (m) {
67066- case 0: /* executable */
67067- mod->init_size = debug_align(mod->init_size);
67068- mod->init_text_size = mod->init_size;
67069- break;
67070- case 1: /* RO: text and ro-data */
67071- mod->init_size = debug_align(mod->init_size);
67072- mod->init_ro_size = mod->init_size;
67073- break;
67074- case 3: /* whole init */
67075- mod->init_size = debug_align(mod->init_size);
67076- break;
67077- }
67078 }
67079 }
67080
67081@@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67082
67083 /* Put symbol section at end of init part of module. */
67084 symsect->sh_flags |= SHF_ALLOC;
67085- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67086+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67087 info->index.sym) | INIT_OFFSET_MASK;
67088 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67089
67090@@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67091 }
67092
67093 /* Append room for core symbols at end of core part. */
67094- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67095- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67096- mod->core_size += strtab_size;
67097+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67098+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67099+ mod->core_size_rx += strtab_size;
67100
67101 /* Put string table section at end of init part of module. */
67102 strsect->sh_flags |= SHF_ALLOC;
67103- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67104+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67105 info->index.str) | INIT_OFFSET_MASK;
67106 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67107 }
67108@@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67109 /* Make sure we get permanent strtab: don't use info->strtab. */
67110 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67111
67112+ pax_open_kernel();
67113+
67114 /* Set types up while we still have access to sections. */
67115 for (i = 0; i < mod->num_symtab; i++)
67116 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67117
67118- mod->core_symtab = dst = mod->module_core + info->symoffs;
67119- mod->core_strtab = s = mod->module_core + info->stroffs;
67120+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67121+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67122 src = mod->symtab;
67123 *dst = *src;
67124 *s++ = 0;
67125@@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67126 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67127 }
67128 mod->core_num_syms = ndst;
67129+
67130+ pax_close_kernel();
67131 }
67132 #else
67133 static inline void layout_symtab(struct module *mod, struct load_info *info)
67134@@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
67135 return size == 0 ? NULL : vmalloc_exec(size);
67136 }
67137
67138-static void *module_alloc_update_bounds(unsigned long size)
67139+static void *module_alloc_update_bounds_rw(unsigned long size)
67140 {
67141 void *ret = module_alloc(size);
67142
67143 if (ret) {
67144 mutex_lock(&module_mutex);
67145 /* Update module bounds. */
67146- if ((unsigned long)ret < module_addr_min)
67147- module_addr_min = (unsigned long)ret;
67148- if ((unsigned long)ret + size > module_addr_max)
67149- module_addr_max = (unsigned long)ret + size;
67150+ if ((unsigned long)ret < module_addr_min_rw)
67151+ module_addr_min_rw = (unsigned long)ret;
67152+ if ((unsigned long)ret + size > module_addr_max_rw)
67153+ module_addr_max_rw = (unsigned long)ret + size;
67154+ mutex_unlock(&module_mutex);
67155+ }
67156+ return ret;
67157+}
67158+
67159+static void *module_alloc_update_bounds_rx(unsigned long size)
67160+{
67161+ void *ret = module_alloc_exec(size);
67162+
67163+ if (ret) {
67164+ mutex_lock(&module_mutex);
67165+ /* Update module bounds. */
67166+ if ((unsigned long)ret < module_addr_min_rx)
67167+ module_addr_min_rx = (unsigned long)ret;
67168+ if ((unsigned long)ret + size > module_addr_max_rx)
67169+ module_addr_max_rx = (unsigned long)ret + size;
67170 mutex_unlock(&module_mutex);
67171 }
67172 return ret;
67173@@ -2543,8 +2581,14 @@ static struct module *setup_load_info(struct load_info *info)
67174 static int check_modinfo(struct module *mod, struct load_info *info)
67175 {
67176 const char *modmagic = get_modinfo(info, "vermagic");
67177+ const char *license = get_modinfo(info, "license");
67178 int err;
67179
67180+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67181+ if (!license || !license_is_gpl_compatible(license))
67182+ return -ENOEXEC;
67183+#endif
67184+
67185 /* This is allowed: modprobe --force will invalidate it. */
67186 if (!modmagic) {
67187 err = try_to_force_load(mod, "bad vermagic");
67188@@ -2567,7 +2611,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67189 }
67190
67191 /* Set up license info based on the info section */
67192- set_license(mod, get_modinfo(info, "license"));
67193+ set_license(mod, license);
67194
67195 return 0;
67196 }
67197@@ -2661,7 +2705,7 @@ static int move_module(struct module *mod, struct load_info *info)
67198 void *ptr;
67199
67200 /* Do the allocs. */
67201- ptr = module_alloc_update_bounds(mod->core_size);
67202+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67203 /*
67204 * The pointer to this block is stored in the module structure
67205 * which is inside the block. Just mark it as not being a
67206@@ -2671,23 +2715,50 @@ static int move_module(struct module *mod, struct load_info *info)
67207 if (!ptr)
67208 return -ENOMEM;
67209
67210- memset(ptr, 0, mod->core_size);
67211- mod->module_core = ptr;
67212+ memset(ptr, 0, mod->core_size_rw);
67213+ mod->module_core_rw = ptr;
67214
67215- ptr = module_alloc_update_bounds(mod->init_size);
67216+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67217 /*
67218 * The pointer to this block is stored in the module structure
67219 * which is inside the block. This block doesn't need to be
67220 * scanned as it contains data and code that will be freed
67221 * after the module is initialized.
67222 */
67223- kmemleak_ignore(ptr);
67224- if (!ptr && mod->init_size) {
67225- module_free(mod, mod->module_core);
67226+ kmemleak_not_leak(ptr);
67227+ if (!ptr && mod->init_size_rw) {
67228+ module_free(mod, mod->module_core_rw);
67229 return -ENOMEM;
67230 }
67231- memset(ptr, 0, mod->init_size);
67232- mod->module_init = ptr;
67233+ memset(ptr, 0, mod->init_size_rw);
67234+ mod->module_init_rw = ptr;
67235+
67236+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67237+ kmemleak_not_leak(ptr);
67238+ if (!ptr) {
67239+ module_free(mod, mod->module_init_rw);
67240+ module_free(mod, mod->module_core_rw);
67241+ return -ENOMEM;
67242+ }
67243+
67244+ pax_open_kernel();
67245+ memset(ptr, 0, mod->core_size_rx);
67246+ pax_close_kernel();
67247+ mod->module_core_rx = ptr;
67248+
67249+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67250+ kmemleak_not_leak(ptr);
67251+ if (!ptr && mod->init_size_rx) {
67252+ module_free_exec(mod, mod->module_core_rx);
67253+ module_free(mod, mod->module_init_rw);
67254+ module_free(mod, mod->module_core_rw);
67255+ return -ENOMEM;
67256+ }
67257+
67258+ pax_open_kernel();
67259+ memset(ptr, 0, mod->init_size_rx);
67260+ pax_close_kernel();
67261+ mod->module_init_rx = ptr;
67262
67263 /* Transfer each section which specifies SHF_ALLOC */
67264 pr_debug("final section addresses:\n");
67265@@ -2698,16 +2769,45 @@ static int move_module(struct module *mod, struct load_info *info)
67266 if (!(shdr->sh_flags & SHF_ALLOC))
67267 continue;
67268
67269- if (shdr->sh_entsize & INIT_OFFSET_MASK)
67270- dest = mod->module_init
67271- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67272- else
67273- dest = mod->module_core + shdr->sh_entsize;
67274+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67275+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67276+ dest = mod->module_init_rw
67277+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67278+ else
67279+ dest = mod->module_init_rx
67280+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67281+ } else {
67282+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67283+ dest = mod->module_core_rw + shdr->sh_entsize;
67284+ else
67285+ dest = mod->module_core_rx + shdr->sh_entsize;
67286+ }
67287+
67288+ if (shdr->sh_type != SHT_NOBITS) {
67289+
67290+#ifdef CONFIG_PAX_KERNEXEC
67291+#ifdef CONFIG_X86_64
67292+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67293+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67294+#endif
67295+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67296+ pax_open_kernel();
67297+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67298+ pax_close_kernel();
67299+ } else
67300+#endif
67301
67302- if (shdr->sh_type != SHT_NOBITS)
67303 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67304+ }
67305 /* Update sh_addr to point to copy in image. */
67306- shdr->sh_addr = (unsigned long)dest;
67307+
67308+#ifdef CONFIG_PAX_KERNEXEC
67309+ if (shdr->sh_flags & SHF_EXECINSTR)
67310+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
67311+ else
67312+#endif
67313+
67314+ shdr->sh_addr = (unsigned long)dest;
67315 pr_debug("\t0x%lx %s\n",
67316 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67317 }
67318@@ -2758,12 +2858,12 @@ static void flush_module_icache(const struct module *mod)
67319 * Do it before processing of module parameters, so the module
67320 * can provide parameter accessor functions of its own.
67321 */
67322- if (mod->module_init)
67323- flush_icache_range((unsigned long)mod->module_init,
67324- (unsigned long)mod->module_init
67325- + mod->init_size);
67326- flush_icache_range((unsigned long)mod->module_core,
67327- (unsigned long)mod->module_core + mod->core_size);
67328+ if (mod->module_init_rx)
67329+ flush_icache_range((unsigned long)mod->module_init_rx,
67330+ (unsigned long)mod->module_init_rx
67331+ + mod->init_size_rx);
67332+ flush_icache_range((unsigned long)mod->module_core_rx,
67333+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
67334
67335 set_fs(old_fs);
67336 }
67337@@ -2833,8 +2933,10 @@ out:
67338 static void module_deallocate(struct module *mod, struct load_info *info)
67339 {
67340 percpu_modfree(mod);
67341- module_free(mod, mod->module_init);
67342- module_free(mod, mod->module_core);
67343+ module_free_exec(mod, mod->module_init_rx);
67344+ module_free_exec(mod, mod->module_core_rx);
67345+ module_free(mod, mod->module_init_rw);
67346+ module_free(mod, mod->module_core_rw);
67347 }
67348
67349 int __weak module_finalize(const Elf_Ehdr *hdr,
67350@@ -2898,9 +3000,38 @@ static struct module *load_module(void __user *umod,
67351 if (err)
67352 goto free_unload;
67353
67354+ /* Now copy in args */
67355+ mod->args = strndup_user(uargs, ~0UL >> 1);
67356+ if (IS_ERR(mod->args)) {
67357+ err = PTR_ERR(mod->args);
67358+ goto free_unload;
67359+ }
67360+
67361 /* Set up MODINFO_ATTR fields */
67362 setup_modinfo(mod, &info);
67363
67364+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67365+ {
67366+ char *p, *p2;
67367+
67368+ if (strstr(mod->args, "grsec_modharden_netdev")) {
67369+ 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);
67370+ err = -EPERM;
67371+ goto free_modinfo;
67372+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67373+ p += strlen("grsec_modharden_normal");
67374+ p2 = strstr(p, "_");
67375+ if (p2) {
67376+ *p2 = '\0';
67377+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67378+ *p2 = '_';
67379+ }
67380+ err = -EPERM;
67381+ goto free_modinfo;
67382+ }
67383+ }
67384+#endif
67385+
67386 /* Fix up syms, so that st_value is a pointer to location. */
67387 err = simplify_symbols(mod, &info);
67388 if (err < 0)
67389@@ -2916,13 +3047,6 @@ static struct module *load_module(void __user *umod,
67390
67391 flush_module_icache(mod);
67392
67393- /* Now copy in args */
67394- mod->args = strndup_user(uargs, ~0UL >> 1);
67395- if (IS_ERR(mod->args)) {
67396- err = PTR_ERR(mod->args);
67397- goto free_arch_cleanup;
67398- }
67399-
67400 /* Mark state as coming so strong_try_module_get() ignores us. */
67401 mod->state = MODULE_STATE_COMING;
67402
67403@@ -2980,11 +3104,10 @@ static struct module *load_module(void __user *umod,
67404 unlock:
67405 mutex_unlock(&module_mutex);
67406 synchronize_sched();
67407- kfree(mod->args);
67408- free_arch_cleanup:
67409 module_arch_cleanup(mod);
67410 free_modinfo:
67411 free_modinfo(mod);
67412+ kfree(mod->args);
67413 free_unload:
67414 module_unload_free(mod);
67415 free_module:
67416@@ -3025,16 +3148,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67417 MODULE_STATE_COMING, mod);
67418
67419 /* Set RO and NX regions for core */
67420- set_section_ro_nx(mod->module_core,
67421- mod->core_text_size,
67422- mod->core_ro_size,
67423- mod->core_size);
67424+ set_section_ro_nx(mod->module_core_rx,
67425+ mod->core_size_rx,
67426+ mod->core_size_rx,
67427+ mod->core_size_rx);
67428
67429 /* Set RO and NX regions for init */
67430- set_section_ro_nx(mod->module_init,
67431- mod->init_text_size,
67432- mod->init_ro_size,
67433- mod->init_size);
67434+ set_section_ro_nx(mod->module_init_rx,
67435+ mod->init_size_rx,
67436+ mod->init_size_rx,
67437+ mod->init_size_rx);
67438
67439 do_mod_ctors(mod);
67440 /* Start the module */
67441@@ -3080,11 +3203,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67442 mod->strtab = mod->core_strtab;
67443 #endif
67444 unset_module_init_ro_nx(mod);
67445- module_free(mod, mod->module_init);
67446- mod->module_init = NULL;
67447- mod->init_size = 0;
67448- mod->init_ro_size = 0;
67449- mod->init_text_size = 0;
67450+ module_free(mod, mod->module_init_rw);
67451+ module_free_exec(mod, mod->module_init_rx);
67452+ mod->module_init_rw = NULL;
67453+ mod->module_init_rx = NULL;
67454+ mod->init_size_rw = 0;
67455+ mod->init_size_rx = 0;
67456 mutex_unlock(&module_mutex);
67457
67458 return 0;
67459@@ -3115,10 +3239,16 @@ static const char *get_ksymbol(struct module *mod,
67460 unsigned long nextval;
67461
67462 /* At worse, next value is at end of module */
67463- if (within_module_init(addr, mod))
67464- nextval = (unsigned long)mod->module_init+mod->init_text_size;
67465+ if (within_module_init_rx(addr, mod))
67466+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67467+ else if (within_module_init_rw(addr, mod))
67468+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67469+ else if (within_module_core_rx(addr, mod))
67470+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67471+ else if (within_module_core_rw(addr, mod))
67472+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67473 else
67474- nextval = (unsigned long)mod->module_core+mod->core_text_size;
67475+ return NULL;
67476
67477 /* Scan for closest preceding symbol, and next symbol. (ELF
67478 starts real symbols at 1). */
67479@@ -3353,7 +3483,7 @@ static int m_show(struct seq_file *m, void *p)
67480 char buf[8];
67481
67482 seq_printf(m, "%s %u",
67483- mod->name, mod->init_size + mod->core_size);
67484+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67485 print_unload_info(m, mod);
67486
67487 /* Informative for users. */
67488@@ -3362,7 +3492,7 @@ static int m_show(struct seq_file *m, void *p)
67489 mod->state == MODULE_STATE_COMING ? "Loading":
67490 "Live");
67491 /* Used by oprofile and other similar tools. */
67492- seq_printf(m, " 0x%pK", mod->module_core);
67493+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67494
67495 /* Taints info */
67496 if (mod->taints)
67497@@ -3398,7 +3528,17 @@ static const struct file_operations proc_modules_operations = {
67498
67499 static int __init proc_modules_init(void)
67500 {
67501+#ifndef CONFIG_GRKERNSEC_HIDESYM
67502+#ifdef CONFIG_GRKERNSEC_PROC_USER
67503+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67504+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67505+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67506+#else
67507 proc_create("modules", 0, NULL, &proc_modules_operations);
67508+#endif
67509+#else
67510+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67511+#endif
67512 return 0;
67513 }
67514 module_init(proc_modules_init);
67515@@ -3457,12 +3597,12 @@ struct module *__module_address(unsigned long addr)
67516 {
67517 struct module *mod;
67518
67519- if (addr < module_addr_min || addr > module_addr_max)
67520+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67521+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
67522 return NULL;
67523
67524 list_for_each_entry_rcu(mod, &modules, list)
67525- if (within_module_core(addr, mod)
67526- || within_module_init(addr, mod))
67527+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
67528 return mod;
67529 return NULL;
67530 }
67531@@ -3496,11 +3636,20 @@ bool is_module_text_address(unsigned long addr)
67532 */
67533 struct module *__module_text_address(unsigned long addr)
67534 {
67535- struct module *mod = __module_address(addr);
67536+ struct module *mod;
67537+
67538+#ifdef CONFIG_X86_32
67539+ addr = ktla_ktva(addr);
67540+#endif
67541+
67542+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67543+ return NULL;
67544+
67545+ mod = __module_address(addr);
67546+
67547 if (mod) {
67548 /* Make sure it's within the text section. */
67549- if (!within(addr, mod->module_init, mod->init_text_size)
67550- && !within(addr, mod->module_core, mod->core_text_size))
67551+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67552 mod = NULL;
67553 }
67554 return mod;
67555diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
67556index 7e3443f..b2a1e6b 100644
67557--- a/kernel/mutex-debug.c
67558+++ b/kernel/mutex-debug.c
67559@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
67560 }
67561
67562 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67563- struct thread_info *ti)
67564+ struct task_struct *task)
67565 {
67566 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
67567
67568 /* Mark the current thread as blocked on the lock: */
67569- ti->task->blocked_on = waiter;
67570+ task->blocked_on = waiter;
67571 }
67572
67573 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67574- struct thread_info *ti)
67575+ struct task_struct *task)
67576 {
67577 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
67578- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
67579- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
67580- ti->task->blocked_on = NULL;
67581+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
67582+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
67583+ task->blocked_on = NULL;
67584
67585 list_del_init(&waiter->list);
67586 waiter->task = NULL;
67587diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
67588index 0799fd3..d06ae3b 100644
67589--- a/kernel/mutex-debug.h
67590+++ b/kernel/mutex-debug.h
67591@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
67592 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
67593 extern void debug_mutex_add_waiter(struct mutex *lock,
67594 struct mutex_waiter *waiter,
67595- struct thread_info *ti);
67596+ struct task_struct *task);
67597 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67598- struct thread_info *ti);
67599+ struct task_struct *task);
67600 extern void debug_mutex_unlock(struct mutex *lock);
67601 extern void debug_mutex_init(struct mutex *lock, const char *name,
67602 struct lock_class_key *key);
67603diff --git a/kernel/mutex.c b/kernel/mutex.c
67604index a307cc9..27fd2e9 100644
67605--- a/kernel/mutex.c
67606+++ b/kernel/mutex.c
67607@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67608 spin_lock_mutex(&lock->wait_lock, flags);
67609
67610 debug_mutex_lock_common(lock, &waiter);
67611- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
67612+ debug_mutex_add_waiter(lock, &waiter, task);
67613
67614 /* add waiting tasks to the end of the waitqueue (FIFO): */
67615 list_add_tail(&waiter.list, &lock->wait_list);
67616@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67617 * TASK_UNINTERRUPTIBLE case.)
67618 */
67619 if (unlikely(signal_pending_state(state, task))) {
67620- mutex_remove_waiter(lock, &waiter,
67621- task_thread_info(task));
67622+ mutex_remove_waiter(lock, &waiter, task);
67623 mutex_release(&lock->dep_map, 1, ip);
67624 spin_unlock_mutex(&lock->wait_lock, flags);
67625
67626@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67627 done:
67628 lock_acquired(&lock->dep_map, ip);
67629 /* got the lock - rejoice! */
67630- mutex_remove_waiter(lock, &waiter, current_thread_info());
67631+ mutex_remove_waiter(lock, &waiter, task);
67632 mutex_set_owner(lock);
67633
67634 /* set it to 0 if there are no waiters left: */
67635diff --git a/kernel/panic.c b/kernel/panic.c
67636index 9ed023b..4846159 100644
67637--- a/kernel/panic.c
67638+++ b/kernel/panic.c
67639@@ -75,6 +75,14 @@ void panic(const char *fmt, ...)
67640 int state = 0;
67641
67642 /*
67643+ * Disable local interrupts. This will prevent panic_smp_self_stop
67644+ * from deadlocking the first cpu that invokes the panic, since
67645+ * there is nothing to prevent an interrupt handler (that runs
67646+ * after the panic_lock is acquired) from invoking panic again.
67647+ */
67648+ local_irq_disable();
67649+
67650+ /*
67651 * It's possible to come here directly from a panic-assertion and
67652 * not have preempt disabled. Some functions called from here want
67653 * preempt to be disabled. No point enabling it later though...
67654@@ -402,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
67655 const char *board;
67656
67657 printk(KERN_WARNING "------------[ cut here ]------------\n");
67658- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
67659+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
67660 board = dmi_get_system_info(DMI_PRODUCT_NAME);
67661 if (board)
67662 printk(KERN_WARNING "Hardware name: %s\n", board);
67663@@ -457,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
67664 */
67665 void __stack_chk_fail(void)
67666 {
67667- panic("stack-protector: Kernel stack is corrupted in: %p\n",
67668+ dump_stack();
67669+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
67670 __builtin_return_address(0));
67671 }
67672 EXPORT_SYMBOL(__stack_chk_fail);
67673diff --git a/kernel/pid.c b/kernel/pid.c
67674index 9f08dfa..6765c40 100644
67675--- a/kernel/pid.c
67676+++ b/kernel/pid.c
67677@@ -33,6 +33,7 @@
67678 #include <linux/rculist.h>
67679 #include <linux/bootmem.h>
67680 #include <linux/hash.h>
67681+#include <linux/security.h>
67682 #include <linux/pid_namespace.h>
67683 #include <linux/init_task.h>
67684 #include <linux/syscalls.h>
67685@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
67686
67687 int pid_max = PID_MAX_DEFAULT;
67688
67689-#define RESERVED_PIDS 300
67690+#define RESERVED_PIDS 500
67691
67692 int pid_max_min = RESERVED_PIDS + 1;
67693 int pid_max_max = PID_MAX_LIMIT;
67694@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
67695 */
67696 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
67697 {
67698+ struct task_struct *task;
67699+
67700 rcu_lockdep_assert(rcu_read_lock_held(),
67701 "find_task_by_pid_ns() needs rcu_read_lock()"
67702 " protection");
67703- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67704+
67705+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67706+
67707+ if (gr_pid_is_chrooted(task))
67708+ return NULL;
67709+
67710+ return task;
67711 }
67712
67713 struct task_struct *find_task_by_vpid(pid_t vnr)
67714@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
67715 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
67716 }
67717
67718+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
67719+{
67720+ rcu_lockdep_assert(rcu_read_lock_held(),
67721+ "find_task_by_pid_ns() needs rcu_read_lock()"
67722+ " protection");
67723+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
67724+}
67725+
67726 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
67727 {
67728 struct pid *pid;
67729diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
67730index 125cb67..a4d1c30 100644
67731--- a/kernel/posix-cpu-timers.c
67732+++ b/kernel/posix-cpu-timers.c
67733@@ -6,6 +6,7 @@
67734 #include <linux/posix-timers.h>
67735 #include <linux/errno.h>
67736 #include <linux/math64.h>
67737+#include <linux/security.h>
67738 #include <asm/uaccess.h>
67739 #include <linux/kernel_stat.h>
67740 #include <trace/events/timer.h>
67741@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
67742
67743 static __init int init_posix_cpu_timers(void)
67744 {
67745- struct k_clock process = {
67746+ static struct k_clock process = {
67747 .clock_getres = process_cpu_clock_getres,
67748 .clock_get = process_cpu_clock_get,
67749 .timer_create = process_cpu_timer_create,
67750 .nsleep = process_cpu_nsleep,
67751 .nsleep_restart = process_cpu_nsleep_restart,
67752 };
67753- struct k_clock thread = {
67754+ static struct k_clock thread = {
67755 .clock_getres = thread_cpu_clock_getres,
67756 .clock_get = thread_cpu_clock_get,
67757 .timer_create = thread_cpu_timer_create,
67758diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
67759index 69185ae..cc2847a 100644
67760--- a/kernel/posix-timers.c
67761+++ b/kernel/posix-timers.c
67762@@ -43,6 +43,7 @@
67763 #include <linux/idr.h>
67764 #include <linux/posix-clock.h>
67765 #include <linux/posix-timers.h>
67766+#include <linux/grsecurity.h>
67767 #include <linux/syscalls.h>
67768 #include <linux/wait.h>
67769 #include <linux/workqueue.h>
67770@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
67771 * which we beg off on and pass to do_sys_settimeofday().
67772 */
67773
67774-static struct k_clock posix_clocks[MAX_CLOCKS];
67775+static struct k_clock *posix_clocks[MAX_CLOCKS];
67776
67777 /*
67778 * These ones are defined below.
67779@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
67780 */
67781 static __init int init_posix_timers(void)
67782 {
67783- struct k_clock clock_realtime = {
67784+ static struct k_clock clock_realtime = {
67785 .clock_getres = hrtimer_get_res,
67786 .clock_get = posix_clock_realtime_get,
67787 .clock_set = posix_clock_realtime_set,
67788@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
67789 .timer_get = common_timer_get,
67790 .timer_del = common_timer_del,
67791 };
67792- struct k_clock clock_monotonic = {
67793+ static struct k_clock clock_monotonic = {
67794 .clock_getres = hrtimer_get_res,
67795 .clock_get = posix_ktime_get_ts,
67796 .nsleep = common_nsleep,
67797@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
67798 .timer_get = common_timer_get,
67799 .timer_del = common_timer_del,
67800 };
67801- struct k_clock clock_monotonic_raw = {
67802+ static struct k_clock clock_monotonic_raw = {
67803 .clock_getres = hrtimer_get_res,
67804 .clock_get = posix_get_monotonic_raw,
67805 };
67806- struct k_clock clock_realtime_coarse = {
67807+ static struct k_clock clock_realtime_coarse = {
67808 .clock_getres = posix_get_coarse_res,
67809 .clock_get = posix_get_realtime_coarse,
67810 };
67811- struct k_clock clock_monotonic_coarse = {
67812+ static struct k_clock clock_monotonic_coarse = {
67813 .clock_getres = posix_get_coarse_res,
67814 .clock_get = posix_get_monotonic_coarse,
67815 };
67816- struct k_clock clock_boottime = {
67817+ static struct k_clock clock_boottime = {
67818 .clock_getres = hrtimer_get_res,
67819 .clock_get = posix_get_boottime,
67820 .nsleep = common_nsleep,
67821@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
67822 return;
67823 }
67824
67825- posix_clocks[clock_id] = *new_clock;
67826+ posix_clocks[clock_id] = new_clock;
67827 }
67828 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
67829
67830@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
67831 return (id & CLOCKFD_MASK) == CLOCKFD ?
67832 &clock_posix_dynamic : &clock_posix_cpu;
67833
67834- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
67835+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
67836 return NULL;
67837- return &posix_clocks[id];
67838+ return posix_clocks[id];
67839 }
67840
67841 static int common_timer_create(struct k_itimer *new_timer)
67842@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67843 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67844 return -EFAULT;
67845
67846+ /* only the CLOCK_REALTIME clock can be set, all other clocks
67847+ have their clock_set fptr set to a nosettime dummy function
67848+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67849+ call common_clock_set, which calls do_sys_settimeofday, which
67850+ we hook
67851+ */
67852+
67853 return kc->clock_set(which_clock, &new_tp);
67854 }
67855
67856diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67857index d523593..68197a4 100644
67858--- a/kernel/power/poweroff.c
67859+++ b/kernel/power/poweroff.c
67860@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
67861 .enable_mask = SYSRQ_ENABLE_BOOT,
67862 };
67863
67864-static int pm_sysrq_init(void)
67865+static int __init pm_sysrq_init(void)
67866 {
67867 register_sysrq_key('o', &sysrq_poweroff_op);
67868 return 0;
67869diff --git a/kernel/power/process.c b/kernel/power/process.c
67870index 19db29f..33b52b6 100644
67871--- a/kernel/power/process.c
67872+++ b/kernel/power/process.c
67873@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
67874 u64 elapsed_csecs64;
67875 unsigned int elapsed_csecs;
67876 bool wakeup = false;
67877+ bool timedout = false;
67878
67879 do_gettimeofday(&start);
67880
67881@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
67882
67883 while (true) {
67884 todo = 0;
67885+ if (time_after(jiffies, end_time))
67886+ timedout = true;
67887 read_lock(&tasklist_lock);
67888 do_each_thread(g, p) {
67889 if (p == current || !freeze_task(p))
67890@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
67891 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
67892 * transition can't race with task state testing here.
67893 */
67894- if (!task_is_stopped_or_traced(p) &&
67895- !freezer_should_skip(p))
67896+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
67897 todo++;
67898+ if (timedout) {
67899+ printk(KERN_ERR "Task refusing to freeze:\n");
67900+ sched_show_task(p);
67901+ }
67902+ }
67903 } while_each_thread(g, p);
67904 read_unlock(&tasklist_lock);
67905
67906@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
67907 todo += wq_busy;
67908 }
67909
67910- if (!todo || time_after(jiffies, end_time))
67911+ if (!todo || timedout)
67912 break;
67913
67914 if (pm_wakeup_pending()) {
67915diff --git a/kernel/printk.c b/kernel/printk.c
67916index b663c2c..1d6ba7a 100644
67917--- a/kernel/printk.c
67918+++ b/kernel/printk.c
67919@@ -316,6 +316,11 @@ static int check_syslog_permissions(int type, bool from_file)
67920 if (from_file && type != SYSLOG_ACTION_OPEN)
67921 return 0;
67922
67923+#ifdef CONFIG_GRKERNSEC_DMESG
67924+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
67925+ return -EPERM;
67926+#endif
67927+
67928 if (syslog_action_restricted(type)) {
67929 if (capable(CAP_SYSLOG))
67930 return 0;
67931diff --git a/kernel/profile.c b/kernel/profile.c
67932index 76b8e77..a2930e8 100644
67933--- a/kernel/profile.c
67934+++ b/kernel/profile.c
67935@@ -39,7 +39,7 @@ struct profile_hit {
67936 /* Oprofile timer tick hook */
67937 static int (*timer_hook)(struct pt_regs *) __read_mostly;
67938
67939-static atomic_t *prof_buffer;
67940+static atomic_unchecked_t *prof_buffer;
67941 static unsigned long prof_len, prof_shift;
67942
67943 int prof_on __read_mostly;
67944@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
67945 hits[i].pc = 0;
67946 continue;
67947 }
67948- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67949+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67950 hits[i].hits = hits[i].pc = 0;
67951 }
67952 }
67953@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67954 * Add the current hit(s) and flush the write-queue out
67955 * to the global buffer:
67956 */
67957- atomic_add(nr_hits, &prof_buffer[pc]);
67958+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
67959 for (i = 0; i < NR_PROFILE_HIT; ++i) {
67960- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67961+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67962 hits[i].pc = hits[i].hits = 0;
67963 }
67964 out:
67965@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67966 {
67967 unsigned long pc;
67968 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
67969- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67970+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67971 }
67972 #endif /* !CONFIG_SMP */
67973
67974@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
67975 return -EFAULT;
67976 buf++; p++; count--; read++;
67977 }
67978- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
67979+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
67980 if (copy_to_user(buf, (void *)pnt, count))
67981 return -EFAULT;
67982 read += count;
67983@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
67984 }
67985 #endif
67986 profile_discard_flip_buffers();
67987- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
67988+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
67989 return count;
67990 }
67991
67992diff --git a/kernel/ptrace.c b/kernel/ptrace.c
67993index ee8d49b..bd3d790 100644
67994--- a/kernel/ptrace.c
67995+++ b/kernel/ptrace.c
67996@@ -280,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
67997
67998 if (seize)
67999 flags |= PT_SEIZED;
68000- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68001+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68002 flags |= PT_PTRACE_CAP;
68003 task->ptrace = flags;
68004
68005@@ -487,7 +487,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68006 break;
68007 return -EIO;
68008 }
68009- if (copy_to_user(dst, buf, retval))
68010+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68011 return -EFAULT;
68012 copied += retval;
68013 src += retval;
68014@@ -672,7 +672,7 @@ int ptrace_request(struct task_struct *child, long request,
68015 bool seized = child->ptrace & PT_SEIZED;
68016 int ret = -EIO;
68017 siginfo_t siginfo, *si;
68018- void __user *datavp = (void __user *) data;
68019+ void __user *datavp = (__force void __user *) data;
68020 unsigned long __user *datalp = datavp;
68021 unsigned long flags;
68022
68023@@ -874,14 +874,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68024 goto out;
68025 }
68026
68027+ if (gr_handle_ptrace(child, request)) {
68028+ ret = -EPERM;
68029+ goto out_put_task_struct;
68030+ }
68031+
68032 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68033 ret = ptrace_attach(child, request, addr, data);
68034 /*
68035 * Some architectures need to do book-keeping after
68036 * a ptrace attach.
68037 */
68038- if (!ret)
68039+ if (!ret) {
68040 arch_ptrace_attach(child);
68041+ gr_audit_ptrace(child);
68042+ }
68043 goto out_put_task_struct;
68044 }
68045
68046@@ -907,7 +914,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68047 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68048 if (copied != sizeof(tmp))
68049 return -EIO;
68050- return put_user(tmp, (unsigned long __user *)data);
68051+ return put_user(tmp, (__force unsigned long __user *)data);
68052 }
68053
68054 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68055@@ -1017,14 +1024,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68056 goto out;
68057 }
68058
68059+ if (gr_handle_ptrace(child, request)) {
68060+ ret = -EPERM;
68061+ goto out_put_task_struct;
68062+ }
68063+
68064 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68065 ret = ptrace_attach(child, request, addr, data);
68066 /*
68067 * Some architectures need to do book-keeping after
68068 * a ptrace attach.
68069 */
68070- if (!ret)
68071+ if (!ret) {
68072 arch_ptrace_attach(child);
68073+ gr_audit_ptrace(child);
68074+ }
68075 goto out_put_task_struct;
68076 }
68077
68078diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68079index 37a5444..eec170a 100644
68080--- a/kernel/rcutiny.c
68081+++ b/kernel/rcutiny.c
68082@@ -46,7 +46,7 @@
68083 struct rcu_ctrlblk;
68084 static void invoke_rcu_callbacks(void);
68085 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68086-static void rcu_process_callbacks(struct softirq_action *unused);
68087+static void rcu_process_callbacks(void);
68088 static void __call_rcu(struct rcu_head *head,
68089 void (*func)(struct rcu_head *rcu),
68090 struct rcu_ctrlblk *rcp);
68091@@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68092 rcu_is_callbacks_kthread()));
68093 }
68094
68095-static void rcu_process_callbacks(struct softirq_action *unused)
68096+static void rcu_process_callbacks(void)
68097 {
68098 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68099 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68100diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68101index 22ecea0..3789898 100644
68102--- a/kernel/rcutiny_plugin.h
68103+++ b/kernel/rcutiny_plugin.h
68104@@ -955,7 +955,7 @@ static int rcu_kthread(void *arg)
68105 have_rcu_kthread_work = morework;
68106 local_irq_restore(flags);
68107 if (work)
68108- rcu_process_callbacks(NULL);
68109+ rcu_process_callbacks();
68110 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68111 }
68112
68113diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68114index a89b381..efdcad8 100644
68115--- a/kernel/rcutorture.c
68116+++ b/kernel/rcutorture.c
68117@@ -158,12 +158,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68118 { 0 };
68119 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68120 { 0 };
68121-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68122-static atomic_t n_rcu_torture_alloc;
68123-static atomic_t n_rcu_torture_alloc_fail;
68124-static atomic_t n_rcu_torture_free;
68125-static atomic_t n_rcu_torture_mberror;
68126-static atomic_t n_rcu_torture_error;
68127+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68128+static atomic_unchecked_t n_rcu_torture_alloc;
68129+static atomic_unchecked_t n_rcu_torture_alloc_fail;
68130+static atomic_unchecked_t n_rcu_torture_free;
68131+static atomic_unchecked_t n_rcu_torture_mberror;
68132+static atomic_unchecked_t n_rcu_torture_error;
68133 static long n_rcu_torture_boost_ktrerror;
68134 static long n_rcu_torture_boost_rterror;
68135 static long n_rcu_torture_boost_failure;
68136@@ -253,11 +253,11 @@ rcu_torture_alloc(void)
68137
68138 spin_lock_bh(&rcu_torture_lock);
68139 if (list_empty(&rcu_torture_freelist)) {
68140- atomic_inc(&n_rcu_torture_alloc_fail);
68141+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68142 spin_unlock_bh(&rcu_torture_lock);
68143 return NULL;
68144 }
68145- atomic_inc(&n_rcu_torture_alloc);
68146+ atomic_inc_unchecked(&n_rcu_torture_alloc);
68147 p = rcu_torture_freelist.next;
68148 list_del_init(p);
68149 spin_unlock_bh(&rcu_torture_lock);
68150@@ -270,7 +270,7 @@ rcu_torture_alloc(void)
68151 static void
68152 rcu_torture_free(struct rcu_torture *p)
68153 {
68154- atomic_inc(&n_rcu_torture_free);
68155+ atomic_inc_unchecked(&n_rcu_torture_free);
68156 spin_lock_bh(&rcu_torture_lock);
68157 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68158 spin_unlock_bh(&rcu_torture_lock);
68159@@ -390,7 +390,7 @@ rcu_torture_cb(struct rcu_head *p)
68160 i = rp->rtort_pipe_count;
68161 if (i > RCU_TORTURE_PIPE_LEN)
68162 i = RCU_TORTURE_PIPE_LEN;
68163- atomic_inc(&rcu_torture_wcount[i]);
68164+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68165 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68166 rp->rtort_mbtest = 0;
68167 rcu_torture_free(rp);
68168@@ -437,7 +437,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68169 i = rp->rtort_pipe_count;
68170 if (i > RCU_TORTURE_PIPE_LEN)
68171 i = RCU_TORTURE_PIPE_LEN;
68172- atomic_inc(&rcu_torture_wcount[i]);
68173+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68174 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68175 rp->rtort_mbtest = 0;
68176 list_del(&rp->rtort_free);
68177@@ -926,7 +926,7 @@ rcu_torture_writer(void *arg)
68178 i = old_rp->rtort_pipe_count;
68179 if (i > RCU_TORTURE_PIPE_LEN)
68180 i = RCU_TORTURE_PIPE_LEN;
68181- atomic_inc(&rcu_torture_wcount[i]);
68182+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68183 old_rp->rtort_pipe_count++;
68184 cur_ops->deferred_free(old_rp);
68185 }
68186@@ -1007,7 +1007,7 @@ static void rcu_torture_timer(unsigned long unused)
68187 }
68188 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68189 if (p->rtort_mbtest == 0)
68190- atomic_inc(&n_rcu_torture_mberror);
68191+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68192 spin_lock(&rand_lock);
68193 cur_ops->read_delay(&rand);
68194 n_rcu_torture_timers++;
68195@@ -1071,7 +1071,7 @@ rcu_torture_reader(void *arg)
68196 }
68197 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68198 if (p->rtort_mbtest == 0)
68199- atomic_inc(&n_rcu_torture_mberror);
68200+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68201 cur_ops->read_delay(&rand);
68202 preempt_disable();
68203 pipe_count = p->rtort_pipe_count;
68204@@ -1133,10 +1133,10 @@ rcu_torture_printk(char *page)
68205 rcu_torture_current,
68206 rcu_torture_current_version,
68207 list_empty(&rcu_torture_freelist),
68208- atomic_read(&n_rcu_torture_alloc),
68209- atomic_read(&n_rcu_torture_alloc_fail),
68210- atomic_read(&n_rcu_torture_free),
68211- atomic_read(&n_rcu_torture_mberror),
68212+ atomic_read_unchecked(&n_rcu_torture_alloc),
68213+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68214+ atomic_read_unchecked(&n_rcu_torture_free),
68215+ atomic_read_unchecked(&n_rcu_torture_mberror),
68216 n_rcu_torture_boost_ktrerror,
68217 n_rcu_torture_boost_rterror,
68218 n_rcu_torture_boost_failure,
68219@@ -1146,7 +1146,7 @@ rcu_torture_printk(char *page)
68220 n_online_attempts,
68221 n_offline_successes,
68222 n_offline_attempts);
68223- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68224+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68225 n_rcu_torture_boost_ktrerror != 0 ||
68226 n_rcu_torture_boost_rterror != 0 ||
68227 n_rcu_torture_boost_failure != 0)
68228@@ -1154,7 +1154,7 @@ rcu_torture_printk(char *page)
68229 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68230 if (i > 1) {
68231 cnt += sprintf(&page[cnt], "!!! ");
68232- atomic_inc(&n_rcu_torture_error);
68233+ atomic_inc_unchecked(&n_rcu_torture_error);
68234 WARN_ON_ONCE(1);
68235 }
68236 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68237@@ -1168,7 +1168,7 @@ rcu_torture_printk(char *page)
68238 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68239 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68240 cnt += sprintf(&page[cnt], " %d",
68241- atomic_read(&rcu_torture_wcount[i]));
68242+ atomic_read_unchecked(&rcu_torture_wcount[i]));
68243 }
68244 cnt += sprintf(&page[cnt], "\n");
68245 if (cur_ops->stats)
68246@@ -1676,7 +1676,7 @@ rcu_torture_cleanup(void)
68247
68248 if (cur_ops->cleanup)
68249 cur_ops->cleanup();
68250- if (atomic_read(&n_rcu_torture_error))
68251+ if (atomic_read_unchecked(&n_rcu_torture_error))
68252 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68253 else if (n_online_successes != n_online_attempts ||
68254 n_offline_successes != n_offline_attempts)
68255@@ -1744,17 +1744,17 @@ rcu_torture_init(void)
68256
68257 rcu_torture_current = NULL;
68258 rcu_torture_current_version = 0;
68259- atomic_set(&n_rcu_torture_alloc, 0);
68260- atomic_set(&n_rcu_torture_alloc_fail, 0);
68261- atomic_set(&n_rcu_torture_free, 0);
68262- atomic_set(&n_rcu_torture_mberror, 0);
68263- atomic_set(&n_rcu_torture_error, 0);
68264+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68265+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68266+ atomic_set_unchecked(&n_rcu_torture_free, 0);
68267+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68268+ atomic_set_unchecked(&n_rcu_torture_error, 0);
68269 n_rcu_torture_boost_ktrerror = 0;
68270 n_rcu_torture_boost_rterror = 0;
68271 n_rcu_torture_boost_failure = 0;
68272 n_rcu_torture_boosts = 0;
68273 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68274- atomic_set(&rcu_torture_wcount[i], 0);
68275+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68276 for_each_possible_cpu(cpu) {
68277 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68278 per_cpu(rcu_torture_count, cpu)[i] = 0;
68279diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68280index d0c5baf..109b2e7 100644
68281--- a/kernel/rcutree.c
68282+++ b/kernel/rcutree.c
68283@@ -357,9 +357,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68284 rcu_prepare_for_idle(smp_processor_id());
68285 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68286 smp_mb__before_atomic_inc(); /* See above. */
68287- atomic_inc(&rdtp->dynticks);
68288+ atomic_inc_unchecked(&rdtp->dynticks);
68289 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68290- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68291+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68292
68293 /*
68294 * The idle task is not permitted to enter the idle loop while
68295@@ -448,10 +448,10 @@ void rcu_irq_exit(void)
68296 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68297 {
68298 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68299- atomic_inc(&rdtp->dynticks);
68300+ atomic_inc_unchecked(&rdtp->dynticks);
68301 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68302 smp_mb__after_atomic_inc(); /* See above. */
68303- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68304+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68305 rcu_cleanup_after_idle(smp_processor_id());
68306 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68307 if (!is_idle_task(current)) {
68308@@ -545,14 +545,14 @@ void rcu_nmi_enter(void)
68309 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68310
68311 if (rdtp->dynticks_nmi_nesting == 0 &&
68312- (atomic_read(&rdtp->dynticks) & 0x1))
68313+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68314 return;
68315 rdtp->dynticks_nmi_nesting++;
68316 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68317- atomic_inc(&rdtp->dynticks);
68318+ atomic_inc_unchecked(&rdtp->dynticks);
68319 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68320 smp_mb__after_atomic_inc(); /* See above. */
68321- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68322+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68323 }
68324
68325 /**
68326@@ -571,9 +571,9 @@ void rcu_nmi_exit(void)
68327 return;
68328 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68329 smp_mb__before_atomic_inc(); /* See above. */
68330- atomic_inc(&rdtp->dynticks);
68331+ atomic_inc_unchecked(&rdtp->dynticks);
68332 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68333- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68334+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68335 }
68336
68337 #ifdef CONFIG_PROVE_RCU
68338@@ -589,7 +589,7 @@ int rcu_is_cpu_idle(void)
68339 int ret;
68340
68341 preempt_disable();
68342- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68343+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68344 preempt_enable();
68345 return ret;
68346 }
68347@@ -659,7 +659,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68348 */
68349 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68350 {
68351- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68352+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68353 return (rdp->dynticks_snap & 0x1) == 0;
68354 }
68355
68356@@ -674,7 +674,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68357 unsigned int curr;
68358 unsigned int snap;
68359
68360- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68361+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68362 snap = (unsigned int)rdp->dynticks_snap;
68363
68364 /*
68365@@ -704,10 +704,10 @@ static int jiffies_till_stall_check(void)
68366 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
68367 */
68368 if (till_stall_check < 3) {
68369- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
68370+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
68371 till_stall_check = 3;
68372 } else if (till_stall_check > 300) {
68373- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
68374+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
68375 till_stall_check = 300;
68376 }
68377 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
68378@@ -1766,7 +1766,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68379 /*
68380 * Do RCU core processing for the current CPU.
68381 */
68382-static void rcu_process_callbacks(struct softirq_action *unused)
68383+static void rcu_process_callbacks(void)
68384 {
68385 trace_rcu_utilization("Start RCU core");
68386 __rcu_process_callbacks(&rcu_sched_state,
68387@@ -1949,8 +1949,8 @@ void synchronize_rcu_bh(void)
68388 }
68389 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
68390
68391-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68392-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68393+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68394+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68395
68396 static int synchronize_sched_expedited_cpu_stop(void *data)
68397 {
68398@@ -2011,7 +2011,7 @@ void synchronize_sched_expedited(void)
68399 int firstsnap, s, snap, trycount = 0;
68400
68401 /* Note that atomic_inc_return() implies full memory barrier. */
68402- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68403+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68404 get_online_cpus();
68405 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
68406
68407@@ -2033,7 +2033,7 @@ void synchronize_sched_expedited(void)
68408 }
68409
68410 /* Check to see if someone else did our work for us. */
68411- s = atomic_read(&sync_sched_expedited_done);
68412+ s = atomic_read_unchecked(&sync_sched_expedited_done);
68413 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68414 smp_mb(); /* ensure test happens before caller kfree */
68415 return;
68416@@ -2048,7 +2048,7 @@ void synchronize_sched_expedited(void)
68417 * grace period works for us.
68418 */
68419 get_online_cpus();
68420- snap = atomic_read(&sync_sched_expedited_started);
68421+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
68422 smp_mb(); /* ensure read is before try_stop_cpus(). */
68423 }
68424
68425@@ -2059,12 +2059,12 @@ void synchronize_sched_expedited(void)
68426 * than we did beat us to the punch.
68427 */
68428 do {
68429- s = atomic_read(&sync_sched_expedited_done);
68430+ s = atomic_read_unchecked(&sync_sched_expedited_done);
68431 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68432 smp_mb(); /* ensure test happens before caller kfree */
68433 break;
68434 }
68435- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68436+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68437
68438 put_online_cpus();
68439 }
68440@@ -2262,7 +2262,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68441 rdp->qlen = 0;
68442 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68443 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
68444- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
68445+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
68446 rdp->cpu = cpu;
68447 rdp->rsp = rsp;
68448 raw_spin_unlock_irqrestore(&rnp->lock, flags);
68449@@ -2290,8 +2290,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
68450 rdp->n_force_qs_snap = rsp->n_force_qs;
68451 rdp->blimit = blimit;
68452 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
68453- atomic_set(&rdp->dynticks->dynticks,
68454- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
68455+ atomic_set_unchecked(&rdp->dynticks->dynticks,
68456+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
68457 rcu_prepare_for_idle_init(cpu);
68458 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
68459
68460diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68461index cdd1be0..5b2efb4 100644
68462--- a/kernel/rcutree.h
68463+++ b/kernel/rcutree.h
68464@@ -87,7 +87,7 @@ struct rcu_dynticks {
68465 long long dynticks_nesting; /* Track irq/process nesting level. */
68466 /* Process level is worth LLONG_MAX/2. */
68467 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68468- atomic_t dynticks; /* Even value for idle, else odd. */
68469+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
68470 };
68471
68472 /* RCU's kthread states for tracing. */
68473diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68474index c023464..7f57225 100644
68475--- a/kernel/rcutree_plugin.h
68476+++ b/kernel/rcutree_plugin.h
68477@@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
68478
68479 /* Clean up and exit. */
68480 smp_mb(); /* ensure expedited GP seen before counter increment. */
68481- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68482+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68483 unlock_mb_ret:
68484 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68485 mb_ret:
68486diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68487index ed459ed..a03c3fa 100644
68488--- a/kernel/rcutree_trace.c
68489+++ b/kernel/rcutree_trace.c
68490@@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68491 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68492 rdp->qs_pending);
68493 seq_printf(m, " dt=%d/%llx/%d df=%lu",
68494- atomic_read(&rdp->dynticks->dynticks),
68495+ atomic_read_unchecked(&rdp->dynticks->dynticks),
68496 rdp->dynticks->dynticks_nesting,
68497 rdp->dynticks->dynticks_nmi_nesting,
68498 rdp->dynticks_fqs);
68499@@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68500 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68501 rdp->qs_pending);
68502 seq_printf(m, ",%d,%llx,%d,%lu",
68503- atomic_read(&rdp->dynticks->dynticks),
68504+ atomic_read_unchecked(&rdp->dynticks->dynticks),
68505 rdp->dynticks->dynticks_nesting,
68506 rdp->dynticks->dynticks_nmi_nesting,
68507 rdp->dynticks_fqs);
68508diff --git a/kernel/resource.c b/kernel/resource.c
68509index 7e8ea66..1efd11f 100644
68510--- a/kernel/resource.c
68511+++ b/kernel/resource.c
68512@@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68513
68514 static int __init ioresources_init(void)
68515 {
68516+#ifdef CONFIG_GRKERNSEC_PROC_ADD
68517+#ifdef CONFIG_GRKERNSEC_PROC_USER
68518+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68519+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68520+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68521+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68522+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68523+#endif
68524+#else
68525 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68526 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68527+#endif
68528 return 0;
68529 }
68530 __initcall(ioresources_init);
68531diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68532index 98ec494..4241d6d 100644
68533--- a/kernel/rtmutex-tester.c
68534+++ b/kernel/rtmutex-tester.c
68535@@ -20,7 +20,7 @@
68536 #define MAX_RT_TEST_MUTEXES 8
68537
68538 static spinlock_t rttest_lock;
68539-static atomic_t rttest_event;
68540+static atomic_unchecked_t rttest_event;
68541
68542 struct test_thread_data {
68543 int opcode;
68544@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68545
68546 case RTTEST_LOCKCONT:
68547 td->mutexes[td->opdata] = 1;
68548- td->event = atomic_add_return(1, &rttest_event);
68549+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68550 return 0;
68551
68552 case RTTEST_RESET:
68553@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68554 return 0;
68555
68556 case RTTEST_RESETEVENT:
68557- atomic_set(&rttest_event, 0);
68558+ atomic_set_unchecked(&rttest_event, 0);
68559 return 0;
68560
68561 default:
68562@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68563 return ret;
68564
68565 td->mutexes[id] = 1;
68566- td->event = atomic_add_return(1, &rttest_event);
68567+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68568 rt_mutex_lock(&mutexes[id]);
68569- td->event = atomic_add_return(1, &rttest_event);
68570+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68571 td->mutexes[id] = 4;
68572 return 0;
68573
68574@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68575 return ret;
68576
68577 td->mutexes[id] = 1;
68578- td->event = atomic_add_return(1, &rttest_event);
68579+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68580 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
68581- td->event = atomic_add_return(1, &rttest_event);
68582+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68583 td->mutexes[id] = ret ? 0 : 4;
68584 return ret ? -EINTR : 0;
68585
68586@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68587 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
68588 return ret;
68589
68590- td->event = atomic_add_return(1, &rttest_event);
68591+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68592 rt_mutex_unlock(&mutexes[id]);
68593- td->event = atomic_add_return(1, &rttest_event);
68594+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68595 td->mutexes[id] = 0;
68596 return 0;
68597
68598@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68599 break;
68600
68601 td->mutexes[dat] = 2;
68602- td->event = atomic_add_return(1, &rttest_event);
68603+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68604 break;
68605
68606 default:
68607@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68608 return;
68609
68610 td->mutexes[dat] = 3;
68611- td->event = atomic_add_return(1, &rttest_event);
68612+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68613 break;
68614
68615 case RTTEST_LOCKNOWAIT:
68616@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68617 return;
68618
68619 td->mutexes[dat] = 1;
68620- td->event = atomic_add_return(1, &rttest_event);
68621+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68622 return;
68623
68624 default:
68625diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
68626index 0984a21..939f183 100644
68627--- a/kernel/sched/auto_group.c
68628+++ b/kernel/sched/auto_group.c
68629@@ -11,7 +11,7 @@
68630
68631 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
68632 static struct autogroup autogroup_default;
68633-static atomic_t autogroup_seq_nr;
68634+static atomic_unchecked_t autogroup_seq_nr;
68635
68636 void __init autogroup_init(struct task_struct *init_task)
68637 {
68638@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
68639
68640 kref_init(&ag->kref);
68641 init_rwsem(&ag->lock);
68642- ag->id = atomic_inc_return(&autogroup_seq_nr);
68643+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
68644 ag->tg = tg;
68645 #ifdef CONFIG_RT_GROUP_SCHED
68646 /*
68647diff --git a/kernel/sched/core.c b/kernel/sched/core.c
68648index 817bf70..9099fb4 100644
68649--- a/kernel/sched/core.c
68650+++ b/kernel/sched/core.c
68651@@ -4038,6 +4038,8 @@ int can_nice(const struct task_struct *p, const int nice)
68652 /* convert nice value [19,-20] to rlimit style value [1,40] */
68653 int nice_rlim = 20 - nice;
68654
68655+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
68656+
68657 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
68658 capable(CAP_SYS_NICE));
68659 }
68660@@ -4071,7 +4073,8 @@ SYSCALL_DEFINE1(nice, int, increment)
68661 if (nice > 19)
68662 nice = 19;
68663
68664- if (increment < 0 && !can_nice(current, nice))
68665+ if (increment < 0 && (!can_nice(current, nice) ||
68666+ gr_handle_chroot_nice()))
68667 return -EPERM;
68668
68669 retval = security_task_setnice(current, nice);
68670@@ -4228,6 +4231,7 @@ recheck:
68671 unsigned long rlim_rtprio =
68672 task_rlimit(p, RLIMIT_RTPRIO);
68673
68674+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
68675 /* can't set/change the rt policy */
68676 if (policy != p->policy && !rlim_rtprio)
68677 return -EPERM;
68678diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
68679index e955364..eacd2a4 100644
68680--- a/kernel/sched/fair.c
68681+++ b/kernel/sched/fair.c
68682@@ -5107,7 +5107,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
68683 * run_rebalance_domains is triggered when needed from the scheduler tick.
68684 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
68685 */
68686-static void run_rebalance_domains(struct softirq_action *h)
68687+static void run_rebalance_domains(void)
68688 {
68689 int this_cpu = smp_processor_id();
68690 struct rq *this_rq = cpu_rq(this_cpu);
68691diff --git a/kernel/signal.c b/kernel/signal.c
68692index 17afcaf..4500b05 100644
68693--- a/kernel/signal.c
68694+++ b/kernel/signal.c
68695@@ -47,12 +47,12 @@ static struct kmem_cache *sigqueue_cachep;
68696
68697 int print_fatal_signals __read_mostly;
68698
68699-static void __user *sig_handler(struct task_struct *t, int sig)
68700+static __sighandler_t sig_handler(struct task_struct *t, int sig)
68701 {
68702 return t->sighand->action[sig - 1].sa.sa_handler;
68703 }
68704
68705-static int sig_handler_ignored(void __user *handler, int sig)
68706+static int sig_handler_ignored(__sighandler_t handler, int sig)
68707 {
68708 /* Is it explicitly or implicitly ignored? */
68709 return handler == SIG_IGN ||
68710@@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
68711
68712 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
68713 {
68714- void __user *handler;
68715+ __sighandler_t handler;
68716
68717 handler = sig_handler(t, sig);
68718
68719@@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
68720 atomic_inc(&user->sigpending);
68721 rcu_read_unlock();
68722
68723+ if (!override_rlimit)
68724+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
68725+
68726 if (override_rlimit ||
68727 atomic_read(&user->sigpending) <=
68728 task_rlimit(t, RLIMIT_SIGPENDING)) {
68729@@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
68730
68731 int unhandled_signal(struct task_struct *tsk, int sig)
68732 {
68733- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
68734+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
68735 if (is_global_init(tsk))
68736 return 1;
68737 if (handler != SIG_IGN && handler != SIG_DFL)
68738@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
68739 }
68740 }
68741
68742+ /* allow glibc communication via tgkill to other threads in our
68743+ thread group */
68744+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
68745+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
68746+ && gr_handle_signal(t, sig))
68747+ return -EPERM;
68748+
68749 return security_task_kill(t, info, sig, 0);
68750 }
68751
68752@@ -1204,7 +1214,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68753 return send_signal(sig, info, p, 1);
68754 }
68755
68756-static int
68757+int
68758 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68759 {
68760 return send_signal(sig, info, t, 0);
68761@@ -1241,6 +1251,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68762 unsigned long int flags;
68763 int ret, blocked, ignored;
68764 struct k_sigaction *action;
68765+ int is_unhandled = 0;
68766
68767 spin_lock_irqsave(&t->sighand->siglock, flags);
68768 action = &t->sighand->action[sig-1];
68769@@ -1255,9 +1266,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68770 }
68771 if (action->sa.sa_handler == SIG_DFL)
68772 t->signal->flags &= ~SIGNAL_UNKILLABLE;
68773+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
68774+ is_unhandled = 1;
68775 ret = specific_send_sig_info(sig, info, t);
68776 spin_unlock_irqrestore(&t->sighand->siglock, flags);
68777
68778+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
68779+ normal operation */
68780+ if (is_unhandled) {
68781+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
68782+ gr_handle_crash(t, sig);
68783+ }
68784+
68785 return ret;
68786 }
68787
68788@@ -1324,8 +1344,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68789 ret = check_kill_permission(sig, info, p);
68790 rcu_read_unlock();
68791
68792- if (!ret && sig)
68793+ if (!ret && sig) {
68794 ret = do_send_sig_info(sig, info, p, true);
68795+ if (!ret)
68796+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
68797+ }
68798
68799 return ret;
68800 }
68801@@ -2840,7 +2863,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68802 int error = -ESRCH;
68803
68804 rcu_read_lock();
68805- p = find_task_by_vpid(pid);
68806+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68807+ /* allow glibc communication via tgkill to other threads in our
68808+ thread group */
68809+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68810+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
68811+ p = find_task_by_vpid_unrestricted(pid);
68812+ else
68813+#endif
68814+ p = find_task_by_vpid(pid);
68815 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68816 error = check_kill_permission(sig, info, p);
68817 /*
68818diff --git a/kernel/smp.c b/kernel/smp.c
68819index 2f8b10e..a41bc14 100644
68820--- a/kernel/smp.c
68821+++ b/kernel/smp.c
68822@@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68823 }
68824 EXPORT_SYMBOL(smp_call_function);
68825
68826-void ipi_call_lock(void)
68827+void ipi_call_lock(void) __acquires(call_function.lock)
68828 {
68829 raw_spin_lock(&call_function.lock);
68830 }
68831
68832-void ipi_call_unlock(void)
68833+void ipi_call_unlock(void) __releases(call_function.lock)
68834 {
68835 raw_spin_unlock(&call_function.lock);
68836 }
68837
68838-void ipi_call_lock_irq(void)
68839+void ipi_call_lock_irq(void) __acquires(call_function.lock)
68840 {
68841 raw_spin_lock_irq(&call_function.lock);
68842 }
68843
68844-void ipi_call_unlock_irq(void)
68845+void ipi_call_unlock_irq(void) __releases(call_function.lock)
68846 {
68847 raw_spin_unlock_irq(&call_function.lock);
68848 }
68849diff --git a/kernel/softirq.c b/kernel/softirq.c
68850index 671f959..91c51cb 100644
68851--- a/kernel/softirq.c
68852+++ b/kernel/softirq.c
68853@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
68854
68855 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
68856
68857-char *softirq_to_name[NR_SOFTIRQS] = {
68858+const char * const softirq_to_name[NR_SOFTIRQS] = {
68859 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
68860 "TASKLET", "SCHED", "HRTIMER", "RCU"
68861 };
68862@@ -235,7 +235,7 @@ restart:
68863 kstat_incr_softirqs_this_cpu(vec_nr);
68864
68865 trace_softirq_entry(vec_nr);
68866- h->action(h);
68867+ h->action();
68868 trace_softirq_exit(vec_nr);
68869 if (unlikely(prev_count != preempt_count())) {
68870 printk(KERN_ERR "huh, entered softirq %u %s %p"
68871@@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
68872 or_softirq_pending(1UL << nr);
68873 }
68874
68875-void open_softirq(int nr, void (*action)(struct softirq_action *))
68876+void open_softirq(int nr, void (*action)(void))
68877 {
68878- softirq_vec[nr].action = action;
68879+ pax_open_kernel();
68880+ *(void **)&softirq_vec[nr].action = action;
68881+ pax_close_kernel();
68882 }
68883
68884 /*
68885@@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
68886
68887 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
68888
68889-static void tasklet_action(struct softirq_action *a)
68890+static void tasklet_action(void)
68891 {
68892 struct tasklet_struct *list;
68893
68894@@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
68895 }
68896 }
68897
68898-static void tasklet_hi_action(struct softirq_action *a)
68899+static void tasklet_hi_action(void)
68900 {
68901 struct tasklet_struct *list;
68902
68903diff --git a/kernel/sys.c b/kernel/sys.c
68904index e7006eb..8fb7c51 100644
68905--- a/kernel/sys.c
68906+++ b/kernel/sys.c
68907@@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
68908 error = -EACCES;
68909 goto out;
68910 }
68911+
68912+ if (gr_handle_chroot_setpriority(p, niceval)) {
68913+ error = -EACCES;
68914+ goto out;
68915+ }
68916+
68917 no_nice = security_task_setnice(p, niceval);
68918 if (no_nice) {
68919 error = no_nice;
68920@@ -581,6 +587,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
68921 goto error;
68922 }
68923
68924+ if (gr_check_group_change(new->gid, new->egid, -1))
68925+ goto error;
68926+
68927 if (rgid != (gid_t) -1 ||
68928 (egid != (gid_t) -1 && egid != old->gid))
68929 new->sgid = new->egid;
68930@@ -610,6 +619,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
68931 old = current_cred();
68932
68933 retval = -EPERM;
68934+
68935+ if (gr_check_group_change(gid, gid, gid))
68936+ goto error;
68937+
68938 if (nsown_capable(CAP_SETGID))
68939 new->gid = new->egid = new->sgid = new->fsgid = gid;
68940 else if (gid == old->gid || gid == old->sgid)
68941@@ -627,7 +640,7 @@ error:
68942 /*
68943 * change the user struct in a credentials set to match the new UID
68944 */
68945-static int set_user(struct cred *new)
68946+int set_user(struct cred *new)
68947 {
68948 struct user_struct *new_user;
68949
68950@@ -697,6 +710,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
68951 goto error;
68952 }
68953
68954+ if (gr_check_user_change(new->uid, new->euid, -1))
68955+ goto error;
68956+
68957 if (new->uid != old->uid) {
68958 retval = set_user(new);
68959 if (retval < 0)
68960@@ -741,6 +757,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
68961 old = current_cred();
68962
68963 retval = -EPERM;
68964+
68965+ if (gr_check_crash_uid(uid))
68966+ goto error;
68967+ if (gr_check_user_change(uid, uid, uid))
68968+ goto error;
68969+
68970 if (nsown_capable(CAP_SETUID)) {
68971 new->suid = new->uid = uid;
68972 if (uid != old->uid) {
68973@@ -795,6 +817,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
68974 goto error;
68975 }
68976
68977+ if (gr_check_user_change(ruid, euid, -1))
68978+ goto error;
68979+
68980 if (ruid != (uid_t) -1) {
68981 new->uid = ruid;
68982 if (ruid != old->uid) {
68983@@ -859,6 +884,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
68984 goto error;
68985 }
68986
68987+ if (gr_check_group_change(rgid, egid, -1))
68988+ goto error;
68989+
68990 if (rgid != (gid_t) -1)
68991 new->gid = rgid;
68992 if (egid != (gid_t) -1)
68993@@ -905,6 +933,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68994 old = current_cred();
68995 old_fsuid = old->fsuid;
68996
68997+ if (gr_check_user_change(-1, -1, uid))
68998+ goto error;
68999+
69000 if (uid == old->uid || uid == old->euid ||
69001 uid == old->suid || uid == old->fsuid ||
69002 nsown_capable(CAP_SETUID)) {
69003@@ -915,6 +946,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69004 }
69005 }
69006
69007+error:
69008 abort_creds(new);
69009 return old_fsuid;
69010
69011@@ -941,12 +973,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69012 if (gid == old->gid || gid == old->egid ||
69013 gid == old->sgid || gid == old->fsgid ||
69014 nsown_capable(CAP_SETGID)) {
69015+ if (gr_check_group_change(-1, -1, gid))
69016+ goto error;
69017+
69018 if (gid != old_fsgid) {
69019 new->fsgid = gid;
69020 goto change_okay;
69021 }
69022 }
69023
69024+error:
69025 abort_creds(new);
69026 return old_fsgid;
69027
69028@@ -1198,7 +1234,10 @@ static int override_release(char __user *release, int len)
69029 }
69030 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69031 snprintf(buf, len, "2.6.%u%s", v, rest);
69032- ret = copy_to_user(release, buf, len);
69033+ if (len > sizeof(buf))
69034+ ret = -EFAULT;
69035+ else
69036+ ret = copy_to_user(release, buf, len);
69037 }
69038 return ret;
69039 }
69040@@ -1252,19 +1291,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69041 return -EFAULT;
69042
69043 down_read(&uts_sem);
69044- error = __copy_to_user(&name->sysname, &utsname()->sysname,
69045+ error = __copy_to_user(name->sysname, &utsname()->sysname,
69046 __OLD_UTS_LEN);
69047 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69048- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69049+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
69050 __OLD_UTS_LEN);
69051 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69052- error |= __copy_to_user(&name->release, &utsname()->release,
69053+ error |= __copy_to_user(name->release, &utsname()->release,
69054 __OLD_UTS_LEN);
69055 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69056- error |= __copy_to_user(&name->version, &utsname()->version,
69057+ error |= __copy_to_user(name->version, &utsname()->version,
69058 __OLD_UTS_LEN);
69059 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69060- error |= __copy_to_user(&name->machine, &utsname()->machine,
69061+ error |= __copy_to_user(name->machine, &utsname()->machine,
69062 __OLD_UTS_LEN);
69063 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69064 up_read(&uts_sem);
69065@@ -1847,7 +1886,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69066 error = get_dumpable(me->mm);
69067 break;
69068 case PR_SET_DUMPABLE:
69069- if (arg2 < 0 || arg2 > 1) {
69070+ if (arg2 > 1) {
69071 error = -EINVAL;
69072 break;
69073 }
69074diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69075index 4ab1187..33f4f2b 100644
69076--- a/kernel/sysctl.c
69077+++ b/kernel/sysctl.c
69078@@ -91,7 +91,6 @@
69079
69080
69081 #if defined(CONFIG_SYSCTL)
69082-
69083 /* External variables not in a header file. */
69084 extern int sysctl_overcommit_memory;
69085 extern int sysctl_overcommit_ratio;
69086@@ -169,10 +168,13 @@ static int proc_taint(struct ctl_table *table, int write,
69087 void __user *buffer, size_t *lenp, loff_t *ppos);
69088 #endif
69089
69090-#ifdef CONFIG_PRINTK
69091 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69092 void __user *buffer, size_t *lenp, loff_t *ppos);
69093-#endif
69094+
69095+static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69096+ void __user *buffer, size_t *lenp, loff_t *ppos);
69097+static int proc_dostring_coredump(struct ctl_table *table, int write,
69098+ void __user *buffer, size_t *lenp, loff_t *ppos);
69099
69100 #ifdef CONFIG_MAGIC_SYSRQ
69101 /* Note: sysrq code uses it's own private copy */
69102@@ -196,6 +198,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69103
69104 #endif
69105
69106+extern struct ctl_table grsecurity_table[];
69107+
69108 static struct ctl_table kern_table[];
69109 static struct ctl_table vm_table[];
69110 static struct ctl_table fs_table[];
69111@@ -210,6 +214,20 @@ extern struct ctl_table epoll_table[];
69112 int sysctl_legacy_va_layout;
69113 #endif
69114
69115+#ifdef CONFIG_PAX_SOFTMODE
69116+static ctl_table pax_table[] = {
69117+ {
69118+ .procname = "softmode",
69119+ .data = &pax_softmode,
69120+ .maxlen = sizeof(unsigned int),
69121+ .mode = 0600,
69122+ .proc_handler = &proc_dointvec,
69123+ },
69124+
69125+ { }
69126+};
69127+#endif
69128+
69129 /* The default sysctl tables: */
69130
69131 static struct ctl_table sysctl_base_table[] = {
69132@@ -256,6 +274,22 @@ static int max_extfrag_threshold = 1000;
69133 #endif
69134
69135 static struct ctl_table kern_table[] = {
69136+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69137+ {
69138+ .procname = "grsecurity",
69139+ .mode = 0500,
69140+ .child = grsecurity_table,
69141+ },
69142+#endif
69143+
69144+#ifdef CONFIG_PAX_SOFTMODE
69145+ {
69146+ .procname = "pax",
69147+ .mode = 0500,
69148+ .child = pax_table,
69149+ },
69150+#endif
69151+
69152 {
69153 .procname = "sched_child_runs_first",
69154 .data = &sysctl_sched_child_runs_first,
69155@@ -410,7 +444,7 @@ static struct ctl_table kern_table[] = {
69156 .data = core_pattern,
69157 .maxlen = CORENAME_MAX_SIZE,
69158 .mode = 0644,
69159- .proc_handler = proc_dostring,
69160+ .proc_handler = proc_dostring_coredump,
69161 },
69162 {
69163 .procname = "core_pipe_limit",
69164@@ -540,7 +574,7 @@ static struct ctl_table kern_table[] = {
69165 .data = &modprobe_path,
69166 .maxlen = KMOD_PATH_LEN,
69167 .mode = 0644,
69168- .proc_handler = proc_dostring,
69169+ .proc_handler = proc_dostring_modpriv,
69170 },
69171 {
69172 .procname = "modules_disabled",
69173@@ -707,16 +741,20 @@ static struct ctl_table kern_table[] = {
69174 .extra1 = &zero,
69175 .extra2 = &one,
69176 },
69177+#endif
69178 {
69179 .procname = "kptr_restrict",
69180 .data = &kptr_restrict,
69181 .maxlen = sizeof(int),
69182 .mode = 0644,
69183 .proc_handler = proc_dointvec_minmax_sysadmin,
69184+#ifdef CONFIG_GRKERNSEC_HIDESYM
69185+ .extra1 = &two,
69186+#else
69187 .extra1 = &zero,
69188+#endif
69189 .extra2 = &two,
69190 },
69191-#endif
69192 {
69193 .procname = "ngroups_max",
69194 .data = &ngroups_max,
69195@@ -1215,6 +1253,13 @@ static struct ctl_table vm_table[] = {
69196 .proc_handler = proc_dointvec_minmax,
69197 .extra1 = &zero,
69198 },
69199+ {
69200+ .procname = "heap_stack_gap",
69201+ .data = &sysctl_heap_stack_gap,
69202+ .maxlen = sizeof(sysctl_heap_stack_gap),
69203+ .mode = 0644,
69204+ .proc_handler = proc_doulongvec_minmax,
69205+ },
69206 #else
69207 {
69208 .procname = "nr_trim_pages",
69209@@ -1498,7 +1543,7 @@ static struct ctl_table fs_table[] = {
69210 .data = &suid_dumpable,
69211 .maxlen = sizeof(int),
69212 .mode = 0644,
69213- .proc_handler = proc_dointvec_minmax,
69214+ .proc_handler = proc_dointvec_minmax_coredump,
69215 .extra1 = &zero,
69216 .extra2 = &two,
69217 },
69218@@ -1645,6 +1690,16 @@ int proc_dostring(struct ctl_table *table, int write,
69219 buffer, lenp, ppos);
69220 }
69221
69222+int proc_dostring_modpriv(struct ctl_table *table, int write,
69223+ void __user *buffer, size_t *lenp, loff_t *ppos)
69224+{
69225+ if (write && !capable(CAP_SYS_MODULE))
69226+ return -EPERM;
69227+
69228+ return _proc_do_string(table->data, table->maxlen, write,
69229+ buffer, lenp, ppos);
69230+}
69231+
69232 static size_t proc_skip_spaces(char **buf)
69233 {
69234 size_t ret;
69235@@ -1750,6 +1805,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69236 len = strlen(tmp);
69237 if (len > *size)
69238 len = *size;
69239+ if (len > sizeof(tmp))
69240+ len = sizeof(tmp);
69241 if (copy_to_user(*buf, tmp, len))
69242 return -EFAULT;
69243 *size -= len;
69244@@ -1942,7 +1999,6 @@ static int proc_taint(struct ctl_table *table, int write,
69245 return err;
69246 }
69247
69248-#ifdef CONFIG_PRINTK
69249 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69250 void __user *buffer, size_t *lenp, loff_t *ppos)
69251 {
69252@@ -1951,7 +2007,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69253
69254 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69255 }
69256-#endif
69257
69258 struct do_proc_dointvec_minmax_conv_param {
69259 int *min;
69260@@ -2009,6 +2064,34 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
69261 do_proc_dointvec_minmax_conv, &param);
69262 }
69263
69264+static void validate_coredump_safety(void)
69265+{
69266+ if (suid_dumpable == SUID_DUMPABLE_SAFE &&
69267+ core_pattern[0] != '/' && core_pattern[0] != '|') {
69268+ printk(KERN_WARNING "Unsafe core_pattern used with "\
69269+ "suid_dumpable=2. Pipe handler or fully qualified "\
69270+ "core dump path required.\n");
69271+ }
69272+}
69273+
69274+static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69275+ void __user *buffer, size_t *lenp, loff_t *ppos)
69276+{
69277+ int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69278+ if (!error)
69279+ validate_coredump_safety();
69280+ return error;
69281+}
69282+
69283+static int proc_dostring_coredump(struct ctl_table *table, int write,
69284+ void __user *buffer, size_t *lenp, loff_t *ppos)
69285+{
69286+ int error = proc_dostring(table, write, buffer, lenp, ppos);
69287+ if (!error)
69288+ validate_coredump_safety();
69289+ return error;
69290+}
69291+
69292 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
69293 void __user *buffer,
69294 size_t *lenp, loff_t *ppos,
69295@@ -2066,8 +2149,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69296 *i = val;
69297 } else {
69298 val = convdiv * (*i) / convmul;
69299- if (!first)
69300+ if (!first) {
69301 err = proc_put_char(&buffer, &left, '\t');
69302+ if (err)
69303+ break;
69304+ }
69305 err = proc_put_long(&buffer, &left, val, false);
69306 if (err)
69307 break;
69308@@ -2459,6 +2545,12 @@ int proc_dostring(struct ctl_table *table, int write,
69309 return -ENOSYS;
69310 }
69311
69312+int proc_dostring_modpriv(struct ctl_table *table, int write,
69313+ void __user *buffer, size_t *lenp, loff_t *ppos)
69314+{
69315+ return -ENOSYS;
69316+}
69317+
69318 int proc_dointvec(struct ctl_table *table, int write,
69319 void __user *buffer, size_t *lenp, loff_t *ppos)
69320 {
69321@@ -2515,5 +2607,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69322 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69323 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69324 EXPORT_SYMBOL(proc_dostring);
69325+EXPORT_SYMBOL(proc_dostring_modpriv);
69326 EXPORT_SYMBOL(proc_doulongvec_minmax);
69327 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69328diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69329index a650694..aaeeb20 100644
69330--- a/kernel/sysctl_binary.c
69331+++ b/kernel/sysctl_binary.c
69332@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69333 int i;
69334
69335 set_fs(KERNEL_DS);
69336- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69337+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69338 set_fs(old_fs);
69339 if (result < 0)
69340 goto out_kfree;
69341@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69342 }
69343
69344 set_fs(KERNEL_DS);
69345- result = vfs_write(file, buffer, str - buffer, &pos);
69346+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69347 set_fs(old_fs);
69348 if (result < 0)
69349 goto out_kfree;
69350@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69351 int i;
69352
69353 set_fs(KERNEL_DS);
69354- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69355+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69356 set_fs(old_fs);
69357 if (result < 0)
69358 goto out_kfree;
69359@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69360 }
69361
69362 set_fs(KERNEL_DS);
69363- result = vfs_write(file, buffer, str - buffer, &pos);
69364+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69365 set_fs(old_fs);
69366 if (result < 0)
69367 goto out_kfree;
69368@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69369 int i;
69370
69371 set_fs(KERNEL_DS);
69372- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69373+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69374 set_fs(old_fs);
69375 if (result < 0)
69376 goto out;
69377@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69378 __le16 dnaddr;
69379
69380 set_fs(KERNEL_DS);
69381- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69382+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69383 set_fs(old_fs);
69384 if (result < 0)
69385 goto out;
69386@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69387 le16_to_cpu(dnaddr) & 0x3ff);
69388
69389 set_fs(KERNEL_DS);
69390- result = vfs_write(file, buf, len, &pos);
69391+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69392 set_fs(old_fs);
69393 if (result < 0)
69394 goto out;
69395diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69396index e660464..c8b9e67 100644
69397--- a/kernel/taskstats.c
69398+++ b/kernel/taskstats.c
69399@@ -27,9 +27,12 @@
69400 #include <linux/cgroup.h>
69401 #include <linux/fs.h>
69402 #include <linux/file.h>
69403+#include <linux/grsecurity.h>
69404 #include <net/genetlink.h>
69405 #include <linux/atomic.h>
69406
69407+extern int gr_is_taskstats_denied(int pid);
69408+
69409 /*
69410 * Maximum length of a cpumask that can be specified in
69411 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69412@@ -556,6 +559,9 @@ err:
69413
69414 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69415 {
69416+ if (gr_is_taskstats_denied(current->pid))
69417+ return -EACCES;
69418+
69419 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69420 return cmd_attr_register_cpumask(info);
69421 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69422diff --git a/kernel/time.c b/kernel/time.c
69423index ba744cf..267b7c5 100644
69424--- a/kernel/time.c
69425+++ b/kernel/time.c
69426@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69427 return error;
69428
69429 if (tz) {
69430+ /* we log in do_settimeofday called below, so don't log twice
69431+ */
69432+ if (!tv)
69433+ gr_log_timechange();
69434+
69435 sys_tz = *tz;
69436 update_vsyscall_tz();
69437 if (firsttime) {
69438diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69439index 8a538c5..def79d4 100644
69440--- a/kernel/time/alarmtimer.c
69441+++ b/kernel/time/alarmtimer.c
69442@@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
69443 struct platform_device *pdev;
69444 int error = 0;
69445 int i;
69446- struct k_clock alarm_clock = {
69447+ static struct k_clock alarm_clock = {
69448 .clock_getres = alarm_clock_getres,
69449 .clock_get = alarm_clock_get,
69450 .timer_create = alarm_timer_create,
69451diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69452index f113755..ec24223 100644
69453--- a/kernel/time/tick-broadcast.c
69454+++ b/kernel/time/tick-broadcast.c
69455@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69456 * then clear the broadcast bit.
69457 */
69458 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69459- int cpu = smp_processor_id();
69460+ cpu = smp_processor_id();
69461
69462 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69463 tick_broadcast_clear_oneshot(cpu);
69464diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69465index 7c50de8..e29a94d 100644
69466--- a/kernel/time/timekeeping.c
69467+++ b/kernel/time/timekeeping.c
69468@@ -14,6 +14,7 @@
69469 #include <linux/init.h>
69470 #include <linux/mm.h>
69471 #include <linux/sched.h>
69472+#include <linux/grsecurity.h>
69473 #include <linux/syscore_ops.h>
69474 #include <linux/clocksource.h>
69475 #include <linux/jiffies.h>
69476@@ -388,6 +389,8 @@ int do_settimeofday(const struct timespec *tv)
69477 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69478 return -EINVAL;
69479
69480+ gr_log_timechange();
69481+
69482 write_seqlock_irqsave(&timekeeper.lock, flags);
69483
69484 timekeeping_forward_now();
69485diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69486index 3258455..f35227d 100644
69487--- a/kernel/time/timer_list.c
69488+++ b/kernel/time/timer_list.c
69489@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69490
69491 static void print_name_offset(struct seq_file *m, void *sym)
69492 {
69493+#ifdef CONFIG_GRKERNSEC_HIDESYM
69494+ SEQ_printf(m, "<%p>", NULL);
69495+#else
69496 char symname[KSYM_NAME_LEN];
69497
69498 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69499 SEQ_printf(m, "<%pK>", sym);
69500 else
69501 SEQ_printf(m, "%s", symname);
69502+#endif
69503 }
69504
69505 static void
69506@@ -112,7 +116,11 @@ next_one:
69507 static void
69508 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69509 {
69510+#ifdef CONFIG_GRKERNSEC_HIDESYM
69511+ SEQ_printf(m, " .base: %p\n", NULL);
69512+#else
69513 SEQ_printf(m, " .base: %pK\n", base);
69514+#endif
69515 SEQ_printf(m, " .index: %d\n",
69516 base->index);
69517 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69518@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69519 {
69520 struct proc_dir_entry *pe;
69521
69522+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69523+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
69524+#else
69525 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
69526+#endif
69527 if (!pe)
69528 return -ENOMEM;
69529 return 0;
69530diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
69531index 0b537f2..9e71eca 100644
69532--- a/kernel/time/timer_stats.c
69533+++ b/kernel/time/timer_stats.c
69534@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
69535 static unsigned long nr_entries;
69536 static struct entry entries[MAX_ENTRIES];
69537
69538-static atomic_t overflow_count;
69539+static atomic_unchecked_t overflow_count;
69540
69541 /*
69542 * The entries are in a hash-table, for fast lookup:
69543@@ -140,7 +140,7 @@ static void reset_entries(void)
69544 nr_entries = 0;
69545 memset(entries, 0, sizeof(entries));
69546 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
69547- atomic_set(&overflow_count, 0);
69548+ atomic_set_unchecked(&overflow_count, 0);
69549 }
69550
69551 static struct entry *alloc_entry(void)
69552@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69553 if (likely(entry))
69554 entry->count++;
69555 else
69556- atomic_inc(&overflow_count);
69557+ atomic_inc_unchecked(&overflow_count);
69558
69559 out_unlock:
69560 raw_spin_unlock_irqrestore(lock, flags);
69561@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69562
69563 static void print_name_offset(struct seq_file *m, unsigned long addr)
69564 {
69565+#ifdef CONFIG_GRKERNSEC_HIDESYM
69566+ seq_printf(m, "<%p>", NULL);
69567+#else
69568 char symname[KSYM_NAME_LEN];
69569
69570 if (lookup_symbol_name(addr, symname) < 0)
69571 seq_printf(m, "<%p>", (void *)addr);
69572 else
69573 seq_printf(m, "%s", symname);
69574+#endif
69575 }
69576
69577 static int tstats_show(struct seq_file *m, void *v)
69578@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
69579
69580 seq_puts(m, "Timer Stats Version: v0.2\n");
69581 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
69582- if (atomic_read(&overflow_count))
69583+ if (atomic_read_unchecked(&overflow_count))
69584 seq_printf(m, "Overflow: %d entries\n",
69585- atomic_read(&overflow_count));
69586+ atomic_read_unchecked(&overflow_count));
69587
69588 for (i = 0; i < nr_entries; i++) {
69589 entry = entries + i;
69590@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
69591 {
69592 struct proc_dir_entry *pe;
69593
69594+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69595+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
69596+#else
69597 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
69598+#endif
69599 if (!pe)
69600 return -ENOMEM;
69601 return 0;
69602diff --git a/kernel/timer.c b/kernel/timer.c
69603index a297ffc..5e16b0b 100644
69604--- a/kernel/timer.c
69605+++ b/kernel/timer.c
69606@@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
69607 /*
69608 * This function runs timers and the timer-tq in bottom half context.
69609 */
69610-static void run_timer_softirq(struct softirq_action *h)
69611+static void run_timer_softirq(void)
69612 {
69613 struct tvec_base *base = __this_cpu_read(tvec_bases);
69614
69615diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
69616index c0bd030..62a1927 100644
69617--- a/kernel/trace/blktrace.c
69618+++ b/kernel/trace/blktrace.c
69619@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
69620 struct blk_trace *bt = filp->private_data;
69621 char buf[16];
69622
69623- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
69624+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
69625
69626 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
69627 }
69628@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
69629 return 1;
69630
69631 bt = buf->chan->private_data;
69632- atomic_inc(&bt->dropped);
69633+ atomic_inc_unchecked(&bt->dropped);
69634 return 0;
69635 }
69636
69637@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
69638
69639 bt->dir = dir;
69640 bt->dev = dev;
69641- atomic_set(&bt->dropped, 0);
69642+ atomic_set_unchecked(&bt->dropped, 0);
69643
69644 ret = -EIO;
69645 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
69646diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
69647index 0fa92f6..89950b2 100644
69648--- a/kernel/trace/ftrace.c
69649+++ b/kernel/trace/ftrace.c
69650@@ -1800,12 +1800,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
69651 if (unlikely(ftrace_disabled))
69652 return 0;
69653
69654+ ret = ftrace_arch_code_modify_prepare();
69655+ FTRACE_WARN_ON(ret);
69656+ if (ret)
69657+ return 0;
69658+
69659 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
69660+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
69661 if (ret) {
69662 ftrace_bug(ret, ip);
69663- return 0;
69664 }
69665- return 1;
69666+ return ret ? 0 : 1;
69667 }
69668
69669 /*
69670@@ -2917,7 +2922,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
69671
69672 int
69673 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
69674- void *data)
69675+ void *data)
69676 {
69677 struct ftrace_func_probe *entry;
69678 struct ftrace_page *pg;
69679diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
69680index 55e4d4c..8c915ec 100644
69681--- a/kernel/trace/trace.c
69682+++ b/kernel/trace/trace.c
69683@@ -4316,10 +4316,9 @@ static const struct file_operations tracing_dyn_info_fops = {
69684 };
69685 #endif
69686
69687-static struct dentry *d_tracer;
69688-
69689 struct dentry *tracing_init_dentry(void)
69690 {
69691+ static struct dentry *d_tracer;
69692 static int once;
69693
69694 if (d_tracer)
69695@@ -4339,10 +4338,9 @@ struct dentry *tracing_init_dentry(void)
69696 return d_tracer;
69697 }
69698
69699-static struct dentry *d_percpu;
69700-
69701 struct dentry *tracing_dentry_percpu(void)
69702 {
69703+ static struct dentry *d_percpu;
69704 static int once;
69705 struct dentry *d_tracer;
69706
69707diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
69708index 29111da..d190fe2 100644
69709--- a/kernel/trace/trace_events.c
69710+++ b/kernel/trace/trace_events.c
69711@@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
69712 struct ftrace_module_file_ops {
69713 struct list_head list;
69714 struct module *mod;
69715- struct file_operations id;
69716- struct file_operations enable;
69717- struct file_operations format;
69718- struct file_operations filter;
69719 };
69720
69721 static struct ftrace_module_file_ops *
69722@@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
69723
69724 file_ops->mod = mod;
69725
69726- file_ops->id = ftrace_event_id_fops;
69727- file_ops->id.owner = mod;
69728-
69729- file_ops->enable = ftrace_enable_fops;
69730- file_ops->enable.owner = mod;
69731-
69732- file_ops->filter = ftrace_event_filter_fops;
69733- file_ops->filter.owner = mod;
69734-
69735- file_ops->format = ftrace_event_format_fops;
69736- file_ops->format.owner = mod;
69737+ pax_open_kernel();
69738+ *(void **)&mod->trace_id.owner = mod;
69739+ *(void **)&mod->trace_enable.owner = mod;
69740+ *(void **)&mod->trace_filter.owner = mod;
69741+ *(void **)&mod->trace_format.owner = mod;
69742+ pax_close_kernel();
69743
69744 list_add(&file_ops->list, &ftrace_module_file_list);
69745
69746@@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
69747
69748 for_each_event(call, start, end) {
69749 __trace_add_event_call(*call, mod,
69750- &file_ops->id, &file_ops->enable,
69751- &file_ops->filter, &file_ops->format);
69752+ &mod->trace_id, &mod->trace_enable,
69753+ &mod->trace_filter, &mod->trace_format);
69754 }
69755 }
69756
69757diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
69758index 580a05e..9b31acb 100644
69759--- a/kernel/trace/trace_kprobe.c
69760+++ b/kernel/trace/trace_kprobe.c
69761@@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69762 long ret;
69763 int maxlen = get_rloc_len(*(u32 *)dest);
69764 u8 *dst = get_rloc_data(dest);
69765- u8 *src = addr;
69766+ const u8 __user *src = (const u8 __force_user *)addr;
69767 mm_segment_t old_fs = get_fs();
69768 if (!maxlen)
69769 return;
69770@@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69771 pagefault_disable();
69772 do
69773 ret = __copy_from_user_inatomic(dst++, src++, 1);
69774- while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
69775+ while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
69776 dst[-1] = '\0';
69777 pagefault_enable();
69778 set_fs(old_fs);
69779@@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69780 ((u8 *)get_rloc_data(dest))[0] = '\0';
69781 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
69782 } else
69783- *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
69784+ *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
69785 get_rloc_offs(*(u32 *)dest));
69786 }
69787 /* Return the length of string -- including null terminal byte */
69788@@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
69789 set_fs(KERNEL_DS);
69790 pagefault_disable();
69791 do {
69792- ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
69793+ ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
69794 len++;
69795 } while (c && ret == 0 && len < MAX_STRING_SIZE);
69796 pagefault_enable();
69797diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
69798index fd3c8aa..5f324a6 100644
69799--- a/kernel/trace/trace_mmiotrace.c
69800+++ b/kernel/trace/trace_mmiotrace.c
69801@@ -24,7 +24,7 @@ struct header_iter {
69802 static struct trace_array *mmio_trace_array;
69803 static bool overrun_detected;
69804 static unsigned long prev_overruns;
69805-static atomic_t dropped_count;
69806+static atomic_unchecked_t dropped_count;
69807
69808 static void mmio_reset_data(struct trace_array *tr)
69809 {
69810@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
69811
69812 static unsigned long count_overruns(struct trace_iterator *iter)
69813 {
69814- unsigned long cnt = atomic_xchg(&dropped_count, 0);
69815+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
69816 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
69817
69818 if (over > prev_overruns)
69819@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
69820 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
69821 sizeof(*entry), 0, pc);
69822 if (!event) {
69823- atomic_inc(&dropped_count);
69824+ atomic_inc_unchecked(&dropped_count);
69825 return;
69826 }
69827 entry = ring_buffer_event_data(event);
69828@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
69829 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
69830 sizeof(*entry), 0, pc);
69831 if (!event) {
69832- atomic_inc(&dropped_count);
69833+ atomic_inc_unchecked(&dropped_count);
69834 return;
69835 }
69836 entry = ring_buffer_event_data(event);
69837diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
69838index df611a0..10d8b32 100644
69839--- a/kernel/trace/trace_output.c
69840+++ b/kernel/trace/trace_output.c
69841@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
69842
69843 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
69844 if (!IS_ERR(p)) {
69845- p = mangle_path(s->buffer + s->len, p, "\n");
69846+ p = mangle_path(s->buffer + s->len, p, "\n\\");
69847 if (p) {
69848 s->len = p - s->buffer;
69849 return 1;
69850diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69851index d4545f4..a9010a1 100644
69852--- a/kernel/trace/trace_stack.c
69853+++ b/kernel/trace/trace_stack.c
69854@@ -53,7 +53,7 @@ static inline void check_stack(void)
69855 return;
69856
69857 /* we do not handle interrupt stacks yet */
69858- if (!object_is_on_stack(&this_size))
69859+ if (!object_starts_on_stack(&this_size))
69860 return;
69861
69862 local_irq_save(flags);
69863diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69864index 209b379..7f76423 100644
69865--- a/kernel/trace/trace_workqueue.c
69866+++ b/kernel/trace/trace_workqueue.c
69867@@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69868 int cpu;
69869 pid_t pid;
69870 /* Can be inserted from interrupt or user context, need to be atomic */
69871- atomic_t inserted;
69872+ atomic_unchecked_t inserted;
69873 /*
69874 * Don't need to be atomic, works are serialized in a single workqueue thread
69875 * on a single CPU.
69876@@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69877 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69878 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69879 if (node->pid == wq_thread->pid) {
69880- atomic_inc(&node->inserted);
69881+ atomic_inc_unchecked(&node->inserted);
69882 goto found;
69883 }
69884 }
69885@@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69886 tsk = get_pid_task(pid, PIDTYPE_PID);
69887 if (tsk) {
69888 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69889- atomic_read(&cws->inserted), cws->executed,
69890+ atomic_read_unchecked(&cws->inserted), cws->executed,
69891 tsk->comm);
69892 put_task_struct(tsk);
69893 }
69894diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
69895index 6777153..8519f60 100644
69896--- a/lib/Kconfig.debug
69897+++ b/lib/Kconfig.debug
69898@@ -1132,6 +1132,7 @@ config LATENCYTOP
69899 depends on DEBUG_KERNEL
69900 depends on STACKTRACE_SUPPORT
69901 depends on PROC_FS
69902+ depends on !GRKERNSEC_HIDESYM
69903 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
69904 select KALLSYMS
69905 select KALLSYMS_ALL
69906diff --git a/lib/bitmap.c b/lib/bitmap.c
69907index b5a8b6a..a69623c 100644
69908--- a/lib/bitmap.c
69909+++ b/lib/bitmap.c
69910@@ -421,7 +421,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
69911 {
69912 int c, old_c, totaldigits, ndigits, nchunks, nbits;
69913 u32 chunk;
69914- const char __user __force *ubuf = (const char __user __force *)buf;
69915+ const char __user *ubuf = (const char __force_user *)buf;
69916
69917 bitmap_zero(maskp, nmaskbits);
69918
69919@@ -506,7 +506,7 @@ int bitmap_parse_user(const char __user *ubuf,
69920 {
69921 if (!access_ok(VERIFY_READ, ubuf, ulen))
69922 return -EFAULT;
69923- return __bitmap_parse((const char __force *)ubuf,
69924+ return __bitmap_parse((const char __force_kernel *)ubuf,
69925 ulen, 1, maskp, nmaskbits);
69926
69927 }
69928@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
69929 {
69930 unsigned a, b;
69931 int c, old_c, totaldigits;
69932- const char __user __force *ubuf = (const char __user __force *)buf;
69933+ const char __user *ubuf = (const char __force_user *)buf;
69934 int exp_digit, in_range;
69935
69936 totaldigits = c = 0;
69937@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
69938 {
69939 if (!access_ok(VERIFY_READ, ubuf, ulen))
69940 return -EFAULT;
69941- return __bitmap_parselist((const char __force *)ubuf,
69942+ return __bitmap_parselist((const char __force_kernel *)ubuf,
69943 ulen, 1, maskp, nmaskbits);
69944 }
69945 EXPORT_SYMBOL(bitmap_parselist_user);
69946diff --git a/lib/bug.c b/lib/bug.c
69947index a28c141..2bd3d95 100644
69948--- a/lib/bug.c
69949+++ b/lib/bug.c
69950@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
69951 return BUG_TRAP_TYPE_NONE;
69952
69953 bug = find_bug(bugaddr);
69954+ if (!bug)
69955+ return BUG_TRAP_TYPE_NONE;
69956
69957 file = NULL;
69958 line = 0;
69959diff --git a/lib/debugobjects.c b/lib/debugobjects.c
69960index 0ab9ae8..f01ceca 100644
69961--- a/lib/debugobjects.c
69962+++ b/lib/debugobjects.c
69963@@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
69964 if (limit > 4)
69965 return;
69966
69967- is_on_stack = object_is_on_stack(addr);
69968+ is_on_stack = object_starts_on_stack(addr);
69969 if (is_on_stack == onstack)
69970 return;
69971
69972diff --git a/lib/devres.c b/lib/devres.c
69973index 80b9c76..9e32279 100644
69974--- a/lib/devres.c
69975+++ b/lib/devres.c
69976@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
69977 void devm_iounmap(struct device *dev, void __iomem *addr)
69978 {
69979 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
69980- (void *)addr));
69981+ (void __force *)addr));
69982 iounmap(addr);
69983 }
69984 EXPORT_SYMBOL(devm_iounmap);
69985@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
69986 {
69987 ioport_unmap(addr);
69988 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
69989- devm_ioport_map_match, (void *)addr));
69990+ devm_ioport_map_match, (void __force *)addr));
69991 }
69992 EXPORT_SYMBOL(devm_ioport_unmap);
69993
69994diff --git a/lib/dma-debug.c b/lib/dma-debug.c
69995index 13ef233..5241683 100644
69996--- a/lib/dma-debug.c
69997+++ b/lib/dma-debug.c
69998@@ -924,7 +924,7 @@ out:
69999
70000 static void check_for_stack(struct device *dev, void *addr)
70001 {
70002- if (object_is_on_stack(addr))
70003+ if (object_starts_on_stack(addr))
70004 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70005 "stack [addr=%p]\n", addr);
70006 }
70007diff --git a/lib/extable.c b/lib/extable.c
70008index 4cac81e..63e9b8f 100644
70009--- a/lib/extable.c
70010+++ b/lib/extable.c
70011@@ -13,6 +13,7 @@
70012 #include <linux/init.h>
70013 #include <linux/sort.h>
70014 #include <asm/uaccess.h>
70015+#include <asm/pgtable.h>
70016
70017 #ifndef ARCH_HAS_SORT_EXTABLE
70018 /*
70019@@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
70020 void sort_extable(struct exception_table_entry *start,
70021 struct exception_table_entry *finish)
70022 {
70023+ pax_open_kernel();
70024 sort(start, finish - start, sizeof(struct exception_table_entry),
70025 cmp_ex, NULL);
70026+ pax_close_kernel();
70027 }
70028
70029 #ifdef CONFIG_MODULES
70030diff --git a/lib/inflate.c b/lib/inflate.c
70031index 013a761..c28f3fc 100644
70032--- a/lib/inflate.c
70033+++ b/lib/inflate.c
70034@@ -269,7 +269,7 @@ static void free(void *where)
70035 malloc_ptr = free_mem_ptr;
70036 }
70037 #else
70038-#define malloc(a) kmalloc(a, GFP_KERNEL)
70039+#define malloc(a) kmalloc((a), GFP_KERNEL)
70040 #define free(a) kfree(a)
70041 #endif
70042
70043diff --git a/lib/ioremap.c b/lib/ioremap.c
70044index 0c9216c..863bd89 100644
70045--- a/lib/ioremap.c
70046+++ b/lib/ioremap.c
70047@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
70048 unsigned long next;
70049
70050 phys_addr -= addr;
70051- pmd = pmd_alloc(&init_mm, pud, addr);
70052+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
70053 if (!pmd)
70054 return -ENOMEM;
70055 do {
70056@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
70057 unsigned long next;
70058
70059 phys_addr -= addr;
70060- pud = pud_alloc(&init_mm, pgd, addr);
70061+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
70062 if (!pud)
70063 return -ENOMEM;
70064 do {
70065diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70066index bd2bea9..6b3c95e 100644
70067--- a/lib/is_single_threaded.c
70068+++ b/lib/is_single_threaded.c
70069@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70070 struct task_struct *p, *t;
70071 bool ret;
70072
70073+ if (!mm)
70074+ return true;
70075+
70076 if (atomic_read(&task->signal->live) != 1)
70077 return false;
70078
70079diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70080index 3ac50dc..240bb7e 100644
70081--- a/lib/radix-tree.c
70082+++ b/lib/radix-tree.c
70083@@ -79,7 +79,7 @@ struct radix_tree_preload {
70084 int nr;
70085 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
70086 };
70087-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70088+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70089
70090 static inline void *ptr_to_indirect(void *ptr)
70091 {
70092diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70093index abbabec..6779788 100644
70094--- a/lib/vsprintf.c
70095+++ b/lib/vsprintf.c
70096@@ -16,6 +16,9 @@
70097 * - scnprintf and vscnprintf
70098 */
70099
70100+#ifdef CONFIG_GRKERNSEC_HIDESYM
70101+#define __INCLUDED_BY_HIDESYM 1
70102+#endif
70103 #include <stdarg.h>
70104 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
70105 #include <linux/types.h>
70106@@ -433,7 +436,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70107 char sym[KSYM_SYMBOL_LEN];
70108 if (ext == 'B')
70109 sprint_backtrace(sym, value);
70110- else if (ext != 'f' && ext != 's')
70111+ else if (ext != 'f' && ext != 's' && ext != 'a')
70112 sprint_symbol(sym, value);
70113 else
70114 kallsyms_lookup(value, NULL, NULL, NULL, sym);
70115@@ -809,7 +812,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70116 return number(buf, end, *(const netdev_features_t *)addr, spec);
70117 }
70118
70119+#ifdef CONFIG_GRKERNSEC_HIDESYM
70120+int kptr_restrict __read_mostly = 2;
70121+#else
70122 int kptr_restrict __read_mostly;
70123+#endif
70124
70125 /*
70126 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70127@@ -823,6 +830,8 @@ int kptr_restrict __read_mostly;
70128 * - 'S' For symbolic direct pointers with offset
70129 * - 's' For symbolic direct pointers without offset
70130 * - 'B' For backtraced symbolic direct pointers with offset
70131+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70132+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70133 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70134 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70135 * - 'M' For a 6-byte MAC address, it prints the address in the
70136@@ -868,12 +877,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70137 {
70138 if (!ptr && *fmt != 'K') {
70139 /*
70140- * Print (null) with the same width as a pointer so it makes
70141+ * Print (nil) with the same width as a pointer so it makes
70142 * tabular output look nice.
70143 */
70144 if (spec.field_width == -1)
70145 spec.field_width = 2 * sizeof(void *);
70146- return string(buf, end, "(null)", spec);
70147+ return string(buf, end, "(nil)", spec);
70148 }
70149
70150 switch (*fmt) {
70151@@ -883,6 +892,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70152 /* Fallthrough */
70153 case 'S':
70154 case 's':
70155+#ifdef CONFIG_GRKERNSEC_HIDESYM
70156+ break;
70157+#else
70158+ return symbol_string(buf, end, ptr, spec, *fmt);
70159+#endif
70160+ case 'A':
70161+ case 'a':
70162 case 'B':
70163 return symbol_string(buf, end, ptr, spec, *fmt);
70164 case 'R':
70165@@ -920,12 +936,15 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70166 va_end(va);
70167 return buf;
70168 }
70169+ case 'P':
70170+ break;
70171 case 'K':
70172 /*
70173 * %pK cannot be used in IRQ context because its test
70174 * for CAP_SYSLOG would be meaningless.
70175 */
70176- if (in_irq() || in_serving_softirq() || in_nmi()) {
70177+ if (kptr_restrict && (in_irq() || in_serving_softirq() ||
70178+ in_nmi())) {
70179 if (spec.field_width == -1)
70180 spec.field_width = 2 * sizeof(void *);
70181 return string(buf, end, "pK-error", spec);
70182@@ -942,6 +961,19 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70183 }
70184 break;
70185 }
70186+
70187+#ifdef CONFIG_GRKERNSEC_HIDESYM
70188+ /* 'P' = approved pointers to copy to userland,
70189+ as in the /proc/kallsyms case, as we make it display nothing
70190+ for non-root users, and the real contents for root users
70191+ */
70192+ if (ptr > TASK_SIZE && *fmt != 'P' && is_usercopy_object(buf)) {
70193+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
70194+ dump_stack();
70195+ ptr = NULL;
70196+ }
70197+#endif
70198+
70199 spec.flags |= SMALL;
70200 if (spec.field_width == -1) {
70201 spec.field_width = 2 * sizeof(void *);
70202@@ -1653,11 +1685,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70203 typeof(type) value; \
70204 if (sizeof(type) == 8) { \
70205 args = PTR_ALIGN(args, sizeof(u32)); \
70206- *(u32 *)&value = *(u32 *)args; \
70207- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70208+ *(u32 *)&value = *(const u32 *)args; \
70209+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70210 } else { \
70211 args = PTR_ALIGN(args, sizeof(type)); \
70212- value = *(typeof(type) *)args; \
70213+ value = *(const typeof(type) *)args; \
70214 } \
70215 args += sizeof(type); \
70216 value; \
70217@@ -1720,7 +1752,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70218 case FORMAT_TYPE_STR: {
70219 const char *str_arg = args;
70220 args += strlen(str_arg) + 1;
70221- str = string(str, end, (char *)str_arg, spec);
70222+ str = string(str, end, str_arg, spec);
70223 break;
70224 }
70225
70226diff --git a/localversion-grsec b/localversion-grsec
70227new file mode 100644
70228index 0000000..7cd6065
70229--- /dev/null
70230+++ b/localversion-grsec
70231@@ -0,0 +1 @@
70232+-grsec
70233diff --git a/mm/Kconfig b/mm/Kconfig
70234index e338407..4210331 100644
70235--- a/mm/Kconfig
70236+++ b/mm/Kconfig
70237@@ -247,10 +247,10 @@ config KSM
70238 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70239
70240 config DEFAULT_MMAP_MIN_ADDR
70241- int "Low address space to protect from user allocation"
70242+ int "Low address space to protect from user allocation"
70243 depends on MMU
70244- default 4096
70245- help
70246+ default 65536
70247+ help
70248 This is the portion of low virtual memory which should be protected
70249 from userspace allocation. Keeping a user from writing to low pages
70250 can help reduce the impact of kernel NULL pointer bugs.
70251@@ -280,7 +280,7 @@ config MEMORY_FAILURE
70252
70253 config HWPOISON_INJECT
70254 tristate "HWPoison pages injector"
70255- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
70256+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
70257 select PROC_PAGE_MONITOR
70258
70259 config NOMMU_INITIAL_TRIM_EXCESS
70260diff --git a/mm/filemap.c b/mm/filemap.c
70261index 79c4b2b..596b417 100644
70262--- a/mm/filemap.c
70263+++ b/mm/filemap.c
70264@@ -1762,7 +1762,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70265 struct address_space *mapping = file->f_mapping;
70266
70267 if (!mapping->a_ops->readpage)
70268- return -ENOEXEC;
70269+ return -ENODEV;
70270 file_accessed(file);
70271 vma->vm_ops = &generic_file_vm_ops;
70272 vma->vm_flags |= VM_CAN_NONLINEAR;
70273@@ -2168,6 +2168,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70274 *pos = i_size_read(inode);
70275
70276 if (limit != RLIM_INFINITY) {
70277+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70278 if (*pos >= limit) {
70279 send_sig(SIGXFSZ, current, 0);
70280 return -EFBIG;
70281diff --git a/mm/fremap.c b/mm/fremap.c
70282index 9ed4fd4..c42648d 100644
70283--- a/mm/fremap.c
70284+++ b/mm/fremap.c
70285@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70286 retry:
70287 vma = find_vma(mm, start);
70288
70289+#ifdef CONFIG_PAX_SEGMEXEC
70290+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70291+ goto out;
70292+#endif
70293+
70294 /*
70295 * Make sure the vma is shared, that it supports prefaulting,
70296 * and that the remapped range is valid and fully within
70297diff --git a/mm/highmem.c b/mm/highmem.c
70298index 57d82c6..e9e0552 100644
70299--- a/mm/highmem.c
70300+++ b/mm/highmem.c
70301@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70302 * So no dangers, even with speculative execution.
70303 */
70304 page = pte_page(pkmap_page_table[i]);
70305+ pax_open_kernel();
70306 pte_clear(&init_mm, (unsigned long)page_address(page),
70307 &pkmap_page_table[i]);
70308-
70309+ pax_close_kernel();
70310 set_page_address(page, NULL);
70311 need_flush = 1;
70312 }
70313@@ -186,9 +187,11 @@ start:
70314 }
70315 }
70316 vaddr = PKMAP_ADDR(last_pkmap_nr);
70317+
70318+ pax_open_kernel();
70319 set_pte_at(&init_mm, vaddr,
70320 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70321-
70322+ pax_close_kernel();
70323 pkmap_count[last_pkmap_nr] = 1;
70324 set_page_address(page, (void *)vaddr);
70325
70326diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70327index f0e5306..cb9398e 100644
70328--- a/mm/huge_memory.c
70329+++ b/mm/huge_memory.c
70330@@ -733,7 +733,7 @@ out:
70331 * run pte_offset_map on the pmd, if an huge pmd could
70332 * materialize from under us from a different thread.
70333 */
70334- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70335+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70336 return VM_FAULT_OOM;
70337 /* if an huge pmd materialized from under us just retry later */
70338 if (unlikely(pmd_trans_huge(*pmd)))
70339diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70340index 263e177..3f36aec 100644
70341--- a/mm/hugetlb.c
70342+++ b/mm/hugetlb.c
70343@@ -2446,6 +2446,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70344 return 1;
70345 }
70346
70347+#ifdef CONFIG_PAX_SEGMEXEC
70348+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70349+{
70350+ struct mm_struct *mm = vma->vm_mm;
70351+ struct vm_area_struct *vma_m;
70352+ unsigned long address_m;
70353+ pte_t *ptep_m;
70354+
70355+ vma_m = pax_find_mirror_vma(vma);
70356+ if (!vma_m)
70357+ return;
70358+
70359+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70360+ address_m = address + SEGMEXEC_TASK_SIZE;
70361+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70362+ get_page(page_m);
70363+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
70364+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70365+}
70366+#endif
70367+
70368 /*
70369 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70370 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70371@@ -2558,6 +2579,11 @@ retry_avoidcopy:
70372 make_huge_pte(vma, new_page, 1));
70373 page_remove_rmap(old_page);
70374 hugepage_add_new_anon_rmap(new_page, vma, address);
70375+
70376+#ifdef CONFIG_PAX_SEGMEXEC
70377+ pax_mirror_huge_pte(vma, address, new_page);
70378+#endif
70379+
70380 /* Make the old page be freed below */
70381 new_page = old_page;
70382 mmu_notifier_invalidate_range_end(mm,
70383@@ -2712,6 +2738,10 @@ retry:
70384 && (vma->vm_flags & VM_SHARED)));
70385 set_huge_pte_at(mm, address, ptep, new_pte);
70386
70387+#ifdef CONFIG_PAX_SEGMEXEC
70388+ pax_mirror_huge_pte(vma, address, page);
70389+#endif
70390+
70391 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70392 /* Optimization, do the COW without a second fault */
70393 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70394@@ -2741,6 +2771,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70395 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70396 struct hstate *h = hstate_vma(vma);
70397
70398+#ifdef CONFIG_PAX_SEGMEXEC
70399+ struct vm_area_struct *vma_m;
70400+#endif
70401+
70402 address &= huge_page_mask(h);
70403
70404 ptep = huge_pte_offset(mm, address);
70405@@ -2754,6 +2788,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70406 VM_FAULT_SET_HINDEX(h - hstates);
70407 }
70408
70409+#ifdef CONFIG_PAX_SEGMEXEC
70410+ vma_m = pax_find_mirror_vma(vma);
70411+ if (vma_m) {
70412+ unsigned long address_m;
70413+
70414+ if (vma->vm_start > vma_m->vm_start) {
70415+ address_m = address;
70416+ address -= SEGMEXEC_TASK_SIZE;
70417+ vma = vma_m;
70418+ h = hstate_vma(vma);
70419+ } else
70420+ address_m = address + SEGMEXEC_TASK_SIZE;
70421+
70422+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70423+ return VM_FAULT_OOM;
70424+ address_m &= HPAGE_MASK;
70425+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70426+ }
70427+#endif
70428+
70429 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70430 if (!ptep)
70431 return VM_FAULT_OOM;
70432diff --git a/mm/internal.h b/mm/internal.h
70433index 2189af4..f2ca332 100644
70434--- a/mm/internal.h
70435+++ b/mm/internal.h
70436@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70437 * in mm/page_alloc.c
70438 */
70439 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70440+extern void free_compound_page(struct page *page);
70441 extern void prep_compound_page(struct page *page, unsigned long order);
70442 #ifdef CONFIG_MEMORY_FAILURE
70443 extern bool is_free_buddy_page(struct page *page);
70444diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70445index 45eb621..6ccd8ea 100644
70446--- a/mm/kmemleak.c
70447+++ b/mm/kmemleak.c
70448@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70449
70450 for (i = 0; i < object->trace_len; i++) {
70451 void *ptr = (void *)object->trace[i];
70452- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70453+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70454 }
70455 }
70456
70457diff --git a/mm/maccess.c b/mm/maccess.c
70458index d53adf9..03a24bf 100644
70459--- a/mm/maccess.c
70460+++ b/mm/maccess.c
70461@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70462 set_fs(KERNEL_DS);
70463 pagefault_disable();
70464 ret = __copy_from_user_inatomic(dst,
70465- (__force const void __user *)src, size);
70466+ (const void __force_user *)src, size);
70467 pagefault_enable();
70468 set_fs(old_fs);
70469
70470@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70471
70472 set_fs(KERNEL_DS);
70473 pagefault_disable();
70474- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70475+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70476 pagefault_enable();
70477 set_fs(old_fs);
70478
70479diff --git a/mm/madvise.c b/mm/madvise.c
70480index 55f645c..cde5320 100644
70481--- a/mm/madvise.c
70482+++ b/mm/madvise.c
70483@@ -46,6 +46,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70484 pgoff_t pgoff;
70485 unsigned long new_flags = vma->vm_flags;
70486
70487+#ifdef CONFIG_PAX_SEGMEXEC
70488+ struct vm_area_struct *vma_m;
70489+#endif
70490+
70491 switch (behavior) {
70492 case MADV_NORMAL:
70493 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70494@@ -117,6 +121,13 @@ success:
70495 /*
70496 * vm_flags is protected by the mmap_sem held in write mode.
70497 */
70498+
70499+#ifdef CONFIG_PAX_SEGMEXEC
70500+ vma_m = pax_find_mirror_vma(vma);
70501+ if (vma_m)
70502+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70503+#endif
70504+
70505 vma->vm_flags = new_flags;
70506
70507 out:
70508@@ -175,6 +186,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70509 struct vm_area_struct ** prev,
70510 unsigned long start, unsigned long end)
70511 {
70512+
70513+#ifdef CONFIG_PAX_SEGMEXEC
70514+ struct vm_area_struct *vma_m;
70515+#endif
70516+
70517 *prev = vma;
70518 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70519 return -EINVAL;
70520@@ -187,6 +203,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70521 zap_page_range(vma, start, end - start, &details);
70522 } else
70523 zap_page_range(vma, start, end - start, NULL);
70524+
70525+#ifdef CONFIG_PAX_SEGMEXEC
70526+ vma_m = pax_find_mirror_vma(vma);
70527+ if (vma_m) {
70528+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70529+ struct zap_details details = {
70530+ .nonlinear_vma = vma_m,
70531+ .last_index = ULONG_MAX,
70532+ };
70533+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70534+ } else
70535+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70536+ }
70537+#endif
70538+
70539 return 0;
70540 }
70541
70542@@ -394,6 +425,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70543 if (end < start)
70544 goto out;
70545
70546+#ifdef CONFIG_PAX_SEGMEXEC
70547+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70548+ if (end > SEGMEXEC_TASK_SIZE)
70549+ goto out;
70550+ } else
70551+#endif
70552+
70553+ if (end > TASK_SIZE)
70554+ goto out;
70555+
70556 error = 0;
70557 if (end == start)
70558 goto out;
70559diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70560index 97cc273..6ed703f 100644
70561--- a/mm/memory-failure.c
70562+++ b/mm/memory-failure.c
70563@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70564
70565 int sysctl_memory_failure_recovery __read_mostly = 1;
70566
70567-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70568+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70569
70570 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70571
70572@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
70573 pfn, t->comm, t->pid);
70574 si.si_signo = SIGBUS;
70575 si.si_errno = 0;
70576- si.si_addr = (void *)addr;
70577+ si.si_addr = (void __user *)addr;
70578 #ifdef __ARCH_SI_TRAPNO
70579 si.si_trapno = trapno;
70580 #endif
70581@@ -1036,7 +1036,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
70582 }
70583
70584 nr_pages = 1 << compound_trans_order(hpage);
70585- atomic_long_add(nr_pages, &mce_bad_pages);
70586+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70587
70588 /*
70589 * We need/can do nothing about count=0 pages.
70590@@ -1066,7 +1066,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
70591 if (!PageHWPoison(hpage)
70592 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70593 || (p != hpage && TestSetPageHWPoison(hpage))) {
70594- atomic_long_sub(nr_pages, &mce_bad_pages);
70595+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70596 return 0;
70597 }
70598 set_page_hwpoison_huge_page(hpage);
70599@@ -1124,7 +1124,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
70600 }
70601 if (hwpoison_filter(p)) {
70602 if (TestClearPageHWPoison(p))
70603- atomic_long_sub(nr_pages, &mce_bad_pages);
70604+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70605 unlock_page(hpage);
70606 put_page(hpage);
70607 return 0;
70608@@ -1319,7 +1319,7 @@ int unpoison_memory(unsigned long pfn)
70609 return 0;
70610 }
70611 if (TestClearPageHWPoison(p))
70612- atomic_long_sub(nr_pages, &mce_bad_pages);
70613+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70614 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
70615 return 0;
70616 }
70617@@ -1333,7 +1333,7 @@ int unpoison_memory(unsigned long pfn)
70618 */
70619 if (TestClearPageHWPoison(page)) {
70620 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
70621- atomic_long_sub(nr_pages, &mce_bad_pages);
70622+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70623 freeit = 1;
70624 if (PageHuge(page))
70625 clear_page_hwpoison_huge_page(page);
70626@@ -1446,7 +1446,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
70627 }
70628 done:
70629 if (!PageHWPoison(hpage))
70630- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
70631+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
70632 set_page_hwpoison_huge_page(hpage);
70633 dequeue_hwpoisoned_huge_page(hpage);
70634 /* keep elevated page count for bad page */
70635@@ -1577,7 +1577,7 @@ int soft_offline_page(struct page *page, int flags)
70636 return ret;
70637
70638 done:
70639- atomic_long_add(1, &mce_bad_pages);
70640+ atomic_long_add_unchecked(1, &mce_bad_pages);
70641 SetPageHWPoison(page);
70642 /* keep elevated page count for bad page */
70643 return ret;
70644diff --git a/mm/memory.c b/mm/memory.c
70645index 6105f47..3363489 100644
70646--- a/mm/memory.c
70647+++ b/mm/memory.c
70648@@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
70649 return;
70650
70651 pmd = pmd_offset(pud, start);
70652+
70653+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
70654 pud_clear(pud);
70655 pmd_free_tlb(tlb, pmd, start);
70656+#endif
70657+
70658 }
70659
70660 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70661@@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70662 if (end - 1 > ceiling - 1)
70663 return;
70664
70665+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
70666 pud = pud_offset(pgd, start);
70667 pgd_clear(pgd);
70668 pud_free_tlb(tlb, pud, start);
70669+#endif
70670+
70671 }
70672
70673 /*
70674@@ -1597,12 +1604,6 @@ no_page_table:
70675 return page;
70676 }
70677
70678-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
70679-{
70680- return stack_guard_page_start(vma, addr) ||
70681- stack_guard_page_end(vma, addr+PAGE_SIZE);
70682-}
70683-
70684 /**
70685 * __get_user_pages() - pin user pages in memory
70686 * @tsk: task_struct of target task
70687@@ -1675,10 +1676,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70688 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
70689 i = 0;
70690
70691- do {
70692+ while (nr_pages) {
70693 struct vm_area_struct *vma;
70694
70695- vma = find_extend_vma(mm, start);
70696+ vma = find_vma(mm, start);
70697 if (!vma && in_gate_area(mm, start)) {
70698 unsigned long pg = start & PAGE_MASK;
70699 pgd_t *pgd;
70700@@ -1726,7 +1727,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70701 goto next_page;
70702 }
70703
70704- if (!vma ||
70705+ if (!vma || start < vma->vm_start ||
70706 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
70707 !(vm_flags & vma->vm_flags))
70708 return i ? : -EFAULT;
70709@@ -1753,11 +1754,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70710 int ret;
70711 unsigned int fault_flags = 0;
70712
70713- /* For mlock, just skip the stack guard page. */
70714- if (foll_flags & FOLL_MLOCK) {
70715- if (stack_guard_page(vma, start))
70716- goto next_page;
70717- }
70718 if (foll_flags & FOLL_WRITE)
70719 fault_flags |= FAULT_FLAG_WRITE;
70720 if (nonblocking)
70721@@ -1831,7 +1827,7 @@ next_page:
70722 start += PAGE_SIZE;
70723 nr_pages--;
70724 } while (nr_pages && start < vma->vm_end);
70725- } while (nr_pages);
70726+ }
70727 return i;
70728 }
70729 EXPORT_SYMBOL(__get_user_pages);
70730@@ -2038,6 +2034,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
70731 page_add_file_rmap(page);
70732 set_pte_at(mm, addr, pte, mk_pte(page, prot));
70733
70734+#ifdef CONFIG_PAX_SEGMEXEC
70735+ pax_mirror_file_pte(vma, addr, page, ptl);
70736+#endif
70737+
70738 retval = 0;
70739 pte_unmap_unlock(pte, ptl);
70740 return retval;
70741@@ -2072,10 +2072,22 @@ out:
70742 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
70743 struct page *page)
70744 {
70745+
70746+#ifdef CONFIG_PAX_SEGMEXEC
70747+ struct vm_area_struct *vma_m;
70748+#endif
70749+
70750 if (addr < vma->vm_start || addr >= vma->vm_end)
70751 return -EFAULT;
70752 if (!page_count(page))
70753 return -EINVAL;
70754+
70755+#ifdef CONFIG_PAX_SEGMEXEC
70756+ vma_m = pax_find_mirror_vma(vma);
70757+ if (vma_m)
70758+ vma_m->vm_flags |= VM_INSERTPAGE;
70759+#endif
70760+
70761 vma->vm_flags |= VM_INSERTPAGE;
70762 return insert_page(vma, addr, page, vma->vm_page_prot);
70763 }
70764@@ -2161,6 +2173,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
70765 unsigned long pfn)
70766 {
70767 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
70768+ BUG_ON(vma->vm_mirror);
70769
70770 if (addr < vma->vm_start || addr >= vma->vm_end)
70771 return -EFAULT;
70772@@ -2368,7 +2381,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
70773
70774 BUG_ON(pud_huge(*pud));
70775
70776- pmd = pmd_alloc(mm, pud, addr);
70777+ pmd = (mm == &init_mm) ?
70778+ pmd_alloc_kernel(mm, pud, addr) :
70779+ pmd_alloc(mm, pud, addr);
70780 if (!pmd)
70781 return -ENOMEM;
70782 do {
70783@@ -2388,7 +2403,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
70784 unsigned long next;
70785 int err;
70786
70787- pud = pud_alloc(mm, pgd, addr);
70788+ pud = (mm == &init_mm) ?
70789+ pud_alloc_kernel(mm, pgd, addr) :
70790+ pud_alloc(mm, pgd, addr);
70791 if (!pud)
70792 return -ENOMEM;
70793 do {
70794@@ -2476,6 +2493,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
70795 copy_user_highpage(dst, src, va, vma);
70796 }
70797
70798+#ifdef CONFIG_PAX_SEGMEXEC
70799+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
70800+{
70801+ struct mm_struct *mm = vma->vm_mm;
70802+ spinlock_t *ptl;
70803+ pte_t *pte, entry;
70804+
70805+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
70806+ entry = *pte;
70807+ if (!pte_present(entry)) {
70808+ if (!pte_none(entry)) {
70809+ BUG_ON(pte_file(entry));
70810+ free_swap_and_cache(pte_to_swp_entry(entry));
70811+ pte_clear_not_present_full(mm, address, pte, 0);
70812+ }
70813+ } else {
70814+ struct page *page;
70815+
70816+ flush_cache_page(vma, address, pte_pfn(entry));
70817+ entry = ptep_clear_flush(vma, address, pte);
70818+ BUG_ON(pte_dirty(entry));
70819+ page = vm_normal_page(vma, address, entry);
70820+ if (page) {
70821+ update_hiwater_rss(mm);
70822+ if (PageAnon(page))
70823+ dec_mm_counter_fast(mm, MM_ANONPAGES);
70824+ else
70825+ dec_mm_counter_fast(mm, MM_FILEPAGES);
70826+ page_remove_rmap(page);
70827+ page_cache_release(page);
70828+ }
70829+ }
70830+ pte_unmap_unlock(pte, ptl);
70831+}
70832+
70833+/* PaX: if vma is mirrored, synchronize the mirror's PTE
70834+ *
70835+ * the ptl of the lower mapped page is held on entry and is not released on exit
70836+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
70837+ */
70838+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70839+{
70840+ struct mm_struct *mm = vma->vm_mm;
70841+ unsigned long address_m;
70842+ spinlock_t *ptl_m;
70843+ struct vm_area_struct *vma_m;
70844+ pmd_t *pmd_m;
70845+ pte_t *pte_m, entry_m;
70846+
70847+ BUG_ON(!page_m || !PageAnon(page_m));
70848+
70849+ vma_m = pax_find_mirror_vma(vma);
70850+ if (!vma_m)
70851+ return;
70852+
70853+ BUG_ON(!PageLocked(page_m));
70854+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70855+ address_m = address + SEGMEXEC_TASK_SIZE;
70856+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70857+ pte_m = pte_offset_map(pmd_m, address_m);
70858+ ptl_m = pte_lockptr(mm, pmd_m);
70859+ if (ptl != ptl_m) {
70860+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70861+ if (!pte_none(*pte_m))
70862+ goto out;
70863+ }
70864+
70865+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70866+ page_cache_get(page_m);
70867+ page_add_anon_rmap(page_m, vma_m, address_m);
70868+ inc_mm_counter_fast(mm, MM_ANONPAGES);
70869+ set_pte_at(mm, address_m, pte_m, entry_m);
70870+ update_mmu_cache(vma_m, address_m, entry_m);
70871+out:
70872+ if (ptl != ptl_m)
70873+ spin_unlock(ptl_m);
70874+ pte_unmap(pte_m);
70875+ unlock_page(page_m);
70876+}
70877+
70878+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70879+{
70880+ struct mm_struct *mm = vma->vm_mm;
70881+ unsigned long address_m;
70882+ spinlock_t *ptl_m;
70883+ struct vm_area_struct *vma_m;
70884+ pmd_t *pmd_m;
70885+ pte_t *pte_m, entry_m;
70886+
70887+ BUG_ON(!page_m || PageAnon(page_m));
70888+
70889+ vma_m = pax_find_mirror_vma(vma);
70890+ if (!vma_m)
70891+ return;
70892+
70893+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70894+ address_m = address + SEGMEXEC_TASK_SIZE;
70895+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70896+ pte_m = pte_offset_map(pmd_m, address_m);
70897+ ptl_m = pte_lockptr(mm, pmd_m);
70898+ if (ptl != ptl_m) {
70899+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70900+ if (!pte_none(*pte_m))
70901+ goto out;
70902+ }
70903+
70904+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70905+ page_cache_get(page_m);
70906+ page_add_file_rmap(page_m);
70907+ inc_mm_counter_fast(mm, MM_FILEPAGES);
70908+ set_pte_at(mm, address_m, pte_m, entry_m);
70909+ update_mmu_cache(vma_m, address_m, entry_m);
70910+out:
70911+ if (ptl != ptl_m)
70912+ spin_unlock(ptl_m);
70913+ pte_unmap(pte_m);
70914+}
70915+
70916+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70917+{
70918+ struct mm_struct *mm = vma->vm_mm;
70919+ unsigned long address_m;
70920+ spinlock_t *ptl_m;
70921+ struct vm_area_struct *vma_m;
70922+ pmd_t *pmd_m;
70923+ pte_t *pte_m, entry_m;
70924+
70925+ vma_m = pax_find_mirror_vma(vma);
70926+ if (!vma_m)
70927+ return;
70928+
70929+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70930+ address_m = address + SEGMEXEC_TASK_SIZE;
70931+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70932+ pte_m = pte_offset_map(pmd_m, address_m);
70933+ ptl_m = pte_lockptr(mm, pmd_m);
70934+ if (ptl != ptl_m) {
70935+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70936+ if (!pte_none(*pte_m))
70937+ goto out;
70938+ }
70939+
70940+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70941+ set_pte_at(mm, address_m, pte_m, entry_m);
70942+out:
70943+ if (ptl != ptl_m)
70944+ spin_unlock(ptl_m);
70945+ pte_unmap(pte_m);
70946+}
70947+
70948+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70949+{
70950+ struct page *page_m;
70951+ pte_t entry;
70952+
70953+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70954+ goto out;
70955+
70956+ entry = *pte;
70957+ page_m = vm_normal_page(vma, address, entry);
70958+ if (!page_m)
70959+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70960+ else if (PageAnon(page_m)) {
70961+ if (pax_find_mirror_vma(vma)) {
70962+ pte_unmap_unlock(pte, ptl);
70963+ lock_page(page_m);
70964+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70965+ if (pte_same(entry, *pte))
70966+ pax_mirror_anon_pte(vma, address, page_m, ptl);
70967+ else
70968+ unlock_page(page_m);
70969+ }
70970+ } else
70971+ pax_mirror_file_pte(vma, address, page_m, ptl);
70972+
70973+out:
70974+ pte_unmap_unlock(pte, ptl);
70975+}
70976+#endif
70977+
70978 /*
70979 * This routine handles present pages, when users try to write
70980 * to a shared page. It is done by copying the page to a new address
70981@@ -2687,6 +2884,12 @@ gotten:
70982 */
70983 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70984 if (likely(pte_same(*page_table, orig_pte))) {
70985+
70986+#ifdef CONFIG_PAX_SEGMEXEC
70987+ if (pax_find_mirror_vma(vma))
70988+ BUG_ON(!trylock_page(new_page));
70989+#endif
70990+
70991 if (old_page) {
70992 if (!PageAnon(old_page)) {
70993 dec_mm_counter_fast(mm, MM_FILEPAGES);
70994@@ -2738,6 +2941,10 @@ gotten:
70995 page_remove_rmap(old_page);
70996 }
70997
70998+#ifdef CONFIG_PAX_SEGMEXEC
70999+ pax_mirror_anon_pte(vma, address, new_page, ptl);
71000+#endif
71001+
71002 /* Free the old page.. */
71003 new_page = old_page;
71004 ret |= VM_FAULT_WRITE;
71005@@ -3017,6 +3224,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71006 swap_free(entry);
71007 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71008 try_to_free_swap(page);
71009+
71010+#ifdef CONFIG_PAX_SEGMEXEC
71011+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71012+#endif
71013+
71014 unlock_page(page);
71015 if (swapcache) {
71016 /*
71017@@ -3040,6 +3252,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71018
71019 /* No need to invalidate - it was non-present before */
71020 update_mmu_cache(vma, address, page_table);
71021+
71022+#ifdef CONFIG_PAX_SEGMEXEC
71023+ pax_mirror_anon_pte(vma, address, page, ptl);
71024+#endif
71025+
71026 unlock:
71027 pte_unmap_unlock(page_table, ptl);
71028 out:
71029@@ -3059,40 +3276,6 @@ out_release:
71030 }
71031
71032 /*
71033- * This is like a special single-page "expand_{down|up}wards()",
71034- * except we must first make sure that 'address{-|+}PAGE_SIZE'
71035- * doesn't hit another vma.
71036- */
71037-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71038-{
71039- address &= PAGE_MASK;
71040- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71041- struct vm_area_struct *prev = vma->vm_prev;
71042-
71043- /*
71044- * Is there a mapping abutting this one below?
71045- *
71046- * That's only ok if it's the same stack mapping
71047- * that has gotten split..
71048- */
71049- if (prev && prev->vm_end == address)
71050- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71051-
71052- expand_downwards(vma, address - PAGE_SIZE);
71053- }
71054- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71055- struct vm_area_struct *next = vma->vm_next;
71056-
71057- /* As VM_GROWSDOWN but s/below/above/ */
71058- if (next && next->vm_start == address + PAGE_SIZE)
71059- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71060-
71061- expand_upwards(vma, address + PAGE_SIZE);
71062- }
71063- return 0;
71064-}
71065-
71066-/*
71067 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71068 * but allow concurrent faults), and pte mapped but not yet locked.
71069 * We return with mmap_sem still held, but pte unmapped and unlocked.
71070@@ -3101,27 +3284,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71071 unsigned long address, pte_t *page_table, pmd_t *pmd,
71072 unsigned int flags)
71073 {
71074- struct page *page;
71075+ struct page *page = NULL;
71076 spinlock_t *ptl;
71077 pte_t entry;
71078
71079- pte_unmap(page_table);
71080-
71081- /* Check if we need to add a guard page to the stack */
71082- if (check_stack_guard_page(vma, address) < 0)
71083- return VM_FAULT_SIGBUS;
71084-
71085- /* Use the zero-page for reads */
71086 if (!(flags & FAULT_FLAG_WRITE)) {
71087 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71088 vma->vm_page_prot));
71089- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71090+ ptl = pte_lockptr(mm, pmd);
71091+ spin_lock(ptl);
71092 if (!pte_none(*page_table))
71093 goto unlock;
71094 goto setpte;
71095 }
71096
71097 /* Allocate our own private page. */
71098+ pte_unmap(page_table);
71099+
71100 if (unlikely(anon_vma_prepare(vma)))
71101 goto oom;
71102 page = alloc_zeroed_user_highpage_movable(vma, address);
71103@@ -3140,6 +3319,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71104 if (!pte_none(*page_table))
71105 goto release;
71106
71107+#ifdef CONFIG_PAX_SEGMEXEC
71108+ if (pax_find_mirror_vma(vma))
71109+ BUG_ON(!trylock_page(page));
71110+#endif
71111+
71112 inc_mm_counter_fast(mm, MM_ANONPAGES);
71113 page_add_new_anon_rmap(page, vma, address);
71114 setpte:
71115@@ -3147,6 +3331,12 @@ setpte:
71116
71117 /* No need to invalidate - it was non-present before */
71118 update_mmu_cache(vma, address, page_table);
71119+
71120+#ifdef CONFIG_PAX_SEGMEXEC
71121+ if (page)
71122+ pax_mirror_anon_pte(vma, address, page, ptl);
71123+#endif
71124+
71125 unlock:
71126 pte_unmap_unlock(page_table, ptl);
71127 return 0;
71128@@ -3290,6 +3480,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71129 */
71130 /* Only go through if we didn't race with anybody else... */
71131 if (likely(pte_same(*page_table, orig_pte))) {
71132+
71133+#ifdef CONFIG_PAX_SEGMEXEC
71134+ if (anon && pax_find_mirror_vma(vma))
71135+ BUG_ON(!trylock_page(page));
71136+#endif
71137+
71138 flush_icache_page(vma, page);
71139 entry = mk_pte(page, vma->vm_page_prot);
71140 if (flags & FAULT_FLAG_WRITE)
71141@@ -3309,6 +3505,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71142
71143 /* no need to invalidate: a not-present page won't be cached */
71144 update_mmu_cache(vma, address, page_table);
71145+
71146+#ifdef CONFIG_PAX_SEGMEXEC
71147+ if (anon)
71148+ pax_mirror_anon_pte(vma, address, page, ptl);
71149+ else
71150+ pax_mirror_file_pte(vma, address, page, ptl);
71151+#endif
71152+
71153 } else {
71154 if (cow_page)
71155 mem_cgroup_uncharge_page(cow_page);
71156@@ -3462,6 +3666,12 @@ int handle_pte_fault(struct mm_struct *mm,
71157 if (flags & FAULT_FLAG_WRITE)
71158 flush_tlb_fix_spurious_fault(vma, address);
71159 }
71160+
71161+#ifdef CONFIG_PAX_SEGMEXEC
71162+ pax_mirror_pte(vma, address, pte, pmd, ptl);
71163+ return 0;
71164+#endif
71165+
71166 unlock:
71167 pte_unmap_unlock(pte, ptl);
71168 return 0;
71169@@ -3478,6 +3688,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71170 pmd_t *pmd;
71171 pte_t *pte;
71172
71173+#ifdef CONFIG_PAX_SEGMEXEC
71174+ struct vm_area_struct *vma_m;
71175+#endif
71176+
71177 __set_current_state(TASK_RUNNING);
71178
71179 count_vm_event(PGFAULT);
71180@@ -3489,6 +3703,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71181 if (unlikely(is_vm_hugetlb_page(vma)))
71182 return hugetlb_fault(mm, vma, address, flags);
71183
71184+#ifdef CONFIG_PAX_SEGMEXEC
71185+ vma_m = pax_find_mirror_vma(vma);
71186+ if (vma_m) {
71187+ unsigned long address_m;
71188+ pgd_t *pgd_m;
71189+ pud_t *pud_m;
71190+ pmd_t *pmd_m;
71191+
71192+ if (vma->vm_start > vma_m->vm_start) {
71193+ address_m = address;
71194+ address -= SEGMEXEC_TASK_SIZE;
71195+ vma = vma_m;
71196+ } else
71197+ address_m = address + SEGMEXEC_TASK_SIZE;
71198+
71199+ pgd_m = pgd_offset(mm, address_m);
71200+ pud_m = pud_alloc(mm, pgd_m, address_m);
71201+ if (!pud_m)
71202+ return VM_FAULT_OOM;
71203+ pmd_m = pmd_alloc(mm, pud_m, address_m);
71204+ if (!pmd_m)
71205+ return VM_FAULT_OOM;
71206+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71207+ return VM_FAULT_OOM;
71208+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71209+ }
71210+#endif
71211+
71212 pgd = pgd_offset(mm, address);
71213 pud = pud_alloc(mm, pgd, address);
71214 if (!pud)
71215@@ -3518,7 +3760,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71216 * run pte_offset_map on the pmd, if an huge pmd could
71217 * materialize from under us from a different thread.
71218 */
71219- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71220+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71221 return VM_FAULT_OOM;
71222 /* if an huge pmd materialized from under us just retry later */
71223 if (unlikely(pmd_trans_huge(*pmd)))
71224@@ -3555,6 +3797,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71225 spin_unlock(&mm->page_table_lock);
71226 return 0;
71227 }
71228+
71229+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71230+{
71231+ pud_t *new = pud_alloc_one(mm, address);
71232+ if (!new)
71233+ return -ENOMEM;
71234+
71235+ smp_wmb(); /* See comment in __pte_alloc */
71236+
71237+ spin_lock(&mm->page_table_lock);
71238+ if (pgd_present(*pgd)) /* Another has populated it */
71239+ pud_free(mm, new);
71240+ else
71241+ pgd_populate_kernel(mm, pgd, new);
71242+ spin_unlock(&mm->page_table_lock);
71243+ return 0;
71244+}
71245 #endif /* __PAGETABLE_PUD_FOLDED */
71246
71247 #ifndef __PAGETABLE_PMD_FOLDED
71248@@ -3585,6 +3844,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71249 spin_unlock(&mm->page_table_lock);
71250 return 0;
71251 }
71252+
71253+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71254+{
71255+ pmd_t *new = pmd_alloc_one(mm, address);
71256+ if (!new)
71257+ return -ENOMEM;
71258+
71259+ smp_wmb(); /* See comment in __pte_alloc */
71260+
71261+ spin_lock(&mm->page_table_lock);
71262+#ifndef __ARCH_HAS_4LEVEL_HACK
71263+ if (pud_present(*pud)) /* Another has populated it */
71264+ pmd_free(mm, new);
71265+ else
71266+ pud_populate_kernel(mm, pud, new);
71267+#else
71268+ if (pgd_present(*pud)) /* Another has populated it */
71269+ pmd_free(mm, new);
71270+ else
71271+ pgd_populate_kernel(mm, pud, new);
71272+#endif /* __ARCH_HAS_4LEVEL_HACK */
71273+ spin_unlock(&mm->page_table_lock);
71274+ return 0;
71275+}
71276 #endif /* __PAGETABLE_PMD_FOLDED */
71277
71278 int make_pages_present(unsigned long addr, unsigned long end)
71279@@ -3622,7 +3905,7 @@ static int __init gate_vma_init(void)
71280 gate_vma.vm_start = FIXADDR_USER_START;
71281 gate_vma.vm_end = FIXADDR_USER_END;
71282 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71283- gate_vma.vm_page_prot = __P101;
71284+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71285
71286 return 0;
71287 }
71288diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71289index bf5b485..e44c2cb 100644
71290--- a/mm/mempolicy.c
71291+++ b/mm/mempolicy.c
71292@@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71293 unsigned long vmstart;
71294 unsigned long vmend;
71295
71296+#ifdef CONFIG_PAX_SEGMEXEC
71297+ struct vm_area_struct *vma_m;
71298+#endif
71299+
71300 vma = find_vma(mm, start);
71301 if (!vma || vma->vm_start > start)
71302 return -EFAULT;
71303@@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71304 if (err)
71305 goto out;
71306 }
71307+
71308+#ifdef CONFIG_PAX_SEGMEXEC
71309+ vma_m = pax_find_mirror_vma(vma);
71310+ if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
71311+ err = vma_m->vm_ops->set_policy(vma_m, new_pol);
71312+ if (err)
71313+ goto out;
71314+ }
71315+#endif
71316+
71317 }
71318
71319 out:
71320@@ -1105,6 +1119,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71321
71322 if (end < start)
71323 return -EINVAL;
71324+
71325+#ifdef CONFIG_PAX_SEGMEXEC
71326+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71327+ if (end > SEGMEXEC_TASK_SIZE)
71328+ return -EINVAL;
71329+ } else
71330+#endif
71331+
71332+ if (end > TASK_SIZE)
71333+ return -EINVAL;
71334+
71335 if (end == start)
71336 return 0;
71337
71338@@ -1328,8 +1353,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71339 */
71340 tcred = __task_cred(task);
71341 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71342- cred->uid != tcred->suid && cred->uid != tcred->uid &&
71343- !capable(CAP_SYS_NICE)) {
71344+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71345 rcu_read_unlock();
71346 err = -EPERM;
71347 goto out_put;
71348@@ -1360,6 +1384,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71349 goto out;
71350 }
71351
71352+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71353+ if (mm != current->mm &&
71354+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71355+ mmput(mm);
71356+ err = -EPERM;
71357+ goto out;
71358+ }
71359+#endif
71360+
71361 err = do_migrate_pages(mm, old, new,
71362 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
71363
71364diff --git a/mm/mlock.c b/mm/mlock.c
71365index ef726e8..cd7f1ec 100644
71366--- a/mm/mlock.c
71367+++ b/mm/mlock.c
71368@@ -13,6 +13,7 @@
71369 #include <linux/pagemap.h>
71370 #include <linux/mempolicy.h>
71371 #include <linux/syscalls.h>
71372+#include <linux/security.h>
71373 #include <linux/sched.h>
71374 #include <linux/export.h>
71375 #include <linux/rmap.h>
71376@@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
71377 {
71378 unsigned long nstart, end, tmp;
71379 struct vm_area_struct * vma, * prev;
71380- int error;
71381+ int error = 0;
71382
71383 VM_BUG_ON(start & ~PAGE_MASK);
71384 VM_BUG_ON(len != PAGE_ALIGN(len));
71385@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71386 return -EINVAL;
71387 if (end == start)
71388 return 0;
71389+ if (end > TASK_SIZE)
71390+ return -EINVAL;
71391+
71392 vma = find_vma(current->mm, start);
71393 if (!vma || vma->vm_start > start)
71394 return -ENOMEM;
71395@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71396 for (nstart = start ; ; ) {
71397 vm_flags_t newflags;
71398
71399+#ifdef CONFIG_PAX_SEGMEXEC
71400+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71401+ break;
71402+#endif
71403+
71404 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71405
71406 newflags = vma->vm_flags | VM_LOCKED;
71407@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71408 lock_limit >>= PAGE_SHIFT;
71409
71410 /* check against resource limits */
71411+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71412 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71413 error = do_mlock(start, len, 1);
71414 up_write(&current->mm->mmap_sem);
71415@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71416 static int do_mlockall(int flags)
71417 {
71418 struct vm_area_struct * vma, * prev = NULL;
71419- unsigned int def_flags = 0;
71420
71421 if (flags & MCL_FUTURE)
71422- def_flags = VM_LOCKED;
71423- current->mm->def_flags = def_flags;
71424+ current->mm->def_flags |= VM_LOCKED;
71425+ else
71426+ current->mm->def_flags &= ~VM_LOCKED;
71427 if (flags == MCL_FUTURE)
71428 goto out;
71429
71430 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71431 vm_flags_t newflags;
71432
71433+#ifdef CONFIG_PAX_SEGMEXEC
71434+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71435+ break;
71436+#endif
71437+
71438+ BUG_ON(vma->vm_end > TASK_SIZE);
71439 newflags = vma->vm_flags | VM_LOCKED;
71440 if (!(flags & MCL_CURRENT))
71441 newflags &= ~VM_LOCKED;
71442@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71443 lock_limit >>= PAGE_SHIFT;
71444
71445 ret = -ENOMEM;
71446+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71447 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71448 capable(CAP_IPC_LOCK))
71449 ret = do_mlockall(flags);
71450diff --git a/mm/mmap.c b/mm/mmap.c
71451index 848ef52..d2b586c 100644
71452--- a/mm/mmap.c
71453+++ b/mm/mmap.c
71454@@ -46,6 +46,16 @@
71455 #define arch_rebalance_pgtables(addr, len) (addr)
71456 #endif
71457
71458+static inline void verify_mm_writelocked(struct mm_struct *mm)
71459+{
71460+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71461+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71462+ up_read(&mm->mmap_sem);
71463+ BUG();
71464+ }
71465+#endif
71466+}
71467+
71468 static void unmap_region(struct mm_struct *mm,
71469 struct vm_area_struct *vma, struct vm_area_struct *prev,
71470 unsigned long start, unsigned long end);
71471@@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
71472 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71473 *
71474 */
71475-pgprot_t protection_map[16] = {
71476+pgprot_t protection_map[16] __read_only = {
71477 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71478 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71479 };
71480
71481-pgprot_t vm_get_page_prot(unsigned long vm_flags)
71482+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71483 {
71484- return __pgprot(pgprot_val(protection_map[vm_flags &
71485+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71486 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71487 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71488+
71489+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71490+ if (!(__supported_pte_mask & _PAGE_NX) &&
71491+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71492+ (vm_flags & (VM_READ | VM_WRITE)))
71493+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71494+#endif
71495+
71496+ return prot;
71497 }
71498 EXPORT_SYMBOL(vm_get_page_prot);
71499
71500 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71501 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71502 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71503+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71504 /*
71505 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71506 * other variables. It can be updated by several CPUs frequently.
71507@@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71508 struct vm_area_struct *next = vma->vm_next;
71509
71510 might_sleep();
71511+ BUG_ON(vma->vm_mirror);
71512 if (vma->vm_ops && vma->vm_ops->close)
71513 vma->vm_ops->close(vma);
71514 if (vma->vm_file) {
71515@@ -274,6 +295,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71516 * not page aligned -Ram Gupta
71517 */
71518 rlim = rlimit(RLIMIT_DATA);
71519+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71520 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71521 (mm->end_data - mm->start_data) > rlim)
71522 goto out;
71523@@ -690,6 +712,12 @@ static int
71524 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71525 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71526 {
71527+
71528+#ifdef CONFIG_PAX_SEGMEXEC
71529+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71530+ return 0;
71531+#endif
71532+
71533 if (is_mergeable_vma(vma, file, vm_flags) &&
71534 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71535 if (vma->vm_pgoff == vm_pgoff)
71536@@ -709,6 +737,12 @@ static int
71537 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71538 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71539 {
71540+
71541+#ifdef CONFIG_PAX_SEGMEXEC
71542+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71543+ return 0;
71544+#endif
71545+
71546 if (is_mergeable_vma(vma, file, vm_flags) &&
71547 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71548 pgoff_t vm_pglen;
71549@@ -751,13 +785,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71550 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71551 struct vm_area_struct *prev, unsigned long addr,
71552 unsigned long end, unsigned long vm_flags,
71553- struct anon_vma *anon_vma, struct file *file,
71554+ struct anon_vma *anon_vma, struct file *file,
71555 pgoff_t pgoff, struct mempolicy *policy)
71556 {
71557 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71558 struct vm_area_struct *area, *next;
71559 int err;
71560
71561+#ifdef CONFIG_PAX_SEGMEXEC
71562+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71563+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71564+
71565+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71566+#endif
71567+
71568 /*
71569 * We later require that vma->vm_flags == vm_flags,
71570 * so this tests vma->vm_flags & VM_SPECIAL, too.
71571@@ -773,6 +814,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71572 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71573 next = next->vm_next;
71574
71575+#ifdef CONFIG_PAX_SEGMEXEC
71576+ if (prev)
71577+ prev_m = pax_find_mirror_vma(prev);
71578+ if (area)
71579+ area_m = pax_find_mirror_vma(area);
71580+ if (next)
71581+ next_m = pax_find_mirror_vma(next);
71582+#endif
71583+
71584 /*
71585 * Can it merge with the predecessor?
71586 */
71587@@ -792,9 +842,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71588 /* cases 1, 6 */
71589 err = vma_adjust(prev, prev->vm_start,
71590 next->vm_end, prev->vm_pgoff, NULL);
71591- } else /* cases 2, 5, 7 */
71592+
71593+#ifdef CONFIG_PAX_SEGMEXEC
71594+ if (!err && prev_m)
71595+ err = vma_adjust(prev_m, prev_m->vm_start,
71596+ next_m->vm_end, prev_m->vm_pgoff, NULL);
71597+#endif
71598+
71599+ } else { /* cases 2, 5, 7 */
71600 err = vma_adjust(prev, prev->vm_start,
71601 end, prev->vm_pgoff, NULL);
71602+
71603+#ifdef CONFIG_PAX_SEGMEXEC
71604+ if (!err && prev_m)
71605+ err = vma_adjust(prev_m, prev_m->vm_start,
71606+ end_m, prev_m->vm_pgoff, NULL);
71607+#endif
71608+
71609+ }
71610 if (err)
71611 return NULL;
71612 khugepaged_enter_vma_merge(prev);
71613@@ -808,12 +873,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71614 mpol_equal(policy, vma_policy(next)) &&
71615 can_vma_merge_before(next, vm_flags,
71616 anon_vma, file, pgoff+pglen)) {
71617- if (prev && addr < prev->vm_end) /* case 4 */
71618+ if (prev && addr < prev->vm_end) { /* case 4 */
71619 err = vma_adjust(prev, prev->vm_start,
71620 addr, prev->vm_pgoff, NULL);
71621- else /* cases 3, 8 */
71622+
71623+#ifdef CONFIG_PAX_SEGMEXEC
71624+ if (!err && prev_m)
71625+ err = vma_adjust(prev_m, prev_m->vm_start,
71626+ addr_m, prev_m->vm_pgoff, NULL);
71627+#endif
71628+
71629+ } else { /* cases 3, 8 */
71630 err = vma_adjust(area, addr, next->vm_end,
71631 next->vm_pgoff - pglen, NULL);
71632+
71633+#ifdef CONFIG_PAX_SEGMEXEC
71634+ if (!err && area_m)
71635+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
71636+ next_m->vm_pgoff - pglen, NULL);
71637+#endif
71638+
71639+ }
71640 if (err)
71641 return NULL;
71642 khugepaged_enter_vma_merge(area);
71643@@ -922,14 +1002,11 @@ none:
71644 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
71645 struct file *file, long pages)
71646 {
71647- const unsigned long stack_flags
71648- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
71649-
71650 if (file) {
71651 mm->shared_vm += pages;
71652 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
71653 mm->exec_vm += pages;
71654- } else if (flags & stack_flags)
71655+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
71656 mm->stack_vm += pages;
71657 if (flags & (VM_RESERVED|VM_IO))
71658 mm->reserved_vm += pages;
71659@@ -969,7 +1046,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71660 * (the exception is when the underlying filesystem is noexec
71661 * mounted, in which case we dont add PROT_EXEC.)
71662 */
71663- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71664+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71665 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
71666 prot |= PROT_EXEC;
71667
71668@@ -995,7 +1072,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71669 /* Obtain the address to map to. we verify (or select) it and ensure
71670 * that it represents a valid section of the address space.
71671 */
71672- addr = get_unmapped_area(file, addr, len, pgoff, flags);
71673+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
71674 if (addr & ~PAGE_MASK)
71675 return addr;
71676
71677@@ -1006,6 +1083,36 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71678 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
71679 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
71680
71681+#ifdef CONFIG_PAX_MPROTECT
71682+ if (mm->pax_flags & MF_PAX_MPROTECT) {
71683+#ifndef CONFIG_PAX_MPROTECT_COMPAT
71684+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
71685+ gr_log_rwxmmap(file);
71686+
71687+#ifdef CONFIG_PAX_EMUPLT
71688+ vm_flags &= ~VM_EXEC;
71689+#else
71690+ return -EPERM;
71691+#endif
71692+
71693+ }
71694+
71695+ if (!(vm_flags & VM_EXEC))
71696+ vm_flags &= ~VM_MAYEXEC;
71697+#else
71698+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71699+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71700+#endif
71701+ else
71702+ vm_flags &= ~VM_MAYWRITE;
71703+ }
71704+#endif
71705+
71706+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71707+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
71708+ vm_flags &= ~VM_PAGEEXEC;
71709+#endif
71710+
71711 if (flags & MAP_LOCKED)
71712 if (!can_do_mlock())
71713 return -EPERM;
71714@@ -1017,6 +1124,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71715 locked += mm->locked_vm;
71716 lock_limit = rlimit(RLIMIT_MEMLOCK);
71717 lock_limit >>= PAGE_SHIFT;
71718+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71719 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
71720 return -EAGAIN;
71721 }
71722@@ -1087,6 +1195,9 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71723 if (error)
71724 return error;
71725
71726+ if (!gr_acl_handle_mmap(file, prot))
71727+ return -EACCES;
71728+
71729 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
71730 }
71731
71732@@ -1192,7 +1303,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
71733 vm_flags_t vm_flags = vma->vm_flags;
71734
71735 /* If it was private or non-writable, the write bit is already clear */
71736- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
71737+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
71738 return 0;
71739
71740 /* The backer wishes to know when pages are first written to? */
71741@@ -1241,14 +1352,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
71742 unsigned long charged = 0;
71743 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
71744
71745+#ifdef CONFIG_PAX_SEGMEXEC
71746+ struct vm_area_struct *vma_m = NULL;
71747+#endif
71748+
71749+ /*
71750+ * mm->mmap_sem is required to protect against another thread
71751+ * changing the mappings in case we sleep.
71752+ */
71753+ verify_mm_writelocked(mm);
71754+
71755 /* Clear old maps */
71756 error = -ENOMEM;
71757-munmap_back:
71758 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71759 if (vma && vma->vm_start < addr + len) {
71760 if (do_munmap(mm, addr, len))
71761 return -ENOMEM;
71762- goto munmap_back;
71763+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71764+ BUG_ON(vma && vma->vm_start < addr + len);
71765 }
71766
71767 /* Check against address space limit. */
71768@@ -1297,6 +1418,16 @@ munmap_back:
71769 goto unacct_error;
71770 }
71771
71772+#ifdef CONFIG_PAX_SEGMEXEC
71773+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
71774+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71775+ if (!vma_m) {
71776+ error = -ENOMEM;
71777+ goto free_vma;
71778+ }
71779+ }
71780+#endif
71781+
71782 vma->vm_mm = mm;
71783 vma->vm_start = addr;
71784 vma->vm_end = addr + len;
71785@@ -1321,6 +1452,19 @@ munmap_back:
71786 error = file->f_op->mmap(file, vma);
71787 if (error)
71788 goto unmap_and_free_vma;
71789+
71790+#ifdef CONFIG_PAX_SEGMEXEC
71791+ if (vma_m && (vm_flags & VM_EXECUTABLE))
71792+ added_exe_file_vma(mm);
71793+#endif
71794+
71795+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71796+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
71797+ vma->vm_flags |= VM_PAGEEXEC;
71798+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71799+ }
71800+#endif
71801+
71802 if (vm_flags & VM_EXECUTABLE)
71803 added_exe_file_vma(mm);
71804
71805@@ -1358,6 +1502,11 @@ munmap_back:
71806 vma_link(mm, vma, prev, rb_link, rb_parent);
71807 file = vma->vm_file;
71808
71809+#ifdef CONFIG_PAX_SEGMEXEC
71810+ if (vma_m)
71811+ BUG_ON(pax_mirror_vma(vma_m, vma));
71812+#endif
71813+
71814 /* Once vma denies write, undo our temporary denial count */
71815 if (correct_wcount)
71816 atomic_inc(&inode->i_writecount);
71817@@ -1366,6 +1515,7 @@ out:
71818
71819 mm->total_vm += len >> PAGE_SHIFT;
71820 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
71821+ track_exec_limit(mm, addr, addr + len, vm_flags);
71822 if (vm_flags & VM_LOCKED) {
71823 if (!mlock_vma_pages_range(vma, addr, addr + len))
71824 mm->locked_vm += (len >> PAGE_SHIFT);
71825@@ -1383,6 +1533,12 @@ unmap_and_free_vma:
71826 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
71827 charged = 0;
71828 free_vma:
71829+
71830+#ifdef CONFIG_PAX_SEGMEXEC
71831+ if (vma_m)
71832+ kmem_cache_free(vm_area_cachep, vma_m);
71833+#endif
71834+
71835 kmem_cache_free(vm_area_cachep, vma);
71836 unacct_error:
71837 if (charged)
71838@@ -1390,6 +1546,44 @@ unacct_error:
71839 return error;
71840 }
71841
71842+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
71843+{
71844+ if (!vma) {
71845+#ifdef CONFIG_STACK_GROWSUP
71846+ if (addr > sysctl_heap_stack_gap)
71847+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
71848+ else
71849+ vma = find_vma(current->mm, 0);
71850+ if (vma && (vma->vm_flags & VM_GROWSUP))
71851+ return false;
71852+#endif
71853+ return true;
71854+ }
71855+
71856+ if (addr + len > vma->vm_start)
71857+ return false;
71858+
71859+ if (vma->vm_flags & VM_GROWSDOWN)
71860+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
71861+#ifdef CONFIG_STACK_GROWSUP
71862+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
71863+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
71864+#endif
71865+
71866+ return true;
71867+}
71868+
71869+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
71870+{
71871+ if (vma->vm_start < len)
71872+ return -ENOMEM;
71873+ if (!(vma->vm_flags & VM_GROWSDOWN))
71874+ return vma->vm_start - len;
71875+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
71876+ return vma->vm_start - len - sysctl_heap_stack_gap;
71877+ return -ENOMEM;
71878+}
71879+
71880 /* Get an address range which is currently unmapped.
71881 * For shmat() with addr=0.
71882 *
71883@@ -1416,18 +1610,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
71884 if (flags & MAP_FIXED)
71885 return addr;
71886
71887+#ifdef CONFIG_PAX_RANDMMAP
71888+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71889+#endif
71890+
71891 if (addr) {
71892 addr = PAGE_ALIGN(addr);
71893- vma = find_vma(mm, addr);
71894- if (TASK_SIZE - len >= addr &&
71895- (!vma || addr + len <= vma->vm_start))
71896- return addr;
71897+ if (TASK_SIZE - len >= addr) {
71898+ vma = find_vma(mm, addr);
71899+ if (check_heap_stack_gap(vma, addr, len))
71900+ return addr;
71901+ }
71902 }
71903 if (len > mm->cached_hole_size) {
71904- start_addr = addr = mm->free_area_cache;
71905+ start_addr = addr = mm->free_area_cache;
71906 } else {
71907- start_addr = addr = TASK_UNMAPPED_BASE;
71908- mm->cached_hole_size = 0;
71909+ start_addr = addr = mm->mmap_base;
71910+ mm->cached_hole_size = 0;
71911 }
71912
71913 full_search:
71914@@ -1438,34 +1637,40 @@ full_search:
71915 * Start a new search - just in case we missed
71916 * some holes.
71917 */
71918- if (start_addr != TASK_UNMAPPED_BASE) {
71919- addr = TASK_UNMAPPED_BASE;
71920- start_addr = addr;
71921+ if (start_addr != mm->mmap_base) {
71922+ start_addr = addr = mm->mmap_base;
71923 mm->cached_hole_size = 0;
71924 goto full_search;
71925 }
71926 return -ENOMEM;
71927 }
71928- if (!vma || addr + len <= vma->vm_start) {
71929- /*
71930- * Remember the place where we stopped the search:
71931- */
71932- mm->free_area_cache = addr + len;
71933- return addr;
71934- }
71935+ if (check_heap_stack_gap(vma, addr, len))
71936+ break;
71937 if (addr + mm->cached_hole_size < vma->vm_start)
71938 mm->cached_hole_size = vma->vm_start - addr;
71939 addr = vma->vm_end;
71940 }
71941+
71942+ /*
71943+ * Remember the place where we stopped the search:
71944+ */
71945+ mm->free_area_cache = addr + len;
71946+ return addr;
71947 }
71948 #endif
71949
71950 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71951 {
71952+
71953+#ifdef CONFIG_PAX_SEGMEXEC
71954+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71955+ return;
71956+#endif
71957+
71958 /*
71959 * Is this a new hole at the lowest possible address?
71960 */
71961- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
71962+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
71963 mm->free_area_cache = addr;
71964 }
71965
71966@@ -1481,7 +1686,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71967 {
71968 struct vm_area_struct *vma;
71969 struct mm_struct *mm = current->mm;
71970- unsigned long addr = addr0, start_addr;
71971+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
71972
71973 /* requested length too big for entire address space */
71974 if (len > TASK_SIZE)
71975@@ -1490,13 +1695,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71976 if (flags & MAP_FIXED)
71977 return addr;
71978
71979+#ifdef CONFIG_PAX_RANDMMAP
71980+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71981+#endif
71982+
71983 /* requesting a specific address */
71984 if (addr) {
71985 addr = PAGE_ALIGN(addr);
71986- vma = find_vma(mm, addr);
71987- if (TASK_SIZE - len >= addr &&
71988- (!vma || addr + len <= vma->vm_start))
71989- return addr;
71990+ if (TASK_SIZE - len >= addr) {
71991+ vma = find_vma(mm, addr);
71992+ if (check_heap_stack_gap(vma, addr, len))
71993+ return addr;
71994+ }
71995 }
71996
71997 /* check if free_area_cache is useful for us */
71998@@ -1520,7 +1730,7 @@ try_again:
71999 * return with success:
72000 */
72001 vma = find_vma(mm, addr);
72002- if (!vma || addr+len <= vma->vm_start)
72003+ if (check_heap_stack_gap(vma, addr, len))
72004 /* remember the address as a hint for next time */
72005 return (mm->free_area_cache = addr);
72006
72007@@ -1529,8 +1739,8 @@ try_again:
72008 mm->cached_hole_size = vma->vm_start - addr;
72009
72010 /* try just below the current vma->vm_start */
72011- addr = vma->vm_start-len;
72012- } while (len < vma->vm_start);
72013+ addr = skip_heap_stack_gap(vma, len);
72014+ } while (!IS_ERR_VALUE(addr));
72015
72016 fail:
72017 /*
72018@@ -1553,13 +1763,21 @@ fail:
72019 * can happen with large stack limits and large mmap()
72020 * allocations.
72021 */
72022+ mm->mmap_base = TASK_UNMAPPED_BASE;
72023+
72024+#ifdef CONFIG_PAX_RANDMMAP
72025+ if (mm->pax_flags & MF_PAX_RANDMMAP)
72026+ mm->mmap_base += mm->delta_mmap;
72027+#endif
72028+
72029+ mm->free_area_cache = mm->mmap_base;
72030 mm->cached_hole_size = ~0UL;
72031- mm->free_area_cache = TASK_UNMAPPED_BASE;
72032 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72033 /*
72034 * Restore the topdown base:
72035 */
72036- mm->free_area_cache = mm->mmap_base;
72037+ mm->mmap_base = base;
72038+ mm->free_area_cache = base;
72039 mm->cached_hole_size = ~0UL;
72040
72041 return addr;
72042@@ -1568,6 +1786,12 @@ fail:
72043
72044 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72045 {
72046+
72047+#ifdef CONFIG_PAX_SEGMEXEC
72048+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72049+ return;
72050+#endif
72051+
72052 /*
72053 * Is this a new hole at the highest possible address?
72054 */
72055@@ -1575,8 +1799,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72056 mm->free_area_cache = addr;
72057
72058 /* dont allow allocations above current base */
72059- if (mm->free_area_cache > mm->mmap_base)
72060+ if (mm->free_area_cache > mm->mmap_base) {
72061 mm->free_area_cache = mm->mmap_base;
72062+ mm->cached_hole_size = ~0UL;
72063+ }
72064 }
72065
72066 unsigned long
72067@@ -1672,6 +1898,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72068 return vma;
72069 }
72070
72071+#ifdef CONFIG_PAX_SEGMEXEC
72072+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72073+{
72074+ struct vm_area_struct *vma_m;
72075+
72076+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72077+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72078+ BUG_ON(vma->vm_mirror);
72079+ return NULL;
72080+ }
72081+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72082+ vma_m = vma->vm_mirror;
72083+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72084+ BUG_ON(vma->vm_file != vma_m->vm_file);
72085+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72086+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72087+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72088+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72089+ return vma_m;
72090+}
72091+#endif
72092+
72093 /*
72094 * Verify that the stack growth is acceptable and
72095 * update accounting. This is shared with both the
72096@@ -1688,6 +1936,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72097 return -ENOMEM;
72098
72099 /* Stack limit test */
72100+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
72101 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72102 return -ENOMEM;
72103
72104@@ -1698,6 +1947,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72105 locked = mm->locked_vm + grow;
72106 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72107 limit >>= PAGE_SHIFT;
72108+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72109 if (locked > limit && !capable(CAP_IPC_LOCK))
72110 return -ENOMEM;
72111 }
72112@@ -1728,37 +1978,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72113 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72114 * vma is the last one with address > vma->vm_end. Have to extend vma.
72115 */
72116+#ifndef CONFIG_IA64
72117+static
72118+#endif
72119 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72120 {
72121 int error;
72122+ bool locknext;
72123
72124 if (!(vma->vm_flags & VM_GROWSUP))
72125 return -EFAULT;
72126
72127+ /* Also guard against wrapping around to address 0. */
72128+ if (address < PAGE_ALIGN(address+1))
72129+ address = PAGE_ALIGN(address+1);
72130+ else
72131+ return -ENOMEM;
72132+
72133 /*
72134 * We must make sure the anon_vma is allocated
72135 * so that the anon_vma locking is not a noop.
72136 */
72137 if (unlikely(anon_vma_prepare(vma)))
72138 return -ENOMEM;
72139+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72140+ if (locknext && anon_vma_prepare(vma->vm_next))
72141+ return -ENOMEM;
72142 vma_lock_anon_vma(vma);
72143+ if (locknext)
72144+ vma_lock_anon_vma(vma->vm_next);
72145
72146 /*
72147 * vma->vm_start/vm_end cannot change under us because the caller
72148 * is required to hold the mmap_sem in read mode. We need the
72149- * anon_vma lock to serialize against concurrent expand_stacks.
72150- * Also guard against wrapping around to address 0.
72151+ * anon_vma locks to serialize against concurrent expand_stacks
72152+ * and expand_upwards.
72153 */
72154- if (address < PAGE_ALIGN(address+4))
72155- address = PAGE_ALIGN(address+4);
72156- else {
72157- vma_unlock_anon_vma(vma);
72158- return -ENOMEM;
72159- }
72160 error = 0;
72161
72162 /* Somebody else might have raced and expanded it already */
72163- if (address > vma->vm_end) {
72164+ 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)
72165+ error = -ENOMEM;
72166+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72167 unsigned long size, grow;
72168
72169 size = address - vma->vm_start;
72170@@ -1773,6 +2034,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72171 }
72172 }
72173 }
72174+ if (locknext)
72175+ vma_unlock_anon_vma(vma->vm_next);
72176 vma_unlock_anon_vma(vma);
72177 khugepaged_enter_vma_merge(vma);
72178 return error;
72179@@ -1786,6 +2049,8 @@ int expand_downwards(struct vm_area_struct *vma,
72180 unsigned long address)
72181 {
72182 int error;
72183+ bool lockprev = false;
72184+ struct vm_area_struct *prev;
72185
72186 /*
72187 * We must make sure the anon_vma is allocated
72188@@ -1799,6 +2064,15 @@ int expand_downwards(struct vm_area_struct *vma,
72189 if (error)
72190 return error;
72191
72192+ prev = vma->vm_prev;
72193+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72194+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72195+#endif
72196+ if (lockprev && anon_vma_prepare(prev))
72197+ return -ENOMEM;
72198+ if (lockprev)
72199+ vma_lock_anon_vma(prev);
72200+
72201 vma_lock_anon_vma(vma);
72202
72203 /*
72204@@ -1808,9 +2082,17 @@ int expand_downwards(struct vm_area_struct *vma,
72205 */
72206
72207 /* Somebody else might have raced and expanded it already */
72208- if (address < vma->vm_start) {
72209+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72210+ error = -ENOMEM;
72211+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72212 unsigned long size, grow;
72213
72214+#ifdef CONFIG_PAX_SEGMEXEC
72215+ struct vm_area_struct *vma_m;
72216+
72217+ vma_m = pax_find_mirror_vma(vma);
72218+#endif
72219+
72220 size = vma->vm_end - address;
72221 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72222
72223@@ -1820,11 +2102,22 @@ int expand_downwards(struct vm_area_struct *vma,
72224 if (!error) {
72225 vma->vm_start = address;
72226 vma->vm_pgoff -= grow;
72227+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72228+
72229+#ifdef CONFIG_PAX_SEGMEXEC
72230+ if (vma_m) {
72231+ vma_m->vm_start -= grow << PAGE_SHIFT;
72232+ vma_m->vm_pgoff -= grow;
72233+ }
72234+#endif
72235+
72236 perf_event_mmap(vma);
72237 }
72238 }
72239 }
72240 vma_unlock_anon_vma(vma);
72241+ if (lockprev)
72242+ vma_unlock_anon_vma(prev);
72243 khugepaged_enter_vma_merge(vma);
72244 return error;
72245 }
72246@@ -1894,6 +2187,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72247 do {
72248 long nrpages = vma_pages(vma);
72249
72250+#ifdef CONFIG_PAX_SEGMEXEC
72251+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72252+ vma = remove_vma(vma);
72253+ continue;
72254+ }
72255+#endif
72256+
72257 mm->total_vm -= nrpages;
72258 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
72259 vma = remove_vma(vma);
72260@@ -1939,6 +2239,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72261 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72262 vma->vm_prev = NULL;
72263 do {
72264+
72265+#ifdef CONFIG_PAX_SEGMEXEC
72266+ if (vma->vm_mirror) {
72267+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72268+ vma->vm_mirror->vm_mirror = NULL;
72269+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
72270+ vma->vm_mirror = NULL;
72271+ }
72272+#endif
72273+
72274 rb_erase(&vma->vm_rb, &mm->mm_rb);
72275 mm->map_count--;
72276 tail_vma = vma;
72277@@ -1967,14 +2277,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72278 struct vm_area_struct *new;
72279 int err = -ENOMEM;
72280
72281+#ifdef CONFIG_PAX_SEGMEXEC
72282+ struct vm_area_struct *vma_m, *new_m = NULL;
72283+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72284+#endif
72285+
72286 if (is_vm_hugetlb_page(vma) && (addr &
72287 ~(huge_page_mask(hstate_vma(vma)))))
72288 return -EINVAL;
72289
72290+#ifdef CONFIG_PAX_SEGMEXEC
72291+ vma_m = pax_find_mirror_vma(vma);
72292+#endif
72293+
72294 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72295 if (!new)
72296 goto out_err;
72297
72298+#ifdef CONFIG_PAX_SEGMEXEC
72299+ if (vma_m) {
72300+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72301+ if (!new_m) {
72302+ kmem_cache_free(vm_area_cachep, new);
72303+ goto out_err;
72304+ }
72305+ }
72306+#endif
72307+
72308 /* most fields are the same, copy all, and then fixup */
72309 *new = *vma;
72310
72311@@ -1987,6 +2316,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72312 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72313 }
72314
72315+#ifdef CONFIG_PAX_SEGMEXEC
72316+ if (vma_m) {
72317+ *new_m = *vma_m;
72318+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
72319+ new_m->vm_mirror = new;
72320+ new->vm_mirror = new_m;
72321+
72322+ if (new_below)
72323+ new_m->vm_end = addr_m;
72324+ else {
72325+ new_m->vm_start = addr_m;
72326+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72327+ }
72328+ }
72329+#endif
72330+
72331 pol = mpol_dup(vma_policy(vma));
72332 if (IS_ERR(pol)) {
72333 err = PTR_ERR(pol);
72334@@ -2012,6 +2357,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72335 else
72336 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72337
72338+#ifdef CONFIG_PAX_SEGMEXEC
72339+ if (!err && vma_m) {
72340+ if (anon_vma_clone(new_m, vma_m))
72341+ goto out_free_mpol;
72342+
72343+ mpol_get(pol);
72344+ vma_set_policy(new_m, pol);
72345+
72346+ if (new_m->vm_file) {
72347+ get_file(new_m->vm_file);
72348+ if (vma_m->vm_flags & VM_EXECUTABLE)
72349+ added_exe_file_vma(mm);
72350+ }
72351+
72352+ if (new_m->vm_ops && new_m->vm_ops->open)
72353+ new_m->vm_ops->open(new_m);
72354+
72355+ if (new_below)
72356+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72357+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72358+ else
72359+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72360+
72361+ if (err) {
72362+ if (new_m->vm_ops && new_m->vm_ops->close)
72363+ new_m->vm_ops->close(new_m);
72364+ if (new_m->vm_file) {
72365+ if (vma_m->vm_flags & VM_EXECUTABLE)
72366+ removed_exe_file_vma(mm);
72367+ fput(new_m->vm_file);
72368+ }
72369+ mpol_put(pol);
72370+ }
72371+ }
72372+#endif
72373+
72374 /* Success. */
72375 if (!err)
72376 return 0;
72377@@ -2024,10 +2405,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72378 removed_exe_file_vma(mm);
72379 fput(new->vm_file);
72380 }
72381- unlink_anon_vmas(new);
72382 out_free_mpol:
72383 mpol_put(pol);
72384 out_free_vma:
72385+
72386+#ifdef CONFIG_PAX_SEGMEXEC
72387+ if (new_m) {
72388+ unlink_anon_vmas(new_m);
72389+ kmem_cache_free(vm_area_cachep, new_m);
72390+ }
72391+#endif
72392+
72393+ unlink_anon_vmas(new);
72394 kmem_cache_free(vm_area_cachep, new);
72395 out_err:
72396 return err;
72397@@ -2040,6 +2429,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72398 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72399 unsigned long addr, int new_below)
72400 {
72401+
72402+#ifdef CONFIG_PAX_SEGMEXEC
72403+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72404+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72405+ if (mm->map_count >= sysctl_max_map_count-1)
72406+ return -ENOMEM;
72407+ } else
72408+#endif
72409+
72410 if (mm->map_count >= sysctl_max_map_count)
72411 return -ENOMEM;
72412
72413@@ -2051,11 +2449,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72414 * work. This now handles partial unmappings.
72415 * Jeremy Fitzhardinge <jeremy@goop.org>
72416 */
72417+#ifdef CONFIG_PAX_SEGMEXEC
72418 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72419 {
72420+ int ret = __do_munmap(mm, start, len);
72421+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72422+ return ret;
72423+
72424+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72425+}
72426+
72427+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72428+#else
72429+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72430+#endif
72431+{
72432 unsigned long end;
72433 struct vm_area_struct *vma, *prev, *last;
72434
72435+ /*
72436+ * mm->mmap_sem is required to protect against another thread
72437+ * changing the mappings in case we sleep.
72438+ */
72439+ verify_mm_writelocked(mm);
72440+
72441 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72442 return -EINVAL;
72443
72444@@ -2130,6 +2547,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72445 /* Fix up all other VM information */
72446 remove_vma_list(mm, vma);
72447
72448+ track_exec_limit(mm, start, end, 0UL);
72449+
72450 return 0;
72451 }
72452 EXPORT_SYMBOL(do_munmap);
72453@@ -2139,6 +2558,13 @@ int vm_munmap(unsigned long start, size_t len)
72454 int ret;
72455 struct mm_struct *mm = current->mm;
72456
72457+
72458+#ifdef CONFIG_PAX_SEGMEXEC
72459+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72460+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
72461+ return -EINVAL;
72462+#endif
72463+
72464 down_write(&mm->mmap_sem);
72465 ret = do_munmap(mm, start, len);
72466 up_write(&mm->mmap_sem);
72467@@ -2152,16 +2578,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72468 return vm_munmap(addr, len);
72469 }
72470
72471-static inline void verify_mm_writelocked(struct mm_struct *mm)
72472-{
72473-#ifdef CONFIG_DEBUG_VM
72474- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72475- WARN_ON(1);
72476- up_read(&mm->mmap_sem);
72477- }
72478-#endif
72479-}
72480-
72481 /*
72482 * this is really a simplified "do_mmap". it only handles
72483 * anonymous maps. eventually we may be able to do some
72484@@ -2175,6 +2591,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72485 struct rb_node ** rb_link, * rb_parent;
72486 pgoff_t pgoff = addr >> PAGE_SHIFT;
72487 int error;
72488+ unsigned long charged;
72489
72490 len = PAGE_ALIGN(len);
72491 if (!len)
72492@@ -2186,16 +2603,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72493
72494 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72495
72496+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72497+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72498+ flags &= ~VM_EXEC;
72499+
72500+#ifdef CONFIG_PAX_MPROTECT
72501+ if (mm->pax_flags & MF_PAX_MPROTECT)
72502+ flags &= ~VM_MAYEXEC;
72503+#endif
72504+
72505+ }
72506+#endif
72507+
72508 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72509 if (error & ~PAGE_MASK)
72510 return error;
72511
72512+ charged = len >> PAGE_SHIFT;
72513+
72514 /*
72515 * mlock MCL_FUTURE?
72516 */
72517 if (mm->def_flags & VM_LOCKED) {
72518 unsigned long locked, lock_limit;
72519- locked = len >> PAGE_SHIFT;
72520+ locked = charged;
72521 locked += mm->locked_vm;
72522 lock_limit = rlimit(RLIMIT_MEMLOCK);
72523 lock_limit >>= PAGE_SHIFT;
72524@@ -2212,22 +2643,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72525 /*
72526 * Clear old maps. this also does some error checking for us
72527 */
72528- munmap_back:
72529 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72530 if (vma && vma->vm_start < addr + len) {
72531 if (do_munmap(mm, addr, len))
72532 return -ENOMEM;
72533- goto munmap_back;
72534- }
72535+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72536+ BUG_ON(vma && vma->vm_start < addr + len);
72537+ }
72538
72539 /* Check against address space limits *after* clearing old maps... */
72540- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72541+ if (!may_expand_vm(mm, charged))
72542 return -ENOMEM;
72543
72544 if (mm->map_count > sysctl_max_map_count)
72545 return -ENOMEM;
72546
72547- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
72548+ if (security_vm_enough_memory_mm(mm, charged))
72549 return -ENOMEM;
72550
72551 /* Can we just expand an old private anonymous mapping? */
72552@@ -2241,7 +2672,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72553 */
72554 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72555 if (!vma) {
72556- vm_unacct_memory(len >> PAGE_SHIFT);
72557+ vm_unacct_memory(charged);
72558 return -ENOMEM;
72559 }
72560
72561@@ -2255,11 +2686,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72562 vma_link(mm, vma, prev, rb_link, rb_parent);
72563 out:
72564 perf_event_mmap(vma);
72565- mm->total_vm += len >> PAGE_SHIFT;
72566+ mm->total_vm += charged;
72567 if (flags & VM_LOCKED) {
72568 if (!mlock_vma_pages_range(vma, addr, addr + len))
72569- mm->locked_vm += (len >> PAGE_SHIFT);
72570+ mm->locked_vm += charged;
72571 }
72572+ track_exec_limit(mm, addr, addr + len, flags);
72573 return addr;
72574 }
72575
72576@@ -2315,8 +2747,10 @@ void exit_mmap(struct mm_struct *mm)
72577 * Walk the list again, actually closing and freeing it,
72578 * with preemption enabled, without holding any MM locks.
72579 */
72580- while (vma)
72581+ while (vma) {
72582+ vma->vm_mirror = NULL;
72583 vma = remove_vma(vma);
72584+ }
72585
72586 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
72587 }
72588@@ -2330,6 +2764,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72589 struct vm_area_struct * __vma, * prev;
72590 struct rb_node ** rb_link, * rb_parent;
72591
72592+#ifdef CONFIG_PAX_SEGMEXEC
72593+ struct vm_area_struct *vma_m = NULL;
72594+#endif
72595+
72596+ if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
72597+ return -EPERM;
72598+
72599 /*
72600 * The vm_pgoff of a purely anonymous vma should be irrelevant
72601 * until its first write fault, when page's anon_vma and index
72602@@ -2352,7 +2793,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72603 if ((vma->vm_flags & VM_ACCOUNT) &&
72604 security_vm_enough_memory_mm(mm, vma_pages(vma)))
72605 return -ENOMEM;
72606+
72607+#ifdef CONFIG_PAX_SEGMEXEC
72608+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
72609+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72610+ if (!vma_m)
72611+ return -ENOMEM;
72612+ }
72613+#endif
72614+
72615 vma_link(mm, vma, prev, rb_link, rb_parent);
72616+
72617+#ifdef CONFIG_PAX_SEGMEXEC
72618+ if (vma_m)
72619+ BUG_ON(pax_mirror_vma(vma_m, vma));
72620+#endif
72621+
72622 return 0;
72623 }
72624
72625@@ -2371,6 +2827,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72626 struct mempolicy *pol;
72627 bool faulted_in_anon_vma = true;
72628
72629+ BUG_ON(vma->vm_mirror);
72630+
72631 /*
72632 * If anonymous vma has not yet been faulted, update new pgoff
72633 * to match new location, to increase its chance of merging.
72634@@ -2438,6 +2896,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72635 return NULL;
72636 }
72637
72638+#ifdef CONFIG_PAX_SEGMEXEC
72639+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
72640+{
72641+ struct vm_area_struct *prev_m;
72642+ struct rb_node **rb_link_m, *rb_parent_m;
72643+ struct mempolicy *pol_m;
72644+
72645+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
72646+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
72647+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
72648+ *vma_m = *vma;
72649+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
72650+ if (anon_vma_clone(vma_m, vma))
72651+ return -ENOMEM;
72652+ pol_m = vma_policy(vma_m);
72653+ mpol_get(pol_m);
72654+ vma_set_policy(vma_m, pol_m);
72655+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
72656+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
72657+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
72658+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
72659+ if (vma_m->vm_file)
72660+ get_file(vma_m->vm_file);
72661+ if (vma_m->vm_ops && vma_m->vm_ops->open)
72662+ vma_m->vm_ops->open(vma_m);
72663+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
72664+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
72665+ vma_m->vm_mirror = vma;
72666+ vma->vm_mirror = vma_m;
72667+ return 0;
72668+}
72669+#endif
72670+
72671 /*
72672 * Return true if the calling process may expand its vm space by the passed
72673 * number of pages
72674@@ -2449,6 +2940,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
72675
72676 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
72677
72678+#ifdef CONFIG_PAX_RANDMMAP
72679+ if (mm->pax_flags & MF_PAX_RANDMMAP)
72680+ cur -= mm->brk_gap;
72681+#endif
72682+
72683+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
72684 if (cur + npages > lim)
72685 return 0;
72686 return 1;
72687@@ -2519,6 +3016,22 @@ int install_special_mapping(struct mm_struct *mm,
72688 vma->vm_start = addr;
72689 vma->vm_end = addr + len;
72690
72691+#ifdef CONFIG_PAX_MPROTECT
72692+ if (mm->pax_flags & MF_PAX_MPROTECT) {
72693+#ifndef CONFIG_PAX_MPROTECT_COMPAT
72694+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
72695+ return -EPERM;
72696+ if (!(vm_flags & VM_EXEC))
72697+ vm_flags &= ~VM_MAYEXEC;
72698+#else
72699+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72700+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72701+#endif
72702+ else
72703+ vm_flags &= ~VM_MAYWRITE;
72704+ }
72705+#endif
72706+
72707 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
72708 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72709
72710diff --git a/mm/mprotect.c b/mm/mprotect.c
72711index a409926..8b32e6d 100644
72712--- a/mm/mprotect.c
72713+++ b/mm/mprotect.c
72714@@ -23,10 +23,17 @@
72715 #include <linux/mmu_notifier.h>
72716 #include <linux/migrate.h>
72717 #include <linux/perf_event.h>
72718+
72719+#ifdef CONFIG_PAX_MPROTECT
72720+#include <linux/elf.h>
72721+#include <linux/binfmts.h>
72722+#endif
72723+
72724 #include <asm/uaccess.h>
72725 #include <asm/pgtable.h>
72726 #include <asm/cacheflush.h>
72727 #include <asm/tlbflush.h>
72728+#include <asm/mmu_context.h>
72729
72730 #ifndef pgprot_modify
72731 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
72732@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
72733 flush_tlb_range(vma, start, end);
72734 }
72735
72736+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72737+/* called while holding the mmap semaphor for writing except stack expansion */
72738+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
72739+{
72740+ unsigned long oldlimit, newlimit = 0UL;
72741+
72742+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
72743+ return;
72744+
72745+ spin_lock(&mm->page_table_lock);
72746+ oldlimit = mm->context.user_cs_limit;
72747+ if ((prot & VM_EXEC) && oldlimit < end)
72748+ /* USER_CS limit moved up */
72749+ newlimit = end;
72750+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
72751+ /* USER_CS limit moved down */
72752+ newlimit = start;
72753+
72754+ if (newlimit) {
72755+ mm->context.user_cs_limit = newlimit;
72756+
72757+#ifdef CONFIG_SMP
72758+ wmb();
72759+ cpus_clear(mm->context.cpu_user_cs_mask);
72760+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
72761+#endif
72762+
72763+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
72764+ }
72765+ spin_unlock(&mm->page_table_lock);
72766+ if (newlimit == end) {
72767+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
72768+
72769+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
72770+ if (is_vm_hugetlb_page(vma))
72771+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
72772+ else
72773+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
72774+ }
72775+}
72776+#endif
72777+
72778 int
72779 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72780 unsigned long start, unsigned long end, unsigned long newflags)
72781@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72782 int error;
72783 int dirty_accountable = 0;
72784
72785+#ifdef CONFIG_PAX_SEGMEXEC
72786+ struct vm_area_struct *vma_m = NULL;
72787+ unsigned long start_m, end_m;
72788+
72789+ start_m = start + SEGMEXEC_TASK_SIZE;
72790+ end_m = end + SEGMEXEC_TASK_SIZE;
72791+#endif
72792+
72793 if (newflags == oldflags) {
72794 *pprev = vma;
72795 return 0;
72796 }
72797
72798+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
72799+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
72800+
72801+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
72802+ return -ENOMEM;
72803+
72804+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
72805+ return -ENOMEM;
72806+ }
72807+
72808 /*
72809 * If we make a private mapping writable we increase our commit;
72810 * but (without finer accounting) cannot reduce our commit if we
72811@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72812 }
72813 }
72814
72815+#ifdef CONFIG_PAX_SEGMEXEC
72816+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
72817+ if (start != vma->vm_start) {
72818+ error = split_vma(mm, vma, start, 1);
72819+ if (error)
72820+ goto fail;
72821+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
72822+ *pprev = (*pprev)->vm_next;
72823+ }
72824+
72825+ if (end != vma->vm_end) {
72826+ error = split_vma(mm, vma, end, 0);
72827+ if (error)
72828+ goto fail;
72829+ }
72830+
72831+ if (pax_find_mirror_vma(vma)) {
72832+ error = __do_munmap(mm, start_m, end_m - start_m);
72833+ if (error)
72834+ goto fail;
72835+ } else {
72836+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72837+ if (!vma_m) {
72838+ error = -ENOMEM;
72839+ goto fail;
72840+ }
72841+ vma->vm_flags = newflags;
72842+ error = pax_mirror_vma(vma_m, vma);
72843+ if (error) {
72844+ vma->vm_flags = oldflags;
72845+ goto fail;
72846+ }
72847+ }
72848+ }
72849+#endif
72850+
72851 /*
72852 * First try to merge with previous and/or next vma.
72853 */
72854@@ -204,9 +307,21 @@ success:
72855 * vm_flags and vm_page_prot are protected by the mmap_sem
72856 * held in write mode.
72857 */
72858+
72859+#ifdef CONFIG_PAX_SEGMEXEC
72860+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
72861+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
72862+#endif
72863+
72864 vma->vm_flags = newflags;
72865+
72866+#ifdef CONFIG_PAX_MPROTECT
72867+ if (mm->binfmt && mm->binfmt->handle_mprotect)
72868+ mm->binfmt->handle_mprotect(vma, newflags);
72869+#endif
72870+
72871 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
72872- vm_get_page_prot(newflags));
72873+ vm_get_page_prot(vma->vm_flags));
72874
72875 if (vma_wants_writenotify(vma)) {
72876 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72877@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72878 end = start + len;
72879 if (end <= start)
72880 return -ENOMEM;
72881+
72882+#ifdef CONFIG_PAX_SEGMEXEC
72883+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72884+ if (end > SEGMEXEC_TASK_SIZE)
72885+ return -EINVAL;
72886+ } else
72887+#endif
72888+
72889+ if (end > TASK_SIZE)
72890+ return -EINVAL;
72891+
72892 if (!arch_validate_prot(prot))
72893 return -EINVAL;
72894
72895@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72896 /*
72897 * Does the application expect PROT_READ to imply PROT_EXEC:
72898 */
72899- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72900+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72901 prot |= PROT_EXEC;
72902
72903 vm_flags = calc_vm_prot_bits(prot);
72904@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72905 if (start > vma->vm_start)
72906 prev = vma;
72907
72908+#ifdef CONFIG_PAX_MPROTECT
72909+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72910+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
72911+#endif
72912+
72913 for (nstart = start ; ; ) {
72914 unsigned long newflags;
72915
72916@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72917
72918 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72919 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72920+ if (prot & (PROT_WRITE | PROT_EXEC))
72921+ gr_log_rwxmprotect(vma->vm_file);
72922+
72923+ error = -EACCES;
72924+ goto out;
72925+ }
72926+
72927+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72928 error = -EACCES;
72929 goto out;
72930 }
72931@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72932 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72933 if (error)
72934 goto out;
72935+
72936+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
72937+
72938 nstart = tmp;
72939
72940 if (nstart < prev->vm_end)
72941diff --git a/mm/mremap.c b/mm/mremap.c
72942index db8d983..76506cb 100644
72943--- a/mm/mremap.c
72944+++ b/mm/mremap.c
72945@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72946 continue;
72947 pte = ptep_get_and_clear(mm, old_addr, old_pte);
72948 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72949+
72950+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72951+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72952+ pte = pte_exprotect(pte);
72953+#endif
72954+
72955 set_pte_at(mm, new_addr, new_pte, pte);
72956 }
72957
72958@@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72959 if (is_vm_hugetlb_page(vma))
72960 goto Einval;
72961
72962+#ifdef CONFIG_PAX_SEGMEXEC
72963+ if (pax_find_mirror_vma(vma))
72964+ goto Einval;
72965+#endif
72966+
72967 /* We can't remap across vm area boundaries */
72968 if (old_len > vma->vm_end - addr)
72969 goto Efault;
72970@@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
72971 unsigned long ret = -EINVAL;
72972 unsigned long charged = 0;
72973 unsigned long map_flags;
72974+ unsigned long pax_task_size = TASK_SIZE;
72975
72976 if (new_addr & ~PAGE_MASK)
72977 goto out;
72978
72979- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72980+#ifdef CONFIG_PAX_SEGMEXEC
72981+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
72982+ pax_task_size = SEGMEXEC_TASK_SIZE;
72983+#endif
72984+
72985+ pax_task_size -= PAGE_SIZE;
72986+
72987+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72988 goto out;
72989
72990 /* Check if the location we're moving into overlaps the
72991 * old location at all, and fail if it does.
72992 */
72993- if ((new_addr <= addr) && (new_addr+new_len) > addr)
72994- goto out;
72995-
72996- if ((addr <= new_addr) && (addr+old_len) > new_addr)
72997+ if (addr + old_len > new_addr && new_addr + new_len > addr)
72998 goto out;
72999
73000 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
73001@@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
73002 struct vm_area_struct *vma;
73003 unsigned long ret = -EINVAL;
73004 unsigned long charged = 0;
73005+ unsigned long pax_task_size = TASK_SIZE;
73006
73007 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
73008 goto out;
73009@@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
73010 if (!new_len)
73011 goto out;
73012
73013+#ifdef CONFIG_PAX_SEGMEXEC
73014+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
73015+ pax_task_size = SEGMEXEC_TASK_SIZE;
73016+#endif
73017+
73018+ pax_task_size -= PAGE_SIZE;
73019+
73020+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73021+ old_len > pax_task_size || addr > pax_task_size-old_len)
73022+ goto out;
73023+
73024 if (flags & MREMAP_FIXED) {
73025 if (flags & MREMAP_MAYMOVE)
73026 ret = mremap_to(addr, old_len, new_addr, new_len);
73027@@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
73028 addr + new_len);
73029 }
73030 ret = addr;
73031+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73032 goto out;
73033 }
73034 }
73035@@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
73036 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
73037 if (ret)
73038 goto out;
73039+
73040+ map_flags = vma->vm_flags;
73041 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73042+ if (!(ret & ~PAGE_MASK)) {
73043+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73044+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73045+ }
73046 }
73047 out:
73048 if (ret & ~PAGE_MASK)
73049diff --git a/mm/nommu.c b/mm/nommu.c
73050index bb8f4f0..40d3e02 100644
73051--- a/mm/nommu.c
73052+++ b/mm/nommu.c
73053@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73054 int sysctl_overcommit_ratio = 50; /* default is 50% */
73055 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73056 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73057-int heap_stack_gap = 0;
73058
73059 atomic_long_t mmap_pages_allocated;
73060
73061@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73062 EXPORT_SYMBOL(find_vma);
73063
73064 /*
73065- * find a VMA
73066- * - we don't extend stack VMAs under NOMMU conditions
73067- */
73068-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73069-{
73070- return find_vma(mm, addr);
73071-}
73072-
73073-/*
73074 * expand a stack to a given address
73075 * - not supported under NOMMU conditions
73076 */
73077@@ -1580,6 +1570,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73078
73079 /* most fields are the same, copy all, and then fixup */
73080 *new = *vma;
73081+ INIT_LIST_HEAD(&new->anon_vma_chain);
73082 *region = *vma->vm_region;
73083 new->vm_region = region;
73084
73085diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73086index 918330f..ae99ae1 100644
73087--- a/mm/page_alloc.c
73088+++ b/mm/page_alloc.c
73089@@ -335,7 +335,7 @@ out:
73090 * This usage means that zero-order pages may not be compound.
73091 */
73092
73093-static void free_compound_page(struct page *page)
73094+void free_compound_page(struct page *page)
73095 {
73096 __free_pages_ok(page, compound_order(page));
73097 }
73098@@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73099 int i;
73100 int bad = 0;
73101
73102+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73103+ unsigned long index = 1UL << order;
73104+#endif
73105+
73106 trace_mm_page_free(page, order);
73107 kmemcheck_free_shadow(page, order);
73108
73109@@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73110 debug_check_no_obj_freed(page_address(page),
73111 PAGE_SIZE << order);
73112 }
73113+
73114+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73115+ for (; index; --index)
73116+ sanitize_highpage(page + index - 1);
73117+#endif
73118+
73119 arch_free_page(page, order);
73120 kernel_map_pages(page, 1 << order, 0);
73121
73122@@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73123 arch_alloc_page(page, order);
73124 kernel_map_pages(page, 1 << order, 1);
73125
73126+#ifndef CONFIG_PAX_MEMORY_SANITIZE
73127 if (gfp_flags & __GFP_ZERO)
73128 prep_zero_page(page, order, gfp_flags);
73129+#endif
73130
73131 if (order && (gfp_flags & __GFP_COMP))
73132 prep_compound_page(page, order);
73133@@ -3523,7 +3535,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73134 unsigned long pfn;
73135
73136 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73137+#ifdef CONFIG_X86_32
73138+ /* boot failures in VMware 8 on 32bit vanilla since
73139+ this change */
73140+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73141+#else
73142 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73143+#endif
73144 return 1;
73145 }
73146 return 0;
73147diff --git a/mm/percpu.c b/mm/percpu.c
73148index bb4be74..a43ea85 100644
73149--- a/mm/percpu.c
73150+++ b/mm/percpu.c
73151@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73152 static unsigned int pcpu_high_unit_cpu __read_mostly;
73153
73154 /* the address of the first chunk which starts with the kernel static area */
73155-void *pcpu_base_addr __read_mostly;
73156+void *pcpu_base_addr __read_only;
73157 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73158
73159 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73160diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73161index c20ff48..137702a 100644
73162--- a/mm/process_vm_access.c
73163+++ b/mm/process_vm_access.c
73164@@ -13,6 +13,7 @@
73165 #include <linux/uio.h>
73166 #include <linux/sched.h>
73167 #include <linux/highmem.h>
73168+#include <linux/security.h>
73169 #include <linux/ptrace.h>
73170 #include <linux/slab.h>
73171 #include <linux/syscalls.h>
73172@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73173 size_t iov_l_curr_offset = 0;
73174 ssize_t iov_len;
73175
73176+ return -ENOSYS; // PaX: until properly audited
73177+
73178 /*
73179 * Work out how many pages of struct pages we're going to need
73180 * when eventually calling get_user_pages
73181 */
73182 for (i = 0; i < riovcnt; i++) {
73183 iov_len = rvec[i].iov_len;
73184- if (iov_len > 0) {
73185- nr_pages_iov = ((unsigned long)rvec[i].iov_base
73186- + iov_len)
73187- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73188- / PAGE_SIZE + 1;
73189- nr_pages = max(nr_pages, nr_pages_iov);
73190- }
73191+ if (iov_len <= 0)
73192+ continue;
73193+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73194+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73195+ nr_pages = max(nr_pages, nr_pages_iov);
73196 }
73197
73198 if (nr_pages == 0)
73199@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73200 goto free_proc_pages;
73201 }
73202
73203+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73204+ rc = -EPERM;
73205+ goto put_task_struct;
73206+ }
73207+
73208 mm = mm_access(task, PTRACE_MODE_ATTACH);
73209 if (!mm || IS_ERR(mm)) {
73210 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73211diff --git a/mm/rmap.c b/mm/rmap.c
73212index 5b5ad58..0f77903 100644
73213--- a/mm/rmap.c
73214+++ b/mm/rmap.c
73215@@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73216 struct anon_vma *anon_vma = vma->anon_vma;
73217 struct anon_vma_chain *avc;
73218
73219+#ifdef CONFIG_PAX_SEGMEXEC
73220+ struct anon_vma_chain *avc_m = NULL;
73221+#endif
73222+
73223 might_sleep();
73224 if (unlikely(!anon_vma)) {
73225 struct mm_struct *mm = vma->vm_mm;
73226@@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73227 if (!avc)
73228 goto out_enomem;
73229
73230+#ifdef CONFIG_PAX_SEGMEXEC
73231+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73232+ if (!avc_m)
73233+ goto out_enomem_free_avc;
73234+#endif
73235+
73236 anon_vma = find_mergeable_anon_vma(vma);
73237 allocated = NULL;
73238 if (!anon_vma) {
73239@@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73240 /* page_table_lock to protect against threads */
73241 spin_lock(&mm->page_table_lock);
73242 if (likely(!vma->anon_vma)) {
73243+
73244+#ifdef CONFIG_PAX_SEGMEXEC
73245+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73246+
73247+ if (vma_m) {
73248+ BUG_ON(vma_m->anon_vma);
73249+ vma_m->anon_vma = anon_vma;
73250+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
73251+ avc_m = NULL;
73252+ }
73253+#endif
73254+
73255 vma->anon_vma = anon_vma;
73256 anon_vma_chain_link(vma, avc, anon_vma);
73257 allocated = NULL;
73258@@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73259
73260 if (unlikely(allocated))
73261 put_anon_vma(allocated);
73262+
73263+#ifdef CONFIG_PAX_SEGMEXEC
73264+ if (unlikely(avc_m))
73265+ anon_vma_chain_free(avc_m);
73266+#endif
73267+
73268 if (unlikely(avc))
73269 anon_vma_chain_free(avc);
73270 }
73271 return 0;
73272
73273 out_enomem_free_avc:
73274+
73275+#ifdef CONFIG_PAX_SEGMEXEC
73276+ if (avc_m)
73277+ anon_vma_chain_free(avc_m);
73278+#endif
73279+
73280 anon_vma_chain_free(avc);
73281 out_enomem:
73282 return -ENOMEM;
73283@@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
73284 * Attach the anon_vmas from src to dst.
73285 * Returns 0 on success, -ENOMEM on failure.
73286 */
73287-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73288+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73289 {
73290 struct anon_vma_chain *avc, *pavc;
73291 struct anon_vma *root = NULL;
73292@@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73293 * the corresponding VMA in the parent process is attached to.
73294 * Returns 0 on success, non-zero on failure.
73295 */
73296-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73297+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73298 {
73299 struct anon_vma_chain *avc;
73300 struct anon_vma *anon_vma;
73301diff --git a/mm/shmem.c b/mm/shmem.c
73302index 9d65a02..7c877e7 100644
73303--- a/mm/shmem.c
73304+++ b/mm/shmem.c
73305@@ -31,7 +31,7 @@
73306 #include <linux/export.h>
73307 #include <linux/swap.h>
73308
73309-static struct vfsmount *shm_mnt;
73310+struct vfsmount *shm_mnt;
73311
73312 #ifdef CONFIG_SHMEM
73313 /*
73314@@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
73315 #define BOGO_DIRENT_SIZE 20
73316
73317 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73318-#define SHORT_SYMLINK_LEN 128
73319+#define SHORT_SYMLINK_LEN 64
73320
73321 struct shmem_xattr {
73322 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73323@@ -2236,8 +2236,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73324 int err = -ENOMEM;
73325
73326 /* Round up to L1_CACHE_BYTES to resist false sharing */
73327- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73328- L1_CACHE_BYTES), GFP_KERNEL);
73329+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73330 if (!sbinfo)
73331 return -ENOMEM;
73332
73333diff --git a/mm/slab.c b/mm/slab.c
73334index e901a36..ca479fc 100644
73335--- a/mm/slab.c
73336+++ b/mm/slab.c
73337@@ -153,7 +153,7 @@
73338
73339 /* Legal flag mask for kmem_cache_create(). */
73340 #if DEBUG
73341-# define CREATE_MASK (SLAB_RED_ZONE | \
73342+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73343 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73344 SLAB_CACHE_DMA | \
73345 SLAB_STORE_USER | \
73346@@ -161,7 +161,7 @@
73347 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73348 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73349 #else
73350-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73351+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73352 SLAB_CACHE_DMA | \
73353 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73354 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73355@@ -290,7 +290,7 @@ struct kmem_list3 {
73356 * Need this for bootstrapping a per node allocator.
73357 */
73358 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73359-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73360+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73361 #define CACHE_CACHE 0
73362 #define SIZE_AC MAX_NUMNODES
73363 #define SIZE_L3 (2 * MAX_NUMNODES)
73364@@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73365 if ((x)->max_freeable < i) \
73366 (x)->max_freeable = i; \
73367 } while (0)
73368-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73369-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73370-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73371-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73372+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73373+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73374+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73375+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73376 #else
73377 #define STATS_INC_ACTIVE(x) do { } while (0)
73378 #define STATS_DEC_ACTIVE(x) do { } while (0)
73379@@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73380 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73381 */
73382 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73383- const struct slab *slab, void *obj)
73384+ const struct slab *slab, const void *obj)
73385 {
73386 u32 offset = (obj - slab->s_mem);
73387 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73388@@ -563,12 +563,13 @@ EXPORT_SYMBOL(malloc_sizes);
73389 struct cache_names {
73390 char *name;
73391 char *name_dma;
73392+ char *name_usercopy;
73393 };
73394
73395 static struct cache_names __initdata cache_names[] = {
73396-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73397+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
73398 #include <linux/kmalloc_sizes.h>
73399- {NULL,}
73400+ {NULL}
73401 #undef CACHE
73402 };
73403
73404@@ -756,6 +757,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
73405 if (unlikely(gfpflags & GFP_DMA))
73406 return csizep->cs_dmacachep;
73407 #endif
73408+
73409+#ifdef CONFIG_PAX_USERCOPY_SLABS
73410+ if (unlikely(gfpflags & GFP_USERCOPY))
73411+ return csizep->cs_usercopycachep;
73412+#endif
73413+
73414 return csizep->cs_cachep;
73415 }
73416
73417@@ -1588,7 +1595,7 @@ void __init kmem_cache_init(void)
73418 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73419 sizes[INDEX_AC].cs_size,
73420 ARCH_KMALLOC_MINALIGN,
73421- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73422+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73423 NULL);
73424
73425 if (INDEX_AC != INDEX_L3) {
73426@@ -1596,7 +1603,7 @@ void __init kmem_cache_init(void)
73427 kmem_cache_create(names[INDEX_L3].name,
73428 sizes[INDEX_L3].cs_size,
73429 ARCH_KMALLOC_MINALIGN,
73430- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73431+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73432 NULL);
73433 }
73434
73435@@ -1614,7 +1621,7 @@ void __init kmem_cache_init(void)
73436 sizes->cs_cachep = kmem_cache_create(names->name,
73437 sizes->cs_size,
73438 ARCH_KMALLOC_MINALIGN,
73439- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73440+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73441 NULL);
73442 }
73443 #ifdef CONFIG_ZONE_DMA
73444@@ -1626,6 +1633,16 @@ void __init kmem_cache_init(void)
73445 SLAB_PANIC,
73446 NULL);
73447 #endif
73448+
73449+#ifdef CONFIG_PAX_USERCOPY_SLABS
73450+ sizes->cs_usercopycachep = kmem_cache_create(
73451+ names->name_usercopy,
73452+ sizes->cs_size,
73453+ ARCH_KMALLOC_MINALIGN,
73454+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73455+ NULL);
73456+#endif
73457+
73458 sizes++;
73459 names++;
73460 }
73461@@ -4390,10 +4407,10 @@ static int s_show(struct seq_file *m, void *p)
73462 }
73463 /* cpu stats */
73464 {
73465- unsigned long allochit = atomic_read(&cachep->allochit);
73466- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73467- unsigned long freehit = atomic_read(&cachep->freehit);
73468- unsigned long freemiss = atomic_read(&cachep->freemiss);
73469+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73470+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73471+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73472+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73473
73474 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73475 allochit, allocmiss, freehit, freemiss);
73476@@ -4652,13 +4669,68 @@ static int __init slab_proc_init(void)
73477 {
73478 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73479 #ifdef CONFIG_DEBUG_SLAB_LEAK
73480- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73481+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73482 #endif
73483 return 0;
73484 }
73485 module_init(slab_proc_init);
73486 #endif
73487
73488+bool is_usercopy_object(const void *ptr)
73489+{
73490+ struct page *page;
73491+ struct kmem_cache *cachep;
73492+
73493+ if (ZERO_OR_NULL_PTR(ptr))
73494+ return false;
73495+
73496+ if (!virt_addr_valid(ptr))
73497+ return false;
73498+
73499+ page = virt_to_head_page(ptr);
73500+
73501+ if (!PageSlab(page))
73502+ return false;
73503+
73504+ cachep = page_get_cache(page);
73505+ return cachep->flags & SLAB_USERCOPY;
73506+}
73507+
73508+#ifdef CONFIG_PAX_USERCOPY
73509+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
73510+{
73511+ struct page *page;
73512+ struct kmem_cache *cachep;
73513+ struct slab *slabp;
73514+ unsigned int objnr;
73515+ unsigned long offset;
73516+
73517+ if (ZERO_OR_NULL_PTR(ptr))
73518+ return "<null>";
73519+
73520+ if (!virt_addr_valid(ptr))
73521+ return NULL;
73522+
73523+ page = virt_to_head_page(ptr);
73524+
73525+ if (!PageSlab(page))
73526+ return NULL;
73527+
73528+ cachep = page_get_cache(page);
73529+ if (!(cachep->flags & SLAB_USERCOPY))
73530+ return cachep->name;
73531+
73532+ slabp = page_get_slab(page);
73533+ objnr = obj_to_index(cachep, slabp, ptr);
73534+ BUG_ON(objnr >= cachep->num);
73535+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73536+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73537+ return NULL;
73538+
73539+ return cachep->name;
73540+}
73541+#endif
73542+
73543 /**
73544 * ksize - get the actual amount of memory allocated for a given object
73545 * @objp: Pointer to the object
73546diff --git a/mm/slob.c b/mm/slob.c
73547index 8105be4..3c15e57 100644
73548--- a/mm/slob.c
73549+++ b/mm/slob.c
73550@@ -29,7 +29,7 @@
73551 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73552 * alloc_pages() directly, allocating compound pages so the page order
73553 * does not have to be separately tracked, and also stores the exact
73554- * allocation size in page->private so that it can be used to accurately
73555+ * allocation size in slob_page->size so that it can be used to accurately
73556 * provide ksize(). These objects are detected in kfree() because slob_page()
73557 * is false for them.
73558 *
73559@@ -58,6 +58,7 @@
73560 */
73561
73562 #include <linux/kernel.h>
73563+#include <linux/sched.h>
73564 #include <linux/slab.h>
73565 #include <linux/mm.h>
73566 #include <linux/swap.h> /* struct reclaim_state */
73567@@ -102,7 +103,8 @@ struct slob_page {
73568 unsigned long flags; /* mandatory */
73569 atomic_t _count; /* mandatory */
73570 slobidx_t units; /* free units left in page */
73571- unsigned long pad[2];
73572+ unsigned long pad[1];
73573+ unsigned long size; /* size when >=PAGE_SIZE */
73574 slob_t *free; /* first free slob_t in page */
73575 struct list_head list; /* linked list of free pages */
73576 };
73577@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73578 */
73579 static inline int is_slob_page(struct slob_page *sp)
73580 {
73581- return PageSlab((struct page *)sp);
73582+ return PageSlab((struct page *)sp) && !sp->size;
73583 }
73584
73585 static inline void set_slob_page(struct slob_page *sp)
73586@@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73587
73588 static inline struct slob_page *slob_page(const void *addr)
73589 {
73590- return (struct slob_page *)virt_to_page(addr);
73591+ return (struct slob_page *)virt_to_head_page(addr);
73592 }
73593
73594 /*
73595@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73596 /*
73597 * Return the size of a slob block.
73598 */
73599-static slobidx_t slob_units(slob_t *s)
73600+static slobidx_t slob_units(const slob_t *s)
73601 {
73602 if (s->units > 0)
73603 return s->units;
73604@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73605 /*
73606 * Return the next free slob block pointer after this one.
73607 */
73608-static slob_t *slob_next(slob_t *s)
73609+static slob_t *slob_next(const slob_t *s)
73610 {
73611 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
73612 slobidx_t next;
73613@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
73614 /*
73615 * Returns true if s is the last free block in its page.
73616 */
73617-static int slob_last(slob_t *s)
73618+static int slob_last(const slob_t *s)
73619 {
73620 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
73621 }
73622@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
73623 if (!page)
73624 return NULL;
73625
73626+ set_slob_page(page);
73627 return page_address(page);
73628 }
73629
73630@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
73631 if (!b)
73632 return NULL;
73633 sp = slob_page(b);
73634- set_slob_page(sp);
73635
73636 spin_lock_irqsave(&slob_lock, flags);
73637 sp->units = SLOB_UNITS(PAGE_SIZE);
73638 sp->free = b;
73639+ sp->size = 0;
73640 INIT_LIST_HEAD(&sp->list);
73641 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
73642 set_slob_page_free(sp, slob_list);
73643@@ -476,10 +479,9 @@ out:
73644 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
73645 */
73646
73647-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73648+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
73649 {
73650- unsigned int *m;
73651- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73652+ slob_t *m;
73653 void *ret;
73654
73655 gfp &= gfp_allowed_mask;
73656@@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73657
73658 if (!m)
73659 return NULL;
73660- *m = size;
73661+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
73662+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
73663+ m[0].units = size;
73664+ m[1].units = align;
73665 ret = (void *)m + align;
73666
73667 trace_kmalloc_node(_RET_IP_, ret,
73668@@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73669 gfp |= __GFP_COMP;
73670 ret = slob_new_pages(gfp, order, node);
73671 if (ret) {
73672- struct page *page;
73673- page = virt_to_page(ret);
73674- page->private = size;
73675+ struct slob_page *sp;
73676+ sp = slob_page(ret);
73677+ sp->size = size;
73678 }
73679
73680 trace_kmalloc_node(_RET_IP_, ret,
73681 size, PAGE_SIZE << order, gfp, node);
73682 }
73683
73684- kmemleak_alloc(ret, size, 1, gfp);
73685+ return ret;
73686+}
73687+
73688+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73689+{
73690+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73691+ void *ret = __kmalloc_node_align(size, gfp, node, align);
73692+
73693+ if (!ZERO_OR_NULL_PTR(ret))
73694+ kmemleak_alloc(ret, size, 1, gfp);
73695 return ret;
73696 }
73697 EXPORT_SYMBOL(__kmalloc_node);
73698@@ -533,13 +547,83 @@ void kfree(const void *block)
73699 sp = slob_page(block);
73700 if (is_slob_page(sp)) {
73701 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73702- unsigned int *m = (unsigned int *)(block - align);
73703- slob_free(m, *m + align);
73704- } else
73705+ slob_t *m = (slob_t *)(block - align);
73706+ slob_free(m, m[0].units + align);
73707+ } else {
73708+ clear_slob_page(sp);
73709+ free_slob_page(sp);
73710+ sp->size = 0;
73711 put_page(&sp->page);
73712+ }
73713 }
73714 EXPORT_SYMBOL(kfree);
73715
73716+bool is_usercopy_object(const void *ptr)
73717+{
73718+ return false;
73719+}
73720+
73721+#ifdef CONFIG_PAX_USERCOPY
73722+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
73723+{
73724+ struct slob_page *sp;
73725+ const slob_t *free;
73726+ const void *base;
73727+ unsigned long flags;
73728+
73729+ if (ZERO_OR_NULL_PTR(ptr))
73730+ return "<null>";
73731+
73732+ if (!virt_addr_valid(ptr))
73733+ return NULL;
73734+
73735+ sp = slob_page(ptr);
73736+ if (!PageSlab((struct page *)sp))
73737+ return NULL;
73738+
73739+ if (sp->size) {
73740+ base = page_address(&sp->page);
73741+ if (base <= ptr && n <= sp->size - (ptr - base))
73742+ return NULL;
73743+ return "<slob>";
73744+ }
73745+
73746+ /* some tricky double walking to find the chunk */
73747+ spin_lock_irqsave(&slob_lock, flags);
73748+ base = (void *)((unsigned long)ptr & PAGE_MASK);
73749+ free = sp->free;
73750+
73751+ while (!slob_last(free) && (void *)free <= ptr) {
73752+ base = free + slob_units(free);
73753+ free = slob_next(free);
73754+ }
73755+
73756+ while (base < (void *)free) {
73757+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
73758+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
73759+ int offset;
73760+
73761+ if (ptr < base + align)
73762+ break;
73763+
73764+ offset = ptr - base - align;
73765+ if (offset >= m) {
73766+ base += size;
73767+ continue;
73768+ }
73769+
73770+ if (n > m - offset)
73771+ break;
73772+
73773+ spin_unlock_irqrestore(&slob_lock, flags);
73774+ return NULL;
73775+ }
73776+
73777+ spin_unlock_irqrestore(&slob_lock, flags);
73778+ return "<slob>";
73779+}
73780+#endif
73781+
73782 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
73783 size_t ksize(const void *block)
73784 {
73785@@ -552,10 +636,10 @@ size_t ksize(const void *block)
73786 sp = slob_page(block);
73787 if (is_slob_page(sp)) {
73788 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73789- unsigned int *m = (unsigned int *)(block - align);
73790- return SLOB_UNITS(*m) * SLOB_UNIT;
73791+ slob_t *m = (slob_t *)(block - align);
73792+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
73793 } else
73794- return sp->page.private;
73795+ return sp->size;
73796 }
73797 EXPORT_SYMBOL(ksize);
73798
73799@@ -571,8 +655,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73800 {
73801 struct kmem_cache *c;
73802
73803+#ifdef CONFIG_PAX_USERCOPY_SLABS
73804+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
73805+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
73806+#else
73807 c = slob_alloc(sizeof(struct kmem_cache),
73808 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
73809+#endif
73810
73811 if (c) {
73812 c->name = name;
73813@@ -614,17 +703,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
73814
73815 lockdep_trace_alloc(flags);
73816
73817+#ifdef CONFIG_PAX_USERCOPY_SLABS
73818+ b = __kmalloc_node_align(c->size, flags, node, c->align);
73819+#else
73820 if (c->size < PAGE_SIZE) {
73821 b = slob_alloc(c->size, flags, c->align, node);
73822 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73823 SLOB_UNITS(c->size) * SLOB_UNIT,
73824 flags, node);
73825 } else {
73826+ struct slob_page *sp;
73827+
73828 b = slob_new_pages(flags, get_order(c->size), node);
73829+ sp = slob_page(b);
73830+ sp->size = c->size;
73831 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73832 PAGE_SIZE << get_order(c->size),
73833 flags, node);
73834 }
73835+#endif
73836
73837 if (c->ctor)
73838 c->ctor(b);
73839@@ -636,10 +733,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
73840
73841 static void __kmem_cache_free(void *b, int size)
73842 {
73843- if (size < PAGE_SIZE)
73844+ struct slob_page *sp = slob_page(b);
73845+
73846+ if (is_slob_page(sp))
73847 slob_free(b, size);
73848- else
73849+ else {
73850+ clear_slob_page(sp);
73851+ free_slob_page(sp);
73852+ sp->size = 0;
73853 slob_free_pages(b, get_order(size));
73854+ }
73855 }
73856
73857 static void kmem_rcu_free(struct rcu_head *head)
73858@@ -652,17 +755,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73859
73860 void kmem_cache_free(struct kmem_cache *c, void *b)
73861 {
73862+ int size = c->size;
73863+
73864+#ifdef CONFIG_PAX_USERCOPY_SLABS
73865+ if (size + c->align < PAGE_SIZE) {
73866+ size += c->align;
73867+ b -= c->align;
73868+ }
73869+#endif
73870+
73871 kmemleak_free_recursive(b, c->flags);
73872 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73873 struct slob_rcu *slob_rcu;
73874- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73875- slob_rcu->size = c->size;
73876+ slob_rcu = b + (size - sizeof(struct slob_rcu));
73877+ slob_rcu->size = size;
73878 call_rcu(&slob_rcu->head, kmem_rcu_free);
73879 } else {
73880- __kmem_cache_free(b, c->size);
73881+ __kmem_cache_free(b, size);
73882 }
73883
73884+#ifdef CONFIG_PAX_USERCOPY_SLABS
73885+ trace_kfree(_RET_IP_, b);
73886+#else
73887 trace_kmem_cache_free(_RET_IP_, b);
73888+#endif
73889+
73890 }
73891 EXPORT_SYMBOL(kmem_cache_free);
73892
73893diff --git a/mm/slub.c b/mm/slub.c
73894index 71de9b5..a93d4a4 100644
73895--- a/mm/slub.c
73896+++ b/mm/slub.c
73897@@ -209,7 +209,7 @@ struct track {
73898
73899 enum track_item { TRACK_ALLOC, TRACK_FREE };
73900
73901-#ifdef CONFIG_SYSFS
73902+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73903 static int sysfs_slab_add(struct kmem_cache *);
73904 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73905 static void sysfs_slab_remove(struct kmem_cache *);
73906@@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
73907 if (!t->addr)
73908 return;
73909
73910- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73911+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73912 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73913 #ifdef CONFIG_STACKTRACE
73914 {
73915@@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73916
73917 page = virt_to_head_page(x);
73918
73919+ BUG_ON(!PageSlab(page));
73920+
73921 slab_free(s, page, x, _RET_IP_);
73922
73923 trace_kmem_cache_free(_RET_IP_, x);
73924@@ -2636,7 +2638,7 @@ static int slub_min_objects;
73925 * Merge control. If this is set then no merging of slab caches will occur.
73926 * (Could be removed. This was introduced to pacify the merge skeptics.)
73927 */
73928-static int slub_nomerge;
73929+static int slub_nomerge = 1;
73930
73931 /*
73932 * Calculate the order of allocation given an slab object size.
73933@@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73934 else
73935 s->cpu_partial = 30;
73936
73937- s->refcount = 1;
73938+ atomic_set(&s->refcount, 1);
73939 #ifdef CONFIG_NUMA
73940 s->remote_node_defrag_ratio = 1000;
73941 #endif
73942@@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73943 void kmem_cache_destroy(struct kmem_cache *s)
73944 {
73945 down_write(&slub_lock);
73946- s->refcount--;
73947- if (!s->refcount) {
73948+ if (atomic_dec_and_test(&s->refcount)) {
73949 list_del(&s->list);
73950 up_write(&slub_lock);
73951 if (kmem_cache_close(s)) {
73952@@ -3223,6 +3224,10 @@ static struct kmem_cache *kmem_cache;
73953 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
73954 #endif
73955
73956+#ifdef CONFIG_PAX_USERCOPY_SLABS
73957+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
73958+#endif
73959+
73960 static int __init setup_slub_min_order(char *str)
73961 {
73962 get_option(&str, &slub_min_order);
73963@@ -3337,6 +3342,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
73964 return kmalloc_dma_caches[index];
73965
73966 #endif
73967+
73968+#ifdef CONFIG_PAX_USERCOPY_SLABS
73969+ if (flags & SLAB_USERCOPY)
73970+ return kmalloc_usercopy_caches[index];
73971+
73972+#endif
73973+
73974 return kmalloc_caches[index];
73975 }
73976
73977@@ -3405,6 +3417,56 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73978 EXPORT_SYMBOL(__kmalloc_node);
73979 #endif
73980
73981+bool is_usercopy_object(const void *ptr)
73982+{
73983+ struct page *page;
73984+ struct kmem_cache *s;
73985+
73986+ if (ZERO_OR_NULL_PTR(ptr))
73987+ return false;
73988+
73989+ if (!virt_addr_valid(ptr))
73990+ return false;
73991+
73992+ page = virt_to_head_page(ptr);
73993+
73994+ if (!PageSlab(page))
73995+ return false;
73996+
73997+ s = page->slab;
73998+ return s->flags & SLAB_USERCOPY;
73999+}
74000+
74001+#ifdef CONFIG_PAX_USERCOPY
74002+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74003+{
74004+ struct page *page;
74005+ struct kmem_cache *s;
74006+ unsigned long offset;
74007+
74008+ if (ZERO_OR_NULL_PTR(ptr))
74009+ return "<null>";
74010+
74011+ if (!virt_addr_valid(ptr))
74012+ return NULL;
74013+
74014+ page = virt_to_head_page(ptr);
74015+
74016+ if (!PageSlab(page))
74017+ return NULL;
74018+
74019+ s = page->slab;
74020+ if (!(s->flags & SLAB_USERCOPY))
74021+ return s->name;
74022+
74023+ offset = (ptr - page_address(page)) % s->size;
74024+ if (offset <= s->objsize && n <= s->objsize - offset)
74025+ return NULL;
74026+
74027+ return s->name;
74028+}
74029+#endif
74030+
74031 size_t ksize(const void *object)
74032 {
74033 struct page *page;
74034@@ -3679,7 +3741,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
74035 int node;
74036
74037 list_add(&s->list, &slab_caches);
74038- s->refcount = -1;
74039+ atomic_set(&s->refcount, -1);
74040
74041 for_each_node_state(node, N_NORMAL_MEMORY) {
74042 struct kmem_cache_node *n = get_node(s, node);
74043@@ -3799,17 +3861,17 @@ void __init kmem_cache_init(void)
74044
74045 /* Caches that are not of the two-to-the-power-of size */
74046 if (KMALLOC_MIN_SIZE <= 32) {
74047- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74048+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74049 caches++;
74050 }
74051
74052 if (KMALLOC_MIN_SIZE <= 64) {
74053- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74054+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74055 caches++;
74056 }
74057
74058 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74059- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74060+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74061 caches++;
74062 }
74063
74064@@ -3851,6 +3913,22 @@ void __init kmem_cache_init(void)
74065 }
74066 }
74067 #endif
74068+
74069+#ifdef CONFIG_PAX_USERCOPY_SLABS
74070+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
74071+ struct kmem_cache *s = kmalloc_caches[i];
74072+
74073+ if (s && s->size) {
74074+ char *name = kasprintf(GFP_NOWAIT,
74075+ "usercopy-kmalloc-%d", s->objsize);
74076+
74077+ BUG_ON(!name);
74078+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
74079+ s->objsize, SLAB_USERCOPY);
74080+ }
74081+ }
74082+#endif
74083+
74084 printk(KERN_INFO
74085 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
74086 " CPUs=%d, Nodes=%d\n",
74087@@ -3877,7 +3955,7 @@ static int slab_unmergeable(struct kmem_cache *s)
74088 /*
74089 * We may have set a slab to be unmergeable during bootstrap.
74090 */
74091- if (s->refcount < 0)
74092+ if (atomic_read(&s->refcount) < 0)
74093 return 1;
74094
74095 return 0;
74096@@ -3936,7 +4014,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74097 down_write(&slub_lock);
74098 s = find_mergeable(size, align, flags, name, ctor);
74099 if (s) {
74100- s->refcount++;
74101+ atomic_inc(&s->refcount);
74102 /*
74103 * Adjust the object sizes so that we clear
74104 * the complete object on kzalloc.
74105@@ -3945,7 +4023,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74106 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74107
74108 if (sysfs_slab_alias(s, name)) {
74109- s->refcount--;
74110+ atomic_dec(&s->refcount);
74111 goto err;
74112 }
74113 up_write(&slub_lock);
74114@@ -4074,7 +4152,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74115 }
74116 #endif
74117
74118-#ifdef CONFIG_SYSFS
74119+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74120 static int count_inuse(struct page *page)
74121 {
74122 return page->inuse;
74123@@ -4461,12 +4539,12 @@ static void resiliency_test(void)
74124 validate_slab_cache(kmalloc_caches[9]);
74125 }
74126 #else
74127-#ifdef CONFIG_SYSFS
74128+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74129 static void resiliency_test(void) {};
74130 #endif
74131 #endif
74132
74133-#ifdef CONFIG_SYSFS
74134+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74135 enum slab_stat_type {
74136 SL_ALL, /* All slabs */
74137 SL_PARTIAL, /* Only partially allocated slabs */
74138@@ -4709,7 +4787,7 @@ SLAB_ATTR_RO(ctor);
74139
74140 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74141 {
74142- return sprintf(buf, "%d\n", s->refcount - 1);
74143+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74144 }
74145 SLAB_ATTR_RO(aliases);
74146
74147@@ -5280,6 +5358,7 @@ static char *create_unique_id(struct kmem_cache *s)
74148 return name;
74149 }
74150
74151+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74152 static int sysfs_slab_add(struct kmem_cache *s)
74153 {
74154 int err;
74155@@ -5342,6 +5421,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74156 kobject_del(&s->kobj);
74157 kobject_put(&s->kobj);
74158 }
74159+#endif
74160
74161 /*
74162 * Need to buffer aliases during bootup until sysfs becomes
74163@@ -5355,6 +5435,7 @@ struct saved_alias {
74164
74165 static struct saved_alias *alias_list;
74166
74167+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74168 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74169 {
74170 struct saved_alias *al;
74171@@ -5377,6 +5458,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74172 alias_list = al;
74173 return 0;
74174 }
74175+#endif
74176
74177 static int __init slab_sysfs_init(void)
74178 {
74179diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
74180index 1b7e22a..3fcd4f3 100644
74181--- a/mm/sparse-vmemmap.c
74182+++ b/mm/sparse-vmemmap.c
74183@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
74184 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74185 if (!p)
74186 return NULL;
74187- pud_populate(&init_mm, pud, p);
74188+ pud_populate_kernel(&init_mm, pud, p);
74189 }
74190 return pud;
74191 }
74192@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74193 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74194 if (!p)
74195 return NULL;
74196- pgd_populate(&init_mm, pgd, p);
74197+ pgd_populate_kernel(&init_mm, pgd, p);
74198 }
74199 return pgd;
74200 }
74201diff --git a/mm/swap.c b/mm/swap.c
74202index 5c13f13..f1cfc13 100644
74203--- a/mm/swap.c
74204+++ b/mm/swap.c
74205@@ -30,6 +30,7 @@
74206 #include <linux/backing-dev.h>
74207 #include <linux/memcontrol.h>
74208 #include <linux/gfp.h>
74209+#include <linux/hugetlb.h>
74210
74211 #include "internal.h"
74212
74213@@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
74214
74215 __page_cache_release(page);
74216 dtor = get_compound_page_dtor(page);
74217+ if (!PageHuge(page))
74218+ BUG_ON(dtor != free_compound_page);
74219 (*dtor)(page);
74220 }
74221
74222diff --git a/mm/swapfile.c b/mm/swapfile.c
74223index 38186d9..bfba6d3 100644
74224--- a/mm/swapfile.c
74225+++ b/mm/swapfile.c
74226@@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
74227
74228 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74229 /* Activity counter to indicate that a swapon or swapoff has occurred */
74230-static atomic_t proc_poll_event = ATOMIC_INIT(0);
74231+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74232
74233 static inline unsigned char swap_count(unsigned char ent)
74234 {
74235@@ -1671,7 +1671,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74236 }
74237 filp_close(swap_file, NULL);
74238 err = 0;
74239- atomic_inc(&proc_poll_event);
74240+ atomic_inc_unchecked(&proc_poll_event);
74241 wake_up_interruptible(&proc_poll_wait);
74242
74243 out_dput:
74244@@ -1687,8 +1687,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74245
74246 poll_wait(file, &proc_poll_wait, wait);
74247
74248- if (seq->poll_event != atomic_read(&proc_poll_event)) {
74249- seq->poll_event = atomic_read(&proc_poll_event);
74250+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74251+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74252 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74253 }
74254
74255@@ -1786,7 +1786,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74256 return ret;
74257
74258 seq = file->private_data;
74259- seq->poll_event = atomic_read(&proc_poll_event);
74260+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74261 return 0;
74262 }
74263
74264@@ -2123,7 +2123,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74265 (p->flags & SWP_DISCARDABLE) ? "D" : "");
74266
74267 mutex_unlock(&swapon_mutex);
74268- atomic_inc(&proc_poll_event);
74269+ atomic_inc_unchecked(&proc_poll_event);
74270 wake_up_interruptible(&proc_poll_wait);
74271
74272 if (S_ISREG(inode->i_mode))
74273diff --git a/mm/util.c b/mm/util.c
74274index ae962b3..0bba886 100644
74275--- a/mm/util.c
74276+++ b/mm/util.c
74277@@ -284,6 +284,12 @@ done:
74278 void arch_pick_mmap_layout(struct mm_struct *mm)
74279 {
74280 mm->mmap_base = TASK_UNMAPPED_BASE;
74281+
74282+#ifdef CONFIG_PAX_RANDMMAP
74283+ if (mm->pax_flags & MF_PAX_RANDMMAP)
74284+ mm->mmap_base += mm->delta_mmap;
74285+#endif
74286+
74287 mm->get_unmapped_area = arch_get_unmapped_area;
74288 mm->unmap_area = arch_unmap_area;
74289 }
74290diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74291index 1196c77..2e608e8 100644
74292--- a/mm/vmalloc.c
74293+++ b/mm/vmalloc.c
74294@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74295
74296 pte = pte_offset_kernel(pmd, addr);
74297 do {
74298- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74299- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74300+
74301+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74302+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74303+ BUG_ON(!pte_exec(*pte));
74304+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74305+ continue;
74306+ }
74307+#endif
74308+
74309+ {
74310+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74311+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74312+ }
74313 } while (pte++, addr += PAGE_SIZE, addr != end);
74314 }
74315
74316@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74317 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74318 {
74319 pte_t *pte;
74320+ int ret = -ENOMEM;
74321
74322 /*
74323 * nr is a running index into the array which helps higher level
74324@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74325 pte = pte_alloc_kernel(pmd, addr);
74326 if (!pte)
74327 return -ENOMEM;
74328+
74329+ pax_open_kernel();
74330 do {
74331 struct page *page = pages[*nr];
74332
74333- if (WARN_ON(!pte_none(*pte)))
74334- return -EBUSY;
74335- if (WARN_ON(!page))
74336- return -ENOMEM;
74337+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74338+ if (pgprot_val(prot) & _PAGE_NX)
74339+#endif
74340+
74341+ if (WARN_ON(!pte_none(*pte))) {
74342+ ret = -EBUSY;
74343+ goto out;
74344+ }
74345+ if (WARN_ON(!page)) {
74346+ ret = -ENOMEM;
74347+ goto out;
74348+ }
74349 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74350 (*nr)++;
74351 } while (pte++, addr += PAGE_SIZE, addr != end);
74352- return 0;
74353+ ret = 0;
74354+out:
74355+ pax_close_kernel();
74356+ return ret;
74357 }
74358
74359 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74360@@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74361 pmd_t *pmd;
74362 unsigned long next;
74363
74364- pmd = pmd_alloc(&init_mm, pud, addr);
74365+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74366 if (!pmd)
74367 return -ENOMEM;
74368 do {
74369@@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
74370 pud_t *pud;
74371 unsigned long next;
74372
74373- pud = pud_alloc(&init_mm, pgd, addr);
74374+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
74375 if (!pud)
74376 return -ENOMEM;
74377 do {
74378@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74379 * and fall back on vmalloc() if that fails. Others
74380 * just put it in the vmalloc space.
74381 */
74382-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74383+#ifdef CONFIG_MODULES
74384+#ifdef MODULES_VADDR
74385 unsigned long addr = (unsigned long)x;
74386 if (addr >= MODULES_VADDR && addr < MODULES_END)
74387 return 1;
74388 #endif
74389+
74390+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74391+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74392+ return 1;
74393+#endif
74394+
74395+#endif
74396+
74397 return is_vmalloc_addr(x);
74398 }
74399
74400@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74401
74402 if (!pgd_none(*pgd)) {
74403 pud_t *pud = pud_offset(pgd, addr);
74404+#ifdef CONFIG_X86
74405+ if (!pud_large(*pud))
74406+#endif
74407 if (!pud_none(*pud)) {
74408 pmd_t *pmd = pmd_offset(pud, addr);
74409+#ifdef CONFIG_X86
74410+ if (!pmd_large(*pmd))
74411+#endif
74412 if (!pmd_none(*pmd)) {
74413 pte_t *ptep, pte;
74414
74415@@ -332,6 +372,10 @@ static void purge_vmap_area_lazy(void);
74416 static struct vmap_area *alloc_vmap_area(unsigned long size,
74417 unsigned long align,
74418 unsigned long vstart, unsigned long vend,
74419+ int node, gfp_t gfp_mask) __size_overflow(1);
74420+static struct vmap_area *alloc_vmap_area(unsigned long size,
74421+ unsigned long align,
74422+ unsigned long vstart, unsigned long vend,
74423 int node, gfp_t gfp_mask)
74424 {
74425 struct vmap_area *va;
74426@@ -1320,6 +1364,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74427 struct vm_struct *area;
74428
74429 BUG_ON(in_interrupt());
74430+
74431+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74432+ if (flags & VM_KERNEXEC) {
74433+ if (start != VMALLOC_START || end != VMALLOC_END)
74434+ return NULL;
74435+ start = (unsigned long)MODULES_EXEC_VADDR;
74436+ end = (unsigned long)MODULES_EXEC_END;
74437+ }
74438+#endif
74439+
74440 if (flags & VM_IOREMAP) {
74441 int bit = fls(size);
74442
74443@@ -1552,6 +1606,11 @@ void *vmap(struct page **pages, unsigned int count,
74444 if (count > totalram_pages)
74445 return NULL;
74446
74447+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74448+ if (!(pgprot_val(prot) & _PAGE_NX))
74449+ flags |= VM_KERNEXEC;
74450+#endif
74451+
74452 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74453 __builtin_return_address(0));
74454 if (!area)
74455@@ -1653,6 +1712,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74456 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74457 goto fail;
74458
74459+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74460+ if (!(pgprot_val(prot) & _PAGE_NX))
74461+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74462+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74463+ else
74464+#endif
74465+
74466 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74467 start, end, node, gfp_mask, caller);
74468 if (!area)
74469@@ -1826,10 +1892,9 @@ EXPORT_SYMBOL(vzalloc_node);
74470 * For tight control over page level allocator and protection flags
74471 * use __vmalloc() instead.
74472 */
74473-
74474 void *vmalloc_exec(unsigned long size)
74475 {
74476- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74477+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74478 -1, __builtin_return_address(0));
74479 }
74480
74481@@ -2124,6 +2189,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74482 unsigned long uaddr = vma->vm_start;
74483 unsigned long usize = vma->vm_end - vma->vm_start;
74484
74485+ BUG_ON(vma->vm_mirror);
74486+
74487 if ((PAGE_SIZE-1) & (unsigned long)addr)
74488 return -EINVAL;
74489
74490@@ -2376,8 +2443,8 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
74491 return NULL;
74492 }
74493
74494- vms = kzalloc(sizeof(vms[0]) * nr_vms, GFP_KERNEL);
74495- vas = kzalloc(sizeof(vas[0]) * nr_vms, GFP_KERNEL);
74496+ vms = kcalloc(nr_vms, sizeof(vms[0]), GFP_KERNEL);
74497+ vas = kcalloc(nr_vms, sizeof(vas[0]), GFP_KERNEL);
74498 if (!vas || !vms)
74499 goto err_free2;
74500
74501diff --git a/mm/vmstat.c b/mm/vmstat.c
74502index 7db1b9b..e9f6b07 100644
74503--- a/mm/vmstat.c
74504+++ b/mm/vmstat.c
74505@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74506 *
74507 * vm_stat contains the global counters
74508 */
74509-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74510+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74511 EXPORT_SYMBOL(vm_stat);
74512
74513 #ifdef CONFIG_SMP
74514@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74515 v = p->vm_stat_diff[i];
74516 p->vm_stat_diff[i] = 0;
74517 local_irq_restore(flags);
74518- atomic_long_add(v, &zone->vm_stat[i]);
74519+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74520 global_diff[i] += v;
74521 #ifdef CONFIG_NUMA
74522 /* 3 seconds idle till flush */
74523@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74524
74525 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74526 if (global_diff[i])
74527- atomic_long_add(global_diff[i], &vm_stat[i]);
74528+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74529 }
74530
74531 #endif
74532@@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
74533 start_cpu_timer(cpu);
74534 #endif
74535 #ifdef CONFIG_PROC_FS
74536- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74537- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74538- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74539- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74540+ {
74541+ mode_t gr_mode = S_IRUGO;
74542+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74543+ gr_mode = S_IRUSR;
74544+#endif
74545+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74546+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74547+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74548+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74549+#else
74550+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74551+#endif
74552+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74553+ }
74554 #endif
74555 return 0;
74556 }
74557diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74558index efea35b..9c8dd0b 100644
74559--- a/net/8021q/vlan.c
74560+++ b/net/8021q/vlan.c
74561@@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74562 err = -EPERM;
74563 if (!capable(CAP_NET_ADMIN))
74564 break;
74565- if ((args.u.name_type >= 0) &&
74566- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74567+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74568 struct vlan_net *vn;
74569
74570 vn = net_generic(net, vlan_net_id);
74571diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74572index fccae26..e7ece2f 100644
74573--- a/net/9p/trans_fd.c
74574+++ b/net/9p/trans_fd.c
74575@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74576 oldfs = get_fs();
74577 set_fs(get_ds());
74578 /* The cast to a user pointer is valid due to the set_fs() */
74579- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74580+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74581 set_fs(oldfs);
74582
74583 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74584diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74585index 876fbe8..8bbea9f 100644
74586--- a/net/atm/atm_misc.c
74587+++ b/net/atm/atm_misc.c
74588@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74589 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74590 return 1;
74591 atm_return(vcc, truesize);
74592- atomic_inc(&vcc->stats->rx_drop);
74593+ atomic_inc_unchecked(&vcc->stats->rx_drop);
74594 return 0;
74595 }
74596 EXPORT_SYMBOL(atm_charge);
74597@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74598 }
74599 }
74600 atm_return(vcc, guess);
74601- atomic_inc(&vcc->stats->rx_drop);
74602+ atomic_inc_unchecked(&vcc->stats->rx_drop);
74603 return NULL;
74604 }
74605 EXPORT_SYMBOL(atm_alloc_charge);
74606@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74607
74608 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74609 {
74610-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74611+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74612 __SONET_ITEMS
74613 #undef __HANDLE_ITEM
74614 }
74615@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74616
74617 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74618 {
74619-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74620+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
74621 __SONET_ITEMS
74622 #undef __HANDLE_ITEM
74623 }
74624diff --git a/net/atm/lec.h b/net/atm/lec.h
74625index dfc0719..47c5322 100644
74626--- a/net/atm/lec.h
74627+++ b/net/atm/lec.h
74628@@ -48,7 +48,7 @@ struct lane2_ops {
74629 const u8 *tlvs, u32 sizeoftlvs);
74630 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
74631 const u8 *tlvs, u32 sizeoftlvs);
74632-};
74633+} __no_const;
74634
74635 /*
74636 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
74637diff --git a/net/atm/mpc.h b/net/atm/mpc.h
74638index 0919a88..a23d54e 100644
74639--- a/net/atm/mpc.h
74640+++ b/net/atm/mpc.h
74641@@ -33,7 +33,7 @@ struct mpoa_client {
74642 struct mpc_parameters parameters; /* parameters for this client */
74643
74644 const struct net_device_ops *old_ops;
74645- struct net_device_ops new_ops;
74646+ net_device_ops_no_const new_ops;
74647 };
74648
74649
74650diff --git a/net/atm/proc.c b/net/atm/proc.c
74651index 0d020de..011c7bb 100644
74652--- a/net/atm/proc.c
74653+++ b/net/atm/proc.c
74654@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
74655 const struct k_atm_aal_stats *stats)
74656 {
74657 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
74658- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
74659- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
74660- atomic_read(&stats->rx_drop));
74661+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
74662+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
74663+ atomic_read_unchecked(&stats->rx_drop));
74664 }
74665
74666 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
74667diff --git a/net/atm/resources.c b/net/atm/resources.c
74668index 23f45ce..c748f1a 100644
74669--- a/net/atm/resources.c
74670+++ b/net/atm/resources.c
74671@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
74672 static void copy_aal_stats(struct k_atm_aal_stats *from,
74673 struct atm_aal_stats *to)
74674 {
74675-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74676+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74677 __AAL_STAT_ITEMS
74678 #undef __HANDLE_ITEM
74679 }
74680@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
74681 static void subtract_aal_stats(struct k_atm_aal_stats *from,
74682 struct atm_aal_stats *to)
74683 {
74684-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74685+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
74686 __AAL_STAT_ITEMS
74687 #undef __HANDLE_ITEM
74688 }
74689diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
74690index a6d5d63..1cc6c2b 100644
74691--- a/net/batman-adv/bat_iv_ogm.c
74692+++ b/net/batman-adv/bat_iv_ogm.c
74693@@ -539,7 +539,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
74694
74695 /* change sequence number to network order */
74696 batman_ogm_packet->seqno =
74697- htonl((uint32_t)atomic_read(&hard_iface->seqno));
74698+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
74699
74700 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
74701 batman_ogm_packet->tt_crc = htons((uint16_t)
74702@@ -559,7 +559,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
74703 else
74704 batman_ogm_packet->gw_flags = NO_FLAGS;
74705
74706- atomic_inc(&hard_iface->seqno);
74707+ atomic_inc_unchecked(&hard_iface->seqno);
74708
74709 slide_own_bcast_window(hard_iface);
74710 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
74711@@ -917,7 +917,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
74712 return;
74713
74714 /* could be changed by schedule_own_packet() */
74715- if_incoming_seqno = atomic_read(&if_incoming->seqno);
74716+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
74717
74718 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
74719
74720diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
74721index 3778977..f6a9450 100644
74722--- a/net/batman-adv/hard-interface.c
74723+++ b/net/batman-adv/hard-interface.c
74724@@ -328,8 +328,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
74725 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
74726 dev_add_pack(&hard_iface->batman_adv_ptype);
74727
74728- atomic_set(&hard_iface->seqno, 1);
74729- atomic_set(&hard_iface->frag_seqno, 1);
74730+ atomic_set_unchecked(&hard_iface->seqno, 1);
74731+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
74732 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
74733 hard_iface->net_dev->name);
74734
74735diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
74736index a5590f4..8d31969 100644
74737--- a/net/batman-adv/soft-interface.c
74738+++ b/net/batman-adv/soft-interface.c
74739@@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
74740
74741 /* set broadcast sequence number */
74742 bcast_packet->seqno =
74743- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
74744+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
74745
74746 add_bcast_packet_to_list(bat_priv, skb, 1);
74747
74748@@ -841,7 +841,7 @@ struct net_device *softif_create(const char *name)
74749 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
74750
74751 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
74752- atomic_set(&bat_priv->bcast_seqno, 1);
74753+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
74754 atomic_set(&bat_priv->ttvn, 0);
74755 atomic_set(&bat_priv->tt_local_changes, 0);
74756 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
74757diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
74758index 302efb5..1590365 100644
74759--- a/net/batman-adv/types.h
74760+++ b/net/batman-adv/types.h
74761@@ -38,8 +38,8 @@ struct hard_iface {
74762 int16_t if_num;
74763 char if_status;
74764 struct net_device *net_dev;
74765- atomic_t seqno;
74766- atomic_t frag_seqno;
74767+ atomic_unchecked_t seqno;
74768+ atomic_unchecked_t frag_seqno;
74769 unsigned char *packet_buff;
74770 int packet_len;
74771 struct kobject *hardif_obj;
74772@@ -155,7 +155,7 @@ struct bat_priv {
74773 atomic_t orig_interval; /* uint */
74774 atomic_t hop_penalty; /* uint */
74775 atomic_t log_level; /* uint */
74776- atomic_t bcast_seqno;
74777+ atomic_unchecked_t bcast_seqno;
74778 atomic_t bcast_queue_left;
74779 atomic_t batman_queue_left;
74780 atomic_t ttvn; /* translation table version number */
74781diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
74782index 676f6a6..3b4e668 100644
74783--- a/net/batman-adv/unicast.c
74784+++ b/net/batman-adv/unicast.c
74785@@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
74786 frag1->flags = UNI_FRAG_HEAD | large_tail;
74787 frag2->flags = large_tail;
74788
74789- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
74790+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
74791 frag1->seqno = htons(seqno - 1);
74792 frag2->seqno = htons(seqno);
74793
74794diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
74795index 5238b6b..c9798ce 100644
74796--- a/net/bluetooth/hci_conn.c
74797+++ b/net/bluetooth/hci_conn.c
74798@@ -233,7 +233,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
74799 memset(&cp, 0, sizeof(cp));
74800
74801 cp.handle = cpu_to_le16(conn->handle);
74802- memcpy(cp.ltk, ltk, sizeof(ltk));
74803+ memcpy(cp.ltk, ltk, sizeof(cp.ltk));
74804
74805 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
74806 }
74807diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
74808index 6f9c25b..d19fd66 100644
74809--- a/net/bluetooth/l2cap_core.c
74810+++ b/net/bluetooth/l2cap_core.c
74811@@ -2466,8 +2466,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
74812 break;
74813
74814 case L2CAP_CONF_RFC:
74815- if (olen == sizeof(rfc))
74816- memcpy(&rfc, (void *)val, olen);
74817+ if (olen != sizeof(rfc))
74818+ break;
74819+
74820+ memcpy(&rfc, (void *)val, olen);
74821
74822 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
74823 rfc.mode != chan->mode)
74824@@ -2585,8 +2587,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
74825
74826 switch (type) {
74827 case L2CAP_CONF_RFC:
74828- if (olen == sizeof(rfc))
74829- memcpy(&rfc, (void *)val, olen);
74830+ if (olen != sizeof(rfc))
74831+ break;
74832+
74833+ memcpy(&rfc, (void *)val, olen);
74834 goto done;
74835 }
74836 }
74837diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
74838index 5fe2ff3..10968b5 100644
74839--- a/net/bridge/netfilter/ebtables.c
74840+++ b/net/bridge/netfilter/ebtables.c
74841@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
74842 tmp.valid_hooks = t->table->valid_hooks;
74843 }
74844 mutex_unlock(&ebt_mutex);
74845- if (copy_to_user(user, &tmp, *len) != 0){
74846+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
74847 BUGPRINT("c2u Didn't work\n");
74848 ret = -EFAULT;
74849 break;
74850diff --git a/net/caif/caif_dev.c b/net/caif/caif_dev.c
74851index aa6f716..7bf4c21 100644
74852--- a/net/caif/caif_dev.c
74853+++ b/net/caif/caif_dev.c
74854@@ -562,9 +562,9 @@ static int __init caif_device_init(void)
74855
74856 static void __exit caif_device_exit(void)
74857 {
74858- unregister_pernet_subsys(&caif_net_ops);
74859 unregister_netdevice_notifier(&caif_device_notifier);
74860 dev_remove_pack(&caif_packet_type);
74861+ unregister_pernet_subsys(&caif_net_ops);
74862 }
74863
74864 module_init(caif_device_init);
74865diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
74866index 5cf5222..6f704ad 100644
74867--- a/net/caif/cfctrl.c
74868+++ b/net/caif/cfctrl.c
74869@@ -9,6 +9,7 @@
74870 #include <linux/stddef.h>
74871 #include <linux/spinlock.h>
74872 #include <linux/slab.h>
74873+#include <linux/sched.h>
74874 #include <net/caif/caif_layer.h>
74875 #include <net/caif/cfpkt.h>
74876 #include <net/caif/cfctrl.h>
74877@@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
74878 memset(&dev_info, 0, sizeof(dev_info));
74879 dev_info.id = 0xff;
74880 cfsrvl_init(&this->serv, 0, &dev_info, false);
74881- atomic_set(&this->req_seq_no, 1);
74882- atomic_set(&this->rsp_seq_no, 1);
74883+ atomic_set_unchecked(&this->req_seq_no, 1);
74884+ atomic_set_unchecked(&this->rsp_seq_no, 1);
74885 this->serv.layer.receive = cfctrl_recv;
74886 sprintf(this->serv.layer.name, "ctrl");
74887 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
74888@@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
74889 struct cfctrl_request_info *req)
74890 {
74891 spin_lock_bh(&ctrl->info_list_lock);
74892- atomic_inc(&ctrl->req_seq_no);
74893- req->sequence_no = atomic_read(&ctrl->req_seq_no);
74894+ atomic_inc_unchecked(&ctrl->req_seq_no);
74895+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
74896 list_add_tail(&req->list, &ctrl->list);
74897 spin_unlock_bh(&ctrl->info_list_lock);
74898 }
74899@@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
74900 if (p != first)
74901 pr_warn("Requests are not received in order\n");
74902
74903- atomic_set(&ctrl->rsp_seq_no,
74904+ atomic_set_unchecked(&ctrl->rsp_seq_no,
74905 p->sequence_no);
74906 list_del(&p->list);
74907 goto out;
74908diff --git a/net/can/gw.c b/net/can/gw.c
74909index 3d79b12..8de85fa 100644
74910--- a/net/can/gw.c
74911+++ b/net/can/gw.c
74912@@ -96,7 +96,7 @@ struct cf_mod {
74913 struct {
74914 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
74915 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
74916- } csumfunc;
74917+ } __no_const csumfunc;
74918 };
74919
74920
74921diff --git a/net/compat.c b/net/compat.c
74922index e055708..3f80795 100644
74923--- a/net/compat.c
74924+++ b/net/compat.c
74925@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
74926 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
74927 __get_user(kmsg->msg_flags, &umsg->msg_flags))
74928 return -EFAULT;
74929- kmsg->msg_name = compat_ptr(tmp1);
74930- kmsg->msg_iov = compat_ptr(tmp2);
74931- kmsg->msg_control = compat_ptr(tmp3);
74932+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
74933+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
74934+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
74935 return 0;
74936 }
74937
74938@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74939
74940 if (kern_msg->msg_namelen) {
74941 if (mode == VERIFY_READ) {
74942- int err = move_addr_to_kernel(kern_msg->msg_name,
74943+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
74944 kern_msg->msg_namelen,
74945 kern_address);
74946 if (err < 0)
74947@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74948 kern_msg->msg_name = NULL;
74949
74950 tot_len = iov_from_user_compat_to_kern(kern_iov,
74951- (struct compat_iovec __user *)kern_msg->msg_iov,
74952+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
74953 kern_msg->msg_iovlen);
74954 if (tot_len >= 0)
74955 kern_msg->msg_iov = kern_iov;
74956@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74957
74958 #define CMSG_COMPAT_FIRSTHDR(msg) \
74959 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
74960- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
74961+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
74962 (struct compat_cmsghdr __user *)NULL)
74963
74964 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
74965 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
74966 (ucmlen) <= (unsigned long) \
74967 ((mhdr)->msg_controllen - \
74968- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
74969+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
74970
74971 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
74972 struct compat_cmsghdr __user *cmsg, int cmsg_len)
74973 {
74974 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
74975- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
74976+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
74977 msg->msg_controllen)
74978 return NULL;
74979 return (struct compat_cmsghdr __user *)ptr;
74980@@ -219,7 +219,7 @@ Efault:
74981
74982 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
74983 {
74984- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74985+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74986 struct compat_cmsghdr cmhdr;
74987 int cmlen;
74988
74989@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74990
74991 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
74992 {
74993- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74994+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74995 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
74996 int fdnum = scm->fp->count;
74997 struct file **fp = scm->fp->fp;
74998@@ -372,7 +372,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
74999 return -EFAULT;
75000 old_fs = get_fs();
75001 set_fs(KERNEL_DS);
75002- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75003+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75004 set_fs(old_fs);
75005
75006 return err;
75007@@ -433,7 +433,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75008 len = sizeof(ktime);
75009 old_fs = get_fs();
75010 set_fs(KERNEL_DS);
75011- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75012+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75013 set_fs(old_fs);
75014
75015 if (!err) {
75016@@ -576,7 +576,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75017 case MCAST_JOIN_GROUP:
75018 case MCAST_LEAVE_GROUP:
75019 {
75020- struct compat_group_req __user *gr32 = (void *)optval;
75021+ struct compat_group_req __user *gr32 = (void __user *)optval;
75022 struct group_req __user *kgr =
75023 compat_alloc_user_space(sizeof(struct group_req));
75024 u32 interface;
75025@@ -597,7 +597,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75026 case MCAST_BLOCK_SOURCE:
75027 case MCAST_UNBLOCK_SOURCE:
75028 {
75029- struct compat_group_source_req __user *gsr32 = (void *)optval;
75030+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75031 struct group_source_req __user *kgsr = compat_alloc_user_space(
75032 sizeof(struct group_source_req));
75033 u32 interface;
75034@@ -618,7 +618,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75035 }
75036 case MCAST_MSFILTER:
75037 {
75038- struct compat_group_filter __user *gf32 = (void *)optval;
75039+ struct compat_group_filter __user *gf32 = (void __user *)optval;
75040 struct group_filter __user *kgf;
75041 u32 interface, fmode, numsrc;
75042
75043@@ -656,7 +656,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75044 char __user *optval, int __user *optlen,
75045 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75046 {
75047- struct compat_group_filter __user *gf32 = (void *)optval;
75048+ struct compat_group_filter __user *gf32 = (void __user *)optval;
75049 struct group_filter __user *kgf;
75050 int __user *koptlen;
75051 u32 interface, fmode, numsrc;
75052diff --git a/net/core/datagram.c b/net/core/datagram.c
75053index e4fbfd6..6a6ac94 100644
75054--- a/net/core/datagram.c
75055+++ b/net/core/datagram.c
75056@@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75057 }
75058
75059 kfree_skb(skb);
75060- atomic_inc(&sk->sk_drops);
75061+ atomic_inc_unchecked(&sk->sk_drops);
75062 sk_mem_reclaim_partial(sk);
75063
75064 return err;
75065diff --git a/net/core/dev.c b/net/core/dev.c
75066index 533c586..f78a55f 100644
75067--- a/net/core/dev.c
75068+++ b/net/core/dev.c
75069@@ -1136,9 +1136,13 @@ void dev_load(struct net *net, const char *name)
75070 if (no_module && capable(CAP_NET_ADMIN))
75071 no_module = request_module("netdev-%s", name);
75072 if (no_module && capable(CAP_SYS_MODULE)) {
75073+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75074+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
75075+#else
75076 if (!request_module("%s", name))
75077 pr_err("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
75078 name);
75079+#endif
75080 }
75081 }
75082 EXPORT_SYMBOL(dev_load);
75083@@ -1602,7 +1606,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75084 {
75085 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75086 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75087- atomic_long_inc(&dev->rx_dropped);
75088+ atomic_long_inc_unchecked(&dev->rx_dropped);
75089 kfree_skb(skb);
75090 return NET_RX_DROP;
75091 }
75092@@ -1612,7 +1616,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75093 nf_reset(skb);
75094
75095 if (unlikely(!is_skb_forwardable(dev, skb))) {
75096- atomic_long_inc(&dev->rx_dropped);
75097+ atomic_long_inc_unchecked(&dev->rx_dropped);
75098 kfree_skb(skb);
75099 return NET_RX_DROP;
75100 }
75101@@ -2042,7 +2046,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75102
75103 struct dev_gso_cb {
75104 void (*destructor)(struct sk_buff *skb);
75105-};
75106+} __no_const;
75107
75108 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75109
75110@@ -2877,7 +2881,7 @@ enqueue:
75111
75112 local_irq_restore(flags);
75113
75114- atomic_long_inc(&skb->dev->rx_dropped);
75115+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75116 kfree_skb(skb);
75117 return NET_RX_DROP;
75118 }
75119@@ -2949,7 +2953,7 @@ int netif_rx_ni(struct sk_buff *skb)
75120 }
75121 EXPORT_SYMBOL(netif_rx_ni);
75122
75123-static void net_tx_action(struct softirq_action *h)
75124+static void net_tx_action(void)
75125 {
75126 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75127
75128@@ -3237,7 +3241,7 @@ ncls:
75129 if (pt_prev) {
75130 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75131 } else {
75132- atomic_long_inc(&skb->dev->rx_dropped);
75133+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75134 kfree_skb(skb);
75135 /* Jamal, now you will not able to escape explaining
75136 * me how you were going to use this. :-)
75137@@ -3797,7 +3801,7 @@ void netif_napi_del(struct napi_struct *napi)
75138 }
75139 EXPORT_SYMBOL(netif_napi_del);
75140
75141-static void net_rx_action(struct softirq_action *h)
75142+static void net_rx_action(void)
75143 {
75144 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75145 unsigned long time_limit = jiffies + 2;
75146@@ -4267,8 +4271,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
75147 else
75148 seq_printf(seq, "%04x", ntohs(pt->type));
75149
75150+#ifdef CONFIG_GRKERNSEC_HIDESYM
75151+ seq_printf(seq, " %-8s %p\n",
75152+ pt->dev ? pt->dev->name : "", NULL);
75153+#else
75154 seq_printf(seq, " %-8s %pF\n",
75155 pt->dev ? pt->dev->name : "", pt->func);
75156+#endif
75157 }
75158
75159 return 0;
75160@@ -5818,7 +5827,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75161 } else {
75162 netdev_stats_to_stats64(storage, &dev->stats);
75163 }
75164- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75165+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75166 return storage;
75167 }
75168 EXPORT_SYMBOL(dev_get_stats);
75169diff --git a/net/core/flow.c b/net/core/flow.c
75170index e318c7e..168b1d0 100644
75171--- a/net/core/flow.c
75172+++ b/net/core/flow.c
75173@@ -61,7 +61,7 @@ struct flow_cache {
75174 struct timer_list rnd_timer;
75175 };
75176
75177-atomic_t flow_cache_genid = ATOMIC_INIT(0);
75178+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75179 EXPORT_SYMBOL(flow_cache_genid);
75180 static struct flow_cache flow_cache_global;
75181 static struct kmem_cache *flow_cachep __read_mostly;
75182@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75183
75184 static int flow_entry_valid(struct flow_cache_entry *fle)
75185 {
75186- if (atomic_read(&flow_cache_genid) != fle->genid)
75187+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75188 return 0;
75189 if (fle->object && !fle->object->ops->check(fle->object))
75190 return 0;
75191@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75192 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75193 fcp->hash_count++;
75194 }
75195- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75196+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75197 flo = fle->object;
75198 if (!flo)
75199 goto ret_object;
75200@@ -280,7 +280,7 @@ nocache:
75201 }
75202 flo = resolver(net, key, family, dir, flo, ctx);
75203 if (fle) {
75204- fle->genid = atomic_read(&flow_cache_genid);
75205+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
75206 if (!IS_ERR(flo))
75207 fle->object = flo;
75208 else
75209diff --git a/net/core/iovec.c b/net/core/iovec.c
75210index 7e7aeb0..2a998cb 100644
75211--- a/net/core/iovec.c
75212+++ b/net/core/iovec.c
75213@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75214 if (m->msg_namelen) {
75215 if (mode == VERIFY_READ) {
75216 void __user *namep;
75217- namep = (void __user __force *) m->msg_name;
75218+ namep = (void __force_user *) m->msg_name;
75219 err = move_addr_to_kernel(namep, m->msg_namelen,
75220 address);
75221 if (err < 0)
75222@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75223 }
75224
75225 size = m->msg_iovlen * sizeof(struct iovec);
75226- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75227+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75228 return -EFAULT;
75229
75230 m->msg_iov = iov;
75231diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75232index 90430b7..0032ec0 100644
75233--- a/net/core/rtnetlink.c
75234+++ b/net/core/rtnetlink.c
75235@@ -56,7 +56,7 @@ struct rtnl_link {
75236 rtnl_doit_func doit;
75237 rtnl_dumpit_func dumpit;
75238 rtnl_calcit_func calcit;
75239-};
75240+} __no_const;
75241
75242 static DEFINE_MUTEX(rtnl_mutex);
75243
75244diff --git a/net/core/scm.c b/net/core/scm.c
75245index 611c5ef..88f6d6d 100644
75246--- a/net/core/scm.c
75247+++ b/net/core/scm.c
75248@@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
75249 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75250 {
75251 struct cmsghdr __user *cm
75252- = (__force struct cmsghdr __user *)msg->msg_control;
75253+ = (struct cmsghdr __force_user *)msg->msg_control;
75254 struct cmsghdr cmhdr;
75255 int cmlen = CMSG_LEN(len);
75256 int err;
75257@@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75258 err = -EFAULT;
75259 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75260 goto out;
75261- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75262+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75263 goto out;
75264 cmlen = CMSG_SPACE(len);
75265 if (msg->msg_controllen < cmlen)
75266@@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
75267 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75268 {
75269 struct cmsghdr __user *cm
75270- = (__force struct cmsghdr __user*)msg->msg_control;
75271+ = (struct cmsghdr __force_user *)msg->msg_control;
75272
75273 int fdmax = 0;
75274 int fdnum = scm->fp->count;
75275@@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75276 if (fdnum < fdmax)
75277 fdmax = fdnum;
75278
75279- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75280+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75281 i++, cmfptr++)
75282 {
75283 int new_fd;
75284diff --git a/net/core/sock.c b/net/core/sock.c
75285index 0f8402e..f0b6338 100644
75286--- a/net/core/sock.c
75287+++ b/net/core/sock.c
75288@@ -340,7 +340,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75289 struct sk_buff_head *list = &sk->sk_receive_queue;
75290
75291 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75292- atomic_inc(&sk->sk_drops);
75293+ atomic_inc_unchecked(&sk->sk_drops);
75294 trace_sock_rcvqueue_full(sk, skb);
75295 return -ENOMEM;
75296 }
75297@@ -350,7 +350,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75298 return err;
75299
75300 if (!sk_rmem_schedule(sk, skb->truesize)) {
75301- atomic_inc(&sk->sk_drops);
75302+ atomic_inc_unchecked(&sk->sk_drops);
75303 return -ENOBUFS;
75304 }
75305
75306@@ -370,7 +370,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75307 skb_dst_force(skb);
75308
75309 spin_lock_irqsave(&list->lock, flags);
75310- skb->dropcount = atomic_read(&sk->sk_drops);
75311+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75312 __skb_queue_tail(list, skb);
75313 spin_unlock_irqrestore(&list->lock, flags);
75314
75315@@ -390,7 +390,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75316 skb->dev = NULL;
75317
75318 if (sk_rcvqueues_full(sk, skb)) {
75319- atomic_inc(&sk->sk_drops);
75320+ atomic_inc_unchecked(&sk->sk_drops);
75321 goto discard_and_relse;
75322 }
75323 if (nested)
75324@@ -408,7 +408,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75325 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75326 } else if (sk_add_backlog(sk, skb)) {
75327 bh_unlock_sock(sk);
75328- atomic_inc(&sk->sk_drops);
75329+ atomic_inc_unchecked(&sk->sk_drops);
75330 goto discard_and_relse;
75331 }
75332
75333@@ -984,7 +984,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75334 if (len > sizeof(peercred))
75335 len = sizeof(peercred);
75336 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75337- if (copy_to_user(optval, &peercred, len))
75338+ if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75339 return -EFAULT;
75340 goto lenout;
75341 }
75342@@ -997,7 +997,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75343 return -ENOTCONN;
75344 if (lv < len)
75345 return -EINVAL;
75346- if (copy_to_user(optval, address, len))
75347+ if (len > sizeof(address) || copy_to_user(optval, address, len))
75348 return -EFAULT;
75349 goto lenout;
75350 }
75351@@ -1043,7 +1043,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75352
75353 if (len > lv)
75354 len = lv;
75355- if (copy_to_user(optval, &v, len))
75356+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
75357 return -EFAULT;
75358 lenout:
75359 if (put_user(len, optlen))
75360@@ -2131,7 +2131,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75361 */
75362 smp_wmb();
75363 atomic_set(&sk->sk_refcnt, 1);
75364- atomic_set(&sk->sk_drops, 0);
75365+ atomic_set_unchecked(&sk->sk_drops, 0);
75366 }
75367 EXPORT_SYMBOL(sock_init_data);
75368
75369diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75370index b9868e1..849f809 100644
75371--- a/net/core/sock_diag.c
75372+++ b/net/core/sock_diag.c
75373@@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75374
75375 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75376 {
75377+#ifndef CONFIG_GRKERNSEC_HIDESYM
75378 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75379 cookie[1] != INET_DIAG_NOCOOKIE) &&
75380 ((u32)(unsigned long)sk != cookie[0] ||
75381 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75382 return -ESTALE;
75383 else
75384+#endif
75385 return 0;
75386 }
75387 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75388
75389 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75390 {
75391+#ifdef CONFIG_GRKERNSEC_HIDESYM
75392+ cookie[0] = 0;
75393+ cookie[1] = 0;
75394+#else
75395 cookie[0] = (u32)(unsigned long)sk;
75396 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75397+#endif
75398 }
75399 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75400
75401diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75402index 02e75d1..9a57a7c 100644
75403--- a/net/decnet/sysctl_net_decnet.c
75404+++ b/net/decnet/sysctl_net_decnet.c
75405@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75406
75407 if (len > *lenp) len = *lenp;
75408
75409- if (copy_to_user(buffer, addr, len))
75410+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
75411 return -EFAULT;
75412
75413 *lenp = len;
75414@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75415
75416 if (len > *lenp) len = *lenp;
75417
75418- if (copy_to_user(buffer, devname, len))
75419+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
75420 return -EFAULT;
75421
75422 *lenp = len;
75423diff --git a/net/econet/Kconfig b/net/econet/Kconfig
75424index 39a2d29..f39c0fe 100644
75425--- a/net/econet/Kconfig
75426+++ b/net/econet/Kconfig
75427@@ -4,7 +4,7 @@
75428
75429 config ECONET
75430 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
75431- depends on EXPERIMENTAL && INET
75432+ depends on EXPERIMENTAL && INET && BROKEN
75433 ---help---
75434 Econet is a fairly old and slow networking protocol mainly used by
75435 Acorn computers to access file and print servers. It uses native
75436diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
75437index c48adc5..667c1d4 100644
75438--- a/net/ipv4/cipso_ipv4.c
75439+++ b/net/ipv4/cipso_ipv4.c
75440@@ -1725,8 +1725,10 @@ int cipso_v4_validate(const struct sk_buff *skb, unsigned char **option)
75441 case CIPSO_V4_TAG_LOCAL:
75442 /* This is a non-standard tag that we only allow for
75443 * local connections, so if the incoming interface is
75444- * not the loopback device drop the packet. */
75445- if (!(skb->dev->flags & IFF_LOOPBACK)) {
75446+ * not the loopback device drop the packet. Further,
75447+ * there is no legitimate reason for setting this from
75448+ * userspace so reject it if skb is NULL. */
75449+ if (skb == NULL || !(skb->dev->flags & IFF_LOOPBACK)) {
75450 err_offset = opt_iter;
75451 goto validate_return_locked;
75452 }
75453diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75454index cbe3a68..a879b75 100644
75455--- a/net/ipv4/fib_frontend.c
75456+++ b/net/ipv4/fib_frontend.c
75457@@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75458 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75459 fib_sync_up(dev);
75460 #endif
75461- atomic_inc(&net->ipv4.dev_addr_genid);
75462+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75463 rt_cache_flush(dev_net(dev), -1);
75464 break;
75465 case NETDEV_DOWN:
75466 fib_del_ifaddr(ifa, NULL);
75467- atomic_inc(&net->ipv4.dev_addr_genid);
75468+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75469 if (ifa->ifa_dev->ifa_list == NULL) {
75470 /* Last address was deleted from this interface.
75471 * Disable IP.
75472@@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75473 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75474 fib_sync_up(dev);
75475 #endif
75476- atomic_inc(&net->ipv4.dev_addr_genid);
75477+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75478 rt_cache_flush(dev_net(dev), -1);
75479 break;
75480 case NETDEV_DOWN:
75481diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75482index 8861f91..ab1e3c1 100644
75483--- a/net/ipv4/fib_semantics.c
75484+++ b/net/ipv4/fib_semantics.c
75485@@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75486 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75487 nh->nh_gw,
75488 nh->nh_parent->fib_scope);
75489- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75490+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75491
75492 return nh->nh_saddr;
75493 }
75494diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75495index 984ec65..97ac518 100644
75496--- a/net/ipv4/inet_hashtables.c
75497+++ b/net/ipv4/inet_hashtables.c
75498@@ -18,12 +18,15 @@
75499 #include <linux/sched.h>
75500 #include <linux/slab.h>
75501 #include <linux/wait.h>
75502+#include <linux/security.h>
75503
75504 #include <net/inet_connection_sock.h>
75505 #include <net/inet_hashtables.h>
75506 #include <net/secure_seq.h>
75507 #include <net/ip.h>
75508
75509+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75510+
75511 /*
75512 * Allocate and initialize a new local port bind bucket.
75513 * The bindhash mutex for snum's hash chain must be held here.
75514@@ -530,6 +533,8 @@ ok:
75515 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75516 spin_unlock(&head->lock);
75517
75518+ gr_update_task_in_ip_table(current, inet_sk(sk));
75519+
75520 if (tw) {
75521 inet_twsk_deschedule(tw, death_row);
75522 while (twrefcnt) {
75523diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75524index dfba343..c827d50 100644
75525--- a/net/ipv4/inetpeer.c
75526+++ b/net/ipv4/inetpeer.c
75527@@ -487,8 +487,8 @@ relookup:
75528 if (p) {
75529 p->daddr = *daddr;
75530 atomic_set(&p->refcnt, 1);
75531- atomic_set(&p->rid, 0);
75532- atomic_set(&p->ip_id_count,
75533+ atomic_set_unchecked(&p->rid, 0);
75534+ atomic_set_unchecked(&p->ip_id_count,
75535 (daddr->family == AF_INET) ?
75536 secure_ip_id(daddr->addr.a4) :
75537 secure_ipv6_id(daddr->addr.a6));
75538diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75539index 3727e23..517f5df 100644
75540--- a/net/ipv4/ip_fragment.c
75541+++ b/net/ipv4/ip_fragment.c
75542@@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75543 return 0;
75544
75545 start = qp->rid;
75546- end = atomic_inc_return(&peer->rid);
75547+ end = atomic_inc_return_unchecked(&peer->rid);
75548 qp->rid = end;
75549
75550 rc = qp->q.fragments && (end - start) > max;
75551diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75552index 2fd0fba..83fac99 100644
75553--- a/net/ipv4/ip_sockglue.c
75554+++ b/net/ipv4/ip_sockglue.c
75555@@ -1137,7 +1137,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75556 len = min_t(unsigned int, len, opt->optlen);
75557 if (put_user(len, optlen))
75558 return -EFAULT;
75559- if (copy_to_user(optval, opt->__data, len))
75560+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75561+ copy_to_user(optval, opt->__data, len))
75562 return -EFAULT;
75563 return 0;
75564 }
75565@@ -1268,7 +1269,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75566 if (sk->sk_type != SOCK_STREAM)
75567 return -ENOPROTOOPT;
75568
75569- msg.msg_control = optval;
75570+ msg.msg_control = (void __force_kernel *)optval;
75571 msg.msg_controllen = len;
75572 msg.msg_flags = flags;
75573
75574diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75575index 92ac7e7..13f93d9 100644
75576--- a/net/ipv4/ipconfig.c
75577+++ b/net/ipv4/ipconfig.c
75578@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75579
75580 mm_segment_t oldfs = get_fs();
75581 set_fs(get_ds());
75582- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75583+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75584 set_fs(oldfs);
75585 return res;
75586 }
75587@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75588
75589 mm_segment_t oldfs = get_fs();
75590 set_fs(get_ds());
75591- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75592+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75593 set_fs(oldfs);
75594 return res;
75595 }
75596@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
75597
75598 mm_segment_t oldfs = get_fs();
75599 set_fs(get_ds());
75600- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
75601+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
75602 set_fs(oldfs);
75603 return res;
75604 }
75605diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
75606index 50009c7..5996a9f 100644
75607--- a/net/ipv4/ping.c
75608+++ b/net/ipv4/ping.c
75609@@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
75610 sk_rmem_alloc_get(sp),
75611 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75612 atomic_read(&sp->sk_refcnt), sp,
75613- atomic_read(&sp->sk_drops), len);
75614+ atomic_read_unchecked(&sp->sk_drops), len);
75615 }
75616
75617 static int ping_seq_show(struct seq_file *seq, void *v)
75618diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
75619index bbd604c..4d5469c 100644
75620--- a/net/ipv4/raw.c
75621+++ b/net/ipv4/raw.c
75622@@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
75623 int raw_rcv(struct sock *sk, struct sk_buff *skb)
75624 {
75625 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
75626- atomic_inc(&sk->sk_drops);
75627+ atomic_inc_unchecked(&sk->sk_drops);
75628 kfree_skb(skb);
75629 return NET_RX_DROP;
75630 }
75631@@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
75632
75633 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
75634 {
75635+ struct icmp_filter filter;
75636+
75637 if (optlen > sizeof(struct icmp_filter))
75638 optlen = sizeof(struct icmp_filter);
75639- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
75640+ if (copy_from_user(&filter, optval, optlen))
75641 return -EFAULT;
75642+ raw_sk(sk)->filter = filter;
75643 return 0;
75644 }
75645
75646 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
75647 {
75648 int len, ret = -EFAULT;
75649+ struct icmp_filter filter;
75650
75651 if (get_user(len, optlen))
75652 goto out;
75653@@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
75654 if (len > sizeof(struct icmp_filter))
75655 len = sizeof(struct icmp_filter);
75656 ret = -EFAULT;
75657- if (put_user(len, optlen) ||
75658- copy_to_user(optval, &raw_sk(sk)->filter, len))
75659+ filter = raw_sk(sk)->filter;
75660+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
75661 goto out;
75662 ret = 0;
75663 out: return ret;
75664@@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75665 sk_wmem_alloc_get(sp),
75666 sk_rmem_alloc_get(sp),
75667 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75668- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75669+ atomic_read(&sp->sk_refcnt),
75670+#ifdef CONFIG_GRKERNSEC_HIDESYM
75671+ NULL,
75672+#else
75673+ sp,
75674+#endif
75675+ atomic_read_unchecked(&sp->sk_drops));
75676 }
75677
75678 static int raw_seq_show(struct seq_file *seq, void *v)
75679diff --git a/net/ipv4/route.c b/net/ipv4/route.c
75680index 167ea10..4b15883 100644
75681--- a/net/ipv4/route.c
75682+++ b/net/ipv4/route.c
75683@@ -312,7 +312,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
75684
75685 static inline int rt_genid(struct net *net)
75686 {
75687- return atomic_read(&net->ipv4.rt_genid);
75688+ return atomic_read_unchecked(&net->ipv4.rt_genid);
75689 }
75690
75691 #ifdef CONFIG_PROC_FS
75692@@ -936,7 +936,7 @@ static void rt_cache_invalidate(struct net *net)
75693 unsigned char shuffle;
75694
75695 get_random_bytes(&shuffle, sizeof(shuffle));
75696- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
75697+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
75698 inetpeer_invalidate_tree(AF_INET);
75699 }
75700
75701@@ -3009,7 +3009,7 @@ static int rt_fill_info(struct net *net,
75702 error = rt->dst.error;
75703 if (peer) {
75704 inet_peer_refcheck(rt->peer);
75705- id = atomic_read(&peer->ip_id_count) & 0xffff;
75706+ id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
75707 if (peer->tcp_ts_stamp) {
75708 ts = peer->tcp_ts;
75709 tsage = get_seconds() - peer->tcp_ts_stamp;
75710diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
75711index 0cb86ce..8e7fda8 100644
75712--- a/net/ipv4/tcp_ipv4.c
75713+++ b/net/ipv4/tcp_ipv4.c
75714@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
75715 EXPORT_SYMBOL(sysctl_tcp_low_latency);
75716
75717
75718+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75719+extern int grsec_enable_blackhole;
75720+#endif
75721+
75722 #ifdef CONFIG_TCP_MD5SIG
75723 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
75724 __be32 daddr, __be32 saddr, const struct tcphdr *th);
75725@@ -1641,6 +1645,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
75726 return 0;
75727
75728 reset:
75729+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75730+ if (!grsec_enable_blackhole)
75731+#endif
75732 tcp_v4_send_reset(rsk, skb);
75733 discard:
75734 kfree_skb(skb);
75735@@ -1703,12 +1710,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
75736 TCP_SKB_CB(skb)->sacked = 0;
75737
75738 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75739- if (!sk)
75740+ if (!sk) {
75741+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75742+ ret = 1;
75743+#endif
75744 goto no_tcp_socket;
75745-
75746+ }
75747 process:
75748- if (sk->sk_state == TCP_TIME_WAIT)
75749+ if (sk->sk_state == TCP_TIME_WAIT) {
75750+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75751+ ret = 2;
75752+#endif
75753 goto do_time_wait;
75754+ }
75755
75756 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
75757 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75758@@ -1758,6 +1772,10 @@ no_tcp_socket:
75759 bad_packet:
75760 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75761 } else {
75762+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75763+ if (!grsec_enable_blackhole || (ret == 1 &&
75764+ (skb->dev->flags & IFF_LOOPBACK)))
75765+#endif
75766 tcp_v4_send_reset(NULL, skb);
75767 }
75768
75769@@ -2419,7 +2437,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
75770 0, /* non standard timer */
75771 0, /* open_requests have no inode */
75772 atomic_read(&sk->sk_refcnt),
75773+#ifdef CONFIG_GRKERNSEC_HIDESYM
75774+ NULL,
75775+#else
75776 req,
75777+#endif
75778 len);
75779 }
75780
75781@@ -2469,7 +2491,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
75782 sock_i_uid(sk),
75783 icsk->icsk_probes_out,
75784 sock_i_ino(sk),
75785- atomic_read(&sk->sk_refcnt), sk,
75786+ atomic_read(&sk->sk_refcnt),
75787+#ifdef CONFIG_GRKERNSEC_HIDESYM
75788+ NULL,
75789+#else
75790+ sk,
75791+#endif
75792 jiffies_to_clock_t(icsk->icsk_rto),
75793 jiffies_to_clock_t(icsk->icsk_ack.ato),
75794 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
75795@@ -2497,7 +2524,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
75796 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
75797 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
75798 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75799- atomic_read(&tw->tw_refcnt), tw, len);
75800+ atomic_read(&tw->tw_refcnt),
75801+#ifdef CONFIG_GRKERNSEC_HIDESYM
75802+ NULL,
75803+#else
75804+ tw,
75805+#endif
75806+ len);
75807 }
75808
75809 #define TMPSZ 150
75810diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
75811index 3cabafb..640525b 100644
75812--- a/net/ipv4/tcp_minisocks.c
75813+++ b/net/ipv4/tcp_minisocks.c
75814@@ -27,6 +27,10 @@
75815 #include <net/inet_common.h>
75816 #include <net/xfrm.h>
75817
75818+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75819+extern int grsec_enable_blackhole;
75820+#endif
75821+
75822 int sysctl_tcp_syncookies __read_mostly = 1;
75823 EXPORT_SYMBOL(sysctl_tcp_syncookies);
75824
75825@@ -753,6 +757,10 @@ listen_overflow:
75826
75827 embryonic_reset:
75828 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
75829+
75830+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75831+ if (!grsec_enable_blackhole)
75832+#endif
75833 if (!(flg & TCP_FLAG_RST))
75834 req->rsk_ops->send_reset(sk, skb);
75835
75836diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
75837index a981cdc..48f4c3a 100644
75838--- a/net/ipv4/tcp_probe.c
75839+++ b/net/ipv4/tcp_probe.c
75840@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
75841 if (cnt + width >= len)
75842 break;
75843
75844- if (copy_to_user(buf + cnt, tbuf, width))
75845+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
75846 return -EFAULT;
75847 cnt += width;
75848 }
75849diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
75850index 34d4a02..3b57f86 100644
75851--- a/net/ipv4/tcp_timer.c
75852+++ b/net/ipv4/tcp_timer.c
75853@@ -22,6 +22,10 @@
75854 #include <linux/gfp.h>
75855 #include <net/tcp.h>
75856
75857+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75858+extern int grsec_lastack_retries;
75859+#endif
75860+
75861 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
75862 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
75863 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
75864@@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
75865 }
75866 }
75867
75868+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75869+ if ((sk->sk_state == TCP_LAST_ACK) &&
75870+ (grsec_lastack_retries > 0) &&
75871+ (grsec_lastack_retries < retry_until))
75872+ retry_until = grsec_lastack_retries;
75873+#endif
75874+
75875 if (retransmits_timed_out(sk, retry_until,
75876 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
75877 /* Has it gone just too far? */
75878diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
75879index fe14105..0618260 100644
75880--- a/net/ipv4/udp.c
75881+++ b/net/ipv4/udp.c
75882@@ -87,6 +87,7 @@
75883 #include <linux/types.h>
75884 #include <linux/fcntl.h>
75885 #include <linux/module.h>
75886+#include <linux/security.h>
75887 #include <linux/socket.h>
75888 #include <linux/sockios.h>
75889 #include <linux/igmp.h>
75890@@ -109,6 +110,10 @@
75891 #include <trace/events/udp.h>
75892 #include "udp_impl.h"
75893
75894+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75895+extern int grsec_enable_blackhole;
75896+#endif
75897+
75898 struct udp_table udp_table __read_mostly;
75899 EXPORT_SYMBOL(udp_table);
75900
75901@@ -567,6 +572,9 @@ found:
75902 return s;
75903 }
75904
75905+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
75906+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
75907+
75908 /*
75909 * This routine is called by the ICMP module when it gets some
75910 * sort of error condition. If err < 0 then the socket should
75911@@ -858,9 +866,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
75912 dport = usin->sin_port;
75913 if (dport == 0)
75914 return -EINVAL;
75915+
75916+ err = gr_search_udp_sendmsg(sk, usin);
75917+ if (err)
75918+ return err;
75919 } else {
75920 if (sk->sk_state != TCP_ESTABLISHED)
75921 return -EDESTADDRREQ;
75922+
75923+ err = gr_search_udp_sendmsg(sk, NULL);
75924+ if (err)
75925+ return err;
75926+
75927 daddr = inet->inet_daddr;
75928 dport = inet->inet_dport;
75929 /* Open fast path for connected socket.
75930@@ -1102,7 +1119,7 @@ static unsigned int first_packet_length(struct sock *sk)
75931 udp_lib_checksum_complete(skb)) {
75932 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75933 IS_UDPLITE(sk));
75934- atomic_inc(&sk->sk_drops);
75935+ atomic_inc_unchecked(&sk->sk_drops);
75936 __skb_unlink(skb, rcvq);
75937 __skb_queue_tail(&list_kill, skb);
75938 }
75939@@ -1188,6 +1205,10 @@ try_again:
75940 if (!skb)
75941 goto out;
75942
75943+ err = gr_search_udp_recvmsg(sk, skb);
75944+ if (err)
75945+ goto out_free;
75946+
75947 ulen = skb->len - sizeof(struct udphdr);
75948 copied = len;
75949 if (copied > ulen)
75950@@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75951
75952 drop:
75953 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75954- atomic_inc(&sk->sk_drops);
75955+ atomic_inc_unchecked(&sk->sk_drops);
75956 kfree_skb(skb);
75957 return -1;
75958 }
75959@@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75960 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
75961
75962 if (!skb1) {
75963- atomic_inc(&sk->sk_drops);
75964+ atomic_inc_unchecked(&sk->sk_drops);
75965 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
75966 IS_UDPLITE(sk));
75967 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75968@@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75969 goto csum_error;
75970
75971 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
75972+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75973+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75974+#endif
75975 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
75976
75977 /*
75978@@ -2094,8 +2118,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
75979 sk_wmem_alloc_get(sp),
75980 sk_rmem_alloc_get(sp),
75981 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75982- atomic_read(&sp->sk_refcnt), sp,
75983- atomic_read(&sp->sk_drops), len);
75984+ atomic_read(&sp->sk_refcnt),
75985+#ifdef CONFIG_GRKERNSEC_HIDESYM
75986+ NULL,
75987+#else
75988+ sp,
75989+#endif
75990+ atomic_read_unchecked(&sp->sk_drops), len);
75991 }
75992
75993 int udp4_seq_show(struct seq_file *seq, void *v)
75994diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
75995index 7d5cb97..c56564f 100644
75996--- a/net/ipv6/addrconf.c
75997+++ b/net/ipv6/addrconf.c
75998@@ -2142,7 +2142,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
75999 p.iph.ihl = 5;
76000 p.iph.protocol = IPPROTO_IPV6;
76001 p.iph.ttl = 64;
76002- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76003+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76004
76005 if (ops->ndo_do_ioctl) {
76006 mm_segment_t oldfs = get_fs();
76007diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76008index 02dd203..e03fcc9 100644
76009--- a/net/ipv6/inet6_connection_sock.c
76010+++ b/net/ipv6/inet6_connection_sock.c
76011@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76012 #ifdef CONFIG_XFRM
76013 {
76014 struct rt6_info *rt = (struct rt6_info *)dst;
76015- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76016+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76017 }
76018 #endif
76019 }
76020@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76021 #ifdef CONFIG_XFRM
76022 if (dst) {
76023 struct rt6_info *rt = (struct rt6_info *)dst;
76024- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76025+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76026 __sk_dst_reset(sk);
76027 dst = NULL;
76028 }
76029diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76030index 63dd1f8..e7f53ca 100644
76031--- a/net/ipv6/ipv6_sockglue.c
76032+++ b/net/ipv6/ipv6_sockglue.c
76033@@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76034 if (sk->sk_type != SOCK_STREAM)
76035 return -ENOPROTOOPT;
76036
76037- msg.msg_control = optval;
76038+ msg.msg_control = (void __force_kernel *)optval;
76039 msg.msg_controllen = len;
76040 msg.msg_flags = flags;
76041
76042diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76043index 5bddea7..82d9d67 100644
76044--- a/net/ipv6/raw.c
76045+++ b/net/ipv6/raw.c
76046@@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76047 {
76048 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76049 skb_checksum_complete(skb)) {
76050- atomic_inc(&sk->sk_drops);
76051+ atomic_inc_unchecked(&sk->sk_drops);
76052 kfree_skb(skb);
76053 return NET_RX_DROP;
76054 }
76055@@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76056 struct raw6_sock *rp = raw6_sk(sk);
76057
76058 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76059- atomic_inc(&sk->sk_drops);
76060+ atomic_inc_unchecked(&sk->sk_drops);
76061 kfree_skb(skb);
76062 return NET_RX_DROP;
76063 }
76064@@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76065
76066 if (inet->hdrincl) {
76067 if (skb_checksum_complete(skb)) {
76068- atomic_inc(&sk->sk_drops);
76069+ atomic_inc_unchecked(&sk->sk_drops);
76070 kfree_skb(skb);
76071 return NET_RX_DROP;
76072 }
76073@@ -602,7 +602,7 @@ out:
76074 return err;
76075 }
76076
76077-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76078+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76079 struct flowi6 *fl6, struct dst_entry **dstp,
76080 unsigned int flags)
76081 {
76082@@ -914,12 +914,15 @@ do_confirm:
76083 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76084 char __user *optval, int optlen)
76085 {
76086+ struct icmp6_filter filter;
76087+
76088 switch (optname) {
76089 case ICMPV6_FILTER:
76090 if (optlen > sizeof(struct icmp6_filter))
76091 optlen = sizeof(struct icmp6_filter);
76092- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76093+ if (copy_from_user(&filter, optval, optlen))
76094 return -EFAULT;
76095+ raw6_sk(sk)->filter = filter;
76096 return 0;
76097 default:
76098 return -ENOPROTOOPT;
76099@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76100 char __user *optval, int __user *optlen)
76101 {
76102 int len;
76103+ struct icmp6_filter filter;
76104
76105 switch (optname) {
76106 case ICMPV6_FILTER:
76107@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76108 len = sizeof(struct icmp6_filter);
76109 if (put_user(len, optlen))
76110 return -EFAULT;
76111- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76112+ filter = raw6_sk(sk)->filter;
76113+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
76114 return -EFAULT;
76115 return 0;
76116 default:
76117@@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76118 0, 0L, 0,
76119 sock_i_uid(sp), 0,
76120 sock_i_ino(sp),
76121- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76122+ atomic_read(&sp->sk_refcnt),
76123+#ifdef CONFIG_GRKERNSEC_HIDESYM
76124+ NULL,
76125+#else
76126+ sp,
76127+#endif
76128+ atomic_read_unchecked(&sp->sk_drops));
76129 }
76130
76131 static int raw6_seq_show(struct seq_file *seq, void *v)
76132diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76133index 98256cf..7f16dbd 100644
76134--- a/net/ipv6/tcp_ipv6.c
76135+++ b/net/ipv6/tcp_ipv6.c
76136@@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76137 }
76138 #endif
76139
76140+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76141+extern int grsec_enable_blackhole;
76142+#endif
76143+
76144 static void tcp_v6_hash(struct sock *sk)
76145 {
76146 if (sk->sk_state != TCP_CLOSE) {
76147@@ -1542,6 +1546,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76148 return 0;
76149
76150 reset:
76151+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76152+ if (!grsec_enable_blackhole)
76153+#endif
76154 tcp_v6_send_reset(sk, skb);
76155 discard:
76156 if (opt_skb)
76157@@ -1623,12 +1630,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76158 TCP_SKB_CB(skb)->sacked = 0;
76159
76160 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76161- if (!sk)
76162+ if (!sk) {
76163+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76164+ ret = 1;
76165+#endif
76166 goto no_tcp_socket;
76167+ }
76168
76169 process:
76170- if (sk->sk_state == TCP_TIME_WAIT)
76171+ if (sk->sk_state == TCP_TIME_WAIT) {
76172+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76173+ ret = 2;
76174+#endif
76175 goto do_time_wait;
76176+ }
76177
76178 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76179 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76180@@ -1676,6 +1691,10 @@ no_tcp_socket:
76181 bad_packet:
76182 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76183 } else {
76184+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76185+ if (!grsec_enable_blackhole || (ret == 1 &&
76186+ (skb->dev->flags & IFF_LOOPBACK)))
76187+#endif
76188 tcp_v6_send_reset(NULL, skb);
76189 }
76190
76191@@ -1930,7 +1949,13 @@ static void get_openreq6(struct seq_file *seq,
76192 uid,
76193 0, /* non standard timer */
76194 0, /* open_requests have no inode */
76195- 0, req);
76196+ 0,
76197+#ifdef CONFIG_GRKERNSEC_HIDESYM
76198+ NULL
76199+#else
76200+ req
76201+#endif
76202+ );
76203 }
76204
76205 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76206@@ -1980,7 +2005,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76207 sock_i_uid(sp),
76208 icsk->icsk_probes_out,
76209 sock_i_ino(sp),
76210- atomic_read(&sp->sk_refcnt), sp,
76211+ atomic_read(&sp->sk_refcnt),
76212+#ifdef CONFIG_GRKERNSEC_HIDESYM
76213+ NULL,
76214+#else
76215+ sp,
76216+#endif
76217 jiffies_to_clock_t(icsk->icsk_rto),
76218 jiffies_to_clock_t(icsk->icsk_ack.ato),
76219 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76220@@ -2015,7 +2045,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76221 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76222 tw->tw_substate, 0, 0,
76223 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76224- atomic_read(&tw->tw_refcnt), tw);
76225+ atomic_read(&tw->tw_refcnt),
76226+#ifdef CONFIG_GRKERNSEC_HIDESYM
76227+ NULL
76228+#else
76229+ tw
76230+#endif
76231+ );
76232 }
76233
76234 static int tcp6_seq_show(struct seq_file *seq, void *v)
76235diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76236index 37b0699..d323408 100644
76237--- a/net/ipv6/udp.c
76238+++ b/net/ipv6/udp.c
76239@@ -50,6 +50,10 @@
76240 #include <linux/seq_file.h>
76241 #include "udp_impl.h"
76242
76243+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76244+extern int grsec_enable_blackhole;
76245+#endif
76246+
76247 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76248 {
76249 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76250@@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
76251
76252 return 0;
76253 drop:
76254- atomic_inc(&sk->sk_drops);
76255+ atomic_inc_unchecked(&sk->sk_drops);
76256 drop_no_sk_drops_inc:
76257 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76258 kfree_skb(skb);
76259@@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76260 continue;
76261 }
76262 drop:
76263- atomic_inc(&sk->sk_drops);
76264+ atomic_inc_unchecked(&sk->sk_drops);
76265 UDP6_INC_STATS_BH(sock_net(sk),
76266 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76267 UDP6_INC_STATS_BH(sock_net(sk),
76268@@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76269 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76270 proto == IPPROTO_UDPLITE);
76271
76272+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76273+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76274+#endif
76275 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76276
76277 kfree_skb(skb);
76278@@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76279 if (!sock_owned_by_user(sk))
76280 udpv6_queue_rcv_skb(sk, skb);
76281 else if (sk_add_backlog(sk, skb)) {
76282- atomic_inc(&sk->sk_drops);
76283+ atomic_inc_unchecked(&sk->sk_drops);
76284 bh_unlock_sock(sk);
76285 sock_put(sk);
76286 goto discard;
76287@@ -1411,8 +1418,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76288 0, 0L, 0,
76289 sock_i_uid(sp), 0,
76290 sock_i_ino(sp),
76291- atomic_read(&sp->sk_refcnt), sp,
76292- atomic_read(&sp->sk_drops));
76293+ atomic_read(&sp->sk_refcnt),
76294+#ifdef CONFIG_GRKERNSEC_HIDESYM
76295+ NULL,
76296+#else
76297+ sp,
76298+#endif
76299+ atomic_read_unchecked(&sp->sk_drops));
76300 }
76301
76302 int udp6_seq_show(struct seq_file *seq, void *v)
76303diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76304index 6b9d5a0..4dffaf1 100644
76305--- a/net/irda/ircomm/ircomm_tty.c
76306+++ b/net/irda/ircomm/ircomm_tty.c
76307@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76308 add_wait_queue(&self->open_wait, &wait);
76309
76310 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76311- __FILE__,__LINE__, tty->driver->name, self->open_count );
76312+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76313
76314 /* As far as I can see, we protect open_count - Jean II */
76315 spin_lock_irqsave(&self->spinlock, flags);
76316 if (!tty_hung_up_p(filp)) {
76317 extra_count = 1;
76318- self->open_count--;
76319+ local_dec(&self->open_count);
76320 }
76321 spin_unlock_irqrestore(&self->spinlock, flags);
76322- self->blocked_open++;
76323+ local_inc(&self->blocked_open);
76324
76325 while (1) {
76326 if (tty->termios->c_cflag & CBAUD) {
76327@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76328 }
76329
76330 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76331- __FILE__,__LINE__, tty->driver->name, self->open_count );
76332+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76333
76334 schedule();
76335 }
76336@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76337 if (extra_count) {
76338 /* ++ is not atomic, so this should be protected - Jean II */
76339 spin_lock_irqsave(&self->spinlock, flags);
76340- self->open_count++;
76341+ local_inc(&self->open_count);
76342 spin_unlock_irqrestore(&self->spinlock, flags);
76343 }
76344- self->blocked_open--;
76345+ local_dec(&self->blocked_open);
76346
76347 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76348- __FILE__,__LINE__, tty->driver->name, self->open_count);
76349+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76350
76351 if (!retval)
76352 self->flags |= ASYNC_NORMAL_ACTIVE;
76353@@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76354 }
76355 /* ++ is not atomic, so this should be protected - Jean II */
76356 spin_lock_irqsave(&self->spinlock, flags);
76357- self->open_count++;
76358+ local_inc(&self->open_count);
76359
76360 tty->driver_data = self;
76361 self->tty = tty;
76362 spin_unlock_irqrestore(&self->spinlock, flags);
76363
76364 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76365- self->line, self->open_count);
76366+ self->line, local_read(&self->open_count));
76367
76368 /* Not really used by us, but lets do it anyway */
76369 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76370@@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76371 return;
76372 }
76373
76374- if ((tty->count == 1) && (self->open_count != 1)) {
76375+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76376 /*
76377 * Uh, oh. tty->count is 1, which means that the tty
76378 * structure will be freed. state->count should always
76379@@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76380 */
76381 IRDA_DEBUG(0, "%s(), bad serial port count; "
76382 "tty->count is 1, state->count is %d\n", __func__ ,
76383- self->open_count);
76384- self->open_count = 1;
76385+ local_read(&self->open_count));
76386+ local_set(&self->open_count, 1);
76387 }
76388
76389- if (--self->open_count < 0) {
76390+ if (local_dec_return(&self->open_count) < 0) {
76391 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76392- __func__, self->line, self->open_count);
76393- self->open_count = 0;
76394+ __func__, self->line, local_read(&self->open_count));
76395+ local_set(&self->open_count, 0);
76396 }
76397- if (self->open_count) {
76398+ if (local_read(&self->open_count)) {
76399 spin_unlock_irqrestore(&self->spinlock, flags);
76400
76401 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76402@@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76403 tty->closing = 0;
76404 self->tty = NULL;
76405
76406- if (self->blocked_open) {
76407+ if (local_read(&self->blocked_open)) {
76408 if (self->close_delay)
76409 schedule_timeout_interruptible(self->close_delay);
76410 wake_up_interruptible(&self->open_wait);
76411@@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76412 spin_lock_irqsave(&self->spinlock, flags);
76413 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76414 self->tty = NULL;
76415- self->open_count = 0;
76416+ local_set(&self->open_count, 0);
76417 spin_unlock_irqrestore(&self->spinlock, flags);
76418
76419 wake_up_interruptible(&self->open_wait);
76420@@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76421 seq_putc(m, '\n');
76422
76423 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76424- seq_printf(m, "Open count: %d\n", self->open_count);
76425+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76426 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76427 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76428
76429diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76430index cd6f7a9..e63fe89 100644
76431--- a/net/iucv/af_iucv.c
76432+++ b/net/iucv/af_iucv.c
76433@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
76434
76435 write_lock_bh(&iucv_sk_list.lock);
76436
76437- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76438+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76439 while (__iucv_get_sock_by_name(name)) {
76440 sprintf(name, "%08x",
76441- atomic_inc_return(&iucv_sk_list.autobind_name));
76442+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76443 }
76444
76445 write_unlock_bh(&iucv_sk_list.lock);
76446diff --git a/net/key/af_key.c b/net/key/af_key.c
76447index 7e5d927..cdbb54e 100644
76448--- a/net/key/af_key.c
76449+++ b/net/key/af_key.c
76450@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76451 static u32 get_acqseq(void)
76452 {
76453 u32 res;
76454- static atomic_t acqseq;
76455+ static atomic_unchecked_t acqseq;
76456
76457 do {
76458- res = atomic_inc_return(&acqseq);
76459+ res = atomic_inc_return_unchecked(&acqseq);
76460 } while (!res);
76461 return res;
76462 }
76463diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76464index db8fae5..ff070cd 100644
76465--- a/net/mac80211/ieee80211_i.h
76466+++ b/net/mac80211/ieee80211_i.h
76467@@ -28,6 +28,7 @@
76468 #include <net/ieee80211_radiotap.h>
76469 #include <net/cfg80211.h>
76470 #include <net/mac80211.h>
76471+#include <asm/local.h>
76472 #include "key.h"
76473 #include "sta_info.h"
76474
76475@@ -842,7 +843,7 @@ struct ieee80211_local {
76476 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76477 spinlock_t queue_stop_reason_lock;
76478
76479- int open_count;
76480+ local_t open_count;
76481 int monitors, cooked_mntrs;
76482 /* number of interfaces with corresponding FIF_ flags */
76483 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76484diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76485index 48f937e..4ccd7b8 100644
76486--- a/net/mac80211/iface.c
76487+++ b/net/mac80211/iface.c
76488@@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76489 break;
76490 }
76491
76492- if (local->open_count == 0) {
76493+ if (local_read(&local->open_count) == 0) {
76494 res = drv_start(local);
76495 if (res)
76496 goto err_del_bss;
76497@@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76498 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
76499
76500 if (!is_valid_ether_addr(dev->dev_addr)) {
76501- if (!local->open_count)
76502+ if (!local_read(&local->open_count))
76503 drv_stop(local);
76504 return -EADDRNOTAVAIL;
76505 }
76506@@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76507 mutex_unlock(&local->mtx);
76508
76509 if (coming_up)
76510- local->open_count++;
76511+ local_inc(&local->open_count);
76512
76513 if (hw_reconf_flags)
76514 ieee80211_hw_config(local, hw_reconf_flags);
76515@@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76516 err_del_interface:
76517 drv_remove_interface(local, sdata);
76518 err_stop:
76519- if (!local->open_count)
76520+ if (!local_read(&local->open_count))
76521 drv_stop(local);
76522 err_del_bss:
76523 sdata->bss = NULL;
76524@@ -491,7 +491,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76525 }
76526
76527 if (going_down)
76528- local->open_count--;
76529+ local_dec(&local->open_count);
76530
76531 switch (sdata->vif.type) {
76532 case NL80211_IFTYPE_AP_VLAN:
76533@@ -562,7 +562,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76534
76535 ieee80211_recalc_ps(local, -1);
76536
76537- if (local->open_count == 0) {
76538+ if (local_read(&local->open_count) == 0) {
76539 if (local->ops->napi_poll)
76540 napi_disable(&local->napi);
76541 ieee80211_clear_tx_pending(local);
76542diff --git a/net/mac80211/main.c b/net/mac80211/main.c
76543index 1633648..d45ebfa 100644
76544--- a/net/mac80211/main.c
76545+++ b/net/mac80211/main.c
76546@@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
76547 local->hw.conf.power_level = power;
76548 }
76549
76550- if (changed && local->open_count) {
76551+ if (changed && local_read(&local->open_count)) {
76552 ret = drv_config(local, changed);
76553 /*
76554 * Goal:
76555diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
76556index ef8eba1..5c63952 100644
76557--- a/net/mac80211/pm.c
76558+++ b/net/mac80211/pm.c
76559@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76560 struct ieee80211_sub_if_data *sdata;
76561 struct sta_info *sta;
76562
76563- if (!local->open_count)
76564+ if (!local_read(&local->open_count))
76565 goto suspend;
76566
76567 ieee80211_scan_cancel(local);
76568@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76569 cancel_work_sync(&local->dynamic_ps_enable_work);
76570 del_timer_sync(&local->dynamic_ps_timer);
76571
76572- local->wowlan = wowlan && local->open_count;
76573+ local->wowlan = wowlan && local_read(&local->open_count);
76574 if (local->wowlan) {
76575 int err = drv_suspend(local, wowlan);
76576 if (err < 0) {
76577@@ -128,7 +128,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76578 }
76579
76580 /* stop hardware - this must stop RX */
76581- if (local->open_count)
76582+ if (local_read(&local->open_count))
76583 ieee80211_stop_device(local);
76584
76585 suspend:
76586diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
76587index 3313c11..bec9f17 100644
76588--- a/net/mac80211/rate.c
76589+++ b/net/mac80211/rate.c
76590@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
76591
76592 ASSERT_RTNL();
76593
76594- if (local->open_count)
76595+ if (local_read(&local->open_count))
76596 return -EBUSY;
76597
76598 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
76599diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
76600index c97a065..ff61928 100644
76601--- a/net/mac80211/rc80211_pid_debugfs.c
76602+++ b/net/mac80211/rc80211_pid_debugfs.c
76603@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
76604
76605 spin_unlock_irqrestore(&events->lock, status);
76606
76607- if (copy_to_user(buf, pb, p))
76608+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
76609 return -EFAULT;
76610
76611 return p;
76612diff --git a/net/mac80211/util.c b/net/mac80211/util.c
76613index eb9d7c0..d34b832 100644
76614--- a/net/mac80211/util.c
76615+++ b/net/mac80211/util.c
76616@@ -1179,7 +1179,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
76617 }
76618 #endif
76619 /* everything else happens only if HW was up & running */
76620- if (!local->open_count)
76621+ if (!local_read(&local->open_count))
76622 goto wake_up;
76623
76624 /*
76625diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
76626index 0c6f67e..d02cdfc 100644
76627--- a/net/netfilter/Kconfig
76628+++ b/net/netfilter/Kconfig
76629@@ -836,6 +836,16 @@ config NETFILTER_XT_MATCH_ESP
76630
76631 To compile it as a module, choose M here. If unsure, say N.
76632
76633+config NETFILTER_XT_MATCH_GRADM
76634+ tristate '"gradm" match support'
76635+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
76636+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
76637+ ---help---
76638+ The gradm match allows to match on grsecurity RBAC being enabled.
76639+ It is useful when iptables rules are applied early on bootup to
76640+ prevent connections to the machine (except from a trusted host)
76641+ while the RBAC system is disabled.
76642+
76643 config NETFILTER_XT_MATCH_HASHLIMIT
76644 tristate '"hashlimit" match support'
76645 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
76646diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
76647index ca36765..0882e7c 100644
76648--- a/net/netfilter/Makefile
76649+++ b/net/netfilter/Makefile
76650@@ -86,6 +86,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
76651 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
76652 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
76653 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
76654+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
76655 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
76656 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
76657 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
76658diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
76659index 29fa5ba..8debc79 100644
76660--- a/net/netfilter/ipvs/ip_vs_conn.c
76661+++ b/net/netfilter/ipvs/ip_vs_conn.c
76662@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
76663 /* Increase the refcnt counter of the dest */
76664 atomic_inc(&dest->refcnt);
76665
76666- conn_flags = atomic_read(&dest->conn_flags);
76667+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
76668 if (cp->protocol != IPPROTO_UDP)
76669 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
76670 /* Bind with the destination and its corresponding transmitter */
76671@@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
76672 atomic_set(&cp->refcnt, 1);
76673
76674 atomic_set(&cp->n_control, 0);
76675- atomic_set(&cp->in_pkts, 0);
76676+ atomic_set_unchecked(&cp->in_pkts, 0);
76677
76678 atomic_inc(&ipvs->conn_count);
76679 if (flags & IP_VS_CONN_F_NO_CPORT)
76680@@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
76681
76682 /* Don't drop the entry if its number of incoming packets is not
76683 located in [0, 8] */
76684- i = atomic_read(&cp->in_pkts);
76685+ i = atomic_read_unchecked(&cp->in_pkts);
76686 if (i > 8 || i < 0) return 0;
76687
76688 if (!todrop_rate[i]) return 0;
76689diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
76690index 00bdb1d..6725a48 100644
76691--- a/net/netfilter/ipvs/ip_vs_core.c
76692+++ b/net/netfilter/ipvs/ip_vs_core.c
76693@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
76694 ret = cp->packet_xmit(skb, cp, pd->pp);
76695 /* do not touch skb anymore */
76696
76697- atomic_inc(&cp->in_pkts);
76698+ atomic_inc_unchecked(&cp->in_pkts);
76699 ip_vs_conn_put(cp);
76700 return ret;
76701 }
76702@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
76703 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
76704 pkts = sysctl_sync_threshold(ipvs);
76705 else
76706- pkts = atomic_add_return(1, &cp->in_pkts);
76707+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76708
76709 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
76710 cp->protocol == IPPROTO_SCTP) {
76711diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
76712index f558998..7dfb054 100644
76713--- a/net/netfilter/ipvs/ip_vs_ctl.c
76714+++ b/net/netfilter/ipvs/ip_vs_ctl.c
76715@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
76716 ip_vs_rs_hash(ipvs, dest);
76717 write_unlock_bh(&ipvs->rs_lock);
76718 }
76719- atomic_set(&dest->conn_flags, conn_flags);
76720+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
76721
76722 /* bind the service */
76723 if (!dest->svc) {
76724@@ -1521,11 +1521,12 @@ static int ip_vs_dst_event(struct notifier_block *this, unsigned long event,
76725 {
76726 struct net_device *dev = ptr;
76727 struct net *net = dev_net(dev);
76728+ struct netns_ipvs *ipvs = net_ipvs(net);
76729 struct ip_vs_service *svc;
76730 struct ip_vs_dest *dest;
76731 unsigned int idx;
76732
76733- if (event != NETDEV_UNREGISTER)
76734+ if (event != NETDEV_UNREGISTER || !ipvs)
76735 return NOTIFY_DONE;
76736 IP_VS_DBG(3, "%s() dev=%s\n", __func__, dev->name);
76737 EnterFunction(2);
76738@@ -1551,7 +1552,7 @@ static int ip_vs_dst_event(struct notifier_block *this, unsigned long event,
76739 }
76740 }
76741
76742- list_for_each_entry(dest, &net_ipvs(net)->dest_trash, n_list) {
76743+ list_for_each_entry(dest, &ipvs->dest_trash, n_list) {
76744 __ip_vs_dev_reset(dest, dev);
76745 }
76746 mutex_unlock(&__ip_vs_mutex);
76747@@ -2028,7 +2029,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76748 " %-7s %-6d %-10d %-10d\n",
76749 &dest->addr.in6,
76750 ntohs(dest->port),
76751- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76752+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76753 atomic_read(&dest->weight),
76754 atomic_read(&dest->activeconns),
76755 atomic_read(&dest->inactconns));
76756@@ -2039,7 +2040,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76757 "%-7s %-6d %-10d %-10d\n",
76758 ntohl(dest->addr.ip),
76759 ntohs(dest->port),
76760- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76761+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76762 atomic_read(&dest->weight),
76763 atomic_read(&dest->activeconns),
76764 atomic_read(&dest->inactconns));
76765@@ -2509,7 +2510,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
76766
76767 entry.addr = dest->addr.ip;
76768 entry.port = dest->port;
76769- entry.conn_flags = atomic_read(&dest->conn_flags);
76770+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
76771 entry.weight = atomic_read(&dest->weight);
76772 entry.u_threshold = dest->u_threshold;
76773 entry.l_threshold = dest->l_threshold;
76774@@ -3042,7 +3043,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
76775 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
76776
76777 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
76778- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76779+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76780 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
76781 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
76782 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
76783diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
76784index 8a0d6d6..90ec197 100644
76785--- a/net/netfilter/ipvs/ip_vs_sync.c
76786+++ b/net/netfilter/ipvs/ip_vs_sync.c
76787@@ -649,7 +649,7 @@ control:
76788 * i.e only increment in_pkts for Templates.
76789 */
76790 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
76791- int pkts = atomic_add_return(1, &cp->in_pkts);
76792+ int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76793
76794 if (pkts % sysctl_sync_period(ipvs) != 1)
76795 return;
76796@@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
76797
76798 if (opt)
76799 memcpy(&cp->in_seq, opt, sizeof(*opt));
76800- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76801+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76802 cp->state = state;
76803 cp->old_state = cp->state;
76804 /*
76805diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
76806index 7fd66de..e6fb361 100644
76807--- a/net/netfilter/ipvs/ip_vs_xmit.c
76808+++ b/net/netfilter/ipvs/ip_vs_xmit.c
76809@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
76810 else
76811 rc = NF_ACCEPT;
76812 /* do not touch skb anymore */
76813- atomic_inc(&cp->in_pkts);
76814+ atomic_inc_unchecked(&cp->in_pkts);
76815 goto out;
76816 }
76817
76818@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
76819 else
76820 rc = NF_ACCEPT;
76821 /* do not touch skb anymore */
76822- atomic_inc(&cp->in_pkts);
76823+ atomic_inc_unchecked(&cp->in_pkts);
76824 goto out;
76825 }
76826
76827diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
76828index 729f157..ac0fa7b 100644
76829--- a/net/netfilter/nf_conntrack_core.c
76830+++ b/net/netfilter/nf_conntrack_core.c
76831@@ -1538,6 +1538,10 @@ err_proto:
76832 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
76833 #define DYING_NULLS_VAL ((1<<30)+1)
76834
76835+#ifdef CONFIG_GRKERNSEC_HIDESYM
76836+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
76837+#endif
76838+
76839 static int nf_conntrack_init_net(struct net *net)
76840 {
76841 int ret;
76842@@ -1551,7 +1555,11 @@ static int nf_conntrack_init_net(struct net *net)
76843 goto err_stat;
76844 }
76845
76846+#ifdef CONFIG_GRKERNSEC_HIDESYM
76847+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
76848+#else
76849 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
76850+#endif
76851 if (!net->ct.slabname) {
76852 ret = -ENOMEM;
76853 goto err_slabname;
76854diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
76855index 66b2c54..c7884e3 100644
76856--- a/net/netfilter/nfnetlink_log.c
76857+++ b/net/netfilter/nfnetlink_log.c
76858@@ -70,7 +70,7 @@ struct nfulnl_instance {
76859 };
76860
76861 static DEFINE_SPINLOCK(instances_lock);
76862-static atomic_t global_seq;
76863+static atomic_unchecked_t global_seq;
76864
76865 #define INSTANCE_BUCKETS 16
76866 static struct hlist_head instance_table[INSTANCE_BUCKETS];
76867@@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
76868 /* global sequence number */
76869 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
76870 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
76871- htonl(atomic_inc_return(&global_seq)));
76872+ htonl(atomic_inc_return_unchecked(&global_seq)));
76873
76874 if (data_len) {
76875 struct nlattr *nla;
76876diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
76877new file mode 100644
76878index 0000000..6905327
76879--- /dev/null
76880+++ b/net/netfilter/xt_gradm.c
76881@@ -0,0 +1,51 @@
76882+/*
76883+ * gradm match for netfilter
76884