]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.5.6-201210071716.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.5.6-201210071716.patch
CommitLineData
b65906ba
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b4a898f..cd023f2 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29+*.vim
30 *.xml
31 *.xz
32 *_MODULES
33+*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38-.*
39+.[^g]*
40+.gen*
41 .*.d
42 .mm
43 53c700_d.h
44@@ -69,6 +75,7 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48+PERF*
49 SCCS
50 System.map*
51 TAGS
52@@ -80,6 +87,7 @@ aic7*seq.h*
53 aicasm
54 aicdb.h*
55 altivec*.c
56+ashldi3.S
57 asm-offsets.h
58 asm_offsets.h
59 autoconf.h*
60@@ -92,19 +100,24 @@ bounds.h
61 bsetup
62 btfixupprep
63 build
64+builtin-policy.h
65 bvmlinux
66 bzImage*
67 capability_names.h
68 capflags.c
69 classlist.h*
70+clut_vga16.c
71+common-cmds.h
72 comp*.log
73 compile.h*
74 conf
75 config
76 config-*
77 config_data.h*
78+config.c
79 config.mak
80 config.mak.autogen
81+config.tmp
82 conmakehash
83 consolemap_deftbl.c*
84 cpustr.h
85@@ -115,9 +128,11 @@ devlist.h*
86 dnotify_test
87 docproc
88 dslm
89+dtc-lexer.lex.c
90 elf2ecoff
91 elfconfig.h*
92 evergreen_reg_safe.h
93+exception_policy.conf
94 fixdep
95 flask.h
96 fore200e_mkfirm
97@@ -125,12 +140,15 @@ fore200e_pca_fw.c*
98 gconf
99 gconf.glade.h
100 gen-devlist
101+gen-kdb_cmds.c
102 gen_crc32table
103 gen_init_cpio
104 generated
105 genheaders
106 genksyms
107 *_gray256.c
108+hash
109+hid-example
110 hpet_example
111 hugepage-mmap
112 hugepage-shm
113@@ -145,7 +163,7 @@ int32.c
114 int4.c
115 int8.c
116 kallsyms
117-kconfig
118+kern_constants.h
119 keywords.c
120 ksym.c*
121 ksym.h*
122@@ -153,7 +171,7 @@ kxgettext
123 lkc_defs.h
124 lex.c
125 lex.*.c
126-linux
127+lib1funcs.S
128 logo_*.c
129 logo_*_clut224.c
130 logo_*_mono.c
131@@ -164,14 +182,15 @@ machtypes.h
132 map
133 map_hugetlb
134 maui_boot.h
135-media
136 mconf
137+mdp
138 miboot*
139 mk_elfconfig
140 mkboot
141 mkbugboot
142 mkcpustr
143 mkdep
144+mkpiggy
145 mkprep
146 mkregtable
147 mktables
148@@ -188,6 +207,8 @@ oui.c*
149 page-types
150 parse.c
151 parse.h
152+parse-events*
153+pasyms.h
154 patches*
155 pca200e.bin
156 pca200e_ecd.bin2
157@@ -197,6 +218,7 @@ perf-archive
158 piggyback
159 piggy.gzip
160 piggy.S
161+pmu-*
162 pnmtologo
163 ppc_defs.h*
164 pss_boot.h
165@@ -206,7 +228,10 @@ r200_reg_safe.h
166 r300_reg_safe.h
167 r420_reg_safe.h
168 r600_reg_safe.h
169+realmode.lds
170+realmode.relocs
171 recordmcount
172+regdb.c
173 relocs
174 rlim_names.h
175 rn50_reg_safe.h
176@@ -216,8 +241,11 @@ series
177 setup
178 setup.bin
179 setup.elf
180+size_overflow_hash.h
181 sImage
182+slabinfo
183 sm_tbl*
184+sortextable
185 split-include
186 syscalltab.h
187 tables.c
188@@ -227,6 +255,7 @@ tftpboot.img
189 timeconst.h
190 times.h*
191 trix_boot.h
192+user_constants.h
193 utsrelease.h*
194 vdso-syms.lds
195 vdso.lds
196@@ -238,13 +267,17 @@ vdso32.lds
197 vdso32.so.dbg
198 vdso64.lds
199 vdso64.so.dbg
200+vdsox32.lds
201+vdsox32-syms.lds
202 version.h*
203 vmImage
204 vmlinux
205 vmlinux-*
206 vmlinux.aout
207 vmlinux.bin.all
208+vmlinux.bin.bz2
209 vmlinux.lds
210+vmlinux.relocs
211 vmlinuz
212 voffset.h
213 vsyscall.lds
214@@ -252,9 +285,11 @@ vsyscall_32.lds
215 wanxlfw.inc
216 uImage
217 unifdef
218+utsrelease.h
219 wakeup.bin
220 wakeup.elf
221 wakeup.lds
222 zImage*
223 zconf.hash.c
224+zconf.lex.c
225 zoffset.h
226diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
227index a92c5eb..b91d3d5 100644
228--- a/Documentation/kernel-parameters.txt
229+++ b/Documentation/kernel-parameters.txt
230@@ -905,6 +905,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
231 gpt [EFI] Forces disk with valid GPT signature but
232 invalid Protective MBR to be treated as GPT.
233
234+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
235+ ignore grsecurity's /proc restrictions
236+
237 hashdist= [KNL,NUMA] Large hashes allocated during boot
238 are distributed across NUMA nodes. Defaults on
239 for 64-bit NUMA, off otherwise.
240@@ -2051,6 +2054,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
241 the specified number of seconds. This is to be used if
242 your oopses keep scrolling off the screen.
243
244+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
245+ virtualization environments that don't cope well with the
246+ expand down segment used by UDEREF on X86-32 or the frequent
247+ page table updates on X86-64.
248+
249+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
250+
251 pcbit= [HW,ISDN]
252
253 pcd. [PARIDE]
254diff --git a/Documentation/sysctl/fs.txt b/Documentation/sysctl/fs.txt
255index 13d6166..8c235b6 100644
256--- a/Documentation/sysctl/fs.txt
257+++ b/Documentation/sysctl/fs.txt
258@@ -163,16 +163,22 @@ This value can be used to query and set the core dump mode for setuid
259 or otherwise protected/tainted binaries. The modes are
260
261 0 - (default) - traditional behaviour. Any process which has changed
262- privilege levels or is execute only will not be dumped
263+ privilege levels or is execute only will not be dumped.
264 1 - (debug) - all processes dump core when possible. The core dump is
265 owned by the current user and no security is applied. This is
266 intended for system debugging situations only. Ptrace is unchecked.
267+ This is insecure as it allows regular users to examine the memory
268+ contents of privileged processes.
269 2 - (suidsafe) - any binary which normally would not be dumped is dumped
270- readable by root only. This allows the end user to remove
271- such a dump but not access it directly. For security reasons
272- core dumps in this mode will not overwrite one another or
273- other files. This mode is appropriate when administrators are
274- attempting to debug problems in a normal environment.
275+ anyway, but only if the "core_pattern" kernel sysctl is set to
276+ either a pipe handler or a fully qualified path. (For more details
277+ on this limitation, see CVE-2006-2451.) This mode is appropriate
278+ when administrators are attempting to debug problems in a normal
279+ environment, and either have a core dump pipe handler that knows
280+ to treat privileged core dumps with care, or specific directory
281+ defined for catching core dumps. If a core dump happens without
282+ a pipe handler or fully qualifid path, a message will be emitted
283+ to syslog warning about the lack of a correct setting.
284
285 ==============================================================
286
287diff --git a/Makefile b/Makefile
288index 75c7683..a1ee05c 100644
289--- a/Makefile
290+++ b/Makefile
291@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
292
293 HOSTCC = gcc
294 HOSTCXX = g++
295-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
296-HOSTCXXFLAGS = -O2
297+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
298+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
299+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
300
301 # Decide whether to build built-in, modular, or both.
302 # Normally, just do built-in.
303@@ -404,8 +405,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
304 # Rules shared between *config targets and build targets
305
306 # Basic helpers built in scripts/
307-PHONY += scripts_basic
308-scripts_basic:
309+PHONY += scripts_basic gcc-plugins
310+scripts_basic: gcc-plugins
311 $(Q)$(MAKE) $(build)=scripts/basic
312 $(Q)rm -f .tmp_quiet_recordmcount
313
314@@ -561,6 +562,60 @@ else
315 KBUILD_CFLAGS += -O2
316 endif
317
318+ifndef DISABLE_PAX_PLUGINS
319+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
320+ifneq ($(PLUGINCC),)
321+ifndef DISABLE_PAX_CONSTIFY_PLUGIN
322+ifndef CONFIG_UML
323+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
324+endif
325+endif
326+ifdef CONFIG_PAX_MEMORY_STACKLEAK
327+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
328+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
329+endif
330+ifdef CONFIG_KALLOCSTAT_PLUGIN
331+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
332+endif
333+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
334+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
335+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
336+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
337+endif
338+ifdef CONFIG_CHECKER_PLUGIN
339+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
340+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
341+endif
342+endif
343+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
344+ifdef CONFIG_PAX_SIZE_OVERFLOW
345+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
346+endif
347+ifdef CONFIG_PAX_LATENT_ENTROPY
348+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
349+endif
350+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
351+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
352+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
353+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
354+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
355+ifeq ($(KBUILD_EXTMOD),)
356+gcc-plugins:
357+ $(Q)$(MAKE) $(build)=tools/gcc
358+else
359+gcc-plugins: ;
360+endif
361+else
362+gcc-plugins:
363+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
364+ $(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.))
365+else
366+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
367+endif
368+ $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
369+endif
370+endif
371+
372 include $(srctree)/arch/$(SRCARCH)/Makefile
373
374 ifdef CONFIG_READABLE_ASM
375@@ -715,7 +770,7 @@ export mod_strip_cmd
376
377
378 ifeq ($(KBUILD_EXTMOD),)
379-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
380+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
381
382 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
383 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
384@@ -762,6 +817,8 @@ endif
385
386 # The actual objects are generated when descending,
387 # make sure no implicit rule kicks in
388+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
389+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
390 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
391
392 # Handle descending into subdirectories listed in $(vmlinux-dirs)
393@@ -771,7 +828,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
394 # Error messages still appears in the original language
395
396 PHONY += $(vmlinux-dirs)
397-$(vmlinux-dirs): prepare scripts
398+$(vmlinux-dirs): gcc-plugins prepare scripts
399 $(Q)$(MAKE) $(build)=$@
400
401 # Store (new) KERNELRELASE string in include/config/kernel.release
402@@ -815,6 +872,7 @@ prepare0: archprepare FORCE
403 $(Q)$(MAKE) $(build)=.
404
405 # All the preparing..
406+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
407 prepare: prepare0
408
409 # Generate some files
410@@ -922,6 +980,8 @@ all: modules
411 # using awk while concatenating to the final file.
412
413 PHONY += modules
414+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
415+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
416 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
417 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
418 @$(kecho) ' Building modules, stage 2.';
419@@ -937,7 +997,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
420
421 # Target to prepare building external modules
422 PHONY += modules_prepare
423-modules_prepare: prepare scripts
424+modules_prepare: gcc-plugins prepare scripts
425
426 # Target to install modules
427 PHONY += modules_install
428@@ -994,7 +1054,7 @@ CLEAN_DIRS += $(MODVERDIR)
429 MRPROPER_DIRS += include/config usr/include include/generated \
430 arch/*/include/generated
431 MRPROPER_FILES += .config .config.old .version .old_version \
432- include/linux/version.h \
433+ include/linux/version.h tools/gcc/size_overflow_hash.h\
434 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
435
436 # clean - Delete most, but leave enough to build external modules
437@@ -1032,6 +1092,7 @@ distclean: mrproper
438 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
439 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
440 -o -name '.*.rej' \
441+ -o -name '.*.rej' -o -name '*.so' \
442 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
443 -type f -print | xargs rm -f
444
445@@ -1192,6 +1253,8 @@ PHONY += $(module-dirs) modules
446 $(module-dirs): crmodverdir $(objtree)/Module.symvers
447 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
448
449+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
450+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
451 modules: $(module-dirs)
452 @$(kecho) ' Building modules, stage 2.';
453 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
454@@ -1326,17 +1389,21 @@ else
455 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
456 endif
457
458-%.s: %.c prepare scripts FORCE
459+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
460+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
461+%.s: %.c gcc-plugins prepare scripts FORCE
462 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
463 %.i: %.c prepare scripts FORCE
464 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
465-%.o: %.c prepare scripts FORCE
466+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
467+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
468+%.o: %.c gcc-plugins prepare scripts FORCE
469 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
470 %.lst: %.c prepare scripts FORCE
471 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
472-%.s: %.S prepare scripts FORCE
473+%.s: %.S gcc-plugins prepare scripts FORCE
474 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
475-%.o: %.S prepare scripts FORCE
476+%.o: %.S gcc-plugins prepare scripts FORCE
477 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
478 %.symtypes: %.c prepare scripts FORCE
479 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
480@@ -1346,11 +1413,15 @@ endif
481 $(cmd_crmodverdir)
482 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
483 $(build)=$(build-dir)
484-%/: prepare scripts FORCE
485+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
486+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
487+%/: gcc-plugins prepare scripts FORCE
488 $(cmd_crmodverdir)
489 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
490 $(build)=$(build-dir)
491-%.ko: prepare scripts FORCE
492+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
493+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
494+%.ko: gcc-plugins prepare scripts FORCE
495 $(cmd_crmodverdir)
496 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
497 $(build)=$(build-dir) $(@:.ko=.o)
498diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
499index c2cbe4f..f7264b4 100644
500--- a/arch/alpha/include/asm/atomic.h
501+++ b/arch/alpha/include/asm/atomic.h
502@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
503 #define atomic_dec(v) atomic_sub(1,(v))
504 #define atomic64_dec(v) atomic64_sub(1,(v))
505
506+#define atomic64_read_unchecked(v) atomic64_read(v)
507+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
508+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
509+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
510+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
511+#define atomic64_inc_unchecked(v) atomic64_inc(v)
512+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
513+#define atomic64_dec_unchecked(v) atomic64_dec(v)
514+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
515+
516 #define smp_mb__before_atomic_dec() smp_mb()
517 #define smp_mb__after_atomic_dec() smp_mb()
518 #define smp_mb__before_atomic_inc() smp_mb()
519diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
520index ad368a9..fbe0f25 100644
521--- a/arch/alpha/include/asm/cache.h
522+++ b/arch/alpha/include/asm/cache.h
523@@ -4,19 +4,19 @@
524 #ifndef __ARCH_ALPHA_CACHE_H
525 #define __ARCH_ALPHA_CACHE_H
526
527+#include <linux/const.h>
528
529 /* Bytes per L1 (data) cache line. */
530 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
531-# define L1_CACHE_BYTES 64
532 # define L1_CACHE_SHIFT 6
533 #else
534 /* Both EV4 and EV5 are write-through, read-allocate,
535 direct-mapped, physical.
536 */
537-# define L1_CACHE_BYTES 32
538 # define L1_CACHE_SHIFT 5
539 #endif
540
541+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
542 #define SMP_CACHE_BYTES L1_CACHE_BYTES
543
544 #endif
545diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
546index 968d999..d36b2df 100644
547--- a/arch/alpha/include/asm/elf.h
548+++ b/arch/alpha/include/asm/elf.h
549@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
550
551 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
552
553+#ifdef CONFIG_PAX_ASLR
554+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
555+
556+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
557+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
558+#endif
559+
560 /* $0 is set by ld.so to a pointer to a function which might be
561 registered using atexit. This provides a mean for the dynamic
562 linker to call DT_FINI functions for shared libraries that have
563diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
564index bc2a0da..8ad11ee 100644
565--- a/arch/alpha/include/asm/pgalloc.h
566+++ b/arch/alpha/include/asm/pgalloc.h
567@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
568 pgd_set(pgd, pmd);
569 }
570
571+static inline void
572+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
573+{
574+ pgd_populate(mm, pgd, pmd);
575+}
576+
577 extern pgd_t *pgd_alloc(struct mm_struct *mm);
578
579 static inline void
580diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
581index 81a4342..348b927 100644
582--- a/arch/alpha/include/asm/pgtable.h
583+++ b/arch/alpha/include/asm/pgtable.h
584@@ -102,6 +102,17 @@ struct vm_area_struct;
585 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
586 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
587 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
588+
589+#ifdef CONFIG_PAX_PAGEEXEC
590+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
591+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
592+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
593+#else
594+# define PAGE_SHARED_NOEXEC PAGE_SHARED
595+# define PAGE_COPY_NOEXEC PAGE_COPY
596+# define PAGE_READONLY_NOEXEC PAGE_READONLY
597+#endif
598+
599 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
600
601 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
602diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
603index 2fd00b7..cfd5069 100644
604--- a/arch/alpha/kernel/module.c
605+++ b/arch/alpha/kernel/module.c
606@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
607
608 /* The small sections were sorted to the end of the segment.
609 The following should definitely cover them. */
610- gp = (u64)me->module_core + me->core_size - 0x8000;
611+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
612 got = sechdrs[me->arch.gotsecindex].sh_addr;
613
614 for (i = 0; i < n; i++) {
615diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
616index 98a1036..fb54ccf 100644
617--- a/arch/alpha/kernel/osf_sys.c
618+++ b/arch/alpha/kernel/osf_sys.c
619@@ -1312,7 +1312,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
620 /* At this point: (!vma || addr < vma->vm_end). */
621 if (limit - len < addr)
622 return -ENOMEM;
623- if (!vma || addr + len <= vma->vm_start)
624+ if (check_heap_stack_gap(vma, addr, len))
625 return addr;
626 addr = vma->vm_end;
627 vma = vma->vm_next;
628@@ -1348,6 +1348,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
629 merely specific addresses, but regions of memory -- perhaps
630 this feature should be incorporated into all ports? */
631
632+#ifdef CONFIG_PAX_RANDMMAP
633+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
634+#endif
635+
636 if (addr) {
637 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
638 if (addr != (unsigned long) -ENOMEM)
639@@ -1355,8 +1359,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
640 }
641
642 /* Next, try allocating at TASK_UNMAPPED_BASE. */
643- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
644- len, limit);
645+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
646+
647 if (addr != (unsigned long) -ENOMEM)
648 return addr;
649
650diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
651index 5eecab1..609abc0 100644
652--- a/arch/alpha/mm/fault.c
653+++ b/arch/alpha/mm/fault.c
654@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
655 __reload_thread(pcb);
656 }
657
658+#ifdef CONFIG_PAX_PAGEEXEC
659+/*
660+ * PaX: decide what to do with offenders (regs->pc = fault address)
661+ *
662+ * returns 1 when task should be killed
663+ * 2 when patched PLT trampoline was detected
664+ * 3 when unpatched PLT trampoline was detected
665+ */
666+static int pax_handle_fetch_fault(struct pt_regs *regs)
667+{
668+
669+#ifdef CONFIG_PAX_EMUPLT
670+ int err;
671+
672+ do { /* PaX: patched PLT emulation #1 */
673+ unsigned int ldah, ldq, jmp;
674+
675+ err = get_user(ldah, (unsigned int *)regs->pc);
676+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
677+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
678+
679+ if (err)
680+ break;
681+
682+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
683+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
684+ jmp == 0x6BFB0000U)
685+ {
686+ unsigned long r27, addr;
687+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
688+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
689+
690+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
691+ err = get_user(r27, (unsigned long *)addr);
692+ if (err)
693+ break;
694+
695+ regs->r27 = r27;
696+ regs->pc = r27;
697+ return 2;
698+ }
699+ } while (0);
700+
701+ do { /* PaX: patched PLT emulation #2 */
702+ unsigned int ldah, lda, br;
703+
704+ err = get_user(ldah, (unsigned int *)regs->pc);
705+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
706+ err |= get_user(br, (unsigned int *)(regs->pc+8));
707+
708+ if (err)
709+ break;
710+
711+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
712+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
713+ (br & 0xFFE00000U) == 0xC3E00000U)
714+ {
715+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
716+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
717+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
718+
719+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
720+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
721+ return 2;
722+ }
723+ } while (0);
724+
725+ do { /* PaX: unpatched PLT emulation */
726+ unsigned int br;
727+
728+ err = get_user(br, (unsigned int *)regs->pc);
729+
730+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
731+ unsigned int br2, ldq, nop, jmp;
732+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
733+
734+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
735+ err = get_user(br2, (unsigned int *)addr);
736+ err |= get_user(ldq, (unsigned int *)(addr+4));
737+ err |= get_user(nop, (unsigned int *)(addr+8));
738+ err |= get_user(jmp, (unsigned int *)(addr+12));
739+ err |= get_user(resolver, (unsigned long *)(addr+16));
740+
741+ if (err)
742+ break;
743+
744+ if (br2 == 0xC3600000U &&
745+ ldq == 0xA77B000CU &&
746+ nop == 0x47FF041FU &&
747+ jmp == 0x6B7B0000U)
748+ {
749+ regs->r28 = regs->pc+4;
750+ regs->r27 = addr+16;
751+ regs->pc = resolver;
752+ return 3;
753+ }
754+ }
755+ } while (0);
756+#endif
757+
758+ return 1;
759+}
760+
761+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
762+{
763+ unsigned long i;
764+
765+ printk(KERN_ERR "PAX: bytes at PC: ");
766+ for (i = 0; i < 5; i++) {
767+ unsigned int c;
768+ if (get_user(c, (unsigned int *)pc+i))
769+ printk(KERN_CONT "???????? ");
770+ else
771+ printk(KERN_CONT "%08x ", c);
772+ }
773+ printk("\n");
774+}
775+#endif
776
777 /*
778 * This routine handles page faults. It determines the address,
779@@ -130,8 +248,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
780 good_area:
781 si_code = SEGV_ACCERR;
782 if (cause < 0) {
783- if (!(vma->vm_flags & VM_EXEC))
784+ if (!(vma->vm_flags & VM_EXEC)) {
785+
786+#ifdef CONFIG_PAX_PAGEEXEC
787+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
788+ goto bad_area;
789+
790+ up_read(&mm->mmap_sem);
791+ switch (pax_handle_fetch_fault(regs)) {
792+
793+#ifdef CONFIG_PAX_EMUPLT
794+ case 2:
795+ case 3:
796+ return;
797+#endif
798+
799+ }
800+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
801+ do_group_exit(SIGKILL);
802+#else
803 goto bad_area;
804+#endif
805+
806+ }
807 } else if (!cause) {
808 /* Allow reads even for write-only mappings */
809 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
810diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
811index c79f61f..9ac0642 100644
812--- a/arch/arm/include/asm/atomic.h
813+++ b/arch/arm/include/asm/atomic.h
814@@ -17,17 +17,35 @@
815 #include <asm/barrier.h>
816 #include <asm/cmpxchg.h>
817
818+#ifdef CONFIG_GENERIC_ATOMIC64
819+#include <asm-generic/atomic64.h>
820+#endif
821+
822 #define ATOMIC_INIT(i) { (i) }
823
824 #ifdef __KERNEL__
825
826+#define _ASM_EXTABLE(from, to) \
827+" .pushsection __ex_table,\"a\"\n"\
828+" .align 3\n" \
829+" .long " #from ", " #to"\n" \
830+" .popsection"
831+
832 /*
833 * On ARM, ordinary assignment (str instruction) doesn't clear the local
834 * strex/ldrex monitor on some implementations. The reason we can use it for
835 * atomic_set() is the clrex or dummy strex done on every exception return.
836 */
837 #define atomic_read(v) (*(volatile int *)&(v)->counter)
838+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
839+{
840+ return v->counter;
841+}
842 #define atomic_set(v,i) (((v)->counter) = (i))
843+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
844+{
845+ v->counter = i;
846+}
847
848 #if __LINUX_ARM_ARCH__ >= 6
849
850@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
851 int result;
852
853 __asm__ __volatile__("@ atomic_add\n"
854+"1: ldrex %1, [%3]\n"
855+" adds %0, %1, %4\n"
856+
857+#ifdef CONFIG_PAX_REFCOUNT
858+" bvc 3f\n"
859+"2: bkpt 0xf103\n"
860+"3:\n"
861+#endif
862+
863+" strex %1, %0, [%3]\n"
864+" teq %1, #0\n"
865+" bne 1b"
866+
867+#ifdef CONFIG_PAX_REFCOUNT
868+"\n4:\n"
869+ _ASM_EXTABLE(2b, 4b)
870+#endif
871+
872+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
873+ : "r" (&v->counter), "Ir" (i)
874+ : "cc");
875+}
876+
877+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
878+{
879+ unsigned long tmp;
880+ int result;
881+
882+ __asm__ __volatile__("@ atomic_add_unchecked\n"
883 "1: ldrex %0, [%3]\n"
884 " add %0, %0, %4\n"
885 " strex %1, %0, [%3]\n"
886@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
887 smp_mb();
888
889 __asm__ __volatile__("@ atomic_add_return\n"
890+"1: ldrex %1, [%3]\n"
891+" adds %0, %1, %4\n"
892+
893+#ifdef CONFIG_PAX_REFCOUNT
894+" bvc 3f\n"
895+" mov %0, %1\n"
896+"2: bkpt 0xf103\n"
897+"3:\n"
898+#endif
899+
900+" strex %1, %0, [%3]\n"
901+" teq %1, #0\n"
902+" bne 1b"
903+
904+#ifdef CONFIG_PAX_REFCOUNT
905+"\n4:\n"
906+ _ASM_EXTABLE(2b, 4b)
907+#endif
908+
909+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
910+ : "r" (&v->counter), "Ir" (i)
911+ : "cc");
912+
913+ smp_mb();
914+
915+ return result;
916+}
917+
918+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
919+{
920+ unsigned long tmp;
921+ int result;
922+
923+ smp_mb();
924+
925+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
926 "1: ldrex %0, [%3]\n"
927 " add %0, %0, %4\n"
928 " strex %1, %0, [%3]\n"
929@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
930 int result;
931
932 __asm__ __volatile__("@ atomic_sub\n"
933+"1: ldrex %1, [%3]\n"
934+" subs %0, %1, %4\n"
935+
936+#ifdef CONFIG_PAX_REFCOUNT
937+" bvc 3f\n"
938+"2: bkpt 0xf103\n"
939+"3:\n"
940+#endif
941+
942+" strex %1, %0, [%3]\n"
943+" teq %1, #0\n"
944+" bne 1b"
945+
946+#ifdef CONFIG_PAX_REFCOUNT
947+"\n4:\n"
948+ _ASM_EXTABLE(2b, 4b)
949+#endif
950+
951+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
952+ : "r" (&v->counter), "Ir" (i)
953+ : "cc");
954+}
955+
956+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
957+{
958+ unsigned long tmp;
959+ int result;
960+
961+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
962 "1: ldrex %0, [%3]\n"
963 " sub %0, %0, %4\n"
964 " strex %1, %0, [%3]\n"
965@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
966 smp_mb();
967
968 __asm__ __volatile__("@ atomic_sub_return\n"
969-"1: ldrex %0, [%3]\n"
970-" sub %0, %0, %4\n"
971+"1: ldrex %1, [%3]\n"
972+" subs %0, %1, %4\n"
973+
974+#ifdef CONFIG_PAX_REFCOUNT
975+" bvc 3f\n"
976+" mov %0, %1\n"
977+"2: bkpt 0xf103\n"
978+"3:\n"
979+#endif
980+
981 " strex %1, %0, [%3]\n"
982 " teq %1, #0\n"
983 " bne 1b"
984+
985+#ifdef CONFIG_PAX_REFCOUNT
986+"\n4:\n"
987+ _ASM_EXTABLE(2b, 4b)
988+#endif
989+
990 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
991 : "r" (&v->counter), "Ir" (i)
992 : "cc");
993@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
994 return oldval;
995 }
996
997+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
998+{
999+ unsigned long oldval, res;
1000+
1001+ smp_mb();
1002+
1003+ do {
1004+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1005+ "ldrex %1, [%3]\n"
1006+ "mov %0, #0\n"
1007+ "teq %1, %4\n"
1008+ "strexeq %0, %5, [%3]\n"
1009+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1010+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1011+ : "cc");
1012+ } while (res);
1013+
1014+ smp_mb();
1015+
1016+ return oldval;
1017+}
1018+
1019 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1020 {
1021 unsigned long tmp, tmp2;
1022@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1023
1024 return val;
1025 }
1026+
1027+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1028+{
1029+ return atomic_add_return(i, v);
1030+}
1031+
1032 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1033+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1034+{
1035+ (void) atomic_add_return(i, v);
1036+}
1037
1038 static inline int atomic_sub_return(int i, atomic_t *v)
1039 {
1040@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1041 return val;
1042 }
1043 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1044+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1045+{
1046+ (void) atomic_sub_return(i, v);
1047+}
1048
1049 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1050 {
1051@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1052 return ret;
1053 }
1054
1055+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1056+{
1057+ return atomic_cmpxchg(v, old, new);
1058+}
1059+
1060 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1061 {
1062 unsigned long flags;
1063@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1064 #endif /* __LINUX_ARM_ARCH__ */
1065
1066 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1067+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1068+{
1069+ return xchg(&v->counter, new);
1070+}
1071
1072 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1073 {
1074@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1075 }
1076
1077 #define atomic_inc(v) atomic_add(1, v)
1078+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1079+{
1080+ atomic_add_unchecked(1, v);
1081+}
1082 #define atomic_dec(v) atomic_sub(1, v)
1083+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1084+{
1085+ atomic_sub_unchecked(1, v);
1086+}
1087
1088 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1089+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1090+{
1091+ return atomic_add_return_unchecked(1, v) == 0;
1092+}
1093 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1094 #define atomic_inc_return(v) (atomic_add_return(1, v))
1095+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1096+{
1097+ return atomic_add_return_unchecked(1, v);
1098+}
1099 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1100 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1101
1102@@ -241,6 +428,14 @@ typedef struct {
1103 u64 __aligned(8) counter;
1104 } atomic64_t;
1105
1106+#ifdef CONFIG_PAX_REFCOUNT
1107+typedef struct {
1108+ u64 __aligned(8) counter;
1109+} atomic64_unchecked_t;
1110+#else
1111+typedef atomic64_t atomic64_unchecked_t;
1112+#endif
1113+
1114 #define ATOMIC64_INIT(i) { (i) }
1115
1116 static inline u64 atomic64_read(const atomic64_t *v)
1117@@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1118 return result;
1119 }
1120
1121+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1122+{
1123+ u64 result;
1124+
1125+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1126+" ldrexd %0, %H0, [%1]"
1127+ : "=&r" (result)
1128+ : "r" (&v->counter), "Qo" (v->counter)
1129+ );
1130+
1131+ return result;
1132+}
1133+
1134 static inline void atomic64_set(atomic64_t *v, u64 i)
1135 {
1136 u64 tmp;
1137@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1138 : "cc");
1139 }
1140
1141+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1142+{
1143+ u64 tmp;
1144+
1145+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1146+"1: ldrexd %0, %H0, [%2]\n"
1147+" strexd %0, %3, %H3, [%2]\n"
1148+" teq %0, #0\n"
1149+" bne 1b"
1150+ : "=&r" (tmp), "=Qo" (v->counter)
1151+ : "r" (&v->counter), "r" (i)
1152+ : "cc");
1153+}
1154+
1155 static inline void atomic64_add(u64 i, atomic64_t *v)
1156 {
1157 u64 result;
1158@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1159 __asm__ __volatile__("@ atomic64_add\n"
1160 "1: ldrexd %0, %H0, [%3]\n"
1161 " adds %0, %0, %4\n"
1162+" adcs %H0, %H0, %H4\n"
1163+
1164+#ifdef CONFIG_PAX_REFCOUNT
1165+" bvc 3f\n"
1166+"2: bkpt 0xf103\n"
1167+"3:\n"
1168+#endif
1169+
1170+" strexd %1, %0, %H0, [%3]\n"
1171+" teq %1, #0\n"
1172+" bne 1b"
1173+
1174+#ifdef CONFIG_PAX_REFCOUNT
1175+"\n4:\n"
1176+ _ASM_EXTABLE(2b, 4b)
1177+#endif
1178+
1179+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1180+ : "r" (&v->counter), "r" (i)
1181+ : "cc");
1182+}
1183+
1184+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1185+{
1186+ u64 result;
1187+ unsigned long tmp;
1188+
1189+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1190+"1: ldrexd %0, %H0, [%3]\n"
1191+" adds %0, %0, %4\n"
1192 " adc %H0, %H0, %H4\n"
1193 " strexd %1, %0, %H0, [%3]\n"
1194 " teq %1, #0\n"
1195@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1196
1197 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1198 {
1199- u64 result;
1200- unsigned long tmp;
1201+ u64 result, tmp;
1202
1203 smp_mb();
1204
1205 __asm__ __volatile__("@ atomic64_add_return\n"
1206+"1: ldrexd %1, %H1, [%3]\n"
1207+" adds %0, %1, %4\n"
1208+" adcs %H0, %H1, %H4\n"
1209+
1210+#ifdef CONFIG_PAX_REFCOUNT
1211+" bvc 3f\n"
1212+" mov %0, %1\n"
1213+" mov %H0, %H1\n"
1214+"2: bkpt 0xf103\n"
1215+"3:\n"
1216+#endif
1217+
1218+" strexd %1, %0, %H0, [%3]\n"
1219+" teq %1, #0\n"
1220+" bne 1b"
1221+
1222+#ifdef CONFIG_PAX_REFCOUNT
1223+"\n4:\n"
1224+ _ASM_EXTABLE(2b, 4b)
1225+#endif
1226+
1227+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1228+ : "r" (&v->counter), "r" (i)
1229+ : "cc");
1230+
1231+ smp_mb();
1232+
1233+ return result;
1234+}
1235+
1236+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1237+{
1238+ u64 result;
1239+ unsigned long tmp;
1240+
1241+ smp_mb();
1242+
1243+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1244 "1: ldrexd %0, %H0, [%3]\n"
1245 " adds %0, %0, %4\n"
1246 " adc %H0, %H0, %H4\n"
1247@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1248 __asm__ __volatile__("@ atomic64_sub\n"
1249 "1: ldrexd %0, %H0, [%3]\n"
1250 " subs %0, %0, %4\n"
1251+" sbcs %H0, %H0, %H4\n"
1252+
1253+#ifdef CONFIG_PAX_REFCOUNT
1254+" bvc 3f\n"
1255+"2: bkpt 0xf103\n"
1256+"3:\n"
1257+#endif
1258+
1259+" strexd %1, %0, %H0, [%3]\n"
1260+" teq %1, #0\n"
1261+" bne 1b"
1262+
1263+#ifdef CONFIG_PAX_REFCOUNT
1264+"\n4:\n"
1265+ _ASM_EXTABLE(2b, 4b)
1266+#endif
1267+
1268+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1269+ : "r" (&v->counter), "r" (i)
1270+ : "cc");
1271+}
1272+
1273+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1274+{
1275+ u64 result;
1276+ unsigned long tmp;
1277+
1278+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1279+"1: ldrexd %0, %H0, [%3]\n"
1280+" subs %0, %0, %4\n"
1281 " sbc %H0, %H0, %H4\n"
1282 " strexd %1, %0, %H0, [%3]\n"
1283 " teq %1, #0\n"
1284@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1285
1286 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1287 {
1288- u64 result;
1289- unsigned long tmp;
1290+ u64 result, tmp;
1291
1292 smp_mb();
1293
1294 __asm__ __volatile__("@ atomic64_sub_return\n"
1295-"1: ldrexd %0, %H0, [%3]\n"
1296-" subs %0, %0, %4\n"
1297-" sbc %H0, %H0, %H4\n"
1298+"1: ldrexd %1, %H1, [%3]\n"
1299+" subs %0, %1, %4\n"
1300+" sbcs %H0, %H1, %H4\n"
1301+
1302+#ifdef CONFIG_PAX_REFCOUNT
1303+" bvc 3f\n"
1304+" mov %0, %1\n"
1305+" mov %H0, %H1\n"
1306+"2: bkpt 0xf103\n"
1307+"3:\n"
1308+#endif
1309+
1310 " strexd %1, %0, %H0, [%3]\n"
1311 " teq %1, #0\n"
1312 " bne 1b"
1313+
1314+#ifdef CONFIG_PAX_REFCOUNT
1315+"\n4:\n"
1316+ _ASM_EXTABLE(2b, 4b)
1317+#endif
1318+
1319 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1320 : "r" (&v->counter), "r" (i)
1321 : "cc");
1322@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1323 return oldval;
1324 }
1325
1326+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1327+{
1328+ u64 oldval;
1329+ unsigned long res;
1330+
1331+ smp_mb();
1332+
1333+ do {
1334+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1335+ "ldrexd %1, %H1, [%3]\n"
1336+ "mov %0, #0\n"
1337+ "teq %1, %4\n"
1338+ "teqeq %H1, %H4\n"
1339+ "strexdeq %0, %5, %H5, [%3]"
1340+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1341+ : "r" (&ptr->counter), "r" (old), "r" (new)
1342+ : "cc");
1343+ } while (res);
1344+
1345+ smp_mb();
1346+
1347+ return oldval;
1348+}
1349+
1350 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1351 {
1352 u64 result;
1353@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1354
1355 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1356 {
1357- u64 result;
1358- unsigned long tmp;
1359+ u64 result, tmp;
1360
1361 smp_mb();
1362
1363 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1364-"1: ldrexd %0, %H0, [%3]\n"
1365-" subs %0, %0, #1\n"
1366-" sbc %H0, %H0, #0\n"
1367+"1: ldrexd %1, %H1, [%3]\n"
1368+" subs %0, %1, #1\n"
1369+" sbcs %H0, %H1, #0\n"
1370+
1371+#ifdef CONFIG_PAX_REFCOUNT
1372+" bvc 3f\n"
1373+" mov %0, %1\n"
1374+" mov %H0, %H1\n"
1375+"2: bkpt 0xf103\n"
1376+"3:\n"
1377+#endif
1378+
1379 " teq %H0, #0\n"
1380-" bmi 2f\n"
1381+" bmi 4f\n"
1382 " strexd %1, %0, %H0, [%3]\n"
1383 " teq %1, #0\n"
1384 " bne 1b\n"
1385-"2:"
1386+"4:\n"
1387+
1388+#ifdef CONFIG_PAX_REFCOUNT
1389+ _ASM_EXTABLE(2b, 4b)
1390+#endif
1391+
1392 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1393 : "r" (&v->counter)
1394 : "cc");
1395@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1396 " teq %0, %5\n"
1397 " teqeq %H0, %H5\n"
1398 " moveq %1, #0\n"
1399-" beq 2f\n"
1400+" beq 4f\n"
1401 " adds %0, %0, %6\n"
1402-" adc %H0, %H0, %H6\n"
1403+" adcs %H0, %H0, %H6\n"
1404+
1405+#ifdef CONFIG_PAX_REFCOUNT
1406+" bvc 3f\n"
1407+"2: bkpt 0xf103\n"
1408+"3:\n"
1409+#endif
1410+
1411 " strexd %2, %0, %H0, [%4]\n"
1412 " teq %2, #0\n"
1413 " bne 1b\n"
1414-"2:"
1415+"4:\n"
1416+
1417+#ifdef CONFIG_PAX_REFCOUNT
1418+ _ASM_EXTABLE(2b, 4b)
1419+#endif
1420+
1421 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1422 : "r" (&v->counter), "r" (u), "r" (a)
1423 : "cc");
1424@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1425
1426 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1427 #define atomic64_inc(v) atomic64_add(1LL, (v))
1428+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1429 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1430+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1431 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1432 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1433 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1434+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1435 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1436 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1437 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1438diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1439index 75fe66b..2255c86 100644
1440--- a/arch/arm/include/asm/cache.h
1441+++ b/arch/arm/include/asm/cache.h
1442@@ -4,8 +4,10 @@
1443 #ifndef __ASMARM_CACHE_H
1444 #define __ASMARM_CACHE_H
1445
1446+#include <linux/const.h>
1447+
1448 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1449-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1450+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1451
1452 /*
1453 * Memory returned by kmalloc() may be used for DMA, so we must make
1454diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1455index e4448e1..7bc86b7 100644
1456--- a/arch/arm/include/asm/cacheflush.h
1457+++ b/arch/arm/include/asm/cacheflush.h
1458@@ -108,7 +108,7 @@ struct cpu_cache_fns {
1459 void (*dma_unmap_area)(const void *, size_t, int);
1460
1461 void (*dma_flush_range)(const void *, const void *);
1462-};
1463+} __no_const;
1464
1465 /*
1466 * Select the calling method
1467diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1468index 7eb18c1..e38b6d2 100644
1469--- a/arch/arm/include/asm/cmpxchg.h
1470+++ b/arch/arm/include/asm/cmpxchg.h
1471@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1472
1473 #define xchg(ptr,x) \
1474 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1475+#define xchg_unchecked(ptr,x) \
1476+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1477
1478 #include <asm-generic/cmpxchg-local.h>
1479
1480diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1481index 38050b1..9d90e8b 100644
1482--- a/arch/arm/include/asm/elf.h
1483+++ b/arch/arm/include/asm/elf.h
1484@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1485 the loader. We need to make sure that it is out of the way of the program
1486 that it will "exec", and that there is sufficient room for the brk. */
1487
1488-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1489+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1490+
1491+#ifdef CONFIG_PAX_ASLR
1492+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1493+
1494+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1495+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1496+#endif
1497
1498 /* When the program starts, a1 contains a pointer to a function to be
1499 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1500@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1501 extern void elf_set_personality(const struct elf32_hdr *);
1502 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1503
1504-struct mm_struct;
1505-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1506-#define arch_randomize_brk arch_randomize_brk
1507-
1508 #endif
1509diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1510index e51b1e8..32a3113 100644
1511--- a/arch/arm/include/asm/kmap_types.h
1512+++ b/arch/arm/include/asm/kmap_types.h
1513@@ -21,6 +21,7 @@ enum km_type {
1514 KM_L1_CACHE,
1515 KM_L2_CACHE,
1516 KM_KDB,
1517+ KM_CLEARPAGE,
1518 KM_TYPE_NR
1519 };
1520
1521diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1522index 53426c6..c7baff3 100644
1523--- a/arch/arm/include/asm/outercache.h
1524+++ b/arch/arm/include/asm/outercache.h
1525@@ -35,7 +35,7 @@ struct outer_cache_fns {
1526 #endif
1527 void (*set_debug)(unsigned long);
1528 void (*resume)(void);
1529-};
1530+} __no_const;
1531
1532 #ifdef CONFIG_OUTER_CACHE
1533
1534diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1535index ecf9019..b71d9a1 100644
1536--- a/arch/arm/include/asm/page.h
1537+++ b/arch/arm/include/asm/page.h
1538@@ -114,7 +114,7 @@ struct cpu_user_fns {
1539 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1540 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1541 unsigned long vaddr, struct vm_area_struct *vma);
1542-};
1543+} __no_const;
1544
1545 #ifdef MULTI_USER
1546 extern struct cpu_user_fns cpu_user;
1547diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1548index 943504f..bf8d667 100644
1549--- a/arch/arm/include/asm/pgalloc.h
1550+++ b/arch/arm/include/asm/pgalloc.h
1551@@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1552 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1553 }
1554
1555+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1556+{
1557+ pud_populate(mm, pud, pmd);
1558+}
1559+
1560 #else /* !CONFIG_ARM_LPAE */
1561
1562 /*
1563@@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1564 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1565 #define pmd_free(mm, pmd) do { } while (0)
1566 #define pud_populate(mm,pmd,pte) BUG()
1567+#define pud_populate_kernel(mm,pmd,pte) BUG()
1568
1569 #endif /* CONFIG_ARM_LPAE */
1570
1571diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1572index af7b0bd..6750a8c 100644
1573--- a/arch/arm/include/asm/thread_info.h
1574+++ b/arch/arm/include/asm/thread_info.h
1575@@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1576 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1577 #define TIF_SYSCALL_TRACE 8
1578 #define TIF_SYSCALL_AUDIT 9
1579+
1580+/* within 8 bits of TIF_SYSCALL_TRACE
1581+ to meet flexible second operand requirements
1582+*/
1583+#define TIF_GRSEC_SETXID 10
1584+
1585 #define TIF_POLLING_NRFLAG 16
1586 #define TIF_USING_IWMMXT 17
1587 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1588@@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1589 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1590 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1591 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1592+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1593
1594 /* Checks for any syscall work in entry-common.S */
1595-#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1596+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1597+ _TIF_GRSEC_SETXID)
1598
1599 /*
1600 * Change these and you break ASM code in entry-common.S
1601diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1602index 0a070e9..9e9e129 100644
1603--- a/arch/arm/include/asm/uaccess.h
1604+++ b/arch/arm/include/asm/uaccess.h
1605@@ -22,6 +22,8 @@
1606 #define VERIFY_READ 0
1607 #define VERIFY_WRITE 1
1608
1609+extern void check_object_size(const void *ptr, unsigned long n, bool to);
1610+
1611 /*
1612 * The exception table consists of pairs of addresses: the first is the
1613 * address of an instruction that is allowed to fault, and the second is
1614@@ -401,8 +403,23 @@ do { \
1615
1616
1617 #ifdef CONFIG_MMU
1618-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1619-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1620+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1621+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1622+
1623+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1624+{
1625+ if (!__builtin_constant_p(n))
1626+ check_object_size(to, n, false);
1627+ return ___copy_from_user(to, from, n);
1628+}
1629+
1630+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1631+{
1632+ if (!__builtin_constant_p(n))
1633+ check_object_size(from, n, true);
1634+ return ___copy_to_user(to, from, n);
1635+}
1636+
1637 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1638 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1639 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1640@@ -417,6 +434,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1641
1642 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1643 {
1644+ if ((long)n < 0)
1645+ return n;
1646+
1647 if (access_ok(VERIFY_READ, from, n))
1648 n = __copy_from_user(to, from, n);
1649 else /* security hole - plug it */
1650@@ -426,6 +446,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1651
1652 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1653 {
1654+ if ((long)n < 0)
1655+ return n;
1656+
1657 if (access_ok(VERIFY_WRITE, to, n))
1658 n = __copy_to_user(to, from, n);
1659 return n;
1660diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1661index b57c75e..ed2d6b2 100644
1662--- a/arch/arm/kernel/armksyms.c
1663+++ b/arch/arm/kernel/armksyms.c
1664@@ -94,8 +94,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1665 #ifdef CONFIG_MMU
1666 EXPORT_SYMBOL(copy_page);
1667
1668-EXPORT_SYMBOL(__copy_from_user);
1669-EXPORT_SYMBOL(__copy_to_user);
1670+EXPORT_SYMBOL(___copy_from_user);
1671+EXPORT_SYMBOL(___copy_to_user);
1672 EXPORT_SYMBOL(__clear_user);
1673
1674 EXPORT_SYMBOL(__get_user_1);
1675diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1676index 693b744..e684262 100644
1677--- a/arch/arm/kernel/process.c
1678+++ b/arch/arm/kernel/process.c
1679@@ -28,7 +28,6 @@
1680 #include <linux/tick.h>
1681 #include <linux/utsname.h>
1682 #include <linux/uaccess.h>
1683-#include <linux/random.h>
1684 #include <linux/hw_breakpoint.h>
1685 #include <linux/cpuidle.h>
1686
1687@@ -256,9 +255,10 @@ void machine_power_off(void)
1688 machine_shutdown();
1689 if (pm_power_off)
1690 pm_power_off();
1691+ BUG();
1692 }
1693
1694-void machine_restart(char *cmd)
1695+__noreturn void machine_restart(char *cmd)
1696 {
1697 machine_shutdown();
1698
1699@@ -501,12 +501,6 @@ unsigned long get_wchan(struct task_struct *p)
1700 return 0;
1701 }
1702
1703-unsigned long arch_randomize_brk(struct mm_struct *mm)
1704-{
1705- unsigned long range_end = mm->brk + 0x02000000;
1706- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1707-}
1708-
1709 #ifdef CONFIG_MMU
1710 /*
1711 * The vectors page is always readable from user space for the
1712diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1713index 14e3826..d832d89 100644
1714--- a/arch/arm/kernel/ptrace.c
1715+++ b/arch/arm/kernel/ptrace.c
1716@@ -907,10 +907,19 @@ long arch_ptrace(struct task_struct *child, long request,
1717 return ret;
1718 }
1719
1720+#ifdef CONFIG_GRKERNSEC_SETXID
1721+extern void gr_delayed_cred_worker(void);
1722+#endif
1723+
1724 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1725 {
1726 unsigned long ip;
1727
1728+#ifdef CONFIG_GRKERNSEC_SETXID
1729+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1730+ gr_delayed_cred_worker();
1731+#endif
1732+
1733 if (why)
1734 audit_syscall_exit(regs);
1735 else
1736diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1737index e15d83b..8c466dd 100644
1738--- a/arch/arm/kernel/setup.c
1739+++ b/arch/arm/kernel/setup.c
1740@@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1741 struct cpu_tlb_fns cpu_tlb __read_mostly;
1742 #endif
1743 #ifdef MULTI_USER
1744-struct cpu_user_fns cpu_user __read_mostly;
1745+struct cpu_user_fns cpu_user __read_only;
1746 #endif
1747 #ifdef MULTI_CACHE
1748-struct cpu_cache_fns cpu_cache __read_mostly;
1749+struct cpu_cache_fns cpu_cache __read_only;
1750 #endif
1751 #ifdef CONFIG_OUTER_CACHE
1752-struct outer_cache_fns outer_cache __read_mostly;
1753+struct outer_cache_fns outer_cache __read_only;
1754 EXPORT_SYMBOL(outer_cache);
1755 #endif
1756
1757diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1758index eeb7520..1cbe902 100644
1759--- a/arch/arm/kernel/traps.c
1760+++ b/arch/arm/kernel/traps.c
1761@@ -264,6 +264,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1762
1763 static DEFINE_RAW_SPINLOCK(die_lock);
1764
1765+extern void gr_handle_kernel_exploit(void);
1766+
1767 /*
1768 * This function is protected against re-entrancy.
1769 */
1770@@ -296,6 +298,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1771 panic("Fatal exception in interrupt");
1772 if (panic_on_oops)
1773 panic("Fatal exception");
1774+
1775+ gr_handle_kernel_exploit();
1776+
1777 if (ret != NOTIFY_STOP)
1778 do_exit(SIGSEGV);
1779 }
1780diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1781index 66a477a..bee61d3 100644
1782--- a/arch/arm/lib/copy_from_user.S
1783+++ b/arch/arm/lib/copy_from_user.S
1784@@ -16,7 +16,7 @@
1785 /*
1786 * Prototype:
1787 *
1788- * size_t __copy_from_user(void *to, const void *from, size_t n)
1789+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
1790 *
1791 * Purpose:
1792 *
1793@@ -84,11 +84,11 @@
1794
1795 .text
1796
1797-ENTRY(__copy_from_user)
1798+ENTRY(___copy_from_user)
1799
1800 #include "copy_template.S"
1801
1802-ENDPROC(__copy_from_user)
1803+ENDPROC(___copy_from_user)
1804
1805 .pushsection .fixup,"ax"
1806 .align 0
1807diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1808index 6ee2f67..d1cce76 100644
1809--- a/arch/arm/lib/copy_page.S
1810+++ b/arch/arm/lib/copy_page.S
1811@@ -10,6 +10,7 @@
1812 * ASM optimised string functions
1813 */
1814 #include <linux/linkage.h>
1815+#include <linux/const.h>
1816 #include <asm/assembler.h>
1817 #include <asm/asm-offsets.h>
1818 #include <asm/cache.h>
1819diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1820index d066df6..df28194 100644
1821--- a/arch/arm/lib/copy_to_user.S
1822+++ b/arch/arm/lib/copy_to_user.S
1823@@ -16,7 +16,7 @@
1824 /*
1825 * Prototype:
1826 *
1827- * size_t __copy_to_user(void *to, const void *from, size_t n)
1828+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
1829 *
1830 * Purpose:
1831 *
1832@@ -88,11 +88,11 @@
1833 .text
1834
1835 ENTRY(__copy_to_user_std)
1836-WEAK(__copy_to_user)
1837+WEAK(___copy_to_user)
1838
1839 #include "copy_template.S"
1840
1841-ENDPROC(__copy_to_user)
1842+ENDPROC(___copy_to_user)
1843 ENDPROC(__copy_to_user_std)
1844
1845 .pushsection .fixup,"ax"
1846diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1847index 025f742..8432b08 100644
1848--- a/arch/arm/lib/uaccess_with_memcpy.c
1849+++ b/arch/arm/lib/uaccess_with_memcpy.c
1850@@ -104,7 +104,7 @@ out:
1851 }
1852
1853 unsigned long
1854-__copy_to_user(void __user *to, const void *from, unsigned long n)
1855+___copy_to_user(void __user *to, const void *from, unsigned long n)
1856 {
1857 /*
1858 * This test is stubbed out of the main function above to keep
1859diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1860index f261cd2..4ae63fb 100644
1861--- a/arch/arm/mach-kirkwood/common.c
1862+++ b/arch/arm/mach-kirkwood/common.c
1863@@ -128,7 +128,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1864 clk_gate_ops.disable(hw);
1865 }
1866
1867-static struct clk_ops clk_gate_fn_ops;
1868+static clk_ops_no_const clk_gate_fn_ops;
1869
1870 static struct clk __init *clk_register_gate_fn(struct device *dev,
1871 const char *name,
1872diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1873index 2c5d0ed..7d9099c 100644
1874--- a/arch/arm/mach-omap2/board-n8x0.c
1875+++ b/arch/arm/mach-omap2/board-n8x0.c
1876@@ -594,7 +594,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1877 }
1878 #endif
1879
1880-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1881+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1882 .late_init = n8x0_menelaus_late_init,
1883 };
1884
1885diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1886index c3bd834..e81ef02 100644
1887--- a/arch/arm/mm/fault.c
1888+++ b/arch/arm/mm/fault.c
1889@@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1890 }
1891 #endif
1892
1893+#ifdef CONFIG_PAX_PAGEEXEC
1894+ if (fsr & FSR_LNX_PF) {
1895+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1896+ do_group_exit(SIGKILL);
1897+ }
1898+#endif
1899+
1900 tsk->thread.address = addr;
1901 tsk->thread.error_code = fsr;
1902 tsk->thread.trap_no = 14;
1903@@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1904 }
1905 #endif /* CONFIG_MMU */
1906
1907+#ifdef CONFIG_PAX_PAGEEXEC
1908+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1909+{
1910+ long i;
1911+
1912+ printk(KERN_ERR "PAX: bytes at PC: ");
1913+ for (i = 0; i < 20; i++) {
1914+ unsigned char c;
1915+ if (get_user(c, (__force unsigned char __user *)pc+i))
1916+ printk(KERN_CONT "?? ");
1917+ else
1918+ printk(KERN_CONT "%02x ", c);
1919+ }
1920+ printk("\n");
1921+
1922+ printk(KERN_ERR "PAX: bytes at SP-4: ");
1923+ for (i = -1; i < 20; i++) {
1924+ unsigned long c;
1925+ if (get_user(c, (__force unsigned long __user *)sp+i))
1926+ printk(KERN_CONT "???????? ");
1927+ else
1928+ printk(KERN_CONT "%08lx ", c);
1929+ }
1930+ printk("\n");
1931+}
1932+#endif
1933+
1934 /*
1935 * First Level Translation Fault Handler
1936 *
1937@@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1938 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1939 struct siginfo info;
1940
1941+#ifdef CONFIG_PAX_REFCOUNT
1942+ if (fsr_fs(ifsr) == 2) {
1943+ unsigned int bkpt;
1944+
1945+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1946+ current->thread.error_code = ifsr;
1947+ current->thread.trap_no = 0;
1948+ pax_report_refcount_overflow(regs);
1949+ fixup_exception(regs);
1950+ return;
1951+ }
1952+ }
1953+#endif
1954+
1955 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1956 return;
1957
1958diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1959index ce8cb19..3ec539d 100644
1960--- a/arch/arm/mm/mmap.c
1961+++ b/arch/arm/mm/mmap.c
1962@@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1963 if (len > TASK_SIZE)
1964 return -ENOMEM;
1965
1966+#ifdef CONFIG_PAX_RANDMMAP
1967+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1968+#endif
1969+
1970 if (addr) {
1971 if (do_align)
1972 addr = COLOUR_ALIGN(addr, pgoff);
1973@@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1974 addr = PAGE_ALIGN(addr);
1975
1976 vma = find_vma(mm, addr);
1977- if (TASK_SIZE - len >= addr &&
1978- (!vma || addr + len <= vma->vm_start))
1979+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1980 return addr;
1981 }
1982 if (len > mm->cached_hole_size) {
1983- start_addr = addr = mm->free_area_cache;
1984+ start_addr = addr = mm->free_area_cache;
1985 } else {
1986- start_addr = addr = mm->mmap_base;
1987- mm->cached_hole_size = 0;
1988+ start_addr = addr = mm->mmap_base;
1989+ mm->cached_hole_size = 0;
1990 }
1991
1992 full_search:
1993@@ -124,14 +127,14 @@ full_search:
1994 * Start a new search - just in case we missed
1995 * some holes.
1996 */
1997- if (start_addr != TASK_UNMAPPED_BASE) {
1998- start_addr = addr = TASK_UNMAPPED_BASE;
1999+ if (start_addr != mm->mmap_base) {
2000+ start_addr = addr = mm->mmap_base;
2001 mm->cached_hole_size = 0;
2002 goto full_search;
2003 }
2004 return -ENOMEM;
2005 }
2006- if (!vma || addr + len <= vma->vm_start) {
2007+ if (check_heap_stack_gap(vma, addr, len)) {
2008 /*
2009 * Remember the place where we stopped the search:
2010 */
2011@@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2012
2013 if (mmap_is_legacy()) {
2014 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2015+
2016+#ifdef CONFIG_PAX_RANDMMAP
2017+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2018+ mm->mmap_base += mm->delta_mmap;
2019+#endif
2020+
2021 mm->get_unmapped_area = arch_get_unmapped_area;
2022 mm->unmap_area = arch_unmap_area;
2023 } else {
2024 mm->mmap_base = mmap_base(random_factor);
2025+
2026+#ifdef CONFIG_PAX_RANDMMAP
2027+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2028+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2029+#endif
2030+
2031 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2032 mm->unmap_area = arch_unmap_area_topdown;
2033 }
2034diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2035index fd556f7..af2e7d2 100644
2036--- a/arch/arm/plat-orion/include/plat/addr-map.h
2037+++ b/arch/arm/plat-orion/include/plat/addr-map.h
2038@@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2039 value in bridge_virt_base */
2040 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2041 const int win);
2042-};
2043+} __no_const;
2044
2045 /*
2046 * Information needed to setup one address mapping.
2047diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2048index 71a6827..e7fbc23 100644
2049--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2050+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2051@@ -43,7 +43,7 @@ struct samsung_dma_ops {
2052 int (*started)(unsigned ch);
2053 int (*flush)(unsigned ch);
2054 int (*stop)(unsigned ch);
2055-};
2056+} __no_const;
2057
2058 extern void *samsung_dmadev_get_ops(void);
2059 extern void *s3c_dma_get_ops(void);
2060diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2061index 5f28cae..3d23723 100644
2062--- a/arch/arm/plat-samsung/include/plat/ehci.h
2063+++ b/arch/arm/plat-samsung/include/plat/ehci.h
2064@@ -14,7 +14,7 @@
2065 struct s5p_ehci_platdata {
2066 int (*phy_init)(struct platform_device *pdev, int type);
2067 int (*phy_exit)(struct platform_device *pdev, int type);
2068-};
2069+} __no_const;
2070
2071 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2072
2073diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2074index c3a58a1..78fbf54 100644
2075--- a/arch/avr32/include/asm/cache.h
2076+++ b/arch/avr32/include/asm/cache.h
2077@@ -1,8 +1,10 @@
2078 #ifndef __ASM_AVR32_CACHE_H
2079 #define __ASM_AVR32_CACHE_H
2080
2081+#include <linux/const.h>
2082+
2083 #define L1_CACHE_SHIFT 5
2084-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2085+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2086
2087 /*
2088 * Memory returned by kmalloc() may be used for DMA, so we must make
2089diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2090index 3b3159b..425ea94 100644
2091--- a/arch/avr32/include/asm/elf.h
2092+++ b/arch/avr32/include/asm/elf.h
2093@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2094 the loader. We need to make sure that it is out of the way of the program
2095 that it will "exec", and that there is sufficient room for the brk. */
2096
2097-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2098+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2099
2100+#ifdef CONFIG_PAX_ASLR
2101+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2102+
2103+#define PAX_DELTA_MMAP_LEN 15
2104+#define PAX_DELTA_STACK_LEN 15
2105+#endif
2106
2107 /* This yields a mask that user programs can use to figure out what
2108 instruction set this CPU supports. This could be done in user space,
2109diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2110index b7f5c68..556135c 100644
2111--- a/arch/avr32/include/asm/kmap_types.h
2112+++ b/arch/avr32/include/asm/kmap_types.h
2113@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2114 D(11) KM_IRQ1,
2115 D(12) KM_SOFTIRQ0,
2116 D(13) KM_SOFTIRQ1,
2117-D(14) KM_TYPE_NR
2118+D(14) KM_CLEARPAGE,
2119+D(15) KM_TYPE_NR
2120 };
2121
2122 #undef D
2123diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2124index f7040a1..db9f300 100644
2125--- a/arch/avr32/mm/fault.c
2126+++ b/arch/avr32/mm/fault.c
2127@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2128
2129 int exception_trace = 1;
2130
2131+#ifdef CONFIG_PAX_PAGEEXEC
2132+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2133+{
2134+ unsigned long i;
2135+
2136+ printk(KERN_ERR "PAX: bytes at PC: ");
2137+ for (i = 0; i < 20; i++) {
2138+ unsigned char c;
2139+ if (get_user(c, (unsigned char *)pc+i))
2140+ printk(KERN_CONT "???????? ");
2141+ else
2142+ printk(KERN_CONT "%02x ", c);
2143+ }
2144+ printk("\n");
2145+}
2146+#endif
2147+
2148 /*
2149 * This routine handles page faults. It determines the address and the
2150 * problem, and then passes it off to one of the appropriate routines.
2151@@ -156,6 +173,16 @@ bad_area:
2152 up_read(&mm->mmap_sem);
2153
2154 if (user_mode(regs)) {
2155+
2156+#ifdef CONFIG_PAX_PAGEEXEC
2157+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2158+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2159+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2160+ do_group_exit(SIGKILL);
2161+ }
2162+ }
2163+#endif
2164+
2165 if (exception_trace && printk_ratelimit())
2166 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2167 "sp %08lx ecr %lu\n",
2168diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2169index 568885a..f8008df 100644
2170--- a/arch/blackfin/include/asm/cache.h
2171+++ b/arch/blackfin/include/asm/cache.h
2172@@ -7,6 +7,7 @@
2173 #ifndef __ARCH_BLACKFIN_CACHE_H
2174 #define __ARCH_BLACKFIN_CACHE_H
2175
2176+#include <linux/const.h>
2177 #include <linux/linkage.h> /* for asmlinkage */
2178
2179 /*
2180@@ -14,7 +15,7 @@
2181 * Blackfin loads 32 bytes for cache
2182 */
2183 #define L1_CACHE_SHIFT 5
2184-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2185+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2186 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2187
2188 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2189diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2190index aea2718..3639a60 100644
2191--- a/arch/cris/include/arch-v10/arch/cache.h
2192+++ b/arch/cris/include/arch-v10/arch/cache.h
2193@@ -1,8 +1,9 @@
2194 #ifndef _ASM_ARCH_CACHE_H
2195 #define _ASM_ARCH_CACHE_H
2196
2197+#include <linux/const.h>
2198 /* Etrax 100LX have 32-byte cache-lines. */
2199-#define L1_CACHE_BYTES 32
2200 #define L1_CACHE_SHIFT 5
2201+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2202
2203 #endif /* _ASM_ARCH_CACHE_H */
2204diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2205index 7caf25d..ee65ac5 100644
2206--- a/arch/cris/include/arch-v32/arch/cache.h
2207+++ b/arch/cris/include/arch-v32/arch/cache.h
2208@@ -1,11 +1,12 @@
2209 #ifndef _ASM_CRIS_ARCH_CACHE_H
2210 #define _ASM_CRIS_ARCH_CACHE_H
2211
2212+#include <linux/const.h>
2213 #include <arch/hwregs/dma.h>
2214
2215 /* A cache-line is 32 bytes. */
2216-#define L1_CACHE_BYTES 32
2217 #define L1_CACHE_SHIFT 5
2218+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2219
2220 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2221
2222diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2223index b86329d..6709906 100644
2224--- a/arch/frv/include/asm/atomic.h
2225+++ b/arch/frv/include/asm/atomic.h
2226@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2227 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2228 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2229
2230+#define atomic64_read_unchecked(v) atomic64_read(v)
2231+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2232+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2233+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2234+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2235+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2236+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2237+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2238+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2239+
2240 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2241 {
2242 int c, old;
2243diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2244index 2797163..c2a401d 100644
2245--- a/arch/frv/include/asm/cache.h
2246+++ b/arch/frv/include/asm/cache.h
2247@@ -12,10 +12,11 @@
2248 #ifndef __ASM_CACHE_H
2249 #define __ASM_CACHE_H
2250
2251+#include <linux/const.h>
2252
2253 /* bytes per L1 cache line */
2254 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2255-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2256+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2257
2258 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2259 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2260diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2261index f8e16b2..c73ff79 100644
2262--- a/arch/frv/include/asm/kmap_types.h
2263+++ b/arch/frv/include/asm/kmap_types.h
2264@@ -23,6 +23,7 @@ enum km_type {
2265 KM_IRQ1,
2266 KM_SOFTIRQ0,
2267 KM_SOFTIRQ1,
2268+ KM_CLEARPAGE,
2269 KM_TYPE_NR
2270 };
2271
2272diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2273index 385fd30..6c3d97e 100644
2274--- a/arch/frv/mm/elf-fdpic.c
2275+++ b/arch/frv/mm/elf-fdpic.c
2276@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2277 if (addr) {
2278 addr = PAGE_ALIGN(addr);
2279 vma = find_vma(current->mm, addr);
2280- if (TASK_SIZE - len >= addr &&
2281- (!vma || addr + len <= vma->vm_start))
2282+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2283 goto success;
2284 }
2285
2286@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2287 for (; vma; vma = vma->vm_next) {
2288 if (addr > limit)
2289 break;
2290- if (addr + len <= vma->vm_start)
2291+ if (check_heap_stack_gap(vma, addr, len))
2292 goto success;
2293 addr = vma->vm_end;
2294 }
2295@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2296 for (; vma; vma = vma->vm_next) {
2297 if (addr > limit)
2298 break;
2299- if (addr + len <= vma->vm_start)
2300+ if (check_heap_stack_gap(vma, addr, len))
2301 goto success;
2302 addr = vma->vm_end;
2303 }
2304diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2305index c635028..6d9445a 100644
2306--- a/arch/h8300/include/asm/cache.h
2307+++ b/arch/h8300/include/asm/cache.h
2308@@ -1,8 +1,10 @@
2309 #ifndef __ARCH_H8300_CACHE_H
2310 #define __ARCH_H8300_CACHE_H
2311
2312+#include <linux/const.h>
2313+
2314 /* bytes per L1 cache line */
2315-#define L1_CACHE_BYTES 4
2316+#define L1_CACHE_BYTES _AC(4,UL)
2317
2318 /* m68k-elf-gcc 2.95.2 doesn't like these */
2319
2320diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2321index 0f01de2..d37d309 100644
2322--- a/arch/hexagon/include/asm/cache.h
2323+++ b/arch/hexagon/include/asm/cache.h
2324@@ -21,9 +21,11 @@
2325 #ifndef __ASM_CACHE_H
2326 #define __ASM_CACHE_H
2327
2328+#include <linux/const.h>
2329+
2330 /* Bytes per L1 cache line */
2331-#define L1_CACHE_SHIFT (5)
2332-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2333+#define L1_CACHE_SHIFT 5
2334+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2335
2336 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2337 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2338diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2339index 6e6fe18..a6ae668 100644
2340--- a/arch/ia64/include/asm/atomic.h
2341+++ b/arch/ia64/include/asm/atomic.h
2342@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2343 #define atomic64_inc(v) atomic64_add(1, (v))
2344 #define atomic64_dec(v) atomic64_sub(1, (v))
2345
2346+#define atomic64_read_unchecked(v) atomic64_read(v)
2347+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2348+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2349+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2350+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2351+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2352+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2353+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2354+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2355+
2356 /* Atomic operations are already serializing */
2357 #define smp_mb__before_atomic_dec() barrier()
2358 #define smp_mb__after_atomic_dec() barrier()
2359diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2360index 988254a..e1ee885 100644
2361--- a/arch/ia64/include/asm/cache.h
2362+++ b/arch/ia64/include/asm/cache.h
2363@@ -1,6 +1,7 @@
2364 #ifndef _ASM_IA64_CACHE_H
2365 #define _ASM_IA64_CACHE_H
2366
2367+#include <linux/const.h>
2368
2369 /*
2370 * Copyright (C) 1998-2000 Hewlett-Packard Co
2371@@ -9,7 +10,7 @@
2372
2373 /* Bytes per L1 (data) cache line. */
2374 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2375-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2376+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2377
2378 #ifdef CONFIG_SMP
2379 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2380diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2381index b5298eb..67c6e62 100644
2382--- a/arch/ia64/include/asm/elf.h
2383+++ b/arch/ia64/include/asm/elf.h
2384@@ -42,6 +42,13 @@
2385 */
2386 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2387
2388+#ifdef CONFIG_PAX_ASLR
2389+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2390+
2391+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2392+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2393+#endif
2394+
2395 #define PT_IA_64_UNWIND 0x70000001
2396
2397 /* IA-64 relocations: */
2398diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2399index 96a8d92..617a1cf 100644
2400--- a/arch/ia64/include/asm/pgalloc.h
2401+++ b/arch/ia64/include/asm/pgalloc.h
2402@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2403 pgd_val(*pgd_entry) = __pa(pud);
2404 }
2405
2406+static inline void
2407+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2408+{
2409+ pgd_populate(mm, pgd_entry, pud);
2410+}
2411+
2412 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2413 {
2414 return quicklist_alloc(0, GFP_KERNEL, NULL);
2415@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2416 pud_val(*pud_entry) = __pa(pmd);
2417 }
2418
2419+static inline void
2420+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2421+{
2422+ pud_populate(mm, pud_entry, pmd);
2423+}
2424+
2425 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2426 {
2427 return quicklist_alloc(0, GFP_KERNEL, NULL);
2428diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2429index 815810c..d60bd4c 100644
2430--- a/arch/ia64/include/asm/pgtable.h
2431+++ b/arch/ia64/include/asm/pgtable.h
2432@@ -12,7 +12,7 @@
2433 * David Mosberger-Tang <davidm@hpl.hp.com>
2434 */
2435
2436-
2437+#include <linux/const.h>
2438 #include <asm/mman.h>
2439 #include <asm/page.h>
2440 #include <asm/processor.h>
2441@@ -142,6 +142,17 @@
2442 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2443 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2444 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2445+
2446+#ifdef CONFIG_PAX_PAGEEXEC
2447+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2448+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2449+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2450+#else
2451+# define PAGE_SHARED_NOEXEC PAGE_SHARED
2452+# define PAGE_READONLY_NOEXEC PAGE_READONLY
2453+# define PAGE_COPY_NOEXEC PAGE_COPY
2454+#endif
2455+
2456 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2457 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2458 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2459diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2460index 54ff557..70c88b7 100644
2461--- a/arch/ia64/include/asm/spinlock.h
2462+++ b/arch/ia64/include/asm/spinlock.h
2463@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2464 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2465
2466 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2467- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2468+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2469 }
2470
2471 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2472diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2473index 449c8c0..432a3d2 100644
2474--- a/arch/ia64/include/asm/uaccess.h
2475+++ b/arch/ia64/include/asm/uaccess.h
2476@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2477 const void *__cu_from = (from); \
2478 long __cu_len = (n); \
2479 \
2480- if (__access_ok(__cu_to, __cu_len, get_fs())) \
2481+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2482 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2483 __cu_len; \
2484 })
2485@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2486 long __cu_len = (n); \
2487 \
2488 __chk_user_ptr(__cu_from); \
2489- if (__access_ok(__cu_from, __cu_len, get_fs())) \
2490+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2491 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2492 __cu_len; \
2493 })
2494diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2495index 24603be..948052d 100644
2496--- a/arch/ia64/kernel/module.c
2497+++ b/arch/ia64/kernel/module.c
2498@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2499 void
2500 module_free (struct module *mod, void *module_region)
2501 {
2502- if (mod && mod->arch.init_unw_table &&
2503- module_region == mod->module_init) {
2504+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2505 unw_remove_unwind_table(mod->arch.init_unw_table);
2506 mod->arch.init_unw_table = NULL;
2507 }
2508@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2509 }
2510
2511 static inline int
2512+in_init_rx (const struct module *mod, uint64_t addr)
2513+{
2514+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2515+}
2516+
2517+static inline int
2518+in_init_rw (const struct module *mod, uint64_t addr)
2519+{
2520+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2521+}
2522+
2523+static inline int
2524 in_init (const struct module *mod, uint64_t addr)
2525 {
2526- return addr - (uint64_t) mod->module_init < mod->init_size;
2527+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2528+}
2529+
2530+static inline int
2531+in_core_rx (const struct module *mod, uint64_t addr)
2532+{
2533+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2534+}
2535+
2536+static inline int
2537+in_core_rw (const struct module *mod, uint64_t addr)
2538+{
2539+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2540 }
2541
2542 static inline int
2543 in_core (const struct module *mod, uint64_t addr)
2544 {
2545- return addr - (uint64_t) mod->module_core < mod->core_size;
2546+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2547 }
2548
2549 static inline int
2550@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2551 break;
2552
2553 case RV_BDREL:
2554- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2555+ if (in_init_rx(mod, val))
2556+ val -= (uint64_t) mod->module_init_rx;
2557+ else if (in_init_rw(mod, val))
2558+ val -= (uint64_t) mod->module_init_rw;
2559+ else if (in_core_rx(mod, val))
2560+ val -= (uint64_t) mod->module_core_rx;
2561+ else if (in_core_rw(mod, val))
2562+ val -= (uint64_t) mod->module_core_rw;
2563 break;
2564
2565 case RV_LTV:
2566@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2567 * addresses have been selected...
2568 */
2569 uint64_t gp;
2570- if (mod->core_size > MAX_LTOFF)
2571+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2572 /*
2573 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2574 * at the end of the module.
2575 */
2576- gp = mod->core_size - MAX_LTOFF / 2;
2577+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2578 else
2579- gp = mod->core_size / 2;
2580- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2581+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2582+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2583 mod->arch.gp = gp;
2584 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2585 }
2586diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2587index d9439ef..b9a4303 100644
2588--- a/arch/ia64/kernel/sys_ia64.c
2589+++ b/arch/ia64/kernel/sys_ia64.c
2590@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2591 if (REGION_NUMBER(addr) == RGN_HPAGE)
2592 addr = 0;
2593 #endif
2594+
2595+#ifdef CONFIG_PAX_RANDMMAP
2596+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2597+ addr = mm->free_area_cache;
2598+ else
2599+#endif
2600+
2601 if (!addr)
2602 addr = mm->free_area_cache;
2603
2604@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2605 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2606 /* At this point: (!vma || addr < vma->vm_end). */
2607 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2608- if (start_addr != TASK_UNMAPPED_BASE) {
2609+ if (start_addr != mm->mmap_base) {
2610 /* Start a new search --- just in case we missed some holes. */
2611- addr = TASK_UNMAPPED_BASE;
2612+ addr = mm->mmap_base;
2613 goto full_search;
2614 }
2615 return -ENOMEM;
2616 }
2617- if (!vma || addr + len <= vma->vm_start) {
2618+ if (check_heap_stack_gap(vma, addr, len)) {
2619 /* Remember the address where we stopped this search: */
2620 mm->free_area_cache = addr + len;
2621 return addr;
2622diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2623index 0ccb28f..8992469 100644
2624--- a/arch/ia64/kernel/vmlinux.lds.S
2625+++ b/arch/ia64/kernel/vmlinux.lds.S
2626@@ -198,7 +198,7 @@ SECTIONS {
2627 /* Per-cpu data: */
2628 . = ALIGN(PERCPU_PAGE_SIZE);
2629 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2630- __phys_per_cpu_start = __per_cpu_load;
2631+ __phys_per_cpu_start = per_cpu_load;
2632 /*
2633 * ensure percpu data fits
2634 * into percpu page size
2635diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2636index 02d29c2..ea893df 100644
2637--- a/arch/ia64/mm/fault.c
2638+++ b/arch/ia64/mm/fault.c
2639@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2640 return pte_present(pte);
2641 }
2642
2643+#ifdef CONFIG_PAX_PAGEEXEC
2644+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2645+{
2646+ unsigned long i;
2647+
2648+ printk(KERN_ERR "PAX: bytes at PC: ");
2649+ for (i = 0; i < 8; i++) {
2650+ unsigned int c;
2651+ if (get_user(c, (unsigned int *)pc+i))
2652+ printk(KERN_CONT "???????? ");
2653+ else
2654+ printk(KERN_CONT "%08x ", c);
2655+ }
2656+ printk("\n");
2657+}
2658+#endif
2659+
2660 void __kprobes
2661 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2662 {
2663@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2664 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2665 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2666
2667- if ((vma->vm_flags & mask) != mask)
2668+ if ((vma->vm_flags & mask) != mask) {
2669+
2670+#ifdef CONFIG_PAX_PAGEEXEC
2671+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2672+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2673+ goto bad_area;
2674+
2675+ up_read(&mm->mmap_sem);
2676+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2677+ do_group_exit(SIGKILL);
2678+ }
2679+#endif
2680+
2681 goto bad_area;
2682
2683+ }
2684+
2685 /*
2686 * If for any reason at all we couldn't handle the fault, make
2687 * sure we exit gracefully rather than endlessly redo the
2688diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2689index 5ca674b..e0e1b70 100644
2690--- a/arch/ia64/mm/hugetlbpage.c
2691+++ b/arch/ia64/mm/hugetlbpage.c
2692@@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2693 /* At this point: (!vmm || addr < vmm->vm_end). */
2694 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2695 return -ENOMEM;
2696- if (!vmm || (addr + len) <= vmm->vm_start)
2697+ if (check_heap_stack_gap(vmm, addr, len))
2698 return addr;
2699 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2700 }
2701diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2702index 0eab454..bd794f2 100644
2703--- a/arch/ia64/mm/init.c
2704+++ b/arch/ia64/mm/init.c
2705@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2706 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2707 vma->vm_end = vma->vm_start + PAGE_SIZE;
2708 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2709+
2710+#ifdef CONFIG_PAX_PAGEEXEC
2711+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2712+ vma->vm_flags &= ~VM_EXEC;
2713+
2714+#ifdef CONFIG_PAX_MPROTECT
2715+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
2716+ vma->vm_flags &= ~VM_MAYEXEC;
2717+#endif
2718+
2719+ }
2720+#endif
2721+
2722 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2723 down_write(&current->mm->mmap_sem);
2724 if (insert_vm_struct(current->mm, vma)) {
2725diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2726index 40b3ee9..8c2c112 100644
2727--- a/arch/m32r/include/asm/cache.h
2728+++ b/arch/m32r/include/asm/cache.h
2729@@ -1,8 +1,10 @@
2730 #ifndef _ASM_M32R_CACHE_H
2731 #define _ASM_M32R_CACHE_H
2732
2733+#include <linux/const.h>
2734+
2735 /* L1 cache line size */
2736 #define L1_CACHE_SHIFT 4
2737-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2738+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2739
2740 #endif /* _ASM_M32R_CACHE_H */
2741diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2742index 82abd15..d95ae5d 100644
2743--- a/arch/m32r/lib/usercopy.c
2744+++ b/arch/m32r/lib/usercopy.c
2745@@ -14,6 +14,9 @@
2746 unsigned long
2747 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2748 {
2749+ if ((long)n < 0)
2750+ return n;
2751+
2752 prefetch(from);
2753 if (access_ok(VERIFY_WRITE, to, n))
2754 __copy_user(to,from,n);
2755@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2756 unsigned long
2757 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2758 {
2759+ if ((long)n < 0)
2760+ return n;
2761+
2762 prefetchw(to);
2763 if (access_ok(VERIFY_READ, from, n))
2764 __copy_user_zeroing(to,from,n);
2765diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2766index 0395c51..5f26031 100644
2767--- a/arch/m68k/include/asm/cache.h
2768+++ b/arch/m68k/include/asm/cache.h
2769@@ -4,9 +4,11 @@
2770 #ifndef __ARCH_M68K_CACHE_H
2771 #define __ARCH_M68K_CACHE_H
2772
2773+#include <linux/const.h>
2774+
2775 /* bytes per L1 cache line */
2776 #define L1_CACHE_SHIFT 4
2777-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2778+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2779
2780 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2781
2782diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2783index 4efe96a..60e8699 100644
2784--- a/arch/microblaze/include/asm/cache.h
2785+++ b/arch/microblaze/include/asm/cache.h
2786@@ -13,11 +13,12 @@
2787 #ifndef _ASM_MICROBLAZE_CACHE_H
2788 #define _ASM_MICROBLAZE_CACHE_H
2789
2790+#include <linux/const.h>
2791 #include <asm/registers.h>
2792
2793 #define L1_CACHE_SHIFT 5
2794 /* word-granular cache in microblaze */
2795-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2796+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2797
2798 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2799
2800diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2801index 3f4c5cb..3439c6e 100644
2802--- a/arch/mips/include/asm/atomic.h
2803+++ b/arch/mips/include/asm/atomic.h
2804@@ -21,6 +21,10 @@
2805 #include <asm/cmpxchg.h>
2806 #include <asm/war.h>
2807
2808+#ifdef CONFIG_GENERIC_ATOMIC64
2809+#include <asm-generic/atomic64.h>
2810+#endif
2811+
2812 #define ATOMIC_INIT(i) { (i) }
2813
2814 /*
2815@@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2816 */
2817 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2818
2819+#define atomic64_read_unchecked(v) atomic64_read(v)
2820+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2821+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2822+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2823+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2824+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2825+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2826+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2827+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2828+
2829 #endif /* CONFIG_64BIT */
2830
2831 /*
2832diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2833index b4db69f..8f3b093 100644
2834--- a/arch/mips/include/asm/cache.h
2835+++ b/arch/mips/include/asm/cache.h
2836@@ -9,10 +9,11 @@
2837 #ifndef _ASM_CACHE_H
2838 #define _ASM_CACHE_H
2839
2840+#include <linux/const.h>
2841 #include <kmalloc.h>
2842
2843 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2844-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2845+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2846
2847 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2848 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2849diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2850index 455c0ac..ad65fbe 100644
2851--- a/arch/mips/include/asm/elf.h
2852+++ b/arch/mips/include/asm/elf.h
2853@@ -372,13 +372,16 @@ extern const char *__elf_platform;
2854 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2855 #endif
2856
2857+#ifdef CONFIG_PAX_ASLR
2858+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2859+
2860+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2861+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2862+#endif
2863+
2864 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2865 struct linux_binprm;
2866 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2867 int uses_interp);
2868
2869-struct mm_struct;
2870-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2871-#define arch_randomize_brk arch_randomize_brk
2872-
2873 #endif /* _ASM_ELF_H */
2874diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2875index c1f6afa..38cc6e9 100644
2876--- a/arch/mips/include/asm/exec.h
2877+++ b/arch/mips/include/asm/exec.h
2878@@ -12,6 +12,6 @@
2879 #ifndef _ASM_EXEC_H
2880 #define _ASM_EXEC_H
2881
2882-extern unsigned long arch_align_stack(unsigned long sp);
2883+#define arch_align_stack(x) ((x) & ~0xfUL)
2884
2885 #endif /* _ASM_EXEC_H */
2886diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2887index da9bd7d..91aa7ab 100644
2888--- a/arch/mips/include/asm/page.h
2889+++ b/arch/mips/include/asm/page.h
2890@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2891 #ifdef CONFIG_CPU_MIPS32
2892 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2893 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2894- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2895+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2896 #else
2897 typedef struct { unsigned long long pte; } pte_t;
2898 #define pte_val(x) ((x).pte)
2899diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2900index 881d18b..cea38bc 100644
2901--- a/arch/mips/include/asm/pgalloc.h
2902+++ b/arch/mips/include/asm/pgalloc.h
2903@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2904 {
2905 set_pud(pud, __pud((unsigned long)pmd));
2906 }
2907+
2908+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2909+{
2910+ pud_populate(mm, pud, pmd);
2911+}
2912 #endif
2913
2914 /*
2915diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2916index ca97e0e..cd08920 100644
2917--- a/arch/mips/include/asm/thread_info.h
2918+++ b/arch/mips/include/asm/thread_info.h
2919@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2920 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2921 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2922 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2923+/* li takes a 32bit immediate */
2924+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2925 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2926
2927 #ifdef CONFIG_MIPS32_O32
2928@@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2929 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2930 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2931 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2932+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2933+
2934+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2935
2936 /* work to do in syscall_trace_leave() */
2937-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2938+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2939
2940 /* work to do on interrupt/exception return */
2941 #define _TIF_WORK_MASK (0x0000ffef & \
2942 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2943 /* work to do on any return to u-space */
2944-#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2945+#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2946
2947 #endif /* __KERNEL__ */
2948
2949diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2950index 9fdd8bc..4bd7f1a 100644
2951--- a/arch/mips/kernel/binfmt_elfn32.c
2952+++ b/arch/mips/kernel/binfmt_elfn32.c
2953@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2954 #undef ELF_ET_DYN_BASE
2955 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2956
2957+#ifdef CONFIG_PAX_ASLR
2958+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2959+
2960+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2961+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2962+#endif
2963+
2964 #include <asm/processor.h>
2965 #include <linux/module.h>
2966 #include <linux/elfcore.h>
2967diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2968index ff44823..97f8906 100644
2969--- a/arch/mips/kernel/binfmt_elfo32.c
2970+++ b/arch/mips/kernel/binfmt_elfo32.c
2971@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2972 #undef ELF_ET_DYN_BASE
2973 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2974
2975+#ifdef CONFIG_PAX_ASLR
2976+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2977+
2978+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2979+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2980+#endif
2981+
2982 #include <asm/processor.h>
2983
2984 /*
2985diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2986index e9a5fd7..378809a 100644
2987--- a/arch/mips/kernel/process.c
2988+++ b/arch/mips/kernel/process.c
2989@@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2990 out:
2991 return pc;
2992 }
2993-
2994-/*
2995- * Don't forget that the stack pointer must be aligned on a 8 bytes
2996- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2997- */
2998-unsigned long arch_align_stack(unsigned long sp)
2999-{
3000- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3001- sp -= get_random_int() & ~PAGE_MASK;
3002-
3003- return sp & ALMASK;
3004-}
3005diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3006index 4812c6d..2069554 100644
3007--- a/arch/mips/kernel/ptrace.c
3008+++ b/arch/mips/kernel/ptrace.c
3009@@ -528,6 +528,10 @@ static inline int audit_arch(void)
3010 return arch;
3011 }
3012
3013+#ifdef CONFIG_GRKERNSEC_SETXID
3014+extern void gr_delayed_cred_worker(void);
3015+#endif
3016+
3017 /*
3018 * Notification of system call entry/exit
3019 * - triggered by current->work.syscall_trace
3020@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3021 /* do the secure computing check first */
3022 secure_computing_strict(regs->regs[2]);
3023
3024+#ifdef CONFIG_GRKERNSEC_SETXID
3025+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3026+ gr_delayed_cred_worker();
3027+#endif
3028+
3029 if (!(current->ptrace & PT_PTRACED))
3030 goto out;
3031
3032diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3033index a632bc1..0b77c7c 100644
3034--- a/arch/mips/kernel/scall32-o32.S
3035+++ b/arch/mips/kernel/scall32-o32.S
3036@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3037
3038 stack_done:
3039 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3040- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3041+ li t1, _TIF_SYSCALL_WORK
3042 and t0, t1
3043 bnez t0, syscall_trace_entry # -> yes
3044
3045diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3046index 3b5a5e9..e1ee86d 100644
3047--- a/arch/mips/kernel/scall64-64.S
3048+++ b/arch/mips/kernel/scall64-64.S
3049@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3050
3051 sd a3, PT_R26(sp) # save a3 for syscall restarting
3052
3053- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3054+ li t1, _TIF_SYSCALL_WORK
3055 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3056 and t0, t1, t0
3057 bnez t0, syscall_trace_entry
3058diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3059index 6be6f70..1859577 100644
3060--- a/arch/mips/kernel/scall64-n32.S
3061+++ b/arch/mips/kernel/scall64-n32.S
3062@@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3063
3064 sd a3, PT_R26(sp) # save a3 for syscall restarting
3065
3066- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3067+ li t1, _TIF_SYSCALL_WORK
3068 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3069 and t0, t1, t0
3070 bnez t0, n32_syscall_trace_entry
3071diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3072index 5422855..74e63a3 100644
3073--- a/arch/mips/kernel/scall64-o32.S
3074+++ b/arch/mips/kernel/scall64-o32.S
3075@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3076 PTR 4b, bad_stack
3077 .previous
3078
3079- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3080+ li t1, _TIF_SYSCALL_WORK
3081 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3082 and t0, t1, t0
3083 bnez t0, trace_a_syscall
3084diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3085index c14f6df..537e729 100644
3086--- a/arch/mips/mm/fault.c
3087+++ b/arch/mips/mm/fault.c
3088@@ -27,6 +27,23 @@
3089 #include <asm/highmem.h> /* For VMALLOC_END */
3090 #include <linux/kdebug.h>
3091
3092+#ifdef CONFIG_PAX_PAGEEXEC
3093+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3094+{
3095+ unsigned long i;
3096+
3097+ printk(KERN_ERR "PAX: bytes at PC: ");
3098+ for (i = 0; i < 5; i++) {
3099+ unsigned int c;
3100+ if (get_user(c, (unsigned int *)pc+i))
3101+ printk(KERN_CONT "???????? ");
3102+ else
3103+ printk(KERN_CONT "%08x ", c);
3104+ }
3105+ printk("\n");
3106+}
3107+#endif
3108+
3109 /*
3110 * This routine handles page faults. It determines the address,
3111 * and the problem, and then passes it off to one of the appropriate
3112diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3113index 302d779..7d35bf8 100644
3114--- a/arch/mips/mm/mmap.c
3115+++ b/arch/mips/mm/mmap.c
3116@@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3117 do_color_align = 1;
3118
3119 /* requesting a specific address */
3120+
3121+#ifdef CONFIG_PAX_RANDMMAP
3122+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3123+#endif
3124+
3125 if (addr) {
3126 if (do_color_align)
3127 addr = COLOUR_ALIGN(addr, pgoff);
3128@@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3129 addr = PAGE_ALIGN(addr);
3130
3131 vma = find_vma(mm, addr);
3132- if (TASK_SIZE - len >= addr &&
3133- (!vma || addr + len <= vma->vm_start))
3134+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3135 return addr;
3136 }
3137
3138@@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3139 /* At this point: (!vma || addr < vma->vm_end). */
3140 if (TASK_SIZE - len < addr)
3141 return -ENOMEM;
3142- if (!vma || addr + len <= vma->vm_start)
3143+ if (check_heap_stack_gap(vmm, addr, len))
3144 return addr;
3145 addr = vma->vm_end;
3146 if (do_color_align)
3147@@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3148 /* make sure it can fit in the remaining address space */
3149 if (likely(addr > len)) {
3150 vma = find_vma(mm, addr - len);
3151- if (!vma || addr <= vma->vm_start) {
3152+ if (check_heap_stack_gap(vmm, addr - len, len))
3153 /* cache the address as a hint for next time */
3154 return mm->free_area_cache = addr - len;
3155 }
3156@@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3157 * return with success:
3158 */
3159 vma = find_vma(mm, addr);
3160- if (likely(!vma || addr + len <= vma->vm_start)) {
3161+ if (check_heap_stack_gap(vmm, addr, len)) {
3162 /* cache the address as a hint for next time */
3163 return mm->free_area_cache = addr;
3164 }
3165@@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3166 mm->unmap_area = arch_unmap_area_topdown;
3167 }
3168 }
3169-
3170-static inline unsigned long brk_rnd(void)
3171-{
3172- unsigned long rnd = get_random_int();
3173-
3174- rnd = rnd << PAGE_SHIFT;
3175- /* 8MB for 32bit, 256MB for 64bit */
3176- if (TASK_IS_32BIT_ADDR)
3177- rnd = rnd & 0x7ffffful;
3178- else
3179- rnd = rnd & 0xffffffful;
3180-
3181- return rnd;
3182-}
3183-
3184-unsigned long arch_randomize_brk(struct mm_struct *mm)
3185-{
3186- unsigned long base = mm->brk;
3187- unsigned long ret;
3188-
3189- ret = PAGE_ALIGN(base + brk_rnd());
3190-
3191- if (ret < mm->brk)
3192- return mm->brk;
3193-
3194- return ret;
3195-}
3196diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3197index 967d144..db12197 100644
3198--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3199+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3200@@ -11,12 +11,14 @@
3201 #ifndef _ASM_PROC_CACHE_H
3202 #define _ASM_PROC_CACHE_H
3203
3204+#include <linux/const.h>
3205+
3206 /* L1 cache */
3207
3208 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3209 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3210-#define L1_CACHE_BYTES 16 /* bytes per entry */
3211 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3212+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3213 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3214
3215 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3216diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3217index bcb5df2..84fabd2 100644
3218--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3219+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3220@@ -16,13 +16,15 @@
3221 #ifndef _ASM_PROC_CACHE_H
3222 #define _ASM_PROC_CACHE_H
3223
3224+#include <linux/const.h>
3225+
3226 /*
3227 * L1 cache
3228 */
3229 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3230 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3231-#define L1_CACHE_BYTES 32 /* bytes per entry */
3232 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3233+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3234 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3235
3236 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3237diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3238index 4ce7a01..449202a 100644
3239--- a/arch/openrisc/include/asm/cache.h
3240+++ b/arch/openrisc/include/asm/cache.h
3241@@ -19,11 +19,13 @@
3242 #ifndef __ASM_OPENRISC_CACHE_H
3243 #define __ASM_OPENRISC_CACHE_H
3244
3245+#include <linux/const.h>
3246+
3247 /* FIXME: How can we replace these with values from the CPU...
3248 * they shouldn't be hard-coded!
3249 */
3250
3251-#define L1_CACHE_BYTES 16
3252 #define L1_CACHE_SHIFT 4
3253+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3254
3255 #endif /* __ASM_OPENRISC_CACHE_H */
3256diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3257index af9cf30..2aae9b2 100644
3258--- a/arch/parisc/include/asm/atomic.h
3259+++ b/arch/parisc/include/asm/atomic.h
3260@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3261
3262 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3263
3264+#define atomic64_read_unchecked(v) atomic64_read(v)
3265+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3266+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3267+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3268+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3269+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3270+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3271+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3272+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3273+
3274 #endif /* !CONFIG_64BIT */
3275
3276
3277diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3278index 47f11c7..3420df2 100644
3279--- a/arch/parisc/include/asm/cache.h
3280+++ b/arch/parisc/include/asm/cache.h
3281@@ -5,6 +5,7 @@
3282 #ifndef __ARCH_PARISC_CACHE_H
3283 #define __ARCH_PARISC_CACHE_H
3284
3285+#include <linux/const.h>
3286
3287 /*
3288 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3289@@ -15,13 +16,13 @@
3290 * just ruin performance.
3291 */
3292 #ifdef CONFIG_PA20
3293-#define L1_CACHE_BYTES 64
3294 #define L1_CACHE_SHIFT 6
3295 #else
3296-#define L1_CACHE_BYTES 32
3297 #define L1_CACHE_SHIFT 5
3298 #endif
3299
3300+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3301+
3302 #ifndef __ASSEMBLY__
3303
3304 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3305diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3306index 19f6cb1..6c78cf2 100644
3307--- a/arch/parisc/include/asm/elf.h
3308+++ b/arch/parisc/include/asm/elf.h
3309@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3310
3311 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3312
3313+#ifdef CONFIG_PAX_ASLR
3314+#define PAX_ELF_ET_DYN_BASE 0x10000UL
3315+
3316+#define PAX_DELTA_MMAP_LEN 16
3317+#define PAX_DELTA_STACK_LEN 16
3318+#endif
3319+
3320 /* This yields a mask that user programs can use to figure out what
3321 instruction set this CPU supports. This could be done in user space,
3322 but it's not easy, and we've already done it here. */
3323diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3324index fc987a1..6e068ef 100644
3325--- a/arch/parisc/include/asm/pgalloc.h
3326+++ b/arch/parisc/include/asm/pgalloc.h
3327@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3328 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3329 }
3330
3331+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3332+{
3333+ pgd_populate(mm, pgd, pmd);
3334+}
3335+
3336 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3337 {
3338 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3339@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3340 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3341 #define pmd_free(mm, x) do { } while (0)
3342 #define pgd_populate(mm, pmd, pte) BUG()
3343+#define pgd_populate_kernel(mm, pmd, pte) BUG()
3344
3345 #endif
3346
3347diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3348index ee99f23..802b0a1 100644
3349--- a/arch/parisc/include/asm/pgtable.h
3350+++ b/arch/parisc/include/asm/pgtable.h
3351@@ -212,6 +212,17 @@ struct vm_area_struct;
3352 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3353 #define PAGE_COPY PAGE_EXECREAD
3354 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3355+
3356+#ifdef CONFIG_PAX_PAGEEXEC
3357+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3358+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3359+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3360+#else
3361+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3362+# define PAGE_COPY_NOEXEC PAGE_COPY
3363+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3364+#endif
3365+
3366 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3367 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3368 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3369diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3370index 4ba2c93..f5e3974 100644
3371--- a/arch/parisc/include/asm/uaccess.h
3372+++ b/arch/parisc/include/asm/uaccess.h
3373@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3374 const void __user *from,
3375 unsigned long n)
3376 {
3377- int sz = __compiletime_object_size(to);
3378+ size_t sz = __compiletime_object_size(to);
3379 int ret = -EFAULT;
3380
3381- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3382+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3383 ret = __copy_from_user(to, from, n);
3384 else
3385 copy_from_user_overflow();
3386diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3387index 5e34ccf..672bc9c 100644
3388--- a/arch/parisc/kernel/module.c
3389+++ b/arch/parisc/kernel/module.c
3390@@ -98,16 +98,38 @@
3391
3392 /* three functions to determine where in the module core
3393 * or init pieces the location is */
3394+static inline int in_init_rx(struct module *me, void *loc)
3395+{
3396+ return (loc >= me->module_init_rx &&
3397+ loc < (me->module_init_rx + me->init_size_rx));
3398+}
3399+
3400+static inline int in_init_rw(struct module *me, void *loc)
3401+{
3402+ return (loc >= me->module_init_rw &&
3403+ loc < (me->module_init_rw + me->init_size_rw));
3404+}
3405+
3406 static inline int in_init(struct module *me, void *loc)
3407 {
3408- return (loc >= me->module_init &&
3409- loc <= (me->module_init + me->init_size));
3410+ return in_init_rx(me, loc) || in_init_rw(me, loc);
3411+}
3412+
3413+static inline int in_core_rx(struct module *me, void *loc)
3414+{
3415+ return (loc >= me->module_core_rx &&
3416+ loc < (me->module_core_rx + me->core_size_rx));
3417+}
3418+
3419+static inline int in_core_rw(struct module *me, void *loc)
3420+{
3421+ return (loc >= me->module_core_rw &&
3422+ loc < (me->module_core_rw + me->core_size_rw));
3423 }
3424
3425 static inline int in_core(struct module *me, void *loc)
3426 {
3427- return (loc >= me->module_core &&
3428- loc <= (me->module_core + me->core_size));
3429+ return in_core_rx(me, loc) || in_core_rw(me, loc);
3430 }
3431
3432 static inline int in_local(struct module *me, void *loc)
3433@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3434 }
3435
3436 /* align things a bit */
3437- me->core_size = ALIGN(me->core_size, 16);
3438- me->arch.got_offset = me->core_size;
3439- me->core_size += gots * sizeof(struct got_entry);
3440+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3441+ me->arch.got_offset = me->core_size_rw;
3442+ me->core_size_rw += gots * sizeof(struct got_entry);
3443
3444- me->core_size = ALIGN(me->core_size, 16);
3445- me->arch.fdesc_offset = me->core_size;
3446- me->core_size += fdescs * sizeof(Elf_Fdesc);
3447+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3448+ me->arch.fdesc_offset = me->core_size_rw;
3449+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3450
3451 me->arch.got_max = gots;
3452 me->arch.fdesc_max = fdescs;
3453@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3454
3455 BUG_ON(value == 0);
3456
3457- got = me->module_core + me->arch.got_offset;
3458+ got = me->module_core_rw + me->arch.got_offset;
3459 for (i = 0; got[i].addr; i++)
3460 if (got[i].addr == value)
3461 goto out;
3462@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3463 #ifdef CONFIG_64BIT
3464 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3465 {
3466- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3467+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3468
3469 if (!value) {
3470 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3471@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3472
3473 /* Create new one */
3474 fdesc->addr = value;
3475- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3476+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3477 return (Elf_Addr)fdesc;
3478 }
3479 #endif /* CONFIG_64BIT */
3480@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3481
3482 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3483 end = table + sechdrs[me->arch.unwind_section].sh_size;
3484- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3485+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3486
3487 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3488 me->arch.unwind_section, table, end, gp);
3489diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3490index c9b9322..02d8940 100644
3491--- a/arch/parisc/kernel/sys_parisc.c
3492+++ b/arch/parisc/kernel/sys_parisc.c
3493@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3494 /* At this point: (!vma || addr < vma->vm_end). */
3495 if (TASK_SIZE - len < addr)
3496 return -ENOMEM;
3497- if (!vma || addr + len <= vma->vm_start)
3498+ if (check_heap_stack_gap(vma, addr, len))
3499 return addr;
3500 addr = vma->vm_end;
3501 }
3502@@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3503 /* At this point: (!vma || addr < vma->vm_end). */
3504 if (TASK_SIZE - len < addr)
3505 return -ENOMEM;
3506- if (!vma || addr + len <= vma->vm_start)
3507+ if (check_heap_stack_gap(vma, addr, len))
3508 return addr;
3509 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3510 if (addr < vma->vm_end) /* handle wraparound */
3511@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3512 if (flags & MAP_FIXED)
3513 return addr;
3514 if (!addr)
3515- addr = TASK_UNMAPPED_BASE;
3516+ addr = current->mm->mmap_base;
3517
3518 if (filp) {
3519 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3520diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3521index 45ba99f..8e22c33 100644
3522--- a/arch/parisc/kernel/traps.c
3523+++ b/arch/parisc/kernel/traps.c
3524@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3525
3526 down_read(&current->mm->mmap_sem);
3527 vma = find_vma(current->mm,regs->iaoq[0]);
3528- if (vma && (regs->iaoq[0] >= vma->vm_start)
3529- && (vma->vm_flags & VM_EXEC)) {
3530-
3531+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3532 fault_address = regs->iaoq[0];
3533 fault_space = regs->iasq[0];
3534
3535diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3536index 18162ce..94de376 100644
3537--- a/arch/parisc/mm/fault.c
3538+++ b/arch/parisc/mm/fault.c
3539@@ -15,6 +15,7 @@
3540 #include <linux/sched.h>
3541 #include <linux/interrupt.h>
3542 #include <linux/module.h>
3543+#include <linux/unistd.h>
3544
3545 #include <asm/uaccess.h>
3546 #include <asm/traps.h>
3547@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3548 static unsigned long
3549 parisc_acctyp(unsigned long code, unsigned int inst)
3550 {
3551- if (code == 6 || code == 16)
3552+ if (code == 6 || code == 7 || code == 16)
3553 return VM_EXEC;
3554
3555 switch (inst & 0xf0000000) {
3556@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3557 }
3558 #endif
3559
3560+#ifdef CONFIG_PAX_PAGEEXEC
3561+/*
3562+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3563+ *
3564+ * returns 1 when task should be killed
3565+ * 2 when rt_sigreturn trampoline was detected
3566+ * 3 when unpatched PLT trampoline was detected
3567+ */
3568+static int pax_handle_fetch_fault(struct pt_regs *regs)
3569+{
3570+
3571+#ifdef CONFIG_PAX_EMUPLT
3572+ int err;
3573+
3574+ do { /* PaX: unpatched PLT emulation */
3575+ unsigned int bl, depwi;
3576+
3577+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3578+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3579+
3580+ if (err)
3581+ break;
3582+
3583+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3584+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3585+
3586+ err = get_user(ldw, (unsigned int *)addr);
3587+ err |= get_user(bv, (unsigned int *)(addr+4));
3588+ err |= get_user(ldw2, (unsigned int *)(addr+8));
3589+
3590+ if (err)
3591+ break;
3592+
3593+ if (ldw == 0x0E801096U &&
3594+ bv == 0xEAC0C000U &&
3595+ ldw2 == 0x0E881095U)
3596+ {
3597+ unsigned int resolver, map;
3598+
3599+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3600+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3601+ if (err)
3602+ break;
3603+
3604+ regs->gr[20] = instruction_pointer(regs)+8;
3605+ regs->gr[21] = map;
3606+ regs->gr[22] = resolver;
3607+ regs->iaoq[0] = resolver | 3UL;
3608+ regs->iaoq[1] = regs->iaoq[0] + 4;
3609+ return 3;
3610+ }
3611+ }
3612+ } while (0);
3613+#endif
3614+
3615+#ifdef CONFIG_PAX_EMUTRAMP
3616+
3617+#ifndef CONFIG_PAX_EMUSIGRT
3618+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3619+ return 1;
3620+#endif
3621+
3622+ do { /* PaX: rt_sigreturn emulation */
3623+ unsigned int ldi1, ldi2, bel, nop;
3624+
3625+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3626+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3627+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3628+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3629+
3630+ if (err)
3631+ break;
3632+
3633+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3634+ ldi2 == 0x3414015AU &&
3635+ bel == 0xE4008200U &&
3636+ nop == 0x08000240U)
3637+ {
3638+ regs->gr[25] = (ldi1 & 2) >> 1;
3639+ regs->gr[20] = __NR_rt_sigreturn;
3640+ regs->gr[31] = regs->iaoq[1] + 16;
3641+ regs->sr[0] = regs->iasq[1];
3642+ regs->iaoq[0] = 0x100UL;
3643+ regs->iaoq[1] = regs->iaoq[0] + 4;
3644+ regs->iasq[0] = regs->sr[2];
3645+ regs->iasq[1] = regs->sr[2];
3646+ return 2;
3647+ }
3648+ } while (0);
3649+#endif
3650+
3651+ return 1;
3652+}
3653+
3654+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3655+{
3656+ unsigned long i;
3657+
3658+ printk(KERN_ERR "PAX: bytes at PC: ");
3659+ for (i = 0; i < 5; i++) {
3660+ unsigned int c;
3661+ if (get_user(c, (unsigned int *)pc+i))
3662+ printk(KERN_CONT "???????? ");
3663+ else
3664+ printk(KERN_CONT "%08x ", c);
3665+ }
3666+ printk("\n");
3667+}
3668+#endif
3669+
3670 int fixup_exception(struct pt_regs *regs)
3671 {
3672 const struct exception_table_entry *fix;
3673@@ -192,8 +303,33 @@ good_area:
3674
3675 acc_type = parisc_acctyp(code,regs->iir);
3676
3677- if ((vma->vm_flags & acc_type) != acc_type)
3678+ if ((vma->vm_flags & acc_type) != acc_type) {
3679+
3680+#ifdef CONFIG_PAX_PAGEEXEC
3681+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3682+ (address & ~3UL) == instruction_pointer(regs))
3683+ {
3684+ up_read(&mm->mmap_sem);
3685+ switch (pax_handle_fetch_fault(regs)) {
3686+
3687+#ifdef CONFIG_PAX_EMUPLT
3688+ case 3:
3689+ return;
3690+#endif
3691+
3692+#ifdef CONFIG_PAX_EMUTRAMP
3693+ case 2:
3694+ return;
3695+#endif
3696+
3697+ }
3698+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3699+ do_group_exit(SIGKILL);
3700+ }
3701+#endif
3702+
3703 goto bad_area;
3704+ }
3705
3706 /*
3707 * If for any reason at all we couldn't handle the fault, make
3708diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3709index da29032..f76c24c 100644
3710--- a/arch/powerpc/include/asm/atomic.h
3711+++ b/arch/powerpc/include/asm/atomic.h
3712@@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3713 return t1;
3714 }
3715
3716+#define atomic64_read_unchecked(v) atomic64_read(v)
3717+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3718+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3719+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3720+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3721+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3722+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3723+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3724+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3725+
3726 #endif /* __powerpc64__ */
3727
3728 #endif /* __KERNEL__ */
3729diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3730index 9e495c9..b6878e5 100644
3731--- a/arch/powerpc/include/asm/cache.h
3732+++ b/arch/powerpc/include/asm/cache.h
3733@@ -3,6 +3,7 @@
3734
3735 #ifdef __KERNEL__
3736
3737+#include <linux/const.h>
3738
3739 /* bytes per L1 cache line */
3740 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3741@@ -22,7 +23,7 @@
3742 #define L1_CACHE_SHIFT 7
3743 #endif
3744
3745-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3746+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3747
3748 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3749
3750diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3751index 3bf9cca..e7457d0 100644
3752--- a/arch/powerpc/include/asm/elf.h
3753+++ b/arch/powerpc/include/asm/elf.h
3754@@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3755 the loader. We need to make sure that it is out of the way of the program
3756 that it will "exec", and that there is sufficient room for the brk. */
3757
3758-extern unsigned long randomize_et_dyn(unsigned long base);
3759-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3760+#define ELF_ET_DYN_BASE (0x20000000)
3761+
3762+#ifdef CONFIG_PAX_ASLR
3763+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3764+
3765+#ifdef __powerpc64__
3766+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3767+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3768+#else
3769+#define PAX_DELTA_MMAP_LEN 15
3770+#define PAX_DELTA_STACK_LEN 15
3771+#endif
3772+#endif
3773
3774 /*
3775 * Our registers are always unsigned longs, whether we're a 32 bit
3776@@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3777 (0x7ff >> (PAGE_SHIFT - 12)) : \
3778 (0x3ffff >> (PAGE_SHIFT - 12)))
3779
3780-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3781-#define arch_randomize_brk arch_randomize_brk
3782-
3783 #endif /* __KERNEL__ */
3784
3785 /*
3786diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3787index 8196e9c..d83a9f3 100644
3788--- a/arch/powerpc/include/asm/exec.h
3789+++ b/arch/powerpc/include/asm/exec.h
3790@@ -4,6 +4,6 @@
3791 #ifndef _ASM_POWERPC_EXEC_H
3792 #define _ASM_POWERPC_EXEC_H
3793
3794-extern unsigned long arch_align_stack(unsigned long sp);
3795+#define arch_align_stack(x) ((x) & ~0xfUL)
3796
3797 #endif /* _ASM_POWERPC_EXEC_H */
3798diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3799index bca8fdc..61e9580 100644
3800--- a/arch/powerpc/include/asm/kmap_types.h
3801+++ b/arch/powerpc/include/asm/kmap_types.h
3802@@ -27,6 +27,7 @@ enum km_type {
3803 KM_PPC_SYNC_PAGE,
3804 KM_PPC_SYNC_ICACHE,
3805 KM_KDB,
3806+ KM_CLEARPAGE,
3807 KM_TYPE_NR
3808 };
3809
3810diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3811index d4a7f64..451de1c 100644
3812--- a/arch/powerpc/include/asm/mman.h
3813+++ b/arch/powerpc/include/asm/mman.h
3814@@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3815 }
3816 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3817
3818-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3819+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3820 {
3821 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3822 }
3823diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3824index f072e97..b436dee 100644
3825--- a/arch/powerpc/include/asm/page.h
3826+++ b/arch/powerpc/include/asm/page.h
3827@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3828 * and needs to be executable. This means the whole heap ends
3829 * up being executable.
3830 */
3831-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3832- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3833+#define VM_DATA_DEFAULT_FLAGS32 \
3834+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3835+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3836
3837 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3838 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3839@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3840 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3841 #endif
3842
3843+#define ktla_ktva(addr) (addr)
3844+#define ktva_ktla(addr) (addr)
3845+
3846 /*
3847 * Use the top bit of the higher-level page table entries to indicate whether
3848 * the entries we point to contain hugepages. This works because we know that
3849diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3850index fed85e6..da5c71b 100644
3851--- a/arch/powerpc/include/asm/page_64.h
3852+++ b/arch/powerpc/include/asm/page_64.h
3853@@ -146,15 +146,18 @@ do { \
3854 * stack by default, so in the absence of a PT_GNU_STACK program header
3855 * we turn execute permission off.
3856 */
3857-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3858- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3859+#define VM_STACK_DEFAULT_FLAGS32 \
3860+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3861+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3862
3863 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3864 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3865
3866+#ifndef CONFIG_PAX_PAGEEXEC
3867 #define VM_STACK_DEFAULT_FLAGS \
3868 (is_32bit_task() ? \
3869 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3870+#endif
3871
3872 #include <asm-generic/getorder.h>
3873
3874diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3875index 292725c..f87ae14 100644
3876--- a/arch/powerpc/include/asm/pgalloc-64.h
3877+++ b/arch/powerpc/include/asm/pgalloc-64.h
3878@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3879 #ifndef CONFIG_PPC_64K_PAGES
3880
3881 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3882+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3883
3884 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3885 {
3886@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3887 pud_set(pud, (unsigned long)pmd);
3888 }
3889
3890+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3891+{
3892+ pud_populate(mm, pud, pmd);
3893+}
3894+
3895 #define pmd_populate(mm, pmd, pte_page) \
3896 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3897 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3898@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3899 #else /* CONFIG_PPC_64K_PAGES */
3900
3901 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3902+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3903
3904 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3905 pte_t *pte)
3906diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3907index 2e0e411..7899c68 100644
3908--- a/arch/powerpc/include/asm/pgtable.h
3909+++ b/arch/powerpc/include/asm/pgtable.h
3910@@ -2,6 +2,7 @@
3911 #define _ASM_POWERPC_PGTABLE_H
3912 #ifdef __KERNEL__
3913
3914+#include <linux/const.h>
3915 #ifndef __ASSEMBLY__
3916 #include <asm/processor.h> /* For TASK_SIZE */
3917 #include <asm/mmu.h>
3918diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3919index 4aad413..85d86bf 100644
3920--- a/arch/powerpc/include/asm/pte-hash32.h
3921+++ b/arch/powerpc/include/asm/pte-hash32.h
3922@@ -21,6 +21,7 @@
3923 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3924 #define _PAGE_USER 0x004 /* usermode access allowed */
3925 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3926+#define _PAGE_EXEC _PAGE_GUARDED
3927 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3928 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3929 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3930diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3931index 360585d..c3930ef 100644
3932--- a/arch/powerpc/include/asm/reg.h
3933+++ b/arch/powerpc/include/asm/reg.h
3934@@ -212,6 +212,7 @@
3935 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3936 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3937 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3938+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3939 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3940 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3941 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3942diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3943index 68831e9..379c695 100644
3944--- a/arch/powerpc/include/asm/thread_info.h
3945+++ b/arch/powerpc/include/asm/thread_info.h
3946@@ -91,12 +91,14 @@ static inline struct thread_info *current_thread_info(void)
3947 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3948 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3949 #define TIF_SINGLESTEP 8 /* singlestepping active */
3950-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3951 #define TIF_SECCOMP 10 /* secure computing */
3952 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3953 #define TIF_NOERROR 12 /* Force successful syscall return */
3954 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3955 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3956+#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3957+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3958+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3959
3960 /* as above, but as bit values */
3961 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3962@@ -113,8 +115,10 @@ static inline struct thread_info *current_thread_info(void)
3963 #define _TIF_NOERROR (1<<TIF_NOERROR)
3964 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3965 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3966+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3967 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3968- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3969+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3970+ _TIF_GRSEC_SETXID)
3971
3972 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3973 _TIF_NOTIFY_RESUME)
3974diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3975index 17bb40c..353c98b 100644
3976--- a/arch/powerpc/include/asm/uaccess.h
3977+++ b/arch/powerpc/include/asm/uaccess.h
3978@@ -13,6 +13,8 @@
3979 #define VERIFY_READ 0
3980 #define VERIFY_WRITE 1
3981
3982+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3983+
3984 /*
3985 * The fs value determines whether argument validity checking should be
3986 * performed or not. If get_fs() == USER_DS, checking is performed, with
3987@@ -329,52 +331,6 @@ do { \
3988 extern unsigned long __copy_tofrom_user(void __user *to,
3989 const void __user *from, unsigned long size);
3990
3991-#ifndef __powerpc64__
3992-
3993-static inline unsigned long copy_from_user(void *to,
3994- const void __user *from, unsigned long n)
3995-{
3996- unsigned long over;
3997-
3998- if (access_ok(VERIFY_READ, from, n))
3999- return __copy_tofrom_user((__force void __user *)to, from, n);
4000- if ((unsigned long)from < TASK_SIZE) {
4001- over = (unsigned long)from + n - TASK_SIZE;
4002- return __copy_tofrom_user((__force void __user *)to, from,
4003- n - over) + over;
4004- }
4005- return n;
4006-}
4007-
4008-static inline unsigned long copy_to_user(void __user *to,
4009- const void *from, unsigned long n)
4010-{
4011- unsigned long over;
4012-
4013- if (access_ok(VERIFY_WRITE, to, n))
4014- return __copy_tofrom_user(to, (__force void __user *)from, n);
4015- if ((unsigned long)to < TASK_SIZE) {
4016- over = (unsigned long)to + n - TASK_SIZE;
4017- return __copy_tofrom_user(to, (__force void __user *)from,
4018- n - over) + over;
4019- }
4020- return n;
4021-}
4022-
4023-#else /* __powerpc64__ */
4024-
4025-#define __copy_in_user(to, from, size) \
4026- __copy_tofrom_user((to), (from), (size))
4027-
4028-extern unsigned long copy_from_user(void *to, const void __user *from,
4029- unsigned long n);
4030-extern unsigned long copy_to_user(void __user *to, const void *from,
4031- unsigned long n);
4032-extern unsigned long copy_in_user(void __user *to, const void __user *from,
4033- unsigned long n);
4034-
4035-#endif /* __powerpc64__ */
4036-
4037 static inline unsigned long __copy_from_user_inatomic(void *to,
4038 const void __user *from, unsigned long n)
4039 {
4040@@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4041 if (ret == 0)
4042 return 0;
4043 }
4044+
4045+ if (!__builtin_constant_p(n))
4046+ check_object_size(to, n, false);
4047+
4048 return __copy_tofrom_user((__force void __user *)to, from, n);
4049 }
4050
4051@@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4052 if (ret == 0)
4053 return 0;
4054 }
4055+
4056+ if (!__builtin_constant_p(n))
4057+ check_object_size(from, n, true);
4058+
4059 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4060 }
4061
4062@@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4063 return __copy_to_user_inatomic(to, from, size);
4064 }
4065
4066+#ifndef __powerpc64__
4067+
4068+static inline unsigned long __must_check copy_from_user(void *to,
4069+ const void __user *from, unsigned long n)
4070+{
4071+ unsigned long over;
4072+
4073+ if ((long)n < 0)
4074+ return n;
4075+
4076+ if (access_ok(VERIFY_READ, from, n)) {
4077+ if (!__builtin_constant_p(n))
4078+ check_object_size(to, n, false);
4079+ return __copy_tofrom_user((__force void __user *)to, from, n);
4080+ }
4081+ if ((unsigned long)from < TASK_SIZE) {
4082+ over = (unsigned long)from + n - TASK_SIZE;
4083+ if (!__builtin_constant_p(n - over))
4084+ check_object_size(to, n - over, false);
4085+ return __copy_tofrom_user((__force void __user *)to, from,
4086+ n - over) + over;
4087+ }
4088+ return n;
4089+}
4090+
4091+static inline unsigned long __must_check copy_to_user(void __user *to,
4092+ const void *from, unsigned long n)
4093+{
4094+ unsigned long over;
4095+
4096+ if ((long)n < 0)
4097+ return n;
4098+
4099+ if (access_ok(VERIFY_WRITE, to, n)) {
4100+ if (!__builtin_constant_p(n))
4101+ check_object_size(from, n, true);
4102+ return __copy_tofrom_user(to, (__force void __user *)from, n);
4103+ }
4104+ if ((unsigned long)to < TASK_SIZE) {
4105+ over = (unsigned long)to + n - TASK_SIZE;
4106+ if (!__builtin_constant_p(n))
4107+ check_object_size(from, n - over, true);
4108+ return __copy_tofrom_user(to, (__force void __user *)from,
4109+ n - over) + over;
4110+ }
4111+ return n;
4112+}
4113+
4114+#else /* __powerpc64__ */
4115+
4116+#define __copy_in_user(to, from, size) \
4117+ __copy_tofrom_user((to), (from), (size))
4118+
4119+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4120+{
4121+ if ((long)n < 0 || n > INT_MAX)
4122+ return n;
4123+
4124+ if (!__builtin_constant_p(n))
4125+ check_object_size(to, n, false);
4126+
4127+ if (likely(access_ok(VERIFY_READ, from, n)))
4128+ n = __copy_from_user(to, from, n);
4129+ else
4130+ memset(to, 0, n);
4131+ return n;
4132+}
4133+
4134+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4135+{
4136+ if ((long)n < 0 || n > INT_MAX)
4137+ return n;
4138+
4139+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
4140+ if (!__builtin_constant_p(n))
4141+ check_object_size(from, n, true);
4142+ n = __copy_to_user(to, from, n);
4143+ }
4144+ return n;
4145+}
4146+
4147+extern unsigned long copy_in_user(void __user *to, const void __user *from,
4148+ unsigned long n);
4149+
4150+#endif /* __powerpc64__ */
4151+
4152 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4153
4154 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4155diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4156index 7215cc2..a9730c1 100644
4157--- a/arch/powerpc/kernel/exceptions-64e.S
4158+++ b/arch/powerpc/kernel/exceptions-64e.S
4159@@ -661,6 +661,7 @@ storage_fault_common:
4160 std r14,_DAR(r1)
4161 std r15,_DSISR(r1)
4162 addi r3,r1,STACK_FRAME_OVERHEAD
4163+ bl .save_nvgprs
4164 mr r4,r14
4165 mr r5,r15
4166 ld r14,PACA_EXGEN+EX_R14(r13)
4167@@ -669,8 +670,7 @@ storage_fault_common:
4168 cmpdi r3,0
4169 bne- 1f
4170 b .ret_from_except_lite
4171-1: bl .save_nvgprs
4172- mr r5,r3
4173+1: mr r5,r3
4174 addi r3,r1,STACK_FRAME_OVERHEAD
4175 ld r4,_DAR(r1)
4176 bl .bad_page_fault
4177diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4178index 1c06d29..c2a339b 100644
4179--- a/arch/powerpc/kernel/exceptions-64s.S
4180+++ b/arch/powerpc/kernel/exceptions-64s.S
4181@@ -888,10 +888,10 @@ handle_page_fault:
4182 11: ld r4,_DAR(r1)
4183 ld r5,_DSISR(r1)
4184 addi r3,r1,STACK_FRAME_OVERHEAD
4185+ bl .save_nvgprs
4186 bl .do_page_fault
4187 cmpdi r3,0
4188 beq+ 12f
4189- bl .save_nvgprs
4190 mr r5,r3
4191 addi r3,r1,STACK_FRAME_OVERHEAD
4192 lwz r4,_DAR(r1)
4193diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4194index 2e3200c..72095ce 100644
4195--- a/arch/powerpc/kernel/module_32.c
4196+++ b/arch/powerpc/kernel/module_32.c
4197@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4198 me->arch.core_plt_section = i;
4199 }
4200 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4201- printk("Module doesn't contain .plt or .init.plt sections.\n");
4202+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4203 return -ENOEXEC;
4204 }
4205
4206@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4207
4208 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4209 /* Init, or core PLT? */
4210- if (location >= mod->module_core
4211- && location < mod->module_core + mod->core_size)
4212+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4213+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4214 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4215- else
4216+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4217+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4218 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4219+ else {
4220+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4221+ return ~0UL;
4222+ }
4223
4224 /* Find this entry, or if that fails, the next avail. entry */
4225 while (entry->jump[0]) {
4226diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4227index 1a1f2dd..f4d1bb4 100644
4228--- a/arch/powerpc/kernel/process.c
4229+++ b/arch/powerpc/kernel/process.c
4230@@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4231 * Lookup NIP late so we have the best change of getting the
4232 * above info out without failing
4233 */
4234- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4235- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4236+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4237+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4238 #endif
4239 show_stack(current, (unsigned long *) regs->gpr[1]);
4240 if (!user_mode(regs))
4241@@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4242 newsp = stack[0];
4243 ip = stack[STACK_FRAME_LR_SAVE];
4244 if (!firstframe || ip != lr) {
4245- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4246+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4247 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4248 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4249- printk(" (%pS)",
4250+ printk(" (%pA)",
4251 (void *)current->ret_stack[curr_frame].ret);
4252 curr_frame--;
4253 }
4254@@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4255 struct pt_regs *regs = (struct pt_regs *)
4256 (sp + STACK_FRAME_OVERHEAD);
4257 lr = regs->link;
4258- printk("--- Exception: %lx at %pS\n LR = %pS\n",
4259+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
4260 regs->trap, (void *)regs->nip, (void *)lr);
4261 firstframe = 1;
4262 }
4263@@ -1246,58 +1246,3 @@ void __ppc64_runlatch_off(void)
4264 mtspr(SPRN_CTRLT, ctrl);
4265 }
4266 #endif /* CONFIG_PPC64 */
4267-
4268-unsigned long arch_align_stack(unsigned long sp)
4269-{
4270- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4271- sp -= get_random_int() & ~PAGE_MASK;
4272- return sp & ~0xf;
4273-}
4274-
4275-static inline unsigned long brk_rnd(void)
4276-{
4277- unsigned long rnd = 0;
4278-
4279- /* 8MB for 32bit, 1GB for 64bit */
4280- if (is_32bit_task())
4281- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4282- else
4283- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4284-
4285- return rnd << PAGE_SHIFT;
4286-}
4287-
4288-unsigned long arch_randomize_brk(struct mm_struct *mm)
4289-{
4290- unsigned long base = mm->brk;
4291- unsigned long ret;
4292-
4293-#ifdef CONFIG_PPC_STD_MMU_64
4294- /*
4295- * If we are using 1TB segments and we are allowed to randomise
4296- * the heap, we can put it above 1TB so it is backed by a 1TB
4297- * segment. Otherwise the heap will be in the bottom 1TB
4298- * which always uses 256MB segments and this may result in a
4299- * performance penalty.
4300- */
4301- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4302- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4303-#endif
4304-
4305- ret = PAGE_ALIGN(base + brk_rnd());
4306-
4307- if (ret < mm->brk)
4308- return mm->brk;
4309-
4310- return ret;
4311-}
4312-
4313-unsigned long randomize_et_dyn(unsigned long base)
4314-{
4315- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4316-
4317- if (ret < base)
4318- return base;
4319-
4320- return ret;
4321-}
4322diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4323index c10fc28..c4ef063 100644
4324--- a/arch/powerpc/kernel/ptrace.c
4325+++ b/arch/powerpc/kernel/ptrace.c
4326@@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4327 return ret;
4328 }
4329
4330+#ifdef CONFIG_GRKERNSEC_SETXID
4331+extern void gr_delayed_cred_worker(void);
4332+#endif
4333+
4334 /*
4335 * We must return the syscall number to actually look up in the table.
4336 * This can be -1L to skip running any syscall at all.
4337@@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4338
4339 secure_computing_strict(regs->gpr[0]);
4340
4341+#ifdef CONFIG_GRKERNSEC_SETXID
4342+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4343+ gr_delayed_cred_worker();
4344+#endif
4345+
4346 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4347 tracehook_report_syscall_entry(regs))
4348 /*
4349@@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4350 {
4351 int step;
4352
4353+#ifdef CONFIG_GRKERNSEC_SETXID
4354+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4355+ gr_delayed_cred_worker();
4356+#endif
4357+
4358 audit_syscall_exit(regs);
4359
4360 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4361diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4362index 8b4c049..dcd6ef3 100644
4363--- a/arch/powerpc/kernel/signal_32.c
4364+++ b/arch/powerpc/kernel/signal_32.c
4365@@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4366 /* Save user registers on the stack */
4367 frame = &rt_sf->uc.uc_mcontext;
4368 addr = frame;
4369- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4370+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4371 if (save_user_regs(regs, frame, 0, 1))
4372 goto badframe;
4373 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4374diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4375index d183f87..1867f1a 100644
4376--- a/arch/powerpc/kernel/signal_64.c
4377+++ b/arch/powerpc/kernel/signal_64.c
4378@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4379 current->thread.fpscr.val = 0;
4380
4381 /* Set up to return from userspace. */
4382- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4383+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4384 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4385 } else {
4386 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4387diff --git a/arch/powerpc/kernel/syscalls.c b/arch/powerpc/kernel/syscalls.c
4388index f2496f2..4e3cc47 100644
4389--- a/arch/powerpc/kernel/syscalls.c
4390+++ b/arch/powerpc/kernel/syscalls.c
4391@@ -107,11 +107,11 @@ long ppc64_personality(unsigned long personality)
4392 long ret;
4393
4394 if (personality(current->personality) == PER_LINUX32
4395- && personality == PER_LINUX)
4396- personality = PER_LINUX32;
4397+ && personality(personality) == PER_LINUX)
4398+ personality = (personality & ~PER_MASK) | PER_LINUX32;
4399 ret = sys_personality(personality);
4400- if (ret == PER_LINUX32)
4401- ret = PER_LINUX;
4402+ if (personality(ret) == PER_LINUX32)
4403+ ret = (ret & ~PER_MASK) | PER_LINUX;
4404 return ret;
4405 }
4406 #endif
4407diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4408index ae0843f..f16372c 100644
4409--- a/arch/powerpc/kernel/traps.c
4410+++ b/arch/powerpc/kernel/traps.c
4411@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4412 return flags;
4413 }
4414
4415+extern void gr_handle_kernel_exploit(void);
4416+
4417 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4418 int signr)
4419 {
4420@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4421 panic("Fatal exception in interrupt");
4422 if (panic_on_oops)
4423 panic("Fatal exception");
4424+
4425+ gr_handle_kernel_exploit();
4426+
4427 do_exit(signr);
4428 }
4429
4430diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4431index 9eb5b9b..e45498a 100644
4432--- a/arch/powerpc/kernel/vdso.c
4433+++ b/arch/powerpc/kernel/vdso.c
4434@@ -34,6 +34,7 @@
4435 #include <asm/firmware.h>
4436 #include <asm/vdso.h>
4437 #include <asm/vdso_datapage.h>
4438+#include <asm/mman.h>
4439
4440 #include "setup.h"
4441
4442@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4443 vdso_base = VDSO32_MBASE;
4444 #endif
4445
4446- current->mm->context.vdso_base = 0;
4447+ current->mm->context.vdso_base = ~0UL;
4448
4449 /* vDSO has a problem and was disabled, just don't "enable" it for the
4450 * process
4451@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4452 vdso_base = get_unmapped_area(NULL, vdso_base,
4453 (vdso_pages << PAGE_SHIFT) +
4454 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4455- 0, 0);
4456+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
4457 if (IS_ERR_VALUE(vdso_base)) {
4458 rc = vdso_base;
4459 goto fail_mmapsem;
4460diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4461index 5eea6f3..5d10396 100644
4462--- a/arch/powerpc/lib/usercopy_64.c
4463+++ b/arch/powerpc/lib/usercopy_64.c
4464@@ -9,22 +9,6 @@
4465 #include <linux/module.h>
4466 #include <asm/uaccess.h>
4467
4468-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4469-{
4470- if (likely(access_ok(VERIFY_READ, from, n)))
4471- n = __copy_from_user(to, from, n);
4472- else
4473- memset(to, 0, n);
4474- return n;
4475-}
4476-
4477-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4478-{
4479- if (likely(access_ok(VERIFY_WRITE, to, n)))
4480- n = __copy_to_user(to, from, n);
4481- return n;
4482-}
4483-
4484 unsigned long copy_in_user(void __user *to, const void __user *from,
4485 unsigned long n)
4486 {
4487@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4488 return n;
4489 }
4490
4491-EXPORT_SYMBOL(copy_from_user);
4492-EXPORT_SYMBOL(copy_to_user);
4493 EXPORT_SYMBOL(copy_in_user);
4494
4495diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4496index 08ffcf5..a0ab912 100644
4497--- a/arch/powerpc/mm/fault.c
4498+++ b/arch/powerpc/mm/fault.c
4499@@ -32,6 +32,10 @@
4500 #include <linux/perf_event.h>
4501 #include <linux/magic.h>
4502 #include <linux/ratelimit.h>
4503+#include <linux/slab.h>
4504+#include <linux/pagemap.h>
4505+#include <linux/compiler.h>
4506+#include <linux/unistd.h>
4507
4508 #include <asm/firmware.h>
4509 #include <asm/page.h>
4510@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4511 }
4512 #endif
4513
4514+#ifdef CONFIG_PAX_PAGEEXEC
4515+/*
4516+ * PaX: decide what to do with offenders (regs->nip = fault address)
4517+ *
4518+ * returns 1 when task should be killed
4519+ */
4520+static int pax_handle_fetch_fault(struct pt_regs *regs)
4521+{
4522+ return 1;
4523+}
4524+
4525+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4526+{
4527+ unsigned long i;
4528+
4529+ printk(KERN_ERR "PAX: bytes at PC: ");
4530+ for (i = 0; i < 5; i++) {
4531+ unsigned int c;
4532+ if (get_user(c, (unsigned int __user *)pc+i))
4533+ printk(KERN_CONT "???????? ");
4534+ else
4535+ printk(KERN_CONT "%08x ", c);
4536+ }
4537+ printk("\n");
4538+}
4539+#endif
4540+
4541 /*
4542 * Check whether the instruction at regs->nip is a store using
4543 * an update addressing form which will update r1.
4544@@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4545 * indicate errors in DSISR but can validly be set in SRR1.
4546 */
4547 if (trap == 0x400)
4548- error_code &= 0x48200000;
4549+ error_code &= 0x58200000;
4550 else
4551 is_write = error_code & DSISR_ISSTORE;
4552 #else
4553@@ -366,7 +397,7 @@ good_area:
4554 * "undefined". Of those that can be set, this is the only
4555 * one which seems bad.
4556 */
4557- if (error_code & 0x10000000)
4558+ if (error_code & DSISR_GUARDED)
4559 /* Guarded storage error. */
4560 goto bad_area;
4561 #endif /* CONFIG_8xx */
4562@@ -381,7 +412,7 @@ good_area:
4563 * processors use the same I/D cache coherency mechanism
4564 * as embedded.
4565 */
4566- if (error_code & DSISR_PROTFAULT)
4567+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4568 goto bad_area;
4569 #endif /* CONFIG_PPC_STD_MMU */
4570
4571@@ -463,6 +494,23 @@ bad_area:
4572 bad_area_nosemaphore:
4573 /* User mode accesses cause a SIGSEGV */
4574 if (user_mode(regs)) {
4575+
4576+#ifdef CONFIG_PAX_PAGEEXEC
4577+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4578+#ifdef CONFIG_PPC_STD_MMU
4579+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4580+#else
4581+ if (is_exec && regs->nip == address) {
4582+#endif
4583+ switch (pax_handle_fetch_fault(regs)) {
4584+ }
4585+
4586+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4587+ do_group_exit(SIGKILL);
4588+ }
4589+ }
4590+#endif
4591+
4592 _exception(SIGSEGV, regs, code, address);
4593 return 0;
4594 }
4595diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4596index 67a42ed..1c7210c 100644
4597--- a/arch/powerpc/mm/mmap_64.c
4598+++ b/arch/powerpc/mm/mmap_64.c
4599@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4600 */
4601 if (mmap_is_legacy()) {
4602 mm->mmap_base = TASK_UNMAPPED_BASE;
4603+
4604+#ifdef CONFIG_PAX_RANDMMAP
4605+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4606+ mm->mmap_base += mm->delta_mmap;
4607+#endif
4608+
4609 mm->get_unmapped_area = arch_get_unmapped_area;
4610 mm->unmap_area = arch_unmap_area;
4611 } else {
4612 mm->mmap_base = mmap_base();
4613+
4614+#ifdef CONFIG_PAX_RANDMMAP
4615+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4616+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4617+#endif
4618+
4619 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4620 mm->unmap_area = arch_unmap_area_topdown;
4621 }
4622diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4623index 73709f7..6b90313 100644
4624--- a/arch/powerpc/mm/slice.c
4625+++ b/arch/powerpc/mm/slice.c
4626@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4627 if ((mm->task_size - len) < addr)
4628 return 0;
4629 vma = find_vma(mm, addr);
4630- return (!vma || (addr + len) <= vma->vm_start);
4631+ return check_heap_stack_gap(vma, addr, len);
4632 }
4633
4634 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4635@@ -256,7 +256,7 @@ full_search:
4636 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4637 continue;
4638 }
4639- if (!vma || addr + len <= vma->vm_start) {
4640+ if (check_heap_stack_gap(vma, addr, len)) {
4641 /*
4642 * Remember the place where we stopped the search:
4643 */
4644@@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4645 }
4646 }
4647
4648- addr = mm->mmap_base;
4649- while (addr > len) {
4650+ if (mm->mmap_base < len)
4651+ addr = -ENOMEM;
4652+ else
4653+ addr = mm->mmap_base - len;
4654+
4655+ while (!IS_ERR_VALUE(addr)) {
4656 /* Go down by chunk size */
4657- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4658+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
4659
4660 /* Check for hit with different page size */
4661 mask = slice_range_to_mask(addr, len);
4662@@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4663 * return with success:
4664 */
4665 vma = find_vma(mm, addr);
4666- if (!vma || (addr + len) <= vma->vm_start) {
4667+ if (check_heap_stack_gap(vma, addr, len)) {
4668 /* remember the address as a hint for next time */
4669 if (use_cache)
4670 mm->free_area_cache = addr;
4671@@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4672 mm->cached_hole_size = vma->vm_start - addr;
4673
4674 /* try just below the current vma->vm_start */
4675- addr = vma->vm_start;
4676+ addr = skip_heap_stack_gap(vma, len);
4677 }
4678
4679 /*
4680@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4681 if (fixed && addr > (mm->task_size - len))
4682 return -EINVAL;
4683
4684+#ifdef CONFIG_PAX_RANDMMAP
4685+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4686+ addr = 0;
4687+#endif
4688+
4689 /* If hint, make sure it matches our alignment restrictions */
4690 if (!fixed && addr) {
4691 addr = _ALIGN_UP(addr, 1ul << pshift);
4692diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4693index 748347b..81bc6c7 100644
4694--- a/arch/s390/include/asm/atomic.h
4695+++ b/arch/s390/include/asm/atomic.h
4696@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4697 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4698 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4699
4700+#define atomic64_read_unchecked(v) atomic64_read(v)
4701+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4702+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4703+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4704+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4705+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4706+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4707+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4708+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4709+
4710 #define smp_mb__before_atomic_dec() smp_mb()
4711 #define smp_mb__after_atomic_dec() smp_mb()
4712 #define smp_mb__before_atomic_inc() smp_mb()
4713diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4714index 2a30d5a..5e5586f 100644
4715--- a/arch/s390/include/asm/cache.h
4716+++ b/arch/s390/include/asm/cache.h
4717@@ -11,8 +11,10 @@
4718 #ifndef __ARCH_S390_CACHE_H
4719 #define __ARCH_S390_CACHE_H
4720
4721-#define L1_CACHE_BYTES 256
4722+#include <linux/const.h>
4723+
4724 #define L1_CACHE_SHIFT 8
4725+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4726 #define NET_SKB_PAD 32
4727
4728 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4729diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4730index 06151e6..598f9a5 100644
4731--- a/arch/s390/include/asm/elf.h
4732+++ b/arch/s390/include/asm/elf.h
4733@@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4734 the loader. We need to make sure that it is out of the way of the program
4735 that it will "exec", and that there is sufficient room for the brk. */
4736
4737-extern unsigned long randomize_et_dyn(unsigned long base);
4738-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4739+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4740+
4741+#ifdef CONFIG_PAX_ASLR
4742+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4743+
4744+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4745+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4746+#endif
4747
4748 /* This yields a mask that user programs can use to figure out what
4749 instruction set this CPU supports. */
4750@@ -182,7 +188,8 @@ extern char elf_platform[];
4751 #define ELF_PLATFORM (elf_platform)
4752
4753 #ifndef CONFIG_64BIT
4754-#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
4755+#define SET_PERSONALITY(ex) \
4756+ set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
4757 #else /* CONFIG_64BIT */
4758 #define SET_PERSONALITY(ex) \
4759 do { \
4760@@ -210,7 +217,4 @@ struct linux_binprm;
4761 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4762 int arch_setup_additional_pages(struct linux_binprm *, int);
4763
4764-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4765-#define arch_randomize_brk arch_randomize_brk
4766-
4767 #endif
4768diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4769index c4a93d6..4d2a9b4 100644
4770--- a/arch/s390/include/asm/exec.h
4771+++ b/arch/s390/include/asm/exec.h
4772@@ -7,6 +7,6 @@
4773 #ifndef __ASM_EXEC_H
4774 #define __ASM_EXEC_H
4775
4776-extern unsigned long arch_align_stack(unsigned long sp);
4777+#define arch_align_stack(x) ((x) & ~0xfUL)
4778
4779 #endif /* __ASM_EXEC_H */
4780diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4781index 1f3a79b..44d7f9c 100644
4782--- a/arch/s390/include/asm/uaccess.h
4783+++ b/arch/s390/include/asm/uaccess.h
4784@@ -241,6 +241,10 @@ static inline unsigned long __must_check
4785 copy_to_user(void __user *to, const void *from, unsigned long n)
4786 {
4787 might_fault();
4788+
4789+ if ((long)n < 0)
4790+ return n;
4791+
4792 if (access_ok(VERIFY_WRITE, to, n))
4793 n = __copy_to_user(to, from, n);
4794 return n;
4795@@ -266,6 +270,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4796 static inline unsigned long __must_check
4797 __copy_from_user(void *to, const void __user *from, unsigned long n)
4798 {
4799+ if ((long)n < 0)
4800+ return n;
4801+
4802 if (__builtin_constant_p(n) && (n <= 256))
4803 return uaccess.copy_from_user_small(n, from, to);
4804 else
4805@@ -297,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4806 static inline unsigned long __must_check
4807 copy_from_user(void *to, const void __user *from, unsigned long n)
4808 {
4809- unsigned int sz = __compiletime_object_size(to);
4810+ size_t sz = __compiletime_object_size(to);
4811
4812 might_fault();
4813- if (unlikely(sz != -1 && sz < n)) {
4814+
4815+ if ((long)n < 0)
4816+ return n;
4817+
4818+ if (unlikely(sz != (size_t)-1 && sz < n)) {
4819 copy_from_user_overflow();
4820 return n;
4821 }
4822diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4823index dfcb343..eda788a 100644
4824--- a/arch/s390/kernel/module.c
4825+++ b/arch/s390/kernel/module.c
4826@@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4827
4828 /* Increase core size by size of got & plt and set start
4829 offsets for got and plt. */
4830- me->core_size = ALIGN(me->core_size, 4);
4831- me->arch.got_offset = me->core_size;
4832- me->core_size += me->arch.got_size;
4833- me->arch.plt_offset = me->core_size;
4834- me->core_size += me->arch.plt_size;
4835+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
4836+ me->arch.got_offset = me->core_size_rw;
4837+ me->core_size_rw += me->arch.got_size;
4838+ me->arch.plt_offset = me->core_size_rx;
4839+ me->core_size_rx += me->arch.plt_size;
4840 return 0;
4841 }
4842
4843@@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4844 if (info->got_initialized == 0) {
4845 Elf_Addr *gotent;
4846
4847- gotent = me->module_core + me->arch.got_offset +
4848+ gotent = me->module_core_rw + me->arch.got_offset +
4849 info->got_offset;
4850 *gotent = val;
4851 info->got_initialized = 1;
4852@@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4853 else if (r_type == R_390_GOTENT ||
4854 r_type == R_390_GOTPLTENT)
4855 *(unsigned int *) loc =
4856- (val + (Elf_Addr) me->module_core - loc) >> 1;
4857+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4858 else if (r_type == R_390_GOT64 ||
4859 r_type == R_390_GOTPLT64)
4860 *(unsigned long *) loc = val;
4861@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4862 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4863 if (info->plt_initialized == 0) {
4864 unsigned int *ip;
4865- ip = me->module_core + me->arch.plt_offset +
4866+ ip = me->module_core_rx + me->arch.plt_offset +
4867 info->plt_offset;
4868 #ifndef CONFIG_64BIT
4869 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4870@@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4871 val - loc + 0xffffUL < 0x1ffffeUL) ||
4872 (r_type == R_390_PLT32DBL &&
4873 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4874- val = (Elf_Addr) me->module_core +
4875+ val = (Elf_Addr) me->module_core_rx +
4876 me->arch.plt_offset +
4877 info->plt_offset;
4878 val += rela->r_addend - loc;
4879@@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4880 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4881 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4882 val = val + rela->r_addend -
4883- ((Elf_Addr) me->module_core + me->arch.got_offset);
4884+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4885 if (r_type == R_390_GOTOFF16)
4886 *(unsigned short *) loc = val;
4887 else if (r_type == R_390_GOTOFF32)
4888@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4889 break;
4890 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4891 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4892- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4893+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4894 rela->r_addend - loc;
4895 if (r_type == R_390_GOTPC)
4896 *(unsigned int *) loc = val;
4897diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4898index 60055ce..ee4b252 100644
4899--- a/arch/s390/kernel/process.c
4900+++ b/arch/s390/kernel/process.c
4901@@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4902 }
4903 return 0;
4904 }
4905-
4906-unsigned long arch_align_stack(unsigned long sp)
4907-{
4908- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4909- sp -= get_random_int() & ~PAGE_MASK;
4910- return sp & ~0xf;
4911-}
4912-
4913-static inline unsigned long brk_rnd(void)
4914-{
4915- /* 8MB for 32bit, 1GB for 64bit */
4916- if (is_32bit_task())
4917- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4918- else
4919- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4920-}
4921-
4922-unsigned long arch_randomize_brk(struct mm_struct *mm)
4923-{
4924- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4925-
4926- if (ret < mm->brk)
4927- return mm->brk;
4928- return ret;
4929-}
4930-
4931-unsigned long randomize_et_dyn(unsigned long base)
4932-{
4933- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4934-
4935- if (!(current->flags & PF_RANDOMIZE))
4936- return base;
4937- if (ret < base)
4938- return base;
4939- return ret;
4940-}
4941diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4942index a64fe53..5c66963 100644
4943--- a/arch/s390/mm/mmap.c
4944+++ b/arch/s390/mm/mmap.c
4945@@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4946 */
4947 if (mmap_is_legacy()) {
4948 mm->mmap_base = TASK_UNMAPPED_BASE;
4949+
4950+#ifdef CONFIG_PAX_RANDMMAP
4951+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4952+ mm->mmap_base += mm->delta_mmap;
4953+#endif
4954+
4955 mm->get_unmapped_area = arch_get_unmapped_area;
4956 mm->unmap_area = arch_unmap_area;
4957 } else {
4958 mm->mmap_base = mmap_base();
4959+
4960+#ifdef CONFIG_PAX_RANDMMAP
4961+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4962+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4963+#endif
4964+
4965 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4966 mm->unmap_area = arch_unmap_area_topdown;
4967 }
4968@@ -174,10 +186,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4969 */
4970 if (mmap_is_legacy()) {
4971 mm->mmap_base = TASK_UNMAPPED_BASE;
4972+
4973+#ifdef CONFIG_PAX_RANDMMAP
4974+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4975+ mm->mmap_base += mm->delta_mmap;
4976+#endif
4977+
4978 mm->get_unmapped_area = s390_get_unmapped_area;
4979 mm->unmap_area = arch_unmap_area;
4980 } else {
4981 mm->mmap_base = mmap_base();
4982+
4983+#ifdef CONFIG_PAX_RANDMMAP
4984+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4985+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4986+#endif
4987+
4988 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4989 mm->unmap_area = arch_unmap_area_topdown;
4990 }
4991diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4992index ae3d59f..f65f075 100644
4993--- a/arch/score/include/asm/cache.h
4994+++ b/arch/score/include/asm/cache.h
4995@@ -1,7 +1,9 @@
4996 #ifndef _ASM_SCORE_CACHE_H
4997 #define _ASM_SCORE_CACHE_H
4998
4999+#include <linux/const.h>
5000+
5001 #define L1_CACHE_SHIFT 4
5002-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5003+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5004
5005 #endif /* _ASM_SCORE_CACHE_H */
5006diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
5007index f9f3cd5..58ff438 100644
5008--- a/arch/score/include/asm/exec.h
5009+++ b/arch/score/include/asm/exec.h
5010@@ -1,6 +1,6 @@
5011 #ifndef _ASM_SCORE_EXEC_H
5012 #define _ASM_SCORE_EXEC_H
5013
5014-extern unsigned long arch_align_stack(unsigned long sp);
5015+#define arch_align_stack(x) (x)
5016
5017 #endif /* _ASM_SCORE_EXEC_H */
5018diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
5019index 2707023..1c2a3b7 100644
5020--- a/arch/score/kernel/process.c
5021+++ b/arch/score/kernel/process.c
5022@@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
5023
5024 return task_pt_regs(task)->cp0_epc;
5025 }
5026-
5027-unsigned long arch_align_stack(unsigned long sp)
5028-{
5029- return sp;
5030-}
5031diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
5032index ef9e555..331bd29 100644
5033--- a/arch/sh/include/asm/cache.h
5034+++ b/arch/sh/include/asm/cache.h
5035@@ -9,10 +9,11 @@
5036 #define __ASM_SH_CACHE_H
5037 #ifdef __KERNEL__
5038
5039+#include <linux/const.h>
5040 #include <linux/init.h>
5041 #include <cpu/cache.h>
5042
5043-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5044+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5045
5046 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5047
5048diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5049index afeb710..d1d1289 100644
5050--- a/arch/sh/mm/mmap.c
5051+++ b/arch/sh/mm/mmap.c
5052@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5053 addr = PAGE_ALIGN(addr);
5054
5055 vma = find_vma(mm, addr);
5056- if (TASK_SIZE - len >= addr &&
5057- (!vma || addr + len <= vma->vm_start))
5058+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5059 return addr;
5060 }
5061
5062@@ -106,7 +105,7 @@ full_search:
5063 }
5064 return -ENOMEM;
5065 }
5066- if (likely(!vma || addr + len <= vma->vm_start)) {
5067+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5068 /*
5069 * Remember the place where we stopped the search:
5070 */
5071@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5072 addr = PAGE_ALIGN(addr);
5073
5074 vma = find_vma(mm, addr);
5075- if (TASK_SIZE - len >= addr &&
5076- (!vma || addr + len <= vma->vm_start))
5077+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5078 return addr;
5079 }
5080
5081@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5082 /* make sure it can fit in the remaining address space */
5083 if (likely(addr > len)) {
5084 vma = find_vma(mm, addr-len);
5085- if (!vma || addr <= vma->vm_start) {
5086+ if (check_heap_stack_gap(vma, addr - len, len)) {
5087 /* remember the address as a hint for next time */
5088 return (mm->free_area_cache = addr-len);
5089 }
5090@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5091 if (unlikely(mm->mmap_base < len))
5092 goto bottomup;
5093
5094- addr = mm->mmap_base-len;
5095- if (do_colour_align)
5096- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5097+ addr = mm->mmap_base - len;
5098
5099 do {
5100+ if (do_colour_align)
5101+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5102 /*
5103 * Lookup failure means no vma is above this address,
5104 * else if new region fits below vma->vm_start,
5105 * return with success:
5106 */
5107 vma = find_vma(mm, addr);
5108- if (likely(!vma || addr+len <= vma->vm_start)) {
5109+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5110 /* remember the address as a hint for next time */
5111 return (mm->free_area_cache = addr);
5112 }
5113@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5114 mm->cached_hole_size = vma->vm_start - addr;
5115
5116 /* try just below the current vma->vm_start */
5117- addr = vma->vm_start-len;
5118- if (do_colour_align)
5119- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5120- } while (likely(len < vma->vm_start));
5121+ addr = skip_heap_stack_gap(vma, len);
5122+ } while (!IS_ERR_VALUE(addr));
5123
5124 bottomup:
5125 /*
5126diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5127index ce35a1c..2e7b8f9 100644
5128--- a/arch/sparc/include/asm/atomic_64.h
5129+++ b/arch/sparc/include/asm/atomic_64.h
5130@@ -14,18 +14,40 @@
5131 #define ATOMIC64_INIT(i) { (i) }
5132
5133 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5134+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5135+{
5136+ return v->counter;
5137+}
5138 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5139+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5140+{
5141+ return v->counter;
5142+}
5143
5144 #define atomic_set(v, i) (((v)->counter) = i)
5145+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5146+{
5147+ v->counter = i;
5148+}
5149 #define atomic64_set(v, i) (((v)->counter) = i)
5150+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5151+{
5152+ v->counter = i;
5153+}
5154
5155 extern void atomic_add(int, atomic_t *);
5156+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5157 extern void atomic64_add(long, atomic64_t *);
5158+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5159 extern void atomic_sub(int, atomic_t *);
5160+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5161 extern void atomic64_sub(long, atomic64_t *);
5162+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5163
5164 extern int atomic_add_ret(int, atomic_t *);
5165+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5166 extern long atomic64_add_ret(long, atomic64_t *);
5167+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5168 extern int atomic_sub_ret(int, atomic_t *);
5169 extern long atomic64_sub_ret(long, atomic64_t *);
5170
5171@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5172 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5173
5174 #define atomic_inc_return(v) atomic_add_ret(1, v)
5175+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5176+{
5177+ return atomic_add_ret_unchecked(1, v);
5178+}
5179 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5180+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5181+{
5182+ return atomic64_add_ret_unchecked(1, v);
5183+}
5184
5185 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5186 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5187
5188 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5189+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5190+{
5191+ return atomic_add_ret_unchecked(i, v);
5192+}
5193 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5194+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5195+{
5196+ return atomic64_add_ret_unchecked(i, v);
5197+}
5198
5199 /*
5200 * atomic_inc_and_test - increment and test
5201@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5202 * other cases.
5203 */
5204 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5205+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5206+{
5207+ return atomic_inc_return_unchecked(v) == 0;
5208+}
5209 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5210
5211 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5212@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5213 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5214
5215 #define atomic_inc(v) atomic_add(1, v)
5216+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5217+{
5218+ atomic_add_unchecked(1, v);
5219+}
5220 #define atomic64_inc(v) atomic64_add(1, v)
5221+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5222+{
5223+ atomic64_add_unchecked(1, v);
5224+}
5225
5226 #define atomic_dec(v) atomic_sub(1, v)
5227+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5228+{
5229+ atomic_sub_unchecked(1, v);
5230+}
5231 #define atomic64_dec(v) atomic64_sub(1, v)
5232+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5233+{
5234+ atomic64_sub_unchecked(1, v);
5235+}
5236
5237 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5238 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5239
5240 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5241+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5242+{
5243+ return cmpxchg(&v->counter, old, new);
5244+}
5245 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5246+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5247+{
5248+ return xchg(&v->counter, new);
5249+}
5250
5251 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5252 {
5253- int c, old;
5254+ int c, old, new;
5255 c = atomic_read(v);
5256 for (;;) {
5257- if (unlikely(c == (u)))
5258+ if (unlikely(c == u))
5259 break;
5260- old = atomic_cmpxchg((v), c, c + (a));
5261+
5262+ asm volatile("addcc %2, %0, %0\n"
5263+
5264+#ifdef CONFIG_PAX_REFCOUNT
5265+ "tvs %%icc, 6\n"
5266+#endif
5267+
5268+ : "=r" (new)
5269+ : "0" (c), "ir" (a)
5270+ : "cc");
5271+
5272+ old = atomic_cmpxchg(v, c, new);
5273 if (likely(old == c))
5274 break;
5275 c = old;
5276@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5277 #define atomic64_cmpxchg(v, o, n) \
5278 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5279 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5280+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5281+{
5282+ return xchg(&v->counter, new);
5283+}
5284
5285 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5286 {
5287- long c, old;
5288+ long c, old, new;
5289 c = atomic64_read(v);
5290 for (;;) {
5291- if (unlikely(c == (u)))
5292+ if (unlikely(c == u))
5293 break;
5294- old = atomic64_cmpxchg((v), c, c + (a));
5295+
5296+ asm volatile("addcc %2, %0, %0\n"
5297+
5298+#ifdef CONFIG_PAX_REFCOUNT
5299+ "tvs %%xcc, 6\n"
5300+#endif
5301+
5302+ : "=r" (new)
5303+ : "0" (c), "ir" (a)
5304+ : "cc");
5305+
5306+ old = atomic64_cmpxchg(v, c, new);
5307 if (likely(old == c))
5308 break;
5309 c = old;
5310 }
5311- return c != (u);
5312+ return c != u;
5313 }
5314
5315 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5316diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5317index 5bb6991..5c2132e 100644
5318--- a/arch/sparc/include/asm/cache.h
5319+++ b/arch/sparc/include/asm/cache.h
5320@@ -7,10 +7,12 @@
5321 #ifndef _SPARC_CACHE_H
5322 #define _SPARC_CACHE_H
5323
5324+#include <linux/const.h>
5325+
5326 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5327
5328 #define L1_CACHE_SHIFT 5
5329-#define L1_CACHE_BYTES 32
5330+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5331
5332 #ifdef CONFIG_SPARC32
5333 #define SMP_CACHE_BYTES_SHIFT 5
5334diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5335index 2d4d755..81b6662 100644
5336--- a/arch/sparc/include/asm/elf_32.h
5337+++ b/arch/sparc/include/asm/elf_32.h
5338@@ -114,6 +114,13 @@ typedef struct {
5339
5340 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5341
5342+#ifdef CONFIG_PAX_ASLR
5343+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5344+
5345+#define PAX_DELTA_MMAP_LEN 16
5346+#define PAX_DELTA_STACK_LEN 16
5347+#endif
5348+
5349 /* This yields a mask that user programs can use to figure out what
5350 instruction set this cpu supports. This can NOT be done in userspace
5351 on Sparc. */
5352diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5353index 7df8b7f..4946269 100644
5354--- a/arch/sparc/include/asm/elf_64.h
5355+++ b/arch/sparc/include/asm/elf_64.h
5356@@ -180,6 +180,13 @@ typedef struct {
5357 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5358 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5359
5360+#ifdef CONFIG_PAX_ASLR
5361+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5362+
5363+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5364+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5365+#endif
5366+
5367 extern unsigned long sparc64_elf_hwcap;
5368 #define ELF_HWCAP sparc64_elf_hwcap
5369
5370diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5371index e5b169b46..e90b4fa 100644
5372--- a/arch/sparc/include/asm/pgalloc_32.h
5373+++ b/arch/sparc/include/asm/pgalloc_32.h
5374@@ -46,6 +46,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5375 }
5376
5377 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5378+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5379
5380 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5381 unsigned long address)
5382diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5383index 40b2d7a..22a665b 100644
5384--- a/arch/sparc/include/asm/pgalloc_64.h
5385+++ b/arch/sparc/include/asm/pgalloc_64.h
5386@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5387 }
5388
5389 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5390+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5391
5392 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5393 {
5394diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5395index cbbbed5..97f72f9 100644
5396--- a/arch/sparc/include/asm/pgtable_32.h
5397+++ b/arch/sparc/include/asm/pgtable_32.h
5398@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5399 #define PAGE_SHARED SRMMU_PAGE_SHARED
5400 #define PAGE_COPY SRMMU_PAGE_COPY
5401 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5402+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5403+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5404+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5405 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5406
5407 /* Top-level page directory */
5408@@ -61,18 +64,18 @@ extern unsigned long ptr_in_current_pgd;
5409
5410 /* xwr */
5411 #define __P000 PAGE_NONE
5412-#define __P001 PAGE_READONLY
5413-#define __P010 PAGE_COPY
5414-#define __P011 PAGE_COPY
5415+#define __P001 PAGE_READONLY_NOEXEC
5416+#define __P010 PAGE_COPY_NOEXEC
5417+#define __P011 PAGE_COPY_NOEXEC
5418 #define __P100 PAGE_READONLY
5419 #define __P101 PAGE_READONLY
5420 #define __P110 PAGE_COPY
5421 #define __P111 PAGE_COPY
5422
5423 #define __S000 PAGE_NONE
5424-#define __S001 PAGE_READONLY
5425-#define __S010 PAGE_SHARED
5426-#define __S011 PAGE_SHARED
5427+#define __S001 PAGE_READONLY_NOEXEC
5428+#define __S010 PAGE_SHARED_NOEXEC
5429+#define __S011 PAGE_SHARED_NOEXEC
5430 #define __S100 PAGE_READONLY
5431 #define __S101 PAGE_READONLY
5432 #define __S110 PAGE_SHARED
5433diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5434index 79da178..c2eede8 100644
5435--- a/arch/sparc/include/asm/pgtsrmmu.h
5436+++ b/arch/sparc/include/asm/pgtsrmmu.h
5437@@ -115,6 +115,11 @@
5438 SRMMU_EXEC | SRMMU_REF)
5439 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5440 SRMMU_EXEC | SRMMU_REF)
5441+
5442+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5443+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5444+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5445+
5446 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5447 SRMMU_DIRTY | SRMMU_REF)
5448
5449diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5450index 9689176..63c18ea 100644
5451--- a/arch/sparc/include/asm/spinlock_64.h
5452+++ b/arch/sparc/include/asm/spinlock_64.h
5453@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5454
5455 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5456
5457-static void inline arch_read_lock(arch_rwlock_t *lock)
5458+static inline void arch_read_lock(arch_rwlock_t *lock)
5459 {
5460 unsigned long tmp1, tmp2;
5461
5462 __asm__ __volatile__ (
5463 "1: ldsw [%2], %0\n"
5464 " brlz,pn %0, 2f\n"
5465-"4: add %0, 1, %1\n"
5466+"4: addcc %0, 1, %1\n"
5467+
5468+#ifdef CONFIG_PAX_REFCOUNT
5469+" tvs %%icc, 6\n"
5470+#endif
5471+
5472 " cas [%2], %0, %1\n"
5473 " cmp %0, %1\n"
5474 " bne,pn %%icc, 1b\n"
5475@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5476 " .previous"
5477 : "=&r" (tmp1), "=&r" (tmp2)
5478 : "r" (lock)
5479- : "memory");
5480+ : "memory", "cc");
5481 }
5482
5483-static int inline arch_read_trylock(arch_rwlock_t *lock)
5484+static inline int arch_read_trylock(arch_rwlock_t *lock)
5485 {
5486 int tmp1, tmp2;
5487
5488@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5489 "1: ldsw [%2], %0\n"
5490 " brlz,a,pn %0, 2f\n"
5491 " mov 0, %0\n"
5492-" add %0, 1, %1\n"
5493+" addcc %0, 1, %1\n"
5494+
5495+#ifdef CONFIG_PAX_REFCOUNT
5496+" tvs %%icc, 6\n"
5497+#endif
5498+
5499 " cas [%2], %0, %1\n"
5500 " cmp %0, %1\n"
5501 " bne,pn %%icc, 1b\n"
5502@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5503 return tmp1;
5504 }
5505
5506-static void inline arch_read_unlock(arch_rwlock_t *lock)
5507+static inline void arch_read_unlock(arch_rwlock_t *lock)
5508 {
5509 unsigned long tmp1, tmp2;
5510
5511 __asm__ __volatile__(
5512 "1: lduw [%2], %0\n"
5513-" sub %0, 1, %1\n"
5514+" subcc %0, 1, %1\n"
5515+
5516+#ifdef CONFIG_PAX_REFCOUNT
5517+" tvs %%icc, 6\n"
5518+#endif
5519+
5520 " cas [%2], %0, %1\n"
5521 " cmp %0, %1\n"
5522 " bne,pn %%xcc, 1b\n"
5523@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5524 : "memory");
5525 }
5526
5527-static void inline arch_write_lock(arch_rwlock_t *lock)
5528+static inline void arch_write_lock(arch_rwlock_t *lock)
5529 {
5530 unsigned long mask, tmp1, tmp2;
5531
5532@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5533 : "memory");
5534 }
5535
5536-static void inline arch_write_unlock(arch_rwlock_t *lock)
5537+static inline void arch_write_unlock(arch_rwlock_t *lock)
5538 {
5539 __asm__ __volatile__(
5540 " stw %%g0, [%0]"
5541@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5542 : "memory");
5543 }
5544
5545-static int inline arch_write_trylock(arch_rwlock_t *lock)
5546+static inline int arch_write_trylock(arch_rwlock_t *lock)
5547 {
5548 unsigned long mask, tmp1, tmp2, result;
5549
5550diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5551index e6cd224..3a71793 100644
5552--- a/arch/sparc/include/asm/thread_info_32.h
5553+++ b/arch/sparc/include/asm/thread_info_32.h
5554@@ -49,6 +49,8 @@ struct thread_info {
5555 unsigned long w_saved;
5556
5557 struct restart_block restart_block;
5558+
5559+ unsigned long lowest_stack;
5560 };
5561
5562 /*
5563diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5564index cfa8c38..13f30d3 100644
5565--- a/arch/sparc/include/asm/thread_info_64.h
5566+++ b/arch/sparc/include/asm/thread_info_64.h
5567@@ -63,6 +63,8 @@ struct thread_info {
5568 struct pt_regs *kern_una_regs;
5569 unsigned int kern_una_insn;
5570
5571+ unsigned long lowest_stack;
5572+
5573 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5574 };
5575
5576@@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5577 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5578 /* flag bit 6 is available */
5579 #define TIF_32BIT 7 /* 32-bit binary */
5580-/* flag bit 8 is available */
5581+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5582 #define TIF_SECCOMP 9 /* secure computing */
5583 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5584 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5585+
5586 /* NOTE: Thread flags >= 12 should be ones we have no interest
5587 * in using in assembly, else we can't use the mask as
5588 * an immediate value in instructions such as andcc.
5589@@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5590 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5591 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5592 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5593+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5594
5595 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5596 _TIF_DO_NOTIFY_RESUME_MASK | \
5597 _TIF_NEED_RESCHED)
5598 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5599
5600+#define _TIF_WORK_SYSCALL \
5601+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5602+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5603+
5604+
5605 /*
5606 * Thread-synchronous status.
5607 *
5608diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5609index 0167d26..9acd8ed 100644
5610--- a/arch/sparc/include/asm/uaccess.h
5611+++ b/arch/sparc/include/asm/uaccess.h
5612@@ -1,5 +1,13 @@
5613 #ifndef ___ASM_SPARC_UACCESS_H
5614 #define ___ASM_SPARC_UACCESS_H
5615+
5616+#ifdef __KERNEL__
5617+#ifndef __ASSEMBLY__
5618+#include <linux/types.h>
5619+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5620+#endif
5621+#endif
5622+
5623 #if defined(__sparc__) && defined(__arch64__)
5624 #include <asm/uaccess_64.h>
5625 #else
5626diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5627index 53a28dd..50c38c3 100644
5628--- a/arch/sparc/include/asm/uaccess_32.h
5629+++ b/arch/sparc/include/asm/uaccess_32.h
5630@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5631
5632 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5633 {
5634- if (n && __access_ok((unsigned long) to, n))
5635+ if ((long)n < 0)
5636+ return n;
5637+
5638+ if (n && __access_ok((unsigned long) to, n)) {
5639+ if (!__builtin_constant_p(n))
5640+ check_object_size(from, n, true);
5641 return __copy_user(to, (__force void __user *) from, n);
5642- else
5643+ } else
5644 return n;
5645 }
5646
5647 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5648 {
5649+ if ((long)n < 0)
5650+ return n;
5651+
5652+ if (!__builtin_constant_p(n))
5653+ check_object_size(from, n, true);
5654+
5655 return __copy_user(to, (__force void __user *) from, n);
5656 }
5657
5658 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5659 {
5660- if (n && __access_ok((unsigned long) from, n))
5661+ if ((long)n < 0)
5662+ return n;
5663+
5664+ if (n && __access_ok((unsigned long) from, n)) {
5665+ if (!__builtin_constant_p(n))
5666+ check_object_size(to, n, false);
5667 return __copy_user((__force void __user *) to, from, n);
5668- else
5669+ } else
5670 return n;
5671 }
5672
5673 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5674 {
5675+ if ((long)n < 0)
5676+ return n;
5677+
5678 return __copy_user((__force void __user *) to, from, n);
5679 }
5680
5681diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5682index 7c831d8..d440ca7 100644
5683--- a/arch/sparc/include/asm/uaccess_64.h
5684+++ b/arch/sparc/include/asm/uaccess_64.h
5685@@ -10,6 +10,7 @@
5686 #include <linux/compiler.h>
5687 #include <linux/string.h>
5688 #include <linux/thread_info.h>
5689+#include <linux/kernel.h>
5690 #include <asm/asi.h>
5691 #include <asm/spitfire.h>
5692 #include <asm-generic/uaccess-unaligned.h>
5693@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5694 static inline unsigned long __must_check
5695 copy_from_user(void *to, const void __user *from, unsigned long size)
5696 {
5697- unsigned long ret = ___copy_from_user(to, from, size);
5698+ unsigned long ret;
5699
5700+ if ((long)size < 0 || size > INT_MAX)
5701+ return size;
5702+
5703+ if (!__builtin_constant_p(size))
5704+ check_object_size(to, size, false);
5705+
5706+ ret = ___copy_from_user(to, from, size);
5707 if (unlikely(ret))
5708 ret = copy_from_user_fixup(to, from, size);
5709
5710@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5711 static inline unsigned long __must_check
5712 copy_to_user(void __user *to, const void *from, unsigned long size)
5713 {
5714- unsigned long ret = ___copy_to_user(to, from, size);
5715+ unsigned long ret;
5716
5717+ if ((long)size < 0 || size > INT_MAX)
5718+ return size;
5719+
5720+ if (!__builtin_constant_p(size))
5721+ check_object_size(from, size, true);
5722+
5723+ ret = ___copy_to_user(to, from, size);
5724 if (unlikely(ret))
5725 ret = copy_to_user_fixup(to, from, size);
5726 return ret;
5727diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5728index 6cf591b..b49e65a 100644
5729--- a/arch/sparc/kernel/Makefile
5730+++ b/arch/sparc/kernel/Makefile
5731@@ -3,7 +3,7 @@
5732 #
5733
5734 asflags-y := -ansi
5735-ccflags-y := -Werror
5736+#ccflags-y := -Werror
5737
5738 extra-y := head_$(BITS).o
5739
5740diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5741index cb36e82..1c1462f 100644
5742--- a/arch/sparc/kernel/process_32.c
5743+++ b/arch/sparc/kernel/process_32.c
5744@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5745
5746 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5747 r->psr, r->pc, r->npc, r->y, print_tainted());
5748- printk("PC: <%pS>\n", (void *) r->pc);
5749+ printk("PC: <%pA>\n", (void *) r->pc);
5750 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5751 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5752 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5753 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5754 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5755 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5756- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5757+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5758
5759 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5760 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5761@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5762 rw = (struct reg_window32 *) fp;
5763 pc = rw->ins[7];
5764 printk("[%08lx : ", pc);
5765- printk("%pS ] ", (void *) pc);
5766+ printk("%pA ] ", (void *) pc);
5767 fp = rw->ins[6];
5768 } while (++count < 16);
5769 printk("\n");
5770diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5771index aff0c72..9067b39 100644
5772--- a/arch/sparc/kernel/process_64.c
5773+++ b/arch/sparc/kernel/process_64.c
5774@@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5775 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5776 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5777 if (regs->tstate & TSTATE_PRIV)
5778- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5779+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5780 }
5781
5782 void show_regs(struct pt_regs *regs)
5783 {
5784 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5785 regs->tpc, regs->tnpc, regs->y, print_tainted());
5786- printk("TPC: <%pS>\n", (void *) regs->tpc);
5787+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5788 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5789 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5790 regs->u_regs[3]);
5791@@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5792 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5793 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5794 regs->u_regs[15]);
5795- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5796+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5797 show_regwindow(regs);
5798 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5799 }
5800@@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5801 ((tp && tp->task) ? tp->task->pid : -1));
5802
5803 if (gp->tstate & TSTATE_PRIV) {
5804- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5805+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5806 (void *) gp->tpc,
5807 (void *) gp->o7,
5808 (void *) gp->i7,
5809diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5810index 484daba..0674139 100644
5811--- a/arch/sparc/kernel/ptrace_64.c
5812+++ b/arch/sparc/kernel/ptrace_64.c
5813@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5814 return ret;
5815 }
5816
5817+#ifdef CONFIG_GRKERNSEC_SETXID
5818+extern void gr_delayed_cred_worker(void);
5819+#endif
5820+
5821 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5822 {
5823 int ret = 0;
5824@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5825 /* do the secure computing check first */
5826 secure_computing_strict(regs->u_regs[UREG_G1]);
5827
5828+#ifdef CONFIG_GRKERNSEC_SETXID
5829+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5830+ gr_delayed_cred_worker();
5831+#endif
5832+
5833 if (test_thread_flag(TIF_SYSCALL_TRACE))
5834 ret = tracehook_report_syscall_entry(regs);
5835
5836@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5837
5838 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5839 {
5840+#ifdef CONFIG_GRKERNSEC_SETXID
5841+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5842+ gr_delayed_cred_worker();
5843+#endif
5844+
5845 audit_syscall_exit(regs);
5846
5847 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5848diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5849index 0c9b31b..7cb7aee 100644
5850--- a/arch/sparc/kernel/sys_sparc_32.c
5851+++ b/arch/sparc/kernel/sys_sparc_32.c
5852@@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5853 if (len > TASK_SIZE - PAGE_SIZE)
5854 return -ENOMEM;
5855 if (!addr)
5856- addr = TASK_UNMAPPED_BASE;
5857+ addr = current->mm->mmap_base;
5858
5859 if (flags & MAP_SHARED)
5860 addr = COLOUR_ALIGN(addr);
5861@@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5862 /* At this point: (!vmm || addr < vmm->vm_end). */
5863 if (TASK_SIZE - PAGE_SIZE - len < addr)
5864 return -ENOMEM;
5865- if (!vmm || addr + len <= vmm->vm_start)
5866+ if (check_heap_stack_gap(vmm, addr, len))
5867 return addr;
5868 addr = vmm->vm_end;
5869 if (flags & MAP_SHARED)
5870diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5871index 275f74f..81bf5b8 100644
5872--- a/arch/sparc/kernel/sys_sparc_64.c
5873+++ b/arch/sparc/kernel/sys_sparc_64.c
5874@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5875 /* We do not accept a shared mapping if it would violate
5876 * cache aliasing constraints.
5877 */
5878- if ((flags & MAP_SHARED) &&
5879+ if ((filp || (flags & MAP_SHARED)) &&
5880 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5881 return -EINVAL;
5882 return addr;
5883@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5884 if (filp || (flags & MAP_SHARED))
5885 do_color_align = 1;
5886
5887+#ifdef CONFIG_PAX_RANDMMAP
5888+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5889+#endif
5890+
5891 if (addr) {
5892 if (do_color_align)
5893 addr = COLOUR_ALIGN(addr, pgoff);
5894@@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5895 addr = PAGE_ALIGN(addr);
5896
5897 vma = find_vma(mm, addr);
5898- if (task_size - len >= addr &&
5899- (!vma || addr + len <= vma->vm_start))
5900+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5901 return addr;
5902 }
5903
5904 if (len > mm->cached_hole_size) {
5905- start_addr = addr = mm->free_area_cache;
5906+ start_addr = addr = mm->free_area_cache;
5907 } else {
5908- start_addr = addr = TASK_UNMAPPED_BASE;
5909+ start_addr = addr = mm->mmap_base;
5910 mm->cached_hole_size = 0;
5911 }
5912
5913@@ -174,14 +177,14 @@ full_search:
5914 vma = find_vma(mm, VA_EXCLUDE_END);
5915 }
5916 if (unlikely(task_size < addr)) {
5917- if (start_addr != TASK_UNMAPPED_BASE) {
5918- start_addr = addr = TASK_UNMAPPED_BASE;
5919+ if (start_addr != mm->mmap_base) {
5920+ start_addr = addr = mm->mmap_base;
5921 mm->cached_hole_size = 0;
5922 goto full_search;
5923 }
5924 return -ENOMEM;
5925 }
5926- if (likely(!vma || addr + len <= vma->vm_start)) {
5927+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5928 /*
5929 * Remember the place where we stopped the search:
5930 */
5931@@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5932 /* We do not accept a shared mapping if it would violate
5933 * cache aliasing constraints.
5934 */
5935- if ((flags & MAP_SHARED) &&
5936+ if ((filp || (flags & MAP_SHARED)) &&
5937 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5938 return -EINVAL;
5939 return addr;
5940@@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5941 addr = PAGE_ALIGN(addr);
5942
5943 vma = find_vma(mm, addr);
5944- if (task_size - len >= addr &&
5945- (!vma || addr + len <= vma->vm_start))
5946+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5947 return addr;
5948 }
5949
5950@@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5951 /* make sure it can fit in the remaining address space */
5952 if (likely(addr > len)) {
5953 vma = find_vma(mm, addr-len);
5954- if (!vma || addr <= vma->vm_start) {
5955+ if (check_heap_stack_gap(vma, addr - len, len)) {
5956 /* remember the address as a hint for next time */
5957 return (mm->free_area_cache = addr-len);
5958 }
5959@@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5960 if (unlikely(mm->mmap_base < len))
5961 goto bottomup;
5962
5963- addr = mm->mmap_base-len;
5964- if (do_color_align)
5965- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5966+ addr = mm->mmap_base - len;
5967
5968 do {
5969+ if (do_color_align)
5970+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5971 /*
5972 * Lookup failure means no vma is above this address,
5973 * else if new region fits below vma->vm_start,
5974 * return with success:
5975 */
5976 vma = find_vma(mm, addr);
5977- if (likely(!vma || addr+len <= vma->vm_start)) {
5978+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5979 /* remember the address as a hint for next time */
5980 return (mm->free_area_cache = addr);
5981 }
5982@@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5983 mm->cached_hole_size = vma->vm_start - addr;
5984
5985 /* try just below the current vma->vm_start */
5986- addr = vma->vm_start-len;
5987- if (do_color_align)
5988- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5989- } while (likely(len < vma->vm_start));
5990+ addr = skip_heap_stack_gap(vma, len);
5991+ } while (!IS_ERR_VALUE(addr));
5992
5993 bottomup:
5994 /*
5995@@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5996 gap == RLIM_INFINITY ||
5997 sysctl_legacy_va_layout) {
5998 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5999+
6000+#ifdef CONFIG_PAX_RANDMMAP
6001+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6002+ mm->mmap_base += mm->delta_mmap;
6003+#endif
6004+
6005 mm->get_unmapped_area = arch_get_unmapped_area;
6006 mm->unmap_area = arch_unmap_area;
6007 } else {
6008@@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6009 gap = (task_size / 6 * 5);
6010
6011 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6012+
6013+#ifdef CONFIG_PAX_RANDMMAP
6014+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6015+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6016+#endif
6017+
6018 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6019 mm->unmap_area = arch_unmap_area_topdown;
6020 }
6021diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
6022index 1d7e274..b39c527 100644
6023--- a/arch/sparc/kernel/syscalls.S
6024+++ b/arch/sparc/kernel/syscalls.S
6025@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6026 #endif
6027 .align 32
6028 1: ldx [%g6 + TI_FLAGS], %l5
6029- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6030+ andcc %l5, _TIF_WORK_SYSCALL, %g0
6031 be,pt %icc, rtrap
6032 nop
6033 call syscall_trace_leave
6034@@ -179,7 +179,7 @@ linux_sparc_syscall32:
6035
6036 srl %i5, 0, %o5 ! IEU1
6037 srl %i2, 0, %o2 ! IEU0 Group
6038- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6039+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6040 bne,pn %icc, linux_syscall_trace32 ! CTI
6041 mov %i0, %l5 ! IEU1
6042 call %l7 ! CTI Group brk forced
6043@@ -202,7 +202,7 @@ linux_sparc_syscall:
6044
6045 mov %i3, %o3 ! IEU1
6046 mov %i4, %o4 ! IEU0 Group
6047- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6048+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6049 bne,pn %icc, linux_syscall_trace ! CTI Group
6050 mov %i0, %l5 ! IEU0
6051 2: call %l7 ! CTI Group brk forced
6052@@ -226,7 +226,7 @@ ret_sys_call:
6053
6054 cmp %o0, -ERESTART_RESTARTBLOCK
6055 bgeu,pn %xcc, 1f
6056- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6057+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6058 80:
6059 /* System call success, clear Carry condition code. */
6060 andn %g3, %g2, %g3
6061@@ -241,7 +241,7 @@ ret_sys_call:
6062 /* System call failure, set Carry condition code.
6063 * Also, get abs(errno) to return to the process.
6064 */
6065- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6066+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6067 sub %g0, %o0, %o0
6068 or %g3, %g2, %g3
6069 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6070diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6071index a5785ea..405c5f7 100644
6072--- a/arch/sparc/kernel/traps_32.c
6073+++ b/arch/sparc/kernel/traps_32.c
6074@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6075 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6076 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6077
6078+extern void gr_handle_kernel_exploit(void);
6079+
6080 void die_if_kernel(char *str, struct pt_regs *regs)
6081 {
6082 static int die_counter;
6083@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6084 count++ < 30 &&
6085 (((unsigned long) rw) >= PAGE_OFFSET) &&
6086 !(((unsigned long) rw) & 0x7)) {
6087- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6088+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6089 (void *) rw->ins[7]);
6090 rw = (struct reg_window32 *)rw->ins[6];
6091 }
6092 }
6093 printk("Instruction DUMP:");
6094 instruction_dump ((unsigned long *) regs->pc);
6095- if(regs->psr & PSR_PS)
6096+ if(regs->psr & PSR_PS) {
6097+ gr_handle_kernel_exploit();
6098 do_exit(SIGKILL);
6099+ }
6100 do_exit(SIGSEGV);
6101 }
6102
6103diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6104index 3b05e66..6ea2917 100644
6105--- a/arch/sparc/kernel/traps_64.c
6106+++ b/arch/sparc/kernel/traps_64.c
6107@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6108 i + 1,
6109 p->trapstack[i].tstate, p->trapstack[i].tpc,
6110 p->trapstack[i].tnpc, p->trapstack[i].tt);
6111- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6112+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6113 }
6114 }
6115
6116@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6117
6118 lvl -= 0x100;
6119 if (regs->tstate & TSTATE_PRIV) {
6120+
6121+#ifdef CONFIG_PAX_REFCOUNT
6122+ if (lvl == 6)
6123+ pax_report_refcount_overflow(regs);
6124+#endif
6125+
6126 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6127 die_if_kernel(buffer, regs);
6128 }
6129@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6130 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6131 {
6132 char buffer[32];
6133-
6134+
6135 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6136 0, lvl, SIGTRAP) == NOTIFY_STOP)
6137 return;
6138
6139+#ifdef CONFIG_PAX_REFCOUNT
6140+ if (lvl == 6)
6141+ pax_report_refcount_overflow(regs);
6142+#endif
6143+
6144 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6145
6146 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6147@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6148 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6149 printk("%s" "ERROR(%d): ",
6150 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6151- printk("TPC<%pS>\n", (void *) regs->tpc);
6152+ printk("TPC<%pA>\n", (void *) regs->tpc);
6153 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6154 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6155 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6156@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6157 smp_processor_id(),
6158 (type & 0x1) ? 'I' : 'D',
6159 regs->tpc);
6160- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6161+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6162 panic("Irrecoverable Cheetah+ parity error.");
6163 }
6164
6165@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6166 smp_processor_id(),
6167 (type & 0x1) ? 'I' : 'D',
6168 regs->tpc);
6169- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6170+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6171 }
6172
6173 struct sun4v_error_entry {
6174@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6175
6176 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6177 regs->tpc, tl);
6178- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6179+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6180 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6181- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6182+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6183 (void *) regs->u_regs[UREG_I7]);
6184 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6185 "pte[%lx] error[%lx]\n",
6186@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6187
6188 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6189 regs->tpc, tl);
6190- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6191+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6192 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6193- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6194+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6195 (void *) regs->u_regs[UREG_I7]);
6196 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6197 "pte[%lx] error[%lx]\n",
6198@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6199 fp = (unsigned long)sf->fp + STACK_BIAS;
6200 }
6201
6202- printk(" [%016lx] %pS\n", pc, (void *) pc);
6203+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6204 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6205 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6206 int index = tsk->curr_ret_stack;
6207 if (tsk->ret_stack && index >= graph) {
6208 pc = tsk->ret_stack[index - graph].ret;
6209- printk(" [%016lx] %pS\n", pc, (void *) pc);
6210+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6211 graph++;
6212 }
6213 }
6214@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6215 return (struct reg_window *) (fp + STACK_BIAS);
6216 }
6217
6218+extern void gr_handle_kernel_exploit(void);
6219+
6220 void die_if_kernel(char *str, struct pt_regs *regs)
6221 {
6222 static int die_counter;
6223@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6224 while (rw &&
6225 count++ < 30 &&
6226 kstack_valid(tp, (unsigned long) rw)) {
6227- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6228+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6229 (void *) rw->ins[7]);
6230
6231 rw = kernel_stack_up(rw);
6232@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6233 }
6234 user_instruction_dump ((unsigned int __user *) regs->tpc);
6235 }
6236- if (regs->tstate & TSTATE_PRIV)
6237+ if (regs->tstate & TSTATE_PRIV) {
6238+ gr_handle_kernel_exploit();
6239 do_exit(SIGKILL);
6240+ }
6241 do_exit(SIGSEGV);
6242 }
6243 EXPORT_SYMBOL(die_if_kernel);
6244diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6245index f81d038..e7a4680 100644
6246--- a/arch/sparc/kernel/unaligned_64.c
6247+++ b/arch/sparc/kernel/unaligned_64.c
6248@@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6249 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6250
6251 if (__ratelimit(&ratelimit)) {
6252- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6253+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6254 regs->tpc, (void *) regs->tpc);
6255 }
6256 }
6257diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6258index dff4096..bd9a388 100644
6259--- a/arch/sparc/lib/Makefile
6260+++ b/arch/sparc/lib/Makefile
6261@@ -2,7 +2,7 @@
6262 #
6263
6264 asflags-y := -ansi -DST_DIV0=0x02
6265-ccflags-y := -Werror
6266+#ccflags-y := -Werror
6267
6268 lib-$(CONFIG_SPARC32) += ashrdi3.o
6269 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6270diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6271index 4d502da..527c48d 100644
6272--- a/arch/sparc/lib/atomic_64.S
6273+++ b/arch/sparc/lib/atomic_64.S
6274@@ -17,7 +17,12 @@
6275 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6276 BACKOFF_SETUP(%o2)
6277 1: lduw [%o1], %g1
6278- add %g1, %o0, %g7
6279+ addcc %g1, %o0, %g7
6280+
6281+#ifdef CONFIG_PAX_REFCOUNT
6282+ tvs %icc, 6
6283+#endif
6284+
6285 cas [%o1], %g1, %g7
6286 cmp %g1, %g7
6287 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6288@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6289 2: BACKOFF_SPIN(%o2, %o3, 1b)
6290 ENDPROC(atomic_add)
6291
6292+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6293+ BACKOFF_SETUP(%o2)
6294+1: lduw [%o1], %g1
6295+ add %g1, %o0, %g7
6296+ cas [%o1], %g1, %g7
6297+ cmp %g1, %g7
6298+ bne,pn %icc, 2f
6299+ nop
6300+ retl
6301+ nop
6302+2: BACKOFF_SPIN(%o2, %o3, 1b)
6303+ENDPROC(atomic_add_unchecked)
6304+
6305 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6306 BACKOFF_SETUP(%o2)
6307 1: lduw [%o1], %g1
6308- sub %g1, %o0, %g7
6309+ subcc %g1, %o0, %g7
6310+
6311+#ifdef CONFIG_PAX_REFCOUNT
6312+ tvs %icc, 6
6313+#endif
6314+
6315 cas [%o1], %g1, %g7
6316 cmp %g1, %g7
6317 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6318@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6319 2: BACKOFF_SPIN(%o2, %o3, 1b)
6320 ENDPROC(atomic_sub)
6321
6322+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6323+ BACKOFF_SETUP(%o2)
6324+1: lduw [%o1], %g1
6325+ sub %g1, %o0, %g7
6326+ cas [%o1], %g1, %g7
6327+ cmp %g1, %g7
6328+ bne,pn %icc, 2f
6329+ nop
6330+ retl
6331+ nop
6332+2: BACKOFF_SPIN(%o2, %o3, 1b)
6333+ENDPROC(atomic_sub_unchecked)
6334+
6335 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6336 BACKOFF_SETUP(%o2)
6337 1: lduw [%o1], %g1
6338- add %g1, %o0, %g7
6339+ addcc %g1, %o0, %g7
6340+
6341+#ifdef CONFIG_PAX_REFCOUNT
6342+ tvs %icc, 6
6343+#endif
6344+
6345 cas [%o1], %g1, %g7
6346 cmp %g1, %g7
6347 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6348@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6349 2: BACKOFF_SPIN(%o2, %o3, 1b)
6350 ENDPROC(atomic_add_ret)
6351
6352+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6353+ BACKOFF_SETUP(%o2)
6354+1: lduw [%o1], %g1
6355+ addcc %g1, %o0, %g7
6356+ cas [%o1], %g1, %g7
6357+ cmp %g1, %g7
6358+ bne,pn %icc, 2f
6359+ add %g7, %o0, %g7
6360+ sra %g7, 0, %o0
6361+ retl
6362+ nop
6363+2: BACKOFF_SPIN(%o2, %o3, 1b)
6364+ENDPROC(atomic_add_ret_unchecked)
6365+
6366 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6367 BACKOFF_SETUP(%o2)
6368 1: lduw [%o1], %g1
6369- sub %g1, %o0, %g7
6370+ subcc %g1, %o0, %g7
6371+
6372+#ifdef CONFIG_PAX_REFCOUNT
6373+ tvs %icc, 6
6374+#endif
6375+
6376 cas [%o1], %g1, %g7
6377 cmp %g1, %g7
6378 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6379@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6380 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6381 BACKOFF_SETUP(%o2)
6382 1: ldx [%o1], %g1
6383- add %g1, %o0, %g7
6384+ addcc %g1, %o0, %g7
6385+
6386+#ifdef CONFIG_PAX_REFCOUNT
6387+ tvs %xcc, 6
6388+#endif
6389+
6390 casx [%o1], %g1, %g7
6391 cmp %g1, %g7
6392 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6393@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6394 2: BACKOFF_SPIN(%o2, %o3, 1b)
6395 ENDPROC(atomic64_add)
6396
6397+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6398+ BACKOFF_SETUP(%o2)
6399+1: ldx [%o1], %g1
6400+ addcc %g1, %o0, %g7
6401+ casx [%o1], %g1, %g7
6402+ cmp %g1, %g7
6403+ bne,pn %xcc, 2f
6404+ nop
6405+ retl
6406+ nop
6407+2: BACKOFF_SPIN(%o2, %o3, 1b)
6408+ENDPROC(atomic64_add_unchecked)
6409+
6410 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6411 BACKOFF_SETUP(%o2)
6412 1: ldx [%o1], %g1
6413- sub %g1, %o0, %g7
6414+ subcc %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@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6424 2: BACKOFF_SPIN(%o2, %o3, 1b)
6425 ENDPROC(atomic64_sub)
6426
6427+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6428+ BACKOFF_SETUP(%o2)
6429+1: ldx [%o1], %g1
6430+ subcc %g1, %o0, %g7
6431+ casx [%o1], %g1, %g7
6432+ cmp %g1, %g7
6433+ bne,pn %xcc, 2f
6434+ nop
6435+ retl
6436+ nop
6437+2: BACKOFF_SPIN(%o2, %o3, 1b)
6438+ENDPROC(atomic64_sub_unchecked)
6439+
6440 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6441 BACKOFF_SETUP(%o2)
6442 1: ldx [%o1], %g1
6443- add %g1, %o0, %g7
6444+ addcc %g1, %o0, %g7
6445+
6446+#ifdef CONFIG_PAX_REFCOUNT
6447+ tvs %xcc, 6
6448+#endif
6449+
6450 casx [%o1], %g1, %g7
6451 cmp %g1, %g7
6452 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6453@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6454 2: BACKOFF_SPIN(%o2, %o3, 1b)
6455 ENDPROC(atomic64_add_ret)
6456
6457+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6458+ BACKOFF_SETUP(%o2)
6459+1: ldx [%o1], %g1
6460+ addcc %g1, %o0, %g7
6461+ casx [%o1], %g1, %g7
6462+ cmp %g1, %g7
6463+ bne,pn %xcc, 2f
6464+ add %g7, %o0, %g7
6465+ mov %g7, %o0
6466+ retl
6467+ nop
6468+2: BACKOFF_SPIN(%o2, %o3, 1b)
6469+ENDPROC(atomic64_add_ret_unchecked)
6470+
6471 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6472 BACKOFF_SETUP(%o2)
6473 1: ldx [%o1], %g1
6474- sub %g1, %o0, %g7
6475+ subcc %g1, %o0, %g7
6476+
6477+#ifdef CONFIG_PAX_REFCOUNT
6478+ tvs %xcc, 6
6479+#endif
6480+
6481 casx [%o1], %g1, %g7
6482 cmp %g1, %g7
6483 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6484diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6485index 3b31218..345c609 100644
6486--- a/arch/sparc/lib/ksyms.c
6487+++ b/arch/sparc/lib/ksyms.c
6488@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6489
6490 /* Atomic counter implementation. */
6491 EXPORT_SYMBOL(atomic_add);
6492+EXPORT_SYMBOL(atomic_add_unchecked);
6493 EXPORT_SYMBOL(atomic_add_ret);
6494+EXPORT_SYMBOL(atomic_add_ret_unchecked);
6495 EXPORT_SYMBOL(atomic_sub);
6496+EXPORT_SYMBOL(atomic_sub_unchecked);
6497 EXPORT_SYMBOL(atomic_sub_ret);
6498 EXPORT_SYMBOL(atomic64_add);
6499+EXPORT_SYMBOL(atomic64_add_unchecked);
6500 EXPORT_SYMBOL(atomic64_add_ret);
6501+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6502 EXPORT_SYMBOL(atomic64_sub);
6503+EXPORT_SYMBOL(atomic64_sub_unchecked);
6504 EXPORT_SYMBOL(atomic64_sub_ret);
6505
6506 /* Atomic bit operations. */
6507diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6508index 30c3ecc..736f015 100644
6509--- a/arch/sparc/mm/Makefile
6510+++ b/arch/sparc/mm/Makefile
6511@@ -2,7 +2,7 @@
6512 #
6513
6514 asflags-y := -ansi
6515-ccflags-y := -Werror
6516+#ccflags-y := -Werror
6517
6518 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6519 obj-y += fault_$(BITS).o
6520diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6521index f46cf6b..7235ec9 100644
6522--- a/arch/sparc/mm/fault_32.c
6523+++ b/arch/sparc/mm/fault_32.c
6524@@ -21,6 +21,9 @@
6525 #include <linux/perf_event.h>
6526 #include <linux/interrupt.h>
6527 #include <linux/kdebug.h>
6528+#include <linux/slab.h>
6529+#include <linux/pagemap.h>
6530+#include <linux/compiler.h>
6531
6532 #include <asm/page.h>
6533 #include <asm/pgtable.h>
6534@@ -177,6 +180,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6535 return safe_compute_effective_address(regs, insn);
6536 }
6537
6538+#ifdef CONFIG_PAX_PAGEEXEC
6539+#ifdef CONFIG_PAX_DLRESOLVE
6540+static void pax_emuplt_close(struct vm_area_struct *vma)
6541+{
6542+ vma->vm_mm->call_dl_resolve = 0UL;
6543+}
6544+
6545+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6546+{
6547+ unsigned int *kaddr;
6548+
6549+ vmf->page = alloc_page(GFP_HIGHUSER);
6550+ if (!vmf->page)
6551+ return VM_FAULT_OOM;
6552+
6553+ kaddr = kmap(vmf->page);
6554+ memset(kaddr, 0, PAGE_SIZE);
6555+ kaddr[0] = 0x9DE3BFA8U; /* save */
6556+ flush_dcache_page(vmf->page);
6557+ kunmap(vmf->page);
6558+ return VM_FAULT_MAJOR;
6559+}
6560+
6561+static const struct vm_operations_struct pax_vm_ops = {
6562+ .close = pax_emuplt_close,
6563+ .fault = pax_emuplt_fault
6564+};
6565+
6566+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6567+{
6568+ int ret;
6569+
6570+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6571+ vma->vm_mm = current->mm;
6572+ vma->vm_start = addr;
6573+ vma->vm_end = addr + PAGE_SIZE;
6574+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6575+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6576+ vma->vm_ops = &pax_vm_ops;
6577+
6578+ ret = insert_vm_struct(current->mm, vma);
6579+ if (ret)
6580+ return ret;
6581+
6582+ ++current->mm->total_vm;
6583+ return 0;
6584+}
6585+#endif
6586+
6587+/*
6588+ * PaX: decide what to do with offenders (regs->pc = fault address)
6589+ *
6590+ * returns 1 when task should be killed
6591+ * 2 when patched PLT trampoline was detected
6592+ * 3 when unpatched PLT trampoline was detected
6593+ */
6594+static int pax_handle_fetch_fault(struct pt_regs *regs)
6595+{
6596+
6597+#ifdef CONFIG_PAX_EMUPLT
6598+ int err;
6599+
6600+ do { /* PaX: patched PLT emulation #1 */
6601+ unsigned int sethi1, sethi2, jmpl;
6602+
6603+ err = get_user(sethi1, (unsigned int *)regs->pc);
6604+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6605+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6606+
6607+ if (err)
6608+ break;
6609+
6610+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6611+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6612+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6613+ {
6614+ unsigned int addr;
6615+
6616+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6617+ addr = regs->u_regs[UREG_G1];
6618+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6619+ regs->pc = addr;
6620+ regs->npc = addr+4;
6621+ return 2;
6622+ }
6623+ } while (0);
6624+
6625+ do { /* PaX: patched PLT emulation #2 */
6626+ unsigned int ba;
6627+
6628+ err = get_user(ba, (unsigned int *)regs->pc);
6629+
6630+ if (err)
6631+ break;
6632+
6633+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6634+ unsigned int addr;
6635+
6636+ if ((ba & 0xFFC00000U) == 0x30800000U)
6637+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6638+ else
6639+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6640+ regs->pc = addr;
6641+ regs->npc = addr+4;
6642+ return 2;
6643+ }
6644+ } while (0);
6645+
6646+ do { /* PaX: patched PLT emulation #3 */
6647+ unsigned int sethi, bajmpl, nop;
6648+
6649+ err = get_user(sethi, (unsigned int *)regs->pc);
6650+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6651+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6652+
6653+ if (err)
6654+ break;
6655+
6656+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6657+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6658+ nop == 0x01000000U)
6659+ {
6660+ unsigned int addr;
6661+
6662+ addr = (sethi & 0x003FFFFFU) << 10;
6663+ regs->u_regs[UREG_G1] = addr;
6664+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6665+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6666+ else
6667+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6668+ regs->pc = addr;
6669+ regs->npc = addr+4;
6670+ return 2;
6671+ }
6672+ } while (0);
6673+
6674+ do { /* PaX: unpatched PLT emulation step 1 */
6675+ unsigned int sethi, ba, nop;
6676+
6677+ err = get_user(sethi, (unsigned int *)regs->pc);
6678+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6679+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6680+
6681+ if (err)
6682+ break;
6683+
6684+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6685+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6686+ nop == 0x01000000U)
6687+ {
6688+ unsigned int addr, save, call;
6689+
6690+ if ((ba & 0xFFC00000U) == 0x30800000U)
6691+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6692+ else
6693+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6694+
6695+ err = get_user(save, (unsigned int *)addr);
6696+ err |= get_user(call, (unsigned int *)(addr+4));
6697+ err |= get_user(nop, (unsigned int *)(addr+8));
6698+ if (err)
6699+ break;
6700+
6701+#ifdef CONFIG_PAX_DLRESOLVE
6702+ if (save == 0x9DE3BFA8U &&
6703+ (call & 0xC0000000U) == 0x40000000U &&
6704+ nop == 0x01000000U)
6705+ {
6706+ struct vm_area_struct *vma;
6707+ unsigned long call_dl_resolve;
6708+
6709+ down_read(&current->mm->mmap_sem);
6710+ call_dl_resolve = current->mm->call_dl_resolve;
6711+ up_read(&current->mm->mmap_sem);
6712+ if (likely(call_dl_resolve))
6713+ goto emulate;
6714+
6715+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6716+
6717+ down_write(&current->mm->mmap_sem);
6718+ if (current->mm->call_dl_resolve) {
6719+ call_dl_resolve = current->mm->call_dl_resolve;
6720+ up_write(&current->mm->mmap_sem);
6721+ if (vma)
6722+ kmem_cache_free(vm_area_cachep, vma);
6723+ goto emulate;
6724+ }
6725+
6726+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6727+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6728+ up_write(&current->mm->mmap_sem);
6729+ if (vma)
6730+ kmem_cache_free(vm_area_cachep, vma);
6731+ return 1;
6732+ }
6733+
6734+ if (pax_insert_vma(vma, call_dl_resolve)) {
6735+ up_write(&current->mm->mmap_sem);
6736+ kmem_cache_free(vm_area_cachep, vma);
6737+ return 1;
6738+ }
6739+
6740+ current->mm->call_dl_resolve = call_dl_resolve;
6741+ up_write(&current->mm->mmap_sem);
6742+
6743+emulate:
6744+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6745+ regs->pc = call_dl_resolve;
6746+ regs->npc = addr+4;
6747+ return 3;
6748+ }
6749+#endif
6750+
6751+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6752+ if ((save & 0xFFC00000U) == 0x05000000U &&
6753+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6754+ nop == 0x01000000U)
6755+ {
6756+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6757+ regs->u_regs[UREG_G2] = addr + 4;
6758+ addr = (save & 0x003FFFFFU) << 10;
6759+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6760+ regs->pc = addr;
6761+ regs->npc = addr+4;
6762+ return 3;
6763+ }
6764+ }
6765+ } while (0);
6766+
6767+ do { /* PaX: unpatched PLT emulation step 2 */
6768+ unsigned int save, call, nop;
6769+
6770+ err = get_user(save, (unsigned int *)(regs->pc-4));
6771+ err |= get_user(call, (unsigned int *)regs->pc);
6772+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6773+ if (err)
6774+ break;
6775+
6776+ if (save == 0x9DE3BFA8U &&
6777+ (call & 0xC0000000U) == 0x40000000U &&
6778+ nop == 0x01000000U)
6779+ {
6780+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6781+
6782+ regs->u_regs[UREG_RETPC] = regs->pc;
6783+ regs->pc = dl_resolve;
6784+ regs->npc = dl_resolve+4;
6785+ return 3;
6786+ }
6787+ } while (0);
6788+#endif
6789+
6790+ return 1;
6791+}
6792+
6793+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6794+{
6795+ unsigned long i;
6796+
6797+ printk(KERN_ERR "PAX: bytes at PC: ");
6798+ for (i = 0; i < 8; i++) {
6799+ unsigned int c;
6800+ if (get_user(c, (unsigned int *)pc+i))
6801+ printk(KERN_CONT "???????? ");
6802+ else
6803+ printk(KERN_CONT "%08x ", c);
6804+ }
6805+ printk("\n");
6806+}
6807+#endif
6808+
6809 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6810 int text_fault)
6811 {
6812@@ -248,6 +522,24 @@ good_area:
6813 if (!(vma->vm_flags & VM_WRITE))
6814 goto bad_area;
6815 } else {
6816+
6817+#ifdef CONFIG_PAX_PAGEEXEC
6818+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6819+ up_read(&mm->mmap_sem);
6820+ switch (pax_handle_fetch_fault(regs)) {
6821+
6822+#ifdef CONFIG_PAX_EMUPLT
6823+ case 2:
6824+ case 3:
6825+ return;
6826+#endif
6827+
6828+ }
6829+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6830+ do_group_exit(SIGKILL);
6831+ }
6832+#endif
6833+
6834 /* Allow reads even for write-only mappings */
6835 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6836 goto bad_area;
6837diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6838index 1fe0429..8dd5dd5 100644
6839--- a/arch/sparc/mm/fault_64.c
6840+++ b/arch/sparc/mm/fault_64.c
6841@@ -21,6 +21,9 @@
6842 #include <linux/kprobes.h>
6843 #include <linux/kdebug.h>
6844 #include <linux/percpu.h>
6845+#include <linux/slab.h>
6846+#include <linux/pagemap.h>
6847+#include <linux/compiler.h>
6848
6849 #include <asm/page.h>
6850 #include <asm/pgtable.h>
6851@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6852 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6853 regs->tpc);
6854 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6855- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6856+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6857 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6858 dump_stack();
6859 unhandled_fault(regs->tpc, current, regs);
6860@@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6861 show_regs(regs);
6862 }
6863
6864+#ifdef CONFIG_PAX_PAGEEXEC
6865+#ifdef CONFIG_PAX_DLRESOLVE
6866+static void pax_emuplt_close(struct vm_area_struct *vma)
6867+{
6868+ vma->vm_mm->call_dl_resolve = 0UL;
6869+}
6870+
6871+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6872+{
6873+ unsigned int *kaddr;
6874+
6875+ vmf->page = alloc_page(GFP_HIGHUSER);
6876+ if (!vmf->page)
6877+ return VM_FAULT_OOM;
6878+
6879+ kaddr = kmap(vmf->page);
6880+ memset(kaddr, 0, PAGE_SIZE);
6881+ kaddr[0] = 0x9DE3BFA8U; /* save */
6882+ flush_dcache_page(vmf->page);
6883+ kunmap(vmf->page);
6884+ return VM_FAULT_MAJOR;
6885+}
6886+
6887+static const struct vm_operations_struct pax_vm_ops = {
6888+ .close = pax_emuplt_close,
6889+ .fault = pax_emuplt_fault
6890+};
6891+
6892+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6893+{
6894+ int ret;
6895+
6896+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6897+ vma->vm_mm = current->mm;
6898+ vma->vm_start = addr;
6899+ vma->vm_end = addr + PAGE_SIZE;
6900+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6901+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6902+ vma->vm_ops = &pax_vm_ops;
6903+
6904+ ret = insert_vm_struct(current->mm, vma);
6905+ if (ret)
6906+ return ret;
6907+
6908+ ++current->mm->total_vm;
6909+ return 0;
6910+}
6911+#endif
6912+
6913+/*
6914+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6915+ *
6916+ * returns 1 when task should be killed
6917+ * 2 when patched PLT trampoline was detected
6918+ * 3 when unpatched PLT trampoline was detected
6919+ */
6920+static int pax_handle_fetch_fault(struct pt_regs *regs)
6921+{
6922+
6923+#ifdef CONFIG_PAX_EMUPLT
6924+ int err;
6925+
6926+ do { /* PaX: patched PLT emulation #1 */
6927+ unsigned int sethi1, sethi2, jmpl;
6928+
6929+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6930+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6931+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6932+
6933+ if (err)
6934+ break;
6935+
6936+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6937+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6938+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6939+ {
6940+ unsigned long addr;
6941+
6942+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6943+ addr = regs->u_regs[UREG_G1];
6944+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6945+
6946+ if (test_thread_flag(TIF_32BIT))
6947+ addr &= 0xFFFFFFFFUL;
6948+
6949+ regs->tpc = addr;
6950+ regs->tnpc = addr+4;
6951+ return 2;
6952+ }
6953+ } while (0);
6954+
6955+ do { /* PaX: patched PLT emulation #2 */
6956+ unsigned int ba;
6957+
6958+ err = get_user(ba, (unsigned int *)regs->tpc);
6959+
6960+ if (err)
6961+ break;
6962+
6963+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6964+ unsigned long addr;
6965+
6966+ if ((ba & 0xFFC00000U) == 0x30800000U)
6967+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6968+ else
6969+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6970+
6971+ if (test_thread_flag(TIF_32BIT))
6972+ addr &= 0xFFFFFFFFUL;
6973+
6974+ regs->tpc = addr;
6975+ regs->tnpc = addr+4;
6976+ return 2;
6977+ }
6978+ } while (0);
6979+
6980+ do { /* PaX: patched PLT emulation #3 */
6981+ unsigned int sethi, bajmpl, nop;
6982+
6983+ err = get_user(sethi, (unsigned int *)regs->tpc);
6984+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6985+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6986+
6987+ if (err)
6988+ break;
6989+
6990+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6991+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6992+ nop == 0x01000000U)
6993+ {
6994+ unsigned long addr;
6995+
6996+ addr = (sethi & 0x003FFFFFU) << 10;
6997+ regs->u_regs[UREG_G1] = addr;
6998+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6999+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7000+ else
7001+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7002+
7003+ if (test_thread_flag(TIF_32BIT))
7004+ addr &= 0xFFFFFFFFUL;
7005+
7006+ regs->tpc = addr;
7007+ regs->tnpc = addr+4;
7008+ return 2;
7009+ }
7010+ } while (0);
7011+
7012+ do { /* PaX: patched PLT emulation #4 */
7013+ unsigned int sethi, mov1, call, mov2;
7014+
7015+ err = get_user(sethi, (unsigned int *)regs->tpc);
7016+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
7017+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
7018+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
7019+
7020+ if (err)
7021+ break;
7022+
7023+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7024+ mov1 == 0x8210000FU &&
7025+ (call & 0xC0000000U) == 0x40000000U &&
7026+ mov2 == 0x9E100001U)
7027+ {
7028+ unsigned long addr;
7029+
7030+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7031+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7032+
7033+ if (test_thread_flag(TIF_32BIT))
7034+ addr &= 0xFFFFFFFFUL;
7035+
7036+ regs->tpc = addr;
7037+ regs->tnpc = addr+4;
7038+ return 2;
7039+ }
7040+ } while (0);
7041+
7042+ do { /* PaX: patched PLT emulation #5 */
7043+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7044+
7045+ err = get_user(sethi, (unsigned int *)regs->tpc);
7046+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7047+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7048+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7049+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7050+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7051+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7052+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7053+
7054+ if (err)
7055+ break;
7056+
7057+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7058+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7059+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7060+ (or1 & 0xFFFFE000U) == 0x82106000U &&
7061+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7062+ sllx == 0x83287020U &&
7063+ jmpl == 0x81C04005U &&
7064+ nop == 0x01000000U)
7065+ {
7066+ unsigned long addr;
7067+
7068+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7069+ regs->u_regs[UREG_G1] <<= 32;
7070+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7071+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7072+ regs->tpc = addr;
7073+ regs->tnpc = addr+4;
7074+ return 2;
7075+ }
7076+ } while (0);
7077+
7078+ do { /* PaX: patched PLT emulation #6 */
7079+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7080+
7081+ err = get_user(sethi, (unsigned int *)regs->tpc);
7082+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7083+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7084+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7085+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7086+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7087+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7088+
7089+ if (err)
7090+ break;
7091+
7092+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7093+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7094+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7095+ sllx == 0x83287020U &&
7096+ (or & 0xFFFFE000U) == 0x8A116000U &&
7097+ jmpl == 0x81C04005U &&
7098+ nop == 0x01000000U)
7099+ {
7100+ unsigned long addr;
7101+
7102+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7103+ regs->u_regs[UREG_G1] <<= 32;
7104+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7105+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7106+ regs->tpc = addr;
7107+ regs->tnpc = addr+4;
7108+ return 2;
7109+ }
7110+ } while (0);
7111+
7112+ do { /* PaX: unpatched PLT emulation step 1 */
7113+ unsigned int sethi, ba, nop;
7114+
7115+ err = get_user(sethi, (unsigned int *)regs->tpc);
7116+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7117+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7118+
7119+ if (err)
7120+ break;
7121+
7122+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7123+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7124+ nop == 0x01000000U)
7125+ {
7126+ unsigned long addr;
7127+ unsigned int save, call;
7128+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7129+
7130+ if ((ba & 0xFFC00000U) == 0x30800000U)
7131+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7132+ else
7133+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7134+
7135+ if (test_thread_flag(TIF_32BIT))
7136+ addr &= 0xFFFFFFFFUL;
7137+
7138+ err = get_user(save, (unsigned int *)addr);
7139+ err |= get_user(call, (unsigned int *)(addr+4));
7140+ err |= get_user(nop, (unsigned int *)(addr+8));
7141+ if (err)
7142+ break;
7143+
7144+#ifdef CONFIG_PAX_DLRESOLVE
7145+ if (save == 0x9DE3BFA8U &&
7146+ (call & 0xC0000000U) == 0x40000000U &&
7147+ nop == 0x01000000U)
7148+ {
7149+ struct vm_area_struct *vma;
7150+ unsigned long call_dl_resolve;
7151+
7152+ down_read(&current->mm->mmap_sem);
7153+ call_dl_resolve = current->mm->call_dl_resolve;
7154+ up_read(&current->mm->mmap_sem);
7155+ if (likely(call_dl_resolve))
7156+ goto emulate;
7157+
7158+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7159+
7160+ down_write(&current->mm->mmap_sem);
7161+ if (current->mm->call_dl_resolve) {
7162+ call_dl_resolve = current->mm->call_dl_resolve;
7163+ up_write(&current->mm->mmap_sem);
7164+ if (vma)
7165+ kmem_cache_free(vm_area_cachep, vma);
7166+ goto emulate;
7167+ }
7168+
7169+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7170+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7171+ up_write(&current->mm->mmap_sem);
7172+ if (vma)
7173+ kmem_cache_free(vm_area_cachep, vma);
7174+ return 1;
7175+ }
7176+
7177+ if (pax_insert_vma(vma, call_dl_resolve)) {
7178+ up_write(&current->mm->mmap_sem);
7179+ kmem_cache_free(vm_area_cachep, vma);
7180+ return 1;
7181+ }
7182+
7183+ current->mm->call_dl_resolve = call_dl_resolve;
7184+ up_write(&current->mm->mmap_sem);
7185+
7186+emulate:
7187+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7188+ regs->tpc = call_dl_resolve;
7189+ regs->tnpc = addr+4;
7190+ return 3;
7191+ }
7192+#endif
7193+
7194+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7195+ if ((save & 0xFFC00000U) == 0x05000000U &&
7196+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7197+ nop == 0x01000000U)
7198+ {
7199+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7200+ regs->u_regs[UREG_G2] = addr + 4;
7201+ addr = (save & 0x003FFFFFU) << 10;
7202+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7203+
7204+ if (test_thread_flag(TIF_32BIT))
7205+ addr &= 0xFFFFFFFFUL;
7206+
7207+ regs->tpc = addr;
7208+ regs->tnpc = addr+4;
7209+ return 3;
7210+ }
7211+
7212+ /* PaX: 64-bit PLT stub */
7213+ err = get_user(sethi1, (unsigned int *)addr);
7214+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7215+ err |= get_user(or1, (unsigned int *)(addr+8));
7216+ err |= get_user(or2, (unsigned int *)(addr+12));
7217+ err |= get_user(sllx, (unsigned int *)(addr+16));
7218+ err |= get_user(add, (unsigned int *)(addr+20));
7219+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7220+ err |= get_user(nop, (unsigned int *)(addr+28));
7221+ if (err)
7222+ break;
7223+
7224+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7225+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7226+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7227+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7228+ sllx == 0x89293020U &&
7229+ add == 0x8A010005U &&
7230+ jmpl == 0x89C14000U &&
7231+ nop == 0x01000000U)
7232+ {
7233+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7234+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7235+ regs->u_regs[UREG_G4] <<= 32;
7236+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7237+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7238+ regs->u_regs[UREG_G4] = addr + 24;
7239+ addr = regs->u_regs[UREG_G5];
7240+ regs->tpc = addr;
7241+ regs->tnpc = addr+4;
7242+ return 3;
7243+ }
7244+ }
7245+ } while (0);
7246+
7247+#ifdef CONFIG_PAX_DLRESOLVE
7248+ do { /* PaX: unpatched PLT emulation step 2 */
7249+ unsigned int save, call, nop;
7250+
7251+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7252+ err |= get_user(call, (unsigned int *)regs->tpc);
7253+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7254+ if (err)
7255+ break;
7256+
7257+ if (save == 0x9DE3BFA8U &&
7258+ (call & 0xC0000000U) == 0x40000000U &&
7259+ nop == 0x01000000U)
7260+ {
7261+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7262+
7263+ if (test_thread_flag(TIF_32BIT))
7264+ dl_resolve &= 0xFFFFFFFFUL;
7265+
7266+ regs->u_regs[UREG_RETPC] = regs->tpc;
7267+ regs->tpc = dl_resolve;
7268+ regs->tnpc = dl_resolve+4;
7269+ return 3;
7270+ }
7271+ } while (0);
7272+#endif
7273+
7274+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7275+ unsigned int sethi, ba, nop;
7276+
7277+ err = get_user(sethi, (unsigned int *)regs->tpc);
7278+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7279+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7280+
7281+ if (err)
7282+ break;
7283+
7284+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7285+ (ba & 0xFFF00000U) == 0x30600000U &&
7286+ nop == 0x01000000U)
7287+ {
7288+ unsigned long addr;
7289+
7290+ addr = (sethi & 0x003FFFFFU) << 10;
7291+ regs->u_regs[UREG_G1] = addr;
7292+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7293+
7294+ if (test_thread_flag(TIF_32BIT))
7295+ addr &= 0xFFFFFFFFUL;
7296+
7297+ regs->tpc = addr;
7298+ regs->tnpc = addr+4;
7299+ return 2;
7300+ }
7301+ } while (0);
7302+
7303+#endif
7304+
7305+ return 1;
7306+}
7307+
7308+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7309+{
7310+ unsigned long i;
7311+
7312+ printk(KERN_ERR "PAX: bytes at PC: ");
7313+ for (i = 0; i < 8; i++) {
7314+ unsigned int c;
7315+ if (get_user(c, (unsigned int *)pc+i))
7316+ printk(KERN_CONT "???????? ");
7317+ else
7318+ printk(KERN_CONT "%08x ", c);
7319+ }
7320+ printk("\n");
7321+}
7322+#endif
7323+
7324 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7325 {
7326 struct mm_struct *mm = current->mm;
7327@@ -343,6 +806,29 @@ retry:
7328 if (!vma)
7329 goto bad_area;
7330
7331+#ifdef CONFIG_PAX_PAGEEXEC
7332+ /* PaX: detect ITLB misses on non-exec pages */
7333+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7334+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7335+ {
7336+ if (address != regs->tpc)
7337+ goto good_area;
7338+
7339+ up_read(&mm->mmap_sem);
7340+ switch (pax_handle_fetch_fault(regs)) {
7341+
7342+#ifdef CONFIG_PAX_EMUPLT
7343+ case 2:
7344+ case 3:
7345+ return;
7346+#endif
7347+
7348+ }
7349+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7350+ do_group_exit(SIGKILL);
7351+ }
7352+#endif
7353+
7354 /* Pure DTLB misses do not tell us whether the fault causing
7355 * load/store/atomic was a write or not, it only says that there
7356 * was no match. So in such a case we (carefully) read the
7357diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7358index 07e1453..0a7d9e9 100644
7359--- a/arch/sparc/mm/hugetlbpage.c
7360+++ b/arch/sparc/mm/hugetlbpage.c
7361@@ -67,7 +67,7 @@ full_search:
7362 }
7363 return -ENOMEM;
7364 }
7365- if (likely(!vma || addr + len <= vma->vm_start)) {
7366+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7367 /*
7368 * Remember the place where we stopped the search:
7369 */
7370@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7371 /* make sure it can fit in the remaining address space */
7372 if (likely(addr > len)) {
7373 vma = find_vma(mm, addr-len);
7374- if (!vma || addr <= vma->vm_start) {
7375+ if (check_heap_stack_gap(vma, addr - len, len)) {
7376 /* remember the address as a hint for next time */
7377 return (mm->free_area_cache = addr-len);
7378 }
7379@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7380 if (unlikely(mm->mmap_base < len))
7381 goto bottomup;
7382
7383- addr = (mm->mmap_base-len) & HPAGE_MASK;
7384+ addr = mm->mmap_base - len;
7385
7386 do {
7387+ addr &= HPAGE_MASK;
7388 /*
7389 * Lookup failure means no vma is above this address,
7390 * else if new region fits below vma->vm_start,
7391 * return with success:
7392 */
7393 vma = find_vma(mm, addr);
7394- if (likely(!vma || addr+len <= vma->vm_start)) {
7395+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7396 /* remember the address as a hint for next time */
7397 return (mm->free_area_cache = addr);
7398 }
7399@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7400 mm->cached_hole_size = vma->vm_start - addr;
7401
7402 /* try just below the current vma->vm_start */
7403- addr = (vma->vm_start-len) & HPAGE_MASK;
7404- } while (likely(len < vma->vm_start));
7405+ addr = skip_heap_stack_gap(vma, len);
7406+ } while (!IS_ERR_VALUE(addr));
7407
7408 bottomup:
7409 /*
7410@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7411 if (addr) {
7412 addr = ALIGN(addr, HPAGE_SIZE);
7413 vma = find_vma(mm, addr);
7414- if (task_size - len >= addr &&
7415- (!vma || addr + len <= vma->vm_start))
7416+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7417 return addr;
7418 }
7419 if (mm->get_unmapped_area == arch_get_unmapped_area)
7420diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7421index f4500c6..889656c 100644
7422--- a/arch/tile/include/asm/atomic_64.h
7423+++ b/arch/tile/include/asm/atomic_64.h
7424@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7425
7426 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7427
7428+#define atomic64_read_unchecked(v) atomic64_read(v)
7429+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7430+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7431+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7432+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7433+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7434+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7435+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7436+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7437+
7438 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7439 #define smp_mb__before_atomic_dec() smp_mb()
7440 #define smp_mb__after_atomic_dec() smp_mb()
7441diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7442index 392e533..536b092 100644
7443--- a/arch/tile/include/asm/cache.h
7444+++ b/arch/tile/include/asm/cache.h
7445@@ -15,11 +15,12 @@
7446 #ifndef _ASM_TILE_CACHE_H
7447 #define _ASM_TILE_CACHE_H
7448
7449+#include <linux/const.h>
7450 #include <arch/chip.h>
7451
7452 /* bytes per L1 data cache line */
7453 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7454-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7455+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7456
7457 /* bytes per L2 cache line */
7458 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7459diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7460index 9ab078a..d6635c2 100644
7461--- a/arch/tile/include/asm/uaccess.h
7462+++ b/arch/tile/include/asm/uaccess.h
7463@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7464 const void __user *from,
7465 unsigned long n)
7466 {
7467- int sz = __compiletime_object_size(to);
7468+ size_t sz = __compiletime_object_size(to);
7469
7470- if (likely(sz == -1 || sz >= n))
7471+ if (likely(sz == (size_t)-1 || sz >= n))
7472 n = _copy_from_user(to, from, n);
7473 else
7474 copy_from_user_overflow();
7475diff --git a/arch/um/Makefile b/arch/um/Makefile
7476index 0970910..9f65c40 100644
7477--- a/arch/um/Makefile
7478+++ b/arch/um/Makefile
7479@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7480 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7481 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7482
7483+ifdef CONSTIFY_PLUGIN
7484+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7485+endif
7486+
7487 #This will adjust *FLAGS accordingly to the platform.
7488 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7489
7490diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7491index 19e1bdd..3665b77 100644
7492--- a/arch/um/include/asm/cache.h
7493+++ b/arch/um/include/asm/cache.h
7494@@ -1,6 +1,7 @@
7495 #ifndef __UM_CACHE_H
7496 #define __UM_CACHE_H
7497
7498+#include <linux/const.h>
7499
7500 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7501 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7502@@ -12,6 +13,6 @@
7503 # define L1_CACHE_SHIFT 5
7504 #endif
7505
7506-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7507+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7508
7509 #endif
7510diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7511index 6c03acd..a5e0215 100644
7512--- a/arch/um/include/asm/kmap_types.h
7513+++ b/arch/um/include/asm/kmap_types.h
7514@@ -23,6 +23,7 @@ enum km_type {
7515 KM_IRQ1,
7516 KM_SOFTIRQ0,
7517 KM_SOFTIRQ1,
7518+ KM_CLEARPAGE,
7519 KM_TYPE_NR
7520 };
7521
7522diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7523index 7cfc3ce..cbd1a58 100644
7524--- a/arch/um/include/asm/page.h
7525+++ b/arch/um/include/asm/page.h
7526@@ -14,6 +14,9 @@
7527 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7528 #define PAGE_MASK (~(PAGE_SIZE-1))
7529
7530+#define ktla_ktva(addr) (addr)
7531+#define ktva_ktla(addr) (addr)
7532+
7533 #ifndef __ASSEMBLY__
7534
7535 struct page;
7536diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7537index 0032f92..cd151e0 100644
7538--- a/arch/um/include/asm/pgtable-3level.h
7539+++ b/arch/um/include/asm/pgtable-3level.h
7540@@ -58,6 +58,7 @@
7541 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7542 #define pud_populate(mm, pud, pmd) \
7543 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7544+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7545
7546 #ifdef CONFIG_64BIT
7547 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7548diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7549index ccb9a9d..cc425bb 100644
7550--- a/arch/um/kernel/process.c
7551+++ b/arch/um/kernel/process.c
7552@@ -407,22 +407,6 @@ int singlestepping(void * t)
7553 return 2;
7554 }
7555
7556-/*
7557- * Only x86 and x86_64 have an arch_align_stack().
7558- * All other arches have "#define arch_align_stack(x) (x)"
7559- * in their asm/system.h
7560- * As this is included in UML from asm-um/system-generic.h,
7561- * we can use it to behave as the subarch does.
7562- */
7563-#ifndef arch_align_stack
7564-unsigned long arch_align_stack(unsigned long sp)
7565-{
7566- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7567- sp -= get_random_int() % 8192;
7568- return sp & ~0xf;
7569-}
7570-#endif
7571-
7572 unsigned long get_wchan(struct task_struct *p)
7573 {
7574 unsigned long stack_page, sp, ip;
7575diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7576index ad8f795..2c7eec6 100644
7577--- a/arch/unicore32/include/asm/cache.h
7578+++ b/arch/unicore32/include/asm/cache.h
7579@@ -12,8 +12,10 @@
7580 #ifndef __UNICORE_CACHE_H__
7581 #define __UNICORE_CACHE_H__
7582
7583-#define L1_CACHE_SHIFT (5)
7584-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7585+#include <linux/const.h>
7586+
7587+#define L1_CACHE_SHIFT 5
7588+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7589
7590 /*
7591 * Memory returned by kmalloc() may be used for DMA, so we must make
7592diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7593index c70684f..698fa4b 100644
7594--- a/arch/x86/Kconfig
7595+++ b/arch/x86/Kconfig
7596@@ -218,7 +218,7 @@ config X86_HT
7597
7598 config X86_32_LAZY_GS
7599 def_bool y
7600- depends on X86_32 && !CC_STACKPROTECTOR
7601+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7602
7603 config ARCH_HWEIGHT_CFLAGS
7604 string
7605@@ -1047,7 +1047,7 @@ choice
7606
7607 config NOHIGHMEM
7608 bool "off"
7609- depends on !X86_NUMAQ
7610+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7611 ---help---
7612 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7613 However, the address space of 32-bit x86 processors is only 4
7614@@ -1084,7 +1084,7 @@ config NOHIGHMEM
7615
7616 config HIGHMEM4G
7617 bool "4GB"
7618- depends on !X86_NUMAQ
7619+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7620 ---help---
7621 Select this if you have a 32-bit processor and between 1 and 4
7622 gigabytes of physical RAM.
7623@@ -1138,7 +1138,7 @@ config PAGE_OFFSET
7624 hex
7625 default 0xB0000000 if VMSPLIT_3G_OPT
7626 default 0x80000000 if VMSPLIT_2G
7627- default 0x78000000 if VMSPLIT_2G_OPT
7628+ default 0x70000000 if VMSPLIT_2G_OPT
7629 default 0x40000000 if VMSPLIT_1G
7630 default 0xC0000000
7631 depends on X86_32
7632@@ -1526,6 +1526,7 @@ config SECCOMP
7633
7634 config CC_STACKPROTECTOR
7635 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7636+ depends on X86_64 || !PAX_MEMORY_UDEREF
7637 ---help---
7638 This option turns on the -fstack-protector GCC feature. This
7639 feature puts, at the beginning of functions, a canary value on
7640@@ -1583,6 +1584,7 @@ config KEXEC_JUMP
7641 config PHYSICAL_START
7642 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7643 default "0x1000000"
7644+ range 0x400000 0x40000000
7645 ---help---
7646 This gives the physical address where the kernel is loaded.
7647
7648@@ -1646,6 +1648,7 @@ config X86_NEED_RELOCS
7649 config PHYSICAL_ALIGN
7650 hex "Alignment value to which kernel should be aligned" if X86_32
7651 default "0x1000000"
7652+ range 0x400000 0x1000000 if PAX_KERNEXEC
7653 range 0x2000 0x1000000
7654 ---help---
7655 This value puts the alignment restrictions on physical address
7656@@ -1677,9 +1680,10 @@ config HOTPLUG_CPU
7657 Say N if you want to disable CPU hotplug.
7658
7659 config COMPAT_VDSO
7660- def_bool y
7661+ def_bool n
7662 prompt "Compat VDSO support"
7663 depends on X86_32 || IA32_EMULATION
7664+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7665 ---help---
7666 Map the 32-bit VDSO to the predictable old-style address too.
7667
7668diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7669index 706e12e..62e4feb 100644
7670--- a/arch/x86/Kconfig.cpu
7671+++ b/arch/x86/Kconfig.cpu
7672@@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7673
7674 config X86_F00F_BUG
7675 def_bool y
7676- depends on M586MMX || M586TSC || M586 || M486 || M386
7677+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7678
7679 config X86_INVD_BUG
7680 def_bool y
7681@@ -358,7 +358,7 @@ config X86_POPAD_OK
7682
7683 config X86_ALIGNMENT_16
7684 def_bool y
7685- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7686+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7687
7688 config X86_INTEL_USERCOPY
7689 def_bool y
7690@@ -404,7 +404,7 @@ config X86_CMPXCHG64
7691 # generates cmov.
7692 config X86_CMOV
7693 def_bool y
7694- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7695+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7696
7697 config X86_MINIMUM_CPU_FAMILY
7698 int
7699diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7700index e46c214..ab62fd1 100644
7701--- a/arch/x86/Kconfig.debug
7702+++ b/arch/x86/Kconfig.debug
7703@@ -84,7 +84,7 @@ config X86_PTDUMP
7704 config DEBUG_RODATA
7705 bool "Write protect kernel read-only data structures"
7706 default y
7707- depends on DEBUG_KERNEL
7708+ depends on DEBUG_KERNEL && BROKEN
7709 ---help---
7710 Mark the kernel read-only data as write-protected in the pagetables,
7711 in order to catch accidental (and incorrect) writes to such const
7712@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7713
7714 config DEBUG_SET_MODULE_RONX
7715 bool "Set loadable kernel module data as NX and text as RO"
7716- depends on MODULES
7717+ depends on MODULES && BROKEN
7718 ---help---
7719 This option helps catch unintended modifications to loadable
7720 kernel module's text and read-only data. It also prevents execution
7721@@ -275,7 +275,7 @@ config OPTIMIZE_INLINING
7722
7723 config DEBUG_STRICT_USER_COPY_CHECKS
7724 bool "Strict copy size checks"
7725- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7726+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7727 ---help---
7728 Enabling this option turns a certain set of sanity checks for user
7729 copy operations into compile time failures.
7730diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7731index 1f25214..39422b3 100644
7732--- a/arch/x86/Makefile
7733+++ b/arch/x86/Makefile
7734@@ -46,6 +46,7 @@ else
7735 UTS_MACHINE := x86_64
7736 CHECKFLAGS += -D__x86_64__ -m64
7737
7738+ biarch := $(call cc-option,-m64)
7739 KBUILD_AFLAGS += -m64
7740 KBUILD_CFLAGS += -m64
7741
7742@@ -222,3 +223,12 @@ define archhelp
7743 echo ' FDARGS="..." arguments for the booted kernel'
7744 echo ' FDINITRD=file initrd for the booted kernel'
7745 endef
7746+
7747+define OLD_LD
7748+
7749+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7750+*** Please upgrade your binutils to 2.18 or newer
7751+endef
7752+
7753+archprepare:
7754+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7755diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7756index 5a747dd..00bece7 100644
7757--- a/arch/x86/boot/Makefile
7758+++ b/arch/x86/boot/Makefile
7759@@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7760 $(call cc-option, -fno-stack-protector) \
7761 $(call cc-option, -mpreferred-stack-boundary=2)
7762 KBUILD_CFLAGS += $(call cc-option, -m32)
7763+ifdef CONSTIFY_PLUGIN
7764+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7765+endif
7766 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7767 GCOV_PROFILE := n
7768
7769diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7770index 878e4b9..20537ab 100644
7771--- a/arch/x86/boot/bitops.h
7772+++ b/arch/x86/boot/bitops.h
7773@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7774 u8 v;
7775 const u32 *p = (const u32 *)addr;
7776
7777- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7778+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7779 return v;
7780 }
7781
7782@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7783
7784 static inline void set_bit(int nr, void *addr)
7785 {
7786- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7787+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7788 }
7789
7790 #endif /* BOOT_BITOPS_H */
7791diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7792index 18997e5..83d9c67 100644
7793--- a/arch/x86/boot/boot.h
7794+++ b/arch/x86/boot/boot.h
7795@@ -85,7 +85,7 @@ static inline void io_delay(void)
7796 static inline u16 ds(void)
7797 {
7798 u16 seg;
7799- asm("movw %%ds,%0" : "=rm" (seg));
7800+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7801 return seg;
7802 }
7803
7804@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7805 static inline int memcmp(const void *s1, const void *s2, size_t len)
7806 {
7807 u8 diff;
7808- asm("repe; cmpsb; setnz %0"
7809+ asm volatile("repe; cmpsb; setnz %0"
7810 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7811 return diff;
7812 }
7813diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7814index e398bb5..80fc805 100644
7815--- a/arch/x86/boot/compressed/Makefile
7816+++ b/arch/x86/boot/compressed/Makefile
7817@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7818 KBUILD_CFLAGS += $(cflags-y)
7819 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7820 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7821+ifdef CONSTIFY_PLUGIN
7822+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7823+endif
7824
7825 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7826 GCOV_PROFILE := n
7827diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7828index 4e85f5f..39fa641 100644
7829--- a/arch/x86/boot/compressed/eboot.c
7830+++ b/arch/x86/boot/compressed/eboot.c
7831@@ -142,7 +142,6 @@ again:
7832 *addr = max_addr;
7833 }
7834
7835-free_pool:
7836 efi_call_phys1(sys_table->boottime->free_pool, map);
7837
7838 fail:
7839@@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7840 if (i == map_size / desc_size)
7841 status = EFI_NOT_FOUND;
7842
7843-free_pool:
7844 efi_call_phys1(sys_table->boottime->free_pool, map);
7845 fail:
7846 return status;
7847diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7848index c85e3ac..6f5aa80 100644
7849--- a/arch/x86/boot/compressed/head_32.S
7850+++ b/arch/x86/boot/compressed/head_32.S
7851@@ -106,7 +106,7 @@ preferred_addr:
7852 notl %eax
7853 andl %eax, %ebx
7854 #else
7855- movl $LOAD_PHYSICAL_ADDR, %ebx
7856+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7857 #endif
7858
7859 /* Target address to relocate to for decompression */
7860@@ -192,7 +192,7 @@ relocated:
7861 * and where it was actually loaded.
7862 */
7863 movl %ebp, %ebx
7864- subl $LOAD_PHYSICAL_ADDR, %ebx
7865+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7866 jz 2f /* Nothing to be done if loaded at compiled addr. */
7867 /*
7868 * Process relocations.
7869@@ -200,8 +200,7 @@ relocated:
7870
7871 1: subl $4, %edi
7872 movl (%edi), %ecx
7873- testl %ecx, %ecx
7874- jz 2f
7875+ jecxz 2f
7876 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7877 jmp 1b
7878 2:
7879diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7880index 87e03a1..0d94c76 100644
7881--- a/arch/x86/boot/compressed/head_64.S
7882+++ b/arch/x86/boot/compressed/head_64.S
7883@@ -91,7 +91,7 @@ ENTRY(startup_32)
7884 notl %eax
7885 andl %eax, %ebx
7886 #else
7887- movl $LOAD_PHYSICAL_ADDR, %ebx
7888+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7889 #endif
7890
7891 /* Target address to relocate to for decompression */
7892@@ -263,7 +263,7 @@ preferred_addr:
7893 notq %rax
7894 andq %rax, %rbp
7895 #else
7896- movq $LOAD_PHYSICAL_ADDR, %rbp
7897+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7898 #endif
7899
7900 /* Target address to relocate to for decompression */
7901diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7902index 7116dcb..d9ae1d7 100644
7903--- a/arch/x86/boot/compressed/misc.c
7904+++ b/arch/x86/boot/compressed/misc.c
7905@@ -310,7 +310,7 @@ static void parse_elf(void *output)
7906 case PT_LOAD:
7907 #ifdef CONFIG_RELOCATABLE
7908 dest = output;
7909- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7910+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7911 #else
7912 dest = (void *)(phdr->p_paddr);
7913 #endif
7914@@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7915 error("Destination address too large");
7916 #endif
7917 #ifndef CONFIG_RELOCATABLE
7918- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7919+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7920 error("Wrong destination address");
7921 #endif
7922
7923diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7924index 4d3ff03..e4972ff 100644
7925--- a/arch/x86/boot/cpucheck.c
7926+++ b/arch/x86/boot/cpucheck.c
7927@@ -74,7 +74,7 @@ static int has_fpu(void)
7928 u16 fcw = -1, fsw = -1;
7929 u32 cr0;
7930
7931- asm("movl %%cr0,%0" : "=r" (cr0));
7932+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
7933 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7934 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7935 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7936@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7937 {
7938 u32 f0, f1;
7939
7940- asm("pushfl ; "
7941+ asm volatile("pushfl ; "
7942 "pushfl ; "
7943 "popl %0 ; "
7944 "movl %0,%1 ; "
7945@@ -115,7 +115,7 @@ static void get_flags(void)
7946 set_bit(X86_FEATURE_FPU, cpu.flags);
7947
7948 if (has_eflag(X86_EFLAGS_ID)) {
7949- asm("cpuid"
7950+ asm volatile("cpuid"
7951 : "=a" (max_intel_level),
7952 "=b" (cpu_vendor[0]),
7953 "=d" (cpu_vendor[1]),
7954@@ -124,7 +124,7 @@ static void get_flags(void)
7955
7956 if (max_intel_level >= 0x00000001 &&
7957 max_intel_level <= 0x0000ffff) {
7958- asm("cpuid"
7959+ asm volatile("cpuid"
7960 : "=a" (tfms),
7961 "=c" (cpu.flags[4]),
7962 "=d" (cpu.flags[0])
7963@@ -136,7 +136,7 @@ static void get_flags(void)
7964 cpu.model += ((tfms >> 16) & 0xf) << 4;
7965 }
7966
7967- asm("cpuid"
7968+ asm volatile("cpuid"
7969 : "=a" (max_amd_level)
7970 : "a" (0x80000000)
7971 : "ebx", "ecx", "edx");
7972@@ -144,7 +144,7 @@ static void get_flags(void)
7973 if (max_amd_level >= 0x80000001 &&
7974 max_amd_level <= 0x8000ffff) {
7975 u32 eax = 0x80000001;
7976- asm("cpuid"
7977+ asm volatile("cpuid"
7978 : "+a" (eax),
7979 "=c" (cpu.flags[6]),
7980 "=d" (cpu.flags[1])
7981@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7982 u32 ecx = MSR_K7_HWCR;
7983 u32 eax, edx;
7984
7985- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7986+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7987 eax &= ~(1 << 15);
7988- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7989+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7990
7991 get_flags(); /* Make sure it really did something */
7992 err = check_flags();
7993@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7994 u32 ecx = MSR_VIA_FCR;
7995 u32 eax, edx;
7996
7997- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7998+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7999 eax |= (1<<1)|(1<<7);
8000- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8001+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8002
8003 set_bit(X86_FEATURE_CX8, cpu.flags);
8004 err = check_flags();
8005@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8006 u32 eax, edx;
8007 u32 level = 1;
8008
8009- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8010- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8011- asm("cpuid"
8012+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8013+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8014+ asm volatile("cpuid"
8015 : "+a" (level), "=d" (cpu.flags[0])
8016 : : "ecx", "ebx");
8017- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8018+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8019
8020 err = check_flags();
8021 }
8022diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8023index efe5acf..22a3784 100644
8024--- a/arch/x86/boot/header.S
8025+++ b/arch/x86/boot/header.S
8026@@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
8027 # single linked list of
8028 # struct setup_data
8029
8030-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8031+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8032
8033 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8034+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
8035+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
8036+#else
8037 #define VO_INIT_SIZE (VO__end - VO__text)
8038+#endif
8039 #if ZO_INIT_SIZE > VO_INIT_SIZE
8040 #define INIT_SIZE ZO_INIT_SIZE
8041 #else
8042diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8043index db75d07..8e6d0af 100644
8044--- a/arch/x86/boot/memory.c
8045+++ b/arch/x86/boot/memory.c
8046@@ -19,7 +19,7 @@
8047
8048 static int detect_memory_e820(void)
8049 {
8050- int count = 0;
8051+ unsigned int count = 0;
8052 struct biosregs ireg, oreg;
8053 struct e820entry *desc = boot_params.e820_map;
8054 static struct e820entry buf; /* static so it is zeroed */
8055diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8056index 11e8c6e..fdbb1ed 100644
8057--- a/arch/x86/boot/video-vesa.c
8058+++ b/arch/x86/boot/video-vesa.c
8059@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8060
8061 boot_params.screen_info.vesapm_seg = oreg.es;
8062 boot_params.screen_info.vesapm_off = oreg.di;
8063+ boot_params.screen_info.vesapm_size = oreg.cx;
8064 }
8065
8066 /*
8067diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8068index 43eda28..5ab5fdb 100644
8069--- a/arch/x86/boot/video.c
8070+++ b/arch/x86/boot/video.c
8071@@ -96,7 +96,7 @@ static void store_mode_params(void)
8072 static unsigned int get_entry(void)
8073 {
8074 char entry_buf[4];
8075- int i, len = 0;
8076+ unsigned int i, len = 0;
8077 int key;
8078 unsigned int v;
8079
8080diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8081index 5b577d5..3c1fed4 100644
8082--- a/arch/x86/crypto/aes-x86_64-asm_64.S
8083+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8084@@ -8,6 +8,8 @@
8085 * including this sentence is retained in full.
8086 */
8087
8088+#include <asm/alternative-asm.h>
8089+
8090 .extern crypto_ft_tab
8091 .extern crypto_it_tab
8092 .extern crypto_fl_tab
8093@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8094 je B192; \
8095 leaq 32(r9),r9;
8096
8097+#define ret pax_force_retaddr 0, 1; ret
8098+
8099 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8100 movq r1,r2; \
8101 movq r3,r4; \
8102diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8103index 3470624..201259d 100644
8104--- a/arch/x86/crypto/aesni-intel_asm.S
8105+++ b/arch/x86/crypto/aesni-intel_asm.S
8106@@ -31,6 +31,7 @@
8107
8108 #include <linux/linkage.h>
8109 #include <asm/inst.h>
8110+#include <asm/alternative-asm.h>
8111
8112 #ifdef __x86_64__
8113 .data
8114@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8115 pop %r14
8116 pop %r13
8117 pop %r12
8118+ pax_force_retaddr 0, 1
8119 ret
8120+ENDPROC(aesni_gcm_dec)
8121
8122
8123 /*****************************************************************************
8124@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8125 pop %r14
8126 pop %r13
8127 pop %r12
8128+ pax_force_retaddr 0, 1
8129 ret
8130+ENDPROC(aesni_gcm_enc)
8131
8132 #endif
8133
8134@@ -1714,6 +1719,7 @@ _key_expansion_256a:
8135 pxor %xmm1, %xmm0
8136 movaps %xmm0, (TKEYP)
8137 add $0x10, TKEYP
8138+ pax_force_retaddr_bts
8139 ret
8140
8141 .align 4
8142@@ -1738,6 +1744,7 @@ _key_expansion_192a:
8143 shufps $0b01001110, %xmm2, %xmm1
8144 movaps %xmm1, 0x10(TKEYP)
8145 add $0x20, TKEYP
8146+ pax_force_retaddr_bts
8147 ret
8148
8149 .align 4
8150@@ -1757,6 +1764,7 @@ _key_expansion_192b:
8151
8152 movaps %xmm0, (TKEYP)
8153 add $0x10, TKEYP
8154+ pax_force_retaddr_bts
8155 ret
8156
8157 .align 4
8158@@ -1769,6 +1777,7 @@ _key_expansion_256b:
8159 pxor %xmm1, %xmm2
8160 movaps %xmm2, (TKEYP)
8161 add $0x10, TKEYP
8162+ pax_force_retaddr_bts
8163 ret
8164
8165 /*
8166@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8167 #ifndef __x86_64__
8168 popl KEYP
8169 #endif
8170+ pax_force_retaddr 0, 1
8171 ret
8172+ENDPROC(aesni_set_key)
8173
8174 /*
8175 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8176@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8177 popl KLEN
8178 popl KEYP
8179 #endif
8180+ pax_force_retaddr 0, 1
8181 ret
8182+ENDPROC(aesni_enc)
8183
8184 /*
8185 * _aesni_enc1: internal ABI
8186@@ -1959,6 +1972,7 @@ _aesni_enc1:
8187 AESENC KEY STATE
8188 movaps 0x70(TKEYP), KEY
8189 AESENCLAST KEY STATE
8190+ pax_force_retaddr_bts
8191 ret
8192
8193 /*
8194@@ -2067,6 +2081,7 @@ _aesni_enc4:
8195 AESENCLAST KEY STATE2
8196 AESENCLAST KEY STATE3
8197 AESENCLAST KEY STATE4
8198+ pax_force_retaddr_bts
8199 ret
8200
8201 /*
8202@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8203 popl KLEN
8204 popl KEYP
8205 #endif
8206+ pax_force_retaddr 0, 1
8207 ret
8208+ENDPROC(aesni_dec)
8209
8210 /*
8211 * _aesni_dec1: internal ABI
8212@@ -2146,6 +2163,7 @@ _aesni_dec1:
8213 AESDEC KEY STATE
8214 movaps 0x70(TKEYP), KEY
8215 AESDECLAST KEY STATE
8216+ pax_force_retaddr_bts
8217 ret
8218
8219 /*
8220@@ -2254,6 +2272,7 @@ _aesni_dec4:
8221 AESDECLAST KEY STATE2
8222 AESDECLAST KEY STATE3
8223 AESDECLAST KEY STATE4
8224+ pax_force_retaddr_bts
8225 ret
8226
8227 /*
8228@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8229 popl KEYP
8230 popl LEN
8231 #endif
8232+ pax_force_retaddr 0, 1
8233 ret
8234+ENDPROC(aesni_ecb_enc)
8235
8236 /*
8237 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8238@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8239 popl KEYP
8240 popl LEN
8241 #endif
8242+ pax_force_retaddr 0, 1
8243 ret
8244+ENDPROC(aesni_ecb_dec)
8245
8246 /*
8247 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8248@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8249 popl LEN
8250 popl IVP
8251 #endif
8252+ pax_force_retaddr 0, 1
8253 ret
8254+ENDPROC(aesni_cbc_enc)
8255
8256 /*
8257 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8258@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8259 popl LEN
8260 popl IVP
8261 #endif
8262+ pax_force_retaddr 0, 1
8263 ret
8264+ENDPROC(aesni_cbc_dec)
8265
8266 #ifdef __x86_64__
8267 .align 16
8268@@ -2526,6 +2553,7 @@ _aesni_inc_init:
8269 mov $1, TCTR_LOW
8270 MOVQ_R64_XMM TCTR_LOW INC
8271 MOVQ_R64_XMM CTR TCTR_LOW
8272+ pax_force_retaddr_bts
8273 ret
8274
8275 /*
8276@@ -2554,6 +2582,7 @@ _aesni_inc:
8277 .Linc_low:
8278 movaps CTR, IV
8279 PSHUFB_XMM BSWAP_MASK IV
8280+ pax_force_retaddr_bts
8281 ret
8282
8283 /*
8284@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8285 .Lctr_enc_ret:
8286 movups IV, (IVP)
8287 .Lctr_enc_just_ret:
8288+ pax_force_retaddr 0, 1
8289 ret
8290+ENDPROC(aesni_ctr_enc)
8291 #endif
8292diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8293index 391d245..67f35c2 100644
8294--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8295+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8296@@ -20,6 +20,8 @@
8297 *
8298 */
8299
8300+#include <asm/alternative-asm.h>
8301+
8302 .file "blowfish-x86_64-asm.S"
8303 .text
8304
8305@@ -151,9 +153,11 @@ __blowfish_enc_blk:
8306 jnz __enc_xor;
8307
8308 write_block();
8309+ pax_force_retaddr 0, 1
8310 ret;
8311 __enc_xor:
8312 xor_block();
8313+ pax_force_retaddr 0, 1
8314 ret;
8315
8316 .align 8
8317@@ -188,6 +192,7 @@ blowfish_dec_blk:
8318
8319 movq %r11, %rbp;
8320
8321+ pax_force_retaddr 0, 1
8322 ret;
8323
8324 /**********************************************************************
8325@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8326
8327 popq %rbx;
8328 popq %rbp;
8329+ pax_force_retaddr 0, 1
8330 ret;
8331
8332 __enc_xor4:
8333@@ -349,6 +355,7 @@ __enc_xor4:
8334
8335 popq %rbx;
8336 popq %rbp;
8337+ pax_force_retaddr 0, 1
8338 ret;
8339
8340 .align 8
8341@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8342 popq %rbx;
8343 popq %rbp;
8344
8345+ pax_force_retaddr 0, 1
8346 ret;
8347
8348diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8349index 0b33743..7a56206 100644
8350--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8351+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8352@@ -20,6 +20,8 @@
8353 *
8354 */
8355
8356+#include <asm/alternative-asm.h>
8357+
8358 .file "camellia-x86_64-asm_64.S"
8359 .text
8360
8361@@ -229,12 +231,14 @@ __enc_done:
8362 enc_outunpack(mov, RT1);
8363
8364 movq RRBP, %rbp;
8365+ pax_force_retaddr 0, 1
8366 ret;
8367
8368 __enc_xor:
8369 enc_outunpack(xor, RT1);
8370
8371 movq RRBP, %rbp;
8372+ pax_force_retaddr 0, 1
8373 ret;
8374
8375 .global camellia_dec_blk;
8376@@ -275,6 +279,7 @@ __dec_rounds16:
8377 dec_outunpack();
8378
8379 movq RRBP, %rbp;
8380+ pax_force_retaddr 0, 1
8381 ret;
8382
8383 /**********************************************************************
8384@@ -468,6 +473,7 @@ __enc2_done:
8385
8386 movq RRBP, %rbp;
8387 popq %rbx;
8388+ pax_force_retaddr 0, 1
8389 ret;
8390
8391 __enc2_xor:
8392@@ -475,6 +481,7 @@ __enc2_xor:
8393
8394 movq RRBP, %rbp;
8395 popq %rbx;
8396+ pax_force_retaddr 0, 1
8397 ret;
8398
8399 .global camellia_dec_blk_2way;
8400@@ -517,4 +524,5 @@ __dec2_rounds16:
8401
8402 movq RRBP, %rbp;
8403 movq RXOR, %rbx;
8404+ pax_force_retaddr 0, 1
8405 ret;
8406diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8407index 6214a9b..1f4fc9a 100644
8408--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8409+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8410@@ -1,3 +1,5 @@
8411+#include <asm/alternative-asm.h>
8412+
8413 # enter ECRYPT_encrypt_bytes
8414 .text
8415 .p2align 5
8416@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8417 add %r11,%rsp
8418 mov %rdi,%rax
8419 mov %rsi,%rdx
8420+ pax_force_retaddr 0, 1
8421 ret
8422 # bytesatleast65:
8423 ._bytesatleast65:
8424@@ -891,6 +894,7 @@ ECRYPT_keysetup:
8425 add %r11,%rsp
8426 mov %rdi,%rax
8427 mov %rsi,%rdx
8428+ pax_force_retaddr
8429 ret
8430 # enter ECRYPT_ivsetup
8431 .text
8432@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8433 add %r11,%rsp
8434 mov %rdi,%rax
8435 mov %rsi,%rdx
8436+ pax_force_retaddr
8437 ret
8438diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8439index 3ee1ff0..cbc568b 100644
8440--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8441+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8442@@ -24,6 +24,8 @@
8443 *
8444 */
8445
8446+#include <asm/alternative-asm.h>
8447+
8448 .file "serpent-sse2-x86_64-asm_64.S"
8449 .text
8450
8451@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8452 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8453 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8454
8455+ pax_force_retaddr
8456 ret;
8457
8458 __enc_xor8:
8459 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8460 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8461
8462+ pax_force_retaddr
8463 ret;
8464
8465 .align 8
8466@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8467 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8468 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8469
8470+ pax_force_retaddr
8471 ret;
8472diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8473index b2c2f57..8470cab 100644
8474--- a/arch/x86/crypto/sha1_ssse3_asm.S
8475+++ b/arch/x86/crypto/sha1_ssse3_asm.S
8476@@ -28,6 +28,8 @@
8477 * (at your option) any later version.
8478 */
8479
8480+#include <asm/alternative-asm.h>
8481+
8482 #define CTX %rdi // arg1
8483 #define BUF %rsi // arg2
8484 #define CNT %rdx // arg3
8485@@ -104,6 +106,7 @@
8486 pop %r12
8487 pop %rbp
8488 pop %rbx
8489+ pax_force_retaddr 0, 1
8490 ret
8491
8492 .size \name, .-\name
8493diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8494index 5b012a2..36d5364 100644
8495--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8496+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8497@@ -20,6 +20,8 @@
8498 *
8499 */
8500
8501+#include <asm/alternative-asm.h>
8502+
8503 .file "twofish-x86_64-asm-3way.S"
8504 .text
8505
8506@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8507 popq %r13;
8508 popq %r14;
8509 popq %r15;
8510+ pax_force_retaddr 0, 1
8511 ret;
8512
8513 __enc_xor3:
8514@@ -271,6 +274,7 @@ __enc_xor3:
8515 popq %r13;
8516 popq %r14;
8517 popq %r15;
8518+ pax_force_retaddr 0, 1
8519 ret;
8520
8521 .global twofish_dec_blk_3way
8522@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8523 popq %r13;
8524 popq %r14;
8525 popq %r15;
8526+ pax_force_retaddr 0, 1
8527 ret;
8528
8529diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8530index 7bcf3fc..f53832f 100644
8531--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8532+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8533@@ -21,6 +21,7 @@
8534 .text
8535
8536 #include <asm/asm-offsets.h>
8537+#include <asm/alternative-asm.h>
8538
8539 #define a_offset 0
8540 #define b_offset 4
8541@@ -268,6 +269,7 @@ twofish_enc_blk:
8542
8543 popq R1
8544 movq $1,%rax
8545+ pax_force_retaddr 0, 1
8546 ret
8547
8548 twofish_dec_blk:
8549@@ -319,4 +321,5 @@ twofish_dec_blk:
8550
8551 popq R1
8552 movq $1,%rax
8553+ pax_force_retaddr 0, 1
8554 ret
8555diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8556index 07b3a68..bd2a388 100644
8557--- a/arch/x86/ia32/ia32_aout.c
8558+++ b/arch/x86/ia32/ia32_aout.c
8559@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8560 unsigned long dump_start, dump_size;
8561 struct user32 dump;
8562
8563+ memset(&dump, 0, sizeof(dump));
8564+
8565 fs = get_fs();
8566 set_fs(KERNEL_DS);
8567 has_dumped = 1;
8568diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8569index 673ac9b..7a8c5df 100644
8570--- a/arch/x86/ia32/ia32_signal.c
8571+++ b/arch/x86/ia32/ia32_signal.c
8572@@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8573 }
8574 seg = get_fs();
8575 set_fs(KERNEL_DS);
8576- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8577+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8578 set_fs(seg);
8579 if (ret >= 0 && uoss_ptr) {
8580 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8581@@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8582 */
8583 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8584 size_t frame_size,
8585- void **fpstate)
8586+ void __user **fpstate)
8587 {
8588 unsigned long sp;
8589
8590@@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8591
8592 if (used_math()) {
8593 sp = sp - sig_xstate_ia32_size;
8594- *fpstate = (struct _fpstate_ia32 *) sp;
8595+ *fpstate = (struct _fpstate_ia32 __user *) sp;
8596 if (save_i387_xstate_ia32(*fpstate) < 0)
8597 return (void __user *) -1L;
8598 }
8599@@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8600 sp -= frame_size;
8601 /* Align the stack pointer according to the i386 ABI,
8602 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8603- sp = ((sp + 4) & -16ul) - 4;
8604+ sp = ((sp - 12) & -16ul) - 4;
8605 return (void __user *) sp;
8606 }
8607
8608@@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8609 * These are actually not used anymore, but left because some
8610 * gdb versions depend on them as a marker.
8611 */
8612- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8613+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8614 } put_user_catch(err);
8615
8616 if (err)
8617@@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8618 0xb8,
8619 __NR_ia32_rt_sigreturn,
8620 0x80cd,
8621- 0,
8622+ 0
8623 };
8624
8625 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8626@@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8627
8628 if (ka->sa.sa_flags & SA_RESTORER)
8629 restorer = ka->sa.sa_restorer;
8630+ else if (current->mm->context.vdso)
8631+ /* Return stub is in 32bit vsyscall page */
8632+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8633 else
8634- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8635- rt_sigreturn);
8636+ restorer = &frame->retcode;
8637 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8638
8639 /*
8640 * Not actually used anymore, but left because some gdb
8641 * versions need it.
8642 */
8643- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8644+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8645 } put_user_catch(err);
8646
8647 if (err)
8648diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8649index 20e5f7b..f33c779 100644
8650--- a/arch/x86/ia32/ia32entry.S
8651+++ b/arch/x86/ia32/ia32entry.S
8652@@ -14,8 +14,10 @@
8653 #include <asm/segment.h>
8654 #include <asm/irqflags.h>
8655 #include <asm/asm.h>
8656+#include <asm/pgtable.h>
8657 #include <linux/linkage.h>
8658 #include <linux/err.h>
8659+#include <asm/alternative-asm.h>
8660
8661 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8662 #include <linux/elf-em.h>
8663@@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8664 ENDPROC(native_irq_enable_sysexit)
8665 #endif
8666
8667+ .macro pax_enter_kernel_user
8668+ pax_set_fptr_mask
8669+#ifdef CONFIG_PAX_MEMORY_UDEREF
8670+ call pax_enter_kernel_user
8671+#endif
8672+ .endm
8673+
8674+ .macro pax_exit_kernel_user
8675+#ifdef CONFIG_PAX_MEMORY_UDEREF
8676+ call pax_exit_kernel_user
8677+#endif
8678+#ifdef CONFIG_PAX_RANDKSTACK
8679+ pushq %rax
8680+ pushq %r11
8681+ call pax_randomize_kstack
8682+ popq %r11
8683+ popq %rax
8684+#endif
8685+ .endm
8686+
8687+.macro pax_erase_kstack
8688+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8689+ call pax_erase_kstack
8690+#endif
8691+.endm
8692+
8693 /*
8694 * 32bit SYSENTER instruction entry.
8695 *
8696@@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8697 CFI_REGISTER rsp,rbp
8698 SWAPGS_UNSAFE_STACK
8699 movq PER_CPU_VAR(kernel_stack), %rsp
8700- addq $(KERNEL_STACK_OFFSET),%rsp
8701- /*
8702- * No need to follow this irqs on/off section: the syscall
8703- * disabled irqs, here we enable it straight after entry:
8704- */
8705- ENABLE_INTERRUPTS(CLBR_NONE)
8706 movl %ebp,%ebp /* zero extension */
8707 pushq_cfi $__USER32_DS
8708 /*CFI_REL_OFFSET ss,0*/
8709@@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8710 CFI_REL_OFFSET rsp,0
8711 pushfq_cfi
8712 /*CFI_REL_OFFSET rflags,0*/
8713- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8714- CFI_REGISTER rip,r10
8715+ orl $X86_EFLAGS_IF,(%rsp)
8716+ GET_THREAD_INFO(%r11)
8717+ movl TI_sysenter_return(%r11), %r11d
8718+ CFI_REGISTER rip,r11
8719 pushq_cfi $__USER32_CS
8720 /*CFI_REL_OFFSET cs,0*/
8721 movl %eax, %eax
8722- pushq_cfi %r10
8723+ pushq_cfi %r11
8724 CFI_REL_OFFSET rip,0
8725 pushq_cfi %rax
8726 cld
8727 SAVE_ARGS 0,1,0
8728+ pax_enter_kernel_user
8729+
8730+#ifdef CONFIG_PAX_RANDKSTACK
8731+ pax_erase_kstack
8732+#endif
8733+
8734+ /*
8735+ * No need to follow this irqs on/off section: the syscall
8736+ * disabled irqs, here we enable it straight after entry:
8737+ */
8738+ ENABLE_INTERRUPTS(CLBR_NONE)
8739 /* no need to do an access_ok check here because rbp has been
8740 32bit zero extended */
8741+
8742+#ifdef CONFIG_PAX_MEMORY_UDEREF
8743+ mov $PAX_USER_SHADOW_BASE,%r11
8744+ add %r11,%rbp
8745+#endif
8746+
8747 1: movl (%rbp),%ebp
8748 _ASM_EXTABLE(1b,ia32_badarg)
8749- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8750- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8751+ GET_THREAD_INFO(%r11)
8752+ orl $TS_COMPAT,TI_status(%r11)
8753+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8754 CFI_REMEMBER_STATE
8755 jnz sysenter_tracesys
8756 cmpq $(IA32_NR_syscalls-1),%rax
8757@@ -159,12 +201,15 @@ sysenter_do_call:
8758 sysenter_dispatch:
8759 call *ia32_sys_call_table(,%rax,8)
8760 movq %rax,RAX-ARGOFFSET(%rsp)
8761+ GET_THREAD_INFO(%r11)
8762 DISABLE_INTERRUPTS(CLBR_NONE)
8763 TRACE_IRQS_OFF
8764- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8765+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8766 jnz sysexit_audit
8767 sysexit_from_sys_call:
8768- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8769+ pax_exit_kernel_user
8770+ pax_erase_kstack
8771+ andl $~TS_COMPAT,TI_status(%r11)
8772 /* clear IF, that popfq doesn't enable interrupts early */
8773 andl $~0x200,EFLAGS-R11(%rsp)
8774 movl RIP-R11(%rsp),%edx /* User %eip */
8775@@ -190,6 +235,9 @@ sysexit_from_sys_call:
8776 movl %eax,%esi /* 2nd arg: syscall number */
8777 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8778 call __audit_syscall_entry
8779+
8780+ pax_erase_kstack
8781+
8782 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8783 cmpq $(IA32_NR_syscalls-1),%rax
8784 ja ia32_badsys
8785@@ -201,7 +249,7 @@ sysexit_from_sys_call:
8786 .endm
8787
8788 .macro auditsys_exit exit
8789- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8790+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8791 jnz ia32_ret_from_sys_call
8792 TRACE_IRQS_ON
8793 sti
8794@@ -212,11 +260,12 @@ sysexit_from_sys_call:
8795 1: setbe %al /* 1 if error, 0 if not */
8796 movzbl %al,%edi /* zero-extend that into %edi */
8797 call __audit_syscall_exit
8798+ GET_THREAD_INFO(%r11)
8799 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8800 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8801 cli
8802 TRACE_IRQS_OFF
8803- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8804+ testl %edi,TI_flags(%r11)
8805 jz \exit
8806 CLEAR_RREGS -ARGOFFSET
8807 jmp int_with_check
8808@@ -234,7 +283,7 @@ sysexit_audit:
8809
8810 sysenter_tracesys:
8811 #ifdef CONFIG_AUDITSYSCALL
8812- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8813+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8814 jz sysenter_auditsys
8815 #endif
8816 SAVE_REST
8817@@ -246,6 +295,9 @@ sysenter_tracesys:
8818 RESTORE_REST
8819 cmpq $(IA32_NR_syscalls-1),%rax
8820 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8821+
8822+ pax_erase_kstack
8823+
8824 jmp sysenter_do_call
8825 CFI_ENDPROC
8826 ENDPROC(ia32_sysenter_target)
8827@@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8828 ENTRY(ia32_cstar_target)
8829 CFI_STARTPROC32 simple
8830 CFI_SIGNAL_FRAME
8831- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8832+ CFI_DEF_CFA rsp,0
8833 CFI_REGISTER rip,rcx
8834 /*CFI_REGISTER rflags,r11*/
8835 SWAPGS_UNSAFE_STACK
8836 movl %esp,%r8d
8837 CFI_REGISTER rsp,r8
8838 movq PER_CPU_VAR(kernel_stack),%rsp
8839+ SAVE_ARGS 8*6,0,0
8840+ pax_enter_kernel_user
8841+
8842+#ifdef CONFIG_PAX_RANDKSTACK
8843+ pax_erase_kstack
8844+#endif
8845+
8846 /*
8847 * No need to follow this irqs on/off section: the syscall
8848 * disabled irqs and here we enable it straight after entry:
8849 */
8850 ENABLE_INTERRUPTS(CLBR_NONE)
8851- SAVE_ARGS 8,0,0
8852 movl %eax,%eax /* zero extension */
8853 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8854 movq %rcx,RIP-ARGOFFSET(%rsp)
8855@@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8856 /* no need to do an access_ok check here because r8 has been
8857 32bit zero extended */
8858 /* hardware stack frame is complete now */
8859+
8860+#ifdef CONFIG_PAX_MEMORY_UDEREF
8861+ mov $PAX_USER_SHADOW_BASE,%r11
8862+ add %r11,%r8
8863+#endif
8864+
8865 1: movl (%r8),%r9d
8866 _ASM_EXTABLE(1b,ia32_badarg)
8867- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8868- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8869+ GET_THREAD_INFO(%r11)
8870+ orl $TS_COMPAT,TI_status(%r11)
8871+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8872 CFI_REMEMBER_STATE
8873 jnz cstar_tracesys
8874 cmpq $IA32_NR_syscalls-1,%rax
8875@@ -314,12 +379,15 @@ cstar_do_call:
8876 cstar_dispatch:
8877 call *ia32_sys_call_table(,%rax,8)
8878 movq %rax,RAX-ARGOFFSET(%rsp)
8879+ GET_THREAD_INFO(%r11)
8880 DISABLE_INTERRUPTS(CLBR_NONE)
8881 TRACE_IRQS_OFF
8882- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8883+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8884 jnz sysretl_audit
8885 sysretl_from_sys_call:
8886- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8887+ pax_exit_kernel_user
8888+ pax_erase_kstack
8889+ andl $~TS_COMPAT,TI_status(%r11)
8890 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8891 movl RIP-ARGOFFSET(%rsp),%ecx
8892 CFI_REGISTER rip,rcx
8893@@ -347,7 +415,7 @@ sysretl_audit:
8894
8895 cstar_tracesys:
8896 #ifdef CONFIG_AUDITSYSCALL
8897- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8898+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8899 jz cstar_auditsys
8900 #endif
8901 xchgl %r9d,%ebp
8902@@ -361,6 +429,9 @@ cstar_tracesys:
8903 xchgl %ebp,%r9d
8904 cmpq $(IA32_NR_syscalls-1),%rax
8905 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8906+
8907+ pax_erase_kstack
8908+
8909 jmp cstar_do_call
8910 END(ia32_cstar_target)
8911
8912@@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8913 CFI_REL_OFFSET rip,RIP-RIP
8914 PARAVIRT_ADJUST_EXCEPTION_FRAME
8915 SWAPGS
8916- /*
8917- * No need to follow this irqs on/off section: the syscall
8918- * disabled irqs and here we enable it straight after entry:
8919- */
8920- ENABLE_INTERRUPTS(CLBR_NONE)
8921 movl %eax,%eax
8922 pushq_cfi %rax
8923 cld
8924 /* note the registers are not zero extended to the sf.
8925 this could be a problem. */
8926 SAVE_ARGS 0,1,0
8927- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8928- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8929+ pax_enter_kernel_user
8930+
8931+#ifdef CONFIG_PAX_RANDKSTACK
8932+ pax_erase_kstack
8933+#endif
8934+
8935+ /*
8936+ * No need to follow this irqs on/off section: the syscall
8937+ * disabled irqs and here we enable it straight after entry:
8938+ */
8939+ ENABLE_INTERRUPTS(CLBR_NONE)
8940+ GET_THREAD_INFO(%r11)
8941+ orl $TS_COMPAT,TI_status(%r11)
8942+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8943 jnz ia32_tracesys
8944 cmpq $(IA32_NR_syscalls-1),%rax
8945 ja ia32_badsys
8946@@ -436,6 +514,9 @@ ia32_tracesys:
8947 RESTORE_REST
8948 cmpq $(IA32_NR_syscalls-1),%rax
8949 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8950+
8951+ pax_erase_kstack
8952+
8953 jmp ia32_do_call
8954 END(ia32_syscall)
8955
8956diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8957index 4540bec..714d913 100644
8958--- a/arch/x86/ia32/sys_ia32.c
8959+++ b/arch/x86/ia32/sys_ia32.c
8960@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8961 */
8962 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8963 {
8964- typeof(ubuf->st_uid) uid = 0;
8965- typeof(ubuf->st_gid) gid = 0;
8966+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
8967+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
8968 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8969 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8970 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8971@@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8972 return ret;
8973 }
8974
8975-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8976+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8977 int options)
8978 {
8979 return compat_sys_wait4(pid, stat_addr, options, NULL);
8980@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8981 mm_segment_t old_fs = get_fs();
8982
8983 set_fs(KERNEL_DS);
8984- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8985+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8986 set_fs(old_fs);
8987 if (put_compat_timespec(&t, interval))
8988 return -EFAULT;
8989@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8990 mm_segment_t old_fs = get_fs();
8991
8992 set_fs(KERNEL_DS);
8993- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8994+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8995 set_fs(old_fs);
8996 if (!ret) {
8997 switch (_NSIG_WORDS) {
8998@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8999 if (copy_siginfo_from_user32(&info, uinfo))
9000 return -EFAULT;
9001 set_fs(KERNEL_DS);
9002- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9003+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9004 set_fs(old_fs);
9005 return ret;
9006 }
9007@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9008 return -EFAULT;
9009
9010 set_fs(KERNEL_DS);
9011- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9012+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9013 count);
9014 set_fs(old_fs);
9015
9016diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9017index 952bd01..7692c6f 100644
9018--- a/arch/x86/include/asm/alternative-asm.h
9019+++ b/arch/x86/include/asm/alternative-asm.h
9020@@ -15,6 +15,45 @@
9021 .endm
9022 #endif
9023
9024+#ifdef KERNEXEC_PLUGIN
9025+ .macro pax_force_retaddr_bts rip=0
9026+ btsq $63,\rip(%rsp)
9027+ .endm
9028+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9029+ .macro pax_force_retaddr rip=0, reload=0
9030+ btsq $63,\rip(%rsp)
9031+ .endm
9032+ .macro pax_force_fptr ptr
9033+ btsq $63,\ptr
9034+ .endm
9035+ .macro pax_set_fptr_mask
9036+ .endm
9037+#endif
9038+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9039+ .macro pax_force_retaddr rip=0, reload=0
9040+ .if \reload
9041+ pax_set_fptr_mask
9042+ .endif
9043+ orq %r10,\rip(%rsp)
9044+ .endm
9045+ .macro pax_force_fptr ptr
9046+ orq %r10,\ptr
9047+ .endm
9048+ .macro pax_set_fptr_mask
9049+ movabs $0x8000000000000000,%r10
9050+ .endm
9051+#endif
9052+#else
9053+ .macro pax_force_retaddr rip=0, reload=0
9054+ .endm
9055+ .macro pax_force_fptr ptr
9056+ .endm
9057+ .macro pax_force_retaddr_bts rip=0
9058+ .endm
9059+ .macro pax_set_fptr_mask
9060+ .endm
9061+#endif
9062+
9063 .macro altinstruction_entry orig alt feature orig_len alt_len
9064 .long \orig - .
9065 .long \alt - .
9066diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9067index 49331be..9706065 100644
9068--- a/arch/x86/include/asm/alternative.h
9069+++ b/arch/x86/include/asm/alternative.h
9070@@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9071 ".section .discard,\"aw\",@progbits\n" \
9072 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9073 ".previous\n" \
9074- ".section .altinstr_replacement, \"ax\"\n" \
9075+ ".section .altinstr_replacement, \"a\"\n" \
9076 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9077 ".previous"
9078
9079diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9080index eaff479..1eff9b5 100644
9081--- a/arch/x86/include/asm/apic.h
9082+++ b/arch/x86/include/asm/apic.h
9083@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9084
9085 #ifdef CONFIG_X86_LOCAL_APIC
9086
9087-extern unsigned int apic_verbosity;
9088+extern int apic_verbosity;
9089 extern int local_apic_timer_c2_ok;
9090
9091 extern int disable_apic;
9092@@ -390,7 +390,7 @@ struct apic {
9093 */
9094 int (*x86_32_numa_cpu_node)(int cpu);
9095 #endif
9096-};
9097+} __do_const;
9098
9099 /*
9100 * Pointer to the local APIC driver in use on this system (there's
9101diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9102index 20370c6..a2eb9b0 100644
9103--- a/arch/x86/include/asm/apm.h
9104+++ b/arch/x86/include/asm/apm.h
9105@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9106 __asm__ __volatile__(APM_DO_ZERO_SEGS
9107 "pushl %%edi\n\t"
9108 "pushl %%ebp\n\t"
9109- "lcall *%%cs:apm_bios_entry\n\t"
9110+ "lcall *%%ss:apm_bios_entry\n\t"
9111 "setc %%al\n\t"
9112 "popl %%ebp\n\t"
9113 "popl %%edi\n\t"
9114@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9115 __asm__ __volatile__(APM_DO_ZERO_SEGS
9116 "pushl %%edi\n\t"
9117 "pushl %%ebp\n\t"
9118- "lcall *%%cs:apm_bios_entry\n\t"
9119+ "lcall *%%ss:apm_bios_entry\n\t"
9120 "setc %%bl\n\t"
9121 "popl %%ebp\n\t"
9122 "popl %%edi\n\t"
9123diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9124index 58cb6d4..a4b806c 100644
9125--- a/arch/x86/include/asm/atomic.h
9126+++ b/arch/x86/include/asm/atomic.h
9127@@ -22,7 +22,18 @@
9128 */
9129 static inline int atomic_read(const atomic_t *v)
9130 {
9131- return (*(volatile int *)&(v)->counter);
9132+ return (*(volatile const int *)&(v)->counter);
9133+}
9134+
9135+/**
9136+ * atomic_read_unchecked - read atomic variable
9137+ * @v: pointer of type atomic_unchecked_t
9138+ *
9139+ * Atomically reads the value of @v.
9140+ */
9141+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9142+{
9143+ return (*(volatile const int *)&(v)->counter);
9144 }
9145
9146 /**
9147@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9148 }
9149
9150 /**
9151+ * atomic_set_unchecked - set atomic variable
9152+ * @v: pointer of type atomic_unchecked_t
9153+ * @i: required value
9154+ *
9155+ * Atomically sets the value of @v to @i.
9156+ */
9157+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9158+{
9159+ v->counter = i;
9160+}
9161+
9162+/**
9163 * atomic_add - add integer to atomic variable
9164 * @i: integer value to add
9165 * @v: pointer of type atomic_t
9166@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9167 */
9168 static inline void atomic_add(int i, atomic_t *v)
9169 {
9170- asm volatile(LOCK_PREFIX "addl %1,%0"
9171+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9172+
9173+#ifdef CONFIG_PAX_REFCOUNT
9174+ "jno 0f\n"
9175+ LOCK_PREFIX "subl %1,%0\n"
9176+ "int $4\n0:\n"
9177+ _ASM_EXTABLE(0b, 0b)
9178+#endif
9179+
9180+ : "+m" (v->counter)
9181+ : "ir" (i));
9182+}
9183+
9184+/**
9185+ * atomic_add_unchecked - add integer to atomic variable
9186+ * @i: integer value to add
9187+ * @v: pointer of type atomic_unchecked_t
9188+ *
9189+ * Atomically adds @i to @v.
9190+ */
9191+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9192+{
9193+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9194 : "+m" (v->counter)
9195 : "ir" (i));
9196 }
9197@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9198 */
9199 static inline void atomic_sub(int i, atomic_t *v)
9200 {
9201- asm volatile(LOCK_PREFIX "subl %1,%0"
9202+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9203+
9204+#ifdef CONFIG_PAX_REFCOUNT
9205+ "jno 0f\n"
9206+ LOCK_PREFIX "addl %1,%0\n"
9207+ "int $4\n0:\n"
9208+ _ASM_EXTABLE(0b, 0b)
9209+#endif
9210+
9211+ : "+m" (v->counter)
9212+ : "ir" (i));
9213+}
9214+
9215+/**
9216+ * atomic_sub_unchecked - subtract integer from atomic variable
9217+ * @i: integer value to subtract
9218+ * @v: pointer of type atomic_unchecked_t
9219+ *
9220+ * Atomically subtracts @i from @v.
9221+ */
9222+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9223+{
9224+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9225 : "+m" (v->counter)
9226 : "ir" (i));
9227 }
9228@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9229 {
9230 unsigned char c;
9231
9232- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9233+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
9234+
9235+#ifdef CONFIG_PAX_REFCOUNT
9236+ "jno 0f\n"
9237+ LOCK_PREFIX "addl %2,%0\n"
9238+ "int $4\n0:\n"
9239+ _ASM_EXTABLE(0b, 0b)
9240+#endif
9241+
9242+ "sete %1\n"
9243 : "+m" (v->counter), "=qm" (c)
9244 : "ir" (i) : "memory");
9245 return c;
9246@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9247 */
9248 static inline void atomic_inc(atomic_t *v)
9249 {
9250- asm volatile(LOCK_PREFIX "incl %0"
9251+ asm volatile(LOCK_PREFIX "incl %0\n"
9252+
9253+#ifdef CONFIG_PAX_REFCOUNT
9254+ "jno 0f\n"
9255+ LOCK_PREFIX "decl %0\n"
9256+ "int $4\n0:\n"
9257+ _ASM_EXTABLE(0b, 0b)
9258+#endif
9259+
9260+ : "+m" (v->counter));
9261+}
9262+
9263+/**
9264+ * atomic_inc_unchecked - increment atomic variable
9265+ * @v: pointer of type atomic_unchecked_t
9266+ *
9267+ * Atomically increments @v by 1.
9268+ */
9269+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9270+{
9271+ asm volatile(LOCK_PREFIX "incl %0\n"
9272 : "+m" (v->counter));
9273 }
9274
9275@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9276 */
9277 static inline void atomic_dec(atomic_t *v)
9278 {
9279- asm volatile(LOCK_PREFIX "decl %0"
9280+ asm volatile(LOCK_PREFIX "decl %0\n"
9281+
9282+#ifdef CONFIG_PAX_REFCOUNT
9283+ "jno 0f\n"
9284+ LOCK_PREFIX "incl %0\n"
9285+ "int $4\n0:\n"
9286+ _ASM_EXTABLE(0b, 0b)
9287+#endif
9288+
9289+ : "+m" (v->counter));
9290+}
9291+
9292+/**
9293+ * atomic_dec_unchecked - decrement atomic variable
9294+ * @v: pointer of type atomic_unchecked_t
9295+ *
9296+ * Atomically decrements @v by 1.
9297+ */
9298+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9299+{
9300+ asm volatile(LOCK_PREFIX "decl %0\n"
9301 : "+m" (v->counter));
9302 }
9303
9304@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9305 {
9306 unsigned char c;
9307
9308- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9309+ asm volatile(LOCK_PREFIX "decl %0\n"
9310+
9311+#ifdef CONFIG_PAX_REFCOUNT
9312+ "jno 0f\n"
9313+ LOCK_PREFIX "incl %0\n"
9314+ "int $4\n0:\n"
9315+ _ASM_EXTABLE(0b, 0b)
9316+#endif
9317+
9318+ "sete %1\n"
9319 : "+m" (v->counter), "=qm" (c)
9320 : : "memory");
9321 return c != 0;
9322@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9323 {
9324 unsigned char c;
9325
9326- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9327+ asm volatile(LOCK_PREFIX "incl %0\n"
9328+
9329+#ifdef CONFIG_PAX_REFCOUNT
9330+ "jno 0f\n"
9331+ LOCK_PREFIX "decl %0\n"
9332+ "int $4\n0:\n"
9333+ _ASM_EXTABLE(0b, 0b)
9334+#endif
9335+
9336+ "sete %1\n"
9337+ : "+m" (v->counter), "=qm" (c)
9338+ : : "memory");
9339+ return c != 0;
9340+}
9341+
9342+/**
9343+ * atomic_inc_and_test_unchecked - increment and test
9344+ * @v: pointer of type atomic_unchecked_t
9345+ *
9346+ * Atomically increments @v by 1
9347+ * and returns true if the result is zero, or false for all
9348+ * other cases.
9349+ */
9350+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9351+{
9352+ unsigned char c;
9353+
9354+ asm volatile(LOCK_PREFIX "incl %0\n"
9355+ "sete %1\n"
9356 : "+m" (v->counter), "=qm" (c)
9357 : : "memory");
9358 return c != 0;
9359@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9360 {
9361 unsigned char c;
9362
9363- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9364+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9365+
9366+#ifdef CONFIG_PAX_REFCOUNT
9367+ "jno 0f\n"
9368+ LOCK_PREFIX "subl %2,%0\n"
9369+ "int $4\n0:\n"
9370+ _ASM_EXTABLE(0b, 0b)
9371+#endif
9372+
9373+ "sets %1\n"
9374 : "+m" (v->counter), "=qm" (c)
9375 : "ir" (i) : "memory");
9376 return c;
9377@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9378 goto no_xadd;
9379 #endif
9380 /* Modern 486+ processor */
9381- return i + xadd(&v->counter, i);
9382+ return i + xadd_check_overflow(&v->counter, i);
9383
9384 #ifdef CONFIG_M386
9385 no_xadd: /* Legacy 386 processor */
9386@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9387 }
9388
9389 /**
9390+ * atomic_add_return_unchecked - add integer and return
9391+ * @i: integer value to add
9392+ * @v: pointer of type atomic_unchecked_t
9393+ *
9394+ * Atomically adds @i to @v and returns @i + @v
9395+ */
9396+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9397+{
9398+#ifdef CONFIG_M386
9399+ int __i;
9400+ unsigned long flags;
9401+ if (unlikely(boot_cpu_data.x86 <= 3))
9402+ goto no_xadd;
9403+#endif
9404+ /* Modern 486+ processor */
9405+ return i + xadd(&v->counter, i);
9406+
9407+#ifdef CONFIG_M386
9408+no_xadd: /* Legacy 386 processor */
9409+ raw_local_irq_save(flags);
9410+ __i = atomic_read_unchecked(v);
9411+ atomic_set_unchecked(v, i + __i);
9412+ raw_local_irq_restore(flags);
9413+ return i + __i;
9414+#endif
9415+}
9416+
9417+/**
9418 * atomic_sub_return - subtract integer and return
9419 * @v: pointer of type atomic_t
9420 * @i: integer value to subtract
9421@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9422 }
9423
9424 #define atomic_inc_return(v) (atomic_add_return(1, v))
9425+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9426+{
9427+ return atomic_add_return_unchecked(1, v);
9428+}
9429 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9430
9431 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9432@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9433 return cmpxchg(&v->counter, old, new);
9434 }
9435
9436+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9437+{
9438+ return cmpxchg(&v->counter, old, new);
9439+}
9440+
9441 static inline int atomic_xchg(atomic_t *v, int new)
9442 {
9443 return xchg(&v->counter, new);
9444 }
9445
9446+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9447+{
9448+ return xchg(&v->counter, new);
9449+}
9450+
9451 /**
9452 * __atomic_add_unless - add unless the number is already a given value
9453 * @v: pointer of type atomic_t
9454@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9455 */
9456 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9457 {
9458- int c, old;
9459+ int c, old, new;
9460 c = atomic_read(v);
9461 for (;;) {
9462- if (unlikely(c == (u)))
9463+ if (unlikely(c == u))
9464 break;
9465- old = atomic_cmpxchg((v), c, c + (a));
9466+
9467+ asm volatile("addl %2,%0\n"
9468+
9469+#ifdef CONFIG_PAX_REFCOUNT
9470+ "jno 0f\n"
9471+ "subl %2,%0\n"
9472+ "int $4\n0:\n"
9473+ _ASM_EXTABLE(0b, 0b)
9474+#endif
9475+
9476+ : "=r" (new)
9477+ : "0" (c), "ir" (a));
9478+
9479+ old = atomic_cmpxchg(v, c, new);
9480 if (likely(old == c))
9481 break;
9482 c = old;
9483@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9484 return c;
9485 }
9486
9487+/**
9488+ * atomic_inc_not_zero_hint - increment if not null
9489+ * @v: pointer of type atomic_t
9490+ * @hint: probable value of the atomic before the increment
9491+ *
9492+ * This version of atomic_inc_not_zero() gives a hint of probable
9493+ * value of the atomic. This helps processor to not read the memory
9494+ * before doing the atomic read/modify/write cycle, lowering
9495+ * number of bus transactions on some arches.
9496+ *
9497+ * Returns: 0 if increment was not done, 1 otherwise.
9498+ */
9499+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9500+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9501+{
9502+ int val, c = hint, new;
9503+
9504+ /* sanity test, should be removed by compiler if hint is a constant */
9505+ if (!hint)
9506+ return __atomic_add_unless(v, 1, 0);
9507+
9508+ do {
9509+ asm volatile("incl %0\n"
9510+
9511+#ifdef CONFIG_PAX_REFCOUNT
9512+ "jno 0f\n"
9513+ "decl %0\n"
9514+ "int $4\n0:\n"
9515+ _ASM_EXTABLE(0b, 0b)
9516+#endif
9517+
9518+ : "=r" (new)
9519+ : "0" (c));
9520+
9521+ val = atomic_cmpxchg(v, c, new);
9522+ if (val == c)
9523+ return 1;
9524+ c = val;
9525+ } while (c);
9526+
9527+ return 0;
9528+}
9529
9530 /*
9531 * atomic_dec_if_positive - decrement by 1 if old value positive
9532@@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9533 #endif
9534
9535 /* These are x86-specific, used by some header files */
9536-#define atomic_clear_mask(mask, addr) \
9537- asm volatile(LOCK_PREFIX "andl %0,%1" \
9538- : : "r" (~(mask)), "m" (*(addr)) : "memory")
9539+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9540+{
9541+ asm volatile(LOCK_PREFIX "andl %1,%0"
9542+ : "+m" (v->counter)
9543+ : "r" (~(mask))
9544+ : "memory");
9545+}
9546
9547-#define atomic_set_mask(mask, addr) \
9548- asm volatile(LOCK_PREFIX "orl %0,%1" \
9549- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9550- : "memory")
9551+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9552+{
9553+ asm volatile(LOCK_PREFIX "andl %1,%0"
9554+ : "+m" (v->counter)
9555+ : "r" (~(mask))
9556+ : "memory");
9557+}
9558+
9559+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9560+{
9561+ asm volatile(LOCK_PREFIX "orl %1,%0"
9562+ : "+m" (v->counter)
9563+ : "r" (mask)
9564+ : "memory");
9565+}
9566+
9567+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9568+{
9569+ asm volatile(LOCK_PREFIX "orl %1,%0"
9570+ : "+m" (v->counter)
9571+ : "r" (mask)
9572+ : "memory");
9573+}
9574
9575 /* Atomic operations are already serializing on x86 */
9576 #define smp_mb__before_atomic_dec() barrier()
9577diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9578index b154de7..aadebd8 100644
9579--- a/arch/x86/include/asm/atomic64_32.h
9580+++ b/arch/x86/include/asm/atomic64_32.h
9581@@ -12,6 +12,14 @@ typedef struct {
9582 u64 __aligned(8) counter;
9583 } atomic64_t;
9584
9585+#ifdef CONFIG_PAX_REFCOUNT
9586+typedef struct {
9587+ u64 __aligned(8) counter;
9588+} atomic64_unchecked_t;
9589+#else
9590+typedef atomic64_t atomic64_unchecked_t;
9591+#endif
9592+
9593 #define ATOMIC64_INIT(val) { (val) }
9594
9595 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9596@@ -37,21 +45,31 @@ typedef struct {
9597 ATOMIC64_DECL_ONE(sym##_386)
9598
9599 ATOMIC64_DECL_ONE(add_386);
9600+ATOMIC64_DECL_ONE(add_unchecked_386);
9601 ATOMIC64_DECL_ONE(sub_386);
9602+ATOMIC64_DECL_ONE(sub_unchecked_386);
9603 ATOMIC64_DECL_ONE(inc_386);
9604+ATOMIC64_DECL_ONE(inc_unchecked_386);
9605 ATOMIC64_DECL_ONE(dec_386);
9606+ATOMIC64_DECL_ONE(dec_unchecked_386);
9607 #endif
9608
9609 #define alternative_atomic64(f, out, in...) \
9610 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9611
9612 ATOMIC64_DECL(read);
9613+ATOMIC64_DECL(read_unchecked);
9614 ATOMIC64_DECL(set);
9615+ATOMIC64_DECL(set_unchecked);
9616 ATOMIC64_DECL(xchg);
9617 ATOMIC64_DECL(add_return);
9618+ATOMIC64_DECL(add_return_unchecked);
9619 ATOMIC64_DECL(sub_return);
9620+ATOMIC64_DECL(sub_return_unchecked);
9621 ATOMIC64_DECL(inc_return);
9622+ATOMIC64_DECL(inc_return_unchecked);
9623 ATOMIC64_DECL(dec_return);
9624+ATOMIC64_DECL(dec_return_unchecked);
9625 ATOMIC64_DECL(dec_if_positive);
9626 ATOMIC64_DECL(inc_not_zero);
9627 ATOMIC64_DECL(add_unless);
9628@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9629 }
9630
9631 /**
9632+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9633+ * @p: pointer to type atomic64_unchecked_t
9634+ * @o: expected value
9635+ * @n: new value
9636+ *
9637+ * Atomically sets @v to @n if it was equal to @o and returns
9638+ * the old value.
9639+ */
9640+
9641+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9642+{
9643+ return cmpxchg64(&v->counter, o, n);
9644+}
9645+
9646+/**
9647 * atomic64_xchg - xchg atomic64 variable
9648 * @v: pointer to type atomic64_t
9649 * @n: value to assign
9650@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9651 }
9652
9653 /**
9654+ * atomic64_set_unchecked - set atomic64 variable
9655+ * @v: pointer to type atomic64_unchecked_t
9656+ * @n: value to assign
9657+ *
9658+ * Atomically sets the value of @v to @n.
9659+ */
9660+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9661+{
9662+ unsigned high = (unsigned)(i >> 32);
9663+ unsigned low = (unsigned)i;
9664+ alternative_atomic64(set, /* no output */,
9665+ "S" (v), "b" (low), "c" (high)
9666+ : "eax", "edx", "memory");
9667+}
9668+
9669+/**
9670 * atomic64_read - read atomic64 variable
9671 * @v: pointer to type atomic64_t
9672 *
9673@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9674 }
9675
9676 /**
9677+ * atomic64_read_unchecked - read atomic64 variable
9678+ * @v: pointer to type atomic64_unchecked_t
9679+ *
9680+ * Atomically reads the value of @v and returns it.
9681+ */
9682+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9683+{
9684+ long long r;
9685+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9686+ return r;
9687+ }
9688+
9689+/**
9690 * atomic64_add_return - add and return
9691 * @i: integer value to add
9692 * @v: pointer to type atomic64_t
9693@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9694 return i;
9695 }
9696
9697+/**
9698+ * atomic64_add_return_unchecked - add and return
9699+ * @i: integer value to add
9700+ * @v: pointer to type atomic64_unchecked_t
9701+ *
9702+ * Atomically adds @i to @v and returns @i + *@v
9703+ */
9704+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9705+{
9706+ alternative_atomic64(add_return_unchecked,
9707+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9708+ ASM_NO_INPUT_CLOBBER("memory"));
9709+ return i;
9710+}
9711+
9712 /*
9713 * Other variants with different arithmetic operators:
9714 */
9715@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9716 return a;
9717 }
9718
9719+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9720+{
9721+ long long a;
9722+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
9723+ "S" (v) : "memory", "ecx");
9724+ return a;
9725+}
9726+
9727 static inline long long atomic64_dec_return(atomic64_t *v)
9728 {
9729 long long a;
9730@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9731 }
9732
9733 /**
9734+ * atomic64_add_unchecked - add integer to atomic64 variable
9735+ * @i: integer value to add
9736+ * @v: pointer to type atomic64_unchecked_t
9737+ *
9738+ * Atomically adds @i to @v.
9739+ */
9740+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9741+{
9742+ __alternative_atomic64(add_unchecked, add_return_unchecked,
9743+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9744+ ASM_NO_INPUT_CLOBBER("memory"));
9745+ return i;
9746+}
9747+
9748+/**
9749 * atomic64_sub - subtract the atomic64 variable
9750 * @i: integer value to subtract
9751 * @v: pointer to type atomic64_t
9752diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9753index 0e1cbfc..5623683 100644
9754--- a/arch/x86/include/asm/atomic64_64.h
9755+++ b/arch/x86/include/asm/atomic64_64.h
9756@@ -18,7 +18,19 @@
9757 */
9758 static inline long atomic64_read(const atomic64_t *v)
9759 {
9760- return (*(volatile long *)&(v)->counter);
9761+ return (*(volatile const long *)&(v)->counter);
9762+}
9763+
9764+/**
9765+ * atomic64_read_unchecked - read atomic64 variable
9766+ * @v: pointer of type atomic64_unchecked_t
9767+ *
9768+ * Atomically reads the value of @v.
9769+ * Doesn't imply a read memory barrier.
9770+ */
9771+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9772+{
9773+ return (*(volatile const long *)&(v)->counter);
9774 }
9775
9776 /**
9777@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9778 }
9779
9780 /**
9781+ * atomic64_set_unchecked - set atomic64 variable
9782+ * @v: pointer to type atomic64_unchecked_t
9783+ * @i: required value
9784+ *
9785+ * Atomically sets the value of @v to @i.
9786+ */
9787+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9788+{
9789+ v->counter = i;
9790+}
9791+
9792+/**
9793 * atomic64_add - add integer to atomic64 variable
9794 * @i: integer value to add
9795 * @v: pointer to type atomic64_t
9796@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9797 */
9798 static inline void atomic64_add(long i, atomic64_t *v)
9799 {
9800+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9801+
9802+#ifdef CONFIG_PAX_REFCOUNT
9803+ "jno 0f\n"
9804+ LOCK_PREFIX "subq %1,%0\n"
9805+ "int $4\n0:\n"
9806+ _ASM_EXTABLE(0b, 0b)
9807+#endif
9808+
9809+ : "=m" (v->counter)
9810+ : "er" (i), "m" (v->counter));
9811+}
9812+
9813+/**
9814+ * atomic64_add_unchecked - add integer to atomic64 variable
9815+ * @i: integer value to add
9816+ * @v: pointer to type atomic64_unchecked_t
9817+ *
9818+ * Atomically adds @i to @v.
9819+ */
9820+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9821+{
9822 asm volatile(LOCK_PREFIX "addq %1,%0"
9823 : "=m" (v->counter)
9824 : "er" (i), "m" (v->counter));
9825@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9826 */
9827 static inline void atomic64_sub(long i, atomic64_t *v)
9828 {
9829- asm volatile(LOCK_PREFIX "subq %1,%0"
9830+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9831+
9832+#ifdef CONFIG_PAX_REFCOUNT
9833+ "jno 0f\n"
9834+ LOCK_PREFIX "addq %1,%0\n"
9835+ "int $4\n0:\n"
9836+ _ASM_EXTABLE(0b, 0b)
9837+#endif
9838+
9839+ : "=m" (v->counter)
9840+ : "er" (i), "m" (v->counter));
9841+}
9842+
9843+/**
9844+ * atomic64_sub_unchecked - subtract the atomic64 variable
9845+ * @i: integer value to subtract
9846+ * @v: pointer to type atomic64_unchecked_t
9847+ *
9848+ * Atomically subtracts @i from @v.
9849+ */
9850+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9851+{
9852+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9853 : "=m" (v->counter)
9854 : "er" (i), "m" (v->counter));
9855 }
9856@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9857 {
9858 unsigned char c;
9859
9860- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9861+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9862+
9863+#ifdef CONFIG_PAX_REFCOUNT
9864+ "jno 0f\n"
9865+ LOCK_PREFIX "addq %2,%0\n"
9866+ "int $4\n0:\n"
9867+ _ASM_EXTABLE(0b, 0b)
9868+#endif
9869+
9870+ "sete %1\n"
9871 : "=m" (v->counter), "=qm" (c)
9872 : "er" (i), "m" (v->counter) : "memory");
9873 return c;
9874@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9875 */
9876 static inline void atomic64_inc(atomic64_t *v)
9877 {
9878+ asm volatile(LOCK_PREFIX "incq %0\n"
9879+
9880+#ifdef CONFIG_PAX_REFCOUNT
9881+ "jno 0f\n"
9882+ LOCK_PREFIX "decq %0\n"
9883+ "int $4\n0:\n"
9884+ _ASM_EXTABLE(0b, 0b)
9885+#endif
9886+
9887+ : "=m" (v->counter)
9888+ : "m" (v->counter));
9889+}
9890+
9891+/**
9892+ * atomic64_inc_unchecked - increment atomic64 variable
9893+ * @v: pointer to type atomic64_unchecked_t
9894+ *
9895+ * Atomically increments @v by 1.
9896+ */
9897+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9898+{
9899 asm volatile(LOCK_PREFIX "incq %0"
9900 : "=m" (v->counter)
9901 : "m" (v->counter));
9902@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9903 */
9904 static inline void atomic64_dec(atomic64_t *v)
9905 {
9906- asm volatile(LOCK_PREFIX "decq %0"
9907+ asm volatile(LOCK_PREFIX "decq %0\n"
9908+
9909+#ifdef CONFIG_PAX_REFCOUNT
9910+ "jno 0f\n"
9911+ LOCK_PREFIX "incq %0\n"
9912+ "int $4\n0:\n"
9913+ _ASM_EXTABLE(0b, 0b)
9914+#endif
9915+
9916+ : "=m" (v->counter)
9917+ : "m" (v->counter));
9918+}
9919+
9920+/**
9921+ * atomic64_dec_unchecked - decrement atomic64 variable
9922+ * @v: pointer to type atomic64_t
9923+ *
9924+ * Atomically decrements @v by 1.
9925+ */
9926+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9927+{
9928+ asm volatile(LOCK_PREFIX "decq %0\n"
9929 : "=m" (v->counter)
9930 : "m" (v->counter));
9931 }
9932@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9933 {
9934 unsigned char c;
9935
9936- asm volatile(LOCK_PREFIX "decq %0; sete %1"
9937+ asm volatile(LOCK_PREFIX "decq %0\n"
9938+
9939+#ifdef CONFIG_PAX_REFCOUNT
9940+ "jno 0f\n"
9941+ LOCK_PREFIX "incq %0\n"
9942+ "int $4\n0:\n"
9943+ _ASM_EXTABLE(0b, 0b)
9944+#endif
9945+
9946+ "sete %1\n"
9947 : "=m" (v->counter), "=qm" (c)
9948 : "m" (v->counter) : "memory");
9949 return c != 0;
9950@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9951 {
9952 unsigned char c;
9953
9954- asm volatile(LOCK_PREFIX "incq %0; sete %1"
9955+ asm volatile(LOCK_PREFIX "incq %0\n"
9956+
9957+#ifdef CONFIG_PAX_REFCOUNT
9958+ "jno 0f\n"
9959+ LOCK_PREFIX "decq %0\n"
9960+ "int $4\n0:\n"
9961+ _ASM_EXTABLE(0b, 0b)
9962+#endif
9963+
9964+ "sete %1\n"
9965 : "=m" (v->counter), "=qm" (c)
9966 : "m" (v->counter) : "memory");
9967 return c != 0;
9968@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9969 {
9970 unsigned char c;
9971
9972- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9973+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
9974+
9975+#ifdef CONFIG_PAX_REFCOUNT
9976+ "jno 0f\n"
9977+ LOCK_PREFIX "subq %2,%0\n"
9978+ "int $4\n0:\n"
9979+ _ASM_EXTABLE(0b, 0b)
9980+#endif
9981+
9982+ "sets %1\n"
9983 : "=m" (v->counter), "=qm" (c)
9984 : "er" (i), "m" (v->counter) : "memory");
9985 return c;
9986@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9987 */
9988 static inline long atomic64_add_return(long i, atomic64_t *v)
9989 {
9990+ return i + xadd_check_overflow(&v->counter, i);
9991+}
9992+
9993+/**
9994+ * atomic64_add_return_unchecked - add and return
9995+ * @i: integer value to add
9996+ * @v: pointer to type atomic64_unchecked_t
9997+ *
9998+ * Atomically adds @i to @v and returns @i + @v
9999+ */
10000+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10001+{
10002 return i + xadd(&v->counter, i);
10003 }
10004
10005@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10006 }
10007
10008 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10009+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10010+{
10011+ return atomic64_add_return_unchecked(1, v);
10012+}
10013 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10014
10015 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10016@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10017 return cmpxchg(&v->counter, old, new);
10018 }
10019
10020+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10021+{
10022+ return cmpxchg(&v->counter, old, new);
10023+}
10024+
10025 static inline long atomic64_xchg(atomic64_t *v, long new)
10026 {
10027 return xchg(&v->counter, new);
10028@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10029 */
10030 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10031 {
10032- long c, old;
10033+ long c, old, new;
10034 c = atomic64_read(v);
10035 for (;;) {
10036- if (unlikely(c == (u)))
10037+ if (unlikely(c == u))
10038 break;
10039- old = atomic64_cmpxchg((v), c, c + (a));
10040+
10041+ asm volatile("add %2,%0\n"
10042+
10043+#ifdef CONFIG_PAX_REFCOUNT
10044+ "jno 0f\n"
10045+ "sub %2,%0\n"
10046+ "int $4\n0:\n"
10047+ _ASM_EXTABLE(0b, 0b)
10048+#endif
10049+
10050+ : "=r" (new)
10051+ : "0" (c), "ir" (a));
10052+
10053+ old = atomic64_cmpxchg(v, c, new);
10054 if (likely(old == c))
10055 break;
10056 c = old;
10057 }
10058- return c != (u);
10059+ return c != u;
10060 }
10061
10062 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10063diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10064index a6983b2..63f48a2 100644
10065--- a/arch/x86/include/asm/bitops.h
10066+++ b/arch/x86/include/asm/bitops.h
10067@@ -40,7 +40,7 @@
10068 * a mask operation on a byte.
10069 */
10070 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10071-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10072+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10073 #define CONST_MASK(nr) (1 << ((nr) & 7))
10074
10075 /**
10076diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10077index b13fe63..0dab13a 100644
10078--- a/arch/x86/include/asm/boot.h
10079+++ b/arch/x86/include/asm/boot.h
10080@@ -11,10 +11,15 @@
10081 #include <asm/pgtable_types.h>
10082
10083 /* Physical address where kernel should be loaded. */
10084-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10085+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10086 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10087 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10088
10089+#ifndef __ASSEMBLY__
10090+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10091+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10092+#endif
10093+
10094 /* Minimum kernel alignment, as a power of two */
10095 #ifdef CONFIG_X86_64
10096 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10097diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10098index 48f99f1..d78ebf9 100644
10099--- a/arch/x86/include/asm/cache.h
10100+++ b/arch/x86/include/asm/cache.h
10101@@ -5,12 +5,13 @@
10102
10103 /* L1 cache line size */
10104 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10105-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10106+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10107
10108 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10109+#define __read_only __attribute__((__section__(".data..read_only")))
10110
10111 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10112-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10113+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10114
10115 #ifdef CONFIG_X86_VSMP
10116 #ifdef CONFIG_SMP
10117diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10118index 9863ee3..4a1f8e1 100644
10119--- a/arch/x86/include/asm/cacheflush.h
10120+++ b/arch/x86/include/asm/cacheflush.h
10121@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10122 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10123
10124 if (pg_flags == _PGMT_DEFAULT)
10125- return -1;
10126+ return ~0UL;
10127 else if (pg_flags == _PGMT_WC)
10128 return _PAGE_CACHE_WC;
10129 else if (pg_flags == _PGMT_UC_MINUS)
10130diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10131index 46fc474..b02b0f9 100644
10132--- a/arch/x86/include/asm/checksum_32.h
10133+++ b/arch/x86/include/asm/checksum_32.h
10134@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10135 int len, __wsum sum,
10136 int *src_err_ptr, int *dst_err_ptr);
10137
10138+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10139+ int len, __wsum sum,
10140+ int *src_err_ptr, int *dst_err_ptr);
10141+
10142+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10143+ int len, __wsum sum,
10144+ int *src_err_ptr, int *dst_err_ptr);
10145+
10146 /*
10147 * Note: when you get a NULL pointer exception here this means someone
10148 * passed in an incorrect kernel address to one of these functions.
10149@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10150 int *err_ptr)
10151 {
10152 might_sleep();
10153- return csum_partial_copy_generic((__force void *)src, dst,
10154+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
10155 len, sum, err_ptr, NULL);
10156 }
10157
10158@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10159 {
10160 might_sleep();
10161 if (access_ok(VERIFY_WRITE, dst, len))
10162- return csum_partial_copy_generic(src, (__force void *)dst,
10163+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10164 len, sum, NULL, err_ptr);
10165
10166 if (len)
10167diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10168index 99480e5..d81165b 100644
10169--- a/arch/x86/include/asm/cmpxchg.h
10170+++ b/arch/x86/include/asm/cmpxchg.h
10171@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10172 __compiletime_error("Bad argument size for cmpxchg");
10173 extern void __xadd_wrong_size(void)
10174 __compiletime_error("Bad argument size for xadd");
10175+extern void __xadd_check_overflow_wrong_size(void)
10176+ __compiletime_error("Bad argument size for xadd_check_overflow");
10177 extern void __add_wrong_size(void)
10178 __compiletime_error("Bad argument size for add");
10179+extern void __add_check_overflow_wrong_size(void)
10180+ __compiletime_error("Bad argument size for add_check_overflow");
10181
10182 /*
10183 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10184@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10185 __ret; \
10186 })
10187
10188+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10189+ ({ \
10190+ __typeof__ (*(ptr)) __ret = (arg); \
10191+ switch (sizeof(*(ptr))) { \
10192+ case __X86_CASE_L: \
10193+ asm volatile (lock #op "l %0, %1\n" \
10194+ "jno 0f\n" \
10195+ "mov %0,%1\n" \
10196+ "int $4\n0:\n" \
10197+ _ASM_EXTABLE(0b, 0b) \
10198+ : "+r" (__ret), "+m" (*(ptr)) \
10199+ : : "memory", "cc"); \
10200+ break; \
10201+ case __X86_CASE_Q: \
10202+ asm volatile (lock #op "q %q0, %1\n" \
10203+ "jno 0f\n" \
10204+ "mov %0,%1\n" \
10205+ "int $4\n0:\n" \
10206+ _ASM_EXTABLE(0b, 0b) \
10207+ : "+r" (__ret), "+m" (*(ptr)) \
10208+ : : "memory", "cc"); \
10209+ break; \
10210+ default: \
10211+ __ ## op ## _check_overflow_wrong_size(); \
10212+ } \
10213+ __ret; \
10214+ })
10215+
10216 /*
10217 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10218 * Since this is generally used to protect other memory information, we
10219@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10220 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10221 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10222
10223+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10224+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10225+
10226 #define __add(ptr, inc, lock) \
10227 ({ \
10228 __typeof__ (*(ptr)) __ret = (inc); \
10229diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10230index f91e80f..7731066 100644
10231--- a/arch/x86/include/asm/cpufeature.h
10232+++ b/arch/x86/include/asm/cpufeature.h
10233@@ -202,11 +202,12 @@
10234 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10235 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10236 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10237-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10238+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10239 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10240 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10241 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10242 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10243+#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10244
10245 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10246
10247@@ -371,7 +372,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10248 ".section .discard,\"aw\",@progbits\n"
10249 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10250 ".previous\n"
10251- ".section .altinstr_replacement,\"ax\"\n"
10252+ ".section .altinstr_replacement,\"a\"\n"
10253 "3: movb $1,%0\n"
10254 "4:\n"
10255 ".previous\n"
10256diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10257index 8bf1c06..f723dfd 100644
10258--- a/arch/x86/include/asm/desc.h
10259+++ b/arch/x86/include/asm/desc.h
10260@@ -4,6 +4,7 @@
10261 #include <asm/desc_defs.h>
10262 #include <asm/ldt.h>
10263 #include <asm/mmu.h>
10264+#include <asm/pgtable.h>
10265
10266 #include <linux/smp.h>
10267 #include <linux/percpu.h>
10268@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10269
10270 desc->type = (info->read_exec_only ^ 1) << 1;
10271 desc->type |= info->contents << 2;
10272+ desc->type |= info->seg_not_present ^ 1;
10273
10274 desc->s = 1;
10275 desc->dpl = 0x3;
10276@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10277 }
10278
10279 extern struct desc_ptr idt_descr;
10280-extern gate_desc idt_table[];
10281 extern struct desc_ptr nmi_idt_descr;
10282-extern gate_desc nmi_idt_table[];
10283-
10284-struct gdt_page {
10285- struct desc_struct gdt[GDT_ENTRIES];
10286-} __attribute__((aligned(PAGE_SIZE)));
10287-
10288-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10289+extern gate_desc idt_table[256];
10290+extern gate_desc nmi_idt_table[256];
10291
10292+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10293 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10294 {
10295- return per_cpu(gdt_page, cpu).gdt;
10296+ return cpu_gdt_table[cpu];
10297 }
10298
10299 #ifdef CONFIG_X86_64
10300@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10301 unsigned long base, unsigned dpl, unsigned flags,
10302 unsigned short seg)
10303 {
10304- gate->a = (seg << 16) | (base & 0xffff);
10305- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10306+ gate->gate.offset_low = base;
10307+ gate->gate.seg = seg;
10308+ gate->gate.reserved = 0;
10309+ gate->gate.type = type;
10310+ gate->gate.s = 0;
10311+ gate->gate.dpl = dpl;
10312+ gate->gate.p = 1;
10313+ gate->gate.offset_high = base >> 16;
10314 }
10315
10316 #endif
10317@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10318
10319 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10320 {
10321+ pax_open_kernel();
10322 memcpy(&idt[entry], gate, sizeof(*gate));
10323+ pax_close_kernel();
10324 }
10325
10326 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10327 {
10328+ pax_open_kernel();
10329 memcpy(&ldt[entry], desc, 8);
10330+ pax_close_kernel();
10331 }
10332
10333 static inline void
10334@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10335 default: size = sizeof(*gdt); break;
10336 }
10337
10338+ pax_open_kernel();
10339 memcpy(&gdt[entry], desc, size);
10340+ pax_close_kernel();
10341 }
10342
10343 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10344@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10345
10346 static inline void native_load_tr_desc(void)
10347 {
10348+ pax_open_kernel();
10349 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10350+ pax_close_kernel();
10351 }
10352
10353 static inline void native_load_gdt(const struct desc_ptr *dtr)
10354@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10355 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10356 unsigned int i;
10357
10358+ pax_open_kernel();
10359 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10360 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10361+ pax_close_kernel();
10362 }
10363
10364 #define _LDT_empty(info) \
10365@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10366 }
10367
10368 #ifdef CONFIG_X86_64
10369-static inline void set_nmi_gate(int gate, void *addr)
10370+static inline void set_nmi_gate(int gate, const void *addr)
10371 {
10372 gate_desc s;
10373
10374@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10375 }
10376 #endif
10377
10378-static inline void _set_gate(int gate, unsigned type, void *addr,
10379+static inline void _set_gate(int gate, unsigned type, const void *addr,
10380 unsigned dpl, unsigned ist, unsigned seg)
10381 {
10382 gate_desc s;
10383@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10384 * Pentium F0 0F bugfix can have resulted in the mapped
10385 * IDT being write-protected.
10386 */
10387-static inline void set_intr_gate(unsigned int n, void *addr)
10388+static inline void set_intr_gate(unsigned int n, const void *addr)
10389 {
10390 BUG_ON((unsigned)n > 0xFF);
10391 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10392@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10393 /*
10394 * This routine sets up an interrupt gate at directory privilege level 3.
10395 */
10396-static inline void set_system_intr_gate(unsigned int n, void *addr)
10397+static inline void set_system_intr_gate(unsigned int n, const void *addr)
10398 {
10399 BUG_ON((unsigned)n > 0xFF);
10400 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10401 }
10402
10403-static inline void set_system_trap_gate(unsigned int n, void *addr)
10404+static inline void set_system_trap_gate(unsigned int n, const void *addr)
10405 {
10406 BUG_ON((unsigned)n > 0xFF);
10407 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10408 }
10409
10410-static inline void set_trap_gate(unsigned int n, void *addr)
10411+static inline void set_trap_gate(unsigned int n, const void *addr)
10412 {
10413 BUG_ON((unsigned)n > 0xFF);
10414 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10415@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10416 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10417 {
10418 BUG_ON((unsigned)n > 0xFF);
10419- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10420+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10421 }
10422
10423-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10424+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10425 {
10426 BUG_ON((unsigned)n > 0xFF);
10427 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10428 }
10429
10430-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10431+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10432 {
10433 BUG_ON((unsigned)n > 0xFF);
10434 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10435 }
10436
10437+#ifdef CONFIG_X86_32
10438+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10439+{
10440+ struct desc_struct d;
10441+
10442+ if (likely(limit))
10443+ limit = (limit - 1UL) >> PAGE_SHIFT;
10444+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
10445+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10446+}
10447+#endif
10448+
10449 #endif /* _ASM_X86_DESC_H */
10450diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10451index 278441f..b95a174 100644
10452--- a/arch/x86/include/asm/desc_defs.h
10453+++ b/arch/x86/include/asm/desc_defs.h
10454@@ -31,6 +31,12 @@ struct desc_struct {
10455 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10456 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10457 };
10458+ struct {
10459+ u16 offset_low;
10460+ u16 seg;
10461+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10462+ unsigned offset_high: 16;
10463+ } gate;
10464 };
10465 } __attribute__((packed));
10466
10467diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10468index 3778256..c5d4fce 100644
10469--- a/arch/x86/include/asm/e820.h
10470+++ b/arch/x86/include/asm/e820.h
10471@@ -69,7 +69,7 @@ struct e820map {
10472 #define ISA_START_ADDRESS 0xa0000
10473 #define ISA_END_ADDRESS 0x100000
10474
10475-#define BIOS_BEGIN 0x000a0000
10476+#define BIOS_BEGIN 0x000c0000
10477 #define BIOS_END 0x00100000
10478
10479 #define BIOS_ROM_BASE 0xffe00000
10480diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10481index 5939f44..f8845f6 100644
10482--- a/arch/x86/include/asm/elf.h
10483+++ b/arch/x86/include/asm/elf.h
10484@@ -243,7 +243,25 @@ extern int force_personality32;
10485 the loader. We need to make sure that it is out of the way of the program
10486 that it will "exec", and that there is sufficient room for the brk. */
10487
10488+#ifdef CONFIG_PAX_SEGMEXEC
10489+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10490+#else
10491 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10492+#endif
10493+
10494+#ifdef CONFIG_PAX_ASLR
10495+#ifdef CONFIG_X86_32
10496+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10497+
10498+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10499+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10500+#else
10501+#define PAX_ELF_ET_DYN_BASE 0x400000UL
10502+
10503+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10504+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10505+#endif
10506+#endif
10507
10508 /* This yields a mask that user programs can use to figure out what
10509 instruction set this CPU supports. This could be done in user space,
10510@@ -296,16 +314,12 @@ do { \
10511
10512 #define ARCH_DLINFO \
10513 do { \
10514- if (vdso_enabled) \
10515- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10516- (unsigned long)current->mm->context.vdso); \
10517+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10518 } while (0)
10519
10520 #define ARCH_DLINFO_X32 \
10521 do { \
10522- if (vdso_enabled) \
10523- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10524- (unsigned long)current->mm->context.vdso); \
10525+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10526 } while (0)
10527
10528 #define AT_SYSINFO 32
10529@@ -320,7 +334,7 @@ else \
10530
10531 #endif /* !CONFIG_X86_32 */
10532
10533-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10534+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10535
10536 #define VDSO_ENTRY \
10537 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10538@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10539 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10540 #define compat_arch_setup_additional_pages syscall32_setup_pages
10541
10542-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10543-#define arch_randomize_brk arch_randomize_brk
10544-
10545 /*
10546 * True on X86_32 or when emulating IA32 on X86_64
10547 */
10548diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10549index cc70c1c..d96d011 100644
10550--- a/arch/x86/include/asm/emergency-restart.h
10551+++ b/arch/x86/include/asm/emergency-restart.h
10552@@ -15,6 +15,6 @@ enum reboot_type {
10553
10554 extern enum reboot_type reboot_type;
10555
10556-extern void machine_emergency_restart(void);
10557+extern void machine_emergency_restart(void) __noreturn;
10558
10559 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10560diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10561index 75f4c6d..ee3eb8f 100644
10562--- a/arch/x86/include/asm/fpu-internal.h
10563+++ b/arch/x86/include/asm/fpu-internal.h
10564@@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10565 {
10566 int err;
10567
10568+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10569+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10570+ fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10571+#endif
10572+
10573 /* See comment in fxsave() below. */
10574 #ifdef CONFIG_AS_FXSAVEQ
10575 asm volatile("1: fxrstorq %[fx]\n\t"
10576@@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10577 {
10578 int err;
10579
10580+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10581+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10582+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10583+#endif
10584+
10585 /*
10586 * Clear the bytes not touched by the fxsave and reserved
10587 * for the SW usage.
10588@@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10589 "emms\n\t" /* clear stack tags */
10590 "fildl %P[addr]", /* set F?P to defined value */
10591 X86_FEATURE_FXSAVE_LEAK,
10592- [addr] "m" (tsk->thread.fpu.has_fpu));
10593+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10594
10595 return fpu_restore_checking(&tsk->thread.fpu);
10596 }
10597diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10598index 71ecbcb..bac10b7 100644
10599--- a/arch/x86/include/asm/futex.h
10600+++ b/arch/x86/include/asm/futex.h
10601@@ -11,16 +11,18 @@
10602 #include <asm/processor.h>
10603
10604 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10605+ typecheck(u32 __user *, uaddr); \
10606 asm volatile("1:\t" insn "\n" \
10607 "2:\t.section .fixup,\"ax\"\n" \
10608 "3:\tmov\t%3, %1\n" \
10609 "\tjmp\t2b\n" \
10610 "\t.previous\n" \
10611 _ASM_EXTABLE(1b, 3b) \
10612- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10613+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10614 : "i" (-EFAULT), "0" (oparg), "1" (0))
10615
10616 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10617+ typecheck(u32 __user *, uaddr); \
10618 asm volatile("1:\tmovl %2, %0\n" \
10619 "\tmovl\t%0, %3\n" \
10620 "\t" insn "\n" \
10621@@ -33,7 +35,7 @@
10622 _ASM_EXTABLE(1b, 4b) \
10623 _ASM_EXTABLE(2b, 4b) \
10624 : "=&a" (oldval), "=&r" (ret), \
10625- "+m" (*uaddr), "=&r" (tem) \
10626+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10627 : "r" (oparg), "i" (-EFAULT), "1" (0))
10628
10629 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10630@@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10631
10632 switch (op) {
10633 case FUTEX_OP_SET:
10634- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10635+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10636 break;
10637 case FUTEX_OP_ADD:
10638- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10639+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10640 uaddr, oparg);
10641 break;
10642 case FUTEX_OP_OR:
10643@@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10644 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10645 return -EFAULT;
10646
10647- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10648+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10649 "2:\t.section .fixup, \"ax\"\n"
10650 "3:\tmov %3, %0\n"
10651 "\tjmp 2b\n"
10652 "\t.previous\n"
10653 _ASM_EXTABLE(1b, 3b)
10654- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10655+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10656 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10657 : "memory"
10658 );
10659diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10660index eb92a6e..b98b2f4 100644
10661--- a/arch/x86/include/asm/hw_irq.h
10662+++ b/arch/x86/include/asm/hw_irq.h
10663@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10664 extern void enable_IO_APIC(void);
10665
10666 /* Statistics */
10667-extern atomic_t irq_err_count;
10668-extern atomic_t irq_mis_count;
10669+extern atomic_unchecked_t irq_err_count;
10670+extern atomic_unchecked_t irq_mis_count;
10671
10672 /* EISA */
10673 extern void eisa_set_level_irq(unsigned int irq);
10674diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10675index d8e8eef..99f81ae 100644
10676--- a/arch/x86/include/asm/io.h
10677+++ b/arch/x86/include/asm/io.h
10678@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10679
10680 #include <linux/vmalloc.h>
10681
10682+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10683+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10684+{
10685+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10686+}
10687+
10688+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10689+{
10690+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10691+}
10692+
10693 /*
10694 * Convert a virtual cached pointer to an uncached pointer
10695 */
10696diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10697index bba3cf8..06bc8da 100644
10698--- a/arch/x86/include/asm/irqflags.h
10699+++ b/arch/x86/include/asm/irqflags.h
10700@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10701 sti; \
10702 sysexit
10703
10704+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10705+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10706+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10707+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10708+
10709 #else
10710 #define INTERRUPT_RETURN iret
10711 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10712diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10713index 5478825..839e88c 100644
10714--- a/arch/x86/include/asm/kprobes.h
10715+++ b/arch/x86/include/asm/kprobes.h
10716@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10717 #define RELATIVEJUMP_SIZE 5
10718 #define RELATIVECALL_OPCODE 0xe8
10719 #define RELATIVE_ADDR_SIZE 4
10720-#define MAX_STACK_SIZE 64
10721-#define MIN_STACK_SIZE(ADDR) \
10722- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10723- THREAD_SIZE - (unsigned long)(ADDR))) \
10724- ? (MAX_STACK_SIZE) \
10725- : (((unsigned long)current_thread_info()) + \
10726- THREAD_SIZE - (unsigned long)(ADDR)))
10727+#define MAX_STACK_SIZE 64UL
10728+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10729
10730 #define flush_insn_slot(p) do { } while (0)
10731
10732diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10733index db7c1f2..92f130a 100644
10734--- a/arch/x86/include/asm/kvm_host.h
10735+++ b/arch/x86/include/asm/kvm_host.h
10736@@ -680,7 +680,7 @@ struct kvm_x86_ops {
10737 int (*check_intercept)(struct kvm_vcpu *vcpu,
10738 struct x86_instruction_info *info,
10739 enum x86_intercept_stage stage);
10740-};
10741+} __do_const;
10742
10743 struct kvm_arch_async_pf {
10744 u32 token;
10745diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10746index c8bed0d..e5721fa 100644
10747--- a/arch/x86/include/asm/local.h
10748+++ b/arch/x86/include/asm/local.h
10749@@ -17,26 +17,58 @@ typedef struct {
10750
10751 static inline void local_inc(local_t *l)
10752 {
10753- asm volatile(_ASM_INC "%0"
10754+ asm volatile(_ASM_INC "%0\n"
10755+
10756+#ifdef CONFIG_PAX_REFCOUNT
10757+ "jno 0f\n"
10758+ _ASM_DEC "%0\n"
10759+ "int $4\n0:\n"
10760+ _ASM_EXTABLE(0b, 0b)
10761+#endif
10762+
10763 : "+m" (l->a.counter));
10764 }
10765
10766 static inline void local_dec(local_t *l)
10767 {
10768- asm volatile(_ASM_DEC "%0"
10769+ asm volatile(_ASM_DEC "%0\n"
10770+
10771+#ifdef CONFIG_PAX_REFCOUNT
10772+ "jno 0f\n"
10773+ _ASM_INC "%0\n"
10774+ "int $4\n0:\n"
10775+ _ASM_EXTABLE(0b, 0b)
10776+#endif
10777+
10778 : "+m" (l->a.counter));
10779 }
10780
10781 static inline void local_add(long i, local_t *l)
10782 {
10783- asm volatile(_ASM_ADD "%1,%0"
10784+ asm volatile(_ASM_ADD "%1,%0\n"
10785+
10786+#ifdef CONFIG_PAX_REFCOUNT
10787+ "jno 0f\n"
10788+ _ASM_SUB "%1,%0\n"
10789+ "int $4\n0:\n"
10790+ _ASM_EXTABLE(0b, 0b)
10791+#endif
10792+
10793 : "+m" (l->a.counter)
10794 : "ir" (i));
10795 }
10796
10797 static inline void local_sub(long i, local_t *l)
10798 {
10799- asm volatile(_ASM_SUB "%1,%0"
10800+ asm volatile(_ASM_SUB "%1,%0\n"
10801+
10802+#ifdef CONFIG_PAX_REFCOUNT
10803+ "jno 0f\n"
10804+ _ASM_ADD "%1,%0\n"
10805+ "int $4\n0:\n"
10806+ _ASM_EXTABLE(0b, 0b)
10807+#endif
10808+
10809 : "+m" (l->a.counter)
10810 : "ir" (i));
10811 }
10812@@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10813 {
10814 unsigned char c;
10815
10816- asm volatile(_ASM_SUB "%2,%0; sete %1"
10817+ asm volatile(_ASM_SUB "%2,%0\n"
10818+
10819+#ifdef CONFIG_PAX_REFCOUNT
10820+ "jno 0f\n"
10821+ _ASM_ADD "%2,%0\n"
10822+ "int $4\n0:\n"
10823+ _ASM_EXTABLE(0b, 0b)
10824+#endif
10825+
10826+ "sete %1\n"
10827 : "+m" (l->a.counter), "=qm" (c)
10828 : "ir" (i) : "memory");
10829 return c;
10830@@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10831 {
10832 unsigned char c;
10833
10834- asm volatile(_ASM_DEC "%0; sete %1"
10835+ asm volatile(_ASM_DEC "%0\n"
10836+
10837+#ifdef CONFIG_PAX_REFCOUNT
10838+ "jno 0f\n"
10839+ _ASM_INC "%0\n"
10840+ "int $4\n0:\n"
10841+ _ASM_EXTABLE(0b, 0b)
10842+#endif
10843+
10844+ "sete %1\n"
10845 : "+m" (l->a.counter), "=qm" (c)
10846 : : "memory");
10847 return c != 0;
10848@@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10849 {
10850 unsigned char c;
10851
10852- asm volatile(_ASM_INC "%0; sete %1"
10853+ asm volatile(_ASM_INC "%0\n"
10854+
10855+#ifdef CONFIG_PAX_REFCOUNT
10856+ "jno 0f\n"
10857+ _ASM_DEC "%0\n"
10858+ "int $4\n0:\n"
10859+ _ASM_EXTABLE(0b, 0b)
10860+#endif
10861+
10862+ "sete %1\n"
10863 : "+m" (l->a.counter), "=qm" (c)
10864 : : "memory");
10865 return c != 0;
10866@@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10867 {
10868 unsigned char c;
10869
10870- asm volatile(_ASM_ADD "%2,%0; sets %1"
10871+ asm volatile(_ASM_ADD "%2,%0\n"
10872+
10873+#ifdef CONFIG_PAX_REFCOUNT
10874+ "jno 0f\n"
10875+ _ASM_SUB "%2,%0\n"
10876+ "int $4\n0:\n"
10877+ _ASM_EXTABLE(0b, 0b)
10878+#endif
10879+
10880+ "sets %1\n"
10881 : "+m" (l->a.counter), "=qm" (c)
10882 : "ir" (i) : "memory");
10883 return c;
10884@@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10885 #endif
10886 /* Modern 486+ processor */
10887 __i = i;
10888- asm volatile(_ASM_XADD "%0, %1;"
10889+ asm volatile(_ASM_XADD "%0, %1\n"
10890+
10891+#ifdef CONFIG_PAX_REFCOUNT
10892+ "jno 0f\n"
10893+ _ASM_MOV "%0,%1\n"
10894+ "int $4\n0:\n"
10895+ _ASM_EXTABLE(0b, 0b)
10896+#endif
10897+
10898 : "+r" (i), "+m" (l->a.counter)
10899 : : "memory");
10900 return i + __i;
10901diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10902index 593e51d..fa69c9a 100644
10903--- a/arch/x86/include/asm/mman.h
10904+++ b/arch/x86/include/asm/mman.h
10905@@ -5,4 +5,14 @@
10906
10907 #include <asm-generic/mman.h>
10908
10909+#ifdef __KERNEL__
10910+#ifndef __ASSEMBLY__
10911+#ifdef CONFIG_X86_32
10912+#define arch_mmap_check i386_mmap_check
10913+int i386_mmap_check(unsigned long addr, unsigned long len,
10914+ unsigned long flags);
10915+#endif
10916+#endif
10917+#endif
10918+
10919 #endif /* _ASM_X86_MMAN_H */
10920diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10921index 5f55e69..e20bfb1 100644
10922--- a/arch/x86/include/asm/mmu.h
10923+++ b/arch/x86/include/asm/mmu.h
10924@@ -9,7 +9,7 @@
10925 * we put the segment information here.
10926 */
10927 typedef struct {
10928- void *ldt;
10929+ struct desc_struct *ldt;
10930 int size;
10931
10932 #ifdef CONFIG_X86_64
10933@@ -18,7 +18,19 @@ typedef struct {
10934 #endif
10935
10936 struct mutex lock;
10937- void *vdso;
10938+ unsigned long vdso;
10939+
10940+#ifdef CONFIG_X86_32
10941+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10942+ unsigned long user_cs_base;
10943+ unsigned long user_cs_limit;
10944+
10945+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10946+ cpumask_t cpu_user_cs_mask;
10947+#endif
10948+
10949+#endif
10950+#endif
10951 } mm_context_t;
10952
10953 #ifdef CONFIG_SMP
10954diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10955index cdbf367..adb37ac 100644
10956--- a/arch/x86/include/asm/mmu_context.h
10957+++ b/arch/x86/include/asm/mmu_context.h
10958@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10959
10960 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10961 {
10962+
10963+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10964+ unsigned int i;
10965+ pgd_t *pgd;
10966+
10967+ pax_open_kernel();
10968+ pgd = get_cpu_pgd(smp_processor_id());
10969+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10970+ set_pgd_batched(pgd+i, native_make_pgd(0));
10971+ pax_close_kernel();
10972+#endif
10973+
10974 #ifdef CONFIG_SMP
10975 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10976 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10977@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10978 struct task_struct *tsk)
10979 {
10980 unsigned cpu = smp_processor_id();
10981+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10982+ int tlbstate = TLBSTATE_OK;
10983+#endif
10984
10985 if (likely(prev != next)) {
10986 #ifdef CONFIG_SMP
10987+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10988+ tlbstate = this_cpu_read(cpu_tlbstate.state);
10989+#endif
10990 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10991 this_cpu_write(cpu_tlbstate.active_mm, next);
10992 #endif
10993 cpumask_set_cpu(cpu, mm_cpumask(next));
10994
10995 /* Re-load page tables */
10996+#ifdef CONFIG_PAX_PER_CPU_PGD
10997+ pax_open_kernel();
10998+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10999+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11000+ pax_close_kernel();
11001+ load_cr3(get_cpu_pgd(cpu));
11002+#else
11003 load_cr3(next->pgd);
11004+#endif
11005
11006 /* stop flush ipis for the previous mm */
11007 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11008@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11009 */
11010 if (unlikely(prev->context.ldt != next->context.ldt))
11011 load_LDT_nolock(&next->context);
11012- }
11013+
11014+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11015+ if (!(__supported_pte_mask & _PAGE_NX)) {
11016+ smp_mb__before_clear_bit();
11017+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11018+ smp_mb__after_clear_bit();
11019+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11020+ }
11021+#endif
11022+
11023+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11024+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11025+ prev->context.user_cs_limit != next->context.user_cs_limit))
11026+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11027 #ifdef CONFIG_SMP
11028+ else if (unlikely(tlbstate != TLBSTATE_OK))
11029+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11030+#endif
11031+#endif
11032+
11033+ }
11034 else {
11035+
11036+#ifdef CONFIG_PAX_PER_CPU_PGD
11037+ pax_open_kernel();
11038+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11039+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11040+ pax_close_kernel();
11041+ load_cr3(get_cpu_pgd(cpu));
11042+#endif
11043+
11044+#ifdef CONFIG_SMP
11045 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11046 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11047
11048@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11049 * tlb flush IPI delivery. We must reload CR3
11050 * to make sure to use no freed page tables.
11051 */
11052+
11053+#ifndef CONFIG_PAX_PER_CPU_PGD
11054 load_cr3(next->pgd);
11055+#endif
11056+
11057 load_LDT_nolock(&next->context);
11058+
11059+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11060+ if (!(__supported_pte_mask & _PAGE_NX))
11061+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11062+#endif
11063+
11064+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11065+#ifdef CONFIG_PAX_PAGEEXEC
11066+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11067+#endif
11068+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11069+#endif
11070+
11071 }
11072+#endif
11073 }
11074-#endif
11075 }
11076
11077 #define activate_mm(prev, next) \
11078diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11079index 9eae775..c914fea 100644
11080--- a/arch/x86/include/asm/module.h
11081+++ b/arch/x86/include/asm/module.h
11082@@ -5,6 +5,7 @@
11083
11084 #ifdef CONFIG_X86_64
11085 /* X86_64 does not define MODULE_PROC_FAMILY */
11086+#define MODULE_PROC_FAMILY ""
11087 #elif defined CONFIG_M386
11088 #define MODULE_PROC_FAMILY "386 "
11089 #elif defined CONFIG_M486
11090@@ -59,8 +60,20 @@
11091 #error unknown processor family
11092 #endif
11093
11094-#ifdef CONFIG_X86_32
11095-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11096+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11097+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11098+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11099+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11100+#else
11101+#define MODULE_PAX_KERNEXEC ""
11102 #endif
11103
11104+#ifdef CONFIG_PAX_MEMORY_UDEREF
11105+#define MODULE_PAX_UDEREF "UDEREF "
11106+#else
11107+#define MODULE_PAX_UDEREF ""
11108+#endif
11109+
11110+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11111+
11112 #endif /* _ASM_X86_MODULE_H */
11113diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11114index 320f7bb..e89f8f8 100644
11115--- a/arch/x86/include/asm/page_64_types.h
11116+++ b/arch/x86/include/asm/page_64_types.h
11117@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11118
11119 /* duplicated to the one in bootmem.h */
11120 extern unsigned long max_pfn;
11121-extern unsigned long phys_base;
11122+extern const unsigned long phys_base;
11123
11124 extern unsigned long __phys_addr(unsigned long);
11125 #define __phys_reloc_hide(x) (x)
11126diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11127index 6cbbabf..11b3aed 100644
11128--- a/arch/x86/include/asm/paravirt.h
11129+++ b/arch/x86/include/asm/paravirt.h
11130@@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11131 val);
11132 }
11133
11134+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11135+{
11136+ pgdval_t val = native_pgd_val(pgd);
11137+
11138+ if (sizeof(pgdval_t) > sizeof(long))
11139+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11140+ val, (u64)val >> 32);
11141+ else
11142+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11143+ val);
11144+}
11145+
11146 static inline void pgd_clear(pgd_t *pgdp)
11147 {
11148 set_pgd(pgdp, __pgd(0));
11149@@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11150 pv_mmu_ops.set_fixmap(idx, phys, flags);
11151 }
11152
11153+#ifdef CONFIG_PAX_KERNEXEC
11154+static inline unsigned long pax_open_kernel(void)
11155+{
11156+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11157+}
11158+
11159+static inline unsigned long pax_close_kernel(void)
11160+{
11161+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11162+}
11163+#else
11164+static inline unsigned long pax_open_kernel(void) { return 0; }
11165+static inline unsigned long pax_close_kernel(void) { return 0; }
11166+#endif
11167+
11168 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11169
11170 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11171@@ -965,7 +992,7 @@ extern void default_banner(void);
11172
11173 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11174 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11175-#define PARA_INDIRECT(addr) *%cs:addr
11176+#define PARA_INDIRECT(addr) *%ss:addr
11177 #endif
11178
11179 #define INTERRUPT_RETURN \
11180@@ -1040,6 +1067,21 @@ extern void default_banner(void);
11181 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11182 CLBR_NONE, \
11183 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11184+
11185+#define GET_CR0_INTO_RDI \
11186+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11187+ mov %rax,%rdi
11188+
11189+#define SET_RDI_INTO_CR0 \
11190+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11191+
11192+#define GET_CR3_INTO_RDI \
11193+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11194+ mov %rax,%rdi
11195+
11196+#define SET_RDI_INTO_CR3 \
11197+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11198+
11199 #endif /* CONFIG_X86_32 */
11200
11201 #endif /* __ASSEMBLY__ */
11202diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11203index 8e8b9a4..f07d725 100644
11204--- a/arch/x86/include/asm/paravirt_types.h
11205+++ b/arch/x86/include/asm/paravirt_types.h
11206@@ -84,20 +84,20 @@ struct pv_init_ops {
11207 */
11208 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11209 unsigned long addr, unsigned len);
11210-};
11211+} __no_const;
11212
11213
11214 struct pv_lazy_ops {
11215 /* Set deferred update mode, used for batching operations. */
11216 void (*enter)(void);
11217 void (*leave)(void);
11218-};
11219+} __no_const;
11220
11221 struct pv_time_ops {
11222 unsigned long long (*sched_clock)(void);
11223 unsigned long long (*steal_clock)(int cpu);
11224 unsigned long (*get_tsc_khz)(void);
11225-};
11226+} __no_const;
11227
11228 struct pv_cpu_ops {
11229 /* hooks for various privileged instructions */
11230@@ -193,7 +193,7 @@ struct pv_cpu_ops {
11231
11232 void (*start_context_switch)(struct task_struct *prev);
11233 void (*end_context_switch)(struct task_struct *next);
11234-};
11235+} __no_const;
11236
11237 struct pv_irq_ops {
11238 /*
11239@@ -224,7 +224,7 @@ struct pv_apic_ops {
11240 unsigned long start_eip,
11241 unsigned long start_esp);
11242 #endif
11243-};
11244+} __no_const;
11245
11246 struct pv_mmu_ops {
11247 unsigned long (*read_cr2)(void);
11248@@ -313,6 +313,7 @@ struct pv_mmu_ops {
11249 struct paravirt_callee_save make_pud;
11250
11251 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11252+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11253 #endif /* PAGETABLE_LEVELS == 4 */
11254 #endif /* PAGETABLE_LEVELS >= 3 */
11255
11256@@ -324,6 +325,12 @@ struct pv_mmu_ops {
11257 an mfn. We can tell which is which from the index. */
11258 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11259 phys_addr_t phys, pgprot_t flags);
11260+
11261+#ifdef CONFIG_PAX_KERNEXEC
11262+ unsigned long (*pax_open_kernel)(void);
11263+ unsigned long (*pax_close_kernel)(void);
11264+#endif
11265+
11266 };
11267
11268 struct arch_spinlock;
11269@@ -334,7 +341,7 @@ struct pv_lock_ops {
11270 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11271 int (*spin_trylock)(struct arch_spinlock *lock);
11272 void (*spin_unlock)(struct arch_spinlock *lock);
11273-};
11274+} __no_const;
11275
11276 /* This contains all the paravirt structures: we get a convenient
11277 * number for each function using the offset which we use to indicate
11278diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11279index b4389a4..7024269 100644
11280--- a/arch/x86/include/asm/pgalloc.h
11281+++ b/arch/x86/include/asm/pgalloc.h
11282@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11283 pmd_t *pmd, pte_t *pte)
11284 {
11285 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11286+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11287+}
11288+
11289+static inline void pmd_populate_user(struct mm_struct *mm,
11290+ pmd_t *pmd, pte_t *pte)
11291+{
11292+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11293 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11294 }
11295
11296@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11297
11298 #ifdef CONFIG_X86_PAE
11299 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11300+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11301+{
11302+ pud_populate(mm, pudp, pmd);
11303+}
11304 #else /* !CONFIG_X86_PAE */
11305 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11306 {
11307 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11308 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11309 }
11310+
11311+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11312+{
11313+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11314+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11315+}
11316 #endif /* CONFIG_X86_PAE */
11317
11318 #if PAGETABLE_LEVELS > 3
11319@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11320 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11321 }
11322
11323+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11324+{
11325+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11326+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11327+}
11328+
11329 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11330 {
11331 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11332diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11333index 98391db..8f6984e 100644
11334--- a/arch/x86/include/asm/pgtable-2level.h
11335+++ b/arch/x86/include/asm/pgtable-2level.h
11336@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11337
11338 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11339 {
11340+ pax_open_kernel();
11341 *pmdp = pmd;
11342+ pax_close_kernel();
11343 }
11344
11345 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11346diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11347index cb00ccc..17e9054 100644
11348--- a/arch/x86/include/asm/pgtable-3level.h
11349+++ b/arch/x86/include/asm/pgtable-3level.h
11350@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11351
11352 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11353 {
11354+ pax_open_kernel();
11355 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11356+ pax_close_kernel();
11357 }
11358
11359 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11360 {
11361+ pax_open_kernel();
11362 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11363+ pax_close_kernel();
11364 }
11365
11366 /*
11367diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11368index 49afb3f..91a8c63 100644
11369--- a/arch/x86/include/asm/pgtable.h
11370+++ b/arch/x86/include/asm/pgtable.h
11371@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11372
11373 #ifndef __PAGETABLE_PUD_FOLDED
11374 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11375+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11376 #define pgd_clear(pgd) native_pgd_clear(pgd)
11377 #endif
11378
11379@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11380
11381 #define arch_end_context_switch(prev) do {} while(0)
11382
11383+#define pax_open_kernel() native_pax_open_kernel()
11384+#define pax_close_kernel() native_pax_close_kernel()
11385 #endif /* CONFIG_PARAVIRT */
11386
11387+#define __HAVE_ARCH_PAX_OPEN_KERNEL
11388+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11389+
11390+#ifdef CONFIG_PAX_KERNEXEC
11391+static inline unsigned long native_pax_open_kernel(void)
11392+{
11393+ unsigned long cr0;
11394+
11395+ preempt_disable();
11396+ barrier();
11397+ cr0 = read_cr0() ^ X86_CR0_WP;
11398+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11399+ write_cr0(cr0);
11400+ return cr0 ^ X86_CR0_WP;
11401+}
11402+
11403+static inline unsigned long native_pax_close_kernel(void)
11404+{
11405+ unsigned long cr0;
11406+
11407+ cr0 = read_cr0() ^ X86_CR0_WP;
11408+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11409+ write_cr0(cr0);
11410+ barrier();
11411+ preempt_enable_no_resched();
11412+ return cr0 ^ X86_CR0_WP;
11413+}
11414+#else
11415+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11416+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11417+#endif
11418+
11419 /*
11420 * The following only work if pte_present() is true.
11421 * Undefined behaviour if not..
11422 */
11423+static inline int pte_user(pte_t pte)
11424+{
11425+ return pte_val(pte) & _PAGE_USER;
11426+}
11427+
11428 static inline int pte_dirty(pte_t pte)
11429 {
11430 return pte_flags(pte) & _PAGE_DIRTY;
11431@@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11432 return pte_clear_flags(pte, _PAGE_RW);
11433 }
11434
11435+static inline pte_t pte_mkread(pte_t pte)
11436+{
11437+ return __pte(pte_val(pte) | _PAGE_USER);
11438+}
11439+
11440 static inline pte_t pte_mkexec(pte_t pte)
11441 {
11442- return pte_clear_flags(pte, _PAGE_NX);
11443+#ifdef CONFIG_X86_PAE
11444+ if (__supported_pte_mask & _PAGE_NX)
11445+ return pte_clear_flags(pte, _PAGE_NX);
11446+ else
11447+#endif
11448+ return pte_set_flags(pte, _PAGE_USER);
11449+}
11450+
11451+static inline pte_t pte_exprotect(pte_t pte)
11452+{
11453+#ifdef CONFIG_X86_PAE
11454+ if (__supported_pte_mask & _PAGE_NX)
11455+ return pte_set_flags(pte, _PAGE_NX);
11456+ else
11457+#endif
11458+ return pte_clear_flags(pte, _PAGE_USER);
11459 }
11460
11461 static inline pte_t pte_mkdirty(pte_t pte)
11462@@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11463 #endif
11464
11465 #ifndef __ASSEMBLY__
11466+
11467+#ifdef CONFIG_PAX_PER_CPU_PGD
11468+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11469+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11470+{
11471+ return cpu_pgd[cpu];
11472+}
11473+#endif
11474+
11475 #include <linux/mm_types.h>
11476
11477 static inline int pte_none(pte_t pte)
11478@@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11479
11480 static inline int pgd_bad(pgd_t pgd)
11481 {
11482- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11483+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11484 }
11485
11486 static inline int pgd_none(pgd_t pgd)
11487@@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11488 * pgd_offset() returns a (pgd_t *)
11489 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11490 */
11491-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11492+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11493+
11494+#ifdef CONFIG_PAX_PER_CPU_PGD
11495+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11496+#endif
11497+
11498 /*
11499 * a shortcut which implies the use of the kernel's pgd, instead
11500 * of a process's
11501@@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11502 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11503 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11504
11505+#ifdef CONFIG_X86_32
11506+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11507+#else
11508+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11509+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11510+
11511+#ifdef CONFIG_PAX_MEMORY_UDEREF
11512+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11513+#else
11514+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11515+#endif
11516+
11517+#endif
11518+
11519 #ifndef __ASSEMBLY__
11520
11521 extern int direct_gbpages;
11522@@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11523 * dst and src can be on the same page, but the range must not overlap,
11524 * and must not cross a page boundary.
11525 */
11526-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11527+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11528 {
11529- memcpy(dst, src, count * sizeof(pgd_t));
11530+ pax_open_kernel();
11531+ while (count--)
11532+ *dst++ = *src++;
11533+ pax_close_kernel();
11534 }
11535
11536+#ifdef CONFIG_PAX_PER_CPU_PGD
11537+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11538+#endif
11539+
11540+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11541+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11542+#else
11543+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11544+#endif
11545
11546 #include <asm-generic/pgtable.h>
11547 #endif /* __ASSEMBLY__ */
11548diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11549index 0c92113..34a77c6 100644
11550--- a/arch/x86/include/asm/pgtable_32.h
11551+++ b/arch/x86/include/asm/pgtable_32.h
11552@@ -25,9 +25,6 @@
11553 struct mm_struct;
11554 struct vm_area_struct;
11555
11556-extern pgd_t swapper_pg_dir[1024];
11557-extern pgd_t initial_page_table[1024];
11558-
11559 static inline void pgtable_cache_init(void) { }
11560 static inline void check_pgt_cache(void) { }
11561 void paging_init(void);
11562@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11563 # include <asm/pgtable-2level.h>
11564 #endif
11565
11566+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11567+extern pgd_t initial_page_table[PTRS_PER_PGD];
11568+#ifdef CONFIG_X86_PAE
11569+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11570+#endif
11571+
11572 #if defined(CONFIG_HIGHPTE)
11573 #define pte_offset_map(dir, address) \
11574 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11575@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11576 /* Clear a kernel PTE and flush it from the TLB */
11577 #define kpte_clear_flush(ptep, vaddr) \
11578 do { \
11579+ pax_open_kernel(); \
11580 pte_clear(&init_mm, (vaddr), (ptep)); \
11581+ pax_close_kernel(); \
11582 __flush_tlb_one((vaddr)); \
11583 } while (0)
11584
11585@@ -74,6 +79,9 @@ do { \
11586
11587 #endif /* !__ASSEMBLY__ */
11588
11589+#define HAVE_ARCH_UNMAPPED_AREA
11590+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11591+
11592 /*
11593 * kern_addr_valid() is (1) for FLATMEM and (0) for
11594 * SPARSEMEM and DISCONTIGMEM
11595diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11596index ed5903b..c7fe163 100644
11597--- a/arch/x86/include/asm/pgtable_32_types.h
11598+++ b/arch/x86/include/asm/pgtable_32_types.h
11599@@ -8,7 +8,7 @@
11600 */
11601 #ifdef CONFIG_X86_PAE
11602 # include <asm/pgtable-3level_types.h>
11603-# define PMD_SIZE (1UL << PMD_SHIFT)
11604+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11605 # define PMD_MASK (~(PMD_SIZE - 1))
11606 #else
11607 # include <asm/pgtable-2level_types.h>
11608@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11609 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11610 #endif
11611
11612+#ifdef CONFIG_PAX_KERNEXEC
11613+#ifndef __ASSEMBLY__
11614+extern unsigned char MODULES_EXEC_VADDR[];
11615+extern unsigned char MODULES_EXEC_END[];
11616+#endif
11617+#include <asm/boot.h>
11618+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11619+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11620+#else
11621+#define ktla_ktva(addr) (addr)
11622+#define ktva_ktla(addr) (addr)
11623+#endif
11624+
11625 #define MODULES_VADDR VMALLOC_START
11626 #define MODULES_END VMALLOC_END
11627 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11628diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11629index 975f709..9f779c9 100644
11630--- a/arch/x86/include/asm/pgtable_64.h
11631+++ b/arch/x86/include/asm/pgtable_64.h
11632@@ -16,10 +16,14 @@
11633
11634 extern pud_t level3_kernel_pgt[512];
11635 extern pud_t level3_ident_pgt[512];
11636+extern pud_t level3_vmalloc_start_pgt[512];
11637+extern pud_t level3_vmalloc_end_pgt[512];
11638+extern pud_t level3_vmemmap_pgt[512];
11639+extern pud_t level2_vmemmap_pgt[512];
11640 extern pmd_t level2_kernel_pgt[512];
11641 extern pmd_t level2_fixmap_pgt[512];
11642-extern pmd_t level2_ident_pgt[512];
11643-extern pgd_t init_level4_pgt[];
11644+extern pmd_t level2_ident_pgt[512*2];
11645+extern pgd_t init_level4_pgt[512];
11646
11647 #define swapper_pg_dir init_level4_pgt
11648
11649@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11650
11651 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11652 {
11653+ pax_open_kernel();
11654 *pmdp = pmd;
11655+ pax_close_kernel();
11656 }
11657
11658 static inline void native_pmd_clear(pmd_t *pmd)
11659@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11660
11661 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11662 {
11663+ pax_open_kernel();
11664 *pudp = pud;
11665+ pax_close_kernel();
11666 }
11667
11668 static inline void native_pud_clear(pud_t *pud)
11669@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11670
11671 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11672 {
11673+ pax_open_kernel();
11674+ *pgdp = pgd;
11675+ pax_close_kernel();
11676+}
11677+
11678+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11679+{
11680 *pgdp = pgd;
11681 }
11682
11683diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11684index 766ea16..5b96cb3 100644
11685--- a/arch/x86/include/asm/pgtable_64_types.h
11686+++ b/arch/x86/include/asm/pgtable_64_types.h
11687@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11688 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11689 #define MODULES_END _AC(0xffffffffff000000, UL)
11690 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11691+#define MODULES_EXEC_VADDR MODULES_VADDR
11692+#define MODULES_EXEC_END MODULES_END
11693+
11694+#define ktla_ktva(addr) (addr)
11695+#define ktva_ktla(addr) (addr)
11696
11697 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11698diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11699index 013286a..8b42f4f 100644
11700--- a/arch/x86/include/asm/pgtable_types.h
11701+++ b/arch/x86/include/asm/pgtable_types.h
11702@@ -16,13 +16,12 @@
11703 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11704 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11705 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11706-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11707+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11708 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11709 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11710 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11711-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11712-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11713-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11714+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11715+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11716 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11717
11718 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11719@@ -40,7 +39,6 @@
11720 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11721 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11722 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11723-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11724 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11725 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11726 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11727@@ -57,8 +55,10 @@
11728
11729 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11730 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11731-#else
11732+#elif defined(CONFIG_KMEMCHECK)
11733 #define _PAGE_NX (_AT(pteval_t, 0))
11734+#else
11735+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11736 #endif
11737
11738 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11739@@ -96,6 +96,9 @@
11740 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11741 _PAGE_ACCESSED)
11742
11743+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11744+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11745+
11746 #define __PAGE_KERNEL_EXEC \
11747 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11748 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11749@@ -106,7 +109,7 @@
11750 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11751 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11752 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11753-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11754+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11755 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11756 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11757 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11758@@ -168,8 +171,8 @@
11759 * bits are combined, this will alow user to access the high address mapped
11760 * VDSO in the presence of CONFIG_COMPAT_VDSO
11761 */
11762-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11763-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11764+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11765+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11766 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11767 #endif
11768
11769@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11770 {
11771 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11772 }
11773+#endif
11774
11775+#if PAGETABLE_LEVELS == 3
11776+#include <asm-generic/pgtable-nopud.h>
11777+#endif
11778+
11779+#if PAGETABLE_LEVELS == 2
11780+#include <asm-generic/pgtable-nopmd.h>
11781+#endif
11782+
11783+#ifndef __ASSEMBLY__
11784 #if PAGETABLE_LEVELS > 3
11785 typedef struct { pudval_t pud; } pud_t;
11786
11787@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11788 return pud.pud;
11789 }
11790 #else
11791-#include <asm-generic/pgtable-nopud.h>
11792-
11793 static inline pudval_t native_pud_val(pud_t pud)
11794 {
11795 return native_pgd_val(pud.pgd);
11796@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11797 return pmd.pmd;
11798 }
11799 #else
11800-#include <asm-generic/pgtable-nopmd.h>
11801-
11802 static inline pmdval_t native_pmd_val(pmd_t pmd)
11803 {
11804 return native_pgd_val(pmd.pud.pgd);
11805@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11806
11807 extern pteval_t __supported_pte_mask;
11808 extern void set_nx(void);
11809-extern int nx_enabled;
11810
11811 #define pgprot_writecombine pgprot_writecombine
11812 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11813diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11814index f8ab3ea..67889db 100644
11815--- a/arch/x86/include/asm/processor-flags.h
11816+++ b/arch/x86/include/asm/processor-flags.h
11817@@ -63,6 +63,7 @@
11818 #define X86_CR4_RDWRGSFS 0x00010000 /* enable RDWRGSFS support */
11819 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11820 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11821+#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11822
11823 /*
11824 * x86-64 Task Priority Register, CR8
11825diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11826index 39bc577..538233f 100644
11827--- a/arch/x86/include/asm/processor.h
11828+++ b/arch/x86/include/asm/processor.h
11829@@ -276,7 +276,7 @@ struct tss_struct {
11830
11831 } ____cacheline_aligned;
11832
11833-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11834+extern struct tss_struct init_tss[NR_CPUS];
11835
11836 /*
11837 * Save the original ist values for checking stack pointers during debugging
11838@@ -809,11 +809,18 @@ static inline void spin_lock_prefetch(const void *x)
11839 */
11840 #define TASK_SIZE PAGE_OFFSET
11841 #define TASK_SIZE_MAX TASK_SIZE
11842+
11843+#ifdef CONFIG_PAX_SEGMEXEC
11844+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11845+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11846+#else
11847 #define STACK_TOP TASK_SIZE
11848-#define STACK_TOP_MAX STACK_TOP
11849+#endif
11850+
11851+#define STACK_TOP_MAX TASK_SIZE
11852
11853 #define INIT_THREAD { \
11854- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11855+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11856 .vm86_info = NULL, \
11857 .sysenter_cs = __KERNEL_CS, \
11858 .io_bitmap_ptr = NULL, \
11859@@ -827,7 +834,7 @@ static inline void spin_lock_prefetch(const void *x)
11860 */
11861 #define INIT_TSS { \
11862 .x86_tss = { \
11863- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11864+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11865 .ss0 = __KERNEL_DS, \
11866 .ss1 = __KERNEL_CS, \
11867 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11868@@ -838,11 +845,7 @@ static inline void spin_lock_prefetch(const void *x)
11869 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11870
11871 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11872-#define KSTK_TOP(info) \
11873-({ \
11874- unsigned long *__ptr = (unsigned long *)(info); \
11875- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11876-})
11877+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11878
11879 /*
11880 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11881@@ -857,7 +860,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11882 #define task_pt_regs(task) \
11883 ({ \
11884 struct pt_regs *__regs__; \
11885- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11886+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11887 __regs__ - 1; \
11888 })
11889
11890@@ -867,13 +870,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11891 /*
11892 * User space process size. 47bits minus one guard page.
11893 */
11894-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11895+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11896
11897 /* This decides where the kernel will search for a free chunk of vm
11898 * space during mmap's.
11899 */
11900 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11901- 0xc0000000 : 0xFFFFe000)
11902+ 0xc0000000 : 0xFFFFf000)
11903
11904 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11905 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11906@@ -884,11 +887,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11907 #define STACK_TOP_MAX TASK_SIZE_MAX
11908
11909 #define INIT_THREAD { \
11910- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11911+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11912 }
11913
11914 #define INIT_TSS { \
11915- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11916+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11917 }
11918
11919 /*
11920@@ -916,6 +919,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11921 */
11922 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11923
11924+#ifdef CONFIG_PAX_SEGMEXEC
11925+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11926+#endif
11927+
11928 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11929
11930 /* Get/set a process' ability to use the timestamp counter instruction */
11931@@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11932 #define cpu_has_amd_erratum(x) (false)
11933 #endif /* CONFIG_CPU_SUP_AMD */
11934
11935-extern unsigned long arch_align_stack(unsigned long sp);
11936+#define arch_align_stack(x) ((x) & ~0xfUL)
11937 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11938
11939 void default_idle(void);
11940 bool set_pm_idle_to_default(void);
11941
11942-void stop_this_cpu(void *dummy);
11943+void stop_this_cpu(void *dummy) __noreturn;
11944
11945 #endif /* _ASM_X86_PROCESSOR_H */
11946diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11947index dcfde52..dbfea06 100644
11948--- a/arch/x86/include/asm/ptrace.h
11949+++ b/arch/x86/include/asm/ptrace.h
11950@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11951 }
11952
11953 /*
11954- * user_mode_vm(regs) determines whether a register set came from user mode.
11955+ * user_mode(regs) determines whether a register set came from user mode.
11956 * This is true if V8086 mode was enabled OR if the register set was from
11957 * protected mode with RPL-3 CS value. This tricky test checks that with
11958 * one comparison. Many places in the kernel can bypass this full check
11959- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11960+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11961+ * be used.
11962 */
11963-static inline int user_mode(struct pt_regs *regs)
11964+static inline int user_mode_novm(struct pt_regs *regs)
11965 {
11966 #ifdef CONFIG_X86_32
11967 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11968 #else
11969- return !!(regs->cs & 3);
11970+ return !!(regs->cs & SEGMENT_RPL_MASK);
11971 #endif
11972 }
11973
11974-static inline int user_mode_vm(struct pt_regs *regs)
11975+static inline int user_mode(struct pt_regs *regs)
11976 {
11977 #ifdef CONFIG_X86_32
11978 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11979 USER_RPL;
11980 #else
11981- return user_mode(regs);
11982+ return user_mode_novm(regs);
11983 #endif
11984 }
11985
11986@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11987 #ifdef CONFIG_X86_64
11988 static inline bool user_64bit_mode(struct pt_regs *regs)
11989 {
11990+ unsigned long cs = regs->cs & 0xffff;
11991 #ifndef CONFIG_PARAVIRT
11992 /*
11993 * On non-paravirt systems, this is the only long mode CPL 3
11994 * selector. We do not allow long mode selectors in the LDT.
11995 */
11996- return regs->cs == __USER_CS;
11997+ return cs == __USER_CS;
11998 #else
11999 /* Headers are too twisted for this to go in paravirt.h. */
12000- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12001+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12002 #endif
12003 }
12004 #endif
12005diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12006index fce3f4a..3f69f2a 100644
12007--- a/arch/x86/include/asm/realmode.h
12008+++ b/arch/x86/include/asm/realmode.h
12009@@ -30,7 +30,7 @@ struct real_mode_header {
12010 struct trampoline_header {
12011 #ifdef CONFIG_X86_32
12012 u32 start;
12013- u16 gdt_pad;
12014+ u16 boot_cs;
12015 u16 gdt_limit;
12016 u32 gdt_base;
12017 #else
12018diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12019index 92f29706..d0a1a53 100644
12020--- a/arch/x86/include/asm/reboot.h
12021+++ b/arch/x86/include/asm/reboot.h
12022@@ -6,19 +6,19 @@
12023 struct pt_regs;
12024
12025 struct machine_ops {
12026- void (*restart)(char *cmd);
12027- void (*halt)(void);
12028- void (*power_off)(void);
12029+ void (* __noreturn restart)(char *cmd);
12030+ void (* __noreturn halt)(void);
12031+ void (* __noreturn power_off)(void);
12032 void (*shutdown)(void);
12033 void (*crash_shutdown)(struct pt_regs *);
12034- void (*emergency_restart)(void);
12035-};
12036+ void (* __noreturn emergency_restart)(void);
12037+} __no_const;
12038
12039 extern struct machine_ops machine_ops;
12040
12041 void native_machine_crash_shutdown(struct pt_regs *regs);
12042 void native_machine_shutdown(void);
12043-void machine_real_restart(unsigned int type);
12044+void __noreturn machine_real_restart(unsigned int type);
12045 /* These must match dispatch_table in reboot_32.S */
12046 #define MRR_BIOS 0
12047 #define MRR_APM 1
12048diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12049index 2dbe4a7..ce1db00 100644
12050--- a/arch/x86/include/asm/rwsem.h
12051+++ b/arch/x86/include/asm/rwsem.h
12052@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12053 {
12054 asm volatile("# beginning down_read\n\t"
12055 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12056+
12057+#ifdef CONFIG_PAX_REFCOUNT
12058+ "jno 0f\n"
12059+ LOCK_PREFIX _ASM_DEC "(%1)\n"
12060+ "int $4\n0:\n"
12061+ _ASM_EXTABLE(0b, 0b)
12062+#endif
12063+
12064 /* adds 0x00000001 */
12065 " jns 1f\n"
12066 " call call_rwsem_down_read_failed\n"
12067@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12068 "1:\n\t"
12069 " mov %1,%2\n\t"
12070 " add %3,%2\n\t"
12071+
12072+#ifdef CONFIG_PAX_REFCOUNT
12073+ "jno 0f\n"
12074+ "sub %3,%2\n"
12075+ "int $4\n0:\n"
12076+ _ASM_EXTABLE(0b, 0b)
12077+#endif
12078+
12079 " jle 2f\n\t"
12080 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12081 " jnz 1b\n\t"
12082@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12083 long tmp;
12084 asm volatile("# beginning down_write\n\t"
12085 LOCK_PREFIX " xadd %1,(%2)\n\t"
12086+
12087+#ifdef CONFIG_PAX_REFCOUNT
12088+ "jno 0f\n"
12089+ "mov %1,(%2)\n"
12090+ "int $4\n0:\n"
12091+ _ASM_EXTABLE(0b, 0b)
12092+#endif
12093+
12094 /* adds 0xffff0001, returns the old value */
12095 " test %1,%1\n\t"
12096 /* was the count 0 before? */
12097@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12098 long tmp;
12099 asm volatile("# beginning __up_read\n\t"
12100 LOCK_PREFIX " xadd %1,(%2)\n\t"
12101+
12102+#ifdef CONFIG_PAX_REFCOUNT
12103+ "jno 0f\n"
12104+ "mov %1,(%2)\n"
12105+ "int $4\n0:\n"
12106+ _ASM_EXTABLE(0b, 0b)
12107+#endif
12108+
12109 /* subtracts 1, returns the old value */
12110 " jns 1f\n\t"
12111 " call call_rwsem_wake\n" /* expects old value in %edx */
12112@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12113 long tmp;
12114 asm volatile("# beginning __up_write\n\t"
12115 LOCK_PREFIX " xadd %1,(%2)\n\t"
12116+
12117+#ifdef CONFIG_PAX_REFCOUNT
12118+ "jno 0f\n"
12119+ "mov %1,(%2)\n"
12120+ "int $4\n0:\n"
12121+ _ASM_EXTABLE(0b, 0b)
12122+#endif
12123+
12124 /* subtracts 0xffff0001, returns the old value */
12125 " jns 1f\n\t"
12126 " call call_rwsem_wake\n" /* expects old value in %edx */
12127@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12128 {
12129 asm volatile("# beginning __downgrade_write\n\t"
12130 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12131+
12132+#ifdef CONFIG_PAX_REFCOUNT
12133+ "jno 0f\n"
12134+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12135+ "int $4\n0:\n"
12136+ _ASM_EXTABLE(0b, 0b)
12137+#endif
12138+
12139 /*
12140 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12141 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12142@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12143 */
12144 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12145 {
12146- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12147+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12148+
12149+#ifdef CONFIG_PAX_REFCOUNT
12150+ "jno 0f\n"
12151+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
12152+ "int $4\n0:\n"
12153+ _ASM_EXTABLE(0b, 0b)
12154+#endif
12155+
12156 : "+m" (sem->count)
12157 : "er" (delta));
12158 }
12159@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12160 */
12161 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12162 {
12163- return delta + xadd(&sem->count, delta);
12164+ return delta + xadd_check_overflow(&sem->count, delta);
12165 }
12166
12167 #endif /* __KERNEL__ */
12168diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12169index c48a950..c6d7468 100644
12170--- a/arch/x86/include/asm/segment.h
12171+++ b/arch/x86/include/asm/segment.h
12172@@ -64,10 +64,15 @@
12173 * 26 - ESPFIX small SS
12174 * 27 - per-cpu [ offset to per-cpu data area ]
12175 * 28 - stack_canary-20 [ for stack protector ]
12176- * 29 - unused
12177- * 30 - unused
12178+ * 29 - PCI BIOS CS
12179+ * 30 - PCI BIOS DS
12180 * 31 - TSS for double fault handler
12181 */
12182+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12183+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12184+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12185+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12186+
12187 #define GDT_ENTRY_TLS_MIN 6
12188 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12189
12190@@ -79,6 +84,8 @@
12191
12192 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12193
12194+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12195+
12196 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12197
12198 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12199@@ -104,6 +111,12 @@
12200 #define __KERNEL_STACK_CANARY 0
12201 #endif
12202
12203+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12204+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12205+
12206+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12207+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12208+
12209 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12210
12211 /*
12212@@ -141,7 +154,7 @@
12213 */
12214
12215 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12216-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12217+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12218
12219
12220 #else
12221@@ -165,6 +178,8 @@
12222 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12223 #define __USER32_DS __USER_DS
12224
12225+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12226+
12227 #define GDT_ENTRY_TSS 8 /* needs two entries */
12228 #define GDT_ENTRY_LDT 10 /* needs two entries */
12229 #define GDT_ENTRY_TLS_MIN 12
12230@@ -185,6 +200,7 @@
12231 #endif
12232
12233 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12234+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12235 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12236 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12237 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12238@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12239 {
12240 unsigned long __limit;
12241 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12242- return __limit + 1;
12243+ return __limit;
12244 }
12245
12246 #endif /* !__ASSEMBLY__ */
12247diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12248index f483945..64a7851 100644
12249--- a/arch/x86/include/asm/smp.h
12250+++ b/arch/x86/include/asm/smp.h
12251@@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12252 /* cpus sharing the last level cache: */
12253 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12254 DECLARE_PER_CPU(u16, cpu_llc_id);
12255-DECLARE_PER_CPU(int, cpu_number);
12256+DECLARE_PER_CPU(unsigned int, cpu_number);
12257
12258 static inline struct cpumask *cpu_sibling_mask(int cpu)
12259 {
12260@@ -79,7 +79,7 @@ struct smp_ops {
12261
12262 void (*send_call_func_ipi)(const struct cpumask *mask);
12263 void (*send_call_func_single_ipi)(int cpu);
12264-};
12265+} __no_const;
12266
12267 /* Globals due to paravirt */
12268 extern void set_cpu_sibling_map(int cpu);
12269@@ -195,14 +195,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12270 extern int safe_smp_processor_id(void);
12271
12272 #elif defined(CONFIG_X86_64_SMP)
12273-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12274-
12275-#define stack_smp_processor_id() \
12276-({ \
12277- struct thread_info *ti; \
12278- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12279- ti->cpu; \
12280-})
12281+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12282+#define stack_smp_processor_id() raw_smp_processor_id()
12283 #define safe_smp_processor_id() smp_processor_id()
12284
12285 #endif
12286diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12287index b315a33..8849ab0 100644
12288--- a/arch/x86/include/asm/spinlock.h
12289+++ b/arch/x86/include/asm/spinlock.h
12290@@ -173,6 +173,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12291 static inline void arch_read_lock(arch_rwlock_t *rw)
12292 {
12293 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12294+
12295+#ifdef CONFIG_PAX_REFCOUNT
12296+ "jno 0f\n"
12297+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12298+ "int $4\n0:\n"
12299+ _ASM_EXTABLE(0b, 0b)
12300+#endif
12301+
12302 "jns 1f\n"
12303 "call __read_lock_failed\n\t"
12304 "1:\n"
12305@@ -182,6 +190,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12306 static inline void arch_write_lock(arch_rwlock_t *rw)
12307 {
12308 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12309+
12310+#ifdef CONFIG_PAX_REFCOUNT
12311+ "jno 0f\n"
12312+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12313+ "int $4\n0:\n"
12314+ _ASM_EXTABLE(0b, 0b)
12315+#endif
12316+
12317 "jz 1f\n"
12318 "call __write_lock_failed\n\t"
12319 "1:\n"
12320@@ -211,13 +227,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12321
12322 static inline void arch_read_unlock(arch_rwlock_t *rw)
12323 {
12324- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12325+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12326+
12327+#ifdef CONFIG_PAX_REFCOUNT
12328+ "jno 0f\n"
12329+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12330+ "int $4\n0:\n"
12331+ _ASM_EXTABLE(0b, 0b)
12332+#endif
12333+
12334 :"+m" (rw->lock) : : "memory");
12335 }
12336
12337 static inline void arch_write_unlock(arch_rwlock_t *rw)
12338 {
12339- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12340+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12341+
12342+#ifdef CONFIG_PAX_REFCOUNT
12343+ "jno 0f\n"
12344+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12345+ "int $4\n0:\n"
12346+ _ASM_EXTABLE(0b, 0b)
12347+#endif
12348+
12349 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12350 }
12351
12352diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12353index 6a99859..03cb807 100644
12354--- a/arch/x86/include/asm/stackprotector.h
12355+++ b/arch/x86/include/asm/stackprotector.h
12356@@ -47,7 +47,7 @@
12357 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12358 */
12359 #define GDT_STACK_CANARY_INIT \
12360- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12361+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12362
12363 /*
12364 * Initialize the stackprotector canary value.
12365@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12366
12367 static inline void load_stack_canary_segment(void)
12368 {
12369-#ifdef CONFIG_X86_32
12370+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12371 asm volatile ("mov %0, %%gs" : : "r" (0));
12372 #endif
12373 }
12374diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12375index 70bbe39..4ae2bd4 100644
12376--- a/arch/x86/include/asm/stacktrace.h
12377+++ b/arch/x86/include/asm/stacktrace.h
12378@@ -11,28 +11,20 @@
12379
12380 extern int kstack_depth_to_print;
12381
12382-struct thread_info;
12383+struct task_struct;
12384 struct stacktrace_ops;
12385
12386-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12387- unsigned long *stack,
12388- unsigned long bp,
12389- const struct stacktrace_ops *ops,
12390- void *data,
12391- unsigned long *end,
12392- int *graph);
12393+typedef unsigned long walk_stack_t(struct task_struct *task,
12394+ void *stack_start,
12395+ unsigned long *stack,
12396+ unsigned long bp,
12397+ const struct stacktrace_ops *ops,
12398+ void *data,
12399+ unsigned long *end,
12400+ int *graph);
12401
12402-extern unsigned long
12403-print_context_stack(struct thread_info *tinfo,
12404- unsigned long *stack, unsigned long bp,
12405- const struct stacktrace_ops *ops, void *data,
12406- unsigned long *end, int *graph);
12407-
12408-extern unsigned long
12409-print_context_stack_bp(struct thread_info *tinfo,
12410- unsigned long *stack, unsigned long bp,
12411- const struct stacktrace_ops *ops, void *data,
12412- unsigned long *end, int *graph);
12413+extern walk_stack_t print_context_stack;
12414+extern walk_stack_t print_context_stack_bp;
12415
12416 /* Generic stack tracer with callbacks */
12417
12418@@ -40,7 +32,7 @@ struct stacktrace_ops {
12419 void (*address)(void *data, unsigned long address, int reliable);
12420 /* On negative return stop dumping */
12421 int (*stack)(void *data, char *name);
12422- walk_stack_t walk_stack;
12423+ walk_stack_t *walk_stack;
12424 };
12425
12426 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12427diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12428index 4ec45b3..a4f0a8a 100644
12429--- a/arch/x86/include/asm/switch_to.h
12430+++ b/arch/x86/include/asm/switch_to.h
12431@@ -108,7 +108,7 @@ do { \
12432 "call __switch_to\n\t" \
12433 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12434 __switch_canary \
12435- "movq %P[thread_info](%%rsi),%%r8\n\t" \
12436+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12437 "movq %%rax,%%rdi\n\t" \
12438 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12439 "jnz ret_from_fork\n\t" \
12440@@ -119,7 +119,7 @@ do { \
12441 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12442 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12443 [_tif_fork] "i" (_TIF_FORK), \
12444- [thread_info] "i" (offsetof(struct task_struct, stack)), \
12445+ [thread_info] "m" (current_tinfo), \
12446 [current_task] "m" (current_task) \
12447 __switch_canary_iparam \
12448 : "memory", "cc" __EXTRA_CLOBBER)
12449diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12450index 3fda9db4..4ca1c61 100644
12451--- a/arch/x86/include/asm/sys_ia32.h
12452+++ b/arch/x86/include/asm/sys_ia32.h
12453@@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12454 struct old_sigaction32 __user *);
12455 asmlinkage long sys32_alarm(unsigned int);
12456
12457-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12458+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12459 asmlinkage long sys32_sysfs(int, u32, u32);
12460
12461 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12462diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12463index 89f794f..1422765 100644
12464--- a/arch/x86/include/asm/thread_info.h
12465+++ b/arch/x86/include/asm/thread_info.h
12466@@ -10,6 +10,7 @@
12467 #include <linux/compiler.h>
12468 #include <asm/page.h>
12469 #include <asm/types.h>
12470+#include <asm/percpu.h>
12471
12472 /*
12473 * low level task data that entry.S needs immediate access to
12474@@ -24,7 +25,6 @@ struct exec_domain;
12475 #include <linux/atomic.h>
12476
12477 struct thread_info {
12478- struct task_struct *task; /* main task structure */
12479 struct exec_domain *exec_domain; /* execution domain */
12480 __u32 flags; /* low level flags */
12481 __u32 status; /* thread synchronous flags */
12482@@ -34,19 +34,13 @@ struct thread_info {
12483 mm_segment_t addr_limit;
12484 struct restart_block restart_block;
12485 void __user *sysenter_return;
12486-#ifdef CONFIG_X86_32
12487- unsigned long previous_esp; /* ESP of the previous stack in
12488- case of nested (IRQ) stacks
12489- */
12490- __u8 supervisor_stack[0];
12491-#endif
12492+ unsigned long lowest_stack;
12493 unsigned int sig_on_uaccess_error:1;
12494 unsigned int uaccess_err:1; /* uaccess failed */
12495 };
12496
12497-#define INIT_THREAD_INFO(tsk) \
12498+#define INIT_THREAD_INFO \
12499 { \
12500- .task = &tsk, \
12501 .exec_domain = &default_exec_domain, \
12502 .flags = 0, \
12503 .cpu = 0, \
12504@@ -57,7 +51,7 @@ struct thread_info {
12505 }, \
12506 }
12507
12508-#define init_thread_info (init_thread_union.thread_info)
12509+#define init_thread_info (init_thread_union.stack)
12510 #define init_stack (init_thread_union.stack)
12511
12512 #else /* !__ASSEMBLY__ */
12513@@ -98,6 +92,7 @@ struct thread_info {
12514 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12515 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12516 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12517+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12518
12519 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12520 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12521@@ -122,16 +117,18 @@ struct thread_info {
12522 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12523 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12524 #define _TIF_X32 (1 << TIF_X32)
12525+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12526
12527 /* work to do in syscall_trace_enter() */
12528 #define _TIF_WORK_SYSCALL_ENTRY \
12529 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12530- _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12531+ _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12532+ _TIF_GRSEC_SETXID)
12533
12534 /* work to do in syscall_trace_leave() */
12535 #define _TIF_WORK_SYSCALL_EXIT \
12536 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12537- _TIF_SYSCALL_TRACEPOINT)
12538+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12539
12540 /* work to do on interrupt/exception return */
12541 #define _TIF_WORK_MASK \
12542@@ -141,7 +138,8 @@ struct thread_info {
12543
12544 /* work to do on any return to user space */
12545 #define _TIF_ALLWORK_MASK \
12546- ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12547+ ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12548+ _TIF_GRSEC_SETXID)
12549
12550 /* Only used for 64 bit */
12551 #define _TIF_DO_NOTIFY_MASK \
12552@@ -157,45 +155,40 @@ struct thread_info {
12553
12554 #define PREEMPT_ACTIVE 0x10000000
12555
12556-#ifdef CONFIG_X86_32
12557-
12558-#define STACK_WARN (THREAD_SIZE/8)
12559-/*
12560- * macros/functions for gaining access to the thread information structure
12561- *
12562- * preempt_count needs to be 1 initially, until the scheduler is functional.
12563- */
12564-#ifndef __ASSEMBLY__
12565-
12566-
12567-/* how to get the current stack pointer from C */
12568-register unsigned long current_stack_pointer asm("esp") __used;
12569-
12570-/* how to get the thread information struct from C */
12571-static inline struct thread_info *current_thread_info(void)
12572-{
12573- return (struct thread_info *)
12574- (current_stack_pointer & ~(THREAD_SIZE - 1));
12575-}
12576-
12577-#else /* !__ASSEMBLY__ */
12578-
12579+#ifdef __ASSEMBLY__
12580 /* how to get the thread information struct from ASM */
12581 #define GET_THREAD_INFO(reg) \
12582- movl $-THREAD_SIZE, reg; \
12583- andl %esp, reg
12584+ mov PER_CPU_VAR(current_tinfo), reg
12585
12586 /* use this one if reg already contains %esp */
12587-#define GET_THREAD_INFO_WITH_ESP(reg) \
12588- andl $-THREAD_SIZE, reg
12589+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12590+#else
12591+/* how to get the thread information struct from C */
12592+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12593+
12594+static __always_inline struct thread_info *current_thread_info(void)
12595+{
12596+ return this_cpu_read_stable(current_tinfo);
12597+}
12598+#endif
12599+
12600+#ifdef CONFIG_X86_32
12601+
12602+#define STACK_WARN (THREAD_SIZE/8)
12603+/*
12604+ * macros/functions for gaining access to the thread information structure
12605+ *
12606+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12607+ */
12608+#ifndef __ASSEMBLY__
12609+
12610+/* how to get the current stack pointer from C */
12611+register unsigned long current_stack_pointer asm("esp") __used;
12612
12613 #endif
12614
12615 #else /* X86_32 */
12616
12617-#include <asm/percpu.h>
12618-#define KERNEL_STACK_OFFSET (5*8)
12619-
12620 /*
12621 * macros/functions for gaining access to the thread information structure
12622 * preempt_count needs to be 1 initially, until the scheduler is functional.
12623@@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12624 #ifndef __ASSEMBLY__
12625 DECLARE_PER_CPU(unsigned long, kernel_stack);
12626
12627-static inline struct thread_info *current_thread_info(void)
12628-{
12629- struct thread_info *ti;
12630- ti = (void *)(this_cpu_read_stable(kernel_stack) +
12631- KERNEL_STACK_OFFSET - THREAD_SIZE);
12632- return ti;
12633-}
12634-
12635-#else /* !__ASSEMBLY__ */
12636-
12637-/* how to get the thread information struct from ASM */
12638-#define GET_THREAD_INFO(reg) \
12639- movq PER_CPU_VAR(kernel_stack),reg ; \
12640- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12641-
12642-/*
12643- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12644- * a certain register (to be used in assembler memory operands).
12645- */
12646-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12647-
12648+/* how to get the current stack pointer from C */
12649+register unsigned long current_stack_pointer asm("rsp") __used;
12650 #endif
12651
12652 #endif /* !X86_32 */
12653@@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12654 extern void arch_task_cache_init(void);
12655 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12656 extern void arch_release_task_struct(struct task_struct *tsk);
12657+
12658+#define __HAVE_THREAD_FUNCTIONS
12659+#define task_thread_info(task) (&(task)->tinfo)
12660+#define task_stack_page(task) ((task)->stack)
12661+#define setup_thread_stack(p, org) do {} while (0)
12662+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12663+
12664 #endif
12665 #endif /* _ASM_X86_THREAD_INFO_H */
12666diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12667index e1f3a17..1ab364d 100644
12668--- a/arch/x86/include/asm/uaccess.h
12669+++ b/arch/x86/include/asm/uaccess.h
12670@@ -7,12 +7,15 @@
12671 #include <linux/compiler.h>
12672 #include <linux/thread_info.h>
12673 #include <linux/string.h>
12674+#include <linux/sched.h>
12675 #include <asm/asm.h>
12676 #include <asm/page.h>
12677
12678 #define VERIFY_READ 0
12679 #define VERIFY_WRITE 1
12680
12681+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12682+
12683 /*
12684 * The fs value determines whether argument validity checking should be
12685 * performed or not. If get_fs() == USER_DS, checking is performed, with
12686@@ -28,7 +31,12 @@
12687
12688 #define get_ds() (KERNEL_DS)
12689 #define get_fs() (current_thread_info()->addr_limit)
12690+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12691+void __set_fs(mm_segment_t x);
12692+void set_fs(mm_segment_t x);
12693+#else
12694 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12695+#endif
12696
12697 #define segment_eq(a, b) ((a).seg == (b).seg)
12698
12699@@ -76,8 +84,33 @@
12700 * checks that the pointer is in the user space range - after calling
12701 * this function, memory access functions may still return -EFAULT.
12702 */
12703-#define access_ok(type, addr, size) \
12704- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12705+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12706+#define access_ok(type, addr, size) \
12707+({ \
12708+ long __size = size; \
12709+ unsigned long __addr = (unsigned long)addr; \
12710+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12711+ unsigned long __end_ao = __addr + __size - 1; \
12712+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12713+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12714+ while(__addr_ao <= __end_ao) { \
12715+ char __c_ao; \
12716+ __addr_ao += PAGE_SIZE; \
12717+ if (__size > PAGE_SIZE) \
12718+ cond_resched(); \
12719+ if (__get_user(__c_ao, (char __user *)__addr)) \
12720+ break; \
12721+ if (type != VERIFY_WRITE) { \
12722+ __addr = __addr_ao; \
12723+ continue; \
12724+ } \
12725+ if (__put_user(__c_ao, (char __user *)__addr)) \
12726+ break; \
12727+ __addr = __addr_ao; \
12728+ } \
12729+ } \
12730+ __ret_ao; \
12731+})
12732
12733 /*
12734 * The exception table consists of pairs of addresses relative to the
12735@@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12736 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12737 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12738
12739-
12740+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12741+#define __copyuser_seg "gs;"
12742+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12743+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12744+#else
12745+#define __copyuser_seg
12746+#define __COPYUSER_SET_ES
12747+#define __COPYUSER_RESTORE_ES
12748+#endif
12749
12750 #ifdef CONFIG_X86_32
12751 #define __put_user_asm_u64(x, addr, err, errret) \
12752- asm volatile("1: movl %%eax,0(%2)\n" \
12753- "2: movl %%edx,4(%2)\n" \
12754+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12755+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12756 "3:\n" \
12757 ".section .fixup,\"ax\"\n" \
12758 "4: movl %3,%0\n" \
12759@@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12760 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12761
12762 #define __put_user_asm_ex_u64(x, addr) \
12763- asm volatile("1: movl %%eax,0(%1)\n" \
12764- "2: movl %%edx,4(%1)\n" \
12765+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12766+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12767 "3:\n" \
12768 _ASM_EXTABLE_EX(1b, 2b) \
12769 _ASM_EXTABLE_EX(2b, 3b) \
12770@@ -258,7 +299,7 @@ extern void __put_user_8(void);
12771 __typeof__(*(ptr)) __pu_val; \
12772 __chk_user_ptr(ptr); \
12773 might_fault(); \
12774- __pu_val = x; \
12775+ __pu_val = (x); \
12776 switch (sizeof(*(ptr))) { \
12777 case 1: \
12778 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12779@@ -379,7 +420,7 @@ do { \
12780 } while (0)
12781
12782 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12783- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12784+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12785 "2:\n" \
12786 ".section .fixup,\"ax\"\n" \
12787 "3: mov %3,%0\n" \
12788@@ -387,7 +428,7 @@ do { \
12789 " jmp 2b\n" \
12790 ".previous\n" \
12791 _ASM_EXTABLE(1b, 3b) \
12792- : "=r" (err), ltype(x) \
12793+ : "=r" (err), ltype (x) \
12794 : "m" (__m(addr)), "i" (errret), "0" (err))
12795
12796 #define __get_user_size_ex(x, ptr, size) \
12797@@ -412,7 +453,7 @@ do { \
12798 } while (0)
12799
12800 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12801- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12802+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12803 "2:\n" \
12804 _ASM_EXTABLE_EX(1b, 2b) \
12805 : ltype(x) : "m" (__m(addr)))
12806@@ -429,13 +470,24 @@ do { \
12807 int __gu_err; \
12808 unsigned long __gu_val; \
12809 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12810- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12811+ (x) = (__typeof__(*(ptr)))__gu_val; \
12812 __gu_err; \
12813 })
12814
12815 /* FIXME: this hack is definitely wrong -AK */
12816 struct __large_struct { unsigned long buf[100]; };
12817-#define __m(x) (*(struct __large_struct __user *)(x))
12818+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12819+#define ____m(x) \
12820+({ \
12821+ unsigned long ____x = (unsigned long)(x); \
12822+ if (____x < PAX_USER_SHADOW_BASE) \
12823+ ____x += PAX_USER_SHADOW_BASE; \
12824+ (void __user *)____x; \
12825+})
12826+#else
12827+#define ____m(x) (x)
12828+#endif
12829+#define __m(x) (*(struct __large_struct __user *)____m(x))
12830
12831 /*
12832 * Tell gcc we read from memory instead of writing: this is because
12833@@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12834 * aliasing issues.
12835 */
12836 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12837- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12838+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12839 "2:\n" \
12840 ".section .fixup,\"ax\"\n" \
12841 "3: mov %3,%0\n" \
12842@@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12843 ".previous\n" \
12844 _ASM_EXTABLE(1b, 3b) \
12845 : "=r"(err) \
12846- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12847+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12848
12849 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12850- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12851+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12852 "2:\n" \
12853 _ASM_EXTABLE_EX(1b, 2b) \
12854 : : ltype(x), "m" (__m(addr)))
12855@@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12856 * On error, the variable @x is set to zero.
12857 */
12858
12859+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12860+#define __get_user(x, ptr) get_user((x), (ptr))
12861+#else
12862 #define __get_user(x, ptr) \
12863 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12864+#endif
12865
12866 /**
12867 * __put_user: - Write a simple value into user space, with less checking.
12868@@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12869 * Returns zero on success, or -EFAULT on error.
12870 */
12871
12872+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12873+#define __put_user(x, ptr) put_user((x), (ptr))
12874+#else
12875 #define __put_user(x, ptr) \
12876 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12877+#endif
12878
12879 #define __get_user_unaligned __get_user
12880 #define __put_user_unaligned __put_user
12881@@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12882 #define get_user_ex(x, ptr) do { \
12883 unsigned long __gue_val; \
12884 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12885- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12886+ (x) = (__typeof__(*(ptr)))__gue_val; \
12887 } while (0)
12888
12889 #ifdef CONFIG_X86_WP_WORKS_OK
12890diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12891index 576e39b..ccd0a39 100644
12892--- a/arch/x86/include/asm/uaccess_32.h
12893+++ b/arch/x86/include/asm/uaccess_32.h
12894@@ -11,15 +11,15 @@
12895 #include <asm/page.h>
12896
12897 unsigned long __must_check __copy_to_user_ll
12898- (void __user *to, const void *from, unsigned long n);
12899+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12900 unsigned long __must_check __copy_from_user_ll
12901- (void *to, const void __user *from, unsigned long n);
12902+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12903 unsigned long __must_check __copy_from_user_ll_nozero
12904- (void *to, const void __user *from, unsigned long n);
12905+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12906 unsigned long __must_check __copy_from_user_ll_nocache
12907- (void *to, const void __user *from, unsigned long n);
12908+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12909 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12910- (void *to, const void __user *from, unsigned long n);
12911+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12912
12913 /**
12914 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12915@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12916 static __always_inline unsigned long __must_check
12917 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12918 {
12919+ if ((long)n < 0)
12920+ return n;
12921+
12922 if (__builtin_constant_p(n)) {
12923 unsigned long ret;
12924
12925@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12926 return ret;
12927 }
12928 }
12929+ if (!__builtin_constant_p(n))
12930+ check_object_size(from, n, true);
12931 return __copy_to_user_ll(to, from, n);
12932 }
12933
12934@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12935 __copy_to_user(void __user *to, const void *from, unsigned long n)
12936 {
12937 might_fault();
12938+
12939 return __copy_to_user_inatomic(to, from, n);
12940 }
12941
12942 static __always_inline unsigned long
12943 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12944 {
12945+ if ((long)n < 0)
12946+ return n;
12947+
12948 /* Avoid zeroing the tail if the copy fails..
12949 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12950 * but as the zeroing behaviour is only significant when n is not
12951@@ -137,6 +146,10 @@ static __always_inline unsigned long
12952 __copy_from_user(void *to, const void __user *from, unsigned long n)
12953 {
12954 might_fault();
12955+
12956+ if ((long)n < 0)
12957+ return n;
12958+
12959 if (__builtin_constant_p(n)) {
12960 unsigned long ret;
12961
12962@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12963 return ret;
12964 }
12965 }
12966+ if (!__builtin_constant_p(n))
12967+ check_object_size(to, n, false);
12968 return __copy_from_user_ll(to, from, n);
12969 }
12970
12971@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12972 const void __user *from, unsigned long n)
12973 {
12974 might_fault();
12975+
12976+ if ((long)n < 0)
12977+ return n;
12978+
12979 if (__builtin_constant_p(n)) {
12980 unsigned long ret;
12981
12982@@ -181,15 +200,19 @@ static __always_inline unsigned long
12983 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12984 unsigned long n)
12985 {
12986- return __copy_from_user_ll_nocache_nozero(to, from, n);
12987+ if ((long)n < 0)
12988+ return n;
12989+
12990+ return __copy_from_user_ll_nocache_nozero(to, from, n);
12991 }
12992
12993-unsigned long __must_check copy_to_user(void __user *to,
12994- const void *from, unsigned long n);
12995-unsigned long __must_check _copy_from_user(void *to,
12996- const void __user *from,
12997- unsigned long n);
12998-
12999+extern void copy_to_user_overflow(void)
13000+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13001+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13002+#else
13003+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13004+#endif
13005+;
13006
13007 extern void copy_from_user_overflow(void)
13008 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13009@@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13010 #endif
13011 ;
13012
13013-static inline unsigned long __must_check copy_from_user(void *to,
13014- const void __user *from,
13015- unsigned long n)
13016+/**
13017+ * copy_to_user: - Copy a block of data into user space.
13018+ * @to: Destination address, in user space.
13019+ * @from: Source address, in kernel space.
13020+ * @n: Number of bytes to copy.
13021+ *
13022+ * Context: User context only. This function may sleep.
13023+ *
13024+ * Copy data from kernel space to user space.
13025+ *
13026+ * Returns number of bytes that could not be copied.
13027+ * On success, this will be zero.
13028+ */
13029+static inline unsigned long __must_check
13030+copy_to_user(void __user *to, const void *from, unsigned long n)
13031 {
13032- int sz = __compiletime_object_size(to);
13033+ size_t sz = __compiletime_object_size(from);
13034
13035- if (likely(sz == -1 || sz >= n))
13036- n = _copy_from_user(to, from, n);
13037- else
13038+ if (unlikely(sz != (size_t)-1 && sz < n))
13039+ copy_to_user_overflow();
13040+ else if (access_ok(VERIFY_WRITE, to, n))
13041+ n = __copy_to_user(to, from, n);
13042+ return n;
13043+}
13044+
13045+/**
13046+ * copy_from_user: - Copy a block of data from user space.
13047+ * @to: Destination address, in kernel space.
13048+ * @from: Source address, in user space.
13049+ * @n: Number of bytes to copy.
13050+ *
13051+ * Context: User context only. This function may sleep.
13052+ *
13053+ * Copy data from user space to kernel space.
13054+ *
13055+ * Returns number of bytes that could not be copied.
13056+ * On success, this will be zero.
13057+ *
13058+ * If some data could not be copied, this function will pad the copied
13059+ * data to the requested size using zero bytes.
13060+ */
13061+static inline unsigned long __must_check
13062+copy_from_user(void *to, const void __user *from, unsigned long n)
13063+{
13064+ size_t sz = __compiletime_object_size(to);
13065+
13066+ if (unlikely(sz != (size_t)-1 && sz < n))
13067 copy_from_user_overflow();
13068-
13069+ else if (access_ok(VERIFY_READ, from, n))
13070+ n = __copy_from_user(to, from, n);
13071+ else if ((long)n > 0) {
13072+ if (!__builtin_constant_p(n))
13073+ check_object_size(to, n, false);
13074+ memset(to, 0, n);
13075+ }
13076 return n;
13077 }
13078
13079-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13080-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13081+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13082+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13083
13084 #endif /* _ASM_X86_UACCESS_32_H */
13085diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13086index 8e796fb..468c55a 100644
13087--- a/arch/x86/include/asm/uaccess_64.h
13088+++ b/arch/x86/include/asm/uaccess_64.h
13089@@ -10,6 +10,9 @@
13090 #include <asm/alternative.h>
13091 #include <asm/cpufeature.h>
13092 #include <asm/page.h>
13093+#include <asm/pgtable.h>
13094+
13095+#define set_fs(x) (current_thread_info()->addr_limit = (x))
13096
13097 /*
13098 * Copy To/From Userspace
13099@@ -17,12 +20,12 @@
13100
13101 /* Handles exceptions in both to and from, but doesn't do access_ok */
13102 __must_check unsigned long
13103-copy_user_generic_string(void *to, const void *from, unsigned len);
13104+copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13105 __must_check unsigned long
13106-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13107+copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13108
13109-static __always_inline __must_check unsigned long
13110-copy_user_generic(void *to, const void *from, unsigned len)
13111+static __always_inline __must_check __size_overflow(3) unsigned long
13112+copy_user_generic(void *to, const void *from, unsigned long len)
13113 {
13114 unsigned ret;
13115
13116@@ -32,142 +35,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13117 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13118 "=d" (len)),
13119 "1" (to), "2" (from), "3" (len)
13120- : "memory", "rcx", "r8", "r9", "r10", "r11");
13121+ : "memory", "rcx", "r8", "r9", "r11");
13122 return ret;
13123 }
13124
13125+static __always_inline __must_check unsigned long
13126+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13127+static __always_inline __must_check unsigned long
13128+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13129 __must_check unsigned long
13130-_copy_to_user(void __user *to, const void *from, unsigned len);
13131-__must_check unsigned long
13132-_copy_from_user(void *to, const void __user *from, unsigned len);
13133-__must_check unsigned long
13134-copy_in_user(void __user *to, const void __user *from, unsigned len);
13135+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13136+
13137+extern void copy_to_user_overflow(void)
13138+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13139+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13140+#else
13141+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13142+#endif
13143+;
13144+
13145+extern void copy_from_user_overflow(void)
13146+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13147+ __compiletime_error("copy_from_user() buffer size is not provably correct")
13148+#else
13149+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
13150+#endif
13151+;
13152
13153 static inline unsigned long __must_check copy_from_user(void *to,
13154 const void __user *from,
13155 unsigned long n)
13156 {
13157- int sz = __compiletime_object_size(to);
13158-
13159 might_fault();
13160- if (likely(sz == -1 || sz >= n))
13161- n = _copy_from_user(to, from, n);
13162-#ifdef CONFIG_DEBUG_VM
13163- else
13164- WARN(1, "Buffer overflow detected!\n");
13165-#endif
13166+
13167+ if (access_ok(VERIFY_READ, from, n))
13168+ n = __copy_from_user(to, from, n);
13169+ else if (n < INT_MAX) {
13170+ if (!__builtin_constant_p(n))
13171+ check_object_size(to, n, false);
13172+ memset(to, 0, n);
13173+ }
13174 return n;
13175 }
13176
13177 static __always_inline __must_check
13178-int copy_to_user(void __user *dst, const void *src, unsigned size)
13179+int copy_to_user(void __user *dst, const void *src, unsigned long size)
13180 {
13181 might_fault();
13182
13183- return _copy_to_user(dst, src, size);
13184+ if (access_ok(VERIFY_WRITE, dst, size))
13185+ size = __copy_to_user(dst, src, size);
13186+ return size;
13187 }
13188
13189 static __always_inline __must_check
13190-int __copy_from_user(void *dst, const void __user *src, unsigned size)
13191+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13192 {
13193- int ret = 0;
13194+ size_t sz = __compiletime_object_size(dst);
13195+ unsigned ret = 0;
13196
13197 might_fault();
13198- if (!__builtin_constant_p(size))
13199- return copy_user_generic(dst, (__force void *)src, size);
13200+
13201+ if (size > INT_MAX)
13202+ return size;
13203+
13204+#ifdef CONFIG_PAX_MEMORY_UDEREF
13205+ if (!__access_ok(VERIFY_READ, src, size))
13206+ return size;
13207+#endif
13208+
13209+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13210+ copy_from_user_overflow();
13211+ return size;
13212+ }
13213+
13214+ if (!__builtin_constant_p(size)) {
13215+ check_object_size(dst, size, false);
13216+
13217+#ifdef CONFIG_PAX_MEMORY_UDEREF
13218+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13219+ src += PAX_USER_SHADOW_BASE;
13220+#endif
13221+
13222+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13223+ }
13224 switch (size) {
13225- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13226+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13227 ret, "b", "b", "=q", 1);
13228 return ret;
13229- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13230+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13231 ret, "w", "w", "=r", 2);
13232 return ret;
13233- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13234+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13235 ret, "l", "k", "=r", 4);
13236 return ret;
13237- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13238+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13239 ret, "q", "", "=r", 8);
13240 return ret;
13241 case 10:
13242- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13243+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13244 ret, "q", "", "=r", 10);
13245 if (unlikely(ret))
13246 return ret;
13247 __get_user_asm(*(u16 *)(8 + (char *)dst),
13248- (u16 __user *)(8 + (char __user *)src),
13249+ (const u16 __user *)(8 + (const char __user *)src),
13250 ret, "w", "w", "=r", 2);
13251 return ret;
13252 case 16:
13253- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13254+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13255 ret, "q", "", "=r", 16);
13256 if (unlikely(ret))
13257 return ret;
13258 __get_user_asm(*(u64 *)(8 + (char *)dst),
13259- (u64 __user *)(8 + (char __user *)src),
13260+ (const u64 __user *)(8 + (const char __user *)src),
13261 ret, "q", "", "=r", 8);
13262 return ret;
13263 default:
13264- return copy_user_generic(dst, (__force void *)src, size);
13265+
13266+#ifdef CONFIG_PAX_MEMORY_UDEREF
13267+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13268+ src += PAX_USER_SHADOW_BASE;
13269+#endif
13270+
13271+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13272 }
13273 }
13274
13275 static __always_inline __must_check
13276-int __copy_to_user(void __user *dst, const void *src, unsigned size)
13277+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13278 {
13279- int ret = 0;
13280+ size_t sz = __compiletime_object_size(src);
13281+ unsigned ret = 0;
13282
13283 might_fault();
13284- if (!__builtin_constant_p(size))
13285- return copy_user_generic((__force void *)dst, src, size);
13286+
13287+ if (size > INT_MAX)
13288+ return size;
13289+
13290+#ifdef CONFIG_PAX_MEMORY_UDEREF
13291+ if (!__access_ok(VERIFY_WRITE, dst, size))
13292+ return size;
13293+#endif
13294+
13295+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13296+ copy_to_user_overflow();
13297+ return size;
13298+ }
13299+
13300+ if (!__builtin_constant_p(size)) {
13301+ check_object_size(src, size, true);
13302+
13303+#ifdef CONFIG_PAX_MEMORY_UDEREF
13304+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13305+ dst += PAX_USER_SHADOW_BASE;
13306+#endif
13307+
13308+ return copy_user_generic((__force_kernel void *)dst, src, size);
13309+ }
13310 switch (size) {
13311- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13312+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13313 ret, "b", "b", "iq", 1);
13314 return ret;
13315- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13316+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13317 ret, "w", "w", "ir", 2);
13318 return ret;
13319- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13320+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13321 ret, "l", "k", "ir", 4);
13322 return ret;
13323- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13324+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13325 ret, "q", "", "er", 8);
13326 return ret;
13327 case 10:
13328- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13329+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13330 ret, "q", "", "er", 10);
13331 if (unlikely(ret))
13332 return ret;
13333 asm("":::"memory");
13334- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13335+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13336 ret, "w", "w", "ir", 2);
13337 return ret;
13338 case 16:
13339- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13340+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13341 ret, "q", "", "er", 16);
13342 if (unlikely(ret))
13343 return ret;
13344 asm("":::"memory");
13345- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13346+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13347 ret, "q", "", "er", 8);
13348 return ret;
13349 default:
13350- return copy_user_generic((__force void *)dst, src, size);
13351+
13352+#ifdef CONFIG_PAX_MEMORY_UDEREF
13353+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13354+ dst += PAX_USER_SHADOW_BASE;
13355+#endif
13356+
13357+ return copy_user_generic((__force_kernel void *)dst, src, size);
13358 }
13359 }
13360
13361 static __always_inline __must_check
13362-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13363+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13364 {
13365- int ret = 0;
13366+ unsigned ret = 0;
13367
13368 might_fault();
13369- if (!__builtin_constant_p(size))
13370- return copy_user_generic((__force void *)dst,
13371- (__force void *)src, size);
13372+
13373+ if (size > INT_MAX)
13374+ return size;
13375+
13376+#ifdef CONFIG_PAX_MEMORY_UDEREF
13377+ if (!__access_ok(VERIFY_READ, src, size))
13378+ return size;
13379+ if (!__access_ok(VERIFY_WRITE, dst, size))
13380+ return size;
13381+#endif
13382+
13383+ if (!__builtin_constant_p(size)) {
13384+
13385+#ifdef CONFIG_PAX_MEMORY_UDEREF
13386+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13387+ src += PAX_USER_SHADOW_BASE;
13388+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13389+ dst += PAX_USER_SHADOW_BASE;
13390+#endif
13391+
13392+ return copy_user_generic((__force_kernel void *)dst,
13393+ (__force_kernel const void *)src, size);
13394+ }
13395 switch (size) {
13396 case 1: {
13397 u8 tmp;
13398- __get_user_asm(tmp, (u8 __user *)src,
13399+ __get_user_asm(tmp, (const u8 __user *)src,
13400 ret, "b", "b", "=q", 1);
13401 if (likely(!ret))
13402 __put_user_asm(tmp, (u8 __user *)dst,
13403@@ -176,7 +275,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13404 }
13405 case 2: {
13406 u16 tmp;
13407- __get_user_asm(tmp, (u16 __user *)src,
13408+ __get_user_asm(tmp, (const u16 __user *)src,
13409 ret, "w", "w", "=r", 2);
13410 if (likely(!ret))
13411 __put_user_asm(tmp, (u16 __user *)dst,
13412@@ -186,7 +285,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13413
13414 case 4: {
13415 u32 tmp;
13416- __get_user_asm(tmp, (u32 __user *)src,
13417+ __get_user_asm(tmp, (const u32 __user *)src,
13418 ret, "l", "k", "=r", 4);
13419 if (likely(!ret))
13420 __put_user_asm(tmp, (u32 __user *)dst,
13421@@ -195,7 +294,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13422 }
13423 case 8: {
13424 u64 tmp;
13425- __get_user_asm(tmp, (u64 __user *)src,
13426+ __get_user_asm(tmp, (const u64 __user *)src,
13427 ret, "q", "", "=r", 8);
13428 if (likely(!ret))
13429 __put_user_asm(tmp, (u64 __user *)dst,
13430@@ -203,44 +302,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13431 return ret;
13432 }
13433 default:
13434- return copy_user_generic((__force void *)dst,
13435- (__force void *)src, size);
13436+
13437+#ifdef CONFIG_PAX_MEMORY_UDEREF
13438+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13439+ src += PAX_USER_SHADOW_BASE;
13440+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13441+ dst += PAX_USER_SHADOW_BASE;
13442+#endif
13443+
13444+ return copy_user_generic((__force_kernel void *)dst,
13445+ (__force_kernel const void *)src, size);
13446 }
13447 }
13448
13449-__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13450-__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13451+__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13452+__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13453
13454 static __must_check __always_inline int
13455-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13456+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13457 {
13458- return copy_user_generic(dst, (__force const void *)src, size);
13459+ if (size > INT_MAX)
13460+ return size;
13461+
13462+#ifdef CONFIG_PAX_MEMORY_UDEREF
13463+ if (!__access_ok(VERIFY_READ, src, size))
13464+ return size;
13465+
13466+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13467+ src += PAX_USER_SHADOW_BASE;
13468+#endif
13469+
13470+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13471 }
13472
13473-static __must_check __always_inline int
13474-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13475+static __must_check __always_inline unsigned long
13476+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13477 {
13478- return copy_user_generic((__force void *)dst, src, size);
13479+ if (size > INT_MAX)
13480+ return size;
13481+
13482+#ifdef CONFIG_PAX_MEMORY_UDEREF
13483+ if (!__access_ok(VERIFY_WRITE, dst, size))
13484+ return size;
13485+
13486+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13487+ dst += PAX_USER_SHADOW_BASE;
13488+#endif
13489+
13490+ return copy_user_generic((__force_kernel void *)dst, src, size);
13491 }
13492
13493-extern long __copy_user_nocache(void *dst, const void __user *src,
13494- unsigned size, int zerorest);
13495+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13496+ unsigned long size, int zerorest) __size_overflow(3);
13497
13498-static inline int
13499-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13500+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13501 {
13502 might_sleep();
13503+
13504+ if (size > INT_MAX)
13505+ return size;
13506+
13507+#ifdef CONFIG_PAX_MEMORY_UDEREF
13508+ if (!__access_ok(VERIFY_READ, src, size))
13509+ return size;
13510+#endif
13511+
13512 return __copy_user_nocache(dst, src, size, 1);
13513 }
13514
13515-static inline int
13516-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13517- unsigned size)
13518+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13519+ unsigned long size)
13520 {
13521+ if (size > INT_MAX)
13522+ return size;
13523+
13524+#ifdef CONFIG_PAX_MEMORY_UDEREF
13525+ if (!__access_ok(VERIFY_READ, src, size))
13526+ return size;
13527+#endif
13528+
13529 return __copy_user_nocache(dst, src, size, 0);
13530 }
13531
13532-unsigned long
13533-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13534+extern unsigned long
13535+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13536
13537 #endif /* _ASM_X86_UACCESS_64_H */
13538diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13539index bb05228..d763d5b 100644
13540--- a/arch/x86/include/asm/vdso.h
13541+++ b/arch/x86/include/asm/vdso.h
13542@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13543 #define VDSO32_SYMBOL(base, name) \
13544 ({ \
13545 extern const char VDSO32_##name[]; \
13546- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13547+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13548 })
13549 #endif
13550
13551diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13552index 5b238981..77fdd78 100644
13553--- a/arch/x86/include/asm/word-at-a-time.h
13554+++ b/arch/x86/include/asm/word-at-a-time.h
13555@@ -11,7 +11,7 @@
13556 * and shift, for example.
13557 */
13558 struct word_at_a_time {
13559- const unsigned long one_bits, high_bits;
13560+ unsigned long one_bits, high_bits;
13561 };
13562
13563 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13564diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13565index c090af1..7e7bf16 100644
13566--- a/arch/x86/include/asm/x86_init.h
13567+++ b/arch/x86/include/asm/x86_init.h
13568@@ -29,7 +29,7 @@ struct x86_init_mpparse {
13569 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13570 void (*find_smp_config)(void);
13571 void (*get_smp_config)(unsigned int early);
13572-};
13573+} __no_const;
13574
13575 /**
13576 * struct x86_init_resources - platform specific resource related ops
13577@@ -43,7 +43,7 @@ struct x86_init_resources {
13578 void (*probe_roms)(void);
13579 void (*reserve_resources)(void);
13580 char *(*memory_setup)(void);
13581-};
13582+} __no_const;
13583
13584 /**
13585 * struct x86_init_irqs - platform specific interrupt setup
13586@@ -56,7 +56,7 @@ struct x86_init_irqs {
13587 void (*pre_vector_init)(void);
13588 void (*intr_init)(void);
13589 void (*trap_init)(void);
13590-};
13591+} __no_const;
13592
13593 /**
13594 * struct x86_init_oem - oem platform specific customizing functions
13595@@ -66,7 +66,7 @@ struct x86_init_irqs {
13596 struct x86_init_oem {
13597 void (*arch_setup)(void);
13598 void (*banner)(void);
13599-};
13600+} __no_const;
13601
13602 /**
13603 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13604@@ -77,7 +77,7 @@ struct x86_init_oem {
13605 */
13606 struct x86_init_mapping {
13607 void (*pagetable_reserve)(u64 start, u64 end);
13608-};
13609+} __no_const;
13610
13611 /**
13612 * struct x86_init_paging - platform specific paging functions
13613@@ -87,7 +87,7 @@ struct x86_init_mapping {
13614 struct x86_init_paging {
13615 void (*pagetable_setup_start)(pgd_t *base);
13616 void (*pagetable_setup_done)(pgd_t *base);
13617-};
13618+} __no_const;
13619
13620 /**
13621 * struct x86_init_timers - platform specific timer setup
13622@@ -102,7 +102,7 @@ struct x86_init_timers {
13623 void (*tsc_pre_init)(void);
13624 void (*timer_init)(void);
13625 void (*wallclock_init)(void);
13626-};
13627+} __no_const;
13628
13629 /**
13630 * struct x86_init_iommu - platform specific iommu setup
13631@@ -110,7 +110,7 @@ struct x86_init_timers {
13632 */
13633 struct x86_init_iommu {
13634 int (*iommu_init)(void);
13635-};
13636+} __no_const;
13637
13638 /**
13639 * struct x86_init_pci - platform specific pci init functions
13640@@ -124,7 +124,7 @@ struct x86_init_pci {
13641 int (*init)(void);
13642 void (*init_irq)(void);
13643 void (*fixup_irqs)(void);
13644-};
13645+} __no_const;
13646
13647 /**
13648 * struct x86_init_ops - functions for platform specific setup
13649@@ -140,7 +140,7 @@ struct x86_init_ops {
13650 struct x86_init_timers timers;
13651 struct x86_init_iommu iommu;
13652 struct x86_init_pci pci;
13653-};
13654+} __no_const;
13655
13656 /**
13657 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13658@@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13659 void (*setup_percpu_clockev)(void);
13660 void (*early_percpu_clock_init)(void);
13661 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13662-};
13663+} __no_const;
13664
13665 /**
13666 * struct x86_platform_ops - platform specific runtime functions
13667@@ -177,7 +177,7 @@ struct x86_platform_ops {
13668 int (*i8042_detect)(void);
13669 void (*save_sched_clock_state)(void);
13670 void (*restore_sched_clock_state)(void);
13671-};
13672+} __no_const;
13673
13674 struct pci_dev;
13675
13676@@ -186,14 +186,14 @@ struct x86_msi_ops {
13677 void (*teardown_msi_irq)(unsigned int irq);
13678 void (*teardown_msi_irqs)(struct pci_dev *dev);
13679 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13680-};
13681+} __no_const;
13682
13683 struct x86_io_apic_ops {
13684 void (*init) (void);
13685 unsigned int (*read) (unsigned int apic, unsigned int reg);
13686 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13687 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13688-};
13689+} __no_const;
13690
13691 extern struct x86_init_ops x86_init;
13692 extern struct x86_cpuinit_ops x86_cpuinit;
13693diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13694index 8a1b6f9..a29c4e4 100644
13695--- a/arch/x86/include/asm/xsave.h
13696+++ b/arch/x86/include/asm/xsave.h
13697@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13698 {
13699 int err;
13700
13701+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13702+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13703+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13704+#endif
13705+
13706 /*
13707 * Clear the xsave header first, so that reserved fields are
13708 * initialized to zero.
13709@@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13710 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13711 {
13712 int err;
13713- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13714+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13715 u32 lmask = mask;
13716 u32 hmask = mask >> 32;
13717
13718+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13719+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13720+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13721+#endif
13722+
13723 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13724 "2:\n"
13725 ".section .fixup,\"ax\"\n"
13726diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13727index 95bf99de..de9235c 100644
13728--- a/arch/x86/kernel/acpi/sleep.c
13729+++ b/arch/x86/kernel/acpi/sleep.c
13730@@ -73,8 +73,12 @@ int acpi_suspend_lowlevel(void)
13731 #else /* CONFIG_64BIT */
13732 #ifdef CONFIG_SMP
13733 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13734+
13735+ pax_open_kernel();
13736 early_gdt_descr.address =
13737 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13738+ pax_close_kernel();
13739+
13740 initial_gs = per_cpu_offset(smp_processor_id());
13741 #endif
13742 initial_code = (unsigned long)wakeup_long64;
13743diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13744index 7261083..5c12053 100644
13745--- a/arch/x86/kernel/acpi/wakeup_32.S
13746+++ b/arch/x86/kernel/acpi/wakeup_32.S
13747@@ -30,13 +30,11 @@ wakeup_pmode_return:
13748 # and restore the stack ... but you need gdt for this to work
13749 movl saved_context_esp, %esp
13750
13751- movl %cs:saved_magic, %eax
13752- cmpl $0x12345678, %eax
13753+ cmpl $0x12345678, saved_magic
13754 jne bogus_magic
13755
13756 # jump to place where we left off
13757- movl saved_eip, %eax
13758- jmp *%eax
13759+ jmp *(saved_eip)
13760
13761 bogus_magic:
13762 jmp bogus_magic
13763diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13764index bda833c..a9bdd97 100644
13765--- a/arch/x86/kernel/alternative.c
13766+++ b/arch/x86/kernel/alternative.c
13767@@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13768 */
13769 for (a = start; a < end; a++) {
13770 instr = (u8 *)&a->instr_offset + a->instr_offset;
13771+
13772+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13773+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13774+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13775+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13776+#endif
13777+
13778 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13779 BUG_ON(a->replacementlen > a->instrlen);
13780 BUG_ON(a->instrlen > sizeof(insnbuf));
13781@@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13782 for (poff = start; poff < end; poff++) {
13783 u8 *ptr = (u8 *)poff + *poff;
13784
13785+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13786+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13787+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13788+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13789+#endif
13790+
13791 if (!*poff || ptr < text || ptr >= text_end)
13792 continue;
13793 /* turn DS segment override prefix into lock prefix */
13794- if (*ptr == 0x3e)
13795+ if (*ktla_ktva(ptr) == 0x3e)
13796 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13797 };
13798 mutex_unlock(&text_mutex);
13799@@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13800 for (poff = start; poff < end; poff++) {
13801 u8 *ptr = (u8 *)poff + *poff;
13802
13803+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13804+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13805+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13806+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13807+#endif
13808+
13809 if (!*poff || ptr < text || ptr >= text_end)
13810 continue;
13811 /* turn lock prefix into DS segment override prefix */
13812- if (*ptr == 0xf0)
13813+ if (*ktla_ktva(ptr) == 0xf0)
13814 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13815 };
13816 mutex_unlock(&text_mutex);
13817@@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13818
13819 BUG_ON(p->len > MAX_PATCH_LEN);
13820 /* prep the buffer with the original instructions */
13821- memcpy(insnbuf, p->instr, p->len);
13822+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13823 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13824 (unsigned long)p->instr, p->len);
13825
13826@@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13827 if (smp_alt_once)
13828 free_init_pages("SMP alternatives",
13829 (unsigned long)__smp_locks,
13830- (unsigned long)__smp_locks_end);
13831+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13832
13833 restart_nmi();
13834 }
13835@@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13836 * instructions. And on the local CPU you need to be protected again NMI or MCE
13837 * handlers seeing an inconsistent instruction while you patch.
13838 */
13839-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13840+void *__kprobes text_poke_early(void *addr, const void *opcode,
13841 size_t len)
13842 {
13843 unsigned long flags;
13844 local_irq_save(flags);
13845- memcpy(addr, opcode, len);
13846+
13847+ pax_open_kernel();
13848+ memcpy(ktla_ktva(addr), opcode, len);
13849 sync_core();
13850+ pax_close_kernel();
13851+
13852 local_irq_restore(flags);
13853 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13854 that causes hangs on some VIA CPUs. */
13855@@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13856 */
13857 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13858 {
13859- unsigned long flags;
13860- char *vaddr;
13861+ unsigned char *vaddr = ktla_ktva(addr);
13862 struct page *pages[2];
13863- int i;
13864+ size_t i;
13865
13866 if (!core_kernel_text((unsigned long)addr)) {
13867- pages[0] = vmalloc_to_page(addr);
13868- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13869+ pages[0] = vmalloc_to_page(vaddr);
13870+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13871 } else {
13872- pages[0] = virt_to_page(addr);
13873+ pages[0] = virt_to_page(vaddr);
13874 WARN_ON(!PageReserved(pages[0]));
13875- pages[1] = virt_to_page(addr + PAGE_SIZE);
13876+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13877 }
13878 BUG_ON(!pages[0]);
13879- local_irq_save(flags);
13880- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13881- if (pages[1])
13882- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13883- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13884- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13885- clear_fixmap(FIX_TEXT_POKE0);
13886- if (pages[1])
13887- clear_fixmap(FIX_TEXT_POKE1);
13888- local_flush_tlb();
13889- sync_core();
13890- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13891- that causes hangs on some VIA CPUs. */
13892+ text_poke_early(addr, opcode, len);
13893 for (i = 0; i < len; i++)
13894- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13895- local_irq_restore(flags);
13896+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13897 return addr;
13898 }
13899
13900diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13901index 39a222e..85a7767 100644
13902--- a/arch/x86/kernel/apic/apic.c
13903+++ b/arch/x86/kernel/apic/apic.c
13904@@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13905 /*
13906 * Debug level, exported for io_apic.c
13907 */
13908-unsigned int apic_verbosity;
13909+int apic_verbosity;
13910
13911 int pic_mode;
13912
13913@@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13914 apic_write(APIC_ESR, 0);
13915 v1 = apic_read(APIC_ESR);
13916 ack_APIC_irq();
13917- atomic_inc(&irq_err_count);
13918+ atomic_inc_unchecked(&irq_err_count);
13919
13920 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13921 smp_processor_id(), v0 , v1);
13922diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13923index 5f0ff59..f9e01bc 100644
13924--- a/arch/x86/kernel/apic/io_apic.c
13925+++ b/arch/x86/kernel/apic/io_apic.c
13926@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13927 }
13928 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13929
13930-void lock_vector_lock(void)
13931+void lock_vector_lock(void) __acquires(vector_lock)
13932 {
13933 /* Used to the online set of cpus does not change
13934 * during assign_irq_vector.
13935@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13936 raw_spin_lock(&vector_lock);
13937 }
13938
13939-void unlock_vector_lock(void)
13940+void unlock_vector_lock(void) __releases(vector_lock)
13941 {
13942 raw_spin_unlock(&vector_lock);
13943 }
13944@@ -2369,7 +2369,7 @@ static void ack_apic_edge(struct irq_data *data)
13945 ack_APIC_irq();
13946 }
13947
13948-atomic_t irq_mis_count;
13949+atomic_unchecked_t irq_mis_count;
13950
13951 #ifdef CONFIG_GENERIC_PENDING_IRQ
13952 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13953@@ -2510,7 +2510,7 @@ static void ack_apic_level(struct irq_data *data)
13954 * at the cpu.
13955 */
13956 if (!(v & (1 << (i & 0x1f)))) {
13957- atomic_inc(&irq_mis_count);
13958+ atomic_inc_unchecked(&irq_mis_count);
13959
13960 eoi_ioapic_irq(irq, cfg);
13961 }
13962diff --git a/arch/x86/kernel/apic/probe_64.c b/arch/x86/kernel/apic/probe_64.c
13963index 3fe9866..6abf259 100644
13964--- a/arch/x86/kernel/apic/probe_64.c
13965+++ b/arch/x86/kernel/apic/probe_64.c
13966@@ -50,7 +50,7 @@ void __init default_setup_apic_routing(void)
13967
13968 if (is_vsmp_box()) {
13969 /* need to update phys_pkg_id */
13970- apic->phys_pkg_id = apicid_phys_pkg_id;
13971+ *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
13972 }
13973 }
13974
13975diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13976index 07b0c0d..1df6f42 100644
13977--- a/arch/x86/kernel/apm_32.c
13978+++ b/arch/x86/kernel/apm_32.c
13979@@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13980 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13981 * even though they are called in protected mode.
13982 */
13983-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13984+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13985 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13986
13987 static const char driver_version[] = "1.16ac"; /* no spaces */
13988@@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13989 BUG_ON(cpu != 0);
13990 gdt = get_cpu_gdt_table(cpu);
13991 save_desc_40 = gdt[0x40 / 8];
13992+
13993+ pax_open_kernel();
13994 gdt[0x40 / 8] = bad_bios_desc;
13995+ pax_close_kernel();
13996
13997 apm_irq_save(flags);
13998 APM_DO_SAVE_SEGS;
13999@@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
14000 &call->esi);
14001 APM_DO_RESTORE_SEGS;
14002 apm_irq_restore(flags);
14003+
14004+ pax_open_kernel();
14005 gdt[0x40 / 8] = save_desc_40;
14006+ pax_close_kernel();
14007+
14008 put_cpu();
14009
14010 return call->eax & 0xff;
14011@@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
14012 BUG_ON(cpu != 0);
14013 gdt = get_cpu_gdt_table(cpu);
14014 save_desc_40 = gdt[0x40 / 8];
14015+
14016+ pax_open_kernel();
14017 gdt[0x40 / 8] = bad_bios_desc;
14018+ pax_close_kernel();
14019
14020 apm_irq_save(flags);
14021 APM_DO_SAVE_SEGS;
14022@@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
14023 &call->eax);
14024 APM_DO_RESTORE_SEGS;
14025 apm_irq_restore(flags);
14026+
14027+ pax_open_kernel();
14028 gdt[0x40 / 8] = save_desc_40;
14029+ pax_close_kernel();
14030+
14031 put_cpu();
14032 return error;
14033 }
14034@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14035 * code to that CPU.
14036 */
14037 gdt = get_cpu_gdt_table(0);
14038+
14039+ pax_open_kernel();
14040 set_desc_base(&gdt[APM_CS >> 3],
14041 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14042 set_desc_base(&gdt[APM_CS_16 >> 3],
14043 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14044 set_desc_base(&gdt[APM_DS >> 3],
14045 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14046+ pax_close_kernel();
14047
14048 proc_create("apm", 0, NULL, &apm_file_ops);
14049
14050diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14051index 68de2dc..1f3c720 100644
14052--- a/arch/x86/kernel/asm-offsets.c
14053+++ b/arch/x86/kernel/asm-offsets.c
14054@@ -33,6 +33,8 @@ void common(void) {
14055 OFFSET(TI_status, thread_info, status);
14056 OFFSET(TI_addr_limit, thread_info, addr_limit);
14057 OFFSET(TI_preempt_count, thread_info, preempt_count);
14058+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14059+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14060
14061 BLANK();
14062 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14063@@ -53,8 +55,26 @@ void common(void) {
14064 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14065 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14066 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14067+
14068+#ifdef CONFIG_PAX_KERNEXEC
14069+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14070 #endif
14071
14072+#ifdef CONFIG_PAX_MEMORY_UDEREF
14073+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14074+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14075+#ifdef CONFIG_X86_64
14076+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14077+#endif
14078+#endif
14079+
14080+#endif
14081+
14082+ BLANK();
14083+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14084+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14085+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14086+
14087 #ifdef CONFIG_XEN
14088 BLANK();
14089 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14090diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14091index 1b4754f..fbb4227 100644
14092--- a/arch/x86/kernel/asm-offsets_64.c
14093+++ b/arch/x86/kernel/asm-offsets_64.c
14094@@ -76,6 +76,7 @@ int main(void)
14095 BLANK();
14096 #undef ENTRY
14097
14098+ DEFINE(TSS_size, sizeof(struct tss_struct));
14099 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14100 BLANK();
14101
14102diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14103index 6ab6aa2..8f71507 100644
14104--- a/arch/x86/kernel/cpu/Makefile
14105+++ b/arch/x86/kernel/cpu/Makefile
14106@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14107 CFLAGS_REMOVE_perf_event.o = -pg
14108 endif
14109
14110-# Make sure load_percpu_segment has no stackprotector
14111-nostackp := $(call cc-option, -fno-stack-protector)
14112-CFLAGS_common.o := $(nostackp)
14113-
14114 obj-y := intel_cacheinfo.o scattered.o topology.o
14115 obj-y += proc.o capflags.o powerflags.o common.o
14116 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14117diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14118index 146bb62..ac9c74a 100644
14119--- a/arch/x86/kernel/cpu/amd.c
14120+++ b/arch/x86/kernel/cpu/amd.c
14121@@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14122 unsigned int size)
14123 {
14124 /* AMD errata T13 (order #21922) */
14125- if ((c->x86 == 6)) {
14126+ if (c->x86 == 6) {
14127 /* Duron Rev A0 */
14128 if (c->x86_model == 3 && c->x86_mask == 0)
14129 size = 64;
14130diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14131index cc9c146..2373d59 100644
14132--- a/arch/x86/kernel/cpu/common.c
14133+++ b/arch/x86/kernel/cpu/common.c
14134@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14135
14136 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14137
14138-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14139-#ifdef CONFIG_X86_64
14140- /*
14141- * We need valid kernel segments for data and code in long mode too
14142- * IRET will check the segment types kkeil 2000/10/28
14143- * Also sysret mandates a special GDT layout
14144- *
14145- * TLS descriptors are currently at a different place compared to i386.
14146- * Hopefully nobody expects them at a fixed place (Wine?)
14147- */
14148- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14149- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14150- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14151- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14152- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14153- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14154-#else
14155- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14156- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14157- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14158- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14159- /*
14160- * Segments used for calling PnP BIOS have byte granularity.
14161- * They code segments and data segments have fixed 64k limits,
14162- * the transfer segment sizes are set at run time.
14163- */
14164- /* 32-bit code */
14165- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14166- /* 16-bit code */
14167- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14168- /* 16-bit data */
14169- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14170- /* 16-bit data */
14171- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14172- /* 16-bit data */
14173- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14174- /*
14175- * The APM segments have byte granularity and their bases
14176- * are set at run time. All have 64k limits.
14177- */
14178- /* 32-bit code */
14179- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14180- /* 16-bit code */
14181- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14182- /* data */
14183- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14184-
14185- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14186- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14187- GDT_STACK_CANARY_INIT
14188-#endif
14189-} };
14190-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14191-
14192 static int __init x86_xsave_setup(char *s)
14193 {
14194 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14195@@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14196 {
14197 struct desc_ptr gdt_descr;
14198
14199- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14200+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14201 gdt_descr.size = GDT_SIZE - 1;
14202 load_gdt(&gdt_descr);
14203 /* Reload the per-cpu base */
14204@@ -843,6 +789,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14205 /* Filter out anything that depends on CPUID levels we don't have */
14206 filter_cpuid_features(c, true);
14207
14208+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14209+ setup_clear_cpu_cap(X86_FEATURE_SEP);
14210+#endif
14211+
14212 /* If the model name is still unset, do table lookup. */
14213 if (!c->x86_model_id[0]) {
14214 const char *p;
14215@@ -1023,10 +973,12 @@ static __init int setup_disablecpuid(char *arg)
14216 }
14217 __setup("clearcpuid=", setup_disablecpuid);
14218
14219+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14220+EXPORT_PER_CPU_SYMBOL(current_tinfo);
14221+
14222 #ifdef CONFIG_X86_64
14223 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14224-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14225- (unsigned long) nmi_idt_table };
14226+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14227
14228 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14229 irq_stack_union) __aligned(PAGE_SIZE);
14230@@ -1040,7 +992,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14231 EXPORT_PER_CPU_SYMBOL(current_task);
14232
14233 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14234- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14235+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14236 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14237
14238 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14239@@ -1134,7 +1086,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14240 {
14241 memset(regs, 0, sizeof(struct pt_regs));
14242 regs->fs = __KERNEL_PERCPU;
14243- regs->gs = __KERNEL_STACK_CANARY;
14244+ savesegment(gs, regs->gs);
14245
14246 return regs;
14247 }
14248@@ -1189,7 +1141,7 @@ void __cpuinit cpu_init(void)
14249 int i;
14250
14251 cpu = stack_smp_processor_id();
14252- t = &per_cpu(init_tss, cpu);
14253+ t = init_tss + cpu;
14254 oist = &per_cpu(orig_ist, cpu);
14255
14256 #ifdef CONFIG_NUMA
14257@@ -1215,7 +1167,7 @@ void __cpuinit cpu_init(void)
14258 switch_to_new_gdt(cpu);
14259 loadsegment(fs, 0);
14260
14261- load_idt((const struct desc_ptr *)&idt_descr);
14262+ load_idt(&idt_descr);
14263
14264 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14265 syscall_init();
14266@@ -1224,7 +1176,6 @@ void __cpuinit cpu_init(void)
14267 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14268 barrier();
14269
14270- x86_configure_nx();
14271 if (cpu != 0)
14272 enable_x2apic();
14273
14274@@ -1280,7 +1231,7 @@ void __cpuinit cpu_init(void)
14275 {
14276 int cpu = smp_processor_id();
14277 struct task_struct *curr = current;
14278- struct tss_struct *t = &per_cpu(init_tss, cpu);
14279+ struct tss_struct *t = init_tss + cpu;
14280 struct thread_struct *thread = &curr->thread;
14281
14282 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14283diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14284index 3e6ff6c..54b4992 100644
14285--- a/arch/x86/kernel/cpu/intel.c
14286+++ b/arch/x86/kernel/cpu/intel.c
14287@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14288 * Update the IDT descriptor and reload the IDT so that
14289 * it uses the read-only mapped virtual address.
14290 */
14291- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14292+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14293 load_idt(&idt_descr);
14294 }
14295 #endif
14296diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14297index c46ed49..5dc0a53 100644
14298--- a/arch/x86/kernel/cpu/mcheck/mce.c
14299+++ b/arch/x86/kernel/cpu/mcheck/mce.c
14300@@ -42,6 +42,7 @@
14301 #include <asm/processor.h>
14302 #include <asm/mce.h>
14303 #include <asm/msr.h>
14304+#include <asm/local.h>
14305
14306 #include "mce-internal.h"
14307
14308@@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14309 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14310 m->cs, m->ip);
14311
14312- if (m->cs == __KERNEL_CS)
14313+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14314 print_symbol("{%s}", m->ip);
14315 pr_cont("\n");
14316 }
14317@@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14318
14319 #define PANIC_TIMEOUT 5 /* 5 seconds */
14320
14321-static atomic_t mce_paniced;
14322+static atomic_unchecked_t mce_paniced;
14323
14324 static int fake_panic;
14325-static atomic_t mce_fake_paniced;
14326+static atomic_unchecked_t mce_fake_paniced;
14327
14328 /* Panic in progress. Enable interrupts and wait for final IPI */
14329 static void wait_for_panic(void)
14330@@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14331 /*
14332 * Make sure only one CPU runs in machine check panic
14333 */
14334- if (atomic_inc_return(&mce_paniced) > 1)
14335+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14336 wait_for_panic();
14337 barrier();
14338
14339@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14340 console_verbose();
14341 } else {
14342 /* Don't log too much for fake panic */
14343- if (atomic_inc_return(&mce_fake_paniced) > 1)
14344+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14345 return;
14346 }
14347 /* First print corrected ones that are still unlogged */
14348@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
14349 * might have been modified by someone else.
14350 */
14351 rmb();
14352- if (atomic_read(&mce_paniced))
14353+ if (atomic_read_unchecked(&mce_paniced))
14354 wait_for_panic();
14355 if (!monarch_timeout)
14356 goto out;
14357@@ -1581,7 +1582,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14358 }
14359
14360 /* Call the installed machine check handler for this CPU setup. */
14361-void (*machine_check_vector)(struct pt_regs *, long error_code) =
14362+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14363 unexpected_machine_check;
14364
14365 /*
14366@@ -1604,7 +1605,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14367 return;
14368 }
14369
14370+ pax_open_kernel();
14371 machine_check_vector = do_machine_check;
14372+ pax_close_kernel();
14373
14374 __mcheck_cpu_init_generic();
14375 __mcheck_cpu_init_vendor(c);
14376@@ -1618,7 +1621,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14377 */
14378
14379 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14380-static int mce_chrdev_open_count; /* #times opened */
14381+static local_t mce_chrdev_open_count; /* #times opened */
14382 static int mce_chrdev_open_exclu; /* already open exclusive? */
14383
14384 static int mce_chrdev_open(struct inode *inode, struct file *file)
14385@@ -1626,7 +1629,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14386 spin_lock(&mce_chrdev_state_lock);
14387
14388 if (mce_chrdev_open_exclu ||
14389- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14390+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14391 spin_unlock(&mce_chrdev_state_lock);
14392
14393 return -EBUSY;
14394@@ -1634,7 +1637,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14395
14396 if (file->f_flags & O_EXCL)
14397 mce_chrdev_open_exclu = 1;
14398- mce_chrdev_open_count++;
14399+ local_inc(&mce_chrdev_open_count);
14400
14401 spin_unlock(&mce_chrdev_state_lock);
14402
14403@@ -1645,7 +1648,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14404 {
14405 spin_lock(&mce_chrdev_state_lock);
14406
14407- mce_chrdev_open_count--;
14408+ local_dec(&mce_chrdev_open_count);
14409 mce_chrdev_open_exclu = 0;
14410
14411 spin_unlock(&mce_chrdev_state_lock);
14412@@ -2370,7 +2373,7 @@ struct dentry *mce_get_debugfs_dir(void)
14413 static void mce_reset(void)
14414 {
14415 cpu_missing = 0;
14416- atomic_set(&mce_fake_paniced, 0);
14417+ atomic_set_unchecked(&mce_fake_paniced, 0);
14418 atomic_set(&mce_executing, 0);
14419 atomic_set(&mce_callin, 0);
14420 atomic_set(&global_nwo, 0);
14421diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14422index 2d5454c..51987eb 100644
14423--- a/arch/x86/kernel/cpu/mcheck/p5.c
14424+++ b/arch/x86/kernel/cpu/mcheck/p5.c
14425@@ -11,6 +11,7 @@
14426 #include <asm/processor.h>
14427 #include <asm/mce.h>
14428 #include <asm/msr.h>
14429+#include <asm/pgtable.h>
14430
14431 /* By default disabled */
14432 int mce_p5_enabled __read_mostly;
14433@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14434 if (!cpu_has(c, X86_FEATURE_MCE))
14435 return;
14436
14437+ pax_open_kernel();
14438 machine_check_vector = pentium_machine_check;
14439+ pax_close_kernel();
14440 /* Make sure the vector pointer is visible before we enable MCEs: */
14441 wmb();
14442
14443diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14444index 2d7998f..17c9de1 100644
14445--- a/arch/x86/kernel/cpu/mcheck/winchip.c
14446+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14447@@ -10,6 +10,7 @@
14448 #include <asm/processor.h>
14449 #include <asm/mce.h>
14450 #include <asm/msr.h>
14451+#include <asm/pgtable.h>
14452
14453 /* Machine check handler for WinChip C6: */
14454 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14455@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14456 {
14457 u32 lo, hi;
14458
14459+ pax_open_kernel();
14460 machine_check_vector = winchip_machine_check;
14461+ pax_close_kernel();
14462 /* Make sure the vector pointer is visible before we enable MCEs: */
14463 wmb();
14464
14465diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14466index 6b96110..0da73eb 100644
14467--- a/arch/x86/kernel/cpu/mtrr/main.c
14468+++ b/arch/x86/kernel/cpu/mtrr/main.c
14469@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14470 u64 size_or_mask, size_and_mask;
14471 static bool mtrr_aps_delayed_init;
14472
14473-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14474+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14475
14476 const struct mtrr_ops *mtrr_if;
14477
14478diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14479index df5e41f..816c719 100644
14480--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14481+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14482@@ -25,7 +25,7 @@ struct mtrr_ops {
14483 int (*validate_add_page)(unsigned long base, unsigned long size,
14484 unsigned int type);
14485 int (*have_wrcomb)(void);
14486-};
14487+} __do_const;
14488
14489 extern int generic_get_free_region(unsigned long base, unsigned long size,
14490 int replace_reg);
14491diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14492index c4706cf..264b0f7 100644
14493--- a/arch/x86/kernel/cpu/perf_event.c
14494+++ b/arch/x86/kernel/cpu/perf_event.c
14495@@ -1837,7 +1837,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14496 break;
14497
14498 perf_callchain_store(entry, frame.return_address);
14499- fp = frame.next_frame;
14500+ fp = (const void __force_user *)frame.next_frame;
14501 }
14502 }
14503
14504diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14505index 187c294..28a069c 100644
14506--- a/arch/x86/kernel/cpu/perf_event_intel.c
14507+++ b/arch/x86/kernel/cpu/perf_event_intel.c
14508@@ -1811,10 +1811,10 @@ __init int intel_pmu_init(void)
14509 * v2 and above have a perf capabilities MSR
14510 */
14511 if (version > 1) {
14512- u64 capabilities;
14513+ u64 capabilities = x86_pmu.intel_cap.capabilities;
14514
14515- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14516- x86_pmu.intel_cap.capabilities = capabilities;
14517+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14518+ x86_pmu.intel_cap.capabilities = capabilities;
14519 }
14520
14521 intel_ds_init();
14522diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14523index 13ad899..f642b9a 100644
14524--- a/arch/x86/kernel/crash.c
14525+++ b/arch/x86/kernel/crash.c
14526@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14527 {
14528 #ifdef CONFIG_X86_32
14529 struct pt_regs fixed_regs;
14530-#endif
14531
14532-#ifdef CONFIG_X86_32
14533- if (!user_mode_vm(regs)) {
14534+ if (!user_mode(regs)) {
14535 crash_fixup_ss_esp(&fixed_regs, regs);
14536 regs = &fixed_regs;
14537 }
14538diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14539index 37250fe..bf2ec74 100644
14540--- a/arch/x86/kernel/doublefault_32.c
14541+++ b/arch/x86/kernel/doublefault_32.c
14542@@ -11,7 +11,7 @@
14543
14544 #define DOUBLEFAULT_STACKSIZE (1024)
14545 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14546-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14547+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14548
14549 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14550
14551@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14552 unsigned long gdt, tss;
14553
14554 store_gdt(&gdt_desc);
14555- gdt = gdt_desc.address;
14556+ gdt = (unsigned long)gdt_desc.address;
14557
14558 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14559
14560@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14561 /* 0x2 bit is always set */
14562 .flags = X86_EFLAGS_SF | 0x2,
14563 .sp = STACK_START,
14564- .es = __USER_DS,
14565+ .es = __KERNEL_DS,
14566 .cs = __KERNEL_CS,
14567 .ss = __KERNEL_DS,
14568- .ds = __USER_DS,
14569+ .ds = __KERNEL_DS,
14570 .fs = __KERNEL_PERCPU,
14571
14572 .__cr3 = __pa_nodebug(swapper_pg_dir),
14573diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14574index 571246d..81f335c 100644
14575--- a/arch/x86/kernel/dumpstack.c
14576+++ b/arch/x86/kernel/dumpstack.c
14577@@ -2,6 +2,9 @@
14578 * Copyright (C) 1991, 1992 Linus Torvalds
14579 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14580 */
14581+#ifdef CONFIG_GRKERNSEC_HIDESYM
14582+#define __INCLUDED_BY_HIDESYM 1
14583+#endif
14584 #include <linux/kallsyms.h>
14585 #include <linux/kprobes.h>
14586 #include <linux/uaccess.h>
14587@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14588 static void
14589 print_ftrace_graph_addr(unsigned long addr, void *data,
14590 const struct stacktrace_ops *ops,
14591- struct thread_info *tinfo, int *graph)
14592+ struct task_struct *task, int *graph)
14593 {
14594- struct task_struct *task;
14595 unsigned long ret_addr;
14596 int index;
14597
14598 if (addr != (unsigned long)return_to_handler)
14599 return;
14600
14601- task = tinfo->task;
14602 index = task->curr_ret_stack;
14603
14604 if (!task->ret_stack || index < *graph)
14605@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14606 static inline void
14607 print_ftrace_graph_addr(unsigned long addr, void *data,
14608 const struct stacktrace_ops *ops,
14609- struct thread_info *tinfo, int *graph)
14610+ struct task_struct *task, int *graph)
14611 { }
14612 #endif
14613
14614@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14615 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14616 */
14617
14618-static inline int valid_stack_ptr(struct thread_info *tinfo,
14619- void *p, unsigned int size, void *end)
14620+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14621 {
14622- void *t = tinfo;
14623 if (end) {
14624 if (p < end && p >= (end-THREAD_SIZE))
14625 return 1;
14626@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14627 }
14628
14629 unsigned long
14630-print_context_stack(struct thread_info *tinfo,
14631+print_context_stack(struct task_struct *task, void *stack_start,
14632 unsigned long *stack, unsigned long bp,
14633 const struct stacktrace_ops *ops, void *data,
14634 unsigned long *end, int *graph)
14635 {
14636 struct stack_frame *frame = (struct stack_frame *)bp;
14637
14638- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14639+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14640 unsigned long addr;
14641
14642 addr = *stack;
14643@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14644 } else {
14645 ops->address(data, addr, 0);
14646 }
14647- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14648+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14649 }
14650 stack++;
14651 }
14652@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14653 EXPORT_SYMBOL_GPL(print_context_stack);
14654
14655 unsigned long
14656-print_context_stack_bp(struct thread_info *tinfo,
14657+print_context_stack_bp(struct task_struct *task, void *stack_start,
14658 unsigned long *stack, unsigned long bp,
14659 const struct stacktrace_ops *ops, void *data,
14660 unsigned long *end, int *graph)
14661@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14662 struct stack_frame *frame = (struct stack_frame *)bp;
14663 unsigned long *ret_addr = &frame->return_address;
14664
14665- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14666+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14667 unsigned long addr = *ret_addr;
14668
14669 if (!__kernel_text_address(addr))
14670@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14671 ops->address(data, addr, 1);
14672 frame = frame->next_frame;
14673 ret_addr = &frame->return_address;
14674- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14675+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14676 }
14677
14678 return (unsigned long)frame;
14679@@ -189,7 +188,7 @@ void dump_stack(void)
14680
14681 bp = stack_frame(current, NULL);
14682 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14683- current->pid, current->comm, print_tainted(),
14684+ task_pid_nr(current), current->comm, print_tainted(),
14685 init_utsname()->release,
14686 (int)strcspn(init_utsname()->version, " "),
14687 init_utsname()->version);
14688@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14689 }
14690 EXPORT_SYMBOL_GPL(oops_begin);
14691
14692+extern void gr_handle_kernel_exploit(void);
14693+
14694 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14695 {
14696 if (regs && kexec_should_crash(current))
14697@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14698 panic("Fatal exception in interrupt");
14699 if (panic_on_oops)
14700 panic("Fatal exception");
14701- do_exit(signr);
14702+
14703+ gr_handle_kernel_exploit();
14704+
14705+ do_group_exit(signr);
14706 }
14707
14708 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14709@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14710
14711 show_regs(regs);
14712 #ifdef CONFIG_X86_32
14713- if (user_mode_vm(regs)) {
14714+ if (user_mode(regs)) {
14715 sp = regs->sp;
14716 ss = regs->ss & 0xffff;
14717 } else {
14718@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14719 unsigned long flags = oops_begin();
14720 int sig = SIGSEGV;
14721
14722- if (!user_mode_vm(regs))
14723+ if (!user_mode(regs))
14724 report_bug(regs->ip, regs);
14725
14726 if (__die(str, regs, err))
14727diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14728index e0b1d78..a8ade5e 100644
14729--- a/arch/x86/kernel/dumpstack_32.c
14730+++ b/arch/x86/kernel/dumpstack_32.c
14731@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14732 bp = stack_frame(task, regs);
14733
14734 for (;;) {
14735- struct thread_info *context;
14736+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14737
14738- context = (struct thread_info *)
14739- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14740- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14741+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14742
14743- stack = (unsigned long *)context->previous_esp;
14744- if (!stack)
14745+ if (stack_start == task_stack_page(task))
14746 break;
14747+ stack = *(unsigned long **)stack_start;
14748 if (ops->stack(data, "IRQ") < 0)
14749 break;
14750 touch_nmi_watchdog();
14751@@ -87,7 +85,7 @@ void show_regs(struct pt_regs *regs)
14752 int i;
14753
14754 print_modules();
14755- __show_regs(regs, !user_mode_vm(regs));
14756+ __show_regs(regs, !user_mode(regs));
14757
14758 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14759 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14760@@ -96,21 +94,22 @@ void show_regs(struct pt_regs *regs)
14761 * When in-kernel, we also print out the stack and code at the
14762 * time of the fault..
14763 */
14764- if (!user_mode_vm(regs)) {
14765+ if (!user_mode(regs)) {
14766 unsigned int code_prologue = code_bytes * 43 / 64;
14767 unsigned int code_len = code_bytes;
14768 unsigned char c;
14769 u8 *ip;
14770+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14771
14772 printk(KERN_EMERG "Stack:\n");
14773 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14774
14775 printk(KERN_EMERG "Code: ");
14776
14777- ip = (u8 *)regs->ip - code_prologue;
14778+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14779 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14780 /* try starting at IP */
14781- ip = (u8 *)regs->ip;
14782+ ip = (u8 *)regs->ip + cs_base;
14783 code_len = code_len - code_prologue + 1;
14784 }
14785 for (i = 0; i < code_len; i++, ip++) {
14786@@ -119,7 +118,7 @@ void show_regs(struct pt_regs *regs)
14787 printk(KERN_CONT " Bad EIP value.");
14788 break;
14789 }
14790- if (ip == (u8 *)regs->ip)
14791+ if (ip == (u8 *)regs->ip + cs_base)
14792 printk(KERN_CONT "<%02x> ", c);
14793 else
14794 printk(KERN_CONT "%02x ", c);
14795@@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14796 {
14797 unsigned short ud2;
14798
14799+ ip = ktla_ktva(ip);
14800 if (ip < PAGE_OFFSET)
14801 return 0;
14802 if (probe_kernel_address((unsigned short *)ip, ud2))
14803@@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14804
14805 return ud2 == 0x0b0f;
14806 }
14807+
14808+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14809+void pax_check_alloca(unsigned long size)
14810+{
14811+ unsigned long sp = (unsigned long)&sp, stack_left;
14812+
14813+ /* all kernel stacks are of the same size */
14814+ stack_left = sp & (THREAD_SIZE - 1);
14815+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14816+}
14817+EXPORT_SYMBOL(pax_check_alloca);
14818+#endif
14819diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14820index 791b761..2ab6e33 100644
14821--- a/arch/x86/kernel/dumpstack_64.c
14822+++ b/arch/x86/kernel/dumpstack_64.c
14823@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14824 unsigned long *irq_stack_end =
14825 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14826 unsigned used = 0;
14827- struct thread_info *tinfo;
14828 int graph = 0;
14829 unsigned long dummy;
14830+ void *stack_start;
14831
14832 if (!task)
14833 task = current;
14834@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14835 * current stack address. If the stacks consist of nested
14836 * exceptions
14837 */
14838- tinfo = task_thread_info(task);
14839 for (;;) {
14840 char *id;
14841 unsigned long *estack_end;
14842+
14843 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14844 &used, &id);
14845
14846@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14847 if (ops->stack(data, id) < 0)
14848 break;
14849
14850- bp = ops->walk_stack(tinfo, stack, bp, ops,
14851+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14852 data, estack_end, &graph);
14853 ops->stack(data, "<EOE>");
14854 /*
14855@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14856 * second-to-last pointer (index -2 to end) in the
14857 * exception stack:
14858 */
14859+ if ((u16)estack_end[-1] != __KERNEL_DS)
14860+ goto out;
14861 stack = (unsigned long *) estack_end[-2];
14862 continue;
14863 }
14864@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14865 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14866 if (ops->stack(data, "IRQ") < 0)
14867 break;
14868- bp = ops->walk_stack(tinfo, stack, bp,
14869+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14870 ops, data, irq_stack_end, &graph);
14871 /*
14872 * We link to the next stack (which would be
14873@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14874 /*
14875 * This handles the process stack:
14876 */
14877- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14878+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14879+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14880+out:
14881 put_cpu();
14882 }
14883 EXPORT_SYMBOL(dump_trace);
14884@@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14885
14886 return ud2 == 0x0b0f;
14887 }
14888+
14889+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14890+void pax_check_alloca(unsigned long size)
14891+{
14892+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14893+ unsigned cpu, used;
14894+ char *id;
14895+
14896+ /* check the process stack first */
14897+ stack_start = (unsigned long)task_stack_page(current);
14898+ stack_end = stack_start + THREAD_SIZE;
14899+ if (likely(stack_start <= sp && sp < stack_end)) {
14900+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14901+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14902+ return;
14903+ }
14904+
14905+ cpu = get_cpu();
14906+
14907+ /* check the irq stacks */
14908+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14909+ stack_start = stack_end - IRQ_STACK_SIZE;
14910+ if (stack_start <= sp && sp < stack_end) {
14911+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14912+ put_cpu();
14913+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14914+ return;
14915+ }
14916+
14917+ /* check the exception stacks */
14918+ used = 0;
14919+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14920+ stack_start = stack_end - EXCEPTION_STKSZ;
14921+ if (stack_end && stack_start <= sp && sp < stack_end) {
14922+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14923+ put_cpu();
14924+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14925+ return;
14926+ }
14927+
14928+ put_cpu();
14929+
14930+ /* unknown stack */
14931+ BUG();
14932+}
14933+EXPORT_SYMBOL(pax_check_alloca);
14934+#endif
14935diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14936index 9b9f18b..9fcaa04 100644
14937--- a/arch/x86/kernel/early_printk.c
14938+++ b/arch/x86/kernel/early_printk.c
14939@@ -7,6 +7,7 @@
14940 #include <linux/pci_regs.h>
14941 #include <linux/pci_ids.h>
14942 #include <linux/errno.h>
14943+#include <linux/sched.h>
14944 #include <asm/io.h>
14945 #include <asm/processor.h>
14946 #include <asm/fcntl.h>
14947diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14948index 623f288..8bdd78a 100644
14949--- a/arch/x86/kernel/entry_32.S
14950+++ b/arch/x86/kernel/entry_32.S
14951@@ -176,13 +176,153 @@
14952 /*CFI_REL_OFFSET gs, PT_GS*/
14953 .endm
14954 .macro SET_KERNEL_GS reg
14955+
14956+#ifdef CONFIG_CC_STACKPROTECTOR
14957 movl $(__KERNEL_STACK_CANARY), \reg
14958+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14959+ movl $(__USER_DS), \reg
14960+#else
14961+ xorl \reg, \reg
14962+#endif
14963+
14964 movl \reg, %gs
14965 .endm
14966
14967 #endif /* CONFIG_X86_32_LAZY_GS */
14968
14969-.macro SAVE_ALL
14970+.macro pax_enter_kernel
14971+#ifdef CONFIG_PAX_KERNEXEC
14972+ call pax_enter_kernel
14973+#endif
14974+.endm
14975+
14976+.macro pax_exit_kernel
14977+#ifdef CONFIG_PAX_KERNEXEC
14978+ call pax_exit_kernel
14979+#endif
14980+.endm
14981+
14982+#ifdef CONFIG_PAX_KERNEXEC
14983+ENTRY(pax_enter_kernel)
14984+#ifdef CONFIG_PARAVIRT
14985+ pushl %eax
14986+ pushl %ecx
14987+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14988+ mov %eax, %esi
14989+#else
14990+ mov %cr0, %esi
14991+#endif
14992+ bts $16, %esi
14993+ jnc 1f
14994+ mov %cs, %esi
14995+ cmp $__KERNEL_CS, %esi
14996+ jz 3f
14997+ ljmp $__KERNEL_CS, $3f
14998+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14999+2:
15000+#ifdef CONFIG_PARAVIRT
15001+ mov %esi, %eax
15002+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15003+#else
15004+ mov %esi, %cr0
15005+#endif
15006+3:
15007+#ifdef CONFIG_PARAVIRT
15008+ popl %ecx
15009+ popl %eax
15010+#endif
15011+ ret
15012+ENDPROC(pax_enter_kernel)
15013+
15014+ENTRY(pax_exit_kernel)
15015+#ifdef CONFIG_PARAVIRT
15016+ pushl %eax
15017+ pushl %ecx
15018+#endif
15019+ mov %cs, %esi
15020+ cmp $__KERNEXEC_KERNEL_CS, %esi
15021+ jnz 2f
15022+#ifdef CONFIG_PARAVIRT
15023+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15024+ mov %eax, %esi
15025+#else
15026+ mov %cr0, %esi
15027+#endif
15028+ btr $16, %esi
15029+ ljmp $__KERNEL_CS, $1f
15030+1:
15031+#ifdef CONFIG_PARAVIRT
15032+ mov %esi, %eax
15033+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15034+#else
15035+ mov %esi, %cr0
15036+#endif
15037+2:
15038+#ifdef CONFIG_PARAVIRT
15039+ popl %ecx
15040+ popl %eax
15041+#endif
15042+ ret
15043+ENDPROC(pax_exit_kernel)
15044+#endif
15045+
15046+.macro pax_erase_kstack
15047+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15048+ call pax_erase_kstack
15049+#endif
15050+.endm
15051+
15052+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15053+/*
15054+ * ebp: thread_info
15055+ */
15056+ENTRY(pax_erase_kstack)
15057+ pushl %edi
15058+ pushl %ecx
15059+ pushl %eax
15060+
15061+ mov TI_lowest_stack(%ebp), %edi
15062+ mov $-0xBEEF, %eax
15063+ std
15064+
15065+1: mov %edi, %ecx
15066+ and $THREAD_SIZE_asm - 1, %ecx
15067+ shr $2, %ecx
15068+ repne scasl
15069+ jecxz 2f
15070+
15071+ cmp $2*16, %ecx
15072+ jc 2f
15073+
15074+ mov $2*16, %ecx
15075+ repe scasl
15076+ jecxz 2f
15077+ jne 1b
15078+
15079+2: cld
15080+ mov %esp, %ecx
15081+ sub %edi, %ecx
15082+
15083+ cmp $THREAD_SIZE_asm, %ecx
15084+ jb 3f
15085+ ud2
15086+3:
15087+
15088+ shr $2, %ecx
15089+ rep stosl
15090+
15091+ mov TI_task_thread_sp0(%ebp), %edi
15092+ sub $128, %edi
15093+ mov %edi, TI_lowest_stack(%ebp)
15094+
15095+ popl %eax
15096+ popl %ecx
15097+ popl %edi
15098+ ret
15099+ENDPROC(pax_erase_kstack)
15100+#endif
15101+
15102+.macro __SAVE_ALL _DS
15103 cld
15104 PUSH_GS
15105 pushl_cfi %fs
15106@@ -205,7 +345,7 @@
15107 CFI_REL_OFFSET ecx, 0
15108 pushl_cfi %ebx
15109 CFI_REL_OFFSET ebx, 0
15110- movl $(__USER_DS), %edx
15111+ movl $\_DS, %edx
15112 movl %edx, %ds
15113 movl %edx, %es
15114 movl $(__KERNEL_PERCPU), %edx
15115@@ -213,6 +353,15 @@
15116 SET_KERNEL_GS %edx
15117 .endm
15118
15119+.macro SAVE_ALL
15120+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15121+ __SAVE_ALL __KERNEL_DS
15122+ pax_enter_kernel
15123+#else
15124+ __SAVE_ALL __USER_DS
15125+#endif
15126+.endm
15127+
15128 .macro RESTORE_INT_REGS
15129 popl_cfi %ebx
15130 CFI_RESTORE ebx
15131@@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15132 popfl_cfi
15133 jmp syscall_exit
15134 CFI_ENDPROC
15135-END(ret_from_fork)
15136+ENDPROC(ret_from_fork)
15137
15138 /*
15139 * Interrupt exit functions should be protected against kprobes
15140@@ -329,7 +478,15 @@ ret_from_intr:
15141 andl $SEGMENT_RPL_MASK, %eax
15142 #endif
15143 cmpl $USER_RPL, %eax
15144+
15145+#ifdef CONFIG_PAX_KERNEXEC
15146+ jae resume_userspace
15147+
15148+ pax_exit_kernel
15149+ jmp resume_kernel
15150+#else
15151 jb resume_kernel # not returning to v8086 or userspace
15152+#endif
15153
15154 ENTRY(resume_userspace)
15155 LOCKDEP_SYS_EXIT
15156@@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15157 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15158 # int/exception return?
15159 jne work_pending
15160- jmp restore_all
15161-END(ret_from_exception)
15162+ jmp restore_all_pax
15163+ENDPROC(ret_from_exception)
15164
15165 #ifdef CONFIG_PREEMPT
15166 ENTRY(resume_kernel)
15167@@ -357,7 +514,7 @@ need_resched:
15168 jz restore_all
15169 call preempt_schedule_irq
15170 jmp need_resched
15171-END(resume_kernel)
15172+ENDPROC(resume_kernel)
15173 #endif
15174 CFI_ENDPROC
15175 /*
15176@@ -391,28 +548,43 @@ sysenter_past_esp:
15177 /*CFI_REL_OFFSET cs, 0*/
15178 /*
15179 * Push current_thread_info()->sysenter_return to the stack.
15180- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15181- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15182 */
15183- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15184+ pushl_cfi $0
15185 CFI_REL_OFFSET eip, 0
15186
15187 pushl_cfi %eax
15188 SAVE_ALL
15189+ GET_THREAD_INFO(%ebp)
15190+ movl TI_sysenter_return(%ebp),%ebp
15191+ movl %ebp,PT_EIP(%esp)
15192 ENABLE_INTERRUPTS(CLBR_NONE)
15193
15194 /*
15195 * Load the potential sixth argument from user stack.
15196 * Careful about security.
15197 */
15198+ movl PT_OLDESP(%esp),%ebp
15199+
15200+#ifdef CONFIG_PAX_MEMORY_UDEREF
15201+ mov PT_OLDSS(%esp),%ds
15202+1: movl %ds:(%ebp),%ebp
15203+ push %ss
15204+ pop %ds
15205+#else
15206 cmpl $__PAGE_OFFSET-3,%ebp
15207 jae syscall_fault
15208 1: movl (%ebp),%ebp
15209+#endif
15210+
15211 movl %ebp,PT_EBP(%esp)
15212 _ASM_EXTABLE(1b,syscall_fault)
15213
15214 GET_THREAD_INFO(%ebp)
15215
15216+#ifdef CONFIG_PAX_RANDKSTACK
15217+ pax_erase_kstack
15218+#endif
15219+
15220 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15221 jnz sysenter_audit
15222 sysenter_do_call:
15223@@ -427,12 +599,24 @@ sysenter_do_call:
15224 testl $_TIF_ALLWORK_MASK, %ecx
15225 jne sysexit_audit
15226 sysenter_exit:
15227+
15228+#ifdef CONFIG_PAX_RANDKSTACK
15229+ pushl_cfi %eax
15230+ movl %esp, %eax
15231+ call pax_randomize_kstack
15232+ popl_cfi %eax
15233+#endif
15234+
15235+ pax_erase_kstack
15236+
15237 /* if something modifies registers it must also disable sysexit */
15238 movl PT_EIP(%esp), %edx
15239 movl PT_OLDESP(%esp), %ecx
15240 xorl %ebp,%ebp
15241 TRACE_IRQS_ON
15242 1: mov PT_FS(%esp), %fs
15243+2: mov PT_DS(%esp), %ds
15244+3: mov PT_ES(%esp), %es
15245 PTGS_TO_GS
15246 ENABLE_INTERRUPTS_SYSEXIT
15247
15248@@ -449,6 +633,9 @@ sysenter_audit:
15249 movl %eax,%edx /* 2nd arg: syscall number */
15250 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15251 call __audit_syscall_entry
15252+
15253+ pax_erase_kstack
15254+
15255 pushl_cfi %ebx
15256 movl PT_EAX(%esp),%eax /* reload syscall number */
15257 jmp sysenter_do_call
15258@@ -474,10 +661,16 @@ sysexit_audit:
15259
15260 CFI_ENDPROC
15261 .pushsection .fixup,"ax"
15262-2: movl $0,PT_FS(%esp)
15263+4: movl $0,PT_FS(%esp)
15264+ jmp 1b
15265+5: movl $0,PT_DS(%esp)
15266+ jmp 1b
15267+6: movl $0,PT_ES(%esp)
15268 jmp 1b
15269 .popsection
15270- _ASM_EXTABLE(1b,2b)
15271+ _ASM_EXTABLE(1b,4b)
15272+ _ASM_EXTABLE(2b,5b)
15273+ _ASM_EXTABLE(3b,6b)
15274 PTGS_TO_GS_EX
15275 ENDPROC(ia32_sysenter_target)
15276
15277@@ -491,6 +684,11 @@ ENTRY(system_call)
15278 pushl_cfi %eax # save orig_eax
15279 SAVE_ALL
15280 GET_THREAD_INFO(%ebp)
15281+
15282+#ifdef CONFIG_PAX_RANDKSTACK
15283+ pax_erase_kstack
15284+#endif
15285+
15286 # system call tracing in operation / emulation
15287 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15288 jnz syscall_trace_entry
15289@@ -509,6 +707,15 @@ syscall_exit:
15290 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15291 jne syscall_exit_work
15292
15293+restore_all_pax:
15294+
15295+#ifdef CONFIG_PAX_RANDKSTACK
15296+ movl %esp, %eax
15297+ call pax_randomize_kstack
15298+#endif
15299+
15300+ pax_erase_kstack
15301+
15302 restore_all:
15303 TRACE_IRQS_IRET
15304 restore_all_notrace:
15305@@ -565,14 +772,34 @@ ldt_ss:
15306 * compensating for the offset by changing to the ESPFIX segment with
15307 * a base address that matches for the difference.
15308 */
15309-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15310+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15311 mov %esp, %edx /* load kernel esp */
15312 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15313 mov %dx, %ax /* eax: new kernel esp */
15314 sub %eax, %edx /* offset (low word is 0) */
15315+#ifdef CONFIG_SMP
15316+ movl PER_CPU_VAR(cpu_number), %ebx
15317+ shll $PAGE_SHIFT_asm, %ebx
15318+ addl $cpu_gdt_table, %ebx
15319+#else
15320+ movl $cpu_gdt_table, %ebx
15321+#endif
15322 shr $16, %edx
15323- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15324- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15325+
15326+#ifdef CONFIG_PAX_KERNEXEC
15327+ mov %cr0, %esi
15328+ btr $16, %esi
15329+ mov %esi, %cr0
15330+#endif
15331+
15332+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15333+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15334+
15335+#ifdef CONFIG_PAX_KERNEXEC
15336+ bts $16, %esi
15337+ mov %esi, %cr0
15338+#endif
15339+
15340 pushl_cfi $__ESPFIX_SS
15341 pushl_cfi %eax /* new kernel esp */
15342 /* Disable interrupts, but do not irqtrace this section: we
15343@@ -601,35 +828,23 @@ work_resched:
15344 movl TI_flags(%ebp), %ecx
15345 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15346 # than syscall tracing?
15347- jz restore_all
15348+ jz restore_all_pax
15349 testb $_TIF_NEED_RESCHED, %cl
15350 jnz work_resched
15351
15352 work_notifysig: # deal with pending signals and
15353 # notify-resume requests
15354+ movl %esp, %eax
15355 #ifdef CONFIG_VM86
15356 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15357- movl %esp, %eax
15358- jne work_notifysig_v86 # returning to kernel-space or
15359+ jz 1f # returning to kernel-space or
15360 # vm86-space
15361- TRACE_IRQS_ON
15362- ENABLE_INTERRUPTS(CLBR_NONE)
15363- movb PT_CS(%esp), %bl
15364- andb $SEGMENT_RPL_MASK, %bl
15365- cmpb $USER_RPL, %bl
15366- jb resume_kernel
15367- xorl %edx, %edx
15368- call do_notify_resume
15369- jmp resume_userspace
15370
15371- ALIGN
15372-work_notifysig_v86:
15373 pushl_cfi %ecx # save ti_flags for do_notify_resume
15374 call save_v86_state # %eax contains pt_regs pointer
15375 popl_cfi %ecx
15376 movl %eax, %esp
15377-#else
15378- movl %esp, %eax
15379+1:
15380 #endif
15381 TRACE_IRQS_ON
15382 ENABLE_INTERRUPTS(CLBR_NONE)
15383@@ -640,7 +855,7 @@ work_notifysig_v86:
15384 xorl %edx, %edx
15385 call do_notify_resume
15386 jmp resume_userspace
15387-END(work_pending)
15388+ENDPROC(work_pending)
15389
15390 # perform syscall exit tracing
15391 ALIGN
15392@@ -648,11 +863,14 @@ syscall_trace_entry:
15393 movl $-ENOSYS,PT_EAX(%esp)
15394 movl %esp, %eax
15395 call syscall_trace_enter
15396+
15397+ pax_erase_kstack
15398+
15399 /* What it returned is what we'll actually use. */
15400 cmpl $(NR_syscalls), %eax
15401 jnae syscall_call
15402 jmp syscall_exit
15403-END(syscall_trace_entry)
15404+ENDPROC(syscall_trace_entry)
15405
15406 # perform syscall exit tracing
15407 ALIGN
15408@@ -665,20 +883,24 @@ syscall_exit_work:
15409 movl %esp, %eax
15410 call syscall_trace_leave
15411 jmp resume_userspace
15412-END(syscall_exit_work)
15413+ENDPROC(syscall_exit_work)
15414 CFI_ENDPROC
15415
15416 RING0_INT_FRAME # can't unwind into user space anyway
15417 syscall_fault:
15418+#ifdef CONFIG_PAX_MEMORY_UDEREF
15419+ push %ss
15420+ pop %ds
15421+#endif
15422 GET_THREAD_INFO(%ebp)
15423 movl $-EFAULT,PT_EAX(%esp)
15424 jmp resume_userspace
15425-END(syscall_fault)
15426+ENDPROC(syscall_fault)
15427
15428 syscall_badsys:
15429 movl $-ENOSYS,PT_EAX(%esp)
15430 jmp resume_userspace
15431-END(syscall_badsys)
15432+ENDPROC(syscall_badsys)
15433 CFI_ENDPROC
15434 /*
15435 * End of kprobes section
15436@@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15437 CFI_ENDPROC
15438 ENDPROC(ptregs_clone)
15439
15440+ ALIGN;
15441+ENTRY(kernel_execve)
15442+ CFI_STARTPROC
15443+ pushl_cfi %ebp
15444+ sub $PT_OLDSS+4,%esp
15445+ pushl_cfi %edi
15446+ pushl_cfi %ecx
15447+ pushl_cfi %eax
15448+ lea 3*4(%esp),%edi
15449+ mov $PT_OLDSS/4+1,%ecx
15450+ xorl %eax,%eax
15451+ rep stosl
15452+ popl_cfi %eax
15453+ popl_cfi %ecx
15454+ popl_cfi %edi
15455+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15456+ pushl_cfi %esp
15457+ call sys_execve
15458+ add $4,%esp
15459+ CFI_ADJUST_CFA_OFFSET -4
15460+ GET_THREAD_INFO(%ebp)
15461+ test %eax,%eax
15462+ jz syscall_exit
15463+ add $PT_OLDSS+4,%esp
15464+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15465+ popl_cfi %ebp
15466+ ret
15467+ CFI_ENDPROC
15468+ENDPROC(kernel_execve)
15469+
15470 .macro FIXUP_ESPFIX_STACK
15471 /*
15472 * Switch back for ESPFIX stack to the normal zerobased stack
15473@@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15474 * normal stack and adjusts ESP with the matching offset.
15475 */
15476 /* fixup the stack */
15477- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15478- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15479+#ifdef CONFIG_SMP
15480+ movl PER_CPU_VAR(cpu_number), %ebx
15481+ shll $PAGE_SHIFT_asm, %ebx
15482+ addl $cpu_gdt_table, %ebx
15483+#else
15484+ movl $cpu_gdt_table, %ebx
15485+#endif
15486+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15487+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15488 shl $16, %eax
15489 addl %esp, %eax /* the adjusted stack pointer */
15490 pushl_cfi $__KERNEL_DS
15491@@ -813,7 +1072,7 @@ vector=vector+1
15492 .endr
15493 2: jmp common_interrupt
15494 .endr
15495-END(irq_entries_start)
15496+ENDPROC(irq_entries_start)
15497
15498 .previous
15499 END(interrupt)
15500@@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15501 pushl_cfi $do_coprocessor_error
15502 jmp error_code
15503 CFI_ENDPROC
15504-END(coprocessor_error)
15505+ENDPROC(coprocessor_error)
15506
15507 ENTRY(simd_coprocessor_error)
15508 RING0_INT_FRAME
15509@@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15510 #endif
15511 jmp error_code
15512 CFI_ENDPROC
15513-END(simd_coprocessor_error)
15514+ENDPROC(simd_coprocessor_error)
15515
15516 ENTRY(device_not_available)
15517 RING0_INT_FRAME
15518@@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15519 pushl_cfi $do_device_not_available
15520 jmp error_code
15521 CFI_ENDPROC
15522-END(device_not_available)
15523+ENDPROC(device_not_available)
15524
15525 #ifdef CONFIG_PARAVIRT
15526 ENTRY(native_iret)
15527 iret
15528 _ASM_EXTABLE(native_iret, iret_exc)
15529-END(native_iret)
15530+ENDPROC(native_iret)
15531
15532 ENTRY(native_irq_enable_sysexit)
15533 sti
15534 sysexit
15535-END(native_irq_enable_sysexit)
15536+ENDPROC(native_irq_enable_sysexit)
15537 #endif
15538
15539 ENTRY(overflow)
15540@@ -910,7 +1169,7 @@ ENTRY(overflow)
15541 pushl_cfi $do_overflow
15542 jmp error_code
15543 CFI_ENDPROC
15544-END(overflow)
15545+ENDPROC(overflow)
15546
15547 ENTRY(bounds)
15548 RING0_INT_FRAME
15549@@ -918,7 +1177,7 @@ ENTRY(bounds)
15550 pushl_cfi $do_bounds
15551 jmp error_code
15552 CFI_ENDPROC
15553-END(bounds)
15554+ENDPROC(bounds)
15555
15556 ENTRY(invalid_op)
15557 RING0_INT_FRAME
15558@@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15559 pushl_cfi $do_invalid_op
15560 jmp error_code
15561 CFI_ENDPROC
15562-END(invalid_op)
15563+ENDPROC(invalid_op)
15564
15565 ENTRY(coprocessor_segment_overrun)
15566 RING0_INT_FRAME
15567@@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15568 pushl_cfi $do_coprocessor_segment_overrun
15569 jmp error_code
15570 CFI_ENDPROC
15571-END(coprocessor_segment_overrun)
15572+ENDPROC(coprocessor_segment_overrun)
15573
15574 ENTRY(invalid_TSS)
15575 RING0_EC_FRAME
15576 pushl_cfi $do_invalid_TSS
15577 jmp error_code
15578 CFI_ENDPROC
15579-END(invalid_TSS)
15580+ENDPROC(invalid_TSS)
15581
15582 ENTRY(segment_not_present)
15583 RING0_EC_FRAME
15584 pushl_cfi $do_segment_not_present
15585 jmp error_code
15586 CFI_ENDPROC
15587-END(segment_not_present)
15588+ENDPROC(segment_not_present)
15589
15590 ENTRY(stack_segment)
15591 RING0_EC_FRAME
15592 pushl_cfi $do_stack_segment
15593 jmp error_code
15594 CFI_ENDPROC
15595-END(stack_segment)
15596+ENDPROC(stack_segment)
15597
15598 ENTRY(alignment_check)
15599 RING0_EC_FRAME
15600 pushl_cfi $do_alignment_check
15601 jmp error_code
15602 CFI_ENDPROC
15603-END(alignment_check)
15604+ENDPROC(alignment_check)
15605
15606 ENTRY(divide_error)
15607 RING0_INT_FRAME
15608@@ -970,7 +1229,7 @@ ENTRY(divide_error)
15609 pushl_cfi $do_divide_error
15610 jmp error_code
15611 CFI_ENDPROC
15612-END(divide_error)
15613+ENDPROC(divide_error)
15614
15615 #ifdef CONFIG_X86_MCE
15616 ENTRY(machine_check)
15617@@ -979,7 +1238,7 @@ ENTRY(machine_check)
15618 pushl_cfi machine_check_vector
15619 jmp error_code
15620 CFI_ENDPROC
15621-END(machine_check)
15622+ENDPROC(machine_check)
15623 #endif
15624
15625 ENTRY(spurious_interrupt_bug)
15626@@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15627 pushl_cfi $do_spurious_interrupt_bug
15628 jmp error_code
15629 CFI_ENDPROC
15630-END(spurious_interrupt_bug)
15631+ENDPROC(spurious_interrupt_bug)
15632 /*
15633 * End of kprobes section
15634 */
15635@@ -1100,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15636
15637 ENTRY(mcount)
15638 ret
15639-END(mcount)
15640+ENDPROC(mcount)
15641
15642 ENTRY(ftrace_caller)
15643 cmpl $0, function_trace_stop
15644@@ -1129,7 +1388,7 @@ ftrace_graph_call:
15645 .globl ftrace_stub
15646 ftrace_stub:
15647 ret
15648-END(ftrace_caller)
15649+ENDPROC(ftrace_caller)
15650
15651 #else /* ! CONFIG_DYNAMIC_FTRACE */
15652
15653@@ -1165,7 +1424,7 @@ trace:
15654 popl %ecx
15655 popl %eax
15656 jmp ftrace_stub
15657-END(mcount)
15658+ENDPROC(mcount)
15659 #endif /* CONFIG_DYNAMIC_FTRACE */
15660 #endif /* CONFIG_FUNCTION_TRACER */
15661
15662@@ -1186,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15663 popl %ecx
15664 popl %eax
15665 ret
15666-END(ftrace_graph_caller)
15667+ENDPROC(ftrace_graph_caller)
15668
15669 .globl return_to_handler
15670 return_to_handler:
15671@@ -1241,15 +1500,18 @@ error_code:
15672 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15673 REG_TO_PTGS %ecx
15674 SET_KERNEL_GS %ecx
15675- movl $(__USER_DS), %ecx
15676+ movl $(__KERNEL_DS), %ecx
15677 movl %ecx, %ds
15678 movl %ecx, %es
15679+
15680+ pax_enter_kernel
15681+
15682 TRACE_IRQS_OFF
15683 movl %esp,%eax # pt_regs pointer
15684 call *%edi
15685 jmp ret_from_exception
15686 CFI_ENDPROC
15687-END(page_fault)
15688+ENDPROC(page_fault)
15689
15690 /*
15691 * Debug traps and NMI can happen at the one SYSENTER instruction
15692@@ -1291,7 +1553,7 @@ debug_stack_correct:
15693 call do_debug
15694 jmp ret_from_exception
15695 CFI_ENDPROC
15696-END(debug)
15697+ENDPROC(debug)
15698
15699 /*
15700 * NMI is doubly nasty. It can happen _while_ we're handling
15701@@ -1328,6 +1590,9 @@ nmi_stack_correct:
15702 xorl %edx,%edx # zero error code
15703 movl %esp,%eax # pt_regs pointer
15704 call do_nmi
15705+
15706+ pax_exit_kernel
15707+
15708 jmp restore_all_notrace
15709 CFI_ENDPROC
15710
15711@@ -1364,12 +1629,15 @@ nmi_espfix_stack:
15712 FIXUP_ESPFIX_STACK # %eax == %esp
15713 xorl %edx,%edx # zero error code
15714 call do_nmi
15715+
15716+ pax_exit_kernel
15717+
15718 RESTORE_REGS
15719 lss 12+4(%esp), %esp # back to espfix stack
15720 CFI_ADJUST_CFA_OFFSET -24
15721 jmp irq_return
15722 CFI_ENDPROC
15723-END(nmi)
15724+ENDPROC(nmi)
15725
15726 ENTRY(int3)
15727 RING0_INT_FRAME
15728@@ -1381,14 +1649,14 @@ ENTRY(int3)
15729 call do_int3
15730 jmp ret_from_exception
15731 CFI_ENDPROC
15732-END(int3)
15733+ENDPROC(int3)
15734
15735 ENTRY(general_protection)
15736 RING0_EC_FRAME
15737 pushl_cfi $do_general_protection
15738 jmp error_code
15739 CFI_ENDPROC
15740-END(general_protection)
15741+ENDPROC(general_protection)
15742
15743 #ifdef CONFIG_KVM_GUEST
15744 ENTRY(async_page_fault)
15745@@ -1396,7 +1664,7 @@ ENTRY(async_page_fault)
15746 pushl_cfi $do_async_page_fault
15747 jmp error_code
15748 CFI_ENDPROC
15749-END(async_page_fault)
15750+ENDPROC(async_page_fault)
15751 #endif
15752
15753 /*
15754diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15755index 7d65133..c888d5f 100644
15756--- a/arch/x86/kernel/entry_64.S
15757+++ b/arch/x86/kernel/entry_64.S
15758@@ -57,6 +57,8 @@
15759 #include <asm/percpu.h>
15760 #include <asm/asm.h>
15761 #include <linux/err.h>
15762+#include <asm/pgtable.h>
15763+#include <asm/alternative-asm.h>
15764
15765 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15766 #include <linux/elf-em.h>
15767@@ -70,8 +72,9 @@
15768 #ifdef CONFIG_FUNCTION_TRACER
15769 #ifdef CONFIG_DYNAMIC_FTRACE
15770 ENTRY(mcount)
15771+ pax_force_retaddr
15772 retq
15773-END(mcount)
15774+ENDPROC(mcount)
15775
15776 ENTRY(ftrace_caller)
15777 cmpl $0, function_trace_stop
15778@@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15779 #endif
15780
15781 GLOBAL(ftrace_stub)
15782+ pax_force_retaddr
15783 retq
15784-END(ftrace_caller)
15785+ENDPROC(ftrace_caller)
15786
15787 #else /* ! CONFIG_DYNAMIC_FTRACE */
15788 ENTRY(mcount)
15789@@ -114,6 +118,7 @@ ENTRY(mcount)
15790 #endif
15791
15792 GLOBAL(ftrace_stub)
15793+ pax_force_retaddr
15794 retq
15795
15796 trace:
15797@@ -123,12 +128,13 @@ trace:
15798 movq 8(%rbp), %rsi
15799 subq $MCOUNT_INSN_SIZE, %rdi
15800
15801+ pax_force_fptr ftrace_trace_function
15802 call *ftrace_trace_function
15803
15804 MCOUNT_RESTORE_FRAME
15805
15806 jmp ftrace_stub
15807-END(mcount)
15808+ENDPROC(mcount)
15809 #endif /* CONFIG_DYNAMIC_FTRACE */
15810 #endif /* CONFIG_FUNCTION_TRACER */
15811
15812@@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15813
15814 MCOUNT_RESTORE_FRAME
15815
15816+ pax_force_retaddr
15817 retq
15818-END(ftrace_graph_caller)
15819+ENDPROC(ftrace_graph_caller)
15820
15821 GLOBAL(return_to_handler)
15822 subq $24, %rsp
15823@@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15824 movq 8(%rsp), %rdx
15825 movq (%rsp), %rax
15826 addq $24, %rsp
15827+ pax_force_fptr %rdi
15828 jmp *%rdi
15829 #endif
15830
15831@@ -180,6 +188,280 @@ ENTRY(native_usergs_sysret64)
15832 ENDPROC(native_usergs_sysret64)
15833 #endif /* CONFIG_PARAVIRT */
15834
15835+ .macro ljmpq sel, off
15836+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15837+ .byte 0x48; ljmp *1234f(%rip)
15838+ .pushsection .rodata
15839+ .align 16
15840+ 1234: .quad \off; .word \sel
15841+ .popsection
15842+#else
15843+ pushq $\sel
15844+ pushq $\off
15845+ lretq
15846+#endif
15847+ .endm
15848+
15849+ .macro pax_enter_kernel
15850+ pax_set_fptr_mask
15851+#ifdef CONFIG_PAX_KERNEXEC
15852+ call pax_enter_kernel
15853+#endif
15854+ .endm
15855+
15856+ .macro pax_exit_kernel
15857+#ifdef CONFIG_PAX_KERNEXEC
15858+ call pax_exit_kernel
15859+#endif
15860+ .endm
15861+
15862+#ifdef CONFIG_PAX_KERNEXEC
15863+ENTRY(pax_enter_kernel)
15864+ pushq %rdi
15865+
15866+#ifdef CONFIG_PARAVIRT
15867+ PV_SAVE_REGS(CLBR_RDI)
15868+#endif
15869+
15870+ GET_CR0_INTO_RDI
15871+ bts $16,%rdi
15872+ jnc 3f
15873+ mov %cs,%edi
15874+ cmp $__KERNEL_CS,%edi
15875+ jnz 2f
15876+1:
15877+
15878+#ifdef CONFIG_PARAVIRT
15879+ PV_RESTORE_REGS(CLBR_RDI)
15880+#endif
15881+
15882+ popq %rdi
15883+ pax_force_retaddr
15884+ retq
15885+
15886+2: ljmpq __KERNEL_CS,1f
15887+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15888+4: SET_RDI_INTO_CR0
15889+ jmp 1b
15890+ENDPROC(pax_enter_kernel)
15891+
15892+ENTRY(pax_exit_kernel)
15893+ pushq %rdi
15894+
15895+#ifdef CONFIG_PARAVIRT
15896+ PV_SAVE_REGS(CLBR_RDI)
15897+#endif
15898+
15899+ mov %cs,%rdi
15900+ cmp $__KERNEXEC_KERNEL_CS,%edi
15901+ jz 2f
15902+1:
15903+
15904+#ifdef CONFIG_PARAVIRT
15905+ PV_RESTORE_REGS(CLBR_RDI);
15906+#endif
15907+
15908+ popq %rdi
15909+ pax_force_retaddr
15910+ retq
15911+
15912+2: GET_CR0_INTO_RDI
15913+ btr $16,%rdi
15914+ ljmpq __KERNEL_CS,3f
15915+3: SET_RDI_INTO_CR0
15916+ jmp 1b
15917+#ifdef CONFIG_PARAVIRT
15918+ PV_RESTORE_REGS(CLBR_RDI);
15919+#endif
15920+
15921+ popq %rdi
15922+ pax_force_retaddr
15923+ retq
15924+ENDPROC(pax_exit_kernel)
15925+#endif
15926+
15927+ .macro pax_enter_kernel_user
15928+ pax_set_fptr_mask
15929+#ifdef CONFIG_PAX_MEMORY_UDEREF
15930+ call pax_enter_kernel_user
15931+#endif
15932+ .endm
15933+
15934+ .macro pax_exit_kernel_user
15935+#ifdef CONFIG_PAX_MEMORY_UDEREF
15936+ call pax_exit_kernel_user
15937+#endif
15938+#ifdef CONFIG_PAX_RANDKSTACK
15939+ pushq %rax
15940+ call pax_randomize_kstack
15941+ popq %rax
15942+#endif
15943+ .endm
15944+
15945+#ifdef CONFIG_PAX_MEMORY_UDEREF
15946+ENTRY(pax_enter_kernel_user)
15947+ pushq %rdi
15948+ pushq %rbx
15949+
15950+#ifdef CONFIG_PARAVIRT
15951+ PV_SAVE_REGS(CLBR_RDI)
15952+#endif
15953+
15954+ GET_CR3_INTO_RDI
15955+ mov %rdi,%rbx
15956+ add $__START_KERNEL_map,%rbx
15957+ sub phys_base(%rip),%rbx
15958+
15959+#ifdef CONFIG_PARAVIRT
15960+ pushq %rdi
15961+ cmpl $0, pv_info+PARAVIRT_enabled
15962+ jz 1f
15963+ i = 0
15964+ .rept USER_PGD_PTRS
15965+ mov i*8(%rbx),%rsi
15966+ mov $0,%sil
15967+ lea i*8(%rbx),%rdi
15968+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15969+ i = i + 1
15970+ .endr
15971+ jmp 2f
15972+1:
15973+#endif
15974+
15975+ i = 0
15976+ .rept USER_PGD_PTRS
15977+ movb $0,i*8(%rbx)
15978+ i = i + 1
15979+ .endr
15980+
15981+#ifdef CONFIG_PARAVIRT
15982+2: popq %rdi
15983+#endif
15984+ SET_RDI_INTO_CR3
15985+
15986+#ifdef CONFIG_PAX_KERNEXEC
15987+ GET_CR0_INTO_RDI
15988+ bts $16,%rdi
15989+ SET_RDI_INTO_CR0
15990+#endif
15991+
15992+#ifdef CONFIG_PARAVIRT
15993+ PV_RESTORE_REGS(CLBR_RDI)
15994+#endif
15995+
15996+ popq %rbx
15997+ popq %rdi
15998+ pax_force_retaddr
15999+ retq
16000+ENDPROC(pax_enter_kernel_user)
16001+
16002+ENTRY(pax_exit_kernel_user)
16003+ push %rdi
16004+
16005+#ifdef CONFIG_PARAVIRT
16006+ pushq %rbx
16007+ PV_SAVE_REGS(CLBR_RDI)
16008+#endif
16009+
16010+#ifdef CONFIG_PAX_KERNEXEC
16011+ GET_CR0_INTO_RDI
16012+ btr $16,%rdi
16013+ SET_RDI_INTO_CR0
16014+#endif
16015+
16016+ GET_CR3_INTO_RDI
16017+ add $__START_KERNEL_map,%rdi
16018+ sub phys_base(%rip),%rdi
16019+
16020+#ifdef CONFIG_PARAVIRT
16021+ cmpl $0, pv_info+PARAVIRT_enabled
16022+ jz 1f
16023+ mov %rdi,%rbx
16024+ i = 0
16025+ .rept USER_PGD_PTRS
16026+ mov i*8(%rbx),%rsi
16027+ mov $0x67,%sil
16028+ lea i*8(%rbx),%rdi
16029+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16030+ i = i + 1
16031+ .endr
16032+ jmp 2f
16033+1:
16034+#endif
16035+
16036+ i = 0
16037+ .rept USER_PGD_PTRS
16038+ movb $0x67,i*8(%rdi)
16039+ i = i + 1
16040+ .endr
16041+
16042+#ifdef CONFIG_PARAVIRT
16043+2: PV_RESTORE_REGS(CLBR_RDI)
16044+ popq %rbx
16045+#endif
16046+
16047+ popq %rdi
16048+ pax_force_retaddr
16049+ retq
16050+ENDPROC(pax_exit_kernel_user)
16051+#endif
16052+
16053+.macro pax_erase_kstack
16054+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16055+ call pax_erase_kstack
16056+#endif
16057+.endm
16058+
16059+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16060+ENTRY(pax_erase_kstack)
16061+ pushq %rdi
16062+ pushq %rcx
16063+ pushq %rax
16064+ pushq %r11
16065+
16066+ GET_THREAD_INFO(%r11)
16067+ mov TI_lowest_stack(%r11), %rdi
16068+ mov $-0xBEEF, %rax
16069+ std
16070+
16071+1: mov %edi, %ecx
16072+ and $THREAD_SIZE_asm - 1, %ecx
16073+ shr $3, %ecx
16074+ repne scasq
16075+ jecxz 2f
16076+
16077+ cmp $2*8, %ecx
16078+ jc 2f
16079+
16080+ mov $2*8, %ecx
16081+ repe scasq
16082+ jecxz 2f
16083+ jne 1b
16084+
16085+2: cld
16086+ mov %esp, %ecx
16087+ sub %edi, %ecx
16088+
16089+ cmp $THREAD_SIZE_asm, %rcx
16090+ jb 3f
16091+ ud2
16092+3:
16093+
16094+ shr $3, %ecx
16095+ rep stosq
16096+
16097+ mov TI_task_thread_sp0(%r11), %rdi
16098+ sub $256, %rdi
16099+ mov %rdi, TI_lowest_stack(%r11)
16100+
16101+ popq %r11
16102+ popq %rax
16103+ popq %rcx
16104+ popq %rdi
16105+ pax_force_retaddr
16106+ ret
16107+ENDPROC(pax_erase_kstack)
16108+#endif
16109
16110 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16111 #ifdef CONFIG_TRACE_IRQFLAGS
16112@@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16113 .endm
16114
16115 .macro UNFAKE_STACK_FRAME
16116- addq $8*6, %rsp
16117- CFI_ADJUST_CFA_OFFSET -(6*8)
16118+ addq $8*6 + ARG_SKIP, %rsp
16119+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16120 .endm
16121
16122 /*
16123@@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16124 movq %rsp, %rsi
16125
16126 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16127- testl $3, CS-RBP(%rsi)
16128+ testb $3, CS-RBP(%rsi)
16129 je 1f
16130 SWAPGS
16131 /*
16132@@ -394,9 +676,10 @@ ENTRY(save_rest)
16133 movq_cfi r15, R15+16
16134 movq %r11, 8(%rsp) /* return address */
16135 FIXUP_TOP_OF_STACK %r11, 16
16136+ pax_force_retaddr
16137 ret
16138 CFI_ENDPROC
16139-END(save_rest)
16140+ENDPROC(save_rest)
16141
16142 /* save complete stack frame */
16143 .pushsection .kprobes.text, "ax"
16144@@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16145 js 1f /* negative -> in kernel */
16146 SWAPGS
16147 xorl %ebx,%ebx
16148-1: ret
16149+1: pax_force_retaddr_bts
16150+ ret
16151 CFI_ENDPROC
16152-END(save_paranoid)
16153+ENDPROC(save_paranoid)
16154 .popsection
16155
16156 /*
16157@@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16158
16159 RESTORE_REST
16160
16161- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16162+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16163 jz retint_restore_args
16164
16165 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16166@@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16167 jmp ret_from_sys_call # go to the SYSRET fastpath
16168
16169 CFI_ENDPROC
16170-END(ret_from_fork)
16171+ENDPROC(ret_from_fork)
16172
16173 /*
16174 * System call entry. Up to 6 arguments in registers are supported.
16175@@ -495,7 +779,7 @@ END(ret_from_fork)
16176 ENTRY(system_call)
16177 CFI_STARTPROC simple
16178 CFI_SIGNAL_FRAME
16179- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16180+ CFI_DEF_CFA rsp,0
16181 CFI_REGISTER rip,rcx
16182 /*CFI_REGISTER rflags,r11*/
16183 SWAPGS_UNSAFE_STACK
16184@@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16185
16186 movq %rsp,PER_CPU_VAR(old_rsp)
16187 movq PER_CPU_VAR(kernel_stack),%rsp
16188+ SAVE_ARGS 8*6,0
16189+ pax_enter_kernel_user
16190+
16191+#ifdef CONFIG_PAX_RANDKSTACK
16192+ pax_erase_kstack
16193+#endif
16194+
16195 /*
16196 * No need to follow this irqs off/on section - it's straight
16197 * and short:
16198 */
16199 ENABLE_INTERRUPTS(CLBR_NONE)
16200- SAVE_ARGS 8,0
16201 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16202 movq %rcx,RIP-ARGOFFSET(%rsp)
16203 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16204- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16205+ GET_THREAD_INFO(%rcx)
16206+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16207 jnz tracesys
16208 system_call_fastpath:
16209 #if __SYSCALL_MASK == ~0
16210@@ -527,7 +818,7 @@ system_call_fastpath:
16211 cmpl $__NR_syscall_max,%eax
16212 #endif
16213 ja badsys
16214- movq %r10,%rcx
16215+ movq R10-ARGOFFSET(%rsp),%rcx
16216 call *sys_call_table(,%rax,8) # XXX: rip relative
16217 movq %rax,RAX-ARGOFFSET(%rsp)
16218 /*
16219@@ -541,10 +832,13 @@ sysret_check:
16220 LOCKDEP_SYS_EXIT
16221 DISABLE_INTERRUPTS(CLBR_NONE)
16222 TRACE_IRQS_OFF
16223- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16224+ GET_THREAD_INFO(%rcx)
16225+ movl TI_flags(%rcx),%edx
16226 andl %edi,%edx
16227 jnz sysret_careful
16228 CFI_REMEMBER_STATE
16229+ pax_exit_kernel_user
16230+ pax_erase_kstack
16231 /*
16232 * sysretq will re-enable interrupts:
16233 */
16234@@ -596,14 +890,18 @@ badsys:
16235 * jump back to the normal fast path.
16236 */
16237 auditsys:
16238- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16239+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16240 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16241 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16242 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16243 movq %rax,%rsi /* 2nd arg: syscall number */
16244 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16245 call __audit_syscall_entry
16246+
16247+ pax_erase_kstack
16248+
16249 LOAD_ARGS 0 /* reload call-clobbered registers */
16250+ pax_set_fptr_mask
16251 jmp system_call_fastpath
16252
16253 /*
16254@@ -624,7 +922,7 @@ sysret_audit:
16255 /* Do syscall tracing */
16256 tracesys:
16257 #ifdef CONFIG_AUDITSYSCALL
16258- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16259+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16260 jz auditsys
16261 #endif
16262 SAVE_REST
16263@@ -632,12 +930,16 @@ tracesys:
16264 FIXUP_TOP_OF_STACK %rdi
16265 movq %rsp,%rdi
16266 call syscall_trace_enter
16267+
16268+ pax_erase_kstack
16269+
16270 /*
16271 * Reload arg registers from stack in case ptrace changed them.
16272 * We don't reload %rax because syscall_trace_enter() returned
16273 * the value it wants us to use in the table lookup.
16274 */
16275 LOAD_ARGS ARGOFFSET, 1
16276+ pax_set_fptr_mask
16277 RESTORE_REST
16278 #if __SYSCALL_MASK == ~0
16279 cmpq $__NR_syscall_max,%rax
16280@@ -646,7 +948,7 @@ tracesys:
16281 cmpl $__NR_syscall_max,%eax
16282 #endif
16283 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16284- movq %r10,%rcx /* fixup for C */
16285+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16286 call *sys_call_table(,%rax,8)
16287 movq %rax,RAX-ARGOFFSET(%rsp)
16288 /* Use IRET because user could have changed frame */
16289@@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16290 andl %edi,%edx
16291 jnz int_careful
16292 andl $~TS_COMPAT,TI_status(%rcx)
16293- jmp retint_swapgs
16294+ pax_exit_kernel_user
16295+ pax_erase_kstack
16296+ jmp retint_swapgs_pax
16297
16298 /* Either reschedule or signal or syscall exit tracking needed. */
16299 /* First do a reschedule test. */
16300@@ -713,7 +1017,7 @@ int_restore_rest:
16301 TRACE_IRQS_OFF
16302 jmp int_with_check
16303 CFI_ENDPROC
16304-END(system_call)
16305+ENDPROC(system_call)
16306
16307 /*
16308 * Certain special system calls that need to save a complete full stack frame.
16309@@ -729,7 +1033,7 @@ ENTRY(\label)
16310 call \func
16311 jmp ptregscall_common
16312 CFI_ENDPROC
16313-END(\label)
16314+ENDPROC(\label)
16315 .endm
16316
16317 PTREGSCALL stub_clone, sys_clone, %r8
16318@@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16319 movq_cfi_restore R12+8, r12
16320 movq_cfi_restore RBP+8, rbp
16321 movq_cfi_restore RBX+8, rbx
16322+ pax_force_retaddr
16323 ret $REST_SKIP /* pop extended registers */
16324 CFI_ENDPROC
16325-END(ptregscall_common)
16326+ENDPROC(ptregscall_common)
16327
16328 ENTRY(stub_execve)
16329 CFI_STARTPROC
16330@@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16331 RESTORE_REST
16332 jmp int_ret_from_sys_call
16333 CFI_ENDPROC
16334-END(stub_execve)
16335+ENDPROC(stub_execve)
16336
16337 /*
16338 * sigreturn is special because it needs to restore all registers on return.
16339@@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16340 RESTORE_REST
16341 jmp int_ret_from_sys_call
16342 CFI_ENDPROC
16343-END(stub_rt_sigreturn)
16344+ENDPROC(stub_rt_sigreturn)
16345
16346 #ifdef CONFIG_X86_X32_ABI
16347 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16348@@ -851,7 +1156,7 @@ vector=vector+1
16349 2: jmp common_interrupt
16350 .endr
16351 CFI_ENDPROC
16352-END(irq_entries_start)
16353+ENDPROC(irq_entries_start)
16354
16355 .previous
16356 END(interrupt)
16357@@ -871,6 +1176,16 @@ END(interrupt)
16358 subq $ORIG_RAX-RBP, %rsp
16359 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16360 SAVE_ARGS_IRQ
16361+#ifdef CONFIG_PAX_MEMORY_UDEREF
16362+ testb $3, CS(%rdi)
16363+ jnz 1f
16364+ pax_enter_kernel
16365+ jmp 2f
16366+1: pax_enter_kernel_user
16367+2:
16368+#else
16369+ pax_enter_kernel
16370+#endif
16371 call \func
16372 .endm
16373
16374@@ -902,7 +1217,7 @@ ret_from_intr:
16375
16376 exit_intr:
16377 GET_THREAD_INFO(%rcx)
16378- testl $3,CS-ARGOFFSET(%rsp)
16379+ testb $3,CS-ARGOFFSET(%rsp)
16380 je retint_kernel
16381
16382 /* Interrupt came from user space */
16383@@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16384 * The iretq could re-enable interrupts:
16385 */
16386 DISABLE_INTERRUPTS(CLBR_ANY)
16387+ pax_exit_kernel_user
16388+retint_swapgs_pax:
16389 TRACE_IRQS_IRETQ
16390 SWAPGS
16391 jmp restore_args
16392
16393 retint_restore_args: /* return to kernel space */
16394 DISABLE_INTERRUPTS(CLBR_ANY)
16395+ pax_exit_kernel
16396+ pax_force_retaddr RIP-ARGOFFSET
16397 /*
16398 * The iretq could re-enable interrupts:
16399 */
16400@@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16401 #endif
16402
16403 CFI_ENDPROC
16404-END(common_interrupt)
16405+ENDPROC(common_interrupt)
16406 /*
16407 * End of kprobes section
16408 */
16409@@ -1029,7 +1348,7 @@ ENTRY(\sym)
16410 interrupt \do_sym
16411 jmp ret_from_intr
16412 CFI_ENDPROC
16413-END(\sym)
16414+ENDPROC(\sym)
16415 .endm
16416
16417 #ifdef CONFIG_SMP
16418@@ -1102,12 +1421,22 @@ ENTRY(\sym)
16419 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16420 call error_entry
16421 DEFAULT_FRAME 0
16422+#ifdef CONFIG_PAX_MEMORY_UDEREF
16423+ testb $3, CS(%rsp)
16424+ jnz 1f
16425+ pax_enter_kernel
16426+ jmp 2f
16427+1: pax_enter_kernel_user
16428+2:
16429+#else
16430+ pax_enter_kernel
16431+#endif
16432 movq %rsp,%rdi /* pt_regs pointer */
16433 xorl %esi,%esi /* no error code */
16434 call \do_sym
16435 jmp error_exit /* %ebx: no swapgs flag */
16436 CFI_ENDPROC
16437-END(\sym)
16438+ENDPROC(\sym)
16439 .endm
16440
16441 .macro paranoidzeroentry sym do_sym
16442@@ -1119,15 +1448,25 @@ ENTRY(\sym)
16443 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16444 call save_paranoid
16445 TRACE_IRQS_OFF
16446+#ifdef CONFIG_PAX_MEMORY_UDEREF
16447+ testb $3, CS(%rsp)
16448+ jnz 1f
16449+ pax_enter_kernel
16450+ jmp 2f
16451+1: pax_enter_kernel_user
16452+2:
16453+#else
16454+ pax_enter_kernel
16455+#endif
16456 movq %rsp,%rdi /* pt_regs pointer */
16457 xorl %esi,%esi /* no error code */
16458 call \do_sym
16459 jmp paranoid_exit /* %ebx: no swapgs flag */
16460 CFI_ENDPROC
16461-END(\sym)
16462+ENDPROC(\sym)
16463 .endm
16464
16465-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16466+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16467 .macro paranoidzeroentry_ist sym do_sym ist
16468 ENTRY(\sym)
16469 INTR_FRAME
16470@@ -1137,14 +1476,30 @@ ENTRY(\sym)
16471 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16472 call save_paranoid
16473 TRACE_IRQS_OFF_DEBUG
16474+#ifdef CONFIG_PAX_MEMORY_UDEREF
16475+ testb $3, CS(%rsp)
16476+ jnz 1f
16477+ pax_enter_kernel
16478+ jmp 2f
16479+1: pax_enter_kernel_user
16480+2:
16481+#else
16482+ pax_enter_kernel
16483+#endif
16484 movq %rsp,%rdi /* pt_regs pointer */
16485 xorl %esi,%esi /* no error code */
16486+#ifdef CONFIG_SMP
16487+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16488+ lea init_tss(%r12), %r12
16489+#else
16490+ lea init_tss(%rip), %r12
16491+#endif
16492 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16493 call \do_sym
16494 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16495 jmp paranoid_exit /* %ebx: no swapgs flag */
16496 CFI_ENDPROC
16497-END(\sym)
16498+ENDPROC(\sym)
16499 .endm
16500
16501 .macro errorentry sym do_sym
16502@@ -1155,13 +1510,23 @@ ENTRY(\sym)
16503 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16504 call error_entry
16505 DEFAULT_FRAME 0
16506+#ifdef CONFIG_PAX_MEMORY_UDEREF
16507+ testb $3, CS(%rsp)
16508+ jnz 1f
16509+ pax_enter_kernel
16510+ jmp 2f
16511+1: pax_enter_kernel_user
16512+2:
16513+#else
16514+ pax_enter_kernel
16515+#endif
16516 movq %rsp,%rdi /* pt_regs pointer */
16517 movq ORIG_RAX(%rsp),%rsi /* get error code */
16518 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16519 call \do_sym
16520 jmp error_exit /* %ebx: no swapgs flag */
16521 CFI_ENDPROC
16522-END(\sym)
16523+ENDPROC(\sym)
16524 .endm
16525
16526 /* error code is on the stack already */
16527@@ -1174,13 +1539,23 @@ ENTRY(\sym)
16528 call save_paranoid
16529 DEFAULT_FRAME 0
16530 TRACE_IRQS_OFF
16531+#ifdef CONFIG_PAX_MEMORY_UDEREF
16532+ testb $3, CS(%rsp)
16533+ jnz 1f
16534+ pax_enter_kernel
16535+ jmp 2f
16536+1: pax_enter_kernel_user
16537+2:
16538+#else
16539+ pax_enter_kernel
16540+#endif
16541 movq %rsp,%rdi /* pt_regs pointer */
16542 movq ORIG_RAX(%rsp),%rsi /* get error code */
16543 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16544 call \do_sym
16545 jmp paranoid_exit /* %ebx: no swapgs flag */
16546 CFI_ENDPROC
16547-END(\sym)
16548+ENDPROC(\sym)
16549 .endm
16550
16551 zeroentry divide_error do_divide_error
16552@@ -1210,9 +1585,10 @@ gs_change:
16553 2: mfence /* workaround */
16554 SWAPGS
16555 popfq_cfi
16556+ pax_force_retaddr
16557 ret
16558 CFI_ENDPROC
16559-END(native_load_gs_index)
16560+ENDPROC(native_load_gs_index)
16561
16562 _ASM_EXTABLE(gs_change,bad_gs)
16563 .section .fixup,"ax"
16564@@ -1231,13 +1607,14 @@ ENTRY(kernel_thread_helper)
16565 * Here we are in the child and the registers are set as they were
16566 * at kernel_thread() invocation in the parent.
16567 */
16568+ pax_force_fptr %rsi
16569 call *%rsi
16570 # exit
16571 mov %eax, %edi
16572 call do_exit
16573 ud2 # padding for call trace
16574 CFI_ENDPROC
16575-END(kernel_thread_helper)
16576+ENDPROC(kernel_thread_helper)
16577
16578 /*
16579 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16580@@ -1264,11 +1641,11 @@ ENTRY(kernel_execve)
16581 RESTORE_REST
16582 testq %rax,%rax
16583 je int_ret_from_sys_call
16584- RESTORE_ARGS
16585 UNFAKE_STACK_FRAME
16586+ pax_force_retaddr
16587 ret
16588 CFI_ENDPROC
16589-END(kernel_execve)
16590+ENDPROC(kernel_execve)
16591
16592 /* Call softirq on interrupt stack. Interrupts are off. */
16593 ENTRY(call_softirq)
16594@@ -1286,9 +1663,10 @@ ENTRY(call_softirq)
16595 CFI_DEF_CFA_REGISTER rsp
16596 CFI_ADJUST_CFA_OFFSET -8
16597 decl PER_CPU_VAR(irq_count)
16598+ pax_force_retaddr
16599 ret
16600 CFI_ENDPROC
16601-END(call_softirq)
16602+ENDPROC(call_softirq)
16603
16604 #ifdef CONFIG_XEN
16605 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16606@@ -1326,7 +1704,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16607 decl PER_CPU_VAR(irq_count)
16608 jmp error_exit
16609 CFI_ENDPROC
16610-END(xen_do_hypervisor_callback)
16611+ENDPROC(xen_do_hypervisor_callback)
16612
16613 /*
16614 * Hypervisor uses this for application faults while it executes.
16615@@ -1385,7 +1763,7 @@ ENTRY(xen_failsafe_callback)
16616 SAVE_ALL
16617 jmp error_exit
16618 CFI_ENDPROC
16619-END(xen_failsafe_callback)
16620+ENDPROC(xen_failsafe_callback)
16621
16622 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16623 xen_hvm_callback_vector xen_evtchn_do_upcall
16624@@ -1434,16 +1812,31 @@ ENTRY(paranoid_exit)
16625 TRACE_IRQS_OFF_DEBUG
16626 testl %ebx,%ebx /* swapgs needed? */
16627 jnz paranoid_restore
16628- testl $3,CS(%rsp)
16629+ testb $3,CS(%rsp)
16630 jnz paranoid_userspace
16631+#ifdef CONFIG_PAX_MEMORY_UDEREF
16632+ pax_exit_kernel
16633+ TRACE_IRQS_IRETQ 0
16634+ SWAPGS_UNSAFE_STACK
16635+ RESTORE_ALL 8
16636+ pax_force_retaddr_bts
16637+ jmp irq_return
16638+#endif
16639 paranoid_swapgs:
16640+#ifdef CONFIG_PAX_MEMORY_UDEREF
16641+ pax_exit_kernel_user
16642+#else
16643+ pax_exit_kernel
16644+#endif
16645 TRACE_IRQS_IRETQ 0
16646 SWAPGS_UNSAFE_STACK
16647 RESTORE_ALL 8
16648 jmp irq_return
16649 paranoid_restore:
16650+ pax_exit_kernel
16651 TRACE_IRQS_IRETQ_DEBUG 0
16652 RESTORE_ALL 8
16653+ pax_force_retaddr_bts
16654 jmp irq_return
16655 paranoid_userspace:
16656 GET_THREAD_INFO(%rcx)
16657@@ -1472,7 +1865,7 @@ paranoid_schedule:
16658 TRACE_IRQS_OFF
16659 jmp paranoid_userspace
16660 CFI_ENDPROC
16661-END(paranoid_exit)
16662+ENDPROC(paranoid_exit)
16663
16664 /*
16665 * Exception entry point. This expects an error code/orig_rax on the stack.
16666@@ -1499,12 +1892,13 @@ ENTRY(error_entry)
16667 movq_cfi r14, R14+8
16668 movq_cfi r15, R15+8
16669 xorl %ebx,%ebx
16670- testl $3,CS+8(%rsp)
16671+ testb $3,CS+8(%rsp)
16672 je error_kernelspace
16673 error_swapgs:
16674 SWAPGS
16675 error_sti:
16676 TRACE_IRQS_OFF
16677+ pax_force_retaddr_bts
16678 ret
16679
16680 /*
16681@@ -1531,7 +1925,7 @@ bstep_iret:
16682 movq %rcx,RIP+8(%rsp)
16683 jmp error_swapgs
16684 CFI_ENDPROC
16685-END(error_entry)
16686+ENDPROC(error_entry)
16687
16688
16689 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16690@@ -1551,7 +1945,7 @@ ENTRY(error_exit)
16691 jnz retint_careful
16692 jmp retint_swapgs
16693 CFI_ENDPROC
16694-END(error_exit)
16695+ENDPROC(error_exit)
16696
16697 /*
16698 * Test if a given stack is an NMI stack or not.
16699@@ -1609,9 +2003,11 @@ ENTRY(nmi)
16700 * If %cs was not the kernel segment, then the NMI triggered in user
16701 * space, which means it is definitely not nested.
16702 */
16703+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16704+ je 1f
16705 cmpl $__KERNEL_CS, 16(%rsp)
16706 jne first_nmi
16707-
16708+1:
16709 /*
16710 * Check the special variable on the stack to see if NMIs are
16711 * executing.
16712@@ -1758,6 +2154,16 @@ end_repeat_nmi:
16713 */
16714 call save_paranoid
16715 DEFAULT_FRAME 0
16716+#ifdef CONFIG_PAX_MEMORY_UDEREF
16717+ testb $3, CS(%rsp)
16718+ jnz 1f
16719+ pax_enter_kernel
16720+ jmp 2f
16721+1: pax_enter_kernel_user
16722+2:
16723+#else
16724+ pax_enter_kernel
16725+#endif
16726 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16727 movq %rsp,%rdi
16728 movq $-1,%rsi
16729@@ -1765,21 +2171,32 @@ end_repeat_nmi:
16730 testl %ebx,%ebx /* swapgs needed? */
16731 jnz nmi_restore
16732 nmi_swapgs:
16733+#ifdef CONFIG_PAX_MEMORY_UDEREF
16734+ pax_exit_kernel_user
16735+#else
16736+ pax_exit_kernel
16737+#endif
16738 SWAPGS_UNSAFE_STACK
16739+ RESTORE_ALL 8
16740+ /* Clear the NMI executing stack variable */
16741+ movq $0, 10*8(%rsp)
16742+ jmp irq_return
16743 nmi_restore:
16744+ pax_exit_kernel
16745 RESTORE_ALL 8
16746+ pax_force_retaddr_bts
16747 /* Clear the NMI executing stack variable */
16748 movq $0, 10*8(%rsp)
16749 jmp irq_return
16750 CFI_ENDPROC
16751-END(nmi)
16752+ENDPROC(nmi)
16753
16754 ENTRY(ignore_sysret)
16755 CFI_STARTPROC
16756 mov $-ENOSYS,%eax
16757 sysret
16758 CFI_ENDPROC
16759-END(ignore_sysret)
16760+ENDPROC(ignore_sysret)
16761
16762 /*
16763 * End of kprobes section
16764diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16765index c3a7cb4..3ad00dc 100644
16766--- a/arch/x86/kernel/ftrace.c
16767+++ b/arch/x86/kernel/ftrace.c
16768@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16769 {
16770 unsigned char replaced[MCOUNT_INSN_SIZE];
16771
16772+ ip = ktla_ktva(ip);
16773+
16774 /*
16775 * Note: Due to modules and __init, code can
16776 * disappear and change, we need to protect against faulting
16777@@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16778 unsigned char old[MCOUNT_INSN_SIZE], *new;
16779 int ret;
16780
16781- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16782+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16783 new = ftrace_call_replace(ip, (unsigned long)func);
16784
16785 /* See comment above by declaration of modifying_ftrace_code */
16786@@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16787 {
16788 unsigned char code[MCOUNT_INSN_SIZE];
16789
16790+ ip = ktla_ktva(ip);
16791+
16792 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16793 return -EFAULT;
16794
16795diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16796index c18f59d..9c0c9f6 100644
16797--- a/arch/x86/kernel/head32.c
16798+++ b/arch/x86/kernel/head32.c
16799@@ -18,6 +18,7 @@
16800 #include <asm/io_apic.h>
16801 #include <asm/bios_ebda.h>
16802 #include <asm/tlbflush.h>
16803+#include <asm/boot.h>
16804
16805 static void __init i386_default_early_setup(void)
16806 {
16807@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16808
16809 void __init i386_start_kernel(void)
16810 {
16811- memblock_reserve(__pa_symbol(&_text),
16812- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16813+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16814
16815 #ifdef CONFIG_BLK_DEV_INITRD
16816 /* Reserve INITRD */
16817diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16818index d42ab17..cb1b997 100644
16819--- a/arch/x86/kernel/head_32.S
16820+++ b/arch/x86/kernel/head_32.S
16821@@ -26,6 +26,12 @@
16822 /* Physical address */
16823 #define pa(X) ((X) - __PAGE_OFFSET)
16824
16825+#ifdef CONFIG_PAX_KERNEXEC
16826+#define ta(X) (X)
16827+#else
16828+#define ta(X) ((X) - __PAGE_OFFSET)
16829+#endif
16830+
16831 /*
16832 * References to members of the new_cpu_data structure.
16833 */
16834@@ -55,11 +61,7 @@
16835 * and small than max_low_pfn, otherwise will waste some page table entries
16836 */
16837
16838-#if PTRS_PER_PMD > 1
16839-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16840-#else
16841-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16842-#endif
16843+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16844
16845 /* Number of possible pages in the lowmem region */
16846 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16847@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16848 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16849
16850 /*
16851+ * Real beginning of normal "text" segment
16852+ */
16853+ENTRY(stext)
16854+ENTRY(_stext)
16855+
16856+/*
16857 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16858 * %esi points to the real-mode code as a 32-bit pointer.
16859 * CS and DS must be 4 GB flat segments, but we don't depend on
16860@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16861 * can.
16862 */
16863 __HEAD
16864+
16865+#ifdef CONFIG_PAX_KERNEXEC
16866+ jmp startup_32
16867+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16868+.fill PAGE_SIZE-5,1,0xcc
16869+#endif
16870+
16871 ENTRY(startup_32)
16872 movl pa(stack_start),%ecx
16873
16874@@ -106,6 +121,57 @@ ENTRY(startup_32)
16875 2:
16876 leal -__PAGE_OFFSET(%ecx),%esp
16877
16878+#ifdef CONFIG_SMP
16879+ movl $pa(cpu_gdt_table),%edi
16880+ movl $__per_cpu_load,%eax
16881+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16882+ rorl $16,%eax
16883+ movb %al,__KERNEL_PERCPU + 4(%edi)
16884+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16885+ movl $__per_cpu_end - 1,%eax
16886+ subl $__per_cpu_start,%eax
16887+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16888+#endif
16889+
16890+#ifdef CONFIG_PAX_MEMORY_UDEREF
16891+ movl $NR_CPUS,%ecx
16892+ movl $pa(cpu_gdt_table),%edi
16893+1:
16894+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16895+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16896+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16897+ addl $PAGE_SIZE_asm,%edi
16898+ loop 1b
16899+#endif
16900+
16901+#ifdef CONFIG_PAX_KERNEXEC
16902+ movl $pa(boot_gdt),%edi
16903+ movl $__LOAD_PHYSICAL_ADDR,%eax
16904+ movw %ax,__BOOT_CS + 2(%edi)
16905+ rorl $16,%eax
16906+ movb %al,__BOOT_CS + 4(%edi)
16907+ movb %ah,__BOOT_CS + 7(%edi)
16908+ rorl $16,%eax
16909+
16910+ ljmp $(__BOOT_CS),$1f
16911+1:
16912+
16913+ movl $NR_CPUS,%ecx
16914+ movl $pa(cpu_gdt_table),%edi
16915+ addl $__PAGE_OFFSET,%eax
16916+1:
16917+ movw %ax,__KERNEL_CS + 2(%edi)
16918+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16919+ rorl $16,%eax
16920+ movb %al,__KERNEL_CS + 4(%edi)
16921+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16922+ movb %ah,__KERNEL_CS + 7(%edi)
16923+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16924+ rorl $16,%eax
16925+ addl $PAGE_SIZE_asm,%edi
16926+ loop 1b
16927+#endif
16928+
16929 /*
16930 * Clear BSS first so that there are no surprises...
16931 */
16932@@ -196,8 +262,11 @@ ENTRY(startup_32)
16933 movl %eax, pa(max_pfn_mapped)
16934
16935 /* Do early initialization of the fixmap area */
16936- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16937- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16938+#ifdef CONFIG_COMPAT_VDSO
16939+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16940+#else
16941+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16942+#endif
16943 #else /* Not PAE */
16944
16945 page_pde_offset = (__PAGE_OFFSET >> 20);
16946@@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16947 movl %eax, pa(max_pfn_mapped)
16948
16949 /* Do early initialization of the fixmap area */
16950- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16951- movl %eax,pa(initial_page_table+0xffc)
16952+#ifdef CONFIG_COMPAT_VDSO
16953+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16954+#else
16955+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16956+#endif
16957 #endif
16958
16959 #ifdef CONFIG_PARAVIRT
16960@@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16961 cmpl $num_subarch_entries, %eax
16962 jae bad_subarch
16963
16964- movl pa(subarch_entries)(,%eax,4), %eax
16965- subl $__PAGE_OFFSET, %eax
16966- jmp *%eax
16967+ jmp *pa(subarch_entries)(,%eax,4)
16968
16969 bad_subarch:
16970 WEAK(lguest_entry)
16971@@ -256,10 +326,10 @@ WEAK(xen_entry)
16972 __INITDATA
16973
16974 subarch_entries:
16975- .long default_entry /* normal x86/PC */
16976- .long lguest_entry /* lguest hypervisor */
16977- .long xen_entry /* Xen hypervisor */
16978- .long default_entry /* Moorestown MID */
16979+ .long ta(default_entry) /* normal x86/PC */
16980+ .long ta(lguest_entry) /* lguest hypervisor */
16981+ .long ta(xen_entry) /* Xen hypervisor */
16982+ .long ta(default_entry) /* Moorestown MID */
16983 num_subarch_entries = (. - subarch_entries) / 4
16984 .previous
16985 #else
16986@@ -310,6 +380,7 @@ default_entry:
16987 orl %edx,%eax
16988 movl %eax,%cr4
16989
16990+#ifdef CONFIG_X86_PAE
16991 testb $X86_CR4_PAE, %al # check if PAE is enabled
16992 jz 6f
16993
16994@@ -338,6 +409,9 @@ default_entry:
16995 /* Make changes effective */
16996 wrmsr
16997
16998+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16999+#endif
17000+
17001 6:
17002
17003 /*
17004@@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
17005 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17006 movl %eax,%ss # after changing gdt.
17007
17008- movl $(__USER_DS),%eax # DS/ES contains default USER segment
17009+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17010 movl %eax,%ds
17011 movl %eax,%es
17012
17013 movl $(__KERNEL_PERCPU), %eax
17014 movl %eax,%fs # set this cpu's percpu
17015
17016+#ifdef CONFIG_CC_STACKPROTECTOR
17017 movl $(__KERNEL_STACK_CANARY),%eax
17018+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17019+ movl $(__USER_DS),%eax
17020+#else
17021+ xorl %eax,%eax
17022+#endif
17023 movl %eax,%gs
17024
17025 xorl %eax,%eax # Clear LDT
17026@@ -520,8 +600,11 @@ setup_once:
17027 * relocation. Manually set base address in stack canary
17028 * segment descriptor.
17029 */
17030- movl $gdt_page,%eax
17031+ movl $cpu_gdt_table,%eax
17032 movl $stack_canary,%ecx
17033+#ifdef CONFIG_SMP
17034+ addl $__per_cpu_load,%ecx
17035+#endif
17036 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17037 shrl $16, %ecx
17038 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17039@@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
17040 /* This is global to keep gas from relaxing the jumps */
17041 ENTRY(early_idt_handler)
17042 cld
17043- cmpl $2,%ss:early_recursion_flag
17044+ cmpl $1,%ss:early_recursion_flag
17045 je hlt_loop
17046 incl %ss:early_recursion_flag
17047
17048@@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
17049 pushl (20+6*4)(%esp) /* trapno */
17050 pushl $fault_msg
17051 call printk
17052-#endif
17053 call dump_stack
17054+#endif
17055 hlt_loop:
17056 hlt
17057 jmp hlt_loop
17058@@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
17059 /* This is the default interrupt "handler" :-) */
17060 ALIGN
17061 ignore_int:
17062- cld
17063 #ifdef CONFIG_PRINTK
17064+ cmpl $2,%ss:early_recursion_flag
17065+ je hlt_loop
17066+ incl %ss:early_recursion_flag
17067+ cld
17068 pushl %eax
17069 pushl %ecx
17070 pushl %edx
17071@@ -620,9 +706,6 @@ ignore_int:
17072 movl $(__KERNEL_DS),%eax
17073 movl %eax,%ds
17074 movl %eax,%es
17075- cmpl $2,early_recursion_flag
17076- je hlt_loop
17077- incl early_recursion_flag
17078 pushl 16(%esp)
17079 pushl 24(%esp)
17080 pushl 32(%esp)
17081@@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
17082 /*
17083 * BSS section
17084 */
17085-__PAGE_ALIGNED_BSS
17086- .align PAGE_SIZE
17087 #ifdef CONFIG_X86_PAE
17088+.section .initial_pg_pmd,"a",@progbits
17089 initial_pg_pmd:
17090 .fill 1024*KPMDS,4,0
17091 #else
17092+.section .initial_page_table,"a",@progbits
17093 ENTRY(initial_page_table)
17094 .fill 1024,4,0
17095 #endif
17096+.section .initial_pg_fixmap,"a",@progbits
17097 initial_pg_fixmap:
17098 .fill 1024,4,0
17099+.section .empty_zero_page,"a",@progbits
17100 ENTRY(empty_zero_page)
17101 .fill 4096,1,0
17102+.section .swapper_pg_dir,"a",@progbits
17103 ENTRY(swapper_pg_dir)
17104+#ifdef CONFIG_X86_PAE
17105+ .fill 4,8,0
17106+#else
17107 .fill 1024,4,0
17108+#endif
17109+
17110+/*
17111+ * The IDT has to be page-aligned to simplify the Pentium
17112+ * F0 0F bug workaround.. We have a special link segment
17113+ * for this.
17114+ */
17115+.section .idt,"a",@progbits
17116+ENTRY(idt_table)
17117+ .fill 256,8,0
17118
17119 /*
17120 * This starts the data section.
17121 */
17122 #ifdef CONFIG_X86_PAE
17123-__PAGE_ALIGNED_DATA
17124- /* Page-aligned for the benefit of paravirt? */
17125- .align PAGE_SIZE
17126+.section .initial_page_table,"a",@progbits
17127 ENTRY(initial_page_table)
17128 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17129 # if KPMDS == 3
17130@@ -697,12 +794,20 @@ ENTRY(initial_page_table)
17131 # error "Kernel PMDs should be 1, 2 or 3"
17132 # endif
17133 .align PAGE_SIZE /* needs to be page-sized too */
17134+
17135+#ifdef CONFIG_PAX_PER_CPU_PGD
17136+ENTRY(cpu_pgd)
17137+ .rept NR_CPUS
17138+ .fill 4,8,0
17139+ .endr
17140+#endif
17141+
17142 #endif
17143
17144 .data
17145 .balign 4
17146 ENTRY(stack_start)
17147- .long init_thread_union+THREAD_SIZE
17148+ .long init_thread_union+THREAD_SIZE-8
17149
17150 __INITRODATA
17151 int_msg:
17152@@ -730,7 +835,7 @@ fault_msg:
17153 * segment size, and 32-bit linear address value:
17154 */
17155
17156- .data
17157+.section .rodata,"a",@progbits
17158 .globl boot_gdt_descr
17159 .globl idt_descr
17160
17161@@ -739,7 +844,7 @@ fault_msg:
17162 .word 0 # 32 bit align gdt_desc.address
17163 boot_gdt_descr:
17164 .word __BOOT_DS+7
17165- .long boot_gdt - __PAGE_OFFSET
17166+ .long pa(boot_gdt)
17167
17168 .word 0 # 32-bit align idt_desc.address
17169 idt_descr:
17170@@ -750,7 +855,7 @@ idt_descr:
17171 .word 0 # 32 bit align gdt_desc.address
17172 ENTRY(early_gdt_descr)
17173 .word GDT_ENTRIES*8-1
17174- .long gdt_page /* Overwritten for secondary CPUs */
17175+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17176
17177 /*
17178 * The boot_gdt must mirror the equivalent in setup.S and is
17179@@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17180 .align L1_CACHE_BYTES
17181 ENTRY(boot_gdt)
17182 .fill GDT_ENTRY_BOOT_CS,8,0
17183- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17184- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17185+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17186+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17187+
17188+ .align PAGE_SIZE_asm
17189+ENTRY(cpu_gdt_table)
17190+ .rept NR_CPUS
17191+ .quad 0x0000000000000000 /* NULL descriptor */
17192+ .quad 0x0000000000000000 /* 0x0b reserved */
17193+ .quad 0x0000000000000000 /* 0x13 reserved */
17194+ .quad 0x0000000000000000 /* 0x1b reserved */
17195+
17196+#ifdef CONFIG_PAX_KERNEXEC
17197+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17198+#else
17199+ .quad 0x0000000000000000 /* 0x20 unused */
17200+#endif
17201+
17202+ .quad 0x0000000000000000 /* 0x28 unused */
17203+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17204+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17205+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17206+ .quad 0x0000000000000000 /* 0x4b reserved */
17207+ .quad 0x0000000000000000 /* 0x53 reserved */
17208+ .quad 0x0000000000000000 /* 0x5b reserved */
17209+
17210+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17211+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17212+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17213+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17214+
17215+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17216+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17217+
17218+ /*
17219+ * Segments used for calling PnP BIOS have byte granularity.
17220+ * The code segments and data segments have fixed 64k limits,
17221+ * the transfer segment sizes are set at run time.
17222+ */
17223+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17224+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17225+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17226+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17227+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17228+
17229+ /*
17230+ * The APM segments have byte granularity and their bases
17231+ * are set at run time. All have 64k limits.
17232+ */
17233+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17234+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17235+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17236+
17237+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17238+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17239+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17240+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17241+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17242+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17243+
17244+ /* Be sure this is zeroed to avoid false validations in Xen */
17245+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17246+ .endr
17247diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17248index 94bf9cc..400455a 100644
17249--- a/arch/x86/kernel/head_64.S
17250+++ b/arch/x86/kernel/head_64.S
17251@@ -20,6 +20,8 @@
17252 #include <asm/processor-flags.h>
17253 #include <asm/percpu.h>
17254 #include <asm/nops.h>
17255+#include <asm/cpufeature.h>
17256+#include <asm/alternative-asm.h>
17257
17258 #ifdef CONFIG_PARAVIRT
17259 #include <asm/asm-offsets.h>
17260@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17261 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17262 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17263 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17264+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17265+L3_VMALLOC_START = pud_index(VMALLOC_START)
17266+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17267+L3_VMALLOC_END = pud_index(VMALLOC_END)
17268+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17269+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17270
17271 .text
17272 __HEAD
17273@@ -88,35 +96,23 @@ startup_64:
17274 */
17275 addq %rbp, init_level4_pgt + 0(%rip)
17276 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17277+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17278+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17279+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17280 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17281
17282 addq %rbp, level3_ident_pgt + 0(%rip)
17283+#ifndef CONFIG_XEN
17284+ addq %rbp, level3_ident_pgt + 8(%rip)
17285+#endif
17286
17287- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17288- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17289+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17290+
17291+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17292+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17293
17294 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17295-
17296- /* Add an Identity mapping if I am above 1G */
17297- leaq _text(%rip), %rdi
17298- andq $PMD_PAGE_MASK, %rdi
17299-
17300- movq %rdi, %rax
17301- shrq $PUD_SHIFT, %rax
17302- andq $(PTRS_PER_PUD - 1), %rax
17303- jz ident_complete
17304-
17305- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17306- leaq level3_ident_pgt(%rip), %rbx
17307- movq %rdx, 0(%rbx, %rax, 8)
17308-
17309- movq %rdi, %rax
17310- shrq $PMD_SHIFT, %rax
17311- andq $(PTRS_PER_PMD - 1), %rax
17312- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17313- leaq level2_spare_pgt(%rip), %rbx
17314- movq %rdx, 0(%rbx, %rax, 8)
17315-ident_complete:
17316+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17317
17318 /*
17319 * Fixup the kernel text+data virtual addresses. Note that
17320@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17321 * after the boot processor executes this code.
17322 */
17323
17324- /* Enable PAE mode and PGE */
17325- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17326+ /* Enable PAE mode and PSE/PGE */
17327+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17328 movq %rax, %cr4
17329
17330 /* Setup early boot stage 4 level pagetables. */
17331@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17332 movl $MSR_EFER, %ecx
17333 rdmsr
17334 btsl $_EFER_SCE, %eax /* Enable System Call */
17335- btl $20,%edi /* No Execute supported? */
17336+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17337 jnc 1f
17338 btsl $_EFER_NX, %eax
17339+ leaq init_level4_pgt(%rip), %rdi
17340+#ifndef CONFIG_EFI
17341+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17342+#endif
17343+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17344+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17345+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17346+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17347 1: wrmsr /* Make changes effective */
17348
17349 /* Setup cr0 */
17350@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17351 * jump. In addition we need to ensure %cs is set so we make this
17352 * a far return.
17353 */
17354+ pax_set_fptr_mask
17355 movq initial_code(%rip),%rax
17356 pushq $0 # fake return address to stop unwinder
17357 pushq $__KERNEL_CS # set correct cs
17358@@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17359 bad_address:
17360 jmp bad_address
17361
17362- .section ".init.text","ax"
17363+ __INIT
17364 .globl early_idt_handlers
17365 early_idt_handlers:
17366 # 104(%rsp) %rflags
17367@@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17368 addq $16,%rsp # drop vector number and error code
17369 decl early_recursion_flag(%rip)
17370 INTERRUPT_RETURN
17371+ .previous
17372
17373+ __INITDATA
17374 .balign 4
17375 early_recursion_flag:
17376 .long 0
17377+ .previous
17378
17379+ .section .rodata,"a",@progbits
17380 #ifdef CONFIG_EARLY_PRINTK
17381 early_idt_msg:
17382 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17383@@ -360,6 +369,7 @@ early_idt_ripmsg:
17384 #endif /* CONFIG_EARLY_PRINTK */
17385 .previous
17386
17387+ .section .rodata,"a",@progbits
17388 #define NEXT_PAGE(name) \
17389 .balign PAGE_SIZE; \
17390 ENTRY(name)
17391@@ -372,7 +382,6 @@ ENTRY(name)
17392 i = i + 1 ; \
17393 .endr
17394
17395- .data
17396 /*
17397 * This default setting generates an ident mapping at address 0x100000
17398 * and a mapping for the kernel that precisely maps virtual address
17399@@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17400 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17401 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17402 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17403+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17404+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17405+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17406+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17407+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17408+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17409 .org init_level4_pgt + L4_START_KERNEL*8, 0
17410 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17411 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17412
17413+#ifdef CONFIG_PAX_PER_CPU_PGD
17414+NEXT_PAGE(cpu_pgd)
17415+ .rept NR_CPUS
17416+ .fill 512,8,0
17417+ .endr
17418+#endif
17419+
17420 NEXT_PAGE(level3_ident_pgt)
17421 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17422+#ifdef CONFIG_XEN
17423 .fill 511,8,0
17424+#else
17425+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17426+ .fill 510,8,0
17427+#endif
17428+
17429+NEXT_PAGE(level3_vmalloc_start_pgt)
17430+ .fill 512,8,0
17431+
17432+NEXT_PAGE(level3_vmalloc_end_pgt)
17433+ .fill 512,8,0
17434+
17435+NEXT_PAGE(level3_vmemmap_pgt)
17436+ .fill L3_VMEMMAP_START,8,0
17437+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17438
17439 NEXT_PAGE(level3_kernel_pgt)
17440 .fill L3_START_KERNEL,8,0
17441@@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17442 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17443 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17444
17445+NEXT_PAGE(level2_vmemmap_pgt)
17446+ .fill 512,8,0
17447+
17448 NEXT_PAGE(level2_fixmap_pgt)
17449- .fill 506,8,0
17450- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17451- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17452- .fill 5,8,0
17453+ .fill 507,8,0
17454+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17455+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17456+ .fill 4,8,0
17457
17458-NEXT_PAGE(level1_fixmap_pgt)
17459+NEXT_PAGE(level1_vsyscall_pgt)
17460 .fill 512,8,0
17461
17462-NEXT_PAGE(level2_ident_pgt)
17463- /* Since I easily can, map the first 1G.
17464+ /* Since I easily can, map the first 2G.
17465 * Don't set NX because code runs from these pages.
17466 */
17467- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17468+NEXT_PAGE(level2_ident_pgt)
17469+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17470
17471 NEXT_PAGE(level2_kernel_pgt)
17472 /*
17473@@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17474 * If you want to increase this then increase MODULES_VADDR
17475 * too.)
17476 */
17477- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17478- KERNEL_IMAGE_SIZE/PMD_SIZE)
17479-
17480-NEXT_PAGE(level2_spare_pgt)
17481- .fill 512, 8, 0
17482+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17483
17484 #undef PMDS
17485 #undef NEXT_PAGE
17486
17487- .data
17488+ .align PAGE_SIZE
17489+ENTRY(cpu_gdt_table)
17490+ .rept NR_CPUS
17491+ .quad 0x0000000000000000 /* NULL descriptor */
17492+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17493+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17494+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17495+ .quad 0x00cffb000000ffff /* __USER32_CS */
17496+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17497+ .quad 0x00affb000000ffff /* __USER_CS */
17498+
17499+#ifdef CONFIG_PAX_KERNEXEC
17500+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17501+#else
17502+ .quad 0x0 /* unused */
17503+#endif
17504+
17505+ .quad 0,0 /* TSS */
17506+ .quad 0,0 /* LDT */
17507+ .quad 0,0,0 /* three TLS descriptors */
17508+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17509+ /* asm/segment.h:GDT_ENTRIES must match this */
17510+
17511+ /* zero the remaining page */
17512+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17513+ .endr
17514+
17515 .align 16
17516 .globl early_gdt_descr
17517 early_gdt_descr:
17518 .word GDT_ENTRIES*8-1
17519 early_gdt_descr_base:
17520- .quad INIT_PER_CPU_VAR(gdt_page)
17521+ .quad cpu_gdt_table
17522
17523 ENTRY(phys_base)
17524 /* This must match the first entry in level2_kernel_pgt */
17525 .quad 0x0000000000000000
17526
17527 #include "../../x86/xen/xen-head.S"
17528-
17529- .section .bss, "aw", @nobits
17530+
17531+ .section .rodata,"a",@progbits
17532 .align L1_CACHE_BYTES
17533 ENTRY(idt_table)
17534- .skip IDT_ENTRIES * 16
17535+ .fill 512,8,0
17536
17537 .align L1_CACHE_BYTES
17538 ENTRY(nmi_idt_table)
17539- .skip IDT_ENTRIES * 16
17540+ .fill 512,8,0
17541
17542 __PAGE_ALIGNED_BSS
17543 .align PAGE_SIZE
17544diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17545index 9c3bd4a..e1d9b35 100644
17546--- a/arch/x86/kernel/i386_ksyms_32.c
17547+++ b/arch/x86/kernel/i386_ksyms_32.c
17548@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17549 EXPORT_SYMBOL(cmpxchg8b_emu);
17550 #endif
17551
17552+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17553+
17554 /* Networking helper routines. */
17555 EXPORT_SYMBOL(csum_partial_copy_generic);
17556+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17557+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17558
17559 EXPORT_SYMBOL(__get_user_1);
17560 EXPORT_SYMBOL(__get_user_2);
17561@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17562
17563 EXPORT_SYMBOL(csum_partial);
17564 EXPORT_SYMBOL(empty_zero_page);
17565+
17566+#ifdef CONFIG_PAX_KERNEXEC
17567+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17568+#endif
17569diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17570index f250431..54097e7 100644
17571--- a/arch/x86/kernel/i387.c
17572+++ b/arch/x86/kernel/i387.c
17573@@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17574 static inline bool interrupted_user_mode(void)
17575 {
17576 struct pt_regs *regs = get_irq_regs();
17577- return regs && user_mode_vm(regs);
17578+ return regs && user_mode(regs);
17579 }
17580
17581 /*
17582diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17583index 36d1853..bf25736 100644
17584--- a/arch/x86/kernel/i8259.c
17585+++ b/arch/x86/kernel/i8259.c
17586@@ -209,7 +209,7 @@ spurious_8259A_irq:
17587 "spurious 8259A interrupt: IRQ%d.\n", irq);
17588 spurious_irq_mask |= irqmask;
17589 }
17590- atomic_inc(&irq_err_count);
17591+ atomic_inc_unchecked(&irq_err_count);
17592 /*
17593 * Theoretically we do not have to handle this IRQ,
17594 * but in Linux this does not cause problems and is
17595diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17596index 8c96897..be66bfa 100644
17597--- a/arch/x86/kernel/ioport.c
17598+++ b/arch/x86/kernel/ioport.c
17599@@ -6,6 +6,7 @@
17600 #include <linux/sched.h>
17601 #include <linux/kernel.h>
17602 #include <linux/capability.h>
17603+#include <linux/security.h>
17604 #include <linux/errno.h>
17605 #include <linux/types.h>
17606 #include <linux/ioport.h>
17607@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17608
17609 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17610 return -EINVAL;
17611+#ifdef CONFIG_GRKERNSEC_IO
17612+ if (turn_on && grsec_disable_privio) {
17613+ gr_handle_ioperm();
17614+ return -EPERM;
17615+ }
17616+#endif
17617 if (turn_on && !capable(CAP_SYS_RAWIO))
17618 return -EPERM;
17619
17620@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17621 * because the ->io_bitmap_max value must match the bitmap
17622 * contents:
17623 */
17624- tss = &per_cpu(init_tss, get_cpu());
17625+ tss = init_tss + get_cpu();
17626
17627 if (turn_on)
17628 bitmap_clear(t->io_bitmap_ptr, from, num);
17629@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17630 return -EINVAL;
17631 /* Trying to gain more privileges? */
17632 if (level > old) {
17633+#ifdef CONFIG_GRKERNSEC_IO
17634+ if (grsec_disable_privio) {
17635+ gr_handle_iopl();
17636+ return -EPERM;
17637+ }
17638+#endif
17639 if (!capable(CAP_SYS_RAWIO))
17640 return -EPERM;
17641 }
17642diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17643index 3dafc60..aa8e9c4 100644
17644--- a/arch/x86/kernel/irq.c
17645+++ b/arch/x86/kernel/irq.c
17646@@ -18,7 +18,7 @@
17647 #include <asm/mce.h>
17648 #include <asm/hw_irq.h>
17649
17650-atomic_t irq_err_count;
17651+atomic_unchecked_t irq_err_count;
17652
17653 /* Function pointer for generic interrupt vector handling */
17654 void (*x86_platform_ipi_callback)(void) = NULL;
17655@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17656 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17657 seq_printf(p, " Machine check polls\n");
17658 #endif
17659- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17660+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17661 #if defined(CONFIG_X86_IO_APIC)
17662- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17663+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17664 #endif
17665 return 0;
17666 }
17667@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17668
17669 u64 arch_irq_stat(void)
17670 {
17671- u64 sum = atomic_read(&irq_err_count);
17672+ u64 sum = atomic_read_unchecked(&irq_err_count);
17673
17674 #ifdef CONFIG_X86_IO_APIC
17675- sum += atomic_read(&irq_mis_count);
17676+ sum += atomic_read_unchecked(&irq_mis_count);
17677 #endif
17678 return sum;
17679 }
17680diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17681index 344faf8..355f60d 100644
17682--- a/arch/x86/kernel/irq_32.c
17683+++ b/arch/x86/kernel/irq_32.c
17684@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17685 __asm__ __volatile__("andl %%esp,%0" :
17686 "=r" (sp) : "0" (THREAD_SIZE - 1));
17687
17688- return sp < (sizeof(struct thread_info) + STACK_WARN);
17689+ return sp < STACK_WARN;
17690 }
17691
17692 static void print_stack_overflow(void)
17693@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17694 * per-CPU IRQ handling contexts (thread information and stack)
17695 */
17696 union irq_ctx {
17697- struct thread_info tinfo;
17698- u32 stack[THREAD_SIZE/sizeof(u32)];
17699+ unsigned long previous_esp;
17700+ u32 stack[THREAD_SIZE/sizeof(u32)];
17701 } __attribute__((aligned(THREAD_SIZE)));
17702
17703 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17704@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17705 static inline int
17706 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17707 {
17708- union irq_ctx *curctx, *irqctx;
17709+ union irq_ctx *irqctx;
17710 u32 *isp, arg1, arg2;
17711
17712- curctx = (union irq_ctx *) current_thread_info();
17713 irqctx = __this_cpu_read(hardirq_ctx);
17714
17715 /*
17716@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17717 * handler) we can't do that and just have to keep using the
17718 * current stack (which is the irq stack already after all)
17719 */
17720- if (unlikely(curctx == irqctx))
17721+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17722 return 0;
17723
17724 /* build the stack frame on the IRQ stack */
17725- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17726- irqctx->tinfo.task = curctx->tinfo.task;
17727- irqctx->tinfo.previous_esp = current_stack_pointer;
17728+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17729+ irqctx->previous_esp = current_stack_pointer;
17730
17731- /* Copy the preempt_count so that the [soft]irq checks work. */
17732- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17733+#ifdef CONFIG_PAX_MEMORY_UDEREF
17734+ __set_fs(MAKE_MM_SEG(0));
17735+#endif
17736
17737 if (unlikely(overflow))
17738 call_on_stack(print_stack_overflow, isp);
17739@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17740 : "0" (irq), "1" (desc), "2" (isp),
17741 "D" (desc->handle_irq)
17742 : "memory", "cc", "ecx");
17743+
17744+#ifdef CONFIG_PAX_MEMORY_UDEREF
17745+ __set_fs(current_thread_info()->addr_limit);
17746+#endif
17747+
17748 return 1;
17749 }
17750
17751@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17752 */
17753 void __cpuinit irq_ctx_init(int cpu)
17754 {
17755- union irq_ctx *irqctx;
17756-
17757 if (per_cpu(hardirq_ctx, cpu))
17758 return;
17759
17760- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17761- THREADINFO_GFP,
17762- THREAD_SIZE_ORDER));
17763- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17764- irqctx->tinfo.cpu = cpu;
17765- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17766- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17767-
17768- per_cpu(hardirq_ctx, cpu) = irqctx;
17769-
17770- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17771- THREADINFO_GFP,
17772- THREAD_SIZE_ORDER));
17773- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17774- irqctx->tinfo.cpu = cpu;
17775- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17776-
17777- per_cpu(softirq_ctx, cpu) = irqctx;
17778+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17779+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17780+
17781+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17782+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17783
17784 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17785 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17786@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17787 asmlinkage void do_softirq(void)
17788 {
17789 unsigned long flags;
17790- struct thread_info *curctx;
17791 union irq_ctx *irqctx;
17792 u32 *isp;
17793
17794@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17795 local_irq_save(flags);
17796
17797 if (local_softirq_pending()) {
17798- curctx = current_thread_info();
17799 irqctx = __this_cpu_read(softirq_ctx);
17800- irqctx->tinfo.task = curctx->task;
17801- irqctx->tinfo.previous_esp = current_stack_pointer;
17802+ irqctx->previous_esp = current_stack_pointer;
17803
17804 /* build the stack frame on the softirq stack */
17805- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17806+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17807+
17808+#ifdef CONFIG_PAX_MEMORY_UDEREF
17809+ __set_fs(MAKE_MM_SEG(0));
17810+#endif
17811
17812 call_on_stack(__do_softirq, isp);
17813+
17814+#ifdef CONFIG_PAX_MEMORY_UDEREF
17815+ __set_fs(current_thread_info()->addr_limit);
17816+#endif
17817+
17818 /*
17819 * Shouldn't happen, we returned above if in_interrupt():
17820 */
17821@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17822 if (unlikely(!desc))
17823 return false;
17824
17825- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17826+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17827 if (unlikely(overflow))
17828 print_stack_overflow();
17829 desc->handle_irq(irq, desc);
17830diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17831index d04d3ec..ea4b374 100644
17832--- a/arch/x86/kernel/irq_64.c
17833+++ b/arch/x86/kernel/irq_64.c
17834@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17835 u64 estack_top, estack_bottom;
17836 u64 curbase = (u64)task_stack_page(current);
17837
17838- if (user_mode_vm(regs))
17839+ if (user_mode(regs))
17840 return;
17841
17842 if (regs->sp >= curbase + sizeof(struct thread_info) +
17843diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17844index 1d5d31e..72731d4 100644
17845--- a/arch/x86/kernel/kdebugfs.c
17846+++ b/arch/x86/kernel/kdebugfs.c
17847@@ -27,7 +27,7 @@ struct setup_data_node {
17848 u32 len;
17849 };
17850
17851-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17852+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17853 size_t count, loff_t *ppos)
17854 {
17855 struct setup_data_node *node = file->private_data;
17856diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17857index 3f61904..873cea9 100644
17858--- a/arch/x86/kernel/kgdb.c
17859+++ b/arch/x86/kernel/kgdb.c
17860@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17861 #ifdef CONFIG_X86_32
17862 switch (regno) {
17863 case GDB_SS:
17864- if (!user_mode_vm(regs))
17865+ if (!user_mode(regs))
17866 *(unsigned long *)mem = __KERNEL_DS;
17867 break;
17868 case GDB_SP:
17869- if (!user_mode_vm(regs))
17870+ if (!user_mode(regs))
17871 *(unsigned long *)mem = kernel_stack_pointer(regs);
17872 break;
17873 case GDB_GS:
17874@@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17875 case 'k':
17876 /* clear the trace bit */
17877 linux_regs->flags &= ~X86_EFLAGS_TF;
17878- atomic_set(&kgdb_cpu_doing_single_step, -1);
17879+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17880
17881 /* set the trace bit if we're stepping */
17882 if (remcomInBuffer[0] == 's') {
17883 linux_regs->flags |= X86_EFLAGS_TF;
17884- atomic_set(&kgdb_cpu_doing_single_step,
17885+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17886 raw_smp_processor_id());
17887 }
17888
17889@@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17890
17891 switch (cmd) {
17892 case DIE_DEBUG:
17893- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17894+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17895 if (user_mode(regs))
17896 return single_step_cont(regs, args);
17897 break;
17898diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17899index c5e410e..da6aaf9 100644
17900--- a/arch/x86/kernel/kprobes-opt.c
17901+++ b/arch/x86/kernel/kprobes-opt.c
17902@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17903 * Verify if the address gap is in 2GB range, because this uses
17904 * a relative jump.
17905 */
17906- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17907+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17908 if (abs(rel) > 0x7fffffff)
17909 return -ERANGE;
17910
17911@@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17912 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17913
17914 /* Set probe function call */
17915- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17916+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17917
17918 /* Set returning jmp instruction at the tail of out-of-line buffer */
17919 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17920- (u8 *)op->kp.addr + op->optinsn.size);
17921+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17922
17923 flush_icache_range((unsigned long) buf,
17924 (unsigned long) buf + TMPL_END_IDX +
17925@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17926 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17927
17928 /* Backup instructions which will be replaced by jump address */
17929- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17930+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17931 RELATIVE_ADDR_SIZE);
17932
17933 insn_buf[0] = RELATIVEJUMP_OPCODE;
17934diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17935index e2f751e..dffa2a0 100644
17936--- a/arch/x86/kernel/kprobes.c
17937+++ b/arch/x86/kernel/kprobes.c
17938@@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17939 } __attribute__((packed)) *insn;
17940
17941 insn = (struct __arch_relative_insn *)from;
17942+
17943+ pax_open_kernel();
17944 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17945 insn->op = op;
17946+ pax_close_kernel();
17947 }
17948
17949 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17950@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17951 kprobe_opcode_t opcode;
17952 kprobe_opcode_t *orig_opcodes = opcodes;
17953
17954- if (search_exception_tables((unsigned long)opcodes))
17955+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17956 return 0; /* Page fault may occur on this address. */
17957
17958 retry:
17959@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17960 /* Another subsystem puts a breakpoint, failed to recover */
17961 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17962 return 0;
17963+ pax_open_kernel();
17964 memcpy(dest, insn.kaddr, insn.length);
17965+ pax_close_kernel();
17966
17967 #ifdef CONFIG_X86_64
17968 if (insn_rip_relative(&insn)) {
17969@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17970 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17971 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17972 disp = (u8 *) dest + insn_offset_displacement(&insn);
17973+ pax_open_kernel();
17974 *(s32 *) disp = (s32) newdisp;
17975+ pax_close_kernel();
17976 }
17977 #endif
17978 return insn.length;
17979@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17980 * nor set current_kprobe, because it doesn't use single
17981 * stepping.
17982 */
17983- regs->ip = (unsigned long)p->ainsn.insn;
17984+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17985 preempt_enable_no_resched();
17986 return;
17987 }
17988@@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17989 if (p->opcode == BREAKPOINT_INSTRUCTION)
17990 regs->ip = (unsigned long)p->addr;
17991 else
17992- regs->ip = (unsigned long)p->ainsn.insn;
17993+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17994 }
17995
17996 /*
17997@@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17998 setup_singlestep(p, regs, kcb, 0);
17999 return 1;
18000 }
18001- } else if (*addr != BREAKPOINT_INSTRUCTION) {
18002+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18003 /*
18004 * The breakpoint instruction was removed right
18005 * after we hit it. Another cpu has removed
18006@@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18007 " movq %rax, 152(%rsp)\n"
18008 RESTORE_REGS_STRING
18009 " popfq\n"
18010+#ifdef KERNEXEC_PLUGIN
18011+ " btsq $63,(%rsp)\n"
18012+#endif
18013 #else
18014 " pushf\n"
18015 SAVE_REGS_STRING
18016@@ -765,7 +775,7 @@ static void __kprobes
18017 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18018 {
18019 unsigned long *tos = stack_addr(regs);
18020- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18021+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18022 unsigned long orig_ip = (unsigned long)p->addr;
18023 kprobe_opcode_t *insn = p->ainsn.insn;
18024
18025@@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18026 struct die_args *args = data;
18027 int ret = NOTIFY_DONE;
18028
18029- if (args->regs && user_mode_vm(args->regs))
18030+ if (args->regs && user_mode(args->regs))
18031 return ret;
18032
18033 switch (val) {
18034diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18035index ebc9873..1b9724b 100644
18036--- a/arch/x86/kernel/ldt.c
18037+++ b/arch/x86/kernel/ldt.c
18038@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18039 if (reload) {
18040 #ifdef CONFIG_SMP
18041 preempt_disable();
18042- load_LDT(pc);
18043+ load_LDT_nolock(pc);
18044 if (!cpumask_equal(mm_cpumask(current->mm),
18045 cpumask_of(smp_processor_id())))
18046 smp_call_function(flush_ldt, current->mm, 1);
18047 preempt_enable();
18048 #else
18049- load_LDT(pc);
18050+ load_LDT_nolock(pc);
18051 #endif
18052 }
18053 if (oldsize) {
18054@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18055 return err;
18056
18057 for (i = 0; i < old->size; i++)
18058- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18059+ write_ldt_entry(new->ldt, i, old->ldt + i);
18060 return 0;
18061 }
18062
18063@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18064 retval = copy_ldt(&mm->context, &old_mm->context);
18065 mutex_unlock(&old_mm->context.lock);
18066 }
18067+
18068+ if (tsk == current) {
18069+ mm->context.vdso = 0;
18070+
18071+#ifdef CONFIG_X86_32
18072+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18073+ mm->context.user_cs_base = 0UL;
18074+ mm->context.user_cs_limit = ~0UL;
18075+
18076+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18077+ cpus_clear(mm->context.cpu_user_cs_mask);
18078+#endif
18079+
18080+#endif
18081+#endif
18082+
18083+ }
18084+
18085 return retval;
18086 }
18087
18088@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18089 }
18090 }
18091
18092+#ifdef CONFIG_PAX_SEGMEXEC
18093+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18094+ error = -EINVAL;
18095+ goto out_unlock;
18096+ }
18097+#endif
18098+
18099 fill_ldt(&ldt, &ldt_info);
18100 if (oldmode)
18101 ldt.avl = 0;
18102diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18103index 5b19e4d..6476a76 100644
18104--- a/arch/x86/kernel/machine_kexec_32.c
18105+++ b/arch/x86/kernel/machine_kexec_32.c
18106@@ -26,7 +26,7 @@
18107 #include <asm/cacheflush.h>
18108 #include <asm/debugreg.h>
18109
18110-static void set_idt(void *newidt, __u16 limit)
18111+static void set_idt(struct desc_struct *newidt, __u16 limit)
18112 {
18113 struct desc_ptr curidt;
18114
18115@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18116 }
18117
18118
18119-static void set_gdt(void *newgdt, __u16 limit)
18120+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18121 {
18122 struct desc_ptr curgdt;
18123
18124@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18125 }
18126
18127 control_page = page_address(image->control_code_page);
18128- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18129+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18130
18131 relocate_kernel_ptr = control_page;
18132 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18133diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18134index 0327e2b..e43737b 100644
18135--- a/arch/x86/kernel/microcode_intel.c
18136+++ b/arch/x86/kernel/microcode_intel.c
18137@@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18138
18139 static int get_ucode_user(void *to, const void *from, size_t n)
18140 {
18141- return copy_from_user(to, from, n);
18142+ return copy_from_user(to, (const void __force_user *)from, n);
18143 }
18144
18145 static enum ucode_state
18146 request_microcode_user(int cpu, const void __user *buf, size_t size)
18147 {
18148- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18149+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18150 }
18151
18152 static void microcode_fini_cpu(int cpu)
18153diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18154index f21fd94..61565cd 100644
18155--- a/arch/x86/kernel/module.c
18156+++ b/arch/x86/kernel/module.c
18157@@ -35,15 +35,60 @@
18158 #define DEBUGP(fmt...)
18159 #endif
18160
18161-void *module_alloc(unsigned long size)
18162+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18163 {
18164- if (PAGE_ALIGN(size) > MODULES_LEN)
18165+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18166 return NULL;
18167 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18168- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18169+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18170 -1, __builtin_return_address(0));
18171 }
18172
18173+void *module_alloc(unsigned long size)
18174+{
18175+
18176+#ifdef CONFIG_PAX_KERNEXEC
18177+ return __module_alloc(size, PAGE_KERNEL);
18178+#else
18179+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18180+#endif
18181+
18182+}
18183+
18184+#ifdef CONFIG_PAX_KERNEXEC
18185+#ifdef CONFIG_X86_32
18186+void *module_alloc_exec(unsigned long size)
18187+{
18188+ struct vm_struct *area;
18189+
18190+ if (size == 0)
18191+ return NULL;
18192+
18193+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18194+ return area ? area->addr : NULL;
18195+}
18196+EXPORT_SYMBOL(module_alloc_exec);
18197+
18198+void module_free_exec(struct module *mod, void *module_region)
18199+{
18200+ vunmap(module_region);
18201+}
18202+EXPORT_SYMBOL(module_free_exec);
18203+#else
18204+void module_free_exec(struct module *mod, void *module_region)
18205+{
18206+ module_free(mod, module_region);
18207+}
18208+EXPORT_SYMBOL(module_free_exec);
18209+
18210+void *module_alloc_exec(unsigned long size)
18211+{
18212+ return __module_alloc(size, PAGE_KERNEL_RX);
18213+}
18214+EXPORT_SYMBOL(module_alloc_exec);
18215+#endif
18216+#endif
18217+
18218 #ifdef CONFIG_X86_32
18219 int apply_relocate(Elf32_Shdr *sechdrs,
18220 const char *strtab,
18221@@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18222 unsigned int i;
18223 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18224 Elf32_Sym *sym;
18225- uint32_t *location;
18226+ uint32_t *plocation, location;
18227
18228 DEBUGP("Applying relocate section %u to %u\n", relsec,
18229 sechdrs[relsec].sh_info);
18230 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18231 /* This is where to make the change */
18232- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18233- + rel[i].r_offset;
18234+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18235+ location = (uint32_t)plocation;
18236+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18237+ plocation = ktla_ktva((void *)plocation);
18238 /* This is the symbol it is referring to. Note that all
18239 undefined symbols have been resolved. */
18240 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18241@@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18242 switch (ELF32_R_TYPE(rel[i].r_info)) {
18243 case R_386_32:
18244 /* We add the value into the location given */
18245- *location += sym->st_value;
18246+ pax_open_kernel();
18247+ *plocation += sym->st_value;
18248+ pax_close_kernel();
18249 break;
18250 case R_386_PC32:
18251 /* Add the value, subtract its postition */
18252- *location += sym->st_value - (uint32_t)location;
18253+ pax_open_kernel();
18254+ *plocation += sym->st_value - location;
18255+ pax_close_kernel();
18256 break;
18257 default:
18258 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18259@@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18260 case R_X86_64_NONE:
18261 break;
18262 case R_X86_64_64:
18263+ pax_open_kernel();
18264 *(u64 *)loc = val;
18265+ pax_close_kernel();
18266 break;
18267 case R_X86_64_32:
18268+ pax_open_kernel();
18269 *(u32 *)loc = val;
18270+ pax_close_kernel();
18271 if (val != *(u32 *)loc)
18272 goto overflow;
18273 break;
18274 case R_X86_64_32S:
18275+ pax_open_kernel();
18276 *(s32 *)loc = val;
18277+ pax_close_kernel();
18278 if ((s64)val != *(s32 *)loc)
18279 goto overflow;
18280 break;
18281 case R_X86_64_PC32:
18282 val -= (u64)loc;
18283+ pax_open_kernel();
18284 *(u32 *)loc = val;
18285+ pax_close_kernel();
18286+
18287 #if 0
18288 if ((s64)val != *(s32 *)loc)
18289 goto overflow;
18290diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18291index a0b2f84..875ab81 100644
18292--- a/arch/x86/kernel/nmi.c
18293+++ b/arch/x86/kernel/nmi.c
18294@@ -460,6 +460,17 @@ static inline void nmi_nesting_postprocess(void)
18295 dotraplinkage notrace __kprobes void
18296 do_nmi(struct pt_regs *regs, long error_code)
18297 {
18298+
18299+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18300+ if (!user_mode(regs)) {
18301+ unsigned long cs = regs->cs & 0xFFFF;
18302+ unsigned long ip = ktva_ktla(regs->ip);
18303+
18304+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18305+ regs->ip = ip;
18306+ }
18307+#endif
18308+
18309 nmi_nesting_preprocess(regs);
18310
18311 nmi_enter();
18312diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18313index 676b8c7..870ba04 100644
18314--- a/arch/x86/kernel/paravirt-spinlocks.c
18315+++ b/arch/x86/kernel/paravirt-spinlocks.c
18316@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18317 arch_spin_lock(lock);
18318 }
18319
18320-struct pv_lock_ops pv_lock_ops = {
18321+struct pv_lock_ops pv_lock_ops __read_only = {
18322 #ifdef CONFIG_SMP
18323 .spin_is_locked = __ticket_spin_is_locked,
18324 .spin_is_contended = __ticket_spin_is_contended,
18325diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18326index 9ce8859..b49bf51 100644
18327--- a/arch/x86/kernel/paravirt.c
18328+++ b/arch/x86/kernel/paravirt.c
18329@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18330 {
18331 return x;
18332 }
18333+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18334+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18335+#endif
18336
18337 void __init default_banner(void)
18338 {
18339@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18340 if (opfunc == NULL)
18341 /* If there's no function, patch it with a ud2a (BUG) */
18342 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18343- else if (opfunc == _paravirt_nop)
18344+ else if (opfunc == (void *)_paravirt_nop)
18345 /* If the operation is a nop, then nop the callsite */
18346 ret = paravirt_patch_nop();
18347
18348 /* identity functions just return their single argument */
18349- else if (opfunc == _paravirt_ident_32)
18350+ else if (opfunc == (void *)_paravirt_ident_32)
18351 ret = paravirt_patch_ident_32(insnbuf, len);
18352- else if (opfunc == _paravirt_ident_64)
18353+ else if (opfunc == (void *)_paravirt_ident_64)
18354 ret = paravirt_patch_ident_64(insnbuf, len);
18355+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18356+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18357+ ret = paravirt_patch_ident_64(insnbuf, len);
18358+#endif
18359
18360 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18361 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18362@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18363 if (insn_len > len || start == NULL)
18364 insn_len = len;
18365 else
18366- memcpy(insnbuf, start, insn_len);
18367+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18368
18369 return insn_len;
18370 }
18371@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18372 preempt_enable();
18373 }
18374
18375-struct pv_info pv_info = {
18376+struct pv_info pv_info __read_only = {
18377 .name = "bare hardware",
18378 .paravirt_enabled = 0,
18379 .kernel_rpl = 0,
18380@@ -315,16 +322,16 @@ struct pv_info pv_info = {
18381 #endif
18382 };
18383
18384-struct pv_init_ops pv_init_ops = {
18385+struct pv_init_ops pv_init_ops __read_only = {
18386 .patch = native_patch,
18387 };
18388
18389-struct pv_time_ops pv_time_ops = {
18390+struct pv_time_ops pv_time_ops __read_only = {
18391 .sched_clock = native_sched_clock,
18392 .steal_clock = native_steal_clock,
18393 };
18394
18395-struct pv_irq_ops pv_irq_ops = {
18396+struct pv_irq_ops pv_irq_ops __read_only = {
18397 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18398 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18399 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18400@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18401 #endif
18402 };
18403
18404-struct pv_cpu_ops pv_cpu_ops = {
18405+struct pv_cpu_ops pv_cpu_ops __read_only = {
18406 .cpuid = native_cpuid,
18407 .get_debugreg = native_get_debugreg,
18408 .set_debugreg = native_set_debugreg,
18409@@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18410 .end_context_switch = paravirt_nop,
18411 };
18412
18413-struct pv_apic_ops pv_apic_ops = {
18414+struct pv_apic_ops pv_apic_ops __read_only = {
18415 #ifdef CONFIG_X86_LOCAL_APIC
18416 .startup_ipi_hook = paravirt_nop,
18417 #endif
18418 };
18419
18420-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18421+#ifdef CONFIG_X86_32
18422+#ifdef CONFIG_X86_PAE
18423+/* 64-bit pagetable entries */
18424+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18425+#else
18426 /* 32-bit pagetable entries */
18427 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18428+#endif
18429 #else
18430 /* 64-bit pagetable entries */
18431 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18432 #endif
18433
18434-struct pv_mmu_ops pv_mmu_ops = {
18435+struct pv_mmu_ops pv_mmu_ops __read_only = {
18436
18437 .read_cr2 = native_read_cr2,
18438 .write_cr2 = native_write_cr2,
18439@@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18440 .make_pud = PTE_IDENT,
18441
18442 .set_pgd = native_set_pgd,
18443+ .set_pgd_batched = native_set_pgd_batched,
18444 #endif
18445 #endif /* PAGETABLE_LEVELS >= 3 */
18446
18447@@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18448 },
18449
18450 .set_fixmap = native_set_fixmap,
18451+
18452+#ifdef CONFIG_PAX_KERNEXEC
18453+ .pax_open_kernel = native_pax_open_kernel,
18454+ .pax_close_kernel = native_pax_close_kernel,
18455+#endif
18456+
18457 };
18458
18459 EXPORT_SYMBOL_GPL(pv_time_ops);
18460diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18461index 35ccf75..7a15747 100644
18462--- a/arch/x86/kernel/pci-iommu_table.c
18463+++ b/arch/x86/kernel/pci-iommu_table.c
18464@@ -2,7 +2,7 @@
18465 #include <asm/iommu_table.h>
18466 #include <linux/string.h>
18467 #include <linux/kallsyms.h>
18468-
18469+#include <linux/sched.h>
18470
18471 #define DEBUG 1
18472
18473diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18474index 735279e..5008677 100644
18475--- a/arch/x86/kernel/process.c
18476+++ b/arch/x86/kernel/process.c
18477@@ -34,7 +34,8 @@
18478 * section. Since TSS's are completely CPU-local, we want them
18479 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18480 */
18481-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18482+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18483+EXPORT_SYMBOL(init_tss);
18484
18485 #ifdef CONFIG_X86_64
18486 static DEFINE_PER_CPU(unsigned char, is_idle);
18487@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
18488 task_xstate_cachep =
18489 kmem_cache_create("task_xstate", xstate_size,
18490 __alignof__(union thread_xstate),
18491- SLAB_PANIC | SLAB_NOTRACK, NULL);
18492+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18493 }
18494
18495 static inline void drop_fpu(struct task_struct *tsk)
18496@@ -115,7 +116,7 @@ void exit_thread(void)
18497 unsigned long *bp = t->io_bitmap_ptr;
18498
18499 if (bp) {
18500- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18501+ struct tss_struct *tss = init_tss + get_cpu();
18502
18503 t->io_bitmap_ptr = NULL;
18504 clear_thread_flag(TIF_IO_BITMAP);
18505@@ -147,7 +148,7 @@ void show_regs_common(void)
18506
18507 printk(KERN_CONT "\n");
18508 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18509- current->pid, current->comm, print_tainted(),
18510+ task_pid_nr(current), current->comm, print_tainted(),
18511 init_utsname()->release,
18512 (int)strcspn(init_utsname()->version, " "),
18513 init_utsname()->version);
18514@@ -161,6 +162,9 @@ void flush_thread(void)
18515 {
18516 struct task_struct *tsk = current;
18517
18518+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18519+ loadsegment(gs, 0);
18520+#endif
18521 flush_ptrace_hw_breakpoint(tsk);
18522 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18523 drop_fpu(tsk);
18524@@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18525 regs.di = (unsigned long) arg;
18526
18527 #ifdef CONFIG_X86_32
18528- regs.ds = __USER_DS;
18529- regs.es = __USER_DS;
18530+ regs.ds = __KERNEL_DS;
18531+ regs.es = __KERNEL_DS;
18532 regs.fs = __KERNEL_PERCPU;
18533- regs.gs = __KERNEL_STACK_CANARY;
18534+ savesegment(gs, regs.gs);
18535 #else
18536 regs.ss = __KERNEL_DS;
18537 #endif
18538@@ -407,7 +411,7 @@ static void __exit_idle(void)
18539 void exit_idle(void)
18540 {
18541 /* idle loop has pid 0 */
18542- if (current->pid)
18543+ if (task_pid_nr(current))
18544 return;
18545 __exit_idle();
18546 }
18547@@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18548
18549 return ret;
18550 }
18551-void stop_this_cpu(void *dummy)
18552+__noreturn void stop_this_cpu(void *dummy)
18553 {
18554 local_irq_disable();
18555 /*
18556@@ -746,16 +750,37 @@ static int __init idle_setup(char *str)
18557 }
18558 early_param("idle", idle_setup);
18559
18560-unsigned long arch_align_stack(unsigned long sp)
18561+#ifdef CONFIG_PAX_RANDKSTACK
18562+void pax_randomize_kstack(struct pt_regs *regs)
18563 {
18564- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18565- sp -= get_random_int() % 8192;
18566- return sp & ~0xf;
18567-}
18568+ struct thread_struct *thread = &current->thread;
18569+ unsigned long time;
18570
18571-unsigned long arch_randomize_brk(struct mm_struct *mm)
18572-{
18573- unsigned long range_end = mm->brk + 0x02000000;
18574- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18575-}
18576+ if (!randomize_va_space)
18577+ return;
18578+
18579+ if (v8086_mode(regs))
18580+ return;
18581
18582+ rdtscl(time);
18583+
18584+ /* P4 seems to return a 0 LSB, ignore it */
18585+#ifdef CONFIG_MPENTIUM4
18586+ time &= 0x3EUL;
18587+ time <<= 2;
18588+#elif defined(CONFIG_X86_64)
18589+ time &= 0xFUL;
18590+ time <<= 4;
18591+#else
18592+ time &= 0x1FUL;
18593+ time <<= 3;
18594+#endif
18595+
18596+ thread->sp0 ^= time;
18597+ load_sp0(init_tss + smp_processor_id(), thread);
18598+
18599+#ifdef CONFIG_X86_64
18600+ this_cpu_write(kernel_stack, thread->sp0);
18601+#endif
18602+}
18603+#endif
18604diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18605index 516fa18..80bd9e6 100644
18606--- a/arch/x86/kernel/process_32.c
18607+++ b/arch/x86/kernel/process_32.c
18608@@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18609 unsigned long thread_saved_pc(struct task_struct *tsk)
18610 {
18611 return ((unsigned long *)tsk->thread.sp)[3];
18612+//XXX return tsk->thread.eip;
18613 }
18614
18615 void __show_regs(struct pt_regs *regs, int all)
18616@@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18617 unsigned long sp;
18618 unsigned short ss, gs;
18619
18620- if (user_mode_vm(regs)) {
18621+ if (user_mode(regs)) {
18622 sp = regs->sp;
18623 ss = regs->ss & 0xffff;
18624- gs = get_user_gs(regs);
18625 } else {
18626 sp = kernel_stack_pointer(regs);
18627 savesegment(ss, ss);
18628- savesegment(gs, gs);
18629 }
18630+ gs = get_user_gs(regs);
18631
18632 show_regs_common();
18633
18634@@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18635 struct task_struct *tsk;
18636 int err;
18637
18638- childregs = task_pt_regs(p);
18639+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18640 *childregs = *regs;
18641 childregs->ax = 0;
18642 childregs->sp = sp;
18643
18644 p->thread.sp = (unsigned long) childregs;
18645 p->thread.sp0 = (unsigned long) (childregs+1);
18646+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18647
18648 p->thread.ip = (unsigned long) ret_from_fork;
18649
18650@@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18651 struct thread_struct *prev = &prev_p->thread,
18652 *next = &next_p->thread;
18653 int cpu = smp_processor_id();
18654- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18655+ struct tss_struct *tss = init_tss + cpu;
18656 fpu_switch_t fpu;
18657
18658 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18659@@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18660 */
18661 lazy_save_gs(prev->gs);
18662
18663+#ifdef CONFIG_PAX_MEMORY_UDEREF
18664+ __set_fs(task_thread_info(next_p)->addr_limit);
18665+#endif
18666+
18667 /*
18668 * Load the per-thread Thread-Local Storage descriptor.
18669 */
18670@@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18671 */
18672 arch_end_context_switch(next_p);
18673
18674+ this_cpu_write(current_task, next_p);
18675+ this_cpu_write(current_tinfo, &next_p->tinfo);
18676+
18677 /*
18678 * Restore %gs if needed (which is common)
18679 */
18680@@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18681
18682 switch_fpu_finish(next_p, fpu);
18683
18684- this_cpu_write(current_task, next_p);
18685-
18686 return prev_p;
18687 }
18688
18689@@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18690 } while (count++ < 16);
18691 return 0;
18692 }
18693-
18694diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18695index 61cdf7f..797f06a 100644
18696--- a/arch/x86/kernel/process_64.c
18697+++ b/arch/x86/kernel/process_64.c
18698@@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18699 struct pt_regs *childregs;
18700 struct task_struct *me = current;
18701
18702- childregs = ((struct pt_regs *)
18703- (THREAD_SIZE + task_stack_page(p))) - 1;
18704+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18705 *childregs = *regs;
18706
18707 childregs->ax = 0;
18708@@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18709 p->thread.sp = (unsigned long) childregs;
18710 p->thread.sp0 = (unsigned long) (childregs+1);
18711 p->thread.usersp = me->thread.usersp;
18712+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18713
18714 set_tsk_thread_flag(p, TIF_FORK);
18715
18716@@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18717 struct thread_struct *prev = &prev_p->thread;
18718 struct thread_struct *next = &next_p->thread;
18719 int cpu = smp_processor_id();
18720- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18721+ struct tss_struct *tss = init_tss + cpu;
18722 unsigned fsindex, gsindex;
18723 fpu_switch_t fpu;
18724
18725@@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18726 prev->usersp = this_cpu_read(old_rsp);
18727 this_cpu_write(old_rsp, next->usersp);
18728 this_cpu_write(current_task, next_p);
18729+ this_cpu_write(current_tinfo, &next_p->tinfo);
18730
18731- this_cpu_write(kernel_stack,
18732- (unsigned long)task_stack_page(next_p) +
18733- THREAD_SIZE - KERNEL_STACK_OFFSET);
18734+ this_cpu_write(kernel_stack, next->sp0);
18735
18736 /*
18737 * Now maybe reload the debug registers and handle I/O bitmaps
18738@@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18739 if (!p || p == current || p->state == TASK_RUNNING)
18740 return 0;
18741 stack = (unsigned long)task_stack_page(p);
18742- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18743+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18744 return 0;
18745 fp = *(u64 *)(p->thread.sp);
18746 do {
18747- if (fp < (unsigned long)stack ||
18748- fp >= (unsigned long)stack+THREAD_SIZE)
18749+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18750 return 0;
18751 ip = *(u64 *)(fp+8);
18752 if (!in_sched_functions(ip))
18753diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18754index c4c6a5c..905f440 100644
18755--- a/arch/x86/kernel/ptrace.c
18756+++ b/arch/x86/kernel/ptrace.c
18757@@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18758 unsigned long addr, unsigned long data)
18759 {
18760 int ret;
18761- unsigned long __user *datap = (unsigned long __user *)data;
18762+ unsigned long __user *datap = (__force unsigned long __user *)data;
18763
18764 switch (request) {
18765 /* read the word at location addr in the USER area. */
18766@@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18767 if ((int) addr < 0)
18768 return -EIO;
18769 ret = do_get_thread_area(child, addr,
18770- (struct user_desc __user *)data);
18771+ (__force struct user_desc __user *) data);
18772 break;
18773
18774 case PTRACE_SET_THREAD_AREA:
18775 if ((int) addr < 0)
18776 return -EIO;
18777 ret = do_set_thread_area(child, addr,
18778- (struct user_desc __user *)data, 0);
18779+ (__force struct user_desc __user *) data, 0);
18780 break;
18781 #endif
18782
18783@@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18784 memset(info, 0, sizeof(*info));
18785 info->si_signo = SIGTRAP;
18786 info->si_code = si_code;
18787- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18788+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18789 }
18790
18791 void user_single_step_siginfo(struct task_struct *tsk,
18792@@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18793 # define IS_IA32 0
18794 #endif
18795
18796+#ifdef CONFIG_GRKERNSEC_SETXID
18797+extern void gr_delayed_cred_worker(void);
18798+#endif
18799+
18800 /*
18801 * We must return the syscall number to actually look up in the table.
18802 * This can be -1L to skip running any syscall at all.
18803@@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18804 {
18805 long ret = 0;
18806
18807+#ifdef CONFIG_GRKERNSEC_SETXID
18808+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18809+ gr_delayed_cred_worker();
18810+#endif
18811+
18812 /*
18813 * If we stepped into a sysenter/syscall insn, it trapped in
18814 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18815@@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18816 {
18817 bool step;
18818
18819+#ifdef CONFIG_GRKERNSEC_SETXID
18820+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18821+ gr_delayed_cred_worker();
18822+#endif
18823+
18824 audit_syscall_exit(regs);
18825
18826 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18827diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18828index 42eb330..139955c 100644
18829--- a/arch/x86/kernel/pvclock.c
18830+++ b/arch/x86/kernel/pvclock.c
18831@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18832 return pv_tsc_khz;
18833 }
18834
18835-static atomic64_t last_value = ATOMIC64_INIT(0);
18836+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18837
18838 void pvclock_resume(void)
18839 {
18840- atomic64_set(&last_value, 0);
18841+ atomic64_set_unchecked(&last_value, 0);
18842 }
18843
18844 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18845@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18846 * updating at the same time, and one of them could be slightly behind,
18847 * making the assumption that last_value always go forward fail to hold.
18848 */
18849- last = atomic64_read(&last_value);
18850+ last = atomic64_read_unchecked(&last_value);
18851 do {
18852 if (ret < last)
18853 return last;
18854- last = atomic64_cmpxchg(&last_value, last, ret);
18855+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18856 } while (unlikely(last != ret));
18857
18858 return ret;
18859diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18860index 5de92f1..776788d 100644
18861--- a/arch/x86/kernel/reboot.c
18862+++ b/arch/x86/kernel/reboot.c
18863@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18864 EXPORT_SYMBOL(pm_power_off);
18865
18866 static const struct desc_ptr no_idt = {};
18867-static int reboot_mode;
18868+static unsigned short reboot_mode;
18869 enum reboot_type reboot_type = BOOT_ACPI;
18870 int reboot_force;
18871
18872@@ -157,11 +157,15 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18873 return 0;
18874 }
18875
18876-void machine_real_restart(unsigned int type)
18877+__noreturn void machine_real_restart(unsigned int type)
18878 {
18879 void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18880 real_mode_header->machine_real_restart_asm;
18881
18882+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18883+ struct desc_struct *gdt;
18884+#endif
18885+
18886 local_irq_disable();
18887
18888 /*
18889@@ -189,10 +193,38 @@ void machine_real_restart(unsigned int type)
18890 * boot)". This seems like a fairly standard thing that gets set by
18891 * REBOOT.COM programs, and the previous reset routine did this
18892 * too. */
18893- *((unsigned short *)0x472) = reboot_mode;
18894+ *(unsigned short *)(__va(0x472)) = reboot_mode;
18895
18896 /* Jump to the identity-mapped low memory code */
18897+
18898+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18899+ gdt = get_cpu_gdt_table(smp_processor_id());
18900+ pax_open_kernel();
18901+#ifdef CONFIG_PAX_MEMORY_UDEREF
18902+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18903+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18904+ loadsegment(ds, __KERNEL_DS);
18905+ loadsegment(es, __KERNEL_DS);
18906+ loadsegment(ss, __KERNEL_DS);
18907+#endif
18908+#ifdef CONFIG_PAX_KERNEXEC
18909+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18910+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18911+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18912+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18913+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18914+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18915+#endif
18916+ pax_close_kernel();
18917+#endif
18918+
18919+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18920+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18921+ unreachable();
18922+#else
18923 restart_lowmem(type);
18924+#endif
18925+
18926 }
18927 #ifdef CONFIG_APM_MODULE
18928 EXPORT_SYMBOL(machine_real_restart);
18929@@ -543,7 +575,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18930 * try to force a triple fault and then cycle between hitting the keyboard
18931 * controller and doing that
18932 */
18933-static void native_machine_emergency_restart(void)
18934+static void __noreturn native_machine_emergency_restart(void)
18935 {
18936 int i;
18937 int attempt = 0;
18938@@ -670,13 +702,13 @@ void native_machine_shutdown(void)
18939 #endif
18940 }
18941
18942-static void __machine_emergency_restart(int emergency)
18943+static __noreturn void __machine_emergency_restart(int emergency)
18944 {
18945 reboot_emergency = emergency;
18946 machine_ops.emergency_restart();
18947 }
18948
18949-static void native_machine_restart(char *__unused)
18950+static void __noreturn native_machine_restart(char *__unused)
18951 {
18952 printk("machine restart\n");
18953
18954@@ -685,7 +717,7 @@ static void native_machine_restart(char *__unused)
18955 __machine_emergency_restart(0);
18956 }
18957
18958-static void native_machine_halt(void)
18959+static void __noreturn native_machine_halt(void)
18960 {
18961 /* Stop other cpus and apics */
18962 machine_shutdown();
18963@@ -695,7 +727,7 @@ static void native_machine_halt(void)
18964 stop_this_cpu(NULL);
18965 }
18966
18967-static void native_machine_power_off(void)
18968+static void __noreturn native_machine_power_off(void)
18969 {
18970 if (pm_power_off) {
18971 if (!reboot_force)
18972@@ -704,6 +736,7 @@ static void native_machine_power_off(void)
18973 }
18974 /* A fallback in case there is no PM info available */
18975 tboot_shutdown(TB_SHUTDOWN_HALT);
18976+ unreachable();
18977 }
18978
18979 struct machine_ops machine_ops = {
18980diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18981index 7a6f3b3..bed145d7 100644
18982--- a/arch/x86/kernel/relocate_kernel_64.S
18983+++ b/arch/x86/kernel/relocate_kernel_64.S
18984@@ -11,6 +11,7 @@
18985 #include <asm/kexec.h>
18986 #include <asm/processor-flags.h>
18987 #include <asm/pgtable_types.h>
18988+#include <asm/alternative-asm.h>
18989
18990 /*
18991 * Must be relocatable PIC code callable as a C function
18992@@ -160,13 +161,14 @@ identity_mapped:
18993 xorq %rbp, %rbp
18994 xorq %r8, %r8
18995 xorq %r9, %r9
18996- xorq %r10, %r9
18997+ xorq %r10, %r10
18998 xorq %r11, %r11
18999 xorq %r12, %r12
19000 xorq %r13, %r13
19001 xorq %r14, %r14
19002 xorq %r15, %r15
19003
19004+ pax_force_retaddr 0, 1
19005 ret
19006
19007 1:
19008diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19009index 16be6dc..4686132 100644
19010--- a/arch/x86/kernel/setup.c
19011+++ b/arch/x86/kernel/setup.c
19012@@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19013
19014 switch (data->type) {
19015 case SETUP_E820_EXT:
19016- parse_e820_ext(data);
19017+ parse_e820_ext((struct setup_data __force_kernel *)data);
19018 break;
19019 case SETUP_DTB:
19020 add_dtb(pa_data);
19021@@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19022 * area (640->1Mb) as ram even though it is not.
19023 * take them out.
19024 */
19025- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19026+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19027 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19028 }
19029
19030@@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19031
19032 if (!boot_params.hdr.root_flags)
19033 root_mountflags &= ~MS_RDONLY;
19034- init_mm.start_code = (unsigned long) _text;
19035- init_mm.end_code = (unsigned long) _etext;
19036+ init_mm.start_code = ktla_ktva((unsigned long) _text);
19037+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
19038 init_mm.end_data = (unsigned long) _edata;
19039 init_mm.brk = _brk_end;
19040
19041- code_resource.start = virt_to_phys(_text);
19042- code_resource.end = virt_to_phys(_etext)-1;
19043- data_resource.start = virt_to_phys(_etext);
19044+ code_resource.start = virt_to_phys(ktla_ktva(_text));
19045+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19046+ data_resource.start = virt_to_phys(_sdata);
19047 data_resource.end = virt_to_phys(_edata)-1;
19048 bss_resource.start = virt_to_phys(&__bss_start);
19049 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19050diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19051index 5a98aa2..2f9288d 100644
19052--- a/arch/x86/kernel/setup_percpu.c
19053+++ b/arch/x86/kernel/setup_percpu.c
19054@@ -21,19 +21,17 @@
19055 #include <asm/cpu.h>
19056 #include <asm/stackprotector.h>
19057
19058-DEFINE_PER_CPU(int, cpu_number);
19059+#ifdef CONFIG_SMP
19060+DEFINE_PER_CPU(unsigned int, cpu_number);
19061 EXPORT_PER_CPU_SYMBOL(cpu_number);
19062+#endif
19063
19064-#ifdef CONFIG_X86_64
19065 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19066-#else
19067-#define BOOT_PERCPU_OFFSET 0
19068-#endif
19069
19070 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19071 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19072
19073-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19074+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19075 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19076 };
19077 EXPORT_SYMBOL(__per_cpu_offset);
19078@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19079 {
19080 #ifdef CONFIG_X86_32
19081 struct desc_struct gdt;
19082+ unsigned long base = per_cpu_offset(cpu);
19083
19084- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19085- 0x2 | DESCTYPE_S, 0x8);
19086- gdt.s = 1;
19087+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19088+ 0x83 | DESCTYPE_S, 0xC);
19089 write_gdt_entry(get_cpu_gdt_table(cpu),
19090 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19091 #endif
19092@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19093 /* alrighty, percpu areas up and running */
19094 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19095 for_each_possible_cpu(cpu) {
19096+#ifdef CONFIG_CC_STACKPROTECTOR
19097+#ifdef CONFIG_X86_32
19098+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
19099+#endif
19100+#endif
19101 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19102 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19103 per_cpu(cpu_number, cpu) = cpu;
19104@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19105 */
19106 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19107 #endif
19108+#ifdef CONFIG_CC_STACKPROTECTOR
19109+#ifdef CONFIG_X86_32
19110+ if (!cpu)
19111+ per_cpu(stack_canary.canary, cpu) = canary;
19112+#endif
19113+#endif
19114 /*
19115 * Up to this point, the boot CPU has been using .init.data
19116 * area. Reload any changed state for the boot CPU.
19117diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19118index 21af737..fb45e22 100644
19119--- a/arch/x86/kernel/signal.c
19120+++ b/arch/x86/kernel/signal.c
19121@@ -191,7 +191,7 @@ static unsigned long align_sigframe(unsigned long sp)
19122 * Align the stack pointer according to the i386 ABI,
19123 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19124 */
19125- sp = ((sp + 4) & -16ul) - 4;
19126+ sp = ((sp - 12) & -16ul) - 4;
19127 #else /* !CONFIG_X86_32 */
19128 sp = round_down(sp, 16) - 8;
19129 #endif
19130@@ -242,11 +242,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19131 * Return an always-bogus address instead so we will die with SIGSEGV.
19132 */
19133 if (onsigstack && !likely(on_sig_stack(sp)))
19134- return (void __user *)-1L;
19135+ return (__force void __user *)-1L;
19136
19137 /* save i387 state */
19138 if (used_math() && save_i387_xstate(*fpstate) < 0)
19139- return (void __user *)-1L;
19140+ return (__force void __user *)-1L;
19141
19142 return (void __user *)sp;
19143 }
19144@@ -301,9 +301,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19145 }
19146
19147 if (current->mm->context.vdso)
19148- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19149+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19150 else
19151- restorer = &frame->retcode;
19152+ restorer = (void __user *)&frame->retcode;
19153 if (ka->sa.sa_flags & SA_RESTORER)
19154 restorer = ka->sa.sa_restorer;
19155
19156@@ -317,7 +317,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19157 * reasons and because gdb uses it as a signature to notice
19158 * signal handler stack frames.
19159 */
19160- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19161+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19162
19163 if (err)
19164 return -EFAULT;
19165@@ -371,7 +371,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19166 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19167
19168 /* Set up to return from userspace. */
19169- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19170+ if (current->mm->context.vdso)
19171+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19172+ else
19173+ restorer = (void __user *)&frame->retcode;
19174 if (ka->sa.sa_flags & SA_RESTORER)
19175 restorer = ka->sa.sa_restorer;
19176 put_user_ex(restorer, &frame->pretcode);
19177@@ -383,7 +386,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19178 * reasons and because gdb uses it as a signature to notice
19179 * signal handler stack frames.
19180 */
19181- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19182+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19183 } put_user_catch(err);
19184
19185 if (err)
19186diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19187index 7bd8a08..2659b5b 100644
19188--- a/arch/x86/kernel/smpboot.c
19189+++ b/arch/x86/kernel/smpboot.c
19190@@ -679,6 +679,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19191 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19192 (THREAD_SIZE + task_stack_page(idle))) - 1);
19193 per_cpu(current_task, cpu) = idle;
19194+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
19195
19196 #ifdef CONFIG_X86_32
19197 /* Stack for startup_32 can be just as for start_secondary onwards */
19198@@ -686,11 +687,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19199 #else
19200 clear_tsk_thread_flag(idle, TIF_FORK);
19201 initial_gs = per_cpu_offset(cpu);
19202- per_cpu(kernel_stack, cpu) =
19203- (unsigned long)task_stack_page(idle) -
19204- KERNEL_STACK_OFFSET + THREAD_SIZE;
19205+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19206 #endif
19207+
19208+ pax_open_kernel();
19209 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19210+ pax_close_kernel();
19211+
19212 initial_code = (unsigned long)start_secondary;
19213 stack_start = idle->thread.sp;
19214
19215@@ -826,6 +829,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19216
19217 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19218
19219+#ifdef CONFIG_PAX_PER_CPU_PGD
19220+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19221+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19222+ KERNEL_PGD_PTRS);
19223+#endif
19224+
19225 err = do_boot_cpu(apicid, cpu, tidle);
19226 if (err) {
19227 pr_debug("do_boot_cpu failed %d\n", err);
19228diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19229index c346d11..d43b163 100644
19230--- a/arch/x86/kernel/step.c
19231+++ b/arch/x86/kernel/step.c
19232@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19233 struct desc_struct *desc;
19234 unsigned long base;
19235
19236- seg &= ~7UL;
19237+ seg >>= 3;
19238
19239 mutex_lock(&child->mm->context.lock);
19240- if (unlikely((seg >> 3) >= child->mm->context.size))
19241+ if (unlikely(seg >= child->mm->context.size))
19242 addr = -1L; /* bogus selector, access would fault */
19243 else {
19244 desc = child->mm->context.ldt + seg;
19245@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19246 addr += base;
19247 }
19248 mutex_unlock(&child->mm->context.lock);
19249- }
19250+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19251+ addr = ktla_ktva(addr);
19252
19253 return addr;
19254 }
19255@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19256 unsigned char opcode[15];
19257 unsigned long addr = convert_ip_to_linear(child, regs);
19258
19259+ if (addr == -EINVAL)
19260+ return 0;
19261+
19262 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19263 for (i = 0; i < copied; i++) {
19264 switch (opcode[i]) {
19265diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19266index 0b0cb5f..db6b9ed 100644
19267--- a/arch/x86/kernel/sys_i386_32.c
19268+++ b/arch/x86/kernel/sys_i386_32.c
19269@@ -24,17 +24,224 @@
19270
19271 #include <asm/syscalls.h>
19272
19273-/*
19274- * Do a system call from kernel instead of calling sys_execve so we
19275- * end up with proper pt_regs.
19276- */
19277-int kernel_execve(const char *filename,
19278- const char *const argv[],
19279- const char *const envp[])
19280+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19281 {
19282- long __res;
19283- asm volatile ("int $0x80"
19284- : "=a" (__res)
19285- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19286- return __res;
19287+ unsigned long pax_task_size = TASK_SIZE;
19288+
19289+#ifdef CONFIG_PAX_SEGMEXEC
19290+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19291+ pax_task_size = SEGMEXEC_TASK_SIZE;
19292+#endif
19293+
19294+ if (len > pax_task_size || addr > pax_task_size - len)
19295+ return -EINVAL;
19296+
19297+ return 0;
19298+}
19299+
19300+unsigned long
19301+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19302+ unsigned long len, unsigned long pgoff, unsigned long flags)
19303+{
19304+ struct mm_struct *mm = current->mm;
19305+ struct vm_area_struct *vma;
19306+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19307+
19308+#ifdef CONFIG_PAX_SEGMEXEC
19309+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19310+ pax_task_size = SEGMEXEC_TASK_SIZE;
19311+#endif
19312+
19313+ pax_task_size -= PAGE_SIZE;
19314+
19315+ if (len > pax_task_size)
19316+ return -ENOMEM;
19317+
19318+ if (flags & MAP_FIXED)
19319+ return addr;
19320+
19321+#ifdef CONFIG_PAX_RANDMMAP
19322+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19323+#endif
19324+
19325+ if (addr) {
19326+ addr = PAGE_ALIGN(addr);
19327+ if (pax_task_size - len >= addr) {
19328+ vma = find_vma(mm, addr);
19329+ if (check_heap_stack_gap(vma, addr, len))
19330+ return addr;
19331+ }
19332+ }
19333+ if (len > mm->cached_hole_size) {
19334+ start_addr = addr = mm->free_area_cache;
19335+ } else {
19336+ start_addr = addr = mm->mmap_base;
19337+ mm->cached_hole_size = 0;
19338+ }
19339+
19340+#ifdef CONFIG_PAX_PAGEEXEC
19341+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19342+ start_addr = 0x00110000UL;
19343+
19344+#ifdef CONFIG_PAX_RANDMMAP
19345+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19346+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19347+#endif
19348+
19349+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19350+ start_addr = addr = mm->mmap_base;
19351+ else
19352+ addr = start_addr;
19353+ }
19354+#endif
19355+
19356+full_search:
19357+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19358+ /* At this point: (!vma || addr < vma->vm_end). */
19359+ if (pax_task_size - len < addr) {
19360+ /*
19361+ * Start a new search - just in case we missed
19362+ * some holes.
19363+ */
19364+ if (start_addr != mm->mmap_base) {
19365+ start_addr = addr = mm->mmap_base;
19366+ mm->cached_hole_size = 0;
19367+ goto full_search;
19368+ }
19369+ return -ENOMEM;
19370+ }
19371+ if (check_heap_stack_gap(vma, addr, len))
19372+ break;
19373+ if (addr + mm->cached_hole_size < vma->vm_start)
19374+ mm->cached_hole_size = vma->vm_start - addr;
19375+ addr = vma->vm_end;
19376+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19377+ start_addr = addr = mm->mmap_base;
19378+ mm->cached_hole_size = 0;
19379+ goto full_search;
19380+ }
19381+ }
19382+
19383+ /*
19384+ * Remember the place where we stopped the search:
19385+ */
19386+ mm->free_area_cache = addr + len;
19387+ return addr;
19388+}
19389+
19390+unsigned long
19391+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19392+ const unsigned long len, const unsigned long pgoff,
19393+ const unsigned long flags)
19394+{
19395+ struct vm_area_struct *vma;
19396+ struct mm_struct *mm = current->mm;
19397+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19398+
19399+#ifdef CONFIG_PAX_SEGMEXEC
19400+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19401+ pax_task_size = SEGMEXEC_TASK_SIZE;
19402+#endif
19403+
19404+ pax_task_size -= PAGE_SIZE;
19405+
19406+ /* requested length too big for entire address space */
19407+ if (len > pax_task_size)
19408+ return -ENOMEM;
19409+
19410+ if (flags & MAP_FIXED)
19411+ return addr;
19412+
19413+#ifdef CONFIG_PAX_PAGEEXEC
19414+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19415+ goto bottomup;
19416+#endif
19417+
19418+#ifdef CONFIG_PAX_RANDMMAP
19419+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19420+#endif
19421+
19422+ /* requesting a specific address */
19423+ if (addr) {
19424+ addr = PAGE_ALIGN(addr);
19425+ if (pax_task_size - len >= addr) {
19426+ vma = find_vma(mm, addr);
19427+ if (check_heap_stack_gap(vma, addr, len))
19428+ return addr;
19429+ }
19430+ }
19431+
19432+ /* check if free_area_cache is useful for us */
19433+ if (len <= mm->cached_hole_size) {
19434+ mm->cached_hole_size = 0;
19435+ mm->free_area_cache = mm->mmap_base;
19436+ }
19437+
19438+ /* either no address requested or can't fit in requested address hole */
19439+ addr = mm->free_area_cache;
19440+
19441+ /* make sure it can fit in the remaining address space */
19442+ if (addr > len) {
19443+ vma = find_vma(mm, addr-len);
19444+ if (check_heap_stack_gap(vma, addr - len, len))
19445+ /* remember the address as a hint for next time */
19446+ return (mm->free_area_cache = addr-len);
19447+ }
19448+
19449+ if (mm->mmap_base < len)
19450+ goto bottomup;
19451+
19452+ addr = mm->mmap_base-len;
19453+
19454+ do {
19455+ /*
19456+ * Lookup failure means no vma is above this address,
19457+ * else if new region fits below vma->vm_start,
19458+ * return with success:
19459+ */
19460+ vma = find_vma(mm, addr);
19461+ if (check_heap_stack_gap(vma, addr, len))
19462+ /* remember the address as a hint for next time */
19463+ return (mm->free_area_cache = addr);
19464+
19465+ /* remember the largest hole we saw so far */
19466+ if (addr + mm->cached_hole_size < vma->vm_start)
19467+ mm->cached_hole_size = vma->vm_start - addr;
19468+
19469+ /* try just below the current vma->vm_start */
19470+ addr = skip_heap_stack_gap(vma, len);
19471+ } while (!IS_ERR_VALUE(addr));
19472+
19473+bottomup:
19474+ /*
19475+ * A failed mmap() very likely causes application failure,
19476+ * so fall back to the bottom-up function here. This scenario
19477+ * can happen with large stack limits and large mmap()
19478+ * allocations.
19479+ */
19480+
19481+#ifdef CONFIG_PAX_SEGMEXEC
19482+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19483+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19484+ else
19485+#endif
19486+
19487+ mm->mmap_base = TASK_UNMAPPED_BASE;
19488+
19489+#ifdef CONFIG_PAX_RANDMMAP
19490+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19491+ mm->mmap_base += mm->delta_mmap;
19492+#endif
19493+
19494+ mm->free_area_cache = mm->mmap_base;
19495+ mm->cached_hole_size = ~0UL;
19496+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19497+ /*
19498+ * Restore the topdown base:
19499+ */
19500+ mm->mmap_base = base;
19501+ mm->free_area_cache = base;
19502+ mm->cached_hole_size = ~0UL;
19503+
19504+ return addr;
19505 }
19506diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19507index b4d3c39..82bb73b 100644
19508--- a/arch/x86/kernel/sys_x86_64.c
19509+++ b/arch/x86/kernel/sys_x86_64.c
19510@@ -95,8 +95,8 @@ out:
19511 return error;
19512 }
19513
19514-static void find_start_end(unsigned long flags, unsigned long *begin,
19515- unsigned long *end)
19516+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19517+ unsigned long *begin, unsigned long *end)
19518 {
19519 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19520 unsigned long new_begin;
19521@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19522 *begin = new_begin;
19523 }
19524 } else {
19525- *begin = TASK_UNMAPPED_BASE;
19526+ *begin = mm->mmap_base;
19527 *end = TASK_SIZE;
19528 }
19529 }
19530@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19531 if (flags & MAP_FIXED)
19532 return addr;
19533
19534- find_start_end(flags, &begin, &end);
19535+ find_start_end(mm, flags, &begin, &end);
19536
19537 if (len > end)
19538 return -ENOMEM;
19539
19540+#ifdef CONFIG_PAX_RANDMMAP
19541+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19542+#endif
19543+
19544 if (addr) {
19545 addr = PAGE_ALIGN(addr);
19546 vma = find_vma(mm, addr);
19547- if (end - len >= addr &&
19548- (!vma || addr + len <= vma->vm_start))
19549+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19550 return addr;
19551 }
19552 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19553@@ -172,7 +175,7 @@ full_search:
19554 }
19555 return -ENOMEM;
19556 }
19557- if (!vma || addr + len <= vma->vm_start) {
19558+ if (check_heap_stack_gap(vma, addr, len)) {
19559 /*
19560 * Remember the place where we stopped the search:
19561 */
19562@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19563 {
19564 struct vm_area_struct *vma;
19565 struct mm_struct *mm = current->mm;
19566- unsigned long addr = addr0, start_addr;
19567+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19568
19569 /* requested length too big for entire address space */
19570 if (len > TASK_SIZE)
19571@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19572 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19573 goto bottomup;
19574
19575+#ifdef CONFIG_PAX_RANDMMAP
19576+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19577+#endif
19578+
19579 /* requesting a specific address */
19580 if (addr) {
19581 addr = PAGE_ALIGN(addr);
19582- vma = find_vma(mm, addr);
19583- if (TASK_SIZE - len >= addr &&
19584- (!vma || addr + len <= vma->vm_start))
19585- return addr;
19586+ if (TASK_SIZE - len >= addr) {
19587+ vma = find_vma(mm, addr);
19588+ if (check_heap_stack_gap(vma, addr, len))
19589+ return addr;
19590+ }
19591 }
19592
19593 /* check if free_area_cache is useful for us */
19594@@ -240,7 +248,7 @@ try_again:
19595 * return with success:
19596 */
19597 vma = find_vma(mm, addr);
19598- if (!vma || addr+len <= vma->vm_start)
19599+ if (check_heap_stack_gap(vma, addr, len))
19600 /* remember the address as a hint for next time */
19601 return mm->free_area_cache = addr;
19602
19603@@ -249,8 +257,8 @@ try_again:
19604 mm->cached_hole_size = vma->vm_start - addr;
19605
19606 /* try just below the current vma->vm_start */
19607- addr = vma->vm_start-len;
19608- } while (len < vma->vm_start);
19609+ addr = skip_heap_stack_gap(vma, len);
19610+ } while (!IS_ERR_VALUE(addr));
19611
19612 fail:
19613 /*
19614@@ -270,13 +278,21 @@ bottomup:
19615 * can happen with large stack limits and large mmap()
19616 * allocations.
19617 */
19618+ mm->mmap_base = TASK_UNMAPPED_BASE;
19619+
19620+#ifdef CONFIG_PAX_RANDMMAP
19621+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19622+ mm->mmap_base += mm->delta_mmap;
19623+#endif
19624+
19625+ mm->free_area_cache = mm->mmap_base;
19626 mm->cached_hole_size = ~0UL;
19627- mm->free_area_cache = TASK_UNMAPPED_BASE;
19628 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19629 /*
19630 * Restore the topdown base:
19631 */
19632- mm->free_area_cache = mm->mmap_base;
19633+ mm->mmap_base = base;
19634+ mm->free_area_cache = base;
19635 mm->cached_hole_size = ~0UL;
19636
19637 return addr;
19638diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19639index f84fe00..93fe08f 100644
19640--- a/arch/x86/kernel/tboot.c
19641+++ b/arch/x86/kernel/tboot.c
19642@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19643
19644 void tboot_shutdown(u32 shutdown_type)
19645 {
19646- void (*shutdown)(void);
19647+ void (* __noreturn shutdown)(void);
19648
19649 if (!tboot_enabled())
19650 return;
19651@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19652
19653 switch_to_tboot_pt();
19654
19655- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19656+ shutdown = (void *)tboot->shutdown_entry;
19657 shutdown();
19658
19659 /* should not reach here */
19660@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19661 return 0;
19662 }
19663
19664-static atomic_t ap_wfs_count;
19665+static atomic_unchecked_t ap_wfs_count;
19666
19667 static int tboot_wait_for_aps(int num_aps)
19668 {
19669@@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19670 {
19671 switch (action) {
19672 case CPU_DYING:
19673- atomic_inc(&ap_wfs_count);
19674+ atomic_inc_unchecked(&ap_wfs_count);
19675 if (num_online_cpus() == 1)
19676- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19677+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19678 return NOTIFY_BAD;
19679 break;
19680 }
19681@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19682
19683 tboot_create_trampoline();
19684
19685- atomic_set(&ap_wfs_count, 0);
19686+ atomic_set_unchecked(&ap_wfs_count, 0);
19687 register_hotcpu_notifier(&tboot_cpu_notifier);
19688
19689 acpi_os_set_prepare_sleep(&tboot_sleep);
19690diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19691index 24d3c91..d06b473 100644
19692--- a/arch/x86/kernel/time.c
19693+++ b/arch/x86/kernel/time.c
19694@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19695 {
19696 unsigned long pc = instruction_pointer(regs);
19697
19698- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19699+ if (!user_mode(regs) && in_lock_functions(pc)) {
19700 #ifdef CONFIG_FRAME_POINTER
19701- return *(unsigned long *)(regs->bp + sizeof(long));
19702+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19703 #else
19704 unsigned long *sp =
19705 (unsigned long *)kernel_stack_pointer(regs);
19706@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19707 * or above a saved flags. Eflags has bits 22-31 zero,
19708 * kernel addresses don't.
19709 */
19710+
19711+#ifdef CONFIG_PAX_KERNEXEC
19712+ return ktla_ktva(sp[0]);
19713+#else
19714 if (sp[0] >> 22)
19715 return sp[0];
19716 if (sp[1] >> 22)
19717 return sp[1];
19718 #endif
19719+
19720+#endif
19721 }
19722 return pc;
19723 }
19724diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19725index 9d9d2f9..cad418a 100644
19726--- a/arch/x86/kernel/tls.c
19727+++ b/arch/x86/kernel/tls.c
19728@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19729 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19730 return -EINVAL;
19731
19732+#ifdef CONFIG_PAX_SEGMEXEC
19733+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19734+ return -EINVAL;
19735+#endif
19736+
19737 set_tls_desc(p, idx, &info, 1);
19738
19739 return 0;
19740@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19741
19742 if (kbuf)
19743 info = kbuf;
19744- else if (__copy_from_user(infobuf, ubuf, count))
19745+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19746 return -EFAULT;
19747 else
19748 info = infobuf;
19749diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19750index 05b31d9..501d3ba 100644
19751--- a/arch/x86/kernel/traps.c
19752+++ b/arch/x86/kernel/traps.c
19753@@ -67,12 +67,6 @@ asmlinkage int system_call(void);
19754
19755 /* Do we ignore FPU interrupts ? */
19756 char ignore_fpu_irq;
19757-
19758-/*
19759- * The IDT has to be page-aligned to simplify the Pentium
19760- * F0 0F bug workaround.
19761- */
19762-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19763 #endif
19764
19765 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19766@@ -105,13 +99,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19767 }
19768
19769 static void __kprobes
19770-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19771+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19772 long error_code, siginfo_t *info)
19773 {
19774 struct task_struct *tsk = current;
19775
19776 #ifdef CONFIG_X86_32
19777- if (regs->flags & X86_VM_MASK) {
19778+ if (v8086_mode(regs)) {
19779 /*
19780 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19781 * On nmi (interrupt 2), do_trap should not be called.
19782@@ -122,7 +116,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19783 }
19784 #endif
19785
19786- if (!user_mode(regs))
19787+ if (!user_mode_novm(regs))
19788 goto kernel_trap;
19789
19790 #ifdef CONFIG_X86_32
19791@@ -145,7 +139,7 @@ trap_signal:
19792 printk_ratelimit()) {
19793 printk(KERN_INFO
19794 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19795- tsk->comm, tsk->pid, str,
19796+ tsk->comm, task_pid_nr(tsk), str,
19797 regs->ip, regs->sp, error_code);
19798 print_vma_addr(" in ", regs->ip);
19799 printk("\n");
19800@@ -162,8 +156,20 @@ kernel_trap:
19801 if (!fixup_exception(regs)) {
19802 tsk->thread.error_code = error_code;
19803 tsk->thread.trap_nr = trapnr;
19804+
19805+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19806+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19807+ str = "PAX: suspicious stack segment fault";
19808+#endif
19809+
19810 die(str, regs, error_code);
19811 }
19812+
19813+#ifdef CONFIG_PAX_REFCOUNT
19814+ if (trapnr == 4)
19815+ pax_report_refcount_overflow(regs);
19816+#endif
19817+
19818 return;
19819
19820 #ifdef CONFIG_X86_32
19821@@ -256,14 +262,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19822 conditional_sti(regs);
19823
19824 #ifdef CONFIG_X86_32
19825- if (regs->flags & X86_VM_MASK)
19826+ if (v8086_mode(regs))
19827 goto gp_in_vm86;
19828 #endif
19829
19830 tsk = current;
19831- if (!user_mode(regs))
19832+ if (!user_mode_novm(regs))
19833 goto gp_in_kernel;
19834
19835+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19836+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19837+ struct mm_struct *mm = tsk->mm;
19838+ unsigned long limit;
19839+
19840+ down_write(&mm->mmap_sem);
19841+ limit = mm->context.user_cs_limit;
19842+ if (limit < TASK_SIZE) {
19843+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19844+ up_write(&mm->mmap_sem);
19845+ return;
19846+ }
19847+ up_write(&mm->mmap_sem);
19848+ }
19849+#endif
19850+
19851 tsk->thread.error_code = error_code;
19852 tsk->thread.trap_nr = X86_TRAP_GP;
19853
19854@@ -296,6 +318,13 @@ gp_in_kernel:
19855 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19856 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19857 return;
19858+
19859+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19860+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19861+ die("PAX: suspicious general protection fault", regs, error_code);
19862+ else
19863+#endif
19864+
19865 die("general protection fault", regs, error_code);
19866 }
19867
19868@@ -431,7 +460,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19869 /* It's safe to allow irq's after DR6 has been saved */
19870 preempt_conditional_sti(regs);
19871
19872- if (regs->flags & X86_VM_MASK) {
19873+ if (v8086_mode(regs)) {
19874 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19875 X86_TRAP_DB);
19876 preempt_conditional_cli(regs);
19877@@ -446,7 +475,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19878 * We already checked v86 mode above, so we can check for kernel mode
19879 * by just checking the CPL of CS.
19880 */
19881- if ((dr6 & DR_STEP) && !user_mode(regs)) {
19882+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19883 tsk->thread.debugreg6 &= ~DR_STEP;
19884 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19885 regs->flags &= ~X86_EFLAGS_TF;
19886@@ -477,7 +506,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19887 return;
19888 conditional_sti(regs);
19889
19890- if (!user_mode_vm(regs))
19891+ if (!user_mode(regs))
19892 {
19893 if (!fixup_exception(regs)) {
19894 task->thread.error_code = error_code;
19895diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19896index dc4e910..c9dedab 100644
19897--- a/arch/x86/kernel/uprobes.c
19898+++ b/arch/x86/kernel/uprobes.c
19899@@ -606,7 +606,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19900 int ret = NOTIFY_DONE;
19901
19902 /* We are only interested in userspace traps */
19903- if (regs && !user_mode_vm(regs))
19904+ if (regs && !user_mode(regs))
19905 return NOTIFY_DONE;
19906
19907 switch (val) {
19908diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19909index b9242ba..50c5edd 100644
19910--- a/arch/x86/kernel/verify_cpu.S
19911+++ b/arch/x86/kernel/verify_cpu.S
19912@@ -20,6 +20,7 @@
19913 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19914 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19915 * arch/x86/kernel/head_32.S: processor startup
19916+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19917 *
19918 * verify_cpu, returns the status of longmode and SSE in register %eax.
19919 * 0: Success 1: Failure
19920diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19921index 255f58a..5e91150 100644
19922--- a/arch/x86/kernel/vm86_32.c
19923+++ b/arch/x86/kernel/vm86_32.c
19924@@ -41,6 +41,7 @@
19925 #include <linux/ptrace.h>
19926 #include <linux/audit.h>
19927 #include <linux/stddef.h>
19928+#include <linux/grsecurity.h>
19929
19930 #include <asm/uaccess.h>
19931 #include <asm/io.h>
19932@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19933 do_exit(SIGSEGV);
19934 }
19935
19936- tss = &per_cpu(init_tss, get_cpu());
19937+ tss = init_tss + get_cpu();
19938 current->thread.sp0 = current->thread.saved_sp0;
19939 current->thread.sysenter_cs = __KERNEL_CS;
19940 load_sp0(tss, &current->thread);
19941@@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19942 struct task_struct *tsk;
19943 int tmp, ret = -EPERM;
19944
19945+#ifdef CONFIG_GRKERNSEC_VM86
19946+ if (!capable(CAP_SYS_RAWIO)) {
19947+ gr_handle_vm86();
19948+ goto out;
19949+ }
19950+#endif
19951+
19952 tsk = current;
19953 if (tsk->thread.saved_sp0)
19954 goto out;
19955@@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19956 int tmp, ret;
19957 struct vm86plus_struct __user *v86;
19958
19959+#ifdef CONFIG_GRKERNSEC_VM86
19960+ if (!capable(CAP_SYS_RAWIO)) {
19961+ gr_handle_vm86();
19962+ ret = -EPERM;
19963+ goto out;
19964+ }
19965+#endif
19966+
19967 tsk = current;
19968 switch (cmd) {
19969 case VM86_REQUEST_IRQ:
19970@@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19971 tsk->thread.saved_fs = info->regs32->fs;
19972 tsk->thread.saved_gs = get_user_gs(info->regs32);
19973
19974- tss = &per_cpu(init_tss, get_cpu());
19975+ tss = init_tss + get_cpu();
19976 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19977 if (cpu_has_sep)
19978 tsk->thread.sysenter_cs = 0;
19979@@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19980 goto cannot_handle;
19981 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19982 goto cannot_handle;
19983- intr_ptr = (unsigned long __user *) (i << 2);
19984+ intr_ptr = (__force unsigned long __user *) (i << 2);
19985 if (get_user(segoffs, intr_ptr))
19986 goto cannot_handle;
19987 if ((segoffs >> 16) == BIOSSEG)
19988diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19989index 22a1530..8fbaaad 100644
19990--- a/arch/x86/kernel/vmlinux.lds.S
19991+++ b/arch/x86/kernel/vmlinux.lds.S
19992@@ -26,6 +26,13 @@
19993 #include <asm/page_types.h>
19994 #include <asm/cache.h>
19995 #include <asm/boot.h>
19996+#include <asm/segment.h>
19997+
19998+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19999+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20000+#else
20001+#define __KERNEL_TEXT_OFFSET 0
20002+#endif
20003
20004 #undef i386 /* in case the preprocessor is a 32bit one */
20005
20006@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20007
20008 PHDRS {
20009 text PT_LOAD FLAGS(5); /* R_E */
20010+#ifdef CONFIG_X86_32
20011+ module PT_LOAD FLAGS(5); /* R_E */
20012+#endif
20013+#ifdef CONFIG_XEN
20014+ rodata PT_LOAD FLAGS(5); /* R_E */
20015+#else
20016+ rodata PT_LOAD FLAGS(4); /* R__ */
20017+#endif
20018 data PT_LOAD FLAGS(6); /* RW_ */
20019-#ifdef CONFIG_X86_64
20020+ init.begin PT_LOAD FLAGS(6); /* RW_ */
20021 #ifdef CONFIG_SMP
20022 percpu PT_LOAD FLAGS(6); /* RW_ */
20023 #endif
20024+ text.init PT_LOAD FLAGS(5); /* R_E */
20025+ text.exit PT_LOAD FLAGS(5); /* R_E */
20026 init PT_LOAD FLAGS(7); /* RWE */
20027-#endif
20028 note PT_NOTE FLAGS(0); /* ___ */
20029 }
20030
20031 SECTIONS
20032 {
20033 #ifdef CONFIG_X86_32
20034- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20035- phys_startup_32 = startup_32 - LOAD_OFFSET;
20036+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20037 #else
20038- . = __START_KERNEL;
20039- phys_startup_64 = startup_64 - LOAD_OFFSET;
20040+ . = __START_KERNEL;
20041 #endif
20042
20043 /* Text and read-only data */
20044- .text : AT(ADDR(.text) - LOAD_OFFSET) {
20045- _text = .;
20046+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20047 /* bootstrapping code */
20048+#ifdef CONFIG_X86_32
20049+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20050+#else
20051+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20052+#endif
20053+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20054+ _text = .;
20055 HEAD_TEXT
20056 #ifdef CONFIG_X86_32
20057 . = ALIGN(PAGE_SIZE);
20058@@ -108,13 +128,48 @@ SECTIONS
20059 IRQENTRY_TEXT
20060 *(.fixup)
20061 *(.gnu.warning)
20062- /* End of text section */
20063- _etext = .;
20064 } :text = 0x9090
20065
20066- NOTES :text :note
20067+ . += __KERNEL_TEXT_OFFSET;
20068
20069- EXCEPTION_TABLE(16) :text = 0x9090
20070+#ifdef CONFIG_X86_32
20071+ . = ALIGN(PAGE_SIZE);
20072+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20073+
20074+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20075+ MODULES_EXEC_VADDR = .;
20076+ BYTE(0)
20077+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20078+ . = ALIGN(HPAGE_SIZE) - 1;
20079+ MODULES_EXEC_END = .;
20080+#endif
20081+
20082+ } :module
20083+#endif
20084+
20085+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20086+ /* End of text section */
20087+ BYTE(0)
20088+ _etext = . - __KERNEL_TEXT_OFFSET;
20089+ }
20090+
20091+#ifdef CONFIG_X86_32
20092+ . = ALIGN(PAGE_SIZE);
20093+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20094+ *(.idt)
20095+ . = ALIGN(PAGE_SIZE);
20096+ *(.empty_zero_page)
20097+ *(.initial_pg_fixmap)
20098+ *(.initial_pg_pmd)
20099+ *(.initial_page_table)
20100+ *(.swapper_pg_dir)
20101+ } :rodata
20102+#endif
20103+
20104+ . = ALIGN(PAGE_SIZE);
20105+ NOTES :rodata :note
20106+
20107+ EXCEPTION_TABLE(16) :rodata
20108
20109 #if defined(CONFIG_DEBUG_RODATA)
20110 /* .text should occupy whole number of pages */
20111@@ -126,16 +181,20 @@ SECTIONS
20112
20113 /* Data */
20114 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20115+
20116+#ifdef CONFIG_PAX_KERNEXEC
20117+ . = ALIGN(HPAGE_SIZE);
20118+#else
20119+ . = ALIGN(PAGE_SIZE);
20120+#endif
20121+
20122 /* Start of data section */
20123 _sdata = .;
20124
20125 /* init_task */
20126 INIT_TASK_DATA(THREAD_SIZE)
20127
20128-#ifdef CONFIG_X86_32
20129- /* 32 bit has nosave before _edata */
20130 NOSAVE_DATA
20131-#endif
20132
20133 PAGE_ALIGNED_DATA(PAGE_SIZE)
20134
20135@@ -176,12 +235,19 @@ SECTIONS
20136 #endif /* CONFIG_X86_64 */
20137
20138 /* Init code and data - will be freed after init */
20139- . = ALIGN(PAGE_SIZE);
20140 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20141+ BYTE(0)
20142+
20143+#ifdef CONFIG_PAX_KERNEXEC
20144+ . = ALIGN(HPAGE_SIZE);
20145+#else
20146+ . = ALIGN(PAGE_SIZE);
20147+#endif
20148+
20149 __init_begin = .; /* paired with __init_end */
20150- }
20151+ } :init.begin
20152
20153-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20154+#ifdef CONFIG_SMP
20155 /*
20156 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20157 * output PHDR, so the next output section - .init.text - should
20158@@ -190,12 +256,27 @@ SECTIONS
20159 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20160 #endif
20161
20162- INIT_TEXT_SECTION(PAGE_SIZE)
20163-#ifdef CONFIG_X86_64
20164- :init
20165-#endif
20166+ . = ALIGN(PAGE_SIZE);
20167+ init_begin = .;
20168+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20169+ VMLINUX_SYMBOL(_sinittext) = .;
20170+ INIT_TEXT
20171+ VMLINUX_SYMBOL(_einittext) = .;
20172+ . = ALIGN(PAGE_SIZE);
20173+ } :text.init
20174
20175- INIT_DATA_SECTION(16)
20176+ /*
20177+ * .exit.text is discard at runtime, not link time, to deal with
20178+ * references from .altinstructions and .eh_frame
20179+ */
20180+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20181+ EXIT_TEXT
20182+ . = ALIGN(16);
20183+ } :text.exit
20184+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20185+
20186+ . = ALIGN(PAGE_SIZE);
20187+ INIT_DATA_SECTION(16) :init
20188
20189 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20190 __x86_cpu_dev_start = .;
20191@@ -257,19 +338,12 @@ SECTIONS
20192 }
20193
20194 . = ALIGN(8);
20195- /*
20196- * .exit.text is discard at runtime, not link time, to deal with
20197- * references from .altinstructions and .eh_frame
20198- */
20199- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20200- EXIT_TEXT
20201- }
20202
20203 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20204 EXIT_DATA
20205 }
20206
20207-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20208+#ifndef CONFIG_SMP
20209 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20210 #endif
20211
20212@@ -288,16 +362,10 @@ SECTIONS
20213 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20214 __smp_locks = .;
20215 *(.smp_locks)
20216- . = ALIGN(PAGE_SIZE);
20217 __smp_locks_end = .;
20218+ . = ALIGN(PAGE_SIZE);
20219 }
20220
20221-#ifdef CONFIG_X86_64
20222- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20223- NOSAVE_DATA
20224- }
20225-#endif
20226-
20227 /* BSS */
20228 . = ALIGN(PAGE_SIZE);
20229 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20230@@ -313,6 +381,7 @@ SECTIONS
20231 __brk_base = .;
20232 . += 64 * 1024; /* 64k alignment slop space */
20233 *(.brk_reservation) /* areas brk users have reserved */
20234+ . = ALIGN(HPAGE_SIZE);
20235 __brk_limit = .;
20236 }
20237
20238@@ -339,13 +408,12 @@ SECTIONS
20239 * for the boot processor.
20240 */
20241 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20242-INIT_PER_CPU(gdt_page);
20243 INIT_PER_CPU(irq_stack_union);
20244
20245 /*
20246 * Build-time check on the image size:
20247 */
20248-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20249+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20250 "kernel image bigger than KERNEL_IMAGE_SIZE");
20251
20252 #ifdef CONFIG_SMP
20253diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20254index 5db36ca..2938af9 100644
20255--- a/arch/x86/kernel/vsyscall_64.c
20256+++ b/arch/x86/kernel/vsyscall_64.c
20257@@ -54,15 +54,13 @@
20258 DEFINE_VVAR(int, vgetcpu_mode);
20259 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20260
20261-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20262+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20263
20264 static int __init vsyscall_setup(char *str)
20265 {
20266 if (str) {
20267 if (!strcmp("emulate", str))
20268 vsyscall_mode = EMULATE;
20269- else if (!strcmp("native", str))
20270- vsyscall_mode = NATIVE;
20271 else if (!strcmp("none", str))
20272 vsyscall_mode = NONE;
20273 else
20274@@ -309,8 +307,7 @@ done:
20275 return true;
20276
20277 sigsegv:
20278- force_sig(SIGSEGV, current);
20279- return true;
20280+ do_group_exit(SIGKILL);
20281 }
20282
20283 /*
20284@@ -363,10 +360,7 @@ void __init map_vsyscall(void)
20285 extern char __vvar_page;
20286 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20287
20288- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20289- vsyscall_mode == NATIVE
20290- ? PAGE_KERNEL_VSYSCALL
20291- : PAGE_KERNEL_VVAR);
20292+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20293 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20294 (unsigned long)VSYSCALL_START);
20295
20296diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20297index 9796c2f..f686fbf 100644
20298--- a/arch/x86/kernel/x8664_ksyms_64.c
20299+++ b/arch/x86/kernel/x8664_ksyms_64.c
20300@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20301 EXPORT_SYMBOL(copy_user_generic_string);
20302 EXPORT_SYMBOL(copy_user_generic_unrolled);
20303 EXPORT_SYMBOL(__copy_user_nocache);
20304-EXPORT_SYMBOL(_copy_from_user);
20305-EXPORT_SYMBOL(_copy_to_user);
20306
20307 EXPORT_SYMBOL(copy_page);
20308 EXPORT_SYMBOL(clear_page);
20309diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20310index bd18149..2ea0183 100644
20311--- a/arch/x86/kernel/xsave.c
20312+++ b/arch/x86/kernel/xsave.c
20313@@ -129,7 +129,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20314 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20315 return -EINVAL;
20316
20317- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20318+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20319 fx_sw_user->extended_size -
20320 FP_XSTATE_MAGIC2_SIZE));
20321 if (err)
20322@@ -265,7 +265,7 @@ fx_only:
20323 * the other extended state.
20324 */
20325 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20326- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20327+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20328 }
20329
20330 /*
20331@@ -294,7 +294,7 @@ int restore_i387_xstate(void __user *buf)
20332 if (use_xsave())
20333 err = restore_user_xstate(buf);
20334 else
20335- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20336+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20337 buf);
20338 if (unlikely(err)) {
20339 /*
20340diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20341index 7df1c6d..9ea7c79 100644
20342--- a/arch/x86/kvm/cpuid.c
20343+++ b/arch/x86/kvm/cpuid.c
20344@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20345 struct kvm_cpuid2 *cpuid,
20346 struct kvm_cpuid_entry2 __user *entries)
20347 {
20348- int r;
20349+ int r, i;
20350
20351 r = -E2BIG;
20352 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20353 goto out;
20354 r = -EFAULT;
20355- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20356- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20357+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20358 goto out;
20359+ for (i = 0; i < cpuid->nent; ++i) {
20360+ struct kvm_cpuid_entry2 cpuid_entry;
20361+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20362+ goto out;
20363+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20364+ }
20365 vcpu->arch.cpuid_nent = cpuid->nent;
20366 kvm_apic_set_version(vcpu);
20367 kvm_x86_ops->cpuid_update(vcpu);
20368@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20369 struct kvm_cpuid2 *cpuid,
20370 struct kvm_cpuid_entry2 __user *entries)
20371 {
20372- int r;
20373+ int r, i;
20374
20375 r = -E2BIG;
20376 if (cpuid->nent < vcpu->arch.cpuid_nent)
20377 goto out;
20378 r = -EFAULT;
20379- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20380- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20381+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20382 goto out;
20383+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20384+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20385+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20386+ goto out;
20387+ }
20388 return 0;
20389
20390 out:
20391diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20392index 4837375..2cc9722 100644
20393--- a/arch/x86/kvm/emulate.c
20394+++ b/arch/x86/kvm/emulate.c
20395@@ -256,6 +256,7 @@ struct gprefix {
20396
20397 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20398 do { \
20399+ unsigned long _tmp; \
20400 __asm__ __volatile__ ( \
20401 _PRE_EFLAGS("0", "4", "2") \
20402 _op _suffix " %"_x"3,%1; " \
20403@@ -270,8 +271,6 @@ struct gprefix {
20404 /* Raw emulation: instruction has two explicit operands. */
20405 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20406 do { \
20407- unsigned long _tmp; \
20408- \
20409 switch ((ctxt)->dst.bytes) { \
20410 case 2: \
20411 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20412@@ -287,7 +286,6 @@ struct gprefix {
20413
20414 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20415 do { \
20416- unsigned long _tmp; \
20417 switch ((ctxt)->dst.bytes) { \
20418 case 1: \
20419 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20420diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20421index 93c1574..d6097dc 100644
20422--- a/arch/x86/kvm/lapic.c
20423+++ b/arch/x86/kvm/lapic.c
20424@@ -54,7 +54,7 @@
20425 #define APIC_BUS_CYCLE_NS 1
20426
20427 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20428-#define apic_debug(fmt, arg...)
20429+#define apic_debug(fmt, arg...) do {} while (0)
20430
20431 #define APIC_LVT_NUM 6
20432 /* 14 is the version for Xeon and Pentium 8.4.8*/
20433diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20434index 34f9709..8eca2d5 100644
20435--- a/arch/x86/kvm/paging_tmpl.h
20436+++ b/arch/x86/kvm/paging_tmpl.h
20437@@ -197,7 +197,7 @@ retry_walk:
20438 if (unlikely(kvm_is_error_hva(host_addr)))
20439 goto error;
20440
20441- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20442+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20443 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20444 goto error;
20445
20446diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20447index f75af40..285b18f 100644
20448--- a/arch/x86/kvm/svm.c
20449+++ b/arch/x86/kvm/svm.c
20450@@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20451 int cpu = raw_smp_processor_id();
20452
20453 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20454+
20455+ pax_open_kernel();
20456 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20457+ pax_close_kernel();
20458+
20459 load_TR_desc();
20460 }
20461
20462@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20463 #endif
20464 #endif
20465
20466+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20467+ __set_fs(current_thread_info()->addr_limit);
20468+#endif
20469+
20470 reload_tss(vcpu);
20471
20472 local_irq_disable();
20473diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20474index 86c8704..d9277bb 100644
20475--- a/arch/x86/kvm/vmx.c
20476+++ b/arch/x86/kvm/vmx.c
20477@@ -1317,7 +1317,11 @@ static void reload_tss(void)
20478 struct desc_struct *descs;
20479
20480 descs = (void *)gdt->address;
20481+
20482+ pax_open_kernel();
20483 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20484+ pax_close_kernel();
20485+
20486 load_TR_desc();
20487 }
20488
20489@@ -1527,6 +1531,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20490 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20491 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20492
20493+#ifdef CONFIG_PAX_PER_CPU_PGD
20494+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20495+#endif
20496+
20497 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20498 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20499 vmx->loaded_vmcs->cpu = cpu;
20500@@ -2650,8 +2658,11 @@ static __init int hardware_setup(void)
20501 if (!cpu_has_vmx_flexpriority())
20502 flexpriority_enabled = 0;
20503
20504- if (!cpu_has_vmx_tpr_shadow())
20505- kvm_x86_ops->update_cr8_intercept = NULL;
20506+ if (!cpu_has_vmx_tpr_shadow()) {
20507+ pax_open_kernel();
20508+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20509+ pax_close_kernel();
20510+ }
20511
20512 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20513 kvm_disable_largepages();
20514@@ -3697,7 +3708,10 @@ static void vmx_set_constant_host_state(void)
20515
20516 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20517 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20518+
20519+#ifndef CONFIG_PAX_PER_CPU_PGD
20520 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20521+#endif
20522
20523 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20524 #ifdef CONFIG_X86_64
20525@@ -3719,7 +3733,7 @@ static void vmx_set_constant_host_state(void)
20526 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20527
20528 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20529- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20530+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20531
20532 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20533 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20534@@ -6257,6 +6271,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20535 "jmp .Lkvm_vmx_return \n\t"
20536 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20537 ".Lkvm_vmx_return: "
20538+
20539+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20540+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20541+ ".Lkvm_vmx_return2: "
20542+#endif
20543+
20544 /* Save guest registers, load host registers, keep flags */
20545 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20546 "pop %0 \n\t"
20547@@ -6305,6 +6325,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20548 #endif
20549 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20550 [wordsize]"i"(sizeof(ulong))
20551+
20552+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20553+ ,[cs]"i"(__KERNEL_CS)
20554+#endif
20555+
20556 : "cc", "memory"
20557 , R"ax", R"bx", R"di", R"si"
20558 #ifdef CONFIG_X86_64
20559@@ -6312,7 +6337,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20560 #endif
20561 );
20562
20563-#ifndef CONFIG_X86_64
20564+#ifdef CONFIG_X86_32
20565 /*
20566 * The sysexit path does not restore ds/es, so we must set them to
20567 * a reasonable value ourselves.
20568@@ -6321,8 +6346,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20569 * may be executed in interrupt context, which saves and restore segments
20570 * around it, nullifying its effect.
20571 */
20572- loadsegment(ds, __USER_DS);
20573- loadsegment(es, __USER_DS);
20574+ loadsegment(ds, __KERNEL_DS);
20575+ loadsegment(es, __KERNEL_DS);
20576+ loadsegment(ss, __KERNEL_DS);
20577+
20578+#ifdef CONFIG_PAX_KERNEXEC
20579+ loadsegment(fs, __KERNEL_PERCPU);
20580+#endif
20581+
20582+#ifdef CONFIG_PAX_MEMORY_UDEREF
20583+ __set_fs(current_thread_info()->addr_limit);
20584+#endif
20585+
20586 #endif
20587
20588 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20589diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20590index 14c290d..0dae6e5 100644
20591--- a/arch/x86/kvm/x86.c
20592+++ b/arch/x86/kvm/x86.c
20593@@ -1361,8 +1361,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20594 {
20595 struct kvm *kvm = vcpu->kvm;
20596 int lm = is_long_mode(vcpu);
20597- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20598- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20599+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20600+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20601 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20602 : kvm->arch.xen_hvm_config.blob_size_32;
20603 u32 page_num = data & ~PAGE_MASK;
20604@@ -2218,6 +2218,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20605 if (n < msr_list.nmsrs)
20606 goto out;
20607 r = -EFAULT;
20608+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20609+ goto out;
20610 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20611 num_msrs_to_save * sizeof(u32)))
20612 goto out;
20613@@ -2343,7 +2345,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20614 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20615 struct kvm_interrupt *irq)
20616 {
20617- if (irq->irq < 0 || irq->irq >= 256)
20618+ if (irq->irq >= 256)
20619 return -EINVAL;
20620 if (irqchip_in_kernel(vcpu->kvm))
20621 return -ENXIO;
20622@@ -4880,7 +4882,7 @@ static void kvm_set_mmio_spte_mask(void)
20623 kvm_mmu_set_mmio_spte_mask(mask);
20624 }
20625
20626-int kvm_arch_init(void *opaque)
20627+int kvm_arch_init(const void *opaque)
20628 {
20629 int r;
20630 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20631diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20632index 642d880..cc9ebac 100644
20633--- a/arch/x86/lguest/boot.c
20634+++ b/arch/x86/lguest/boot.c
20635@@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20636
20637 static void set_lguest_basic_apic_ops(void)
20638 {
20639- apic->read = lguest_apic_read;
20640- apic->write = lguest_apic_write;
20641- apic->icr_read = lguest_apic_icr_read;
20642- apic->icr_write = lguest_apic_icr_write;
20643- apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20644- apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20645+ *(void **)&apic->read = lguest_apic_read;
20646+ *(void **)&apic->write = lguest_apic_write;
20647+ *(void **)&apic->icr_read = lguest_apic_icr_read;
20648+ *(void **)&apic->icr_write = lguest_apic_icr_write;
20649+ *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20650+ *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20651 };
20652 #endif
20653
20654@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20655 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20656 * Launcher to reboot us.
20657 */
20658-static void lguest_restart(char *reason)
20659+static __noreturn void lguest_restart(char *reason)
20660 {
20661 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20662+ BUG();
20663 }
20664
20665 /*G:050
20666diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20667index 00933d5..3a64af9 100644
20668--- a/arch/x86/lib/atomic64_386_32.S
20669+++ b/arch/x86/lib/atomic64_386_32.S
20670@@ -48,6 +48,10 @@ BEGIN(read)
20671 movl (v), %eax
20672 movl 4(v), %edx
20673 RET_ENDP
20674+BEGIN(read_unchecked)
20675+ movl (v), %eax
20676+ movl 4(v), %edx
20677+RET_ENDP
20678 #undef v
20679
20680 #define v %esi
20681@@ -55,6 +59,10 @@ BEGIN(set)
20682 movl %ebx, (v)
20683 movl %ecx, 4(v)
20684 RET_ENDP
20685+BEGIN(set_unchecked)
20686+ movl %ebx, (v)
20687+ movl %ecx, 4(v)
20688+RET_ENDP
20689 #undef v
20690
20691 #define v %esi
20692@@ -70,6 +78,20 @@ RET_ENDP
20693 BEGIN(add)
20694 addl %eax, (v)
20695 adcl %edx, 4(v)
20696+
20697+#ifdef CONFIG_PAX_REFCOUNT
20698+ jno 0f
20699+ subl %eax, (v)
20700+ sbbl %edx, 4(v)
20701+ int $4
20702+0:
20703+ _ASM_EXTABLE(0b, 0b)
20704+#endif
20705+
20706+RET_ENDP
20707+BEGIN(add_unchecked)
20708+ addl %eax, (v)
20709+ adcl %edx, 4(v)
20710 RET_ENDP
20711 #undef v
20712
20713@@ -77,6 +99,24 @@ RET_ENDP
20714 BEGIN(add_return)
20715 addl (v), %eax
20716 adcl 4(v), %edx
20717+
20718+#ifdef CONFIG_PAX_REFCOUNT
20719+ into
20720+1234:
20721+ _ASM_EXTABLE(1234b, 2f)
20722+#endif
20723+
20724+ movl %eax, (v)
20725+ movl %edx, 4(v)
20726+
20727+#ifdef CONFIG_PAX_REFCOUNT
20728+2:
20729+#endif
20730+
20731+RET_ENDP
20732+BEGIN(add_return_unchecked)
20733+ addl (v), %eax
20734+ adcl 4(v), %edx
20735 movl %eax, (v)
20736 movl %edx, 4(v)
20737 RET_ENDP
20738@@ -86,6 +126,20 @@ RET_ENDP
20739 BEGIN(sub)
20740 subl %eax, (v)
20741 sbbl %edx, 4(v)
20742+
20743+#ifdef CONFIG_PAX_REFCOUNT
20744+ jno 0f
20745+ addl %eax, (v)
20746+ adcl %edx, 4(v)
20747+ int $4
20748+0:
20749+ _ASM_EXTABLE(0b, 0b)
20750+#endif
20751+
20752+RET_ENDP
20753+BEGIN(sub_unchecked)
20754+ subl %eax, (v)
20755+ sbbl %edx, 4(v)
20756 RET_ENDP
20757 #undef v
20758
20759@@ -96,6 +150,27 @@ BEGIN(sub_return)
20760 sbbl $0, %edx
20761 addl (v), %eax
20762 adcl 4(v), %edx
20763+
20764+#ifdef CONFIG_PAX_REFCOUNT
20765+ into
20766+1234:
20767+ _ASM_EXTABLE(1234b, 2f)
20768+#endif
20769+
20770+ movl %eax, (v)
20771+ movl %edx, 4(v)
20772+
20773+#ifdef CONFIG_PAX_REFCOUNT
20774+2:
20775+#endif
20776+
20777+RET_ENDP
20778+BEGIN(sub_return_unchecked)
20779+ negl %edx
20780+ negl %eax
20781+ sbbl $0, %edx
20782+ addl (v), %eax
20783+ adcl 4(v), %edx
20784 movl %eax, (v)
20785 movl %edx, 4(v)
20786 RET_ENDP
20787@@ -105,6 +180,20 @@ RET_ENDP
20788 BEGIN(inc)
20789 addl $1, (v)
20790 adcl $0, 4(v)
20791+
20792+#ifdef CONFIG_PAX_REFCOUNT
20793+ jno 0f
20794+ subl $1, (v)
20795+ sbbl $0, 4(v)
20796+ int $4
20797+0:
20798+ _ASM_EXTABLE(0b, 0b)
20799+#endif
20800+
20801+RET_ENDP
20802+BEGIN(inc_unchecked)
20803+ addl $1, (v)
20804+ adcl $0, 4(v)
20805 RET_ENDP
20806 #undef v
20807
20808@@ -114,6 +203,26 @@ BEGIN(inc_return)
20809 movl 4(v), %edx
20810 addl $1, %eax
20811 adcl $0, %edx
20812+
20813+#ifdef CONFIG_PAX_REFCOUNT
20814+ into
20815+1234:
20816+ _ASM_EXTABLE(1234b, 2f)
20817+#endif
20818+
20819+ movl %eax, (v)
20820+ movl %edx, 4(v)
20821+
20822+#ifdef CONFIG_PAX_REFCOUNT
20823+2:
20824+#endif
20825+
20826+RET_ENDP
20827+BEGIN(inc_return_unchecked)
20828+ movl (v), %eax
20829+ movl 4(v), %edx
20830+ addl $1, %eax
20831+ adcl $0, %edx
20832 movl %eax, (v)
20833 movl %edx, 4(v)
20834 RET_ENDP
20835@@ -123,6 +232,20 @@ RET_ENDP
20836 BEGIN(dec)
20837 subl $1, (v)
20838 sbbl $0, 4(v)
20839+
20840+#ifdef CONFIG_PAX_REFCOUNT
20841+ jno 0f
20842+ addl $1, (v)
20843+ adcl $0, 4(v)
20844+ int $4
20845+0:
20846+ _ASM_EXTABLE(0b, 0b)
20847+#endif
20848+
20849+RET_ENDP
20850+BEGIN(dec_unchecked)
20851+ subl $1, (v)
20852+ sbbl $0, 4(v)
20853 RET_ENDP
20854 #undef v
20855
20856@@ -132,6 +255,26 @@ BEGIN(dec_return)
20857 movl 4(v), %edx
20858 subl $1, %eax
20859 sbbl $0, %edx
20860+
20861+#ifdef CONFIG_PAX_REFCOUNT
20862+ into
20863+1234:
20864+ _ASM_EXTABLE(1234b, 2f)
20865+#endif
20866+
20867+ movl %eax, (v)
20868+ movl %edx, 4(v)
20869+
20870+#ifdef CONFIG_PAX_REFCOUNT
20871+2:
20872+#endif
20873+
20874+RET_ENDP
20875+BEGIN(dec_return_unchecked)
20876+ movl (v), %eax
20877+ movl 4(v), %edx
20878+ subl $1, %eax
20879+ sbbl $0, %edx
20880 movl %eax, (v)
20881 movl %edx, 4(v)
20882 RET_ENDP
20883@@ -143,6 +286,13 @@ BEGIN(add_unless)
20884 adcl %edx, %edi
20885 addl (v), %eax
20886 adcl 4(v), %edx
20887+
20888+#ifdef CONFIG_PAX_REFCOUNT
20889+ into
20890+1234:
20891+ _ASM_EXTABLE(1234b, 2f)
20892+#endif
20893+
20894 cmpl %eax, %ecx
20895 je 3f
20896 1:
20897@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20898 1:
20899 addl $1, %eax
20900 adcl $0, %edx
20901+
20902+#ifdef CONFIG_PAX_REFCOUNT
20903+ into
20904+1234:
20905+ _ASM_EXTABLE(1234b, 2f)
20906+#endif
20907+
20908 movl %eax, (v)
20909 movl %edx, 4(v)
20910 movl $1, %eax
20911@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20912 movl 4(v), %edx
20913 subl $1, %eax
20914 sbbl $0, %edx
20915+
20916+#ifdef CONFIG_PAX_REFCOUNT
20917+ into
20918+1234:
20919+ _ASM_EXTABLE(1234b, 1f)
20920+#endif
20921+
20922 js 1f
20923 movl %eax, (v)
20924 movl %edx, 4(v)
20925diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20926index f5cc9eb..51fa319 100644
20927--- a/arch/x86/lib/atomic64_cx8_32.S
20928+++ b/arch/x86/lib/atomic64_cx8_32.S
20929@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20930 CFI_STARTPROC
20931
20932 read64 %ecx
20933+ pax_force_retaddr
20934 ret
20935 CFI_ENDPROC
20936 ENDPROC(atomic64_read_cx8)
20937
20938+ENTRY(atomic64_read_unchecked_cx8)
20939+ CFI_STARTPROC
20940+
20941+ read64 %ecx
20942+ pax_force_retaddr
20943+ ret
20944+ CFI_ENDPROC
20945+ENDPROC(atomic64_read_unchecked_cx8)
20946+
20947 ENTRY(atomic64_set_cx8)
20948 CFI_STARTPROC
20949
20950@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20951 cmpxchg8b (%esi)
20952 jne 1b
20953
20954+ pax_force_retaddr
20955 ret
20956 CFI_ENDPROC
20957 ENDPROC(atomic64_set_cx8)
20958
20959+ENTRY(atomic64_set_unchecked_cx8)
20960+ CFI_STARTPROC
20961+
20962+1:
20963+/* we don't need LOCK_PREFIX since aligned 64-bit writes
20964+ * are atomic on 586 and newer */
20965+ cmpxchg8b (%esi)
20966+ jne 1b
20967+
20968+ pax_force_retaddr
20969+ ret
20970+ CFI_ENDPROC
20971+ENDPROC(atomic64_set_unchecked_cx8)
20972+
20973 ENTRY(atomic64_xchg_cx8)
20974 CFI_STARTPROC
20975
20976@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20977 cmpxchg8b (%esi)
20978 jne 1b
20979
20980+ pax_force_retaddr
20981 ret
20982 CFI_ENDPROC
20983 ENDPROC(atomic64_xchg_cx8)
20984
20985-.macro addsub_return func ins insc
20986-ENTRY(atomic64_\func\()_return_cx8)
20987+.macro addsub_return func ins insc unchecked=""
20988+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20989 CFI_STARTPROC
20990 SAVE ebp
20991 SAVE ebx
20992@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20993 movl %edx, %ecx
20994 \ins\()l %esi, %ebx
20995 \insc\()l %edi, %ecx
20996+
20997+.ifb \unchecked
20998+#ifdef CONFIG_PAX_REFCOUNT
20999+ into
21000+2:
21001+ _ASM_EXTABLE(2b, 3f)
21002+#endif
21003+.endif
21004+
21005 LOCK_PREFIX
21006 cmpxchg8b (%ebp)
21007 jne 1b
21008-
21009-10:
21010 movl %ebx, %eax
21011 movl %ecx, %edx
21012+
21013+.ifb \unchecked
21014+#ifdef CONFIG_PAX_REFCOUNT
21015+3:
21016+#endif
21017+.endif
21018+
21019 RESTORE edi
21020 RESTORE esi
21021 RESTORE ebx
21022 RESTORE ebp
21023+ pax_force_retaddr
21024 ret
21025 CFI_ENDPROC
21026-ENDPROC(atomic64_\func\()_return_cx8)
21027+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21028 .endm
21029
21030 addsub_return add add adc
21031 addsub_return sub sub sbb
21032+addsub_return add add adc _unchecked
21033+addsub_return sub sub sbb _unchecked
21034
21035-.macro incdec_return func ins insc
21036-ENTRY(atomic64_\func\()_return_cx8)
21037+.macro incdec_return func ins insc unchecked=""
21038+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21039 CFI_STARTPROC
21040 SAVE ebx
21041
21042@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21043 movl %edx, %ecx
21044 \ins\()l $1, %ebx
21045 \insc\()l $0, %ecx
21046+
21047+.ifb \unchecked
21048+#ifdef CONFIG_PAX_REFCOUNT
21049+ into
21050+2:
21051+ _ASM_EXTABLE(2b, 3f)
21052+#endif
21053+.endif
21054+
21055 LOCK_PREFIX
21056 cmpxchg8b (%esi)
21057 jne 1b
21058
21059-10:
21060 movl %ebx, %eax
21061 movl %ecx, %edx
21062+
21063+.ifb \unchecked
21064+#ifdef CONFIG_PAX_REFCOUNT
21065+3:
21066+#endif
21067+.endif
21068+
21069 RESTORE ebx
21070+ pax_force_retaddr
21071 ret
21072 CFI_ENDPROC
21073-ENDPROC(atomic64_\func\()_return_cx8)
21074+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21075 .endm
21076
21077 incdec_return inc add adc
21078 incdec_return dec sub sbb
21079+incdec_return inc add adc _unchecked
21080+incdec_return dec sub sbb _unchecked
21081
21082 ENTRY(atomic64_dec_if_positive_cx8)
21083 CFI_STARTPROC
21084@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21085 movl %edx, %ecx
21086 subl $1, %ebx
21087 sbb $0, %ecx
21088+
21089+#ifdef CONFIG_PAX_REFCOUNT
21090+ into
21091+1234:
21092+ _ASM_EXTABLE(1234b, 2f)
21093+#endif
21094+
21095 js 2f
21096 LOCK_PREFIX
21097 cmpxchg8b (%esi)
21098@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21099 movl %ebx, %eax
21100 movl %ecx, %edx
21101 RESTORE ebx
21102+ pax_force_retaddr
21103 ret
21104 CFI_ENDPROC
21105 ENDPROC(atomic64_dec_if_positive_cx8)
21106@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21107 movl %edx, %ecx
21108 addl %ebp, %ebx
21109 adcl %edi, %ecx
21110+
21111+#ifdef CONFIG_PAX_REFCOUNT
21112+ into
21113+1234:
21114+ _ASM_EXTABLE(1234b, 3f)
21115+#endif
21116+
21117 LOCK_PREFIX
21118 cmpxchg8b (%esi)
21119 jne 1b
21120@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21121 CFI_ADJUST_CFA_OFFSET -8
21122 RESTORE ebx
21123 RESTORE ebp
21124+ pax_force_retaddr
21125 ret
21126 4:
21127 cmpl %edx, 4(%esp)
21128@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21129 xorl %ecx, %ecx
21130 addl $1, %ebx
21131 adcl %edx, %ecx
21132+
21133+#ifdef CONFIG_PAX_REFCOUNT
21134+ into
21135+1234:
21136+ _ASM_EXTABLE(1234b, 3f)
21137+#endif
21138+
21139 LOCK_PREFIX
21140 cmpxchg8b (%esi)
21141 jne 1b
21142@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21143 movl $1, %eax
21144 3:
21145 RESTORE ebx
21146+ pax_force_retaddr
21147 ret
21148 CFI_ENDPROC
21149 ENDPROC(atomic64_inc_not_zero_cx8)
21150diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21151index 2af5df3..62b1a5a 100644
21152--- a/arch/x86/lib/checksum_32.S
21153+++ b/arch/x86/lib/checksum_32.S
21154@@ -29,7 +29,8 @@
21155 #include <asm/dwarf2.h>
21156 #include <asm/errno.h>
21157 #include <asm/asm.h>
21158-
21159+#include <asm/segment.h>
21160+
21161 /*
21162 * computes a partial checksum, e.g. for TCP/UDP fragments
21163 */
21164@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21165
21166 #define ARGBASE 16
21167 #define FP 12
21168-
21169-ENTRY(csum_partial_copy_generic)
21170+
21171+ENTRY(csum_partial_copy_generic_to_user)
21172 CFI_STARTPROC
21173+
21174+#ifdef CONFIG_PAX_MEMORY_UDEREF
21175+ pushl_cfi %gs
21176+ popl_cfi %es
21177+ jmp csum_partial_copy_generic
21178+#endif
21179+
21180+ENTRY(csum_partial_copy_generic_from_user)
21181+
21182+#ifdef CONFIG_PAX_MEMORY_UDEREF
21183+ pushl_cfi %gs
21184+ popl_cfi %ds
21185+#endif
21186+
21187+ENTRY(csum_partial_copy_generic)
21188 subl $4,%esp
21189 CFI_ADJUST_CFA_OFFSET 4
21190 pushl_cfi %edi
21191@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21192 jmp 4f
21193 SRC(1: movw (%esi), %bx )
21194 addl $2, %esi
21195-DST( movw %bx, (%edi) )
21196+DST( movw %bx, %es:(%edi) )
21197 addl $2, %edi
21198 addw %bx, %ax
21199 adcl $0, %eax
21200@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21201 SRC(1: movl (%esi), %ebx )
21202 SRC( movl 4(%esi), %edx )
21203 adcl %ebx, %eax
21204-DST( movl %ebx, (%edi) )
21205+DST( movl %ebx, %es:(%edi) )
21206 adcl %edx, %eax
21207-DST( movl %edx, 4(%edi) )
21208+DST( movl %edx, %es:4(%edi) )
21209
21210 SRC( movl 8(%esi), %ebx )
21211 SRC( movl 12(%esi), %edx )
21212 adcl %ebx, %eax
21213-DST( movl %ebx, 8(%edi) )
21214+DST( movl %ebx, %es:8(%edi) )
21215 adcl %edx, %eax
21216-DST( movl %edx, 12(%edi) )
21217+DST( movl %edx, %es:12(%edi) )
21218
21219 SRC( movl 16(%esi), %ebx )
21220 SRC( movl 20(%esi), %edx )
21221 adcl %ebx, %eax
21222-DST( movl %ebx, 16(%edi) )
21223+DST( movl %ebx, %es:16(%edi) )
21224 adcl %edx, %eax
21225-DST( movl %edx, 20(%edi) )
21226+DST( movl %edx, %es:20(%edi) )
21227
21228 SRC( movl 24(%esi), %ebx )
21229 SRC( movl 28(%esi), %edx )
21230 adcl %ebx, %eax
21231-DST( movl %ebx, 24(%edi) )
21232+DST( movl %ebx, %es:24(%edi) )
21233 adcl %edx, %eax
21234-DST( movl %edx, 28(%edi) )
21235+DST( movl %edx, %es:28(%edi) )
21236
21237 lea 32(%esi), %esi
21238 lea 32(%edi), %edi
21239@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21240 shrl $2, %edx # This clears CF
21241 SRC(3: movl (%esi), %ebx )
21242 adcl %ebx, %eax
21243-DST( movl %ebx, (%edi) )
21244+DST( movl %ebx, %es:(%edi) )
21245 lea 4(%esi), %esi
21246 lea 4(%edi), %edi
21247 dec %edx
21248@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21249 jb 5f
21250 SRC( movw (%esi), %cx )
21251 leal 2(%esi), %esi
21252-DST( movw %cx, (%edi) )
21253+DST( movw %cx, %es:(%edi) )
21254 leal 2(%edi), %edi
21255 je 6f
21256 shll $16,%ecx
21257 SRC(5: movb (%esi), %cl )
21258-DST( movb %cl, (%edi) )
21259+DST( movb %cl, %es:(%edi) )
21260 6: addl %ecx, %eax
21261 adcl $0, %eax
21262 7:
21263@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21264
21265 6001:
21266 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21267- movl $-EFAULT, (%ebx)
21268+ movl $-EFAULT, %ss:(%ebx)
21269
21270 # zero the complete destination - computing the rest
21271 # is too much work
21272@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21273
21274 6002:
21275 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21276- movl $-EFAULT,(%ebx)
21277+ movl $-EFAULT,%ss:(%ebx)
21278 jmp 5000b
21279
21280 .previous
21281
21282+ pushl_cfi %ss
21283+ popl_cfi %ds
21284+ pushl_cfi %ss
21285+ popl_cfi %es
21286 popl_cfi %ebx
21287 CFI_RESTORE ebx
21288 popl_cfi %esi
21289@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21290 popl_cfi %ecx # equivalent to addl $4,%esp
21291 ret
21292 CFI_ENDPROC
21293-ENDPROC(csum_partial_copy_generic)
21294+ENDPROC(csum_partial_copy_generic_to_user)
21295
21296 #else
21297
21298 /* Version for PentiumII/PPro */
21299
21300 #define ROUND1(x) \
21301+ nop; nop; nop; \
21302 SRC(movl x(%esi), %ebx ) ; \
21303 addl %ebx, %eax ; \
21304- DST(movl %ebx, x(%edi) ) ;
21305+ DST(movl %ebx, %es:x(%edi)) ;
21306
21307 #define ROUND(x) \
21308+ nop; nop; nop; \
21309 SRC(movl x(%esi), %ebx ) ; \
21310 adcl %ebx, %eax ; \
21311- DST(movl %ebx, x(%edi) ) ;
21312+ DST(movl %ebx, %es:x(%edi)) ;
21313
21314 #define ARGBASE 12
21315-
21316-ENTRY(csum_partial_copy_generic)
21317+
21318+ENTRY(csum_partial_copy_generic_to_user)
21319 CFI_STARTPROC
21320+
21321+#ifdef CONFIG_PAX_MEMORY_UDEREF
21322+ pushl_cfi %gs
21323+ popl_cfi %es
21324+ jmp csum_partial_copy_generic
21325+#endif
21326+
21327+ENTRY(csum_partial_copy_generic_from_user)
21328+
21329+#ifdef CONFIG_PAX_MEMORY_UDEREF
21330+ pushl_cfi %gs
21331+ popl_cfi %ds
21332+#endif
21333+
21334+ENTRY(csum_partial_copy_generic)
21335 pushl_cfi %ebx
21336 CFI_REL_OFFSET ebx, 0
21337 pushl_cfi %edi
21338@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21339 subl %ebx, %edi
21340 lea -1(%esi),%edx
21341 andl $-32,%edx
21342- lea 3f(%ebx,%ebx), %ebx
21343+ lea 3f(%ebx,%ebx,2), %ebx
21344 testl %esi, %esi
21345 jmp *%ebx
21346 1: addl $64,%esi
21347@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21348 jb 5f
21349 SRC( movw (%esi), %dx )
21350 leal 2(%esi), %esi
21351-DST( movw %dx, (%edi) )
21352+DST( movw %dx, %es:(%edi) )
21353 leal 2(%edi), %edi
21354 je 6f
21355 shll $16,%edx
21356 5:
21357 SRC( movb (%esi), %dl )
21358-DST( movb %dl, (%edi) )
21359+DST( movb %dl, %es:(%edi) )
21360 6: addl %edx, %eax
21361 adcl $0, %eax
21362 7:
21363 .section .fixup, "ax"
21364 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21365- movl $-EFAULT, (%ebx)
21366+ movl $-EFAULT, %ss:(%ebx)
21367 # zero the complete destination (computing the rest is too much work)
21368 movl ARGBASE+8(%esp),%edi # dst
21369 movl ARGBASE+12(%esp),%ecx # len
21370@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21371 rep; stosb
21372 jmp 7b
21373 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21374- movl $-EFAULT, (%ebx)
21375+ movl $-EFAULT, %ss:(%ebx)
21376 jmp 7b
21377 .previous
21378
21379+#ifdef CONFIG_PAX_MEMORY_UDEREF
21380+ pushl_cfi %ss
21381+ popl_cfi %ds
21382+ pushl_cfi %ss
21383+ popl_cfi %es
21384+#endif
21385+
21386 popl_cfi %esi
21387 CFI_RESTORE esi
21388 popl_cfi %edi
21389@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21390 CFI_RESTORE ebx
21391 ret
21392 CFI_ENDPROC
21393-ENDPROC(csum_partial_copy_generic)
21394+ENDPROC(csum_partial_copy_generic_to_user)
21395
21396 #undef ROUND
21397 #undef ROUND1
21398diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21399index f2145cf..cea889d 100644
21400--- a/arch/x86/lib/clear_page_64.S
21401+++ b/arch/x86/lib/clear_page_64.S
21402@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21403 movl $4096/8,%ecx
21404 xorl %eax,%eax
21405 rep stosq
21406+ pax_force_retaddr
21407 ret
21408 CFI_ENDPROC
21409 ENDPROC(clear_page_c)
21410@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21411 movl $4096,%ecx
21412 xorl %eax,%eax
21413 rep stosb
21414+ pax_force_retaddr
21415 ret
21416 CFI_ENDPROC
21417 ENDPROC(clear_page_c_e)
21418@@ -43,6 +45,7 @@ ENTRY(clear_page)
21419 leaq 64(%rdi),%rdi
21420 jnz .Lloop
21421 nop
21422+ pax_force_retaddr
21423 ret
21424 CFI_ENDPROC
21425 .Lclear_page_end:
21426@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21427
21428 #include <asm/cpufeature.h>
21429
21430- .section .altinstr_replacement,"ax"
21431+ .section .altinstr_replacement,"a"
21432 1: .byte 0xeb /* jmp <disp8> */
21433 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21434 2: .byte 0xeb /* jmp <disp8> */
21435diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21436index 1e572c5..2a162cd 100644
21437--- a/arch/x86/lib/cmpxchg16b_emu.S
21438+++ b/arch/x86/lib/cmpxchg16b_emu.S
21439@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21440
21441 popf
21442 mov $1, %al
21443+ pax_force_retaddr
21444 ret
21445
21446 not_same:
21447 popf
21448 xor %al,%al
21449+ pax_force_retaddr
21450 ret
21451
21452 CFI_ENDPROC
21453diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21454index 6b34d04..dccb07f 100644
21455--- a/arch/x86/lib/copy_page_64.S
21456+++ b/arch/x86/lib/copy_page_64.S
21457@@ -9,6 +9,7 @@ copy_page_c:
21458 CFI_STARTPROC
21459 movl $4096/8,%ecx
21460 rep movsq
21461+ pax_force_retaddr
21462 ret
21463 CFI_ENDPROC
21464 ENDPROC(copy_page_c)
21465@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21466
21467 ENTRY(copy_page)
21468 CFI_STARTPROC
21469- subq $2*8,%rsp
21470- CFI_ADJUST_CFA_OFFSET 2*8
21471+ subq $3*8,%rsp
21472+ CFI_ADJUST_CFA_OFFSET 3*8
21473 movq %rbx,(%rsp)
21474 CFI_REL_OFFSET rbx, 0
21475 movq %r12,1*8(%rsp)
21476 CFI_REL_OFFSET r12, 1*8
21477+ movq %r13,2*8(%rsp)
21478+ CFI_REL_OFFSET r13, 2*8
21479
21480 movl $(4096/64)-5,%ecx
21481 .p2align 4
21482@@ -37,7 +40,7 @@ ENTRY(copy_page)
21483 movq 16 (%rsi), %rdx
21484 movq 24 (%rsi), %r8
21485 movq 32 (%rsi), %r9
21486- movq 40 (%rsi), %r10
21487+ movq 40 (%rsi), %r13
21488 movq 48 (%rsi), %r11
21489 movq 56 (%rsi), %r12
21490
21491@@ -48,7 +51,7 @@ ENTRY(copy_page)
21492 movq %rdx, 16 (%rdi)
21493 movq %r8, 24 (%rdi)
21494 movq %r9, 32 (%rdi)
21495- movq %r10, 40 (%rdi)
21496+ movq %r13, 40 (%rdi)
21497 movq %r11, 48 (%rdi)
21498 movq %r12, 56 (%rdi)
21499
21500@@ -67,7 +70,7 @@ ENTRY(copy_page)
21501 movq 16 (%rsi), %rdx
21502 movq 24 (%rsi), %r8
21503 movq 32 (%rsi), %r9
21504- movq 40 (%rsi), %r10
21505+ movq 40 (%rsi), %r13
21506 movq 48 (%rsi), %r11
21507 movq 56 (%rsi), %r12
21508
21509@@ -76,7 +79,7 @@ ENTRY(copy_page)
21510 movq %rdx, 16 (%rdi)
21511 movq %r8, 24 (%rdi)
21512 movq %r9, 32 (%rdi)
21513- movq %r10, 40 (%rdi)
21514+ movq %r13, 40 (%rdi)
21515 movq %r11, 48 (%rdi)
21516 movq %r12, 56 (%rdi)
21517
21518@@ -89,8 +92,11 @@ ENTRY(copy_page)
21519 CFI_RESTORE rbx
21520 movq 1*8(%rsp),%r12
21521 CFI_RESTORE r12
21522- addq $2*8,%rsp
21523- CFI_ADJUST_CFA_OFFSET -2*8
21524+ movq 2*8(%rsp),%r13
21525+ CFI_RESTORE r13
21526+ addq $3*8,%rsp
21527+ CFI_ADJUST_CFA_OFFSET -3*8
21528+ pax_force_retaddr
21529 ret
21530 .Lcopy_page_end:
21531 CFI_ENDPROC
21532@@ -101,7 +107,7 @@ ENDPROC(copy_page)
21533
21534 #include <asm/cpufeature.h>
21535
21536- .section .altinstr_replacement,"ax"
21537+ .section .altinstr_replacement,"a"
21538 1: .byte 0xeb /* jmp <disp8> */
21539 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21540 2:
21541diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21542index 5b2995f..78e7644 100644
21543--- a/arch/x86/lib/copy_user_64.S
21544+++ b/arch/x86/lib/copy_user_64.S
21545@@ -17,6 +17,7 @@
21546 #include <asm/cpufeature.h>
21547 #include <asm/alternative-asm.h>
21548 #include <asm/asm.h>
21549+#include <asm/pgtable.h>
21550
21551 /*
21552 * By placing feature2 after feature1 in altinstructions section, we logically
21553@@ -30,7 +31,7 @@
21554 .byte 0xe9 /* 32bit jump */
21555 .long \orig-1f /* by default jump to orig */
21556 1:
21557- .section .altinstr_replacement,"ax"
21558+ .section .altinstr_replacement,"a"
21559 2: .byte 0xe9 /* near jump with 32bit immediate */
21560 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21561 3: .byte 0xe9 /* near jump with 32bit immediate */
21562@@ -69,47 +70,20 @@
21563 #endif
21564 .endm
21565
21566-/* Standard copy_to_user with segment limit checking */
21567-ENTRY(_copy_to_user)
21568- CFI_STARTPROC
21569- GET_THREAD_INFO(%rax)
21570- movq %rdi,%rcx
21571- addq %rdx,%rcx
21572- jc bad_to_user
21573- cmpq TI_addr_limit(%rax),%rcx
21574- ja bad_to_user
21575- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21576- copy_user_generic_unrolled,copy_user_generic_string, \
21577- copy_user_enhanced_fast_string
21578- CFI_ENDPROC
21579-ENDPROC(_copy_to_user)
21580-
21581-/* Standard copy_from_user with segment limit checking */
21582-ENTRY(_copy_from_user)
21583- CFI_STARTPROC
21584- GET_THREAD_INFO(%rax)
21585- movq %rsi,%rcx
21586- addq %rdx,%rcx
21587- jc bad_from_user
21588- cmpq TI_addr_limit(%rax),%rcx
21589- ja bad_from_user
21590- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21591- copy_user_generic_unrolled,copy_user_generic_string, \
21592- copy_user_enhanced_fast_string
21593- CFI_ENDPROC
21594-ENDPROC(_copy_from_user)
21595-
21596 .section .fixup,"ax"
21597 /* must zero dest */
21598 ENTRY(bad_from_user)
21599 bad_from_user:
21600 CFI_STARTPROC
21601+ testl %edx,%edx
21602+ js bad_to_user
21603 movl %edx,%ecx
21604 xorl %eax,%eax
21605 rep
21606 stosb
21607 bad_to_user:
21608 movl %edx,%eax
21609+ pax_force_retaddr
21610 ret
21611 CFI_ENDPROC
21612 ENDPROC(bad_from_user)
21613@@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21614 jz 17f
21615 1: movq (%rsi),%r8
21616 2: movq 1*8(%rsi),%r9
21617-3: movq 2*8(%rsi),%r10
21618+3: movq 2*8(%rsi),%rax
21619 4: movq 3*8(%rsi),%r11
21620 5: movq %r8,(%rdi)
21621 6: movq %r9,1*8(%rdi)
21622-7: movq %r10,2*8(%rdi)
21623+7: movq %rax,2*8(%rdi)
21624 8: movq %r11,3*8(%rdi)
21625 9: movq 4*8(%rsi),%r8
21626 10: movq 5*8(%rsi),%r9
21627-11: movq 6*8(%rsi),%r10
21628+11: movq 6*8(%rsi),%rax
21629 12: movq 7*8(%rsi),%r11
21630 13: movq %r8,4*8(%rdi)
21631 14: movq %r9,5*8(%rdi)
21632-15: movq %r10,6*8(%rdi)
21633+15: movq %rax,6*8(%rdi)
21634 16: movq %r11,7*8(%rdi)
21635 leaq 64(%rsi),%rsi
21636 leaq 64(%rdi),%rdi
21637@@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21638 decl %ecx
21639 jnz 21b
21640 23: xor %eax,%eax
21641+ pax_force_retaddr
21642 ret
21643
21644 .section .fixup,"ax"
21645@@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21646 3: rep
21647 movsb
21648 4: xorl %eax,%eax
21649+ pax_force_retaddr
21650 ret
21651
21652 .section .fixup,"ax"
21653@@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21654 1: rep
21655 movsb
21656 2: xorl %eax,%eax
21657+ pax_force_retaddr
21658 ret
21659
21660 .section .fixup,"ax"
21661diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21662index cacddc7..09d49e4 100644
21663--- a/arch/x86/lib/copy_user_nocache_64.S
21664+++ b/arch/x86/lib/copy_user_nocache_64.S
21665@@ -8,6 +8,7 @@
21666
21667 #include <linux/linkage.h>
21668 #include <asm/dwarf2.h>
21669+#include <asm/alternative-asm.h>
21670
21671 #define FIX_ALIGNMENT 1
21672
21673@@ -15,6 +16,7 @@
21674 #include <asm/asm-offsets.h>
21675 #include <asm/thread_info.h>
21676 #include <asm/asm.h>
21677+#include <asm/pgtable.h>
21678
21679 .macro ALIGN_DESTINATION
21680 #ifdef FIX_ALIGNMENT
21681@@ -48,6 +50,15 @@
21682 */
21683 ENTRY(__copy_user_nocache)
21684 CFI_STARTPROC
21685+
21686+#ifdef CONFIG_PAX_MEMORY_UDEREF
21687+ mov $PAX_USER_SHADOW_BASE,%rcx
21688+ cmp %rcx,%rsi
21689+ jae 1f
21690+ add %rcx,%rsi
21691+1:
21692+#endif
21693+
21694 cmpl $8,%edx
21695 jb 20f /* less then 8 bytes, go to byte copy loop */
21696 ALIGN_DESTINATION
21697@@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21698 jz 17f
21699 1: movq (%rsi),%r8
21700 2: movq 1*8(%rsi),%r9
21701-3: movq 2*8(%rsi),%r10
21702+3: movq 2*8(%rsi),%rax
21703 4: movq 3*8(%rsi),%r11
21704 5: movnti %r8,(%rdi)
21705 6: movnti %r9,1*8(%rdi)
21706-7: movnti %r10,2*8(%rdi)
21707+7: movnti %rax,2*8(%rdi)
21708 8: movnti %r11,3*8(%rdi)
21709 9: movq 4*8(%rsi),%r8
21710 10: movq 5*8(%rsi),%r9
21711-11: movq 6*8(%rsi),%r10
21712+11: movq 6*8(%rsi),%rax
21713 12: movq 7*8(%rsi),%r11
21714 13: movnti %r8,4*8(%rdi)
21715 14: movnti %r9,5*8(%rdi)
21716-15: movnti %r10,6*8(%rdi)
21717+15: movnti %rax,6*8(%rdi)
21718 16: movnti %r11,7*8(%rdi)
21719 leaq 64(%rsi),%rsi
21720 leaq 64(%rdi),%rdi
21721@@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21722 jnz 21b
21723 23: xorl %eax,%eax
21724 sfence
21725+ pax_force_retaddr
21726 ret
21727
21728 .section .fixup,"ax"
21729diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21730index 2419d5f..953ee51 100644
21731--- a/arch/x86/lib/csum-copy_64.S
21732+++ b/arch/x86/lib/csum-copy_64.S
21733@@ -9,6 +9,7 @@
21734 #include <asm/dwarf2.h>
21735 #include <asm/errno.h>
21736 #include <asm/asm.h>
21737+#include <asm/alternative-asm.h>
21738
21739 /*
21740 * Checksum copy with exception handling.
21741@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21742 CFI_RESTORE rbp
21743 addq $7*8, %rsp
21744 CFI_ADJUST_CFA_OFFSET -7*8
21745+ pax_force_retaddr 0, 1
21746 ret
21747 CFI_RESTORE_STATE
21748
21749diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21750index 25b7ae8..3b52ccd 100644
21751--- a/arch/x86/lib/csum-wrappers_64.c
21752+++ b/arch/x86/lib/csum-wrappers_64.c
21753@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21754 len -= 2;
21755 }
21756 }
21757- isum = csum_partial_copy_generic((__force const void *)src,
21758+
21759+#ifdef CONFIG_PAX_MEMORY_UDEREF
21760+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21761+ src += PAX_USER_SHADOW_BASE;
21762+#endif
21763+
21764+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21765 dst, len, isum, errp, NULL);
21766 if (unlikely(*errp))
21767 goto out_err;
21768@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21769 }
21770
21771 *errp = 0;
21772- return csum_partial_copy_generic(src, (void __force *)dst,
21773+
21774+#ifdef CONFIG_PAX_MEMORY_UDEREF
21775+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21776+ dst += PAX_USER_SHADOW_BASE;
21777+#endif
21778+
21779+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21780 len, isum, NULL, errp);
21781 }
21782 EXPORT_SYMBOL(csum_partial_copy_to_user);
21783diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21784index b33b1fb..219f389 100644
21785--- a/arch/x86/lib/getuser.S
21786+++ b/arch/x86/lib/getuser.S
21787@@ -33,15 +33,38 @@
21788 #include <asm/asm-offsets.h>
21789 #include <asm/thread_info.h>
21790 #include <asm/asm.h>
21791+#include <asm/segment.h>
21792+#include <asm/pgtable.h>
21793+#include <asm/alternative-asm.h>
21794+
21795+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21796+#define __copyuser_seg gs;
21797+#else
21798+#define __copyuser_seg
21799+#endif
21800
21801 .text
21802 ENTRY(__get_user_1)
21803 CFI_STARTPROC
21804+
21805+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21806 GET_THREAD_INFO(%_ASM_DX)
21807 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21808 jae bad_get_user
21809-1: movzb (%_ASM_AX),%edx
21810+
21811+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21812+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21813+ cmp %_ASM_DX,%_ASM_AX
21814+ jae 1234f
21815+ add %_ASM_DX,%_ASM_AX
21816+1234:
21817+#endif
21818+
21819+#endif
21820+
21821+1: __copyuser_seg movzb (%_ASM_AX),%edx
21822 xor %eax,%eax
21823+ pax_force_retaddr
21824 ret
21825 CFI_ENDPROC
21826 ENDPROC(__get_user_1)
21827@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21828 ENTRY(__get_user_2)
21829 CFI_STARTPROC
21830 add $1,%_ASM_AX
21831+
21832+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21833 jc bad_get_user
21834 GET_THREAD_INFO(%_ASM_DX)
21835 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21836 jae bad_get_user
21837-2: movzwl -1(%_ASM_AX),%edx
21838+
21839+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21840+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21841+ cmp %_ASM_DX,%_ASM_AX
21842+ jae 1234f
21843+ add %_ASM_DX,%_ASM_AX
21844+1234:
21845+#endif
21846+
21847+#endif
21848+
21849+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21850 xor %eax,%eax
21851+ pax_force_retaddr
21852 ret
21853 CFI_ENDPROC
21854 ENDPROC(__get_user_2)
21855@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21856 ENTRY(__get_user_4)
21857 CFI_STARTPROC
21858 add $3,%_ASM_AX
21859+
21860+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21861 jc bad_get_user
21862 GET_THREAD_INFO(%_ASM_DX)
21863 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21864 jae bad_get_user
21865-3: mov -3(%_ASM_AX),%edx
21866+
21867+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21868+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21869+ cmp %_ASM_DX,%_ASM_AX
21870+ jae 1234f
21871+ add %_ASM_DX,%_ASM_AX
21872+1234:
21873+#endif
21874+
21875+#endif
21876+
21877+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21878 xor %eax,%eax
21879+ pax_force_retaddr
21880 ret
21881 CFI_ENDPROC
21882 ENDPROC(__get_user_4)
21883@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21884 GET_THREAD_INFO(%_ASM_DX)
21885 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21886 jae bad_get_user
21887+
21888+#ifdef CONFIG_PAX_MEMORY_UDEREF
21889+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21890+ cmp %_ASM_DX,%_ASM_AX
21891+ jae 1234f
21892+ add %_ASM_DX,%_ASM_AX
21893+1234:
21894+#endif
21895+
21896 4: movq -7(%_ASM_AX),%_ASM_DX
21897 xor %eax,%eax
21898+ pax_force_retaddr
21899 ret
21900 CFI_ENDPROC
21901 ENDPROC(__get_user_8)
21902@@ -91,6 +152,7 @@ bad_get_user:
21903 CFI_STARTPROC
21904 xor %edx,%edx
21905 mov $(-EFAULT),%_ASM_AX
21906+ pax_force_retaddr
21907 ret
21908 CFI_ENDPROC
21909 END(bad_get_user)
21910diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21911index b1e6c4b..21ae8fc 100644
21912--- a/arch/x86/lib/insn.c
21913+++ b/arch/x86/lib/insn.c
21914@@ -21,6 +21,11 @@
21915 #include <linux/string.h>
21916 #include <asm/inat.h>
21917 #include <asm/insn.h>
21918+#ifdef __KERNEL__
21919+#include <asm/pgtable_types.h>
21920+#else
21921+#define ktla_ktva(addr) addr
21922+#endif
21923
21924 /* Verify next sizeof(t) bytes can be on the same instruction */
21925 #define validate_next(t, insn, n) \
21926@@ -49,8 +54,8 @@
21927 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21928 {
21929 memset(insn, 0, sizeof(*insn));
21930- insn->kaddr = kaddr;
21931- insn->next_byte = kaddr;
21932+ insn->kaddr = ktla_ktva(kaddr);
21933+ insn->next_byte = ktla_ktva(kaddr);
21934 insn->x86_64 = x86_64 ? 1 : 0;
21935 insn->opnd_bytes = 4;
21936 if (x86_64)
21937diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21938index 05a95e7..326f2fa 100644
21939--- a/arch/x86/lib/iomap_copy_64.S
21940+++ b/arch/x86/lib/iomap_copy_64.S
21941@@ -17,6 +17,7 @@
21942
21943 #include <linux/linkage.h>
21944 #include <asm/dwarf2.h>
21945+#include <asm/alternative-asm.h>
21946
21947 /*
21948 * override generic version in lib/iomap_copy.c
21949@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21950 CFI_STARTPROC
21951 movl %edx,%ecx
21952 rep movsd
21953+ pax_force_retaddr
21954 ret
21955 CFI_ENDPROC
21956 ENDPROC(__iowrite32_copy)
21957diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21958index 1c273be..da9cc0e 100644
21959--- a/arch/x86/lib/memcpy_64.S
21960+++ b/arch/x86/lib/memcpy_64.S
21961@@ -33,6 +33,7 @@
21962 rep movsq
21963 movl %edx, %ecx
21964 rep movsb
21965+ pax_force_retaddr
21966 ret
21967 .Lmemcpy_e:
21968 .previous
21969@@ -49,6 +50,7 @@
21970 movq %rdi, %rax
21971 movq %rdx, %rcx
21972 rep movsb
21973+ pax_force_retaddr
21974 ret
21975 .Lmemcpy_e_e:
21976 .previous
21977@@ -76,13 +78,13 @@ ENTRY(memcpy)
21978 */
21979 movq 0*8(%rsi), %r8
21980 movq 1*8(%rsi), %r9
21981- movq 2*8(%rsi), %r10
21982+ movq 2*8(%rsi), %rcx
21983 movq 3*8(%rsi), %r11
21984 leaq 4*8(%rsi), %rsi
21985
21986 movq %r8, 0*8(%rdi)
21987 movq %r9, 1*8(%rdi)
21988- movq %r10, 2*8(%rdi)
21989+ movq %rcx, 2*8(%rdi)
21990 movq %r11, 3*8(%rdi)
21991 leaq 4*8(%rdi), %rdi
21992 jae .Lcopy_forward_loop
21993@@ -105,12 +107,12 @@ ENTRY(memcpy)
21994 subq $0x20, %rdx
21995 movq -1*8(%rsi), %r8
21996 movq -2*8(%rsi), %r9
21997- movq -3*8(%rsi), %r10
21998+ movq -3*8(%rsi), %rcx
21999 movq -4*8(%rsi), %r11
22000 leaq -4*8(%rsi), %rsi
22001 movq %r8, -1*8(%rdi)
22002 movq %r9, -2*8(%rdi)
22003- movq %r10, -3*8(%rdi)
22004+ movq %rcx, -3*8(%rdi)
22005 movq %r11, -4*8(%rdi)
22006 leaq -4*8(%rdi), %rdi
22007 jae .Lcopy_backward_loop
22008@@ -130,12 +132,13 @@ ENTRY(memcpy)
22009 */
22010 movq 0*8(%rsi), %r8
22011 movq 1*8(%rsi), %r9
22012- movq -2*8(%rsi, %rdx), %r10
22013+ movq -2*8(%rsi, %rdx), %rcx
22014 movq -1*8(%rsi, %rdx), %r11
22015 movq %r8, 0*8(%rdi)
22016 movq %r9, 1*8(%rdi)
22017- movq %r10, -2*8(%rdi, %rdx)
22018+ movq %rcx, -2*8(%rdi, %rdx)
22019 movq %r11, -1*8(%rdi, %rdx)
22020+ pax_force_retaddr
22021 retq
22022 .p2align 4
22023 .Lless_16bytes:
22024@@ -148,6 +151,7 @@ ENTRY(memcpy)
22025 movq -1*8(%rsi, %rdx), %r9
22026 movq %r8, 0*8(%rdi)
22027 movq %r9, -1*8(%rdi, %rdx)
22028+ pax_force_retaddr
22029 retq
22030 .p2align 4
22031 .Lless_8bytes:
22032@@ -161,6 +165,7 @@ ENTRY(memcpy)
22033 movl -4(%rsi, %rdx), %r8d
22034 movl %ecx, (%rdi)
22035 movl %r8d, -4(%rdi, %rdx)
22036+ pax_force_retaddr
22037 retq
22038 .p2align 4
22039 .Lless_3bytes:
22040@@ -179,6 +184,7 @@ ENTRY(memcpy)
22041 movb %cl, (%rdi)
22042
22043 .Lend:
22044+ pax_force_retaddr
22045 retq
22046 CFI_ENDPROC
22047 ENDPROC(memcpy)
22048diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22049index ee16461..c39c199 100644
22050--- a/arch/x86/lib/memmove_64.S
22051+++ b/arch/x86/lib/memmove_64.S
22052@@ -61,13 +61,13 @@ ENTRY(memmove)
22053 5:
22054 sub $0x20, %rdx
22055 movq 0*8(%rsi), %r11
22056- movq 1*8(%rsi), %r10
22057+ movq 1*8(%rsi), %rcx
22058 movq 2*8(%rsi), %r9
22059 movq 3*8(%rsi), %r8
22060 leaq 4*8(%rsi), %rsi
22061
22062 movq %r11, 0*8(%rdi)
22063- movq %r10, 1*8(%rdi)
22064+ movq %rcx, 1*8(%rdi)
22065 movq %r9, 2*8(%rdi)
22066 movq %r8, 3*8(%rdi)
22067 leaq 4*8(%rdi), %rdi
22068@@ -81,10 +81,10 @@ ENTRY(memmove)
22069 4:
22070 movq %rdx, %rcx
22071 movq -8(%rsi, %rdx), %r11
22072- lea -8(%rdi, %rdx), %r10
22073+ lea -8(%rdi, %rdx), %r9
22074 shrq $3, %rcx
22075 rep movsq
22076- movq %r11, (%r10)
22077+ movq %r11, (%r9)
22078 jmp 13f
22079 .Lmemmove_end_forward:
22080
22081@@ -95,14 +95,14 @@ ENTRY(memmove)
22082 7:
22083 movq %rdx, %rcx
22084 movq (%rsi), %r11
22085- movq %rdi, %r10
22086+ movq %rdi, %r9
22087 leaq -8(%rsi, %rdx), %rsi
22088 leaq -8(%rdi, %rdx), %rdi
22089 shrq $3, %rcx
22090 std
22091 rep movsq
22092 cld
22093- movq %r11, (%r10)
22094+ movq %r11, (%r9)
22095 jmp 13f
22096
22097 /*
22098@@ -127,13 +127,13 @@ ENTRY(memmove)
22099 8:
22100 subq $0x20, %rdx
22101 movq -1*8(%rsi), %r11
22102- movq -2*8(%rsi), %r10
22103+ movq -2*8(%rsi), %rcx
22104 movq -3*8(%rsi), %r9
22105 movq -4*8(%rsi), %r8
22106 leaq -4*8(%rsi), %rsi
22107
22108 movq %r11, -1*8(%rdi)
22109- movq %r10, -2*8(%rdi)
22110+ movq %rcx, -2*8(%rdi)
22111 movq %r9, -3*8(%rdi)
22112 movq %r8, -4*8(%rdi)
22113 leaq -4*8(%rdi), %rdi
22114@@ -151,11 +151,11 @@ ENTRY(memmove)
22115 * Move data from 16 bytes to 31 bytes.
22116 */
22117 movq 0*8(%rsi), %r11
22118- movq 1*8(%rsi), %r10
22119+ movq 1*8(%rsi), %rcx
22120 movq -2*8(%rsi, %rdx), %r9
22121 movq -1*8(%rsi, %rdx), %r8
22122 movq %r11, 0*8(%rdi)
22123- movq %r10, 1*8(%rdi)
22124+ movq %rcx, 1*8(%rdi)
22125 movq %r9, -2*8(%rdi, %rdx)
22126 movq %r8, -1*8(%rdi, %rdx)
22127 jmp 13f
22128@@ -167,9 +167,9 @@ ENTRY(memmove)
22129 * Move data from 8 bytes to 15 bytes.
22130 */
22131 movq 0*8(%rsi), %r11
22132- movq -1*8(%rsi, %rdx), %r10
22133+ movq -1*8(%rsi, %rdx), %r9
22134 movq %r11, 0*8(%rdi)
22135- movq %r10, -1*8(%rdi, %rdx)
22136+ movq %r9, -1*8(%rdi, %rdx)
22137 jmp 13f
22138 10:
22139 cmpq $4, %rdx
22140@@ -178,9 +178,9 @@ ENTRY(memmove)
22141 * Move data from 4 bytes to 7 bytes.
22142 */
22143 movl (%rsi), %r11d
22144- movl -4(%rsi, %rdx), %r10d
22145+ movl -4(%rsi, %rdx), %r9d
22146 movl %r11d, (%rdi)
22147- movl %r10d, -4(%rdi, %rdx)
22148+ movl %r9d, -4(%rdi, %rdx)
22149 jmp 13f
22150 11:
22151 cmp $2, %rdx
22152@@ -189,9 +189,9 @@ ENTRY(memmove)
22153 * Move data from 2 bytes to 3 bytes.
22154 */
22155 movw (%rsi), %r11w
22156- movw -2(%rsi, %rdx), %r10w
22157+ movw -2(%rsi, %rdx), %r9w
22158 movw %r11w, (%rdi)
22159- movw %r10w, -2(%rdi, %rdx)
22160+ movw %r9w, -2(%rdi, %rdx)
22161 jmp 13f
22162 12:
22163 cmp $1, %rdx
22164@@ -202,6 +202,7 @@ ENTRY(memmove)
22165 movb (%rsi), %r11b
22166 movb %r11b, (%rdi)
22167 13:
22168+ pax_force_retaddr
22169 retq
22170 CFI_ENDPROC
22171
22172@@ -210,6 +211,7 @@ ENTRY(memmove)
22173 /* Forward moving data. */
22174 movq %rdx, %rcx
22175 rep movsb
22176+ pax_force_retaddr
22177 retq
22178 .Lmemmove_end_forward_efs:
22179 .previous
22180diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22181index 2dcb380..963660a 100644
22182--- a/arch/x86/lib/memset_64.S
22183+++ b/arch/x86/lib/memset_64.S
22184@@ -30,6 +30,7 @@
22185 movl %edx,%ecx
22186 rep stosb
22187 movq %r9,%rax
22188+ pax_force_retaddr
22189 ret
22190 .Lmemset_e:
22191 .previous
22192@@ -52,6 +53,7 @@
22193 movq %rdx,%rcx
22194 rep stosb
22195 movq %r9,%rax
22196+ pax_force_retaddr
22197 ret
22198 .Lmemset_e_e:
22199 .previous
22200@@ -59,7 +61,7 @@
22201 ENTRY(memset)
22202 ENTRY(__memset)
22203 CFI_STARTPROC
22204- movq %rdi,%r10
22205+ movq %rdi,%r11
22206
22207 /* expand byte value */
22208 movzbl %sil,%ecx
22209@@ -117,7 +119,8 @@ ENTRY(__memset)
22210 jnz .Lloop_1
22211
22212 .Lende:
22213- movq %r10,%rax
22214+ movq %r11,%rax
22215+ pax_force_retaddr
22216 ret
22217
22218 CFI_RESTORE_STATE
22219diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22220index c9f2d9b..e7fd2c0 100644
22221--- a/arch/x86/lib/mmx_32.c
22222+++ b/arch/x86/lib/mmx_32.c
22223@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22224 {
22225 void *p;
22226 int i;
22227+ unsigned long cr0;
22228
22229 if (unlikely(in_interrupt()))
22230 return __memcpy(to, from, len);
22231@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22232 kernel_fpu_begin();
22233
22234 __asm__ __volatile__ (
22235- "1: prefetch (%0)\n" /* This set is 28 bytes */
22236- " prefetch 64(%0)\n"
22237- " prefetch 128(%0)\n"
22238- " prefetch 192(%0)\n"
22239- " prefetch 256(%0)\n"
22240+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22241+ " prefetch 64(%1)\n"
22242+ " prefetch 128(%1)\n"
22243+ " prefetch 192(%1)\n"
22244+ " prefetch 256(%1)\n"
22245 "2: \n"
22246 ".section .fixup, \"ax\"\n"
22247- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22248+ "3: \n"
22249+
22250+#ifdef CONFIG_PAX_KERNEXEC
22251+ " movl %%cr0, %0\n"
22252+ " movl %0, %%eax\n"
22253+ " andl $0xFFFEFFFF, %%eax\n"
22254+ " movl %%eax, %%cr0\n"
22255+#endif
22256+
22257+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22258+
22259+#ifdef CONFIG_PAX_KERNEXEC
22260+ " movl %0, %%cr0\n"
22261+#endif
22262+
22263 " jmp 2b\n"
22264 ".previous\n"
22265 _ASM_EXTABLE(1b, 3b)
22266- : : "r" (from));
22267+ : "=&r" (cr0) : "r" (from) : "ax");
22268
22269 for ( ; i > 5; i--) {
22270 __asm__ __volatile__ (
22271- "1: prefetch 320(%0)\n"
22272- "2: movq (%0), %%mm0\n"
22273- " movq 8(%0), %%mm1\n"
22274- " movq 16(%0), %%mm2\n"
22275- " movq 24(%0), %%mm3\n"
22276- " movq %%mm0, (%1)\n"
22277- " movq %%mm1, 8(%1)\n"
22278- " movq %%mm2, 16(%1)\n"
22279- " movq %%mm3, 24(%1)\n"
22280- " movq 32(%0), %%mm0\n"
22281- " movq 40(%0), %%mm1\n"
22282- " movq 48(%0), %%mm2\n"
22283- " movq 56(%0), %%mm3\n"
22284- " movq %%mm0, 32(%1)\n"
22285- " movq %%mm1, 40(%1)\n"
22286- " movq %%mm2, 48(%1)\n"
22287- " movq %%mm3, 56(%1)\n"
22288+ "1: prefetch 320(%1)\n"
22289+ "2: movq (%1), %%mm0\n"
22290+ " movq 8(%1), %%mm1\n"
22291+ " movq 16(%1), %%mm2\n"
22292+ " movq 24(%1), %%mm3\n"
22293+ " movq %%mm0, (%2)\n"
22294+ " movq %%mm1, 8(%2)\n"
22295+ " movq %%mm2, 16(%2)\n"
22296+ " movq %%mm3, 24(%2)\n"
22297+ " movq 32(%1), %%mm0\n"
22298+ " movq 40(%1), %%mm1\n"
22299+ " movq 48(%1), %%mm2\n"
22300+ " movq 56(%1), %%mm3\n"
22301+ " movq %%mm0, 32(%2)\n"
22302+ " movq %%mm1, 40(%2)\n"
22303+ " movq %%mm2, 48(%2)\n"
22304+ " movq %%mm3, 56(%2)\n"
22305 ".section .fixup, \"ax\"\n"
22306- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22307+ "3:\n"
22308+
22309+#ifdef CONFIG_PAX_KERNEXEC
22310+ " movl %%cr0, %0\n"
22311+ " movl %0, %%eax\n"
22312+ " andl $0xFFFEFFFF, %%eax\n"
22313+ " movl %%eax, %%cr0\n"
22314+#endif
22315+
22316+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22317+
22318+#ifdef CONFIG_PAX_KERNEXEC
22319+ " movl %0, %%cr0\n"
22320+#endif
22321+
22322 " jmp 2b\n"
22323 ".previous\n"
22324 _ASM_EXTABLE(1b, 3b)
22325- : : "r" (from), "r" (to) : "memory");
22326+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22327
22328 from += 64;
22329 to += 64;
22330@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22331 static void fast_copy_page(void *to, void *from)
22332 {
22333 int i;
22334+ unsigned long cr0;
22335
22336 kernel_fpu_begin();
22337
22338@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22339 * but that is for later. -AV
22340 */
22341 __asm__ __volatile__(
22342- "1: prefetch (%0)\n"
22343- " prefetch 64(%0)\n"
22344- " prefetch 128(%0)\n"
22345- " prefetch 192(%0)\n"
22346- " prefetch 256(%0)\n"
22347+ "1: prefetch (%1)\n"
22348+ " prefetch 64(%1)\n"
22349+ " prefetch 128(%1)\n"
22350+ " prefetch 192(%1)\n"
22351+ " prefetch 256(%1)\n"
22352 "2: \n"
22353 ".section .fixup, \"ax\"\n"
22354- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22355+ "3: \n"
22356+
22357+#ifdef CONFIG_PAX_KERNEXEC
22358+ " movl %%cr0, %0\n"
22359+ " movl %0, %%eax\n"
22360+ " andl $0xFFFEFFFF, %%eax\n"
22361+ " movl %%eax, %%cr0\n"
22362+#endif
22363+
22364+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22365+
22366+#ifdef CONFIG_PAX_KERNEXEC
22367+ " movl %0, %%cr0\n"
22368+#endif
22369+
22370 " jmp 2b\n"
22371 ".previous\n"
22372- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22373+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22374
22375 for (i = 0; i < (4096-320)/64; i++) {
22376 __asm__ __volatile__ (
22377- "1: prefetch 320(%0)\n"
22378- "2: movq (%0), %%mm0\n"
22379- " movntq %%mm0, (%1)\n"
22380- " movq 8(%0), %%mm1\n"
22381- " movntq %%mm1, 8(%1)\n"
22382- " movq 16(%0), %%mm2\n"
22383- " movntq %%mm2, 16(%1)\n"
22384- " movq 24(%0), %%mm3\n"
22385- " movntq %%mm3, 24(%1)\n"
22386- " movq 32(%0), %%mm4\n"
22387- " movntq %%mm4, 32(%1)\n"
22388- " movq 40(%0), %%mm5\n"
22389- " movntq %%mm5, 40(%1)\n"
22390- " movq 48(%0), %%mm6\n"
22391- " movntq %%mm6, 48(%1)\n"
22392- " movq 56(%0), %%mm7\n"
22393- " movntq %%mm7, 56(%1)\n"
22394+ "1: prefetch 320(%1)\n"
22395+ "2: movq (%1), %%mm0\n"
22396+ " movntq %%mm0, (%2)\n"
22397+ " movq 8(%1), %%mm1\n"
22398+ " movntq %%mm1, 8(%2)\n"
22399+ " movq 16(%1), %%mm2\n"
22400+ " movntq %%mm2, 16(%2)\n"
22401+ " movq 24(%1), %%mm3\n"
22402+ " movntq %%mm3, 24(%2)\n"
22403+ " movq 32(%1), %%mm4\n"
22404+ " movntq %%mm4, 32(%2)\n"
22405+ " movq 40(%1), %%mm5\n"
22406+ " movntq %%mm5, 40(%2)\n"
22407+ " movq 48(%1), %%mm6\n"
22408+ " movntq %%mm6, 48(%2)\n"
22409+ " movq 56(%1), %%mm7\n"
22410+ " movntq %%mm7, 56(%2)\n"
22411 ".section .fixup, \"ax\"\n"
22412- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22413+ "3:\n"
22414+
22415+#ifdef CONFIG_PAX_KERNEXEC
22416+ " movl %%cr0, %0\n"
22417+ " movl %0, %%eax\n"
22418+ " andl $0xFFFEFFFF, %%eax\n"
22419+ " movl %%eax, %%cr0\n"
22420+#endif
22421+
22422+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22423+
22424+#ifdef CONFIG_PAX_KERNEXEC
22425+ " movl %0, %%cr0\n"
22426+#endif
22427+
22428 " jmp 2b\n"
22429 ".previous\n"
22430- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22431+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22432
22433 from += 64;
22434 to += 64;
22435@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22436 static void fast_copy_page(void *to, void *from)
22437 {
22438 int i;
22439+ unsigned long cr0;
22440
22441 kernel_fpu_begin();
22442
22443 __asm__ __volatile__ (
22444- "1: prefetch (%0)\n"
22445- " prefetch 64(%0)\n"
22446- " prefetch 128(%0)\n"
22447- " prefetch 192(%0)\n"
22448- " prefetch 256(%0)\n"
22449+ "1: prefetch (%1)\n"
22450+ " prefetch 64(%1)\n"
22451+ " prefetch 128(%1)\n"
22452+ " prefetch 192(%1)\n"
22453+ " prefetch 256(%1)\n"
22454 "2: \n"
22455 ".section .fixup, \"ax\"\n"
22456- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22457+ "3: \n"
22458+
22459+#ifdef CONFIG_PAX_KERNEXEC
22460+ " movl %%cr0, %0\n"
22461+ " movl %0, %%eax\n"
22462+ " andl $0xFFFEFFFF, %%eax\n"
22463+ " movl %%eax, %%cr0\n"
22464+#endif
22465+
22466+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22467+
22468+#ifdef CONFIG_PAX_KERNEXEC
22469+ " movl %0, %%cr0\n"
22470+#endif
22471+
22472 " jmp 2b\n"
22473 ".previous\n"
22474- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22475+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22476
22477 for (i = 0; i < 4096/64; i++) {
22478 __asm__ __volatile__ (
22479- "1: prefetch 320(%0)\n"
22480- "2: movq (%0), %%mm0\n"
22481- " movq 8(%0), %%mm1\n"
22482- " movq 16(%0), %%mm2\n"
22483- " movq 24(%0), %%mm3\n"
22484- " movq %%mm0, (%1)\n"
22485- " movq %%mm1, 8(%1)\n"
22486- " movq %%mm2, 16(%1)\n"
22487- " movq %%mm3, 24(%1)\n"
22488- " movq 32(%0), %%mm0\n"
22489- " movq 40(%0), %%mm1\n"
22490- " movq 48(%0), %%mm2\n"
22491- " movq 56(%0), %%mm3\n"
22492- " movq %%mm0, 32(%1)\n"
22493- " movq %%mm1, 40(%1)\n"
22494- " movq %%mm2, 48(%1)\n"
22495- " movq %%mm3, 56(%1)\n"
22496+ "1: prefetch 320(%1)\n"
22497+ "2: movq (%1), %%mm0\n"
22498+ " movq 8(%1), %%mm1\n"
22499+ " movq 16(%1), %%mm2\n"
22500+ " movq 24(%1), %%mm3\n"
22501+ " movq %%mm0, (%2)\n"
22502+ " movq %%mm1, 8(%2)\n"
22503+ " movq %%mm2, 16(%2)\n"
22504+ " movq %%mm3, 24(%2)\n"
22505+ " movq 32(%1), %%mm0\n"
22506+ " movq 40(%1), %%mm1\n"
22507+ " movq 48(%1), %%mm2\n"
22508+ " movq 56(%1), %%mm3\n"
22509+ " movq %%mm0, 32(%2)\n"
22510+ " movq %%mm1, 40(%2)\n"
22511+ " movq %%mm2, 48(%2)\n"
22512+ " movq %%mm3, 56(%2)\n"
22513 ".section .fixup, \"ax\"\n"
22514- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22515+ "3:\n"
22516+
22517+#ifdef CONFIG_PAX_KERNEXEC
22518+ " movl %%cr0, %0\n"
22519+ " movl %0, %%eax\n"
22520+ " andl $0xFFFEFFFF, %%eax\n"
22521+ " movl %%eax, %%cr0\n"
22522+#endif
22523+
22524+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22525+
22526+#ifdef CONFIG_PAX_KERNEXEC
22527+ " movl %0, %%cr0\n"
22528+#endif
22529+
22530 " jmp 2b\n"
22531 ".previous\n"
22532 _ASM_EXTABLE(1b, 3b)
22533- : : "r" (from), "r" (to) : "memory");
22534+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22535
22536 from += 64;
22537 to += 64;
22538diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22539index 69fa106..adda88b 100644
22540--- a/arch/x86/lib/msr-reg.S
22541+++ b/arch/x86/lib/msr-reg.S
22542@@ -3,6 +3,7 @@
22543 #include <asm/dwarf2.h>
22544 #include <asm/asm.h>
22545 #include <asm/msr.h>
22546+#include <asm/alternative-asm.h>
22547
22548 #ifdef CONFIG_X86_64
22549 /*
22550@@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22551 CFI_STARTPROC
22552 pushq_cfi %rbx
22553 pushq_cfi %rbp
22554- movq %rdi, %r10 /* Save pointer */
22555+ movq %rdi, %r9 /* Save pointer */
22556 xorl %r11d, %r11d /* Return value */
22557 movl (%rdi), %eax
22558 movl 4(%rdi), %ecx
22559@@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22560 movl 28(%rdi), %edi
22561 CFI_REMEMBER_STATE
22562 1: \op
22563-2: movl %eax, (%r10)
22564+2: movl %eax, (%r9)
22565 movl %r11d, %eax /* Return value */
22566- movl %ecx, 4(%r10)
22567- movl %edx, 8(%r10)
22568- movl %ebx, 12(%r10)
22569- movl %ebp, 20(%r10)
22570- movl %esi, 24(%r10)
22571- movl %edi, 28(%r10)
22572+ movl %ecx, 4(%r9)
22573+ movl %edx, 8(%r9)
22574+ movl %ebx, 12(%r9)
22575+ movl %ebp, 20(%r9)
22576+ movl %esi, 24(%r9)
22577+ movl %edi, 28(%r9)
22578 popq_cfi %rbp
22579 popq_cfi %rbx
22580+ pax_force_retaddr
22581 ret
22582 3:
22583 CFI_RESTORE_STATE
22584diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22585index 7f951c8..ebd573a 100644
22586--- a/arch/x86/lib/putuser.S
22587+++ b/arch/x86/lib/putuser.S
22588@@ -15,7 +15,9 @@
22589 #include <asm/thread_info.h>
22590 #include <asm/errno.h>
22591 #include <asm/asm.h>
22592-
22593+#include <asm/segment.h>
22594+#include <asm/pgtable.h>
22595+#include <asm/alternative-asm.h>
22596
22597 /*
22598 * __put_user_X
22599@@ -29,52 +31,119 @@
22600 * as they get called from within inline assembly.
22601 */
22602
22603-#define ENTER CFI_STARTPROC ; \
22604- GET_THREAD_INFO(%_ASM_BX)
22605-#define EXIT ret ; \
22606+#define ENTER CFI_STARTPROC
22607+#define EXIT pax_force_retaddr; ret ; \
22608 CFI_ENDPROC
22609
22610+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22611+#define _DEST %_ASM_CX,%_ASM_BX
22612+#else
22613+#define _DEST %_ASM_CX
22614+#endif
22615+
22616+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22617+#define __copyuser_seg gs;
22618+#else
22619+#define __copyuser_seg
22620+#endif
22621+
22622 .text
22623 ENTRY(__put_user_1)
22624 ENTER
22625+
22626+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22627+ GET_THREAD_INFO(%_ASM_BX)
22628 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22629 jae bad_put_user
22630-1: movb %al,(%_ASM_CX)
22631+
22632+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22633+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22634+ cmp %_ASM_BX,%_ASM_CX
22635+ jb 1234f
22636+ xor %ebx,%ebx
22637+1234:
22638+#endif
22639+
22640+#endif
22641+
22642+1: __copyuser_seg movb %al,(_DEST)
22643 xor %eax,%eax
22644 EXIT
22645 ENDPROC(__put_user_1)
22646
22647 ENTRY(__put_user_2)
22648 ENTER
22649+
22650+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22651+ GET_THREAD_INFO(%_ASM_BX)
22652 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22653 sub $1,%_ASM_BX
22654 cmp %_ASM_BX,%_ASM_CX
22655 jae bad_put_user
22656-2: movw %ax,(%_ASM_CX)
22657+
22658+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22659+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22660+ cmp %_ASM_BX,%_ASM_CX
22661+ jb 1234f
22662+ xor %ebx,%ebx
22663+1234:
22664+#endif
22665+
22666+#endif
22667+
22668+2: __copyuser_seg movw %ax,(_DEST)
22669 xor %eax,%eax
22670 EXIT
22671 ENDPROC(__put_user_2)
22672
22673 ENTRY(__put_user_4)
22674 ENTER
22675+
22676+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22677+ GET_THREAD_INFO(%_ASM_BX)
22678 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22679 sub $3,%_ASM_BX
22680 cmp %_ASM_BX,%_ASM_CX
22681 jae bad_put_user
22682-3: movl %eax,(%_ASM_CX)
22683+
22684+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22685+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22686+ cmp %_ASM_BX,%_ASM_CX
22687+ jb 1234f
22688+ xor %ebx,%ebx
22689+1234:
22690+#endif
22691+
22692+#endif
22693+
22694+3: __copyuser_seg movl %eax,(_DEST)
22695 xor %eax,%eax
22696 EXIT
22697 ENDPROC(__put_user_4)
22698
22699 ENTRY(__put_user_8)
22700 ENTER
22701+
22702+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22703+ GET_THREAD_INFO(%_ASM_BX)
22704 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22705 sub $7,%_ASM_BX
22706 cmp %_ASM_BX,%_ASM_CX
22707 jae bad_put_user
22708-4: mov %_ASM_AX,(%_ASM_CX)
22709+
22710+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22711+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22712+ cmp %_ASM_BX,%_ASM_CX
22713+ jb 1234f
22714+ xor %ebx,%ebx
22715+1234:
22716+#endif
22717+
22718+#endif
22719+
22720+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22721 #ifdef CONFIG_X86_32
22722-5: movl %edx,4(%_ASM_CX)
22723+5: __copyuser_seg movl %edx,4(_DEST)
22724 #endif
22725 xor %eax,%eax
22726 EXIT
22727diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22728index 1cad221..de671ee 100644
22729--- a/arch/x86/lib/rwlock.S
22730+++ b/arch/x86/lib/rwlock.S
22731@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22732 FRAME
22733 0: LOCK_PREFIX
22734 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22735+
22736+#ifdef CONFIG_PAX_REFCOUNT
22737+ jno 1234f
22738+ LOCK_PREFIX
22739+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22740+ int $4
22741+1234:
22742+ _ASM_EXTABLE(1234b, 1234b)
22743+#endif
22744+
22745 1: rep; nop
22746 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22747 jne 1b
22748 LOCK_PREFIX
22749 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22750+
22751+#ifdef CONFIG_PAX_REFCOUNT
22752+ jno 1234f
22753+ LOCK_PREFIX
22754+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22755+ int $4
22756+1234:
22757+ _ASM_EXTABLE(1234b, 1234b)
22758+#endif
22759+
22760 jnz 0b
22761 ENDFRAME
22762+ pax_force_retaddr
22763 ret
22764 CFI_ENDPROC
22765 END(__write_lock_failed)
22766@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22767 FRAME
22768 0: LOCK_PREFIX
22769 READ_LOCK_SIZE(inc) (%__lock_ptr)
22770+
22771+#ifdef CONFIG_PAX_REFCOUNT
22772+ jno 1234f
22773+ LOCK_PREFIX
22774+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22775+ int $4
22776+1234:
22777+ _ASM_EXTABLE(1234b, 1234b)
22778+#endif
22779+
22780 1: rep; nop
22781 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22782 js 1b
22783 LOCK_PREFIX
22784 READ_LOCK_SIZE(dec) (%__lock_ptr)
22785+
22786+#ifdef CONFIG_PAX_REFCOUNT
22787+ jno 1234f
22788+ LOCK_PREFIX
22789+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22790+ int $4
22791+1234:
22792+ _ASM_EXTABLE(1234b, 1234b)
22793+#endif
22794+
22795 js 0b
22796 ENDFRAME
22797+ pax_force_retaddr
22798 ret
22799 CFI_ENDPROC
22800 END(__read_lock_failed)
22801diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22802index 5dff5f0..cadebf4 100644
22803--- a/arch/x86/lib/rwsem.S
22804+++ b/arch/x86/lib/rwsem.S
22805@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22806 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22807 CFI_RESTORE __ASM_REG(dx)
22808 restore_common_regs
22809+ pax_force_retaddr
22810 ret
22811 CFI_ENDPROC
22812 ENDPROC(call_rwsem_down_read_failed)
22813@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22814 movq %rax,%rdi
22815 call rwsem_down_write_failed
22816 restore_common_regs
22817+ pax_force_retaddr
22818 ret
22819 CFI_ENDPROC
22820 ENDPROC(call_rwsem_down_write_failed)
22821@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22822 movq %rax,%rdi
22823 call rwsem_wake
22824 restore_common_regs
22825-1: ret
22826+1: pax_force_retaddr
22827+ ret
22828 CFI_ENDPROC
22829 ENDPROC(call_rwsem_wake)
22830
22831@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22832 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22833 CFI_RESTORE __ASM_REG(dx)
22834 restore_common_regs
22835+ pax_force_retaddr
22836 ret
22837 CFI_ENDPROC
22838 ENDPROC(call_rwsem_downgrade_wake)
22839diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22840index a63efd6..ccecad8 100644
22841--- a/arch/x86/lib/thunk_64.S
22842+++ b/arch/x86/lib/thunk_64.S
22843@@ -8,6 +8,7 @@
22844 #include <linux/linkage.h>
22845 #include <asm/dwarf2.h>
22846 #include <asm/calling.h>
22847+#include <asm/alternative-asm.h>
22848
22849 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22850 .macro THUNK name, func, put_ret_addr_in_rdi=0
22851@@ -41,5 +42,6 @@
22852 SAVE_ARGS
22853 restore:
22854 RESTORE_ARGS
22855+ pax_force_retaddr
22856 ret
22857 CFI_ENDPROC
22858diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22859index 1781b2f..90368dd 100644
22860--- a/arch/x86/lib/usercopy_32.c
22861+++ b/arch/x86/lib/usercopy_32.c
22862@@ -42,10 +42,12 @@ do { \
22863 int __d0; \
22864 might_fault(); \
22865 __asm__ __volatile__( \
22866+ __COPYUSER_SET_ES \
22867 "0: rep; stosl\n" \
22868 " movl %2,%0\n" \
22869 "1: rep; stosb\n" \
22870 "2:\n" \
22871+ __COPYUSER_RESTORE_ES \
22872 ".section .fixup,\"ax\"\n" \
22873 "3: lea 0(%2,%0,4),%0\n" \
22874 " jmp 2b\n" \
22875@@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22876
22877 #ifdef CONFIG_X86_INTEL_USERCOPY
22878 static unsigned long
22879-__copy_user_intel(void __user *to, const void *from, unsigned long size)
22880+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22881 {
22882 int d0, d1;
22883 __asm__ __volatile__(
22884@@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22885 " .align 2,0x90\n"
22886 "3: movl 0(%4), %%eax\n"
22887 "4: movl 4(%4), %%edx\n"
22888- "5: movl %%eax, 0(%3)\n"
22889- "6: movl %%edx, 4(%3)\n"
22890+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22891+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22892 "7: movl 8(%4), %%eax\n"
22893 "8: movl 12(%4),%%edx\n"
22894- "9: movl %%eax, 8(%3)\n"
22895- "10: movl %%edx, 12(%3)\n"
22896+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22897+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22898 "11: movl 16(%4), %%eax\n"
22899 "12: movl 20(%4), %%edx\n"
22900- "13: movl %%eax, 16(%3)\n"
22901- "14: movl %%edx, 20(%3)\n"
22902+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22903+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22904 "15: movl 24(%4), %%eax\n"
22905 "16: movl 28(%4), %%edx\n"
22906- "17: movl %%eax, 24(%3)\n"
22907- "18: movl %%edx, 28(%3)\n"
22908+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22909+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22910 "19: movl 32(%4), %%eax\n"
22911 "20: movl 36(%4), %%edx\n"
22912- "21: movl %%eax, 32(%3)\n"
22913- "22: movl %%edx, 36(%3)\n"
22914+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22915+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22916 "23: movl 40(%4), %%eax\n"
22917 "24: movl 44(%4), %%edx\n"
22918- "25: movl %%eax, 40(%3)\n"
22919- "26: movl %%edx, 44(%3)\n"
22920+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22921+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22922 "27: movl 48(%4), %%eax\n"
22923 "28: movl 52(%4), %%edx\n"
22924- "29: movl %%eax, 48(%3)\n"
22925- "30: movl %%edx, 52(%3)\n"
22926+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22927+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22928 "31: movl 56(%4), %%eax\n"
22929 "32: movl 60(%4), %%edx\n"
22930- "33: movl %%eax, 56(%3)\n"
22931- "34: movl %%edx, 60(%3)\n"
22932+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22933+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22934 " addl $-64, %0\n"
22935 " addl $64, %4\n"
22936 " addl $64, %3\n"
22937@@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22938 " shrl $2, %0\n"
22939 " andl $3, %%eax\n"
22940 " cld\n"
22941+ __COPYUSER_SET_ES
22942 "99: rep; movsl\n"
22943 "36: movl %%eax, %0\n"
22944 "37: rep; movsb\n"
22945 "100:\n"
22946+ __COPYUSER_RESTORE_ES
22947 ".section .fixup,\"ax\"\n"
22948 "101: lea 0(%%eax,%0,4),%0\n"
22949 " jmp 100b\n"
22950@@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22951 }
22952
22953 static unsigned long
22954+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22955+{
22956+ int d0, d1;
22957+ __asm__ __volatile__(
22958+ " .align 2,0x90\n"
22959+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22960+ " cmpl $67, %0\n"
22961+ " jbe 3f\n"
22962+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22963+ " .align 2,0x90\n"
22964+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22965+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22966+ "5: movl %%eax, 0(%3)\n"
22967+ "6: movl %%edx, 4(%3)\n"
22968+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22969+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22970+ "9: movl %%eax, 8(%3)\n"
22971+ "10: movl %%edx, 12(%3)\n"
22972+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22973+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22974+ "13: movl %%eax, 16(%3)\n"
22975+ "14: movl %%edx, 20(%3)\n"
22976+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22977+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22978+ "17: movl %%eax, 24(%3)\n"
22979+ "18: movl %%edx, 28(%3)\n"
22980+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22981+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22982+ "21: movl %%eax, 32(%3)\n"
22983+ "22: movl %%edx, 36(%3)\n"
22984+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22985+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22986+ "25: movl %%eax, 40(%3)\n"
22987+ "26: movl %%edx, 44(%3)\n"
22988+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22989+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22990+ "29: movl %%eax, 48(%3)\n"
22991+ "30: movl %%edx, 52(%3)\n"
22992+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22993+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22994+ "33: movl %%eax, 56(%3)\n"
22995+ "34: movl %%edx, 60(%3)\n"
22996+ " addl $-64, %0\n"
22997+ " addl $64, %4\n"
22998+ " addl $64, %3\n"
22999+ " cmpl $63, %0\n"
23000+ " ja 1b\n"
23001+ "35: movl %0, %%eax\n"
23002+ " shrl $2, %0\n"
23003+ " andl $3, %%eax\n"
23004+ " cld\n"
23005+ "99: rep; "__copyuser_seg" movsl\n"
23006+ "36: movl %%eax, %0\n"
23007+ "37: rep; "__copyuser_seg" movsb\n"
23008+ "100:\n"
23009+ ".section .fixup,\"ax\"\n"
23010+ "101: lea 0(%%eax,%0,4),%0\n"
23011+ " jmp 100b\n"
23012+ ".previous\n"
23013+ _ASM_EXTABLE(1b,100b)
23014+ _ASM_EXTABLE(2b,100b)
23015+ _ASM_EXTABLE(3b,100b)
23016+ _ASM_EXTABLE(4b,100b)
23017+ _ASM_EXTABLE(5b,100b)
23018+ _ASM_EXTABLE(6b,100b)
23019+ _ASM_EXTABLE(7b,100b)
23020+ _ASM_EXTABLE(8b,100b)
23021+ _ASM_EXTABLE(9b,100b)
23022+ _ASM_EXTABLE(10b,100b)
23023+ _ASM_EXTABLE(11b,100b)
23024+ _ASM_EXTABLE(12b,100b)
23025+ _ASM_EXTABLE(13b,100b)
23026+ _ASM_EXTABLE(14b,100b)
23027+ _ASM_EXTABLE(15b,100b)
23028+ _ASM_EXTABLE(16b,100b)
23029+ _ASM_EXTABLE(17b,100b)
23030+ _ASM_EXTABLE(18b,100b)
23031+ _ASM_EXTABLE(19b,100b)
23032+ _ASM_EXTABLE(20b,100b)
23033+ _ASM_EXTABLE(21b,100b)
23034+ _ASM_EXTABLE(22b,100b)
23035+ _ASM_EXTABLE(23b,100b)
23036+ _ASM_EXTABLE(24b,100b)
23037+ _ASM_EXTABLE(25b,100b)
23038+ _ASM_EXTABLE(26b,100b)
23039+ _ASM_EXTABLE(27b,100b)
23040+ _ASM_EXTABLE(28b,100b)
23041+ _ASM_EXTABLE(29b,100b)
23042+ _ASM_EXTABLE(30b,100b)
23043+ _ASM_EXTABLE(31b,100b)
23044+ _ASM_EXTABLE(32b,100b)
23045+ _ASM_EXTABLE(33b,100b)
23046+ _ASM_EXTABLE(34b,100b)
23047+ _ASM_EXTABLE(35b,100b)
23048+ _ASM_EXTABLE(36b,100b)
23049+ _ASM_EXTABLE(37b,100b)
23050+ _ASM_EXTABLE(99b,101b)
23051+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
23052+ : "1"(to), "2"(from), "0"(size)
23053+ : "eax", "edx", "memory");
23054+ return size;
23055+}
23056+
23057+static unsigned long __size_overflow(3)
23058 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23059 {
23060 int d0, d1;
23061 __asm__ __volatile__(
23062 " .align 2,0x90\n"
23063- "0: movl 32(%4), %%eax\n"
23064+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23065 " cmpl $67, %0\n"
23066 " jbe 2f\n"
23067- "1: movl 64(%4), %%eax\n"
23068+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23069 " .align 2,0x90\n"
23070- "2: movl 0(%4), %%eax\n"
23071- "21: movl 4(%4), %%edx\n"
23072+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23073+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23074 " movl %%eax, 0(%3)\n"
23075 " movl %%edx, 4(%3)\n"
23076- "3: movl 8(%4), %%eax\n"
23077- "31: movl 12(%4),%%edx\n"
23078+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23079+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23080 " movl %%eax, 8(%3)\n"
23081 " movl %%edx, 12(%3)\n"
23082- "4: movl 16(%4), %%eax\n"
23083- "41: movl 20(%4), %%edx\n"
23084+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23085+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23086 " movl %%eax, 16(%3)\n"
23087 " movl %%edx, 20(%3)\n"
23088- "10: movl 24(%4), %%eax\n"
23089- "51: movl 28(%4), %%edx\n"
23090+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23091+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23092 " movl %%eax, 24(%3)\n"
23093 " movl %%edx, 28(%3)\n"
23094- "11: movl 32(%4), %%eax\n"
23095- "61: movl 36(%4), %%edx\n"
23096+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23097+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23098 " movl %%eax, 32(%3)\n"
23099 " movl %%edx, 36(%3)\n"
23100- "12: movl 40(%4), %%eax\n"
23101- "71: movl 44(%4), %%edx\n"
23102+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23103+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23104 " movl %%eax, 40(%3)\n"
23105 " movl %%edx, 44(%3)\n"
23106- "13: movl 48(%4), %%eax\n"
23107- "81: movl 52(%4), %%edx\n"
23108+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23109+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23110 " movl %%eax, 48(%3)\n"
23111 " movl %%edx, 52(%3)\n"
23112- "14: movl 56(%4), %%eax\n"
23113- "91: movl 60(%4), %%edx\n"
23114+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23115+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23116 " movl %%eax, 56(%3)\n"
23117 " movl %%edx, 60(%3)\n"
23118 " addl $-64, %0\n"
23119@@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23120 " shrl $2, %0\n"
23121 " andl $3, %%eax\n"
23122 " cld\n"
23123- "6: rep; movsl\n"
23124+ "6: rep; "__copyuser_seg" movsl\n"
23125 " movl %%eax,%0\n"
23126- "7: rep; movsb\n"
23127+ "7: rep; "__copyuser_seg" movsb\n"
23128 "8:\n"
23129 ".section .fixup,\"ax\"\n"
23130 "9: lea 0(%%eax,%0,4),%0\n"
23131@@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23132 * hyoshiok@miraclelinux.com
23133 */
23134
23135-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23136+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23137 const void __user *from, unsigned long size)
23138 {
23139 int d0, d1;
23140
23141 __asm__ __volatile__(
23142 " .align 2,0x90\n"
23143- "0: movl 32(%4), %%eax\n"
23144+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23145 " cmpl $67, %0\n"
23146 " jbe 2f\n"
23147- "1: movl 64(%4), %%eax\n"
23148+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23149 " .align 2,0x90\n"
23150- "2: movl 0(%4), %%eax\n"
23151- "21: movl 4(%4), %%edx\n"
23152+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23153+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23154 " movnti %%eax, 0(%3)\n"
23155 " movnti %%edx, 4(%3)\n"
23156- "3: movl 8(%4), %%eax\n"
23157- "31: movl 12(%4),%%edx\n"
23158+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23159+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23160 " movnti %%eax, 8(%3)\n"
23161 " movnti %%edx, 12(%3)\n"
23162- "4: movl 16(%4), %%eax\n"
23163- "41: movl 20(%4), %%edx\n"
23164+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23165+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23166 " movnti %%eax, 16(%3)\n"
23167 " movnti %%edx, 20(%3)\n"
23168- "10: movl 24(%4), %%eax\n"
23169- "51: movl 28(%4), %%edx\n"
23170+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23171+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23172 " movnti %%eax, 24(%3)\n"
23173 " movnti %%edx, 28(%3)\n"
23174- "11: movl 32(%4), %%eax\n"
23175- "61: movl 36(%4), %%edx\n"
23176+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23177+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23178 " movnti %%eax, 32(%3)\n"
23179 " movnti %%edx, 36(%3)\n"
23180- "12: movl 40(%4), %%eax\n"
23181- "71: movl 44(%4), %%edx\n"
23182+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23183+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23184 " movnti %%eax, 40(%3)\n"
23185 " movnti %%edx, 44(%3)\n"
23186- "13: movl 48(%4), %%eax\n"
23187- "81: movl 52(%4), %%edx\n"
23188+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23189+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23190 " movnti %%eax, 48(%3)\n"
23191 " movnti %%edx, 52(%3)\n"
23192- "14: movl 56(%4), %%eax\n"
23193- "91: movl 60(%4), %%edx\n"
23194+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23195+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23196 " movnti %%eax, 56(%3)\n"
23197 " movnti %%edx, 60(%3)\n"
23198 " addl $-64, %0\n"
23199@@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23200 " shrl $2, %0\n"
23201 " andl $3, %%eax\n"
23202 " cld\n"
23203- "6: rep; movsl\n"
23204+ "6: rep; "__copyuser_seg" movsl\n"
23205 " movl %%eax,%0\n"
23206- "7: rep; movsb\n"
23207+ "7: rep; "__copyuser_seg" movsb\n"
23208 "8:\n"
23209 ".section .fixup,\"ax\"\n"
23210 "9: lea 0(%%eax,%0,4),%0\n"
23211@@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23212 return size;
23213 }
23214
23215-static unsigned long __copy_user_intel_nocache(void *to,
23216+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23217 const void __user *from, unsigned long size)
23218 {
23219 int d0, d1;
23220
23221 __asm__ __volatile__(
23222 " .align 2,0x90\n"
23223- "0: movl 32(%4), %%eax\n"
23224+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23225 " cmpl $67, %0\n"
23226 " jbe 2f\n"
23227- "1: movl 64(%4), %%eax\n"
23228+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23229 " .align 2,0x90\n"
23230- "2: movl 0(%4), %%eax\n"
23231- "21: movl 4(%4), %%edx\n"
23232+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23233+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23234 " movnti %%eax, 0(%3)\n"
23235 " movnti %%edx, 4(%3)\n"
23236- "3: movl 8(%4), %%eax\n"
23237- "31: movl 12(%4),%%edx\n"
23238+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23239+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23240 " movnti %%eax, 8(%3)\n"
23241 " movnti %%edx, 12(%3)\n"
23242- "4: movl 16(%4), %%eax\n"
23243- "41: movl 20(%4), %%edx\n"
23244+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23245+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23246 " movnti %%eax, 16(%3)\n"
23247 " movnti %%edx, 20(%3)\n"
23248- "10: movl 24(%4), %%eax\n"
23249- "51: movl 28(%4), %%edx\n"
23250+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23251+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23252 " movnti %%eax, 24(%3)\n"
23253 " movnti %%edx, 28(%3)\n"
23254- "11: movl 32(%4), %%eax\n"
23255- "61: movl 36(%4), %%edx\n"
23256+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23257+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23258 " movnti %%eax, 32(%3)\n"
23259 " movnti %%edx, 36(%3)\n"
23260- "12: movl 40(%4), %%eax\n"
23261- "71: movl 44(%4), %%edx\n"
23262+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23263+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23264 " movnti %%eax, 40(%3)\n"
23265 " movnti %%edx, 44(%3)\n"
23266- "13: movl 48(%4), %%eax\n"
23267- "81: movl 52(%4), %%edx\n"
23268+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23269+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23270 " movnti %%eax, 48(%3)\n"
23271 " movnti %%edx, 52(%3)\n"
23272- "14: movl 56(%4), %%eax\n"
23273- "91: movl 60(%4), %%edx\n"
23274+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23275+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23276 " movnti %%eax, 56(%3)\n"
23277 " movnti %%edx, 60(%3)\n"
23278 " addl $-64, %0\n"
23279@@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23280 " shrl $2, %0\n"
23281 " andl $3, %%eax\n"
23282 " cld\n"
23283- "6: rep; movsl\n"
23284+ "6: rep; "__copyuser_seg" movsl\n"
23285 " movl %%eax,%0\n"
23286- "7: rep; movsb\n"
23287+ "7: rep; "__copyuser_seg" movsb\n"
23288 "8:\n"
23289 ".section .fixup,\"ax\"\n"
23290 "9: lea 0(%%eax,%0,4),%0\n"
23291@@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23292 */
23293 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23294 unsigned long size);
23295-unsigned long __copy_user_intel(void __user *to, const void *from,
23296+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23297+ unsigned long size);
23298+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23299 unsigned long size);
23300 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23301 const void __user *from, unsigned long size);
23302 #endif /* CONFIG_X86_INTEL_USERCOPY */
23303
23304 /* Generic arbitrary sized copy. */
23305-#define __copy_user(to, from, size) \
23306+#define __copy_user(to, from, size, prefix, set, restore) \
23307 do { \
23308 int __d0, __d1, __d2; \
23309 __asm__ __volatile__( \
23310+ set \
23311 " cmp $7,%0\n" \
23312 " jbe 1f\n" \
23313 " movl %1,%0\n" \
23314 " negl %0\n" \
23315 " andl $7,%0\n" \
23316 " subl %0,%3\n" \
23317- "4: rep; movsb\n" \
23318+ "4: rep; "prefix"movsb\n" \
23319 " movl %3,%0\n" \
23320 " shrl $2,%0\n" \
23321 " andl $3,%3\n" \
23322 " .align 2,0x90\n" \
23323- "0: rep; movsl\n" \
23324+ "0: rep; "prefix"movsl\n" \
23325 " movl %3,%0\n" \
23326- "1: rep; movsb\n" \
23327+ "1: rep; "prefix"movsb\n" \
23328 "2:\n" \
23329+ restore \
23330 ".section .fixup,\"ax\"\n" \
23331 "5: addl %3,%0\n" \
23332 " jmp 2b\n" \
23333@@ -537,14 +649,14 @@ do { \
23334 " negl %0\n" \
23335 " andl $7,%0\n" \
23336 " subl %0,%3\n" \
23337- "4: rep; movsb\n" \
23338+ "4: rep; "__copyuser_seg"movsb\n" \
23339 " movl %3,%0\n" \
23340 " shrl $2,%0\n" \
23341 " andl $3,%3\n" \
23342 " .align 2,0x90\n" \
23343- "0: rep; movsl\n" \
23344+ "0: rep; "__copyuser_seg"movsl\n" \
23345 " movl %3,%0\n" \
23346- "1: rep; movsb\n" \
23347+ "1: rep; "__copyuser_seg"movsb\n" \
23348 "2:\n" \
23349 ".section .fixup,\"ax\"\n" \
23350 "5: addl %3,%0\n" \
23351@@ -627,9 +739,9 @@ survive:
23352 }
23353 #endif
23354 if (movsl_is_ok(to, from, n))
23355- __copy_user(to, from, n);
23356+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23357 else
23358- n = __copy_user_intel(to, from, n);
23359+ n = __generic_copy_to_user_intel(to, from, n);
23360 return n;
23361 }
23362 EXPORT_SYMBOL(__copy_to_user_ll);
23363@@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23364 unsigned long n)
23365 {
23366 if (movsl_is_ok(to, from, n))
23367- __copy_user(to, from, n);
23368+ __copy_user(to, from, n, __copyuser_seg, "", "");
23369 else
23370- n = __copy_user_intel((void __user *)to,
23371- (const void *)from, n);
23372+ n = __generic_copy_from_user_intel(to, from, n);
23373 return n;
23374 }
23375 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23376@@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23377 if (n > 64 && cpu_has_xmm2)
23378 n = __copy_user_intel_nocache(to, from, n);
23379 else
23380- __copy_user(to, from, n);
23381+ __copy_user(to, from, n, __copyuser_seg, "", "");
23382 #else
23383- __copy_user(to, from, n);
23384+ __copy_user(to, from, n, __copyuser_seg, "", "");
23385 #endif
23386 return n;
23387 }
23388 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23389
23390-/**
23391- * copy_to_user: - Copy a block of data into user space.
23392- * @to: Destination address, in user space.
23393- * @from: Source address, in kernel space.
23394- * @n: Number of bytes to copy.
23395- *
23396- * Context: User context only. This function may sleep.
23397- *
23398- * Copy data from kernel space to user space.
23399- *
23400- * Returns number of bytes that could not be copied.
23401- * On success, this will be zero.
23402- */
23403-unsigned long
23404-copy_to_user(void __user *to, const void *from, unsigned long n)
23405-{
23406- if (access_ok(VERIFY_WRITE, to, n))
23407- n = __copy_to_user(to, from, n);
23408- return n;
23409-}
23410-EXPORT_SYMBOL(copy_to_user);
23411-
23412-/**
23413- * copy_from_user: - Copy a block of data from user space.
23414- * @to: Destination address, in kernel space.
23415- * @from: Source address, in user space.
23416- * @n: Number of bytes to copy.
23417- *
23418- * Context: User context only. This function may sleep.
23419- *
23420- * Copy data from user space to kernel space.
23421- *
23422- * Returns number of bytes that could not be copied.
23423- * On success, this will be zero.
23424- *
23425- * If some data could not be copied, this function will pad the copied
23426- * data to the requested size using zero bytes.
23427- */
23428-unsigned long
23429-_copy_from_user(void *to, const void __user *from, unsigned long n)
23430-{
23431- if (access_ok(VERIFY_READ, from, n))
23432- n = __copy_from_user(to, from, n);
23433- else
23434- memset(to, 0, n);
23435- return n;
23436-}
23437-EXPORT_SYMBOL(_copy_from_user);
23438-
23439 void copy_from_user_overflow(void)
23440 {
23441 WARN(1, "Buffer overflow detected!\n");
23442 }
23443 EXPORT_SYMBOL(copy_from_user_overflow);
23444+
23445+void copy_to_user_overflow(void)
23446+{
23447+ WARN(1, "Buffer overflow detected!\n");
23448+}
23449+EXPORT_SYMBOL(copy_to_user_overflow);
23450+
23451+#ifdef CONFIG_PAX_MEMORY_UDEREF
23452+void __set_fs(mm_segment_t x)
23453+{
23454+ switch (x.seg) {
23455+ case 0:
23456+ loadsegment(gs, 0);
23457+ break;
23458+ case TASK_SIZE_MAX:
23459+ loadsegment(gs, __USER_DS);
23460+ break;
23461+ case -1UL:
23462+ loadsegment(gs, __KERNEL_DS);
23463+ break;
23464+ default:
23465+ BUG();
23466+ }
23467+ return;
23468+}
23469+EXPORT_SYMBOL(__set_fs);
23470+
23471+void set_fs(mm_segment_t x)
23472+{
23473+ current_thread_info()->addr_limit = x;
23474+ __set_fs(x);
23475+}
23476+EXPORT_SYMBOL(set_fs);
23477+#endif
23478diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23479index e5b130b..6690d31 100644
23480--- a/arch/x86/lib/usercopy_64.c
23481+++ b/arch/x86/lib/usercopy_64.c
23482@@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23483 {
23484 long __d0;
23485 might_fault();
23486+
23487+#ifdef CONFIG_PAX_MEMORY_UDEREF
23488+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23489+ addr += PAX_USER_SHADOW_BASE;
23490+#endif
23491+
23492 /* no memory constraint because it doesn't change any memory gcc knows
23493 about */
23494 asm volatile(
23495@@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23496 }
23497 EXPORT_SYMBOL(clear_user);
23498
23499-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23500+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23501 {
23502- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23503- return copy_user_generic((__force void *)to, (__force void *)from, len);
23504- }
23505- return len;
23506+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23507+
23508+#ifdef CONFIG_PAX_MEMORY_UDEREF
23509+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23510+ to += PAX_USER_SHADOW_BASE;
23511+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23512+ from += PAX_USER_SHADOW_BASE;
23513+#endif
23514+
23515+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23516+ }
23517+ return len;
23518 }
23519 EXPORT_SYMBOL(copy_in_user);
23520
23521@@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23522 * it is not necessary to optimize tail handling.
23523 */
23524 unsigned long
23525-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23526+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23527 {
23528 char c;
23529 unsigned zero_len;
23530@@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23531 break;
23532 return len;
23533 }
23534+
23535+void copy_from_user_overflow(void)
23536+{
23537+ WARN(1, "Buffer overflow detected!\n");
23538+}
23539+EXPORT_SYMBOL(copy_from_user_overflow);
23540+
23541+void copy_to_user_overflow(void)
23542+{
23543+ WARN(1, "Buffer overflow detected!\n");
23544+}
23545+EXPORT_SYMBOL(copy_to_user_overflow);
23546diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23547index 903ec1e..c4166b2 100644
23548--- a/arch/x86/mm/extable.c
23549+++ b/arch/x86/mm/extable.c
23550@@ -6,12 +6,24 @@
23551 static inline unsigned long
23552 ex_insn_addr(const struct exception_table_entry *x)
23553 {
23554- return (unsigned long)&x->insn + x->insn;
23555+ unsigned long reloc = 0;
23556+
23557+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23558+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23559+#endif
23560+
23561+ return (unsigned long)&x->insn + x->insn + reloc;
23562 }
23563 static inline unsigned long
23564 ex_fixup_addr(const struct exception_table_entry *x)
23565 {
23566- return (unsigned long)&x->fixup + x->fixup;
23567+ unsigned long reloc = 0;
23568+
23569+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23570+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23571+#endif
23572+
23573+ return (unsigned long)&x->fixup + x->fixup + reloc;
23574 }
23575
23576 int fixup_exception(struct pt_regs *regs)
23577@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23578 unsigned long new_ip;
23579
23580 #ifdef CONFIG_PNPBIOS
23581- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23582+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23583 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23584 extern u32 pnp_bios_is_utter_crap;
23585 pnp_bios_is_utter_crap = 1;
23586@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23587 i += 4;
23588 p->fixup -= i;
23589 i += 4;
23590+
23591+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23592+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23593+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23594+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23595+#endif
23596+
23597 }
23598 }
23599
23600diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23601index 76dcd9d..e9dffde 100644
23602--- a/arch/x86/mm/fault.c
23603+++ b/arch/x86/mm/fault.c
23604@@ -13,11 +13,18 @@
23605 #include <linux/perf_event.h> /* perf_sw_event */
23606 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23607 #include <linux/prefetch.h> /* prefetchw */
23608+#include <linux/unistd.h>
23609+#include <linux/compiler.h>
23610
23611 #include <asm/traps.h> /* dotraplinkage, ... */
23612 #include <asm/pgalloc.h> /* pgd_*(), ... */
23613 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23614 #include <asm/fixmap.h> /* VSYSCALL_START */
23615+#include <asm/tlbflush.h>
23616+
23617+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23618+#include <asm/stacktrace.h>
23619+#endif
23620
23621 /*
23622 * Page fault error code bits:
23623@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23624 int ret = 0;
23625
23626 /* kprobe_running() needs smp_processor_id() */
23627- if (kprobes_built_in() && !user_mode_vm(regs)) {
23628+ if (kprobes_built_in() && !user_mode(regs)) {
23629 preempt_disable();
23630 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23631 ret = 1;
23632@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23633 return !instr_lo || (instr_lo>>1) == 1;
23634 case 0x00:
23635 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23636- if (probe_kernel_address(instr, opcode))
23637+ if (user_mode(regs)) {
23638+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23639+ return 0;
23640+ } else if (probe_kernel_address(instr, opcode))
23641 return 0;
23642
23643 *prefetch = (instr_lo == 0xF) &&
23644@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23645 while (instr < max_instr) {
23646 unsigned char opcode;
23647
23648- if (probe_kernel_address(instr, opcode))
23649+ if (user_mode(regs)) {
23650+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23651+ break;
23652+ } else if (probe_kernel_address(instr, opcode))
23653 break;
23654
23655 instr++;
23656@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23657 force_sig_info(si_signo, &info, tsk);
23658 }
23659
23660+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23661+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23662+#endif
23663+
23664+#ifdef CONFIG_PAX_EMUTRAMP
23665+static int pax_handle_fetch_fault(struct pt_regs *regs);
23666+#endif
23667+
23668+#ifdef CONFIG_PAX_PAGEEXEC
23669+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23670+{
23671+ pgd_t *pgd;
23672+ pud_t *pud;
23673+ pmd_t *pmd;
23674+
23675+ pgd = pgd_offset(mm, address);
23676+ if (!pgd_present(*pgd))
23677+ return NULL;
23678+ pud = pud_offset(pgd, address);
23679+ if (!pud_present(*pud))
23680+ return NULL;
23681+ pmd = pmd_offset(pud, address);
23682+ if (!pmd_present(*pmd))
23683+ return NULL;
23684+ return pmd;
23685+}
23686+#endif
23687+
23688 DEFINE_SPINLOCK(pgd_lock);
23689 LIST_HEAD(pgd_list);
23690
23691@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23692 for (address = VMALLOC_START & PMD_MASK;
23693 address >= TASK_SIZE && address < FIXADDR_TOP;
23694 address += PMD_SIZE) {
23695+
23696+#ifdef CONFIG_PAX_PER_CPU_PGD
23697+ unsigned long cpu;
23698+#else
23699 struct page *page;
23700+#endif
23701
23702 spin_lock(&pgd_lock);
23703+
23704+#ifdef CONFIG_PAX_PER_CPU_PGD
23705+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23706+ pgd_t *pgd = get_cpu_pgd(cpu);
23707+ pmd_t *ret;
23708+#else
23709 list_for_each_entry(page, &pgd_list, lru) {
23710+ pgd_t *pgd = page_address(page);
23711 spinlock_t *pgt_lock;
23712 pmd_t *ret;
23713
23714@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23715 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23716
23717 spin_lock(pgt_lock);
23718- ret = vmalloc_sync_one(page_address(page), address);
23719+#endif
23720+
23721+ ret = vmalloc_sync_one(pgd, address);
23722+
23723+#ifndef CONFIG_PAX_PER_CPU_PGD
23724 spin_unlock(pgt_lock);
23725+#endif
23726
23727 if (!ret)
23728 break;
23729@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23730 * an interrupt in the middle of a task switch..
23731 */
23732 pgd_paddr = read_cr3();
23733+
23734+#ifdef CONFIG_PAX_PER_CPU_PGD
23735+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23736+#endif
23737+
23738 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23739 if (!pmd_k)
23740 return -1;
23741@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23742 * happen within a race in page table update. In the later
23743 * case just flush:
23744 */
23745+
23746+#ifdef CONFIG_PAX_PER_CPU_PGD
23747+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23748+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23749+#else
23750 pgd = pgd_offset(current->active_mm, address);
23751+#endif
23752+
23753 pgd_ref = pgd_offset_k(address);
23754 if (pgd_none(*pgd_ref))
23755 return -1;
23756@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23757 static int is_errata100(struct pt_regs *regs, unsigned long address)
23758 {
23759 #ifdef CONFIG_X86_64
23760- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23761+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23762 return 1;
23763 #endif
23764 return 0;
23765@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23766 }
23767
23768 static const char nx_warning[] = KERN_CRIT
23769-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23770+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23771
23772 static void
23773 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23774@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23775 if (!oops_may_print())
23776 return;
23777
23778- if (error_code & PF_INSTR) {
23779+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23780 unsigned int level;
23781
23782 pte_t *pte = lookup_address(address, &level);
23783
23784 if (pte && pte_present(*pte) && !pte_exec(*pte))
23785- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23786+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23787 }
23788
23789+#ifdef CONFIG_PAX_KERNEXEC
23790+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23791+ if (current->signal->curr_ip)
23792+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23793+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23794+ else
23795+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23796+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23797+ }
23798+#endif
23799+
23800 printk(KERN_ALERT "BUG: unable to handle kernel ");
23801 if (address < PAGE_SIZE)
23802 printk(KERN_CONT "NULL pointer dereference");
23803@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23804 }
23805 #endif
23806
23807+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23808+ if (pax_is_fetch_fault(regs, error_code, address)) {
23809+
23810+#ifdef CONFIG_PAX_EMUTRAMP
23811+ switch (pax_handle_fetch_fault(regs)) {
23812+ case 2:
23813+ return;
23814+ }
23815+#endif
23816+
23817+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23818+ do_group_exit(SIGKILL);
23819+ }
23820+#endif
23821+
23822 if (unlikely(show_unhandled_signals))
23823 show_signal_msg(regs, error_code, address, tsk);
23824
23825@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23826 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23827 printk(KERN_ERR
23828 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23829- tsk->comm, tsk->pid, address);
23830+ tsk->comm, task_pid_nr(tsk), address);
23831 code = BUS_MCEERR_AR;
23832 }
23833 #endif
23834@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23835 return 1;
23836 }
23837
23838+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23839+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23840+{
23841+ pte_t *pte;
23842+ pmd_t *pmd;
23843+ spinlock_t *ptl;
23844+ unsigned char pte_mask;
23845+
23846+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23847+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23848+ return 0;
23849+
23850+ /* PaX: it's our fault, let's handle it if we can */
23851+
23852+ /* PaX: take a look at read faults before acquiring any locks */
23853+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23854+ /* instruction fetch attempt from a protected page in user mode */
23855+ up_read(&mm->mmap_sem);
23856+
23857+#ifdef CONFIG_PAX_EMUTRAMP
23858+ switch (pax_handle_fetch_fault(regs)) {
23859+ case 2:
23860+ return 1;
23861+ }
23862+#endif
23863+
23864+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23865+ do_group_exit(SIGKILL);
23866+ }
23867+
23868+ pmd = pax_get_pmd(mm, address);
23869+ if (unlikely(!pmd))
23870+ return 0;
23871+
23872+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23873+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23874+ pte_unmap_unlock(pte, ptl);
23875+ return 0;
23876+ }
23877+
23878+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23879+ /* write attempt to a protected page in user mode */
23880+ pte_unmap_unlock(pte, ptl);
23881+ return 0;
23882+ }
23883+
23884+#ifdef CONFIG_SMP
23885+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23886+#else
23887+ if (likely(address > get_limit(regs->cs)))
23888+#endif
23889+ {
23890+ set_pte(pte, pte_mkread(*pte));
23891+ __flush_tlb_one(address);
23892+ pte_unmap_unlock(pte, ptl);
23893+ up_read(&mm->mmap_sem);
23894+ return 1;
23895+ }
23896+
23897+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23898+
23899+ /*
23900+ * PaX: fill DTLB with user rights and retry
23901+ */
23902+ __asm__ __volatile__ (
23903+ "orb %2,(%1)\n"
23904+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23905+/*
23906+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23907+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23908+ * page fault when examined during a TLB load attempt. this is true not only
23909+ * for PTEs holding a non-present entry but also present entries that will
23910+ * raise a page fault (such as those set up by PaX, or the copy-on-write
23911+ * mechanism). in effect it means that we do *not* need to flush the TLBs
23912+ * for our target pages since their PTEs are simply not in the TLBs at all.
23913+
23914+ * the best thing in omitting it is that we gain around 15-20% speed in the
23915+ * fast path of the page fault handler and can get rid of tracing since we
23916+ * can no longer flush unintended entries.
23917+ */
23918+ "invlpg (%0)\n"
23919+#endif
23920+ __copyuser_seg"testb $0,(%0)\n"
23921+ "xorb %3,(%1)\n"
23922+ :
23923+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23924+ : "memory", "cc");
23925+ pte_unmap_unlock(pte, ptl);
23926+ up_read(&mm->mmap_sem);
23927+ return 1;
23928+}
23929+#endif
23930+
23931 /*
23932 * Handle a spurious fault caused by a stale TLB entry.
23933 *
23934@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23935 static inline int
23936 access_error(unsigned long error_code, struct vm_area_struct *vma)
23937 {
23938+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23939+ return 1;
23940+
23941 if (error_code & PF_WRITE) {
23942 /* write, present and write, not present: */
23943 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23944@@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23945 {
23946 struct vm_area_struct *vma;
23947 struct task_struct *tsk;
23948- unsigned long address;
23949 struct mm_struct *mm;
23950 int fault;
23951 int write = error_code & PF_WRITE;
23952 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23953 (write ? FAULT_FLAG_WRITE : 0);
23954
23955- tsk = current;
23956- mm = tsk->mm;
23957-
23958 /* Get the faulting address: */
23959- address = read_cr2();
23960+ unsigned long address = read_cr2();
23961+
23962+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23963+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23964+ if (!search_exception_tables(regs->ip)) {
23965+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23966+ bad_area_nosemaphore(regs, error_code, address);
23967+ return;
23968+ }
23969+ if (address < PAX_USER_SHADOW_BASE) {
23970+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23971+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23972+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23973+ } else
23974+ address -= PAX_USER_SHADOW_BASE;
23975+ }
23976+#endif
23977+
23978+ tsk = current;
23979+ mm = tsk->mm;
23980
23981 /*
23982 * Detect and handle instructions that would cause a page fault for
23983@@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23984 * User-mode registers count as a user access even for any
23985 * potential system fault or CPU buglet:
23986 */
23987- if (user_mode_vm(regs)) {
23988+ if (user_mode(regs)) {
23989 local_irq_enable();
23990 error_code |= PF_USER;
23991 } else {
23992@@ -1132,6 +1339,11 @@ retry:
23993 might_sleep();
23994 }
23995
23996+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23997+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23998+ return;
23999+#endif
24000+
24001 vma = find_vma(mm, address);
24002 if (unlikely(!vma)) {
24003 bad_area(regs, error_code, address);
24004@@ -1143,18 +1355,24 @@ retry:
24005 bad_area(regs, error_code, address);
24006 return;
24007 }
24008- if (error_code & PF_USER) {
24009- /*
24010- * Accessing the stack below %sp is always a bug.
24011- * The large cushion allows instructions like enter
24012- * and pusha to work. ("enter $65535, $31" pushes
24013- * 32 pointers and then decrements %sp by 65535.)
24014- */
24015- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24016- bad_area(regs, error_code, address);
24017- return;
24018- }
24019+ /*
24020+ * Accessing the stack below %sp is always a bug.
24021+ * The large cushion allows instructions like enter
24022+ * and pusha to work. ("enter $65535, $31" pushes
24023+ * 32 pointers and then decrements %sp by 65535.)
24024+ */
24025+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24026+ bad_area(regs, error_code, address);
24027+ return;
24028 }
24029+
24030+#ifdef CONFIG_PAX_SEGMEXEC
24031+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24032+ bad_area(regs, error_code, address);
24033+ return;
24034+ }
24035+#endif
24036+
24037 if (unlikely(expand_stack(vma, address))) {
24038 bad_area(regs, error_code, address);
24039 return;
24040@@ -1209,3 +1427,292 @@ good_area:
24041
24042 up_read(&mm->mmap_sem);
24043 }
24044+
24045+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24046+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24047+{
24048+ struct mm_struct *mm = current->mm;
24049+ unsigned long ip = regs->ip;
24050+
24051+ if (v8086_mode(regs))
24052+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24053+
24054+#ifdef CONFIG_PAX_PAGEEXEC
24055+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24056+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24057+ return true;
24058+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24059+ return true;
24060+ return false;
24061+ }
24062+#endif
24063+
24064+#ifdef CONFIG_PAX_SEGMEXEC
24065+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24066+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24067+ return true;
24068+ return false;
24069+ }
24070+#endif
24071+
24072+ return false;
24073+}
24074+#endif
24075+
24076+#ifdef CONFIG_PAX_EMUTRAMP
24077+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24078+{
24079+ int err;
24080+
24081+ do { /* PaX: libffi trampoline emulation */
24082+ unsigned char mov, jmp;
24083+ unsigned int addr1, addr2;
24084+
24085+#ifdef CONFIG_X86_64
24086+ if ((regs->ip + 9) >> 32)
24087+ break;
24088+#endif
24089+
24090+ err = get_user(mov, (unsigned char __user *)regs->ip);
24091+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24092+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24093+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24094+
24095+ if (err)
24096+ break;
24097+
24098+ if (mov == 0xB8 && jmp == 0xE9) {
24099+ regs->ax = addr1;
24100+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24101+ return 2;
24102+ }
24103+ } while (0);
24104+
24105+ do { /* PaX: gcc trampoline emulation #1 */
24106+ unsigned char mov1, mov2;
24107+ unsigned short jmp;
24108+ unsigned int addr1, addr2;
24109+
24110+#ifdef CONFIG_X86_64
24111+ if ((regs->ip + 11) >> 32)
24112+ break;
24113+#endif
24114+
24115+ err = get_user(mov1, (unsigned char __user *)regs->ip);
24116+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24117+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24118+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24119+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24120+
24121+ if (err)
24122+ break;
24123+
24124+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24125+ regs->cx = addr1;
24126+ regs->ax = addr2;
24127+ regs->ip = addr2;
24128+ return 2;
24129+ }
24130+ } while (0);
24131+
24132+ do { /* PaX: gcc trampoline emulation #2 */
24133+ unsigned char mov, jmp;
24134+ unsigned int addr1, addr2;
24135+
24136+#ifdef CONFIG_X86_64
24137+ if ((regs->ip + 9) >> 32)
24138+ break;
24139+#endif
24140+
24141+ err = get_user(mov, (unsigned char __user *)regs->ip);
24142+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24143+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24144+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24145+
24146+ if (err)
24147+ break;
24148+
24149+ if (mov == 0xB9 && jmp == 0xE9) {
24150+ regs->cx = addr1;
24151+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24152+ return 2;
24153+ }
24154+ } while (0);
24155+
24156+ return 1; /* PaX in action */
24157+}
24158+
24159+#ifdef CONFIG_X86_64
24160+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24161+{
24162+ int err;
24163+
24164+ do { /* PaX: libffi trampoline emulation */
24165+ unsigned short mov1, mov2, jmp1;
24166+ unsigned char stcclc, jmp2;
24167+ unsigned long addr1, addr2;
24168+
24169+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24170+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24171+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24172+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24173+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24174+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24175+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24176+
24177+ if (err)
24178+ break;
24179+
24180+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24181+ regs->r11 = addr1;
24182+ regs->r10 = addr2;
24183+ if (stcclc == 0xF8)
24184+ regs->flags &= ~X86_EFLAGS_CF;
24185+ else
24186+ regs->flags |= X86_EFLAGS_CF;
24187+ regs->ip = addr1;
24188+ return 2;
24189+ }
24190+ } while (0);
24191+
24192+ do { /* PaX: gcc trampoline emulation #1 */
24193+ unsigned short mov1, mov2, jmp1;
24194+ unsigned char jmp2;
24195+ unsigned int addr1;
24196+ unsigned long addr2;
24197+
24198+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24199+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24200+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24201+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24202+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24203+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24204+
24205+ if (err)
24206+ break;
24207+
24208+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24209+ regs->r11 = addr1;
24210+ regs->r10 = addr2;
24211+ regs->ip = addr1;
24212+ return 2;
24213+ }
24214+ } while (0);
24215+
24216+ do { /* PaX: gcc trampoline emulation #2 */
24217+ unsigned short mov1, mov2, jmp1;
24218+ unsigned char jmp2;
24219+ unsigned long addr1, addr2;
24220+
24221+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24222+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24223+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24224+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24225+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24226+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24227+
24228+ if (err)
24229+ break;
24230+
24231+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24232+ regs->r11 = addr1;
24233+ regs->r10 = addr2;
24234+ regs->ip = addr1;
24235+ return 2;
24236+ }
24237+ } while (0);
24238+
24239+ return 1; /* PaX in action */
24240+}
24241+#endif
24242+
24243+/*
24244+ * PaX: decide what to do with offenders (regs->ip = fault address)
24245+ *
24246+ * returns 1 when task should be killed
24247+ * 2 when gcc trampoline was detected
24248+ */
24249+static int pax_handle_fetch_fault(struct pt_regs *regs)
24250+{
24251+ if (v8086_mode(regs))
24252+ return 1;
24253+
24254+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24255+ return 1;
24256+
24257+#ifdef CONFIG_X86_32
24258+ return pax_handle_fetch_fault_32(regs);
24259+#else
24260+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24261+ return pax_handle_fetch_fault_32(regs);
24262+ else
24263+ return pax_handle_fetch_fault_64(regs);
24264+#endif
24265+}
24266+#endif
24267+
24268+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24269+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24270+{
24271+ long i;
24272+
24273+ printk(KERN_ERR "PAX: bytes at PC: ");
24274+ for (i = 0; i < 20; i++) {
24275+ unsigned char c;
24276+ if (get_user(c, (unsigned char __force_user *)pc+i))
24277+ printk(KERN_CONT "?? ");
24278+ else
24279+ printk(KERN_CONT "%02x ", c);
24280+ }
24281+ printk("\n");
24282+
24283+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24284+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24285+ unsigned long c;
24286+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24287+#ifdef CONFIG_X86_32
24288+ printk(KERN_CONT "???????? ");
24289+#else
24290+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24291+ printk(KERN_CONT "???????? ???????? ");
24292+ else
24293+ printk(KERN_CONT "???????????????? ");
24294+#endif
24295+ } else {
24296+#ifdef CONFIG_X86_64
24297+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24298+ printk(KERN_CONT "%08x ", (unsigned int)c);
24299+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24300+ } else
24301+#endif
24302+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24303+ }
24304+ }
24305+ printk("\n");
24306+}
24307+#endif
24308+
24309+/**
24310+ * probe_kernel_write(): safely attempt to write to a location
24311+ * @dst: address to write to
24312+ * @src: pointer to the data that shall be written
24313+ * @size: size of the data chunk
24314+ *
24315+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24316+ * happens, handle that and return -EFAULT.
24317+ */
24318+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24319+{
24320+ long ret;
24321+ mm_segment_t old_fs = get_fs();
24322+
24323+ set_fs(KERNEL_DS);
24324+ pagefault_disable();
24325+ pax_open_kernel();
24326+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24327+ pax_close_kernel();
24328+ pagefault_enable();
24329+ set_fs(old_fs);
24330+
24331+ return ret ? -EFAULT : 0;
24332+}
24333diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24334index dd74e46..7d26398 100644
24335--- a/arch/x86/mm/gup.c
24336+++ b/arch/x86/mm/gup.c
24337@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24338 addr = start;
24339 len = (unsigned long) nr_pages << PAGE_SHIFT;
24340 end = start + len;
24341- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24342+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24343 (void __user *)start, len)))
24344 return 0;
24345
24346diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24347index 6f31ee5..8ee4164 100644
24348--- a/arch/x86/mm/highmem_32.c
24349+++ b/arch/x86/mm/highmem_32.c
24350@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24351 idx = type + KM_TYPE_NR*smp_processor_id();
24352 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24353 BUG_ON(!pte_none(*(kmap_pte-idx)));
24354+
24355+ pax_open_kernel();
24356 set_pte(kmap_pte-idx, mk_pte(page, prot));
24357+ pax_close_kernel();
24358+
24359 arch_flush_lazy_mmu_mode();
24360
24361 return (void *)vaddr;
24362diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24363index b91e485..d00e7c9 100644
24364--- a/arch/x86/mm/hugetlbpage.c
24365+++ b/arch/x86/mm/hugetlbpage.c
24366@@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24367 struct hstate *h = hstate_file(file);
24368 struct mm_struct *mm = current->mm;
24369 struct vm_area_struct *vma;
24370- unsigned long start_addr;
24371+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24372+
24373+#ifdef CONFIG_PAX_SEGMEXEC
24374+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24375+ pax_task_size = SEGMEXEC_TASK_SIZE;
24376+#endif
24377+
24378+ pax_task_size -= PAGE_SIZE;
24379
24380 if (len > mm->cached_hole_size) {
24381- start_addr = mm->free_area_cache;
24382+ start_addr = mm->free_area_cache;
24383 } else {
24384- start_addr = TASK_UNMAPPED_BASE;
24385- mm->cached_hole_size = 0;
24386+ start_addr = mm->mmap_base;
24387+ mm->cached_hole_size = 0;
24388 }
24389
24390 full_search:
24391@@ -291,26 +298,27 @@ full_search:
24392
24393 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24394 /* At this point: (!vma || addr < vma->vm_end). */
24395- if (TASK_SIZE - len < addr) {
24396+ if (pax_task_size - len < addr) {
24397 /*
24398 * Start a new search - just in case we missed
24399 * some holes.
24400 */
24401- if (start_addr != TASK_UNMAPPED_BASE) {
24402- start_addr = TASK_UNMAPPED_BASE;
24403+ if (start_addr != mm->mmap_base) {
24404+ start_addr = mm->mmap_base;
24405 mm->cached_hole_size = 0;
24406 goto full_search;
24407 }
24408 return -ENOMEM;
24409 }
24410- if (!vma || addr + len <= vma->vm_start) {
24411- mm->free_area_cache = addr + len;
24412- return addr;
24413- }
24414+ if (check_heap_stack_gap(vma, addr, len))
24415+ break;
24416 if (addr + mm->cached_hole_size < vma->vm_start)
24417 mm->cached_hole_size = vma->vm_start - addr;
24418 addr = ALIGN(vma->vm_end, huge_page_size(h));
24419 }
24420+
24421+ mm->free_area_cache = addr + len;
24422+ return addr;
24423 }
24424
24425 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24426@@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24427 struct mm_struct *mm = current->mm;
24428 struct vm_area_struct *vma;
24429 unsigned long base = mm->mmap_base;
24430- unsigned long addr = addr0;
24431+ unsigned long addr;
24432 unsigned long largest_hole = mm->cached_hole_size;
24433- unsigned long start_addr;
24434
24435 /* don't allow allocations above current base */
24436 if (mm->free_area_cache > base)
24437@@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24438 largest_hole = 0;
24439 mm->free_area_cache = base;
24440 }
24441-try_again:
24442- start_addr = mm->free_area_cache;
24443
24444 /* make sure it can fit in the remaining address space */
24445 if (mm->free_area_cache < len)
24446 goto fail;
24447
24448 /* either no address requested or can't fit in requested address hole */
24449- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24450+ addr = mm->free_area_cache - len;
24451 do {
24452+ addr &= huge_page_mask(h);
24453 /*
24454 * Lookup failure means no vma is above this address,
24455 * i.e. return with success:
24456@@ -351,10 +357,10 @@ try_again:
24457 if (!vma)
24458 return addr;
24459
24460- if (addr + len <= vma->vm_start) {
24461+ if (check_heap_stack_gap(vma, addr, len)) {
24462 /* remember the address as a hint for next time */
24463- mm->cached_hole_size = largest_hole;
24464- return (mm->free_area_cache = addr);
24465+ mm->cached_hole_size = largest_hole;
24466+ return (mm->free_area_cache = addr);
24467 } else if (mm->free_area_cache == vma->vm_end) {
24468 /* pull free_area_cache down to the first hole */
24469 mm->free_area_cache = vma->vm_start;
24470@@ -363,29 +369,34 @@ try_again:
24471
24472 /* remember the largest hole we saw so far */
24473 if (addr + largest_hole < vma->vm_start)
24474- largest_hole = vma->vm_start - addr;
24475+ largest_hole = vma->vm_start - addr;
24476
24477 /* try just below the current vma->vm_start */
24478- addr = (vma->vm_start - len) & huge_page_mask(h);
24479- } while (len <= vma->vm_start);
24480+ addr = skip_heap_stack_gap(vma, len);
24481+ } while (!IS_ERR_VALUE(addr));
24482
24483 fail:
24484 /*
24485- * if hint left us with no space for the requested
24486- * mapping then try again:
24487- */
24488- if (start_addr != base) {
24489- mm->free_area_cache = base;
24490- largest_hole = 0;
24491- goto try_again;
24492- }
24493- /*
24494 * A failed mmap() very likely causes application failure,
24495 * so fall back to the bottom-up function here. This scenario
24496 * can happen with large stack limits and large mmap()
24497 * allocations.
24498 */
24499- mm->free_area_cache = TASK_UNMAPPED_BASE;
24500+
24501+#ifdef CONFIG_PAX_SEGMEXEC
24502+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24503+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24504+ else
24505+#endif
24506+
24507+ mm->mmap_base = TASK_UNMAPPED_BASE;
24508+
24509+#ifdef CONFIG_PAX_RANDMMAP
24510+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24511+ mm->mmap_base += mm->delta_mmap;
24512+#endif
24513+
24514+ mm->free_area_cache = mm->mmap_base;
24515 mm->cached_hole_size = ~0UL;
24516 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24517 len, pgoff, flags);
24518@@ -393,6 +404,7 @@ fail:
24519 /*
24520 * Restore the topdown base:
24521 */
24522+ mm->mmap_base = base;
24523 mm->free_area_cache = base;
24524 mm->cached_hole_size = ~0UL;
24525
24526@@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24527 struct hstate *h = hstate_file(file);
24528 struct mm_struct *mm = current->mm;
24529 struct vm_area_struct *vma;
24530+ unsigned long pax_task_size = TASK_SIZE;
24531
24532 if (len & ~huge_page_mask(h))
24533 return -EINVAL;
24534- if (len > TASK_SIZE)
24535+
24536+#ifdef CONFIG_PAX_SEGMEXEC
24537+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24538+ pax_task_size = SEGMEXEC_TASK_SIZE;
24539+#endif
24540+
24541+ pax_task_size -= PAGE_SIZE;
24542+
24543+ if (len > pax_task_size)
24544 return -ENOMEM;
24545
24546 if (flags & MAP_FIXED) {
24547@@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24548 if (addr) {
24549 addr = ALIGN(addr, huge_page_size(h));
24550 vma = find_vma(mm, addr);
24551- if (TASK_SIZE - len >= addr &&
24552- (!vma || addr + len <= vma->vm_start))
24553+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24554 return addr;
24555 }
24556 if (mm->get_unmapped_area == arch_get_unmapped_area)
24557diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24558index bc4e9d8..ca4c14b 100644
24559--- a/arch/x86/mm/init.c
24560+++ b/arch/x86/mm/init.c
24561@@ -16,6 +16,8 @@
24562 #include <asm/tlb.h>
24563 #include <asm/proto.h>
24564 #include <asm/dma.h> /* for MAX_DMA_PFN */
24565+#include <asm/desc.h>
24566+#include <asm/bios_ebda.h>
24567
24568 unsigned long __initdata pgt_buf_start;
24569 unsigned long __meminitdata pgt_buf_end;
24570@@ -38,7 +40,7 @@ struct map_range {
24571 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24572 int use_pse, int use_gbpages)
24573 {
24574- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24575+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24576 phys_addr_t base;
24577
24578 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24579@@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24580 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24581 * mmio resources as well as potential bios/acpi data regions.
24582 */
24583+
24584+#ifdef CONFIG_GRKERNSEC_KMEM
24585+static unsigned int ebda_start __read_only;
24586+static unsigned int ebda_end __read_only;
24587+#endif
24588+
24589 int devmem_is_allowed(unsigned long pagenr)
24590 {
24591+#ifdef CONFIG_GRKERNSEC_KMEM
24592+ /* allow BDA */
24593+ if (!pagenr)
24594+ return 1;
24595+ /* allow EBDA */
24596+ if (pagenr >= ebda_start && pagenr < ebda_end)
24597+ return 1;
24598+#else
24599+ if (!pagenr)
24600+ return 1;
24601+#ifdef CONFIG_VM86
24602+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24603+ return 1;
24604+#endif
24605+#endif
24606+
24607+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24608+ return 1;
24609+#ifdef CONFIG_GRKERNSEC_KMEM
24610+ /* throw out everything else below 1MB */
24611 if (pagenr <= 256)
24612- return 1;
24613+ return 0;
24614+#endif
24615 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24616 return 0;
24617 if (!page_is_ram(pagenr))
24618@@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24619 #endif
24620 }
24621
24622+#ifdef CONFIG_GRKERNSEC_KMEM
24623+static inline void gr_init_ebda(void)
24624+{
24625+ unsigned int ebda_addr;
24626+ unsigned int ebda_size = 0;
24627+
24628+ ebda_addr = get_bios_ebda();
24629+ if (ebda_addr) {
24630+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24631+ ebda_size <<= 10;
24632+ }
24633+ if (ebda_addr && ebda_size) {
24634+ ebda_start = ebda_addr >> PAGE_SHIFT;
24635+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24636+ } else {
24637+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24638+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24639+ }
24640+}
24641+#else
24642+static inline void gr_init_ebda(void) { }
24643+#endif
24644+
24645 void free_initmem(void)
24646 {
24647+#ifdef CONFIG_PAX_KERNEXEC
24648+#ifdef CONFIG_X86_32
24649+ /* PaX: limit KERNEL_CS to actual size */
24650+ unsigned long addr, limit;
24651+ struct desc_struct d;
24652+ int cpu;
24653+#else
24654+ pgd_t *pgd;
24655+ pud_t *pud;
24656+ pmd_t *pmd;
24657+ unsigned long addr, end;
24658+#endif
24659+#endif
24660+
24661+ gr_init_ebda();
24662+
24663+#ifdef CONFIG_PAX_KERNEXEC
24664+#ifdef CONFIG_X86_32
24665+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24666+ limit = (limit - 1UL) >> PAGE_SHIFT;
24667+
24668+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24669+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24670+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24671+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24672+ }
24673+
24674+ /* PaX: make KERNEL_CS read-only */
24675+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24676+ if (!paravirt_enabled())
24677+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24678+/*
24679+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24680+ pgd = pgd_offset_k(addr);
24681+ pud = pud_offset(pgd, addr);
24682+ pmd = pmd_offset(pud, addr);
24683+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24684+ }
24685+*/
24686+#ifdef CONFIG_X86_PAE
24687+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24688+/*
24689+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24690+ pgd = pgd_offset_k(addr);
24691+ pud = pud_offset(pgd, addr);
24692+ pmd = pmd_offset(pud, addr);
24693+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24694+ }
24695+*/
24696+#endif
24697+
24698+#ifdef CONFIG_MODULES
24699+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24700+#endif
24701+
24702+#else
24703+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24704+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24705+ pgd = pgd_offset_k(addr);
24706+ pud = pud_offset(pgd, addr);
24707+ pmd = pmd_offset(pud, addr);
24708+ if (!pmd_present(*pmd))
24709+ continue;
24710+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24711+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24712+ else
24713+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24714+ }
24715+
24716+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24717+ end = addr + KERNEL_IMAGE_SIZE;
24718+ for (; addr < end; addr += PMD_SIZE) {
24719+ pgd = pgd_offset_k(addr);
24720+ pud = pud_offset(pgd, addr);
24721+ pmd = pmd_offset(pud, addr);
24722+ if (!pmd_present(*pmd))
24723+ continue;
24724+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24725+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24726+ }
24727+#endif
24728+
24729+ flush_tlb_all();
24730+#endif
24731+
24732 free_init_pages("unused kernel memory",
24733 (unsigned long)(&__init_begin),
24734 (unsigned long)(&__init_end));
24735diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24736index 575d86f..4987469 100644
24737--- a/arch/x86/mm/init_32.c
24738+++ b/arch/x86/mm/init_32.c
24739@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24740 }
24741
24742 /*
24743- * Creates a middle page table and puts a pointer to it in the
24744- * given global directory entry. This only returns the gd entry
24745- * in non-PAE compilation mode, since the middle layer is folded.
24746- */
24747-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24748-{
24749- pud_t *pud;
24750- pmd_t *pmd_table;
24751-
24752-#ifdef CONFIG_X86_PAE
24753- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24754- if (after_bootmem)
24755- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24756- else
24757- pmd_table = (pmd_t *)alloc_low_page();
24758- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24759- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24760- pud = pud_offset(pgd, 0);
24761- BUG_ON(pmd_table != pmd_offset(pud, 0));
24762-
24763- return pmd_table;
24764- }
24765-#endif
24766- pud = pud_offset(pgd, 0);
24767- pmd_table = pmd_offset(pud, 0);
24768-
24769- return pmd_table;
24770-}
24771-
24772-/*
24773 * Create a page table and place a pointer to it in a middle page
24774 * directory entry:
24775 */
24776@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24777 page_table = (pte_t *)alloc_low_page();
24778
24779 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24780+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24781+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24782+#else
24783 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24784+#endif
24785 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24786 }
24787
24788 return pte_offset_kernel(pmd, 0);
24789 }
24790
24791+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24792+{
24793+ pud_t *pud;
24794+ pmd_t *pmd_table;
24795+
24796+ pud = pud_offset(pgd, 0);
24797+ pmd_table = pmd_offset(pud, 0);
24798+
24799+ return pmd_table;
24800+}
24801+
24802 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24803 {
24804 int pgd_idx = pgd_index(vaddr);
24805@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24806 int pgd_idx, pmd_idx;
24807 unsigned long vaddr;
24808 pgd_t *pgd;
24809+ pud_t *pud;
24810 pmd_t *pmd;
24811 pte_t *pte = NULL;
24812
24813@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24814 pgd = pgd_base + pgd_idx;
24815
24816 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24817- pmd = one_md_table_init(pgd);
24818- pmd = pmd + pmd_index(vaddr);
24819+ pud = pud_offset(pgd, vaddr);
24820+ pmd = pmd_offset(pud, vaddr);
24821+
24822+#ifdef CONFIG_X86_PAE
24823+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24824+#endif
24825+
24826 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24827 pmd++, pmd_idx++) {
24828 pte = page_table_kmap_check(one_page_table_init(pmd),
24829@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24830 }
24831 }
24832
24833-static inline int is_kernel_text(unsigned long addr)
24834+static inline int is_kernel_text(unsigned long start, unsigned long end)
24835 {
24836- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24837- return 1;
24838- return 0;
24839+ if ((start > ktla_ktva((unsigned long)_etext) ||
24840+ end <= ktla_ktva((unsigned long)_stext)) &&
24841+ (start > ktla_ktva((unsigned long)_einittext) ||
24842+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24843+
24844+#ifdef CONFIG_ACPI_SLEEP
24845+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24846+#endif
24847+
24848+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24849+ return 0;
24850+ return 1;
24851 }
24852
24853 /*
24854@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24855 unsigned long last_map_addr = end;
24856 unsigned long start_pfn, end_pfn;
24857 pgd_t *pgd_base = swapper_pg_dir;
24858- int pgd_idx, pmd_idx, pte_ofs;
24859+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24860 unsigned long pfn;
24861 pgd_t *pgd;
24862+ pud_t *pud;
24863 pmd_t *pmd;
24864 pte_t *pte;
24865 unsigned pages_2m, pages_4k;
24866@@ -280,8 +281,13 @@ repeat:
24867 pfn = start_pfn;
24868 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24869 pgd = pgd_base + pgd_idx;
24870- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24871- pmd = one_md_table_init(pgd);
24872+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24873+ pud = pud_offset(pgd, 0);
24874+ pmd = pmd_offset(pud, 0);
24875+
24876+#ifdef CONFIG_X86_PAE
24877+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24878+#endif
24879
24880 if (pfn >= end_pfn)
24881 continue;
24882@@ -293,14 +299,13 @@ repeat:
24883 #endif
24884 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24885 pmd++, pmd_idx++) {
24886- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24887+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24888
24889 /*
24890 * Map with big pages if possible, otherwise
24891 * create normal page tables:
24892 */
24893 if (use_pse) {
24894- unsigned int addr2;
24895 pgprot_t prot = PAGE_KERNEL_LARGE;
24896 /*
24897 * first pass will use the same initial
24898@@ -310,11 +315,7 @@ repeat:
24899 __pgprot(PTE_IDENT_ATTR |
24900 _PAGE_PSE);
24901
24902- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24903- PAGE_OFFSET + PAGE_SIZE-1;
24904-
24905- if (is_kernel_text(addr) ||
24906- is_kernel_text(addr2))
24907+ if (is_kernel_text(address, address + PMD_SIZE))
24908 prot = PAGE_KERNEL_LARGE_EXEC;
24909
24910 pages_2m++;
24911@@ -331,7 +332,7 @@ repeat:
24912 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24913 pte += pte_ofs;
24914 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24915- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24916+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24917 pgprot_t prot = PAGE_KERNEL;
24918 /*
24919 * first pass will use the same initial
24920@@ -339,7 +340,7 @@ repeat:
24921 */
24922 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24923
24924- if (is_kernel_text(addr))
24925+ if (is_kernel_text(address, address + PAGE_SIZE))
24926 prot = PAGE_KERNEL_EXEC;
24927
24928 pages_4k++;
24929@@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24930
24931 pud = pud_offset(pgd, va);
24932 pmd = pmd_offset(pud, va);
24933- if (!pmd_present(*pmd))
24934+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
24935 break;
24936
24937 pte = pte_offset_kernel(pmd, va);
24938@@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24939
24940 static void __init pagetable_init(void)
24941 {
24942- pgd_t *pgd_base = swapper_pg_dir;
24943-
24944- permanent_kmaps_init(pgd_base);
24945+ permanent_kmaps_init(swapper_pg_dir);
24946 }
24947
24948-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24949+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24950 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24951
24952 /* user-defined highmem size */
24953@@ -734,6 +733,12 @@ void __init mem_init(void)
24954
24955 pci_iommu_alloc();
24956
24957+#ifdef CONFIG_PAX_PER_CPU_PGD
24958+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24959+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24960+ KERNEL_PGD_PTRS);
24961+#endif
24962+
24963 #ifdef CONFIG_FLATMEM
24964 BUG_ON(!mem_map);
24965 #endif
24966@@ -760,7 +765,7 @@ void __init mem_init(void)
24967 reservedpages++;
24968
24969 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24970- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24971+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24972 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24973
24974 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24975@@ -801,10 +806,10 @@ void __init mem_init(void)
24976 ((unsigned long)&__init_end -
24977 (unsigned long)&__init_begin) >> 10,
24978
24979- (unsigned long)&_etext, (unsigned long)&_edata,
24980- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24981+ (unsigned long)&_sdata, (unsigned long)&_edata,
24982+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24983
24984- (unsigned long)&_text, (unsigned long)&_etext,
24985+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24986 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24987
24988 /*
24989@@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24990 if (!kernel_set_to_readonly)
24991 return;
24992
24993+ start = ktla_ktva(start);
24994 pr_debug("Set kernel text: %lx - %lx for read write\n",
24995 start, start+size);
24996
24997@@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24998 if (!kernel_set_to_readonly)
24999 return;
25000
25001+ start = ktla_ktva(start);
25002 pr_debug("Set kernel text: %lx - %lx for read only\n",
25003 start, start+size);
25004
25005@@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25006 unsigned long start = PFN_ALIGN(_text);
25007 unsigned long size = PFN_ALIGN(_etext) - start;
25008
25009+ start = ktla_ktva(start);
25010 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25011 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25012 size >> 10);
25013diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25014index 2b6b4a3..c17210d 100644
25015--- a/arch/x86/mm/init_64.c
25016+++ b/arch/x86/mm/init_64.c
25017@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25018 * around without checking the pgd every time.
25019 */
25020
25021-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25022+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25023 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25024
25025 int force_personality32;
25026@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25027
25028 for (address = start; address <= end; address += PGDIR_SIZE) {
25029 const pgd_t *pgd_ref = pgd_offset_k(address);
25030+
25031+#ifdef CONFIG_PAX_PER_CPU_PGD
25032+ unsigned long cpu;
25033+#else
25034 struct page *page;
25035+#endif
25036
25037 if (pgd_none(*pgd_ref))
25038 continue;
25039
25040 spin_lock(&pgd_lock);
25041+
25042+#ifdef CONFIG_PAX_PER_CPU_PGD
25043+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25044+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
25045+#else
25046 list_for_each_entry(page, &pgd_list, lru) {
25047 pgd_t *pgd;
25048 spinlock_t *pgt_lock;
25049@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25050 /* the pgt_lock only for Xen */
25051 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25052 spin_lock(pgt_lock);
25053+#endif
25054
25055 if (pgd_none(*pgd))
25056 set_pgd(pgd, *pgd_ref);
25057@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25058 BUG_ON(pgd_page_vaddr(*pgd)
25059 != pgd_page_vaddr(*pgd_ref));
25060
25061+#ifndef CONFIG_PAX_PER_CPU_PGD
25062 spin_unlock(pgt_lock);
25063+#endif
25064+
25065 }
25066 spin_unlock(&pgd_lock);
25067 }
25068@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25069 {
25070 if (pgd_none(*pgd)) {
25071 pud_t *pud = (pud_t *)spp_getpage();
25072- pgd_populate(&init_mm, pgd, pud);
25073+ pgd_populate_kernel(&init_mm, pgd, pud);
25074 if (pud != pud_offset(pgd, 0))
25075 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25076 pud, pud_offset(pgd, 0));
25077@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25078 {
25079 if (pud_none(*pud)) {
25080 pmd_t *pmd = (pmd_t *) spp_getpage();
25081- pud_populate(&init_mm, pud, pmd);
25082+ pud_populate_kernel(&init_mm, pud, pmd);
25083 if (pmd != pmd_offset(pud, 0))
25084 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25085 pmd, pmd_offset(pud, 0));
25086@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25087 pmd = fill_pmd(pud, vaddr);
25088 pte = fill_pte(pmd, vaddr);
25089
25090+ pax_open_kernel();
25091 set_pte(pte, new_pte);
25092+ pax_close_kernel();
25093
25094 /*
25095 * It's enough to flush this one mapping.
25096@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25097 pgd = pgd_offset_k((unsigned long)__va(phys));
25098 if (pgd_none(*pgd)) {
25099 pud = (pud_t *) spp_getpage();
25100- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25101- _PAGE_USER));
25102+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25103 }
25104 pud = pud_offset(pgd, (unsigned long)__va(phys));
25105 if (pud_none(*pud)) {
25106 pmd = (pmd_t *) spp_getpage();
25107- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25108- _PAGE_USER));
25109+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25110 }
25111 pmd = pmd_offset(pud, phys);
25112 BUG_ON(!pmd_none(*pmd));
25113@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25114 if (pfn >= pgt_buf_top)
25115 panic("alloc_low_page: ran out of memory");
25116
25117- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25118+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25119 clear_page(adr);
25120 *phys = pfn * PAGE_SIZE;
25121 return adr;
25122@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25123
25124 phys = __pa(virt);
25125 left = phys & (PAGE_SIZE - 1);
25126- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25127+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25128 adr = (void *)(((unsigned long)adr) | left);
25129
25130 return adr;
25131@@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25132 unmap_low_page(pmd);
25133
25134 spin_lock(&init_mm.page_table_lock);
25135- pud_populate(&init_mm, pud, __va(pmd_phys));
25136+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25137 spin_unlock(&init_mm.page_table_lock);
25138 }
25139 __flush_tlb_all();
25140@@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
25141 unmap_low_page(pud);
25142
25143 spin_lock(&init_mm.page_table_lock);
25144- pgd_populate(&init_mm, pgd, __va(pud_phys));
25145+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25146 spin_unlock(&init_mm.page_table_lock);
25147 pgd_changed = true;
25148 }
25149@@ -686,6 +700,12 @@ void __init mem_init(void)
25150
25151 pci_iommu_alloc();
25152
25153+#ifdef CONFIG_PAX_PER_CPU_PGD
25154+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25155+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25156+ KERNEL_PGD_PTRS);
25157+#endif
25158+
25159 /* clear_bss() already clear the empty_zero_page */
25160
25161 reservedpages = 0;
25162@@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
25163 static struct vm_area_struct gate_vma = {
25164 .vm_start = VSYSCALL_START,
25165 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25166- .vm_page_prot = PAGE_READONLY_EXEC,
25167- .vm_flags = VM_READ | VM_EXEC
25168+ .vm_page_prot = PAGE_READONLY,
25169+ .vm_flags = VM_READ
25170 };
25171
25172 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25173@@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
25174
25175 const char *arch_vma_name(struct vm_area_struct *vma)
25176 {
25177- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25178+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25179 return "[vdso]";
25180 if (vma == &gate_vma)
25181 return "[vsyscall]";
25182diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25183index 7b179b4..6bd1777 100644
25184--- a/arch/x86/mm/iomap_32.c
25185+++ b/arch/x86/mm/iomap_32.c
25186@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25187 type = kmap_atomic_idx_push();
25188 idx = type + KM_TYPE_NR * smp_processor_id();
25189 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25190+
25191+ pax_open_kernel();
25192 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25193+ pax_close_kernel();
25194+
25195 arch_flush_lazy_mmu_mode();
25196
25197 return (void *)vaddr;
25198diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25199index 78fe3f1..8293b6f 100644
25200--- a/arch/x86/mm/ioremap.c
25201+++ b/arch/x86/mm/ioremap.c
25202@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25203 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25204 int is_ram = page_is_ram(pfn);
25205
25206- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25207+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25208 return NULL;
25209 WARN_ON_ONCE(is_ram);
25210 }
25211@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25212
25213 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25214 if (page_is_ram(start >> PAGE_SHIFT))
25215+#ifdef CONFIG_HIGHMEM
25216+ if ((start >> PAGE_SHIFT) < max_low_pfn)
25217+#endif
25218 return __va(phys);
25219
25220 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25221@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25222 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25223
25224 static __initdata int after_paging_init;
25225-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25226+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25227
25228 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25229 {
25230@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25231 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25232
25233 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25234- memset(bm_pte, 0, sizeof(bm_pte));
25235- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25236+ pmd_populate_user(&init_mm, pmd, bm_pte);
25237
25238 /*
25239 * The boot-ioremap range spans multiple pmds, for which
25240diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25241index d87dd6d..bf3fa66 100644
25242--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25243+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25244@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25245 * memory (e.g. tracked pages)? For now, we need this to avoid
25246 * invoking kmemcheck for PnP BIOS calls.
25247 */
25248- if (regs->flags & X86_VM_MASK)
25249+ if (v8086_mode(regs))
25250 return false;
25251- if (regs->cs != __KERNEL_CS)
25252+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25253 return false;
25254
25255 pte = kmemcheck_pte_lookup(address);
25256diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25257index 845df68..1d8d29f 100644
25258--- a/arch/x86/mm/mmap.c
25259+++ b/arch/x86/mm/mmap.c
25260@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25261 * Leave an at least ~128 MB hole with possible stack randomization.
25262 */
25263 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25264-#define MAX_GAP (TASK_SIZE/6*5)
25265+#define MAX_GAP (pax_task_size/6*5)
25266
25267 static int mmap_is_legacy(void)
25268 {
25269@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25270 return rnd << PAGE_SHIFT;
25271 }
25272
25273-static unsigned long mmap_base(void)
25274+static unsigned long mmap_base(struct mm_struct *mm)
25275 {
25276 unsigned long gap = rlimit(RLIMIT_STACK);
25277+ unsigned long pax_task_size = TASK_SIZE;
25278+
25279+#ifdef CONFIG_PAX_SEGMEXEC
25280+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25281+ pax_task_size = SEGMEXEC_TASK_SIZE;
25282+#endif
25283
25284 if (gap < MIN_GAP)
25285 gap = MIN_GAP;
25286 else if (gap > MAX_GAP)
25287 gap = MAX_GAP;
25288
25289- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25290+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25291 }
25292
25293 /*
25294 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25295 * does, but not when emulating X86_32
25296 */
25297-static unsigned long mmap_legacy_base(void)
25298+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25299 {
25300- if (mmap_is_ia32())
25301+ if (mmap_is_ia32()) {
25302+
25303+#ifdef CONFIG_PAX_SEGMEXEC
25304+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25305+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25306+ else
25307+#endif
25308+
25309 return TASK_UNMAPPED_BASE;
25310- else
25311+ } else
25312 return TASK_UNMAPPED_BASE + mmap_rnd();
25313 }
25314
25315@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25316 void arch_pick_mmap_layout(struct mm_struct *mm)
25317 {
25318 if (mmap_is_legacy()) {
25319- mm->mmap_base = mmap_legacy_base();
25320+ mm->mmap_base = mmap_legacy_base(mm);
25321+
25322+#ifdef CONFIG_PAX_RANDMMAP
25323+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25324+ mm->mmap_base += mm->delta_mmap;
25325+#endif
25326+
25327 mm->get_unmapped_area = arch_get_unmapped_area;
25328 mm->unmap_area = arch_unmap_area;
25329 } else {
25330- mm->mmap_base = mmap_base();
25331+ mm->mmap_base = mmap_base(mm);
25332+
25333+#ifdef CONFIG_PAX_RANDMMAP
25334+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25335+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25336+#endif
25337+
25338 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25339 mm->unmap_area = arch_unmap_area_topdown;
25340 }
25341diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25342index dc0b727..dc9d71a 100644
25343--- a/arch/x86/mm/mmio-mod.c
25344+++ b/arch/x86/mm/mmio-mod.c
25345@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25346 break;
25347 default:
25348 {
25349- unsigned char *ip = (unsigned char *)instptr;
25350+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25351 my_trace->opcode = MMIO_UNKNOWN_OP;
25352 my_trace->width = 0;
25353 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25354@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25355 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25356 void __iomem *addr)
25357 {
25358- static atomic_t next_id;
25359+ static atomic_unchecked_t next_id;
25360 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25361 /* These are page-unaligned. */
25362 struct mmiotrace_map map = {
25363@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25364 .private = trace
25365 },
25366 .phys = offset,
25367- .id = atomic_inc_return(&next_id)
25368+ .id = atomic_inc_return_unchecked(&next_id)
25369 };
25370 map.map_id = trace->id;
25371
25372diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25373index b008656..773eac2 100644
25374--- a/arch/x86/mm/pageattr-test.c
25375+++ b/arch/x86/mm/pageattr-test.c
25376@@ -36,7 +36,7 @@ enum {
25377
25378 static int pte_testbit(pte_t pte)
25379 {
25380- return pte_flags(pte) & _PAGE_UNUSED1;
25381+ return pte_flags(pte) & _PAGE_CPA_TEST;
25382 }
25383
25384 struct split_state {
25385diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25386index a718e0d..45efc32 100644
25387--- a/arch/x86/mm/pageattr.c
25388+++ b/arch/x86/mm/pageattr.c
25389@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25390 */
25391 #ifdef CONFIG_PCI_BIOS
25392 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25393- pgprot_val(forbidden) |= _PAGE_NX;
25394+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25395 #endif
25396
25397 /*
25398@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25399 * Does not cover __inittext since that is gone later on. On
25400 * 64bit we do not enforce !NX on the low mapping
25401 */
25402- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25403- pgprot_val(forbidden) |= _PAGE_NX;
25404+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25405+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25406
25407+#ifdef CONFIG_DEBUG_RODATA
25408 /*
25409 * The .rodata section needs to be read-only. Using the pfn
25410 * catches all aliases.
25411@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25412 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25413 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25414 pgprot_val(forbidden) |= _PAGE_RW;
25415+#endif
25416
25417 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25418 /*
25419@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25420 }
25421 #endif
25422
25423+#ifdef CONFIG_PAX_KERNEXEC
25424+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25425+ pgprot_val(forbidden) |= _PAGE_RW;
25426+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25427+ }
25428+#endif
25429+
25430 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25431
25432 return prot;
25433@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25434 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25435 {
25436 /* change init_mm */
25437+ pax_open_kernel();
25438 set_pte_atomic(kpte, pte);
25439+
25440 #ifdef CONFIG_X86_32
25441 if (!SHARED_KERNEL_PMD) {
25442+
25443+#ifdef CONFIG_PAX_PER_CPU_PGD
25444+ unsigned long cpu;
25445+#else
25446 struct page *page;
25447+#endif
25448
25449+#ifdef CONFIG_PAX_PER_CPU_PGD
25450+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25451+ pgd_t *pgd = get_cpu_pgd(cpu);
25452+#else
25453 list_for_each_entry(page, &pgd_list, lru) {
25454- pgd_t *pgd;
25455+ pgd_t *pgd = (pgd_t *)page_address(page);
25456+#endif
25457+
25458 pud_t *pud;
25459 pmd_t *pmd;
25460
25461- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25462+ pgd += pgd_index(address);
25463 pud = pud_offset(pgd, address);
25464 pmd = pmd_offset(pud, address);
25465 set_pte_atomic((pte_t *)pmd, pte);
25466 }
25467 }
25468 #endif
25469+ pax_close_kernel();
25470 }
25471
25472 static int
25473diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25474index 3d68ef6..7f69136 100644
25475--- a/arch/x86/mm/pat.c
25476+++ b/arch/x86/mm/pat.c
25477@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25478
25479 if (!entry) {
25480 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25481- current->comm, current->pid, start, end - 1);
25482+ current->comm, task_pid_nr(current), start, end - 1);
25483 return -EINVAL;
25484 }
25485
25486@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25487
25488 while (cursor < to) {
25489 if (!devmem_is_allowed(pfn)) {
25490- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25491- current->comm, from, to - 1);
25492+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25493+ current->comm, from, to - 1, cursor);
25494 return 0;
25495 }
25496 cursor += PAGE_SIZE;
25497@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25498 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25499 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25500 "for [mem %#010Lx-%#010Lx]\n",
25501- current->comm, current->pid,
25502+ current->comm, task_pid_nr(current),
25503 cattr_name(flags),
25504 base, (unsigned long long)(base + size-1));
25505 return -EINVAL;
25506@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25507 flags = lookup_memtype(paddr);
25508 if (want_flags != flags) {
25509 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25510- current->comm, current->pid,
25511+ current->comm, task_pid_nr(current),
25512 cattr_name(want_flags),
25513 (unsigned long long)paddr,
25514 (unsigned long long)(paddr + size - 1),
25515@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25516 free_memtype(paddr, paddr + size);
25517 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25518 " for [mem %#010Lx-%#010Lx], got %s\n",
25519- current->comm, current->pid,
25520+ current->comm, task_pid_nr(current),
25521 cattr_name(want_flags),
25522 (unsigned long long)paddr,
25523 (unsigned long long)(paddr + size - 1),
25524diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25525index 9f0614d..92ae64a 100644
25526--- a/arch/x86/mm/pf_in.c
25527+++ b/arch/x86/mm/pf_in.c
25528@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25529 int i;
25530 enum reason_type rv = OTHERS;
25531
25532- p = (unsigned char *)ins_addr;
25533+ p = (unsigned char *)ktla_ktva(ins_addr);
25534 p += skip_prefix(p, &prf);
25535 p += get_opcode(p, &opcode);
25536
25537@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25538 struct prefix_bits prf;
25539 int i;
25540
25541- p = (unsigned char *)ins_addr;
25542+ p = (unsigned char *)ktla_ktva(ins_addr);
25543 p += skip_prefix(p, &prf);
25544 p += get_opcode(p, &opcode);
25545
25546@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25547 struct prefix_bits prf;
25548 int i;
25549
25550- p = (unsigned char *)ins_addr;
25551+ p = (unsigned char *)ktla_ktva(ins_addr);
25552 p += skip_prefix(p, &prf);
25553 p += get_opcode(p, &opcode);
25554
25555@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25556 struct prefix_bits prf;
25557 int i;
25558
25559- p = (unsigned char *)ins_addr;
25560+ p = (unsigned char *)ktla_ktva(ins_addr);
25561 p += skip_prefix(p, &prf);
25562 p += get_opcode(p, &opcode);
25563 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25564@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25565 struct prefix_bits prf;
25566 int i;
25567
25568- p = (unsigned char *)ins_addr;
25569+ p = (unsigned char *)ktla_ktva(ins_addr);
25570 p += skip_prefix(p, &prf);
25571 p += get_opcode(p, &opcode);
25572 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25573diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25574index 8573b83..4f3ed7e 100644
25575--- a/arch/x86/mm/pgtable.c
25576+++ b/arch/x86/mm/pgtable.c
25577@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25578 list_del(&page->lru);
25579 }
25580
25581-#define UNSHARED_PTRS_PER_PGD \
25582- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25583+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25584+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25585
25586+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25587+{
25588+ unsigned int count = USER_PGD_PTRS;
25589
25590+ while (count--)
25591+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25592+}
25593+#endif
25594+
25595+#ifdef CONFIG_PAX_PER_CPU_PGD
25596+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25597+{
25598+ unsigned int count = USER_PGD_PTRS;
25599+
25600+ while (count--) {
25601+ pgd_t pgd;
25602+
25603+#ifdef CONFIG_X86_64
25604+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25605+#else
25606+ pgd = *src++;
25607+#endif
25608+
25609+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25610+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25611+#endif
25612+
25613+ *dst++ = pgd;
25614+ }
25615+
25616+}
25617+#endif
25618+
25619+#ifdef CONFIG_X86_64
25620+#define pxd_t pud_t
25621+#define pyd_t pgd_t
25622+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25623+#define pxd_free(mm, pud) pud_free((mm), (pud))
25624+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25625+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25626+#define PYD_SIZE PGDIR_SIZE
25627+#else
25628+#define pxd_t pmd_t
25629+#define pyd_t pud_t
25630+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25631+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25632+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25633+#define pyd_offset(mm, address) pud_offset((mm), (address))
25634+#define PYD_SIZE PUD_SIZE
25635+#endif
25636+
25637+#ifdef CONFIG_PAX_PER_CPU_PGD
25638+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25639+static inline void pgd_dtor(pgd_t *pgd) {}
25640+#else
25641 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25642 {
25643 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25644@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25645 pgd_list_del(pgd);
25646 spin_unlock(&pgd_lock);
25647 }
25648+#endif
25649
25650 /*
25651 * List of all pgd's needed for non-PAE so it can invalidate entries
25652@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25653 * -- wli
25654 */
25655
25656-#ifdef CONFIG_X86_PAE
25657+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25658 /*
25659 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25660 * updating the top-level pagetable entries to guarantee the
25661@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25662 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25663 * and initialize the kernel pmds here.
25664 */
25665-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25666+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25667
25668 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25669 {
25670@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25671 */
25672 flush_tlb_mm(mm);
25673 }
25674+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25675+#define PREALLOCATED_PXDS USER_PGD_PTRS
25676 #else /* !CONFIG_X86_PAE */
25677
25678 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25679-#define PREALLOCATED_PMDS 0
25680+#define PREALLOCATED_PXDS 0
25681
25682 #endif /* CONFIG_X86_PAE */
25683
25684-static void free_pmds(pmd_t *pmds[])
25685+static void free_pxds(pxd_t *pxds[])
25686 {
25687 int i;
25688
25689- for(i = 0; i < PREALLOCATED_PMDS; i++)
25690- if (pmds[i])
25691- free_page((unsigned long)pmds[i]);
25692+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25693+ if (pxds[i])
25694+ free_page((unsigned long)pxds[i]);
25695 }
25696
25697-static int preallocate_pmds(pmd_t *pmds[])
25698+static int preallocate_pxds(pxd_t *pxds[])
25699 {
25700 int i;
25701 bool failed = false;
25702
25703- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25704- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25705- if (pmd == NULL)
25706+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25707+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25708+ if (pxd == NULL)
25709 failed = true;
25710- pmds[i] = pmd;
25711+ pxds[i] = pxd;
25712 }
25713
25714 if (failed) {
25715- free_pmds(pmds);
25716+ free_pxds(pxds);
25717 return -ENOMEM;
25718 }
25719
25720@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25721 * preallocate which never got a corresponding vma will need to be
25722 * freed manually.
25723 */
25724-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25725+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25726 {
25727 int i;
25728
25729- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25730+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25731 pgd_t pgd = pgdp[i];
25732
25733 if (pgd_val(pgd) != 0) {
25734- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25735+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25736
25737- pgdp[i] = native_make_pgd(0);
25738+ set_pgd(pgdp + i, native_make_pgd(0));
25739
25740- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25741- pmd_free(mm, pmd);
25742+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25743+ pxd_free(mm, pxd);
25744 }
25745 }
25746 }
25747
25748-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25749+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25750 {
25751- pud_t *pud;
25752+ pyd_t *pyd;
25753 unsigned long addr;
25754 int i;
25755
25756- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25757+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25758 return;
25759
25760- pud = pud_offset(pgd, 0);
25761+#ifdef CONFIG_X86_64
25762+ pyd = pyd_offset(mm, 0L);
25763+#else
25764+ pyd = pyd_offset(pgd, 0L);
25765+#endif
25766
25767- for (addr = i = 0; i < PREALLOCATED_PMDS;
25768- i++, pud++, addr += PUD_SIZE) {
25769- pmd_t *pmd = pmds[i];
25770+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25771+ i++, pyd++, addr += PYD_SIZE) {
25772+ pxd_t *pxd = pxds[i];
25773
25774 if (i >= KERNEL_PGD_BOUNDARY)
25775- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25776- sizeof(pmd_t) * PTRS_PER_PMD);
25777+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25778+ sizeof(pxd_t) * PTRS_PER_PMD);
25779
25780- pud_populate(mm, pud, pmd);
25781+ pyd_populate(mm, pyd, pxd);
25782 }
25783 }
25784
25785 pgd_t *pgd_alloc(struct mm_struct *mm)
25786 {
25787 pgd_t *pgd;
25788- pmd_t *pmds[PREALLOCATED_PMDS];
25789+ pxd_t *pxds[PREALLOCATED_PXDS];
25790
25791 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25792
25793@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25794
25795 mm->pgd = pgd;
25796
25797- if (preallocate_pmds(pmds) != 0)
25798+ if (preallocate_pxds(pxds) != 0)
25799 goto out_free_pgd;
25800
25801 if (paravirt_pgd_alloc(mm) != 0)
25802- goto out_free_pmds;
25803+ goto out_free_pxds;
25804
25805 /*
25806 * Make sure that pre-populating the pmds is atomic with
25807@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25808 spin_lock(&pgd_lock);
25809
25810 pgd_ctor(mm, pgd);
25811- pgd_prepopulate_pmd(mm, pgd, pmds);
25812+ pgd_prepopulate_pxd(mm, pgd, pxds);
25813
25814 spin_unlock(&pgd_lock);
25815
25816 return pgd;
25817
25818-out_free_pmds:
25819- free_pmds(pmds);
25820+out_free_pxds:
25821+ free_pxds(pxds);
25822 out_free_pgd:
25823 free_page((unsigned long)pgd);
25824 out:
25825@@ -295,7 +356,7 @@ out:
25826
25827 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25828 {
25829- pgd_mop_up_pmds(mm, pgd);
25830+ pgd_mop_up_pxds(mm, pgd);
25831 pgd_dtor(pgd);
25832 paravirt_pgd_free(mm, pgd);
25833 free_page((unsigned long)pgd);
25834diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25835index a69bcb8..19068ab 100644
25836--- a/arch/x86/mm/pgtable_32.c
25837+++ b/arch/x86/mm/pgtable_32.c
25838@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25839 return;
25840 }
25841 pte = pte_offset_kernel(pmd, vaddr);
25842+
25843+ pax_open_kernel();
25844 if (pte_val(pteval))
25845 set_pte_at(&init_mm, vaddr, pte, pteval);
25846 else
25847 pte_clear(&init_mm, vaddr, pte);
25848+ pax_close_kernel();
25849
25850 /*
25851 * It's enough to flush this one mapping.
25852diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25853index 410531d..0f16030 100644
25854--- a/arch/x86/mm/setup_nx.c
25855+++ b/arch/x86/mm/setup_nx.c
25856@@ -5,8 +5,10 @@
25857 #include <asm/pgtable.h>
25858 #include <asm/proto.h>
25859
25860+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25861 static int disable_nx __cpuinitdata;
25862
25863+#ifndef CONFIG_PAX_PAGEEXEC
25864 /*
25865 * noexec = on|off
25866 *
25867@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25868 return 0;
25869 }
25870 early_param("noexec", noexec_setup);
25871+#endif
25872+
25873+#endif
25874
25875 void __cpuinit x86_configure_nx(void)
25876 {
25877+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25878 if (cpu_has_nx && !disable_nx)
25879 __supported_pte_mask |= _PAGE_NX;
25880 else
25881+#endif
25882 __supported_pte_mask &= ~_PAGE_NX;
25883 }
25884
25885diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25886index 5e57e11..64874249 100644
25887--- a/arch/x86/mm/tlb.c
25888+++ b/arch/x86/mm/tlb.c
25889@@ -66,7 +66,11 @@ void leave_mm(int cpu)
25890 BUG();
25891 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25892 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25893+
25894+#ifndef CONFIG_PAX_PER_CPU_PGD
25895 load_cr3(swapper_pg_dir);
25896+#endif
25897+
25898 }
25899 }
25900 EXPORT_SYMBOL_GPL(leave_mm);
25901diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25902index 877b9a1..a8ecf42 100644
25903--- a/arch/x86/net/bpf_jit.S
25904+++ b/arch/x86/net/bpf_jit.S
25905@@ -9,6 +9,7 @@
25906 */
25907 #include <linux/linkage.h>
25908 #include <asm/dwarf2.h>
25909+#include <asm/alternative-asm.h>
25910
25911 /*
25912 * Calling convention :
25913@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25914 jle bpf_slow_path_word
25915 mov (SKBDATA,%rsi),%eax
25916 bswap %eax /* ntohl() */
25917+ pax_force_retaddr
25918 ret
25919
25920 sk_load_half:
25921@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25922 jle bpf_slow_path_half
25923 movzwl (SKBDATA,%rsi),%eax
25924 rol $8,%ax # ntohs()
25925+ pax_force_retaddr
25926 ret
25927
25928 sk_load_byte:
25929@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25930 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25931 jle bpf_slow_path_byte
25932 movzbl (SKBDATA,%rsi),%eax
25933+ pax_force_retaddr
25934 ret
25935
25936 /**
25937@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25938 movzbl (SKBDATA,%rsi),%ebx
25939 and $15,%bl
25940 shl $2,%bl
25941+ pax_force_retaddr
25942 ret
25943
25944 /* rsi contains offset and can be scratched */
25945@@ -109,6 +114,7 @@ bpf_slow_path_word:
25946 js bpf_error
25947 mov -12(%rbp),%eax
25948 bswap %eax
25949+ pax_force_retaddr
25950 ret
25951
25952 bpf_slow_path_half:
25953@@ -117,12 +123,14 @@ bpf_slow_path_half:
25954 mov -12(%rbp),%ax
25955 rol $8,%ax
25956 movzwl %ax,%eax
25957+ pax_force_retaddr
25958 ret
25959
25960 bpf_slow_path_byte:
25961 bpf_slow_path_common(1)
25962 js bpf_error
25963 movzbl -12(%rbp),%eax
25964+ pax_force_retaddr
25965 ret
25966
25967 bpf_slow_path_byte_msh:
25968@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25969 and $15,%al
25970 shl $2,%al
25971 xchg %eax,%ebx
25972+ pax_force_retaddr
25973 ret
25974
25975 #define sk_negative_common(SIZE) \
25976@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25977 sk_negative_common(4)
25978 mov (%rax), %eax
25979 bswap %eax
25980+ pax_force_retaddr
25981 ret
25982
25983 bpf_slow_path_half_neg:
25984@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25985 mov (%rax),%ax
25986 rol $8,%ax
25987 movzwl %ax,%eax
25988+ pax_force_retaddr
25989 ret
25990
25991 bpf_slow_path_byte_neg:
25992@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25993 .globl sk_load_byte_negative_offset
25994 sk_negative_common(1)
25995 movzbl (%rax), %eax
25996+ pax_force_retaddr
25997 ret
25998
25999 bpf_slow_path_byte_msh_neg:
26000@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26001 and $15,%al
26002 shl $2,%al
26003 xchg %eax,%ebx
26004+ pax_force_retaddr
26005 ret
26006
26007 bpf_error:
26008@@ -197,4 +210,5 @@ bpf_error:
26009 xor %eax,%eax
26010 mov -8(%rbp),%rbx
26011 leaveq
26012+ pax_force_retaddr
26013 ret
26014diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26015index 0597f95..a12c36e 100644
26016--- a/arch/x86/net/bpf_jit_comp.c
26017+++ b/arch/x86/net/bpf_jit_comp.c
26018@@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26019 set_fs(old_fs);
26020 }
26021
26022+struct bpf_jit_work {
26023+ struct work_struct work;
26024+ void *image;
26025+};
26026+
26027 #define CHOOSE_LOAD_FUNC(K, func) \
26028 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26029
26030@@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26031 if (addrs == NULL)
26032 return;
26033
26034+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26035+ if (!fp->work)
26036+ goto out;
26037+
26038 /* Before first pass, make a rough estimation of addrs[]
26039 * each bpf instruction is translated to less than 64 bytes
26040 */
26041@@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26042 break;
26043 default:
26044 /* hmm, too complex filter, give up with jit compiler */
26045- goto out;
26046+ goto error;
26047 }
26048 ilen = prog - temp;
26049 if (image) {
26050 if (unlikely(proglen + ilen > oldproglen)) {
26051 pr_err("bpb_jit_compile fatal error\n");
26052- kfree(addrs);
26053- module_free(NULL, image);
26054- return;
26055+ module_free_exec(NULL, image);
26056+ goto error;
26057 }
26058+ pax_open_kernel();
26059 memcpy(image + proglen, temp, ilen);
26060+ pax_close_kernel();
26061 }
26062 proglen += ilen;
26063 addrs[i] = proglen;
26064@@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26065 break;
26066 }
26067 if (proglen == oldproglen) {
26068- image = module_alloc(max_t(unsigned int,
26069- proglen,
26070- sizeof(struct work_struct)));
26071+ image = module_alloc_exec(proglen);
26072 if (!image)
26073- goto out;
26074+ goto error;
26075 }
26076 oldproglen = proglen;
26077 }
26078@@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26079 bpf_flush_icache(image, image + proglen);
26080
26081 fp->bpf_func = (void *)image;
26082- }
26083+ } else
26084+error:
26085+ kfree(fp->work);
26086+
26087 out:
26088 kfree(addrs);
26089 return;
26090@@ -648,18 +659,20 @@ out:
26091
26092 static void jit_free_defer(struct work_struct *arg)
26093 {
26094- module_free(NULL, arg);
26095+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26096+ kfree(arg);
26097 }
26098
26099 /* run from softirq, we must use a work_struct to call
26100- * module_free() from process context
26101+ * module_free_exec() from process context
26102 */
26103 void bpf_jit_free(struct sk_filter *fp)
26104 {
26105 if (fp->bpf_func != sk_run_filter) {
26106- struct work_struct *work = (struct work_struct *)fp->bpf_func;
26107+ struct work_struct *work = &fp->work->work;
26108
26109 INIT_WORK(work, jit_free_defer);
26110+ fp->work->image = fp->bpf_func;
26111 schedule_work(work);
26112 }
26113 }
26114diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26115index d6aa6e8..266395a 100644
26116--- a/arch/x86/oprofile/backtrace.c
26117+++ b/arch/x86/oprofile/backtrace.c
26118@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26119 struct stack_frame_ia32 *fp;
26120 unsigned long bytes;
26121
26122- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26123+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26124 if (bytes != sizeof(bufhead))
26125 return NULL;
26126
26127- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26128+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26129
26130 oprofile_add_trace(bufhead[0].return_address);
26131
26132@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26133 struct stack_frame bufhead[2];
26134 unsigned long bytes;
26135
26136- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26137+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26138 if (bytes != sizeof(bufhead))
26139 return NULL;
26140
26141@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26142 {
26143 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26144
26145- if (!user_mode_vm(regs)) {
26146+ if (!user_mode(regs)) {
26147 unsigned long stack = kernel_stack_pointer(regs);
26148 if (depth)
26149 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26150diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26151index 140942f..8a5cc55 100644
26152--- a/arch/x86/pci/mrst.c
26153+++ b/arch/x86/pci/mrst.c
26154@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26155 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26156 pci_mmcfg_late_init();
26157 pcibios_enable_irq = mrst_pci_irq_enable;
26158- pci_root_ops = pci_mrst_ops;
26159+ pax_open_kernel();
26160+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26161+ pax_close_kernel();
26162 pci_soc_mode = 1;
26163 /* Continue with standard init */
26164 return 1;
26165diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26166index da8fe05..7ee6704 100644
26167--- a/arch/x86/pci/pcbios.c
26168+++ b/arch/x86/pci/pcbios.c
26169@@ -79,50 +79,93 @@ union bios32 {
26170 static struct {
26171 unsigned long address;
26172 unsigned short segment;
26173-} bios32_indirect = { 0, __KERNEL_CS };
26174+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26175
26176 /*
26177 * Returns the entry point for the given service, NULL on error
26178 */
26179
26180-static unsigned long bios32_service(unsigned long service)
26181+static unsigned long __devinit bios32_service(unsigned long service)
26182 {
26183 unsigned char return_code; /* %al */
26184 unsigned long address; /* %ebx */
26185 unsigned long length; /* %ecx */
26186 unsigned long entry; /* %edx */
26187 unsigned long flags;
26188+ struct desc_struct d, *gdt;
26189
26190 local_irq_save(flags);
26191- __asm__("lcall *(%%edi); cld"
26192+
26193+ gdt = get_cpu_gdt_table(smp_processor_id());
26194+
26195+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26196+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26197+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26198+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26199+
26200+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26201 : "=a" (return_code),
26202 "=b" (address),
26203 "=c" (length),
26204 "=d" (entry)
26205 : "0" (service),
26206 "1" (0),
26207- "D" (&bios32_indirect));
26208+ "D" (&bios32_indirect),
26209+ "r"(__PCIBIOS_DS)
26210+ : "memory");
26211+
26212+ pax_open_kernel();
26213+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26214+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26215+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26216+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26217+ pax_close_kernel();
26218+
26219 local_irq_restore(flags);
26220
26221 switch (return_code) {
26222- case 0:
26223- return address + entry;
26224- case 0x80: /* Not present */
26225- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26226- return 0;
26227- default: /* Shouldn't happen */
26228- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26229- service, return_code);
26230+ case 0: {
26231+ int cpu;
26232+ unsigned char flags;
26233+
26234+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26235+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26236+ printk(KERN_WARNING "bios32_service: not valid\n");
26237 return 0;
26238+ }
26239+ address = address + PAGE_OFFSET;
26240+ length += 16UL; /* some BIOSs underreport this... */
26241+ flags = 4;
26242+ if (length >= 64*1024*1024) {
26243+ length >>= PAGE_SHIFT;
26244+ flags |= 8;
26245+ }
26246+
26247+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26248+ gdt = get_cpu_gdt_table(cpu);
26249+ pack_descriptor(&d, address, length, 0x9b, flags);
26250+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26251+ pack_descriptor(&d, address, length, 0x93, flags);
26252+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26253+ }
26254+ return entry;
26255+ }
26256+ case 0x80: /* Not present */
26257+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26258+ return 0;
26259+ default: /* Shouldn't happen */
26260+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26261+ service, return_code);
26262+ return 0;
26263 }
26264 }
26265
26266 static struct {
26267 unsigned long address;
26268 unsigned short segment;
26269-} pci_indirect = { 0, __KERNEL_CS };
26270+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26271
26272-static int pci_bios_present;
26273+static int pci_bios_present __read_only;
26274
26275 static int __devinit check_pcibios(void)
26276 {
26277@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26278 unsigned long flags, pcibios_entry;
26279
26280 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26281- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26282+ pci_indirect.address = pcibios_entry;
26283
26284 local_irq_save(flags);
26285- __asm__(
26286- "lcall *(%%edi); cld\n\t"
26287+ __asm__("movw %w6, %%ds\n\t"
26288+ "lcall *%%ss:(%%edi); cld\n\t"
26289+ "push %%ss\n\t"
26290+ "pop %%ds\n\t"
26291 "jc 1f\n\t"
26292 "xor %%ah, %%ah\n"
26293 "1:"
26294@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26295 "=b" (ebx),
26296 "=c" (ecx)
26297 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26298- "D" (&pci_indirect)
26299+ "D" (&pci_indirect),
26300+ "r" (__PCIBIOS_DS)
26301 : "memory");
26302 local_irq_restore(flags);
26303
26304@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26305
26306 switch (len) {
26307 case 1:
26308- __asm__("lcall *(%%esi); cld\n\t"
26309+ __asm__("movw %w6, %%ds\n\t"
26310+ "lcall *%%ss:(%%esi); cld\n\t"
26311+ "push %%ss\n\t"
26312+ "pop %%ds\n\t"
26313 "jc 1f\n\t"
26314 "xor %%ah, %%ah\n"
26315 "1:"
26316@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26317 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26318 "b" (bx),
26319 "D" ((long)reg),
26320- "S" (&pci_indirect));
26321+ "S" (&pci_indirect),
26322+ "r" (__PCIBIOS_DS));
26323 /*
26324 * Zero-extend the result beyond 8 bits, do not trust the
26325 * BIOS having done it:
26326@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26327 *value &= 0xff;
26328 break;
26329 case 2:
26330- __asm__("lcall *(%%esi); cld\n\t"
26331+ __asm__("movw %w6, %%ds\n\t"
26332+ "lcall *%%ss:(%%esi); cld\n\t"
26333+ "push %%ss\n\t"
26334+ "pop %%ds\n\t"
26335 "jc 1f\n\t"
26336 "xor %%ah, %%ah\n"
26337 "1:"
26338@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26339 : "1" (PCIBIOS_READ_CONFIG_WORD),
26340 "b" (bx),
26341 "D" ((long)reg),
26342- "S" (&pci_indirect));
26343+ "S" (&pci_indirect),
26344+ "r" (__PCIBIOS_DS));
26345 /*
26346 * Zero-extend the result beyond 16 bits, do not trust the
26347 * BIOS having done it:
26348@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26349 *value &= 0xffff;
26350 break;
26351 case 4:
26352- __asm__("lcall *(%%esi); cld\n\t"
26353+ __asm__("movw %w6, %%ds\n\t"
26354+ "lcall *%%ss:(%%esi); cld\n\t"
26355+ "push %%ss\n\t"
26356+ "pop %%ds\n\t"
26357 "jc 1f\n\t"
26358 "xor %%ah, %%ah\n"
26359 "1:"
26360@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26361 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26362 "b" (bx),
26363 "D" ((long)reg),
26364- "S" (&pci_indirect));
26365+ "S" (&pci_indirect),
26366+ "r" (__PCIBIOS_DS));
26367 break;
26368 }
26369
26370@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26371
26372 switch (len) {
26373 case 1:
26374- __asm__("lcall *(%%esi); cld\n\t"
26375+ __asm__("movw %w6, %%ds\n\t"
26376+ "lcall *%%ss:(%%esi); cld\n\t"
26377+ "push %%ss\n\t"
26378+ "pop %%ds\n\t"
26379 "jc 1f\n\t"
26380 "xor %%ah, %%ah\n"
26381 "1:"
26382@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26383 "c" (value),
26384 "b" (bx),
26385 "D" ((long)reg),
26386- "S" (&pci_indirect));
26387+ "S" (&pci_indirect),
26388+ "r" (__PCIBIOS_DS));
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@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26400 "c" (value),
26401 "b" (bx),
26402 "D" ((long)reg),
26403- "S" (&pci_indirect));
26404+ "S" (&pci_indirect),
26405+ "r" (__PCIBIOS_DS));
26406 break;
26407 case 4:
26408- __asm__("lcall *(%%esi); cld\n\t"
26409+ __asm__("movw %w6, %%ds\n\t"
26410+ "lcall *%%ss:(%%esi); cld\n\t"
26411+ "push %%ss\n\t"
26412+ "pop %%ds\n\t"
26413 "jc 1f\n\t"
26414 "xor %%ah, %%ah\n"
26415 "1:"
26416@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26417 "c" (value),
26418 "b" (bx),
26419 "D" ((long)reg),
26420- "S" (&pci_indirect));
26421+ "S" (&pci_indirect),
26422+ "r" (__PCIBIOS_DS));
26423 break;
26424 }
26425
26426@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26427
26428 DBG("PCI: Fetching IRQ routing table... ");
26429 __asm__("push %%es\n\t"
26430+ "movw %w8, %%ds\n\t"
26431 "push %%ds\n\t"
26432 "pop %%es\n\t"
26433- "lcall *(%%esi); cld\n\t"
26434+ "lcall *%%ss:(%%esi); cld\n\t"
26435 "pop %%es\n\t"
26436+ "push %%ss\n\t"
26437+ "pop %%ds\n"
26438 "jc 1f\n\t"
26439 "xor %%ah, %%ah\n"
26440 "1:"
26441@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26442 "1" (0),
26443 "D" ((long) &opt),
26444 "S" (&pci_indirect),
26445- "m" (opt)
26446+ "m" (opt),
26447+ "r" (__PCIBIOS_DS)
26448 : "memory");
26449 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26450 if (ret & 0xff00)
26451@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26452 {
26453 int ret;
26454
26455- __asm__("lcall *(%%esi); cld\n\t"
26456+ __asm__("movw %w5, %%ds\n\t"
26457+ "lcall *%%ss:(%%esi); cld\n\t"
26458+ "push %%ss\n\t"
26459+ "pop %%ds\n"
26460 "jc 1f\n\t"
26461 "xor %%ah, %%ah\n"
26462 "1:"
26463@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26464 : "0" (PCIBIOS_SET_PCI_HW_INT),
26465 "b" ((dev->bus->number << 8) | dev->devfn),
26466 "c" ((irq << 8) | (pin + 10)),
26467- "S" (&pci_indirect));
26468+ "S" (&pci_indirect),
26469+ "r" (__PCIBIOS_DS));
26470 return !(ret & 0xff00);
26471 }
26472 EXPORT_SYMBOL(pcibios_set_irq_routing);
26473diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26474index 40e4469..1ab536e 100644
26475--- a/arch/x86/platform/efi/efi_32.c
26476+++ b/arch/x86/platform/efi/efi_32.c
26477@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26478 {
26479 struct desc_ptr gdt_descr;
26480
26481+#ifdef CONFIG_PAX_KERNEXEC
26482+ struct desc_struct d;
26483+#endif
26484+
26485 local_irq_save(efi_rt_eflags);
26486
26487 load_cr3(initial_page_table);
26488 __flush_tlb_all();
26489
26490+#ifdef CONFIG_PAX_KERNEXEC
26491+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26492+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26493+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26494+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26495+#endif
26496+
26497 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26498 gdt_descr.size = GDT_SIZE - 1;
26499 load_gdt(&gdt_descr);
26500@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26501 {
26502 struct desc_ptr gdt_descr;
26503
26504+#ifdef CONFIG_PAX_KERNEXEC
26505+ struct desc_struct d;
26506+
26507+ memset(&d, 0, sizeof d);
26508+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26509+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26510+#endif
26511+
26512 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26513 gdt_descr.size = GDT_SIZE - 1;
26514 load_gdt(&gdt_descr);
26515diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26516index fbe66e6..eae5e38 100644
26517--- a/arch/x86/platform/efi/efi_stub_32.S
26518+++ b/arch/x86/platform/efi/efi_stub_32.S
26519@@ -6,7 +6,9 @@
26520 */
26521
26522 #include <linux/linkage.h>
26523+#include <linux/init.h>
26524 #include <asm/page_types.h>
26525+#include <asm/segment.h>
26526
26527 /*
26528 * efi_call_phys(void *, ...) is a function with variable parameters.
26529@@ -20,7 +22,7 @@
26530 * service functions will comply with gcc calling convention, too.
26531 */
26532
26533-.text
26534+__INIT
26535 ENTRY(efi_call_phys)
26536 /*
26537 * 0. The function can only be called in Linux kernel. So CS has been
26538@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26539 * The mapping of lower virtual memory has been created in prelog and
26540 * epilog.
26541 */
26542- movl $1f, %edx
26543- subl $__PAGE_OFFSET, %edx
26544- jmp *%edx
26545+#ifdef CONFIG_PAX_KERNEXEC
26546+ movl $(__KERNEXEC_EFI_DS), %edx
26547+ mov %edx, %ds
26548+ mov %edx, %es
26549+ mov %edx, %ss
26550+ addl $2f,(1f)
26551+ ljmp *(1f)
26552+
26553+__INITDATA
26554+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26555+.previous
26556+
26557+2:
26558+ subl $2b,(1b)
26559+#else
26560+ jmp 1f-__PAGE_OFFSET
26561 1:
26562+#endif
26563
26564 /*
26565 * 2. Now on the top of stack is the return
26566@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26567 * parameter 2, ..., param n. To make things easy, we save the return
26568 * address of efi_call_phys in a global variable.
26569 */
26570- popl %edx
26571- movl %edx, saved_return_addr
26572- /* get the function pointer into ECX*/
26573- popl %ecx
26574- movl %ecx, efi_rt_function_ptr
26575- movl $2f, %edx
26576- subl $__PAGE_OFFSET, %edx
26577- pushl %edx
26578+ popl (saved_return_addr)
26579+ popl (efi_rt_function_ptr)
26580
26581 /*
26582 * 3. Clear PG bit in %CR0.
26583@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26584 /*
26585 * 5. Call the physical function.
26586 */
26587- jmp *%ecx
26588+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26589
26590-2:
26591 /*
26592 * 6. After EFI runtime service returns, control will return to
26593 * following instruction. We'd better readjust stack pointer first.
26594@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26595 movl %cr0, %edx
26596 orl $0x80000000, %edx
26597 movl %edx, %cr0
26598- jmp 1f
26599-1:
26600+
26601 /*
26602 * 8. Now restore the virtual mode from flat mode by
26603 * adding EIP with PAGE_OFFSET.
26604 */
26605- movl $1f, %edx
26606- jmp *%edx
26607+#ifdef CONFIG_PAX_KERNEXEC
26608+ movl $(__KERNEL_DS), %edx
26609+ mov %edx, %ds
26610+ mov %edx, %es
26611+ mov %edx, %ss
26612+ ljmp $(__KERNEL_CS),$1f
26613+#else
26614+ jmp 1f+__PAGE_OFFSET
26615+#endif
26616 1:
26617
26618 /*
26619 * 9. Balance the stack. And because EAX contain the return value,
26620 * we'd better not clobber it.
26621 */
26622- leal efi_rt_function_ptr, %edx
26623- movl (%edx), %ecx
26624- pushl %ecx
26625+ pushl (efi_rt_function_ptr)
26626
26627 /*
26628- * 10. Push the saved return address onto the stack and return.
26629+ * 10. Return to the saved return address.
26630 */
26631- leal saved_return_addr, %edx
26632- movl (%edx), %ecx
26633- pushl %ecx
26634- ret
26635+ jmpl *(saved_return_addr)
26636 ENDPROC(efi_call_phys)
26637 .previous
26638
26639-.data
26640+__INITDATA
26641 saved_return_addr:
26642 .long 0
26643 efi_rt_function_ptr:
26644diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26645index 4c07cca..2c8427d 100644
26646--- a/arch/x86/platform/efi/efi_stub_64.S
26647+++ b/arch/x86/platform/efi/efi_stub_64.S
26648@@ -7,6 +7,7 @@
26649 */
26650
26651 #include <linux/linkage.h>
26652+#include <asm/alternative-asm.h>
26653
26654 #define SAVE_XMM \
26655 mov %rsp, %rax; \
26656@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26657 call *%rdi
26658 addq $32, %rsp
26659 RESTORE_XMM
26660+ pax_force_retaddr 0, 1
26661 ret
26662 ENDPROC(efi_call0)
26663
26664@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26665 call *%rdi
26666 addq $32, %rsp
26667 RESTORE_XMM
26668+ pax_force_retaddr 0, 1
26669 ret
26670 ENDPROC(efi_call1)
26671
26672@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26673 call *%rdi
26674 addq $32, %rsp
26675 RESTORE_XMM
26676+ pax_force_retaddr 0, 1
26677 ret
26678 ENDPROC(efi_call2)
26679
26680@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26681 call *%rdi
26682 addq $32, %rsp
26683 RESTORE_XMM
26684+ pax_force_retaddr 0, 1
26685 ret
26686 ENDPROC(efi_call3)
26687
26688@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26689 call *%rdi
26690 addq $32, %rsp
26691 RESTORE_XMM
26692+ pax_force_retaddr 0, 1
26693 ret
26694 ENDPROC(efi_call4)
26695
26696@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26697 call *%rdi
26698 addq $48, %rsp
26699 RESTORE_XMM
26700+ pax_force_retaddr 0, 1
26701 ret
26702 ENDPROC(efi_call5)
26703
26704@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26705 call *%rdi
26706 addq $48, %rsp
26707 RESTORE_XMM
26708+ pax_force_retaddr 0, 1
26709 ret
26710 ENDPROC(efi_call6)
26711diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26712index fd41a92..9c33628 100644
26713--- a/arch/x86/platform/mrst/mrst.c
26714+++ b/arch/x86/platform/mrst/mrst.c
26715@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26716 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26717 int sfi_mrtc_num;
26718
26719-static void mrst_power_off(void)
26720+static __noreturn void mrst_power_off(void)
26721 {
26722+ BUG();
26723 }
26724
26725-static void mrst_reboot(void)
26726+static __noreturn void mrst_reboot(void)
26727 {
26728 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26729+ BUG();
26730 }
26731
26732 /* parse all the mtimer info to a static mtimer array */
26733diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26734index 218cdb1..fd55c08 100644
26735--- a/arch/x86/power/cpu.c
26736+++ b/arch/x86/power/cpu.c
26737@@ -132,7 +132,7 @@ static void do_fpu_end(void)
26738 static void fix_processor_context(void)
26739 {
26740 int cpu = smp_processor_id();
26741- struct tss_struct *t = &per_cpu(init_tss, cpu);
26742+ struct tss_struct *t = init_tss + cpu;
26743
26744 set_tss_desc(cpu, t); /*
26745 * This just modifies memory; should not be
26746@@ -142,7 +142,9 @@ static void fix_processor_context(void)
26747 */
26748
26749 #ifdef CONFIG_X86_64
26750+ pax_open_kernel();
26751 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26752+ pax_close_kernel();
26753
26754 syscall_init(); /* This sets MSR_*STAR and related */
26755 #endif
26756diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26757index cbca565..bae7133 100644
26758--- a/arch/x86/realmode/init.c
26759+++ b/arch/x86/realmode/init.c
26760@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26761 __va(real_mode_header->trampoline_header);
26762
26763 #ifdef CONFIG_X86_32
26764- trampoline_header->start = __pa(startup_32_smp);
26765+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26766+
26767+#ifdef CONFIG_PAX_KERNEXEC
26768+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26769+#endif
26770+
26771+ trampoline_header->boot_cs = __BOOT_CS;
26772 trampoline_header->gdt_limit = __BOOT_DS + 7;
26773 trampoline_header->gdt_base = __pa(boot_gdt);
26774 #else
26775diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26776index 5b84a2d..be46798 100644
26777--- a/arch/x86/realmode/rm/Makefile
26778+++ b/arch/x86/realmode/rm/Makefile
26779@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26780 $(call cc-option, -fno-unit-at-a-time)) \
26781 $(call cc-option, -fno-stack-protector) \
26782 $(call cc-option, -mpreferred-stack-boundary=2)
26783+ifdef CONSTIFY_PLUGIN
26784+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
26785+endif
26786 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26787 GCOV_PROFILE := n
26788diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26789index c1b2791..f9e31c7 100644
26790--- a/arch/x86/realmode/rm/trampoline_32.S
26791+++ b/arch/x86/realmode/rm/trampoline_32.S
26792@@ -25,6 +25,12 @@
26793 #include <asm/page_types.h>
26794 #include "realmode.h"
26795
26796+#ifdef CONFIG_PAX_KERNEXEC
26797+#define ta(X) (X)
26798+#else
26799+#define ta(X) (pa_ ## X)
26800+#endif
26801+
26802 .text
26803 .code16
26804
26805@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26806
26807 cli # We should be safe anyway
26808
26809- movl tr_start, %eax # where we need to go
26810-
26811 movl $0xA5A5A5A5, trampoline_status
26812 # write marker for master knows we're running
26813
26814@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26815 movw $1, %dx # protected mode (PE) bit
26816 lmsw %dx # into protected mode
26817
26818- ljmpl $__BOOT_CS, $pa_startup_32
26819+ ljmpl *(trampoline_header)
26820
26821 .section ".text32","ax"
26822 .code32
26823@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26824 .balign 8
26825 GLOBAL(trampoline_header)
26826 tr_start: .space 4
26827- tr_gdt_pad: .space 2
26828+ tr_boot_cs: .space 2
26829 tr_gdt: .space 6
26830 END(trampoline_header)
26831
26832diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26833index bb360dc..3e5945f 100644
26834--- a/arch/x86/realmode/rm/trampoline_64.S
26835+++ b/arch/x86/realmode/rm/trampoline_64.S
26836@@ -107,7 +107,7 @@ ENTRY(startup_32)
26837 wrmsr
26838
26839 # Enable paging and in turn activate Long Mode
26840- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26841+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
26842 movl %eax, %cr0
26843
26844 /*
26845diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26846index 5a1847d..deccb30 100644
26847--- a/arch/x86/tools/relocs.c
26848+++ b/arch/x86/tools/relocs.c
26849@@ -12,10 +12,13 @@
26850 #include <regex.h>
26851 #include <tools/le_byteshift.h>
26852
26853+#include "../../../include/generated/autoconf.h"
26854+
26855 static void die(char *fmt, ...);
26856
26857 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26858 static Elf32_Ehdr ehdr;
26859+static Elf32_Phdr *phdr;
26860 static unsigned long reloc_count, reloc_idx;
26861 static unsigned long *relocs;
26862 static unsigned long reloc16_count, reloc16_idx;
26863@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26864 }
26865 }
26866
26867+static void read_phdrs(FILE *fp)
26868+{
26869+ unsigned int i;
26870+
26871+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26872+ if (!phdr) {
26873+ die("Unable to allocate %d program headers\n",
26874+ ehdr.e_phnum);
26875+ }
26876+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26877+ die("Seek to %d failed: %s\n",
26878+ ehdr.e_phoff, strerror(errno));
26879+ }
26880+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26881+ die("Cannot read ELF program headers: %s\n",
26882+ strerror(errno));
26883+ }
26884+ for(i = 0; i < ehdr.e_phnum; i++) {
26885+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26886+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26887+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26888+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26889+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26890+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26891+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26892+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26893+ }
26894+
26895+}
26896+
26897 static void read_shdrs(FILE *fp)
26898 {
26899- int i;
26900+ unsigned int i;
26901 Elf32_Shdr shdr;
26902
26903 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26904@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26905
26906 static void read_strtabs(FILE *fp)
26907 {
26908- int i;
26909+ unsigned int i;
26910 for (i = 0; i < ehdr.e_shnum; i++) {
26911 struct section *sec = &secs[i];
26912 if (sec->shdr.sh_type != SHT_STRTAB) {
26913@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26914
26915 static void read_symtabs(FILE *fp)
26916 {
26917- int i,j;
26918+ unsigned int i,j;
26919 for (i = 0; i < ehdr.e_shnum; i++) {
26920 struct section *sec = &secs[i];
26921 if (sec->shdr.sh_type != SHT_SYMTAB) {
26922@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26923 }
26924
26925
26926-static void read_relocs(FILE *fp)
26927+static void read_relocs(FILE *fp, int use_real_mode)
26928 {
26929- int i,j;
26930+ unsigned int i,j;
26931+ uint32_t base;
26932+
26933 for (i = 0; i < ehdr.e_shnum; i++) {
26934 struct section *sec = &secs[i];
26935 if (sec->shdr.sh_type != SHT_REL) {
26936@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26937 die("Cannot read symbol table: %s\n",
26938 strerror(errno));
26939 }
26940+ base = 0;
26941+
26942+#ifdef CONFIG_X86_32
26943+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26944+ if (phdr[j].p_type != PT_LOAD )
26945+ continue;
26946+ 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)
26947+ continue;
26948+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26949+ break;
26950+ }
26951+#endif
26952+
26953 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26954 Elf32_Rel *rel = &sec->reltab[j];
26955- rel->r_offset = elf32_to_cpu(rel->r_offset);
26956+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26957 rel->r_info = elf32_to_cpu(rel->r_info);
26958 }
26959 }
26960@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26961
26962 static void print_absolute_symbols(void)
26963 {
26964- int i;
26965+ unsigned int i;
26966 printf("Absolute symbols\n");
26967 printf(" Num: Value Size Type Bind Visibility Name\n");
26968 for (i = 0; i < ehdr.e_shnum; i++) {
26969 struct section *sec = &secs[i];
26970 char *sym_strtab;
26971- int j;
26972+ unsigned int j;
26973
26974 if (sec->shdr.sh_type != SHT_SYMTAB) {
26975 continue;
26976@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
26977
26978 static void print_absolute_relocs(void)
26979 {
26980- int i, printed = 0;
26981+ unsigned int i, printed = 0;
26982
26983 for (i = 0; i < ehdr.e_shnum; i++) {
26984 struct section *sec = &secs[i];
26985 struct section *sec_applies, *sec_symtab;
26986 char *sym_strtab;
26987 Elf32_Sym *sh_symtab;
26988- int j;
26989+ unsigned int j;
26990 if (sec->shdr.sh_type != SHT_REL) {
26991 continue;
26992 }
26993@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
26994 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26995 int use_real_mode)
26996 {
26997- int i;
26998+ unsigned int i;
26999 /* Walk through the relocations */
27000 for (i = 0; i < ehdr.e_shnum; i++) {
27001 char *sym_strtab;
27002 Elf32_Sym *sh_symtab;
27003 struct section *sec_applies, *sec_symtab;
27004- int j;
27005+ unsigned int j;
27006 struct section *sec = &secs[i];
27007
27008 if (sec->shdr.sh_type != SHT_REL) {
27009@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27010 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27011 r_type = ELF32_R_TYPE(rel->r_info);
27012
27013+ if (!use_real_mode) {
27014+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27015+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27016+ continue;
27017+
27018+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27019+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27020+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27021+ continue;
27022+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27023+ continue;
27024+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27025+ continue;
27026+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27027+ continue;
27028+#endif
27029+ }
27030+
27031 shn_abs = sym->st_shndx == SHN_ABS;
27032
27033 switch (r_type) {
27034@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27035
27036 static void emit_relocs(int as_text, int use_real_mode)
27037 {
27038- int i;
27039+ unsigned int i;
27040 /* Count how many relocations I have and allocate space for them. */
27041 reloc_count = 0;
27042 walk_relocs(count_reloc, use_real_mode);
27043@@ -808,10 +874,11 @@ int main(int argc, char **argv)
27044 fname, strerror(errno));
27045 }
27046 read_ehdr(fp);
27047+ read_phdrs(fp);
27048 read_shdrs(fp);
27049 read_strtabs(fp);
27050 read_symtabs(fp);
27051- read_relocs(fp);
27052+ read_relocs(fp, use_real_mode);
27053 if (show_absolute_syms) {
27054 print_absolute_symbols();
27055 return 0;
27056diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27057index fd14be1..e3c79c0 100644
27058--- a/arch/x86/vdso/Makefile
27059+++ b/arch/x86/vdso/Makefile
27060@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27061 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27062 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27063
27064-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27065+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27066 GCOV_PROFILE := n
27067
27068 #
27069diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27070index 66e6d93..587f435 100644
27071--- a/arch/x86/vdso/vdso32-setup.c
27072+++ b/arch/x86/vdso/vdso32-setup.c
27073@@ -25,6 +25,7 @@
27074 #include <asm/tlbflush.h>
27075 #include <asm/vdso.h>
27076 #include <asm/proto.h>
27077+#include <asm/mman.h>
27078
27079 enum {
27080 VDSO_DISABLED = 0,
27081@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27082 void enable_sep_cpu(void)
27083 {
27084 int cpu = get_cpu();
27085- struct tss_struct *tss = &per_cpu(init_tss, cpu);
27086+ struct tss_struct *tss = init_tss + cpu;
27087
27088 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27089 put_cpu();
27090@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27091 gate_vma.vm_start = FIXADDR_USER_START;
27092 gate_vma.vm_end = FIXADDR_USER_END;
27093 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27094- gate_vma.vm_page_prot = __P101;
27095+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27096
27097 return 0;
27098 }
27099@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27100 if (compat)
27101 addr = VDSO_HIGH_BASE;
27102 else {
27103- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27104+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27105 if (IS_ERR_VALUE(addr)) {
27106 ret = addr;
27107 goto up_fail;
27108 }
27109 }
27110
27111- current->mm->context.vdso = (void *)addr;
27112+ current->mm->context.vdso = addr;
27113
27114 if (compat_uses_vma || !compat) {
27115 /*
27116@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27117 }
27118
27119 current_thread_info()->sysenter_return =
27120- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27121+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27122
27123 up_fail:
27124 if (ret)
27125- current->mm->context.vdso = NULL;
27126+ current->mm->context.vdso = 0;
27127
27128 up_write(&mm->mmap_sem);
27129
27130@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27131
27132 const char *arch_vma_name(struct vm_area_struct *vma)
27133 {
27134- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27135+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27136 return "[vdso]";
27137+
27138+#ifdef CONFIG_PAX_SEGMEXEC
27139+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27140+ return "[vdso]";
27141+#endif
27142+
27143 return NULL;
27144 }
27145
27146@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27147 * Check to see if the corresponding task was created in compat vdso
27148 * mode.
27149 */
27150- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27151+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27152 return &gate_vma;
27153 return NULL;
27154 }
27155diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27156index 00aaf04..4a26505 100644
27157--- a/arch/x86/vdso/vma.c
27158+++ b/arch/x86/vdso/vma.c
27159@@ -16,8 +16,6 @@
27160 #include <asm/vdso.h>
27161 #include <asm/page.h>
27162
27163-unsigned int __read_mostly vdso_enabled = 1;
27164-
27165 extern char vdso_start[], vdso_end[];
27166 extern unsigned short vdso_sync_cpuid;
27167
27168@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27169 * unaligned here as a result of stack start randomization.
27170 */
27171 addr = PAGE_ALIGN(addr);
27172- addr = align_addr(addr, NULL, ALIGN_VDSO);
27173
27174 return addr;
27175 }
27176@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27177 unsigned size)
27178 {
27179 struct mm_struct *mm = current->mm;
27180- unsigned long addr;
27181+ unsigned long addr = 0;
27182 int ret;
27183
27184- if (!vdso_enabled)
27185- return 0;
27186-
27187 down_write(&mm->mmap_sem);
27188+
27189+#ifdef CONFIG_PAX_RANDMMAP
27190+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27191+#endif
27192+
27193 addr = vdso_addr(mm->start_stack, size);
27194+ addr = align_addr(addr, NULL, ALIGN_VDSO);
27195 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27196 if (IS_ERR_VALUE(addr)) {
27197 ret = addr;
27198 goto up_fail;
27199 }
27200
27201- current->mm->context.vdso = (void *)addr;
27202+ mm->context.vdso = addr;
27203
27204 ret = install_special_mapping(mm, addr, size,
27205 VM_READ|VM_EXEC|
27206 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27207 pages);
27208- if (ret) {
27209- current->mm->context.vdso = NULL;
27210- goto up_fail;
27211- }
27212+ if (ret)
27213+ mm->context.vdso = 0;
27214
27215 up_fail:
27216 up_write(&mm->mmap_sem);
27217@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27218 vdsox32_size);
27219 }
27220 #endif
27221-
27222-static __init int vdso_setup(char *s)
27223-{
27224- vdso_enabled = simple_strtoul(s, NULL, 0);
27225- return 0;
27226-}
27227-__setup("vdso=", vdso_setup);
27228diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27229index 405307f..7ecf7b0 100644
27230--- a/arch/x86/xen/enlighten.c
27231+++ b/arch/x86/xen/enlighten.c
27232@@ -97,8 +97,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27233
27234 struct shared_info xen_dummy_shared_info;
27235
27236-void *xen_initial_gdt;
27237-
27238 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27239 __read_mostly int xen_have_vector_callback;
27240 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27241@@ -885,21 +883,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27242
27243 static void set_xen_basic_apic_ops(void)
27244 {
27245- apic->read = xen_apic_read;
27246- apic->write = xen_apic_write;
27247- apic->icr_read = xen_apic_icr_read;
27248- apic->icr_write = xen_apic_icr_write;
27249- apic->wait_icr_idle = xen_apic_wait_icr_idle;
27250- apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27251- apic->set_apic_id = xen_set_apic_id;
27252- apic->get_apic_id = xen_get_apic_id;
27253+ *(void **)&apic->read = xen_apic_read;
27254+ *(void **)&apic->write = xen_apic_write;
27255+ *(void **)&apic->icr_read = xen_apic_icr_read;
27256+ *(void **)&apic->icr_write = xen_apic_icr_write;
27257+ *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27258+ *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27259+ *(void **)&apic->set_apic_id = xen_set_apic_id;
27260+ *(void **)&apic->get_apic_id = xen_get_apic_id;
27261
27262 #ifdef CONFIG_SMP
27263- apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27264- apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27265- apic->send_IPI_mask = xen_send_IPI_mask;
27266- apic->send_IPI_all = xen_send_IPI_all;
27267- apic->send_IPI_self = xen_send_IPI_self;
27268+ *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27269+ *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27270+ *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27271+ *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27272+ *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27273 #endif
27274 }
27275
27276@@ -1175,30 +1173,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27277 #endif
27278 };
27279
27280-static void xen_reboot(int reason)
27281+static __noreturn void xen_reboot(int reason)
27282 {
27283 struct sched_shutdown r = { .reason = reason };
27284
27285- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27286- BUG();
27287+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27288+ BUG();
27289 }
27290
27291-static void xen_restart(char *msg)
27292+static __noreturn void xen_restart(char *msg)
27293 {
27294 xen_reboot(SHUTDOWN_reboot);
27295 }
27296
27297-static void xen_emergency_restart(void)
27298+static __noreturn void xen_emergency_restart(void)
27299 {
27300 xen_reboot(SHUTDOWN_reboot);
27301 }
27302
27303-static void xen_machine_halt(void)
27304+static __noreturn void xen_machine_halt(void)
27305 {
27306 xen_reboot(SHUTDOWN_poweroff);
27307 }
27308
27309-static void xen_machine_power_off(void)
27310+static __noreturn void xen_machine_power_off(void)
27311 {
27312 if (pm_power_off)
27313 pm_power_off();
27314@@ -1301,7 +1299,17 @@ asmlinkage void __init xen_start_kernel(void)
27315 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27316
27317 /* Work out if we support NX */
27318- x86_configure_nx();
27319+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27320+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27321+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27322+ unsigned l, h;
27323+
27324+ __supported_pte_mask |= _PAGE_NX;
27325+ rdmsr(MSR_EFER, l, h);
27326+ l |= EFER_NX;
27327+ wrmsr(MSR_EFER, l, h);
27328+ }
27329+#endif
27330
27331 xen_setup_features();
27332
27333@@ -1332,13 +1340,6 @@ asmlinkage void __init xen_start_kernel(void)
27334
27335 machine_ops = xen_machine_ops;
27336
27337- /*
27338- * The only reliable way to retain the initial address of the
27339- * percpu gdt_page is to remember it here, so we can go and
27340- * mark it RW later, when the initial percpu area is freed.
27341- */
27342- xen_initial_gdt = &per_cpu(gdt_page, 0);
27343-
27344 xen_smp_init();
27345
27346 #ifdef CONFIG_ACPI_NUMA
27347diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27348index 3a73785..0d30df2 100644
27349--- a/arch/x86/xen/mmu.c
27350+++ b/arch/x86/xen/mmu.c
27351@@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27352 convert_pfn_mfn(init_level4_pgt);
27353 convert_pfn_mfn(level3_ident_pgt);
27354 convert_pfn_mfn(level3_kernel_pgt);
27355+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27356+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27357+ convert_pfn_mfn(level3_vmemmap_pgt);
27358
27359 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27360 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27361@@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27362 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27363 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27364 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27365+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27366+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27367+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27368 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27369+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27370 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27371 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27372
27373@@ -1940,6 +1947,7 @@ static void __init xen_post_allocator_init(void)
27374 pv_mmu_ops.set_pud = xen_set_pud;
27375 #if PAGETABLE_LEVELS == 4
27376 pv_mmu_ops.set_pgd = xen_set_pgd;
27377+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27378 #endif
27379
27380 /* This will work as long as patching hasn't happened yet
27381@@ -2021,6 +2029,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27382 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27383 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27384 .set_pgd = xen_set_pgd_hyper,
27385+ .set_pgd_batched = xen_set_pgd_hyper,
27386
27387 .alloc_pud = xen_alloc_pmd_init,
27388 .release_pud = xen_release_pmd_init,
27389diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27390index afb250d..627075f 100644
27391--- a/arch/x86/xen/smp.c
27392+++ b/arch/x86/xen/smp.c
27393@@ -231,11 +231,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27394 {
27395 BUG_ON(smp_processor_id() != 0);
27396 native_smp_prepare_boot_cpu();
27397-
27398- /* We've switched to the "real" per-cpu gdt, so make sure the
27399- old memory can be recycled */
27400- make_lowmem_page_readwrite(xen_initial_gdt);
27401-
27402 xen_filter_cpu_maps();
27403 xen_setup_vcpu_info_placement();
27404 }
27405@@ -302,12 +297,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27406 gdt = get_cpu_gdt_table(cpu);
27407
27408 ctxt->flags = VGCF_IN_KERNEL;
27409- ctxt->user_regs.ds = __USER_DS;
27410- ctxt->user_regs.es = __USER_DS;
27411+ ctxt->user_regs.ds = __KERNEL_DS;
27412+ ctxt->user_regs.es = __KERNEL_DS;
27413 ctxt->user_regs.ss = __KERNEL_DS;
27414 #ifdef CONFIG_X86_32
27415 ctxt->user_regs.fs = __KERNEL_PERCPU;
27416- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27417+ savesegment(gs, ctxt->user_regs.gs);
27418 #else
27419 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27420 #endif
27421@@ -357,13 +352,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27422 int rc;
27423
27424 per_cpu(current_task, cpu) = idle;
27425+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27426 #ifdef CONFIG_X86_32
27427 irq_ctx_init(cpu);
27428 #else
27429 clear_tsk_thread_flag(idle, TIF_FORK);
27430- per_cpu(kernel_stack, cpu) =
27431- (unsigned long)task_stack_page(idle) -
27432- KERNEL_STACK_OFFSET + THREAD_SIZE;
27433+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27434 #endif
27435 xen_setup_runstate_info(cpu);
27436 xen_setup_timer(cpu);
27437diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27438index f9643fc..602e8af 100644
27439--- a/arch/x86/xen/xen-asm_32.S
27440+++ b/arch/x86/xen/xen-asm_32.S
27441@@ -84,14 +84,14 @@ ENTRY(xen_iret)
27442 ESP_OFFSET=4 # bytes pushed onto stack
27443
27444 /*
27445- * Store vcpu_info pointer for easy access. Do it this way to
27446- * avoid having to reload %fs
27447+ * Store vcpu_info pointer for easy access.
27448 */
27449 #ifdef CONFIG_SMP
27450- GET_THREAD_INFO(%eax)
27451- movl TI_cpu(%eax), %eax
27452- movl __per_cpu_offset(,%eax,4), %eax
27453- mov xen_vcpu(%eax), %eax
27454+ push %fs
27455+ mov $(__KERNEL_PERCPU), %eax
27456+ mov %eax, %fs
27457+ mov PER_CPU_VAR(xen_vcpu), %eax
27458+ pop %fs
27459 #else
27460 movl xen_vcpu, %eax
27461 #endif
27462diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27463index aaa7291..3f77960 100644
27464--- a/arch/x86/xen/xen-head.S
27465+++ b/arch/x86/xen/xen-head.S
27466@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27467 #ifdef CONFIG_X86_32
27468 mov %esi,xen_start_info
27469 mov $init_thread_union+THREAD_SIZE,%esp
27470+#ifdef CONFIG_SMP
27471+ movl $cpu_gdt_table,%edi
27472+ movl $__per_cpu_load,%eax
27473+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27474+ rorl $16,%eax
27475+ movb %al,__KERNEL_PERCPU + 4(%edi)
27476+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27477+ movl $__per_cpu_end - 1,%eax
27478+ subl $__per_cpu_start,%eax
27479+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27480+#endif
27481 #else
27482 mov %rsi,xen_start_info
27483 mov $init_thread_union+THREAD_SIZE,%rsp
27484diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27485index 202d4c1..99b072a 100644
27486--- a/arch/x86/xen/xen-ops.h
27487+++ b/arch/x86/xen/xen-ops.h
27488@@ -10,8 +10,6 @@
27489 extern const char xen_hypervisor_callback[];
27490 extern const char xen_failsafe_callback[];
27491
27492-extern void *xen_initial_gdt;
27493-
27494 struct trap_info;
27495 void xen_copy_trap_info(struct trap_info *traps);
27496
27497diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27498index 525bd3d..ef888b1 100644
27499--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27500+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27501@@ -119,9 +119,9 @@
27502 ----------------------------------------------------------------------*/
27503
27504 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27505-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27506 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27507 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27508+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27509
27510 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27511 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27512diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27513index 2f33760..835e50a 100644
27514--- a/arch/xtensa/variants/fsf/include/variant/core.h
27515+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27516@@ -11,6 +11,7 @@
27517 #ifndef _XTENSA_CORE_H
27518 #define _XTENSA_CORE_H
27519
27520+#include <linux/const.h>
27521
27522 /****************************************************************************
27523 Parameters Useful for Any Code, USER or PRIVILEGED
27524@@ -112,9 +113,9 @@
27525 ----------------------------------------------------------------------*/
27526
27527 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27528-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27529 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27530 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27531+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27532
27533 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27534 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27535diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27536index af00795..2bb8105 100644
27537--- a/arch/xtensa/variants/s6000/include/variant/core.h
27538+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27539@@ -11,6 +11,7 @@
27540 #ifndef _XTENSA_CORE_CONFIGURATION_H
27541 #define _XTENSA_CORE_CONFIGURATION_H
27542
27543+#include <linux/const.h>
27544
27545 /****************************************************************************
27546 Parameters Useful for Any Code, USER or PRIVILEGED
27547@@ -118,9 +119,9 @@
27548 ----------------------------------------------------------------------*/
27549
27550 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27551-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27552 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27553 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27554+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27555
27556 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27557 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27558diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27559index 58916af..9cb880b 100644
27560--- a/block/blk-iopoll.c
27561+++ b/block/blk-iopoll.c
27562@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27563 }
27564 EXPORT_SYMBOL(blk_iopoll_complete);
27565
27566-static void blk_iopoll_softirq(struct softirq_action *h)
27567+static void blk_iopoll_softirq(void)
27568 {
27569 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27570 int rearm = 0, budget = blk_iopoll_budget;
27571diff --git a/block/blk-map.c b/block/blk-map.c
27572index 623e1cd..ca1e109 100644
27573--- a/block/blk-map.c
27574+++ b/block/blk-map.c
27575@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27576 if (!len || !kbuf)
27577 return -EINVAL;
27578
27579- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27580+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27581 if (do_copy)
27582 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27583 else
27584diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27585index 467c8de..4bddc6d 100644
27586--- a/block/blk-softirq.c
27587+++ b/block/blk-softirq.c
27588@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27589 * Softirq action handler - move entries to local list and loop over them
27590 * while passing them to the queue registered handler.
27591 */
27592-static void blk_done_softirq(struct softirq_action *h)
27593+static void blk_done_softirq(void)
27594 {
27595 struct list_head *cpu_list, local_list;
27596
27597diff --git a/block/bsg.c b/block/bsg.c
27598index ff64ae3..593560c 100644
27599--- a/block/bsg.c
27600+++ b/block/bsg.c
27601@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27602 struct sg_io_v4 *hdr, struct bsg_device *bd,
27603 fmode_t has_write_perm)
27604 {
27605+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27606+ unsigned char *cmdptr;
27607+
27608 if (hdr->request_len > BLK_MAX_CDB) {
27609 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27610 if (!rq->cmd)
27611 return -ENOMEM;
27612- }
27613+ cmdptr = rq->cmd;
27614+ } else
27615+ cmdptr = tmpcmd;
27616
27617- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27618+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27619 hdr->request_len))
27620 return -EFAULT;
27621
27622+ if (cmdptr != rq->cmd)
27623+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27624+
27625 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27626 if (blk_verify_command(rq->cmd, has_write_perm))
27627 return -EPERM;
27628diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27629index 7c668c8..db3521c 100644
27630--- a/block/compat_ioctl.c
27631+++ b/block/compat_ioctl.c
27632@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27633 err |= __get_user(f->spec1, &uf->spec1);
27634 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27635 err |= __get_user(name, &uf->name);
27636- f->name = compat_ptr(name);
27637+ f->name = (void __force_kernel *)compat_ptr(name);
27638 if (err) {
27639 err = -EFAULT;
27640 goto out;
27641diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27642index 6296b40..417c00f 100644
27643--- a/block/partitions/efi.c
27644+++ b/block/partitions/efi.c
27645@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27646 if (!gpt)
27647 return NULL;
27648
27649+ if (!le32_to_cpu(gpt->num_partition_entries))
27650+ return NULL;
27651+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27652+ if (!pte)
27653+ return NULL;
27654+
27655 count = le32_to_cpu(gpt->num_partition_entries) *
27656 le32_to_cpu(gpt->sizeof_partition_entry);
27657- if (!count)
27658- return NULL;
27659- pte = kzalloc(count, GFP_KERNEL);
27660- if (!pte)
27661- return NULL;
27662-
27663 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27664 (u8 *) pte,
27665 count) < count) {
27666diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27667index 9a87daa..fb17486 100644
27668--- a/block/scsi_ioctl.c
27669+++ b/block/scsi_ioctl.c
27670@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27671 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27672 struct sg_io_hdr *hdr, fmode_t mode)
27673 {
27674- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27675+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27676+ unsigned char *cmdptr;
27677+
27678+ if (rq->cmd != rq->__cmd)
27679+ cmdptr = rq->cmd;
27680+ else
27681+ cmdptr = tmpcmd;
27682+
27683+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27684 return -EFAULT;
27685+
27686+ if (cmdptr != rq->cmd)
27687+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27688+
27689 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27690 return -EPERM;
27691
27692@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27693 int err;
27694 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27695 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27696+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27697+ unsigned char *cmdptr;
27698
27699 if (!sic)
27700 return -EINVAL;
27701@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27702 */
27703 err = -EFAULT;
27704 rq->cmd_len = cmdlen;
27705- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27706+
27707+ if (rq->cmd != rq->__cmd)
27708+ cmdptr = rq->cmd;
27709+ else
27710+ cmdptr = tmpcmd;
27711+
27712+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27713 goto error;
27714
27715+ if (rq->cmd != cmdptr)
27716+ memcpy(rq->cmd, cmdptr, cmdlen);
27717+
27718 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27719 goto error;
27720
27721diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27722index 671d4d6..5f24030 100644
27723--- a/crypto/cryptd.c
27724+++ b/crypto/cryptd.c
27725@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27726
27727 struct cryptd_blkcipher_request_ctx {
27728 crypto_completion_t complete;
27729-};
27730+} __no_const;
27731
27732 struct cryptd_hash_ctx {
27733 struct crypto_shash *child;
27734@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27735
27736 struct cryptd_aead_request_ctx {
27737 crypto_completion_t complete;
27738-};
27739+} __no_const;
27740
27741 static void cryptd_queue_worker(struct work_struct *work);
27742
27743diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27744index e6defd8..c26a225 100644
27745--- a/drivers/acpi/apei/cper.c
27746+++ b/drivers/acpi/apei/cper.c
27747@@ -38,12 +38,12 @@
27748 */
27749 u64 cper_next_record_id(void)
27750 {
27751- static atomic64_t seq;
27752+ static atomic64_unchecked_t seq;
27753
27754- if (!atomic64_read(&seq))
27755- atomic64_set(&seq, ((u64)get_seconds()) << 32);
27756+ if (!atomic64_read_unchecked(&seq))
27757+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27758
27759- return atomic64_inc_return(&seq);
27760+ return atomic64_inc_return_unchecked(&seq);
27761 }
27762 EXPORT_SYMBOL_GPL(cper_next_record_id);
27763
27764diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27765index 7586544..636a2f0 100644
27766--- a/drivers/acpi/ec_sys.c
27767+++ b/drivers/acpi/ec_sys.c
27768@@ -12,6 +12,7 @@
27769 #include <linux/acpi.h>
27770 #include <linux/debugfs.h>
27771 #include <linux/module.h>
27772+#include <linux/uaccess.h>
27773 #include "internal.h"
27774
27775 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27776@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27777 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27778 */
27779 unsigned int size = EC_SPACE_SIZE;
27780- u8 *data = (u8 *) buf;
27781+ u8 data;
27782 loff_t init_off = *off;
27783 int err = 0;
27784
27785@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27786 size = count;
27787
27788 while (size) {
27789- err = ec_read(*off, &data[*off - init_off]);
27790+ err = ec_read(*off, &data);
27791 if (err)
27792 return err;
27793+ if (put_user(data, &buf[*off - init_off]))
27794+ return -EFAULT;
27795 *off += 1;
27796 size--;
27797 }
27798@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27799
27800 unsigned int size = count;
27801 loff_t init_off = *off;
27802- u8 *data = (u8 *) buf;
27803 int err = 0;
27804
27805 if (*off >= EC_SPACE_SIZE)
27806@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27807 }
27808
27809 while (size) {
27810- u8 byte_write = data[*off - init_off];
27811+ u8 byte_write;
27812+ if (get_user(byte_write, &buf[*off - init_off]))
27813+ return -EFAULT;
27814 err = ec_write(*off, byte_write);
27815 if (err)
27816 return err;
27817diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27818index 251c7b62..000462d 100644
27819--- a/drivers/acpi/proc.c
27820+++ b/drivers/acpi/proc.c
27821@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27822 size_t count, loff_t * ppos)
27823 {
27824 struct list_head *node, *next;
27825- char strbuf[5];
27826- char str[5] = "";
27827- unsigned int len = count;
27828+ char strbuf[5] = {0};
27829
27830- if (len > 4)
27831- len = 4;
27832- if (len < 0)
27833+ if (count > 4)
27834+ count = 4;
27835+ if (copy_from_user(strbuf, buffer, count))
27836 return -EFAULT;
27837-
27838- if (copy_from_user(strbuf, buffer, len))
27839- return -EFAULT;
27840- strbuf[len] = '\0';
27841- sscanf(strbuf, "%s", str);
27842+ strbuf[count] = '\0';
27843
27844 mutex_lock(&acpi_device_lock);
27845 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27846@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27847 if (!dev->wakeup.flags.valid)
27848 continue;
27849
27850- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27851+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27852 if (device_can_wakeup(&dev->dev)) {
27853 bool enable = !device_may_wakeup(&dev->dev);
27854 device_set_wakeup_enable(&dev->dev, enable);
27855diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27856index bbac51e..4c094f9 100644
27857--- a/drivers/acpi/processor_driver.c
27858+++ b/drivers/acpi/processor_driver.c
27859@@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27860 return 0;
27861 #endif
27862
27863- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27864+ BUG_ON(pr->id >= nr_cpu_ids);
27865
27866 /*
27867 * Buggy BIOS check
27868diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27869index 71e8385..98d1e14 100644
27870--- a/drivers/ata/libata-core.c
27871+++ b/drivers/ata/libata-core.c
27872@@ -4744,7 +4744,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27873 struct ata_port *ap;
27874 unsigned int tag;
27875
27876- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27877+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27878 ap = qc->ap;
27879
27880 qc->flags = 0;
27881@@ -4760,7 +4760,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27882 struct ata_port *ap;
27883 struct ata_link *link;
27884
27885- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27886+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27887 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27888 ap = qc->ap;
27889 link = qc->dev->link;
27890@@ -5824,6 +5824,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27891 return;
27892
27893 spin_lock(&lock);
27894+ pax_open_kernel();
27895
27896 for (cur = ops->inherits; cur; cur = cur->inherits) {
27897 void **inherit = (void **)cur;
27898@@ -5837,8 +5838,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27899 if (IS_ERR(*pp))
27900 *pp = NULL;
27901
27902- ops->inherits = NULL;
27903+ *(struct ata_port_operations **)&ops->inherits = NULL;
27904
27905+ pax_close_kernel();
27906 spin_unlock(&lock);
27907 }
27908
27909diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27910index ac6a5be..c7176b1 100644
27911--- a/drivers/ata/pata_arasan_cf.c
27912+++ b/drivers/ata/pata_arasan_cf.c
27913@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27914 /* Handle platform specific quirks */
27915 if (pdata->quirk) {
27916 if (pdata->quirk & CF_BROKEN_PIO) {
27917- ap->ops->set_piomode = NULL;
27918+ pax_open_kernel();
27919+ *(void **)&ap->ops->set_piomode = NULL;
27920+ pax_close_kernel();
27921 ap->pio_mask = 0;
27922 }
27923 if (pdata->quirk & CF_BROKEN_MWDMA)
27924diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27925index f9b983a..887b9d8 100644
27926--- a/drivers/atm/adummy.c
27927+++ b/drivers/atm/adummy.c
27928@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27929 vcc->pop(vcc, skb);
27930 else
27931 dev_kfree_skb_any(skb);
27932- atomic_inc(&vcc->stats->tx);
27933+ atomic_inc_unchecked(&vcc->stats->tx);
27934
27935 return 0;
27936 }
27937diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27938index 89b30f3..7964211 100644
27939--- a/drivers/atm/ambassador.c
27940+++ b/drivers/atm/ambassador.c
27941@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27942 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27943
27944 // VC layer stats
27945- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27946+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27947
27948 // free the descriptor
27949 kfree (tx_descr);
27950@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27951 dump_skb ("<<<", vc, skb);
27952
27953 // VC layer stats
27954- atomic_inc(&atm_vcc->stats->rx);
27955+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27956 __net_timestamp(skb);
27957 // end of our responsibility
27958 atm_vcc->push (atm_vcc, skb);
27959@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27960 } else {
27961 PRINTK (KERN_INFO, "dropped over-size frame");
27962 // should we count this?
27963- atomic_inc(&atm_vcc->stats->rx_drop);
27964+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27965 }
27966
27967 } else {
27968@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27969 }
27970
27971 if (check_area (skb->data, skb->len)) {
27972- atomic_inc(&atm_vcc->stats->tx_err);
27973+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27974 return -ENOMEM; // ?
27975 }
27976
27977diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27978index b22d71c..d6e1049 100644
27979--- a/drivers/atm/atmtcp.c
27980+++ b/drivers/atm/atmtcp.c
27981@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27982 if (vcc->pop) vcc->pop(vcc,skb);
27983 else dev_kfree_skb(skb);
27984 if (dev_data) return 0;
27985- atomic_inc(&vcc->stats->tx_err);
27986+ atomic_inc_unchecked(&vcc->stats->tx_err);
27987 return -ENOLINK;
27988 }
27989 size = skb->len+sizeof(struct atmtcp_hdr);
27990@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27991 if (!new_skb) {
27992 if (vcc->pop) vcc->pop(vcc,skb);
27993 else dev_kfree_skb(skb);
27994- atomic_inc(&vcc->stats->tx_err);
27995+ atomic_inc_unchecked(&vcc->stats->tx_err);
27996 return -ENOBUFS;
27997 }
27998 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27999@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28000 if (vcc->pop) vcc->pop(vcc,skb);
28001 else dev_kfree_skb(skb);
28002 out_vcc->push(out_vcc,new_skb);
28003- atomic_inc(&vcc->stats->tx);
28004- atomic_inc(&out_vcc->stats->rx);
28005+ atomic_inc_unchecked(&vcc->stats->tx);
28006+ atomic_inc_unchecked(&out_vcc->stats->rx);
28007 return 0;
28008 }
28009
28010@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28011 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28012 read_unlock(&vcc_sklist_lock);
28013 if (!out_vcc) {
28014- atomic_inc(&vcc->stats->tx_err);
28015+ atomic_inc_unchecked(&vcc->stats->tx_err);
28016 goto done;
28017 }
28018 skb_pull(skb,sizeof(struct atmtcp_hdr));
28019@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28020 __net_timestamp(new_skb);
28021 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28022 out_vcc->push(out_vcc,new_skb);
28023- atomic_inc(&vcc->stats->tx);
28024- atomic_inc(&out_vcc->stats->rx);
28025+ atomic_inc_unchecked(&vcc->stats->tx);
28026+ atomic_inc_unchecked(&out_vcc->stats->rx);
28027 done:
28028 if (vcc->pop) vcc->pop(vcc,skb);
28029 else dev_kfree_skb(skb);
28030diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28031index 2059ee4..faf51c7 100644
28032--- a/drivers/atm/eni.c
28033+++ b/drivers/atm/eni.c
28034@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28035 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28036 vcc->dev->number);
28037 length = 0;
28038- atomic_inc(&vcc->stats->rx_err);
28039+ atomic_inc_unchecked(&vcc->stats->rx_err);
28040 }
28041 else {
28042 length = ATM_CELL_SIZE-1; /* no HEC */
28043@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28044 size);
28045 }
28046 eff = length = 0;
28047- atomic_inc(&vcc->stats->rx_err);
28048+ atomic_inc_unchecked(&vcc->stats->rx_err);
28049 }
28050 else {
28051 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28052@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28053 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28054 vcc->dev->number,vcc->vci,length,size << 2,descr);
28055 length = eff = 0;
28056- atomic_inc(&vcc->stats->rx_err);
28057+ atomic_inc_unchecked(&vcc->stats->rx_err);
28058 }
28059 }
28060 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28061@@ -767,7 +767,7 @@ rx_dequeued++;
28062 vcc->push(vcc,skb);
28063 pushed++;
28064 }
28065- atomic_inc(&vcc->stats->rx);
28066+ atomic_inc_unchecked(&vcc->stats->rx);
28067 }
28068 wake_up(&eni_dev->rx_wait);
28069 }
28070@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28071 PCI_DMA_TODEVICE);
28072 if (vcc->pop) vcc->pop(vcc,skb);
28073 else dev_kfree_skb_irq(skb);
28074- atomic_inc(&vcc->stats->tx);
28075+ atomic_inc_unchecked(&vcc->stats->tx);
28076 wake_up(&eni_dev->tx_wait);
28077 dma_complete++;
28078 }
28079@@ -1567,7 +1567,7 @@ tx_complete++;
28080 /*--------------------------------- entries ---------------------------------*/
28081
28082
28083-static const char *media_name[] __devinitdata = {
28084+static const char *media_name[] __devinitconst = {
28085 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28086 "UTP", "05?", "06?", "07?", /* 4- 7 */
28087 "TAXI","09?", "10?", "11?", /* 8-11 */
28088diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28089index 86fed1b..6dc4721 100644
28090--- a/drivers/atm/firestream.c
28091+++ b/drivers/atm/firestream.c
28092@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28093 }
28094 }
28095
28096- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28097+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28098
28099 fs_dprintk (FS_DEBUG_TXMEM, "i");
28100 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28101@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28102 #endif
28103 skb_put (skb, qe->p1 & 0xffff);
28104 ATM_SKB(skb)->vcc = atm_vcc;
28105- atomic_inc(&atm_vcc->stats->rx);
28106+ atomic_inc_unchecked(&atm_vcc->stats->rx);
28107 __net_timestamp(skb);
28108 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28109 atm_vcc->push (atm_vcc, skb);
28110@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28111 kfree (pe);
28112 }
28113 if (atm_vcc)
28114- atomic_inc(&atm_vcc->stats->rx_drop);
28115+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28116 break;
28117 case 0x1f: /* Reassembly abort: no buffers. */
28118 /* Silently increment error counter. */
28119 if (atm_vcc)
28120- atomic_inc(&atm_vcc->stats->rx_drop);
28121+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28122 break;
28123 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28124 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28125diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28126index 361f5ae..7fc552d 100644
28127--- a/drivers/atm/fore200e.c
28128+++ b/drivers/atm/fore200e.c
28129@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28130 #endif
28131 /* check error condition */
28132 if (*entry->status & STATUS_ERROR)
28133- atomic_inc(&vcc->stats->tx_err);
28134+ atomic_inc_unchecked(&vcc->stats->tx_err);
28135 else
28136- atomic_inc(&vcc->stats->tx);
28137+ atomic_inc_unchecked(&vcc->stats->tx);
28138 }
28139 }
28140
28141@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28142 if (skb == NULL) {
28143 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28144
28145- atomic_inc(&vcc->stats->rx_drop);
28146+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28147 return -ENOMEM;
28148 }
28149
28150@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28151
28152 dev_kfree_skb_any(skb);
28153
28154- atomic_inc(&vcc->stats->rx_drop);
28155+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28156 return -ENOMEM;
28157 }
28158
28159 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28160
28161 vcc->push(vcc, skb);
28162- atomic_inc(&vcc->stats->rx);
28163+ atomic_inc_unchecked(&vcc->stats->rx);
28164
28165 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28166
28167@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28168 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28169 fore200e->atm_dev->number,
28170 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28171- atomic_inc(&vcc->stats->rx_err);
28172+ atomic_inc_unchecked(&vcc->stats->rx_err);
28173 }
28174 }
28175
28176@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28177 goto retry_here;
28178 }
28179
28180- atomic_inc(&vcc->stats->tx_err);
28181+ atomic_inc_unchecked(&vcc->stats->tx_err);
28182
28183 fore200e->tx_sat++;
28184 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28185diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28186index b182c2f..1c6fa8a 100644
28187--- a/drivers/atm/he.c
28188+++ b/drivers/atm/he.c
28189@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28190
28191 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28192 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28193- atomic_inc(&vcc->stats->rx_drop);
28194+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28195 goto return_host_buffers;
28196 }
28197
28198@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28199 RBRQ_LEN_ERR(he_dev->rbrq_head)
28200 ? "LEN_ERR" : "",
28201 vcc->vpi, vcc->vci);
28202- atomic_inc(&vcc->stats->rx_err);
28203+ atomic_inc_unchecked(&vcc->stats->rx_err);
28204 goto return_host_buffers;
28205 }
28206
28207@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28208 vcc->push(vcc, skb);
28209 spin_lock(&he_dev->global_lock);
28210
28211- atomic_inc(&vcc->stats->rx);
28212+ atomic_inc_unchecked(&vcc->stats->rx);
28213
28214 return_host_buffers:
28215 ++pdus_assembled;
28216@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28217 tpd->vcc->pop(tpd->vcc, tpd->skb);
28218 else
28219 dev_kfree_skb_any(tpd->skb);
28220- atomic_inc(&tpd->vcc->stats->tx_err);
28221+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28222 }
28223 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28224 return;
28225@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28226 vcc->pop(vcc, skb);
28227 else
28228 dev_kfree_skb_any(skb);
28229- atomic_inc(&vcc->stats->tx_err);
28230+ atomic_inc_unchecked(&vcc->stats->tx_err);
28231 return -EINVAL;
28232 }
28233
28234@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28235 vcc->pop(vcc, skb);
28236 else
28237 dev_kfree_skb_any(skb);
28238- atomic_inc(&vcc->stats->tx_err);
28239+ atomic_inc_unchecked(&vcc->stats->tx_err);
28240 return -EINVAL;
28241 }
28242 #endif
28243@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28244 vcc->pop(vcc, skb);
28245 else
28246 dev_kfree_skb_any(skb);
28247- atomic_inc(&vcc->stats->tx_err);
28248+ atomic_inc_unchecked(&vcc->stats->tx_err);
28249 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28250 return -ENOMEM;
28251 }
28252@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28253 vcc->pop(vcc, skb);
28254 else
28255 dev_kfree_skb_any(skb);
28256- atomic_inc(&vcc->stats->tx_err);
28257+ atomic_inc_unchecked(&vcc->stats->tx_err);
28258 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28259 return -ENOMEM;
28260 }
28261@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28262 __enqueue_tpd(he_dev, tpd, cid);
28263 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28264
28265- atomic_inc(&vcc->stats->tx);
28266+ atomic_inc_unchecked(&vcc->stats->tx);
28267
28268 return 0;
28269 }
28270diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28271index 7d01c2a..4e3ac01 100644
28272--- a/drivers/atm/horizon.c
28273+++ b/drivers/atm/horizon.c
28274@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28275 {
28276 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28277 // VC layer stats
28278- atomic_inc(&vcc->stats->rx);
28279+ atomic_inc_unchecked(&vcc->stats->rx);
28280 __net_timestamp(skb);
28281 // end of our responsibility
28282 vcc->push (vcc, skb);
28283@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28284 dev->tx_iovec = NULL;
28285
28286 // VC layer stats
28287- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28288+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28289
28290 // free the skb
28291 hrz_kfree_skb (skb);
28292diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28293index 8974bd2..b856f85 100644
28294--- a/drivers/atm/idt77252.c
28295+++ b/drivers/atm/idt77252.c
28296@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28297 else
28298 dev_kfree_skb(skb);
28299
28300- atomic_inc(&vcc->stats->tx);
28301+ atomic_inc_unchecked(&vcc->stats->tx);
28302 }
28303
28304 atomic_dec(&scq->used);
28305@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28306 if ((sb = dev_alloc_skb(64)) == NULL) {
28307 printk("%s: Can't allocate buffers for aal0.\n",
28308 card->name);
28309- atomic_add(i, &vcc->stats->rx_drop);
28310+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28311 break;
28312 }
28313 if (!atm_charge(vcc, sb->truesize)) {
28314 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28315 card->name);
28316- atomic_add(i - 1, &vcc->stats->rx_drop);
28317+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28318 dev_kfree_skb(sb);
28319 break;
28320 }
28321@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28322 ATM_SKB(sb)->vcc = vcc;
28323 __net_timestamp(sb);
28324 vcc->push(vcc, sb);
28325- atomic_inc(&vcc->stats->rx);
28326+ atomic_inc_unchecked(&vcc->stats->rx);
28327
28328 cell += ATM_CELL_PAYLOAD;
28329 }
28330@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28331 "(CDC: %08x)\n",
28332 card->name, len, rpp->len, readl(SAR_REG_CDC));
28333 recycle_rx_pool_skb(card, rpp);
28334- atomic_inc(&vcc->stats->rx_err);
28335+ atomic_inc_unchecked(&vcc->stats->rx_err);
28336 return;
28337 }
28338 if (stat & SAR_RSQE_CRC) {
28339 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28340 recycle_rx_pool_skb(card, rpp);
28341- atomic_inc(&vcc->stats->rx_err);
28342+ atomic_inc_unchecked(&vcc->stats->rx_err);
28343 return;
28344 }
28345 if (skb_queue_len(&rpp->queue) > 1) {
28346@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28347 RXPRINTK("%s: Can't alloc RX skb.\n",
28348 card->name);
28349 recycle_rx_pool_skb(card, rpp);
28350- atomic_inc(&vcc->stats->rx_err);
28351+ atomic_inc_unchecked(&vcc->stats->rx_err);
28352 return;
28353 }
28354 if (!atm_charge(vcc, skb->truesize)) {
28355@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28356 __net_timestamp(skb);
28357
28358 vcc->push(vcc, skb);
28359- atomic_inc(&vcc->stats->rx);
28360+ atomic_inc_unchecked(&vcc->stats->rx);
28361
28362 return;
28363 }
28364@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28365 __net_timestamp(skb);
28366
28367 vcc->push(vcc, skb);
28368- atomic_inc(&vcc->stats->rx);
28369+ atomic_inc_unchecked(&vcc->stats->rx);
28370
28371 if (skb->truesize > SAR_FB_SIZE_3)
28372 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28373@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28374 if (vcc->qos.aal != ATM_AAL0) {
28375 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28376 card->name, vpi, vci);
28377- atomic_inc(&vcc->stats->rx_drop);
28378+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28379 goto drop;
28380 }
28381
28382 if ((sb = dev_alloc_skb(64)) == NULL) {
28383 printk("%s: Can't allocate buffers for AAL0.\n",
28384 card->name);
28385- atomic_inc(&vcc->stats->rx_err);
28386+ atomic_inc_unchecked(&vcc->stats->rx_err);
28387 goto drop;
28388 }
28389
28390@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28391 ATM_SKB(sb)->vcc = vcc;
28392 __net_timestamp(sb);
28393 vcc->push(vcc, sb);
28394- atomic_inc(&vcc->stats->rx);
28395+ atomic_inc_unchecked(&vcc->stats->rx);
28396
28397 drop:
28398 skb_pull(queue, 64);
28399@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28400
28401 if (vc == NULL) {
28402 printk("%s: NULL connection in send().\n", card->name);
28403- atomic_inc(&vcc->stats->tx_err);
28404+ atomic_inc_unchecked(&vcc->stats->tx_err);
28405 dev_kfree_skb(skb);
28406 return -EINVAL;
28407 }
28408 if (!test_bit(VCF_TX, &vc->flags)) {
28409 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28410- atomic_inc(&vcc->stats->tx_err);
28411+ atomic_inc_unchecked(&vcc->stats->tx_err);
28412 dev_kfree_skb(skb);
28413 return -EINVAL;
28414 }
28415@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28416 break;
28417 default:
28418 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28419- atomic_inc(&vcc->stats->tx_err);
28420+ atomic_inc_unchecked(&vcc->stats->tx_err);
28421 dev_kfree_skb(skb);
28422 return -EINVAL;
28423 }
28424
28425 if (skb_shinfo(skb)->nr_frags != 0) {
28426 printk("%s: No scatter-gather yet.\n", card->name);
28427- atomic_inc(&vcc->stats->tx_err);
28428+ atomic_inc_unchecked(&vcc->stats->tx_err);
28429 dev_kfree_skb(skb);
28430 return -EINVAL;
28431 }
28432@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28433
28434 err = queue_skb(card, vc, skb, oam);
28435 if (err) {
28436- atomic_inc(&vcc->stats->tx_err);
28437+ atomic_inc_unchecked(&vcc->stats->tx_err);
28438 dev_kfree_skb(skb);
28439 return err;
28440 }
28441@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28442 skb = dev_alloc_skb(64);
28443 if (!skb) {
28444 printk("%s: Out of memory in send_oam().\n", card->name);
28445- atomic_inc(&vcc->stats->tx_err);
28446+ atomic_inc_unchecked(&vcc->stats->tx_err);
28447 return -ENOMEM;
28448 }
28449 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28450diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28451index d438601..8b98495 100644
28452--- a/drivers/atm/iphase.c
28453+++ b/drivers/atm/iphase.c
28454@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28455 status = (u_short) (buf_desc_ptr->desc_mode);
28456 if (status & (RX_CER | RX_PTE | RX_OFL))
28457 {
28458- atomic_inc(&vcc->stats->rx_err);
28459+ atomic_inc_unchecked(&vcc->stats->rx_err);
28460 IF_ERR(printk("IA: bad packet, dropping it");)
28461 if (status & RX_CER) {
28462 IF_ERR(printk(" cause: packet CRC error\n");)
28463@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28464 len = dma_addr - buf_addr;
28465 if (len > iadev->rx_buf_sz) {
28466 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28467- atomic_inc(&vcc->stats->rx_err);
28468+ atomic_inc_unchecked(&vcc->stats->rx_err);
28469 goto out_free_desc;
28470 }
28471
28472@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28473 ia_vcc = INPH_IA_VCC(vcc);
28474 if (ia_vcc == NULL)
28475 {
28476- atomic_inc(&vcc->stats->rx_err);
28477+ atomic_inc_unchecked(&vcc->stats->rx_err);
28478 atm_return(vcc, skb->truesize);
28479 dev_kfree_skb_any(skb);
28480 goto INCR_DLE;
28481@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28482 if ((length > iadev->rx_buf_sz) || (length >
28483 (skb->len - sizeof(struct cpcs_trailer))))
28484 {
28485- atomic_inc(&vcc->stats->rx_err);
28486+ atomic_inc_unchecked(&vcc->stats->rx_err);
28487 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28488 length, skb->len);)
28489 atm_return(vcc, skb->truesize);
28490@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28491
28492 IF_RX(printk("rx_dle_intr: skb push");)
28493 vcc->push(vcc,skb);
28494- atomic_inc(&vcc->stats->rx);
28495+ atomic_inc_unchecked(&vcc->stats->rx);
28496 iadev->rx_pkt_cnt++;
28497 }
28498 INCR_DLE:
28499@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28500 {
28501 struct k_sonet_stats *stats;
28502 stats = &PRIV(_ia_dev[board])->sonet_stats;
28503- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28504- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28505- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28506- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28507- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28508- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28509- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28510- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28511- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28512+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28513+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28514+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28515+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28516+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28517+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28518+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28519+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28520+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28521 }
28522 ia_cmds.status = 0;
28523 break;
28524@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28525 if ((desc == 0) || (desc > iadev->num_tx_desc))
28526 {
28527 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28528- atomic_inc(&vcc->stats->tx);
28529+ atomic_inc_unchecked(&vcc->stats->tx);
28530 if (vcc->pop)
28531 vcc->pop(vcc, skb);
28532 else
28533@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28534 ATM_DESC(skb) = vcc->vci;
28535 skb_queue_tail(&iadev->tx_dma_q, skb);
28536
28537- atomic_inc(&vcc->stats->tx);
28538+ atomic_inc_unchecked(&vcc->stats->tx);
28539 iadev->tx_pkt_cnt++;
28540 /* Increment transaction counter */
28541 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28542
28543 #if 0
28544 /* add flow control logic */
28545- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28546+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28547 if (iavcc->vc_desc_cnt > 10) {
28548 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28549 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28550diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28551index 68c7588..7036683 100644
28552--- a/drivers/atm/lanai.c
28553+++ b/drivers/atm/lanai.c
28554@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28555 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28556 lanai_endtx(lanai, lvcc);
28557 lanai_free_skb(lvcc->tx.atmvcc, skb);
28558- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28559+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28560 }
28561
28562 /* Try to fill the buffer - don't call unless there is backlog */
28563@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28564 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28565 __net_timestamp(skb);
28566 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28567- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28568+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28569 out:
28570 lvcc->rx.buf.ptr = end;
28571 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28572@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28573 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28574 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28575 lanai->stats.service_rxnotaal5++;
28576- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28577+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28578 return 0;
28579 }
28580 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28581@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28582 int bytes;
28583 read_unlock(&vcc_sklist_lock);
28584 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28585- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28586+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28587 lvcc->stats.x.aal5.service_trash++;
28588 bytes = (SERVICE_GET_END(s) * 16) -
28589 (((unsigned long) lvcc->rx.buf.ptr) -
28590@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28591 }
28592 if (s & SERVICE_STREAM) {
28593 read_unlock(&vcc_sklist_lock);
28594- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28595+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28596 lvcc->stats.x.aal5.service_stream++;
28597 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28598 "PDU on VCI %d!\n", lanai->number, vci);
28599@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28600 return 0;
28601 }
28602 DPRINTK("got rx crc error on vci %d\n", vci);
28603- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28604+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28605 lvcc->stats.x.aal5.service_rxcrc++;
28606 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28607 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28608diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28609index 1c70c45..300718d 100644
28610--- a/drivers/atm/nicstar.c
28611+++ b/drivers/atm/nicstar.c
28612@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28613 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28614 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28615 card->index);
28616- atomic_inc(&vcc->stats->tx_err);
28617+ atomic_inc_unchecked(&vcc->stats->tx_err);
28618 dev_kfree_skb_any(skb);
28619 return -EINVAL;
28620 }
28621@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28622 if (!vc->tx) {
28623 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28624 card->index);
28625- atomic_inc(&vcc->stats->tx_err);
28626+ atomic_inc_unchecked(&vcc->stats->tx_err);
28627 dev_kfree_skb_any(skb);
28628 return -EINVAL;
28629 }
28630@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28631 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28632 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28633 card->index);
28634- atomic_inc(&vcc->stats->tx_err);
28635+ atomic_inc_unchecked(&vcc->stats->tx_err);
28636 dev_kfree_skb_any(skb);
28637 return -EINVAL;
28638 }
28639
28640 if (skb_shinfo(skb)->nr_frags != 0) {
28641 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28642- atomic_inc(&vcc->stats->tx_err);
28643+ atomic_inc_unchecked(&vcc->stats->tx_err);
28644 dev_kfree_skb_any(skb);
28645 return -EINVAL;
28646 }
28647@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28648 }
28649
28650 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28651- atomic_inc(&vcc->stats->tx_err);
28652+ atomic_inc_unchecked(&vcc->stats->tx_err);
28653 dev_kfree_skb_any(skb);
28654 return -EIO;
28655 }
28656- atomic_inc(&vcc->stats->tx);
28657+ atomic_inc_unchecked(&vcc->stats->tx);
28658
28659 return 0;
28660 }
28661@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28662 printk
28663 ("nicstar%d: Can't allocate buffers for aal0.\n",
28664 card->index);
28665- atomic_add(i, &vcc->stats->rx_drop);
28666+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28667 break;
28668 }
28669 if (!atm_charge(vcc, sb->truesize)) {
28670 RXPRINTK
28671 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28672 card->index);
28673- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28674+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28675 dev_kfree_skb_any(sb);
28676 break;
28677 }
28678@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28679 ATM_SKB(sb)->vcc = vcc;
28680 __net_timestamp(sb);
28681 vcc->push(vcc, sb);
28682- atomic_inc(&vcc->stats->rx);
28683+ atomic_inc_unchecked(&vcc->stats->rx);
28684 cell += ATM_CELL_PAYLOAD;
28685 }
28686
28687@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28688 if (iovb == NULL) {
28689 printk("nicstar%d: Out of iovec buffers.\n",
28690 card->index);
28691- atomic_inc(&vcc->stats->rx_drop);
28692+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28693 recycle_rx_buf(card, skb);
28694 return;
28695 }
28696@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28697 small or large buffer itself. */
28698 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28699 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28700- atomic_inc(&vcc->stats->rx_err);
28701+ atomic_inc_unchecked(&vcc->stats->rx_err);
28702 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28703 NS_MAX_IOVECS);
28704 NS_PRV_IOVCNT(iovb) = 0;
28705@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28706 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28707 card->index);
28708 which_list(card, skb);
28709- atomic_inc(&vcc->stats->rx_err);
28710+ atomic_inc_unchecked(&vcc->stats->rx_err);
28711 recycle_rx_buf(card, skb);
28712 vc->rx_iov = NULL;
28713 recycle_iov_buf(card, iovb);
28714@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28715 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28716 card->index);
28717 which_list(card, skb);
28718- atomic_inc(&vcc->stats->rx_err);
28719+ atomic_inc_unchecked(&vcc->stats->rx_err);
28720 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28721 NS_PRV_IOVCNT(iovb));
28722 vc->rx_iov = NULL;
28723@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28724 printk(" - PDU size mismatch.\n");
28725 else
28726 printk(".\n");
28727- atomic_inc(&vcc->stats->rx_err);
28728+ atomic_inc_unchecked(&vcc->stats->rx_err);
28729 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28730 NS_PRV_IOVCNT(iovb));
28731 vc->rx_iov = NULL;
28732@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28733 /* skb points to a small buffer */
28734 if (!atm_charge(vcc, skb->truesize)) {
28735 push_rxbufs(card, skb);
28736- atomic_inc(&vcc->stats->rx_drop);
28737+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28738 } else {
28739 skb_put(skb, len);
28740 dequeue_sm_buf(card, skb);
28741@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28742 ATM_SKB(skb)->vcc = vcc;
28743 __net_timestamp(skb);
28744 vcc->push(vcc, skb);
28745- atomic_inc(&vcc->stats->rx);
28746+ atomic_inc_unchecked(&vcc->stats->rx);
28747 }
28748 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28749 struct sk_buff *sb;
28750@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28751 if (len <= NS_SMBUFSIZE) {
28752 if (!atm_charge(vcc, sb->truesize)) {
28753 push_rxbufs(card, sb);
28754- atomic_inc(&vcc->stats->rx_drop);
28755+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28756 } else {
28757 skb_put(sb, len);
28758 dequeue_sm_buf(card, sb);
28759@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28760 ATM_SKB(sb)->vcc = vcc;
28761 __net_timestamp(sb);
28762 vcc->push(vcc, sb);
28763- atomic_inc(&vcc->stats->rx);
28764+ atomic_inc_unchecked(&vcc->stats->rx);
28765 }
28766
28767 push_rxbufs(card, skb);
28768@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28769
28770 if (!atm_charge(vcc, skb->truesize)) {
28771 push_rxbufs(card, skb);
28772- atomic_inc(&vcc->stats->rx_drop);
28773+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28774 } else {
28775 dequeue_lg_buf(card, skb);
28776 #ifdef NS_USE_DESTRUCTORS
28777@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28778 ATM_SKB(skb)->vcc = vcc;
28779 __net_timestamp(skb);
28780 vcc->push(vcc, skb);
28781- atomic_inc(&vcc->stats->rx);
28782+ atomic_inc_unchecked(&vcc->stats->rx);
28783 }
28784
28785 push_rxbufs(card, sb);
28786@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28787 printk
28788 ("nicstar%d: Out of huge buffers.\n",
28789 card->index);
28790- atomic_inc(&vcc->stats->rx_drop);
28791+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28792 recycle_iovec_rx_bufs(card,
28793 (struct iovec *)
28794 iovb->data,
28795@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28796 card->hbpool.count++;
28797 } else
28798 dev_kfree_skb_any(hb);
28799- atomic_inc(&vcc->stats->rx_drop);
28800+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28801 } else {
28802 /* Copy the small buffer to the huge buffer */
28803 sb = (struct sk_buff *)iov->iov_base;
28804@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28805 #endif /* NS_USE_DESTRUCTORS */
28806 __net_timestamp(hb);
28807 vcc->push(vcc, hb);
28808- atomic_inc(&vcc->stats->rx);
28809+ atomic_inc_unchecked(&vcc->stats->rx);
28810 }
28811 }
28812
28813diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28814index 9851093..adb2b1e 100644
28815--- a/drivers/atm/solos-pci.c
28816+++ b/drivers/atm/solos-pci.c
28817@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28818 }
28819 atm_charge(vcc, skb->truesize);
28820 vcc->push(vcc, skb);
28821- atomic_inc(&vcc->stats->rx);
28822+ atomic_inc_unchecked(&vcc->stats->rx);
28823 break;
28824
28825 case PKT_STATUS:
28826@@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28827 vcc = SKB_CB(oldskb)->vcc;
28828
28829 if (vcc) {
28830- atomic_inc(&vcc->stats->tx);
28831+ atomic_inc_unchecked(&vcc->stats->tx);
28832 solos_pop(vcc, oldskb);
28833 } else
28834 dev_kfree_skb_irq(oldskb);
28835diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28836index 0215934..ce9f5b1 100644
28837--- a/drivers/atm/suni.c
28838+++ b/drivers/atm/suni.c
28839@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28840
28841
28842 #define ADD_LIMITED(s,v) \
28843- atomic_add((v),&stats->s); \
28844- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28845+ atomic_add_unchecked((v),&stats->s); \
28846+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28847
28848
28849 static void suni_hz(unsigned long from_timer)
28850diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28851index 5120a96..e2572bd 100644
28852--- a/drivers/atm/uPD98402.c
28853+++ b/drivers/atm/uPD98402.c
28854@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28855 struct sonet_stats tmp;
28856 int error = 0;
28857
28858- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28859+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28860 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28861 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28862 if (zero && !error) {
28863@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28864
28865
28866 #define ADD_LIMITED(s,v) \
28867- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28868- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28869- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28870+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28871+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28872+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28873
28874
28875 static void stat_event(struct atm_dev *dev)
28876@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28877 if (reason & uPD98402_INT_PFM) stat_event(dev);
28878 if (reason & uPD98402_INT_PCO) {
28879 (void) GET(PCOCR); /* clear interrupt cause */
28880- atomic_add(GET(HECCT),
28881+ atomic_add_unchecked(GET(HECCT),
28882 &PRIV(dev)->sonet_stats.uncorr_hcs);
28883 }
28884 if ((reason & uPD98402_INT_RFO) &&
28885@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28886 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28887 uPD98402_INT_LOS),PIMR); /* enable them */
28888 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28889- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28890- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28891- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28892+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28893+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28894+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28895 return 0;
28896 }
28897
28898diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28899index abe4e20..83c4727 100644
28900--- a/drivers/atm/zatm.c
28901+++ b/drivers/atm/zatm.c
28902@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28903 }
28904 if (!size) {
28905 dev_kfree_skb_irq(skb);
28906- if (vcc) atomic_inc(&vcc->stats->rx_err);
28907+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28908 continue;
28909 }
28910 if (!atm_charge(vcc,skb->truesize)) {
28911@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28912 skb->len = size;
28913 ATM_SKB(skb)->vcc = vcc;
28914 vcc->push(vcc,skb);
28915- atomic_inc(&vcc->stats->rx);
28916+ atomic_inc_unchecked(&vcc->stats->rx);
28917 }
28918 zout(pos & 0xffff,MTA(mbx));
28919 #if 0 /* probably a stupid idea */
28920@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28921 skb_queue_head(&zatm_vcc->backlog,skb);
28922 break;
28923 }
28924- atomic_inc(&vcc->stats->tx);
28925+ atomic_inc_unchecked(&vcc->stats->tx);
28926 wake_up(&zatm_vcc->tx_wait);
28927 }
28928
28929diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28930index 765c3a2..771ace6 100644
28931--- a/drivers/base/devtmpfs.c
28932+++ b/drivers/base/devtmpfs.c
28933@@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28934 if (!thread)
28935 return 0;
28936
28937- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28938+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28939 if (err)
28940 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28941 else
28942diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28943index cbb463b..babe2cf 100644
28944--- a/drivers/base/power/wakeup.c
28945+++ b/drivers/base/power/wakeup.c
28946@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28947 * They need to be modified together atomically, so it's better to use one
28948 * atomic variable to hold them both.
28949 */
28950-static atomic_t combined_event_count = ATOMIC_INIT(0);
28951+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28952
28953 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28954 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28955
28956 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28957 {
28958- unsigned int comb = atomic_read(&combined_event_count);
28959+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
28960
28961 *cnt = (comb >> IN_PROGRESS_BITS);
28962 *inpr = comb & MAX_IN_PROGRESS;
28963@@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28964 ws->start_prevent_time = ws->last_time;
28965
28966 /* Increment the counter of events in progress. */
28967- cec = atomic_inc_return(&combined_event_count);
28968+ cec = atomic_inc_return_unchecked(&combined_event_count);
28969
28970 trace_wakeup_source_activate(ws->name, cec);
28971 }
28972@@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28973 * Increment the counter of registered wakeup events and decrement the
28974 * couter of wakeup events in progress simultaneously.
28975 */
28976- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
28977+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28978 trace_wakeup_source_deactivate(ws->name, cec);
28979
28980 split_counters(&cnt, &inpr);
28981diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28982index b0f553b..77b928b 100644
28983--- a/drivers/block/cciss.c
28984+++ b/drivers/block/cciss.c
28985@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28986 int err;
28987 u32 cp;
28988
28989+ memset(&arg64, 0, sizeof(arg64));
28990+
28991 err = 0;
28992 err |=
28993 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28994@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28995 while (!list_empty(&h->reqQ)) {
28996 c = list_entry(h->reqQ.next, CommandList_struct, list);
28997 /* can't do anything if fifo is full */
28998- if ((h->access.fifo_full(h))) {
28999+ if ((h->access->fifo_full(h))) {
29000 dev_warn(&h->pdev->dev, "fifo full\n");
29001 break;
29002 }
29003@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29004 h->Qdepth--;
29005
29006 /* Tell the controller execute command */
29007- h->access.submit_command(h, c);
29008+ h->access->submit_command(h, c);
29009
29010 /* Put job onto the completed Q */
29011 addQ(&h->cmpQ, c);
29012@@ -3443,17 +3445,17 @@ startio:
29013
29014 static inline unsigned long get_next_completion(ctlr_info_t *h)
29015 {
29016- return h->access.command_completed(h);
29017+ return h->access->command_completed(h);
29018 }
29019
29020 static inline int interrupt_pending(ctlr_info_t *h)
29021 {
29022- return h->access.intr_pending(h);
29023+ return h->access->intr_pending(h);
29024 }
29025
29026 static inline long interrupt_not_for_us(ctlr_info_t *h)
29027 {
29028- return ((h->access.intr_pending(h) == 0) ||
29029+ return ((h->access->intr_pending(h) == 0) ||
29030 (h->interrupts_enabled == 0));
29031 }
29032
29033@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29034 u32 a;
29035
29036 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29037- return h->access.command_completed(h);
29038+ return h->access->command_completed(h);
29039
29040 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29041 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29042@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29043 trans_support & CFGTBL_Trans_use_short_tags);
29044
29045 /* Change the access methods to the performant access methods */
29046- h->access = SA5_performant_access;
29047+ h->access = &SA5_performant_access;
29048 h->transMethod = CFGTBL_Trans_Performant;
29049
29050 return;
29051@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29052 if (prod_index < 0)
29053 return -ENODEV;
29054 h->product_name = products[prod_index].product_name;
29055- h->access = *(products[prod_index].access);
29056+ h->access = products[prod_index].access;
29057
29058 if (cciss_board_disabled(h)) {
29059 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29060@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29061 }
29062
29063 /* make sure the board interrupts are off */
29064- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29065+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29066 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29067 if (rc)
29068 goto clean2;
29069@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29070 * fake ones to scoop up any residual completions.
29071 */
29072 spin_lock_irqsave(&h->lock, flags);
29073- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29074+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29075 spin_unlock_irqrestore(&h->lock, flags);
29076 free_irq(h->intr[h->intr_mode], h);
29077 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29078@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29079 dev_info(&h->pdev->dev, "Board READY.\n");
29080 dev_info(&h->pdev->dev,
29081 "Waiting for stale completions to drain.\n");
29082- h->access.set_intr_mask(h, CCISS_INTR_ON);
29083+ h->access->set_intr_mask(h, CCISS_INTR_ON);
29084 msleep(10000);
29085- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29086+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29087
29088 rc = controller_reset_failed(h->cfgtable);
29089 if (rc)
29090@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29091 cciss_scsi_setup(h);
29092
29093 /* Turn the interrupts on so we can service requests */
29094- h->access.set_intr_mask(h, CCISS_INTR_ON);
29095+ h->access->set_intr_mask(h, CCISS_INTR_ON);
29096
29097 /* Get the firmware version */
29098 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29099@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29100 kfree(flush_buf);
29101 if (return_code != IO_OK)
29102 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29103- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29104+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29105 free_irq(h->intr[h->intr_mode], h);
29106 }
29107
29108diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29109index 7fda30e..eb5dfe0 100644
29110--- a/drivers/block/cciss.h
29111+++ b/drivers/block/cciss.h
29112@@ -101,7 +101,7 @@ struct ctlr_info
29113 /* information about each logical volume */
29114 drive_info_struct *drv[CISS_MAX_LUN];
29115
29116- struct access_method access;
29117+ struct access_method *access;
29118
29119 /* queue and queue Info */
29120 struct list_head reqQ;
29121diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29122index 9125bbe..eede5c8 100644
29123--- a/drivers/block/cpqarray.c
29124+++ b/drivers/block/cpqarray.c
29125@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29126 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29127 goto Enomem4;
29128 }
29129- hba[i]->access.set_intr_mask(hba[i], 0);
29130+ hba[i]->access->set_intr_mask(hba[i], 0);
29131 if (request_irq(hba[i]->intr, do_ida_intr,
29132 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29133 {
29134@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29135 add_timer(&hba[i]->timer);
29136
29137 /* Enable IRQ now that spinlock and rate limit timer are set up */
29138- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29139+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29140
29141 for(j=0; j<NWD; j++) {
29142 struct gendisk *disk = ida_gendisk[i][j];
29143@@ -694,7 +694,7 @@ DBGINFO(
29144 for(i=0; i<NR_PRODUCTS; i++) {
29145 if (board_id == products[i].board_id) {
29146 c->product_name = products[i].product_name;
29147- c->access = *(products[i].access);
29148+ c->access = products[i].access;
29149 break;
29150 }
29151 }
29152@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29153 hba[ctlr]->intr = intr;
29154 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29155 hba[ctlr]->product_name = products[j].product_name;
29156- hba[ctlr]->access = *(products[j].access);
29157+ hba[ctlr]->access = products[j].access;
29158 hba[ctlr]->ctlr = ctlr;
29159 hba[ctlr]->board_id = board_id;
29160 hba[ctlr]->pci_dev = NULL; /* not PCI */
29161@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29162
29163 while((c = h->reqQ) != NULL) {
29164 /* Can't do anything if we're busy */
29165- if (h->access.fifo_full(h) == 0)
29166+ if (h->access->fifo_full(h) == 0)
29167 return;
29168
29169 /* Get the first entry from the request Q */
29170@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29171 h->Qdepth--;
29172
29173 /* Tell the controller to do our bidding */
29174- h->access.submit_command(h, c);
29175+ h->access->submit_command(h, c);
29176
29177 /* Get onto the completion Q */
29178 addQ(&h->cmpQ, c);
29179@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29180 unsigned long flags;
29181 __u32 a,a1;
29182
29183- istat = h->access.intr_pending(h);
29184+ istat = h->access->intr_pending(h);
29185 /* Is this interrupt for us? */
29186 if (istat == 0)
29187 return IRQ_NONE;
29188@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29189 */
29190 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29191 if (istat & FIFO_NOT_EMPTY) {
29192- while((a = h->access.command_completed(h))) {
29193+ while((a = h->access->command_completed(h))) {
29194 a1 = a; a &= ~3;
29195 if ((c = h->cmpQ) == NULL)
29196 {
29197@@ -1449,11 +1449,11 @@ static int sendcmd(
29198 /*
29199 * Disable interrupt
29200 */
29201- info_p->access.set_intr_mask(info_p, 0);
29202+ info_p->access->set_intr_mask(info_p, 0);
29203 /* Make sure there is room in the command FIFO */
29204 /* Actually it should be completely empty at this time. */
29205 for (i = 200000; i > 0; i--) {
29206- temp = info_p->access.fifo_full(info_p);
29207+ temp = info_p->access->fifo_full(info_p);
29208 if (temp != 0) {
29209 break;
29210 }
29211@@ -1466,7 +1466,7 @@ DBG(
29212 /*
29213 * Send the cmd
29214 */
29215- info_p->access.submit_command(info_p, c);
29216+ info_p->access->submit_command(info_p, c);
29217 complete = pollcomplete(ctlr);
29218
29219 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29220@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29221 * we check the new geometry. Then turn interrupts back on when
29222 * we're done.
29223 */
29224- host->access.set_intr_mask(host, 0);
29225+ host->access->set_intr_mask(host, 0);
29226 getgeometry(ctlr);
29227- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29228+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29229
29230 for(i=0; i<NWD; i++) {
29231 struct gendisk *disk = ida_gendisk[ctlr][i];
29232@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29233 /* Wait (up to 2 seconds) for a command to complete */
29234
29235 for (i = 200000; i > 0; i--) {
29236- done = hba[ctlr]->access.command_completed(hba[ctlr]);
29237+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
29238 if (done == 0) {
29239 udelay(10); /* a short fixed delay */
29240 } else
29241diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29242index be73e9d..7fbf140 100644
29243--- a/drivers/block/cpqarray.h
29244+++ b/drivers/block/cpqarray.h
29245@@ -99,7 +99,7 @@ struct ctlr_info {
29246 drv_info_t drv[NWD];
29247 struct proc_dir_entry *proc;
29248
29249- struct access_method access;
29250+ struct access_method *access;
29251
29252 cmdlist_t *reqQ;
29253 cmdlist_t *cmpQ;
29254diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29255index 02f013a..afeba24 100644
29256--- a/drivers/block/drbd/drbd_int.h
29257+++ b/drivers/block/drbd/drbd_int.h
29258@@ -735,7 +735,7 @@ struct drbd_request;
29259 struct drbd_epoch {
29260 struct list_head list;
29261 unsigned int barrier_nr;
29262- atomic_t epoch_size; /* increased on every request added. */
29263+ atomic_unchecked_t epoch_size; /* increased on every request added. */
29264 atomic_t active; /* increased on every req. added, and dec on every finished. */
29265 unsigned long flags;
29266 };
29267@@ -1110,7 +1110,7 @@ struct drbd_conf {
29268 void *int_dig_in;
29269 void *int_dig_vv;
29270 wait_queue_head_t seq_wait;
29271- atomic_t packet_seq;
29272+ atomic_unchecked_t packet_seq;
29273 unsigned int peer_seq;
29274 spinlock_t peer_seq_lock;
29275 unsigned int minor;
29276@@ -1651,30 +1651,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29277
29278 static inline void drbd_tcp_cork(struct socket *sock)
29279 {
29280- int __user val = 1;
29281+ int val = 1;
29282 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29283- (char __user *)&val, sizeof(val));
29284+ (char __force_user *)&val, sizeof(val));
29285 }
29286
29287 static inline void drbd_tcp_uncork(struct socket *sock)
29288 {
29289- int __user val = 0;
29290+ int val = 0;
29291 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29292- (char __user *)&val, sizeof(val));
29293+ (char __force_user *)&val, sizeof(val));
29294 }
29295
29296 static inline void drbd_tcp_nodelay(struct socket *sock)
29297 {
29298- int __user val = 1;
29299+ int val = 1;
29300 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29301- (char __user *)&val, sizeof(val));
29302+ (char __force_user *)&val, sizeof(val));
29303 }
29304
29305 static inline void drbd_tcp_quickack(struct socket *sock)
29306 {
29307- int __user val = 2;
29308+ int val = 2;
29309 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29310- (char __user *)&val, sizeof(val));
29311+ (char __force_user *)&val, sizeof(val));
29312 }
29313
29314 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29315diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29316index 920ede2..cb827ba 100644
29317--- a/drivers/block/drbd/drbd_main.c
29318+++ b/drivers/block/drbd/drbd_main.c
29319@@ -2555,7 +2555,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29320 p.sector = sector;
29321 p.block_id = block_id;
29322 p.blksize = blksize;
29323- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29324+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29325
29326 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29327 return false;
29328@@ -2853,7 +2853,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29329
29330 p.sector = cpu_to_be64(req->sector);
29331 p.block_id = (unsigned long)req;
29332- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29333+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29334
29335 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29336
29337@@ -3138,7 +3138,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29338 atomic_set(&mdev->unacked_cnt, 0);
29339 atomic_set(&mdev->local_cnt, 0);
29340 atomic_set(&mdev->net_cnt, 0);
29341- atomic_set(&mdev->packet_seq, 0);
29342+ atomic_set_unchecked(&mdev->packet_seq, 0);
29343 atomic_set(&mdev->pp_in_use, 0);
29344 atomic_set(&mdev->pp_in_use_by_net, 0);
29345 atomic_set(&mdev->rs_sect_in, 0);
29346@@ -3220,8 +3220,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29347 mdev->receiver.t_state);
29348
29349 /* no need to lock it, I'm the only thread alive */
29350- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29351- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29352+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29353+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29354 mdev->al_writ_cnt =
29355 mdev->bm_writ_cnt =
29356 mdev->read_cnt =
29357diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29358index 6d4de6a..7b7ad4b 100644
29359--- a/drivers/block/drbd/drbd_nl.c
29360+++ b/drivers/block/drbd/drbd_nl.c
29361@@ -2387,7 +2387,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29362 module_put(THIS_MODULE);
29363 }
29364
29365-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29366+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29367
29368 static unsigned short *
29369 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29370@@ -2458,7 +2458,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29371 cn_reply->id.idx = CN_IDX_DRBD;
29372 cn_reply->id.val = CN_VAL_DRBD;
29373
29374- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29375+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29376 cn_reply->ack = 0; /* not used here. */
29377 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29378 (int)((char *)tl - (char *)reply->tag_list);
29379@@ -2490,7 +2490,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29380 cn_reply->id.idx = CN_IDX_DRBD;
29381 cn_reply->id.val = CN_VAL_DRBD;
29382
29383- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29384+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29385 cn_reply->ack = 0; /* not used here. */
29386 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29387 (int)((char *)tl - (char *)reply->tag_list);
29388@@ -2568,7 +2568,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29389 cn_reply->id.idx = CN_IDX_DRBD;
29390 cn_reply->id.val = CN_VAL_DRBD;
29391
29392- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29393+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29394 cn_reply->ack = 0; // not used here.
29395 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29396 (int)((char*)tl - (char*)reply->tag_list);
29397@@ -2607,7 +2607,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29398 cn_reply->id.idx = CN_IDX_DRBD;
29399 cn_reply->id.val = CN_VAL_DRBD;
29400
29401- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29402+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29403 cn_reply->ack = 0; /* not used here. */
29404 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29405 (int)((char *)tl - (char *)reply->tag_list);
29406diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29407index ea4836e..272d72a 100644
29408--- a/drivers/block/drbd/drbd_receiver.c
29409+++ b/drivers/block/drbd/drbd_receiver.c
29410@@ -893,7 +893,7 @@ retry:
29411 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29412 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29413
29414- atomic_set(&mdev->packet_seq, 0);
29415+ atomic_set_unchecked(&mdev->packet_seq, 0);
29416 mdev->peer_seq = 0;
29417
29418 if (drbd_send_protocol(mdev) == -1)
29419@@ -994,7 +994,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29420 do {
29421 next_epoch = NULL;
29422
29423- epoch_size = atomic_read(&epoch->epoch_size);
29424+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29425
29426 switch (ev & ~EV_CLEANUP) {
29427 case EV_PUT:
29428@@ -1030,7 +1030,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29429 rv = FE_DESTROYED;
29430 } else {
29431 epoch->flags = 0;
29432- atomic_set(&epoch->epoch_size, 0);
29433+ atomic_set_unchecked(&epoch->epoch_size, 0);
29434 /* atomic_set(&epoch->active, 0); is already zero */
29435 if (rv == FE_STILL_LIVE)
29436 rv = FE_RECYCLED;
29437@@ -1205,14 +1205,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29438 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29439 drbd_flush(mdev);
29440
29441- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29442+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29443 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29444 if (epoch)
29445 break;
29446 }
29447
29448 epoch = mdev->current_epoch;
29449- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29450+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29451
29452 D_ASSERT(atomic_read(&epoch->active) == 0);
29453 D_ASSERT(epoch->flags == 0);
29454@@ -1224,11 +1224,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29455 }
29456
29457 epoch->flags = 0;
29458- atomic_set(&epoch->epoch_size, 0);
29459+ atomic_set_unchecked(&epoch->epoch_size, 0);
29460 atomic_set(&epoch->active, 0);
29461
29462 spin_lock(&mdev->epoch_lock);
29463- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29464+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29465 list_add(&epoch->list, &mdev->current_epoch->list);
29466 mdev->current_epoch = epoch;
29467 mdev->epochs++;
29468@@ -1695,7 +1695,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29469 spin_unlock(&mdev->peer_seq_lock);
29470
29471 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29472- atomic_inc(&mdev->current_epoch->epoch_size);
29473+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29474 return drbd_drain_block(mdev, data_size);
29475 }
29476
29477@@ -1721,7 +1721,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29478
29479 spin_lock(&mdev->epoch_lock);
29480 e->epoch = mdev->current_epoch;
29481- atomic_inc(&e->epoch->epoch_size);
29482+ atomic_inc_unchecked(&e->epoch->epoch_size);
29483 atomic_inc(&e->epoch->active);
29484 spin_unlock(&mdev->epoch_lock);
29485
29486@@ -3936,7 +3936,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29487 D_ASSERT(list_empty(&mdev->done_ee));
29488
29489 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29490- atomic_set(&mdev->current_epoch->epoch_size, 0);
29491+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29492 D_ASSERT(list_empty(&mdev->current_epoch->list));
29493 }
29494
29495diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29496index 3bba655..6151b66 100644
29497--- a/drivers/block/loop.c
29498+++ b/drivers/block/loop.c
29499@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29500 mm_segment_t old_fs = get_fs();
29501
29502 set_fs(get_ds());
29503- bw = file->f_op->write(file, buf, len, &pos);
29504+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29505 set_fs(old_fs);
29506 if (likely(bw == len))
29507 return 0;
29508diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29509index ea6f632..eafb192 100644
29510--- a/drivers/char/Kconfig
29511+++ b/drivers/char/Kconfig
29512@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29513
29514 config DEVKMEM
29515 bool "/dev/kmem virtual device support"
29516- default y
29517+ default n
29518+ depends on !GRKERNSEC_KMEM
29519 help
29520 Say Y here if you want to support the /dev/kmem device. The
29521 /dev/kmem device is rarely used, but can be used for certain
29522@@ -581,6 +582,7 @@ config DEVPORT
29523 bool
29524 depends on !M68K
29525 depends on ISA || PCI
29526+ depends on !GRKERNSEC_KMEM
29527 default y
29528
29529 source "drivers/s390/char/Kconfig"
29530diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29531index 2e04433..22afc64 100644
29532--- a/drivers/char/agp/frontend.c
29533+++ b/drivers/char/agp/frontend.c
29534@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29535 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29536 return -EFAULT;
29537
29538- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29539+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29540 return -EFAULT;
29541
29542 client = agp_find_client_by_pid(reserve.pid);
29543diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29544index 21cb980..f15107c 100644
29545--- a/drivers/char/genrtc.c
29546+++ b/drivers/char/genrtc.c
29547@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29548 switch (cmd) {
29549
29550 case RTC_PLL_GET:
29551+ memset(&pll, 0, sizeof(pll));
29552 if (get_rtc_pll(&pll))
29553 return -EINVAL;
29554 else
29555diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29556index dfd7876..c0b0885 100644
29557--- a/drivers/char/hpet.c
29558+++ b/drivers/char/hpet.c
29559@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29560 }
29561
29562 static int
29563-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29564+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29565 struct hpet_info *info)
29566 {
29567 struct hpet_timer __iomem *timer;
29568diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29569index 2c29942..604c5ba 100644
29570--- a/drivers/char/ipmi/ipmi_msghandler.c
29571+++ b/drivers/char/ipmi/ipmi_msghandler.c
29572@@ -420,7 +420,7 @@ struct ipmi_smi {
29573 struct proc_dir_entry *proc_dir;
29574 char proc_dir_name[10];
29575
29576- atomic_t stats[IPMI_NUM_STATS];
29577+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29578
29579 /*
29580 * run_to_completion duplicate of smb_info, smi_info
29581@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29582
29583
29584 #define ipmi_inc_stat(intf, stat) \
29585- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29586+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29587 #define ipmi_get_stat(intf, stat) \
29588- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29589+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29590
29591 static int is_lan_addr(struct ipmi_addr *addr)
29592 {
29593@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29594 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29595 init_waitqueue_head(&intf->waitq);
29596 for (i = 0; i < IPMI_NUM_STATS; i++)
29597- atomic_set(&intf->stats[i], 0);
29598+ atomic_set_unchecked(&intf->stats[i], 0);
29599
29600 intf->proc_dir = NULL;
29601
29602diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29603index 1e638ff..a869ef5 100644
29604--- a/drivers/char/ipmi/ipmi_si_intf.c
29605+++ b/drivers/char/ipmi/ipmi_si_intf.c
29606@@ -275,7 +275,7 @@ struct smi_info {
29607 unsigned char slave_addr;
29608
29609 /* Counters and things for the proc filesystem. */
29610- atomic_t stats[SI_NUM_STATS];
29611+ atomic_unchecked_t stats[SI_NUM_STATS];
29612
29613 struct task_struct *thread;
29614
29615@@ -284,9 +284,9 @@ struct smi_info {
29616 };
29617
29618 #define smi_inc_stat(smi, stat) \
29619- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29620+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29621 #define smi_get_stat(smi, stat) \
29622- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29623+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29624
29625 #define SI_MAX_PARMS 4
29626
29627@@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29628 atomic_set(&new_smi->req_events, 0);
29629 new_smi->run_to_completion = 0;
29630 for (i = 0; i < SI_NUM_STATS; i++)
29631- atomic_set(&new_smi->stats[i], 0);
29632+ atomic_set_unchecked(&new_smi->stats[i], 0);
29633
29634 new_smi->interrupt_disabled = 1;
29635 atomic_set(&new_smi->stop_operation, 0);
29636diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29637index 47ff7e4..0c7d340 100644
29638--- a/drivers/char/mbcs.c
29639+++ b/drivers/char/mbcs.c
29640@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29641 return 0;
29642 }
29643
29644-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29645+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29646 {
29647 .part_num = MBCS_PART_NUM,
29648 .mfg_num = MBCS_MFG_NUM,
29649diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29650index 67c3371..ba8429d 100644
29651--- a/drivers/char/mem.c
29652+++ b/drivers/char/mem.c
29653@@ -18,6 +18,7 @@
29654 #include <linux/raw.h>
29655 #include <linux/tty.h>
29656 #include <linux/capability.h>
29657+#include <linux/security.h>
29658 #include <linux/ptrace.h>
29659 #include <linux/device.h>
29660 #include <linux/highmem.h>
29661@@ -35,6 +36,10 @@
29662 # include <linux/efi.h>
29663 #endif
29664
29665+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29666+extern const struct file_operations grsec_fops;
29667+#endif
29668+
29669 static inline unsigned long size_inside_page(unsigned long start,
29670 unsigned long size)
29671 {
29672@@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29673
29674 while (cursor < to) {
29675 if (!devmem_is_allowed(pfn)) {
29676+#ifdef CONFIG_GRKERNSEC_KMEM
29677+ gr_handle_mem_readwrite(from, to);
29678+#else
29679 printk(KERN_INFO
29680 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29681 current->comm, from, to);
29682+#endif
29683 return 0;
29684 }
29685 cursor += PAGE_SIZE;
29686@@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29687 }
29688 return 1;
29689 }
29690+#elif defined(CONFIG_GRKERNSEC_KMEM)
29691+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29692+{
29693+ return 0;
29694+}
29695 #else
29696 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29697 {
29698@@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29699
29700 while (count > 0) {
29701 unsigned long remaining;
29702+ char *temp;
29703
29704 sz = size_inside_page(p, count);
29705
29706@@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29707 if (!ptr)
29708 return -EFAULT;
29709
29710- remaining = copy_to_user(buf, ptr, sz);
29711+#ifdef CONFIG_PAX_USERCOPY
29712+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29713+ if (!temp) {
29714+ unxlate_dev_mem_ptr(p, ptr);
29715+ return -ENOMEM;
29716+ }
29717+ memcpy(temp, ptr, sz);
29718+#else
29719+ temp = ptr;
29720+#endif
29721+
29722+ remaining = copy_to_user(buf, temp, sz);
29723+
29724+#ifdef CONFIG_PAX_USERCOPY
29725+ kfree(temp);
29726+#endif
29727+
29728 unxlate_dev_mem_ptr(p, ptr);
29729 if (remaining)
29730 return -EFAULT;
29731@@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29732 size_t count, loff_t *ppos)
29733 {
29734 unsigned long p = *ppos;
29735- ssize_t low_count, read, sz;
29736+ ssize_t low_count, read, sz, err = 0;
29737 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29738- int err = 0;
29739
29740 read = 0;
29741 if (p < (unsigned long) high_memory) {
29742@@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29743 }
29744 #endif
29745 while (low_count > 0) {
29746+ char *temp;
29747+
29748 sz = size_inside_page(p, low_count);
29749
29750 /*
29751@@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29752 */
29753 kbuf = xlate_dev_kmem_ptr((char *)p);
29754
29755- if (copy_to_user(buf, kbuf, sz))
29756+#ifdef CONFIG_PAX_USERCOPY
29757+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29758+ if (!temp)
29759+ return -ENOMEM;
29760+ memcpy(temp, kbuf, sz);
29761+#else
29762+ temp = kbuf;
29763+#endif
29764+
29765+ err = copy_to_user(buf, temp, sz);
29766+
29767+#ifdef CONFIG_PAX_USERCOPY
29768+ kfree(temp);
29769+#endif
29770+
29771+ if (err)
29772 return -EFAULT;
29773 buf += sz;
29774 p += sz;
29775@@ -831,6 +878,9 @@ static const struct memdev {
29776 #ifdef CONFIG_CRASH_DUMP
29777 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29778 #endif
29779+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29780+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29781+#endif
29782 };
29783
29784 static int memory_open(struct inode *inode, struct file *filp)
29785diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29786index 9df78e2..01ba9ae 100644
29787--- a/drivers/char/nvram.c
29788+++ b/drivers/char/nvram.c
29789@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29790
29791 spin_unlock_irq(&rtc_lock);
29792
29793- if (copy_to_user(buf, contents, tmp - contents))
29794+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29795 return -EFAULT;
29796
29797 *ppos = i;
29798diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29799index 0a484b4..f48ccd1 100644
29800--- a/drivers/char/pcmcia/synclink_cs.c
29801+++ b/drivers/char/pcmcia/synclink_cs.c
29802@@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29803
29804 if (debug_level >= DEBUG_LEVEL_INFO)
29805 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29806- __FILE__,__LINE__, info->device_name, port->count);
29807+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29808
29809- WARN_ON(!port->count);
29810+ WARN_ON(!atomic_read(&port->count));
29811
29812 if (tty_port_close_start(port, tty, filp) == 0)
29813 goto cleanup;
29814@@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29815 cleanup:
29816 if (debug_level >= DEBUG_LEVEL_INFO)
29817 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29818- tty->driver->name, port->count);
29819+ tty->driver->name, atomic_read(&port->count));
29820 }
29821
29822 /* Wait until the transmitter is empty.
29823@@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29824
29825 if (debug_level >= DEBUG_LEVEL_INFO)
29826 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29827- __FILE__,__LINE__,tty->driver->name, port->count);
29828+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29829
29830 /* If port is closing, signal caller to try again */
29831 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29832@@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29833 goto cleanup;
29834 }
29835 spin_lock(&port->lock);
29836- port->count++;
29837+ atomic_inc(&port->count);
29838 spin_unlock(&port->lock);
29839 spin_unlock_irqrestore(&info->netlock, flags);
29840
29841- if (port->count == 1) {
29842+ if (atomic_read(&port->count) == 1) {
29843 /* 1st open on this device, init hardware */
29844 retval = startup(info, tty);
29845 if (retval < 0)
29846@@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29847 unsigned short new_crctype;
29848
29849 /* return error if TTY interface open */
29850- if (info->port.count)
29851+ if (atomic_read(&info->port.count))
29852 return -EBUSY;
29853
29854 switch (encoding)
29855@@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29856
29857 /* arbitrate between network and tty opens */
29858 spin_lock_irqsave(&info->netlock, flags);
29859- if (info->port.count != 0 || info->netcount != 0) {
29860+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29861 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29862 spin_unlock_irqrestore(&info->netlock, flags);
29863 return -EBUSY;
29864@@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29865 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29866
29867 /* return error if TTY interface open */
29868- if (info->port.count)
29869+ if (atomic_read(&info->port.count))
29870 return -EBUSY;
29871
29872 if (cmd != SIOCWANDEV)
29873diff --git a/drivers/char/random.c b/drivers/char/random.c
29874index d98b2a6..f0ceb97 100644
29875--- a/drivers/char/random.c
29876+++ b/drivers/char/random.c
29877@@ -272,8 +272,13 @@
29878 /*
29879 * Configuration information
29880 */
29881+#ifdef CONFIG_GRKERNSEC_RANDNET
29882+#define INPUT_POOL_WORDS 512
29883+#define OUTPUT_POOL_WORDS 128
29884+#else
29885 #define INPUT_POOL_WORDS 128
29886 #define OUTPUT_POOL_WORDS 32
29887+#endif
29888 #define SEC_XFER_SIZE 512
29889 #define EXTRACT_SIZE 10
29890
29891@@ -313,10 +318,17 @@ static struct poolinfo {
29892 int poolwords;
29893 int tap1, tap2, tap3, tap4, tap5;
29894 } poolinfo_table[] = {
29895+#ifdef CONFIG_GRKERNSEC_RANDNET
29896+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29897+ { 512, 411, 308, 208, 104, 1 },
29898+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29899+ { 128, 103, 76, 51, 25, 1 },
29900+#else
29901 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29902 { 128, 103, 76, 51, 25, 1 },
29903 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29904 { 32, 26, 20, 14, 7, 1 },
29905+#endif
29906 #if 0
29907 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29908 { 2048, 1638, 1231, 819, 411, 1 },
29909@@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29910 input_rotate += i ? 7 : 14;
29911 }
29912
29913- ACCESS_ONCE(r->input_rotate) = input_rotate;
29914- ACCESS_ONCE(r->add_ptr) = i;
29915+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29916+ ACCESS_ONCE_RW(r->add_ptr) = i;
29917 smp_wmb();
29918
29919 if (out)
29920@@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29921 }
29922 #endif
29923
29924+#ifdef CONFIG_PAX_LATENT_ENTROPY
29925+u64 latent_entropy;
29926+
29927+__init void transfer_latent_entropy(void)
29928+{
29929+ mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29930+ mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29931+// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29932+}
29933+#endif
29934+
29935 /*********************************************************************
29936 *
29937 * Entropy extraction routines
29938@@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29939
29940 extract_buf(r, tmp);
29941 i = min_t(int, nbytes, EXTRACT_SIZE);
29942- if (copy_to_user(buf, tmp, i)) {
29943+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29944 ret = -EFAULT;
29945 break;
29946 }
29947@@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29948 #include <linux/sysctl.h>
29949
29950 static int min_read_thresh = 8, min_write_thresh;
29951-static int max_read_thresh = INPUT_POOL_WORDS * 32;
29952+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29953 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29954 static char sysctl_bootid[16];
29955
29956diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29957index 45713f0..8286d21 100644
29958--- a/drivers/char/sonypi.c
29959+++ b/drivers/char/sonypi.c
29960@@ -54,6 +54,7 @@
29961
29962 #include <asm/uaccess.h>
29963 #include <asm/io.h>
29964+#include <asm/local.h>
29965
29966 #include <linux/sonypi.h>
29967
29968@@ -490,7 +491,7 @@ static struct sonypi_device {
29969 spinlock_t fifo_lock;
29970 wait_queue_head_t fifo_proc_list;
29971 struct fasync_struct *fifo_async;
29972- int open_count;
29973+ local_t open_count;
29974 int model;
29975 struct input_dev *input_jog_dev;
29976 struct input_dev *input_key_dev;
29977@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29978 static int sonypi_misc_release(struct inode *inode, struct file *file)
29979 {
29980 mutex_lock(&sonypi_device.lock);
29981- sonypi_device.open_count--;
29982+ local_dec(&sonypi_device.open_count);
29983 mutex_unlock(&sonypi_device.lock);
29984 return 0;
29985 }
29986@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29987 {
29988 mutex_lock(&sonypi_device.lock);
29989 /* Flush input queue on first open */
29990- if (!sonypi_device.open_count)
29991+ if (!local_read(&sonypi_device.open_count))
29992 kfifo_reset(&sonypi_device.fifo);
29993- sonypi_device.open_count++;
29994+ local_inc(&sonypi_device.open_count);
29995 mutex_unlock(&sonypi_device.lock);
29996
29997 return 0;
29998diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29999index 08427ab..1ab10b7 100644
30000--- a/drivers/char/tpm/tpm.c
30001+++ b/drivers/char/tpm/tpm.c
30002@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30003 chip->vendor.req_complete_val)
30004 goto out_recv;
30005
30006- if ((status == chip->vendor.req_canceled)) {
30007+ if (status == chip->vendor.req_canceled) {
30008 dev_err(chip->dev, "Operation Canceled\n");
30009 rc = -ECANCELED;
30010 goto out;
30011diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30012index 0636520..169c1d0 100644
30013--- a/drivers/char/tpm/tpm_bios.c
30014+++ b/drivers/char/tpm/tpm_bios.c
30015@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30016 event = addr;
30017
30018 if ((event->event_type == 0 && event->event_size == 0) ||
30019- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30020+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30021 return NULL;
30022
30023 return addr;
30024@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30025 return NULL;
30026
30027 if ((event->event_type == 0 && event->event_size == 0) ||
30028- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30029+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30030 return NULL;
30031
30032 (*pos)++;
30033@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30034 int i;
30035
30036 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30037- seq_putc(m, data[i]);
30038+ if (!seq_putc(m, data[i]))
30039+ return -EFAULT;
30040
30041 return 0;
30042 }
30043@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30044 log->bios_event_log_end = log->bios_event_log + len;
30045
30046 virt = acpi_os_map_memory(start, len);
30047+ if (!virt) {
30048+ kfree(log->bios_event_log);
30049+ log->bios_event_log = NULL;
30050+ return -EFAULT;
30051+ }
30052
30053- memcpy(log->bios_event_log, virt, len);
30054+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30055
30056 acpi_os_unmap_memory(virt, len);
30057 return 0;
30058diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30059index cdf2f54..e55c197 100644
30060--- a/drivers/char/virtio_console.c
30061+++ b/drivers/char/virtio_console.c
30062@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30063 if (to_user) {
30064 ssize_t ret;
30065
30066- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30067+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30068 if (ret)
30069 return -EFAULT;
30070 } else {
30071@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30072 if (!port_has_data(port) && !port->host_connected)
30073 return 0;
30074
30075- return fill_readbuf(port, ubuf, count, true);
30076+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30077 }
30078
30079 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30080diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30081index 97f5064..202b6e6 100644
30082--- a/drivers/edac/edac_pci_sysfs.c
30083+++ b/drivers/edac/edac_pci_sysfs.c
30084@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30085 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30086 static int edac_pci_poll_msec = 1000; /* one second workq period */
30087
30088-static atomic_t pci_parity_count = ATOMIC_INIT(0);
30089-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30090+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30091+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30092
30093 static struct kobject *edac_pci_top_main_kobj;
30094 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30095@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30096 edac_printk(KERN_CRIT, EDAC_PCI,
30097 "Signaled System Error on %s\n",
30098 pci_name(dev));
30099- atomic_inc(&pci_nonparity_count);
30100+ atomic_inc_unchecked(&pci_nonparity_count);
30101 }
30102
30103 if (status & (PCI_STATUS_PARITY)) {
30104@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30105 "Master Data Parity Error on %s\n",
30106 pci_name(dev));
30107
30108- atomic_inc(&pci_parity_count);
30109+ atomic_inc_unchecked(&pci_parity_count);
30110 }
30111
30112 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30113@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30114 "Detected Parity Error on %s\n",
30115 pci_name(dev));
30116
30117- atomic_inc(&pci_parity_count);
30118+ atomic_inc_unchecked(&pci_parity_count);
30119 }
30120 }
30121
30122@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30123 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30124 "Signaled System Error on %s\n",
30125 pci_name(dev));
30126- atomic_inc(&pci_nonparity_count);
30127+ atomic_inc_unchecked(&pci_nonparity_count);
30128 }
30129
30130 if (status & (PCI_STATUS_PARITY)) {
30131@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30132 "Master Data Parity Error on "
30133 "%s\n", pci_name(dev));
30134
30135- atomic_inc(&pci_parity_count);
30136+ atomic_inc_unchecked(&pci_parity_count);
30137 }
30138
30139 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30140@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30141 "Detected Parity Error on %s\n",
30142 pci_name(dev));
30143
30144- atomic_inc(&pci_parity_count);
30145+ atomic_inc_unchecked(&pci_parity_count);
30146 }
30147 }
30148 }
30149@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
30150 if (!check_pci_errors)
30151 return;
30152
30153- before_count = atomic_read(&pci_parity_count);
30154+ before_count = atomic_read_unchecked(&pci_parity_count);
30155
30156 /* scan all PCI devices looking for a Parity Error on devices and
30157 * bridges.
30158@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
30159 /* Only if operator has selected panic on PCI Error */
30160 if (edac_pci_get_panic_on_pe()) {
30161 /* If the count is different 'after' from 'before' */
30162- if (before_count != atomic_read(&pci_parity_count))
30163+ if (before_count != atomic_read_unchecked(&pci_parity_count))
30164 panic("EDAC: PCI Parity Error");
30165 }
30166 }
30167diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30168index 8c87a5e..a19cbd7 100644
30169--- a/drivers/edac/mce_amd.h
30170+++ b/drivers/edac/mce_amd.h
30171@@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30172 struct amd_decoder_ops {
30173 bool (*dc_mce)(u16, u8);
30174 bool (*ic_mce)(u16, u8);
30175-};
30176+} __no_const;
30177
30178 void amd_report_gart_errors(bool);
30179 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30180diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30181index 57ea7f4..789e3c3 100644
30182--- a/drivers/firewire/core-card.c
30183+++ b/drivers/firewire/core-card.c
30184@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30185
30186 void fw_core_remove_card(struct fw_card *card)
30187 {
30188- struct fw_card_driver dummy_driver = dummy_driver_template;
30189+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
30190
30191 card->driver->update_phy_reg(card, 4,
30192 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30193diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30194index 2783f69..9f4b0cc 100644
30195--- a/drivers/firewire/core-cdev.c
30196+++ b/drivers/firewire/core-cdev.c
30197@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30198 int ret;
30199
30200 if ((request->channels == 0 && request->bandwidth == 0) ||
30201- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30202- request->bandwidth < 0)
30203+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30204 return -EINVAL;
30205
30206 r = kmalloc(sizeof(*r), GFP_KERNEL);
30207diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30208index 780708d..ad60a66 100644
30209--- a/drivers/firewire/core-transaction.c
30210+++ b/drivers/firewire/core-transaction.c
30211@@ -37,6 +37,7 @@
30212 #include <linux/timer.h>
30213 #include <linux/types.h>
30214 #include <linux/workqueue.h>
30215+#include <linux/sched.h>
30216
30217 #include <asm/byteorder.h>
30218
30219diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30220index 515a42c..5ecf3ba 100644
30221--- a/drivers/firewire/core.h
30222+++ b/drivers/firewire/core.h
30223@@ -111,6 +111,7 @@ struct fw_card_driver {
30224
30225 int (*stop_iso)(struct fw_iso_context *ctx);
30226 };
30227+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30228
30229 void fw_card_initialize(struct fw_card *card,
30230 const struct fw_card_driver *driver, struct device *device);
30231diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30232index b298158..7ed8432 100644
30233--- a/drivers/firmware/dmi_scan.c
30234+++ b/drivers/firmware/dmi_scan.c
30235@@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30236 }
30237 }
30238 else {
30239- /*
30240- * no iounmap() for that ioremap(); it would be a no-op, but
30241- * it's so early in setup that sucker gets confused into doing
30242- * what it shouldn't if we actually call it.
30243- */
30244 p = dmi_ioremap(0xF0000, 0x10000);
30245 if (p == NULL)
30246 goto error;
30247@@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30248 if (buf == NULL)
30249 return -1;
30250
30251- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30252+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30253
30254 iounmap(buf);
30255 return 0;
30256diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30257index 82d5c20..44a7177 100644
30258--- a/drivers/gpio/gpio-vr41xx.c
30259+++ b/drivers/gpio/gpio-vr41xx.c
30260@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30261 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30262 maskl, pendl, maskh, pendh);
30263
30264- atomic_inc(&irq_err_count);
30265+ atomic_inc_unchecked(&irq_err_count);
30266
30267 return -EINVAL;
30268 }
30269diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30270index 3252e70..b5314ace 100644
30271--- a/drivers/gpu/drm/drm_crtc_helper.c
30272+++ b/drivers/gpu/drm/drm_crtc_helper.c
30273@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30274 struct drm_crtc *tmp;
30275 int crtc_mask = 1;
30276
30277- WARN(!crtc, "checking null crtc?\n");
30278+ BUG_ON(!crtc);
30279
30280 dev = crtc->dev;
30281
30282diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30283index 8a9d079..606cdd5 100644
30284--- a/drivers/gpu/drm/drm_drv.c
30285+++ b/drivers/gpu/drm/drm_drv.c
30286@@ -318,7 +318,7 @@ module_exit(drm_core_exit);
30287 /**
30288 * Copy and IOCTL return string to user space
30289 */
30290-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30291+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30292 {
30293 int len;
30294
30295@@ -401,7 +401,7 @@ long drm_ioctl(struct file *filp,
30296 return -ENODEV;
30297
30298 atomic_inc(&dev->ioctl_count);
30299- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30300+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30301 ++file_priv->ioctl_count;
30302
30303 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30304diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30305index 123de28..43a0897 100644
30306--- a/drivers/gpu/drm/drm_fops.c
30307+++ b/drivers/gpu/drm/drm_fops.c
30308@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30309 }
30310
30311 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30312- atomic_set(&dev->counts[i], 0);
30313+ atomic_set_unchecked(&dev->counts[i], 0);
30314
30315 dev->sigdata.lock = NULL;
30316
30317@@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30318
30319 retcode = drm_open_helper(inode, filp, dev);
30320 if (!retcode) {
30321- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30322- if (!dev->open_count++)
30323+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30324+ if (local_inc_return(&dev->open_count) == 1)
30325 retcode = drm_setup(dev);
30326 }
30327 if (!retcode) {
30328@@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30329
30330 mutex_lock(&drm_global_mutex);
30331
30332- DRM_DEBUG("open_count = %d\n", dev->open_count);
30333+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30334
30335 if (dev->driver->preclose)
30336 dev->driver->preclose(dev, file_priv);
30337@@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30338 * Begin inline drm_release
30339 */
30340
30341- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30342+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30343 task_pid_nr(current),
30344 (long)old_encode_dev(file_priv->minor->device),
30345- dev->open_count);
30346+ local_read(&dev->open_count));
30347
30348 /* Release any auth tokens that might point to this file_priv,
30349 (do that under the drm_global_mutex) */
30350@@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30351 * End inline drm_release
30352 */
30353
30354- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30355- if (!--dev->open_count) {
30356+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30357+ if (local_dec_and_test(&dev->open_count)) {
30358 if (atomic_read(&dev->ioctl_count)) {
30359 DRM_ERROR("Device busy: %d\n",
30360 atomic_read(&dev->ioctl_count));
30361diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30362index c87dc96..326055d 100644
30363--- a/drivers/gpu/drm/drm_global.c
30364+++ b/drivers/gpu/drm/drm_global.c
30365@@ -36,7 +36,7 @@
30366 struct drm_global_item {
30367 struct mutex mutex;
30368 void *object;
30369- int refcount;
30370+ atomic_t refcount;
30371 };
30372
30373 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30374@@ -49,7 +49,7 @@ void drm_global_init(void)
30375 struct drm_global_item *item = &glob[i];
30376 mutex_init(&item->mutex);
30377 item->object = NULL;
30378- item->refcount = 0;
30379+ atomic_set(&item->refcount, 0);
30380 }
30381 }
30382
30383@@ -59,7 +59,7 @@ void drm_global_release(void)
30384 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30385 struct drm_global_item *item = &glob[i];
30386 BUG_ON(item->object != NULL);
30387- BUG_ON(item->refcount != 0);
30388+ BUG_ON(atomic_read(&item->refcount) != 0);
30389 }
30390 }
30391
30392@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30393 void *object;
30394
30395 mutex_lock(&item->mutex);
30396- if (item->refcount == 0) {
30397+ if (atomic_read(&item->refcount) == 0) {
30398 item->object = kzalloc(ref->size, GFP_KERNEL);
30399 if (unlikely(item->object == NULL)) {
30400 ret = -ENOMEM;
30401@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30402 goto out_err;
30403
30404 }
30405- ++item->refcount;
30406+ atomic_inc(&item->refcount);
30407 ref->object = item->object;
30408 object = item->object;
30409 mutex_unlock(&item->mutex);
30410@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30411 struct drm_global_item *item = &glob[ref->global_type];
30412
30413 mutex_lock(&item->mutex);
30414- BUG_ON(item->refcount == 0);
30415+ BUG_ON(atomic_read(&item->refcount) == 0);
30416 BUG_ON(ref->object != item->object);
30417- if (--item->refcount == 0) {
30418+ if (atomic_dec_and_test(&item->refcount)) {
30419 ref->release(ref);
30420 item->object = NULL;
30421 }
30422diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30423index ab1162d..42587b2 100644
30424--- a/drivers/gpu/drm/drm_info.c
30425+++ b/drivers/gpu/drm/drm_info.c
30426@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30427 struct drm_local_map *map;
30428 struct drm_map_list *r_list;
30429
30430- /* Hardcoded from _DRM_FRAME_BUFFER,
30431- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30432- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30433- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30434+ static const char * const types[] = {
30435+ [_DRM_FRAME_BUFFER] = "FB",
30436+ [_DRM_REGISTERS] = "REG",
30437+ [_DRM_SHM] = "SHM",
30438+ [_DRM_AGP] = "AGP",
30439+ [_DRM_SCATTER_GATHER] = "SG",
30440+ [_DRM_CONSISTENT] = "PCI",
30441+ [_DRM_GEM] = "GEM" };
30442 const char *type;
30443 int i;
30444
30445@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30446 map = r_list->map;
30447 if (!map)
30448 continue;
30449- if (map->type < 0 || map->type > 5)
30450+ if (map->type >= ARRAY_SIZE(types))
30451 type = "??";
30452 else
30453 type = types[map->type];
30454@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30455 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30456 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30457 vma->vm_flags & VM_IO ? 'i' : '-',
30458+#ifdef CONFIG_GRKERNSEC_HIDESYM
30459+ 0);
30460+#else
30461 vma->vm_pgoff);
30462+#endif
30463
30464 #if defined(__i386__)
30465 pgprot = pgprot_val(vma->vm_page_prot);
30466diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30467index 637fcc3..e890b33 100644
30468--- a/drivers/gpu/drm/drm_ioc32.c
30469+++ b/drivers/gpu/drm/drm_ioc32.c
30470@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30471 request = compat_alloc_user_space(nbytes);
30472 if (!access_ok(VERIFY_WRITE, request, nbytes))
30473 return -EFAULT;
30474- list = (struct drm_buf_desc *) (request + 1);
30475+ list = (struct drm_buf_desc __user *) (request + 1);
30476
30477 if (__put_user(count, &request->count)
30478 || __put_user(list, &request->list))
30479@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30480 request = compat_alloc_user_space(nbytes);
30481 if (!access_ok(VERIFY_WRITE, request, nbytes))
30482 return -EFAULT;
30483- list = (struct drm_buf_pub *) (request + 1);
30484+ list = (struct drm_buf_pub __user *) (request + 1);
30485
30486 if (__put_user(count, &request->count)
30487 || __put_user(list, &request->list))
30488diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30489index 64a62c6..ceab35e 100644
30490--- a/drivers/gpu/drm/drm_ioctl.c
30491+++ b/drivers/gpu/drm/drm_ioctl.c
30492@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30493 stats->data[i].value =
30494 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30495 else
30496- stats->data[i].value = atomic_read(&dev->counts[i]);
30497+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30498 stats->data[i].type = dev->types[i];
30499 }
30500
30501diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30502index 5211520..c744d85 100644
30503--- a/drivers/gpu/drm/drm_lock.c
30504+++ b/drivers/gpu/drm/drm_lock.c
30505@@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30506 if (drm_lock_take(&master->lock, lock->context)) {
30507 master->lock.file_priv = file_priv;
30508 master->lock.lock_time = jiffies;
30509- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30510+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30511 break; /* Got lock */
30512 }
30513
30514@@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30515 return -EINVAL;
30516 }
30517
30518- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30519+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30520
30521 if (drm_lock_free(&master->lock, lock->context)) {
30522 /* FIXME: Should really bail out here. */
30523diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30524index 21bcd4a..8e074e0 100644
30525--- a/drivers/gpu/drm/drm_stub.c
30526+++ b/drivers/gpu/drm/drm_stub.c
30527@@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30528
30529 drm_device_set_unplugged(dev);
30530
30531- if (dev->open_count == 0) {
30532+ if (local_read(&dev->open_count) == 0) {
30533 drm_put_dev(dev);
30534 }
30535 mutex_unlock(&drm_global_mutex);
30536diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30537index fa94391..ed26ec8 100644
30538--- a/drivers/gpu/drm/i810/i810_dma.c
30539+++ b/drivers/gpu/drm/i810/i810_dma.c
30540@@ -943,8 +943,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30541 dma->buflist[vertex->idx],
30542 vertex->discard, vertex->used);
30543
30544- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30545- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30546+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30547+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30548 sarea_priv->last_enqueue = dev_priv->counter - 1;
30549 sarea_priv->last_dispatch = (int)hw_status[5];
30550
30551@@ -1104,8 +1104,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30552 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30553 mc->last_render);
30554
30555- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30556- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30557+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30558+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30559 sarea_priv->last_enqueue = dev_priv->counter - 1;
30560 sarea_priv->last_dispatch = (int)hw_status[5];
30561
30562diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30563index c9339f4..f5e1b9d 100644
30564--- a/drivers/gpu/drm/i810/i810_drv.h
30565+++ b/drivers/gpu/drm/i810/i810_drv.h
30566@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30567 int page_flipping;
30568
30569 wait_queue_head_t irq_queue;
30570- atomic_t irq_received;
30571- atomic_t irq_emitted;
30572+ atomic_unchecked_t irq_received;
30573+ atomic_unchecked_t irq_emitted;
30574
30575 int front_offset;
30576 } drm_i810_private_t;
30577diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30578index 5363e9c..59360d1 100644
30579--- a/drivers/gpu/drm/i915/i915_debugfs.c
30580+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30581@@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30582 I915_READ(GTIMR));
30583 }
30584 seq_printf(m, "Interrupts received: %d\n",
30585- atomic_read(&dev_priv->irq_received));
30586+ atomic_read_unchecked(&dev_priv->irq_received));
30587 for (i = 0; i < I915_NUM_RINGS; i++) {
30588 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30589 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30590diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30591index 36822b9..b725e1b 100644
30592--- a/drivers/gpu/drm/i915/i915_dma.c
30593+++ b/drivers/gpu/drm/i915/i915_dma.c
30594@@ -1266,7 +1266,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30595 bool can_switch;
30596
30597 spin_lock(&dev->count_lock);
30598- can_switch = (dev->open_count == 0);
30599+ can_switch = (local_read(&dev->open_count) == 0);
30600 spin_unlock(&dev->count_lock);
30601 return can_switch;
30602 }
30603diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30604index b0b676a..d107105 100644
30605--- a/drivers/gpu/drm/i915/i915_drv.h
30606+++ b/drivers/gpu/drm/i915/i915_drv.h
30607@@ -268,7 +268,7 @@ struct drm_i915_display_funcs {
30608 /* render clock increase/decrease */
30609 /* display clock increase/decrease */
30610 /* pll clock increase/decrease */
30611-};
30612+} __no_const;
30613
30614 struct intel_device_info {
30615 u8 gen;
30616@@ -386,7 +386,7 @@ typedef struct drm_i915_private {
30617 int current_page;
30618 int page_flipping;
30619
30620- atomic_t irq_received;
30621+ atomic_unchecked_t irq_received;
30622
30623 /* protects the irq masks */
30624 spinlock_t irq_lock;
30625@@ -985,7 +985,7 @@ struct drm_i915_gem_object {
30626 * will be page flipped away on the next vblank. When it
30627 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30628 */
30629- atomic_t pending_flip;
30630+ atomic_unchecked_t pending_flip;
30631 };
30632
30633 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30634@@ -1434,7 +1434,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30635 struct drm_i915_private *dev_priv, unsigned port);
30636 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30637 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30638-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30639+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30640 {
30641 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30642 }
30643diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30644index 974a9f1..b3ebd45 100644
30645--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30646+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30647@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30648 i915_gem_clflush_object(obj);
30649
30650 if (obj->base.pending_write_domain)
30651- cd->flips |= atomic_read(&obj->pending_flip);
30652+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30653
30654 /* The actual obj->write_domain will be updated with
30655 * pending_write_domain after we emit the accumulated flush for all
30656@@ -916,9 +916,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30657
30658 static int
30659 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30660- int count)
30661+ unsigned int count)
30662 {
30663- int i;
30664+ unsigned int i;
30665
30666 for (i = 0; i < count; i++) {
30667 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30668diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30669index acc91b1..f383084 100644
30670--- a/drivers/gpu/drm/i915/i915_irq.c
30671+++ b/drivers/gpu/drm/i915/i915_irq.c
30672@@ -433,7 +433,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30673 int vblank = 0;
30674 bool blc_event;
30675
30676- atomic_inc(&dev_priv->irq_received);
30677+ atomic_inc_unchecked(&dev_priv->irq_received);
30678
30679 vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS |
30680 PIPE_VBLANK_INTERRUPT_STATUS;
30681@@ -586,7 +586,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30682 irqreturn_t ret = IRQ_NONE;
30683 int i;
30684
30685- atomic_inc(&dev_priv->irq_received);
30686+ atomic_inc_unchecked(&dev_priv->irq_received);
30687
30688 /* disable master interrupt before clearing iir */
30689 de_ier = I915_READ(DEIER);
30690@@ -661,7 +661,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30691 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30692 u32 hotplug_mask;
30693
30694- atomic_inc(&dev_priv->irq_received);
30695+ atomic_inc_unchecked(&dev_priv->irq_received);
30696
30697 /* disable master interrupt before clearing iir */
30698 de_ier = I915_READ(DEIER);
30699@@ -1646,7 +1646,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30700 {
30701 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30702
30703- atomic_set(&dev_priv->irq_received, 0);
30704+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30705
30706
30707 I915_WRITE(HWSTAM, 0xeffe);
30708@@ -1673,7 +1673,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30709 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30710 int pipe;
30711
30712- atomic_set(&dev_priv->irq_received, 0);
30713+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30714
30715 /* VLV magic */
30716 I915_WRITE(VLV_IMR, 0);
30717@@ -1969,7 +1969,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30718 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30719 int pipe;
30720
30721- atomic_set(&dev_priv->irq_received, 0);
30722+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30723
30724 for_each_pipe(pipe)
30725 I915_WRITE(PIPESTAT(pipe), 0);
30726@@ -2020,7 +2020,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30727 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30728 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30729
30730- atomic_inc(&dev_priv->irq_received);
30731+ atomic_inc_unchecked(&dev_priv->irq_received);
30732
30733 iir = I915_READ16(IIR);
30734 if (iir == 0)
30735@@ -2105,7 +2105,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30736 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30737 int pipe;
30738
30739- atomic_set(&dev_priv->irq_received, 0);
30740+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30741
30742 if (I915_HAS_HOTPLUG(dev)) {
30743 I915_WRITE(PORT_HOTPLUG_EN, 0);
30744@@ -2200,7 +2200,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30745 };
30746 int pipe, ret = IRQ_NONE;
30747
30748- atomic_inc(&dev_priv->irq_received);
30749+ atomic_inc_unchecked(&dev_priv->irq_received);
30750
30751 iir = I915_READ(IIR);
30752 do {
30753@@ -2326,7 +2326,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30754 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30755 int pipe;
30756
30757- atomic_set(&dev_priv->irq_received, 0);
30758+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30759
30760 if (I915_HAS_HOTPLUG(dev)) {
30761 I915_WRITE(PORT_HOTPLUG_EN, 0);
30762@@ -2436,7 +2436,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30763 int irq_received;
30764 int ret = IRQ_NONE, pipe;
30765
30766- atomic_inc(&dev_priv->irq_received);
30767+ atomic_inc_unchecked(&dev_priv->irq_received);
30768
30769 iir = I915_READ(IIR);
30770
30771diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30772index 2f22bea..bc9e330 100644
30773--- a/drivers/gpu/drm/i915/intel_display.c
30774+++ b/drivers/gpu/drm/i915/intel_display.c
30775@@ -2000,7 +2000,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30776
30777 wait_event(dev_priv->pending_flip_queue,
30778 atomic_read(&dev_priv->mm.wedged) ||
30779- atomic_read(&obj->pending_flip) == 0);
30780+ atomic_read_unchecked(&obj->pending_flip) == 0);
30781
30782 /* Big Hammer, we also need to ensure that any pending
30783 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30784@@ -5914,9 +5914,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30785
30786 obj = work->old_fb_obj;
30787
30788- atomic_clear_mask(1 << intel_crtc->plane,
30789- &obj->pending_flip.counter);
30790- if (atomic_read(&obj->pending_flip) == 0)
30791+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30792+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
30793 wake_up(&dev_priv->pending_flip_queue);
30794
30795 schedule_work(&work->work);
30796@@ -6253,7 +6252,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30797 /* Block clients from rendering to the new back buffer until
30798 * the flip occurs and the object is no longer visible.
30799 */
30800- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30801+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30802
30803 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30804 if (ret)
30805@@ -6268,7 +6267,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30806 return 0;
30807
30808 cleanup_pending:
30809- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30810+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30811 drm_gem_object_unreference(&work->old_fb_obj->base);
30812 drm_gem_object_unreference(&obj->base);
30813 mutex_unlock(&dev->struct_mutex);
30814diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30815index 54558a0..2d97005 100644
30816--- a/drivers/gpu/drm/mga/mga_drv.h
30817+++ b/drivers/gpu/drm/mga/mga_drv.h
30818@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30819 u32 clear_cmd;
30820 u32 maccess;
30821
30822- atomic_t vbl_received; /**< Number of vblanks received. */
30823+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30824 wait_queue_head_t fence_queue;
30825- atomic_t last_fence_retired;
30826+ atomic_unchecked_t last_fence_retired;
30827 u32 next_fence_to_post;
30828
30829 unsigned int fb_cpp;
30830diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30831index 2581202..f230a8d9 100644
30832--- a/drivers/gpu/drm/mga/mga_irq.c
30833+++ b/drivers/gpu/drm/mga/mga_irq.c
30834@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30835 if (crtc != 0)
30836 return 0;
30837
30838- return atomic_read(&dev_priv->vbl_received);
30839+ return atomic_read_unchecked(&dev_priv->vbl_received);
30840 }
30841
30842
30843@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30844 /* VBLANK interrupt */
30845 if (status & MGA_VLINEPEN) {
30846 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30847- atomic_inc(&dev_priv->vbl_received);
30848+ atomic_inc_unchecked(&dev_priv->vbl_received);
30849 drm_handle_vblank(dev, 0);
30850 handled = 1;
30851 }
30852@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30853 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30854 MGA_WRITE(MGA_PRIMEND, prim_end);
30855
30856- atomic_inc(&dev_priv->last_fence_retired);
30857+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
30858 DRM_WAKEUP(&dev_priv->fence_queue);
30859 handled = 1;
30860 }
30861@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30862 * using fences.
30863 */
30864 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30865- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30866+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30867 - *sequence) <= (1 << 23)));
30868
30869 *sequence = cur_fence;
30870diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30871index 2f11e16..191267e 100644
30872--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30873+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30874@@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30875 struct bit_table {
30876 const char id;
30877 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30878-};
30879+} __no_const;
30880
30881 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30882
30883diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30884index b863a3a..c55e0dc 100644
30885--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30886+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30887@@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30888 u32 handle, u16 class);
30889 void (*set_tile_region)(struct drm_device *dev, int i);
30890 void (*tlb_flush)(struct drm_device *, int engine);
30891-};
30892+} __no_const;
30893
30894 struct nouveau_instmem_engine {
30895 void *priv;
30896@@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30897 struct nouveau_mc_engine {
30898 int (*init)(struct drm_device *dev);
30899 void (*takedown)(struct drm_device *dev);
30900-};
30901+} __no_const;
30902
30903 struct nouveau_timer_engine {
30904 int (*init)(struct drm_device *dev);
30905 void (*takedown)(struct drm_device *dev);
30906 uint64_t (*read)(struct drm_device *dev);
30907-};
30908+} __no_const;
30909
30910 struct nouveau_fb_engine {
30911 int num_tiles;
30912@@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30913 void (*put)(struct drm_device *, struct nouveau_mem **);
30914
30915 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30916-};
30917+} __no_const;
30918
30919 struct nouveau_engine {
30920 struct nouveau_instmem_engine instmem;
30921@@ -693,7 +693,7 @@ struct drm_nouveau_private {
30922 struct drm_global_reference mem_global_ref;
30923 struct ttm_bo_global_ref bo_global_ref;
30924 struct ttm_bo_device bdev;
30925- atomic_t validate_sequence;
30926+ atomic_unchecked_t validate_sequence;
30927 int (*move)(struct nouveau_channel *,
30928 struct ttm_buffer_object *,
30929 struct ttm_mem_reg *, struct ttm_mem_reg *);
30930diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30931index 30f5423..abca136 100644
30932--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30933+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30934@@ -319,7 +319,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30935 int trycnt = 0;
30936 int ret, i;
30937
30938- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30939+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30940 retry:
30941 if (++trycnt > 100000) {
30942 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30943diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30944index 22a90a0..8ccea014 100644
30945--- a/drivers/gpu/drm/nouveau/nouveau_state.c
30946+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30947@@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30948 bool can_switch;
30949
30950 spin_lock(&dev->count_lock);
30951- can_switch = (dev->open_count == 0);
30952+ can_switch = (local_read(&dev->open_count) == 0);
30953 spin_unlock(&dev->count_lock);
30954 return can_switch;
30955 }
30956diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30957index a9514ea..369d511 100644
30958--- a/drivers/gpu/drm/nouveau/nv50_sor.c
30959+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30960@@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30961 }
30962
30963 if (nv_encoder->dcb->type == OUTPUT_DP) {
30964- struct dp_train_func func = {
30965+ static struct dp_train_func func = {
30966 .link_set = nv50_sor_dp_link_set,
30967 .train_set = nv50_sor_dp_train_set,
30968 .train_adj = nv50_sor_dp_train_adj
30969diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30970index c50b075..6b07dfc 100644
30971--- a/drivers/gpu/drm/nouveau/nvd0_display.c
30972+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30973@@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30974 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30975
30976 if (nv_encoder->dcb->type == OUTPUT_DP) {
30977- struct dp_train_func func = {
30978+ static struct dp_train_func func = {
30979 .link_set = nvd0_sor_dp_link_set,
30980 .train_set = nvd0_sor_dp_train_set,
30981 .train_adj = nvd0_sor_dp_train_adj
30982diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30983index bcac90b..53bfc76 100644
30984--- a/drivers/gpu/drm/r128/r128_cce.c
30985+++ b/drivers/gpu/drm/r128/r128_cce.c
30986@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30987
30988 /* GH: Simple idle check.
30989 */
30990- atomic_set(&dev_priv->idle_count, 0);
30991+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30992
30993 /* We don't support anything other than bus-mastering ring mode,
30994 * but the ring can be in either AGP or PCI space for the ring
30995diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30996index 930c71b..499aded 100644
30997--- a/drivers/gpu/drm/r128/r128_drv.h
30998+++ b/drivers/gpu/drm/r128/r128_drv.h
30999@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31000 int is_pci;
31001 unsigned long cce_buffers_offset;
31002
31003- atomic_t idle_count;
31004+ atomic_unchecked_t idle_count;
31005
31006 int page_flipping;
31007 int current_page;
31008 u32 crtc_offset;
31009 u32 crtc_offset_cntl;
31010
31011- atomic_t vbl_received;
31012+ atomic_unchecked_t vbl_received;
31013
31014 u32 color_fmt;
31015 unsigned int front_offset;
31016diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31017index 429d5a0..7e899ed 100644
31018--- a/drivers/gpu/drm/r128/r128_irq.c
31019+++ b/drivers/gpu/drm/r128/r128_irq.c
31020@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31021 if (crtc != 0)
31022 return 0;
31023
31024- return atomic_read(&dev_priv->vbl_received);
31025+ return atomic_read_unchecked(&dev_priv->vbl_received);
31026 }
31027
31028 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31029@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31030 /* VBLANK interrupt */
31031 if (status & R128_CRTC_VBLANK_INT) {
31032 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31033- atomic_inc(&dev_priv->vbl_received);
31034+ atomic_inc_unchecked(&dev_priv->vbl_received);
31035 drm_handle_vblank(dev, 0);
31036 return IRQ_HANDLED;
31037 }
31038diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31039index a9e33ce..09edd4b 100644
31040--- a/drivers/gpu/drm/r128/r128_state.c
31041+++ b/drivers/gpu/drm/r128/r128_state.c
31042@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31043
31044 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31045 {
31046- if (atomic_read(&dev_priv->idle_count) == 0)
31047+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31048 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31049 else
31050- atomic_set(&dev_priv->idle_count, 0);
31051+ atomic_set_unchecked(&dev_priv->idle_count, 0);
31052 }
31053
31054 #endif
31055diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31056index 5a82b6b..9e69c73 100644
31057--- a/drivers/gpu/drm/radeon/mkregtable.c
31058+++ b/drivers/gpu/drm/radeon/mkregtable.c
31059@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31060 regex_t mask_rex;
31061 regmatch_t match[4];
31062 char buf[1024];
31063- size_t end;
31064+ long end;
31065 int len;
31066 int done = 0;
31067 int r;
31068 unsigned o;
31069 struct offset *offset;
31070 char last_reg_s[10];
31071- int last_reg;
31072+ unsigned long last_reg;
31073
31074 if (regcomp
31075 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31076diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31077index 5c8a0bf..b7a311c 100644
31078--- a/drivers/gpu/drm/radeon/radeon.h
31079+++ b/drivers/gpu/drm/radeon/radeon.h
31080@@ -729,7 +729,7 @@ struct r600_blit_cp_primitives {
31081 int x2, int y2);
31082 void (*draw_auto)(struct radeon_device *rdev);
31083 void (*set_default_state)(struct radeon_device *rdev);
31084-};
31085+} __no_const;
31086
31087 struct r600_blit {
31088 struct radeon_bo *shader_obj;
31089@@ -1230,7 +1230,7 @@ struct radeon_asic {
31090 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31091 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31092 } pflip;
31093-};
31094+} __no_const;
31095
31096 /*
31097 * Asic structures
31098diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31099index 8867400..72761bc 100644
31100--- a/drivers/gpu/drm/radeon/radeon_device.c
31101+++ b/drivers/gpu/drm/radeon/radeon_device.c
31102@@ -692,7 +692,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31103 bool can_switch;
31104
31105 spin_lock(&dev->count_lock);
31106- can_switch = (dev->open_count == 0);
31107+ can_switch = (local_read(&dev->open_count) == 0);
31108 spin_unlock(&dev->count_lock);
31109 return can_switch;
31110 }
31111diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31112index a1b59ca..86f2d44 100644
31113--- a/drivers/gpu/drm/radeon/radeon_drv.h
31114+++ b/drivers/gpu/drm/radeon/radeon_drv.h
31115@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31116
31117 /* SW interrupt */
31118 wait_queue_head_t swi_queue;
31119- atomic_t swi_emitted;
31120+ atomic_unchecked_t swi_emitted;
31121 int vblank_crtc;
31122 uint32_t irq_enable_reg;
31123 uint32_t r500_disp_irq_reg;
31124diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31125index 48b7cea..342236f 100644
31126--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31127+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31128@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31129 request = compat_alloc_user_space(sizeof(*request));
31130 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31131 || __put_user(req32.param, &request->param)
31132- || __put_user((void __user *)(unsigned long)req32.value,
31133+ || __put_user((unsigned long)req32.value,
31134 &request->value))
31135 return -EFAULT;
31136
31137diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31138index 00da384..32f972d 100644
31139--- a/drivers/gpu/drm/radeon/radeon_irq.c
31140+++ b/drivers/gpu/drm/radeon/radeon_irq.c
31141@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31142 unsigned int ret;
31143 RING_LOCALS;
31144
31145- atomic_inc(&dev_priv->swi_emitted);
31146- ret = atomic_read(&dev_priv->swi_emitted);
31147+ atomic_inc_unchecked(&dev_priv->swi_emitted);
31148+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31149
31150 BEGIN_RING(4);
31151 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31152@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31153 drm_radeon_private_t *dev_priv =
31154 (drm_radeon_private_t *) dev->dev_private;
31155
31156- atomic_set(&dev_priv->swi_emitted, 0);
31157+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31158 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31159
31160 dev->max_vblank_count = 0x001fffff;
31161diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31162index e8422ae..d22d4a8 100644
31163--- a/drivers/gpu/drm/radeon/radeon_state.c
31164+++ b/drivers/gpu/drm/radeon/radeon_state.c
31165@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31166 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31167 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31168
31169- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31170+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31171 sarea_priv->nbox * sizeof(depth_boxes[0])))
31172 return -EFAULT;
31173
31174@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31175 {
31176 drm_radeon_private_t *dev_priv = dev->dev_private;
31177 drm_radeon_getparam_t *param = data;
31178- int value;
31179+ int value = 0;
31180
31181 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31182
31183diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31184index c94a225..5795d34 100644
31185--- a/drivers/gpu/drm/radeon/radeon_ttm.c
31186+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31187@@ -852,8 +852,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31188 }
31189 if (unlikely(ttm_vm_ops == NULL)) {
31190 ttm_vm_ops = vma->vm_ops;
31191- radeon_ttm_vm_ops = *ttm_vm_ops;
31192- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31193+ pax_open_kernel();
31194+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31195+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31196+ pax_close_kernel();
31197 }
31198 vma->vm_ops = &radeon_ttm_vm_ops;
31199 return 0;
31200diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31201index 159b6a4..fa82487 100644
31202--- a/drivers/gpu/drm/radeon/rs690.c
31203+++ b/drivers/gpu/drm/radeon/rs690.c
31204@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31205 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31206 rdev->pm.sideport_bandwidth.full)
31207 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31208- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31209+ read_delay_latency.full = dfixed_const(800 * 1000);
31210 read_delay_latency.full = dfixed_div(read_delay_latency,
31211 rdev->pm.igp_sideport_mclk);
31212+ a.full = dfixed_const(370);
31213+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31214 } else {
31215 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31216 rdev->pm.k8_bandwidth.full)
31217diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31218index ebc6fac..a8313ed 100644
31219--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31220+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31221@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31222 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31223 struct shrink_control *sc)
31224 {
31225- static atomic_t start_pool = ATOMIC_INIT(0);
31226+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31227 unsigned i;
31228- unsigned pool_offset = atomic_add_return(1, &start_pool);
31229+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31230 struct ttm_page_pool *pool;
31231 int shrink_pages = sc->nr_to_scan;
31232
31233diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31234index 88edacc..1e5412b 100644
31235--- a/drivers/gpu/drm/via/via_drv.h
31236+++ b/drivers/gpu/drm/via/via_drv.h
31237@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31238 typedef uint32_t maskarray_t[5];
31239
31240 typedef struct drm_via_irq {
31241- atomic_t irq_received;
31242+ atomic_unchecked_t irq_received;
31243 uint32_t pending_mask;
31244 uint32_t enable_mask;
31245 wait_queue_head_t irq_queue;
31246@@ -75,7 +75,7 @@ typedef struct drm_via_private {
31247 struct timeval last_vblank;
31248 int last_vblank_valid;
31249 unsigned usec_per_vblank;
31250- atomic_t vbl_received;
31251+ atomic_unchecked_t vbl_received;
31252 drm_via_state_t hc_state;
31253 char pci_buf[VIA_PCI_BUF_SIZE];
31254 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31255diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31256index d391f48..10c8ca3 100644
31257--- a/drivers/gpu/drm/via/via_irq.c
31258+++ b/drivers/gpu/drm/via/via_irq.c
31259@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31260 if (crtc != 0)
31261 return 0;
31262
31263- return atomic_read(&dev_priv->vbl_received);
31264+ return atomic_read_unchecked(&dev_priv->vbl_received);
31265 }
31266
31267 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31268@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31269
31270 status = VIA_READ(VIA_REG_INTERRUPT);
31271 if (status & VIA_IRQ_VBLANK_PENDING) {
31272- atomic_inc(&dev_priv->vbl_received);
31273- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31274+ atomic_inc_unchecked(&dev_priv->vbl_received);
31275+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31276 do_gettimeofday(&cur_vblank);
31277 if (dev_priv->last_vblank_valid) {
31278 dev_priv->usec_per_vblank =
31279@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31280 dev_priv->last_vblank = cur_vblank;
31281 dev_priv->last_vblank_valid = 1;
31282 }
31283- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31284+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31285 DRM_DEBUG("US per vblank is: %u\n",
31286 dev_priv->usec_per_vblank);
31287 }
31288@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31289
31290 for (i = 0; i < dev_priv->num_irqs; ++i) {
31291 if (status & cur_irq->pending_mask) {
31292- atomic_inc(&cur_irq->irq_received);
31293+ atomic_inc_unchecked(&cur_irq->irq_received);
31294 DRM_WAKEUP(&cur_irq->irq_queue);
31295 handled = 1;
31296 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31297@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31298 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31299 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31300 masks[irq][4]));
31301- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31302+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31303 } else {
31304 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31305 (((cur_irq_sequence =
31306- atomic_read(&cur_irq->irq_received)) -
31307+ atomic_read_unchecked(&cur_irq->irq_received)) -
31308 *sequence) <= (1 << 23)));
31309 }
31310 *sequence = cur_irq_sequence;
31311@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31312 }
31313
31314 for (i = 0; i < dev_priv->num_irqs; ++i) {
31315- atomic_set(&cur_irq->irq_received, 0);
31316+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31317 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31318 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31319 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31320@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31321 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31322 case VIA_IRQ_RELATIVE:
31323 irqwait->request.sequence +=
31324- atomic_read(&cur_irq->irq_received);
31325+ atomic_read_unchecked(&cur_irq->irq_received);
31326 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31327 case VIA_IRQ_ABSOLUTE:
31328 break;
31329diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31330index 29c984f..4084f1a 100644
31331--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31332+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31333@@ -263,7 +263,7 @@ struct vmw_private {
31334 * Fencing and IRQs.
31335 */
31336
31337- atomic_t marker_seq;
31338+ atomic_unchecked_t marker_seq;
31339 wait_queue_head_t fence_queue;
31340 wait_queue_head_t fifo_queue;
31341 int fence_queue_waiters; /* Protected by hw_mutex */
31342diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31343index a0c2f12..68ae6cb 100644
31344--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31345+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31346@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31347 (unsigned int) min,
31348 (unsigned int) fifo->capabilities);
31349
31350- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31351+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31352 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31353 vmw_marker_queue_init(&fifo->marker_queue);
31354 return vmw_fifo_send_fence(dev_priv, &dummy);
31355@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31356 if (reserveable)
31357 iowrite32(bytes, fifo_mem +
31358 SVGA_FIFO_RESERVED);
31359- return fifo_mem + (next_cmd >> 2);
31360+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31361 } else {
31362 need_bounce = true;
31363 }
31364@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31365
31366 fm = vmw_fifo_reserve(dev_priv, bytes);
31367 if (unlikely(fm == NULL)) {
31368- *seqno = atomic_read(&dev_priv->marker_seq);
31369+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31370 ret = -ENOMEM;
31371 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31372 false, 3*HZ);
31373@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31374 }
31375
31376 do {
31377- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31378+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31379 } while (*seqno == 0);
31380
31381 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31382diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31383index cabc95f..14b3d77 100644
31384--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31385+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31386@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31387 * emitted. Then the fence is stale and signaled.
31388 */
31389
31390- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31391+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31392 > VMW_FENCE_WRAP);
31393
31394 return ret;
31395@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31396
31397 if (fifo_idle)
31398 down_read(&fifo_state->rwsem);
31399- signal_seq = atomic_read(&dev_priv->marker_seq);
31400+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31401 ret = 0;
31402
31403 for (;;) {
31404diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31405index 8a8725c..afed796 100644
31406--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31407+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31408@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31409 while (!vmw_lag_lt(queue, us)) {
31410 spin_lock(&queue->lock);
31411 if (list_empty(&queue->head))
31412- seqno = atomic_read(&dev_priv->marker_seq);
31413+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31414 else {
31415 marker = list_first_entry(&queue->head,
31416 struct vmw_marker, head);
31417diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31418index 0e4d41e..dfd88b4 100644
31419--- a/drivers/hid/hid-core.c
31420+++ b/drivers/hid/hid-core.c
31421@@ -2163,7 +2163,7 @@ static bool hid_ignore(struct hid_device *hdev)
31422
31423 int hid_add_device(struct hid_device *hdev)
31424 {
31425- static atomic_t id = ATOMIC_INIT(0);
31426+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31427 int ret;
31428
31429 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31430@@ -2198,7 +2198,7 @@ int hid_add_device(struct hid_device *hdev)
31431 /* XXX hack, any other cleaner solution after the driver core
31432 * is converted to allow more than 20 bytes as the device name? */
31433 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31434- hdev->vendor, hdev->product, atomic_inc_return(&id));
31435+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31436
31437 hid_debug_register(hdev, dev_name(&hdev->dev));
31438 ret = device_add(&hdev->dev);
31439diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31440index eec3291..8ed706b 100644
31441--- a/drivers/hid/hid-wiimote-debug.c
31442+++ b/drivers/hid/hid-wiimote-debug.c
31443@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31444 else if (size == 0)
31445 return -EIO;
31446
31447- if (copy_to_user(u, buf, size))
31448+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
31449 return -EFAULT;
31450
31451 *off += size;
31452diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31453index 14599e2..711c965 100644
31454--- a/drivers/hid/usbhid/hiddev.c
31455+++ b/drivers/hid/usbhid/hiddev.c
31456@@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31457 break;
31458
31459 case HIDIOCAPPLICATION:
31460- if (arg < 0 || arg >= hid->maxapplication)
31461+ if (arg >= hid->maxapplication)
31462 break;
31463
31464 for (i = 0; i < hid->maxcollection; i++)
31465diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31466index 4065374..10ed7dc 100644
31467--- a/drivers/hv/channel.c
31468+++ b/drivers/hv/channel.c
31469@@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31470 int ret = 0;
31471 int t;
31472
31473- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31474- atomic_inc(&vmbus_connection.next_gpadl_handle);
31475+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31476+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31477
31478 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31479 if (ret)
31480diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31481index 86f8885..ab9cb2b 100644
31482--- a/drivers/hv/hv.c
31483+++ b/drivers/hv/hv.c
31484@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31485 u64 output_address = (output) ? virt_to_phys(output) : 0;
31486 u32 output_address_hi = output_address >> 32;
31487 u32 output_address_lo = output_address & 0xFFFFFFFF;
31488- void *hypercall_page = hv_context.hypercall_page;
31489+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31490
31491 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31492 "=a"(hv_status_lo) : "d" (control_hi),
31493diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31494index b9426a6..677ce34 100644
31495--- a/drivers/hv/hyperv_vmbus.h
31496+++ b/drivers/hv/hyperv_vmbus.h
31497@@ -555,7 +555,7 @@ enum vmbus_connect_state {
31498 struct vmbus_connection {
31499 enum vmbus_connect_state conn_state;
31500
31501- atomic_t next_gpadl_handle;
31502+ atomic_unchecked_t next_gpadl_handle;
31503
31504 /*
31505 * Represents channel interrupts. Each bit position represents a
31506diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31507index a220e57..428f54d 100644
31508--- a/drivers/hv/vmbus_drv.c
31509+++ b/drivers/hv/vmbus_drv.c
31510@@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31511 {
31512 int ret = 0;
31513
31514- static atomic_t device_num = ATOMIC_INIT(0);
31515+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31516
31517 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31518- atomic_inc_return(&device_num));
31519+ atomic_inc_return_unchecked(&device_num));
31520
31521 child_device_obj->device.bus = &hv_bus;
31522 child_device_obj->device.parent = &hv_acpi_dev->dev;
31523diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31524index 34ad5a2..e2b0ae8 100644
31525--- a/drivers/hwmon/acpi_power_meter.c
31526+++ b/drivers/hwmon/acpi_power_meter.c
31527@@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31528 return res;
31529
31530 temp /= 1000;
31531- if (temp < 0)
31532- return -EINVAL;
31533
31534 mutex_lock(&resource->lock);
31535 resource->trip[attr->index - 7] = temp;
31536diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31537index 8b011d0..3de24a1 100644
31538--- a/drivers/hwmon/sht15.c
31539+++ b/drivers/hwmon/sht15.c
31540@@ -166,7 +166,7 @@ struct sht15_data {
31541 int supply_uV;
31542 bool supply_uV_valid;
31543 struct work_struct update_supply_work;
31544- atomic_t interrupt_handled;
31545+ atomic_unchecked_t interrupt_handled;
31546 };
31547
31548 /**
31549@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31550 return ret;
31551
31552 gpio_direction_input(data->pdata->gpio_data);
31553- atomic_set(&data->interrupt_handled, 0);
31554+ atomic_set_unchecked(&data->interrupt_handled, 0);
31555
31556 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31557 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31558 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31559 /* Only relevant if the interrupt hasn't occurred. */
31560- if (!atomic_read(&data->interrupt_handled))
31561+ if (!atomic_read_unchecked(&data->interrupt_handled))
31562 schedule_work(&data->read_work);
31563 }
31564 ret = wait_event_timeout(data->wait_queue,
31565@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31566
31567 /* First disable the interrupt */
31568 disable_irq_nosync(irq);
31569- atomic_inc(&data->interrupt_handled);
31570+ atomic_inc_unchecked(&data->interrupt_handled);
31571 /* Then schedule a reading work struct */
31572 if (data->state != SHT15_READING_NOTHING)
31573 schedule_work(&data->read_work);
31574@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31575 * If not, then start the interrupt again - care here as could
31576 * have gone low in meantime so verify it hasn't!
31577 */
31578- atomic_set(&data->interrupt_handled, 0);
31579+ atomic_set_unchecked(&data->interrupt_handled, 0);
31580 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31581 /* If still not occurred or another handler was scheduled */
31582 if (gpio_get_value(data->pdata->gpio_data)
31583- || atomic_read(&data->interrupt_handled))
31584+ || atomic_read_unchecked(&data->interrupt_handled))
31585 return;
31586 }
31587
31588diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31589index 378fcb5..5e91fa8 100644
31590--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31591+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31592@@ -43,7 +43,7 @@
31593 extern struct i2c_adapter amd756_smbus;
31594
31595 static struct i2c_adapter *s4882_adapter;
31596-static struct i2c_algorithm *s4882_algo;
31597+static i2c_algorithm_no_const *s4882_algo;
31598
31599 /* Wrapper access functions for multiplexed SMBus */
31600 static DEFINE_MUTEX(amd756_lock);
31601diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31602index 29015eb..af2d8e9 100644
31603--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31604+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31605@@ -41,7 +41,7 @@
31606 extern struct i2c_adapter *nforce2_smbus;
31607
31608 static struct i2c_adapter *s4985_adapter;
31609-static struct i2c_algorithm *s4985_algo;
31610+static i2c_algorithm_no_const *s4985_algo;
31611
31612 /* Wrapper access functions for multiplexed SMBus */
31613 static DEFINE_MUTEX(nforce2_lock);
31614diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31615index 1038c38..eb92f51 100644
31616--- a/drivers/i2c/i2c-mux.c
31617+++ b/drivers/i2c/i2c-mux.c
31618@@ -30,7 +30,7 @@
31619 /* multiplexer per channel data */
31620 struct i2c_mux_priv {
31621 struct i2c_adapter adap;
31622- struct i2c_algorithm algo;
31623+ i2c_algorithm_no_const algo;
31624
31625 struct i2c_adapter *parent;
31626 void *mux_priv; /* the mux chip/device */
31627diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31628index 57d00ca..0145194 100644
31629--- a/drivers/ide/aec62xx.c
31630+++ b/drivers/ide/aec62xx.c
31631@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31632 .cable_detect = atp86x_cable_detect,
31633 };
31634
31635-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31636+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31637 { /* 0: AEC6210 */
31638 .name = DRV_NAME,
31639 .init_chipset = init_chipset_aec62xx,
31640diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31641index 2c8016a..911a27c 100644
31642--- a/drivers/ide/alim15x3.c
31643+++ b/drivers/ide/alim15x3.c
31644@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31645 .dma_sff_read_status = ide_dma_sff_read_status,
31646 };
31647
31648-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31649+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31650 .name = DRV_NAME,
31651 .init_chipset = init_chipset_ali15x3,
31652 .init_hwif = init_hwif_ali15x3,
31653diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31654index 3747b25..56fc995 100644
31655--- a/drivers/ide/amd74xx.c
31656+++ b/drivers/ide/amd74xx.c
31657@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31658 .udma_mask = udma, \
31659 }
31660
31661-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31662+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31663 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31664 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31665 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31666diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31667index 15f0ead..cb43480 100644
31668--- a/drivers/ide/atiixp.c
31669+++ b/drivers/ide/atiixp.c
31670@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31671 .cable_detect = atiixp_cable_detect,
31672 };
31673
31674-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31675+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31676 { /* 0: IXP200/300/400/700 */
31677 .name = DRV_NAME,
31678 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31679diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31680index 5f80312..d1fc438 100644
31681--- a/drivers/ide/cmd64x.c
31682+++ b/drivers/ide/cmd64x.c
31683@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31684 .dma_sff_read_status = ide_dma_sff_read_status,
31685 };
31686
31687-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31688+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31689 { /* 0: CMD643 */
31690 .name = DRV_NAME,
31691 .init_chipset = init_chipset_cmd64x,
31692diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31693index 2c1e5f7..1444762 100644
31694--- a/drivers/ide/cs5520.c
31695+++ b/drivers/ide/cs5520.c
31696@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31697 .set_dma_mode = cs5520_set_dma_mode,
31698 };
31699
31700-static const struct ide_port_info cyrix_chipset __devinitdata = {
31701+static const struct ide_port_info cyrix_chipset __devinitconst = {
31702 .name = DRV_NAME,
31703 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31704 .port_ops = &cs5520_port_ops,
31705diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31706index 4dc4eb9..49b40ad 100644
31707--- a/drivers/ide/cs5530.c
31708+++ b/drivers/ide/cs5530.c
31709@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31710 .udma_filter = cs5530_udma_filter,
31711 };
31712
31713-static const struct ide_port_info cs5530_chipset __devinitdata = {
31714+static const struct ide_port_info cs5530_chipset __devinitconst = {
31715 .name = DRV_NAME,
31716 .init_chipset = init_chipset_cs5530,
31717 .init_hwif = init_hwif_cs5530,
31718diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31719index 5059faf..18d4c85 100644
31720--- a/drivers/ide/cs5535.c
31721+++ b/drivers/ide/cs5535.c
31722@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31723 .cable_detect = cs5535_cable_detect,
31724 };
31725
31726-static const struct ide_port_info cs5535_chipset __devinitdata = {
31727+static const struct ide_port_info cs5535_chipset __devinitconst = {
31728 .name = DRV_NAME,
31729 .port_ops = &cs5535_port_ops,
31730 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31731diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31732index 847553f..3ffb49d 100644
31733--- a/drivers/ide/cy82c693.c
31734+++ b/drivers/ide/cy82c693.c
31735@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31736 .set_dma_mode = cy82c693_set_dma_mode,
31737 };
31738
31739-static const struct ide_port_info cy82c693_chipset __devinitdata = {
31740+static const struct ide_port_info cy82c693_chipset __devinitconst = {
31741 .name = DRV_NAME,
31742 .init_iops = init_iops_cy82c693,
31743 .port_ops = &cy82c693_port_ops,
31744diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31745index 58c51cd..4aec3b8 100644
31746--- a/drivers/ide/hpt366.c
31747+++ b/drivers/ide/hpt366.c
31748@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31749 }
31750 };
31751
31752-static const struct hpt_info hpt36x __devinitdata = {
31753+static const struct hpt_info hpt36x __devinitconst = {
31754 .chip_name = "HPT36x",
31755 .chip_type = HPT36x,
31756 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31757@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31758 .timings = &hpt36x_timings
31759 };
31760
31761-static const struct hpt_info hpt370 __devinitdata = {
31762+static const struct hpt_info hpt370 __devinitconst = {
31763 .chip_name = "HPT370",
31764 .chip_type = HPT370,
31765 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31766@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31767 .timings = &hpt37x_timings
31768 };
31769
31770-static const struct hpt_info hpt370a __devinitdata = {
31771+static const struct hpt_info hpt370a __devinitconst = {
31772 .chip_name = "HPT370A",
31773 .chip_type = HPT370A,
31774 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31775@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31776 .timings = &hpt37x_timings
31777 };
31778
31779-static const struct hpt_info hpt374 __devinitdata = {
31780+static const struct hpt_info hpt374 __devinitconst = {
31781 .chip_name = "HPT374",
31782 .chip_type = HPT374,
31783 .udma_mask = ATA_UDMA5,
31784@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31785 .timings = &hpt37x_timings
31786 };
31787
31788-static const struct hpt_info hpt372 __devinitdata = {
31789+static const struct hpt_info hpt372 __devinitconst = {
31790 .chip_name = "HPT372",
31791 .chip_type = HPT372,
31792 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31793@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31794 .timings = &hpt37x_timings
31795 };
31796
31797-static const struct hpt_info hpt372a __devinitdata = {
31798+static const struct hpt_info hpt372a __devinitconst = {
31799 .chip_name = "HPT372A",
31800 .chip_type = HPT372A,
31801 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31802@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31803 .timings = &hpt37x_timings
31804 };
31805
31806-static const struct hpt_info hpt302 __devinitdata = {
31807+static const struct hpt_info hpt302 __devinitconst = {
31808 .chip_name = "HPT302",
31809 .chip_type = HPT302,
31810 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31811@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31812 .timings = &hpt37x_timings
31813 };
31814
31815-static const struct hpt_info hpt371 __devinitdata = {
31816+static const struct hpt_info hpt371 __devinitconst = {
31817 .chip_name = "HPT371",
31818 .chip_type = HPT371,
31819 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31820@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31821 .timings = &hpt37x_timings
31822 };
31823
31824-static const struct hpt_info hpt372n __devinitdata = {
31825+static const struct hpt_info hpt372n __devinitconst = {
31826 .chip_name = "HPT372N",
31827 .chip_type = HPT372N,
31828 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31829@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31830 .timings = &hpt37x_timings
31831 };
31832
31833-static const struct hpt_info hpt302n __devinitdata = {
31834+static const struct hpt_info hpt302n __devinitconst = {
31835 .chip_name = "HPT302N",
31836 .chip_type = HPT302N,
31837 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31838@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31839 .timings = &hpt37x_timings
31840 };
31841
31842-static const struct hpt_info hpt371n __devinitdata = {
31843+static const struct hpt_info hpt371n __devinitconst = {
31844 .chip_name = "HPT371N",
31845 .chip_type = HPT371N,
31846 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31847@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31848 .dma_sff_read_status = ide_dma_sff_read_status,
31849 };
31850
31851-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31852+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31853 { /* 0: HPT36x */
31854 .name = DRV_NAME,
31855 .init_chipset = init_chipset_hpt366,
31856diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31857index 8126824..55a2798 100644
31858--- a/drivers/ide/ide-cd.c
31859+++ b/drivers/ide/ide-cd.c
31860@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31861 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31862 if ((unsigned long)buf & alignment
31863 || blk_rq_bytes(rq) & q->dma_pad_mask
31864- || object_is_on_stack(buf))
31865+ || object_starts_on_stack(buf))
31866 drive->dma = 0;
31867 }
31868 }
31869diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31870index 7f56b73..dab5b67 100644
31871--- a/drivers/ide/ide-pci-generic.c
31872+++ b/drivers/ide/ide-pci-generic.c
31873@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31874 .udma_mask = ATA_UDMA6, \
31875 }
31876
31877-static const struct ide_port_info generic_chipsets[] __devinitdata = {
31878+static const struct ide_port_info generic_chipsets[] __devinitconst = {
31879 /* 0: Unknown */
31880 DECLARE_GENERIC_PCI_DEV(0),
31881
31882diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31883index 560e66d..d5dd180 100644
31884--- a/drivers/ide/it8172.c
31885+++ b/drivers/ide/it8172.c
31886@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31887 .set_dma_mode = it8172_set_dma_mode,
31888 };
31889
31890-static const struct ide_port_info it8172_port_info __devinitdata = {
31891+static const struct ide_port_info it8172_port_info __devinitconst = {
31892 .name = DRV_NAME,
31893 .port_ops = &it8172_port_ops,
31894 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31895diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31896index 46816ba..1847aeb 100644
31897--- a/drivers/ide/it8213.c
31898+++ b/drivers/ide/it8213.c
31899@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31900 .cable_detect = it8213_cable_detect,
31901 };
31902
31903-static const struct ide_port_info it8213_chipset __devinitdata = {
31904+static const struct ide_port_info it8213_chipset __devinitconst = {
31905 .name = DRV_NAME,
31906 .enablebits = { {0x41, 0x80, 0x80} },
31907 .port_ops = &it8213_port_ops,
31908diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31909index 2e3169f..c5611db 100644
31910--- a/drivers/ide/it821x.c
31911+++ b/drivers/ide/it821x.c
31912@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31913 .cable_detect = it821x_cable_detect,
31914 };
31915
31916-static const struct ide_port_info it821x_chipset __devinitdata = {
31917+static const struct ide_port_info it821x_chipset __devinitconst = {
31918 .name = DRV_NAME,
31919 .init_chipset = init_chipset_it821x,
31920 .init_hwif = init_hwif_it821x,
31921diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31922index 74c2c4a..efddd7d 100644
31923--- a/drivers/ide/jmicron.c
31924+++ b/drivers/ide/jmicron.c
31925@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31926 .cable_detect = jmicron_cable_detect,
31927 };
31928
31929-static const struct ide_port_info jmicron_chipset __devinitdata = {
31930+static const struct ide_port_info jmicron_chipset __devinitconst = {
31931 .name = DRV_NAME,
31932 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31933 .port_ops = &jmicron_port_ops,
31934diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31935index 95327a2..73f78d8 100644
31936--- a/drivers/ide/ns87415.c
31937+++ b/drivers/ide/ns87415.c
31938@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31939 .dma_sff_read_status = superio_dma_sff_read_status,
31940 };
31941
31942-static const struct ide_port_info ns87415_chipset __devinitdata = {
31943+static const struct ide_port_info ns87415_chipset __devinitconst = {
31944 .name = DRV_NAME,
31945 .init_hwif = init_hwif_ns87415,
31946 .tp_ops = &ns87415_tp_ops,
31947diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31948index 1a53a4c..39edc66 100644
31949--- a/drivers/ide/opti621.c
31950+++ b/drivers/ide/opti621.c
31951@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31952 .set_pio_mode = opti621_set_pio_mode,
31953 };
31954
31955-static const struct ide_port_info opti621_chipset __devinitdata = {
31956+static const struct ide_port_info opti621_chipset __devinitconst = {
31957 .name = DRV_NAME,
31958 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31959 .port_ops = &opti621_port_ops,
31960diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31961index 9546fe2..2e5ceb6 100644
31962--- a/drivers/ide/pdc202xx_new.c
31963+++ b/drivers/ide/pdc202xx_new.c
31964@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31965 .udma_mask = udma, \
31966 }
31967
31968-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31969+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31970 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31971 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31972 };
31973diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31974index 3a35ec6..5634510 100644
31975--- a/drivers/ide/pdc202xx_old.c
31976+++ b/drivers/ide/pdc202xx_old.c
31977@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31978 .max_sectors = sectors, \
31979 }
31980
31981-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31982+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31983 { /* 0: PDC20246 */
31984 .name = DRV_NAME,
31985 .init_chipset = init_chipset_pdc202xx,
31986diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31987index 1892e81..fe0fd60 100644
31988--- a/drivers/ide/piix.c
31989+++ b/drivers/ide/piix.c
31990@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31991 .udma_mask = udma, \
31992 }
31993
31994-static const struct ide_port_info piix_pci_info[] __devinitdata = {
31995+static const struct ide_port_info piix_pci_info[] __devinitconst = {
31996 /* 0: MPIIX */
31997 { /*
31998 * MPIIX actually has only a single IDE channel mapped to
31999diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32000index a6414a8..c04173e 100644
32001--- a/drivers/ide/rz1000.c
32002+++ b/drivers/ide/rz1000.c
32003@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32004 }
32005 }
32006
32007-static const struct ide_port_info rz1000_chipset __devinitdata = {
32008+static const struct ide_port_info rz1000_chipset __devinitconst = {
32009 .name = DRV_NAME,
32010 .host_flags = IDE_HFLAG_NO_DMA,
32011 };
32012diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32013index 356b9b5..d4758eb 100644
32014--- a/drivers/ide/sc1200.c
32015+++ b/drivers/ide/sc1200.c
32016@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32017 .dma_sff_read_status = ide_dma_sff_read_status,
32018 };
32019
32020-static const struct ide_port_info sc1200_chipset __devinitdata = {
32021+static const struct ide_port_info sc1200_chipset __devinitconst = {
32022 .name = DRV_NAME,
32023 .port_ops = &sc1200_port_ops,
32024 .dma_ops = &sc1200_dma_ops,
32025diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32026index b7f5b0c..9701038 100644
32027--- a/drivers/ide/scc_pata.c
32028+++ b/drivers/ide/scc_pata.c
32029@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32030 .dma_sff_read_status = scc_dma_sff_read_status,
32031 };
32032
32033-static const struct ide_port_info scc_chipset __devinitdata = {
32034+static const struct ide_port_info scc_chipset __devinitconst = {
32035 .name = "sccIDE",
32036 .init_iops = init_iops_scc,
32037 .init_dma = scc_init_dma,
32038diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32039index 35fb8da..24d72ef 100644
32040--- a/drivers/ide/serverworks.c
32041+++ b/drivers/ide/serverworks.c
32042@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32043 .cable_detect = svwks_cable_detect,
32044 };
32045
32046-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32047+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32048 { /* 0: OSB4 */
32049 .name = DRV_NAME,
32050 .init_chipset = init_chipset_svwks,
32051diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32052index ddeda44..46f7e30 100644
32053--- a/drivers/ide/siimage.c
32054+++ b/drivers/ide/siimage.c
32055@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32056 .udma_mask = ATA_UDMA6, \
32057 }
32058
32059-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32060+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32061 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32062 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32063 };
32064diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32065index 4a00225..09e61b4 100644
32066--- a/drivers/ide/sis5513.c
32067+++ b/drivers/ide/sis5513.c
32068@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32069 .cable_detect = sis_cable_detect,
32070 };
32071
32072-static const struct ide_port_info sis5513_chipset __devinitdata = {
32073+static const struct ide_port_info sis5513_chipset __devinitconst = {
32074 .name = DRV_NAME,
32075 .init_chipset = init_chipset_sis5513,
32076 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32077diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32078index f21dc2a..d051cd2 100644
32079--- a/drivers/ide/sl82c105.c
32080+++ b/drivers/ide/sl82c105.c
32081@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32082 .dma_sff_read_status = ide_dma_sff_read_status,
32083 };
32084
32085-static const struct ide_port_info sl82c105_chipset __devinitdata = {
32086+static const struct ide_port_info sl82c105_chipset __devinitconst = {
32087 .name = DRV_NAME,
32088 .init_chipset = init_chipset_sl82c105,
32089 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32090diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32091index 864ffe0..863a5e9 100644
32092--- a/drivers/ide/slc90e66.c
32093+++ b/drivers/ide/slc90e66.c
32094@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32095 .cable_detect = slc90e66_cable_detect,
32096 };
32097
32098-static const struct ide_port_info slc90e66_chipset __devinitdata = {
32099+static const struct ide_port_info slc90e66_chipset __devinitconst = {
32100 .name = DRV_NAME,
32101 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32102 .port_ops = &slc90e66_port_ops,
32103diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32104index 4799d5c..1794678 100644
32105--- a/drivers/ide/tc86c001.c
32106+++ b/drivers/ide/tc86c001.c
32107@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32108 .dma_sff_read_status = ide_dma_sff_read_status,
32109 };
32110
32111-static const struct ide_port_info tc86c001_chipset __devinitdata = {
32112+static const struct ide_port_info tc86c001_chipset __devinitconst = {
32113 .name = DRV_NAME,
32114 .init_hwif = init_hwif_tc86c001,
32115 .port_ops = &tc86c001_port_ops,
32116diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32117index 281c914..55ce1b8 100644
32118--- a/drivers/ide/triflex.c
32119+++ b/drivers/ide/triflex.c
32120@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32121 .set_dma_mode = triflex_set_mode,
32122 };
32123
32124-static const struct ide_port_info triflex_device __devinitdata = {
32125+static const struct ide_port_info triflex_device __devinitconst = {
32126 .name = DRV_NAME,
32127 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32128 .port_ops = &triflex_port_ops,
32129diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32130index 4b42ca0..e494a98 100644
32131--- a/drivers/ide/trm290.c
32132+++ b/drivers/ide/trm290.c
32133@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32134 .dma_check = trm290_dma_check,
32135 };
32136
32137-static const struct ide_port_info trm290_chipset __devinitdata = {
32138+static const struct ide_port_info trm290_chipset __devinitconst = {
32139 .name = DRV_NAME,
32140 .init_hwif = init_hwif_trm290,
32141 .tp_ops = &trm290_tp_ops,
32142diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32143index f46f49c..eb77678 100644
32144--- a/drivers/ide/via82cxxx.c
32145+++ b/drivers/ide/via82cxxx.c
32146@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32147 .cable_detect = via82cxxx_cable_detect,
32148 };
32149
32150-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32151+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32152 .name = DRV_NAME,
32153 .init_chipset = init_chipset_via82cxxx,
32154 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32155diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32156index 73d4531..c90cd2d 100644
32157--- a/drivers/ieee802154/fakehard.c
32158+++ b/drivers/ieee802154/fakehard.c
32159@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32160 phy->transmit_power = 0xbf;
32161
32162 dev->netdev_ops = &fake_ops;
32163- dev->ml_priv = &fake_mlme;
32164+ dev->ml_priv = (void *)&fake_mlme;
32165
32166 priv = netdev_priv(dev);
32167 priv->phy = phy;
32168diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32169index c889aae..6cf5aa7 100644
32170--- a/drivers/infiniband/core/cm.c
32171+++ b/drivers/infiniband/core/cm.c
32172@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32173
32174 struct cm_counter_group {
32175 struct kobject obj;
32176- atomic_long_t counter[CM_ATTR_COUNT];
32177+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32178 };
32179
32180 struct cm_counter_attribute {
32181@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32182 struct ib_mad_send_buf *msg = NULL;
32183 int ret;
32184
32185- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32186+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32187 counter[CM_REQ_COUNTER]);
32188
32189 /* Quick state check to discard duplicate REQs. */
32190@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32191 if (!cm_id_priv)
32192 return;
32193
32194- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32195+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32196 counter[CM_REP_COUNTER]);
32197 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32198 if (ret)
32199@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32200 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32201 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32202 spin_unlock_irq(&cm_id_priv->lock);
32203- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32204+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32205 counter[CM_RTU_COUNTER]);
32206 goto out;
32207 }
32208@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32209 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32210 dreq_msg->local_comm_id);
32211 if (!cm_id_priv) {
32212- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32213+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32214 counter[CM_DREQ_COUNTER]);
32215 cm_issue_drep(work->port, work->mad_recv_wc);
32216 return -EINVAL;
32217@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32218 case IB_CM_MRA_REP_RCVD:
32219 break;
32220 case IB_CM_TIMEWAIT:
32221- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32222+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32223 counter[CM_DREQ_COUNTER]);
32224 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32225 goto unlock;
32226@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32227 cm_free_msg(msg);
32228 goto deref;
32229 case IB_CM_DREQ_RCVD:
32230- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32231+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32232 counter[CM_DREQ_COUNTER]);
32233 goto unlock;
32234 default:
32235@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32236 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32237 cm_id_priv->msg, timeout)) {
32238 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32239- atomic_long_inc(&work->port->
32240+ atomic_long_inc_unchecked(&work->port->
32241 counter_group[CM_RECV_DUPLICATES].
32242 counter[CM_MRA_COUNTER]);
32243 goto out;
32244@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32245 break;
32246 case IB_CM_MRA_REQ_RCVD:
32247 case IB_CM_MRA_REP_RCVD:
32248- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32249+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32250 counter[CM_MRA_COUNTER]);
32251 /* fall through */
32252 default:
32253@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32254 case IB_CM_LAP_IDLE:
32255 break;
32256 case IB_CM_MRA_LAP_SENT:
32257- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32258+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32259 counter[CM_LAP_COUNTER]);
32260 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32261 goto unlock;
32262@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32263 cm_free_msg(msg);
32264 goto deref;
32265 case IB_CM_LAP_RCVD:
32266- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32267+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32268 counter[CM_LAP_COUNTER]);
32269 goto unlock;
32270 default:
32271@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32272 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32273 if (cur_cm_id_priv) {
32274 spin_unlock_irq(&cm.lock);
32275- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32276+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32277 counter[CM_SIDR_REQ_COUNTER]);
32278 goto out; /* Duplicate message. */
32279 }
32280@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32281 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32282 msg->retries = 1;
32283
32284- atomic_long_add(1 + msg->retries,
32285+ atomic_long_add_unchecked(1 + msg->retries,
32286 &port->counter_group[CM_XMIT].counter[attr_index]);
32287 if (msg->retries)
32288- atomic_long_add(msg->retries,
32289+ atomic_long_add_unchecked(msg->retries,
32290 &port->counter_group[CM_XMIT_RETRIES].
32291 counter[attr_index]);
32292
32293@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32294 }
32295
32296 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32297- atomic_long_inc(&port->counter_group[CM_RECV].
32298+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32299 counter[attr_id - CM_ATTR_ID_OFFSET]);
32300
32301 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32302@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32303 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32304
32305 return sprintf(buf, "%ld\n",
32306- atomic_long_read(&group->counter[cm_attr->index]));
32307+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32308 }
32309
32310 static const struct sysfs_ops cm_counter_ops = {
32311diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32312index 176c8f9..2627b62 100644
32313--- a/drivers/infiniband/core/fmr_pool.c
32314+++ b/drivers/infiniband/core/fmr_pool.c
32315@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32316
32317 struct task_struct *thread;
32318
32319- atomic_t req_ser;
32320- atomic_t flush_ser;
32321+ atomic_unchecked_t req_ser;
32322+ atomic_unchecked_t flush_ser;
32323
32324 wait_queue_head_t force_wait;
32325 };
32326@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32327 struct ib_fmr_pool *pool = pool_ptr;
32328
32329 do {
32330- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32331+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32332 ib_fmr_batch_release(pool);
32333
32334- atomic_inc(&pool->flush_ser);
32335+ atomic_inc_unchecked(&pool->flush_ser);
32336 wake_up_interruptible(&pool->force_wait);
32337
32338 if (pool->flush_function)
32339@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32340 }
32341
32342 set_current_state(TASK_INTERRUPTIBLE);
32343- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32344+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32345 !kthread_should_stop())
32346 schedule();
32347 __set_current_state(TASK_RUNNING);
32348@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32349 pool->dirty_watermark = params->dirty_watermark;
32350 pool->dirty_len = 0;
32351 spin_lock_init(&pool->pool_lock);
32352- atomic_set(&pool->req_ser, 0);
32353- atomic_set(&pool->flush_ser, 0);
32354+ atomic_set_unchecked(&pool->req_ser, 0);
32355+ atomic_set_unchecked(&pool->flush_ser, 0);
32356 init_waitqueue_head(&pool->force_wait);
32357
32358 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32359@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32360 }
32361 spin_unlock_irq(&pool->pool_lock);
32362
32363- serial = atomic_inc_return(&pool->req_ser);
32364+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32365 wake_up_process(pool->thread);
32366
32367 if (wait_event_interruptible(pool->force_wait,
32368- atomic_read(&pool->flush_ser) - serial >= 0))
32369+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32370 return -EINTR;
32371
32372 return 0;
32373@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32374 } else {
32375 list_add_tail(&fmr->list, &pool->dirty_list);
32376 if (++pool->dirty_len >= pool->dirty_watermark) {
32377- atomic_inc(&pool->req_ser);
32378+ atomic_inc_unchecked(&pool->req_ser);
32379 wake_up_process(pool->thread);
32380 }
32381 }
32382diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32383index 57e07c6..56d09d4 100644
32384--- a/drivers/infiniband/hw/cxgb4/mem.c
32385+++ b/drivers/infiniband/hw/cxgb4/mem.c
32386@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32387 int err;
32388 struct fw_ri_tpte tpt;
32389 u32 stag_idx;
32390- static atomic_t key;
32391+ static atomic_unchecked_t key;
32392
32393 if (c4iw_fatal_error(rdev))
32394 return -EIO;
32395@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32396 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32397 rdev->stats.stag.max = rdev->stats.stag.cur;
32398 mutex_unlock(&rdev->stats.lock);
32399- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32400+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32401 }
32402 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32403 __func__, stag_state, type, pdid, stag_idx);
32404diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32405index 79b3dbc..96e5fcc 100644
32406--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32407+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32408@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32409 struct ib_atomic_eth *ateth;
32410 struct ipath_ack_entry *e;
32411 u64 vaddr;
32412- atomic64_t *maddr;
32413+ atomic64_unchecked_t *maddr;
32414 u64 sdata;
32415 u32 rkey;
32416 u8 next;
32417@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32418 IB_ACCESS_REMOTE_ATOMIC)))
32419 goto nack_acc_unlck;
32420 /* Perform atomic OP and save result. */
32421- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32422+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32423 sdata = be64_to_cpu(ateth->swap_data);
32424 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32425 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32426- (u64) atomic64_add_return(sdata, maddr) - sdata :
32427+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32428 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32429 be64_to_cpu(ateth->compare_data),
32430 sdata);
32431diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32432index 1f95bba..9530f87 100644
32433--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32434+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32435@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32436 unsigned long flags;
32437 struct ib_wc wc;
32438 u64 sdata;
32439- atomic64_t *maddr;
32440+ atomic64_unchecked_t *maddr;
32441 enum ib_wc_status send_status;
32442
32443 /*
32444@@ -382,11 +382,11 @@ again:
32445 IB_ACCESS_REMOTE_ATOMIC)))
32446 goto acc_err;
32447 /* Perform atomic OP and save result. */
32448- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32449+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32450 sdata = wqe->wr.wr.atomic.compare_add;
32451 *(u64 *) sqp->s_sge.sge.vaddr =
32452 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32453- (u64) atomic64_add_return(sdata, maddr) - sdata :
32454+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32455 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32456 sdata, wqe->wr.wr.atomic.swap);
32457 goto send_comp;
32458diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32459index 7140199..da60063 100644
32460--- a/drivers/infiniband/hw/nes/nes.c
32461+++ b/drivers/infiniband/hw/nes/nes.c
32462@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32463 LIST_HEAD(nes_adapter_list);
32464 static LIST_HEAD(nes_dev_list);
32465
32466-atomic_t qps_destroyed;
32467+atomic_unchecked_t qps_destroyed;
32468
32469 static unsigned int ee_flsh_adapter;
32470 static unsigned int sysfs_nonidx_addr;
32471@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32472 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32473 struct nes_adapter *nesadapter = nesdev->nesadapter;
32474
32475- atomic_inc(&qps_destroyed);
32476+ atomic_inc_unchecked(&qps_destroyed);
32477
32478 /* Free the control structures */
32479
32480diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32481index c438e46..ca30356 100644
32482--- a/drivers/infiniband/hw/nes/nes.h
32483+++ b/drivers/infiniband/hw/nes/nes.h
32484@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32485 extern unsigned int wqm_quanta;
32486 extern struct list_head nes_adapter_list;
32487
32488-extern atomic_t cm_connects;
32489-extern atomic_t cm_accepts;
32490-extern atomic_t cm_disconnects;
32491-extern atomic_t cm_closes;
32492-extern atomic_t cm_connecteds;
32493-extern atomic_t cm_connect_reqs;
32494-extern atomic_t cm_rejects;
32495-extern atomic_t mod_qp_timouts;
32496-extern atomic_t qps_created;
32497-extern atomic_t qps_destroyed;
32498-extern atomic_t sw_qps_destroyed;
32499+extern atomic_unchecked_t cm_connects;
32500+extern atomic_unchecked_t cm_accepts;
32501+extern atomic_unchecked_t cm_disconnects;
32502+extern atomic_unchecked_t cm_closes;
32503+extern atomic_unchecked_t cm_connecteds;
32504+extern atomic_unchecked_t cm_connect_reqs;
32505+extern atomic_unchecked_t cm_rejects;
32506+extern atomic_unchecked_t mod_qp_timouts;
32507+extern atomic_unchecked_t qps_created;
32508+extern atomic_unchecked_t qps_destroyed;
32509+extern atomic_unchecked_t sw_qps_destroyed;
32510 extern u32 mh_detected;
32511 extern u32 mh_pauses_sent;
32512 extern u32 cm_packets_sent;
32513@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32514 extern u32 cm_packets_received;
32515 extern u32 cm_packets_dropped;
32516 extern u32 cm_packets_retrans;
32517-extern atomic_t cm_listens_created;
32518-extern atomic_t cm_listens_destroyed;
32519+extern atomic_unchecked_t cm_listens_created;
32520+extern atomic_unchecked_t cm_listens_destroyed;
32521 extern u32 cm_backlog_drops;
32522-extern atomic_t cm_loopbacks;
32523-extern atomic_t cm_nodes_created;
32524-extern atomic_t cm_nodes_destroyed;
32525-extern atomic_t cm_accel_dropped_pkts;
32526-extern atomic_t cm_resets_recvd;
32527-extern atomic_t pau_qps_created;
32528-extern atomic_t pau_qps_destroyed;
32529+extern atomic_unchecked_t cm_loopbacks;
32530+extern atomic_unchecked_t cm_nodes_created;
32531+extern atomic_unchecked_t cm_nodes_destroyed;
32532+extern atomic_unchecked_t cm_accel_dropped_pkts;
32533+extern atomic_unchecked_t cm_resets_recvd;
32534+extern atomic_unchecked_t pau_qps_created;
32535+extern atomic_unchecked_t pau_qps_destroyed;
32536
32537 extern u32 int_mod_timer_init;
32538 extern u32 int_mod_cq_depth_256;
32539diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32540index 020e95c..fbb3450 100644
32541--- a/drivers/infiniband/hw/nes/nes_cm.c
32542+++ b/drivers/infiniband/hw/nes/nes_cm.c
32543@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32544 u32 cm_packets_retrans;
32545 u32 cm_packets_created;
32546 u32 cm_packets_received;
32547-atomic_t cm_listens_created;
32548-atomic_t cm_listens_destroyed;
32549+atomic_unchecked_t cm_listens_created;
32550+atomic_unchecked_t cm_listens_destroyed;
32551 u32 cm_backlog_drops;
32552-atomic_t cm_loopbacks;
32553-atomic_t cm_nodes_created;
32554-atomic_t cm_nodes_destroyed;
32555-atomic_t cm_accel_dropped_pkts;
32556-atomic_t cm_resets_recvd;
32557+atomic_unchecked_t cm_loopbacks;
32558+atomic_unchecked_t cm_nodes_created;
32559+atomic_unchecked_t cm_nodes_destroyed;
32560+atomic_unchecked_t cm_accel_dropped_pkts;
32561+atomic_unchecked_t cm_resets_recvd;
32562
32563 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32564 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32565@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32566
32567 static struct nes_cm_core *g_cm_core;
32568
32569-atomic_t cm_connects;
32570-atomic_t cm_accepts;
32571-atomic_t cm_disconnects;
32572-atomic_t cm_closes;
32573-atomic_t cm_connecteds;
32574-atomic_t cm_connect_reqs;
32575-atomic_t cm_rejects;
32576+atomic_unchecked_t cm_connects;
32577+atomic_unchecked_t cm_accepts;
32578+atomic_unchecked_t cm_disconnects;
32579+atomic_unchecked_t cm_closes;
32580+atomic_unchecked_t cm_connecteds;
32581+atomic_unchecked_t cm_connect_reqs;
32582+atomic_unchecked_t cm_rejects;
32583
32584 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32585 {
32586@@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32587 kfree(listener);
32588 listener = NULL;
32589 ret = 0;
32590- atomic_inc(&cm_listens_destroyed);
32591+ atomic_inc_unchecked(&cm_listens_destroyed);
32592 } else {
32593 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32594 }
32595@@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32596 cm_node->rem_mac);
32597
32598 add_hte_node(cm_core, cm_node);
32599- atomic_inc(&cm_nodes_created);
32600+ atomic_inc_unchecked(&cm_nodes_created);
32601
32602 return cm_node;
32603 }
32604@@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32605 }
32606
32607 atomic_dec(&cm_core->node_cnt);
32608- atomic_inc(&cm_nodes_destroyed);
32609+ atomic_inc_unchecked(&cm_nodes_destroyed);
32610 nesqp = cm_node->nesqp;
32611 if (nesqp) {
32612 nesqp->cm_node = NULL;
32613@@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32614
32615 static void drop_packet(struct sk_buff *skb)
32616 {
32617- atomic_inc(&cm_accel_dropped_pkts);
32618+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32619 dev_kfree_skb_any(skb);
32620 }
32621
32622@@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32623 {
32624
32625 int reset = 0; /* whether to send reset in case of err.. */
32626- atomic_inc(&cm_resets_recvd);
32627+ atomic_inc_unchecked(&cm_resets_recvd);
32628 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32629 " refcnt=%d\n", cm_node, cm_node->state,
32630 atomic_read(&cm_node->ref_count));
32631@@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32632 rem_ref_cm_node(cm_node->cm_core, cm_node);
32633 return NULL;
32634 }
32635- atomic_inc(&cm_loopbacks);
32636+ atomic_inc_unchecked(&cm_loopbacks);
32637 loopbackremotenode->loopbackpartner = cm_node;
32638 loopbackremotenode->tcp_cntxt.rcv_wscale =
32639 NES_CM_DEFAULT_RCV_WND_SCALE;
32640@@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32641 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32642 else {
32643 rem_ref_cm_node(cm_core, cm_node);
32644- atomic_inc(&cm_accel_dropped_pkts);
32645+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32646 dev_kfree_skb_any(skb);
32647 }
32648 break;
32649@@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32650
32651 if ((cm_id) && (cm_id->event_handler)) {
32652 if (issue_disconn) {
32653- atomic_inc(&cm_disconnects);
32654+ atomic_inc_unchecked(&cm_disconnects);
32655 cm_event.event = IW_CM_EVENT_DISCONNECT;
32656 cm_event.status = disconn_status;
32657 cm_event.local_addr = cm_id->local_addr;
32658@@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32659 }
32660
32661 if (issue_close) {
32662- atomic_inc(&cm_closes);
32663+ atomic_inc_unchecked(&cm_closes);
32664 nes_disconnect(nesqp, 1);
32665
32666 cm_id->provider_data = nesqp;
32667@@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32668
32669 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32670 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32671- atomic_inc(&cm_accepts);
32672+ atomic_inc_unchecked(&cm_accepts);
32673
32674 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32675 netdev_refcnt_read(nesvnic->netdev));
32676@@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32677 struct nes_cm_core *cm_core;
32678 u8 *start_buff;
32679
32680- atomic_inc(&cm_rejects);
32681+ atomic_inc_unchecked(&cm_rejects);
32682 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32683 loopback = cm_node->loopbackpartner;
32684 cm_core = cm_node->cm_core;
32685@@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32686 ntohl(cm_id->local_addr.sin_addr.s_addr),
32687 ntohs(cm_id->local_addr.sin_port));
32688
32689- atomic_inc(&cm_connects);
32690+ atomic_inc_unchecked(&cm_connects);
32691 nesqp->active_conn = 1;
32692
32693 /* cache the cm_id in the qp */
32694@@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32695 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32696 return err;
32697 }
32698- atomic_inc(&cm_listens_created);
32699+ atomic_inc_unchecked(&cm_listens_created);
32700 }
32701
32702 cm_id->add_ref(cm_id);
32703@@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32704
32705 if (nesqp->destroyed)
32706 return;
32707- atomic_inc(&cm_connecteds);
32708+ atomic_inc_unchecked(&cm_connecteds);
32709 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32710 " local port 0x%04X. jiffies = %lu.\n",
32711 nesqp->hwqp.qp_id,
32712@@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32713
32714 cm_id->add_ref(cm_id);
32715 ret = cm_id->event_handler(cm_id, &cm_event);
32716- atomic_inc(&cm_closes);
32717+ atomic_inc_unchecked(&cm_closes);
32718 cm_event.event = IW_CM_EVENT_CLOSE;
32719 cm_event.status = 0;
32720 cm_event.provider_data = cm_id->provider_data;
32721@@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32722 return;
32723 cm_id = cm_node->cm_id;
32724
32725- atomic_inc(&cm_connect_reqs);
32726+ atomic_inc_unchecked(&cm_connect_reqs);
32727 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32728 cm_node, cm_id, jiffies);
32729
32730@@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32731 return;
32732 cm_id = cm_node->cm_id;
32733
32734- atomic_inc(&cm_connect_reqs);
32735+ atomic_inc_unchecked(&cm_connect_reqs);
32736 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32737 cm_node, cm_id, jiffies);
32738
32739diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32740index 3ba7be3..c81f6ff 100644
32741--- a/drivers/infiniband/hw/nes/nes_mgt.c
32742+++ b/drivers/infiniband/hw/nes/nes_mgt.c
32743@@ -40,8 +40,8 @@
32744 #include "nes.h"
32745 #include "nes_mgt.h"
32746
32747-atomic_t pau_qps_created;
32748-atomic_t pau_qps_destroyed;
32749+atomic_unchecked_t pau_qps_created;
32750+atomic_unchecked_t pau_qps_destroyed;
32751
32752 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32753 {
32754@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32755 {
32756 struct sk_buff *skb;
32757 unsigned long flags;
32758- atomic_inc(&pau_qps_destroyed);
32759+ atomic_inc_unchecked(&pau_qps_destroyed);
32760
32761 /* Free packets that have not yet been forwarded */
32762 /* Lock is acquired by skb_dequeue when removing the skb */
32763@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32764 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32765 skb_queue_head_init(&nesqp->pau_list);
32766 spin_lock_init(&nesqp->pau_lock);
32767- atomic_inc(&pau_qps_created);
32768+ atomic_inc_unchecked(&pau_qps_created);
32769 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32770 }
32771
32772diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32773index f3a3ecf..57d311d 100644
32774--- a/drivers/infiniband/hw/nes/nes_nic.c
32775+++ b/drivers/infiniband/hw/nes/nes_nic.c
32776@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32777 target_stat_values[++index] = mh_detected;
32778 target_stat_values[++index] = mh_pauses_sent;
32779 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32780- target_stat_values[++index] = atomic_read(&cm_connects);
32781- target_stat_values[++index] = atomic_read(&cm_accepts);
32782- target_stat_values[++index] = atomic_read(&cm_disconnects);
32783- target_stat_values[++index] = atomic_read(&cm_connecteds);
32784- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32785- target_stat_values[++index] = atomic_read(&cm_rejects);
32786- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32787- target_stat_values[++index] = atomic_read(&qps_created);
32788- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32789- target_stat_values[++index] = atomic_read(&qps_destroyed);
32790- target_stat_values[++index] = atomic_read(&cm_closes);
32791+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32792+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32793+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32794+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32795+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32796+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32797+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32798+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32799+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32800+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32801+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32802 target_stat_values[++index] = cm_packets_sent;
32803 target_stat_values[++index] = cm_packets_bounced;
32804 target_stat_values[++index] = cm_packets_created;
32805 target_stat_values[++index] = cm_packets_received;
32806 target_stat_values[++index] = cm_packets_dropped;
32807 target_stat_values[++index] = cm_packets_retrans;
32808- target_stat_values[++index] = atomic_read(&cm_listens_created);
32809- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32810+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32811+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32812 target_stat_values[++index] = cm_backlog_drops;
32813- target_stat_values[++index] = atomic_read(&cm_loopbacks);
32814- target_stat_values[++index] = atomic_read(&cm_nodes_created);
32815- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32816- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32817- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32818+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32819+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32820+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32821+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32822+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32823 target_stat_values[++index] = nesadapter->free_4kpbl;
32824 target_stat_values[++index] = nesadapter->free_256pbl;
32825 target_stat_values[++index] = int_mod_timer_init;
32826 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32827 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32828 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32829- target_stat_values[++index] = atomic_read(&pau_qps_created);
32830- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32831+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32832+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32833 }
32834
32835 /**
32836diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32837index 8b8812d..a5e1133 100644
32838--- a/drivers/infiniband/hw/nes/nes_verbs.c
32839+++ b/drivers/infiniband/hw/nes/nes_verbs.c
32840@@ -46,9 +46,9 @@
32841
32842 #include <rdma/ib_umem.h>
32843
32844-atomic_t mod_qp_timouts;
32845-atomic_t qps_created;
32846-atomic_t sw_qps_destroyed;
32847+atomic_unchecked_t mod_qp_timouts;
32848+atomic_unchecked_t qps_created;
32849+atomic_unchecked_t sw_qps_destroyed;
32850
32851 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32852
32853@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32854 if (init_attr->create_flags)
32855 return ERR_PTR(-EINVAL);
32856
32857- atomic_inc(&qps_created);
32858+ atomic_inc_unchecked(&qps_created);
32859 switch (init_attr->qp_type) {
32860 case IB_QPT_RC:
32861 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32862@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32863 struct iw_cm_event cm_event;
32864 int ret = 0;
32865
32866- atomic_inc(&sw_qps_destroyed);
32867+ atomic_inc_unchecked(&sw_qps_destroyed);
32868 nesqp->destroyed = 1;
32869
32870 /* Blow away the connection if it exists. */
32871diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32872index 7e62f41..4c2b8e2 100644
32873--- a/drivers/infiniband/hw/qib/qib.h
32874+++ b/drivers/infiniband/hw/qib/qib.h
32875@@ -51,6 +51,7 @@
32876 #include <linux/completion.h>
32877 #include <linux/kref.h>
32878 #include <linux/sched.h>
32879+#include <linux/slab.h>
32880
32881 #include "qib_common.h"
32882 #include "qib_verbs.h"
32883diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32884index da739d9..da1c7f4 100644
32885--- a/drivers/input/gameport/gameport.c
32886+++ b/drivers/input/gameport/gameport.c
32887@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32888 */
32889 static void gameport_init_port(struct gameport *gameport)
32890 {
32891- static atomic_t gameport_no = ATOMIC_INIT(0);
32892+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32893
32894 __module_get(THIS_MODULE);
32895
32896 mutex_init(&gameport->drv_mutex);
32897 device_initialize(&gameport->dev);
32898 dev_set_name(&gameport->dev, "gameport%lu",
32899- (unsigned long)atomic_inc_return(&gameport_no) - 1);
32900+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32901 gameport->dev.bus = &gameport_bus;
32902 gameport->dev.release = gameport_release_port;
32903 if (gameport->parent)
32904diff --git a/drivers/input/input.c b/drivers/input/input.c
32905index 8921c61..f5cd63d 100644
32906--- a/drivers/input/input.c
32907+++ b/drivers/input/input.c
32908@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32909 */
32910 int input_register_device(struct input_dev *dev)
32911 {
32912- static atomic_t input_no = ATOMIC_INIT(0);
32913+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32914 struct input_handler *handler;
32915 const char *path;
32916 int error;
32917@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32918 dev->setkeycode = input_default_setkeycode;
32919
32920 dev_set_name(&dev->dev, "input%ld",
32921- (unsigned long) atomic_inc_return(&input_no) - 1);
32922+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32923
32924 error = device_add(&dev->dev);
32925 if (error)
32926diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32927index 04c69af..5f92d00 100644
32928--- a/drivers/input/joystick/sidewinder.c
32929+++ b/drivers/input/joystick/sidewinder.c
32930@@ -30,6 +30,7 @@
32931 #include <linux/kernel.h>
32932 #include <linux/module.h>
32933 #include <linux/slab.h>
32934+#include <linux/sched.h>
32935 #include <linux/init.h>
32936 #include <linux/input.h>
32937 #include <linux/gameport.h>
32938diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32939index 83811e4..0822b90 100644
32940--- a/drivers/input/joystick/xpad.c
32941+++ b/drivers/input/joystick/xpad.c
32942@@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32943
32944 static int xpad_led_probe(struct usb_xpad *xpad)
32945 {
32946- static atomic_t led_seq = ATOMIC_INIT(0);
32947+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32948 long led_no;
32949 struct xpad_led *led;
32950 struct led_classdev *led_cdev;
32951@@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32952 if (!led)
32953 return -ENOMEM;
32954
32955- led_no = (long)atomic_inc_return(&led_seq) - 1;
32956+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32957
32958 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32959 led->xpad = xpad;
32960diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32961index 0110b5a..d3ad144 100644
32962--- a/drivers/input/mousedev.c
32963+++ b/drivers/input/mousedev.c
32964@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32965
32966 spin_unlock_irq(&client->packet_lock);
32967
32968- if (copy_to_user(buffer, data, count))
32969+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
32970 return -EFAULT;
32971
32972 return count;
32973diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32974index d0f7533..fb8215b 100644
32975--- a/drivers/input/serio/serio.c
32976+++ b/drivers/input/serio/serio.c
32977@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32978 */
32979 static void serio_init_port(struct serio *serio)
32980 {
32981- static atomic_t serio_no = ATOMIC_INIT(0);
32982+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32983
32984 __module_get(THIS_MODULE);
32985
32986@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32987 mutex_init(&serio->drv_mutex);
32988 device_initialize(&serio->dev);
32989 dev_set_name(&serio->dev, "serio%ld",
32990- (long)atomic_inc_return(&serio_no) - 1);
32991+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
32992 serio->dev.bus = &serio_bus;
32993 serio->dev.release = serio_release_port;
32994 serio->dev.groups = serio_device_attr_groups;
32995diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32996index 38c4bd8..58965d9 100644
32997--- a/drivers/isdn/capi/capi.c
32998+++ b/drivers/isdn/capi/capi.c
32999@@ -83,8 +83,8 @@ struct capiminor {
33000
33001 struct capi20_appl *ap;
33002 u32 ncci;
33003- atomic_t datahandle;
33004- atomic_t msgid;
33005+ atomic_unchecked_t datahandle;
33006+ atomic_unchecked_t msgid;
33007
33008 struct tty_port port;
33009 int ttyinstop;
33010@@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33011 capimsg_setu16(s, 2, mp->ap->applid);
33012 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33013 capimsg_setu8 (s, 5, CAPI_RESP);
33014- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33015+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33016 capimsg_setu32(s, 8, mp->ncci);
33017 capimsg_setu16(s, 12, datahandle);
33018 }
33019@@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33020 mp->outbytes -= len;
33021 spin_unlock_bh(&mp->outlock);
33022
33023- datahandle = atomic_inc_return(&mp->datahandle);
33024+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33025 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33026 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33027 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33028 capimsg_setu16(skb->data, 2, mp->ap->applid);
33029 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33030 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33031- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33032+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33033 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33034 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33035 capimsg_setu16(skb->data, 16, len); /* Data length */
33036diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33037index a6d9fd2..afdb8a3 100644
33038--- a/drivers/isdn/gigaset/interface.c
33039+++ b/drivers/isdn/gigaset/interface.c
33040@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33041 }
33042 tty->driver_data = cs;
33043
33044- ++cs->port.count;
33045+ atomic_inc(&cs->port.count);
33046
33047- if (cs->port.count == 1) {
33048+ if (atomic_read(&cs->port.count) == 1) {
33049 tty_port_tty_set(&cs->port, tty);
33050 tty->low_latency = 1;
33051 }
33052@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33053
33054 if (!cs->connected)
33055 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33056- else if (!cs->port.count)
33057+ else if (!atomic_read(&cs->port.count))
33058 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33059- else if (!--cs->port.count)
33060+ else if (!atomic_dec_return(&cs->port.count))
33061 tty_port_tty_set(&cs->port, NULL);
33062
33063 mutex_unlock(&cs->mutex);
33064diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33065index 821f7ac..28d4030 100644
33066--- a/drivers/isdn/hardware/avm/b1.c
33067+++ b/drivers/isdn/hardware/avm/b1.c
33068@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33069 }
33070 if (left) {
33071 if (t4file->user) {
33072- if (copy_from_user(buf, dp, left))
33073+ if (left > sizeof buf || copy_from_user(buf, dp, left))
33074 return -EFAULT;
33075 } else {
33076 memcpy(buf, dp, left);
33077@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33078 }
33079 if (left) {
33080 if (config->user) {
33081- if (copy_from_user(buf, dp, left))
33082+ if (left > sizeof buf || copy_from_user(buf, dp, left))
33083 return -EFAULT;
33084 } else {
33085 memcpy(buf, dp, left);
33086diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33087index dd6b53a..19d9ee6 100644
33088--- a/drivers/isdn/hardware/eicon/divasync.h
33089+++ b/drivers/isdn/hardware/eicon/divasync.h
33090@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33091 } diva_didd_add_adapter_t;
33092 typedef struct _diva_didd_remove_adapter {
33093 IDI_CALL p_request;
33094-} diva_didd_remove_adapter_t;
33095+} __no_const diva_didd_remove_adapter_t;
33096 typedef struct _diva_didd_read_adapter_array {
33097 void *buffer;
33098 dword length;
33099diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33100index d303e65..28bcb7b 100644
33101--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33102+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33103@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33104 typedef struct _diva_os_idi_adapter_interface {
33105 diva_init_card_proc_t cleanup_adapter_proc;
33106 diva_cmd_card_proc_t cmd_proc;
33107-} diva_os_idi_adapter_interface_t;
33108+} __no_const diva_os_idi_adapter_interface_t;
33109
33110 typedef struct _diva_os_xdi_adapter {
33111 struct list_head link;
33112diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33113index 7bc5067..fd36232 100644
33114--- a/drivers/isdn/i4l/isdn_tty.c
33115+++ b/drivers/isdn/i4l/isdn_tty.c
33116@@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33117 port = &info->port;
33118 #ifdef ISDN_DEBUG_MODEM_OPEN
33119 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33120- port->count);
33121+ atomic_read(&port->count))
33122 #endif
33123- port->count++;
33124+ atomic_inc(&port->count);
33125 tty->driver_data = info;
33126 port->tty = tty;
33127 tty->port = port;
33128@@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33129 #endif
33130 return;
33131 }
33132- if ((tty->count == 1) && (port->count != 1)) {
33133+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33134 /*
33135 * Uh, oh. tty->count is 1, which means that the tty
33136 * structure will be freed. Info->count should always
33137@@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33138 * serial port won't be shutdown.
33139 */
33140 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33141- "info->count is %d\n", port->count);
33142- port->count = 1;
33143+ "info->count is %d\n", atomic_read(&port->count));
33144+ atomic_set(&port->count, 1);
33145 }
33146- if (--port->count < 0) {
33147+ if (atomic_dec_return(&port->count) < 0) {
33148 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33149- info->line, port->count);
33150- port->count = 0;
33151+ info->line, atomic_read(&port->count));
33152+ atomic_set(&port->count, 0);
33153 }
33154- if (port->count) {
33155+ if (atomic_read(&port->count)) {
33156 #ifdef ISDN_DEBUG_MODEM_OPEN
33157 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33158 #endif
33159@@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33160 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33161 return;
33162 isdn_tty_shutdown(info);
33163- port->count = 0;
33164+ atomic_set(&port->count, 0);
33165 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33166 port->tty = NULL;
33167 wake_up_interruptible(&port->open_wait);
33168@@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33169 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33170 modem_info *info = &dev->mdm.info[i];
33171
33172- if (info->port.count == 0)
33173+ if (atomic_read(&info->port.count) == 0)
33174 continue;
33175 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33176 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33177diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33178index e74df7c..03a03ba 100644
33179--- a/drivers/isdn/icn/icn.c
33180+++ b/drivers/isdn/icn/icn.c
33181@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33182 if (count > len)
33183 count = len;
33184 if (user) {
33185- if (copy_from_user(msg, buf, count))
33186+ if (count > sizeof msg || copy_from_user(msg, buf, count))
33187 return -EFAULT;
33188 } else
33189 memcpy(msg, buf, count);
33190diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33191index b5fdcb7..5b6c59f 100644
33192--- a/drivers/lguest/core.c
33193+++ b/drivers/lguest/core.c
33194@@ -92,9 +92,17 @@ static __init int map_switcher(void)
33195 * it's worked so far. The end address needs +1 because __get_vm_area
33196 * allocates an extra guard page, so we need space for that.
33197 */
33198+
33199+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33200+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33201+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33202+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33203+#else
33204 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33205 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33206 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33207+#endif
33208+
33209 if (!switcher_vma) {
33210 err = -ENOMEM;
33211 printk("lguest: could not map switcher pages high\n");
33212@@ -119,7 +127,7 @@ static __init int map_switcher(void)
33213 * Now the Switcher is mapped at the right address, we can't fail!
33214 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33215 */
33216- memcpy(switcher_vma->addr, start_switcher_text,
33217+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33218 end_switcher_text - start_switcher_text);
33219
33220 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33221diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33222index 39809035..ce25c5e 100644
33223--- a/drivers/lguest/x86/core.c
33224+++ b/drivers/lguest/x86/core.c
33225@@ -59,7 +59,7 @@ static struct {
33226 /* Offset from where switcher.S was compiled to where we've copied it */
33227 static unsigned long switcher_offset(void)
33228 {
33229- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33230+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33231 }
33232
33233 /* This cpu's struct lguest_pages. */
33234@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33235 * These copies are pretty cheap, so we do them unconditionally: */
33236 /* Save the current Host top-level page directory.
33237 */
33238+
33239+#ifdef CONFIG_PAX_PER_CPU_PGD
33240+ pages->state.host_cr3 = read_cr3();
33241+#else
33242 pages->state.host_cr3 = __pa(current->mm->pgd);
33243+#endif
33244+
33245 /*
33246 * Set up the Guest's page tables to see this CPU's pages (and no
33247 * other CPU's pages).
33248@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33249 * compiled-in switcher code and the high-mapped copy we just made.
33250 */
33251 for (i = 0; i < IDT_ENTRIES; i++)
33252- default_idt_entries[i] += switcher_offset();
33253+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33254
33255 /*
33256 * Set up the Switcher's per-cpu areas.
33257@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33258 * it will be undisturbed when we switch. To change %cs and jump we
33259 * need this structure to feed to Intel's "lcall" instruction.
33260 */
33261- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33262+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33263 lguest_entry.segment = LGUEST_CS;
33264
33265 /*
33266diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33267index 40634b0..4f5855e 100644
33268--- a/drivers/lguest/x86/switcher_32.S
33269+++ b/drivers/lguest/x86/switcher_32.S
33270@@ -87,6 +87,7 @@
33271 #include <asm/page.h>
33272 #include <asm/segment.h>
33273 #include <asm/lguest.h>
33274+#include <asm/processor-flags.h>
33275
33276 // We mark the start of the code to copy
33277 // It's placed in .text tho it's never run here
33278@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33279 // Changes type when we load it: damn Intel!
33280 // For after we switch over our page tables
33281 // That entry will be read-only: we'd crash.
33282+
33283+#ifdef CONFIG_PAX_KERNEXEC
33284+ mov %cr0, %edx
33285+ xor $X86_CR0_WP, %edx
33286+ mov %edx, %cr0
33287+#endif
33288+
33289 movl $(GDT_ENTRY_TSS*8), %edx
33290 ltr %dx
33291
33292@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33293 // Let's clear it again for our return.
33294 // The GDT descriptor of the Host
33295 // Points to the table after two "size" bytes
33296- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33297+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33298 // Clear "used" from type field (byte 5, bit 2)
33299- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33300+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33301+
33302+#ifdef CONFIG_PAX_KERNEXEC
33303+ mov %cr0, %eax
33304+ xor $X86_CR0_WP, %eax
33305+ mov %eax, %cr0
33306+#endif
33307
33308 // Once our page table's switched, the Guest is live!
33309 // The Host fades as we run this final step.
33310@@ -295,13 +309,12 @@ deliver_to_host:
33311 // I consulted gcc, and it gave
33312 // These instructions, which I gladly credit:
33313 leal (%edx,%ebx,8), %eax
33314- movzwl (%eax),%edx
33315- movl 4(%eax), %eax
33316- xorw %ax, %ax
33317- orl %eax, %edx
33318+ movl 4(%eax), %edx
33319+ movw (%eax), %dx
33320 // Now the address of the handler's in %edx
33321 // We call it now: its "iret" drops us home.
33322- jmp *%edx
33323+ ljmp $__KERNEL_CS, $1f
33324+1: jmp *%edx
33325
33326 // Every interrupt can come to us here
33327 // But we must truly tell each apart.
33328diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33329index 20e5c2c..9e849a9 100644
33330--- a/drivers/macintosh/macio_asic.c
33331+++ b/drivers/macintosh/macio_asic.c
33332@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33333 * MacIO is matched against any Apple ID, it's probe() function
33334 * will then decide wether it applies or not
33335 */
33336-static const struct pci_device_id __devinitdata pci_ids [] = { {
33337+static const struct pci_device_id __devinitconst pci_ids [] = { {
33338 .vendor = PCI_VENDOR_ID_APPLE,
33339 .device = PCI_ANY_ID,
33340 .subvendor = PCI_ANY_ID,
33341diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33342index 15dbe03..743fc65 100644
33343--- a/drivers/md/bitmap.c
33344+++ b/drivers/md/bitmap.c
33345@@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33346 chunk_kb ? "KB" : "B");
33347 if (bitmap->storage.file) {
33348 seq_printf(seq, ", file: ");
33349- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33350+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33351 }
33352
33353 seq_printf(seq, "\n");
33354diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33355index a1a3e6d..1918bfc 100644
33356--- a/drivers/md/dm-ioctl.c
33357+++ b/drivers/md/dm-ioctl.c
33358@@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33359 cmd == DM_LIST_VERSIONS_CMD)
33360 return 0;
33361
33362- if ((cmd == DM_DEV_CREATE_CMD)) {
33363+ if (cmd == DM_DEV_CREATE_CMD) {
33364 if (!*param->name) {
33365 DMWARN("name not supplied when creating device");
33366 return -EINVAL;
33367diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33368index b58b7a3..8018b19 100644
33369--- a/drivers/md/dm-raid1.c
33370+++ b/drivers/md/dm-raid1.c
33371@@ -40,7 +40,7 @@ enum dm_raid1_error {
33372
33373 struct mirror {
33374 struct mirror_set *ms;
33375- atomic_t error_count;
33376+ atomic_unchecked_t error_count;
33377 unsigned long error_type;
33378 struct dm_dev *dev;
33379 sector_t offset;
33380@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33381 struct mirror *m;
33382
33383 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33384- if (!atomic_read(&m->error_count))
33385+ if (!atomic_read_unchecked(&m->error_count))
33386 return m;
33387
33388 return NULL;
33389@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33390 * simple way to tell if a device has encountered
33391 * errors.
33392 */
33393- atomic_inc(&m->error_count);
33394+ atomic_inc_unchecked(&m->error_count);
33395
33396 if (test_and_set_bit(error_type, &m->error_type))
33397 return;
33398@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33399 struct mirror *m = get_default_mirror(ms);
33400
33401 do {
33402- if (likely(!atomic_read(&m->error_count)))
33403+ if (likely(!atomic_read_unchecked(&m->error_count)))
33404 return m;
33405
33406 if (m-- == ms->mirror)
33407@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33408 {
33409 struct mirror *default_mirror = get_default_mirror(m->ms);
33410
33411- return !atomic_read(&default_mirror->error_count);
33412+ return !atomic_read_unchecked(&default_mirror->error_count);
33413 }
33414
33415 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33416@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33417 */
33418 if (likely(region_in_sync(ms, region, 1)))
33419 m = choose_mirror(ms, bio->bi_sector);
33420- else if (m && atomic_read(&m->error_count))
33421+ else if (m && atomic_read_unchecked(&m->error_count))
33422 m = NULL;
33423
33424 if (likely(m))
33425@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33426 }
33427
33428 ms->mirror[mirror].ms = ms;
33429- atomic_set(&(ms->mirror[mirror].error_count), 0);
33430+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33431 ms->mirror[mirror].error_type = 0;
33432 ms->mirror[mirror].offset = offset;
33433
33434@@ -1352,7 +1352,7 @@ static void mirror_resume(struct dm_target *ti)
33435 */
33436 static char device_status_char(struct mirror *m)
33437 {
33438- if (!atomic_read(&(m->error_count)))
33439+ if (!atomic_read_unchecked(&(m->error_count)))
33440 return 'A';
33441
33442 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33443diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33444index 35c94ff..20d4c17 100644
33445--- a/drivers/md/dm-stripe.c
33446+++ b/drivers/md/dm-stripe.c
33447@@ -20,7 +20,7 @@ struct stripe {
33448 struct dm_dev *dev;
33449 sector_t physical_start;
33450
33451- atomic_t error_count;
33452+ atomic_unchecked_t error_count;
33453 };
33454
33455 struct stripe_c {
33456@@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33457 kfree(sc);
33458 return r;
33459 }
33460- atomic_set(&(sc->stripe[i].error_count), 0);
33461+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33462 }
33463
33464 ti->private = sc;
33465@@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33466 DMEMIT("%d ", sc->stripes);
33467 for (i = 0; i < sc->stripes; i++) {
33468 DMEMIT("%s ", sc->stripe[i].dev->name);
33469- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33470+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33471 'D' : 'A';
33472 }
33473 buffer[i] = '\0';
33474@@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33475 */
33476 for (i = 0; i < sc->stripes; i++)
33477 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33478- atomic_inc(&(sc->stripe[i].error_count));
33479- if (atomic_read(&(sc->stripe[i].error_count)) <
33480+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33481+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33482 DM_IO_ERROR_THRESHOLD)
33483 schedule_work(&sc->trigger_event);
33484 }
33485diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33486index f220a69..512fd1c 100644
33487--- a/drivers/md/dm-table.c
33488+++ b/drivers/md/dm-table.c
33489@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33490 if (!dev_size)
33491 return 0;
33492
33493- if ((start >= dev_size) || (start + len > dev_size)) {
33494+ if ((start >= dev_size) || (len > dev_size - start)) {
33495 DMWARN("%s: %s too small for target: "
33496 "start=%llu, len=%llu, dev_size=%llu",
33497 dm_device_name(ti->table->md), bdevname(bdev, b),
33498diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33499index 3e2907f..c28851a 100644
33500--- a/drivers/md/dm-thin-metadata.c
33501+++ b/drivers/md/dm-thin-metadata.c
33502@@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33503
33504 pmd->info.tm = tm;
33505 pmd->info.levels = 2;
33506- pmd->info.value_type.context = pmd->data_sm;
33507+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33508 pmd->info.value_type.size = sizeof(__le64);
33509 pmd->info.value_type.inc = data_block_inc;
33510 pmd->info.value_type.dec = data_block_dec;
33511@@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33512
33513 pmd->bl_info.tm = tm;
33514 pmd->bl_info.levels = 1;
33515- pmd->bl_info.value_type.context = pmd->data_sm;
33516+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33517 pmd->bl_info.value_type.size = sizeof(__le64);
33518 pmd->bl_info.value_type.inc = data_block_inc;
33519 pmd->bl_info.value_type.dec = data_block_dec;
33520diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33521index 9ff3019..c119fde 100644
33522--- a/drivers/md/dm.c
33523+++ b/drivers/md/dm.c
33524@@ -176,9 +176,9 @@ struct mapped_device {
33525 /*
33526 * Event handling.
33527 */
33528- atomic_t event_nr;
33529+ atomic_unchecked_t event_nr;
33530 wait_queue_head_t eventq;
33531- atomic_t uevent_seq;
33532+ atomic_unchecked_t uevent_seq;
33533 struct list_head uevent_list;
33534 spinlock_t uevent_lock; /* Protect access to uevent_list */
33535
33536@@ -1865,8 +1865,8 @@ static struct mapped_device *alloc_dev(int minor)
33537 rwlock_init(&md->map_lock);
33538 atomic_set(&md->holders, 1);
33539 atomic_set(&md->open_count, 0);
33540- atomic_set(&md->event_nr, 0);
33541- atomic_set(&md->uevent_seq, 0);
33542+ atomic_set_unchecked(&md->event_nr, 0);
33543+ atomic_set_unchecked(&md->uevent_seq, 0);
33544 INIT_LIST_HEAD(&md->uevent_list);
33545 spin_lock_init(&md->uevent_lock);
33546
33547@@ -2000,7 +2000,7 @@ static void event_callback(void *context)
33548
33549 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33550
33551- atomic_inc(&md->event_nr);
33552+ atomic_inc_unchecked(&md->event_nr);
33553 wake_up(&md->eventq);
33554 }
33555
33556@@ -2642,18 +2642,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33557
33558 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33559 {
33560- return atomic_add_return(1, &md->uevent_seq);
33561+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33562 }
33563
33564 uint32_t dm_get_event_nr(struct mapped_device *md)
33565 {
33566- return atomic_read(&md->event_nr);
33567+ return atomic_read_unchecked(&md->event_nr);
33568 }
33569
33570 int dm_wait_event(struct mapped_device *md, int event_nr)
33571 {
33572 return wait_event_interruptible(md->eventq,
33573- (event_nr != atomic_read(&md->event_nr)));
33574+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33575 }
33576
33577 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33578diff --git a/drivers/md/md.c b/drivers/md/md.c
33579index 6fc0c26..0c864b6 100644
33580--- a/drivers/md/md.c
33581+++ b/drivers/md/md.c
33582@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33583 * start build, activate spare
33584 */
33585 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33586-static atomic_t md_event_count;
33587+static atomic_unchecked_t md_event_count;
33588 void md_new_event(struct mddev *mddev)
33589 {
33590- atomic_inc(&md_event_count);
33591+ atomic_inc_unchecked(&md_event_count);
33592 wake_up(&md_event_waiters);
33593 }
33594 EXPORT_SYMBOL_GPL(md_new_event);
33595@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33596 */
33597 static void md_new_event_inintr(struct mddev *mddev)
33598 {
33599- atomic_inc(&md_event_count);
33600+ atomic_inc_unchecked(&md_event_count);
33601 wake_up(&md_event_waiters);
33602 }
33603
33604@@ -1568,7 +1568,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33605 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33606 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33607 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33608- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33609+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33610
33611 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33612 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33613@@ -1812,7 +1812,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33614 else
33615 sb->resync_offset = cpu_to_le64(0);
33616
33617- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33618+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33619
33620 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33621 sb->size = cpu_to_le64(mddev->dev_sectors);
33622@@ -2806,7 +2806,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33623 static ssize_t
33624 errors_show(struct md_rdev *rdev, char *page)
33625 {
33626- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33627+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33628 }
33629
33630 static ssize_t
33631@@ -2815,7 +2815,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33632 char *e;
33633 unsigned long n = simple_strtoul(buf, &e, 10);
33634 if (*buf && (*e == 0 || *e == '\n')) {
33635- atomic_set(&rdev->corrected_errors, n);
33636+ atomic_set_unchecked(&rdev->corrected_errors, n);
33637 return len;
33638 }
33639 return -EINVAL;
33640@@ -3262,8 +3262,8 @@ int md_rdev_init(struct md_rdev *rdev)
33641 rdev->sb_loaded = 0;
33642 rdev->bb_page = NULL;
33643 atomic_set(&rdev->nr_pending, 0);
33644- atomic_set(&rdev->read_errors, 0);
33645- atomic_set(&rdev->corrected_errors, 0);
33646+ atomic_set_unchecked(&rdev->read_errors, 0);
33647+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33648
33649 INIT_LIST_HEAD(&rdev->same_set);
33650 init_waitqueue_head(&rdev->blocked_wait);
33651@@ -7000,7 +7000,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33652
33653 spin_unlock(&pers_lock);
33654 seq_printf(seq, "\n");
33655- seq->poll_event = atomic_read(&md_event_count);
33656+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33657 return 0;
33658 }
33659 if (v == (void*)2) {
33660@@ -7103,7 +7103,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33661 return error;
33662
33663 seq = file->private_data;
33664- seq->poll_event = atomic_read(&md_event_count);
33665+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33666 return error;
33667 }
33668
33669@@ -7117,7 +7117,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33670 /* always allow read */
33671 mask = POLLIN | POLLRDNORM;
33672
33673- if (seq->poll_event != atomic_read(&md_event_count))
33674+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33675 mask |= POLLERR | POLLPRI;
33676 return mask;
33677 }
33678@@ -7161,7 +7161,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33679 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33680 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33681 (int)part_stat_read(&disk->part0, sectors[1]) -
33682- atomic_read(&disk->sync_io);
33683+ atomic_read_unchecked(&disk->sync_io);
33684 /* sync IO will cause sync_io to increase before the disk_stats
33685 * as sync_io is counted when a request starts, and
33686 * disk_stats is counted when it completes.
33687diff --git a/drivers/md/md.h b/drivers/md/md.h
33688index 7b4a3c3..994ad4f 100644
33689--- a/drivers/md/md.h
33690+++ b/drivers/md/md.h
33691@@ -94,13 +94,13 @@ struct md_rdev {
33692 * only maintained for arrays that
33693 * support hot removal
33694 */
33695- atomic_t read_errors; /* number of consecutive read errors that
33696+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
33697 * we have tried to ignore.
33698 */
33699 struct timespec last_read_error; /* monotonic time since our
33700 * last read error
33701 */
33702- atomic_t corrected_errors; /* number of corrected read errors,
33703+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33704 * for reporting to userspace and storing
33705 * in superblock.
33706 */
33707@@ -435,7 +435,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33708
33709 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33710 {
33711- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33712+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33713 }
33714
33715 struct md_personality
33716diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33717index fc90c11..c8cd9a9 100644
33718--- a/drivers/md/persistent-data/dm-space-map-checker.c
33719+++ b/drivers/md/persistent-data/dm-space-map-checker.c
33720@@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33721 /*----------------------------------------------------------------*/
33722
33723 struct sm_checker {
33724- struct dm_space_map sm;
33725+ dm_space_map_no_const sm;
33726
33727 struct count_array old_counts;
33728 struct count_array counts;
33729diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33730index 3d0ed53..35dc592 100644
33731--- a/drivers/md/persistent-data/dm-space-map-disk.c
33732+++ b/drivers/md/persistent-data/dm-space-map-disk.c
33733@@ -23,7 +23,7 @@
33734 * Space map interface.
33735 */
33736 struct sm_disk {
33737- struct dm_space_map sm;
33738+ dm_space_map_no_const sm;
33739
33740 struct ll_disk ll;
33741 struct ll_disk old_ll;
33742diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33743index e89ae5e..062e4c2 100644
33744--- a/drivers/md/persistent-data/dm-space-map-metadata.c
33745+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33746@@ -43,7 +43,7 @@ struct block_op {
33747 };
33748
33749 struct sm_metadata {
33750- struct dm_space_map sm;
33751+ dm_space_map_no_const sm;
33752
33753 struct ll_disk ll;
33754 struct ll_disk old_ll;
33755diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33756index 1cbfc6b..56e1dbb 100644
33757--- a/drivers/md/persistent-data/dm-space-map.h
33758+++ b/drivers/md/persistent-data/dm-space-map.h
33759@@ -60,6 +60,7 @@ struct dm_space_map {
33760 int (*root_size)(struct dm_space_map *sm, size_t *result);
33761 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33762 };
33763+typedef struct dm_space_map __no_const dm_space_map_no_const;
33764
33765 /*----------------------------------------------------------------*/
33766
33767diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33768index 53aec45..250851c 100644
33769--- a/drivers/md/raid1.c
33770+++ b/drivers/md/raid1.c
33771@@ -1685,7 +1685,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33772 if (r1_sync_page_io(rdev, sect, s,
33773 bio->bi_io_vec[idx].bv_page,
33774 READ) != 0)
33775- atomic_add(s, &rdev->corrected_errors);
33776+ atomic_add_unchecked(s, &rdev->corrected_errors);
33777 }
33778 sectors -= s;
33779 sect += s;
33780@@ -1907,7 +1907,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33781 test_bit(In_sync, &rdev->flags)) {
33782 if (r1_sync_page_io(rdev, sect, s,
33783 conf->tmppage, READ)) {
33784- atomic_add(s, &rdev->corrected_errors);
33785+ atomic_add_unchecked(s, &rdev->corrected_errors);
33786 printk(KERN_INFO
33787 "md/raid1:%s: read error corrected "
33788 "(%d sectors at %llu on %s)\n",
33789diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33790index e987da4..83649e4 100644
33791--- a/drivers/md/raid10.c
33792+++ b/drivers/md/raid10.c
33793@@ -1790,7 +1790,7 @@ static void end_sync_read(struct bio *bio, int error)
33794 /* The write handler will notice the lack of
33795 * R10BIO_Uptodate and record any errors etc
33796 */
33797- atomic_add(r10_bio->sectors,
33798+ atomic_add_unchecked(r10_bio->sectors,
33799 &conf->mirrors[d].rdev->corrected_errors);
33800
33801 /* for reconstruct, we always reschedule after a read.
33802@@ -2139,7 +2139,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33803 {
33804 struct timespec cur_time_mon;
33805 unsigned long hours_since_last;
33806- unsigned int read_errors = atomic_read(&rdev->read_errors);
33807+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33808
33809 ktime_get_ts(&cur_time_mon);
33810
33811@@ -2161,9 +2161,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33812 * overflowing the shift of read_errors by hours_since_last.
33813 */
33814 if (hours_since_last >= 8 * sizeof(read_errors))
33815- atomic_set(&rdev->read_errors, 0);
33816+ atomic_set_unchecked(&rdev->read_errors, 0);
33817 else
33818- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33819+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33820 }
33821
33822 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33823@@ -2217,8 +2217,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33824 return;
33825
33826 check_decay_read_errors(mddev, rdev);
33827- atomic_inc(&rdev->read_errors);
33828- if (atomic_read(&rdev->read_errors) > max_read_errors) {
33829+ atomic_inc_unchecked(&rdev->read_errors);
33830+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33831 char b[BDEVNAME_SIZE];
33832 bdevname(rdev->bdev, b);
33833
33834@@ -2226,7 +2226,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33835 "md/raid10:%s: %s: Raid device exceeded "
33836 "read_error threshold [cur %d:max %d]\n",
33837 mdname(mddev), b,
33838- atomic_read(&rdev->read_errors), max_read_errors);
33839+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33840 printk(KERN_NOTICE
33841 "md/raid10:%s: %s: Failing raid device\n",
33842 mdname(mddev), b);
33843@@ -2381,7 +2381,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33844 sect +
33845 choose_data_offset(r10_bio, rdev)),
33846 bdevname(rdev->bdev, b));
33847- atomic_add(s, &rdev->corrected_errors);
33848+ atomic_add_unchecked(s, &rdev->corrected_errors);
33849 }
33850
33851 rdev_dec_pending(rdev, mddev);
33852diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33853index bcd096b..c24f08f 100644
33854--- a/drivers/md/raid5.c
33855+++ b/drivers/md/raid5.c
33856@@ -1740,19 +1740,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
33857 mdname(conf->mddev), STRIPE_SECTORS,
33858 (unsigned long long)s,
33859 bdevname(rdev->bdev, b));
33860- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33861+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33862 clear_bit(R5_ReadError, &sh->dev[i].flags);
33863 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33864 }
33865- if (atomic_read(&rdev->read_errors))
33866- atomic_set(&rdev->read_errors, 0);
33867+ if (atomic_read_unchecked(&rdev->read_errors))
33868+ atomic_set_unchecked(&rdev->read_errors, 0);
33869 } else {
33870 const char *bdn = bdevname(rdev->bdev, b);
33871 int retry = 0;
33872 int set_bad = 0;
33873
33874 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33875- atomic_inc(&rdev->read_errors);
33876+ atomic_inc_unchecked(&rdev->read_errors);
33877 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33878 printk_ratelimited(
33879 KERN_WARNING
33880@@ -1780,7 +1780,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33881 mdname(conf->mddev),
33882 (unsigned long long)s,
33883 bdn);
33884- } else if (atomic_read(&rdev->read_errors)
33885+ } else if (atomic_read_unchecked(&rdev->read_errors)
33886 > conf->max_nr_stripes)
33887 printk(KERN_WARNING
33888 "md/raid:%s: Too many read errors, failing device %s.\n",
33889diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33890index 131b938..8572ed1 100644
33891--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33892+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33893@@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33894 .subvendor = _subvend, .subdevice = _subdev, \
33895 .driver_data = (unsigned long)&_driverdata }
33896
33897-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33898+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33899 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33900 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33901 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33902diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33903index fa7188a..04a045e 100644
33904--- a/drivers/media/dvb/dvb-core/dvb_demux.h
33905+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33906@@ -73,7 +73,7 @@ struct dvb_demux_feed {
33907 union {
33908 dmx_ts_cb ts;
33909 dmx_section_cb sec;
33910- } cb;
33911+ } __no_const cb;
33912
33913 struct dvb_demux *demux;
33914 void *priv;
33915diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33916index 39eab73..60033e7 100644
33917--- a/drivers/media/dvb/dvb-core/dvbdev.c
33918+++ b/drivers/media/dvb/dvb-core/dvbdev.c
33919@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33920 const struct dvb_device *template, void *priv, int type)
33921 {
33922 struct dvb_device *dvbdev;
33923- struct file_operations *dvbdevfops;
33924+ file_operations_no_const *dvbdevfops;
33925 struct device *clsdev;
33926 int minor;
33927 int id;
33928diff --git a/drivers/media/dvb/dvb-usb/az6007.c b/drivers/media/dvb/dvb-usb/az6007.c
33929index 4008b9c..ce714f5 100644
33930--- a/drivers/media/dvb/dvb-usb/az6007.c
33931+++ b/drivers/media/dvb/dvb-usb/az6007.c
33932@@ -590,7 +590,7 @@ static int az6007_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
33933 int ret;
33934
33935 ret = az6007_read(d, AZ6007_READ_DATA, 6, 0, st->data, 6);
33936- memcpy(mac, st->data, sizeof(mac));
33937+ memcpy(mac, st->data, 6);
33938
33939 if (ret > 0)
33940 deb_info("%s: mac is %02x:%02x:%02x:%02x:%02x:%02x\n",
33941diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33942index 3940bb0..fb3952a 100644
33943--- a/drivers/media/dvb/dvb-usb/cxusb.c
33944+++ b/drivers/media/dvb/dvb-usb/cxusb.c
33945@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33946
33947 struct dib0700_adapter_state {
33948 int (*set_param_save) (struct dvb_frontend *);
33949-};
33950+} __no_const;
33951
33952 static int dib7070_set_param_override(struct dvb_frontend *fe)
33953 {
33954diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33955index 9382895..ac8093c 100644
33956--- a/drivers/media/dvb/dvb-usb/dw2102.c
33957+++ b/drivers/media/dvb/dvb-usb/dw2102.c
33958@@ -95,7 +95,7 @@ struct su3000_state {
33959
33960 struct s6x0_state {
33961 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33962-};
33963+} __no_const;
33964
33965 /* debug */
33966 static int dvb_usb_dw2102_debug;
33967diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33968index 404f63a..4796533 100644
33969--- a/drivers/media/dvb/frontends/dib3000.h
33970+++ b/drivers/media/dvb/frontends/dib3000.h
33971@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33972 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33973 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33974 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33975-};
33976+} __no_const;
33977
33978 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33979 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33980diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33981index 7539a5d..06531a6 100644
33982--- a/drivers/media/dvb/ngene/ngene-cards.c
33983+++ b/drivers/media/dvb/ngene/ngene-cards.c
33984@@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33985
33986 /****************************************************************************/
33987
33988-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33989+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33990 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33991 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33992 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33993diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33994index 16a089f..1661b11 100644
33995--- a/drivers/media/radio/radio-cadet.c
33996+++ b/drivers/media/radio/radio-cadet.c
33997@@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33998 unsigned char readbuf[RDS_BUFFER];
33999 int i = 0;
34000
34001+ if (count > RDS_BUFFER)
34002+ return -EFAULT;
34003 mutex_lock(&dev->lock);
34004 if (dev->rdsstat == 0) {
34005 dev->rdsstat = 1;
34006@@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34007 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34008 mutex_unlock(&dev->lock);
34009
34010- if (copy_to_user(data, readbuf, i))
34011+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34012 return -EFAULT;
34013 return i;
34014 }
34015diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34016index 9cde353..8c6a1c3 100644
34017--- a/drivers/media/video/au0828/au0828.h
34018+++ b/drivers/media/video/au0828/au0828.h
34019@@ -191,7 +191,7 @@ struct au0828_dev {
34020
34021 /* I2C */
34022 struct i2c_adapter i2c_adap;
34023- struct i2c_algorithm i2c_algo;
34024+ i2c_algorithm_no_const i2c_algo;
34025 struct i2c_client i2c_client;
34026 u32 i2c_rc;
34027
34028diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34029index 04bf662..e0ac026 100644
34030--- a/drivers/media/video/cx88/cx88-alsa.c
34031+++ b/drivers/media/video/cx88/cx88-alsa.c
34032@@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34033 * Only boards with eeprom and byte 1 at eeprom=1 have it
34034 */
34035
34036-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34037+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34038 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34039 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34040 {0, }
34041diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34042index 88cf9d9..bbc4b2c 100644
34043--- a/drivers/media/video/omap/omap_vout.c
34044+++ b/drivers/media/video/omap/omap_vout.c
34045@@ -64,7 +64,6 @@ enum omap_vout_channels {
34046 OMAP_VIDEO2,
34047 };
34048
34049-static struct videobuf_queue_ops video_vbq_ops;
34050 /* Variables configurable through module params*/
34051 static u32 video1_numbuffers = 3;
34052 static u32 video2_numbuffers = 3;
34053@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34054 {
34055 struct videobuf_queue *q;
34056 struct omap_vout_device *vout = NULL;
34057+ static struct videobuf_queue_ops video_vbq_ops = {
34058+ .buf_setup = omap_vout_buffer_setup,
34059+ .buf_prepare = omap_vout_buffer_prepare,
34060+ .buf_release = omap_vout_buffer_release,
34061+ .buf_queue = omap_vout_buffer_queue,
34062+ };
34063
34064 vout = video_drvdata(file);
34065 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34066@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34067 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34068
34069 q = &vout->vbq;
34070- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34071- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34072- video_vbq_ops.buf_release = omap_vout_buffer_release;
34073- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34074 spin_lock_init(&vout->vbq_lock);
34075
34076 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34077diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34078index 036952f..80d356d 100644
34079--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34080+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34081@@ -196,7 +196,7 @@ struct pvr2_hdw {
34082
34083 /* I2C stuff */
34084 struct i2c_adapter i2c_adap;
34085- struct i2c_algorithm i2c_algo;
34086+ i2c_algorithm_no_const i2c_algo;
34087 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34088 int i2c_cx25840_hack_state;
34089 int i2c_linked;
34090diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34091index 02194c0..091733b 100644
34092--- a/drivers/media/video/timblogiw.c
34093+++ b/drivers/media/video/timblogiw.c
34094@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34095
34096 /* Platform device functions */
34097
34098-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34099+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34100 .vidioc_querycap = timblogiw_querycap,
34101 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34102 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34103@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34104 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34105 };
34106
34107-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34108+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34109 .owner = THIS_MODULE,
34110 .open = timblogiw_open,
34111 .release = timblogiw_close,
34112diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34113index d99db56..a16b959 100644
34114--- a/drivers/message/fusion/mptbase.c
34115+++ b/drivers/message/fusion/mptbase.c
34116@@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34117 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34118 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34119
34120+#ifdef CONFIG_GRKERNSEC_HIDESYM
34121+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34122+#else
34123 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34124 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34125+#endif
34126+
34127 /*
34128 * Rounding UP to nearest 4-kB boundary here...
34129 */
34130diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34131index 551262e..7551198 100644
34132--- a/drivers/message/fusion/mptsas.c
34133+++ b/drivers/message/fusion/mptsas.c
34134@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34135 return 0;
34136 }
34137
34138+static inline void
34139+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34140+{
34141+ if (phy_info->port_details) {
34142+ phy_info->port_details->rphy = rphy;
34143+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34144+ ioc->name, rphy));
34145+ }
34146+
34147+ if (rphy) {
34148+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34149+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34150+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34151+ ioc->name, rphy, rphy->dev.release));
34152+ }
34153+}
34154+
34155 /* no mutex */
34156 static void
34157 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34158@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34159 return NULL;
34160 }
34161
34162-static inline void
34163-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34164-{
34165- if (phy_info->port_details) {
34166- phy_info->port_details->rphy = rphy;
34167- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34168- ioc->name, rphy));
34169- }
34170-
34171- if (rphy) {
34172- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34173- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34174- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34175- ioc->name, rphy, rphy->dev.release));
34176- }
34177-}
34178-
34179 static inline struct sas_port *
34180 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34181 {
34182diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34183index 0c3ced7..1fe34ec 100644
34184--- a/drivers/message/fusion/mptscsih.c
34185+++ b/drivers/message/fusion/mptscsih.c
34186@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34187
34188 h = shost_priv(SChost);
34189
34190- if (h) {
34191- if (h->info_kbuf == NULL)
34192- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34193- return h->info_kbuf;
34194- h->info_kbuf[0] = '\0';
34195+ if (!h)
34196+ return NULL;
34197
34198- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34199- h->info_kbuf[size-1] = '\0';
34200- }
34201+ if (h->info_kbuf == NULL)
34202+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34203+ return h->info_kbuf;
34204+ h->info_kbuf[0] = '\0';
34205+
34206+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34207+ h->info_kbuf[size-1] = '\0';
34208
34209 return h->info_kbuf;
34210 }
34211diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34212index 506c36f..b137580 100644
34213--- a/drivers/message/i2o/i2o_proc.c
34214+++ b/drivers/message/i2o/i2o_proc.c
34215@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34216 "Array Controller Device"
34217 };
34218
34219-static char *chtostr(u8 * chars, int n)
34220-{
34221- char tmp[256];
34222- tmp[0] = 0;
34223- return strncat(tmp, (char *)chars, n);
34224-}
34225-
34226 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34227 char *group)
34228 {
34229@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34230
34231 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34232 seq_printf(seq, "%-#8x", ddm_table.module_id);
34233- seq_printf(seq, "%-29s",
34234- chtostr(ddm_table.module_name_version, 28));
34235+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34236 seq_printf(seq, "%9d ", ddm_table.data_size);
34237 seq_printf(seq, "%8d", ddm_table.code_size);
34238
34239@@ -927,8 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34240
34241 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34242 seq_printf(seq, "%-#8x", dst->module_id);
34243- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34244- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34245+ seq_printf(seq, "%-.28s", dst->module_name_version);
34246+ seq_printf(seq, "%-.8s", dst->date);
34247 seq_printf(seq, "%8d ", dst->module_size);
34248 seq_printf(seq, "%8d ", dst->mpb_size);
34249 seq_printf(seq, "0x%04x", dst->module_flags);
34250@@ -1259,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34251 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34252 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34253 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34254- seq_printf(seq, "Vendor info : %s\n",
34255- chtostr((u8 *) (work32 + 2), 16));
34256- seq_printf(seq, "Product info : %s\n",
34257- chtostr((u8 *) (work32 + 6), 16));
34258- seq_printf(seq, "Description : %s\n",
34259- chtostr((u8 *) (work32 + 10), 16));
34260- seq_printf(seq, "Product rev. : %s\n",
34261- chtostr((u8 *) (work32 + 14), 8));
34262+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34263+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34264+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34265+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34266
34267 seq_printf(seq, "Serial number : ");
34268 print_serial_number(seq, (u8 *) (work32 + 16),
34269@@ -1311,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34270 }
34271
34272 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34273- seq_printf(seq, "Module name : %s\n",
34274- chtostr(result.module_name, 24));
34275- seq_printf(seq, "Module revision : %s\n",
34276- chtostr(result.module_rev, 8));
34277+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
34278+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34279
34280 seq_printf(seq, "Serial number : ");
34281 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34282@@ -1345,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34283 return 0;
34284 }
34285
34286- seq_printf(seq, "Device name : %s\n",
34287- chtostr(result.device_name, 64));
34288- seq_printf(seq, "Service name : %s\n",
34289- chtostr(result.service_name, 64));
34290- seq_printf(seq, "Physical name : %s\n",
34291- chtostr(result.physical_location, 64));
34292- seq_printf(seq, "Instance number : %s\n",
34293- chtostr(result.instance_number, 4));
34294+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34295+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34296+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34297+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34298
34299 return 0;
34300 }
34301diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34302index a8c08f3..155fe3d 100644
34303--- a/drivers/message/i2o/iop.c
34304+++ b/drivers/message/i2o/iop.c
34305@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34306
34307 spin_lock_irqsave(&c->context_list_lock, flags);
34308
34309- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34310- atomic_inc(&c->context_list_counter);
34311+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34312+ atomic_inc_unchecked(&c->context_list_counter);
34313
34314- entry->context = atomic_read(&c->context_list_counter);
34315+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34316
34317 list_add(&entry->list, &c->context_list);
34318
34319@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34320
34321 #if BITS_PER_LONG == 64
34322 spin_lock_init(&c->context_list_lock);
34323- atomic_set(&c->context_list_counter, 0);
34324+ atomic_set_unchecked(&c->context_list_counter, 0);
34325 INIT_LIST_HEAD(&c->context_list);
34326 #endif
34327
34328diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34329index 7ce65f4..e66e9bc 100644
34330--- a/drivers/mfd/abx500-core.c
34331+++ b/drivers/mfd/abx500-core.c
34332@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34333
34334 struct abx500_device_entry {
34335 struct list_head list;
34336- struct abx500_ops ops;
34337+ abx500_ops_no_const ops;
34338 struct device *dev;
34339 };
34340
34341diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34342index 2ea9998..51dabee 100644
34343--- a/drivers/mfd/janz-cmodio.c
34344+++ b/drivers/mfd/janz-cmodio.c
34345@@ -13,6 +13,7 @@
34346
34347 #include <linux/kernel.h>
34348 #include <linux/module.h>
34349+#include <linux/slab.h>
34350 #include <linux/init.h>
34351 #include <linux/pci.h>
34352 #include <linux/interrupt.h>
34353diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34354index a981e2a..5ca0c8b 100644
34355--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34356+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34357@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34358 * the lid is closed. This leads to interrupts as soon as a little move
34359 * is done.
34360 */
34361- atomic_inc(&lis3->count);
34362+ atomic_inc_unchecked(&lis3->count);
34363
34364 wake_up_interruptible(&lis3->misc_wait);
34365 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34366@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34367 if (lis3->pm_dev)
34368 pm_runtime_get_sync(lis3->pm_dev);
34369
34370- atomic_set(&lis3->count, 0);
34371+ atomic_set_unchecked(&lis3->count, 0);
34372 return 0;
34373 }
34374
34375@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34376 add_wait_queue(&lis3->misc_wait, &wait);
34377 while (true) {
34378 set_current_state(TASK_INTERRUPTIBLE);
34379- data = atomic_xchg(&lis3->count, 0);
34380+ data = atomic_xchg_unchecked(&lis3->count, 0);
34381 if (data)
34382 break;
34383
34384@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34385 struct lis3lv02d, miscdev);
34386
34387 poll_wait(file, &lis3->misc_wait, wait);
34388- if (atomic_read(&lis3->count))
34389+ if (atomic_read_unchecked(&lis3->count))
34390 return POLLIN | POLLRDNORM;
34391 return 0;
34392 }
34393diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34394index 2b1482a..5d33616 100644
34395--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34396+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34397@@ -266,7 +266,7 @@ struct lis3lv02d {
34398 struct input_polled_dev *idev; /* input device */
34399 struct platform_device *pdev; /* platform device */
34400 struct regulator_bulk_data regulators[2];
34401- atomic_t count; /* interrupt count after last read */
34402+ atomic_unchecked_t count; /* interrupt count after last read */
34403 union axis_conversion ac; /* hw -> logical axis */
34404 int mapped_btns[3];
34405
34406diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
34407index 28adefe..08aad69 100644
34408--- a/drivers/misc/lkdtm.c
34409+++ b/drivers/misc/lkdtm.c
34410@@ -477,6 +477,8 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
34411 int i, n, out;
34412
34413 buf = (char *)__get_free_page(GFP_KERNEL);
34414+ if (buf == NULL)
34415+ return -ENOMEM;
34416
34417 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
34418 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
34419diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34420index 2f30bad..c4c13d0 100644
34421--- a/drivers/misc/sgi-gru/gruhandles.c
34422+++ b/drivers/misc/sgi-gru/gruhandles.c
34423@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34424 unsigned long nsec;
34425
34426 nsec = CLKS2NSEC(clks);
34427- atomic_long_inc(&mcs_op_statistics[op].count);
34428- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34429+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34430+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34431 if (mcs_op_statistics[op].max < nsec)
34432 mcs_op_statistics[op].max = nsec;
34433 }
34434diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34435index 950dbe9..eeef0f8 100644
34436--- a/drivers/misc/sgi-gru/gruprocfs.c
34437+++ b/drivers/misc/sgi-gru/gruprocfs.c
34438@@ -32,9 +32,9 @@
34439
34440 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34441
34442-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34443+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34444 {
34445- unsigned long val = atomic_long_read(v);
34446+ unsigned long val = atomic_long_read_unchecked(v);
34447
34448 seq_printf(s, "%16lu %s\n", val, id);
34449 }
34450@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34451
34452 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34453 for (op = 0; op < mcsop_last; op++) {
34454- count = atomic_long_read(&mcs_op_statistics[op].count);
34455- total = atomic_long_read(&mcs_op_statistics[op].total);
34456+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34457+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34458 max = mcs_op_statistics[op].max;
34459 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34460 count ? total / count : 0, max);
34461diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34462index 5c3ce24..4915ccb 100644
34463--- a/drivers/misc/sgi-gru/grutables.h
34464+++ b/drivers/misc/sgi-gru/grutables.h
34465@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34466 * GRU statistics.
34467 */
34468 struct gru_stats_s {
34469- atomic_long_t vdata_alloc;
34470- atomic_long_t vdata_free;
34471- atomic_long_t gts_alloc;
34472- atomic_long_t gts_free;
34473- atomic_long_t gms_alloc;
34474- atomic_long_t gms_free;
34475- atomic_long_t gts_double_allocate;
34476- atomic_long_t assign_context;
34477- atomic_long_t assign_context_failed;
34478- atomic_long_t free_context;
34479- atomic_long_t load_user_context;
34480- atomic_long_t load_kernel_context;
34481- atomic_long_t lock_kernel_context;
34482- atomic_long_t unlock_kernel_context;
34483- atomic_long_t steal_user_context;
34484- atomic_long_t steal_kernel_context;
34485- atomic_long_t steal_context_failed;
34486- atomic_long_t nopfn;
34487- atomic_long_t asid_new;
34488- atomic_long_t asid_next;
34489- atomic_long_t asid_wrap;
34490- atomic_long_t asid_reuse;
34491- atomic_long_t intr;
34492- atomic_long_t intr_cbr;
34493- atomic_long_t intr_tfh;
34494- atomic_long_t intr_spurious;
34495- atomic_long_t intr_mm_lock_failed;
34496- atomic_long_t call_os;
34497- atomic_long_t call_os_wait_queue;
34498- atomic_long_t user_flush_tlb;
34499- atomic_long_t user_unload_context;
34500- atomic_long_t user_exception;
34501- atomic_long_t set_context_option;
34502- atomic_long_t check_context_retarget_intr;
34503- atomic_long_t check_context_unload;
34504- atomic_long_t tlb_dropin;
34505- atomic_long_t tlb_preload_page;
34506- atomic_long_t tlb_dropin_fail_no_asid;
34507- atomic_long_t tlb_dropin_fail_upm;
34508- atomic_long_t tlb_dropin_fail_invalid;
34509- atomic_long_t tlb_dropin_fail_range_active;
34510- atomic_long_t tlb_dropin_fail_idle;
34511- atomic_long_t tlb_dropin_fail_fmm;
34512- atomic_long_t tlb_dropin_fail_no_exception;
34513- atomic_long_t tfh_stale_on_fault;
34514- atomic_long_t mmu_invalidate_range;
34515- atomic_long_t mmu_invalidate_page;
34516- atomic_long_t flush_tlb;
34517- atomic_long_t flush_tlb_gru;
34518- atomic_long_t flush_tlb_gru_tgh;
34519- atomic_long_t flush_tlb_gru_zero_asid;
34520+ atomic_long_unchecked_t vdata_alloc;
34521+ atomic_long_unchecked_t vdata_free;
34522+ atomic_long_unchecked_t gts_alloc;
34523+ atomic_long_unchecked_t gts_free;
34524+ atomic_long_unchecked_t gms_alloc;
34525+ atomic_long_unchecked_t gms_free;
34526+ atomic_long_unchecked_t gts_double_allocate;
34527+ atomic_long_unchecked_t assign_context;
34528+ atomic_long_unchecked_t assign_context_failed;
34529+ atomic_long_unchecked_t free_context;
34530+ atomic_long_unchecked_t load_user_context;
34531+ atomic_long_unchecked_t load_kernel_context;
34532+ atomic_long_unchecked_t lock_kernel_context;
34533+ atomic_long_unchecked_t unlock_kernel_context;
34534+ atomic_long_unchecked_t steal_user_context;
34535+ atomic_long_unchecked_t steal_kernel_context;
34536+ atomic_long_unchecked_t steal_context_failed;
34537+ atomic_long_unchecked_t nopfn;
34538+ atomic_long_unchecked_t asid_new;
34539+ atomic_long_unchecked_t asid_next;
34540+ atomic_long_unchecked_t asid_wrap;
34541+ atomic_long_unchecked_t asid_reuse;
34542+ atomic_long_unchecked_t intr;
34543+ atomic_long_unchecked_t intr_cbr;
34544+ atomic_long_unchecked_t intr_tfh;
34545+ atomic_long_unchecked_t intr_spurious;
34546+ atomic_long_unchecked_t intr_mm_lock_failed;
34547+ atomic_long_unchecked_t call_os;
34548+ atomic_long_unchecked_t call_os_wait_queue;
34549+ atomic_long_unchecked_t user_flush_tlb;
34550+ atomic_long_unchecked_t user_unload_context;
34551+ atomic_long_unchecked_t user_exception;
34552+ atomic_long_unchecked_t set_context_option;
34553+ atomic_long_unchecked_t check_context_retarget_intr;
34554+ atomic_long_unchecked_t check_context_unload;
34555+ atomic_long_unchecked_t tlb_dropin;
34556+ atomic_long_unchecked_t tlb_preload_page;
34557+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34558+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34559+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34560+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34561+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34562+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34563+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34564+ atomic_long_unchecked_t tfh_stale_on_fault;
34565+ atomic_long_unchecked_t mmu_invalidate_range;
34566+ atomic_long_unchecked_t mmu_invalidate_page;
34567+ atomic_long_unchecked_t flush_tlb;
34568+ atomic_long_unchecked_t flush_tlb_gru;
34569+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34570+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34571
34572- atomic_long_t copy_gpa;
34573- atomic_long_t read_gpa;
34574+ atomic_long_unchecked_t copy_gpa;
34575+ atomic_long_unchecked_t read_gpa;
34576
34577- atomic_long_t mesq_receive;
34578- atomic_long_t mesq_receive_none;
34579- atomic_long_t mesq_send;
34580- atomic_long_t mesq_send_failed;
34581- atomic_long_t mesq_noop;
34582- atomic_long_t mesq_send_unexpected_error;
34583- atomic_long_t mesq_send_lb_overflow;
34584- atomic_long_t mesq_send_qlimit_reached;
34585- atomic_long_t mesq_send_amo_nacked;
34586- atomic_long_t mesq_send_put_nacked;
34587- atomic_long_t mesq_page_overflow;
34588- atomic_long_t mesq_qf_locked;
34589- atomic_long_t mesq_qf_noop_not_full;
34590- atomic_long_t mesq_qf_switch_head_failed;
34591- atomic_long_t mesq_qf_unexpected_error;
34592- atomic_long_t mesq_noop_unexpected_error;
34593- atomic_long_t mesq_noop_lb_overflow;
34594- atomic_long_t mesq_noop_qlimit_reached;
34595- atomic_long_t mesq_noop_amo_nacked;
34596- atomic_long_t mesq_noop_put_nacked;
34597- atomic_long_t mesq_noop_page_overflow;
34598+ atomic_long_unchecked_t mesq_receive;
34599+ atomic_long_unchecked_t mesq_receive_none;
34600+ atomic_long_unchecked_t mesq_send;
34601+ atomic_long_unchecked_t mesq_send_failed;
34602+ atomic_long_unchecked_t mesq_noop;
34603+ atomic_long_unchecked_t mesq_send_unexpected_error;
34604+ atomic_long_unchecked_t mesq_send_lb_overflow;
34605+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34606+ atomic_long_unchecked_t mesq_send_amo_nacked;
34607+ atomic_long_unchecked_t mesq_send_put_nacked;
34608+ atomic_long_unchecked_t mesq_page_overflow;
34609+ atomic_long_unchecked_t mesq_qf_locked;
34610+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34611+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34612+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34613+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34614+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34615+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34616+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34617+ atomic_long_unchecked_t mesq_noop_put_nacked;
34618+ atomic_long_unchecked_t mesq_noop_page_overflow;
34619
34620 };
34621
34622@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34623 tghop_invalidate, mcsop_last};
34624
34625 struct mcs_op_statistic {
34626- atomic_long_t count;
34627- atomic_long_t total;
34628+ atomic_long_unchecked_t count;
34629+ atomic_long_unchecked_t total;
34630 unsigned long max;
34631 };
34632
34633@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34634
34635 #define STAT(id) do { \
34636 if (gru_options & OPT_STATS) \
34637- atomic_long_inc(&gru_stats.id); \
34638+ atomic_long_inc_unchecked(&gru_stats.id); \
34639 } while (0)
34640
34641 #ifdef CONFIG_SGI_GRU_DEBUG
34642diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34643index c862cd4..0d176fe 100644
34644--- a/drivers/misc/sgi-xp/xp.h
34645+++ b/drivers/misc/sgi-xp/xp.h
34646@@ -288,7 +288,7 @@ struct xpc_interface {
34647 xpc_notify_func, void *);
34648 void (*received) (short, int, void *);
34649 enum xp_retval (*partid_to_nasids) (short, void *);
34650-};
34651+} __no_const;
34652
34653 extern struct xpc_interface xpc_interface;
34654
34655diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34656index b94d5f7..7f494c5 100644
34657--- a/drivers/misc/sgi-xp/xpc.h
34658+++ b/drivers/misc/sgi-xp/xpc.h
34659@@ -835,6 +835,7 @@ struct xpc_arch_operations {
34660 void (*received_payload) (struct xpc_channel *, void *);
34661 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34662 };
34663+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34664
34665 /* struct xpc_partition act_state values (for XPC HB) */
34666
34667@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34668 /* found in xpc_main.c */
34669 extern struct device *xpc_part;
34670 extern struct device *xpc_chan;
34671-extern struct xpc_arch_operations xpc_arch_ops;
34672+extern xpc_arch_operations_no_const xpc_arch_ops;
34673 extern int xpc_disengage_timelimit;
34674 extern int xpc_disengage_timedout;
34675 extern int xpc_activate_IRQ_rcvd;
34676diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34677index 8d082b4..aa749ae 100644
34678--- a/drivers/misc/sgi-xp/xpc_main.c
34679+++ b/drivers/misc/sgi-xp/xpc_main.c
34680@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34681 .notifier_call = xpc_system_die,
34682 };
34683
34684-struct xpc_arch_operations xpc_arch_ops;
34685+xpc_arch_operations_no_const xpc_arch_ops;
34686
34687 /*
34688 * Timer function to enforce the timelimit on the partition disengage.
34689diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
34690index 2b62232..acfaeeb 100644
34691--- a/drivers/misc/ti-st/st_core.c
34692+++ b/drivers/misc/ti-st/st_core.c
34693@@ -349,6 +349,11 @@ void st_int_recv(void *disc_data,
34694 st_gdata->rx_skb = alloc_skb(
34695 st_gdata->list[type]->max_frame_size,
34696 GFP_ATOMIC);
34697+ if (st_gdata->rx_skb == NULL) {
34698+ pr_err("out of memory: dropping\n");
34699+ goto done;
34700+ }
34701+
34702 skb_reserve(st_gdata->rx_skb,
34703 st_gdata->list[type]->reserve);
34704 /* next 2 required for BT only */
34705diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34706index 504da71..9722d43 100644
34707--- a/drivers/mmc/host/sdhci-pci.c
34708+++ b/drivers/mmc/host/sdhci-pci.c
34709@@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34710 .probe = via_probe,
34711 };
34712
34713-static const struct pci_device_id pci_ids[] __devinitdata = {
34714+static const struct pci_device_id pci_ids[] __devinitconst = {
34715 {
34716 .vendor = PCI_VENDOR_ID_RICOH,
34717 .device = PCI_DEVICE_ID_RICOH_R5C822,
34718diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34719index a4eb8b5..8c0628f 100644
34720--- a/drivers/mtd/devices/doc2000.c
34721+++ b/drivers/mtd/devices/doc2000.c
34722@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34723
34724 /* The ECC will not be calculated correctly if less than 512 is written */
34725 /* DBB-
34726- if (len != 0x200 && eccbuf)
34727+ if (len != 0x200)
34728 printk(KERN_WARNING
34729 "ECC needs a full sector write (adr: %lx size %lx)\n",
34730 (long) to, (long) len);
34731diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
34732index f2f482b..a6e7451 100644
34733--- a/drivers/mtd/mtdchar.c
34734+++ b/drivers/mtd/mtdchar.c
34735@@ -1123,6 +1123,33 @@ static unsigned long mtdchar_get_unmapped_area(struct file *file,
34736 }
34737 #endif
34738
34739+static inline unsigned long get_vm_size(struct vm_area_struct *vma)
34740+{
34741+ return vma->vm_end - vma->vm_start;
34742+}
34743+
34744+static inline resource_size_t get_vm_offset(struct vm_area_struct *vma)
34745+{
34746+ return (resource_size_t) vma->vm_pgoff << PAGE_SHIFT;
34747+}
34748+
34749+/*
34750+ * Set a new vm offset.
34751+ *
34752+ * Verify that the incoming offset really works as a page offset,
34753+ * and that the offset and size fit in a resource_size_t.
34754+ */
34755+static inline int set_vm_offset(struct vm_area_struct *vma, resource_size_t off)
34756+{
34757+ pgoff_t pgoff = off >> PAGE_SHIFT;
34758+ if (off != (resource_size_t) pgoff << PAGE_SHIFT)
34759+ return -EINVAL;
34760+ if (off + get_vm_size(vma) - 1 < off)
34761+ return -EINVAL;
34762+ vma->vm_pgoff = pgoff;
34763+ return 0;
34764+}
34765+
34766 /*
34767 * set up a mapping for shared memory segments
34768 */
34769@@ -1132,20 +1159,29 @@ static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma)
34770 struct mtd_file_info *mfi = file->private_data;
34771 struct mtd_info *mtd = mfi->mtd;
34772 struct map_info *map = mtd->priv;
34773- unsigned long start;
34774- unsigned long off;
34775- u32 len;
34776+ resource_size_t start, off;
34777+ unsigned long len, vma_len;
34778
34779 if (mtd->type == MTD_RAM || mtd->type == MTD_ROM) {
34780- off = vma->vm_pgoff << PAGE_SHIFT;
34781+ off = get_vm_offset(vma);
34782 start = map->phys;
34783 len = PAGE_ALIGN((start & ~PAGE_MASK) + map->size);
34784 start &= PAGE_MASK;
34785- if ((vma->vm_end - vma->vm_start + off) > len)
34786+ vma_len = get_vm_size(vma);
34787+
34788+ /* Overflow in off+len? */
34789+ if (vma_len + off < off)
34790+ return -EINVAL;
34791+ /* Does it fit in the mapping? */
34792+ if (vma_len + off > len)
34793 return -EINVAL;
34794
34795 off += start;
34796- vma->vm_pgoff = off >> PAGE_SHIFT;
34797+ /* Did that overflow? */
34798+ if (off < start)
34799+ return -EINVAL;
34800+ if (set_vm_offset(vma, off) < 0)
34801+ return -EINVAL;
34802 vma->vm_flags |= VM_IO | VM_RESERVED;
34803
34804 #ifdef pgprot_noncached
34805diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34806index 0650aaf..7718762 100644
34807--- a/drivers/mtd/nand/denali.c
34808+++ b/drivers/mtd/nand/denali.c
34809@@ -26,6 +26,7 @@
34810 #include <linux/pci.h>
34811 #include <linux/mtd/mtd.h>
34812 #include <linux/module.h>
34813+#include <linux/slab.h>
34814
34815 #include "denali.h"
34816
34817diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34818index 51b9d6a..52af9a7 100644
34819--- a/drivers/mtd/nftlmount.c
34820+++ b/drivers/mtd/nftlmount.c
34821@@ -24,6 +24,7 @@
34822 #include <asm/errno.h>
34823 #include <linux/delay.h>
34824 #include <linux/slab.h>
34825+#include <linux/sched.h>
34826 #include <linux/mtd/mtd.h>
34827 #include <linux/mtd/nand.h>
34828 #include <linux/mtd/nftl.h>
34829diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34830index 6762dc4..9956862 100644
34831--- a/drivers/net/ethernet/atheros/atlx/atl2.c
34832+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34833@@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34834 */
34835
34836 #define ATL2_PARAM(X, desc) \
34837- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34838+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34839 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34840 MODULE_PARM_DESC(X, desc);
34841 #else
34842diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34843index efd80bd..21fcff0 100644
34844--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34845+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34846@@ -487,7 +487,7 @@ struct bnx2x_rx_mode_obj {
34847
34848 int (*wait_comp)(struct bnx2x *bp,
34849 struct bnx2x_rx_mode_ramrod_params *p);
34850-};
34851+} __no_const;
34852
34853 /********************** Set multicast group ***********************************/
34854
34855diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34856index 93865f8..5448741 100644
34857--- a/drivers/net/ethernet/broadcom/tg3.h
34858+++ b/drivers/net/ethernet/broadcom/tg3.h
34859@@ -140,6 +140,7 @@
34860 #define CHIPREV_ID_5750_A0 0x4000
34861 #define CHIPREV_ID_5750_A1 0x4001
34862 #define CHIPREV_ID_5750_A3 0x4003
34863+#define CHIPREV_ID_5750_C1 0x4201
34864 #define CHIPREV_ID_5750_C2 0x4202
34865 #define CHIPREV_ID_5752_A0_HW 0x5000
34866 #define CHIPREV_ID_5752_A0 0x6000
34867diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34868index c4e8643..0979484 100644
34869--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34870+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34871@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34872 */
34873 struct l2t_skb_cb {
34874 arp_failure_handler_func arp_failure_handler;
34875-};
34876+} __no_const;
34877
34878 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34879
34880diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34881index d3cd489..0fd52dd 100644
34882--- a/drivers/net/ethernet/dec/tulip/de4x5.c
34883+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34884@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34885 for (i=0; i<ETH_ALEN; i++) {
34886 tmp.addr[i] = dev->dev_addr[i];
34887 }
34888- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34889+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34890 break;
34891
34892 case DE4X5_SET_HWADDR: /* Set the hardware address */
34893@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34894 spin_lock_irqsave(&lp->lock, flags);
34895 memcpy(&statbuf, &lp->pktStats, ioc->len);
34896 spin_unlock_irqrestore(&lp->lock, flags);
34897- if (copy_to_user(ioc->data, &statbuf, ioc->len))
34898+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34899 return -EFAULT;
34900 break;
34901 }
34902diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34903index ed7d1dc..d426748 100644
34904--- a/drivers/net/ethernet/dec/tulip/eeprom.c
34905+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34906@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34907 {NULL}};
34908
34909
34910-static const char *block_name[] __devinitdata = {
34911+static const char *block_name[] __devinitconst = {
34912 "21140 non-MII",
34913 "21140 MII PHY",
34914 "21142 Serial PHY",
34915diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34916index 75d45f8..3d9c55b 100644
34917--- a/drivers/net/ethernet/dec/tulip/uli526x.c
34918+++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34919@@ -129,7 +129,7 @@ struct uli526x_board_info {
34920 struct uli_phy_ops {
34921 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34922 u16 (*read)(struct uli526x_board_info *, u8, u8);
34923- } phy;
34924+ } __no_const phy;
34925 struct net_device *next_dev; /* next device */
34926 struct pci_dev *pdev; /* PCI device */
34927 spinlock_t lock;
34928diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34929index 4d1ffca..7c1ec4d 100644
34930--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34931+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34932@@ -236,7 +236,7 @@ struct pci_id_info {
34933 int drv_flags; /* Driver use, intended as capability flags. */
34934 };
34935
34936-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34937+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34938 { /* Sometime a Level-One switch card. */
34939 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34940 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34941diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34942index d7bb52a..3b83588 100644
34943--- a/drivers/net/ethernet/dlink/sundance.c
34944+++ b/drivers/net/ethernet/dlink/sundance.c
34945@@ -218,7 +218,7 @@ enum {
34946 struct pci_id_info {
34947 const char *name;
34948 };
34949-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34950+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34951 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34952 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34953 {"D-Link DFE-580TX 4 port Server Adapter"},
34954diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34955index bd5cf7e..c165651 100644
34956--- a/drivers/net/ethernet/emulex/benet/be_main.c
34957+++ b/drivers/net/ethernet/emulex/benet/be_main.c
34958@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34959
34960 if (wrapped)
34961 newacc += 65536;
34962- ACCESS_ONCE(*acc) = newacc;
34963+ ACCESS_ONCE_RW(*acc) = newacc;
34964 }
34965
34966 void be_parse_stats(struct be_adapter *adapter)
34967diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34968index 16b0704..d2c07d7 100644
34969--- a/drivers/net/ethernet/faraday/ftgmac100.c
34970+++ b/drivers/net/ethernet/faraday/ftgmac100.c
34971@@ -31,6 +31,8 @@
34972 #include <linux/netdevice.h>
34973 #include <linux/phy.h>
34974 #include <linux/platform_device.h>
34975+#include <linux/interrupt.h>
34976+#include <linux/irqreturn.h>
34977 #include <net/ip.h>
34978
34979 #include "ftgmac100.h"
34980diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34981index 829b109..4ae5f6a 100644
34982--- a/drivers/net/ethernet/faraday/ftmac100.c
34983+++ b/drivers/net/ethernet/faraday/ftmac100.c
34984@@ -31,6 +31,8 @@
34985 #include <linux/module.h>
34986 #include <linux/netdevice.h>
34987 #include <linux/platform_device.h>
34988+#include <linux/interrupt.h>
34989+#include <linux/irqreturn.h>
34990
34991 #include "ftmac100.h"
34992
34993diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34994index 9d71c9c..0e4a0ac 100644
34995--- a/drivers/net/ethernet/fealnx.c
34996+++ b/drivers/net/ethernet/fealnx.c
34997@@ -150,7 +150,7 @@ struct chip_info {
34998 int flags;
34999 };
35000
35001-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
35002+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
35003 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35004 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35005 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35006diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
35007index fa47b85..246edeb 100644
35008--- a/drivers/net/ethernet/intel/e1000e/e1000.h
35009+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
35010@@ -181,7 +181,7 @@ struct e1000_info;
35011 #define E1000_TXDCTL_DMA_BURST_ENABLE \
35012 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
35013 E1000_TXDCTL_COUNT_DESC | \
35014- (5 << 16) | /* wthresh must be +1 more than desired */\
35015+ (1 << 16) | /* wthresh must be +1 more than desired */\
35016 (1 << 8) | /* hthresh */ \
35017 0x1f) /* pthresh */
35018
35019diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35020index ed5b409..ec37828 100644
35021--- a/drivers/net/ethernet/intel/e1000e/hw.h
35022+++ b/drivers/net/ethernet/intel/e1000e/hw.h
35023@@ -797,6 +797,7 @@ struct e1000_mac_operations {
35024 void (*rar_set)(struct e1000_hw *, u8 *, u32);
35025 s32 (*read_mac_addr)(struct e1000_hw *);
35026 };
35027+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35028
35029 /*
35030 * When to use various PHY register access functions:
35031@@ -837,6 +838,7 @@ struct e1000_phy_operations {
35032 void (*power_up)(struct e1000_hw *);
35033 void (*power_down)(struct e1000_hw *);
35034 };
35035+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35036
35037 /* Function pointers for the NVM. */
35038 struct e1000_nvm_operations {
35039@@ -849,9 +851,10 @@ struct e1000_nvm_operations {
35040 s32 (*validate)(struct e1000_hw *);
35041 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35042 };
35043+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35044
35045 struct e1000_mac_info {
35046- struct e1000_mac_operations ops;
35047+ e1000_mac_operations_no_const ops;
35048 u8 addr[ETH_ALEN];
35049 u8 perm_addr[ETH_ALEN];
35050
35051@@ -892,7 +895,7 @@ struct e1000_mac_info {
35052 };
35053
35054 struct e1000_phy_info {
35055- struct e1000_phy_operations ops;
35056+ e1000_phy_operations_no_const ops;
35057
35058 enum e1000_phy_type type;
35059
35060@@ -926,7 +929,7 @@ struct e1000_phy_info {
35061 };
35062
35063 struct e1000_nvm_info {
35064- struct e1000_nvm_operations ops;
35065+ e1000_nvm_operations_no_const ops;
35066
35067 enum e1000_nvm_type type;
35068 enum e1000_nvm_override override;
35069diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35070index c2a51dc..c2bd262 100644
35071--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35072+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35073@@ -327,6 +327,7 @@ struct e1000_mac_operations {
35074 void (*release_swfw_sync)(struct e1000_hw *, u16);
35075
35076 };
35077+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35078
35079 struct e1000_phy_operations {
35080 s32 (*acquire)(struct e1000_hw *);
35081@@ -343,6 +344,7 @@ struct e1000_phy_operations {
35082 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35083 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35084 };
35085+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35086
35087 struct e1000_nvm_operations {
35088 s32 (*acquire)(struct e1000_hw *);
35089@@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35090 s32 (*validate)(struct e1000_hw *);
35091 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35092 };
35093+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35094
35095 struct e1000_info {
35096 s32 (*get_invariants)(struct e1000_hw *);
35097@@ -364,7 +367,7 @@ struct e1000_info {
35098 extern const struct e1000_info e1000_82575_info;
35099
35100 struct e1000_mac_info {
35101- struct e1000_mac_operations ops;
35102+ e1000_mac_operations_no_const ops;
35103
35104 u8 addr[6];
35105 u8 perm_addr[6];
35106@@ -402,7 +405,7 @@ struct e1000_mac_info {
35107 };
35108
35109 struct e1000_phy_info {
35110- struct e1000_phy_operations ops;
35111+ e1000_phy_operations_no_const ops;
35112
35113 enum e1000_phy_type type;
35114
35115@@ -437,7 +440,7 @@ struct e1000_phy_info {
35116 };
35117
35118 struct e1000_nvm_info {
35119- struct e1000_nvm_operations ops;
35120+ e1000_nvm_operations_no_const ops;
35121 enum e1000_nvm_type type;
35122 enum e1000_nvm_override override;
35123
35124@@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35125 s32 (*check_for_ack)(struct e1000_hw *, u16);
35126 s32 (*check_for_rst)(struct e1000_hw *, u16);
35127 };
35128+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35129
35130 struct e1000_mbx_stats {
35131 u32 msgs_tx;
35132@@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35133 };
35134
35135 struct e1000_mbx_info {
35136- struct e1000_mbx_operations ops;
35137+ e1000_mbx_operations_no_const ops;
35138 struct e1000_mbx_stats stats;
35139 u32 timeout;
35140 u32 usec_delay;
35141diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35142index 57db3c6..aa825fc 100644
35143--- a/drivers/net/ethernet/intel/igbvf/vf.h
35144+++ b/drivers/net/ethernet/intel/igbvf/vf.h
35145@@ -189,9 +189,10 @@ struct e1000_mac_operations {
35146 s32 (*read_mac_addr)(struct e1000_hw *);
35147 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35148 };
35149+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35150
35151 struct e1000_mac_info {
35152- struct e1000_mac_operations ops;
35153+ e1000_mac_operations_no_const ops;
35154 u8 addr[6];
35155 u8 perm_addr[6];
35156
35157@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35158 s32 (*check_for_ack)(struct e1000_hw *);
35159 s32 (*check_for_rst)(struct e1000_hw *);
35160 };
35161+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35162
35163 struct e1000_mbx_stats {
35164 u32 msgs_tx;
35165@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35166 };
35167
35168 struct e1000_mbx_info {
35169- struct e1000_mbx_operations ops;
35170+ e1000_mbx_operations_no_const ops;
35171 struct e1000_mbx_stats stats;
35172 u32 timeout;
35173 u32 usec_delay;
35174diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35175index dcebd12..c1fe8be 100644
35176--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35177+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35178@@ -805,7 +805,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35179 /* store the new cycle speed */
35180 adapter->cycle_speed = cycle_speed;
35181
35182- ACCESS_ONCE(adapter->base_incval) = incval;
35183+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
35184 smp_mb();
35185
35186 /* grab the ptp lock */
35187diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35188index 204848d..d8aeaec 100644
35189--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35190+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35191@@ -2791,6 +2791,7 @@ struct ixgbe_eeprom_operations {
35192 s32 (*update_checksum)(struct ixgbe_hw *);
35193 u16 (*calc_checksum)(struct ixgbe_hw *);
35194 };
35195+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35196
35197 struct ixgbe_mac_operations {
35198 s32 (*init_hw)(struct ixgbe_hw *);
35199@@ -2856,6 +2857,7 @@ struct ixgbe_mac_operations {
35200 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35201 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35202 };
35203+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35204
35205 struct ixgbe_phy_operations {
35206 s32 (*identify)(struct ixgbe_hw *);
35207@@ -2875,9 +2877,10 @@ struct ixgbe_phy_operations {
35208 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35209 s32 (*check_overtemp)(struct ixgbe_hw *);
35210 };
35211+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35212
35213 struct ixgbe_eeprom_info {
35214- struct ixgbe_eeprom_operations ops;
35215+ ixgbe_eeprom_operations_no_const ops;
35216 enum ixgbe_eeprom_type type;
35217 u32 semaphore_delay;
35218 u16 word_size;
35219@@ -2887,7 +2890,7 @@ struct ixgbe_eeprom_info {
35220
35221 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35222 struct ixgbe_mac_info {
35223- struct ixgbe_mac_operations ops;
35224+ ixgbe_mac_operations_no_const ops;
35225 enum ixgbe_mac_type type;
35226 u8 addr[ETH_ALEN];
35227 u8 perm_addr[ETH_ALEN];
35228@@ -2916,7 +2919,7 @@ struct ixgbe_mac_info {
35229 };
35230
35231 struct ixgbe_phy_info {
35232- struct ixgbe_phy_operations ops;
35233+ ixgbe_phy_operations_no_const ops;
35234 struct mdio_if_info mdio;
35235 enum ixgbe_phy_type type;
35236 u32 id;
35237@@ -2944,6 +2947,7 @@ struct ixgbe_mbx_operations {
35238 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35239 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35240 };
35241+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35242
35243 struct ixgbe_mbx_stats {
35244 u32 msgs_tx;
35245@@ -2955,7 +2959,7 @@ struct ixgbe_mbx_stats {
35246 };
35247
35248 struct ixgbe_mbx_info {
35249- struct ixgbe_mbx_operations ops;
35250+ ixgbe_mbx_operations_no_const ops;
35251 struct ixgbe_mbx_stats stats;
35252 u32 timeout;
35253 u32 usec_delay;
35254diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35255index 25c951d..cc7cf33 100644
35256--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35257+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35258@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35259 s32 (*clear_vfta)(struct ixgbe_hw *);
35260 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35261 };
35262+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35263
35264 enum ixgbe_mac_type {
35265 ixgbe_mac_unknown = 0,
35266@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35267 };
35268
35269 struct ixgbe_mac_info {
35270- struct ixgbe_mac_operations ops;
35271+ ixgbe_mac_operations_no_const ops;
35272 u8 addr[6];
35273 u8 perm_addr[6];
35274
35275@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35276 s32 (*check_for_ack)(struct ixgbe_hw *);
35277 s32 (*check_for_rst)(struct ixgbe_hw *);
35278 };
35279+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35280
35281 struct ixgbe_mbx_stats {
35282 u32 msgs_tx;
35283@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35284 };
35285
35286 struct ixgbe_mbx_info {
35287- struct ixgbe_mbx_operations ops;
35288+ ixgbe_mbx_operations_no_const ops;
35289 struct ixgbe_mbx_stats stats;
35290 u32 timeout;
35291 u32 udelay;
35292diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35293index a0313de..e83a572 100644
35294--- a/drivers/net/ethernet/mellanox/mlx4/main.c
35295+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35296@@ -41,6 +41,7 @@
35297 #include <linux/slab.h>
35298 #include <linux/io-mapping.h>
35299 #include <linux/delay.h>
35300+#include <linux/sched.h>
35301
35302 #include <linux/mlx4/device.h>
35303 #include <linux/mlx4/doorbell.h>
35304diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35305index 5046a64..71ca936 100644
35306--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35307+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35308@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35309 void (*link_down)(struct __vxge_hw_device *devh);
35310 void (*crit_err)(struct __vxge_hw_device *devh,
35311 enum vxge_hw_event type, u64 ext_data);
35312-};
35313+} __no_const;
35314
35315 /*
35316 * struct __vxge_hw_blockpool_entry - Block private data structure
35317diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35318index 4a518a3..936b334 100644
35319--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35320+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35321@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35322 struct vxge_hw_mempool_dma *dma_object,
35323 u32 index,
35324 u32 is_last);
35325-};
35326+} __no_const;
35327
35328 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35329 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35330diff --git a/drivers/net/ethernet/octeon/octeon_mgmt.c b/drivers/net/ethernet/octeon/octeon_mgmt.c
35331index cd827ff..389795e 100644
35332--- a/drivers/net/ethernet/octeon/octeon_mgmt.c
35333+++ b/drivers/net/ethernet/octeon/octeon_mgmt.c
35334@@ -683,10 +683,8 @@ static int octeon_mgmt_init_phy(struct net_device *netdev)
35335 p->phydev = phy_connect(netdev, phy_id, octeon_mgmt_adjust_link, 0,
35336 PHY_INTERFACE_MODE_MII);
35337
35338- if (IS_ERR(p->phydev)) {
35339- p->phydev = NULL;
35340+ if (!p->phydev)
35341 return -1;
35342- }
35343
35344 phy_start_aneg(p->phydev);
35345
35346diff --git a/drivers/net/ethernet/pasemi/pasemi_mac.c b/drivers/net/ethernet/pasemi/pasemi_mac.c
35347index e559dfa..6fa74d5 100644
35348--- a/drivers/net/ethernet/pasemi/pasemi_mac.c
35349+++ b/drivers/net/ethernet/pasemi/pasemi_mac.c
35350@@ -1101,9 +1101,9 @@ static int pasemi_mac_phy_init(struct net_device *dev)
35351 phydev = of_phy_connect(dev, phy_dn, &pasemi_adjust_link, 0,
35352 PHY_INTERFACE_MODE_SGMII);
35353
35354- if (IS_ERR(phydev)) {
35355+ if (!phydev) {
35356 printk(KERN_ERR "%s: Could not attach to phy\n", dev->name);
35357- return PTR_ERR(phydev);
35358+ return -ENODEV;
35359 }
35360
35361 mac->phydev = phydev;
35362diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35363index eb81da4..1592b62 100644
35364--- a/drivers/net/ethernet/realtek/r8169.c
35365+++ b/drivers/net/ethernet/realtek/r8169.c
35366@@ -723,22 +723,22 @@ struct rtl8169_private {
35367 struct mdio_ops {
35368 void (*write)(void __iomem *, int, int);
35369 int (*read)(void __iomem *, int);
35370- } mdio_ops;
35371+ } __no_const mdio_ops;
35372
35373 struct pll_power_ops {
35374 void (*down)(struct rtl8169_private *);
35375 void (*up)(struct rtl8169_private *);
35376- } pll_power_ops;
35377+ } __no_const pll_power_ops;
35378
35379 struct jumbo_ops {
35380 void (*enable)(struct rtl8169_private *);
35381 void (*disable)(struct rtl8169_private *);
35382- } jumbo_ops;
35383+ } __no_const jumbo_ops;
35384
35385 struct csi_ops {
35386 void (*write)(void __iomem *, int, int);
35387 u32 (*read)(void __iomem *, int);
35388- } csi_ops;
35389+ } __no_const csi_ops;
35390
35391 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35392 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35393diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35394index 4613591..d816601 100644
35395--- a/drivers/net/ethernet/sis/sis190.c
35396+++ b/drivers/net/ethernet/sis/sis190.c
35397@@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35398 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35399 struct net_device *dev)
35400 {
35401- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35402+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35403 struct sis190_private *tp = netdev_priv(dev);
35404 struct pci_dev *isa_bridge;
35405 u8 reg, tmp8;
35406diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35407index c07cfe9..81cbf7e 100644
35408--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35409+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35410@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35411
35412 writel(value, ioaddr + MMC_CNTRL);
35413
35414- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35415- MMC_CNTRL, value);
35416+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35417+// MMC_CNTRL, value);
35418 }
35419
35420 /* To mask all all interrupts.*/
35421diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35422index 2857ab0..9a1f9b0 100644
35423--- a/drivers/net/hyperv/hyperv_net.h
35424+++ b/drivers/net/hyperv/hyperv_net.h
35425@@ -99,7 +99,7 @@ struct rndis_device {
35426
35427 enum rndis_device_state state;
35428 bool link_state;
35429- atomic_t new_req_id;
35430+ atomic_unchecked_t new_req_id;
35431
35432 spinlock_t request_lock;
35433 struct list_head req_list;
35434diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35435index 981ebb1..b34959b 100644
35436--- a/drivers/net/hyperv/rndis_filter.c
35437+++ b/drivers/net/hyperv/rndis_filter.c
35438@@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35439 * template
35440 */
35441 set = &rndis_msg->msg.set_req;
35442- set->req_id = atomic_inc_return(&dev->new_req_id);
35443+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35444
35445 /* Add to the request list */
35446 spin_lock_irqsave(&dev->request_lock, flags);
35447@@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35448
35449 /* Setup the rndis set */
35450 halt = &request->request_msg.msg.halt_req;
35451- halt->req_id = atomic_inc_return(&dev->new_req_id);
35452+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35453
35454 /* Ignore return since this msg is optional. */
35455 rndis_filter_send_request(dev, request);
35456diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35457index 5c05572..389610b 100644
35458--- a/drivers/net/ppp/ppp_generic.c
35459+++ b/drivers/net/ppp/ppp_generic.c
35460@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35461 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35462 struct ppp_stats stats;
35463 struct ppp_comp_stats cstats;
35464- char *vers;
35465
35466 switch (cmd) {
35467 case SIOCGPPPSTATS:
35468@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35469 break;
35470
35471 case SIOCGPPPVER:
35472- vers = PPP_VERSION;
35473- if (copy_to_user(addr, vers, strlen(vers) + 1))
35474+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35475 break;
35476 err = 0;
35477 break;
35478diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
35479index c61ae35..7758801 100644
35480--- a/drivers/net/team/team.c
35481+++ b/drivers/net/team/team.c
35482@@ -1410,8 +1410,8 @@ static int team_nl_cmd_noop(struct sk_buff *skb, struct genl_info *info)
35483
35484 hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
35485 &team_nl_family, 0, TEAM_CMD_NOOP);
35486- if (IS_ERR(hdr)) {
35487- err = PTR_ERR(hdr);
35488+ if (!hdr) {
35489+ err = -EMSGSIZE;
35490 goto err_msg_put;
35491 }
35492
35493@@ -1493,8 +1493,8 @@ static int team_nl_fill_options_get(struct sk_buff *skb,
35494
35495 hdr = genlmsg_put(skb, pid, seq, &team_nl_family, flags,
35496 TEAM_CMD_OPTIONS_GET);
35497- if (IS_ERR(hdr))
35498- return PTR_ERR(hdr);
35499+ if (!hdr)
35500+ return -EMSGSIZE;
35501
35502 if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
35503 goto nla_put_failure;
35504@@ -1739,8 +1739,8 @@ static int team_nl_fill_port_list_get(struct sk_buff *skb,
35505
35506 hdr = genlmsg_put(skb, pid, seq, &team_nl_family, flags,
35507 TEAM_CMD_PORT_LIST_GET);
35508- if (IS_ERR(hdr))
35509- return PTR_ERR(hdr);
35510+ if (!hdr)
35511+ return -EMSGSIZE;
35512
35513 if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
35514 goto nla_put_failure;
35515diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35516index 5fb59ae..989715a 100644
35517--- a/drivers/net/tun.c
35518+++ b/drivers/net/tun.c
35519@@ -1243,7 +1243,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35520 }
35521
35522 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35523- unsigned long arg, int ifreq_len)
35524+ unsigned long arg, size_t ifreq_len)
35525 {
35526 struct tun_file *tfile = file->private_data;
35527 struct tun_struct *tun;
35528@@ -1254,6 +1254,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35529 int vnet_hdr_sz;
35530 int ret;
35531
35532+ if (ifreq_len > sizeof ifr)
35533+ return -EFAULT;
35534+
35535 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35536 if (copy_from_user(&ifr, argp, ifreq_len))
35537 return -EFAULT;
35538diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35539index 62f30b4..ff99dfd 100644
35540--- a/drivers/net/usb/hso.c
35541+++ b/drivers/net/usb/hso.c
35542@@ -71,7 +71,7 @@
35543 #include <asm/byteorder.h>
35544 #include <linux/serial_core.h>
35545 #include <linux/serial.h>
35546-
35547+#include <asm/local.h>
35548
35549 #define MOD_AUTHOR "Option Wireless"
35550 #define MOD_DESCRIPTION "USB High Speed Option driver"
35551@@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35552 struct urb *urb;
35553
35554 urb = serial->rx_urb[0];
35555- if (serial->port.count > 0) {
35556+ if (atomic_read(&serial->port.count) > 0) {
35557 count = put_rxbuf_data(urb, serial);
35558 if (count == -1)
35559 return;
35560@@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35561 DUMP1(urb->transfer_buffer, urb->actual_length);
35562
35563 /* Anyone listening? */
35564- if (serial->port.count == 0)
35565+ if (atomic_read(&serial->port.count) == 0)
35566 return;
35567
35568 if (status == 0) {
35569@@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35570 tty_port_tty_set(&serial->port, tty);
35571
35572 /* check for port already opened, if not set the termios */
35573- serial->port.count++;
35574- if (serial->port.count == 1) {
35575+ if (atomic_inc_return(&serial->port.count) == 1) {
35576 serial->rx_state = RX_IDLE;
35577 /* Force default termio settings */
35578 _hso_serial_set_termios(tty, NULL);
35579@@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35580 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35581 if (result) {
35582 hso_stop_serial_device(serial->parent);
35583- serial->port.count--;
35584+ atomic_dec(&serial->port.count);
35585 kref_put(&serial->parent->ref, hso_serial_ref_free);
35586 }
35587 } else {
35588@@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35589
35590 /* reset the rts and dtr */
35591 /* do the actual close */
35592- serial->port.count--;
35593+ atomic_dec(&serial->port.count);
35594
35595- if (serial->port.count <= 0) {
35596- serial->port.count = 0;
35597+ if (atomic_read(&serial->port.count) <= 0) {
35598+ atomic_set(&serial->port.count, 0);
35599 tty_port_tty_set(&serial->port, NULL);
35600 if (!usb_gone)
35601 hso_stop_serial_device(serial->parent);
35602@@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35603
35604 /* the actual setup */
35605 spin_lock_irqsave(&serial->serial_lock, flags);
35606- if (serial->port.count)
35607+ if (atomic_read(&serial->port.count))
35608 _hso_serial_set_termios(tty, old);
35609 else
35610 tty->termios = old;
35611@@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35612 D1("Pending read interrupt on port %d\n", i);
35613 spin_lock(&serial->serial_lock);
35614 if (serial->rx_state == RX_IDLE &&
35615- serial->port.count > 0) {
35616+ atomic_read(&serial->port.count) > 0) {
35617 /* Setup and send a ctrl req read on
35618 * port i */
35619 if (!serial->rx_urb_filled[0]) {
35620@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35621 /* Start all serial ports */
35622 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35623 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35624- if (dev2ser(serial_table[i])->port.count) {
35625+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35626 result =
35627 hso_start_serial_device(serial_table[i], GFP_NOIO);
35628 hso_kick_transmit(dev2ser(serial_table[i]));
35629diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35630index 420d69b..74f90a2 100644
35631--- a/drivers/net/wireless/ath/ath.h
35632+++ b/drivers/net/wireless/ath/ath.h
35633@@ -119,6 +119,7 @@ struct ath_ops {
35634 void (*write_flush) (void *);
35635 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35636 };
35637+typedef struct ath_ops __no_const ath_ops_no_const;
35638
35639 struct ath_common;
35640 struct ath_bus_ops;
35641diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35642index 8d78253..bebbb68 100644
35643--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35644+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35645@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35646 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35647 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35648
35649- ACCESS_ONCE(ads->ds_link) = i->link;
35650- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35651+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35652+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35653
35654 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35655 ctl6 = SM(i->keytype, AR_EncrType);
35656@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35657
35658 if ((i->is_first || i->is_last) &&
35659 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35660- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35661+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35662 | set11nTries(i->rates, 1)
35663 | set11nTries(i->rates, 2)
35664 | set11nTries(i->rates, 3)
35665 | (i->dur_update ? AR_DurUpdateEna : 0)
35666 | SM(0, AR_BurstDur);
35667
35668- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35669+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35670 | set11nRate(i->rates, 1)
35671 | set11nRate(i->rates, 2)
35672 | set11nRate(i->rates, 3);
35673 } else {
35674- ACCESS_ONCE(ads->ds_ctl2) = 0;
35675- ACCESS_ONCE(ads->ds_ctl3) = 0;
35676+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35677+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35678 }
35679
35680 if (!i->is_first) {
35681- ACCESS_ONCE(ads->ds_ctl0) = 0;
35682- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35683- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35684+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35685+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35686+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35687 return;
35688 }
35689
35690@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35691 break;
35692 }
35693
35694- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35695+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35696 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35697 | SM(i->txpower, AR_XmitPower)
35698 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35699@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35700 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35701 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35702
35703- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35704- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35705+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35706+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35707
35708 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35709 return;
35710
35711- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35712+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35713 | set11nPktDurRTSCTS(i->rates, 1);
35714
35715- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35716+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35717 | set11nPktDurRTSCTS(i->rates, 3);
35718
35719- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35720+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35721 | set11nRateFlags(i->rates, 1)
35722 | set11nRateFlags(i->rates, 2)
35723 | set11nRateFlags(i->rates, 3)
35724diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35725index d9e0824..1a874e7 100644
35726--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35727+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35728@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35729 (i->qcu << AR_TxQcuNum_S) | desc_len;
35730
35731 checksum += val;
35732- ACCESS_ONCE(ads->info) = val;
35733+ ACCESS_ONCE_RW(ads->info) = val;
35734
35735 checksum += i->link;
35736- ACCESS_ONCE(ads->link) = i->link;
35737+ ACCESS_ONCE_RW(ads->link) = i->link;
35738
35739 checksum += i->buf_addr[0];
35740- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35741+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35742 checksum += i->buf_addr[1];
35743- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35744+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35745 checksum += i->buf_addr[2];
35746- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35747+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35748 checksum += i->buf_addr[3];
35749- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35750+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35751
35752 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35753- ACCESS_ONCE(ads->ctl3) = val;
35754+ ACCESS_ONCE_RW(ads->ctl3) = val;
35755 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35756- ACCESS_ONCE(ads->ctl5) = val;
35757+ ACCESS_ONCE_RW(ads->ctl5) = val;
35758 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35759- ACCESS_ONCE(ads->ctl7) = val;
35760+ ACCESS_ONCE_RW(ads->ctl7) = val;
35761 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35762- ACCESS_ONCE(ads->ctl9) = val;
35763+ ACCESS_ONCE_RW(ads->ctl9) = val;
35764
35765 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35766- ACCESS_ONCE(ads->ctl10) = checksum;
35767+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
35768
35769 if (i->is_first || i->is_last) {
35770- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35771+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35772 | set11nTries(i->rates, 1)
35773 | set11nTries(i->rates, 2)
35774 | set11nTries(i->rates, 3)
35775 | (i->dur_update ? AR_DurUpdateEna : 0)
35776 | SM(0, AR_BurstDur);
35777
35778- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35779+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35780 | set11nRate(i->rates, 1)
35781 | set11nRate(i->rates, 2)
35782 | set11nRate(i->rates, 3);
35783 } else {
35784- ACCESS_ONCE(ads->ctl13) = 0;
35785- ACCESS_ONCE(ads->ctl14) = 0;
35786+ ACCESS_ONCE_RW(ads->ctl13) = 0;
35787+ ACCESS_ONCE_RW(ads->ctl14) = 0;
35788 }
35789
35790 ads->ctl20 = 0;
35791@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35792
35793 ctl17 = SM(i->keytype, AR_EncrType);
35794 if (!i->is_first) {
35795- ACCESS_ONCE(ads->ctl11) = 0;
35796- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35797- ACCESS_ONCE(ads->ctl15) = 0;
35798- ACCESS_ONCE(ads->ctl16) = 0;
35799- ACCESS_ONCE(ads->ctl17) = ctl17;
35800- ACCESS_ONCE(ads->ctl18) = 0;
35801- ACCESS_ONCE(ads->ctl19) = 0;
35802+ ACCESS_ONCE_RW(ads->ctl11) = 0;
35803+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35804+ ACCESS_ONCE_RW(ads->ctl15) = 0;
35805+ ACCESS_ONCE_RW(ads->ctl16) = 0;
35806+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35807+ ACCESS_ONCE_RW(ads->ctl18) = 0;
35808+ ACCESS_ONCE_RW(ads->ctl19) = 0;
35809 return;
35810 }
35811
35812- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35813+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35814 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35815 | SM(i->txpower, AR_XmitPower)
35816 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35817@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35818 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35819 ctl12 |= SM(val, AR_PAPRDChainMask);
35820
35821- ACCESS_ONCE(ads->ctl12) = ctl12;
35822- ACCESS_ONCE(ads->ctl17) = ctl17;
35823+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35824+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35825
35826- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35827+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35828 | set11nPktDurRTSCTS(i->rates, 1);
35829
35830- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35831+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35832 | set11nPktDurRTSCTS(i->rates, 3);
35833
35834- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35835+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35836 | set11nRateFlags(i->rates, 1)
35837 | set11nRateFlags(i->rates, 2)
35838 | set11nRateFlags(i->rates, 3)
35839 | SM(i->rtscts_rate, AR_RTSCTSRate);
35840
35841- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35842+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35843 }
35844
35845 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35846diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35847index 02f5007..bd0bd8f 100644
35848--- a/drivers/net/wireless/ath/ath9k/hw.h
35849+++ b/drivers/net/wireless/ath/ath9k/hw.h
35850@@ -610,7 +610,7 @@ struct ath_hw_private_ops {
35851
35852 /* ANI */
35853 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35854-};
35855+} __no_const;
35856
35857 /**
35858 * struct ath_hw_ops - callbacks used by hardware code and driver code
35859@@ -640,7 +640,7 @@ struct ath_hw_ops {
35860 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35861 struct ath_hw_antcomb_conf *antconf);
35862
35863-};
35864+} __no_const;
35865
35866 struct ath_nf_limits {
35867 s16 max;
35868@@ -660,7 +660,7 @@ enum ath_cal_list {
35869 #define AH_FASTCC 0x4
35870
35871 struct ath_hw {
35872- struct ath_ops reg_ops;
35873+ ath_ops_no_const reg_ops;
35874
35875 struct ieee80211_hw *hw;
35876 struct ath_common common;
35877diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35878index af00e2c..ab04d34 100644
35879--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35880+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35881@@ -545,7 +545,7 @@ struct phy_func_ptr {
35882 void (*carrsuppr)(struct brcms_phy *);
35883 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35884 void (*detach)(struct brcms_phy *);
35885-};
35886+} __no_const;
35887
35888 struct brcms_phy {
35889 struct brcms_phy_pub pubpi_ro;
35890diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35891index faec404..a5277f1 100644
35892--- a/drivers/net/wireless/iwlegacy/3945-mac.c
35893+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35894@@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35895 */
35896 if (il3945_mod_params.disable_hw_scan) {
35897 D_INFO("Disabling hw_scan\n");
35898- il3945_mac_ops.hw_scan = NULL;
35899+ pax_open_kernel();
35900+ *(void **)&il3945_mac_ops.hw_scan = NULL;
35901+ pax_close_kernel();
35902 }
35903
35904 D_INFO("*** LOAD DRIVER ***\n");
35905diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
35906index 5000690..a67f98a 100644
35907--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
35908+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
35909@@ -207,7 +207,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35910 {
35911 struct iwl_priv *priv = file->private_data;
35912 char buf[64];
35913- int buf_size;
35914+ size_t buf_size;
35915 u32 offset, len;
35916
35917 memset(buf, 0, sizeof(buf));
35918@@ -484,7 +484,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35919 struct iwl_priv *priv = file->private_data;
35920
35921 char buf[8];
35922- int buf_size;
35923+ size_t buf_size;
35924 u32 reset_flag;
35925
35926 memset(buf, 0, sizeof(buf));
35927@@ -565,7 +565,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35928 {
35929 struct iwl_priv *priv = file->private_data;
35930 char buf[8];
35931- int buf_size;
35932+ size_t buf_size;
35933 int ht40;
35934
35935 memset(buf, 0, sizeof(buf));
35936@@ -617,7 +617,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35937 {
35938 struct iwl_priv *priv = file->private_data;
35939 char buf[8];
35940- int buf_size;
35941+ size_t buf_size;
35942 int value;
35943
35944 memset(buf, 0, sizeof(buf));
35945@@ -1882,7 +1882,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35946 {
35947 struct iwl_priv *priv = file->private_data;
35948 char buf[8];
35949- int buf_size;
35950+ size_t buf_size;
35951 int clear;
35952
35953 memset(buf, 0, sizeof(buf));
35954@@ -1927,7 +1927,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35955 {
35956 struct iwl_priv *priv = file->private_data;
35957 char buf[8];
35958- int buf_size;
35959+ size_t buf_size;
35960 int trace;
35961
35962 memset(buf, 0, sizeof(buf));
35963@@ -1998,7 +1998,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
35964 {
35965 struct iwl_priv *priv = file->private_data;
35966 char buf[8];
35967- int buf_size;
35968+ size_t buf_size;
35969 int missed;
35970
35971 memset(buf, 0, sizeof(buf));
35972@@ -2039,7 +2039,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
35973
35974 struct iwl_priv *priv = file->private_data;
35975 char buf[8];
35976- int buf_size;
35977+ size_t buf_size;
35978 int plcp;
35979
35980 memset(buf, 0, sizeof(buf));
35981@@ -2099,7 +2099,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
35982
35983 struct iwl_priv *priv = file->private_data;
35984 char buf[8];
35985- int buf_size;
35986+ size_t buf_size;
35987 int flush;
35988
35989 memset(buf, 0, sizeof(buf));
35990@@ -2189,7 +2189,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35991
35992 struct iwl_priv *priv = file->private_data;
35993 char buf[8];
35994- int buf_size;
35995+ size_t buf_size;
35996 int rts;
35997
35998 if (!priv->cfg->ht_params)
35999@@ -2231,7 +2231,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
36000 {
36001 struct iwl_priv *priv = file->private_data;
36002 char buf[8];
36003- int buf_size;
36004+ size_t buf_size;
36005
36006 memset(buf, 0, sizeof(buf));
36007 buf_size = min(count, sizeof(buf) - 1);
36008@@ -2267,7 +2267,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
36009 struct iwl_priv *priv = file->private_data;
36010 u32 event_log_flag;
36011 char buf[8];
36012- int buf_size;
36013+ size_t buf_size;
36014
36015 memset(buf, 0, sizeof(buf));
36016 buf_size = min(count, sizeof(buf) - 1);
36017@@ -2317,7 +2317,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
36018 struct iwl_priv *priv = file->private_data;
36019 char buf[8];
36020 u32 calib_disabled;
36021- int buf_size;
36022+ size_t buf_size;
36023
36024 memset(buf, 0, sizeof(buf));
36025 buf_size = min(count, sizeof(buf) - 1);
36026diff --git a/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c b/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c
36027index a1fb025..378e8a5 100644
36028--- a/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c
36029+++ b/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c
36030@@ -1951,7 +1951,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
36031 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
36032
36033 char buf[8];
36034- int buf_size;
36035+ size_t buf_size;
36036 u32 reset_flag;
36037
36038 memset(buf, 0, sizeof(buf));
36039@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
36040 {
36041 struct iwl_trans *trans = file->private_data;
36042 char buf[8];
36043- int buf_size;
36044+ size_t buf_size;
36045 int csr;
36046
36047 memset(buf, 0, sizeof(buf));
36048diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36049index a0b7cfd..20b49f7 100644
36050--- a/drivers/net/wireless/mac80211_hwsim.c
36051+++ b/drivers/net/wireless/mac80211_hwsim.c
36052@@ -1752,9 +1752,11 @@ static int __init init_mac80211_hwsim(void)
36053 return -EINVAL;
36054
36055 if (fake_hw_scan) {
36056- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36057- mac80211_hwsim_ops.sw_scan_start = NULL;
36058- mac80211_hwsim_ops.sw_scan_complete = NULL;
36059+ pax_open_kernel();
36060+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36061+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36062+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36063+ pax_close_kernel();
36064 }
36065
36066 spin_lock_init(&hwsim_radio_lock);
36067diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
36068index bd3b0bf..f9db92a 100644
36069--- a/drivers/net/wireless/mwifiex/main.h
36070+++ b/drivers/net/wireless/mwifiex/main.h
36071@@ -567,7 +567,7 @@ struct mwifiex_if_ops {
36072 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
36073 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
36074 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
36075-};
36076+} __no_const;
36077
36078 struct mwifiex_adapter {
36079 u8 iface_type;
36080diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36081index dfcd02a..a42a59d 100644
36082--- a/drivers/net/wireless/rndis_wlan.c
36083+++ b/drivers/net/wireless/rndis_wlan.c
36084@@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36085
36086 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36087
36088- if (rts_threshold < 0 || rts_threshold > 2347)
36089+ if (rts_threshold > 2347)
36090 rts_threshold = 2347;
36091
36092 tmp = cpu_to_le32(rts_threshold);
36093diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
36094index 8f75402..eed109d 100644
36095--- a/drivers/net/wireless/rt2x00/rt2x00.h
36096+++ b/drivers/net/wireless/rt2x00/rt2x00.h
36097@@ -396,7 +396,7 @@ struct rt2x00_intf {
36098 * for hardware which doesn't support hardware
36099 * sequence counting.
36100 */
36101- atomic_t seqno;
36102+ atomic_unchecked_t seqno;
36103 };
36104
36105 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
36106diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
36107index 2fd8301..9767e8c 100644
36108--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
36109+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
36110@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
36111 * sequence counter given by mac80211.
36112 */
36113 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
36114- seqno = atomic_add_return(0x10, &intf->seqno);
36115+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
36116 else
36117- seqno = atomic_read(&intf->seqno);
36118+ seqno = atomic_read_unchecked(&intf->seqno);
36119
36120 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36121 hdr->seq_ctrl |= cpu_to_le16(seqno);
36122diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
36123index 9d8f581..0f6589e 100644
36124--- a/drivers/net/wireless/ti/wl1251/wl1251.h
36125+++ b/drivers/net/wireless/ti/wl1251/wl1251.h
36126@@ -266,7 +266,7 @@ struct wl1251_if_operations {
36127 void (*reset)(struct wl1251 *wl);
36128 void (*enable_irq)(struct wl1251 *wl);
36129 void (*disable_irq)(struct wl1251 *wl);
36130-};
36131+} __no_const;
36132
36133 struct wl1251 {
36134 struct ieee80211_hw *hw;
36135diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36136index 0b3f0b5..62f68bd 100644
36137--- a/drivers/net/wireless/ti/wlcore/wlcore.h
36138+++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36139@@ -61,7 +61,7 @@ struct wlcore_ops {
36140 struct wl12xx_vif *wlvif);
36141 s8 (*get_pg_ver)(struct wl1271 *wl);
36142 void (*get_mac)(struct wl1271 *wl);
36143-};
36144+} __no_const;
36145
36146 enum wlcore_partitions {
36147 PART_DOWN,
36148diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36149index f34b5b2..b5abb9f 100644
36150--- a/drivers/oprofile/buffer_sync.c
36151+++ b/drivers/oprofile/buffer_sync.c
36152@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36153 if (cookie == NO_COOKIE)
36154 offset = pc;
36155 if (cookie == INVALID_COOKIE) {
36156- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36157+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36158 offset = pc;
36159 }
36160 if (cookie != last_cookie) {
36161@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36162 /* add userspace sample */
36163
36164 if (!mm) {
36165- atomic_inc(&oprofile_stats.sample_lost_no_mm);
36166+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36167 return 0;
36168 }
36169
36170 cookie = lookup_dcookie(mm, s->eip, &offset);
36171
36172 if (cookie == INVALID_COOKIE) {
36173- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36174+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36175 return 0;
36176 }
36177
36178@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36179 /* ignore backtraces if failed to add a sample */
36180 if (state == sb_bt_start) {
36181 state = sb_bt_ignore;
36182- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36183+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36184 }
36185 }
36186 release_mm(mm);
36187diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36188index c0cc4e7..44d4e54 100644
36189--- a/drivers/oprofile/event_buffer.c
36190+++ b/drivers/oprofile/event_buffer.c
36191@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36192 }
36193
36194 if (buffer_pos == buffer_size) {
36195- atomic_inc(&oprofile_stats.event_lost_overflow);
36196+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36197 return;
36198 }
36199
36200diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36201index ed2c3ec..deda85a 100644
36202--- a/drivers/oprofile/oprof.c
36203+++ b/drivers/oprofile/oprof.c
36204@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36205 if (oprofile_ops.switch_events())
36206 return;
36207
36208- atomic_inc(&oprofile_stats.multiplex_counter);
36209+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36210 start_switch_worker();
36211 }
36212
36213diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36214index 917d28e..d62d981 100644
36215--- a/drivers/oprofile/oprofile_stats.c
36216+++ b/drivers/oprofile/oprofile_stats.c
36217@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36218 cpu_buf->sample_invalid_eip = 0;
36219 }
36220
36221- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36222- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36223- atomic_set(&oprofile_stats.event_lost_overflow, 0);
36224- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36225- atomic_set(&oprofile_stats.multiplex_counter, 0);
36226+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36227+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36228+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36229+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36230+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36231 }
36232
36233
36234diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36235index 38b6fc0..b5cbfce 100644
36236--- a/drivers/oprofile/oprofile_stats.h
36237+++ b/drivers/oprofile/oprofile_stats.h
36238@@ -13,11 +13,11 @@
36239 #include <linux/atomic.h>
36240
36241 struct oprofile_stat_struct {
36242- atomic_t sample_lost_no_mm;
36243- atomic_t sample_lost_no_mapping;
36244- atomic_t bt_lost_no_mapping;
36245- atomic_t event_lost_overflow;
36246- atomic_t multiplex_counter;
36247+ atomic_unchecked_t sample_lost_no_mm;
36248+ atomic_unchecked_t sample_lost_no_mapping;
36249+ atomic_unchecked_t bt_lost_no_mapping;
36250+ atomic_unchecked_t event_lost_overflow;
36251+ atomic_unchecked_t multiplex_counter;
36252 };
36253
36254 extern struct oprofile_stat_struct oprofile_stats;
36255diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36256index 849357c..b83c1e0 100644
36257--- a/drivers/oprofile/oprofilefs.c
36258+++ b/drivers/oprofile/oprofilefs.c
36259@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36260
36261
36262 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36263- char const *name, atomic_t *val)
36264+ char const *name, atomic_unchecked_t *val)
36265 {
36266 return __oprofilefs_create_file(sb, root, name,
36267 &atomic_ro_fops, 0444, val);
36268diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36269index 3f56bc0..707d642 100644
36270--- a/drivers/parport/procfs.c
36271+++ b/drivers/parport/procfs.c
36272@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36273
36274 *ppos += len;
36275
36276- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36277+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36278 }
36279
36280 #ifdef CONFIG_PARPORT_1284
36281@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36282
36283 *ppos += len;
36284
36285- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36286+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36287 }
36288 #endif /* IEEE1284.3 support. */
36289
36290diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36291index 9fff878..ad0ad53 100644
36292--- a/drivers/pci/hotplug/cpci_hotplug.h
36293+++ b/drivers/pci/hotplug/cpci_hotplug.h
36294@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36295 int (*hardware_test) (struct slot* slot, u32 value);
36296 u8 (*get_power) (struct slot* slot);
36297 int (*set_power) (struct slot* slot, int value);
36298-};
36299+} __no_const;
36300
36301 struct cpci_hp_controller {
36302 unsigned int irq;
36303diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36304index 76ba8a1..20ca857 100644
36305--- a/drivers/pci/hotplug/cpqphp_nvram.c
36306+++ b/drivers/pci/hotplug/cpqphp_nvram.c
36307@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36308
36309 void compaq_nvram_init (void __iomem *rom_start)
36310 {
36311+
36312+#ifndef CONFIG_PAX_KERNEXEC
36313 if (rom_start) {
36314 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36315 }
36316+#endif
36317+
36318 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36319
36320 /* initialize our int15 lock */
36321diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36322index b500840..d7159d3 100644
36323--- a/drivers/pci/pcie/aspm.c
36324+++ b/drivers/pci/pcie/aspm.c
36325@@ -27,9 +27,9 @@
36326 #define MODULE_PARAM_PREFIX "pcie_aspm."
36327
36328 /* Note: those are not register definitions */
36329-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36330-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36331-#define ASPM_STATE_L1 (4) /* L1 state */
36332+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36333+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36334+#define ASPM_STATE_L1 (4U) /* L1 state */
36335 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36336 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36337
36338diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36339index 658ac97..05e1b90 100644
36340--- a/drivers/pci/probe.c
36341+++ b/drivers/pci/probe.c
36342@@ -137,7 +137,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36343 u16 orig_cmd;
36344 struct pci_bus_region region;
36345
36346- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36347+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36348
36349 if (!dev->mmio_always_on) {
36350 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36351diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36352index 27911b5..5b6db88 100644
36353--- a/drivers/pci/proc.c
36354+++ b/drivers/pci/proc.c
36355@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36356 static int __init pci_proc_init(void)
36357 {
36358 struct pci_dev *dev = NULL;
36359+
36360+#ifdef CONFIG_GRKERNSEC_PROC_ADD
36361+#ifdef CONFIG_GRKERNSEC_PROC_USER
36362+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36363+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36364+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36365+#endif
36366+#else
36367 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36368+#endif
36369 proc_create("devices", 0, proc_bus_pci_dir,
36370 &proc_bus_pci_dev_operations);
36371 proc_initialized = 1;
36372diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36373index 8b5610d..a4c22bb 100644
36374--- a/drivers/platform/x86/thinkpad_acpi.c
36375+++ b/drivers/platform/x86/thinkpad_acpi.c
36376@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
36377 return 0;
36378 }
36379
36380-void static hotkey_mask_warn_incomplete_mask(void)
36381+static void hotkey_mask_warn_incomplete_mask(void)
36382 {
36383 /* log only what the user can fix... */
36384 const u32 wantedmask = hotkey_driver_mask &
36385@@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36386 }
36387 }
36388
36389-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36390- struct tp_nvram_state *newn,
36391- const u32 event_mask)
36392-{
36393-
36394 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36395 do { \
36396 if ((event_mask & (1 << __scancode)) && \
36397@@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36398 tpacpi_hotkey_send_key(__scancode); \
36399 } while (0)
36400
36401- void issue_volchange(const unsigned int oldvol,
36402- const unsigned int newvol)
36403- {
36404- unsigned int i = oldvol;
36405+static void issue_volchange(const unsigned int oldvol,
36406+ const unsigned int newvol,
36407+ const u32 event_mask)
36408+{
36409+ unsigned int i = oldvol;
36410
36411- while (i > newvol) {
36412- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36413- i--;
36414- }
36415- while (i < newvol) {
36416- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36417- i++;
36418- }
36419+ while (i > newvol) {
36420+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36421+ i--;
36422 }
36423+ while (i < newvol) {
36424+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36425+ i++;
36426+ }
36427+}
36428
36429- void issue_brightnesschange(const unsigned int oldbrt,
36430- const unsigned int newbrt)
36431- {
36432- unsigned int i = oldbrt;
36433+static void issue_brightnesschange(const unsigned int oldbrt,
36434+ const unsigned int newbrt,
36435+ const u32 event_mask)
36436+{
36437+ unsigned int i = oldbrt;
36438
36439- while (i > newbrt) {
36440- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36441- i--;
36442- }
36443- while (i < newbrt) {
36444- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36445- i++;
36446- }
36447+ while (i > newbrt) {
36448+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36449+ i--;
36450+ }
36451+ while (i < newbrt) {
36452+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36453+ i++;
36454 }
36455+}
36456
36457+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36458+ struct tp_nvram_state *newn,
36459+ const u32 event_mask)
36460+{
36461 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36462 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36463 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36464@@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36465 oldn->volume_level != newn->volume_level) {
36466 /* recently muted, or repeated mute keypress, or
36467 * multiple presses ending in mute */
36468- issue_volchange(oldn->volume_level, newn->volume_level);
36469+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36470 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36471 }
36472 } else {
36473@@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36474 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36475 }
36476 if (oldn->volume_level != newn->volume_level) {
36477- issue_volchange(oldn->volume_level, newn->volume_level);
36478+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36479 } else if (oldn->volume_toggle != newn->volume_toggle) {
36480 /* repeated vol up/down keypress at end of scale ? */
36481 if (newn->volume_level == 0)
36482@@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36483 /* handle brightness */
36484 if (oldn->brightness_level != newn->brightness_level) {
36485 issue_brightnesschange(oldn->brightness_level,
36486- newn->brightness_level);
36487+ newn->brightness_level,
36488+ event_mask);
36489 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36490 /* repeated key presses that didn't change state */
36491 if (newn->brightness_level == 0)
36492@@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36493 && !tp_features.bright_unkfw)
36494 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36495 }
36496+}
36497
36498 #undef TPACPI_COMPARE_KEY
36499 #undef TPACPI_MAY_SEND_KEY
36500-}
36501
36502 /*
36503 * Polling driver
36504diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36505index 769d265..a3a05ca 100644
36506--- a/drivers/pnp/pnpbios/bioscalls.c
36507+++ b/drivers/pnp/pnpbios/bioscalls.c
36508@@ -58,7 +58,7 @@ do { \
36509 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36510 } while(0)
36511
36512-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36513+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36514 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36515
36516 /*
36517@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36518
36519 cpu = get_cpu();
36520 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36521+
36522+ pax_open_kernel();
36523 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36524+ pax_close_kernel();
36525
36526 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36527 spin_lock_irqsave(&pnp_bios_lock, flags);
36528@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36529 :"memory");
36530 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36531
36532+ pax_open_kernel();
36533 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36534+ pax_close_kernel();
36535+
36536 put_cpu();
36537
36538 /* If we get here and this is set then the PnP BIOS faulted on us. */
36539@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36540 return status;
36541 }
36542
36543-void pnpbios_calls_init(union pnp_bios_install_struct *header)
36544+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36545 {
36546 int i;
36547
36548@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36549 pnp_bios_callpoint.offset = header->fields.pm16offset;
36550 pnp_bios_callpoint.segment = PNP_CS16;
36551
36552+ pax_open_kernel();
36553+
36554 for_each_possible_cpu(i) {
36555 struct desc_struct *gdt = get_cpu_gdt_table(i);
36556 if (!gdt)
36557@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36558 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36559 (unsigned long)__va(header->fields.pm16dseg));
36560 }
36561+
36562+ pax_close_kernel();
36563 }
36564diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36565index b0ecacb..7c9da2e 100644
36566--- a/drivers/pnp/resource.c
36567+++ b/drivers/pnp/resource.c
36568@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36569 return 1;
36570
36571 /* check if the resource is valid */
36572- if (*irq < 0 || *irq > 15)
36573+ if (*irq > 15)
36574 return 0;
36575
36576 /* check if the resource is reserved */
36577@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36578 return 1;
36579
36580 /* check if the resource is valid */
36581- if (*dma < 0 || *dma == 4 || *dma > 7)
36582+ if (*dma == 4 || *dma > 7)
36583 return 0;
36584
36585 /* check if the resource is reserved */
36586diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36587index f5d6d37..739f6a9 100644
36588--- a/drivers/power/bq27x00_battery.c
36589+++ b/drivers/power/bq27x00_battery.c
36590@@ -72,7 +72,7 @@
36591 struct bq27x00_device_info;
36592 struct bq27x00_access_methods {
36593 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36594-};
36595+} __no_const;
36596
36597 enum bq27x00_chip { BQ27000, BQ27500 };
36598
36599diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36600index 8d53174..04c65de 100644
36601--- a/drivers/regulator/max8660.c
36602+++ b/drivers/regulator/max8660.c
36603@@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36604 max8660->shadow_regs[MAX8660_OVER1] = 5;
36605 } else {
36606 /* Otherwise devices can be toggled via software */
36607- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36608- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36609+ pax_open_kernel();
36610+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36611+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36612+ pax_close_kernel();
36613 }
36614
36615 /*
36616diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36617index 970a233..ee1f241 100644
36618--- a/drivers/regulator/mc13892-regulator.c
36619+++ b/drivers/regulator/mc13892-regulator.c
36620@@ -566,10 +566,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36621 }
36622 mc13xxx_unlock(mc13892);
36623
36624- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36625+ pax_open_kernel();
36626+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36627 = mc13892_vcam_set_mode;
36628- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36629+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36630 = mc13892_vcam_get_mode;
36631+ pax_close_kernel();
36632
36633 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36634 ARRAY_SIZE(mc13892_regulators));
36635diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36636index cace6d3..f623fda 100644
36637--- a/drivers/rtc/rtc-dev.c
36638+++ b/drivers/rtc/rtc-dev.c
36639@@ -14,6 +14,7 @@
36640 #include <linux/module.h>
36641 #include <linux/rtc.h>
36642 #include <linux/sched.h>
36643+#include <linux/grsecurity.h>
36644 #include "rtc-core.h"
36645
36646 static dev_t rtc_devt;
36647@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36648 if (copy_from_user(&tm, uarg, sizeof(tm)))
36649 return -EFAULT;
36650
36651+ gr_log_timechange();
36652+
36653 return rtc_set_time(rtc, &tm);
36654
36655 case RTC_PIE_ON:
36656diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36657index 3fcf627..f334910 100644
36658--- a/drivers/scsi/aacraid/aacraid.h
36659+++ b/drivers/scsi/aacraid/aacraid.h
36660@@ -492,7 +492,7 @@ struct adapter_ops
36661 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36662 /* Administrative operations */
36663 int (*adapter_comm)(struct aac_dev * dev, int comm);
36664-};
36665+} __no_const;
36666
36667 /*
36668 * Define which interrupt handler needs to be installed
36669diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36670index 0d279c44..3d25a97 100644
36671--- a/drivers/scsi/aacraid/linit.c
36672+++ b/drivers/scsi/aacraid/linit.c
36673@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36674 #elif defined(__devinitconst)
36675 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36676 #else
36677-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36678+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36679 #endif
36680 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36681 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36682diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36683index ff80552..1c4120c 100644
36684--- a/drivers/scsi/aic94xx/aic94xx_init.c
36685+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36686@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36687 .lldd_ata_set_dmamode = asd_set_dmamode,
36688 };
36689
36690-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36691+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36692 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36693 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36694 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36695diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36696index 4ad7e36..d004679 100644
36697--- a/drivers/scsi/bfa/bfa.h
36698+++ b/drivers/scsi/bfa/bfa.h
36699@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36700 u32 *end);
36701 int cpe_vec_q0;
36702 int rme_vec_q0;
36703-};
36704+} __no_const;
36705 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36706
36707 struct bfa_faa_cbfn_s {
36708diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36709index f0f80e2..8ec946b 100644
36710--- a/drivers/scsi/bfa/bfa_fcpim.c
36711+++ b/drivers/scsi/bfa/bfa_fcpim.c
36712@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36713
36714 bfa_iotag_attach(fcp);
36715
36716- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36717+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36718 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36719 (fcp->num_itns * sizeof(struct bfa_itn_s));
36720 memset(fcp->itn_arr, 0,
36721@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36722 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36723 {
36724 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36725- struct bfa_itn_s *itn;
36726+ bfa_itn_s_no_const *itn;
36727
36728 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36729 itn->isr = isr;
36730diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36731index 36f26da..38a34a8 100644
36732--- a/drivers/scsi/bfa/bfa_fcpim.h
36733+++ b/drivers/scsi/bfa/bfa_fcpim.h
36734@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36735 struct bfa_itn_s {
36736 bfa_isr_func_t isr;
36737 };
36738+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36739
36740 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36741 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36742@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36743 struct list_head iotag_tio_free_q; /* free IO resources */
36744 struct list_head iotag_unused_q; /* unused IO resources*/
36745 struct bfa_iotag_s *iotag_arr;
36746- struct bfa_itn_s *itn_arr;
36747+ bfa_itn_s_no_const *itn_arr;
36748 int num_ioim_reqs;
36749 int num_fwtio_reqs;
36750 int num_itns;
36751diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36752index 1a99d4b..e85d64b 100644
36753--- a/drivers/scsi/bfa/bfa_ioc.h
36754+++ b/drivers/scsi/bfa/bfa_ioc.h
36755@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36756 bfa_ioc_disable_cbfn_t disable_cbfn;
36757 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36758 bfa_ioc_reset_cbfn_t reset_cbfn;
36759-};
36760+} __no_const;
36761
36762 /*
36763 * IOC event notification mechanism.
36764@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36765 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36766 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36767 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36768-};
36769+} __no_const;
36770
36771 /*
36772 * Queue element to wait for room in request queue. FIFO order is
36773diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36774index b48c24f..dac0fbc 100644
36775--- a/drivers/scsi/hosts.c
36776+++ b/drivers/scsi/hosts.c
36777@@ -42,7 +42,7 @@
36778 #include "scsi_logging.h"
36779
36780
36781-static atomic_t scsi_host_next_hn; /* host_no for next new host */
36782+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36783
36784
36785 static void scsi_host_cls_release(struct device *dev)
36786@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36787 * subtract one because we increment first then return, but we need to
36788 * know what the next host number was before increment
36789 */
36790- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36791+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36792 shost->dma_channel = 0xff;
36793
36794 /* These three are default values which can be overridden */
36795diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36796index f9823f2..7bc3e81 100644
36797--- a/drivers/scsi/hpsa.c
36798+++ b/drivers/scsi/hpsa.c
36799@@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36800 unsigned long flags;
36801
36802 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36803- return h->access.command_completed(h, q);
36804+ return h->access->command_completed(h, q);
36805
36806 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36807 a = rq->head[rq->current_entry];
36808@@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
36809 while (!list_empty(&h->reqQ)) {
36810 c = list_entry(h->reqQ.next, struct CommandList, list);
36811 /* can't do anything if fifo is full */
36812- if ((h->access.fifo_full(h))) {
36813+ if ((h->access->fifo_full(h))) {
36814 dev_warn(&h->pdev->dev, "fifo full\n");
36815 break;
36816 }
36817@@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
36818
36819 /* Tell the controller execute command */
36820 spin_unlock_irqrestore(&h->lock, flags);
36821- h->access.submit_command(h, c);
36822+ h->access->submit_command(h, c);
36823 spin_lock_irqsave(&h->lock, flags);
36824 }
36825 spin_unlock_irqrestore(&h->lock, flags);
36826@@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
36827
36828 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36829 {
36830- return h->access.command_completed(h, q);
36831+ return h->access->command_completed(h, q);
36832 }
36833
36834 static inline bool interrupt_pending(struct ctlr_info *h)
36835 {
36836- return h->access.intr_pending(h);
36837+ return h->access->intr_pending(h);
36838 }
36839
36840 static inline long interrupt_not_for_us(struct ctlr_info *h)
36841 {
36842- return (h->access.intr_pending(h) == 0) ||
36843+ return (h->access->intr_pending(h) == 0) ||
36844 (h->interrupts_enabled == 0);
36845 }
36846
36847@@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36848 if (prod_index < 0)
36849 return -ENODEV;
36850 h->product_name = products[prod_index].product_name;
36851- h->access = *(products[prod_index].access);
36852+ h->access = products[prod_index].access;
36853
36854 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36855 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36856@@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36857
36858 assert_spin_locked(&lockup_detector_lock);
36859 remove_ctlr_from_lockup_detector_list(h);
36860- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36861+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36862 spin_lock_irqsave(&h->lock, flags);
36863 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36864 spin_unlock_irqrestore(&h->lock, flags);
36865@@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
36866 }
36867
36868 /* make sure the board interrupts are off */
36869- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36870+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36871
36872 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36873 goto clean2;
36874@@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
36875 * fake ones to scoop up any residual completions.
36876 */
36877 spin_lock_irqsave(&h->lock, flags);
36878- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36879+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36880 spin_unlock_irqrestore(&h->lock, flags);
36881 free_irqs(h);
36882 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36883@@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
36884 dev_info(&h->pdev->dev, "Board READY.\n");
36885 dev_info(&h->pdev->dev,
36886 "Waiting for stale completions to drain.\n");
36887- h->access.set_intr_mask(h, HPSA_INTR_ON);
36888+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36889 msleep(10000);
36890- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36891+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36892
36893 rc = controller_reset_failed(h->cfgtable);
36894 if (rc)
36895@@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
36896 }
36897
36898 /* Turn the interrupts on so we can service requests */
36899- h->access.set_intr_mask(h, HPSA_INTR_ON);
36900+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36901
36902 hpsa_hba_inquiry(h);
36903 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36904@@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36905 * To write all data in the battery backed cache to disks
36906 */
36907 hpsa_flush_cache(h);
36908- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36909+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36910 hpsa_free_irqs_and_disable_msix(h);
36911 }
36912
36913@@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36914 return;
36915 }
36916 /* Change the access methods to the performant access methods */
36917- h->access = SA5_performant_access;
36918+ h->access = &SA5_performant_access;
36919 h->transMethod = CFGTBL_Trans_Performant;
36920 }
36921
36922diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36923index 9816479..c5d4e97 100644
36924--- a/drivers/scsi/hpsa.h
36925+++ b/drivers/scsi/hpsa.h
36926@@ -79,7 +79,7 @@ struct ctlr_info {
36927 unsigned int msix_vector;
36928 unsigned int msi_vector;
36929 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36930- struct access_method access;
36931+ struct access_method *access;
36932
36933 /* queue and queue Info */
36934 struct list_head reqQ;
36935diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36936index f2df059..a3a9930 100644
36937--- a/drivers/scsi/ips.h
36938+++ b/drivers/scsi/ips.h
36939@@ -1027,7 +1027,7 @@ typedef struct {
36940 int (*intr)(struct ips_ha *);
36941 void (*enableint)(struct ips_ha *);
36942 uint32_t (*statupd)(struct ips_ha *);
36943-} ips_hw_func_t;
36944+} __no_const ips_hw_func_t;
36945
36946 typedef struct ips_ha {
36947 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36948diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36949index aceffad..c35c08d 100644
36950--- a/drivers/scsi/libfc/fc_exch.c
36951+++ b/drivers/scsi/libfc/fc_exch.c
36952@@ -105,12 +105,12 @@ struct fc_exch_mgr {
36953 * all together if not used XXX
36954 */
36955 struct {
36956- atomic_t no_free_exch;
36957- atomic_t no_free_exch_xid;
36958- atomic_t xid_not_found;
36959- atomic_t xid_busy;
36960- atomic_t seq_not_found;
36961- atomic_t non_bls_resp;
36962+ atomic_unchecked_t no_free_exch;
36963+ atomic_unchecked_t no_free_exch_xid;
36964+ atomic_unchecked_t xid_not_found;
36965+ atomic_unchecked_t xid_busy;
36966+ atomic_unchecked_t seq_not_found;
36967+ atomic_unchecked_t non_bls_resp;
36968 } stats;
36969 };
36970
36971@@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36972 /* allocate memory for exchange */
36973 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36974 if (!ep) {
36975- atomic_inc(&mp->stats.no_free_exch);
36976+ atomic_inc_unchecked(&mp->stats.no_free_exch);
36977 goto out;
36978 }
36979 memset(ep, 0, sizeof(*ep));
36980@@ -780,7 +780,7 @@ out:
36981 return ep;
36982 err:
36983 spin_unlock_bh(&pool->lock);
36984- atomic_inc(&mp->stats.no_free_exch_xid);
36985+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36986 mempool_free(ep, mp->ep_pool);
36987 return NULL;
36988 }
36989@@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36990 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36991 ep = fc_exch_find(mp, xid);
36992 if (!ep) {
36993- atomic_inc(&mp->stats.xid_not_found);
36994+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36995 reject = FC_RJT_OX_ID;
36996 goto out;
36997 }
36998@@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36999 ep = fc_exch_find(mp, xid);
37000 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
37001 if (ep) {
37002- atomic_inc(&mp->stats.xid_busy);
37003+ atomic_inc_unchecked(&mp->stats.xid_busy);
37004 reject = FC_RJT_RX_ID;
37005 goto rel;
37006 }
37007@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37008 }
37009 xid = ep->xid; /* get our XID */
37010 } else if (!ep) {
37011- atomic_inc(&mp->stats.xid_not_found);
37012+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37013 reject = FC_RJT_RX_ID; /* XID not found */
37014 goto out;
37015 }
37016@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37017 } else {
37018 sp = &ep->seq;
37019 if (sp->id != fh->fh_seq_id) {
37020- atomic_inc(&mp->stats.seq_not_found);
37021+ atomic_inc_unchecked(&mp->stats.seq_not_found);
37022 if (f_ctl & FC_FC_END_SEQ) {
37023 /*
37024 * Update sequence_id based on incoming last
37025@@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37026
37027 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37028 if (!ep) {
37029- atomic_inc(&mp->stats.xid_not_found);
37030+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37031 goto out;
37032 }
37033 if (ep->esb_stat & ESB_ST_COMPLETE) {
37034- atomic_inc(&mp->stats.xid_not_found);
37035+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37036 goto rel;
37037 }
37038 if (ep->rxid == FC_XID_UNKNOWN)
37039 ep->rxid = ntohs(fh->fh_rx_id);
37040 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37041- atomic_inc(&mp->stats.xid_not_found);
37042+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37043 goto rel;
37044 }
37045 if (ep->did != ntoh24(fh->fh_s_id) &&
37046 ep->did != FC_FID_FLOGI) {
37047- atomic_inc(&mp->stats.xid_not_found);
37048+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37049 goto rel;
37050 }
37051 sof = fr_sof(fp);
37052@@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37053 sp->ssb_stat |= SSB_ST_RESP;
37054 sp->id = fh->fh_seq_id;
37055 } else if (sp->id != fh->fh_seq_id) {
37056- atomic_inc(&mp->stats.seq_not_found);
37057+ atomic_inc_unchecked(&mp->stats.seq_not_found);
37058 goto rel;
37059 }
37060
37061@@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37062 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37063
37064 if (!sp)
37065- atomic_inc(&mp->stats.xid_not_found);
37066+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37067 else
37068- atomic_inc(&mp->stats.non_bls_resp);
37069+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
37070
37071 fc_frame_free(fp);
37072 }
37073diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37074index d109cc3..09f4e7d 100644
37075--- a/drivers/scsi/libsas/sas_ata.c
37076+++ b/drivers/scsi/libsas/sas_ata.c
37077@@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
37078 .postreset = ata_std_postreset,
37079 .error_handler = ata_std_error_handler,
37080 .post_internal_cmd = sas_ata_post_internal,
37081- .qc_defer = ata_std_qc_defer,
37082+ .qc_defer = ata_std_qc_defer,
37083 .qc_prep = ata_noop_qc_prep,
37084 .qc_issue = sas_ata_qc_issue,
37085 .qc_fill_rtf = sas_ata_qc_fill_rtf,
37086diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
37087index e5da6da..c888d48 100644
37088--- a/drivers/scsi/lpfc/lpfc.h
37089+++ b/drivers/scsi/lpfc/lpfc.h
37090@@ -416,7 +416,7 @@ struct lpfc_vport {
37091 struct dentry *debug_nodelist;
37092 struct dentry *vport_debugfs_root;
37093 struct lpfc_debugfs_trc *disc_trc;
37094- atomic_t disc_trc_cnt;
37095+ atomic_unchecked_t disc_trc_cnt;
37096 #endif
37097 uint8_t stat_data_enabled;
37098 uint8_t stat_data_blocked;
37099@@ -830,8 +830,8 @@ struct lpfc_hba {
37100 struct timer_list fabric_block_timer;
37101 unsigned long bit_flags;
37102 #define FABRIC_COMANDS_BLOCKED 0
37103- atomic_t num_rsrc_err;
37104- atomic_t num_cmd_success;
37105+ atomic_unchecked_t num_rsrc_err;
37106+ atomic_unchecked_t num_cmd_success;
37107 unsigned long last_rsrc_error_time;
37108 unsigned long last_ramp_down_time;
37109 unsigned long last_ramp_up_time;
37110@@ -867,7 +867,7 @@ struct lpfc_hba {
37111
37112 struct dentry *debug_slow_ring_trc;
37113 struct lpfc_debugfs_trc *slow_ring_trc;
37114- atomic_t slow_ring_trc_cnt;
37115+ atomic_unchecked_t slow_ring_trc_cnt;
37116 /* iDiag debugfs sub-directory */
37117 struct dentry *idiag_root;
37118 struct dentry *idiag_pci_cfg;
37119diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37120index 3217d63..c417981 100644
37121--- a/drivers/scsi/lpfc/lpfc_debugfs.c
37122+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37123@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37124
37125 #include <linux/debugfs.h>
37126
37127-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37128+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37129 static unsigned long lpfc_debugfs_start_time = 0L;
37130
37131 /* iDiag */
37132@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37133 lpfc_debugfs_enable = 0;
37134
37135 len = 0;
37136- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37137+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37138 (lpfc_debugfs_max_disc_trc - 1);
37139 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37140 dtp = vport->disc_trc + i;
37141@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37142 lpfc_debugfs_enable = 0;
37143
37144 len = 0;
37145- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37146+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37147 (lpfc_debugfs_max_slow_ring_trc - 1);
37148 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37149 dtp = phba->slow_ring_trc + i;
37150@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37151 !vport || !vport->disc_trc)
37152 return;
37153
37154- index = atomic_inc_return(&vport->disc_trc_cnt) &
37155+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37156 (lpfc_debugfs_max_disc_trc - 1);
37157 dtp = vport->disc_trc + index;
37158 dtp->fmt = fmt;
37159 dtp->data1 = data1;
37160 dtp->data2 = data2;
37161 dtp->data3 = data3;
37162- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37163+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37164 dtp->jif = jiffies;
37165 #endif
37166 return;
37167@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37168 !phba || !phba->slow_ring_trc)
37169 return;
37170
37171- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37172+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37173 (lpfc_debugfs_max_slow_ring_trc - 1);
37174 dtp = phba->slow_ring_trc + index;
37175 dtp->fmt = fmt;
37176 dtp->data1 = data1;
37177 dtp->data2 = data2;
37178 dtp->data3 = data3;
37179- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37180+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37181 dtp->jif = jiffies;
37182 #endif
37183 return;
37184@@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37185 "slow_ring buffer\n");
37186 goto debug_failed;
37187 }
37188- atomic_set(&phba->slow_ring_trc_cnt, 0);
37189+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37190 memset(phba->slow_ring_trc, 0,
37191 (sizeof(struct lpfc_debugfs_trc) *
37192 lpfc_debugfs_max_slow_ring_trc));
37193@@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37194 "buffer\n");
37195 goto debug_failed;
37196 }
37197- atomic_set(&vport->disc_trc_cnt, 0);
37198+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37199
37200 snprintf(name, sizeof(name), "discovery_trace");
37201 vport->debug_disc_trc =
37202diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37203index 411ed48..967f553 100644
37204--- a/drivers/scsi/lpfc/lpfc_init.c
37205+++ b/drivers/scsi/lpfc/lpfc_init.c
37206@@ -10341,8 +10341,10 @@ lpfc_init(void)
37207 "misc_register returned with status %d", error);
37208
37209 if (lpfc_enable_npiv) {
37210- lpfc_transport_functions.vport_create = lpfc_vport_create;
37211- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37212+ pax_open_kernel();
37213+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37214+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37215+ pax_close_kernel();
37216 }
37217 lpfc_transport_template =
37218 fc_attach_transport(&lpfc_transport_functions);
37219diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37220index 66e0906..1620281 100644
37221--- a/drivers/scsi/lpfc/lpfc_scsi.c
37222+++ b/drivers/scsi/lpfc/lpfc_scsi.c
37223@@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37224 uint32_t evt_posted;
37225
37226 spin_lock_irqsave(&phba->hbalock, flags);
37227- atomic_inc(&phba->num_rsrc_err);
37228+ atomic_inc_unchecked(&phba->num_rsrc_err);
37229 phba->last_rsrc_error_time = jiffies;
37230
37231 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37232@@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37233 unsigned long flags;
37234 struct lpfc_hba *phba = vport->phba;
37235 uint32_t evt_posted;
37236- atomic_inc(&phba->num_cmd_success);
37237+ atomic_inc_unchecked(&phba->num_cmd_success);
37238
37239 if (vport->cfg_lun_queue_depth <= queue_depth)
37240 return;
37241@@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37242 unsigned long num_rsrc_err, num_cmd_success;
37243 int i;
37244
37245- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37246- num_cmd_success = atomic_read(&phba->num_cmd_success);
37247+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37248+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37249
37250 /*
37251 * The error and success command counters are global per
37252@@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37253 }
37254 }
37255 lpfc_destroy_vport_work_array(phba, vports);
37256- atomic_set(&phba->num_rsrc_err, 0);
37257- atomic_set(&phba->num_cmd_success, 0);
37258+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37259+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37260 }
37261
37262 /**
37263@@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37264 }
37265 }
37266 lpfc_destroy_vport_work_array(phba, vports);
37267- atomic_set(&phba->num_rsrc_err, 0);
37268- atomic_set(&phba->num_cmd_success, 0);
37269+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37270+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37271 }
37272
37273 /**
37274diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37275index ea8a0b4..812a124 100644
37276--- a/drivers/scsi/pmcraid.c
37277+++ b/drivers/scsi/pmcraid.c
37278@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37279 res->scsi_dev = scsi_dev;
37280 scsi_dev->hostdata = res;
37281 res->change_detected = 0;
37282- atomic_set(&res->read_failures, 0);
37283- atomic_set(&res->write_failures, 0);
37284+ atomic_set_unchecked(&res->read_failures, 0);
37285+ atomic_set_unchecked(&res->write_failures, 0);
37286 rc = 0;
37287 }
37288 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37289@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37290
37291 /* If this was a SCSI read/write command keep count of errors */
37292 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37293- atomic_inc(&res->read_failures);
37294+ atomic_inc_unchecked(&res->read_failures);
37295 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37296- atomic_inc(&res->write_failures);
37297+ atomic_inc_unchecked(&res->write_failures);
37298
37299 if (!RES_IS_GSCSI(res->cfg_entry) &&
37300 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37301@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37302 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37303 * hrrq_id assigned here in queuecommand
37304 */
37305- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37306+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37307 pinstance->num_hrrq;
37308 cmd->cmd_done = pmcraid_io_done;
37309
37310@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37311 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37312 * hrrq_id assigned here in queuecommand
37313 */
37314- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37315+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37316 pinstance->num_hrrq;
37317
37318 if (request_size) {
37319@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37320
37321 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37322 /* add resources only after host is added into system */
37323- if (!atomic_read(&pinstance->expose_resources))
37324+ if (!atomic_read_unchecked(&pinstance->expose_resources))
37325 return;
37326
37327 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37328@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37329 init_waitqueue_head(&pinstance->reset_wait_q);
37330
37331 atomic_set(&pinstance->outstanding_cmds, 0);
37332- atomic_set(&pinstance->last_message_id, 0);
37333- atomic_set(&pinstance->expose_resources, 0);
37334+ atomic_set_unchecked(&pinstance->last_message_id, 0);
37335+ atomic_set_unchecked(&pinstance->expose_resources, 0);
37336
37337 INIT_LIST_HEAD(&pinstance->free_res_q);
37338 INIT_LIST_HEAD(&pinstance->used_res_q);
37339@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37340 /* Schedule worker thread to handle CCN and take care of adding and
37341 * removing devices to OS
37342 */
37343- atomic_set(&pinstance->expose_resources, 1);
37344+ atomic_set_unchecked(&pinstance->expose_resources, 1);
37345 schedule_work(&pinstance->worker_q);
37346 return rc;
37347
37348diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37349index e1d150f..6c6df44 100644
37350--- a/drivers/scsi/pmcraid.h
37351+++ b/drivers/scsi/pmcraid.h
37352@@ -748,7 +748,7 @@ struct pmcraid_instance {
37353 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37354
37355 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37356- atomic_t last_message_id;
37357+ atomic_unchecked_t last_message_id;
37358
37359 /* configuration table */
37360 struct pmcraid_config_table *cfg_table;
37361@@ -777,7 +777,7 @@ struct pmcraid_instance {
37362 atomic_t outstanding_cmds;
37363
37364 /* should add/delete resources to mid-layer now ?*/
37365- atomic_t expose_resources;
37366+ atomic_unchecked_t expose_resources;
37367
37368
37369
37370@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37371 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37372 };
37373 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37374- atomic_t read_failures; /* count of failed READ commands */
37375- atomic_t write_failures; /* count of failed WRITE commands */
37376+ atomic_unchecked_t read_failures; /* count of failed READ commands */
37377+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37378
37379 /* To indicate add/delete/modify during CCN */
37380 u8 change_detected;
37381diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37382index 5ab9530..2dd80f7 100644
37383--- a/drivers/scsi/qla2xxx/qla_attr.c
37384+++ b/drivers/scsi/qla2xxx/qla_attr.c
37385@@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37386 return 0;
37387 }
37388
37389-struct fc_function_template qla2xxx_transport_functions = {
37390+fc_function_template_no_const qla2xxx_transport_functions = {
37391
37392 .show_host_node_name = 1,
37393 .show_host_port_name = 1,
37394@@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37395 .bsg_timeout = qla24xx_bsg_timeout,
37396 };
37397
37398-struct fc_function_template qla2xxx_transport_vport_functions = {
37399+fc_function_template_no_const qla2xxx_transport_vport_functions = {
37400
37401 .show_host_node_name = 1,
37402 .show_host_port_name = 1,
37403diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37404index 39007f5..7fafc64 100644
37405--- a/drivers/scsi/qla2xxx/qla_def.h
37406+++ b/drivers/scsi/qla2xxx/qla_def.h
37407@@ -2284,7 +2284,7 @@ struct isp_operations {
37408 int (*start_scsi) (srb_t *);
37409 int (*abort_isp) (struct scsi_qla_host *);
37410 int (*iospace_config)(struct qla_hw_data*);
37411-};
37412+} __no_const;
37413
37414 /* MSI-X Support *************************************************************/
37415
37416diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37417index 9eacd2d..d79629c 100644
37418--- a/drivers/scsi/qla2xxx/qla_gbl.h
37419+++ b/drivers/scsi/qla2xxx/qla_gbl.h
37420@@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37421 struct device_attribute;
37422 extern struct device_attribute *qla2x00_host_attrs[];
37423 struct fc_function_template;
37424-extern struct fc_function_template qla2xxx_transport_functions;
37425-extern struct fc_function_template qla2xxx_transport_vport_functions;
37426+extern fc_function_template_no_const qla2xxx_transport_functions;
37427+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37428 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37429 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37430 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37431diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37432index 96a5616..eeb185a 100644
37433--- a/drivers/scsi/qla4xxx/ql4_def.h
37434+++ b/drivers/scsi/qla4xxx/ql4_def.h
37435@@ -268,7 +268,7 @@ struct ddb_entry {
37436 * (4000 only) */
37437 atomic_t relogin_timer; /* Max Time to wait for
37438 * relogin to complete */
37439- atomic_t relogin_retry_count; /* Num of times relogin has been
37440+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37441 * retried */
37442 uint32_t default_time2wait; /* Default Min time between
37443 * relogins (+aens) */
37444diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37445index cd15678..f7e6846 100644
37446--- a/drivers/scsi/qla4xxx/ql4_os.c
37447+++ b/drivers/scsi/qla4xxx/ql4_os.c
37448@@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37449 */
37450 if (!iscsi_is_session_online(cls_sess)) {
37451 /* Reset retry relogin timer */
37452- atomic_inc(&ddb_entry->relogin_retry_count);
37453+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37454 DEBUG2(ql4_printk(KERN_INFO, ha,
37455 "%s: index[%d] relogin timed out-retrying"
37456 " relogin (%d), retry (%d)\n", __func__,
37457 ddb_entry->fw_ddb_index,
37458- atomic_read(&ddb_entry->relogin_retry_count),
37459+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37460 ddb_entry->default_time2wait + 4));
37461 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37462 atomic_set(&ddb_entry->retry_relogin_timer,
37463@@ -4517,7 +4517,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37464
37465 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37466 atomic_set(&ddb_entry->relogin_timer, 0);
37467- atomic_set(&ddb_entry->relogin_retry_count, 0);
37468+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37469 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37470 ddb_entry->default_relogin_timeout =
37471 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37472diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37473index bbbc9c9..ce22f77 100644
37474--- a/drivers/scsi/scsi.c
37475+++ b/drivers/scsi/scsi.c
37476@@ -659,7 +659,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37477 unsigned long timeout;
37478 int rtn = 0;
37479
37480- atomic_inc(&cmd->device->iorequest_cnt);
37481+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37482
37483 /* check if the device is still usable */
37484 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37485diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37486index dae3873..bb4bee6 100644
37487--- a/drivers/scsi/scsi_lib.c
37488+++ b/drivers/scsi/scsi_lib.c
37489@@ -1425,7 +1425,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37490 shost = sdev->host;
37491 scsi_init_cmd_errh(cmd);
37492 cmd->result = DID_NO_CONNECT << 16;
37493- atomic_inc(&cmd->device->iorequest_cnt);
37494+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37495
37496 /*
37497 * SCSI request completion path will do scsi_device_unbusy(),
37498@@ -1451,9 +1451,9 @@ static void scsi_softirq_done(struct request *rq)
37499
37500 INIT_LIST_HEAD(&cmd->eh_entry);
37501
37502- atomic_inc(&cmd->device->iodone_cnt);
37503+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
37504 if (cmd->result)
37505- atomic_inc(&cmd->device->ioerr_cnt);
37506+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37507
37508 disposition = scsi_decide_disposition(cmd);
37509 if (disposition != SUCCESS &&
37510diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37511index 08d48a3..2be990d 100644
37512--- a/drivers/scsi/scsi_sysfs.c
37513+++ b/drivers/scsi/scsi_sysfs.c
37514@@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37515 char *buf) \
37516 { \
37517 struct scsi_device *sdev = to_scsi_device(dev); \
37518- unsigned long long count = atomic_read(&sdev->field); \
37519+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
37520 return snprintf(buf, 20, "0x%llx\n", count); \
37521 } \
37522 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37523diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37524index 84a1fdf..693b0d6 100644
37525--- a/drivers/scsi/scsi_tgt_lib.c
37526+++ b/drivers/scsi/scsi_tgt_lib.c
37527@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37528 int err;
37529
37530 dprintk("%lx %u\n", uaddr, len);
37531- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37532+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37533 if (err) {
37534 /*
37535 * TODO: need to fixup sg_tablesize, max_segment_size,
37536diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37537index 5797604..289a5b5 100644
37538--- a/drivers/scsi/scsi_transport_fc.c
37539+++ b/drivers/scsi/scsi_transport_fc.c
37540@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37541 * Netlink Infrastructure
37542 */
37543
37544-static atomic_t fc_event_seq;
37545+static atomic_unchecked_t fc_event_seq;
37546
37547 /**
37548 * fc_get_event_number - Obtain the next sequential FC event number
37549@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37550 u32
37551 fc_get_event_number(void)
37552 {
37553- return atomic_add_return(1, &fc_event_seq);
37554+ return atomic_add_return_unchecked(1, &fc_event_seq);
37555 }
37556 EXPORT_SYMBOL(fc_get_event_number);
37557
37558@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37559 {
37560 int error;
37561
37562- atomic_set(&fc_event_seq, 0);
37563+ atomic_set_unchecked(&fc_event_seq, 0);
37564
37565 error = transport_class_register(&fc_host_class);
37566 if (error)
37567@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37568 char *cp;
37569
37570 *val = simple_strtoul(buf, &cp, 0);
37571- if ((*cp && (*cp != '\n')) || (*val < 0))
37572+ if (*cp && (*cp != '\n'))
37573 return -EINVAL;
37574 /*
37575 * Check for overflow; dev_loss_tmo is u32
37576diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37577index 1cf640e..78e9014 100644
37578--- a/drivers/scsi/scsi_transport_iscsi.c
37579+++ b/drivers/scsi/scsi_transport_iscsi.c
37580@@ -79,7 +79,7 @@ struct iscsi_internal {
37581 struct transport_container session_cont;
37582 };
37583
37584-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37585+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37586 static struct workqueue_struct *iscsi_eh_timer_workq;
37587
37588 static DEFINE_IDA(iscsi_sess_ida);
37589@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37590 int err;
37591
37592 ihost = shost->shost_data;
37593- session->sid = atomic_add_return(1, &iscsi_session_nr);
37594+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37595
37596 if (target_id == ISCSI_MAX_TARGET) {
37597 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37598@@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37599 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37600 ISCSI_TRANSPORT_VERSION);
37601
37602- atomic_set(&iscsi_session_nr, 0);
37603+ atomic_set_unchecked(&iscsi_session_nr, 0);
37604
37605 err = class_register(&iscsi_transport_class);
37606 if (err)
37607diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37608index 21a045e..ec89e03 100644
37609--- a/drivers/scsi/scsi_transport_srp.c
37610+++ b/drivers/scsi/scsi_transport_srp.c
37611@@ -33,7 +33,7 @@
37612 #include "scsi_transport_srp_internal.h"
37613
37614 struct srp_host_attrs {
37615- atomic_t next_port_id;
37616+ atomic_unchecked_t next_port_id;
37617 };
37618 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37619
37620@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37621 struct Scsi_Host *shost = dev_to_shost(dev);
37622 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37623
37624- atomic_set(&srp_host->next_port_id, 0);
37625+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37626 return 0;
37627 }
37628
37629@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37630 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37631 rport->roles = ids->roles;
37632
37633- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37634+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37635 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37636
37637 transport_setup_device(&rport->dev);
37638diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37639index 9c5c5f2..8414557 100644
37640--- a/drivers/scsi/sg.c
37641+++ b/drivers/scsi/sg.c
37642@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37643 sdp->disk->disk_name,
37644 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37645 NULL,
37646- (char *)arg);
37647+ (char __user *)arg);
37648 case BLKTRACESTART:
37649 return blk_trace_startstop(sdp->device->request_queue, 1);
37650 case BLKTRACESTOP:
37651diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37652index 1041cb8..4a946fa 100644
37653--- a/drivers/spi/spi.c
37654+++ b/drivers/spi/spi.c
37655@@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37656 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37657
37658 /* portable code must never pass more than 32 bytes */
37659-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37660+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37661
37662 static u8 *buf;
37663
37664diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37665index 34afc16..ffe44dd 100644
37666--- a/drivers/staging/octeon/ethernet-rx.c
37667+++ b/drivers/staging/octeon/ethernet-rx.c
37668@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37669 /* Increment RX stats for virtual ports */
37670 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37671 #ifdef CONFIG_64BIT
37672- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37673- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37674+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37675+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37676 #else
37677- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37678- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37679+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37680+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37681 #endif
37682 }
37683 netif_receive_skb(skb);
37684@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37685 dev->name);
37686 */
37687 #ifdef CONFIG_64BIT
37688- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37689+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37690 #else
37691- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37692+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37693 #endif
37694 dev_kfree_skb_irq(skb);
37695 }
37696diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37697index 18f7a79..cc3bc24 100644
37698--- a/drivers/staging/octeon/ethernet.c
37699+++ b/drivers/staging/octeon/ethernet.c
37700@@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37701 * since the RX tasklet also increments it.
37702 */
37703 #ifdef CONFIG_64BIT
37704- atomic64_add(rx_status.dropped_packets,
37705- (atomic64_t *)&priv->stats.rx_dropped);
37706+ atomic64_add_unchecked(rx_status.dropped_packets,
37707+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37708 #else
37709- atomic_add(rx_status.dropped_packets,
37710- (atomic_t *)&priv->stats.rx_dropped);
37711+ atomic_add_unchecked(rx_status.dropped_packets,
37712+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37713 #endif
37714 }
37715
37716diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37717index dc23395..cf7e9b1 100644
37718--- a/drivers/staging/rtl8712/rtl871x_io.h
37719+++ b/drivers/staging/rtl8712/rtl871x_io.h
37720@@ -108,7 +108,7 @@ struct _io_ops {
37721 u8 *pmem);
37722 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37723 u8 *pmem);
37724-};
37725+} __no_const;
37726
37727 struct io_req {
37728 struct list_head list;
37729diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37730index c7b5e8b..783d6cb 100644
37731--- a/drivers/staging/sbe-2t3e3/netdev.c
37732+++ b/drivers/staging/sbe-2t3e3/netdev.c
37733@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37734 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37735
37736 if (rlen)
37737- if (copy_to_user(data, &resp, rlen))
37738+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37739 return -EFAULT;
37740
37741 return 0;
37742diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37743index 5d89c0f..9261317 100644
37744--- a/drivers/staging/usbip/usbip_common.h
37745+++ b/drivers/staging/usbip/usbip_common.h
37746@@ -289,7 +289,7 @@ struct usbip_device {
37747 void (*shutdown)(struct usbip_device *);
37748 void (*reset)(struct usbip_device *);
37749 void (*unusable)(struct usbip_device *);
37750- } eh_ops;
37751+ } __no_const eh_ops;
37752 };
37753
37754 #define kthread_get_run(threadfn, data, namefmt, ...) \
37755diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37756index 88b3298..3783eee 100644
37757--- a/drivers/staging/usbip/vhci.h
37758+++ b/drivers/staging/usbip/vhci.h
37759@@ -88,7 +88,7 @@ struct vhci_hcd {
37760 unsigned resuming:1;
37761 unsigned long re_timeout;
37762
37763- atomic_t seqnum;
37764+ atomic_unchecked_t seqnum;
37765
37766 /*
37767 * NOTE:
37768diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37769index f708cba..2de6d72 100644
37770--- a/drivers/staging/usbip/vhci_hcd.c
37771+++ b/drivers/staging/usbip/vhci_hcd.c
37772@@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37773 return;
37774 }
37775
37776- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37777+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37778 if (priv->seqnum == 0xffff)
37779 dev_info(&urb->dev->dev, "seqnum max\n");
37780
37781@@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37782 return -ENOMEM;
37783 }
37784
37785- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37786+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37787 if (unlink->seqnum == 0xffff)
37788 pr_info("seqnum max\n");
37789
37790@@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37791 vdev->rhport = rhport;
37792 }
37793
37794- atomic_set(&vhci->seqnum, 0);
37795+ atomic_set_unchecked(&vhci->seqnum, 0);
37796 spin_lock_init(&vhci->lock);
37797
37798 hcd->power_budget = 0; /* no limit */
37799diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37800index f0eaf04..5a82e06 100644
37801--- a/drivers/staging/usbip/vhci_rx.c
37802+++ b/drivers/staging/usbip/vhci_rx.c
37803@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37804 if (!urb) {
37805 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37806 pr_info("max seqnum %d\n",
37807- atomic_read(&the_controller->seqnum));
37808+ atomic_read_unchecked(&the_controller->seqnum));
37809 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37810 return;
37811 }
37812diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37813index 7735027..30eed13 100644
37814--- a/drivers/staging/vt6655/hostap.c
37815+++ b/drivers/staging/vt6655/hostap.c
37816@@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37817 *
37818 */
37819
37820+static net_device_ops_no_const apdev_netdev_ops;
37821+
37822 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37823 {
37824 PSDevice apdev_priv;
37825 struct net_device *dev = pDevice->dev;
37826 int ret;
37827- const struct net_device_ops apdev_netdev_ops = {
37828- .ndo_start_xmit = pDevice->tx_80211,
37829- };
37830
37831 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37832
37833@@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37834 *apdev_priv = *pDevice;
37835 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37836
37837+ /* only half broken now */
37838+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37839 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37840
37841 pDevice->apdev->type = ARPHRD_IEEE80211;
37842diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37843index 51b5adf..098e320 100644
37844--- a/drivers/staging/vt6656/hostap.c
37845+++ b/drivers/staging/vt6656/hostap.c
37846@@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37847 *
37848 */
37849
37850+static net_device_ops_no_const apdev_netdev_ops;
37851+
37852 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37853 {
37854 PSDevice apdev_priv;
37855 struct net_device *dev = pDevice->dev;
37856 int ret;
37857- const struct net_device_ops apdev_netdev_ops = {
37858- .ndo_start_xmit = pDevice->tx_80211,
37859- };
37860
37861 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37862
37863@@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37864 *apdev_priv = *pDevice;
37865 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37866
37867+ /* only half broken now */
37868+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37869 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37870
37871 pDevice->apdev->type = ARPHRD_IEEE80211;
37872diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37873index 7843dfd..3db105f 100644
37874--- a/drivers/staging/wlan-ng/hfa384x_usb.c
37875+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37876@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37877
37878 struct usbctlx_completor {
37879 int (*complete) (struct usbctlx_completor *);
37880-};
37881+} __no_const;
37882
37883 static int
37884 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37885diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37886index 1ca66ea..76f1343 100644
37887--- a/drivers/staging/zcache/tmem.c
37888+++ b/drivers/staging/zcache/tmem.c
37889@@ -39,7 +39,7 @@
37890 * A tmem host implementation must use this function to register callbacks
37891 * for memory allocation.
37892 */
37893-static struct tmem_hostops tmem_hostops;
37894+static tmem_hostops_no_const tmem_hostops;
37895
37896 static void tmem_objnode_tree_init(void);
37897
37898@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37899 * A tmem host implementation must use this function to register
37900 * callbacks for a page-accessible memory (PAM) implementation
37901 */
37902-static struct tmem_pamops tmem_pamops;
37903+static tmem_pamops_no_const tmem_pamops;
37904
37905 void tmem_register_pamops(struct tmem_pamops *m)
37906 {
37907diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37908index 0d4aa82..f7832d4 100644
37909--- a/drivers/staging/zcache/tmem.h
37910+++ b/drivers/staging/zcache/tmem.h
37911@@ -180,6 +180,7 @@ struct tmem_pamops {
37912 void (*new_obj)(struct tmem_obj *);
37913 int (*replace_in_obj)(void *, struct tmem_obj *);
37914 };
37915+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37916 extern void tmem_register_pamops(struct tmem_pamops *m);
37917
37918 /* memory allocation methods provided by the host implementation */
37919@@ -189,6 +190,7 @@ struct tmem_hostops {
37920 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37921 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37922 };
37923+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37924 extern void tmem_register_hostops(struct tmem_hostops *m);
37925
37926 /* core tmem accessor functions */
37927diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37928index 0981707..fa256ac 100644
37929--- a/drivers/target/target_core_transport.c
37930+++ b/drivers/target/target_core_transport.c
37931@@ -1233,7 +1233,7 @@ struct se_device *transport_add_device_to_core_hba(
37932 spin_lock_init(&dev->se_port_lock);
37933 spin_lock_init(&dev->se_tmr_lock);
37934 spin_lock_init(&dev->qf_cmd_lock);
37935- atomic_set(&dev->dev_ordered_id, 0);
37936+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
37937
37938 se_dev_set_default_attribs(dev, dev_limits);
37939
37940@@ -1402,7 +1402,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37941 * Used to determine when ORDERED commands should go from
37942 * Dormant to Active status.
37943 */
37944- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37945+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37946 smp_mb__after_atomic_inc();
37947 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37948 cmd->se_ordered_id, cmd->sam_task_attr,
37949diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37950index e61cabd..7617d26 100644
37951--- a/drivers/tty/cyclades.c
37952+++ b/drivers/tty/cyclades.c
37953@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37954 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37955 info->port.count);
37956 #endif
37957- info->port.count++;
37958+ atomic_inc(&info->port.count);
37959 #ifdef CY_DEBUG_COUNT
37960 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37961- current->pid, info->port.count);
37962+ current->pid, atomic_read(&info->port.count));
37963 #endif
37964
37965 /*
37966@@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37967 for (j = 0; j < cy_card[i].nports; j++) {
37968 info = &cy_card[i].ports[j];
37969
37970- if (info->port.count) {
37971+ if (atomic_read(&info->port.count)) {
37972 /* XXX is the ldisc num worth this? */
37973 struct tty_struct *tty;
37974 struct tty_ldisc *ld;
37975diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37976index 2d691eb..be02ebd 100644
37977--- a/drivers/tty/hvc/hvc_console.c
37978+++ b/drivers/tty/hvc/hvc_console.c
37979@@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37980
37981 spin_lock_irqsave(&hp->port.lock, flags);
37982 /* Check and then increment for fast path open. */
37983- if (hp->port.count++ > 0) {
37984+ if (atomic_inc_return(&hp->port.count) > 1) {
37985 spin_unlock_irqrestore(&hp->port.lock, flags);
37986 hvc_kick();
37987 return 0;
37988@@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37989
37990 spin_lock_irqsave(&hp->port.lock, flags);
37991
37992- if (--hp->port.count == 0) {
37993+ if (atomic_dec_return(&hp->port.count) == 0) {
37994 spin_unlock_irqrestore(&hp->port.lock, flags);
37995 /* We are done with the tty pointer now. */
37996 tty_port_tty_set(&hp->port, NULL);
37997@@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37998 */
37999 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
38000 } else {
38001- if (hp->port.count < 0)
38002+ if (atomic_read(&hp->port.count) < 0)
38003 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
38004- hp->vtermno, hp->port.count);
38005+ hp->vtermno, atomic_read(&hp->port.count));
38006 spin_unlock_irqrestore(&hp->port.lock, flags);
38007 }
38008
38009@@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
38010 * open->hangup case this can be called after the final close so prevent
38011 * that from happening for now.
38012 */
38013- if (hp->port.count <= 0) {
38014+ if (atomic_read(&hp->port.count) <= 0) {
38015 spin_unlock_irqrestore(&hp->port.lock, flags);
38016 return;
38017 }
38018
38019- temp_open_count = hp->port.count;
38020- hp->port.count = 0;
38021+ temp_open_count = atomic_read(&hp->port.count);
38022+ atomic_set(&hp->port.count, 0);
38023 spin_unlock_irqrestore(&hp->port.lock, flags);
38024 tty_port_tty_set(&hp->port, NULL);
38025
38026@@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
38027 return -EPIPE;
38028
38029 /* FIXME what's this (unprotected) check for? */
38030- if (hp->port.count <= 0)
38031+ if (atomic_read(&hp->port.count) <= 0)
38032 return -EIO;
38033
38034 spin_lock_irqsave(&hp->lock, flags);
38035diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38036index d56788c..12d8f85 100644
38037--- a/drivers/tty/hvc/hvcs.c
38038+++ b/drivers/tty/hvc/hvcs.c
38039@@ -83,6 +83,7 @@
38040 #include <asm/hvcserver.h>
38041 #include <asm/uaccess.h>
38042 #include <asm/vio.h>
38043+#include <asm/local.h>
38044
38045 /*
38046 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38047@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38048
38049 spin_lock_irqsave(&hvcsd->lock, flags);
38050
38051- if (hvcsd->port.count > 0) {
38052+ if (atomic_read(&hvcsd->port.count) > 0) {
38053 spin_unlock_irqrestore(&hvcsd->lock, flags);
38054 printk(KERN_INFO "HVCS: vterm state unchanged. "
38055 "The hvcs device node is still in use.\n");
38056@@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38057 if ((retval = hvcs_partner_connect(hvcsd)))
38058 goto error_release;
38059
38060- hvcsd->port.count = 1;
38061+ atomic_set(&hvcsd->port.count, 1);
38062 hvcsd->port.tty = tty;
38063 tty->driver_data = hvcsd;
38064
38065@@ -1168,7 +1169,7 @@ fast_open:
38066
38067 spin_lock_irqsave(&hvcsd->lock, flags);
38068 tty_port_get(&hvcsd->port);
38069- hvcsd->port.count++;
38070+ atomic_inc(&hvcsd->port.count);
38071 hvcsd->todo_mask |= HVCS_SCHED_READ;
38072 spin_unlock_irqrestore(&hvcsd->lock, flags);
38073
38074@@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38075 hvcsd = tty->driver_data;
38076
38077 spin_lock_irqsave(&hvcsd->lock, flags);
38078- if (--hvcsd->port.count == 0) {
38079+ if (atomic_dec_and_test(&hvcsd->port.count)) {
38080
38081 vio_disable_interrupts(hvcsd->vdev);
38082
38083@@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38084 free_irq(irq, hvcsd);
38085 tty_port_put(&hvcsd->port);
38086 return;
38087- } else if (hvcsd->port.count < 0) {
38088+ } else if (atomic_read(&hvcsd->port.count) < 0) {
38089 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38090 " is missmanaged.\n",
38091- hvcsd->vdev->unit_address, hvcsd->port.count);
38092+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38093 }
38094
38095 spin_unlock_irqrestore(&hvcsd->lock, flags);
38096@@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38097
38098 spin_lock_irqsave(&hvcsd->lock, flags);
38099 /* Preserve this so that we know how many kref refs to put */
38100- temp_open_count = hvcsd->port.count;
38101+ temp_open_count = atomic_read(&hvcsd->port.count);
38102
38103 /*
38104 * Don't kref put inside the spinlock because the destruction
38105@@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38106 tty->driver_data = NULL;
38107 hvcsd->port.tty = NULL;
38108
38109- hvcsd->port.count = 0;
38110+ atomic_set(&hvcsd->port.count, 0);
38111
38112 /* This will drop any buffered data on the floor which is OK in a hangup
38113 * scenario. */
38114@@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38115 * the middle of a write operation? This is a crummy place to do this
38116 * but we want to keep it all in the spinlock.
38117 */
38118- if (hvcsd->port.count <= 0) {
38119+ if (atomic_read(&hvcsd->port.count) <= 0) {
38120 spin_unlock_irqrestore(&hvcsd->lock, flags);
38121 return -ENODEV;
38122 }
38123@@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38124 {
38125 struct hvcs_struct *hvcsd = tty->driver_data;
38126
38127- if (!hvcsd || hvcsd->port.count <= 0)
38128+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38129 return 0;
38130
38131 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38132diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38133index f8b5fa0..4ba9f89 100644
38134--- a/drivers/tty/ipwireless/tty.c
38135+++ b/drivers/tty/ipwireless/tty.c
38136@@ -29,6 +29,7 @@
38137 #include <linux/tty_driver.h>
38138 #include <linux/tty_flip.h>
38139 #include <linux/uaccess.h>
38140+#include <asm/local.h>
38141
38142 #include "tty.h"
38143 #include "network.h"
38144@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38145 mutex_unlock(&tty->ipw_tty_mutex);
38146 return -ENODEV;
38147 }
38148- if (tty->port.count == 0)
38149+ if (atomic_read(&tty->port.count) == 0)
38150 tty->tx_bytes_queued = 0;
38151
38152- tty->port.count++;
38153+ atomic_inc(&tty->port.count);
38154
38155 tty->port.tty = linux_tty;
38156 linux_tty->driver_data = tty;
38157@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38158
38159 static void do_ipw_close(struct ipw_tty *tty)
38160 {
38161- tty->port.count--;
38162-
38163- if (tty->port.count == 0) {
38164+ if (atomic_dec_return(&tty->port.count) == 0) {
38165 struct tty_struct *linux_tty = tty->port.tty;
38166
38167 if (linux_tty != NULL) {
38168@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38169 return;
38170
38171 mutex_lock(&tty->ipw_tty_mutex);
38172- if (tty->port.count == 0) {
38173+ if (atomic_read(&tty->port.count) == 0) {
38174 mutex_unlock(&tty->ipw_tty_mutex);
38175 return;
38176 }
38177@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38178 return;
38179 }
38180
38181- if (!tty->port.count) {
38182+ if (!atomic_read(&tty->port.count)) {
38183 mutex_unlock(&tty->ipw_tty_mutex);
38184 return;
38185 }
38186@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38187 return -ENODEV;
38188
38189 mutex_lock(&tty->ipw_tty_mutex);
38190- if (!tty->port.count) {
38191+ if (!atomic_read(&tty->port.count)) {
38192 mutex_unlock(&tty->ipw_tty_mutex);
38193 return -EINVAL;
38194 }
38195@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38196 if (!tty)
38197 return -ENODEV;
38198
38199- if (!tty->port.count)
38200+ if (!atomic_read(&tty->port.count))
38201 return -EINVAL;
38202
38203 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38204@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38205 if (!tty)
38206 return 0;
38207
38208- if (!tty->port.count)
38209+ if (!atomic_read(&tty->port.count))
38210 return 0;
38211
38212 return tty->tx_bytes_queued;
38213@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38214 if (!tty)
38215 return -ENODEV;
38216
38217- if (!tty->port.count)
38218+ if (!atomic_read(&tty->port.count))
38219 return -EINVAL;
38220
38221 return get_control_lines(tty);
38222@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38223 if (!tty)
38224 return -ENODEV;
38225
38226- if (!tty->port.count)
38227+ if (!atomic_read(&tty->port.count))
38228 return -EINVAL;
38229
38230 return set_control_lines(tty, set, clear);
38231@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38232 if (!tty)
38233 return -ENODEV;
38234
38235- if (!tty->port.count)
38236+ if (!atomic_read(&tty->port.count))
38237 return -EINVAL;
38238
38239 /* FIXME: Exactly how is the tty object locked here .. */
38240@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38241 * are gone */
38242 mutex_lock(&ttyj->ipw_tty_mutex);
38243 }
38244- while (ttyj->port.count)
38245+ while (atomic_read(&ttyj->port.count))
38246 do_ipw_close(ttyj);
38247 ipwireless_disassociate_network_ttys(network,
38248 ttyj->channel_idx);
38249diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38250index 324467d..504cc25 100644
38251--- a/drivers/tty/moxa.c
38252+++ b/drivers/tty/moxa.c
38253@@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38254 }
38255
38256 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38257- ch->port.count++;
38258+ atomic_inc(&ch->port.count);
38259 tty->driver_data = ch;
38260 tty_port_tty_set(&ch->port, tty);
38261 mutex_lock(&ch->port.mutex);
38262diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38263index 90dff82..08119c3 100644
38264--- a/drivers/tty/n_gsm.c
38265+++ b/drivers/tty/n_gsm.c
38266@@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38267 kref_init(&dlci->ref);
38268 mutex_init(&dlci->mutex);
38269 dlci->fifo = &dlci->_fifo;
38270- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38271+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38272 kfree(dlci);
38273 return NULL;
38274 }
38275@@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38276 if (dlci == NULL)
38277 return -ENOMEM;
38278 port = &dlci->port;
38279- port->count++;
38280+ atomic_inc(&port->count);
38281 tty->driver_data = dlci;
38282 dlci_get(dlci);
38283 dlci_get(dlci->gsm->dlci[0]);
38284diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38285index 26f0d0e..b7c4273 100644
38286--- a/drivers/tty/n_tty.c
38287+++ b/drivers/tty/n_tty.c
38288@@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38289 {
38290 *ops = tty_ldisc_N_TTY;
38291 ops->owner = NULL;
38292- ops->refcount = ops->flags = 0;
38293+ atomic_set(&ops->refcount, 0);
38294+ ops->flags = 0;
38295 }
38296 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38297diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38298index 5505ffc..7affff9 100644
38299--- a/drivers/tty/pty.c
38300+++ b/drivers/tty/pty.c
38301@@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38302 panic("Couldn't register Unix98 pts driver");
38303
38304 /* Now create the /dev/ptmx special device */
38305+ pax_open_kernel();
38306 tty_default_fops(&ptmx_fops);
38307- ptmx_fops.open = ptmx_open;
38308+ *(void **)&ptmx_fops.open = ptmx_open;
38309+ pax_close_kernel();
38310
38311 cdev_init(&ptmx_cdev, &ptmx_fops);
38312 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38313diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38314index 777d5f9..56d67ca 100644
38315--- a/drivers/tty/rocket.c
38316+++ b/drivers/tty/rocket.c
38317@@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38318 tty->driver_data = info;
38319 tty_port_tty_set(port, tty);
38320
38321- if (port->count++ == 0) {
38322+ if (atomic_inc_return(&port->count) == 1) {
38323 atomic_inc(&rp_num_ports_open);
38324
38325 #ifdef ROCKET_DEBUG_OPEN
38326@@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38327 #endif
38328 }
38329 #ifdef ROCKET_DEBUG_OPEN
38330- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38331+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38332 #endif
38333
38334 /*
38335@@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38336 spin_unlock_irqrestore(&info->port.lock, flags);
38337 return;
38338 }
38339- if (info->port.count)
38340+ if (atomic_read(&info->port.count))
38341 atomic_dec(&rp_num_ports_open);
38342 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38343 spin_unlock_irqrestore(&info->port.lock, flags);
38344diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38345index 2b42a01..32a2ed3 100644
38346--- a/drivers/tty/serial/kgdboc.c
38347+++ b/drivers/tty/serial/kgdboc.c
38348@@ -24,8 +24,9 @@
38349 #define MAX_CONFIG_LEN 40
38350
38351 static struct kgdb_io kgdboc_io_ops;
38352+static struct kgdb_io kgdboc_io_ops_console;
38353
38354-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38355+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38356 static int configured = -1;
38357
38358 static char config[MAX_CONFIG_LEN];
38359@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38360 kgdboc_unregister_kbd();
38361 if (configured == 1)
38362 kgdb_unregister_io_module(&kgdboc_io_ops);
38363+ else if (configured == 2)
38364+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
38365 }
38366
38367 static int configure_kgdboc(void)
38368@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38369 int err;
38370 char *cptr = config;
38371 struct console *cons;
38372+ int is_console = 0;
38373
38374 err = kgdboc_option_setup(config);
38375 if (err || !strlen(config) || isspace(config[0]))
38376 goto noconfig;
38377
38378 err = -ENODEV;
38379- kgdboc_io_ops.is_console = 0;
38380 kgdb_tty_driver = NULL;
38381
38382 kgdboc_use_kms = 0;
38383@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38384 int idx;
38385 if (cons->device && cons->device(cons, &idx) == p &&
38386 idx == tty_line) {
38387- kgdboc_io_ops.is_console = 1;
38388+ is_console = 1;
38389 break;
38390 }
38391 cons = cons->next;
38392@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38393 kgdb_tty_line = tty_line;
38394
38395 do_register:
38396- err = kgdb_register_io_module(&kgdboc_io_ops);
38397+ if (is_console) {
38398+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
38399+ configured = 2;
38400+ } else {
38401+ err = kgdb_register_io_module(&kgdboc_io_ops);
38402+ configured = 1;
38403+ }
38404 if (err)
38405 goto noconfig;
38406
38407- configured = 1;
38408-
38409 return 0;
38410
38411 noconfig:
38412@@ -213,7 +220,7 @@ noconfig:
38413 static int __init init_kgdboc(void)
38414 {
38415 /* Already configured? */
38416- if (configured == 1)
38417+ if (configured >= 1)
38418 return 0;
38419
38420 return configure_kgdboc();
38421@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38422 if (config[len - 1] == '\n')
38423 config[len - 1] = '\0';
38424
38425- if (configured == 1)
38426+ if (configured >= 1)
38427 cleanup_kgdboc();
38428
38429 /* Go and configure with the new params. */
38430@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38431 .post_exception = kgdboc_post_exp_handler,
38432 };
38433
38434+static struct kgdb_io kgdboc_io_ops_console = {
38435+ .name = "kgdboc",
38436+ .read_char = kgdboc_get_char,
38437+ .write_char = kgdboc_put_char,
38438+ .pre_exception = kgdboc_pre_exp_handler,
38439+ .post_exception = kgdboc_post_exp_handler,
38440+ .is_console = 1
38441+};
38442+
38443 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38444 /* This is only available if kgdboc is a built in for early debugging */
38445 static int __init kgdboc_early_init(char *opt)
38446diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38447index 246b823..9e0db76 100644
38448--- a/drivers/tty/serial/serial_core.c
38449+++ b/drivers/tty/serial/serial_core.c
38450@@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38451 uart_flush_buffer(tty);
38452 uart_shutdown(tty, state);
38453 spin_lock_irqsave(&port->lock, flags);
38454- port->count = 0;
38455+ atomic_set(&port->count, 0);
38456 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38457 spin_unlock_irqrestore(&port->lock, flags);
38458 tty_port_tty_set(port, NULL);
38459@@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38460 goto end;
38461 }
38462
38463- port->count++;
38464+ atomic_inc(&port->count);
38465 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38466 retval = -ENXIO;
38467 goto err_dec_count;
38468@@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38469 /*
38470 * Make sure the device is in D0 state.
38471 */
38472- if (port->count == 1)
38473+ if (atomic_read(&port->count) == 1)
38474 uart_change_pm(state, 0);
38475
38476 /*
38477@@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38478 end:
38479 return retval;
38480 err_dec_count:
38481- port->count--;
38482+ atomic_inc(&port->count);
38483 mutex_unlock(&port->mutex);
38484 goto end;
38485 }
38486diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38487index 593d40a..bdc61f3 100644
38488--- a/drivers/tty/synclink.c
38489+++ b/drivers/tty/synclink.c
38490@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38491
38492 if (debug_level >= DEBUG_LEVEL_INFO)
38493 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38494- __FILE__,__LINE__, info->device_name, info->port.count);
38495+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38496
38497 if (tty_port_close_start(&info->port, tty, filp) == 0)
38498 goto cleanup;
38499@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38500 cleanup:
38501 if (debug_level >= DEBUG_LEVEL_INFO)
38502 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38503- tty->driver->name, info->port.count);
38504+ tty->driver->name, atomic_read(&info->port.count));
38505
38506 } /* end of mgsl_close() */
38507
38508@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38509
38510 mgsl_flush_buffer(tty);
38511 shutdown(info);
38512-
38513- info->port.count = 0;
38514+
38515+ atomic_set(&info->port.count, 0);
38516 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38517 info->port.tty = NULL;
38518
38519@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38520
38521 if (debug_level >= DEBUG_LEVEL_INFO)
38522 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38523- __FILE__,__LINE__, tty->driver->name, port->count );
38524+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38525
38526 spin_lock_irqsave(&info->irq_spinlock, flags);
38527 if (!tty_hung_up_p(filp)) {
38528 extra_count = true;
38529- port->count--;
38530+ atomic_dec(&port->count);
38531 }
38532 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38533 port->blocked_open++;
38534@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38535
38536 if (debug_level >= DEBUG_LEVEL_INFO)
38537 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38538- __FILE__,__LINE__, tty->driver->name, port->count );
38539+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38540
38541 tty_unlock();
38542 schedule();
38543@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38544
38545 /* FIXME: Racy on hangup during close wait */
38546 if (extra_count)
38547- port->count++;
38548+ atomic_inc(&port->count);
38549 port->blocked_open--;
38550
38551 if (debug_level >= DEBUG_LEVEL_INFO)
38552 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38553- __FILE__,__LINE__, tty->driver->name, port->count );
38554+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38555
38556 if (!retval)
38557 port->flags |= ASYNC_NORMAL_ACTIVE;
38558@@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38559
38560 if (debug_level >= DEBUG_LEVEL_INFO)
38561 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38562- __FILE__,__LINE__,tty->driver->name, info->port.count);
38563+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38564
38565 /* If port is closing, signal caller to try again */
38566 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38567@@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38568 spin_unlock_irqrestore(&info->netlock, flags);
38569 goto cleanup;
38570 }
38571- info->port.count++;
38572+ atomic_inc(&info->port.count);
38573 spin_unlock_irqrestore(&info->netlock, flags);
38574
38575- if (info->port.count == 1) {
38576+ if (atomic_read(&info->port.count) == 1) {
38577 /* 1st open on this device, init hardware */
38578 retval = startup(info);
38579 if (retval < 0)
38580@@ -3444,8 +3444,8 @@ cleanup:
38581 if (retval) {
38582 if (tty->count == 1)
38583 info->port.tty = NULL; /* tty layer will release tty struct */
38584- if(info->port.count)
38585- info->port.count--;
38586+ if (atomic_read(&info->port.count))
38587+ atomic_dec(&info->port.count);
38588 }
38589
38590 return retval;
38591@@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38592 unsigned short new_crctype;
38593
38594 /* return error if TTY interface open */
38595- if (info->port.count)
38596+ if (atomic_read(&info->port.count))
38597 return -EBUSY;
38598
38599 switch (encoding)
38600@@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38601
38602 /* arbitrate between network and tty opens */
38603 spin_lock_irqsave(&info->netlock, flags);
38604- if (info->port.count != 0 || info->netcount != 0) {
38605+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38606 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38607 spin_unlock_irqrestore(&info->netlock, flags);
38608 return -EBUSY;
38609@@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38610 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38611
38612 /* return error if TTY interface open */
38613- if (info->port.count)
38614+ if (atomic_read(&info->port.count))
38615 return -EBUSY;
38616
38617 if (cmd != SIOCWANDEV)
38618diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38619index aa1debf..9297a16 100644
38620--- a/drivers/tty/synclink_gt.c
38621+++ b/drivers/tty/synclink_gt.c
38622@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38623 tty->driver_data = info;
38624 info->port.tty = tty;
38625
38626- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38627+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38628
38629 /* If port is closing, signal caller to try again */
38630 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38631@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38632 mutex_unlock(&info->port.mutex);
38633 goto cleanup;
38634 }
38635- info->port.count++;
38636+ atomic_inc(&info->port.count);
38637 spin_unlock_irqrestore(&info->netlock, flags);
38638
38639- if (info->port.count == 1) {
38640+ if (atomic_read(&info->port.count) == 1) {
38641 /* 1st open on this device, init hardware */
38642 retval = startup(info);
38643 if (retval < 0) {
38644@@ -716,8 +716,8 @@ cleanup:
38645 if (retval) {
38646 if (tty->count == 1)
38647 info->port.tty = NULL; /* tty layer will release tty struct */
38648- if(info->port.count)
38649- info->port.count--;
38650+ if(atomic_read(&info->port.count))
38651+ atomic_dec(&info->port.count);
38652 }
38653
38654 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38655@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38656
38657 if (sanity_check(info, tty->name, "close"))
38658 return;
38659- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38660+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38661
38662 if (tty_port_close_start(&info->port, tty, filp) == 0)
38663 goto cleanup;
38664@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38665 tty_port_close_end(&info->port, tty);
38666 info->port.tty = NULL;
38667 cleanup:
38668- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38669+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38670 }
38671
38672 static void hangup(struct tty_struct *tty)
38673@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38674 shutdown(info);
38675
38676 spin_lock_irqsave(&info->port.lock, flags);
38677- info->port.count = 0;
38678+ atomic_set(&info->port.count, 0);
38679 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38680 info->port.tty = NULL;
38681 spin_unlock_irqrestore(&info->port.lock, flags);
38682@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38683 unsigned short new_crctype;
38684
38685 /* return error if TTY interface open */
38686- if (info->port.count)
38687+ if (atomic_read(&info->port.count))
38688 return -EBUSY;
38689
38690 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38691@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38692
38693 /* arbitrate between network and tty opens */
38694 spin_lock_irqsave(&info->netlock, flags);
38695- if (info->port.count != 0 || info->netcount != 0) {
38696+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38697 DBGINFO(("%s hdlc_open busy\n", dev->name));
38698 spin_unlock_irqrestore(&info->netlock, flags);
38699 return -EBUSY;
38700@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38701 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38702
38703 /* return error if TTY interface open */
38704- if (info->port.count)
38705+ if (atomic_read(&info->port.count))
38706 return -EBUSY;
38707
38708 if (cmd != SIOCWANDEV)
38709@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38710 if (port == NULL)
38711 continue;
38712 spin_lock(&port->lock);
38713- if ((port->port.count || port->netcount) &&
38714+ if ((atomic_read(&port->port.count) || port->netcount) &&
38715 port->pending_bh && !port->bh_running &&
38716 !port->bh_requested) {
38717 DBGISR(("%s bh queued\n", port->device_name));
38718@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38719 spin_lock_irqsave(&info->lock, flags);
38720 if (!tty_hung_up_p(filp)) {
38721 extra_count = true;
38722- port->count--;
38723+ atomic_dec(&port->count);
38724 }
38725 spin_unlock_irqrestore(&info->lock, flags);
38726 port->blocked_open++;
38727@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38728 remove_wait_queue(&port->open_wait, &wait);
38729
38730 if (extra_count)
38731- port->count++;
38732+ atomic_inc(&port->count);
38733 port->blocked_open--;
38734
38735 if (!retval)
38736diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38737index a3dddc1..8905ab2 100644
38738--- a/drivers/tty/synclinkmp.c
38739+++ b/drivers/tty/synclinkmp.c
38740@@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38741
38742 if (debug_level >= DEBUG_LEVEL_INFO)
38743 printk("%s(%d):%s open(), old ref count = %d\n",
38744- __FILE__,__LINE__,tty->driver->name, info->port.count);
38745+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38746
38747 /* If port is closing, signal caller to try again */
38748 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38749@@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38750 spin_unlock_irqrestore(&info->netlock, flags);
38751 goto cleanup;
38752 }
38753- info->port.count++;
38754+ atomic_inc(&info->port.count);
38755 spin_unlock_irqrestore(&info->netlock, flags);
38756
38757- if (info->port.count == 1) {
38758+ if (atomic_read(&info->port.count) == 1) {
38759 /* 1st open on this device, init hardware */
38760 retval = startup(info);
38761 if (retval < 0)
38762@@ -788,8 +788,8 @@ cleanup:
38763 if (retval) {
38764 if (tty->count == 1)
38765 info->port.tty = NULL; /* tty layer will release tty struct */
38766- if(info->port.count)
38767- info->port.count--;
38768+ if(atomic_read(&info->port.count))
38769+ atomic_dec(&info->port.count);
38770 }
38771
38772 return retval;
38773@@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38774
38775 if (debug_level >= DEBUG_LEVEL_INFO)
38776 printk("%s(%d):%s close() entry, count=%d\n",
38777- __FILE__,__LINE__, info->device_name, info->port.count);
38778+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38779
38780 if (tty_port_close_start(&info->port, tty, filp) == 0)
38781 goto cleanup;
38782@@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38783 cleanup:
38784 if (debug_level >= DEBUG_LEVEL_INFO)
38785 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38786- tty->driver->name, info->port.count);
38787+ tty->driver->name, atomic_read(&info->port.count));
38788 }
38789
38790 /* Called by tty_hangup() when a hangup is signaled.
38791@@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38792 shutdown(info);
38793
38794 spin_lock_irqsave(&info->port.lock, flags);
38795- info->port.count = 0;
38796+ atomic_set(&info->port.count, 0);
38797 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38798 info->port.tty = NULL;
38799 spin_unlock_irqrestore(&info->port.lock, flags);
38800@@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38801 unsigned short new_crctype;
38802
38803 /* return error if TTY interface open */
38804- if (info->port.count)
38805+ if (atomic_read(&info->port.count))
38806 return -EBUSY;
38807
38808 switch (encoding)
38809@@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38810
38811 /* arbitrate between network and tty opens */
38812 spin_lock_irqsave(&info->netlock, flags);
38813- if (info->port.count != 0 || info->netcount != 0) {
38814+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38815 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38816 spin_unlock_irqrestore(&info->netlock, flags);
38817 return -EBUSY;
38818@@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38819 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38820
38821 /* return error if TTY interface open */
38822- if (info->port.count)
38823+ if (atomic_read(&info->port.count))
38824 return -EBUSY;
38825
38826 if (cmd != SIOCWANDEV)
38827@@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38828 * do not request bottom half processing if the
38829 * device is not open in a normal mode.
38830 */
38831- if ( port && (port->port.count || port->netcount) &&
38832+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38833 port->pending_bh && !port->bh_running &&
38834 !port->bh_requested ) {
38835 if ( debug_level >= DEBUG_LEVEL_ISR )
38836@@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38837
38838 if (debug_level >= DEBUG_LEVEL_INFO)
38839 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38840- __FILE__,__LINE__, tty->driver->name, port->count );
38841+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38842
38843 spin_lock_irqsave(&info->lock, flags);
38844 if (!tty_hung_up_p(filp)) {
38845 extra_count = true;
38846- port->count--;
38847+ atomic_dec(&port->count);
38848 }
38849 spin_unlock_irqrestore(&info->lock, flags);
38850 port->blocked_open++;
38851@@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38852
38853 if (debug_level >= DEBUG_LEVEL_INFO)
38854 printk("%s(%d):%s block_til_ready() count=%d\n",
38855- __FILE__,__LINE__, tty->driver->name, port->count );
38856+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38857
38858 tty_unlock();
38859 schedule();
38860@@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38861 remove_wait_queue(&port->open_wait, &wait);
38862
38863 if (extra_count)
38864- port->count++;
38865+ atomic_inc(&port->count);
38866 port->blocked_open--;
38867
38868 if (debug_level >= DEBUG_LEVEL_INFO)
38869 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38870- __FILE__,__LINE__, tty->driver->name, port->count );
38871+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38872
38873 if (!retval)
38874 port->flags |= ASYNC_NORMAL_ACTIVE;
38875diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38876index 05728894..b9d44c6 100644
38877--- a/drivers/tty/sysrq.c
38878+++ b/drivers/tty/sysrq.c
38879@@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38880 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38881 size_t count, loff_t *ppos)
38882 {
38883- if (count) {
38884+ if (count && capable(CAP_SYS_ADMIN)) {
38885 char c;
38886
38887 if (get_user(c, buf))
38888diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38889index b425c79..08a3f06 100644
38890--- a/drivers/tty/tty_io.c
38891+++ b/drivers/tty/tty_io.c
38892@@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38893
38894 void tty_default_fops(struct file_operations *fops)
38895 {
38896- *fops = tty_fops;
38897+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38898 }
38899
38900 /*
38901diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38902index 9911eb6..5abe0e1 100644
38903--- a/drivers/tty/tty_ldisc.c
38904+++ b/drivers/tty/tty_ldisc.c
38905@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38906 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38907 struct tty_ldisc_ops *ldo = ld->ops;
38908
38909- ldo->refcount--;
38910+ atomic_dec(&ldo->refcount);
38911 module_put(ldo->owner);
38912 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38913
38914@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38915 spin_lock_irqsave(&tty_ldisc_lock, flags);
38916 tty_ldiscs[disc] = new_ldisc;
38917 new_ldisc->num = disc;
38918- new_ldisc->refcount = 0;
38919+ atomic_set(&new_ldisc->refcount, 0);
38920 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38921
38922 return ret;
38923@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38924 return -EINVAL;
38925
38926 spin_lock_irqsave(&tty_ldisc_lock, flags);
38927- if (tty_ldiscs[disc]->refcount)
38928+ if (atomic_read(&tty_ldiscs[disc]->refcount))
38929 ret = -EBUSY;
38930 else
38931 tty_ldiscs[disc] = NULL;
38932@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38933 if (ldops) {
38934 ret = ERR_PTR(-EAGAIN);
38935 if (try_module_get(ldops->owner)) {
38936- ldops->refcount++;
38937+ atomic_inc(&ldops->refcount);
38938 ret = ldops;
38939 }
38940 }
38941@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38942 unsigned long flags;
38943
38944 spin_lock_irqsave(&tty_ldisc_lock, flags);
38945- ldops->refcount--;
38946+ atomic_dec(&ldops->refcount);
38947 module_put(ldops->owner);
38948 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38949 }
38950diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38951index bf6e238..d401c04 100644
38952--- a/drivers/tty/tty_port.c
38953+++ b/drivers/tty/tty_port.c
38954@@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38955 unsigned long flags;
38956
38957 spin_lock_irqsave(&port->lock, flags);
38958- port->count = 0;
38959+ atomic_set(&port->count, 0);
38960 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38961 if (port->tty) {
38962 set_bit(TTY_IO_ERROR, &port->tty->flags);
38963@@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38964 /* The port lock protects the port counts */
38965 spin_lock_irqsave(&port->lock, flags);
38966 if (!tty_hung_up_p(filp))
38967- port->count--;
38968+ atomic_dec(&port->count);
38969 port->blocked_open++;
38970 spin_unlock_irqrestore(&port->lock, flags);
38971
38972@@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38973 we must not mess that up further */
38974 spin_lock_irqsave(&port->lock, flags);
38975 if (!tty_hung_up_p(filp))
38976- port->count++;
38977+ atomic_inc(&port->count);
38978 port->blocked_open--;
38979 if (retval == 0)
38980 port->flags |= ASYNC_NORMAL_ACTIVE;
38981@@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38982 return 0;
38983 }
38984
38985- if (tty->count == 1 && port->count != 1) {
38986+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
38987 printk(KERN_WARNING
38988 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38989- port->count);
38990- port->count = 1;
38991+ atomic_read(&port->count));
38992+ atomic_set(&port->count, 1);
38993 }
38994- if (--port->count < 0) {
38995+ if (atomic_dec_return(&port->count) < 0) {
38996 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38997- port->count);
38998- port->count = 0;
38999+ atomic_read(&port->count));
39000+ atomic_set(&port->count, 0);
39001 }
39002
39003- if (port->count) {
39004+ if (atomic_read(&port->count)) {
39005 spin_unlock_irqrestore(&port->lock, flags);
39006 if (port->ops->drop)
39007 port->ops->drop(port);
39008@@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
39009 {
39010 spin_lock_irq(&port->lock);
39011 if (!tty_hung_up_p(filp))
39012- ++port->count;
39013+ atomic_inc(&port->count);
39014 spin_unlock_irq(&port->lock);
39015 tty_port_tty_set(port, tty);
39016
39017diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
39018index 770a854..e5d3db3 100644
39019--- a/drivers/tty/vt/keyboard.c
39020+++ b/drivers/tty/vt/keyboard.c
39021@@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
39022 kbd->kbdmode == VC_OFF) &&
39023 value != KVAL(K_SAK))
39024 return; /* SAK is allowed even in raw mode */
39025+
39026+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
39027+ {
39028+ void *func = fn_handler[value];
39029+ if (func == fn_show_state || func == fn_show_ptregs ||
39030+ func == fn_show_mem)
39031+ return;
39032+ }
39033+#endif
39034+
39035 fn_handler[value](vc);
39036 }
39037
39038@@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39039 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
39040 return -EFAULT;
39041
39042- if (!capable(CAP_SYS_TTY_CONFIG))
39043- perm = 0;
39044-
39045 switch (cmd) {
39046 case KDGKBENT:
39047 /* Ensure another thread doesn't free it under us */
39048@@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39049 spin_unlock_irqrestore(&kbd_event_lock, flags);
39050 return put_user(val, &user_kbe->kb_value);
39051 case KDSKBENT:
39052+ if (!capable(CAP_SYS_TTY_CONFIG))
39053+ perm = 0;
39054+
39055 if (!perm)
39056 return -EPERM;
39057 if (!i && v == K_NOSUCHMAP) {
39058@@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39059 int i, j, k;
39060 int ret;
39061
39062- if (!capable(CAP_SYS_TTY_CONFIG))
39063- perm = 0;
39064-
39065 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
39066 if (!kbs) {
39067 ret = -ENOMEM;
39068@@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39069 kfree(kbs);
39070 return ((p && *p) ? -EOVERFLOW : 0);
39071 case KDSKBSENT:
39072+ if (!capable(CAP_SYS_TTY_CONFIG))
39073+ perm = 0;
39074+
39075 if (!perm) {
39076 ret = -EPERM;
39077 goto reterr;
39078diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
39079index a783d53..cb30d94 100644
39080--- a/drivers/uio/uio.c
39081+++ b/drivers/uio/uio.c
39082@@ -25,6 +25,7 @@
39083 #include <linux/kobject.h>
39084 #include <linux/cdev.h>
39085 #include <linux/uio_driver.h>
39086+#include <asm/local.h>
39087
39088 #define UIO_MAX_DEVICES (1U << MINORBITS)
39089
39090@@ -32,10 +33,10 @@ struct uio_device {
39091 struct module *owner;
39092 struct device *dev;
39093 int minor;
39094- atomic_t event;
39095+ atomic_unchecked_t event;
39096 struct fasync_struct *async_queue;
39097 wait_queue_head_t wait;
39098- int vma_count;
39099+ local_t vma_count;
39100 struct uio_info *info;
39101 struct kobject *map_dir;
39102 struct kobject *portio_dir;
39103@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39104 struct device_attribute *attr, char *buf)
39105 {
39106 struct uio_device *idev = dev_get_drvdata(dev);
39107- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39108+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39109 }
39110
39111 static struct device_attribute uio_class_attributes[] = {
39112@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39113 {
39114 struct uio_device *idev = info->uio_dev;
39115
39116- atomic_inc(&idev->event);
39117+ atomic_inc_unchecked(&idev->event);
39118 wake_up_interruptible(&idev->wait);
39119 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39120 }
39121@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39122 }
39123
39124 listener->dev = idev;
39125- listener->event_count = atomic_read(&idev->event);
39126+ listener->event_count = atomic_read_unchecked(&idev->event);
39127 filep->private_data = listener;
39128
39129 if (idev->info->open) {
39130@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39131 return -EIO;
39132
39133 poll_wait(filep, &idev->wait, wait);
39134- if (listener->event_count != atomic_read(&idev->event))
39135+ if (listener->event_count != atomic_read_unchecked(&idev->event))
39136 return POLLIN | POLLRDNORM;
39137 return 0;
39138 }
39139@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39140 do {
39141 set_current_state(TASK_INTERRUPTIBLE);
39142
39143- event_count = atomic_read(&idev->event);
39144+ event_count = atomic_read_unchecked(&idev->event);
39145 if (event_count != listener->event_count) {
39146 if (copy_to_user(buf, &event_count, count))
39147 retval = -EFAULT;
39148@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39149 static void uio_vma_open(struct vm_area_struct *vma)
39150 {
39151 struct uio_device *idev = vma->vm_private_data;
39152- idev->vma_count++;
39153+ local_inc(&idev->vma_count);
39154 }
39155
39156 static void uio_vma_close(struct vm_area_struct *vma)
39157 {
39158 struct uio_device *idev = vma->vm_private_data;
39159- idev->vma_count--;
39160+ local_dec(&idev->vma_count);
39161 }
39162
39163 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39164@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39165 idev->owner = owner;
39166 idev->info = info;
39167 init_waitqueue_head(&idev->wait);
39168- atomic_set(&idev->event, 0);
39169+ atomic_set_unchecked(&idev->event, 0);
39170
39171 ret = uio_get_minor(idev);
39172 if (ret)
39173diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39174index b7eb86a..36d28af 100644
39175--- a/drivers/usb/atm/cxacru.c
39176+++ b/drivers/usb/atm/cxacru.c
39177@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39178 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39179 if (ret < 2)
39180 return -EINVAL;
39181- if (index < 0 || index > 0x7f)
39182+ if (index > 0x7f)
39183 return -EINVAL;
39184 pos += tmp;
39185
39186diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39187index ee62b35..b663594 100644
39188--- a/drivers/usb/atm/usbatm.c
39189+++ b/drivers/usb/atm/usbatm.c
39190@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39191 if (printk_ratelimit())
39192 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39193 __func__, vpi, vci);
39194- atomic_inc(&vcc->stats->rx_err);
39195+ atomic_inc_unchecked(&vcc->stats->rx_err);
39196 return;
39197 }
39198
39199@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39200 if (length > ATM_MAX_AAL5_PDU) {
39201 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39202 __func__, length, vcc);
39203- atomic_inc(&vcc->stats->rx_err);
39204+ atomic_inc_unchecked(&vcc->stats->rx_err);
39205 goto out;
39206 }
39207
39208@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39209 if (sarb->len < pdu_length) {
39210 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39211 __func__, pdu_length, sarb->len, vcc);
39212- atomic_inc(&vcc->stats->rx_err);
39213+ atomic_inc_unchecked(&vcc->stats->rx_err);
39214 goto out;
39215 }
39216
39217 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39218 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39219 __func__, vcc);
39220- atomic_inc(&vcc->stats->rx_err);
39221+ atomic_inc_unchecked(&vcc->stats->rx_err);
39222 goto out;
39223 }
39224
39225@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39226 if (printk_ratelimit())
39227 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39228 __func__, length);
39229- atomic_inc(&vcc->stats->rx_drop);
39230+ atomic_inc_unchecked(&vcc->stats->rx_drop);
39231 goto out;
39232 }
39233
39234@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39235
39236 vcc->push(vcc, skb);
39237
39238- atomic_inc(&vcc->stats->rx);
39239+ atomic_inc_unchecked(&vcc->stats->rx);
39240 out:
39241 skb_trim(sarb, 0);
39242 }
39243@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39244 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39245
39246 usbatm_pop(vcc, skb);
39247- atomic_inc(&vcc->stats->tx);
39248+ atomic_inc_unchecked(&vcc->stats->tx);
39249
39250 skb = skb_dequeue(&instance->sndqueue);
39251 }
39252@@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39253 if (!left--)
39254 return sprintf(page,
39255 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39256- atomic_read(&atm_dev->stats.aal5.tx),
39257- atomic_read(&atm_dev->stats.aal5.tx_err),
39258- atomic_read(&atm_dev->stats.aal5.rx),
39259- atomic_read(&atm_dev->stats.aal5.rx_err),
39260- atomic_read(&atm_dev->stats.aal5.rx_drop));
39261+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39262+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39263+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39264+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39265+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39266
39267 if (!left--) {
39268 if (instance->disconnected)
39269diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39270index 3440812..2a4ef1f 100644
39271--- a/drivers/usb/core/devices.c
39272+++ b/drivers/usb/core/devices.c
39273@@ -126,7 +126,7 @@ static const char format_endpt[] =
39274 * time it gets called.
39275 */
39276 static struct device_connect_event {
39277- atomic_t count;
39278+ atomic_unchecked_t count;
39279 wait_queue_head_t wait;
39280 } device_event = {
39281 .count = ATOMIC_INIT(1),
39282@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39283
39284 void usbfs_conn_disc_event(void)
39285 {
39286- atomic_add(2, &device_event.count);
39287+ atomic_add_unchecked(2, &device_event.count);
39288 wake_up(&device_event.wait);
39289 }
39290
39291@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39292
39293 poll_wait(file, &device_event.wait, wait);
39294
39295- event_count = atomic_read(&device_event.count);
39296+ event_count = atomic_read_unchecked(&device_event.count);
39297 if (file->f_version != event_count) {
39298 file->f_version = event_count;
39299 return POLLIN | POLLRDNORM;
39300diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39301index 347bb05..63e1b73 100644
39302--- a/drivers/usb/early/ehci-dbgp.c
39303+++ b/drivers/usb/early/ehci-dbgp.c
39304@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39305
39306 #ifdef CONFIG_KGDB
39307 static struct kgdb_io kgdbdbgp_io_ops;
39308-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39309+static struct kgdb_io kgdbdbgp_io_ops_console;
39310+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39311 #else
39312 #define dbgp_kgdb_mode (0)
39313 #endif
39314@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39315 .write_char = kgdbdbgp_write_char,
39316 };
39317
39318+static struct kgdb_io kgdbdbgp_io_ops_console = {
39319+ .name = "kgdbdbgp",
39320+ .read_char = kgdbdbgp_read_char,
39321+ .write_char = kgdbdbgp_write_char,
39322+ .is_console = 1
39323+};
39324+
39325 static int kgdbdbgp_wait_time;
39326
39327 static int __init kgdbdbgp_parse_config(char *str)
39328@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39329 ptr++;
39330 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39331 }
39332- kgdb_register_io_module(&kgdbdbgp_io_ops);
39333- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39334+ if (early_dbgp_console.index != -1)
39335+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39336+ else
39337+ kgdb_register_io_module(&kgdbdbgp_io_ops);
39338
39339 return 0;
39340 }
39341diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39342index 5b3f5ff..6e00893 100644
39343--- a/drivers/usb/gadget/u_serial.c
39344+++ b/drivers/usb/gadget/u_serial.c
39345@@ -731,9 +731,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39346 spin_lock_irq(&port->port_lock);
39347
39348 /* already open? Great. */
39349- if (port->port.count) {
39350+ if (atomic_read(&port->port.count)) {
39351 status = 0;
39352- port->port.count++;
39353+ atomic_inc(&port->port.count);
39354
39355 /* currently opening/closing? wait ... */
39356 } else if (port->openclose) {
39357@@ -792,7 +792,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39358 tty->driver_data = port;
39359 port->port.tty = tty;
39360
39361- port->port.count = 1;
39362+ atomic_set(&port->port.count, 1);
39363 port->openclose = false;
39364
39365 /* if connected, start the I/O stream */
39366@@ -834,11 +834,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39367
39368 spin_lock_irq(&port->port_lock);
39369
39370- if (port->port.count != 1) {
39371- if (port->port.count == 0)
39372+ if (atomic_read(&port->port.count) != 1) {
39373+ if (atomic_read(&port->port.count) == 0)
39374 WARN_ON(1);
39375 else
39376- --port->port.count;
39377+ atomic_dec(&port->port.count);
39378 goto exit;
39379 }
39380
39381@@ -848,7 +848,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39382 * and sleep if necessary
39383 */
39384 port->openclose = true;
39385- port->port.count = 0;
39386+ atomic_set(&port->port.count, 0);
39387
39388 gser = port->port_usb;
39389 if (gser && gser->disconnect)
39390@@ -1152,7 +1152,7 @@ static int gs_closed(struct gs_port *port)
39391 int cond;
39392
39393 spin_lock_irq(&port->port_lock);
39394- cond = (port->port.count == 0) && !port->openclose;
39395+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39396 spin_unlock_irq(&port->port_lock);
39397 return cond;
39398 }
39399@@ -1265,7 +1265,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39400 /* if it's already open, start I/O ... and notify the serial
39401 * protocol about open/close status (connect/disconnect).
39402 */
39403- if (port->port.count) {
39404+ if (atomic_read(&port->port.count)) {
39405 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39406 gs_start_io(port);
39407 if (gser->connect)
39408@@ -1312,7 +1312,7 @@ void gserial_disconnect(struct gserial *gser)
39409
39410 port->port_usb = NULL;
39411 gser->ioport = NULL;
39412- if (port->port.count > 0 || port->openclose) {
39413+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
39414 wake_up_interruptible(&port->drain_wait);
39415 if (port->port.tty)
39416 tty_hangup(port->port.tty);
39417@@ -1328,7 +1328,7 @@ void gserial_disconnect(struct gserial *gser)
39418
39419 /* finally, free any unused/unusable I/O buffers */
39420 spin_lock_irqsave(&port->port_lock, flags);
39421- if (port->port.count == 0 && !port->openclose)
39422+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
39423 gs_buf_free(&port->port_write_buf);
39424 gs_free_requests(gser->out, &port->read_pool, NULL);
39425 gs_free_requests(gser->out, &port->read_queue, NULL);
39426diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39427index b9cca6d..75c75df 100644
39428--- a/drivers/usb/serial/console.c
39429+++ b/drivers/usb/serial/console.c
39430@@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39431
39432 info->port = port;
39433
39434- ++port->port.count;
39435+ atomic_inc(&port->port.count);
39436 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39437 if (serial->type->set_termios) {
39438 /*
39439@@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39440 }
39441 /* Now that any required fake tty operations are completed restore
39442 * the tty port count */
39443- --port->port.count;
39444+ atomic_dec(&port->port.count);
39445 /* The console is special in terms of closing the device so
39446 * indicate this port is now acting as a system console. */
39447 port->port.console = 1;
39448@@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39449 free_tty:
39450 kfree(tty);
39451 reset_open_count:
39452- port->port.count = 0;
39453+ atomic_set(&port->port.count, 0);
39454 usb_autopm_put_interface(serial->interface);
39455 error_get_interface:
39456 usb_serial_put(serial);
39457diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39458index d6bea3e..60b250e 100644
39459--- a/drivers/usb/wusbcore/wa-hc.h
39460+++ b/drivers/usb/wusbcore/wa-hc.h
39461@@ -192,7 +192,7 @@ struct wahc {
39462 struct list_head xfer_delayed_list;
39463 spinlock_t xfer_list_lock;
39464 struct work_struct xfer_work;
39465- atomic_t xfer_id_count;
39466+ atomic_unchecked_t xfer_id_count;
39467 };
39468
39469
39470@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39471 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39472 spin_lock_init(&wa->xfer_list_lock);
39473 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39474- atomic_set(&wa->xfer_id_count, 1);
39475+ atomic_set_unchecked(&wa->xfer_id_count, 1);
39476 }
39477
39478 /**
39479diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39480index 57c01ab..8a05959 100644
39481--- a/drivers/usb/wusbcore/wa-xfer.c
39482+++ b/drivers/usb/wusbcore/wa-xfer.c
39483@@ -296,7 +296,7 @@ out:
39484 */
39485 static void wa_xfer_id_init(struct wa_xfer *xfer)
39486 {
39487- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39488+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39489 }
39490
39491 /*
39492diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39493index 112156f..eb81154 100644
39494--- a/drivers/vhost/vhost.c
39495+++ b/drivers/vhost/vhost.c
39496@@ -635,7 +635,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39497 return 0;
39498 }
39499
39500-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39501+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39502 {
39503 struct file *eventfp, *filep = NULL,
39504 *pollstart = NULL, *pollstop = NULL;
39505diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39506index b0b2ac3..89a4399 100644
39507--- a/drivers/video/aty/aty128fb.c
39508+++ b/drivers/video/aty/aty128fb.c
39509@@ -148,7 +148,7 @@ enum {
39510 };
39511
39512 /* Must match above enum */
39513-static const char *r128_family[] __devinitdata = {
39514+static const char *r128_family[] __devinitconst = {
39515 "AGP",
39516 "PCI",
39517 "PRO AGP",
39518diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
39519index 88e9204..fdefa8f 100644
39520--- a/drivers/video/console/fbcon.c
39521+++ b/drivers/video/console/fbcon.c
39522@@ -449,7 +449,7 @@ static int __init fb_console_setup(char *this_opt)
39523
39524 while ((options = strsep(&this_opt, ",")) != NULL) {
39525 if (!strncmp(options, "font:", 5))
39526- strcpy(fontname, options + 5);
39527+ strlcpy(fontname, options + 5, sizeof(fontname));
39528
39529 if (!strncmp(options, "scrollback:", 11)) {
39530 options += 11;
39531diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39532index 5c3960d..15cf8fc 100644
39533--- a/drivers/video/fbcmap.c
39534+++ b/drivers/video/fbcmap.c
39535@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39536 rc = -ENODEV;
39537 goto out;
39538 }
39539- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39540- !info->fbops->fb_setcmap)) {
39541+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39542 rc = -EINVAL;
39543 goto out1;
39544 }
39545diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39546index 0dff12a..2ef47b3 100644
39547--- a/drivers/video/fbmem.c
39548+++ b/drivers/video/fbmem.c
39549@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39550 image->dx += image->width + 8;
39551 }
39552 } else if (rotate == FB_ROTATE_UD) {
39553- for (x = 0; x < num && image->dx >= 0; x++) {
39554+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39555 info->fbops->fb_imageblit(info, image);
39556 image->dx -= image->width + 8;
39557 }
39558@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39559 image->dy += image->height + 8;
39560 }
39561 } else if (rotate == FB_ROTATE_CCW) {
39562- for (x = 0; x < num && image->dy >= 0; x++) {
39563+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39564 info->fbops->fb_imageblit(info, image);
39565 image->dy -= image->height + 8;
39566 }
39567@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39568 return -EFAULT;
39569 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39570 return -EINVAL;
39571- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39572+ if (con2fb.framebuffer >= FB_MAX)
39573 return -EINVAL;
39574 if (!registered_fb[con2fb.framebuffer])
39575 request_module("fb%d", con2fb.framebuffer);
39576diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39577index 5a5d092..265c5ed 100644
39578--- a/drivers/video/geode/gx1fb_core.c
39579+++ b/drivers/video/geode/gx1fb_core.c
39580@@ -29,7 +29,7 @@ static int crt_option = 1;
39581 static char panel_option[32] = "";
39582
39583 /* Modes relevant to the GX1 (taken from modedb.c) */
39584-static const struct fb_videomode __devinitdata gx1_modedb[] = {
39585+static const struct fb_videomode __devinitconst gx1_modedb[] = {
39586 /* 640x480-60 VESA */
39587 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39588 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39589diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39590index 0fad23f..0e9afa4 100644
39591--- a/drivers/video/gxt4500.c
39592+++ b/drivers/video/gxt4500.c
39593@@ -156,7 +156,7 @@ struct gxt4500_par {
39594 static char *mode_option;
39595
39596 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39597-static const struct fb_videomode defaultmode __devinitdata = {
39598+static const struct fb_videomode defaultmode __devinitconst = {
39599 .refresh = 60,
39600 .xres = 1280,
39601 .yres = 1024,
39602@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39603 return 0;
39604 }
39605
39606-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39607+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39608 .id = "IBM GXT4500P",
39609 .type = FB_TYPE_PACKED_PIXELS,
39610 .visual = FB_VISUAL_PSEUDOCOLOR,
39611diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39612index 7672d2e..b56437f 100644
39613--- a/drivers/video/i810/i810_accel.c
39614+++ b/drivers/video/i810/i810_accel.c
39615@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39616 }
39617 }
39618 printk("ringbuffer lockup!!!\n");
39619+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39620 i810_report_error(mmio);
39621 par->dev_flags |= LOCKUP;
39622 info->pixmap.scan_align = 1;
39623diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39624index b83f361..2b05a91 100644
39625--- a/drivers/video/i810/i810_main.c
39626+++ b/drivers/video/i810/i810_main.c
39627@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39628 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39629
39630 /* PCI */
39631-static const char *i810_pci_list[] __devinitdata = {
39632+static const char *i810_pci_list[] __devinitconst = {
39633 "Intel(R) 810 Framebuffer Device" ,
39634 "Intel(R) 810-DC100 Framebuffer Device" ,
39635 "Intel(R) 810E Framebuffer Device" ,
39636diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39637index de36693..3c63fc2 100644
39638--- a/drivers/video/jz4740_fb.c
39639+++ b/drivers/video/jz4740_fb.c
39640@@ -136,7 +136,7 @@ struct jzfb {
39641 uint32_t pseudo_palette[16];
39642 };
39643
39644-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39645+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39646 .id = "JZ4740 FB",
39647 .type = FB_TYPE_PACKED_PIXELS,
39648 .visual = FB_VISUAL_TRUECOLOR,
39649diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39650index 3c14e43..eafa544 100644
39651--- a/drivers/video/logo/logo_linux_clut224.ppm
39652+++ b/drivers/video/logo/logo_linux_clut224.ppm
39653@@ -1,1604 +1,1123 @@
39654 P3
39655-# Standard 224-color Linux logo
39656 80 80
39657 255
39658- 0 0 0 0 0 0 0 0 0 0 0 0
39659- 0 0 0 0 0 0 0 0 0 0 0 0
39660- 0 0 0 0 0 0 0 0 0 0 0 0
39661- 0 0 0 0 0 0 0 0 0 0 0 0
39662- 0 0 0 0 0 0 0 0 0 0 0 0
39663- 0 0 0 0 0 0 0 0 0 0 0 0
39664- 0 0 0 0 0 0 0 0 0 0 0 0
39665- 0 0 0 0 0 0 0 0 0 0 0 0
39666- 0 0 0 0 0 0 0 0 0 0 0 0
39667- 6 6 6 6 6 6 10 10 10 10 10 10
39668- 10 10 10 6 6 6 6 6 6 6 6 6
39669- 0 0 0 0 0 0 0 0 0 0 0 0
39670- 0 0 0 0 0 0 0 0 0 0 0 0
39671- 0 0 0 0 0 0 0 0 0 0 0 0
39672- 0 0 0 0 0 0 0 0 0 0 0 0
39673- 0 0 0 0 0 0 0 0 0 0 0 0
39674- 0 0 0 0 0 0 0 0 0 0 0 0
39675- 0 0 0 0 0 0 0 0 0 0 0 0
39676- 0 0 0 0 0 0 0 0 0 0 0 0
39677- 0 0 0 0 0 0 0 0 0 0 0 0
39678- 0 0 0 0 0 0 0 0 0 0 0 0
39679- 0 0 0 0 0 0 0 0 0 0 0 0
39680- 0 0 0 0 0 0 0 0 0 0 0 0
39681- 0 0 0 0 0 0 0 0 0 0 0 0
39682- 0 0 0 0 0 0 0 0 0 0 0 0
39683- 0 0 0 0 0 0 0 0 0 0 0 0
39684- 0 0 0 0 0 0 0 0 0 0 0 0
39685- 0 0 0 0 0 0 0 0 0 0 0 0
39686- 0 0 0 6 6 6 10 10 10 14 14 14
39687- 22 22 22 26 26 26 30 30 30 34 34 34
39688- 30 30 30 30 30 30 26 26 26 18 18 18
39689- 14 14 14 10 10 10 6 6 6 0 0 0
39690- 0 0 0 0 0 0 0 0 0 0 0 0
39691- 0 0 0 0 0 0 0 0 0 0 0 0
39692- 0 0 0 0 0 0 0 0 0 0 0 0
39693- 0 0 0 0 0 0 0 0 0 0 0 0
39694- 0 0 0 0 0 0 0 0 0 0 0 0
39695- 0 0 0 0 0 0 0 0 0 0 0 0
39696- 0 0 0 0 0 0 0 0 0 0 0 0
39697- 0 0 0 0 0 0 0 0 0 0 0 0
39698- 0 0 0 0 0 0 0 0 0 0 0 0
39699- 0 0 0 0 0 1 0 0 1 0 0 0
39700- 0 0 0 0 0 0 0 0 0 0 0 0
39701- 0 0 0 0 0 0 0 0 0 0 0 0
39702- 0 0 0 0 0 0 0 0 0 0 0 0
39703- 0 0 0 0 0 0 0 0 0 0 0 0
39704- 0 0 0 0 0 0 0 0 0 0 0 0
39705- 0 0 0 0 0 0 0 0 0 0 0 0
39706- 6 6 6 14 14 14 26 26 26 42 42 42
39707- 54 54 54 66 66 66 78 78 78 78 78 78
39708- 78 78 78 74 74 74 66 66 66 54 54 54
39709- 42 42 42 26 26 26 18 18 18 10 10 10
39710- 6 6 6 0 0 0 0 0 0 0 0 0
39711- 0 0 0 0 0 0 0 0 0 0 0 0
39712- 0 0 0 0 0 0 0 0 0 0 0 0
39713- 0 0 0 0 0 0 0 0 0 0 0 0
39714- 0 0 0 0 0 0 0 0 0 0 0 0
39715- 0 0 0 0 0 0 0 0 0 0 0 0
39716- 0 0 0 0 0 0 0 0 0 0 0 0
39717- 0 0 0 0 0 0 0 0 0 0 0 0
39718- 0 0 0 0 0 0 0 0 0 0 0 0
39719- 0 0 1 0 0 0 0 0 0 0 0 0
39720- 0 0 0 0 0 0 0 0 0 0 0 0
39721- 0 0 0 0 0 0 0 0 0 0 0 0
39722- 0 0 0 0 0 0 0 0 0 0 0 0
39723- 0 0 0 0 0 0 0 0 0 0 0 0
39724- 0 0 0 0 0 0 0 0 0 0 0 0
39725- 0 0 0 0 0 0 0 0 0 10 10 10
39726- 22 22 22 42 42 42 66 66 66 86 86 86
39727- 66 66 66 38 38 38 38 38 38 22 22 22
39728- 26 26 26 34 34 34 54 54 54 66 66 66
39729- 86 86 86 70 70 70 46 46 46 26 26 26
39730- 14 14 14 6 6 6 0 0 0 0 0 0
39731- 0 0 0 0 0 0 0 0 0 0 0 0
39732- 0 0 0 0 0 0 0 0 0 0 0 0
39733- 0 0 0 0 0 0 0 0 0 0 0 0
39734- 0 0 0 0 0 0 0 0 0 0 0 0
39735- 0 0 0 0 0 0 0 0 0 0 0 0
39736- 0 0 0 0 0 0 0 0 0 0 0 0
39737- 0 0 0 0 0 0 0 0 0 0 0 0
39738- 0 0 0 0 0 0 0 0 0 0 0 0
39739- 0 0 1 0 0 1 0 0 1 0 0 0
39740- 0 0 0 0 0 0 0 0 0 0 0 0
39741- 0 0 0 0 0 0 0 0 0 0 0 0
39742- 0 0 0 0 0 0 0 0 0 0 0 0
39743- 0 0 0 0 0 0 0 0 0 0 0 0
39744- 0 0 0 0 0 0 0 0 0 0 0 0
39745- 0 0 0 0 0 0 10 10 10 26 26 26
39746- 50 50 50 82 82 82 58 58 58 6 6 6
39747- 2 2 6 2 2 6 2 2 6 2 2 6
39748- 2 2 6 2 2 6 2 2 6 2 2 6
39749- 6 6 6 54 54 54 86 86 86 66 66 66
39750- 38 38 38 18 18 18 6 6 6 0 0 0
39751- 0 0 0 0 0 0 0 0 0 0 0 0
39752- 0 0 0 0 0 0 0 0 0 0 0 0
39753- 0 0 0 0 0 0 0 0 0 0 0 0
39754- 0 0 0 0 0 0 0 0 0 0 0 0
39755- 0 0 0 0 0 0 0 0 0 0 0 0
39756- 0 0 0 0 0 0 0 0 0 0 0 0
39757- 0 0 0 0 0 0 0 0 0 0 0 0
39758- 0 0 0 0 0 0 0 0 0 0 0 0
39759- 0 0 0 0 0 0 0 0 0 0 0 0
39760- 0 0 0 0 0 0 0 0 0 0 0 0
39761- 0 0 0 0 0 0 0 0 0 0 0 0
39762- 0 0 0 0 0 0 0 0 0 0 0 0
39763- 0 0 0 0 0 0 0 0 0 0 0 0
39764- 0 0 0 0 0 0 0 0 0 0 0 0
39765- 0 0 0 6 6 6 22 22 22 50 50 50
39766- 78 78 78 34 34 34 2 2 6 2 2 6
39767- 2 2 6 2 2 6 2 2 6 2 2 6
39768- 2 2 6 2 2 6 2 2 6 2 2 6
39769- 2 2 6 2 2 6 6 6 6 70 70 70
39770- 78 78 78 46 46 46 22 22 22 6 6 6
39771- 0 0 0 0 0 0 0 0 0 0 0 0
39772- 0 0 0 0 0 0 0 0 0 0 0 0
39773- 0 0 0 0 0 0 0 0 0 0 0 0
39774- 0 0 0 0 0 0 0 0 0 0 0 0
39775- 0 0 0 0 0 0 0 0 0 0 0 0
39776- 0 0 0 0 0 0 0 0 0 0 0 0
39777- 0 0 0 0 0 0 0 0 0 0 0 0
39778- 0 0 0 0 0 0 0 0 0 0 0 0
39779- 0 0 1 0 0 1 0 0 1 0 0 0
39780- 0 0 0 0 0 0 0 0 0 0 0 0
39781- 0 0 0 0 0 0 0 0 0 0 0 0
39782- 0 0 0 0 0 0 0 0 0 0 0 0
39783- 0 0 0 0 0 0 0 0 0 0 0 0
39784- 0 0 0 0 0 0 0 0 0 0 0 0
39785- 6 6 6 18 18 18 42 42 42 82 82 82
39786- 26 26 26 2 2 6 2 2 6 2 2 6
39787- 2 2 6 2 2 6 2 2 6 2 2 6
39788- 2 2 6 2 2 6 2 2 6 14 14 14
39789- 46 46 46 34 34 34 6 6 6 2 2 6
39790- 42 42 42 78 78 78 42 42 42 18 18 18
39791- 6 6 6 0 0 0 0 0 0 0 0 0
39792- 0 0 0 0 0 0 0 0 0 0 0 0
39793- 0 0 0 0 0 0 0 0 0 0 0 0
39794- 0 0 0 0 0 0 0 0 0 0 0 0
39795- 0 0 0 0 0 0 0 0 0 0 0 0
39796- 0 0 0 0 0 0 0 0 0 0 0 0
39797- 0 0 0 0 0 0 0 0 0 0 0 0
39798- 0 0 0 0 0 0 0 0 0 0 0 0
39799- 0 0 1 0 0 0 0 0 1 0 0 0
39800- 0 0 0 0 0 0 0 0 0 0 0 0
39801- 0 0 0 0 0 0 0 0 0 0 0 0
39802- 0 0 0 0 0 0 0 0 0 0 0 0
39803- 0 0 0 0 0 0 0 0 0 0 0 0
39804- 0 0 0 0 0 0 0 0 0 0 0 0
39805- 10 10 10 30 30 30 66 66 66 58 58 58
39806- 2 2 6 2 2 6 2 2 6 2 2 6
39807- 2 2 6 2 2 6 2 2 6 2 2 6
39808- 2 2 6 2 2 6 2 2 6 26 26 26
39809- 86 86 86 101 101 101 46 46 46 10 10 10
39810- 2 2 6 58 58 58 70 70 70 34 34 34
39811- 10 10 10 0 0 0 0 0 0 0 0 0
39812- 0 0 0 0 0 0 0 0 0 0 0 0
39813- 0 0 0 0 0 0 0 0 0 0 0 0
39814- 0 0 0 0 0 0 0 0 0 0 0 0
39815- 0 0 0 0 0 0 0 0 0 0 0 0
39816- 0 0 0 0 0 0 0 0 0 0 0 0
39817- 0 0 0 0 0 0 0 0 0 0 0 0
39818- 0 0 0 0 0 0 0 0 0 0 0 0
39819- 0 0 1 0 0 1 0 0 1 0 0 0
39820- 0 0 0 0 0 0 0 0 0 0 0 0
39821- 0 0 0 0 0 0 0 0 0 0 0 0
39822- 0 0 0 0 0 0 0 0 0 0 0 0
39823- 0 0 0 0 0 0 0 0 0 0 0 0
39824- 0 0 0 0 0 0 0 0 0 0 0 0
39825- 14 14 14 42 42 42 86 86 86 10 10 10
39826- 2 2 6 2 2 6 2 2 6 2 2 6
39827- 2 2 6 2 2 6 2 2 6 2 2 6
39828- 2 2 6 2 2 6 2 2 6 30 30 30
39829- 94 94 94 94 94 94 58 58 58 26 26 26
39830- 2 2 6 6 6 6 78 78 78 54 54 54
39831- 22 22 22 6 6 6 0 0 0 0 0 0
39832- 0 0 0 0 0 0 0 0 0 0 0 0
39833- 0 0 0 0 0 0 0 0 0 0 0 0
39834- 0 0 0 0 0 0 0 0 0 0 0 0
39835- 0 0 0 0 0 0 0 0 0 0 0 0
39836- 0 0 0 0 0 0 0 0 0 0 0 0
39837- 0 0 0 0 0 0 0 0 0 0 0 0
39838- 0 0 0 0 0 0 0 0 0 0 0 0
39839- 0 0 0 0 0 0 0 0 0 0 0 0
39840- 0 0 0 0 0 0 0 0 0 0 0 0
39841- 0 0 0 0 0 0 0 0 0 0 0 0
39842- 0 0 0 0 0 0 0 0 0 0 0 0
39843- 0 0 0 0 0 0 0 0 0 0 0 0
39844- 0 0 0 0 0 0 0 0 0 6 6 6
39845- 22 22 22 62 62 62 62 62 62 2 2 6
39846- 2 2 6 2 2 6 2 2 6 2 2 6
39847- 2 2 6 2 2 6 2 2 6 2 2 6
39848- 2 2 6 2 2 6 2 2 6 26 26 26
39849- 54 54 54 38 38 38 18 18 18 10 10 10
39850- 2 2 6 2 2 6 34 34 34 82 82 82
39851- 38 38 38 14 14 14 0 0 0 0 0 0
39852- 0 0 0 0 0 0 0 0 0 0 0 0
39853- 0 0 0 0 0 0 0 0 0 0 0 0
39854- 0 0 0 0 0 0 0 0 0 0 0 0
39855- 0 0 0 0 0 0 0 0 0 0 0 0
39856- 0 0 0 0 0 0 0 0 0 0 0 0
39857- 0 0 0 0 0 0 0 0 0 0 0 0
39858- 0 0 0 0 0 0 0 0 0 0 0 0
39859- 0 0 0 0 0 1 0 0 1 0 0 0
39860- 0 0 0 0 0 0 0 0 0 0 0 0
39861- 0 0 0 0 0 0 0 0 0 0 0 0
39862- 0 0 0 0 0 0 0 0 0 0 0 0
39863- 0 0 0 0 0 0 0 0 0 0 0 0
39864- 0 0 0 0 0 0 0 0 0 6 6 6
39865- 30 30 30 78 78 78 30 30 30 2 2 6
39866- 2 2 6 2 2 6 2 2 6 2 2 6
39867- 2 2 6 2 2 6 2 2 6 2 2 6
39868- 2 2 6 2 2 6 2 2 6 10 10 10
39869- 10 10 10 2 2 6 2 2 6 2 2 6
39870- 2 2 6 2 2 6 2 2 6 78 78 78
39871- 50 50 50 18 18 18 6 6 6 0 0 0
39872- 0 0 0 0 0 0 0 0 0 0 0 0
39873- 0 0 0 0 0 0 0 0 0 0 0 0
39874- 0 0 0 0 0 0 0 0 0 0 0 0
39875- 0 0 0 0 0 0 0 0 0 0 0 0
39876- 0 0 0 0 0 0 0 0 0 0 0 0
39877- 0 0 0 0 0 0 0 0 0 0 0 0
39878- 0 0 0 0 0 0 0 0 0 0 0 0
39879- 0 0 1 0 0 0 0 0 0 0 0 0
39880- 0 0 0 0 0 0 0 0 0 0 0 0
39881- 0 0 0 0 0 0 0 0 0 0 0 0
39882- 0 0 0 0 0 0 0 0 0 0 0 0
39883- 0 0 0 0 0 0 0 0 0 0 0 0
39884- 0 0 0 0 0 0 0 0 0 10 10 10
39885- 38 38 38 86 86 86 14 14 14 2 2 6
39886- 2 2 6 2 2 6 2 2 6 2 2 6
39887- 2 2 6 2 2 6 2 2 6 2 2 6
39888- 2 2 6 2 2 6 2 2 6 2 2 6
39889- 2 2 6 2 2 6 2 2 6 2 2 6
39890- 2 2 6 2 2 6 2 2 6 54 54 54
39891- 66 66 66 26 26 26 6 6 6 0 0 0
39892- 0 0 0 0 0 0 0 0 0 0 0 0
39893- 0 0 0 0 0 0 0 0 0 0 0 0
39894- 0 0 0 0 0 0 0 0 0 0 0 0
39895- 0 0 0 0 0 0 0 0 0 0 0 0
39896- 0 0 0 0 0 0 0 0 0 0 0 0
39897- 0 0 0 0 0 0 0 0 0 0 0 0
39898- 0 0 0 0 0 0 0 0 0 0 0 0
39899- 0 0 0 0 0 1 0 0 1 0 0 0
39900- 0 0 0 0 0 0 0 0 0 0 0 0
39901- 0 0 0 0 0 0 0 0 0 0 0 0
39902- 0 0 0 0 0 0 0 0 0 0 0 0
39903- 0 0 0 0 0 0 0 0 0 0 0 0
39904- 0 0 0 0 0 0 0 0 0 14 14 14
39905- 42 42 42 82 82 82 2 2 6 2 2 6
39906- 2 2 6 6 6 6 10 10 10 2 2 6
39907- 2 2 6 2 2 6 2 2 6 2 2 6
39908- 2 2 6 2 2 6 2 2 6 6 6 6
39909- 14 14 14 10 10 10 2 2 6 2 2 6
39910- 2 2 6 2 2 6 2 2 6 18 18 18
39911- 82 82 82 34 34 34 10 10 10 0 0 0
39912- 0 0 0 0 0 0 0 0 0 0 0 0
39913- 0 0 0 0 0 0 0 0 0 0 0 0
39914- 0 0 0 0 0 0 0 0 0 0 0 0
39915- 0 0 0 0 0 0 0 0 0 0 0 0
39916- 0 0 0 0 0 0 0 0 0 0 0 0
39917- 0 0 0 0 0 0 0 0 0 0 0 0
39918- 0 0 0 0 0 0 0 0 0 0 0 0
39919- 0 0 1 0 0 0 0 0 0 0 0 0
39920- 0 0 0 0 0 0 0 0 0 0 0 0
39921- 0 0 0 0 0 0 0 0 0 0 0 0
39922- 0 0 0 0 0 0 0 0 0 0 0 0
39923- 0 0 0 0 0 0 0 0 0 0 0 0
39924- 0 0 0 0 0 0 0 0 0 14 14 14
39925- 46 46 46 86 86 86 2 2 6 2 2 6
39926- 6 6 6 6 6 6 22 22 22 34 34 34
39927- 6 6 6 2 2 6 2 2 6 2 2 6
39928- 2 2 6 2 2 6 18 18 18 34 34 34
39929- 10 10 10 50 50 50 22 22 22 2 2 6
39930- 2 2 6 2 2 6 2 2 6 10 10 10
39931- 86 86 86 42 42 42 14 14 14 0 0 0
39932- 0 0 0 0 0 0 0 0 0 0 0 0
39933- 0 0 0 0 0 0 0 0 0 0 0 0
39934- 0 0 0 0 0 0 0 0 0 0 0 0
39935- 0 0 0 0 0 0 0 0 0 0 0 0
39936- 0 0 0 0 0 0 0 0 0 0 0 0
39937- 0 0 0 0 0 0 0 0 0 0 0 0
39938- 0 0 0 0 0 0 0 0 0 0 0 0
39939- 0 0 1 0 0 1 0 0 1 0 0 0
39940- 0 0 0 0 0 0 0 0 0 0 0 0
39941- 0 0 0 0 0 0 0 0 0 0 0 0
39942- 0 0 0 0 0 0 0 0 0 0 0 0
39943- 0 0 0 0 0 0 0 0 0 0 0 0
39944- 0 0 0 0 0 0 0 0 0 14 14 14
39945- 46 46 46 86 86 86 2 2 6 2 2 6
39946- 38 38 38 116 116 116 94 94 94 22 22 22
39947- 22 22 22 2 2 6 2 2 6 2 2 6
39948- 14 14 14 86 86 86 138 138 138 162 162 162
39949-154 154 154 38 38 38 26 26 26 6 6 6
39950- 2 2 6 2 2 6 2 2 6 2 2 6
39951- 86 86 86 46 46 46 14 14 14 0 0 0
39952- 0 0 0 0 0 0 0 0 0 0 0 0
39953- 0 0 0 0 0 0 0 0 0 0 0 0
39954- 0 0 0 0 0 0 0 0 0 0 0 0
39955- 0 0 0 0 0 0 0 0 0 0 0 0
39956- 0 0 0 0 0 0 0 0 0 0 0 0
39957- 0 0 0 0 0 0 0 0 0 0 0 0
39958- 0 0 0 0 0 0 0 0 0 0 0 0
39959- 0 0 0 0 0 0 0 0 0 0 0 0
39960- 0 0 0 0 0 0 0 0 0 0 0 0
39961- 0 0 0 0 0 0 0 0 0 0 0 0
39962- 0 0 0 0 0 0 0 0 0 0 0 0
39963- 0 0 0 0 0 0 0 0 0 0 0 0
39964- 0 0 0 0 0 0 0 0 0 14 14 14
39965- 46 46 46 86 86 86 2 2 6 14 14 14
39966-134 134 134 198 198 198 195 195 195 116 116 116
39967- 10 10 10 2 2 6 2 2 6 6 6 6
39968-101 98 89 187 187 187 210 210 210 218 218 218
39969-214 214 214 134 134 134 14 14 14 6 6 6
39970- 2 2 6 2 2 6 2 2 6 2 2 6
39971- 86 86 86 50 50 50 18 18 18 6 6 6
39972- 0 0 0 0 0 0 0 0 0 0 0 0
39973- 0 0 0 0 0 0 0 0 0 0 0 0
39974- 0 0 0 0 0 0 0 0 0 0 0 0
39975- 0 0 0 0 0 0 0 0 0 0 0 0
39976- 0 0 0 0 0 0 0 0 0 0 0 0
39977- 0 0 0 0 0 0 0 0 0 0 0 0
39978- 0 0 0 0 0 0 0 0 1 0 0 0
39979- 0 0 1 0 0 1 0 0 1 0 0 0
39980- 0 0 0 0 0 0 0 0 0 0 0 0
39981- 0 0 0 0 0 0 0 0 0 0 0 0
39982- 0 0 0 0 0 0 0 0 0 0 0 0
39983- 0 0 0 0 0 0 0 0 0 0 0 0
39984- 0 0 0 0 0 0 0 0 0 14 14 14
39985- 46 46 46 86 86 86 2 2 6 54 54 54
39986-218 218 218 195 195 195 226 226 226 246 246 246
39987- 58 58 58 2 2 6 2 2 6 30 30 30
39988-210 210 210 253 253 253 174 174 174 123 123 123
39989-221 221 221 234 234 234 74 74 74 2 2 6
39990- 2 2 6 2 2 6 2 2 6 2 2 6
39991- 70 70 70 58 58 58 22 22 22 6 6 6
39992- 0 0 0 0 0 0 0 0 0 0 0 0
39993- 0 0 0 0 0 0 0 0 0 0 0 0
39994- 0 0 0 0 0 0 0 0 0 0 0 0
39995- 0 0 0 0 0 0 0 0 0 0 0 0
39996- 0 0 0 0 0 0 0 0 0 0 0 0
39997- 0 0 0 0 0 0 0 0 0 0 0 0
39998- 0 0 0 0 0 0 0 0 0 0 0 0
39999- 0 0 0 0 0 0 0 0 0 0 0 0
40000- 0 0 0 0 0 0 0 0 0 0 0 0
40001- 0 0 0 0 0 0 0 0 0 0 0 0
40002- 0 0 0 0 0 0 0 0 0 0 0 0
40003- 0 0 0 0 0 0 0 0 0 0 0 0
40004- 0 0 0 0 0 0 0 0 0 14 14 14
40005- 46 46 46 82 82 82 2 2 6 106 106 106
40006-170 170 170 26 26 26 86 86 86 226 226 226
40007-123 123 123 10 10 10 14 14 14 46 46 46
40008-231 231 231 190 190 190 6 6 6 70 70 70
40009- 90 90 90 238 238 238 158 158 158 2 2 6
40010- 2 2 6 2 2 6 2 2 6 2 2 6
40011- 70 70 70 58 58 58 22 22 22 6 6 6
40012- 0 0 0 0 0 0 0 0 0 0 0 0
40013- 0 0 0 0 0 0 0 0 0 0 0 0
40014- 0 0 0 0 0 0 0 0 0 0 0 0
40015- 0 0 0 0 0 0 0 0 0 0 0 0
40016- 0 0 0 0 0 0 0 0 0 0 0 0
40017- 0 0 0 0 0 0 0 0 0 0 0 0
40018- 0 0 0 0 0 0 0 0 1 0 0 0
40019- 0 0 1 0 0 1 0 0 1 0 0 0
40020- 0 0 0 0 0 0 0 0 0 0 0 0
40021- 0 0 0 0 0 0 0 0 0 0 0 0
40022- 0 0 0 0 0 0 0 0 0 0 0 0
40023- 0 0 0 0 0 0 0 0 0 0 0 0
40024- 0 0 0 0 0 0 0 0 0 14 14 14
40025- 42 42 42 86 86 86 6 6 6 116 116 116
40026-106 106 106 6 6 6 70 70 70 149 149 149
40027-128 128 128 18 18 18 38 38 38 54 54 54
40028-221 221 221 106 106 106 2 2 6 14 14 14
40029- 46 46 46 190 190 190 198 198 198 2 2 6
40030- 2 2 6 2 2 6 2 2 6 2 2 6
40031- 74 74 74 62 62 62 22 22 22 6 6 6
40032- 0 0 0 0 0 0 0 0 0 0 0 0
40033- 0 0 0 0 0 0 0 0 0 0 0 0
40034- 0 0 0 0 0 0 0 0 0 0 0 0
40035- 0 0 0 0 0 0 0 0 0 0 0 0
40036- 0 0 0 0 0 0 0 0 0 0 0 0
40037- 0 0 0 0 0 0 0 0 0 0 0 0
40038- 0 0 0 0 0 0 0 0 1 0 0 0
40039- 0 0 1 0 0 0 0 0 1 0 0 0
40040- 0 0 0 0 0 0 0 0 0 0 0 0
40041- 0 0 0 0 0 0 0 0 0 0 0 0
40042- 0 0 0 0 0 0 0 0 0 0 0 0
40043- 0 0 0 0 0 0 0 0 0 0 0 0
40044- 0 0 0 0 0 0 0 0 0 14 14 14
40045- 42 42 42 94 94 94 14 14 14 101 101 101
40046-128 128 128 2 2 6 18 18 18 116 116 116
40047-118 98 46 121 92 8 121 92 8 98 78 10
40048-162 162 162 106 106 106 2 2 6 2 2 6
40049- 2 2 6 195 195 195 195 195 195 6 6 6
40050- 2 2 6 2 2 6 2 2 6 2 2 6
40051- 74 74 74 62 62 62 22 22 22 6 6 6
40052- 0 0 0 0 0 0 0 0 0 0 0 0
40053- 0 0 0 0 0 0 0 0 0 0 0 0
40054- 0 0 0 0 0 0 0 0 0 0 0 0
40055- 0 0 0 0 0 0 0 0 0 0 0 0
40056- 0 0 0 0 0 0 0 0 0 0 0 0
40057- 0 0 0 0 0 0 0 0 0 0 0 0
40058- 0 0 0 0 0 0 0 0 1 0 0 1
40059- 0 0 1 0 0 0 0 0 1 0 0 0
40060- 0 0 0 0 0 0 0 0 0 0 0 0
40061- 0 0 0 0 0 0 0 0 0 0 0 0
40062- 0 0 0 0 0 0 0 0 0 0 0 0
40063- 0 0 0 0 0 0 0 0 0 0 0 0
40064- 0 0 0 0 0 0 0 0 0 10 10 10
40065- 38 38 38 90 90 90 14 14 14 58 58 58
40066-210 210 210 26 26 26 54 38 6 154 114 10
40067-226 170 11 236 186 11 225 175 15 184 144 12
40068-215 174 15 175 146 61 37 26 9 2 2 6
40069- 70 70 70 246 246 246 138 138 138 2 2 6
40070- 2 2 6 2 2 6 2 2 6 2 2 6
40071- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0 0 0 0 0 0 0
40076- 0 0 0 0 0 0 0 0 0 0 0 0
40077- 0 0 0 0 0 0 0 0 0 0 0 0
40078- 0 0 0 0 0 0 0 0 0 0 0 0
40079- 0 0 0 0 0 0 0 0 0 0 0 0
40080- 0 0 0 0 0 0 0 0 0 0 0 0
40081- 0 0 0 0 0 0 0 0 0 0 0 0
40082- 0 0 0 0 0 0 0 0 0 0 0 0
40083- 0 0 0 0 0 0 0 0 0 0 0 0
40084- 0 0 0 0 0 0 0 0 0 10 10 10
40085- 38 38 38 86 86 86 14 14 14 10 10 10
40086-195 195 195 188 164 115 192 133 9 225 175 15
40087-239 182 13 234 190 10 232 195 16 232 200 30
40088-245 207 45 241 208 19 232 195 16 184 144 12
40089-218 194 134 211 206 186 42 42 42 2 2 6
40090- 2 2 6 2 2 6 2 2 6 2 2 6
40091- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0 0 0 0 0 0 0
40097- 0 0 0 0 0 0 0 0 0 0 0 0
40098- 0 0 0 0 0 0 0 0 0 0 0 0
40099- 0 0 0 0 0 0 0 0 0 0 0 0
40100- 0 0 0 0 0 0 0 0 0 0 0 0
40101- 0 0 0 0 0 0 0 0 0 0 0 0
40102- 0 0 0 0 0 0 0 0 0 0 0 0
40103- 0 0 0 0 0 0 0 0 0 0 0 0
40104- 0 0 0 0 0 0 0 0 0 10 10 10
40105- 34 34 34 86 86 86 14 14 14 2 2 6
40106-121 87 25 192 133 9 219 162 10 239 182 13
40107-236 186 11 232 195 16 241 208 19 244 214 54
40108-246 218 60 246 218 38 246 215 20 241 208 19
40109-241 208 19 226 184 13 121 87 25 2 2 6
40110- 2 2 6 2 2 6 2 2 6 2 2 6
40111- 50 50 50 82 82 82 34 34 34 10 10 10
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- 0 0 0 0 0 0 0 0 0 0 0 0
40118- 0 0 0 0 0 0 0 0 0 0 0 0
40119- 0 0 0 0 0 0 0 0 0 0 0 0
40120- 0 0 0 0 0 0 0 0 0 0 0 0
40121- 0 0 0 0 0 0 0 0 0 0 0 0
40122- 0 0 0 0 0 0 0 0 0 0 0 0
40123- 0 0 0 0 0 0 0 0 0 0 0 0
40124- 0 0 0 0 0 0 0 0 0 10 10 10
40125- 34 34 34 82 82 82 30 30 30 61 42 6
40126-180 123 7 206 145 10 230 174 11 239 182 13
40127-234 190 10 238 202 15 241 208 19 246 218 74
40128-246 218 38 246 215 20 246 215 20 246 215 20
40129-226 184 13 215 174 15 184 144 12 6 6 6
40130- 2 2 6 2 2 6 2 2 6 2 2 6
40131- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
40138- 0 0 0 0 0 0 0 0 0 0 0 0
40139- 0 0 0 0 0 0 0 0 0 0 0 0
40140- 0 0 0 0 0 0 0 0 0 0 0 0
40141- 0 0 0 0 0 0 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 10 10 10
40145- 30 30 30 78 78 78 50 50 50 104 69 6
40146-192 133 9 216 158 10 236 178 12 236 186 11
40147-232 195 16 241 208 19 244 214 54 245 215 43
40148-246 215 20 246 215 20 241 208 19 198 155 10
40149-200 144 11 216 158 10 156 118 10 2 2 6
40150- 2 2 6 2 2 6 2 2 6 2 2 6
40151- 6 6 6 90 90 90 54 54 54 18 18 18
40152- 6 6 6 0 0 0 0 0 0 0 0 0
40153- 0 0 0 0 0 0 0 0 0 0 0 0
40154- 0 0 0 0 0 0 0 0 0 0 0 0
40155- 0 0 0 0 0 0 0 0 0 0 0 0
40156- 0 0 0 0 0 0 0 0 0 0 0 0
40157- 0 0 0 0 0 0 0 0 0 0 0 0
40158- 0 0 0 0 0 0 0 0 0 0 0 0
40159- 0 0 0 0 0 0 0 0 0 0 0 0
40160- 0 0 0 0 0 0 0 0 0 0 0 0
40161- 0 0 0 0 0 0 0 0 0 0 0 0
40162- 0 0 0 0 0 0 0 0 0 0 0 0
40163- 0 0 0 0 0 0 0 0 0 0 0 0
40164- 0 0 0 0 0 0 0 0 0 10 10 10
40165- 30 30 30 78 78 78 46 46 46 22 22 22
40166-137 92 6 210 162 10 239 182 13 238 190 10
40167-238 202 15 241 208 19 246 215 20 246 215 20
40168-241 208 19 203 166 17 185 133 11 210 150 10
40169-216 158 10 210 150 10 102 78 10 2 2 6
40170- 6 6 6 54 54 54 14 14 14 2 2 6
40171- 2 2 6 62 62 62 74 74 74 30 30 30
40172- 10 10 10 0 0 0 0 0 0 0 0 0
40173- 0 0 0 0 0 0 0 0 0 0 0 0
40174- 0 0 0 0 0 0 0 0 0 0 0 0
40175- 0 0 0 0 0 0 0 0 0 0 0 0
40176- 0 0 0 0 0 0 0 0 0 0 0 0
40177- 0 0 0 0 0 0 0 0 0 0 0 0
40178- 0 0 0 0 0 0 0 0 0 0 0 0
40179- 0 0 0 0 0 0 0 0 0 0 0 0
40180- 0 0 0 0 0 0 0 0 0 0 0 0
40181- 0 0 0 0 0 0 0 0 0 0 0 0
40182- 0 0 0 0 0 0 0 0 0 0 0 0
40183- 0 0 0 0 0 0 0 0 0 0 0 0
40184- 0 0 0 0 0 0 0 0 0 10 10 10
40185- 34 34 34 78 78 78 50 50 50 6 6 6
40186- 94 70 30 139 102 15 190 146 13 226 184 13
40187-232 200 30 232 195 16 215 174 15 190 146 13
40188-168 122 10 192 133 9 210 150 10 213 154 11
40189-202 150 34 182 157 106 101 98 89 2 2 6
40190- 2 2 6 78 78 78 116 116 116 58 58 58
40191- 2 2 6 22 22 22 90 90 90 46 46 46
40192- 18 18 18 6 6 6 0 0 0 0 0 0
40193- 0 0 0 0 0 0 0 0 0 0 0 0
40194- 0 0 0 0 0 0 0 0 0 0 0 0
40195- 0 0 0 0 0 0 0 0 0 0 0 0
40196- 0 0 0 0 0 0 0 0 0 0 0 0
40197- 0 0 0 0 0 0 0 0 0 0 0 0
40198- 0 0 0 0 0 0 0 0 0 0 0 0
40199- 0 0 0 0 0 0 0 0 0 0 0 0
40200- 0 0 0 0 0 0 0 0 0 0 0 0
40201- 0 0 0 0 0 0 0 0 0 0 0 0
40202- 0 0 0 0 0 0 0 0 0 0 0 0
40203- 0 0 0 0 0 0 0 0 0 0 0 0
40204- 0 0 0 0 0 0 0 0 0 10 10 10
40205- 38 38 38 86 86 86 50 50 50 6 6 6
40206-128 128 128 174 154 114 156 107 11 168 122 10
40207-198 155 10 184 144 12 197 138 11 200 144 11
40208-206 145 10 206 145 10 197 138 11 188 164 115
40209-195 195 195 198 198 198 174 174 174 14 14 14
40210- 2 2 6 22 22 22 116 116 116 116 116 116
40211- 22 22 22 2 2 6 74 74 74 70 70 70
40212- 30 30 30 10 10 10 0 0 0 0 0 0
40213- 0 0 0 0 0 0 0 0 0 0 0 0
40214- 0 0 0 0 0 0 0 0 0 0 0 0
40215- 0 0 0 0 0 0 0 0 0 0 0 0
40216- 0 0 0 0 0 0 0 0 0 0 0 0
40217- 0 0 0 0 0 0 0 0 0 0 0 0
40218- 0 0 0 0 0 0 0 0 0 0 0 0
40219- 0 0 0 0 0 0 0 0 0 0 0 0
40220- 0 0 0 0 0 0 0 0 0 0 0 0
40221- 0 0 0 0 0 0 0 0 0 0 0 0
40222- 0 0 0 0 0 0 0 0 0 0 0 0
40223- 0 0 0 0 0 0 0 0 0 0 0 0
40224- 0 0 0 0 0 0 6 6 6 18 18 18
40225- 50 50 50 101 101 101 26 26 26 10 10 10
40226-138 138 138 190 190 190 174 154 114 156 107 11
40227-197 138 11 200 144 11 197 138 11 192 133 9
40228-180 123 7 190 142 34 190 178 144 187 187 187
40229-202 202 202 221 221 221 214 214 214 66 66 66
40230- 2 2 6 2 2 6 50 50 50 62 62 62
40231- 6 6 6 2 2 6 10 10 10 90 90 90
40232- 50 50 50 18 18 18 6 6 6 0 0 0
40233- 0 0 0 0 0 0 0 0 0 0 0 0
40234- 0 0 0 0 0 0 0 0 0 0 0 0
40235- 0 0 0 0 0 0 0 0 0 0 0 0
40236- 0 0 0 0 0 0 0 0 0 0 0 0
40237- 0 0 0 0 0 0 0 0 0 0 0 0
40238- 0 0 0 0 0 0 0 0 0 0 0 0
40239- 0 0 0 0 0 0 0 0 0 0 0 0
40240- 0 0 0 0 0 0 0 0 0 0 0 0
40241- 0 0 0 0 0 0 0 0 0 0 0 0
40242- 0 0 0 0 0 0 0 0 0 0 0 0
40243- 0 0 0 0 0 0 0 0 0 0 0 0
40244- 0 0 0 0 0 0 10 10 10 34 34 34
40245- 74 74 74 74 74 74 2 2 6 6 6 6
40246-144 144 144 198 198 198 190 190 190 178 166 146
40247-154 121 60 156 107 11 156 107 11 168 124 44
40248-174 154 114 187 187 187 190 190 190 210 210 210
40249-246 246 246 253 253 253 253 253 253 182 182 182
40250- 6 6 6 2 2 6 2 2 6 2 2 6
40251- 2 2 6 2 2 6 2 2 6 62 62 62
40252- 74 74 74 34 34 34 14 14 14 0 0 0
40253- 0 0 0 0 0 0 0 0 0 0 0 0
40254- 0 0 0 0 0 0 0 0 0 0 0 0
40255- 0 0 0 0 0 0 0 0 0 0 0 0
40256- 0 0 0 0 0 0 0 0 0 0 0 0
40257- 0 0 0 0 0 0 0 0 0 0 0 0
40258- 0 0 0 0 0 0 0 0 0 0 0 0
40259- 0 0 0 0 0 0 0 0 0 0 0 0
40260- 0 0 0 0 0 0 0 0 0 0 0 0
40261- 0 0 0 0 0 0 0 0 0 0 0 0
40262- 0 0 0 0 0 0 0 0 0 0 0 0
40263- 0 0 0 0 0 0 0 0 0 0 0 0
40264- 0 0 0 10 10 10 22 22 22 54 54 54
40265- 94 94 94 18 18 18 2 2 6 46 46 46
40266-234 234 234 221 221 221 190 190 190 190 190 190
40267-190 190 190 187 187 187 187 187 187 190 190 190
40268-190 190 190 195 195 195 214 214 214 242 242 242
40269-253 253 253 253 253 253 253 253 253 253 253 253
40270- 82 82 82 2 2 6 2 2 6 2 2 6
40271- 2 2 6 2 2 6 2 2 6 14 14 14
40272- 86 86 86 54 54 54 22 22 22 6 6 6
40273- 0 0 0 0 0 0 0 0 0 0 0 0
40274- 0 0 0 0 0 0 0 0 0 0 0 0
40275- 0 0 0 0 0 0 0 0 0 0 0 0
40276- 0 0 0 0 0 0 0 0 0 0 0 0
40277- 0 0 0 0 0 0 0 0 0 0 0 0
40278- 0 0 0 0 0 0 0 0 0 0 0 0
40279- 0 0 0 0 0 0 0 0 0 0 0 0
40280- 0 0 0 0 0 0 0 0 0 0 0 0
40281- 0 0 0 0 0 0 0 0 0 0 0 0
40282- 0 0 0 0 0 0 0 0 0 0 0 0
40283- 0 0 0 0 0 0 0 0 0 0 0 0
40284- 6 6 6 18 18 18 46 46 46 90 90 90
40285- 46 46 46 18 18 18 6 6 6 182 182 182
40286-253 253 253 246 246 246 206 206 206 190 190 190
40287-190 190 190 190 190 190 190 190 190 190 190 190
40288-206 206 206 231 231 231 250 250 250 253 253 253
40289-253 253 253 253 253 253 253 253 253 253 253 253
40290-202 202 202 14 14 14 2 2 6 2 2 6
40291- 2 2 6 2 2 6 2 2 6 2 2 6
40292- 42 42 42 86 86 86 42 42 42 18 18 18
40293- 6 6 6 0 0 0 0 0 0 0 0 0
40294- 0 0 0 0 0 0 0 0 0 0 0 0
40295- 0 0 0 0 0 0 0 0 0 0 0 0
40296- 0 0 0 0 0 0 0 0 0 0 0 0
40297- 0 0 0 0 0 0 0 0 0 0 0 0
40298- 0 0 0 0 0 0 0 0 0 0 0 0
40299- 0 0 0 0 0 0 0 0 0 0 0 0
40300- 0 0 0 0 0 0 0 0 0 0 0 0
40301- 0 0 0 0 0 0 0 0 0 0 0 0
40302- 0 0 0 0 0 0 0 0 0 0 0 0
40303- 0 0 0 0 0 0 0 0 0 6 6 6
40304- 14 14 14 38 38 38 74 74 74 66 66 66
40305- 2 2 6 6 6 6 90 90 90 250 250 250
40306-253 253 253 253 253 253 238 238 238 198 198 198
40307-190 190 190 190 190 190 195 195 195 221 221 221
40308-246 246 246 253 253 253 253 253 253 253 253 253
40309-253 253 253 253 253 253 253 253 253 253 253 253
40310-253 253 253 82 82 82 2 2 6 2 2 6
40311- 2 2 6 2 2 6 2 2 6 2 2 6
40312- 2 2 6 78 78 78 70 70 70 34 34 34
40313- 14 14 14 6 6 6 0 0 0 0 0 0
40314- 0 0 0 0 0 0 0 0 0 0 0 0
40315- 0 0 0 0 0 0 0 0 0 0 0 0
40316- 0 0 0 0 0 0 0 0 0 0 0 0
40317- 0 0 0 0 0 0 0 0 0 0 0 0
40318- 0 0 0 0 0 0 0 0 0 0 0 0
40319- 0 0 0 0 0 0 0 0 0 0 0 0
40320- 0 0 0 0 0 0 0 0 0 0 0 0
40321- 0 0 0 0 0 0 0 0 0 0 0 0
40322- 0 0 0 0 0 0 0 0 0 0 0 0
40323- 0 0 0 0 0 0 0 0 0 14 14 14
40324- 34 34 34 66 66 66 78 78 78 6 6 6
40325- 2 2 6 18 18 18 218 218 218 253 253 253
40326-253 253 253 253 253 253 253 253 253 246 246 246
40327-226 226 226 231 231 231 246 246 246 253 253 253
40328-253 253 253 253 253 253 253 253 253 253 253 253
40329-253 253 253 253 253 253 253 253 253 253 253 253
40330-253 253 253 178 178 178 2 2 6 2 2 6
40331- 2 2 6 2 2 6 2 2 6 2 2 6
40332- 2 2 6 18 18 18 90 90 90 62 62 62
40333- 30 30 30 10 10 10 0 0 0 0 0 0
40334- 0 0 0 0 0 0 0 0 0 0 0 0
40335- 0 0 0 0 0 0 0 0 0 0 0 0
40336- 0 0 0 0 0 0 0 0 0 0 0 0
40337- 0 0 0 0 0 0 0 0 0 0 0 0
40338- 0 0 0 0 0 0 0 0 0 0 0 0
40339- 0 0 0 0 0 0 0 0 0 0 0 0
40340- 0 0 0 0 0 0 0 0 0 0 0 0
40341- 0 0 0 0 0 0 0 0 0 0 0 0
40342- 0 0 0 0 0 0 0 0 0 0 0 0
40343- 0 0 0 0 0 0 10 10 10 26 26 26
40344- 58 58 58 90 90 90 18 18 18 2 2 6
40345- 2 2 6 110 110 110 253 253 253 253 253 253
40346-253 253 253 253 253 253 253 253 253 253 253 253
40347-250 250 250 253 253 253 253 253 253 253 253 253
40348-253 253 253 253 253 253 253 253 253 253 253 253
40349-253 253 253 253 253 253 253 253 253 253 253 253
40350-253 253 253 231 231 231 18 18 18 2 2 6
40351- 2 2 6 2 2 6 2 2 6 2 2 6
40352- 2 2 6 2 2 6 18 18 18 94 94 94
40353- 54 54 54 26 26 26 10 10 10 0 0 0
40354- 0 0 0 0 0 0 0 0 0 0 0 0
40355- 0 0 0 0 0 0 0 0 0 0 0 0
40356- 0 0 0 0 0 0 0 0 0 0 0 0
40357- 0 0 0 0 0 0 0 0 0 0 0 0
40358- 0 0 0 0 0 0 0 0 0 0 0 0
40359- 0 0 0 0 0 0 0 0 0 0 0 0
40360- 0 0 0 0 0 0 0 0 0 0 0 0
40361- 0 0 0 0 0 0 0 0 0 0 0 0
40362- 0 0 0 0 0 0 0 0 0 0 0 0
40363- 0 0 0 6 6 6 22 22 22 50 50 50
40364- 90 90 90 26 26 26 2 2 6 2 2 6
40365- 14 14 14 195 195 195 250 250 250 253 253 253
40366-253 253 253 253 253 253 253 253 253 253 253 253
40367-253 253 253 253 253 253 253 253 253 253 253 253
40368-253 253 253 253 253 253 253 253 253 253 253 253
40369-253 253 253 253 253 253 253 253 253 253 253 253
40370-250 250 250 242 242 242 54 54 54 2 2 6
40371- 2 2 6 2 2 6 2 2 6 2 2 6
40372- 2 2 6 2 2 6 2 2 6 38 38 38
40373- 86 86 86 50 50 50 22 22 22 6 6 6
40374- 0 0 0 0 0 0 0 0 0 0 0 0
40375- 0 0 0 0 0 0 0 0 0 0 0 0
40376- 0 0 0 0 0 0 0 0 0 0 0 0
40377- 0 0 0 0 0 0 0 0 0 0 0 0
40378- 0 0 0 0 0 0 0 0 0 0 0 0
40379- 0 0 0 0 0 0 0 0 0 0 0 0
40380- 0 0 0 0 0 0 0 0 0 0 0 0
40381- 0 0 0 0 0 0 0 0 0 0 0 0
40382- 0 0 0 0 0 0 0 0 0 0 0 0
40383- 6 6 6 14 14 14 38 38 38 82 82 82
40384- 34 34 34 2 2 6 2 2 6 2 2 6
40385- 42 42 42 195 195 195 246 246 246 253 253 253
40386-253 253 253 253 253 253 253 253 253 250 250 250
40387-242 242 242 242 242 242 250 250 250 253 253 253
40388-253 253 253 253 253 253 253 253 253 253 253 253
40389-253 253 253 250 250 250 246 246 246 238 238 238
40390-226 226 226 231 231 231 101 101 101 6 6 6
40391- 2 2 6 2 2 6 2 2 6 2 2 6
40392- 2 2 6 2 2 6 2 2 6 2 2 6
40393- 38 38 38 82 82 82 42 42 42 14 14 14
40394- 6 6 6 0 0 0 0 0 0 0 0 0
40395- 0 0 0 0 0 0 0 0 0 0 0 0
40396- 0 0 0 0 0 0 0 0 0 0 0 0
40397- 0 0 0 0 0 0 0 0 0 0 0 0
40398- 0 0 0 0 0 0 0 0 0 0 0 0
40399- 0 0 0 0 0 0 0 0 0 0 0 0
40400- 0 0 0 0 0 0 0 0 0 0 0 0
40401- 0 0 0 0 0 0 0 0 0 0 0 0
40402- 0 0 0 0 0 0 0 0 0 0 0 0
40403- 10 10 10 26 26 26 62 62 62 66 66 66
40404- 2 2 6 2 2 6 2 2 6 6 6 6
40405- 70 70 70 170 170 170 206 206 206 234 234 234
40406-246 246 246 250 250 250 250 250 250 238 238 238
40407-226 226 226 231 231 231 238 238 238 250 250 250
40408-250 250 250 250 250 250 246 246 246 231 231 231
40409-214 214 214 206 206 206 202 202 202 202 202 202
40410-198 198 198 202 202 202 182 182 182 18 18 18
40411- 2 2 6 2 2 6 2 2 6 2 2 6
40412- 2 2 6 2 2 6 2 2 6 2 2 6
40413- 2 2 6 62 62 62 66 66 66 30 30 30
40414- 10 10 10 0 0 0 0 0 0 0 0 0
40415- 0 0 0 0 0 0 0 0 0 0 0 0
40416- 0 0 0 0 0 0 0 0 0 0 0 0
40417- 0 0 0 0 0 0 0 0 0 0 0 0
40418- 0 0 0 0 0 0 0 0 0 0 0 0
40419- 0 0 0 0 0 0 0 0 0 0 0 0
40420- 0 0 0 0 0 0 0 0 0 0 0 0
40421- 0 0 0 0 0 0 0 0 0 0 0 0
40422- 0 0 0 0 0 0 0 0 0 0 0 0
40423- 14 14 14 42 42 42 82 82 82 18 18 18
40424- 2 2 6 2 2 6 2 2 6 10 10 10
40425- 94 94 94 182 182 182 218 218 218 242 242 242
40426-250 250 250 253 253 253 253 253 253 250 250 250
40427-234 234 234 253 253 253 253 253 253 253 253 253
40428-253 253 253 253 253 253 253 253 253 246 246 246
40429-238 238 238 226 226 226 210 210 210 202 202 202
40430-195 195 195 195 195 195 210 210 210 158 158 158
40431- 6 6 6 14 14 14 50 50 50 14 14 14
40432- 2 2 6 2 2 6 2 2 6 2 2 6
40433- 2 2 6 6 6 6 86 86 86 46 46 46
40434- 18 18 18 6 6 6 0 0 0 0 0 0
40435- 0 0 0 0 0 0 0 0 0 0 0 0
40436- 0 0 0 0 0 0 0 0 0 0 0 0
40437- 0 0 0 0 0 0 0 0 0 0 0 0
40438- 0 0 0 0 0 0 0 0 0 0 0 0
40439- 0 0 0 0 0 0 0 0 0 0 0 0
40440- 0 0 0 0 0 0 0 0 0 0 0 0
40441- 0 0 0 0 0 0 0 0 0 0 0 0
40442- 0 0 0 0 0 0 0 0 0 6 6 6
40443- 22 22 22 54 54 54 70 70 70 2 2 6
40444- 2 2 6 10 10 10 2 2 6 22 22 22
40445-166 166 166 231 231 231 250 250 250 253 253 253
40446-253 253 253 253 253 253 253 253 253 250 250 250
40447-242 242 242 253 253 253 253 253 253 253 253 253
40448-253 253 253 253 253 253 253 253 253 253 253 253
40449-253 253 253 253 253 253 253 253 253 246 246 246
40450-231 231 231 206 206 206 198 198 198 226 226 226
40451- 94 94 94 2 2 6 6 6 6 38 38 38
40452- 30 30 30 2 2 6 2 2 6 2 2 6
40453- 2 2 6 2 2 6 62 62 62 66 66 66
40454- 26 26 26 10 10 10 0 0 0 0 0 0
40455- 0 0 0 0 0 0 0 0 0 0 0 0
40456- 0 0 0 0 0 0 0 0 0 0 0 0
40457- 0 0 0 0 0 0 0 0 0 0 0 0
40458- 0 0 0 0 0 0 0 0 0 0 0 0
40459- 0 0 0 0 0 0 0 0 0 0 0 0
40460- 0 0 0 0 0 0 0 0 0 0 0 0
40461- 0 0 0 0 0 0 0 0 0 0 0 0
40462- 0 0 0 0 0 0 0 0 0 10 10 10
40463- 30 30 30 74 74 74 50 50 50 2 2 6
40464- 26 26 26 26 26 26 2 2 6 106 106 106
40465-238 238 238 253 253 253 253 253 253 253 253 253
40466-253 253 253 253 253 253 253 253 253 253 253 253
40467-253 253 253 253 253 253 253 253 253 253 253 253
40468-253 253 253 253 253 253 253 253 253 253 253 253
40469-253 253 253 253 253 253 253 253 253 253 253 253
40470-253 253 253 246 246 246 218 218 218 202 202 202
40471-210 210 210 14 14 14 2 2 6 2 2 6
40472- 30 30 30 22 22 22 2 2 6 2 2 6
40473- 2 2 6 2 2 6 18 18 18 86 86 86
40474- 42 42 42 14 14 14 0 0 0 0 0 0
40475- 0 0 0 0 0 0 0 0 0 0 0 0
40476- 0 0 0 0 0 0 0 0 0 0 0 0
40477- 0 0 0 0 0 0 0 0 0 0 0 0
40478- 0 0 0 0 0 0 0 0 0 0 0 0
40479- 0 0 0 0 0 0 0 0 0 0 0 0
40480- 0 0 0 0 0 0 0 0 0 0 0 0
40481- 0 0 0 0 0 0 0 0 0 0 0 0
40482- 0 0 0 0 0 0 0 0 0 14 14 14
40483- 42 42 42 90 90 90 22 22 22 2 2 6
40484- 42 42 42 2 2 6 18 18 18 218 218 218
40485-253 253 253 253 253 253 253 253 253 253 253 253
40486-253 253 253 253 253 253 253 253 253 253 253 253
40487-253 253 253 253 253 253 253 253 253 253 253 253
40488-253 253 253 253 253 253 253 253 253 253 253 253
40489-253 253 253 253 253 253 253 253 253 253 253 253
40490-253 253 253 253 253 253 250 250 250 221 221 221
40491-218 218 218 101 101 101 2 2 6 14 14 14
40492- 18 18 18 38 38 38 10 10 10 2 2 6
40493- 2 2 6 2 2 6 2 2 6 78 78 78
40494- 58 58 58 22 22 22 6 6 6 0 0 0
40495- 0 0 0 0 0 0 0 0 0 0 0 0
40496- 0 0 0 0 0 0 0 0 0 0 0 0
40497- 0 0 0 0 0 0 0 0 0 0 0 0
40498- 0 0 0 0 0 0 0 0 0 0 0 0
40499- 0 0 0 0 0 0 0 0 0 0 0 0
40500- 0 0 0 0 0 0 0 0 0 0 0 0
40501- 0 0 0 0 0 0 0 0 0 0 0 0
40502- 0 0 0 0 0 0 6 6 6 18 18 18
40503- 54 54 54 82 82 82 2 2 6 26 26 26
40504- 22 22 22 2 2 6 123 123 123 253 253 253
40505-253 253 253 253 253 253 253 253 253 253 253 253
40506-253 253 253 253 253 253 253 253 253 253 253 253
40507-253 253 253 253 253 253 253 253 253 253 253 253
40508-253 253 253 253 253 253 253 253 253 253 253 253
40509-253 253 253 253 253 253 253 253 253 253 253 253
40510-253 253 253 253 253 253 253 253 253 250 250 250
40511-238 238 238 198 198 198 6 6 6 38 38 38
40512- 58 58 58 26 26 26 38 38 38 2 2 6
40513- 2 2 6 2 2 6 2 2 6 46 46 46
40514- 78 78 78 30 30 30 10 10 10 0 0 0
40515- 0 0 0 0 0 0 0 0 0 0 0 0
40516- 0 0 0 0 0 0 0 0 0 0 0 0
40517- 0 0 0 0 0 0 0 0 0 0 0 0
40518- 0 0 0 0 0 0 0 0 0 0 0 0
40519- 0 0 0 0 0 0 0 0 0 0 0 0
40520- 0 0 0 0 0 0 0 0 0 0 0 0
40521- 0 0 0 0 0 0 0 0 0 0 0 0
40522- 0 0 0 0 0 0 10 10 10 30 30 30
40523- 74 74 74 58 58 58 2 2 6 42 42 42
40524- 2 2 6 22 22 22 231 231 231 253 253 253
40525-253 253 253 253 253 253 253 253 253 253 253 253
40526-253 253 253 253 253 253 253 253 253 250 250 250
40527-253 253 253 253 253 253 253 253 253 253 253 253
40528-253 253 253 253 253 253 253 253 253 253 253 253
40529-253 253 253 253 253 253 253 253 253 253 253 253
40530-253 253 253 253 253 253 253 253 253 253 253 253
40531-253 253 253 246 246 246 46 46 46 38 38 38
40532- 42 42 42 14 14 14 38 38 38 14 14 14
40533- 2 2 6 2 2 6 2 2 6 6 6 6
40534- 86 86 86 46 46 46 14 14 14 0 0 0
40535- 0 0 0 0 0 0 0 0 0 0 0 0
40536- 0 0 0 0 0 0 0 0 0 0 0 0
40537- 0 0 0 0 0 0 0 0 0 0 0 0
40538- 0 0 0 0 0 0 0 0 0 0 0 0
40539- 0 0 0 0 0 0 0 0 0 0 0 0
40540- 0 0 0 0 0 0 0 0 0 0 0 0
40541- 0 0 0 0 0 0 0 0 0 0 0 0
40542- 0 0 0 6 6 6 14 14 14 42 42 42
40543- 90 90 90 18 18 18 18 18 18 26 26 26
40544- 2 2 6 116 116 116 253 253 253 253 253 253
40545-253 253 253 253 253 253 253 253 253 253 253 253
40546-253 253 253 253 253 253 250 250 250 238 238 238
40547-253 253 253 253 253 253 253 253 253 253 253 253
40548-253 253 253 253 253 253 253 253 253 253 253 253
40549-253 253 253 253 253 253 253 253 253 253 253 253
40550-253 253 253 253 253 253 253 253 253 253 253 253
40551-253 253 253 253 253 253 94 94 94 6 6 6
40552- 2 2 6 2 2 6 10 10 10 34 34 34
40553- 2 2 6 2 2 6 2 2 6 2 2 6
40554- 74 74 74 58 58 58 22 22 22 6 6 6
40555- 0 0 0 0 0 0 0 0 0 0 0 0
40556- 0 0 0 0 0 0 0 0 0 0 0 0
40557- 0 0 0 0 0 0 0 0 0 0 0 0
40558- 0 0 0 0 0 0 0 0 0 0 0 0
40559- 0 0 0 0 0 0 0 0 0 0 0 0
40560- 0 0 0 0 0 0 0 0 0 0 0 0
40561- 0 0 0 0 0 0 0 0 0 0 0 0
40562- 0 0 0 10 10 10 26 26 26 66 66 66
40563- 82 82 82 2 2 6 38 38 38 6 6 6
40564- 14 14 14 210 210 210 253 253 253 253 253 253
40565-253 253 253 253 253 253 253 253 253 253 253 253
40566-253 253 253 253 253 253 246 246 246 242 242 242
40567-253 253 253 253 253 253 253 253 253 253 253 253
40568-253 253 253 253 253 253 253 253 253 253 253 253
40569-253 253 253 253 253 253 253 253 253 253 253 253
40570-253 253 253 253 253 253 253 253 253 253 253 253
40571-253 253 253 253 253 253 144 144 144 2 2 6
40572- 2 2 6 2 2 6 2 2 6 46 46 46
40573- 2 2 6 2 2 6 2 2 6 2 2 6
40574- 42 42 42 74 74 74 30 30 30 10 10 10
40575- 0 0 0 0 0 0 0 0 0 0 0 0
40576- 0 0 0 0 0 0 0 0 0 0 0 0
40577- 0 0 0 0 0 0 0 0 0 0 0 0
40578- 0 0 0 0 0 0 0 0 0 0 0 0
40579- 0 0 0 0 0 0 0 0 0 0 0 0
40580- 0 0 0 0 0 0 0 0 0 0 0 0
40581- 0 0 0 0 0 0 0 0 0 0 0 0
40582- 6 6 6 14 14 14 42 42 42 90 90 90
40583- 26 26 26 6 6 6 42 42 42 2 2 6
40584- 74 74 74 250 250 250 253 253 253 253 253 253
40585-253 253 253 253 253 253 253 253 253 253 253 253
40586-253 253 253 253 253 253 242 242 242 242 242 242
40587-253 253 253 253 253 253 253 253 253 253 253 253
40588-253 253 253 253 253 253 253 253 253 253 253 253
40589-253 253 253 253 253 253 253 253 253 253 253 253
40590-253 253 253 253 253 253 253 253 253 253 253 253
40591-253 253 253 253 253 253 182 182 182 2 2 6
40592- 2 2 6 2 2 6 2 2 6 46 46 46
40593- 2 2 6 2 2 6 2 2 6 2 2 6
40594- 10 10 10 86 86 86 38 38 38 10 10 10
40595- 0 0 0 0 0 0 0 0 0 0 0 0
40596- 0 0 0 0 0 0 0 0 0 0 0 0
40597- 0 0 0 0 0 0 0 0 0 0 0 0
40598- 0 0 0 0 0 0 0 0 0 0 0 0
40599- 0 0 0 0 0 0 0 0 0 0 0 0
40600- 0 0 0 0 0 0 0 0 0 0 0 0
40601- 0 0 0 0 0 0 0 0 0 0 0 0
40602- 10 10 10 26 26 26 66 66 66 82 82 82
40603- 2 2 6 22 22 22 18 18 18 2 2 6
40604-149 149 149 253 253 253 253 253 253 253 253 253
40605-253 253 253 253 253 253 253 253 253 253 253 253
40606-253 253 253 253 253 253 234 234 234 242 242 242
40607-253 253 253 253 253 253 253 253 253 253 253 253
40608-253 253 253 253 253 253 253 253 253 253 253 253
40609-253 253 253 253 253 253 253 253 253 253 253 253
40610-253 253 253 253 253 253 253 253 253 253 253 253
40611-253 253 253 253 253 253 206 206 206 2 2 6
40612- 2 2 6 2 2 6 2 2 6 38 38 38
40613- 2 2 6 2 2 6 2 2 6 2 2 6
40614- 6 6 6 86 86 86 46 46 46 14 14 14
40615- 0 0 0 0 0 0 0 0 0 0 0 0
40616- 0 0 0 0 0 0 0 0 0 0 0 0
40617- 0 0 0 0 0 0 0 0 0 0 0 0
40618- 0 0 0 0 0 0 0 0 0 0 0 0
40619- 0 0 0 0 0 0 0 0 0 0 0 0
40620- 0 0 0 0 0 0 0 0 0 0 0 0
40621- 0 0 0 0 0 0 0 0 0 6 6 6
40622- 18 18 18 46 46 46 86 86 86 18 18 18
40623- 2 2 6 34 34 34 10 10 10 6 6 6
40624-210 210 210 253 253 253 253 253 253 253 253 253
40625-253 253 253 253 253 253 253 253 253 253 253 253
40626-253 253 253 253 253 253 234 234 234 242 242 242
40627-253 253 253 253 253 253 253 253 253 253 253 253
40628-253 253 253 253 253 253 253 253 253 253 253 253
40629-253 253 253 253 253 253 253 253 253 253 253 253
40630-253 253 253 253 253 253 253 253 253 253 253 253
40631-253 253 253 253 253 253 221 221 221 6 6 6
40632- 2 2 6 2 2 6 6 6 6 30 30 30
40633- 2 2 6 2 2 6 2 2 6 2 2 6
40634- 2 2 6 82 82 82 54 54 54 18 18 18
40635- 6 6 6 0 0 0 0 0 0 0 0 0
40636- 0 0 0 0 0 0 0 0 0 0 0 0
40637- 0 0 0 0 0 0 0 0 0 0 0 0
40638- 0 0 0 0 0 0 0 0 0 0 0 0
40639- 0 0 0 0 0 0 0 0 0 0 0 0
40640- 0 0 0 0 0 0 0 0 0 0 0 0
40641- 0 0 0 0 0 0 0 0 0 10 10 10
40642- 26 26 26 66 66 66 62 62 62 2 2 6
40643- 2 2 6 38 38 38 10 10 10 26 26 26
40644-238 238 238 253 253 253 253 253 253 253 253 253
40645-253 253 253 253 253 253 253 253 253 253 253 253
40646-253 253 253 253 253 253 231 231 231 238 238 238
40647-253 253 253 253 253 253 253 253 253 253 253 253
40648-253 253 253 253 253 253 253 253 253 253 253 253
40649-253 253 253 253 253 253 253 253 253 253 253 253
40650-253 253 253 253 253 253 253 253 253 253 253 253
40651-253 253 253 253 253 253 231 231 231 6 6 6
40652- 2 2 6 2 2 6 10 10 10 30 30 30
40653- 2 2 6 2 2 6 2 2 6 2 2 6
40654- 2 2 6 66 66 66 58 58 58 22 22 22
40655- 6 6 6 0 0 0 0 0 0 0 0 0
40656- 0 0 0 0 0 0 0 0 0 0 0 0
40657- 0 0 0 0 0 0 0 0 0 0 0 0
40658- 0 0 0 0 0 0 0 0 0 0 0 0
40659- 0 0 0 0 0 0 0 0 0 0 0 0
40660- 0 0 0 0 0 0 0 0 0 0 0 0
40661- 0 0 0 0 0 0 0 0 0 10 10 10
40662- 38 38 38 78 78 78 6 6 6 2 2 6
40663- 2 2 6 46 46 46 14 14 14 42 42 42
40664-246 246 246 253 253 253 253 253 253 253 253 253
40665-253 253 253 253 253 253 253 253 253 253 253 253
40666-253 253 253 253 253 253 231 231 231 242 242 242
40667-253 253 253 253 253 253 253 253 253 253 253 253
40668-253 253 253 253 253 253 253 253 253 253 253 253
40669-253 253 253 253 253 253 253 253 253 253 253 253
40670-253 253 253 253 253 253 253 253 253 253 253 253
40671-253 253 253 253 253 253 234 234 234 10 10 10
40672- 2 2 6 2 2 6 22 22 22 14 14 14
40673- 2 2 6 2 2 6 2 2 6 2 2 6
40674- 2 2 6 66 66 66 62 62 62 22 22 22
40675- 6 6 6 0 0 0 0 0 0 0 0 0
40676- 0 0 0 0 0 0 0 0 0 0 0 0
40677- 0 0 0 0 0 0 0 0 0 0 0 0
40678- 0 0 0 0 0 0 0 0 0 0 0 0
40679- 0 0 0 0 0 0 0 0 0 0 0 0
40680- 0 0 0 0 0 0 0 0 0 0 0 0
40681- 0 0 0 0 0 0 6 6 6 18 18 18
40682- 50 50 50 74 74 74 2 2 6 2 2 6
40683- 14 14 14 70 70 70 34 34 34 62 62 62
40684-250 250 250 253 253 253 253 253 253 253 253 253
40685-253 253 253 253 253 253 253 253 253 253 253 253
40686-253 253 253 253 253 253 231 231 231 246 246 246
40687-253 253 253 253 253 253 253 253 253 253 253 253
40688-253 253 253 253 253 253 253 253 253 253 253 253
40689-253 253 253 253 253 253 253 253 253 253 253 253
40690-253 253 253 253 253 253 253 253 253 253 253 253
40691-253 253 253 253 253 253 234 234 234 14 14 14
40692- 2 2 6 2 2 6 30 30 30 2 2 6
40693- 2 2 6 2 2 6 2 2 6 2 2 6
40694- 2 2 6 66 66 66 62 62 62 22 22 22
40695- 6 6 6 0 0 0 0 0 0 0 0 0
40696- 0 0 0 0 0 0 0 0 0 0 0 0
40697- 0 0 0 0 0 0 0 0 0 0 0 0
40698- 0 0 0 0 0 0 0 0 0 0 0 0
40699- 0 0 0 0 0 0 0 0 0 0 0 0
40700- 0 0 0 0 0 0 0 0 0 0 0 0
40701- 0 0 0 0 0 0 6 6 6 18 18 18
40702- 54 54 54 62 62 62 2 2 6 2 2 6
40703- 2 2 6 30 30 30 46 46 46 70 70 70
40704-250 250 250 253 253 253 253 253 253 253 253 253
40705-253 253 253 253 253 253 253 253 253 253 253 253
40706-253 253 253 253 253 253 231 231 231 246 246 246
40707-253 253 253 253 253 253 253 253 253 253 253 253
40708-253 253 253 253 253 253 253 253 253 253 253 253
40709-253 253 253 253 253 253 253 253 253 253 253 253
40710-253 253 253 253 253 253 253 253 253 253 253 253
40711-253 253 253 253 253 253 226 226 226 10 10 10
40712- 2 2 6 6 6 6 30 30 30 2 2 6
40713- 2 2 6 2 2 6 2 2 6 2 2 6
40714- 2 2 6 66 66 66 58 58 58 22 22 22
40715- 6 6 6 0 0 0 0 0 0 0 0 0
40716- 0 0 0 0 0 0 0 0 0 0 0 0
40717- 0 0 0 0 0 0 0 0 0 0 0 0
40718- 0 0 0 0 0 0 0 0 0 0 0 0
40719- 0 0 0 0 0 0 0 0 0 0 0 0
40720- 0 0 0 0 0 0 0 0 0 0 0 0
40721- 0 0 0 0 0 0 6 6 6 22 22 22
40722- 58 58 58 62 62 62 2 2 6 2 2 6
40723- 2 2 6 2 2 6 30 30 30 78 78 78
40724-250 250 250 253 253 253 253 253 253 253 253 253
40725-253 253 253 253 253 253 253 253 253 253 253 253
40726-253 253 253 253 253 253 231 231 231 246 246 246
40727-253 253 253 253 253 253 253 253 253 253 253 253
40728-253 253 253 253 253 253 253 253 253 253 253 253
40729-253 253 253 253 253 253 253 253 253 253 253 253
40730-253 253 253 253 253 253 253 253 253 253 253 253
40731-253 253 253 253 253 253 206 206 206 2 2 6
40732- 22 22 22 34 34 34 18 14 6 22 22 22
40733- 26 26 26 18 18 18 6 6 6 2 2 6
40734- 2 2 6 82 82 82 54 54 54 18 18 18
40735- 6 6 6 0 0 0 0 0 0 0 0 0
40736- 0 0 0 0 0 0 0 0 0 0 0 0
40737- 0 0 0 0 0 0 0 0 0 0 0 0
40738- 0 0 0 0 0 0 0 0 0 0 0 0
40739- 0 0 0 0 0 0 0 0 0 0 0 0
40740- 0 0 0 0 0 0 0 0 0 0 0 0
40741- 0 0 0 0 0 0 6 6 6 26 26 26
40742- 62 62 62 106 106 106 74 54 14 185 133 11
40743-210 162 10 121 92 8 6 6 6 62 62 62
40744-238 238 238 253 253 253 253 253 253 253 253 253
40745-253 253 253 253 253 253 253 253 253 253 253 253
40746-253 253 253 253 253 253 231 231 231 246 246 246
40747-253 253 253 253 253 253 253 253 253 253 253 253
40748-253 253 253 253 253 253 253 253 253 253 253 253
40749-253 253 253 253 253 253 253 253 253 253 253 253
40750-253 253 253 253 253 253 253 253 253 253 253 253
40751-253 253 253 253 253 253 158 158 158 18 18 18
40752- 14 14 14 2 2 6 2 2 6 2 2 6
40753- 6 6 6 18 18 18 66 66 66 38 38 38
40754- 6 6 6 94 94 94 50 50 50 18 18 18
40755- 6 6 6 0 0 0 0 0 0 0 0 0
40756- 0 0 0 0 0 0 0 0 0 0 0 0
40757- 0 0 0 0 0 0 0 0 0 0 0 0
40758- 0 0 0 0 0 0 0 0 0 0 0 0
40759- 0 0 0 0 0 0 0 0 0 0 0 0
40760- 0 0 0 0 0 0 0 0 0 6 6 6
40761- 10 10 10 10 10 10 18 18 18 38 38 38
40762- 78 78 78 142 134 106 216 158 10 242 186 14
40763-246 190 14 246 190 14 156 118 10 10 10 10
40764- 90 90 90 238 238 238 253 253 253 253 253 253
40765-253 253 253 253 253 253 253 253 253 253 253 253
40766-253 253 253 253 253 253 231 231 231 250 250 250
40767-253 253 253 253 253 253 253 253 253 253 253 253
40768-253 253 253 253 253 253 253 253 253 253 253 253
40769-253 253 253 253 253 253 253 253 253 253 253 253
40770-253 253 253 253 253 253 253 253 253 246 230 190
40771-238 204 91 238 204 91 181 142 44 37 26 9
40772- 2 2 6 2 2 6 2 2 6 2 2 6
40773- 2 2 6 2 2 6 38 38 38 46 46 46
40774- 26 26 26 106 106 106 54 54 54 18 18 18
40775- 6 6 6 0 0 0 0 0 0 0 0 0
40776- 0 0 0 0 0 0 0 0 0 0 0 0
40777- 0 0 0 0 0 0 0 0 0 0 0 0
40778- 0 0 0 0 0 0 0 0 0 0 0 0
40779- 0 0 0 0 0 0 0 0 0 0 0 0
40780- 0 0 0 6 6 6 14 14 14 22 22 22
40781- 30 30 30 38 38 38 50 50 50 70 70 70
40782-106 106 106 190 142 34 226 170 11 242 186 14
40783-246 190 14 246 190 14 246 190 14 154 114 10
40784- 6 6 6 74 74 74 226 226 226 253 253 253
40785-253 253 253 253 253 253 253 253 253 253 253 253
40786-253 253 253 253 253 253 231 231 231 250 250 250
40787-253 253 253 253 253 253 253 253 253 253 253 253
40788-253 253 253 253 253 253 253 253 253 253 253 253
40789-253 253 253 253 253 253 253 253 253 253 253 253
40790-253 253 253 253 253 253 253 253 253 228 184 62
40791-241 196 14 241 208 19 232 195 16 38 30 10
40792- 2 2 6 2 2 6 2 2 6 2 2 6
40793- 2 2 6 6 6 6 30 30 30 26 26 26
40794-203 166 17 154 142 90 66 66 66 26 26 26
40795- 6 6 6 0 0 0 0 0 0 0 0 0
40796- 0 0 0 0 0 0 0 0 0 0 0 0
40797- 0 0 0 0 0 0 0 0 0 0 0 0
40798- 0 0 0 0 0 0 0 0 0 0 0 0
40799- 0 0 0 0 0 0 0 0 0 0 0 0
40800- 6 6 6 18 18 18 38 38 38 58 58 58
40801- 78 78 78 86 86 86 101 101 101 123 123 123
40802-175 146 61 210 150 10 234 174 13 246 186 14
40803-246 190 14 246 190 14 246 190 14 238 190 10
40804-102 78 10 2 2 6 46 46 46 198 198 198
40805-253 253 253 253 253 253 253 253 253 253 253 253
40806-253 253 253 253 253 253 234 234 234 242 242 242
40807-253 253 253 253 253 253 253 253 253 253 253 253
40808-253 253 253 253 253 253 253 253 253 253 253 253
40809-253 253 253 253 253 253 253 253 253 253 253 253
40810-253 253 253 253 253 253 253 253 253 224 178 62
40811-242 186 14 241 196 14 210 166 10 22 18 6
40812- 2 2 6 2 2 6 2 2 6 2 2 6
40813- 2 2 6 2 2 6 6 6 6 121 92 8
40814-238 202 15 232 195 16 82 82 82 34 34 34
40815- 10 10 10 0 0 0 0 0 0 0 0 0
40816- 0 0 0 0 0 0 0 0 0 0 0 0
40817- 0 0 0 0 0 0 0 0 0 0 0 0
40818- 0 0 0 0 0 0 0 0 0 0 0 0
40819- 0 0 0 0 0 0 0 0 0 0 0 0
40820- 14 14 14 38 38 38 70 70 70 154 122 46
40821-190 142 34 200 144 11 197 138 11 197 138 11
40822-213 154 11 226 170 11 242 186 14 246 190 14
40823-246 190 14 246 190 14 246 190 14 246 190 14
40824-225 175 15 46 32 6 2 2 6 22 22 22
40825-158 158 158 250 250 250 253 253 253 253 253 253
40826-253 253 253 253 253 253 253 253 253 253 253 253
40827-253 253 253 253 253 253 253 253 253 253 253 253
40828-253 253 253 253 253 253 253 253 253 253 253 253
40829-253 253 253 253 253 253 253 253 253 253 253 253
40830-253 253 253 250 250 250 242 242 242 224 178 62
40831-239 182 13 236 186 11 213 154 11 46 32 6
40832- 2 2 6 2 2 6 2 2 6 2 2 6
40833- 2 2 6 2 2 6 61 42 6 225 175 15
40834-238 190 10 236 186 11 112 100 78 42 42 42
40835- 14 14 14 0 0 0 0 0 0 0 0 0
40836- 0 0 0 0 0 0 0 0 0 0 0 0
40837- 0 0 0 0 0 0 0 0 0 0 0 0
40838- 0 0 0 0 0 0 0 0 0 0 0 0
40839- 0 0 0 0 0 0 0 0 0 6 6 6
40840- 22 22 22 54 54 54 154 122 46 213 154 11
40841-226 170 11 230 174 11 226 170 11 226 170 11
40842-236 178 12 242 186 14 246 190 14 246 190 14
40843-246 190 14 246 190 14 246 190 14 246 190 14
40844-241 196 14 184 144 12 10 10 10 2 2 6
40845- 6 6 6 116 116 116 242 242 242 253 253 253
40846-253 253 253 253 253 253 253 253 253 253 253 253
40847-253 253 253 253 253 253 253 253 253 253 253 253
40848-253 253 253 253 253 253 253 253 253 253 253 253
40849-253 253 253 253 253 253 253 253 253 253 253 253
40850-253 253 253 231 231 231 198 198 198 214 170 54
40851-236 178 12 236 178 12 210 150 10 137 92 6
40852- 18 14 6 2 2 6 2 2 6 2 2 6
40853- 6 6 6 70 47 6 200 144 11 236 178 12
40854-239 182 13 239 182 13 124 112 88 58 58 58
40855- 22 22 22 6 6 6 0 0 0 0 0 0
40856- 0 0 0 0 0 0 0 0 0 0 0 0
40857- 0 0 0 0 0 0 0 0 0 0 0 0
40858- 0 0 0 0 0 0 0 0 0 0 0 0
40859- 0 0 0 0 0 0 0 0 0 10 10 10
40860- 30 30 30 70 70 70 180 133 36 226 170 11
40861-239 182 13 242 186 14 242 186 14 246 186 14
40862-246 190 14 246 190 14 246 190 14 246 190 14
40863-246 190 14 246 190 14 246 190 14 246 190 14
40864-246 190 14 232 195 16 98 70 6 2 2 6
40865- 2 2 6 2 2 6 66 66 66 221 221 221
40866-253 253 253 253 253 253 253 253 253 253 253 253
40867-253 253 253 253 253 253 253 253 253 253 253 253
40868-253 253 253 253 253 253 253 253 253 253 253 253
40869-253 253 253 253 253 253 253 253 253 253 253 253
40870-253 253 253 206 206 206 198 198 198 214 166 58
40871-230 174 11 230 174 11 216 158 10 192 133 9
40872-163 110 8 116 81 8 102 78 10 116 81 8
40873-167 114 7 197 138 11 226 170 11 239 182 13
40874-242 186 14 242 186 14 162 146 94 78 78 78
40875- 34 34 34 14 14 14 6 6 6 0 0 0
40876- 0 0 0 0 0 0 0 0 0 0 0 0
40877- 0 0 0 0 0 0 0 0 0 0 0 0
40878- 0 0 0 0 0 0 0 0 0 0 0 0
40879- 0 0 0 0 0 0 0 0 0 6 6 6
40880- 30 30 30 78 78 78 190 142 34 226 170 11
40881-239 182 13 246 190 14 246 190 14 246 190 14
40882-246 190 14 246 190 14 246 190 14 246 190 14
40883-246 190 14 246 190 14 246 190 14 246 190 14
40884-246 190 14 241 196 14 203 166 17 22 18 6
40885- 2 2 6 2 2 6 2 2 6 38 38 38
40886-218 218 218 253 253 253 253 253 253 253 253 253
40887-253 253 253 253 253 253 253 253 253 253 253 253
40888-253 253 253 253 253 253 253 253 253 253 253 253
40889-253 253 253 253 253 253 253 253 253 253 253 253
40890-250 250 250 206 206 206 198 198 198 202 162 69
40891-226 170 11 236 178 12 224 166 10 210 150 10
40892-200 144 11 197 138 11 192 133 9 197 138 11
40893-210 150 10 226 170 11 242 186 14 246 190 14
40894-246 190 14 246 186 14 225 175 15 124 112 88
40895- 62 62 62 30 30 30 14 14 14 6 6 6
40896- 0 0 0 0 0 0 0 0 0 0 0 0
40897- 0 0 0 0 0 0 0 0 0 0 0 0
40898- 0 0 0 0 0 0 0 0 0 0 0 0
40899- 0 0 0 0 0 0 0 0 0 10 10 10
40900- 30 30 30 78 78 78 174 135 50 224 166 10
40901-239 182 13 246 190 14 246 190 14 246 190 14
40902-246 190 14 246 190 14 246 190 14 246 190 14
40903-246 190 14 246 190 14 246 190 14 246 190 14
40904-246 190 14 246 190 14 241 196 14 139 102 15
40905- 2 2 6 2 2 6 2 2 6 2 2 6
40906- 78 78 78 250 250 250 253 253 253 253 253 253
40907-253 253 253 253 253 253 253 253 253 253 253 253
40908-253 253 253 253 253 253 253 253 253 253 253 253
40909-253 253 253 253 253 253 253 253 253 253 253 253
40910-250 250 250 214 214 214 198 198 198 190 150 46
40911-219 162 10 236 178 12 234 174 13 224 166 10
40912-216 158 10 213 154 11 213 154 11 216 158 10
40913-226 170 11 239 182 13 246 190 14 246 190 14
40914-246 190 14 246 190 14 242 186 14 206 162 42
40915-101 101 101 58 58 58 30 30 30 14 14 14
40916- 6 6 6 0 0 0 0 0 0 0 0 0
40917- 0 0 0 0 0 0 0 0 0 0 0 0
40918- 0 0 0 0 0 0 0 0 0 0 0 0
40919- 0 0 0 0 0 0 0 0 0 10 10 10
40920- 30 30 30 74 74 74 174 135 50 216 158 10
40921-236 178 12 246 190 14 246 190 14 246 190 14
40922-246 190 14 246 190 14 246 190 14 246 190 14
40923-246 190 14 246 190 14 246 190 14 246 190 14
40924-246 190 14 246 190 14 241 196 14 226 184 13
40925- 61 42 6 2 2 6 2 2 6 2 2 6
40926- 22 22 22 238 238 238 253 253 253 253 253 253
40927-253 253 253 253 253 253 253 253 253 253 253 253
40928-253 253 253 253 253 253 253 253 253 253 253 253
40929-253 253 253 253 253 253 253 253 253 253 253 253
40930-253 253 253 226 226 226 187 187 187 180 133 36
40931-216 158 10 236 178 12 239 182 13 236 178 12
40932-230 174 11 226 170 11 226 170 11 230 174 11
40933-236 178 12 242 186 14 246 190 14 246 190 14
40934-246 190 14 246 190 14 246 186 14 239 182 13
40935-206 162 42 106 106 106 66 66 66 34 34 34
40936- 14 14 14 6 6 6 0 0 0 0 0 0
40937- 0 0 0 0 0 0 0 0 0 0 0 0
40938- 0 0 0 0 0 0 0 0 0 0 0 0
40939- 0 0 0 0 0 0 0 0 0 6 6 6
40940- 26 26 26 70 70 70 163 133 67 213 154 11
40941-236 178 12 246 190 14 246 190 14 246 190 14
40942-246 190 14 246 190 14 246 190 14 246 190 14
40943-246 190 14 246 190 14 246 190 14 246 190 14
40944-246 190 14 246 190 14 246 190 14 241 196 14
40945-190 146 13 18 14 6 2 2 6 2 2 6
40946- 46 46 46 246 246 246 253 253 253 253 253 253
40947-253 253 253 253 253 253 253 253 253 253 253 253
40948-253 253 253 253 253 253 253 253 253 253 253 253
40949-253 253 253 253 253 253 253 253 253 253 253 253
40950-253 253 253 221 221 221 86 86 86 156 107 11
40951-216 158 10 236 178 12 242 186 14 246 186 14
40952-242 186 14 239 182 13 239 182 13 242 186 14
40953-242 186 14 246 186 14 246 190 14 246 190 14
40954-246 190 14 246 190 14 246 190 14 246 190 14
40955-242 186 14 225 175 15 142 122 72 66 66 66
40956- 30 30 30 10 10 10 0 0 0 0 0 0
40957- 0 0 0 0 0 0 0 0 0 0 0 0
40958- 0 0 0 0 0 0 0 0 0 0 0 0
40959- 0 0 0 0 0 0 0 0 0 6 6 6
40960- 26 26 26 70 70 70 163 133 67 210 150 10
40961-236 178 12 246 190 14 246 190 14 246 190 14
40962-246 190 14 246 190 14 246 190 14 246 190 14
40963-246 190 14 246 190 14 246 190 14 246 190 14
40964-246 190 14 246 190 14 246 190 14 246 190 14
40965-232 195 16 121 92 8 34 34 34 106 106 106
40966-221 221 221 253 253 253 253 253 253 253 253 253
40967-253 253 253 253 253 253 253 253 253 253 253 253
40968-253 253 253 253 253 253 253 253 253 253 253 253
40969-253 253 253 253 253 253 253 253 253 253 253 253
40970-242 242 242 82 82 82 18 14 6 163 110 8
40971-216 158 10 236 178 12 242 186 14 246 190 14
40972-246 190 14 246 190 14 246 190 14 246 190 14
40973-246 190 14 246 190 14 246 190 14 246 190 14
40974-246 190 14 246 190 14 246 190 14 246 190 14
40975-246 190 14 246 190 14 242 186 14 163 133 67
40976- 46 46 46 18 18 18 6 6 6 0 0 0
40977- 0 0 0 0 0 0 0 0 0 0 0 0
40978- 0 0 0 0 0 0 0 0 0 0 0 0
40979- 0 0 0 0 0 0 0 0 0 10 10 10
40980- 30 30 30 78 78 78 163 133 67 210 150 10
40981-236 178 12 246 186 14 246 190 14 246 190 14
40982-246 190 14 246 190 14 246 190 14 246 190 14
40983-246 190 14 246 190 14 246 190 14 246 190 14
40984-246 190 14 246 190 14 246 190 14 246 190 14
40985-241 196 14 215 174 15 190 178 144 253 253 253
40986-253 253 253 253 253 253 253 253 253 253 253 253
40987-253 253 253 253 253 253 253 253 253 253 253 253
40988-253 253 253 253 253 253 253 253 253 253 253 253
40989-253 253 253 253 253 253 253 253 253 218 218 218
40990- 58 58 58 2 2 6 22 18 6 167 114 7
40991-216 158 10 236 178 12 246 186 14 246 190 14
40992-246 190 14 246 190 14 246 190 14 246 190 14
40993-246 190 14 246 190 14 246 190 14 246 190 14
40994-246 190 14 246 190 14 246 190 14 246 190 14
40995-246 190 14 246 186 14 242 186 14 190 150 46
40996- 54 54 54 22 22 22 6 6 6 0 0 0
40997- 0 0 0 0 0 0 0 0 0 0 0 0
40998- 0 0 0 0 0 0 0 0 0 0 0 0
40999- 0 0 0 0 0 0 0 0 0 14 14 14
41000- 38 38 38 86 86 86 180 133 36 213 154 11
41001-236 178 12 246 186 14 246 190 14 246 190 14
41002-246 190 14 246 190 14 246 190 14 246 190 14
41003-246 190 14 246 190 14 246 190 14 246 190 14
41004-246 190 14 246 190 14 246 190 14 246 190 14
41005-246 190 14 232 195 16 190 146 13 214 214 214
41006-253 253 253 253 253 253 253 253 253 253 253 253
41007-253 253 253 253 253 253 253 253 253 253 253 253
41008-253 253 253 253 253 253 253 253 253 253 253 253
41009-253 253 253 250 250 250 170 170 170 26 26 26
41010- 2 2 6 2 2 6 37 26 9 163 110 8
41011-219 162 10 239 182 13 246 186 14 246 190 14
41012-246 190 14 246 190 14 246 190 14 246 190 14
41013-246 190 14 246 190 14 246 190 14 246 190 14
41014-246 190 14 246 190 14 246 190 14 246 190 14
41015-246 186 14 236 178 12 224 166 10 142 122 72
41016- 46 46 46 18 18 18 6 6 6 0 0 0
41017- 0 0 0 0 0 0 0 0 0 0 0 0
41018- 0 0 0 0 0 0 0 0 0 0 0 0
41019- 0 0 0 0 0 0 6 6 6 18 18 18
41020- 50 50 50 109 106 95 192 133 9 224 166 10
41021-242 186 14 246 190 14 246 190 14 246 190 14
41022-246 190 14 246 190 14 246 190 14 246 190 14
41023-246 190 14 246 190 14 246 190 14 246 190 14
41024-246 190 14 246 190 14 246 190 14 246 190 14
41025-242 186 14 226 184 13 210 162 10 142 110 46
41026-226 226 226 253 253 253 253 253 253 253 253 253
41027-253 253 253 253 253 253 253 253 253 253 253 253
41028-253 253 253 253 253 253 253 253 253 253 253 253
41029-198 198 198 66 66 66 2 2 6 2 2 6
41030- 2 2 6 2 2 6 50 34 6 156 107 11
41031-219 162 10 239 182 13 246 186 14 246 190 14
41032-246 190 14 246 190 14 246 190 14 246 190 14
41033-246 190 14 246 190 14 246 190 14 246 190 14
41034-246 190 14 246 190 14 246 190 14 242 186 14
41035-234 174 13 213 154 11 154 122 46 66 66 66
41036- 30 30 30 10 10 10 0 0 0 0 0 0
41037- 0 0 0 0 0 0 0 0 0 0 0 0
41038- 0 0 0 0 0 0 0 0 0 0 0 0
41039- 0 0 0 0 0 0 6 6 6 22 22 22
41040- 58 58 58 154 121 60 206 145 10 234 174 13
41041-242 186 14 246 186 14 246 190 14 246 190 14
41042-246 190 14 246 190 14 246 190 14 246 190 14
41043-246 190 14 246 190 14 246 190 14 246 190 14
41044-246 190 14 246 190 14 246 190 14 246 190 14
41045-246 186 14 236 178 12 210 162 10 163 110 8
41046- 61 42 6 138 138 138 218 218 218 250 250 250
41047-253 253 253 253 253 253 253 253 253 250 250 250
41048-242 242 242 210 210 210 144 144 144 66 66 66
41049- 6 6 6 2 2 6 2 2 6 2 2 6
41050- 2 2 6 2 2 6 61 42 6 163 110 8
41051-216 158 10 236 178 12 246 190 14 246 190 14
41052-246 190 14 246 190 14 246 190 14 246 190 14
41053-246 190 14 246 190 14 246 190 14 246 190 14
41054-246 190 14 239 182 13 230 174 11 216 158 10
41055-190 142 34 124 112 88 70 70 70 38 38 38
41056- 18 18 18 6 6 6 0 0 0 0 0 0
41057- 0 0 0 0 0 0 0 0 0 0 0 0
41058- 0 0 0 0 0 0 0 0 0 0 0 0
41059- 0 0 0 0 0 0 6 6 6 22 22 22
41060- 62 62 62 168 124 44 206 145 10 224 166 10
41061-236 178 12 239 182 13 242 186 14 242 186 14
41062-246 186 14 246 190 14 246 190 14 246 190 14
41063-246 190 14 246 190 14 246 190 14 246 190 14
41064-246 190 14 246 190 14 246 190 14 246 190 14
41065-246 190 14 236 178 12 216 158 10 175 118 6
41066- 80 54 7 2 2 6 6 6 6 30 30 30
41067- 54 54 54 62 62 62 50 50 50 38 38 38
41068- 14 14 14 2 2 6 2 2 6 2 2 6
41069- 2 2 6 2 2 6 2 2 6 2 2 6
41070- 2 2 6 6 6 6 80 54 7 167 114 7
41071-213 154 11 236 178 12 246 190 14 246 190 14
41072-246 190 14 246 190 14 246 190 14 246 190 14
41073-246 190 14 242 186 14 239 182 13 239 182 13
41074-230 174 11 210 150 10 174 135 50 124 112 88
41075- 82 82 82 54 54 54 34 34 34 18 18 18
41076- 6 6 6 0 0 0 0 0 0 0 0 0
41077- 0 0 0 0 0 0 0 0 0 0 0 0
41078- 0 0 0 0 0 0 0 0 0 0 0 0
41079- 0 0 0 0 0 0 6 6 6 18 18 18
41080- 50 50 50 158 118 36 192 133 9 200 144 11
41081-216 158 10 219 162 10 224 166 10 226 170 11
41082-230 174 11 236 178 12 239 182 13 239 182 13
41083-242 186 14 246 186 14 246 190 14 246 190 14
41084-246 190 14 246 190 14 246 190 14 246 190 14
41085-246 186 14 230 174 11 210 150 10 163 110 8
41086-104 69 6 10 10 10 2 2 6 2 2 6
41087- 2 2 6 2 2 6 2 2 6 2 2 6
41088- 2 2 6 2 2 6 2 2 6 2 2 6
41089- 2 2 6 2 2 6 2 2 6 2 2 6
41090- 2 2 6 6 6 6 91 60 6 167 114 7
41091-206 145 10 230 174 11 242 186 14 246 190 14
41092-246 190 14 246 190 14 246 186 14 242 186 14
41093-239 182 13 230 174 11 224 166 10 213 154 11
41094-180 133 36 124 112 88 86 86 86 58 58 58
41095- 38 38 38 22 22 22 10 10 10 6 6 6
41096- 0 0 0 0 0 0 0 0 0 0 0 0
41097- 0 0 0 0 0 0 0 0 0 0 0 0
41098- 0 0 0 0 0 0 0 0 0 0 0 0
41099- 0 0 0 0 0 0 0 0 0 14 14 14
41100- 34 34 34 70 70 70 138 110 50 158 118 36
41101-167 114 7 180 123 7 192 133 9 197 138 11
41102-200 144 11 206 145 10 213 154 11 219 162 10
41103-224 166 10 230 174 11 239 182 13 242 186 14
41104-246 186 14 246 186 14 246 186 14 246 186 14
41105-239 182 13 216 158 10 185 133 11 152 99 6
41106-104 69 6 18 14 6 2 2 6 2 2 6
41107- 2 2 6 2 2 6 2 2 6 2 2 6
41108- 2 2 6 2 2 6 2 2 6 2 2 6
41109- 2 2 6 2 2 6 2 2 6 2 2 6
41110- 2 2 6 6 6 6 80 54 7 152 99 6
41111-192 133 9 219 162 10 236 178 12 239 182 13
41112-246 186 14 242 186 14 239 182 13 236 178 12
41113-224 166 10 206 145 10 192 133 9 154 121 60
41114- 94 94 94 62 62 62 42 42 42 22 22 22
41115- 14 14 14 6 6 6 0 0 0 0 0 0
41116- 0 0 0 0 0 0 0 0 0 0 0 0
41117- 0 0 0 0 0 0 0 0 0 0 0 0
41118- 0 0 0 0 0 0 0 0 0 0 0 0
41119- 0 0 0 0 0 0 0 0 0 6 6 6
41120- 18 18 18 34 34 34 58 58 58 78 78 78
41121-101 98 89 124 112 88 142 110 46 156 107 11
41122-163 110 8 167 114 7 175 118 6 180 123 7
41123-185 133 11 197 138 11 210 150 10 219 162 10
41124-226 170 11 236 178 12 236 178 12 234 174 13
41125-219 162 10 197 138 11 163 110 8 130 83 6
41126- 91 60 6 10 10 10 2 2 6 2 2 6
41127- 18 18 18 38 38 38 38 38 38 38 38 38
41128- 38 38 38 38 38 38 38 38 38 38 38 38
41129- 38 38 38 38 38 38 26 26 26 2 2 6
41130- 2 2 6 6 6 6 70 47 6 137 92 6
41131-175 118 6 200 144 11 219 162 10 230 174 11
41132-234 174 13 230 174 11 219 162 10 210 150 10
41133-192 133 9 163 110 8 124 112 88 82 82 82
41134- 50 50 50 30 30 30 14 14 14 6 6 6
41135- 0 0 0 0 0 0 0 0 0 0 0 0
41136- 0 0 0 0 0 0 0 0 0 0 0 0
41137- 0 0 0 0 0 0 0 0 0 0 0 0
41138- 0 0 0 0 0 0 0 0 0 0 0 0
41139- 0 0 0 0 0 0 0 0 0 0 0 0
41140- 6 6 6 14 14 14 22 22 22 34 34 34
41141- 42 42 42 58 58 58 74 74 74 86 86 86
41142-101 98 89 122 102 70 130 98 46 121 87 25
41143-137 92 6 152 99 6 163 110 8 180 123 7
41144-185 133 11 197 138 11 206 145 10 200 144 11
41145-180 123 7 156 107 11 130 83 6 104 69 6
41146- 50 34 6 54 54 54 110 110 110 101 98 89
41147- 86 86 86 82 82 82 78 78 78 78 78 78
41148- 78 78 78 78 78 78 78 78 78 78 78 78
41149- 78 78 78 82 82 82 86 86 86 94 94 94
41150-106 106 106 101 101 101 86 66 34 124 80 6
41151-156 107 11 180 123 7 192 133 9 200 144 11
41152-206 145 10 200 144 11 192 133 9 175 118 6
41153-139 102 15 109 106 95 70 70 70 42 42 42
41154- 22 22 22 10 10 10 0 0 0 0 0 0
41155- 0 0 0 0 0 0 0 0 0 0 0 0
41156- 0 0 0 0 0 0 0 0 0 0 0 0
41157- 0 0 0 0 0 0 0 0 0 0 0 0
41158- 0 0 0 0 0 0 0 0 0 0 0 0
41159- 0 0 0 0 0 0 0 0 0 0 0 0
41160- 0 0 0 0 0 0 6 6 6 10 10 10
41161- 14 14 14 22 22 22 30 30 30 38 38 38
41162- 50 50 50 62 62 62 74 74 74 90 90 90
41163-101 98 89 112 100 78 121 87 25 124 80 6
41164-137 92 6 152 99 6 152 99 6 152 99 6
41165-138 86 6 124 80 6 98 70 6 86 66 30
41166-101 98 89 82 82 82 58 58 58 46 46 46
41167- 38 38 38 34 34 34 34 34 34 34 34 34
41168- 34 34 34 34 34 34 34 34 34 34 34 34
41169- 34 34 34 34 34 34 38 38 38 42 42 42
41170- 54 54 54 82 82 82 94 86 76 91 60 6
41171-134 86 6 156 107 11 167 114 7 175 118 6
41172-175 118 6 167 114 7 152 99 6 121 87 25
41173-101 98 89 62 62 62 34 34 34 18 18 18
41174- 6 6 6 0 0 0 0 0 0 0 0 0
41175- 0 0 0 0 0 0 0 0 0 0 0 0
41176- 0 0 0 0 0 0 0 0 0 0 0 0
41177- 0 0 0 0 0 0 0 0 0 0 0 0
41178- 0 0 0 0 0 0 0 0 0 0 0 0
41179- 0 0 0 0 0 0 0 0 0 0 0 0
41180- 0 0 0 0 0 0 0 0 0 0 0 0
41181- 0 0 0 6 6 6 6 6 6 10 10 10
41182- 18 18 18 22 22 22 30 30 30 42 42 42
41183- 50 50 50 66 66 66 86 86 86 101 98 89
41184-106 86 58 98 70 6 104 69 6 104 69 6
41185-104 69 6 91 60 6 82 62 34 90 90 90
41186- 62 62 62 38 38 38 22 22 22 14 14 14
41187- 10 10 10 10 10 10 10 10 10 10 10 10
41188- 10 10 10 10 10 10 6 6 6 10 10 10
41189- 10 10 10 10 10 10 10 10 10 14 14 14
41190- 22 22 22 42 42 42 70 70 70 89 81 66
41191- 80 54 7 104 69 6 124 80 6 137 92 6
41192-134 86 6 116 81 8 100 82 52 86 86 86
41193- 58 58 58 30 30 30 14 14 14 6 6 6
41194- 0 0 0 0 0 0 0 0 0 0 0 0
41195- 0 0 0 0 0 0 0 0 0 0 0 0
41196- 0 0 0 0 0 0 0 0 0 0 0 0
41197- 0 0 0 0 0 0 0 0 0 0 0 0
41198- 0 0 0 0 0 0 0 0 0 0 0 0
41199- 0 0 0 0 0 0 0 0 0 0 0 0
41200- 0 0 0 0 0 0 0 0 0 0 0 0
41201- 0 0 0 0 0 0 0 0 0 0 0 0
41202- 0 0 0 6 6 6 10 10 10 14 14 14
41203- 18 18 18 26 26 26 38 38 38 54 54 54
41204- 70 70 70 86 86 86 94 86 76 89 81 66
41205- 89 81 66 86 86 86 74 74 74 50 50 50
41206- 30 30 30 14 14 14 6 6 6 0 0 0
41207- 0 0 0 0 0 0 0 0 0 0 0 0
41208- 0 0 0 0 0 0 0 0 0 0 0 0
41209- 0 0 0 0 0 0 0 0 0 0 0 0
41210- 6 6 6 18 18 18 34 34 34 58 58 58
41211- 82 82 82 89 81 66 89 81 66 89 81 66
41212- 94 86 66 94 86 76 74 74 74 50 50 50
41213- 26 26 26 14 14 14 6 6 6 0 0 0
41214- 0 0 0 0 0 0 0 0 0 0 0 0
41215- 0 0 0 0 0 0 0 0 0 0 0 0
41216- 0 0 0 0 0 0 0 0 0 0 0 0
41217- 0 0 0 0 0 0 0 0 0 0 0 0
41218- 0 0 0 0 0 0 0 0 0 0 0 0
41219- 0 0 0 0 0 0 0 0 0 0 0 0
41220- 0 0 0 0 0 0 0 0 0 0 0 0
41221- 0 0 0 0 0 0 0 0 0 0 0 0
41222- 0 0 0 0 0 0 0 0 0 0 0 0
41223- 6 6 6 6 6 6 14 14 14 18 18 18
41224- 30 30 30 38 38 38 46 46 46 54 54 54
41225- 50 50 50 42 42 42 30 30 30 18 18 18
41226- 10 10 10 0 0 0 0 0 0 0 0 0
41227- 0 0 0 0 0 0 0 0 0 0 0 0
41228- 0 0 0 0 0 0 0 0 0 0 0 0
41229- 0 0 0 0 0 0 0 0 0 0 0 0
41230- 0 0 0 6 6 6 14 14 14 26 26 26
41231- 38 38 38 50 50 50 58 58 58 58 58 58
41232- 54 54 54 42 42 42 30 30 30 18 18 18
41233- 10 10 10 0 0 0 0 0 0 0 0 0
41234- 0 0 0 0 0 0 0 0 0 0 0 0
41235- 0 0 0 0 0 0 0 0 0 0 0 0
41236- 0 0 0 0 0 0 0 0 0 0 0 0
41237- 0 0 0 0 0 0 0 0 0 0 0 0
41238- 0 0 0 0 0 0 0 0 0 0 0 0
41239- 0 0 0 0 0 0 0 0 0 0 0 0
41240- 0 0 0 0 0 0 0 0 0 0 0 0
41241- 0 0 0 0 0 0 0 0 0 0 0 0
41242- 0 0 0 0 0 0 0 0 0 0 0 0
41243- 0 0 0 0 0 0 0 0 0 6 6 6
41244- 6 6 6 10 10 10 14 14 14 18 18 18
41245- 18 18 18 14 14 14 10 10 10 6 6 6
41246- 0 0 0 0 0 0 0 0 0 0 0 0
41247- 0 0 0 0 0 0 0 0 0 0 0 0
41248- 0 0 0 0 0 0 0 0 0 0 0 0
41249- 0 0 0 0 0 0 0 0 0 0 0 0
41250- 0 0 0 0 0 0 0 0 0 6 6 6
41251- 14 14 14 18 18 18 22 22 22 22 22 22
41252- 18 18 18 14 14 14 10 10 10 6 6 6
41253- 0 0 0 0 0 0 0 0 0 0 0 0
41254- 0 0 0 0 0 0 0 0 0 0 0 0
41255- 0 0 0 0 0 0 0 0 0 0 0 0
41256- 0 0 0 0 0 0 0 0 0 0 0 0
41257- 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4
41263+4 4 4 4 4 4 4 4 4 4 4 4 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
41272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41285+4 4 4 4 4 4
41286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41299+4 4 4 4 4 4
41300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41313+4 4 4 4 4 4
41314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41327+4 4 4 4 4 4
41328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41341+4 4 4 4 4 4
41342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41346+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41347+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41351+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41352+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41353+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41355+4 4 4 4 4 4
41356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41360+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41361+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41362+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41365+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41366+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41367+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41368+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41369+4 4 4 4 4 4
41370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41374+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41375+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41376+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41379+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41380+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41381+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41382+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41383+4 4 4 4 4 4
41384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41387+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41388+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41389+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41390+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41391+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41392+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41393+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41394+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41395+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41396+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41397+4 4 4 4 4 4
41398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41401+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41402+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41403+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41404+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41405+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41406+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41407+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41408+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41409+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41410+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41411+4 4 4 4 4 4
41412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41415+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41416+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41417+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41418+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41419+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41420+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41421+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41422+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41423+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41424+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41425+4 4 4 4 4 4
41426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41428+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41429+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41430+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41431+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41432+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41433+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41434+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41435+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41436+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41437+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41438+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41439+4 4 4 4 4 4
41440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41442+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41443+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41444+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41445+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41446+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41447+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41448+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41449+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41450+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41451+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41452+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41453+4 4 4 4 4 4
41454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41456+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41457+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41458+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41459+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41460+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41461+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41462+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41463+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41464+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41465+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41466+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41467+4 4 4 4 4 4
41468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41470+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41471+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41472+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41473+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41474+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41475+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41476+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41477+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41478+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41479+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41480+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41481+4 4 4 4 4 4
41482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41483+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41484+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41485+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41486+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41487+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41488+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41489+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41490+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41491+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41492+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41493+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41494+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41495+4 4 4 4 4 4
41496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41497+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41498+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41499+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41500+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41501+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41502+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41503+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41504+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41505+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41506+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41507+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41508+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41509+0 0 0 4 4 4
41510+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41511+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41512+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41513+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41514+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41515+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41516+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41517+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41518+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41519+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41520+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41521+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41522+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41523+2 0 0 0 0 0
41524+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41525+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41526+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41527+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41528+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41529+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41530+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41531+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41532+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41533+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41534+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41535+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41536+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41537+37 38 37 0 0 0
41538+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41539+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41540+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41541+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41542+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41543+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41544+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41545+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41546+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41547+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41548+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41549+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41550+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41551+85 115 134 4 0 0
41552+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41553+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41554+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41555+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41556+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41557+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41558+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41559+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41560+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41561+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41562+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41563+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41564+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41565+60 73 81 4 0 0
41566+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41567+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41568+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41569+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41570+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41571+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41572+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41573+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41574+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41575+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41576+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41577+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41578+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41579+16 19 21 4 0 0
41580+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41581+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41582+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41583+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41584+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41585+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41586+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41587+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41588+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41589+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41590+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41591+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41592+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41593+4 0 0 4 3 3
41594+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41595+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41596+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41598+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41599+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41600+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41601+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41602+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41603+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41604+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41605+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41606+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41607+3 2 2 4 4 4
41608+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41609+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41610+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41611+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41612+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41613+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41614+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41615+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41616+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41617+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41618+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41619+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41620+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41621+4 4 4 4 4 4
41622+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41623+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41624+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41625+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41626+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41627+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41628+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41629+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41630+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41631+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41632+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41633+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41634+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41635+4 4 4 4 4 4
41636+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41637+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41638+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41639+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41640+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41641+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41642+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41643+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41644+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41645+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41646+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41647+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41648+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41649+5 5 5 5 5 5
41650+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41651+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41652+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41653+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41654+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41655+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41656+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41657+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41658+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41659+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41660+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41661+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41662+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41663+5 5 5 4 4 4
41664+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41665+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41666+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41667+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41668+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41669+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41670+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41671+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41672+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41673+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41674+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41675+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41677+4 4 4 4 4 4
41678+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41679+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41680+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41681+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41682+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41683+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41684+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41685+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41686+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41687+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41688+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41689+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41691+4 4 4 4 4 4
41692+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41693+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41694+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41695+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41696+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41697+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41698+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41699+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41700+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41701+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41702+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41705+4 4 4 4 4 4
41706+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41707+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41708+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41709+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41710+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41711+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41712+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41713+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41714+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41715+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41716+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41719+4 4 4 4 4 4
41720+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41721+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41722+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41723+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41724+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41725+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41726+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41727+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41728+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41729+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41730+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41733+4 4 4 4 4 4
41734+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41735+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41736+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41737+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41738+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41739+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41740+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41741+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41742+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41743+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41744+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41747+4 4 4 4 4 4
41748+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41749+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41750+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41751+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41752+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41753+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41754+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41755+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41756+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41757+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41758+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41761+4 4 4 4 4 4
41762+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41763+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41764+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41765+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41766+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41767+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41768+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41769+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41770+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41771+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41772+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41775+4 4 4 4 4 4
41776+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41777+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41778+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41779+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41780+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41781+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41782+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41783+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41784+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41785+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41786+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41789+4 4 4 4 4 4
41790+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41791+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41792+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41793+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41794+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41795+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41796+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41797+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41798+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41799+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41800+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41803+4 4 4 4 4 4
41804+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41805+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41806+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41807+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41808+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41809+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41810+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41811+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41812+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41813+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41814+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41817+4 4 4 4 4 4
41818+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41819+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41820+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41821+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41822+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41823+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41824+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41825+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41826+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41827+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41828+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41831+4 4 4 4 4 4
41832+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41833+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41834+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41835+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41836+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41837+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41838+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41839+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41840+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41841+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41842+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41845+4 4 4 4 4 4
41846+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41847+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41848+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41849+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41850+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41851+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41852+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41853+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41854+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41855+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41856+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41859+4 4 4 4 4 4
41860+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41861+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41862+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41863+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41864+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41865+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41866+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41867+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41868+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41869+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41870+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41873+4 4 4 4 4 4
41874+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41875+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41876+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41877+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41878+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41879+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41880+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41881+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41882+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41883+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41884+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41887+4 4 4 4 4 4
41888+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41889+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41890+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41891+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41892+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41893+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41894+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41895+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41896+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41897+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41898+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41901+4 4 4 4 4 4
41902+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41903+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41904+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41905+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41906+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41907+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41908+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41909+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41910+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41911+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41912+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41915+4 4 4 4 4 4
41916+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41917+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41918+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41919+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41920+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41921+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41922+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41923+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41924+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41925+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41926+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41929+4 4 4 4 4 4
41930+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41931+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41932+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41933+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41934+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41935+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41936+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41937+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41938+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41939+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41940+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41943+4 4 4 4 4 4
41944+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41945+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41946+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41947+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41948+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41949+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41950+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41951+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41952+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41953+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41954+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41957+4 4 4 4 4 4
41958+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41959+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41960+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41961+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41962+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41963+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41964+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41965+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41966+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41967+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41968+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41971+4 4 4 4 4 4
41972+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41973+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41974+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41975+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41976+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41977+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41978+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41979+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41980+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41981+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41982+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41985+4 4 4 4 4 4
41986+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41987+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41988+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41989+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41990+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41991+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41992+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41993+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41994+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41995+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41996+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41999+4 4 4 4 4 4
42000+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42001+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
42002+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
42003+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
42004+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
42005+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
42006+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
42007+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
42008+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
42009+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42010+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42013+4 4 4 4 4 4
42014+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
42015+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
42016+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
42017+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
42018+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
42019+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
42020+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
42021+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
42022+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
42023+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
42024+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42027+4 4 4 4 4 4
42028+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42029+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42030+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42031+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42032+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42033+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42034+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42035+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42036+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42037+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42038+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42041+4 4 4 4 4 4
42042+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42043+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42044+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42045+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42046+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42047+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42048+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42049+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42050+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42051+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42052+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42055+4 4 4 4 4 4
42056+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42057+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42058+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42059+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42060+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42061+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42062+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42063+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42064+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42065+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42066+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42069+4 4 4 4 4 4
42070+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42071+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42072+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42073+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42074+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42075+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42076+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42077+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42078+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42079+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42083+4 4 4 4 4 4
42084+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42085+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42086+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42087+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42088+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42089+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42090+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42091+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42092+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42093+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42097+4 4 4 4 4 4
42098+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42099+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42100+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42101+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42102+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42103+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42104+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42105+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42106+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42107+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42111+4 4 4 4 4 4
42112+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42113+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42114+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42115+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42116+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42117+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42118+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42119+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42120+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42121+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42125+4 4 4 4 4 4
42126+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42127+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42128+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42129+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42130+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42131+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42132+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42133+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42134+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42139+4 4 4 4 4 4
42140+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42141+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42142+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42143+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42144+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42145+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42146+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42147+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42148+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42153+4 4 4 4 4 4
42154+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42155+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42156+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42157+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42158+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42159+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42160+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42161+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42162+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42167+4 4 4 4 4 4
42168+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42169+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42170+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42171+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42172+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42173+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42174+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42175+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42181+4 4 4 4 4 4
42182+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42183+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42184+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42185+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42186+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42187+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42188+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42189+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42195+4 4 4 4 4 4
42196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42197+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42198+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42199+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42200+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42201+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42202+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42203+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42209+4 4 4 4 4 4
42210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42211+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42212+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42213+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42214+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42215+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42216+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42217+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42223+4 4 4 4 4 4
42224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42225+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42226+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42227+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42228+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42229+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42230+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42231+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42237+4 4 4 4 4 4
42238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42240+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42241+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42242+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42243+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42244+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42245+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42251+4 4 4 4 4 4
42252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42255+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42256+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42257+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42258+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42265+4 4 4 4 4 4
42266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42269+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42270+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42271+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42272+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42279+4 4 4 4 4 4
42280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42283+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42284+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42285+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42286+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42293+4 4 4 4 4 4
42294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42297+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42298+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42299+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42300+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42307+4 4 4 4 4 4
42308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42312+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42313+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42314+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42321+4 4 4 4 4 4
42322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42326+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42327+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42328+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42335+4 4 4 4 4 4
42336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42340+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42341+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42342+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42349+4 4 4 4 4 4
42350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42354+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42355+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42363+4 4 4 4 4 4
42364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42368+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42369+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42377+4 4 4 4 4 4
42378diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42379index 8af6414..658c030 100644
42380--- a/drivers/video/udlfb.c
42381+++ b/drivers/video/udlfb.c
42382@@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42383 dlfb_urb_completion(urb);
42384
42385 error:
42386- atomic_add(bytes_sent, &dev->bytes_sent);
42387- atomic_add(bytes_identical, &dev->bytes_identical);
42388- atomic_add(width*height*2, &dev->bytes_rendered);
42389+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42390+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42391+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42392 end_cycles = get_cycles();
42393- atomic_add(((unsigned int) ((end_cycles - start_cycles)
42394+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42395 >> 10)), /* Kcycles */
42396 &dev->cpu_kcycles_used);
42397
42398@@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42399 dlfb_urb_completion(urb);
42400
42401 error:
42402- atomic_add(bytes_sent, &dev->bytes_sent);
42403- atomic_add(bytes_identical, &dev->bytes_identical);
42404- atomic_add(bytes_rendered, &dev->bytes_rendered);
42405+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42406+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42407+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42408 end_cycles = get_cycles();
42409- atomic_add(((unsigned int) ((end_cycles - start_cycles)
42410+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42411 >> 10)), /* Kcycles */
42412 &dev->cpu_kcycles_used);
42413 }
42414@@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42415 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42416 struct dlfb_data *dev = fb_info->par;
42417 return snprintf(buf, PAGE_SIZE, "%u\n",
42418- atomic_read(&dev->bytes_rendered));
42419+ atomic_read_unchecked(&dev->bytes_rendered));
42420 }
42421
42422 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42423@@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42424 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42425 struct dlfb_data *dev = fb_info->par;
42426 return snprintf(buf, PAGE_SIZE, "%u\n",
42427- atomic_read(&dev->bytes_identical));
42428+ atomic_read_unchecked(&dev->bytes_identical));
42429 }
42430
42431 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42432@@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42433 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42434 struct dlfb_data *dev = fb_info->par;
42435 return snprintf(buf, PAGE_SIZE, "%u\n",
42436- atomic_read(&dev->bytes_sent));
42437+ atomic_read_unchecked(&dev->bytes_sent));
42438 }
42439
42440 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42441@@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42442 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42443 struct dlfb_data *dev = fb_info->par;
42444 return snprintf(buf, PAGE_SIZE, "%u\n",
42445- atomic_read(&dev->cpu_kcycles_used));
42446+ atomic_read_unchecked(&dev->cpu_kcycles_used));
42447 }
42448
42449 static ssize_t edid_show(
42450@@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42451 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42452 struct dlfb_data *dev = fb_info->par;
42453
42454- atomic_set(&dev->bytes_rendered, 0);
42455- atomic_set(&dev->bytes_identical, 0);
42456- atomic_set(&dev->bytes_sent, 0);
42457- atomic_set(&dev->cpu_kcycles_used, 0);
42458+ atomic_set_unchecked(&dev->bytes_rendered, 0);
42459+ atomic_set_unchecked(&dev->bytes_identical, 0);
42460+ atomic_set_unchecked(&dev->bytes_sent, 0);
42461+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42462
42463 return count;
42464 }
42465diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42466index b0e2a42..e2df3ad 100644
42467--- a/drivers/video/uvesafb.c
42468+++ b/drivers/video/uvesafb.c
42469@@ -19,6 +19,7 @@
42470 #include <linux/io.h>
42471 #include <linux/mutex.h>
42472 #include <linux/slab.h>
42473+#include <linux/moduleloader.h>
42474 #include <video/edid.h>
42475 #include <video/uvesafb.h>
42476 #ifdef CONFIG_X86
42477@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42478 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42479 par->pmi_setpal = par->ypan = 0;
42480 } else {
42481+
42482+#ifdef CONFIG_PAX_KERNEXEC
42483+#ifdef CONFIG_MODULES
42484+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42485+#endif
42486+ if (!par->pmi_code) {
42487+ par->pmi_setpal = par->ypan = 0;
42488+ return 0;
42489+ }
42490+#endif
42491+
42492 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42493 + task->t.regs.edi);
42494+
42495+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42496+ pax_open_kernel();
42497+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42498+ pax_close_kernel();
42499+
42500+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42501+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42502+#else
42503 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42504 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42505+#endif
42506+
42507 printk(KERN_INFO "uvesafb: protected mode interface info at "
42508 "%04x:%04x\n",
42509 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42510@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42511 par->ypan = ypan;
42512
42513 if (par->pmi_setpal || par->ypan) {
42514+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42515 if (__supported_pte_mask & _PAGE_NX) {
42516 par->pmi_setpal = par->ypan = 0;
42517 printk(KERN_WARNING "uvesafb: NX protection is actively."
42518 "We have better not to use the PMI.\n");
42519- } else {
42520+ } else
42521+#endif
42522 uvesafb_vbe_getpmi(task, par);
42523- }
42524 }
42525 #else
42526 /* The protected mode interface is not available on non-x86. */
42527@@ -1836,6 +1860,11 @@ out:
42528 if (par->vbe_modes)
42529 kfree(par->vbe_modes);
42530
42531+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42532+ if (par->pmi_code)
42533+ module_free_exec(NULL, par->pmi_code);
42534+#endif
42535+
42536 framebuffer_release(info);
42537 return err;
42538 }
42539@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42540 kfree(par->vbe_state_orig);
42541 if (par->vbe_state_saved)
42542 kfree(par->vbe_state_saved);
42543+
42544+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42545+ if (par->pmi_code)
42546+ module_free_exec(NULL, par->pmi_code);
42547+#endif
42548+
42549 }
42550
42551 framebuffer_release(info);
42552diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42553index 501b340..86bd4cf 100644
42554--- a/drivers/video/vesafb.c
42555+++ b/drivers/video/vesafb.c
42556@@ -9,6 +9,7 @@
42557 */
42558
42559 #include <linux/module.h>
42560+#include <linux/moduleloader.h>
42561 #include <linux/kernel.h>
42562 #include <linux/errno.h>
42563 #include <linux/string.h>
42564@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42565 static int vram_total __initdata; /* Set total amount of memory */
42566 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42567 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42568-static void (*pmi_start)(void) __read_mostly;
42569-static void (*pmi_pal) (void) __read_mostly;
42570+static void (*pmi_start)(void) __read_only;
42571+static void (*pmi_pal) (void) __read_only;
42572 static int depth __read_mostly;
42573 static int vga_compat __read_mostly;
42574 /* --------------------------------------------------------------------- */
42575@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42576 unsigned int size_vmode;
42577 unsigned int size_remap;
42578 unsigned int size_total;
42579+ void *pmi_code = NULL;
42580
42581 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42582 return -ENODEV;
42583@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42584 size_remap = size_total;
42585 vesafb_fix.smem_len = size_remap;
42586
42587-#ifndef __i386__
42588- screen_info.vesapm_seg = 0;
42589-#endif
42590-
42591 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42592 printk(KERN_WARNING
42593 "vesafb: cannot reserve video memory at 0x%lx\n",
42594@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42595 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42596 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42597
42598+#ifdef __i386__
42599+
42600+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42601+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
42602+ if (!pmi_code)
42603+#elif !defined(CONFIG_PAX_KERNEXEC)
42604+ if (0)
42605+#endif
42606+
42607+#endif
42608+ screen_info.vesapm_seg = 0;
42609+
42610 if (screen_info.vesapm_seg) {
42611- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42612- screen_info.vesapm_seg,screen_info.vesapm_off);
42613+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42614+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42615 }
42616
42617 if (screen_info.vesapm_seg < 0xc000)
42618@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42619
42620 if (ypan || pmi_setpal) {
42621 unsigned short *pmi_base;
42622+
42623 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42624- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42625- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42626+
42627+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42628+ pax_open_kernel();
42629+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42630+#else
42631+ pmi_code = pmi_base;
42632+#endif
42633+
42634+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42635+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42636+
42637+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42638+ pmi_start = ktva_ktla(pmi_start);
42639+ pmi_pal = ktva_ktla(pmi_pal);
42640+ pax_close_kernel();
42641+#endif
42642+
42643 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42644 if (pmi_base[3]) {
42645 printk(KERN_INFO "vesafb: pmi: ports = ");
42646@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42647 info->node, info->fix.id);
42648 return 0;
42649 err:
42650+
42651+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42652+ module_free_exec(NULL, pmi_code);
42653+#endif
42654+
42655 if (info->screen_base)
42656 iounmap(info->screen_base);
42657 framebuffer_release(info);
42658diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42659index 88714ae..16c2e11 100644
42660--- a/drivers/video/via/via_clock.h
42661+++ b/drivers/video/via/via_clock.h
42662@@ -56,7 +56,7 @@ struct via_clock {
42663
42664 void (*set_engine_pll_state)(u8 state);
42665 void (*set_engine_pll)(struct via_pll_config config);
42666-};
42667+} __no_const;
42668
42669
42670 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42671diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42672index e56c934..fc22f4b 100644
42673--- a/drivers/xen/xen-pciback/conf_space.h
42674+++ b/drivers/xen/xen-pciback/conf_space.h
42675@@ -44,15 +44,15 @@ struct config_field {
42676 struct {
42677 conf_dword_write write;
42678 conf_dword_read read;
42679- } dw;
42680+ } __no_const dw;
42681 struct {
42682 conf_word_write write;
42683 conf_word_read read;
42684- } w;
42685+ } __no_const w;
42686 struct {
42687 conf_byte_write write;
42688 conf_byte_read read;
42689- } b;
42690+ } __no_const b;
42691 } u;
42692 struct list_head list;
42693 };
42694diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42695index 57ccb75..f6d05f8 100644
42696--- a/fs/9p/vfs_inode.c
42697+++ b/fs/9p/vfs_inode.c
42698@@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42699 void
42700 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42701 {
42702- char *s = nd_get_link(nd);
42703+ const char *s = nd_get_link(nd);
42704
42705 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42706 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42707diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42708index 0225742..1cd4732 100644
42709--- a/fs/Kconfig.binfmt
42710+++ b/fs/Kconfig.binfmt
42711@@ -89,7 +89,7 @@ config HAVE_AOUT
42712
42713 config BINFMT_AOUT
42714 tristate "Kernel support for a.out and ECOFF binaries"
42715- depends on HAVE_AOUT
42716+ depends on HAVE_AOUT && BROKEN
42717 ---help---
42718 A.out (Assembler.OUTput) is a set of formats for libraries and
42719 executables used in the earliest versions of UNIX. Linux used
42720diff --git a/fs/aio.c b/fs/aio.c
42721index 55c4c76..11aee6f 100644
42722--- a/fs/aio.c
42723+++ b/fs/aio.c
42724@@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42725 size += sizeof(struct io_event) * nr_events;
42726 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42727
42728- if (nr_pages < 0)
42729+ if (nr_pages <= 0)
42730 return -EINVAL;
42731
42732 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42733@@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42734 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42735 {
42736 ssize_t ret;
42737+ struct iovec iovstack;
42738
42739 #ifdef CONFIG_COMPAT
42740 if (compat)
42741 ret = compat_rw_copy_check_uvector(type,
42742 (struct compat_iovec __user *)kiocb->ki_buf,
42743- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42744+ kiocb->ki_nbytes, 1, &iovstack,
42745 &kiocb->ki_iovec);
42746 else
42747 #endif
42748 ret = rw_copy_check_uvector(type,
42749 (struct iovec __user *)kiocb->ki_buf,
42750- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42751+ kiocb->ki_nbytes, 1, &iovstack,
42752 &kiocb->ki_iovec);
42753 if (ret < 0)
42754 goto out;
42755@@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42756 if (ret < 0)
42757 goto out;
42758
42759+ if (kiocb->ki_iovec == &iovstack) {
42760+ kiocb->ki_inline_vec = iovstack;
42761+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
42762+ }
42763 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42764 kiocb->ki_cur_seg = 0;
42765 /* ki_nbytes/left now reflect bytes instead of segs */
42766diff --git a/fs/attr.c b/fs/attr.c
42767index 0da9095..1386693 100644
42768--- a/fs/attr.c
42769+++ b/fs/attr.c
42770@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42771 unsigned long limit;
42772
42773 limit = rlimit(RLIMIT_FSIZE);
42774+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42775 if (limit != RLIM_INFINITY && offset > limit)
42776 goto out_sig;
42777 if (offset > inode->i_sb->s_maxbytes)
42778diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42779index da8876d..4456166 100644
42780--- a/fs/autofs4/waitq.c
42781+++ b/fs/autofs4/waitq.c
42782@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42783 {
42784 unsigned long sigpipe, flags;
42785 mm_segment_t fs;
42786- const char *data = (const char *)addr;
42787+ const char __user *data = (const char __force_user *)addr;
42788 ssize_t wr = 0;
42789
42790 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42791@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42792 return 1;
42793 }
42794
42795+#ifdef CONFIG_GRKERNSEC_HIDESYM
42796+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42797+#endif
42798+
42799 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42800 enum autofs_notify notify)
42801 {
42802@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42803
42804 /* If this is a direct mount request create a dummy name */
42805 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42806+#ifdef CONFIG_GRKERNSEC_HIDESYM
42807+ /* this name does get written to userland via autofs4_write() */
42808+ qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42809+#else
42810 qstr.len = sprintf(name, "%p", dentry);
42811+#endif
42812 else {
42813 qstr.len = autofs4_getpath(sbi, dentry, &name);
42814 if (!qstr.len) {
42815diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42816index e18da23..affc30e 100644
42817--- a/fs/befs/linuxvfs.c
42818+++ b/fs/befs/linuxvfs.c
42819@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42820 {
42821 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42822 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42823- char *link = nd_get_link(nd);
42824+ const char *link = nd_get_link(nd);
42825 if (!IS_ERR(link))
42826 kfree(link);
42827 }
42828diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42829index d146e18..12d1bd1 100644
42830--- a/fs/binfmt_aout.c
42831+++ b/fs/binfmt_aout.c
42832@@ -16,6 +16,7 @@
42833 #include <linux/string.h>
42834 #include <linux/fs.h>
42835 #include <linux/file.h>
42836+#include <linux/security.h>
42837 #include <linux/stat.h>
42838 #include <linux/fcntl.h>
42839 #include <linux/ptrace.h>
42840@@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42841 #endif
42842 # define START_STACK(u) ((void __user *)u.start_stack)
42843
42844+ memset(&dump, 0, sizeof(dump));
42845+
42846 fs = get_fs();
42847 set_fs(KERNEL_DS);
42848 has_dumped = 1;
42849@@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42850
42851 /* If the size of the dump file exceeds the rlimit, then see what would happen
42852 if we wrote the stack, but not the data area. */
42853+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42854 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42855 dump.u_dsize = 0;
42856
42857 /* Make sure we have enough room to write the stack and data areas. */
42858+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42859 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42860 dump.u_ssize = 0;
42861
42862@@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42863 rlim = rlimit(RLIMIT_DATA);
42864 if (rlim >= RLIM_INFINITY)
42865 rlim = ~0;
42866+
42867+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42868 if (ex.a_data + ex.a_bss > rlim)
42869 return -ENOMEM;
42870
42871@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42872
42873 install_exec_creds(bprm);
42874
42875+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42876+ current->mm->pax_flags = 0UL;
42877+#endif
42878+
42879+#ifdef CONFIG_PAX_PAGEEXEC
42880+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42881+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42882+
42883+#ifdef CONFIG_PAX_EMUTRAMP
42884+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42885+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42886+#endif
42887+
42888+#ifdef CONFIG_PAX_MPROTECT
42889+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42890+ current->mm->pax_flags |= MF_PAX_MPROTECT;
42891+#endif
42892+
42893+ }
42894+#endif
42895+
42896 if (N_MAGIC(ex) == OMAGIC) {
42897 unsigned long text_addr, map_size;
42898 loff_t pos;
42899@@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42900 }
42901
42902 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42903- PROT_READ | PROT_WRITE | PROT_EXEC,
42904+ PROT_READ | PROT_WRITE,
42905 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42906 fd_offset + ex.a_text);
42907 if (error != N_DATADDR(ex)) {
42908diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42909index 0225fdd..9f0ef53 100644
42910--- a/fs/binfmt_elf.c
42911+++ b/fs/binfmt_elf.c
42912@@ -32,6 +32,7 @@
42913 #include <linux/elf.h>
42914 #include <linux/utsname.h>
42915 #include <linux/coredump.h>
42916+#include <linux/xattr.h>
42917 #include <asm/uaccess.h>
42918 #include <asm/param.h>
42919 #include <asm/page.h>
42920@@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42921 #define elf_core_dump NULL
42922 #endif
42923
42924+#ifdef CONFIG_PAX_MPROTECT
42925+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42926+#endif
42927+
42928 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42929 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42930 #else
42931@@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42932 .load_binary = load_elf_binary,
42933 .load_shlib = load_elf_library,
42934 .core_dump = elf_core_dump,
42935+
42936+#ifdef CONFIG_PAX_MPROTECT
42937+ .handle_mprotect= elf_handle_mprotect,
42938+#endif
42939+
42940 .min_coredump = ELF_EXEC_PAGESIZE,
42941 };
42942
42943@@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42944
42945 static int set_brk(unsigned long start, unsigned long end)
42946 {
42947+ unsigned long e = end;
42948+
42949 start = ELF_PAGEALIGN(start);
42950 end = ELF_PAGEALIGN(end);
42951 if (end > start) {
42952@@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42953 if (BAD_ADDR(addr))
42954 return addr;
42955 }
42956- current->mm->start_brk = current->mm->brk = end;
42957+ current->mm->start_brk = current->mm->brk = e;
42958 return 0;
42959 }
42960
42961@@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42962 elf_addr_t __user *u_rand_bytes;
42963 const char *k_platform = ELF_PLATFORM;
42964 const char *k_base_platform = ELF_BASE_PLATFORM;
42965- unsigned char k_rand_bytes[16];
42966+ u32 k_rand_bytes[4];
42967 int items;
42968 elf_addr_t *elf_info;
42969 int ei_index = 0;
42970 const struct cred *cred = current_cred();
42971 struct vm_area_struct *vma;
42972+ unsigned long saved_auxv[AT_VECTOR_SIZE];
42973
42974 /*
42975 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42976@@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42977 * Generate 16 random bytes for userspace PRNG seeding.
42978 */
42979 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42980- u_rand_bytes = (elf_addr_t __user *)
42981- STACK_ALLOC(p, sizeof(k_rand_bytes));
42982+ srandom32(k_rand_bytes[0] ^ random32());
42983+ srandom32(k_rand_bytes[1] ^ random32());
42984+ srandom32(k_rand_bytes[2] ^ random32());
42985+ srandom32(k_rand_bytes[3] ^ random32());
42986+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
42987+ u_rand_bytes = (elf_addr_t __user *) p;
42988 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42989 return -EFAULT;
42990
42991@@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42992 return -EFAULT;
42993 current->mm->env_end = p;
42994
42995+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42996+
42997 /* Put the elf_info on the stack in the right place. */
42998 sp = (elf_addr_t __user *)envp + 1;
42999- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43000+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43001 return -EFAULT;
43002 return 0;
43003 }
43004@@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43005 {
43006 struct elf_phdr *elf_phdata;
43007 struct elf_phdr *eppnt;
43008- unsigned long load_addr = 0;
43009+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43010 int load_addr_set = 0;
43011 unsigned long last_bss = 0, elf_bss = 0;
43012- unsigned long error = ~0UL;
43013+ unsigned long error = -EINVAL;
43014 unsigned long total_size;
43015 int retval, i, size;
43016
43017@@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43018 goto out_close;
43019 }
43020
43021+#ifdef CONFIG_PAX_SEGMEXEC
43022+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43023+ pax_task_size = SEGMEXEC_TASK_SIZE;
43024+#endif
43025+
43026 eppnt = elf_phdata;
43027 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43028 if (eppnt->p_type == PT_LOAD) {
43029@@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43030 k = load_addr + eppnt->p_vaddr;
43031 if (BAD_ADDR(k) ||
43032 eppnt->p_filesz > eppnt->p_memsz ||
43033- eppnt->p_memsz > TASK_SIZE ||
43034- TASK_SIZE - eppnt->p_memsz < k) {
43035+ eppnt->p_memsz > pax_task_size ||
43036+ pax_task_size - eppnt->p_memsz < k) {
43037 error = -ENOMEM;
43038 goto out_close;
43039 }
43040@@ -523,6 +547,311 @@ out:
43041 return error;
43042 }
43043
43044+#ifdef CONFIG_PAX_PT_PAX_FLAGS
43045+#ifdef CONFIG_PAX_SOFTMODE
43046+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
43047+{
43048+ unsigned long pax_flags = 0UL;
43049+
43050+#ifdef CONFIG_PAX_PAGEEXEC
43051+ if (elf_phdata->p_flags & PF_PAGEEXEC)
43052+ pax_flags |= MF_PAX_PAGEEXEC;
43053+#endif
43054+
43055+#ifdef CONFIG_PAX_SEGMEXEC
43056+ if (elf_phdata->p_flags & PF_SEGMEXEC)
43057+ pax_flags |= MF_PAX_SEGMEXEC;
43058+#endif
43059+
43060+#ifdef CONFIG_PAX_EMUTRAMP
43061+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
43062+ pax_flags |= MF_PAX_EMUTRAMP;
43063+#endif
43064+
43065+#ifdef CONFIG_PAX_MPROTECT
43066+ if (elf_phdata->p_flags & PF_MPROTECT)
43067+ pax_flags |= MF_PAX_MPROTECT;
43068+#endif
43069+
43070+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43071+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43072+ pax_flags |= MF_PAX_RANDMMAP;
43073+#endif
43074+
43075+ return pax_flags;
43076+}
43077+#endif
43078+
43079+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
43080+{
43081+ unsigned long pax_flags = 0UL;
43082+
43083+#ifdef CONFIG_PAX_PAGEEXEC
43084+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43085+ pax_flags |= MF_PAX_PAGEEXEC;
43086+#endif
43087+
43088+#ifdef CONFIG_PAX_SEGMEXEC
43089+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43090+ pax_flags |= MF_PAX_SEGMEXEC;
43091+#endif
43092+
43093+#ifdef CONFIG_PAX_EMUTRAMP
43094+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43095+ pax_flags |= MF_PAX_EMUTRAMP;
43096+#endif
43097+
43098+#ifdef CONFIG_PAX_MPROTECT
43099+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43100+ pax_flags |= MF_PAX_MPROTECT;
43101+#endif
43102+
43103+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43104+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43105+ pax_flags |= MF_PAX_RANDMMAP;
43106+#endif
43107+
43108+ return pax_flags;
43109+}
43110+#endif
43111+
43112+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43113+#ifdef CONFIG_PAX_SOFTMODE
43114+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43115+{
43116+ unsigned long pax_flags = 0UL;
43117+
43118+#ifdef CONFIG_PAX_PAGEEXEC
43119+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43120+ pax_flags |= MF_PAX_PAGEEXEC;
43121+#endif
43122+
43123+#ifdef CONFIG_PAX_SEGMEXEC
43124+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43125+ pax_flags |= MF_PAX_SEGMEXEC;
43126+#endif
43127+
43128+#ifdef CONFIG_PAX_EMUTRAMP
43129+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43130+ pax_flags |= MF_PAX_EMUTRAMP;
43131+#endif
43132+
43133+#ifdef CONFIG_PAX_MPROTECT
43134+ if (pax_flags_softmode & MF_PAX_MPROTECT)
43135+ pax_flags |= MF_PAX_MPROTECT;
43136+#endif
43137+
43138+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43139+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43140+ pax_flags |= MF_PAX_RANDMMAP;
43141+#endif
43142+
43143+ return pax_flags;
43144+}
43145+#endif
43146+
43147+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43148+{
43149+ unsigned long pax_flags = 0UL;
43150+
43151+#ifdef CONFIG_PAX_PAGEEXEC
43152+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43153+ pax_flags |= MF_PAX_PAGEEXEC;
43154+#endif
43155+
43156+#ifdef CONFIG_PAX_SEGMEXEC
43157+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43158+ pax_flags |= MF_PAX_SEGMEXEC;
43159+#endif
43160+
43161+#ifdef CONFIG_PAX_EMUTRAMP
43162+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43163+ pax_flags |= MF_PAX_EMUTRAMP;
43164+#endif
43165+
43166+#ifdef CONFIG_PAX_MPROTECT
43167+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43168+ pax_flags |= MF_PAX_MPROTECT;
43169+#endif
43170+
43171+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43172+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43173+ pax_flags |= MF_PAX_RANDMMAP;
43174+#endif
43175+
43176+ return pax_flags;
43177+}
43178+#endif
43179+
43180+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43181+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43182+{
43183+ unsigned long pax_flags = 0UL;
43184+
43185+#ifdef CONFIG_PAX_EI_PAX
43186+
43187+#ifdef CONFIG_PAX_PAGEEXEC
43188+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43189+ pax_flags |= MF_PAX_PAGEEXEC;
43190+#endif
43191+
43192+#ifdef CONFIG_PAX_SEGMEXEC
43193+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43194+ pax_flags |= MF_PAX_SEGMEXEC;
43195+#endif
43196+
43197+#ifdef CONFIG_PAX_EMUTRAMP
43198+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43199+ pax_flags |= MF_PAX_EMUTRAMP;
43200+#endif
43201+
43202+#ifdef CONFIG_PAX_MPROTECT
43203+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43204+ pax_flags |= MF_PAX_MPROTECT;
43205+#endif
43206+
43207+#ifdef CONFIG_PAX_ASLR
43208+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43209+ pax_flags |= MF_PAX_RANDMMAP;
43210+#endif
43211+
43212+#else
43213+
43214+#ifdef CONFIG_PAX_PAGEEXEC
43215+ pax_flags |= MF_PAX_PAGEEXEC;
43216+#endif
43217+
43218+#ifdef CONFIG_PAX_SEGMEXEC
43219+ pax_flags |= MF_PAX_SEGMEXEC;
43220+#endif
43221+
43222+#ifdef CONFIG_PAX_MPROTECT
43223+ pax_flags |= MF_PAX_MPROTECT;
43224+#endif
43225+
43226+#ifdef CONFIG_PAX_RANDMMAP
43227+ if (randomize_va_space)
43228+ pax_flags |= MF_PAX_RANDMMAP;
43229+#endif
43230+
43231+#endif
43232+
43233+ return pax_flags;
43234+}
43235+
43236+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43237+{
43238+
43239+#ifdef CONFIG_PAX_PT_PAX_FLAGS
43240+ unsigned long i;
43241+
43242+ for (i = 0UL; i < elf_ex->e_phnum; i++)
43243+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43244+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43245+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43246+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43247+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43248+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43249+ return ~0UL;
43250+
43251+#ifdef CONFIG_PAX_SOFTMODE
43252+ if (pax_softmode)
43253+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43254+ else
43255+#endif
43256+
43257+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43258+ break;
43259+ }
43260+#endif
43261+
43262+ return ~0UL;
43263+}
43264+
43265+static unsigned long pax_parse_xattr_pax(struct file * const file)
43266+{
43267+
43268+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43269+ ssize_t xattr_size, i;
43270+ unsigned char xattr_value[5];
43271+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43272+
43273+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43274+ if (xattr_size <= 0)
43275+ return ~0UL;
43276+
43277+ for (i = 0; i < xattr_size; i++)
43278+ switch (xattr_value[i]) {
43279+ default:
43280+ return ~0UL;
43281+
43282+#define parse_flag(option1, option2, flag) \
43283+ case option1: \
43284+ pax_flags_hardmode |= MF_PAX_##flag; \
43285+ break; \
43286+ case option2: \
43287+ pax_flags_softmode |= MF_PAX_##flag; \
43288+ break;
43289+
43290+ parse_flag('p', 'P', PAGEEXEC);
43291+ parse_flag('e', 'E', EMUTRAMP);
43292+ parse_flag('m', 'M', MPROTECT);
43293+ parse_flag('r', 'R', RANDMMAP);
43294+ parse_flag('s', 'S', SEGMEXEC);
43295+
43296+#undef parse_flag
43297+ }
43298+
43299+ if (pax_flags_hardmode & pax_flags_softmode)
43300+ return ~0UL;
43301+
43302+#ifdef CONFIG_PAX_SOFTMODE
43303+ if (pax_softmode)
43304+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43305+ else
43306+#endif
43307+
43308+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43309+#else
43310+ return ~0UL;
43311+#endif
43312+
43313+}
43314+
43315+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43316+{
43317+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43318+
43319+ pax_flags = pax_parse_ei_pax(elf_ex);
43320+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43321+ xattr_pax_flags = pax_parse_xattr_pax(file);
43322+
43323+ if (pt_pax_flags == ~0UL)
43324+ pt_pax_flags = xattr_pax_flags;
43325+ else if (xattr_pax_flags == ~0UL)
43326+ xattr_pax_flags = pt_pax_flags;
43327+ if (pt_pax_flags != xattr_pax_flags)
43328+ return -EINVAL;
43329+ if (pt_pax_flags != ~0UL)
43330+ pax_flags = pt_pax_flags;
43331+
43332+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43333+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43334+ if ((__supported_pte_mask & _PAGE_NX))
43335+ pax_flags &= ~MF_PAX_SEGMEXEC;
43336+ else
43337+ pax_flags &= ~MF_PAX_PAGEEXEC;
43338+ }
43339+#endif
43340+
43341+ if (0 > pax_check_flags(&pax_flags))
43342+ return -EINVAL;
43343+
43344+ current->mm->pax_flags = pax_flags;
43345+ return 0;
43346+}
43347+#endif
43348+
43349 /*
43350 * These are the functions used to load ELF style executables and shared
43351 * libraries. There is no binary dependent code anywhere else.
43352@@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43353 {
43354 unsigned int random_variable = 0;
43355
43356+#ifdef CONFIG_PAX_RANDUSTACK
43357+ if (randomize_va_space)
43358+ return stack_top - current->mm->delta_stack;
43359+#endif
43360+
43361 if ((current->flags & PF_RANDOMIZE) &&
43362 !(current->personality & ADDR_NO_RANDOMIZE)) {
43363 random_variable = get_random_int() & STACK_RND_MASK;
43364@@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43365 unsigned long load_addr = 0, load_bias = 0;
43366 int load_addr_set = 0;
43367 char * elf_interpreter = NULL;
43368- unsigned long error;
43369+ unsigned long error = 0;
43370 struct elf_phdr *elf_ppnt, *elf_phdata;
43371 unsigned long elf_bss, elf_brk;
43372 int retval, i;
43373@@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43374 unsigned long start_code, end_code, start_data, end_data;
43375 unsigned long reloc_func_desc __maybe_unused = 0;
43376 int executable_stack = EXSTACK_DEFAULT;
43377- unsigned long def_flags = 0;
43378 struct {
43379 struct elfhdr elf_ex;
43380 struct elfhdr interp_elf_ex;
43381 } *loc;
43382+ unsigned long pax_task_size = TASK_SIZE;
43383
43384 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43385 if (!loc) {
43386@@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43387 goto out_free_dentry;
43388
43389 /* OK, This is the point of no return */
43390- current->mm->def_flags = def_flags;
43391+
43392+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43393+ current->mm->pax_flags = 0UL;
43394+#endif
43395+
43396+#ifdef CONFIG_PAX_DLRESOLVE
43397+ current->mm->call_dl_resolve = 0UL;
43398+#endif
43399+
43400+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43401+ current->mm->call_syscall = 0UL;
43402+#endif
43403+
43404+#ifdef CONFIG_PAX_ASLR
43405+ current->mm->delta_mmap = 0UL;
43406+ current->mm->delta_stack = 0UL;
43407+#endif
43408+
43409+ current->mm->def_flags = 0;
43410+
43411+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43412+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43413+ send_sig(SIGKILL, current, 0);
43414+ goto out_free_dentry;
43415+ }
43416+#endif
43417+
43418+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43419+ pax_set_initial_flags(bprm);
43420+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43421+ if (pax_set_initial_flags_func)
43422+ (pax_set_initial_flags_func)(bprm);
43423+#endif
43424+
43425+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43426+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43427+ current->mm->context.user_cs_limit = PAGE_SIZE;
43428+ current->mm->def_flags |= VM_PAGEEXEC;
43429+ }
43430+#endif
43431+
43432+#ifdef CONFIG_PAX_SEGMEXEC
43433+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43434+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43435+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43436+ pax_task_size = SEGMEXEC_TASK_SIZE;
43437+ current->mm->def_flags |= VM_NOHUGEPAGE;
43438+ }
43439+#endif
43440+
43441+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43442+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43443+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43444+ put_cpu();
43445+ }
43446+#endif
43447
43448 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43449 may depend on the personality. */
43450 SET_PERSONALITY(loc->elf_ex);
43451+
43452+#ifdef CONFIG_PAX_ASLR
43453+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43454+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43455+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43456+ }
43457+#endif
43458+
43459+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43460+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43461+ executable_stack = EXSTACK_DISABLE_X;
43462+ current->personality &= ~READ_IMPLIES_EXEC;
43463+ } else
43464+#endif
43465+
43466 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43467 current->personality |= READ_IMPLIES_EXEC;
43468
43469@@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43470 #else
43471 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43472 #endif
43473+
43474+#ifdef CONFIG_PAX_RANDMMAP
43475+ /* PaX: randomize base address at the default exe base if requested */
43476+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43477+#ifdef CONFIG_SPARC64
43478+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43479+#else
43480+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43481+#endif
43482+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43483+ elf_flags |= MAP_FIXED;
43484+ }
43485+#endif
43486+
43487 }
43488
43489 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43490@@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43491 * allowed task size. Note that p_filesz must always be
43492 * <= p_memsz so it is only necessary to check p_memsz.
43493 */
43494- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43495- elf_ppnt->p_memsz > TASK_SIZE ||
43496- TASK_SIZE - elf_ppnt->p_memsz < k) {
43497+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43498+ elf_ppnt->p_memsz > pax_task_size ||
43499+ pax_task_size - elf_ppnt->p_memsz < k) {
43500 /* set_brk can never work. Avoid overflows. */
43501 send_sig(SIGKILL, current, 0);
43502 retval = -EINVAL;
43503@@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43504 goto out_free_dentry;
43505 }
43506 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43507- send_sig(SIGSEGV, current, 0);
43508- retval = -EFAULT; /* Nobody gets to see this, but.. */
43509- goto out_free_dentry;
43510+ /*
43511+ * This bss-zeroing can fail if the ELF
43512+ * file specifies odd protections. So
43513+ * we don't check the return value
43514+ */
43515 }
43516
43517+#ifdef CONFIG_PAX_RANDMMAP
43518+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43519+ unsigned long start, size;
43520+
43521+ start = ELF_PAGEALIGN(elf_brk);
43522+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43523+ down_read(&current->mm->mmap_sem);
43524+ retval = -ENOMEM;
43525+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43526+ unsigned long prot = PROT_NONE;
43527+
43528+ up_read(&current->mm->mmap_sem);
43529+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43530+// if (current->personality & ADDR_NO_RANDOMIZE)
43531+// prot = PROT_READ;
43532+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43533+ retval = IS_ERR_VALUE(start) ? start : 0;
43534+ } else
43535+ up_read(&current->mm->mmap_sem);
43536+ if (retval == 0)
43537+ retval = set_brk(start + size, start + size + PAGE_SIZE);
43538+ if (retval < 0) {
43539+ send_sig(SIGKILL, current, 0);
43540+ goto out_free_dentry;
43541+ }
43542+ }
43543+#endif
43544+
43545 if (elf_interpreter) {
43546 unsigned long uninitialized_var(interp_map_addr);
43547
43548@@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43549 * Decide what to dump of a segment, part, all or none.
43550 */
43551 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43552- unsigned long mm_flags)
43553+ unsigned long mm_flags, long signr)
43554 {
43555 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43556
43557@@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43558 if (vma->vm_file == NULL)
43559 return 0;
43560
43561- if (FILTER(MAPPED_PRIVATE))
43562+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43563 goto whole;
43564
43565 /*
43566@@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43567 {
43568 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43569 int i = 0;
43570- do
43571+ do {
43572 i += 2;
43573- while (auxv[i - 2] != AT_NULL);
43574+ } while (auxv[i - 2] != AT_NULL);
43575 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43576 }
43577
43578@@ -1879,14 +2327,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43579 }
43580
43581 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43582- unsigned long mm_flags)
43583+ struct coredump_params *cprm)
43584 {
43585 struct vm_area_struct *vma;
43586 size_t size = 0;
43587
43588 for (vma = first_vma(current, gate_vma); vma != NULL;
43589 vma = next_vma(vma, gate_vma))
43590- size += vma_dump_size(vma, mm_flags);
43591+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43592 return size;
43593 }
43594
43595@@ -1980,7 +2428,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43596
43597 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43598
43599- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43600+ offset += elf_core_vma_data_size(gate_vma, cprm);
43601 offset += elf_core_extra_data_size();
43602 e_shoff = offset;
43603
43604@@ -1994,10 +2442,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43605 offset = dataoff;
43606
43607 size += sizeof(*elf);
43608+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43609 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43610 goto end_coredump;
43611
43612 size += sizeof(*phdr4note);
43613+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43614 if (size > cprm->limit
43615 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43616 goto end_coredump;
43617@@ -2011,7 +2461,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43618 phdr.p_offset = offset;
43619 phdr.p_vaddr = vma->vm_start;
43620 phdr.p_paddr = 0;
43621- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43622+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43623 phdr.p_memsz = vma->vm_end - vma->vm_start;
43624 offset += phdr.p_filesz;
43625 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43626@@ -2022,6 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43627 phdr.p_align = ELF_EXEC_PAGESIZE;
43628
43629 size += sizeof(phdr);
43630+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43631 if (size > cprm->limit
43632 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43633 goto end_coredump;
43634@@ -2046,7 +2497,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43635 unsigned long addr;
43636 unsigned long end;
43637
43638- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43639+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43640
43641 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43642 struct page *page;
43643@@ -2055,6 +2506,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43644 page = get_dump_page(addr);
43645 if (page) {
43646 void *kaddr = kmap(page);
43647+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43648 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43649 !dump_write(cprm->file, kaddr,
43650 PAGE_SIZE);
43651@@ -2072,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43652
43653 if (e_phnum == PN_XNUM) {
43654 size += sizeof(*shdr4extnum);
43655+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43656 if (size > cprm->limit
43657 || !dump_write(cprm->file, shdr4extnum,
43658 sizeof(*shdr4extnum)))
43659@@ -2092,6 +2545,97 @@ out:
43660
43661 #endif /* CONFIG_ELF_CORE */
43662
43663+#ifdef CONFIG_PAX_MPROTECT
43664+/* PaX: non-PIC ELF libraries need relocations on their executable segments
43665+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43666+ * we'll remove VM_MAYWRITE for good on RELRO segments.
43667+ *
43668+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43669+ * basis because we want to allow the common case and not the special ones.
43670+ */
43671+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43672+{
43673+ struct elfhdr elf_h;
43674+ struct elf_phdr elf_p;
43675+ unsigned long i;
43676+ unsigned long oldflags;
43677+ bool is_textrel_rw, is_textrel_rx, is_relro;
43678+
43679+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43680+ return;
43681+
43682+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43683+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43684+
43685+#ifdef CONFIG_PAX_ELFRELOCS
43686+ /* possible TEXTREL */
43687+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43688+ 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);
43689+#else
43690+ is_textrel_rw = false;
43691+ is_textrel_rx = false;
43692+#endif
43693+
43694+ /* possible RELRO */
43695+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43696+
43697+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43698+ return;
43699+
43700+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43701+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43702+
43703+#ifdef CONFIG_PAX_ETEXECRELOCS
43704+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43705+#else
43706+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43707+#endif
43708+
43709+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43710+ !elf_check_arch(&elf_h) ||
43711+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43712+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43713+ return;
43714+
43715+ for (i = 0UL; i < elf_h.e_phnum; i++) {
43716+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43717+ return;
43718+ switch (elf_p.p_type) {
43719+ case PT_DYNAMIC:
43720+ if (!is_textrel_rw && !is_textrel_rx)
43721+ continue;
43722+ i = 0UL;
43723+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43724+ elf_dyn dyn;
43725+
43726+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43727+ return;
43728+ if (dyn.d_tag == DT_NULL)
43729+ return;
43730+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43731+ gr_log_textrel(vma);
43732+ if (is_textrel_rw)
43733+ vma->vm_flags |= VM_MAYWRITE;
43734+ else
43735+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43736+ vma->vm_flags &= ~VM_MAYWRITE;
43737+ return;
43738+ }
43739+ i++;
43740+ }
43741+ return;
43742+
43743+ case PT_GNU_RELRO:
43744+ if (!is_relro)
43745+ continue;
43746+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43747+ vma->vm_flags &= ~VM_MAYWRITE;
43748+ return;
43749+ }
43750+ }
43751+}
43752+#endif
43753+
43754 static int __init init_elf_binfmt(void)
43755 {
43756 register_binfmt(&elf_format);
43757diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43758index 178cb70..8972997 100644
43759--- a/fs/binfmt_flat.c
43760+++ b/fs/binfmt_flat.c
43761@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43762 realdatastart = (unsigned long) -ENOMEM;
43763 printk("Unable to allocate RAM for process data, errno %d\n",
43764 (int)-realdatastart);
43765+ down_write(&current->mm->mmap_sem);
43766 vm_munmap(textpos, text_len);
43767+ up_write(&current->mm->mmap_sem);
43768 ret = realdatastart;
43769 goto err;
43770 }
43771@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43772 }
43773 if (IS_ERR_VALUE(result)) {
43774 printk("Unable to read data+bss, errno %d\n", (int)-result);
43775+ down_write(&current->mm->mmap_sem);
43776 vm_munmap(textpos, text_len);
43777 vm_munmap(realdatastart, len);
43778+ up_write(&current->mm->mmap_sem);
43779 ret = result;
43780 goto err;
43781 }
43782@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43783 }
43784 if (IS_ERR_VALUE(result)) {
43785 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43786+ down_write(&current->mm->mmap_sem);
43787 vm_munmap(textpos, text_len + data_len + extra +
43788 MAX_SHARED_LIBS * sizeof(unsigned long));
43789+ up_write(&current->mm->mmap_sem);
43790 ret = result;
43791 goto err;
43792 }
43793diff --git a/fs/bio.c b/fs/bio.c
43794index 73922ab..16642dd 100644
43795--- a/fs/bio.c
43796+++ b/fs/bio.c
43797@@ -841,7 +841,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43798 /*
43799 * Overflow, abort
43800 */
43801- if (end < start)
43802+ if (end < start || end - start > INT_MAX - nr_pages)
43803 return ERR_PTR(-EINVAL);
43804
43805 nr_pages += end - start;
43806@@ -975,7 +975,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43807 /*
43808 * Overflow, abort
43809 */
43810- if (end < start)
43811+ if (end < start || end - start > INT_MAX - nr_pages)
43812 return ERR_PTR(-EINVAL);
43813
43814 nr_pages += end - start;
43815@@ -1237,7 +1237,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43816 const int read = bio_data_dir(bio) == READ;
43817 struct bio_map_data *bmd = bio->bi_private;
43818 int i;
43819- char *p = bmd->sgvecs[0].iov_base;
43820+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43821
43822 __bio_for_each_segment(bvec, bio, i, 0) {
43823 char *addr = page_address(bvec->bv_page);
43824diff --git a/fs/block_dev.c b/fs/block_dev.c
43825index c2bbe1f..9dfbc23 100644
43826--- a/fs/block_dev.c
43827+++ b/fs/block_dev.c
43828@@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43829 else if (bdev->bd_contains == bdev)
43830 return true; /* is a whole device which isn't held */
43831
43832- else if (whole->bd_holder == bd_may_claim)
43833+ else if (whole->bd_holder == (void *)bd_may_claim)
43834 return true; /* is a partition of a device that is being partitioned */
43835 else if (whole->bd_holder != NULL)
43836 return false; /* is a partition of a held device */
43837diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43838index da6e936..1598dd0 100644
43839--- a/fs/btrfs/check-integrity.c
43840+++ b/fs/btrfs/check-integrity.c
43841@@ -155,7 +155,7 @@ struct btrfsic_block {
43842 union {
43843 bio_end_io_t *bio;
43844 bh_end_io_t *bh;
43845- } orig_bio_bh_end_io;
43846+ } __no_const orig_bio_bh_end_io;
43847 int submit_bio_bh_rw;
43848 u64 flush_gen; /* only valid if !never_written */
43849 };
43850diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43851index 8206b39..06d5654 100644
43852--- a/fs/btrfs/ctree.c
43853+++ b/fs/btrfs/ctree.c
43854@@ -973,9 +973,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43855 free_extent_buffer(buf);
43856 add_root_to_dirty_list(root);
43857 } else {
43858- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43859- parent_start = parent->start;
43860- else
43861+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43862+ if (parent)
43863+ parent_start = parent->start;
43864+ else
43865+ parent_start = 0;
43866+ } else
43867 parent_start = 0;
43868
43869 WARN_ON(trans->transid != btrfs_header_generation(parent));
43870diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43871index a7d1921..a32dba2 100644
43872--- a/fs/btrfs/inode.c
43873+++ b/fs/btrfs/inode.c
43874@@ -7111,7 +7111,7 @@ fail:
43875 return -ENOMEM;
43876 }
43877
43878-static int btrfs_getattr(struct vfsmount *mnt,
43879+int btrfs_getattr(struct vfsmount *mnt,
43880 struct dentry *dentry, struct kstat *stat)
43881 {
43882 struct inode *inode = dentry->d_inode;
43883@@ -7125,6 +7125,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43884 return 0;
43885 }
43886
43887+EXPORT_SYMBOL(btrfs_getattr);
43888+
43889+dev_t get_btrfs_dev_from_inode(struct inode *inode)
43890+{
43891+ return BTRFS_I(inode)->root->anon_dev;
43892+}
43893+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43894+
43895 /*
43896 * If a file is moved, it will inherit the cow and compression flags of the new
43897 * directory.
43898diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43899index 0e92e57..8b560de 100644
43900--- a/fs/btrfs/ioctl.c
43901+++ b/fs/btrfs/ioctl.c
43902@@ -2902,9 +2902,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43903 for (i = 0; i < num_types; i++) {
43904 struct btrfs_space_info *tmp;
43905
43906+ /* Don't copy in more than we allocated */
43907 if (!slot_count)
43908 break;
43909
43910+ slot_count--;
43911+
43912 info = NULL;
43913 rcu_read_lock();
43914 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43915@@ -2926,10 +2929,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43916 memcpy(dest, &space, sizeof(space));
43917 dest++;
43918 space_args.total_spaces++;
43919- slot_count--;
43920 }
43921- if (!slot_count)
43922- break;
43923 }
43924 up_read(&info->groups_sem);
43925 }
43926diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43927index 646ee21..f020f87 100644
43928--- a/fs/btrfs/relocation.c
43929+++ b/fs/btrfs/relocation.c
43930@@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43931 }
43932 spin_unlock(&rc->reloc_root_tree.lock);
43933
43934- BUG_ON((struct btrfs_root *)node->data != root);
43935+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
43936
43937 if (!del) {
43938 spin_lock(&rc->reloc_root_tree.lock);
43939diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43940index 622f469..e8d2d55 100644
43941--- a/fs/cachefiles/bind.c
43942+++ b/fs/cachefiles/bind.c
43943@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43944 args);
43945
43946 /* start by checking things over */
43947- ASSERT(cache->fstop_percent >= 0 &&
43948- cache->fstop_percent < cache->fcull_percent &&
43949+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
43950 cache->fcull_percent < cache->frun_percent &&
43951 cache->frun_percent < 100);
43952
43953- ASSERT(cache->bstop_percent >= 0 &&
43954- cache->bstop_percent < cache->bcull_percent &&
43955+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
43956 cache->bcull_percent < cache->brun_percent &&
43957 cache->brun_percent < 100);
43958
43959diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43960index 0a1467b..6a53245 100644
43961--- a/fs/cachefiles/daemon.c
43962+++ b/fs/cachefiles/daemon.c
43963@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43964 if (n > buflen)
43965 return -EMSGSIZE;
43966
43967- if (copy_to_user(_buffer, buffer, n) != 0)
43968+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43969 return -EFAULT;
43970
43971 return n;
43972@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43973 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43974 return -EIO;
43975
43976- if (datalen < 0 || datalen > PAGE_SIZE - 1)
43977+ if (datalen > PAGE_SIZE - 1)
43978 return -EOPNOTSUPP;
43979
43980 /* drag the command string into the kernel so we can parse it */
43981@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43982 if (args[0] != '%' || args[1] != '\0')
43983 return -EINVAL;
43984
43985- if (fstop < 0 || fstop >= cache->fcull_percent)
43986+ if (fstop >= cache->fcull_percent)
43987 return cachefiles_daemon_range_error(cache, args);
43988
43989 cache->fstop_percent = fstop;
43990@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43991 if (args[0] != '%' || args[1] != '\0')
43992 return -EINVAL;
43993
43994- if (bstop < 0 || bstop >= cache->bcull_percent)
43995+ if (bstop >= cache->bcull_percent)
43996 return cachefiles_daemon_range_error(cache, args);
43997
43998 cache->bstop_percent = bstop;
43999diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
44000index bd6bc1b..b627b53 100644
44001--- a/fs/cachefiles/internal.h
44002+++ b/fs/cachefiles/internal.h
44003@@ -57,7 +57,7 @@ struct cachefiles_cache {
44004 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44005 struct rb_root active_nodes; /* active nodes (can't be culled) */
44006 rwlock_t active_lock; /* lock for active_nodes */
44007- atomic_t gravecounter; /* graveyard uniquifier */
44008+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44009 unsigned frun_percent; /* when to stop culling (% files) */
44010 unsigned fcull_percent; /* when to start culling (% files) */
44011 unsigned fstop_percent; /* when to stop allocating (% files) */
44012@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
44013 * proc.c
44014 */
44015 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44016-extern atomic_t cachefiles_lookup_histogram[HZ];
44017-extern atomic_t cachefiles_mkdir_histogram[HZ];
44018-extern atomic_t cachefiles_create_histogram[HZ];
44019+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44020+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44021+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44022
44023 extern int __init cachefiles_proc_init(void);
44024 extern void cachefiles_proc_cleanup(void);
44025 static inline
44026-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44027+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44028 {
44029 unsigned long jif = jiffies - start_jif;
44030 if (jif >= HZ)
44031 jif = HZ - 1;
44032- atomic_inc(&histogram[jif]);
44033+ atomic_inc_unchecked(&histogram[jif]);
44034 }
44035
44036 #else
44037diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
44038index 7f0771d..87d4f36 100644
44039--- a/fs/cachefiles/namei.c
44040+++ b/fs/cachefiles/namei.c
44041@@ -318,7 +318,7 @@ try_again:
44042 /* first step is to make up a grave dentry in the graveyard */
44043 sprintf(nbuffer, "%08x%08x",
44044 (uint32_t) get_seconds(),
44045- (uint32_t) atomic_inc_return(&cache->gravecounter));
44046+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44047
44048 /* do the multiway lock magic */
44049 trap = lock_rename(cache->graveyard, dir);
44050diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
44051index eccd339..4c1d995 100644
44052--- a/fs/cachefiles/proc.c
44053+++ b/fs/cachefiles/proc.c
44054@@ -14,9 +14,9 @@
44055 #include <linux/seq_file.h>
44056 #include "internal.h"
44057
44058-atomic_t cachefiles_lookup_histogram[HZ];
44059-atomic_t cachefiles_mkdir_histogram[HZ];
44060-atomic_t cachefiles_create_histogram[HZ];
44061+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44062+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44063+atomic_unchecked_t cachefiles_create_histogram[HZ];
44064
44065 /*
44066 * display the latency histogram
44067@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
44068 return 0;
44069 default:
44070 index = (unsigned long) v - 3;
44071- x = atomic_read(&cachefiles_lookup_histogram[index]);
44072- y = atomic_read(&cachefiles_mkdir_histogram[index]);
44073- z = atomic_read(&cachefiles_create_histogram[index]);
44074+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44075+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44076+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44077 if (x == 0 && y == 0 && z == 0)
44078 return 0;
44079
44080diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44081index 0e3c092..818480e 100644
44082--- a/fs/cachefiles/rdwr.c
44083+++ b/fs/cachefiles/rdwr.c
44084@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44085 old_fs = get_fs();
44086 set_fs(KERNEL_DS);
44087 ret = file->f_op->write(
44088- file, (const void __user *) data, len, &pos);
44089+ file, (const void __force_user *) data, len, &pos);
44090 set_fs(old_fs);
44091 kunmap(page);
44092 if (ret != len)
44093diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44094index 3e8094b..cb3ff3d 100644
44095--- a/fs/ceph/dir.c
44096+++ b/fs/ceph/dir.c
44097@@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44098 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44099 struct ceph_mds_client *mdsc = fsc->mdsc;
44100 unsigned frag = fpos_frag(filp->f_pos);
44101- int off = fpos_off(filp->f_pos);
44102+ unsigned int off = fpos_off(filp->f_pos);
44103 int err;
44104 u32 ftype;
44105 struct ceph_mds_reply_info_parsed *rinfo;
44106@@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
44107 if (nd &&
44108 (nd->flags & LOOKUP_OPEN) &&
44109 !(nd->intent.open.flags & O_CREAT)) {
44110- int mode = nd->intent.open.create_mode & ~current->fs->umask;
44111+ int mode = nd->intent.open.create_mode & ~current_umask();
44112 return ceph_lookup_open(dir, dentry, nd, mode, 1);
44113 }
44114
44115diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44116index e814052..28dcdf7 100644
44117--- a/fs/cifs/cifs_debug.c
44118+++ b/fs/cifs/cifs_debug.c
44119@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44120
44121 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44122 #ifdef CONFIG_CIFS_STATS2
44123- atomic_set(&totBufAllocCount, 0);
44124- atomic_set(&totSmBufAllocCount, 0);
44125+ atomic_set_unchecked(&totBufAllocCount, 0);
44126+ atomic_set_unchecked(&totSmBufAllocCount, 0);
44127 #endif /* CONFIG_CIFS_STATS2 */
44128 spin_lock(&cifs_tcp_ses_lock);
44129 list_for_each(tmp1, &cifs_tcp_ses_list) {
44130@@ -281,25 +281,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44131 tcon = list_entry(tmp3,
44132 struct cifs_tcon,
44133 tcon_list);
44134- atomic_set(&tcon->num_smbs_sent, 0);
44135- atomic_set(&tcon->num_writes, 0);
44136- atomic_set(&tcon->num_reads, 0);
44137- atomic_set(&tcon->num_oplock_brks, 0);
44138- atomic_set(&tcon->num_opens, 0);
44139- atomic_set(&tcon->num_posixopens, 0);
44140- atomic_set(&tcon->num_posixmkdirs, 0);
44141- atomic_set(&tcon->num_closes, 0);
44142- atomic_set(&tcon->num_deletes, 0);
44143- atomic_set(&tcon->num_mkdirs, 0);
44144- atomic_set(&tcon->num_rmdirs, 0);
44145- atomic_set(&tcon->num_renames, 0);
44146- atomic_set(&tcon->num_t2renames, 0);
44147- atomic_set(&tcon->num_ffirst, 0);
44148- atomic_set(&tcon->num_fnext, 0);
44149- atomic_set(&tcon->num_fclose, 0);
44150- atomic_set(&tcon->num_hardlinks, 0);
44151- atomic_set(&tcon->num_symlinks, 0);
44152- atomic_set(&tcon->num_locks, 0);
44153+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44154+ atomic_set_unchecked(&tcon->num_writes, 0);
44155+ atomic_set_unchecked(&tcon->num_reads, 0);
44156+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
44157+ atomic_set_unchecked(&tcon->num_opens, 0);
44158+ atomic_set_unchecked(&tcon->num_posixopens, 0);
44159+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
44160+ atomic_set_unchecked(&tcon->num_closes, 0);
44161+ atomic_set_unchecked(&tcon->num_deletes, 0);
44162+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
44163+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
44164+ atomic_set_unchecked(&tcon->num_renames, 0);
44165+ atomic_set_unchecked(&tcon->num_t2renames, 0);
44166+ atomic_set_unchecked(&tcon->num_ffirst, 0);
44167+ atomic_set_unchecked(&tcon->num_fnext, 0);
44168+ atomic_set_unchecked(&tcon->num_fclose, 0);
44169+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
44170+ atomic_set_unchecked(&tcon->num_symlinks, 0);
44171+ atomic_set_unchecked(&tcon->num_locks, 0);
44172 }
44173 }
44174 }
44175@@ -329,8 +329,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44176 smBufAllocCount.counter, cifs_min_small);
44177 #ifdef CONFIG_CIFS_STATS2
44178 seq_printf(m, "Total Large %d Small %d Allocations\n",
44179- atomic_read(&totBufAllocCount),
44180- atomic_read(&totSmBufAllocCount));
44181+ atomic_read_unchecked(&totBufAllocCount),
44182+ atomic_read_unchecked(&totSmBufAllocCount));
44183 #endif /* CONFIG_CIFS_STATS2 */
44184
44185 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44186@@ -359,41 +359,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44187 if (tcon->need_reconnect)
44188 seq_puts(m, "\tDISCONNECTED ");
44189 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
44190- atomic_read(&tcon->num_smbs_sent),
44191- atomic_read(&tcon->num_oplock_brks));
44192+ atomic_read_unchecked(&tcon->num_smbs_sent),
44193+ atomic_read_unchecked(&tcon->num_oplock_brks));
44194 seq_printf(m, "\nReads: %d Bytes: %lld",
44195- atomic_read(&tcon->num_reads),
44196+ atomic_read_unchecked(&tcon->num_reads),
44197 (long long)(tcon->bytes_read));
44198 seq_printf(m, "\nWrites: %d Bytes: %lld",
44199- atomic_read(&tcon->num_writes),
44200+ atomic_read_unchecked(&tcon->num_writes),
44201 (long long)(tcon->bytes_written));
44202 seq_printf(m, "\nFlushes: %d",
44203- atomic_read(&tcon->num_flushes));
44204+ atomic_read_unchecked(&tcon->num_flushes));
44205 seq_printf(m, "\nLocks: %d HardLinks: %d "
44206 "Symlinks: %d",
44207- atomic_read(&tcon->num_locks),
44208- atomic_read(&tcon->num_hardlinks),
44209- atomic_read(&tcon->num_symlinks));
44210+ atomic_read_unchecked(&tcon->num_locks),
44211+ atomic_read_unchecked(&tcon->num_hardlinks),
44212+ atomic_read_unchecked(&tcon->num_symlinks));
44213 seq_printf(m, "\nOpens: %d Closes: %d "
44214 "Deletes: %d",
44215- atomic_read(&tcon->num_opens),
44216- atomic_read(&tcon->num_closes),
44217- atomic_read(&tcon->num_deletes));
44218+ atomic_read_unchecked(&tcon->num_opens),
44219+ atomic_read_unchecked(&tcon->num_closes),
44220+ atomic_read_unchecked(&tcon->num_deletes));
44221 seq_printf(m, "\nPosix Opens: %d "
44222 "Posix Mkdirs: %d",
44223- atomic_read(&tcon->num_posixopens),
44224- atomic_read(&tcon->num_posixmkdirs));
44225+ atomic_read_unchecked(&tcon->num_posixopens),
44226+ atomic_read_unchecked(&tcon->num_posixmkdirs));
44227 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44228- atomic_read(&tcon->num_mkdirs),
44229- atomic_read(&tcon->num_rmdirs));
44230+ atomic_read_unchecked(&tcon->num_mkdirs),
44231+ atomic_read_unchecked(&tcon->num_rmdirs));
44232 seq_printf(m, "\nRenames: %d T2 Renames %d",
44233- atomic_read(&tcon->num_renames),
44234- atomic_read(&tcon->num_t2renames));
44235+ atomic_read_unchecked(&tcon->num_renames),
44236+ atomic_read_unchecked(&tcon->num_t2renames));
44237 seq_printf(m, "\nFindFirst: %d FNext %d "
44238 "FClose %d",
44239- atomic_read(&tcon->num_ffirst),
44240- atomic_read(&tcon->num_fnext),
44241- atomic_read(&tcon->num_fclose));
44242+ atomic_read_unchecked(&tcon->num_ffirst),
44243+ atomic_read_unchecked(&tcon->num_fnext),
44244+ atomic_read_unchecked(&tcon->num_fclose));
44245 }
44246 }
44247 }
44248diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44249index 8b6e344..303a662 100644
44250--- a/fs/cifs/cifsfs.c
44251+++ b/fs/cifs/cifsfs.c
44252@@ -994,7 +994,7 @@ cifs_init_request_bufs(void)
44253 cifs_req_cachep = kmem_cache_create("cifs_request",
44254 CIFSMaxBufSize +
44255 MAX_CIFS_HDR_SIZE, 0,
44256- SLAB_HWCACHE_ALIGN, NULL);
44257+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44258 if (cifs_req_cachep == NULL)
44259 return -ENOMEM;
44260
44261@@ -1021,7 +1021,7 @@ cifs_init_request_bufs(void)
44262 efficient to alloc 1 per page off the slab compared to 17K (5page)
44263 alloc of large cifs buffers even when page debugging is on */
44264 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44265- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44266+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44267 NULL);
44268 if (cifs_sm_req_cachep == NULL) {
44269 mempool_destroy(cifs_req_poolp);
44270@@ -1106,8 +1106,8 @@ init_cifs(void)
44271 atomic_set(&bufAllocCount, 0);
44272 atomic_set(&smBufAllocCount, 0);
44273 #ifdef CONFIG_CIFS_STATS2
44274- atomic_set(&totBufAllocCount, 0);
44275- atomic_set(&totSmBufAllocCount, 0);
44276+ atomic_set_unchecked(&totBufAllocCount, 0);
44277+ atomic_set_unchecked(&totSmBufAllocCount, 0);
44278 #endif /* CONFIG_CIFS_STATS2 */
44279
44280 atomic_set(&midCount, 0);
44281diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44282index d86ba9f..e80049d 100644
44283--- a/fs/cifs/cifsglob.h
44284+++ b/fs/cifs/cifsglob.h
44285@@ -491,28 +491,28 @@ struct cifs_tcon {
44286 __u16 Flags; /* optional support bits */
44287 enum statusEnum tidStatus;
44288 #ifdef CONFIG_CIFS_STATS
44289- atomic_t num_smbs_sent;
44290- atomic_t num_writes;
44291- atomic_t num_reads;
44292- atomic_t num_flushes;
44293- atomic_t num_oplock_brks;
44294- atomic_t num_opens;
44295- atomic_t num_closes;
44296- atomic_t num_deletes;
44297- atomic_t num_mkdirs;
44298- atomic_t num_posixopens;
44299- atomic_t num_posixmkdirs;
44300- atomic_t num_rmdirs;
44301- atomic_t num_renames;
44302- atomic_t num_t2renames;
44303- atomic_t num_ffirst;
44304- atomic_t num_fnext;
44305- atomic_t num_fclose;
44306- atomic_t num_hardlinks;
44307- atomic_t num_symlinks;
44308- atomic_t num_locks;
44309- atomic_t num_acl_get;
44310- atomic_t num_acl_set;
44311+ atomic_unchecked_t num_smbs_sent;
44312+ atomic_unchecked_t num_writes;
44313+ atomic_unchecked_t num_reads;
44314+ atomic_unchecked_t num_flushes;
44315+ atomic_unchecked_t num_oplock_brks;
44316+ atomic_unchecked_t num_opens;
44317+ atomic_unchecked_t num_closes;
44318+ atomic_unchecked_t num_deletes;
44319+ atomic_unchecked_t num_mkdirs;
44320+ atomic_unchecked_t num_posixopens;
44321+ atomic_unchecked_t num_posixmkdirs;
44322+ atomic_unchecked_t num_rmdirs;
44323+ atomic_unchecked_t num_renames;
44324+ atomic_unchecked_t num_t2renames;
44325+ atomic_unchecked_t num_ffirst;
44326+ atomic_unchecked_t num_fnext;
44327+ atomic_unchecked_t num_fclose;
44328+ atomic_unchecked_t num_hardlinks;
44329+ atomic_unchecked_t num_symlinks;
44330+ atomic_unchecked_t num_locks;
44331+ atomic_unchecked_t num_acl_get;
44332+ atomic_unchecked_t num_acl_set;
44333 #ifdef CONFIG_CIFS_STATS2
44334 unsigned long long time_writes;
44335 unsigned long long time_reads;
44336@@ -735,7 +735,7 @@ convert_delimiter(char *path, char delim)
44337 }
44338
44339 #ifdef CONFIG_CIFS_STATS
44340-#define cifs_stats_inc atomic_inc
44341+#define cifs_stats_inc atomic_inc_unchecked
44342
44343 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44344 unsigned int bytes)
44345@@ -1093,8 +1093,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44346 /* Various Debug counters */
44347 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44348 #ifdef CONFIG_CIFS_STATS2
44349-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44350-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44351+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44352+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44353 #endif
44354 GLOBAL_EXTERN atomic_t smBufAllocCount;
44355 GLOBAL_EXTERN atomic_t midCount;
44356diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44357index 6b0e064..94e6c3c 100644
44358--- a/fs/cifs/link.c
44359+++ b/fs/cifs/link.c
44360@@ -600,7 +600,7 @@ symlink_exit:
44361
44362 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44363 {
44364- char *p = nd_get_link(nd);
44365+ const char *p = nd_get_link(nd);
44366 if (!IS_ERR(p))
44367 kfree(p);
44368 }
44369diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44370index 557506a..2fd3816 100644
44371--- a/fs/cifs/misc.c
44372+++ b/fs/cifs/misc.c
44373@@ -156,7 +156,7 @@ cifs_buf_get(void)
44374 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
44375 atomic_inc(&bufAllocCount);
44376 #ifdef CONFIG_CIFS_STATS2
44377- atomic_inc(&totBufAllocCount);
44378+ atomic_inc_unchecked(&totBufAllocCount);
44379 #endif /* CONFIG_CIFS_STATS2 */
44380 }
44381
44382@@ -191,7 +191,7 @@ cifs_small_buf_get(void)
44383 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44384 atomic_inc(&smBufAllocCount);
44385 #ifdef CONFIG_CIFS_STATS2
44386- atomic_inc(&totSmBufAllocCount);
44387+ atomic_inc_unchecked(&totSmBufAllocCount);
44388 #endif /* CONFIG_CIFS_STATS2 */
44389
44390 }
44391diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44392index 6901578..d402eb5 100644
44393--- a/fs/coda/cache.c
44394+++ b/fs/coda/cache.c
44395@@ -24,7 +24,7 @@
44396 #include "coda_linux.h"
44397 #include "coda_cache.h"
44398
44399-static atomic_t permission_epoch = ATOMIC_INIT(0);
44400+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44401
44402 /* replace or extend an acl cache hit */
44403 void coda_cache_enter(struct inode *inode, int mask)
44404@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44405 struct coda_inode_info *cii = ITOC(inode);
44406
44407 spin_lock(&cii->c_lock);
44408- cii->c_cached_epoch = atomic_read(&permission_epoch);
44409+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44410 if (cii->c_uid != current_fsuid()) {
44411 cii->c_uid = current_fsuid();
44412 cii->c_cached_perm = mask;
44413@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44414 {
44415 struct coda_inode_info *cii = ITOC(inode);
44416 spin_lock(&cii->c_lock);
44417- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44418+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44419 spin_unlock(&cii->c_lock);
44420 }
44421
44422 /* remove all acl caches */
44423 void coda_cache_clear_all(struct super_block *sb)
44424 {
44425- atomic_inc(&permission_epoch);
44426+ atomic_inc_unchecked(&permission_epoch);
44427 }
44428
44429
44430@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44431 spin_lock(&cii->c_lock);
44432 hit = (mask & cii->c_cached_perm) == mask &&
44433 cii->c_uid == current_fsuid() &&
44434- cii->c_cached_epoch == atomic_read(&permission_epoch);
44435+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44436 spin_unlock(&cii->c_lock);
44437
44438 return hit;
44439diff --git a/fs/compat.c b/fs/compat.c
44440index 1bdb350..9f28287 100644
44441--- a/fs/compat.c
44442+++ b/fs/compat.c
44443@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44444
44445 set_fs(KERNEL_DS);
44446 /* The __user pointer cast is valid because of the set_fs() */
44447- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44448+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44449 set_fs(oldfs);
44450 /* truncating is ok because it's a user address */
44451 if (!ret)
44452@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44453 goto out;
44454
44455 ret = -EINVAL;
44456- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44457+ if (nr_segs > UIO_MAXIOV)
44458 goto out;
44459 if (nr_segs > fast_segs) {
44460 ret = -ENOMEM;
44461@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44462
44463 struct compat_readdir_callback {
44464 struct compat_old_linux_dirent __user *dirent;
44465+ struct file * file;
44466 int result;
44467 };
44468
44469@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44470 buf->result = -EOVERFLOW;
44471 return -EOVERFLOW;
44472 }
44473+
44474+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44475+ return 0;
44476+
44477 buf->result++;
44478 dirent = buf->dirent;
44479 if (!access_ok(VERIFY_WRITE, dirent,
44480@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44481
44482 buf.result = 0;
44483 buf.dirent = dirent;
44484+ buf.file = file;
44485
44486 error = vfs_readdir(file, compat_fillonedir, &buf);
44487 if (buf.result)
44488@@ -899,6 +905,7 @@ struct compat_linux_dirent {
44489 struct compat_getdents_callback {
44490 struct compat_linux_dirent __user *current_dir;
44491 struct compat_linux_dirent __user *previous;
44492+ struct file * file;
44493 int count;
44494 int error;
44495 };
44496@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44497 buf->error = -EOVERFLOW;
44498 return -EOVERFLOW;
44499 }
44500+
44501+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44502+ return 0;
44503+
44504 dirent = buf->previous;
44505 if (dirent) {
44506 if (__put_user(offset, &dirent->d_off))
44507@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44508 buf.previous = NULL;
44509 buf.count = count;
44510 buf.error = 0;
44511+ buf.file = file;
44512
44513 error = vfs_readdir(file, compat_filldir, &buf);
44514 if (error >= 0)
44515@@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44516 struct compat_getdents_callback64 {
44517 struct linux_dirent64 __user *current_dir;
44518 struct linux_dirent64 __user *previous;
44519+ struct file * file;
44520 int count;
44521 int error;
44522 };
44523@@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44524 buf->error = -EINVAL; /* only used if we fail.. */
44525 if (reclen > buf->count)
44526 return -EINVAL;
44527+
44528+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44529+ return 0;
44530+
44531 dirent = buf->previous;
44532
44533 if (dirent) {
44534@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44535 buf.previous = NULL;
44536 buf.count = count;
44537 buf.error = 0;
44538+ buf.file = file;
44539
44540 error = vfs_readdir(file, compat_filldir64, &buf);
44541 if (error >= 0)
44542 error = buf.error;
44543 lastdirent = buf.previous;
44544 if (lastdirent) {
44545- typeof(lastdirent->d_off) d_off = file->f_pos;
44546+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44547 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44548 error = -EFAULT;
44549 else
44550diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44551index 112e45a..b59845b 100644
44552--- a/fs/compat_binfmt_elf.c
44553+++ b/fs/compat_binfmt_elf.c
44554@@ -30,11 +30,13 @@
44555 #undef elf_phdr
44556 #undef elf_shdr
44557 #undef elf_note
44558+#undef elf_dyn
44559 #undef elf_addr_t
44560 #define elfhdr elf32_hdr
44561 #define elf_phdr elf32_phdr
44562 #define elf_shdr elf32_shdr
44563 #define elf_note elf32_note
44564+#define elf_dyn Elf32_Dyn
44565 #define elf_addr_t Elf32_Addr
44566
44567 /*
44568diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44569index debdfe0..75d31d4 100644
44570--- a/fs/compat_ioctl.c
44571+++ b/fs/compat_ioctl.c
44572@@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44573
44574 err = get_user(palp, &up->palette);
44575 err |= get_user(length, &up->length);
44576+ if (err)
44577+ return -EFAULT;
44578
44579 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44580 err = put_user(compat_ptr(palp), &up_native->palette);
44581@@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44582 return -EFAULT;
44583 if (__get_user(udata, &ss32->iomem_base))
44584 return -EFAULT;
44585- ss.iomem_base = compat_ptr(udata);
44586+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44587 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44588 __get_user(ss.port_high, &ss32->port_high))
44589 return -EFAULT;
44590@@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44591 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44592 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44593 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44594- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44595+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44596 return -EFAULT;
44597
44598 return ioctl_preallocate(file, p);
44599@@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44600 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44601 {
44602 unsigned int a, b;
44603- a = *(unsigned int *)p;
44604- b = *(unsigned int *)q;
44605+ a = *(const unsigned int *)p;
44606+ b = *(const unsigned int *)q;
44607 if (a > b)
44608 return 1;
44609 if (a < b)
44610diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44611index 7e6c52d..94bc756 100644
44612--- a/fs/configfs/dir.c
44613+++ b/fs/configfs/dir.c
44614@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44615 }
44616 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44617 struct configfs_dirent *next;
44618- const char * name;
44619+ const unsigned char * name;
44620+ char d_name[sizeof(next->s_dentry->d_iname)];
44621 int len;
44622 struct inode *inode = NULL;
44623
44624@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44625 continue;
44626
44627 name = configfs_get_name(next);
44628- len = strlen(name);
44629+ if (next->s_dentry && name == next->s_dentry->d_iname) {
44630+ len = next->s_dentry->d_name.len;
44631+ memcpy(d_name, name, len);
44632+ name = d_name;
44633+ } else
44634+ len = strlen(name);
44635
44636 /*
44637 * We'll have a dentry and an inode for
44638diff --git a/fs/dcache.c b/fs/dcache.c
44639index 9560257..5381f16 100644
44640--- a/fs/dcache.c
44641+++ b/fs/dcache.c
44642@@ -3160,7 +3160,7 @@ void __init vfs_caches_init(unsigned long mempages)
44643 mempages -= reserve;
44644
44645 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44646- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44647+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44648
44649 dcache_init();
44650 inode_init();
44651diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44652index b80bc84..0d46d1a 100644
44653--- a/fs/debugfs/inode.c
44654+++ b/fs/debugfs/inode.c
44655@@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44656 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44657 {
44658 return debugfs_create_file(name,
44659+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44660+ S_IFDIR | S_IRWXU,
44661+#else
44662 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44663+#endif
44664 parent, NULL, NULL);
44665 }
44666 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44667diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44668index 02e2fec..5c47fa2 100644
44669--- a/fs/ecryptfs/inode.c
44670+++ b/fs/ecryptfs/inode.c
44671@@ -676,7 +676,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44672 old_fs = get_fs();
44673 set_fs(get_ds());
44674 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44675- (char __user *)lower_buf,
44676+ (char __force_user *)lower_buf,
44677 PATH_MAX);
44678 set_fs(old_fs);
44679 if (rc < 0)
44680@@ -708,7 +708,7 @@ out:
44681 static void
44682 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44683 {
44684- char *buf = nd_get_link(nd);
44685+ const char *buf = nd_get_link(nd);
44686 if (!IS_ERR(buf)) {
44687 /* Free the char* */
44688 kfree(buf);
44689diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44690index c0038f6..47ab347 100644
44691--- a/fs/ecryptfs/miscdev.c
44692+++ b/fs/ecryptfs/miscdev.c
44693@@ -355,7 +355,7 @@ check_list:
44694 goto out_unlock_msg_ctx;
44695 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44696 if (msg_ctx->msg) {
44697- if (copy_to_user(&buf[i], packet_length, packet_length_size))
44698+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44699 goto out_unlock_msg_ctx;
44700 i += packet_length_size;
44701 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44702diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44703index b2a34a1..162fa69 100644
44704--- a/fs/ecryptfs/read_write.c
44705+++ b/fs/ecryptfs/read_write.c
44706@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44707 return -EIO;
44708 fs_save = get_fs();
44709 set_fs(get_ds());
44710- rc = vfs_write(lower_file, data, size, &offset);
44711+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44712 set_fs(fs_save);
44713 mark_inode_dirty_sync(ecryptfs_inode);
44714 return rc;
44715@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44716 return -EIO;
44717 fs_save = get_fs();
44718 set_fs(get_ds());
44719- rc = vfs_read(lower_file, data, size, &offset);
44720+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44721 set_fs(fs_save);
44722 return rc;
44723 }
44724diff --git a/fs/eventpoll.c b/fs/eventpoll.c
44725index 1c8b556..eedec84 100644
44726--- a/fs/eventpoll.c
44727+++ b/fs/eventpoll.c
44728@@ -1654,8 +1654,8 @@ SYSCALL_DEFINE1(epoll_create1, int, flags)
44729 error = PTR_ERR(file);
44730 goto out_free_fd;
44731 }
44732- fd_install(fd, file);
44733 ep->file = file;
44734+ fd_install(fd, file);
44735 return fd;
44736
44737 out_free_fd:
44738diff --git a/fs/exec.c b/fs/exec.c
44739index e95aeed..a943469 100644
44740--- a/fs/exec.c
44741+++ b/fs/exec.c
44742@@ -55,6 +55,15 @@
44743 #include <linux/pipe_fs_i.h>
44744 #include <linux/oom.h>
44745 #include <linux/compat.h>
44746+#include <linux/random.h>
44747+#include <linux/seq_file.h>
44748+
44749+#ifdef CONFIG_PAX_REFCOUNT
44750+#include <linux/kallsyms.h>
44751+#include <linux/kdebug.h>
44752+#endif
44753+
44754+#include <trace/events/fs.h>
44755
44756 #include <asm/uaccess.h>
44757 #include <asm/mmu_context.h>
44758@@ -66,6 +75,18 @@
44759
44760 #include <trace/events/sched.h>
44761
44762+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44763+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44764+{
44765+ 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");
44766+}
44767+#endif
44768+
44769+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44770+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44771+EXPORT_SYMBOL(pax_set_initial_flags_func);
44772+#endif
44773+
44774 int core_uses_pid;
44775 char core_pattern[CORENAME_MAX_SIZE] = "core";
44776 unsigned int core_pipe_limit;
44777@@ -75,7 +96,7 @@ struct core_name {
44778 char *corename;
44779 int used, size;
44780 };
44781-static atomic_t call_count = ATOMIC_INIT(1);
44782+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44783
44784 /* The maximal length of core_pattern is also specified in sysctl.c */
44785
44786@@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44787 int write)
44788 {
44789 struct page *page;
44790- int ret;
44791
44792-#ifdef CONFIG_STACK_GROWSUP
44793- if (write) {
44794- ret = expand_downwards(bprm->vma, pos);
44795- if (ret < 0)
44796- return NULL;
44797- }
44798-#endif
44799- ret = get_user_pages(current, bprm->mm, pos,
44800- 1, write, 1, &page, NULL);
44801- if (ret <= 0)
44802+ if (0 > expand_downwards(bprm->vma, pos))
44803+ return NULL;
44804+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44805 return NULL;
44806
44807 if (write) {
44808@@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44809 if (size <= ARG_MAX)
44810 return page;
44811
44812+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44813+ // only allow 512KB for argv+env on suid/sgid binaries
44814+ // to prevent easy ASLR exhaustion
44815+ if (((bprm->cred->euid != current_euid()) ||
44816+ (bprm->cred->egid != current_egid())) &&
44817+ (size > (512 * 1024))) {
44818+ put_page(page);
44819+ return NULL;
44820+ }
44821+#endif
44822+
44823 /*
44824 * Limit to 1/4-th the stack size for the argv+env strings.
44825 * This ensures that:
44826@@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44827 vma->vm_end = STACK_TOP_MAX;
44828 vma->vm_start = vma->vm_end - PAGE_SIZE;
44829 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44830+
44831+#ifdef CONFIG_PAX_SEGMEXEC
44832+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44833+#endif
44834+
44835 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44836 INIT_LIST_HEAD(&vma->anon_vma_chain);
44837
44838@@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44839 mm->stack_vm = mm->total_vm = 1;
44840 up_write(&mm->mmap_sem);
44841 bprm->p = vma->vm_end - sizeof(void *);
44842+
44843+#ifdef CONFIG_PAX_RANDUSTACK
44844+ if (randomize_va_space)
44845+ bprm->p ^= random32() & ~PAGE_MASK;
44846+#endif
44847+
44848 return 0;
44849 err:
44850 up_write(&mm->mmap_sem);
44851@@ -395,19 +430,7 @@ err:
44852 return err;
44853 }
44854
44855-struct user_arg_ptr {
44856-#ifdef CONFIG_COMPAT
44857- bool is_compat;
44858-#endif
44859- union {
44860- const char __user *const __user *native;
44861-#ifdef CONFIG_COMPAT
44862- compat_uptr_t __user *compat;
44863-#endif
44864- } ptr;
44865-};
44866-
44867-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44868+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44869 {
44870 const char __user *native;
44871
44872@@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44873 compat_uptr_t compat;
44874
44875 if (get_user(compat, argv.ptr.compat + nr))
44876- return ERR_PTR(-EFAULT);
44877+ return (const char __force_user *)ERR_PTR(-EFAULT);
44878
44879 return compat_ptr(compat);
44880 }
44881 #endif
44882
44883 if (get_user(native, argv.ptr.native + nr))
44884- return ERR_PTR(-EFAULT);
44885+ return (const char __force_user *)ERR_PTR(-EFAULT);
44886
44887 return native;
44888 }
44889@@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44890 if (!p)
44891 break;
44892
44893- if (IS_ERR(p))
44894+ if (IS_ERR((const char __force_kernel *)p))
44895 return -EFAULT;
44896
44897 if (i++ >= max)
44898@@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44899
44900 ret = -EFAULT;
44901 str = get_user_arg_ptr(argv, argc);
44902- if (IS_ERR(str))
44903+ if (IS_ERR((const char __force_kernel *)str))
44904 goto out;
44905
44906 len = strnlen_user(str, MAX_ARG_STRLEN);
44907@@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44908 int r;
44909 mm_segment_t oldfs = get_fs();
44910 struct user_arg_ptr argv = {
44911- .ptr.native = (const char __user *const __user *)__argv,
44912+ .ptr.native = (const char __force_user *const __force_user *)__argv,
44913 };
44914
44915 set_fs(KERNEL_DS);
44916@@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44917 unsigned long new_end = old_end - shift;
44918 struct mmu_gather tlb;
44919
44920- BUG_ON(new_start > new_end);
44921+ if (new_start >= new_end || new_start < mmap_min_addr)
44922+ return -ENOMEM;
44923
44924 /*
44925 * ensure there are no vmas between where we want to go
44926@@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44927 if (vma != find_vma(mm, new_start))
44928 return -EFAULT;
44929
44930+#ifdef CONFIG_PAX_SEGMEXEC
44931+ BUG_ON(pax_find_mirror_vma(vma));
44932+#endif
44933+
44934 /*
44935 * cover the whole range: [new_start, old_end)
44936 */
44937@@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44938 stack_top = arch_align_stack(stack_top);
44939 stack_top = PAGE_ALIGN(stack_top);
44940
44941- if (unlikely(stack_top < mmap_min_addr) ||
44942- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44943- return -ENOMEM;
44944-
44945 stack_shift = vma->vm_end - stack_top;
44946
44947 bprm->p -= stack_shift;
44948@@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44949 bprm->exec -= stack_shift;
44950
44951 down_write(&mm->mmap_sem);
44952+
44953+ /* Move stack pages down in memory. */
44954+ if (stack_shift) {
44955+ ret = shift_arg_pages(vma, stack_shift);
44956+ if (ret)
44957+ goto out_unlock;
44958+ }
44959+
44960 vm_flags = VM_STACK_FLAGS;
44961
44962+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44963+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44964+ vm_flags &= ~VM_EXEC;
44965+
44966+#ifdef CONFIG_PAX_MPROTECT
44967+ if (mm->pax_flags & MF_PAX_MPROTECT)
44968+ vm_flags &= ~VM_MAYEXEC;
44969+#endif
44970+
44971+ }
44972+#endif
44973+
44974 /*
44975 * Adjust stack execute permissions; explicitly enable for
44976 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44977@@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44978 goto out_unlock;
44979 BUG_ON(prev != vma);
44980
44981- /* Move stack pages down in memory. */
44982- if (stack_shift) {
44983- ret = shift_arg_pages(vma, stack_shift);
44984- if (ret)
44985- goto out_unlock;
44986- }
44987-
44988 /* mprotect_fixup is overkill to remove the temporary stack flags */
44989 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44990
44991@@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
44992
44993 fsnotify_open(file);
44994
44995+ trace_open_exec(name);
44996+
44997 err = deny_write_access(file);
44998 if (err)
44999 goto exit;
45000@@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45001 old_fs = get_fs();
45002 set_fs(get_ds());
45003 /* The cast to a user pointer is valid due to the set_fs() */
45004- result = vfs_read(file, (void __user *)addr, count, &pos);
45005+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
45006 set_fs(old_fs);
45007 return result;
45008 }
45009@@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45010 }
45011 rcu_read_unlock();
45012
45013- if (p->fs->users > n_fs) {
45014+ if (atomic_read(&p->fs->users) > n_fs) {
45015 bprm->unsafe |= LSM_UNSAFE_SHARE;
45016 } else {
45017 res = -EAGAIN;
45018@@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45019
45020 EXPORT_SYMBOL(search_binary_handler);
45021
45022+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45023+static DEFINE_PER_CPU(u64, exec_counter);
45024+static int __init init_exec_counters(void)
45025+{
45026+ unsigned int cpu;
45027+
45028+ for_each_possible_cpu(cpu) {
45029+ per_cpu(exec_counter, cpu) = (u64)cpu;
45030+ }
45031+
45032+ return 0;
45033+}
45034+early_initcall(init_exec_counters);
45035+static inline void increment_exec_counter(void)
45036+{
45037+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
45038+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45039+}
45040+#else
45041+static inline void increment_exec_counter(void) {}
45042+#endif
45043+
45044 /*
45045 * sys_execve() executes a new program.
45046 */
45047@@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
45048 struct user_arg_ptr envp,
45049 struct pt_regs *regs)
45050 {
45051+#ifdef CONFIG_GRKERNSEC
45052+ struct file *old_exec_file;
45053+ struct acl_subject_label *old_acl;
45054+ struct rlimit old_rlim[RLIM_NLIMITS];
45055+#endif
45056 struct linux_binprm *bprm;
45057 struct file *file;
45058 struct files_struct *displaced;
45059@@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
45060 int retval;
45061 const struct cred *cred = current_cred();
45062
45063+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45064+
45065 /*
45066 * We move the actual failure in case of RLIMIT_NPROC excess from
45067 * set*uid() to execve() because too many poorly written programs
45068@@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
45069 if (IS_ERR(file))
45070 goto out_unmark;
45071
45072+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
45073+ retval = -EPERM;
45074+ goto out_file;
45075+ }
45076+
45077 sched_exec();
45078
45079 bprm->file = file;
45080 bprm->filename = filename;
45081 bprm->interp = filename;
45082
45083+ if (gr_process_user_ban()) {
45084+ retval = -EPERM;
45085+ goto out_file;
45086+ }
45087+
45088+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45089+ retval = -EACCES;
45090+ goto out_file;
45091+ }
45092+
45093 retval = bprm_mm_init(bprm);
45094 if (retval)
45095 goto out_file;
45096@@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
45097 if (retval < 0)
45098 goto out;
45099
45100+#ifdef CONFIG_GRKERNSEC
45101+ old_acl = current->acl;
45102+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45103+ old_exec_file = current->exec_file;
45104+ get_file(file);
45105+ current->exec_file = file;
45106+#endif
45107+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45108+ /* limit suid stack to 8MB
45109+ we saved the old limits above and will restore them if this exec fails
45110+ */
45111+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45112+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45113+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45114+#endif
45115+
45116+ if (!gr_tpe_allow(file)) {
45117+ retval = -EACCES;
45118+ goto out_fail;
45119+ }
45120+
45121+ if (gr_check_crash_exec(file)) {
45122+ retval = -EACCES;
45123+ goto out_fail;
45124+ }
45125+
45126+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45127+ bprm->unsafe);
45128+ if (retval < 0)
45129+ goto out_fail;
45130+
45131 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45132 if (retval < 0)
45133- goto out;
45134+ goto out_fail;
45135
45136 bprm->exec = bprm->p;
45137 retval = copy_strings(bprm->envc, envp, bprm);
45138 if (retval < 0)
45139- goto out;
45140+ goto out_fail;
45141
45142 retval = copy_strings(bprm->argc, argv, bprm);
45143 if (retval < 0)
45144- goto out;
45145+ goto out_fail;
45146+
45147+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45148+
45149+ gr_handle_exec_args(bprm, argv);
45150
45151 retval = search_binary_handler(bprm,regs);
45152 if (retval < 0)
45153- goto out;
45154+ goto out_fail;
45155+#ifdef CONFIG_GRKERNSEC
45156+ if (old_exec_file)
45157+ fput(old_exec_file);
45158+#endif
45159
45160 /* execve succeeded */
45161+
45162+ increment_exec_counter();
45163 current->fs->in_exec = 0;
45164 current->in_execve = 0;
45165 acct_update_integrals(current);
45166@@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
45167 put_files_struct(displaced);
45168 return retval;
45169
45170+out_fail:
45171+#ifdef CONFIG_GRKERNSEC
45172+ current->acl = old_acl;
45173+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45174+ fput(current->exec_file);
45175+ current->exec_file = old_exec_file;
45176+#endif
45177+
45178 out:
45179 if (bprm->mm) {
45180 acct_arg_size(bprm, 0);
45181@@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
45182 {
45183 char *old_corename = cn->corename;
45184
45185- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45186+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45187 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45188
45189 if (!cn->corename) {
45190@@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
45191 int pid_in_pattern = 0;
45192 int err = 0;
45193
45194- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45195+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45196 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45197 cn->used = 0;
45198
45199@@ -1830,6 +1962,250 @@ out:
45200 return ispipe;
45201 }
45202
45203+int pax_check_flags(unsigned long *flags)
45204+{
45205+ int retval = 0;
45206+
45207+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45208+ if (*flags & MF_PAX_SEGMEXEC)
45209+ {
45210+ *flags &= ~MF_PAX_SEGMEXEC;
45211+ retval = -EINVAL;
45212+ }
45213+#endif
45214+
45215+ if ((*flags & MF_PAX_PAGEEXEC)
45216+
45217+#ifdef CONFIG_PAX_PAGEEXEC
45218+ && (*flags & MF_PAX_SEGMEXEC)
45219+#endif
45220+
45221+ )
45222+ {
45223+ *flags &= ~MF_PAX_PAGEEXEC;
45224+ retval = -EINVAL;
45225+ }
45226+
45227+ if ((*flags & MF_PAX_MPROTECT)
45228+
45229+#ifdef CONFIG_PAX_MPROTECT
45230+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45231+#endif
45232+
45233+ )
45234+ {
45235+ *flags &= ~MF_PAX_MPROTECT;
45236+ retval = -EINVAL;
45237+ }
45238+
45239+ if ((*flags & MF_PAX_EMUTRAMP)
45240+
45241+#ifdef CONFIG_PAX_EMUTRAMP
45242+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45243+#endif
45244+
45245+ )
45246+ {
45247+ *flags &= ~MF_PAX_EMUTRAMP;
45248+ retval = -EINVAL;
45249+ }
45250+
45251+ return retval;
45252+}
45253+
45254+EXPORT_SYMBOL(pax_check_flags);
45255+
45256+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45257+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45258+{
45259+ struct task_struct *tsk = current;
45260+ struct mm_struct *mm = current->mm;
45261+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45262+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45263+ char *path_exec = NULL;
45264+ char *path_fault = NULL;
45265+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
45266+
45267+ if (buffer_exec && buffer_fault) {
45268+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45269+
45270+ down_read(&mm->mmap_sem);
45271+ vma = mm->mmap;
45272+ while (vma && (!vma_exec || !vma_fault)) {
45273+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45274+ vma_exec = vma;
45275+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45276+ vma_fault = vma;
45277+ vma = vma->vm_next;
45278+ }
45279+ if (vma_exec) {
45280+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45281+ if (IS_ERR(path_exec))
45282+ path_exec = "<path too long>";
45283+ else {
45284+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45285+ if (path_exec) {
45286+ *path_exec = 0;
45287+ path_exec = buffer_exec;
45288+ } else
45289+ path_exec = "<path too long>";
45290+ }
45291+ }
45292+ if (vma_fault) {
45293+ start = vma_fault->vm_start;
45294+ end = vma_fault->vm_end;
45295+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45296+ if (vma_fault->vm_file) {
45297+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45298+ if (IS_ERR(path_fault))
45299+ path_fault = "<path too long>";
45300+ else {
45301+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45302+ if (path_fault) {
45303+ *path_fault = 0;
45304+ path_fault = buffer_fault;
45305+ } else
45306+ path_fault = "<path too long>";
45307+ }
45308+ } else
45309+ path_fault = "<anonymous mapping>";
45310+ }
45311+ up_read(&mm->mmap_sem);
45312+ }
45313+ if (tsk->signal->curr_ip)
45314+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45315+ else
45316+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45317+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45318+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45319+ task_uid(tsk), task_euid(tsk), pc, sp);
45320+ free_page((unsigned long)buffer_exec);
45321+ free_page((unsigned long)buffer_fault);
45322+ pax_report_insns(regs, pc, sp);
45323+ do_coredump(SIGKILL, SIGKILL, regs);
45324+}
45325+#endif
45326+
45327+#ifdef CONFIG_PAX_REFCOUNT
45328+void pax_report_refcount_overflow(struct pt_regs *regs)
45329+{
45330+ if (current->signal->curr_ip)
45331+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45332+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45333+ else
45334+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45335+ current->comm, task_pid_nr(current), current_uid(), current_euid());
45336+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45337+ show_regs(regs);
45338+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45339+}
45340+#endif
45341+
45342+#ifdef CONFIG_PAX_USERCOPY
45343+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45344+static noinline int check_stack_object(const void *obj, unsigned long len)
45345+{
45346+ const void * const stack = task_stack_page(current);
45347+ const void * const stackend = stack + THREAD_SIZE;
45348+
45349+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45350+ const void *frame = NULL;
45351+ const void *oldframe;
45352+#endif
45353+
45354+ if (obj + len < obj)
45355+ return -1;
45356+
45357+ if (obj + len <= stack || stackend <= obj)
45358+ return 0;
45359+
45360+ if (obj < stack || stackend < obj + len)
45361+ return -1;
45362+
45363+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45364+ oldframe = __builtin_frame_address(1);
45365+ if (oldframe)
45366+ frame = __builtin_frame_address(2);
45367+ /*
45368+ low ----------------------------------------------> high
45369+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
45370+ ^----------------^
45371+ allow copies only within here
45372+ */
45373+ while (stack <= frame && frame < stackend) {
45374+ /* if obj + len extends past the last frame, this
45375+ check won't pass and the next frame will be 0,
45376+ causing us to bail out and correctly report
45377+ the copy as invalid
45378+ */
45379+ if (obj + len <= frame)
45380+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45381+ oldframe = frame;
45382+ frame = *(const void * const *)frame;
45383+ }
45384+ return -1;
45385+#else
45386+ return 1;
45387+#endif
45388+}
45389+
45390+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45391+{
45392+ if (current->signal->curr_ip)
45393+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45394+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45395+ else
45396+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45397+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45398+ dump_stack();
45399+ gr_handle_kernel_exploit();
45400+ do_group_exit(SIGKILL);
45401+}
45402+#endif
45403+
45404+void check_object_size(const void *ptr, unsigned long n, bool to)
45405+{
45406+
45407+#ifdef CONFIG_PAX_USERCOPY
45408+ const char *type;
45409+
45410+ if (!n)
45411+ return;
45412+
45413+ type = check_heap_object(ptr, n, to);
45414+ if (!type) {
45415+ if (check_stack_object(ptr, n) != -1)
45416+ return;
45417+ type = "<process stack>";
45418+ }
45419+
45420+ pax_report_usercopy(ptr, n, to, type);
45421+#endif
45422+
45423+}
45424+EXPORT_SYMBOL(check_object_size);
45425+
45426+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45427+void pax_track_stack(void)
45428+{
45429+ unsigned long sp = (unsigned long)&sp;
45430+ if (sp < current_thread_info()->lowest_stack &&
45431+ sp > (unsigned long)task_stack_page(current))
45432+ current_thread_info()->lowest_stack = sp;
45433+}
45434+EXPORT_SYMBOL(pax_track_stack);
45435+#endif
45436+
45437+#ifdef CONFIG_PAX_SIZE_OVERFLOW
45438+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45439+{
45440+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45441+ dump_stack();
45442+ do_group_exit(SIGKILL);
45443+}
45444+EXPORT_SYMBOL(report_size_overflow);
45445+#endif
45446+
45447 static int zap_process(struct task_struct *start, int exit_code)
45448 {
45449 struct task_struct *t;
45450@@ -2002,17 +2378,17 @@ static void coredump_finish(struct mm_struct *mm)
45451 void set_dumpable(struct mm_struct *mm, int value)
45452 {
45453 switch (value) {
45454- case 0:
45455+ case SUID_DUMPABLE_DISABLED:
45456 clear_bit(MMF_DUMPABLE, &mm->flags);
45457 smp_wmb();
45458 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
45459 break;
45460- case 1:
45461+ case SUID_DUMPABLE_ENABLED:
45462 set_bit(MMF_DUMPABLE, &mm->flags);
45463 smp_wmb();
45464 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
45465 break;
45466- case 2:
45467+ case SUID_DUMPABLE_SAFE:
45468 set_bit(MMF_DUMP_SECURELY, &mm->flags);
45469 smp_wmb();
45470 set_bit(MMF_DUMPABLE, &mm->flags);
45471@@ -2025,7 +2401,7 @@ static int __get_dumpable(unsigned long mm_flags)
45472 int ret;
45473
45474 ret = mm_flags & MMF_DUMPABLE_MASK;
45475- return (ret >= 2) ? 2 : ret;
45476+ return (ret > SUID_DUMPABLE_ENABLED) ? SUID_DUMPABLE_SAFE : ret;
45477 }
45478
45479 int get_dumpable(struct mm_struct *mm)
45480@@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
45481 pipe = file->f_path.dentry->d_inode->i_pipe;
45482
45483 pipe_lock(pipe);
45484- pipe->readers++;
45485- pipe->writers--;
45486+ atomic_inc(&pipe->readers);
45487+ atomic_dec(&pipe->writers);
45488
45489- while ((pipe->readers > 1) && (!signal_pending(current))) {
45490+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45491 wake_up_interruptible_sync(&pipe->wait);
45492 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45493 pipe_wait(pipe);
45494 }
45495
45496- pipe->readers--;
45497- pipe->writers++;
45498+ atomic_dec(&pipe->readers);
45499+ atomic_inc(&pipe->writers);
45500 pipe_unlock(pipe);
45501
45502 }
45503@@ -2111,7 +2487,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45504 int retval = 0;
45505 int flag = 0;
45506 int ispipe;
45507- static atomic_t core_dump_count = ATOMIC_INIT(0);
45508+ bool need_nonrelative = false;
45509+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45510 struct coredump_params cprm = {
45511 .signr = signr,
45512 .regs = regs,
45513@@ -2126,6 +2503,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45514
45515 audit_core_dumps(signr);
45516
45517+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45518+ gr_handle_brute_attach(current, cprm.mm_flags);
45519+
45520 binfmt = mm->binfmt;
45521 if (!binfmt || !binfmt->core_dump)
45522 goto fail;
45523@@ -2136,14 +2516,16 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45524 if (!cred)
45525 goto fail;
45526 /*
45527- * We cannot trust fsuid as being the "true" uid of the
45528- * process nor do we know its entire history. We only know it
45529- * was tainted so we dump it as root in mode 2.
45530+ * We cannot trust fsuid as being the "true" uid of the process
45531+ * nor do we know its entire history. We only know it was tainted
45532+ * so we dump it as root in mode 2, and only into a controlled
45533+ * environment (pipe handler or fully qualified path).
45534 */
45535- if (__get_dumpable(cprm.mm_flags) == 2) {
45536+ if (__get_dumpable(cprm.mm_flags) == SUID_DUMPABLE_SAFE) {
45537 /* Setuid core dump mode */
45538 flag = O_EXCL; /* Stop rewrite attacks */
45539 cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
45540+ need_nonrelative = true;
45541 }
45542
45543 retval = coredump_wait(exit_code, &core_state);
45544@@ -2193,7 +2575,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45545 }
45546 cprm.limit = RLIM_INFINITY;
45547
45548- dump_count = atomic_inc_return(&core_dump_count);
45549+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
45550 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45551 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45552 task_tgid_vnr(current), current->comm);
45553@@ -2220,9 +2602,19 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45554 } else {
45555 struct inode *inode;
45556
45557+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45558+
45559 if (cprm.limit < binfmt->min_coredump)
45560 goto fail_unlock;
45561
45562+ if (need_nonrelative && cn.corename[0] != '/') {
45563+ printk(KERN_WARNING "Pid %d(%s) can only dump core "\
45564+ "to fully qualified path!\n",
45565+ task_tgid_vnr(current), current->comm);
45566+ printk(KERN_WARNING "Skipping core dump\n");
45567+ goto fail_unlock;
45568+ }
45569+
45570 cprm.file = filp_open(cn.corename,
45571 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
45572 0600);
45573@@ -2263,7 +2655,7 @@ close_fail:
45574 filp_close(cprm.file, NULL);
45575 fail_dropcount:
45576 if (ispipe)
45577- atomic_dec(&core_dump_count);
45578+ atomic_dec_unchecked(&core_dump_count);
45579 fail_unlock:
45580 kfree(cn.corename);
45581 fail_corename:
45582@@ -2282,7 +2674,7 @@ fail:
45583 */
45584 int dump_write(struct file *file, const void *addr, int nr)
45585 {
45586- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45587+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45588 }
45589 EXPORT_SYMBOL(dump_write);
45590
45591diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45592index 1c36139..cf6b350 100644
45593--- a/fs/ext2/balloc.c
45594+++ b/fs/ext2/balloc.c
45595@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45596
45597 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45598 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45599- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45600+ if (free_blocks < root_blocks + 1 &&
45601 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45602 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45603- !in_group_p (sbi->s_resgid))) {
45604+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45605 return 0;
45606 }
45607 return 1;
45608diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45609index 25cd608..9ed5294 100644
45610--- a/fs/ext3/balloc.c
45611+++ b/fs/ext3/balloc.c
45612@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45613
45614 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45615 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45616- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45617+ if (free_blocks < root_blocks + 1 &&
45618 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45619 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45620- !in_group_p (sbi->s_resgid))) {
45621+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45622 return 0;
45623 }
45624 return 1;
45625diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45626index 1b50890..e56c5ad 100644
45627--- a/fs/ext4/balloc.c
45628+++ b/fs/ext4/balloc.c
45629@@ -500,8 +500,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45630 /* Hm, nope. Are (enough) root reserved clusters available? */
45631 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45632 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45633- capable(CAP_SYS_RESOURCE) ||
45634- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45635+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45636+ capable_nolog(CAP_SYS_RESOURCE)) {
45637
45638 if (free_clusters >= (nclusters + dirty_clusters))
45639 return 1;
45640diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45641index 01434f2..bd995b4 100644
45642--- a/fs/ext4/ext4.h
45643+++ b/fs/ext4/ext4.h
45644@@ -1246,19 +1246,19 @@ struct ext4_sb_info {
45645 unsigned long s_mb_last_start;
45646
45647 /* stats for buddy allocator */
45648- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45649- atomic_t s_bal_success; /* we found long enough chunks */
45650- atomic_t s_bal_allocated; /* in blocks */
45651- atomic_t s_bal_ex_scanned; /* total extents scanned */
45652- atomic_t s_bal_goals; /* goal hits */
45653- atomic_t s_bal_breaks; /* too long searches */
45654- atomic_t s_bal_2orders; /* 2^order hits */
45655+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45656+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45657+ atomic_unchecked_t s_bal_allocated; /* in blocks */
45658+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45659+ atomic_unchecked_t s_bal_goals; /* goal hits */
45660+ atomic_unchecked_t s_bal_breaks; /* too long searches */
45661+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45662 spinlock_t s_bal_lock;
45663 unsigned long s_mb_buddies_generated;
45664 unsigned long long s_mb_generation_time;
45665- atomic_t s_mb_lost_chunks;
45666- atomic_t s_mb_preallocated;
45667- atomic_t s_mb_discarded;
45668+ atomic_unchecked_t s_mb_lost_chunks;
45669+ atomic_unchecked_t s_mb_preallocated;
45670+ atomic_unchecked_t s_mb_discarded;
45671 atomic_t s_lock_busy;
45672
45673 /* locality groups */
45674diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45675index 1cd6994..5799d45 100644
45676--- a/fs/ext4/mballoc.c
45677+++ b/fs/ext4/mballoc.c
45678@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45679 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45680
45681 if (EXT4_SB(sb)->s_mb_stats)
45682- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45683+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45684
45685 break;
45686 }
45687@@ -2041,7 +2041,7 @@ repeat:
45688 ac->ac_status = AC_STATUS_CONTINUE;
45689 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45690 cr = 3;
45691- atomic_inc(&sbi->s_mb_lost_chunks);
45692+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45693 goto repeat;
45694 }
45695 }
45696@@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
45697 if (sbi->s_mb_stats) {
45698 ext4_msg(sb, KERN_INFO,
45699 "mballoc: %u blocks %u reqs (%u success)",
45700- atomic_read(&sbi->s_bal_allocated),
45701- atomic_read(&sbi->s_bal_reqs),
45702- atomic_read(&sbi->s_bal_success));
45703+ atomic_read_unchecked(&sbi->s_bal_allocated),
45704+ atomic_read_unchecked(&sbi->s_bal_reqs),
45705+ atomic_read_unchecked(&sbi->s_bal_success));
45706 ext4_msg(sb, KERN_INFO,
45707 "mballoc: %u extents scanned, %u goal hits, "
45708 "%u 2^N hits, %u breaks, %u lost",
45709- atomic_read(&sbi->s_bal_ex_scanned),
45710- atomic_read(&sbi->s_bal_goals),
45711- atomic_read(&sbi->s_bal_2orders),
45712- atomic_read(&sbi->s_bal_breaks),
45713- atomic_read(&sbi->s_mb_lost_chunks));
45714+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45715+ atomic_read_unchecked(&sbi->s_bal_goals),
45716+ atomic_read_unchecked(&sbi->s_bal_2orders),
45717+ atomic_read_unchecked(&sbi->s_bal_breaks),
45718+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45719 ext4_msg(sb, KERN_INFO,
45720 "mballoc: %lu generated and it took %Lu",
45721 sbi->s_mb_buddies_generated,
45722 sbi->s_mb_generation_time);
45723 ext4_msg(sb, KERN_INFO,
45724 "mballoc: %u preallocated, %u discarded",
45725- atomic_read(&sbi->s_mb_preallocated),
45726- atomic_read(&sbi->s_mb_discarded));
45727+ atomic_read_unchecked(&sbi->s_mb_preallocated),
45728+ atomic_read_unchecked(&sbi->s_mb_discarded));
45729 }
45730
45731 free_percpu(sbi->s_locality_groups);
45732@@ -3047,16 +3047,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45733 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45734
45735 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45736- atomic_inc(&sbi->s_bal_reqs);
45737- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45738+ atomic_inc_unchecked(&sbi->s_bal_reqs);
45739+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45740 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45741- atomic_inc(&sbi->s_bal_success);
45742- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45743+ atomic_inc_unchecked(&sbi->s_bal_success);
45744+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45745 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45746 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45747- atomic_inc(&sbi->s_bal_goals);
45748+ atomic_inc_unchecked(&sbi->s_bal_goals);
45749 if (ac->ac_found > sbi->s_mb_max_to_scan)
45750- atomic_inc(&sbi->s_bal_breaks);
45751+ atomic_inc_unchecked(&sbi->s_bal_breaks);
45752 }
45753
45754 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45755@@ -3456,7 +3456,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45756 trace_ext4_mb_new_inode_pa(ac, pa);
45757
45758 ext4_mb_use_inode_pa(ac, pa);
45759- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45760+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45761
45762 ei = EXT4_I(ac->ac_inode);
45763 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45764@@ -3516,7 +3516,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45765 trace_ext4_mb_new_group_pa(ac, pa);
45766
45767 ext4_mb_use_group_pa(ac, pa);
45768- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45769+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45770
45771 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45772 lg = ac->ac_lg;
45773@@ -3605,7 +3605,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45774 * from the bitmap and continue.
45775 */
45776 }
45777- atomic_add(free, &sbi->s_mb_discarded);
45778+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
45779
45780 return err;
45781 }
45782@@ -3623,7 +3623,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45783 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45784 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45785 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45786- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45787+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45788 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45789
45790 return 0;
45791diff --git a/fs/fcntl.c b/fs/fcntl.c
45792index 81b70e6..d9ae6cf 100644
45793--- a/fs/fcntl.c
45794+++ b/fs/fcntl.c
45795@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45796 if (err)
45797 return err;
45798
45799+ if (gr_handle_chroot_fowner(pid, type))
45800+ return -ENOENT;
45801+ if (gr_check_protected_task_fowner(pid, type))
45802+ return -EACCES;
45803+
45804 f_modown(filp, pid, type, force);
45805 return 0;
45806 }
45807@@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45808
45809 static int f_setown_ex(struct file *filp, unsigned long arg)
45810 {
45811- struct f_owner_ex * __user owner_p = (void * __user)arg;
45812+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45813 struct f_owner_ex owner;
45814 struct pid *pid;
45815 int type;
45816@@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45817
45818 static int f_getown_ex(struct file *filp, unsigned long arg)
45819 {
45820- struct f_owner_ex * __user owner_p = (void * __user)arg;
45821+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45822 struct f_owner_ex owner;
45823 int ret = 0;
45824
45825@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45826 switch (cmd) {
45827 case F_DUPFD:
45828 case F_DUPFD_CLOEXEC:
45829+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45830 if (arg >= rlimit(RLIMIT_NOFILE))
45831 break;
45832 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45833diff --git a/fs/fifo.c b/fs/fifo.c
45834index cf6f434..3d7942c 100644
45835--- a/fs/fifo.c
45836+++ b/fs/fifo.c
45837@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45838 */
45839 filp->f_op = &read_pipefifo_fops;
45840 pipe->r_counter++;
45841- if (pipe->readers++ == 0)
45842+ if (atomic_inc_return(&pipe->readers) == 1)
45843 wake_up_partner(inode);
45844
45845- if (!pipe->writers) {
45846+ if (!atomic_read(&pipe->writers)) {
45847 if ((filp->f_flags & O_NONBLOCK)) {
45848 /* suppress POLLHUP until we have
45849 * seen a writer */
45850@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45851 * errno=ENXIO when there is no process reading the FIFO.
45852 */
45853 ret = -ENXIO;
45854- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45855+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45856 goto err;
45857
45858 filp->f_op = &write_pipefifo_fops;
45859 pipe->w_counter++;
45860- if (!pipe->writers++)
45861+ if (atomic_inc_return(&pipe->writers) == 1)
45862 wake_up_partner(inode);
45863
45864- if (!pipe->readers) {
45865+ if (!atomic_read(&pipe->readers)) {
45866 if (wait_for_partner(inode, &pipe->r_counter))
45867 goto err_wr;
45868 }
45869@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45870 */
45871 filp->f_op = &rdwr_pipefifo_fops;
45872
45873- pipe->readers++;
45874- pipe->writers++;
45875+ atomic_inc(&pipe->readers);
45876+ atomic_inc(&pipe->writers);
45877 pipe->r_counter++;
45878 pipe->w_counter++;
45879- if (pipe->readers == 1 || pipe->writers == 1)
45880+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45881 wake_up_partner(inode);
45882 break;
45883
45884@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45885 return 0;
45886
45887 err_rd:
45888- if (!--pipe->readers)
45889+ if (atomic_dec_and_test(&pipe->readers))
45890 wake_up_interruptible(&pipe->wait);
45891 ret = -ERESTARTSYS;
45892 goto err;
45893
45894 err_wr:
45895- if (!--pipe->writers)
45896+ if (atomic_dec_and_test(&pipe->writers))
45897 wake_up_interruptible(&pipe->wait);
45898 ret = -ERESTARTSYS;
45899 goto err;
45900
45901 err:
45902- if (!pipe->readers && !pipe->writers)
45903+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45904 free_pipe_info(inode);
45905
45906 err_nocleanup:
45907diff --git a/fs/file.c b/fs/file.c
45908index ba3f605..fade102 100644
45909--- a/fs/file.c
45910+++ b/fs/file.c
45911@@ -15,6 +15,7 @@
45912 #include <linux/slab.h>
45913 #include <linux/vmalloc.h>
45914 #include <linux/file.h>
45915+#include <linux/security.h>
45916 #include <linux/fdtable.h>
45917 #include <linux/bitops.h>
45918 #include <linux/interrupt.h>
45919@@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45920 * N.B. For clone tasks sharing a files structure, this test
45921 * will limit the total number of files that can be opened.
45922 */
45923+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45924 if (nr >= rlimit(RLIMIT_NOFILE))
45925 return -EMFILE;
45926
45927diff --git a/fs/filesystems.c b/fs/filesystems.c
45928index 96f2428..f5eeb8e 100644
45929--- a/fs/filesystems.c
45930+++ b/fs/filesystems.c
45931@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45932 int len = dot ? dot - name : strlen(name);
45933
45934 fs = __get_fs_type(name, len);
45935+
45936+#ifdef CONFIG_GRKERNSEC_MODHARDEN
45937+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45938+#else
45939 if (!fs && (request_module("%.*s", len, name) == 0))
45940+#endif
45941 fs = __get_fs_type(name, len);
45942
45943 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45944diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45945index e159e68..e7d2a6f 100644
45946--- a/fs/fs_struct.c
45947+++ b/fs/fs_struct.c
45948@@ -4,6 +4,7 @@
45949 #include <linux/path.h>
45950 #include <linux/slab.h>
45951 #include <linux/fs_struct.h>
45952+#include <linux/grsecurity.h>
45953 #include "internal.h"
45954
45955 static inline void path_get_longterm(struct path *path)
45956@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45957 write_seqcount_begin(&fs->seq);
45958 old_root = fs->root;
45959 fs->root = *path;
45960+ gr_set_chroot_entries(current, path);
45961 write_seqcount_end(&fs->seq);
45962 spin_unlock(&fs->lock);
45963 if (old_root.dentry)
45964@@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45965 return 1;
45966 }
45967
45968+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45969+{
45970+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45971+ return 0;
45972+ *p = *new;
45973+
45974+ gr_set_chroot_entries(task, new);
45975+
45976+ return 1;
45977+}
45978+
45979 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45980 {
45981 struct task_struct *g, *p;
45982@@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45983 int hits = 0;
45984 spin_lock(&fs->lock);
45985 write_seqcount_begin(&fs->seq);
45986- hits += replace_path(&fs->root, old_root, new_root);
45987+ hits += replace_root_path(p, &fs->root, old_root, new_root);
45988 hits += replace_path(&fs->pwd, old_root, new_root);
45989 write_seqcount_end(&fs->seq);
45990 while (hits--) {
45991@@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
45992 task_lock(tsk);
45993 spin_lock(&fs->lock);
45994 tsk->fs = NULL;
45995- kill = !--fs->users;
45996+ gr_clear_chroot_entries(tsk);
45997+ kill = !atomic_dec_return(&fs->users);
45998 spin_unlock(&fs->lock);
45999 task_unlock(tsk);
46000 if (kill)
46001@@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46002 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46003 /* We don't need to lock fs - think why ;-) */
46004 if (fs) {
46005- fs->users = 1;
46006+ atomic_set(&fs->users, 1);
46007 fs->in_exec = 0;
46008 spin_lock_init(&fs->lock);
46009 seqcount_init(&fs->seq);
46010@@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46011 spin_lock(&old->lock);
46012 fs->root = old->root;
46013 path_get_longterm(&fs->root);
46014+ /* instead of calling gr_set_chroot_entries here,
46015+ we call it from every caller of this function
46016+ */
46017 fs->pwd = old->pwd;
46018 path_get_longterm(&fs->pwd);
46019 spin_unlock(&old->lock);
46020@@ -151,8 +168,9 @@ int unshare_fs_struct(void)
46021
46022 task_lock(current);
46023 spin_lock(&fs->lock);
46024- kill = !--fs->users;
46025+ kill = !atomic_dec_return(&fs->users);
46026 current->fs = new_fs;
46027+ gr_set_chroot_entries(current, &new_fs->root);
46028 spin_unlock(&fs->lock);
46029 task_unlock(current);
46030
46031@@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46032
46033 int current_umask(void)
46034 {
46035- return current->fs->umask;
46036+ return current->fs->umask | gr_acl_umask();
46037 }
46038 EXPORT_SYMBOL(current_umask);
46039
46040 /* to be mentioned only in INIT_TASK */
46041 struct fs_struct init_fs = {
46042- .users = 1,
46043+ .users = ATOMIC_INIT(1),
46044 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46045 .seq = SEQCNT_ZERO,
46046 .umask = 0022,
46047@@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
46048 task_lock(current);
46049
46050 spin_lock(&init_fs.lock);
46051- init_fs.users++;
46052+ atomic_inc(&init_fs.users);
46053 spin_unlock(&init_fs.lock);
46054
46055 spin_lock(&fs->lock);
46056 current->fs = &init_fs;
46057- kill = !--fs->users;
46058+ gr_set_chroot_entries(current, &current->fs->root);
46059+ kill = !atomic_dec_return(&fs->users);
46060 spin_unlock(&fs->lock);
46061
46062 task_unlock(current);
46063diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46064index 9905350..02eaec4 100644
46065--- a/fs/fscache/cookie.c
46066+++ b/fs/fscache/cookie.c
46067@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46068 parent ? (char *) parent->def->name : "<no-parent>",
46069 def->name, netfs_data);
46070
46071- fscache_stat(&fscache_n_acquires);
46072+ fscache_stat_unchecked(&fscache_n_acquires);
46073
46074 /* if there's no parent cookie, then we don't create one here either */
46075 if (!parent) {
46076- fscache_stat(&fscache_n_acquires_null);
46077+ fscache_stat_unchecked(&fscache_n_acquires_null);
46078 _leave(" [no parent]");
46079 return NULL;
46080 }
46081@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46082 /* allocate and initialise a cookie */
46083 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46084 if (!cookie) {
46085- fscache_stat(&fscache_n_acquires_oom);
46086+ fscache_stat_unchecked(&fscache_n_acquires_oom);
46087 _leave(" [ENOMEM]");
46088 return NULL;
46089 }
46090@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46091
46092 switch (cookie->def->type) {
46093 case FSCACHE_COOKIE_TYPE_INDEX:
46094- fscache_stat(&fscache_n_cookie_index);
46095+ fscache_stat_unchecked(&fscache_n_cookie_index);
46096 break;
46097 case FSCACHE_COOKIE_TYPE_DATAFILE:
46098- fscache_stat(&fscache_n_cookie_data);
46099+ fscache_stat_unchecked(&fscache_n_cookie_data);
46100 break;
46101 default:
46102- fscache_stat(&fscache_n_cookie_special);
46103+ fscache_stat_unchecked(&fscache_n_cookie_special);
46104 break;
46105 }
46106
46107@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46108 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46109 atomic_dec(&parent->n_children);
46110 __fscache_cookie_put(cookie);
46111- fscache_stat(&fscache_n_acquires_nobufs);
46112+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46113 _leave(" = NULL");
46114 return NULL;
46115 }
46116 }
46117
46118- fscache_stat(&fscache_n_acquires_ok);
46119+ fscache_stat_unchecked(&fscache_n_acquires_ok);
46120 _leave(" = %p", cookie);
46121 return cookie;
46122 }
46123@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46124 cache = fscache_select_cache_for_object(cookie->parent);
46125 if (!cache) {
46126 up_read(&fscache_addremove_sem);
46127- fscache_stat(&fscache_n_acquires_no_cache);
46128+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46129 _leave(" = -ENOMEDIUM [no cache]");
46130 return -ENOMEDIUM;
46131 }
46132@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46133 object = cache->ops->alloc_object(cache, cookie);
46134 fscache_stat_d(&fscache_n_cop_alloc_object);
46135 if (IS_ERR(object)) {
46136- fscache_stat(&fscache_n_object_no_alloc);
46137+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
46138 ret = PTR_ERR(object);
46139 goto error;
46140 }
46141
46142- fscache_stat(&fscache_n_object_alloc);
46143+ fscache_stat_unchecked(&fscache_n_object_alloc);
46144
46145 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46146
46147@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46148 struct fscache_object *object;
46149 struct hlist_node *_p;
46150
46151- fscache_stat(&fscache_n_updates);
46152+ fscache_stat_unchecked(&fscache_n_updates);
46153
46154 if (!cookie) {
46155- fscache_stat(&fscache_n_updates_null);
46156+ fscache_stat_unchecked(&fscache_n_updates_null);
46157 _leave(" [no cookie]");
46158 return;
46159 }
46160@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46161 struct fscache_object *object;
46162 unsigned long event;
46163
46164- fscache_stat(&fscache_n_relinquishes);
46165+ fscache_stat_unchecked(&fscache_n_relinquishes);
46166 if (retire)
46167- fscache_stat(&fscache_n_relinquishes_retire);
46168+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46169
46170 if (!cookie) {
46171- fscache_stat(&fscache_n_relinquishes_null);
46172+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
46173 _leave(" [no cookie]");
46174 return;
46175 }
46176@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46177
46178 /* wait for the cookie to finish being instantiated (or to fail) */
46179 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46180- fscache_stat(&fscache_n_relinquishes_waitcrt);
46181+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46182 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46183 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46184 }
46185diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46186index f6aad48..88dcf26 100644
46187--- a/fs/fscache/internal.h
46188+++ b/fs/fscache/internal.h
46189@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46190 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46191 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46192
46193-extern atomic_t fscache_n_op_pend;
46194-extern atomic_t fscache_n_op_run;
46195-extern atomic_t fscache_n_op_enqueue;
46196-extern atomic_t fscache_n_op_deferred_release;
46197-extern atomic_t fscache_n_op_release;
46198-extern atomic_t fscache_n_op_gc;
46199-extern atomic_t fscache_n_op_cancelled;
46200-extern atomic_t fscache_n_op_rejected;
46201+extern atomic_unchecked_t fscache_n_op_pend;
46202+extern atomic_unchecked_t fscache_n_op_run;
46203+extern atomic_unchecked_t fscache_n_op_enqueue;
46204+extern atomic_unchecked_t fscache_n_op_deferred_release;
46205+extern atomic_unchecked_t fscache_n_op_release;
46206+extern atomic_unchecked_t fscache_n_op_gc;
46207+extern atomic_unchecked_t fscache_n_op_cancelled;
46208+extern atomic_unchecked_t fscache_n_op_rejected;
46209
46210-extern atomic_t fscache_n_attr_changed;
46211-extern atomic_t fscache_n_attr_changed_ok;
46212-extern atomic_t fscache_n_attr_changed_nobufs;
46213-extern atomic_t fscache_n_attr_changed_nomem;
46214-extern atomic_t fscache_n_attr_changed_calls;
46215+extern atomic_unchecked_t fscache_n_attr_changed;
46216+extern atomic_unchecked_t fscache_n_attr_changed_ok;
46217+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46218+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46219+extern atomic_unchecked_t fscache_n_attr_changed_calls;
46220
46221-extern atomic_t fscache_n_allocs;
46222-extern atomic_t fscache_n_allocs_ok;
46223-extern atomic_t fscache_n_allocs_wait;
46224-extern atomic_t fscache_n_allocs_nobufs;
46225-extern atomic_t fscache_n_allocs_intr;
46226-extern atomic_t fscache_n_allocs_object_dead;
46227-extern atomic_t fscache_n_alloc_ops;
46228-extern atomic_t fscache_n_alloc_op_waits;
46229+extern atomic_unchecked_t fscache_n_allocs;
46230+extern atomic_unchecked_t fscache_n_allocs_ok;
46231+extern atomic_unchecked_t fscache_n_allocs_wait;
46232+extern atomic_unchecked_t fscache_n_allocs_nobufs;
46233+extern atomic_unchecked_t fscache_n_allocs_intr;
46234+extern atomic_unchecked_t fscache_n_allocs_object_dead;
46235+extern atomic_unchecked_t fscache_n_alloc_ops;
46236+extern atomic_unchecked_t fscache_n_alloc_op_waits;
46237
46238-extern atomic_t fscache_n_retrievals;
46239-extern atomic_t fscache_n_retrievals_ok;
46240-extern atomic_t fscache_n_retrievals_wait;
46241-extern atomic_t fscache_n_retrievals_nodata;
46242-extern atomic_t fscache_n_retrievals_nobufs;
46243-extern atomic_t fscache_n_retrievals_intr;
46244-extern atomic_t fscache_n_retrievals_nomem;
46245-extern atomic_t fscache_n_retrievals_object_dead;
46246-extern atomic_t fscache_n_retrieval_ops;
46247-extern atomic_t fscache_n_retrieval_op_waits;
46248+extern atomic_unchecked_t fscache_n_retrievals;
46249+extern atomic_unchecked_t fscache_n_retrievals_ok;
46250+extern atomic_unchecked_t fscache_n_retrievals_wait;
46251+extern atomic_unchecked_t fscache_n_retrievals_nodata;
46252+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46253+extern atomic_unchecked_t fscache_n_retrievals_intr;
46254+extern atomic_unchecked_t fscache_n_retrievals_nomem;
46255+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46256+extern atomic_unchecked_t fscache_n_retrieval_ops;
46257+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46258
46259-extern atomic_t fscache_n_stores;
46260-extern atomic_t fscache_n_stores_ok;
46261-extern atomic_t fscache_n_stores_again;
46262-extern atomic_t fscache_n_stores_nobufs;
46263-extern atomic_t fscache_n_stores_oom;
46264-extern atomic_t fscache_n_store_ops;
46265-extern atomic_t fscache_n_store_calls;
46266-extern atomic_t fscache_n_store_pages;
46267-extern atomic_t fscache_n_store_radix_deletes;
46268-extern atomic_t fscache_n_store_pages_over_limit;
46269+extern atomic_unchecked_t fscache_n_stores;
46270+extern atomic_unchecked_t fscache_n_stores_ok;
46271+extern atomic_unchecked_t fscache_n_stores_again;
46272+extern atomic_unchecked_t fscache_n_stores_nobufs;
46273+extern atomic_unchecked_t fscache_n_stores_oom;
46274+extern atomic_unchecked_t fscache_n_store_ops;
46275+extern atomic_unchecked_t fscache_n_store_calls;
46276+extern atomic_unchecked_t fscache_n_store_pages;
46277+extern atomic_unchecked_t fscache_n_store_radix_deletes;
46278+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46279
46280-extern atomic_t fscache_n_store_vmscan_not_storing;
46281-extern atomic_t fscache_n_store_vmscan_gone;
46282-extern atomic_t fscache_n_store_vmscan_busy;
46283-extern atomic_t fscache_n_store_vmscan_cancelled;
46284+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46285+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46286+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46287+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46288
46289-extern atomic_t fscache_n_marks;
46290-extern atomic_t fscache_n_uncaches;
46291+extern atomic_unchecked_t fscache_n_marks;
46292+extern atomic_unchecked_t fscache_n_uncaches;
46293
46294-extern atomic_t fscache_n_acquires;
46295-extern atomic_t fscache_n_acquires_null;
46296-extern atomic_t fscache_n_acquires_no_cache;
46297-extern atomic_t fscache_n_acquires_ok;
46298-extern atomic_t fscache_n_acquires_nobufs;
46299-extern atomic_t fscache_n_acquires_oom;
46300+extern atomic_unchecked_t fscache_n_acquires;
46301+extern atomic_unchecked_t fscache_n_acquires_null;
46302+extern atomic_unchecked_t fscache_n_acquires_no_cache;
46303+extern atomic_unchecked_t fscache_n_acquires_ok;
46304+extern atomic_unchecked_t fscache_n_acquires_nobufs;
46305+extern atomic_unchecked_t fscache_n_acquires_oom;
46306
46307-extern atomic_t fscache_n_updates;
46308-extern atomic_t fscache_n_updates_null;
46309-extern atomic_t fscache_n_updates_run;
46310+extern atomic_unchecked_t fscache_n_updates;
46311+extern atomic_unchecked_t fscache_n_updates_null;
46312+extern atomic_unchecked_t fscache_n_updates_run;
46313
46314-extern atomic_t fscache_n_relinquishes;
46315-extern atomic_t fscache_n_relinquishes_null;
46316-extern atomic_t fscache_n_relinquishes_waitcrt;
46317-extern atomic_t fscache_n_relinquishes_retire;
46318+extern atomic_unchecked_t fscache_n_relinquishes;
46319+extern atomic_unchecked_t fscache_n_relinquishes_null;
46320+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46321+extern atomic_unchecked_t fscache_n_relinquishes_retire;
46322
46323-extern atomic_t fscache_n_cookie_index;
46324-extern atomic_t fscache_n_cookie_data;
46325-extern atomic_t fscache_n_cookie_special;
46326+extern atomic_unchecked_t fscache_n_cookie_index;
46327+extern atomic_unchecked_t fscache_n_cookie_data;
46328+extern atomic_unchecked_t fscache_n_cookie_special;
46329
46330-extern atomic_t fscache_n_object_alloc;
46331-extern atomic_t fscache_n_object_no_alloc;
46332-extern atomic_t fscache_n_object_lookups;
46333-extern atomic_t fscache_n_object_lookups_negative;
46334-extern atomic_t fscache_n_object_lookups_positive;
46335-extern atomic_t fscache_n_object_lookups_timed_out;
46336-extern atomic_t fscache_n_object_created;
46337-extern atomic_t fscache_n_object_avail;
46338-extern atomic_t fscache_n_object_dead;
46339+extern atomic_unchecked_t fscache_n_object_alloc;
46340+extern atomic_unchecked_t fscache_n_object_no_alloc;
46341+extern atomic_unchecked_t fscache_n_object_lookups;
46342+extern atomic_unchecked_t fscache_n_object_lookups_negative;
46343+extern atomic_unchecked_t fscache_n_object_lookups_positive;
46344+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46345+extern atomic_unchecked_t fscache_n_object_created;
46346+extern atomic_unchecked_t fscache_n_object_avail;
46347+extern atomic_unchecked_t fscache_n_object_dead;
46348
46349-extern atomic_t fscache_n_checkaux_none;
46350-extern atomic_t fscache_n_checkaux_okay;
46351-extern atomic_t fscache_n_checkaux_update;
46352-extern atomic_t fscache_n_checkaux_obsolete;
46353+extern atomic_unchecked_t fscache_n_checkaux_none;
46354+extern atomic_unchecked_t fscache_n_checkaux_okay;
46355+extern atomic_unchecked_t fscache_n_checkaux_update;
46356+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46357
46358 extern atomic_t fscache_n_cop_alloc_object;
46359 extern atomic_t fscache_n_cop_lookup_object;
46360@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46361 atomic_inc(stat);
46362 }
46363
46364+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46365+{
46366+ atomic_inc_unchecked(stat);
46367+}
46368+
46369 static inline void fscache_stat_d(atomic_t *stat)
46370 {
46371 atomic_dec(stat);
46372@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46373
46374 #define __fscache_stat(stat) (NULL)
46375 #define fscache_stat(stat) do {} while (0)
46376+#define fscache_stat_unchecked(stat) do {} while (0)
46377 #define fscache_stat_d(stat) do {} while (0)
46378 #endif
46379
46380diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46381index b6b897c..0ffff9c 100644
46382--- a/fs/fscache/object.c
46383+++ b/fs/fscache/object.c
46384@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46385 /* update the object metadata on disk */
46386 case FSCACHE_OBJECT_UPDATING:
46387 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46388- fscache_stat(&fscache_n_updates_run);
46389+ fscache_stat_unchecked(&fscache_n_updates_run);
46390 fscache_stat(&fscache_n_cop_update_object);
46391 object->cache->ops->update_object(object);
46392 fscache_stat_d(&fscache_n_cop_update_object);
46393@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46394 spin_lock(&object->lock);
46395 object->state = FSCACHE_OBJECT_DEAD;
46396 spin_unlock(&object->lock);
46397- fscache_stat(&fscache_n_object_dead);
46398+ fscache_stat_unchecked(&fscache_n_object_dead);
46399 goto terminal_transit;
46400
46401 /* handle the parent cache of this object being withdrawn from
46402@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46403 spin_lock(&object->lock);
46404 object->state = FSCACHE_OBJECT_DEAD;
46405 spin_unlock(&object->lock);
46406- fscache_stat(&fscache_n_object_dead);
46407+ fscache_stat_unchecked(&fscache_n_object_dead);
46408 goto terminal_transit;
46409
46410 /* complain about the object being woken up once it is
46411@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46412 parent->cookie->def->name, cookie->def->name,
46413 object->cache->tag->name);
46414
46415- fscache_stat(&fscache_n_object_lookups);
46416+ fscache_stat_unchecked(&fscache_n_object_lookups);
46417 fscache_stat(&fscache_n_cop_lookup_object);
46418 ret = object->cache->ops->lookup_object(object);
46419 fscache_stat_d(&fscache_n_cop_lookup_object);
46420@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46421 if (ret == -ETIMEDOUT) {
46422 /* probably stuck behind another object, so move this one to
46423 * the back of the queue */
46424- fscache_stat(&fscache_n_object_lookups_timed_out);
46425+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46426 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46427 }
46428
46429@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46430
46431 spin_lock(&object->lock);
46432 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46433- fscache_stat(&fscache_n_object_lookups_negative);
46434+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46435
46436 /* transit here to allow write requests to begin stacking up
46437 * and read requests to begin returning ENODATA */
46438@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46439 * result, in which case there may be data available */
46440 spin_lock(&object->lock);
46441 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46442- fscache_stat(&fscache_n_object_lookups_positive);
46443+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46444
46445 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46446
46447@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46448 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46449 } else {
46450 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46451- fscache_stat(&fscache_n_object_created);
46452+ fscache_stat_unchecked(&fscache_n_object_created);
46453
46454 object->state = FSCACHE_OBJECT_AVAILABLE;
46455 spin_unlock(&object->lock);
46456@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46457 fscache_enqueue_dependents(object);
46458
46459 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46460- fscache_stat(&fscache_n_object_avail);
46461+ fscache_stat_unchecked(&fscache_n_object_avail);
46462
46463 _leave("");
46464 }
46465@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46466 enum fscache_checkaux result;
46467
46468 if (!object->cookie->def->check_aux) {
46469- fscache_stat(&fscache_n_checkaux_none);
46470+ fscache_stat_unchecked(&fscache_n_checkaux_none);
46471 return FSCACHE_CHECKAUX_OKAY;
46472 }
46473
46474@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46475 switch (result) {
46476 /* entry okay as is */
46477 case FSCACHE_CHECKAUX_OKAY:
46478- fscache_stat(&fscache_n_checkaux_okay);
46479+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
46480 break;
46481
46482 /* entry requires update */
46483 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46484- fscache_stat(&fscache_n_checkaux_update);
46485+ fscache_stat_unchecked(&fscache_n_checkaux_update);
46486 break;
46487
46488 /* entry requires deletion */
46489 case FSCACHE_CHECKAUX_OBSOLETE:
46490- fscache_stat(&fscache_n_checkaux_obsolete);
46491+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46492 break;
46493
46494 default:
46495diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46496index 30afdfa..2256596 100644
46497--- a/fs/fscache/operation.c
46498+++ b/fs/fscache/operation.c
46499@@ -17,7 +17,7 @@
46500 #include <linux/slab.h>
46501 #include "internal.h"
46502
46503-atomic_t fscache_op_debug_id;
46504+atomic_unchecked_t fscache_op_debug_id;
46505 EXPORT_SYMBOL(fscache_op_debug_id);
46506
46507 /**
46508@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46509 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46510 ASSERTCMP(atomic_read(&op->usage), >, 0);
46511
46512- fscache_stat(&fscache_n_op_enqueue);
46513+ fscache_stat_unchecked(&fscache_n_op_enqueue);
46514 switch (op->flags & FSCACHE_OP_TYPE) {
46515 case FSCACHE_OP_ASYNC:
46516 _debug("queue async");
46517@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46518 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46519 if (op->processor)
46520 fscache_enqueue_operation(op);
46521- fscache_stat(&fscache_n_op_run);
46522+ fscache_stat_unchecked(&fscache_n_op_run);
46523 }
46524
46525 /*
46526@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46527 if (object->n_ops > 1) {
46528 atomic_inc(&op->usage);
46529 list_add_tail(&op->pend_link, &object->pending_ops);
46530- fscache_stat(&fscache_n_op_pend);
46531+ fscache_stat_unchecked(&fscache_n_op_pend);
46532 } else if (!list_empty(&object->pending_ops)) {
46533 atomic_inc(&op->usage);
46534 list_add_tail(&op->pend_link, &object->pending_ops);
46535- fscache_stat(&fscache_n_op_pend);
46536+ fscache_stat_unchecked(&fscache_n_op_pend);
46537 fscache_start_operations(object);
46538 } else {
46539 ASSERTCMP(object->n_in_progress, ==, 0);
46540@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46541 object->n_exclusive++; /* reads and writes must wait */
46542 atomic_inc(&op->usage);
46543 list_add_tail(&op->pend_link, &object->pending_ops);
46544- fscache_stat(&fscache_n_op_pend);
46545+ fscache_stat_unchecked(&fscache_n_op_pend);
46546 ret = 0;
46547 } else {
46548 /* not allowed to submit ops in any other state */
46549@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46550 if (object->n_exclusive > 0) {
46551 atomic_inc(&op->usage);
46552 list_add_tail(&op->pend_link, &object->pending_ops);
46553- fscache_stat(&fscache_n_op_pend);
46554+ fscache_stat_unchecked(&fscache_n_op_pend);
46555 } else if (!list_empty(&object->pending_ops)) {
46556 atomic_inc(&op->usage);
46557 list_add_tail(&op->pend_link, &object->pending_ops);
46558- fscache_stat(&fscache_n_op_pend);
46559+ fscache_stat_unchecked(&fscache_n_op_pend);
46560 fscache_start_operations(object);
46561 } else {
46562 ASSERTCMP(object->n_exclusive, ==, 0);
46563@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46564 object->n_ops++;
46565 atomic_inc(&op->usage);
46566 list_add_tail(&op->pend_link, &object->pending_ops);
46567- fscache_stat(&fscache_n_op_pend);
46568+ fscache_stat_unchecked(&fscache_n_op_pend);
46569 ret = 0;
46570 } else if (object->state == FSCACHE_OBJECT_DYING ||
46571 object->state == FSCACHE_OBJECT_LC_DYING ||
46572 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46573- fscache_stat(&fscache_n_op_rejected);
46574+ fscache_stat_unchecked(&fscache_n_op_rejected);
46575 ret = -ENOBUFS;
46576 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46577 fscache_report_unexpected_submission(object, op, ostate);
46578@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46579
46580 ret = -EBUSY;
46581 if (!list_empty(&op->pend_link)) {
46582- fscache_stat(&fscache_n_op_cancelled);
46583+ fscache_stat_unchecked(&fscache_n_op_cancelled);
46584 list_del_init(&op->pend_link);
46585 object->n_ops--;
46586 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46587@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46588 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46589 BUG();
46590
46591- fscache_stat(&fscache_n_op_release);
46592+ fscache_stat_unchecked(&fscache_n_op_release);
46593
46594 if (op->release) {
46595 op->release(op);
46596@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46597 * lock, and defer it otherwise */
46598 if (!spin_trylock(&object->lock)) {
46599 _debug("defer put");
46600- fscache_stat(&fscache_n_op_deferred_release);
46601+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
46602
46603 cache = object->cache;
46604 spin_lock(&cache->op_gc_list_lock);
46605@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46606
46607 _debug("GC DEFERRED REL OBJ%x OP%x",
46608 object->debug_id, op->debug_id);
46609- fscache_stat(&fscache_n_op_gc);
46610+ fscache_stat_unchecked(&fscache_n_op_gc);
46611
46612 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46613
46614diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46615index 3f7a59b..cf196cc 100644
46616--- a/fs/fscache/page.c
46617+++ b/fs/fscache/page.c
46618@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46619 val = radix_tree_lookup(&cookie->stores, page->index);
46620 if (!val) {
46621 rcu_read_unlock();
46622- fscache_stat(&fscache_n_store_vmscan_not_storing);
46623+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46624 __fscache_uncache_page(cookie, page);
46625 return true;
46626 }
46627@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46628 spin_unlock(&cookie->stores_lock);
46629
46630 if (xpage) {
46631- fscache_stat(&fscache_n_store_vmscan_cancelled);
46632- fscache_stat(&fscache_n_store_radix_deletes);
46633+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46634+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46635 ASSERTCMP(xpage, ==, page);
46636 } else {
46637- fscache_stat(&fscache_n_store_vmscan_gone);
46638+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46639 }
46640
46641 wake_up_bit(&cookie->flags, 0);
46642@@ -107,7 +107,7 @@ page_busy:
46643 /* we might want to wait here, but that could deadlock the allocator as
46644 * the work threads writing to the cache may all end up sleeping
46645 * on memory allocation */
46646- fscache_stat(&fscache_n_store_vmscan_busy);
46647+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46648 return false;
46649 }
46650 EXPORT_SYMBOL(__fscache_maybe_release_page);
46651@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46652 FSCACHE_COOKIE_STORING_TAG);
46653 if (!radix_tree_tag_get(&cookie->stores, page->index,
46654 FSCACHE_COOKIE_PENDING_TAG)) {
46655- fscache_stat(&fscache_n_store_radix_deletes);
46656+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46657 xpage = radix_tree_delete(&cookie->stores, page->index);
46658 }
46659 spin_unlock(&cookie->stores_lock);
46660@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46661
46662 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46663
46664- fscache_stat(&fscache_n_attr_changed_calls);
46665+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46666
46667 if (fscache_object_is_active(object)) {
46668 fscache_stat(&fscache_n_cop_attr_changed);
46669@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46670
46671 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46672
46673- fscache_stat(&fscache_n_attr_changed);
46674+ fscache_stat_unchecked(&fscache_n_attr_changed);
46675
46676 op = kzalloc(sizeof(*op), GFP_KERNEL);
46677 if (!op) {
46678- fscache_stat(&fscache_n_attr_changed_nomem);
46679+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46680 _leave(" = -ENOMEM");
46681 return -ENOMEM;
46682 }
46683@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46684 if (fscache_submit_exclusive_op(object, op) < 0)
46685 goto nobufs;
46686 spin_unlock(&cookie->lock);
46687- fscache_stat(&fscache_n_attr_changed_ok);
46688+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46689 fscache_put_operation(op);
46690 _leave(" = 0");
46691 return 0;
46692@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46693 nobufs:
46694 spin_unlock(&cookie->lock);
46695 kfree(op);
46696- fscache_stat(&fscache_n_attr_changed_nobufs);
46697+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46698 _leave(" = %d", -ENOBUFS);
46699 return -ENOBUFS;
46700 }
46701@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46702 /* allocate a retrieval operation and attempt to submit it */
46703 op = kzalloc(sizeof(*op), GFP_NOIO);
46704 if (!op) {
46705- fscache_stat(&fscache_n_retrievals_nomem);
46706+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46707 return NULL;
46708 }
46709
46710@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46711 return 0;
46712 }
46713
46714- fscache_stat(&fscache_n_retrievals_wait);
46715+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
46716
46717 jif = jiffies;
46718 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46719 fscache_wait_bit_interruptible,
46720 TASK_INTERRUPTIBLE) != 0) {
46721- fscache_stat(&fscache_n_retrievals_intr);
46722+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46723 _leave(" = -ERESTARTSYS");
46724 return -ERESTARTSYS;
46725 }
46726@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46727 */
46728 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46729 struct fscache_retrieval *op,
46730- atomic_t *stat_op_waits,
46731- atomic_t *stat_object_dead)
46732+ atomic_unchecked_t *stat_op_waits,
46733+ atomic_unchecked_t *stat_object_dead)
46734 {
46735 int ret;
46736
46737@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46738 goto check_if_dead;
46739
46740 _debug(">>> WT");
46741- fscache_stat(stat_op_waits);
46742+ fscache_stat_unchecked(stat_op_waits);
46743 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46744 fscache_wait_bit_interruptible,
46745 TASK_INTERRUPTIBLE) < 0) {
46746@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46747
46748 check_if_dead:
46749 if (unlikely(fscache_object_is_dead(object))) {
46750- fscache_stat(stat_object_dead);
46751+ fscache_stat_unchecked(stat_object_dead);
46752 return -ENOBUFS;
46753 }
46754 return 0;
46755@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46756
46757 _enter("%p,%p,,,", cookie, page);
46758
46759- fscache_stat(&fscache_n_retrievals);
46760+ fscache_stat_unchecked(&fscache_n_retrievals);
46761
46762 if (hlist_empty(&cookie->backing_objects))
46763 goto nobufs;
46764@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46765 goto nobufs_unlock;
46766 spin_unlock(&cookie->lock);
46767
46768- fscache_stat(&fscache_n_retrieval_ops);
46769+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46770
46771 /* pin the netfs read context in case we need to do the actual netfs
46772 * read because we've encountered a cache read failure */
46773@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46774
46775 error:
46776 if (ret == -ENOMEM)
46777- fscache_stat(&fscache_n_retrievals_nomem);
46778+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46779 else if (ret == -ERESTARTSYS)
46780- fscache_stat(&fscache_n_retrievals_intr);
46781+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46782 else if (ret == -ENODATA)
46783- fscache_stat(&fscache_n_retrievals_nodata);
46784+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46785 else if (ret < 0)
46786- fscache_stat(&fscache_n_retrievals_nobufs);
46787+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46788 else
46789- fscache_stat(&fscache_n_retrievals_ok);
46790+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46791
46792 fscache_put_retrieval(op);
46793 _leave(" = %d", ret);
46794@@ -429,7 +429,7 @@ nobufs_unlock:
46795 spin_unlock(&cookie->lock);
46796 kfree(op);
46797 nobufs:
46798- fscache_stat(&fscache_n_retrievals_nobufs);
46799+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46800 _leave(" = -ENOBUFS");
46801 return -ENOBUFS;
46802 }
46803@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46804
46805 _enter("%p,,%d,,,", cookie, *nr_pages);
46806
46807- fscache_stat(&fscache_n_retrievals);
46808+ fscache_stat_unchecked(&fscache_n_retrievals);
46809
46810 if (hlist_empty(&cookie->backing_objects))
46811 goto nobufs;
46812@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46813 goto nobufs_unlock;
46814 spin_unlock(&cookie->lock);
46815
46816- fscache_stat(&fscache_n_retrieval_ops);
46817+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46818
46819 /* pin the netfs read context in case we need to do the actual netfs
46820 * read because we've encountered a cache read failure */
46821@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46822
46823 error:
46824 if (ret == -ENOMEM)
46825- fscache_stat(&fscache_n_retrievals_nomem);
46826+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46827 else if (ret == -ERESTARTSYS)
46828- fscache_stat(&fscache_n_retrievals_intr);
46829+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46830 else if (ret == -ENODATA)
46831- fscache_stat(&fscache_n_retrievals_nodata);
46832+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46833 else if (ret < 0)
46834- fscache_stat(&fscache_n_retrievals_nobufs);
46835+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46836 else
46837- fscache_stat(&fscache_n_retrievals_ok);
46838+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46839
46840 fscache_put_retrieval(op);
46841 _leave(" = %d", ret);
46842@@ -545,7 +545,7 @@ nobufs_unlock:
46843 spin_unlock(&cookie->lock);
46844 kfree(op);
46845 nobufs:
46846- fscache_stat(&fscache_n_retrievals_nobufs);
46847+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46848 _leave(" = -ENOBUFS");
46849 return -ENOBUFS;
46850 }
46851@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46852
46853 _enter("%p,%p,,,", cookie, page);
46854
46855- fscache_stat(&fscache_n_allocs);
46856+ fscache_stat_unchecked(&fscache_n_allocs);
46857
46858 if (hlist_empty(&cookie->backing_objects))
46859 goto nobufs;
46860@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46861 goto nobufs_unlock;
46862 spin_unlock(&cookie->lock);
46863
46864- fscache_stat(&fscache_n_alloc_ops);
46865+ fscache_stat_unchecked(&fscache_n_alloc_ops);
46866
46867 ret = fscache_wait_for_retrieval_activation(
46868 object, op,
46869@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46870
46871 error:
46872 if (ret == -ERESTARTSYS)
46873- fscache_stat(&fscache_n_allocs_intr);
46874+ fscache_stat_unchecked(&fscache_n_allocs_intr);
46875 else if (ret < 0)
46876- fscache_stat(&fscache_n_allocs_nobufs);
46877+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46878 else
46879- fscache_stat(&fscache_n_allocs_ok);
46880+ fscache_stat_unchecked(&fscache_n_allocs_ok);
46881
46882 fscache_put_retrieval(op);
46883 _leave(" = %d", ret);
46884@@ -625,7 +625,7 @@ nobufs_unlock:
46885 spin_unlock(&cookie->lock);
46886 kfree(op);
46887 nobufs:
46888- fscache_stat(&fscache_n_allocs_nobufs);
46889+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46890 _leave(" = -ENOBUFS");
46891 return -ENOBUFS;
46892 }
46893@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46894
46895 spin_lock(&cookie->stores_lock);
46896
46897- fscache_stat(&fscache_n_store_calls);
46898+ fscache_stat_unchecked(&fscache_n_store_calls);
46899
46900 /* find a page to store */
46901 page = NULL;
46902@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46903 page = results[0];
46904 _debug("gang %d [%lx]", n, page->index);
46905 if (page->index > op->store_limit) {
46906- fscache_stat(&fscache_n_store_pages_over_limit);
46907+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46908 goto superseded;
46909 }
46910
46911@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46912 spin_unlock(&cookie->stores_lock);
46913 spin_unlock(&object->lock);
46914
46915- fscache_stat(&fscache_n_store_pages);
46916+ fscache_stat_unchecked(&fscache_n_store_pages);
46917 fscache_stat(&fscache_n_cop_write_page);
46918 ret = object->cache->ops->write_page(op, page);
46919 fscache_stat_d(&fscache_n_cop_write_page);
46920@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46921 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46922 ASSERT(PageFsCache(page));
46923
46924- fscache_stat(&fscache_n_stores);
46925+ fscache_stat_unchecked(&fscache_n_stores);
46926
46927 op = kzalloc(sizeof(*op), GFP_NOIO);
46928 if (!op)
46929@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46930 spin_unlock(&cookie->stores_lock);
46931 spin_unlock(&object->lock);
46932
46933- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46934+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46935 op->store_limit = object->store_limit;
46936
46937 if (fscache_submit_op(object, &op->op) < 0)
46938@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46939
46940 spin_unlock(&cookie->lock);
46941 radix_tree_preload_end();
46942- fscache_stat(&fscache_n_store_ops);
46943- fscache_stat(&fscache_n_stores_ok);
46944+ fscache_stat_unchecked(&fscache_n_store_ops);
46945+ fscache_stat_unchecked(&fscache_n_stores_ok);
46946
46947 /* the work queue now carries its own ref on the object */
46948 fscache_put_operation(&op->op);
46949@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46950 return 0;
46951
46952 already_queued:
46953- fscache_stat(&fscache_n_stores_again);
46954+ fscache_stat_unchecked(&fscache_n_stores_again);
46955 already_pending:
46956 spin_unlock(&cookie->stores_lock);
46957 spin_unlock(&object->lock);
46958 spin_unlock(&cookie->lock);
46959 radix_tree_preload_end();
46960 kfree(op);
46961- fscache_stat(&fscache_n_stores_ok);
46962+ fscache_stat_unchecked(&fscache_n_stores_ok);
46963 _leave(" = 0");
46964 return 0;
46965
46966@@ -851,14 +851,14 @@ nobufs:
46967 spin_unlock(&cookie->lock);
46968 radix_tree_preload_end();
46969 kfree(op);
46970- fscache_stat(&fscache_n_stores_nobufs);
46971+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
46972 _leave(" = -ENOBUFS");
46973 return -ENOBUFS;
46974
46975 nomem_free:
46976 kfree(op);
46977 nomem:
46978- fscache_stat(&fscache_n_stores_oom);
46979+ fscache_stat_unchecked(&fscache_n_stores_oom);
46980 _leave(" = -ENOMEM");
46981 return -ENOMEM;
46982 }
46983@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46984 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46985 ASSERTCMP(page, !=, NULL);
46986
46987- fscache_stat(&fscache_n_uncaches);
46988+ fscache_stat_unchecked(&fscache_n_uncaches);
46989
46990 /* cache withdrawal may beat us to it */
46991 if (!PageFsCache(page))
46992@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46993 unsigned long loop;
46994
46995 #ifdef CONFIG_FSCACHE_STATS
46996- atomic_add(pagevec->nr, &fscache_n_marks);
46997+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46998 #endif
46999
47000 for (loop = 0; loop < pagevec->nr; loop++) {
47001diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47002index 4765190..2a067f2 100644
47003--- a/fs/fscache/stats.c
47004+++ b/fs/fscache/stats.c
47005@@ -18,95 +18,95 @@
47006 /*
47007 * operation counters
47008 */
47009-atomic_t fscache_n_op_pend;
47010-atomic_t fscache_n_op_run;
47011-atomic_t fscache_n_op_enqueue;
47012-atomic_t fscache_n_op_requeue;
47013-atomic_t fscache_n_op_deferred_release;
47014-atomic_t fscache_n_op_release;
47015-atomic_t fscache_n_op_gc;
47016-atomic_t fscache_n_op_cancelled;
47017-atomic_t fscache_n_op_rejected;
47018+atomic_unchecked_t fscache_n_op_pend;
47019+atomic_unchecked_t fscache_n_op_run;
47020+atomic_unchecked_t fscache_n_op_enqueue;
47021+atomic_unchecked_t fscache_n_op_requeue;
47022+atomic_unchecked_t fscache_n_op_deferred_release;
47023+atomic_unchecked_t fscache_n_op_release;
47024+atomic_unchecked_t fscache_n_op_gc;
47025+atomic_unchecked_t fscache_n_op_cancelled;
47026+atomic_unchecked_t fscache_n_op_rejected;
47027
47028-atomic_t fscache_n_attr_changed;
47029-atomic_t fscache_n_attr_changed_ok;
47030-atomic_t fscache_n_attr_changed_nobufs;
47031-atomic_t fscache_n_attr_changed_nomem;
47032-atomic_t fscache_n_attr_changed_calls;
47033+atomic_unchecked_t fscache_n_attr_changed;
47034+atomic_unchecked_t fscache_n_attr_changed_ok;
47035+atomic_unchecked_t fscache_n_attr_changed_nobufs;
47036+atomic_unchecked_t fscache_n_attr_changed_nomem;
47037+atomic_unchecked_t fscache_n_attr_changed_calls;
47038
47039-atomic_t fscache_n_allocs;
47040-atomic_t fscache_n_allocs_ok;
47041-atomic_t fscache_n_allocs_wait;
47042-atomic_t fscache_n_allocs_nobufs;
47043-atomic_t fscache_n_allocs_intr;
47044-atomic_t fscache_n_allocs_object_dead;
47045-atomic_t fscache_n_alloc_ops;
47046-atomic_t fscache_n_alloc_op_waits;
47047+atomic_unchecked_t fscache_n_allocs;
47048+atomic_unchecked_t fscache_n_allocs_ok;
47049+atomic_unchecked_t fscache_n_allocs_wait;
47050+atomic_unchecked_t fscache_n_allocs_nobufs;
47051+atomic_unchecked_t fscache_n_allocs_intr;
47052+atomic_unchecked_t fscache_n_allocs_object_dead;
47053+atomic_unchecked_t fscache_n_alloc_ops;
47054+atomic_unchecked_t fscache_n_alloc_op_waits;
47055
47056-atomic_t fscache_n_retrievals;
47057-atomic_t fscache_n_retrievals_ok;
47058-atomic_t fscache_n_retrievals_wait;
47059-atomic_t fscache_n_retrievals_nodata;
47060-atomic_t fscache_n_retrievals_nobufs;
47061-atomic_t fscache_n_retrievals_intr;
47062-atomic_t fscache_n_retrievals_nomem;
47063-atomic_t fscache_n_retrievals_object_dead;
47064-atomic_t fscache_n_retrieval_ops;
47065-atomic_t fscache_n_retrieval_op_waits;
47066+atomic_unchecked_t fscache_n_retrievals;
47067+atomic_unchecked_t fscache_n_retrievals_ok;
47068+atomic_unchecked_t fscache_n_retrievals_wait;
47069+atomic_unchecked_t fscache_n_retrievals_nodata;
47070+atomic_unchecked_t fscache_n_retrievals_nobufs;
47071+atomic_unchecked_t fscache_n_retrievals_intr;
47072+atomic_unchecked_t fscache_n_retrievals_nomem;
47073+atomic_unchecked_t fscache_n_retrievals_object_dead;
47074+atomic_unchecked_t fscache_n_retrieval_ops;
47075+atomic_unchecked_t fscache_n_retrieval_op_waits;
47076
47077-atomic_t fscache_n_stores;
47078-atomic_t fscache_n_stores_ok;
47079-atomic_t fscache_n_stores_again;
47080-atomic_t fscache_n_stores_nobufs;
47081-atomic_t fscache_n_stores_oom;
47082-atomic_t fscache_n_store_ops;
47083-atomic_t fscache_n_store_calls;
47084-atomic_t fscache_n_store_pages;
47085-atomic_t fscache_n_store_radix_deletes;
47086-atomic_t fscache_n_store_pages_over_limit;
47087+atomic_unchecked_t fscache_n_stores;
47088+atomic_unchecked_t fscache_n_stores_ok;
47089+atomic_unchecked_t fscache_n_stores_again;
47090+atomic_unchecked_t fscache_n_stores_nobufs;
47091+atomic_unchecked_t fscache_n_stores_oom;
47092+atomic_unchecked_t fscache_n_store_ops;
47093+atomic_unchecked_t fscache_n_store_calls;
47094+atomic_unchecked_t fscache_n_store_pages;
47095+atomic_unchecked_t fscache_n_store_radix_deletes;
47096+atomic_unchecked_t fscache_n_store_pages_over_limit;
47097
47098-atomic_t fscache_n_store_vmscan_not_storing;
47099-atomic_t fscache_n_store_vmscan_gone;
47100-atomic_t fscache_n_store_vmscan_busy;
47101-atomic_t fscache_n_store_vmscan_cancelled;
47102+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47103+atomic_unchecked_t fscache_n_store_vmscan_gone;
47104+atomic_unchecked_t fscache_n_store_vmscan_busy;
47105+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47106
47107-atomic_t fscache_n_marks;
47108-atomic_t fscache_n_uncaches;
47109+atomic_unchecked_t fscache_n_marks;
47110+atomic_unchecked_t fscache_n_uncaches;
47111
47112-atomic_t fscache_n_acquires;
47113-atomic_t fscache_n_acquires_null;
47114-atomic_t fscache_n_acquires_no_cache;
47115-atomic_t fscache_n_acquires_ok;
47116-atomic_t fscache_n_acquires_nobufs;
47117-atomic_t fscache_n_acquires_oom;
47118+atomic_unchecked_t fscache_n_acquires;
47119+atomic_unchecked_t fscache_n_acquires_null;
47120+atomic_unchecked_t fscache_n_acquires_no_cache;
47121+atomic_unchecked_t fscache_n_acquires_ok;
47122+atomic_unchecked_t fscache_n_acquires_nobufs;
47123+atomic_unchecked_t fscache_n_acquires_oom;
47124
47125-atomic_t fscache_n_updates;
47126-atomic_t fscache_n_updates_null;
47127-atomic_t fscache_n_updates_run;
47128+atomic_unchecked_t fscache_n_updates;
47129+atomic_unchecked_t fscache_n_updates_null;
47130+atomic_unchecked_t fscache_n_updates_run;
47131
47132-atomic_t fscache_n_relinquishes;
47133-atomic_t fscache_n_relinquishes_null;
47134-atomic_t fscache_n_relinquishes_waitcrt;
47135-atomic_t fscache_n_relinquishes_retire;
47136+atomic_unchecked_t fscache_n_relinquishes;
47137+atomic_unchecked_t fscache_n_relinquishes_null;
47138+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47139+atomic_unchecked_t fscache_n_relinquishes_retire;
47140
47141-atomic_t fscache_n_cookie_index;
47142-atomic_t fscache_n_cookie_data;
47143-atomic_t fscache_n_cookie_special;
47144+atomic_unchecked_t fscache_n_cookie_index;
47145+atomic_unchecked_t fscache_n_cookie_data;
47146+atomic_unchecked_t fscache_n_cookie_special;
47147
47148-atomic_t fscache_n_object_alloc;
47149-atomic_t fscache_n_object_no_alloc;
47150-atomic_t fscache_n_object_lookups;
47151-atomic_t fscache_n_object_lookups_negative;
47152-atomic_t fscache_n_object_lookups_positive;
47153-atomic_t fscache_n_object_lookups_timed_out;
47154-atomic_t fscache_n_object_created;
47155-atomic_t fscache_n_object_avail;
47156-atomic_t fscache_n_object_dead;
47157+atomic_unchecked_t fscache_n_object_alloc;
47158+atomic_unchecked_t fscache_n_object_no_alloc;
47159+atomic_unchecked_t fscache_n_object_lookups;
47160+atomic_unchecked_t fscache_n_object_lookups_negative;
47161+atomic_unchecked_t fscache_n_object_lookups_positive;
47162+atomic_unchecked_t fscache_n_object_lookups_timed_out;
47163+atomic_unchecked_t fscache_n_object_created;
47164+atomic_unchecked_t fscache_n_object_avail;
47165+atomic_unchecked_t fscache_n_object_dead;
47166
47167-atomic_t fscache_n_checkaux_none;
47168-atomic_t fscache_n_checkaux_okay;
47169-atomic_t fscache_n_checkaux_update;
47170-atomic_t fscache_n_checkaux_obsolete;
47171+atomic_unchecked_t fscache_n_checkaux_none;
47172+atomic_unchecked_t fscache_n_checkaux_okay;
47173+atomic_unchecked_t fscache_n_checkaux_update;
47174+atomic_unchecked_t fscache_n_checkaux_obsolete;
47175
47176 atomic_t fscache_n_cop_alloc_object;
47177 atomic_t fscache_n_cop_lookup_object;
47178@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47179 seq_puts(m, "FS-Cache statistics\n");
47180
47181 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47182- atomic_read(&fscache_n_cookie_index),
47183- atomic_read(&fscache_n_cookie_data),
47184- atomic_read(&fscache_n_cookie_special));
47185+ atomic_read_unchecked(&fscache_n_cookie_index),
47186+ atomic_read_unchecked(&fscache_n_cookie_data),
47187+ atomic_read_unchecked(&fscache_n_cookie_special));
47188
47189 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47190- atomic_read(&fscache_n_object_alloc),
47191- atomic_read(&fscache_n_object_no_alloc),
47192- atomic_read(&fscache_n_object_avail),
47193- atomic_read(&fscache_n_object_dead));
47194+ atomic_read_unchecked(&fscache_n_object_alloc),
47195+ atomic_read_unchecked(&fscache_n_object_no_alloc),
47196+ atomic_read_unchecked(&fscache_n_object_avail),
47197+ atomic_read_unchecked(&fscache_n_object_dead));
47198 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47199- atomic_read(&fscache_n_checkaux_none),
47200- atomic_read(&fscache_n_checkaux_okay),
47201- atomic_read(&fscache_n_checkaux_update),
47202- atomic_read(&fscache_n_checkaux_obsolete));
47203+ atomic_read_unchecked(&fscache_n_checkaux_none),
47204+ atomic_read_unchecked(&fscache_n_checkaux_okay),
47205+ atomic_read_unchecked(&fscache_n_checkaux_update),
47206+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47207
47208 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47209- atomic_read(&fscache_n_marks),
47210- atomic_read(&fscache_n_uncaches));
47211+ atomic_read_unchecked(&fscache_n_marks),
47212+ atomic_read_unchecked(&fscache_n_uncaches));
47213
47214 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47215 " oom=%u\n",
47216- atomic_read(&fscache_n_acquires),
47217- atomic_read(&fscache_n_acquires_null),
47218- atomic_read(&fscache_n_acquires_no_cache),
47219- atomic_read(&fscache_n_acquires_ok),
47220- atomic_read(&fscache_n_acquires_nobufs),
47221- atomic_read(&fscache_n_acquires_oom));
47222+ atomic_read_unchecked(&fscache_n_acquires),
47223+ atomic_read_unchecked(&fscache_n_acquires_null),
47224+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
47225+ atomic_read_unchecked(&fscache_n_acquires_ok),
47226+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
47227+ atomic_read_unchecked(&fscache_n_acquires_oom));
47228
47229 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47230- atomic_read(&fscache_n_object_lookups),
47231- atomic_read(&fscache_n_object_lookups_negative),
47232- atomic_read(&fscache_n_object_lookups_positive),
47233- atomic_read(&fscache_n_object_created),
47234- atomic_read(&fscache_n_object_lookups_timed_out));
47235+ atomic_read_unchecked(&fscache_n_object_lookups),
47236+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
47237+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
47238+ atomic_read_unchecked(&fscache_n_object_created),
47239+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47240
47241 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47242- atomic_read(&fscache_n_updates),
47243- atomic_read(&fscache_n_updates_null),
47244- atomic_read(&fscache_n_updates_run));
47245+ atomic_read_unchecked(&fscache_n_updates),
47246+ atomic_read_unchecked(&fscache_n_updates_null),
47247+ atomic_read_unchecked(&fscache_n_updates_run));
47248
47249 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47250- atomic_read(&fscache_n_relinquishes),
47251- atomic_read(&fscache_n_relinquishes_null),
47252- atomic_read(&fscache_n_relinquishes_waitcrt),
47253- atomic_read(&fscache_n_relinquishes_retire));
47254+ atomic_read_unchecked(&fscache_n_relinquishes),
47255+ atomic_read_unchecked(&fscache_n_relinquishes_null),
47256+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47257+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
47258
47259 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47260- atomic_read(&fscache_n_attr_changed),
47261- atomic_read(&fscache_n_attr_changed_ok),
47262- atomic_read(&fscache_n_attr_changed_nobufs),
47263- atomic_read(&fscache_n_attr_changed_nomem),
47264- atomic_read(&fscache_n_attr_changed_calls));
47265+ atomic_read_unchecked(&fscache_n_attr_changed),
47266+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
47267+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47268+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47269+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
47270
47271 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47272- atomic_read(&fscache_n_allocs),
47273- atomic_read(&fscache_n_allocs_ok),
47274- atomic_read(&fscache_n_allocs_wait),
47275- atomic_read(&fscache_n_allocs_nobufs),
47276- atomic_read(&fscache_n_allocs_intr));
47277+ atomic_read_unchecked(&fscache_n_allocs),
47278+ atomic_read_unchecked(&fscache_n_allocs_ok),
47279+ atomic_read_unchecked(&fscache_n_allocs_wait),
47280+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
47281+ atomic_read_unchecked(&fscache_n_allocs_intr));
47282 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47283- atomic_read(&fscache_n_alloc_ops),
47284- atomic_read(&fscache_n_alloc_op_waits),
47285- atomic_read(&fscache_n_allocs_object_dead));
47286+ atomic_read_unchecked(&fscache_n_alloc_ops),
47287+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
47288+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
47289
47290 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47291 " int=%u oom=%u\n",
47292- atomic_read(&fscache_n_retrievals),
47293- atomic_read(&fscache_n_retrievals_ok),
47294- atomic_read(&fscache_n_retrievals_wait),
47295- atomic_read(&fscache_n_retrievals_nodata),
47296- atomic_read(&fscache_n_retrievals_nobufs),
47297- atomic_read(&fscache_n_retrievals_intr),
47298- atomic_read(&fscache_n_retrievals_nomem));
47299+ atomic_read_unchecked(&fscache_n_retrievals),
47300+ atomic_read_unchecked(&fscache_n_retrievals_ok),
47301+ atomic_read_unchecked(&fscache_n_retrievals_wait),
47302+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
47303+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47304+ atomic_read_unchecked(&fscache_n_retrievals_intr),
47305+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
47306 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47307- atomic_read(&fscache_n_retrieval_ops),
47308- atomic_read(&fscache_n_retrieval_op_waits),
47309- atomic_read(&fscache_n_retrievals_object_dead));
47310+ atomic_read_unchecked(&fscache_n_retrieval_ops),
47311+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47312+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47313
47314 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47315- atomic_read(&fscache_n_stores),
47316- atomic_read(&fscache_n_stores_ok),
47317- atomic_read(&fscache_n_stores_again),
47318- atomic_read(&fscache_n_stores_nobufs),
47319- atomic_read(&fscache_n_stores_oom));
47320+ atomic_read_unchecked(&fscache_n_stores),
47321+ atomic_read_unchecked(&fscache_n_stores_ok),
47322+ atomic_read_unchecked(&fscache_n_stores_again),
47323+ atomic_read_unchecked(&fscache_n_stores_nobufs),
47324+ atomic_read_unchecked(&fscache_n_stores_oom));
47325 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47326- atomic_read(&fscache_n_store_ops),
47327- atomic_read(&fscache_n_store_calls),
47328- atomic_read(&fscache_n_store_pages),
47329- atomic_read(&fscache_n_store_radix_deletes),
47330- atomic_read(&fscache_n_store_pages_over_limit));
47331+ atomic_read_unchecked(&fscache_n_store_ops),
47332+ atomic_read_unchecked(&fscache_n_store_calls),
47333+ atomic_read_unchecked(&fscache_n_store_pages),
47334+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
47335+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47336
47337 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47338- atomic_read(&fscache_n_store_vmscan_not_storing),
47339- atomic_read(&fscache_n_store_vmscan_gone),
47340- atomic_read(&fscache_n_store_vmscan_busy),
47341- atomic_read(&fscache_n_store_vmscan_cancelled));
47342+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47343+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47344+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47345+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47346
47347 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47348- atomic_read(&fscache_n_op_pend),
47349- atomic_read(&fscache_n_op_run),
47350- atomic_read(&fscache_n_op_enqueue),
47351- atomic_read(&fscache_n_op_cancelled),
47352- atomic_read(&fscache_n_op_rejected));
47353+ atomic_read_unchecked(&fscache_n_op_pend),
47354+ atomic_read_unchecked(&fscache_n_op_run),
47355+ atomic_read_unchecked(&fscache_n_op_enqueue),
47356+ atomic_read_unchecked(&fscache_n_op_cancelled),
47357+ atomic_read_unchecked(&fscache_n_op_rejected));
47358 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47359- atomic_read(&fscache_n_op_deferred_release),
47360- atomic_read(&fscache_n_op_release),
47361- atomic_read(&fscache_n_op_gc));
47362+ atomic_read_unchecked(&fscache_n_op_deferred_release),
47363+ atomic_read_unchecked(&fscache_n_op_release),
47364+ atomic_read_unchecked(&fscache_n_op_gc));
47365
47366 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47367 atomic_read(&fscache_n_cop_alloc_object),
47368diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47369index 3426521..3b75162 100644
47370--- a/fs/fuse/cuse.c
47371+++ b/fs/fuse/cuse.c
47372@@ -587,10 +587,12 @@ static int __init cuse_init(void)
47373 INIT_LIST_HEAD(&cuse_conntbl[i]);
47374
47375 /* inherit and extend fuse_dev_operations */
47376- cuse_channel_fops = fuse_dev_operations;
47377- cuse_channel_fops.owner = THIS_MODULE;
47378- cuse_channel_fops.open = cuse_channel_open;
47379- cuse_channel_fops.release = cuse_channel_release;
47380+ pax_open_kernel();
47381+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47382+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47383+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
47384+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
47385+ pax_close_kernel();
47386
47387 cuse_class = class_create(THIS_MODULE, "cuse");
47388 if (IS_ERR(cuse_class))
47389diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47390index f4246cf..b4aed1d 100644
47391--- a/fs/fuse/dev.c
47392+++ b/fs/fuse/dev.c
47393@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47394 ret = 0;
47395 pipe_lock(pipe);
47396
47397- if (!pipe->readers) {
47398+ if (!atomic_read(&pipe->readers)) {
47399 send_sig(SIGPIPE, current, 0);
47400 if (!ret)
47401 ret = -EPIPE;
47402diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47403index 334e0b1..fc571e8 100644
47404--- a/fs/fuse/dir.c
47405+++ b/fs/fuse/dir.c
47406@@ -1189,7 +1189,7 @@ static char *read_link(struct dentry *dentry)
47407 return link;
47408 }
47409
47410-static void free_link(char *link)
47411+static void free_link(const char *link)
47412 {
47413 if (!IS_ERR(link))
47414 free_page((unsigned long) link);
47415diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47416index a9ba244..d9df391 100644
47417--- a/fs/gfs2/inode.c
47418+++ b/fs/gfs2/inode.c
47419@@ -1496,7 +1496,7 @@ out:
47420
47421 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47422 {
47423- char *s = nd_get_link(nd);
47424+ const char *s = nd_get_link(nd);
47425 if (!IS_ERR(s))
47426 kfree(s);
47427 }
47428diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47429index cc9281b..58996fb 100644
47430--- a/fs/hugetlbfs/inode.c
47431+++ b/fs/hugetlbfs/inode.c
47432@@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47433 .kill_sb = kill_litter_super,
47434 };
47435
47436-static struct vfsmount *hugetlbfs_vfsmount;
47437+struct vfsmount *hugetlbfs_vfsmount;
47438
47439 static int can_do_hugetlb_shm(void)
47440 {
47441diff --git a/fs/inode.c b/fs/inode.c
47442index c99163b..a11ad40 100644
47443--- a/fs/inode.c
47444+++ b/fs/inode.c
47445@@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47446
47447 #ifdef CONFIG_SMP
47448 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47449- static atomic_t shared_last_ino;
47450- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47451+ static atomic_unchecked_t shared_last_ino;
47452+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47453
47454 res = next - LAST_INO_BATCH;
47455 }
47456diff --git a/fs/isofs/export.c b/fs/isofs/export.c
47457index aa4356d..1d38044 100644
47458--- a/fs/isofs/export.c
47459+++ b/fs/isofs/export.c
47460@@ -134,6 +134,7 @@ isofs_export_encode_fh(struct inode *inode,
47461 len = 3;
47462 fh32[0] = ei->i_iget5_block;
47463 fh16[2] = (__u16)ei->i_iget5_offset; /* fh16 [sic] */
47464+ fh16[3] = 0; /* avoid leaking uninitialized data */
47465 fh32[2] = inode->i_generation;
47466 if (parent) {
47467 struct iso_inode_info *eparent;
47468diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47469index 4a6cf28..d3a29d3 100644
47470--- a/fs/jffs2/erase.c
47471+++ b/fs/jffs2/erase.c
47472@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47473 struct jffs2_unknown_node marker = {
47474 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47475 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47476- .totlen = cpu_to_je32(c->cleanmarker_size)
47477+ .totlen = cpu_to_je32(c->cleanmarker_size),
47478+ .hdr_crc = cpu_to_je32(0)
47479 };
47480
47481 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47482diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47483index 6f4529d..bf12806 100644
47484--- a/fs/jffs2/wbuf.c
47485+++ b/fs/jffs2/wbuf.c
47486@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47487 {
47488 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47489 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47490- .totlen = constant_cpu_to_je32(8)
47491+ .totlen = constant_cpu_to_je32(8),
47492+ .hdr_crc = constant_cpu_to_je32(0)
47493 };
47494
47495 /*
47496diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47497index 4a82950..bcaa0cb 100644
47498--- a/fs/jfs/super.c
47499+++ b/fs/jfs/super.c
47500@@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
47501
47502 jfs_inode_cachep =
47503 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47504- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47505+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47506 init_once);
47507 if (jfs_inode_cachep == NULL)
47508 return -ENOMEM;
47509diff --git a/fs/libfs.c b/fs/libfs.c
47510index f86ec27..4734776 100644
47511--- a/fs/libfs.c
47512+++ b/fs/libfs.c
47513@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47514
47515 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47516 struct dentry *next;
47517+ char d_name[sizeof(next->d_iname)];
47518+ const unsigned char *name;
47519+
47520 next = list_entry(p, struct dentry, d_u.d_child);
47521 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47522 if (!simple_positive(next)) {
47523@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47524
47525 spin_unlock(&next->d_lock);
47526 spin_unlock(&dentry->d_lock);
47527- if (filldir(dirent, next->d_name.name,
47528+ name = next->d_name.name;
47529+ if (name == next->d_iname) {
47530+ memcpy(d_name, name, next->d_name.len);
47531+ name = d_name;
47532+ }
47533+ if (filldir(dirent, name,
47534 next->d_name.len, filp->f_pos,
47535 next->d_inode->i_ino,
47536 dt_type(next->d_inode)) < 0)
47537diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47538index 8392cb8..80d6193 100644
47539--- a/fs/lockd/clntproc.c
47540+++ b/fs/lockd/clntproc.c
47541@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47542 /*
47543 * Cookie counter for NLM requests
47544 */
47545-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47546+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47547
47548 void nlmclnt_next_cookie(struct nlm_cookie *c)
47549 {
47550- u32 cookie = atomic_inc_return(&nlm_cookie);
47551+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47552
47553 memcpy(c->data, &cookie, 4);
47554 c->len=4;
47555diff --git a/fs/locks.c b/fs/locks.c
47556index 82c3533..34e929c 100644
47557--- a/fs/locks.c
47558+++ b/fs/locks.c
47559@@ -2076,16 +2076,16 @@ void locks_remove_flock(struct file *filp)
47560 return;
47561
47562 if (filp->f_op && filp->f_op->flock) {
47563- struct file_lock fl = {
47564+ struct file_lock flock = {
47565 .fl_pid = current->tgid,
47566 .fl_file = filp,
47567 .fl_flags = FL_FLOCK,
47568 .fl_type = F_UNLCK,
47569 .fl_end = OFFSET_MAX,
47570 };
47571- filp->f_op->flock(filp, F_SETLKW, &fl);
47572- if (fl.fl_ops && fl.fl_ops->fl_release_private)
47573- fl.fl_ops->fl_release_private(&fl);
47574+ filp->f_op->flock(filp, F_SETLKW, &flock);
47575+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
47576+ flock.fl_ops->fl_release_private(&flock);
47577 }
47578
47579 lock_flocks();
47580diff --git a/fs/namei.c b/fs/namei.c
47581index 7d69419..c7a09f0 100644
47582--- a/fs/namei.c
47583+++ b/fs/namei.c
47584@@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47585 if (ret != -EACCES)
47586 return ret;
47587
47588+#ifdef CONFIG_GRKERNSEC
47589+ /* we'll block if we have to log due to a denied capability use */
47590+ if (mask & MAY_NOT_BLOCK)
47591+ return -ECHILD;
47592+#endif
47593+
47594 if (S_ISDIR(inode->i_mode)) {
47595 /* DACs are overridable for directories */
47596- if (inode_capable(inode, CAP_DAC_OVERRIDE))
47597- return 0;
47598 if (!(mask & MAY_WRITE))
47599- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47600+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47601+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47602 return 0;
47603+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
47604+ return 0;
47605 return -EACCES;
47606 }
47607 /*
47608+ * Searching includes executable on directories, else just read.
47609+ */
47610+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47611+ if (mask == MAY_READ)
47612+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47613+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47614+ return 0;
47615+
47616+ /*
47617 * Read/write DACs are always overridable.
47618 * Executable DACs are overridable when there is
47619 * at least one exec bit set.
47620@@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47621 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47622 return 0;
47623
47624- /*
47625- * Searching includes executable on directories, else just read.
47626- */
47627- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47628- if (mask == MAY_READ)
47629- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47630- return 0;
47631-
47632 return -EACCES;
47633 }
47634
47635@@ -639,11 +647,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47636 return error;
47637 }
47638
47639+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
47640+ dentry->d_inode, dentry, nd->path.mnt)) {
47641+ error = -EACCES;
47642+ *p = ERR_PTR(error); /* no ->put_link(), please */
47643+ path_put(&nd->path);
47644+ return error;
47645+ }
47646+
47647 nd->last_type = LAST_BIND;
47648 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47649 error = PTR_ERR(*p);
47650 if (!IS_ERR(*p)) {
47651- char *s = nd_get_link(nd);
47652+ const char *s = nd_get_link(nd);
47653 error = 0;
47654 if (s)
47655 error = __vfs_follow_link(nd, s);
47656@@ -1386,6 +1402,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47657 if (!res)
47658 res = walk_component(nd, path, &nd->last,
47659 nd->last_type, LOOKUP_FOLLOW);
47660+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47661+ res = -EACCES;
47662 put_link(nd, &link, cookie);
47663 } while (res > 0);
47664
47665@@ -1779,6 +1797,8 @@ static int path_lookupat(int dfd, const char *name,
47666 err = follow_link(&link, nd, &cookie);
47667 if (!err)
47668 err = lookup_last(nd, &path);
47669+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
47670+ err = -EACCES;
47671 put_link(nd, &link, cookie);
47672 }
47673 }
47674@@ -1786,6 +1806,21 @@ static int path_lookupat(int dfd, const char *name,
47675 if (!err)
47676 err = complete_walk(nd);
47677
47678+ if (!(nd->flags & LOOKUP_PARENT)) {
47679+#ifdef CONFIG_GRKERNSEC
47680+ if (flags & LOOKUP_RCU) {
47681+ if (!err)
47682+ path_put(&nd->path);
47683+ err = -ECHILD;
47684+ } else
47685+#endif
47686+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47687+ if (!err)
47688+ path_put(&nd->path);
47689+ err = -ENOENT;
47690+ }
47691+ }
47692+
47693 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47694 if (!nd->inode->i_op->lookup) {
47695 path_put(&nd->path);
47696@@ -1813,6 +1848,15 @@ static int do_path_lookup(int dfd, const char *name,
47697 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47698
47699 if (likely(!retval)) {
47700+ if (*name != '/' && nd->path.dentry && nd->inode) {
47701+#ifdef CONFIG_GRKERNSEC
47702+ if (flags & LOOKUP_RCU)
47703+ return -ECHILD;
47704+#endif
47705+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47706+ return -ENOENT;
47707+ }
47708+
47709 if (unlikely(!audit_dummy_context())) {
47710 if (nd->path.dentry && nd->inode)
47711 audit_inode(name, nd->path.dentry);
47712@@ -2155,6 +2199,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47713 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47714 return -EPERM;
47715
47716+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47717+ return -EPERM;
47718+ if (gr_handle_rawio(inode))
47719+ return -EPERM;
47720+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47721+ return -EACCES;
47722+
47723 return 0;
47724 }
47725
47726@@ -2190,7 +2241,7 @@ static inline int open_to_namei_flags(int flag)
47727 /*
47728 * Handle the last step of open()
47729 */
47730-static struct file *do_last(struct nameidata *nd, struct path *path,
47731+static struct file *do_last(struct nameidata *nd, struct path *path, struct path *link,
47732 const struct open_flags *op, const char *pathname)
47733 {
47734 struct dentry *dir = nd->path.dentry;
47735@@ -2220,16 +2271,44 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47736 error = complete_walk(nd);
47737 if (error)
47738 return ERR_PTR(error);
47739+#ifdef CONFIG_GRKERNSEC
47740+ if (nd->flags & LOOKUP_RCU) {
47741+ error = -ECHILD;
47742+ goto exit;
47743+ }
47744+#endif
47745+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47746+ error = -ENOENT;
47747+ goto exit;
47748+ }
47749 audit_inode(pathname, nd->path.dentry);
47750 if (open_flag & O_CREAT) {
47751 error = -EISDIR;
47752 goto exit;
47753 }
47754+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47755+ error = -EACCES;
47756+ goto exit;
47757+ }
47758 goto ok;
47759 case LAST_BIND:
47760 error = complete_walk(nd);
47761 if (error)
47762 return ERR_PTR(error);
47763+#ifdef CONFIG_GRKERNSEC
47764+ if (nd->flags & LOOKUP_RCU) {
47765+ error = -ECHILD;
47766+ goto exit;
47767+ }
47768+#endif
47769+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47770+ error = -ENOENT;
47771+ goto exit;
47772+ }
47773+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47774+ error = -EACCES;
47775+ goto exit;
47776+ }
47777 audit_inode(pathname, dir);
47778 goto ok;
47779 }
47780@@ -2285,6 +2364,17 @@ retry_lookup:
47781 /* Negative dentry, just create the file */
47782 if (!dentry->d_inode) {
47783 umode_t mode = op->mode;
47784+
47785+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47786+ error = -EACCES;
47787+ goto exit_mutex_unlock;
47788+ }
47789+
47790+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47791+ error = -EACCES;
47792+ goto exit_mutex_unlock;
47793+ }
47794+
47795 if (!IS_POSIXACL(dir->d_inode))
47796 mode &= ~current_umask();
47797 /*
47798@@ -2308,6 +2398,8 @@ retry_lookup:
47799 error = vfs_create(dir->d_inode, dentry, mode, nd);
47800 if (error)
47801 goto exit_mutex_unlock;
47802+ else
47803+ gr_handle_create(path->dentry, path->mnt);
47804 mutex_unlock(&dir->d_inode->i_mutex);
47805 dput(nd->path.dentry);
47806 nd->path.dentry = dentry;
47807@@ -2317,6 +2409,23 @@ retry_lookup:
47808 /*
47809 * It already exists.
47810 */
47811+
47812+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47813+ error = -ENOENT;
47814+ goto exit_mutex_unlock;
47815+ }
47816+ if (link && gr_handle_symlink_owner(link, dentry->d_inode)) {
47817+ error = -EACCES;
47818+ goto exit_mutex_unlock;
47819+ }
47820+
47821+ /* only check if O_CREAT is specified, all other checks need to go
47822+ into may_open */
47823+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47824+ error = -EACCES;
47825+ goto exit_mutex_unlock;
47826+ }
47827+
47828 mutex_unlock(&dir->d_inode->i_mutex);
47829 audit_inode(pathname, path->dentry);
47830
47831@@ -2349,6 +2458,11 @@ finish_lookup:
47832 }
47833 }
47834 BUG_ON(inode != path->dentry->d_inode);
47835+ /* if we're resolving a symlink to another symlink */
47836+ if (link && gr_handle_symlink_owner(link, inode)) {
47837+ error = -EACCES;
47838+ goto exit;
47839+ }
47840 return NULL;
47841 }
47842
47843@@ -2358,7 +2472,6 @@ finish_lookup:
47844 save_parent.dentry = nd->path.dentry;
47845 save_parent.mnt = mntget(path->mnt);
47846 nd->path.dentry = path->dentry;
47847-
47848 }
47849 nd->inode = inode;
47850 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47851@@ -2367,6 +2480,21 @@ finish_lookup:
47852 path_put(&save_parent);
47853 return ERR_PTR(error);
47854 }
47855+#ifdef CONFIG_GRKERNSEC
47856+ if (nd->flags & LOOKUP_RCU) {
47857+ error = -ECHILD;
47858+ goto exit;
47859+ }
47860+#endif
47861+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47862+ error = -ENOENT;
47863+ goto exit;
47864+ }
47865+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47866+ error = -EACCES;
47867+ goto exit;
47868+ }
47869+
47870 error = -EISDIR;
47871 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47872 goto exit;
47873@@ -2461,7 +2589,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47874 if (unlikely(error))
47875 goto out_filp;
47876
47877- filp = do_last(nd, &path, op, pathname);
47878+ filp = do_last(nd, &path, NULL, op, pathname);
47879 while (unlikely(!filp)) { /* trailing symlink */
47880 struct path link = path;
47881 void *cookie;
47882@@ -2476,8 +2604,9 @@ static struct file *path_openat(int dfd, const char *pathname,
47883 error = follow_link(&link, nd, &cookie);
47884 if (unlikely(error))
47885 filp = ERR_PTR(error);
47886- else
47887- filp = do_last(nd, &path, op, pathname);
47888+ else {
47889+ filp = do_last(nd, &path, &link, op, pathname);
47890+ }
47891 put_link(nd, &link, cookie);
47892 }
47893 out:
47894@@ -2577,6 +2706,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47895 *path = nd.path;
47896 return dentry;
47897 eexist:
47898+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47899+ dput(dentry);
47900+ dentry = ERR_PTR(-ENOENT);
47901+ goto fail;
47902+ }
47903 dput(dentry);
47904 dentry = ERR_PTR(-EEXIST);
47905 fail:
47906@@ -2599,6 +2733,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47907 }
47908 EXPORT_SYMBOL(user_path_create);
47909
47910+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47911+{
47912+ char *tmp = getname(pathname);
47913+ struct dentry *res;
47914+ if (IS_ERR(tmp))
47915+ return ERR_CAST(tmp);
47916+ res = kern_path_create(dfd, tmp, path, is_dir);
47917+ if (IS_ERR(res))
47918+ putname(tmp);
47919+ else
47920+ *to = tmp;
47921+ return res;
47922+}
47923+
47924 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47925 {
47926 int error = may_create(dir, dentry);
47927@@ -2665,6 +2813,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47928 error = mnt_want_write(path.mnt);
47929 if (error)
47930 goto out_dput;
47931+
47932+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47933+ error = -EPERM;
47934+ goto out_drop_write;
47935+ }
47936+
47937+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47938+ error = -EACCES;
47939+ goto out_drop_write;
47940+ }
47941+
47942 error = security_path_mknod(&path, dentry, mode, dev);
47943 if (error)
47944 goto out_drop_write;
47945@@ -2682,6 +2841,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47946 }
47947 out_drop_write:
47948 mnt_drop_write(path.mnt);
47949+
47950+ if (!error)
47951+ gr_handle_create(dentry, path.mnt);
47952 out_dput:
47953 dput(dentry);
47954 mutex_unlock(&path.dentry->d_inode->i_mutex);
47955@@ -2735,12 +2897,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47956 error = mnt_want_write(path.mnt);
47957 if (error)
47958 goto out_dput;
47959+
47960+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47961+ error = -EACCES;
47962+ goto out_drop_write;
47963+ }
47964+
47965 error = security_path_mkdir(&path, dentry, mode);
47966 if (error)
47967 goto out_drop_write;
47968 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47969 out_drop_write:
47970 mnt_drop_write(path.mnt);
47971+
47972+ if (!error)
47973+ gr_handle_create(dentry, path.mnt);
47974 out_dput:
47975 dput(dentry);
47976 mutex_unlock(&path.dentry->d_inode->i_mutex);
47977@@ -2820,6 +2991,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47978 char * name;
47979 struct dentry *dentry;
47980 struct nameidata nd;
47981+ ino_t saved_ino = 0;
47982+ dev_t saved_dev = 0;
47983
47984 error = user_path_parent(dfd, pathname, &nd, &name);
47985 if (error)
47986@@ -2848,6 +3021,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47987 error = -ENOENT;
47988 goto exit3;
47989 }
47990+
47991+ saved_ino = dentry->d_inode->i_ino;
47992+ saved_dev = gr_get_dev_from_dentry(dentry);
47993+
47994+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47995+ error = -EACCES;
47996+ goto exit3;
47997+ }
47998+
47999 error = mnt_want_write(nd.path.mnt);
48000 if (error)
48001 goto exit3;
48002@@ -2855,6 +3037,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48003 if (error)
48004 goto exit4;
48005 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48006+ if (!error && (saved_dev || saved_ino))
48007+ gr_handle_delete(saved_ino, saved_dev);
48008 exit4:
48009 mnt_drop_write(nd.path.mnt);
48010 exit3:
48011@@ -2917,6 +3101,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48012 struct dentry *dentry;
48013 struct nameidata nd;
48014 struct inode *inode = NULL;
48015+ ino_t saved_ino = 0;
48016+ dev_t saved_dev = 0;
48017
48018 error = user_path_parent(dfd, pathname, &nd, &name);
48019 if (error)
48020@@ -2939,6 +3125,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48021 if (!inode)
48022 goto slashes;
48023 ihold(inode);
48024+
48025+ if (inode->i_nlink <= 1) {
48026+ saved_ino = inode->i_ino;
48027+ saved_dev = gr_get_dev_from_dentry(dentry);
48028+ }
48029+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48030+ error = -EACCES;
48031+ goto exit2;
48032+ }
48033+
48034 error = mnt_want_write(nd.path.mnt);
48035 if (error)
48036 goto exit2;
48037@@ -2946,6 +3142,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48038 if (error)
48039 goto exit3;
48040 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48041+ if (!error && (saved_ino || saved_dev))
48042+ gr_handle_delete(saved_ino, saved_dev);
48043 exit3:
48044 mnt_drop_write(nd.path.mnt);
48045 exit2:
48046@@ -3021,10 +3219,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48047 error = mnt_want_write(path.mnt);
48048 if (error)
48049 goto out_dput;
48050+
48051+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48052+ error = -EACCES;
48053+ goto out_drop_write;
48054+ }
48055+
48056 error = security_path_symlink(&path, dentry, from);
48057 if (error)
48058 goto out_drop_write;
48059 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48060+ if (!error)
48061+ gr_handle_create(dentry, path.mnt);
48062 out_drop_write:
48063 mnt_drop_write(path.mnt);
48064 out_dput:
48065@@ -3099,6 +3305,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48066 {
48067 struct dentry *new_dentry;
48068 struct path old_path, new_path;
48069+ char *to = NULL;
48070 int how = 0;
48071 int error;
48072
48073@@ -3122,7 +3329,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48074 if (error)
48075 return error;
48076
48077- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48078+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48079 error = PTR_ERR(new_dentry);
48080 if (IS_ERR(new_dentry))
48081 goto out;
48082@@ -3133,13 +3340,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48083 error = mnt_want_write(new_path.mnt);
48084 if (error)
48085 goto out_dput;
48086+
48087+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48088+ old_path.dentry->d_inode,
48089+ old_path.dentry->d_inode->i_mode, to)) {
48090+ error = -EACCES;
48091+ goto out_drop_write;
48092+ }
48093+
48094+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48095+ old_path.dentry, old_path.mnt, to)) {
48096+ error = -EACCES;
48097+ goto out_drop_write;
48098+ }
48099+
48100 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48101 if (error)
48102 goto out_drop_write;
48103 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48104+ if (!error)
48105+ gr_handle_create(new_dentry, new_path.mnt);
48106 out_drop_write:
48107 mnt_drop_write(new_path.mnt);
48108 out_dput:
48109+ putname(to);
48110 dput(new_dentry);
48111 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
48112 path_put(&new_path);
48113@@ -3373,6 +3597,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48114 if (new_dentry == trap)
48115 goto exit5;
48116
48117+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48118+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
48119+ to);
48120+ if (error)
48121+ goto exit5;
48122+
48123 error = mnt_want_write(oldnd.path.mnt);
48124 if (error)
48125 goto exit5;
48126@@ -3382,6 +3612,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48127 goto exit6;
48128 error = vfs_rename(old_dir->d_inode, old_dentry,
48129 new_dir->d_inode, new_dentry);
48130+ if (!error)
48131+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48132+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48133 exit6:
48134 mnt_drop_write(oldnd.path.mnt);
48135 exit5:
48136@@ -3407,6 +3640,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48137
48138 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48139 {
48140+ char tmpbuf[64];
48141+ const char *newlink;
48142 int len;
48143
48144 len = PTR_ERR(link);
48145@@ -3416,7 +3651,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48146 len = strlen(link);
48147 if (len > (unsigned) buflen)
48148 len = buflen;
48149- if (copy_to_user(buffer, link, len))
48150+
48151+ if (len < sizeof(tmpbuf)) {
48152+ memcpy(tmpbuf, link, len);
48153+ newlink = tmpbuf;
48154+ } else
48155+ newlink = link;
48156+
48157+ if (copy_to_user(buffer, newlink, len))
48158 len = -EFAULT;
48159 out:
48160 return len;
48161diff --git a/fs/namespace.c b/fs/namespace.c
48162index 1e4a5fe..a5ce747 100644
48163--- a/fs/namespace.c
48164+++ b/fs/namespace.c
48165@@ -1157,6 +1157,9 @@ static int do_umount(struct mount *mnt, int flags)
48166 if (!(sb->s_flags & MS_RDONLY))
48167 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48168 up_write(&sb->s_umount);
48169+
48170+ gr_log_remount(mnt->mnt_devname, retval);
48171+
48172 return retval;
48173 }
48174
48175@@ -1176,6 +1179,9 @@ static int do_umount(struct mount *mnt, int flags)
48176 br_write_unlock(&vfsmount_lock);
48177 up_write(&namespace_sem);
48178 release_mounts(&umount_list);
48179+
48180+ gr_log_unmount(mnt->mnt_devname, retval);
48181+
48182 return retval;
48183 }
48184
48185@@ -2177,6 +2183,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48186 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48187 MS_STRICTATIME);
48188
48189+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48190+ retval = -EPERM;
48191+ goto dput_out;
48192+ }
48193+
48194+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48195+ retval = -EPERM;
48196+ goto dput_out;
48197+ }
48198+
48199 if (flags & MS_REMOUNT)
48200 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48201 data_page);
48202@@ -2191,6 +2207,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48203 dev_name, data_page);
48204 dput_out:
48205 path_put(&path);
48206+
48207+ gr_log_mount(dev_name, dir_name, retval);
48208+
48209 return retval;
48210 }
48211
48212@@ -2472,6 +2491,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48213 if (error)
48214 goto out2;
48215
48216+ if (gr_handle_chroot_pivot()) {
48217+ error = -EPERM;
48218+ goto out2;
48219+ }
48220+
48221 get_fs_root(current->fs, &root);
48222 error = lock_mount(&old);
48223 if (error)
48224diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48225index 30bd45a..2ad67a5 100644
48226--- a/fs/nfs/inode.c
48227+++ b/fs/nfs/inode.c
48228@@ -1008,16 +1008,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48229 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48230 }
48231
48232-static atomic_long_t nfs_attr_generation_counter;
48233+static atomic_long_unchecked_t nfs_attr_generation_counter;
48234
48235 static unsigned long nfs_read_attr_generation_counter(void)
48236 {
48237- return atomic_long_read(&nfs_attr_generation_counter);
48238+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48239 }
48240
48241 unsigned long nfs_inc_attr_generation_counter(void)
48242 {
48243- return atomic_long_inc_return(&nfs_attr_generation_counter);
48244+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48245 }
48246
48247 void nfs_fattr_init(struct nfs_fattr *fattr)
48248diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48249index c8bd9c3..4f83416 100644
48250--- a/fs/nfsd/vfs.c
48251+++ b/fs/nfsd/vfs.c
48252@@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48253 } else {
48254 oldfs = get_fs();
48255 set_fs(KERNEL_DS);
48256- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48257+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48258 set_fs(oldfs);
48259 }
48260
48261@@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48262
48263 /* Write the data. */
48264 oldfs = get_fs(); set_fs(KERNEL_DS);
48265- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48266+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48267 set_fs(oldfs);
48268 if (host_err < 0)
48269 goto out_nfserr;
48270@@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48271 */
48272
48273 oldfs = get_fs(); set_fs(KERNEL_DS);
48274- host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48275+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48276 set_fs(oldfs);
48277
48278 if (host_err < 0)
48279diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48280index 3568c8a..e0240d8 100644
48281--- a/fs/notify/fanotify/fanotify_user.c
48282+++ b/fs/notify/fanotify/fanotify_user.c
48283@@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48284 goto out_close_fd;
48285
48286 ret = -EFAULT;
48287- if (copy_to_user(buf, &fanotify_event_metadata,
48288+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48289+ copy_to_user(buf, &fanotify_event_metadata,
48290 fanotify_event_metadata.event_len))
48291 goto out_kill_access_response;
48292
48293diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48294index c887b13..0fdf472 100644
48295--- a/fs/notify/notification.c
48296+++ b/fs/notify/notification.c
48297@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48298 * get set to 0 so it will never get 'freed'
48299 */
48300 static struct fsnotify_event *q_overflow_event;
48301-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48302+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48303
48304 /**
48305 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48306@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48307 */
48308 u32 fsnotify_get_cookie(void)
48309 {
48310- return atomic_inc_return(&fsnotify_sync_cookie);
48311+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48312 }
48313 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48314
48315diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48316index 99e3610..02c1068 100644
48317--- a/fs/ntfs/dir.c
48318+++ b/fs/ntfs/dir.c
48319@@ -1329,7 +1329,7 @@ find_next_index_buffer:
48320 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48321 ~(s64)(ndir->itype.index.block_size - 1)));
48322 /* Bounds checks. */
48323- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48324+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48325 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48326 "inode 0x%lx or driver bug.", vdir->i_ino);
48327 goto err_out;
48328diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48329index 7389d2d..dfd5dbe 100644
48330--- a/fs/ntfs/file.c
48331+++ b/fs/ntfs/file.c
48332@@ -2231,6 +2231,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48333 #endif /* NTFS_RW */
48334 };
48335
48336-const struct file_operations ntfs_empty_file_ops = {};
48337+const struct file_operations ntfs_empty_file_ops __read_only;
48338
48339-const struct inode_operations ntfs_empty_inode_ops = {};
48340+const struct inode_operations ntfs_empty_inode_ops __read_only;
48341diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48342index 210c352..a174f83 100644
48343--- a/fs/ocfs2/localalloc.c
48344+++ b/fs/ocfs2/localalloc.c
48345@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48346 goto bail;
48347 }
48348
48349- atomic_inc(&osb->alloc_stats.moves);
48350+ atomic_inc_unchecked(&osb->alloc_stats.moves);
48351
48352 bail:
48353 if (handle)
48354diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48355index d355e6e..578d905 100644
48356--- a/fs/ocfs2/ocfs2.h
48357+++ b/fs/ocfs2/ocfs2.h
48358@@ -235,11 +235,11 @@ enum ocfs2_vol_state
48359
48360 struct ocfs2_alloc_stats
48361 {
48362- atomic_t moves;
48363- atomic_t local_data;
48364- atomic_t bitmap_data;
48365- atomic_t bg_allocs;
48366- atomic_t bg_extends;
48367+ atomic_unchecked_t moves;
48368+ atomic_unchecked_t local_data;
48369+ atomic_unchecked_t bitmap_data;
48370+ atomic_unchecked_t bg_allocs;
48371+ atomic_unchecked_t bg_extends;
48372 };
48373
48374 enum ocfs2_local_alloc_state
48375diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48376index f169da4..9112253 100644
48377--- a/fs/ocfs2/suballoc.c
48378+++ b/fs/ocfs2/suballoc.c
48379@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48380 mlog_errno(status);
48381 goto bail;
48382 }
48383- atomic_inc(&osb->alloc_stats.bg_extends);
48384+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48385
48386 /* You should never ask for this much metadata */
48387 BUG_ON(bits_wanted >
48388@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48389 mlog_errno(status);
48390 goto bail;
48391 }
48392- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48393+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48394
48395 *suballoc_loc = res.sr_bg_blkno;
48396 *suballoc_bit_start = res.sr_bit_offset;
48397@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48398 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48399 res->sr_bits);
48400
48401- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48402+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48403
48404 BUG_ON(res->sr_bits != 1);
48405
48406@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48407 mlog_errno(status);
48408 goto bail;
48409 }
48410- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48411+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48412
48413 BUG_ON(res.sr_bits != 1);
48414
48415@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48416 cluster_start,
48417 num_clusters);
48418 if (!status)
48419- atomic_inc(&osb->alloc_stats.local_data);
48420+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
48421 } else {
48422 if (min_clusters > (osb->bitmap_cpg - 1)) {
48423 /* The only paths asking for contiguousness
48424@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48425 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48426 res.sr_bg_blkno,
48427 res.sr_bit_offset);
48428- atomic_inc(&osb->alloc_stats.bitmap_data);
48429+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48430 *num_clusters = res.sr_bits;
48431 }
48432 }
48433diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48434index 68f4541..89cfe6a 100644
48435--- a/fs/ocfs2/super.c
48436+++ b/fs/ocfs2/super.c
48437@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48438 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48439 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48440 "Stats",
48441- atomic_read(&osb->alloc_stats.bitmap_data),
48442- atomic_read(&osb->alloc_stats.local_data),
48443- atomic_read(&osb->alloc_stats.bg_allocs),
48444- atomic_read(&osb->alloc_stats.moves),
48445- atomic_read(&osb->alloc_stats.bg_extends));
48446+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48447+ atomic_read_unchecked(&osb->alloc_stats.local_data),
48448+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48449+ atomic_read_unchecked(&osb->alloc_stats.moves),
48450+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48451
48452 out += snprintf(buf + out, len - out,
48453 "%10s => State: %u Descriptor: %llu Size: %u bits "
48454@@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48455 spin_lock_init(&osb->osb_xattr_lock);
48456 ocfs2_init_steal_slots(osb);
48457
48458- atomic_set(&osb->alloc_stats.moves, 0);
48459- atomic_set(&osb->alloc_stats.local_data, 0);
48460- atomic_set(&osb->alloc_stats.bitmap_data, 0);
48461- atomic_set(&osb->alloc_stats.bg_allocs, 0);
48462- atomic_set(&osb->alloc_stats.bg_extends, 0);
48463+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48464+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48465+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48466+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48467+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48468
48469 /* Copy the blockcheck stats from the superblock probe */
48470 osb->osb_ecc_stats = *stats;
48471diff --git a/fs/open.c b/fs/open.c
48472index 5d9c71b..adb5b19 100644
48473--- a/fs/open.c
48474+++ b/fs/open.c
48475@@ -31,6 +31,8 @@
48476 #include <linux/ima.h>
48477 #include <linux/dnotify.h>
48478
48479+#define CREATE_TRACE_POINTS
48480+#include <trace/events/fs.h>
48481 #include "internal.h"
48482
48483 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48484@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48485 error = locks_verify_truncate(inode, NULL, length);
48486 if (!error)
48487 error = security_path_truncate(&path);
48488+
48489+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48490+ error = -EACCES;
48491+
48492 if (!error)
48493 error = do_truncate(path.dentry, length, 0, NULL);
48494
48495@@ -359,6 +365,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48496 if (__mnt_is_readonly(path.mnt))
48497 res = -EROFS;
48498
48499+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48500+ res = -EACCES;
48501+
48502 out_path_release:
48503 path_put(&path);
48504 out:
48505@@ -385,6 +394,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48506 if (error)
48507 goto dput_and_out;
48508
48509+ gr_log_chdir(path.dentry, path.mnt);
48510+
48511 set_fs_pwd(current->fs, &path);
48512
48513 dput_and_out:
48514@@ -411,6 +422,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48515 goto out_putf;
48516
48517 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48518+
48519+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48520+ error = -EPERM;
48521+
48522+ if (!error)
48523+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48524+
48525 if (!error)
48526 set_fs_pwd(current->fs, &file->f_path);
48527 out_putf:
48528@@ -439,7 +457,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48529 if (error)
48530 goto dput_and_out;
48531
48532+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48533+ goto dput_and_out;
48534+
48535 set_fs_root(current->fs, &path);
48536+
48537+ gr_handle_chroot_chdir(&path);
48538+
48539 error = 0;
48540 dput_and_out:
48541 path_put(&path);
48542@@ -457,6 +481,16 @@ static int chmod_common(struct path *path, umode_t mode)
48543 if (error)
48544 return error;
48545 mutex_lock(&inode->i_mutex);
48546+
48547+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48548+ error = -EACCES;
48549+ goto out_unlock;
48550+ }
48551+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48552+ error = -EACCES;
48553+ goto out_unlock;
48554+ }
48555+
48556 error = security_path_chmod(path, mode);
48557 if (error)
48558 goto out_unlock;
48559@@ -512,6 +546,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48560 uid = make_kuid(current_user_ns(), user);
48561 gid = make_kgid(current_user_ns(), group);
48562
48563+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
48564+ return -EACCES;
48565+
48566 newattrs.ia_valid = ATTR_CTIME;
48567 if (user != (uid_t) -1) {
48568 if (!uid_valid(uid))
48569@@ -1036,6 +1073,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48570 } else {
48571 fsnotify_open(f);
48572 fd_install(fd, f);
48573+ trace_do_sys_open(tmp, flags, mode);
48574 }
48575 }
48576 putname(tmp);
48577diff --git a/fs/pipe.c b/fs/pipe.c
48578index 49c1065..13b9e12 100644
48579--- a/fs/pipe.c
48580+++ b/fs/pipe.c
48581@@ -438,9 +438,9 @@ redo:
48582 }
48583 if (bufs) /* More to do? */
48584 continue;
48585- if (!pipe->writers)
48586+ if (!atomic_read(&pipe->writers))
48587 break;
48588- if (!pipe->waiting_writers) {
48589+ if (!atomic_read(&pipe->waiting_writers)) {
48590 /* syscall merging: Usually we must not sleep
48591 * if O_NONBLOCK is set, or if we got some data.
48592 * But if a writer sleeps in kernel space, then
48593@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48594 mutex_lock(&inode->i_mutex);
48595 pipe = inode->i_pipe;
48596
48597- if (!pipe->readers) {
48598+ if (!atomic_read(&pipe->readers)) {
48599 send_sig(SIGPIPE, current, 0);
48600 ret = -EPIPE;
48601 goto out;
48602@@ -553,7 +553,7 @@ redo1:
48603 for (;;) {
48604 int bufs;
48605
48606- if (!pipe->readers) {
48607+ if (!atomic_read(&pipe->readers)) {
48608 send_sig(SIGPIPE, current, 0);
48609 if (!ret)
48610 ret = -EPIPE;
48611@@ -644,9 +644,9 @@ redo2:
48612 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48613 do_wakeup = 0;
48614 }
48615- pipe->waiting_writers++;
48616+ atomic_inc(&pipe->waiting_writers);
48617 pipe_wait(pipe);
48618- pipe->waiting_writers--;
48619+ atomic_dec(&pipe->waiting_writers);
48620 }
48621 out:
48622 mutex_unlock(&inode->i_mutex);
48623@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48624 mask = 0;
48625 if (filp->f_mode & FMODE_READ) {
48626 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48627- if (!pipe->writers && filp->f_version != pipe->w_counter)
48628+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48629 mask |= POLLHUP;
48630 }
48631
48632@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48633 * Most Unices do not set POLLERR for FIFOs but on Linux they
48634 * behave exactly like pipes for poll().
48635 */
48636- if (!pipe->readers)
48637+ if (!atomic_read(&pipe->readers))
48638 mask |= POLLERR;
48639 }
48640
48641@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48642
48643 mutex_lock(&inode->i_mutex);
48644 pipe = inode->i_pipe;
48645- pipe->readers -= decr;
48646- pipe->writers -= decw;
48647+ atomic_sub(decr, &pipe->readers);
48648+ atomic_sub(decw, &pipe->writers);
48649
48650- if (!pipe->readers && !pipe->writers) {
48651+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48652 free_pipe_info(inode);
48653 } else {
48654 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48655@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48656
48657 if (inode->i_pipe) {
48658 ret = 0;
48659- inode->i_pipe->readers++;
48660+ atomic_inc(&inode->i_pipe->readers);
48661 }
48662
48663 mutex_unlock(&inode->i_mutex);
48664@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48665
48666 if (inode->i_pipe) {
48667 ret = 0;
48668- inode->i_pipe->writers++;
48669+ atomic_inc(&inode->i_pipe->writers);
48670 }
48671
48672 mutex_unlock(&inode->i_mutex);
48673@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48674 if (inode->i_pipe) {
48675 ret = 0;
48676 if (filp->f_mode & FMODE_READ)
48677- inode->i_pipe->readers++;
48678+ atomic_inc(&inode->i_pipe->readers);
48679 if (filp->f_mode & FMODE_WRITE)
48680- inode->i_pipe->writers++;
48681+ atomic_inc(&inode->i_pipe->writers);
48682 }
48683
48684 mutex_unlock(&inode->i_mutex);
48685@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48686 inode->i_pipe = NULL;
48687 }
48688
48689-static struct vfsmount *pipe_mnt __read_mostly;
48690+struct vfsmount *pipe_mnt __read_mostly;
48691
48692 /*
48693 * pipefs_dname() is called from d_path().
48694@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48695 goto fail_iput;
48696 inode->i_pipe = pipe;
48697
48698- pipe->readers = pipe->writers = 1;
48699+ atomic_set(&pipe->readers, 1);
48700+ atomic_set(&pipe->writers, 1);
48701 inode->i_fop = &rdwr_pipefifo_fops;
48702
48703 /*
48704diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48705index 15af622..0e9f4467 100644
48706--- a/fs/proc/Kconfig
48707+++ b/fs/proc/Kconfig
48708@@ -30,12 +30,12 @@ config PROC_FS
48709
48710 config PROC_KCORE
48711 bool "/proc/kcore support" if !ARM
48712- depends on PROC_FS && MMU
48713+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48714
48715 config PROC_VMCORE
48716 bool "/proc/vmcore support"
48717- depends on PROC_FS && CRASH_DUMP
48718- default y
48719+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48720+ default n
48721 help
48722 Exports the dump image of crashed kernel in ELF format.
48723
48724@@ -59,8 +59,8 @@ config PROC_SYSCTL
48725 limited in memory.
48726
48727 config PROC_PAGE_MONITOR
48728- default y
48729- depends on PROC_FS && MMU
48730+ default n
48731+ depends on PROC_FS && MMU && !GRKERNSEC
48732 bool "Enable /proc page monitoring" if EXPERT
48733 help
48734 Various /proc files exist to monitor process memory utilization:
48735diff --git a/fs/proc/array.c b/fs/proc/array.c
48736index c1c207c..01ce725 100644
48737--- a/fs/proc/array.c
48738+++ b/fs/proc/array.c
48739@@ -60,6 +60,7 @@
48740 #include <linux/tty.h>
48741 #include <linux/string.h>
48742 #include <linux/mman.h>
48743+#include <linux/grsecurity.h>
48744 #include <linux/proc_fs.h>
48745 #include <linux/ioport.h>
48746 #include <linux/uaccess.h>
48747@@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48748 seq_putc(m, '\n');
48749 }
48750
48751+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48752+static inline void task_pax(struct seq_file *m, struct task_struct *p)
48753+{
48754+ if (p->mm)
48755+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48756+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48757+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48758+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48759+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48760+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48761+ else
48762+ seq_printf(m, "PaX:\t-----\n");
48763+}
48764+#endif
48765+
48766 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48767 struct pid *pid, struct task_struct *task)
48768 {
48769@@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48770 task_cpus_allowed(m, task);
48771 cpuset_task_status_allowed(m, task);
48772 task_context_switch_counts(m, task);
48773+
48774+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48775+ task_pax(m, task);
48776+#endif
48777+
48778+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48779+ task_grsec_rbac(m, task);
48780+#endif
48781+
48782 return 0;
48783 }
48784
48785+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48786+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48787+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48788+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48789+#endif
48790+
48791 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48792 struct pid *pid, struct task_struct *task, int whole)
48793 {
48794@@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48795 char tcomm[sizeof(task->comm)];
48796 unsigned long flags;
48797
48798+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48799+ if (current->exec_id != m->exec_id) {
48800+ gr_log_badprocpid("stat");
48801+ return 0;
48802+ }
48803+#endif
48804+
48805 state = *get_task_state(task);
48806 vsize = eip = esp = 0;
48807 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48808@@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48809 gtime = task->gtime;
48810 }
48811
48812+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48813+ if (PAX_RAND_FLAGS(mm)) {
48814+ eip = 0;
48815+ esp = 0;
48816+ wchan = 0;
48817+ }
48818+#endif
48819+#ifdef CONFIG_GRKERNSEC_HIDESYM
48820+ wchan = 0;
48821+ eip =0;
48822+ esp =0;
48823+#endif
48824+
48825 /* scale priority and nice values from timeslices to -20..20 */
48826 /* to make it look like a "normal" Unix priority/nice value */
48827 priority = task_prio(task);
48828@@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48829 seq_put_decimal_ull(m, ' ', vsize);
48830 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48831 seq_put_decimal_ull(m, ' ', rsslim);
48832+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48833+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48834+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48835+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48836+#else
48837 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48838 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48839 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48840+#endif
48841 seq_put_decimal_ull(m, ' ', esp);
48842 seq_put_decimal_ull(m, ' ', eip);
48843 /* The signal information here is obsolete.
48844@@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48845 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48846 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48847
48848- if (mm && permitted) {
48849+ if (mm && permitted
48850+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48851+ && !PAX_RAND_FLAGS(mm)
48852+#endif
48853+ ) {
48854 seq_put_decimal_ull(m, ' ', mm->start_data);
48855 seq_put_decimal_ull(m, ' ', mm->end_data);
48856 seq_put_decimal_ull(m, ' ', mm->start_brk);
48857@@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48858 struct pid *pid, struct task_struct *task)
48859 {
48860 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48861- struct mm_struct *mm = get_task_mm(task);
48862+ struct mm_struct *mm;
48863
48864+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48865+ if (current->exec_id != m->exec_id) {
48866+ gr_log_badprocpid("statm");
48867+ return 0;
48868+ }
48869+#endif
48870+ mm = get_task_mm(task);
48871 if (mm) {
48872 size = task_statm(mm, &shared, &text, &data, &resident);
48873 mmput(mm);
48874@@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48875 return 0;
48876 }
48877
48878+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48879+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48880+{
48881+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
48882+}
48883+#endif
48884+
48885 #ifdef CONFIG_CHECKPOINT_RESTORE
48886 static struct pid *
48887 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48888diff --git a/fs/proc/base.c b/fs/proc/base.c
48889index 437195f..e1b6a2d 100644
48890--- a/fs/proc/base.c
48891+++ b/fs/proc/base.c
48892@@ -110,6 +110,14 @@ struct pid_entry {
48893 union proc_op op;
48894 };
48895
48896+struct getdents_callback {
48897+ struct linux_dirent __user * current_dir;
48898+ struct linux_dirent __user * previous;
48899+ struct file * file;
48900+ int count;
48901+ int error;
48902+};
48903+
48904 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48905 .name = (NAME), \
48906 .len = sizeof(NAME) - 1, \
48907@@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48908 if (!mm->arg_end)
48909 goto out_mm; /* Shh! No looking before we're done */
48910
48911+ if (gr_acl_handle_procpidmem(task))
48912+ goto out_mm;
48913+
48914 len = mm->arg_end - mm->arg_start;
48915
48916 if (len > PAGE_SIZE)
48917@@ -236,12 +247,28 @@ out:
48918 return res;
48919 }
48920
48921+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48922+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48923+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48924+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48925+#endif
48926+
48927 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48928 {
48929 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48930 int res = PTR_ERR(mm);
48931 if (mm && !IS_ERR(mm)) {
48932 unsigned int nwords = 0;
48933+
48934+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48935+ /* allow if we're currently ptracing this task */
48936+ if (PAX_RAND_FLAGS(mm) &&
48937+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48938+ mmput(mm);
48939+ return 0;
48940+ }
48941+#endif
48942+
48943 do {
48944 nwords += 2;
48945 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48946@@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48947 }
48948
48949
48950-#ifdef CONFIG_KALLSYMS
48951+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48952 /*
48953 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48954 * Returns the resolved symbol. If that fails, simply return the address.
48955@@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48956 mutex_unlock(&task->signal->cred_guard_mutex);
48957 }
48958
48959-#ifdef CONFIG_STACKTRACE
48960+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48961
48962 #define MAX_STACK_TRACE_DEPTH 64
48963
48964@@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48965 return count;
48966 }
48967
48968-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48969+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48970 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48971 {
48972 long nr;
48973@@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48974 /************************************************************************/
48975
48976 /* permission checks */
48977-static int proc_fd_access_allowed(struct inode *inode)
48978+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48979 {
48980 struct task_struct *task;
48981 int allowed = 0;
48982@@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48983 */
48984 task = get_proc_task(inode);
48985 if (task) {
48986- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48987+ if (log)
48988+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48989+ else
48990+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48991 put_task_struct(task);
48992 }
48993 return allowed;
48994@@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48995 struct task_struct *task,
48996 int hide_pid_min)
48997 {
48998+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48999+ return false;
49000+
49001+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49002+ rcu_read_lock();
49003+ {
49004+ const struct cred *tmpcred = current_cred();
49005+ const struct cred *cred = __task_cred(task);
49006+
49007+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49008+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49009+ || in_group_p(grsec_proc_gid)
49010+#endif
49011+ ) {
49012+ rcu_read_unlock();
49013+ return true;
49014+ }
49015+ }
49016+ rcu_read_unlock();
49017+
49018+ if (!pid->hide_pid)
49019+ return false;
49020+#endif
49021+
49022 if (pid->hide_pid < hide_pid_min)
49023 return true;
49024 if (in_group_p(pid->pid_gid))
49025 return true;
49026+
49027 return ptrace_may_access(task, PTRACE_MODE_READ);
49028 }
49029
49030@@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49031 put_task_struct(task);
49032
49033 if (!has_perms) {
49034+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49035+ {
49036+#else
49037 if (pid->hide_pid == 2) {
49038+#endif
49039 /*
49040 * Let's make getdents(), stat(), and open()
49041 * consistent with each other. If a process
49042@@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49043 if (!task)
49044 return -ESRCH;
49045
49046+ if (gr_acl_handle_procpidmem(task)) {
49047+ put_task_struct(task);
49048+ return -EPERM;
49049+ }
49050+
49051 mm = mm_access(task, mode);
49052 put_task_struct(task);
49053
49054@@ -695,16 +759,24 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49055 mmput(mm);
49056 }
49057
49058- /* OK to pass negative loff_t, we can catch out-of-range */
49059- file->f_mode |= FMODE_UNSIGNED_OFFSET;
49060 file->private_data = mm;
49061
49062+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49063+ file->f_version = current->exec_id;
49064+#endif
49065+
49066 return 0;
49067 }
49068
49069 static int mem_open(struct inode *inode, struct file *file)
49070 {
49071- return __mem_open(inode, file, PTRACE_MODE_ATTACH);
49072+ int ret;
49073+ ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);
49074+
49075+ /* OK to pass negative loff_t, we can catch out-of-range */
49076+ file->f_mode |= FMODE_UNSIGNED_OFFSET;
49077+
49078+ return ret;
49079 }
49080
49081 static ssize_t mem_rw(struct file *file, char __user *buf,
49082@@ -715,6 +787,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49083 ssize_t copied;
49084 char *page;
49085
49086+#ifdef CONFIG_GRKERNSEC
49087+ if (write)
49088+ return -EPERM;
49089+#endif
49090+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49091+ if (file->f_version != current->exec_id) {
49092+ gr_log_badprocpid("mem");
49093+ return 0;
49094+ }
49095+#endif
49096+
49097 if (!mm)
49098 return 0;
49099
49100@@ -819,6 +902,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49101 if (!mm)
49102 return 0;
49103
49104+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49105+ if (file->f_version != current->exec_id) {
49106+ gr_log_badprocpid("environ");
49107+ return 0;
49108+ }
49109+#endif
49110+
49111 page = (char *)__get_free_page(GFP_TEMPORARY);
49112 if (!page)
49113 return -ENOMEM;
49114@@ -827,15 +917,17 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49115 if (!atomic_inc_not_zero(&mm->mm_users))
49116 goto free;
49117 while (count > 0) {
49118- int this_len, retval, max_len;
49119+ size_t this_len, max_len;
49120+ int retval;
49121+
49122+ if (src >= (mm->env_end - mm->env_start))
49123+ break;
49124
49125 this_len = mm->env_end - (mm->env_start + src);
49126
49127- if (this_len <= 0)
49128- break;
49129
49130- max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
49131- this_len = (this_len > max_len) ? max_len : this_len;
49132+ max_len = min_t(size_t, PAGE_SIZE, count);
49133+ this_len = min(max_len, this_len);
49134
49135 retval = access_remote_vm(mm, (mm->env_start + src),
49136 page, this_len, 0);
49137@@ -1433,7 +1525,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49138 path_put(&nd->path);
49139
49140 /* Are we allowed to snoop on the tasks file descriptors? */
49141- if (!proc_fd_access_allowed(inode))
49142+ if (!proc_fd_access_allowed(inode, 0))
49143 goto out;
49144
49145 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
49146@@ -1472,8 +1564,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49147 struct path path;
49148
49149 /* Are we allowed to snoop on the tasks file descriptors? */
49150- if (!proc_fd_access_allowed(inode))
49151- goto out;
49152+ /* logging this is needed for learning on chromium to work properly,
49153+ but we don't want to flood the logs from 'ps' which does a readlink
49154+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49155+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
49156+ */
49157+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49158+ if (!proc_fd_access_allowed(inode,0))
49159+ goto out;
49160+ } else {
49161+ if (!proc_fd_access_allowed(inode,1))
49162+ goto out;
49163+ }
49164
49165 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49166 if (error)
49167@@ -1538,7 +1640,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49168 rcu_read_lock();
49169 cred = __task_cred(task);
49170 inode->i_uid = cred->euid;
49171+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49172+ inode->i_gid = grsec_proc_gid;
49173+#else
49174 inode->i_gid = cred->egid;
49175+#endif
49176 rcu_read_unlock();
49177 }
49178 security_task_to_inode(task, inode);
49179@@ -1574,10 +1680,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49180 return -ENOENT;
49181 }
49182 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49183+#ifdef CONFIG_GRKERNSEC_PROC_USER
49184+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49185+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49186+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49187+#endif
49188 task_dumpable(task)) {
49189 cred = __task_cred(task);
49190 stat->uid = cred->euid;
49191+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49192+ stat->gid = grsec_proc_gid;
49193+#else
49194 stat->gid = cred->egid;
49195+#endif
49196 }
49197 }
49198 rcu_read_unlock();
49199@@ -1615,11 +1730,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
49200
49201 if (task) {
49202 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49203+#ifdef CONFIG_GRKERNSEC_PROC_USER
49204+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49205+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49206+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49207+#endif
49208 task_dumpable(task)) {
49209 rcu_read_lock();
49210 cred = __task_cred(task);
49211 inode->i_uid = cred->euid;
49212+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49213+ inode->i_gid = grsec_proc_gid;
49214+#else
49215 inode->i_gid = cred->egid;
49216+#endif
49217 rcu_read_unlock();
49218 } else {
49219 inode->i_uid = GLOBAL_ROOT_UID;
49220@@ -1737,7 +1861,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49221 int fd = proc_fd(inode);
49222
49223 if (task) {
49224- files = get_files_struct(task);
49225+ if (!gr_acl_handle_procpidmem(task))
49226+ files = get_files_struct(task);
49227 put_task_struct(task);
49228 }
49229 if (files) {
49230@@ -2336,11 +2461,21 @@ static const struct file_operations proc_map_files_operations = {
49231 */
49232 static int proc_fd_permission(struct inode *inode, int mask)
49233 {
49234+ struct task_struct *task;
49235 int rv = generic_permission(inode, mask);
49236- if (rv == 0)
49237- return 0;
49238+
49239 if (task_pid(current) == proc_pid(inode))
49240 rv = 0;
49241+
49242+ task = get_proc_task(inode);
49243+ if (task == NULL)
49244+ return rv;
49245+
49246+ if (gr_acl_handle_procpidmem(task))
49247+ rv = -EACCES;
49248+
49249+ put_task_struct(task);
49250+
49251 return rv;
49252 }
49253
49254@@ -2450,6 +2585,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49255 if (!task)
49256 goto out_no_task;
49257
49258+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49259+ goto out;
49260+
49261 /*
49262 * Yes, it does not scale. And it should not. Don't add
49263 * new entries into /proc/<tgid>/ without very good reasons.
49264@@ -2494,6 +2632,9 @@ static int proc_pident_readdir(struct file *filp,
49265 if (!task)
49266 goto out_no_task;
49267
49268+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49269+ goto out;
49270+
49271 ret = 0;
49272 i = filp->f_pos;
49273 switch (i) {
49274@@ -2764,7 +2905,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49275 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49276 void *cookie)
49277 {
49278- char *s = nd_get_link(nd);
49279+ const char *s = nd_get_link(nd);
49280 if (!IS_ERR(s))
49281 __putname(s);
49282 }
49283@@ -3033,7 +3174,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49284 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49285 #endif
49286 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49287-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49288+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49289 INF("syscall", S_IRUGO, proc_pid_syscall),
49290 #endif
49291 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49292@@ -3058,10 +3199,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49293 #ifdef CONFIG_SECURITY
49294 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49295 #endif
49296-#ifdef CONFIG_KALLSYMS
49297+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49298 INF("wchan", S_IRUGO, proc_pid_wchan),
49299 #endif
49300-#ifdef CONFIG_STACKTRACE
49301+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49302 ONE("stack", S_IRUGO, proc_pid_stack),
49303 #endif
49304 #ifdef CONFIG_SCHEDSTATS
49305@@ -3095,6 +3236,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49306 #ifdef CONFIG_HARDWALL
49307 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49308 #endif
49309+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49310+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49311+#endif
49312 #ifdef CONFIG_USER_NS
49313 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49314 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49315@@ -3225,7 +3369,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49316 if (!inode)
49317 goto out;
49318
49319+#ifdef CONFIG_GRKERNSEC_PROC_USER
49320+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49321+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49322+ inode->i_gid = grsec_proc_gid;
49323+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49324+#else
49325 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49326+#endif
49327 inode->i_op = &proc_tgid_base_inode_operations;
49328 inode->i_fop = &proc_tgid_base_operations;
49329 inode->i_flags|=S_IMMUTABLE;
49330@@ -3267,7 +3418,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
49331 if (!task)
49332 goto out;
49333
49334+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49335+ goto out_put_task;
49336+
49337 result = proc_pid_instantiate(dir, dentry, task, NULL);
49338+out_put_task:
49339 put_task_struct(task);
49340 out:
49341 return result;
49342@@ -3330,6 +3485,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49343 static int fake_filldir(void *buf, const char *name, int namelen,
49344 loff_t offset, u64 ino, unsigned d_type)
49345 {
49346+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
49347+ __buf->error = -EINVAL;
49348 return 0;
49349 }
49350
49351@@ -3396,7 +3553,7 @@ static const struct pid_entry tid_base_stuff[] = {
49352 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49353 #endif
49354 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49355-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49356+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49357 INF("syscall", S_IRUGO, proc_pid_syscall),
49358 #endif
49359 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49360@@ -3423,10 +3580,10 @@ static const struct pid_entry tid_base_stuff[] = {
49361 #ifdef CONFIG_SECURITY
49362 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49363 #endif
49364-#ifdef CONFIG_KALLSYMS
49365+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49366 INF("wchan", S_IRUGO, proc_pid_wchan),
49367 #endif
49368-#ifdef CONFIG_STACKTRACE
49369+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49370 ONE("stack", S_IRUGO, proc_pid_stack),
49371 #endif
49372 #ifdef CONFIG_SCHEDSTATS
49373diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49374index 82676e3..5f8518a 100644
49375--- a/fs/proc/cmdline.c
49376+++ b/fs/proc/cmdline.c
49377@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49378
49379 static int __init proc_cmdline_init(void)
49380 {
49381+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49382+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49383+#else
49384 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49385+#endif
49386 return 0;
49387 }
49388 module_init(proc_cmdline_init);
49389diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49390index b143471..bb105e5 100644
49391--- a/fs/proc/devices.c
49392+++ b/fs/proc/devices.c
49393@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49394
49395 static int __init proc_devices_init(void)
49396 {
49397+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49398+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49399+#else
49400 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49401+#endif
49402 return 0;
49403 }
49404 module_init(proc_devices_init);
49405diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49406index 7ac817b..c5c9eb0 100644
49407--- a/fs/proc/inode.c
49408+++ b/fs/proc/inode.c
49409@@ -21,11 +21,17 @@
49410 #include <linux/seq_file.h>
49411 #include <linux/slab.h>
49412 #include <linux/mount.h>
49413+#include <linux/grsecurity.h>
49414
49415 #include <asm/uaccess.h>
49416
49417 #include "internal.h"
49418
49419+#ifdef CONFIG_PROC_SYSCTL
49420+extern const struct inode_operations proc_sys_inode_operations;
49421+extern const struct inode_operations proc_sys_dir_operations;
49422+#endif
49423+
49424 static void proc_evict_inode(struct inode *inode)
49425 {
49426 struct proc_dir_entry *de;
49427@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49428 ns_ops = PROC_I(inode)->ns_ops;
49429 if (ns_ops && ns_ops->put)
49430 ns_ops->put(PROC_I(inode)->ns);
49431+
49432+#ifdef CONFIG_PROC_SYSCTL
49433+ if (inode->i_op == &proc_sys_inode_operations ||
49434+ inode->i_op == &proc_sys_dir_operations)
49435+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49436+#endif
49437+
49438 }
49439
49440 static struct kmem_cache * proc_inode_cachep;
49441@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49442 if (de->mode) {
49443 inode->i_mode = de->mode;
49444 inode->i_uid = de->uid;
49445+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49446+ inode->i_gid = grsec_proc_gid;
49447+#else
49448 inode->i_gid = de->gid;
49449+#endif
49450 }
49451 if (de->size)
49452 inode->i_size = de->size;
49453diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49454index eca4aca..19166b2 100644
49455--- a/fs/proc/internal.h
49456+++ b/fs/proc/internal.h
49457@@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49458 struct pid *pid, struct task_struct *task);
49459 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49460 struct pid *pid, struct task_struct *task);
49461+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49462+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49463+#endif
49464 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49465
49466 extern const struct file_operations proc_tid_children_operations;
49467diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49468index 86c67ee..cdca321 100644
49469--- a/fs/proc/kcore.c
49470+++ b/fs/proc/kcore.c
49471@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49472 * the addresses in the elf_phdr on our list.
49473 */
49474 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49475- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49476+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49477+ if (tsz > buflen)
49478 tsz = buflen;
49479-
49480+
49481 while (buflen) {
49482 struct kcore_list *m;
49483
49484@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49485 kfree(elf_buf);
49486 } else {
49487 if (kern_addr_valid(start)) {
49488- unsigned long n;
49489+ char *elf_buf;
49490+ mm_segment_t oldfs;
49491
49492- n = copy_to_user(buffer, (char *)start, tsz);
49493- /*
49494- * We cannot distinguish between fault on source
49495- * and fault on destination. When this happens
49496- * we clear too and hope it will trigger the
49497- * EFAULT again.
49498- */
49499- if (n) {
49500- if (clear_user(buffer + tsz - n,
49501- n))
49502+ elf_buf = kmalloc(tsz, GFP_KERNEL);
49503+ if (!elf_buf)
49504+ return -ENOMEM;
49505+ oldfs = get_fs();
49506+ set_fs(KERNEL_DS);
49507+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49508+ set_fs(oldfs);
49509+ if (copy_to_user(buffer, elf_buf, tsz)) {
49510+ kfree(elf_buf);
49511 return -EFAULT;
49512+ }
49513 }
49514+ set_fs(oldfs);
49515+ kfree(elf_buf);
49516 } else {
49517 if (clear_user(buffer, tsz))
49518 return -EFAULT;
49519@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49520
49521 static int open_kcore(struct inode *inode, struct file *filp)
49522 {
49523+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49524+ return -EPERM;
49525+#endif
49526 if (!capable(CAP_SYS_RAWIO))
49527 return -EPERM;
49528 if (kcore_need_update)
49529diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49530index 80e4645..53e5fcf 100644
49531--- a/fs/proc/meminfo.c
49532+++ b/fs/proc/meminfo.c
49533@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49534 vmi.used >> 10,
49535 vmi.largest_chunk >> 10
49536 #ifdef CONFIG_MEMORY_FAILURE
49537- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49538+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49539 #endif
49540 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49541 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49542diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49543index b1822dd..df622cb 100644
49544--- a/fs/proc/nommu.c
49545+++ b/fs/proc/nommu.c
49546@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49547 if (len < 1)
49548 len = 1;
49549 seq_printf(m, "%*c", len, ' ');
49550- seq_path(m, &file->f_path, "");
49551+ seq_path(m, &file->f_path, "\n\\");
49552 }
49553
49554 seq_putc(m, '\n');
49555diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49556index 06e1cc1..a6eba7d 100644
49557--- a/fs/proc/proc_net.c
49558+++ b/fs/proc/proc_net.c
49559@@ -23,6 +23,7 @@
49560 #include <linux/nsproxy.h>
49561 #include <net/net_namespace.h>
49562 #include <linux/seq_file.h>
49563+#include <linux/grsecurity.h>
49564
49565 #include "internal.h"
49566
49567@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49568 struct task_struct *task;
49569 struct nsproxy *ns;
49570 struct net *net = NULL;
49571+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49572+ const struct cred *cred = current_cred();
49573+#endif
49574+
49575+#ifdef CONFIG_GRKERNSEC_PROC_USER
49576+ if (cred->fsuid)
49577+ return net;
49578+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49579+ if (cred->fsuid && !in_group_p(grsec_proc_gid))
49580+ return net;
49581+#endif
49582
49583 rcu_read_lock();
49584 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49585diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49586index 5d00eb8..75e1775 100644
49587--- a/fs/proc/proc_sysctl.c
49588+++ b/fs/proc/proc_sysctl.c
49589@@ -12,11 +12,15 @@
49590 #include <linux/module.h>
49591 #include "internal.h"
49592
49593+extern int gr_handle_chroot_sysctl(const int op);
49594+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49595+ const int op);
49596+
49597 static const struct dentry_operations proc_sys_dentry_operations;
49598 static const struct file_operations proc_sys_file_operations;
49599-static const struct inode_operations proc_sys_inode_operations;
49600+const struct inode_operations proc_sys_inode_operations;
49601 static const struct file_operations proc_sys_dir_file_operations;
49602-static const struct inode_operations proc_sys_dir_operations;
49603+const struct inode_operations proc_sys_dir_operations;
49604
49605 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49606 {
49607@@ -467,8 +471,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49608
49609 err = NULL;
49610 d_set_d_op(dentry, &proc_sys_dentry_operations);
49611+
49612+ gr_handle_proc_create(dentry, inode);
49613+
49614 d_add(dentry, inode);
49615
49616+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
49617+ err = ERR_PTR(-ENOENT);
49618+
49619 out:
49620 if (h)
49621 sysctl_head_finish(h);
49622@@ -482,18 +492,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49623 struct inode *inode = filp->f_path.dentry->d_inode;
49624 struct ctl_table_header *head = grab_header(inode);
49625 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49626+ int op = write ? MAY_WRITE : MAY_READ;
49627 ssize_t error;
49628 size_t res;
49629
49630 if (IS_ERR(head))
49631 return PTR_ERR(head);
49632
49633+
49634 /*
49635 * At this point we know that the sysctl was not unregistered
49636 * and won't be until we finish.
49637 */
49638 error = -EPERM;
49639- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49640+ if (sysctl_perm(head->root, table, op))
49641 goto out;
49642
49643 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49644@@ -501,6 +513,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49645 if (!table->proc_handler)
49646 goto out;
49647
49648+#ifdef CONFIG_GRKERNSEC
49649+ error = -EPERM;
49650+ if (gr_handle_chroot_sysctl(op))
49651+ goto out;
49652+ dget(filp->f_path.dentry);
49653+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49654+ dput(filp->f_path.dentry);
49655+ goto out;
49656+ }
49657+ dput(filp->f_path.dentry);
49658+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49659+ goto out;
49660+ if (write && !capable(CAP_SYS_ADMIN))
49661+ goto out;
49662+#endif
49663+
49664 /* careful: calling conventions are nasty here */
49665 res = count;
49666 error = table->proc_handler(table, write, buf, &res, ppos);
49667@@ -598,6 +626,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49668 return -ENOMEM;
49669 } else {
49670 d_set_d_op(child, &proc_sys_dentry_operations);
49671+
49672+ gr_handle_proc_create(child, inode);
49673+
49674 d_add(child, inode);
49675 }
49676 } else {
49677@@ -641,6 +672,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49678 if ((*pos)++ < file->f_pos)
49679 return 0;
49680
49681+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49682+ return 0;
49683+
49684 if (unlikely(S_ISLNK(table->mode)))
49685 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49686 else
49687@@ -758,6 +792,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49688 if (IS_ERR(head))
49689 return PTR_ERR(head);
49690
49691+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49692+ return -ENOENT;
49693+
49694 generic_fillattr(inode, stat);
49695 if (table)
49696 stat->mode = (stat->mode & S_IFMT) | table->mode;
49697@@ -780,13 +817,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49698 .llseek = generic_file_llseek,
49699 };
49700
49701-static const struct inode_operations proc_sys_inode_operations = {
49702+const struct inode_operations proc_sys_inode_operations = {
49703 .permission = proc_sys_permission,
49704 .setattr = proc_sys_setattr,
49705 .getattr = proc_sys_getattr,
49706 };
49707
49708-static const struct inode_operations proc_sys_dir_operations = {
49709+const struct inode_operations proc_sys_dir_operations = {
49710 .lookup = proc_sys_lookup,
49711 .permission = proc_sys_permission,
49712 .setattr = proc_sys_setattr,
49713diff --git a/fs/proc/root.c b/fs/proc/root.c
49714index 7c30fce..b3d3aa2 100644
49715--- a/fs/proc/root.c
49716+++ b/fs/proc/root.c
49717@@ -188,7 +188,15 @@ void __init proc_root_init(void)
49718 #ifdef CONFIG_PROC_DEVICETREE
49719 proc_device_tree_init();
49720 #endif
49721+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49722+#ifdef CONFIG_GRKERNSEC_PROC_USER
49723+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49724+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49725+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49726+#endif
49727+#else
49728 proc_mkdir("bus", NULL);
49729+#endif
49730 proc_sys_init();
49731 }
49732
49733diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49734index 4540b8f..1b9772f 100644
49735--- a/fs/proc/task_mmu.c
49736+++ b/fs/proc/task_mmu.c
49737@@ -11,12 +11,19 @@
49738 #include <linux/rmap.h>
49739 #include <linux/swap.h>
49740 #include <linux/swapops.h>
49741+#include <linux/grsecurity.h>
49742
49743 #include <asm/elf.h>
49744 #include <asm/uaccess.h>
49745 #include <asm/tlbflush.h>
49746 #include "internal.h"
49747
49748+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49749+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49750+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49751+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49752+#endif
49753+
49754 void task_mem(struct seq_file *m, struct mm_struct *mm)
49755 {
49756 unsigned long data, text, lib, swap;
49757@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49758 "VmExe:\t%8lu kB\n"
49759 "VmLib:\t%8lu kB\n"
49760 "VmPTE:\t%8lu kB\n"
49761- "VmSwap:\t%8lu kB\n",
49762- hiwater_vm << (PAGE_SHIFT-10),
49763+ "VmSwap:\t%8lu kB\n"
49764+
49765+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49766+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49767+#endif
49768+
49769+ ,hiwater_vm << (PAGE_SHIFT-10),
49770 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49771 mm->locked_vm << (PAGE_SHIFT-10),
49772 mm->pinned_vm << (PAGE_SHIFT-10),
49773@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49774 data << (PAGE_SHIFT-10),
49775 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49776 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49777- swap << (PAGE_SHIFT-10));
49778+ swap << (PAGE_SHIFT-10)
49779+
49780+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49781+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49782+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49783+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49784+#else
49785+ , mm->context.user_cs_base
49786+ , mm->context.user_cs_limit
49787+#endif
49788+#endif
49789+
49790+ );
49791 }
49792
49793 unsigned long task_vsize(struct mm_struct *mm)
49794@@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49795 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49796 }
49797
49798- /* We don't show the stack guard page in /proc/maps */
49799+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49800+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49801+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49802+#else
49803 start = vma->vm_start;
49804- if (stack_guard_page_start(vma, start))
49805- start += PAGE_SIZE;
49806 end = vma->vm_end;
49807- if (stack_guard_page_end(vma, end))
49808- end -= PAGE_SIZE;
49809+#endif
49810
49811 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49812 start,
49813@@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49814 flags & VM_WRITE ? 'w' : '-',
49815 flags & VM_EXEC ? 'x' : '-',
49816 flags & VM_MAYSHARE ? 's' : 'p',
49817+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49818+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49819+#else
49820 pgoff,
49821+#endif
49822 MAJOR(dev), MINOR(dev), ino, &len);
49823
49824 /*
49825@@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49826 */
49827 if (file) {
49828 pad_len_spaces(m, len);
49829- seq_path(m, &file->f_path, "\n");
49830+ seq_path(m, &file->f_path, "\n\\");
49831 goto done;
49832 }
49833
49834@@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49835 * Thread stack in /proc/PID/task/TID/maps or
49836 * the main process stack.
49837 */
49838- if (!is_pid || (vma->vm_start <= mm->start_stack &&
49839- vma->vm_end >= mm->start_stack)) {
49840+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49841+ (vma->vm_start <= mm->start_stack &&
49842+ vma->vm_end >= mm->start_stack)) {
49843 name = "[stack]";
49844 } else {
49845 /* Thread stack in /proc/PID/maps */
49846@@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49847 struct proc_maps_private *priv = m->private;
49848 struct task_struct *task = priv->task;
49849
49850+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49851+ if (current->exec_id != m->exec_id) {
49852+ gr_log_badprocpid("maps");
49853+ return 0;
49854+ }
49855+#endif
49856+
49857 show_map_vma(m, vma, is_pid);
49858
49859 if (m->count < m->size) /* vma is copied successfully */
49860@@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49861 .private = &mss,
49862 };
49863
49864+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49865+ if (current->exec_id != m->exec_id) {
49866+ gr_log_badprocpid("smaps");
49867+ return 0;
49868+ }
49869+#endif
49870 memset(&mss, 0, sizeof mss);
49871- mss.vma = vma;
49872- /* mmap_sem is held in m_start */
49873- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49874- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49875-
49876+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49877+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49878+#endif
49879+ mss.vma = vma;
49880+ /* mmap_sem is held in m_start */
49881+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49882+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49883+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49884+ }
49885+#endif
49886 show_map_vma(m, vma, is_pid);
49887
49888 seq_printf(m,
49889@@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49890 "KernelPageSize: %8lu kB\n"
49891 "MMUPageSize: %8lu kB\n"
49892 "Locked: %8lu kB\n",
49893+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49894+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49895+#else
49896 (vma->vm_end - vma->vm_start) >> 10,
49897+#endif
49898 mss.resident >> 10,
49899 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49900 mss.shared_clean >> 10,
49901@@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49902 int n;
49903 char buffer[50];
49904
49905+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49906+ if (current->exec_id != m->exec_id) {
49907+ gr_log_badprocpid("numa_maps");
49908+ return 0;
49909+ }
49910+#endif
49911+
49912 if (!mm)
49913 return 0;
49914
49915@@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49916 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49917 mpol_cond_put(pol);
49918
49919+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49920+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49921+#else
49922 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49923+#endif
49924
49925 if (file) {
49926 seq_printf(m, " file=");
49927- seq_path(m, &file->f_path, "\n\t= ");
49928+ seq_path(m, &file->f_path, "\n\t\\= ");
49929 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49930 seq_printf(m, " heap");
49931 } else {
49932diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49933index 1ccfa53..0848f95 100644
49934--- a/fs/proc/task_nommu.c
49935+++ b/fs/proc/task_nommu.c
49936@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49937 else
49938 bytes += kobjsize(mm);
49939
49940- if (current->fs && current->fs->users > 1)
49941+ if (current->fs && atomic_read(&current->fs->users) > 1)
49942 sbytes += kobjsize(current->fs);
49943 else
49944 bytes += kobjsize(current->fs);
49945@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49946
49947 if (file) {
49948 pad_len_spaces(m, len);
49949- seq_path(m, &file->f_path, "");
49950+ seq_path(m, &file->f_path, "\n\\");
49951 } else if (mm) {
49952 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49953
49954diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49955index d67908b..d13f6a6 100644
49956--- a/fs/quota/netlink.c
49957+++ b/fs/quota/netlink.c
49958@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49959 void quota_send_warning(short type, unsigned int id, dev_t dev,
49960 const char warntype)
49961 {
49962- static atomic_t seq;
49963+ static atomic_unchecked_t seq;
49964 struct sk_buff *skb;
49965 void *msg_head;
49966 int ret;
49967@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49968 "VFS: Not enough memory to send quota warning.\n");
49969 return;
49970 }
49971- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49972+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49973 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49974 if (!msg_head) {
49975 printk(KERN_ERR
49976diff --git a/fs/readdir.c b/fs/readdir.c
49977index 39e3370..20d446d 100644
49978--- a/fs/readdir.c
49979+++ b/fs/readdir.c
49980@@ -17,6 +17,7 @@
49981 #include <linux/security.h>
49982 #include <linux/syscalls.h>
49983 #include <linux/unistd.h>
49984+#include <linux/namei.h>
49985
49986 #include <asm/uaccess.h>
49987
49988@@ -67,6 +68,7 @@ struct old_linux_dirent {
49989
49990 struct readdir_callback {
49991 struct old_linux_dirent __user * dirent;
49992+ struct file * file;
49993 int result;
49994 };
49995
49996@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49997 buf->result = -EOVERFLOW;
49998 return -EOVERFLOW;
49999 }
50000+
50001+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50002+ return 0;
50003+
50004 buf->result++;
50005 dirent = buf->dirent;
50006 if (!access_ok(VERIFY_WRITE, dirent,
50007@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
50008
50009 buf.result = 0;
50010 buf.dirent = dirent;
50011+ buf.file = file;
50012
50013 error = vfs_readdir(file, fillonedir, &buf);
50014 if (buf.result)
50015@@ -141,6 +148,7 @@ struct linux_dirent {
50016 struct getdents_callback {
50017 struct linux_dirent __user * current_dir;
50018 struct linux_dirent __user * previous;
50019+ struct file * file;
50020 int count;
50021 int error;
50022 };
50023@@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50024 buf->error = -EOVERFLOW;
50025 return -EOVERFLOW;
50026 }
50027+
50028+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50029+ return 0;
50030+
50031 dirent = buf->previous;
50032 if (dirent) {
50033 if (__put_user(offset, &dirent->d_off))
50034@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50035 buf.previous = NULL;
50036 buf.count = count;
50037 buf.error = 0;
50038+ buf.file = file;
50039
50040 error = vfs_readdir(file, filldir, &buf);
50041 if (error >= 0)
50042@@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50043 struct getdents_callback64 {
50044 struct linux_dirent64 __user * current_dir;
50045 struct linux_dirent64 __user * previous;
50046+ struct file *file;
50047 int count;
50048 int error;
50049 };
50050@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50051 buf->error = -EINVAL; /* only used if we fail.. */
50052 if (reclen > buf->count)
50053 return -EINVAL;
50054+
50055+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50056+ return 0;
50057+
50058 dirent = buf->previous;
50059 if (dirent) {
50060 if (__put_user(offset, &dirent->d_off))
50061@@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50062
50063 buf.current_dir = dirent;
50064 buf.previous = NULL;
50065+ buf.file = file;
50066 buf.count = count;
50067 buf.error = 0;
50068
50069@@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50070 error = buf.error;
50071 lastdirent = buf.previous;
50072 if (lastdirent) {
50073- typeof(lastdirent->d_off) d_off = file->f_pos;
50074+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50075 if (__put_user(d_off, &lastdirent->d_off))
50076 error = -EFAULT;
50077 else
50078diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50079index 2b7882b..1c5ef48 100644
50080--- a/fs/reiserfs/do_balan.c
50081+++ b/fs/reiserfs/do_balan.c
50082@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50083 return;
50084 }
50085
50086- atomic_inc(&(fs_generation(tb->tb_sb)));
50087+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50088 do_balance_starts(tb);
50089
50090 /* balance leaf returns 0 except if combining L R and S into
50091diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50092index 2c1ade6..8c59d8d 100644
50093--- a/fs/reiserfs/procfs.c
50094+++ b/fs/reiserfs/procfs.c
50095@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50096 "SMALL_TAILS " : "NO_TAILS ",
50097 replay_only(sb) ? "REPLAY_ONLY " : "",
50098 convert_reiserfs(sb) ? "CONV " : "",
50099- atomic_read(&r->s_generation_counter),
50100+ atomic_read_unchecked(&r->s_generation_counter),
50101 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50102 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50103 SF(s_good_search_by_key_reada), SF(s_bmaps),
50104diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50105index 33215f5..c5d427a 100644
50106--- a/fs/reiserfs/reiserfs.h
50107+++ b/fs/reiserfs/reiserfs.h
50108@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50109 /* Comment? -Hans */
50110 wait_queue_head_t s_wait;
50111 /* To be obsoleted soon by per buffer seals.. -Hans */
50112- atomic_t s_generation_counter; // increased by one every time the
50113+ atomic_unchecked_t s_generation_counter; // increased by one every time the
50114 // tree gets re-balanced
50115 unsigned long s_properties; /* File system properties. Currently holds
50116 on-disk FS format */
50117@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50118 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50119
50120 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50121-#define get_generation(s) atomic_read (&fs_generation(s))
50122+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50123 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50124 #define __fs_changed(gen,s) (gen != get_generation (s))
50125 #define fs_changed(gen,s) \
50126diff --git a/fs/select.c b/fs/select.c
50127index db14c78..3aae1bd 100644
50128--- a/fs/select.c
50129+++ b/fs/select.c
50130@@ -20,6 +20,7 @@
50131 #include <linux/export.h>
50132 #include <linux/slab.h>
50133 #include <linux/poll.h>
50134+#include <linux/security.h>
50135 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50136 #include <linux/file.h>
50137 #include <linux/fdtable.h>
50138@@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50139 struct poll_list *walk = head;
50140 unsigned long todo = nfds;
50141
50142+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50143 if (nfds > rlimit(RLIMIT_NOFILE))
50144 return -EINVAL;
50145
50146diff --git a/fs/seq_file.c b/fs/seq_file.c
50147index 0cbd049..64e705c 100644
50148--- a/fs/seq_file.c
50149+++ b/fs/seq_file.c
50150@@ -9,6 +9,7 @@
50151 #include <linux/export.h>
50152 #include <linux/seq_file.h>
50153 #include <linux/slab.h>
50154+#include <linux/sched.h>
50155
50156 #include <asm/uaccess.h>
50157 #include <asm/page.h>
50158@@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50159 memset(p, 0, sizeof(*p));
50160 mutex_init(&p->lock);
50161 p->op = op;
50162+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50163+ p->exec_id = current->exec_id;
50164+#endif
50165
50166 /*
50167 * Wrappers around seq_open(e.g. swaps_open) need to be
50168@@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50169 return 0;
50170 }
50171 if (!m->buf) {
50172- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50173+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50174 if (!m->buf)
50175 return -ENOMEM;
50176 }
50177@@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50178 Eoverflow:
50179 m->op->stop(m, p);
50180 kfree(m->buf);
50181- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50182+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50183 return !m->buf ? -ENOMEM : -EAGAIN;
50184 }
50185
50186@@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50187
50188 /* grab buffer if we didn't have one */
50189 if (!m->buf) {
50190- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50191+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50192 if (!m->buf)
50193 goto Enomem;
50194 }
50195@@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50196 goto Fill;
50197 m->op->stop(m, p);
50198 kfree(m->buf);
50199- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50200+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50201 if (!m->buf)
50202 goto Enomem;
50203 m->count = 0;
50204@@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
50205 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50206 void *data)
50207 {
50208- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50209+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50210 int res = -ENOMEM;
50211
50212 if (op) {
50213diff --git a/fs/splice.c b/fs/splice.c
50214index 7bf08fa..eb35c2f 100644
50215--- a/fs/splice.c
50216+++ b/fs/splice.c
50217@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50218 pipe_lock(pipe);
50219
50220 for (;;) {
50221- if (!pipe->readers) {
50222+ if (!atomic_read(&pipe->readers)) {
50223 send_sig(SIGPIPE, current, 0);
50224 if (!ret)
50225 ret = -EPIPE;
50226@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50227 do_wakeup = 0;
50228 }
50229
50230- pipe->waiting_writers++;
50231+ atomic_inc(&pipe->waiting_writers);
50232 pipe_wait(pipe);
50233- pipe->waiting_writers--;
50234+ atomic_dec(&pipe->waiting_writers);
50235 }
50236
50237 pipe_unlock(pipe);
50238@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50239 old_fs = get_fs();
50240 set_fs(get_ds());
50241 /* The cast to a user pointer is valid due to the set_fs() */
50242- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50243+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50244 set_fs(old_fs);
50245
50246 return res;
50247@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50248 old_fs = get_fs();
50249 set_fs(get_ds());
50250 /* The cast to a user pointer is valid due to the set_fs() */
50251- res = vfs_write(file, (const char __user *)buf, count, &pos);
50252+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50253 set_fs(old_fs);
50254
50255 return res;
50256@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50257 goto err;
50258
50259 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50260- vec[i].iov_base = (void __user *) page_address(page);
50261+ vec[i].iov_base = (void __force_user *) page_address(page);
50262 vec[i].iov_len = this_len;
50263 spd.pages[i] = page;
50264 spd.nr_pages++;
50265@@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50266 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50267 {
50268 while (!pipe->nrbufs) {
50269- if (!pipe->writers)
50270+ if (!atomic_read(&pipe->writers))
50271 return 0;
50272
50273- if (!pipe->waiting_writers && sd->num_spliced)
50274+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50275 return 0;
50276
50277 if (sd->flags & SPLICE_F_NONBLOCK)
50278@@ -1187,7 +1187,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50279 * out of the pipe right after the splice_to_pipe(). So set
50280 * PIPE_READERS appropriately.
50281 */
50282- pipe->readers = 1;
50283+ atomic_set(&pipe->readers, 1);
50284
50285 current->splice_pipe = pipe;
50286 }
50287@@ -1740,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50288 ret = -ERESTARTSYS;
50289 break;
50290 }
50291- if (!pipe->writers)
50292+ if (!atomic_read(&pipe->writers))
50293 break;
50294- if (!pipe->waiting_writers) {
50295+ if (!atomic_read(&pipe->waiting_writers)) {
50296 if (flags & SPLICE_F_NONBLOCK) {
50297 ret = -EAGAIN;
50298 break;
50299@@ -1774,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50300 pipe_lock(pipe);
50301
50302 while (pipe->nrbufs >= pipe->buffers) {
50303- if (!pipe->readers) {
50304+ if (!atomic_read(&pipe->readers)) {
50305 send_sig(SIGPIPE, current, 0);
50306 ret = -EPIPE;
50307 break;
50308@@ -1787,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50309 ret = -ERESTARTSYS;
50310 break;
50311 }
50312- pipe->waiting_writers++;
50313+ atomic_inc(&pipe->waiting_writers);
50314 pipe_wait(pipe);
50315- pipe->waiting_writers--;
50316+ atomic_dec(&pipe->waiting_writers);
50317 }
50318
50319 pipe_unlock(pipe);
50320@@ -1825,14 +1825,14 @@ retry:
50321 pipe_double_lock(ipipe, opipe);
50322
50323 do {
50324- if (!opipe->readers) {
50325+ if (!atomic_read(&opipe->readers)) {
50326 send_sig(SIGPIPE, current, 0);
50327 if (!ret)
50328 ret = -EPIPE;
50329 break;
50330 }
50331
50332- if (!ipipe->nrbufs && !ipipe->writers)
50333+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50334 break;
50335
50336 /*
50337@@ -1929,7 +1929,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50338 pipe_double_lock(ipipe, opipe);
50339
50340 do {
50341- if (!opipe->readers) {
50342+ if (!atomic_read(&opipe->readers)) {
50343 send_sig(SIGPIPE, current, 0);
50344 if (!ret)
50345 ret = -EPIPE;
50346@@ -1974,7 +1974,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50347 * return EAGAIN if we have the potential of some data in the
50348 * future, otherwise just return 0
50349 */
50350- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50351+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50352 ret = -EAGAIN;
50353
50354 pipe_unlock(ipipe);
50355diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50356index e6bb9b2..d8e3951 100644
50357--- a/fs/sysfs/dir.c
50358+++ b/fs/sysfs/dir.c
50359@@ -678,6 +678,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50360 struct sysfs_dirent *sd;
50361 int rc;
50362
50363+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50364+ const char *parent_name = parent_sd->s_name;
50365+
50366+ mode = S_IFDIR | S_IRWXU;
50367+
50368+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50369+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50370+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50371+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50372+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50373+#endif
50374+
50375 /* allocate */
50376 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50377 if (!sd)
50378diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50379index 00012e3..8392349 100644
50380--- a/fs/sysfs/file.c
50381+++ b/fs/sysfs/file.c
50382@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50383
50384 struct sysfs_open_dirent {
50385 atomic_t refcnt;
50386- atomic_t event;
50387+ atomic_unchecked_t event;
50388 wait_queue_head_t poll;
50389 struct list_head buffers; /* goes through sysfs_buffer.list */
50390 };
50391@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50392 if (!sysfs_get_active(attr_sd))
50393 return -ENODEV;
50394
50395- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50396+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50397 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50398
50399 sysfs_put_active(attr_sd);
50400@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50401 return -ENOMEM;
50402
50403 atomic_set(&new_od->refcnt, 0);
50404- atomic_set(&new_od->event, 1);
50405+ atomic_set_unchecked(&new_od->event, 1);
50406 init_waitqueue_head(&new_od->poll);
50407 INIT_LIST_HEAD(&new_od->buffers);
50408 goto retry;
50409@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50410
50411 sysfs_put_active(attr_sd);
50412
50413- if (buffer->event != atomic_read(&od->event))
50414+ if (buffer->event != atomic_read_unchecked(&od->event))
50415 goto trigger;
50416
50417 return DEFAULT_POLLMASK;
50418@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50419
50420 od = sd->s_attr.open;
50421 if (od) {
50422- atomic_inc(&od->event);
50423+ atomic_inc_unchecked(&od->event);
50424 wake_up_interruptible(&od->poll);
50425 }
50426
50427diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50428index a7ac78f..02158e1 100644
50429--- a/fs/sysfs/symlink.c
50430+++ b/fs/sysfs/symlink.c
50431@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50432
50433 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50434 {
50435- char *page = nd_get_link(nd);
50436+ const char *page = nd_get_link(nd);
50437 if (!IS_ERR(page))
50438 free_page((unsigned long)page);
50439 }
50440diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50441index c175b4d..8f36a16 100644
50442--- a/fs/udf/misc.c
50443+++ b/fs/udf/misc.c
50444@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50445
50446 u8 udf_tag_checksum(const struct tag *t)
50447 {
50448- u8 *data = (u8 *)t;
50449+ const u8 *data = (const u8 *)t;
50450 u8 checksum = 0;
50451 int i;
50452 for (i = 0; i < sizeof(struct tag); ++i)
50453diff --git a/fs/udf/namei.c b/fs/udf/namei.c
50454index 1802417..c31deb3 100644
50455--- a/fs/udf/namei.c
50456+++ b/fs/udf/namei.c
50457@@ -1279,6 +1279,7 @@ static int udf_encode_fh(struct inode *inode, __u32 *fh, int *lenp,
50458 *lenp = 3;
50459 fid->udf.block = location.logicalBlockNum;
50460 fid->udf.partref = location.partitionReferenceNum;
50461+ fid->udf.parent_partref = 0;
50462 fid->udf.generation = inode->i_generation;
50463
50464 if (parent) {
50465diff --git a/fs/utimes.c b/fs/utimes.c
50466index fa4dbe4..e12d1b9 100644
50467--- a/fs/utimes.c
50468+++ b/fs/utimes.c
50469@@ -1,6 +1,7 @@
50470 #include <linux/compiler.h>
50471 #include <linux/file.h>
50472 #include <linux/fs.h>
50473+#include <linux/security.h>
50474 #include <linux/linkage.h>
50475 #include <linux/mount.h>
50476 #include <linux/namei.h>
50477@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50478 goto mnt_drop_write_and_out;
50479 }
50480 }
50481+
50482+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50483+ error = -EACCES;
50484+ goto mnt_drop_write_and_out;
50485+ }
50486+
50487 mutex_lock(&inode->i_mutex);
50488 error = notify_change(path->dentry, &newattrs);
50489 mutex_unlock(&inode->i_mutex);
50490diff --git a/fs/xattr.c b/fs/xattr.c
50491index 1d7ac37..23cb9ec 100644
50492--- a/fs/xattr.c
50493+++ b/fs/xattr.c
50494@@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50495 * Extended attribute SET operations
50496 */
50497 static long
50498-setxattr(struct dentry *d, const char __user *name, const void __user *value,
50499+setxattr(struct path *path, const char __user *name, const void __user *value,
50500 size_t size, int flags)
50501 {
50502 int error;
50503@@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50504 }
50505 }
50506
50507- error = vfs_setxattr(d, kname, kvalue, size, flags);
50508+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50509+ error = -EACCES;
50510+ goto out;
50511+ }
50512+
50513+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50514 out:
50515 if (vvalue)
50516 vfree(vvalue);
50517@@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50518 return error;
50519 error = mnt_want_write(path.mnt);
50520 if (!error) {
50521- error = setxattr(path.dentry, name, value, size, flags);
50522+ error = setxattr(&path, name, value, size, flags);
50523 mnt_drop_write(path.mnt);
50524 }
50525 path_put(&path);
50526@@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50527 return error;
50528 error = mnt_want_write(path.mnt);
50529 if (!error) {
50530- error = setxattr(path.dentry, name, value, size, flags);
50531+ error = setxattr(&path, name, value, size, flags);
50532 mnt_drop_write(path.mnt);
50533 }
50534 path_put(&path);
50535@@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50536 {
50537 int fput_needed;
50538 struct file *f;
50539- struct dentry *dentry;
50540 int error = -EBADF;
50541
50542 f = fget_light(fd, &fput_needed);
50543 if (!f)
50544 return error;
50545- dentry = f->f_path.dentry;
50546- audit_inode(NULL, dentry);
50547+ audit_inode(NULL, f->f_path.dentry);
50548 error = mnt_want_write_file(f);
50549 if (!error) {
50550- error = setxattr(dentry, name, value, size, flags);
50551+ error = setxattr(&f->f_path, name, value, size, flags);
50552 mnt_drop_write_file(f);
50553 }
50554 fput_light(f, fput_needed);
50555diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50556index 69d06b0..c0996e5 100644
50557--- a/fs/xattr_acl.c
50558+++ b/fs/xattr_acl.c
50559@@ -17,8 +17,8 @@
50560 struct posix_acl *
50561 posix_acl_from_xattr(const void *value, size_t size)
50562 {
50563- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50564- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50565+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50566+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50567 int count;
50568 struct posix_acl *acl;
50569 struct posix_acl_entry *acl_e;
50570diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50571index 58b815e..595ddee 100644
50572--- a/fs/xfs/xfs_bmap.c
50573+++ b/fs/xfs/xfs_bmap.c
50574@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50575 int nmap,
50576 int ret_nmap);
50577 #else
50578-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50579+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50580 #endif /* DEBUG */
50581
50582 STATIC int
50583diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50584index 19bf0c5..9f26b02 100644
50585--- a/fs/xfs/xfs_dir2_sf.c
50586+++ b/fs/xfs/xfs_dir2_sf.c
50587@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50588 }
50589
50590 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50591- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50592+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50593+ char name[sfep->namelen];
50594+ memcpy(name, sfep->name, sfep->namelen);
50595+ if (filldir(dirent, name, sfep->namelen,
50596+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
50597+ *offset = off & 0x7fffffff;
50598+ return 0;
50599+ }
50600+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50601 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50602 *offset = off & 0x7fffffff;
50603 return 0;
50604diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
50605index f9c3fe3..69cf4fc 100644
50606--- a/fs/xfs/xfs_discard.c
50607+++ b/fs/xfs/xfs_discard.c
50608@@ -179,12 +179,14 @@ xfs_ioc_trim(
50609 * used by the fstrim application. In the end it really doesn't
50610 * matter as trimming blocks is an advisory interface.
50611 */
50612+ if (range.start >= XFS_FSB_TO_B(mp, mp->m_sb.sb_dblocks) ||
50613+ range.minlen > XFS_FSB_TO_B(mp, XFS_ALLOC_AG_MAX_USABLE(mp)))
50614+ return -XFS_ERROR(EINVAL);
50615+
50616 start = BTOBB(range.start);
50617 end = start + BTOBBT(range.len) - 1;
50618 minlen = BTOBB(max_t(u64, granularity, range.minlen));
50619
50620- if (XFS_BB_TO_FSB(mp, start) >= mp->m_sb.sb_dblocks)
50621- return -XFS_ERROR(EINVAL);
50622 if (end > XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks) - 1)
50623 end = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks)- 1;
50624
50625diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50626index 3a05a41..320bec6 100644
50627--- a/fs/xfs/xfs_ioctl.c
50628+++ b/fs/xfs/xfs_ioctl.c
50629@@ -126,7 +126,7 @@ xfs_find_handle(
50630 }
50631
50632 error = -EFAULT;
50633- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50634+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50635 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50636 goto out_put;
50637
50638diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50639index 1a25fd8..e935581 100644
50640--- a/fs/xfs/xfs_iops.c
50641+++ b/fs/xfs/xfs_iops.c
50642@@ -394,7 +394,7 @@ xfs_vn_put_link(
50643 struct nameidata *nd,
50644 void *p)
50645 {
50646- char *s = nd_get_link(nd);
50647+ const char *s = nd_get_link(nd);
50648
50649 if (!IS_ERR(s))
50650 kfree(s);
50651diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
50652index 92d4331..ca28a4b 100644
50653--- a/fs/xfs/xfs_rtalloc.c
50654+++ b/fs/xfs/xfs_rtalloc.c
50655@@ -857,7 +857,7 @@ xfs_rtbuf_get(
50656 xfs_buf_t *bp; /* block buffer, result */
50657 xfs_inode_t *ip; /* bitmap or summary inode */
50658 xfs_bmbt_irec_t map;
50659- int nmap;
50660+ int nmap = 1;
50661 int error; /* error value */
50662
50663 ip = issum ? mp->m_rsumip : mp->m_rbmip;
50664diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50665new file mode 100644
50666index 0000000..d38b430
50667--- /dev/null
50668+++ b/grsecurity/Kconfig
50669@@ -0,0 +1,947 @@
50670+#
50671+# grecurity configuration
50672+#
50673+menu "Memory Protections"
50674+depends on GRKERNSEC
50675+
50676+config GRKERNSEC_KMEM
50677+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50678+ default y if GRKERNSEC_CONFIG_AUTO
50679+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50680+ help
50681+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50682+ be written to or read from to modify or leak the contents of the running
50683+ kernel. /dev/port will also not be allowed to be opened. If you have module
50684+ support disabled, enabling this will close up four ways that are
50685+ currently used to insert malicious code into the running kernel.
50686+ Even with all these features enabled, we still highly recommend that
50687+ you use the RBAC system, as it is still possible for an attacker to
50688+ modify the running kernel through privileged I/O granted by ioperm/iopl.
50689+ If you are not using XFree86, you may be able to stop this additional
50690+ case by enabling the 'Disable privileged I/O' option. Though nothing
50691+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50692+ but only to video memory, which is the only writing we allow in this
50693+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50694+ not be allowed to mprotect it with PROT_WRITE later.
50695+ It is highly recommended that you say Y here if you meet all the
50696+ conditions above.
50697+
50698+config GRKERNSEC_VM86
50699+ bool "Restrict VM86 mode"
50700+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50701+ depends on X86_32
50702+
50703+ help
50704+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50705+ make use of a special execution mode on 32bit x86 processors called
50706+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50707+ video cards and will still work with this option enabled. The purpose
50708+ of the option is to prevent exploitation of emulation errors in
50709+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
50710+ Nearly all users should be able to enable this option.
50711+
50712+config GRKERNSEC_IO
50713+ bool "Disable privileged I/O"
50714+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50715+ depends on X86
50716+ select RTC_CLASS
50717+ select RTC_INTF_DEV
50718+ select RTC_DRV_CMOS
50719+
50720+ help
50721+ If you say Y here, all ioperm and iopl calls will return an error.
50722+ Ioperm and iopl can be used to modify the running kernel.
50723+ Unfortunately, some programs need this access to operate properly,
50724+ the most notable of which are XFree86 and hwclock. hwclock can be
50725+ remedied by having RTC support in the kernel, so real-time
50726+ clock support is enabled if this option is enabled, to ensure
50727+ that hwclock operates correctly. XFree86 still will not
50728+ operate correctly with this option enabled, so DO NOT CHOOSE Y
50729+ IF YOU USE XFree86. If you use XFree86 and you still want to
50730+ protect your kernel against modification, use the RBAC system.
50731+
50732+config GRKERNSEC_PROC_MEMMAP
50733+ bool "Harden ASLR against information leaks and entropy reduction"
50734+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50735+ depends on PAX_NOEXEC || PAX_ASLR
50736+ help
50737+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50738+ give no information about the addresses of its mappings if
50739+ PaX features that rely on random addresses are enabled on the task.
50740+ In addition to sanitizing this information and disabling other
50741+ dangerous sources of information, this option causes reads of sensitive
50742+ /proc/<pid> entries where the file descriptor was opened in a different
50743+ task than the one performing the read. Such attempts are logged.
50744+ This option also limits argv/env strings for suid/sgid binaries
50745+ to 512KB to prevent a complete exhaustion of the stack entropy provided
50746+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50747+ binaries to prevent alternative mmap layouts from being abused.
50748+
50749+ If you use PaX it is essential that you say Y here as it closes up
50750+ several holes that make full ASLR useless locally.
50751+
50752+config GRKERNSEC_BRUTE
50753+ bool "Deter exploit bruteforcing"
50754+ default y if GRKERNSEC_CONFIG_AUTO
50755+ help
50756+ If you say Y here, attempts to bruteforce exploits against forking
50757+ daemons such as apache or sshd, as well as against suid/sgid binaries
50758+ will be deterred. When a child of a forking daemon is killed by PaX
50759+ or crashes due to an illegal instruction or other suspicious signal,
50760+ the parent process will be delayed 30 seconds upon every subsequent
50761+ fork until the administrator is able to assess the situation and
50762+ restart the daemon.
50763+ In the suid/sgid case, the attempt is logged, the user has all their
50764+ processes terminated, and they are prevented from executing any further
50765+ processes for 15 minutes.
50766+ It is recommended that you also enable signal logging in the auditing
50767+ section so that logs are generated when a process triggers a suspicious
50768+ signal.
50769+ If the sysctl option is enabled, a sysctl option with name
50770+ "deter_bruteforce" is created.
50771+
50772+
50773+config GRKERNSEC_MODHARDEN
50774+ bool "Harden module auto-loading"
50775+ default y if GRKERNSEC_CONFIG_AUTO
50776+ depends on MODULES
50777+ help
50778+ If you say Y here, module auto-loading in response to use of some
50779+ feature implemented by an unloaded module will be restricted to
50780+ root users. Enabling this option helps defend against attacks
50781+ by unprivileged users who abuse the auto-loading behavior to
50782+ cause a vulnerable module to load that is then exploited.
50783+
50784+ If this option prevents a legitimate use of auto-loading for a
50785+ non-root user, the administrator can execute modprobe manually
50786+ with the exact name of the module mentioned in the alert log.
50787+ Alternatively, the administrator can add the module to the list
50788+ of modules loaded at boot by modifying init scripts.
50789+
50790+ Modification of init scripts will most likely be needed on
50791+ Ubuntu servers with encrypted home directory support enabled,
50792+ as the first non-root user logging in will cause the ecb(aes),
50793+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50794+
50795+config GRKERNSEC_HIDESYM
50796+ bool "Hide kernel symbols"
50797+ default y if GRKERNSEC_CONFIG_AUTO
50798+ select PAX_USERCOPY_SLABS
50799+ help
50800+ If you say Y here, getting information on loaded modules, and
50801+ displaying all kernel symbols through a syscall will be restricted
50802+ to users with CAP_SYS_MODULE. For software compatibility reasons,
50803+ /proc/kallsyms will be restricted to the root user. The RBAC
50804+ system can hide that entry even from root.
50805+
50806+ This option also prevents leaking of kernel addresses through
50807+ several /proc entries.
50808+
50809+ Note that this option is only effective provided the following
50810+ conditions are met:
50811+ 1) The kernel using grsecurity is not precompiled by some distribution
50812+ 2) You have also enabled GRKERNSEC_DMESG
50813+ 3) You are using the RBAC system and hiding other files such as your
50814+ kernel image and System.map. Alternatively, enabling this option
50815+ causes the permissions on /boot, /lib/modules, and the kernel
50816+ source directory to change at compile time to prevent
50817+ reading by non-root users.
50818+ If the above conditions are met, this option will aid in providing a
50819+ useful protection against local kernel exploitation of overflows
50820+ and arbitrary read/write vulnerabilities.
50821+
50822+config GRKERNSEC_KERN_LOCKOUT
50823+ bool "Active kernel exploit response"
50824+ default y if GRKERNSEC_CONFIG_AUTO
50825+ depends on X86 || ARM || PPC || SPARC
50826+ help
50827+ If you say Y here, when a PaX alert is triggered due to suspicious
50828+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50829+ or an OOPS occurs due to bad memory accesses, instead of just
50830+ terminating the offending process (and potentially allowing
50831+ a subsequent exploit from the same user), we will take one of two
50832+ actions:
50833+ If the user was root, we will panic the system
50834+ If the user was non-root, we will log the attempt, terminate
50835+ all processes owned by the user, then prevent them from creating
50836+ any new processes until the system is restarted
50837+ This deters repeated kernel exploitation/bruteforcing attempts
50838+ and is useful for later forensics.
50839+
50840+endmenu
50841+menu "Role Based Access Control Options"
50842+depends on GRKERNSEC
50843+
50844+config GRKERNSEC_RBAC_DEBUG
50845+ bool
50846+
50847+config GRKERNSEC_NO_RBAC
50848+ bool "Disable RBAC system"
50849+ help
50850+ If you say Y here, the /dev/grsec device will be removed from the kernel,
50851+ preventing the RBAC system from being enabled. You should only say Y
50852+ here if you have no intention of using the RBAC system, so as to prevent
50853+ an attacker with root access from misusing the RBAC system to hide files
50854+ and processes when loadable module support and /dev/[k]mem have been
50855+ locked down.
50856+
50857+config GRKERNSEC_ACL_HIDEKERN
50858+ bool "Hide kernel processes"
50859+ help
50860+ If you say Y here, all kernel threads will be hidden to all
50861+ processes but those whose subject has the "view hidden processes"
50862+ flag.
50863+
50864+config GRKERNSEC_ACL_MAXTRIES
50865+ int "Maximum tries before password lockout"
50866+ default 3
50867+ help
50868+ This option enforces the maximum number of times a user can attempt
50869+ to authorize themselves with the grsecurity RBAC system before being
50870+ denied the ability to attempt authorization again for a specified time.
50871+ The lower the number, the harder it will be to brute-force a password.
50872+
50873+config GRKERNSEC_ACL_TIMEOUT
50874+ int "Time to wait after max password tries, in seconds"
50875+ default 30
50876+ help
50877+ This option specifies the time the user must wait after attempting to
50878+ authorize to the RBAC system with the maximum number of invalid
50879+ passwords. The higher the number, the harder it will be to brute-force
50880+ a password.
50881+
50882+endmenu
50883+menu "Filesystem Protections"
50884+depends on GRKERNSEC
50885+
50886+config GRKERNSEC_PROC
50887+ bool "Proc restrictions"
50888+ default y if GRKERNSEC_CONFIG_AUTO
50889+ help
50890+ If you say Y here, the permissions of the /proc filesystem
50891+ will be altered to enhance system security and privacy. You MUST
50892+ choose either a user only restriction or a user and group restriction.
50893+ Depending upon the option you choose, you can either restrict users to
50894+ see only the processes they themselves run, or choose a group that can
50895+ view all processes and files normally restricted to root if you choose
50896+ the "restrict to user only" option. NOTE: If you're running identd or
50897+ ntpd as a non-root user, you will have to run it as the group you
50898+ specify here.
50899+
50900+config GRKERNSEC_PROC_USER
50901+ bool "Restrict /proc to user only"
50902+ depends on GRKERNSEC_PROC
50903+ help
50904+ If you say Y here, non-root users will only be able to view their own
50905+ processes, and restricts them from viewing network-related information,
50906+ and viewing kernel symbol and module information.
50907+
50908+config GRKERNSEC_PROC_USERGROUP
50909+ bool "Allow special group"
50910+ default y if GRKERNSEC_CONFIG_AUTO
50911+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50912+ help
50913+ If you say Y here, you will be able to select a group that will be
50914+ able to view all processes and network-related information. If you've
50915+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50916+ remain hidden. This option is useful if you want to run identd as
50917+ a non-root user. The group you select may also be chosen at boot time
50918+ via "grsec_proc_gid=" on the kernel commandline.
50919+
50920+config GRKERNSEC_PROC_GID
50921+ int "GID for special group"
50922+ depends on GRKERNSEC_PROC_USERGROUP
50923+ default 1001
50924+
50925+config GRKERNSEC_PROC_ADD
50926+ bool "Additional restrictions"
50927+ default y if GRKERNSEC_CONFIG_AUTO
50928+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50929+ help
50930+ If you say Y here, additional restrictions will be placed on
50931+ /proc that keep normal users from viewing device information and
50932+ slabinfo information that could be useful for exploits.
50933+
50934+config GRKERNSEC_LINK
50935+ bool "Linking restrictions"
50936+ default y if GRKERNSEC_CONFIG_AUTO
50937+ help
50938+ If you say Y here, /tmp race exploits will be prevented, since users
50939+ will no longer be able to follow symlinks owned by other users in
50940+ world-writable +t directories (e.g. /tmp), unless the owner of the
50941+ symlink is the owner of the directory. users will also not be
50942+ able to hardlink to files they do not own. If the sysctl option is
50943+ enabled, a sysctl option with name "linking_restrictions" is created.
50944+
50945+config GRKERNSEC_SYMLINKOWN
50946+ bool "Kernel-enforced SymlinksIfOwnerMatch"
50947+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50948+ help
50949+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
50950+ that prevents it from being used as a security feature. As Apache
50951+ verifies the symlink by performing a stat() against the target of
50952+ the symlink before it is followed, an attacker can setup a symlink
50953+ to point to a same-owned file, then replace the symlink with one
50954+ that targets another user's file just after Apache "validates" the
50955+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
50956+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50957+ will be in place for the group you specify. If the sysctl option
50958+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
50959+ created.
50960+
50961+config GRKERNSEC_SYMLINKOWN_GID
50962+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50963+ depends on GRKERNSEC_SYMLINKOWN
50964+ default 1006
50965+ help
50966+ Setting this GID determines what group kernel-enforced
50967+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50968+ is enabled, a sysctl option with name "symlinkown_gid" is created.
50969+
50970+config GRKERNSEC_FIFO
50971+ bool "FIFO restrictions"
50972+ default y if GRKERNSEC_CONFIG_AUTO
50973+ help
50974+ If you say Y here, users will not be able to write to FIFOs they don't
50975+ own in world-writable +t directories (e.g. /tmp), unless the owner of
50976+ the FIFO is the same owner of the directory it's held in. If the sysctl
50977+ option is enabled, a sysctl option with name "fifo_restrictions" is
50978+ created.
50979+
50980+config GRKERNSEC_SYSFS_RESTRICT
50981+ bool "Sysfs/debugfs restriction"
50982+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50983+ depends on SYSFS
50984+ help
50985+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50986+ any filesystem normally mounted under it (e.g. debugfs) will be
50987+ mostly accessible only by root. These filesystems generally provide access
50988+ to hardware and debug information that isn't appropriate for unprivileged
50989+ users of the system. Sysfs and debugfs have also become a large source
50990+ of new vulnerabilities, ranging from infoleaks to local compromise.
50991+ There has been very little oversight with an eye toward security involved
50992+ in adding new exporters of information to these filesystems, so their
50993+ use is discouraged.
50994+ For reasons of compatibility, a few directories have been whitelisted
50995+ for access by non-root users:
50996+ /sys/fs/selinux
50997+ /sys/fs/fuse
50998+ /sys/devices/system/cpu
50999+
51000+config GRKERNSEC_ROFS
51001+ bool "Runtime read-only mount protection"
51002+ help
51003+ If you say Y here, a sysctl option with name "romount_protect" will
51004+ be created. By setting this option to 1 at runtime, filesystems
51005+ will be protected in the following ways:
51006+ * No new writable mounts will be allowed
51007+ * Existing read-only mounts won't be able to be remounted read/write
51008+ * Write operations will be denied on all block devices
51009+ This option acts independently of grsec_lock: once it is set to 1,
51010+ it cannot be turned off. Therefore, please be mindful of the resulting
51011+ behavior if this option is enabled in an init script on a read-only
51012+ filesystem. This feature is mainly intended for secure embedded systems.
51013+
51014+config GRKERNSEC_CHROOT
51015+ bool "Chroot jail restrictions"
51016+ default y if GRKERNSEC_CONFIG_AUTO
51017+ help
51018+ If you say Y here, you will be able to choose several options that will
51019+ make breaking out of a chrooted jail much more difficult. If you
51020+ encounter no software incompatibilities with the following options, it
51021+ is recommended that you enable each one.
51022+
51023+config GRKERNSEC_CHROOT_MOUNT
51024+ bool "Deny mounts"
51025+ default y if GRKERNSEC_CONFIG_AUTO
51026+ depends on GRKERNSEC_CHROOT
51027+ help
51028+ If you say Y here, processes inside a chroot will not be able to
51029+ mount or remount filesystems. If the sysctl option is enabled, a
51030+ sysctl option with name "chroot_deny_mount" is created.
51031+
51032+config GRKERNSEC_CHROOT_DOUBLE
51033+ bool "Deny double-chroots"
51034+ default y if GRKERNSEC_CONFIG_AUTO
51035+ depends on GRKERNSEC_CHROOT
51036+ help
51037+ If you say Y here, processes inside a chroot will not be able to chroot
51038+ again outside the chroot. This is a widely used method of breaking
51039+ out of a chroot jail and should not be allowed. If the sysctl
51040+ option is enabled, a sysctl option with name
51041+ "chroot_deny_chroot" is created.
51042+
51043+config GRKERNSEC_CHROOT_PIVOT
51044+ bool "Deny pivot_root in chroot"
51045+ default y if GRKERNSEC_CONFIG_AUTO
51046+ depends on GRKERNSEC_CHROOT
51047+ help
51048+ If you say Y here, processes inside a chroot will not be able to use
51049+ a function called pivot_root() that was introduced in Linux 2.3.41. It
51050+ works similar to chroot in that it changes the root filesystem. This
51051+ function could be misused in a chrooted process to attempt to break out
51052+ of the chroot, and therefore should not be allowed. If the sysctl
51053+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
51054+ created.
51055+
51056+config GRKERNSEC_CHROOT_CHDIR
51057+ bool "Enforce chdir(\"/\") on all chroots"
51058+ default y if GRKERNSEC_CONFIG_AUTO
51059+ depends on GRKERNSEC_CHROOT
51060+ help
51061+ If you say Y here, the current working directory of all newly-chrooted
51062+ applications will be set to the the root directory of the chroot.
51063+ The man page on chroot(2) states:
51064+ Note that this call does not change the current working
51065+ directory, so that `.' can be outside the tree rooted at
51066+ `/'. In particular, the super-user can escape from a
51067+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51068+
51069+ It is recommended that you say Y here, since it's not known to break
51070+ any software. If the sysctl option is enabled, a sysctl option with
51071+ name "chroot_enforce_chdir" is created.
51072+
51073+config GRKERNSEC_CHROOT_CHMOD
51074+ bool "Deny (f)chmod +s"
51075+ default y if GRKERNSEC_CONFIG_AUTO
51076+ depends on GRKERNSEC_CHROOT
51077+ help
51078+ If you say Y here, processes inside a chroot will not be able to chmod
51079+ or fchmod files to make them have suid or sgid bits. This protects
51080+ against another published method of breaking a chroot. If the sysctl
51081+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
51082+ created.
51083+
51084+config GRKERNSEC_CHROOT_FCHDIR
51085+ bool "Deny fchdir out of chroot"
51086+ default y if GRKERNSEC_CONFIG_AUTO
51087+ depends on GRKERNSEC_CHROOT
51088+ help
51089+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
51090+ to a file descriptor of the chrooting process that points to a directory
51091+ outside the filesystem will be stopped. If the sysctl option
51092+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51093+
51094+config GRKERNSEC_CHROOT_MKNOD
51095+ bool "Deny mknod"
51096+ default y if GRKERNSEC_CONFIG_AUTO
51097+ depends on GRKERNSEC_CHROOT
51098+ help
51099+ If you say Y here, processes inside a chroot will not be allowed to
51100+ mknod. The problem with using mknod inside a chroot is that it
51101+ would allow an attacker to create a device entry that is the same
51102+ as one on the physical root of your system, which could range from
51103+ anything from the console device to a device for your harddrive (which
51104+ they could then use to wipe the drive or steal data). It is recommended
51105+ that you say Y here, unless you run into software incompatibilities.
51106+ If the sysctl option is enabled, a sysctl option with name
51107+ "chroot_deny_mknod" is created.
51108+
51109+config GRKERNSEC_CHROOT_SHMAT
51110+ bool "Deny shmat() out of chroot"
51111+ default y if GRKERNSEC_CONFIG_AUTO
51112+ depends on GRKERNSEC_CHROOT
51113+ help
51114+ If you say Y here, processes inside a chroot will not be able to attach
51115+ to shared memory segments that were created outside of the chroot jail.
51116+ It is recommended that you say Y here. If the sysctl option is enabled,
51117+ a sysctl option with name "chroot_deny_shmat" is created.
51118+
51119+config GRKERNSEC_CHROOT_UNIX
51120+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
51121+ default y if GRKERNSEC_CONFIG_AUTO
51122+ depends on GRKERNSEC_CHROOT
51123+ help
51124+ If you say Y here, processes inside a chroot will not be able to
51125+ connect to abstract (meaning not belonging to a filesystem) Unix
51126+ domain sockets that were bound outside of a chroot. It is recommended
51127+ that you say Y here. If the sysctl option is enabled, a sysctl option
51128+ with name "chroot_deny_unix" is created.
51129+
51130+config GRKERNSEC_CHROOT_FINDTASK
51131+ bool "Protect outside processes"
51132+ default y if GRKERNSEC_CONFIG_AUTO
51133+ depends on GRKERNSEC_CHROOT
51134+ help
51135+ If you say Y here, processes inside a chroot will not be able to
51136+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51137+ getsid, or view any process outside of the chroot. If the sysctl
51138+ option is enabled, a sysctl option with name "chroot_findtask" is
51139+ created.
51140+
51141+config GRKERNSEC_CHROOT_NICE
51142+ bool "Restrict priority changes"
51143+ default y if GRKERNSEC_CONFIG_AUTO
51144+ depends on GRKERNSEC_CHROOT
51145+ help
51146+ If you say Y here, processes inside a chroot will not be able to raise
51147+ the priority of processes in the chroot, or alter the priority of
51148+ processes outside the chroot. This provides more security than simply
51149+ removing CAP_SYS_NICE from the process' capability set. If the
51150+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51151+ is created.
51152+
51153+config GRKERNSEC_CHROOT_SYSCTL
51154+ bool "Deny sysctl writes"
51155+ default y if GRKERNSEC_CONFIG_AUTO
51156+ depends on GRKERNSEC_CHROOT
51157+ help
51158+ If you say Y here, an attacker in a chroot will not be able to
51159+ write to sysctl entries, either by sysctl(2) or through a /proc
51160+ interface. It is strongly recommended that you say Y here. If the
51161+ sysctl option is enabled, a sysctl option with name
51162+ "chroot_deny_sysctl" is created.
51163+
51164+config GRKERNSEC_CHROOT_CAPS
51165+ bool "Capability restrictions"
51166+ default y if GRKERNSEC_CONFIG_AUTO
51167+ depends on GRKERNSEC_CHROOT
51168+ help
51169+ If you say Y here, the capabilities on all processes within a
51170+ chroot jail will be lowered to stop module insertion, raw i/o,
51171+ system and net admin tasks, rebooting the system, modifying immutable
51172+ files, modifying IPC owned by another, and changing the system time.
51173+ This is left an option because it can break some apps. Disable this
51174+ if your chrooted apps are having problems performing those kinds of
51175+ tasks. If the sysctl option is enabled, a sysctl option with
51176+ name "chroot_caps" is created.
51177+
51178+endmenu
51179+menu "Kernel Auditing"
51180+depends on GRKERNSEC
51181+
51182+config GRKERNSEC_AUDIT_GROUP
51183+ bool "Single group for auditing"
51184+ help
51185+ If you say Y here, the exec, chdir, and (un)mount logging features
51186+ will only operate on a group you specify. This option is recommended
51187+ if you only want to watch certain users instead of having a large
51188+ amount of logs from the entire system. If the sysctl option is enabled,
51189+ a sysctl option with name "audit_group" is created.
51190+
51191+config GRKERNSEC_AUDIT_GID
51192+ int "GID for auditing"
51193+ depends on GRKERNSEC_AUDIT_GROUP
51194+ default 1007
51195+
51196+config GRKERNSEC_EXECLOG
51197+ bool "Exec logging"
51198+ help
51199+ If you say Y here, all execve() calls will be logged (since the
51200+ other exec*() calls are frontends to execve(), all execution
51201+ will be logged). Useful for shell-servers that like to keep track
51202+ of their users. If the sysctl option is enabled, a sysctl option with
51203+ name "exec_logging" is created.
51204+ WARNING: This option when enabled will produce a LOT of logs, especially
51205+ on an active system.
51206+
51207+config GRKERNSEC_RESLOG
51208+ bool "Resource logging"
51209+ default y if GRKERNSEC_CONFIG_AUTO
51210+ help
51211+ If you say Y here, all attempts to overstep resource limits will
51212+ be logged with the resource name, the requested size, and the current
51213+ limit. It is highly recommended that you say Y here. If the sysctl
51214+ option is enabled, a sysctl option with name "resource_logging" is
51215+ created. If the RBAC system is enabled, the sysctl value is ignored.
51216+
51217+config GRKERNSEC_CHROOT_EXECLOG
51218+ bool "Log execs within chroot"
51219+ help
51220+ If you say Y here, all executions inside a chroot jail will be logged
51221+ to syslog. This can cause a large amount of logs if certain
51222+ applications (eg. djb's daemontools) are installed on the system, and
51223+ is therefore left as an option. If the sysctl option is enabled, a
51224+ sysctl option with name "chroot_execlog" is created.
51225+
51226+config GRKERNSEC_AUDIT_PTRACE
51227+ bool "Ptrace logging"
51228+ help
51229+ If you say Y here, all attempts to attach to a process via ptrace
51230+ will be logged. If the sysctl option is enabled, a sysctl option
51231+ with name "audit_ptrace" is created.
51232+
51233+config GRKERNSEC_AUDIT_CHDIR
51234+ bool "Chdir logging"
51235+ help
51236+ If you say Y here, all chdir() calls will be logged. If the sysctl
51237+ option is enabled, a sysctl option with name "audit_chdir" is created.
51238+
51239+config GRKERNSEC_AUDIT_MOUNT
51240+ bool "(Un)Mount logging"
51241+ help
51242+ If you say Y here, all mounts and unmounts will be logged. If the
51243+ sysctl option is enabled, a sysctl option with name "audit_mount" is
51244+ created.
51245+
51246+config GRKERNSEC_SIGNAL
51247+ bool "Signal logging"
51248+ default y if GRKERNSEC_CONFIG_AUTO
51249+ help
51250+ If you say Y here, certain important signals will be logged, such as
51251+ SIGSEGV, which will as a result inform you of when a error in a program
51252+ occurred, which in some cases could mean a possible exploit attempt.
51253+ If the sysctl option is enabled, a sysctl option with name
51254+ "signal_logging" is created.
51255+
51256+config GRKERNSEC_FORKFAIL
51257+ bool "Fork failure logging"
51258+ help
51259+ If you say Y here, all failed fork() attempts will be logged.
51260+ This could suggest a fork bomb, or someone attempting to overstep
51261+ their process limit. If the sysctl option is enabled, a sysctl option
51262+ with name "forkfail_logging" is created.
51263+
51264+config GRKERNSEC_TIME
51265+ bool "Time change logging"
51266+ default y if GRKERNSEC_CONFIG_AUTO
51267+ help
51268+ If you say Y here, any changes of the system clock will be logged.
51269+ If the sysctl option is enabled, a sysctl option with name
51270+ "timechange_logging" is created.
51271+
51272+config GRKERNSEC_PROC_IPADDR
51273+ bool "/proc/<pid>/ipaddr support"
51274+ default y if GRKERNSEC_CONFIG_AUTO
51275+ help
51276+ If you say Y here, a new entry will be added to each /proc/<pid>
51277+ directory that contains the IP address of the person using the task.
51278+ The IP is carried across local TCP and AF_UNIX stream sockets.
51279+ This information can be useful for IDS/IPSes to perform remote response
51280+ to a local attack. The entry is readable by only the owner of the
51281+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51282+ the RBAC system), and thus does not create privacy concerns.
51283+
51284+config GRKERNSEC_RWXMAP_LOG
51285+ bool 'Denied RWX mmap/mprotect logging'
51286+ default y if GRKERNSEC_CONFIG_AUTO
51287+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51288+ help
51289+ If you say Y here, calls to mmap() and mprotect() with explicit
51290+ usage of PROT_WRITE and PROT_EXEC together will be logged when
51291+ denied by the PAX_MPROTECT feature. If the sysctl option is
51292+ enabled, a sysctl option with name "rwxmap_logging" is created.
51293+
51294+config GRKERNSEC_AUDIT_TEXTREL
51295+ bool 'ELF text relocations logging (READ HELP)'
51296+ depends on PAX_MPROTECT
51297+ help
51298+ If you say Y here, text relocations will be logged with the filename
51299+ of the offending library or binary. The purpose of the feature is
51300+ to help Linux distribution developers get rid of libraries and
51301+ binaries that need text relocations which hinder the future progress
51302+ of PaX. Only Linux distribution developers should say Y here, and
51303+ never on a production machine, as this option creates an information
51304+ leak that could aid an attacker in defeating the randomization of
51305+ a single memory region. If the sysctl option is enabled, a sysctl
51306+ option with name "audit_textrel" is created.
51307+
51308+endmenu
51309+
51310+menu "Executable Protections"
51311+depends on GRKERNSEC
51312+
51313+config GRKERNSEC_DMESG
51314+ bool "Dmesg(8) restriction"
51315+ default y if GRKERNSEC_CONFIG_AUTO
51316+ help
51317+ If you say Y here, non-root users will not be able to use dmesg(8)
51318+ to view up to the last 4kb of messages in the kernel's log buffer.
51319+ The kernel's log buffer often contains kernel addresses and other
51320+ identifying information useful to an attacker in fingerprinting a
51321+ system for a targeted exploit.
51322+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
51323+ created.
51324+
51325+config GRKERNSEC_HARDEN_PTRACE
51326+ bool "Deter ptrace-based process snooping"
51327+ default y if GRKERNSEC_CONFIG_AUTO
51328+ help
51329+ If you say Y here, TTY sniffers and other malicious monitoring
51330+ programs implemented through ptrace will be defeated. If you
51331+ have been using the RBAC system, this option has already been
51332+ enabled for several years for all users, with the ability to make
51333+ fine-grained exceptions.
51334+
51335+ This option only affects the ability of non-root users to ptrace
51336+ processes that are not a descendent of the ptracing process.
51337+ This means that strace ./binary and gdb ./binary will still work,
51338+ but attaching to arbitrary processes will not. If the sysctl
51339+ option is enabled, a sysctl option with name "harden_ptrace" is
51340+ created.
51341+
51342+config GRKERNSEC_PTRACE_READEXEC
51343+ bool "Require read access to ptrace sensitive binaries"
51344+ default y if GRKERNSEC_CONFIG_AUTO
51345+ help
51346+ If you say Y here, unprivileged users will not be able to ptrace unreadable
51347+ binaries. This option is useful in environments that
51348+ remove the read bits (e.g. file mode 4711) from suid binaries to
51349+ prevent infoleaking of their contents. This option adds
51350+ consistency to the use of that file mode, as the binary could normally
51351+ be read out when run without privileges while ptracing.
51352+
51353+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51354+ is created.
51355+
51356+config GRKERNSEC_SETXID
51357+ bool "Enforce consistent multithreaded privileges"
51358+ default y if GRKERNSEC_CONFIG_AUTO
51359+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51360+ help
51361+ If you say Y here, a change from a root uid to a non-root uid
51362+ in a multithreaded application will cause the resulting uids,
51363+ gids, supplementary groups, and capabilities in that thread
51364+ to be propagated to the other threads of the process. In most
51365+ cases this is unnecessary, as glibc will emulate this behavior
51366+ on behalf of the application. Other libcs do not act in the
51367+ same way, allowing the other threads of the process to continue
51368+ running with root privileges. If the sysctl option is enabled,
51369+ a sysctl option with name "consistent_setxid" is created.
51370+
51371+config GRKERNSEC_TPE
51372+ bool "Trusted Path Execution (TPE)"
51373+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51374+ help
51375+ If you say Y here, you will be able to choose a gid to add to the
51376+ supplementary groups of users you want to mark as "untrusted."
51377+ These users will not be able to execute any files that are not in
51378+ root-owned directories writable only by root. If the sysctl option
51379+ is enabled, a sysctl option with name "tpe" is created.
51380+
51381+config GRKERNSEC_TPE_ALL
51382+ bool "Partially restrict all non-root users"
51383+ depends on GRKERNSEC_TPE
51384+ help
51385+ If you say Y here, all non-root users will be covered under
51386+ a weaker TPE restriction. This is separate from, and in addition to,
51387+ the main TPE options that you have selected elsewhere. Thus, if a
51388+ "trusted" GID is chosen, this restriction applies to even that GID.
51389+ Under this restriction, all non-root users will only be allowed to
51390+ execute files in directories they own that are not group or
51391+ world-writable, or in directories owned by root and writable only by
51392+ root. If the sysctl option is enabled, a sysctl option with name
51393+ "tpe_restrict_all" is created.
51394+
51395+config GRKERNSEC_TPE_INVERT
51396+ bool "Invert GID option"
51397+ depends on GRKERNSEC_TPE
51398+ help
51399+ If you say Y here, the group you specify in the TPE configuration will
51400+ decide what group TPE restrictions will be *disabled* for. This
51401+ option is useful if you want TPE restrictions to be applied to most
51402+ users on the system. If the sysctl option is enabled, a sysctl option
51403+ with name "tpe_invert" is created. Unlike other sysctl options, this
51404+ entry will default to on for backward-compatibility.
51405+
51406+config GRKERNSEC_TPE_GID
51407+ int
51408+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51409+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51410+
51411+config GRKERNSEC_TPE_UNTRUSTED_GID
51412+ int "GID for TPE-untrusted users"
51413+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51414+ default 1005
51415+ help
51416+ Setting this GID determines what group TPE restrictions will be
51417+ *enabled* for. If the sysctl option is enabled, a sysctl option
51418+ with name "tpe_gid" is created.
51419+
51420+config GRKERNSEC_TPE_TRUSTED_GID
51421+ int "GID for TPE-trusted users"
51422+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51423+ default 1005
51424+ help
51425+ Setting this GID determines what group TPE restrictions will be
51426+ *disabled* for. If the sysctl option is enabled, a sysctl option
51427+ with name "tpe_gid" is created.
51428+
51429+endmenu
51430+menu "Network Protections"
51431+depends on GRKERNSEC
51432+
51433+config GRKERNSEC_RANDNET
51434+ bool "Larger entropy pools"
51435+ default y if GRKERNSEC_CONFIG_AUTO
51436+ help
51437+ If you say Y here, the entropy pools used for many features of Linux
51438+ and grsecurity will be doubled in size. Since several grsecurity
51439+ features use additional randomness, it is recommended that you say Y
51440+ here. Saying Y here has a similar effect as modifying
51441+ /proc/sys/kernel/random/poolsize.
51442+
51443+config GRKERNSEC_BLACKHOLE
51444+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51445+ default y if GRKERNSEC_CONFIG_AUTO
51446+ depends on NET
51447+ help
51448+ If you say Y here, neither TCP resets nor ICMP
51449+ destination-unreachable packets will be sent in response to packets
51450+ sent to ports for which no associated listening process exists.
51451+ This feature supports both IPV4 and IPV6 and exempts the
51452+ loopback interface from blackholing. Enabling this feature
51453+ makes a host more resilient to DoS attacks and reduces network
51454+ visibility against scanners.
51455+
51456+ The blackhole feature as-implemented is equivalent to the FreeBSD
51457+ blackhole feature, as it prevents RST responses to all packets, not
51458+ just SYNs. Under most application behavior this causes no
51459+ problems, but applications (like haproxy) may not close certain
51460+ connections in a way that cleanly terminates them on the remote
51461+ end, leaving the remote host in LAST_ACK state. Because of this
51462+ side-effect and to prevent intentional LAST_ACK DoSes, this
51463+ feature also adds automatic mitigation against such attacks.
51464+ The mitigation drastically reduces the amount of time a socket
51465+ can spend in LAST_ACK state. If you're using haproxy and not
51466+ all servers it connects to have this option enabled, consider
51467+ disabling this feature on the haproxy host.
51468+
51469+ If the sysctl option is enabled, two sysctl options with names
51470+ "ip_blackhole" and "lastack_retries" will be created.
51471+ While "ip_blackhole" takes the standard zero/non-zero on/off
51472+ toggle, "lastack_retries" uses the same kinds of values as
51473+ "tcp_retries1" and "tcp_retries2". The default value of 4
51474+ prevents a socket from lasting more than 45 seconds in LAST_ACK
51475+ state.
51476+
51477+config GRKERNSEC_SOCKET
51478+ bool "Socket restrictions"
51479+ depends on NET
51480+ help
51481+ If you say Y here, you will be able to choose from several options.
51482+ If you assign a GID on your system and add it to the supplementary
51483+ groups of users you want to restrict socket access to, this patch
51484+ will perform up to three things, based on the option(s) you choose.
51485+
51486+config GRKERNSEC_SOCKET_ALL
51487+ bool "Deny any sockets to group"
51488+ depends on GRKERNSEC_SOCKET
51489+ help
51490+ If you say Y here, you will be able to choose a GID of whose users will
51491+ be unable to connect to other hosts from your machine or run server
51492+ applications from your machine. If the sysctl option is enabled, a
51493+ sysctl option with name "socket_all" is created.
51494+
51495+config GRKERNSEC_SOCKET_ALL_GID
51496+ int "GID to deny all sockets for"
51497+ depends on GRKERNSEC_SOCKET_ALL
51498+ default 1004
51499+ help
51500+ Here you can choose the GID to disable socket access for. Remember to
51501+ add the users you want socket access disabled for to the GID
51502+ specified here. If the sysctl option is enabled, a sysctl option
51503+ with name "socket_all_gid" is created.
51504+
51505+config GRKERNSEC_SOCKET_CLIENT
51506+ bool "Deny client sockets to group"
51507+ depends on GRKERNSEC_SOCKET
51508+ help
51509+ If you say Y here, you will be able to choose a GID of whose users will
51510+ be unable to connect to other hosts from your machine, but will be
51511+ able to run servers. If this option is enabled, all users in the group
51512+ you specify will have to use passive mode when initiating ftp transfers
51513+ from the shell on your machine. If the sysctl option is enabled, a
51514+ sysctl option with name "socket_client" is created.
51515+
51516+config GRKERNSEC_SOCKET_CLIENT_GID
51517+ int "GID to deny client sockets for"
51518+ depends on GRKERNSEC_SOCKET_CLIENT
51519+ default 1003
51520+ help
51521+ Here you can choose the GID to disable client socket access for.
51522+ Remember to add the users you want client socket access disabled for to
51523+ the GID specified here. If the sysctl option is enabled, a sysctl
51524+ option with name "socket_client_gid" is created.
51525+
51526+config GRKERNSEC_SOCKET_SERVER
51527+ bool "Deny server sockets to group"
51528+ depends on GRKERNSEC_SOCKET
51529+ help
51530+ If you say Y here, you will be able to choose a GID of whose users will
51531+ be unable to run server applications from your machine. If the sysctl
51532+ option is enabled, a sysctl option with name "socket_server" is created.
51533+
51534+config GRKERNSEC_SOCKET_SERVER_GID
51535+ int "GID to deny server sockets for"
51536+ depends on GRKERNSEC_SOCKET_SERVER
51537+ default 1002
51538+ help
51539+ Here you can choose the GID to disable server socket access for.
51540+ Remember to add the users you want server socket access disabled for to
51541+ the GID specified here. If the sysctl option is enabled, a sysctl
51542+ option with name "socket_server_gid" is created.
51543+
51544+endmenu
51545+menu "Sysctl Support"
51546+depends on GRKERNSEC && SYSCTL
51547+
51548+config GRKERNSEC_SYSCTL
51549+ bool "Sysctl support"
51550+ default y if GRKERNSEC_CONFIG_AUTO
51551+ help
51552+ If you say Y here, you will be able to change the options that
51553+ grsecurity runs with at bootup, without having to recompile your
51554+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51555+ to enable (1) or disable (0) various features. All the sysctl entries
51556+ are mutable until the "grsec_lock" entry is set to a non-zero value.
51557+ All features enabled in the kernel configuration are disabled at boot
51558+ if you do not say Y to the "Turn on features by default" option.
51559+ All options should be set at startup, and the grsec_lock entry should
51560+ be set to a non-zero value after all the options are set.
51561+ *THIS IS EXTREMELY IMPORTANT*
51562+
51563+config GRKERNSEC_SYSCTL_DISTRO
51564+ bool "Extra sysctl support for distro makers (READ HELP)"
51565+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51566+ help
51567+ If you say Y here, additional sysctl options will be created
51568+ for features that affect processes running as root. Therefore,
51569+ it is critical when using this option that the grsec_lock entry be
51570+ enabled after boot. Only distros with prebuilt kernel packages
51571+ with this option enabled that can ensure grsec_lock is enabled
51572+ after boot should use this option.
51573+ *Failure to set grsec_lock after boot makes all grsec features
51574+ this option covers useless*
51575+
51576+ Currently this option creates the following sysctl entries:
51577+ "Disable Privileged I/O": "disable_priv_io"
51578+
51579+config GRKERNSEC_SYSCTL_ON
51580+ bool "Turn on features by default"
51581+ default y if GRKERNSEC_CONFIG_AUTO
51582+ depends on GRKERNSEC_SYSCTL
51583+ help
51584+ If you say Y here, instead of having all features enabled in the
51585+ kernel configuration disabled at boot time, the features will be
51586+ enabled at boot time. It is recommended you say Y here unless
51587+ there is some reason you would want all sysctl-tunable features to
51588+ be disabled by default. As mentioned elsewhere, it is important
51589+ to enable the grsec_lock entry once you have finished modifying
51590+ the sysctl entries.
51591+
51592+endmenu
51593+menu "Logging Options"
51594+depends on GRKERNSEC
51595+
51596+config GRKERNSEC_FLOODTIME
51597+ int "Seconds in between log messages (minimum)"
51598+ default 10
51599+ help
51600+ This option allows you to enforce the number of seconds between
51601+ grsecurity log messages. The default should be suitable for most
51602+ people, however, if you choose to change it, choose a value small enough
51603+ to allow informative logs to be produced, but large enough to
51604+ prevent flooding.
51605+
51606+config GRKERNSEC_FLOODBURST
51607+ int "Number of messages in a burst (maximum)"
51608+ default 6
51609+ help
51610+ This option allows you to choose the maximum number of messages allowed
51611+ within the flood time interval you chose in a separate option. The
51612+ default should be suitable for most people, however if you find that
51613+ many of your logs are being interpreted as flooding, you may want to
51614+ raise this value.
51615+
51616+endmenu
51617diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51618new file mode 100644
51619index 0000000..1b9afa9
51620--- /dev/null
51621+++ b/grsecurity/Makefile
51622@@ -0,0 +1,38 @@
51623+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51624+# during 2001-2009 it has been completely redesigned by Brad Spengler
51625+# into an RBAC system
51626+#
51627+# All code in this directory and various hooks inserted throughout the kernel
51628+# are copyright Brad Spengler - Open Source Security, Inc., and released
51629+# under the GPL v2 or higher
51630+
51631+KBUILD_CFLAGS += -Werror
51632+
51633+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51634+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
51635+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51636+
51637+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51638+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51639+ gracl_learn.o grsec_log.o
51640+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51641+
51642+ifdef CONFIG_NET
51643+obj-y += grsec_sock.o
51644+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51645+endif
51646+
51647+ifndef CONFIG_GRKERNSEC
51648+obj-y += grsec_disabled.o
51649+endif
51650+
51651+ifdef CONFIG_GRKERNSEC_HIDESYM
51652+extra-y := grsec_hidesym.o
51653+$(obj)/grsec_hidesym.o:
51654+ @-chmod -f 500 /boot
51655+ @-chmod -f 500 /lib/modules
51656+ @-chmod -f 500 /lib64/modules
51657+ @-chmod -f 500 /lib32/modules
51658+ @-chmod -f 700 .
51659+ @echo ' grsec: protected kernel image paths'
51660+endif
51661diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51662new file mode 100644
51663index 0000000..07cd799
51664--- /dev/null
51665+++ b/grsecurity/gracl.c
51666@@ -0,0 +1,4017 @@
51667+#include <linux/kernel.h>
51668+#include <linux/module.h>
51669+#include <linux/sched.h>
51670+#include <linux/mm.h>
51671+#include <linux/file.h>
51672+#include <linux/fs.h>
51673+#include <linux/namei.h>
51674+#include <linux/mount.h>
51675+#include <linux/tty.h>
51676+#include <linux/proc_fs.h>
51677+#include <linux/lglock.h>
51678+#include <linux/slab.h>
51679+#include <linux/vmalloc.h>
51680+#include <linux/types.h>
51681+#include <linux/sysctl.h>
51682+#include <linux/netdevice.h>
51683+#include <linux/ptrace.h>
51684+#include <linux/gracl.h>
51685+#include <linux/gralloc.h>
51686+#include <linux/security.h>
51687+#include <linux/grinternal.h>
51688+#include <linux/pid_namespace.h>
51689+#include <linux/stop_machine.h>
51690+#include <linux/fdtable.h>
51691+#include <linux/percpu.h>
51692+#include <linux/lglock.h>
51693+#include "../fs/mount.h"
51694+
51695+#include <asm/uaccess.h>
51696+#include <asm/errno.h>
51697+#include <asm/mman.h>
51698+
51699+extern struct lglock vfsmount_lock;
51700+
51701+static struct acl_role_db acl_role_set;
51702+static struct name_db name_set;
51703+static struct inodev_db inodev_set;
51704+
51705+/* for keeping track of userspace pointers used for subjects, so we
51706+ can share references in the kernel as well
51707+*/
51708+
51709+static struct path real_root;
51710+
51711+static struct acl_subj_map_db subj_map_set;
51712+
51713+static struct acl_role_label *default_role;
51714+
51715+static struct acl_role_label *role_list;
51716+
51717+static u16 acl_sp_role_value;
51718+
51719+extern char *gr_shared_page[4];
51720+static DEFINE_MUTEX(gr_dev_mutex);
51721+DEFINE_RWLOCK(gr_inode_lock);
51722+
51723+struct gr_arg *gr_usermode;
51724+
51725+static unsigned int gr_status __read_only = GR_STATUS_INIT;
51726+
51727+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51728+extern void gr_clear_learn_entries(void);
51729+
51730+#ifdef CONFIG_GRKERNSEC_RESLOG
51731+extern void gr_log_resource(const struct task_struct *task,
51732+ const int res, const unsigned long wanted, const int gt);
51733+#endif
51734+
51735+unsigned char *gr_system_salt;
51736+unsigned char *gr_system_sum;
51737+
51738+static struct sprole_pw **acl_special_roles = NULL;
51739+static __u16 num_sprole_pws = 0;
51740+
51741+static struct acl_role_label *kernel_role = NULL;
51742+
51743+static unsigned int gr_auth_attempts = 0;
51744+static unsigned long gr_auth_expires = 0UL;
51745+
51746+#ifdef CONFIG_NET
51747+extern struct vfsmount *sock_mnt;
51748+#endif
51749+
51750+extern struct vfsmount *pipe_mnt;
51751+extern struct vfsmount *shm_mnt;
51752+#ifdef CONFIG_HUGETLBFS
51753+extern struct vfsmount *hugetlbfs_vfsmount;
51754+#endif
51755+
51756+static struct acl_object_label *fakefs_obj_rw;
51757+static struct acl_object_label *fakefs_obj_rwx;
51758+
51759+extern int gr_init_uidset(void);
51760+extern void gr_free_uidset(void);
51761+extern void gr_remove_uid(uid_t uid);
51762+extern int gr_find_uid(uid_t uid);
51763+
51764+__inline__ int
51765+gr_acl_is_enabled(void)
51766+{
51767+ return (gr_status & GR_READY);
51768+}
51769+
51770+#ifdef CONFIG_BTRFS_FS
51771+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51772+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51773+#endif
51774+
51775+static inline dev_t __get_dev(const struct dentry *dentry)
51776+{
51777+#ifdef CONFIG_BTRFS_FS
51778+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51779+ return get_btrfs_dev_from_inode(dentry->d_inode);
51780+ else
51781+#endif
51782+ return dentry->d_inode->i_sb->s_dev;
51783+}
51784+
51785+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51786+{
51787+ return __get_dev(dentry);
51788+}
51789+
51790+static char gr_task_roletype_to_char(struct task_struct *task)
51791+{
51792+ switch (task->role->roletype &
51793+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51794+ GR_ROLE_SPECIAL)) {
51795+ case GR_ROLE_DEFAULT:
51796+ return 'D';
51797+ case GR_ROLE_USER:
51798+ return 'U';
51799+ case GR_ROLE_GROUP:
51800+ return 'G';
51801+ case GR_ROLE_SPECIAL:
51802+ return 'S';
51803+ }
51804+
51805+ return 'X';
51806+}
51807+
51808+char gr_roletype_to_char(void)
51809+{
51810+ return gr_task_roletype_to_char(current);
51811+}
51812+
51813+__inline__ int
51814+gr_acl_tpe_check(void)
51815+{
51816+ if (unlikely(!(gr_status & GR_READY)))
51817+ return 0;
51818+ if (current->role->roletype & GR_ROLE_TPE)
51819+ return 1;
51820+ else
51821+ return 0;
51822+}
51823+
51824+int
51825+gr_handle_rawio(const struct inode *inode)
51826+{
51827+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51828+ if (inode && S_ISBLK(inode->i_mode) &&
51829+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51830+ !capable(CAP_SYS_RAWIO))
51831+ return 1;
51832+#endif
51833+ return 0;
51834+}
51835+
51836+static int
51837+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51838+{
51839+ if (likely(lena != lenb))
51840+ return 0;
51841+
51842+ return !memcmp(a, b, lena);
51843+}
51844+
51845+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51846+{
51847+ *buflen -= namelen;
51848+ if (*buflen < 0)
51849+ return -ENAMETOOLONG;
51850+ *buffer -= namelen;
51851+ memcpy(*buffer, str, namelen);
51852+ return 0;
51853+}
51854+
51855+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51856+{
51857+ return prepend(buffer, buflen, name->name, name->len);
51858+}
51859+
51860+static int prepend_path(const struct path *path, struct path *root,
51861+ char **buffer, int *buflen)
51862+{
51863+ struct dentry *dentry = path->dentry;
51864+ struct vfsmount *vfsmnt = path->mnt;
51865+ struct mount *mnt = real_mount(vfsmnt);
51866+ bool slash = false;
51867+ int error = 0;
51868+
51869+ while (dentry != root->dentry || vfsmnt != root->mnt) {
51870+ struct dentry * parent;
51871+
51872+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51873+ /* Global root? */
51874+ if (!mnt_has_parent(mnt)) {
51875+ goto out;
51876+ }
51877+ dentry = mnt->mnt_mountpoint;
51878+ mnt = mnt->mnt_parent;
51879+ vfsmnt = &mnt->mnt;
51880+ continue;
51881+ }
51882+ parent = dentry->d_parent;
51883+ prefetch(parent);
51884+ spin_lock(&dentry->d_lock);
51885+ error = prepend_name(buffer, buflen, &dentry->d_name);
51886+ spin_unlock(&dentry->d_lock);
51887+ if (!error)
51888+ error = prepend(buffer, buflen, "/", 1);
51889+ if (error)
51890+ break;
51891+
51892+ slash = true;
51893+ dentry = parent;
51894+ }
51895+
51896+out:
51897+ if (!error && !slash)
51898+ error = prepend(buffer, buflen, "/", 1);
51899+
51900+ return error;
51901+}
51902+
51903+/* this must be called with vfsmount_lock and rename_lock held */
51904+
51905+static char *__our_d_path(const struct path *path, struct path *root,
51906+ char *buf, int buflen)
51907+{
51908+ char *res = buf + buflen;
51909+ int error;
51910+
51911+ prepend(&res, &buflen, "\0", 1);
51912+ error = prepend_path(path, root, &res, &buflen);
51913+ if (error)
51914+ return ERR_PTR(error);
51915+
51916+ return res;
51917+}
51918+
51919+static char *
51920+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51921+{
51922+ char *retval;
51923+
51924+ retval = __our_d_path(path, root, buf, buflen);
51925+ if (unlikely(IS_ERR(retval)))
51926+ retval = strcpy(buf, "<path too long>");
51927+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51928+ retval[1] = '\0';
51929+
51930+ return retval;
51931+}
51932+
51933+static char *
51934+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51935+ char *buf, int buflen)
51936+{
51937+ struct path path;
51938+ char *res;
51939+
51940+ path.dentry = (struct dentry *)dentry;
51941+ path.mnt = (struct vfsmount *)vfsmnt;
51942+
51943+ /* we can use real_root.dentry, real_root.mnt, because this is only called
51944+ by the RBAC system */
51945+ res = gen_full_path(&path, &real_root, buf, buflen);
51946+
51947+ return res;
51948+}
51949+
51950+static char *
51951+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51952+ char *buf, int buflen)
51953+{
51954+ char *res;
51955+ struct path path;
51956+ struct path root;
51957+ struct task_struct *reaper = init_pid_ns.child_reaper;
51958+
51959+ path.dentry = (struct dentry *)dentry;
51960+ path.mnt = (struct vfsmount *)vfsmnt;
51961+
51962+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51963+ get_fs_root(reaper->fs, &root);
51964+
51965+ write_seqlock(&rename_lock);
51966+ br_read_lock(&vfsmount_lock);
51967+ res = gen_full_path(&path, &root, buf, buflen);
51968+ br_read_unlock(&vfsmount_lock);
51969+ write_sequnlock(&rename_lock);
51970+
51971+ path_put(&root);
51972+ return res;
51973+}
51974+
51975+static char *
51976+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51977+{
51978+ char *ret;
51979+ write_seqlock(&rename_lock);
51980+ br_read_lock(&vfsmount_lock);
51981+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51982+ PAGE_SIZE);
51983+ br_read_unlock(&vfsmount_lock);
51984+ write_sequnlock(&rename_lock);
51985+ return ret;
51986+}
51987+
51988+static char *
51989+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51990+{
51991+ char *ret;
51992+ char *buf;
51993+ int buflen;
51994+
51995+ write_seqlock(&rename_lock);
51996+ br_read_lock(&vfsmount_lock);
51997+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51998+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51999+ buflen = (int)(ret - buf);
52000+ if (buflen >= 5)
52001+ prepend(&ret, &buflen, "/proc", 5);
52002+ else
52003+ ret = strcpy(buf, "<path too long>");
52004+ br_read_unlock(&vfsmount_lock);
52005+ write_sequnlock(&rename_lock);
52006+ return ret;
52007+}
52008+
52009+char *
52010+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
52011+{
52012+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52013+ PAGE_SIZE);
52014+}
52015+
52016+char *
52017+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
52018+{
52019+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52020+ PAGE_SIZE);
52021+}
52022+
52023+char *
52024+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
52025+{
52026+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
52027+ PAGE_SIZE);
52028+}
52029+
52030+char *
52031+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
52032+{
52033+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52034+ PAGE_SIZE);
52035+}
52036+
52037+char *
52038+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52039+{
52040+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52041+ PAGE_SIZE);
52042+}
52043+
52044+__inline__ __u32
52045+to_gr_audit(const __u32 reqmode)
52046+{
52047+ /* masks off auditable permission flags, then shifts them to create
52048+ auditing flags, and adds the special case of append auditing if
52049+ we're requesting write */
52050+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52051+}
52052+
52053+struct acl_subject_label *
52054+lookup_subject_map(const struct acl_subject_label *userp)
52055+{
52056+ unsigned int index = shash(userp, subj_map_set.s_size);
52057+ struct subject_map *match;
52058+
52059+ match = subj_map_set.s_hash[index];
52060+
52061+ while (match && match->user != userp)
52062+ match = match->next;
52063+
52064+ if (match != NULL)
52065+ return match->kernel;
52066+ else
52067+ return NULL;
52068+}
52069+
52070+static void
52071+insert_subj_map_entry(struct subject_map *subjmap)
52072+{
52073+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
52074+ struct subject_map **curr;
52075+
52076+ subjmap->prev = NULL;
52077+
52078+ curr = &subj_map_set.s_hash[index];
52079+ if (*curr != NULL)
52080+ (*curr)->prev = subjmap;
52081+
52082+ subjmap->next = *curr;
52083+ *curr = subjmap;
52084+
52085+ return;
52086+}
52087+
52088+static struct acl_role_label *
52089+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52090+ const gid_t gid)
52091+{
52092+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52093+ struct acl_role_label *match;
52094+ struct role_allowed_ip *ipp;
52095+ unsigned int x;
52096+ u32 curr_ip = task->signal->curr_ip;
52097+
52098+ task->signal->saved_ip = curr_ip;
52099+
52100+ match = acl_role_set.r_hash[index];
52101+
52102+ while (match) {
52103+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52104+ for (x = 0; x < match->domain_child_num; x++) {
52105+ if (match->domain_children[x] == uid)
52106+ goto found;
52107+ }
52108+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52109+ break;
52110+ match = match->next;
52111+ }
52112+found:
52113+ if (match == NULL) {
52114+ try_group:
52115+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52116+ match = acl_role_set.r_hash[index];
52117+
52118+ while (match) {
52119+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52120+ for (x = 0; x < match->domain_child_num; x++) {
52121+ if (match->domain_children[x] == gid)
52122+ goto found2;
52123+ }
52124+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52125+ break;
52126+ match = match->next;
52127+ }
52128+found2:
52129+ if (match == NULL)
52130+ match = default_role;
52131+ if (match->allowed_ips == NULL)
52132+ return match;
52133+ else {
52134+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52135+ if (likely
52136+ ((ntohl(curr_ip) & ipp->netmask) ==
52137+ (ntohl(ipp->addr) & ipp->netmask)))
52138+ return match;
52139+ }
52140+ match = default_role;
52141+ }
52142+ } else if (match->allowed_ips == NULL) {
52143+ return match;
52144+ } else {
52145+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52146+ if (likely
52147+ ((ntohl(curr_ip) & ipp->netmask) ==
52148+ (ntohl(ipp->addr) & ipp->netmask)))
52149+ return match;
52150+ }
52151+ goto try_group;
52152+ }
52153+
52154+ return match;
52155+}
52156+
52157+struct acl_subject_label *
52158+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52159+ const struct acl_role_label *role)
52160+{
52161+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
52162+ struct acl_subject_label *match;
52163+
52164+ match = role->subj_hash[index];
52165+
52166+ while (match && (match->inode != ino || match->device != dev ||
52167+ (match->mode & GR_DELETED))) {
52168+ match = match->next;
52169+ }
52170+
52171+ if (match && !(match->mode & GR_DELETED))
52172+ return match;
52173+ else
52174+ return NULL;
52175+}
52176+
52177+struct acl_subject_label *
52178+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52179+ const struct acl_role_label *role)
52180+{
52181+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
52182+ struct acl_subject_label *match;
52183+
52184+ match = role->subj_hash[index];
52185+
52186+ while (match && (match->inode != ino || match->device != dev ||
52187+ !(match->mode & GR_DELETED))) {
52188+ match = match->next;
52189+ }
52190+
52191+ if (match && (match->mode & GR_DELETED))
52192+ return match;
52193+ else
52194+ return NULL;
52195+}
52196+
52197+static struct acl_object_label *
52198+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52199+ const struct acl_subject_label *subj)
52200+{
52201+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52202+ struct acl_object_label *match;
52203+
52204+ match = subj->obj_hash[index];
52205+
52206+ while (match && (match->inode != ino || match->device != dev ||
52207+ (match->mode & GR_DELETED))) {
52208+ match = match->next;
52209+ }
52210+
52211+ if (match && !(match->mode & GR_DELETED))
52212+ return match;
52213+ else
52214+ return NULL;
52215+}
52216+
52217+static struct acl_object_label *
52218+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52219+ const struct acl_subject_label *subj)
52220+{
52221+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52222+ struct acl_object_label *match;
52223+
52224+ match = subj->obj_hash[index];
52225+
52226+ while (match && (match->inode != ino || match->device != dev ||
52227+ !(match->mode & GR_DELETED))) {
52228+ match = match->next;
52229+ }
52230+
52231+ if (match && (match->mode & GR_DELETED))
52232+ return match;
52233+
52234+ match = subj->obj_hash[index];
52235+
52236+ while (match && (match->inode != ino || match->device != dev ||
52237+ (match->mode & GR_DELETED))) {
52238+ match = match->next;
52239+ }
52240+
52241+ if (match && !(match->mode & GR_DELETED))
52242+ return match;
52243+ else
52244+ return NULL;
52245+}
52246+
52247+static struct name_entry *
52248+lookup_name_entry(const char *name)
52249+{
52250+ unsigned int len = strlen(name);
52251+ unsigned int key = full_name_hash(name, len);
52252+ unsigned int index = key % name_set.n_size;
52253+ struct name_entry *match;
52254+
52255+ match = name_set.n_hash[index];
52256+
52257+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52258+ match = match->next;
52259+
52260+ return match;
52261+}
52262+
52263+static struct name_entry *
52264+lookup_name_entry_create(const char *name)
52265+{
52266+ unsigned int len = strlen(name);
52267+ unsigned int key = full_name_hash(name, len);
52268+ unsigned int index = key % name_set.n_size;
52269+ struct name_entry *match;
52270+
52271+ match = name_set.n_hash[index];
52272+
52273+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52274+ !match->deleted))
52275+ match = match->next;
52276+
52277+ if (match && match->deleted)
52278+ return match;
52279+
52280+ match = name_set.n_hash[index];
52281+
52282+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52283+ match->deleted))
52284+ match = match->next;
52285+
52286+ if (match && !match->deleted)
52287+ return match;
52288+ else
52289+ return NULL;
52290+}
52291+
52292+static struct inodev_entry *
52293+lookup_inodev_entry(const ino_t ino, const dev_t dev)
52294+{
52295+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
52296+ struct inodev_entry *match;
52297+
52298+ match = inodev_set.i_hash[index];
52299+
52300+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52301+ match = match->next;
52302+
52303+ return match;
52304+}
52305+
52306+static void
52307+insert_inodev_entry(struct inodev_entry *entry)
52308+{
52309+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52310+ inodev_set.i_size);
52311+ struct inodev_entry **curr;
52312+
52313+ entry->prev = NULL;
52314+
52315+ curr = &inodev_set.i_hash[index];
52316+ if (*curr != NULL)
52317+ (*curr)->prev = entry;
52318+
52319+ entry->next = *curr;
52320+ *curr = entry;
52321+
52322+ return;
52323+}
52324+
52325+static void
52326+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52327+{
52328+ unsigned int index =
52329+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52330+ struct acl_role_label **curr;
52331+ struct acl_role_label *tmp, *tmp2;
52332+
52333+ curr = &acl_role_set.r_hash[index];
52334+
52335+ /* simple case, slot is empty, just set it to our role */
52336+ if (*curr == NULL) {
52337+ *curr = role;
52338+ } else {
52339+ /* example:
52340+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
52341+ 2 -> 3
52342+ */
52343+ /* first check to see if we can already be reached via this slot */
52344+ tmp = *curr;
52345+ while (tmp && tmp != role)
52346+ tmp = tmp->next;
52347+ if (tmp == role) {
52348+ /* we don't need to add ourselves to this slot's chain */
52349+ return;
52350+ }
52351+ /* we need to add ourselves to this chain, two cases */
52352+ if (role->next == NULL) {
52353+ /* simple case, append the current chain to our role */
52354+ role->next = *curr;
52355+ *curr = role;
52356+ } else {
52357+ /* 1 -> 2 -> 3 -> 4
52358+ 2 -> 3 -> 4
52359+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52360+ */
52361+ /* trickier case: walk our role's chain until we find
52362+ the role for the start of the current slot's chain */
52363+ tmp = role;
52364+ tmp2 = *curr;
52365+ while (tmp->next && tmp->next != tmp2)
52366+ tmp = tmp->next;
52367+ if (tmp->next == tmp2) {
52368+ /* from example above, we found 3, so just
52369+ replace this slot's chain with ours */
52370+ *curr = role;
52371+ } else {
52372+ /* we didn't find a subset of our role's chain
52373+ in the current slot's chain, so append their
52374+ chain to ours, and set us as the first role in
52375+ the slot's chain
52376+
52377+ we could fold this case with the case above,
52378+ but making it explicit for clarity
52379+ */
52380+ tmp->next = tmp2;
52381+ *curr = role;
52382+ }
52383+ }
52384+ }
52385+
52386+ return;
52387+}
52388+
52389+static void
52390+insert_acl_role_label(struct acl_role_label *role)
52391+{
52392+ int i;
52393+
52394+ if (role_list == NULL) {
52395+ role_list = role;
52396+ role->prev = NULL;
52397+ } else {
52398+ role->prev = role_list;
52399+ role_list = role;
52400+ }
52401+
52402+ /* used for hash chains */
52403+ role->next = NULL;
52404+
52405+ if (role->roletype & GR_ROLE_DOMAIN) {
52406+ for (i = 0; i < role->domain_child_num; i++)
52407+ __insert_acl_role_label(role, role->domain_children[i]);
52408+ } else
52409+ __insert_acl_role_label(role, role->uidgid);
52410+}
52411+
52412+static int
52413+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52414+{
52415+ struct name_entry **curr, *nentry;
52416+ struct inodev_entry *ientry;
52417+ unsigned int len = strlen(name);
52418+ unsigned int key = full_name_hash(name, len);
52419+ unsigned int index = key % name_set.n_size;
52420+
52421+ curr = &name_set.n_hash[index];
52422+
52423+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52424+ curr = &((*curr)->next);
52425+
52426+ if (*curr != NULL)
52427+ return 1;
52428+
52429+ nentry = acl_alloc(sizeof (struct name_entry));
52430+ if (nentry == NULL)
52431+ return 0;
52432+ ientry = acl_alloc(sizeof (struct inodev_entry));
52433+ if (ientry == NULL)
52434+ return 0;
52435+ ientry->nentry = nentry;
52436+
52437+ nentry->key = key;
52438+ nentry->name = name;
52439+ nentry->inode = inode;
52440+ nentry->device = device;
52441+ nentry->len = len;
52442+ nentry->deleted = deleted;
52443+
52444+ nentry->prev = NULL;
52445+ curr = &name_set.n_hash[index];
52446+ if (*curr != NULL)
52447+ (*curr)->prev = nentry;
52448+ nentry->next = *curr;
52449+ *curr = nentry;
52450+
52451+ /* insert us into the table searchable by inode/dev */
52452+ insert_inodev_entry(ientry);
52453+
52454+ return 1;
52455+}
52456+
52457+static void
52458+insert_acl_obj_label(struct acl_object_label *obj,
52459+ struct acl_subject_label *subj)
52460+{
52461+ unsigned int index =
52462+ fhash(obj->inode, obj->device, subj->obj_hash_size);
52463+ struct acl_object_label **curr;
52464+
52465+
52466+ obj->prev = NULL;
52467+
52468+ curr = &subj->obj_hash[index];
52469+ if (*curr != NULL)
52470+ (*curr)->prev = obj;
52471+
52472+ obj->next = *curr;
52473+ *curr = obj;
52474+
52475+ return;
52476+}
52477+
52478+static void
52479+insert_acl_subj_label(struct acl_subject_label *obj,
52480+ struct acl_role_label *role)
52481+{
52482+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52483+ struct acl_subject_label **curr;
52484+
52485+ obj->prev = NULL;
52486+
52487+ curr = &role->subj_hash[index];
52488+ if (*curr != NULL)
52489+ (*curr)->prev = obj;
52490+
52491+ obj->next = *curr;
52492+ *curr = obj;
52493+
52494+ return;
52495+}
52496+
52497+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52498+
52499+static void *
52500+create_table(__u32 * len, int elementsize)
52501+{
52502+ unsigned int table_sizes[] = {
52503+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52504+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52505+ 4194301, 8388593, 16777213, 33554393, 67108859
52506+ };
52507+ void *newtable = NULL;
52508+ unsigned int pwr = 0;
52509+
52510+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52511+ table_sizes[pwr] <= *len)
52512+ pwr++;
52513+
52514+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52515+ return newtable;
52516+
52517+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52518+ newtable =
52519+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52520+ else
52521+ newtable = vmalloc(table_sizes[pwr] * elementsize);
52522+
52523+ *len = table_sizes[pwr];
52524+
52525+ return newtable;
52526+}
52527+
52528+static int
52529+init_variables(const struct gr_arg *arg)
52530+{
52531+ struct task_struct *reaper = init_pid_ns.child_reaper;
52532+ unsigned int stacksize;
52533+
52534+ subj_map_set.s_size = arg->role_db.num_subjects;
52535+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52536+ name_set.n_size = arg->role_db.num_objects;
52537+ inodev_set.i_size = arg->role_db.num_objects;
52538+
52539+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
52540+ !name_set.n_size || !inodev_set.i_size)
52541+ return 1;
52542+
52543+ if (!gr_init_uidset())
52544+ return 1;
52545+
52546+ /* set up the stack that holds allocation info */
52547+
52548+ stacksize = arg->role_db.num_pointers + 5;
52549+
52550+ if (!acl_alloc_stack_init(stacksize))
52551+ return 1;
52552+
52553+ /* grab reference for the real root dentry and vfsmount */
52554+ get_fs_root(reaper->fs, &real_root);
52555+
52556+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52557+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52558+#endif
52559+
52560+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52561+ if (fakefs_obj_rw == NULL)
52562+ return 1;
52563+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52564+
52565+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52566+ if (fakefs_obj_rwx == NULL)
52567+ return 1;
52568+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52569+
52570+ subj_map_set.s_hash =
52571+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52572+ acl_role_set.r_hash =
52573+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52574+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52575+ inodev_set.i_hash =
52576+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52577+
52578+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52579+ !name_set.n_hash || !inodev_set.i_hash)
52580+ return 1;
52581+
52582+ memset(subj_map_set.s_hash, 0,
52583+ sizeof(struct subject_map *) * subj_map_set.s_size);
52584+ memset(acl_role_set.r_hash, 0,
52585+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
52586+ memset(name_set.n_hash, 0,
52587+ sizeof (struct name_entry *) * name_set.n_size);
52588+ memset(inodev_set.i_hash, 0,
52589+ sizeof (struct inodev_entry *) * inodev_set.i_size);
52590+
52591+ return 0;
52592+}
52593+
52594+/* free information not needed after startup
52595+ currently contains user->kernel pointer mappings for subjects
52596+*/
52597+
52598+static void
52599+free_init_variables(void)
52600+{
52601+ __u32 i;
52602+
52603+ if (subj_map_set.s_hash) {
52604+ for (i = 0; i < subj_map_set.s_size; i++) {
52605+ if (subj_map_set.s_hash[i]) {
52606+ kfree(subj_map_set.s_hash[i]);
52607+ subj_map_set.s_hash[i] = NULL;
52608+ }
52609+ }
52610+
52611+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52612+ PAGE_SIZE)
52613+ kfree(subj_map_set.s_hash);
52614+ else
52615+ vfree(subj_map_set.s_hash);
52616+ }
52617+
52618+ return;
52619+}
52620+
52621+static void
52622+free_variables(void)
52623+{
52624+ struct acl_subject_label *s;
52625+ struct acl_role_label *r;
52626+ struct task_struct *task, *task2;
52627+ unsigned int x;
52628+
52629+ gr_clear_learn_entries();
52630+
52631+ read_lock(&tasklist_lock);
52632+ do_each_thread(task2, task) {
52633+ task->acl_sp_role = 0;
52634+ task->acl_role_id = 0;
52635+ task->acl = NULL;
52636+ task->role = NULL;
52637+ } while_each_thread(task2, task);
52638+ read_unlock(&tasklist_lock);
52639+
52640+ /* release the reference to the real root dentry and vfsmount */
52641+ path_put(&real_root);
52642+ memset(&real_root, 0, sizeof(real_root));
52643+
52644+ /* free all object hash tables */
52645+
52646+ FOR_EACH_ROLE_START(r)
52647+ if (r->subj_hash == NULL)
52648+ goto next_role;
52649+ FOR_EACH_SUBJECT_START(r, s, x)
52650+ if (s->obj_hash == NULL)
52651+ break;
52652+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52653+ kfree(s->obj_hash);
52654+ else
52655+ vfree(s->obj_hash);
52656+ FOR_EACH_SUBJECT_END(s, x)
52657+ FOR_EACH_NESTED_SUBJECT_START(r, s)
52658+ if (s->obj_hash == NULL)
52659+ break;
52660+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52661+ kfree(s->obj_hash);
52662+ else
52663+ vfree(s->obj_hash);
52664+ FOR_EACH_NESTED_SUBJECT_END(s)
52665+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52666+ kfree(r->subj_hash);
52667+ else
52668+ vfree(r->subj_hash);
52669+ r->subj_hash = NULL;
52670+next_role:
52671+ FOR_EACH_ROLE_END(r)
52672+
52673+ acl_free_all();
52674+
52675+ if (acl_role_set.r_hash) {
52676+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52677+ PAGE_SIZE)
52678+ kfree(acl_role_set.r_hash);
52679+ else
52680+ vfree(acl_role_set.r_hash);
52681+ }
52682+ if (name_set.n_hash) {
52683+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
52684+ PAGE_SIZE)
52685+ kfree(name_set.n_hash);
52686+ else
52687+ vfree(name_set.n_hash);
52688+ }
52689+
52690+ if (inodev_set.i_hash) {
52691+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52692+ PAGE_SIZE)
52693+ kfree(inodev_set.i_hash);
52694+ else
52695+ vfree(inodev_set.i_hash);
52696+ }
52697+
52698+ gr_free_uidset();
52699+
52700+ memset(&name_set, 0, sizeof (struct name_db));
52701+ memset(&inodev_set, 0, sizeof (struct inodev_db));
52702+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52703+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52704+
52705+ default_role = NULL;
52706+ kernel_role = NULL;
52707+ role_list = NULL;
52708+
52709+ return;
52710+}
52711+
52712+static __u32
52713+count_user_objs(struct acl_object_label *userp)
52714+{
52715+ struct acl_object_label o_tmp;
52716+ __u32 num = 0;
52717+
52718+ while (userp) {
52719+ if (copy_from_user(&o_tmp, userp,
52720+ sizeof (struct acl_object_label)))
52721+ break;
52722+
52723+ userp = o_tmp.prev;
52724+ num++;
52725+ }
52726+
52727+ return num;
52728+}
52729+
52730+static struct acl_subject_label *
52731+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52732+
52733+static int
52734+copy_user_glob(struct acl_object_label *obj)
52735+{
52736+ struct acl_object_label *g_tmp, **guser;
52737+ unsigned int len;
52738+ char *tmp;
52739+
52740+ if (obj->globbed == NULL)
52741+ return 0;
52742+
52743+ guser = &obj->globbed;
52744+ while (*guser) {
52745+ g_tmp = (struct acl_object_label *)
52746+ acl_alloc(sizeof (struct acl_object_label));
52747+ if (g_tmp == NULL)
52748+ return -ENOMEM;
52749+
52750+ if (copy_from_user(g_tmp, *guser,
52751+ sizeof (struct acl_object_label)))
52752+ return -EFAULT;
52753+
52754+ len = strnlen_user(g_tmp->filename, PATH_MAX);
52755+
52756+ if (!len || len >= PATH_MAX)
52757+ return -EINVAL;
52758+
52759+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52760+ return -ENOMEM;
52761+
52762+ if (copy_from_user(tmp, g_tmp->filename, len))
52763+ return -EFAULT;
52764+ tmp[len-1] = '\0';
52765+ g_tmp->filename = tmp;
52766+
52767+ *guser = g_tmp;
52768+ guser = &(g_tmp->next);
52769+ }
52770+
52771+ return 0;
52772+}
52773+
52774+static int
52775+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52776+ struct acl_role_label *role)
52777+{
52778+ struct acl_object_label *o_tmp;
52779+ unsigned int len;
52780+ int ret;
52781+ char *tmp;
52782+
52783+ while (userp) {
52784+ if ((o_tmp = (struct acl_object_label *)
52785+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
52786+ return -ENOMEM;
52787+
52788+ if (copy_from_user(o_tmp, userp,
52789+ sizeof (struct acl_object_label)))
52790+ return -EFAULT;
52791+
52792+ userp = o_tmp->prev;
52793+
52794+ len = strnlen_user(o_tmp->filename, PATH_MAX);
52795+
52796+ if (!len || len >= PATH_MAX)
52797+ return -EINVAL;
52798+
52799+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52800+ return -ENOMEM;
52801+
52802+ if (copy_from_user(tmp, o_tmp->filename, len))
52803+ return -EFAULT;
52804+ tmp[len-1] = '\0';
52805+ o_tmp->filename = tmp;
52806+
52807+ insert_acl_obj_label(o_tmp, subj);
52808+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52809+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52810+ return -ENOMEM;
52811+
52812+ ret = copy_user_glob(o_tmp);
52813+ if (ret)
52814+ return ret;
52815+
52816+ if (o_tmp->nested) {
52817+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52818+ if (IS_ERR(o_tmp->nested))
52819+ return PTR_ERR(o_tmp->nested);
52820+
52821+ /* insert into nested subject list */
52822+ o_tmp->nested->next = role->hash->first;
52823+ role->hash->first = o_tmp->nested;
52824+ }
52825+ }
52826+
52827+ return 0;
52828+}
52829+
52830+static __u32
52831+count_user_subjs(struct acl_subject_label *userp)
52832+{
52833+ struct acl_subject_label s_tmp;
52834+ __u32 num = 0;
52835+
52836+ while (userp) {
52837+ if (copy_from_user(&s_tmp, userp,
52838+ sizeof (struct acl_subject_label)))
52839+ break;
52840+
52841+ userp = s_tmp.prev;
52842+ /* do not count nested subjects against this count, since
52843+ they are not included in the hash table, but are
52844+ attached to objects. We have already counted
52845+ the subjects in userspace for the allocation
52846+ stack
52847+ */
52848+ if (!(s_tmp.mode & GR_NESTED))
52849+ num++;
52850+ }
52851+
52852+ return num;
52853+}
52854+
52855+static int
52856+copy_user_allowedips(struct acl_role_label *rolep)
52857+{
52858+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52859+
52860+ ruserip = rolep->allowed_ips;
52861+
52862+ while (ruserip) {
52863+ rlast = rtmp;
52864+
52865+ if ((rtmp = (struct role_allowed_ip *)
52866+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52867+ return -ENOMEM;
52868+
52869+ if (copy_from_user(rtmp, ruserip,
52870+ sizeof (struct role_allowed_ip)))
52871+ return -EFAULT;
52872+
52873+ ruserip = rtmp->prev;
52874+
52875+ if (!rlast) {
52876+ rtmp->prev = NULL;
52877+ rolep->allowed_ips = rtmp;
52878+ } else {
52879+ rlast->next = rtmp;
52880+ rtmp->prev = rlast;
52881+ }
52882+
52883+ if (!ruserip)
52884+ rtmp->next = NULL;
52885+ }
52886+
52887+ return 0;
52888+}
52889+
52890+static int
52891+copy_user_transitions(struct acl_role_label *rolep)
52892+{
52893+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
52894+
52895+ unsigned int len;
52896+ char *tmp;
52897+
52898+ rusertp = rolep->transitions;
52899+
52900+ while (rusertp) {
52901+ rlast = rtmp;
52902+
52903+ if ((rtmp = (struct role_transition *)
52904+ acl_alloc(sizeof (struct role_transition))) == NULL)
52905+ return -ENOMEM;
52906+
52907+ if (copy_from_user(rtmp, rusertp,
52908+ sizeof (struct role_transition)))
52909+ return -EFAULT;
52910+
52911+ rusertp = rtmp->prev;
52912+
52913+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52914+
52915+ if (!len || len >= GR_SPROLE_LEN)
52916+ return -EINVAL;
52917+
52918+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52919+ return -ENOMEM;
52920+
52921+ if (copy_from_user(tmp, rtmp->rolename, len))
52922+ return -EFAULT;
52923+ tmp[len-1] = '\0';
52924+ rtmp->rolename = tmp;
52925+
52926+ if (!rlast) {
52927+ rtmp->prev = NULL;
52928+ rolep->transitions = rtmp;
52929+ } else {
52930+ rlast->next = rtmp;
52931+ rtmp->prev = rlast;
52932+ }
52933+
52934+ if (!rusertp)
52935+ rtmp->next = NULL;
52936+ }
52937+
52938+ return 0;
52939+}
52940+
52941+static struct acl_subject_label *
52942+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52943+{
52944+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52945+ unsigned int len;
52946+ char *tmp;
52947+ __u32 num_objs;
52948+ struct acl_ip_label **i_tmp, *i_utmp2;
52949+ struct gr_hash_struct ghash;
52950+ struct subject_map *subjmap;
52951+ unsigned int i_num;
52952+ int err;
52953+
52954+ s_tmp = lookup_subject_map(userp);
52955+
52956+ /* we've already copied this subject into the kernel, just return
52957+ the reference to it, and don't copy it over again
52958+ */
52959+ if (s_tmp)
52960+ return(s_tmp);
52961+
52962+ if ((s_tmp = (struct acl_subject_label *)
52963+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52964+ return ERR_PTR(-ENOMEM);
52965+
52966+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52967+ if (subjmap == NULL)
52968+ return ERR_PTR(-ENOMEM);
52969+
52970+ subjmap->user = userp;
52971+ subjmap->kernel = s_tmp;
52972+ insert_subj_map_entry(subjmap);
52973+
52974+ if (copy_from_user(s_tmp, userp,
52975+ sizeof (struct acl_subject_label)))
52976+ return ERR_PTR(-EFAULT);
52977+
52978+ len = strnlen_user(s_tmp->filename, PATH_MAX);
52979+
52980+ if (!len || len >= PATH_MAX)
52981+ return ERR_PTR(-EINVAL);
52982+
52983+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52984+ return ERR_PTR(-ENOMEM);
52985+
52986+ if (copy_from_user(tmp, s_tmp->filename, len))
52987+ return ERR_PTR(-EFAULT);
52988+ tmp[len-1] = '\0';
52989+ s_tmp->filename = tmp;
52990+
52991+ if (!strcmp(s_tmp->filename, "/"))
52992+ role->root_label = s_tmp;
52993+
52994+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52995+ return ERR_PTR(-EFAULT);
52996+
52997+ /* copy user and group transition tables */
52998+
52999+ if (s_tmp->user_trans_num) {
53000+ uid_t *uidlist;
53001+
53002+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
53003+ if (uidlist == NULL)
53004+ return ERR_PTR(-ENOMEM);
53005+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
53006+ return ERR_PTR(-EFAULT);
53007+
53008+ s_tmp->user_transitions = uidlist;
53009+ }
53010+
53011+ if (s_tmp->group_trans_num) {
53012+ gid_t *gidlist;
53013+
53014+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
53015+ if (gidlist == NULL)
53016+ return ERR_PTR(-ENOMEM);
53017+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
53018+ return ERR_PTR(-EFAULT);
53019+
53020+ s_tmp->group_transitions = gidlist;
53021+ }
53022+
53023+ /* set up object hash table */
53024+ num_objs = count_user_objs(ghash.first);
53025+
53026+ s_tmp->obj_hash_size = num_objs;
53027+ s_tmp->obj_hash =
53028+ (struct acl_object_label **)
53029+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
53030+
53031+ if (!s_tmp->obj_hash)
53032+ return ERR_PTR(-ENOMEM);
53033+
53034+ memset(s_tmp->obj_hash, 0,
53035+ s_tmp->obj_hash_size *
53036+ sizeof (struct acl_object_label *));
53037+
53038+ /* add in objects */
53039+ err = copy_user_objs(ghash.first, s_tmp, role);
53040+
53041+ if (err)
53042+ return ERR_PTR(err);
53043+
53044+ /* set pointer for parent subject */
53045+ if (s_tmp->parent_subject) {
53046+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
53047+
53048+ if (IS_ERR(s_tmp2))
53049+ return s_tmp2;
53050+
53051+ s_tmp->parent_subject = s_tmp2;
53052+ }
53053+
53054+ /* add in ip acls */
53055+
53056+ if (!s_tmp->ip_num) {
53057+ s_tmp->ips = NULL;
53058+ goto insert;
53059+ }
53060+
53061+ i_tmp =
53062+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53063+ sizeof (struct acl_ip_label *));
53064+
53065+ if (!i_tmp)
53066+ return ERR_PTR(-ENOMEM);
53067+
53068+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53069+ *(i_tmp + i_num) =
53070+ (struct acl_ip_label *)
53071+ acl_alloc(sizeof (struct acl_ip_label));
53072+ if (!*(i_tmp + i_num))
53073+ return ERR_PTR(-ENOMEM);
53074+
53075+ if (copy_from_user
53076+ (&i_utmp2, s_tmp->ips + i_num,
53077+ sizeof (struct acl_ip_label *)))
53078+ return ERR_PTR(-EFAULT);
53079+
53080+ if (copy_from_user
53081+ (*(i_tmp + i_num), i_utmp2,
53082+ sizeof (struct acl_ip_label)))
53083+ return ERR_PTR(-EFAULT);
53084+
53085+ if ((*(i_tmp + i_num))->iface == NULL)
53086+ continue;
53087+
53088+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53089+ if (!len || len >= IFNAMSIZ)
53090+ return ERR_PTR(-EINVAL);
53091+ tmp = acl_alloc(len);
53092+ if (tmp == NULL)
53093+ return ERR_PTR(-ENOMEM);
53094+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53095+ return ERR_PTR(-EFAULT);
53096+ (*(i_tmp + i_num))->iface = tmp;
53097+ }
53098+
53099+ s_tmp->ips = i_tmp;
53100+
53101+insert:
53102+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53103+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53104+ return ERR_PTR(-ENOMEM);
53105+
53106+ return s_tmp;
53107+}
53108+
53109+static int
53110+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53111+{
53112+ struct acl_subject_label s_pre;
53113+ struct acl_subject_label * ret;
53114+ int err;
53115+
53116+ while (userp) {
53117+ if (copy_from_user(&s_pre, userp,
53118+ sizeof (struct acl_subject_label)))
53119+ return -EFAULT;
53120+
53121+ /* do not add nested subjects here, add
53122+ while parsing objects
53123+ */
53124+
53125+ if (s_pre.mode & GR_NESTED) {
53126+ userp = s_pre.prev;
53127+ continue;
53128+ }
53129+
53130+ ret = do_copy_user_subj(userp, role);
53131+
53132+ err = PTR_ERR(ret);
53133+ if (IS_ERR(ret))
53134+ return err;
53135+
53136+ insert_acl_subj_label(ret, role);
53137+
53138+ userp = s_pre.prev;
53139+ }
53140+
53141+ return 0;
53142+}
53143+
53144+static int
53145+copy_user_acl(struct gr_arg *arg)
53146+{
53147+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53148+ struct sprole_pw *sptmp;
53149+ struct gr_hash_struct *ghash;
53150+ uid_t *domainlist;
53151+ unsigned int r_num;
53152+ unsigned int len;
53153+ char *tmp;
53154+ int err = 0;
53155+ __u16 i;
53156+ __u32 num_subjs;
53157+
53158+ /* we need a default and kernel role */
53159+ if (arg->role_db.num_roles < 2)
53160+ return -EINVAL;
53161+
53162+ /* copy special role authentication info from userspace */
53163+
53164+ num_sprole_pws = arg->num_sprole_pws;
53165+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53166+
53167+ if (!acl_special_roles && num_sprole_pws)
53168+ return -ENOMEM;
53169+
53170+ for (i = 0; i < num_sprole_pws; i++) {
53171+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53172+ if (!sptmp)
53173+ return -ENOMEM;
53174+ if (copy_from_user(sptmp, arg->sprole_pws + i,
53175+ sizeof (struct sprole_pw)))
53176+ return -EFAULT;
53177+
53178+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53179+
53180+ if (!len || len >= GR_SPROLE_LEN)
53181+ return -EINVAL;
53182+
53183+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53184+ return -ENOMEM;
53185+
53186+ if (copy_from_user(tmp, sptmp->rolename, len))
53187+ return -EFAULT;
53188+
53189+ tmp[len-1] = '\0';
53190+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53191+ printk(KERN_ALERT "Copying special role %s\n", tmp);
53192+#endif
53193+ sptmp->rolename = tmp;
53194+ acl_special_roles[i] = sptmp;
53195+ }
53196+
53197+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53198+
53199+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53200+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
53201+
53202+ if (!r_tmp)
53203+ return -ENOMEM;
53204+
53205+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
53206+ sizeof (struct acl_role_label *)))
53207+ return -EFAULT;
53208+
53209+ if (copy_from_user(r_tmp, r_utmp2,
53210+ sizeof (struct acl_role_label)))
53211+ return -EFAULT;
53212+
53213+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53214+
53215+ if (!len || len >= PATH_MAX)
53216+ return -EINVAL;
53217+
53218+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53219+ return -ENOMEM;
53220+
53221+ if (copy_from_user(tmp, r_tmp->rolename, len))
53222+ return -EFAULT;
53223+
53224+ tmp[len-1] = '\0';
53225+ r_tmp->rolename = tmp;
53226+
53227+ if (!strcmp(r_tmp->rolename, "default")
53228+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53229+ default_role = r_tmp;
53230+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53231+ kernel_role = r_tmp;
53232+ }
53233+
53234+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53235+ return -ENOMEM;
53236+
53237+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53238+ return -EFAULT;
53239+
53240+ r_tmp->hash = ghash;
53241+
53242+ num_subjs = count_user_subjs(r_tmp->hash->first);
53243+
53244+ r_tmp->subj_hash_size = num_subjs;
53245+ r_tmp->subj_hash =
53246+ (struct acl_subject_label **)
53247+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53248+
53249+ if (!r_tmp->subj_hash)
53250+ return -ENOMEM;
53251+
53252+ err = copy_user_allowedips(r_tmp);
53253+ if (err)
53254+ return err;
53255+
53256+ /* copy domain info */
53257+ if (r_tmp->domain_children != NULL) {
53258+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53259+ if (domainlist == NULL)
53260+ return -ENOMEM;
53261+
53262+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53263+ return -EFAULT;
53264+
53265+ r_tmp->domain_children = domainlist;
53266+ }
53267+
53268+ err = copy_user_transitions(r_tmp);
53269+ if (err)
53270+ return err;
53271+
53272+ memset(r_tmp->subj_hash, 0,
53273+ r_tmp->subj_hash_size *
53274+ sizeof (struct acl_subject_label *));
53275+
53276+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
53277+
53278+ if (err)
53279+ return err;
53280+
53281+ /* set nested subject list to null */
53282+ r_tmp->hash->first = NULL;
53283+
53284+ insert_acl_role_label(r_tmp);
53285+ }
53286+
53287+ if (default_role == NULL || kernel_role == NULL)
53288+ return -EINVAL;
53289+
53290+ return err;
53291+}
53292+
53293+static int
53294+gracl_init(struct gr_arg *args)
53295+{
53296+ int error = 0;
53297+
53298+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53299+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53300+
53301+ if (init_variables(args)) {
53302+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53303+ error = -ENOMEM;
53304+ free_variables();
53305+ goto out;
53306+ }
53307+
53308+ error = copy_user_acl(args);
53309+ free_init_variables();
53310+ if (error) {
53311+ free_variables();
53312+ goto out;
53313+ }
53314+
53315+ if ((error = gr_set_acls(0))) {
53316+ free_variables();
53317+ goto out;
53318+ }
53319+
53320+ pax_open_kernel();
53321+ gr_status |= GR_READY;
53322+ pax_close_kernel();
53323+
53324+ out:
53325+ return error;
53326+}
53327+
53328+/* derived from glibc fnmatch() 0: match, 1: no match*/
53329+
53330+static int
53331+glob_match(const char *p, const char *n)
53332+{
53333+ char c;
53334+
53335+ while ((c = *p++) != '\0') {
53336+ switch (c) {
53337+ case '?':
53338+ if (*n == '\0')
53339+ return 1;
53340+ else if (*n == '/')
53341+ return 1;
53342+ break;
53343+ case '\\':
53344+ if (*n != c)
53345+ return 1;
53346+ break;
53347+ case '*':
53348+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
53349+ if (*n == '/')
53350+ return 1;
53351+ else if (c == '?') {
53352+ if (*n == '\0')
53353+ return 1;
53354+ else
53355+ ++n;
53356+ }
53357+ }
53358+ if (c == '\0') {
53359+ return 0;
53360+ } else {
53361+ const char *endp;
53362+
53363+ if ((endp = strchr(n, '/')) == NULL)
53364+ endp = n + strlen(n);
53365+
53366+ if (c == '[') {
53367+ for (--p; n < endp; ++n)
53368+ if (!glob_match(p, n))
53369+ return 0;
53370+ } else if (c == '/') {
53371+ while (*n != '\0' && *n != '/')
53372+ ++n;
53373+ if (*n == '/' && !glob_match(p, n + 1))
53374+ return 0;
53375+ } else {
53376+ for (--p; n < endp; ++n)
53377+ if (*n == c && !glob_match(p, n))
53378+ return 0;
53379+ }
53380+
53381+ return 1;
53382+ }
53383+ case '[':
53384+ {
53385+ int not;
53386+ char cold;
53387+
53388+ if (*n == '\0' || *n == '/')
53389+ return 1;
53390+
53391+ not = (*p == '!' || *p == '^');
53392+ if (not)
53393+ ++p;
53394+
53395+ c = *p++;
53396+ for (;;) {
53397+ unsigned char fn = (unsigned char)*n;
53398+
53399+ if (c == '\0')
53400+ return 1;
53401+ else {
53402+ if (c == fn)
53403+ goto matched;
53404+ cold = c;
53405+ c = *p++;
53406+
53407+ if (c == '-' && *p != ']') {
53408+ unsigned char cend = *p++;
53409+
53410+ if (cend == '\0')
53411+ return 1;
53412+
53413+ if (cold <= fn && fn <= cend)
53414+ goto matched;
53415+
53416+ c = *p++;
53417+ }
53418+ }
53419+
53420+ if (c == ']')
53421+ break;
53422+ }
53423+ if (!not)
53424+ return 1;
53425+ break;
53426+ matched:
53427+ while (c != ']') {
53428+ if (c == '\0')
53429+ return 1;
53430+
53431+ c = *p++;
53432+ }
53433+ if (not)
53434+ return 1;
53435+ }
53436+ break;
53437+ default:
53438+ if (c != *n)
53439+ return 1;
53440+ }
53441+
53442+ ++n;
53443+ }
53444+
53445+ if (*n == '\0')
53446+ return 0;
53447+
53448+ if (*n == '/')
53449+ return 0;
53450+
53451+ return 1;
53452+}
53453+
53454+static struct acl_object_label *
53455+chk_glob_label(struct acl_object_label *globbed,
53456+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53457+{
53458+ struct acl_object_label *tmp;
53459+
53460+ if (*path == NULL)
53461+ *path = gr_to_filename_nolock(dentry, mnt);
53462+
53463+ tmp = globbed;
53464+
53465+ while (tmp) {
53466+ if (!glob_match(tmp->filename, *path))
53467+ return tmp;
53468+ tmp = tmp->next;
53469+ }
53470+
53471+ return NULL;
53472+}
53473+
53474+static struct acl_object_label *
53475+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53476+ const ino_t curr_ino, const dev_t curr_dev,
53477+ const struct acl_subject_label *subj, char **path, const int checkglob)
53478+{
53479+ struct acl_subject_label *tmpsubj;
53480+ struct acl_object_label *retval;
53481+ struct acl_object_label *retval2;
53482+
53483+ tmpsubj = (struct acl_subject_label *) subj;
53484+ read_lock(&gr_inode_lock);
53485+ do {
53486+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53487+ if (retval) {
53488+ if (checkglob && retval->globbed) {
53489+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53490+ if (retval2)
53491+ retval = retval2;
53492+ }
53493+ break;
53494+ }
53495+ } while ((tmpsubj = tmpsubj->parent_subject));
53496+ read_unlock(&gr_inode_lock);
53497+
53498+ return retval;
53499+}
53500+
53501+static __inline__ struct acl_object_label *
53502+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53503+ struct dentry *curr_dentry,
53504+ const struct acl_subject_label *subj, char **path, const int checkglob)
53505+{
53506+ int newglob = checkglob;
53507+ ino_t inode;
53508+ dev_t device;
53509+
53510+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53511+ as we don't want a / * rule to match instead of the / object
53512+ don't do this for create lookups that call this function though, since they're looking up
53513+ on the parent and thus need globbing checks on all paths
53514+ */
53515+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53516+ newglob = GR_NO_GLOB;
53517+
53518+ spin_lock(&curr_dentry->d_lock);
53519+ inode = curr_dentry->d_inode->i_ino;
53520+ device = __get_dev(curr_dentry);
53521+ spin_unlock(&curr_dentry->d_lock);
53522+
53523+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53524+}
53525+
53526+static struct acl_object_label *
53527+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53528+ const struct acl_subject_label *subj, char *path, const int checkglob)
53529+{
53530+ struct dentry *dentry = (struct dentry *) l_dentry;
53531+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53532+ struct mount *real_mnt = real_mount(mnt);
53533+ struct acl_object_label *retval;
53534+ struct dentry *parent;
53535+
53536+ write_seqlock(&rename_lock);
53537+ br_read_lock(&vfsmount_lock);
53538+
53539+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53540+#ifdef CONFIG_NET
53541+ mnt == sock_mnt ||
53542+#endif
53543+#ifdef CONFIG_HUGETLBFS
53544+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53545+#endif
53546+ /* ignore Eric Biederman */
53547+ IS_PRIVATE(l_dentry->d_inode))) {
53548+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53549+ goto out;
53550+ }
53551+
53552+ for (;;) {
53553+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53554+ break;
53555+
53556+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53557+ if (!mnt_has_parent(real_mnt))
53558+ break;
53559+
53560+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53561+ if (retval != NULL)
53562+ goto out;
53563+
53564+ dentry = real_mnt->mnt_mountpoint;
53565+ real_mnt = real_mnt->mnt_parent;
53566+ mnt = &real_mnt->mnt;
53567+ continue;
53568+ }
53569+
53570+ parent = dentry->d_parent;
53571+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53572+ if (retval != NULL)
53573+ goto out;
53574+
53575+ dentry = parent;
53576+ }
53577+
53578+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53579+
53580+ /* real_root is pinned so we don't have to hold a reference */
53581+ if (retval == NULL)
53582+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53583+out:
53584+ br_read_unlock(&vfsmount_lock);
53585+ write_sequnlock(&rename_lock);
53586+
53587+ BUG_ON(retval == NULL);
53588+
53589+ return retval;
53590+}
53591+
53592+static __inline__ struct acl_object_label *
53593+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53594+ const struct acl_subject_label *subj)
53595+{
53596+ char *path = NULL;
53597+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53598+}
53599+
53600+static __inline__ struct acl_object_label *
53601+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53602+ const struct acl_subject_label *subj)
53603+{
53604+ char *path = NULL;
53605+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53606+}
53607+
53608+static __inline__ struct acl_object_label *
53609+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53610+ const struct acl_subject_label *subj, char *path)
53611+{
53612+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53613+}
53614+
53615+static struct acl_subject_label *
53616+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53617+ const struct acl_role_label *role)
53618+{
53619+ struct dentry *dentry = (struct dentry *) l_dentry;
53620+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53621+ struct mount *real_mnt = real_mount(mnt);
53622+ struct acl_subject_label *retval;
53623+ struct dentry *parent;
53624+
53625+ write_seqlock(&rename_lock);
53626+ br_read_lock(&vfsmount_lock);
53627+
53628+ for (;;) {
53629+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53630+ break;
53631+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53632+ if (!mnt_has_parent(real_mnt))
53633+ break;
53634+
53635+ spin_lock(&dentry->d_lock);
53636+ read_lock(&gr_inode_lock);
53637+ retval =
53638+ lookup_acl_subj_label(dentry->d_inode->i_ino,
53639+ __get_dev(dentry), role);
53640+ read_unlock(&gr_inode_lock);
53641+ spin_unlock(&dentry->d_lock);
53642+ if (retval != NULL)
53643+ goto out;
53644+
53645+ dentry = real_mnt->mnt_mountpoint;
53646+ real_mnt = real_mnt->mnt_parent;
53647+ mnt = &real_mnt->mnt;
53648+ continue;
53649+ }
53650+
53651+ spin_lock(&dentry->d_lock);
53652+ read_lock(&gr_inode_lock);
53653+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53654+ __get_dev(dentry), role);
53655+ read_unlock(&gr_inode_lock);
53656+ parent = dentry->d_parent;
53657+ spin_unlock(&dentry->d_lock);
53658+
53659+ if (retval != NULL)
53660+ goto out;
53661+
53662+ dentry = parent;
53663+ }
53664+
53665+ spin_lock(&dentry->d_lock);
53666+ read_lock(&gr_inode_lock);
53667+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53668+ __get_dev(dentry), role);
53669+ read_unlock(&gr_inode_lock);
53670+ spin_unlock(&dentry->d_lock);
53671+
53672+ if (unlikely(retval == NULL)) {
53673+ /* real_root is pinned, we don't need to hold a reference */
53674+ read_lock(&gr_inode_lock);
53675+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53676+ __get_dev(real_root.dentry), role);
53677+ read_unlock(&gr_inode_lock);
53678+ }
53679+out:
53680+ br_read_unlock(&vfsmount_lock);
53681+ write_sequnlock(&rename_lock);
53682+
53683+ BUG_ON(retval == NULL);
53684+
53685+ return retval;
53686+}
53687+
53688+static void
53689+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53690+{
53691+ struct task_struct *task = current;
53692+ const struct cred *cred = current_cred();
53693+
53694+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53695+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53696+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53697+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53698+
53699+ return;
53700+}
53701+
53702+static void
53703+gr_log_learn_id_change(const char type, const unsigned int real,
53704+ const unsigned int effective, const unsigned int fs)
53705+{
53706+ struct task_struct *task = current;
53707+ const struct cred *cred = current_cred();
53708+
53709+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53710+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53711+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53712+ type, real, effective, fs, &task->signal->saved_ip);
53713+
53714+ return;
53715+}
53716+
53717+__u32
53718+gr_search_file(const struct dentry * dentry, const __u32 mode,
53719+ const struct vfsmount * mnt)
53720+{
53721+ __u32 retval = mode;
53722+ struct acl_subject_label *curracl;
53723+ struct acl_object_label *currobj;
53724+
53725+ if (unlikely(!(gr_status & GR_READY)))
53726+ return (mode & ~GR_AUDITS);
53727+
53728+ curracl = current->acl;
53729+
53730+ currobj = chk_obj_label(dentry, mnt, curracl);
53731+ retval = currobj->mode & mode;
53732+
53733+ /* if we're opening a specified transfer file for writing
53734+ (e.g. /dev/initctl), then transfer our role to init
53735+ */
53736+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53737+ current->role->roletype & GR_ROLE_PERSIST)) {
53738+ struct task_struct *task = init_pid_ns.child_reaper;
53739+
53740+ if (task->role != current->role) {
53741+ task->acl_sp_role = 0;
53742+ task->acl_role_id = current->acl_role_id;
53743+ task->role = current->role;
53744+ rcu_read_lock();
53745+ read_lock(&grsec_exec_file_lock);
53746+ gr_apply_subject_to_task(task);
53747+ read_unlock(&grsec_exec_file_lock);
53748+ rcu_read_unlock();
53749+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53750+ }
53751+ }
53752+
53753+ if (unlikely
53754+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53755+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53756+ __u32 new_mode = mode;
53757+
53758+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53759+
53760+ retval = new_mode;
53761+
53762+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53763+ new_mode |= GR_INHERIT;
53764+
53765+ if (!(mode & GR_NOLEARN))
53766+ gr_log_learn(dentry, mnt, new_mode);
53767+ }
53768+
53769+ return retval;
53770+}
53771+
53772+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53773+ const struct dentry *parent,
53774+ const struct vfsmount *mnt)
53775+{
53776+ struct name_entry *match;
53777+ struct acl_object_label *matchpo;
53778+ struct acl_subject_label *curracl;
53779+ char *path;
53780+
53781+ if (unlikely(!(gr_status & GR_READY)))
53782+ return NULL;
53783+
53784+ preempt_disable();
53785+ path = gr_to_filename_rbac(new_dentry, mnt);
53786+ match = lookup_name_entry_create(path);
53787+
53788+ curracl = current->acl;
53789+
53790+ if (match) {
53791+ read_lock(&gr_inode_lock);
53792+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53793+ read_unlock(&gr_inode_lock);
53794+
53795+ if (matchpo) {
53796+ preempt_enable();
53797+ return matchpo;
53798+ }
53799+ }
53800+
53801+ // lookup parent
53802+
53803+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53804+
53805+ preempt_enable();
53806+ return matchpo;
53807+}
53808+
53809+__u32
53810+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53811+ const struct vfsmount * mnt, const __u32 mode)
53812+{
53813+ struct acl_object_label *matchpo;
53814+ __u32 retval;
53815+
53816+ if (unlikely(!(gr_status & GR_READY)))
53817+ return (mode & ~GR_AUDITS);
53818+
53819+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
53820+
53821+ retval = matchpo->mode & mode;
53822+
53823+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53824+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53825+ __u32 new_mode = mode;
53826+
53827+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53828+
53829+ gr_log_learn(new_dentry, mnt, new_mode);
53830+ return new_mode;
53831+ }
53832+
53833+ return retval;
53834+}
53835+
53836+__u32
53837+gr_check_link(const struct dentry * new_dentry,
53838+ const struct dentry * parent_dentry,
53839+ const struct vfsmount * parent_mnt,
53840+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53841+{
53842+ struct acl_object_label *obj;
53843+ __u32 oldmode, newmode;
53844+ __u32 needmode;
53845+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53846+ GR_DELETE | GR_INHERIT;
53847+
53848+ if (unlikely(!(gr_status & GR_READY)))
53849+ return (GR_CREATE | GR_LINK);
53850+
53851+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53852+ oldmode = obj->mode;
53853+
53854+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53855+ newmode = obj->mode;
53856+
53857+ needmode = newmode & checkmodes;
53858+
53859+ // old name for hardlink must have at least the permissions of the new name
53860+ if ((oldmode & needmode) != needmode)
53861+ goto bad;
53862+
53863+ // if old name had restrictions/auditing, make sure the new name does as well
53864+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53865+
53866+ // don't allow hardlinking of suid/sgid/fcapped files without permission
53867+ if (is_privileged_binary(old_dentry))
53868+ needmode |= GR_SETID;
53869+
53870+ if ((newmode & needmode) != needmode)
53871+ goto bad;
53872+
53873+ // enforce minimum permissions
53874+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53875+ return newmode;
53876+bad:
53877+ needmode = oldmode;
53878+ if (is_privileged_binary(old_dentry))
53879+ needmode |= GR_SETID;
53880+
53881+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53882+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53883+ return (GR_CREATE | GR_LINK);
53884+ } else if (newmode & GR_SUPPRESS)
53885+ return GR_SUPPRESS;
53886+ else
53887+ return 0;
53888+}
53889+
53890+int
53891+gr_check_hidden_task(const struct task_struct *task)
53892+{
53893+ if (unlikely(!(gr_status & GR_READY)))
53894+ return 0;
53895+
53896+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53897+ return 1;
53898+
53899+ return 0;
53900+}
53901+
53902+int
53903+gr_check_protected_task(const struct task_struct *task)
53904+{
53905+ if (unlikely(!(gr_status & GR_READY) || !task))
53906+ return 0;
53907+
53908+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53909+ task->acl != current->acl)
53910+ return 1;
53911+
53912+ return 0;
53913+}
53914+
53915+int
53916+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53917+{
53918+ struct task_struct *p;
53919+ int ret = 0;
53920+
53921+ if (unlikely(!(gr_status & GR_READY) || !pid))
53922+ return ret;
53923+
53924+ read_lock(&tasklist_lock);
53925+ do_each_pid_task(pid, type, p) {
53926+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53927+ p->acl != current->acl) {
53928+ ret = 1;
53929+ goto out;
53930+ }
53931+ } while_each_pid_task(pid, type, p);
53932+out:
53933+ read_unlock(&tasklist_lock);
53934+
53935+ return ret;
53936+}
53937+
53938+void
53939+gr_copy_label(struct task_struct *tsk)
53940+{
53941+ tsk->signal->used_accept = 0;
53942+ tsk->acl_sp_role = 0;
53943+ tsk->acl_role_id = current->acl_role_id;
53944+ tsk->acl = current->acl;
53945+ tsk->role = current->role;
53946+ tsk->signal->curr_ip = current->signal->curr_ip;
53947+ tsk->signal->saved_ip = current->signal->saved_ip;
53948+ if (current->exec_file)
53949+ get_file(current->exec_file);
53950+ tsk->exec_file = current->exec_file;
53951+ tsk->is_writable = current->is_writable;
53952+ if (unlikely(current->signal->used_accept)) {
53953+ current->signal->curr_ip = 0;
53954+ current->signal->saved_ip = 0;
53955+ }
53956+
53957+ return;
53958+}
53959+
53960+static void
53961+gr_set_proc_res(struct task_struct *task)
53962+{
53963+ struct acl_subject_label *proc;
53964+ unsigned short i;
53965+
53966+ proc = task->acl;
53967+
53968+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53969+ return;
53970+
53971+ for (i = 0; i < RLIM_NLIMITS; i++) {
53972+ if (!(proc->resmask & (1 << i)))
53973+ continue;
53974+
53975+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53976+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53977+ }
53978+
53979+ return;
53980+}
53981+
53982+extern int __gr_process_user_ban(struct user_struct *user);
53983+
53984+int
53985+gr_check_user_change(int real, int effective, int fs)
53986+{
53987+ unsigned int i;
53988+ __u16 num;
53989+ uid_t *uidlist;
53990+ int curuid;
53991+ int realok = 0;
53992+ int effectiveok = 0;
53993+ int fsok = 0;
53994+
53995+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53996+ struct user_struct *user;
53997+
53998+ if (real == -1)
53999+ goto skipit;
54000+
54001+ user = find_user(real);
54002+ if (user == NULL)
54003+ goto skipit;
54004+
54005+ if (__gr_process_user_ban(user)) {
54006+ /* for find_user */
54007+ free_uid(user);
54008+ return 1;
54009+ }
54010+
54011+ /* for find_user */
54012+ free_uid(user);
54013+
54014+skipit:
54015+#endif
54016+
54017+ if (unlikely(!(gr_status & GR_READY)))
54018+ return 0;
54019+
54020+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54021+ gr_log_learn_id_change('u', real, effective, fs);
54022+
54023+ num = current->acl->user_trans_num;
54024+ uidlist = current->acl->user_transitions;
54025+
54026+ if (uidlist == NULL)
54027+ return 0;
54028+
54029+ if (real == -1)
54030+ realok = 1;
54031+ if (effective == -1)
54032+ effectiveok = 1;
54033+ if (fs == -1)
54034+ fsok = 1;
54035+
54036+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
54037+ for (i = 0; i < num; i++) {
54038+ curuid = (int)uidlist[i];
54039+ if (real == curuid)
54040+ realok = 1;
54041+ if (effective == curuid)
54042+ effectiveok = 1;
54043+ if (fs == curuid)
54044+ fsok = 1;
54045+ }
54046+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
54047+ for (i = 0; i < num; i++) {
54048+ curuid = (int)uidlist[i];
54049+ if (real == curuid)
54050+ break;
54051+ if (effective == curuid)
54052+ break;
54053+ if (fs == curuid)
54054+ break;
54055+ }
54056+ /* not in deny list */
54057+ if (i == num) {
54058+ realok = 1;
54059+ effectiveok = 1;
54060+ fsok = 1;
54061+ }
54062+ }
54063+
54064+ if (realok && effectiveok && fsok)
54065+ return 0;
54066+ else {
54067+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54068+ return 1;
54069+ }
54070+}
54071+
54072+int
54073+gr_check_group_change(int real, int effective, int fs)
54074+{
54075+ unsigned int i;
54076+ __u16 num;
54077+ gid_t *gidlist;
54078+ int curgid;
54079+ int realok = 0;
54080+ int effectiveok = 0;
54081+ int fsok = 0;
54082+
54083+ if (unlikely(!(gr_status & GR_READY)))
54084+ return 0;
54085+
54086+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54087+ gr_log_learn_id_change('g', real, effective, fs);
54088+
54089+ num = current->acl->group_trans_num;
54090+ gidlist = current->acl->group_transitions;
54091+
54092+ if (gidlist == NULL)
54093+ return 0;
54094+
54095+ if (real == -1)
54096+ realok = 1;
54097+ if (effective == -1)
54098+ effectiveok = 1;
54099+ if (fs == -1)
54100+ fsok = 1;
54101+
54102+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
54103+ for (i = 0; i < num; i++) {
54104+ curgid = (int)gidlist[i];
54105+ if (real == curgid)
54106+ realok = 1;
54107+ if (effective == curgid)
54108+ effectiveok = 1;
54109+ if (fs == curgid)
54110+ fsok = 1;
54111+ }
54112+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
54113+ for (i = 0; i < num; i++) {
54114+ curgid = (int)gidlist[i];
54115+ if (real == curgid)
54116+ break;
54117+ if (effective == curgid)
54118+ break;
54119+ if (fs == curgid)
54120+ break;
54121+ }
54122+ /* not in deny list */
54123+ if (i == num) {
54124+ realok = 1;
54125+ effectiveok = 1;
54126+ fsok = 1;
54127+ }
54128+ }
54129+
54130+ if (realok && effectiveok && fsok)
54131+ return 0;
54132+ else {
54133+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54134+ return 1;
54135+ }
54136+}
54137+
54138+extern int gr_acl_is_capable(const int cap);
54139+
54140+void
54141+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54142+{
54143+ struct acl_role_label *role = task->role;
54144+ struct acl_subject_label *subj = NULL;
54145+ struct acl_object_label *obj;
54146+ struct file *filp;
54147+
54148+ if (unlikely(!(gr_status & GR_READY)))
54149+ return;
54150+
54151+ filp = task->exec_file;
54152+
54153+ /* kernel process, we'll give them the kernel role */
54154+ if (unlikely(!filp)) {
54155+ task->role = kernel_role;
54156+ task->acl = kernel_role->root_label;
54157+ return;
54158+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54159+ role = lookup_acl_role_label(task, uid, gid);
54160+
54161+ /* don't change the role if we're not a privileged process */
54162+ if (role && task->role != role &&
54163+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54164+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54165+ return;
54166+
54167+ /* perform subject lookup in possibly new role
54168+ we can use this result below in the case where role == task->role
54169+ */
54170+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54171+
54172+ /* if we changed uid/gid, but result in the same role
54173+ and are using inheritance, don't lose the inherited subject
54174+ if current subject is other than what normal lookup
54175+ would result in, we arrived via inheritance, don't
54176+ lose subject
54177+ */
54178+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54179+ (subj == task->acl)))
54180+ task->acl = subj;
54181+
54182+ task->role = role;
54183+
54184+ task->is_writable = 0;
54185+
54186+ /* ignore additional mmap checks for processes that are writable
54187+ by the default ACL */
54188+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54189+ if (unlikely(obj->mode & GR_WRITE))
54190+ task->is_writable = 1;
54191+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54192+ if (unlikely(obj->mode & GR_WRITE))
54193+ task->is_writable = 1;
54194+
54195+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54196+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54197+#endif
54198+
54199+ gr_set_proc_res(task);
54200+
54201+ return;
54202+}
54203+
54204+int
54205+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54206+ const int unsafe_flags)
54207+{
54208+ struct task_struct *task = current;
54209+ struct acl_subject_label *newacl;
54210+ struct acl_object_label *obj;
54211+ __u32 retmode;
54212+
54213+ if (unlikely(!(gr_status & GR_READY)))
54214+ return 0;
54215+
54216+ newacl = chk_subj_label(dentry, mnt, task->role);
54217+
54218+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54219+ did an exec
54220+ */
54221+ rcu_read_lock();
54222+ read_lock(&tasklist_lock);
54223+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54224+ (task->parent->acl->mode & GR_POVERRIDE))) {
54225+ read_unlock(&tasklist_lock);
54226+ rcu_read_unlock();
54227+ goto skip_check;
54228+ }
54229+ read_unlock(&tasklist_lock);
54230+ rcu_read_unlock();
54231+
54232+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54233+ !(task->role->roletype & GR_ROLE_GOD) &&
54234+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54235+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54236+ if (unsafe_flags & LSM_UNSAFE_SHARE)
54237+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54238+ else
54239+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54240+ return -EACCES;
54241+ }
54242+
54243+skip_check:
54244+
54245+ obj = chk_obj_label(dentry, mnt, task->acl);
54246+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54247+
54248+ if (!(task->acl->mode & GR_INHERITLEARN) &&
54249+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54250+ if (obj->nested)
54251+ task->acl = obj->nested;
54252+ else
54253+ task->acl = newacl;
54254+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54255+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54256+
54257+ task->is_writable = 0;
54258+
54259+ /* ignore additional mmap checks for processes that are writable
54260+ by the default ACL */
54261+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
54262+ if (unlikely(obj->mode & GR_WRITE))
54263+ task->is_writable = 1;
54264+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
54265+ if (unlikely(obj->mode & GR_WRITE))
54266+ task->is_writable = 1;
54267+
54268+ gr_set_proc_res(task);
54269+
54270+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54271+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54272+#endif
54273+ return 0;
54274+}
54275+
54276+/* always called with valid inodev ptr */
54277+static void
54278+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54279+{
54280+ struct acl_object_label *matchpo;
54281+ struct acl_subject_label *matchps;
54282+ struct acl_subject_label *subj;
54283+ struct acl_role_label *role;
54284+ unsigned int x;
54285+
54286+ FOR_EACH_ROLE_START(role)
54287+ FOR_EACH_SUBJECT_START(role, subj, x)
54288+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54289+ matchpo->mode |= GR_DELETED;
54290+ FOR_EACH_SUBJECT_END(subj,x)
54291+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
54292+ if (subj->inode == ino && subj->device == dev)
54293+ subj->mode |= GR_DELETED;
54294+ FOR_EACH_NESTED_SUBJECT_END(subj)
54295+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54296+ matchps->mode |= GR_DELETED;
54297+ FOR_EACH_ROLE_END(role)
54298+
54299+ inodev->nentry->deleted = 1;
54300+
54301+ return;
54302+}
54303+
54304+void
54305+gr_handle_delete(const ino_t ino, const dev_t dev)
54306+{
54307+ struct inodev_entry *inodev;
54308+
54309+ if (unlikely(!(gr_status & GR_READY)))
54310+ return;
54311+
54312+ write_lock(&gr_inode_lock);
54313+ inodev = lookup_inodev_entry(ino, dev);
54314+ if (inodev != NULL)
54315+ do_handle_delete(inodev, ino, dev);
54316+ write_unlock(&gr_inode_lock);
54317+
54318+ return;
54319+}
54320+
54321+static void
54322+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54323+ const ino_t newinode, const dev_t newdevice,
54324+ struct acl_subject_label *subj)
54325+{
54326+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54327+ struct acl_object_label *match;
54328+
54329+ match = subj->obj_hash[index];
54330+
54331+ while (match && (match->inode != oldinode ||
54332+ match->device != olddevice ||
54333+ !(match->mode & GR_DELETED)))
54334+ match = match->next;
54335+
54336+ if (match && (match->inode == oldinode)
54337+ && (match->device == olddevice)
54338+ && (match->mode & GR_DELETED)) {
54339+ if (match->prev == NULL) {
54340+ subj->obj_hash[index] = match->next;
54341+ if (match->next != NULL)
54342+ match->next->prev = NULL;
54343+ } else {
54344+ match->prev->next = match->next;
54345+ if (match->next != NULL)
54346+ match->next->prev = match->prev;
54347+ }
54348+ match->prev = NULL;
54349+ match->next = NULL;
54350+ match->inode = newinode;
54351+ match->device = newdevice;
54352+ match->mode &= ~GR_DELETED;
54353+
54354+ insert_acl_obj_label(match, subj);
54355+ }
54356+
54357+ return;
54358+}
54359+
54360+static void
54361+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54362+ const ino_t newinode, const dev_t newdevice,
54363+ struct acl_role_label *role)
54364+{
54365+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54366+ struct acl_subject_label *match;
54367+
54368+ match = role->subj_hash[index];
54369+
54370+ while (match && (match->inode != oldinode ||
54371+ match->device != olddevice ||
54372+ !(match->mode & GR_DELETED)))
54373+ match = match->next;
54374+
54375+ if (match && (match->inode == oldinode)
54376+ && (match->device == olddevice)
54377+ && (match->mode & GR_DELETED)) {
54378+ if (match->prev == NULL) {
54379+ role->subj_hash[index] = match->next;
54380+ if (match->next != NULL)
54381+ match->next->prev = NULL;
54382+ } else {
54383+ match->prev->next = match->next;
54384+ if (match->next != NULL)
54385+ match->next->prev = match->prev;
54386+ }
54387+ match->prev = NULL;
54388+ match->next = NULL;
54389+ match->inode = newinode;
54390+ match->device = newdevice;
54391+ match->mode &= ~GR_DELETED;
54392+
54393+ insert_acl_subj_label(match, role);
54394+ }
54395+
54396+ return;
54397+}
54398+
54399+static void
54400+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54401+ const ino_t newinode, const dev_t newdevice)
54402+{
54403+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54404+ struct inodev_entry *match;
54405+
54406+ match = inodev_set.i_hash[index];
54407+
54408+ while (match && (match->nentry->inode != oldinode ||
54409+ match->nentry->device != olddevice || !match->nentry->deleted))
54410+ match = match->next;
54411+
54412+ if (match && (match->nentry->inode == oldinode)
54413+ && (match->nentry->device == olddevice) &&
54414+ match->nentry->deleted) {
54415+ if (match->prev == NULL) {
54416+ inodev_set.i_hash[index] = match->next;
54417+ if (match->next != NULL)
54418+ match->next->prev = NULL;
54419+ } else {
54420+ match->prev->next = match->next;
54421+ if (match->next != NULL)
54422+ match->next->prev = match->prev;
54423+ }
54424+ match->prev = NULL;
54425+ match->next = NULL;
54426+ match->nentry->inode = newinode;
54427+ match->nentry->device = newdevice;
54428+ match->nentry->deleted = 0;
54429+
54430+ insert_inodev_entry(match);
54431+ }
54432+
54433+ return;
54434+}
54435+
54436+static void
54437+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54438+{
54439+ struct acl_subject_label *subj;
54440+ struct acl_role_label *role;
54441+ unsigned int x;
54442+
54443+ FOR_EACH_ROLE_START(role)
54444+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54445+
54446+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
54447+ if ((subj->inode == ino) && (subj->device == dev)) {
54448+ subj->inode = ino;
54449+ subj->device = dev;
54450+ }
54451+ FOR_EACH_NESTED_SUBJECT_END(subj)
54452+ FOR_EACH_SUBJECT_START(role, subj, x)
54453+ update_acl_obj_label(matchn->inode, matchn->device,
54454+ ino, dev, subj);
54455+ FOR_EACH_SUBJECT_END(subj,x)
54456+ FOR_EACH_ROLE_END(role)
54457+
54458+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54459+
54460+ return;
54461+}
54462+
54463+static void
54464+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54465+ const struct vfsmount *mnt)
54466+{
54467+ ino_t ino = dentry->d_inode->i_ino;
54468+ dev_t dev = __get_dev(dentry);
54469+
54470+ __do_handle_create(matchn, ino, dev);
54471+
54472+ return;
54473+}
54474+
54475+void
54476+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54477+{
54478+ struct name_entry *matchn;
54479+
54480+ if (unlikely(!(gr_status & GR_READY)))
54481+ return;
54482+
54483+ preempt_disable();
54484+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54485+
54486+ if (unlikely((unsigned long)matchn)) {
54487+ write_lock(&gr_inode_lock);
54488+ do_handle_create(matchn, dentry, mnt);
54489+ write_unlock(&gr_inode_lock);
54490+ }
54491+ preempt_enable();
54492+
54493+ return;
54494+}
54495+
54496+void
54497+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54498+{
54499+ struct name_entry *matchn;
54500+
54501+ if (unlikely(!(gr_status & GR_READY)))
54502+ return;
54503+
54504+ preempt_disable();
54505+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54506+
54507+ if (unlikely((unsigned long)matchn)) {
54508+ write_lock(&gr_inode_lock);
54509+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54510+ write_unlock(&gr_inode_lock);
54511+ }
54512+ preempt_enable();
54513+
54514+ return;
54515+}
54516+
54517+void
54518+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54519+ struct dentry *old_dentry,
54520+ struct dentry *new_dentry,
54521+ struct vfsmount *mnt, const __u8 replace)
54522+{
54523+ struct name_entry *matchn;
54524+ struct inodev_entry *inodev;
54525+ struct inode *inode = new_dentry->d_inode;
54526+ ino_t old_ino = old_dentry->d_inode->i_ino;
54527+ dev_t old_dev = __get_dev(old_dentry);
54528+
54529+ /* vfs_rename swaps the name and parent link for old_dentry and
54530+ new_dentry
54531+ at this point, old_dentry has the new name, parent link, and inode
54532+ for the renamed file
54533+ if a file is being replaced by a rename, new_dentry has the inode
54534+ and name for the replaced file
54535+ */
54536+
54537+ if (unlikely(!(gr_status & GR_READY)))
54538+ return;
54539+
54540+ preempt_disable();
54541+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54542+
54543+ /* we wouldn't have to check d_inode if it weren't for
54544+ NFS silly-renaming
54545+ */
54546+
54547+ write_lock(&gr_inode_lock);
54548+ if (unlikely(replace && inode)) {
54549+ ino_t new_ino = inode->i_ino;
54550+ dev_t new_dev = __get_dev(new_dentry);
54551+
54552+ inodev = lookup_inodev_entry(new_ino, new_dev);
54553+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54554+ do_handle_delete(inodev, new_ino, new_dev);
54555+ }
54556+
54557+ inodev = lookup_inodev_entry(old_ino, old_dev);
54558+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54559+ do_handle_delete(inodev, old_ino, old_dev);
54560+
54561+ if (unlikely((unsigned long)matchn))
54562+ do_handle_create(matchn, old_dentry, mnt);
54563+
54564+ write_unlock(&gr_inode_lock);
54565+ preempt_enable();
54566+
54567+ return;
54568+}
54569+
54570+static int
54571+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54572+ unsigned char **sum)
54573+{
54574+ struct acl_role_label *r;
54575+ struct role_allowed_ip *ipp;
54576+ struct role_transition *trans;
54577+ unsigned int i;
54578+ int found = 0;
54579+ u32 curr_ip = current->signal->curr_ip;
54580+
54581+ current->signal->saved_ip = curr_ip;
54582+
54583+ /* check transition table */
54584+
54585+ for (trans = current->role->transitions; trans; trans = trans->next) {
54586+ if (!strcmp(rolename, trans->rolename)) {
54587+ found = 1;
54588+ break;
54589+ }
54590+ }
54591+
54592+ if (!found)
54593+ return 0;
54594+
54595+ /* handle special roles that do not require authentication
54596+ and check ip */
54597+
54598+ FOR_EACH_ROLE_START(r)
54599+ if (!strcmp(rolename, r->rolename) &&
54600+ (r->roletype & GR_ROLE_SPECIAL)) {
54601+ found = 0;
54602+ if (r->allowed_ips != NULL) {
54603+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54604+ if ((ntohl(curr_ip) & ipp->netmask) ==
54605+ (ntohl(ipp->addr) & ipp->netmask))
54606+ found = 1;
54607+ }
54608+ } else
54609+ found = 2;
54610+ if (!found)
54611+ return 0;
54612+
54613+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54614+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54615+ *salt = NULL;
54616+ *sum = NULL;
54617+ return 1;
54618+ }
54619+ }
54620+ FOR_EACH_ROLE_END(r)
54621+
54622+ for (i = 0; i < num_sprole_pws; i++) {
54623+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54624+ *salt = acl_special_roles[i]->salt;
54625+ *sum = acl_special_roles[i]->sum;
54626+ return 1;
54627+ }
54628+ }
54629+
54630+ return 0;
54631+}
54632+
54633+static void
54634+assign_special_role(char *rolename)
54635+{
54636+ struct acl_object_label *obj;
54637+ struct acl_role_label *r;
54638+ struct acl_role_label *assigned = NULL;
54639+ struct task_struct *tsk;
54640+ struct file *filp;
54641+
54642+ FOR_EACH_ROLE_START(r)
54643+ if (!strcmp(rolename, r->rolename) &&
54644+ (r->roletype & GR_ROLE_SPECIAL)) {
54645+ assigned = r;
54646+ break;
54647+ }
54648+ FOR_EACH_ROLE_END(r)
54649+
54650+ if (!assigned)
54651+ return;
54652+
54653+ read_lock(&tasklist_lock);
54654+ read_lock(&grsec_exec_file_lock);
54655+
54656+ tsk = current->real_parent;
54657+ if (tsk == NULL)
54658+ goto out_unlock;
54659+
54660+ filp = tsk->exec_file;
54661+ if (filp == NULL)
54662+ goto out_unlock;
54663+
54664+ tsk->is_writable = 0;
54665+
54666+ tsk->acl_sp_role = 1;
54667+ tsk->acl_role_id = ++acl_sp_role_value;
54668+ tsk->role = assigned;
54669+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54670+
54671+ /* ignore additional mmap checks for processes that are writable
54672+ by the default ACL */
54673+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54674+ if (unlikely(obj->mode & GR_WRITE))
54675+ tsk->is_writable = 1;
54676+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54677+ if (unlikely(obj->mode & GR_WRITE))
54678+ tsk->is_writable = 1;
54679+
54680+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54681+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54682+#endif
54683+
54684+out_unlock:
54685+ read_unlock(&grsec_exec_file_lock);
54686+ read_unlock(&tasklist_lock);
54687+ return;
54688+}
54689+
54690+int gr_check_secure_terminal(struct task_struct *task)
54691+{
54692+ struct task_struct *p, *p2, *p3;
54693+ struct files_struct *files;
54694+ struct fdtable *fdt;
54695+ struct file *our_file = NULL, *file;
54696+ int i;
54697+
54698+ if (task->signal->tty == NULL)
54699+ return 1;
54700+
54701+ files = get_files_struct(task);
54702+ if (files != NULL) {
54703+ rcu_read_lock();
54704+ fdt = files_fdtable(files);
54705+ for (i=0; i < fdt->max_fds; i++) {
54706+ file = fcheck_files(files, i);
54707+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54708+ get_file(file);
54709+ our_file = file;
54710+ }
54711+ }
54712+ rcu_read_unlock();
54713+ put_files_struct(files);
54714+ }
54715+
54716+ if (our_file == NULL)
54717+ return 1;
54718+
54719+ read_lock(&tasklist_lock);
54720+ do_each_thread(p2, p) {
54721+ files = get_files_struct(p);
54722+ if (files == NULL ||
54723+ (p->signal && p->signal->tty == task->signal->tty)) {
54724+ if (files != NULL)
54725+ put_files_struct(files);
54726+ continue;
54727+ }
54728+ rcu_read_lock();
54729+ fdt = files_fdtable(files);
54730+ for (i=0; i < fdt->max_fds; i++) {
54731+ file = fcheck_files(files, i);
54732+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54733+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54734+ p3 = task;
54735+ while (p3->pid > 0) {
54736+ if (p3 == p)
54737+ break;
54738+ p3 = p3->real_parent;
54739+ }
54740+ if (p3 == p)
54741+ break;
54742+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54743+ gr_handle_alertkill(p);
54744+ rcu_read_unlock();
54745+ put_files_struct(files);
54746+ read_unlock(&tasklist_lock);
54747+ fput(our_file);
54748+ return 0;
54749+ }
54750+ }
54751+ rcu_read_unlock();
54752+ put_files_struct(files);
54753+ } while_each_thread(p2, p);
54754+ read_unlock(&tasklist_lock);
54755+
54756+ fput(our_file);
54757+ return 1;
54758+}
54759+
54760+static int gr_rbac_disable(void *unused)
54761+{
54762+ pax_open_kernel();
54763+ gr_status &= ~GR_READY;
54764+ pax_close_kernel();
54765+
54766+ return 0;
54767+}
54768+
54769+ssize_t
54770+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54771+{
54772+ struct gr_arg_wrapper uwrap;
54773+ unsigned char *sprole_salt = NULL;
54774+ unsigned char *sprole_sum = NULL;
54775+ int error = sizeof (struct gr_arg_wrapper);
54776+ int error2 = 0;
54777+
54778+ mutex_lock(&gr_dev_mutex);
54779+
54780+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54781+ error = -EPERM;
54782+ goto out;
54783+ }
54784+
54785+ if (count != sizeof (struct gr_arg_wrapper)) {
54786+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54787+ error = -EINVAL;
54788+ goto out;
54789+ }
54790+
54791+
54792+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54793+ gr_auth_expires = 0;
54794+ gr_auth_attempts = 0;
54795+ }
54796+
54797+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54798+ error = -EFAULT;
54799+ goto out;
54800+ }
54801+
54802+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54803+ error = -EINVAL;
54804+ goto out;
54805+ }
54806+
54807+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54808+ error = -EFAULT;
54809+ goto out;
54810+ }
54811+
54812+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54813+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54814+ time_after(gr_auth_expires, get_seconds())) {
54815+ error = -EBUSY;
54816+ goto out;
54817+ }
54818+
54819+ /* if non-root trying to do anything other than use a special role,
54820+ do not attempt authentication, do not count towards authentication
54821+ locking
54822+ */
54823+
54824+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54825+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54826+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54827+ error = -EPERM;
54828+ goto out;
54829+ }
54830+
54831+ /* ensure pw and special role name are null terminated */
54832+
54833+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54834+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54835+
54836+ /* Okay.
54837+ * We have our enough of the argument structure..(we have yet
54838+ * to copy_from_user the tables themselves) . Copy the tables
54839+ * only if we need them, i.e. for loading operations. */
54840+
54841+ switch (gr_usermode->mode) {
54842+ case GR_STATUS:
54843+ if (gr_status & GR_READY) {
54844+ error = 1;
54845+ if (!gr_check_secure_terminal(current))
54846+ error = 3;
54847+ } else
54848+ error = 2;
54849+ goto out;
54850+ case GR_SHUTDOWN:
54851+ if ((gr_status & GR_READY)
54852+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54853+ stop_machine(gr_rbac_disable, NULL, NULL);
54854+ free_variables();
54855+ memset(gr_usermode, 0, sizeof (struct gr_arg));
54856+ memset(gr_system_salt, 0, GR_SALT_LEN);
54857+ memset(gr_system_sum, 0, GR_SHA_LEN);
54858+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54859+ } else if (gr_status & GR_READY) {
54860+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54861+ error = -EPERM;
54862+ } else {
54863+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54864+ error = -EAGAIN;
54865+ }
54866+ break;
54867+ case GR_ENABLE:
54868+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54869+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54870+ else {
54871+ if (gr_status & GR_READY)
54872+ error = -EAGAIN;
54873+ else
54874+ error = error2;
54875+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54876+ }
54877+ break;
54878+ case GR_RELOAD:
54879+ if (!(gr_status & GR_READY)) {
54880+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54881+ error = -EAGAIN;
54882+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54883+ stop_machine(gr_rbac_disable, NULL, NULL);
54884+ free_variables();
54885+ error2 = gracl_init(gr_usermode);
54886+ if (!error2)
54887+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54888+ else {
54889+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54890+ error = error2;
54891+ }
54892+ } else {
54893+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54894+ error = -EPERM;
54895+ }
54896+ break;
54897+ case GR_SEGVMOD:
54898+ if (unlikely(!(gr_status & GR_READY))) {
54899+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54900+ error = -EAGAIN;
54901+ break;
54902+ }
54903+
54904+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54905+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54906+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54907+ struct acl_subject_label *segvacl;
54908+ segvacl =
54909+ lookup_acl_subj_label(gr_usermode->segv_inode,
54910+ gr_usermode->segv_device,
54911+ current->role);
54912+ if (segvacl) {
54913+ segvacl->crashes = 0;
54914+ segvacl->expires = 0;
54915+ }
54916+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54917+ gr_remove_uid(gr_usermode->segv_uid);
54918+ }
54919+ } else {
54920+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54921+ error = -EPERM;
54922+ }
54923+ break;
54924+ case GR_SPROLE:
54925+ case GR_SPROLEPAM:
54926+ if (unlikely(!(gr_status & GR_READY))) {
54927+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54928+ error = -EAGAIN;
54929+ break;
54930+ }
54931+
54932+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54933+ current->role->expires = 0;
54934+ current->role->auth_attempts = 0;
54935+ }
54936+
54937+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54938+ time_after(current->role->expires, get_seconds())) {
54939+ error = -EBUSY;
54940+ goto out;
54941+ }
54942+
54943+ if (lookup_special_role_auth
54944+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54945+ && ((!sprole_salt && !sprole_sum)
54946+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54947+ char *p = "";
54948+ assign_special_role(gr_usermode->sp_role);
54949+ read_lock(&tasklist_lock);
54950+ if (current->real_parent)
54951+ p = current->real_parent->role->rolename;
54952+ read_unlock(&tasklist_lock);
54953+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54954+ p, acl_sp_role_value);
54955+ } else {
54956+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54957+ error = -EPERM;
54958+ if(!(current->role->auth_attempts++))
54959+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54960+
54961+ goto out;
54962+ }
54963+ break;
54964+ case GR_UNSPROLE:
54965+ if (unlikely(!(gr_status & GR_READY))) {
54966+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54967+ error = -EAGAIN;
54968+ break;
54969+ }
54970+
54971+ if (current->role->roletype & GR_ROLE_SPECIAL) {
54972+ char *p = "";
54973+ int i = 0;
54974+
54975+ read_lock(&tasklist_lock);
54976+ if (current->real_parent) {
54977+ p = current->real_parent->role->rolename;
54978+ i = current->real_parent->acl_role_id;
54979+ }
54980+ read_unlock(&tasklist_lock);
54981+
54982+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54983+ gr_set_acls(1);
54984+ } else {
54985+ error = -EPERM;
54986+ goto out;
54987+ }
54988+ break;
54989+ default:
54990+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54991+ error = -EINVAL;
54992+ break;
54993+ }
54994+
54995+ if (error != -EPERM)
54996+ goto out;
54997+
54998+ if(!(gr_auth_attempts++))
54999+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55000+
55001+ out:
55002+ mutex_unlock(&gr_dev_mutex);
55003+ return error;
55004+}
55005+
55006+/* must be called with
55007+ rcu_read_lock();
55008+ read_lock(&tasklist_lock);
55009+ read_lock(&grsec_exec_file_lock);
55010+*/
55011+int gr_apply_subject_to_task(struct task_struct *task)
55012+{
55013+ struct acl_object_label *obj;
55014+ char *tmpname;
55015+ struct acl_subject_label *tmpsubj;
55016+ struct file *filp;
55017+ struct name_entry *nmatch;
55018+
55019+ filp = task->exec_file;
55020+ if (filp == NULL)
55021+ return 0;
55022+
55023+ /* the following is to apply the correct subject
55024+ on binaries running when the RBAC system
55025+ is enabled, when the binaries have been
55026+ replaced or deleted since their execution
55027+ -----
55028+ when the RBAC system starts, the inode/dev
55029+ from exec_file will be one the RBAC system
55030+ is unaware of. It only knows the inode/dev
55031+ of the present file on disk, or the absence
55032+ of it.
55033+ */
55034+ preempt_disable();
55035+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55036+
55037+ nmatch = lookup_name_entry(tmpname);
55038+ preempt_enable();
55039+ tmpsubj = NULL;
55040+ if (nmatch) {
55041+ if (nmatch->deleted)
55042+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55043+ else
55044+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55045+ if (tmpsubj != NULL)
55046+ task->acl = tmpsubj;
55047+ }
55048+ if (tmpsubj == NULL)
55049+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55050+ task->role);
55051+ if (task->acl) {
55052+ task->is_writable = 0;
55053+ /* ignore additional mmap checks for processes that are writable
55054+ by the default ACL */
55055+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55056+ if (unlikely(obj->mode & GR_WRITE))
55057+ task->is_writable = 1;
55058+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55059+ if (unlikely(obj->mode & GR_WRITE))
55060+ task->is_writable = 1;
55061+
55062+ gr_set_proc_res(task);
55063+
55064+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55065+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55066+#endif
55067+ } else {
55068+ return 1;
55069+ }
55070+
55071+ return 0;
55072+}
55073+
55074+int
55075+gr_set_acls(const int type)
55076+{
55077+ struct task_struct *task, *task2;
55078+ struct acl_role_label *role = current->role;
55079+ __u16 acl_role_id = current->acl_role_id;
55080+ const struct cred *cred;
55081+ int ret;
55082+
55083+ rcu_read_lock();
55084+ read_lock(&tasklist_lock);
55085+ read_lock(&grsec_exec_file_lock);
55086+ do_each_thread(task2, task) {
55087+ /* check to see if we're called from the exit handler,
55088+ if so, only replace ACLs that have inherited the admin
55089+ ACL */
55090+
55091+ if (type && (task->role != role ||
55092+ task->acl_role_id != acl_role_id))
55093+ continue;
55094+
55095+ task->acl_role_id = 0;
55096+ task->acl_sp_role = 0;
55097+
55098+ if (task->exec_file) {
55099+ cred = __task_cred(task);
55100+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55101+ ret = gr_apply_subject_to_task(task);
55102+ if (ret) {
55103+ read_unlock(&grsec_exec_file_lock);
55104+ read_unlock(&tasklist_lock);
55105+ rcu_read_unlock();
55106+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55107+ return ret;
55108+ }
55109+ } else {
55110+ // it's a kernel process
55111+ task->role = kernel_role;
55112+ task->acl = kernel_role->root_label;
55113+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55114+ task->acl->mode &= ~GR_PROCFIND;
55115+#endif
55116+ }
55117+ } while_each_thread(task2, task);
55118+ read_unlock(&grsec_exec_file_lock);
55119+ read_unlock(&tasklist_lock);
55120+ rcu_read_unlock();
55121+
55122+ return 0;
55123+}
55124+
55125+void
55126+gr_learn_resource(const struct task_struct *task,
55127+ const int res, const unsigned long wanted, const int gt)
55128+{
55129+ struct acl_subject_label *acl;
55130+ const struct cred *cred;
55131+
55132+ if (unlikely((gr_status & GR_READY) &&
55133+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55134+ goto skip_reslog;
55135+
55136+#ifdef CONFIG_GRKERNSEC_RESLOG
55137+ gr_log_resource(task, res, wanted, gt);
55138+#endif
55139+ skip_reslog:
55140+
55141+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55142+ return;
55143+
55144+ acl = task->acl;
55145+
55146+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55147+ !(acl->resmask & (1 << (unsigned short) res))))
55148+ return;
55149+
55150+ if (wanted >= acl->res[res].rlim_cur) {
55151+ unsigned long res_add;
55152+
55153+ res_add = wanted;
55154+ switch (res) {
55155+ case RLIMIT_CPU:
55156+ res_add += GR_RLIM_CPU_BUMP;
55157+ break;
55158+ case RLIMIT_FSIZE:
55159+ res_add += GR_RLIM_FSIZE_BUMP;
55160+ break;
55161+ case RLIMIT_DATA:
55162+ res_add += GR_RLIM_DATA_BUMP;
55163+ break;
55164+ case RLIMIT_STACK:
55165+ res_add += GR_RLIM_STACK_BUMP;
55166+ break;
55167+ case RLIMIT_CORE:
55168+ res_add += GR_RLIM_CORE_BUMP;
55169+ break;
55170+ case RLIMIT_RSS:
55171+ res_add += GR_RLIM_RSS_BUMP;
55172+ break;
55173+ case RLIMIT_NPROC:
55174+ res_add += GR_RLIM_NPROC_BUMP;
55175+ break;
55176+ case RLIMIT_NOFILE:
55177+ res_add += GR_RLIM_NOFILE_BUMP;
55178+ break;
55179+ case RLIMIT_MEMLOCK:
55180+ res_add += GR_RLIM_MEMLOCK_BUMP;
55181+ break;
55182+ case RLIMIT_AS:
55183+ res_add += GR_RLIM_AS_BUMP;
55184+ break;
55185+ case RLIMIT_LOCKS:
55186+ res_add += GR_RLIM_LOCKS_BUMP;
55187+ break;
55188+ case RLIMIT_SIGPENDING:
55189+ res_add += GR_RLIM_SIGPENDING_BUMP;
55190+ break;
55191+ case RLIMIT_MSGQUEUE:
55192+ res_add += GR_RLIM_MSGQUEUE_BUMP;
55193+ break;
55194+ case RLIMIT_NICE:
55195+ res_add += GR_RLIM_NICE_BUMP;
55196+ break;
55197+ case RLIMIT_RTPRIO:
55198+ res_add += GR_RLIM_RTPRIO_BUMP;
55199+ break;
55200+ case RLIMIT_RTTIME:
55201+ res_add += GR_RLIM_RTTIME_BUMP;
55202+ break;
55203+ }
55204+
55205+ acl->res[res].rlim_cur = res_add;
55206+
55207+ if (wanted > acl->res[res].rlim_max)
55208+ acl->res[res].rlim_max = res_add;
55209+
55210+ /* only log the subject filename, since resource logging is supported for
55211+ single-subject learning only */
55212+ rcu_read_lock();
55213+ cred = __task_cred(task);
55214+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55215+ task->role->roletype, cred->uid, cred->gid, acl->filename,
55216+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55217+ "", (unsigned long) res, &task->signal->saved_ip);
55218+ rcu_read_unlock();
55219+ }
55220+
55221+ return;
55222+}
55223+
55224+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55225+void
55226+pax_set_initial_flags(struct linux_binprm *bprm)
55227+{
55228+ struct task_struct *task = current;
55229+ struct acl_subject_label *proc;
55230+ unsigned long flags;
55231+
55232+ if (unlikely(!(gr_status & GR_READY)))
55233+ return;
55234+
55235+ flags = pax_get_flags(task);
55236+
55237+ proc = task->acl;
55238+
55239+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55240+ flags &= ~MF_PAX_PAGEEXEC;
55241+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55242+ flags &= ~MF_PAX_SEGMEXEC;
55243+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55244+ flags &= ~MF_PAX_RANDMMAP;
55245+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55246+ flags &= ~MF_PAX_EMUTRAMP;
55247+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55248+ flags &= ~MF_PAX_MPROTECT;
55249+
55250+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55251+ flags |= MF_PAX_PAGEEXEC;
55252+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55253+ flags |= MF_PAX_SEGMEXEC;
55254+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55255+ flags |= MF_PAX_RANDMMAP;
55256+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55257+ flags |= MF_PAX_EMUTRAMP;
55258+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55259+ flags |= MF_PAX_MPROTECT;
55260+
55261+ pax_set_flags(task, flags);
55262+
55263+ return;
55264+}
55265+#endif
55266+
55267+int
55268+gr_handle_proc_ptrace(struct task_struct *task)
55269+{
55270+ struct file *filp;
55271+ struct task_struct *tmp = task;
55272+ struct task_struct *curtemp = current;
55273+ __u32 retmode;
55274+
55275+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55276+ if (unlikely(!(gr_status & GR_READY)))
55277+ return 0;
55278+#endif
55279+
55280+ read_lock(&tasklist_lock);
55281+ read_lock(&grsec_exec_file_lock);
55282+ filp = task->exec_file;
55283+
55284+ while (tmp->pid > 0) {
55285+ if (tmp == curtemp)
55286+ break;
55287+ tmp = tmp->real_parent;
55288+ }
55289+
55290+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55291+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55292+ read_unlock(&grsec_exec_file_lock);
55293+ read_unlock(&tasklist_lock);
55294+ return 1;
55295+ }
55296+
55297+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55298+ if (!(gr_status & GR_READY)) {
55299+ read_unlock(&grsec_exec_file_lock);
55300+ read_unlock(&tasklist_lock);
55301+ return 0;
55302+ }
55303+#endif
55304+
55305+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55306+ read_unlock(&grsec_exec_file_lock);
55307+ read_unlock(&tasklist_lock);
55308+
55309+ if (retmode & GR_NOPTRACE)
55310+ return 1;
55311+
55312+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55313+ && (current->acl != task->acl || (current->acl != current->role->root_label
55314+ && current->pid != task->pid)))
55315+ return 1;
55316+
55317+ return 0;
55318+}
55319+
55320+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55321+{
55322+ if (unlikely(!(gr_status & GR_READY)))
55323+ return;
55324+
55325+ if (!(current->role->roletype & GR_ROLE_GOD))
55326+ return;
55327+
55328+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55329+ p->role->rolename, gr_task_roletype_to_char(p),
55330+ p->acl->filename);
55331+}
55332+
55333+int
55334+gr_handle_ptrace(struct task_struct *task, const long request)
55335+{
55336+ struct task_struct *tmp = task;
55337+ struct task_struct *curtemp = current;
55338+ __u32 retmode;
55339+
55340+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55341+ if (unlikely(!(gr_status & GR_READY)))
55342+ return 0;
55343+#endif
55344+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55345+ read_lock(&tasklist_lock);
55346+ while (tmp->pid > 0) {
55347+ if (tmp == curtemp)
55348+ break;
55349+ tmp = tmp->real_parent;
55350+ }
55351+
55352+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55353+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55354+ read_unlock(&tasklist_lock);
55355+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55356+ return 1;
55357+ }
55358+ read_unlock(&tasklist_lock);
55359+ }
55360+
55361+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55362+ if (!(gr_status & GR_READY))
55363+ return 0;
55364+#endif
55365+
55366+ read_lock(&grsec_exec_file_lock);
55367+ if (unlikely(!task->exec_file)) {
55368+ read_unlock(&grsec_exec_file_lock);
55369+ return 0;
55370+ }
55371+
55372+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55373+ read_unlock(&grsec_exec_file_lock);
55374+
55375+ if (retmode & GR_NOPTRACE) {
55376+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55377+ return 1;
55378+ }
55379+
55380+ if (retmode & GR_PTRACERD) {
55381+ switch (request) {
55382+ case PTRACE_SEIZE:
55383+ case PTRACE_POKETEXT:
55384+ case PTRACE_POKEDATA:
55385+ case PTRACE_POKEUSR:
55386+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55387+ case PTRACE_SETREGS:
55388+ case PTRACE_SETFPREGS:
55389+#endif
55390+#ifdef CONFIG_X86
55391+ case PTRACE_SETFPXREGS:
55392+#endif
55393+#ifdef CONFIG_ALTIVEC
55394+ case PTRACE_SETVRREGS:
55395+#endif
55396+ return 1;
55397+ default:
55398+ return 0;
55399+ }
55400+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
55401+ !(current->role->roletype & GR_ROLE_GOD) &&
55402+ (current->acl != task->acl)) {
55403+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55404+ return 1;
55405+ }
55406+
55407+ return 0;
55408+}
55409+
55410+static int is_writable_mmap(const struct file *filp)
55411+{
55412+ struct task_struct *task = current;
55413+ struct acl_object_label *obj, *obj2;
55414+
55415+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55416+ !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))) {
55417+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55418+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55419+ task->role->root_label);
55420+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55421+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55422+ return 1;
55423+ }
55424+ }
55425+ return 0;
55426+}
55427+
55428+int
55429+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55430+{
55431+ __u32 mode;
55432+
55433+ if (unlikely(!file || !(prot & PROT_EXEC)))
55434+ return 1;
55435+
55436+ if (is_writable_mmap(file))
55437+ return 0;
55438+
55439+ mode =
55440+ gr_search_file(file->f_path.dentry,
55441+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55442+ file->f_path.mnt);
55443+
55444+ if (!gr_tpe_allow(file))
55445+ return 0;
55446+
55447+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55448+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55449+ return 0;
55450+ } else if (unlikely(!(mode & GR_EXEC))) {
55451+ return 0;
55452+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55453+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55454+ return 1;
55455+ }
55456+
55457+ return 1;
55458+}
55459+
55460+int
55461+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55462+{
55463+ __u32 mode;
55464+
55465+ if (unlikely(!file || !(prot & PROT_EXEC)))
55466+ return 1;
55467+
55468+ if (is_writable_mmap(file))
55469+ return 0;
55470+
55471+ mode =
55472+ gr_search_file(file->f_path.dentry,
55473+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55474+ file->f_path.mnt);
55475+
55476+ if (!gr_tpe_allow(file))
55477+ return 0;
55478+
55479+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55480+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55481+ return 0;
55482+ } else if (unlikely(!(mode & GR_EXEC))) {
55483+ return 0;
55484+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55485+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55486+ return 1;
55487+ }
55488+
55489+ return 1;
55490+}
55491+
55492+void
55493+gr_acl_handle_psacct(struct task_struct *task, const long code)
55494+{
55495+ unsigned long runtime;
55496+ unsigned long cputime;
55497+ unsigned int wday, cday;
55498+ __u8 whr, chr;
55499+ __u8 wmin, cmin;
55500+ __u8 wsec, csec;
55501+ struct timespec timeval;
55502+
55503+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55504+ !(task->acl->mode & GR_PROCACCT)))
55505+ return;
55506+
55507+ do_posix_clock_monotonic_gettime(&timeval);
55508+ runtime = timeval.tv_sec - task->start_time.tv_sec;
55509+ wday = runtime / (3600 * 24);
55510+ runtime -= wday * (3600 * 24);
55511+ whr = runtime / 3600;
55512+ runtime -= whr * 3600;
55513+ wmin = runtime / 60;
55514+ runtime -= wmin * 60;
55515+ wsec = runtime;
55516+
55517+ cputime = (task->utime + task->stime) / HZ;
55518+ cday = cputime / (3600 * 24);
55519+ cputime -= cday * (3600 * 24);
55520+ chr = cputime / 3600;
55521+ cputime -= chr * 3600;
55522+ cmin = cputime / 60;
55523+ cputime -= cmin * 60;
55524+ csec = cputime;
55525+
55526+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55527+
55528+ return;
55529+}
55530+
55531+void gr_set_kernel_label(struct task_struct *task)
55532+{
55533+ if (gr_status & GR_READY) {
55534+ task->role = kernel_role;
55535+ task->acl = kernel_role->root_label;
55536+ }
55537+ return;
55538+}
55539+
55540+#ifdef CONFIG_TASKSTATS
55541+int gr_is_taskstats_denied(int pid)
55542+{
55543+ struct task_struct *task;
55544+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55545+ const struct cred *cred;
55546+#endif
55547+ int ret = 0;
55548+
55549+ /* restrict taskstats viewing to un-chrooted root users
55550+ who have the 'view' subject flag if the RBAC system is enabled
55551+ */
55552+
55553+ rcu_read_lock();
55554+ read_lock(&tasklist_lock);
55555+ task = find_task_by_vpid(pid);
55556+ if (task) {
55557+#ifdef CONFIG_GRKERNSEC_CHROOT
55558+ if (proc_is_chrooted(task))
55559+ ret = -EACCES;
55560+#endif
55561+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55562+ cred = __task_cred(task);
55563+#ifdef CONFIG_GRKERNSEC_PROC_USER
55564+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55565+ ret = -EACCES;
55566+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55567+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55568+ ret = -EACCES;
55569+#endif
55570+#endif
55571+ if (gr_status & GR_READY) {
55572+ if (!(task->acl->mode & GR_VIEW))
55573+ ret = -EACCES;
55574+ }
55575+ } else
55576+ ret = -ENOENT;
55577+
55578+ read_unlock(&tasklist_lock);
55579+ rcu_read_unlock();
55580+
55581+ return ret;
55582+}
55583+#endif
55584+
55585+/* AUXV entries are filled via a descendant of search_binary_handler
55586+ after we've already applied the subject for the target
55587+*/
55588+int gr_acl_enable_at_secure(void)
55589+{
55590+ if (unlikely(!(gr_status & GR_READY)))
55591+ return 0;
55592+
55593+ if (current->acl->mode & GR_ATSECURE)
55594+ return 1;
55595+
55596+ return 0;
55597+}
55598+
55599+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55600+{
55601+ struct task_struct *task = current;
55602+ struct dentry *dentry = file->f_path.dentry;
55603+ struct vfsmount *mnt = file->f_path.mnt;
55604+ struct acl_object_label *obj, *tmp;
55605+ struct acl_subject_label *subj;
55606+ unsigned int bufsize;
55607+ int is_not_root;
55608+ char *path;
55609+ dev_t dev = __get_dev(dentry);
55610+
55611+ if (unlikely(!(gr_status & GR_READY)))
55612+ return 1;
55613+
55614+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55615+ return 1;
55616+
55617+ /* ignore Eric Biederman */
55618+ if (IS_PRIVATE(dentry->d_inode))
55619+ return 1;
55620+
55621+ subj = task->acl;
55622+ read_lock(&gr_inode_lock);
55623+ do {
55624+ obj = lookup_acl_obj_label(ino, dev, subj);
55625+ if (obj != NULL) {
55626+ read_unlock(&gr_inode_lock);
55627+ return (obj->mode & GR_FIND) ? 1 : 0;
55628+ }
55629+ } while ((subj = subj->parent_subject));
55630+ read_unlock(&gr_inode_lock);
55631+
55632+ /* this is purely an optimization since we're looking for an object
55633+ for the directory we're doing a readdir on
55634+ if it's possible for any globbed object to match the entry we're
55635+ filling into the directory, then the object we find here will be
55636+ an anchor point with attached globbed objects
55637+ */
55638+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55639+ if (obj->globbed == NULL)
55640+ return (obj->mode & GR_FIND) ? 1 : 0;
55641+
55642+ is_not_root = ((obj->filename[0] == '/') &&
55643+ (obj->filename[1] == '\0')) ? 0 : 1;
55644+ bufsize = PAGE_SIZE - namelen - is_not_root;
55645+
55646+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
55647+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55648+ return 1;
55649+
55650+ preempt_disable();
55651+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55652+ bufsize);
55653+
55654+ bufsize = strlen(path);
55655+
55656+ /* if base is "/", don't append an additional slash */
55657+ if (is_not_root)
55658+ *(path + bufsize) = '/';
55659+ memcpy(path + bufsize + is_not_root, name, namelen);
55660+ *(path + bufsize + namelen + is_not_root) = '\0';
55661+
55662+ tmp = obj->globbed;
55663+ while (tmp) {
55664+ if (!glob_match(tmp->filename, path)) {
55665+ preempt_enable();
55666+ return (tmp->mode & GR_FIND) ? 1 : 0;
55667+ }
55668+ tmp = tmp->next;
55669+ }
55670+ preempt_enable();
55671+ return (obj->mode & GR_FIND) ? 1 : 0;
55672+}
55673+
55674+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55675+EXPORT_SYMBOL(gr_acl_is_enabled);
55676+#endif
55677+EXPORT_SYMBOL(gr_learn_resource);
55678+EXPORT_SYMBOL(gr_set_kernel_label);
55679+#ifdef CONFIG_SECURITY
55680+EXPORT_SYMBOL(gr_check_user_change);
55681+EXPORT_SYMBOL(gr_check_group_change);
55682+#endif
55683+
55684diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55685new file mode 100644
55686index 0000000..34fefda
55687--- /dev/null
55688+++ b/grsecurity/gracl_alloc.c
55689@@ -0,0 +1,105 @@
55690+#include <linux/kernel.h>
55691+#include <linux/mm.h>
55692+#include <linux/slab.h>
55693+#include <linux/vmalloc.h>
55694+#include <linux/gracl.h>
55695+#include <linux/grsecurity.h>
55696+
55697+static unsigned long alloc_stack_next = 1;
55698+static unsigned long alloc_stack_size = 1;
55699+static void **alloc_stack;
55700+
55701+static __inline__ int
55702+alloc_pop(void)
55703+{
55704+ if (alloc_stack_next == 1)
55705+ return 0;
55706+
55707+ kfree(alloc_stack[alloc_stack_next - 2]);
55708+
55709+ alloc_stack_next--;
55710+
55711+ return 1;
55712+}
55713+
55714+static __inline__ int
55715+alloc_push(void *buf)
55716+{
55717+ if (alloc_stack_next >= alloc_stack_size)
55718+ return 1;
55719+
55720+ alloc_stack[alloc_stack_next - 1] = buf;
55721+
55722+ alloc_stack_next++;
55723+
55724+ return 0;
55725+}
55726+
55727+void *
55728+acl_alloc(unsigned long len)
55729+{
55730+ void *ret = NULL;
55731+
55732+ if (!len || len > PAGE_SIZE)
55733+ goto out;
55734+
55735+ ret = kmalloc(len, GFP_KERNEL);
55736+
55737+ if (ret) {
55738+ if (alloc_push(ret)) {
55739+ kfree(ret);
55740+ ret = NULL;
55741+ }
55742+ }
55743+
55744+out:
55745+ return ret;
55746+}
55747+
55748+void *
55749+acl_alloc_num(unsigned long num, unsigned long len)
55750+{
55751+ if (!len || (num > (PAGE_SIZE / len)))
55752+ return NULL;
55753+
55754+ return acl_alloc(num * len);
55755+}
55756+
55757+void
55758+acl_free_all(void)
55759+{
55760+ if (gr_acl_is_enabled() || !alloc_stack)
55761+ return;
55762+
55763+ while (alloc_pop()) ;
55764+
55765+ if (alloc_stack) {
55766+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55767+ kfree(alloc_stack);
55768+ else
55769+ vfree(alloc_stack);
55770+ }
55771+
55772+ alloc_stack = NULL;
55773+ alloc_stack_size = 1;
55774+ alloc_stack_next = 1;
55775+
55776+ return;
55777+}
55778+
55779+int
55780+acl_alloc_stack_init(unsigned long size)
55781+{
55782+ if ((size * sizeof (void *)) <= PAGE_SIZE)
55783+ alloc_stack =
55784+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55785+ else
55786+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
55787+
55788+ alloc_stack_size = size;
55789+
55790+ if (!alloc_stack)
55791+ return 0;
55792+ else
55793+ return 1;
55794+}
55795diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55796new file mode 100644
55797index 0000000..6d21049
55798--- /dev/null
55799+++ b/grsecurity/gracl_cap.c
55800@@ -0,0 +1,110 @@
55801+#include <linux/kernel.h>
55802+#include <linux/module.h>
55803+#include <linux/sched.h>
55804+#include <linux/gracl.h>
55805+#include <linux/grsecurity.h>
55806+#include <linux/grinternal.h>
55807+
55808+extern const char *captab_log[];
55809+extern int captab_log_entries;
55810+
55811+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55812+{
55813+ struct acl_subject_label *curracl;
55814+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55815+ kernel_cap_t cap_audit = __cap_empty_set;
55816+
55817+ if (!gr_acl_is_enabled())
55818+ return 1;
55819+
55820+ curracl = task->acl;
55821+
55822+ cap_drop = curracl->cap_lower;
55823+ cap_mask = curracl->cap_mask;
55824+ cap_audit = curracl->cap_invert_audit;
55825+
55826+ while ((curracl = curracl->parent_subject)) {
55827+ /* if the cap isn't specified in the current computed mask but is specified in the
55828+ current level subject, and is lowered in the current level subject, then add
55829+ it to the set of dropped capabilities
55830+ otherwise, add the current level subject's mask to the current computed mask
55831+ */
55832+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55833+ cap_raise(cap_mask, cap);
55834+ if (cap_raised(curracl->cap_lower, cap))
55835+ cap_raise(cap_drop, cap);
55836+ if (cap_raised(curracl->cap_invert_audit, cap))
55837+ cap_raise(cap_audit, cap);
55838+ }
55839+ }
55840+
55841+ if (!cap_raised(cap_drop, cap)) {
55842+ if (cap_raised(cap_audit, cap))
55843+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55844+ return 1;
55845+ }
55846+
55847+ curracl = task->acl;
55848+
55849+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55850+ && cap_raised(cred->cap_effective, cap)) {
55851+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55852+ task->role->roletype, cred->uid,
55853+ cred->gid, task->exec_file ?
55854+ gr_to_filename(task->exec_file->f_path.dentry,
55855+ task->exec_file->f_path.mnt) : curracl->filename,
55856+ curracl->filename, 0UL,
55857+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55858+ return 1;
55859+ }
55860+
55861+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55862+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55863+
55864+ return 0;
55865+}
55866+
55867+int
55868+gr_acl_is_capable(const int cap)
55869+{
55870+ return gr_task_acl_is_capable(current, current_cred(), cap);
55871+}
55872+
55873+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55874+{
55875+ struct acl_subject_label *curracl;
55876+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55877+
55878+ if (!gr_acl_is_enabled())
55879+ return 1;
55880+
55881+ curracl = task->acl;
55882+
55883+ cap_drop = curracl->cap_lower;
55884+ cap_mask = curracl->cap_mask;
55885+
55886+ while ((curracl = curracl->parent_subject)) {
55887+ /* if the cap isn't specified in the current computed mask but is specified in the
55888+ current level subject, and is lowered in the current level subject, then add
55889+ it to the set of dropped capabilities
55890+ otherwise, add the current level subject's mask to the current computed mask
55891+ */
55892+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55893+ cap_raise(cap_mask, cap);
55894+ if (cap_raised(curracl->cap_lower, cap))
55895+ cap_raise(cap_drop, cap);
55896+ }
55897+ }
55898+
55899+ if (!cap_raised(cap_drop, cap))
55900+ return 1;
55901+
55902+ return 0;
55903+}
55904+
55905+int
55906+gr_acl_is_capable_nolog(const int cap)
55907+{
55908+ return gr_task_acl_is_capable_nolog(current, cap);
55909+}
55910+
55911diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55912new file mode 100644
55913index 0000000..d28e241
55914--- /dev/null
55915+++ b/grsecurity/gracl_fs.c
55916@@ -0,0 +1,437 @@
55917+#include <linux/kernel.h>
55918+#include <linux/sched.h>
55919+#include <linux/types.h>
55920+#include <linux/fs.h>
55921+#include <linux/file.h>
55922+#include <linux/stat.h>
55923+#include <linux/grsecurity.h>
55924+#include <linux/grinternal.h>
55925+#include <linux/gracl.h>
55926+
55927+umode_t
55928+gr_acl_umask(void)
55929+{
55930+ if (unlikely(!gr_acl_is_enabled()))
55931+ return 0;
55932+
55933+ return current->role->umask;
55934+}
55935+
55936+__u32
55937+gr_acl_handle_hidden_file(const struct dentry * dentry,
55938+ const struct vfsmount * mnt)
55939+{
55940+ __u32 mode;
55941+
55942+ if (unlikely(!dentry->d_inode))
55943+ return GR_FIND;
55944+
55945+ mode =
55946+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55947+
55948+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55949+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55950+ return mode;
55951+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55952+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55953+ return 0;
55954+ } else if (unlikely(!(mode & GR_FIND)))
55955+ return 0;
55956+
55957+ return GR_FIND;
55958+}
55959+
55960+__u32
55961+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55962+ int acc_mode)
55963+{
55964+ __u32 reqmode = GR_FIND;
55965+ __u32 mode;
55966+
55967+ if (unlikely(!dentry->d_inode))
55968+ return reqmode;
55969+
55970+ if (acc_mode & MAY_APPEND)
55971+ reqmode |= GR_APPEND;
55972+ else if (acc_mode & MAY_WRITE)
55973+ reqmode |= GR_WRITE;
55974+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55975+ reqmode |= GR_READ;
55976+
55977+ mode =
55978+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55979+ mnt);
55980+
55981+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55982+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55983+ reqmode & GR_READ ? " reading" : "",
55984+ reqmode & GR_WRITE ? " writing" : reqmode &
55985+ GR_APPEND ? " appending" : "");
55986+ return reqmode;
55987+ } else
55988+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55989+ {
55990+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55991+ reqmode & GR_READ ? " reading" : "",
55992+ reqmode & GR_WRITE ? " writing" : reqmode &
55993+ GR_APPEND ? " appending" : "");
55994+ return 0;
55995+ } else if (unlikely((mode & reqmode) != reqmode))
55996+ return 0;
55997+
55998+ return reqmode;
55999+}
56000+
56001+__u32
56002+gr_acl_handle_creat(const struct dentry * dentry,
56003+ const struct dentry * p_dentry,
56004+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56005+ const int imode)
56006+{
56007+ __u32 reqmode = GR_WRITE | GR_CREATE;
56008+ __u32 mode;
56009+
56010+ if (acc_mode & MAY_APPEND)
56011+ reqmode |= GR_APPEND;
56012+ // if a directory was required or the directory already exists, then
56013+ // don't count this open as a read
56014+ if ((acc_mode & MAY_READ) &&
56015+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56016+ reqmode |= GR_READ;
56017+ if ((open_flags & O_CREAT) &&
56018+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56019+ reqmode |= GR_SETID;
56020+
56021+ mode =
56022+ gr_check_create(dentry, p_dentry, p_mnt,
56023+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56024+
56025+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56026+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56027+ reqmode & GR_READ ? " reading" : "",
56028+ reqmode & GR_WRITE ? " writing" : reqmode &
56029+ GR_APPEND ? " appending" : "");
56030+ return reqmode;
56031+ } else
56032+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56033+ {
56034+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56035+ reqmode & GR_READ ? " reading" : "",
56036+ reqmode & GR_WRITE ? " writing" : reqmode &
56037+ GR_APPEND ? " appending" : "");
56038+ return 0;
56039+ } else if (unlikely((mode & reqmode) != reqmode))
56040+ return 0;
56041+
56042+ return reqmode;
56043+}
56044+
56045+__u32
56046+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56047+ const int fmode)
56048+{
56049+ __u32 mode, reqmode = GR_FIND;
56050+
56051+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56052+ reqmode |= GR_EXEC;
56053+ if (fmode & S_IWOTH)
56054+ reqmode |= GR_WRITE;
56055+ if (fmode & S_IROTH)
56056+ reqmode |= GR_READ;
56057+
56058+ mode =
56059+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56060+ mnt);
56061+
56062+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56063+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56064+ reqmode & GR_READ ? " reading" : "",
56065+ reqmode & GR_WRITE ? " writing" : "",
56066+ reqmode & GR_EXEC ? " executing" : "");
56067+ return reqmode;
56068+ } else
56069+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56070+ {
56071+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56072+ reqmode & GR_READ ? " reading" : "",
56073+ reqmode & GR_WRITE ? " writing" : "",
56074+ reqmode & GR_EXEC ? " executing" : "");
56075+ return 0;
56076+ } else if (unlikely((mode & reqmode) != reqmode))
56077+ return 0;
56078+
56079+ return reqmode;
56080+}
56081+
56082+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56083+{
56084+ __u32 mode;
56085+
56086+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56087+
56088+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56089+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56090+ return mode;
56091+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56092+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56093+ return 0;
56094+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
56095+ return 0;
56096+
56097+ return (reqmode);
56098+}
56099+
56100+__u32
56101+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56102+{
56103+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56104+}
56105+
56106+__u32
56107+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56108+{
56109+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56110+}
56111+
56112+__u32
56113+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56114+{
56115+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56116+}
56117+
56118+__u32
56119+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56120+{
56121+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56122+}
56123+
56124+__u32
56125+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56126+ umode_t *modeptr)
56127+{
56128+ umode_t mode;
56129+
56130+ *modeptr &= ~gr_acl_umask();
56131+ mode = *modeptr;
56132+
56133+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56134+ return 1;
56135+
56136+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56137+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56138+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56139+ GR_CHMOD_ACL_MSG);
56140+ } else {
56141+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56142+ }
56143+}
56144+
56145+__u32
56146+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56147+{
56148+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56149+}
56150+
56151+__u32
56152+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56153+{
56154+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56155+}
56156+
56157+__u32
56158+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56159+{
56160+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56161+}
56162+
56163+__u32
56164+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56165+{
56166+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56167+ GR_UNIXCONNECT_ACL_MSG);
56168+}
56169+
56170+/* hardlinks require at minimum create and link permission,
56171+ any additional privilege required is based on the
56172+ privilege of the file being linked to
56173+*/
56174+__u32
56175+gr_acl_handle_link(const struct dentry * new_dentry,
56176+ const struct dentry * parent_dentry,
56177+ const struct vfsmount * parent_mnt,
56178+ const struct dentry * old_dentry,
56179+ const struct vfsmount * old_mnt, const char *to)
56180+{
56181+ __u32 mode;
56182+ __u32 needmode = GR_CREATE | GR_LINK;
56183+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56184+
56185+ mode =
56186+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56187+ old_mnt);
56188+
56189+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56190+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56191+ return mode;
56192+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56193+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56194+ return 0;
56195+ } else if (unlikely((mode & needmode) != needmode))
56196+ return 0;
56197+
56198+ return 1;
56199+}
56200+
56201+__u32
56202+gr_acl_handle_symlink(const struct dentry * new_dentry,
56203+ const struct dentry * parent_dentry,
56204+ const struct vfsmount * parent_mnt, const char *from)
56205+{
56206+ __u32 needmode = GR_WRITE | GR_CREATE;
56207+ __u32 mode;
56208+
56209+ mode =
56210+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
56211+ GR_CREATE | GR_AUDIT_CREATE |
56212+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56213+
56214+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56215+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56216+ return mode;
56217+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56218+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56219+ return 0;
56220+ } else if (unlikely((mode & needmode) != needmode))
56221+ return 0;
56222+
56223+ return (GR_WRITE | GR_CREATE);
56224+}
56225+
56226+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)
56227+{
56228+ __u32 mode;
56229+
56230+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56231+
56232+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56233+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56234+ return mode;
56235+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56236+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56237+ return 0;
56238+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
56239+ return 0;
56240+
56241+ return (reqmode);
56242+}
56243+
56244+__u32
56245+gr_acl_handle_mknod(const struct dentry * new_dentry,
56246+ const struct dentry * parent_dentry,
56247+ const struct vfsmount * parent_mnt,
56248+ const int mode)
56249+{
56250+ __u32 reqmode = GR_WRITE | GR_CREATE;
56251+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56252+ reqmode |= GR_SETID;
56253+
56254+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56255+ reqmode, GR_MKNOD_ACL_MSG);
56256+}
56257+
56258+__u32
56259+gr_acl_handle_mkdir(const struct dentry *new_dentry,
56260+ const struct dentry *parent_dentry,
56261+ const struct vfsmount *parent_mnt)
56262+{
56263+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56264+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56265+}
56266+
56267+#define RENAME_CHECK_SUCCESS(old, new) \
56268+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56269+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56270+
56271+int
56272+gr_acl_handle_rename(struct dentry *new_dentry,
56273+ struct dentry *parent_dentry,
56274+ const struct vfsmount *parent_mnt,
56275+ struct dentry *old_dentry,
56276+ struct inode *old_parent_inode,
56277+ struct vfsmount *old_mnt, const char *newname)
56278+{
56279+ __u32 comp1, comp2;
56280+ int error = 0;
56281+
56282+ if (unlikely(!gr_acl_is_enabled()))
56283+ return 0;
56284+
56285+ if (!new_dentry->d_inode) {
56286+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56287+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56288+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56289+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56290+ GR_DELETE | GR_AUDIT_DELETE |
56291+ GR_AUDIT_READ | GR_AUDIT_WRITE |
56292+ GR_SUPPRESS, old_mnt);
56293+ } else {
56294+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56295+ GR_CREATE | GR_DELETE |
56296+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56297+ GR_AUDIT_READ | GR_AUDIT_WRITE |
56298+ GR_SUPPRESS, parent_mnt);
56299+ comp2 =
56300+ gr_search_file(old_dentry,
56301+ GR_READ | GR_WRITE | GR_AUDIT_READ |
56302+ GR_DELETE | GR_AUDIT_DELETE |
56303+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56304+ }
56305+
56306+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56307+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56308+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56309+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56310+ && !(comp2 & GR_SUPPRESS)) {
56311+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56312+ error = -EACCES;
56313+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56314+ error = -EACCES;
56315+
56316+ return error;
56317+}
56318+
56319+void
56320+gr_acl_handle_exit(void)
56321+{
56322+ u16 id;
56323+ char *rolename;
56324+ struct file *exec_file;
56325+
56326+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56327+ !(current->role->roletype & GR_ROLE_PERSIST))) {
56328+ id = current->acl_role_id;
56329+ rolename = current->role->rolename;
56330+ gr_set_acls(1);
56331+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56332+ }
56333+
56334+ write_lock(&grsec_exec_file_lock);
56335+ exec_file = current->exec_file;
56336+ current->exec_file = NULL;
56337+ write_unlock(&grsec_exec_file_lock);
56338+
56339+ if (exec_file)
56340+ fput(exec_file);
56341+}
56342+
56343+int
56344+gr_acl_handle_procpidmem(const struct task_struct *task)
56345+{
56346+ if (unlikely(!gr_acl_is_enabled()))
56347+ return 0;
56348+
56349+ if (task != current && task->acl->mode & GR_PROTPROCFD)
56350+ return -EACCES;
56351+
56352+ return 0;
56353+}
56354diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56355new file mode 100644
56356index 0000000..58800a7
56357--- /dev/null
56358+++ b/grsecurity/gracl_ip.c
56359@@ -0,0 +1,384 @@
56360+#include <linux/kernel.h>
56361+#include <asm/uaccess.h>
56362+#include <asm/errno.h>
56363+#include <net/sock.h>
56364+#include <linux/file.h>
56365+#include <linux/fs.h>
56366+#include <linux/net.h>
56367+#include <linux/in.h>
56368+#include <linux/skbuff.h>
56369+#include <linux/ip.h>
56370+#include <linux/udp.h>
56371+#include <linux/types.h>
56372+#include <linux/sched.h>
56373+#include <linux/netdevice.h>
56374+#include <linux/inetdevice.h>
56375+#include <linux/gracl.h>
56376+#include <linux/grsecurity.h>
56377+#include <linux/grinternal.h>
56378+
56379+#define GR_BIND 0x01
56380+#define GR_CONNECT 0x02
56381+#define GR_INVERT 0x04
56382+#define GR_BINDOVERRIDE 0x08
56383+#define GR_CONNECTOVERRIDE 0x10
56384+#define GR_SOCK_FAMILY 0x20
56385+
56386+static const char * gr_protocols[IPPROTO_MAX] = {
56387+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56388+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56389+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56390+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56391+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56392+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56393+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56394+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56395+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56396+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56397+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56398+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56399+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56400+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56401+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56402+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56403+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56404+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56405+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56406+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56407+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56408+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56409+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56410+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56411+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56412+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56413+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56414+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56415+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56416+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56417+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56418+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56419+ };
56420+
56421+static const char * gr_socktypes[SOCK_MAX] = {
56422+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56423+ "unknown:7", "unknown:8", "unknown:9", "packet"
56424+ };
56425+
56426+static const char * gr_sockfamilies[AF_MAX+1] = {
56427+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56428+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56429+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56430+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56431+ };
56432+
56433+const char *
56434+gr_proto_to_name(unsigned char proto)
56435+{
56436+ return gr_protocols[proto];
56437+}
56438+
56439+const char *
56440+gr_socktype_to_name(unsigned char type)
56441+{
56442+ return gr_socktypes[type];
56443+}
56444+
56445+const char *
56446+gr_sockfamily_to_name(unsigned char family)
56447+{
56448+ return gr_sockfamilies[family];
56449+}
56450+
56451+int
56452+gr_search_socket(const int domain, const int type, const int protocol)
56453+{
56454+ struct acl_subject_label *curr;
56455+ const struct cred *cred = current_cred();
56456+
56457+ if (unlikely(!gr_acl_is_enabled()))
56458+ goto exit;
56459+
56460+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
56461+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56462+ goto exit; // let the kernel handle it
56463+
56464+ curr = current->acl;
56465+
56466+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56467+ /* the family is allowed, if this is PF_INET allow it only if
56468+ the extra sock type/protocol checks pass */
56469+ if (domain == PF_INET)
56470+ goto inet_check;
56471+ goto exit;
56472+ } else {
56473+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56474+ __u32 fakeip = 0;
56475+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56476+ current->role->roletype, cred->uid,
56477+ cred->gid, current->exec_file ?
56478+ gr_to_filename(current->exec_file->f_path.dentry,
56479+ current->exec_file->f_path.mnt) :
56480+ curr->filename, curr->filename,
56481+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56482+ &current->signal->saved_ip);
56483+ goto exit;
56484+ }
56485+ goto exit_fail;
56486+ }
56487+
56488+inet_check:
56489+ /* the rest of this checking is for IPv4 only */
56490+ if (!curr->ips)
56491+ goto exit;
56492+
56493+ if ((curr->ip_type & (1 << type)) &&
56494+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56495+ goto exit;
56496+
56497+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56498+ /* we don't place acls on raw sockets , and sometimes
56499+ dgram/ip sockets are opened for ioctl and not
56500+ bind/connect, so we'll fake a bind learn log */
56501+ if (type == SOCK_RAW || type == SOCK_PACKET) {
56502+ __u32 fakeip = 0;
56503+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56504+ current->role->roletype, cred->uid,
56505+ cred->gid, current->exec_file ?
56506+ gr_to_filename(current->exec_file->f_path.dentry,
56507+ current->exec_file->f_path.mnt) :
56508+ curr->filename, curr->filename,
56509+ &fakeip, 0, type,
56510+ protocol, GR_CONNECT, &current->signal->saved_ip);
56511+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56512+ __u32 fakeip = 0;
56513+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56514+ current->role->roletype, cred->uid,
56515+ cred->gid, current->exec_file ?
56516+ gr_to_filename(current->exec_file->f_path.dentry,
56517+ current->exec_file->f_path.mnt) :
56518+ curr->filename, curr->filename,
56519+ &fakeip, 0, type,
56520+ protocol, GR_BIND, &current->signal->saved_ip);
56521+ }
56522+ /* we'll log when they use connect or bind */
56523+ goto exit;
56524+ }
56525+
56526+exit_fail:
56527+ if (domain == PF_INET)
56528+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56529+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
56530+ else
56531+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56532+ gr_socktype_to_name(type), protocol);
56533+
56534+ return 0;
56535+exit:
56536+ return 1;
56537+}
56538+
56539+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)
56540+{
56541+ if ((ip->mode & mode) &&
56542+ (ip_port >= ip->low) &&
56543+ (ip_port <= ip->high) &&
56544+ ((ntohl(ip_addr) & our_netmask) ==
56545+ (ntohl(our_addr) & our_netmask))
56546+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56547+ && (ip->type & (1 << type))) {
56548+ if (ip->mode & GR_INVERT)
56549+ return 2; // specifically denied
56550+ else
56551+ return 1; // allowed
56552+ }
56553+
56554+ return 0; // not specifically allowed, may continue parsing
56555+}
56556+
56557+static int
56558+gr_search_connectbind(const int full_mode, struct sock *sk,
56559+ struct sockaddr_in *addr, const int type)
56560+{
56561+ char iface[IFNAMSIZ] = {0};
56562+ struct acl_subject_label *curr;
56563+ struct acl_ip_label *ip;
56564+ struct inet_sock *isk;
56565+ struct net_device *dev;
56566+ struct in_device *idev;
56567+ unsigned long i;
56568+ int ret;
56569+ int mode = full_mode & (GR_BIND | GR_CONNECT);
56570+ __u32 ip_addr = 0;
56571+ __u32 our_addr;
56572+ __u32 our_netmask;
56573+ char *p;
56574+ __u16 ip_port = 0;
56575+ const struct cred *cred = current_cred();
56576+
56577+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56578+ return 0;
56579+
56580+ curr = current->acl;
56581+ isk = inet_sk(sk);
56582+
56583+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56584+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56585+ addr->sin_addr.s_addr = curr->inaddr_any_override;
56586+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56587+ struct sockaddr_in saddr;
56588+ int err;
56589+
56590+ saddr.sin_family = AF_INET;
56591+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
56592+ saddr.sin_port = isk->inet_sport;
56593+
56594+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56595+ if (err)
56596+ return err;
56597+
56598+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56599+ if (err)
56600+ return err;
56601+ }
56602+
56603+ if (!curr->ips)
56604+ return 0;
56605+
56606+ ip_addr = addr->sin_addr.s_addr;
56607+ ip_port = ntohs(addr->sin_port);
56608+
56609+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56610+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56611+ current->role->roletype, cred->uid,
56612+ cred->gid, current->exec_file ?
56613+ gr_to_filename(current->exec_file->f_path.dentry,
56614+ current->exec_file->f_path.mnt) :
56615+ curr->filename, curr->filename,
56616+ &ip_addr, ip_port, type,
56617+ sk->sk_protocol, mode, &current->signal->saved_ip);
56618+ return 0;
56619+ }
56620+
56621+ for (i = 0; i < curr->ip_num; i++) {
56622+ ip = *(curr->ips + i);
56623+ if (ip->iface != NULL) {
56624+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
56625+ p = strchr(iface, ':');
56626+ if (p != NULL)
56627+ *p = '\0';
56628+ dev = dev_get_by_name(sock_net(sk), iface);
56629+ if (dev == NULL)
56630+ continue;
56631+ idev = in_dev_get(dev);
56632+ if (idev == NULL) {
56633+ dev_put(dev);
56634+ continue;
56635+ }
56636+ rcu_read_lock();
56637+ for_ifa(idev) {
56638+ if (!strcmp(ip->iface, ifa->ifa_label)) {
56639+ our_addr = ifa->ifa_address;
56640+ our_netmask = 0xffffffff;
56641+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56642+ if (ret == 1) {
56643+ rcu_read_unlock();
56644+ in_dev_put(idev);
56645+ dev_put(dev);
56646+ return 0;
56647+ } else if (ret == 2) {
56648+ rcu_read_unlock();
56649+ in_dev_put(idev);
56650+ dev_put(dev);
56651+ goto denied;
56652+ }
56653+ }
56654+ } endfor_ifa(idev);
56655+ rcu_read_unlock();
56656+ in_dev_put(idev);
56657+ dev_put(dev);
56658+ } else {
56659+ our_addr = ip->addr;
56660+ our_netmask = ip->netmask;
56661+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56662+ if (ret == 1)
56663+ return 0;
56664+ else if (ret == 2)
56665+ goto denied;
56666+ }
56667+ }
56668+
56669+denied:
56670+ if (mode == GR_BIND)
56671+ 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));
56672+ else if (mode == GR_CONNECT)
56673+ 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));
56674+
56675+ return -EACCES;
56676+}
56677+
56678+int
56679+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56680+{
56681+ /* always allow disconnection of dgram sockets with connect */
56682+ if (addr->sin_family == AF_UNSPEC)
56683+ return 0;
56684+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56685+}
56686+
56687+int
56688+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56689+{
56690+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56691+}
56692+
56693+int gr_search_listen(struct socket *sock)
56694+{
56695+ struct sock *sk = sock->sk;
56696+ struct sockaddr_in addr;
56697+
56698+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56699+ addr.sin_port = inet_sk(sk)->inet_sport;
56700+
56701+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56702+}
56703+
56704+int gr_search_accept(struct socket *sock)
56705+{
56706+ struct sock *sk = sock->sk;
56707+ struct sockaddr_in addr;
56708+
56709+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56710+ addr.sin_port = inet_sk(sk)->inet_sport;
56711+
56712+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56713+}
56714+
56715+int
56716+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56717+{
56718+ if (addr)
56719+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56720+ else {
56721+ struct sockaddr_in sin;
56722+ const struct inet_sock *inet = inet_sk(sk);
56723+
56724+ sin.sin_addr.s_addr = inet->inet_daddr;
56725+ sin.sin_port = inet->inet_dport;
56726+
56727+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56728+ }
56729+}
56730+
56731+int
56732+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56733+{
56734+ struct sockaddr_in sin;
56735+
56736+ if (unlikely(skb->len < sizeof (struct udphdr)))
56737+ return 0; // skip this packet
56738+
56739+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56740+ sin.sin_port = udp_hdr(skb)->source;
56741+
56742+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56743+}
56744diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56745new file mode 100644
56746index 0000000..25f54ef
56747--- /dev/null
56748+++ b/grsecurity/gracl_learn.c
56749@@ -0,0 +1,207 @@
56750+#include <linux/kernel.h>
56751+#include <linux/mm.h>
56752+#include <linux/sched.h>
56753+#include <linux/poll.h>
56754+#include <linux/string.h>
56755+#include <linux/file.h>
56756+#include <linux/types.h>
56757+#include <linux/vmalloc.h>
56758+#include <linux/grinternal.h>
56759+
56760+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56761+ size_t count, loff_t *ppos);
56762+extern int gr_acl_is_enabled(void);
56763+
56764+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56765+static int gr_learn_attached;
56766+
56767+/* use a 512k buffer */
56768+#define LEARN_BUFFER_SIZE (512 * 1024)
56769+
56770+static DEFINE_SPINLOCK(gr_learn_lock);
56771+static DEFINE_MUTEX(gr_learn_user_mutex);
56772+
56773+/* we need to maintain two buffers, so that the kernel context of grlearn
56774+ uses a semaphore around the userspace copying, and the other kernel contexts
56775+ use a spinlock when copying into the buffer, since they cannot sleep
56776+*/
56777+static char *learn_buffer;
56778+static char *learn_buffer_user;
56779+static int learn_buffer_len;
56780+static int learn_buffer_user_len;
56781+
56782+static ssize_t
56783+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56784+{
56785+ DECLARE_WAITQUEUE(wait, current);
56786+ ssize_t retval = 0;
56787+
56788+ add_wait_queue(&learn_wait, &wait);
56789+ set_current_state(TASK_INTERRUPTIBLE);
56790+ do {
56791+ mutex_lock(&gr_learn_user_mutex);
56792+ spin_lock(&gr_learn_lock);
56793+ if (learn_buffer_len)
56794+ break;
56795+ spin_unlock(&gr_learn_lock);
56796+ mutex_unlock(&gr_learn_user_mutex);
56797+ if (file->f_flags & O_NONBLOCK) {
56798+ retval = -EAGAIN;
56799+ goto out;
56800+ }
56801+ if (signal_pending(current)) {
56802+ retval = -ERESTARTSYS;
56803+ goto out;
56804+ }
56805+
56806+ schedule();
56807+ } while (1);
56808+
56809+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56810+ learn_buffer_user_len = learn_buffer_len;
56811+ retval = learn_buffer_len;
56812+ learn_buffer_len = 0;
56813+
56814+ spin_unlock(&gr_learn_lock);
56815+
56816+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56817+ retval = -EFAULT;
56818+
56819+ mutex_unlock(&gr_learn_user_mutex);
56820+out:
56821+ set_current_state(TASK_RUNNING);
56822+ remove_wait_queue(&learn_wait, &wait);
56823+ return retval;
56824+}
56825+
56826+static unsigned int
56827+poll_learn(struct file * file, poll_table * wait)
56828+{
56829+ poll_wait(file, &learn_wait, wait);
56830+
56831+ if (learn_buffer_len)
56832+ return (POLLIN | POLLRDNORM);
56833+
56834+ return 0;
56835+}
56836+
56837+void
56838+gr_clear_learn_entries(void)
56839+{
56840+ char *tmp;
56841+
56842+ mutex_lock(&gr_learn_user_mutex);
56843+ spin_lock(&gr_learn_lock);
56844+ tmp = learn_buffer;
56845+ learn_buffer = NULL;
56846+ spin_unlock(&gr_learn_lock);
56847+ if (tmp)
56848+ vfree(tmp);
56849+ if (learn_buffer_user != NULL) {
56850+ vfree(learn_buffer_user);
56851+ learn_buffer_user = NULL;
56852+ }
56853+ learn_buffer_len = 0;
56854+ mutex_unlock(&gr_learn_user_mutex);
56855+
56856+ return;
56857+}
56858+
56859+void
56860+gr_add_learn_entry(const char *fmt, ...)
56861+{
56862+ va_list args;
56863+ unsigned int len;
56864+
56865+ if (!gr_learn_attached)
56866+ return;
56867+
56868+ spin_lock(&gr_learn_lock);
56869+
56870+ /* leave a gap at the end so we know when it's "full" but don't have to
56871+ compute the exact length of the string we're trying to append
56872+ */
56873+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56874+ spin_unlock(&gr_learn_lock);
56875+ wake_up_interruptible(&learn_wait);
56876+ return;
56877+ }
56878+ if (learn_buffer == NULL) {
56879+ spin_unlock(&gr_learn_lock);
56880+ return;
56881+ }
56882+
56883+ va_start(args, fmt);
56884+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56885+ va_end(args);
56886+
56887+ learn_buffer_len += len + 1;
56888+
56889+ spin_unlock(&gr_learn_lock);
56890+ wake_up_interruptible(&learn_wait);
56891+
56892+ return;
56893+}
56894+
56895+static int
56896+open_learn(struct inode *inode, struct file *file)
56897+{
56898+ if (file->f_mode & FMODE_READ && gr_learn_attached)
56899+ return -EBUSY;
56900+ if (file->f_mode & FMODE_READ) {
56901+ int retval = 0;
56902+ mutex_lock(&gr_learn_user_mutex);
56903+ if (learn_buffer == NULL)
56904+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56905+ if (learn_buffer_user == NULL)
56906+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56907+ if (learn_buffer == NULL) {
56908+ retval = -ENOMEM;
56909+ goto out_error;
56910+ }
56911+ if (learn_buffer_user == NULL) {
56912+ retval = -ENOMEM;
56913+ goto out_error;
56914+ }
56915+ learn_buffer_len = 0;
56916+ learn_buffer_user_len = 0;
56917+ gr_learn_attached = 1;
56918+out_error:
56919+ mutex_unlock(&gr_learn_user_mutex);
56920+ return retval;
56921+ }
56922+ return 0;
56923+}
56924+
56925+static int
56926+close_learn(struct inode *inode, struct file *file)
56927+{
56928+ if (file->f_mode & FMODE_READ) {
56929+ char *tmp = NULL;
56930+ mutex_lock(&gr_learn_user_mutex);
56931+ spin_lock(&gr_learn_lock);
56932+ tmp = learn_buffer;
56933+ learn_buffer = NULL;
56934+ spin_unlock(&gr_learn_lock);
56935+ if (tmp)
56936+ vfree(tmp);
56937+ if (learn_buffer_user != NULL) {
56938+ vfree(learn_buffer_user);
56939+ learn_buffer_user = NULL;
56940+ }
56941+ learn_buffer_len = 0;
56942+ learn_buffer_user_len = 0;
56943+ gr_learn_attached = 0;
56944+ mutex_unlock(&gr_learn_user_mutex);
56945+ }
56946+
56947+ return 0;
56948+}
56949+
56950+const struct file_operations grsec_fops = {
56951+ .read = read_learn,
56952+ .write = write_grsec_handler,
56953+ .open = open_learn,
56954+ .release = close_learn,
56955+ .poll = poll_learn,
56956+};
56957diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56958new file mode 100644
56959index 0000000..39645c9
56960--- /dev/null
56961+++ b/grsecurity/gracl_res.c
56962@@ -0,0 +1,68 @@
56963+#include <linux/kernel.h>
56964+#include <linux/sched.h>
56965+#include <linux/gracl.h>
56966+#include <linux/grinternal.h>
56967+
56968+static const char *restab_log[] = {
56969+ [RLIMIT_CPU] = "RLIMIT_CPU",
56970+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56971+ [RLIMIT_DATA] = "RLIMIT_DATA",
56972+ [RLIMIT_STACK] = "RLIMIT_STACK",
56973+ [RLIMIT_CORE] = "RLIMIT_CORE",
56974+ [RLIMIT_RSS] = "RLIMIT_RSS",
56975+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
56976+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56977+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56978+ [RLIMIT_AS] = "RLIMIT_AS",
56979+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56980+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56981+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56982+ [RLIMIT_NICE] = "RLIMIT_NICE",
56983+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56984+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56985+ [GR_CRASH_RES] = "RLIMIT_CRASH"
56986+};
56987+
56988+void
56989+gr_log_resource(const struct task_struct *task,
56990+ const int res, const unsigned long wanted, const int gt)
56991+{
56992+ const struct cred *cred;
56993+ unsigned long rlim;
56994+
56995+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
56996+ return;
56997+
56998+ // not yet supported resource
56999+ if (unlikely(!restab_log[res]))
57000+ return;
57001+
57002+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57003+ rlim = task_rlimit_max(task, res);
57004+ else
57005+ rlim = task_rlimit(task, res);
57006+
57007+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57008+ return;
57009+
57010+ rcu_read_lock();
57011+ cred = __task_cred(task);
57012+
57013+ if (res == RLIMIT_NPROC &&
57014+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57015+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57016+ goto out_rcu_unlock;
57017+ else if (res == RLIMIT_MEMLOCK &&
57018+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57019+ goto out_rcu_unlock;
57020+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57021+ goto out_rcu_unlock;
57022+ rcu_read_unlock();
57023+
57024+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57025+
57026+ return;
57027+out_rcu_unlock:
57028+ rcu_read_unlock();
57029+ return;
57030+}
57031diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57032new file mode 100644
57033index 0000000..25197e9
57034--- /dev/null
57035+++ b/grsecurity/gracl_segv.c
57036@@ -0,0 +1,299 @@
57037+#include <linux/kernel.h>
57038+#include <linux/mm.h>
57039+#include <asm/uaccess.h>
57040+#include <asm/errno.h>
57041+#include <asm/mman.h>
57042+#include <net/sock.h>
57043+#include <linux/file.h>
57044+#include <linux/fs.h>
57045+#include <linux/net.h>
57046+#include <linux/in.h>
57047+#include <linux/slab.h>
57048+#include <linux/types.h>
57049+#include <linux/sched.h>
57050+#include <linux/timer.h>
57051+#include <linux/gracl.h>
57052+#include <linux/grsecurity.h>
57053+#include <linux/grinternal.h>
57054+
57055+static struct crash_uid *uid_set;
57056+static unsigned short uid_used;
57057+static DEFINE_SPINLOCK(gr_uid_lock);
57058+extern rwlock_t gr_inode_lock;
57059+extern struct acl_subject_label *
57060+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57061+ struct acl_role_label *role);
57062+
57063+#ifdef CONFIG_BTRFS_FS
57064+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57065+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57066+#endif
57067+
57068+static inline dev_t __get_dev(const struct dentry *dentry)
57069+{
57070+#ifdef CONFIG_BTRFS_FS
57071+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57072+ return get_btrfs_dev_from_inode(dentry->d_inode);
57073+ else
57074+#endif
57075+ return dentry->d_inode->i_sb->s_dev;
57076+}
57077+
57078+int
57079+gr_init_uidset(void)
57080+{
57081+ uid_set =
57082+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57083+ uid_used = 0;
57084+
57085+ return uid_set ? 1 : 0;
57086+}
57087+
57088+void
57089+gr_free_uidset(void)
57090+{
57091+ if (uid_set)
57092+ kfree(uid_set);
57093+
57094+ return;
57095+}
57096+
57097+int
57098+gr_find_uid(const uid_t uid)
57099+{
57100+ struct crash_uid *tmp = uid_set;
57101+ uid_t buid;
57102+ int low = 0, high = uid_used - 1, mid;
57103+
57104+ while (high >= low) {
57105+ mid = (low + high) >> 1;
57106+ buid = tmp[mid].uid;
57107+ if (buid == uid)
57108+ return mid;
57109+ if (buid > uid)
57110+ high = mid - 1;
57111+ if (buid < uid)
57112+ low = mid + 1;
57113+ }
57114+
57115+ return -1;
57116+}
57117+
57118+static __inline__ void
57119+gr_insertsort(void)
57120+{
57121+ unsigned short i, j;
57122+ struct crash_uid index;
57123+
57124+ for (i = 1; i < uid_used; i++) {
57125+ index = uid_set[i];
57126+ j = i;
57127+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57128+ uid_set[j] = uid_set[j - 1];
57129+ j--;
57130+ }
57131+ uid_set[j] = index;
57132+ }
57133+
57134+ return;
57135+}
57136+
57137+static __inline__ void
57138+gr_insert_uid(const uid_t uid, const unsigned long expires)
57139+{
57140+ int loc;
57141+
57142+ if (uid_used == GR_UIDTABLE_MAX)
57143+ return;
57144+
57145+ loc = gr_find_uid(uid);
57146+
57147+ if (loc >= 0) {
57148+ uid_set[loc].expires = expires;
57149+ return;
57150+ }
57151+
57152+ uid_set[uid_used].uid = uid;
57153+ uid_set[uid_used].expires = expires;
57154+ uid_used++;
57155+
57156+ gr_insertsort();
57157+
57158+ return;
57159+}
57160+
57161+void
57162+gr_remove_uid(const unsigned short loc)
57163+{
57164+ unsigned short i;
57165+
57166+ for (i = loc + 1; i < uid_used; i++)
57167+ uid_set[i - 1] = uid_set[i];
57168+
57169+ uid_used--;
57170+
57171+ return;
57172+}
57173+
57174+int
57175+gr_check_crash_uid(const uid_t uid)
57176+{
57177+ int loc;
57178+ int ret = 0;
57179+
57180+ if (unlikely(!gr_acl_is_enabled()))
57181+ return 0;
57182+
57183+ spin_lock(&gr_uid_lock);
57184+ loc = gr_find_uid(uid);
57185+
57186+ if (loc < 0)
57187+ goto out_unlock;
57188+
57189+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
57190+ gr_remove_uid(loc);
57191+ else
57192+ ret = 1;
57193+
57194+out_unlock:
57195+ spin_unlock(&gr_uid_lock);
57196+ return ret;
57197+}
57198+
57199+static __inline__ int
57200+proc_is_setxid(const struct cred *cred)
57201+{
57202+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57203+ !uid_eq(cred->uid, cred->fsuid))
57204+ return 1;
57205+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57206+ !uid_eq(cred->gid, cred->fsgid))
57207+ return 1;
57208+
57209+ return 0;
57210+}
57211+
57212+extern int gr_fake_force_sig(int sig, struct task_struct *t);
57213+
57214+void
57215+gr_handle_crash(struct task_struct *task, const int sig)
57216+{
57217+ struct acl_subject_label *curr;
57218+ struct task_struct *tsk, *tsk2;
57219+ const struct cred *cred;
57220+ const struct cred *cred2;
57221+
57222+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57223+ return;
57224+
57225+ if (unlikely(!gr_acl_is_enabled()))
57226+ return;
57227+
57228+ curr = task->acl;
57229+
57230+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
57231+ return;
57232+
57233+ if (time_before_eq(curr->expires, get_seconds())) {
57234+ curr->expires = 0;
57235+ curr->crashes = 0;
57236+ }
57237+
57238+ curr->crashes++;
57239+
57240+ if (!curr->expires)
57241+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57242+
57243+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57244+ time_after(curr->expires, get_seconds())) {
57245+ rcu_read_lock();
57246+ cred = __task_cred(task);
57247+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57248+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57249+ spin_lock(&gr_uid_lock);
57250+ gr_insert_uid(cred->uid, curr->expires);
57251+ spin_unlock(&gr_uid_lock);
57252+ curr->expires = 0;
57253+ curr->crashes = 0;
57254+ read_lock(&tasklist_lock);
57255+ do_each_thread(tsk2, tsk) {
57256+ cred2 = __task_cred(tsk);
57257+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
57258+ gr_fake_force_sig(SIGKILL, tsk);
57259+ } while_each_thread(tsk2, tsk);
57260+ read_unlock(&tasklist_lock);
57261+ } else {
57262+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57263+ read_lock(&tasklist_lock);
57264+ read_lock(&grsec_exec_file_lock);
57265+ do_each_thread(tsk2, tsk) {
57266+ if (likely(tsk != task)) {
57267+ // if this thread has the same subject as the one that triggered
57268+ // RES_CRASH and it's the same binary, kill it
57269+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57270+ gr_fake_force_sig(SIGKILL, tsk);
57271+ }
57272+ } while_each_thread(tsk2, tsk);
57273+ read_unlock(&grsec_exec_file_lock);
57274+ read_unlock(&tasklist_lock);
57275+ }
57276+ rcu_read_unlock();
57277+ }
57278+
57279+ return;
57280+}
57281+
57282+int
57283+gr_check_crash_exec(const struct file *filp)
57284+{
57285+ struct acl_subject_label *curr;
57286+
57287+ if (unlikely(!gr_acl_is_enabled()))
57288+ return 0;
57289+
57290+ read_lock(&gr_inode_lock);
57291+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57292+ __get_dev(filp->f_path.dentry),
57293+ current->role);
57294+ read_unlock(&gr_inode_lock);
57295+
57296+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57297+ (!curr->crashes && !curr->expires))
57298+ return 0;
57299+
57300+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57301+ time_after(curr->expires, get_seconds()))
57302+ return 1;
57303+ else if (time_before_eq(curr->expires, get_seconds())) {
57304+ curr->crashes = 0;
57305+ curr->expires = 0;
57306+ }
57307+
57308+ return 0;
57309+}
57310+
57311+void
57312+gr_handle_alertkill(struct task_struct *task)
57313+{
57314+ struct acl_subject_label *curracl;
57315+ __u32 curr_ip;
57316+ struct task_struct *p, *p2;
57317+
57318+ if (unlikely(!gr_acl_is_enabled()))
57319+ return;
57320+
57321+ curracl = task->acl;
57322+ curr_ip = task->signal->curr_ip;
57323+
57324+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57325+ read_lock(&tasklist_lock);
57326+ do_each_thread(p2, p) {
57327+ if (p->signal->curr_ip == curr_ip)
57328+ gr_fake_force_sig(SIGKILL, p);
57329+ } while_each_thread(p2, p);
57330+ read_unlock(&tasklist_lock);
57331+ } else if (curracl->mode & GR_KILLPROC)
57332+ gr_fake_force_sig(SIGKILL, task);
57333+
57334+ return;
57335+}
57336diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57337new file mode 100644
57338index 0000000..9d83a69
57339--- /dev/null
57340+++ b/grsecurity/gracl_shm.c
57341@@ -0,0 +1,40 @@
57342+#include <linux/kernel.h>
57343+#include <linux/mm.h>
57344+#include <linux/sched.h>
57345+#include <linux/file.h>
57346+#include <linux/ipc.h>
57347+#include <linux/gracl.h>
57348+#include <linux/grsecurity.h>
57349+#include <linux/grinternal.h>
57350+
57351+int
57352+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57353+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57354+{
57355+ struct task_struct *task;
57356+
57357+ if (!gr_acl_is_enabled())
57358+ return 1;
57359+
57360+ rcu_read_lock();
57361+ read_lock(&tasklist_lock);
57362+
57363+ task = find_task_by_vpid(shm_cprid);
57364+
57365+ if (unlikely(!task))
57366+ task = find_task_by_vpid(shm_lapid);
57367+
57368+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57369+ (task->pid == shm_lapid)) &&
57370+ (task->acl->mode & GR_PROTSHM) &&
57371+ (task->acl != current->acl))) {
57372+ read_unlock(&tasklist_lock);
57373+ rcu_read_unlock();
57374+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57375+ return 0;
57376+ }
57377+ read_unlock(&tasklist_lock);
57378+ rcu_read_unlock();
57379+
57380+ return 1;
57381+}
57382diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57383new file mode 100644
57384index 0000000..bc0be01
57385--- /dev/null
57386+++ b/grsecurity/grsec_chdir.c
57387@@ -0,0 +1,19 @@
57388+#include <linux/kernel.h>
57389+#include <linux/sched.h>
57390+#include <linux/fs.h>
57391+#include <linux/file.h>
57392+#include <linux/grsecurity.h>
57393+#include <linux/grinternal.h>
57394+
57395+void
57396+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57397+{
57398+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57399+ if ((grsec_enable_chdir && grsec_enable_group &&
57400+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57401+ !grsec_enable_group)) {
57402+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57403+ }
57404+#endif
57405+ return;
57406+}
57407diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57408new file mode 100644
57409index 0000000..9807ee2
57410--- /dev/null
57411+++ b/grsecurity/grsec_chroot.c
57412@@ -0,0 +1,368 @@
57413+#include <linux/kernel.h>
57414+#include <linux/module.h>
57415+#include <linux/sched.h>
57416+#include <linux/file.h>
57417+#include <linux/fs.h>
57418+#include <linux/mount.h>
57419+#include <linux/types.h>
57420+#include "../fs/mount.h"
57421+#include <linux/grsecurity.h>
57422+#include <linux/grinternal.h>
57423+
57424+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57425+{
57426+#ifdef CONFIG_GRKERNSEC
57427+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57428+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57429+ task->gr_is_chrooted = 1;
57430+ else
57431+ task->gr_is_chrooted = 0;
57432+
57433+ task->gr_chroot_dentry = path->dentry;
57434+#endif
57435+ return;
57436+}
57437+
57438+void gr_clear_chroot_entries(struct task_struct *task)
57439+{
57440+#ifdef CONFIG_GRKERNSEC
57441+ task->gr_is_chrooted = 0;
57442+ task->gr_chroot_dentry = NULL;
57443+#endif
57444+ return;
57445+}
57446+
57447+int
57448+gr_handle_chroot_unix(const pid_t pid)
57449+{
57450+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57451+ struct task_struct *p;
57452+
57453+ if (unlikely(!grsec_enable_chroot_unix))
57454+ return 1;
57455+
57456+ if (likely(!proc_is_chrooted(current)))
57457+ return 1;
57458+
57459+ rcu_read_lock();
57460+ read_lock(&tasklist_lock);
57461+ p = find_task_by_vpid_unrestricted(pid);
57462+ if (unlikely(p && !have_same_root(current, p))) {
57463+ read_unlock(&tasklist_lock);
57464+ rcu_read_unlock();
57465+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57466+ return 0;
57467+ }
57468+ read_unlock(&tasklist_lock);
57469+ rcu_read_unlock();
57470+#endif
57471+ return 1;
57472+}
57473+
57474+int
57475+gr_handle_chroot_nice(void)
57476+{
57477+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57478+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57479+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57480+ return -EPERM;
57481+ }
57482+#endif
57483+ return 0;
57484+}
57485+
57486+int
57487+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57488+{
57489+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57490+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57491+ && proc_is_chrooted(current)) {
57492+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57493+ return -EACCES;
57494+ }
57495+#endif
57496+ return 0;
57497+}
57498+
57499+int
57500+gr_handle_chroot_rawio(const struct inode *inode)
57501+{
57502+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57503+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57504+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57505+ return 1;
57506+#endif
57507+ return 0;
57508+}
57509+
57510+int
57511+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57512+{
57513+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57514+ struct task_struct *p;
57515+ int ret = 0;
57516+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57517+ return ret;
57518+
57519+ read_lock(&tasklist_lock);
57520+ do_each_pid_task(pid, type, p) {
57521+ if (!have_same_root(current, p)) {
57522+ ret = 1;
57523+ goto out;
57524+ }
57525+ } while_each_pid_task(pid, type, p);
57526+out:
57527+ read_unlock(&tasklist_lock);
57528+ return ret;
57529+#endif
57530+ return 0;
57531+}
57532+
57533+int
57534+gr_pid_is_chrooted(struct task_struct *p)
57535+{
57536+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57537+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57538+ return 0;
57539+
57540+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57541+ !have_same_root(current, p)) {
57542+ return 1;
57543+ }
57544+#endif
57545+ return 0;
57546+}
57547+
57548+EXPORT_SYMBOL(gr_pid_is_chrooted);
57549+
57550+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57551+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57552+{
57553+ struct path path, currentroot;
57554+ int ret = 0;
57555+
57556+ path.dentry = (struct dentry *)u_dentry;
57557+ path.mnt = (struct vfsmount *)u_mnt;
57558+ get_fs_root(current->fs, &currentroot);
57559+ if (path_is_under(&path, &currentroot))
57560+ ret = 1;
57561+ path_put(&currentroot);
57562+
57563+ return ret;
57564+}
57565+#endif
57566+
57567+int
57568+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57569+{
57570+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57571+ if (!grsec_enable_chroot_fchdir)
57572+ return 1;
57573+
57574+ if (!proc_is_chrooted(current))
57575+ return 1;
57576+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57577+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57578+ return 0;
57579+ }
57580+#endif
57581+ return 1;
57582+}
57583+
57584+int
57585+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57586+ const time_t shm_createtime)
57587+{
57588+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57589+ struct task_struct *p;
57590+ time_t starttime;
57591+
57592+ if (unlikely(!grsec_enable_chroot_shmat))
57593+ return 1;
57594+
57595+ if (likely(!proc_is_chrooted(current)))
57596+ return 1;
57597+
57598+ rcu_read_lock();
57599+ read_lock(&tasklist_lock);
57600+
57601+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57602+ starttime = p->start_time.tv_sec;
57603+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57604+ if (have_same_root(current, p)) {
57605+ goto allow;
57606+ } else {
57607+ read_unlock(&tasklist_lock);
57608+ rcu_read_unlock();
57609+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57610+ return 0;
57611+ }
57612+ }
57613+ /* creator exited, pid reuse, fall through to next check */
57614+ }
57615+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57616+ if (unlikely(!have_same_root(current, p))) {
57617+ read_unlock(&tasklist_lock);
57618+ rcu_read_unlock();
57619+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57620+ return 0;
57621+ }
57622+ }
57623+
57624+allow:
57625+ read_unlock(&tasklist_lock);
57626+ rcu_read_unlock();
57627+#endif
57628+ return 1;
57629+}
57630+
57631+void
57632+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57633+{
57634+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57635+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57636+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57637+#endif
57638+ return;
57639+}
57640+
57641+int
57642+gr_handle_chroot_mknod(const struct dentry *dentry,
57643+ const struct vfsmount *mnt, const int mode)
57644+{
57645+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57646+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57647+ proc_is_chrooted(current)) {
57648+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57649+ return -EPERM;
57650+ }
57651+#endif
57652+ return 0;
57653+}
57654+
57655+int
57656+gr_handle_chroot_mount(const struct dentry *dentry,
57657+ const struct vfsmount *mnt, const char *dev_name)
57658+{
57659+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57660+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57661+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57662+ return -EPERM;
57663+ }
57664+#endif
57665+ return 0;
57666+}
57667+
57668+int
57669+gr_handle_chroot_pivot(void)
57670+{
57671+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57672+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57673+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57674+ return -EPERM;
57675+ }
57676+#endif
57677+ return 0;
57678+}
57679+
57680+int
57681+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57682+{
57683+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57684+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57685+ !gr_is_outside_chroot(dentry, mnt)) {
57686+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57687+ return -EPERM;
57688+ }
57689+#endif
57690+ return 0;
57691+}
57692+
57693+extern const char *captab_log[];
57694+extern int captab_log_entries;
57695+
57696+int
57697+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57698+{
57699+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57700+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57701+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57702+ if (cap_raised(chroot_caps, cap)) {
57703+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57704+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57705+ }
57706+ return 0;
57707+ }
57708+ }
57709+#endif
57710+ return 1;
57711+}
57712+
57713+int
57714+gr_chroot_is_capable(const int cap)
57715+{
57716+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57717+ return gr_task_chroot_is_capable(current, current_cred(), cap);
57718+#endif
57719+ return 1;
57720+}
57721+
57722+int
57723+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57724+{
57725+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57726+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57727+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57728+ if (cap_raised(chroot_caps, cap)) {
57729+ return 0;
57730+ }
57731+ }
57732+#endif
57733+ return 1;
57734+}
57735+
57736+int
57737+gr_chroot_is_capable_nolog(const int cap)
57738+{
57739+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57740+ return gr_task_chroot_is_capable_nolog(current, cap);
57741+#endif
57742+ return 1;
57743+}
57744+
57745+int
57746+gr_handle_chroot_sysctl(const int op)
57747+{
57748+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57749+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57750+ proc_is_chrooted(current))
57751+ return -EACCES;
57752+#endif
57753+ return 0;
57754+}
57755+
57756+void
57757+gr_handle_chroot_chdir(struct path *path)
57758+{
57759+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57760+ if (grsec_enable_chroot_chdir)
57761+ set_fs_pwd(current->fs, path);
57762+#endif
57763+ return;
57764+}
57765+
57766+int
57767+gr_handle_chroot_chmod(const struct dentry *dentry,
57768+ const struct vfsmount *mnt, const int mode)
57769+{
57770+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57771+ /* allow chmod +s on directories, but not files */
57772+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57773+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57774+ proc_is_chrooted(current)) {
57775+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57776+ return -EPERM;
57777+ }
57778+#endif
57779+ return 0;
57780+}
57781diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57782new file mode 100644
57783index 0000000..213ad8b
57784--- /dev/null
57785+++ b/grsecurity/grsec_disabled.c
57786@@ -0,0 +1,437 @@
57787+#include <linux/kernel.h>
57788+#include <linux/module.h>
57789+#include <linux/sched.h>
57790+#include <linux/file.h>
57791+#include <linux/fs.h>
57792+#include <linux/kdev_t.h>
57793+#include <linux/net.h>
57794+#include <linux/in.h>
57795+#include <linux/ip.h>
57796+#include <linux/skbuff.h>
57797+#include <linux/sysctl.h>
57798+
57799+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57800+void
57801+pax_set_initial_flags(struct linux_binprm *bprm)
57802+{
57803+ return;
57804+}
57805+#endif
57806+
57807+#ifdef CONFIG_SYSCTL
57808+__u32
57809+gr_handle_sysctl(const struct ctl_table * table, const int op)
57810+{
57811+ return 0;
57812+}
57813+#endif
57814+
57815+#ifdef CONFIG_TASKSTATS
57816+int gr_is_taskstats_denied(int pid)
57817+{
57818+ return 0;
57819+}
57820+#endif
57821+
57822+int
57823+gr_acl_is_enabled(void)
57824+{
57825+ return 0;
57826+}
57827+
57828+void
57829+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57830+{
57831+ return;
57832+}
57833+
57834+int
57835+gr_handle_rawio(const struct inode *inode)
57836+{
57837+ return 0;
57838+}
57839+
57840+void
57841+gr_acl_handle_psacct(struct task_struct *task, const long code)
57842+{
57843+ return;
57844+}
57845+
57846+int
57847+gr_handle_ptrace(struct task_struct *task, const long request)
57848+{
57849+ return 0;
57850+}
57851+
57852+int
57853+gr_handle_proc_ptrace(struct task_struct *task)
57854+{
57855+ return 0;
57856+}
57857+
57858+void
57859+gr_learn_resource(const struct task_struct *task,
57860+ const int res, const unsigned long wanted, const int gt)
57861+{
57862+ return;
57863+}
57864+
57865+int
57866+gr_set_acls(const int type)
57867+{
57868+ return 0;
57869+}
57870+
57871+int
57872+gr_check_hidden_task(const struct task_struct *tsk)
57873+{
57874+ return 0;
57875+}
57876+
57877+int
57878+gr_check_protected_task(const struct task_struct *task)
57879+{
57880+ return 0;
57881+}
57882+
57883+int
57884+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57885+{
57886+ return 0;
57887+}
57888+
57889+void
57890+gr_copy_label(struct task_struct *tsk)
57891+{
57892+ return;
57893+}
57894+
57895+void
57896+gr_set_pax_flags(struct task_struct *task)
57897+{
57898+ return;
57899+}
57900+
57901+int
57902+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57903+ const int unsafe_share)
57904+{
57905+ return 0;
57906+}
57907+
57908+void
57909+gr_handle_delete(const ino_t ino, const dev_t dev)
57910+{
57911+ return;
57912+}
57913+
57914+void
57915+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57916+{
57917+ return;
57918+}
57919+
57920+void
57921+gr_handle_crash(struct task_struct *task, const int sig)
57922+{
57923+ return;
57924+}
57925+
57926+int
57927+gr_check_crash_exec(const struct file *filp)
57928+{
57929+ return 0;
57930+}
57931+
57932+int
57933+gr_check_crash_uid(const uid_t uid)
57934+{
57935+ return 0;
57936+}
57937+
57938+void
57939+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57940+ struct dentry *old_dentry,
57941+ struct dentry *new_dentry,
57942+ struct vfsmount *mnt, const __u8 replace)
57943+{
57944+ return;
57945+}
57946+
57947+int
57948+gr_search_socket(const int family, const int type, const int protocol)
57949+{
57950+ return 1;
57951+}
57952+
57953+int
57954+gr_search_connectbind(const int mode, const struct socket *sock,
57955+ const struct sockaddr_in *addr)
57956+{
57957+ return 0;
57958+}
57959+
57960+void
57961+gr_handle_alertkill(struct task_struct *task)
57962+{
57963+ return;
57964+}
57965+
57966+__u32
57967+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57968+{
57969+ return 1;
57970+}
57971+
57972+__u32
57973+gr_acl_handle_hidden_file(const struct dentry * dentry,
57974+ const struct vfsmount * mnt)
57975+{
57976+ return 1;
57977+}
57978+
57979+__u32
57980+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57981+ int acc_mode)
57982+{
57983+ return 1;
57984+}
57985+
57986+__u32
57987+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57988+{
57989+ return 1;
57990+}
57991+
57992+__u32
57993+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57994+{
57995+ return 1;
57996+}
57997+
57998+int
57999+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58000+ unsigned int *vm_flags)
58001+{
58002+ return 1;
58003+}
58004+
58005+__u32
58006+gr_acl_handle_truncate(const struct dentry * dentry,
58007+ const struct vfsmount * mnt)
58008+{
58009+ return 1;
58010+}
58011+
58012+__u32
58013+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58014+{
58015+ return 1;
58016+}
58017+
58018+__u32
58019+gr_acl_handle_access(const struct dentry * dentry,
58020+ const struct vfsmount * mnt, const int fmode)
58021+{
58022+ return 1;
58023+}
58024+
58025+__u32
58026+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58027+ umode_t *mode)
58028+{
58029+ return 1;
58030+}
58031+
58032+__u32
58033+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58034+{
58035+ return 1;
58036+}
58037+
58038+__u32
58039+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58040+{
58041+ return 1;
58042+}
58043+
58044+void
58045+grsecurity_init(void)
58046+{
58047+ return;
58048+}
58049+
58050+umode_t gr_acl_umask(void)
58051+{
58052+ return 0;
58053+}
58054+
58055+__u32
58056+gr_acl_handle_mknod(const struct dentry * new_dentry,
58057+ const struct dentry * parent_dentry,
58058+ const struct vfsmount * parent_mnt,
58059+ const int mode)
58060+{
58061+ return 1;
58062+}
58063+
58064+__u32
58065+gr_acl_handle_mkdir(const struct dentry * new_dentry,
58066+ const struct dentry * parent_dentry,
58067+ const struct vfsmount * parent_mnt)
58068+{
58069+ return 1;
58070+}
58071+
58072+__u32
58073+gr_acl_handle_symlink(const struct dentry * new_dentry,
58074+ const struct dentry * parent_dentry,
58075+ const struct vfsmount * parent_mnt, const char *from)
58076+{
58077+ return 1;
58078+}
58079+
58080+__u32
58081+gr_acl_handle_link(const struct dentry * new_dentry,
58082+ const struct dentry * parent_dentry,
58083+ const struct vfsmount * parent_mnt,
58084+ const struct dentry * old_dentry,
58085+ const struct vfsmount * old_mnt, const char *to)
58086+{
58087+ return 1;
58088+}
58089+
58090+int
58091+gr_acl_handle_rename(const struct dentry *new_dentry,
58092+ const struct dentry *parent_dentry,
58093+ const struct vfsmount *parent_mnt,
58094+ const struct dentry *old_dentry,
58095+ const struct inode *old_parent_inode,
58096+ const struct vfsmount *old_mnt, const char *newname)
58097+{
58098+ return 0;
58099+}
58100+
58101+int
58102+gr_acl_handle_filldir(const struct file *file, const char *name,
58103+ const int namelen, const ino_t ino)
58104+{
58105+ return 1;
58106+}
58107+
58108+int
58109+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58110+ const time_t shm_createtime, const uid_t cuid, const int shmid)
58111+{
58112+ return 1;
58113+}
58114+
58115+int
58116+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58117+{
58118+ return 0;
58119+}
58120+
58121+int
58122+gr_search_accept(const struct socket *sock)
58123+{
58124+ return 0;
58125+}
58126+
58127+int
58128+gr_search_listen(const struct socket *sock)
58129+{
58130+ return 0;
58131+}
58132+
58133+int
58134+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58135+{
58136+ return 0;
58137+}
58138+
58139+__u32
58140+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58141+{
58142+ return 1;
58143+}
58144+
58145+__u32
58146+gr_acl_handle_creat(const struct dentry * dentry,
58147+ const struct dentry * p_dentry,
58148+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58149+ const int imode)
58150+{
58151+ return 1;
58152+}
58153+
58154+void
58155+gr_acl_handle_exit(void)
58156+{
58157+ return;
58158+}
58159+
58160+int
58161+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58162+{
58163+ return 1;
58164+}
58165+
58166+void
58167+gr_set_role_label(const uid_t uid, const gid_t gid)
58168+{
58169+ return;
58170+}
58171+
58172+int
58173+gr_acl_handle_procpidmem(const struct task_struct *task)
58174+{
58175+ return 0;
58176+}
58177+
58178+int
58179+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58180+{
58181+ return 0;
58182+}
58183+
58184+int
58185+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58186+{
58187+ return 0;
58188+}
58189+
58190+void
58191+gr_set_kernel_label(struct task_struct *task)
58192+{
58193+ return;
58194+}
58195+
58196+int
58197+gr_check_user_change(int real, int effective, int fs)
58198+{
58199+ return 0;
58200+}
58201+
58202+int
58203+gr_check_group_change(int real, int effective, int fs)
58204+{
58205+ return 0;
58206+}
58207+
58208+int gr_acl_enable_at_secure(void)
58209+{
58210+ return 0;
58211+}
58212+
58213+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58214+{
58215+ return dentry->d_inode->i_sb->s_dev;
58216+}
58217+
58218+EXPORT_SYMBOL(gr_learn_resource);
58219+EXPORT_SYMBOL(gr_set_kernel_label);
58220+#ifdef CONFIG_SECURITY
58221+EXPORT_SYMBOL(gr_check_user_change);
58222+EXPORT_SYMBOL(gr_check_group_change);
58223+#endif
58224diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58225new file mode 100644
58226index 0000000..abfa971
58227--- /dev/null
58228+++ b/grsecurity/grsec_exec.c
58229@@ -0,0 +1,174 @@
58230+#include <linux/kernel.h>
58231+#include <linux/sched.h>
58232+#include <linux/file.h>
58233+#include <linux/binfmts.h>
58234+#include <linux/fs.h>
58235+#include <linux/types.h>
58236+#include <linux/grdefs.h>
58237+#include <linux/grsecurity.h>
58238+#include <linux/grinternal.h>
58239+#include <linux/capability.h>
58240+#include <linux/module.h>
58241+
58242+#include <asm/uaccess.h>
58243+
58244+#ifdef CONFIG_GRKERNSEC_EXECLOG
58245+static char gr_exec_arg_buf[132];
58246+static DEFINE_MUTEX(gr_exec_arg_mutex);
58247+#endif
58248+
58249+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58250+
58251+void
58252+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58253+{
58254+#ifdef CONFIG_GRKERNSEC_EXECLOG
58255+ char *grarg = gr_exec_arg_buf;
58256+ unsigned int i, x, execlen = 0;
58257+ char c;
58258+
58259+ if (!((grsec_enable_execlog && grsec_enable_group &&
58260+ in_group_p(grsec_audit_gid))
58261+ || (grsec_enable_execlog && !grsec_enable_group)))
58262+ return;
58263+
58264+ mutex_lock(&gr_exec_arg_mutex);
58265+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
58266+
58267+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
58268+ const char __user *p;
58269+ unsigned int len;
58270+
58271+ p = get_user_arg_ptr(argv, i);
58272+ if (IS_ERR(p))
58273+ goto log;
58274+
58275+ len = strnlen_user(p, 128 - execlen);
58276+ if (len > 128 - execlen)
58277+ len = 128 - execlen;
58278+ else if (len > 0)
58279+ len--;
58280+ if (copy_from_user(grarg + execlen, p, len))
58281+ goto log;
58282+
58283+ /* rewrite unprintable characters */
58284+ for (x = 0; x < len; x++) {
58285+ c = *(grarg + execlen + x);
58286+ if (c < 32 || c > 126)
58287+ *(grarg + execlen + x) = ' ';
58288+ }
58289+
58290+ execlen += len;
58291+ *(grarg + execlen) = ' ';
58292+ *(grarg + execlen + 1) = '\0';
58293+ execlen++;
58294+ }
58295+
58296+ log:
58297+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58298+ bprm->file->f_path.mnt, grarg);
58299+ mutex_unlock(&gr_exec_arg_mutex);
58300+#endif
58301+ return;
58302+}
58303+
58304+#ifdef CONFIG_GRKERNSEC
58305+extern int gr_acl_is_capable(const int cap);
58306+extern int gr_acl_is_capable_nolog(const int cap);
58307+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58308+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58309+extern int gr_chroot_is_capable(const int cap);
58310+extern int gr_chroot_is_capable_nolog(const int cap);
58311+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58312+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58313+#endif
58314+
58315+const char *captab_log[] = {
58316+ "CAP_CHOWN",
58317+ "CAP_DAC_OVERRIDE",
58318+ "CAP_DAC_READ_SEARCH",
58319+ "CAP_FOWNER",
58320+ "CAP_FSETID",
58321+ "CAP_KILL",
58322+ "CAP_SETGID",
58323+ "CAP_SETUID",
58324+ "CAP_SETPCAP",
58325+ "CAP_LINUX_IMMUTABLE",
58326+ "CAP_NET_BIND_SERVICE",
58327+ "CAP_NET_BROADCAST",
58328+ "CAP_NET_ADMIN",
58329+ "CAP_NET_RAW",
58330+ "CAP_IPC_LOCK",
58331+ "CAP_IPC_OWNER",
58332+ "CAP_SYS_MODULE",
58333+ "CAP_SYS_RAWIO",
58334+ "CAP_SYS_CHROOT",
58335+ "CAP_SYS_PTRACE",
58336+ "CAP_SYS_PACCT",
58337+ "CAP_SYS_ADMIN",
58338+ "CAP_SYS_BOOT",
58339+ "CAP_SYS_NICE",
58340+ "CAP_SYS_RESOURCE",
58341+ "CAP_SYS_TIME",
58342+ "CAP_SYS_TTY_CONFIG",
58343+ "CAP_MKNOD",
58344+ "CAP_LEASE",
58345+ "CAP_AUDIT_WRITE",
58346+ "CAP_AUDIT_CONTROL",
58347+ "CAP_SETFCAP",
58348+ "CAP_MAC_OVERRIDE",
58349+ "CAP_MAC_ADMIN",
58350+ "CAP_SYSLOG",
58351+ "CAP_WAKE_ALARM"
58352+};
58353+
58354+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58355+
58356+int gr_is_capable(const int cap)
58357+{
58358+#ifdef CONFIG_GRKERNSEC
58359+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58360+ return 1;
58361+ return 0;
58362+#else
58363+ return 1;
58364+#endif
58365+}
58366+
58367+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58368+{
58369+#ifdef CONFIG_GRKERNSEC
58370+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58371+ return 1;
58372+ return 0;
58373+#else
58374+ return 1;
58375+#endif
58376+}
58377+
58378+int gr_is_capable_nolog(const int cap)
58379+{
58380+#ifdef CONFIG_GRKERNSEC
58381+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58382+ return 1;
58383+ return 0;
58384+#else
58385+ return 1;
58386+#endif
58387+}
58388+
58389+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58390+{
58391+#ifdef CONFIG_GRKERNSEC
58392+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58393+ return 1;
58394+ return 0;
58395+#else
58396+ return 1;
58397+#endif
58398+}
58399+
58400+EXPORT_SYMBOL(gr_is_capable);
58401+EXPORT_SYMBOL(gr_is_capable_nolog);
58402+EXPORT_SYMBOL(gr_task_is_capable);
58403+EXPORT_SYMBOL(gr_task_is_capable_nolog);
58404diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58405new file mode 100644
58406index 0000000..d3ee748
58407--- /dev/null
58408+++ b/grsecurity/grsec_fifo.c
58409@@ -0,0 +1,24 @@
58410+#include <linux/kernel.h>
58411+#include <linux/sched.h>
58412+#include <linux/fs.h>
58413+#include <linux/file.h>
58414+#include <linux/grinternal.h>
58415+
58416+int
58417+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58418+ const struct dentry *dir, const int flag, const int acc_mode)
58419+{
58420+#ifdef CONFIG_GRKERNSEC_FIFO
58421+ const struct cred *cred = current_cred();
58422+
58423+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58424+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58425+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58426+ (cred->fsuid != dentry->d_inode->i_uid)) {
58427+ if (!inode_permission(dentry->d_inode, acc_mode))
58428+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58429+ return -EACCES;
58430+ }
58431+#endif
58432+ return 0;
58433+}
58434diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58435new file mode 100644
58436index 0000000..8ca18bf
58437--- /dev/null
58438+++ b/grsecurity/grsec_fork.c
58439@@ -0,0 +1,23 @@
58440+#include <linux/kernel.h>
58441+#include <linux/sched.h>
58442+#include <linux/grsecurity.h>
58443+#include <linux/grinternal.h>
58444+#include <linux/errno.h>
58445+
58446+void
58447+gr_log_forkfail(const int retval)
58448+{
58449+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58450+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58451+ switch (retval) {
58452+ case -EAGAIN:
58453+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58454+ break;
58455+ case -ENOMEM:
58456+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58457+ break;
58458+ }
58459+ }
58460+#endif
58461+ return;
58462+}
58463diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58464new file mode 100644
58465index 0000000..05a6015
58466--- /dev/null
58467+++ b/grsecurity/grsec_init.c
58468@@ -0,0 +1,283 @@
58469+#include <linux/kernel.h>
58470+#include <linux/sched.h>
58471+#include <linux/mm.h>
58472+#include <linux/gracl.h>
58473+#include <linux/slab.h>
58474+#include <linux/vmalloc.h>
58475+#include <linux/percpu.h>
58476+#include <linux/module.h>
58477+
58478+int grsec_enable_ptrace_readexec;
58479+int grsec_enable_setxid;
58480+int grsec_enable_symlinkown;
58481+int grsec_symlinkown_gid;
58482+int grsec_enable_brute;
58483+int grsec_enable_link;
58484+int grsec_enable_dmesg;
58485+int grsec_enable_harden_ptrace;
58486+int grsec_enable_fifo;
58487+int grsec_enable_execlog;
58488+int grsec_enable_signal;
58489+int grsec_enable_forkfail;
58490+int grsec_enable_audit_ptrace;
58491+int grsec_enable_time;
58492+int grsec_enable_audit_textrel;
58493+int grsec_enable_group;
58494+int grsec_audit_gid;
58495+int grsec_enable_chdir;
58496+int grsec_enable_mount;
58497+int grsec_enable_rofs;
58498+int grsec_enable_chroot_findtask;
58499+int grsec_enable_chroot_mount;
58500+int grsec_enable_chroot_shmat;
58501+int grsec_enable_chroot_fchdir;
58502+int grsec_enable_chroot_double;
58503+int grsec_enable_chroot_pivot;
58504+int grsec_enable_chroot_chdir;
58505+int grsec_enable_chroot_chmod;
58506+int grsec_enable_chroot_mknod;
58507+int grsec_enable_chroot_nice;
58508+int grsec_enable_chroot_execlog;
58509+int grsec_enable_chroot_caps;
58510+int grsec_enable_chroot_sysctl;
58511+int grsec_enable_chroot_unix;
58512+int grsec_enable_tpe;
58513+int grsec_tpe_gid;
58514+int grsec_enable_blackhole;
58515+#ifdef CONFIG_IPV6_MODULE
58516+EXPORT_SYMBOL(grsec_enable_blackhole);
58517+#endif
58518+int grsec_lastack_retries;
58519+int grsec_enable_tpe_all;
58520+int grsec_enable_tpe_invert;
58521+int grsec_enable_socket_all;
58522+int grsec_socket_all_gid;
58523+int grsec_enable_socket_client;
58524+int grsec_socket_client_gid;
58525+int grsec_enable_socket_server;
58526+int grsec_socket_server_gid;
58527+int grsec_resource_logging;
58528+int grsec_disable_privio;
58529+int grsec_enable_log_rwxmaps;
58530+int grsec_lock;
58531+
58532+DEFINE_SPINLOCK(grsec_alert_lock);
58533+unsigned long grsec_alert_wtime = 0;
58534+unsigned long grsec_alert_fyet = 0;
58535+
58536+DEFINE_SPINLOCK(grsec_audit_lock);
58537+
58538+DEFINE_RWLOCK(grsec_exec_file_lock);
58539+
58540+char *gr_shared_page[4];
58541+
58542+char *gr_alert_log_fmt;
58543+char *gr_audit_log_fmt;
58544+char *gr_alert_log_buf;
58545+char *gr_audit_log_buf;
58546+
58547+extern struct gr_arg *gr_usermode;
58548+extern unsigned char *gr_system_salt;
58549+extern unsigned char *gr_system_sum;
58550+
58551+void __init
58552+grsecurity_init(void)
58553+{
58554+ int j;
58555+ /* create the per-cpu shared pages */
58556+
58557+#ifdef CONFIG_X86
58558+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58559+#endif
58560+
58561+ for (j = 0; j < 4; j++) {
58562+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58563+ if (gr_shared_page[j] == NULL) {
58564+ panic("Unable to allocate grsecurity shared page");
58565+ return;
58566+ }
58567+ }
58568+
58569+ /* allocate log buffers */
58570+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58571+ if (!gr_alert_log_fmt) {
58572+ panic("Unable to allocate grsecurity alert log format buffer");
58573+ return;
58574+ }
58575+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58576+ if (!gr_audit_log_fmt) {
58577+ panic("Unable to allocate grsecurity audit log format buffer");
58578+ return;
58579+ }
58580+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58581+ if (!gr_alert_log_buf) {
58582+ panic("Unable to allocate grsecurity alert log buffer");
58583+ return;
58584+ }
58585+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58586+ if (!gr_audit_log_buf) {
58587+ panic("Unable to allocate grsecurity audit log buffer");
58588+ return;
58589+ }
58590+
58591+ /* allocate memory for authentication structure */
58592+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58593+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58594+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58595+
58596+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58597+ panic("Unable to allocate grsecurity authentication structure");
58598+ return;
58599+ }
58600+
58601+
58602+#ifdef CONFIG_GRKERNSEC_IO
58603+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58604+ grsec_disable_privio = 1;
58605+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58606+ grsec_disable_privio = 1;
58607+#else
58608+ grsec_disable_privio = 0;
58609+#endif
58610+#endif
58611+
58612+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58613+ /* for backward compatibility, tpe_invert always defaults to on if
58614+ enabled in the kernel
58615+ */
58616+ grsec_enable_tpe_invert = 1;
58617+#endif
58618+
58619+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58620+#ifndef CONFIG_GRKERNSEC_SYSCTL
58621+ grsec_lock = 1;
58622+#endif
58623+
58624+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58625+ grsec_enable_audit_textrel = 1;
58626+#endif
58627+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58628+ grsec_enable_log_rwxmaps = 1;
58629+#endif
58630+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58631+ grsec_enable_group = 1;
58632+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58633+#endif
58634+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58635+ grsec_enable_ptrace_readexec = 1;
58636+#endif
58637+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58638+ grsec_enable_chdir = 1;
58639+#endif
58640+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58641+ grsec_enable_harden_ptrace = 1;
58642+#endif
58643+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58644+ grsec_enable_mount = 1;
58645+#endif
58646+#ifdef CONFIG_GRKERNSEC_LINK
58647+ grsec_enable_link = 1;
58648+#endif
58649+#ifdef CONFIG_GRKERNSEC_BRUTE
58650+ grsec_enable_brute = 1;
58651+#endif
58652+#ifdef CONFIG_GRKERNSEC_DMESG
58653+ grsec_enable_dmesg = 1;
58654+#endif
58655+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58656+ grsec_enable_blackhole = 1;
58657+ grsec_lastack_retries = 4;
58658+#endif
58659+#ifdef CONFIG_GRKERNSEC_FIFO
58660+ grsec_enable_fifo = 1;
58661+#endif
58662+#ifdef CONFIG_GRKERNSEC_EXECLOG
58663+ grsec_enable_execlog = 1;
58664+#endif
58665+#ifdef CONFIG_GRKERNSEC_SETXID
58666+ grsec_enable_setxid = 1;
58667+#endif
58668+#ifdef CONFIG_GRKERNSEC_SIGNAL
58669+ grsec_enable_signal = 1;
58670+#endif
58671+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58672+ grsec_enable_forkfail = 1;
58673+#endif
58674+#ifdef CONFIG_GRKERNSEC_TIME
58675+ grsec_enable_time = 1;
58676+#endif
58677+#ifdef CONFIG_GRKERNSEC_RESLOG
58678+ grsec_resource_logging = 1;
58679+#endif
58680+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58681+ grsec_enable_chroot_findtask = 1;
58682+#endif
58683+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58684+ grsec_enable_chroot_unix = 1;
58685+#endif
58686+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58687+ grsec_enable_chroot_mount = 1;
58688+#endif
58689+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58690+ grsec_enable_chroot_fchdir = 1;
58691+#endif
58692+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58693+ grsec_enable_chroot_shmat = 1;
58694+#endif
58695+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58696+ grsec_enable_audit_ptrace = 1;
58697+#endif
58698+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58699+ grsec_enable_chroot_double = 1;
58700+#endif
58701+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58702+ grsec_enable_chroot_pivot = 1;
58703+#endif
58704+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58705+ grsec_enable_chroot_chdir = 1;
58706+#endif
58707+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58708+ grsec_enable_chroot_chmod = 1;
58709+#endif
58710+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58711+ grsec_enable_chroot_mknod = 1;
58712+#endif
58713+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58714+ grsec_enable_chroot_nice = 1;
58715+#endif
58716+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58717+ grsec_enable_chroot_execlog = 1;
58718+#endif
58719+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58720+ grsec_enable_chroot_caps = 1;
58721+#endif
58722+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58723+ grsec_enable_chroot_sysctl = 1;
58724+#endif
58725+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58726+ grsec_enable_symlinkown = 1;
58727+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58728+#endif
58729+#ifdef CONFIG_GRKERNSEC_TPE
58730+ grsec_enable_tpe = 1;
58731+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58732+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58733+ grsec_enable_tpe_all = 1;
58734+#endif
58735+#endif
58736+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58737+ grsec_enable_socket_all = 1;
58738+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58739+#endif
58740+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58741+ grsec_enable_socket_client = 1;
58742+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58743+#endif
58744+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58745+ grsec_enable_socket_server = 1;
58746+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58747+#endif
58748+#endif
58749+
58750+ return;
58751+}
58752diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58753new file mode 100644
58754index 0000000..589481f
58755--- /dev/null
58756+++ b/grsecurity/grsec_link.c
58757@@ -0,0 +1,58 @@
58758+#include <linux/kernel.h>
58759+#include <linux/sched.h>
58760+#include <linux/fs.h>
58761+#include <linux/file.h>
58762+#include <linux/grinternal.h>
58763+
58764+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58765+{
58766+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58767+ const struct inode *link_inode = link->dentry->d_inode;
58768+
58769+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58770+ /* ignore root-owned links, e.g. /proc/self */
58771+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58772+ !uid_eq(link_inode->i_uid, target->i_uid)) {
58773+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58774+ return 1;
58775+ }
58776+#endif
58777+ return 0;
58778+}
58779+
58780+int
58781+gr_handle_follow_link(const struct inode *parent,
58782+ const struct inode *inode,
58783+ const struct dentry *dentry, const struct vfsmount *mnt)
58784+{
58785+#ifdef CONFIG_GRKERNSEC_LINK
58786+ const struct cred *cred = current_cred();
58787+
58788+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58789+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58790+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58791+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58792+ return -EACCES;
58793+ }
58794+#endif
58795+ return 0;
58796+}
58797+
58798+int
58799+gr_handle_hardlink(const struct dentry *dentry,
58800+ const struct vfsmount *mnt,
58801+ struct inode *inode, const int mode, const char *to)
58802+{
58803+#ifdef CONFIG_GRKERNSEC_LINK
58804+ const struct cred *cred = current_cred();
58805+
58806+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58807+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58808+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58809+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58810+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58811+ return -EPERM;
58812+ }
58813+#endif
58814+ return 0;
58815+}
58816diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58817new file mode 100644
58818index 0000000..a45d2e9
58819--- /dev/null
58820+++ b/grsecurity/grsec_log.c
58821@@ -0,0 +1,322 @@
58822+#include <linux/kernel.h>
58823+#include <linux/sched.h>
58824+#include <linux/file.h>
58825+#include <linux/tty.h>
58826+#include <linux/fs.h>
58827+#include <linux/grinternal.h>
58828+
58829+#ifdef CONFIG_TREE_PREEMPT_RCU
58830+#define DISABLE_PREEMPT() preempt_disable()
58831+#define ENABLE_PREEMPT() preempt_enable()
58832+#else
58833+#define DISABLE_PREEMPT()
58834+#define ENABLE_PREEMPT()
58835+#endif
58836+
58837+#define BEGIN_LOCKS(x) \
58838+ DISABLE_PREEMPT(); \
58839+ rcu_read_lock(); \
58840+ read_lock(&tasklist_lock); \
58841+ read_lock(&grsec_exec_file_lock); \
58842+ if (x != GR_DO_AUDIT) \
58843+ spin_lock(&grsec_alert_lock); \
58844+ else \
58845+ spin_lock(&grsec_audit_lock)
58846+
58847+#define END_LOCKS(x) \
58848+ if (x != GR_DO_AUDIT) \
58849+ spin_unlock(&grsec_alert_lock); \
58850+ else \
58851+ spin_unlock(&grsec_audit_lock); \
58852+ read_unlock(&grsec_exec_file_lock); \
58853+ read_unlock(&tasklist_lock); \
58854+ rcu_read_unlock(); \
58855+ ENABLE_PREEMPT(); \
58856+ if (x == GR_DONT_AUDIT) \
58857+ gr_handle_alertkill(current)
58858+
58859+enum {
58860+ FLOODING,
58861+ NO_FLOODING
58862+};
58863+
58864+extern char *gr_alert_log_fmt;
58865+extern char *gr_audit_log_fmt;
58866+extern char *gr_alert_log_buf;
58867+extern char *gr_audit_log_buf;
58868+
58869+static int gr_log_start(int audit)
58870+{
58871+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58872+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58873+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58874+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58875+ unsigned long curr_secs = get_seconds();
58876+
58877+ if (audit == GR_DO_AUDIT)
58878+ goto set_fmt;
58879+
58880+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58881+ grsec_alert_wtime = curr_secs;
58882+ grsec_alert_fyet = 0;
58883+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58884+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58885+ grsec_alert_fyet++;
58886+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58887+ grsec_alert_wtime = curr_secs;
58888+ grsec_alert_fyet++;
58889+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58890+ return FLOODING;
58891+ }
58892+ else return FLOODING;
58893+
58894+set_fmt:
58895+#endif
58896+ memset(buf, 0, PAGE_SIZE);
58897+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
58898+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58899+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58900+ } else if (current->signal->curr_ip) {
58901+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58902+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58903+ } else if (gr_acl_is_enabled()) {
58904+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58905+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58906+ } else {
58907+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
58908+ strcpy(buf, fmt);
58909+ }
58910+
58911+ return NO_FLOODING;
58912+}
58913+
58914+static void gr_log_middle(int audit, const char *msg, va_list ap)
58915+ __attribute__ ((format (printf, 2, 0)));
58916+
58917+static void gr_log_middle(int audit, const char *msg, va_list ap)
58918+{
58919+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58920+ unsigned int len = strlen(buf);
58921+
58922+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58923+
58924+ return;
58925+}
58926+
58927+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58928+ __attribute__ ((format (printf, 2, 3)));
58929+
58930+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58931+{
58932+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58933+ unsigned int len = strlen(buf);
58934+ va_list ap;
58935+
58936+ va_start(ap, msg);
58937+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58938+ va_end(ap);
58939+
58940+ return;
58941+}
58942+
58943+static void gr_log_end(int audit, int append_default)
58944+{
58945+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58946+
58947+ if (append_default) {
58948+ unsigned int len = strlen(buf);
58949+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58950+ }
58951+
58952+ printk("%s\n", buf);
58953+
58954+ return;
58955+}
58956+
58957+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58958+{
58959+ int logtype;
58960+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58961+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58962+ void *voidptr = NULL;
58963+ int num1 = 0, num2 = 0;
58964+ unsigned long ulong1 = 0, ulong2 = 0;
58965+ struct dentry *dentry = NULL;
58966+ struct vfsmount *mnt = NULL;
58967+ struct file *file = NULL;
58968+ struct task_struct *task = NULL;
58969+ const struct cred *cred, *pcred;
58970+ va_list ap;
58971+
58972+ BEGIN_LOCKS(audit);
58973+ logtype = gr_log_start(audit);
58974+ if (logtype == FLOODING) {
58975+ END_LOCKS(audit);
58976+ return;
58977+ }
58978+ va_start(ap, argtypes);
58979+ switch (argtypes) {
58980+ case GR_TTYSNIFF:
58981+ task = va_arg(ap, struct task_struct *);
58982+ 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);
58983+ break;
58984+ case GR_SYSCTL_HIDDEN:
58985+ str1 = va_arg(ap, char *);
58986+ gr_log_middle_varargs(audit, msg, result, str1);
58987+ break;
58988+ case GR_RBAC:
58989+ dentry = va_arg(ap, struct dentry *);
58990+ mnt = va_arg(ap, struct vfsmount *);
58991+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58992+ break;
58993+ case GR_RBAC_STR:
58994+ dentry = va_arg(ap, struct dentry *);
58995+ mnt = va_arg(ap, struct vfsmount *);
58996+ str1 = va_arg(ap, char *);
58997+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58998+ break;
58999+ case GR_STR_RBAC:
59000+ str1 = va_arg(ap, char *);
59001+ dentry = va_arg(ap, struct dentry *);
59002+ mnt = va_arg(ap, struct vfsmount *);
59003+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59004+ break;
59005+ case GR_RBAC_MODE2:
59006+ dentry = va_arg(ap, struct dentry *);
59007+ mnt = va_arg(ap, struct vfsmount *);
59008+ str1 = va_arg(ap, char *);
59009+ str2 = va_arg(ap, char *);
59010+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59011+ break;
59012+ case GR_RBAC_MODE3:
59013+ dentry = va_arg(ap, struct dentry *);
59014+ mnt = va_arg(ap, struct vfsmount *);
59015+ str1 = va_arg(ap, char *);
59016+ str2 = va_arg(ap, char *);
59017+ str3 = va_arg(ap, char *);
59018+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59019+ break;
59020+ case GR_FILENAME:
59021+ dentry = va_arg(ap, struct dentry *);
59022+ mnt = va_arg(ap, struct vfsmount *);
59023+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59024+ break;
59025+ case GR_STR_FILENAME:
59026+ str1 = va_arg(ap, char *);
59027+ dentry = va_arg(ap, struct dentry *);
59028+ mnt = va_arg(ap, struct vfsmount *);
59029+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59030+ break;
59031+ case GR_FILENAME_STR:
59032+ dentry = va_arg(ap, struct dentry *);
59033+ mnt = va_arg(ap, struct vfsmount *);
59034+ str1 = va_arg(ap, char *);
59035+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59036+ break;
59037+ case GR_FILENAME_TWO_INT:
59038+ dentry = va_arg(ap, struct dentry *);
59039+ mnt = va_arg(ap, struct vfsmount *);
59040+ num1 = va_arg(ap, int);
59041+ num2 = va_arg(ap, int);
59042+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59043+ break;
59044+ case GR_FILENAME_TWO_INT_STR:
59045+ dentry = va_arg(ap, struct dentry *);
59046+ mnt = va_arg(ap, struct vfsmount *);
59047+ num1 = va_arg(ap, int);
59048+ num2 = va_arg(ap, int);
59049+ str1 = va_arg(ap, char *);
59050+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59051+ break;
59052+ case GR_TEXTREL:
59053+ file = va_arg(ap, struct file *);
59054+ ulong1 = va_arg(ap, unsigned long);
59055+ ulong2 = va_arg(ap, unsigned long);
59056+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59057+ break;
59058+ case GR_PTRACE:
59059+ task = va_arg(ap, struct task_struct *);
59060+ 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);
59061+ break;
59062+ case GR_RESOURCE:
59063+ task = va_arg(ap, struct task_struct *);
59064+ cred = __task_cred(task);
59065+ pcred = __task_cred(task->real_parent);
59066+ ulong1 = va_arg(ap, unsigned long);
59067+ str1 = va_arg(ap, char *);
59068+ ulong2 = va_arg(ap, unsigned long);
59069+ 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);
59070+ break;
59071+ case GR_CAP:
59072+ task = va_arg(ap, struct task_struct *);
59073+ cred = __task_cred(task);
59074+ pcred = __task_cred(task->real_parent);
59075+ str1 = va_arg(ap, char *);
59076+ 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);
59077+ break;
59078+ case GR_SIG:
59079+ str1 = va_arg(ap, char *);
59080+ voidptr = va_arg(ap, void *);
59081+ gr_log_middle_varargs(audit, msg, str1, voidptr);
59082+ break;
59083+ case GR_SIG2:
59084+ task = va_arg(ap, struct task_struct *);
59085+ cred = __task_cred(task);
59086+ pcred = __task_cred(task->real_parent);
59087+ num1 = va_arg(ap, int);
59088+ 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);
59089+ break;
59090+ case GR_CRASH1:
59091+ task = va_arg(ap, struct task_struct *);
59092+ cred = __task_cred(task);
59093+ pcred = __task_cred(task->real_parent);
59094+ ulong1 = va_arg(ap, unsigned long);
59095+ 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);
59096+ break;
59097+ case GR_CRASH2:
59098+ task = va_arg(ap, struct task_struct *);
59099+ cred = __task_cred(task);
59100+ pcred = __task_cred(task->real_parent);
59101+ ulong1 = va_arg(ap, unsigned long);
59102+ 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);
59103+ break;
59104+ case GR_RWXMAP:
59105+ file = va_arg(ap, struct file *);
59106+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59107+ break;
59108+ case GR_PSACCT:
59109+ {
59110+ unsigned int wday, cday;
59111+ __u8 whr, chr;
59112+ __u8 wmin, cmin;
59113+ __u8 wsec, csec;
59114+ char cur_tty[64] = { 0 };
59115+ char parent_tty[64] = { 0 };
59116+
59117+ task = va_arg(ap, struct task_struct *);
59118+ wday = va_arg(ap, unsigned int);
59119+ cday = va_arg(ap, unsigned int);
59120+ whr = va_arg(ap, int);
59121+ chr = va_arg(ap, int);
59122+ wmin = va_arg(ap, int);
59123+ cmin = va_arg(ap, int);
59124+ wsec = va_arg(ap, int);
59125+ csec = va_arg(ap, int);
59126+ ulong1 = va_arg(ap, unsigned long);
59127+ cred = __task_cred(task);
59128+ pcred = __task_cred(task->real_parent);
59129+
59130+ 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);
59131+ }
59132+ break;
59133+ default:
59134+ gr_log_middle(audit, msg, ap);
59135+ }
59136+ va_end(ap);
59137+ // these don't need DEFAULTSECARGS printed on the end
59138+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59139+ gr_log_end(audit, 0);
59140+ else
59141+ gr_log_end(audit, 1);
59142+ END_LOCKS(audit);
59143+}
59144diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59145new file mode 100644
59146index 0000000..f536303
59147--- /dev/null
59148+++ b/grsecurity/grsec_mem.c
59149@@ -0,0 +1,40 @@
59150+#include <linux/kernel.h>
59151+#include <linux/sched.h>
59152+#include <linux/mm.h>
59153+#include <linux/mman.h>
59154+#include <linux/grinternal.h>
59155+
59156+void
59157+gr_handle_ioperm(void)
59158+{
59159+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59160+ return;
59161+}
59162+
59163+void
59164+gr_handle_iopl(void)
59165+{
59166+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59167+ return;
59168+}
59169+
59170+void
59171+gr_handle_mem_readwrite(u64 from, u64 to)
59172+{
59173+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59174+ return;
59175+}
59176+
59177+void
59178+gr_handle_vm86(void)
59179+{
59180+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59181+ return;
59182+}
59183+
59184+void
59185+gr_log_badprocpid(const char *entry)
59186+{
59187+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59188+ return;
59189+}
59190diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59191new file mode 100644
59192index 0000000..2131422
59193--- /dev/null
59194+++ b/grsecurity/grsec_mount.c
59195@@ -0,0 +1,62 @@
59196+#include <linux/kernel.h>
59197+#include <linux/sched.h>
59198+#include <linux/mount.h>
59199+#include <linux/grsecurity.h>
59200+#include <linux/grinternal.h>
59201+
59202+void
59203+gr_log_remount(const char *devname, const int retval)
59204+{
59205+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59206+ if (grsec_enable_mount && (retval >= 0))
59207+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59208+#endif
59209+ return;
59210+}
59211+
59212+void
59213+gr_log_unmount(const char *devname, const int retval)
59214+{
59215+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59216+ if (grsec_enable_mount && (retval >= 0))
59217+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59218+#endif
59219+ return;
59220+}
59221+
59222+void
59223+gr_log_mount(const char *from, const char *to, const int retval)
59224+{
59225+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59226+ if (grsec_enable_mount && (retval >= 0))
59227+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59228+#endif
59229+ return;
59230+}
59231+
59232+int
59233+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59234+{
59235+#ifdef CONFIG_GRKERNSEC_ROFS
59236+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59237+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59238+ return -EPERM;
59239+ } else
59240+ return 0;
59241+#endif
59242+ return 0;
59243+}
59244+
59245+int
59246+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59247+{
59248+#ifdef CONFIG_GRKERNSEC_ROFS
59249+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59250+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59251+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59252+ return -EPERM;
59253+ } else
59254+ return 0;
59255+#endif
59256+ return 0;
59257+}
59258diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59259new file mode 100644
59260index 0000000..a3b12a0
59261--- /dev/null
59262+++ b/grsecurity/grsec_pax.c
59263@@ -0,0 +1,36 @@
59264+#include <linux/kernel.h>
59265+#include <linux/sched.h>
59266+#include <linux/mm.h>
59267+#include <linux/file.h>
59268+#include <linux/grinternal.h>
59269+#include <linux/grsecurity.h>
59270+
59271+void
59272+gr_log_textrel(struct vm_area_struct * vma)
59273+{
59274+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59275+ if (grsec_enable_audit_textrel)
59276+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59277+#endif
59278+ return;
59279+}
59280+
59281+void
59282+gr_log_rwxmmap(struct file *file)
59283+{
59284+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59285+ if (grsec_enable_log_rwxmaps)
59286+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59287+#endif
59288+ return;
59289+}
59290+
59291+void
59292+gr_log_rwxmprotect(struct file *file)
59293+{
59294+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59295+ if (grsec_enable_log_rwxmaps)
59296+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59297+#endif
59298+ return;
59299+}
59300diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59301new file mode 100644
59302index 0000000..f7f29aa
59303--- /dev/null
59304+++ b/grsecurity/grsec_ptrace.c
59305@@ -0,0 +1,30 @@
59306+#include <linux/kernel.h>
59307+#include <linux/sched.h>
59308+#include <linux/grinternal.h>
59309+#include <linux/security.h>
59310+
59311+void
59312+gr_audit_ptrace(struct task_struct *task)
59313+{
59314+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59315+ if (grsec_enable_audit_ptrace)
59316+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59317+#endif
59318+ return;
59319+}
59320+
59321+int
59322+gr_ptrace_readexec(struct file *file, int unsafe_flags)
59323+{
59324+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59325+ const struct dentry *dentry = file->f_path.dentry;
59326+ const struct vfsmount *mnt = file->f_path.mnt;
59327+
59328+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59329+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59330+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59331+ return -EACCES;
59332+ }
59333+#endif
59334+ return 0;
59335+}
59336diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59337new file mode 100644
59338index 0000000..b4ac94c
59339--- /dev/null
59340+++ b/grsecurity/grsec_sig.c
59341@@ -0,0 +1,209 @@
59342+#include <linux/kernel.h>
59343+#include <linux/sched.h>
59344+#include <linux/delay.h>
59345+#include <linux/grsecurity.h>
59346+#include <linux/grinternal.h>
59347+#include <linux/hardirq.h>
59348+
59349+char *signames[] = {
59350+ [SIGSEGV] = "Segmentation fault",
59351+ [SIGILL] = "Illegal instruction",
59352+ [SIGABRT] = "Abort",
59353+ [SIGBUS] = "Invalid alignment/Bus error"
59354+};
59355+
59356+void
59357+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59358+{
59359+#ifdef CONFIG_GRKERNSEC_SIGNAL
59360+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59361+ (sig == SIGABRT) || (sig == SIGBUS))) {
59362+ if (t->pid == current->pid) {
59363+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59364+ } else {
59365+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59366+ }
59367+ }
59368+#endif
59369+ return;
59370+}
59371+
59372+int
59373+gr_handle_signal(const struct task_struct *p, const int sig)
59374+{
59375+#ifdef CONFIG_GRKERNSEC
59376+ /* ignore the 0 signal for protected task checks */
59377+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59378+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59379+ return -EPERM;
59380+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59381+ return -EPERM;
59382+ }
59383+#endif
59384+ return 0;
59385+}
59386+
59387+#ifdef CONFIG_GRKERNSEC
59388+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59389+
59390+int gr_fake_force_sig(int sig, struct task_struct *t)
59391+{
59392+ unsigned long int flags;
59393+ int ret, blocked, ignored;
59394+ struct k_sigaction *action;
59395+
59396+ spin_lock_irqsave(&t->sighand->siglock, flags);
59397+ action = &t->sighand->action[sig-1];
59398+ ignored = action->sa.sa_handler == SIG_IGN;
59399+ blocked = sigismember(&t->blocked, sig);
59400+ if (blocked || ignored) {
59401+ action->sa.sa_handler = SIG_DFL;
59402+ if (blocked) {
59403+ sigdelset(&t->blocked, sig);
59404+ recalc_sigpending_and_wake(t);
59405+ }
59406+ }
59407+ if (action->sa.sa_handler == SIG_DFL)
59408+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
59409+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59410+
59411+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
59412+
59413+ return ret;
59414+}
59415+#endif
59416+
59417+#ifdef CONFIG_GRKERNSEC_BRUTE
59418+#define GR_USER_BAN_TIME (15 * 60)
59419+
59420+static int __get_dumpable(unsigned long mm_flags)
59421+{
59422+ int ret;
59423+
59424+ ret = mm_flags & MMF_DUMPABLE_MASK;
59425+ return (ret >= 2) ? 2 : ret;
59426+}
59427+#endif
59428+
59429+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59430+{
59431+#ifdef CONFIG_GRKERNSEC_BRUTE
59432+ kuid_t uid = GLOBAL_ROOT_UID;
59433+
59434+ if (!grsec_enable_brute)
59435+ return;
59436+
59437+ rcu_read_lock();
59438+ read_lock(&tasklist_lock);
59439+ read_lock(&grsec_exec_file_lock);
59440+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59441+ p->real_parent->brute = 1;
59442+ else {
59443+ const struct cred *cred = __task_cred(p), *cred2;
59444+ struct task_struct *tsk, *tsk2;
59445+
59446+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59447+ struct user_struct *user;
59448+
59449+ uid = cred->uid;
59450+
59451+ /* this is put upon execution past expiration */
59452+ user = find_user(uid);
59453+ if (user == NULL)
59454+ goto unlock;
59455+ user->banned = 1;
59456+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59457+ if (user->ban_expires == ~0UL)
59458+ user->ban_expires--;
59459+
59460+ do_each_thread(tsk2, tsk) {
59461+ cred2 = __task_cred(tsk);
59462+ if (tsk != p && uid_eq(cred2->uid, uid))
59463+ gr_fake_force_sig(SIGKILL, tsk);
59464+ } while_each_thread(tsk2, tsk);
59465+ }
59466+ }
59467+unlock:
59468+ read_unlock(&grsec_exec_file_lock);
59469+ read_unlock(&tasklist_lock);
59470+ rcu_read_unlock();
59471+
59472+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
59473+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59474+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59475+
59476+#endif
59477+ return;
59478+}
59479+
59480+void gr_handle_brute_check(void)
59481+{
59482+#ifdef CONFIG_GRKERNSEC_BRUTE
59483+ if (current->brute)
59484+ msleep(30 * 1000);
59485+#endif
59486+ return;
59487+}
59488+
59489+void gr_handle_kernel_exploit(void)
59490+{
59491+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59492+ const struct cred *cred;
59493+ struct task_struct *tsk, *tsk2;
59494+ struct user_struct *user;
59495+ kuid_t uid;
59496+
59497+ if (in_irq() || in_serving_softirq() || in_nmi())
59498+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59499+
59500+ uid = current_uid();
59501+
59502+ if (uid_eq(uid, GLOBAL_ROOT_UID))
59503+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
59504+ else {
59505+ /* kill all the processes of this user, hold a reference
59506+ to their creds struct, and prevent them from creating
59507+ another process until system reset
59508+ */
59509+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59510+ from_kuid_munged(&init_user_ns, uid));
59511+ /* we intentionally leak this ref */
59512+ user = get_uid(current->cred->user);
59513+ if (user) {
59514+ user->banned = 1;
59515+ user->ban_expires = ~0UL;
59516+ }
59517+
59518+ read_lock(&tasklist_lock);
59519+ do_each_thread(tsk2, tsk) {
59520+ cred = __task_cred(tsk);
59521+ if (uid_eq(cred->uid, uid))
59522+ gr_fake_force_sig(SIGKILL, tsk);
59523+ } while_each_thread(tsk2, tsk);
59524+ read_unlock(&tasklist_lock);
59525+ }
59526+#endif
59527+}
59528+
59529+int __gr_process_user_ban(struct user_struct *user)
59530+{
59531+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59532+ if (unlikely(user->banned)) {
59533+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59534+ user->banned = 0;
59535+ user->ban_expires = 0;
59536+ free_uid(user);
59537+ } else
59538+ return -EPERM;
59539+ }
59540+#endif
59541+ return 0;
59542+}
59543+
59544+int gr_process_user_ban(void)
59545+{
59546+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59547+ return __gr_process_user_ban(current->cred->user);
59548+#endif
59549+ return 0;
59550+}
59551diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59552new file mode 100644
59553index 0000000..4030d57
59554--- /dev/null
59555+++ b/grsecurity/grsec_sock.c
59556@@ -0,0 +1,244 @@
59557+#include <linux/kernel.h>
59558+#include <linux/module.h>
59559+#include <linux/sched.h>
59560+#include <linux/file.h>
59561+#include <linux/net.h>
59562+#include <linux/in.h>
59563+#include <linux/ip.h>
59564+#include <net/sock.h>
59565+#include <net/inet_sock.h>
59566+#include <linux/grsecurity.h>
59567+#include <linux/grinternal.h>
59568+#include <linux/gracl.h>
59569+
59570+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59571+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59572+
59573+EXPORT_SYMBOL(gr_search_udp_recvmsg);
59574+EXPORT_SYMBOL(gr_search_udp_sendmsg);
59575+
59576+#ifdef CONFIG_UNIX_MODULE
59577+EXPORT_SYMBOL(gr_acl_handle_unix);
59578+EXPORT_SYMBOL(gr_acl_handle_mknod);
59579+EXPORT_SYMBOL(gr_handle_chroot_unix);
59580+EXPORT_SYMBOL(gr_handle_create);
59581+#endif
59582+
59583+#ifdef CONFIG_GRKERNSEC
59584+#define gr_conn_table_size 32749
59585+struct conn_table_entry {
59586+ struct conn_table_entry *next;
59587+ struct signal_struct *sig;
59588+};
59589+
59590+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59591+DEFINE_SPINLOCK(gr_conn_table_lock);
59592+
59593+extern const char * gr_socktype_to_name(unsigned char type);
59594+extern const char * gr_proto_to_name(unsigned char proto);
59595+extern const char * gr_sockfamily_to_name(unsigned char family);
59596+
59597+static __inline__ int
59598+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59599+{
59600+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59601+}
59602+
59603+static __inline__ int
59604+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59605+ __u16 sport, __u16 dport)
59606+{
59607+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59608+ sig->gr_sport == sport && sig->gr_dport == dport))
59609+ return 1;
59610+ else
59611+ return 0;
59612+}
59613+
59614+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59615+{
59616+ struct conn_table_entry **match;
59617+ unsigned int index;
59618+
59619+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59620+ sig->gr_sport, sig->gr_dport,
59621+ gr_conn_table_size);
59622+
59623+ newent->sig = sig;
59624+
59625+ match = &gr_conn_table[index];
59626+ newent->next = *match;
59627+ *match = newent;
59628+
59629+ return;
59630+}
59631+
59632+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59633+{
59634+ struct conn_table_entry *match, *last = NULL;
59635+ unsigned int index;
59636+
59637+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59638+ sig->gr_sport, sig->gr_dport,
59639+ gr_conn_table_size);
59640+
59641+ match = gr_conn_table[index];
59642+ while (match && !conn_match(match->sig,
59643+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59644+ sig->gr_dport)) {
59645+ last = match;
59646+ match = match->next;
59647+ }
59648+
59649+ if (match) {
59650+ if (last)
59651+ last->next = match->next;
59652+ else
59653+ gr_conn_table[index] = NULL;
59654+ kfree(match);
59655+ }
59656+
59657+ return;
59658+}
59659+
59660+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59661+ __u16 sport, __u16 dport)
59662+{
59663+ struct conn_table_entry *match;
59664+ unsigned int index;
59665+
59666+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59667+
59668+ match = gr_conn_table[index];
59669+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59670+ match = match->next;
59671+
59672+ if (match)
59673+ return match->sig;
59674+ else
59675+ return NULL;
59676+}
59677+
59678+#endif
59679+
59680+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59681+{
59682+#ifdef CONFIG_GRKERNSEC
59683+ struct signal_struct *sig = task->signal;
59684+ struct conn_table_entry *newent;
59685+
59686+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59687+ if (newent == NULL)
59688+ return;
59689+ /* no bh lock needed since we are called with bh disabled */
59690+ spin_lock(&gr_conn_table_lock);
59691+ gr_del_task_from_ip_table_nolock(sig);
59692+ sig->gr_saddr = inet->inet_rcv_saddr;
59693+ sig->gr_daddr = inet->inet_daddr;
59694+ sig->gr_sport = inet->inet_sport;
59695+ sig->gr_dport = inet->inet_dport;
59696+ gr_add_to_task_ip_table_nolock(sig, newent);
59697+ spin_unlock(&gr_conn_table_lock);
59698+#endif
59699+ return;
59700+}
59701+
59702+void gr_del_task_from_ip_table(struct task_struct *task)
59703+{
59704+#ifdef CONFIG_GRKERNSEC
59705+ spin_lock_bh(&gr_conn_table_lock);
59706+ gr_del_task_from_ip_table_nolock(task->signal);
59707+ spin_unlock_bh(&gr_conn_table_lock);
59708+#endif
59709+ return;
59710+}
59711+
59712+void
59713+gr_attach_curr_ip(const struct sock *sk)
59714+{
59715+#ifdef CONFIG_GRKERNSEC
59716+ struct signal_struct *p, *set;
59717+ const struct inet_sock *inet = inet_sk(sk);
59718+
59719+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59720+ return;
59721+
59722+ set = current->signal;
59723+
59724+ spin_lock_bh(&gr_conn_table_lock);
59725+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59726+ inet->inet_dport, inet->inet_sport);
59727+ if (unlikely(p != NULL)) {
59728+ set->curr_ip = p->curr_ip;
59729+ set->used_accept = 1;
59730+ gr_del_task_from_ip_table_nolock(p);
59731+ spin_unlock_bh(&gr_conn_table_lock);
59732+ return;
59733+ }
59734+ spin_unlock_bh(&gr_conn_table_lock);
59735+
59736+ set->curr_ip = inet->inet_daddr;
59737+ set->used_accept = 1;
59738+#endif
59739+ return;
59740+}
59741+
59742+int
59743+gr_handle_sock_all(const int family, const int type, const int protocol)
59744+{
59745+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59746+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59747+ (family != AF_UNIX)) {
59748+ if (family == AF_INET)
59749+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59750+ else
59751+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59752+ return -EACCES;
59753+ }
59754+#endif
59755+ return 0;
59756+}
59757+
59758+int
59759+gr_handle_sock_server(const struct sockaddr *sck)
59760+{
59761+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59762+ if (grsec_enable_socket_server &&
59763+ in_group_p(grsec_socket_server_gid) &&
59764+ sck && (sck->sa_family != AF_UNIX) &&
59765+ (sck->sa_family != AF_LOCAL)) {
59766+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59767+ return -EACCES;
59768+ }
59769+#endif
59770+ return 0;
59771+}
59772+
59773+int
59774+gr_handle_sock_server_other(const struct sock *sck)
59775+{
59776+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59777+ if (grsec_enable_socket_server &&
59778+ in_group_p(grsec_socket_server_gid) &&
59779+ sck && (sck->sk_family != AF_UNIX) &&
59780+ (sck->sk_family != AF_LOCAL)) {
59781+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59782+ return -EACCES;
59783+ }
59784+#endif
59785+ return 0;
59786+}
59787+
59788+int
59789+gr_handle_sock_client(const struct sockaddr *sck)
59790+{
59791+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59792+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59793+ sck && (sck->sa_family != AF_UNIX) &&
59794+ (sck->sa_family != AF_LOCAL)) {
59795+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59796+ return -EACCES;
59797+ }
59798+#endif
59799+ return 0;
59800+}
59801diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59802new file mode 100644
59803index 0000000..f55ef0f
59804--- /dev/null
59805+++ b/grsecurity/grsec_sysctl.c
59806@@ -0,0 +1,469 @@
59807+#include <linux/kernel.h>
59808+#include <linux/sched.h>
59809+#include <linux/sysctl.h>
59810+#include <linux/grsecurity.h>
59811+#include <linux/grinternal.h>
59812+
59813+int
59814+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59815+{
59816+#ifdef CONFIG_GRKERNSEC_SYSCTL
59817+ if (dirname == NULL || name == NULL)
59818+ return 0;
59819+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59820+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59821+ return -EACCES;
59822+ }
59823+#endif
59824+ return 0;
59825+}
59826+
59827+#ifdef CONFIG_GRKERNSEC_ROFS
59828+static int __maybe_unused one = 1;
59829+#endif
59830+
59831+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59832+struct ctl_table grsecurity_table[] = {
59833+#ifdef CONFIG_GRKERNSEC_SYSCTL
59834+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59835+#ifdef CONFIG_GRKERNSEC_IO
59836+ {
59837+ .procname = "disable_priv_io",
59838+ .data = &grsec_disable_privio,
59839+ .maxlen = sizeof(int),
59840+ .mode = 0600,
59841+ .proc_handler = &proc_dointvec,
59842+ },
59843+#endif
59844+#endif
59845+#ifdef CONFIG_GRKERNSEC_LINK
59846+ {
59847+ .procname = "linking_restrictions",
59848+ .data = &grsec_enable_link,
59849+ .maxlen = sizeof(int),
59850+ .mode = 0600,
59851+ .proc_handler = &proc_dointvec,
59852+ },
59853+#endif
59854+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59855+ {
59856+ .procname = "enforce_symlinksifowner",
59857+ .data = &grsec_enable_symlinkown,
59858+ .maxlen = sizeof(int),
59859+ .mode = 0600,
59860+ .proc_handler = &proc_dointvec,
59861+ },
59862+ {
59863+ .procname = "symlinkown_gid",
59864+ .data = &grsec_symlinkown_gid,
59865+ .maxlen = sizeof(int),
59866+ .mode = 0600,
59867+ .proc_handler = &proc_dointvec,
59868+ },
59869+#endif
59870+#ifdef CONFIG_GRKERNSEC_BRUTE
59871+ {
59872+ .procname = "deter_bruteforce",
59873+ .data = &grsec_enable_brute,
59874+ .maxlen = sizeof(int),
59875+ .mode = 0600,
59876+ .proc_handler = &proc_dointvec,
59877+ },
59878+#endif
59879+#ifdef CONFIG_GRKERNSEC_FIFO
59880+ {
59881+ .procname = "fifo_restrictions",
59882+ .data = &grsec_enable_fifo,
59883+ .maxlen = sizeof(int),
59884+ .mode = 0600,
59885+ .proc_handler = &proc_dointvec,
59886+ },
59887+#endif
59888+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59889+ {
59890+ .procname = "ptrace_readexec",
59891+ .data = &grsec_enable_ptrace_readexec,
59892+ .maxlen = sizeof(int),
59893+ .mode = 0600,
59894+ .proc_handler = &proc_dointvec,
59895+ },
59896+#endif
59897+#ifdef CONFIG_GRKERNSEC_SETXID
59898+ {
59899+ .procname = "consistent_setxid",
59900+ .data = &grsec_enable_setxid,
59901+ .maxlen = sizeof(int),
59902+ .mode = 0600,
59903+ .proc_handler = &proc_dointvec,
59904+ },
59905+#endif
59906+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59907+ {
59908+ .procname = "ip_blackhole",
59909+ .data = &grsec_enable_blackhole,
59910+ .maxlen = sizeof(int),
59911+ .mode = 0600,
59912+ .proc_handler = &proc_dointvec,
59913+ },
59914+ {
59915+ .procname = "lastack_retries",
59916+ .data = &grsec_lastack_retries,
59917+ .maxlen = sizeof(int),
59918+ .mode = 0600,
59919+ .proc_handler = &proc_dointvec,
59920+ },
59921+#endif
59922+#ifdef CONFIG_GRKERNSEC_EXECLOG
59923+ {
59924+ .procname = "exec_logging",
59925+ .data = &grsec_enable_execlog,
59926+ .maxlen = sizeof(int),
59927+ .mode = 0600,
59928+ .proc_handler = &proc_dointvec,
59929+ },
59930+#endif
59931+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59932+ {
59933+ .procname = "rwxmap_logging",
59934+ .data = &grsec_enable_log_rwxmaps,
59935+ .maxlen = sizeof(int),
59936+ .mode = 0600,
59937+ .proc_handler = &proc_dointvec,
59938+ },
59939+#endif
59940+#ifdef CONFIG_GRKERNSEC_SIGNAL
59941+ {
59942+ .procname = "signal_logging",
59943+ .data = &grsec_enable_signal,
59944+ .maxlen = sizeof(int),
59945+ .mode = 0600,
59946+ .proc_handler = &proc_dointvec,
59947+ },
59948+#endif
59949+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59950+ {
59951+ .procname = "forkfail_logging",
59952+ .data = &grsec_enable_forkfail,
59953+ .maxlen = sizeof(int),
59954+ .mode = 0600,
59955+ .proc_handler = &proc_dointvec,
59956+ },
59957+#endif
59958+#ifdef CONFIG_GRKERNSEC_TIME
59959+ {
59960+ .procname = "timechange_logging",
59961+ .data = &grsec_enable_time,
59962+ .maxlen = sizeof(int),
59963+ .mode = 0600,
59964+ .proc_handler = &proc_dointvec,
59965+ },
59966+#endif
59967+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59968+ {
59969+ .procname = "chroot_deny_shmat",
59970+ .data = &grsec_enable_chroot_shmat,
59971+ .maxlen = sizeof(int),
59972+ .mode = 0600,
59973+ .proc_handler = &proc_dointvec,
59974+ },
59975+#endif
59976+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59977+ {
59978+ .procname = "chroot_deny_unix",
59979+ .data = &grsec_enable_chroot_unix,
59980+ .maxlen = sizeof(int),
59981+ .mode = 0600,
59982+ .proc_handler = &proc_dointvec,
59983+ },
59984+#endif
59985+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59986+ {
59987+ .procname = "chroot_deny_mount",
59988+ .data = &grsec_enable_chroot_mount,
59989+ .maxlen = sizeof(int),
59990+ .mode = 0600,
59991+ .proc_handler = &proc_dointvec,
59992+ },
59993+#endif
59994+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59995+ {
59996+ .procname = "chroot_deny_fchdir",
59997+ .data = &grsec_enable_chroot_fchdir,
59998+ .maxlen = sizeof(int),
59999+ .mode = 0600,
60000+ .proc_handler = &proc_dointvec,
60001+ },
60002+#endif
60003+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60004+ {
60005+ .procname = "chroot_deny_chroot",
60006+ .data = &grsec_enable_chroot_double,
60007+ .maxlen = sizeof(int),
60008+ .mode = 0600,
60009+ .proc_handler = &proc_dointvec,
60010+ },
60011+#endif
60012+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60013+ {
60014+ .procname = "chroot_deny_pivot",
60015+ .data = &grsec_enable_chroot_pivot,
60016+ .maxlen = sizeof(int),
60017+ .mode = 0600,
60018+ .proc_handler = &proc_dointvec,
60019+ },
60020+#endif
60021+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60022+ {
60023+ .procname = "chroot_enforce_chdir",
60024+ .data = &grsec_enable_chroot_chdir,
60025+ .maxlen = sizeof(int),
60026+ .mode = 0600,
60027+ .proc_handler = &proc_dointvec,
60028+ },
60029+#endif
60030+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60031+ {
60032+ .procname = "chroot_deny_chmod",
60033+ .data = &grsec_enable_chroot_chmod,
60034+ .maxlen = sizeof(int),
60035+ .mode = 0600,
60036+ .proc_handler = &proc_dointvec,
60037+ },
60038+#endif
60039+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60040+ {
60041+ .procname = "chroot_deny_mknod",
60042+ .data = &grsec_enable_chroot_mknod,
60043+ .maxlen = sizeof(int),
60044+ .mode = 0600,
60045+ .proc_handler = &proc_dointvec,
60046+ },
60047+#endif
60048+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60049+ {
60050+ .procname = "chroot_restrict_nice",
60051+ .data = &grsec_enable_chroot_nice,
60052+ .maxlen = sizeof(int),
60053+ .mode = 0600,
60054+ .proc_handler = &proc_dointvec,
60055+ },
60056+#endif
60057+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60058+ {
60059+ .procname = "chroot_execlog",
60060+ .data = &grsec_enable_chroot_execlog,
60061+ .maxlen = sizeof(int),
60062+ .mode = 0600,
60063+ .proc_handler = &proc_dointvec,
60064+ },
60065+#endif
60066+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60067+ {
60068+ .procname = "chroot_caps",
60069+ .data = &grsec_enable_chroot_caps,
60070+ .maxlen = sizeof(int),
60071+ .mode = 0600,
60072+ .proc_handler = &proc_dointvec,
60073+ },
60074+#endif
60075+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60076+ {
60077+ .procname = "chroot_deny_sysctl",
60078+ .data = &grsec_enable_chroot_sysctl,
60079+ .maxlen = sizeof(int),
60080+ .mode = 0600,
60081+ .proc_handler = &proc_dointvec,
60082+ },
60083+#endif
60084+#ifdef CONFIG_GRKERNSEC_TPE
60085+ {
60086+ .procname = "tpe",
60087+ .data = &grsec_enable_tpe,
60088+ .maxlen = sizeof(int),
60089+ .mode = 0600,
60090+ .proc_handler = &proc_dointvec,
60091+ },
60092+ {
60093+ .procname = "tpe_gid",
60094+ .data = &grsec_tpe_gid,
60095+ .maxlen = sizeof(int),
60096+ .mode = 0600,
60097+ .proc_handler = &proc_dointvec,
60098+ },
60099+#endif
60100+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60101+ {
60102+ .procname = "tpe_invert",
60103+ .data = &grsec_enable_tpe_invert,
60104+ .maxlen = sizeof(int),
60105+ .mode = 0600,
60106+ .proc_handler = &proc_dointvec,
60107+ },
60108+#endif
60109+#ifdef CONFIG_GRKERNSEC_TPE_ALL
60110+ {
60111+ .procname = "tpe_restrict_all",
60112+ .data = &grsec_enable_tpe_all,
60113+ .maxlen = sizeof(int),
60114+ .mode = 0600,
60115+ .proc_handler = &proc_dointvec,
60116+ },
60117+#endif
60118+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60119+ {
60120+ .procname = "socket_all",
60121+ .data = &grsec_enable_socket_all,
60122+ .maxlen = sizeof(int),
60123+ .mode = 0600,
60124+ .proc_handler = &proc_dointvec,
60125+ },
60126+ {
60127+ .procname = "socket_all_gid",
60128+ .data = &grsec_socket_all_gid,
60129+ .maxlen = sizeof(int),
60130+ .mode = 0600,
60131+ .proc_handler = &proc_dointvec,
60132+ },
60133+#endif
60134+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60135+ {
60136+ .procname = "socket_client",
60137+ .data = &grsec_enable_socket_client,
60138+ .maxlen = sizeof(int),
60139+ .mode = 0600,
60140+ .proc_handler = &proc_dointvec,
60141+ },
60142+ {
60143+ .procname = "socket_client_gid",
60144+ .data = &grsec_socket_client_gid,
60145+ .maxlen = sizeof(int),
60146+ .mode = 0600,
60147+ .proc_handler = &proc_dointvec,
60148+ },
60149+#endif
60150+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60151+ {
60152+ .procname = "socket_server",
60153+ .data = &grsec_enable_socket_server,
60154+ .maxlen = sizeof(int),
60155+ .mode = 0600,
60156+ .proc_handler = &proc_dointvec,
60157+ },
60158+ {
60159+ .procname = "socket_server_gid",
60160+ .data = &grsec_socket_server_gid,
60161+ .maxlen = sizeof(int),
60162+ .mode = 0600,
60163+ .proc_handler = &proc_dointvec,
60164+ },
60165+#endif
60166+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60167+ {
60168+ .procname = "audit_group",
60169+ .data = &grsec_enable_group,
60170+ .maxlen = sizeof(int),
60171+ .mode = 0600,
60172+ .proc_handler = &proc_dointvec,
60173+ },
60174+ {
60175+ .procname = "audit_gid",
60176+ .data = &grsec_audit_gid,
60177+ .maxlen = sizeof(int),
60178+ .mode = 0600,
60179+ .proc_handler = &proc_dointvec,
60180+ },
60181+#endif
60182+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60183+ {
60184+ .procname = "audit_chdir",
60185+ .data = &grsec_enable_chdir,
60186+ .maxlen = sizeof(int),
60187+ .mode = 0600,
60188+ .proc_handler = &proc_dointvec,
60189+ },
60190+#endif
60191+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60192+ {
60193+ .procname = "audit_mount",
60194+ .data = &grsec_enable_mount,
60195+ .maxlen = sizeof(int),
60196+ .mode = 0600,
60197+ .proc_handler = &proc_dointvec,
60198+ },
60199+#endif
60200+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60201+ {
60202+ .procname = "audit_textrel",
60203+ .data = &grsec_enable_audit_textrel,
60204+ .maxlen = sizeof(int),
60205+ .mode = 0600,
60206+ .proc_handler = &proc_dointvec,
60207+ },
60208+#endif
60209+#ifdef CONFIG_GRKERNSEC_DMESG
60210+ {
60211+ .procname = "dmesg",
60212+ .data = &grsec_enable_dmesg,
60213+ .maxlen = sizeof(int),
60214+ .mode = 0600,
60215+ .proc_handler = &proc_dointvec,
60216+ },
60217+#endif
60218+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60219+ {
60220+ .procname = "chroot_findtask",
60221+ .data = &grsec_enable_chroot_findtask,
60222+ .maxlen = sizeof(int),
60223+ .mode = 0600,
60224+ .proc_handler = &proc_dointvec,
60225+ },
60226+#endif
60227+#ifdef CONFIG_GRKERNSEC_RESLOG
60228+ {
60229+ .procname = "resource_logging",
60230+ .data = &grsec_resource_logging,
60231+ .maxlen = sizeof(int),
60232+ .mode = 0600,
60233+ .proc_handler = &proc_dointvec,
60234+ },
60235+#endif
60236+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60237+ {
60238+ .procname = "audit_ptrace",
60239+ .data = &grsec_enable_audit_ptrace,
60240+ .maxlen = sizeof(int),
60241+ .mode = 0600,
60242+ .proc_handler = &proc_dointvec,
60243+ },
60244+#endif
60245+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60246+ {
60247+ .procname = "harden_ptrace",
60248+ .data = &grsec_enable_harden_ptrace,
60249+ .maxlen = sizeof(int),
60250+ .mode = 0600,
60251+ .proc_handler = &proc_dointvec,
60252+ },
60253+#endif
60254+ {
60255+ .procname = "grsec_lock",
60256+ .data = &grsec_lock,
60257+ .maxlen = sizeof(int),
60258+ .mode = 0600,
60259+ .proc_handler = &proc_dointvec,
60260+ },
60261+#endif
60262+#ifdef CONFIG_GRKERNSEC_ROFS
60263+ {
60264+ .procname = "romount_protect",
60265+ .data = &grsec_enable_rofs,
60266+ .maxlen = sizeof(int),
60267+ .mode = 0600,
60268+ .proc_handler = &proc_dointvec_minmax,
60269+ .extra1 = &one,
60270+ .extra2 = &one,
60271+ },
60272+#endif
60273+ { }
60274+};
60275+#endif
60276diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60277new file mode 100644
60278index 0000000..0dc13c3
60279--- /dev/null
60280+++ b/grsecurity/grsec_time.c
60281@@ -0,0 +1,16 @@
60282+#include <linux/kernel.h>
60283+#include <linux/sched.h>
60284+#include <linux/grinternal.h>
60285+#include <linux/module.h>
60286+
60287+void
60288+gr_log_timechange(void)
60289+{
60290+#ifdef CONFIG_GRKERNSEC_TIME
60291+ if (grsec_enable_time)
60292+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60293+#endif
60294+ return;
60295+}
60296+
60297+EXPORT_SYMBOL(gr_log_timechange);
60298diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60299new file mode 100644
60300index 0000000..07e0dc0
60301--- /dev/null
60302+++ b/grsecurity/grsec_tpe.c
60303@@ -0,0 +1,73 @@
60304+#include <linux/kernel.h>
60305+#include <linux/sched.h>
60306+#include <linux/file.h>
60307+#include <linux/fs.h>
60308+#include <linux/grinternal.h>
60309+
60310+extern int gr_acl_tpe_check(void);
60311+
60312+int
60313+gr_tpe_allow(const struct file *file)
60314+{
60315+#ifdef CONFIG_GRKERNSEC
60316+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60317+ const struct cred *cred = current_cred();
60318+ char *msg = NULL;
60319+ char *msg2 = NULL;
60320+
60321+ // never restrict root
60322+ if (!cred->uid)
60323+ return 1;
60324+
60325+ if (grsec_enable_tpe) {
60326+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60327+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60328+ msg = "not being in trusted group";
60329+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60330+ msg = "being in untrusted group";
60331+#else
60332+ if (in_group_p(grsec_tpe_gid))
60333+ msg = "being in untrusted group";
60334+#endif
60335+ }
60336+ if (!msg && gr_acl_tpe_check())
60337+ msg = "being in untrusted role";
60338+
60339+ // not in any affected group/role
60340+ if (!msg)
60341+ goto next_check;
60342+
60343+ if (inode->i_uid)
60344+ msg2 = "file in non-root-owned directory";
60345+ else if (inode->i_mode & S_IWOTH)
60346+ msg2 = "file in world-writable directory";
60347+ else if (inode->i_mode & S_IWGRP)
60348+ msg2 = "file in group-writable directory";
60349+
60350+ if (msg && msg2) {
60351+ char fullmsg[70] = {0};
60352+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60353+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60354+ return 0;
60355+ }
60356+ msg = NULL;
60357+next_check:
60358+#ifdef CONFIG_GRKERNSEC_TPE_ALL
60359+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60360+ return 1;
60361+
60362+ if (inode->i_uid && (inode->i_uid != cred->uid))
60363+ msg = "directory not owned by user";
60364+ else if (inode->i_mode & S_IWOTH)
60365+ msg = "file in world-writable directory";
60366+ else if (inode->i_mode & S_IWGRP)
60367+ msg = "file in group-writable directory";
60368+
60369+ if (msg) {
60370+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60371+ return 0;
60372+ }
60373+#endif
60374+#endif
60375+ return 1;
60376+}
60377diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60378new file mode 100644
60379index 0000000..9f7b1ac
60380--- /dev/null
60381+++ b/grsecurity/grsum.c
60382@@ -0,0 +1,61 @@
60383+#include <linux/err.h>
60384+#include <linux/kernel.h>
60385+#include <linux/sched.h>
60386+#include <linux/mm.h>
60387+#include <linux/scatterlist.h>
60388+#include <linux/crypto.h>
60389+#include <linux/gracl.h>
60390+
60391+
60392+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60393+#error "crypto and sha256 must be built into the kernel"
60394+#endif
60395+
60396+int
60397+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60398+{
60399+ char *p;
60400+ struct crypto_hash *tfm;
60401+ struct hash_desc desc;
60402+ struct scatterlist sg;
60403+ unsigned char temp_sum[GR_SHA_LEN];
60404+ volatile int retval = 0;
60405+ volatile int dummy = 0;
60406+ unsigned int i;
60407+
60408+ sg_init_table(&sg, 1);
60409+
60410+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60411+ if (IS_ERR(tfm)) {
60412+ /* should never happen, since sha256 should be built in */
60413+ return 1;
60414+ }
60415+
60416+ desc.tfm = tfm;
60417+ desc.flags = 0;
60418+
60419+ crypto_hash_init(&desc);
60420+
60421+ p = salt;
60422+ sg_set_buf(&sg, p, GR_SALT_LEN);
60423+ crypto_hash_update(&desc, &sg, sg.length);
60424+
60425+ p = entry->pw;
60426+ sg_set_buf(&sg, p, strlen(p));
60427+
60428+ crypto_hash_update(&desc, &sg, sg.length);
60429+
60430+ crypto_hash_final(&desc, temp_sum);
60431+
60432+ memset(entry->pw, 0, GR_PW_LEN);
60433+
60434+ for (i = 0; i < GR_SHA_LEN; i++)
60435+ if (sum[i] != temp_sum[i])
60436+ retval = 1;
60437+ else
60438+ dummy = 1; // waste a cycle
60439+
60440+ crypto_free_hash(tfm);
60441+
60442+ return retval;
60443+}
60444diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60445index 9e6e1c6..d47b906 100644
60446--- a/include/acpi/acpi_bus.h
60447+++ b/include/acpi/acpi_bus.h
60448@@ -138,7 +138,7 @@ struct acpi_device_ops {
60449 acpi_op_bind bind;
60450 acpi_op_unbind unbind;
60451 acpi_op_notify notify;
60452-};
60453+} __no_const;
60454
60455 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60456
60457diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60458index 77ff547..181834f 100644
60459--- a/include/asm-generic/4level-fixup.h
60460+++ b/include/asm-generic/4level-fixup.h
60461@@ -13,8 +13,10 @@
60462 #define pmd_alloc(mm, pud, address) \
60463 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60464 NULL: pmd_offset(pud, address))
60465+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60466
60467 #define pud_alloc(mm, pgd, address) (pgd)
60468+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60469 #define pud_offset(pgd, start) (pgd)
60470 #define pud_none(pud) 0
60471 #define pud_bad(pud) 0
60472diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60473index b7babf0..3ba8aee 100644
60474--- a/include/asm-generic/atomic-long.h
60475+++ b/include/asm-generic/atomic-long.h
60476@@ -22,6 +22,12 @@
60477
60478 typedef atomic64_t atomic_long_t;
60479
60480+#ifdef CONFIG_PAX_REFCOUNT
60481+typedef atomic64_unchecked_t atomic_long_unchecked_t;
60482+#else
60483+typedef atomic64_t atomic_long_unchecked_t;
60484+#endif
60485+
60486 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60487
60488 static inline long atomic_long_read(atomic_long_t *l)
60489@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60490 return (long)atomic64_read(v);
60491 }
60492
60493+#ifdef CONFIG_PAX_REFCOUNT
60494+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60495+{
60496+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60497+
60498+ return (long)atomic64_read_unchecked(v);
60499+}
60500+#endif
60501+
60502 static inline void atomic_long_set(atomic_long_t *l, long i)
60503 {
60504 atomic64_t *v = (atomic64_t *)l;
60505@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60506 atomic64_set(v, i);
60507 }
60508
60509+#ifdef CONFIG_PAX_REFCOUNT
60510+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60511+{
60512+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60513+
60514+ atomic64_set_unchecked(v, i);
60515+}
60516+#endif
60517+
60518 static inline void atomic_long_inc(atomic_long_t *l)
60519 {
60520 atomic64_t *v = (atomic64_t *)l;
60521@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60522 atomic64_inc(v);
60523 }
60524
60525+#ifdef CONFIG_PAX_REFCOUNT
60526+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60527+{
60528+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60529+
60530+ atomic64_inc_unchecked(v);
60531+}
60532+#endif
60533+
60534 static inline void atomic_long_dec(atomic_long_t *l)
60535 {
60536 atomic64_t *v = (atomic64_t *)l;
60537@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60538 atomic64_dec(v);
60539 }
60540
60541+#ifdef CONFIG_PAX_REFCOUNT
60542+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60543+{
60544+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60545+
60546+ atomic64_dec_unchecked(v);
60547+}
60548+#endif
60549+
60550 static inline void atomic_long_add(long i, atomic_long_t *l)
60551 {
60552 atomic64_t *v = (atomic64_t *)l;
60553@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60554 atomic64_add(i, v);
60555 }
60556
60557+#ifdef CONFIG_PAX_REFCOUNT
60558+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60559+{
60560+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60561+
60562+ atomic64_add_unchecked(i, v);
60563+}
60564+#endif
60565+
60566 static inline void atomic_long_sub(long i, atomic_long_t *l)
60567 {
60568 atomic64_t *v = (atomic64_t *)l;
60569@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60570 atomic64_sub(i, v);
60571 }
60572
60573+#ifdef CONFIG_PAX_REFCOUNT
60574+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60575+{
60576+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60577+
60578+ atomic64_sub_unchecked(i, v);
60579+}
60580+#endif
60581+
60582 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60583 {
60584 atomic64_t *v = (atomic64_t *)l;
60585@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60586 return (long)atomic64_inc_return(v);
60587 }
60588
60589+#ifdef CONFIG_PAX_REFCOUNT
60590+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60591+{
60592+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60593+
60594+ return (long)atomic64_inc_return_unchecked(v);
60595+}
60596+#endif
60597+
60598 static inline long atomic_long_dec_return(atomic_long_t *l)
60599 {
60600 atomic64_t *v = (atomic64_t *)l;
60601@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60602
60603 typedef atomic_t atomic_long_t;
60604
60605+#ifdef CONFIG_PAX_REFCOUNT
60606+typedef atomic_unchecked_t atomic_long_unchecked_t;
60607+#else
60608+typedef atomic_t atomic_long_unchecked_t;
60609+#endif
60610+
60611 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60612 static inline long atomic_long_read(atomic_long_t *l)
60613 {
60614@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60615 return (long)atomic_read(v);
60616 }
60617
60618+#ifdef CONFIG_PAX_REFCOUNT
60619+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60620+{
60621+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60622+
60623+ return (long)atomic_read_unchecked(v);
60624+}
60625+#endif
60626+
60627 static inline void atomic_long_set(atomic_long_t *l, long i)
60628 {
60629 atomic_t *v = (atomic_t *)l;
60630@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60631 atomic_set(v, i);
60632 }
60633
60634+#ifdef CONFIG_PAX_REFCOUNT
60635+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60636+{
60637+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60638+
60639+ atomic_set_unchecked(v, i);
60640+}
60641+#endif
60642+
60643 static inline void atomic_long_inc(atomic_long_t *l)
60644 {
60645 atomic_t *v = (atomic_t *)l;
60646@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60647 atomic_inc(v);
60648 }
60649
60650+#ifdef CONFIG_PAX_REFCOUNT
60651+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60652+{
60653+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60654+
60655+ atomic_inc_unchecked(v);
60656+}
60657+#endif
60658+
60659 static inline void atomic_long_dec(atomic_long_t *l)
60660 {
60661 atomic_t *v = (atomic_t *)l;
60662@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60663 atomic_dec(v);
60664 }
60665
60666+#ifdef CONFIG_PAX_REFCOUNT
60667+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60668+{
60669+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60670+
60671+ atomic_dec_unchecked(v);
60672+}
60673+#endif
60674+
60675 static inline void atomic_long_add(long i, atomic_long_t *l)
60676 {
60677 atomic_t *v = (atomic_t *)l;
60678@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60679 atomic_add(i, v);
60680 }
60681
60682+#ifdef CONFIG_PAX_REFCOUNT
60683+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60684+{
60685+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60686+
60687+ atomic_add_unchecked(i, v);
60688+}
60689+#endif
60690+
60691 static inline void atomic_long_sub(long i, atomic_long_t *l)
60692 {
60693 atomic_t *v = (atomic_t *)l;
60694@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60695 atomic_sub(i, v);
60696 }
60697
60698+#ifdef CONFIG_PAX_REFCOUNT
60699+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60700+{
60701+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60702+
60703+ atomic_sub_unchecked(i, v);
60704+}
60705+#endif
60706+
60707 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60708 {
60709 atomic_t *v = (atomic_t *)l;
60710@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60711 return (long)atomic_inc_return(v);
60712 }
60713
60714+#ifdef CONFIG_PAX_REFCOUNT
60715+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60716+{
60717+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60718+
60719+ return (long)atomic_inc_return_unchecked(v);
60720+}
60721+#endif
60722+
60723 static inline long atomic_long_dec_return(atomic_long_t *l)
60724 {
60725 atomic_t *v = (atomic_t *)l;
60726@@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60727
60728 #endif /* BITS_PER_LONG == 64 */
60729
60730+#ifdef CONFIG_PAX_REFCOUNT
60731+static inline void pax_refcount_needs_these_functions(void)
60732+{
60733+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
60734+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60735+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60736+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60737+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60738+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60739+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60740+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60741+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60742+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60743+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60744+#ifdef CONFIG_X86
60745+ atomic_clear_mask_unchecked(0, NULL);
60746+ atomic_set_mask_unchecked(0, NULL);
60747+#endif
60748+
60749+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60750+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60751+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60752+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60753+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60754+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60755+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60756+}
60757+#else
60758+#define atomic_read_unchecked(v) atomic_read(v)
60759+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60760+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60761+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60762+#define atomic_inc_unchecked(v) atomic_inc(v)
60763+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60764+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60765+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60766+#define atomic_dec_unchecked(v) atomic_dec(v)
60767+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60768+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60769+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60770+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60771+
60772+#define atomic_long_read_unchecked(v) atomic_long_read(v)
60773+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60774+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60775+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60776+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60777+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60778+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60779+#endif
60780+
60781 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60782diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60783index 1ced641..c896ee8 100644
60784--- a/include/asm-generic/atomic.h
60785+++ b/include/asm-generic/atomic.h
60786@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60787 * Atomically clears the bits set in @mask from @v
60788 */
60789 #ifndef atomic_clear_mask
60790-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60791+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60792 {
60793 unsigned long flags;
60794
60795diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60796index b18ce4f..2ee2843 100644
60797--- a/include/asm-generic/atomic64.h
60798+++ b/include/asm-generic/atomic64.h
60799@@ -16,6 +16,8 @@ typedef struct {
60800 long long counter;
60801 } atomic64_t;
60802
60803+typedef atomic64_t atomic64_unchecked_t;
60804+
60805 #define ATOMIC64_INIT(i) { (i) }
60806
60807 extern long long atomic64_read(const atomic64_t *v);
60808@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60809 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60810 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60811
60812+#define atomic64_read_unchecked(v) atomic64_read(v)
60813+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60814+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60815+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60816+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60817+#define atomic64_inc_unchecked(v) atomic64_inc(v)
60818+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60819+#define atomic64_dec_unchecked(v) atomic64_dec(v)
60820+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60821+
60822 #endif /* _ASM_GENERIC_ATOMIC64_H */
60823diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60824index 1bfcfe5..e04c5c9 100644
60825--- a/include/asm-generic/cache.h
60826+++ b/include/asm-generic/cache.h
60827@@ -6,7 +6,7 @@
60828 * cache lines need to provide their own cache.h.
60829 */
60830
60831-#define L1_CACHE_SHIFT 5
60832-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60833+#define L1_CACHE_SHIFT 5UL
60834+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60835
60836 #endif /* __ASM_GENERIC_CACHE_H */
60837diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60838index 0d68a1e..b74a761 100644
60839--- a/include/asm-generic/emergency-restart.h
60840+++ b/include/asm-generic/emergency-restart.h
60841@@ -1,7 +1,7 @@
60842 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60843 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60844
60845-static inline void machine_emergency_restart(void)
60846+static inline __noreturn void machine_emergency_restart(void)
60847 {
60848 machine_restart(NULL);
60849 }
60850diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60851index 0232ccb..13d9165 100644
60852--- a/include/asm-generic/kmap_types.h
60853+++ b/include/asm-generic/kmap_types.h
60854@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60855 KMAP_D(17) KM_NMI,
60856 KMAP_D(18) KM_NMI_PTE,
60857 KMAP_D(19) KM_KDB,
60858+KMAP_D(20) KM_CLEARPAGE,
60859 /*
60860 * Remember to update debug_kmap_atomic() when adding new kmap types!
60861 */
60862-KMAP_D(20) KM_TYPE_NR
60863+KMAP_D(21) KM_TYPE_NR
60864 };
60865
60866 #undef KMAP_D
60867diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60868index 9ceb03b..2efbcbd 100644
60869--- a/include/asm-generic/local.h
60870+++ b/include/asm-generic/local.h
60871@@ -39,6 +39,7 @@ typedef struct
60872 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60873 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60874 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60875+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60876
60877 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60878 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60879diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60880index 725612b..9cc513a 100644
60881--- a/include/asm-generic/pgtable-nopmd.h
60882+++ b/include/asm-generic/pgtable-nopmd.h
60883@@ -1,14 +1,19 @@
60884 #ifndef _PGTABLE_NOPMD_H
60885 #define _PGTABLE_NOPMD_H
60886
60887-#ifndef __ASSEMBLY__
60888-
60889 #include <asm-generic/pgtable-nopud.h>
60890
60891-struct mm_struct;
60892-
60893 #define __PAGETABLE_PMD_FOLDED
60894
60895+#define PMD_SHIFT PUD_SHIFT
60896+#define PTRS_PER_PMD 1
60897+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60898+#define PMD_MASK (~(PMD_SIZE-1))
60899+
60900+#ifndef __ASSEMBLY__
60901+
60902+struct mm_struct;
60903+
60904 /*
60905 * Having the pmd type consist of a pud gets the size right, and allows
60906 * us to conceptually access the pud entry that this pmd is folded into
60907@@ -16,11 +21,6 @@ struct mm_struct;
60908 */
60909 typedef struct { pud_t pud; } pmd_t;
60910
60911-#define PMD_SHIFT PUD_SHIFT
60912-#define PTRS_PER_PMD 1
60913-#define PMD_SIZE (1UL << PMD_SHIFT)
60914-#define PMD_MASK (~(PMD_SIZE-1))
60915-
60916 /*
60917 * The "pud_xxx()" functions here are trivial for a folded two-level
60918 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60919diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60920index 810431d..0ec4804f 100644
60921--- a/include/asm-generic/pgtable-nopud.h
60922+++ b/include/asm-generic/pgtable-nopud.h
60923@@ -1,10 +1,15 @@
60924 #ifndef _PGTABLE_NOPUD_H
60925 #define _PGTABLE_NOPUD_H
60926
60927-#ifndef __ASSEMBLY__
60928-
60929 #define __PAGETABLE_PUD_FOLDED
60930
60931+#define PUD_SHIFT PGDIR_SHIFT
60932+#define PTRS_PER_PUD 1
60933+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60934+#define PUD_MASK (~(PUD_SIZE-1))
60935+
60936+#ifndef __ASSEMBLY__
60937+
60938 /*
60939 * Having the pud type consist of a pgd gets the size right, and allows
60940 * us to conceptually access the pgd entry that this pud is folded into
60941@@ -12,11 +17,6 @@
60942 */
60943 typedef struct { pgd_t pgd; } pud_t;
60944
60945-#define PUD_SHIFT PGDIR_SHIFT
60946-#define PTRS_PER_PUD 1
60947-#define PUD_SIZE (1UL << PUD_SHIFT)
60948-#define PUD_MASK (~(PUD_SIZE-1))
60949-
60950 /*
60951 * The "pgd_xxx()" functions here are trivial for a folded two-level
60952 * setup: the pud is never bad, and a pud always exists (as it's folded
60953@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60954 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60955
60956 #define pgd_populate(mm, pgd, pud) do { } while (0)
60957+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60958 /*
60959 * (puds are folded into pgds so this doesn't get actually called,
60960 * but the define is needed for a generic inline function.)
60961diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60962index ff4947b..f48183f 100644
60963--- a/include/asm-generic/pgtable.h
60964+++ b/include/asm-generic/pgtable.h
60965@@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60966 #endif
60967 }
60968
60969+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60970+static inline unsigned long pax_open_kernel(void) { return 0; }
60971+#endif
60972+
60973+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60974+static inline unsigned long pax_close_kernel(void) { return 0; }
60975+#endif
60976+
60977 #endif /* CONFIG_MMU */
60978
60979 #endif /* !__ASSEMBLY__ */
60980diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60981index 4e2e1cc..12c266b 100644
60982--- a/include/asm-generic/vmlinux.lds.h
60983+++ b/include/asm-generic/vmlinux.lds.h
60984@@ -218,6 +218,7 @@
60985 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60986 VMLINUX_SYMBOL(__start_rodata) = .; \
60987 *(.rodata) *(.rodata.*) \
60988+ *(.data..read_only) \
60989 *(__vermagic) /* Kernel version magic */ \
60990 . = ALIGN(8); \
60991 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60992@@ -716,17 +717,18 @@
60993 * section in the linker script will go there too. @phdr should have
60994 * a leading colon.
60995 *
60996- * Note that this macros defines __per_cpu_load as an absolute symbol.
60997+ * Note that this macros defines per_cpu_load as an absolute symbol.
60998 * If there is no need to put the percpu section at a predetermined
60999 * address, use PERCPU_SECTION.
61000 */
61001 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61002- VMLINUX_SYMBOL(__per_cpu_load) = .; \
61003- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61004+ per_cpu_load = .; \
61005+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61006 - LOAD_OFFSET) { \
61007+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61008 PERCPU_INPUT(cacheline) \
61009 } phdr \
61010- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61011+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61012
61013 /**
61014 * PERCPU_SECTION - define output section for percpu area, simple version
61015diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61016index 31ad880..4e79884 100644
61017--- a/include/drm/drmP.h
61018+++ b/include/drm/drmP.h
61019@@ -72,6 +72,7 @@
61020 #include <linux/workqueue.h>
61021 #include <linux/poll.h>
61022 #include <asm/pgalloc.h>
61023+#include <asm/local.h>
61024 #include "drm.h"
61025
61026 #include <linux/idr.h>
61027@@ -1074,7 +1075,7 @@ struct drm_device {
61028
61029 /** \name Usage Counters */
61030 /*@{ */
61031- int open_count; /**< Outstanding files open */
61032+ local_t open_count; /**< Outstanding files open */
61033 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61034 atomic_t vma_count; /**< Outstanding vma areas open */
61035 int buf_use; /**< Buffers in use -- cannot alloc */
61036@@ -1085,7 +1086,7 @@ struct drm_device {
61037 /*@{ */
61038 unsigned long counters;
61039 enum drm_stat_type types[15];
61040- atomic_t counts[15];
61041+ atomic_unchecked_t counts[15];
61042 /*@} */
61043
61044 struct list_head filelist;
61045diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61046index 7988e55..ec974c9 100644
61047--- a/include/drm/drm_crtc_helper.h
61048+++ b/include/drm/drm_crtc_helper.h
61049@@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61050
61051 /* disable crtc when not in use - more explicit than dpms off */
61052 void (*disable)(struct drm_crtc *crtc);
61053-};
61054+} __no_const;
61055
61056 /**
61057 * drm_encoder_helper_funcs - helper operations for encoders
61058@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61059 struct drm_connector *connector);
61060 /* disable encoder when not in use - more explicit than dpms off */
61061 void (*disable)(struct drm_encoder *encoder);
61062-};
61063+} __no_const;
61064
61065 /**
61066 * drm_connector_helper_funcs - helper operations for connectors
61067diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61068index d6d1da4..fdd1ac5 100644
61069--- a/include/drm/ttm/ttm_memory.h
61070+++ b/include/drm/ttm/ttm_memory.h
61071@@ -48,7 +48,7 @@
61072
61073 struct ttm_mem_shrink {
61074 int (*do_shrink) (struct ttm_mem_shrink *);
61075-};
61076+} __no_const;
61077
61078 /**
61079 * struct ttm_mem_global - Global memory accounting structure.
61080diff --git a/include/linux/a.out.h b/include/linux/a.out.h
61081index e86dfca..40cc55f 100644
61082--- a/include/linux/a.out.h
61083+++ b/include/linux/a.out.h
61084@@ -39,6 +39,14 @@ enum machine_type {
61085 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61086 };
61087
61088+/* Constants for the N_FLAGS field */
61089+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61090+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61091+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61092+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61093+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61094+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61095+
61096 #if !defined (N_MAGIC)
61097 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61098 #endif
61099diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61100index 06fd4bb..1caec0d 100644
61101--- a/include/linux/atmdev.h
61102+++ b/include/linux/atmdev.h
61103@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61104 #endif
61105
61106 struct k_atm_aal_stats {
61107-#define __HANDLE_ITEM(i) atomic_t i
61108+#define __HANDLE_ITEM(i) atomic_unchecked_t i
61109 __AAL_STAT_ITEMS
61110 #undef __HANDLE_ITEM
61111 };
61112diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61113index 366422b..1fa7f84 100644
61114--- a/include/linux/binfmts.h
61115+++ b/include/linux/binfmts.h
61116@@ -89,6 +89,7 @@ struct linux_binfmt {
61117 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61118 int (*load_shlib)(struct file *);
61119 int (*core_dump)(struct coredump_params *cprm);
61120+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61121 unsigned long min_coredump; /* minimal dump size */
61122 };
61123
61124diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61125index 07954b0..cb2ae71 100644
61126--- a/include/linux/blkdev.h
61127+++ b/include/linux/blkdev.h
61128@@ -1393,7 +1393,7 @@ struct block_device_operations {
61129 /* this callback is with swap_lock and sometimes page table lock held */
61130 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61131 struct module *owner;
61132-};
61133+} __do_const;
61134
61135 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61136 unsigned long);
61137diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61138index 4d1a074..88f929a 100644
61139--- a/include/linux/blktrace_api.h
61140+++ b/include/linux/blktrace_api.h
61141@@ -162,7 +162,7 @@ struct blk_trace {
61142 struct dentry *dir;
61143 struct dentry *dropped_file;
61144 struct dentry *msg_file;
61145- atomic_t dropped;
61146+ atomic_unchecked_t dropped;
61147 };
61148
61149 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61150diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61151index 83195fb..0b0f77d 100644
61152--- a/include/linux/byteorder/little_endian.h
61153+++ b/include/linux/byteorder/little_endian.h
61154@@ -42,51 +42,51 @@
61155
61156 static inline __le64 __cpu_to_le64p(const __u64 *p)
61157 {
61158- return (__force __le64)*p;
61159+ return (__force const __le64)*p;
61160 }
61161 static inline __u64 __le64_to_cpup(const __le64 *p)
61162 {
61163- return (__force __u64)*p;
61164+ return (__force const __u64)*p;
61165 }
61166 static inline __le32 __cpu_to_le32p(const __u32 *p)
61167 {
61168- return (__force __le32)*p;
61169+ return (__force const __le32)*p;
61170 }
61171 static inline __u32 __le32_to_cpup(const __le32 *p)
61172 {
61173- return (__force __u32)*p;
61174+ return (__force const __u32)*p;
61175 }
61176 static inline __le16 __cpu_to_le16p(const __u16 *p)
61177 {
61178- return (__force __le16)*p;
61179+ return (__force const __le16)*p;
61180 }
61181 static inline __u16 __le16_to_cpup(const __le16 *p)
61182 {
61183- return (__force __u16)*p;
61184+ return (__force const __u16)*p;
61185 }
61186 static inline __be64 __cpu_to_be64p(const __u64 *p)
61187 {
61188- return (__force __be64)__swab64p(p);
61189+ return (__force const __be64)__swab64p(p);
61190 }
61191 static inline __u64 __be64_to_cpup(const __be64 *p)
61192 {
61193- return __swab64p((__u64 *)p);
61194+ return __swab64p((const __u64 *)p);
61195 }
61196 static inline __be32 __cpu_to_be32p(const __u32 *p)
61197 {
61198- return (__force __be32)__swab32p(p);
61199+ return (__force const __be32)__swab32p(p);
61200 }
61201 static inline __u32 __be32_to_cpup(const __be32 *p)
61202 {
61203- return __swab32p((__u32 *)p);
61204+ return __swab32p((const __u32 *)p);
61205 }
61206 static inline __be16 __cpu_to_be16p(const __u16 *p)
61207 {
61208- return (__force __be16)__swab16p(p);
61209+ return (__force const __be16)__swab16p(p);
61210 }
61211 static inline __u16 __be16_to_cpup(const __be16 *p)
61212 {
61213- return __swab16p((__u16 *)p);
61214+ return __swab16p((const __u16 *)p);
61215 }
61216 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61217 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61218diff --git a/include/linux/cache.h b/include/linux/cache.h
61219index 4c57065..4307975 100644
61220--- a/include/linux/cache.h
61221+++ b/include/linux/cache.h
61222@@ -16,6 +16,10 @@
61223 #define __read_mostly
61224 #endif
61225
61226+#ifndef __read_only
61227+#define __read_only __read_mostly
61228+#endif
61229+
61230 #ifndef ____cacheline_aligned
61231 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61232 #endif
61233diff --git a/include/linux/capability.h b/include/linux/capability.h
61234index d10b7ed..0288b79 100644
61235--- a/include/linux/capability.h
61236+++ b/include/linux/capability.h
61237@@ -553,10 +553,15 @@ extern bool capable(int cap);
61238 extern bool ns_capable(struct user_namespace *ns, int cap);
61239 extern bool nsown_capable(int cap);
61240 extern bool inode_capable(const struct inode *inode, int cap);
61241+extern bool capable_nolog(int cap);
61242+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61243+extern bool inode_capable_nolog(const struct inode *inode, int cap);
61244
61245 /* audit system wants to get cap info from files as well */
61246 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61247
61248+extern int is_privileged_binary(const struct dentry *dentry);
61249+
61250 #endif /* __KERNEL__ */
61251
61252 #endif /* !_LINUX_CAPABILITY_H */
61253diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61254index 42e55de..1cd0e66 100644
61255--- a/include/linux/cleancache.h
61256+++ b/include/linux/cleancache.h
61257@@ -31,7 +31,7 @@ struct cleancache_ops {
61258 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61259 void (*invalidate_inode)(int, struct cleancache_filekey);
61260 void (*invalidate_fs)(int);
61261-};
61262+} __no_const;
61263
61264 extern struct cleancache_ops
61265 cleancache_register_ops(struct cleancache_ops *ops);
61266diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61267index 4a0b483..f1f70ba 100644
61268--- a/include/linux/clk-provider.h
61269+++ b/include/linux/clk-provider.h
61270@@ -110,6 +110,7 @@ struct clk_ops {
61271 unsigned long);
61272 void (*init)(struct clk_hw *hw);
61273 };
61274+typedef struct clk_ops __no_const clk_ops_no_const;
61275
61276 /**
61277 * struct clk_init_data - holds init data that's common to all clocks and is
61278diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61279index 2f40791..938880e 100644
61280--- a/include/linux/compiler-gcc4.h
61281+++ b/include/linux/compiler-gcc4.h
61282@@ -32,6 +32,21 @@
61283 #define __linktime_error(message) __attribute__((__error__(message)))
61284
61285 #if __GNUC_MINOR__ >= 5
61286+
61287+#ifdef CONSTIFY_PLUGIN
61288+#define __no_const __attribute__((no_const))
61289+#define __do_const __attribute__((do_const))
61290+#endif
61291+
61292+#ifdef SIZE_OVERFLOW_PLUGIN
61293+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61294+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61295+#endif
61296+
61297+#ifdef LATENT_ENTROPY_PLUGIN
61298+#define __latent_entropy __attribute__((latent_entropy))
61299+#endif
61300+
61301 /*
61302 * Mark a position in code as unreachable. This can be used to
61303 * suppress control flow warnings after asm blocks that transfer
61304@@ -47,6 +62,11 @@
61305 #define __noclone __attribute__((__noclone__))
61306
61307 #endif
61308+
61309+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61310+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61311+#define __bos0(ptr) __bos((ptr), 0)
61312+#define __bos1(ptr) __bos((ptr), 1)
61313 #endif
61314
61315 #if __GNUC_MINOR__ > 0
61316diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61317index 923d093..3625de1 100644
61318--- a/include/linux/compiler.h
61319+++ b/include/linux/compiler.h
61320@@ -5,31 +5,62 @@
61321
61322 #ifdef __CHECKER__
61323 # define __user __attribute__((noderef, address_space(1)))
61324+# define __force_user __force __user
61325 # define __kernel __attribute__((address_space(0)))
61326+# define __force_kernel __force __kernel
61327 # define __safe __attribute__((safe))
61328 # define __force __attribute__((force))
61329 # define __nocast __attribute__((nocast))
61330 # define __iomem __attribute__((noderef, address_space(2)))
61331+# define __force_iomem __force __iomem
61332 # define __acquires(x) __attribute__((context(x,0,1)))
61333 # define __releases(x) __attribute__((context(x,1,0)))
61334 # define __acquire(x) __context__(x,1)
61335 # define __release(x) __context__(x,-1)
61336 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61337 # define __percpu __attribute__((noderef, address_space(3)))
61338+# define __force_percpu __force __percpu
61339 #ifdef CONFIG_SPARSE_RCU_POINTER
61340 # define __rcu __attribute__((noderef, address_space(4)))
61341+# define __force_rcu __force __rcu
61342 #else
61343 # define __rcu
61344+# define __force_rcu
61345 #endif
61346 extern void __chk_user_ptr(const volatile void __user *);
61347 extern void __chk_io_ptr(const volatile void __iomem *);
61348+#elif defined(CHECKER_PLUGIN)
61349+//# define __user
61350+//# define __force_user
61351+//# define __kernel
61352+//# define __force_kernel
61353+# define __safe
61354+# define __force
61355+# define __nocast
61356+# define __iomem
61357+# define __force_iomem
61358+# define __chk_user_ptr(x) (void)0
61359+# define __chk_io_ptr(x) (void)0
61360+# define __builtin_warning(x, y...) (1)
61361+# define __acquires(x)
61362+# define __releases(x)
61363+# define __acquire(x) (void)0
61364+# define __release(x) (void)0
61365+# define __cond_lock(x,c) (c)
61366+# define __percpu
61367+# define __force_percpu
61368+# define __rcu
61369+# define __force_rcu
61370 #else
61371 # define __user
61372+# define __force_user
61373 # define __kernel
61374+# define __force_kernel
61375 # define __safe
61376 # define __force
61377 # define __nocast
61378 # define __iomem
61379+# define __force_iomem
61380 # define __chk_user_ptr(x) (void)0
61381 # define __chk_io_ptr(x) (void)0
61382 # define __builtin_warning(x, y...) (1)
61383@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61384 # define __release(x) (void)0
61385 # define __cond_lock(x,c) (c)
61386 # define __percpu
61387+# define __force_percpu
61388 # define __rcu
61389+# define __force_rcu
61390 #endif
61391
61392 #ifdef __KERNEL__
61393@@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61394 # define __attribute_const__ /* unimplemented */
61395 #endif
61396
61397+#ifndef __no_const
61398+# define __no_const
61399+#endif
61400+
61401+#ifndef __do_const
61402+# define __do_const
61403+#endif
61404+
61405+#ifndef __size_overflow
61406+# define __size_overflow(...)
61407+#endif
61408+
61409+#ifndef __latent_entropy
61410+# define __latent_entropy
61411+#endif
61412+
61413+#ifndef __intentional_overflow
61414+# define __intentional_overflow(...)
61415+#endif
61416+
61417 /*
61418 * Tell gcc if a function is cold. The compiler will assume any path
61419 * directly leading to the call is unlikely.
61420@@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61421 #define __cold
61422 #endif
61423
61424+#ifndef __alloc_size
61425+#define __alloc_size(...)
61426+#endif
61427+
61428+#ifndef __bos
61429+#define __bos(ptr, arg)
61430+#endif
61431+
61432+#ifndef __bos0
61433+#define __bos0(ptr)
61434+#endif
61435+
61436+#ifndef __bos1
61437+#define __bos1(ptr)
61438+#endif
61439+
61440 /* Simple shorthand for a section definition */
61441 #ifndef __section
61442 # define __section(S) __attribute__ ((__section__(#S)))
61443@@ -308,6 +377,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61444 * use is to mediate communication between process-level code and irq/NMI
61445 * handlers, all running on the same CPU.
61446 */
61447-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61448+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61449+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61450
61451 #endif /* __LINUX_COMPILER_H */
61452diff --git a/include/linux/cred.h b/include/linux/cred.h
61453index ebbed2c..908cc2c 100644
61454--- a/include/linux/cred.h
61455+++ b/include/linux/cred.h
61456@@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61457 static inline void validate_process_creds(void)
61458 {
61459 }
61460+static inline void validate_task_creds(struct task_struct *task)
61461+{
61462+}
61463 #endif
61464
61465 /**
61466diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61467index b92eadf..b4ecdc1 100644
61468--- a/include/linux/crypto.h
61469+++ b/include/linux/crypto.h
61470@@ -373,7 +373,7 @@ struct cipher_tfm {
61471 const u8 *key, unsigned int keylen);
61472 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61473 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61474-};
61475+} __no_const;
61476
61477 struct hash_tfm {
61478 int (*init)(struct hash_desc *desc);
61479@@ -394,13 +394,13 @@ struct compress_tfm {
61480 int (*cot_decompress)(struct crypto_tfm *tfm,
61481 const u8 *src, unsigned int slen,
61482 u8 *dst, unsigned int *dlen);
61483-};
61484+} __no_const;
61485
61486 struct rng_tfm {
61487 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61488 unsigned int dlen);
61489 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61490-};
61491+} __no_const;
61492
61493 #define crt_ablkcipher crt_u.ablkcipher
61494 #define crt_aead crt_u.aead
61495diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61496index 7925bf0..d5143d2 100644
61497--- a/include/linux/decompress/mm.h
61498+++ b/include/linux/decompress/mm.h
61499@@ -77,7 +77,7 @@ static void free(void *where)
61500 * warnings when not needed (indeed large_malloc / large_free are not
61501 * needed by inflate */
61502
61503-#define malloc(a) kmalloc(a, GFP_KERNEL)
61504+#define malloc(a) kmalloc((a), GFP_KERNEL)
61505 #define free(a) kfree(a)
61506
61507 #define large_malloc(a) vmalloc(a)
61508diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61509index dfc099e..e583e66 100644
61510--- a/include/linux/dma-mapping.h
61511+++ b/include/linux/dma-mapping.h
61512@@ -51,7 +51,7 @@ struct dma_map_ops {
61513 u64 (*get_required_mask)(struct device *dev);
61514 #endif
61515 int is_phys;
61516-};
61517+} __do_const;
61518
61519 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61520
61521diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61522index 56377df..4eb4990 100644
61523--- a/include/linux/dmaengine.h
61524+++ b/include/linux/dmaengine.h
61525@@ -1007,9 +1007,9 @@ struct dma_pinned_list {
61526 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61527 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61528
61529-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61530+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61531 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61532-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61533+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61534 struct dma_pinned_list *pinned_list, struct page *page,
61535 unsigned int offset, size_t len);
61536
61537diff --git a/include/linux/efi.h b/include/linux/efi.h
61538index ec45ccd..9923c32 100644
61539--- a/include/linux/efi.h
61540+++ b/include/linux/efi.h
61541@@ -635,7 +635,7 @@ struct efivar_operations {
61542 efi_get_variable_t *get_variable;
61543 efi_get_next_variable_t *get_next_variable;
61544 efi_set_variable_t *set_variable;
61545-};
61546+} __no_const;
61547
61548 struct efivars {
61549 /*
61550diff --git a/include/linux/elf.h b/include/linux/elf.h
61551index 999b4f5..57753b4 100644
61552--- a/include/linux/elf.h
61553+++ b/include/linux/elf.h
61554@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61555 #define PT_GNU_EH_FRAME 0x6474e550
61556
61557 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61558+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61559+
61560+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61561+
61562+/* Constants for the e_flags field */
61563+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61564+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61565+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61566+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61567+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61568+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61569
61570 /*
61571 * Extended Numbering
61572@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61573 #define DT_DEBUG 21
61574 #define DT_TEXTREL 22
61575 #define DT_JMPREL 23
61576+#define DT_FLAGS 30
61577+ #define DF_TEXTREL 0x00000004
61578 #define DT_ENCODING 32
61579 #define OLD_DT_LOOS 0x60000000
61580 #define DT_LOOS 0x6000000d
61581@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61582 #define PF_W 0x2
61583 #define PF_X 0x1
61584
61585+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61586+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61587+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61588+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61589+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61590+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61591+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61592+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61593+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61594+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61595+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61596+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61597+
61598 typedef struct elf32_phdr{
61599 Elf32_Word p_type;
61600 Elf32_Off p_offset;
61601@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61602 #define EI_OSABI 7
61603 #define EI_PAD 8
61604
61605+#define EI_PAX 14
61606+
61607 #define ELFMAG0 0x7f /* EI_MAG */
61608 #define ELFMAG1 'E'
61609 #define ELFMAG2 'L'
61610@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61611 #define elf_note elf32_note
61612 #define elf_addr_t Elf32_Off
61613 #define Elf_Half Elf32_Half
61614+#define elf_dyn Elf32_Dyn
61615
61616 #else
61617
61618@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61619 #define elf_note elf64_note
61620 #define elf_addr_t Elf64_Off
61621 #define Elf_Half Elf64_Half
61622+#define elf_dyn Elf64_Dyn
61623
61624 #endif
61625
61626diff --git a/include/linux/filter.h b/include/linux/filter.h
61627index 82b0135..917914d 100644
61628--- a/include/linux/filter.h
61629+++ b/include/linux/filter.h
61630@@ -146,6 +146,7 @@ struct compat_sock_fprog {
61631
61632 struct sk_buff;
61633 struct sock;
61634+struct bpf_jit_work;
61635
61636 struct sk_filter
61637 {
61638@@ -153,6 +154,9 @@ struct sk_filter
61639 unsigned int len; /* Number of filter blocks */
61640 unsigned int (*bpf_func)(const struct sk_buff *skb,
61641 const struct sock_filter *filter);
61642+#ifdef CONFIG_BPF_JIT
61643+ struct bpf_jit_work *work;
61644+#endif
61645 struct rcu_head rcu;
61646 struct sock_filter insns[0];
61647 };
61648diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61649index 7edcf10..714d5e8 100644
61650--- a/include/linux/firewire.h
61651+++ b/include/linux/firewire.h
61652@@ -430,7 +430,7 @@ struct fw_iso_context {
61653 union {
61654 fw_iso_callback_t sc;
61655 fw_iso_mc_callback_t mc;
61656- } callback;
61657+ } __no_const callback;
61658 void *callback_data;
61659 };
61660
61661diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61662index 0e4e2ee..4ff4312 100644
61663--- a/include/linux/frontswap.h
61664+++ b/include/linux/frontswap.h
61665@@ -11,7 +11,7 @@ struct frontswap_ops {
61666 int (*load)(unsigned, pgoff_t, struct page *);
61667 void (*invalidate_page)(unsigned, pgoff_t);
61668 void (*invalidate_area)(unsigned);
61669-};
61670+} __no_const;
61671
61672 extern bool frontswap_enabled;
61673 extern struct frontswap_ops
61674diff --git a/include/linux/fs.h b/include/linux/fs.h
61675index 17fd887..8eebca0 100644
61676--- a/include/linux/fs.h
61677+++ b/include/linux/fs.h
61678@@ -1663,7 +1663,8 @@ struct file_operations {
61679 int (*setlease)(struct file *, long, struct file_lock **);
61680 long (*fallocate)(struct file *file, int mode, loff_t offset,
61681 loff_t len);
61682-};
61683+} __do_const;
61684+typedef struct file_operations __no_const file_operations_no_const;
61685
61686 struct inode_operations {
61687 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
61688diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61689index 003dc0f..3c4ea97 100644
61690--- a/include/linux/fs_struct.h
61691+++ b/include/linux/fs_struct.h
61692@@ -6,7 +6,7 @@
61693 #include <linux/seqlock.h>
61694
61695 struct fs_struct {
61696- int users;
61697+ atomic_t users;
61698 spinlock_t lock;
61699 seqcount_t seq;
61700 int umask;
61701diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61702index ce31408..b1ad003 100644
61703--- a/include/linux/fscache-cache.h
61704+++ b/include/linux/fscache-cache.h
61705@@ -102,7 +102,7 @@ struct fscache_operation {
61706 fscache_operation_release_t release;
61707 };
61708
61709-extern atomic_t fscache_op_debug_id;
61710+extern atomic_unchecked_t fscache_op_debug_id;
61711 extern void fscache_op_work_func(struct work_struct *work);
61712
61713 extern void fscache_enqueue_operation(struct fscache_operation *);
61714@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61715 {
61716 INIT_WORK(&op->work, fscache_op_work_func);
61717 atomic_set(&op->usage, 1);
61718- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61719+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61720 op->processor = processor;
61721 op->release = release;
61722 INIT_LIST_HEAD(&op->pend_link);
61723diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61724index a6dfe69..569586df 100644
61725--- a/include/linux/fsnotify.h
61726+++ b/include/linux/fsnotify.h
61727@@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61728 */
61729 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61730 {
61731- return kstrdup(name, GFP_KERNEL);
61732+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61733 }
61734
61735 /*
61736diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61737index 63d966d..cdcb717 100644
61738--- a/include/linux/fsnotify_backend.h
61739+++ b/include/linux/fsnotify_backend.h
61740@@ -105,6 +105,7 @@ struct fsnotify_ops {
61741 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61742 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61743 };
61744+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61745
61746 /*
61747 * A group is a "thing" that wants to receive notification about filesystem
61748diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61749index 176a939..1462211 100644
61750--- a/include/linux/ftrace_event.h
61751+++ b/include/linux/ftrace_event.h
61752@@ -97,7 +97,7 @@ struct trace_event_functions {
61753 trace_print_func raw;
61754 trace_print_func hex;
61755 trace_print_func binary;
61756-};
61757+} __no_const;
61758
61759 struct trace_event {
61760 struct hlist_node node;
61761@@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61762 extern int trace_add_event_call(struct ftrace_event_call *call);
61763 extern void trace_remove_event_call(struct ftrace_event_call *call);
61764
61765-#define is_signed_type(type) (((type)(-1)) < 0)
61766+#define is_signed_type(type) (((type)(-1)) < (type)1)
61767
61768 int trace_set_clr_event(const char *system, const char *event, int set);
61769
61770diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61771index 017a7fb..33a8507 100644
61772--- a/include/linux/genhd.h
61773+++ b/include/linux/genhd.h
61774@@ -185,7 +185,7 @@ struct gendisk {
61775 struct kobject *slave_dir;
61776
61777 struct timer_rand_state *random;
61778- atomic_t sync_io; /* RAID */
61779+ atomic_unchecked_t sync_io; /* RAID */
61780 struct disk_events *ev;
61781 #ifdef CONFIG_BLK_DEV_INTEGRITY
61782 struct blk_integrity *integrity;
61783diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61784index 1e49be4..b8a9305 100644
61785--- a/include/linux/gfp.h
61786+++ b/include/linux/gfp.h
61787@@ -38,6 +38,12 @@ struct vm_area_struct;
61788 #define ___GFP_OTHER_NODE 0x800000u
61789 #define ___GFP_WRITE 0x1000000u
61790
61791+#ifdef CONFIG_PAX_USERCOPY_SLABS
61792+#define ___GFP_USERCOPY 0x2000000u
61793+#else
61794+#define ___GFP_USERCOPY 0
61795+#endif
61796+
61797 /*
61798 * GFP bitmasks..
61799 *
61800@@ -87,6 +93,7 @@ struct vm_area_struct;
61801 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61802 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61803 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61804+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61805
61806 /*
61807 * This may seem redundant, but it's a way of annotating false positives vs.
61808@@ -94,7 +101,7 @@ struct vm_area_struct;
61809 */
61810 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61811
61812-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61813+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61814 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61815
61816 /* This equals 0, but use constants in case they ever change */
61817@@ -148,6 +155,8 @@ struct vm_area_struct;
61818 /* 4GB DMA on some platforms */
61819 #define GFP_DMA32 __GFP_DMA32
61820
61821+#define GFP_USERCOPY __GFP_USERCOPY
61822+
61823 /* Convert GFP flags to their corresponding migrate type */
61824 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61825 {
61826diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61827new file mode 100644
61828index 0000000..c938b1f
61829--- /dev/null
61830+++ b/include/linux/gracl.h
61831@@ -0,0 +1,319 @@
61832+#ifndef GR_ACL_H
61833+#define GR_ACL_H
61834+
61835+#include <linux/grdefs.h>
61836+#include <linux/resource.h>
61837+#include <linux/capability.h>
61838+#include <linux/dcache.h>
61839+#include <asm/resource.h>
61840+
61841+/* Major status information */
61842+
61843+#define GR_VERSION "grsecurity 2.9.1"
61844+#define GRSECURITY_VERSION 0x2901
61845+
61846+enum {
61847+ GR_SHUTDOWN = 0,
61848+ GR_ENABLE = 1,
61849+ GR_SPROLE = 2,
61850+ GR_RELOAD = 3,
61851+ GR_SEGVMOD = 4,
61852+ GR_STATUS = 5,
61853+ GR_UNSPROLE = 6,
61854+ GR_PASSSET = 7,
61855+ GR_SPROLEPAM = 8,
61856+};
61857+
61858+/* Password setup definitions
61859+ * kernel/grhash.c */
61860+enum {
61861+ GR_PW_LEN = 128,
61862+ GR_SALT_LEN = 16,
61863+ GR_SHA_LEN = 32,
61864+};
61865+
61866+enum {
61867+ GR_SPROLE_LEN = 64,
61868+};
61869+
61870+enum {
61871+ GR_NO_GLOB = 0,
61872+ GR_REG_GLOB,
61873+ GR_CREATE_GLOB
61874+};
61875+
61876+#define GR_NLIMITS 32
61877+
61878+/* Begin Data Structures */
61879+
61880+struct sprole_pw {
61881+ unsigned char *rolename;
61882+ unsigned char salt[GR_SALT_LEN];
61883+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61884+};
61885+
61886+struct name_entry {
61887+ __u32 key;
61888+ ino_t inode;
61889+ dev_t device;
61890+ char *name;
61891+ __u16 len;
61892+ __u8 deleted;
61893+ struct name_entry *prev;
61894+ struct name_entry *next;
61895+};
61896+
61897+struct inodev_entry {
61898+ struct name_entry *nentry;
61899+ struct inodev_entry *prev;
61900+ struct inodev_entry *next;
61901+};
61902+
61903+struct acl_role_db {
61904+ struct acl_role_label **r_hash;
61905+ __u32 r_size;
61906+};
61907+
61908+struct inodev_db {
61909+ struct inodev_entry **i_hash;
61910+ __u32 i_size;
61911+};
61912+
61913+struct name_db {
61914+ struct name_entry **n_hash;
61915+ __u32 n_size;
61916+};
61917+
61918+struct crash_uid {
61919+ uid_t uid;
61920+ unsigned long expires;
61921+};
61922+
61923+struct gr_hash_struct {
61924+ void **table;
61925+ void **nametable;
61926+ void *first;
61927+ __u32 table_size;
61928+ __u32 used_size;
61929+ int type;
61930+};
61931+
61932+/* Userspace Grsecurity ACL data structures */
61933+
61934+struct acl_subject_label {
61935+ char *filename;
61936+ ino_t inode;
61937+ dev_t device;
61938+ __u32 mode;
61939+ kernel_cap_t cap_mask;
61940+ kernel_cap_t cap_lower;
61941+ kernel_cap_t cap_invert_audit;
61942+
61943+ struct rlimit res[GR_NLIMITS];
61944+ __u32 resmask;
61945+
61946+ __u8 user_trans_type;
61947+ __u8 group_trans_type;
61948+ uid_t *user_transitions;
61949+ gid_t *group_transitions;
61950+ __u16 user_trans_num;
61951+ __u16 group_trans_num;
61952+
61953+ __u32 sock_families[2];
61954+ __u32 ip_proto[8];
61955+ __u32 ip_type;
61956+ struct acl_ip_label **ips;
61957+ __u32 ip_num;
61958+ __u32 inaddr_any_override;
61959+
61960+ __u32 crashes;
61961+ unsigned long expires;
61962+
61963+ struct acl_subject_label *parent_subject;
61964+ struct gr_hash_struct *hash;
61965+ struct acl_subject_label *prev;
61966+ struct acl_subject_label *next;
61967+
61968+ struct acl_object_label **obj_hash;
61969+ __u32 obj_hash_size;
61970+ __u16 pax_flags;
61971+};
61972+
61973+struct role_allowed_ip {
61974+ __u32 addr;
61975+ __u32 netmask;
61976+
61977+ struct role_allowed_ip *prev;
61978+ struct role_allowed_ip *next;
61979+};
61980+
61981+struct role_transition {
61982+ char *rolename;
61983+
61984+ struct role_transition *prev;
61985+ struct role_transition *next;
61986+};
61987+
61988+struct acl_role_label {
61989+ char *rolename;
61990+ uid_t uidgid;
61991+ __u16 roletype;
61992+
61993+ __u16 auth_attempts;
61994+ unsigned long expires;
61995+
61996+ struct acl_subject_label *root_label;
61997+ struct gr_hash_struct *hash;
61998+
61999+ struct acl_role_label *prev;
62000+ struct acl_role_label *next;
62001+
62002+ struct role_transition *transitions;
62003+ struct role_allowed_ip *allowed_ips;
62004+ uid_t *domain_children;
62005+ __u16 domain_child_num;
62006+
62007+ umode_t umask;
62008+
62009+ struct acl_subject_label **subj_hash;
62010+ __u32 subj_hash_size;
62011+};
62012+
62013+struct user_acl_role_db {
62014+ struct acl_role_label **r_table;
62015+ __u32 num_pointers; /* Number of allocations to track */
62016+ __u32 num_roles; /* Number of roles */
62017+ __u32 num_domain_children; /* Number of domain children */
62018+ __u32 num_subjects; /* Number of subjects */
62019+ __u32 num_objects; /* Number of objects */
62020+};
62021+
62022+struct acl_object_label {
62023+ char *filename;
62024+ ino_t inode;
62025+ dev_t device;
62026+ __u32 mode;
62027+
62028+ struct acl_subject_label *nested;
62029+ struct acl_object_label *globbed;
62030+
62031+ /* next two structures not used */
62032+
62033+ struct acl_object_label *prev;
62034+ struct acl_object_label *next;
62035+};
62036+
62037+struct acl_ip_label {
62038+ char *iface;
62039+ __u32 addr;
62040+ __u32 netmask;
62041+ __u16 low, high;
62042+ __u8 mode;
62043+ __u32 type;
62044+ __u32 proto[8];
62045+
62046+ /* next two structures not used */
62047+
62048+ struct acl_ip_label *prev;
62049+ struct acl_ip_label *next;
62050+};
62051+
62052+struct gr_arg {
62053+ struct user_acl_role_db role_db;
62054+ unsigned char pw[GR_PW_LEN];
62055+ unsigned char salt[GR_SALT_LEN];
62056+ unsigned char sum[GR_SHA_LEN];
62057+ unsigned char sp_role[GR_SPROLE_LEN];
62058+ struct sprole_pw *sprole_pws;
62059+ dev_t segv_device;
62060+ ino_t segv_inode;
62061+ uid_t segv_uid;
62062+ __u16 num_sprole_pws;
62063+ __u16 mode;
62064+};
62065+
62066+struct gr_arg_wrapper {
62067+ struct gr_arg *arg;
62068+ __u32 version;
62069+ __u32 size;
62070+};
62071+
62072+struct subject_map {
62073+ struct acl_subject_label *user;
62074+ struct acl_subject_label *kernel;
62075+ struct subject_map *prev;
62076+ struct subject_map *next;
62077+};
62078+
62079+struct acl_subj_map_db {
62080+ struct subject_map **s_hash;
62081+ __u32 s_size;
62082+};
62083+
62084+/* End Data Structures Section */
62085+
62086+/* Hash functions generated by empirical testing by Brad Spengler
62087+ Makes good use of the low bits of the inode. Generally 0-1 times
62088+ in loop for successful match. 0-3 for unsuccessful match.
62089+ Shift/add algorithm with modulus of table size and an XOR*/
62090+
62091+static __inline__ unsigned int
62092+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62093+{
62094+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
62095+}
62096+
62097+ static __inline__ unsigned int
62098+shash(const struct acl_subject_label *userp, const unsigned int sz)
62099+{
62100+ return ((const unsigned long)userp % sz);
62101+}
62102+
62103+static __inline__ unsigned int
62104+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62105+{
62106+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62107+}
62108+
62109+static __inline__ unsigned int
62110+nhash(const char *name, const __u16 len, const unsigned int sz)
62111+{
62112+ return full_name_hash((const unsigned char *)name, len) % sz;
62113+}
62114+
62115+#define FOR_EACH_ROLE_START(role) \
62116+ role = role_list; \
62117+ while (role) {
62118+
62119+#define FOR_EACH_ROLE_END(role) \
62120+ role = role->prev; \
62121+ }
62122+
62123+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62124+ subj = NULL; \
62125+ iter = 0; \
62126+ while (iter < role->subj_hash_size) { \
62127+ if (subj == NULL) \
62128+ subj = role->subj_hash[iter]; \
62129+ if (subj == NULL) { \
62130+ iter++; \
62131+ continue; \
62132+ }
62133+
62134+#define FOR_EACH_SUBJECT_END(subj,iter) \
62135+ subj = subj->next; \
62136+ if (subj == NULL) \
62137+ iter++; \
62138+ }
62139+
62140+
62141+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62142+ subj = role->hash->first; \
62143+ while (subj != NULL) {
62144+
62145+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62146+ subj = subj->next; \
62147+ }
62148+
62149+#endif
62150+
62151diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62152new file mode 100644
62153index 0000000..323ecf2
62154--- /dev/null
62155+++ b/include/linux/gralloc.h
62156@@ -0,0 +1,9 @@
62157+#ifndef __GRALLOC_H
62158+#define __GRALLOC_H
62159+
62160+void acl_free_all(void);
62161+int acl_alloc_stack_init(unsigned long size);
62162+void *acl_alloc(unsigned long len);
62163+void *acl_alloc_num(unsigned long num, unsigned long len);
62164+
62165+#endif
62166diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62167new file mode 100644
62168index 0000000..b30e9bc
62169--- /dev/null
62170+++ b/include/linux/grdefs.h
62171@@ -0,0 +1,140 @@
62172+#ifndef GRDEFS_H
62173+#define GRDEFS_H
62174+
62175+/* Begin grsecurity status declarations */
62176+
62177+enum {
62178+ GR_READY = 0x01,
62179+ GR_STATUS_INIT = 0x00 // disabled state
62180+};
62181+
62182+/* Begin ACL declarations */
62183+
62184+/* Role flags */
62185+
62186+enum {
62187+ GR_ROLE_USER = 0x0001,
62188+ GR_ROLE_GROUP = 0x0002,
62189+ GR_ROLE_DEFAULT = 0x0004,
62190+ GR_ROLE_SPECIAL = 0x0008,
62191+ GR_ROLE_AUTH = 0x0010,
62192+ GR_ROLE_NOPW = 0x0020,
62193+ GR_ROLE_GOD = 0x0040,
62194+ GR_ROLE_LEARN = 0x0080,
62195+ GR_ROLE_TPE = 0x0100,
62196+ GR_ROLE_DOMAIN = 0x0200,
62197+ GR_ROLE_PAM = 0x0400,
62198+ GR_ROLE_PERSIST = 0x0800
62199+};
62200+
62201+/* ACL Subject and Object mode flags */
62202+enum {
62203+ GR_DELETED = 0x80000000
62204+};
62205+
62206+/* ACL Object-only mode flags */
62207+enum {
62208+ GR_READ = 0x00000001,
62209+ GR_APPEND = 0x00000002,
62210+ GR_WRITE = 0x00000004,
62211+ GR_EXEC = 0x00000008,
62212+ GR_FIND = 0x00000010,
62213+ GR_INHERIT = 0x00000020,
62214+ GR_SETID = 0x00000040,
62215+ GR_CREATE = 0x00000080,
62216+ GR_DELETE = 0x00000100,
62217+ GR_LINK = 0x00000200,
62218+ GR_AUDIT_READ = 0x00000400,
62219+ GR_AUDIT_APPEND = 0x00000800,
62220+ GR_AUDIT_WRITE = 0x00001000,
62221+ GR_AUDIT_EXEC = 0x00002000,
62222+ GR_AUDIT_FIND = 0x00004000,
62223+ GR_AUDIT_INHERIT= 0x00008000,
62224+ GR_AUDIT_SETID = 0x00010000,
62225+ GR_AUDIT_CREATE = 0x00020000,
62226+ GR_AUDIT_DELETE = 0x00040000,
62227+ GR_AUDIT_LINK = 0x00080000,
62228+ GR_PTRACERD = 0x00100000,
62229+ GR_NOPTRACE = 0x00200000,
62230+ GR_SUPPRESS = 0x00400000,
62231+ GR_NOLEARN = 0x00800000,
62232+ GR_INIT_TRANSFER= 0x01000000
62233+};
62234+
62235+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62236+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62237+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62238+
62239+/* ACL subject-only mode flags */
62240+enum {
62241+ GR_KILL = 0x00000001,
62242+ GR_VIEW = 0x00000002,
62243+ GR_PROTECTED = 0x00000004,
62244+ GR_LEARN = 0x00000008,
62245+ GR_OVERRIDE = 0x00000010,
62246+ /* just a placeholder, this mode is only used in userspace */
62247+ GR_DUMMY = 0x00000020,
62248+ GR_PROTSHM = 0x00000040,
62249+ GR_KILLPROC = 0x00000080,
62250+ GR_KILLIPPROC = 0x00000100,
62251+ /* just a placeholder, this mode is only used in userspace */
62252+ GR_NOTROJAN = 0x00000200,
62253+ GR_PROTPROCFD = 0x00000400,
62254+ GR_PROCACCT = 0x00000800,
62255+ GR_RELAXPTRACE = 0x00001000,
62256+ GR_NESTED = 0x00002000,
62257+ GR_INHERITLEARN = 0x00004000,
62258+ GR_PROCFIND = 0x00008000,
62259+ GR_POVERRIDE = 0x00010000,
62260+ GR_KERNELAUTH = 0x00020000,
62261+ GR_ATSECURE = 0x00040000,
62262+ GR_SHMEXEC = 0x00080000
62263+};
62264+
62265+enum {
62266+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62267+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62268+ GR_PAX_ENABLE_MPROTECT = 0x0004,
62269+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
62270+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62271+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62272+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62273+ GR_PAX_DISABLE_MPROTECT = 0x0400,
62274+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
62275+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62276+};
62277+
62278+enum {
62279+ GR_ID_USER = 0x01,
62280+ GR_ID_GROUP = 0x02,
62281+};
62282+
62283+enum {
62284+ GR_ID_ALLOW = 0x01,
62285+ GR_ID_DENY = 0x02,
62286+};
62287+
62288+#define GR_CRASH_RES 31
62289+#define GR_UIDTABLE_MAX 500
62290+
62291+/* begin resource learning section */
62292+enum {
62293+ GR_RLIM_CPU_BUMP = 60,
62294+ GR_RLIM_FSIZE_BUMP = 50000,
62295+ GR_RLIM_DATA_BUMP = 10000,
62296+ GR_RLIM_STACK_BUMP = 1000,
62297+ GR_RLIM_CORE_BUMP = 10000,
62298+ GR_RLIM_RSS_BUMP = 500000,
62299+ GR_RLIM_NPROC_BUMP = 1,
62300+ GR_RLIM_NOFILE_BUMP = 5,
62301+ GR_RLIM_MEMLOCK_BUMP = 50000,
62302+ GR_RLIM_AS_BUMP = 500000,
62303+ GR_RLIM_LOCKS_BUMP = 2,
62304+ GR_RLIM_SIGPENDING_BUMP = 5,
62305+ GR_RLIM_MSGQUEUE_BUMP = 10000,
62306+ GR_RLIM_NICE_BUMP = 1,
62307+ GR_RLIM_RTPRIO_BUMP = 1,
62308+ GR_RLIM_RTTIME_BUMP = 1000000
62309+};
62310+
62311+#endif
62312diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62313new file mode 100644
62314index 0000000..c9292f7
62315--- /dev/null
62316+++ b/include/linux/grinternal.h
62317@@ -0,0 +1,223 @@
62318+#ifndef __GRINTERNAL_H
62319+#define __GRINTERNAL_H
62320+
62321+#ifdef CONFIG_GRKERNSEC
62322+
62323+#include <linux/fs.h>
62324+#include <linux/mnt_namespace.h>
62325+#include <linux/nsproxy.h>
62326+#include <linux/gracl.h>
62327+#include <linux/grdefs.h>
62328+#include <linux/grmsg.h>
62329+
62330+void gr_add_learn_entry(const char *fmt, ...)
62331+ __attribute__ ((format (printf, 1, 2)));
62332+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62333+ const struct vfsmount *mnt);
62334+__u32 gr_check_create(const struct dentry *new_dentry,
62335+ const struct dentry *parent,
62336+ const struct vfsmount *mnt, const __u32 mode);
62337+int gr_check_protected_task(const struct task_struct *task);
62338+__u32 to_gr_audit(const __u32 reqmode);
62339+int gr_set_acls(const int type);
62340+int gr_apply_subject_to_task(struct task_struct *task);
62341+int gr_acl_is_enabled(void);
62342+char gr_roletype_to_char(void);
62343+
62344+void gr_handle_alertkill(struct task_struct *task);
62345+char *gr_to_filename(const struct dentry *dentry,
62346+ const struct vfsmount *mnt);
62347+char *gr_to_filename1(const struct dentry *dentry,
62348+ const struct vfsmount *mnt);
62349+char *gr_to_filename2(const struct dentry *dentry,
62350+ const struct vfsmount *mnt);
62351+char *gr_to_filename3(const struct dentry *dentry,
62352+ const struct vfsmount *mnt);
62353+
62354+extern int grsec_enable_ptrace_readexec;
62355+extern int grsec_enable_harden_ptrace;
62356+extern int grsec_enable_link;
62357+extern int grsec_enable_fifo;
62358+extern int grsec_enable_execve;
62359+extern int grsec_enable_shm;
62360+extern int grsec_enable_execlog;
62361+extern int grsec_enable_signal;
62362+extern int grsec_enable_audit_ptrace;
62363+extern int grsec_enable_forkfail;
62364+extern int grsec_enable_time;
62365+extern int grsec_enable_rofs;
62366+extern int grsec_enable_chroot_shmat;
62367+extern int grsec_enable_chroot_mount;
62368+extern int grsec_enable_chroot_double;
62369+extern int grsec_enable_chroot_pivot;
62370+extern int grsec_enable_chroot_chdir;
62371+extern int grsec_enable_chroot_chmod;
62372+extern int grsec_enable_chroot_mknod;
62373+extern int grsec_enable_chroot_fchdir;
62374+extern int grsec_enable_chroot_nice;
62375+extern int grsec_enable_chroot_execlog;
62376+extern int grsec_enable_chroot_caps;
62377+extern int grsec_enable_chroot_sysctl;
62378+extern int grsec_enable_chroot_unix;
62379+extern int grsec_enable_symlinkown;
62380+extern int grsec_symlinkown_gid;
62381+extern int grsec_enable_tpe;
62382+extern int grsec_tpe_gid;
62383+extern int grsec_enable_tpe_all;
62384+extern int grsec_enable_tpe_invert;
62385+extern int grsec_enable_socket_all;
62386+extern int grsec_socket_all_gid;
62387+extern int grsec_enable_socket_client;
62388+extern int grsec_socket_client_gid;
62389+extern int grsec_enable_socket_server;
62390+extern int grsec_socket_server_gid;
62391+extern int grsec_audit_gid;
62392+extern int grsec_enable_group;
62393+extern int grsec_enable_audit_textrel;
62394+extern int grsec_enable_log_rwxmaps;
62395+extern int grsec_enable_mount;
62396+extern int grsec_enable_chdir;
62397+extern int grsec_resource_logging;
62398+extern int grsec_enable_blackhole;
62399+extern int grsec_lastack_retries;
62400+extern int grsec_enable_brute;
62401+extern int grsec_lock;
62402+
62403+extern spinlock_t grsec_alert_lock;
62404+extern unsigned long grsec_alert_wtime;
62405+extern unsigned long grsec_alert_fyet;
62406+
62407+extern spinlock_t grsec_audit_lock;
62408+
62409+extern rwlock_t grsec_exec_file_lock;
62410+
62411+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62412+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62413+ (tsk)->exec_file->f_vfsmnt) : "/")
62414+
62415+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62416+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62417+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62418+
62419+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62420+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
62421+ (tsk)->exec_file->f_vfsmnt) : "/")
62422+
62423+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62424+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62425+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62426+
62427+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62428+
62429+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62430+
62431+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62432+ (task)->pid, (cred)->uid, \
62433+ (cred)->euid, (cred)->gid, (cred)->egid, \
62434+ gr_parent_task_fullpath(task), \
62435+ (task)->real_parent->comm, (task)->real_parent->pid, \
62436+ (pcred)->uid, (pcred)->euid, \
62437+ (pcred)->gid, (pcred)->egid
62438+
62439+#define GR_CHROOT_CAPS {{ \
62440+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62441+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62442+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62443+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62444+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62445+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62446+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62447+
62448+#define security_learn(normal_msg,args...) \
62449+({ \
62450+ read_lock(&grsec_exec_file_lock); \
62451+ gr_add_learn_entry(normal_msg "\n", ## args); \
62452+ read_unlock(&grsec_exec_file_lock); \
62453+})
62454+
62455+enum {
62456+ GR_DO_AUDIT,
62457+ GR_DONT_AUDIT,
62458+ /* used for non-audit messages that we shouldn't kill the task on */
62459+ GR_DONT_AUDIT_GOOD
62460+};
62461+
62462+enum {
62463+ GR_TTYSNIFF,
62464+ GR_RBAC,
62465+ GR_RBAC_STR,
62466+ GR_STR_RBAC,
62467+ GR_RBAC_MODE2,
62468+ GR_RBAC_MODE3,
62469+ GR_FILENAME,
62470+ GR_SYSCTL_HIDDEN,
62471+ GR_NOARGS,
62472+ GR_ONE_INT,
62473+ GR_ONE_INT_TWO_STR,
62474+ GR_ONE_STR,
62475+ GR_STR_INT,
62476+ GR_TWO_STR_INT,
62477+ GR_TWO_INT,
62478+ GR_TWO_U64,
62479+ GR_THREE_INT,
62480+ GR_FIVE_INT_TWO_STR,
62481+ GR_TWO_STR,
62482+ GR_THREE_STR,
62483+ GR_FOUR_STR,
62484+ GR_STR_FILENAME,
62485+ GR_FILENAME_STR,
62486+ GR_FILENAME_TWO_INT,
62487+ GR_FILENAME_TWO_INT_STR,
62488+ GR_TEXTREL,
62489+ GR_PTRACE,
62490+ GR_RESOURCE,
62491+ GR_CAP,
62492+ GR_SIG,
62493+ GR_SIG2,
62494+ GR_CRASH1,
62495+ GR_CRASH2,
62496+ GR_PSACCT,
62497+ GR_RWXMAP
62498+};
62499+
62500+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62501+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62502+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62503+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62504+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62505+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62506+#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)
62507+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62508+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62509+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62510+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62511+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62512+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62513+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62514+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62515+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62516+#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)
62517+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62518+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62519+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62520+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62521+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62522+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62523+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62524+#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)
62525+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62526+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62527+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62528+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62529+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62530+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62531+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62532+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62533+#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)
62534+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62535+
62536+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62537+
62538+#endif
62539+
62540+#endif
62541diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62542new file mode 100644
62543index 0000000..54f4e85
62544--- /dev/null
62545+++ b/include/linux/grmsg.h
62546@@ -0,0 +1,110 @@
62547+#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"
62548+#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"
62549+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62550+#define GR_STOPMOD_MSG "denied modification of module state by "
62551+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62552+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62553+#define GR_IOPERM_MSG "denied use of ioperm() by "
62554+#define GR_IOPL_MSG "denied use of iopl() by "
62555+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62556+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62557+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62558+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62559+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62560+#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"
62561+#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"
62562+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62563+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62564+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62565+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62566+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62567+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62568+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62569+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62570+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62571+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62572+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62573+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62574+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62575+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62576+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62577+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62578+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62579+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62580+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62581+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62582+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62583+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62584+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62585+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62586+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62587+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62588+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62589+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62590+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62591+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62592+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62593+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62594+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62595+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62596+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62597+#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"
62598+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62599+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62600+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62601+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62602+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62603+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62604+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62605+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62606+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62607+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62608+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62609+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62610+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62611+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62612+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62613+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62614+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62615+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62616+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62617+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62618+#define GR_FAILFORK_MSG "failed fork with errno %s by "
62619+#define GR_NICE_CHROOT_MSG "denied priority change by "
62620+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62621+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62622+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62623+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62624+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62625+#define GR_TIME_MSG "time set by "
62626+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62627+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62628+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62629+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62630+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62631+#define GR_BIND_MSG "denied bind() by "
62632+#define GR_CONNECT_MSG "denied connect() by "
62633+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62634+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62635+#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"
62636+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62637+#define GR_CAP_ACL_MSG "use of %s denied for "
62638+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62639+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62640+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62641+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62642+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62643+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62644+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62645+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62646+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62647+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62648+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62649+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62650+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62651+#define GR_VM86_MSG "denied use of vm86 by "
62652+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62653+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62654+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62655+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62656+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62657diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62658new file mode 100644
62659index 0000000..f9b9a21
62660--- /dev/null
62661+++ b/include/linux/grsecurity.h
62662@@ -0,0 +1,238 @@
62663+#ifndef GR_SECURITY_H
62664+#define GR_SECURITY_H
62665+#include <linux/fs.h>
62666+#include <linux/fs_struct.h>
62667+#include <linux/binfmts.h>
62668+#include <linux/gracl.h>
62669+
62670+/* notify of brain-dead configs */
62671+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62672+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62673+#endif
62674+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62675+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62676+#endif
62677+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62678+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62679+#endif
62680+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62681+#error "CONFIG_PAX enabled, but no PaX options are enabled."
62682+#endif
62683+
62684+#include <linux/compat.h>
62685+
62686+struct user_arg_ptr {
62687+#ifdef CONFIG_COMPAT
62688+ bool is_compat;
62689+#endif
62690+ union {
62691+ const char __user *const __user *native;
62692+#ifdef CONFIG_COMPAT
62693+ compat_uptr_t __user *compat;
62694+#endif
62695+ } ptr;
62696+};
62697+
62698+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62699+void gr_handle_brute_check(void);
62700+void gr_handle_kernel_exploit(void);
62701+int gr_process_user_ban(void);
62702+
62703+char gr_roletype_to_char(void);
62704+
62705+int gr_acl_enable_at_secure(void);
62706+
62707+int gr_check_user_change(int real, int effective, int fs);
62708+int gr_check_group_change(int real, int effective, int fs);
62709+
62710+void gr_del_task_from_ip_table(struct task_struct *p);
62711+
62712+int gr_pid_is_chrooted(struct task_struct *p);
62713+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62714+int gr_handle_chroot_nice(void);
62715+int gr_handle_chroot_sysctl(const int op);
62716+int gr_handle_chroot_setpriority(struct task_struct *p,
62717+ const int niceval);
62718+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62719+int gr_handle_chroot_chroot(const struct dentry *dentry,
62720+ const struct vfsmount *mnt);
62721+void gr_handle_chroot_chdir(struct path *path);
62722+int gr_handle_chroot_chmod(const struct dentry *dentry,
62723+ const struct vfsmount *mnt, const int mode);
62724+int gr_handle_chroot_mknod(const struct dentry *dentry,
62725+ const struct vfsmount *mnt, const int mode);
62726+int gr_handle_chroot_mount(const struct dentry *dentry,
62727+ const struct vfsmount *mnt,
62728+ const char *dev_name);
62729+int gr_handle_chroot_pivot(void);
62730+int gr_handle_chroot_unix(const pid_t pid);
62731+
62732+int gr_handle_rawio(const struct inode *inode);
62733+
62734+void gr_handle_ioperm(void);
62735+void gr_handle_iopl(void);
62736+
62737+umode_t gr_acl_umask(void);
62738+
62739+int gr_tpe_allow(const struct file *file);
62740+
62741+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62742+void gr_clear_chroot_entries(struct task_struct *task);
62743+
62744+void gr_log_forkfail(const int retval);
62745+void gr_log_timechange(void);
62746+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62747+void gr_log_chdir(const struct dentry *dentry,
62748+ const struct vfsmount *mnt);
62749+void gr_log_chroot_exec(const struct dentry *dentry,
62750+ const struct vfsmount *mnt);
62751+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62752+void gr_log_remount(const char *devname, const int retval);
62753+void gr_log_unmount(const char *devname, const int retval);
62754+void gr_log_mount(const char *from, const char *to, const int retval);
62755+void gr_log_textrel(struct vm_area_struct *vma);
62756+void gr_log_rwxmmap(struct file *file);
62757+void gr_log_rwxmprotect(struct file *file);
62758+
62759+int gr_handle_follow_link(const struct inode *parent,
62760+ const struct inode *inode,
62761+ const struct dentry *dentry,
62762+ const struct vfsmount *mnt);
62763+int gr_handle_fifo(const struct dentry *dentry,
62764+ const struct vfsmount *mnt,
62765+ const struct dentry *dir, const int flag,
62766+ const int acc_mode);
62767+int gr_handle_hardlink(const struct dentry *dentry,
62768+ const struct vfsmount *mnt,
62769+ struct inode *inode,
62770+ const int mode, const char *to);
62771+
62772+int gr_is_capable(const int cap);
62773+int gr_is_capable_nolog(const int cap);
62774+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62775+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62776+
62777+void gr_learn_resource(const struct task_struct *task, const int limit,
62778+ const unsigned long wanted, const int gt);
62779+void gr_copy_label(struct task_struct *tsk);
62780+void gr_handle_crash(struct task_struct *task, const int sig);
62781+int gr_handle_signal(const struct task_struct *p, const int sig);
62782+int gr_check_crash_uid(const uid_t uid);
62783+int gr_check_protected_task(const struct task_struct *task);
62784+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62785+int gr_acl_handle_mmap(const struct file *file,
62786+ const unsigned long prot);
62787+int gr_acl_handle_mprotect(const struct file *file,
62788+ const unsigned long prot);
62789+int gr_check_hidden_task(const struct task_struct *tsk);
62790+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62791+ const struct vfsmount *mnt);
62792+__u32 gr_acl_handle_utime(const struct dentry *dentry,
62793+ const struct vfsmount *mnt);
62794+__u32 gr_acl_handle_access(const struct dentry *dentry,
62795+ const struct vfsmount *mnt, const int fmode);
62796+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62797+ const struct vfsmount *mnt, umode_t *mode);
62798+__u32 gr_acl_handle_chown(const struct dentry *dentry,
62799+ const struct vfsmount *mnt);
62800+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62801+ const struct vfsmount *mnt);
62802+int gr_handle_ptrace(struct task_struct *task, const long request);
62803+int gr_handle_proc_ptrace(struct task_struct *task);
62804+__u32 gr_acl_handle_execve(const struct dentry *dentry,
62805+ const struct vfsmount *mnt);
62806+int gr_check_crash_exec(const struct file *filp);
62807+int gr_acl_is_enabled(void);
62808+void gr_set_kernel_label(struct task_struct *task);
62809+void gr_set_role_label(struct task_struct *task, const uid_t uid,
62810+ const gid_t gid);
62811+int gr_set_proc_label(const struct dentry *dentry,
62812+ const struct vfsmount *mnt,
62813+ const int unsafe_flags);
62814+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62815+ const struct vfsmount *mnt);
62816+__u32 gr_acl_handle_open(const struct dentry *dentry,
62817+ const struct vfsmount *mnt, int acc_mode);
62818+__u32 gr_acl_handle_creat(const struct dentry *dentry,
62819+ const struct dentry *p_dentry,
62820+ const struct vfsmount *p_mnt,
62821+ int open_flags, int acc_mode, const int imode);
62822+void gr_handle_create(const struct dentry *dentry,
62823+ const struct vfsmount *mnt);
62824+void gr_handle_proc_create(const struct dentry *dentry,
62825+ const struct inode *inode);
62826+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62827+ const struct dentry *parent_dentry,
62828+ const struct vfsmount *parent_mnt,
62829+ const int mode);
62830+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62831+ const struct dentry *parent_dentry,
62832+ const struct vfsmount *parent_mnt);
62833+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62834+ const struct vfsmount *mnt);
62835+void gr_handle_delete(const ino_t ino, const dev_t dev);
62836+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62837+ const struct vfsmount *mnt);
62838+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62839+ const struct dentry *parent_dentry,
62840+ const struct vfsmount *parent_mnt,
62841+ const char *from);
62842+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62843+ const struct dentry *parent_dentry,
62844+ const struct vfsmount *parent_mnt,
62845+ const struct dentry *old_dentry,
62846+ const struct vfsmount *old_mnt, const char *to);
62847+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62848+int gr_acl_handle_rename(struct dentry *new_dentry,
62849+ struct dentry *parent_dentry,
62850+ const struct vfsmount *parent_mnt,
62851+ struct dentry *old_dentry,
62852+ struct inode *old_parent_inode,
62853+ struct vfsmount *old_mnt, const char *newname);
62854+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62855+ struct dentry *old_dentry,
62856+ struct dentry *new_dentry,
62857+ struct vfsmount *mnt, const __u8 replace);
62858+__u32 gr_check_link(const struct dentry *new_dentry,
62859+ const struct dentry *parent_dentry,
62860+ const struct vfsmount *parent_mnt,
62861+ const struct dentry *old_dentry,
62862+ const struct vfsmount *old_mnt);
62863+int gr_acl_handle_filldir(const struct file *file, const char *name,
62864+ const unsigned int namelen, const ino_t ino);
62865+
62866+__u32 gr_acl_handle_unix(const struct dentry *dentry,
62867+ const struct vfsmount *mnt);
62868+void gr_acl_handle_exit(void);
62869+void gr_acl_handle_psacct(struct task_struct *task, const long code);
62870+int gr_acl_handle_procpidmem(const struct task_struct *task);
62871+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62872+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62873+void gr_audit_ptrace(struct task_struct *task);
62874+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62875+
62876+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62877+
62878+#ifdef CONFIG_GRKERNSEC
62879+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62880+void gr_handle_vm86(void);
62881+void gr_handle_mem_readwrite(u64 from, u64 to);
62882+
62883+void gr_log_badprocpid(const char *entry);
62884+
62885+extern int grsec_enable_dmesg;
62886+extern int grsec_disable_privio;
62887+
62888+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62889+extern int grsec_proc_gid;
62890+#endif
62891+
62892+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62893+extern int grsec_enable_chroot_findtask;
62894+#endif
62895+#ifdef CONFIG_GRKERNSEC_SETXID
62896+extern int grsec_enable_setxid;
62897+#endif
62898+#endif
62899+
62900+#endif
62901diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62902new file mode 100644
62903index 0000000..e7ffaaf
62904--- /dev/null
62905+++ b/include/linux/grsock.h
62906@@ -0,0 +1,19 @@
62907+#ifndef __GRSOCK_H
62908+#define __GRSOCK_H
62909+
62910+extern void gr_attach_curr_ip(const struct sock *sk);
62911+extern int gr_handle_sock_all(const int family, const int type,
62912+ const int protocol);
62913+extern int gr_handle_sock_server(const struct sockaddr *sck);
62914+extern int gr_handle_sock_server_other(const struct sock *sck);
62915+extern int gr_handle_sock_client(const struct sockaddr *sck);
62916+extern int gr_search_connect(struct socket * sock,
62917+ struct sockaddr_in * addr);
62918+extern int gr_search_bind(struct socket * sock,
62919+ struct sockaddr_in * addr);
62920+extern int gr_search_listen(struct socket * sock);
62921+extern int gr_search_accept(struct socket * sock);
62922+extern int gr_search_socket(const int domain, const int type,
62923+ const int protocol);
62924+
62925+#endif
62926diff --git a/include/linux/hid.h b/include/linux/hid.h
62927index 449fa38..b37c8cc 100644
62928--- a/include/linux/hid.h
62929+++ b/include/linux/hid.h
62930@@ -704,7 +704,7 @@ struct hid_ll_driver {
62931 unsigned int code, int value);
62932
62933 int (*parse)(struct hid_device *hdev);
62934-};
62935+} __no_const;
62936
62937 #define PM_HINT_FULLON 1<<5
62938 #define PM_HINT_NORMAL 1<<1
62939diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62940index d3999b4..1304cb4 100644
62941--- a/include/linux/highmem.h
62942+++ b/include/linux/highmem.h
62943@@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
62944 kunmap_atomic(kaddr);
62945 }
62946
62947+static inline void sanitize_highpage(struct page *page)
62948+{
62949+ void *kaddr;
62950+ unsigned long flags;
62951+
62952+ local_irq_save(flags);
62953+ kaddr = kmap_atomic(page);
62954+ clear_page(kaddr);
62955+ kunmap_atomic(kaddr);
62956+ local_irq_restore(flags);
62957+}
62958+
62959 static inline void zero_user_segments(struct page *page,
62960 unsigned start1, unsigned end1,
62961 unsigned start2, unsigned end2)
62962diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62963index ddfa041..a44cfff 100644
62964--- a/include/linux/i2c.h
62965+++ b/include/linux/i2c.h
62966@@ -366,6 +366,7 @@ struct i2c_algorithm {
62967 /* To determine what the adapter supports */
62968 u32 (*functionality) (struct i2c_adapter *);
62969 };
62970+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62971
62972 /*
62973 * i2c_adapter is the structure used to identify a physical i2c bus along
62974diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62975index d23c3c2..eb63c81 100644
62976--- a/include/linux/i2o.h
62977+++ b/include/linux/i2o.h
62978@@ -565,7 +565,7 @@ struct i2o_controller {
62979 struct i2o_device *exec; /* Executive */
62980 #if BITS_PER_LONG == 64
62981 spinlock_t context_list_lock; /* lock for context_list */
62982- atomic_t context_list_counter; /* needed for unique contexts */
62983+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62984 struct list_head context_list; /* list of context id's
62985 and pointers */
62986 #endif
62987diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62988index 8185f57..7b2d222 100644
62989--- a/include/linux/if_team.h
62990+++ b/include/linux/if_team.h
62991@@ -74,6 +74,7 @@ struct team_mode_ops {
62992 void (*port_leave)(struct team *team, struct team_port *port);
62993 void (*port_change_mac)(struct team *team, struct team_port *port);
62994 };
62995+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62996
62997 enum team_option_type {
62998 TEAM_OPTION_TYPE_U32,
62999@@ -136,7 +137,7 @@ struct team {
63000 struct list_head option_inst_list; /* list of option instances */
63001
63002 const struct team_mode *mode;
63003- struct team_mode_ops ops;
63004+ team_mode_ops_no_const ops;
63005 long mode_priv[TEAM_MODE_PRIV_LONGS];
63006 };
63007
63008diff --git a/include/linux/init.h b/include/linux/init.h
63009index 6b95109..7616d09 100644
63010--- a/include/linux/init.h
63011+++ b/include/linux/init.h
63012@@ -39,9 +39,15 @@
63013 * Also note, that this data cannot be "const".
63014 */
63015
63016+#ifdef MODULE
63017+#define add_latent_entropy
63018+#else
63019+#define add_latent_entropy __latent_entropy
63020+#endif
63021+
63022 /* These are for everybody (although not all archs will actually
63023 discard it in modules) */
63024-#define __init __section(.init.text) __cold notrace
63025+#define __init __section(.init.text) __cold notrace add_latent_entropy
63026 #define __initdata __section(.init.data)
63027 #define __initconst __section(.init.rodata)
63028 #define __exitdata __section(.exit.data)
63029@@ -83,7 +89,7 @@
63030 #define __exit __section(.exit.text) __exitused __cold notrace
63031
63032 /* Used for HOTPLUG */
63033-#define __devinit __section(.devinit.text) __cold notrace
63034+#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
63035 #define __devinitdata __section(.devinit.data)
63036 #define __devinitconst __section(.devinit.rodata)
63037 #define __devexit __section(.devexit.text) __exitused __cold notrace
63038@@ -91,7 +97,7 @@
63039 #define __devexitconst __section(.devexit.rodata)
63040
63041 /* Used for HOTPLUG_CPU */
63042-#define __cpuinit __section(.cpuinit.text) __cold notrace
63043+#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
63044 #define __cpuinitdata __section(.cpuinit.data)
63045 #define __cpuinitconst __section(.cpuinit.rodata)
63046 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63047@@ -99,7 +105,7 @@
63048 #define __cpuexitconst __section(.cpuexit.rodata)
63049
63050 /* Used for MEMORY_HOTPLUG */
63051-#define __meminit __section(.meminit.text) __cold notrace
63052+#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
63053 #define __meminitdata __section(.meminit.data)
63054 #define __meminitconst __section(.meminit.rodata)
63055 #define __memexit __section(.memexit.text) __exitused __cold notrace
63056diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63057index b806b82..2e2837e 100644
63058--- a/include/linux/init_task.h
63059+++ b/include/linux/init_task.h
63060@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63061
63062 #define INIT_TASK_COMM "swapper"
63063
63064+#ifdef CONFIG_X86
63065+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63066+#else
63067+#define INIT_TASK_THREAD_INFO
63068+#endif
63069+
63070 /*
63071 * INIT_TASK is used to set up the first task table, touch at
63072 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63073@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63074 RCU_INIT_POINTER(.cred, &init_cred), \
63075 .comm = INIT_TASK_COMM, \
63076 .thread = INIT_THREAD, \
63077+ INIT_TASK_THREAD_INFO \
63078 .fs = &init_fs, \
63079 .files = &init_files, \
63080 .signal = &init_signals, \
63081diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63082index e6ca56d..8583707 100644
63083--- a/include/linux/intel-iommu.h
63084+++ b/include/linux/intel-iommu.h
63085@@ -296,7 +296,7 @@ struct iommu_flush {
63086 u8 fm, u64 type);
63087 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63088 unsigned int size_order, u64 type);
63089-};
63090+} __no_const;
63091
63092 enum {
63093 SR_DMAR_FECTL_REG,
63094diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63095index e68a8e5..811b9af 100644
63096--- a/include/linux/interrupt.h
63097+++ b/include/linux/interrupt.h
63098@@ -435,7 +435,7 @@ enum
63099 /* map softirq index to softirq name. update 'softirq_to_name' in
63100 * kernel/softirq.c when adding a new softirq.
63101 */
63102-extern char *softirq_to_name[NR_SOFTIRQS];
63103+extern const char * const softirq_to_name[NR_SOFTIRQS];
63104
63105 /* softirq mask and active fields moved to irq_cpustat_t in
63106 * asm/hardirq.h to get better cache usage. KAO
63107@@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63108
63109 struct softirq_action
63110 {
63111- void (*action)(struct softirq_action *);
63112+ void (*action)(void);
63113 };
63114
63115 asmlinkage void do_softirq(void);
63116 asmlinkage void __do_softirq(void);
63117-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63118+extern void open_softirq(int nr, void (*action)(void));
63119 extern void softirq_init(void);
63120 extern void __raise_softirq_irqoff(unsigned int nr);
63121
63122diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63123index 6883e19..06992b1 100644
63124--- a/include/linux/kallsyms.h
63125+++ b/include/linux/kallsyms.h
63126@@ -15,7 +15,8 @@
63127
63128 struct module;
63129
63130-#ifdef CONFIG_KALLSYMS
63131+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63132+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63133 /* Lookup the address for a symbol. Returns 0 if not found. */
63134 unsigned long kallsyms_lookup_name(const char *name);
63135
63136@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63137 /* Stupid that this does nothing, but I didn't create this mess. */
63138 #define __print_symbol(fmt, addr)
63139 #endif /*CONFIG_KALLSYMS*/
63140+#else /* when included by kallsyms.c, vsnprintf.c, or
63141+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63142+extern void __print_symbol(const char *fmt, unsigned long address);
63143+extern int sprint_backtrace(char *buffer, unsigned long address);
63144+extern int sprint_symbol(char *buffer, unsigned long address);
63145+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63146+const char *kallsyms_lookup(unsigned long addr,
63147+ unsigned long *symbolsize,
63148+ unsigned long *offset,
63149+ char **modname, char *namebuf);
63150+#endif
63151
63152 /* This macro allows us to keep printk typechecking */
63153 static __printf(1, 2)
63154diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63155index c4d2fc1..5df9c19 100644
63156--- a/include/linux/kgdb.h
63157+++ b/include/linux/kgdb.h
63158@@ -53,7 +53,7 @@ extern int kgdb_connected;
63159 extern int kgdb_io_module_registered;
63160
63161 extern atomic_t kgdb_setting_breakpoint;
63162-extern atomic_t kgdb_cpu_doing_single_step;
63163+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63164
63165 extern struct task_struct *kgdb_usethread;
63166 extern struct task_struct *kgdb_contthread;
63167@@ -252,7 +252,7 @@ struct kgdb_arch {
63168 void (*disable_hw_break)(struct pt_regs *regs);
63169 void (*remove_all_hw_break)(void);
63170 void (*correct_hw_break)(void);
63171-};
63172+} __do_const;
63173
63174 /**
63175 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63176@@ -277,7 +277,7 @@ struct kgdb_io {
63177 void (*pre_exception) (void);
63178 void (*post_exception) (void);
63179 int is_console;
63180-};
63181+} __do_const;
63182
63183 extern struct kgdb_arch arch_kgdb_ops;
63184
63185diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63186index 5398d58..5883a34 100644
63187--- a/include/linux/kmod.h
63188+++ b/include/linux/kmod.h
63189@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63190 * usually useless though. */
63191 extern __printf(2, 3)
63192 int __request_module(bool wait, const char *name, ...);
63193+extern __printf(3, 4)
63194+int ___request_module(bool wait, char *param_name, const char *name, ...);
63195 #define request_module(mod...) __request_module(true, mod)
63196 #define request_module_nowait(mod...) __request_module(false, mod)
63197 #define try_then_request_module(x, mod...) \
63198diff --git a/include/linux/kref.h b/include/linux/kref.h
63199index 9c07dce..a92fa71 100644
63200--- a/include/linux/kref.h
63201+++ b/include/linux/kref.h
63202@@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
63203 static inline int kref_sub(struct kref *kref, unsigned int count,
63204 void (*release)(struct kref *kref))
63205 {
63206- WARN_ON(release == NULL);
63207+ BUG_ON(release == NULL);
63208
63209 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63210 release(kref);
63211diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63212index 96c158a..1864db5 100644
63213--- a/include/linux/kvm_host.h
63214+++ b/include/linux/kvm_host.h
63215@@ -345,7 +345,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63216 void vcpu_load(struct kvm_vcpu *vcpu);
63217 void vcpu_put(struct kvm_vcpu *vcpu);
63218
63219-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63220+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63221 struct module *module);
63222 void kvm_exit(void);
63223
63224@@ -511,7 +511,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63225 struct kvm_guest_debug *dbg);
63226 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63227
63228-int kvm_arch_init(void *opaque);
63229+int kvm_arch_init(const void *opaque);
63230 void kvm_arch_exit(void);
63231
63232 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63233diff --git a/include/linux/libata.h b/include/linux/libata.h
63234index 6e887c7..4539601 100644
63235--- a/include/linux/libata.h
63236+++ b/include/linux/libata.h
63237@@ -910,7 +910,7 @@ struct ata_port_operations {
63238 * fields must be pointers.
63239 */
63240 const struct ata_port_operations *inherits;
63241-};
63242+} __do_const;
63243
63244 struct ata_port_info {
63245 unsigned long flags;
63246diff --git a/include/linux/memory.h b/include/linux/memory.h
63247index ff9a9f8..c715deb 100644
63248--- a/include/linux/memory.h
63249+++ b/include/linux/memory.h
63250@@ -143,7 +143,7 @@ struct memory_accessor {
63251 size_t count);
63252 ssize_t (*write)(struct memory_accessor *, const char *buf,
63253 off_t offset, size_t count);
63254-};
63255+} __no_const;
63256
63257 /*
63258 * Kernel text modification mutex, used for code patching. Users of this lock
63259diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63260index 1318ca6..7521340 100644
63261--- a/include/linux/mfd/abx500.h
63262+++ b/include/linux/mfd/abx500.h
63263@@ -452,6 +452,7 @@ struct abx500_ops {
63264 int (*event_registers_startup_state_get) (struct device *, u8 *);
63265 int (*startup_irq_enabled) (struct device *, unsigned int);
63266 };
63267+typedef struct abx500_ops __no_const abx500_ops_no_const;
63268
63269 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63270 void abx500_remove_ops(struct device *dev);
63271diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63272index 9b07725..3d55001 100644
63273--- a/include/linux/mfd/abx500/ux500_chargalg.h
63274+++ b/include/linux/mfd/abx500/ux500_chargalg.h
63275@@ -19,7 +19,7 @@ struct ux500_charger_ops {
63276 int (*enable) (struct ux500_charger *, int, int, int);
63277 int (*kick_wd) (struct ux500_charger *);
63278 int (*update_curr) (struct ux500_charger *, int);
63279-};
63280+} __no_const;
63281
63282 /**
63283 * struct ux500_charger - power supply ux500 charger sub class
63284diff --git a/include/linux/mm.h b/include/linux/mm.h
63285index f9f279c..198da78 100644
63286--- a/include/linux/mm.h
63287+++ b/include/linux/mm.h
63288@@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63289
63290 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63291 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63292+
63293+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63294+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63295+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63296+#else
63297 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63298+#endif
63299+
63300 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63301 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63302
63303@@ -1009,34 +1016,6 @@ int set_page_dirty(struct page *page);
63304 int set_page_dirty_lock(struct page *page);
63305 int clear_page_dirty_for_io(struct page *page);
63306
63307-/* Is the vma a continuation of the stack vma above it? */
63308-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63309-{
63310- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63311-}
63312-
63313-static inline int stack_guard_page_start(struct vm_area_struct *vma,
63314- unsigned long addr)
63315-{
63316- return (vma->vm_flags & VM_GROWSDOWN) &&
63317- (vma->vm_start == addr) &&
63318- !vma_growsdown(vma->vm_prev, addr);
63319-}
63320-
63321-/* Is the vma a continuation of the stack vma below it? */
63322-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63323-{
63324- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63325-}
63326-
63327-static inline int stack_guard_page_end(struct vm_area_struct *vma,
63328- unsigned long addr)
63329-{
63330- return (vma->vm_flags & VM_GROWSUP) &&
63331- (vma->vm_end == addr) &&
63332- !vma_growsup(vma->vm_next, addr);
63333-}
63334-
63335 extern pid_t
63336 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63337
63338@@ -1135,6 +1114,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63339 }
63340 #endif
63341
63342+#ifdef CONFIG_MMU
63343+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63344+#else
63345+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63346+{
63347+ return __pgprot(0);
63348+}
63349+#endif
63350+
63351 int vma_wants_writenotify(struct vm_area_struct *vma);
63352
63353 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63354@@ -1153,8 +1141,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63355 {
63356 return 0;
63357 }
63358+
63359+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63360+ unsigned long address)
63361+{
63362+ return 0;
63363+}
63364 #else
63365 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63366+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63367 #endif
63368
63369 #ifdef __PAGETABLE_PMD_FOLDED
63370@@ -1163,8 +1158,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63371 {
63372 return 0;
63373 }
63374+
63375+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63376+ unsigned long address)
63377+{
63378+ return 0;
63379+}
63380 #else
63381 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63382+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63383 #endif
63384
63385 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63386@@ -1182,11 +1184,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63387 NULL: pud_offset(pgd, address);
63388 }
63389
63390+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63391+{
63392+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63393+ NULL: pud_offset(pgd, address);
63394+}
63395+
63396 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63397 {
63398 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63399 NULL: pmd_offset(pud, address);
63400 }
63401+
63402+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63403+{
63404+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63405+ NULL: pmd_offset(pud, address);
63406+}
63407 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63408
63409 #if USE_SPLIT_PTLOCKS
63410@@ -1396,6 +1410,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63411 unsigned long, unsigned long,
63412 unsigned long, unsigned long);
63413 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63414+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63415
63416 /* These take the mm semaphore themselves */
63417 extern unsigned long vm_brk(unsigned long, unsigned long);
63418@@ -1458,6 +1473,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63419 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63420 struct vm_area_struct **pprev);
63421
63422+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63423+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63424+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63425+
63426 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63427 NULL if none. Assume start_addr < end_addr. */
63428 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63429@@ -1486,15 +1505,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63430 return vma;
63431 }
63432
63433-#ifdef CONFIG_MMU
63434-pgprot_t vm_get_page_prot(unsigned long vm_flags);
63435-#else
63436-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63437-{
63438- return __pgprot(0);
63439-}
63440-#endif
63441-
63442 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63443 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63444 unsigned long pfn, unsigned long size, pgprot_t);
63445@@ -1599,7 +1609,7 @@ extern int unpoison_memory(unsigned long pfn);
63446 extern int sysctl_memory_failure_early_kill;
63447 extern int sysctl_memory_failure_recovery;
63448 extern void shake_page(struct page *p, int access);
63449-extern atomic_long_t mce_bad_pages;
63450+extern atomic_long_unchecked_t mce_bad_pages;
63451 extern int soft_offline_page(struct page *page, int flags);
63452
63453 extern void dump_page(struct page *page);
63454@@ -1630,5 +1640,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63455 static inline bool page_is_guard(struct page *page) { return false; }
63456 #endif /* CONFIG_DEBUG_PAGEALLOC */
63457
63458+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63459+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63460+#else
63461+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63462+#endif
63463+
63464 #endif /* __KERNEL__ */
63465 #endif /* _LINUX_MM_H */
63466diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63467index 704a626..bb0705a 100644
63468--- a/include/linux/mm_types.h
63469+++ b/include/linux/mm_types.h
63470@@ -263,6 +263,8 @@ struct vm_area_struct {
63471 #ifdef CONFIG_NUMA
63472 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63473 #endif
63474+
63475+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63476 };
63477
63478 struct core_thread {
63479@@ -337,7 +339,7 @@ struct mm_struct {
63480 unsigned long def_flags;
63481 unsigned long nr_ptes; /* Page table pages */
63482 unsigned long start_code, end_code, start_data, end_data;
63483- unsigned long start_brk, brk, start_stack;
63484+ unsigned long brk_gap, start_brk, brk, start_stack;
63485 unsigned long arg_start, arg_end, env_start, env_end;
63486
63487 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63488@@ -389,6 +391,24 @@ struct mm_struct {
63489 struct cpumask cpumask_allocation;
63490 #endif
63491 struct uprobes_state uprobes_state;
63492+
63493+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63494+ unsigned long pax_flags;
63495+#endif
63496+
63497+#ifdef CONFIG_PAX_DLRESOLVE
63498+ unsigned long call_dl_resolve;
63499+#endif
63500+
63501+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63502+ unsigned long call_syscall;
63503+#endif
63504+
63505+#ifdef CONFIG_PAX_ASLR
63506+ unsigned long delta_mmap; /* randomized offset */
63507+ unsigned long delta_stack; /* randomized offset */
63508+#endif
63509+
63510 };
63511
63512 static inline void mm_init_cpumask(struct mm_struct *mm)
63513diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63514index 1d1b1e1..2a13c78 100644
63515--- a/include/linux/mmu_notifier.h
63516+++ b/include/linux/mmu_notifier.h
63517@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63518 */
63519 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63520 ({ \
63521- pte_t __pte; \
63522+ pte_t ___pte; \
63523 struct vm_area_struct *___vma = __vma; \
63524 unsigned long ___address = __address; \
63525- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63526+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63527 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63528- __pte; \
63529+ ___pte; \
63530 })
63531
63532 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63533diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63534index 68c569f..5f43753 100644
63535--- a/include/linux/mmzone.h
63536+++ b/include/linux/mmzone.h
63537@@ -411,7 +411,7 @@ struct zone {
63538 unsigned long flags; /* zone flags, see below */
63539
63540 /* Zone statistics */
63541- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63542+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63543
63544 /*
63545 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63546diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63547index 5db9382..50e801d 100644
63548--- a/include/linux/mod_devicetable.h
63549+++ b/include/linux/mod_devicetable.h
63550@@ -12,7 +12,7 @@
63551 typedef unsigned long kernel_ulong_t;
63552 #endif
63553
63554-#define PCI_ANY_ID (~0)
63555+#define PCI_ANY_ID ((__u16)~0)
63556
63557 struct pci_device_id {
63558 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63559@@ -131,7 +131,7 @@ struct usb_device_id {
63560 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
63561 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63562
63563-#define HID_ANY_ID (~0)
63564+#define HID_ANY_ID (~0U)
63565 #define HID_BUS_ANY 0xffff
63566 #define HID_GROUP_ANY 0x0000
63567
63568diff --git a/include/linux/module.h b/include/linux/module.h
63569index fbcafe2..e5d9587 100644
63570--- a/include/linux/module.h
63571+++ b/include/linux/module.h
63572@@ -17,6 +17,7 @@
63573 #include <linux/moduleparam.h>
63574 #include <linux/tracepoint.h>
63575 #include <linux/export.h>
63576+#include <linux/fs.h>
63577
63578 #include <linux/percpu.h>
63579 #include <asm/module.h>
63580@@ -273,19 +274,16 @@ struct module
63581 int (*init)(void);
63582
63583 /* If this is non-NULL, vfree after init() returns */
63584- void *module_init;
63585+ void *module_init_rx, *module_init_rw;
63586
63587 /* Here is the actual code + data, vfree'd on unload. */
63588- void *module_core;
63589+ void *module_core_rx, *module_core_rw;
63590
63591 /* Here are the sizes of the init and core sections */
63592- unsigned int init_size, core_size;
63593+ unsigned int init_size_rw, core_size_rw;
63594
63595 /* The size of the executable code in each section. */
63596- unsigned int init_text_size, core_text_size;
63597-
63598- /* Size of RO sections of the module (text+rodata) */
63599- unsigned int init_ro_size, core_ro_size;
63600+ unsigned int init_size_rx, core_size_rx;
63601
63602 /* Arch-specific module values */
63603 struct mod_arch_specific arch;
63604@@ -341,6 +339,10 @@ struct module
63605 #ifdef CONFIG_EVENT_TRACING
63606 struct ftrace_event_call **trace_events;
63607 unsigned int num_trace_events;
63608+ struct file_operations trace_id;
63609+ struct file_operations trace_enable;
63610+ struct file_operations trace_format;
63611+ struct file_operations trace_filter;
63612 #endif
63613 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63614 unsigned int num_ftrace_callsites;
63615@@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63616 bool is_module_percpu_address(unsigned long addr);
63617 bool is_module_text_address(unsigned long addr);
63618
63619+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63620+{
63621+
63622+#ifdef CONFIG_PAX_KERNEXEC
63623+ if (ktla_ktva(addr) >= (unsigned long)start &&
63624+ ktla_ktva(addr) < (unsigned long)start + size)
63625+ return 1;
63626+#endif
63627+
63628+ return ((void *)addr >= start && (void *)addr < start + size);
63629+}
63630+
63631+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63632+{
63633+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63634+}
63635+
63636+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63637+{
63638+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63639+}
63640+
63641+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63642+{
63643+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63644+}
63645+
63646+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63647+{
63648+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63649+}
63650+
63651 static inline int within_module_core(unsigned long addr, struct module *mod)
63652 {
63653- return (unsigned long)mod->module_core <= addr &&
63654- addr < (unsigned long)mod->module_core + mod->core_size;
63655+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63656 }
63657
63658 static inline int within_module_init(unsigned long addr, struct module *mod)
63659 {
63660- return (unsigned long)mod->module_init <= addr &&
63661- addr < (unsigned long)mod->module_init + mod->init_size;
63662+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63663 }
63664
63665 /* Search for module by name: must hold module_mutex. */
63666diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63667index b2be02e..72d2f78 100644
63668--- a/include/linux/moduleloader.h
63669+++ b/include/linux/moduleloader.h
63670@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63671
63672 /* Allocator used for allocating struct module, core sections and init
63673 sections. Returns NULL on failure. */
63674-void *module_alloc(unsigned long size);
63675+void *module_alloc(unsigned long size) __size_overflow(1);
63676+
63677+#ifdef CONFIG_PAX_KERNEXEC
63678+void *module_alloc_exec(unsigned long size) __size_overflow(1);
63679+#else
63680+#define module_alloc_exec(x) module_alloc(x)
63681+#endif
63682
63683 /* Free memory returned from module_alloc. */
63684 void module_free(struct module *mod, void *module_region);
63685
63686+#ifdef CONFIG_PAX_KERNEXEC
63687+void module_free_exec(struct module *mod, void *module_region);
63688+#else
63689+#define module_free_exec(x, y) module_free((x), (y))
63690+#endif
63691+
63692 /* Apply the given relocation to the (simplified) ELF. Return -error
63693 or 0. */
63694 int apply_relocate(Elf_Shdr *sechdrs,
63695diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63696index d6a5806..7c13347 100644
63697--- a/include/linux/moduleparam.h
63698+++ b/include/linux/moduleparam.h
63699@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63700 * @len is usually just sizeof(string).
63701 */
63702 #define module_param_string(name, string, len, perm) \
63703- static const struct kparam_string __param_string_##name \
63704+ static const struct kparam_string __param_string_##name __used \
63705 = { len, string }; \
63706 __module_param_call(MODULE_PARAM_PREFIX, name, \
63707 &param_ops_string, \
63708@@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63709 */
63710 #define module_param_array_named(name, array, type, nump, perm) \
63711 param_check_##type(name, &(array)[0]); \
63712- static const struct kparam_array __param_arr_##name \
63713+ static const struct kparam_array __param_arr_##name __used \
63714 = { .max = ARRAY_SIZE(array), .num = nump, \
63715 .ops = &param_ops_##type, \
63716 .elemsize = sizeof(array[0]), .elem = array }; \
63717diff --git a/include/linux/namei.h b/include/linux/namei.h
63718index ffc0213..2c1f2cb 100644
63719--- a/include/linux/namei.h
63720+++ b/include/linux/namei.h
63721@@ -24,7 +24,7 @@ struct nameidata {
63722 unsigned seq;
63723 int last_type;
63724 unsigned depth;
63725- char *saved_names[MAX_NESTED_LINKS + 1];
63726+ const char *saved_names[MAX_NESTED_LINKS + 1];
63727
63728 /* Intent data */
63729 union {
63730@@ -94,12 +94,12 @@ extern int follow_up(struct path *);
63731 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
63732 extern void unlock_rename(struct dentry *, struct dentry *);
63733
63734-static inline void nd_set_link(struct nameidata *nd, char *path)
63735+static inline void nd_set_link(struct nameidata *nd, const char *path)
63736 {
63737 nd->saved_names[nd->depth] = path;
63738 }
63739
63740-static inline char *nd_get_link(struct nameidata *nd)
63741+static inline const char *nd_get_link(const struct nameidata *nd)
63742 {
63743 return nd->saved_names[nd->depth];
63744 }
63745diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63746index b52070a..ea67208 100644
63747--- a/include/linux/netdevice.h
63748+++ b/include/linux/netdevice.h
63749@@ -1026,6 +1026,7 @@ struct net_device_ops {
63750 struct net_device *dev,
63751 int idx);
63752 };
63753+typedef struct net_device_ops __no_const net_device_ops_no_const;
63754
63755 /*
63756 * The DEVICE structure.
63757@@ -1087,7 +1088,7 @@ struct net_device {
63758 int iflink;
63759
63760 struct net_device_stats stats;
63761- atomic_long_t rx_dropped; /* dropped packets by core network
63762+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63763 * Do not use this in drivers.
63764 */
63765
63766diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63767new file mode 100644
63768index 0000000..33f4af8
63769--- /dev/null
63770+++ b/include/linux/netfilter/xt_gradm.h
63771@@ -0,0 +1,9 @@
63772+#ifndef _LINUX_NETFILTER_XT_GRADM_H
63773+#define _LINUX_NETFILTER_XT_GRADM_H 1
63774+
63775+struct xt_gradm_mtinfo {
63776+ __u16 flags;
63777+ __u16 invflags;
63778+};
63779+
63780+#endif
63781diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63782index c65a18a..0c05f3a 100644
63783--- a/include/linux/of_pdt.h
63784+++ b/include/linux/of_pdt.h
63785@@ -32,7 +32,7 @@ struct of_pdt_ops {
63786
63787 /* return 0 on success; fill in 'len' with number of bytes in path */
63788 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63789-};
63790+} __no_const;
63791
63792 extern void *prom_early_alloc(unsigned long size);
63793
63794diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63795index a4c5624..79d6d88 100644
63796--- a/include/linux/oprofile.h
63797+++ b/include/linux/oprofile.h
63798@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63799 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63800 char const * name, ulong * val);
63801
63802-/** Create a file for read-only access to an atomic_t. */
63803+/** Create a file for read-only access to an atomic_unchecked_t. */
63804 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63805- char const * name, atomic_t * val);
63806+ char const * name, atomic_unchecked_t * val);
63807
63808 /** create a directory */
63809 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63810diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63811index c3c98a6..c57555e 100644
63812--- a/include/linux/perf_event.h
63813+++ b/include/linux/perf_event.h
63814@@ -881,8 +881,8 @@ struct perf_event {
63815
63816 enum perf_event_active_state state;
63817 unsigned int attach_state;
63818- local64_t count;
63819- atomic64_t child_count;
63820+ local64_t count; /* PaX: fix it one day */
63821+ atomic64_unchecked_t child_count;
63822
63823 /*
63824 * These are the total time in nanoseconds that the event
63825@@ -933,8 +933,8 @@ struct perf_event {
63826 * These accumulate total time (in nanoseconds) that children
63827 * events have been enabled and running, respectively.
63828 */
63829- atomic64_t child_total_time_enabled;
63830- atomic64_t child_total_time_running;
63831+ atomic64_unchecked_t child_total_time_enabled;
63832+ atomic64_unchecked_t child_total_time_running;
63833
63834 /*
63835 * Protect attach/detach and child_list:
63836diff --git a/include/linux/personality.h b/include/linux/personality.h
63837index 8fc7dd1a..c19d89e 100644
63838--- a/include/linux/personality.h
63839+++ b/include/linux/personality.h
63840@@ -44,6 +44,7 @@ enum {
63841 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63842 ADDR_NO_RANDOMIZE | \
63843 ADDR_COMPAT_LAYOUT | \
63844+ ADDR_LIMIT_3GB | \
63845 MMAP_PAGE_ZERO)
63846
63847 /*
63848diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63849index e1ac1ce..0675fed 100644
63850--- a/include/linux/pipe_fs_i.h
63851+++ b/include/linux/pipe_fs_i.h
63852@@ -45,9 +45,9 @@ struct pipe_buffer {
63853 struct pipe_inode_info {
63854 wait_queue_head_t wait;
63855 unsigned int nrbufs, curbuf, buffers;
63856- unsigned int readers;
63857- unsigned int writers;
63858- unsigned int waiting_writers;
63859+ atomic_t readers;
63860+ atomic_t writers;
63861+ atomic_t waiting_writers;
63862 unsigned int r_counter;
63863 unsigned int w_counter;
63864 struct page *tmp_page;
63865diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63866index f271860..6b3bec5 100644
63867--- a/include/linux/pm_runtime.h
63868+++ b/include/linux/pm_runtime.h
63869@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63870
63871 static inline void pm_runtime_mark_last_busy(struct device *dev)
63872 {
63873- ACCESS_ONCE(dev->power.last_busy) = jiffies;
63874+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63875 }
63876
63877 #else /* !CONFIG_PM_RUNTIME */
63878diff --git a/include/linux/poison.h b/include/linux/poison.h
63879index 2110a81..13a11bb 100644
63880--- a/include/linux/poison.h
63881+++ b/include/linux/poison.h
63882@@ -19,8 +19,8 @@
63883 * under normal circumstances, used to verify that nobody uses
63884 * non-initialized list entries.
63885 */
63886-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63887-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63888+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63889+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63890
63891 /********** include/linux/timer.h **********/
63892 /*
63893diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63894index 5a710b9..0b0dab9 100644
63895--- a/include/linux/preempt.h
63896+++ b/include/linux/preempt.h
63897@@ -126,7 +126,7 @@ struct preempt_ops {
63898 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63899 void (*sched_out)(struct preempt_notifier *notifier,
63900 struct task_struct *next);
63901-};
63902+} __no_const;
63903
63904 /**
63905 * preempt_notifier - key for installing preemption notifiers
63906diff --git a/include/linux/printk.h b/include/linux/printk.h
63907index 1bec2f7..b66e833 100644
63908--- a/include/linux/printk.h
63909+++ b/include/linux/printk.h
63910@@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
63911 extern int printk_needs_cpu(int cpu);
63912 extern void printk_tick(void);
63913
63914+extern int kptr_restrict;
63915+
63916 #ifdef CONFIG_PRINTK
63917 asmlinkage __printf(5, 0)
63918 int vprintk_emit(int facility, int level,
63919@@ -128,7 +130,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63920
63921 extern int printk_delay_msec;
63922 extern int dmesg_restrict;
63923-extern int kptr_restrict;
63924
63925 void log_buf_kexec_setup(void);
63926 void __init setup_log_buf(int early);
63927diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63928index 3fd2e87..d93a721 100644
63929--- a/include/linux/proc_fs.h
63930+++ b/include/linux/proc_fs.h
63931@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63932 return proc_create_data(name, mode, parent, proc_fops, NULL);
63933 }
63934
63935+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63936+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63937+{
63938+#ifdef CONFIG_GRKERNSEC_PROC_USER
63939+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63940+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63941+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63942+#else
63943+ return proc_create_data(name, mode, parent, proc_fops, NULL);
63944+#endif
63945+}
63946+
63947 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63948 umode_t mode, struct proc_dir_entry *base,
63949 read_proc_t *read_proc, void * data)
63950@@ -258,7 +270,7 @@ union proc_op {
63951 int (*proc_show)(struct seq_file *m,
63952 struct pid_namespace *ns, struct pid *pid,
63953 struct task_struct *task);
63954-};
63955+} __no_const;
63956
63957 struct ctl_table_header;
63958 struct ctl_table;
63959diff --git a/include/linux/random.h b/include/linux/random.h
63960index ac621ce..c1215f3 100644
63961--- a/include/linux/random.h
63962+++ b/include/linux/random.h
63963@@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63964 unsigned int value);
63965 extern void add_interrupt_randomness(int irq, int irq_flags);
63966
63967+#ifdef CONFIG_PAX_LATENT_ENTROPY
63968+extern void transfer_latent_entropy(void);
63969+#endif
63970+
63971 extern void get_random_bytes(void *buf, int nbytes);
63972 extern void get_random_bytes_arch(void *buf, int nbytes);
63973 void generate_random_uuid(unsigned char uuid_out[16]);
63974@@ -69,12 +73,17 @@ void srandom32(u32 seed);
63975
63976 u32 prandom32(struct rnd_state *);
63977
63978+static inline unsigned long pax_get_random_long(void)
63979+{
63980+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63981+}
63982+
63983 /*
63984 * Handle minimum values for seeds
63985 */
63986 static inline u32 __seed(u32 x, u32 m)
63987 {
63988- return (x < m) ? x + m : x;
63989+ return (x <= m) ? x + m + 1 : x;
63990 }
63991
63992 /**
63993diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63994index e0879a7..a12f962 100644
63995--- a/include/linux/reboot.h
63996+++ b/include/linux/reboot.h
63997@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63998 * Architecture-specific implementations of sys_reboot commands.
63999 */
64000
64001-extern void machine_restart(char *cmd);
64002-extern void machine_halt(void);
64003-extern void machine_power_off(void);
64004+extern void machine_restart(char *cmd) __noreturn;
64005+extern void machine_halt(void) __noreturn;
64006+extern void machine_power_off(void) __noreturn;
64007
64008 extern void machine_shutdown(void);
64009 struct pt_regs;
64010@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
64011 */
64012
64013 extern void kernel_restart_prepare(char *cmd);
64014-extern void kernel_restart(char *cmd);
64015-extern void kernel_halt(void);
64016-extern void kernel_power_off(void);
64017+extern void kernel_restart(char *cmd) __noreturn;
64018+extern void kernel_halt(void) __noreturn;
64019+extern void kernel_power_off(void) __noreturn;
64020
64021 extern int C_A_D; /* for sysctl */
64022 void ctrl_alt_del(void);
64023@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
64024 * Emergency restart, callable from an interrupt handler.
64025 */
64026
64027-extern void emergency_restart(void);
64028+extern void emergency_restart(void) __noreturn;
64029 #include <asm/emergency-restart.h>
64030
64031 #endif
64032diff --git a/include/linux/relay.h b/include/linux/relay.h
64033index 91cacc3..b55ff74 100644
64034--- a/include/linux/relay.h
64035+++ b/include/linux/relay.h
64036@@ -160,7 +160,7 @@ struct rchan_callbacks
64037 * The callback should return 0 if successful, negative if not.
64038 */
64039 int (*remove_buf_file)(struct dentry *dentry);
64040-};
64041+} __no_const;
64042
64043 /*
64044 * CONFIG_RELAY kernel API, kernel/relay.c
64045diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
64046index 6fdf027..ff72610 100644
64047--- a/include/linux/rfkill.h
64048+++ b/include/linux/rfkill.h
64049@@ -147,6 +147,7 @@ struct rfkill_ops {
64050 void (*query)(struct rfkill *rfkill, void *data);
64051 int (*set_block)(void *data, bool blocked);
64052 };
64053+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64054
64055 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64056 /**
64057diff --git a/include/linux/rio.h b/include/linux/rio.h
64058index a90ebad..fd87b5d 100644
64059--- a/include/linux/rio.h
64060+++ b/include/linux/rio.h
64061@@ -321,7 +321,7 @@ struct rio_ops {
64062 int mbox, void *buffer, size_t len);
64063 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
64064 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
64065-};
64066+} __no_const;
64067
64068 #define RIO_RESOURCE_MEM 0x00000100
64069 #define RIO_RESOURCE_DOORBELL 0x00000200
64070diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64071index 3fce545..b4fed6e 100644
64072--- a/include/linux/rmap.h
64073+++ b/include/linux/rmap.h
64074@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64075 void anon_vma_init(void); /* create anon_vma_cachep */
64076 int anon_vma_prepare(struct vm_area_struct *);
64077 void unlink_anon_vmas(struct vm_area_struct *);
64078-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64079+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64080 void anon_vma_moveto_tail(struct vm_area_struct *);
64081-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64082+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64083
64084 static inline void anon_vma_merge(struct vm_area_struct *vma,
64085 struct vm_area_struct *next)
64086diff --git a/include/linux/sched.h b/include/linux/sched.h
64087index e63650f..7dfd1b3 100644
64088--- a/include/linux/sched.h
64089+++ b/include/linux/sched.h
64090@@ -101,6 +101,7 @@ struct bio_list;
64091 struct fs_struct;
64092 struct perf_event_context;
64093 struct blk_plug;
64094+struct linux_binprm;
64095
64096 /*
64097 * List of flags we want to share for kernel threads,
64098@@ -384,10 +385,13 @@ struct user_namespace;
64099 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64100
64101 extern int sysctl_max_map_count;
64102+extern unsigned long sysctl_heap_stack_gap;
64103
64104 #include <linux/aio.h>
64105
64106 #ifdef CONFIG_MMU
64107+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64108+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64109 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64110 extern unsigned long
64111 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64112@@ -406,6 +410,11 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
64113 extern void set_dumpable(struct mm_struct *mm, int value);
64114 extern int get_dumpable(struct mm_struct *mm);
64115
64116+/* get/set_dumpable() values */
64117+#define SUID_DUMPABLE_DISABLED 0
64118+#define SUID_DUMPABLE_ENABLED 1
64119+#define SUID_DUMPABLE_SAFE 2
64120+
64121 /* mm flags */
64122 /* dumpable bits */
64123 #define MMF_DUMPABLE 0 /* core dump is permitted */
64124@@ -646,6 +655,17 @@ struct signal_struct {
64125 #ifdef CONFIG_TASKSTATS
64126 struct taskstats *stats;
64127 #endif
64128+
64129+#ifdef CONFIG_GRKERNSEC
64130+ u32 curr_ip;
64131+ u32 saved_ip;
64132+ u32 gr_saddr;
64133+ u32 gr_daddr;
64134+ u16 gr_sport;
64135+ u16 gr_dport;
64136+ u8 used_accept:1;
64137+#endif
64138+
64139 #ifdef CONFIG_AUDIT
64140 unsigned audit_tty;
64141 struct tty_audit_buf *tty_audit_buf;
64142@@ -729,6 +749,11 @@ struct user_struct {
64143 struct key *session_keyring; /* UID's default session keyring */
64144 #endif
64145
64146+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64147+ unsigned int banned;
64148+ unsigned long ban_expires;
64149+#endif
64150+
64151 /* Hash table maintenance information */
64152 struct hlist_node uidhash_node;
64153 kuid_t uid;
64154@@ -1351,8 +1376,8 @@ struct task_struct {
64155 struct list_head thread_group;
64156
64157 struct completion *vfork_done; /* for vfork() */
64158- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64159- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64160+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64161+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64162
64163 cputime_t utime, stime, utimescaled, stimescaled;
64164 cputime_t gtime;
64165@@ -1368,11 +1393,6 @@ struct task_struct {
64166 struct task_cputime cputime_expires;
64167 struct list_head cpu_timers[3];
64168
64169-/* process credentials */
64170- const struct cred __rcu *real_cred; /* objective and real subjective task
64171- * credentials (COW) */
64172- const struct cred __rcu *cred; /* effective (overridable) subjective task
64173- * credentials (COW) */
64174 char comm[TASK_COMM_LEN]; /* executable name excluding path
64175 - access with [gs]et_task_comm (which lock
64176 it with task_lock())
64177@@ -1389,8 +1409,16 @@ struct task_struct {
64178 #endif
64179 /* CPU-specific state of this task */
64180 struct thread_struct thread;
64181+/* thread_info moved to task_struct */
64182+#ifdef CONFIG_X86
64183+ struct thread_info tinfo;
64184+#endif
64185 /* filesystem information */
64186 struct fs_struct *fs;
64187+
64188+ const struct cred __rcu *cred; /* effective (overridable) subjective task
64189+ * credentials (COW) */
64190+
64191 /* open file information */
64192 struct files_struct *files;
64193 /* namespaces */
64194@@ -1434,6 +1462,11 @@ struct task_struct {
64195 struct rt_mutex_waiter *pi_blocked_on;
64196 #endif
64197
64198+/* process credentials */
64199+ const struct cred __rcu *real_cred; /* objective and real subjective task
64200+ * credentials (COW) */
64201+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64202+
64203 #ifdef CONFIG_DEBUG_MUTEXES
64204 /* mutex deadlock detection */
64205 struct mutex_waiter *blocked_on;
64206@@ -1550,6 +1583,27 @@ struct task_struct {
64207 unsigned long default_timer_slack_ns;
64208
64209 struct list_head *scm_work_list;
64210+
64211+#ifdef CONFIG_GRKERNSEC
64212+ /* grsecurity */
64213+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64214+ u64 exec_id;
64215+#endif
64216+#ifdef CONFIG_GRKERNSEC_SETXID
64217+ const struct cred *delayed_cred;
64218+#endif
64219+ struct dentry *gr_chroot_dentry;
64220+ struct acl_subject_label *acl;
64221+ struct acl_role_label *role;
64222+ struct file *exec_file;
64223+ u16 acl_role_id;
64224+ /* is this the task that authenticated to the special role */
64225+ u8 acl_sp_role;
64226+ u8 is_writable;
64227+ u8 brute;
64228+ u8 gr_is_chrooted;
64229+#endif
64230+
64231 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
64232 /* Index of current stored address in ret_stack */
64233 int curr_ret_stack;
64234@@ -1588,6 +1642,51 @@ struct task_struct {
64235 #endif
64236 };
64237
64238+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64239+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64240+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64241+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64242+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64243+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64244+
64245+#ifdef CONFIG_PAX_SOFTMODE
64246+extern int pax_softmode;
64247+#endif
64248+
64249+extern int pax_check_flags(unsigned long *);
64250+
64251+/* if tsk != current then task_lock must be held on it */
64252+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64253+static inline unsigned long pax_get_flags(struct task_struct *tsk)
64254+{
64255+ if (likely(tsk->mm))
64256+ return tsk->mm->pax_flags;
64257+ else
64258+ return 0UL;
64259+}
64260+
64261+/* if tsk != current then task_lock must be held on it */
64262+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64263+{
64264+ if (likely(tsk->mm)) {
64265+ tsk->mm->pax_flags = flags;
64266+ return 0;
64267+ }
64268+ return -EINVAL;
64269+}
64270+#endif
64271+
64272+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64273+extern void pax_set_initial_flags(struct linux_binprm *bprm);
64274+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64275+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64276+#endif
64277+
64278+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64279+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64280+extern void pax_report_refcount_overflow(struct pt_regs *regs);
64281+extern void check_object_size(const void *ptr, unsigned long n, bool to);
64282+
64283 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64284 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64285
64286@@ -2115,7 +2214,9 @@ void yield(void);
64287 extern struct exec_domain default_exec_domain;
64288
64289 union thread_union {
64290+#ifndef CONFIG_X86
64291 struct thread_info thread_info;
64292+#endif
64293 unsigned long stack[THREAD_SIZE/sizeof(long)];
64294 };
64295
64296@@ -2148,6 +2249,7 @@ extern struct pid_namespace init_pid_ns;
64297 */
64298
64299 extern struct task_struct *find_task_by_vpid(pid_t nr);
64300+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64301 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64302 struct pid_namespace *ns);
64303
64304@@ -2304,7 +2406,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64305 extern void exit_itimers(struct signal_struct *);
64306 extern void flush_itimer_signals(void);
64307
64308-extern void do_group_exit(int);
64309+extern __noreturn void do_group_exit(int);
64310
64311 extern void daemonize(const char *, ...);
64312 extern int allow_signal(int);
64313@@ -2505,9 +2607,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64314
64315 #endif
64316
64317-static inline int object_is_on_stack(void *obj)
64318+static inline int object_starts_on_stack(void *obj)
64319 {
64320- void *stack = task_stack_page(current);
64321+ const void *stack = task_stack_page(current);
64322
64323 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64324 }
64325diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64326index 899fbb4..1cb4138 100644
64327--- a/include/linux/screen_info.h
64328+++ b/include/linux/screen_info.h
64329@@ -43,7 +43,8 @@ struct screen_info {
64330 __u16 pages; /* 0x32 */
64331 __u16 vesa_attributes; /* 0x34 */
64332 __u32 capabilities; /* 0x36 */
64333- __u8 _reserved[6]; /* 0x3a */
64334+ __u16 vesapm_size; /* 0x3a */
64335+ __u8 _reserved[4]; /* 0x3c */
64336 } __attribute__((packed));
64337
64338 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64339diff --git a/include/linux/security.h b/include/linux/security.h
64340index d143b8e..9f27b95 100644
64341--- a/include/linux/security.h
64342+++ b/include/linux/security.h
64343@@ -26,6 +26,7 @@
64344 #include <linux/capability.h>
64345 #include <linux/slab.h>
64346 #include <linux/err.h>
64347+#include <linux/grsecurity.h>
64348
64349 struct linux_binprm;
64350 struct cred;
64351diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64352index fc61854..d7c490b 100644
64353--- a/include/linux/seq_file.h
64354+++ b/include/linux/seq_file.h
64355@@ -25,6 +25,9 @@ struct seq_file {
64356 struct mutex lock;
64357 const struct seq_operations *op;
64358 int poll_event;
64359+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64360+ u64 exec_id;
64361+#endif
64362 void *private;
64363 };
64364
64365@@ -34,6 +37,7 @@ struct seq_operations {
64366 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64367 int (*show) (struct seq_file *m, void *v);
64368 };
64369+typedef struct seq_operations __no_const seq_operations_no_const;
64370
64371 #define SEQ_SKIP 1
64372
64373diff --git a/include/linux/shm.h b/include/linux/shm.h
64374index 92808b8..c28cac4 100644
64375--- a/include/linux/shm.h
64376+++ b/include/linux/shm.h
64377@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64378
64379 /* The task created the shm object. NULL if the task is dead. */
64380 struct task_struct *shm_creator;
64381+#ifdef CONFIG_GRKERNSEC
64382+ time_t shm_createtime;
64383+ pid_t shm_lapid;
64384+#endif
64385 };
64386
64387 /* shm_mode upper byte flags */
64388diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64389index 642cb73..2efdb98 100644
64390--- a/include/linux/skbuff.h
64391+++ b/include/linux/skbuff.h
64392@@ -567,7 +567,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64393 extern struct sk_buff *__alloc_skb(unsigned int size,
64394 gfp_t priority, int fclone, int node);
64395 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64396-static inline struct sk_buff *alloc_skb(unsigned int size,
64397+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64398 gfp_t priority)
64399 {
64400 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64401@@ -680,7 +680,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64402 */
64403 static inline int skb_queue_empty(const struct sk_buff_head *list)
64404 {
64405- return list->next == (struct sk_buff *)list;
64406+ return list->next == (const struct sk_buff *)list;
64407 }
64408
64409 /**
64410@@ -693,7 +693,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64411 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64412 const struct sk_buff *skb)
64413 {
64414- return skb->next == (struct sk_buff *)list;
64415+ return skb->next == (const struct sk_buff *)list;
64416 }
64417
64418 /**
64419@@ -706,7 +706,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64420 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64421 const struct sk_buff *skb)
64422 {
64423- return skb->prev == (struct sk_buff *)list;
64424+ return skb->prev == (const struct sk_buff *)list;
64425 }
64426
64427 /**
64428@@ -1605,7 +1605,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64429 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64430 */
64431 #ifndef NET_SKB_PAD
64432-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64433+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64434 #endif
64435
64436 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64437@@ -2112,7 +2112,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64438 int noblock, int *err);
64439 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64440 struct poll_table_struct *wait);
64441-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64442+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64443 int offset, struct iovec *to,
64444 int size);
64445 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64446diff --git a/include/linux/slab.h b/include/linux/slab.h
64447index 67d5d94..bbd740b 100644
64448--- a/include/linux/slab.h
64449+++ b/include/linux/slab.h
64450@@ -11,12 +11,20 @@
64451
64452 #include <linux/gfp.h>
64453 #include <linux/types.h>
64454+#include <linux/err.h>
64455
64456 /*
64457 * Flags to pass to kmem_cache_create().
64458 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64459 */
64460 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64461+
64462+#ifdef CONFIG_PAX_USERCOPY_SLABS
64463+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64464+#else
64465+#define SLAB_USERCOPY 0x00000000UL
64466+#endif
64467+
64468 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64469 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64470 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64471@@ -87,10 +95,13 @@
64472 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64473 * Both make kfree a no-op.
64474 */
64475-#define ZERO_SIZE_PTR ((void *)16)
64476+#define ZERO_SIZE_PTR \
64477+({ \
64478+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64479+ (void *)(-MAX_ERRNO-1L); \
64480+})
64481
64482-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64483- (unsigned long)ZERO_SIZE_PTR)
64484+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64485
64486 /*
64487 * struct kmem_cache related prototypes
64488@@ -161,6 +172,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64489 void kfree(const void *);
64490 void kzfree(const void *);
64491 size_t ksize(const void *);
64492+const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64493+bool is_usercopy_object(const void *ptr);
64494
64495 /*
64496 * Allocator specific definitions. These are mainly used to establish optimized
64497@@ -298,7 +311,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64498 */
64499 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64500 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64501-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64502+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64503 #define kmalloc_track_caller(size, flags) \
64504 __kmalloc_track_caller(size, flags, _RET_IP_)
64505 #else
64506@@ -317,7 +330,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64507 */
64508 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64509 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64510-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64511+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64512 #define kmalloc_node_track_caller(size, flags, node) \
64513 __kmalloc_node_track_caller(size, flags, node, \
64514 _RET_IP_)
64515diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64516index fbd1117..0a3d314 100644
64517--- a/include/linux/slab_def.h
64518+++ b/include/linux/slab_def.h
64519@@ -66,10 +66,10 @@ struct kmem_cache {
64520 unsigned long node_allocs;
64521 unsigned long node_frees;
64522 unsigned long node_overflow;
64523- atomic_t allochit;
64524- atomic_t allocmiss;
64525- atomic_t freehit;
64526- atomic_t freemiss;
64527+ atomic_unchecked_t allochit;
64528+ atomic_unchecked_t allocmiss;
64529+ atomic_unchecked_t freehit;
64530+ atomic_unchecked_t freemiss;
64531
64532 /*
64533 * If debugging is enabled, then the allocator can add additional
64534@@ -103,11 +103,16 @@ struct cache_sizes {
64535 #ifdef CONFIG_ZONE_DMA
64536 struct kmem_cache *cs_dmacachep;
64537 #endif
64538+
64539+#ifdef CONFIG_PAX_USERCOPY_SLABS
64540+ struct kmem_cache *cs_usercopycachep;
64541+#endif
64542+
64543 };
64544 extern struct cache_sizes malloc_sizes[];
64545
64546 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64547-void *__kmalloc(size_t size, gfp_t flags);
64548+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64549
64550 #ifdef CONFIG_TRACING
64551 extern void *kmem_cache_alloc_trace(size_t size,
64552@@ -150,6 +155,13 @@ found:
64553 cachep = malloc_sizes[i].cs_dmacachep;
64554 else
64555 #endif
64556+
64557+#ifdef CONFIG_PAX_USERCOPY_SLABS
64558+ if (flags & GFP_USERCOPY)
64559+ cachep = malloc_sizes[i].cs_usercopycachep;
64560+ else
64561+#endif
64562+
64563 cachep = malloc_sizes[i].cs_cachep;
64564
64565 ret = kmem_cache_alloc_trace(size, cachep, flags);
64566@@ -160,7 +172,7 @@ found:
64567 }
64568
64569 #ifdef CONFIG_NUMA
64570-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64571+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64572 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64573
64574 #ifdef CONFIG_TRACING
64575@@ -203,6 +215,13 @@ found:
64576 cachep = malloc_sizes[i].cs_dmacachep;
64577 else
64578 #endif
64579+
64580+#ifdef CONFIG_PAX_USERCOPY_SLABS
64581+ if (flags & GFP_USERCOPY)
64582+ cachep = malloc_sizes[i].cs_usercopycachep;
64583+ else
64584+#endif
64585+
64586 cachep = malloc_sizes[i].cs_cachep;
64587
64588 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64589diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64590index 0ec00b3..22b4715 100644
64591--- a/include/linux/slob_def.h
64592+++ b/include/linux/slob_def.h
64593@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64594 return kmem_cache_alloc_node(cachep, flags, -1);
64595 }
64596
64597-void *__kmalloc_node(size_t size, gfp_t flags, int node);
64598+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64599
64600 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64601 {
64602@@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64603 return __kmalloc_node(size, flags, -1);
64604 }
64605
64606-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64607+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64608 {
64609 return kmalloc(size, flags);
64610 }
64611diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64612index c2f8c8b..d992a41 100644
64613--- a/include/linux/slub_def.h
64614+++ b/include/linux/slub_def.h
64615@@ -92,7 +92,7 @@ struct kmem_cache {
64616 struct kmem_cache_order_objects max;
64617 struct kmem_cache_order_objects min;
64618 gfp_t allocflags; /* gfp flags to use on each alloc */
64619- int refcount; /* Refcount for slab cache destroy */
64620+ atomic_t refcount; /* Refcount for slab cache destroy */
64621 void (*ctor)(void *);
64622 int inuse; /* Offset to metadata */
64623 int align; /* Alignment */
64624@@ -153,7 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64625 * Sorry that the following has to be that ugly but some versions of GCC
64626 * have trouble with constant propagation and loops.
64627 */
64628-static __always_inline int kmalloc_index(size_t size)
64629+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64630 {
64631 if (!size)
64632 return 0;
64633@@ -218,7 +218,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64634 }
64635
64636 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64637-void *__kmalloc(size_t size, gfp_t flags);
64638+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64639
64640 static __always_inline void *
64641 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64642@@ -259,7 +259,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64643 }
64644 #endif
64645
64646-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64647+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64648 {
64649 unsigned int order = get_order(size);
64650 return kmalloc_order_trace(size, flags, order);
64651@@ -284,7 +284,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64652 }
64653
64654 #ifdef CONFIG_NUMA
64655-void *__kmalloc_node(size_t size, gfp_t flags, int node);
64656+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64657 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64658
64659 #ifdef CONFIG_TRACING
64660diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64661index de8832d..0147b46 100644
64662--- a/include/linux/sonet.h
64663+++ b/include/linux/sonet.h
64664@@ -61,7 +61,7 @@ struct sonet_stats {
64665 #include <linux/atomic.h>
64666
64667 struct k_sonet_stats {
64668-#define __HANDLE_ITEM(i) atomic_t i
64669+#define __HANDLE_ITEM(i) atomic_unchecked_t i
64670 __SONET_ITEMS
64671 #undef __HANDLE_ITEM
64672 };
64673diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64674index 523547e..2cb7140 100644
64675--- a/include/linux/sunrpc/clnt.h
64676+++ b/include/linux/sunrpc/clnt.h
64677@@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64678 {
64679 switch (sap->sa_family) {
64680 case AF_INET:
64681- return ntohs(((struct sockaddr_in *)sap)->sin_port);
64682+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64683 case AF_INET6:
64684- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64685+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64686 }
64687 return 0;
64688 }
64689@@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64690 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64691 const struct sockaddr *src)
64692 {
64693- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64694+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64695 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64696
64697 dsin->sin_family = ssin->sin_family;
64698@@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64699 if (sa->sa_family != AF_INET6)
64700 return 0;
64701
64702- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64703+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64704 }
64705
64706 #endif /* __KERNEL__ */
64707diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64708index dc0c3cc..8503fb6 100644
64709--- a/include/linux/sunrpc/sched.h
64710+++ b/include/linux/sunrpc/sched.h
64711@@ -106,6 +106,7 @@ struct rpc_call_ops {
64712 void (*rpc_count_stats)(struct rpc_task *, void *);
64713 void (*rpc_release)(void *);
64714 };
64715+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64716
64717 struct rpc_task_setup {
64718 struct rpc_task *task;
64719diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64720index 0b8e3e6..33e0a01 100644
64721--- a/include/linux/sunrpc/svc_rdma.h
64722+++ b/include/linux/sunrpc/svc_rdma.h
64723@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64724 extern unsigned int svcrdma_max_requests;
64725 extern unsigned int svcrdma_max_req_size;
64726
64727-extern atomic_t rdma_stat_recv;
64728-extern atomic_t rdma_stat_read;
64729-extern atomic_t rdma_stat_write;
64730-extern atomic_t rdma_stat_sq_starve;
64731-extern atomic_t rdma_stat_rq_starve;
64732-extern atomic_t rdma_stat_rq_poll;
64733-extern atomic_t rdma_stat_rq_prod;
64734-extern atomic_t rdma_stat_sq_poll;
64735-extern atomic_t rdma_stat_sq_prod;
64736+extern atomic_unchecked_t rdma_stat_recv;
64737+extern atomic_unchecked_t rdma_stat_read;
64738+extern atomic_unchecked_t rdma_stat_write;
64739+extern atomic_unchecked_t rdma_stat_sq_starve;
64740+extern atomic_unchecked_t rdma_stat_rq_starve;
64741+extern atomic_unchecked_t rdma_stat_rq_poll;
64742+extern atomic_unchecked_t rdma_stat_rq_prod;
64743+extern atomic_unchecked_t rdma_stat_sq_poll;
64744+extern atomic_unchecked_t rdma_stat_sq_prod;
64745
64746 #define RPCRDMA_VERSION 1
64747
64748diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64749index c34b4c8..a65b67d 100644
64750--- a/include/linux/sysctl.h
64751+++ b/include/linux/sysctl.h
64752@@ -155,7 +155,11 @@ enum
64753 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64754 };
64755
64756-
64757+#ifdef CONFIG_PAX_SOFTMODE
64758+enum {
64759+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64760+};
64761+#endif
64762
64763 /* CTL_VM names: */
64764 enum
64765@@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64766
64767 extern int proc_dostring(struct ctl_table *, int,
64768 void __user *, size_t *, loff_t *);
64769+extern int proc_dostring_modpriv(struct ctl_table *, int,
64770+ void __user *, size_t *, loff_t *);
64771 extern int proc_dointvec(struct ctl_table *, int,
64772 void __user *, size_t *, loff_t *);
64773 extern int proc_dointvec_minmax(struct ctl_table *, int,
64774diff --git a/include/linux/tty.h b/include/linux/tty.h
64775index 9f47ab5..73da944 100644
64776--- a/include/linux/tty.h
64777+++ b/include/linux/tty.h
64778@@ -225,7 +225,7 @@ struct tty_port {
64779 const struct tty_port_operations *ops; /* Port operations */
64780 spinlock_t lock; /* Lock protecting tty field */
64781 int blocked_open; /* Waiting to open */
64782- int count; /* Usage count */
64783+ atomic_t count; /* Usage count */
64784 wait_queue_head_t open_wait; /* Open waiters */
64785 wait_queue_head_t close_wait; /* Close waiters */
64786 wait_queue_head_t delta_msr_wait; /* Modem status change */
64787@@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64788 struct tty_struct *tty, struct file *filp);
64789 static inline int tty_port_users(struct tty_port *port)
64790 {
64791- return port->count + port->blocked_open;
64792+ return atomic_read(&port->count) + port->blocked_open;
64793 }
64794
64795 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64796diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64797index fb79dd8d..07d4773 100644
64798--- a/include/linux/tty_ldisc.h
64799+++ b/include/linux/tty_ldisc.h
64800@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64801
64802 struct module *owner;
64803
64804- int refcount;
64805+ atomic_t refcount;
64806 };
64807
64808 struct tty_ldisc {
64809diff --git a/include/linux/types.h b/include/linux/types.h
64810index 9c1bd53..c2370f6 100644
64811--- a/include/linux/types.h
64812+++ b/include/linux/types.h
64813@@ -220,10 +220,26 @@ typedef struct {
64814 int counter;
64815 } atomic_t;
64816
64817+#ifdef CONFIG_PAX_REFCOUNT
64818+typedef struct {
64819+ int counter;
64820+} atomic_unchecked_t;
64821+#else
64822+typedef atomic_t atomic_unchecked_t;
64823+#endif
64824+
64825 #ifdef CONFIG_64BIT
64826 typedef struct {
64827 long counter;
64828 } atomic64_t;
64829+
64830+#ifdef CONFIG_PAX_REFCOUNT
64831+typedef struct {
64832+ long counter;
64833+} atomic64_unchecked_t;
64834+#else
64835+typedef atomic64_t atomic64_unchecked_t;
64836+#endif
64837 #endif
64838
64839 struct list_head {
64840diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64841index 5ca0951..ab496a5 100644
64842--- a/include/linux/uaccess.h
64843+++ b/include/linux/uaccess.h
64844@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64845 long ret; \
64846 mm_segment_t old_fs = get_fs(); \
64847 \
64848- set_fs(KERNEL_DS); \
64849 pagefault_disable(); \
64850- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64851- pagefault_enable(); \
64852+ set_fs(KERNEL_DS); \
64853+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64854 set_fs(old_fs); \
64855+ pagefault_enable(); \
64856 ret; \
64857 })
64858
64859diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64860index 99c1b4d..bb94261 100644
64861--- a/include/linux/unaligned/access_ok.h
64862+++ b/include/linux/unaligned/access_ok.h
64863@@ -6,32 +6,32 @@
64864
64865 static inline u16 get_unaligned_le16(const void *p)
64866 {
64867- return le16_to_cpup((__le16 *)p);
64868+ return le16_to_cpup((const __le16 *)p);
64869 }
64870
64871 static inline u32 get_unaligned_le32(const void *p)
64872 {
64873- return le32_to_cpup((__le32 *)p);
64874+ return le32_to_cpup((const __le32 *)p);
64875 }
64876
64877 static inline u64 get_unaligned_le64(const void *p)
64878 {
64879- return le64_to_cpup((__le64 *)p);
64880+ return le64_to_cpup((const __le64 *)p);
64881 }
64882
64883 static inline u16 get_unaligned_be16(const void *p)
64884 {
64885- return be16_to_cpup((__be16 *)p);
64886+ return be16_to_cpup((const __be16 *)p);
64887 }
64888
64889 static inline u32 get_unaligned_be32(const void *p)
64890 {
64891- return be32_to_cpup((__be32 *)p);
64892+ return be32_to_cpup((const __be32 *)p);
64893 }
64894
64895 static inline u64 get_unaligned_be64(const void *p)
64896 {
64897- return be64_to_cpup((__be64 *)p);
64898+ return be64_to_cpup((const __be64 *)p);
64899 }
64900
64901 static inline void put_unaligned_le16(u16 val, void *p)
64902diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64903index 547e59c..db6ad19 100644
64904--- a/include/linux/usb/renesas_usbhs.h
64905+++ b/include/linux/usb/renesas_usbhs.h
64906@@ -39,7 +39,7 @@ enum {
64907 */
64908 struct renesas_usbhs_driver_callback {
64909 int (*notify_hotplug)(struct platform_device *pdev);
64910-};
64911+} __no_const;
64912
64913 /*
64914 * callback functions for platform
64915@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64916 * VBUS control is needed for Host
64917 */
64918 int (*set_vbus)(struct platform_device *pdev, int enable);
64919-};
64920+} __no_const;
64921
64922 /*
64923 * parameters for renesas usbhs
64924diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64925index 6f8fbcf..8259001 100644
64926--- a/include/linux/vermagic.h
64927+++ b/include/linux/vermagic.h
64928@@ -25,9 +25,35 @@
64929 #define MODULE_ARCH_VERMAGIC ""
64930 #endif
64931
64932+#ifdef CONFIG_PAX_REFCOUNT
64933+#define MODULE_PAX_REFCOUNT "REFCOUNT "
64934+#else
64935+#define MODULE_PAX_REFCOUNT ""
64936+#endif
64937+
64938+#ifdef CONSTIFY_PLUGIN
64939+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64940+#else
64941+#define MODULE_CONSTIFY_PLUGIN ""
64942+#endif
64943+
64944+#ifdef STACKLEAK_PLUGIN
64945+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64946+#else
64947+#define MODULE_STACKLEAK_PLUGIN ""
64948+#endif
64949+
64950+#ifdef CONFIG_GRKERNSEC
64951+#define MODULE_GRSEC "GRSEC "
64952+#else
64953+#define MODULE_GRSEC ""
64954+#endif
64955+
64956 #define VERMAGIC_STRING \
64957 UTS_RELEASE " " \
64958 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64959 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64960- MODULE_ARCH_VERMAGIC
64961+ MODULE_ARCH_VERMAGIC \
64962+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64963+ MODULE_GRSEC
64964
64965diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64966index dcdfc2b..ec79ab5 100644
64967--- a/include/linux/vmalloc.h
64968+++ b/include/linux/vmalloc.h
64969@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64970 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64971 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64972 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64973+
64974+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64975+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64976+#endif
64977+
64978 /* bits [20..32] reserved for arch specific ioremap internals */
64979
64980 /*
64981@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64982 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64983 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64984 unsigned long start, unsigned long end, gfp_t gfp_mask,
64985- pgprot_t prot, int node, void *caller);
64986+ pgprot_t prot, int node, void *caller) __size_overflow(1);
64987 extern void vfree(const void *addr);
64988
64989 extern void *vmap(struct page **pages, unsigned int count,
64990@@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64991 extern void free_vm_area(struct vm_struct *area);
64992
64993 /* for /dev/kmem */
64994-extern long vread(char *buf, char *addr, unsigned long count);
64995-extern long vwrite(char *buf, char *addr, unsigned long count);
64996+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64997+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64998
64999 /*
65000 * Internals. Dont't use..
65001diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
65002index 65efb92..137adbb 100644
65003--- a/include/linux/vmstat.h
65004+++ b/include/linux/vmstat.h
65005@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
65006 /*
65007 * Zone based page accounting with per cpu differentials.
65008 */
65009-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65010+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65011
65012 static inline void zone_page_state_add(long x, struct zone *zone,
65013 enum zone_stat_item item)
65014 {
65015- atomic_long_add(x, &zone->vm_stat[item]);
65016- atomic_long_add(x, &vm_stat[item]);
65017+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65018+ atomic_long_add_unchecked(x, &vm_stat[item]);
65019 }
65020
65021 static inline unsigned long global_page_state(enum zone_stat_item item)
65022 {
65023- long x = atomic_long_read(&vm_stat[item]);
65024+ long x = atomic_long_read_unchecked(&vm_stat[item]);
65025 #ifdef CONFIG_SMP
65026 if (x < 0)
65027 x = 0;
65028@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
65029 static inline unsigned long zone_page_state(struct zone *zone,
65030 enum zone_stat_item item)
65031 {
65032- long x = atomic_long_read(&zone->vm_stat[item]);
65033+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65034 #ifdef CONFIG_SMP
65035 if (x < 0)
65036 x = 0;
65037@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
65038 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65039 enum zone_stat_item item)
65040 {
65041- long x = atomic_long_read(&zone->vm_stat[item]);
65042+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65043
65044 #ifdef CONFIG_SMP
65045 int cpu;
65046@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
65047
65048 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65049 {
65050- atomic_long_inc(&zone->vm_stat[item]);
65051- atomic_long_inc(&vm_stat[item]);
65052+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
65053+ atomic_long_inc_unchecked(&vm_stat[item]);
65054 }
65055
65056 static inline void __inc_zone_page_state(struct page *page,
65057@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
65058
65059 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65060 {
65061- atomic_long_dec(&zone->vm_stat[item]);
65062- atomic_long_dec(&vm_stat[item]);
65063+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
65064+ atomic_long_dec_unchecked(&vm_stat[item]);
65065 }
65066
65067 static inline void __dec_zone_page_state(struct page *page,
65068diff --git a/include/linux/xattr.h b/include/linux/xattr.h
65069index e5d1220..ef6e406 100644
65070--- a/include/linux/xattr.h
65071+++ b/include/linux/xattr.h
65072@@ -57,6 +57,11 @@
65073 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65074 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65075
65076+/* User namespace */
65077+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65078+#define XATTR_PAX_FLAGS_SUFFIX "flags"
65079+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65080+
65081 #ifdef __KERNEL__
65082
65083 #include <linux/types.h>
65084diff --git a/include/linux/xfrm.h b/include/linux/xfrm.h
65085index 22e61fd..28e493b 100644
65086--- a/include/linux/xfrm.h
65087+++ b/include/linux/xfrm.h
65088@@ -84,6 +84,8 @@ struct xfrm_replay_state {
65089 __u32 bitmap;
65090 };
65091
65092+#define XFRMA_REPLAY_ESN_MAX 4096
65093+
65094 struct xfrm_replay_state_esn {
65095 unsigned int bmp_len;
65096 __u32 oseq;
65097diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
65098index 944ecdf..a3994fc 100644
65099--- a/include/media/saa7146_vv.h
65100+++ b/include/media/saa7146_vv.h
65101@@ -161,8 +161,8 @@ struct saa7146_ext_vv
65102 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65103
65104 /* the extension can override this */
65105- struct v4l2_ioctl_ops vid_ops;
65106- struct v4l2_ioctl_ops vbi_ops;
65107+ v4l2_ioctl_ops_no_const vid_ops;
65108+ v4l2_ioctl_ops_no_const vbi_ops;
65109 /* pointer to the saa7146 core ops */
65110 const struct v4l2_ioctl_ops *core_ops;
65111
65112diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65113index a056e6e..31023a5 100644
65114--- a/include/media/v4l2-dev.h
65115+++ b/include/media/v4l2-dev.h
65116@@ -73,7 +73,8 @@ struct v4l2_file_operations {
65117 int (*mmap) (struct file *, struct vm_area_struct *);
65118 int (*open) (struct file *);
65119 int (*release) (struct file *);
65120-};
65121+} __do_const;
65122+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65123
65124 /*
65125 * Newer version of video_device, handled by videodev2.c
65126diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65127index d8b76f7..7d5aa18 100644
65128--- a/include/media/v4l2-ioctl.h
65129+++ b/include/media/v4l2-ioctl.h
65130@@ -287,7 +287,7 @@ struct v4l2_ioctl_ops {
65131 long (*vidioc_default) (struct file *file, void *fh,
65132 bool valid_prio, int cmd, void *arg);
65133 };
65134-
65135+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65136
65137 /* v4l debugging and diagnostics */
65138
65139diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65140index 439dadc..1c67e3f 100644
65141--- a/include/net/caif/caif_hsi.h
65142+++ b/include/net/caif/caif_hsi.h
65143@@ -98,7 +98,7 @@ struct cfhsi_drv {
65144 void (*rx_done_cb) (struct cfhsi_drv *drv);
65145 void (*wake_up_cb) (struct cfhsi_drv *drv);
65146 void (*wake_down_cb) (struct cfhsi_drv *drv);
65147-};
65148+} __no_const;
65149
65150 /* Structure implemented by HSI device. */
65151 struct cfhsi_dev {
65152diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65153index 9e5425b..8136ffc 100644
65154--- a/include/net/caif/cfctrl.h
65155+++ b/include/net/caif/cfctrl.h
65156@@ -52,7 +52,7 @@ struct cfctrl_rsp {
65157 void (*radioset_rsp)(void);
65158 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65159 struct cflayer *client_layer);
65160-};
65161+} __no_const;
65162
65163 /* Link Setup Parameters for CAIF-Links. */
65164 struct cfctrl_link_param {
65165@@ -101,8 +101,8 @@ struct cfctrl_request_info {
65166 struct cfctrl {
65167 struct cfsrvl serv;
65168 struct cfctrl_rsp res;
65169- atomic_t req_seq_no;
65170- atomic_t rsp_seq_no;
65171+ atomic_unchecked_t req_seq_no;
65172+ atomic_unchecked_t rsp_seq_no;
65173 struct list_head list;
65174 /* Protects from simultaneous access to first_req list */
65175 spinlock_t info_list_lock;
65176diff --git a/include/net/flow.h b/include/net/flow.h
65177index 6c469db..7743b8e 100644
65178--- a/include/net/flow.h
65179+++ b/include/net/flow.h
65180@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65181
65182 extern void flow_cache_flush(void);
65183 extern void flow_cache_flush_deferred(void);
65184-extern atomic_t flow_cache_genid;
65185+extern atomic_unchecked_t flow_cache_genid;
65186
65187 #endif
65188diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65189index 2040bff..f4c0733 100644
65190--- a/include/net/inetpeer.h
65191+++ b/include/net/inetpeer.h
65192@@ -51,8 +51,8 @@ struct inet_peer {
65193 */
65194 union {
65195 struct {
65196- atomic_t rid; /* Frag reception counter */
65197- atomic_t ip_id_count; /* IP ID for the next packet */
65198+ atomic_unchecked_t rid; /* Frag reception counter */
65199+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65200 __u32 tcp_ts;
65201 __u32 tcp_ts_stamp;
65202 };
65203@@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65204 more++;
65205 inet_peer_refcheck(p);
65206 do {
65207- old = atomic_read(&p->ip_id_count);
65208+ old = atomic_read_unchecked(&p->ip_id_count);
65209 new = old + more;
65210 if (!new)
65211 new = 1;
65212- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65213+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65214 return new;
65215 }
65216
65217diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65218index 78df0866..00e5c9b 100644
65219--- a/include/net/ip_fib.h
65220+++ b/include/net/ip_fib.h
65221@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65222
65223 #define FIB_RES_SADDR(net, res) \
65224 ((FIB_RES_NH(res).nh_saddr_genid == \
65225- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65226+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65227 FIB_RES_NH(res).nh_saddr : \
65228 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65229 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65230diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65231index 95374d1..2300e36 100644
65232--- a/include/net/ip_vs.h
65233+++ b/include/net/ip_vs.h
65234@@ -510,7 +510,7 @@ struct ip_vs_conn {
65235 struct ip_vs_conn *control; /* Master control connection */
65236 atomic_t n_control; /* Number of controlled ones */
65237 struct ip_vs_dest *dest; /* real server */
65238- atomic_t in_pkts; /* incoming packet counter */
65239+ atomic_unchecked_t in_pkts; /* incoming packet counter */
65240
65241 /* packet transmitter for different forwarding methods. If it
65242 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65243@@ -648,7 +648,7 @@ struct ip_vs_dest {
65244 __be16 port; /* port number of the server */
65245 union nf_inet_addr addr; /* IP address of the server */
65246 volatile unsigned int flags; /* dest status flags */
65247- atomic_t conn_flags; /* flags to copy to conn */
65248+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
65249 atomic_t weight; /* server weight */
65250
65251 atomic_t refcnt; /* reference counter */
65252diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65253index 69b610a..fe3962c 100644
65254--- a/include/net/irda/ircomm_core.h
65255+++ b/include/net/irda/ircomm_core.h
65256@@ -51,7 +51,7 @@ typedef struct {
65257 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65258 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65259 struct ircomm_info *);
65260-} call_t;
65261+} __no_const call_t;
65262
65263 struct ircomm_cb {
65264 irda_queue_t queue;
65265diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65266index 59ba38bc..d515662 100644
65267--- a/include/net/irda/ircomm_tty.h
65268+++ b/include/net/irda/ircomm_tty.h
65269@@ -35,6 +35,7 @@
65270 #include <linux/termios.h>
65271 #include <linux/timer.h>
65272 #include <linux/tty.h> /* struct tty_struct */
65273+#include <asm/local.h>
65274
65275 #include <net/irda/irias_object.h>
65276 #include <net/irda/ircomm_core.h>
65277@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65278 unsigned short close_delay;
65279 unsigned short closing_wait; /* time to wait before closing */
65280
65281- int open_count;
65282- int blocked_open; /* # of blocked opens */
65283+ local_t open_count;
65284+ local_t blocked_open; /* # of blocked opens */
65285
65286 /* Protect concurent access to :
65287 * o self->open_count
65288diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65289index cc7c197..9f2da2a 100644
65290--- a/include/net/iucv/af_iucv.h
65291+++ b/include/net/iucv/af_iucv.h
65292@@ -141,7 +141,7 @@ struct iucv_sock {
65293 struct iucv_sock_list {
65294 struct hlist_head head;
65295 rwlock_t lock;
65296- atomic_t autobind_name;
65297+ atomic_unchecked_t autobind_name;
65298 };
65299
65300 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65301diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65302index 6cdfeed..55a0256 100644
65303--- a/include/net/neighbour.h
65304+++ b/include/net/neighbour.h
65305@@ -123,7 +123,7 @@ struct neigh_ops {
65306 void (*error_report)(struct neighbour *, struct sk_buff *);
65307 int (*output)(struct neighbour *, struct sk_buff *);
65308 int (*connected_output)(struct neighbour *, struct sk_buff *);
65309-};
65310+} __do_const;
65311
65312 struct pneigh_entry {
65313 struct pneigh_entry *next;
65314diff --git a/include/net/netdma.h b/include/net/netdma.h
65315index 8ba8ce2..99b7fff 100644
65316--- a/include/net/netdma.h
65317+++ b/include/net/netdma.h
65318@@ -24,7 +24,7 @@
65319 #include <linux/dmaengine.h>
65320 #include <linux/skbuff.h>
65321
65322-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65323+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65324 struct sk_buff *skb, int offset, struct iovec *to,
65325 size_t len, struct dma_pinned_list *pinned_list);
65326
65327diff --git a/include/net/netlink.h b/include/net/netlink.h
65328index 785f37a..c81dc0c 100644
65329--- a/include/net/netlink.h
65330+++ b/include/net/netlink.h
65331@@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65332 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65333 {
65334 if (mark)
65335- skb_trim(skb, (unsigned char *) mark - skb->data);
65336+ skb_trim(skb, (const unsigned char *) mark - skb->data);
65337 }
65338
65339 /**
65340diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65341index bbd023a..97c6d0d 100644
65342--- a/include/net/netns/ipv4.h
65343+++ b/include/net/netns/ipv4.h
65344@@ -57,8 +57,8 @@ struct netns_ipv4 {
65345 unsigned int sysctl_ping_group_range[2];
65346 long sysctl_tcp_mem[3];
65347
65348- atomic_t rt_genid;
65349- atomic_t dev_addr_genid;
65350+ atomic_unchecked_t rt_genid;
65351+ atomic_unchecked_t dev_addr_genid;
65352
65353 #ifdef CONFIG_IP_MROUTE
65354 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65355diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65356index a2ef814..31a8e3f 100644
65357--- a/include/net/sctp/sctp.h
65358+++ b/include/net/sctp/sctp.h
65359@@ -318,9 +318,9 @@ do { \
65360
65361 #else /* SCTP_DEBUG */
65362
65363-#define SCTP_DEBUG_PRINTK(whatever...)
65364-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65365-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65366+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65367+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65368+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65369 #define SCTP_ENABLE_DEBUG
65370 #define SCTP_DISABLE_DEBUG
65371 #define SCTP_ASSERT(expr, str, func)
65372diff --git a/include/net/sock.h b/include/net/sock.h
65373index 5de6557..0bad07b 100644
65374--- a/include/net/sock.h
65375+++ b/include/net/sock.h
65376@@ -304,7 +304,7 @@ struct sock {
65377 #ifdef CONFIG_RPS
65378 __u32 sk_rxhash;
65379 #endif
65380- atomic_t sk_drops;
65381+ atomic_unchecked_t sk_drops;
65382 int sk_rcvbuf;
65383
65384 struct sk_filter __rcu *sk_filter;
65385@@ -1728,7 +1728,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65386 }
65387
65388 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65389- char __user *from, char *to,
65390+ char __user *from, unsigned char *to,
65391 int copy, int offset)
65392 {
65393 if (skb->ip_summed == CHECKSUM_NONE) {
65394@@ -1987,7 +1987,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65395 }
65396 }
65397
65398-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65399+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65400
65401 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65402 {
65403diff --git a/include/net/tcp.h b/include/net/tcp.h
65404index e79aa48..05e52de 100644
65405--- a/include/net/tcp.h
65406+++ b/include/net/tcp.h
65407@@ -476,7 +476,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65408 extern void tcp_xmit_retransmit_queue(struct sock *);
65409 extern void tcp_simple_retransmit(struct sock *);
65410 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65411-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65412+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65413
65414 extern void tcp_send_probe0(struct sock *);
65415 extern void tcp_send_partial(struct sock *);
65416@@ -643,8 +643,8 @@ struct tcp_skb_cb {
65417 struct inet6_skb_parm h6;
65418 #endif
65419 } header; /* For incoming frames */
65420- __u32 seq; /* Starting sequence number */
65421- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65422+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
65423+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65424 __u32 when; /* used to compute rtt's */
65425 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65426
65427@@ -658,7 +658,7 @@ struct tcp_skb_cb {
65428
65429 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65430 /* 1 byte hole */
65431- __u32 ack_seq; /* Sequence number ACK'd */
65432+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65433 };
65434
65435 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65436@@ -1459,7 +1459,7 @@ struct tcp_seq_afinfo {
65437 char *name;
65438 sa_family_t family;
65439 const struct file_operations *seq_fops;
65440- struct seq_operations seq_ops;
65441+ seq_operations_no_const seq_ops;
65442 };
65443
65444 struct tcp_iter_state {
65445diff --git a/include/net/udp.h b/include/net/udp.h
65446index 065f379..b661b40 100644
65447--- a/include/net/udp.h
65448+++ b/include/net/udp.h
65449@@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65450 sa_family_t family;
65451 struct udp_table *udp_table;
65452 const struct file_operations *seq_fops;
65453- struct seq_operations seq_ops;
65454+ seq_operations_no_const seq_ops;
65455 };
65456
65457 struct udp_iter_state {
65458diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65459index e0a55df..5890bca07 100644
65460--- a/include/net/xfrm.h
65461+++ b/include/net/xfrm.h
65462@@ -505,7 +505,7 @@ struct xfrm_policy {
65463 struct timer_list timer;
65464
65465 struct flow_cache_object flo;
65466- atomic_t genid;
65467+ atomic_unchecked_t genid;
65468 u32 priority;
65469 u32 index;
65470 struct xfrm_mark mark;
65471diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65472index 1a046b1..ee0bef0 100644
65473--- a/include/rdma/iw_cm.h
65474+++ b/include/rdma/iw_cm.h
65475@@ -122,7 +122,7 @@ struct iw_cm_verbs {
65476 int backlog);
65477
65478 int (*destroy_listen)(struct iw_cm_id *cm_id);
65479-};
65480+} __no_const;
65481
65482 /**
65483 * iw_create_cm_id - Create an IW CM identifier.
65484diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65485index 8f9dfba..610ab6c 100644
65486--- a/include/scsi/libfc.h
65487+++ b/include/scsi/libfc.h
65488@@ -756,6 +756,7 @@ struct libfc_function_template {
65489 */
65490 void (*disc_stop_final) (struct fc_lport *);
65491 };
65492+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65493
65494 /**
65495 * struct fc_disc - Discovery context
65496@@ -861,7 +862,7 @@ struct fc_lport {
65497 struct fc_vport *vport;
65498
65499 /* Operational Information */
65500- struct libfc_function_template tt;
65501+ libfc_function_template_no_const tt;
65502 u8 link_up;
65503 u8 qfull;
65504 enum fc_lport_state state;
65505diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65506index ba96988..ecf2eb9 100644
65507--- a/include/scsi/scsi_device.h
65508+++ b/include/scsi/scsi_device.h
65509@@ -163,9 +163,9 @@ struct scsi_device {
65510 unsigned int max_device_blocked; /* what device_blocked counts down from */
65511 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65512
65513- atomic_t iorequest_cnt;
65514- atomic_t iodone_cnt;
65515- atomic_t ioerr_cnt;
65516+ atomic_unchecked_t iorequest_cnt;
65517+ atomic_unchecked_t iodone_cnt;
65518+ atomic_unchecked_t ioerr_cnt;
65519
65520 struct device sdev_gendev,
65521 sdev_dev;
65522diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65523index 719faf1..07b6728 100644
65524--- a/include/scsi/scsi_transport_fc.h
65525+++ b/include/scsi/scsi_transport_fc.h
65526@@ -739,7 +739,8 @@ struct fc_function_template {
65527 unsigned long show_host_system_hostname:1;
65528
65529 unsigned long disable_target_scan:1;
65530-};
65531+} __do_const;
65532+typedef struct fc_function_template __no_const fc_function_template_no_const;
65533
65534
65535 /**
65536diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65537index 030b87c..98a6954 100644
65538--- a/include/sound/ak4xxx-adda.h
65539+++ b/include/sound/ak4xxx-adda.h
65540@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65541 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65542 unsigned char val);
65543 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65544-};
65545+} __no_const;
65546
65547 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65548
65549diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65550index 8c05e47..2b5df97 100644
65551--- a/include/sound/hwdep.h
65552+++ b/include/sound/hwdep.h
65553@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65554 struct snd_hwdep_dsp_status *status);
65555 int (*dsp_load)(struct snd_hwdep *hw,
65556 struct snd_hwdep_dsp_image *image);
65557-};
65558+} __no_const;
65559
65560 struct snd_hwdep {
65561 struct snd_card *card;
65562diff --git a/include/sound/info.h b/include/sound/info.h
65563index 9ca1a49..aba1728 100644
65564--- a/include/sound/info.h
65565+++ b/include/sound/info.h
65566@@ -44,7 +44,7 @@ struct snd_info_entry_text {
65567 struct snd_info_buffer *buffer);
65568 void (*write)(struct snd_info_entry *entry,
65569 struct snd_info_buffer *buffer);
65570-};
65571+} __no_const;
65572
65573 struct snd_info_entry_ops {
65574 int (*open)(struct snd_info_entry *entry,
65575diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65576index 0d11128..814178e 100644
65577--- a/include/sound/pcm.h
65578+++ b/include/sound/pcm.h
65579@@ -81,6 +81,7 @@ struct snd_pcm_ops {
65580 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65581 int (*ack)(struct snd_pcm_substream *substream);
65582 };
65583+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65584
65585 /*
65586 *
65587diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65588index af1b49e..a5d55a5 100644
65589--- a/include/sound/sb16_csp.h
65590+++ b/include/sound/sb16_csp.h
65591@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65592 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65593 int (*csp_stop) (struct snd_sb_csp * p);
65594 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65595-};
65596+} __no_const;
65597
65598 /*
65599 * CSP private data
65600diff --git a/include/sound/soc.h b/include/sound/soc.h
65601index c703871..f7fbbbd 100644
65602--- a/include/sound/soc.h
65603+++ b/include/sound/soc.h
65604@@ -757,7 +757,7 @@ struct snd_soc_platform_driver {
65605 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65606 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65607 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65608-};
65609+} __do_const;
65610
65611 struct snd_soc_platform {
65612 const char *name;
65613@@ -949,7 +949,7 @@ struct snd_soc_pcm_runtime {
65614 struct snd_soc_dai_link *dai_link;
65615 struct mutex pcm_mutex;
65616 enum snd_soc_pcm_subclass pcm_subclass;
65617- struct snd_pcm_ops ops;
65618+ snd_pcm_ops_no_const ops;
65619
65620 unsigned int dev_registered:1;
65621
65622diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65623index 0c3c2fb..d9d9990 100644
65624--- a/include/sound/tea575x-tuner.h
65625+++ b/include/sound/tea575x-tuner.h
65626@@ -44,7 +44,7 @@ struct snd_tea575x_ops {
65627
65628 struct snd_tea575x {
65629 struct v4l2_device *v4l2_dev;
65630- struct v4l2_file_operations fops;
65631+ v4l2_file_operations_no_const fops;
65632 struct video_device vd; /* video device */
65633 int radio_nr; /* radio_nr */
65634 bool tea5759; /* 5759 chip is present */
65635diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
65636index 4119966..1a4671c 100644
65637--- a/include/sound/ymfpci.h
65638+++ b/include/sound/ymfpci.h
65639@@ -358,7 +358,7 @@ struct snd_ymfpci {
65640 spinlock_t reg_lock;
65641 spinlock_t voice_lock;
65642 wait_queue_head_t interrupt_sleep;
65643- atomic_t interrupt_sleep_count;
65644+ atomic_unchecked_t interrupt_sleep_count;
65645 struct snd_info_entry *proc_entry;
65646 const struct firmware *dsp_microcode;
65647 const struct firmware *controller_microcode;
65648diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65649index 362e0d9..36b9a83 100644
65650--- a/include/target/target_core_base.h
65651+++ b/include/target/target_core_base.h
65652@@ -441,7 +441,7 @@ struct t10_reservation_ops {
65653 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65654 int (*t10_pr_register)(struct se_cmd *);
65655 int (*t10_pr_clear)(struct se_cmd *);
65656-};
65657+} __no_const;
65658
65659 struct t10_reservation {
65660 /* Reservation effects all target ports */
65661@@ -780,7 +780,7 @@ struct se_device {
65662 spinlock_t stats_lock;
65663 /* Active commands on this virtual SE device */
65664 atomic_t simple_cmds;
65665- atomic_t dev_ordered_id;
65666+ atomic_unchecked_t dev_ordered_id;
65667 atomic_t execute_tasks;
65668 atomic_t dev_ordered_sync;
65669 atomic_t dev_qf_count;
65670diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65671new file mode 100644
65672index 0000000..2efe49d
65673--- /dev/null
65674+++ b/include/trace/events/fs.h
65675@@ -0,0 +1,53 @@
65676+#undef TRACE_SYSTEM
65677+#define TRACE_SYSTEM fs
65678+
65679+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65680+#define _TRACE_FS_H
65681+
65682+#include <linux/fs.h>
65683+#include <linux/tracepoint.h>
65684+
65685+TRACE_EVENT(do_sys_open,
65686+
65687+ TP_PROTO(char *filename, int flags, int mode),
65688+
65689+ TP_ARGS(filename, flags, mode),
65690+
65691+ TP_STRUCT__entry(
65692+ __string( filename, filename )
65693+ __field( int, flags )
65694+ __field( int, mode )
65695+ ),
65696+
65697+ TP_fast_assign(
65698+ __assign_str(filename, filename);
65699+ __entry->flags = flags;
65700+ __entry->mode = mode;
65701+ ),
65702+
65703+ TP_printk("\"%s\" %x %o",
65704+ __get_str(filename), __entry->flags, __entry->mode)
65705+);
65706+
65707+TRACE_EVENT(open_exec,
65708+
65709+ TP_PROTO(const char *filename),
65710+
65711+ TP_ARGS(filename),
65712+
65713+ TP_STRUCT__entry(
65714+ __string( filename, filename )
65715+ ),
65716+
65717+ TP_fast_assign(
65718+ __assign_str(filename, filename);
65719+ ),
65720+
65721+ TP_printk("\"%s\"",
65722+ __get_str(filename))
65723+);
65724+
65725+#endif /* _TRACE_FS_H */
65726+
65727+/* This part must be outside protection */
65728+#include <trace/define_trace.h>
65729diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65730index 1c09820..7f5ec79 100644
65731--- a/include/trace/events/irq.h
65732+++ b/include/trace/events/irq.h
65733@@ -36,7 +36,7 @@ struct softirq_action;
65734 */
65735 TRACE_EVENT(irq_handler_entry,
65736
65737- TP_PROTO(int irq, struct irqaction *action),
65738+ TP_PROTO(int irq, const struct irqaction *action),
65739
65740 TP_ARGS(irq, action),
65741
65742@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65743 */
65744 TRACE_EVENT(irq_handler_exit,
65745
65746- TP_PROTO(int irq, struct irqaction *action, int ret),
65747+ TP_PROTO(int irq, const struct irqaction *action, int ret),
65748
65749 TP_ARGS(irq, action, ret),
65750
65751diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65752index f9466fa..f4e2b81 100644
65753--- a/include/video/udlfb.h
65754+++ b/include/video/udlfb.h
65755@@ -53,10 +53,10 @@ struct dlfb_data {
65756 u32 pseudo_palette[256];
65757 int blank_mode; /*one of FB_BLANK_ */
65758 /* blit-only rendering path metrics, exposed through sysfs */
65759- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65760- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65761- atomic_t bytes_sent; /* to usb, after compression including overhead */
65762- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65763+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65764+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65765+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65766+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65767 };
65768
65769 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65770diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65771index 0993a22..32ba2fe 100644
65772--- a/include/video/uvesafb.h
65773+++ b/include/video/uvesafb.h
65774@@ -177,6 +177,7 @@ struct uvesafb_par {
65775 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65776 u8 pmi_setpal; /* PMI for palette changes */
65777 u16 *pmi_base; /* protected mode interface location */
65778+ u8 *pmi_code; /* protected mode code location */
65779 void *pmi_start;
65780 void *pmi_pal;
65781 u8 *vbe_state_orig; /*
65782diff --git a/init/Kconfig b/init/Kconfig
65783index d07dcf9..fa47d0e 100644
65784--- a/init/Kconfig
65785+++ b/init/Kconfig
65786@@ -835,6 +835,7 @@ endif # CGROUPS
65787
65788 config CHECKPOINT_RESTORE
65789 bool "Checkpoint/restore support" if EXPERT
65790+ depends on !GRKERNSEC
65791 default n
65792 help
65793 Enables additional kernel features in a sake of checkpoint/restore.
65794@@ -1014,6 +1015,7 @@ config UIDGID_CONVERTED
65795 # Security modules
65796 depends on SECURITY_TOMOYO = n
65797 depends on SECURITY_APPARMOR = n
65798+ depends on GRKERNSEC = n
65799
65800 config UIDGID_STRICT_TYPE_CHECKS
65801 bool "Require conversions between uid/gids and their internal representation"
65802@@ -1401,7 +1403,7 @@ config SLUB_DEBUG
65803
65804 config COMPAT_BRK
65805 bool "Disable heap randomization"
65806- default y
65807+ default n
65808 help
65809 Randomizing heap placement makes heap exploits harder, but it
65810 also breaks ancient binaries (including anything libc5 based).
65811@@ -1584,7 +1586,7 @@ config INIT_ALL_POSSIBLE
65812 config STOP_MACHINE
65813 bool
65814 default y
65815- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65816+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65817 help
65818 Need stop_machine() primitive.
65819
65820diff --git a/init/Makefile b/init/Makefile
65821index 7bc47ee..6da2dc7 100644
65822--- a/init/Makefile
65823+++ b/init/Makefile
65824@@ -2,6 +2,9 @@
65825 # Makefile for the linux kernel.
65826 #
65827
65828+ccflags-y := $(GCC_PLUGINS_CFLAGS)
65829+asflags-y := $(GCC_PLUGINS_AFLAGS)
65830+
65831 obj-y := main.o version.o mounts.o
65832 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65833 obj-y += noinitramfs.o
65834diff --git a/init/do_mounts.c b/init/do_mounts.c
65835index d3f0aee..c9322f5 100644
65836--- a/init/do_mounts.c
65837+++ b/init/do_mounts.c
65838@@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65839 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65840 {
65841 struct super_block *s;
65842- int err = sys_mount(name, "/root", fs, flags, data);
65843+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65844 if (err)
65845 return err;
65846
65847- sys_chdir("/root");
65848+ sys_chdir((const char __force_user *)"/root");
65849 s = current->fs->pwd.dentry->d_sb;
65850 ROOT_DEV = s->s_dev;
65851 printk(KERN_INFO
65852@@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65853 va_start(args, fmt);
65854 vsprintf(buf, fmt, args);
65855 va_end(args);
65856- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65857+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65858 if (fd >= 0) {
65859 sys_ioctl(fd, FDEJECT, 0);
65860 sys_close(fd);
65861 }
65862 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65863- fd = sys_open("/dev/console", O_RDWR, 0);
65864+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65865 if (fd >= 0) {
65866 sys_ioctl(fd, TCGETS, (long)&termios);
65867 termios.c_lflag &= ~ICANON;
65868 sys_ioctl(fd, TCSETSF, (long)&termios);
65869- sys_read(fd, &c, 1);
65870+ sys_read(fd, (char __user *)&c, 1);
65871 termios.c_lflag |= ICANON;
65872 sys_ioctl(fd, TCSETSF, (long)&termios);
65873 sys_close(fd);
65874@@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65875 mount_root();
65876 out:
65877 devtmpfs_mount("dev");
65878- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65879- sys_chroot(".");
65880+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65881+ sys_chroot((const char __force_user *)".");
65882 }
65883diff --git a/init/do_mounts.h b/init/do_mounts.h
65884index f5b978a..69dbfe8 100644
65885--- a/init/do_mounts.h
65886+++ b/init/do_mounts.h
65887@@ -15,15 +15,15 @@ extern int root_mountflags;
65888
65889 static inline int create_dev(char *name, dev_t dev)
65890 {
65891- sys_unlink(name);
65892- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65893+ sys_unlink((char __force_user *)name);
65894+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65895 }
65896
65897 #if BITS_PER_LONG == 32
65898 static inline u32 bstat(char *name)
65899 {
65900 struct stat64 stat;
65901- if (sys_stat64(name, &stat) != 0)
65902+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65903 return 0;
65904 if (!S_ISBLK(stat.st_mode))
65905 return 0;
65906@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65907 static inline u32 bstat(char *name)
65908 {
65909 struct stat stat;
65910- if (sys_newstat(name, &stat) != 0)
65911+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65912 return 0;
65913 if (!S_ISBLK(stat.st_mode))
65914 return 0;
65915diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65916index 135959a2..28a3f43 100644
65917--- a/init/do_mounts_initrd.c
65918+++ b/init/do_mounts_initrd.c
65919@@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65920 create_dev("/dev/root.old", Root_RAM0);
65921 /* mount initrd on rootfs' /root */
65922 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65923- sys_mkdir("/old", 0700);
65924- root_fd = sys_open("/", 0, 0);
65925- old_fd = sys_open("/old", 0, 0);
65926+ sys_mkdir((const char __force_user *)"/old", 0700);
65927+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
65928+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65929 /* move initrd over / and chdir/chroot in initrd root */
65930- sys_chdir("/root");
65931- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65932- sys_chroot(".");
65933+ sys_chdir((const char __force_user *)"/root");
65934+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65935+ sys_chroot((const char __force_user *)".");
65936
65937 /*
65938 * In case that a resume from disk is carried out by linuxrc or one of
65939@@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65940
65941 /* move initrd to rootfs' /old */
65942 sys_fchdir(old_fd);
65943- sys_mount("/", ".", NULL, MS_MOVE, NULL);
65944+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65945 /* switch root and cwd back to / of rootfs */
65946 sys_fchdir(root_fd);
65947- sys_chroot(".");
65948+ sys_chroot((const char __force_user *)".");
65949 sys_close(old_fd);
65950 sys_close(root_fd);
65951
65952 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65953- sys_chdir("/old");
65954+ sys_chdir((const char __force_user *)"/old");
65955 return;
65956 }
65957
65958@@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65959 mount_root();
65960
65961 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65962- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65963+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65964 if (!error)
65965 printk("okay\n");
65966 else {
65967- int fd = sys_open("/dev/root.old", O_RDWR, 0);
65968+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65969 if (error == -ENOENT)
65970 printk("/initrd does not exist. Ignored.\n");
65971 else
65972 printk("failed\n");
65973 printk(KERN_NOTICE "Unmounting old root\n");
65974- sys_umount("/old", MNT_DETACH);
65975+ sys_umount((char __force_user *)"/old", MNT_DETACH);
65976 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65977 if (fd < 0) {
65978 error = fd;
65979@@ -125,11 +125,11 @@ int __init initrd_load(void)
65980 * mounted in the normal path.
65981 */
65982 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65983- sys_unlink("/initrd.image");
65984+ sys_unlink((const char __force_user *)"/initrd.image");
65985 handle_initrd();
65986 return 1;
65987 }
65988 }
65989- sys_unlink("/initrd.image");
65990+ sys_unlink((const char __force_user *)"/initrd.image");
65991 return 0;
65992 }
65993diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65994index 8cb6db5..d729f50 100644
65995--- a/init/do_mounts_md.c
65996+++ b/init/do_mounts_md.c
65997@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65998 partitioned ? "_d" : "", minor,
65999 md_setup_args[ent].device_names);
66000
66001- fd = sys_open(name, 0, 0);
66002+ fd = sys_open((char __force_user *)name, 0, 0);
66003 if (fd < 0) {
66004 printk(KERN_ERR "md: open failed - cannot start "
66005 "array %s\n", name);
66006@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66007 * array without it
66008 */
66009 sys_close(fd);
66010- fd = sys_open(name, 0, 0);
66011+ fd = sys_open((char __force_user *)name, 0, 0);
66012 sys_ioctl(fd, BLKRRPART, 0);
66013 }
66014 sys_close(fd);
66015@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66016
66017 wait_for_device_probe();
66018
66019- fd = sys_open("/dev/md0", 0, 0);
66020+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66021 if (fd >= 0) {
66022 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66023 sys_close(fd);
66024diff --git a/init/init_task.c b/init/init_task.c
66025index 8b2f399..f0797c9 100644
66026--- a/init/init_task.c
66027+++ b/init/init_task.c
66028@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66029 * Initial thread structure. Alignment of this is handled by a special
66030 * linker map entry.
66031 */
66032+#ifdef CONFIG_X86
66033+union thread_union init_thread_union __init_task_data;
66034+#else
66035 union thread_union init_thread_union __init_task_data =
66036 { INIT_THREAD_INFO(init_task) };
66037+#endif
66038diff --git a/init/initramfs.c b/init/initramfs.c
66039index 84c6bf1..8899338 100644
66040--- a/init/initramfs.c
66041+++ b/init/initramfs.c
66042@@ -84,7 +84,7 @@ static void __init free_hash(void)
66043 }
66044 }
66045
66046-static long __init do_utime(char *filename, time_t mtime)
66047+static long __init do_utime(char __force_user *filename, time_t mtime)
66048 {
66049 struct timespec t[2];
66050
66051@@ -119,7 +119,7 @@ static void __init dir_utime(void)
66052 struct dir_entry *de, *tmp;
66053 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66054 list_del(&de->list);
66055- do_utime(de->name, de->mtime);
66056+ do_utime((char __force_user *)de->name, de->mtime);
66057 kfree(de->name);
66058 kfree(de);
66059 }
66060@@ -281,7 +281,7 @@ static int __init maybe_link(void)
66061 if (nlink >= 2) {
66062 char *old = find_link(major, minor, ino, mode, collected);
66063 if (old)
66064- return (sys_link(old, collected) < 0) ? -1 : 1;
66065+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66066 }
66067 return 0;
66068 }
66069@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66070 {
66071 struct stat st;
66072
66073- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66074+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66075 if (S_ISDIR(st.st_mode))
66076- sys_rmdir(path);
66077+ sys_rmdir((char __force_user *)path);
66078 else
66079- sys_unlink(path);
66080+ sys_unlink((char __force_user *)path);
66081 }
66082 }
66083
66084@@ -315,7 +315,7 @@ static int __init do_name(void)
66085 int openflags = O_WRONLY|O_CREAT;
66086 if (ml != 1)
66087 openflags |= O_TRUNC;
66088- wfd = sys_open(collected, openflags, mode);
66089+ wfd = sys_open((char __force_user *)collected, openflags, mode);
66090
66091 if (wfd >= 0) {
66092 sys_fchown(wfd, uid, gid);
66093@@ -327,17 +327,17 @@ static int __init do_name(void)
66094 }
66095 }
66096 } else if (S_ISDIR(mode)) {
66097- sys_mkdir(collected, mode);
66098- sys_chown(collected, uid, gid);
66099- sys_chmod(collected, mode);
66100+ sys_mkdir((char __force_user *)collected, mode);
66101+ sys_chown((char __force_user *)collected, uid, gid);
66102+ sys_chmod((char __force_user *)collected, mode);
66103 dir_add(collected, mtime);
66104 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66105 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66106 if (maybe_link() == 0) {
66107- sys_mknod(collected, mode, rdev);
66108- sys_chown(collected, uid, gid);
66109- sys_chmod(collected, mode);
66110- do_utime(collected, mtime);
66111+ sys_mknod((char __force_user *)collected, mode, rdev);
66112+ sys_chown((char __force_user *)collected, uid, gid);
66113+ sys_chmod((char __force_user *)collected, mode);
66114+ do_utime((char __force_user *)collected, mtime);
66115 }
66116 }
66117 return 0;
66118@@ -346,15 +346,15 @@ static int __init do_name(void)
66119 static int __init do_copy(void)
66120 {
66121 if (count >= body_len) {
66122- sys_write(wfd, victim, body_len);
66123+ sys_write(wfd, (char __force_user *)victim, body_len);
66124 sys_close(wfd);
66125- do_utime(vcollected, mtime);
66126+ do_utime((char __force_user *)vcollected, mtime);
66127 kfree(vcollected);
66128 eat(body_len);
66129 state = SkipIt;
66130 return 0;
66131 } else {
66132- sys_write(wfd, victim, count);
66133+ sys_write(wfd, (char __force_user *)victim, count);
66134 body_len -= count;
66135 eat(count);
66136 return 1;
66137@@ -365,9 +365,9 @@ static int __init do_symlink(void)
66138 {
66139 collected[N_ALIGN(name_len) + body_len] = '\0';
66140 clean_path(collected, 0);
66141- sys_symlink(collected + N_ALIGN(name_len), collected);
66142- sys_lchown(collected, uid, gid);
66143- do_utime(collected, mtime);
66144+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66145+ sys_lchown((char __force_user *)collected, uid, gid);
66146+ do_utime((char __force_user *)collected, mtime);
66147 state = SkipIt;
66148 next_state = Reset;
66149 return 0;
66150diff --git a/init/main.c b/init/main.c
66151index b5cc0a7..ed8e21f 100644
66152--- a/init/main.c
66153+++ b/init/main.c
66154@@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
66155 extern void tc_init(void);
66156 #endif
66157
66158+extern void grsecurity_init(void);
66159+
66160 /*
66161 * Debug helper: via this flag we know that we are in 'early bootup code'
66162 * where only the boot processor is running with IRQ disabled. This means
66163@@ -148,6 +150,61 @@ static int __init set_reset_devices(char *str)
66164
66165 __setup("reset_devices", set_reset_devices);
66166
66167+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66168+int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66169+static int __init setup_grsec_proc_gid(char *str)
66170+{
66171+ grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66172+ return 1;
66173+}
66174+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66175+#endif
66176+
66177+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66178+extern char pax_enter_kernel_user[];
66179+extern char pax_exit_kernel_user[];
66180+extern pgdval_t clone_pgd_mask;
66181+#endif
66182+
66183+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66184+static int __init setup_pax_nouderef(char *str)
66185+{
66186+#ifdef CONFIG_X86_32
66187+ unsigned int cpu;
66188+ struct desc_struct *gdt;
66189+
66190+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66191+ gdt = get_cpu_gdt_table(cpu);
66192+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66193+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66194+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66195+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66196+ }
66197+ loadsegment(ds, __KERNEL_DS);
66198+ loadsegment(es, __KERNEL_DS);
66199+ loadsegment(ss, __KERNEL_DS);
66200+#else
66201+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66202+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66203+ clone_pgd_mask = ~(pgdval_t)0UL;
66204+#endif
66205+
66206+ return 0;
66207+}
66208+early_param("pax_nouderef", setup_pax_nouderef);
66209+#endif
66210+
66211+#ifdef CONFIG_PAX_SOFTMODE
66212+int pax_softmode;
66213+
66214+static int __init setup_pax_softmode(char *str)
66215+{
66216+ get_option(&str, &pax_softmode);
66217+ return 1;
66218+}
66219+__setup("pax_softmode=", setup_pax_softmode);
66220+#endif
66221+
66222 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66223 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66224 static const char *panic_later, *panic_param;
66225@@ -674,6 +731,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66226 {
66227 int count = preempt_count();
66228 int ret;
66229+ const char *msg1 = "", *msg2 = "";
66230
66231 if (initcall_debug)
66232 ret = do_one_initcall_debug(fn);
66233@@ -686,15 +744,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66234 sprintf(msgbuf, "error code %d ", ret);
66235
66236 if (preempt_count() != count) {
66237- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66238+ msg1 = " preemption imbalance";
66239 preempt_count() = count;
66240 }
66241 if (irqs_disabled()) {
66242- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66243+ msg2 = " disabled interrupts";
66244 local_irq_enable();
66245 }
66246- if (msgbuf[0]) {
66247- printk("initcall %pF returned with %s\n", fn, msgbuf);
66248+ if (msgbuf[0] || *msg1 || *msg2) {
66249+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66250 }
66251
66252 return ret;
66253@@ -747,8 +805,14 @@ static void __init do_initcall_level(int level)
66254 level, level,
66255 &repair_env_string);
66256
66257- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66258+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66259 do_one_initcall(*fn);
66260+
66261+#ifdef CONFIG_PAX_LATENT_ENTROPY
66262+ transfer_latent_entropy();
66263+#endif
66264+
66265+ }
66266 }
66267
66268 static void __init do_initcalls(void)
66269@@ -782,8 +846,14 @@ static void __init do_pre_smp_initcalls(void)
66270 {
66271 initcall_t *fn;
66272
66273- for (fn = __initcall_start; fn < __initcall0_start; fn++)
66274+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66275 do_one_initcall(*fn);
66276+
66277+#ifdef CONFIG_PAX_LATENT_ENTROPY
66278+ transfer_latent_entropy();
66279+#endif
66280+
66281+ }
66282 }
66283
66284 static void run_init_process(const char *init_filename)
66285@@ -865,7 +935,7 @@ static int __init kernel_init(void * unused)
66286 do_basic_setup();
66287
66288 /* Open the /dev/console on the rootfs, this should never fail */
66289- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66290+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66291 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66292
66293 (void) sys_dup(0);
66294@@ -878,11 +948,13 @@ static int __init kernel_init(void * unused)
66295 if (!ramdisk_execute_command)
66296 ramdisk_execute_command = "/init";
66297
66298- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66299+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66300 ramdisk_execute_command = NULL;
66301 prepare_namespace();
66302 }
66303
66304+ grsecurity_init();
66305+
66306 /*
66307 * Ok, we have completed the initial bootup, and
66308 * we're essentially up and running. Get rid of the
66309diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66310index 8ce5769..4666884 100644
66311--- a/ipc/mqueue.c
66312+++ b/ipc/mqueue.c
66313@@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66314 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66315 info->attr.mq_msgsize);
66316
66317+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66318 spin_lock(&mq_lock);
66319 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66320 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66321diff --git a/ipc/msg.c b/ipc/msg.c
66322index 7385de2..a8180e08 100644
66323--- a/ipc/msg.c
66324+++ b/ipc/msg.c
66325@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66326 return security_msg_queue_associate(msq, msgflg);
66327 }
66328
66329+static struct ipc_ops msg_ops = {
66330+ .getnew = newque,
66331+ .associate = msg_security,
66332+ .more_checks = NULL
66333+};
66334+
66335 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66336 {
66337 struct ipc_namespace *ns;
66338- struct ipc_ops msg_ops;
66339 struct ipc_params msg_params;
66340
66341 ns = current->nsproxy->ipc_ns;
66342
66343- msg_ops.getnew = newque;
66344- msg_ops.associate = msg_security;
66345- msg_ops.more_checks = NULL;
66346-
66347 msg_params.key = key;
66348 msg_params.flg = msgflg;
66349
66350diff --git a/ipc/sem.c b/ipc/sem.c
66351index 5215a81..cfc0cac 100644
66352--- a/ipc/sem.c
66353+++ b/ipc/sem.c
66354@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66355 return 0;
66356 }
66357
66358+static struct ipc_ops sem_ops = {
66359+ .getnew = newary,
66360+ .associate = sem_security,
66361+ .more_checks = sem_more_checks
66362+};
66363+
66364 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66365 {
66366 struct ipc_namespace *ns;
66367- struct ipc_ops sem_ops;
66368 struct ipc_params sem_params;
66369
66370 ns = current->nsproxy->ipc_ns;
66371@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66372 if (nsems < 0 || nsems > ns->sc_semmsl)
66373 return -EINVAL;
66374
66375- sem_ops.getnew = newary;
66376- sem_ops.associate = sem_security;
66377- sem_ops.more_checks = sem_more_checks;
66378-
66379 sem_params.key = key;
66380 sem_params.flg = semflg;
66381 sem_params.u.nsems = nsems;
66382diff --git a/ipc/shm.c b/ipc/shm.c
66383index 41c1285..cf6404c 100644
66384--- a/ipc/shm.c
66385+++ b/ipc/shm.c
66386@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66387 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66388 #endif
66389
66390+#ifdef CONFIG_GRKERNSEC
66391+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66392+ const time_t shm_createtime, const uid_t cuid,
66393+ const int shmid);
66394+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66395+ const time_t shm_createtime);
66396+#endif
66397+
66398 void shm_init_ns(struct ipc_namespace *ns)
66399 {
66400 ns->shm_ctlmax = SHMMAX;
66401@@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66402 shp->shm_lprid = 0;
66403 shp->shm_atim = shp->shm_dtim = 0;
66404 shp->shm_ctim = get_seconds();
66405+#ifdef CONFIG_GRKERNSEC
66406+ {
66407+ struct timespec timeval;
66408+ do_posix_clock_monotonic_gettime(&timeval);
66409+
66410+ shp->shm_createtime = timeval.tv_sec;
66411+ }
66412+#endif
66413 shp->shm_segsz = size;
66414 shp->shm_nattch = 0;
66415 shp->shm_file = file;
66416@@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66417 return 0;
66418 }
66419
66420+static struct ipc_ops shm_ops = {
66421+ .getnew = newseg,
66422+ .associate = shm_security,
66423+ .more_checks = shm_more_checks
66424+};
66425+
66426 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66427 {
66428 struct ipc_namespace *ns;
66429- struct ipc_ops shm_ops;
66430 struct ipc_params shm_params;
66431
66432 ns = current->nsproxy->ipc_ns;
66433
66434- shm_ops.getnew = newseg;
66435- shm_ops.associate = shm_security;
66436- shm_ops.more_checks = shm_more_checks;
66437-
66438 shm_params.key = key;
66439 shm_params.flg = shmflg;
66440 shm_params.u.size = size;
66441@@ -1000,6 +1017,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
66442 f_mode = FMODE_READ | FMODE_WRITE;
66443 }
66444 if (shmflg & SHM_EXEC) {
66445+
66446+#ifdef CONFIG_PAX_MPROTECT
66447+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
66448+ goto out;
66449+#endif
66450+
66451 prot |= PROT_EXEC;
66452 acc_mode |= S_IXUGO;
66453 }
66454@@ -1023,9 +1046,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
66455 if (err)
66456 goto out_unlock;
66457
66458+#ifdef CONFIG_GRKERNSEC
66459+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66460+ shp->shm_perm.cuid, shmid) ||
66461+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66462+ err = -EACCES;
66463+ goto out_unlock;
66464+ }
66465+#endif
66466+
66467 path = shp->shm_file->f_path;
66468 path_get(&path);
66469 shp->shm_nattch++;
66470+#ifdef CONFIG_GRKERNSEC
66471+ shp->shm_lapid = current->pid;
66472+#endif
66473 size = i_size_read(path.dentry->d_inode);
66474 shm_unlock(shp);
66475
66476diff --git a/kernel/acct.c b/kernel/acct.c
66477index 02e6167..54824f7 100644
66478--- a/kernel/acct.c
66479+++ b/kernel/acct.c
66480@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66481 */
66482 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66483 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66484- file->f_op->write(file, (char *)&ac,
66485+ file->f_op->write(file, (char __force_user *)&ac,
66486 sizeof(acct_t), &file->f_pos);
66487 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66488 set_fs(fs);
66489diff --git a/kernel/audit.c b/kernel/audit.c
66490index 1c7f2c6..9ba5359 100644
66491--- a/kernel/audit.c
66492+++ b/kernel/audit.c
66493@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66494 3) suppressed due to audit_rate_limit
66495 4) suppressed due to audit_backlog_limit
66496 */
66497-static atomic_t audit_lost = ATOMIC_INIT(0);
66498+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66499
66500 /* The netlink socket. */
66501 static struct sock *audit_sock;
66502@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66503 unsigned long now;
66504 int print;
66505
66506- atomic_inc(&audit_lost);
66507+ atomic_inc_unchecked(&audit_lost);
66508
66509 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66510
66511@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66512 printk(KERN_WARNING
66513 "audit: audit_lost=%d audit_rate_limit=%d "
66514 "audit_backlog_limit=%d\n",
66515- atomic_read(&audit_lost),
66516+ atomic_read_unchecked(&audit_lost),
66517 audit_rate_limit,
66518 audit_backlog_limit);
66519 audit_panic(message);
66520@@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66521 status_set.pid = audit_pid;
66522 status_set.rate_limit = audit_rate_limit;
66523 status_set.backlog_limit = audit_backlog_limit;
66524- status_set.lost = atomic_read(&audit_lost);
66525+ status_set.lost = atomic_read_unchecked(&audit_lost);
66526 status_set.backlog = skb_queue_len(&audit_skb_queue);
66527 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66528 &status_set, sizeof(status_set));
66529diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66530index 4b96415..d8c16ee 100644
66531--- a/kernel/auditsc.c
66532+++ b/kernel/auditsc.c
66533@@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66534 }
66535
66536 /* global counter which is incremented every time something logs in */
66537-static atomic_t session_id = ATOMIC_INIT(0);
66538+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66539
66540 /**
66541 * audit_set_loginuid - set current task's audit_context loginuid
66542@@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66543 return -EPERM;
66544 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66545
66546- sessionid = atomic_inc_return(&session_id);
66547+ sessionid = atomic_inc_return_unchecked(&session_id);
66548 if (context && context->in_syscall) {
66549 struct audit_buffer *ab;
66550
66551diff --git a/kernel/capability.c b/kernel/capability.c
66552index 493d972..ea17248 100644
66553--- a/kernel/capability.c
66554+++ b/kernel/capability.c
66555@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66556 * before modification is attempted and the application
66557 * fails.
66558 */
66559+ if (tocopy > ARRAY_SIZE(kdata))
66560+ return -EFAULT;
66561+
66562 if (copy_to_user(dataptr, kdata, tocopy
66563 * sizeof(struct __user_cap_data_struct))) {
66564 return -EFAULT;
66565@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66566 int ret;
66567
66568 rcu_read_lock();
66569- ret = security_capable(__task_cred(t), ns, cap);
66570+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66571+ gr_task_is_capable(t, __task_cred(t), cap);
66572 rcu_read_unlock();
66573
66574- return (ret == 0);
66575+ return ret;
66576 }
66577
66578 /**
66579@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66580 int ret;
66581
66582 rcu_read_lock();
66583- ret = security_capable_noaudit(__task_cred(t), ns, cap);
66584+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66585 rcu_read_unlock();
66586
66587- return (ret == 0);
66588+ return ret;
66589 }
66590
66591 /**
66592@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66593 BUG();
66594 }
66595
66596- if (security_capable(current_cred(), ns, cap) == 0) {
66597+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66598 current->flags |= PF_SUPERPRIV;
66599 return true;
66600 }
66601@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66602 }
66603 EXPORT_SYMBOL(ns_capable);
66604
66605+bool ns_capable_nolog(struct user_namespace *ns, int cap)
66606+{
66607+ if (unlikely(!cap_valid(cap))) {
66608+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66609+ BUG();
66610+ }
66611+
66612+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66613+ current->flags |= PF_SUPERPRIV;
66614+ return true;
66615+ }
66616+ return false;
66617+}
66618+EXPORT_SYMBOL(ns_capable_nolog);
66619+
66620 /**
66621 * capable - Determine if the current task has a superior capability in effect
66622 * @cap: The capability to be tested for
66623@@ -408,6 +427,12 @@ bool capable(int cap)
66624 }
66625 EXPORT_SYMBOL(capable);
66626
66627+bool capable_nolog(int cap)
66628+{
66629+ return ns_capable_nolog(&init_user_ns, cap);
66630+}
66631+EXPORT_SYMBOL(capable_nolog);
66632+
66633 /**
66634 * nsown_capable - Check superior capability to one's own user_ns
66635 * @cap: The capability in question
66636@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66637
66638 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66639 }
66640+
66641+bool inode_capable_nolog(const struct inode *inode, int cap)
66642+{
66643+ struct user_namespace *ns = current_user_ns();
66644+
66645+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66646+}
66647diff --git a/kernel/compat.c b/kernel/compat.c
66648index c28a306..b4d0cf3 100644
66649--- a/kernel/compat.c
66650+++ b/kernel/compat.c
66651@@ -13,6 +13,7 @@
66652
66653 #include <linux/linkage.h>
66654 #include <linux/compat.h>
66655+#include <linux/module.h>
66656 #include <linux/errno.h>
66657 #include <linux/time.h>
66658 #include <linux/signal.h>
66659@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66660 mm_segment_t oldfs;
66661 long ret;
66662
66663- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66664+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66665 oldfs = get_fs();
66666 set_fs(KERNEL_DS);
66667 ret = hrtimer_nanosleep_restart(restart);
66668@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66669 oldfs = get_fs();
66670 set_fs(KERNEL_DS);
66671 ret = hrtimer_nanosleep(&tu,
66672- rmtp ? (struct timespec __user *)&rmt : NULL,
66673+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
66674 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66675 set_fs(oldfs);
66676
66677@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66678 mm_segment_t old_fs = get_fs();
66679
66680 set_fs(KERNEL_DS);
66681- ret = sys_sigpending((old_sigset_t __user *) &s);
66682+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
66683 set_fs(old_fs);
66684 if (ret == 0)
66685 ret = put_user(s, set);
66686@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66687 mm_segment_t old_fs = get_fs();
66688
66689 set_fs(KERNEL_DS);
66690- ret = sys_old_getrlimit(resource, &r);
66691+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66692 set_fs(old_fs);
66693
66694 if (!ret) {
66695@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66696 mm_segment_t old_fs = get_fs();
66697
66698 set_fs(KERNEL_DS);
66699- ret = sys_getrusage(who, (struct rusage __user *) &r);
66700+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66701 set_fs(old_fs);
66702
66703 if (ret)
66704@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66705 set_fs (KERNEL_DS);
66706 ret = sys_wait4(pid,
66707 (stat_addr ?
66708- (unsigned int __user *) &status : NULL),
66709- options, (struct rusage __user *) &r);
66710+ (unsigned int __force_user *) &status : NULL),
66711+ options, (struct rusage __force_user *) &r);
66712 set_fs (old_fs);
66713
66714 if (ret > 0) {
66715@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66716 memset(&info, 0, sizeof(info));
66717
66718 set_fs(KERNEL_DS);
66719- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66720- uru ? (struct rusage __user *)&ru : NULL);
66721+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66722+ uru ? (struct rusage __force_user *)&ru : NULL);
66723 set_fs(old_fs);
66724
66725 if ((ret < 0) || (info.si_signo == 0))
66726@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66727 oldfs = get_fs();
66728 set_fs(KERNEL_DS);
66729 err = sys_timer_settime(timer_id, flags,
66730- (struct itimerspec __user *) &newts,
66731- (struct itimerspec __user *) &oldts);
66732+ (struct itimerspec __force_user *) &newts,
66733+ (struct itimerspec __force_user *) &oldts);
66734 set_fs(oldfs);
66735 if (!err && old && put_compat_itimerspec(old, &oldts))
66736 return -EFAULT;
66737@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66738 oldfs = get_fs();
66739 set_fs(KERNEL_DS);
66740 err = sys_timer_gettime(timer_id,
66741- (struct itimerspec __user *) &ts);
66742+ (struct itimerspec __force_user *) &ts);
66743 set_fs(oldfs);
66744 if (!err && put_compat_itimerspec(setting, &ts))
66745 return -EFAULT;
66746@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66747 oldfs = get_fs();
66748 set_fs(KERNEL_DS);
66749 err = sys_clock_settime(which_clock,
66750- (struct timespec __user *) &ts);
66751+ (struct timespec __force_user *) &ts);
66752 set_fs(oldfs);
66753 return err;
66754 }
66755@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66756 oldfs = get_fs();
66757 set_fs(KERNEL_DS);
66758 err = sys_clock_gettime(which_clock,
66759- (struct timespec __user *) &ts);
66760+ (struct timespec __force_user *) &ts);
66761 set_fs(oldfs);
66762 if (!err && put_compat_timespec(&ts, tp))
66763 return -EFAULT;
66764@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66765
66766 oldfs = get_fs();
66767 set_fs(KERNEL_DS);
66768- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66769+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66770 set_fs(oldfs);
66771
66772 err = compat_put_timex(utp, &txc);
66773@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66774 oldfs = get_fs();
66775 set_fs(KERNEL_DS);
66776 err = sys_clock_getres(which_clock,
66777- (struct timespec __user *) &ts);
66778+ (struct timespec __force_user *) &ts);
66779 set_fs(oldfs);
66780 if (!err && tp && put_compat_timespec(&ts, tp))
66781 return -EFAULT;
66782@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66783 long err;
66784 mm_segment_t oldfs;
66785 struct timespec tu;
66786- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66787+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66788
66789- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66790+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66791 oldfs = get_fs();
66792 set_fs(KERNEL_DS);
66793 err = clock_nanosleep_restart(restart);
66794@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66795 oldfs = get_fs();
66796 set_fs(KERNEL_DS);
66797 err = sys_clock_nanosleep(which_clock, flags,
66798- (struct timespec __user *) &in,
66799- (struct timespec __user *) &out);
66800+ (struct timespec __force_user *) &in,
66801+ (struct timespec __force_user *) &out);
66802 set_fs(oldfs);
66803
66804 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66805diff --git a/kernel/configs.c b/kernel/configs.c
66806index 42e8fa0..9e7406b 100644
66807--- a/kernel/configs.c
66808+++ b/kernel/configs.c
66809@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66810 struct proc_dir_entry *entry;
66811
66812 /* create the current config file */
66813+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66814+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66815+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66816+ &ikconfig_file_ops);
66817+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66818+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66819+ &ikconfig_file_ops);
66820+#endif
66821+#else
66822 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66823 &ikconfig_file_ops);
66824+#endif
66825+
66826 if (!entry)
66827 return -ENOMEM;
66828
66829diff --git a/kernel/cred.c b/kernel/cred.c
66830index de728ac..e3c267c 100644
66831--- a/kernel/cred.c
66832+++ b/kernel/cred.c
66833@@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66834 validate_creds(cred);
66835 alter_cred_subscribers(cred, -1);
66836 put_cred(cred);
66837+
66838+#ifdef CONFIG_GRKERNSEC_SETXID
66839+ cred = (struct cred *) tsk->delayed_cred;
66840+ if (cred != NULL) {
66841+ tsk->delayed_cred = NULL;
66842+ validate_creds(cred);
66843+ alter_cred_subscribers(cred, -1);
66844+ put_cred(cred);
66845+ }
66846+#endif
66847 }
66848
66849 /**
66850@@ -469,7 +479,7 @@ error_put:
66851 * Always returns 0 thus allowing this function to be tail-called at the end
66852 * of, say, sys_setgid().
66853 */
66854-int commit_creds(struct cred *new)
66855+static int __commit_creds(struct cred *new)
66856 {
66857 struct task_struct *task = current;
66858 const struct cred *old = task->real_cred;
66859@@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66860
66861 get_cred(new); /* we will require a ref for the subj creds too */
66862
66863+ gr_set_role_label(task, new->uid, new->gid);
66864+
66865 /* dumpability changes */
66866 if (!uid_eq(old->euid, new->euid) ||
66867 !gid_eq(old->egid, new->egid) ||
66868@@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66869 put_cred(old);
66870 return 0;
66871 }
66872+#ifdef CONFIG_GRKERNSEC_SETXID
66873+extern int set_user(struct cred *new);
66874+
66875+void gr_delayed_cred_worker(void)
66876+{
66877+ const struct cred *new = current->delayed_cred;
66878+ struct cred *ncred;
66879+
66880+ current->delayed_cred = NULL;
66881+
66882+ if (current_uid() && new != NULL) {
66883+ // from doing get_cred on it when queueing this
66884+ put_cred(new);
66885+ return;
66886+ } else if (new == NULL)
66887+ return;
66888+
66889+ ncred = prepare_creds();
66890+ if (!ncred)
66891+ goto die;
66892+ // uids
66893+ ncred->uid = new->uid;
66894+ ncred->euid = new->euid;
66895+ ncred->suid = new->suid;
66896+ ncred->fsuid = new->fsuid;
66897+ // gids
66898+ ncred->gid = new->gid;
66899+ ncred->egid = new->egid;
66900+ ncred->sgid = new->sgid;
66901+ ncred->fsgid = new->fsgid;
66902+ // groups
66903+ if (set_groups(ncred, new->group_info) < 0) {
66904+ abort_creds(ncred);
66905+ goto die;
66906+ }
66907+ // caps
66908+ ncred->securebits = new->securebits;
66909+ ncred->cap_inheritable = new->cap_inheritable;
66910+ ncred->cap_permitted = new->cap_permitted;
66911+ ncred->cap_effective = new->cap_effective;
66912+ ncred->cap_bset = new->cap_bset;
66913+
66914+ if (set_user(ncred)) {
66915+ abort_creds(ncred);
66916+ goto die;
66917+ }
66918+
66919+ // from doing get_cred on it when queueing this
66920+ put_cred(new);
66921+
66922+ __commit_creds(ncred);
66923+ return;
66924+die:
66925+ // from doing get_cred on it when queueing this
66926+ put_cred(new);
66927+ do_group_exit(SIGKILL);
66928+}
66929+#endif
66930+
66931+int commit_creds(struct cred *new)
66932+{
66933+#ifdef CONFIG_GRKERNSEC_SETXID
66934+ int ret;
66935+ int schedule_it = 0;
66936+ struct task_struct *t;
66937+
66938+ /* we won't get called with tasklist_lock held for writing
66939+ and interrupts disabled as the cred struct in that case is
66940+ init_cred
66941+ */
66942+ if (grsec_enable_setxid && !current_is_single_threaded() &&
66943+ !current_uid() && new->uid) {
66944+ schedule_it = 1;
66945+ }
66946+ ret = __commit_creds(new);
66947+ if (schedule_it) {
66948+ rcu_read_lock();
66949+ read_lock(&tasklist_lock);
66950+ for (t = next_thread(current); t != current;
66951+ t = next_thread(t)) {
66952+ if (t->delayed_cred == NULL) {
66953+ t->delayed_cred = get_cred(new);
66954+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66955+ set_tsk_need_resched(t);
66956+ }
66957+ }
66958+ read_unlock(&tasklist_lock);
66959+ rcu_read_unlock();
66960+ }
66961+ return ret;
66962+#else
66963+ return __commit_creds(new);
66964+#endif
66965+}
66966+
66967 EXPORT_SYMBOL(commit_creds);
66968
66969 /**
66970diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66971index 0557f24..1a00d9a 100644
66972--- a/kernel/debug/debug_core.c
66973+++ b/kernel/debug/debug_core.c
66974@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66975 */
66976 static atomic_t masters_in_kgdb;
66977 static atomic_t slaves_in_kgdb;
66978-static atomic_t kgdb_break_tasklet_var;
66979+static atomic_unchecked_t kgdb_break_tasklet_var;
66980 atomic_t kgdb_setting_breakpoint;
66981
66982 struct task_struct *kgdb_usethread;
66983@@ -132,7 +132,7 @@ int kgdb_single_step;
66984 static pid_t kgdb_sstep_pid;
66985
66986 /* to keep track of the CPU which is doing the single stepping*/
66987-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66988+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66989
66990 /*
66991 * If you are debugging a problem where roundup (the collection of
66992@@ -540,7 +540,7 @@ return_normal:
66993 * kernel will only try for the value of sstep_tries before
66994 * giving up and continuing on.
66995 */
66996- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66997+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66998 (kgdb_info[cpu].task &&
66999 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67000 atomic_set(&kgdb_active, -1);
67001@@ -634,8 +634,8 @@ cpu_master_loop:
67002 }
67003
67004 kgdb_restore:
67005- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67006- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67007+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67008+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67009 if (kgdb_info[sstep_cpu].task)
67010 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67011 else
67012@@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
67013 static void kgdb_tasklet_bpt(unsigned long ing)
67014 {
67015 kgdb_breakpoint();
67016- atomic_set(&kgdb_break_tasklet_var, 0);
67017+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67018 }
67019
67020 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67021
67022 void kgdb_schedule_breakpoint(void)
67023 {
67024- if (atomic_read(&kgdb_break_tasklet_var) ||
67025+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67026 atomic_read(&kgdb_active) != -1 ||
67027 atomic_read(&kgdb_setting_breakpoint))
67028 return;
67029- atomic_inc(&kgdb_break_tasklet_var);
67030+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
67031 tasklet_schedule(&kgdb_tasklet_breakpoint);
67032 }
67033 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67034diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67035index 1f91413..362a0a1 100644
67036--- a/kernel/debug/kdb/kdb_main.c
67037+++ b/kernel/debug/kdb/kdb_main.c
67038@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
67039 list_for_each_entry(mod, kdb_modules, list) {
67040
67041 kdb_printf("%-20s%8u 0x%p ", mod->name,
67042- mod->core_size, (void *)mod);
67043+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
67044 #ifdef CONFIG_MODULE_UNLOAD
67045 kdb_printf("%4ld ", module_refcount(mod));
67046 #endif
67047@@ -1994,7 +1994,7 @@ static int kdb_lsmod(int argc, const char **argv)
67048 kdb_printf(" (Loading)");
67049 else
67050 kdb_printf(" (Live)");
67051- kdb_printf(" 0x%p", mod->module_core);
67052+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67053
67054 #ifdef CONFIG_MODULE_UNLOAD
67055 {
67056diff --git a/kernel/events/core.c b/kernel/events/core.c
67057index 11409af..b6ec863 100644
67058--- a/kernel/events/core.c
67059+++ b/kernel/events/core.c
67060@@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67061 return 0;
67062 }
67063
67064-static atomic64_t perf_event_id;
67065+static atomic64_unchecked_t perf_event_id;
67066
67067 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67068 enum event_type_t event_type);
67069@@ -2663,7 +2663,7 @@ static void __perf_event_read(void *info)
67070
67071 static inline u64 perf_event_count(struct perf_event *event)
67072 {
67073- return local64_read(&event->count) + atomic64_read(&event->child_count);
67074+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67075 }
67076
67077 static u64 perf_event_read(struct perf_event *event)
67078@@ -2993,9 +2993,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67079 mutex_lock(&event->child_mutex);
67080 total += perf_event_read(event);
67081 *enabled += event->total_time_enabled +
67082- atomic64_read(&event->child_total_time_enabled);
67083+ atomic64_read_unchecked(&event->child_total_time_enabled);
67084 *running += event->total_time_running +
67085- atomic64_read(&event->child_total_time_running);
67086+ atomic64_read_unchecked(&event->child_total_time_running);
67087
67088 list_for_each_entry(child, &event->child_list, child_list) {
67089 total += perf_event_read(child);
67090@@ -3404,10 +3404,10 @@ void perf_event_update_userpage(struct perf_event *event)
67091 userpg->offset -= local64_read(&event->hw.prev_count);
67092
67093 userpg->time_enabled = enabled +
67094- atomic64_read(&event->child_total_time_enabled);
67095+ atomic64_read_unchecked(&event->child_total_time_enabled);
67096
67097 userpg->time_running = running +
67098- atomic64_read(&event->child_total_time_running);
67099+ atomic64_read_unchecked(&event->child_total_time_running);
67100
67101 arch_perf_update_userpage(userpg, now);
67102
67103@@ -3840,11 +3840,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67104 values[n++] = perf_event_count(event);
67105 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67106 values[n++] = enabled +
67107- atomic64_read(&event->child_total_time_enabled);
67108+ atomic64_read_unchecked(&event->child_total_time_enabled);
67109 }
67110 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67111 values[n++] = running +
67112- atomic64_read(&event->child_total_time_running);
67113+ atomic64_read_unchecked(&event->child_total_time_running);
67114 }
67115 if (read_format & PERF_FORMAT_ID)
67116 values[n++] = primary_event_id(event);
67117@@ -4522,12 +4522,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67118 * need to add enough zero bytes after the string to handle
67119 * the 64bit alignment we do later.
67120 */
67121- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67122+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
67123 if (!buf) {
67124 name = strncpy(tmp, "//enomem", sizeof(tmp));
67125 goto got_name;
67126 }
67127- name = d_path(&file->f_path, buf, PATH_MAX);
67128+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67129 if (IS_ERR(name)) {
67130 name = strncpy(tmp, "//toolong", sizeof(tmp));
67131 goto got_name;
67132@@ -5940,7 +5940,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67133 event->parent = parent_event;
67134
67135 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67136- event->id = atomic64_inc_return(&perf_event_id);
67137+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
67138
67139 event->state = PERF_EVENT_STATE_INACTIVE;
67140
67141@@ -6500,10 +6500,10 @@ static void sync_child_event(struct perf_event *child_event,
67142 /*
67143 * Add back the child's count to the parent's count:
67144 */
67145- atomic64_add(child_val, &parent_event->child_count);
67146- atomic64_add(child_event->total_time_enabled,
67147+ atomic64_add_unchecked(child_val, &parent_event->child_count);
67148+ atomic64_add_unchecked(child_event->total_time_enabled,
67149 &parent_event->child_total_time_enabled);
67150- atomic64_add(child_event->total_time_running,
67151+ atomic64_add_unchecked(child_event->total_time_running,
67152 &parent_event->child_total_time_running);
67153
67154 /*
67155diff --git a/kernel/exit.c b/kernel/exit.c
67156index 46ce8da..c648f3a 100644
67157--- a/kernel/exit.c
67158+++ b/kernel/exit.c
67159@@ -59,6 +59,10 @@
67160 #include <asm/pgtable.h>
67161 #include <asm/mmu_context.h>
67162
67163+#ifdef CONFIG_GRKERNSEC
67164+extern rwlock_t grsec_exec_file_lock;
67165+#endif
67166+
67167 static void exit_mm(struct task_struct * tsk);
67168
67169 static void __unhash_process(struct task_struct *p, bool group_dead)
67170@@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
67171 struct task_struct *leader;
67172 int zap_leader;
67173 repeat:
67174+#ifdef CONFIG_NET
67175+ gr_del_task_from_ip_table(p);
67176+#endif
67177+
67178 /* don't need to get the RCU readlock here - the process is dead and
67179 * can't be modifying its own credentials. But shut RCU-lockdep up */
67180 rcu_read_lock();
67181@@ -394,7 +402,7 @@ int allow_signal(int sig)
67182 * know it'll be handled, so that they don't get converted to
67183 * SIGKILL or just silently dropped.
67184 */
67185- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67186+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67187 recalc_sigpending();
67188 spin_unlock_irq(&current->sighand->siglock);
67189 return 0;
67190@@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
67191 vsnprintf(current->comm, sizeof(current->comm), name, args);
67192 va_end(args);
67193
67194+#ifdef CONFIG_GRKERNSEC
67195+ write_lock(&grsec_exec_file_lock);
67196+ if (current->exec_file) {
67197+ fput(current->exec_file);
67198+ current->exec_file = NULL;
67199+ }
67200+ write_unlock(&grsec_exec_file_lock);
67201+#endif
67202+
67203+ gr_set_kernel_label(current);
67204+
67205 /*
67206 * If we were started as result of loading a module, close all of the
67207 * user space pages. We don't need them, and if we didn't close them
67208@@ -907,6 +926,8 @@ void do_exit(long code)
67209 struct task_struct *tsk = current;
67210 int group_dead;
67211
67212+ set_fs(USER_DS);
67213+
67214 profile_task_exit(tsk);
67215
67216 WARN_ON(blk_needs_flush_plug(tsk));
67217@@ -923,7 +944,6 @@ void do_exit(long code)
67218 * mm_release()->clear_child_tid() from writing to a user-controlled
67219 * kernel address.
67220 */
67221- set_fs(USER_DS);
67222
67223 ptrace_event(PTRACE_EVENT_EXIT, code);
67224
67225@@ -985,6 +1005,9 @@ void do_exit(long code)
67226 tsk->exit_code = code;
67227 taskstats_exit(tsk, group_dead);
67228
67229+ gr_acl_handle_psacct(tsk, code);
67230+ gr_acl_handle_exit();
67231+
67232 exit_mm(tsk);
67233
67234 if (group_dead)
67235@@ -1101,7 +1124,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67236 * Take down every thread in the group. This is called by fatal signals
67237 * as well as by sys_exit_group (below).
67238 */
67239-void
67240+__noreturn void
67241 do_group_exit(int exit_code)
67242 {
67243 struct signal_struct *sig = current->signal;
67244diff --git a/kernel/fork.c b/kernel/fork.c
67245index f9d0499..e4f8f44 100644
67246--- a/kernel/fork.c
67247+++ b/kernel/fork.c
67248@@ -321,7 +321,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67249 *stackend = STACK_END_MAGIC; /* for overflow detection */
67250
67251 #ifdef CONFIG_CC_STACKPROTECTOR
67252- tsk->stack_canary = get_random_int();
67253+ tsk->stack_canary = pax_get_random_long();
67254 #endif
67255
67256 /*
67257@@ -345,13 +345,78 @@ out:
67258 }
67259
67260 #ifdef CONFIG_MMU
67261+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67262+{
67263+ struct vm_area_struct *tmp;
67264+ unsigned long charge;
67265+ struct mempolicy *pol;
67266+ struct file *file;
67267+
67268+ charge = 0;
67269+ if (mpnt->vm_flags & VM_ACCOUNT) {
67270+ unsigned long len;
67271+ len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67272+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67273+ goto fail_nomem;
67274+ charge = len;
67275+ }
67276+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67277+ if (!tmp)
67278+ goto fail_nomem;
67279+ *tmp = *mpnt;
67280+ tmp->vm_mm = mm;
67281+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
67282+ pol = mpol_dup(vma_policy(mpnt));
67283+ if (IS_ERR(pol))
67284+ goto fail_nomem_policy;
67285+ vma_set_policy(tmp, pol);
67286+ if (anon_vma_fork(tmp, mpnt))
67287+ goto fail_nomem_anon_vma_fork;
67288+ tmp->vm_flags &= ~VM_LOCKED;
67289+ tmp->vm_next = tmp->vm_prev = NULL;
67290+ tmp->vm_mirror = NULL;
67291+ file = tmp->vm_file;
67292+ if (file) {
67293+ struct inode *inode = file->f_path.dentry->d_inode;
67294+ struct address_space *mapping = file->f_mapping;
67295+
67296+ get_file(file);
67297+ if (tmp->vm_flags & VM_DENYWRITE)
67298+ atomic_dec(&inode->i_writecount);
67299+ mutex_lock(&mapping->i_mmap_mutex);
67300+ if (tmp->vm_flags & VM_SHARED)
67301+ mapping->i_mmap_writable++;
67302+ flush_dcache_mmap_lock(mapping);
67303+ /* insert tmp into the share list, just after mpnt */
67304+ vma_prio_tree_add(tmp, mpnt);
67305+ flush_dcache_mmap_unlock(mapping);
67306+ mutex_unlock(&mapping->i_mmap_mutex);
67307+ }
67308+
67309+ /*
67310+ * Clear hugetlb-related page reserves for children. This only
67311+ * affects MAP_PRIVATE mappings. Faults generated by the child
67312+ * are not guaranteed to succeed, even if read-only
67313+ */
67314+ if (is_vm_hugetlb_page(tmp))
67315+ reset_vma_resv_huge_pages(tmp);
67316+
67317+ return tmp;
67318+
67319+fail_nomem_anon_vma_fork:
67320+ mpol_put(pol);
67321+fail_nomem_policy:
67322+ kmem_cache_free(vm_area_cachep, tmp);
67323+fail_nomem:
67324+ vm_unacct_memory(charge);
67325+ return NULL;
67326+}
67327+
67328 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67329 {
67330 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67331 struct rb_node **rb_link, *rb_parent;
67332 int retval;
67333- unsigned long charge;
67334- struct mempolicy *pol;
67335
67336 down_write(&oldmm->mmap_sem);
67337 flush_cache_dup_mm(oldmm);
67338@@ -363,8 +428,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67339 mm->locked_vm = 0;
67340 mm->mmap = NULL;
67341 mm->mmap_cache = NULL;
67342- mm->free_area_cache = oldmm->mmap_base;
67343- mm->cached_hole_size = ~0UL;
67344+ mm->free_area_cache = oldmm->free_area_cache;
67345+ mm->cached_hole_size = oldmm->cached_hole_size;
67346 mm->map_count = 0;
67347 cpumask_clear(mm_cpumask(mm));
67348 mm->mm_rb = RB_ROOT;
67349@@ -380,8 +445,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67350
67351 prev = NULL;
67352 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67353- struct file *file;
67354-
67355 if (mpnt->vm_flags & VM_DONTCOPY) {
67356 long pages = vma_pages(mpnt);
67357 mm->total_vm -= pages;
67358@@ -389,54 +452,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67359 -pages);
67360 continue;
67361 }
67362- charge = 0;
67363- if (mpnt->vm_flags & VM_ACCOUNT) {
67364- unsigned long len;
67365- len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67366- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67367- goto fail_nomem;
67368- charge = len;
67369+ tmp = dup_vma(mm, oldmm, mpnt);
67370+ if (!tmp) {
67371+ retval = -ENOMEM;
67372+ goto out;
67373 }
67374- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67375- if (!tmp)
67376- goto fail_nomem;
67377- *tmp = *mpnt;
67378- INIT_LIST_HEAD(&tmp->anon_vma_chain);
67379- pol = mpol_dup(vma_policy(mpnt));
67380- retval = PTR_ERR(pol);
67381- if (IS_ERR(pol))
67382- goto fail_nomem_policy;
67383- vma_set_policy(tmp, pol);
67384- tmp->vm_mm = mm;
67385- if (anon_vma_fork(tmp, mpnt))
67386- goto fail_nomem_anon_vma_fork;
67387- tmp->vm_flags &= ~VM_LOCKED;
67388- tmp->vm_next = tmp->vm_prev = NULL;
67389- file = tmp->vm_file;
67390- if (file) {
67391- struct inode *inode = file->f_path.dentry->d_inode;
67392- struct address_space *mapping = file->f_mapping;
67393-
67394- get_file(file);
67395- if (tmp->vm_flags & VM_DENYWRITE)
67396- atomic_dec(&inode->i_writecount);
67397- mutex_lock(&mapping->i_mmap_mutex);
67398- if (tmp->vm_flags & VM_SHARED)
67399- mapping->i_mmap_writable++;
67400- flush_dcache_mmap_lock(mapping);
67401- /* insert tmp into the share list, just after mpnt */
67402- vma_prio_tree_add(tmp, mpnt);
67403- flush_dcache_mmap_unlock(mapping);
67404- mutex_unlock(&mapping->i_mmap_mutex);
67405- }
67406-
67407- /*
67408- * Clear hugetlb-related page reserves for children. This only
67409- * affects MAP_PRIVATE mappings. Faults generated by the child
67410- * are not guaranteed to succeed, even if read-only
67411- */
67412- if (is_vm_hugetlb_page(tmp))
67413- reset_vma_resv_huge_pages(tmp);
67414
67415 /*
67416 * Link in the new vma and copy the page table entries.
67417@@ -459,9 +479,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67418 if (retval)
67419 goto out;
67420
67421- if (file)
67422+ if (tmp->vm_file)
67423 uprobe_mmap(tmp);
67424 }
67425+
67426+#ifdef CONFIG_PAX_SEGMEXEC
67427+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67428+ struct vm_area_struct *mpnt_m;
67429+
67430+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67431+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67432+
67433+ if (!mpnt->vm_mirror)
67434+ continue;
67435+
67436+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67437+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67438+ mpnt->vm_mirror = mpnt_m;
67439+ } else {
67440+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67441+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67442+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67443+ mpnt->vm_mirror->vm_mirror = mpnt;
67444+ }
67445+ }
67446+ BUG_ON(mpnt_m);
67447+ }
67448+#endif
67449+
67450 /* a new mm has just been created */
67451 arch_dup_mmap(oldmm, mm);
67452 retval = 0;
67453@@ -470,14 +515,6 @@ out:
67454 flush_tlb_mm(oldmm);
67455 up_write(&oldmm->mmap_sem);
67456 return retval;
67457-fail_nomem_anon_vma_fork:
67458- mpol_put(pol);
67459-fail_nomem_policy:
67460- kmem_cache_free(vm_area_cachep, tmp);
67461-fail_nomem:
67462- retval = -ENOMEM;
67463- vm_unacct_memory(charge);
67464- goto out;
67465 }
67466
67467 static inline int mm_alloc_pgd(struct mm_struct *mm)
67468@@ -714,8 +751,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67469 return ERR_PTR(err);
67470
67471 mm = get_task_mm(task);
67472- if (mm && mm != current->mm &&
67473- !ptrace_may_access(task, mode)) {
67474+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67475+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67476 mmput(mm);
67477 mm = ERR_PTR(-EACCES);
67478 }
67479@@ -936,13 +973,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67480 spin_unlock(&fs->lock);
67481 return -EAGAIN;
67482 }
67483- fs->users++;
67484+ atomic_inc(&fs->users);
67485 spin_unlock(&fs->lock);
67486 return 0;
67487 }
67488 tsk->fs = copy_fs_struct(fs);
67489 if (!tsk->fs)
67490 return -ENOMEM;
67491+ gr_set_chroot_entries(tsk, &tsk->fs->root);
67492 return 0;
67493 }
67494
67495@@ -1209,6 +1247,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67496 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67497 #endif
67498 retval = -EAGAIN;
67499+
67500+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67501+
67502 if (atomic_read(&p->real_cred->user->processes) >=
67503 task_rlimit(p, RLIMIT_NPROC)) {
67504 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67505@@ -1431,6 +1472,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67506 /* Need tasklist lock for parent etc handling! */
67507 write_lock_irq(&tasklist_lock);
67508
67509+ /* synchronizes with gr_set_acls() */
67510+ gr_copy_label(p);
67511+
67512 /* CLONE_PARENT re-uses the old parent */
67513 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67514 p->real_parent = current->real_parent;
67515@@ -1541,6 +1585,8 @@ bad_fork_cleanup_count:
67516 bad_fork_free:
67517 free_task(p);
67518 fork_out:
67519+ gr_log_forkfail(retval);
67520+
67521 return ERR_PTR(retval);
67522 }
67523
67524@@ -1641,6 +1687,8 @@ long do_fork(unsigned long clone_flags,
67525 if (clone_flags & CLONE_PARENT_SETTID)
67526 put_user(nr, parent_tidptr);
67527
67528+ gr_handle_brute_check();
67529+
67530 if (clone_flags & CLONE_VFORK) {
67531 p->vfork_done = &vfork;
67532 init_completion(&vfork);
67533@@ -1739,7 +1787,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67534 return 0;
67535
67536 /* don't need lock here; in the worst case we'll do useless copy */
67537- if (fs->users == 1)
67538+ if (atomic_read(&fs->users) == 1)
67539 return 0;
67540
67541 *new_fsp = copy_fs_struct(fs);
67542@@ -1828,7 +1876,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67543 fs = current->fs;
67544 spin_lock(&fs->lock);
67545 current->fs = new_fs;
67546- if (--fs->users)
67547+ gr_set_chroot_entries(current, &current->fs->root);
67548+ if (atomic_dec_return(&fs->users))
67549 new_fs = NULL;
67550 else
67551 new_fs = fs;
67552diff --git a/kernel/futex.c b/kernel/futex.c
67553index 3717e7b..473c750 100644
67554--- a/kernel/futex.c
67555+++ b/kernel/futex.c
67556@@ -54,6 +54,7 @@
67557 #include <linux/mount.h>
67558 #include <linux/pagemap.h>
67559 #include <linux/syscalls.h>
67560+#include <linux/ptrace.h>
67561 #include <linux/signal.h>
67562 #include <linux/export.h>
67563 #include <linux/magic.h>
67564@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67565 struct page *page, *page_head;
67566 int err, ro = 0;
67567
67568+#ifdef CONFIG_PAX_SEGMEXEC
67569+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67570+ return -EFAULT;
67571+#endif
67572+
67573 /*
67574 * The futex address must be "naturally" aligned.
67575 */
67576@@ -2714,6 +2720,7 @@ static int __init futex_init(void)
67577 {
67578 u32 curval;
67579 int i;
67580+ mm_segment_t oldfs;
67581
67582 /*
67583 * This will fail and we want it. Some arch implementations do
67584@@ -2725,8 +2732,11 @@ static int __init futex_init(void)
67585 * implementation, the non-functional ones will return
67586 * -ENOSYS.
67587 */
67588+ oldfs = get_fs();
67589+ set_fs(USER_DS);
67590 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67591 futex_cmpxchg_enabled = 1;
67592+ set_fs(oldfs);
67593
67594 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67595 plist_head_init(&futex_queues[i].chain);
67596diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67597index 9b22d03..6295b62 100644
67598--- a/kernel/gcov/base.c
67599+++ b/kernel/gcov/base.c
67600@@ -102,11 +102,6 @@ void gcov_enable_events(void)
67601 }
67602
67603 #ifdef CONFIG_MODULES
67604-static inline int within(void *addr, void *start, unsigned long size)
67605-{
67606- return ((addr >= start) && (addr < start + size));
67607-}
67608-
67609 /* Update list and generate events when modules are unloaded. */
67610 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67611 void *data)
67612@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67613 prev = NULL;
67614 /* Remove entries located in module from linked list. */
67615 for (info = gcov_info_head; info; info = info->next) {
67616- if (within(info, mod->module_core, mod->core_size)) {
67617+ if (within_module_core_rw((unsigned long)info, mod)) {
67618 if (prev)
67619 prev->next = info->next;
67620 else
67621diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67622index 6db7a5e..25b6648 100644
67623--- a/kernel/hrtimer.c
67624+++ b/kernel/hrtimer.c
67625@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67626 local_irq_restore(flags);
67627 }
67628
67629-static void run_hrtimer_softirq(struct softirq_action *h)
67630+static void run_hrtimer_softirq(void)
67631 {
67632 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67633
67634diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67635index 4304919..408c4c0 100644
67636--- a/kernel/jump_label.c
67637+++ b/kernel/jump_label.c
67638@@ -13,6 +13,7 @@
67639 #include <linux/sort.h>
67640 #include <linux/err.h>
67641 #include <linux/static_key.h>
67642+#include <linux/mm.h>
67643
67644 #ifdef HAVE_JUMP_LABEL
67645
67646@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67647
67648 size = (((unsigned long)stop - (unsigned long)start)
67649 / sizeof(struct jump_entry));
67650+ pax_open_kernel();
67651 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67652+ pax_close_kernel();
67653 }
67654
67655 static void jump_label_update(struct static_key *key, int enable);
67656@@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67657 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67658 struct jump_entry *iter;
67659
67660+ pax_open_kernel();
67661 for (iter = iter_start; iter < iter_stop; iter++) {
67662 if (within_module_init(iter->code, mod))
67663 iter->code = 0;
67664 }
67665+ pax_close_kernel();
67666 }
67667
67668 static int
67669diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67670index 2169fee..45c017a 100644
67671--- a/kernel/kallsyms.c
67672+++ b/kernel/kallsyms.c
67673@@ -11,6 +11,9 @@
67674 * Changed the compression method from stem compression to "table lookup"
67675 * compression (see scripts/kallsyms.c for a more complete description)
67676 */
67677+#ifdef CONFIG_GRKERNSEC_HIDESYM
67678+#define __INCLUDED_BY_HIDESYM 1
67679+#endif
67680 #include <linux/kallsyms.h>
67681 #include <linux/module.h>
67682 #include <linux/init.h>
67683@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67684
67685 static inline int is_kernel_inittext(unsigned long addr)
67686 {
67687+ if (system_state != SYSTEM_BOOTING)
67688+ return 0;
67689+
67690 if (addr >= (unsigned long)_sinittext
67691 && addr <= (unsigned long)_einittext)
67692 return 1;
67693 return 0;
67694 }
67695
67696+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67697+#ifdef CONFIG_MODULES
67698+static inline int is_module_text(unsigned long addr)
67699+{
67700+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67701+ return 1;
67702+
67703+ addr = ktla_ktva(addr);
67704+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67705+}
67706+#else
67707+static inline int is_module_text(unsigned long addr)
67708+{
67709+ return 0;
67710+}
67711+#endif
67712+#endif
67713+
67714 static inline int is_kernel_text(unsigned long addr)
67715 {
67716 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67717@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67718
67719 static inline int is_kernel(unsigned long addr)
67720 {
67721+
67722+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67723+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
67724+ return 1;
67725+
67726+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67727+#else
67728 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67729+#endif
67730+
67731 return 1;
67732 return in_gate_area_no_mm(addr);
67733 }
67734
67735 static int is_ksym_addr(unsigned long addr)
67736 {
67737+
67738+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67739+ if (is_module_text(addr))
67740+ return 0;
67741+#endif
67742+
67743 if (all_var)
67744 return is_kernel(addr);
67745
67746@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67747
67748 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67749 {
67750- iter->name[0] = '\0';
67751 iter->nameoff = get_symbol_offset(new_pos);
67752 iter->pos = new_pos;
67753 }
67754@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67755 {
67756 struct kallsym_iter *iter = m->private;
67757
67758+#ifdef CONFIG_GRKERNSEC_HIDESYM
67759+ if (current_uid())
67760+ return 0;
67761+#endif
67762+
67763 /* Some debugging symbols have no name. Ignore them. */
67764 if (!iter->name[0])
67765 return 0;
67766@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67767 */
67768 type = iter->exported ? toupper(iter->type) :
67769 tolower(iter->type);
67770+
67771 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67772 type, iter->name, iter->module_name);
67773 } else
67774@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67775 struct kallsym_iter *iter;
67776 int ret;
67777
67778- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67779+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67780 if (!iter)
67781 return -ENOMEM;
67782 reset_iter(iter, 0);
67783diff --git a/kernel/kexec.c b/kernel/kexec.c
67784index 4e2e472..cd0c7ae 100644
67785--- a/kernel/kexec.c
67786+++ b/kernel/kexec.c
67787@@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67788 unsigned long flags)
67789 {
67790 struct compat_kexec_segment in;
67791- struct kexec_segment out, __user *ksegments;
67792+ struct kexec_segment out;
67793+ struct kexec_segment __user *ksegments;
67794 unsigned long i, result;
67795
67796 /* Don't allow clients that don't understand the native
67797diff --git a/kernel/kmod.c b/kernel/kmod.c
67798index ff2c7cb..085d7af 100644
67799--- a/kernel/kmod.c
67800+++ b/kernel/kmod.c
67801@@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67802 kfree(info->argv);
67803 }
67804
67805-static int call_modprobe(char *module_name, int wait)
67806+static int call_modprobe(char *module_name, char *module_param, int wait)
67807 {
67808 static char *envp[] = {
67809 "HOME=/",
67810@@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
67811 NULL
67812 };
67813
67814- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67815+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67816 if (!argv)
67817 goto out;
67818
67819@@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
67820 argv[1] = "-q";
67821 argv[2] = "--";
67822 argv[3] = module_name; /* check free_modprobe_argv() */
67823- argv[4] = NULL;
67824+ argv[4] = module_param;
67825+ argv[5] = NULL;
67826
67827 return call_usermodehelper_fns(modprobe_path, argv, envp,
67828 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67829@@ -112,9 +113,8 @@ out:
67830 * If module auto-loading support is disabled then this function
67831 * becomes a no-operation.
67832 */
67833-int __request_module(bool wait, const char *fmt, ...)
67834+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67835 {
67836- va_list args;
67837 char module_name[MODULE_NAME_LEN];
67838 unsigned int max_modprobes;
67839 int ret;
67840@@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
67841 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67842 static int kmod_loop_msg;
67843
67844- va_start(args, fmt);
67845- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67846- va_end(args);
67847+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67848 if (ret >= MODULE_NAME_LEN)
67849 return -ENAMETOOLONG;
67850
67851@@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
67852 if (ret)
67853 return ret;
67854
67855+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67856+ if (!current_uid()) {
67857+ /* hack to workaround consolekit/udisks stupidity */
67858+ read_lock(&tasklist_lock);
67859+ if (!strcmp(current->comm, "mount") &&
67860+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67861+ read_unlock(&tasklist_lock);
67862+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67863+ return -EPERM;
67864+ }
67865+ read_unlock(&tasklist_lock);
67866+ }
67867+#endif
67868+
67869 /* If modprobe needs a service that is in a module, we get a recursive
67870 * loop. Limit the number of running kmod threads to max_threads/2 or
67871 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67872@@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
67873
67874 trace_module_request(module_name, wait, _RET_IP_);
67875
67876- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67877+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67878
67879 atomic_dec(&kmod_concurrent);
67880 return ret;
67881 }
67882+
67883+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67884+{
67885+ va_list args;
67886+ int ret;
67887+
67888+ va_start(args, fmt);
67889+ ret = ____request_module(wait, module_param, fmt, args);
67890+ va_end(args);
67891+
67892+ return ret;
67893+}
67894+
67895+int __request_module(bool wait, const char *fmt, ...)
67896+{
67897+ va_list args;
67898+ int ret;
67899+
67900+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67901+ if (current_uid()) {
67902+ char module_param[MODULE_NAME_LEN];
67903+
67904+ memset(module_param, 0, sizeof(module_param));
67905+
67906+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67907+
67908+ va_start(args, fmt);
67909+ ret = ____request_module(wait, module_param, fmt, args);
67910+ va_end(args);
67911+
67912+ return ret;
67913+ }
67914+#endif
67915+
67916+ va_start(args, fmt);
67917+ ret = ____request_module(wait, NULL, fmt, args);
67918+ va_end(args);
67919+
67920+ return ret;
67921+}
67922+
67923 EXPORT_SYMBOL(__request_module);
67924 #endif /* CONFIG_MODULES */
67925
67926@@ -266,7 +319,7 @@ static int wait_for_helper(void *data)
67927 *
67928 * Thus the __user pointer cast is valid here.
67929 */
67930- sys_wait4(pid, (int __user *)&ret, 0, NULL);
67931+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67932
67933 /*
67934 * If ret is 0, either ____call_usermodehelper failed and the
67935diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67936index c62b854..cb67968 100644
67937--- a/kernel/kprobes.c
67938+++ b/kernel/kprobes.c
67939@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67940 * kernel image and loaded module images reside. This is required
67941 * so x86_64 can correctly handle the %rip-relative fixups.
67942 */
67943- kip->insns = module_alloc(PAGE_SIZE);
67944+ kip->insns = module_alloc_exec(PAGE_SIZE);
67945 if (!kip->insns) {
67946 kfree(kip);
67947 return NULL;
67948@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67949 */
67950 if (!list_is_singular(&kip->list)) {
67951 list_del(&kip->list);
67952- module_free(NULL, kip->insns);
67953+ module_free_exec(NULL, kip->insns);
67954 kfree(kip);
67955 }
67956 return 1;
67957@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67958 {
67959 int i, err = 0;
67960 unsigned long offset = 0, size = 0;
67961- char *modname, namebuf[128];
67962+ char *modname, namebuf[KSYM_NAME_LEN];
67963 const char *symbol_name;
67964 void *addr;
67965 struct kprobe_blackpoint *kb;
67966@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67967 const char *sym = NULL;
67968 unsigned int i = *(loff_t *) v;
67969 unsigned long offset = 0;
67970- char *modname, namebuf[128];
67971+ char *modname, namebuf[KSYM_NAME_LEN];
67972
67973 head = &kprobe_table[i];
67974 preempt_disable();
67975diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67976index 4e316e1..5501eef 100644
67977--- a/kernel/ksysfs.c
67978+++ b/kernel/ksysfs.c
67979@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67980 {
67981 if (count+1 > UEVENT_HELPER_PATH_LEN)
67982 return -ENOENT;
67983+ if (!capable(CAP_SYS_ADMIN))
67984+ return -EPERM;
67985 memcpy(uevent_helper, buf, count);
67986 uevent_helper[count] = '\0';
67987 if (count && uevent_helper[count-1] == '\n')
67988diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67989index ea9ee45..67ebc8f 100644
67990--- a/kernel/lockdep.c
67991+++ b/kernel/lockdep.c
67992@@ -590,6 +590,10 @@ static int static_obj(void *obj)
67993 end = (unsigned long) &_end,
67994 addr = (unsigned long) obj;
67995
67996+#ifdef CONFIG_PAX_KERNEXEC
67997+ start = ktla_ktva(start);
67998+#endif
67999+
68000 /*
68001 * static variable?
68002 */
68003@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68004 if (!static_obj(lock->key)) {
68005 debug_locks_off();
68006 printk("INFO: trying to register non-static key.\n");
68007+ printk("lock:%pS key:%pS.\n", lock, lock->key);
68008 printk("the code is fine but needs lockdep annotation.\n");
68009 printk("turning off the locking correctness validator.\n");
68010 dump_stack();
68011@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68012 if (!class)
68013 return 0;
68014 }
68015- atomic_inc((atomic_t *)&class->ops);
68016+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68017 if (very_verbose(class)) {
68018 printk("\nacquire class [%p] %s", class->key, class->name);
68019 if (class->name_version > 1)
68020diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68021index 91c32a0..b2c71c5 100644
68022--- a/kernel/lockdep_proc.c
68023+++ b/kernel/lockdep_proc.c
68024@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68025
68026 static void print_name(struct seq_file *m, struct lock_class *class)
68027 {
68028- char str[128];
68029+ char str[KSYM_NAME_LEN];
68030 const char *name = class->name;
68031
68032 if (!name) {
68033diff --git a/kernel/module.c b/kernel/module.c
68034index 4edbd9c..165e780 100644
68035--- a/kernel/module.c
68036+++ b/kernel/module.c
68037@@ -58,6 +58,7 @@
68038 #include <linux/jump_label.h>
68039 #include <linux/pfn.h>
68040 #include <linux/bsearch.h>
68041+#include <linux/grsecurity.h>
68042
68043 #define CREATE_TRACE_POINTS
68044 #include <trace/events/module.h>
68045@@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68046
68047 /* Bounds of module allocation, for speeding __module_address.
68048 * Protected by module_mutex. */
68049-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68050+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68051+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68052
68053 int register_module_notifier(struct notifier_block * nb)
68054 {
68055@@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68056 return true;
68057
68058 list_for_each_entry_rcu(mod, &modules, list) {
68059- struct symsearch arr[] = {
68060+ struct symsearch modarr[] = {
68061 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68062 NOT_GPL_ONLY, false },
68063 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68064@@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68065 #endif
68066 };
68067
68068- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68069+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68070 return true;
68071 }
68072 return false;
68073@@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68074 static int percpu_modalloc(struct module *mod,
68075 unsigned long size, unsigned long align)
68076 {
68077- if (align > PAGE_SIZE) {
68078+ if (align-1 >= PAGE_SIZE) {
68079 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68080 mod->name, align, PAGE_SIZE);
68081 align = PAGE_SIZE;
68082@@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68083 static ssize_t show_coresize(struct module_attribute *mattr,
68084 struct module_kobject *mk, char *buffer)
68085 {
68086- return sprintf(buffer, "%u\n", mk->mod->core_size);
68087+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68088 }
68089
68090 static struct module_attribute modinfo_coresize =
68091@@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68092 static ssize_t show_initsize(struct module_attribute *mattr,
68093 struct module_kobject *mk, char *buffer)
68094 {
68095- return sprintf(buffer, "%u\n", mk->mod->init_size);
68096+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68097 }
68098
68099 static struct module_attribute modinfo_initsize =
68100@@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68101 */
68102 #ifdef CONFIG_SYSFS
68103
68104-#ifdef CONFIG_KALLSYMS
68105+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68106 static inline bool sect_empty(const Elf_Shdr *sect)
68107 {
68108 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68109@@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68110
68111 static void unset_module_core_ro_nx(struct module *mod)
68112 {
68113- set_page_attributes(mod->module_core + mod->core_text_size,
68114- mod->module_core + mod->core_size,
68115+ set_page_attributes(mod->module_core_rw,
68116+ mod->module_core_rw + mod->core_size_rw,
68117 set_memory_x);
68118- set_page_attributes(mod->module_core,
68119- mod->module_core + mod->core_ro_size,
68120+ set_page_attributes(mod->module_core_rx,
68121+ mod->module_core_rx + mod->core_size_rx,
68122 set_memory_rw);
68123 }
68124
68125 static void unset_module_init_ro_nx(struct module *mod)
68126 {
68127- set_page_attributes(mod->module_init + mod->init_text_size,
68128- mod->module_init + mod->init_size,
68129+ set_page_attributes(mod->module_init_rw,
68130+ mod->module_init_rw + mod->init_size_rw,
68131 set_memory_x);
68132- set_page_attributes(mod->module_init,
68133- mod->module_init + mod->init_ro_size,
68134+ set_page_attributes(mod->module_init_rx,
68135+ mod->module_init_rx + mod->init_size_rx,
68136 set_memory_rw);
68137 }
68138
68139@@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68140
68141 mutex_lock(&module_mutex);
68142 list_for_each_entry_rcu(mod, &modules, list) {
68143- if ((mod->module_core) && (mod->core_text_size)) {
68144- set_page_attributes(mod->module_core,
68145- mod->module_core + mod->core_text_size,
68146+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
68147+ set_page_attributes(mod->module_core_rx,
68148+ mod->module_core_rx + mod->core_size_rx,
68149 set_memory_rw);
68150 }
68151- if ((mod->module_init) && (mod->init_text_size)) {
68152- set_page_attributes(mod->module_init,
68153- mod->module_init + mod->init_text_size,
68154+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
68155+ set_page_attributes(mod->module_init_rx,
68156+ mod->module_init_rx + mod->init_size_rx,
68157 set_memory_rw);
68158 }
68159 }
68160@@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68161
68162 mutex_lock(&module_mutex);
68163 list_for_each_entry_rcu(mod, &modules, list) {
68164- if ((mod->module_core) && (mod->core_text_size)) {
68165- set_page_attributes(mod->module_core,
68166- mod->module_core + mod->core_text_size,
68167+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
68168+ set_page_attributes(mod->module_core_rx,
68169+ mod->module_core_rx + mod->core_size_rx,
68170 set_memory_ro);
68171 }
68172- if ((mod->module_init) && (mod->init_text_size)) {
68173- set_page_attributes(mod->module_init,
68174- mod->module_init + mod->init_text_size,
68175+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
68176+ set_page_attributes(mod->module_init_rx,
68177+ mod->module_init_rx + mod->init_size_rx,
68178 set_memory_ro);
68179 }
68180 }
68181@@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68182
68183 /* This may be NULL, but that's OK */
68184 unset_module_init_ro_nx(mod);
68185- module_free(mod, mod->module_init);
68186+ module_free(mod, mod->module_init_rw);
68187+ module_free_exec(mod, mod->module_init_rx);
68188 kfree(mod->args);
68189 percpu_modfree(mod);
68190
68191 /* Free lock-classes: */
68192- lockdep_free_key_range(mod->module_core, mod->core_size);
68193+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68194+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68195
68196 /* Finally, free the core (containing the module structure) */
68197 unset_module_core_ro_nx(mod);
68198- module_free(mod, mod->module_core);
68199+ module_free_exec(mod, mod->module_core_rx);
68200+ module_free(mod, mod->module_core_rw);
68201
68202 #ifdef CONFIG_MPU
68203 update_protections(current->mm);
68204@@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68205 int ret = 0;
68206 const struct kernel_symbol *ksym;
68207
68208+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68209+ int is_fs_load = 0;
68210+ int register_filesystem_found = 0;
68211+ char *p;
68212+
68213+ p = strstr(mod->args, "grsec_modharden_fs");
68214+ if (p) {
68215+ char *endptr = p + strlen("grsec_modharden_fs");
68216+ /* copy \0 as well */
68217+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68218+ is_fs_load = 1;
68219+ }
68220+#endif
68221+
68222 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68223 const char *name = info->strtab + sym[i].st_name;
68224
68225+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68226+ /* it's a real shame this will never get ripped and copied
68227+ upstream! ;(
68228+ */
68229+ if (is_fs_load && !strcmp(name, "register_filesystem"))
68230+ register_filesystem_found = 1;
68231+#endif
68232+
68233 switch (sym[i].st_shndx) {
68234 case SHN_COMMON:
68235 /* We compiled with -fno-common. These are not
68236@@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68237 ksym = resolve_symbol_wait(mod, info, name);
68238 /* Ok if resolved. */
68239 if (ksym && !IS_ERR(ksym)) {
68240+ pax_open_kernel();
68241 sym[i].st_value = ksym->value;
68242+ pax_close_kernel();
68243 break;
68244 }
68245
68246@@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68247 secbase = (unsigned long)mod_percpu(mod);
68248 else
68249 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68250+ pax_open_kernel();
68251 sym[i].st_value += secbase;
68252+ pax_close_kernel();
68253 break;
68254 }
68255 }
68256
68257+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68258+ if (is_fs_load && !register_filesystem_found) {
68259+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68260+ ret = -EPERM;
68261+ }
68262+#endif
68263+
68264 return ret;
68265 }
68266
68267@@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68268 || s->sh_entsize != ~0UL
68269 || strstarts(sname, ".init"))
68270 continue;
68271- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68272+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68273+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68274+ else
68275+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68276 pr_debug("\t%s\n", sname);
68277 }
68278- switch (m) {
68279- case 0: /* executable */
68280- mod->core_size = debug_align(mod->core_size);
68281- mod->core_text_size = mod->core_size;
68282- break;
68283- case 1: /* RO: text and ro-data */
68284- mod->core_size = debug_align(mod->core_size);
68285- mod->core_ro_size = mod->core_size;
68286- break;
68287- case 3: /* whole core */
68288- mod->core_size = debug_align(mod->core_size);
68289- break;
68290- }
68291 }
68292
68293 pr_debug("Init section allocation order:\n");
68294@@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68295 || s->sh_entsize != ~0UL
68296 || !strstarts(sname, ".init"))
68297 continue;
68298- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68299- | INIT_OFFSET_MASK);
68300+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68301+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68302+ else
68303+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68304+ s->sh_entsize |= INIT_OFFSET_MASK;
68305 pr_debug("\t%s\n", sname);
68306 }
68307- switch (m) {
68308- case 0: /* executable */
68309- mod->init_size = debug_align(mod->init_size);
68310- mod->init_text_size = mod->init_size;
68311- break;
68312- case 1: /* RO: text and ro-data */
68313- mod->init_size = debug_align(mod->init_size);
68314- mod->init_ro_size = mod->init_size;
68315- break;
68316- case 3: /* whole init */
68317- mod->init_size = debug_align(mod->init_size);
68318- break;
68319- }
68320 }
68321 }
68322
68323@@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68324
68325 /* Put symbol section at end of init part of module. */
68326 symsect->sh_flags |= SHF_ALLOC;
68327- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68328+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68329 info->index.sym) | INIT_OFFSET_MASK;
68330 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68331
68332@@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68333 }
68334
68335 /* Append room for core symbols at end of core part. */
68336- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68337- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68338- mod->core_size += strtab_size;
68339+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68340+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68341+ mod->core_size_rx += strtab_size;
68342
68343 /* Put string table section at end of init part of module. */
68344 strsect->sh_flags |= SHF_ALLOC;
68345- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68346+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68347 info->index.str) | INIT_OFFSET_MASK;
68348 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68349 }
68350@@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68351 /* Make sure we get permanent strtab: don't use info->strtab. */
68352 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68353
68354+ pax_open_kernel();
68355+
68356 /* Set types up while we still have access to sections. */
68357 for (i = 0; i < mod->num_symtab; i++)
68358 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68359
68360- mod->core_symtab = dst = mod->module_core + info->symoffs;
68361- mod->core_strtab = s = mod->module_core + info->stroffs;
68362+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68363+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68364 src = mod->symtab;
68365 *dst = *src;
68366 *s++ = 0;
68367@@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68368 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68369 }
68370 mod->core_num_syms = ndst;
68371+
68372+ pax_close_kernel();
68373 }
68374 #else
68375 static inline void layout_symtab(struct module *mod, struct load_info *info)
68376@@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
68377 return size == 0 ? NULL : vmalloc_exec(size);
68378 }
68379
68380-static void *module_alloc_update_bounds(unsigned long size)
68381+static void *module_alloc_update_bounds_rw(unsigned long size)
68382 {
68383 void *ret = module_alloc(size);
68384
68385 if (ret) {
68386 mutex_lock(&module_mutex);
68387 /* Update module bounds. */
68388- if ((unsigned long)ret < module_addr_min)
68389- module_addr_min = (unsigned long)ret;
68390- if ((unsigned long)ret + size > module_addr_max)
68391- module_addr_max = (unsigned long)ret + size;
68392+ if ((unsigned long)ret < module_addr_min_rw)
68393+ module_addr_min_rw = (unsigned long)ret;
68394+ if ((unsigned long)ret + size > module_addr_max_rw)
68395+ module_addr_max_rw = (unsigned long)ret + size;
68396+ mutex_unlock(&module_mutex);
68397+ }
68398+ return ret;
68399+}
68400+
68401+static void *module_alloc_update_bounds_rx(unsigned long size)
68402+{
68403+ void *ret = module_alloc_exec(size);
68404+
68405+ if (ret) {
68406+ mutex_lock(&module_mutex);
68407+ /* Update module bounds. */
68408+ if ((unsigned long)ret < module_addr_min_rx)
68409+ module_addr_min_rx = (unsigned long)ret;
68410+ if ((unsigned long)ret + size > module_addr_max_rx)
68411+ module_addr_max_rx = (unsigned long)ret + size;
68412 mutex_unlock(&module_mutex);
68413 }
68414 return ret;
68415@@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
68416 static int check_modinfo(struct module *mod, struct load_info *info)
68417 {
68418 const char *modmagic = get_modinfo(info, "vermagic");
68419+ const char *license = get_modinfo(info, "license");
68420 int err;
68421
68422+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68423+ if (!license || !license_is_gpl_compatible(license))
68424+ return -ENOEXEC;
68425+#endif
68426+
68427 /* This is allowed: modprobe --force will invalidate it. */
68428 if (!modmagic) {
68429 err = try_to_force_load(mod, "bad vermagic");
68430@@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68431 }
68432
68433 /* Set up license info based on the info section */
68434- set_license(mod, get_modinfo(info, "license"));
68435+ set_license(mod, license);
68436
68437 return 0;
68438 }
68439@@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
68440 void *ptr;
68441
68442 /* Do the allocs. */
68443- ptr = module_alloc_update_bounds(mod->core_size);
68444+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68445 /*
68446 * The pointer to this block is stored in the module structure
68447 * which is inside the block. Just mark it as not being a
68448@@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
68449 if (!ptr)
68450 return -ENOMEM;
68451
68452- memset(ptr, 0, mod->core_size);
68453- mod->module_core = ptr;
68454+ memset(ptr, 0, mod->core_size_rw);
68455+ mod->module_core_rw = ptr;
68456
68457- ptr = module_alloc_update_bounds(mod->init_size);
68458+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68459 /*
68460 * The pointer to this block is stored in the module structure
68461 * which is inside the block. This block doesn't need to be
68462 * scanned as it contains data and code that will be freed
68463 * after the module is initialized.
68464 */
68465- kmemleak_ignore(ptr);
68466- if (!ptr && mod->init_size) {
68467- module_free(mod, mod->module_core);
68468+ kmemleak_not_leak(ptr);
68469+ if (!ptr && mod->init_size_rw) {
68470+ module_free(mod, mod->module_core_rw);
68471 return -ENOMEM;
68472 }
68473- memset(ptr, 0, mod->init_size);
68474- mod->module_init = ptr;
68475+ memset(ptr, 0, mod->init_size_rw);
68476+ mod->module_init_rw = ptr;
68477+
68478+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68479+ kmemleak_not_leak(ptr);
68480+ if (!ptr) {
68481+ module_free(mod, mod->module_init_rw);
68482+ module_free(mod, mod->module_core_rw);
68483+ return -ENOMEM;
68484+ }
68485+
68486+ pax_open_kernel();
68487+ memset(ptr, 0, mod->core_size_rx);
68488+ pax_close_kernel();
68489+ mod->module_core_rx = ptr;
68490+
68491+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68492+ kmemleak_not_leak(ptr);
68493+ if (!ptr && mod->init_size_rx) {
68494+ module_free_exec(mod, mod->module_core_rx);
68495+ module_free(mod, mod->module_init_rw);
68496+ module_free(mod, mod->module_core_rw);
68497+ return -ENOMEM;
68498+ }
68499+
68500+ pax_open_kernel();
68501+ memset(ptr, 0, mod->init_size_rx);
68502+ pax_close_kernel();
68503+ mod->module_init_rx = ptr;
68504
68505 /* Transfer each section which specifies SHF_ALLOC */
68506 pr_debug("final section addresses:\n");
68507@@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
68508 if (!(shdr->sh_flags & SHF_ALLOC))
68509 continue;
68510
68511- if (shdr->sh_entsize & INIT_OFFSET_MASK)
68512- dest = mod->module_init
68513- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68514- else
68515- dest = mod->module_core + shdr->sh_entsize;
68516+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68517+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68518+ dest = mod->module_init_rw
68519+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68520+ else
68521+ dest = mod->module_init_rx
68522+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68523+ } else {
68524+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68525+ dest = mod->module_core_rw + shdr->sh_entsize;
68526+ else
68527+ dest = mod->module_core_rx + shdr->sh_entsize;
68528+ }
68529+
68530+ if (shdr->sh_type != SHT_NOBITS) {
68531+
68532+#ifdef CONFIG_PAX_KERNEXEC
68533+#ifdef CONFIG_X86_64
68534+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68535+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68536+#endif
68537+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68538+ pax_open_kernel();
68539+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68540+ pax_close_kernel();
68541+ } else
68542+#endif
68543
68544- if (shdr->sh_type != SHT_NOBITS)
68545 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68546+ }
68547 /* Update sh_addr to point to copy in image. */
68548- shdr->sh_addr = (unsigned long)dest;
68549+
68550+#ifdef CONFIG_PAX_KERNEXEC
68551+ if (shdr->sh_flags & SHF_EXECINSTR)
68552+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
68553+ else
68554+#endif
68555+
68556+ shdr->sh_addr = (unsigned long)dest;
68557 pr_debug("\t0x%lx %s\n",
68558 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68559 }
68560@@ -2759,12 +2859,12 @@ static void flush_module_icache(const struct module *mod)
68561 * Do it before processing of module parameters, so the module
68562 * can provide parameter accessor functions of its own.
68563 */
68564- if (mod->module_init)
68565- flush_icache_range((unsigned long)mod->module_init,
68566- (unsigned long)mod->module_init
68567- + mod->init_size);
68568- flush_icache_range((unsigned long)mod->module_core,
68569- (unsigned long)mod->module_core + mod->core_size);
68570+ if (mod->module_init_rx)
68571+ flush_icache_range((unsigned long)mod->module_init_rx,
68572+ (unsigned long)mod->module_init_rx
68573+ + mod->init_size_rx);
68574+ flush_icache_range((unsigned long)mod->module_core_rx,
68575+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
68576
68577 set_fs(old_fs);
68578 }
68579@@ -2834,8 +2934,10 @@ out:
68580 static void module_deallocate(struct module *mod, struct load_info *info)
68581 {
68582 percpu_modfree(mod);
68583- module_free(mod, mod->module_init);
68584- module_free(mod, mod->module_core);
68585+ module_free_exec(mod, mod->module_init_rx);
68586+ module_free_exec(mod, mod->module_core_rx);
68587+ module_free(mod, mod->module_init_rw);
68588+ module_free(mod, mod->module_core_rw);
68589 }
68590
68591 int __weak module_finalize(const Elf_Ehdr *hdr,
68592@@ -2848,7 +2950,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68593 static int post_relocation(struct module *mod, const struct load_info *info)
68594 {
68595 /* Sort exception table now relocations are done. */
68596+ pax_open_kernel();
68597 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68598+ pax_close_kernel();
68599
68600 /* Copy relocated percpu area over. */
68601 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68602@@ -2899,9 +3003,38 @@ static struct module *load_module(void __user *umod,
68603 if (err)
68604 goto free_unload;
68605
68606+ /* Now copy in args */
68607+ mod->args = strndup_user(uargs, ~0UL >> 1);
68608+ if (IS_ERR(mod->args)) {
68609+ err = PTR_ERR(mod->args);
68610+ goto free_unload;
68611+ }
68612+
68613 /* Set up MODINFO_ATTR fields */
68614 setup_modinfo(mod, &info);
68615
68616+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68617+ {
68618+ char *p, *p2;
68619+
68620+ if (strstr(mod->args, "grsec_modharden_netdev")) {
68621+ 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);
68622+ err = -EPERM;
68623+ goto free_modinfo;
68624+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68625+ p += strlen("grsec_modharden_normal");
68626+ p2 = strstr(p, "_");
68627+ if (p2) {
68628+ *p2 = '\0';
68629+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68630+ *p2 = '_';
68631+ }
68632+ err = -EPERM;
68633+ goto free_modinfo;
68634+ }
68635+ }
68636+#endif
68637+
68638 /* Fix up syms, so that st_value is a pointer to location. */
68639 err = simplify_symbols(mod, &info);
68640 if (err < 0)
68641@@ -2917,13 +3050,6 @@ static struct module *load_module(void __user *umod,
68642
68643 flush_module_icache(mod);
68644
68645- /* Now copy in args */
68646- mod->args = strndup_user(uargs, ~0UL >> 1);
68647- if (IS_ERR(mod->args)) {
68648- err = PTR_ERR(mod->args);
68649- goto free_arch_cleanup;
68650- }
68651-
68652 /* Mark state as coming so strong_try_module_get() ignores us. */
68653 mod->state = MODULE_STATE_COMING;
68654
68655@@ -2981,11 +3107,10 @@ static struct module *load_module(void __user *umod,
68656 unlock:
68657 mutex_unlock(&module_mutex);
68658 synchronize_sched();
68659- kfree(mod->args);
68660- free_arch_cleanup:
68661 module_arch_cleanup(mod);
68662 free_modinfo:
68663 free_modinfo(mod);
68664+ kfree(mod->args);
68665 free_unload:
68666 module_unload_free(mod);
68667 free_module:
68668@@ -3026,16 +3151,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68669 MODULE_STATE_COMING, mod);
68670
68671 /* Set RO and NX regions for core */
68672- set_section_ro_nx(mod->module_core,
68673- mod->core_text_size,
68674- mod->core_ro_size,
68675- mod->core_size);
68676+ set_section_ro_nx(mod->module_core_rx,
68677+ mod->core_size_rx,
68678+ mod->core_size_rx,
68679+ mod->core_size_rx);
68680
68681 /* Set RO and NX regions for init */
68682- set_section_ro_nx(mod->module_init,
68683- mod->init_text_size,
68684- mod->init_ro_size,
68685- mod->init_size);
68686+ set_section_ro_nx(mod->module_init_rx,
68687+ mod->init_size_rx,
68688+ mod->init_size_rx,
68689+ mod->init_size_rx);
68690
68691 do_mod_ctors(mod);
68692 /* Start the module */
68693@@ -3081,11 +3206,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68694 mod->strtab = mod->core_strtab;
68695 #endif
68696 unset_module_init_ro_nx(mod);
68697- module_free(mod, mod->module_init);
68698- mod->module_init = NULL;
68699- mod->init_size = 0;
68700- mod->init_ro_size = 0;
68701- mod->init_text_size = 0;
68702+ module_free(mod, mod->module_init_rw);
68703+ module_free_exec(mod, mod->module_init_rx);
68704+ mod->module_init_rw = NULL;
68705+ mod->module_init_rx = NULL;
68706+ mod->init_size_rw = 0;
68707+ mod->init_size_rx = 0;
68708 mutex_unlock(&module_mutex);
68709
68710 return 0;
68711@@ -3116,10 +3242,16 @@ static const char *get_ksymbol(struct module *mod,
68712 unsigned long nextval;
68713
68714 /* At worse, next value is at end of module */
68715- if (within_module_init(addr, mod))
68716- nextval = (unsigned long)mod->module_init+mod->init_text_size;
68717+ if (within_module_init_rx(addr, mod))
68718+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68719+ else if (within_module_init_rw(addr, mod))
68720+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68721+ else if (within_module_core_rx(addr, mod))
68722+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68723+ else if (within_module_core_rw(addr, mod))
68724+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68725 else
68726- nextval = (unsigned long)mod->module_core+mod->core_text_size;
68727+ return NULL;
68728
68729 /* Scan for closest preceding symbol, and next symbol. (ELF
68730 starts real symbols at 1). */
68731@@ -3354,7 +3486,7 @@ static int m_show(struct seq_file *m, void *p)
68732 char buf[8];
68733
68734 seq_printf(m, "%s %u",
68735- mod->name, mod->init_size + mod->core_size);
68736+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68737 print_unload_info(m, mod);
68738
68739 /* Informative for users. */
68740@@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
68741 mod->state == MODULE_STATE_COMING ? "Loading":
68742 "Live");
68743 /* Used by oprofile and other similar tools. */
68744- seq_printf(m, " 0x%pK", mod->module_core);
68745+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68746
68747 /* Taints info */
68748 if (mod->taints)
68749@@ -3399,7 +3531,17 @@ static const struct file_operations proc_modules_operations = {
68750
68751 static int __init proc_modules_init(void)
68752 {
68753+#ifndef CONFIG_GRKERNSEC_HIDESYM
68754+#ifdef CONFIG_GRKERNSEC_PROC_USER
68755+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68756+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68757+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68758+#else
68759 proc_create("modules", 0, NULL, &proc_modules_operations);
68760+#endif
68761+#else
68762+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68763+#endif
68764 return 0;
68765 }
68766 module_init(proc_modules_init);
68767@@ -3458,12 +3600,12 @@ struct module *__module_address(unsigned long addr)
68768 {
68769 struct module *mod;
68770
68771- if (addr < module_addr_min || addr > module_addr_max)
68772+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68773+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
68774 return NULL;
68775
68776 list_for_each_entry_rcu(mod, &modules, list)
68777- if (within_module_core(addr, mod)
68778- || within_module_init(addr, mod))
68779+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
68780 return mod;
68781 return NULL;
68782 }
68783@@ -3497,11 +3639,20 @@ bool is_module_text_address(unsigned long addr)
68784 */
68785 struct module *__module_text_address(unsigned long addr)
68786 {
68787- struct module *mod = __module_address(addr);
68788+ struct module *mod;
68789+
68790+#ifdef CONFIG_X86_32
68791+ addr = ktla_ktva(addr);
68792+#endif
68793+
68794+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68795+ return NULL;
68796+
68797+ mod = __module_address(addr);
68798+
68799 if (mod) {
68800 /* Make sure it's within the text section. */
68801- if (!within(addr, mod->module_init, mod->init_text_size)
68802- && !within(addr, mod->module_core, mod->core_text_size))
68803+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68804 mod = NULL;
68805 }
68806 return mod;
68807diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68808index 7e3443f..b2a1e6b 100644
68809--- a/kernel/mutex-debug.c
68810+++ b/kernel/mutex-debug.c
68811@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68812 }
68813
68814 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68815- struct thread_info *ti)
68816+ struct task_struct *task)
68817 {
68818 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68819
68820 /* Mark the current thread as blocked on the lock: */
68821- ti->task->blocked_on = waiter;
68822+ task->blocked_on = waiter;
68823 }
68824
68825 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68826- struct thread_info *ti)
68827+ struct task_struct *task)
68828 {
68829 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68830- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68831- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68832- ti->task->blocked_on = NULL;
68833+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
68834+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68835+ task->blocked_on = NULL;
68836
68837 list_del_init(&waiter->list);
68838 waiter->task = NULL;
68839diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68840index 0799fd3..d06ae3b 100644
68841--- a/kernel/mutex-debug.h
68842+++ b/kernel/mutex-debug.h
68843@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68844 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68845 extern void debug_mutex_add_waiter(struct mutex *lock,
68846 struct mutex_waiter *waiter,
68847- struct thread_info *ti);
68848+ struct task_struct *task);
68849 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68850- struct thread_info *ti);
68851+ struct task_struct *task);
68852 extern void debug_mutex_unlock(struct mutex *lock);
68853 extern void debug_mutex_init(struct mutex *lock, const char *name,
68854 struct lock_class_key *key);
68855diff --git a/kernel/mutex.c b/kernel/mutex.c
68856index a307cc9..27fd2e9 100644
68857--- a/kernel/mutex.c
68858+++ b/kernel/mutex.c
68859@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68860 spin_lock_mutex(&lock->wait_lock, flags);
68861
68862 debug_mutex_lock_common(lock, &waiter);
68863- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68864+ debug_mutex_add_waiter(lock, &waiter, task);
68865
68866 /* add waiting tasks to the end of the waitqueue (FIFO): */
68867 list_add_tail(&waiter.list, &lock->wait_list);
68868@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68869 * TASK_UNINTERRUPTIBLE case.)
68870 */
68871 if (unlikely(signal_pending_state(state, task))) {
68872- mutex_remove_waiter(lock, &waiter,
68873- task_thread_info(task));
68874+ mutex_remove_waiter(lock, &waiter, task);
68875 mutex_release(&lock->dep_map, 1, ip);
68876 spin_unlock_mutex(&lock->wait_lock, flags);
68877
68878@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68879 done:
68880 lock_acquired(&lock->dep_map, ip);
68881 /* got the lock - rejoice! */
68882- mutex_remove_waiter(lock, &waiter, current_thread_info());
68883+ mutex_remove_waiter(lock, &waiter, task);
68884 mutex_set_owner(lock);
68885
68886 /* set it to 0 if there are no waiters left: */
68887diff --git a/kernel/panic.c b/kernel/panic.c
68888index d2a5f4e..5edc1d9 100644
68889--- a/kernel/panic.c
68890+++ b/kernel/panic.c
68891@@ -75,6 +75,14 @@ void panic(const char *fmt, ...)
68892 int state = 0;
68893
68894 /*
68895+ * Disable local interrupts. This will prevent panic_smp_self_stop
68896+ * from deadlocking the first cpu that invokes the panic, since
68897+ * there is nothing to prevent an interrupt handler (that runs
68898+ * after the panic_lock is acquired) from invoking panic again.
68899+ */
68900+ local_irq_disable();
68901+
68902+ /*
68903 * It's possible to come here directly from a panic-assertion and
68904 * not have preempt disabled. Some functions called from here want
68905 * preempt to be disabled. No point enabling it later though...
68906@@ -402,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68907 const char *board;
68908
68909 printk(KERN_WARNING "------------[ cut here ]------------\n");
68910- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68911+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68912 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68913 if (board)
68914 printk(KERN_WARNING "Hardware name: %s\n", board);
68915@@ -457,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68916 */
68917 void __stack_chk_fail(void)
68918 {
68919- panic("stack-protector: Kernel stack is corrupted in: %p\n",
68920+ dump_stack();
68921+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68922 __builtin_return_address(0));
68923 }
68924 EXPORT_SYMBOL(__stack_chk_fail);
68925diff --git a/kernel/pid.c b/kernel/pid.c
68926index e86b291a..e8b0fb5 100644
68927--- a/kernel/pid.c
68928+++ b/kernel/pid.c
68929@@ -33,6 +33,7 @@
68930 #include <linux/rculist.h>
68931 #include <linux/bootmem.h>
68932 #include <linux/hash.h>
68933+#include <linux/security.h>
68934 #include <linux/pid_namespace.h>
68935 #include <linux/init_task.h>
68936 #include <linux/syscalls.h>
68937@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68938
68939 int pid_max = PID_MAX_DEFAULT;
68940
68941-#define RESERVED_PIDS 300
68942+#define RESERVED_PIDS 500
68943
68944 int pid_max_min = RESERVED_PIDS + 1;
68945 int pid_max_max = PID_MAX_LIMIT;
68946@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68947 */
68948 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68949 {
68950+ struct task_struct *task;
68951+
68952 rcu_lockdep_assert(rcu_read_lock_held(),
68953 "find_task_by_pid_ns() needs rcu_read_lock()"
68954 " protection");
68955- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68956+
68957+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68958+
68959+ if (gr_pid_is_chrooted(task))
68960+ return NULL;
68961+
68962+ return task;
68963 }
68964
68965 struct task_struct *find_task_by_vpid(pid_t vnr)
68966@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68967 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68968 }
68969
68970+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68971+{
68972+ rcu_lockdep_assert(rcu_read_lock_held(),
68973+ "find_task_by_pid_ns() needs rcu_read_lock()"
68974+ " protection");
68975+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68976+}
68977+
68978 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68979 {
68980 struct pid *pid;
68981diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
68982index b3c7fd5..6144bab 100644
68983--- a/kernel/pid_namespace.c
68984+++ b/kernel/pid_namespace.c
68985@@ -232,15 +232,19 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
68986 */
68987
68988 tmp.data = &current->nsproxy->pid_ns->last_pid;
68989- return proc_dointvec(&tmp, write, buffer, lenp, ppos);
68990+ return proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
68991 }
68992
68993+extern int pid_max;
68994+static int zero = 0;
68995 static struct ctl_table pid_ns_ctl_table[] = {
68996 {
68997 .procname = "ns_last_pid",
68998 .maxlen = sizeof(int),
68999 .mode = 0666, /* permissions are checked in the handler */
69000 .proc_handler = pid_ns_ctl_handler,
69001+ .extra1 = &zero,
69002+ .extra2 = &pid_max,
69003 },
69004 { }
69005 };
69006diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69007index 125cb67..a4d1c30 100644
69008--- a/kernel/posix-cpu-timers.c
69009+++ b/kernel/posix-cpu-timers.c
69010@@ -6,6 +6,7 @@
69011 #include <linux/posix-timers.h>
69012 #include <linux/errno.h>
69013 #include <linux/math64.h>
69014+#include <linux/security.h>
69015 #include <asm/uaccess.h>
69016 #include <linux/kernel_stat.h>
69017 #include <trace/events/timer.h>
69018@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
69019
69020 static __init int init_posix_cpu_timers(void)
69021 {
69022- struct k_clock process = {
69023+ static struct k_clock process = {
69024 .clock_getres = process_cpu_clock_getres,
69025 .clock_get = process_cpu_clock_get,
69026 .timer_create = process_cpu_timer_create,
69027 .nsleep = process_cpu_nsleep,
69028 .nsleep_restart = process_cpu_nsleep_restart,
69029 };
69030- struct k_clock thread = {
69031+ static struct k_clock thread = {
69032 .clock_getres = thread_cpu_clock_getres,
69033 .clock_get = thread_cpu_clock_get,
69034 .timer_create = thread_cpu_timer_create,
69035diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69036index 69185ae..cc2847a 100644
69037--- a/kernel/posix-timers.c
69038+++ b/kernel/posix-timers.c
69039@@ -43,6 +43,7 @@
69040 #include <linux/idr.h>
69041 #include <linux/posix-clock.h>
69042 #include <linux/posix-timers.h>
69043+#include <linux/grsecurity.h>
69044 #include <linux/syscalls.h>
69045 #include <linux/wait.h>
69046 #include <linux/workqueue.h>
69047@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69048 * which we beg off on and pass to do_sys_settimeofday().
69049 */
69050
69051-static struct k_clock posix_clocks[MAX_CLOCKS];
69052+static struct k_clock *posix_clocks[MAX_CLOCKS];
69053
69054 /*
69055 * These ones are defined below.
69056@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69057 */
69058 static __init int init_posix_timers(void)
69059 {
69060- struct k_clock clock_realtime = {
69061+ static struct k_clock clock_realtime = {
69062 .clock_getres = hrtimer_get_res,
69063 .clock_get = posix_clock_realtime_get,
69064 .clock_set = posix_clock_realtime_set,
69065@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69066 .timer_get = common_timer_get,
69067 .timer_del = common_timer_del,
69068 };
69069- struct k_clock clock_monotonic = {
69070+ static struct k_clock clock_monotonic = {
69071 .clock_getres = hrtimer_get_res,
69072 .clock_get = posix_ktime_get_ts,
69073 .nsleep = common_nsleep,
69074@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69075 .timer_get = common_timer_get,
69076 .timer_del = common_timer_del,
69077 };
69078- struct k_clock clock_monotonic_raw = {
69079+ static struct k_clock clock_monotonic_raw = {
69080 .clock_getres = hrtimer_get_res,
69081 .clock_get = posix_get_monotonic_raw,
69082 };
69083- struct k_clock clock_realtime_coarse = {
69084+ static struct k_clock clock_realtime_coarse = {
69085 .clock_getres = posix_get_coarse_res,
69086 .clock_get = posix_get_realtime_coarse,
69087 };
69088- struct k_clock clock_monotonic_coarse = {
69089+ static struct k_clock clock_monotonic_coarse = {
69090 .clock_getres = posix_get_coarse_res,
69091 .clock_get = posix_get_monotonic_coarse,
69092 };
69093- struct k_clock clock_boottime = {
69094+ static struct k_clock clock_boottime = {
69095 .clock_getres = hrtimer_get_res,
69096 .clock_get = posix_get_boottime,
69097 .nsleep = common_nsleep,
69098@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69099 return;
69100 }
69101
69102- posix_clocks[clock_id] = *new_clock;
69103+ posix_clocks[clock_id] = new_clock;
69104 }
69105 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69106
69107@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69108 return (id & CLOCKFD_MASK) == CLOCKFD ?
69109 &clock_posix_dynamic : &clock_posix_cpu;
69110
69111- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69112+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69113 return NULL;
69114- return &posix_clocks[id];
69115+ return posix_clocks[id];
69116 }
69117
69118 static int common_timer_create(struct k_itimer *new_timer)
69119@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69120 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69121 return -EFAULT;
69122
69123+ /* only the CLOCK_REALTIME clock can be set, all other clocks
69124+ have their clock_set fptr set to a nosettime dummy function
69125+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69126+ call common_clock_set, which calls do_sys_settimeofday, which
69127+ we hook
69128+ */
69129+
69130 return kc->clock_set(which_clock, &new_tp);
69131 }
69132
69133diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69134index d523593..68197a4 100644
69135--- a/kernel/power/poweroff.c
69136+++ b/kernel/power/poweroff.c
69137@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69138 .enable_mask = SYSRQ_ENABLE_BOOT,
69139 };
69140
69141-static int pm_sysrq_init(void)
69142+static int __init pm_sysrq_init(void)
69143 {
69144 register_sysrq_key('o', &sysrq_poweroff_op);
69145 return 0;
69146diff --git a/kernel/power/process.c b/kernel/power/process.c
69147index 19db29f..33b52b6 100644
69148--- a/kernel/power/process.c
69149+++ b/kernel/power/process.c
69150@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69151 u64 elapsed_csecs64;
69152 unsigned int elapsed_csecs;
69153 bool wakeup = false;
69154+ bool timedout = false;
69155
69156 do_gettimeofday(&start);
69157
69158@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69159
69160 while (true) {
69161 todo = 0;
69162+ if (time_after(jiffies, end_time))
69163+ timedout = true;
69164 read_lock(&tasklist_lock);
69165 do_each_thread(g, p) {
69166 if (p == current || !freeze_task(p))
69167@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69168 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69169 * transition can't race with task state testing here.
69170 */
69171- if (!task_is_stopped_or_traced(p) &&
69172- !freezer_should_skip(p))
69173+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69174 todo++;
69175+ if (timedout) {
69176+ printk(KERN_ERR "Task refusing to freeze:\n");
69177+ sched_show_task(p);
69178+ }
69179+ }
69180 } while_each_thread(g, p);
69181 read_unlock(&tasklist_lock);
69182
69183@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69184 todo += wq_busy;
69185 }
69186
69187- if (!todo || time_after(jiffies, end_time))
69188+ if (!todo || timedout)
69189 break;
69190
69191 if (pm_wakeup_pending()) {
69192diff --git a/kernel/printk.c b/kernel/printk.c
69193index 146827f..a501fec 100644
69194--- a/kernel/printk.c
69195+++ b/kernel/printk.c
69196@@ -782,6 +782,11 @@ static int check_syslog_permissions(int type, bool from_file)
69197 if (from_file && type != SYSLOG_ACTION_OPEN)
69198 return 0;
69199
69200+#ifdef CONFIG_GRKERNSEC_DMESG
69201+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69202+ return -EPERM;
69203+#endif
69204+
69205 if (syslog_action_restricted(type)) {
69206 if (capable(CAP_SYSLOG))
69207 return 0;
69208diff --git a/kernel/profile.c b/kernel/profile.c
69209index 76b8e77..a2930e8 100644
69210--- a/kernel/profile.c
69211+++ b/kernel/profile.c
69212@@ -39,7 +39,7 @@ struct profile_hit {
69213 /* Oprofile timer tick hook */
69214 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69215
69216-static atomic_t *prof_buffer;
69217+static atomic_unchecked_t *prof_buffer;
69218 static unsigned long prof_len, prof_shift;
69219
69220 int prof_on __read_mostly;
69221@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69222 hits[i].pc = 0;
69223 continue;
69224 }
69225- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69226+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69227 hits[i].hits = hits[i].pc = 0;
69228 }
69229 }
69230@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69231 * Add the current hit(s) and flush the write-queue out
69232 * to the global buffer:
69233 */
69234- atomic_add(nr_hits, &prof_buffer[pc]);
69235+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69236 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69237- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69238+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69239 hits[i].pc = hits[i].hits = 0;
69240 }
69241 out:
69242@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69243 {
69244 unsigned long pc;
69245 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69246- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69247+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69248 }
69249 #endif /* !CONFIG_SMP */
69250
69251@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69252 return -EFAULT;
69253 buf++; p++; count--; read++;
69254 }
69255- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69256+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69257 if (copy_to_user(buf, (void *)pnt, count))
69258 return -EFAULT;
69259 read += count;
69260@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69261 }
69262 #endif
69263 profile_discard_flip_buffers();
69264- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69265+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69266 return count;
69267 }
69268
69269diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69270index a232bb5..2a65ef9 100644
69271--- a/kernel/ptrace.c
69272+++ b/kernel/ptrace.c
69273@@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69274
69275 if (seize)
69276 flags |= PT_SEIZED;
69277- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69278+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69279 flags |= PT_PTRACE_CAP;
69280 task->ptrace = flags;
69281
69282@@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69283 break;
69284 return -EIO;
69285 }
69286- if (copy_to_user(dst, buf, retval))
69287+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69288 return -EFAULT;
69289 copied += retval;
69290 src += retval;
69291@@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69292 bool seized = child->ptrace & PT_SEIZED;
69293 int ret = -EIO;
69294 siginfo_t siginfo, *si;
69295- void __user *datavp = (void __user *) data;
69296+ void __user *datavp = (__force void __user *) data;
69297 unsigned long __user *datalp = datavp;
69298 unsigned long flags;
69299
69300@@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69301 goto out;
69302 }
69303
69304+ if (gr_handle_ptrace(child, request)) {
69305+ ret = -EPERM;
69306+ goto out_put_task_struct;
69307+ }
69308+
69309 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69310 ret = ptrace_attach(child, request, addr, data);
69311 /*
69312 * Some architectures need to do book-keeping after
69313 * a ptrace attach.
69314 */
69315- if (!ret)
69316+ if (!ret) {
69317 arch_ptrace_attach(child);
69318+ gr_audit_ptrace(child);
69319+ }
69320 goto out_put_task_struct;
69321 }
69322
69323@@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69324 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69325 if (copied != sizeof(tmp))
69326 return -EIO;
69327- return put_user(tmp, (unsigned long __user *)data);
69328+ return put_user(tmp, (__force unsigned long __user *)data);
69329 }
69330
69331 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69332@@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69333 goto out;
69334 }
69335
69336+ if (gr_handle_ptrace(child, request)) {
69337+ ret = -EPERM;
69338+ goto out_put_task_struct;
69339+ }
69340+
69341 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69342 ret = ptrace_attach(child, request, addr, data);
69343 /*
69344 * Some architectures need to do book-keeping after
69345 * a ptrace attach.
69346 */
69347- if (!ret)
69348+ if (!ret) {
69349 arch_ptrace_attach(child);
69350+ gr_audit_ptrace(child);
69351+ }
69352 goto out_put_task_struct;
69353 }
69354
69355diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69356index 37a5444..eec170a 100644
69357--- a/kernel/rcutiny.c
69358+++ b/kernel/rcutiny.c
69359@@ -46,7 +46,7 @@
69360 struct rcu_ctrlblk;
69361 static void invoke_rcu_callbacks(void);
69362 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69363-static void rcu_process_callbacks(struct softirq_action *unused);
69364+static void rcu_process_callbacks(void);
69365 static void __call_rcu(struct rcu_head *head,
69366 void (*func)(struct rcu_head *rcu),
69367 struct rcu_ctrlblk *rcp);
69368@@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69369 rcu_is_callbacks_kthread()));
69370 }
69371
69372-static void rcu_process_callbacks(struct softirq_action *unused)
69373+static void rcu_process_callbacks(void)
69374 {
69375 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69376 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69377diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69378index fc31a2d..be2ec04 100644
69379--- a/kernel/rcutiny_plugin.h
69380+++ b/kernel/rcutiny_plugin.h
69381@@ -939,7 +939,7 @@ static int rcu_kthread(void *arg)
69382 have_rcu_kthread_work = morework;
69383 local_irq_restore(flags);
69384 if (work)
69385- rcu_process_callbacks(NULL);
69386+ rcu_process_callbacks();
69387 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69388 }
69389
69390diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69391index e66b34a..4b8b626 100644
69392--- a/kernel/rcutorture.c
69393+++ b/kernel/rcutorture.c
69394@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69395 { 0 };
69396 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69397 { 0 };
69398-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69399-static atomic_t n_rcu_torture_alloc;
69400-static atomic_t n_rcu_torture_alloc_fail;
69401-static atomic_t n_rcu_torture_free;
69402-static atomic_t n_rcu_torture_mberror;
69403-static atomic_t n_rcu_torture_error;
69404+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69405+static atomic_unchecked_t n_rcu_torture_alloc;
69406+static atomic_unchecked_t n_rcu_torture_alloc_fail;
69407+static atomic_unchecked_t n_rcu_torture_free;
69408+static atomic_unchecked_t n_rcu_torture_mberror;
69409+static atomic_unchecked_t n_rcu_torture_error;
69410 static long n_rcu_torture_barrier_error;
69411 static long n_rcu_torture_boost_ktrerror;
69412 static long n_rcu_torture_boost_rterror;
69413@@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69414
69415 spin_lock_bh(&rcu_torture_lock);
69416 if (list_empty(&rcu_torture_freelist)) {
69417- atomic_inc(&n_rcu_torture_alloc_fail);
69418+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69419 spin_unlock_bh(&rcu_torture_lock);
69420 return NULL;
69421 }
69422- atomic_inc(&n_rcu_torture_alloc);
69423+ atomic_inc_unchecked(&n_rcu_torture_alloc);
69424 p = rcu_torture_freelist.next;
69425 list_del_init(p);
69426 spin_unlock_bh(&rcu_torture_lock);
69427@@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69428 static void
69429 rcu_torture_free(struct rcu_torture *p)
69430 {
69431- atomic_inc(&n_rcu_torture_free);
69432+ atomic_inc_unchecked(&n_rcu_torture_free);
69433 spin_lock_bh(&rcu_torture_lock);
69434 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69435 spin_unlock_bh(&rcu_torture_lock);
69436@@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69437 i = rp->rtort_pipe_count;
69438 if (i > RCU_TORTURE_PIPE_LEN)
69439 i = RCU_TORTURE_PIPE_LEN;
69440- atomic_inc(&rcu_torture_wcount[i]);
69441+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69442 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69443 rp->rtort_mbtest = 0;
69444 rcu_torture_free(rp);
69445@@ -451,7 +451,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69446 i = rp->rtort_pipe_count;
69447 if (i > RCU_TORTURE_PIPE_LEN)
69448 i = RCU_TORTURE_PIPE_LEN;
69449- atomic_inc(&rcu_torture_wcount[i]);
69450+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69451 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69452 rp->rtort_mbtest = 0;
69453 list_del(&rp->rtort_free);
69454@@ -983,7 +983,7 @@ rcu_torture_writer(void *arg)
69455 i = old_rp->rtort_pipe_count;
69456 if (i > RCU_TORTURE_PIPE_LEN)
69457 i = RCU_TORTURE_PIPE_LEN;
69458- atomic_inc(&rcu_torture_wcount[i]);
69459+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69460 old_rp->rtort_pipe_count++;
69461 cur_ops->deferred_free(old_rp);
69462 }
69463@@ -1064,7 +1064,7 @@ static void rcu_torture_timer(unsigned long unused)
69464 }
69465 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69466 if (p->rtort_mbtest == 0)
69467- atomic_inc(&n_rcu_torture_mberror);
69468+ atomic_inc_unchecked(&n_rcu_torture_mberror);
69469 spin_lock(&rand_lock);
69470 cur_ops->read_delay(&rand);
69471 n_rcu_torture_timers++;
69472@@ -1128,7 +1128,7 @@ rcu_torture_reader(void *arg)
69473 }
69474 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69475 if (p->rtort_mbtest == 0)
69476- atomic_inc(&n_rcu_torture_mberror);
69477+ atomic_inc_unchecked(&n_rcu_torture_mberror);
69478 cur_ops->read_delay(&rand);
69479 preempt_disable();
69480 pipe_count = p->rtort_pipe_count;
69481@@ -1191,10 +1191,10 @@ rcu_torture_printk(char *page)
69482 rcu_torture_current,
69483 rcu_torture_current_version,
69484 list_empty(&rcu_torture_freelist),
69485- atomic_read(&n_rcu_torture_alloc),
69486- atomic_read(&n_rcu_torture_alloc_fail),
69487- atomic_read(&n_rcu_torture_free),
69488- atomic_read(&n_rcu_torture_mberror),
69489+ atomic_read_unchecked(&n_rcu_torture_alloc),
69490+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69491+ atomic_read_unchecked(&n_rcu_torture_free),
69492+ atomic_read_unchecked(&n_rcu_torture_mberror),
69493 n_rcu_torture_boost_ktrerror,
69494 n_rcu_torture_boost_rterror,
69495 n_rcu_torture_boost_failure,
69496@@ -1208,14 +1208,14 @@ rcu_torture_printk(char *page)
69497 n_barrier_attempts,
69498 n_rcu_torture_barrier_error);
69499 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69500- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69501+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69502 n_rcu_torture_barrier_error != 0 ||
69503 n_rcu_torture_boost_ktrerror != 0 ||
69504 n_rcu_torture_boost_rterror != 0 ||
69505 n_rcu_torture_boost_failure != 0 ||
69506 i > 1) {
69507 cnt += sprintf(&page[cnt], "!!! ");
69508- atomic_inc(&n_rcu_torture_error);
69509+ atomic_inc_unchecked(&n_rcu_torture_error);
69510 WARN_ON_ONCE(1);
69511 }
69512 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69513@@ -1229,7 +1229,7 @@ rcu_torture_printk(char *page)
69514 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69515 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69516 cnt += sprintf(&page[cnt], " %d",
69517- atomic_read(&rcu_torture_wcount[i]));
69518+ atomic_read_unchecked(&rcu_torture_wcount[i]));
69519 }
69520 cnt += sprintf(&page[cnt], "\n");
69521 if (cur_ops->stats)
69522@@ -1888,7 +1888,7 @@ rcu_torture_cleanup(void)
69523
69524 if (cur_ops->cleanup)
69525 cur_ops->cleanup();
69526- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69527+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69528 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69529 else if (n_online_successes != n_online_attempts ||
69530 n_offline_successes != n_offline_attempts)
69531@@ -1958,18 +1958,18 @@ rcu_torture_init(void)
69532
69533 rcu_torture_current = NULL;
69534 rcu_torture_current_version = 0;
69535- atomic_set(&n_rcu_torture_alloc, 0);
69536- atomic_set(&n_rcu_torture_alloc_fail, 0);
69537- atomic_set(&n_rcu_torture_free, 0);
69538- atomic_set(&n_rcu_torture_mberror, 0);
69539- atomic_set(&n_rcu_torture_error, 0);
69540+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69541+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69542+ atomic_set_unchecked(&n_rcu_torture_free, 0);
69543+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69544+ atomic_set_unchecked(&n_rcu_torture_error, 0);
69545 n_rcu_torture_barrier_error = 0;
69546 n_rcu_torture_boost_ktrerror = 0;
69547 n_rcu_torture_boost_rterror = 0;
69548 n_rcu_torture_boost_failure = 0;
69549 n_rcu_torture_boosts = 0;
69550 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69551- atomic_set(&rcu_torture_wcount[i], 0);
69552+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69553 for_each_possible_cpu(cpu) {
69554 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69555 per_cpu(rcu_torture_count, cpu)[i] = 0;
69556diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69557index 4b97bba..b92c9d2 100644
69558--- a/kernel/rcutree.c
69559+++ b/kernel/rcutree.c
69560@@ -366,9 +366,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69561 rcu_prepare_for_idle(smp_processor_id());
69562 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69563 smp_mb__before_atomic_inc(); /* See above. */
69564- atomic_inc(&rdtp->dynticks);
69565+ atomic_inc_unchecked(&rdtp->dynticks);
69566 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69567- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69568+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69569
69570 /*
69571 * The idle task is not permitted to enter the idle loop while
69572@@ -457,10 +457,10 @@ void rcu_irq_exit(void)
69573 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69574 {
69575 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69576- atomic_inc(&rdtp->dynticks);
69577+ atomic_inc_unchecked(&rdtp->dynticks);
69578 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69579 smp_mb__after_atomic_inc(); /* See above. */
69580- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69581+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69582 rcu_cleanup_after_idle(smp_processor_id());
69583 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69584 if (!is_idle_task(current)) {
69585@@ -554,14 +554,14 @@ void rcu_nmi_enter(void)
69586 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69587
69588 if (rdtp->dynticks_nmi_nesting == 0 &&
69589- (atomic_read(&rdtp->dynticks) & 0x1))
69590+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69591 return;
69592 rdtp->dynticks_nmi_nesting++;
69593 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69594- atomic_inc(&rdtp->dynticks);
69595+ atomic_inc_unchecked(&rdtp->dynticks);
69596 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69597 smp_mb__after_atomic_inc(); /* See above. */
69598- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69599+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69600 }
69601
69602 /**
69603@@ -580,9 +580,9 @@ void rcu_nmi_exit(void)
69604 return;
69605 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69606 smp_mb__before_atomic_inc(); /* See above. */
69607- atomic_inc(&rdtp->dynticks);
69608+ atomic_inc_unchecked(&rdtp->dynticks);
69609 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69610- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69611+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69612 }
69613
69614 #ifdef CONFIG_PROVE_RCU
69615@@ -598,7 +598,7 @@ int rcu_is_cpu_idle(void)
69616 int ret;
69617
69618 preempt_disable();
69619- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69620+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69621 preempt_enable();
69622 return ret;
69623 }
69624@@ -668,7 +668,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69625 */
69626 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69627 {
69628- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69629+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69630 return (rdp->dynticks_snap & 0x1) == 0;
69631 }
69632
69633@@ -683,7 +683,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69634 unsigned int curr;
69635 unsigned int snap;
69636
69637- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69638+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69639 snap = (unsigned int)rdp->dynticks_snap;
69640
69641 /*
69642@@ -713,10 +713,10 @@ static int jiffies_till_stall_check(void)
69643 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69644 */
69645 if (till_stall_check < 3) {
69646- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69647+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69648 till_stall_check = 3;
69649 } else if (till_stall_check > 300) {
69650- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69651+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69652 till_stall_check = 300;
69653 }
69654 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69655@@ -1824,7 +1824,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
69656 /*
69657 * Do RCU core processing for the current CPU.
69658 */
69659-static void rcu_process_callbacks(struct softirq_action *unused)
69660+static void rcu_process_callbacks(void)
69661 {
69662 trace_rcu_utilization("Start RCU core");
69663 __rcu_process_callbacks(&rcu_sched_state,
69664@@ -2042,8 +2042,8 @@ void synchronize_rcu_bh(void)
69665 }
69666 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69667
69668-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69669-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69670+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69671+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69672
69673 static int synchronize_sched_expedited_cpu_stop(void *data)
69674 {
69675@@ -2104,7 +2104,7 @@ void synchronize_sched_expedited(void)
69676 int firstsnap, s, snap, trycount = 0;
69677
69678 /* Note that atomic_inc_return() implies full memory barrier. */
69679- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69680+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69681 get_online_cpus();
69682 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69683
69684@@ -2126,7 +2126,7 @@ void synchronize_sched_expedited(void)
69685 }
69686
69687 /* Check to see if someone else did our work for us. */
69688- s = atomic_read(&sync_sched_expedited_done);
69689+ s = atomic_read_unchecked(&sync_sched_expedited_done);
69690 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69691 smp_mb(); /* ensure test happens before caller kfree */
69692 return;
69693@@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69694 * grace period works for us.
69695 */
69696 get_online_cpus();
69697- snap = atomic_read(&sync_sched_expedited_started);
69698+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
69699 smp_mb(); /* ensure read is before try_stop_cpus(). */
69700 }
69701
69702@@ -2152,12 +2152,12 @@ void synchronize_sched_expedited(void)
69703 * than we did beat us to the punch.
69704 */
69705 do {
69706- s = atomic_read(&sync_sched_expedited_done);
69707+ s = atomic_read_unchecked(&sync_sched_expedited_done);
69708 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69709 smp_mb(); /* ensure test happens before caller kfree */
69710 break;
69711 }
69712- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69713+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69714
69715 put_online_cpus();
69716 }
69717@@ -2421,7 +2421,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69718 rdp->qlen = 0;
69719 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69720 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69721- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69722+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69723 rdp->cpu = cpu;
69724 rdp->rsp = rsp;
69725 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69726@@ -2449,8 +2449,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69727 rdp->n_force_qs_snap = rsp->n_force_qs;
69728 rdp->blimit = blimit;
69729 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69730- atomic_set(&rdp->dynticks->dynticks,
69731- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69732+ atomic_set_unchecked(&rdp->dynticks->dynticks,
69733+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69734 rcu_prepare_for_idle_init(cpu);
69735 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69736
69737diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69738index 19b61ac..5c60a94 100644
69739--- a/kernel/rcutree.h
69740+++ b/kernel/rcutree.h
69741@@ -83,7 +83,7 @@ struct rcu_dynticks {
69742 long long dynticks_nesting; /* Track irq/process nesting level. */
69743 /* Process level is worth LLONG_MAX/2. */
69744 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69745- atomic_t dynticks; /* Even value for idle, else odd. */
69746+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69747 #ifdef CONFIG_RCU_FAST_NO_HZ
69748 int dyntick_drain; /* Prepare-for-idle state variable. */
69749 unsigned long dyntick_holdoff;
69750diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69751index 3e48994..d94f03a 100644
69752--- a/kernel/rcutree_plugin.h
69753+++ b/kernel/rcutree_plugin.h
69754@@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
69755
69756 /* Clean up and exit. */
69757 smp_mb(); /* ensure expedited GP seen before counter increment. */
69758- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69759+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69760 unlock_mb_ret:
69761 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69762 mb_ret:
69763diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69764index d4bc16d..c234a5c 100644
69765--- a/kernel/rcutree_trace.c
69766+++ b/kernel/rcutree_trace.c
69767@@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69768 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69769 rdp->qs_pending);
69770 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69771- atomic_read(&rdp->dynticks->dynticks),
69772+ atomic_read_unchecked(&rdp->dynticks->dynticks),
69773 rdp->dynticks->dynticks_nesting,
69774 rdp->dynticks->dynticks_nmi_nesting,
69775 rdp->dynticks_fqs);
69776@@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69777 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69778 rdp->qs_pending);
69779 seq_printf(m, ",%d,%llx,%d,%lu",
69780- atomic_read(&rdp->dynticks->dynticks),
69781+ atomic_read_unchecked(&rdp->dynticks->dynticks),
69782 rdp->dynticks->dynticks_nesting,
69783 rdp->dynticks->dynticks_nmi_nesting,
69784 rdp->dynticks_fqs);
69785diff --git a/kernel/resource.c b/kernel/resource.c
69786index e1d2b8e..24820bb 100644
69787--- a/kernel/resource.c
69788+++ b/kernel/resource.c
69789@@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
69790
69791 static int __init ioresources_init(void)
69792 {
69793+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69794+#ifdef CONFIG_GRKERNSEC_PROC_USER
69795+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69796+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69797+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69798+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69799+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69800+#endif
69801+#else
69802 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69803 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69804+#endif
69805 return 0;
69806 }
69807 __initcall(ioresources_init);
69808diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69809index 98ec494..4241d6d 100644
69810--- a/kernel/rtmutex-tester.c
69811+++ b/kernel/rtmutex-tester.c
69812@@ -20,7 +20,7 @@
69813 #define MAX_RT_TEST_MUTEXES 8
69814
69815 static spinlock_t rttest_lock;
69816-static atomic_t rttest_event;
69817+static atomic_unchecked_t rttest_event;
69818
69819 struct test_thread_data {
69820 int opcode;
69821@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69822
69823 case RTTEST_LOCKCONT:
69824 td->mutexes[td->opdata] = 1;
69825- td->event = atomic_add_return(1, &rttest_event);
69826+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69827 return 0;
69828
69829 case RTTEST_RESET:
69830@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69831 return 0;
69832
69833 case RTTEST_RESETEVENT:
69834- atomic_set(&rttest_event, 0);
69835+ atomic_set_unchecked(&rttest_event, 0);
69836 return 0;
69837
69838 default:
69839@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69840 return ret;
69841
69842 td->mutexes[id] = 1;
69843- td->event = atomic_add_return(1, &rttest_event);
69844+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69845 rt_mutex_lock(&mutexes[id]);
69846- td->event = atomic_add_return(1, &rttest_event);
69847+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69848 td->mutexes[id] = 4;
69849 return 0;
69850
69851@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69852 return ret;
69853
69854 td->mutexes[id] = 1;
69855- td->event = atomic_add_return(1, &rttest_event);
69856+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69857 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69858- td->event = atomic_add_return(1, &rttest_event);
69859+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69860 td->mutexes[id] = ret ? 0 : 4;
69861 return ret ? -EINTR : 0;
69862
69863@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69864 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69865 return ret;
69866
69867- td->event = atomic_add_return(1, &rttest_event);
69868+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69869 rt_mutex_unlock(&mutexes[id]);
69870- td->event = atomic_add_return(1, &rttest_event);
69871+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69872 td->mutexes[id] = 0;
69873 return 0;
69874
69875@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69876 break;
69877
69878 td->mutexes[dat] = 2;
69879- td->event = atomic_add_return(1, &rttest_event);
69880+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69881 break;
69882
69883 default:
69884@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69885 return;
69886
69887 td->mutexes[dat] = 3;
69888- td->event = atomic_add_return(1, &rttest_event);
69889+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69890 break;
69891
69892 case RTTEST_LOCKNOWAIT:
69893@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69894 return;
69895
69896 td->mutexes[dat] = 1;
69897- td->event = atomic_add_return(1, &rttest_event);
69898+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69899 return;
69900
69901 default:
69902diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69903index 0984a21..939f183 100644
69904--- a/kernel/sched/auto_group.c
69905+++ b/kernel/sched/auto_group.c
69906@@ -11,7 +11,7 @@
69907
69908 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69909 static struct autogroup autogroup_default;
69910-static atomic_t autogroup_seq_nr;
69911+static atomic_unchecked_t autogroup_seq_nr;
69912
69913 void __init autogroup_init(struct task_struct *init_task)
69914 {
69915@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69916
69917 kref_init(&ag->kref);
69918 init_rwsem(&ag->lock);
69919- ag->id = atomic_inc_return(&autogroup_seq_nr);
69920+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69921 ag->tg = tg;
69922 #ifdef CONFIG_RT_GROUP_SCHED
69923 /*
69924diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69925index c04c9ff..98c54bf 100644
69926--- a/kernel/sched/core.c
69927+++ b/kernel/sched/core.c
69928@@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
69929 /* convert nice value [19,-20] to rlimit style value [1,40] */
69930 int nice_rlim = 20 - nice;
69931
69932+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69933+
69934 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69935 capable(CAP_SYS_NICE));
69936 }
69937@@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69938 if (nice > 19)
69939 nice = 19;
69940
69941- if (increment < 0 && !can_nice(current, nice))
69942+ if (increment < 0 && (!can_nice(current, nice) ||
69943+ gr_handle_chroot_nice()))
69944 return -EPERM;
69945
69946 retval = security_task_setnice(current, nice);
69947@@ -4290,6 +4293,7 @@ recheck:
69948 unsigned long rlim_rtprio =
69949 task_rlimit(p, RLIMIT_RTPRIO);
69950
69951+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69952 /* can't set/change the rt policy */
69953 if (policy != p->policy && !rlim_rtprio)
69954 return -EPERM;
69955diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69956index c099cc6..06aec4f 100644
69957--- a/kernel/sched/fair.c
69958+++ b/kernel/sched/fair.c
69959@@ -4846,7 +4846,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69960 * run_rebalance_domains is triggered when needed from the scheduler tick.
69961 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69962 */
69963-static void run_rebalance_domains(struct softirq_action *h)
69964+static void run_rebalance_domains(void)
69965 {
69966 int this_cpu = smp_processor_id();
69967 struct rq *this_rq = cpu_rq(this_cpu);
69968diff --git a/kernel/signal.c b/kernel/signal.c
69969index 6771027..763e51e 100644
69970--- a/kernel/signal.c
69971+++ b/kernel/signal.c
69972@@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69973
69974 int print_fatal_signals __read_mostly;
69975
69976-static void __user *sig_handler(struct task_struct *t, int sig)
69977+static __sighandler_t sig_handler(struct task_struct *t, int sig)
69978 {
69979 return t->sighand->action[sig - 1].sa.sa_handler;
69980 }
69981
69982-static int sig_handler_ignored(void __user *handler, int sig)
69983+static int sig_handler_ignored(__sighandler_t handler, int sig)
69984 {
69985 /* Is it explicitly or implicitly ignored? */
69986 return handler == SIG_IGN ||
69987@@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69988
69989 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69990 {
69991- void __user *handler;
69992+ __sighandler_t handler;
69993
69994 handler = sig_handler(t, sig);
69995
69996@@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69997 atomic_inc(&user->sigpending);
69998 rcu_read_unlock();
69999
70000+ if (!override_rlimit)
70001+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70002+
70003 if (override_rlimit ||
70004 atomic_read(&user->sigpending) <=
70005 task_rlimit(t, RLIMIT_SIGPENDING)) {
70006@@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70007
70008 int unhandled_signal(struct task_struct *tsk, int sig)
70009 {
70010- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70011+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70012 if (is_global_init(tsk))
70013 return 1;
70014 if (handler != SIG_IGN && handler != SIG_DFL)
70015@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70016 }
70017 }
70018
70019+ /* allow glibc communication via tgkill to other threads in our
70020+ thread group */
70021+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70022+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70023+ && gr_handle_signal(t, sig))
70024+ return -EPERM;
70025+
70026 return security_task_kill(t, info, sig, 0);
70027 }
70028
70029@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70030 return send_signal(sig, info, p, 1);
70031 }
70032
70033-static int
70034+int
70035 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70036 {
70037 return send_signal(sig, info, t, 0);
70038@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70039 unsigned long int flags;
70040 int ret, blocked, ignored;
70041 struct k_sigaction *action;
70042+ int is_unhandled = 0;
70043
70044 spin_lock_irqsave(&t->sighand->siglock, flags);
70045 action = &t->sighand->action[sig-1];
70046@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70047 }
70048 if (action->sa.sa_handler == SIG_DFL)
70049 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70050+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70051+ is_unhandled = 1;
70052 ret = specific_send_sig_info(sig, info, t);
70053 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70054
70055+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
70056+ normal operation */
70057+ if (is_unhandled) {
70058+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70059+ gr_handle_crash(t, sig);
70060+ }
70061+
70062 return ret;
70063 }
70064
70065@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70066 ret = check_kill_permission(sig, info, p);
70067 rcu_read_unlock();
70068
70069- if (!ret && sig)
70070+ if (!ret && sig) {
70071 ret = do_send_sig_info(sig, info, p, true);
70072+ if (!ret)
70073+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70074+ }
70075
70076 return ret;
70077 }
70078@@ -2858,7 +2881,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70079 int error = -ESRCH;
70080
70081 rcu_read_lock();
70082- p = find_task_by_vpid(pid);
70083+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70084+ /* allow glibc communication via tgkill to other threads in our
70085+ thread group */
70086+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70087+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
70088+ p = find_task_by_vpid_unrestricted(pid);
70089+ else
70090+#endif
70091+ p = find_task_by_vpid(pid);
70092 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70093 error = check_kill_permission(sig, info, p);
70094 /*
70095diff --git a/kernel/smp.c b/kernel/smp.c
70096index d0ae5b2..b87c5a8 100644
70097--- a/kernel/smp.c
70098+++ b/kernel/smp.c
70099@@ -582,22 +582,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
70100 }
70101 EXPORT_SYMBOL(smp_call_function);
70102
70103-void ipi_call_lock(void)
70104+void ipi_call_lock(void) __acquires(call_function.lock)
70105 {
70106 raw_spin_lock(&call_function.lock);
70107 }
70108
70109-void ipi_call_unlock(void)
70110+void ipi_call_unlock(void) __releases(call_function.lock)
70111 {
70112 raw_spin_unlock(&call_function.lock);
70113 }
70114
70115-void ipi_call_lock_irq(void)
70116+void ipi_call_lock_irq(void) __acquires(call_function.lock)
70117 {
70118 raw_spin_lock_irq(&call_function.lock);
70119 }
70120
70121-void ipi_call_unlock_irq(void)
70122+void ipi_call_unlock_irq(void) __releases(call_function.lock)
70123 {
70124 raw_spin_unlock_irq(&call_function.lock);
70125 }
70126diff --git a/kernel/softirq.c b/kernel/softirq.c
70127index 671f959..91c51cb 100644
70128--- a/kernel/softirq.c
70129+++ b/kernel/softirq.c
70130@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70131
70132 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70133
70134-char *softirq_to_name[NR_SOFTIRQS] = {
70135+const char * const softirq_to_name[NR_SOFTIRQS] = {
70136 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70137 "TASKLET", "SCHED", "HRTIMER", "RCU"
70138 };
70139@@ -235,7 +235,7 @@ restart:
70140 kstat_incr_softirqs_this_cpu(vec_nr);
70141
70142 trace_softirq_entry(vec_nr);
70143- h->action(h);
70144+ h->action();
70145 trace_softirq_exit(vec_nr);
70146 if (unlikely(prev_count != preempt_count())) {
70147 printk(KERN_ERR "huh, entered softirq %u %s %p"
70148@@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70149 or_softirq_pending(1UL << nr);
70150 }
70151
70152-void open_softirq(int nr, void (*action)(struct softirq_action *))
70153+void open_softirq(int nr, void (*action)(void))
70154 {
70155- softirq_vec[nr].action = action;
70156+ pax_open_kernel();
70157+ *(void **)&softirq_vec[nr].action = action;
70158+ pax_close_kernel();
70159 }
70160
70161 /*
70162@@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70163
70164 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70165
70166-static void tasklet_action(struct softirq_action *a)
70167+static void tasklet_action(void)
70168 {
70169 struct tasklet_struct *list;
70170
70171@@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
70172 }
70173 }
70174
70175-static void tasklet_hi_action(struct softirq_action *a)
70176+static void tasklet_hi_action(void)
70177 {
70178 struct tasklet_struct *list;
70179
70180diff --git a/kernel/srcu.c b/kernel/srcu.c
70181index 2095be3..9a5b89d 100644
70182--- a/kernel/srcu.c
70183+++ b/kernel/srcu.c
70184@@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70185 preempt_disable();
70186 idx = rcu_dereference_index_check(sp->completed,
70187 rcu_read_lock_sched_held()) & 0x1;
70188- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70189+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70190 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70191- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70192+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70193 preempt_enable();
70194 return idx;
70195 }
70196@@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70197 {
70198 preempt_disable();
70199 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70200- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70201+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70202 preempt_enable();
70203 }
70204 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70205diff --git a/kernel/sys.c b/kernel/sys.c
70206index 2d39a84..1c3abe4 100644
70207--- a/kernel/sys.c
70208+++ b/kernel/sys.c
70209@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70210 error = -EACCES;
70211 goto out;
70212 }
70213+
70214+ if (gr_handle_chroot_setpriority(p, niceval)) {
70215+ error = -EACCES;
70216+ goto out;
70217+ }
70218+
70219 no_nice = security_task_setnice(p, niceval);
70220 if (no_nice) {
70221 error = no_nice;
70222@@ -594,6 +600,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70223 goto error;
70224 }
70225
70226+ if (gr_check_group_change(new->gid, new->egid, -1))
70227+ goto error;
70228+
70229 if (rgid != (gid_t) -1 ||
70230 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70231 new->sgid = new->egid;
70232@@ -629,6 +638,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70233 old = current_cred();
70234
70235 retval = -EPERM;
70236+
70237+ if (gr_check_group_change(kgid, kgid, kgid))
70238+ goto error;
70239+
70240 if (nsown_capable(CAP_SETGID))
70241 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70242 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70243@@ -646,7 +659,7 @@ error:
70244 /*
70245 * change the user struct in a credentials set to match the new UID
70246 */
70247-static int set_user(struct cred *new)
70248+int set_user(struct cred *new)
70249 {
70250 struct user_struct *new_user;
70251
70252@@ -726,6 +739,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70253 goto error;
70254 }
70255
70256+ if (gr_check_user_change(new->uid, new->euid, -1))
70257+ goto error;
70258+
70259 if (!uid_eq(new->uid, old->uid)) {
70260 retval = set_user(new);
70261 if (retval < 0)
70262@@ -776,6 +792,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70263 old = current_cred();
70264
70265 retval = -EPERM;
70266+
70267+ if (gr_check_crash_uid(kuid))
70268+ goto error;
70269+ if (gr_check_user_change(kuid, kuid, kuid))
70270+ goto error;
70271+
70272 if (nsown_capable(CAP_SETUID)) {
70273 new->suid = new->uid = kuid;
70274 if (!uid_eq(kuid, old->uid)) {
70275@@ -845,6 +867,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70276 goto error;
70277 }
70278
70279+ if (gr_check_user_change(kruid, keuid, -1))
70280+ goto error;
70281+
70282 if (ruid != (uid_t) -1) {
70283 new->uid = kruid;
70284 if (!uid_eq(kruid, old->uid)) {
70285@@ -927,6 +952,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70286 goto error;
70287 }
70288
70289+ if (gr_check_group_change(krgid, kegid, -1))
70290+ goto error;
70291+
70292 if (rgid != (gid_t) -1)
70293 new->gid = krgid;
70294 if (egid != (gid_t) -1)
70295@@ -980,6 +1008,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70296 if (!uid_valid(kuid))
70297 return old_fsuid;
70298
70299+ if (gr_check_user_change(-1, -1, kuid))
70300+ goto error;
70301+
70302 new = prepare_creds();
70303 if (!new)
70304 return old_fsuid;
70305@@ -994,6 +1025,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70306 }
70307 }
70308
70309+error:
70310 abort_creds(new);
70311 return old_fsuid;
70312
70313@@ -1026,12 +1058,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70314 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70315 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70316 nsown_capable(CAP_SETGID)) {
70317+ if (gr_check_group_change(-1, -1, kgid))
70318+ goto error;
70319+
70320 if (!gid_eq(kgid, old->fsgid)) {
70321 new->fsgid = kgid;
70322 goto change_okay;
70323 }
70324 }
70325
70326+error:
70327 abort_creds(new);
70328 return old_fsgid;
70329
70330@@ -1264,13 +1300,13 @@ DECLARE_RWSEM(uts_sem);
70331 * Work around broken programs that cannot handle "Linux 3.0".
70332 * Instead we map 3.x to 2.6.40+x, so e.g. 3.0 would be 2.6.40
70333 */
70334-static int override_release(char __user *release, int len)
70335+static int override_release(char __user *release, size_t len)
70336 {
70337 int ret = 0;
70338- char buf[65];
70339
70340 if (current->personality & UNAME26) {
70341- char *rest = UTS_RELEASE;
70342+ char buf[65] = { 0 };
70343+ const char *rest = UTS_RELEASE;
70344 int ndots = 0;
70345 unsigned v;
70346
70347@@ -1282,7 +1318,10 @@ static int override_release(char __user *release, int len)
70348 rest++;
70349 }
70350 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
70351+ if (sizeof buf < len)
70352+ len = sizeof buf;
70353 snprintf(buf, len, "2.6.%u%s", v, rest);
70354+ buf[len - 1] = 0;
70355 ret = copy_to_user(release, buf, len);
70356 }
70357 return ret;
70358@@ -1337,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70359 return -EFAULT;
70360
70361 down_read(&uts_sem);
70362- error = __copy_to_user(&name->sysname, &utsname()->sysname,
70363+ error = __copy_to_user(name->sysname, &utsname()->sysname,
70364 __OLD_UTS_LEN);
70365 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70366- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70367+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
70368 __OLD_UTS_LEN);
70369 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70370- error |= __copy_to_user(&name->release, &utsname()->release,
70371+ error |= __copy_to_user(name->release, &utsname()->release,
70372 __OLD_UTS_LEN);
70373 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70374- error |= __copy_to_user(&name->version, &utsname()->version,
70375+ error |= __copy_to_user(name->version, &utsname()->version,
70376 __OLD_UTS_LEN);
70377 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70378- error |= __copy_to_user(&name->machine, &utsname()->machine,
70379+ error |= __copy_to_user(name->machine, &utsname()->machine,
70380 __OLD_UTS_LEN);
70381 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70382 up_read(&uts_sem);
70383@@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70384 error = get_dumpable(me->mm);
70385 break;
70386 case PR_SET_DUMPABLE:
70387- if (arg2 < 0 || arg2 > 1) {
70388+ if (arg2 > 1) {
70389 error = -EINVAL;
70390 break;
70391 }
70392diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70393index 4ab1187..33f4f2b 100644
70394--- a/kernel/sysctl.c
70395+++ b/kernel/sysctl.c
70396@@ -91,7 +91,6 @@
70397
70398
70399 #if defined(CONFIG_SYSCTL)
70400-
70401 /* External variables not in a header file. */
70402 extern int sysctl_overcommit_memory;
70403 extern int sysctl_overcommit_ratio;
70404@@ -169,10 +168,13 @@ static int proc_taint(struct ctl_table *table, int write,
70405 void __user *buffer, size_t *lenp, loff_t *ppos);
70406 #endif
70407
70408-#ifdef CONFIG_PRINTK
70409 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70410 void __user *buffer, size_t *lenp, loff_t *ppos);
70411-#endif
70412+
70413+static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70414+ void __user *buffer, size_t *lenp, loff_t *ppos);
70415+static int proc_dostring_coredump(struct ctl_table *table, int write,
70416+ void __user *buffer, size_t *lenp, loff_t *ppos);
70417
70418 #ifdef CONFIG_MAGIC_SYSRQ
70419 /* Note: sysrq code uses it's own private copy */
70420@@ -196,6 +198,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70421
70422 #endif
70423
70424+extern struct ctl_table grsecurity_table[];
70425+
70426 static struct ctl_table kern_table[];
70427 static struct ctl_table vm_table[];
70428 static struct ctl_table fs_table[];
70429@@ -210,6 +214,20 @@ extern struct ctl_table epoll_table[];
70430 int sysctl_legacy_va_layout;
70431 #endif
70432
70433+#ifdef CONFIG_PAX_SOFTMODE
70434+static ctl_table pax_table[] = {
70435+ {
70436+ .procname = "softmode",
70437+ .data = &pax_softmode,
70438+ .maxlen = sizeof(unsigned int),
70439+ .mode = 0600,
70440+ .proc_handler = &proc_dointvec,
70441+ },
70442+
70443+ { }
70444+};
70445+#endif
70446+
70447 /* The default sysctl tables: */
70448
70449 static struct ctl_table sysctl_base_table[] = {
70450@@ -256,6 +274,22 @@ static int max_extfrag_threshold = 1000;
70451 #endif
70452
70453 static struct ctl_table kern_table[] = {
70454+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70455+ {
70456+ .procname = "grsecurity",
70457+ .mode = 0500,
70458+ .child = grsecurity_table,
70459+ },
70460+#endif
70461+
70462+#ifdef CONFIG_PAX_SOFTMODE
70463+ {
70464+ .procname = "pax",
70465+ .mode = 0500,
70466+ .child = pax_table,
70467+ },
70468+#endif
70469+
70470 {
70471 .procname = "sched_child_runs_first",
70472 .data = &sysctl_sched_child_runs_first,
70473@@ -410,7 +444,7 @@ static struct ctl_table kern_table[] = {
70474 .data = core_pattern,
70475 .maxlen = CORENAME_MAX_SIZE,
70476 .mode = 0644,
70477- .proc_handler = proc_dostring,
70478+ .proc_handler = proc_dostring_coredump,
70479 },
70480 {
70481 .procname = "core_pipe_limit",
70482@@ -540,7 +574,7 @@ static struct ctl_table kern_table[] = {
70483 .data = &modprobe_path,
70484 .maxlen = KMOD_PATH_LEN,
70485 .mode = 0644,
70486- .proc_handler = proc_dostring,
70487+ .proc_handler = proc_dostring_modpriv,
70488 },
70489 {
70490 .procname = "modules_disabled",
70491@@ -707,16 +741,20 @@ static struct ctl_table kern_table[] = {
70492 .extra1 = &zero,
70493 .extra2 = &one,
70494 },
70495+#endif
70496 {
70497 .procname = "kptr_restrict",
70498 .data = &kptr_restrict,
70499 .maxlen = sizeof(int),
70500 .mode = 0644,
70501 .proc_handler = proc_dointvec_minmax_sysadmin,
70502+#ifdef CONFIG_GRKERNSEC_HIDESYM
70503+ .extra1 = &two,
70504+#else
70505 .extra1 = &zero,
70506+#endif
70507 .extra2 = &two,
70508 },
70509-#endif
70510 {
70511 .procname = "ngroups_max",
70512 .data = &ngroups_max,
70513@@ -1215,6 +1253,13 @@ static struct ctl_table vm_table[] = {
70514 .proc_handler = proc_dointvec_minmax,
70515 .extra1 = &zero,
70516 },
70517+ {
70518+ .procname = "heap_stack_gap",
70519+ .data = &sysctl_heap_stack_gap,
70520+ .maxlen = sizeof(sysctl_heap_stack_gap),
70521+ .mode = 0644,
70522+ .proc_handler = proc_doulongvec_minmax,
70523+ },
70524 #else
70525 {
70526 .procname = "nr_trim_pages",
70527@@ -1498,7 +1543,7 @@ static struct ctl_table fs_table[] = {
70528 .data = &suid_dumpable,
70529 .maxlen = sizeof(int),
70530 .mode = 0644,
70531- .proc_handler = proc_dointvec_minmax,
70532+ .proc_handler = proc_dointvec_minmax_coredump,
70533 .extra1 = &zero,
70534 .extra2 = &two,
70535 },
70536@@ -1645,6 +1690,16 @@ int proc_dostring(struct ctl_table *table, int write,
70537 buffer, lenp, ppos);
70538 }
70539
70540+int proc_dostring_modpriv(struct ctl_table *table, int write,
70541+ void __user *buffer, size_t *lenp, loff_t *ppos)
70542+{
70543+ if (write && !capable(CAP_SYS_MODULE))
70544+ return -EPERM;
70545+
70546+ return _proc_do_string(table->data, table->maxlen, write,
70547+ buffer, lenp, ppos);
70548+}
70549+
70550 static size_t proc_skip_spaces(char **buf)
70551 {
70552 size_t ret;
70553@@ -1750,6 +1805,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70554 len = strlen(tmp);
70555 if (len > *size)
70556 len = *size;
70557+ if (len > sizeof(tmp))
70558+ len = sizeof(tmp);
70559 if (copy_to_user(*buf, tmp, len))
70560 return -EFAULT;
70561 *size -= len;
70562@@ -1942,7 +1999,6 @@ static int proc_taint(struct ctl_table *table, int write,
70563 return err;
70564 }
70565
70566-#ifdef CONFIG_PRINTK
70567 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70568 void __user *buffer, size_t *lenp, loff_t *ppos)
70569 {
70570@@ -1951,7 +2007,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70571
70572 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70573 }
70574-#endif
70575
70576 struct do_proc_dointvec_minmax_conv_param {
70577 int *min;
70578@@ -2009,6 +2064,34 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
70579 do_proc_dointvec_minmax_conv, &param);
70580 }
70581
70582+static void validate_coredump_safety(void)
70583+{
70584+ if (suid_dumpable == SUID_DUMPABLE_SAFE &&
70585+ core_pattern[0] != '/' && core_pattern[0] != '|') {
70586+ printk(KERN_WARNING "Unsafe core_pattern used with "\
70587+ "suid_dumpable=2. Pipe handler or fully qualified "\
70588+ "core dump path required.\n");
70589+ }
70590+}
70591+
70592+static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70593+ void __user *buffer, size_t *lenp, loff_t *ppos)
70594+{
70595+ int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70596+ if (!error)
70597+ validate_coredump_safety();
70598+ return error;
70599+}
70600+
70601+static int proc_dostring_coredump(struct ctl_table *table, int write,
70602+ void __user *buffer, size_t *lenp, loff_t *ppos)
70603+{
70604+ int error = proc_dostring(table, write, buffer, lenp, ppos);
70605+ if (!error)
70606+ validate_coredump_safety();
70607+ return error;
70608+}
70609+
70610 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
70611 void __user *buffer,
70612 size_t *lenp, loff_t *ppos,
70613@@ -2066,8 +2149,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70614 *i = val;
70615 } else {
70616 val = convdiv * (*i) / convmul;
70617- if (!first)
70618+ if (!first) {
70619 err = proc_put_char(&buffer, &left, '\t');
70620+ if (err)
70621+ break;
70622+ }
70623 err = proc_put_long(&buffer, &left, val, false);
70624 if (err)
70625 break;
70626@@ -2459,6 +2545,12 @@ int proc_dostring(struct ctl_table *table, int write,
70627 return -ENOSYS;
70628 }
70629
70630+int proc_dostring_modpriv(struct ctl_table *table, int write,
70631+ void __user *buffer, size_t *lenp, loff_t *ppos)
70632+{
70633+ return -ENOSYS;
70634+}
70635+
70636 int proc_dointvec(struct ctl_table *table, int write,
70637 void __user *buffer, size_t *lenp, loff_t *ppos)
70638 {
70639@@ -2515,5 +2607,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70640 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70641 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70642 EXPORT_SYMBOL(proc_dostring);
70643+EXPORT_SYMBOL(proc_dostring_modpriv);
70644 EXPORT_SYMBOL(proc_doulongvec_minmax);
70645 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70646diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70647index a650694..aaeeb20 100644
70648--- a/kernel/sysctl_binary.c
70649+++ b/kernel/sysctl_binary.c
70650@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70651 int i;
70652
70653 set_fs(KERNEL_DS);
70654- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70655+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70656 set_fs(old_fs);
70657 if (result < 0)
70658 goto out_kfree;
70659@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70660 }
70661
70662 set_fs(KERNEL_DS);
70663- result = vfs_write(file, buffer, str - buffer, &pos);
70664+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70665 set_fs(old_fs);
70666 if (result < 0)
70667 goto out_kfree;
70668@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70669 int i;
70670
70671 set_fs(KERNEL_DS);
70672- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70673+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70674 set_fs(old_fs);
70675 if (result < 0)
70676 goto out_kfree;
70677@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70678 }
70679
70680 set_fs(KERNEL_DS);
70681- result = vfs_write(file, buffer, str - buffer, &pos);
70682+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70683 set_fs(old_fs);
70684 if (result < 0)
70685 goto out_kfree;
70686@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70687 int i;
70688
70689 set_fs(KERNEL_DS);
70690- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70691+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70692 set_fs(old_fs);
70693 if (result < 0)
70694 goto out;
70695@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70696 __le16 dnaddr;
70697
70698 set_fs(KERNEL_DS);
70699- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70700+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70701 set_fs(old_fs);
70702 if (result < 0)
70703 goto out;
70704@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70705 le16_to_cpu(dnaddr) & 0x3ff);
70706
70707 set_fs(KERNEL_DS);
70708- result = vfs_write(file, buf, len, &pos);
70709+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70710 set_fs(old_fs);
70711 if (result < 0)
70712 goto out;
70713diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70714index e660464..c8b9e67 100644
70715--- a/kernel/taskstats.c
70716+++ b/kernel/taskstats.c
70717@@ -27,9 +27,12 @@
70718 #include <linux/cgroup.h>
70719 #include <linux/fs.h>
70720 #include <linux/file.h>
70721+#include <linux/grsecurity.h>
70722 #include <net/genetlink.h>
70723 #include <linux/atomic.h>
70724
70725+extern int gr_is_taskstats_denied(int pid);
70726+
70727 /*
70728 * Maximum length of a cpumask that can be specified in
70729 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70730@@ -556,6 +559,9 @@ err:
70731
70732 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70733 {
70734+ if (gr_is_taskstats_denied(current->pid))
70735+ return -EACCES;
70736+
70737 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70738 return cmd_attr_register_cpumask(info);
70739 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70740diff --git a/kernel/time.c b/kernel/time.c
70741index ba744cf..267b7c5 100644
70742--- a/kernel/time.c
70743+++ b/kernel/time.c
70744@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70745 return error;
70746
70747 if (tz) {
70748+ /* we log in do_settimeofday called below, so don't log twice
70749+ */
70750+ if (!tv)
70751+ gr_log_timechange();
70752+
70753 sys_tz = *tz;
70754 update_vsyscall_tz();
70755 if (firsttime) {
70756diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70757index aa27d39..34d221c 100644
70758--- a/kernel/time/alarmtimer.c
70759+++ b/kernel/time/alarmtimer.c
70760@@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70761 struct platform_device *pdev;
70762 int error = 0;
70763 int i;
70764- struct k_clock alarm_clock = {
70765+ static struct k_clock alarm_clock = {
70766 .clock_getres = alarm_clock_getres,
70767 .clock_get = alarm_clock_get,
70768 .timer_create = alarm_timer_create,
70769diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70770index f113755..ec24223 100644
70771--- a/kernel/time/tick-broadcast.c
70772+++ b/kernel/time/tick-broadcast.c
70773@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70774 * then clear the broadcast bit.
70775 */
70776 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70777- int cpu = smp_processor_id();
70778+ cpu = smp_processor_id();
70779
70780 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70781 tick_broadcast_clear_oneshot(cpu);
70782diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70783index 63c88c1..8fd3c2f 100644
70784--- a/kernel/time/timekeeping.c
70785+++ b/kernel/time/timekeeping.c
70786@@ -14,6 +14,7 @@
70787 #include <linux/init.h>
70788 #include <linux/mm.h>
70789 #include <linux/sched.h>
70790+#include <linux/grsecurity.h>
70791 #include <linux/syscore_ops.h>
70792 #include <linux/clocksource.h>
70793 #include <linux/jiffies.h>
70794@@ -387,6 +388,8 @@ int do_settimeofday(const struct timespec *tv)
70795 if (!timespec_valid_strict(tv))
70796 return -EINVAL;
70797
70798+ gr_log_timechange();
70799+
70800 write_seqlock_irqsave(&timekeeper.lock, flags);
70801
70802 timekeeping_forward_now();
70803diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70804index 3258455..f35227d 100644
70805--- a/kernel/time/timer_list.c
70806+++ b/kernel/time/timer_list.c
70807@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70808
70809 static void print_name_offset(struct seq_file *m, void *sym)
70810 {
70811+#ifdef CONFIG_GRKERNSEC_HIDESYM
70812+ SEQ_printf(m, "<%p>", NULL);
70813+#else
70814 char symname[KSYM_NAME_LEN];
70815
70816 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70817 SEQ_printf(m, "<%pK>", sym);
70818 else
70819 SEQ_printf(m, "%s", symname);
70820+#endif
70821 }
70822
70823 static void
70824@@ -112,7 +116,11 @@ next_one:
70825 static void
70826 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70827 {
70828+#ifdef CONFIG_GRKERNSEC_HIDESYM
70829+ SEQ_printf(m, " .base: %p\n", NULL);
70830+#else
70831 SEQ_printf(m, " .base: %pK\n", base);
70832+#endif
70833 SEQ_printf(m, " .index: %d\n",
70834 base->index);
70835 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70836@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70837 {
70838 struct proc_dir_entry *pe;
70839
70840+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70841+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70842+#else
70843 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70844+#endif
70845 if (!pe)
70846 return -ENOMEM;
70847 return 0;
70848diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70849index 0b537f2..9e71eca 100644
70850--- a/kernel/time/timer_stats.c
70851+++ b/kernel/time/timer_stats.c
70852@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70853 static unsigned long nr_entries;
70854 static struct entry entries[MAX_ENTRIES];
70855
70856-static atomic_t overflow_count;
70857+static atomic_unchecked_t overflow_count;
70858
70859 /*
70860 * The entries are in a hash-table, for fast lookup:
70861@@ -140,7 +140,7 @@ static void reset_entries(void)
70862 nr_entries = 0;
70863 memset(entries, 0, sizeof(entries));
70864 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70865- atomic_set(&overflow_count, 0);
70866+ atomic_set_unchecked(&overflow_count, 0);
70867 }
70868
70869 static struct entry *alloc_entry(void)
70870@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70871 if (likely(entry))
70872 entry->count++;
70873 else
70874- atomic_inc(&overflow_count);
70875+ atomic_inc_unchecked(&overflow_count);
70876
70877 out_unlock:
70878 raw_spin_unlock_irqrestore(lock, flags);
70879@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70880
70881 static void print_name_offset(struct seq_file *m, unsigned long addr)
70882 {
70883+#ifdef CONFIG_GRKERNSEC_HIDESYM
70884+ seq_printf(m, "<%p>", NULL);
70885+#else
70886 char symname[KSYM_NAME_LEN];
70887
70888 if (lookup_symbol_name(addr, symname) < 0)
70889 seq_printf(m, "<%p>", (void *)addr);
70890 else
70891 seq_printf(m, "%s", symname);
70892+#endif
70893 }
70894
70895 static int tstats_show(struct seq_file *m, void *v)
70896@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70897
70898 seq_puts(m, "Timer Stats Version: v0.2\n");
70899 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70900- if (atomic_read(&overflow_count))
70901+ if (atomic_read_unchecked(&overflow_count))
70902 seq_printf(m, "Overflow: %d entries\n",
70903- atomic_read(&overflow_count));
70904+ atomic_read_unchecked(&overflow_count));
70905
70906 for (i = 0; i < nr_entries; i++) {
70907 entry = entries + i;
70908@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70909 {
70910 struct proc_dir_entry *pe;
70911
70912+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70913+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70914+#else
70915 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70916+#endif
70917 if (!pe)
70918 return -ENOMEM;
70919 return 0;
70920diff --git a/kernel/timer.c b/kernel/timer.c
70921index 6ec7e7e..cbc448b 100644
70922--- a/kernel/timer.c
70923+++ b/kernel/timer.c
70924@@ -1362,7 +1362,7 @@ void update_process_times(int user_tick)
70925 /*
70926 * This function runs timers and the timer-tq in bottom half context.
70927 */
70928-static void run_timer_softirq(struct softirq_action *h)
70929+static void run_timer_softirq(void)
70930 {
70931 struct tvec_base *base = __this_cpu_read(tvec_bases);
70932
70933diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70934index c0bd030..62a1927 100644
70935--- a/kernel/trace/blktrace.c
70936+++ b/kernel/trace/blktrace.c
70937@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70938 struct blk_trace *bt = filp->private_data;
70939 char buf[16];
70940
70941- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70942+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70943
70944 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70945 }
70946@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70947 return 1;
70948
70949 bt = buf->chan->private_data;
70950- atomic_inc(&bt->dropped);
70951+ atomic_inc_unchecked(&bt->dropped);
70952 return 0;
70953 }
70954
70955@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70956
70957 bt->dir = dir;
70958 bt->dev = dev;
70959- atomic_set(&bt->dropped, 0);
70960+ atomic_set_unchecked(&bt->dropped, 0);
70961
70962 ret = -EIO;
70963 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70964diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70965index a008663..30d7429 100644
70966--- a/kernel/trace/ftrace.c
70967+++ b/kernel/trace/ftrace.c
70968@@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70969 if (unlikely(ftrace_disabled))
70970 return 0;
70971
70972+ ret = ftrace_arch_code_modify_prepare();
70973+ FTRACE_WARN_ON(ret);
70974+ if (ret)
70975+ return 0;
70976+
70977 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70978+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70979 if (ret) {
70980 ftrace_bug(ret, ip);
70981- return 0;
70982 }
70983- return 1;
70984+ return ret ? 0 : 1;
70985 }
70986
70987 /*
70988@@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70989
70990 int
70991 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70992- void *data)
70993+ void *data)
70994 {
70995 struct ftrace_func_probe *entry;
70996 struct ftrace_page *pg;
70997@@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70998 if (!count)
70999 return 0;
71000
71001+ pax_open_kernel();
71002 sort(start, count, sizeof(*start),
71003 ftrace_cmp_ips, ftrace_swap_ips);
71004+ pax_close_kernel();
71005
71006 start_pg = ftrace_allocate_pages(count);
71007 if (!start_pg)
71008diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71009index a7fa070..403bc8d 100644
71010--- a/kernel/trace/trace.c
71011+++ b/kernel/trace/trace.c
71012@@ -4421,10 +4421,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71013 };
71014 #endif
71015
71016-static struct dentry *d_tracer;
71017-
71018 struct dentry *tracing_init_dentry(void)
71019 {
71020+ static struct dentry *d_tracer;
71021 static int once;
71022
71023 if (d_tracer)
71024@@ -4444,10 +4443,9 @@ struct dentry *tracing_init_dentry(void)
71025 return d_tracer;
71026 }
71027
71028-static struct dentry *d_percpu;
71029-
71030 struct dentry *tracing_dentry_percpu(void)
71031 {
71032+ static struct dentry *d_percpu;
71033 static int once;
71034 struct dentry *d_tracer;
71035
71036diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71037index 29111da..d190fe2 100644
71038--- a/kernel/trace/trace_events.c
71039+++ b/kernel/trace/trace_events.c
71040@@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
71041 struct ftrace_module_file_ops {
71042 struct list_head list;
71043 struct module *mod;
71044- struct file_operations id;
71045- struct file_operations enable;
71046- struct file_operations format;
71047- struct file_operations filter;
71048 };
71049
71050 static struct ftrace_module_file_ops *
71051@@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
71052
71053 file_ops->mod = mod;
71054
71055- file_ops->id = ftrace_event_id_fops;
71056- file_ops->id.owner = mod;
71057-
71058- file_ops->enable = ftrace_enable_fops;
71059- file_ops->enable.owner = mod;
71060-
71061- file_ops->filter = ftrace_event_filter_fops;
71062- file_ops->filter.owner = mod;
71063-
71064- file_ops->format = ftrace_event_format_fops;
71065- file_ops->format.owner = mod;
71066+ pax_open_kernel();
71067+ *(void **)&mod->trace_id.owner = mod;
71068+ *(void **)&mod->trace_enable.owner = mod;
71069+ *(void **)&mod->trace_filter.owner = mod;
71070+ *(void **)&mod->trace_format.owner = mod;
71071+ pax_close_kernel();
71072
71073 list_add(&file_ops->list, &ftrace_module_file_list);
71074
71075@@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
71076
71077 for_each_event(call, start, end) {
71078 __trace_add_event_call(*call, mod,
71079- &file_ops->id, &file_ops->enable,
71080- &file_ops->filter, &file_ops->format);
71081+ &mod->trace_id, &mod->trace_enable,
71082+ &mod->trace_filter, &mod->trace_format);
71083 }
71084 }
71085
71086diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71087index fd3c8aa..5f324a6 100644
71088--- a/kernel/trace/trace_mmiotrace.c
71089+++ b/kernel/trace/trace_mmiotrace.c
71090@@ -24,7 +24,7 @@ struct header_iter {
71091 static struct trace_array *mmio_trace_array;
71092 static bool overrun_detected;
71093 static unsigned long prev_overruns;
71094-static atomic_t dropped_count;
71095+static atomic_unchecked_t dropped_count;
71096
71097 static void mmio_reset_data(struct trace_array *tr)
71098 {
71099@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71100
71101 static unsigned long count_overruns(struct trace_iterator *iter)
71102 {
71103- unsigned long cnt = atomic_xchg(&dropped_count, 0);
71104+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71105 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71106
71107 if (over > prev_overruns)
71108@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71109 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71110 sizeof(*entry), 0, pc);
71111 if (!event) {
71112- atomic_inc(&dropped_count);
71113+ atomic_inc_unchecked(&dropped_count);
71114 return;
71115 }
71116 entry = ring_buffer_event_data(event);
71117@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71118 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71119 sizeof(*entry), 0, pc);
71120 if (!event) {
71121- atomic_inc(&dropped_count);
71122+ atomic_inc_unchecked(&dropped_count);
71123 return;
71124 }
71125 entry = ring_buffer_event_data(event);
71126diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71127index df611a0..10d8b32 100644
71128--- a/kernel/trace/trace_output.c
71129+++ b/kernel/trace/trace_output.c
71130@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71131
71132 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71133 if (!IS_ERR(p)) {
71134- p = mangle_path(s->buffer + s->len, p, "\n");
71135+ p = mangle_path(s->buffer + s->len, p, "\n\\");
71136 if (p) {
71137 s->len = p - s->buffer;
71138 return 1;
71139diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71140index d4545f4..a9010a1 100644
71141--- a/kernel/trace/trace_stack.c
71142+++ b/kernel/trace/trace_stack.c
71143@@ -53,7 +53,7 @@ static inline void check_stack(void)
71144 return;
71145
71146 /* we do not handle interrupt stacks yet */
71147- if (!object_is_on_stack(&this_size))
71148+ if (!object_starts_on_stack(&this_size))
71149 return;
71150
71151 local_irq_save(flags);
71152diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71153index 2016347..070fbbe 100644
71154--- a/kernel/workqueue.c
71155+++ b/kernel/workqueue.c
71156@@ -3451,7 +3451,7 @@ static int __cpuinit trustee_thread(void *__gcwq)
71157 */
71158 worker_flags |= WORKER_REBIND;
71159 worker_flags &= ~WORKER_ROGUE;
71160- ACCESS_ONCE(worker->flags) = worker_flags;
71161+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
71162
71163 /* queue rebind_work, wq doesn't matter, use the default one */
71164 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71165diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71166index ff5bdee..e68c124 100644
71167--- a/lib/Kconfig.debug
71168+++ b/lib/Kconfig.debug
71169@@ -1165,6 +1165,7 @@ config LATENCYTOP
71170 depends on DEBUG_KERNEL
71171 depends on STACKTRACE_SUPPORT
71172 depends on PROC_FS
71173+ depends on !GRKERNSEC_HIDESYM
71174 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71175 select KALLSYMS
71176 select KALLSYMS_ALL
71177@@ -1180,7 +1181,7 @@ source kernel/trace/Kconfig
71178
71179 config PROVIDE_OHCI1394_DMA_INIT
71180 bool "Remote debugging over FireWire early on boot"
71181- depends on PCI && X86
71182+ depends on PCI && X86 && !GRKERNSEC
71183 help
71184 If you want to debug problems which hang or crash the kernel early
71185 on boot and the crashing machine has a FireWire port, you can use
71186@@ -1209,7 +1210,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71187
71188 config FIREWIRE_OHCI_REMOTE_DMA
71189 bool "Remote debugging over FireWire with firewire-ohci"
71190- depends on FIREWIRE_OHCI
71191+ depends on FIREWIRE_OHCI && !GRKERNSEC
71192 help
71193 This option lets you use the FireWire bus for remote debugging
71194 with help of the firewire-ohci driver. It enables unfiltered
71195diff --git a/lib/bitmap.c b/lib/bitmap.c
71196index 06fdfa1..97c5c7d 100644
71197--- a/lib/bitmap.c
71198+++ b/lib/bitmap.c
71199@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71200 {
71201 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71202 u32 chunk;
71203- const char __user __force *ubuf = (const char __user __force *)buf;
71204+ const char __user *ubuf = (const char __force_user *)buf;
71205
71206 bitmap_zero(maskp, nmaskbits);
71207
71208@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71209 {
71210 if (!access_ok(VERIFY_READ, ubuf, ulen))
71211 return -EFAULT;
71212- return __bitmap_parse((const char __force *)ubuf,
71213+ return __bitmap_parse((const char __force_kernel *)ubuf,
71214 ulen, 1, maskp, nmaskbits);
71215
71216 }
71217@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71218 {
71219 unsigned a, b;
71220 int c, old_c, totaldigits;
71221- const char __user __force *ubuf = (const char __user __force *)buf;
71222+ const char __user *ubuf = (const char __force_user *)buf;
71223 int exp_digit, in_range;
71224
71225 totaldigits = c = 0;
71226@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71227 {
71228 if (!access_ok(VERIFY_READ, ubuf, ulen))
71229 return -EFAULT;
71230- return __bitmap_parselist((const char __force *)ubuf,
71231+ return __bitmap_parselist((const char __force_kernel *)ubuf,
71232 ulen, 1, maskp, nmaskbits);
71233 }
71234 EXPORT_SYMBOL(bitmap_parselist_user);
71235diff --git a/lib/bug.c b/lib/bug.c
71236index a28c141..2bd3d95 100644
71237--- a/lib/bug.c
71238+++ b/lib/bug.c
71239@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71240 return BUG_TRAP_TYPE_NONE;
71241
71242 bug = find_bug(bugaddr);
71243+ if (!bug)
71244+ return BUG_TRAP_TYPE_NONE;
71245
71246 file = NULL;
71247 line = 0;
71248diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71249index d11808c..dc2d6f8 100644
71250--- a/lib/debugobjects.c
71251+++ b/lib/debugobjects.c
71252@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71253 if (limit > 4)
71254 return;
71255
71256- is_on_stack = object_is_on_stack(addr);
71257+ is_on_stack = object_starts_on_stack(addr);
71258 if (is_on_stack == onstack)
71259 return;
71260
71261diff --git a/lib/devres.c b/lib/devres.c
71262index 80b9c76..9e32279 100644
71263--- a/lib/devres.c
71264+++ b/lib/devres.c
71265@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71266 void devm_iounmap(struct device *dev, void __iomem *addr)
71267 {
71268 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71269- (void *)addr));
71270+ (void __force *)addr));
71271 iounmap(addr);
71272 }
71273 EXPORT_SYMBOL(devm_iounmap);
71274@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71275 {
71276 ioport_unmap(addr);
71277 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71278- devm_ioport_map_match, (void *)addr));
71279+ devm_ioport_map_match, (void __force *)addr));
71280 }
71281 EXPORT_SYMBOL(devm_ioport_unmap);
71282
71283diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71284index 66ce414..6f0a0dd 100644
71285--- a/lib/dma-debug.c
71286+++ b/lib/dma-debug.c
71287@@ -924,7 +924,7 @@ out:
71288
71289 static void check_for_stack(struct device *dev, void *addr)
71290 {
71291- if (object_is_on_stack(addr))
71292+ if (object_starts_on_stack(addr))
71293 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71294 "stack [addr=%p]\n", addr);
71295 }
71296diff --git a/lib/inflate.c b/lib/inflate.c
71297index 013a761..c28f3fc 100644
71298--- a/lib/inflate.c
71299+++ b/lib/inflate.c
71300@@ -269,7 +269,7 @@ static void free(void *where)
71301 malloc_ptr = free_mem_ptr;
71302 }
71303 #else
71304-#define malloc(a) kmalloc(a, GFP_KERNEL)
71305+#define malloc(a) kmalloc((a), GFP_KERNEL)
71306 #define free(a) kfree(a)
71307 #endif
71308
71309diff --git a/lib/ioremap.c b/lib/ioremap.c
71310index 0c9216c..863bd89 100644
71311--- a/lib/ioremap.c
71312+++ b/lib/ioremap.c
71313@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71314 unsigned long next;
71315
71316 phys_addr -= addr;
71317- pmd = pmd_alloc(&init_mm, pud, addr);
71318+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71319 if (!pmd)
71320 return -ENOMEM;
71321 do {
71322@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71323 unsigned long next;
71324
71325 phys_addr -= addr;
71326- pud = pud_alloc(&init_mm, pgd, addr);
71327+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
71328 if (!pud)
71329 return -ENOMEM;
71330 do {
71331diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71332index bd2bea9..6b3c95e 100644
71333--- a/lib/is_single_threaded.c
71334+++ b/lib/is_single_threaded.c
71335@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71336 struct task_struct *p, *t;
71337 bool ret;
71338
71339+ if (!mm)
71340+ return true;
71341+
71342 if (atomic_read(&task->signal->live) != 1)
71343 return false;
71344
71345diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71346index e796429..6e38f9f 100644
71347--- a/lib/radix-tree.c
71348+++ b/lib/radix-tree.c
71349@@ -92,7 +92,7 @@ struct radix_tree_preload {
71350 int nr;
71351 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71352 };
71353-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71354+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71355
71356 static inline void *ptr_to_indirect(void *ptr)
71357 {
71358diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71359index 598a73e..5c5aeb5 100644
71360--- a/lib/vsprintf.c
71361+++ b/lib/vsprintf.c
71362@@ -16,6 +16,9 @@
71363 * - scnprintf and vscnprintf
71364 */
71365
71366+#ifdef CONFIG_GRKERNSEC_HIDESYM
71367+#define __INCLUDED_BY_HIDESYM 1
71368+#endif
71369 #include <stdarg.h>
71370 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71371 #include <linux/types.h>
71372@@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71373 char sym[KSYM_SYMBOL_LEN];
71374 if (ext == 'B')
71375 sprint_backtrace(sym, value);
71376- else if (ext != 'f' && ext != 's')
71377+ else if (ext != 'f' && ext != 's' && ext != 'a')
71378 sprint_symbol(sym, value);
71379 else
71380 sprint_symbol_no_offset(sym, value);
71381@@ -912,7 +915,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71382 return number(buf, end, *(const netdev_features_t *)addr, spec);
71383 }
71384
71385+#ifdef CONFIG_GRKERNSEC_HIDESYM
71386+int kptr_restrict __read_mostly = 2;
71387+#else
71388 int kptr_restrict __read_mostly;
71389+#endif
71390
71391 /*
71392 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71393@@ -926,6 +933,8 @@ int kptr_restrict __read_mostly;
71394 * - 'S' For symbolic direct pointers with offset
71395 * - 's' For symbolic direct pointers without offset
71396 * - 'B' For backtraced symbolic direct pointers with offset
71397+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71398+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71399 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71400 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71401 * - 'M' For a 6-byte MAC address, it prints the address in the
71402@@ -973,12 +982,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71403
71404 if (!ptr && *fmt != 'K') {
71405 /*
71406- * Print (null) with the same width as a pointer so it makes
71407+ * Print (nil) with the same width as a pointer so it makes
71408 * tabular output look nice.
71409 */
71410 if (spec.field_width == -1)
71411 spec.field_width = default_width;
71412- return string(buf, end, "(null)", spec);
71413+ return string(buf, end, "(nil)", spec);
71414 }
71415
71416 switch (*fmt) {
71417@@ -988,6 +997,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71418 /* Fallthrough */
71419 case 'S':
71420 case 's':
71421+#ifdef CONFIG_GRKERNSEC_HIDESYM
71422+ break;
71423+#else
71424+ return symbol_string(buf, end, ptr, spec, *fmt);
71425+#endif
71426+ case 'A':
71427+ case 'a':
71428 case 'B':
71429 return symbol_string(buf, end, ptr, spec, *fmt);
71430 case 'R':
71431@@ -1025,6 +1041,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71432 va_end(va);
71433 return buf;
71434 }
71435+ case 'P':
71436+ break;
71437 case 'K':
71438 /*
71439 * %pK cannot be used in IRQ context because its test
71440@@ -1048,6 +1066,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71441 }
71442 break;
71443 }
71444+
71445+#ifdef CONFIG_GRKERNSEC_HIDESYM
71446+ /* 'P' = approved pointers to copy to userland,
71447+ as in the /proc/kallsyms case, as we make it display nothing
71448+ for non-root users, and the real contents for root users
71449+ Also ignore 'K' pointers, since we force their NULLing for non-root users
71450+ above
71451+ */
71452+ if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71453+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71454+ dump_stack();
71455+ ptr = NULL;
71456+ }
71457+#endif
71458+
71459 spec.flags |= SMALL;
71460 if (spec.field_width == -1) {
71461 spec.field_width = default_width;
71462@@ -1759,11 +1792,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71463 typeof(type) value; \
71464 if (sizeof(type) == 8) { \
71465 args = PTR_ALIGN(args, sizeof(u32)); \
71466- *(u32 *)&value = *(u32 *)args; \
71467- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71468+ *(u32 *)&value = *(const u32 *)args; \
71469+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71470 } else { \
71471 args = PTR_ALIGN(args, sizeof(type)); \
71472- value = *(typeof(type) *)args; \
71473+ value = *(const typeof(type) *)args; \
71474 } \
71475 args += sizeof(type); \
71476 value; \
71477@@ -1826,7 +1859,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71478 case FORMAT_TYPE_STR: {
71479 const char *str_arg = args;
71480 args += strlen(str_arg) + 1;
71481- str = string(str, end, (char *)str_arg, spec);
71482+ str = string(str, end, str_arg, spec);
71483 break;
71484 }
71485
71486diff --git a/localversion-grsec b/localversion-grsec
71487new file mode 100644
71488index 0000000..7cd6065
71489--- /dev/null
71490+++ b/localversion-grsec
71491@@ -0,0 +1 @@
71492+-grsec
71493diff --git a/mm/Kconfig b/mm/Kconfig
71494index 82fed4e..979e814 100644
71495--- a/mm/Kconfig
71496+++ b/mm/Kconfig
71497@@ -247,10 +247,10 @@ config KSM
71498 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71499
71500 config DEFAULT_MMAP_MIN_ADDR
71501- int "Low address space to protect from user allocation"
71502+ int "Low address space to protect from user allocation"
71503 depends on MMU
71504- default 4096
71505- help
71506+ default 65536
71507+ help
71508 This is the portion of low virtual memory which should be protected
71509 from userspace allocation. Keeping a user from writing to low pages
71510 can help reduce the impact of kernel NULL pointer bugs.
71511@@ -280,7 +280,7 @@ config MEMORY_FAILURE
71512
71513 config HWPOISON_INJECT
71514 tristate "HWPoison pages injector"
71515- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71516+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71517 select PROC_PAGE_MONITOR
71518
71519 config NOMMU_INITIAL_TRIM_EXCESS
71520diff --git a/mm/filemap.c b/mm/filemap.c
71521index a4a5260..6151dc5 100644
71522--- a/mm/filemap.c
71523+++ b/mm/filemap.c
71524@@ -1723,7 +1723,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71525 struct address_space *mapping = file->f_mapping;
71526
71527 if (!mapping->a_ops->readpage)
71528- return -ENOEXEC;
71529+ return -ENODEV;
71530 file_accessed(file);
71531 vma->vm_ops = &generic_file_vm_ops;
71532 vma->vm_flags |= VM_CAN_NONLINEAR;
71533@@ -2064,6 +2064,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71534 *pos = i_size_read(inode);
71535
71536 if (limit != RLIM_INFINITY) {
71537+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71538 if (*pos >= limit) {
71539 send_sig(SIGXFSZ, current, 0);
71540 return -EFBIG;
71541diff --git a/mm/fremap.c b/mm/fremap.c
71542index 9ed4fd4..c42648d 100644
71543--- a/mm/fremap.c
71544+++ b/mm/fremap.c
71545@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71546 retry:
71547 vma = find_vma(mm, start);
71548
71549+#ifdef CONFIG_PAX_SEGMEXEC
71550+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71551+ goto out;
71552+#endif
71553+
71554 /*
71555 * Make sure the vma is shared, that it supports prefaulting,
71556 * and that the remapped range is valid and fully within
71557diff --git a/mm/highmem.c b/mm/highmem.c
71558index 57d82c6..e9e0552 100644
71559--- a/mm/highmem.c
71560+++ b/mm/highmem.c
71561@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
71562 * So no dangers, even with speculative execution.
71563 */
71564 page = pte_page(pkmap_page_table[i]);
71565+ pax_open_kernel();
71566 pte_clear(&init_mm, (unsigned long)page_address(page),
71567 &pkmap_page_table[i]);
71568-
71569+ pax_close_kernel();
71570 set_page_address(page, NULL);
71571 need_flush = 1;
71572 }
71573@@ -186,9 +187,11 @@ start:
71574 }
71575 }
71576 vaddr = PKMAP_ADDR(last_pkmap_nr);
71577+
71578+ pax_open_kernel();
71579 set_pte_at(&init_mm, vaddr,
71580 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71581-
71582+ pax_close_kernel();
71583 pkmap_count[last_pkmap_nr] = 1;
71584 set_page_address(page, (void *)vaddr);
71585
71586diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71587index 57c4b93..24b8f59 100644
71588--- a/mm/huge_memory.c
71589+++ b/mm/huge_memory.c
71590@@ -735,7 +735,7 @@ out:
71591 * run pte_offset_map on the pmd, if an huge pmd could
71592 * materialize from under us from a different thread.
71593 */
71594- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71595+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71596 return VM_FAULT_OOM;
71597 /* if an huge pmd materialized from under us just retry later */
71598 if (unlikely(pmd_trans_huge(*pmd)))
71599diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71600index 19558df..f7743b3 100644
71601--- a/mm/hugetlb.c
71602+++ b/mm/hugetlb.c
71603@@ -2463,6 +2463,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71604 return 1;
71605 }
71606
71607+#ifdef CONFIG_PAX_SEGMEXEC
71608+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71609+{
71610+ struct mm_struct *mm = vma->vm_mm;
71611+ struct vm_area_struct *vma_m;
71612+ unsigned long address_m;
71613+ pte_t *ptep_m;
71614+
71615+ vma_m = pax_find_mirror_vma(vma);
71616+ if (!vma_m)
71617+ return;
71618+
71619+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71620+ address_m = address + SEGMEXEC_TASK_SIZE;
71621+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71622+ get_page(page_m);
71623+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
71624+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71625+}
71626+#endif
71627+
71628 /*
71629 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71630 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71631@@ -2575,6 +2596,11 @@ retry_avoidcopy:
71632 make_huge_pte(vma, new_page, 1));
71633 page_remove_rmap(old_page);
71634 hugepage_add_new_anon_rmap(new_page, vma, address);
71635+
71636+#ifdef CONFIG_PAX_SEGMEXEC
71637+ pax_mirror_huge_pte(vma, address, new_page);
71638+#endif
71639+
71640 /* Make the old page be freed below */
71641 new_page = old_page;
71642 mmu_notifier_invalidate_range_end(mm,
71643@@ -2729,6 +2755,10 @@ retry:
71644 && (vma->vm_flags & VM_SHARED)));
71645 set_huge_pte_at(mm, address, ptep, new_pte);
71646
71647+#ifdef CONFIG_PAX_SEGMEXEC
71648+ pax_mirror_huge_pte(vma, address, page);
71649+#endif
71650+
71651 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71652 /* Optimization, do the COW without a second fault */
71653 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71654@@ -2758,6 +2788,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71655 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71656 struct hstate *h = hstate_vma(vma);
71657
71658+#ifdef CONFIG_PAX_SEGMEXEC
71659+ struct vm_area_struct *vma_m;
71660+#endif
71661+
71662 address &= huge_page_mask(h);
71663
71664 ptep = huge_pte_offset(mm, address);
71665@@ -2771,6 +2805,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71666 VM_FAULT_SET_HINDEX(h - hstates);
71667 }
71668
71669+#ifdef CONFIG_PAX_SEGMEXEC
71670+ vma_m = pax_find_mirror_vma(vma);
71671+ if (vma_m) {
71672+ unsigned long address_m;
71673+
71674+ if (vma->vm_start > vma_m->vm_start) {
71675+ address_m = address;
71676+ address -= SEGMEXEC_TASK_SIZE;
71677+ vma = vma_m;
71678+ h = hstate_vma(vma);
71679+ } else
71680+ address_m = address + SEGMEXEC_TASK_SIZE;
71681+
71682+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71683+ return VM_FAULT_OOM;
71684+ address_m &= HPAGE_MASK;
71685+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71686+ }
71687+#endif
71688+
71689 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71690 if (!ptep)
71691 return VM_FAULT_OOM;
71692diff --git a/mm/internal.h b/mm/internal.h
71693index 8052379..47029d1 100644
71694--- a/mm/internal.h
71695+++ b/mm/internal.h
71696@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71697 * in mm/page_alloc.c
71698 */
71699 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71700+extern void free_compound_page(struct page *page);
71701 extern void prep_compound_page(struct page *page, unsigned long order);
71702 #ifdef CONFIG_MEMORY_FAILURE
71703 extern bool is_free_buddy_page(struct page *page);
71704diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71705index 45eb621..6ccd8ea 100644
71706--- a/mm/kmemleak.c
71707+++ b/mm/kmemleak.c
71708@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71709
71710 for (i = 0; i < object->trace_len; i++) {
71711 void *ptr = (void *)object->trace[i];
71712- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71713+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71714 }
71715 }
71716
71717diff --git a/mm/maccess.c b/mm/maccess.c
71718index d53adf9..03a24bf 100644
71719--- a/mm/maccess.c
71720+++ b/mm/maccess.c
71721@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71722 set_fs(KERNEL_DS);
71723 pagefault_disable();
71724 ret = __copy_from_user_inatomic(dst,
71725- (__force const void __user *)src, size);
71726+ (const void __force_user *)src, size);
71727 pagefault_enable();
71728 set_fs(old_fs);
71729
71730@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71731
71732 set_fs(KERNEL_DS);
71733 pagefault_disable();
71734- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71735+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71736 pagefault_enable();
71737 set_fs(old_fs);
71738
71739diff --git a/mm/madvise.c b/mm/madvise.c
71740index 14d260f..b2a80fd 100644
71741--- a/mm/madvise.c
71742+++ b/mm/madvise.c
71743@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71744 pgoff_t pgoff;
71745 unsigned long new_flags = vma->vm_flags;
71746
71747+#ifdef CONFIG_PAX_SEGMEXEC
71748+ struct vm_area_struct *vma_m;
71749+#endif
71750+
71751 switch (behavior) {
71752 case MADV_NORMAL:
71753 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71754@@ -119,6 +123,13 @@ success:
71755 /*
71756 * vm_flags is protected by the mmap_sem held in write mode.
71757 */
71758+
71759+#ifdef CONFIG_PAX_SEGMEXEC
71760+ vma_m = pax_find_mirror_vma(vma);
71761+ if (vma_m)
71762+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71763+#endif
71764+
71765 vma->vm_flags = new_flags;
71766
71767 out:
71768@@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71769 struct vm_area_struct ** prev,
71770 unsigned long start, unsigned long end)
71771 {
71772+
71773+#ifdef CONFIG_PAX_SEGMEXEC
71774+ struct vm_area_struct *vma_m;
71775+#endif
71776+
71777 *prev = vma;
71778 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71779 return -EINVAL;
71780@@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71781 zap_page_range(vma, start, end - start, &details);
71782 } else
71783 zap_page_range(vma, start, end - start, NULL);
71784+
71785+#ifdef CONFIG_PAX_SEGMEXEC
71786+ vma_m = pax_find_mirror_vma(vma);
71787+ if (vma_m) {
71788+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71789+ struct zap_details details = {
71790+ .nonlinear_vma = vma_m,
71791+ .last_index = ULONG_MAX,
71792+ };
71793+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71794+ } else
71795+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71796+ }
71797+#endif
71798+
71799 return 0;
71800 }
71801
71802@@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71803 if (end < start)
71804 goto out;
71805
71806+#ifdef CONFIG_PAX_SEGMEXEC
71807+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71808+ if (end > SEGMEXEC_TASK_SIZE)
71809+ goto out;
71810+ } else
71811+#endif
71812+
71813+ if (end > TASK_SIZE)
71814+ goto out;
71815+
71816 error = 0;
71817 if (end == start)
71818 goto out;
71819diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71820index 6de0d61..da836cf 100644
71821--- a/mm/memory-failure.c
71822+++ b/mm/memory-failure.c
71823@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71824
71825 int sysctl_memory_failure_recovery __read_mostly = 1;
71826
71827-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71828+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71829
71830 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71831
71832@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71833 pfn, t->comm, t->pid);
71834 si.si_signo = SIGBUS;
71835 si.si_errno = 0;
71836- si.si_addr = (void *)addr;
71837+ si.si_addr = (void __user *)addr;
71838 #ifdef __ARCH_SI_TRAPNO
71839 si.si_trapno = trapno;
71840 #endif
71841@@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71842 }
71843
71844 nr_pages = 1 << compound_trans_order(hpage);
71845- atomic_long_add(nr_pages, &mce_bad_pages);
71846+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71847
71848 /*
71849 * We need/can do nothing about count=0 pages.
71850@@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71851 if (!PageHWPoison(hpage)
71852 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71853 || (p != hpage && TestSetPageHWPoison(hpage))) {
71854- atomic_long_sub(nr_pages, &mce_bad_pages);
71855+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71856 return 0;
71857 }
71858 set_page_hwpoison_huge_page(hpage);
71859@@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71860 }
71861 if (hwpoison_filter(p)) {
71862 if (TestClearPageHWPoison(p))
71863- atomic_long_sub(nr_pages, &mce_bad_pages);
71864+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71865 unlock_page(hpage);
71866 put_page(hpage);
71867 return 0;
71868@@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71869 return 0;
71870 }
71871 if (TestClearPageHWPoison(p))
71872- atomic_long_sub(nr_pages, &mce_bad_pages);
71873+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71874 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71875 return 0;
71876 }
71877@@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71878 */
71879 if (TestClearPageHWPoison(page)) {
71880 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71881- atomic_long_sub(nr_pages, &mce_bad_pages);
71882+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71883 freeit = 1;
71884 if (PageHuge(page))
71885 clear_page_hwpoison_huge_page(page);
71886@@ -1448,7 +1448,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71887 }
71888 done:
71889 if (!PageHWPoison(hpage))
71890- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
71891+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
71892 set_page_hwpoison_huge_page(hpage);
71893 dequeue_hwpoisoned_huge_page(hpage);
71894 /* keep elevated page count for bad page */
71895@@ -1579,7 +1579,7 @@ int soft_offline_page(struct page *page, int flags)
71896 return ret;
71897
71898 done:
71899- atomic_long_add(1, &mce_bad_pages);
71900+ atomic_long_add_unchecked(1, &mce_bad_pages);
71901 SetPageHWPoison(page);
71902 /* keep elevated page count for bad page */
71903 return ret;
71904diff --git a/mm/memory.c b/mm/memory.c
71905index 2466d12..595ed79 100644
71906--- a/mm/memory.c
71907+++ b/mm/memory.c
71908@@ -422,6 +422,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71909 free_pte_range(tlb, pmd, addr);
71910 } while (pmd++, addr = next, addr != end);
71911
71912+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71913 start &= PUD_MASK;
71914 if (start < floor)
71915 return;
71916@@ -436,6 +437,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71917 pmd = pmd_offset(pud, start);
71918 pud_clear(pud);
71919 pmd_free_tlb(tlb, pmd, start);
71920+#endif
71921+
71922 }
71923
71924 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71925@@ -455,6 +458,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71926 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
71927 } while (pud++, addr = next, addr != end);
71928
71929+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71930 start &= PGDIR_MASK;
71931 if (start < floor)
71932 return;
71933@@ -469,6 +473,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71934 pud = pud_offset(pgd, start);
71935 pgd_clear(pgd);
71936 pud_free_tlb(tlb, pud, start);
71937+#endif
71938+
71939 }
71940
71941 /*
71942@@ -1602,12 +1608,6 @@ no_page_table:
71943 return page;
71944 }
71945
71946-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71947-{
71948- return stack_guard_page_start(vma, addr) ||
71949- stack_guard_page_end(vma, addr+PAGE_SIZE);
71950-}
71951-
71952 /**
71953 * __get_user_pages() - pin user pages in memory
71954 * @tsk: task_struct of target task
71955@@ -1680,10 +1680,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71956 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71957 i = 0;
71958
71959- do {
71960+ while (nr_pages) {
71961 struct vm_area_struct *vma;
71962
71963- vma = find_extend_vma(mm, start);
71964+ vma = find_vma(mm, start);
71965 if (!vma && in_gate_area(mm, start)) {
71966 unsigned long pg = start & PAGE_MASK;
71967 pgd_t *pgd;
71968@@ -1731,7 +1731,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71969 goto next_page;
71970 }
71971
71972- if (!vma ||
71973+ if (!vma || start < vma->vm_start ||
71974 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71975 !(vm_flags & vma->vm_flags))
71976 return i ? : -EFAULT;
71977@@ -1758,11 +1758,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71978 int ret;
71979 unsigned int fault_flags = 0;
71980
71981- /* For mlock, just skip the stack guard page. */
71982- if (foll_flags & FOLL_MLOCK) {
71983- if (stack_guard_page(vma, start))
71984- goto next_page;
71985- }
71986 if (foll_flags & FOLL_WRITE)
71987 fault_flags |= FAULT_FLAG_WRITE;
71988 if (nonblocking)
71989@@ -1836,7 +1831,7 @@ next_page:
71990 start += PAGE_SIZE;
71991 nr_pages--;
71992 } while (nr_pages && start < vma->vm_end);
71993- } while (nr_pages);
71994+ }
71995 return i;
71996 }
71997 EXPORT_SYMBOL(__get_user_pages);
71998@@ -2043,6 +2038,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71999 page_add_file_rmap(page);
72000 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72001
72002+#ifdef CONFIG_PAX_SEGMEXEC
72003+ pax_mirror_file_pte(vma, addr, page, ptl);
72004+#endif
72005+
72006 retval = 0;
72007 pte_unmap_unlock(pte, ptl);
72008 return retval;
72009@@ -2077,10 +2076,22 @@ out:
72010 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72011 struct page *page)
72012 {
72013+
72014+#ifdef CONFIG_PAX_SEGMEXEC
72015+ struct vm_area_struct *vma_m;
72016+#endif
72017+
72018 if (addr < vma->vm_start || addr >= vma->vm_end)
72019 return -EFAULT;
72020 if (!page_count(page))
72021 return -EINVAL;
72022+
72023+#ifdef CONFIG_PAX_SEGMEXEC
72024+ vma_m = pax_find_mirror_vma(vma);
72025+ if (vma_m)
72026+ vma_m->vm_flags |= VM_INSERTPAGE;
72027+#endif
72028+
72029 vma->vm_flags |= VM_INSERTPAGE;
72030 return insert_page(vma, addr, page, vma->vm_page_prot);
72031 }
72032@@ -2166,6 +2177,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72033 unsigned long pfn)
72034 {
72035 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72036+ BUG_ON(vma->vm_mirror);
72037
72038 if (addr < vma->vm_start || addr >= vma->vm_end)
72039 return -EFAULT;
72040@@ -2373,7 +2385,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72041
72042 BUG_ON(pud_huge(*pud));
72043
72044- pmd = pmd_alloc(mm, pud, addr);
72045+ pmd = (mm == &init_mm) ?
72046+ pmd_alloc_kernel(mm, pud, addr) :
72047+ pmd_alloc(mm, pud, addr);
72048 if (!pmd)
72049 return -ENOMEM;
72050 do {
72051@@ -2393,7 +2407,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72052 unsigned long next;
72053 int err;
72054
72055- pud = pud_alloc(mm, pgd, addr);
72056+ pud = (mm == &init_mm) ?
72057+ pud_alloc_kernel(mm, pgd, addr) :
72058+ pud_alloc(mm, pgd, addr);
72059 if (!pud)
72060 return -ENOMEM;
72061 do {
72062@@ -2481,6 +2497,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72063 copy_user_highpage(dst, src, va, vma);
72064 }
72065
72066+#ifdef CONFIG_PAX_SEGMEXEC
72067+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72068+{
72069+ struct mm_struct *mm = vma->vm_mm;
72070+ spinlock_t *ptl;
72071+ pte_t *pte, entry;
72072+
72073+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72074+ entry = *pte;
72075+ if (!pte_present(entry)) {
72076+ if (!pte_none(entry)) {
72077+ BUG_ON(pte_file(entry));
72078+ free_swap_and_cache(pte_to_swp_entry(entry));
72079+ pte_clear_not_present_full(mm, address, pte, 0);
72080+ }
72081+ } else {
72082+ struct page *page;
72083+
72084+ flush_cache_page(vma, address, pte_pfn(entry));
72085+ entry = ptep_clear_flush(vma, address, pte);
72086+ BUG_ON(pte_dirty(entry));
72087+ page = vm_normal_page(vma, address, entry);
72088+ if (page) {
72089+ update_hiwater_rss(mm);
72090+ if (PageAnon(page))
72091+ dec_mm_counter_fast(mm, MM_ANONPAGES);
72092+ else
72093+ dec_mm_counter_fast(mm, MM_FILEPAGES);
72094+ page_remove_rmap(page);
72095+ page_cache_release(page);
72096+ }
72097+ }
72098+ pte_unmap_unlock(pte, ptl);
72099+}
72100+
72101+/* PaX: if vma is mirrored, synchronize the mirror's PTE
72102+ *
72103+ * the ptl of the lower mapped page is held on entry and is not released on exit
72104+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72105+ */
72106+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72107+{
72108+ struct mm_struct *mm = vma->vm_mm;
72109+ unsigned long address_m;
72110+ spinlock_t *ptl_m;
72111+ struct vm_area_struct *vma_m;
72112+ pmd_t *pmd_m;
72113+ pte_t *pte_m, entry_m;
72114+
72115+ BUG_ON(!page_m || !PageAnon(page_m));
72116+
72117+ vma_m = pax_find_mirror_vma(vma);
72118+ if (!vma_m)
72119+ return;
72120+
72121+ BUG_ON(!PageLocked(page_m));
72122+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72123+ address_m = address + SEGMEXEC_TASK_SIZE;
72124+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72125+ pte_m = pte_offset_map(pmd_m, address_m);
72126+ ptl_m = pte_lockptr(mm, pmd_m);
72127+ if (ptl != ptl_m) {
72128+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72129+ if (!pte_none(*pte_m))
72130+ goto out;
72131+ }
72132+
72133+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72134+ page_cache_get(page_m);
72135+ page_add_anon_rmap(page_m, vma_m, address_m);
72136+ inc_mm_counter_fast(mm, MM_ANONPAGES);
72137+ set_pte_at(mm, address_m, pte_m, entry_m);
72138+ update_mmu_cache(vma_m, address_m, entry_m);
72139+out:
72140+ if (ptl != ptl_m)
72141+ spin_unlock(ptl_m);
72142+ pte_unmap(pte_m);
72143+ unlock_page(page_m);
72144+}
72145+
72146+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72147+{
72148+ struct mm_struct *mm = vma->vm_mm;
72149+ unsigned long address_m;
72150+ spinlock_t *ptl_m;
72151+ struct vm_area_struct *vma_m;
72152+ pmd_t *pmd_m;
72153+ pte_t *pte_m, entry_m;
72154+
72155+ BUG_ON(!page_m || PageAnon(page_m));
72156+
72157+ vma_m = pax_find_mirror_vma(vma);
72158+ if (!vma_m)
72159+ return;
72160+
72161+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72162+ address_m = address + SEGMEXEC_TASK_SIZE;
72163+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72164+ pte_m = pte_offset_map(pmd_m, address_m);
72165+ ptl_m = pte_lockptr(mm, pmd_m);
72166+ if (ptl != ptl_m) {
72167+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72168+ if (!pte_none(*pte_m))
72169+ goto out;
72170+ }
72171+
72172+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72173+ page_cache_get(page_m);
72174+ page_add_file_rmap(page_m);
72175+ inc_mm_counter_fast(mm, MM_FILEPAGES);
72176+ set_pte_at(mm, address_m, pte_m, entry_m);
72177+ update_mmu_cache(vma_m, address_m, entry_m);
72178+out:
72179+ if (ptl != ptl_m)
72180+ spin_unlock(ptl_m);
72181+ pte_unmap(pte_m);
72182+}
72183+
72184+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72185+{
72186+ struct mm_struct *mm = vma->vm_mm;
72187+ unsigned long address_m;
72188+ spinlock_t *ptl_m;
72189+ struct vm_area_struct *vma_m;
72190+ pmd_t *pmd_m;
72191+ pte_t *pte_m, entry_m;
72192+
72193+ vma_m = pax_find_mirror_vma(vma);
72194+ if (!vma_m)
72195+ return;
72196+
72197+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72198+ address_m = address + SEGMEXEC_TASK_SIZE;
72199+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72200+ pte_m = pte_offset_map(pmd_m, address_m);
72201+ ptl_m = pte_lockptr(mm, pmd_m);
72202+ if (ptl != ptl_m) {
72203+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72204+ if (!pte_none(*pte_m))
72205+ goto out;
72206+ }
72207+
72208+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72209+ set_pte_at(mm, address_m, pte_m, entry_m);
72210+out:
72211+ if (ptl != ptl_m)
72212+ spin_unlock(ptl_m);
72213+ pte_unmap(pte_m);
72214+}
72215+
72216+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72217+{
72218+ struct page *page_m;
72219+ pte_t entry;
72220+
72221+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72222+ goto out;
72223+
72224+ entry = *pte;
72225+ page_m = vm_normal_page(vma, address, entry);
72226+ if (!page_m)
72227+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72228+ else if (PageAnon(page_m)) {
72229+ if (pax_find_mirror_vma(vma)) {
72230+ pte_unmap_unlock(pte, ptl);
72231+ lock_page(page_m);
72232+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72233+ if (pte_same(entry, *pte))
72234+ pax_mirror_anon_pte(vma, address, page_m, ptl);
72235+ else
72236+ unlock_page(page_m);
72237+ }
72238+ } else
72239+ pax_mirror_file_pte(vma, address, page_m, ptl);
72240+
72241+out:
72242+ pte_unmap_unlock(pte, ptl);
72243+}
72244+#endif
72245+
72246 /*
72247 * This routine handles present pages, when users try to write
72248 * to a shared page. It is done by copying the page to a new address
72249@@ -2692,6 +2888,12 @@ gotten:
72250 */
72251 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72252 if (likely(pte_same(*page_table, orig_pte))) {
72253+
72254+#ifdef CONFIG_PAX_SEGMEXEC
72255+ if (pax_find_mirror_vma(vma))
72256+ BUG_ON(!trylock_page(new_page));
72257+#endif
72258+
72259 if (old_page) {
72260 if (!PageAnon(old_page)) {
72261 dec_mm_counter_fast(mm, MM_FILEPAGES);
72262@@ -2743,6 +2945,10 @@ gotten:
72263 page_remove_rmap(old_page);
72264 }
72265
72266+#ifdef CONFIG_PAX_SEGMEXEC
72267+ pax_mirror_anon_pte(vma, address, new_page, ptl);
72268+#endif
72269+
72270 /* Free the old page.. */
72271 new_page = old_page;
72272 ret |= VM_FAULT_WRITE;
72273@@ -3022,6 +3228,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72274 swap_free(entry);
72275 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72276 try_to_free_swap(page);
72277+
72278+#ifdef CONFIG_PAX_SEGMEXEC
72279+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72280+#endif
72281+
72282 unlock_page(page);
72283 if (swapcache) {
72284 /*
72285@@ -3045,6 +3256,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72286
72287 /* No need to invalidate - it was non-present before */
72288 update_mmu_cache(vma, address, page_table);
72289+
72290+#ifdef CONFIG_PAX_SEGMEXEC
72291+ pax_mirror_anon_pte(vma, address, page, ptl);
72292+#endif
72293+
72294 unlock:
72295 pte_unmap_unlock(page_table, ptl);
72296 out:
72297@@ -3064,40 +3280,6 @@ out_release:
72298 }
72299
72300 /*
72301- * This is like a special single-page "expand_{down|up}wards()",
72302- * except we must first make sure that 'address{-|+}PAGE_SIZE'
72303- * doesn't hit another vma.
72304- */
72305-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72306-{
72307- address &= PAGE_MASK;
72308- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72309- struct vm_area_struct *prev = vma->vm_prev;
72310-
72311- /*
72312- * Is there a mapping abutting this one below?
72313- *
72314- * That's only ok if it's the same stack mapping
72315- * that has gotten split..
72316- */
72317- if (prev && prev->vm_end == address)
72318- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72319-
72320- expand_downwards(vma, address - PAGE_SIZE);
72321- }
72322- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72323- struct vm_area_struct *next = vma->vm_next;
72324-
72325- /* As VM_GROWSDOWN but s/below/above/ */
72326- if (next && next->vm_start == address + PAGE_SIZE)
72327- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72328-
72329- expand_upwards(vma, address + PAGE_SIZE);
72330- }
72331- return 0;
72332-}
72333-
72334-/*
72335 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72336 * but allow concurrent faults), and pte mapped but not yet locked.
72337 * We return with mmap_sem still held, but pte unmapped and unlocked.
72338@@ -3106,27 +3288,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72339 unsigned long address, pte_t *page_table, pmd_t *pmd,
72340 unsigned int flags)
72341 {
72342- struct page *page;
72343+ struct page *page = NULL;
72344 spinlock_t *ptl;
72345 pte_t entry;
72346
72347- pte_unmap(page_table);
72348-
72349- /* Check if we need to add a guard page to the stack */
72350- if (check_stack_guard_page(vma, address) < 0)
72351- return VM_FAULT_SIGBUS;
72352-
72353- /* Use the zero-page for reads */
72354 if (!(flags & FAULT_FLAG_WRITE)) {
72355 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72356 vma->vm_page_prot));
72357- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72358+ ptl = pte_lockptr(mm, pmd);
72359+ spin_lock(ptl);
72360 if (!pte_none(*page_table))
72361 goto unlock;
72362 goto setpte;
72363 }
72364
72365 /* Allocate our own private page. */
72366+ pte_unmap(page_table);
72367+
72368 if (unlikely(anon_vma_prepare(vma)))
72369 goto oom;
72370 page = alloc_zeroed_user_highpage_movable(vma, address);
72371@@ -3145,6 +3323,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72372 if (!pte_none(*page_table))
72373 goto release;
72374
72375+#ifdef CONFIG_PAX_SEGMEXEC
72376+ if (pax_find_mirror_vma(vma))
72377+ BUG_ON(!trylock_page(page));
72378+#endif
72379+
72380 inc_mm_counter_fast(mm, MM_ANONPAGES);
72381 page_add_new_anon_rmap(page, vma, address);
72382 setpte:
72383@@ -3152,6 +3335,12 @@ setpte:
72384
72385 /* No need to invalidate - it was non-present before */
72386 update_mmu_cache(vma, address, page_table);
72387+
72388+#ifdef CONFIG_PAX_SEGMEXEC
72389+ if (page)
72390+ pax_mirror_anon_pte(vma, address, page, ptl);
72391+#endif
72392+
72393 unlock:
72394 pte_unmap_unlock(page_table, ptl);
72395 return 0;
72396@@ -3295,6 +3484,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72397 */
72398 /* Only go through if we didn't race with anybody else... */
72399 if (likely(pte_same(*page_table, orig_pte))) {
72400+
72401+#ifdef CONFIG_PAX_SEGMEXEC
72402+ if (anon && pax_find_mirror_vma(vma))
72403+ BUG_ON(!trylock_page(page));
72404+#endif
72405+
72406 flush_icache_page(vma, page);
72407 entry = mk_pte(page, vma->vm_page_prot);
72408 if (flags & FAULT_FLAG_WRITE)
72409@@ -3314,6 +3509,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72410
72411 /* no need to invalidate: a not-present page won't be cached */
72412 update_mmu_cache(vma, address, page_table);
72413+
72414+#ifdef CONFIG_PAX_SEGMEXEC
72415+ if (anon)
72416+ pax_mirror_anon_pte(vma, address, page, ptl);
72417+ else
72418+ pax_mirror_file_pte(vma, address, page, ptl);
72419+#endif
72420+
72421 } else {
72422 if (cow_page)
72423 mem_cgroup_uncharge_page(cow_page);
72424@@ -3467,6 +3670,12 @@ int handle_pte_fault(struct mm_struct *mm,
72425 if (flags & FAULT_FLAG_WRITE)
72426 flush_tlb_fix_spurious_fault(vma, address);
72427 }
72428+
72429+#ifdef CONFIG_PAX_SEGMEXEC
72430+ pax_mirror_pte(vma, address, pte, pmd, ptl);
72431+ return 0;
72432+#endif
72433+
72434 unlock:
72435 pte_unmap_unlock(pte, ptl);
72436 return 0;
72437@@ -3483,6 +3692,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72438 pmd_t *pmd;
72439 pte_t *pte;
72440
72441+#ifdef CONFIG_PAX_SEGMEXEC
72442+ struct vm_area_struct *vma_m;
72443+#endif
72444+
72445 __set_current_state(TASK_RUNNING);
72446
72447 count_vm_event(PGFAULT);
72448@@ -3494,6 +3707,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72449 if (unlikely(is_vm_hugetlb_page(vma)))
72450 return hugetlb_fault(mm, vma, address, flags);
72451
72452+#ifdef CONFIG_PAX_SEGMEXEC
72453+ vma_m = pax_find_mirror_vma(vma);
72454+ if (vma_m) {
72455+ unsigned long address_m;
72456+ pgd_t *pgd_m;
72457+ pud_t *pud_m;
72458+ pmd_t *pmd_m;
72459+
72460+ if (vma->vm_start > vma_m->vm_start) {
72461+ address_m = address;
72462+ address -= SEGMEXEC_TASK_SIZE;
72463+ vma = vma_m;
72464+ } else
72465+ address_m = address + SEGMEXEC_TASK_SIZE;
72466+
72467+ pgd_m = pgd_offset(mm, address_m);
72468+ pud_m = pud_alloc(mm, pgd_m, address_m);
72469+ if (!pud_m)
72470+ return VM_FAULT_OOM;
72471+ pmd_m = pmd_alloc(mm, pud_m, address_m);
72472+ if (!pmd_m)
72473+ return VM_FAULT_OOM;
72474+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72475+ return VM_FAULT_OOM;
72476+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72477+ }
72478+#endif
72479+
72480 retry:
72481 pgd = pgd_offset(mm, address);
72482 pud = pud_alloc(mm, pgd, address);
72483@@ -3535,7 +3776,7 @@ retry:
72484 * run pte_offset_map on the pmd, if an huge pmd could
72485 * materialize from under us from a different thread.
72486 */
72487- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72488+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72489 return VM_FAULT_OOM;
72490 /* if an huge pmd materialized from under us just retry later */
72491 if (unlikely(pmd_trans_huge(*pmd)))
72492@@ -3572,6 +3813,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72493 spin_unlock(&mm->page_table_lock);
72494 return 0;
72495 }
72496+
72497+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72498+{
72499+ pud_t *new = pud_alloc_one(mm, address);
72500+ if (!new)
72501+ return -ENOMEM;
72502+
72503+ smp_wmb(); /* See comment in __pte_alloc */
72504+
72505+ spin_lock(&mm->page_table_lock);
72506+ if (pgd_present(*pgd)) /* Another has populated it */
72507+ pud_free(mm, new);
72508+ else
72509+ pgd_populate_kernel(mm, pgd, new);
72510+ spin_unlock(&mm->page_table_lock);
72511+ return 0;
72512+}
72513 #endif /* __PAGETABLE_PUD_FOLDED */
72514
72515 #ifndef __PAGETABLE_PMD_FOLDED
72516@@ -3602,6 +3860,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72517 spin_unlock(&mm->page_table_lock);
72518 return 0;
72519 }
72520+
72521+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72522+{
72523+ pmd_t *new = pmd_alloc_one(mm, address);
72524+ if (!new)
72525+ return -ENOMEM;
72526+
72527+ smp_wmb(); /* See comment in __pte_alloc */
72528+
72529+ spin_lock(&mm->page_table_lock);
72530+#ifndef __ARCH_HAS_4LEVEL_HACK
72531+ if (pud_present(*pud)) /* Another has populated it */
72532+ pmd_free(mm, new);
72533+ else
72534+ pud_populate_kernel(mm, pud, new);
72535+#else
72536+ if (pgd_present(*pud)) /* Another has populated it */
72537+ pmd_free(mm, new);
72538+ else
72539+ pgd_populate_kernel(mm, pud, new);
72540+#endif /* __ARCH_HAS_4LEVEL_HACK */
72541+ spin_unlock(&mm->page_table_lock);
72542+ return 0;
72543+}
72544 #endif /* __PAGETABLE_PMD_FOLDED */
72545
72546 int make_pages_present(unsigned long addr, unsigned long end)
72547@@ -3639,7 +3921,7 @@ static int __init gate_vma_init(void)
72548 gate_vma.vm_start = FIXADDR_USER_START;
72549 gate_vma.vm_end = FIXADDR_USER_END;
72550 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72551- gate_vma.vm_page_prot = __P101;
72552+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72553
72554 return 0;
72555 }
72556diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72557index b12b28a..64b57d0 100644
72558--- a/mm/mempolicy.c
72559+++ b/mm/mempolicy.c
72560@@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72561 unsigned long vmstart;
72562 unsigned long vmend;
72563
72564+#ifdef CONFIG_PAX_SEGMEXEC
72565+ struct vm_area_struct *vma_m;
72566+#endif
72567+
72568 vma = find_vma(mm, start);
72569 if (!vma || vma->vm_start > start)
72570 return -EFAULT;
72571@@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72572 if (err)
72573 goto out;
72574 }
72575+
72576+#ifdef CONFIG_PAX_SEGMEXEC
72577+ vma_m = pax_find_mirror_vma(vma);
72578+ if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
72579+ err = vma_m->vm_ops->set_policy(vma_m, new_pol);
72580+ if (err)
72581+ goto out;
72582+ }
72583+#endif
72584+
72585 }
72586
72587 out:
72588@@ -1125,6 +1139,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72589
72590 if (end < start)
72591 return -EINVAL;
72592+
72593+#ifdef CONFIG_PAX_SEGMEXEC
72594+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72595+ if (end > SEGMEXEC_TASK_SIZE)
72596+ return -EINVAL;
72597+ } else
72598+#endif
72599+
72600+ if (end > TASK_SIZE)
72601+ return -EINVAL;
72602+
72603 if (end == start)
72604 return 0;
72605
72606@@ -1348,8 +1373,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72607 */
72608 tcred = __task_cred(task);
72609 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72610- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72611- !capable(CAP_SYS_NICE)) {
72612+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72613 rcu_read_unlock();
72614 err = -EPERM;
72615 goto out_put;
72616@@ -1380,6 +1404,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72617 goto out;
72618 }
72619
72620+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72621+ if (mm != current->mm &&
72622+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72623+ mmput(mm);
72624+ err = -EPERM;
72625+ goto out;
72626+ }
72627+#endif
72628+
72629 err = do_migrate_pages(mm, old, new,
72630 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72631
72632diff --git a/mm/mlock.c b/mm/mlock.c
72633index ef726e8..cd7f1ec 100644
72634--- a/mm/mlock.c
72635+++ b/mm/mlock.c
72636@@ -13,6 +13,7 @@
72637 #include <linux/pagemap.h>
72638 #include <linux/mempolicy.h>
72639 #include <linux/syscalls.h>
72640+#include <linux/security.h>
72641 #include <linux/sched.h>
72642 #include <linux/export.h>
72643 #include <linux/rmap.h>
72644@@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72645 {
72646 unsigned long nstart, end, tmp;
72647 struct vm_area_struct * vma, * prev;
72648- int error;
72649+ int error = 0;
72650
72651 VM_BUG_ON(start & ~PAGE_MASK);
72652 VM_BUG_ON(len != PAGE_ALIGN(len));
72653@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72654 return -EINVAL;
72655 if (end == start)
72656 return 0;
72657+ if (end > TASK_SIZE)
72658+ return -EINVAL;
72659+
72660 vma = find_vma(current->mm, start);
72661 if (!vma || vma->vm_start > start)
72662 return -ENOMEM;
72663@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72664 for (nstart = start ; ; ) {
72665 vm_flags_t newflags;
72666
72667+#ifdef CONFIG_PAX_SEGMEXEC
72668+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72669+ break;
72670+#endif
72671+
72672 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72673
72674 newflags = vma->vm_flags | VM_LOCKED;
72675@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72676 lock_limit >>= PAGE_SHIFT;
72677
72678 /* check against resource limits */
72679+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72680 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72681 error = do_mlock(start, len, 1);
72682 up_write(&current->mm->mmap_sem);
72683@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72684 static int do_mlockall(int flags)
72685 {
72686 struct vm_area_struct * vma, * prev = NULL;
72687- unsigned int def_flags = 0;
72688
72689 if (flags & MCL_FUTURE)
72690- def_flags = VM_LOCKED;
72691- current->mm->def_flags = def_flags;
72692+ current->mm->def_flags |= VM_LOCKED;
72693+ else
72694+ current->mm->def_flags &= ~VM_LOCKED;
72695 if (flags == MCL_FUTURE)
72696 goto out;
72697
72698 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72699 vm_flags_t newflags;
72700
72701+#ifdef CONFIG_PAX_SEGMEXEC
72702+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72703+ break;
72704+#endif
72705+
72706+ BUG_ON(vma->vm_end > TASK_SIZE);
72707 newflags = vma->vm_flags | VM_LOCKED;
72708 if (!(flags & MCL_CURRENT))
72709 newflags &= ~VM_LOCKED;
72710@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72711 lock_limit >>= PAGE_SHIFT;
72712
72713 ret = -ENOMEM;
72714+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72715 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72716 capable(CAP_IPC_LOCK))
72717 ret = do_mlockall(flags);
72718diff --git a/mm/mmap.c b/mm/mmap.c
72719index fa1f274..86de476 100644
72720--- a/mm/mmap.c
72721+++ b/mm/mmap.c
72722@@ -47,6 +47,16 @@
72723 #define arch_rebalance_pgtables(addr, len) (addr)
72724 #endif
72725
72726+static inline void verify_mm_writelocked(struct mm_struct *mm)
72727+{
72728+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72729+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72730+ up_read(&mm->mmap_sem);
72731+ BUG();
72732+ }
72733+#endif
72734+}
72735+
72736 static void unmap_region(struct mm_struct *mm,
72737 struct vm_area_struct *vma, struct vm_area_struct *prev,
72738 unsigned long start, unsigned long end);
72739@@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72740 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72741 *
72742 */
72743-pgprot_t protection_map[16] = {
72744+pgprot_t protection_map[16] __read_only = {
72745 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72746 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72747 };
72748
72749-pgprot_t vm_get_page_prot(unsigned long vm_flags)
72750+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72751 {
72752- return __pgprot(pgprot_val(protection_map[vm_flags &
72753+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72754 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72755 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72756+
72757+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72758+ if (!(__supported_pte_mask & _PAGE_NX) &&
72759+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72760+ (vm_flags & (VM_READ | VM_WRITE)))
72761+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72762+#endif
72763+
72764+ return prot;
72765 }
72766 EXPORT_SYMBOL(vm_get_page_prot);
72767
72768 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72769 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72770 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72771+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72772 /*
72773 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72774 * other variables. It can be updated by several CPUs frequently.
72775@@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72776 struct vm_area_struct *next = vma->vm_next;
72777
72778 might_sleep();
72779+ BUG_ON(vma->vm_mirror);
72780 if (vma->vm_ops && vma->vm_ops->close)
72781 vma->vm_ops->close(vma);
72782 if (vma->vm_file) {
72783@@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72784 * not page aligned -Ram Gupta
72785 */
72786 rlim = rlimit(RLIMIT_DATA);
72787+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72788 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72789 (mm->end_data - mm->start_data) > rlim)
72790 goto out;
72791@@ -708,6 +730,12 @@ static int
72792 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72793 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72794 {
72795+
72796+#ifdef CONFIG_PAX_SEGMEXEC
72797+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72798+ return 0;
72799+#endif
72800+
72801 if (is_mergeable_vma(vma, file, vm_flags) &&
72802 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72803 if (vma->vm_pgoff == vm_pgoff)
72804@@ -727,6 +755,12 @@ static int
72805 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72806 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72807 {
72808+
72809+#ifdef CONFIG_PAX_SEGMEXEC
72810+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72811+ return 0;
72812+#endif
72813+
72814 if (is_mergeable_vma(vma, file, vm_flags) &&
72815 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72816 pgoff_t vm_pglen;
72817@@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72818 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72819 struct vm_area_struct *prev, unsigned long addr,
72820 unsigned long end, unsigned long vm_flags,
72821- struct anon_vma *anon_vma, struct file *file,
72822+ struct anon_vma *anon_vma, struct file *file,
72823 pgoff_t pgoff, struct mempolicy *policy)
72824 {
72825 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72826 struct vm_area_struct *area, *next;
72827 int err;
72828
72829+#ifdef CONFIG_PAX_SEGMEXEC
72830+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72831+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72832+
72833+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72834+#endif
72835+
72836 /*
72837 * We later require that vma->vm_flags == vm_flags,
72838 * so this tests vma->vm_flags & VM_SPECIAL, too.
72839@@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72840 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72841 next = next->vm_next;
72842
72843+#ifdef CONFIG_PAX_SEGMEXEC
72844+ if (prev)
72845+ prev_m = pax_find_mirror_vma(prev);
72846+ if (area)
72847+ area_m = pax_find_mirror_vma(area);
72848+ if (next)
72849+ next_m = pax_find_mirror_vma(next);
72850+#endif
72851+
72852 /*
72853 * Can it merge with the predecessor?
72854 */
72855@@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72856 /* cases 1, 6 */
72857 err = vma_adjust(prev, prev->vm_start,
72858 next->vm_end, prev->vm_pgoff, NULL);
72859- } else /* cases 2, 5, 7 */
72860+
72861+#ifdef CONFIG_PAX_SEGMEXEC
72862+ if (!err && prev_m)
72863+ err = vma_adjust(prev_m, prev_m->vm_start,
72864+ next_m->vm_end, prev_m->vm_pgoff, NULL);
72865+#endif
72866+
72867+ } else { /* cases 2, 5, 7 */
72868 err = vma_adjust(prev, prev->vm_start,
72869 end, prev->vm_pgoff, NULL);
72870+
72871+#ifdef CONFIG_PAX_SEGMEXEC
72872+ if (!err && prev_m)
72873+ err = vma_adjust(prev_m, prev_m->vm_start,
72874+ end_m, prev_m->vm_pgoff, NULL);
72875+#endif
72876+
72877+ }
72878 if (err)
72879 return NULL;
72880 khugepaged_enter_vma_merge(prev);
72881@@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72882 mpol_equal(policy, vma_policy(next)) &&
72883 can_vma_merge_before(next, vm_flags,
72884 anon_vma, file, pgoff+pglen)) {
72885- if (prev && addr < prev->vm_end) /* case 4 */
72886+ if (prev && addr < prev->vm_end) { /* case 4 */
72887 err = vma_adjust(prev, prev->vm_start,
72888 addr, prev->vm_pgoff, NULL);
72889- else /* cases 3, 8 */
72890+
72891+#ifdef CONFIG_PAX_SEGMEXEC
72892+ if (!err && prev_m)
72893+ err = vma_adjust(prev_m, prev_m->vm_start,
72894+ addr_m, prev_m->vm_pgoff, NULL);
72895+#endif
72896+
72897+ } else { /* cases 3, 8 */
72898 err = vma_adjust(area, addr, next->vm_end,
72899 next->vm_pgoff - pglen, NULL);
72900+
72901+#ifdef CONFIG_PAX_SEGMEXEC
72902+ if (!err && area_m)
72903+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
72904+ next_m->vm_pgoff - pglen, NULL);
72905+#endif
72906+
72907+ }
72908 if (err)
72909 return NULL;
72910 khugepaged_enter_vma_merge(area);
72911@@ -940,14 +1020,11 @@ none:
72912 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72913 struct file *file, long pages)
72914 {
72915- const unsigned long stack_flags
72916- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72917-
72918 if (file) {
72919 mm->shared_vm += pages;
72920 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72921 mm->exec_vm += pages;
72922- } else if (flags & stack_flags)
72923+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72924 mm->stack_vm += pages;
72925 if (flags & (VM_RESERVED|VM_IO))
72926 mm->reserved_vm += pages;
72927@@ -985,7 +1062,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72928 * (the exception is when the underlying filesystem is noexec
72929 * mounted, in which case we dont add PROT_EXEC.)
72930 */
72931- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72932+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72933 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72934 prot |= PROT_EXEC;
72935
72936@@ -1011,7 +1088,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72937 /* Obtain the address to map to. we verify (or select) it and ensure
72938 * that it represents a valid section of the address space.
72939 */
72940- addr = get_unmapped_area(file, addr, len, pgoff, flags);
72941+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72942 if (addr & ~PAGE_MASK)
72943 return addr;
72944
72945@@ -1022,6 +1099,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72946 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72947 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72948
72949+#ifdef CONFIG_PAX_MPROTECT
72950+ if (mm->pax_flags & MF_PAX_MPROTECT) {
72951+#ifndef CONFIG_PAX_MPROTECT_COMPAT
72952+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72953+ gr_log_rwxmmap(file);
72954+
72955+#ifdef CONFIG_PAX_EMUPLT
72956+ vm_flags &= ~VM_EXEC;
72957+#else
72958+ return -EPERM;
72959+#endif
72960+
72961+ }
72962+
72963+ if (!(vm_flags & VM_EXEC))
72964+ vm_flags &= ~VM_MAYEXEC;
72965+#else
72966+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72967+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72968+#endif
72969+ else
72970+ vm_flags &= ~VM_MAYWRITE;
72971+ }
72972+#endif
72973+
72974+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72975+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72976+ vm_flags &= ~VM_PAGEEXEC;
72977+#endif
72978+
72979 if (flags & MAP_LOCKED)
72980 if (!can_do_mlock())
72981 return -EPERM;
72982@@ -1033,6 +1140,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72983 locked += mm->locked_vm;
72984 lock_limit = rlimit(RLIMIT_MEMLOCK);
72985 lock_limit >>= PAGE_SHIFT;
72986+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72987 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72988 return -EAGAIN;
72989 }
72990@@ -1099,6 +1207,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72991 }
72992 }
72993
72994+ if (!gr_acl_handle_mmap(file, prot))
72995+ return -EACCES;
72996+
72997 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72998 }
72999
73000@@ -1175,7 +1286,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73001 vm_flags_t vm_flags = vma->vm_flags;
73002
73003 /* If it was private or non-writable, the write bit is already clear */
73004- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73005+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73006 return 0;
73007
73008 /* The backer wishes to know when pages are first written to? */
73009@@ -1224,14 +1335,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73010 unsigned long charged = 0;
73011 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73012
73013+#ifdef CONFIG_PAX_SEGMEXEC
73014+ struct vm_area_struct *vma_m = NULL;
73015+#endif
73016+
73017+ /*
73018+ * mm->mmap_sem is required to protect against another thread
73019+ * changing the mappings in case we sleep.
73020+ */
73021+ verify_mm_writelocked(mm);
73022+
73023 /* Clear old maps */
73024 error = -ENOMEM;
73025-munmap_back:
73026 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73027 if (vma && vma->vm_start < addr + len) {
73028 if (do_munmap(mm, addr, len))
73029 return -ENOMEM;
73030- goto munmap_back;
73031+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73032+ BUG_ON(vma && vma->vm_start < addr + len);
73033 }
73034
73035 /* Check against address space limit. */
73036@@ -1280,6 +1401,16 @@ munmap_back:
73037 goto unacct_error;
73038 }
73039
73040+#ifdef CONFIG_PAX_SEGMEXEC
73041+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73042+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73043+ if (!vma_m) {
73044+ error = -ENOMEM;
73045+ goto free_vma;
73046+ }
73047+ }
73048+#endif
73049+
73050 vma->vm_mm = mm;
73051 vma->vm_start = addr;
73052 vma->vm_end = addr + len;
73053@@ -1304,6 +1435,19 @@ munmap_back:
73054 error = file->f_op->mmap(file, vma);
73055 if (error)
73056 goto unmap_and_free_vma;
73057+
73058+#ifdef CONFIG_PAX_SEGMEXEC
73059+ if (vma_m && (vm_flags & VM_EXECUTABLE))
73060+ added_exe_file_vma(mm);
73061+#endif
73062+
73063+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73064+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73065+ vma->vm_flags |= VM_PAGEEXEC;
73066+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73067+ }
73068+#endif
73069+
73070 if (vm_flags & VM_EXECUTABLE)
73071 added_exe_file_vma(mm);
73072
73073@@ -1341,6 +1485,11 @@ munmap_back:
73074 vma_link(mm, vma, prev, rb_link, rb_parent);
73075 file = vma->vm_file;
73076
73077+#ifdef CONFIG_PAX_SEGMEXEC
73078+ if (vma_m)
73079+ BUG_ON(pax_mirror_vma(vma_m, vma));
73080+#endif
73081+
73082 /* Once vma denies write, undo our temporary denial count */
73083 if (correct_wcount)
73084 atomic_inc(&inode->i_writecount);
73085@@ -1349,6 +1498,7 @@ out:
73086
73087 mm->total_vm += len >> PAGE_SHIFT;
73088 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73089+ track_exec_limit(mm, addr, addr + len, vm_flags);
73090 if (vm_flags & VM_LOCKED) {
73091 if (!mlock_vma_pages_range(vma, addr, addr + len))
73092 mm->locked_vm += (len >> PAGE_SHIFT);
73093@@ -1370,6 +1520,12 @@ unmap_and_free_vma:
73094 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73095 charged = 0;
73096 free_vma:
73097+
73098+#ifdef CONFIG_PAX_SEGMEXEC
73099+ if (vma_m)
73100+ kmem_cache_free(vm_area_cachep, vma_m);
73101+#endif
73102+
73103 kmem_cache_free(vm_area_cachep, vma);
73104 unacct_error:
73105 if (charged)
73106@@ -1377,6 +1533,44 @@ unacct_error:
73107 return error;
73108 }
73109
73110+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73111+{
73112+ if (!vma) {
73113+#ifdef CONFIG_STACK_GROWSUP
73114+ if (addr > sysctl_heap_stack_gap)
73115+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73116+ else
73117+ vma = find_vma(current->mm, 0);
73118+ if (vma && (vma->vm_flags & VM_GROWSUP))
73119+ return false;
73120+#endif
73121+ return true;
73122+ }
73123+
73124+ if (addr + len > vma->vm_start)
73125+ return false;
73126+
73127+ if (vma->vm_flags & VM_GROWSDOWN)
73128+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73129+#ifdef CONFIG_STACK_GROWSUP
73130+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73131+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73132+#endif
73133+
73134+ return true;
73135+}
73136+
73137+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73138+{
73139+ if (vma->vm_start < len)
73140+ return -ENOMEM;
73141+ if (!(vma->vm_flags & VM_GROWSDOWN))
73142+ return vma->vm_start - len;
73143+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
73144+ return vma->vm_start - len - sysctl_heap_stack_gap;
73145+ return -ENOMEM;
73146+}
73147+
73148 /* Get an address range which is currently unmapped.
73149 * For shmat() with addr=0.
73150 *
73151@@ -1403,18 +1597,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73152 if (flags & MAP_FIXED)
73153 return addr;
73154
73155+#ifdef CONFIG_PAX_RANDMMAP
73156+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73157+#endif
73158+
73159 if (addr) {
73160 addr = PAGE_ALIGN(addr);
73161- vma = find_vma(mm, addr);
73162- if (TASK_SIZE - len >= addr &&
73163- (!vma || addr + len <= vma->vm_start))
73164- return addr;
73165+ if (TASK_SIZE - len >= addr) {
73166+ vma = find_vma(mm, addr);
73167+ if (check_heap_stack_gap(vma, addr, len))
73168+ return addr;
73169+ }
73170 }
73171 if (len > mm->cached_hole_size) {
73172- start_addr = addr = mm->free_area_cache;
73173+ start_addr = addr = mm->free_area_cache;
73174 } else {
73175- start_addr = addr = TASK_UNMAPPED_BASE;
73176- mm->cached_hole_size = 0;
73177+ start_addr = addr = mm->mmap_base;
73178+ mm->cached_hole_size = 0;
73179 }
73180
73181 full_search:
73182@@ -1425,34 +1624,40 @@ full_search:
73183 * Start a new search - just in case we missed
73184 * some holes.
73185 */
73186- if (start_addr != TASK_UNMAPPED_BASE) {
73187- addr = TASK_UNMAPPED_BASE;
73188- start_addr = addr;
73189+ if (start_addr != mm->mmap_base) {
73190+ start_addr = addr = mm->mmap_base;
73191 mm->cached_hole_size = 0;
73192 goto full_search;
73193 }
73194 return -ENOMEM;
73195 }
73196- if (!vma || addr + len <= vma->vm_start) {
73197- /*
73198- * Remember the place where we stopped the search:
73199- */
73200- mm->free_area_cache = addr + len;
73201- return addr;
73202- }
73203+ if (check_heap_stack_gap(vma, addr, len))
73204+ break;
73205 if (addr + mm->cached_hole_size < vma->vm_start)
73206 mm->cached_hole_size = vma->vm_start - addr;
73207 addr = vma->vm_end;
73208 }
73209+
73210+ /*
73211+ * Remember the place where we stopped the search:
73212+ */
73213+ mm->free_area_cache = addr + len;
73214+ return addr;
73215 }
73216 #endif
73217
73218 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73219 {
73220+
73221+#ifdef CONFIG_PAX_SEGMEXEC
73222+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73223+ return;
73224+#endif
73225+
73226 /*
73227 * Is this a new hole at the lowest possible address?
73228 */
73229- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73230+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73231 mm->free_area_cache = addr;
73232 }
73233
73234@@ -1468,7 +1673,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73235 {
73236 struct vm_area_struct *vma;
73237 struct mm_struct *mm = current->mm;
73238- unsigned long addr = addr0, start_addr;
73239+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73240
73241 /* requested length too big for entire address space */
73242 if (len > TASK_SIZE)
73243@@ -1477,13 +1682,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73244 if (flags & MAP_FIXED)
73245 return addr;
73246
73247+#ifdef CONFIG_PAX_RANDMMAP
73248+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73249+#endif
73250+
73251 /* requesting a specific address */
73252 if (addr) {
73253 addr = PAGE_ALIGN(addr);
73254- vma = find_vma(mm, addr);
73255- if (TASK_SIZE - len >= addr &&
73256- (!vma || addr + len <= vma->vm_start))
73257- return addr;
73258+ if (TASK_SIZE - len >= addr) {
73259+ vma = find_vma(mm, addr);
73260+ if (check_heap_stack_gap(vma, addr, len))
73261+ return addr;
73262+ }
73263 }
73264
73265 /* check if free_area_cache is useful for us */
73266@@ -1507,7 +1717,7 @@ try_again:
73267 * return with success:
73268 */
73269 vma = find_vma(mm, addr);
73270- if (!vma || addr+len <= vma->vm_start)
73271+ if (check_heap_stack_gap(vma, addr, len))
73272 /* remember the address as a hint for next time */
73273 return (mm->free_area_cache = addr);
73274
73275@@ -1516,8 +1726,8 @@ try_again:
73276 mm->cached_hole_size = vma->vm_start - addr;
73277
73278 /* try just below the current vma->vm_start */
73279- addr = vma->vm_start-len;
73280- } while (len < vma->vm_start);
73281+ addr = skip_heap_stack_gap(vma, len);
73282+ } while (!IS_ERR_VALUE(addr));
73283
73284 fail:
73285 /*
73286@@ -1540,13 +1750,21 @@ fail:
73287 * can happen with large stack limits and large mmap()
73288 * allocations.
73289 */
73290+ mm->mmap_base = TASK_UNMAPPED_BASE;
73291+
73292+#ifdef CONFIG_PAX_RANDMMAP
73293+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73294+ mm->mmap_base += mm->delta_mmap;
73295+#endif
73296+
73297+ mm->free_area_cache = mm->mmap_base;
73298 mm->cached_hole_size = ~0UL;
73299- mm->free_area_cache = TASK_UNMAPPED_BASE;
73300 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73301 /*
73302 * Restore the topdown base:
73303 */
73304- mm->free_area_cache = mm->mmap_base;
73305+ mm->mmap_base = base;
73306+ mm->free_area_cache = base;
73307 mm->cached_hole_size = ~0UL;
73308
73309 return addr;
73310@@ -1555,6 +1773,12 @@ fail:
73311
73312 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73313 {
73314+
73315+#ifdef CONFIG_PAX_SEGMEXEC
73316+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73317+ return;
73318+#endif
73319+
73320 /*
73321 * Is this a new hole at the highest possible address?
73322 */
73323@@ -1562,8 +1786,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73324 mm->free_area_cache = addr;
73325
73326 /* dont allow allocations above current base */
73327- if (mm->free_area_cache > mm->mmap_base)
73328+ if (mm->free_area_cache > mm->mmap_base) {
73329 mm->free_area_cache = mm->mmap_base;
73330+ mm->cached_hole_size = ~0UL;
73331+ }
73332 }
73333
73334 unsigned long
73335@@ -1662,6 +1888,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73336 return vma;
73337 }
73338
73339+#ifdef CONFIG_PAX_SEGMEXEC
73340+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73341+{
73342+ struct vm_area_struct *vma_m;
73343+
73344+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73345+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73346+ BUG_ON(vma->vm_mirror);
73347+ return NULL;
73348+ }
73349+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73350+ vma_m = vma->vm_mirror;
73351+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73352+ BUG_ON(vma->vm_file != vma_m->vm_file);
73353+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73354+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73355+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73356+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73357+ return vma_m;
73358+}
73359+#endif
73360+
73361 /*
73362 * Verify that the stack growth is acceptable and
73363 * update accounting. This is shared with both the
73364@@ -1678,6 +1926,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73365 return -ENOMEM;
73366
73367 /* Stack limit test */
73368+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
73369 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73370 return -ENOMEM;
73371
73372@@ -1688,6 +1937,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73373 locked = mm->locked_vm + grow;
73374 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73375 limit >>= PAGE_SHIFT;
73376+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73377 if (locked > limit && !capable(CAP_IPC_LOCK))
73378 return -ENOMEM;
73379 }
73380@@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73381 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73382 * vma is the last one with address > vma->vm_end. Have to extend vma.
73383 */
73384+#ifndef CONFIG_IA64
73385+static
73386+#endif
73387 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73388 {
73389 int error;
73390+ bool locknext;
73391
73392 if (!(vma->vm_flags & VM_GROWSUP))
73393 return -EFAULT;
73394
73395+ /* Also guard against wrapping around to address 0. */
73396+ if (address < PAGE_ALIGN(address+1))
73397+ address = PAGE_ALIGN(address+1);
73398+ else
73399+ return -ENOMEM;
73400+
73401 /*
73402 * We must make sure the anon_vma is allocated
73403 * so that the anon_vma locking is not a noop.
73404 */
73405 if (unlikely(anon_vma_prepare(vma)))
73406 return -ENOMEM;
73407+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73408+ if (locknext && anon_vma_prepare(vma->vm_next))
73409+ return -ENOMEM;
73410 vma_lock_anon_vma(vma);
73411+ if (locknext)
73412+ vma_lock_anon_vma(vma->vm_next);
73413
73414 /*
73415 * vma->vm_start/vm_end cannot change under us because the caller
73416 * is required to hold the mmap_sem in read mode. We need the
73417- * anon_vma lock to serialize against concurrent expand_stacks.
73418- * Also guard against wrapping around to address 0.
73419+ * anon_vma locks to serialize against concurrent expand_stacks
73420+ * and expand_upwards.
73421 */
73422- if (address < PAGE_ALIGN(address+4))
73423- address = PAGE_ALIGN(address+4);
73424- else {
73425- vma_unlock_anon_vma(vma);
73426- return -ENOMEM;
73427- }
73428 error = 0;
73429
73430 /* Somebody else might have raced and expanded it already */
73431- if (address > vma->vm_end) {
73432+ 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)
73433+ error = -ENOMEM;
73434+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73435 unsigned long size, grow;
73436
73437 size = address - vma->vm_start;
73438@@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73439 }
73440 }
73441 }
73442+ if (locknext)
73443+ vma_unlock_anon_vma(vma->vm_next);
73444 vma_unlock_anon_vma(vma);
73445 khugepaged_enter_vma_merge(vma);
73446 return error;
73447@@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
73448 unsigned long address)
73449 {
73450 int error;
73451+ bool lockprev = false;
73452+ struct vm_area_struct *prev;
73453
73454 /*
73455 * We must make sure the anon_vma is allocated
73456@@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
73457 if (error)
73458 return error;
73459
73460+ prev = vma->vm_prev;
73461+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73462+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73463+#endif
73464+ if (lockprev && anon_vma_prepare(prev))
73465+ return -ENOMEM;
73466+ if (lockprev)
73467+ vma_lock_anon_vma(prev);
73468+
73469 vma_lock_anon_vma(vma);
73470
73471 /*
73472@@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
73473 */
73474
73475 /* Somebody else might have raced and expanded it already */
73476- if (address < vma->vm_start) {
73477+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73478+ error = -ENOMEM;
73479+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73480 unsigned long size, grow;
73481
73482+#ifdef CONFIG_PAX_SEGMEXEC
73483+ struct vm_area_struct *vma_m;
73484+
73485+ vma_m = pax_find_mirror_vma(vma);
73486+#endif
73487+
73488 size = vma->vm_end - address;
73489 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73490
73491@@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
73492 if (!error) {
73493 vma->vm_start = address;
73494 vma->vm_pgoff -= grow;
73495+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73496+
73497+#ifdef CONFIG_PAX_SEGMEXEC
73498+ if (vma_m) {
73499+ vma_m->vm_start -= grow << PAGE_SHIFT;
73500+ vma_m->vm_pgoff -= grow;
73501+ }
73502+#endif
73503+
73504 perf_event_mmap(vma);
73505 }
73506 }
73507 }
73508 vma_unlock_anon_vma(vma);
73509+ if (lockprev)
73510+ vma_unlock_anon_vma(prev);
73511 khugepaged_enter_vma_merge(vma);
73512 return error;
73513 }
73514@@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73515 do {
73516 long nrpages = vma_pages(vma);
73517
73518+#ifdef CONFIG_PAX_SEGMEXEC
73519+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73520+ vma = remove_vma(vma);
73521+ continue;
73522+ }
73523+#endif
73524+
73525 if (vma->vm_flags & VM_ACCOUNT)
73526 nr_accounted += nrpages;
73527 mm->total_vm -= nrpages;
73528@@ -1932,6 +2232,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73529 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73530 vma->vm_prev = NULL;
73531 do {
73532+
73533+#ifdef CONFIG_PAX_SEGMEXEC
73534+ if (vma->vm_mirror) {
73535+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73536+ vma->vm_mirror->vm_mirror = NULL;
73537+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
73538+ vma->vm_mirror = NULL;
73539+ }
73540+#endif
73541+
73542 rb_erase(&vma->vm_rb, &mm->mm_rb);
73543 mm->map_count--;
73544 tail_vma = vma;
73545@@ -1960,14 +2270,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73546 struct vm_area_struct *new;
73547 int err = -ENOMEM;
73548
73549+#ifdef CONFIG_PAX_SEGMEXEC
73550+ struct vm_area_struct *vma_m, *new_m = NULL;
73551+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73552+#endif
73553+
73554 if (is_vm_hugetlb_page(vma) && (addr &
73555 ~(huge_page_mask(hstate_vma(vma)))))
73556 return -EINVAL;
73557
73558+#ifdef CONFIG_PAX_SEGMEXEC
73559+ vma_m = pax_find_mirror_vma(vma);
73560+#endif
73561+
73562 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73563 if (!new)
73564 goto out_err;
73565
73566+#ifdef CONFIG_PAX_SEGMEXEC
73567+ if (vma_m) {
73568+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73569+ if (!new_m) {
73570+ kmem_cache_free(vm_area_cachep, new);
73571+ goto out_err;
73572+ }
73573+ }
73574+#endif
73575+
73576 /* most fields are the same, copy all, and then fixup */
73577 *new = *vma;
73578
73579@@ -1980,6 +2309,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73580 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73581 }
73582
73583+#ifdef CONFIG_PAX_SEGMEXEC
73584+ if (vma_m) {
73585+ *new_m = *vma_m;
73586+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
73587+ new_m->vm_mirror = new;
73588+ new->vm_mirror = new_m;
73589+
73590+ if (new_below)
73591+ new_m->vm_end = addr_m;
73592+ else {
73593+ new_m->vm_start = addr_m;
73594+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73595+ }
73596+ }
73597+#endif
73598+
73599 pol = mpol_dup(vma_policy(vma));
73600 if (IS_ERR(pol)) {
73601 err = PTR_ERR(pol);
73602@@ -2005,6 +2350,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73603 else
73604 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73605
73606+#ifdef CONFIG_PAX_SEGMEXEC
73607+ if (!err && vma_m) {
73608+ if (anon_vma_clone(new_m, vma_m))
73609+ goto out_free_mpol;
73610+
73611+ mpol_get(pol);
73612+ vma_set_policy(new_m, pol);
73613+
73614+ if (new_m->vm_file) {
73615+ get_file(new_m->vm_file);
73616+ if (vma_m->vm_flags & VM_EXECUTABLE)
73617+ added_exe_file_vma(mm);
73618+ }
73619+
73620+ if (new_m->vm_ops && new_m->vm_ops->open)
73621+ new_m->vm_ops->open(new_m);
73622+
73623+ if (new_below)
73624+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73625+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73626+ else
73627+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73628+
73629+ if (err) {
73630+ if (new_m->vm_ops && new_m->vm_ops->close)
73631+ new_m->vm_ops->close(new_m);
73632+ if (new_m->vm_file) {
73633+ if (vma_m->vm_flags & VM_EXECUTABLE)
73634+ removed_exe_file_vma(mm);
73635+ fput(new_m->vm_file);
73636+ }
73637+ mpol_put(pol);
73638+ }
73639+ }
73640+#endif
73641+
73642 /* Success. */
73643 if (!err)
73644 return 0;
73645@@ -2017,10 +2398,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73646 removed_exe_file_vma(mm);
73647 fput(new->vm_file);
73648 }
73649- unlink_anon_vmas(new);
73650 out_free_mpol:
73651 mpol_put(pol);
73652 out_free_vma:
73653+
73654+#ifdef CONFIG_PAX_SEGMEXEC
73655+ if (new_m) {
73656+ unlink_anon_vmas(new_m);
73657+ kmem_cache_free(vm_area_cachep, new_m);
73658+ }
73659+#endif
73660+
73661+ unlink_anon_vmas(new);
73662 kmem_cache_free(vm_area_cachep, new);
73663 out_err:
73664 return err;
73665@@ -2033,6 +2422,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73666 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73667 unsigned long addr, int new_below)
73668 {
73669+
73670+#ifdef CONFIG_PAX_SEGMEXEC
73671+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73672+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73673+ if (mm->map_count >= sysctl_max_map_count-1)
73674+ return -ENOMEM;
73675+ } else
73676+#endif
73677+
73678 if (mm->map_count >= sysctl_max_map_count)
73679 return -ENOMEM;
73680
73681@@ -2044,11 +2442,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73682 * work. This now handles partial unmappings.
73683 * Jeremy Fitzhardinge <jeremy@goop.org>
73684 */
73685+#ifdef CONFIG_PAX_SEGMEXEC
73686 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73687 {
73688+ int ret = __do_munmap(mm, start, len);
73689+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73690+ return ret;
73691+
73692+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73693+}
73694+
73695+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73696+#else
73697+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73698+#endif
73699+{
73700 unsigned long end;
73701 struct vm_area_struct *vma, *prev, *last;
73702
73703+ /*
73704+ * mm->mmap_sem is required to protect against another thread
73705+ * changing the mappings in case we sleep.
73706+ */
73707+ verify_mm_writelocked(mm);
73708+
73709 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73710 return -EINVAL;
73711
73712@@ -2123,6 +2540,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73713 /* Fix up all other VM information */
73714 remove_vma_list(mm, vma);
73715
73716+ track_exec_limit(mm, start, end, 0UL);
73717+
73718 return 0;
73719 }
73720
73721@@ -2131,6 +2550,13 @@ int vm_munmap(unsigned long start, size_t len)
73722 int ret;
73723 struct mm_struct *mm = current->mm;
73724
73725+
73726+#ifdef CONFIG_PAX_SEGMEXEC
73727+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73728+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73729+ return -EINVAL;
73730+#endif
73731+
73732 down_write(&mm->mmap_sem);
73733 ret = do_munmap(mm, start, len);
73734 up_write(&mm->mmap_sem);
73735@@ -2144,16 +2570,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73736 return vm_munmap(addr, len);
73737 }
73738
73739-static inline void verify_mm_writelocked(struct mm_struct *mm)
73740-{
73741-#ifdef CONFIG_DEBUG_VM
73742- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73743- WARN_ON(1);
73744- up_read(&mm->mmap_sem);
73745- }
73746-#endif
73747-}
73748-
73749 /*
73750 * this is really a simplified "do_mmap". it only handles
73751 * anonymous maps. eventually we may be able to do some
73752@@ -2167,6 +2583,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73753 struct rb_node ** rb_link, * rb_parent;
73754 pgoff_t pgoff = addr >> PAGE_SHIFT;
73755 int error;
73756+ unsigned long charged;
73757
73758 len = PAGE_ALIGN(len);
73759 if (!len)
73760@@ -2174,16 +2591,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73761
73762 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73763
73764+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73765+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73766+ flags &= ~VM_EXEC;
73767+
73768+#ifdef CONFIG_PAX_MPROTECT
73769+ if (mm->pax_flags & MF_PAX_MPROTECT)
73770+ flags &= ~VM_MAYEXEC;
73771+#endif
73772+
73773+ }
73774+#endif
73775+
73776 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73777 if (error & ~PAGE_MASK)
73778 return error;
73779
73780+ charged = len >> PAGE_SHIFT;
73781+
73782 /*
73783 * mlock MCL_FUTURE?
73784 */
73785 if (mm->def_flags & VM_LOCKED) {
73786 unsigned long locked, lock_limit;
73787- locked = len >> PAGE_SHIFT;
73788+ locked = charged;
73789 locked += mm->locked_vm;
73790 lock_limit = rlimit(RLIMIT_MEMLOCK);
73791 lock_limit >>= PAGE_SHIFT;
73792@@ -2200,22 +2631,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73793 /*
73794 * Clear old maps. this also does some error checking for us
73795 */
73796- munmap_back:
73797 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73798 if (vma && vma->vm_start < addr + len) {
73799 if (do_munmap(mm, addr, len))
73800 return -ENOMEM;
73801- goto munmap_back;
73802- }
73803+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73804+ BUG_ON(vma && vma->vm_start < addr + len);
73805+ }
73806
73807 /* Check against address space limits *after* clearing old maps... */
73808- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73809+ if (!may_expand_vm(mm, charged))
73810 return -ENOMEM;
73811
73812 if (mm->map_count > sysctl_max_map_count)
73813 return -ENOMEM;
73814
73815- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73816+ if (security_vm_enough_memory_mm(mm, charged))
73817 return -ENOMEM;
73818
73819 /* Can we just expand an old private anonymous mapping? */
73820@@ -2229,7 +2660,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73821 */
73822 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73823 if (!vma) {
73824- vm_unacct_memory(len >> PAGE_SHIFT);
73825+ vm_unacct_memory(charged);
73826 return -ENOMEM;
73827 }
73828
73829@@ -2243,11 +2674,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73830 vma_link(mm, vma, prev, rb_link, rb_parent);
73831 out:
73832 perf_event_mmap(vma);
73833- mm->total_vm += len >> PAGE_SHIFT;
73834+ mm->total_vm += charged;
73835 if (flags & VM_LOCKED) {
73836 if (!mlock_vma_pages_range(vma, addr, addr + len))
73837- mm->locked_vm += (len >> PAGE_SHIFT);
73838+ mm->locked_vm += charged;
73839 }
73840+ track_exec_limit(mm, addr, addr + len, flags);
73841 return addr;
73842 }
73843
73844@@ -2305,6 +2737,7 @@ void exit_mmap(struct mm_struct *mm)
73845 while (vma) {
73846 if (vma->vm_flags & VM_ACCOUNT)
73847 nr_accounted += vma_pages(vma);
73848+ vma->vm_mirror = NULL;
73849 vma = remove_vma(vma);
73850 }
73851 vm_unacct_memory(nr_accounted);
73852@@ -2321,6 +2754,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73853 struct vm_area_struct * __vma, * prev;
73854 struct rb_node ** rb_link, * rb_parent;
73855
73856+#ifdef CONFIG_PAX_SEGMEXEC
73857+ struct vm_area_struct *vma_m = NULL;
73858+#endif
73859+
73860+ if (security_mmap_addr(vma->vm_start))
73861+ return -EPERM;
73862+
73863 /*
73864 * The vm_pgoff of a purely anonymous vma should be irrelevant
73865 * until its first write fault, when page's anon_vma and index
73866@@ -2347,7 +2787,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73867 if (vma->vm_file && uprobe_mmap(vma))
73868 return -EINVAL;
73869
73870+#ifdef CONFIG_PAX_SEGMEXEC
73871+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73872+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73873+ if (!vma_m)
73874+ return -ENOMEM;
73875+ }
73876+#endif
73877+
73878 vma_link(mm, vma, prev, rb_link, rb_parent);
73879+
73880+#ifdef CONFIG_PAX_SEGMEXEC
73881+ if (vma_m)
73882+ BUG_ON(pax_mirror_vma(vma_m, vma));
73883+#endif
73884+
73885 return 0;
73886 }
73887
73888@@ -2366,6 +2820,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73889 struct mempolicy *pol;
73890 bool faulted_in_anon_vma = true;
73891
73892+ BUG_ON(vma->vm_mirror);
73893+
73894 /*
73895 * If anonymous vma has not yet been faulted, update new pgoff
73896 * to match new location, to increase its chance of merging.
73897@@ -2437,6 +2893,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73898 return NULL;
73899 }
73900
73901+#ifdef CONFIG_PAX_SEGMEXEC
73902+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73903+{
73904+ struct vm_area_struct *prev_m;
73905+ struct rb_node **rb_link_m, *rb_parent_m;
73906+ struct mempolicy *pol_m;
73907+
73908+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73909+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73910+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73911+ *vma_m = *vma;
73912+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73913+ if (anon_vma_clone(vma_m, vma))
73914+ return -ENOMEM;
73915+ pol_m = vma_policy(vma_m);
73916+ mpol_get(pol_m);
73917+ vma_set_policy(vma_m, pol_m);
73918+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73919+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73920+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73921+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73922+ if (vma_m->vm_file)
73923+ get_file(vma_m->vm_file);
73924+ if (vma_m->vm_ops && vma_m->vm_ops->open)
73925+ vma_m->vm_ops->open(vma_m);
73926+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73927+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73928+ vma_m->vm_mirror = vma;
73929+ vma->vm_mirror = vma_m;
73930+ return 0;
73931+}
73932+#endif
73933+
73934 /*
73935 * Return true if the calling process may expand its vm space by the passed
73936 * number of pages
73937@@ -2448,6 +2937,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73938
73939 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73940
73941+#ifdef CONFIG_PAX_RANDMMAP
73942+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73943+ cur -= mm->brk_gap;
73944+#endif
73945+
73946+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73947 if (cur + npages > lim)
73948 return 0;
73949 return 1;
73950@@ -2518,6 +3013,22 @@ int install_special_mapping(struct mm_struct *mm,
73951 vma->vm_start = addr;
73952 vma->vm_end = addr + len;
73953
73954+#ifdef CONFIG_PAX_MPROTECT
73955+ if (mm->pax_flags & MF_PAX_MPROTECT) {
73956+#ifndef CONFIG_PAX_MPROTECT_COMPAT
73957+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73958+ return -EPERM;
73959+ if (!(vm_flags & VM_EXEC))
73960+ vm_flags &= ~VM_MAYEXEC;
73961+#else
73962+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73963+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73964+#endif
73965+ else
73966+ vm_flags &= ~VM_MAYWRITE;
73967+ }
73968+#endif
73969+
73970 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73971 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73972
73973diff --git a/mm/mprotect.c b/mm/mprotect.c
73974index a409926..8b32e6d 100644
73975--- a/mm/mprotect.c
73976+++ b/mm/mprotect.c
73977@@ -23,10 +23,17 @@
73978 #include <linux/mmu_notifier.h>
73979 #include <linux/migrate.h>
73980 #include <linux/perf_event.h>
73981+
73982+#ifdef CONFIG_PAX_MPROTECT
73983+#include <linux/elf.h>
73984+#include <linux/binfmts.h>
73985+#endif
73986+
73987 #include <asm/uaccess.h>
73988 #include <asm/pgtable.h>
73989 #include <asm/cacheflush.h>
73990 #include <asm/tlbflush.h>
73991+#include <asm/mmu_context.h>
73992
73993 #ifndef pgprot_modify
73994 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73995@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73996 flush_tlb_range(vma, start, end);
73997 }
73998
73999+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74000+/* called while holding the mmap semaphor for writing except stack expansion */
74001+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74002+{
74003+ unsigned long oldlimit, newlimit = 0UL;
74004+
74005+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74006+ return;
74007+
74008+ spin_lock(&mm->page_table_lock);
74009+ oldlimit = mm->context.user_cs_limit;
74010+ if ((prot & VM_EXEC) && oldlimit < end)
74011+ /* USER_CS limit moved up */
74012+ newlimit = end;
74013+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74014+ /* USER_CS limit moved down */
74015+ newlimit = start;
74016+
74017+ if (newlimit) {
74018+ mm->context.user_cs_limit = newlimit;
74019+
74020+#ifdef CONFIG_SMP
74021+ wmb();
74022+ cpus_clear(mm->context.cpu_user_cs_mask);
74023+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74024+#endif
74025+
74026+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74027+ }
74028+ spin_unlock(&mm->page_table_lock);
74029+ if (newlimit == end) {
74030+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
74031+
74032+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
74033+ if (is_vm_hugetlb_page(vma))
74034+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74035+ else
74036+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74037+ }
74038+}
74039+#endif
74040+
74041 int
74042 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74043 unsigned long start, unsigned long end, unsigned long newflags)
74044@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74045 int error;
74046 int dirty_accountable = 0;
74047
74048+#ifdef CONFIG_PAX_SEGMEXEC
74049+ struct vm_area_struct *vma_m = NULL;
74050+ unsigned long start_m, end_m;
74051+
74052+ start_m = start + SEGMEXEC_TASK_SIZE;
74053+ end_m = end + SEGMEXEC_TASK_SIZE;
74054+#endif
74055+
74056 if (newflags == oldflags) {
74057 *pprev = vma;
74058 return 0;
74059 }
74060
74061+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74062+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74063+
74064+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74065+ return -ENOMEM;
74066+
74067+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74068+ return -ENOMEM;
74069+ }
74070+
74071 /*
74072 * If we make a private mapping writable we increase our commit;
74073 * but (without finer accounting) cannot reduce our commit if we
74074@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74075 }
74076 }
74077
74078+#ifdef CONFIG_PAX_SEGMEXEC
74079+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74080+ if (start != vma->vm_start) {
74081+ error = split_vma(mm, vma, start, 1);
74082+ if (error)
74083+ goto fail;
74084+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74085+ *pprev = (*pprev)->vm_next;
74086+ }
74087+
74088+ if (end != vma->vm_end) {
74089+ error = split_vma(mm, vma, end, 0);
74090+ if (error)
74091+ goto fail;
74092+ }
74093+
74094+ if (pax_find_mirror_vma(vma)) {
74095+ error = __do_munmap(mm, start_m, end_m - start_m);
74096+ if (error)
74097+ goto fail;
74098+ } else {
74099+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74100+ if (!vma_m) {
74101+ error = -ENOMEM;
74102+ goto fail;
74103+ }
74104+ vma->vm_flags = newflags;
74105+ error = pax_mirror_vma(vma_m, vma);
74106+ if (error) {
74107+ vma->vm_flags = oldflags;
74108+ goto fail;
74109+ }
74110+ }
74111+ }
74112+#endif
74113+
74114 /*
74115 * First try to merge with previous and/or next vma.
74116 */
74117@@ -204,9 +307,21 @@ success:
74118 * vm_flags and vm_page_prot are protected by the mmap_sem
74119 * held in write mode.
74120 */
74121+
74122+#ifdef CONFIG_PAX_SEGMEXEC
74123+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74124+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74125+#endif
74126+
74127 vma->vm_flags = newflags;
74128+
74129+#ifdef CONFIG_PAX_MPROTECT
74130+ if (mm->binfmt && mm->binfmt->handle_mprotect)
74131+ mm->binfmt->handle_mprotect(vma, newflags);
74132+#endif
74133+
74134 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74135- vm_get_page_prot(newflags));
74136+ vm_get_page_prot(vma->vm_flags));
74137
74138 if (vma_wants_writenotify(vma)) {
74139 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74140@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74141 end = start + len;
74142 if (end <= start)
74143 return -ENOMEM;
74144+
74145+#ifdef CONFIG_PAX_SEGMEXEC
74146+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74147+ if (end > SEGMEXEC_TASK_SIZE)
74148+ return -EINVAL;
74149+ } else
74150+#endif
74151+
74152+ if (end > TASK_SIZE)
74153+ return -EINVAL;
74154+
74155 if (!arch_validate_prot(prot))
74156 return -EINVAL;
74157
74158@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74159 /*
74160 * Does the application expect PROT_READ to imply PROT_EXEC:
74161 */
74162- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74163+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74164 prot |= PROT_EXEC;
74165
74166 vm_flags = calc_vm_prot_bits(prot);
74167@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74168 if (start > vma->vm_start)
74169 prev = vma;
74170
74171+#ifdef CONFIG_PAX_MPROTECT
74172+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74173+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
74174+#endif
74175+
74176 for (nstart = start ; ; ) {
74177 unsigned long newflags;
74178
74179@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74180
74181 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74182 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74183+ if (prot & (PROT_WRITE | PROT_EXEC))
74184+ gr_log_rwxmprotect(vma->vm_file);
74185+
74186+ error = -EACCES;
74187+ goto out;
74188+ }
74189+
74190+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74191 error = -EACCES;
74192 goto out;
74193 }
74194@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74195 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74196 if (error)
74197 goto out;
74198+
74199+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
74200+
74201 nstart = tmp;
74202
74203 if (nstart < prev->vm_end)
74204diff --git a/mm/mremap.c b/mm/mremap.c
74205index 21fed20..6822658 100644
74206--- a/mm/mremap.c
74207+++ b/mm/mremap.c
74208@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74209 continue;
74210 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74211 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74212+
74213+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74214+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74215+ pte = pte_exprotect(pte);
74216+#endif
74217+
74218 set_pte_at(mm, new_addr, new_pte, pte);
74219 }
74220
74221@@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74222 if (is_vm_hugetlb_page(vma))
74223 goto Einval;
74224
74225+#ifdef CONFIG_PAX_SEGMEXEC
74226+ if (pax_find_mirror_vma(vma))
74227+ goto Einval;
74228+#endif
74229+
74230 /* We can't remap across vm area boundaries */
74231 if (old_len > vma->vm_end - addr)
74232 goto Efault;
74233@@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
74234 unsigned long ret = -EINVAL;
74235 unsigned long charged = 0;
74236 unsigned long map_flags;
74237+ unsigned long pax_task_size = TASK_SIZE;
74238
74239 if (new_addr & ~PAGE_MASK)
74240 goto out;
74241
74242- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74243+#ifdef CONFIG_PAX_SEGMEXEC
74244+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
74245+ pax_task_size = SEGMEXEC_TASK_SIZE;
74246+#endif
74247+
74248+ pax_task_size -= PAGE_SIZE;
74249+
74250+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74251 goto out;
74252
74253 /* Check if the location we're moving into overlaps the
74254 * old location at all, and fail if it does.
74255 */
74256- if ((new_addr <= addr) && (new_addr+new_len) > addr)
74257- goto out;
74258-
74259- if ((addr <= new_addr) && (addr+old_len) > new_addr)
74260+ if (addr + old_len > new_addr && new_addr + new_len > addr)
74261 goto out;
74262
74263 ret = do_munmap(mm, new_addr, new_len);
74264@@ -436,6 +452,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74265 struct vm_area_struct *vma;
74266 unsigned long ret = -EINVAL;
74267 unsigned long charged = 0;
74268+ unsigned long pax_task_size = TASK_SIZE;
74269
74270 down_write(&current->mm->mmap_sem);
74271
74272@@ -456,6 +473,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74273 if (!new_len)
74274 goto out;
74275
74276+#ifdef CONFIG_PAX_SEGMEXEC
74277+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
74278+ pax_task_size = SEGMEXEC_TASK_SIZE;
74279+#endif
74280+
74281+ pax_task_size -= PAGE_SIZE;
74282+
74283+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74284+ old_len > pax_task_size || addr > pax_task_size-old_len)
74285+ goto out;
74286+
74287 if (flags & MREMAP_FIXED) {
74288 if (flags & MREMAP_MAYMOVE)
74289 ret = mremap_to(addr, old_len, new_addr, new_len);
74290@@ -505,6 +533,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74291 addr + new_len);
74292 }
74293 ret = addr;
74294+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74295 goto out;
74296 }
74297 }
74298@@ -528,7 +557,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74299 goto out;
74300 }
74301
74302+ map_flags = vma->vm_flags;
74303 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74304+ if (!(ret & ~PAGE_MASK)) {
74305+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74306+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74307+ }
74308 }
74309 out:
74310 if (ret & ~PAGE_MASK)
74311diff --git a/mm/nommu.c b/mm/nommu.c
74312index d4b0c10..ed421b5 100644
74313--- a/mm/nommu.c
74314+++ b/mm/nommu.c
74315@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74316 int sysctl_overcommit_ratio = 50; /* default is 50% */
74317 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74318 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74319-int heap_stack_gap = 0;
74320
74321 atomic_long_t mmap_pages_allocated;
74322
74323@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74324 EXPORT_SYMBOL(find_vma);
74325
74326 /*
74327- * find a VMA
74328- * - we don't extend stack VMAs under NOMMU conditions
74329- */
74330-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74331-{
74332- return find_vma(mm, addr);
74333-}
74334-
74335-/*
74336 * expand a stack to a given address
74337 * - not supported under NOMMU conditions
74338 */
74339@@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74340
74341 /* most fields are the same, copy all, and then fixup */
74342 *new = *vma;
74343+ INIT_LIST_HEAD(&new->anon_vma_chain);
74344 *region = *vma->vm_region;
74345 new->vm_region = region;
74346
74347diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74348index 34d879e..62970df 100644
74349--- a/mm/page_alloc.c
74350+++ b/mm/page_alloc.c
74351@@ -336,7 +336,7 @@ out:
74352 * This usage means that zero-order pages may not be compound.
74353 */
74354
74355-static void free_compound_page(struct page *page)
74356+void free_compound_page(struct page *page)
74357 {
74358 __free_pages_ok(page, compound_order(page));
74359 }
74360@@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74361 int i;
74362 int bad = 0;
74363
74364+#ifdef CONFIG_PAX_MEMORY_SANITIZE
74365+ unsigned long index = 1UL << order;
74366+#endif
74367+
74368 trace_mm_page_free(page, order);
74369 kmemcheck_free_shadow(page, order);
74370
74371@@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74372 debug_check_no_obj_freed(page_address(page),
74373 PAGE_SIZE << order);
74374 }
74375+
74376+#ifdef CONFIG_PAX_MEMORY_SANITIZE
74377+ for (; index; --index)
74378+ sanitize_highpage(page + index - 1);
74379+#endif
74380+
74381 arch_free_page(page, order);
74382 kernel_map_pages(page, 1 << order, 0);
74383
74384@@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74385 arch_alloc_page(page, order);
74386 kernel_map_pages(page, 1 << order, 1);
74387
74388+#ifndef CONFIG_PAX_MEMORY_SANITIZE
74389 if (gfp_flags & __GFP_ZERO)
74390 prep_zero_page(page, order, gfp_flags);
74391+#endif
74392
74393 if (order && (gfp_flags & __GFP_COMP))
74394 prep_compound_page(page, order);
74395@@ -3579,7 +3591,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74396 unsigned long pfn;
74397
74398 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74399+#ifdef CONFIG_X86_32
74400+ /* boot failures in VMware 8 on 32bit vanilla since
74401+ this change */
74402+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74403+#else
74404 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74405+#endif
74406 return 1;
74407 }
74408 return 0;
74409diff --git a/mm/percpu.c b/mm/percpu.c
74410index bb4be74..a43ea85 100644
74411--- a/mm/percpu.c
74412+++ b/mm/percpu.c
74413@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74414 static unsigned int pcpu_high_unit_cpu __read_mostly;
74415
74416 /* the address of the first chunk which starts with the kernel static area */
74417-void *pcpu_base_addr __read_mostly;
74418+void *pcpu_base_addr __read_only;
74419 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74420
74421 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74422diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74423index 926b466..b23df53 100644
74424--- a/mm/process_vm_access.c
74425+++ b/mm/process_vm_access.c
74426@@ -13,6 +13,7 @@
74427 #include <linux/uio.h>
74428 #include <linux/sched.h>
74429 #include <linux/highmem.h>
74430+#include <linux/security.h>
74431 #include <linux/ptrace.h>
74432 #include <linux/slab.h>
74433 #include <linux/syscalls.h>
74434@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74435 size_t iov_l_curr_offset = 0;
74436 ssize_t iov_len;
74437
74438+ return -ENOSYS; // PaX: until properly audited
74439+
74440 /*
74441 * Work out how many pages of struct pages we're going to need
74442 * when eventually calling get_user_pages
74443 */
74444 for (i = 0; i < riovcnt; i++) {
74445 iov_len = rvec[i].iov_len;
74446- if (iov_len > 0) {
74447- nr_pages_iov = ((unsigned long)rvec[i].iov_base
74448- + iov_len)
74449- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74450- / PAGE_SIZE + 1;
74451- nr_pages = max(nr_pages, nr_pages_iov);
74452- }
74453+ if (iov_len <= 0)
74454+ continue;
74455+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74456+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74457+ nr_pages = max(nr_pages, nr_pages_iov);
74458 }
74459
74460 if (nr_pages == 0)
74461@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74462 goto free_proc_pages;
74463 }
74464
74465+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74466+ rc = -EPERM;
74467+ goto put_task_struct;
74468+ }
74469+
74470 mm = mm_access(task, PTRACE_MODE_ATTACH);
74471 if (!mm || IS_ERR(mm)) {
74472 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74473diff --git a/mm/rmap.c b/mm/rmap.c
74474index 0f3b7cd..c5652b6 100644
74475--- a/mm/rmap.c
74476+++ b/mm/rmap.c
74477@@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74478 struct anon_vma *anon_vma = vma->anon_vma;
74479 struct anon_vma_chain *avc;
74480
74481+#ifdef CONFIG_PAX_SEGMEXEC
74482+ struct anon_vma_chain *avc_m = NULL;
74483+#endif
74484+
74485 might_sleep();
74486 if (unlikely(!anon_vma)) {
74487 struct mm_struct *mm = vma->vm_mm;
74488@@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74489 if (!avc)
74490 goto out_enomem;
74491
74492+#ifdef CONFIG_PAX_SEGMEXEC
74493+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74494+ if (!avc_m)
74495+ goto out_enomem_free_avc;
74496+#endif
74497+
74498 anon_vma = find_mergeable_anon_vma(vma);
74499 allocated = NULL;
74500 if (!anon_vma) {
74501@@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74502 /* page_table_lock to protect against threads */
74503 spin_lock(&mm->page_table_lock);
74504 if (likely(!vma->anon_vma)) {
74505+
74506+#ifdef CONFIG_PAX_SEGMEXEC
74507+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74508+
74509+ if (vma_m) {
74510+ BUG_ON(vma_m->anon_vma);
74511+ vma_m->anon_vma = anon_vma;
74512+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
74513+ avc_m = NULL;
74514+ }
74515+#endif
74516+
74517 vma->anon_vma = anon_vma;
74518 anon_vma_chain_link(vma, avc, anon_vma);
74519 allocated = NULL;
74520@@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74521
74522 if (unlikely(allocated))
74523 put_anon_vma(allocated);
74524+
74525+#ifdef CONFIG_PAX_SEGMEXEC
74526+ if (unlikely(avc_m))
74527+ anon_vma_chain_free(avc_m);
74528+#endif
74529+
74530 if (unlikely(avc))
74531 anon_vma_chain_free(avc);
74532 }
74533 return 0;
74534
74535 out_enomem_free_avc:
74536+
74537+#ifdef CONFIG_PAX_SEGMEXEC
74538+ if (avc_m)
74539+ anon_vma_chain_free(avc_m);
74540+#endif
74541+
74542 anon_vma_chain_free(avc);
74543 out_enomem:
74544 return -ENOMEM;
74545@@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74546 * Attach the anon_vmas from src to dst.
74547 * Returns 0 on success, -ENOMEM on failure.
74548 */
74549-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74550+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74551 {
74552 struct anon_vma_chain *avc, *pavc;
74553 struct anon_vma *root = NULL;
74554@@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74555 * the corresponding VMA in the parent process is attached to.
74556 * Returns 0 on success, non-zero on failure.
74557 */
74558-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74559+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74560 {
74561 struct anon_vma_chain *avc;
74562 struct anon_vma *anon_vma;
74563diff --git a/mm/shmem.c b/mm/shmem.c
74564index bd10636..5c16d49 100644
74565--- a/mm/shmem.c
74566+++ b/mm/shmem.c
74567@@ -31,7 +31,7 @@
74568 #include <linux/export.h>
74569 #include <linux/swap.h>
74570
74571-static struct vfsmount *shm_mnt;
74572+struct vfsmount *shm_mnt;
74573
74574 #ifdef CONFIG_SHMEM
74575 /*
74576@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74577 #define BOGO_DIRENT_SIZE 20
74578
74579 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74580-#define SHORT_SYMLINK_LEN 128
74581+#define SHORT_SYMLINK_LEN 64
74582
74583 struct shmem_xattr {
74584 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74585@@ -2590,8 +2590,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74586 int err = -ENOMEM;
74587
74588 /* Round up to L1_CACHE_BYTES to resist false sharing */
74589- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74590- L1_CACHE_BYTES), GFP_KERNEL);
74591+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74592 if (!sbinfo)
74593 return -ENOMEM;
74594
74595diff --git a/mm/slab.c b/mm/slab.c
74596index e901a36..9ff3f90 100644
74597--- a/mm/slab.c
74598+++ b/mm/slab.c
74599@@ -153,7 +153,7 @@
74600
74601 /* Legal flag mask for kmem_cache_create(). */
74602 #if DEBUG
74603-# define CREATE_MASK (SLAB_RED_ZONE | \
74604+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74605 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74606 SLAB_CACHE_DMA | \
74607 SLAB_STORE_USER | \
74608@@ -161,7 +161,7 @@
74609 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74610 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74611 #else
74612-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74613+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74614 SLAB_CACHE_DMA | \
74615 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74616 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74617@@ -290,7 +290,7 @@ struct kmem_list3 {
74618 * Need this for bootstrapping a per node allocator.
74619 */
74620 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74621-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74622+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74623 #define CACHE_CACHE 0
74624 #define SIZE_AC MAX_NUMNODES
74625 #define SIZE_L3 (2 * MAX_NUMNODES)
74626@@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74627 if ((x)->max_freeable < i) \
74628 (x)->max_freeable = i; \
74629 } while (0)
74630-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74631-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74632-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74633-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74634+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74635+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74636+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74637+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74638 #else
74639 #define STATS_INC_ACTIVE(x) do { } while (0)
74640 #define STATS_DEC_ACTIVE(x) do { } while (0)
74641@@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74642 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74643 */
74644 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74645- const struct slab *slab, void *obj)
74646+ const struct slab *slab, const void *obj)
74647 {
74648 u32 offset = (obj - slab->s_mem);
74649 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74650@@ -563,12 +563,13 @@ EXPORT_SYMBOL(malloc_sizes);
74651 struct cache_names {
74652 char *name;
74653 char *name_dma;
74654+ char *name_usercopy;
74655 };
74656
74657 static struct cache_names __initdata cache_names[] = {
74658-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74659+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74660 #include <linux/kmalloc_sizes.h>
74661- {NULL,}
74662+ {NULL}
74663 #undef CACHE
74664 };
74665
74666@@ -756,6 +757,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74667 if (unlikely(gfpflags & GFP_DMA))
74668 return csizep->cs_dmacachep;
74669 #endif
74670+
74671+#ifdef CONFIG_PAX_USERCOPY_SLABS
74672+ if (unlikely(gfpflags & GFP_USERCOPY))
74673+ return csizep->cs_usercopycachep;
74674+#endif
74675+
74676 return csizep->cs_cachep;
74677 }
74678
74679@@ -1588,7 +1595,7 @@ void __init kmem_cache_init(void)
74680 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
74681 sizes[INDEX_AC].cs_size,
74682 ARCH_KMALLOC_MINALIGN,
74683- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74684+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74685 NULL);
74686
74687 if (INDEX_AC != INDEX_L3) {
74688@@ -1596,7 +1603,7 @@ void __init kmem_cache_init(void)
74689 kmem_cache_create(names[INDEX_L3].name,
74690 sizes[INDEX_L3].cs_size,
74691 ARCH_KMALLOC_MINALIGN,
74692- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74693+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74694 NULL);
74695 }
74696
74697@@ -1614,7 +1621,7 @@ void __init kmem_cache_init(void)
74698 sizes->cs_cachep = kmem_cache_create(names->name,
74699 sizes->cs_size,
74700 ARCH_KMALLOC_MINALIGN,
74701- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74702+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74703 NULL);
74704 }
74705 #ifdef CONFIG_ZONE_DMA
74706@@ -1626,6 +1633,16 @@ void __init kmem_cache_init(void)
74707 SLAB_PANIC,
74708 NULL);
74709 #endif
74710+
74711+#ifdef CONFIG_PAX_USERCOPY_SLABS
74712+ sizes->cs_usercopycachep = kmem_cache_create(
74713+ names->name_usercopy,
74714+ sizes->cs_size,
74715+ ARCH_KMALLOC_MINALIGN,
74716+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74717+ NULL);
74718+#endif
74719+
74720 sizes++;
74721 names++;
74722 }
74723@@ -4390,10 +4407,10 @@ static int s_show(struct seq_file *m, void *p)
74724 }
74725 /* cpu stats */
74726 {
74727- unsigned long allochit = atomic_read(&cachep->allochit);
74728- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74729- unsigned long freehit = atomic_read(&cachep->freehit);
74730- unsigned long freemiss = atomic_read(&cachep->freemiss);
74731+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74732+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74733+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74734+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74735
74736 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74737 allochit, allocmiss, freehit, freemiss);
74738@@ -4652,13 +4669,71 @@ static int __init slab_proc_init(void)
74739 {
74740 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74741 #ifdef CONFIG_DEBUG_SLAB_LEAK
74742- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74743+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74744 #endif
74745 return 0;
74746 }
74747 module_init(slab_proc_init);
74748 #endif
74749
74750+bool is_usercopy_object(const void *ptr)
74751+{
74752+ struct page *page;
74753+ struct kmem_cache *cachep;
74754+
74755+ if (ZERO_OR_NULL_PTR(ptr))
74756+ return false;
74757+
74758+ if (!slab_is_available())
74759+ return false;
74760+
74761+ if (!virt_addr_valid(ptr))
74762+ return false;
74763+
74764+ page = virt_to_head_page(ptr);
74765+
74766+ if (!PageSlab(page))
74767+ return false;
74768+
74769+ cachep = page_get_cache(page);
74770+ return cachep->flags & SLAB_USERCOPY;
74771+}
74772+
74773+#ifdef CONFIG_PAX_USERCOPY
74774+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74775+{
74776+ struct page *page;
74777+ struct kmem_cache *cachep;
74778+ struct slab *slabp;
74779+ unsigned int objnr;
74780+ unsigned long offset;
74781+
74782+ if (ZERO_OR_NULL_PTR(ptr))
74783+ return "<null>";
74784+
74785+ if (!virt_addr_valid(ptr))
74786+ return NULL;
74787+
74788+ page = virt_to_head_page(ptr);
74789+
74790+ if (!PageSlab(page))
74791+ return NULL;
74792+
74793+ cachep = page_get_cache(page);
74794+ if (!(cachep->flags & SLAB_USERCOPY))
74795+ return cachep->name;
74796+
74797+ slabp = page_get_slab(page);
74798+ objnr = obj_to_index(cachep, slabp, ptr);
74799+ BUG_ON(objnr >= cachep->num);
74800+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74801+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
74802+ return NULL;
74803+
74804+ return cachep->name;
74805+}
74806+#endif
74807+
74808 /**
74809 * ksize - get the actual amount of memory allocated for a given object
74810 * @objp: Pointer to the object
74811diff --git a/mm/slob.c b/mm/slob.c
74812index 8105be4..33e52d7 100644
74813--- a/mm/slob.c
74814+++ b/mm/slob.c
74815@@ -29,7 +29,7 @@
74816 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
74817 * alloc_pages() directly, allocating compound pages so the page order
74818 * does not have to be separately tracked, and also stores the exact
74819- * allocation size in page->private so that it can be used to accurately
74820+ * allocation size in slob_page->size so that it can be used to accurately
74821 * provide ksize(). These objects are detected in kfree() because slob_page()
74822 * is false for them.
74823 *
74824@@ -58,6 +58,7 @@
74825 */
74826
74827 #include <linux/kernel.h>
74828+#include <linux/sched.h>
74829 #include <linux/slab.h>
74830 #include <linux/mm.h>
74831 #include <linux/swap.h> /* struct reclaim_state */
74832@@ -100,9 +101,8 @@ struct slob_page {
74833 union {
74834 struct {
74835 unsigned long flags; /* mandatory */
74836- atomic_t _count; /* mandatory */
74837 slobidx_t units; /* free units left in page */
74838- unsigned long pad[2];
74839+ unsigned long size; /* size when >=PAGE_SIZE */
74840 slob_t *free; /* first free slob_t in page */
74841 struct list_head list; /* linked list of free pages */
74842 };
74843@@ -135,7 +135,7 @@ static LIST_HEAD(free_slob_large);
74844 */
74845 static inline int is_slob_page(struct slob_page *sp)
74846 {
74847- return PageSlab((struct page *)sp);
74848+ return PageSlab((struct page *)sp) && !sp->size;
74849 }
74850
74851 static inline void set_slob_page(struct slob_page *sp)
74852@@ -150,7 +150,7 @@ static inline void clear_slob_page(struct slob_page *sp)
74853
74854 static inline struct slob_page *slob_page(const void *addr)
74855 {
74856- return (struct slob_page *)virt_to_page(addr);
74857+ return (struct slob_page *)virt_to_head_page(addr);
74858 }
74859
74860 /*
74861@@ -210,7 +210,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74862 /*
74863 * Return the size of a slob block.
74864 */
74865-static slobidx_t slob_units(slob_t *s)
74866+static slobidx_t slob_units(const slob_t *s)
74867 {
74868 if (s->units > 0)
74869 return s->units;
74870@@ -220,7 +220,7 @@ static slobidx_t slob_units(slob_t *s)
74871 /*
74872 * Return the next free slob block pointer after this one.
74873 */
74874-static slob_t *slob_next(slob_t *s)
74875+static slob_t *slob_next(const slob_t *s)
74876 {
74877 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74878 slobidx_t next;
74879@@ -235,7 +235,7 @@ static slob_t *slob_next(slob_t *s)
74880 /*
74881 * Returns true if s is the last free block in its page.
74882 */
74883-static int slob_last(slob_t *s)
74884+static int slob_last(const slob_t *s)
74885 {
74886 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74887 }
74888@@ -254,6 +254,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74889 if (!page)
74890 return NULL;
74891
74892+ set_slob_page(page);
74893 return page_address(page);
74894 }
74895
74896@@ -370,11 +371,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74897 if (!b)
74898 return NULL;
74899 sp = slob_page(b);
74900- set_slob_page(sp);
74901
74902 spin_lock_irqsave(&slob_lock, flags);
74903 sp->units = SLOB_UNITS(PAGE_SIZE);
74904 sp->free = b;
74905+ sp->size = 0;
74906 INIT_LIST_HEAD(&sp->list);
74907 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74908 set_slob_page_free(sp, slob_list);
74909@@ -476,10 +477,9 @@ out:
74910 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74911 */
74912
74913-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74914+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74915 {
74916- unsigned int *m;
74917- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74918+ slob_t *m;
74919 void *ret;
74920
74921 gfp &= gfp_allowed_mask;
74922@@ -494,7 +494,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74923
74924 if (!m)
74925 return NULL;
74926- *m = size;
74927+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74928+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74929+ m[0].units = size;
74930+ m[1].units = align;
74931 ret = (void *)m + align;
74932
74933 trace_kmalloc_node(_RET_IP_, ret,
74934@@ -506,16 +509,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74935 gfp |= __GFP_COMP;
74936 ret = slob_new_pages(gfp, order, node);
74937 if (ret) {
74938- struct page *page;
74939- page = virt_to_page(ret);
74940- page->private = size;
74941+ struct slob_page *sp;
74942+ sp = slob_page(ret);
74943+ sp->size = size;
74944 }
74945
74946 trace_kmalloc_node(_RET_IP_, ret,
74947 size, PAGE_SIZE << order, gfp, node);
74948 }
74949
74950- kmemleak_alloc(ret, size, 1, gfp);
74951+ return ret;
74952+}
74953+
74954+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74955+{
74956+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74957+ void *ret = __kmalloc_node_align(size, gfp, node, align);
74958+
74959+ if (!ZERO_OR_NULL_PTR(ret))
74960+ kmemleak_alloc(ret, size, 1, gfp);
74961 return ret;
74962 }
74963 EXPORT_SYMBOL(__kmalloc_node);
74964@@ -533,13 +545,88 @@ void kfree(const void *block)
74965 sp = slob_page(block);
74966 if (is_slob_page(sp)) {
74967 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74968- unsigned int *m = (unsigned int *)(block - align);
74969- slob_free(m, *m + align);
74970- } else
74971+ slob_t *m = (slob_t *)(block - align);
74972+ slob_free(m, m[0].units + align);
74973+ } else {
74974+ clear_slob_page(sp);
74975+ free_slob_page(sp);
74976+ sp->size = 0;
74977 put_page(&sp->page);
74978+ }
74979 }
74980 EXPORT_SYMBOL(kfree);
74981
74982+bool is_usercopy_object(const void *ptr)
74983+{
74984+ if (!slab_is_available())
74985+ return false;
74986+
74987+ // PAX: TODO
74988+
74989+ return false;
74990+}
74991+
74992+#ifdef CONFIG_PAX_USERCOPY
74993+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74994+{
74995+ struct slob_page *sp;
74996+ const slob_t *free;
74997+ const void *base;
74998+ unsigned long flags;
74999+
75000+ if (ZERO_OR_NULL_PTR(ptr))
75001+ return "<null>";
75002+
75003+ if (!virt_addr_valid(ptr))
75004+ return NULL;
75005+
75006+ sp = slob_page(ptr);
75007+ if (!PageSlab((struct page *)sp))
75008+ return NULL;
75009+
75010+ if (sp->size) {
75011+ base = page_address(&sp->page);
75012+ if (base <= ptr && n <= sp->size - (ptr - base))
75013+ return NULL;
75014+ return "<slob>";
75015+ }
75016+
75017+ /* some tricky double walking to find the chunk */
75018+ spin_lock_irqsave(&slob_lock, flags);
75019+ base = (void *)((unsigned long)ptr & PAGE_MASK);
75020+ free = sp->free;
75021+
75022+ while ((void *)free <= ptr) {
75023+ base = free + slob_units(free);
75024+ free = slob_next(free);
75025+ }
75026+
75027+ while (base < (void *)free) {
75028+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75029+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
75030+ int offset;
75031+
75032+ if (ptr < base + align)
75033+ break;
75034+
75035+ offset = ptr - base - align;
75036+ if (offset >= m) {
75037+ base += size;
75038+ continue;
75039+ }
75040+
75041+ if (n > m - offset)
75042+ break;
75043+
75044+ spin_unlock_irqrestore(&slob_lock, flags);
75045+ return NULL;
75046+ }
75047+
75048+ spin_unlock_irqrestore(&slob_lock, flags);
75049+ return "<slob>";
75050+}
75051+#endif
75052+
75053 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75054 size_t ksize(const void *block)
75055 {
75056@@ -552,10 +639,10 @@ size_t ksize(const void *block)
75057 sp = slob_page(block);
75058 if (is_slob_page(sp)) {
75059 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75060- unsigned int *m = (unsigned int *)(block - align);
75061- return SLOB_UNITS(*m) * SLOB_UNIT;
75062+ slob_t *m = (slob_t *)(block - align);
75063+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75064 } else
75065- return sp->page.private;
75066+ return sp->size;
75067 }
75068 EXPORT_SYMBOL(ksize);
75069
75070@@ -571,8 +658,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
75071 {
75072 struct kmem_cache *c;
75073
75074+#ifdef CONFIG_PAX_USERCOPY_SLABS
75075+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
75076+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
75077+#else
75078 c = slob_alloc(sizeof(struct kmem_cache),
75079 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
75080+#endif
75081
75082 if (c) {
75083 c->name = name;
75084@@ -614,17 +706,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75085
75086 lockdep_trace_alloc(flags);
75087
75088+#ifdef CONFIG_PAX_USERCOPY_SLABS
75089+ b = __kmalloc_node_align(c->size, flags, node, c->align);
75090+#else
75091 if (c->size < PAGE_SIZE) {
75092 b = slob_alloc(c->size, flags, c->align, node);
75093 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75094 SLOB_UNITS(c->size) * SLOB_UNIT,
75095 flags, node);
75096 } else {
75097+ struct slob_page *sp;
75098+
75099 b = slob_new_pages(flags, get_order(c->size), node);
75100+ sp = slob_page(b);
75101+ sp->size = c->size;
75102 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75103 PAGE_SIZE << get_order(c->size),
75104 flags, node);
75105 }
75106+#endif
75107
75108 if (c->ctor)
75109 c->ctor(b);
75110@@ -636,10 +736,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75111
75112 static void __kmem_cache_free(void *b, int size)
75113 {
75114- if (size < PAGE_SIZE)
75115+ struct slob_page *sp = slob_page(b);
75116+
75117+ if (is_slob_page(sp))
75118 slob_free(b, size);
75119- else
75120+ else {
75121+ clear_slob_page(sp);
75122+ free_slob_page(sp);
75123+ sp->size = 0;
75124 slob_free_pages(b, get_order(size));
75125+ }
75126 }
75127
75128 static void kmem_rcu_free(struct rcu_head *head)
75129@@ -652,17 +758,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75130
75131 void kmem_cache_free(struct kmem_cache *c, void *b)
75132 {
75133+ int size = c->size;
75134+
75135+#ifdef CONFIG_PAX_USERCOPY_SLABS
75136+ if (size + c->align < PAGE_SIZE) {
75137+ size += c->align;
75138+ b -= c->align;
75139+ }
75140+#endif
75141+
75142 kmemleak_free_recursive(b, c->flags);
75143 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75144 struct slob_rcu *slob_rcu;
75145- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75146- slob_rcu->size = c->size;
75147+ slob_rcu = b + (size - sizeof(struct slob_rcu));
75148+ slob_rcu->size = size;
75149 call_rcu(&slob_rcu->head, kmem_rcu_free);
75150 } else {
75151- __kmem_cache_free(b, c->size);
75152+ __kmem_cache_free(b, size);
75153 }
75154
75155+#ifdef CONFIG_PAX_USERCOPY_SLABS
75156+ trace_kfree(_RET_IP_, b);
75157+#else
75158 trace_kmem_cache_free(_RET_IP_, b);
75159+#endif
75160+
75161 }
75162 EXPORT_SYMBOL(kmem_cache_free);
75163
75164diff --git a/mm/slub.c b/mm/slub.c
75165index 8c691fa..2993c2b 100644
75166--- a/mm/slub.c
75167+++ b/mm/slub.c
75168@@ -209,7 +209,7 @@ struct track {
75169
75170 enum track_item { TRACK_ALLOC, TRACK_FREE };
75171
75172-#ifdef CONFIG_SYSFS
75173+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75174 static int sysfs_slab_add(struct kmem_cache *);
75175 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75176 static void sysfs_slab_remove(struct kmem_cache *);
75177@@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
75178 if (!t->addr)
75179 return;
75180
75181- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75182+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75183 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75184 #ifdef CONFIG_STACKTRACE
75185 {
75186@@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75187
75188 page = virt_to_head_page(x);
75189
75190+ BUG_ON(!PageSlab(page));
75191+
75192 slab_free(s, page, x, _RET_IP_);
75193
75194 trace_kmem_cache_free(_RET_IP_, x);
75195@@ -2636,7 +2638,7 @@ static int slub_min_objects;
75196 * Merge control. If this is set then no merging of slab caches will occur.
75197 * (Could be removed. This was introduced to pacify the merge skeptics.)
75198 */
75199-static int slub_nomerge;
75200+static int slub_nomerge = 1;
75201
75202 /*
75203 * Calculate the order of allocation given an slab object size.
75204@@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75205 else
75206 s->cpu_partial = 30;
75207
75208- s->refcount = 1;
75209+ atomic_set(&s->refcount, 1);
75210 #ifdef CONFIG_NUMA
75211 s->remote_node_defrag_ratio = 1000;
75212 #endif
75213@@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75214 void kmem_cache_destroy(struct kmem_cache *s)
75215 {
75216 down_write(&slub_lock);
75217- s->refcount--;
75218- if (!s->refcount) {
75219+ if (atomic_dec_and_test(&s->refcount)) {
75220 list_del(&s->list);
75221 up_write(&slub_lock);
75222 if (kmem_cache_close(s)) {
75223@@ -3223,6 +3224,10 @@ static struct kmem_cache *kmem_cache;
75224 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75225 #endif
75226
75227+#ifdef CONFIG_PAX_USERCOPY_SLABS
75228+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75229+#endif
75230+
75231 static int __init setup_slub_min_order(char *str)
75232 {
75233 get_option(&str, &slub_min_order);
75234@@ -3337,6 +3342,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75235 return kmalloc_dma_caches[index];
75236
75237 #endif
75238+
75239+#ifdef CONFIG_PAX_USERCOPY_SLABS
75240+ if (flags & SLAB_USERCOPY)
75241+ return kmalloc_usercopy_caches[index];
75242+
75243+#endif
75244+
75245 return kmalloc_caches[index];
75246 }
75247
75248@@ -3405,6 +3417,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75249 EXPORT_SYMBOL(__kmalloc_node);
75250 #endif
75251
75252+bool is_usercopy_object(const void *ptr)
75253+{
75254+ struct page *page;
75255+ struct kmem_cache *s;
75256+
75257+ if (ZERO_OR_NULL_PTR(ptr))
75258+ return false;
75259+
75260+ if (!slab_is_available())
75261+ return false;
75262+
75263+ if (!virt_addr_valid(ptr))
75264+ return false;
75265+
75266+ page = virt_to_head_page(ptr);
75267+
75268+ if (!PageSlab(page))
75269+ return false;
75270+
75271+ s = page->slab;
75272+ return s->flags & SLAB_USERCOPY;
75273+}
75274+
75275+#ifdef CONFIG_PAX_USERCOPY
75276+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75277+{
75278+ struct page *page;
75279+ struct kmem_cache *s;
75280+ unsigned long offset;
75281+
75282+ if (ZERO_OR_NULL_PTR(ptr))
75283+ return "<null>";
75284+
75285+ if (!virt_addr_valid(ptr))
75286+ return NULL;
75287+
75288+ page = virt_to_head_page(ptr);
75289+
75290+ if (!PageSlab(page))
75291+ return NULL;
75292+
75293+ s = page->slab;
75294+ if (!(s->flags & SLAB_USERCOPY))
75295+ return s->name;
75296+
75297+ offset = (ptr - page_address(page)) % s->size;
75298+ if (offset <= s->objsize && n <= s->objsize - offset)
75299+ return NULL;
75300+
75301+ return s->name;
75302+}
75303+#endif
75304+
75305 size_t ksize(const void *object)
75306 {
75307 struct page *page;
75308@@ -3679,7 +3744,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75309 int node;
75310
75311 list_add(&s->list, &slab_caches);
75312- s->refcount = -1;
75313+ atomic_set(&s->refcount, -1);
75314
75315 for_each_node_state(node, N_NORMAL_MEMORY) {
75316 struct kmem_cache_node *n = get_node(s, node);
75317@@ -3799,17 +3864,17 @@ void __init kmem_cache_init(void)
75318
75319 /* Caches that are not of the two-to-the-power-of size */
75320 if (KMALLOC_MIN_SIZE <= 32) {
75321- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75322+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75323 caches++;
75324 }
75325
75326 if (KMALLOC_MIN_SIZE <= 64) {
75327- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75328+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75329 caches++;
75330 }
75331
75332 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75333- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75334+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75335 caches++;
75336 }
75337
75338@@ -3851,6 +3916,22 @@ void __init kmem_cache_init(void)
75339 }
75340 }
75341 #endif
75342+
75343+#ifdef CONFIG_PAX_USERCOPY_SLABS
75344+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75345+ struct kmem_cache *s = kmalloc_caches[i];
75346+
75347+ if (s && s->size) {
75348+ char *name = kasprintf(GFP_NOWAIT,
75349+ "usercopy-kmalloc-%d", s->objsize);
75350+
75351+ BUG_ON(!name);
75352+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75353+ s->objsize, SLAB_USERCOPY);
75354+ }
75355+ }
75356+#endif
75357+
75358 printk(KERN_INFO
75359 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75360 " CPUs=%d, Nodes=%d\n",
75361@@ -3877,7 +3958,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75362 /*
75363 * We may have set a slab to be unmergeable during bootstrap.
75364 */
75365- if (s->refcount < 0)
75366+ if (atomic_read(&s->refcount) < 0)
75367 return 1;
75368
75369 return 0;
75370@@ -3936,7 +4017,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
75371 down_write(&slub_lock);
75372 s = find_mergeable(size, align, flags, name, ctor);
75373 if (s) {
75374- s->refcount++;
75375+ atomic_inc(&s->refcount);
75376 /*
75377 * Adjust the object sizes so that we clear
75378 * the complete object on kzalloc.
75379@@ -3945,7 +4026,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
75380 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75381
75382 if (sysfs_slab_alias(s, name)) {
75383- s->refcount--;
75384+ atomic_dec(&s->refcount);
75385 goto err;
75386 }
75387 up_write(&slub_lock);
75388@@ -4074,7 +4155,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75389 }
75390 #endif
75391
75392-#ifdef CONFIG_SYSFS
75393+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75394 static int count_inuse(struct page *page)
75395 {
75396 return page->inuse;
75397@@ -4461,12 +4542,12 @@ static void resiliency_test(void)
75398 validate_slab_cache(kmalloc_caches[9]);
75399 }
75400 #else
75401-#ifdef CONFIG_SYSFS
75402+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75403 static void resiliency_test(void) {};
75404 #endif
75405 #endif
75406
75407-#ifdef CONFIG_SYSFS
75408+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75409 enum slab_stat_type {
75410 SL_ALL, /* All slabs */
75411 SL_PARTIAL, /* Only partially allocated slabs */
75412@@ -4709,7 +4790,7 @@ SLAB_ATTR_RO(ctor);
75413
75414 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75415 {
75416- return sprintf(buf, "%d\n", s->refcount - 1);
75417+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75418 }
75419 SLAB_ATTR_RO(aliases);
75420
75421@@ -5280,6 +5361,7 @@ static char *create_unique_id(struct kmem_cache *s)
75422 return name;
75423 }
75424
75425+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75426 static int sysfs_slab_add(struct kmem_cache *s)
75427 {
75428 int err;
75429@@ -5342,6 +5424,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75430 kobject_del(&s->kobj);
75431 kobject_put(&s->kobj);
75432 }
75433+#endif
75434
75435 /*
75436 * Need to buffer aliases during bootup until sysfs becomes
75437@@ -5355,6 +5438,7 @@ struct saved_alias {
75438
75439 static struct saved_alias *alias_list;
75440
75441+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75442 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75443 {
75444 struct saved_alias *al;
75445@@ -5377,6 +5461,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75446 alias_list = al;
75447 return 0;
75448 }
75449+#endif
75450
75451 static int __init slab_sysfs_init(void)
75452 {
75453diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75454index 1b7e22a..3fcd4f3 100644
75455--- a/mm/sparse-vmemmap.c
75456+++ b/mm/sparse-vmemmap.c
75457@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75458 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75459 if (!p)
75460 return NULL;
75461- pud_populate(&init_mm, pud, p);
75462+ pud_populate_kernel(&init_mm, pud, p);
75463 }
75464 return pud;
75465 }
75466@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75467 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75468 if (!p)
75469 return NULL;
75470- pgd_populate(&init_mm, pgd, p);
75471+ pgd_populate_kernel(&init_mm, pgd, p);
75472 }
75473 return pgd;
75474 }
75475diff --git a/mm/swap.c b/mm/swap.c
75476index 4e7e2ec..0c57830 100644
75477--- a/mm/swap.c
75478+++ b/mm/swap.c
75479@@ -30,6 +30,7 @@
75480 #include <linux/backing-dev.h>
75481 #include <linux/memcontrol.h>
75482 #include <linux/gfp.h>
75483+#include <linux/hugetlb.h>
75484
75485 #include "internal.h"
75486
75487@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75488
75489 __page_cache_release(page);
75490 dtor = get_compound_page_dtor(page);
75491+ if (!PageHuge(page))
75492+ BUG_ON(dtor != free_compound_page);
75493 (*dtor)(page);
75494 }
75495
75496diff --git a/mm/swapfile.c b/mm/swapfile.c
75497index 71373d0..11fa7d9 100644
75498--- a/mm/swapfile.c
75499+++ b/mm/swapfile.c
75500@@ -63,7 +63,7 @@ static DEFINE_MUTEX(swapon_mutex);
75501
75502 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75503 /* Activity counter to indicate that a swapon or swapoff has occurred */
75504-static atomic_t proc_poll_event = ATOMIC_INIT(0);
75505+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75506
75507 static inline unsigned char swap_count(unsigned char ent)
75508 {
75509@@ -1663,7 +1663,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75510 }
75511 filp_close(swap_file, NULL);
75512 err = 0;
75513- atomic_inc(&proc_poll_event);
75514+ atomic_inc_unchecked(&proc_poll_event);
75515 wake_up_interruptible(&proc_poll_wait);
75516
75517 out_dput:
75518@@ -1679,8 +1679,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75519
75520 poll_wait(file, &proc_poll_wait, wait);
75521
75522- if (seq->poll_event != atomic_read(&proc_poll_event)) {
75523- seq->poll_event = atomic_read(&proc_poll_event);
75524+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75525+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75526 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75527 }
75528
75529@@ -1778,7 +1778,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75530 return ret;
75531
75532 seq = file->private_data;
75533- seq->poll_event = atomic_read(&proc_poll_event);
75534+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75535 return 0;
75536 }
75537
75538@@ -2120,7 +2120,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75539 (frontswap_map) ? "FS" : "");
75540
75541 mutex_unlock(&swapon_mutex);
75542- atomic_inc(&proc_poll_event);
75543+ atomic_inc_unchecked(&proc_poll_event);
75544 wake_up_interruptible(&proc_poll_wait);
75545
75546 if (S_ISREG(inode->i_mode))
75547diff --git a/mm/util.c b/mm/util.c
75548index 8c7265a..c96d884 100644
75549--- a/mm/util.c
75550+++ b/mm/util.c
75551@@ -285,6 +285,12 @@ done:
75552 void arch_pick_mmap_layout(struct mm_struct *mm)
75553 {
75554 mm->mmap_base = TASK_UNMAPPED_BASE;
75555+
75556+#ifdef CONFIG_PAX_RANDMMAP
75557+ if (mm->pax_flags & MF_PAX_RANDMMAP)
75558+ mm->mmap_base += mm->delta_mmap;
75559+#endif
75560+
75561 mm->get_unmapped_area = arch_get_unmapped_area;
75562 mm->unmap_area = arch_unmap_area;
75563 }
75564diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75565index 2aad499..8aad8b1 100644
75566--- a/mm/vmalloc.c
75567+++ b/mm/vmalloc.c
75568@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75569
75570 pte = pte_offset_kernel(pmd, addr);
75571 do {
75572- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75573- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75574+
75575+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75576+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75577+ BUG_ON(!pte_exec(*pte));
75578+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75579+ continue;
75580+ }
75581+#endif
75582+
75583+ {
75584+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75585+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75586+ }
75587 } while (pte++, addr += PAGE_SIZE, addr != end);
75588 }
75589
75590@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75591 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75592 {
75593 pte_t *pte;
75594+ int ret = -ENOMEM;
75595
75596 /*
75597 * nr is a running index into the array which helps higher level
75598@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75599 pte = pte_alloc_kernel(pmd, addr);
75600 if (!pte)
75601 return -ENOMEM;
75602+
75603+ pax_open_kernel();
75604 do {
75605 struct page *page = pages[*nr];
75606
75607- if (WARN_ON(!pte_none(*pte)))
75608- return -EBUSY;
75609- if (WARN_ON(!page))
75610- return -ENOMEM;
75611+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75612+ if (pgprot_val(prot) & _PAGE_NX)
75613+#endif
75614+
75615+ if (WARN_ON(!pte_none(*pte))) {
75616+ ret = -EBUSY;
75617+ goto out;
75618+ }
75619+ if (WARN_ON(!page)) {
75620+ ret = -ENOMEM;
75621+ goto out;
75622+ }
75623 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75624 (*nr)++;
75625 } while (pte++, addr += PAGE_SIZE, addr != end);
75626- return 0;
75627+ ret = 0;
75628+out:
75629+ pax_close_kernel();
75630+ return ret;
75631 }
75632
75633 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75634@@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75635 pmd_t *pmd;
75636 unsigned long next;
75637
75638- pmd = pmd_alloc(&init_mm, pud, addr);
75639+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75640 if (!pmd)
75641 return -ENOMEM;
75642 do {
75643@@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75644 pud_t *pud;
75645 unsigned long next;
75646
75647- pud = pud_alloc(&init_mm, pgd, addr);
75648+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
75649 if (!pud)
75650 return -ENOMEM;
75651 do {
75652@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75653 * and fall back on vmalloc() if that fails. Others
75654 * just put it in the vmalloc space.
75655 */
75656-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75657+#ifdef CONFIG_MODULES
75658+#ifdef MODULES_VADDR
75659 unsigned long addr = (unsigned long)x;
75660 if (addr >= MODULES_VADDR && addr < MODULES_END)
75661 return 1;
75662 #endif
75663+
75664+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75665+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75666+ return 1;
75667+#endif
75668+
75669+#endif
75670+
75671 return is_vmalloc_addr(x);
75672 }
75673
75674@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75675
75676 if (!pgd_none(*pgd)) {
75677 pud_t *pud = pud_offset(pgd, addr);
75678+#ifdef CONFIG_X86
75679+ if (!pud_large(*pud))
75680+#endif
75681 if (!pud_none(*pud)) {
75682 pmd_t *pmd = pmd_offset(pud, addr);
75683+#ifdef CONFIG_X86
75684+ if (!pmd_large(*pmd))
75685+#endif
75686 if (!pmd_none(*pmd)) {
75687 pte_t *ptep, pte;
75688
75689@@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75690 * Allocate a region of KVA of the specified size and alignment, within the
75691 * vstart and vend.
75692 */
75693-static struct vmap_area *alloc_vmap_area(unsigned long size,
75694+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75695 unsigned long align,
75696 unsigned long vstart, unsigned long vend,
75697 int node, gfp_t gfp_mask)
75698@@ -1320,6 +1360,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75699 struct vm_struct *area;
75700
75701 BUG_ON(in_interrupt());
75702+
75703+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75704+ if (flags & VM_KERNEXEC) {
75705+ if (start != VMALLOC_START || end != VMALLOC_END)
75706+ return NULL;
75707+ start = (unsigned long)MODULES_EXEC_VADDR;
75708+ end = (unsigned long)MODULES_EXEC_END;
75709+ }
75710+#endif
75711+
75712 if (flags & VM_IOREMAP) {
75713 int bit = fls(size);
75714
75715@@ -1552,6 +1602,11 @@ void *vmap(struct page **pages, unsigned int count,
75716 if (count > totalram_pages)
75717 return NULL;
75718
75719+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75720+ if (!(pgprot_val(prot) & _PAGE_NX))
75721+ flags |= VM_KERNEXEC;
75722+#endif
75723+
75724 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75725 __builtin_return_address(0));
75726 if (!area)
75727@@ -1653,6 +1708,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75728 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75729 goto fail;
75730
75731+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75732+ if (!(pgprot_val(prot) & _PAGE_NX))
75733+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75734+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75735+ else
75736+#endif
75737+
75738 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75739 start, end, node, gfp_mask, caller);
75740 if (!area)
75741@@ -1826,10 +1888,9 @@ EXPORT_SYMBOL(vzalloc_node);
75742 * For tight control over page level allocator and protection flags
75743 * use __vmalloc() instead.
75744 */
75745-
75746 void *vmalloc_exec(unsigned long size)
75747 {
75748- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75749+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75750 -1, __builtin_return_address(0));
75751 }
75752
75753@@ -2124,6 +2185,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75754 unsigned long uaddr = vma->vm_start;
75755 unsigned long usize = vma->vm_end - vma->vm_start;
75756
75757+ BUG_ON(vma->vm_mirror);
75758+
75759 if ((PAGE_SIZE-1) & (unsigned long)addr)
75760 return -EINVAL;
75761
75762@@ -2560,7 +2623,7 @@ static int s_show(struct seq_file *m, void *p)
75763 {
75764 struct vm_struct *v = p;
75765
75766- seq_printf(m, "0x%p-0x%p %7ld",
75767+ seq_printf(m, "0x%pK-0x%pK %7ld",
75768 v->addr, v->addr + v->size, v->size);
75769
75770 if (v->caller)
75771diff --git a/mm/vmstat.c b/mm/vmstat.c
75772index 1bbbbd9..ff35669 100644
75773--- a/mm/vmstat.c
75774+++ b/mm/vmstat.c
75775@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75776 *
75777 * vm_stat contains the global counters
75778 */
75779-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75780+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75781 EXPORT_SYMBOL(vm_stat);
75782
75783 #ifdef CONFIG_SMP
75784@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75785 v = p->vm_stat_diff[i];
75786 p->vm_stat_diff[i] = 0;
75787 local_irq_restore(flags);
75788- atomic_long_add(v, &zone->vm_stat[i]);
75789+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75790 global_diff[i] += v;
75791 #ifdef CONFIG_NUMA
75792 /* 3 seconds idle till flush */
75793@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75794
75795 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75796 if (global_diff[i])
75797- atomic_long_add(global_diff[i], &vm_stat[i]);
75798+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75799 }
75800
75801 #endif
75802@@ -1211,10 +1211,20 @@ static int __init setup_vmstat(void)
75803 start_cpu_timer(cpu);
75804 #endif
75805 #ifdef CONFIG_PROC_FS
75806- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75807- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75808- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75809- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75810+ {
75811+ mode_t gr_mode = S_IRUGO;
75812+#ifdef CONFIG_GRKERNSEC_PROC_ADD
75813+ gr_mode = S_IRUSR;
75814+#endif
75815+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75816+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75817+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75818+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75819+#else
75820+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75821+#endif
75822+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75823+ }
75824 #endif
75825 return 0;
75826 }
75827diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75828index 9096bcb..43ed7bb 100644
75829--- a/net/8021q/vlan.c
75830+++ b/net/8021q/vlan.c
75831@@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75832 err = -EPERM;
75833 if (!capable(CAP_NET_ADMIN))
75834 break;
75835- if ((args.u.name_type >= 0) &&
75836- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75837+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75838 struct vlan_net *vn;
75839
75840 vn = net_generic(net, vlan_net_id);
75841diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75842index 6449bae..8c1f454 100644
75843--- a/net/9p/trans_fd.c
75844+++ b/net/9p/trans_fd.c
75845@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75846 oldfs = get_fs();
75847 set_fs(get_ds());
75848 /* The cast to a user pointer is valid due to the set_fs() */
75849- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75850+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75851 set_fs(oldfs);
75852
75853 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75854diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75855index 876fbe8..8bbea9f 100644
75856--- a/net/atm/atm_misc.c
75857+++ b/net/atm/atm_misc.c
75858@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75859 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75860 return 1;
75861 atm_return(vcc, truesize);
75862- atomic_inc(&vcc->stats->rx_drop);
75863+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75864 return 0;
75865 }
75866 EXPORT_SYMBOL(atm_charge);
75867@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75868 }
75869 }
75870 atm_return(vcc, guess);
75871- atomic_inc(&vcc->stats->rx_drop);
75872+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75873 return NULL;
75874 }
75875 EXPORT_SYMBOL(atm_alloc_charge);
75876@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75877
75878 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75879 {
75880-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75881+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75882 __SONET_ITEMS
75883 #undef __HANDLE_ITEM
75884 }
75885@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75886
75887 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75888 {
75889-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75890+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75891 __SONET_ITEMS
75892 #undef __HANDLE_ITEM
75893 }
75894diff --git a/net/atm/lec.h b/net/atm/lec.h
75895index a86aff9..3a0d6f6 100644
75896--- a/net/atm/lec.h
75897+++ b/net/atm/lec.h
75898@@ -48,7 +48,7 @@ struct lane2_ops {
75899 const u8 *tlvs, u32 sizeoftlvs);
75900 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75901 const u8 *tlvs, u32 sizeoftlvs);
75902-};
75903+} __no_const;
75904
75905 /*
75906 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75907diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75908index 0919a88..a23d54e 100644
75909--- a/net/atm/mpc.h
75910+++ b/net/atm/mpc.h
75911@@ -33,7 +33,7 @@ struct mpoa_client {
75912 struct mpc_parameters parameters; /* parameters for this client */
75913
75914 const struct net_device_ops *old_ops;
75915- struct net_device_ops new_ops;
75916+ net_device_ops_no_const new_ops;
75917 };
75918
75919
75920diff --git a/net/atm/proc.c b/net/atm/proc.c
75921index 0d020de..011c7bb 100644
75922--- a/net/atm/proc.c
75923+++ b/net/atm/proc.c
75924@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75925 const struct k_atm_aal_stats *stats)
75926 {
75927 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75928- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75929- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75930- atomic_read(&stats->rx_drop));
75931+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75932+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75933+ atomic_read_unchecked(&stats->rx_drop));
75934 }
75935
75936 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75937diff --git a/net/atm/resources.c b/net/atm/resources.c
75938index 23f45ce..c748f1a 100644
75939--- a/net/atm/resources.c
75940+++ b/net/atm/resources.c
75941@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75942 static void copy_aal_stats(struct k_atm_aal_stats *from,
75943 struct atm_aal_stats *to)
75944 {
75945-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75946+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75947 __AAL_STAT_ITEMS
75948 #undef __HANDLE_ITEM
75949 }
75950@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75951 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75952 struct atm_aal_stats *to)
75953 {
75954-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75955+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75956 __AAL_STAT_ITEMS
75957 #undef __HANDLE_ITEM
75958 }
75959diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75960index dc53798..dc66333 100644
75961--- a/net/batman-adv/bat_iv_ogm.c
75962+++ b/net/batman-adv/bat_iv_ogm.c
75963@@ -63,7 +63,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
75964
75965 /* randomize initial seqno to avoid collision */
75966 get_random_bytes(&random_seqno, sizeof(random_seqno));
75967- atomic_set(&hard_iface->seqno, random_seqno);
75968+ atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75969
75970 hard_iface->packet_len = BATMAN_OGM_HLEN;
75971 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75972@@ -572,7 +572,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75973
75974 /* change sequence number to network order */
75975 batman_ogm_packet->seqno =
75976- htonl((uint32_t)atomic_read(&hard_iface->seqno));
75977+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75978
75979 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75980 batman_ogm_packet->tt_crc = htons((uint16_t)
75981@@ -592,7 +592,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75982 else
75983 batman_ogm_packet->gw_flags = NO_FLAGS;
75984
75985- atomic_inc(&hard_iface->seqno);
75986+ atomic_inc_unchecked(&hard_iface->seqno);
75987
75988 slide_own_bcast_window(hard_iface);
75989 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
75990@@ -956,7 +956,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
75991 return;
75992
75993 /* could be changed by schedule_own_packet() */
75994- if_incoming_seqno = atomic_read(&if_incoming->seqno);
75995+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75996
75997 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
75998
75999diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76000index dc334fa..766a01a 100644
76001--- a/net/batman-adv/hard-interface.c
76002+++ b/net/batman-adv/hard-interface.c
76003@@ -321,7 +321,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
76004 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76005 dev_add_pack(&hard_iface->batman_adv_ptype);
76006
76007- atomic_set(&hard_iface->frag_seqno, 1);
76008+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76009 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
76010 hard_iface->net_dev->name);
76011
76012@@ -444,7 +444,7 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
76013 * This can't be called via a bat_priv callback because
76014 * we have no bat_priv yet.
76015 */
76016- atomic_set(&hard_iface->seqno, 1);
76017+ atomic_set_unchecked(&hard_iface->seqno, 1);
76018 hard_iface->packet_buff = NULL;
76019
76020 return hard_iface;
76021diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76022index a0ec0e4..7beb587 100644
76023--- a/net/batman-adv/soft-interface.c
76024+++ b/net/batman-adv/soft-interface.c
76025@@ -214,7 +214,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
76026
76027 /* set broadcast sequence number */
76028 bcast_packet->seqno =
76029- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
76030+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
76031
76032 add_bcast_packet_to_list(bat_priv, skb, 1);
76033
76034@@ -390,7 +390,7 @@ struct net_device *softif_create(const char *name)
76035 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
76036
76037 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
76038- atomic_set(&bat_priv->bcast_seqno, 1);
76039+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76040 atomic_set(&bat_priv->ttvn, 0);
76041 atomic_set(&bat_priv->tt_local_changes, 0);
76042 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
76043diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76044index 61308e8..2e142b2 100644
76045--- a/net/batman-adv/types.h
76046+++ b/net/batman-adv/types.h
76047@@ -38,8 +38,8 @@ struct hard_iface {
76048 int16_t if_num;
76049 char if_status;
76050 struct net_device *net_dev;
76051- atomic_t seqno;
76052- atomic_t frag_seqno;
76053+ atomic_unchecked_t seqno;
76054+ atomic_unchecked_t frag_seqno;
76055 unsigned char *packet_buff;
76056 int packet_len;
76057 struct kobject *hardif_obj;
76058@@ -163,7 +163,7 @@ struct bat_priv {
76059 atomic_t orig_interval; /* uint */
76060 atomic_t hop_penalty; /* uint */
76061 atomic_t log_level; /* uint */
76062- atomic_t bcast_seqno;
76063+ atomic_unchecked_t bcast_seqno;
76064 atomic_t bcast_queue_left;
76065 atomic_t batman_queue_left;
76066 atomic_t ttvn; /* translation table version number */
76067diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76068index 74175c2..32f8901 100644
76069--- a/net/batman-adv/unicast.c
76070+++ b/net/batman-adv/unicast.c
76071@@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
76072 frag1->flags = UNI_FRAG_HEAD | large_tail;
76073 frag2->flags = large_tail;
76074
76075- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76076+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76077 frag1->seqno = htons(seqno - 1);
76078 frag2->seqno = htons(seqno);
76079
76080diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76081index bedc768..a4a2b19 100644
76082--- a/net/bluetooth/hci_sock.c
76083+++ b/net/bluetooth/hci_sock.c
76084@@ -942,7 +942,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname, char
76085 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76086 }
76087
76088- len = min_t(unsigned int, len, sizeof(uf));
76089+ len = min((size_t)len, sizeof(uf));
76090 if (copy_from_user(&uf, optval, len)) {
76091 err = -EFAULT;
76092 break;
76093diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76094index 6204170..5ae8707 100644
76095--- a/net/bluetooth/l2cap_core.c
76096+++ b/net/bluetooth/l2cap_core.c
76097@@ -2800,8 +2800,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76098 break;
76099
76100 case L2CAP_CONF_RFC:
76101- if (olen == sizeof(rfc))
76102- memcpy(&rfc, (void *)val, olen);
76103+ if (olen != sizeof(rfc))
76104+ break;
76105+
76106+ memcpy(&rfc, (void *)val, olen);
76107
76108 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76109 rfc.mode != chan->mode)
76110diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76111index 9c94d44..831dc8e 100644
76112--- a/net/bluetooth/l2cap_sock.c
76113+++ b/net/bluetooth/l2cap_sock.c
76114@@ -452,7 +452,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76115 struct sock *sk = sock->sk;
76116 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76117 struct l2cap_options opts;
76118- int len, err = 0;
76119+ int err = 0;
76120+ size_t len = optlen;
76121 u32 opt;
76122
76123 BT_DBG("sk %p", sk);
76124@@ -474,7 +475,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76125 opts.max_tx = chan->max_tx;
76126 opts.txwin_size = chan->tx_win;
76127
76128- len = min_t(unsigned int, sizeof(opts), optlen);
76129+ len = min(sizeof(opts), len);
76130 if (copy_from_user((char *) &opts, optval, len)) {
76131 err = -EFAULT;
76132 break;
76133@@ -547,7 +548,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76134 struct bt_security sec;
76135 struct bt_power pwr;
76136 struct l2cap_conn *conn;
76137- int len, err = 0;
76138+ int err = 0;
76139+ size_t len = optlen;
76140 u32 opt;
76141
76142 BT_DBG("sk %p", sk);
76143@@ -570,7 +572,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76144
76145 sec.level = BT_SECURITY_LOW;
76146
76147- len = min_t(unsigned int, sizeof(sec), optlen);
76148+ len = min(sizeof(sec), len);
76149 if (copy_from_user((char *) &sec, optval, len)) {
76150 err = -EFAULT;
76151 break;
76152@@ -667,7 +669,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76153
76154 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76155
76156- len = min_t(unsigned int, sizeof(pwr), optlen);
76157+ len = min(sizeof(pwr), len);
76158 if (copy_from_user((char *) &pwr, optval, len)) {
76159 err = -EFAULT;
76160 break;
76161diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76162index 2df6956..4b24eef 100644
76163--- a/net/bluetooth/rfcomm/sock.c
76164+++ b/net/bluetooth/rfcomm/sock.c
76165@@ -686,7 +686,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76166 struct sock *sk = sock->sk;
76167 struct bt_security sec;
76168 int err = 0;
76169- size_t len;
76170+ size_t len = optlen;
76171 u32 opt;
76172
76173 BT_DBG("sk %p", sk);
76174@@ -708,7 +708,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76175
76176 sec.level = BT_SECURITY_LOW;
76177
76178- len = min_t(unsigned int, sizeof(sec), optlen);
76179+ len = min(sizeof(sec), len);
76180 if (copy_from_user((char *) &sec, optval, len)) {
76181 err = -EFAULT;
76182 break;
76183diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76184index 6435296..4f8c8f6 100644
76185--- a/net/bluetooth/rfcomm/tty.c
76186+++ b/net/bluetooth/rfcomm/tty.c
76187@@ -314,7 +314,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76188 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76189
76190 spin_lock_irqsave(&dev->port.lock, flags);
76191- if (dev->port.count > 0) {
76192+ if (atomic_read(&dev->port.count) > 0) {
76193 spin_unlock_irqrestore(&dev->port.lock, flags);
76194 return;
76195 }
76196@@ -669,10 +669,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76197 return -ENODEV;
76198
76199 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76200- dev->channel, dev->port.count);
76201+ dev->channel, atomic_read(&dev->port.count));
76202
76203 spin_lock_irqsave(&dev->port.lock, flags);
76204- if (++dev->port.count > 1) {
76205+ if (atomic_inc_return(&dev->port.count) > 1) {
76206 spin_unlock_irqrestore(&dev->port.lock, flags);
76207 return 0;
76208 }
76209@@ -737,10 +737,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76210 return;
76211
76212 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76213- dev->port.count);
76214+ atomic_read(&dev->port.count));
76215
76216 spin_lock_irqsave(&dev->port.lock, flags);
76217- if (!--dev->port.count) {
76218+ if (!atomic_dec_return(&dev->port.count)) {
76219 spin_unlock_irqrestore(&dev->port.lock, flags);
76220 if (dev->tty_dev->parent)
76221 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76222diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76223index 5fe2ff3..121d696 100644
76224--- a/net/bridge/netfilter/ebtables.c
76225+++ b/net/bridge/netfilter/ebtables.c
76226@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76227 tmp.valid_hooks = t->table->valid_hooks;
76228 }
76229 mutex_unlock(&ebt_mutex);
76230- if (copy_to_user(user, &tmp, *len) != 0){
76231+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76232 BUGPRINT("c2u Didn't work\n");
76233 ret = -EFAULT;
76234 break;
76235@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76236 goto out;
76237 tmp.valid_hooks = t->valid_hooks;
76238
76239- if (copy_to_user(user, &tmp, *len) != 0) {
76240+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76241 ret = -EFAULT;
76242 break;
76243 }
76244@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76245 tmp.entries_size = t->table->entries_size;
76246 tmp.valid_hooks = t->table->valid_hooks;
76247
76248- if (copy_to_user(user, &tmp, *len) != 0) {
76249+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76250 ret = -EFAULT;
76251 break;
76252 }
76253diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76254index 047cd0e..461fd28 100644
76255--- a/net/caif/cfctrl.c
76256+++ b/net/caif/cfctrl.c
76257@@ -10,6 +10,7 @@
76258 #include <linux/spinlock.h>
76259 #include <linux/slab.h>
76260 #include <linux/pkt_sched.h>
76261+#include <linux/sched.h>
76262 #include <net/caif/caif_layer.h>
76263 #include <net/caif/cfpkt.h>
76264 #include <net/caif/cfctrl.h>
76265@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76266 memset(&dev_info, 0, sizeof(dev_info));
76267 dev_info.id = 0xff;
76268 cfsrvl_init(&this->serv, 0, &dev_info, false);
76269- atomic_set(&this->req_seq_no, 1);
76270- atomic_set(&this->rsp_seq_no, 1);
76271+ atomic_set_unchecked(&this->req_seq_no, 1);
76272+ atomic_set_unchecked(&this->rsp_seq_no, 1);
76273 this->serv.layer.receive = cfctrl_recv;
76274 sprintf(this->serv.layer.name, "ctrl");
76275 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76276@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76277 struct cfctrl_request_info *req)
76278 {
76279 spin_lock_bh(&ctrl->info_list_lock);
76280- atomic_inc(&ctrl->req_seq_no);
76281- req->sequence_no = atomic_read(&ctrl->req_seq_no);
76282+ atomic_inc_unchecked(&ctrl->req_seq_no);
76283+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76284 list_add_tail(&req->list, &ctrl->list);
76285 spin_unlock_bh(&ctrl->info_list_lock);
76286 }
76287@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76288 if (p != first)
76289 pr_warn("Requests are not received in order\n");
76290
76291- atomic_set(&ctrl->rsp_seq_no,
76292+ atomic_set_unchecked(&ctrl->rsp_seq_no,
76293 p->sequence_no);
76294 list_del(&p->list);
76295 goto out;
76296diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
76297index 69771c0..e597733 100644
76298--- a/net/caif/chnl_net.c
76299+++ b/net/caif/chnl_net.c
76300@@ -94,6 +94,10 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
76301
76302 /* check the version of IP */
76303 ip_version = skb_header_pointer(skb, 0, 1, &buf);
76304+ if (!ip_version) {
76305+ kfree_skb(skb);
76306+ return -EINVAL;
76307+ }
76308
76309 switch (*ip_version >> 4) {
76310 case 4:
76311diff --git a/net/can/gw.c b/net/can/gw.c
76312index b41acf2..3affb3a 100644
76313--- a/net/can/gw.c
76314+++ b/net/can/gw.c
76315@@ -96,7 +96,7 @@ struct cf_mod {
76316 struct {
76317 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76318 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76319- } csumfunc;
76320+ } __no_const csumfunc;
76321 };
76322
76323
76324diff --git a/net/compat.c b/net/compat.c
76325index 74ed1d7..3695bd9 100644
76326--- a/net/compat.c
76327+++ b/net/compat.c
76328@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76329 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76330 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76331 return -EFAULT;
76332- kmsg->msg_name = compat_ptr(tmp1);
76333- kmsg->msg_iov = compat_ptr(tmp2);
76334- kmsg->msg_control = compat_ptr(tmp3);
76335+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76336+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76337+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76338 return 0;
76339 }
76340
76341@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76342
76343 if (kern_msg->msg_namelen) {
76344 if (mode == VERIFY_READ) {
76345- int err = move_addr_to_kernel(kern_msg->msg_name,
76346+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76347 kern_msg->msg_namelen,
76348 kern_address);
76349 if (err < 0)
76350@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76351 kern_msg->msg_name = NULL;
76352
76353 tot_len = iov_from_user_compat_to_kern(kern_iov,
76354- (struct compat_iovec __user *)kern_msg->msg_iov,
76355+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
76356 kern_msg->msg_iovlen);
76357 if (tot_len >= 0)
76358 kern_msg->msg_iov = kern_iov;
76359@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76360
76361 #define CMSG_COMPAT_FIRSTHDR(msg) \
76362 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76363- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76364+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76365 (struct compat_cmsghdr __user *)NULL)
76366
76367 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76368 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76369 (ucmlen) <= (unsigned long) \
76370 ((mhdr)->msg_controllen - \
76371- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76372+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76373
76374 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76375 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76376 {
76377 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76378- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76379+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76380 msg->msg_controllen)
76381 return NULL;
76382 return (struct compat_cmsghdr __user *)ptr;
76383@@ -219,7 +219,7 @@ Efault:
76384
76385 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76386 {
76387- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76388+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76389 struct compat_cmsghdr cmhdr;
76390 struct compat_timeval ctv;
76391 struct compat_timespec cts[3];
76392@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76393
76394 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76395 {
76396- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76397+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76398 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76399 int fdnum = scm->fp->count;
76400 struct file **fp = scm->fp->fp;
76401@@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76402 return -EFAULT;
76403 old_fs = get_fs();
76404 set_fs(KERNEL_DS);
76405- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76406+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76407 set_fs(old_fs);
76408
76409 return err;
76410@@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76411 len = sizeof(ktime);
76412 old_fs = get_fs();
76413 set_fs(KERNEL_DS);
76414- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76415+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76416 set_fs(old_fs);
76417
76418 if (!err) {
76419@@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76420 case MCAST_JOIN_GROUP:
76421 case MCAST_LEAVE_GROUP:
76422 {
76423- struct compat_group_req __user *gr32 = (void *)optval;
76424+ struct compat_group_req __user *gr32 = (void __user *)optval;
76425 struct group_req __user *kgr =
76426 compat_alloc_user_space(sizeof(struct group_req));
76427 u32 interface;
76428@@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76429 case MCAST_BLOCK_SOURCE:
76430 case MCAST_UNBLOCK_SOURCE:
76431 {
76432- struct compat_group_source_req __user *gsr32 = (void *)optval;
76433+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76434 struct group_source_req __user *kgsr = compat_alloc_user_space(
76435 sizeof(struct group_source_req));
76436 u32 interface;
76437@@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76438 }
76439 case MCAST_MSFILTER:
76440 {
76441- struct compat_group_filter __user *gf32 = (void *)optval;
76442+ struct compat_group_filter __user *gf32 = (void __user *)optval;
76443 struct group_filter __user *kgf;
76444 u32 interface, fmode, numsrc;
76445
76446@@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76447 char __user *optval, int __user *optlen,
76448 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76449 {
76450- struct compat_group_filter __user *gf32 = (void *)optval;
76451+ struct compat_group_filter __user *gf32 = (void __user *)optval;
76452 struct group_filter __user *kgf;
76453 int __user *koptlen;
76454 u32 interface, fmode, numsrc;
76455@@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76456
76457 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76458 return -EINVAL;
76459- if (copy_from_user(a, args, nas[call]))
76460+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76461 return -EFAULT;
76462 a0 = a[0];
76463 a1 = a[1];
76464diff --git a/net/core/datagram.c b/net/core/datagram.c
76465index ae6acf6..d5c8f66 100644
76466--- a/net/core/datagram.c
76467+++ b/net/core/datagram.c
76468@@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76469 }
76470
76471 kfree_skb(skb);
76472- atomic_inc(&sk->sk_drops);
76473+ atomic_inc_unchecked(&sk->sk_drops);
76474 sk_mem_reclaim_partial(sk);
76475
76476 return err;
76477diff --git a/net/core/dev.c b/net/core/dev.c
76478index e2215ee..b850ae4 100644
76479--- a/net/core/dev.c
76480+++ b/net/core/dev.c
76481@@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
76482 if (no_module && capable(CAP_NET_ADMIN))
76483 no_module = request_module("netdev-%s", name);
76484 if (no_module && capable(CAP_SYS_MODULE)) {
76485+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76486+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
76487+#else
76488 if (!request_module("%s", name))
76489 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76490 name);
76491+#endif
76492 }
76493 }
76494 EXPORT_SYMBOL(dev_load);
76495@@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76496 {
76497 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76498 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76499- atomic_long_inc(&dev->rx_dropped);
76500+ atomic_long_inc_unchecked(&dev->rx_dropped);
76501 kfree_skb(skb);
76502 return NET_RX_DROP;
76503 }
76504@@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76505 nf_reset(skb);
76506
76507 if (unlikely(!is_skb_forwardable(dev, skb))) {
76508- atomic_long_inc(&dev->rx_dropped);
76509+ atomic_long_inc_unchecked(&dev->rx_dropped);
76510 kfree_skb(skb);
76511 return NET_RX_DROP;
76512 }
76513@@ -2056,7 +2060,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76514
76515 struct dev_gso_cb {
76516 void (*destructor)(struct sk_buff *skb);
76517-};
76518+} __no_const;
76519
76520 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76521
76522@@ -2894,7 +2898,7 @@ enqueue:
76523
76524 local_irq_restore(flags);
76525
76526- atomic_long_inc(&skb->dev->rx_dropped);
76527+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76528 kfree_skb(skb);
76529 return NET_RX_DROP;
76530 }
76531@@ -2966,7 +2970,7 @@ int netif_rx_ni(struct sk_buff *skb)
76532 }
76533 EXPORT_SYMBOL(netif_rx_ni);
76534
76535-static void net_tx_action(struct softirq_action *h)
76536+static void net_tx_action(void)
76537 {
76538 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76539
76540@@ -3253,7 +3257,7 @@ ncls:
76541 if (pt_prev) {
76542 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76543 } else {
76544- atomic_long_inc(&skb->dev->rx_dropped);
76545+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76546 kfree_skb(skb);
76547 /* Jamal, now you will not able to escape explaining
76548 * me how you were going to use this. :-)
76549@@ -3818,7 +3822,7 @@ void netif_napi_del(struct napi_struct *napi)
76550 }
76551 EXPORT_SYMBOL(netif_napi_del);
76552
76553-static void net_rx_action(struct softirq_action *h)
76554+static void net_rx_action(void)
76555 {
76556 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76557 unsigned long time_limit = jiffies + 2;
76558@@ -4288,8 +4292,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76559 else
76560 seq_printf(seq, "%04x", ntohs(pt->type));
76561
76562+#ifdef CONFIG_GRKERNSEC_HIDESYM
76563+ seq_printf(seq, " %-8s %p\n",
76564+ pt->dev ? pt->dev->name : "", NULL);
76565+#else
76566 seq_printf(seq, " %-8s %pF\n",
76567 pt->dev ? pt->dev->name : "", pt->func);
76568+#endif
76569 }
76570
76571 return 0;
76572@@ -5841,7 +5850,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76573 } else {
76574 netdev_stats_to_stats64(storage, &dev->stats);
76575 }
76576- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76577+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76578 return storage;
76579 }
76580 EXPORT_SYMBOL(dev_get_stats);
76581diff --git a/net/core/flow.c b/net/core/flow.c
76582index e318c7e..168b1d0 100644
76583--- a/net/core/flow.c
76584+++ b/net/core/flow.c
76585@@ -61,7 +61,7 @@ struct flow_cache {
76586 struct timer_list rnd_timer;
76587 };
76588
76589-atomic_t flow_cache_genid = ATOMIC_INIT(0);
76590+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76591 EXPORT_SYMBOL(flow_cache_genid);
76592 static struct flow_cache flow_cache_global;
76593 static struct kmem_cache *flow_cachep __read_mostly;
76594@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76595
76596 static int flow_entry_valid(struct flow_cache_entry *fle)
76597 {
76598- if (atomic_read(&flow_cache_genid) != fle->genid)
76599+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76600 return 0;
76601 if (fle->object && !fle->object->ops->check(fle->object))
76602 return 0;
76603@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76604 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76605 fcp->hash_count++;
76606 }
76607- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76608+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76609 flo = fle->object;
76610 if (!flo)
76611 goto ret_object;
76612@@ -280,7 +280,7 @@ nocache:
76613 }
76614 flo = resolver(net, key, family, dir, flo, ctx);
76615 if (fle) {
76616- fle->genid = atomic_read(&flow_cache_genid);
76617+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
76618 if (!IS_ERR(flo))
76619 fle->object = flo;
76620 else
76621diff --git a/net/core/iovec.c b/net/core/iovec.c
76622index 7e7aeb0..2a998cb 100644
76623--- a/net/core/iovec.c
76624+++ b/net/core/iovec.c
76625@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76626 if (m->msg_namelen) {
76627 if (mode == VERIFY_READ) {
76628 void __user *namep;
76629- namep = (void __user __force *) m->msg_name;
76630+ namep = (void __force_user *) m->msg_name;
76631 err = move_addr_to_kernel(namep, m->msg_namelen,
76632 address);
76633 if (err < 0)
76634@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76635 }
76636
76637 size = m->msg_iovlen * sizeof(struct iovec);
76638- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76639+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76640 return -EFAULT;
76641
76642 m->msg_iov = iov;
76643diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76644index 6c50ac0..6b4c038 100644
76645--- a/net/core/rtnetlink.c
76646+++ b/net/core/rtnetlink.c
76647@@ -58,7 +58,7 @@ struct rtnl_link {
76648 rtnl_doit_func doit;
76649 rtnl_dumpit_func dumpit;
76650 rtnl_calcit_func calcit;
76651-};
76652+} __no_const;
76653
76654 static DEFINE_MUTEX(rtnl_mutex);
76655
76656diff --git a/net/core/scm.c b/net/core/scm.c
76657index 611c5ef..88f6d6d 100644
76658--- a/net/core/scm.c
76659+++ b/net/core/scm.c
76660@@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
76661 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76662 {
76663 struct cmsghdr __user *cm
76664- = (__force struct cmsghdr __user *)msg->msg_control;
76665+ = (struct cmsghdr __force_user *)msg->msg_control;
76666 struct cmsghdr cmhdr;
76667 int cmlen = CMSG_LEN(len);
76668 int err;
76669@@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76670 err = -EFAULT;
76671 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76672 goto out;
76673- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76674+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76675 goto out;
76676 cmlen = CMSG_SPACE(len);
76677 if (msg->msg_controllen < cmlen)
76678@@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
76679 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76680 {
76681 struct cmsghdr __user *cm
76682- = (__force struct cmsghdr __user*)msg->msg_control;
76683+ = (struct cmsghdr __force_user *)msg->msg_control;
76684
76685 int fdmax = 0;
76686 int fdnum = scm->fp->count;
76687@@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76688 if (fdnum < fdmax)
76689 fdmax = fdnum;
76690
76691- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76692+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76693 i++, cmfptr++)
76694 {
76695 int new_fd;
76696diff --git a/net/core/sock.c b/net/core/sock.c
76697index fcf8fdf..74437a5 100644
76698--- a/net/core/sock.c
76699+++ b/net/core/sock.c
76700@@ -344,7 +344,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76701 struct sk_buff_head *list = &sk->sk_receive_queue;
76702
76703 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76704- atomic_inc(&sk->sk_drops);
76705+ atomic_inc_unchecked(&sk->sk_drops);
76706 trace_sock_rcvqueue_full(sk, skb);
76707 return -ENOMEM;
76708 }
76709@@ -354,7 +354,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76710 return err;
76711
76712 if (!sk_rmem_schedule(sk, skb->truesize)) {
76713- atomic_inc(&sk->sk_drops);
76714+ atomic_inc_unchecked(&sk->sk_drops);
76715 return -ENOBUFS;
76716 }
76717
76718@@ -374,7 +374,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76719 skb_dst_force(skb);
76720
76721 spin_lock_irqsave(&list->lock, flags);
76722- skb->dropcount = atomic_read(&sk->sk_drops);
76723+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76724 __skb_queue_tail(list, skb);
76725 spin_unlock_irqrestore(&list->lock, flags);
76726
76727@@ -394,7 +394,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76728 skb->dev = NULL;
76729
76730 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76731- atomic_inc(&sk->sk_drops);
76732+ atomic_inc_unchecked(&sk->sk_drops);
76733 goto discard_and_relse;
76734 }
76735 if (nested)
76736@@ -412,7 +412,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76737 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76738 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76739 bh_unlock_sock(sk);
76740- atomic_inc(&sk->sk_drops);
76741+ atomic_inc_unchecked(&sk->sk_drops);
76742 goto discard_and_relse;
76743 }
76744
76745@@ -636,7 +636,8 @@ set_rcvbuf:
76746
76747 case SO_KEEPALIVE:
76748 #ifdef CONFIG_INET
76749- if (sk->sk_protocol == IPPROTO_TCP)
76750+ if (sk->sk_protocol == IPPROTO_TCP &&
76751+ sk->sk_type == SOCK_STREAM)
76752 tcp_set_keepalive(sk, valbool);
76753 #endif
76754 sock_valbool_flag(sk, SOCK_KEEPOPEN, valbool);
76755@@ -830,12 +831,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76756 struct timeval tm;
76757 } v;
76758
76759- int lv = sizeof(int);
76760- int len;
76761+ unsigned int lv = sizeof(int);
76762+ unsigned int len;
76763
76764 if (get_user(len, optlen))
76765 return -EFAULT;
76766- if (len < 0)
76767+ if (len > INT_MAX)
76768 return -EINVAL;
76769
76770 memset(&v, 0, sizeof(v));
76771@@ -976,18 +977,18 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76772 if (len > sizeof(peercred))
76773 len = sizeof(peercred);
76774 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
76775- if (copy_to_user(optval, &peercred, len))
76776+ if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
76777 return -EFAULT;
76778 goto lenout;
76779 }
76780
76781 case SO_PEERNAME:
76782 {
76783- char address[128];
76784+ char address[_K_SS_MAXSIZE];
76785
76786 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
76787 return -ENOTCONN;
76788- if (lv < len)
76789+ if (lv < len || sizeof address < len)
76790 return -EINVAL;
76791 if (copy_to_user(optval, address, len))
76792 return -EFAULT;
76793@@ -1035,7 +1036,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76794
76795 if (len > lv)
76796 len = lv;
76797- if (copy_to_user(optval, &v, len))
76798+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
76799 return -EFAULT;
76800 lenout:
76801 if (put_user(len, optlen))
76802@@ -2125,7 +2126,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76803 */
76804 smp_wmb();
76805 atomic_set(&sk->sk_refcnt, 1);
76806- atomic_set(&sk->sk_drops, 0);
76807+ atomic_set_unchecked(&sk->sk_drops, 0);
76808 }
76809 EXPORT_SYMBOL(sock_init_data);
76810
76811diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76812index 5fd1467..8b70900 100644
76813--- a/net/core/sock_diag.c
76814+++ b/net/core/sock_diag.c
76815@@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76816
76817 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76818 {
76819+#ifndef CONFIG_GRKERNSEC_HIDESYM
76820 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76821 cookie[1] != INET_DIAG_NOCOOKIE) &&
76822 ((u32)(unsigned long)sk != cookie[0] ||
76823 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76824 return -ESTALE;
76825 else
76826+#endif
76827 return 0;
76828 }
76829 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76830
76831 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76832 {
76833+#ifdef CONFIG_GRKERNSEC_HIDESYM
76834+ cookie[0] = 0;
76835+ cookie[1] = 0;
76836+#else
76837 cookie[0] = (u32)(unsigned long)sk;
76838 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76839+#endif
76840 }
76841 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76842
76843diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76844index a55eecc..dd8428c 100644
76845--- a/net/decnet/sysctl_net_decnet.c
76846+++ b/net/decnet/sysctl_net_decnet.c
76847@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76848
76849 if (len > *lenp) len = *lenp;
76850
76851- if (copy_to_user(buffer, addr, len))
76852+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
76853 return -EFAULT;
76854
76855 *lenp = len;
76856@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76857
76858 if (len > *lenp) len = *lenp;
76859
76860- if (copy_to_user(buffer, devname, len))
76861+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
76862 return -EFAULT;
76863
76864 *lenp = len;
76865diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76866index 3854411..2201a94 100644
76867--- a/net/ipv4/fib_frontend.c
76868+++ b/net/ipv4/fib_frontend.c
76869@@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76870 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76871 fib_sync_up(dev);
76872 #endif
76873- atomic_inc(&net->ipv4.dev_addr_genid);
76874+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76875 rt_cache_flush(dev_net(dev), -1);
76876 break;
76877 case NETDEV_DOWN:
76878 fib_del_ifaddr(ifa, NULL);
76879- atomic_inc(&net->ipv4.dev_addr_genid);
76880+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76881 if (ifa->ifa_dev->ifa_list == NULL) {
76882 /* Last address was deleted from this interface.
76883 * Disable IP.
76884@@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76885 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76886 fib_sync_up(dev);
76887 #endif
76888- atomic_inc(&net->ipv4.dev_addr_genid);
76889+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76890 rt_cache_flush(dev_net(dev), -1);
76891 break;
76892 case NETDEV_DOWN:
76893diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76894index e5b7182..570a90e 100644
76895--- a/net/ipv4/fib_semantics.c
76896+++ b/net/ipv4/fib_semantics.c
76897@@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76898 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76899 nh->nh_gw,
76900 nh->nh_parent->fib_scope);
76901- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76902+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76903
76904 return nh->nh_saddr;
76905 }
76906diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76907index 7880af9..70f92a3 100644
76908--- a/net/ipv4/inet_hashtables.c
76909+++ b/net/ipv4/inet_hashtables.c
76910@@ -18,12 +18,15 @@
76911 #include <linux/sched.h>
76912 #include <linux/slab.h>
76913 #include <linux/wait.h>
76914+#include <linux/security.h>
76915
76916 #include <net/inet_connection_sock.h>
76917 #include <net/inet_hashtables.h>
76918 #include <net/secure_seq.h>
76919 #include <net/ip.h>
76920
76921+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76922+
76923 /*
76924 * Allocate and initialize a new local port bind bucket.
76925 * The bindhash mutex for snum's hash chain must be held here.
76926@@ -530,6 +533,8 @@ ok:
76927 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76928 spin_unlock(&head->lock);
76929
76930+ gr_update_task_in_ip_table(current, inet_sk(sk));
76931+
76932 if (tw) {
76933 inet_twsk_deschedule(tw, death_row);
76934 while (twrefcnt) {
76935diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76936index dfba343..c827d50 100644
76937--- a/net/ipv4/inetpeer.c
76938+++ b/net/ipv4/inetpeer.c
76939@@ -487,8 +487,8 @@ relookup:
76940 if (p) {
76941 p->daddr = *daddr;
76942 atomic_set(&p->refcnt, 1);
76943- atomic_set(&p->rid, 0);
76944- atomic_set(&p->ip_id_count,
76945+ atomic_set_unchecked(&p->rid, 0);
76946+ atomic_set_unchecked(&p->ip_id_count,
76947 (daddr->family == AF_INET) ?
76948 secure_ip_id(daddr->addr.a4) :
76949 secure_ipv6_id(daddr->addr.a6));
76950diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76951index 9dbd3dd..0c59fb2 100644
76952--- a/net/ipv4/ip_fragment.c
76953+++ b/net/ipv4/ip_fragment.c
76954@@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76955 return 0;
76956
76957 start = qp->rid;
76958- end = atomic_inc_return(&peer->rid);
76959+ end = atomic_inc_return_unchecked(&peer->rid);
76960 qp->rid = end;
76961
76962 rc = qp->q.fragments && (end - start) > max;
76963diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76964index 0d11f23..2bb3f64 100644
76965--- a/net/ipv4/ip_sockglue.c
76966+++ b/net/ipv4/ip_sockglue.c
76967@@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76968 len = min_t(unsigned int, len, opt->optlen);
76969 if (put_user(len, optlen))
76970 return -EFAULT;
76971- if (copy_to_user(optval, opt->__data, len))
76972+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76973+ copy_to_user(optval, opt->__data, len))
76974 return -EFAULT;
76975 return 0;
76976 }
76977@@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76978 if (sk->sk_type != SOCK_STREAM)
76979 return -ENOPROTOOPT;
76980
76981- msg.msg_control = optval;
76982+ msg.msg_control = (void __force_kernel *)optval;
76983 msg.msg_controllen = len;
76984 msg.msg_flags = flags;
76985
76986diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76987index 67e8a6b..386764d 100644
76988--- a/net/ipv4/ipconfig.c
76989+++ b/net/ipv4/ipconfig.c
76990@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76991
76992 mm_segment_t oldfs = get_fs();
76993 set_fs(get_ds());
76994- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76995+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76996 set_fs(oldfs);
76997 return res;
76998 }
76999@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77000
77001 mm_segment_t oldfs = get_fs();
77002 set_fs(get_ds());
77003- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77004+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77005 set_fs(oldfs);
77006 return res;
77007 }
77008@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77009
77010 mm_segment_t oldfs = get_fs();
77011 set_fs(get_ds());
77012- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77013+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77014 set_fs(oldfs);
77015 return res;
77016 }
77017diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77018index 97e61ea..cac1bbb 100644
77019--- a/net/ipv4/netfilter/arp_tables.c
77020+++ b/net/ipv4/netfilter/arp_tables.c
77021@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77022 #endif
77023
77024 static int get_info(struct net *net, void __user *user,
77025- const int *len, int compat)
77026+ int len, int compat)
77027 {
77028 char name[XT_TABLE_MAXNAMELEN];
77029 struct xt_table *t;
77030 int ret;
77031
77032- if (*len != sizeof(struct arpt_getinfo)) {
77033- duprintf("length %u != %Zu\n", *len,
77034+ if (len != sizeof(struct arpt_getinfo)) {
77035+ duprintf("length %u != %Zu\n", len,
77036 sizeof(struct arpt_getinfo));
77037 return -EINVAL;
77038 }
77039@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77040 info.size = private->size;
77041 strcpy(info.name, name);
77042
77043- if (copy_to_user(user, &info, *len) != 0)
77044+ if (copy_to_user(user, &info, len) != 0)
77045 ret = -EFAULT;
77046 else
77047 ret = 0;
77048@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77049
77050 switch (cmd) {
77051 case ARPT_SO_GET_INFO:
77052- ret = get_info(sock_net(sk), user, len, 1);
77053+ ret = get_info(sock_net(sk), user, *len, 1);
77054 break;
77055 case ARPT_SO_GET_ENTRIES:
77056 ret = compat_get_entries(sock_net(sk), user, len);
77057@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77058
77059 switch (cmd) {
77060 case ARPT_SO_GET_INFO:
77061- ret = get_info(sock_net(sk), user, len, 0);
77062+ ret = get_info(sock_net(sk), user, *len, 0);
77063 break;
77064
77065 case ARPT_SO_GET_ENTRIES:
77066diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77067index 170b1fd..6105b91 100644
77068--- a/net/ipv4/netfilter/ip_tables.c
77069+++ b/net/ipv4/netfilter/ip_tables.c
77070@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77071 #endif
77072
77073 static int get_info(struct net *net, void __user *user,
77074- const int *len, int compat)
77075+ int len, int compat)
77076 {
77077 char name[XT_TABLE_MAXNAMELEN];
77078 struct xt_table *t;
77079 int ret;
77080
77081- if (*len != sizeof(struct ipt_getinfo)) {
77082- duprintf("length %u != %zu\n", *len,
77083+ if (len != sizeof(struct ipt_getinfo)) {
77084+ duprintf("length %u != %zu\n", len,
77085 sizeof(struct ipt_getinfo));
77086 return -EINVAL;
77087 }
77088@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77089 info.size = private->size;
77090 strcpy(info.name, name);
77091
77092- if (copy_to_user(user, &info, *len) != 0)
77093+ if (copy_to_user(user, &info, len) != 0)
77094 ret = -EFAULT;
77095 else
77096 ret = 0;
77097@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77098
77099 switch (cmd) {
77100 case IPT_SO_GET_INFO:
77101- ret = get_info(sock_net(sk), user, len, 1);
77102+ ret = get_info(sock_net(sk), user, *len, 1);
77103 break;
77104 case IPT_SO_GET_ENTRIES:
77105 ret = compat_get_entries(sock_net(sk), user, len);
77106@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77107
77108 switch (cmd) {
77109 case IPT_SO_GET_INFO:
77110- ret = get_info(sock_net(sk), user, len, 0);
77111+ ret = get_info(sock_net(sk), user, *len, 0);
77112 break;
77113
77114 case IPT_SO_GET_ENTRIES:
77115diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77116index 2c00e8b..45b3bdd 100644
77117--- a/net/ipv4/ping.c
77118+++ b/net/ipv4/ping.c
77119@@ -845,7 +845,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77120 sk_rmem_alloc_get(sp),
77121 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77122 atomic_read(&sp->sk_refcnt), sp,
77123- atomic_read(&sp->sk_drops), len);
77124+ atomic_read_unchecked(&sp->sk_drops), len);
77125 }
77126
77127 static int ping_seq_show(struct seq_file *seq, void *v)
77128diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77129index 4032b81..625143c 100644
77130--- a/net/ipv4/raw.c
77131+++ b/net/ipv4/raw.c
77132@@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77133 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77134 {
77135 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77136- atomic_inc(&sk->sk_drops);
77137+ atomic_inc_unchecked(&sk->sk_drops);
77138 kfree_skb(skb);
77139 return NET_RX_DROP;
77140 }
77141@@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
77142
77143 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77144 {
77145+ struct icmp_filter filter;
77146+
77147 if (optlen > sizeof(struct icmp_filter))
77148 optlen = sizeof(struct icmp_filter);
77149- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77150+ if (copy_from_user(&filter, optval, optlen))
77151 return -EFAULT;
77152+ raw_sk(sk)->filter = filter;
77153 return 0;
77154 }
77155
77156 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77157 {
77158 int len, ret = -EFAULT;
77159+ struct icmp_filter filter;
77160
77161 if (get_user(len, optlen))
77162 goto out;
77163@@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77164 if (len > sizeof(struct icmp_filter))
77165 len = sizeof(struct icmp_filter);
77166 ret = -EFAULT;
77167- if (put_user(len, optlen) ||
77168- copy_to_user(optval, &raw_sk(sk)->filter, len))
77169+ filter = raw_sk(sk)->filter;
77170+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77171 goto out;
77172 ret = 0;
77173 out: return ret;
77174@@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77175 sk_wmem_alloc_get(sp),
77176 sk_rmem_alloc_get(sp),
77177 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77178- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77179+ atomic_read(&sp->sk_refcnt),
77180+#ifdef CONFIG_GRKERNSEC_HIDESYM
77181+ NULL,
77182+#else
77183+ sp,
77184+#endif
77185+ atomic_read_unchecked(&sp->sk_drops));
77186 }
77187
77188 static int raw_seq_show(struct seq_file *seq, void *v)
77189diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77190index 98b30d0..cfa3cf7 100644
77191--- a/net/ipv4/route.c
77192+++ b/net/ipv4/route.c
77193@@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
77194
77195 static inline int rt_genid(struct net *net)
77196 {
77197- return atomic_read(&net->ipv4.rt_genid);
77198+ return atomic_read_unchecked(&net->ipv4.rt_genid);
77199 }
77200
77201 #ifdef CONFIG_PROC_FS
77202@@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
77203 unsigned char shuffle;
77204
77205 get_random_bytes(&shuffle, sizeof(shuffle));
77206- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
77207+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
77208 inetpeer_invalidate_tree(AF_INET);
77209 }
77210
77211@@ -3011,7 +3011,7 @@ static int rt_fill_info(struct net *net,
77212 error = rt->dst.error;
77213 if (peer) {
77214 inet_peer_refcheck(rt->peer);
77215- id = atomic_read(&peer->ip_id_count) & 0xffff;
77216+ id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
77217 if (peer->tcp_ts_stamp) {
77218 ts = peer->tcp_ts;
77219 tsage = get_seconds() - peer->tcp_ts_stamp;
77220diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77221index 262316b..5a9f3f3 100644
77222--- a/net/ipv4/tcp_input.c
77223+++ b/net/ipv4/tcp_input.c
77224@@ -4885,7 +4885,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77225 * simplifies code)
77226 */
77227 static void
77228-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77229+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77230 struct sk_buff *head, struct sk_buff *tail,
77231 u32 start, u32 end)
77232 {
77233diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77234index c8d28c4..e40f75a 100644
77235--- a/net/ipv4/tcp_ipv4.c
77236+++ b/net/ipv4/tcp_ipv4.c
77237@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77238 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77239
77240
77241+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77242+extern int grsec_enable_blackhole;
77243+#endif
77244+
77245 #ifdef CONFIG_TCP_MD5SIG
77246 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77247 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77248@@ -1656,6 +1660,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77249 return 0;
77250
77251 reset:
77252+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77253+ if (!grsec_enable_blackhole)
77254+#endif
77255 tcp_v4_send_reset(rsk, skb);
77256 discard:
77257 kfree_skb(skb);
77258@@ -1718,12 +1725,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77259 TCP_SKB_CB(skb)->sacked = 0;
77260
77261 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77262- if (!sk)
77263+ if (!sk) {
77264+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77265+ ret = 1;
77266+#endif
77267 goto no_tcp_socket;
77268-
77269+ }
77270 process:
77271- if (sk->sk_state == TCP_TIME_WAIT)
77272+ if (sk->sk_state == TCP_TIME_WAIT) {
77273+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77274+ ret = 2;
77275+#endif
77276 goto do_time_wait;
77277+ }
77278
77279 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77280 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77281@@ -1774,6 +1788,10 @@ no_tcp_socket:
77282 bad_packet:
77283 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77284 } else {
77285+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77286+ if (!grsec_enable_blackhole || (ret == 1 &&
77287+ (skb->dev->flags & IFF_LOOPBACK)))
77288+#endif
77289 tcp_v4_send_reset(NULL, skb);
77290 }
77291
77292@@ -2386,7 +2404,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77293 0, /* non standard timer */
77294 0, /* open_requests have no inode */
77295 atomic_read(&sk->sk_refcnt),
77296+#ifdef CONFIG_GRKERNSEC_HIDESYM
77297+ NULL,
77298+#else
77299 req,
77300+#endif
77301 len);
77302 }
77303
77304@@ -2436,7 +2458,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77305 sock_i_uid(sk),
77306 icsk->icsk_probes_out,
77307 sock_i_ino(sk),
77308- atomic_read(&sk->sk_refcnt), sk,
77309+ atomic_read(&sk->sk_refcnt),
77310+#ifdef CONFIG_GRKERNSEC_HIDESYM
77311+ NULL,
77312+#else
77313+ sk,
77314+#endif
77315 jiffies_to_clock_t(icsk->icsk_rto),
77316 jiffies_to_clock_t(icsk->icsk_ack.ato),
77317 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77318@@ -2464,7 +2491,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77319 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77320 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77321 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77322- atomic_read(&tw->tw_refcnt), tw, len);
77323+ atomic_read(&tw->tw_refcnt),
77324+#ifdef CONFIG_GRKERNSEC_HIDESYM
77325+ NULL,
77326+#else
77327+ tw,
77328+#endif
77329+ len);
77330 }
77331
77332 #define TMPSZ 150
77333diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77334index b85d9fe..4b0eed9 100644
77335--- a/net/ipv4/tcp_minisocks.c
77336+++ b/net/ipv4/tcp_minisocks.c
77337@@ -27,6 +27,10 @@
77338 #include <net/inet_common.h>
77339 #include <net/xfrm.h>
77340
77341+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77342+extern int grsec_enable_blackhole;
77343+#endif
77344+
77345 int sysctl_tcp_syncookies __read_mostly = 1;
77346 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77347
77348@@ -754,6 +758,10 @@ listen_overflow:
77349
77350 embryonic_reset:
77351 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77352+
77353+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77354+ if (!grsec_enable_blackhole)
77355+#endif
77356 if (!(flg & TCP_FLAG_RST))
77357 req->rsk_ops->send_reset(sk, skb);
77358
77359diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77360index 4526fe6..1a34e43 100644
77361--- a/net/ipv4/tcp_probe.c
77362+++ b/net/ipv4/tcp_probe.c
77363@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77364 if (cnt + width >= len)
77365 break;
77366
77367- if (copy_to_user(buf + cnt, tbuf, width))
77368+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77369 return -EFAULT;
77370 cnt += width;
77371 }
77372diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77373index e911e6c..d0a9356 100644
77374--- a/net/ipv4/tcp_timer.c
77375+++ b/net/ipv4/tcp_timer.c
77376@@ -22,6 +22,10 @@
77377 #include <linux/gfp.h>
77378 #include <net/tcp.h>
77379
77380+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77381+extern int grsec_lastack_retries;
77382+#endif
77383+
77384 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77385 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77386 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77387@@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
77388 }
77389 }
77390
77391+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77392+ if ((sk->sk_state == TCP_LAST_ACK) &&
77393+ (grsec_lastack_retries > 0) &&
77394+ (grsec_lastack_retries < retry_until))
77395+ retry_until = grsec_lastack_retries;
77396+#endif
77397+
77398 if (retransmits_timed_out(sk, retry_until,
77399 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77400 /* Has it gone just too far? */
77401diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77402index eaca736..60488ae 100644
77403--- a/net/ipv4/udp.c
77404+++ b/net/ipv4/udp.c
77405@@ -87,6 +87,7 @@
77406 #include <linux/types.h>
77407 #include <linux/fcntl.h>
77408 #include <linux/module.h>
77409+#include <linux/security.h>
77410 #include <linux/socket.h>
77411 #include <linux/sockios.h>
77412 #include <linux/igmp.h>
77413@@ -110,6 +111,10 @@
77414 #include <linux/static_key.h>
77415 #include "udp_impl.h"
77416
77417+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77418+extern int grsec_enable_blackhole;
77419+#endif
77420+
77421 struct udp_table udp_table __read_mostly;
77422 EXPORT_SYMBOL(udp_table);
77423
77424@@ -568,6 +573,9 @@ found:
77425 return s;
77426 }
77427
77428+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77429+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77430+
77431 /*
77432 * This routine is called by the ICMP module when it gets some
77433 * sort of error condition. If err < 0 then the socket should
77434@@ -859,9 +867,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77435 dport = usin->sin_port;
77436 if (dport == 0)
77437 return -EINVAL;
77438+
77439+ err = gr_search_udp_sendmsg(sk, usin);
77440+ if (err)
77441+ return err;
77442 } else {
77443 if (sk->sk_state != TCP_ESTABLISHED)
77444 return -EDESTADDRREQ;
77445+
77446+ err = gr_search_udp_sendmsg(sk, NULL);
77447+ if (err)
77448+ return err;
77449+
77450 daddr = inet->inet_daddr;
77451 dport = inet->inet_dport;
77452 /* Open fast path for connected socket.
77453@@ -1103,7 +1120,7 @@ static unsigned int first_packet_length(struct sock *sk)
77454 udp_lib_checksum_complete(skb)) {
77455 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77456 IS_UDPLITE(sk));
77457- atomic_inc(&sk->sk_drops);
77458+ atomic_inc_unchecked(&sk->sk_drops);
77459 __skb_unlink(skb, rcvq);
77460 __skb_queue_tail(&list_kill, skb);
77461 }
77462@@ -1189,6 +1206,10 @@ try_again:
77463 if (!skb)
77464 goto out;
77465
77466+ err = gr_search_udp_recvmsg(sk, skb);
77467+ if (err)
77468+ goto out_free;
77469+
77470 ulen = skb->len - sizeof(struct udphdr);
77471 copied = len;
77472 if (copied > ulen)
77473@@ -1498,7 +1519,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77474
77475 drop:
77476 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77477- atomic_inc(&sk->sk_drops);
77478+ atomic_inc_unchecked(&sk->sk_drops);
77479 kfree_skb(skb);
77480 return -1;
77481 }
77482@@ -1517,7 +1538,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77483 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77484
77485 if (!skb1) {
77486- atomic_inc(&sk->sk_drops);
77487+ atomic_inc_unchecked(&sk->sk_drops);
77488 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77489 IS_UDPLITE(sk));
77490 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77491@@ -1686,6 +1707,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77492 goto csum_error;
77493
77494 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77495+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77496+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77497+#endif
77498 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77499
77500 /*
77501@@ -2104,8 +2128,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77502 sk_wmem_alloc_get(sp),
77503 sk_rmem_alloc_get(sp),
77504 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77505- atomic_read(&sp->sk_refcnt), sp,
77506- atomic_read(&sp->sk_drops), len);
77507+ atomic_read(&sp->sk_refcnt),
77508+#ifdef CONFIG_GRKERNSEC_HIDESYM
77509+ NULL,
77510+#else
77511+ sp,
77512+#endif
77513+ atomic_read_unchecked(&sp->sk_drops), len);
77514 }
77515
77516 int udp4_seq_show(struct seq_file *seq, void *v)
77517diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77518index 938ba6d..30c8021 100644
77519--- a/net/ipv6/addrconf.c
77520+++ b/net/ipv6/addrconf.c
77521@@ -2143,7 +2143,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77522 p.iph.ihl = 5;
77523 p.iph.protocol = IPPROTO_IPV6;
77524 p.iph.ttl = 64;
77525- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77526+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77527
77528 if (ops->ndo_do_ioctl) {
77529 mm_segment_t oldfs = get_fs();
77530diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
77531index db1521f..ebb3314 100644
77532--- a/net/ipv6/esp6.c
77533+++ b/net/ipv6/esp6.c
77534@@ -166,8 +166,6 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
77535 struct esp_data *esp = x->data;
77536
77537 /* skb is pure payload to encrypt */
77538- err = -ENOMEM;
77539-
77540 aead = esp->aead;
77541 alen = crypto_aead_authsize(aead);
77542
77543@@ -202,8 +200,10 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
77544 }
77545
77546 tmp = esp_alloc_tmp(aead, nfrags + sglists, seqhilen);
77547- if (!tmp)
77548+ if (!tmp) {
77549+ err = -ENOMEM;
77550 goto error;
77551+ }
77552
77553 seqhi = esp_tmp_seqhi(tmp);
77554 iv = esp_tmp_iv(aead, tmp, seqhilen);
77555diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
77556index e6cee52..cf47476 100644
77557--- a/net/ipv6/inet6_connection_sock.c
77558+++ b/net/ipv6/inet6_connection_sock.c
77559@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
77560 #ifdef CONFIG_XFRM
77561 {
77562 struct rt6_info *rt = (struct rt6_info *)dst;
77563- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
77564+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
77565 }
77566 #endif
77567 }
77568@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
77569 #ifdef CONFIG_XFRM
77570 if (dst) {
77571 struct rt6_info *rt = (struct rt6_info *)dst;
77572- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
77573+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
77574 __sk_dst_reset(sk);
77575 dst = NULL;
77576 }
77577diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77578index ba6d13d..6899122 100644
77579--- a/net/ipv6/ipv6_sockglue.c
77580+++ b/net/ipv6/ipv6_sockglue.c
77581@@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77582 if (sk->sk_type != SOCK_STREAM)
77583 return -ENOPROTOOPT;
77584
77585- msg.msg_control = optval;
77586+ msg.msg_control = (void __force_kernel *)optval;
77587 msg.msg_controllen = len;
77588 msg.msg_flags = flags;
77589
77590diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77591index d7cb045..8c0ded6 100644
77592--- a/net/ipv6/netfilter/ip6_tables.c
77593+++ b/net/ipv6/netfilter/ip6_tables.c
77594@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77595 #endif
77596
77597 static int get_info(struct net *net, void __user *user,
77598- const int *len, int compat)
77599+ int len, int compat)
77600 {
77601 char name[XT_TABLE_MAXNAMELEN];
77602 struct xt_table *t;
77603 int ret;
77604
77605- if (*len != sizeof(struct ip6t_getinfo)) {
77606- duprintf("length %u != %zu\n", *len,
77607+ if (len != sizeof(struct ip6t_getinfo)) {
77608+ duprintf("length %u != %zu\n", len,
77609 sizeof(struct ip6t_getinfo));
77610 return -EINVAL;
77611 }
77612@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77613 info.size = private->size;
77614 strcpy(info.name, name);
77615
77616- if (copy_to_user(user, &info, *len) != 0)
77617+ if (copy_to_user(user, &info, len) != 0)
77618 ret = -EFAULT;
77619 else
77620 ret = 0;
77621@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77622
77623 switch (cmd) {
77624 case IP6T_SO_GET_INFO:
77625- ret = get_info(sock_net(sk), user, len, 1);
77626+ ret = get_info(sock_net(sk), user, *len, 1);
77627 break;
77628 case IP6T_SO_GET_ENTRIES:
77629 ret = compat_get_entries(sock_net(sk), user, len);
77630@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77631
77632 switch (cmd) {
77633 case IP6T_SO_GET_INFO:
77634- ret = get_info(sock_net(sk), user, len, 0);
77635+ ret = get_info(sock_net(sk), user, *len, 0);
77636 break;
77637
77638 case IP6T_SO_GET_ENTRIES:
77639diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77640index 93d6983..8e54c4d 100644
77641--- a/net/ipv6/raw.c
77642+++ b/net/ipv6/raw.c
77643@@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77644 {
77645 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77646 skb_checksum_complete(skb)) {
77647- atomic_inc(&sk->sk_drops);
77648+ atomic_inc_unchecked(&sk->sk_drops);
77649 kfree_skb(skb);
77650 return NET_RX_DROP;
77651 }
77652@@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77653 struct raw6_sock *rp = raw6_sk(sk);
77654
77655 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77656- atomic_inc(&sk->sk_drops);
77657+ atomic_inc_unchecked(&sk->sk_drops);
77658 kfree_skb(skb);
77659 return NET_RX_DROP;
77660 }
77661@@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77662
77663 if (inet->hdrincl) {
77664 if (skb_checksum_complete(skb)) {
77665- atomic_inc(&sk->sk_drops);
77666+ atomic_inc_unchecked(&sk->sk_drops);
77667 kfree_skb(skb);
77668 return NET_RX_DROP;
77669 }
77670@@ -602,7 +602,7 @@ out:
77671 return err;
77672 }
77673
77674-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77675+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77676 struct flowi6 *fl6, struct dst_entry **dstp,
77677 unsigned int flags)
77678 {
77679@@ -914,12 +914,15 @@ do_confirm:
77680 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77681 char __user *optval, int optlen)
77682 {
77683+ struct icmp6_filter filter;
77684+
77685 switch (optname) {
77686 case ICMPV6_FILTER:
77687 if (optlen > sizeof(struct icmp6_filter))
77688 optlen = sizeof(struct icmp6_filter);
77689- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77690+ if (copy_from_user(&filter, optval, optlen))
77691 return -EFAULT;
77692+ raw6_sk(sk)->filter = filter;
77693 return 0;
77694 default:
77695 return -ENOPROTOOPT;
77696@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77697 char __user *optval, int __user *optlen)
77698 {
77699 int len;
77700+ struct icmp6_filter filter;
77701
77702 switch (optname) {
77703 case ICMPV6_FILTER:
77704@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77705 len = sizeof(struct icmp6_filter);
77706 if (put_user(len, optlen))
77707 return -EFAULT;
77708- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77709+ filter = raw6_sk(sk)->filter;
77710+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
77711 return -EFAULT;
77712 return 0;
77713 default:
77714@@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77715 0, 0L, 0,
77716 sock_i_uid(sp), 0,
77717 sock_i_ino(sp),
77718- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77719+ atomic_read(&sp->sk_refcnt),
77720+#ifdef CONFIG_GRKERNSEC_HIDESYM
77721+ NULL,
77722+#else
77723+ sp,
77724+#endif
77725+ atomic_read_unchecked(&sp->sk_drops));
77726 }
77727
77728 static int raw6_seq_show(struct seq_file *seq, void *v)
77729diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
77730index 9df64a5..39875da 100644
77731--- a/net/ipv6/tcp_ipv6.c
77732+++ b/net/ipv6/tcp_ipv6.c
77733@@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
77734 }
77735 #endif
77736
77737+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77738+extern int grsec_enable_blackhole;
77739+#endif
77740+
77741 static void tcp_v6_hash(struct sock *sk)
77742 {
77743 if (sk->sk_state != TCP_CLOSE) {
77744@@ -1544,6 +1548,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
77745 return 0;
77746
77747 reset:
77748+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77749+ if (!grsec_enable_blackhole)
77750+#endif
77751 tcp_v6_send_reset(sk, skb);
77752 discard:
77753 if (opt_skb)
77754@@ -1625,12 +1632,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
77755 TCP_SKB_CB(skb)->sacked = 0;
77756
77757 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77758- if (!sk)
77759+ if (!sk) {
77760+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77761+ ret = 1;
77762+#endif
77763 goto no_tcp_socket;
77764+ }
77765
77766 process:
77767- if (sk->sk_state == TCP_TIME_WAIT)
77768+ if (sk->sk_state == TCP_TIME_WAIT) {
77769+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77770+ ret = 2;
77771+#endif
77772 goto do_time_wait;
77773+ }
77774
77775 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77776 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77777@@ -1679,6 +1694,10 @@ no_tcp_socket:
77778 bad_packet:
77779 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77780 } else {
77781+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77782+ if (!grsec_enable_blackhole || (ret == 1 &&
77783+ (skb->dev->flags & IFF_LOOPBACK)))
77784+#endif
77785 tcp_v6_send_reset(NULL, skb);
77786 }
77787
77788@@ -1885,7 +1904,13 @@ static void get_openreq6(struct seq_file *seq,
77789 uid,
77790 0, /* non standard timer */
77791 0, /* open_requests have no inode */
77792- 0, req);
77793+ 0,
77794+#ifdef CONFIG_GRKERNSEC_HIDESYM
77795+ NULL
77796+#else
77797+ req
77798+#endif
77799+ );
77800 }
77801
77802 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77803@@ -1935,7 +1960,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77804 sock_i_uid(sp),
77805 icsk->icsk_probes_out,
77806 sock_i_ino(sp),
77807- atomic_read(&sp->sk_refcnt), sp,
77808+ atomic_read(&sp->sk_refcnt),
77809+#ifdef CONFIG_GRKERNSEC_HIDESYM
77810+ NULL,
77811+#else
77812+ sp,
77813+#endif
77814 jiffies_to_clock_t(icsk->icsk_rto),
77815 jiffies_to_clock_t(icsk->icsk_ack.ato),
77816 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77817@@ -1970,7 +2000,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77818 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77819 tw->tw_substate, 0, 0,
77820 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77821- atomic_read(&tw->tw_refcnt), tw);
77822+ atomic_read(&tw->tw_refcnt),
77823+#ifdef CONFIG_GRKERNSEC_HIDESYM
77824+ NULL
77825+#else
77826+ tw
77827+#endif
77828+ );
77829 }
77830
77831 static int tcp6_seq_show(struct seq_file *seq, void *v)
77832diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77833index f05099f..ea613f0 100644
77834--- a/net/ipv6/udp.c
77835+++ b/net/ipv6/udp.c
77836@@ -50,6 +50,10 @@
77837 #include <linux/seq_file.h>
77838 #include "udp_impl.h"
77839
77840+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77841+extern int grsec_enable_blackhole;
77842+#endif
77843+
77844 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77845 {
77846 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77847@@ -615,7 +619,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77848 return rc;
77849 drop:
77850 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77851- atomic_inc(&sk->sk_drops);
77852+ atomic_inc_unchecked(&sk->sk_drops);
77853 kfree_skb(skb);
77854 return -1;
77855 }
77856@@ -673,7 +677,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77857 if (likely(skb1 == NULL))
77858 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77859 if (!skb1) {
77860- atomic_inc(&sk->sk_drops);
77861+ atomic_inc_unchecked(&sk->sk_drops);
77862 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77863 IS_UDPLITE(sk));
77864 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77865@@ -844,6 +848,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77866 goto discard;
77867
77868 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77869+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77870+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77871+#endif
77872 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77873
77874 kfree_skb(skb);
77875@@ -1453,8 +1460,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77876 0, 0L, 0,
77877 sock_i_uid(sp), 0,
77878 sock_i_ino(sp),
77879- atomic_read(&sp->sk_refcnt), sp,
77880- atomic_read(&sp->sk_drops));
77881+ atomic_read(&sp->sk_refcnt),
77882+#ifdef CONFIG_GRKERNSEC_HIDESYM
77883+ NULL,
77884+#else
77885+ sp,
77886+#endif
77887+ atomic_read_unchecked(&sp->sk_drops));
77888 }
77889
77890 int udp6_seq_show(struct seq_file *seq, void *v)
77891diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77892index 6b9d5a0..4dffaf1 100644
77893--- a/net/irda/ircomm/ircomm_tty.c
77894+++ b/net/irda/ircomm/ircomm_tty.c
77895@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77896 add_wait_queue(&self->open_wait, &wait);
77897
77898 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77899- __FILE__,__LINE__, tty->driver->name, self->open_count );
77900+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77901
77902 /* As far as I can see, we protect open_count - Jean II */
77903 spin_lock_irqsave(&self->spinlock, flags);
77904 if (!tty_hung_up_p(filp)) {
77905 extra_count = 1;
77906- self->open_count--;
77907+ local_dec(&self->open_count);
77908 }
77909 spin_unlock_irqrestore(&self->spinlock, flags);
77910- self->blocked_open++;
77911+ local_inc(&self->blocked_open);
77912
77913 while (1) {
77914 if (tty->termios->c_cflag & CBAUD) {
77915@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77916 }
77917
77918 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77919- __FILE__,__LINE__, tty->driver->name, self->open_count );
77920+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77921
77922 schedule();
77923 }
77924@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77925 if (extra_count) {
77926 /* ++ is not atomic, so this should be protected - Jean II */
77927 spin_lock_irqsave(&self->spinlock, flags);
77928- self->open_count++;
77929+ local_inc(&self->open_count);
77930 spin_unlock_irqrestore(&self->spinlock, flags);
77931 }
77932- self->blocked_open--;
77933+ local_dec(&self->blocked_open);
77934
77935 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77936- __FILE__,__LINE__, tty->driver->name, self->open_count);
77937+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77938
77939 if (!retval)
77940 self->flags |= ASYNC_NORMAL_ACTIVE;
77941@@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
77942 }
77943 /* ++ is not atomic, so this should be protected - Jean II */
77944 spin_lock_irqsave(&self->spinlock, flags);
77945- self->open_count++;
77946+ local_inc(&self->open_count);
77947
77948 tty->driver_data = self;
77949 self->tty = tty;
77950 spin_unlock_irqrestore(&self->spinlock, flags);
77951
77952 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77953- self->line, self->open_count);
77954+ self->line, local_read(&self->open_count));
77955
77956 /* Not really used by us, but lets do it anyway */
77957 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77958@@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77959 return;
77960 }
77961
77962- if ((tty->count == 1) && (self->open_count != 1)) {
77963+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77964 /*
77965 * Uh, oh. tty->count is 1, which means that the tty
77966 * structure will be freed. state->count should always
77967@@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77968 */
77969 IRDA_DEBUG(0, "%s(), bad serial port count; "
77970 "tty->count is 1, state->count is %d\n", __func__ ,
77971- self->open_count);
77972- self->open_count = 1;
77973+ local_read(&self->open_count));
77974+ local_set(&self->open_count, 1);
77975 }
77976
77977- if (--self->open_count < 0) {
77978+ if (local_dec_return(&self->open_count) < 0) {
77979 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77980- __func__, self->line, self->open_count);
77981- self->open_count = 0;
77982+ __func__, self->line, local_read(&self->open_count));
77983+ local_set(&self->open_count, 0);
77984 }
77985- if (self->open_count) {
77986+ if (local_read(&self->open_count)) {
77987 spin_unlock_irqrestore(&self->spinlock, flags);
77988
77989 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77990@@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77991 tty->closing = 0;
77992 self->tty = NULL;
77993
77994- if (self->blocked_open) {
77995+ if (local_read(&self->blocked_open)) {
77996 if (self->close_delay)
77997 schedule_timeout_interruptible(self->close_delay);
77998 wake_up_interruptible(&self->open_wait);
77999@@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78000 spin_lock_irqsave(&self->spinlock, flags);
78001 self->flags &= ~ASYNC_NORMAL_ACTIVE;
78002 self->tty = NULL;
78003- self->open_count = 0;
78004+ local_set(&self->open_count, 0);
78005 spin_unlock_irqrestore(&self->spinlock, flags);
78006
78007 wake_up_interruptible(&self->open_wait);
78008@@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78009 seq_putc(m, '\n');
78010
78011 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78012- seq_printf(m, "Open count: %d\n", self->open_count);
78013+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
78014 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78015 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78016
78017diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78018index cd6f7a9..e63fe89 100644
78019--- a/net/iucv/af_iucv.c
78020+++ b/net/iucv/af_iucv.c
78021@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78022
78023 write_lock_bh(&iucv_sk_list.lock);
78024
78025- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78026+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78027 while (__iucv_get_sock_by_name(name)) {
78028 sprintf(name, "%08x",
78029- atomic_inc_return(&iucv_sk_list.autobind_name));
78030+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78031 }
78032
78033 write_unlock_bh(&iucv_sk_list.lock);
78034diff --git a/net/key/af_key.c b/net/key/af_key.c
78035index 34e4185..8823368 100644
78036--- a/net/key/af_key.c
78037+++ b/net/key/af_key.c
78038@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78039 static u32 get_acqseq(void)
78040 {
78041 u32 res;
78042- static atomic_t acqseq;
78043+ static atomic_unchecked_t acqseq;
78044
78045 do {
78046- res = atomic_inc_return(&acqseq);
78047+ res = atomic_inc_return_unchecked(&acqseq);
78048 } while (!res);
78049 return res;
78050 }
78051diff --git a/net/l2tp/l2tp_netlink.c b/net/l2tp/l2tp_netlink.c
78052index ddc553e..1937a14 100644
78053--- a/net/l2tp/l2tp_netlink.c
78054+++ b/net/l2tp/l2tp_netlink.c
78055@@ -80,8 +80,8 @@ static int l2tp_nl_cmd_noop(struct sk_buff *skb, struct genl_info *info)
78056
78057 hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
78058 &l2tp_nl_family, 0, L2TP_CMD_NOOP);
78059- if (IS_ERR(hdr)) {
78060- ret = PTR_ERR(hdr);
78061+ if (!hdr) {
78062+ ret = -EMSGSIZE;
78063 goto err_out;
78064 }
78065
78066@@ -250,8 +250,8 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 pid, u32 seq, int flags,
78067
78068 hdr = genlmsg_put(skb, pid, seq, &l2tp_nl_family, flags,
78069 L2TP_CMD_TUNNEL_GET);
78070- if (IS_ERR(hdr))
78071- return PTR_ERR(hdr);
78072+ if (!hdr)
78073+ return -EMSGSIZE;
78074
78075 if (nla_put_u8(skb, L2TP_ATTR_PROTO_VERSION, tunnel->version) ||
78076 nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
78077@@ -617,8 +617,8 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 pid, u32 seq, int flags
78078 sk = tunnel->sock;
78079
78080 hdr = genlmsg_put(skb, pid, seq, &l2tp_nl_family, flags, L2TP_CMD_SESSION_GET);
78081- if (IS_ERR(hdr))
78082- return PTR_ERR(hdr);
78083+ if (!hdr)
78084+ return -EMSGSIZE;
78085
78086 if (nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
78087 nla_put_u32(skb, L2TP_ATTR_SESSION_ID, session->session_id) ||
78088diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78089index 3f3cd50..d2cf249 100644
78090--- a/net/mac80211/ieee80211_i.h
78091+++ b/net/mac80211/ieee80211_i.h
78092@@ -28,6 +28,7 @@
78093 #include <net/ieee80211_radiotap.h>
78094 #include <net/cfg80211.h>
78095 #include <net/mac80211.h>
78096+#include <asm/local.h>
78097 #include "key.h"
78098 #include "sta_info.h"
78099
78100@@ -863,7 +864,7 @@ struct ieee80211_local {
78101 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78102 spinlock_t queue_stop_reason_lock;
78103
78104- int open_count;
78105+ local_t open_count;
78106 int monitors, cooked_mntrs;
78107 /* number of interfaces with corresponding FIF_ flags */
78108 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78109diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78110index 8664111..1d6a065 100644
78111--- a/net/mac80211/iface.c
78112+++ b/net/mac80211/iface.c
78113@@ -328,7 +328,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78114 break;
78115 }
78116
78117- if (local->open_count == 0) {
78118+ if (local_read(&local->open_count) == 0) {
78119 res = drv_start(local);
78120 if (res)
78121 goto err_del_bss;
78122@@ -371,7 +371,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78123 break;
78124 }
78125
78126- if (local->monitors == 0 && local->open_count == 0) {
78127+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78128 res = ieee80211_add_virtual_monitor(local);
78129 if (res)
78130 goto err_stop;
78131@@ -468,7 +468,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78132 mutex_unlock(&local->mtx);
78133
78134 if (coming_up)
78135- local->open_count++;
78136+ local_inc(&local->open_count);
78137
78138 if (hw_reconf_flags)
78139 ieee80211_hw_config(local, hw_reconf_flags);
78140@@ -481,7 +481,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78141 err_del_interface:
78142 drv_remove_interface(local, sdata);
78143 err_stop:
78144- if (!local->open_count)
78145+ if (!local_read(&local->open_count))
78146 drv_stop(local);
78147 err_del_bss:
78148 sdata->bss = NULL;
78149@@ -613,7 +613,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78150 }
78151
78152 if (going_down)
78153- local->open_count--;
78154+ local_dec(&local->open_count);
78155
78156 switch (sdata->vif.type) {
78157 case NL80211_IFTYPE_AP_VLAN:
78158@@ -685,7 +685,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78159
78160 ieee80211_recalc_ps(local, -1);
78161
78162- if (local->open_count == 0) {
78163+ if (local_read(&local->open_count) == 0) {
78164 if (local->ops->napi_poll)
78165 napi_disable(&local->napi);
78166 ieee80211_clear_tx_pending(local);
78167@@ -717,7 +717,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78168 }
78169 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78170
78171- if (local->monitors == local->open_count && local->monitors > 0)
78172+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78173 ieee80211_add_virtual_monitor(local);
78174 }
78175
78176diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78177index f5548e9..474a15f 100644
78178--- a/net/mac80211/main.c
78179+++ b/net/mac80211/main.c
78180@@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78181 local->hw.conf.power_level = power;
78182 }
78183
78184- if (changed && local->open_count) {
78185+ if (changed && local_read(&local->open_count)) {
78186 ret = drv_config(local, changed);
78187 /*
78188 * Goal:
78189diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78190index af1c4e2..24dbbe3 100644
78191--- a/net/mac80211/pm.c
78192+++ b/net/mac80211/pm.c
78193@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78194 struct ieee80211_sub_if_data *sdata;
78195 struct sta_info *sta;
78196
78197- if (!local->open_count)
78198+ if (!local_read(&local->open_count))
78199 goto suspend;
78200
78201 ieee80211_scan_cancel(local);
78202@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78203 cancel_work_sync(&local->dynamic_ps_enable_work);
78204 del_timer_sync(&local->dynamic_ps_timer);
78205
78206- local->wowlan = wowlan && local->open_count;
78207+ local->wowlan = wowlan && local_read(&local->open_count);
78208 if (local->wowlan) {
78209 int err = drv_suspend(local, wowlan);
78210 if (err < 0) {
78211@@ -132,7 +132,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78212 drv_remove_interface(local, sdata);
78213
78214 /* stop hardware - this must stop RX */
78215- if (local->open_count)
78216+ if (local_read(&local->open_count))
78217 ieee80211_stop_device(local);
78218
78219 suspend:
78220diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78221index 3313c11..bec9f17 100644
78222--- a/net/mac80211/rate.c
78223+++ b/net/mac80211/rate.c
78224@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78225
78226 ASSERT_RTNL();
78227
78228- if (local->open_count)
78229+ if (local_read(&local->open_count))
78230 return -EBUSY;
78231
78232 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78233diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78234index c97a065..ff61928 100644
78235--- a/net/mac80211/rc80211_pid_debugfs.c
78236+++ b/net/mac80211/rc80211_pid_debugfs.c
78237@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78238
78239 spin_unlock_irqrestore(&events->lock, status);
78240
78241- if (copy_to_user(buf, pb, p))
78242+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78243 return -EFAULT;
78244
78245 return p;
78246diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78247index f564b5e..22fee47 100644
78248--- a/net/mac80211/util.c
78249+++ b/net/mac80211/util.c
78250@@ -1224,7 +1224,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78251 }
78252 #endif
78253 /* everything else happens only if HW was up & running */
78254- if (!local->open_count)
78255+ if (!local_read(&local->open_count))
78256 goto wake_up;
78257
78258 /*
78259diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78260index 209c1ed..39484dc 100644
78261--- a/net/netfilter/Kconfig
78262+++ b/net/netfilter/Kconfig
78263@@ -851,6 +851,16 @@ config NETFILTER_XT_MATCH_ESP
78264
78265 To compile it as a module, choose M here. If unsure, say N.
78266
78267+config NETFILTER_XT_MATCH_GRADM
78268+ tristate '"gradm" match support'
78269+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78270+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78271+ ---help---
78272+ The gradm match allows to match on grsecurity RBAC being enabled.
78273+ It is useful when iptables rules are applied early on bootup to
78274+ prevent connections to the machine (except from a trusted host)
78275+ while the RBAC system is disabled.
78276+
78277 config NETFILTER_XT_MATCH_HASHLIMIT
78278 tristate '"hashlimit" match support'
78279 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78280diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78281index 4e7960c..89e48d4 100644
78282--- a/net/netfilter/Makefile
78283+++ b/net/netfilter/Makefile
78284@@ -87,6 +87,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78285 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78286 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78287 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78288+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78289 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78290 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78291 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78292diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78293index 1548df9..98ad9b4 100644
78294--- a/net/netfilter/ipvs/ip_vs_conn.c
78295+++ b/net/netfilter/ipvs/ip_vs_conn.c
78296@@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78297 /* Increase the refcnt counter of the dest */
78298 atomic_inc(&dest->refcnt);
78299
78300- conn_flags = atomic_read(&dest->conn_flags);
78301+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
78302 if (cp->protocol != IPPROTO_UDP)
78303 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78304 flags = cp->flags;
78305@@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78306 atomic_set(&cp->refcnt, 1);
78307
78308 atomic_set(&cp->n_control, 0);
78309- atomic_set(&cp->in_pkts, 0);
78310+ atomic_set_unchecked(&cp->in_pkts, 0);
78311
78312 atomic_inc(&ipvs->conn_count);
78313 if (flags & IP_VS_CONN_F_NO_CPORT)
78314@@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78315
78316 /* Don't drop the entry if its number of incoming packets is not
78317 located in [0, 8] */
78318- i = atomic_read(&cp->in_pkts);
78319+ i = atomic_read_unchecked(&cp->in_pkts);
78320 if (i > 8 || i < 0) return 0;
78321
78322 if (!todrop_rate[i]) return 0;
78323diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78324index a54b018c..07e0120 100644
78325--- a/net/netfilter/ipvs/ip_vs_core.c
78326+++ b/net/netfilter/ipvs/ip_vs_core.c
78327@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78328 ret = cp->packet_xmit(skb, cp, pd->pp);
78329 /* do not touch skb anymore */
78330
78331- atomic_inc(&cp->in_pkts);
78332+ atomic_inc_unchecked(&cp->in_pkts);
78333 ip_vs_conn_put(cp);
78334 return ret;
78335 }
78336@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78337 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78338 pkts = sysctl_sync_threshold(ipvs);
78339 else
78340- pkts = atomic_add_return(1, &cp->in_pkts);
78341+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78342
78343 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78344 ip_vs_sync_conn(net, cp, pkts);
78345diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78346index 72bf32a..f91c066 100644
78347--- a/net/netfilter/ipvs/ip_vs_ctl.c
78348+++ b/net/netfilter/ipvs/ip_vs_ctl.c
78349@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78350 ip_vs_rs_hash(ipvs, dest);
78351 write_unlock_bh(&ipvs->rs_lock);
78352 }
78353- atomic_set(&dest->conn_flags, conn_flags);
78354+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
78355
78356 /* bind the service */
78357 if (!dest->svc) {
78358@@ -2074,7 +2074,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78359 " %-7s %-6d %-10d %-10d\n",
78360 &dest->addr.in6,
78361 ntohs(dest->port),
78362- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78363+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78364 atomic_read(&dest->weight),
78365 atomic_read(&dest->activeconns),
78366 atomic_read(&dest->inactconns));
78367@@ -2085,7 +2085,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78368 "%-7s %-6d %-10d %-10d\n",
78369 ntohl(dest->addr.ip),
78370 ntohs(dest->port),
78371- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78372+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78373 atomic_read(&dest->weight),
78374 atomic_read(&dest->activeconns),
78375 atomic_read(&dest->inactconns));
78376@@ -2555,7 +2555,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78377
78378 entry.addr = dest->addr.ip;
78379 entry.port = dest->port;
78380- entry.conn_flags = atomic_read(&dest->conn_flags);
78381+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78382 entry.weight = atomic_read(&dest->weight);
78383 entry.u_threshold = dest->u_threshold;
78384 entry.l_threshold = dest->l_threshold;
78385@@ -3090,7 +3090,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78386 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78387 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78388 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78389- (atomic_read(&dest->conn_flags) &
78390+ (atomic_read_unchecked(&dest->conn_flags) &
78391 IP_VS_CONN_F_FWD_MASK)) ||
78392 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78393 atomic_read(&dest->weight)) ||
78394diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78395index effa10c..9058928 100644
78396--- a/net/netfilter/ipvs/ip_vs_sync.c
78397+++ b/net/netfilter/ipvs/ip_vs_sync.c
78398@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78399 cp = cp->control;
78400 if (cp) {
78401 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78402- pkts = atomic_add_return(1, &cp->in_pkts);
78403+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78404 else
78405 pkts = sysctl_sync_threshold(ipvs);
78406 ip_vs_sync_conn(net, cp->control, pkts);
78407@@ -758,7 +758,7 @@ control:
78408 if (!cp)
78409 return;
78410 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78411- pkts = atomic_add_return(1, &cp->in_pkts);
78412+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78413 else
78414 pkts = sysctl_sync_threshold(ipvs);
78415 goto sloop;
78416@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78417
78418 if (opt)
78419 memcpy(&cp->in_seq, opt, sizeof(*opt));
78420- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78421+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78422 cp->state = state;
78423 cp->old_state = cp->state;
78424 /*
78425diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78426index 7fd66de..e6fb361 100644
78427--- a/net/netfilter/ipvs/ip_vs_xmit.c
78428+++ b/net/netfilter/ipvs/ip_vs_xmit.c
78429@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78430 else
78431 rc = NF_ACCEPT;
78432 /* do not touch skb anymore */
78433- atomic_inc(&cp->in_pkts);
78434+ atomic_inc_unchecked(&cp->in_pkts);
78435 goto out;
78436 }
78437
78438@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78439 else
78440 rc = NF_ACCEPT;
78441 /* do not touch skb anymore */
78442- atomic_inc(&cp->in_pkts);
78443+ atomic_inc_unchecked(&cp->in_pkts);
78444 goto out;
78445 }
78446
78447diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78448index ac3af97..c134c21 100644
78449--- a/net/netfilter/nf_conntrack_core.c
78450+++ b/net/netfilter/nf_conntrack_core.c
78451@@ -1530,6 +1530,10 @@ err_proto:
78452 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78453 #define DYING_NULLS_VAL ((1<<30)+1)
78454
78455+#ifdef CONFIG_GRKERNSEC_HIDESYM
78456+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78457+#endif
78458+
78459 static int nf_conntrack_init_net(struct net *net)
78460 {
78461 int ret;
78462@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
78463 goto err_stat;
78464 }
78465
78466+#ifdef CONFIG_GRKERNSEC_HIDESYM
78467+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78468+#else
78469 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78470+#endif
78471 if (!net->ct.slabname) {
78472 ret = -ENOMEM;
78473 goto err_slabname;
78474diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78475index 3c3cfc0..7a6ea1a 100644
78476--- a/net/netfilter/nfnetlink_log.c
78477+++ b/net/netfilter/nfnetlink_log.c
78478@@ -70,7 +70,7 @@ struct nfulnl_instance {
78479 };
78480
78481 static DEFINE_SPINLOCK(instances_lock);
78482-static atomic_t global_seq;
78483+static atomic_unchecked_t global_seq;
78484
78485 #define INSTANCE_BUCKETS 16
78486 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78487@@ -517,7 +517,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78488 /* global sequence number */
78489 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78490 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78491- htonl(atomic_inc_return(&global_seq))))
78492+ htonl(atomic_inc_return_unchecked(&global_seq))))
78493 goto nla_put_failure;
78494
78495 if (data_len) {
78496diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78497new file mode 100644
78498index 0000000..6905327
78499--- /dev/null
78500+++ b/net/netfilter/xt_gradm.c
78501@@ -0,0 +1,51 @@
78502+/*
78503+ * gradm match for netfilter
78504