]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.6.1-201210111929.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.1-201210111929.patch
CommitLineData
ca4a3969
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index 39462cf..611a556 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,14 +163,14 @@ 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 kxgettext
123 lex.c
124 lex.*.c
125-linux
126+lib1funcs.S
127 logo_*.c
128 logo_*_clut224.c
129 logo_*_mono.c
130@@ -163,14 +181,15 @@ machtypes.h
131 map
132 map_hugetlb
133 maui_boot.h
134-media
135 mconf
136+mdp
137 miboot*
138 mk_elfconfig
139 mkboot
140 mkbugboot
141 mkcpustr
142 mkdep
143+mkpiggy
144 mkprep
145 mkregtable
146 mktables
147@@ -187,6 +206,8 @@ oui.c*
148 page-types
149 parse.c
150 parse.h
151+parse-events*
152+pasyms.h
153 patches*
154 pca200e.bin
155 pca200e_ecd.bin2
156@@ -196,6 +217,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160+pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164@@ -205,7 +227,10 @@ r200_reg_safe.h
165 r300_reg_safe.h
166 r420_reg_safe.h
167 r600_reg_safe.h
168+realmode.lds
169+realmode.relocs
170 recordmcount
171+regdb.c
172 relocs
173 rlim_names.h
174 rn50_reg_safe.h
175@@ -215,8 +240,11 @@ series
176 setup
177 setup.bin
178 setup.elf
179+size_overflow_hash.h
180 sImage
181+slabinfo
182 sm_tbl*
183+sortextable
184 split-include
185 syscalltab.h
186 tables.c
187@@ -226,6 +254,7 @@ tftpboot.img
188 timeconst.h
189 times.h*
190 trix_boot.h
191+user_constants.h
192 utsrelease.h*
193 vdso-syms.lds
194 vdso.lds
195@@ -237,13 +266,17 @@ vdso32.lds
196 vdso32.so.dbg
197 vdso64.lds
198 vdso64.so.dbg
199+vdsox32.lds
200+vdsox32-syms.lds
201 version.h*
202 vmImage
203 vmlinux
204 vmlinux-*
205 vmlinux.aout
206 vmlinux.bin.all
207+vmlinux.bin.bz2
208 vmlinux.lds
209+vmlinux.relocs
210 vmlinuz
211 voffset.h
212 vsyscall.lds
213@@ -251,9 +284,11 @@ vsyscall_32.lds
214 wanxlfw.inc
215 uImage
216 unifdef
217+utsrelease.h
218 wakeup.bin
219 wakeup.elf
220 wakeup.lds
221 zImage*
222 zconf.hash.c
223+zconf.lex.c
224 zoffset.h
225diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
226index ad7e2e5..199f49e 100644
227--- a/Documentation/kernel-parameters.txt
228+++ b/Documentation/kernel-parameters.txt
229@@ -905,6 +905,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
230 gpt [EFI] Forces disk with valid GPT signature but
231 invalid Protective MBR to be treated as GPT.
232
233+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
234+ ignore grsecurity's /proc restrictions
235+
236 hashdist= [KNL,NUMA] Large hashes allocated during boot
237 are distributed across NUMA nodes. Defaults on
238 for 64-bit NUMA, off otherwise.
239@@ -2050,6 +2053,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
240 the specified number of seconds. This is to be used if
241 your oopses keep scrolling off the screen.
242
243+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
244+ virtualization environments that don't cope well with the
245+ expand down segment used by UDEREF on X86-32 or the frequent
246+ page table updates on X86-64.
247+
248+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
249+
250 pcbit= [HW,ISDN]
251
252 pcd. [PARIDE]
253diff --git a/Makefile b/Makefile
254index 9ed5898..27db564 100644
255--- a/Makefile
256+++ b/Makefile
257@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
258
259 HOSTCC = gcc
260 HOSTCXX = g++
261-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
262-HOSTCXXFLAGS = -O2
263+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
264+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
265+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
266
267 # Decide whether to build built-in, modular, or both.
268 # Normally, just do built-in.
269@@ -404,8 +405,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
270 # Rules shared between *config targets and build targets
271
272 # Basic helpers built in scripts/
273-PHONY += scripts_basic
274-scripts_basic:
275+PHONY += scripts_basic gcc-plugins
276+scripts_basic: gcc-plugins
277 $(Q)$(MAKE) $(build)=scripts/basic
278 $(Q)rm -f .tmp_quiet_recordmcount
279
280@@ -561,6 +562,60 @@ else
281 KBUILD_CFLAGS += -O2
282 endif
283
284+ifndef DISABLE_PAX_PLUGINS
285+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
286+ifneq ($(PLUGINCC),)
287+ifndef DISABLE_PAX_CONSTIFY_PLUGIN
288+ifndef CONFIG_UML
289+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
290+endif
291+endif
292+ifdef CONFIG_PAX_MEMORY_STACKLEAK
293+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
294+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
295+endif
296+ifdef CONFIG_KALLOCSTAT_PLUGIN
297+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
298+endif
299+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
300+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
301+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
302+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
303+endif
304+ifdef CONFIG_CHECKER_PLUGIN
305+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
306+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
307+endif
308+endif
309+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
310+ifdef CONFIG_PAX_SIZE_OVERFLOW
311+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
312+endif
313+ifdef CONFIG_PAX_LATENT_ENTROPY
314+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
315+endif
316+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
317+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
318+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
319+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
320+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
321+ifeq ($(KBUILD_EXTMOD),)
322+gcc-plugins:
323+ $(Q)$(MAKE) $(build)=tools/gcc
324+else
325+gcc-plugins: ;
326+endif
327+else
328+gcc-plugins:
329+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
330+ $(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.))
331+else
332+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
333+endif
334+ $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
335+endif
336+endif
337+
338 include $(srctree)/arch/$(SRCARCH)/Makefile
339
340 ifdef CONFIG_READABLE_ASM
341@@ -715,7 +770,7 @@ export mod_strip_cmd
342
343
344 ifeq ($(KBUILD_EXTMOD),)
345-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
346+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
347
348 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
349 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
350@@ -762,6 +817,8 @@ endif
351
352 # The actual objects are generated when descending,
353 # make sure no implicit rule kicks in
354+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
357
358 # Handle descending into subdirectories listed in $(vmlinux-dirs)
359@@ -771,7 +828,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
360 # Error messages still appears in the original language
361
362 PHONY += $(vmlinux-dirs)
363-$(vmlinux-dirs): prepare scripts
364+$(vmlinux-dirs): gcc-plugins prepare scripts
365 $(Q)$(MAKE) $(build)=$@
366
367 # Store (new) KERNELRELASE string in include/config/kernel.release
368@@ -815,6 +872,7 @@ prepare0: archprepare FORCE
369 $(Q)$(MAKE) $(build)=.
370
371 # All the preparing..
372+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
373 prepare: prepare0
374
375 # Generate some files
376@@ -922,6 +980,8 @@ all: modules
377 # using awk while concatenating to the final file.
378
379 PHONY += modules
380+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
381+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
382 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
383 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
384 @$(kecho) ' Building modules, stage 2.';
385@@ -937,7 +997,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
386
387 # Target to prepare building external modules
388 PHONY += modules_prepare
389-modules_prepare: prepare scripts
390+modules_prepare: gcc-plugins prepare scripts
391
392 # Target to install modules
393 PHONY += modules_install
394@@ -994,7 +1054,7 @@ CLEAN_DIRS += $(MODVERDIR)
395 MRPROPER_DIRS += include/config usr/include include/generated \
396 arch/*/include/generated
397 MRPROPER_FILES += .config .config.old .version .old_version \
398- include/linux/version.h \
399+ include/linux/version.h tools/gcc/size_overflow_hash.h\
400 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
401
402 # clean - Delete most, but leave enough to build external modules
403@@ -1032,6 +1092,7 @@ distclean: mrproper
404 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
405 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
406 -o -name '.*.rej' \
407+ -o -name '.*.rej' -o -name '*.so' \
408 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
409 -type f -print | xargs rm -f
410
411@@ -1192,6 +1253,8 @@ PHONY += $(module-dirs) modules
412 $(module-dirs): crmodverdir $(objtree)/Module.symvers
413 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
414
415+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(module-dirs)
418 @$(kecho) ' Building modules, stage 2.';
419 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
420@@ -1326,17 +1389,21 @@ else
421 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
422 endif
423
424-%.s: %.c prepare scripts FORCE
425+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427+%.s: %.c gcc-plugins prepare scripts FORCE
428 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
429 %.i: %.c prepare scripts FORCE
430 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
431-%.o: %.c prepare scripts FORCE
432+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434+%.o: %.c gcc-plugins prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 %.lst: %.c prepare scripts FORCE
437 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
438-%.s: %.S prepare scripts FORCE
439+%.s: %.S gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441-%.o: %.S prepare scripts FORCE
442+%.o: %.S gcc-plugins prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444 %.symtypes: %.c prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446@@ -1346,11 +1413,15 @@ endif
447 $(cmd_crmodverdir)
448 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
449 $(build)=$(build-dir)
450-%/: prepare scripts FORCE
451+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
452+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
453+%/: gcc-plugins prepare scripts FORCE
454 $(cmd_crmodverdir)
455 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
456 $(build)=$(build-dir)
457-%.ko: prepare scripts FORCE
458+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
459+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
460+%.ko: gcc-plugins prepare scripts FORCE
461 $(cmd_crmodverdir)
462 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
463 $(build)=$(build-dir) $(@:.ko=.o)
464diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
465index c2cbe4f..f7264b4 100644
466--- a/arch/alpha/include/asm/atomic.h
467+++ b/arch/alpha/include/asm/atomic.h
468@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
469 #define atomic_dec(v) atomic_sub(1,(v))
470 #define atomic64_dec(v) atomic64_sub(1,(v))
471
472+#define atomic64_read_unchecked(v) atomic64_read(v)
473+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
474+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
475+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
476+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
477+#define atomic64_inc_unchecked(v) atomic64_inc(v)
478+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
479+#define atomic64_dec_unchecked(v) atomic64_dec(v)
480+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
481+
482 #define smp_mb__before_atomic_dec() smp_mb()
483 #define smp_mb__after_atomic_dec() smp_mb()
484 #define smp_mb__before_atomic_inc() smp_mb()
485diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
486index ad368a9..fbe0f25 100644
487--- a/arch/alpha/include/asm/cache.h
488+++ b/arch/alpha/include/asm/cache.h
489@@ -4,19 +4,19 @@
490 #ifndef __ARCH_ALPHA_CACHE_H
491 #define __ARCH_ALPHA_CACHE_H
492
493+#include <linux/const.h>
494
495 /* Bytes per L1 (data) cache line. */
496 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
497-# define L1_CACHE_BYTES 64
498 # define L1_CACHE_SHIFT 6
499 #else
500 /* Both EV4 and EV5 are write-through, read-allocate,
501 direct-mapped, physical.
502 */
503-# define L1_CACHE_BYTES 32
504 # define L1_CACHE_SHIFT 5
505 #endif
506
507+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
509
510 #endif
511diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
512index 968d999..d36b2df 100644
513--- a/arch/alpha/include/asm/elf.h
514+++ b/arch/alpha/include/asm/elf.h
515@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
516
517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
518
519+#ifdef CONFIG_PAX_ASLR
520+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
521+
522+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
523+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
524+#endif
525+
526 /* $0 is set by ld.so to a pointer to a function which might be
527 registered using atexit. This provides a mean for the dynamic
528 linker to call DT_FINI functions for shared libraries that have
529diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
530index bc2a0da..8ad11ee 100644
531--- a/arch/alpha/include/asm/pgalloc.h
532+++ b/arch/alpha/include/asm/pgalloc.h
533@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
534 pgd_set(pgd, pmd);
535 }
536
537+static inline void
538+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539+{
540+ pgd_populate(mm, pgd, pmd);
541+}
542+
543 extern pgd_t *pgd_alloc(struct mm_struct *mm);
544
545 static inline void
546diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
547index 81a4342..348b927 100644
548--- a/arch/alpha/include/asm/pgtable.h
549+++ b/arch/alpha/include/asm/pgtable.h
550@@ -102,6 +102,17 @@ struct vm_area_struct;
551 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
552 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
553 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
554+
555+#ifdef CONFIG_PAX_PAGEEXEC
556+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
557+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
558+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
559+#else
560+# define PAGE_SHARED_NOEXEC PAGE_SHARED
561+# define PAGE_COPY_NOEXEC PAGE_COPY
562+# define PAGE_READONLY_NOEXEC PAGE_READONLY
563+#endif
564+
565 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
566
567 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
568diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
569index 2fd00b7..cfd5069 100644
570--- a/arch/alpha/kernel/module.c
571+++ b/arch/alpha/kernel/module.c
572@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
573
574 /* The small sections were sorted to the end of the segment.
575 The following should definitely cover them. */
576- gp = (u64)me->module_core + me->core_size - 0x8000;
577+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
578 got = sechdrs[me->arch.gotsecindex].sh_addr;
579
580 for (i = 0; i < n; i++) {
581diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
582index bc1acdd..a922a6d 100644
583--- a/arch/alpha/kernel/osf_sys.c
584+++ b/arch/alpha/kernel/osf_sys.c
585@@ -1312,7 +1312,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
586 /* At this point: (!vma || addr < vma->vm_end). */
587 if (limit - len < addr)
588 return -ENOMEM;
589- if (!vma || addr + len <= vma->vm_start)
590+ if (check_heap_stack_gap(vma, addr, len))
591 return addr;
592 addr = vma->vm_end;
593 vma = vma->vm_next;
594@@ -1348,6 +1348,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
595 merely specific addresses, but regions of memory -- perhaps
596 this feature should be incorporated into all ports? */
597
598+#ifdef CONFIG_PAX_RANDMMAP
599+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
600+#endif
601+
602 if (addr) {
603 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
604 if (addr != (unsigned long) -ENOMEM)
605@@ -1355,8 +1359,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
606 }
607
608 /* Next, try allocating at TASK_UNMAPPED_BASE. */
609- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
610- len, limit);
611+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
612+
613 if (addr != (unsigned long) -ENOMEM)
614 return addr;
615
616diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
617index 0c4132d..88f0d53 100644
618--- a/arch/alpha/mm/fault.c
619+++ b/arch/alpha/mm/fault.c
620@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
621 __reload_thread(pcb);
622 }
623
624+#ifdef CONFIG_PAX_PAGEEXEC
625+/*
626+ * PaX: decide what to do with offenders (regs->pc = fault address)
627+ *
628+ * returns 1 when task should be killed
629+ * 2 when patched PLT trampoline was detected
630+ * 3 when unpatched PLT trampoline was detected
631+ */
632+static int pax_handle_fetch_fault(struct pt_regs *regs)
633+{
634+
635+#ifdef CONFIG_PAX_EMUPLT
636+ int err;
637+
638+ do { /* PaX: patched PLT emulation #1 */
639+ unsigned int ldah, ldq, jmp;
640+
641+ err = get_user(ldah, (unsigned int *)regs->pc);
642+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
643+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
644+
645+ if (err)
646+ break;
647+
648+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
649+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
650+ jmp == 0x6BFB0000U)
651+ {
652+ unsigned long r27, addr;
653+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
654+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
655+
656+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
657+ err = get_user(r27, (unsigned long *)addr);
658+ if (err)
659+ break;
660+
661+ regs->r27 = r27;
662+ regs->pc = r27;
663+ return 2;
664+ }
665+ } while (0);
666+
667+ do { /* PaX: patched PLT emulation #2 */
668+ unsigned int ldah, lda, br;
669+
670+ err = get_user(ldah, (unsigned int *)regs->pc);
671+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
672+ err |= get_user(br, (unsigned int *)(regs->pc+8));
673+
674+ if (err)
675+ break;
676+
677+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
678+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
679+ (br & 0xFFE00000U) == 0xC3E00000U)
680+ {
681+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
682+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
683+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
684+
685+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
686+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
687+ return 2;
688+ }
689+ } while (0);
690+
691+ do { /* PaX: unpatched PLT emulation */
692+ unsigned int br;
693+
694+ err = get_user(br, (unsigned int *)regs->pc);
695+
696+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
697+ unsigned int br2, ldq, nop, jmp;
698+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
699+
700+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
701+ err = get_user(br2, (unsigned int *)addr);
702+ err |= get_user(ldq, (unsigned int *)(addr+4));
703+ err |= get_user(nop, (unsigned int *)(addr+8));
704+ err |= get_user(jmp, (unsigned int *)(addr+12));
705+ err |= get_user(resolver, (unsigned long *)(addr+16));
706+
707+ if (err)
708+ break;
709+
710+ if (br2 == 0xC3600000U &&
711+ ldq == 0xA77B000CU &&
712+ nop == 0x47FF041FU &&
713+ jmp == 0x6B7B0000U)
714+ {
715+ regs->r28 = regs->pc+4;
716+ regs->r27 = addr+16;
717+ regs->pc = resolver;
718+ return 3;
719+ }
720+ }
721+ } while (0);
722+#endif
723+
724+ return 1;
725+}
726+
727+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
728+{
729+ unsigned long i;
730+
731+ printk(KERN_ERR "PAX: bytes at PC: ");
732+ for (i = 0; i < 5; i++) {
733+ unsigned int c;
734+ if (get_user(c, (unsigned int *)pc+i))
735+ printk(KERN_CONT "???????? ");
736+ else
737+ printk(KERN_CONT "%08x ", c);
738+ }
739+ printk("\n");
740+}
741+#endif
742
743 /*
744 * This routine handles page faults. It determines the address,
745@@ -133,8 +251,29 @@ retry:
746 good_area:
747 si_code = SEGV_ACCERR;
748 if (cause < 0) {
749- if (!(vma->vm_flags & VM_EXEC))
750+ if (!(vma->vm_flags & VM_EXEC)) {
751+
752+#ifdef CONFIG_PAX_PAGEEXEC
753+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
754+ goto bad_area;
755+
756+ up_read(&mm->mmap_sem);
757+ switch (pax_handle_fetch_fault(regs)) {
758+
759+#ifdef CONFIG_PAX_EMUPLT
760+ case 2:
761+ case 3:
762+ return;
763+#endif
764+
765+ }
766+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
767+ do_group_exit(SIGKILL);
768+#else
769 goto bad_area;
770+#endif
771+
772+ }
773 } else if (!cause) {
774 /* Allow reads even for write-only mappings */
775 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
776diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
777index c79f61f..9ac0642 100644
778--- a/arch/arm/include/asm/atomic.h
779+++ b/arch/arm/include/asm/atomic.h
780@@ -17,17 +17,35 @@
781 #include <asm/barrier.h>
782 #include <asm/cmpxchg.h>
783
784+#ifdef CONFIG_GENERIC_ATOMIC64
785+#include <asm-generic/atomic64.h>
786+#endif
787+
788 #define ATOMIC_INIT(i) { (i) }
789
790 #ifdef __KERNEL__
791
792+#define _ASM_EXTABLE(from, to) \
793+" .pushsection __ex_table,\"a\"\n"\
794+" .align 3\n" \
795+" .long " #from ", " #to"\n" \
796+" .popsection"
797+
798 /*
799 * On ARM, ordinary assignment (str instruction) doesn't clear the local
800 * strex/ldrex monitor on some implementations. The reason we can use it for
801 * atomic_set() is the clrex or dummy strex done on every exception return.
802 */
803 #define atomic_read(v) (*(volatile int *)&(v)->counter)
804+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
805+{
806+ return v->counter;
807+}
808 #define atomic_set(v,i) (((v)->counter) = (i))
809+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
810+{
811+ v->counter = i;
812+}
813
814 #if __LINUX_ARM_ARCH__ >= 6
815
816@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
817 int result;
818
819 __asm__ __volatile__("@ atomic_add\n"
820+"1: ldrex %1, [%3]\n"
821+" adds %0, %1, %4\n"
822+
823+#ifdef CONFIG_PAX_REFCOUNT
824+" bvc 3f\n"
825+"2: bkpt 0xf103\n"
826+"3:\n"
827+#endif
828+
829+" strex %1, %0, [%3]\n"
830+" teq %1, #0\n"
831+" bne 1b"
832+
833+#ifdef CONFIG_PAX_REFCOUNT
834+"\n4:\n"
835+ _ASM_EXTABLE(2b, 4b)
836+#endif
837+
838+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
839+ : "r" (&v->counter), "Ir" (i)
840+ : "cc");
841+}
842+
843+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
844+{
845+ unsigned long tmp;
846+ int result;
847+
848+ __asm__ __volatile__("@ atomic_add_unchecked\n"
849 "1: ldrex %0, [%3]\n"
850 " add %0, %0, %4\n"
851 " strex %1, %0, [%3]\n"
852@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
853 smp_mb();
854
855 __asm__ __volatile__("@ atomic_add_return\n"
856+"1: ldrex %1, [%3]\n"
857+" adds %0, %1, %4\n"
858+
859+#ifdef CONFIG_PAX_REFCOUNT
860+" bvc 3f\n"
861+" mov %0, %1\n"
862+"2: bkpt 0xf103\n"
863+"3:\n"
864+#endif
865+
866+" strex %1, %0, [%3]\n"
867+" teq %1, #0\n"
868+" bne 1b"
869+
870+#ifdef CONFIG_PAX_REFCOUNT
871+"\n4:\n"
872+ _ASM_EXTABLE(2b, 4b)
873+#endif
874+
875+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876+ : "r" (&v->counter), "Ir" (i)
877+ : "cc");
878+
879+ smp_mb();
880+
881+ return result;
882+}
883+
884+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
885+{
886+ unsigned long tmp;
887+ int result;
888+
889+ smp_mb();
890+
891+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
892 "1: ldrex %0, [%3]\n"
893 " add %0, %0, %4\n"
894 " strex %1, %0, [%3]\n"
895@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
896 int result;
897
898 __asm__ __volatile__("@ atomic_sub\n"
899+"1: ldrex %1, [%3]\n"
900+" subs %0, %1, %4\n"
901+
902+#ifdef CONFIG_PAX_REFCOUNT
903+" bvc 3f\n"
904+"2: bkpt 0xf103\n"
905+"3:\n"
906+#endif
907+
908+" strex %1, %0, [%3]\n"
909+" teq %1, #0\n"
910+" bne 1b"
911+
912+#ifdef CONFIG_PAX_REFCOUNT
913+"\n4:\n"
914+ _ASM_EXTABLE(2b, 4b)
915+#endif
916+
917+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
918+ : "r" (&v->counter), "Ir" (i)
919+ : "cc");
920+}
921+
922+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
923+{
924+ unsigned long tmp;
925+ int result;
926+
927+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
928 "1: ldrex %0, [%3]\n"
929 " sub %0, %0, %4\n"
930 " strex %1, %0, [%3]\n"
931@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
932 smp_mb();
933
934 __asm__ __volatile__("@ atomic_sub_return\n"
935-"1: ldrex %0, [%3]\n"
936-" sub %0, %0, %4\n"
937+"1: ldrex %1, [%3]\n"
938+" subs %0, %1, %4\n"
939+
940+#ifdef CONFIG_PAX_REFCOUNT
941+" bvc 3f\n"
942+" mov %0, %1\n"
943+"2: bkpt 0xf103\n"
944+"3:\n"
945+#endif
946+
947 " strex %1, %0, [%3]\n"
948 " teq %1, #0\n"
949 " bne 1b"
950+
951+#ifdef CONFIG_PAX_REFCOUNT
952+"\n4:\n"
953+ _ASM_EXTABLE(2b, 4b)
954+#endif
955+
956 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
957 : "r" (&v->counter), "Ir" (i)
958 : "cc");
959@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
960 return oldval;
961 }
962
963+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
964+{
965+ unsigned long oldval, res;
966+
967+ smp_mb();
968+
969+ do {
970+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
971+ "ldrex %1, [%3]\n"
972+ "mov %0, #0\n"
973+ "teq %1, %4\n"
974+ "strexeq %0, %5, [%3]\n"
975+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
976+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
977+ : "cc");
978+ } while (res);
979+
980+ smp_mb();
981+
982+ return oldval;
983+}
984+
985 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
986 {
987 unsigned long tmp, tmp2;
988@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
989
990 return val;
991 }
992+
993+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
994+{
995+ return atomic_add_return(i, v);
996+}
997+
998 #define atomic_add(i, v) (void) atomic_add_return(i, v)
999+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1000+{
1001+ (void) atomic_add_return(i, v);
1002+}
1003
1004 static inline int atomic_sub_return(int i, atomic_t *v)
1005 {
1006@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1007 return val;
1008 }
1009 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1010+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1011+{
1012+ (void) atomic_sub_return(i, v);
1013+}
1014
1015 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1016 {
1017@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1018 return ret;
1019 }
1020
1021+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1022+{
1023+ return atomic_cmpxchg(v, old, new);
1024+}
1025+
1026 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1027 {
1028 unsigned long flags;
1029@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1030 #endif /* __LINUX_ARM_ARCH__ */
1031
1032 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1033+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1034+{
1035+ return xchg(&v->counter, new);
1036+}
1037
1038 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1039 {
1040@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1041 }
1042
1043 #define atomic_inc(v) atomic_add(1, v)
1044+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1045+{
1046+ atomic_add_unchecked(1, v);
1047+}
1048 #define atomic_dec(v) atomic_sub(1, v)
1049+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1050+{
1051+ atomic_sub_unchecked(1, v);
1052+}
1053
1054 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1055+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1056+{
1057+ return atomic_add_return_unchecked(1, v) == 0;
1058+}
1059 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1060 #define atomic_inc_return(v) (atomic_add_return(1, v))
1061+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1062+{
1063+ return atomic_add_return_unchecked(1, v);
1064+}
1065 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1066 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1067
1068@@ -241,6 +428,14 @@ typedef struct {
1069 u64 __aligned(8) counter;
1070 } atomic64_t;
1071
1072+#ifdef CONFIG_PAX_REFCOUNT
1073+typedef struct {
1074+ u64 __aligned(8) counter;
1075+} atomic64_unchecked_t;
1076+#else
1077+typedef atomic64_t atomic64_unchecked_t;
1078+#endif
1079+
1080 #define ATOMIC64_INIT(i) { (i) }
1081
1082 static inline u64 atomic64_read(const atomic64_t *v)
1083@@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1084 return result;
1085 }
1086
1087+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1088+{
1089+ u64 result;
1090+
1091+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1092+" ldrexd %0, %H0, [%1]"
1093+ : "=&r" (result)
1094+ : "r" (&v->counter), "Qo" (v->counter)
1095+ );
1096+
1097+ return result;
1098+}
1099+
1100 static inline void atomic64_set(atomic64_t *v, u64 i)
1101 {
1102 u64 tmp;
1103@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1104 : "cc");
1105 }
1106
1107+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1108+{
1109+ u64 tmp;
1110+
1111+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1112+"1: ldrexd %0, %H0, [%2]\n"
1113+" strexd %0, %3, %H3, [%2]\n"
1114+" teq %0, #0\n"
1115+" bne 1b"
1116+ : "=&r" (tmp), "=Qo" (v->counter)
1117+ : "r" (&v->counter), "r" (i)
1118+ : "cc");
1119+}
1120+
1121 static inline void atomic64_add(u64 i, atomic64_t *v)
1122 {
1123 u64 result;
1124@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1125 __asm__ __volatile__("@ atomic64_add\n"
1126 "1: ldrexd %0, %H0, [%3]\n"
1127 " adds %0, %0, %4\n"
1128+" adcs %H0, %H0, %H4\n"
1129+
1130+#ifdef CONFIG_PAX_REFCOUNT
1131+" bvc 3f\n"
1132+"2: bkpt 0xf103\n"
1133+"3:\n"
1134+#endif
1135+
1136+" strexd %1, %0, %H0, [%3]\n"
1137+" teq %1, #0\n"
1138+" bne 1b"
1139+
1140+#ifdef CONFIG_PAX_REFCOUNT
1141+"\n4:\n"
1142+ _ASM_EXTABLE(2b, 4b)
1143+#endif
1144+
1145+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1146+ : "r" (&v->counter), "r" (i)
1147+ : "cc");
1148+}
1149+
1150+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1151+{
1152+ u64 result;
1153+ unsigned long tmp;
1154+
1155+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1156+"1: ldrexd %0, %H0, [%3]\n"
1157+" adds %0, %0, %4\n"
1158 " adc %H0, %H0, %H4\n"
1159 " strexd %1, %0, %H0, [%3]\n"
1160 " teq %1, #0\n"
1161@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162
1163 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1164 {
1165- u64 result;
1166- unsigned long tmp;
1167+ u64 result, tmp;
1168
1169 smp_mb();
1170
1171 __asm__ __volatile__("@ atomic64_add_return\n"
1172+"1: ldrexd %1, %H1, [%3]\n"
1173+" adds %0, %1, %4\n"
1174+" adcs %H0, %H1, %H4\n"
1175+
1176+#ifdef CONFIG_PAX_REFCOUNT
1177+" bvc 3f\n"
1178+" mov %0, %1\n"
1179+" mov %H0, %H1\n"
1180+"2: bkpt 0xf103\n"
1181+"3:\n"
1182+#endif
1183+
1184+" strexd %1, %0, %H0, [%3]\n"
1185+" teq %1, #0\n"
1186+" bne 1b"
1187+
1188+#ifdef CONFIG_PAX_REFCOUNT
1189+"\n4:\n"
1190+ _ASM_EXTABLE(2b, 4b)
1191+#endif
1192+
1193+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1194+ : "r" (&v->counter), "r" (i)
1195+ : "cc");
1196+
1197+ smp_mb();
1198+
1199+ return result;
1200+}
1201+
1202+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1203+{
1204+ u64 result;
1205+ unsigned long tmp;
1206+
1207+ smp_mb();
1208+
1209+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1210 "1: ldrexd %0, %H0, [%3]\n"
1211 " adds %0, %0, %4\n"
1212 " adc %H0, %H0, %H4\n"
1213@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1214 __asm__ __volatile__("@ atomic64_sub\n"
1215 "1: ldrexd %0, %H0, [%3]\n"
1216 " subs %0, %0, %4\n"
1217+" sbcs %H0, %H0, %H4\n"
1218+
1219+#ifdef CONFIG_PAX_REFCOUNT
1220+" bvc 3f\n"
1221+"2: bkpt 0xf103\n"
1222+"3:\n"
1223+#endif
1224+
1225+" strexd %1, %0, %H0, [%3]\n"
1226+" teq %1, #0\n"
1227+" bne 1b"
1228+
1229+#ifdef CONFIG_PAX_REFCOUNT
1230+"\n4:\n"
1231+ _ASM_EXTABLE(2b, 4b)
1232+#endif
1233+
1234+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1235+ : "r" (&v->counter), "r" (i)
1236+ : "cc");
1237+}
1238+
1239+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1240+{
1241+ u64 result;
1242+ unsigned long tmp;
1243+
1244+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1245+"1: ldrexd %0, %H0, [%3]\n"
1246+" subs %0, %0, %4\n"
1247 " sbc %H0, %H0, %H4\n"
1248 " strexd %1, %0, %H0, [%3]\n"
1249 " teq %1, #0\n"
1250@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251
1252 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1253 {
1254- u64 result;
1255- unsigned long tmp;
1256+ u64 result, tmp;
1257
1258 smp_mb();
1259
1260 __asm__ __volatile__("@ atomic64_sub_return\n"
1261-"1: ldrexd %0, %H0, [%3]\n"
1262-" subs %0, %0, %4\n"
1263-" sbc %H0, %H0, %H4\n"
1264+"1: ldrexd %1, %H1, [%3]\n"
1265+" subs %0, %1, %4\n"
1266+" sbcs %H0, %H1, %H4\n"
1267+
1268+#ifdef CONFIG_PAX_REFCOUNT
1269+" bvc 3f\n"
1270+" mov %0, %1\n"
1271+" mov %H0, %H1\n"
1272+"2: bkpt 0xf103\n"
1273+"3:\n"
1274+#endif
1275+
1276 " strexd %1, %0, %H0, [%3]\n"
1277 " teq %1, #0\n"
1278 " bne 1b"
1279+
1280+#ifdef CONFIG_PAX_REFCOUNT
1281+"\n4:\n"
1282+ _ASM_EXTABLE(2b, 4b)
1283+#endif
1284+
1285 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1286 : "r" (&v->counter), "r" (i)
1287 : "cc");
1288@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1289 return oldval;
1290 }
1291
1292+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1293+{
1294+ u64 oldval;
1295+ unsigned long res;
1296+
1297+ smp_mb();
1298+
1299+ do {
1300+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1301+ "ldrexd %1, %H1, [%3]\n"
1302+ "mov %0, #0\n"
1303+ "teq %1, %4\n"
1304+ "teqeq %H1, %H4\n"
1305+ "strexdeq %0, %5, %H5, [%3]"
1306+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1307+ : "r" (&ptr->counter), "r" (old), "r" (new)
1308+ : "cc");
1309+ } while (res);
1310+
1311+ smp_mb();
1312+
1313+ return oldval;
1314+}
1315+
1316 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1317 {
1318 u64 result;
1319@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1320
1321 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1322 {
1323- u64 result;
1324- unsigned long tmp;
1325+ u64 result, tmp;
1326
1327 smp_mb();
1328
1329 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1330-"1: ldrexd %0, %H0, [%3]\n"
1331-" subs %0, %0, #1\n"
1332-" sbc %H0, %H0, #0\n"
1333+"1: ldrexd %1, %H1, [%3]\n"
1334+" subs %0, %1, #1\n"
1335+" sbcs %H0, %H1, #0\n"
1336+
1337+#ifdef CONFIG_PAX_REFCOUNT
1338+" bvc 3f\n"
1339+" mov %0, %1\n"
1340+" mov %H0, %H1\n"
1341+"2: bkpt 0xf103\n"
1342+"3:\n"
1343+#endif
1344+
1345 " teq %H0, #0\n"
1346-" bmi 2f\n"
1347+" bmi 4f\n"
1348 " strexd %1, %0, %H0, [%3]\n"
1349 " teq %1, #0\n"
1350 " bne 1b\n"
1351-"2:"
1352+"4:\n"
1353+
1354+#ifdef CONFIG_PAX_REFCOUNT
1355+ _ASM_EXTABLE(2b, 4b)
1356+#endif
1357+
1358 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1359 : "r" (&v->counter)
1360 : "cc");
1361@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1362 " teq %0, %5\n"
1363 " teqeq %H0, %H5\n"
1364 " moveq %1, #0\n"
1365-" beq 2f\n"
1366+" beq 4f\n"
1367 " adds %0, %0, %6\n"
1368-" adc %H0, %H0, %H6\n"
1369+" adcs %H0, %H0, %H6\n"
1370+
1371+#ifdef CONFIG_PAX_REFCOUNT
1372+" bvc 3f\n"
1373+"2: bkpt 0xf103\n"
1374+"3:\n"
1375+#endif
1376+
1377 " strexd %2, %0, %H0, [%4]\n"
1378 " teq %2, #0\n"
1379 " bne 1b\n"
1380-"2:"
1381+"4:\n"
1382+
1383+#ifdef CONFIG_PAX_REFCOUNT
1384+ _ASM_EXTABLE(2b, 4b)
1385+#endif
1386+
1387 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1388 : "r" (&v->counter), "r" (u), "r" (a)
1389 : "cc");
1390@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1391
1392 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1393 #define atomic64_inc(v) atomic64_add(1LL, (v))
1394+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1395 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1396+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1397 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1398 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1399 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1400+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1401 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1402 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1403 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1404diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1405index 75fe66b..2255c86 100644
1406--- a/arch/arm/include/asm/cache.h
1407+++ b/arch/arm/include/asm/cache.h
1408@@ -4,8 +4,10 @@
1409 #ifndef __ASMARM_CACHE_H
1410 #define __ASMARM_CACHE_H
1411
1412+#include <linux/const.h>
1413+
1414 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1415-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1416+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1417
1418 /*
1419 * Memory returned by kmalloc() may be used for DMA, so we must make
1420diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1421index e4448e1..7bc86b7 100644
1422--- a/arch/arm/include/asm/cacheflush.h
1423+++ b/arch/arm/include/asm/cacheflush.h
1424@@ -108,7 +108,7 @@ struct cpu_cache_fns {
1425 void (*dma_unmap_area)(const void *, size_t, int);
1426
1427 void (*dma_flush_range)(const void *, const void *);
1428-};
1429+} __no_const;
1430
1431 /*
1432 * Select the calling method
1433diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1434index 7eb18c1..e38b6d2 100644
1435--- a/arch/arm/include/asm/cmpxchg.h
1436+++ b/arch/arm/include/asm/cmpxchg.h
1437@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1438
1439 #define xchg(ptr,x) \
1440 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1441+#define xchg_unchecked(ptr,x) \
1442+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1443
1444 #include <asm-generic/cmpxchg-local.h>
1445
1446diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1447index 38050b1..9d90e8b 100644
1448--- a/arch/arm/include/asm/elf.h
1449+++ b/arch/arm/include/asm/elf.h
1450@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1451 the loader. We need to make sure that it is out of the way of the program
1452 that it will "exec", and that there is sufficient room for the brk. */
1453
1454-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1455+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1456+
1457+#ifdef CONFIG_PAX_ASLR
1458+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1459+
1460+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1461+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1462+#endif
1463
1464 /* When the program starts, a1 contains a pointer to a function to be
1465 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1466@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1467 extern void elf_set_personality(const struct elf32_hdr *);
1468 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1469
1470-struct mm_struct;
1471-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1472-#define arch_randomize_brk arch_randomize_brk
1473-
1474 #endif
1475diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1476index 83eb2f7..ed77159 100644
1477--- a/arch/arm/include/asm/kmap_types.h
1478+++ b/arch/arm/include/asm/kmap_types.h
1479@@ -4,6 +4,6 @@
1480 /*
1481 * This is the "bare minimum". AIO seems to require this.
1482 */
1483-#define KM_TYPE_NR 16
1484+#define KM_TYPE_NR 17
1485
1486 #endif
1487diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1488index 53426c6..c7baff3 100644
1489--- a/arch/arm/include/asm/outercache.h
1490+++ b/arch/arm/include/asm/outercache.h
1491@@ -35,7 +35,7 @@ struct outer_cache_fns {
1492 #endif
1493 void (*set_debug)(unsigned long);
1494 void (*resume)(void);
1495-};
1496+} __no_const;
1497
1498 #ifdef CONFIG_OUTER_CACHE
1499
1500diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1501index ecf9019..b71d9a1 100644
1502--- a/arch/arm/include/asm/page.h
1503+++ b/arch/arm/include/asm/page.h
1504@@ -114,7 +114,7 @@ struct cpu_user_fns {
1505 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1506 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1507 unsigned long vaddr, struct vm_area_struct *vma);
1508-};
1509+} __no_const;
1510
1511 #ifdef MULTI_USER
1512 extern struct cpu_user_fns cpu_user;
1513diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1514index 943504f..bf8d667 100644
1515--- a/arch/arm/include/asm/pgalloc.h
1516+++ b/arch/arm/include/asm/pgalloc.h
1517@@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1518 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1519 }
1520
1521+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1522+{
1523+ pud_populate(mm, pud, pmd);
1524+}
1525+
1526 #else /* !CONFIG_ARM_LPAE */
1527
1528 /*
1529@@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1530 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1531 #define pmd_free(mm, pmd) do { } while (0)
1532 #define pud_populate(mm,pmd,pte) BUG()
1533+#define pud_populate_kernel(mm,pmd,pte) BUG()
1534
1535 #endif /* CONFIG_ARM_LPAE */
1536
1537diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1538index af7b0bd..6750a8c 100644
1539--- a/arch/arm/include/asm/thread_info.h
1540+++ b/arch/arm/include/asm/thread_info.h
1541@@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1542 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1543 #define TIF_SYSCALL_TRACE 8
1544 #define TIF_SYSCALL_AUDIT 9
1545+
1546+/* within 8 bits of TIF_SYSCALL_TRACE
1547+ to meet flexible second operand requirements
1548+*/
1549+#define TIF_GRSEC_SETXID 10
1550+
1551 #define TIF_POLLING_NRFLAG 16
1552 #define TIF_USING_IWMMXT 17
1553 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1554@@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1555 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1556 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1557 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1558+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1559
1560 /* Checks for any syscall work in entry-common.S */
1561-#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1562+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1563+ _TIF_GRSEC_SETXID)
1564
1565 /*
1566 * Change these and you break ASM code in entry-common.S
1567diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1568index 77bd79f..ad4cd27 100644
1569--- a/arch/arm/include/asm/uaccess.h
1570+++ b/arch/arm/include/asm/uaccess.h
1571@@ -22,6 +22,8 @@
1572 #define VERIFY_READ 0
1573 #define VERIFY_WRITE 1
1574
1575+extern void check_object_size(const void *ptr, unsigned long n, bool to);
1576+
1577 /*
1578 * The exception table consists of pairs of addresses: the first is the
1579 * address of an instruction that is allowed to fault, and the second is
1580@@ -418,8 +420,23 @@ do { \
1581
1582
1583 #ifdef CONFIG_MMU
1584-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1585-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1586+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1587+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1588+
1589+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1590+{
1591+ if (!__builtin_constant_p(n))
1592+ check_object_size(to, n, false);
1593+ return ___copy_from_user(to, from, n);
1594+}
1595+
1596+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1597+{
1598+ if (!__builtin_constant_p(n))
1599+ check_object_size(from, n, true);
1600+ return ___copy_to_user(to, from, n);
1601+}
1602+
1603 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1604 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1605 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1606@@ -431,6 +448,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1607
1608 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1609 {
1610+ if ((long)n < 0)
1611+ return n;
1612+
1613 if (access_ok(VERIFY_READ, from, n))
1614 n = __copy_from_user(to, from, n);
1615 else /* security hole - plug it */
1616@@ -440,6 +460,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1617
1618 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1619 {
1620+ if ((long)n < 0)
1621+ return n;
1622+
1623 if (access_ok(VERIFY_WRITE, to, n))
1624 n = __copy_to_user(to, from, n);
1625 return n;
1626diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1627index 60d3b73..9168db0 100644
1628--- a/arch/arm/kernel/armksyms.c
1629+++ b/arch/arm/kernel/armksyms.c
1630@@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1631 #ifdef CONFIG_MMU
1632 EXPORT_SYMBOL(copy_page);
1633
1634-EXPORT_SYMBOL(__copy_from_user);
1635-EXPORT_SYMBOL(__copy_to_user);
1636+EXPORT_SYMBOL(___copy_from_user);
1637+EXPORT_SYMBOL(___copy_to_user);
1638 EXPORT_SYMBOL(__clear_user);
1639
1640 EXPORT_SYMBOL(__get_user_1);
1641diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1642index 693b744..e684262 100644
1643--- a/arch/arm/kernel/process.c
1644+++ b/arch/arm/kernel/process.c
1645@@ -28,7 +28,6 @@
1646 #include <linux/tick.h>
1647 #include <linux/utsname.h>
1648 #include <linux/uaccess.h>
1649-#include <linux/random.h>
1650 #include <linux/hw_breakpoint.h>
1651 #include <linux/cpuidle.h>
1652
1653@@ -256,9 +255,10 @@ void machine_power_off(void)
1654 machine_shutdown();
1655 if (pm_power_off)
1656 pm_power_off();
1657+ BUG();
1658 }
1659
1660-void machine_restart(char *cmd)
1661+__noreturn void machine_restart(char *cmd)
1662 {
1663 machine_shutdown();
1664
1665@@ -501,12 +501,6 @@ unsigned long get_wchan(struct task_struct *p)
1666 return 0;
1667 }
1668
1669-unsigned long arch_randomize_brk(struct mm_struct *mm)
1670-{
1671- unsigned long range_end = mm->brk + 0x02000000;
1672- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1673-}
1674-
1675 #ifdef CONFIG_MMU
1676 /*
1677 * The vectors page is always readable from user space for the
1678diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1679index 3e0fc5f..a42d2ec 100644
1680--- a/arch/arm/kernel/ptrace.c
1681+++ b/arch/arm/kernel/ptrace.c
1682@@ -913,11 +913,20 @@ enum ptrace_syscall_dir {
1683 PTRACE_SYSCALL_EXIT,
1684 };
1685
1686+#ifdef CONFIG_GRKERNSEC_SETXID
1687+extern void gr_delayed_cred_worker(void);
1688+#endif
1689+
1690 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
1691 enum ptrace_syscall_dir dir)
1692 {
1693 unsigned long ip;
1694
1695+#ifdef CONFIG_GRKERNSEC_SETXID
1696+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1697+ gr_delayed_cred_worker();
1698+#endif
1699+
1700 if (!test_thread_flag(TIF_SYSCALL_TRACE))
1701 return scno;
1702
1703diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1704index a81dcec..ac42f0f 100644
1705--- a/arch/arm/kernel/setup.c
1706+++ b/arch/arm/kernel/setup.c
1707@@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1708 struct cpu_tlb_fns cpu_tlb __read_mostly;
1709 #endif
1710 #ifdef MULTI_USER
1711-struct cpu_user_fns cpu_user __read_mostly;
1712+struct cpu_user_fns cpu_user __read_only;
1713 #endif
1714 #ifdef MULTI_CACHE
1715-struct cpu_cache_fns cpu_cache __read_mostly;
1716+struct cpu_cache_fns cpu_cache __read_only;
1717 #endif
1718 #ifdef CONFIG_OUTER_CACHE
1719-struct outer_cache_fns outer_cache __read_mostly;
1720+struct outer_cache_fns outer_cache __read_only;
1721 EXPORT_SYMBOL(outer_cache);
1722 #endif
1723
1724diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1725index b0179b8..b54c6c1 100644
1726--- a/arch/arm/kernel/traps.c
1727+++ b/arch/arm/kernel/traps.c
1728@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
1729 static int die_owner = -1;
1730 static unsigned int die_nest_count;
1731
1732+extern void gr_handle_kernel_exploit(void);
1733+
1734 static unsigned long oops_begin(void)
1735 {
1736 int cpu;
1737@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
1738 panic("Fatal exception in interrupt");
1739 if (panic_on_oops)
1740 panic("Fatal exception");
1741+
1742+ gr_handle_kernel_exploit();
1743+
1744 if (signr)
1745 do_exit(signr);
1746 }
1747diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1748index 66a477a..bee61d3 100644
1749--- a/arch/arm/lib/copy_from_user.S
1750+++ b/arch/arm/lib/copy_from_user.S
1751@@ -16,7 +16,7 @@
1752 /*
1753 * Prototype:
1754 *
1755- * size_t __copy_from_user(void *to, const void *from, size_t n)
1756+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
1757 *
1758 * Purpose:
1759 *
1760@@ -84,11 +84,11 @@
1761
1762 .text
1763
1764-ENTRY(__copy_from_user)
1765+ENTRY(___copy_from_user)
1766
1767 #include "copy_template.S"
1768
1769-ENDPROC(__copy_from_user)
1770+ENDPROC(___copy_from_user)
1771
1772 .pushsection .fixup,"ax"
1773 .align 0
1774diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1775index 6ee2f67..d1cce76 100644
1776--- a/arch/arm/lib/copy_page.S
1777+++ b/arch/arm/lib/copy_page.S
1778@@ -10,6 +10,7 @@
1779 * ASM optimised string functions
1780 */
1781 #include <linux/linkage.h>
1782+#include <linux/const.h>
1783 #include <asm/assembler.h>
1784 #include <asm/asm-offsets.h>
1785 #include <asm/cache.h>
1786diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1787index d066df6..df28194 100644
1788--- a/arch/arm/lib/copy_to_user.S
1789+++ b/arch/arm/lib/copy_to_user.S
1790@@ -16,7 +16,7 @@
1791 /*
1792 * Prototype:
1793 *
1794- * size_t __copy_to_user(void *to, const void *from, size_t n)
1795+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
1796 *
1797 * Purpose:
1798 *
1799@@ -88,11 +88,11 @@
1800 .text
1801
1802 ENTRY(__copy_to_user_std)
1803-WEAK(__copy_to_user)
1804+WEAK(___copy_to_user)
1805
1806 #include "copy_template.S"
1807
1808-ENDPROC(__copy_to_user)
1809+ENDPROC(___copy_to_user)
1810 ENDPROC(__copy_to_user_std)
1811
1812 .pushsection .fixup,"ax"
1813diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1814index 025f742..8432b08 100644
1815--- a/arch/arm/lib/uaccess_with_memcpy.c
1816+++ b/arch/arm/lib/uaccess_with_memcpy.c
1817@@ -104,7 +104,7 @@ out:
1818 }
1819
1820 unsigned long
1821-__copy_to_user(void __user *to, const void *from, unsigned long n)
1822+___copy_to_user(void __user *to, const void *from, unsigned long n)
1823 {
1824 /*
1825 * This test is stubbed out of the main function above to keep
1826diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1827index 1201191..eabbb2c 100644
1828--- a/arch/arm/mach-kirkwood/common.c
1829+++ b/arch/arm/mach-kirkwood/common.c
1830@@ -160,7 +160,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1831 clk_gate_ops.disable(hw);
1832 }
1833
1834-static struct clk_ops clk_gate_fn_ops;
1835+static clk_ops_no_const clk_gate_fn_ops;
1836
1837 static struct clk __init *clk_register_gate_fn(struct device *dev,
1838 const char *name,
1839diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1840index 677357f..8828dda 100644
1841--- a/arch/arm/mach-omap2/board-n8x0.c
1842+++ b/arch/arm/mach-omap2/board-n8x0.c
1843@@ -593,7 +593,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1844 }
1845 #endif
1846
1847-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1848+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1849 .late_init = n8x0_menelaus_late_init,
1850 };
1851
1852diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1853index c3bd834..e81ef02 100644
1854--- a/arch/arm/mm/fault.c
1855+++ b/arch/arm/mm/fault.c
1856@@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1857 }
1858 #endif
1859
1860+#ifdef CONFIG_PAX_PAGEEXEC
1861+ if (fsr & FSR_LNX_PF) {
1862+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1863+ do_group_exit(SIGKILL);
1864+ }
1865+#endif
1866+
1867 tsk->thread.address = addr;
1868 tsk->thread.error_code = fsr;
1869 tsk->thread.trap_no = 14;
1870@@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1871 }
1872 #endif /* CONFIG_MMU */
1873
1874+#ifdef CONFIG_PAX_PAGEEXEC
1875+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1876+{
1877+ long i;
1878+
1879+ printk(KERN_ERR "PAX: bytes at PC: ");
1880+ for (i = 0; i < 20; i++) {
1881+ unsigned char c;
1882+ if (get_user(c, (__force unsigned char __user *)pc+i))
1883+ printk(KERN_CONT "?? ");
1884+ else
1885+ printk(KERN_CONT "%02x ", c);
1886+ }
1887+ printk("\n");
1888+
1889+ printk(KERN_ERR "PAX: bytes at SP-4: ");
1890+ for (i = -1; i < 20; i++) {
1891+ unsigned long c;
1892+ if (get_user(c, (__force unsigned long __user *)sp+i))
1893+ printk(KERN_CONT "???????? ");
1894+ else
1895+ printk(KERN_CONT "%08lx ", c);
1896+ }
1897+ printk("\n");
1898+}
1899+#endif
1900+
1901 /*
1902 * First Level Translation Fault Handler
1903 *
1904@@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1905 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1906 struct siginfo info;
1907
1908+#ifdef CONFIG_PAX_REFCOUNT
1909+ if (fsr_fs(ifsr) == 2) {
1910+ unsigned int bkpt;
1911+
1912+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1913+ current->thread.error_code = ifsr;
1914+ current->thread.trap_no = 0;
1915+ pax_report_refcount_overflow(regs);
1916+ fixup_exception(regs);
1917+ return;
1918+ }
1919+ }
1920+#endif
1921+
1922 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1923 return;
1924
1925diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1926index ce8cb19..3ec539d 100644
1927--- a/arch/arm/mm/mmap.c
1928+++ b/arch/arm/mm/mmap.c
1929@@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1930 if (len > TASK_SIZE)
1931 return -ENOMEM;
1932
1933+#ifdef CONFIG_PAX_RANDMMAP
1934+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1935+#endif
1936+
1937 if (addr) {
1938 if (do_align)
1939 addr = COLOUR_ALIGN(addr, pgoff);
1940@@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1941 addr = PAGE_ALIGN(addr);
1942
1943 vma = find_vma(mm, addr);
1944- if (TASK_SIZE - len >= addr &&
1945- (!vma || addr + len <= vma->vm_start))
1946+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1947 return addr;
1948 }
1949 if (len > mm->cached_hole_size) {
1950- start_addr = addr = mm->free_area_cache;
1951+ start_addr = addr = mm->free_area_cache;
1952 } else {
1953- start_addr = addr = mm->mmap_base;
1954- mm->cached_hole_size = 0;
1955+ start_addr = addr = mm->mmap_base;
1956+ mm->cached_hole_size = 0;
1957 }
1958
1959 full_search:
1960@@ -124,14 +127,14 @@ full_search:
1961 * Start a new search - just in case we missed
1962 * some holes.
1963 */
1964- if (start_addr != TASK_UNMAPPED_BASE) {
1965- start_addr = addr = TASK_UNMAPPED_BASE;
1966+ if (start_addr != mm->mmap_base) {
1967+ start_addr = addr = mm->mmap_base;
1968 mm->cached_hole_size = 0;
1969 goto full_search;
1970 }
1971 return -ENOMEM;
1972 }
1973- if (!vma || addr + len <= vma->vm_start) {
1974+ if (check_heap_stack_gap(vma, addr, len)) {
1975 /*
1976 * Remember the place where we stopped the search:
1977 */
1978@@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1979
1980 if (mmap_is_legacy()) {
1981 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1982+
1983+#ifdef CONFIG_PAX_RANDMMAP
1984+ if (mm->pax_flags & MF_PAX_RANDMMAP)
1985+ mm->mmap_base += mm->delta_mmap;
1986+#endif
1987+
1988 mm->get_unmapped_area = arch_get_unmapped_area;
1989 mm->unmap_area = arch_unmap_area;
1990 } else {
1991 mm->mmap_base = mmap_base(random_factor);
1992+
1993+#ifdef CONFIG_PAX_RANDMMAP
1994+ if (mm->pax_flags & MF_PAX_RANDMMAP)
1995+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1996+#endif
1997+
1998 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1999 mm->unmap_area = arch_unmap_area_topdown;
2000 }
2001diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2002index fd556f7..af2e7d2 100644
2003--- a/arch/arm/plat-orion/include/plat/addr-map.h
2004+++ b/arch/arm/plat-orion/include/plat/addr-map.h
2005@@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2006 value in bridge_virt_base */
2007 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2008 const int win);
2009-};
2010+} __no_const;
2011
2012 /*
2013 * Information needed to setup one address mapping.
2014diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2015index f5144cd..71f6d1f 100644
2016--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2017+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2018@@ -47,7 +47,7 @@ struct samsung_dma_ops {
2019 int (*started)(unsigned ch);
2020 int (*flush)(unsigned ch);
2021 int (*stop)(unsigned ch);
2022-};
2023+} __no_const;
2024
2025 extern void *samsung_dmadev_get_ops(void);
2026 extern void *s3c_dma_get_ops(void);
2027diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2028index 5f28cae..3d23723 100644
2029--- a/arch/arm/plat-samsung/include/plat/ehci.h
2030+++ b/arch/arm/plat-samsung/include/plat/ehci.h
2031@@ -14,7 +14,7 @@
2032 struct s5p_ehci_platdata {
2033 int (*phy_init)(struct platform_device *pdev, int type);
2034 int (*phy_exit)(struct platform_device *pdev, int type);
2035-};
2036+} __no_const;
2037
2038 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2039
2040diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2041index c3a58a1..78fbf54 100644
2042--- a/arch/avr32/include/asm/cache.h
2043+++ b/arch/avr32/include/asm/cache.h
2044@@ -1,8 +1,10 @@
2045 #ifndef __ASM_AVR32_CACHE_H
2046 #define __ASM_AVR32_CACHE_H
2047
2048+#include <linux/const.h>
2049+
2050 #define L1_CACHE_SHIFT 5
2051-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2052+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2053
2054 /*
2055 * Memory returned by kmalloc() may be used for DMA, so we must make
2056diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2057index 3b3159b..425ea94 100644
2058--- a/arch/avr32/include/asm/elf.h
2059+++ b/arch/avr32/include/asm/elf.h
2060@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2061 the loader. We need to make sure that it is out of the way of the program
2062 that it will "exec", and that there is sufficient room for the brk. */
2063
2064-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2065+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2066
2067+#ifdef CONFIG_PAX_ASLR
2068+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2069+
2070+#define PAX_DELTA_MMAP_LEN 15
2071+#define PAX_DELTA_STACK_LEN 15
2072+#endif
2073
2074 /* This yields a mask that user programs can use to figure out what
2075 instruction set this CPU supports. This could be done in user space,
2076diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2077index 479330b..53717a8 100644
2078--- a/arch/avr32/include/asm/kmap_types.h
2079+++ b/arch/avr32/include/asm/kmap_types.h
2080@@ -2,9 +2,9 @@
2081 #define __ASM_AVR32_KMAP_TYPES_H
2082
2083 #ifdef CONFIG_DEBUG_HIGHMEM
2084-# define KM_TYPE_NR 29
2085+# define KM_TYPE_NR 30
2086 #else
2087-# define KM_TYPE_NR 14
2088+# define KM_TYPE_NR 15
2089 #endif
2090
2091 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2092diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2093index b92e609..b69c101 100644
2094--- a/arch/avr32/mm/fault.c
2095+++ b/arch/avr32/mm/fault.c
2096@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2097
2098 int exception_trace = 1;
2099
2100+#ifdef CONFIG_PAX_PAGEEXEC
2101+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2102+{
2103+ unsigned long i;
2104+
2105+ printk(KERN_ERR "PAX: bytes at PC: ");
2106+ for (i = 0; i < 20; i++) {
2107+ unsigned char c;
2108+ if (get_user(c, (unsigned char *)pc+i))
2109+ printk(KERN_CONT "???????? ");
2110+ else
2111+ printk(KERN_CONT "%02x ", c);
2112+ }
2113+ printk("\n");
2114+}
2115+#endif
2116+
2117 /*
2118 * This routine handles page faults. It determines the address and the
2119 * problem, and then passes it off to one of the appropriate routines.
2120@@ -173,6 +190,16 @@ bad_area:
2121 up_read(&mm->mmap_sem);
2122
2123 if (user_mode(regs)) {
2124+
2125+#ifdef CONFIG_PAX_PAGEEXEC
2126+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2127+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2128+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2129+ do_group_exit(SIGKILL);
2130+ }
2131+ }
2132+#endif
2133+
2134 if (exception_trace && printk_ratelimit())
2135 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2136 "sp %08lx ecr %lu\n",
2137diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2138index 568885a..f8008df 100644
2139--- a/arch/blackfin/include/asm/cache.h
2140+++ b/arch/blackfin/include/asm/cache.h
2141@@ -7,6 +7,7 @@
2142 #ifndef __ARCH_BLACKFIN_CACHE_H
2143 #define __ARCH_BLACKFIN_CACHE_H
2144
2145+#include <linux/const.h>
2146 #include <linux/linkage.h> /* for asmlinkage */
2147
2148 /*
2149@@ -14,7 +15,7 @@
2150 * Blackfin loads 32 bytes for cache
2151 */
2152 #define L1_CACHE_SHIFT 5
2153-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2154+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2155 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2156
2157 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2158diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2159index aea2718..3639a60 100644
2160--- a/arch/cris/include/arch-v10/arch/cache.h
2161+++ b/arch/cris/include/arch-v10/arch/cache.h
2162@@ -1,8 +1,9 @@
2163 #ifndef _ASM_ARCH_CACHE_H
2164 #define _ASM_ARCH_CACHE_H
2165
2166+#include <linux/const.h>
2167 /* Etrax 100LX have 32-byte cache-lines. */
2168-#define L1_CACHE_BYTES 32
2169 #define L1_CACHE_SHIFT 5
2170+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2171
2172 #endif /* _ASM_ARCH_CACHE_H */
2173diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2174index 7caf25d..ee65ac5 100644
2175--- a/arch/cris/include/arch-v32/arch/cache.h
2176+++ b/arch/cris/include/arch-v32/arch/cache.h
2177@@ -1,11 +1,12 @@
2178 #ifndef _ASM_CRIS_ARCH_CACHE_H
2179 #define _ASM_CRIS_ARCH_CACHE_H
2180
2181+#include <linux/const.h>
2182 #include <arch/hwregs/dma.h>
2183
2184 /* A cache-line is 32 bytes. */
2185-#define L1_CACHE_BYTES 32
2186 #define L1_CACHE_SHIFT 5
2187+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2188
2189 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2190
2191diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2192index b86329d..6709906 100644
2193--- a/arch/frv/include/asm/atomic.h
2194+++ b/arch/frv/include/asm/atomic.h
2195@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2196 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2197 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2198
2199+#define atomic64_read_unchecked(v) atomic64_read(v)
2200+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2201+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2202+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2203+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2204+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2205+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2206+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2207+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2208+
2209 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2210 {
2211 int c, old;
2212diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2213index 2797163..c2a401d 100644
2214--- a/arch/frv/include/asm/cache.h
2215+++ b/arch/frv/include/asm/cache.h
2216@@ -12,10 +12,11 @@
2217 #ifndef __ASM_CACHE_H
2218 #define __ASM_CACHE_H
2219
2220+#include <linux/const.h>
2221
2222 /* bytes per L1 cache line */
2223 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2224-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2225+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2226
2227 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2228 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2229diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2230index 43901f2..0d8b865 100644
2231--- a/arch/frv/include/asm/kmap_types.h
2232+++ b/arch/frv/include/asm/kmap_types.h
2233@@ -2,6 +2,6 @@
2234 #ifndef _ASM_KMAP_TYPES_H
2235 #define _ASM_KMAP_TYPES_H
2236
2237-#define KM_TYPE_NR 17
2238+#define KM_TYPE_NR 18
2239
2240 #endif
2241diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2242index 385fd30..6c3d97e 100644
2243--- a/arch/frv/mm/elf-fdpic.c
2244+++ b/arch/frv/mm/elf-fdpic.c
2245@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2246 if (addr) {
2247 addr = PAGE_ALIGN(addr);
2248 vma = find_vma(current->mm, addr);
2249- if (TASK_SIZE - len >= addr &&
2250- (!vma || addr + len <= vma->vm_start))
2251+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2252 goto success;
2253 }
2254
2255@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2256 for (; vma; vma = vma->vm_next) {
2257 if (addr > limit)
2258 break;
2259- if (addr + len <= vma->vm_start)
2260+ if (check_heap_stack_gap(vma, addr, len))
2261 goto success;
2262 addr = vma->vm_end;
2263 }
2264@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2265 for (; vma; vma = vma->vm_next) {
2266 if (addr > limit)
2267 break;
2268- if (addr + len <= vma->vm_start)
2269+ if (check_heap_stack_gap(vma, addr, len))
2270 goto success;
2271 addr = vma->vm_end;
2272 }
2273diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2274index c635028..6d9445a 100644
2275--- a/arch/h8300/include/asm/cache.h
2276+++ b/arch/h8300/include/asm/cache.h
2277@@ -1,8 +1,10 @@
2278 #ifndef __ARCH_H8300_CACHE_H
2279 #define __ARCH_H8300_CACHE_H
2280
2281+#include <linux/const.h>
2282+
2283 /* bytes per L1 cache line */
2284-#define L1_CACHE_BYTES 4
2285+#define L1_CACHE_BYTES _AC(4,UL)
2286
2287 /* m68k-elf-gcc 2.95.2 doesn't like these */
2288
2289diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2290index 0f01de2..d37d309 100644
2291--- a/arch/hexagon/include/asm/cache.h
2292+++ b/arch/hexagon/include/asm/cache.h
2293@@ -21,9 +21,11 @@
2294 #ifndef __ASM_CACHE_H
2295 #define __ASM_CACHE_H
2296
2297+#include <linux/const.h>
2298+
2299 /* Bytes per L1 cache line */
2300-#define L1_CACHE_SHIFT (5)
2301-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2302+#define L1_CACHE_SHIFT 5
2303+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2304
2305 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2306 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2307diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2308index 6e6fe18..a6ae668 100644
2309--- a/arch/ia64/include/asm/atomic.h
2310+++ b/arch/ia64/include/asm/atomic.h
2311@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2312 #define atomic64_inc(v) atomic64_add(1, (v))
2313 #define atomic64_dec(v) atomic64_sub(1, (v))
2314
2315+#define atomic64_read_unchecked(v) atomic64_read(v)
2316+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2317+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2318+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2319+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2320+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2321+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2322+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2323+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2324+
2325 /* Atomic operations are already serializing */
2326 #define smp_mb__before_atomic_dec() barrier()
2327 #define smp_mb__after_atomic_dec() barrier()
2328diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2329index 988254a..e1ee885 100644
2330--- a/arch/ia64/include/asm/cache.h
2331+++ b/arch/ia64/include/asm/cache.h
2332@@ -1,6 +1,7 @@
2333 #ifndef _ASM_IA64_CACHE_H
2334 #define _ASM_IA64_CACHE_H
2335
2336+#include <linux/const.h>
2337
2338 /*
2339 * Copyright (C) 1998-2000 Hewlett-Packard Co
2340@@ -9,7 +10,7 @@
2341
2342 /* Bytes per L1 (data) cache line. */
2343 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2344-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2345+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2346
2347 #ifdef CONFIG_SMP
2348 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2349diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2350index b5298eb..67c6e62 100644
2351--- a/arch/ia64/include/asm/elf.h
2352+++ b/arch/ia64/include/asm/elf.h
2353@@ -42,6 +42,13 @@
2354 */
2355 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2356
2357+#ifdef CONFIG_PAX_ASLR
2358+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2359+
2360+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2361+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2362+#endif
2363+
2364 #define PT_IA_64_UNWIND 0x70000001
2365
2366 /* IA-64 relocations: */
2367diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2368index 96a8d92..617a1cf 100644
2369--- a/arch/ia64/include/asm/pgalloc.h
2370+++ b/arch/ia64/include/asm/pgalloc.h
2371@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2372 pgd_val(*pgd_entry) = __pa(pud);
2373 }
2374
2375+static inline void
2376+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2377+{
2378+ pgd_populate(mm, pgd_entry, pud);
2379+}
2380+
2381 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2382 {
2383 return quicklist_alloc(0, GFP_KERNEL, NULL);
2384@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2385 pud_val(*pud_entry) = __pa(pmd);
2386 }
2387
2388+static inline void
2389+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2390+{
2391+ pud_populate(mm, pud_entry, pmd);
2392+}
2393+
2394 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2395 {
2396 return quicklist_alloc(0, GFP_KERNEL, NULL);
2397diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2398index 815810c..d60bd4c 100644
2399--- a/arch/ia64/include/asm/pgtable.h
2400+++ b/arch/ia64/include/asm/pgtable.h
2401@@ -12,7 +12,7 @@
2402 * David Mosberger-Tang <davidm@hpl.hp.com>
2403 */
2404
2405-
2406+#include <linux/const.h>
2407 #include <asm/mman.h>
2408 #include <asm/page.h>
2409 #include <asm/processor.h>
2410@@ -142,6 +142,17 @@
2411 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2412 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2413 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2414+
2415+#ifdef CONFIG_PAX_PAGEEXEC
2416+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2417+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2418+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2419+#else
2420+# define PAGE_SHARED_NOEXEC PAGE_SHARED
2421+# define PAGE_READONLY_NOEXEC PAGE_READONLY
2422+# define PAGE_COPY_NOEXEC PAGE_COPY
2423+#endif
2424+
2425 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2426 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2427 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2428diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2429index 54ff557..70c88b7 100644
2430--- a/arch/ia64/include/asm/spinlock.h
2431+++ b/arch/ia64/include/asm/spinlock.h
2432@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2433 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2434
2435 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2436- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2437+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2438 }
2439
2440 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2441diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2442index 449c8c0..432a3d2 100644
2443--- a/arch/ia64/include/asm/uaccess.h
2444+++ b/arch/ia64/include/asm/uaccess.h
2445@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2446 const void *__cu_from = (from); \
2447 long __cu_len = (n); \
2448 \
2449- if (__access_ok(__cu_to, __cu_len, get_fs())) \
2450+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2451 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2452 __cu_len; \
2453 })
2454@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2455 long __cu_len = (n); \
2456 \
2457 __chk_user_ptr(__cu_from); \
2458- if (__access_ok(__cu_from, __cu_len, get_fs())) \
2459+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2460 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2461 __cu_len; \
2462 })
2463diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2464index 24603be..948052d 100644
2465--- a/arch/ia64/kernel/module.c
2466+++ b/arch/ia64/kernel/module.c
2467@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2468 void
2469 module_free (struct module *mod, void *module_region)
2470 {
2471- if (mod && mod->arch.init_unw_table &&
2472- module_region == mod->module_init) {
2473+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2474 unw_remove_unwind_table(mod->arch.init_unw_table);
2475 mod->arch.init_unw_table = NULL;
2476 }
2477@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2478 }
2479
2480 static inline int
2481+in_init_rx (const struct module *mod, uint64_t addr)
2482+{
2483+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2484+}
2485+
2486+static inline int
2487+in_init_rw (const struct module *mod, uint64_t addr)
2488+{
2489+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2490+}
2491+
2492+static inline int
2493 in_init (const struct module *mod, uint64_t addr)
2494 {
2495- return addr - (uint64_t) mod->module_init < mod->init_size;
2496+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2497+}
2498+
2499+static inline int
2500+in_core_rx (const struct module *mod, uint64_t addr)
2501+{
2502+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2503+}
2504+
2505+static inline int
2506+in_core_rw (const struct module *mod, uint64_t addr)
2507+{
2508+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2509 }
2510
2511 static inline int
2512 in_core (const struct module *mod, uint64_t addr)
2513 {
2514- return addr - (uint64_t) mod->module_core < mod->core_size;
2515+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2516 }
2517
2518 static inline int
2519@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2520 break;
2521
2522 case RV_BDREL:
2523- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2524+ if (in_init_rx(mod, val))
2525+ val -= (uint64_t) mod->module_init_rx;
2526+ else if (in_init_rw(mod, val))
2527+ val -= (uint64_t) mod->module_init_rw;
2528+ else if (in_core_rx(mod, val))
2529+ val -= (uint64_t) mod->module_core_rx;
2530+ else if (in_core_rw(mod, val))
2531+ val -= (uint64_t) mod->module_core_rw;
2532 break;
2533
2534 case RV_LTV:
2535@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2536 * addresses have been selected...
2537 */
2538 uint64_t gp;
2539- if (mod->core_size > MAX_LTOFF)
2540+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2541 /*
2542 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2543 * at the end of the module.
2544 */
2545- gp = mod->core_size - MAX_LTOFF / 2;
2546+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2547 else
2548- gp = mod->core_size / 2;
2549- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2550+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2551+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2552 mod->arch.gp = gp;
2553 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2554 }
2555diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2556index d9439ef..b9a4303 100644
2557--- a/arch/ia64/kernel/sys_ia64.c
2558+++ b/arch/ia64/kernel/sys_ia64.c
2559@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2560 if (REGION_NUMBER(addr) == RGN_HPAGE)
2561 addr = 0;
2562 #endif
2563+
2564+#ifdef CONFIG_PAX_RANDMMAP
2565+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2566+ addr = mm->free_area_cache;
2567+ else
2568+#endif
2569+
2570 if (!addr)
2571 addr = mm->free_area_cache;
2572
2573@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2574 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2575 /* At this point: (!vma || addr < vma->vm_end). */
2576 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2577- if (start_addr != TASK_UNMAPPED_BASE) {
2578+ if (start_addr != mm->mmap_base) {
2579 /* Start a new search --- just in case we missed some holes. */
2580- addr = TASK_UNMAPPED_BASE;
2581+ addr = mm->mmap_base;
2582 goto full_search;
2583 }
2584 return -ENOMEM;
2585 }
2586- if (!vma || addr + len <= vma->vm_start) {
2587+ if (check_heap_stack_gap(vma, addr, len)) {
2588 /* Remember the address where we stopped this search: */
2589 mm->free_area_cache = addr + len;
2590 return addr;
2591diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2592index 0ccb28f..8992469 100644
2593--- a/arch/ia64/kernel/vmlinux.lds.S
2594+++ b/arch/ia64/kernel/vmlinux.lds.S
2595@@ -198,7 +198,7 @@ SECTIONS {
2596 /* Per-cpu data: */
2597 . = ALIGN(PERCPU_PAGE_SIZE);
2598 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2599- __phys_per_cpu_start = __per_cpu_load;
2600+ __phys_per_cpu_start = per_cpu_load;
2601 /*
2602 * ensure percpu data fits
2603 * into percpu page size
2604diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2605index 8443daf..0a01e30 100644
2606--- a/arch/ia64/mm/fault.c
2607+++ b/arch/ia64/mm/fault.c
2608@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2609 return pte_present(pte);
2610 }
2611
2612+#ifdef CONFIG_PAX_PAGEEXEC
2613+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2614+{
2615+ unsigned long i;
2616+
2617+ printk(KERN_ERR "PAX: bytes at PC: ");
2618+ for (i = 0; i < 8; i++) {
2619+ unsigned int c;
2620+ if (get_user(c, (unsigned int *)pc+i))
2621+ printk(KERN_CONT "???????? ");
2622+ else
2623+ printk(KERN_CONT "%08x ", c);
2624+ }
2625+ printk("\n");
2626+}
2627+#endif
2628+
2629 # define VM_READ_BIT 0
2630 # define VM_WRITE_BIT 1
2631 # define VM_EXEC_BIT 2
2632@@ -149,8 +166,21 @@ retry:
2633 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
2634 goto bad_area;
2635
2636- if ((vma->vm_flags & mask) != mask)
2637+ if ((vma->vm_flags & mask) != mask) {
2638+
2639+#ifdef CONFIG_PAX_PAGEEXEC
2640+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2641+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2642+ goto bad_area;
2643+
2644+ up_read(&mm->mmap_sem);
2645+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2646+ do_group_exit(SIGKILL);
2647+ }
2648+#endif
2649+
2650 goto bad_area;
2651+ }
2652
2653 /*
2654 * If for any reason at all we couldn't handle the fault, make
2655diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2656index 5ca674b..e0e1b70 100644
2657--- a/arch/ia64/mm/hugetlbpage.c
2658+++ b/arch/ia64/mm/hugetlbpage.c
2659@@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2660 /* At this point: (!vmm || addr < vmm->vm_end). */
2661 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2662 return -ENOMEM;
2663- if (!vmm || (addr + len) <= vmm->vm_start)
2664+ if (check_heap_stack_gap(vmm, addr, len))
2665 return addr;
2666 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2667 }
2668diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2669index 0eab454..bd794f2 100644
2670--- a/arch/ia64/mm/init.c
2671+++ b/arch/ia64/mm/init.c
2672@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2673 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2674 vma->vm_end = vma->vm_start + PAGE_SIZE;
2675 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2676+
2677+#ifdef CONFIG_PAX_PAGEEXEC
2678+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2679+ vma->vm_flags &= ~VM_EXEC;
2680+
2681+#ifdef CONFIG_PAX_MPROTECT
2682+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
2683+ vma->vm_flags &= ~VM_MAYEXEC;
2684+#endif
2685+
2686+ }
2687+#endif
2688+
2689 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2690 down_write(&current->mm->mmap_sem);
2691 if (insert_vm_struct(current->mm, vma)) {
2692diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2693index 40b3ee9..8c2c112 100644
2694--- a/arch/m32r/include/asm/cache.h
2695+++ b/arch/m32r/include/asm/cache.h
2696@@ -1,8 +1,10 @@
2697 #ifndef _ASM_M32R_CACHE_H
2698 #define _ASM_M32R_CACHE_H
2699
2700+#include <linux/const.h>
2701+
2702 /* L1 cache line size */
2703 #define L1_CACHE_SHIFT 4
2704-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2705+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2706
2707 #endif /* _ASM_M32R_CACHE_H */
2708diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2709index 82abd15..d95ae5d 100644
2710--- a/arch/m32r/lib/usercopy.c
2711+++ b/arch/m32r/lib/usercopy.c
2712@@ -14,6 +14,9 @@
2713 unsigned long
2714 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2715 {
2716+ if ((long)n < 0)
2717+ return n;
2718+
2719 prefetch(from);
2720 if (access_ok(VERIFY_WRITE, to, n))
2721 __copy_user(to,from,n);
2722@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2723 unsigned long
2724 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2725 {
2726+ if ((long)n < 0)
2727+ return n;
2728+
2729 prefetchw(to);
2730 if (access_ok(VERIFY_READ, from, n))
2731 __copy_user_zeroing(to,from,n);
2732diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2733index 0395c51..5f26031 100644
2734--- a/arch/m68k/include/asm/cache.h
2735+++ b/arch/m68k/include/asm/cache.h
2736@@ -4,9 +4,11 @@
2737 #ifndef __ARCH_M68K_CACHE_H
2738 #define __ARCH_M68K_CACHE_H
2739
2740+#include <linux/const.h>
2741+
2742 /* bytes per L1 cache line */
2743 #define L1_CACHE_SHIFT 4
2744-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2745+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2746
2747 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2748
2749diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2750index 4efe96a..60e8699 100644
2751--- a/arch/microblaze/include/asm/cache.h
2752+++ b/arch/microblaze/include/asm/cache.h
2753@@ -13,11 +13,12 @@
2754 #ifndef _ASM_MICROBLAZE_CACHE_H
2755 #define _ASM_MICROBLAZE_CACHE_H
2756
2757+#include <linux/const.h>
2758 #include <asm/registers.h>
2759
2760 #define L1_CACHE_SHIFT 5
2761 /* word-granular cache in microblaze */
2762-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2763+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2764
2765 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2766
2767diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2768index 3f4c5cb..3439c6e 100644
2769--- a/arch/mips/include/asm/atomic.h
2770+++ b/arch/mips/include/asm/atomic.h
2771@@ -21,6 +21,10 @@
2772 #include <asm/cmpxchg.h>
2773 #include <asm/war.h>
2774
2775+#ifdef CONFIG_GENERIC_ATOMIC64
2776+#include <asm-generic/atomic64.h>
2777+#endif
2778+
2779 #define ATOMIC_INIT(i) { (i) }
2780
2781 /*
2782@@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2783 */
2784 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2785
2786+#define atomic64_read_unchecked(v) atomic64_read(v)
2787+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2788+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2789+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2790+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2791+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2792+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2793+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2794+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2795+
2796 #endif /* CONFIG_64BIT */
2797
2798 /*
2799diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2800index b4db69f..8f3b093 100644
2801--- a/arch/mips/include/asm/cache.h
2802+++ b/arch/mips/include/asm/cache.h
2803@@ -9,10 +9,11 @@
2804 #ifndef _ASM_CACHE_H
2805 #define _ASM_CACHE_H
2806
2807+#include <linux/const.h>
2808 #include <kmalloc.h>
2809
2810 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2811-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2812+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2813
2814 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2815 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2816diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2817index 455c0ac..ad65fbe 100644
2818--- a/arch/mips/include/asm/elf.h
2819+++ b/arch/mips/include/asm/elf.h
2820@@ -372,13 +372,16 @@ extern const char *__elf_platform;
2821 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2822 #endif
2823
2824+#ifdef CONFIG_PAX_ASLR
2825+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2826+
2827+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2828+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2829+#endif
2830+
2831 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2832 struct linux_binprm;
2833 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2834 int uses_interp);
2835
2836-struct mm_struct;
2837-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2838-#define arch_randomize_brk arch_randomize_brk
2839-
2840 #endif /* _ASM_ELF_H */
2841diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2842index c1f6afa..38cc6e9 100644
2843--- a/arch/mips/include/asm/exec.h
2844+++ b/arch/mips/include/asm/exec.h
2845@@ -12,6 +12,6 @@
2846 #ifndef _ASM_EXEC_H
2847 #define _ASM_EXEC_H
2848
2849-extern unsigned long arch_align_stack(unsigned long sp);
2850+#define arch_align_stack(x) ((x) & ~0xfUL)
2851
2852 #endif /* _ASM_EXEC_H */
2853diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2854index da9bd7d..91aa7ab 100644
2855--- a/arch/mips/include/asm/page.h
2856+++ b/arch/mips/include/asm/page.h
2857@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2858 #ifdef CONFIG_CPU_MIPS32
2859 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2860 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2861- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2862+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2863 #else
2864 typedef struct { unsigned long long pte; } pte_t;
2865 #define pte_val(x) ((x).pte)
2866diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2867index 881d18b..cea38bc 100644
2868--- a/arch/mips/include/asm/pgalloc.h
2869+++ b/arch/mips/include/asm/pgalloc.h
2870@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2871 {
2872 set_pud(pud, __pud((unsigned long)pmd));
2873 }
2874+
2875+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2876+{
2877+ pud_populate(mm, pud, pmd);
2878+}
2879 #endif
2880
2881 /*
2882diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2883index ca97e0e..cd08920 100644
2884--- a/arch/mips/include/asm/thread_info.h
2885+++ b/arch/mips/include/asm/thread_info.h
2886@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2887 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2888 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2889 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2890+/* li takes a 32bit immediate */
2891+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2892 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2893
2894 #ifdef CONFIG_MIPS32_O32
2895@@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2896 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2897 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2898 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2899+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2900+
2901+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2902
2903 /* work to do in syscall_trace_leave() */
2904-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2905+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2906
2907 /* work to do on interrupt/exception return */
2908 #define _TIF_WORK_MASK (0x0000ffef & \
2909 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2910 /* work to do on any return to u-space */
2911-#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2912+#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2913
2914 #endif /* __KERNEL__ */
2915
2916diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2917index 9fdd8bc..4bd7f1a 100644
2918--- a/arch/mips/kernel/binfmt_elfn32.c
2919+++ b/arch/mips/kernel/binfmt_elfn32.c
2920@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2921 #undef ELF_ET_DYN_BASE
2922 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2923
2924+#ifdef CONFIG_PAX_ASLR
2925+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2926+
2927+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2928+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2929+#endif
2930+
2931 #include <asm/processor.h>
2932 #include <linux/module.h>
2933 #include <linux/elfcore.h>
2934diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2935index ff44823..97f8906 100644
2936--- a/arch/mips/kernel/binfmt_elfo32.c
2937+++ b/arch/mips/kernel/binfmt_elfo32.c
2938@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2939 #undef ELF_ET_DYN_BASE
2940 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2941
2942+#ifdef CONFIG_PAX_ASLR
2943+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2944+
2945+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2946+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2947+#endif
2948+
2949 #include <asm/processor.h>
2950
2951 /*
2952diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2953index e9a5fd7..378809a 100644
2954--- a/arch/mips/kernel/process.c
2955+++ b/arch/mips/kernel/process.c
2956@@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2957 out:
2958 return pc;
2959 }
2960-
2961-/*
2962- * Don't forget that the stack pointer must be aligned on a 8 bytes
2963- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2964- */
2965-unsigned long arch_align_stack(unsigned long sp)
2966-{
2967- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2968- sp -= get_random_int() & ~PAGE_MASK;
2969-
2970- return sp & ALMASK;
2971-}
2972diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2973index 4812c6d..2069554 100644
2974--- a/arch/mips/kernel/ptrace.c
2975+++ b/arch/mips/kernel/ptrace.c
2976@@ -528,6 +528,10 @@ static inline int audit_arch(void)
2977 return arch;
2978 }
2979
2980+#ifdef CONFIG_GRKERNSEC_SETXID
2981+extern void gr_delayed_cred_worker(void);
2982+#endif
2983+
2984 /*
2985 * Notification of system call entry/exit
2986 * - triggered by current->work.syscall_trace
2987@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
2988 /* do the secure computing check first */
2989 secure_computing_strict(regs->regs[2]);
2990
2991+#ifdef CONFIG_GRKERNSEC_SETXID
2992+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2993+ gr_delayed_cred_worker();
2994+#endif
2995+
2996 if (!(current->ptrace & PT_PTRACED))
2997 goto out;
2998
2999diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3000index a632bc1..0b77c7c 100644
3001--- a/arch/mips/kernel/scall32-o32.S
3002+++ b/arch/mips/kernel/scall32-o32.S
3003@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3004
3005 stack_done:
3006 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3007- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3008+ li t1, _TIF_SYSCALL_WORK
3009 and t0, t1
3010 bnez t0, syscall_trace_entry # -> yes
3011
3012diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3013index 3b5a5e9..e1ee86d 100644
3014--- a/arch/mips/kernel/scall64-64.S
3015+++ b/arch/mips/kernel/scall64-64.S
3016@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3017
3018 sd a3, PT_R26(sp) # save a3 for syscall restarting
3019
3020- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3021+ li t1, _TIF_SYSCALL_WORK
3022 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3023 and t0, t1, t0
3024 bnez t0, syscall_trace_entry
3025diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3026index 6be6f70..1859577 100644
3027--- a/arch/mips/kernel/scall64-n32.S
3028+++ b/arch/mips/kernel/scall64-n32.S
3029@@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3030
3031 sd a3, PT_R26(sp) # save a3 for syscall restarting
3032
3033- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3034+ li t1, _TIF_SYSCALL_WORK
3035 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3036 and t0, t1, t0
3037 bnez t0, n32_syscall_trace_entry
3038diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3039index 5422855..74e63a3 100644
3040--- a/arch/mips/kernel/scall64-o32.S
3041+++ b/arch/mips/kernel/scall64-o32.S
3042@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3043 PTR 4b, bad_stack
3044 .previous
3045
3046- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3047+ li t1, _TIF_SYSCALL_WORK
3048 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3049 and t0, t1, t0
3050 bnez t0, trace_a_syscall
3051diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3052index c14f6df..537e729 100644
3053--- a/arch/mips/mm/fault.c
3054+++ b/arch/mips/mm/fault.c
3055@@ -27,6 +27,23 @@
3056 #include <asm/highmem.h> /* For VMALLOC_END */
3057 #include <linux/kdebug.h>
3058
3059+#ifdef CONFIG_PAX_PAGEEXEC
3060+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3061+{
3062+ unsigned long i;
3063+
3064+ printk(KERN_ERR "PAX: bytes at PC: ");
3065+ for (i = 0; i < 5; i++) {
3066+ unsigned int c;
3067+ if (get_user(c, (unsigned int *)pc+i))
3068+ printk(KERN_CONT "???????? ");
3069+ else
3070+ printk(KERN_CONT "%08x ", c);
3071+ }
3072+ printk("\n");
3073+}
3074+#endif
3075+
3076 /*
3077 * This routine handles page faults. It determines the address,
3078 * and the problem, and then passes it off to one of the appropriate
3079diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3080index 302d779..7d35bf8 100644
3081--- a/arch/mips/mm/mmap.c
3082+++ b/arch/mips/mm/mmap.c
3083@@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3084 do_color_align = 1;
3085
3086 /* requesting a specific address */
3087+
3088+#ifdef CONFIG_PAX_RANDMMAP
3089+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3090+#endif
3091+
3092 if (addr) {
3093 if (do_color_align)
3094 addr = COLOUR_ALIGN(addr, pgoff);
3095@@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3096 addr = PAGE_ALIGN(addr);
3097
3098 vma = find_vma(mm, addr);
3099- if (TASK_SIZE - len >= addr &&
3100- (!vma || addr + len <= vma->vm_start))
3101+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3102 return addr;
3103 }
3104
3105@@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3106 /* At this point: (!vma || addr < vma->vm_end). */
3107 if (TASK_SIZE - len < addr)
3108 return -ENOMEM;
3109- if (!vma || addr + len <= vma->vm_start)
3110+ if (check_heap_stack_gap(vmm, addr, len))
3111 return addr;
3112 addr = vma->vm_end;
3113 if (do_color_align)
3114@@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3115 /* make sure it can fit in the remaining address space */
3116 if (likely(addr > len)) {
3117 vma = find_vma(mm, addr - len);
3118- if (!vma || addr <= vma->vm_start) {
3119+ if (check_heap_stack_gap(vmm, addr - len, len))
3120 /* cache the address as a hint for next time */
3121 return mm->free_area_cache = addr - len;
3122 }
3123@@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3124 * return with success:
3125 */
3126 vma = find_vma(mm, addr);
3127- if (likely(!vma || addr + len <= vma->vm_start)) {
3128+ if (check_heap_stack_gap(vmm, addr, len)) {
3129 /* cache the address as a hint for next time */
3130 return mm->free_area_cache = addr;
3131 }
3132@@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3133 mm->unmap_area = arch_unmap_area_topdown;
3134 }
3135 }
3136-
3137-static inline unsigned long brk_rnd(void)
3138-{
3139- unsigned long rnd = get_random_int();
3140-
3141- rnd = rnd << PAGE_SHIFT;
3142- /* 8MB for 32bit, 256MB for 64bit */
3143- if (TASK_IS_32BIT_ADDR)
3144- rnd = rnd & 0x7ffffful;
3145- else
3146- rnd = rnd & 0xffffffful;
3147-
3148- return rnd;
3149-}
3150-
3151-unsigned long arch_randomize_brk(struct mm_struct *mm)
3152-{
3153- unsigned long base = mm->brk;
3154- unsigned long ret;
3155-
3156- ret = PAGE_ALIGN(base + brk_rnd());
3157-
3158- if (ret < mm->brk)
3159- return mm->brk;
3160-
3161- return ret;
3162-}
3163diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3164index 967d144..db12197 100644
3165--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3166+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3167@@ -11,12 +11,14 @@
3168 #ifndef _ASM_PROC_CACHE_H
3169 #define _ASM_PROC_CACHE_H
3170
3171+#include <linux/const.h>
3172+
3173 /* L1 cache */
3174
3175 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3176 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3177-#define L1_CACHE_BYTES 16 /* bytes per entry */
3178 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3179+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3180 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3181
3182 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3183diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3184index bcb5df2..84fabd2 100644
3185--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3186+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3187@@ -16,13 +16,15 @@
3188 #ifndef _ASM_PROC_CACHE_H
3189 #define _ASM_PROC_CACHE_H
3190
3191+#include <linux/const.h>
3192+
3193 /*
3194 * L1 cache
3195 */
3196 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3197 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3198-#define L1_CACHE_BYTES 32 /* bytes per entry */
3199 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3200+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3201 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3202
3203 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3204diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3205index 4ce7a01..449202a 100644
3206--- a/arch/openrisc/include/asm/cache.h
3207+++ b/arch/openrisc/include/asm/cache.h
3208@@ -19,11 +19,13 @@
3209 #ifndef __ASM_OPENRISC_CACHE_H
3210 #define __ASM_OPENRISC_CACHE_H
3211
3212+#include <linux/const.h>
3213+
3214 /* FIXME: How can we replace these with values from the CPU...
3215 * they shouldn't be hard-coded!
3216 */
3217
3218-#define L1_CACHE_BYTES 16
3219 #define L1_CACHE_SHIFT 4
3220+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3221
3222 #endif /* __ASM_OPENRISC_CACHE_H */
3223diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3224index af9cf30..2aae9b2 100644
3225--- a/arch/parisc/include/asm/atomic.h
3226+++ b/arch/parisc/include/asm/atomic.h
3227@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3228
3229 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3230
3231+#define atomic64_read_unchecked(v) atomic64_read(v)
3232+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3233+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3234+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3235+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3236+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3237+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3238+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3239+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3240+
3241 #endif /* !CONFIG_64BIT */
3242
3243
3244diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3245index 47f11c7..3420df2 100644
3246--- a/arch/parisc/include/asm/cache.h
3247+++ b/arch/parisc/include/asm/cache.h
3248@@ -5,6 +5,7 @@
3249 #ifndef __ARCH_PARISC_CACHE_H
3250 #define __ARCH_PARISC_CACHE_H
3251
3252+#include <linux/const.h>
3253
3254 /*
3255 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3256@@ -15,13 +16,13 @@
3257 * just ruin performance.
3258 */
3259 #ifdef CONFIG_PA20
3260-#define L1_CACHE_BYTES 64
3261 #define L1_CACHE_SHIFT 6
3262 #else
3263-#define L1_CACHE_BYTES 32
3264 #define L1_CACHE_SHIFT 5
3265 #endif
3266
3267+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3268+
3269 #ifndef __ASSEMBLY__
3270
3271 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3272diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3273index 19f6cb1..6c78cf2 100644
3274--- a/arch/parisc/include/asm/elf.h
3275+++ b/arch/parisc/include/asm/elf.h
3276@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3277
3278 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3279
3280+#ifdef CONFIG_PAX_ASLR
3281+#define PAX_ELF_ET_DYN_BASE 0x10000UL
3282+
3283+#define PAX_DELTA_MMAP_LEN 16
3284+#define PAX_DELTA_STACK_LEN 16
3285+#endif
3286+
3287 /* This yields a mask that user programs can use to figure out what
3288 instruction set this CPU supports. This could be done in user space,
3289 but it's not easy, and we've already done it here. */
3290diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3291index fc987a1..6e068ef 100644
3292--- a/arch/parisc/include/asm/pgalloc.h
3293+++ b/arch/parisc/include/asm/pgalloc.h
3294@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3295 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3296 }
3297
3298+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3299+{
3300+ pgd_populate(mm, pgd, pmd);
3301+}
3302+
3303 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3304 {
3305 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3306@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3307 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3308 #define pmd_free(mm, x) do { } while (0)
3309 #define pgd_populate(mm, pmd, pte) BUG()
3310+#define pgd_populate_kernel(mm, pmd, pte) BUG()
3311
3312 #endif
3313
3314diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3315index ee99f23..802b0a1 100644
3316--- a/arch/parisc/include/asm/pgtable.h
3317+++ b/arch/parisc/include/asm/pgtable.h
3318@@ -212,6 +212,17 @@ struct vm_area_struct;
3319 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3320 #define PAGE_COPY PAGE_EXECREAD
3321 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3322+
3323+#ifdef CONFIG_PAX_PAGEEXEC
3324+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3325+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3326+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3327+#else
3328+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3329+# define PAGE_COPY_NOEXEC PAGE_COPY
3330+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3331+#endif
3332+
3333 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3334 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3335 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3336diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3337index 4ba2c93..f5e3974 100644
3338--- a/arch/parisc/include/asm/uaccess.h
3339+++ b/arch/parisc/include/asm/uaccess.h
3340@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3341 const void __user *from,
3342 unsigned long n)
3343 {
3344- int sz = __compiletime_object_size(to);
3345+ size_t sz = __compiletime_object_size(to);
3346 int ret = -EFAULT;
3347
3348- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3349+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3350 ret = __copy_from_user(to, from, n);
3351 else
3352 copy_from_user_overflow();
3353diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3354index 5e34ccf..672bc9c 100644
3355--- a/arch/parisc/kernel/module.c
3356+++ b/arch/parisc/kernel/module.c
3357@@ -98,16 +98,38 @@
3358
3359 /* three functions to determine where in the module core
3360 * or init pieces the location is */
3361+static inline int in_init_rx(struct module *me, void *loc)
3362+{
3363+ return (loc >= me->module_init_rx &&
3364+ loc < (me->module_init_rx + me->init_size_rx));
3365+}
3366+
3367+static inline int in_init_rw(struct module *me, void *loc)
3368+{
3369+ return (loc >= me->module_init_rw &&
3370+ loc < (me->module_init_rw + me->init_size_rw));
3371+}
3372+
3373 static inline int in_init(struct module *me, void *loc)
3374 {
3375- return (loc >= me->module_init &&
3376- loc <= (me->module_init + me->init_size));
3377+ return in_init_rx(me, loc) || in_init_rw(me, loc);
3378+}
3379+
3380+static inline int in_core_rx(struct module *me, void *loc)
3381+{
3382+ return (loc >= me->module_core_rx &&
3383+ loc < (me->module_core_rx + me->core_size_rx));
3384+}
3385+
3386+static inline int in_core_rw(struct module *me, void *loc)
3387+{
3388+ return (loc >= me->module_core_rw &&
3389+ loc < (me->module_core_rw + me->core_size_rw));
3390 }
3391
3392 static inline int in_core(struct module *me, void *loc)
3393 {
3394- return (loc >= me->module_core &&
3395- loc <= (me->module_core + me->core_size));
3396+ return in_core_rx(me, loc) || in_core_rw(me, loc);
3397 }
3398
3399 static inline int in_local(struct module *me, void *loc)
3400@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3401 }
3402
3403 /* align things a bit */
3404- me->core_size = ALIGN(me->core_size, 16);
3405- me->arch.got_offset = me->core_size;
3406- me->core_size += gots * sizeof(struct got_entry);
3407+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3408+ me->arch.got_offset = me->core_size_rw;
3409+ me->core_size_rw += gots * sizeof(struct got_entry);
3410
3411- me->core_size = ALIGN(me->core_size, 16);
3412- me->arch.fdesc_offset = me->core_size;
3413- me->core_size += fdescs * sizeof(Elf_Fdesc);
3414+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3415+ me->arch.fdesc_offset = me->core_size_rw;
3416+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3417
3418 me->arch.got_max = gots;
3419 me->arch.fdesc_max = fdescs;
3420@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3421
3422 BUG_ON(value == 0);
3423
3424- got = me->module_core + me->arch.got_offset;
3425+ got = me->module_core_rw + me->arch.got_offset;
3426 for (i = 0; got[i].addr; i++)
3427 if (got[i].addr == value)
3428 goto out;
3429@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3430 #ifdef CONFIG_64BIT
3431 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3432 {
3433- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3434+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3435
3436 if (!value) {
3437 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3438@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3439
3440 /* Create new one */
3441 fdesc->addr = value;
3442- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3443+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3444 return (Elf_Addr)fdesc;
3445 }
3446 #endif /* CONFIG_64BIT */
3447@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3448
3449 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3450 end = table + sechdrs[me->arch.unwind_section].sh_size;
3451- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3452+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3453
3454 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3455 me->arch.unwind_section, table, end, gp);
3456diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3457index 7426e40..30c8dbe 100644
3458--- a/arch/parisc/kernel/sys_parisc.c
3459+++ b/arch/parisc/kernel/sys_parisc.c
3460@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3461 /* At this point: (!vma || addr < vma->vm_end). */
3462 if (TASK_SIZE - len < addr)
3463 return -ENOMEM;
3464- if (!vma || addr + len <= vma->vm_start)
3465+ if (check_heap_stack_gap(vma, addr, len))
3466 return addr;
3467 addr = vma->vm_end;
3468 }
3469@@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3470 /* At this point: (!vma || addr < vma->vm_end). */
3471 if (TASK_SIZE - len < addr)
3472 return -ENOMEM;
3473- if (!vma || addr + len <= vma->vm_start)
3474+ if (check_heap_stack_gap(vma, addr, len))
3475 return addr;
3476 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3477 if (addr < vma->vm_end) /* handle wraparound */
3478@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3479 if (flags & MAP_FIXED)
3480 return addr;
3481 if (!addr)
3482- addr = TASK_UNMAPPED_BASE;
3483+ addr = current->mm->mmap_base;
3484
3485 if (filp) {
3486 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3487diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3488index 45ba99f..8e22c33 100644
3489--- a/arch/parisc/kernel/traps.c
3490+++ b/arch/parisc/kernel/traps.c
3491@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3492
3493 down_read(&current->mm->mmap_sem);
3494 vma = find_vma(current->mm,regs->iaoq[0]);
3495- if (vma && (regs->iaoq[0] >= vma->vm_start)
3496- && (vma->vm_flags & VM_EXEC)) {
3497-
3498+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3499 fault_address = regs->iaoq[0];
3500 fault_space = regs->iasq[0];
3501
3502diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3503index 18162ce..94de376 100644
3504--- a/arch/parisc/mm/fault.c
3505+++ b/arch/parisc/mm/fault.c
3506@@ -15,6 +15,7 @@
3507 #include <linux/sched.h>
3508 #include <linux/interrupt.h>
3509 #include <linux/module.h>
3510+#include <linux/unistd.h>
3511
3512 #include <asm/uaccess.h>
3513 #include <asm/traps.h>
3514@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3515 static unsigned long
3516 parisc_acctyp(unsigned long code, unsigned int inst)
3517 {
3518- if (code == 6 || code == 16)
3519+ if (code == 6 || code == 7 || code == 16)
3520 return VM_EXEC;
3521
3522 switch (inst & 0xf0000000) {
3523@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3524 }
3525 #endif
3526
3527+#ifdef CONFIG_PAX_PAGEEXEC
3528+/*
3529+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3530+ *
3531+ * returns 1 when task should be killed
3532+ * 2 when rt_sigreturn trampoline was detected
3533+ * 3 when unpatched PLT trampoline was detected
3534+ */
3535+static int pax_handle_fetch_fault(struct pt_regs *regs)
3536+{
3537+
3538+#ifdef CONFIG_PAX_EMUPLT
3539+ int err;
3540+
3541+ do { /* PaX: unpatched PLT emulation */
3542+ unsigned int bl, depwi;
3543+
3544+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3545+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3546+
3547+ if (err)
3548+ break;
3549+
3550+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3551+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3552+
3553+ err = get_user(ldw, (unsigned int *)addr);
3554+ err |= get_user(bv, (unsigned int *)(addr+4));
3555+ err |= get_user(ldw2, (unsigned int *)(addr+8));
3556+
3557+ if (err)
3558+ break;
3559+
3560+ if (ldw == 0x0E801096U &&
3561+ bv == 0xEAC0C000U &&
3562+ ldw2 == 0x0E881095U)
3563+ {
3564+ unsigned int resolver, map;
3565+
3566+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3567+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3568+ if (err)
3569+ break;
3570+
3571+ regs->gr[20] = instruction_pointer(regs)+8;
3572+ regs->gr[21] = map;
3573+ regs->gr[22] = resolver;
3574+ regs->iaoq[0] = resolver | 3UL;
3575+ regs->iaoq[1] = regs->iaoq[0] + 4;
3576+ return 3;
3577+ }
3578+ }
3579+ } while (0);
3580+#endif
3581+
3582+#ifdef CONFIG_PAX_EMUTRAMP
3583+
3584+#ifndef CONFIG_PAX_EMUSIGRT
3585+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3586+ return 1;
3587+#endif
3588+
3589+ do { /* PaX: rt_sigreturn emulation */
3590+ unsigned int ldi1, ldi2, bel, nop;
3591+
3592+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3593+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3594+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3595+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3596+
3597+ if (err)
3598+ break;
3599+
3600+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3601+ ldi2 == 0x3414015AU &&
3602+ bel == 0xE4008200U &&
3603+ nop == 0x08000240U)
3604+ {
3605+ regs->gr[25] = (ldi1 & 2) >> 1;
3606+ regs->gr[20] = __NR_rt_sigreturn;
3607+ regs->gr[31] = regs->iaoq[1] + 16;
3608+ regs->sr[0] = regs->iasq[1];
3609+ regs->iaoq[0] = 0x100UL;
3610+ regs->iaoq[1] = regs->iaoq[0] + 4;
3611+ regs->iasq[0] = regs->sr[2];
3612+ regs->iasq[1] = regs->sr[2];
3613+ return 2;
3614+ }
3615+ } while (0);
3616+#endif
3617+
3618+ return 1;
3619+}
3620+
3621+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3622+{
3623+ unsigned long i;
3624+
3625+ printk(KERN_ERR "PAX: bytes at PC: ");
3626+ for (i = 0; i < 5; i++) {
3627+ unsigned int c;
3628+ if (get_user(c, (unsigned int *)pc+i))
3629+ printk(KERN_CONT "???????? ");
3630+ else
3631+ printk(KERN_CONT "%08x ", c);
3632+ }
3633+ printk("\n");
3634+}
3635+#endif
3636+
3637 int fixup_exception(struct pt_regs *regs)
3638 {
3639 const struct exception_table_entry *fix;
3640@@ -192,8 +303,33 @@ good_area:
3641
3642 acc_type = parisc_acctyp(code,regs->iir);
3643
3644- if ((vma->vm_flags & acc_type) != acc_type)
3645+ if ((vma->vm_flags & acc_type) != acc_type) {
3646+
3647+#ifdef CONFIG_PAX_PAGEEXEC
3648+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3649+ (address & ~3UL) == instruction_pointer(regs))
3650+ {
3651+ up_read(&mm->mmap_sem);
3652+ switch (pax_handle_fetch_fault(regs)) {
3653+
3654+#ifdef CONFIG_PAX_EMUPLT
3655+ case 3:
3656+ return;
3657+#endif
3658+
3659+#ifdef CONFIG_PAX_EMUTRAMP
3660+ case 2:
3661+ return;
3662+#endif
3663+
3664+ }
3665+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3666+ do_group_exit(SIGKILL);
3667+ }
3668+#endif
3669+
3670 goto bad_area;
3671+ }
3672
3673 /*
3674 * If for any reason at all we couldn't handle the fault, make
3675diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3676index da29032..f76c24c 100644
3677--- a/arch/powerpc/include/asm/atomic.h
3678+++ b/arch/powerpc/include/asm/atomic.h
3679@@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3680 return t1;
3681 }
3682
3683+#define atomic64_read_unchecked(v) atomic64_read(v)
3684+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3685+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3686+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3687+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3688+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3689+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3690+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3691+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3692+
3693 #endif /* __powerpc64__ */
3694
3695 #endif /* __KERNEL__ */
3696diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3697index 9e495c9..b6878e5 100644
3698--- a/arch/powerpc/include/asm/cache.h
3699+++ b/arch/powerpc/include/asm/cache.h
3700@@ -3,6 +3,7 @@
3701
3702 #ifdef __KERNEL__
3703
3704+#include <linux/const.h>
3705
3706 /* bytes per L1 cache line */
3707 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3708@@ -22,7 +23,7 @@
3709 #define L1_CACHE_SHIFT 7
3710 #endif
3711
3712-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3713+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3714
3715 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3716
3717diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3718index 3bf9cca..e7457d0 100644
3719--- a/arch/powerpc/include/asm/elf.h
3720+++ b/arch/powerpc/include/asm/elf.h
3721@@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3722 the loader. We need to make sure that it is out of the way of the program
3723 that it will "exec", and that there is sufficient room for the brk. */
3724
3725-extern unsigned long randomize_et_dyn(unsigned long base);
3726-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3727+#define ELF_ET_DYN_BASE (0x20000000)
3728+
3729+#ifdef CONFIG_PAX_ASLR
3730+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3731+
3732+#ifdef __powerpc64__
3733+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3734+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3735+#else
3736+#define PAX_DELTA_MMAP_LEN 15
3737+#define PAX_DELTA_STACK_LEN 15
3738+#endif
3739+#endif
3740
3741 /*
3742 * Our registers are always unsigned longs, whether we're a 32 bit
3743@@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3744 (0x7ff >> (PAGE_SHIFT - 12)) : \
3745 (0x3ffff >> (PAGE_SHIFT - 12)))
3746
3747-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3748-#define arch_randomize_brk arch_randomize_brk
3749-
3750 #endif /* __KERNEL__ */
3751
3752 /*
3753diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3754index 8196e9c..d83a9f3 100644
3755--- a/arch/powerpc/include/asm/exec.h
3756+++ b/arch/powerpc/include/asm/exec.h
3757@@ -4,6 +4,6 @@
3758 #ifndef _ASM_POWERPC_EXEC_H
3759 #define _ASM_POWERPC_EXEC_H
3760
3761-extern unsigned long arch_align_stack(unsigned long sp);
3762+#define arch_align_stack(x) ((x) & ~0xfUL)
3763
3764 #endif /* _ASM_POWERPC_EXEC_H */
3765diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3766index 5acabbd..7ea14fa 100644
3767--- a/arch/powerpc/include/asm/kmap_types.h
3768+++ b/arch/powerpc/include/asm/kmap_types.h
3769@@ -10,7 +10,7 @@
3770 * 2 of the License, or (at your option) any later version.
3771 */
3772
3773-#define KM_TYPE_NR 16
3774+#define KM_TYPE_NR 17
3775
3776 #endif /* __KERNEL__ */
3777 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
3778diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3779index d4a7f64..451de1c 100644
3780--- a/arch/powerpc/include/asm/mman.h
3781+++ b/arch/powerpc/include/asm/mman.h
3782@@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3783 }
3784 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3785
3786-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3787+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3788 {
3789 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3790 }
3791diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3792index f072e97..b436dee 100644
3793--- a/arch/powerpc/include/asm/page.h
3794+++ b/arch/powerpc/include/asm/page.h
3795@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3796 * and needs to be executable. This means the whole heap ends
3797 * up being executable.
3798 */
3799-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3800- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3801+#define VM_DATA_DEFAULT_FLAGS32 \
3802+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3803+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3804
3805 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3806 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3807@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3808 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3809 #endif
3810
3811+#define ktla_ktva(addr) (addr)
3812+#define ktva_ktla(addr) (addr)
3813+
3814 /*
3815 * Use the top bit of the higher-level page table entries to indicate whether
3816 * the entries we point to contain hugepages. This works because we know that
3817diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3818index fed85e6..da5c71b 100644
3819--- a/arch/powerpc/include/asm/page_64.h
3820+++ b/arch/powerpc/include/asm/page_64.h
3821@@ -146,15 +146,18 @@ do { \
3822 * stack by default, so in the absence of a PT_GNU_STACK program header
3823 * we turn execute permission off.
3824 */
3825-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3826- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3827+#define VM_STACK_DEFAULT_FLAGS32 \
3828+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3829+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3830
3831 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3832 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3833
3834+#ifndef CONFIG_PAX_PAGEEXEC
3835 #define VM_STACK_DEFAULT_FLAGS \
3836 (is_32bit_task() ? \
3837 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3838+#endif
3839
3840 #include <asm-generic/getorder.h>
3841
3842diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3843index 292725c..f87ae14 100644
3844--- a/arch/powerpc/include/asm/pgalloc-64.h
3845+++ b/arch/powerpc/include/asm/pgalloc-64.h
3846@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3847 #ifndef CONFIG_PPC_64K_PAGES
3848
3849 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3850+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3851
3852 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3853 {
3854@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3855 pud_set(pud, (unsigned long)pmd);
3856 }
3857
3858+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3859+{
3860+ pud_populate(mm, pud, pmd);
3861+}
3862+
3863 #define pmd_populate(mm, pmd, pte_page) \
3864 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3865 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3866@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3867 #else /* CONFIG_PPC_64K_PAGES */
3868
3869 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3870+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3871
3872 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3873 pte_t *pte)
3874diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3875index 2e0e411..7899c68 100644
3876--- a/arch/powerpc/include/asm/pgtable.h
3877+++ b/arch/powerpc/include/asm/pgtable.h
3878@@ -2,6 +2,7 @@
3879 #define _ASM_POWERPC_PGTABLE_H
3880 #ifdef __KERNEL__
3881
3882+#include <linux/const.h>
3883 #ifndef __ASSEMBLY__
3884 #include <asm/processor.h> /* For TASK_SIZE */
3885 #include <asm/mmu.h>
3886diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3887index 4aad413..85d86bf 100644
3888--- a/arch/powerpc/include/asm/pte-hash32.h
3889+++ b/arch/powerpc/include/asm/pte-hash32.h
3890@@ -21,6 +21,7 @@
3891 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3892 #define _PAGE_USER 0x004 /* usermode access allowed */
3893 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3894+#define _PAGE_EXEC _PAGE_GUARDED
3895 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3896 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3897 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3898diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3899index 6386086..6982225 100644
3900--- a/arch/powerpc/include/asm/reg.h
3901+++ b/arch/powerpc/include/asm/reg.h
3902@@ -212,6 +212,7 @@
3903 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3904 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3905 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3906+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3907 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3908 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3909 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3910diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3911index faf9352..ab2ccec 100644
3912--- a/arch/powerpc/include/asm/thread_info.h
3913+++ b/arch/powerpc/include/asm/thread_info.h
3914@@ -97,12 +97,14 @@ static inline struct thread_info *current_thread_info(void)
3915 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3916 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3917 #define TIF_SINGLESTEP 8 /* singlestepping active */
3918-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3919 #define TIF_SECCOMP 10 /* secure computing */
3920 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3921 #define TIF_NOERROR 12 /* Force successful syscall return */
3922 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3923 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3924+#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3925+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3926+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3927
3928 /* as above, but as bit values */
3929 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3930@@ -119,8 +121,10 @@ static inline struct thread_info *current_thread_info(void)
3931 #define _TIF_NOERROR (1<<TIF_NOERROR)
3932 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3933 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3934+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3935 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3936- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3937+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3938+ _TIF_GRSEC_SETXID)
3939
3940 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3941 _TIF_NOTIFY_RESUME)
3942diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3943index 17bb40c..353c98b 100644
3944--- a/arch/powerpc/include/asm/uaccess.h
3945+++ b/arch/powerpc/include/asm/uaccess.h
3946@@ -13,6 +13,8 @@
3947 #define VERIFY_READ 0
3948 #define VERIFY_WRITE 1
3949
3950+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3951+
3952 /*
3953 * The fs value determines whether argument validity checking should be
3954 * performed or not. If get_fs() == USER_DS, checking is performed, with
3955@@ -329,52 +331,6 @@ do { \
3956 extern unsigned long __copy_tofrom_user(void __user *to,
3957 const void __user *from, unsigned long size);
3958
3959-#ifndef __powerpc64__
3960-
3961-static inline unsigned long copy_from_user(void *to,
3962- const void __user *from, unsigned long n)
3963-{
3964- unsigned long over;
3965-
3966- if (access_ok(VERIFY_READ, from, n))
3967- return __copy_tofrom_user((__force void __user *)to, from, n);
3968- if ((unsigned long)from < TASK_SIZE) {
3969- over = (unsigned long)from + n - TASK_SIZE;
3970- return __copy_tofrom_user((__force void __user *)to, from,
3971- n - over) + over;
3972- }
3973- return n;
3974-}
3975-
3976-static inline unsigned long copy_to_user(void __user *to,
3977- const void *from, unsigned long n)
3978-{
3979- unsigned long over;
3980-
3981- if (access_ok(VERIFY_WRITE, to, n))
3982- return __copy_tofrom_user(to, (__force void __user *)from, n);
3983- if ((unsigned long)to < TASK_SIZE) {
3984- over = (unsigned long)to + n - TASK_SIZE;
3985- return __copy_tofrom_user(to, (__force void __user *)from,
3986- n - over) + over;
3987- }
3988- return n;
3989-}
3990-
3991-#else /* __powerpc64__ */
3992-
3993-#define __copy_in_user(to, from, size) \
3994- __copy_tofrom_user((to), (from), (size))
3995-
3996-extern unsigned long copy_from_user(void *to, const void __user *from,
3997- unsigned long n);
3998-extern unsigned long copy_to_user(void __user *to, const void *from,
3999- unsigned long n);
4000-extern unsigned long copy_in_user(void __user *to, const void __user *from,
4001- unsigned long n);
4002-
4003-#endif /* __powerpc64__ */
4004-
4005 static inline unsigned long __copy_from_user_inatomic(void *to,
4006 const void __user *from, unsigned long n)
4007 {
4008@@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4009 if (ret == 0)
4010 return 0;
4011 }
4012+
4013+ if (!__builtin_constant_p(n))
4014+ check_object_size(to, n, false);
4015+
4016 return __copy_tofrom_user((__force void __user *)to, from, n);
4017 }
4018
4019@@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4020 if (ret == 0)
4021 return 0;
4022 }
4023+
4024+ if (!__builtin_constant_p(n))
4025+ check_object_size(from, n, true);
4026+
4027 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4028 }
4029
4030@@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4031 return __copy_to_user_inatomic(to, from, size);
4032 }
4033
4034+#ifndef __powerpc64__
4035+
4036+static inline unsigned long __must_check copy_from_user(void *to,
4037+ const void __user *from, unsigned long n)
4038+{
4039+ unsigned long over;
4040+
4041+ if ((long)n < 0)
4042+ return n;
4043+
4044+ if (access_ok(VERIFY_READ, from, n)) {
4045+ if (!__builtin_constant_p(n))
4046+ check_object_size(to, n, false);
4047+ return __copy_tofrom_user((__force void __user *)to, from, n);
4048+ }
4049+ if ((unsigned long)from < TASK_SIZE) {
4050+ over = (unsigned long)from + n - TASK_SIZE;
4051+ if (!__builtin_constant_p(n - over))
4052+ check_object_size(to, n - over, false);
4053+ return __copy_tofrom_user((__force void __user *)to, from,
4054+ n - over) + over;
4055+ }
4056+ return n;
4057+}
4058+
4059+static inline unsigned long __must_check copy_to_user(void __user *to,
4060+ const void *from, unsigned long n)
4061+{
4062+ unsigned long over;
4063+
4064+ if ((long)n < 0)
4065+ return n;
4066+
4067+ if (access_ok(VERIFY_WRITE, to, n)) {
4068+ if (!__builtin_constant_p(n))
4069+ check_object_size(from, n, true);
4070+ return __copy_tofrom_user(to, (__force void __user *)from, n);
4071+ }
4072+ if ((unsigned long)to < TASK_SIZE) {
4073+ over = (unsigned long)to + n - TASK_SIZE;
4074+ if (!__builtin_constant_p(n))
4075+ check_object_size(from, n - over, true);
4076+ return __copy_tofrom_user(to, (__force void __user *)from,
4077+ n - over) + over;
4078+ }
4079+ return n;
4080+}
4081+
4082+#else /* __powerpc64__ */
4083+
4084+#define __copy_in_user(to, from, size) \
4085+ __copy_tofrom_user((to), (from), (size))
4086+
4087+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4088+{
4089+ if ((long)n < 0 || n > INT_MAX)
4090+ return n;
4091+
4092+ if (!__builtin_constant_p(n))
4093+ check_object_size(to, n, false);
4094+
4095+ if (likely(access_ok(VERIFY_READ, from, n)))
4096+ n = __copy_from_user(to, from, n);
4097+ else
4098+ memset(to, 0, n);
4099+ return n;
4100+}
4101+
4102+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4103+{
4104+ if ((long)n < 0 || n > INT_MAX)
4105+ return n;
4106+
4107+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
4108+ if (!__builtin_constant_p(n))
4109+ check_object_size(from, n, true);
4110+ n = __copy_to_user(to, from, n);
4111+ }
4112+ return n;
4113+}
4114+
4115+extern unsigned long copy_in_user(void __user *to, const void __user *from,
4116+ unsigned long n);
4117+
4118+#endif /* __powerpc64__ */
4119+
4120 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4121
4122 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4123diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4124index 98be7f0..8ef62de 100644
4125--- a/arch/powerpc/kernel/exceptions-64e.S
4126+++ b/arch/powerpc/kernel/exceptions-64e.S
4127@@ -661,6 +661,7 @@ storage_fault_common:
4128 std r14,_DAR(r1)
4129 std r15,_DSISR(r1)
4130 addi r3,r1,STACK_FRAME_OVERHEAD
4131+ bl .save_nvgprs
4132 mr r4,r14
4133 mr r5,r15
4134 ld r14,PACA_EXGEN+EX_R14(r13)
4135@@ -669,8 +670,7 @@ storage_fault_common:
4136 cmpdi r3,0
4137 bne- 1f
4138 b .ret_from_except_lite
4139-1: bl .save_nvgprs
4140- mr r5,r3
4141+1: mr r5,r3
4142 addi r3,r1,STACK_FRAME_OVERHEAD
4143 ld r4,_DAR(r1)
4144 bl .bad_page_fault
4145diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4146index 39aa97d..dc916ee 100644
4147--- a/arch/powerpc/kernel/exceptions-64s.S
4148+++ b/arch/powerpc/kernel/exceptions-64s.S
4149@@ -890,10 +890,10 @@ handle_page_fault:
4150 11: ld r4,_DAR(r1)
4151 ld r5,_DSISR(r1)
4152 addi r3,r1,STACK_FRAME_OVERHEAD
4153+ bl .save_nvgprs
4154 bl .do_page_fault
4155 cmpdi r3,0
4156 beq+ 12f
4157- bl .save_nvgprs
4158 mr r5,r3
4159 addi r3,r1,STACK_FRAME_OVERHEAD
4160 lwz r4,_DAR(r1)
4161diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4162index 2e3200c..72095ce 100644
4163--- a/arch/powerpc/kernel/module_32.c
4164+++ b/arch/powerpc/kernel/module_32.c
4165@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4166 me->arch.core_plt_section = i;
4167 }
4168 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4169- printk("Module doesn't contain .plt or .init.plt sections.\n");
4170+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4171 return -ENOEXEC;
4172 }
4173
4174@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4175
4176 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4177 /* Init, or core PLT? */
4178- if (location >= mod->module_core
4179- && location < mod->module_core + mod->core_size)
4180+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4181+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4182 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4183- else
4184+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4185+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4186 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4187+ else {
4188+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4189+ return ~0UL;
4190+ }
4191
4192 /* Find this entry, or if that fails, the next avail. entry */
4193 while (entry->jump[0]) {
4194diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4195index 1a1f2dd..f4d1bb4 100644
4196--- a/arch/powerpc/kernel/process.c
4197+++ b/arch/powerpc/kernel/process.c
4198@@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4199 * Lookup NIP late so we have the best change of getting the
4200 * above info out without failing
4201 */
4202- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4203- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4204+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4205+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4206 #endif
4207 show_stack(current, (unsigned long *) regs->gpr[1]);
4208 if (!user_mode(regs))
4209@@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4210 newsp = stack[0];
4211 ip = stack[STACK_FRAME_LR_SAVE];
4212 if (!firstframe || ip != lr) {
4213- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4214+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4215 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4216 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4217- printk(" (%pS)",
4218+ printk(" (%pA)",
4219 (void *)current->ret_stack[curr_frame].ret);
4220 curr_frame--;
4221 }
4222@@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4223 struct pt_regs *regs = (struct pt_regs *)
4224 (sp + STACK_FRAME_OVERHEAD);
4225 lr = regs->link;
4226- printk("--- Exception: %lx at %pS\n LR = %pS\n",
4227+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
4228 regs->trap, (void *)regs->nip, (void *)lr);
4229 firstframe = 1;
4230 }
4231@@ -1246,58 +1246,3 @@ void __ppc64_runlatch_off(void)
4232 mtspr(SPRN_CTRLT, ctrl);
4233 }
4234 #endif /* CONFIG_PPC64 */
4235-
4236-unsigned long arch_align_stack(unsigned long sp)
4237-{
4238- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4239- sp -= get_random_int() & ~PAGE_MASK;
4240- return sp & ~0xf;
4241-}
4242-
4243-static inline unsigned long brk_rnd(void)
4244-{
4245- unsigned long rnd = 0;
4246-
4247- /* 8MB for 32bit, 1GB for 64bit */
4248- if (is_32bit_task())
4249- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4250- else
4251- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4252-
4253- return rnd << PAGE_SHIFT;
4254-}
4255-
4256-unsigned long arch_randomize_brk(struct mm_struct *mm)
4257-{
4258- unsigned long base = mm->brk;
4259- unsigned long ret;
4260-
4261-#ifdef CONFIG_PPC_STD_MMU_64
4262- /*
4263- * If we are using 1TB segments and we are allowed to randomise
4264- * the heap, we can put it above 1TB so it is backed by a 1TB
4265- * segment. Otherwise the heap will be in the bottom 1TB
4266- * which always uses 256MB segments and this may result in a
4267- * performance penalty.
4268- */
4269- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4270- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4271-#endif
4272-
4273- ret = PAGE_ALIGN(base + brk_rnd());
4274-
4275- if (ret < mm->brk)
4276- return mm->brk;
4277-
4278- return ret;
4279-}
4280-
4281-unsigned long randomize_et_dyn(unsigned long base)
4282-{
4283- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4284-
4285- if (ret < base)
4286- return base;
4287-
4288- return ret;
4289-}
4290diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4291index c10fc28..c4ef063 100644
4292--- a/arch/powerpc/kernel/ptrace.c
4293+++ b/arch/powerpc/kernel/ptrace.c
4294@@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4295 return ret;
4296 }
4297
4298+#ifdef CONFIG_GRKERNSEC_SETXID
4299+extern void gr_delayed_cred_worker(void);
4300+#endif
4301+
4302 /*
4303 * We must return the syscall number to actually look up in the table.
4304 * This can be -1L to skip running any syscall at all.
4305@@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4306
4307 secure_computing_strict(regs->gpr[0]);
4308
4309+#ifdef CONFIG_GRKERNSEC_SETXID
4310+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4311+ gr_delayed_cred_worker();
4312+#endif
4313+
4314 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4315 tracehook_report_syscall_entry(regs))
4316 /*
4317@@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4318 {
4319 int step;
4320
4321+#ifdef CONFIG_GRKERNSEC_SETXID
4322+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4323+ gr_delayed_cred_worker();
4324+#endif
4325+
4326 audit_syscall_exit(regs);
4327
4328 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4329diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4330index 8b4c049..dcd6ef3 100644
4331--- a/arch/powerpc/kernel/signal_32.c
4332+++ b/arch/powerpc/kernel/signal_32.c
4333@@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4334 /* Save user registers on the stack */
4335 frame = &rt_sf->uc.uc_mcontext;
4336 addr = frame;
4337- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4338+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4339 if (save_user_regs(regs, frame, 0, 1))
4340 goto badframe;
4341 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4342diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4343index d183f87..1867f1a 100644
4344--- a/arch/powerpc/kernel/signal_64.c
4345+++ b/arch/powerpc/kernel/signal_64.c
4346@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4347 current->thread.fpscr.val = 0;
4348
4349 /* Set up to return from userspace. */
4350- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4351+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4352 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4353 } else {
4354 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4355diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4356index ae0843f..f16372c 100644
4357--- a/arch/powerpc/kernel/traps.c
4358+++ b/arch/powerpc/kernel/traps.c
4359@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4360 return flags;
4361 }
4362
4363+extern void gr_handle_kernel_exploit(void);
4364+
4365 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4366 int signr)
4367 {
4368@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4369 panic("Fatal exception in interrupt");
4370 if (panic_on_oops)
4371 panic("Fatal exception");
4372+
4373+ gr_handle_kernel_exploit();
4374+
4375 do_exit(signr);
4376 }
4377
4378diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4379index b67db22..38825d2 100644
4380--- a/arch/powerpc/kernel/vdso.c
4381+++ b/arch/powerpc/kernel/vdso.c
4382@@ -34,6 +34,7 @@
4383 #include <asm/firmware.h>
4384 #include <asm/vdso.h>
4385 #include <asm/vdso_datapage.h>
4386+#include <asm/mman.h>
4387
4388 #include "setup.h"
4389
4390@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4391 vdso_base = VDSO32_MBASE;
4392 #endif
4393
4394- current->mm->context.vdso_base = 0;
4395+ current->mm->context.vdso_base = ~0UL;
4396
4397 /* vDSO has a problem and was disabled, just don't "enable" it for the
4398 * process
4399@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4400 vdso_base = get_unmapped_area(NULL, vdso_base,
4401 (vdso_pages << PAGE_SHIFT) +
4402 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4403- 0, 0);
4404+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
4405 if (IS_ERR_VALUE(vdso_base)) {
4406 rc = vdso_base;
4407 goto fail_mmapsem;
4408diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4409index 5eea6f3..5d10396 100644
4410--- a/arch/powerpc/lib/usercopy_64.c
4411+++ b/arch/powerpc/lib/usercopy_64.c
4412@@ -9,22 +9,6 @@
4413 #include <linux/module.h>
4414 #include <asm/uaccess.h>
4415
4416-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4417-{
4418- if (likely(access_ok(VERIFY_READ, from, n)))
4419- n = __copy_from_user(to, from, n);
4420- else
4421- memset(to, 0, n);
4422- return n;
4423-}
4424-
4425-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4426-{
4427- if (likely(access_ok(VERIFY_WRITE, to, n)))
4428- n = __copy_to_user(to, from, n);
4429- return n;
4430-}
4431-
4432 unsigned long copy_in_user(void __user *to, const void __user *from,
4433 unsigned long n)
4434 {
4435@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4436 return n;
4437 }
4438
4439-EXPORT_SYMBOL(copy_from_user);
4440-EXPORT_SYMBOL(copy_to_user);
4441 EXPORT_SYMBOL(copy_in_user);
4442
4443diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4444index 08ffcf5..a0ab912 100644
4445--- a/arch/powerpc/mm/fault.c
4446+++ b/arch/powerpc/mm/fault.c
4447@@ -32,6 +32,10 @@
4448 #include <linux/perf_event.h>
4449 #include <linux/magic.h>
4450 #include <linux/ratelimit.h>
4451+#include <linux/slab.h>
4452+#include <linux/pagemap.h>
4453+#include <linux/compiler.h>
4454+#include <linux/unistd.h>
4455
4456 #include <asm/firmware.h>
4457 #include <asm/page.h>
4458@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4459 }
4460 #endif
4461
4462+#ifdef CONFIG_PAX_PAGEEXEC
4463+/*
4464+ * PaX: decide what to do with offenders (regs->nip = fault address)
4465+ *
4466+ * returns 1 when task should be killed
4467+ */
4468+static int pax_handle_fetch_fault(struct pt_regs *regs)
4469+{
4470+ return 1;
4471+}
4472+
4473+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4474+{
4475+ unsigned long i;
4476+
4477+ printk(KERN_ERR "PAX: bytes at PC: ");
4478+ for (i = 0; i < 5; i++) {
4479+ unsigned int c;
4480+ if (get_user(c, (unsigned int __user *)pc+i))
4481+ printk(KERN_CONT "???????? ");
4482+ else
4483+ printk(KERN_CONT "%08x ", c);
4484+ }
4485+ printk("\n");
4486+}
4487+#endif
4488+
4489 /*
4490 * Check whether the instruction at regs->nip is a store using
4491 * an update addressing form which will update r1.
4492@@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4493 * indicate errors in DSISR but can validly be set in SRR1.
4494 */
4495 if (trap == 0x400)
4496- error_code &= 0x48200000;
4497+ error_code &= 0x58200000;
4498 else
4499 is_write = error_code & DSISR_ISSTORE;
4500 #else
4501@@ -366,7 +397,7 @@ good_area:
4502 * "undefined". Of those that can be set, this is the only
4503 * one which seems bad.
4504 */
4505- if (error_code & 0x10000000)
4506+ if (error_code & DSISR_GUARDED)
4507 /* Guarded storage error. */
4508 goto bad_area;
4509 #endif /* CONFIG_8xx */
4510@@ -381,7 +412,7 @@ good_area:
4511 * processors use the same I/D cache coherency mechanism
4512 * as embedded.
4513 */
4514- if (error_code & DSISR_PROTFAULT)
4515+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4516 goto bad_area;
4517 #endif /* CONFIG_PPC_STD_MMU */
4518
4519@@ -463,6 +494,23 @@ bad_area:
4520 bad_area_nosemaphore:
4521 /* User mode accesses cause a SIGSEGV */
4522 if (user_mode(regs)) {
4523+
4524+#ifdef CONFIG_PAX_PAGEEXEC
4525+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4526+#ifdef CONFIG_PPC_STD_MMU
4527+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4528+#else
4529+ if (is_exec && regs->nip == address) {
4530+#endif
4531+ switch (pax_handle_fetch_fault(regs)) {
4532+ }
4533+
4534+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4535+ do_group_exit(SIGKILL);
4536+ }
4537+ }
4538+#endif
4539+
4540 _exception(SIGSEGV, regs, code, address);
4541 return 0;
4542 }
4543diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4544index 67a42ed..1c7210c 100644
4545--- a/arch/powerpc/mm/mmap_64.c
4546+++ b/arch/powerpc/mm/mmap_64.c
4547@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4548 */
4549 if (mmap_is_legacy()) {
4550 mm->mmap_base = TASK_UNMAPPED_BASE;
4551+
4552+#ifdef CONFIG_PAX_RANDMMAP
4553+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4554+ mm->mmap_base += mm->delta_mmap;
4555+#endif
4556+
4557 mm->get_unmapped_area = arch_get_unmapped_area;
4558 mm->unmap_area = arch_unmap_area;
4559 } else {
4560 mm->mmap_base = mmap_base();
4561+
4562+#ifdef CONFIG_PAX_RANDMMAP
4563+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4564+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4565+#endif
4566+
4567 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4568 mm->unmap_area = arch_unmap_area_topdown;
4569 }
4570diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4571index 73709f7..6b90313 100644
4572--- a/arch/powerpc/mm/slice.c
4573+++ b/arch/powerpc/mm/slice.c
4574@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4575 if ((mm->task_size - len) < addr)
4576 return 0;
4577 vma = find_vma(mm, addr);
4578- return (!vma || (addr + len) <= vma->vm_start);
4579+ return check_heap_stack_gap(vma, addr, len);
4580 }
4581
4582 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4583@@ -256,7 +256,7 @@ full_search:
4584 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4585 continue;
4586 }
4587- if (!vma || addr + len <= vma->vm_start) {
4588+ if (check_heap_stack_gap(vma, addr, len)) {
4589 /*
4590 * Remember the place where we stopped the search:
4591 */
4592@@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4593 }
4594 }
4595
4596- addr = mm->mmap_base;
4597- while (addr > len) {
4598+ if (mm->mmap_base < len)
4599+ addr = -ENOMEM;
4600+ else
4601+ addr = mm->mmap_base - len;
4602+
4603+ while (!IS_ERR_VALUE(addr)) {
4604 /* Go down by chunk size */
4605- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4606+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
4607
4608 /* Check for hit with different page size */
4609 mask = slice_range_to_mask(addr, len);
4610@@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4611 * return with success:
4612 */
4613 vma = find_vma(mm, addr);
4614- if (!vma || (addr + len) <= vma->vm_start) {
4615+ if (check_heap_stack_gap(vma, addr, len)) {
4616 /* remember the address as a hint for next time */
4617 if (use_cache)
4618 mm->free_area_cache = addr;
4619@@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4620 mm->cached_hole_size = vma->vm_start - addr;
4621
4622 /* try just below the current vma->vm_start */
4623- addr = vma->vm_start;
4624+ addr = skip_heap_stack_gap(vma, len);
4625 }
4626
4627 /*
4628@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4629 if (fixed && addr > (mm->task_size - len))
4630 return -EINVAL;
4631
4632+#ifdef CONFIG_PAX_RANDMMAP
4633+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4634+ addr = 0;
4635+#endif
4636+
4637 /* If hint, make sure it matches our alignment restrictions */
4638 if (!fixed && addr) {
4639 addr = _ALIGN_UP(addr, 1ul << pshift);
4640diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4641index c797832..ce575c8 100644
4642--- a/arch/s390/include/asm/atomic.h
4643+++ b/arch/s390/include/asm/atomic.h
4644@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4645 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4646 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4647
4648+#define atomic64_read_unchecked(v) atomic64_read(v)
4649+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4650+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4651+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4652+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4653+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4654+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4655+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4656+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4657+
4658 #define smp_mb__before_atomic_dec() smp_mb()
4659 #define smp_mb__after_atomic_dec() smp_mb()
4660 #define smp_mb__before_atomic_inc() smp_mb()
4661diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4662index 4d7ccac..d03d0ad 100644
4663--- a/arch/s390/include/asm/cache.h
4664+++ b/arch/s390/include/asm/cache.h
4665@@ -9,8 +9,10 @@
4666 #ifndef __ARCH_S390_CACHE_H
4667 #define __ARCH_S390_CACHE_H
4668
4669-#define L1_CACHE_BYTES 256
4670+#include <linux/const.h>
4671+
4672 #define L1_CACHE_SHIFT 8
4673+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4674 #define NET_SKB_PAD 32
4675
4676 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4677diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4678index 9b94a16..63d4034 100644
4679--- a/arch/s390/include/asm/elf.h
4680+++ b/arch/s390/include/asm/elf.h
4681@@ -159,8 +159,14 @@ extern unsigned int vdso_enabled;
4682 the loader. We need to make sure that it is out of the way of the program
4683 that it will "exec", and that there is sufficient room for the brk. */
4684
4685-extern unsigned long randomize_et_dyn(unsigned long base);
4686-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4687+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4688+
4689+#ifdef CONFIG_PAX_ASLR
4690+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4691+
4692+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4693+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4694+#endif
4695
4696 /* This yields a mask that user programs can use to figure out what
4697 instruction set this CPU supports. */
4698@@ -209,7 +215,4 @@ struct linux_binprm;
4699 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4700 int arch_setup_additional_pages(struct linux_binprm *, int);
4701
4702-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4703-#define arch_randomize_brk arch_randomize_brk
4704-
4705 #endif
4706diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4707index c4a93d6..4d2a9b4 100644
4708--- a/arch/s390/include/asm/exec.h
4709+++ b/arch/s390/include/asm/exec.h
4710@@ -7,6 +7,6 @@
4711 #ifndef __ASM_EXEC_H
4712 #define __ASM_EXEC_H
4713
4714-extern unsigned long arch_align_stack(unsigned long sp);
4715+#define arch_align_stack(x) ((x) & ~0xfUL)
4716
4717 #endif /* __ASM_EXEC_H */
4718diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4719index a8ab18b..75ddbf0 100644
4720--- a/arch/s390/include/asm/uaccess.h
4721+++ b/arch/s390/include/asm/uaccess.h
4722@@ -239,6 +239,10 @@ static inline unsigned long __must_check
4723 copy_to_user(void __user *to, const void *from, unsigned long n)
4724 {
4725 might_fault();
4726+
4727+ if ((long)n < 0)
4728+ return n;
4729+
4730 if (access_ok(VERIFY_WRITE, to, n))
4731 n = __copy_to_user(to, from, n);
4732 return n;
4733@@ -264,6 +268,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4734 static inline unsigned long __must_check
4735 __copy_from_user(void *to, const void __user *from, unsigned long n)
4736 {
4737+ if ((long)n < 0)
4738+ return n;
4739+
4740 if (__builtin_constant_p(n) && (n <= 256))
4741 return uaccess.copy_from_user_small(n, from, to);
4742 else
4743@@ -295,10 +302,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4744 static inline unsigned long __must_check
4745 copy_from_user(void *to, const void __user *from, unsigned long n)
4746 {
4747- unsigned int sz = __compiletime_object_size(to);
4748+ size_t sz = __compiletime_object_size(to);
4749
4750 might_fault();
4751- if (unlikely(sz != -1 && sz < n)) {
4752+
4753+ if ((long)n < 0)
4754+ return n;
4755+
4756+ if (unlikely(sz != (size_t)-1 && sz < n)) {
4757 copy_from_user_overflow();
4758 return n;
4759 }
4760diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4761index 46412b1..e32874f 100644
4762--- a/arch/s390/kernel/module.c
4763+++ b/arch/s390/kernel/module.c
4764@@ -160,11 +160,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4765
4766 /* Increase core size by size of got & plt and set start
4767 offsets for got and plt. */
4768- me->core_size = ALIGN(me->core_size, 4);
4769- me->arch.got_offset = me->core_size;
4770- me->core_size += me->arch.got_size;
4771- me->arch.plt_offset = me->core_size;
4772- me->core_size += me->arch.plt_size;
4773+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
4774+ me->arch.got_offset = me->core_size_rw;
4775+ me->core_size_rw += me->arch.got_size;
4776+ me->arch.plt_offset = me->core_size_rx;
4777+ me->core_size_rx += me->arch.plt_size;
4778 return 0;
4779 }
4780
4781@@ -241,7 +241,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4782 if (info->got_initialized == 0) {
4783 Elf_Addr *gotent;
4784
4785- gotent = me->module_core + me->arch.got_offset +
4786+ gotent = me->module_core_rw + me->arch.got_offset +
4787 info->got_offset;
4788 *gotent = val;
4789 info->got_initialized = 1;
4790@@ -265,7 +265,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4791 else if (r_type == R_390_GOTENT ||
4792 r_type == R_390_GOTPLTENT)
4793 *(unsigned int *) loc =
4794- (val + (Elf_Addr) me->module_core - loc) >> 1;
4795+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4796 else if (r_type == R_390_GOT64 ||
4797 r_type == R_390_GOTPLT64)
4798 *(unsigned long *) loc = val;
4799@@ -279,7 +279,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4800 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4801 if (info->plt_initialized == 0) {
4802 unsigned int *ip;
4803- ip = me->module_core + me->arch.plt_offset +
4804+ ip = me->module_core_rx + me->arch.plt_offset +
4805 info->plt_offset;
4806 #ifndef CONFIG_64BIT
4807 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4808@@ -304,7 +304,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4809 val - loc + 0xffffUL < 0x1ffffeUL) ||
4810 (r_type == R_390_PLT32DBL &&
4811 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4812- val = (Elf_Addr) me->module_core +
4813+ val = (Elf_Addr) me->module_core_rx +
4814 me->arch.plt_offset +
4815 info->plt_offset;
4816 val += rela->r_addend - loc;
4817@@ -326,7 +326,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4818 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4819 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4820 val = val + rela->r_addend -
4821- ((Elf_Addr) me->module_core + me->arch.got_offset);
4822+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4823 if (r_type == R_390_GOTOFF16)
4824 *(unsigned short *) loc = val;
4825 else if (r_type == R_390_GOTOFF32)
4826@@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4827 break;
4828 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4829 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4830- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4831+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4832 rela->r_addend - loc;
4833 if (r_type == R_390_GOTPC)
4834 *(unsigned int *) loc = val;
4835diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4836index 7331753..dd71de4 100644
4837--- a/arch/s390/kernel/process.c
4838+++ b/arch/s390/kernel/process.c
4839@@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4840 }
4841 return 0;
4842 }
4843-
4844-unsigned long arch_align_stack(unsigned long sp)
4845-{
4846- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4847- sp -= get_random_int() & ~PAGE_MASK;
4848- return sp & ~0xf;
4849-}
4850-
4851-static inline unsigned long brk_rnd(void)
4852-{
4853- /* 8MB for 32bit, 1GB for 64bit */
4854- if (is_32bit_task())
4855- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4856- else
4857- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4858-}
4859-
4860-unsigned long arch_randomize_brk(struct mm_struct *mm)
4861-{
4862- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4863-
4864- if (ret < mm->brk)
4865- return mm->brk;
4866- return ret;
4867-}
4868-
4869-unsigned long randomize_et_dyn(unsigned long base)
4870-{
4871- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4872-
4873- if (!(current->flags & PF_RANDOMIZE))
4874- return base;
4875- if (ret < base)
4876- return base;
4877- return ret;
4878-}
4879diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4880index c59a5ef..3fae59c 100644
4881--- a/arch/s390/mm/mmap.c
4882+++ b/arch/s390/mm/mmap.c
4883@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4884 */
4885 if (mmap_is_legacy()) {
4886 mm->mmap_base = TASK_UNMAPPED_BASE;
4887+
4888+#ifdef CONFIG_PAX_RANDMMAP
4889+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4890+ mm->mmap_base += mm->delta_mmap;
4891+#endif
4892+
4893 mm->get_unmapped_area = arch_get_unmapped_area;
4894 mm->unmap_area = arch_unmap_area;
4895 } else {
4896 mm->mmap_base = mmap_base();
4897+
4898+#ifdef CONFIG_PAX_RANDMMAP
4899+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4900+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4901+#endif
4902+
4903 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4904 mm->unmap_area = arch_unmap_area_topdown;
4905 }
4906@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4907 */
4908 if (mmap_is_legacy()) {
4909 mm->mmap_base = TASK_UNMAPPED_BASE;
4910+
4911+#ifdef CONFIG_PAX_RANDMMAP
4912+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4913+ mm->mmap_base += mm->delta_mmap;
4914+#endif
4915+
4916 mm->get_unmapped_area = s390_get_unmapped_area;
4917 mm->unmap_area = arch_unmap_area;
4918 } else {
4919 mm->mmap_base = mmap_base();
4920+
4921+#ifdef CONFIG_PAX_RANDMMAP
4922+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4923+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4924+#endif
4925+
4926 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4927 mm->unmap_area = arch_unmap_area_topdown;
4928 }
4929diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4930index ae3d59f..f65f075 100644
4931--- a/arch/score/include/asm/cache.h
4932+++ b/arch/score/include/asm/cache.h
4933@@ -1,7 +1,9 @@
4934 #ifndef _ASM_SCORE_CACHE_H
4935 #define _ASM_SCORE_CACHE_H
4936
4937+#include <linux/const.h>
4938+
4939 #define L1_CACHE_SHIFT 4
4940-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4941+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4942
4943 #endif /* _ASM_SCORE_CACHE_H */
4944diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4945index f9f3cd5..58ff438 100644
4946--- a/arch/score/include/asm/exec.h
4947+++ b/arch/score/include/asm/exec.h
4948@@ -1,6 +1,6 @@
4949 #ifndef _ASM_SCORE_EXEC_H
4950 #define _ASM_SCORE_EXEC_H
4951
4952-extern unsigned long arch_align_stack(unsigned long sp);
4953+#define arch_align_stack(x) (x)
4954
4955 #endif /* _ASM_SCORE_EXEC_H */
4956diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4957index 2707023..1c2a3b7 100644
4958--- a/arch/score/kernel/process.c
4959+++ b/arch/score/kernel/process.c
4960@@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
4961
4962 return task_pt_regs(task)->cp0_epc;
4963 }
4964-
4965-unsigned long arch_align_stack(unsigned long sp)
4966-{
4967- return sp;
4968-}
4969diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4970index ef9e555..331bd29 100644
4971--- a/arch/sh/include/asm/cache.h
4972+++ b/arch/sh/include/asm/cache.h
4973@@ -9,10 +9,11 @@
4974 #define __ASM_SH_CACHE_H
4975 #ifdef __KERNEL__
4976
4977+#include <linux/const.h>
4978 #include <linux/init.h>
4979 #include <cpu/cache.h>
4980
4981-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4982+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4983
4984 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4985
4986diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4987index afeb710..d1d1289 100644
4988--- a/arch/sh/mm/mmap.c
4989+++ b/arch/sh/mm/mmap.c
4990@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4991 addr = PAGE_ALIGN(addr);
4992
4993 vma = find_vma(mm, addr);
4994- if (TASK_SIZE - len >= addr &&
4995- (!vma || addr + len <= vma->vm_start))
4996+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4997 return addr;
4998 }
4999
5000@@ -106,7 +105,7 @@ full_search:
5001 }
5002 return -ENOMEM;
5003 }
5004- if (likely(!vma || addr + len <= vma->vm_start)) {
5005+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5006 /*
5007 * Remember the place where we stopped the search:
5008 */
5009@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5010 addr = PAGE_ALIGN(addr);
5011
5012 vma = find_vma(mm, addr);
5013- if (TASK_SIZE - len >= addr &&
5014- (!vma || addr + len <= vma->vm_start))
5015+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5016 return addr;
5017 }
5018
5019@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5020 /* make sure it can fit in the remaining address space */
5021 if (likely(addr > len)) {
5022 vma = find_vma(mm, addr-len);
5023- if (!vma || addr <= vma->vm_start) {
5024+ if (check_heap_stack_gap(vma, addr - len, len)) {
5025 /* remember the address as a hint for next time */
5026 return (mm->free_area_cache = addr-len);
5027 }
5028@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5029 if (unlikely(mm->mmap_base < len))
5030 goto bottomup;
5031
5032- addr = mm->mmap_base-len;
5033- if (do_colour_align)
5034- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5035+ addr = mm->mmap_base - len;
5036
5037 do {
5038+ if (do_colour_align)
5039+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5040 /*
5041 * Lookup failure means no vma is above this address,
5042 * else if new region fits below vma->vm_start,
5043 * return with success:
5044 */
5045 vma = find_vma(mm, addr);
5046- if (likely(!vma || addr+len <= vma->vm_start)) {
5047+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5048 /* remember the address as a hint for next time */
5049 return (mm->free_area_cache = addr);
5050 }
5051@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5052 mm->cached_hole_size = vma->vm_start - addr;
5053
5054 /* try just below the current vma->vm_start */
5055- addr = vma->vm_start-len;
5056- if (do_colour_align)
5057- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5058- } while (likely(len < vma->vm_start));
5059+ addr = skip_heap_stack_gap(vma, len);
5060+ } while (!IS_ERR_VALUE(addr));
5061
5062 bottomup:
5063 /*
5064diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5065index ce35a1c..2e7b8f9 100644
5066--- a/arch/sparc/include/asm/atomic_64.h
5067+++ b/arch/sparc/include/asm/atomic_64.h
5068@@ -14,18 +14,40 @@
5069 #define ATOMIC64_INIT(i) { (i) }
5070
5071 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5072+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5073+{
5074+ return v->counter;
5075+}
5076 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5077+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5078+{
5079+ return v->counter;
5080+}
5081
5082 #define atomic_set(v, i) (((v)->counter) = i)
5083+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5084+{
5085+ v->counter = i;
5086+}
5087 #define atomic64_set(v, i) (((v)->counter) = i)
5088+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5089+{
5090+ v->counter = i;
5091+}
5092
5093 extern void atomic_add(int, atomic_t *);
5094+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5095 extern void atomic64_add(long, atomic64_t *);
5096+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5097 extern void atomic_sub(int, atomic_t *);
5098+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5099 extern void atomic64_sub(long, atomic64_t *);
5100+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5101
5102 extern int atomic_add_ret(int, atomic_t *);
5103+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5104 extern long atomic64_add_ret(long, atomic64_t *);
5105+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5106 extern int atomic_sub_ret(int, atomic_t *);
5107 extern long atomic64_sub_ret(long, atomic64_t *);
5108
5109@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5110 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5111
5112 #define atomic_inc_return(v) atomic_add_ret(1, v)
5113+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5114+{
5115+ return atomic_add_ret_unchecked(1, v);
5116+}
5117 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5118+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5119+{
5120+ return atomic64_add_ret_unchecked(1, v);
5121+}
5122
5123 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5124 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5125
5126 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5127+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5128+{
5129+ return atomic_add_ret_unchecked(i, v);
5130+}
5131 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5132+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5133+{
5134+ return atomic64_add_ret_unchecked(i, v);
5135+}
5136
5137 /*
5138 * atomic_inc_and_test - increment and test
5139@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5140 * other cases.
5141 */
5142 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5143+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5144+{
5145+ return atomic_inc_return_unchecked(v) == 0;
5146+}
5147 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5148
5149 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5150@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5151 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5152
5153 #define atomic_inc(v) atomic_add(1, v)
5154+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5155+{
5156+ atomic_add_unchecked(1, v);
5157+}
5158 #define atomic64_inc(v) atomic64_add(1, v)
5159+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5160+{
5161+ atomic64_add_unchecked(1, v);
5162+}
5163
5164 #define atomic_dec(v) atomic_sub(1, v)
5165+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5166+{
5167+ atomic_sub_unchecked(1, v);
5168+}
5169 #define atomic64_dec(v) atomic64_sub(1, v)
5170+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5171+{
5172+ atomic64_sub_unchecked(1, v);
5173+}
5174
5175 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5176 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5177
5178 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5179+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5180+{
5181+ return cmpxchg(&v->counter, old, new);
5182+}
5183 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5184+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5185+{
5186+ return xchg(&v->counter, new);
5187+}
5188
5189 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5190 {
5191- int c, old;
5192+ int c, old, new;
5193 c = atomic_read(v);
5194 for (;;) {
5195- if (unlikely(c == (u)))
5196+ if (unlikely(c == u))
5197 break;
5198- old = atomic_cmpxchg((v), c, c + (a));
5199+
5200+ asm volatile("addcc %2, %0, %0\n"
5201+
5202+#ifdef CONFIG_PAX_REFCOUNT
5203+ "tvs %%icc, 6\n"
5204+#endif
5205+
5206+ : "=r" (new)
5207+ : "0" (c), "ir" (a)
5208+ : "cc");
5209+
5210+ old = atomic_cmpxchg(v, c, new);
5211 if (likely(old == c))
5212 break;
5213 c = old;
5214@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5215 #define atomic64_cmpxchg(v, o, n) \
5216 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5217 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5218+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5219+{
5220+ return xchg(&v->counter, new);
5221+}
5222
5223 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5224 {
5225- long c, old;
5226+ long c, old, new;
5227 c = atomic64_read(v);
5228 for (;;) {
5229- if (unlikely(c == (u)))
5230+ if (unlikely(c == u))
5231 break;
5232- old = atomic64_cmpxchg((v), c, c + (a));
5233+
5234+ asm volatile("addcc %2, %0, %0\n"
5235+
5236+#ifdef CONFIG_PAX_REFCOUNT
5237+ "tvs %%xcc, 6\n"
5238+#endif
5239+
5240+ : "=r" (new)
5241+ : "0" (c), "ir" (a)
5242+ : "cc");
5243+
5244+ old = atomic64_cmpxchg(v, c, new);
5245 if (likely(old == c))
5246 break;
5247 c = old;
5248 }
5249- return c != (u);
5250+ return c != u;
5251 }
5252
5253 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5254diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5255index 5bb6991..5c2132e 100644
5256--- a/arch/sparc/include/asm/cache.h
5257+++ b/arch/sparc/include/asm/cache.h
5258@@ -7,10 +7,12 @@
5259 #ifndef _SPARC_CACHE_H
5260 #define _SPARC_CACHE_H
5261
5262+#include <linux/const.h>
5263+
5264 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5265
5266 #define L1_CACHE_SHIFT 5
5267-#define L1_CACHE_BYTES 32
5268+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5269
5270 #ifdef CONFIG_SPARC32
5271 #define SMP_CACHE_BYTES_SHIFT 5
5272diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5273index 2d4d755..81b6662 100644
5274--- a/arch/sparc/include/asm/elf_32.h
5275+++ b/arch/sparc/include/asm/elf_32.h
5276@@ -114,6 +114,13 @@ typedef struct {
5277
5278 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5279
5280+#ifdef CONFIG_PAX_ASLR
5281+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5282+
5283+#define PAX_DELTA_MMAP_LEN 16
5284+#define PAX_DELTA_STACK_LEN 16
5285+#endif
5286+
5287 /* This yields a mask that user programs can use to figure out what
5288 instruction set this cpu supports. This can NOT be done in userspace
5289 on Sparc. */
5290diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5291index 7df8b7f..4946269 100644
5292--- a/arch/sparc/include/asm/elf_64.h
5293+++ b/arch/sparc/include/asm/elf_64.h
5294@@ -180,6 +180,13 @@ typedef struct {
5295 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5296 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5297
5298+#ifdef CONFIG_PAX_ASLR
5299+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5300+
5301+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5302+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5303+#endif
5304+
5305 extern unsigned long sparc64_elf_hwcap;
5306 #define ELF_HWCAP sparc64_elf_hwcap
5307
5308diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5309index 9b1c36d..209298b 100644
5310--- a/arch/sparc/include/asm/pgalloc_32.h
5311+++ b/arch/sparc/include/asm/pgalloc_32.h
5312@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5313 }
5314
5315 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5316+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5317
5318 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5319 unsigned long address)
5320diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5321index 40b2d7a..22a665b 100644
5322--- a/arch/sparc/include/asm/pgalloc_64.h
5323+++ b/arch/sparc/include/asm/pgalloc_64.h
5324@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5325 }
5326
5327 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5328+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5329
5330 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5331 {
5332diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5333index 6fc1348..390c50a 100644
5334--- a/arch/sparc/include/asm/pgtable_32.h
5335+++ b/arch/sparc/include/asm/pgtable_32.h
5336@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5337 #define PAGE_SHARED SRMMU_PAGE_SHARED
5338 #define PAGE_COPY SRMMU_PAGE_COPY
5339 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5340+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5341+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5342+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5343 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5344
5345 /* Top-level page directory - dummy used by init-mm.
5346@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
5347
5348 /* xwr */
5349 #define __P000 PAGE_NONE
5350-#define __P001 PAGE_READONLY
5351-#define __P010 PAGE_COPY
5352-#define __P011 PAGE_COPY
5353+#define __P001 PAGE_READONLY_NOEXEC
5354+#define __P010 PAGE_COPY_NOEXEC
5355+#define __P011 PAGE_COPY_NOEXEC
5356 #define __P100 PAGE_READONLY
5357 #define __P101 PAGE_READONLY
5358 #define __P110 PAGE_COPY
5359 #define __P111 PAGE_COPY
5360
5361 #define __S000 PAGE_NONE
5362-#define __S001 PAGE_READONLY
5363-#define __S010 PAGE_SHARED
5364-#define __S011 PAGE_SHARED
5365+#define __S001 PAGE_READONLY_NOEXEC
5366+#define __S010 PAGE_SHARED_NOEXEC
5367+#define __S011 PAGE_SHARED_NOEXEC
5368 #define __S100 PAGE_READONLY
5369 #define __S101 PAGE_READONLY
5370 #define __S110 PAGE_SHARED
5371diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5372index 79da178..c2eede8 100644
5373--- a/arch/sparc/include/asm/pgtsrmmu.h
5374+++ b/arch/sparc/include/asm/pgtsrmmu.h
5375@@ -115,6 +115,11 @@
5376 SRMMU_EXEC | SRMMU_REF)
5377 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5378 SRMMU_EXEC | SRMMU_REF)
5379+
5380+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5381+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5382+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5383+
5384 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5385 SRMMU_DIRTY | SRMMU_REF)
5386
5387diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5388index 9689176..63c18ea 100644
5389--- a/arch/sparc/include/asm/spinlock_64.h
5390+++ b/arch/sparc/include/asm/spinlock_64.h
5391@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5392
5393 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5394
5395-static void inline arch_read_lock(arch_rwlock_t *lock)
5396+static inline void arch_read_lock(arch_rwlock_t *lock)
5397 {
5398 unsigned long tmp1, tmp2;
5399
5400 __asm__ __volatile__ (
5401 "1: ldsw [%2], %0\n"
5402 " brlz,pn %0, 2f\n"
5403-"4: add %0, 1, %1\n"
5404+"4: addcc %0, 1, %1\n"
5405+
5406+#ifdef CONFIG_PAX_REFCOUNT
5407+" tvs %%icc, 6\n"
5408+#endif
5409+
5410 " cas [%2], %0, %1\n"
5411 " cmp %0, %1\n"
5412 " bne,pn %%icc, 1b\n"
5413@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5414 " .previous"
5415 : "=&r" (tmp1), "=&r" (tmp2)
5416 : "r" (lock)
5417- : "memory");
5418+ : "memory", "cc");
5419 }
5420
5421-static int inline arch_read_trylock(arch_rwlock_t *lock)
5422+static inline int arch_read_trylock(arch_rwlock_t *lock)
5423 {
5424 int tmp1, tmp2;
5425
5426@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5427 "1: ldsw [%2], %0\n"
5428 " brlz,a,pn %0, 2f\n"
5429 " mov 0, %0\n"
5430-" add %0, 1, %1\n"
5431+" addcc %0, 1, %1\n"
5432+
5433+#ifdef CONFIG_PAX_REFCOUNT
5434+" tvs %%icc, 6\n"
5435+#endif
5436+
5437 " cas [%2], %0, %1\n"
5438 " cmp %0, %1\n"
5439 " bne,pn %%icc, 1b\n"
5440@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5441 return tmp1;
5442 }
5443
5444-static void inline arch_read_unlock(arch_rwlock_t *lock)
5445+static inline void arch_read_unlock(arch_rwlock_t *lock)
5446 {
5447 unsigned long tmp1, tmp2;
5448
5449 __asm__ __volatile__(
5450 "1: lduw [%2], %0\n"
5451-" sub %0, 1, %1\n"
5452+" subcc %0, 1, %1\n"
5453+
5454+#ifdef CONFIG_PAX_REFCOUNT
5455+" tvs %%icc, 6\n"
5456+#endif
5457+
5458 " cas [%2], %0, %1\n"
5459 " cmp %0, %1\n"
5460 " bne,pn %%xcc, 1b\n"
5461@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5462 : "memory");
5463 }
5464
5465-static void inline arch_write_lock(arch_rwlock_t *lock)
5466+static inline void arch_write_lock(arch_rwlock_t *lock)
5467 {
5468 unsigned long mask, tmp1, tmp2;
5469
5470@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5471 : "memory");
5472 }
5473
5474-static void inline arch_write_unlock(arch_rwlock_t *lock)
5475+static inline void arch_write_unlock(arch_rwlock_t *lock)
5476 {
5477 __asm__ __volatile__(
5478 " stw %%g0, [%0]"
5479@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5480 : "memory");
5481 }
5482
5483-static int inline arch_write_trylock(arch_rwlock_t *lock)
5484+static inline int arch_write_trylock(arch_rwlock_t *lock)
5485 {
5486 unsigned long mask, tmp1, tmp2, result;
5487
5488diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5489index e6cd224..3a71793 100644
5490--- a/arch/sparc/include/asm/thread_info_32.h
5491+++ b/arch/sparc/include/asm/thread_info_32.h
5492@@ -49,6 +49,8 @@ struct thread_info {
5493 unsigned long w_saved;
5494
5495 struct restart_block restart_block;
5496+
5497+ unsigned long lowest_stack;
5498 };
5499
5500 /*
5501diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5502index cfa8c38..13f30d3 100644
5503--- a/arch/sparc/include/asm/thread_info_64.h
5504+++ b/arch/sparc/include/asm/thread_info_64.h
5505@@ -63,6 +63,8 @@ struct thread_info {
5506 struct pt_regs *kern_una_regs;
5507 unsigned int kern_una_insn;
5508
5509+ unsigned long lowest_stack;
5510+
5511 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5512 };
5513
5514@@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5515 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5516 /* flag bit 6 is available */
5517 #define TIF_32BIT 7 /* 32-bit binary */
5518-/* flag bit 8 is available */
5519+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5520 #define TIF_SECCOMP 9 /* secure computing */
5521 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5522 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5523+
5524 /* NOTE: Thread flags >= 12 should be ones we have no interest
5525 * in using in assembly, else we can't use the mask as
5526 * an immediate value in instructions such as andcc.
5527@@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5528 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5529 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5530 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5531+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5532
5533 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5534 _TIF_DO_NOTIFY_RESUME_MASK | \
5535 _TIF_NEED_RESCHED)
5536 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5537
5538+#define _TIF_WORK_SYSCALL \
5539+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5540+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5541+
5542+
5543 /*
5544 * Thread-synchronous status.
5545 *
5546diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5547index 0167d26..9acd8ed 100644
5548--- a/arch/sparc/include/asm/uaccess.h
5549+++ b/arch/sparc/include/asm/uaccess.h
5550@@ -1,5 +1,13 @@
5551 #ifndef ___ASM_SPARC_UACCESS_H
5552 #define ___ASM_SPARC_UACCESS_H
5553+
5554+#ifdef __KERNEL__
5555+#ifndef __ASSEMBLY__
5556+#include <linux/types.h>
5557+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5558+#endif
5559+#endif
5560+
5561 #if defined(__sparc__) && defined(__arch64__)
5562 #include <asm/uaccess_64.h>
5563 #else
5564diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5565index 53a28dd..50c38c3 100644
5566--- a/arch/sparc/include/asm/uaccess_32.h
5567+++ b/arch/sparc/include/asm/uaccess_32.h
5568@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5569
5570 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5571 {
5572- if (n && __access_ok((unsigned long) to, n))
5573+ if ((long)n < 0)
5574+ return n;
5575+
5576+ if (n && __access_ok((unsigned long) to, n)) {
5577+ if (!__builtin_constant_p(n))
5578+ check_object_size(from, n, true);
5579 return __copy_user(to, (__force void __user *) from, n);
5580- else
5581+ } else
5582 return n;
5583 }
5584
5585 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5586 {
5587+ if ((long)n < 0)
5588+ return n;
5589+
5590+ if (!__builtin_constant_p(n))
5591+ check_object_size(from, n, true);
5592+
5593 return __copy_user(to, (__force void __user *) from, n);
5594 }
5595
5596 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5597 {
5598- if (n && __access_ok((unsigned long) from, n))
5599+ if ((long)n < 0)
5600+ return n;
5601+
5602+ if (n && __access_ok((unsigned long) from, n)) {
5603+ if (!__builtin_constant_p(n))
5604+ check_object_size(to, n, false);
5605 return __copy_user((__force void __user *) to, from, n);
5606- else
5607+ } else
5608 return n;
5609 }
5610
5611 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5612 {
5613+ if ((long)n < 0)
5614+ return n;
5615+
5616 return __copy_user((__force void __user *) to, from, n);
5617 }
5618
5619diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5620index 7c831d8..d440ca7 100644
5621--- a/arch/sparc/include/asm/uaccess_64.h
5622+++ b/arch/sparc/include/asm/uaccess_64.h
5623@@ -10,6 +10,7 @@
5624 #include <linux/compiler.h>
5625 #include <linux/string.h>
5626 #include <linux/thread_info.h>
5627+#include <linux/kernel.h>
5628 #include <asm/asi.h>
5629 #include <asm/spitfire.h>
5630 #include <asm-generic/uaccess-unaligned.h>
5631@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5632 static inline unsigned long __must_check
5633 copy_from_user(void *to, const void __user *from, unsigned long size)
5634 {
5635- unsigned long ret = ___copy_from_user(to, from, size);
5636+ unsigned long ret;
5637
5638+ if ((long)size < 0 || size > INT_MAX)
5639+ return size;
5640+
5641+ if (!__builtin_constant_p(size))
5642+ check_object_size(to, size, false);
5643+
5644+ ret = ___copy_from_user(to, from, size);
5645 if (unlikely(ret))
5646 ret = copy_from_user_fixup(to, from, size);
5647
5648@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5649 static inline unsigned long __must_check
5650 copy_to_user(void __user *to, const void *from, unsigned long size)
5651 {
5652- unsigned long ret = ___copy_to_user(to, from, size);
5653+ unsigned long ret;
5654
5655+ if ((long)size < 0 || size > INT_MAX)
5656+ return size;
5657+
5658+ if (!__builtin_constant_p(size))
5659+ check_object_size(from, size, true);
5660+
5661+ ret = ___copy_to_user(to, from, size);
5662 if (unlikely(ret))
5663 ret = copy_to_user_fixup(to, from, size);
5664 return ret;
5665diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5666index 6cf591b..b49e65a 100644
5667--- a/arch/sparc/kernel/Makefile
5668+++ b/arch/sparc/kernel/Makefile
5669@@ -3,7 +3,7 @@
5670 #
5671
5672 asflags-y := -ansi
5673-ccflags-y := -Werror
5674+#ccflags-y := -Werror
5675
5676 extra-y := head_$(BITS).o
5677
5678diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5679index 14006d8..8146238 100644
5680--- a/arch/sparc/kernel/process_32.c
5681+++ b/arch/sparc/kernel/process_32.c
5682@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5683
5684 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5685 r->psr, r->pc, r->npc, r->y, print_tainted());
5686- printk("PC: <%pS>\n", (void *) r->pc);
5687+ printk("PC: <%pA>\n", (void *) r->pc);
5688 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5689 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5690 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5691 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5692 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5693 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5694- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5695+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5696
5697 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5698 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5699@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5700 rw = (struct reg_window32 *) fp;
5701 pc = rw->ins[7];
5702 printk("[%08lx : ", pc);
5703- printk("%pS ] ", (void *) pc);
5704+ printk("%pA ] ", (void *) pc);
5705 fp = rw->ins[6];
5706 } while (++count < 16);
5707 printk("\n");
5708diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5709index aff0c72..9067b39 100644
5710--- a/arch/sparc/kernel/process_64.c
5711+++ b/arch/sparc/kernel/process_64.c
5712@@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5713 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5714 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5715 if (regs->tstate & TSTATE_PRIV)
5716- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5717+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5718 }
5719
5720 void show_regs(struct pt_regs *regs)
5721 {
5722 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5723 regs->tpc, regs->tnpc, regs->y, print_tainted());
5724- printk("TPC: <%pS>\n", (void *) regs->tpc);
5725+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5726 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5727 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5728 regs->u_regs[3]);
5729@@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5730 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5731 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5732 regs->u_regs[15]);
5733- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5734+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5735 show_regwindow(regs);
5736 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5737 }
5738@@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5739 ((tp && tp->task) ? tp->task->pid : -1));
5740
5741 if (gp->tstate & TSTATE_PRIV) {
5742- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5743+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5744 (void *) gp->tpc,
5745 (void *) gp->o7,
5746 (void *) gp->i7,
5747diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5748index 484daba..0674139 100644
5749--- a/arch/sparc/kernel/ptrace_64.c
5750+++ b/arch/sparc/kernel/ptrace_64.c
5751@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5752 return ret;
5753 }
5754
5755+#ifdef CONFIG_GRKERNSEC_SETXID
5756+extern void gr_delayed_cred_worker(void);
5757+#endif
5758+
5759 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5760 {
5761 int ret = 0;
5762@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5763 /* do the secure computing check first */
5764 secure_computing_strict(regs->u_regs[UREG_G1]);
5765
5766+#ifdef CONFIG_GRKERNSEC_SETXID
5767+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5768+ gr_delayed_cred_worker();
5769+#endif
5770+
5771 if (test_thread_flag(TIF_SYSCALL_TRACE))
5772 ret = tracehook_report_syscall_entry(regs);
5773
5774@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5775
5776 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5777 {
5778+#ifdef CONFIG_GRKERNSEC_SETXID
5779+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5780+ gr_delayed_cred_worker();
5781+#endif
5782+
5783 audit_syscall_exit(regs);
5784
5785 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5786diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5787index 0c9b31b..7cb7aee 100644
5788--- a/arch/sparc/kernel/sys_sparc_32.c
5789+++ b/arch/sparc/kernel/sys_sparc_32.c
5790@@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5791 if (len > TASK_SIZE - PAGE_SIZE)
5792 return -ENOMEM;
5793 if (!addr)
5794- addr = TASK_UNMAPPED_BASE;
5795+ addr = current->mm->mmap_base;
5796
5797 if (flags & MAP_SHARED)
5798 addr = COLOUR_ALIGN(addr);
5799@@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5800 /* At this point: (!vmm || addr < vmm->vm_end). */
5801 if (TASK_SIZE - PAGE_SIZE - len < addr)
5802 return -ENOMEM;
5803- if (!vmm || addr + len <= vmm->vm_start)
5804+ if (check_heap_stack_gap(vmm, addr, len))
5805 return addr;
5806 addr = vmm->vm_end;
5807 if (flags & MAP_SHARED)
5808diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5809index 11c6c96..3ec33e8 100644
5810--- a/arch/sparc/kernel/sys_sparc_64.c
5811+++ b/arch/sparc/kernel/sys_sparc_64.c
5812@@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5813 /* We do not accept a shared mapping if it would violate
5814 * cache aliasing constraints.
5815 */
5816- if ((flags & MAP_SHARED) &&
5817+ if ((filp || (flags & MAP_SHARED)) &&
5818 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5819 return -EINVAL;
5820 return addr;
5821@@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5822 if (filp || (flags & MAP_SHARED))
5823 do_color_align = 1;
5824
5825+#ifdef CONFIG_PAX_RANDMMAP
5826+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5827+#endif
5828+
5829 if (addr) {
5830 if (do_color_align)
5831 addr = COLOUR_ALIGN(addr, pgoff);
5832@@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5833 addr = PAGE_ALIGN(addr);
5834
5835 vma = find_vma(mm, addr);
5836- if (task_size - len >= addr &&
5837- (!vma || addr + len <= vma->vm_start))
5838+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5839 return addr;
5840 }
5841
5842 if (len > mm->cached_hole_size) {
5843- start_addr = addr = mm->free_area_cache;
5844+ start_addr = addr = mm->free_area_cache;
5845 } else {
5846- start_addr = addr = TASK_UNMAPPED_BASE;
5847+ start_addr = addr = mm->mmap_base;
5848 mm->cached_hole_size = 0;
5849 }
5850
5851@@ -157,14 +160,14 @@ full_search:
5852 vma = find_vma(mm, VA_EXCLUDE_END);
5853 }
5854 if (unlikely(task_size < addr)) {
5855- if (start_addr != TASK_UNMAPPED_BASE) {
5856- start_addr = addr = TASK_UNMAPPED_BASE;
5857+ if (start_addr != mm->mmap_base) {
5858+ start_addr = addr = mm->mmap_base;
5859 mm->cached_hole_size = 0;
5860 goto full_search;
5861 }
5862 return -ENOMEM;
5863 }
5864- if (likely(!vma || addr + len <= vma->vm_start)) {
5865+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5866 /*
5867 * Remember the place where we stopped the search:
5868 */
5869@@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5870 /* We do not accept a shared mapping if it would violate
5871 * cache aliasing constraints.
5872 */
5873- if ((flags & MAP_SHARED) &&
5874+ if ((filp || (flags & MAP_SHARED)) &&
5875 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5876 return -EINVAL;
5877 return addr;
5878@@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5879 addr = PAGE_ALIGN(addr);
5880
5881 vma = find_vma(mm, addr);
5882- if (task_size - len >= addr &&
5883- (!vma || addr + len <= vma->vm_start))
5884+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5885 return addr;
5886 }
5887
5888@@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5889 /* make sure it can fit in the remaining address space */
5890 if (likely(addr > len)) {
5891 vma = find_vma(mm, addr-len);
5892- if (!vma || addr <= vma->vm_start) {
5893+ if (check_heap_stack_gap(vma, addr - len, len)) {
5894 /* remember the address as a hint for next time */
5895 return (mm->free_area_cache = addr-len);
5896 }
5897@@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5898 if (unlikely(mm->mmap_base < len))
5899 goto bottomup;
5900
5901- addr = mm->mmap_base-len;
5902- if (do_color_align)
5903- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5904+ addr = mm->mmap_base - len;
5905
5906 do {
5907+ if (do_color_align)
5908+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5909 /*
5910 * Lookup failure means no vma is above this address,
5911 * else if new region fits below vma->vm_start,
5912 * return with success:
5913 */
5914 vma = find_vma(mm, addr);
5915- if (likely(!vma || addr+len <= vma->vm_start)) {
5916+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5917 /* remember the address as a hint for next time */
5918 return (mm->free_area_cache = addr);
5919 }
5920@@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5921 mm->cached_hole_size = vma->vm_start - addr;
5922
5923 /* try just below the current vma->vm_start */
5924- addr = vma->vm_start-len;
5925- if (do_color_align)
5926- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5927- } while (likely(len < vma->vm_start));
5928+ addr = skip_heap_stack_gap(vma, len);
5929+ } while (!IS_ERR_VALUE(addr));
5930
5931 bottomup:
5932 /*
5933@@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5934 gap == RLIM_INFINITY ||
5935 sysctl_legacy_va_layout) {
5936 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5937+
5938+#ifdef CONFIG_PAX_RANDMMAP
5939+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5940+ mm->mmap_base += mm->delta_mmap;
5941+#endif
5942+
5943 mm->get_unmapped_area = arch_get_unmapped_area;
5944 mm->unmap_area = arch_unmap_area;
5945 } else {
5946@@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5947 gap = (task_size / 6 * 5);
5948
5949 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5950+
5951+#ifdef CONFIG_PAX_RANDMMAP
5952+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5953+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5954+#endif
5955+
5956 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5957 mm->unmap_area = arch_unmap_area_topdown;
5958 }
5959diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5960index 1d7e274..b39c527 100644
5961--- a/arch/sparc/kernel/syscalls.S
5962+++ b/arch/sparc/kernel/syscalls.S
5963@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5964 #endif
5965 .align 32
5966 1: ldx [%g6 + TI_FLAGS], %l5
5967- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5968+ andcc %l5, _TIF_WORK_SYSCALL, %g0
5969 be,pt %icc, rtrap
5970 nop
5971 call syscall_trace_leave
5972@@ -179,7 +179,7 @@ linux_sparc_syscall32:
5973
5974 srl %i5, 0, %o5 ! IEU1
5975 srl %i2, 0, %o2 ! IEU0 Group
5976- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5977+ andcc %l0, _TIF_WORK_SYSCALL, %g0
5978 bne,pn %icc, linux_syscall_trace32 ! CTI
5979 mov %i0, %l5 ! IEU1
5980 call %l7 ! CTI Group brk forced
5981@@ -202,7 +202,7 @@ linux_sparc_syscall:
5982
5983 mov %i3, %o3 ! IEU1
5984 mov %i4, %o4 ! IEU0 Group
5985- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5986+ andcc %l0, _TIF_WORK_SYSCALL, %g0
5987 bne,pn %icc, linux_syscall_trace ! CTI Group
5988 mov %i0, %l5 ! IEU0
5989 2: call %l7 ! CTI Group brk forced
5990@@ -226,7 +226,7 @@ ret_sys_call:
5991
5992 cmp %o0, -ERESTART_RESTARTBLOCK
5993 bgeu,pn %xcc, 1f
5994- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
5995+ andcc %l0, _TIF_WORK_SYSCALL, %l6
5996 80:
5997 /* System call success, clear Carry condition code. */
5998 andn %g3, %g2, %g3
5999@@ -241,7 +241,7 @@ ret_sys_call:
6000 /* System call failure, set Carry condition code.
6001 * Also, get abs(errno) to return to the process.
6002 */
6003- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6004+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6005 sub %g0, %o0, %o0
6006 or %g3, %g2, %g3
6007 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6008diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6009index a5785ea..405c5f7 100644
6010--- a/arch/sparc/kernel/traps_32.c
6011+++ b/arch/sparc/kernel/traps_32.c
6012@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6013 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6014 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6015
6016+extern void gr_handle_kernel_exploit(void);
6017+
6018 void die_if_kernel(char *str, struct pt_regs *regs)
6019 {
6020 static int die_counter;
6021@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6022 count++ < 30 &&
6023 (((unsigned long) rw) >= PAGE_OFFSET) &&
6024 !(((unsigned long) rw) & 0x7)) {
6025- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6026+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6027 (void *) rw->ins[7]);
6028 rw = (struct reg_window32 *)rw->ins[6];
6029 }
6030 }
6031 printk("Instruction DUMP:");
6032 instruction_dump ((unsigned long *) regs->pc);
6033- if(regs->psr & PSR_PS)
6034+ if(regs->psr & PSR_PS) {
6035+ gr_handle_kernel_exploit();
6036 do_exit(SIGKILL);
6037+ }
6038 do_exit(SIGSEGV);
6039 }
6040
6041diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6042index 3b05e66..6ea2917 100644
6043--- a/arch/sparc/kernel/traps_64.c
6044+++ b/arch/sparc/kernel/traps_64.c
6045@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6046 i + 1,
6047 p->trapstack[i].tstate, p->trapstack[i].tpc,
6048 p->trapstack[i].tnpc, p->trapstack[i].tt);
6049- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6050+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6051 }
6052 }
6053
6054@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6055
6056 lvl -= 0x100;
6057 if (regs->tstate & TSTATE_PRIV) {
6058+
6059+#ifdef CONFIG_PAX_REFCOUNT
6060+ if (lvl == 6)
6061+ pax_report_refcount_overflow(regs);
6062+#endif
6063+
6064 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6065 die_if_kernel(buffer, regs);
6066 }
6067@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6068 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6069 {
6070 char buffer[32];
6071-
6072+
6073 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6074 0, lvl, SIGTRAP) == NOTIFY_STOP)
6075 return;
6076
6077+#ifdef CONFIG_PAX_REFCOUNT
6078+ if (lvl == 6)
6079+ pax_report_refcount_overflow(regs);
6080+#endif
6081+
6082 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6083
6084 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6085@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6086 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6087 printk("%s" "ERROR(%d): ",
6088 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6089- printk("TPC<%pS>\n", (void *) regs->tpc);
6090+ printk("TPC<%pA>\n", (void *) regs->tpc);
6091 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6092 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6093 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6094@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6095 smp_processor_id(),
6096 (type & 0x1) ? 'I' : 'D',
6097 regs->tpc);
6098- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6099+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6100 panic("Irrecoverable Cheetah+ parity error.");
6101 }
6102
6103@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6104 smp_processor_id(),
6105 (type & 0x1) ? 'I' : 'D',
6106 regs->tpc);
6107- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6108+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6109 }
6110
6111 struct sun4v_error_entry {
6112@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6113
6114 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6115 regs->tpc, tl);
6116- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6117+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6118 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6119- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6120+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6121 (void *) regs->u_regs[UREG_I7]);
6122 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6123 "pte[%lx] error[%lx]\n",
6124@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6125
6126 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6127 regs->tpc, tl);
6128- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6129+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6130 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6131- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6132+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6133 (void *) regs->u_regs[UREG_I7]);
6134 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6135 "pte[%lx] error[%lx]\n",
6136@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6137 fp = (unsigned long)sf->fp + STACK_BIAS;
6138 }
6139
6140- printk(" [%016lx] %pS\n", pc, (void *) pc);
6141+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6142 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6143 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6144 int index = tsk->curr_ret_stack;
6145 if (tsk->ret_stack && index >= graph) {
6146 pc = tsk->ret_stack[index - graph].ret;
6147- printk(" [%016lx] %pS\n", pc, (void *) pc);
6148+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6149 graph++;
6150 }
6151 }
6152@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6153 return (struct reg_window *) (fp + STACK_BIAS);
6154 }
6155
6156+extern void gr_handle_kernel_exploit(void);
6157+
6158 void die_if_kernel(char *str, struct pt_regs *regs)
6159 {
6160 static int die_counter;
6161@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6162 while (rw &&
6163 count++ < 30 &&
6164 kstack_valid(tp, (unsigned long) rw)) {
6165- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6166+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6167 (void *) rw->ins[7]);
6168
6169 rw = kernel_stack_up(rw);
6170@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6171 }
6172 user_instruction_dump ((unsigned int __user *) regs->tpc);
6173 }
6174- if (regs->tstate & TSTATE_PRIV)
6175+ if (regs->tstate & TSTATE_PRIV) {
6176+ gr_handle_kernel_exploit();
6177 do_exit(SIGKILL);
6178+ }
6179 do_exit(SIGSEGV);
6180 }
6181 EXPORT_SYMBOL(die_if_kernel);
6182diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6183index f81d038..e7a4680 100644
6184--- a/arch/sparc/kernel/unaligned_64.c
6185+++ b/arch/sparc/kernel/unaligned_64.c
6186@@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6187 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6188
6189 if (__ratelimit(&ratelimit)) {
6190- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6191+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6192 regs->tpc, (void *) regs->tpc);
6193 }
6194 }
6195diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6196index dff4096..bd9a388 100644
6197--- a/arch/sparc/lib/Makefile
6198+++ b/arch/sparc/lib/Makefile
6199@@ -2,7 +2,7 @@
6200 #
6201
6202 asflags-y := -ansi -DST_DIV0=0x02
6203-ccflags-y := -Werror
6204+#ccflags-y := -Werror
6205
6206 lib-$(CONFIG_SPARC32) += ashrdi3.o
6207 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6208diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6209index 4d502da..527c48d 100644
6210--- a/arch/sparc/lib/atomic_64.S
6211+++ b/arch/sparc/lib/atomic_64.S
6212@@ -17,7 +17,12 @@
6213 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6214 BACKOFF_SETUP(%o2)
6215 1: lduw [%o1], %g1
6216- add %g1, %o0, %g7
6217+ addcc %g1, %o0, %g7
6218+
6219+#ifdef CONFIG_PAX_REFCOUNT
6220+ tvs %icc, 6
6221+#endif
6222+
6223 cas [%o1], %g1, %g7
6224 cmp %g1, %g7
6225 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6226@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6227 2: BACKOFF_SPIN(%o2, %o3, 1b)
6228 ENDPROC(atomic_add)
6229
6230+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6231+ BACKOFF_SETUP(%o2)
6232+1: lduw [%o1], %g1
6233+ add %g1, %o0, %g7
6234+ cas [%o1], %g1, %g7
6235+ cmp %g1, %g7
6236+ bne,pn %icc, 2f
6237+ nop
6238+ retl
6239+ nop
6240+2: BACKOFF_SPIN(%o2, %o3, 1b)
6241+ENDPROC(atomic_add_unchecked)
6242+
6243 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6244 BACKOFF_SETUP(%o2)
6245 1: lduw [%o1], %g1
6246- sub %g1, %o0, %g7
6247+ subcc %g1, %o0, %g7
6248+
6249+#ifdef CONFIG_PAX_REFCOUNT
6250+ tvs %icc, 6
6251+#endif
6252+
6253 cas [%o1], %g1, %g7
6254 cmp %g1, %g7
6255 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6256@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6257 2: BACKOFF_SPIN(%o2, %o3, 1b)
6258 ENDPROC(atomic_sub)
6259
6260+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6261+ BACKOFF_SETUP(%o2)
6262+1: lduw [%o1], %g1
6263+ sub %g1, %o0, %g7
6264+ cas [%o1], %g1, %g7
6265+ cmp %g1, %g7
6266+ bne,pn %icc, 2f
6267+ nop
6268+ retl
6269+ nop
6270+2: BACKOFF_SPIN(%o2, %o3, 1b)
6271+ENDPROC(atomic_sub_unchecked)
6272+
6273 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6274 BACKOFF_SETUP(%o2)
6275 1: lduw [%o1], %g1
6276- add %g1, %o0, %g7
6277+ addcc %g1, %o0, %g7
6278+
6279+#ifdef CONFIG_PAX_REFCOUNT
6280+ tvs %icc, 6
6281+#endif
6282+
6283 cas [%o1], %g1, %g7
6284 cmp %g1, %g7
6285 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6286@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6287 2: BACKOFF_SPIN(%o2, %o3, 1b)
6288 ENDPROC(atomic_add_ret)
6289
6290+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6291+ BACKOFF_SETUP(%o2)
6292+1: lduw [%o1], %g1
6293+ addcc %g1, %o0, %g7
6294+ cas [%o1], %g1, %g7
6295+ cmp %g1, %g7
6296+ bne,pn %icc, 2f
6297+ add %g7, %o0, %g7
6298+ sra %g7, 0, %o0
6299+ retl
6300+ nop
6301+2: BACKOFF_SPIN(%o2, %o3, 1b)
6302+ENDPROC(atomic_add_ret_unchecked)
6303+
6304 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6305 BACKOFF_SETUP(%o2)
6306 1: lduw [%o1], %g1
6307- sub %g1, %o0, %g7
6308+ subcc %g1, %o0, %g7
6309+
6310+#ifdef CONFIG_PAX_REFCOUNT
6311+ tvs %icc, 6
6312+#endif
6313+
6314 cas [%o1], %g1, %g7
6315 cmp %g1, %g7
6316 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6317@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6318 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6319 BACKOFF_SETUP(%o2)
6320 1: ldx [%o1], %g1
6321- add %g1, %o0, %g7
6322+ addcc %g1, %o0, %g7
6323+
6324+#ifdef CONFIG_PAX_REFCOUNT
6325+ tvs %xcc, 6
6326+#endif
6327+
6328 casx [%o1], %g1, %g7
6329 cmp %g1, %g7
6330 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6331@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6332 2: BACKOFF_SPIN(%o2, %o3, 1b)
6333 ENDPROC(atomic64_add)
6334
6335+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6336+ BACKOFF_SETUP(%o2)
6337+1: ldx [%o1], %g1
6338+ addcc %g1, %o0, %g7
6339+ casx [%o1], %g1, %g7
6340+ cmp %g1, %g7
6341+ bne,pn %xcc, 2f
6342+ nop
6343+ retl
6344+ nop
6345+2: BACKOFF_SPIN(%o2, %o3, 1b)
6346+ENDPROC(atomic64_add_unchecked)
6347+
6348 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6349 BACKOFF_SETUP(%o2)
6350 1: ldx [%o1], %g1
6351- sub %g1, %o0, %g7
6352+ subcc %g1, %o0, %g7
6353+
6354+#ifdef CONFIG_PAX_REFCOUNT
6355+ tvs %xcc, 6
6356+#endif
6357+
6358 casx [%o1], %g1, %g7
6359 cmp %g1, %g7
6360 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6361@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6362 2: BACKOFF_SPIN(%o2, %o3, 1b)
6363 ENDPROC(atomic64_sub)
6364
6365+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6366+ BACKOFF_SETUP(%o2)
6367+1: ldx [%o1], %g1
6368+ subcc %g1, %o0, %g7
6369+ casx [%o1], %g1, %g7
6370+ cmp %g1, %g7
6371+ bne,pn %xcc, 2f
6372+ nop
6373+ retl
6374+ nop
6375+2: BACKOFF_SPIN(%o2, %o3, 1b)
6376+ENDPROC(atomic64_sub_unchecked)
6377+
6378 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6379 BACKOFF_SETUP(%o2)
6380 1: ldx [%o1], %g1
6381- add %g1, %o0, %g7
6382+ addcc %g1, %o0, %g7
6383+
6384+#ifdef CONFIG_PAX_REFCOUNT
6385+ tvs %xcc, 6
6386+#endif
6387+
6388 casx [%o1], %g1, %g7
6389 cmp %g1, %g7
6390 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6391@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6392 2: BACKOFF_SPIN(%o2, %o3, 1b)
6393 ENDPROC(atomic64_add_ret)
6394
6395+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6396+ BACKOFF_SETUP(%o2)
6397+1: ldx [%o1], %g1
6398+ addcc %g1, %o0, %g7
6399+ casx [%o1], %g1, %g7
6400+ cmp %g1, %g7
6401+ bne,pn %xcc, 2f
6402+ add %g7, %o0, %g7
6403+ mov %g7, %o0
6404+ retl
6405+ nop
6406+2: BACKOFF_SPIN(%o2, %o3, 1b)
6407+ENDPROC(atomic64_add_ret_unchecked)
6408+
6409 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6410 BACKOFF_SETUP(%o2)
6411 1: ldx [%o1], %g1
6412- sub %g1, %o0, %g7
6413+ subcc %g1, %o0, %g7
6414+
6415+#ifdef CONFIG_PAX_REFCOUNT
6416+ tvs %xcc, 6
6417+#endif
6418+
6419 casx [%o1], %g1, %g7
6420 cmp %g1, %g7
6421 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6422diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6423index 3b31218..345c609 100644
6424--- a/arch/sparc/lib/ksyms.c
6425+++ b/arch/sparc/lib/ksyms.c
6426@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6427
6428 /* Atomic counter implementation. */
6429 EXPORT_SYMBOL(atomic_add);
6430+EXPORT_SYMBOL(atomic_add_unchecked);
6431 EXPORT_SYMBOL(atomic_add_ret);
6432+EXPORT_SYMBOL(atomic_add_ret_unchecked);
6433 EXPORT_SYMBOL(atomic_sub);
6434+EXPORT_SYMBOL(atomic_sub_unchecked);
6435 EXPORT_SYMBOL(atomic_sub_ret);
6436 EXPORT_SYMBOL(atomic64_add);
6437+EXPORT_SYMBOL(atomic64_add_unchecked);
6438 EXPORT_SYMBOL(atomic64_add_ret);
6439+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6440 EXPORT_SYMBOL(atomic64_sub);
6441+EXPORT_SYMBOL(atomic64_sub_unchecked);
6442 EXPORT_SYMBOL(atomic64_sub_ret);
6443
6444 /* Atomic bit operations. */
6445diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6446index 30c3ecc..736f015 100644
6447--- a/arch/sparc/mm/Makefile
6448+++ b/arch/sparc/mm/Makefile
6449@@ -2,7 +2,7 @@
6450 #
6451
6452 asflags-y := -ansi
6453-ccflags-y := -Werror
6454+#ccflags-y := -Werror
6455
6456 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6457 obj-y += fault_$(BITS).o
6458diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6459index 77ac917..baf45db 100644
6460--- a/arch/sparc/mm/fault_32.c
6461+++ b/arch/sparc/mm/fault_32.c
6462@@ -21,6 +21,9 @@
6463 #include <linux/perf_event.h>
6464 #include <linux/interrupt.h>
6465 #include <linux/kdebug.h>
6466+#include <linux/slab.h>
6467+#include <linux/pagemap.h>
6468+#include <linux/compiler.h>
6469
6470 #include <asm/page.h>
6471 #include <asm/pgtable.h>
6472@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6473 return safe_compute_effective_address(regs, insn);
6474 }
6475
6476+#ifdef CONFIG_PAX_PAGEEXEC
6477+#ifdef CONFIG_PAX_DLRESOLVE
6478+static void pax_emuplt_close(struct vm_area_struct *vma)
6479+{
6480+ vma->vm_mm->call_dl_resolve = 0UL;
6481+}
6482+
6483+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6484+{
6485+ unsigned int *kaddr;
6486+
6487+ vmf->page = alloc_page(GFP_HIGHUSER);
6488+ if (!vmf->page)
6489+ return VM_FAULT_OOM;
6490+
6491+ kaddr = kmap(vmf->page);
6492+ memset(kaddr, 0, PAGE_SIZE);
6493+ kaddr[0] = 0x9DE3BFA8U; /* save */
6494+ flush_dcache_page(vmf->page);
6495+ kunmap(vmf->page);
6496+ return VM_FAULT_MAJOR;
6497+}
6498+
6499+static const struct vm_operations_struct pax_vm_ops = {
6500+ .close = pax_emuplt_close,
6501+ .fault = pax_emuplt_fault
6502+};
6503+
6504+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6505+{
6506+ int ret;
6507+
6508+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6509+ vma->vm_mm = current->mm;
6510+ vma->vm_start = addr;
6511+ vma->vm_end = addr + PAGE_SIZE;
6512+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6513+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6514+ vma->vm_ops = &pax_vm_ops;
6515+
6516+ ret = insert_vm_struct(current->mm, vma);
6517+ if (ret)
6518+ return ret;
6519+
6520+ ++current->mm->total_vm;
6521+ return 0;
6522+}
6523+#endif
6524+
6525+/*
6526+ * PaX: decide what to do with offenders (regs->pc = fault address)
6527+ *
6528+ * returns 1 when task should be killed
6529+ * 2 when patched PLT trampoline was detected
6530+ * 3 when unpatched PLT trampoline was detected
6531+ */
6532+static int pax_handle_fetch_fault(struct pt_regs *regs)
6533+{
6534+
6535+#ifdef CONFIG_PAX_EMUPLT
6536+ int err;
6537+
6538+ do { /* PaX: patched PLT emulation #1 */
6539+ unsigned int sethi1, sethi2, jmpl;
6540+
6541+ err = get_user(sethi1, (unsigned int *)regs->pc);
6542+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6543+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6544+
6545+ if (err)
6546+ break;
6547+
6548+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6549+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6550+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6551+ {
6552+ unsigned int addr;
6553+
6554+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6555+ addr = regs->u_regs[UREG_G1];
6556+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6557+ regs->pc = addr;
6558+ regs->npc = addr+4;
6559+ return 2;
6560+ }
6561+ } while (0);
6562+
6563+ do { /* PaX: patched PLT emulation #2 */
6564+ unsigned int ba;
6565+
6566+ err = get_user(ba, (unsigned int *)regs->pc);
6567+
6568+ if (err)
6569+ break;
6570+
6571+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6572+ unsigned int addr;
6573+
6574+ if ((ba & 0xFFC00000U) == 0x30800000U)
6575+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6576+ else
6577+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6578+ regs->pc = addr;
6579+ regs->npc = addr+4;
6580+ return 2;
6581+ }
6582+ } while (0);
6583+
6584+ do { /* PaX: patched PLT emulation #3 */
6585+ unsigned int sethi, bajmpl, nop;
6586+
6587+ err = get_user(sethi, (unsigned int *)regs->pc);
6588+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6589+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6590+
6591+ if (err)
6592+ break;
6593+
6594+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6595+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6596+ nop == 0x01000000U)
6597+ {
6598+ unsigned int addr;
6599+
6600+ addr = (sethi & 0x003FFFFFU) << 10;
6601+ regs->u_regs[UREG_G1] = addr;
6602+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6603+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6604+ else
6605+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6606+ regs->pc = addr;
6607+ regs->npc = addr+4;
6608+ return 2;
6609+ }
6610+ } while (0);
6611+
6612+ do { /* PaX: unpatched PLT emulation step 1 */
6613+ unsigned int sethi, ba, nop;
6614+
6615+ err = get_user(sethi, (unsigned int *)regs->pc);
6616+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6617+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6618+
6619+ if (err)
6620+ break;
6621+
6622+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6623+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6624+ nop == 0x01000000U)
6625+ {
6626+ unsigned int addr, save, call;
6627+
6628+ if ((ba & 0xFFC00000U) == 0x30800000U)
6629+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6630+ else
6631+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6632+
6633+ err = get_user(save, (unsigned int *)addr);
6634+ err |= get_user(call, (unsigned int *)(addr+4));
6635+ err |= get_user(nop, (unsigned int *)(addr+8));
6636+ if (err)
6637+ break;
6638+
6639+#ifdef CONFIG_PAX_DLRESOLVE
6640+ if (save == 0x9DE3BFA8U &&
6641+ (call & 0xC0000000U) == 0x40000000U &&
6642+ nop == 0x01000000U)
6643+ {
6644+ struct vm_area_struct *vma;
6645+ unsigned long call_dl_resolve;
6646+
6647+ down_read(&current->mm->mmap_sem);
6648+ call_dl_resolve = current->mm->call_dl_resolve;
6649+ up_read(&current->mm->mmap_sem);
6650+ if (likely(call_dl_resolve))
6651+ goto emulate;
6652+
6653+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6654+
6655+ down_write(&current->mm->mmap_sem);
6656+ if (current->mm->call_dl_resolve) {
6657+ call_dl_resolve = current->mm->call_dl_resolve;
6658+ up_write(&current->mm->mmap_sem);
6659+ if (vma)
6660+ kmem_cache_free(vm_area_cachep, vma);
6661+ goto emulate;
6662+ }
6663+
6664+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6665+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6666+ up_write(&current->mm->mmap_sem);
6667+ if (vma)
6668+ kmem_cache_free(vm_area_cachep, vma);
6669+ return 1;
6670+ }
6671+
6672+ if (pax_insert_vma(vma, call_dl_resolve)) {
6673+ up_write(&current->mm->mmap_sem);
6674+ kmem_cache_free(vm_area_cachep, vma);
6675+ return 1;
6676+ }
6677+
6678+ current->mm->call_dl_resolve = call_dl_resolve;
6679+ up_write(&current->mm->mmap_sem);
6680+
6681+emulate:
6682+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6683+ regs->pc = call_dl_resolve;
6684+ regs->npc = addr+4;
6685+ return 3;
6686+ }
6687+#endif
6688+
6689+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6690+ if ((save & 0xFFC00000U) == 0x05000000U &&
6691+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6692+ nop == 0x01000000U)
6693+ {
6694+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6695+ regs->u_regs[UREG_G2] = addr + 4;
6696+ addr = (save & 0x003FFFFFU) << 10;
6697+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6698+ regs->pc = addr;
6699+ regs->npc = addr+4;
6700+ return 3;
6701+ }
6702+ }
6703+ } while (0);
6704+
6705+ do { /* PaX: unpatched PLT emulation step 2 */
6706+ unsigned int save, call, nop;
6707+
6708+ err = get_user(save, (unsigned int *)(regs->pc-4));
6709+ err |= get_user(call, (unsigned int *)regs->pc);
6710+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6711+ if (err)
6712+ break;
6713+
6714+ if (save == 0x9DE3BFA8U &&
6715+ (call & 0xC0000000U) == 0x40000000U &&
6716+ nop == 0x01000000U)
6717+ {
6718+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6719+
6720+ regs->u_regs[UREG_RETPC] = regs->pc;
6721+ regs->pc = dl_resolve;
6722+ regs->npc = dl_resolve+4;
6723+ return 3;
6724+ }
6725+ } while (0);
6726+#endif
6727+
6728+ return 1;
6729+}
6730+
6731+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6732+{
6733+ unsigned long i;
6734+
6735+ printk(KERN_ERR "PAX: bytes at PC: ");
6736+ for (i = 0; i < 8; i++) {
6737+ unsigned int c;
6738+ if (get_user(c, (unsigned int *)pc+i))
6739+ printk(KERN_CONT "???????? ");
6740+ else
6741+ printk(KERN_CONT "%08x ", c);
6742+ }
6743+ printk("\n");
6744+}
6745+#endif
6746+
6747 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6748 int text_fault)
6749 {
6750@@ -230,6 +504,24 @@ good_area:
6751 if (!(vma->vm_flags & VM_WRITE))
6752 goto bad_area;
6753 } else {
6754+
6755+#ifdef CONFIG_PAX_PAGEEXEC
6756+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6757+ up_read(&mm->mmap_sem);
6758+ switch (pax_handle_fetch_fault(regs)) {
6759+
6760+#ifdef CONFIG_PAX_EMUPLT
6761+ case 2:
6762+ case 3:
6763+ return;
6764+#endif
6765+
6766+ }
6767+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6768+ do_group_exit(SIGKILL);
6769+ }
6770+#endif
6771+
6772 /* Allow reads even for write-only mappings */
6773 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6774 goto bad_area;
6775diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6776index 1fe0429..8dd5dd5 100644
6777--- a/arch/sparc/mm/fault_64.c
6778+++ b/arch/sparc/mm/fault_64.c
6779@@ -21,6 +21,9 @@
6780 #include <linux/kprobes.h>
6781 #include <linux/kdebug.h>
6782 #include <linux/percpu.h>
6783+#include <linux/slab.h>
6784+#include <linux/pagemap.h>
6785+#include <linux/compiler.h>
6786
6787 #include <asm/page.h>
6788 #include <asm/pgtable.h>
6789@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6790 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6791 regs->tpc);
6792 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6793- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6794+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6795 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6796 dump_stack();
6797 unhandled_fault(regs->tpc, current, regs);
6798@@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6799 show_regs(regs);
6800 }
6801
6802+#ifdef CONFIG_PAX_PAGEEXEC
6803+#ifdef CONFIG_PAX_DLRESOLVE
6804+static void pax_emuplt_close(struct vm_area_struct *vma)
6805+{
6806+ vma->vm_mm->call_dl_resolve = 0UL;
6807+}
6808+
6809+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6810+{
6811+ unsigned int *kaddr;
6812+
6813+ vmf->page = alloc_page(GFP_HIGHUSER);
6814+ if (!vmf->page)
6815+ return VM_FAULT_OOM;
6816+
6817+ kaddr = kmap(vmf->page);
6818+ memset(kaddr, 0, PAGE_SIZE);
6819+ kaddr[0] = 0x9DE3BFA8U; /* save */
6820+ flush_dcache_page(vmf->page);
6821+ kunmap(vmf->page);
6822+ return VM_FAULT_MAJOR;
6823+}
6824+
6825+static const struct vm_operations_struct pax_vm_ops = {
6826+ .close = pax_emuplt_close,
6827+ .fault = pax_emuplt_fault
6828+};
6829+
6830+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6831+{
6832+ int ret;
6833+
6834+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6835+ vma->vm_mm = current->mm;
6836+ vma->vm_start = addr;
6837+ vma->vm_end = addr + PAGE_SIZE;
6838+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6839+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6840+ vma->vm_ops = &pax_vm_ops;
6841+
6842+ ret = insert_vm_struct(current->mm, vma);
6843+ if (ret)
6844+ return ret;
6845+
6846+ ++current->mm->total_vm;
6847+ return 0;
6848+}
6849+#endif
6850+
6851+/*
6852+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6853+ *
6854+ * returns 1 when task should be killed
6855+ * 2 when patched PLT trampoline was detected
6856+ * 3 when unpatched PLT trampoline was detected
6857+ */
6858+static int pax_handle_fetch_fault(struct pt_regs *regs)
6859+{
6860+
6861+#ifdef CONFIG_PAX_EMUPLT
6862+ int err;
6863+
6864+ do { /* PaX: patched PLT emulation #1 */
6865+ unsigned int sethi1, sethi2, jmpl;
6866+
6867+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6868+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6869+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6870+
6871+ if (err)
6872+ break;
6873+
6874+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6875+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6876+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6877+ {
6878+ unsigned long addr;
6879+
6880+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6881+ addr = regs->u_regs[UREG_G1];
6882+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6883+
6884+ if (test_thread_flag(TIF_32BIT))
6885+ addr &= 0xFFFFFFFFUL;
6886+
6887+ regs->tpc = addr;
6888+ regs->tnpc = addr+4;
6889+ return 2;
6890+ }
6891+ } while (0);
6892+
6893+ do { /* PaX: patched PLT emulation #2 */
6894+ unsigned int ba;
6895+
6896+ err = get_user(ba, (unsigned int *)regs->tpc);
6897+
6898+ if (err)
6899+ break;
6900+
6901+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6902+ unsigned long addr;
6903+
6904+ if ((ba & 0xFFC00000U) == 0x30800000U)
6905+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6906+ else
6907+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6908+
6909+ if (test_thread_flag(TIF_32BIT))
6910+ addr &= 0xFFFFFFFFUL;
6911+
6912+ regs->tpc = addr;
6913+ regs->tnpc = addr+4;
6914+ return 2;
6915+ }
6916+ } while (0);
6917+
6918+ do { /* PaX: patched PLT emulation #3 */
6919+ unsigned int sethi, bajmpl, nop;
6920+
6921+ err = get_user(sethi, (unsigned int *)regs->tpc);
6922+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6923+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6924+
6925+ if (err)
6926+ break;
6927+
6928+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6929+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6930+ nop == 0x01000000U)
6931+ {
6932+ unsigned long addr;
6933+
6934+ addr = (sethi & 0x003FFFFFU) << 10;
6935+ regs->u_regs[UREG_G1] = addr;
6936+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6937+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6938+ else
6939+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6940+
6941+ if (test_thread_flag(TIF_32BIT))
6942+ addr &= 0xFFFFFFFFUL;
6943+
6944+ regs->tpc = addr;
6945+ regs->tnpc = addr+4;
6946+ return 2;
6947+ }
6948+ } while (0);
6949+
6950+ do { /* PaX: patched PLT emulation #4 */
6951+ unsigned int sethi, mov1, call, mov2;
6952+
6953+ err = get_user(sethi, (unsigned int *)regs->tpc);
6954+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6955+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
6956+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6957+
6958+ if (err)
6959+ break;
6960+
6961+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6962+ mov1 == 0x8210000FU &&
6963+ (call & 0xC0000000U) == 0x40000000U &&
6964+ mov2 == 0x9E100001U)
6965+ {
6966+ unsigned long addr;
6967+
6968+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6969+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 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 #5 */
6981+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6982+
6983+ err = get_user(sethi, (unsigned int *)regs->tpc);
6984+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6985+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6986+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6987+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6988+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6989+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6990+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6991+
6992+ if (err)
6993+ break;
6994+
6995+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6996+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
6997+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6998+ (or1 & 0xFFFFE000U) == 0x82106000U &&
6999+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7000+ sllx == 0x83287020U &&
7001+ jmpl == 0x81C04005U &&
7002+ nop == 0x01000000U)
7003+ {
7004+ unsigned long addr;
7005+
7006+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7007+ regs->u_regs[UREG_G1] <<= 32;
7008+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7009+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7010+ regs->tpc = addr;
7011+ regs->tnpc = addr+4;
7012+ return 2;
7013+ }
7014+ } while (0);
7015+
7016+ do { /* PaX: patched PLT emulation #6 */
7017+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7018+
7019+ err = get_user(sethi, (unsigned int *)regs->tpc);
7020+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7021+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7022+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7023+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7024+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7025+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7026+
7027+ if (err)
7028+ break;
7029+
7030+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7031+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7032+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7033+ sllx == 0x83287020U &&
7034+ (or & 0xFFFFE000U) == 0x8A116000U &&
7035+ jmpl == 0x81C04005U &&
7036+ nop == 0x01000000U)
7037+ {
7038+ unsigned long addr;
7039+
7040+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7041+ regs->u_regs[UREG_G1] <<= 32;
7042+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7043+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7044+ regs->tpc = addr;
7045+ regs->tnpc = addr+4;
7046+ return 2;
7047+ }
7048+ } while (0);
7049+
7050+ do { /* PaX: unpatched PLT emulation step 1 */
7051+ unsigned int sethi, ba, nop;
7052+
7053+ err = get_user(sethi, (unsigned int *)regs->tpc);
7054+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7055+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7056+
7057+ if (err)
7058+ break;
7059+
7060+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7061+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7062+ nop == 0x01000000U)
7063+ {
7064+ unsigned long addr;
7065+ unsigned int save, call;
7066+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7067+
7068+ if ((ba & 0xFFC00000U) == 0x30800000U)
7069+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7070+ else
7071+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7072+
7073+ if (test_thread_flag(TIF_32BIT))
7074+ addr &= 0xFFFFFFFFUL;
7075+
7076+ err = get_user(save, (unsigned int *)addr);
7077+ err |= get_user(call, (unsigned int *)(addr+4));
7078+ err |= get_user(nop, (unsigned int *)(addr+8));
7079+ if (err)
7080+ break;
7081+
7082+#ifdef CONFIG_PAX_DLRESOLVE
7083+ if (save == 0x9DE3BFA8U &&
7084+ (call & 0xC0000000U) == 0x40000000U &&
7085+ nop == 0x01000000U)
7086+ {
7087+ struct vm_area_struct *vma;
7088+ unsigned long call_dl_resolve;
7089+
7090+ down_read(&current->mm->mmap_sem);
7091+ call_dl_resolve = current->mm->call_dl_resolve;
7092+ up_read(&current->mm->mmap_sem);
7093+ if (likely(call_dl_resolve))
7094+ goto emulate;
7095+
7096+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7097+
7098+ down_write(&current->mm->mmap_sem);
7099+ if (current->mm->call_dl_resolve) {
7100+ call_dl_resolve = current->mm->call_dl_resolve;
7101+ up_write(&current->mm->mmap_sem);
7102+ if (vma)
7103+ kmem_cache_free(vm_area_cachep, vma);
7104+ goto emulate;
7105+ }
7106+
7107+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7108+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7109+ up_write(&current->mm->mmap_sem);
7110+ if (vma)
7111+ kmem_cache_free(vm_area_cachep, vma);
7112+ return 1;
7113+ }
7114+
7115+ if (pax_insert_vma(vma, call_dl_resolve)) {
7116+ up_write(&current->mm->mmap_sem);
7117+ kmem_cache_free(vm_area_cachep, vma);
7118+ return 1;
7119+ }
7120+
7121+ current->mm->call_dl_resolve = call_dl_resolve;
7122+ up_write(&current->mm->mmap_sem);
7123+
7124+emulate:
7125+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7126+ regs->tpc = call_dl_resolve;
7127+ regs->tnpc = addr+4;
7128+ return 3;
7129+ }
7130+#endif
7131+
7132+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7133+ if ((save & 0xFFC00000U) == 0x05000000U &&
7134+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7135+ nop == 0x01000000U)
7136+ {
7137+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7138+ regs->u_regs[UREG_G2] = addr + 4;
7139+ addr = (save & 0x003FFFFFU) << 10;
7140+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7141+
7142+ if (test_thread_flag(TIF_32BIT))
7143+ addr &= 0xFFFFFFFFUL;
7144+
7145+ regs->tpc = addr;
7146+ regs->tnpc = addr+4;
7147+ return 3;
7148+ }
7149+
7150+ /* PaX: 64-bit PLT stub */
7151+ err = get_user(sethi1, (unsigned int *)addr);
7152+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7153+ err |= get_user(or1, (unsigned int *)(addr+8));
7154+ err |= get_user(or2, (unsigned int *)(addr+12));
7155+ err |= get_user(sllx, (unsigned int *)(addr+16));
7156+ err |= get_user(add, (unsigned int *)(addr+20));
7157+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7158+ err |= get_user(nop, (unsigned int *)(addr+28));
7159+ if (err)
7160+ break;
7161+
7162+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7163+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7164+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7165+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7166+ sllx == 0x89293020U &&
7167+ add == 0x8A010005U &&
7168+ jmpl == 0x89C14000U &&
7169+ nop == 0x01000000U)
7170+ {
7171+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7172+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7173+ regs->u_regs[UREG_G4] <<= 32;
7174+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7175+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7176+ regs->u_regs[UREG_G4] = addr + 24;
7177+ addr = regs->u_regs[UREG_G5];
7178+ regs->tpc = addr;
7179+ regs->tnpc = addr+4;
7180+ return 3;
7181+ }
7182+ }
7183+ } while (0);
7184+
7185+#ifdef CONFIG_PAX_DLRESOLVE
7186+ do { /* PaX: unpatched PLT emulation step 2 */
7187+ unsigned int save, call, nop;
7188+
7189+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7190+ err |= get_user(call, (unsigned int *)regs->tpc);
7191+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7192+ if (err)
7193+ break;
7194+
7195+ if (save == 0x9DE3BFA8U &&
7196+ (call & 0xC0000000U) == 0x40000000U &&
7197+ nop == 0x01000000U)
7198+ {
7199+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7200+
7201+ if (test_thread_flag(TIF_32BIT))
7202+ dl_resolve &= 0xFFFFFFFFUL;
7203+
7204+ regs->u_regs[UREG_RETPC] = regs->tpc;
7205+ regs->tpc = dl_resolve;
7206+ regs->tnpc = dl_resolve+4;
7207+ return 3;
7208+ }
7209+ } while (0);
7210+#endif
7211+
7212+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7213+ unsigned int sethi, ba, nop;
7214+
7215+ err = get_user(sethi, (unsigned int *)regs->tpc);
7216+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7217+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7218+
7219+ if (err)
7220+ break;
7221+
7222+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7223+ (ba & 0xFFF00000U) == 0x30600000U &&
7224+ nop == 0x01000000U)
7225+ {
7226+ unsigned long addr;
7227+
7228+ addr = (sethi & 0x003FFFFFU) << 10;
7229+ regs->u_regs[UREG_G1] = addr;
7230+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7231+
7232+ if (test_thread_flag(TIF_32BIT))
7233+ addr &= 0xFFFFFFFFUL;
7234+
7235+ regs->tpc = addr;
7236+ regs->tnpc = addr+4;
7237+ return 2;
7238+ }
7239+ } while (0);
7240+
7241+#endif
7242+
7243+ return 1;
7244+}
7245+
7246+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7247+{
7248+ unsigned long i;
7249+
7250+ printk(KERN_ERR "PAX: bytes at PC: ");
7251+ for (i = 0; i < 8; i++) {
7252+ unsigned int c;
7253+ if (get_user(c, (unsigned int *)pc+i))
7254+ printk(KERN_CONT "???????? ");
7255+ else
7256+ printk(KERN_CONT "%08x ", c);
7257+ }
7258+ printk("\n");
7259+}
7260+#endif
7261+
7262 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7263 {
7264 struct mm_struct *mm = current->mm;
7265@@ -343,6 +806,29 @@ retry:
7266 if (!vma)
7267 goto bad_area;
7268
7269+#ifdef CONFIG_PAX_PAGEEXEC
7270+ /* PaX: detect ITLB misses on non-exec pages */
7271+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7272+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7273+ {
7274+ if (address != regs->tpc)
7275+ goto good_area;
7276+
7277+ up_read(&mm->mmap_sem);
7278+ switch (pax_handle_fetch_fault(regs)) {
7279+
7280+#ifdef CONFIG_PAX_EMUPLT
7281+ case 2:
7282+ case 3:
7283+ return;
7284+#endif
7285+
7286+ }
7287+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7288+ do_group_exit(SIGKILL);
7289+ }
7290+#endif
7291+
7292 /* Pure DTLB misses do not tell us whether the fault causing
7293 * load/store/atomic was a write or not, it only says that there
7294 * was no match. So in such a case we (carefully) read the
7295diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7296index 07e1453..0a7d9e9 100644
7297--- a/arch/sparc/mm/hugetlbpage.c
7298+++ b/arch/sparc/mm/hugetlbpage.c
7299@@ -67,7 +67,7 @@ full_search:
7300 }
7301 return -ENOMEM;
7302 }
7303- if (likely(!vma || addr + len <= vma->vm_start)) {
7304+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7305 /*
7306 * Remember the place where we stopped the search:
7307 */
7308@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7309 /* make sure it can fit in the remaining address space */
7310 if (likely(addr > len)) {
7311 vma = find_vma(mm, addr-len);
7312- if (!vma || addr <= vma->vm_start) {
7313+ if (check_heap_stack_gap(vma, addr - len, len)) {
7314 /* remember the address as a hint for next time */
7315 return (mm->free_area_cache = addr-len);
7316 }
7317@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7318 if (unlikely(mm->mmap_base < len))
7319 goto bottomup;
7320
7321- addr = (mm->mmap_base-len) & HPAGE_MASK;
7322+ addr = mm->mmap_base - len;
7323
7324 do {
7325+ addr &= HPAGE_MASK;
7326 /*
7327 * Lookup failure means no vma is above this address,
7328 * else if new region fits below vma->vm_start,
7329 * return with success:
7330 */
7331 vma = find_vma(mm, addr);
7332- if (likely(!vma || addr+len <= vma->vm_start)) {
7333+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7334 /* remember the address as a hint for next time */
7335 return (mm->free_area_cache = addr);
7336 }
7337@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7338 mm->cached_hole_size = vma->vm_start - addr;
7339
7340 /* try just below the current vma->vm_start */
7341- addr = (vma->vm_start-len) & HPAGE_MASK;
7342- } while (likely(len < vma->vm_start));
7343+ addr = skip_heap_stack_gap(vma, len);
7344+ } while (!IS_ERR_VALUE(addr));
7345
7346 bottomup:
7347 /*
7348@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7349 if (addr) {
7350 addr = ALIGN(addr, HPAGE_SIZE);
7351 vma = find_vma(mm, addr);
7352- if (task_size - len >= addr &&
7353- (!vma || addr + len <= vma->vm_start))
7354+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7355 return addr;
7356 }
7357 if (mm->get_unmapped_area == arch_get_unmapped_area)
7358diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7359index f4500c6..889656c 100644
7360--- a/arch/tile/include/asm/atomic_64.h
7361+++ b/arch/tile/include/asm/atomic_64.h
7362@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7363
7364 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7365
7366+#define atomic64_read_unchecked(v) atomic64_read(v)
7367+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7368+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7369+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7370+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7371+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7372+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7373+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7374+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7375+
7376 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7377 #define smp_mb__before_atomic_dec() smp_mb()
7378 #define smp_mb__after_atomic_dec() smp_mb()
7379diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7380index a9a5299..0fce79e 100644
7381--- a/arch/tile/include/asm/cache.h
7382+++ b/arch/tile/include/asm/cache.h
7383@@ -15,11 +15,12 @@
7384 #ifndef _ASM_TILE_CACHE_H
7385 #define _ASM_TILE_CACHE_H
7386
7387+#include <linux/const.h>
7388 #include <arch/chip.h>
7389
7390 /* bytes per L1 data cache line */
7391 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7392-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7393+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7394
7395 /* bytes per L2 cache line */
7396 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7397diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7398index 9ab078a..d6635c2 100644
7399--- a/arch/tile/include/asm/uaccess.h
7400+++ b/arch/tile/include/asm/uaccess.h
7401@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7402 const void __user *from,
7403 unsigned long n)
7404 {
7405- int sz = __compiletime_object_size(to);
7406+ size_t sz = __compiletime_object_size(to);
7407
7408- if (likely(sz == -1 || sz >= n))
7409+ if (likely(sz == (size_t)-1 || sz >= n))
7410 n = _copy_from_user(to, from, n);
7411 else
7412 copy_from_user_overflow();
7413diff --git a/arch/um/Makefile b/arch/um/Makefile
7414index 0970910..9f65c40 100644
7415--- a/arch/um/Makefile
7416+++ b/arch/um/Makefile
7417@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7418 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7419 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7420
7421+ifdef CONSTIFY_PLUGIN
7422+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7423+endif
7424+
7425 #This will adjust *FLAGS accordingly to the platform.
7426 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7427
7428diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7429index 19e1bdd..3665b77 100644
7430--- a/arch/um/include/asm/cache.h
7431+++ b/arch/um/include/asm/cache.h
7432@@ -1,6 +1,7 @@
7433 #ifndef __UM_CACHE_H
7434 #define __UM_CACHE_H
7435
7436+#include <linux/const.h>
7437
7438 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7439 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7440@@ -12,6 +13,6 @@
7441 # define L1_CACHE_SHIFT 5
7442 #endif
7443
7444-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7445+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7446
7447 #endif
7448diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7449index 2e0a6b1..a64d0f5 100644
7450--- a/arch/um/include/asm/kmap_types.h
7451+++ b/arch/um/include/asm/kmap_types.h
7452@@ -8,6 +8,6 @@
7453
7454 /* No more #include "asm/arch/kmap_types.h" ! */
7455
7456-#define KM_TYPE_NR 14
7457+#define KM_TYPE_NR 15
7458
7459 #endif
7460diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7461index 7cfc3ce..cbd1a58 100644
7462--- a/arch/um/include/asm/page.h
7463+++ b/arch/um/include/asm/page.h
7464@@ -14,6 +14,9 @@
7465 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7466 #define PAGE_MASK (~(PAGE_SIZE-1))
7467
7468+#define ktla_ktva(addr) (addr)
7469+#define ktva_ktla(addr) (addr)
7470+
7471 #ifndef __ASSEMBLY__
7472
7473 struct page;
7474diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7475index 0032f92..cd151e0 100644
7476--- a/arch/um/include/asm/pgtable-3level.h
7477+++ b/arch/um/include/asm/pgtable-3level.h
7478@@ -58,6 +58,7 @@
7479 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7480 #define pud_populate(mm, pud, pmd) \
7481 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7482+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7483
7484 #ifdef CONFIG_64BIT
7485 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7486diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7487index c5f5afa..6abce4b 100644
7488--- a/arch/um/kernel/process.c
7489+++ b/arch/um/kernel/process.c
7490@@ -402,22 +402,6 @@ int singlestepping(void * t)
7491 return 2;
7492 }
7493
7494-/*
7495- * Only x86 and x86_64 have an arch_align_stack().
7496- * All other arches have "#define arch_align_stack(x) (x)"
7497- * in their asm/system.h
7498- * As this is included in UML from asm-um/system-generic.h,
7499- * we can use it to behave as the subarch does.
7500- */
7501-#ifndef arch_align_stack
7502-unsigned long arch_align_stack(unsigned long sp)
7503-{
7504- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7505- sp -= get_random_int() % 8192;
7506- return sp & ~0xf;
7507-}
7508-#endif
7509-
7510 unsigned long get_wchan(struct task_struct *p)
7511 {
7512 unsigned long stack_page, sp, ip;
7513diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7514index ad8f795..2c7eec6 100644
7515--- a/arch/unicore32/include/asm/cache.h
7516+++ b/arch/unicore32/include/asm/cache.h
7517@@ -12,8 +12,10 @@
7518 #ifndef __UNICORE_CACHE_H__
7519 #define __UNICORE_CACHE_H__
7520
7521-#define L1_CACHE_SHIFT (5)
7522-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7523+#include <linux/const.h>
7524+
7525+#define L1_CACHE_SHIFT 5
7526+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7527
7528 /*
7529 * Memory returned by kmalloc() may be used for DMA, so we must make
7530diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7531index 50a1d1f..c26369f 100644
7532--- a/arch/x86/Kconfig
7533+++ b/arch/x86/Kconfig
7534@@ -220,7 +220,7 @@ config X86_HT
7535
7536 config X86_32_LAZY_GS
7537 def_bool y
7538- depends on X86_32 && !CC_STACKPROTECTOR
7539+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7540
7541 config ARCH_HWEIGHT_CFLAGS
7542 string
7543@@ -1049,7 +1049,7 @@ choice
7544
7545 config NOHIGHMEM
7546 bool "off"
7547- depends on !X86_NUMAQ
7548+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7549 ---help---
7550 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7551 However, the address space of 32-bit x86 processors is only 4
7552@@ -1086,7 +1086,7 @@ config NOHIGHMEM
7553
7554 config HIGHMEM4G
7555 bool "4GB"
7556- depends on !X86_NUMAQ
7557+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7558 ---help---
7559 Select this if you have a 32-bit processor and between 1 and 4
7560 gigabytes of physical RAM.
7561@@ -1140,7 +1140,7 @@ config PAGE_OFFSET
7562 hex
7563 default 0xB0000000 if VMSPLIT_3G_OPT
7564 default 0x80000000 if VMSPLIT_2G
7565- default 0x78000000 if VMSPLIT_2G_OPT
7566+ default 0x70000000 if VMSPLIT_2G_OPT
7567 default 0x40000000 if VMSPLIT_1G
7568 default 0xC0000000
7569 depends on X86_32
7570@@ -1528,6 +1528,7 @@ config SECCOMP
7571
7572 config CC_STACKPROTECTOR
7573 bool "Enable -fstack-protector buffer overflow detection"
7574+ depends on X86_64 || !PAX_MEMORY_UDEREF
7575 ---help---
7576 This option turns on the -fstack-protector GCC feature. This
7577 feature puts, at the beginning of functions, a canary value on
7578@@ -1585,6 +1586,7 @@ config KEXEC_JUMP
7579 config PHYSICAL_START
7580 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7581 default "0x1000000"
7582+ range 0x400000 0x40000000
7583 ---help---
7584 This gives the physical address where the kernel is loaded.
7585
7586@@ -1648,6 +1650,7 @@ config X86_NEED_RELOCS
7587 config PHYSICAL_ALIGN
7588 hex "Alignment value to which kernel should be aligned" if X86_32
7589 default "0x1000000"
7590+ range 0x400000 0x1000000 if PAX_KERNEXEC
7591 range 0x2000 0x1000000
7592 ---help---
7593 This value puts the alignment restrictions on physical address
7594@@ -1679,9 +1682,10 @@ config HOTPLUG_CPU
7595 Say N if you want to disable CPU hotplug.
7596
7597 config COMPAT_VDSO
7598- def_bool y
7599+ def_bool n
7600 prompt "Compat VDSO support"
7601 depends on X86_32 || IA32_EMULATION
7602+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7603 ---help---
7604 Map the 32-bit VDSO to the predictable old-style address too.
7605
7606diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7607index 706e12e..62e4feb 100644
7608--- a/arch/x86/Kconfig.cpu
7609+++ b/arch/x86/Kconfig.cpu
7610@@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7611
7612 config X86_F00F_BUG
7613 def_bool y
7614- depends on M586MMX || M586TSC || M586 || M486 || M386
7615+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7616
7617 config X86_INVD_BUG
7618 def_bool y
7619@@ -358,7 +358,7 @@ config X86_POPAD_OK
7620
7621 config X86_ALIGNMENT_16
7622 def_bool y
7623- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7624+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7625
7626 config X86_INTEL_USERCOPY
7627 def_bool y
7628@@ -404,7 +404,7 @@ config X86_CMPXCHG64
7629 # generates cmov.
7630 config X86_CMOV
7631 def_bool y
7632- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7633+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7634
7635 config X86_MINIMUM_CPU_FAMILY
7636 int
7637diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7638index b322f12..652d0d9 100644
7639--- a/arch/x86/Kconfig.debug
7640+++ b/arch/x86/Kconfig.debug
7641@@ -84,7 +84,7 @@ config X86_PTDUMP
7642 config DEBUG_RODATA
7643 bool "Write protect kernel read-only data structures"
7644 default y
7645- depends on DEBUG_KERNEL
7646+ depends on DEBUG_KERNEL && BROKEN
7647 ---help---
7648 Mark the kernel read-only data as write-protected in the pagetables,
7649 in order to catch accidental (and incorrect) writes to such const
7650@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7651
7652 config DEBUG_SET_MODULE_RONX
7653 bool "Set loadable kernel module data as NX and text as RO"
7654- depends on MODULES
7655+ depends on MODULES && BROKEN
7656 ---help---
7657 This option helps catch unintended modifications to loadable
7658 kernel module's text and read-only data. It also prevents execution
7659@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7660
7661 config DEBUG_STRICT_USER_COPY_CHECKS
7662 bool "Strict copy size checks"
7663- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7664+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7665 ---help---
7666 Enabling this option turns a certain set of sanity checks for user
7667 copy operations into compile time failures.
7668diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7669index 474ca35..d44c6a0 100644
7670--- a/arch/x86/Makefile
7671+++ b/arch/x86/Makefile
7672@@ -50,6 +50,7 @@ else
7673 UTS_MACHINE := x86_64
7674 CHECKFLAGS += -D__x86_64__ -m64
7675
7676+ biarch := $(call cc-option,-m64)
7677 KBUILD_AFLAGS += -m64
7678 KBUILD_CFLAGS += -m64
7679
7680@@ -229,3 +230,12 @@ define archhelp
7681 echo ' FDARGS="..." arguments for the booted kernel'
7682 echo ' FDINITRD=file initrd for the booted kernel'
7683 endef
7684+
7685+define OLD_LD
7686+
7687+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7688+*** Please upgrade your binutils to 2.18 or newer
7689+endef
7690+
7691+archprepare:
7692+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7693diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7694index f7535be..37db2d1 100644
7695--- a/arch/x86/boot/Makefile
7696+++ b/arch/x86/boot/Makefile
7697@@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7698 $(call cc-option, -fno-stack-protector) \
7699 $(call cc-option, -mpreferred-stack-boundary=2)
7700 KBUILD_CFLAGS += $(call cc-option, -m32)
7701+ifdef CONSTIFY_PLUGIN
7702+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7703+endif
7704 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7705 GCOV_PROFILE := n
7706
7707diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7708index 878e4b9..20537ab 100644
7709--- a/arch/x86/boot/bitops.h
7710+++ b/arch/x86/boot/bitops.h
7711@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7712 u8 v;
7713 const u32 *p = (const u32 *)addr;
7714
7715- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7716+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7717 return v;
7718 }
7719
7720@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7721
7722 static inline void set_bit(int nr, void *addr)
7723 {
7724- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7725+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7726 }
7727
7728 #endif /* BOOT_BITOPS_H */
7729diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7730index 18997e5..83d9c67 100644
7731--- a/arch/x86/boot/boot.h
7732+++ b/arch/x86/boot/boot.h
7733@@ -85,7 +85,7 @@ static inline void io_delay(void)
7734 static inline u16 ds(void)
7735 {
7736 u16 seg;
7737- asm("movw %%ds,%0" : "=rm" (seg));
7738+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7739 return seg;
7740 }
7741
7742@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7743 static inline int memcmp(const void *s1, const void *s2, size_t len)
7744 {
7745 u8 diff;
7746- asm("repe; cmpsb; setnz %0"
7747+ asm volatile("repe; cmpsb; setnz %0"
7748 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7749 return diff;
7750 }
7751diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7752index e398bb5..80fc805 100644
7753--- a/arch/x86/boot/compressed/Makefile
7754+++ b/arch/x86/boot/compressed/Makefile
7755@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7756 KBUILD_CFLAGS += $(cflags-y)
7757 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7758 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7759+ifdef CONSTIFY_PLUGIN
7760+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7761+endif
7762
7763 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7764 GCOV_PROFILE := n
7765diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7766index b3e0227..f2c02d5 100644
7767--- a/arch/x86/boot/compressed/eboot.c
7768+++ b/arch/x86/boot/compressed/eboot.c
7769@@ -142,7 +142,6 @@ again:
7770 *addr = max_addr;
7771 }
7772
7773-free_pool:
7774 efi_call_phys1(sys_table->boottime->free_pool, map);
7775
7776 fail:
7777@@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7778 if (i == map_size / desc_size)
7779 status = EFI_NOT_FOUND;
7780
7781-free_pool:
7782 efi_call_phys1(sys_table->boottime->free_pool, map);
7783 fail:
7784 return status;
7785diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7786index aa4aaf1..6656f2f 100644
7787--- a/arch/x86/boot/compressed/head_32.S
7788+++ b/arch/x86/boot/compressed/head_32.S
7789@@ -116,7 +116,7 @@ preferred_addr:
7790 notl %eax
7791 andl %eax, %ebx
7792 #else
7793- movl $LOAD_PHYSICAL_ADDR, %ebx
7794+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7795 #endif
7796
7797 /* Target address to relocate to for decompression */
7798@@ -202,7 +202,7 @@ relocated:
7799 * and where it was actually loaded.
7800 */
7801 movl %ebp, %ebx
7802- subl $LOAD_PHYSICAL_ADDR, %ebx
7803+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7804 jz 2f /* Nothing to be done if loaded at compiled addr. */
7805 /*
7806 * Process relocations.
7807@@ -210,8 +210,7 @@ relocated:
7808
7809 1: subl $4, %edi
7810 movl (%edi), %ecx
7811- testl %ecx, %ecx
7812- jz 2f
7813+ jecxz 2f
7814 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7815 jmp 1b
7816 2:
7817diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7818index 2c4b171..e1fa5b1 100644
7819--- a/arch/x86/boot/compressed/head_64.S
7820+++ b/arch/x86/boot/compressed/head_64.S
7821@@ -91,7 +91,7 @@ ENTRY(startup_32)
7822 notl %eax
7823 andl %eax, %ebx
7824 #else
7825- movl $LOAD_PHYSICAL_ADDR, %ebx
7826+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7827 #endif
7828
7829 /* Target address to relocate to for decompression */
7830@@ -273,7 +273,7 @@ preferred_addr:
7831 notq %rax
7832 andq %rax, %rbp
7833 #else
7834- movq $LOAD_PHYSICAL_ADDR, %rbp
7835+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7836 #endif
7837
7838 /* Target address to relocate to for decompression */
7839diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7840index 88f7ff6..ed695dd 100644
7841--- a/arch/x86/boot/compressed/misc.c
7842+++ b/arch/x86/boot/compressed/misc.c
7843@@ -303,7 +303,7 @@ static void parse_elf(void *output)
7844 case PT_LOAD:
7845 #ifdef CONFIG_RELOCATABLE
7846 dest = output;
7847- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7848+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7849 #else
7850 dest = (void *)(phdr->p_paddr);
7851 #endif
7852@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7853 error("Destination address too large");
7854 #endif
7855 #ifndef CONFIG_RELOCATABLE
7856- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7857+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7858 error("Wrong destination address");
7859 #endif
7860
7861diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7862index 4d3ff03..e4972ff 100644
7863--- a/arch/x86/boot/cpucheck.c
7864+++ b/arch/x86/boot/cpucheck.c
7865@@ -74,7 +74,7 @@ static int has_fpu(void)
7866 u16 fcw = -1, fsw = -1;
7867 u32 cr0;
7868
7869- asm("movl %%cr0,%0" : "=r" (cr0));
7870+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
7871 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7872 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7873 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7874@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7875 {
7876 u32 f0, f1;
7877
7878- asm("pushfl ; "
7879+ asm volatile("pushfl ; "
7880 "pushfl ; "
7881 "popl %0 ; "
7882 "movl %0,%1 ; "
7883@@ -115,7 +115,7 @@ static void get_flags(void)
7884 set_bit(X86_FEATURE_FPU, cpu.flags);
7885
7886 if (has_eflag(X86_EFLAGS_ID)) {
7887- asm("cpuid"
7888+ asm volatile("cpuid"
7889 : "=a" (max_intel_level),
7890 "=b" (cpu_vendor[0]),
7891 "=d" (cpu_vendor[1]),
7892@@ -124,7 +124,7 @@ static void get_flags(void)
7893
7894 if (max_intel_level >= 0x00000001 &&
7895 max_intel_level <= 0x0000ffff) {
7896- asm("cpuid"
7897+ asm volatile("cpuid"
7898 : "=a" (tfms),
7899 "=c" (cpu.flags[4]),
7900 "=d" (cpu.flags[0])
7901@@ -136,7 +136,7 @@ static void get_flags(void)
7902 cpu.model += ((tfms >> 16) & 0xf) << 4;
7903 }
7904
7905- asm("cpuid"
7906+ asm volatile("cpuid"
7907 : "=a" (max_amd_level)
7908 : "a" (0x80000000)
7909 : "ebx", "ecx", "edx");
7910@@ -144,7 +144,7 @@ static void get_flags(void)
7911 if (max_amd_level >= 0x80000001 &&
7912 max_amd_level <= 0x8000ffff) {
7913 u32 eax = 0x80000001;
7914- asm("cpuid"
7915+ asm volatile("cpuid"
7916 : "+a" (eax),
7917 "=c" (cpu.flags[6]),
7918 "=d" (cpu.flags[1])
7919@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7920 u32 ecx = MSR_K7_HWCR;
7921 u32 eax, edx;
7922
7923- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7924+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7925 eax &= ~(1 << 15);
7926- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7927+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7928
7929 get_flags(); /* Make sure it really did something */
7930 err = check_flags();
7931@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7932 u32 ecx = MSR_VIA_FCR;
7933 u32 eax, edx;
7934
7935- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7936+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7937 eax |= (1<<1)|(1<<7);
7938- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7939+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7940
7941 set_bit(X86_FEATURE_CX8, cpu.flags);
7942 err = check_flags();
7943@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7944 u32 eax, edx;
7945 u32 level = 1;
7946
7947- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7948- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7949- asm("cpuid"
7950+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7951+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7952+ asm volatile("cpuid"
7953 : "+a" (level), "=d" (cpu.flags[0])
7954 : : "ecx", "ebx");
7955- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7956+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7957
7958 err = check_flags();
7959 }
7960diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7961index b4e15dd..8ac59ce 100644
7962--- a/arch/x86/boot/header.S
7963+++ b/arch/x86/boot/header.S
7964@@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7965 # single linked list of
7966 # struct setup_data
7967
7968-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7969+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7970
7971 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7972+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
7973+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
7974+#else
7975 #define VO_INIT_SIZE (VO__end - VO__text)
7976+#endif
7977 #if ZO_INIT_SIZE > VO_INIT_SIZE
7978 #define INIT_SIZE ZO_INIT_SIZE
7979 #else
7980diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7981index db75d07..8e6d0af 100644
7982--- a/arch/x86/boot/memory.c
7983+++ b/arch/x86/boot/memory.c
7984@@ -19,7 +19,7 @@
7985
7986 static int detect_memory_e820(void)
7987 {
7988- int count = 0;
7989+ unsigned int count = 0;
7990 struct biosregs ireg, oreg;
7991 struct e820entry *desc = boot_params.e820_map;
7992 static struct e820entry buf; /* static so it is zeroed */
7993diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7994index 11e8c6e..fdbb1ed 100644
7995--- a/arch/x86/boot/video-vesa.c
7996+++ b/arch/x86/boot/video-vesa.c
7997@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7998
7999 boot_params.screen_info.vesapm_seg = oreg.es;
8000 boot_params.screen_info.vesapm_off = oreg.di;
8001+ boot_params.screen_info.vesapm_size = oreg.cx;
8002 }
8003
8004 /*
8005diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8006index 43eda28..5ab5fdb 100644
8007--- a/arch/x86/boot/video.c
8008+++ b/arch/x86/boot/video.c
8009@@ -96,7 +96,7 @@ static void store_mode_params(void)
8010 static unsigned int get_entry(void)
8011 {
8012 char entry_buf[4];
8013- int i, len = 0;
8014+ unsigned int i, len = 0;
8015 int key;
8016 unsigned int v;
8017
8018diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8019index 5b577d5..3c1fed4 100644
8020--- a/arch/x86/crypto/aes-x86_64-asm_64.S
8021+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8022@@ -8,6 +8,8 @@
8023 * including this sentence is retained in full.
8024 */
8025
8026+#include <asm/alternative-asm.h>
8027+
8028 .extern crypto_ft_tab
8029 .extern crypto_it_tab
8030 .extern crypto_fl_tab
8031@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8032 je B192; \
8033 leaq 32(r9),r9;
8034
8035+#define ret pax_force_retaddr 0, 1; ret
8036+
8037 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8038 movq r1,r2; \
8039 movq r3,r4; \
8040diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8041index 3470624..201259d 100644
8042--- a/arch/x86/crypto/aesni-intel_asm.S
8043+++ b/arch/x86/crypto/aesni-intel_asm.S
8044@@ -31,6 +31,7 @@
8045
8046 #include <linux/linkage.h>
8047 #include <asm/inst.h>
8048+#include <asm/alternative-asm.h>
8049
8050 #ifdef __x86_64__
8051 .data
8052@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8053 pop %r14
8054 pop %r13
8055 pop %r12
8056+ pax_force_retaddr 0, 1
8057 ret
8058+ENDPROC(aesni_gcm_dec)
8059
8060
8061 /*****************************************************************************
8062@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8063 pop %r14
8064 pop %r13
8065 pop %r12
8066+ pax_force_retaddr 0, 1
8067 ret
8068+ENDPROC(aesni_gcm_enc)
8069
8070 #endif
8071
8072@@ -1714,6 +1719,7 @@ _key_expansion_256a:
8073 pxor %xmm1, %xmm0
8074 movaps %xmm0, (TKEYP)
8075 add $0x10, TKEYP
8076+ pax_force_retaddr_bts
8077 ret
8078
8079 .align 4
8080@@ -1738,6 +1744,7 @@ _key_expansion_192a:
8081 shufps $0b01001110, %xmm2, %xmm1
8082 movaps %xmm1, 0x10(TKEYP)
8083 add $0x20, TKEYP
8084+ pax_force_retaddr_bts
8085 ret
8086
8087 .align 4
8088@@ -1757,6 +1764,7 @@ _key_expansion_192b:
8089
8090 movaps %xmm0, (TKEYP)
8091 add $0x10, TKEYP
8092+ pax_force_retaddr_bts
8093 ret
8094
8095 .align 4
8096@@ -1769,6 +1777,7 @@ _key_expansion_256b:
8097 pxor %xmm1, %xmm2
8098 movaps %xmm2, (TKEYP)
8099 add $0x10, TKEYP
8100+ pax_force_retaddr_bts
8101 ret
8102
8103 /*
8104@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8105 #ifndef __x86_64__
8106 popl KEYP
8107 #endif
8108+ pax_force_retaddr 0, 1
8109 ret
8110+ENDPROC(aesni_set_key)
8111
8112 /*
8113 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8114@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8115 popl KLEN
8116 popl KEYP
8117 #endif
8118+ pax_force_retaddr 0, 1
8119 ret
8120+ENDPROC(aesni_enc)
8121
8122 /*
8123 * _aesni_enc1: internal ABI
8124@@ -1959,6 +1972,7 @@ _aesni_enc1:
8125 AESENC KEY STATE
8126 movaps 0x70(TKEYP), KEY
8127 AESENCLAST KEY STATE
8128+ pax_force_retaddr_bts
8129 ret
8130
8131 /*
8132@@ -2067,6 +2081,7 @@ _aesni_enc4:
8133 AESENCLAST KEY STATE2
8134 AESENCLAST KEY STATE3
8135 AESENCLAST KEY STATE4
8136+ pax_force_retaddr_bts
8137 ret
8138
8139 /*
8140@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8141 popl KLEN
8142 popl KEYP
8143 #endif
8144+ pax_force_retaddr 0, 1
8145 ret
8146+ENDPROC(aesni_dec)
8147
8148 /*
8149 * _aesni_dec1: internal ABI
8150@@ -2146,6 +2163,7 @@ _aesni_dec1:
8151 AESDEC KEY STATE
8152 movaps 0x70(TKEYP), KEY
8153 AESDECLAST KEY STATE
8154+ pax_force_retaddr_bts
8155 ret
8156
8157 /*
8158@@ -2254,6 +2272,7 @@ _aesni_dec4:
8159 AESDECLAST KEY STATE2
8160 AESDECLAST KEY STATE3
8161 AESDECLAST KEY STATE4
8162+ pax_force_retaddr_bts
8163 ret
8164
8165 /*
8166@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8167 popl KEYP
8168 popl LEN
8169 #endif
8170+ pax_force_retaddr 0, 1
8171 ret
8172+ENDPROC(aesni_ecb_enc)
8173
8174 /*
8175 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8176@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8177 popl KEYP
8178 popl LEN
8179 #endif
8180+ pax_force_retaddr 0, 1
8181 ret
8182+ENDPROC(aesni_ecb_dec)
8183
8184 /*
8185 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8186@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8187 popl LEN
8188 popl IVP
8189 #endif
8190+ pax_force_retaddr 0, 1
8191 ret
8192+ENDPROC(aesni_cbc_enc)
8193
8194 /*
8195 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8196@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8197 popl LEN
8198 popl IVP
8199 #endif
8200+ pax_force_retaddr 0, 1
8201 ret
8202+ENDPROC(aesni_cbc_dec)
8203
8204 #ifdef __x86_64__
8205 .align 16
8206@@ -2526,6 +2553,7 @@ _aesni_inc_init:
8207 mov $1, TCTR_LOW
8208 MOVQ_R64_XMM TCTR_LOW INC
8209 MOVQ_R64_XMM CTR TCTR_LOW
8210+ pax_force_retaddr_bts
8211 ret
8212
8213 /*
8214@@ -2554,6 +2582,7 @@ _aesni_inc:
8215 .Linc_low:
8216 movaps CTR, IV
8217 PSHUFB_XMM BSWAP_MASK IV
8218+ pax_force_retaddr_bts
8219 ret
8220
8221 /*
8222@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8223 .Lctr_enc_ret:
8224 movups IV, (IVP)
8225 .Lctr_enc_just_ret:
8226+ pax_force_retaddr 0, 1
8227 ret
8228+ENDPROC(aesni_ctr_enc)
8229 #endif
8230diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8231index 391d245..67f35c2 100644
8232--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8233+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8234@@ -20,6 +20,8 @@
8235 *
8236 */
8237
8238+#include <asm/alternative-asm.h>
8239+
8240 .file "blowfish-x86_64-asm.S"
8241 .text
8242
8243@@ -151,9 +153,11 @@ __blowfish_enc_blk:
8244 jnz __enc_xor;
8245
8246 write_block();
8247+ pax_force_retaddr 0, 1
8248 ret;
8249 __enc_xor:
8250 xor_block();
8251+ pax_force_retaddr 0, 1
8252 ret;
8253
8254 .align 8
8255@@ -188,6 +192,7 @@ blowfish_dec_blk:
8256
8257 movq %r11, %rbp;
8258
8259+ pax_force_retaddr 0, 1
8260 ret;
8261
8262 /**********************************************************************
8263@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8264
8265 popq %rbx;
8266 popq %rbp;
8267+ pax_force_retaddr 0, 1
8268 ret;
8269
8270 __enc_xor4:
8271@@ -349,6 +355,7 @@ __enc_xor4:
8272
8273 popq %rbx;
8274 popq %rbp;
8275+ pax_force_retaddr 0, 1
8276 ret;
8277
8278 .align 8
8279@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8280 popq %rbx;
8281 popq %rbp;
8282
8283+ pax_force_retaddr 0, 1
8284 ret;
8285
8286diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8287index 0b33743..7a56206 100644
8288--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8289+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8290@@ -20,6 +20,8 @@
8291 *
8292 */
8293
8294+#include <asm/alternative-asm.h>
8295+
8296 .file "camellia-x86_64-asm_64.S"
8297 .text
8298
8299@@ -229,12 +231,14 @@ __enc_done:
8300 enc_outunpack(mov, RT1);
8301
8302 movq RRBP, %rbp;
8303+ pax_force_retaddr 0, 1
8304 ret;
8305
8306 __enc_xor:
8307 enc_outunpack(xor, RT1);
8308
8309 movq RRBP, %rbp;
8310+ pax_force_retaddr 0, 1
8311 ret;
8312
8313 .global camellia_dec_blk;
8314@@ -275,6 +279,7 @@ __dec_rounds16:
8315 dec_outunpack();
8316
8317 movq RRBP, %rbp;
8318+ pax_force_retaddr 0, 1
8319 ret;
8320
8321 /**********************************************************************
8322@@ -468,6 +473,7 @@ __enc2_done:
8323
8324 movq RRBP, %rbp;
8325 popq %rbx;
8326+ pax_force_retaddr 0, 1
8327 ret;
8328
8329 __enc2_xor:
8330@@ -475,6 +481,7 @@ __enc2_xor:
8331
8332 movq RRBP, %rbp;
8333 popq %rbx;
8334+ pax_force_retaddr 0, 1
8335 ret;
8336
8337 .global camellia_dec_blk_2way;
8338@@ -517,4 +524,5 @@ __dec2_rounds16:
8339
8340 movq RRBP, %rbp;
8341 movq RXOR, %rbx;
8342+ pax_force_retaddr 0, 1
8343 ret;
8344diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8345index 6214a9b..1f4fc9a 100644
8346--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8347+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8348@@ -1,3 +1,5 @@
8349+#include <asm/alternative-asm.h>
8350+
8351 # enter ECRYPT_encrypt_bytes
8352 .text
8353 .p2align 5
8354@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8355 add %r11,%rsp
8356 mov %rdi,%rax
8357 mov %rsi,%rdx
8358+ pax_force_retaddr 0, 1
8359 ret
8360 # bytesatleast65:
8361 ._bytesatleast65:
8362@@ -891,6 +894,7 @@ ECRYPT_keysetup:
8363 add %r11,%rsp
8364 mov %rdi,%rax
8365 mov %rsi,%rdx
8366+ pax_force_retaddr
8367 ret
8368 # enter ECRYPT_ivsetup
8369 .text
8370@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8371 add %r11,%rsp
8372 mov %rdi,%rax
8373 mov %rsi,%rdx
8374+ pax_force_retaddr
8375 ret
8376diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8377index 504106b..4e50951 100644
8378--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8379+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8380@@ -24,6 +24,8 @@
8381 *
8382 */
8383
8384+#include <asm/alternative-asm.h>
8385+
8386 .file "serpent-avx-x86_64-asm_64.S"
8387 .text
8388
8389@@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8390 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8391 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8392
8393+ pax_force_retaddr
8394 ret;
8395
8396 __enc_xor8:
8397 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8398 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8399
8400+ pax_force_retaddr
8401 ret;
8402
8403 .align 8
8404@@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8405 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8406 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8407
8408+ pax_force_retaddr
8409 ret;
8410diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8411index 3ee1ff0..cbc568b 100644
8412--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8413+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8414@@ -24,6 +24,8 @@
8415 *
8416 */
8417
8418+#include <asm/alternative-asm.h>
8419+
8420 .file "serpent-sse2-x86_64-asm_64.S"
8421 .text
8422
8423@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8424 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8425 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8426
8427+ pax_force_retaddr
8428 ret;
8429
8430 __enc_xor8:
8431 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8432 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8433
8434+ pax_force_retaddr
8435 ret;
8436
8437 .align 8
8438@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8439 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8440 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8441
8442+ pax_force_retaddr
8443 ret;
8444diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8445index 49d6987..df66bd4 100644
8446--- a/arch/x86/crypto/sha1_ssse3_asm.S
8447+++ b/arch/x86/crypto/sha1_ssse3_asm.S
8448@@ -28,6 +28,8 @@
8449 * (at your option) any later version.
8450 */
8451
8452+#include <asm/alternative-asm.h>
8453+
8454 #define CTX %rdi // arg1
8455 #define BUF %rsi // arg2
8456 #define CNT %rdx // arg3
8457@@ -104,6 +106,7 @@
8458 pop %r12
8459 pop %rbp
8460 pop %rbx
8461+ pax_force_retaddr 0, 1
8462 ret
8463
8464 .size \name, .-\name
8465diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8466index 35f4557..16b379f 100644
8467--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8468+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8469@@ -21,6 +21,8 @@
8470 *
8471 */
8472
8473+#include <asm/alternative-asm.h>
8474+
8475 .file "twofish-avx-x86_64-asm_64.S"
8476 .text
8477
8478@@ -250,12 +252,14 @@ __twofish_enc_blk_8way:
8479 outunpack_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8480 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8481
8482+ pax_force_retaddr
8483 ret;
8484
8485 __enc_xor8:
8486 outunpack_xor_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8487 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8488
8489+ pax_force_retaddr
8490 ret;
8491
8492 .align 8
8493@@ -297,4 +301,5 @@ twofish_dec_blk_8way:
8494 outunpack_blocks(%rsi, RA1, RB1, RC1, RD1, RK1, RX, RY, RK2);
8495 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX, RY, RK2);
8496
8497+ pax_force_retaddr
8498 ret;
8499diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8500index 5b012a2..36d5364 100644
8501--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8502+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8503@@ -20,6 +20,8 @@
8504 *
8505 */
8506
8507+#include <asm/alternative-asm.h>
8508+
8509 .file "twofish-x86_64-asm-3way.S"
8510 .text
8511
8512@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8513 popq %r13;
8514 popq %r14;
8515 popq %r15;
8516+ pax_force_retaddr 0, 1
8517 ret;
8518
8519 __enc_xor3:
8520@@ -271,6 +274,7 @@ __enc_xor3:
8521 popq %r13;
8522 popq %r14;
8523 popq %r15;
8524+ pax_force_retaddr 0, 1
8525 ret;
8526
8527 .global twofish_dec_blk_3way
8528@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8529 popq %r13;
8530 popq %r14;
8531 popq %r15;
8532+ pax_force_retaddr 0, 1
8533 ret;
8534
8535diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8536index 7bcf3fc..f53832f 100644
8537--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8538+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8539@@ -21,6 +21,7 @@
8540 .text
8541
8542 #include <asm/asm-offsets.h>
8543+#include <asm/alternative-asm.h>
8544
8545 #define a_offset 0
8546 #define b_offset 4
8547@@ -268,6 +269,7 @@ twofish_enc_blk:
8548
8549 popq R1
8550 movq $1,%rax
8551+ pax_force_retaddr 0, 1
8552 ret
8553
8554 twofish_dec_blk:
8555@@ -319,4 +321,5 @@ twofish_dec_blk:
8556
8557 popq R1
8558 movq $1,%rax
8559+ pax_force_retaddr 0, 1
8560 ret
8561diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8562index 07b3a68..bd2a388 100644
8563--- a/arch/x86/ia32/ia32_aout.c
8564+++ b/arch/x86/ia32/ia32_aout.c
8565@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8566 unsigned long dump_start, dump_size;
8567 struct user32 dump;
8568
8569+ memset(&dump, 0, sizeof(dump));
8570+
8571 fs = get_fs();
8572 set_fs(KERNEL_DS);
8573 has_dumped = 1;
8574diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8575index 673ac9b..7a8c5df 100644
8576--- a/arch/x86/ia32/ia32_signal.c
8577+++ b/arch/x86/ia32/ia32_signal.c
8578@@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8579 }
8580 seg = get_fs();
8581 set_fs(KERNEL_DS);
8582- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8583+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8584 set_fs(seg);
8585 if (ret >= 0 && uoss_ptr) {
8586 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8587@@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8588 */
8589 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8590 size_t frame_size,
8591- void **fpstate)
8592+ void __user **fpstate)
8593 {
8594 unsigned long sp;
8595
8596@@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8597
8598 if (used_math()) {
8599 sp = sp - sig_xstate_ia32_size;
8600- *fpstate = (struct _fpstate_ia32 *) sp;
8601+ *fpstate = (struct _fpstate_ia32 __user *) sp;
8602 if (save_i387_xstate_ia32(*fpstate) < 0)
8603 return (void __user *) -1L;
8604 }
8605@@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8606 sp -= frame_size;
8607 /* Align the stack pointer according to the i386 ABI,
8608 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8609- sp = ((sp + 4) & -16ul) - 4;
8610+ sp = ((sp - 12) & -16ul) - 4;
8611 return (void __user *) sp;
8612 }
8613
8614@@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8615 * These are actually not used anymore, but left because some
8616 * gdb versions depend on them as a marker.
8617 */
8618- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8619+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8620 } put_user_catch(err);
8621
8622 if (err)
8623@@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8624 0xb8,
8625 __NR_ia32_rt_sigreturn,
8626 0x80cd,
8627- 0,
8628+ 0
8629 };
8630
8631 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8632@@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8633
8634 if (ka->sa.sa_flags & SA_RESTORER)
8635 restorer = ka->sa.sa_restorer;
8636+ else if (current->mm->context.vdso)
8637+ /* Return stub is in 32bit vsyscall page */
8638+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8639 else
8640- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8641- rt_sigreturn);
8642+ restorer = &frame->retcode;
8643 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8644
8645 /*
8646 * Not actually used anymore, but left because some gdb
8647 * versions need it.
8648 */
8649- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8650+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8651 } put_user_catch(err);
8652
8653 if (err)
8654diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8655index 20e5f7b..f33c779 100644
8656--- a/arch/x86/ia32/ia32entry.S
8657+++ b/arch/x86/ia32/ia32entry.S
8658@@ -14,8 +14,10 @@
8659 #include <asm/segment.h>
8660 #include <asm/irqflags.h>
8661 #include <asm/asm.h>
8662+#include <asm/pgtable.h>
8663 #include <linux/linkage.h>
8664 #include <linux/err.h>
8665+#include <asm/alternative-asm.h>
8666
8667 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8668 #include <linux/elf-em.h>
8669@@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8670 ENDPROC(native_irq_enable_sysexit)
8671 #endif
8672
8673+ .macro pax_enter_kernel_user
8674+ pax_set_fptr_mask
8675+#ifdef CONFIG_PAX_MEMORY_UDEREF
8676+ call pax_enter_kernel_user
8677+#endif
8678+ .endm
8679+
8680+ .macro pax_exit_kernel_user
8681+#ifdef CONFIG_PAX_MEMORY_UDEREF
8682+ call pax_exit_kernel_user
8683+#endif
8684+#ifdef CONFIG_PAX_RANDKSTACK
8685+ pushq %rax
8686+ pushq %r11
8687+ call pax_randomize_kstack
8688+ popq %r11
8689+ popq %rax
8690+#endif
8691+ .endm
8692+
8693+.macro pax_erase_kstack
8694+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8695+ call pax_erase_kstack
8696+#endif
8697+.endm
8698+
8699 /*
8700 * 32bit SYSENTER instruction entry.
8701 *
8702@@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8703 CFI_REGISTER rsp,rbp
8704 SWAPGS_UNSAFE_STACK
8705 movq PER_CPU_VAR(kernel_stack), %rsp
8706- addq $(KERNEL_STACK_OFFSET),%rsp
8707- /*
8708- * No need to follow this irqs on/off section: the syscall
8709- * disabled irqs, here we enable it straight after entry:
8710- */
8711- ENABLE_INTERRUPTS(CLBR_NONE)
8712 movl %ebp,%ebp /* zero extension */
8713 pushq_cfi $__USER32_DS
8714 /*CFI_REL_OFFSET ss,0*/
8715@@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8716 CFI_REL_OFFSET rsp,0
8717 pushfq_cfi
8718 /*CFI_REL_OFFSET rflags,0*/
8719- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8720- CFI_REGISTER rip,r10
8721+ orl $X86_EFLAGS_IF,(%rsp)
8722+ GET_THREAD_INFO(%r11)
8723+ movl TI_sysenter_return(%r11), %r11d
8724+ CFI_REGISTER rip,r11
8725 pushq_cfi $__USER32_CS
8726 /*CFI_REL_OFFSET cs,0*/
8727 movl %eax, %eax
8728- pushq_cfi %r10
8729+ pushq_cfi %r11
8730 CFI_REL_OFFSET rip,0
8731 pushq_cfi %rax
8732 cld
8733 SAVE_ARGS 0,1,0
8734+ pax_enter_kernel_user
8735+
8736+#ifdef CONFIG_PAX_RANDKSTACK
8737+ pax_erase_kstack
8738+#endif
8739+
8740+ /*
8741+ * No need to follow this irqs on/off section: the syscall
8742+ * disabled irqs, here we enable it straight after entry:
8743+ */
8744+ ENABLE_INTERRUPTS(CLBR_NONE)
8745 /* no need to do an access_ok check here because rbp has been
8746 32bit zero extended */
8747+
8748+#ifdef CONFIG_PAX_MEMORY_UDEREF
8749+ mov $PAX_USER_SHADOW_BASE,%r11
8750+ add %r11,%rbp
8751+#endif
8752+
8753 1: movl (%rbp),%ebp
8754 _ASM_EXTABLE(1b,ia32_badarg)
8755- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8756- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8757+ GET_THREAD_INFO(%r11)
8758+ orl $TS_COMPAT,TI_status(%r11)
8759+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8760 CFI_REMEMBER_STATE
8761 jnz sysenter_tracesys
8762 cmpq $(IA32_NR_syscalls-1),%rax
8763@@ -159,12 +201,15 @@ sysenter_do_call:
8764 sysenter_dispatch:
8765 call *ia32_sys_call_table(,%rax,8)
8766 movq %rax,RAX-ARGOFFSET(%rsp)
8767+ GET_THREAD_INFO(%r11)
8768 DISABLE_INTERRUPTS(CLBR_NONE)
8769 TRACE_IRQS_OFF
8770- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8771+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8772 jnz sysexit_audit
8773 sysexit_from_sys_call:
8774- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8775+ pax_exit_kernel_user
8776+ pax_erase_kstack
8777+ andl $~TS_COMPAT,TI_status(%r11)
8778 /* clear IF, that popfq doesn't enable interrupts early */
8779 andl $~0x200,EFLAGS-R11(%rsp)
8780 movl RIP-R11(%rsp),%edx /* User %eip */
8781@@ -190,6 +235,9 @@ sysexit_from_sys_call:
8782 movl %eax,%esi /* 2nd arg: syscall number */
8783 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8784 call __audit_syscall_entry
8785+
8786+ pax_erase_kstack
8787+
8788 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8789 cmpq $(IA32_NR_syscalls-1),%rax
8790 ja ia32_badsys
8791@@ -201,7 +249,7 @@ sysexit_from_sys_call:
8792 .endm
8793
8794 .macro auditsys_exit exit
8795- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8796+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8797 jnz ia32_ret_from_sys_call
8798 TRACE_IRQS_ON
8799 sti
8800@@ -212,11 +260,12 @@ sysexit_from_sys_call:
8801 1: setbe %al /* 1 if error, 0 if not */
8802 movzbl %al,%edi /* zero-extend that into %edi */
8803 call __audit_syscall_exit
8804+ GET_THREAD_INFO(%r11)
8805 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8806 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8807 cli
8808 TRACE_IRQS_OFF
8809- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8810+ testl %edi,TI_flags(%r11)
8811 jz \exit
8812 CLEAR_RREGS -ARGOFFSET
8813 jmp int_with_check
8814@@ -234,7 +283,7 @@ sysexit_audit:
8815
8816 sysenter_tracesys:
8817 #ifdef CONFIG_AUDITSYSCALL
8818- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8819+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8820 jz sysenter_auditsys
8821 #endif
8822 SAVE_REST
8823@@ -246,6 +295,9 @@ sysenter_tracesys:
8824 RESTORE_REST
8825 cmpq $(IA32_NR_syscalls-1),%rax
8826 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8827+
8828+ pax_erase_kstack
8829+
8830 jmp sysenter_do_call
8831 CFI_ENDPROC
8832 ENDPROC(ia32_sysenter_target)
8833@@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8834 ENTRY(ia32_cstar_target)
8835 CFI_STARTPROC32 simple
8836 CFI_SIGNAL_FRAME
8837- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8838+ CFI_DEF_CFA rsp,0
8839 CFI_REGISTER rip,rcx
8840 /*CFI_REGISTER rflags,r11*/
8841 SWAPGS_UNSAFE_STACK
8842 movl %esp,%r8d
8843 CFI_REGISTER rsp,r8
8844 movq PER_CPU_VAR(kernel_stack),%rsp
8845+ SAVE_ARGS 8*6,0,0
8846+ pax_enter_kernel_user
8847+
8848+#ifdef CONFIG_PAX_RANDKSTACK
8849+ pax_erase_kstack
8850+#endif
8851+
8852 /*
8853 * No need to follow this irqs on/off section: the syscall
8854 * disabled irqs and here we enable it straight after entry:
8855 */
8856 ENABLE_INTERRUPTS(CLBR_NONE)
8857- SAVE_ARGS 8,0,0
8858 movl %eax,%eax /* zero extension */
8859 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8860 movq %rcx,RIP-ARGOFFSET(%rsp)
8861@@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8862 /* no need to do an access_ok check here because r8 has been
8863 32bit zero extended */
8864 /* hardware stack frame is complete now */
8865+
8866+#ifdef CONFIG_PAX_MEMORY_UDEREF
8867+ mov $PAX_USER_SHADOW_BASE,%r11
8868+ add %r11,%r8
8869+#endif
8870+
8871 1: movl (%r8),%r9d
8872 _ASM_EXTABLE(1b,ia32_badarg)
8873- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8874- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8875+ GET_THREAD_INFO(%r11)
8876+ orl $TS_COMPAT,TI_status(%r11)
8877+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8878 CFI_REMEMBER_STATE
8879 jnz cstar_tracesys
8880 cmpq $IA32_NR_syscalls-1,%rax
8881@@ -314,12 +379,15 @@ cstar_do_call:
8882 cstar_dispatch:
8883 call *ia32_sys_call_table(,%rax,8)
8884 movq %rax,RAX-ARGOFFSET(%rsp)
8885+ GET_THREAD_INFO(%r11)
8886 DISABLE_INTERRUPTS(CLBR_NONE)
8887 TRACE_IRQS_OFF
8888- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8889+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8890 jnz sysretl_audit
8891 sysretl_from_sys_call:
8892- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8893+ pax_exit_kernel_user
8894+ pax_erase_kstack
8895+ andl $~TS_COMPAT,TI_status(%r11)
8896 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8897 movl RIP-ARGOFFSET(%rsp),%ecx
8898 CFI_REGISTER rip,rcx
8899@@ -347,7 +415,7 @@ sysretl_audit:
8900
8901 cstar_tracesys:
8902 #ifdef CONFIG_AUDITSYSCALL
8903- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8904+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8905 jz cstar_auditsys
8906 #endif
8907 xchgl %r9d,%ebp
8908@@ -361,6 +429,9 @@ cstar_tracesys:
8909 xchgl %ebp,%r9d
8910 cmpq $(IA32_NR_syscalls-1),%rax
8911 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8912+
8913+ pax_erase_kstack
8914+
8915 jmp cstar_do_call
8916 END(ia32_cstar_target)
8917
8918@@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8919 CFI_REL_OFFSET rip,RIP-RIP
8920 PARAVIRT_ADJUST_EXCEPTION_FRAME
8921 SWAPGS
8922- /*
8923- * No need to follow this irqs on/off section: the syscall
8924- * disabled irqs and here we enable it straight after entry:
8925- */
8926- ENABLE_INTERRUPTS(CLBR_NONE)
8927 movl %eax,%eax
8928 pushq_cfi %rax
8929 cld
8930 /* note the registers are not zero extended to the sf.
8931 this could be a problem. */
8932 SAVE_ARGS 0,1,0
8933- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8934- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8935+ pax_enter_kernel_user
8936+
8937+#ifdef CONFIG_PAX_RANDKSTACK
8938+ pax_erase_kstack
8939+#endif
8940+
8941+ /*
8942+ * No need to follow this irqs on/off section: the syscall
8943+ * disabled irqs and here we enable it straight after entry:
8944+ */
8945+ ENABLE_INTERRUPTS(CLBR_NONE)
8946+ GET_THREAD_INFO(%r11)
8947+ orl $TS_COMPAT,TI_status(%r11)
8948+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8949 jnz ia32_tracesys
8950 cmpq $(IA32_NR_syscalls-1),%rax
8951 ja ia32_badsys
8952@@ -436,6 +514,9 @@ ia32_tracesys:
8953 RESTORE_REST
8954 cmpq $(IA32_NR_syscalls-1),%rax
8955 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8956+
8957+ pax_erase_kstack
8958+
8959 jmp ia32_do_call
8960 END(ia32_syscall)
8961
8962diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8963index 4540bec..714d913 100644
8964--- a/arch/x86/ia32/sys_ia32.c
8965+++ b/arch/x86/ia32/sys_ia32.c
8966@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8967 */
8968 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8969 {
8970- typeof(ubuf->st_uid) uid = 0;
8971- typeof(ubuf->st_gid) gid = 0;
8972+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
8973+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
8974 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8975 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8976 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8977@@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8978 return ret;
8979 }
8980
8981-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8982+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8983 int options)
8984 {
8985 return compat_sys_wait4(pid, stat_addr, options, NULL);
8986@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8987 mm_segment_t old_fs = get_fs();
8988
8989 set_fs(KERNEL_DS);
8990- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8991+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8992 set_fs(old_fs);
8993 if (put_compat_timespec(&t, interval))
8994 return -EFAULT;
8995@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8996 mm_segment_t old_fs = get_fs();
8997
8998 set_fs(KERNEL_DS);
8999- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9000+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9001 set_fs(old_fs);
9002 if (!ret) {
9003 switch (_NSIG_WORDS) {
9004@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9005 if (copy_siginfo_from_user32(&info, uinfo))
9006 return -EFAULT;
9007 set_fs(KERNEL_DS);
9008- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9009+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9010 set_fs(old_fs);
9011 return ret;
9012 }
9013@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9014 return -EFAULT;
9015
9016 set_fs(KERNEL_DS);
9017- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9018+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9019 count);
9020 set_fs(old_fs);
9021
9022diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9023index 952bd01..7692c6f 100644
9024--- a/arch/x86/include/asm/alternative-asm.h
9025+++ b/arch/x86/include/asm/alternative-asm.h
9026@@ -15,6 +15,45 @@
9027 .endm
9028 #endif
9029
9030+#ifdef KERNEXEC_PLUGIN
9031+ .macro pax_force_retaddr_bts rip=0
9032+ btsq $63,\rip(%rsp)
9033+ .endm
9034+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9035+ .macro pax_force_retaddr rip=0, reload=0
9036+ btsq $63,\rip(%rsp)
9037+ .endm
9038+ .macro pax_force_fptr ptr
9039+ btsq $63,\ptr
9040+ .endm
9041+ .macro pax_set_fptr_mask
9042+ .endm
9043+#endif
9044+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9045+ .macro pax_force_retaddr rip=0, reload=0
9046+ .if \reload
9047+ pax_set_fptr_mask
9048+ .endif
9049+ orq %r10,\rip(%rsp)
9050+ .endm
9051+ .macro pax_force_fptr ptr
9052+ orq %r10,\ptr
9053+ .endm
9054+ .macro pax_set_fptr_mask
9055+ movabs $0x8000000000000000,%r10
9056+ .endm
9057+#endif
9058+#else
9059+ .macro pax_force_retaddr rip=0, reload=0
9060+ .endm
9061+ .macro pax_force_fptr ptr
9062+ .endm
9063+ .macro pax_force_retaddr_bts rip=0
9064+ .endm
9065+ .macro pax_set_fptr_mask
9066+ .endm
9067+#endif
9068+
9069 .macro altinstruction_entry orig alt feature orig_len alt_len
9070 .long \orig - .
9071 .long \alt - .
9072diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9073index 7078068..f58bcda 100644
9074--- a/arch/x86/include/asm/alternative.h
9075+++ b/arch/x86/include/asm/alternative.h
9076@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9077 ".section .discard,\"aw\",@progbits\n" \
9078 DISCARD_ENTRY(1) \
9079 ".previous\n" \
9080- ".section .altinstr_replacement, \"ax\"\n" \
9081+ ".section .altinstr_replacement, \"a\"\n" \
9082 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9083 ".previous"
9084
9085@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9086 DISCARD_ENTRY(1) \
9087 DISCARD_ENTRY(2) \
9088 ".previous\n" \
9089- ".section .altinstr_replacement, \"ax\"\n" \
9090+ ".section .altinstr_replacement, \"a\"\n" \
9091 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9092 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9093 ".previous"
9094diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9095index f342612..b3fe911 100644
9096--- a/arch/x86/include/asm/apic.h
9097+++ b/arch/x86/include/asm/apic.h
9098@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9099
9100 #ifdef CONFIG_X86_LOCAL_APIC
9101
9102-extern unsigned int apic_verbosity;
9103+extern int apic_verbosity;
9104 extern int local_apic_timer_c2_ok;
9105
9106 extern int disable_apic;
9107@@ -391,7 +391,7 @@ struct apic {
9108 */
9109 int (*x86_32_numa_cpu_node)(int cpu);
9110 #endif
9111-};
9112+} __do_const;
9113
9114 /*
9115 * Pointer to the local APIC driver in use on this system (there's
9116diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9117index 20370c6..a2eb9b0 100644
9118--- a/arch/x86/include/asm/apm.h
9119+++ b/arch/x86/include/asm/apm.h
9120@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9121 __asm__ __volatile__(APM_DO_ZERO_SEGS
9122 "pushl %%edi\n\t"
9123 "pushl %%ebp\n\t"
9124- "lcall *%%cs:apm_bios_entry\n\t"
9125+ "lcall *%%ss:apm_bios_entry\n\t"
9126 "setc %%al\n\t"
9127 "popl %%ebp\n\t"
9128 "popl %%edi\n\t"
9129@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9130 __asm__ __volatile__(APM_DO_ZERO_SEGS
9131 "pushl %%edi\n\t"
9132 "pushl %%ebp\n\t"
9133- "lcall *%%cs:apm_bios_entry\n\t"
9134+ "lcall *%%ss:apm_bios_entry\n\t"
9135 "setc %%bl\n\t"
9136 "popl %%ebp\n\t"
9137 "popl %%edi\n\t"
9138diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9139index 58cb6d4..a4b806c 100644
9140--- a/arch/x86/include/asm/atomic.h
9141+++ b/arch/x86/include/asm/atomic.h
9142@@ -22,7 +22,18 @@
9143 */
9144 static inline int atomic_read(const atomic_t *v)
9145 {
9146- return (*(volatile int *)&(v)->counter);
9147+ return (*(volatile const int *)&(v)->counter);
9148+}
9149+
9150+/**
9151+ * atomic_read_unchecked - read atomic variable
9152+ * @v: pointer of type atomic_unchecked_t
9153+ *
9154+ * Atomically reads the value of @v.
9155+ */
9156+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9157+{
9158+ return (*(volatile const int *)&(v)->counter);
9159 }
9160
9161 /**
9162@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9163 }
9164
9165 /**
9166+ * atomic_set_unchecked - set atomic variable
9167+ * @v: pointer of type atomic_unchecked_t
9168+ * @i: required value
9169+ *
9170+ * Atomically sets the value of @v to @i.
9171+ */
9172+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9173+{
9174+ v->counter = i;
9175+}
9176+
9177+/**
9178 * atomic_add - add integer to atomic variable
9179 * @i: integer value to add
9180 * @v: pointer of type atomic_t
9181@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9182 */
9183 static inline void atomic_add(int i, atomic_t *v)
9184 {
9185- asm volatile(LOCK_PREFIX "addl %1,%0"
9186+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9187+
9188+#ifdef CONFIG_PAX_REFCOUNT
9189+ "jno 0f\n"
9190+ LOCK_PREFIX "subl %1,%0\n"
9191+ "int $4\n0:\n"
9192+ _ASM_EXTABLE(0b, 0b)
9193+#endif
9194+
9195+ : "+m" (v->counter)
9196+ : "ir" (i));
9197+}
9198+
9199+/**
9200+ * atomic_add_unchecked - add integer to atomic variable
9201+ * @i: integer value to add
9202+ * @v: pointer of type atomic_unchecked_t
9203+ *
9204+ * Atomically adds @i to @v.
9205+ */
9206+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9207+{
9208+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9209 : "+m" (v->counter)
9210 : "ir" (i));
9211 }
9212@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9213 */
9214 static inline void atomic_sub(int i, atomic_t *v)
9215 {
9216- asm volatile(LOCK_PREFIX "subl %1,%0"
9217+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9218+
9219+#ifdef CONFIG_PAX_REFCOUNT
9220+ "jno 0f\n"
9221+ LOCK_PREFIX "addl %1,%0\n"
9222+ "int $4\n0:\n"
9223+ _ASM_EXTABLE(0b, 0b)
9224+#endif
9225+
9226+ : "+m" (v->counter)
9227+ : "ir" (i));
9228+}
9229+
9230+/**
9231+ * atomic_sub_unchecked - subtract integer from atomic variable
9232+ * @i: integer value to subtract
9233+ * @v: pointer of type atomic_unchecked_t
9234+ *
9235+ * Atomically subtracts @i from @v.
9236+ */
9237+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9238+{
9239+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9240 : "+m" (v->counter)
9241 : "ir" (i));
9242 }
9243@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9244 {
9245 unsigned char c;
9246
9247- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9248+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
9249+
9250+#ifdef CONFIG_PAX_REFCOUNT
9251+ "jno 0f\n"
9252+ LOCK_PREFIX "addl %2,%0\n"
9253+ "int $4\n0:\n"
9254+ _ASM_EXTABLE(0b, 0b)
9255+#endif
9256+
9257+ "sete %1\n"
9258 : "+m" (v->counter), "=qm" (c)
9259 : "ir" (i) : "memory");
9260 return c;
9261@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9262 */
9263 static inline void atomic_inc(atomic_t *v)
9264 {
9265- asm volatile(LOCK_PREFIX "incl %0"
9266+ asm volatile(LOCK_PREFIX "incl %0\n"
9267+
9268+#ifdef CONFIG_PAX_REFCOUNT
9269+ "jno 0f\n"
9270+ LOCK_PREFIX "decl %0\n"
9271+ "int $4\n0:\n"
9272+ _ASM_EXTABLE(0b, 0b)
9273+#endif
9274+
9275+ : "+m" (v->counter));
9276+}
9277+
9278+/**
9279+ * atomic_inc_unchecked - increment atomic variable
9280+ * @v: pointer of type atomic_unchecked_t
9281+ *
9282+ * Atomically increments @v by 1.
9283+ */
9284+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9285+{
9286+ asm volatile(LOCK_PREFIX "incl %0\n"
9287 : "+m" (v->counter));
9288 }
9289
9290@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9291 */
9292 static inline void atomic_dec(atomic_t *v)
9293 {
9294- asm volatile(LOCK_PREFIX "decl %0"
9295+ asm volatile(LOCK_PREFIX "decl %0\n"
9296+
9297+#ifdef CONFIG_PAX_REFCOUNT
9298+ "jno 0f\n"
9299+ LOCK_PREFIX "incl %0\n"
9300+ "int $4\n0:\n"
9301+ _ASM_EXTABLE(0b, 0b)
9302+#endif
9303+
9304+ : "+m" (v->counter));
9305+}
9306+
9307+/**
9308+ * atomic_dec_unchecked - decrement atomic variable
9309+ * @v: pointer of type atomic_unchecked_t
9310+ *
9311+ * Atomically decrements @v by 1.
9312+ */
9313+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9314+{
9315+ asm volatile(LOCK_PREFIX "decl %0\n"
9316 : "+m" (v->counter));
9317 }
9318
9319@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9320 {
9321 unsigned char c;
9322
9323- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9324+ asm volatile(LOCK_PREFIX "decl %0\n"
9325+
9326+#ifdef CONFIG_PAX_REFCOUNT
9327+ "jno 0f\n"
9328+ LOCK_PREFIX "incl %0\n"
9329+ "int $4\n0:\n"
9330+ _ASM_EXTABLE(0b, 0b)
9331+#endif
9332+
9333+ "sete %1\n"
9334 : "+m" (v->counter), "=qm" (c)
9335 : : "memory");
9336 return c != 0;
9337@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9338 {
9339 unsigned char c;
9340
9341- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9342+ asm volatile(LOCK_PREFIX "incl %0\n"
9343+
9344+#ifdef CONFIG_PAX_REFCOUNT
9345+ "jno 0f\n"
9346+ LOCK_PREFIX "decl %0\n"
9347+ "int $4\n0:\n"
9348+ _ASM_EXTABLE(0b, 0b)
9349+#endif
9350+
9351+ "sete %1\n"
9352+ : "+m" (v->counter), "=qm" (c)
9353+ : : "memory");
9354+ return c != 0;
9355+}
9356+
9357+/**
9358+ * atomic_inc_and_test_unchecked - increment and test
9359+ * @v: pointer of type atomic_unchecked_t
9360+ *
9361+ * Atomically increments @v by 1
9362+ * and returns true if the result is zero, or false for all
9363+ * other cases.
9364+ */
9365+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9366+{
9367+ unsigned char c;
9368+
9369+ asm volatile(LOCK_PREFIX "incl %0\n"
9370+ "sete %1\n"
9371 : "+m" (v->counter), "=qm" (c)
9372 : : "memory");
9373 return c != 0;
9374@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9375 {
9376 unsigned char c;
9377
9378- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9379+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9380+
9381+#ifdef CONFIG_PAX_REFCOUNT
9382+ "jno 0f\n"
9383+ LOCK_PREFIX "subl %2,%0\n"
9384+ "int $4\n0:\n"
9385+ _ASM_EXTABLE(0b, 0b)
9386+#endif
9387+
9388+ "sets %1\n"
9389 : "+m" (v->counter), "=qm" (c)
9390 : "ir" (i) : "memory");
9391 return c;
9392@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9393 goto no_xadd;
9394 #endif
9395 /* Modern 486+ processor */
9396- return i + xadd(&v->counter, i);
9397+ return i + xadd_check_overflow(&v->counter, i);
9398
9399 #ifdef CONFIG_M386
9400 no_xadd: /* Legacy 386 processor */
9401@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9402 }
9403
9404 /**
9405+ * atomic_add_return_unchecked - add integer and return
9406+ * @i: integer value to add
9407+ * @v: pointer of type atomic_unchecked_t
9408+ *
9409+ * Atomically adds @i to @v and returns @i + @v
9410+ */
9411+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9412+{
9413+#ifdef CONFIG_M386
9414+ int __i;
9415+ unsigned long flags;
9416+ if (unlikely(boot_cpu_data.x86 <= 3))
9417+ goto no_xadd;
9418+#endif
9419+ /* Modern 486+ processor */
9420+ return i + xadd(&v->counter, i);
9421+
9422+#ifdef CONFIG_M386
9423+no_xadd: /* Legacy 386 processor */
9424+ raw_local_irq_save(flags);
9425+ __i = atomic_read_unchecked(v);
9426+ atomic_set_unchecked(v, i + __i);
9427+ raw_local_irq_restore(flags);
9428+ return i + __i;
9429+#endif
9430+}
9431+
9432+/**
9433 * atomic_sub_return - subtract integer and return
9434 * @v: pointer of type atomic_t
9435 * @i: integer value to subtract
9436@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9437 }
9438
9439 #define atomic_inc_return(v) (atomic_add_return(1, v))
9440+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9441+{
9442+ return atomic_add_return_unchecked(1, v);
9443+}
9444 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9445
9446 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9447@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9448 return cmpxchg(&v->counter, old, new);
9449 }
9450
9451+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9452+{
9453+ return cmpxchg(&v->counter, old, new);
9454+}
9455+
9456 static inline int atomic_xchg(atomic_t *v, int new)
9457 {
9458 return xchg(&v->counter, new);
9459 }
9460
9461+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9462+{
9463+ return xchg(&v->counter, new);
9464+}
9465+
9466 /**
9467 * __atomic_add_unless - add unless the number is already a given value
9468 * @v: pointer of type atomic_t
9469@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9470 */
9471 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9472 {
9473- int c, old;
9474+ int c, old, new;
9475 c = atomic_read(v);
9476 for (;;) {
9477- if (unlikely(c == (u)))
9478+ if (unlikely(c == u))
9479 break;
9480- old = atomic_cmpxchg((v), c, c + (a));
9481+
9482+ asm volatile("addl %2,%0\n"
9483+
9484+#ifdef CONFIG_PAX_REFCOUNT
9485+ "jno 0f\n"
9486+ "subl %2,%0\n"
9487+ "int $4\n0:\n"
9488+ _ASM_EXTABLE(0b, 0b)
9489+#endif
9490+
9491+ : "=r" (new)
9492+ : "0" (c), "ir" (a));
9493+
9494+ old = atomic_cmpxchg(v, c, new);
9495 if (likely(old == c))
9496 break;
9497 c = old;
9498@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9499 return c;
9500 }
9501
9502+/**
9503+ * atomic_inc_not_zero_hint - increment if not null
9504+ * @v: pointer of type atomic_t
9505+ * @hint: probable value of the atomic before the increment
9506+ *
9507+ * This version of atomic_inc_not_zero() gives a hint of probable
9508+ * value of the atomic. This helps processor to not read the memory
9509+ * before doing the atomic read/modify/write cycle, lowering
9510+ * number of bus transactions on some arches.
9511+ *
9512+ * Returns: 0 if increment was not done, 1 otherwise.
9513+ */
9514+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9515+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9516+{
9517+ int val, c = hint, new;
9518+
9519+ /* sanity test, should be removed by compiler if hint is a constant */
9520+ if (!hint)
9521+ return __atomic_add_unless(v, 1, 0);
9522+
9523+ do {
9524+ asm volatile("incl %0\n"
9525+
9526+#ifdef CONFIG_PAX_REFCOUNT
9527+ "jno 0f\n"
9528+ "decl %0\n"
9529+ "int $4\n0:\n"
9530+ _ASM_EXTABLE(0b, 0b)
9531+#endif
9532+
9533+ : "=r" (new)
9534+ : "0" (c));
9535+
9536+ val = atomic_cmpxchg(v, c, new);
9537+ if (val == c)
9538+ return 1;
9539+ c = val;
9540+ } while (c);
9541+
9542+ return 0;
9543+}
9544
9545 /*
9546 * atomic_dec_if_positive - decrement by 1 if old value positive
9547@@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9548 #endif
9549
9550 /* These are x86-specific, used by some header files */
9551-#define atomic_clear_mask(mask, addr) \
9552- asm volatile(LOCK_PREFIX "andl %0,%1" \
9553- : : "r" (~(mask)), "m" (*(addr)) : "memory")
9554+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9555+{
9556+ asm volatile(LOCK_PREFIX "andl %1,%0"
9557+ : "+m" (v->counter)
9558+ : "r" (~(mask))
9559+ : "memory");
9560+}
9561
9562-#define atomic_set_mask(mask, addr) \
9563- asm volatile(LOCK_PREFIX "orl %0,%1" \
9564- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9565- : "memory")
9566+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9567+{
9568+ asm volatile(LOCK_PREFIX "andl %1,%0"
9569+ : "+m" (v->counter)
9570+ : "r" (~(mask))
9571+ : "memory");
9572+}
9573+
9574+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9575+{
9576+ asm volatile(LOCK_PREFIX "orl %1,%0"
9577+ : "+m" (v->counter)
9578+ : "r" (mask)
9579+ : "memory");
9580+}
9581+
9582+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9583+{
9584+ asm volatile(LOCK_PREFIX "orl %1,%0"
9585+ : "+m" (v->counter)
9586+ : "r" (mask)
9587+ : "memory");
9588+}
9589
9590 /* Atomic operations are already serializing on x86 */
9591 #define smp_mb__before_atomic_dec() barrier()
9592diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9593index b154de7..aadebd8 100644
9594--- a/arch/x86/include/asm/atomic64_32.h
9595+++ b/arch/x86/include/asm/atomic64_32.h
9596@@ -12,6 +12,14 @@ typedef struct {
9597 u64 __aligned(8) counter;
9598 } atomic64_t;
9599
9600+#ifdef CONFIG_PAX_REFCOUNT
9601+typedef struct {
9602+ u64 __aligned(8) counter;
9603+} atomic64_unchecked_t;
9604+#else
9605+typedef atomic64_t atomic64_unchecked_t;
9606+#endif
9607+
9608 #define ATOMIC64_INIT(val) { (val) }
9609
9610 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9611@@ -37,21 +45,31 @@ typedef struct {
9612 ATOMIC64_DECL_ONE(sym##_386)
9613
9614 ATOMIC64_DECL_ONE(add_386);
9615+ATOMIC64_DECL_ONE(add_unchecked_386);
9616 ATOMIC64_DECL_ONE(sub_386);
9617+ATOMIC64_DECL_ONE(sub_unchecked_386);
9618 ATOMIC64_DECL_ONE(inc_386);
9619+ATOMIC64_DECL_ONE(inc_unchecked_386);
9620 ATOMIC64_DECL_ONE(dec_386);
9621+ATOMIC64_DECL_ONE(dec_unchecked_386);
9622 #endif
9623
9624 #define alternative_atomic64(f, out, in...) \
9625 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9626
9627 ATOMIC64_DECL(read);
9628+ATOMIC64_DECL(read_unchecked);
9629 ATOMIC64_DECL(set);
9630+ATOMIC64_DECL(set_unchecked);
9631 ATOMIC64_DECL(xchg);
9632 ATOMIC64_DECL(add_return);
9633+ATOMIC64_DECL(add_return_unchecked);
9634 ATOMIC64_DECL(sub_return);
9635+ATOMIC64_DECL(sub_return_unchecked);
9636 ATOMIC64_DECL(inc_return);
9637+ATOMIC64_DECL(inc_return_unchecked);
9638 ATOMIC64_DECL(dec_return);
9639+ATOMIC64_DECL(dec_return_unchecked);
9640 ATOMIC64_DECL(dec_if_positive);
9641 ATOMIC64_DECL(inc_not_zero);
9642 ATOMIC64_DECL(add_unless);
9643@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9644 }
9645
9646 /**
9647+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9648+ * @p: pointer to type atomic64_unchecked_t
9649+ * @o: expected value
9650+ * @n: new value
9651+ *
9652+ * Atomically sets @v to @n if it was equal to @o and returns
9653+ * the old value.
9654+ */
9655+
9656+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9657+{
9658+ return cmpxchg64(&v->counter, o, n);
9659+}
9660+
9661+/**
9662 * atomic64_xchg - xchg atomic64 variable
9663 * @v: pointer to type atomic64_t
9664 * @n: value to assign
9665@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9666 }
9667
9668 /**
9669+ * atomic64_set_unchecked - set atomic64 variable
9670+ * @v: pointer to type atomic64_unchecked_t
9671+ * @n: value to assign
9672+ *
9673+ * Atomically sets the value of @v to @n.
9674+ */
9675+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9676+{
9677+ unsigned high = (unsigned)(i >> 32);
9678+ unsigned low = (unsigned)i;
9679+ alternative_atomic64(set, /* no output */,
9680+ "S" (v), "b" (low), "c" (high)
9681+ : "eax", "edx", "memory");
9682+}
9683+
9684+/**
9685 * atomic64_read - read atomic64 variable
9686 * @v: pointer to type atomic64_t
9687 *
9688@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9689 }
9690
9691 /**
9692+ * atomic64_read_unchecked - read atomic64 variable
9693+ * @v: pointer to type atomic64_unchecked_t
9694+ *
9695+ * Atomically reads the value of @v and returns it.
9696+ */
9697+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9698+{
9699+ long long r;
9700+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9701+ return r;
9702+ }
9703+
9704+/**
9705 * atomic64_add_return - add and return
9706 * @i: integer value to add
9707 * @v: pointer to type atomic64_t
9708@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9709 return i;
9710 }
9711
9712+/**
9713+ * atomic64_add_return_unchecked - add and return
9714+ * @i: integer value to add
9715+ * @v: pointer to type atomic64_unchecked_t
9716+ *
9717+ * Atomically adds @i to @v and returns @i + *@v
9718+ */
9719+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9720+{
9721+ alternative_atomic64(add_return_unchecked,
9722+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9723+ ASM_NO_INPUT_CLOBBER("memory"));
9724+ return i;
9725+}
9726+
9727 /*
9728 * Other variants with different arithmetic operators:
9729 */
9730@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9731 return a;
9732 }
9733
9734+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9735+{
9736+ long long a;
9737+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
9738+ "S" (v) : "memory", "ecx");
9739+ return a;
9740+}
9741+
9742 static inline long long atomic64_dec_return(atomic64_t *v)
9743 {
9744 long long a;
9745@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9746 }
9747
9748 /**
9749+ * atomic64_add_unchecked - add integer to atomic64 variable
9750+ * @i: integer value to add
9751+ * @v: pointer to type atomic64_unchecked_t
9752+ *
9753+ * Atomically adds @i to @v.
9754+ */
9755+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9756+{
9757+ __alternative_atomic64(add_unchecked, add_return_unchecked,
9758+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9759+ ASM_NO_INPUT_CLOBBER("memory"));
9760+ return i;
9761+}
9762+
9763+/**
9764 * atomic64_sub - subtract the atomic64 variable
9765 * @i: integer value to subtract
9766 * @v: pointer to type atomic64_t
9767diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9768index 0e1cbfc..5623683 100644
9769--- a/arch/x86/include/asm/atomic64_64.h
9770+++ b/arch/x86/include/asm/atomic64_64.h
9771@@ -18,7 +18,19 @@
9772 */
9773 static inline long atomic64_read(const atomic64_t *v)
9774 {
9775- return (*(volatile long *)&(v)->counter);
9776+ return (*(volatile const long *)&(v)->counter);
9777+}
9778+
9779+/**
9780+ * atomic64_read_unchecked - read atomic64 variable
9781+ * @v: pointer of type atomic64_unchecked_t
9782+ *
9783+ * Atomically reads the value of @v.
9784+ * Doesn't imply a read memory barrier.
9785+ */
9786+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9787+{
9788+ return (*(volatile const long *)&(v)->counter);
9789 }
9790
9791 /**
9792@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9793 }
9794
9795 /**
9796+ * atomic64_set_unchecked - set atomic64 variable
9797+ * @v: pointer to type atomic64_unchecked_t
9798+ * @i: required value
9799+ *
9800+ * Atomically sets the value of @v to @i.
9801+ */
9802+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9803+{
9804+ v->counter = i;
9805+}
9806+
9807+/**
9808 * atomic64_add - add integer to atomic64 variable
9809 * @i: integer value to add
9810 * @v: pointer to type atomic64_t
9811@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9812 */
9813 static inline void atomic64_add(long i, atomic64_t *v)
9814 {
9815+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9816+
9817+#ifdef CONFIG_PAX_REFCOUNT
9818+ "jno 0f\n"
9819+ LOCK_PREFIX "subq %1,%0\n"
9820+ "int $4\n0:\n"
9821+ _ASM_EXTABLE(0b, 0b)
9822+#endif
9823+
9824+ : "=m" (v->counter)
9825+ : "er" (i), "m" (v->counter));
9826+}
9827+
9828+/**
9829+ * atomic64_add_unchecked - add integer to atomic64 variable
9830+ * @i: integer value to add
9831+ * @v: pointer to type atomic64_unchecked_t
9832+ *
9833+ * Atomically adds @i to @v.
9834+ */
9835+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9836+{
9837 asm volatile(LOCK_PREFIX "addq %1,%0"
9838 : "=m" (v->counter)
9839 : "er" (i), "m" (v->counter));
9840@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9841 */
9842 static inline void atomic64_sub(long i, atomic64_t *v)
9843 {
9844- asm volatile(LOCK_PREFIX "subq %1,%0"
9845+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9846+
9847+#ifdef CONFIG_PAX_REFCOUNT
9848+ "jno 0f\n"
9849+ LOCK_PREFIX "addq %1,%0\n"
9850+ "int $4\n0:\n"
9851+ _ASM_EXTABLE(0b, 0b)
9852+#endif
9853+
9854+ : "=m" (v->counter)
9855+ : "er" (i), "m" (v->counter));
9856+}
9857+
9858+/**
9859+ * atomic64_sub_unchecked - subtract the atomic64 variable
9860+ * @i: integer value to subtract
9861+ * @v: pointer to type atomic64_unchecked_t
9862+ *
9863+ * Atomically subtracts @i from @v.
9864+ */
9865+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9866+{
9867+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9868 : "=m" (v->counter)
9869 : "er" (i), "m" (v->counter));
9870 }
9871@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9872 {
9873 unsigned char c;
9874
9875- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9876+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9877+
9878+#ifdef CONFIG_PAX_REFCOUNT
9879+ "jno 0f\n"
9880+ LOCK_PREFIX "addq %2,%0\n"
9881+ "int $4\n0:\n"
9882+ _ASM_EXTABLE(0b, 0b)
9883+#endif
9884+
9885+ "sete %1\n"
9886 : "=m" (v->counter), "=qm" (c)
9887 : "er" (i), "m" (v->counter) : "memory");
9888 return c;
9889@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9890 */
9891 static inline void atomic64_inc(atomic64_t *v)
9892 {
9893+ asm volatile(LOCK_PREFIX "incq %0\n"
9894+
9895+#ifdef CONFIG_PAX_REFCOUNT
9896+ "jno 0f\n"
9897+ LOCK_PREFIX "decq %0\n"
9898+ "int $4\n0:\n"
9899+ _ASM_EXTABLE(0b, 0b)
9900+#endif
9901+
9902+ : "=m" (v->counter)
9903+ : "m" (v->counter));
9904+}
9905+
9906+/**
9907+ * atomic64_inc_unchecked - increment atomic64 variable
9908+ * @v: pointer to type atomic64_unchecked_t
9909+ *
9910+ * Atomically increments @v by 1.
9911+ */
9912+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9913+{
9914 asm volatile(LOCK_PREFIX "incq %0"
9915 : "=m" (v->counter)
9916 : "m" (v->counter));
9917@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9918 */
9919 static inline void atomic64_dec(atomic64_t *v)
9920 {
9921- asm volatile(LOCK_PREFIX "decq %0"
9922+ asm volatile(LOCK_PREFIX "decq %0\n"
9923+
9924+#ifdef CONFIG_PAX_REFCOUNT
9925+ "jno 0f\n"
9926+ LOCK_PREFIX "incq %0\n"
9927+ "int $4\n0:\n"
9928+ _ASM_EXTABLE(0b, 0b)
9929+#endif
9930+
9931+ : "=m" (v->counter)
9932+ : "m" (v->counter));
9933+}
9934+
9935+/**
9936+ * atomic64_dec_unchecked - decrement atomic64 variable
9937+ * @v: pointer to type atomic64_t
9938+ *
9939+ * Atomically decrements @v by 1.
9940+ */
9941+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9942+{
9943+ asm volatile(LOCK_PREFIX "decq %0\n"
9944 : "=m" (v->counter)
9945 : "m" (v->counter));
9946 }
9947@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9948 {
9949 unsigned char c;
9950
9951- asm volatile(LOCK_PREFIX "decq %0; sete %1"
9952+ asm volatile(LOCK_PREFIX "decq %0\n"
9953+
9954+#ifdef CONFIG_PAX_REFCOUNT
9955+ "jno 0f\n"
9956+ LOCK_PREFIX "incq %0\n"
9957+ "int $4\n0:\n"
9958+ _ASM_EXTABLE(0b, 0b)
9959+#endif
9960+
9961+ "sete %1\n"
9962 : "=m" (v->counter), "=qm" (c)
9963 : "m" (v->counter) : "memory");
9964 return c != 0;
9965@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9966 {
9967 unsigned char c;
9968
9969- asm volatile(LOCK_PREFIX "incq %0; sete %1"
9970+ asm volatile(LOCK_PREFIX "incq %0\n"
9971+
9972+#ifdef CONFIG_PAX_REFCOUNT
9973+ "jno 0f\n"
9974+ LOCK_PREFIX "decq %0\n"
9975+ "int $4\n0:\n"
9976+ _ASM_EXTABLE(0b, 0b)
9977+#endif
9978+
9979+ "sete %1\n"
9980 : "=m" (v->counter), "=qm" (c)
9981 : "m" (v->counter) : "memory");
9982 return c != 0;
9983@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9984 {
9985 unsigned char c;
9986
9987- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9988+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
9989+
9990+#ifdef CONFIG_PAX_REFCOUNT
9991+ "jno 0f\n"
9992+ LOCK_PREFIX "subq %2,%0\n"
9993+ "int $4\n0:\n"
9994+ _ASM_EXTABLE(0b, 0b)
9995+#endif
9996+
9997+ "sets %1\n"
9998 : "=m" (v->counter), "=qm" (c)
9999 : "er" (i), "m" (v->counter) : "memory");
10000 return c;
10001@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10002 */
10003 static inline long atomic64_add_return(long i, atomic64_t *v)
10004 {
10005+ return i + xadd_check_overflow(&v->counter, i);
10006+}
10007+
10008+/**
10009+ * atomic64_add_return_unchecked - add and return
10010+ * @i: integer value to add
10011+ * @v: pointer to type atomic64_unchecked_t
10012+ *
10013+ * Atomically adds @i to @v and returns @i + @v
10014+ */
10015+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10016+{
10017 return i + xadd(&v->counter, i);
10018 }
10019
10020@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10021 }
10022
10023 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10024+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10025+{
10026+ return atomic64_add_return_unchecked(1, v);
10027+}
10028 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10029
10030 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10031@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10032 return cmpxchg(&v->counter, old, new);
10033 }
10034
10035+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10036+{
10037+ return cmpxchg(&v->counter, old, new);
10038+}
10039+
10040 static inline long atomic64_xchg(atomic64_t *v, long new)
10041 {
10042 return xchg(&v->counter, new);
10043@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10044 */
10045 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10046 {
10047- long c, old;
10048+ long c, old, new;
10049 c = atomic64_read(v);
10050 for (;;) {
10051- if (unlikely(c == (u)))
10052+ if (unlikely(c == u))
10053 break;
10054- old = atomic64_cmpxchg((v), c, c + (a));
10055+
10056+ asm volatile("add %2,%0\n"
10057+
10058+#ifdef CONFIG_PAX_REFCOUNT
10059+ "jno 0f\n"
10060+ "sub %2,%0\n"
10061+ "int $4\n0:\n"
10062+ _ASM_EXTABLE(0b, 0b)
10063+#endif
10064+
10065+ : "=r" (new)
10066+ : "0" (c), "ir" (a));
10067+
10068+ old = atomic64_cmpxchg(v, c, new);
10069 if (likely(old == c))
10070 break;
10071 c = old;
10072 }
10073- return c != (u);
10074+ return c != u;
10075 }
10076
10077 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10078diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10079index 72f5009..2f8b9a9 100644
10080--- a/arch/x86/include/asm/bitops.h
10081+++ b/arch/x86/include/asm/bitops.h
10082@@ -40,7 +40,7 @@
10083 * a mask operation on a byte.
10084 */
10085 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10086-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10087+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10088 #define CONST_MASK(nr) (1 << ((nr) & 7))
10089
10090 /**
10091diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10092index b13fe63..0dab13a 100644
10093--- a/arch/x86/include/asm/boot.h
10094+++ b/arch/x86/include/asm/boot.h
10095@@ -11,10 +11,15 @@
10096 #include <asm/pgtable_types.h>
10097
10098 /* Physical address where kernel should be loaded. */
10099-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10100+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10101 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10102 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10103
10104+#ifndef __ASSEMBLY__
10105+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10106+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10107+#endif
10108+
10109 /* Minimum kernel alignment, as a power of two */
10110 #ifdef CONFIG_X86_64
10111 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10112diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10113index 48f99f1..d78ebf9 100644
10114--- a/arch/x86/include/asm/cache.h
10115+++ b/arch/x86/include/asm/cache.h
10116@@ -5,12 +5,13 @@
10117
10118 /* L1 cache line size */
10119 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10120-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10121+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10122
10123 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10124+#define __read_only __attribute__((__section__(".data..read_only")))
10125
10126 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10127-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10128+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10129
10130 #ifdef CONFIG_X86_VSMP
10131 #ifdef CONFIG_SMP
10132diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10133index 9863ee3..4a1f8e1 100644
10134--- a/arch/x86/include/asm/cacheflush.h
10135+++ b/arch/x86/include/asm/cacheflush.h
10136@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10137 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10138
10139 if (pg_flags == _PGMT_DEFAULT)
10140- return -1;
10141+ return ~0UL;
10142 else if (pg_flags == _PGMT_WC)
10143 return _PAGE_CACHE_WC;
10144 else if (pg_flags == _PGMT_UC_MINUS)
10145diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10146index 46fc474..b02b0f9 100644
10147--- a/arch/x86/include/asm/checksum_32.h
10148+++ b/arch/x86/include/asm/checksum_32.h
10149@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10150 int len, __wsum sum,
10151 int *src_err_ptr, int *dst_err_ptr);
10152
10153+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10154+ int len, __wsum sum,
10155+ int *src_err_ptr, int *dst_err_ptr);
10156+
10157+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10158+ int len, __wsum sum,
10159+ int *src_err_ptr, int *dst_err_ptr);
10160+
10161 /*
10162 * Note: when you get a NULL pointer exception here this means someone
10163 * passed in an incorrect kernel address to one of these functions.
10164@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10165 int *err_ptr)
10166 {
10167 might_sleep();
10168- return csum_partial_copy_generic((__force void *)src, dst,
10169+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
10170 len, sum, err_ptr, NULL);
10171 }
10172
10173@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10174 {
10175 might_sleep();
10176 if (access_ok(VERIFY_WRITE, dst, len))
10177- return csum_partial_copy_generic(src, (__force void *)dst,
10178+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10179 len, sum, NULL, err_ptr);
10180
10181 if (len)
10182diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10183index 99480e5..d81165b 100644
10184--- a/arch/x86/include/asm/cmpxchg.h
10185+++ b/arch/x86/include/asm/cmpxchg.h
10186@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10187 __compiletime_error("Bad argument size for cmpxchg");
10188 extern void __xadd_wrong_size(void)
10189 __compiletime_error("Bad argument size for xadd");
10190+extern void __xadd_check_overflow_wrong_size(void)
10191+ __compiletime_error("Bad argument size for xadd_check_overflow");
10192 extern void __add_wrong_size(void)
10193 __compiletime_error("Bad argument size for add");
10194+extern void __add_check_overflow_wrong_size(void)
10195+ __compiletime_error("Bad argument size for add_check_overflow");
10196
10197 /*
10198 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10199@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10200 __ret; \
10201 })
10202
10203+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10204+ ({ \
10205+ __typeof__ (*(ptr)) __ret = (arg); \
10206+ switch (sizeof(*(ptr))) { \
10207+ case __X86_CASE_L: \
10208+ asm volatile (lock #op "l %0, %1\n" \
10209+ "jno 0f\n" \
10210+ "mov %0,%1\n" \
10211+ "int $4\n0:\n" \
10212+ _ASM_EXTABLE(0b, 0b) \
10213+ : "+r" (__ret), "+m" (*(ptr)) \
10214+ : : "memory", "cc"); \
10215+ break; \
10216+ case __X86_CASE_Q: \
10217+ asm volatile (lock #op "q %q0, %1\n" \
10218+ "jno 0f\n" \
10219+ "mov %0,%1\n" \
10220+ "int $4\n0:\n" \
10221+ _ASM_EXTABLE(0b, 0b) \
10222+ : "+r" (__ret), "+m" (*(ptr)) \
10223+ : : "memory", "cc"); \
10224+ break; \
10225+ default: \
10226+ __ ## op ## _check_overflow_wrong_size(); \
10227+ } \
10228+ __ret; \
10229+ })
10230+
10231 /*
10232 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10233 * Since this is generally used to protect other memory information, we
10234@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10235 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10236 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10237
10238+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10239+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10240+
10241 #define __add(ptr, inc, lock) \
10242 ({ \
10243 __typeof__ (*(ptr)) __ret = (inc); \
10244diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10245index 6b7ee5f..9d664b3 100644
10246--- a/arch/x86/include/asm/cpufeature.h
10247+++ b/arch/x86/include/asm/cpufeature.h
10248@@ -202,13 +202,14 @@
10249 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10250 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10251 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10252-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10253+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10254 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10255 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10256 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10257 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10258 #define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
10259 #define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
10260+#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10261
10262 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10263
10264@@ -373,7 +374,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10265 ".section .discard,\"aw\",@progbits\n"
10266 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10267 ".previous\n"
10268- ".section .altinstr_replacement,\"ax\"\n"
10269+ ".section .altinstr_replacement,\"a\"\n"
10270 "3: movb $1,%0\n"
10271 "4:\n"
10272 ".previous\n"
10273diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10274index 8bf1c06..f723dfd 100644
10275--- a/arch/x86/include/asm/desc.h
10276+++ b/arch/x86/include/asm/desc.h
10277@@ -4,6 +4,7 @@
10278 #include <asm/desc_defs.h>
10279 #include <asm/ldt.h>
10280 #include <asm/mmu.h>
10281+#include <asm/pgtable.h>
10282
10283 #include <linux/smp.h>
10284 #include <linux/percpu.h>
10285@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10286
10287 desc->type = (info->read_exec_only ^ 1) << 1;
10288 desc->type |= info->contents << 2;
10289+ desc->type |= info->seg_not_present ^ 1;
10290
10291 desc->s = 1;
10292 desc->dpl = 0x3;
10293@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10294 }
10295
10296 extern struct desc_ptr idt_descr;
10297-extern gate_desc idt_table[];
10298 extern struct desc_ptr nmi_idt_descr;
10299-extern gate_desc nmi_idt_table[];
10300-
10301-struct gdt_page {
10302- struct desc_struct gdt[GDT_ENTRIES];
10303-} __attribute__((aligned(PAGE_SIZE)));
10304-
10305-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10306+extern gate_desc idt_table[256];
10307+extern gate_desc nmi_idt_table[256];
10308
10309+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10310 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10311 {
10312- return per_cpu(gdt_page, cpu).gdt;
10313+ return cpu_gdt_table[cpu];
10314 }
10315
10316 #ifdef CONFIG_X86_64
10317@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10318 unsigned long base, unsigned dpl, unsigned flags,
10319 unsigned short seg)
10320 {
10321- gate->a = (seg << 16) | (base & 0xffff);
10322- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10323+ gate->gate.offset_low = base;
10324+ gate->gate.seg = seg;
10325+ gate->gate.reserved = 0;
10326+ gate->gate.type = type;
10327+ gate->gate.s = 0;
10328+ gate->gate.dpl = dpl;
10329+ gate->gate.p = 1;
10330+ gate->gate.offset_high = base >> 16;
10331 }
10332
10333 #endif
10334@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10335
10336 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10337 {
10338+ pax_open_kernel();
10339 memcpy(&idt[entry], gate, sizeof(*gate));
10340+ pax_close_kernel();
10341 }
10342
10343 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10344 {
10345+ pax_open_kernel();
10346 memcpy(&ldt[entry], desc, 8);
10347+ pax_close_kernel();
10348 }
10349
10350 static inline void
10351@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10352 default: size = sizeof(*gdt); break;
10353 }
10354
10355+ pax_open_kernel();
10356 memcpy(&gdt[entry], desc, size);
10357+ pax_close_kernel();
10358 }
10359
10360 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10361@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10362
10363 static inline void native_load_tr_desc(void)
10364 {
10365+ pax_open_kernel();
10366 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10367+ pax_close_kernel();
10368 }
10369
10370 static inline void native_load_gdt(const struct desc_ptr *dtr)
10371@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10372 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10373 unsigned int i;
10374
10375+ pax_open_kernel();
10376 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10377 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10378+ pax_close_kernel();
10379 }
10380
10381 #define _LDT_empty(info) \
10382@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10383 }
10384
10385 #ifdef CONFIG_X86_64
10386-static inline void set_nmi_gate(int gate, void *addr)
10387+static inline void set_nmi_gate(int gate, const void *addr)
10388 {
10389 gate_desc s;
10390
10391@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10392 }
10393 #endif
10394
10395-static inline void _set_gate(int gate, unsigned type, void *addr,
10396+static inline void _set_gate(int gate, unsigned type, const void *addr,
10397 unsigned dpl, unsigned ist, unsigned seg)
10398 {
10399 gate_desc s;
10400@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10401 * Pentium F0 0F bugfix can have resulted in the mapped
10402 * IDT being write-protected.
10403 */
10404-static inline void set_intr_gate(unsigned int n, void *addr)
10405+static inline void set_intr_gate(unsigned int n, const void *addr)
10406 {
10407 BUG_ON((unsigned)n > 0xFF);
10408 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10409@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10410 /*
10411 * This routine sets up an interrupt gate at directory privilege level 3.
10412 */
10413-static inline void set_system_intr_gate(unsigned int n, void *addr)
10414+static inline void set_system_intr_gate(unsigned int n, const void *addr)
10415 {
10416 BUG_ON((unsigned)n > 0xFF);
10417 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10418 }
10419
10420-static inline void set_system_trap_gate(unsigned int n, void *addr)
10421+static inline void set_system_trap_gate(unsigned int n, const void *addr)
10422 {
10423 BUG_ON((unsigned)n > 0xFF);
10424 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10425 }
10426
10427-static inline void set_trap_gate(unsigned int n, void *addr)
10428+static inline void set_trap_gate(unsigned int n, const void *addr)
10429 {
10430 BUG_ON((unsigned)n > 0xFF);
10431 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10432@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10433 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10434 {
10435 BUG_ON((unsigned)n > 0xFF);
10436- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10437+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10438 }
10439
10440-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10441+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10442 {
10443 BUG_ON((unsigned)n > 0xFF);
10444 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10445 }
10446
10447-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10448+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10449 {
10450 BUG_ON((unsigned)n > 0xFF);
10451 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10452 }
10453
10454+#ifdef CONFIG_X86_32
10455+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10456+{
10457+ struct desc_struct d;
10458+
10459+ if (likely(limit))
10460+ limit = (limit - 1UL) >> PAGE_SHIFT;
10461+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
10462+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10463+}
10464+#endif
10465+
10466 #endif /* _ASM_X86_DESC_H */
10467diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10468index 278441f..b95a174 100644
10469--- a/arch/x86/include/asm/desc_defs.h
10470+++ b/arch/x86/include/asm/desc_defs.h
10471@@ -31,6 +31,12 @@ struct desc_struct {
10472 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10473 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10474 };
10475+ struct {
10476+ u16 offset_low;
10477+ u16 seg;
10478+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10479+ unsigned offset_high: 16;
10480+ } gate;
10481 };
10482 } __attribute__((packed));
10483
10484diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10485index 3778256..c5d4fce 100644
10486--- a/arch/x86/include/asm/e820.h
10487+++ b/arch/x86/include/asm/e820.h
10488@@ -69,7 +69,7 @@ struct e820map {
10489 #define ISA_START_ADDRESS 0xa0000
10490 #define ISA_END_ADDRESS 0x100000
10491
10492-#define BIOS_BEGIN 0x000a0000
10493+#define BIOS_BEGIN 0x000c0000
10494 #define BIOS_END 0x00100000
10495
10496 #define BIOS_ROM_BASE 0xffe00000
10497diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10498index 5939f44..f8845f6 100644
10499--- a/arch/x86/include/asm/elf.h
10500+++ b/arch/x86/include/asm/elf.h
10501@@ -243,7 +243,25 @@ extern int force_personality32;
10502 the loader. We need to make sure that it is out of the way of the program
10503 that it will "exec", and that there is sufficient room for the brk. */
10504
10505+#ifdef CONFIG_PAX_SEGMEXEC
10506+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10507+#else
10508 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10509+#endif
10510+
10511+#ifdef CONFIG_PAX_ASLR
10512+#ifdef CONFIG_X86_32
10513+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10514+
10515+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10516+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10517+#else
10518+#define PAX_ELF_ET_DYN_BASE 0x400000UL
10519+
10520+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10521+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10522+#endif
10523+#endif
10524
10525 /* This yields a mask that user programs can use to figure out what
10526 instruction set this CPU supports. This could be done in user space,
10527@@ -296,16 +314,12 @@ do { \
10528
10529 #define ARCH_DLINFO \
10530 do { \
10531- if (vdso_enabled) \
10532- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10533- (unsigned long)current->mm->context.vdso); \
10534+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10535 } while (0)
10536
10537 #define ARCH_DLINFO_X32 \
10538 do { \
10539- if (vdso_enabled) \
10540- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10541- (unsigned long)current->mm->context.vdso); \
10542+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10543 } while (0)
10544
10545 #define AT_SYSINFO 32
10546@@ -320,7 +334,7 @@ else \
10547
10548 #endif /* !CONFIG_X86_32 */
10549
10550-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10551+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10552
10553 #define VDSO_ENTRY \
10554 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10555@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10556 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10557 #define compat_arch_setup_additional_pages syscall32_setup_pages
10558
10559-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10560-#define arch_randomize_brk arch_randomize_brk
10561-
10562 /*
10563 * True on X86_32 or when emulating IA32 on X86_64
10564 */
10565diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10566index 75ce3f4..882e801 100644
10567--- a/arch/x86/include/asm/emergency-restart.h
10568+++ b/arch/x86/include/asm/emergency-restart.h
10569@@ -13,6 +13,6 @@ enum reboot_type {
10570
10571 extern enum reboot_type reboot_type;
10572
10573-extern void machine_emergency_restart(void);
10574+extern void machine_emergency_restart(void) __noreturn;
10575
10576 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10577diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10578index 75f4c6d..ee3eb8f 100644
10579--- a/arch/x86/include/asm/fpu-internal.h
10580+++ b/arch/x86/include/asm/fpu-internal.h
10581@@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10582 {
10583 int err;
10584
10585+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10586+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10587+ fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10588+#endif
10589+
10590 /* See comment in fxsave() below. */
10591 #ifdef CONFIG_AS_FXSAVEQ
10592 asm volatile("1: fxrstorq %[fx]\n\t"
10593@@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10594 {
10595 int err;
10596
10597+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10598+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10599+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10600+#endif
10601+
10602 /*
10603 * Clear the bytes not touched by the fxsave and reserved
10604 * for the SW usage.
10605@@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10606 "emms\n\t" /* clear stack tags */
10607 "fildl %P[addr]", /* set F?P to defined value */
10608 X86_FEATURE_FXSAVE_LEAK,
10609- [addr] "m" (tsk->thread.fpu.has_fpu));
10610+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10611
10612 return fpu_restore_checking(&tsk->thread.fpu);
10613 }
10614diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10615index 71ecbcb..bac10b7 100644
10616--- a/arch/x86/include/asm/futex.h
10617+++ b/arch/x86/include/asm/futex.h
10618@@ -11,16 +11,18 @@
10619 #include <asm/processor.h>
10620
10621 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10622+ typecheck(u32 __user *, uaddr); \
10623 asm volatile("1:\t" insn "\n" \
10624 "2:\t.section .fixup,\"ax\"\n" \
10625 "3:\tmov\t%3, %1\n" \
10626 "\tjmp\t2b\n" \
10627 "\t.previous\n" \
10628 _ASM_EXTABLE(1b, 3b) \
10629- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10630+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10631 : "i" (-EFAULT), "0" (oparg), "1" (0))
10632
10633 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10634+ typecheck(u32 __user *, uaddr); \
10635 asm volatile("1:\tmovl %2, %0\n" \
10636 "\tmovl\t%0, %3\n" \
10637 "\t" insn "\n" \
10638@@ -33,7 +35,7 @@
10639 _ASM_EXTABLE(1b, 4b) \
10640 _ASM_EXTABLE(2b, 4b) \
10641 : "=&a" (oldval), "=&r" (ret), \
10642- "+m" (*uaddr), "=&r" (tem) \
10643+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10644 : "r" (oparg), "i" (-EFAULT), "1" (0))
10645
10646 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10647@@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10648
10649 switch (op) {
10650 case FUTEX_OP_SET:
10651- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10652+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10653 break;
10654 case FUTEX_OP_ADD:
10655- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10656+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10657 uaddr, oparg);
10658 break;
10659 case FUTEX_OP_OR:
10660@@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10661 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10662 return -EFAULT;
10663
10664- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10665+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10666 "2:\t.section .fixup, \"ax\"\n"
10667 "3:\tmov %3, %0\n"
10668 "\tjmp 2b\n"
10669 "\t.previous\n"
10670 _ASM_EXTABLE(1b, 3b)
10671- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10672+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10673 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10674 : "memory"
10675 );
10676diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10677index eb92a6e..b98b2f4 100644
10678--- a/arch/x86/include/asm/hw_irq.h
10679+++ b/arch/x86/include/asm/hw_irq.h
10680@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10681 extern void enable_IO_APIC(void);
10682
10683 /* Statistics */
10684-extern atomic_t irq_err_count;
10685-extern atomic_t irq_mis_count;
10686+extern atomic_unchecked_t irq_err_count;
10687+extern atomic_unchecked_t irq_mis_count;
10688
10689 /* EISA */
10690 extern void eisa_set_level_irq(unsigned int irq);
10691diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10692index d8e8eef..99f81ae 100644
10693--- a/arch/x86/include/asm/io.h
10694+++ b/arch/x86/include/asm/io.h
10695@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10696
10697 #include <linux/vmalloc.h>
10698
10699+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10700+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10701+{
10702+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10703+}
10704+
10705+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10706+{
10707+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10708+}
10709+
10710 /*
10711 * Convert a virtual cached pointer to an uncached pointer
10712 */
10713diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10714index bba3cf8..06bc8da 100644
10715--- a/arch/x86/include/asm/irqflags.h
10716+++ b/arch/x86/include/asm/irqflags.h
10717@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10718 sti; \
10719 sysexit
10720
10721+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10722+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10723+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10724+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10725+
10726 #else
10727 #define INTERRUPT_RETURN iret
10728 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10729diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10730index 5478825..839e88c 100644
10731--- a/arch/x86/include/asm/kprobes.h
10732+++ b/arch/x86/include/asm/kprobes.h
10733@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10734 #define RELATIVEJUMP_SIZE 5
10735 #define RELATIVECALL_OPCODE 0xe8
10736 #define RELATIVE_ADDR_SIZE 4
10737-#define MAX_STACK_SIZE 64
10738-#define MIN_STACK_SIZE(ADDR) \
10739- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10740- THREAD_SIZE - (unsigned long)(ADDR))) \
10741- ? (MAX_STACK_SIZE) \
10742- : (((unsigned long)current_thread_info()) + \
10743- THREAD_SIZE - (unsigned long)(ADDR)))
10744+#define MAX_STACK_SIZE 64UL
10745+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10746
10747 #define flush_insn_slot(p) do { } while (0)
10748
10749diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10750index 09155d6..d2e6df9 100644
10751--- a/arch/x86/include/asm/kvm_host.h
10752+++ b/arch/x86/include/asm/kvm_host.h
10753@@ -694,7 +694,7 @@ struct kvm_x86_ops {
10754 int (*check_intercept)(struct kvm_vcpu *vcpu,
10755 struct x86_instruction_info *info,
10756 enum x86_intercept_stage stage);
10757-};
10758+} __do_const;
10759
10760 struct kvm_arch_async_pf {
10761 u32 token;
10762diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10763index c8bed0d..e5721fa 100644
10764--- a/arch/x86/include/asm/local.h
10765+++ b/arch/x86/include/asm/local.h
10766@@ -17,26 +17,58 @@ typedef struct {
10767
10768 static inline void local_inc(local_t *l)
10769 {
10770- asm volatile(_ASM_INC "%0"
10771+ asm volatile(_ASM_INC "%0\n"
10772+
10773+#ifdef CONFIG_PAX_REFCOUNT
10774+ "jno 0f\n"
10775+ _ASM_DEC "%0\n"
10776+ "int $4\n0:\n"
10777+ _ASM_EXTABLE(0b, 0b)
10778+#endif
10779+
10780 : "+m" (l->a.counter));
10781 }
10782
10783 static inline void local_dec(local_t *l)
10784 {
10785- asm volatile(_ASM_DEC "%0"
10786+ asm volatile(_ASM_DEC "%0\n"
10787+
10788+#ifdef CONFIG_PAX_REFCOUNT
10789+ "jno 0f\n"
10790+ _ASM_INC "%0\n"
10791+ "int $4\n0:\n"
10792+ _ASM_EXTABLE(0b, 0b)
10793+#endif
10794+
10795 : "+m" (l->a.counter));
10796 }
10797
10798 static inline void local_add(long i, local_t *l)
10799 {
10800- asm volatile(_ASM_ADD "%1,%0"
10801+ asm volatile(_ASM_ADD "%1,%0\n"
10802+
10803+#ifdef CONFIG_PAX_REFCOUNT
10804+ "jno 0f\n"
10805+ _ASM_SUB "%1,%0\n"
10806+ "int $4\n0:\n"
10807+ _ASM_EXTABLE(0b, 0b)
10808+#endif
10809+
10810 : "+m" (l->a.counter)
10811 : "ir" (i));
10812 }
10813
10814 static inline void local_sub(long i, local_t *l)
10815 {
10816- asm volatile(_ASM_SUB "%1,%0"
10817+ asm volatile(_ASM_SUB "%1,%0\n"
10818+
10819+#ifdef CONFIG_PAX_REFCOUNT
10820+ "jno 0f\n"
10821+ _ASM_ADD "%1,%0\n"
10822+ "int $4\n0:\n"
10823+ _ASM_EXTABLE(0b, 0b)
10824+#endif
10825+
10826 : "+m" (l->a.counter)
10827 : "ir" (i));
10828 }
10829@@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10830 {
10831 unsigned char c;
10832
10833- asm volatile(_ASM_SUB "%2,%0; sete %1"
10834+ asm volatile(_ASM_SUB "%2,%0\n"
10835+
10836+#ifdef CONFIG_PAX_REFCOUNT
10837+ "jno 0f\n"
10838+ _ASM_ADD "%2,%0\n"
10839+ "int $4\n0:\n"
10840+ _ASM_EXTABLE(0b, 0b)
10841+#endif
10842+
10843+ "sete %1\n"
10844 : "+m" (l->a.counter), "=qm" (c)
10845 : "ir" (i) : "memory");
10846 return c;
10847@@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10848 {
10849 unsigned char c;
10850
10851- asm volatile(_ASM_DEC "%0; sete %1"
10852+ asm volatile(_ASM_DEC "%0\n"
10853+
10854+#ifdef CONFIG_PAX_REFCOUNT
10855+ "jno 0f\n"
10856+ _ASM_INC "%0\n"
10857+ "int $4\n0:\n"
10858+ _ASM_EXTABLE(0b, 0b)
10859+#endif
10860+
10861+ "sete %1\n"
10862 : "+m" (l->a.counter), "=qm" (c)
10863 : : "memory");
10864 return c != 0;
10865@@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10866 {
10867 unsigned char c;
10868
10869- asm volatile(_ASM_INC "%0; sete %1"
10870+ asm volatile(_ASM_INC "%0\n"
10871+
10872+#ifdef CONFIG_PAX_REFCOUNT
10873+ "jno 0f\n"
10874+ _ASM_DEC "%0\n"
10875+ "int $4\n0:\n"
10876+ _ASM_EXTABLE(0b, 0b)
10877+#endif
10878+
10879+ "sete %1\n"
10880 : "+m" (l->a.counter), "=qm" (c)
10881 : : "memory");
10882 return c != 0;
10883@@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10884 {
10885 unsigned char c;
10886
10887- asm volatile(_ASM_ADD "%2,%0; sets %1"
10888+ asm volatile(_ASM_ADD "%2,%0\n"
10889+
10890+#ifdef CONFIG_PAX_REFCOUNT
10891+ "jno 0f\n"
10892+ _ASM_SUB "%2,%0\n"
10893+ "int $4\n0:\n"
10894+ _ASM_EXTABLE(0b, 0b)
10895+#endif
10896+
10897+ "sets %1\n"
10898 : "+m" (l->a.counter), "=qm" (c)
10899 : "ir" (i) : "memory");
10900 return c;
10901@@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10902 #endif
10903 /* Modern 486+ processor */
10904 __i = i;
10905- asm volatile(_ASM_XADD "%0, %1;"
10906+ asm volatile(_ASM_XADD "%0, %1\n"
10907+
10908+#ifdef CONFIG_PAX_REFCOUNT
10909+ "jno 0f\n"
10910+ _ASM_MOV "%0,%1\n"
10911+ "int $4\n0:\n"
10912+ _ASM_EXTABLE(0b, 0b)
10913+#endif
10914+
10915 : "+r" (i), "+m" (l->a.counter)
10916 : : "memory");
10917 return i + __i;
10918diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10919index 593e51d..fa69c9a 100644
10920--- a/arch/x86/include/asm/mman.h
10921+++ b/arch/x86/include/asm/mman.h
10922@@ -5,4 +5,14 @@
10923
10924 #include <asm-generic/mman.h>
10925
10926+#ifdef __KERNEL__
10927+#ifndef __ASSEMBLY__
10928+#ifdef CONFIG_X86_32
10929+#define arch_mmap_check i386_mmap_check
10930+int i386_mmap_check(unsigned long addr, unsigned long len,
10931+ unsigned long flags);
10932+#endif
10933+#endif
10934+#endif
10935+
10936 #endif /* _ASM_X86_MMAN_H */
10937diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10938index 5f55e69..e20bfb1 100644
10939--- a/arch/x86/include/asm/mmu.h
10940+++ b/arch/x86/include/asm/mmu.h
10941@@ -9,7 +9,7 @@
10942 * we put the segment information here.
10943 */
10944 typedef struct {
10945- void *ldt;
10946+ struct desc_struct *ldt;
10947 int size;
10948
10949 #ifdef CONFIG_X86_64
10950@@ -18,7 +18,19 @@ typedef struct {
10951 #endif
10952
10953 struct mutex lock;
10954- void *vdso;
10955+ unsigned long vdso;
10956+
10957+#ifdef CONFIG_X86_32
10958+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10959+ unsigned long user_cs_base;
10960+ unsigned long user_cs_limit;
10961+
10962+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10963+ cpumask_t cpu_user_cs_mask;
10964+#endif
10965+
10966+#endif
10967+#endif
10968 } mm_context_t;
10969
10970 #ifdef CONFIG_SMP
10971diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10972index cdbf367..adb37ac 100644
10973--- a/arch/x86/include/asm/mmu_context.h
10974+++ b/arch/x86/include/asm/mmu_context.h
10975@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10976
10977 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10978 {
10979+
10980+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10981+ unsigned int i;
10982+ pgd_t *pgd;
10983+
10984+ pax_open_kernel();
10985+ pgd = get_cpu_pgd(smp_processor_id());
10986+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10987+ set_pgd_batched(pgd+i, native_make_pgd(0));
10988+ pax_close_kernel();
10989+#endif
10990+
10991 #ifdef CONFIG_SMP
10992 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10993 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10994@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10995 struct task_struct *tsk)
10996 {
10997 unsigned cpu = smp_processor_id();
10998+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10999+ int tlbstate = TLBSTATE_OK;
11000+#endif
11001
11002 if (likely(prev != next)) {
11003 #ifdef CONFIG_SMP
11004+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11005+ tlbstate = this_cpu_read(cpu_tlbstate.state);
11006+#endif
11007 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11008 this_cpu_write(cpu_tlbstate.active_mm, next);
11009 #endif
11010 cpumask_set_cpu(cpu, mm_cpumask(next));
11011
11012 /* Re-load page tables */
11013+#ifdef CONFIG_PAX_PER_CPU_PGD
11014+ pax_open_kernel();
11015+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11016+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11017+ pax_close_kernel();
11018+ load_cr3(get_cpu_pgd(cpu));
11019+#else
11020 load_cr3(next->pgd);
11021+#endif
11022
11023 /* stop flush ipis for the previous mm */
11024 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11025@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11026 */
11027 if (unlikely(prev->context.ldt != next->context.ldt))
11028 load_LDT_nolock(&next->context);
11029- }
11030+
11031+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11032+ if (!(__supported_pte_mask & _PAGE_NX)) {
11033+ smp_mb__before_clear_bit();
11034+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11035+ smp_mb__after_clear_bit();
11036+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11037+ }
11038+#endif
11039+
11040+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11041+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11042+ prev->context.user_cs_limit != next->context.user_cs_limit))
11043+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11044 #ifdef CONFIG_SMP
11045+ else if (unlikely(tlbstate != TLBSTATE_OK))
11046+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11047+#endif
11048+#endif
11049+
11050+ }
11051 else {
11052+
11053+#ifdef CONFIG_PAX_PER_CPU_PGD
11054+ pax_open_kernel();
11055+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11056+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11057+ pax_close_kernel();
11058+ load_cr3(get_cpu_pgd(cpu));
11059+#endif
11060+
11061+#ifdef CONFIG_SMP
11062 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11063 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11064
11065@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11066 * tlb flush IPI delivery. We must reload CR3
11067 * to make sure to use no freed page tables.
11068 */
11069+
11070+#ifndef CONFIG_PAX_PER_CPU_PGD
11071 load_cr3(next->pgd);
11072+#endif
11073+
11074 load_LDT_nolock(&next->context);
11075+
11076+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11077+ if (!(__supported_pte_mask & _PAGE_NX))
11078+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11079+#endif
11080+
11081+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11082+#ifdef CONFIG_PAX_PAGEEXEC
11083+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11084+#endif
11085+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11086+#endif
11087+
11088 }
11089+#endif
11090 }
11091-#endif
11092 }
11093
11094 #define activate_mm(prev, next) \
11095diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11096index 9eae775..c914fea 100644
11097--- a/arch/x86/include/asm/module.h
11098+++ b/arch/x86/include/asm/module.h
11099@@ -5,6 +5,7 @@
11100
11101 #ifdef CONFIG_X86_64
11102 /* X86_64 does not define MODULE_PROC_FAMILY */
11103+#define MODULE_PROC_FAMILY ""
11104 #elif defined CONFIG_M386
11105 #define MODULE_PROC_FAMILY "386 "
11106 #elif defined CONFIG_M486
11107@@ -59,8 +60,20 @@
11108 #error unknown processor family
11109 #endif
11110
11111-#ifdef CONFIG_X86_32
11112-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11113+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11114+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11115+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11116+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11117+#else
11118+#define MODULE_PAX_KERNEXEC ""
11119 #endif
11120
11121+#ifdef CONFIG_PAX_MEMORY_UDEREF
11122+#define MODULE_PAX_UDEREF "UDEREF "
11123+#else
11124+#define MODULE_PAX_UDEREF ""
11125+#endif
11126+
11127+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11128+
11129 #endif /* _ASM_X86_MODULE_H */
11130diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11131index 320f7bb..e89f8f8 100644
11132--- a/arch/x86/include/asm/page_64_types.h
11133+++ b/arch/x86/include/asm/page_64_types.h
11134@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11135
11136 /* duplicated to the one in bootmem.h */
11137 extern unsigned long max_pfn;
11138-extern unsigned long phys_base;
11139+extern const unsigned long phys_base;
11140
11141 extern unsigned long __phys_addr(unsigned long);
11142 #define __phys_reloc_hide(x) (x)
11143diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11144index a0facf3..c017b15 100644
11145--- a/arch/x86/include/asm/paravirt.h
11146+++ b/arch/x86/include/asm/paravirt.h
11147@@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11148 val);
11149 }
11150
11151+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11152+{
11153+ pgdval_t val = native_pgd_val(pgd);
11154+
11155+ if (sizeof(pgdval_t) > sizeof(long))
11156+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11157+ val, (u64)val >> 32);
11158+ else
11159+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11160+ val);
11161+}
11162+
11163 static inline void pgd_clear(pgd_t *pgdp)
11164 {
11165 set_pgd(pgdp, __pgd(0));
11166@@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11167 pv_mmu_ops.set_fixmap(idx, phys, flags);
11168 }
11169
11170+#ifdef CONFIG_PAX_KERNEXEC
11171+static inline unsigned long pax_open_kernel(void)
11172+{
11173+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11174+}
11175+
11176+static inline unsigned long pax_close_kernel(void)
11177+{
11178+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11179+}
11180+#else
11181+static inline unsigned long pax_open_kernel(void) { return 0; }
11182+static inline unsigned long pax_close_kernel(void) { return 0; }
11183+#endif
11184+
11185 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11186
11187 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11188@@ -929,7 +956,7 @@ extern void default_banner(void);
11189
11190 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11191 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11192-#define PARA_INDIRECT(addr) *%cs:addr
11193+#define PARA_INDIRECT(addr) *%ss:addr
11194 #endif
11195
11196 #define INTERRUPT_RETURN \
11197@@ -1004,6 +1031,21 @@ extern void default_banner(void);
11198 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11199 CLBR_NONE, \
11200 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11201+
11202+#define GET_CR0_INTO_RDI \
11203+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11204+ mov %rax,%rdi
11205+
11206+#define SET_RDI_INTO_CR0 \
11207+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11208+
11209+#define GET_CR3_INTO_RDI \
11210+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11211+ mov %rax,%rdi
11212+
11213+#define SET_RDI_INTO_CR3 \
11214+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11215+
11216 #endif /* CONFIG_X86_32 */
11217
11218 #endif /* __ASSEMBLY__ */
11219diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11220index 142236e..6a6b4a6 100644
11221--- a/arch/x86/include/asm/paravirt_types.h
11222+++ b/arch/x86/include/asm/paravirt_types.h
11223@@ -84,20 +84,20 @@ struct pv_init_ops {
11224 */
11225 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11226 unsigned long addr, unsigned len);
11227-};
11228+} __no_const;
11229
11230
11231 struct pv_lazy_ops {
11232 /* Set deferred update mode, used for batching operations. */
11233 void (*enter)(void);
11234 void (*leave)(void);
11235-};
11236+} __no_const;
11237
11238 struct pv_time_ops {
11239 unsigned long long (*sched_clock)(void);
11240 unsigned long long (*steal_clock)(int cpu);
11241 unsigned long (*get_tsc_khz)(void);
11242-};
11243+} __no_const;
11244
11245 struct pv_cpu_ops {
11246 /* hooks for various privileged instructions */
11247@@ -191,7 +191,7 @@ struct pv_cpu_ops {
11248
11249 void (*start_context_switch)(struct task_struct *prev);
11250 void (*end_context_switch)(struct task_struct *next);
11251-};
11252+} __no_const;
11253
11254 struct pv_irq_ops {
11255 /*
11256@@ -222,7 +222,7 @@ struct pv_apic_ops {
11257 unsigned long start_eip,
11258 unsigned long start_esp);
11259 #endif
11260-};
11261+} __no_const;
11262
11263 struct pv_mmu_ops {
11264 unsigned long (*read_cr2)(void);
11265@@ -312,6 +312,7 @@ struct pv_mmu_ops {
11266 struct paravirt_callee_save make_pud;
11267
11268 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11269+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11270 #endif /* PAGETABLE_LEVELS == 4 */
11271 #endif /* PAGETABLE_LEVELS >= 3 */
11272
11273@@ -323,6 +324,12 @@ struct pv_mmu_ops {
11274 an mfn. We can tell which is which from the index. */
11275 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11276 phys_addr_t phys, pgprot_t flags);
11277+
11278+#ifdef CONFIG_PAX_KERNEXEC
11279+ unsigned long (*pax_open_kernel)(void);
11280+ unsigned long (*pax_close_kernel)(void);
11281+#endif
11282+
11283 };
11284
11285 struct arch_spinlock;
11286@@ -333,7 +340,7 @@ struct pv_lock_ops {
11287 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11288 int (*spin_trylock)(struct arch_spinlock *lock);
11289 void (*spin_unlock)(struct arch_spinlock *lock);
11290-};
11291+} __no_const;
11292
11293 /* This contains all the paravirt structures: we get a convenient
11294 * number for each function using the offset which we use to indicate
11295diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11296index b4389a4..7024269 100644
11297--- a/arch/x86/include/asm/pgalloc.h
11298+++ b/arch/x86/include/asm/pgalloc.h
11299@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11300 pmd_t *pmd, pte_t *pte)
11301 {
11302 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11303+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11304+}
11305+
11306+static inline void pmd_populate_user(struct mm_struct *mm,
11307+ pmd_t *pmd, pte_t *pte)
11308+{
11309+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11310 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11311 }
11312
11313@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11314
11315 #ifdef CONFIG_X86_PAE
11316 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11317+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11318+{
11319+ pud_populate(mm, pudp, pmd);
11320+}
11321 #else /* !CONFIG_X86_PAE */
11322 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11323 {
11324 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11325 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11326 }
11327+
11328+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11329+{
11330+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11331+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11332+}
11333 #endif /* CONFIG_X86_PAE */
11334
11335 #if PAGETABLE_LEVELS > 3
11336@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11337 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11338 }
11339
11340+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11341+{
11342+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11343+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11344+}
11345+
11346 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11347 {
11348 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11349diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11350index f2b489c..4f7e2e5 100644
11351--- a/arch/x86/include/asm/pgtable-2level.h
11352+++ b/arch/x86/include/asm/pgtable-2level.h
11353@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11354
11355 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11356 {
11357+ pax_open_kernel();
11358 *pmdp = pmd;
11359+ pax_close_kernel();
11360 }
11361
11362 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11363diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11364index 4cc9f2b..5fd9226 100644
11365--- a/arch/x86/include/asm/pgtable-3level.h
11366+++ b/arch/x86/include/asm/pgtable-3level.h
11367@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11368
11369 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11370 {
11371+ pax_open_kernel();
11372 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11373+ pax_close_kernel();
11374 }
11375
11376 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11377 {
11378+ pax_open_kernel();
11379 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11380+ pax_close_kernel();
11381 }
11382
11383 /*
11384diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11385index 49afb3f..91a8c63 100644
11386--- a/arch/x86/include/asm/pgtable.h
11387+++ b/arch/x86/include/asm/pgtable.h
11388@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11389
11390 #ifndef __PAGETABLE_PUD_FOLDED
11391 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11392+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11393 #define pgd_clear(pgd) native_pgd_clear(pgd)
11394 #endif
11395
11396@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11397
11398 #define arch_end_context_switch(prev) do {} while(0)
11399
11400+#define pax_open_kernel() native_pax_open_kernel()
11401+#define pax_close_kernel() native_pax_close_kernel()
11402 #endif /* CONFIG_PARAVIRT */
11403
11404+#define __HAVE_ARCH_PAX_OPEN_KERNEL
11405+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11406+
11407+#ifdef CONFIG_PAX_KERNEXEC
11408+static inline unsigned long native_pax_open_kernel(void)
11409+{
11410+ unsigned long cr0;
11411+
11412+ preempt_disable();
11413+ barrier();
11414+ cr0 = read_cr0() ^ X86_CR0_WP;
11415+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11416+ write_cr0(cr0);
11417+ return cr0 ^ X86_CR0_WP;
11418+}
11419+
11420+static inline unsigned long native_pax_close_kernel(void)
11421+{
11422+ unsigned long cr0;
11423+
11424+ cr0 = read_cr0() ^ X86_CR0_WP;
11425+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11426+ write_cr0(cr0);
11427+ barrier();
11428+ preempt_enable_no_resched();
11429+ return cr0 ^ X86_CR0_WP;
11430+}
11431+#else
11432+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11433+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11434+#endif
11435+
11436 /*
11437 * The following only work if pte_present() is true.
11438 * Undefined behaviour if not..
11439 */
11440+static inline int pte_user(pte_t pte)
11441+{
11442+ return pte_val(pte) & _PAGE_USER;
11443+}
11444+
11445 static inline int pte_dirty(pte_t pte)
11446 {
11447 return pte_flags(pte) & _PAGE_DIRTY;
11448@@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11449 return pte_clear_flags(pte, _PAGE_RW);
11450 }
11451
11452+static inline pte_t pte_mkread(pte_t pte)
11453+{
11454+ return __pte(pte_val(pte) | _PAGE_USER);
11455+}
11456+
11457 static inline pte_t pte_mkexec(pte_t pte)
11458 {
11459- return pte_clear_flags(pte, _PAGE_NX);
11460+#ifdef CONFIG_X86_PAE
11461+ if (__supported_pte_mask & _PAGE_NX)
11462+ return pte_clear_flags(pte, _PAGE_NX);
11463+ else
11464+#endif
11465+ return pte_set_flags(pte, _PAGE_USER);
11466+}
11467+
11468+static inline pte_t pte_exprotect(pte_t pte)
11469+{
11470+#ifdef CONFIG_X86_PAE
11471+ if (__supported_pte_mask & _PAGE_NX)
11472+ return pte_set_flags(pte, _PAGE_NX);
11473+ else
11474+#endif
11475+ return pte_clear_flags(pte, _PAGE_USER);
11476 }
11477
11478 static inline pte_t pte_mkdirty(pte_t pte)
11479@@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11480 #endif
11481
11482 #ifndef __ASSEMBLY__
11483+
11484+#ifdef CONFIG_PAX_PER_CPU_PGD
11485+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11486+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11487+{
11488+ return cpu_pgd[cpu];
11489+}
11490+#endif
11491+
11492 #include <linux/mm_types.h>
11493
11494 static inline int pte_none(pte_t pte)
11495@@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11496
11497 static inline int pgd_bad(pgd_t pgd)
11498 {
11499- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11500+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11501 }
11502
11503 static inline int pgd_none(pgd_t pgd)
11504@@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11505 * pgd_offset() returns a (pgd_t *)
11506 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11507 */
11508-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11509+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11510+
11511+#ifdef CONFIG_PAX_PER_CPU_PGD
11512+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11513+#endif
11514+
11515 /*
11516 * a shortcut which implies the use of the kernel's pgd, instead
11517 * of a process's
11518@@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11519 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11520 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11521
11522+#ifdef CONFIG_X86_32
11523+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11524+#else
11525+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11526+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11527+
11528+#ifdef CONFIG_PAX_MEMORY_UDEREF
11529+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11530+#else
11531+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11532+#endif
11533+
11534+#endif
11535+
11536 #ifndef __ASSEMBLY__
11537
11538 extern int direct_gbpages;
11539@@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11540 * dst and src can be on the same page, but the range must not overlap,
11541 * and must not cross a page boundary.
11542 */
11543-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11544+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11545 {
11546- memcpy(dst, src, count * sizeof(pgd_t));
11547+ pax_open_kernel();
11548+ while (count--)
11549+ *dst++ = *src++;
11550+ pax_close_kernel();
11551 }
11552
11553+#ifdef CONFIG_PAX_PER_CPU_PGD
11554+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11555+#endif
11556+
11557+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11558+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11559+#else
11560+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11561+#endif
11562
11563 #include <asm-generic/pgtable.h>
11564 #endif /* __ASSEMBLY__ */
11565diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11566index 0c92113..34a77c6 100644
11567--- a/arch/x86/include/asm/pgtable_32.h
11568+++ b/arch/x86/include/asm/pgtable_32.h
11569@@ -25,9 +25,6 @@
11570 struct mm_struct;
11571 struct vm_area_struct;
11572
11573-extern pgd_t swapper_pg_dir[1024];
11574-extern pgd_t initial_page_table[1024];
11575-
11576 static inline void pgtable_cache_init(void) { }
11577 static inline void check_pgt_cache(void) { }
11578 void paging_init(void);
11579@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11580 # include <asm/pgtable-2level.h>
11581 #endif
11582
11583+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11584+extern pgd_t initial_page_table[PTRS_PER_PGD];
11585+#ifdef CONFIG_X86_PAE
11586+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11587+#endif
11588+
11589 #if defined(CONFIG_HIGHPTE)
11590 #define pte_offset_map(dir, address) \
11591 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11592@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11593 /* Clear a kernel PTE and flush it from the TLB */
11594 #define kpte_clear_flush(ptep, vaddr) \
11595 do { \
11596+ pax_open_kernel(); \
11597 pte_clear(&init_mm, (vaddr), (ptep)); \
11598+ pax_close_kernel(); \
11599 __flush_tlb_one((vaddr)); \
11600 } while (0)
11601
11602@@ -74,6 +79,9 @@ do { \
11603
11604 #endif /* !__ASSEMBLY__ */
11605
11606+#define HAVE_ARCH_UNMAPPED_AREA
11607+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11608+
11609 /*
11610 * kern_addr_valid() is (1) for FLATMEM and (0) for
11611 * SPARSEMEM and DISCONTIGMEM
11612diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11613index ed5903b..c7fe163 100644
11614--- a/arch/x86/include/asm/pgtable_32_types.h
11615+++ b/arch/x86/include/asm/pgtable_32_types.h
11616@@ -8,7 +8,7 @@
11617 */
11618 #ifdef CONFIG_X86_PAE
11619 # include <asm/pgtable-3level_types.h>
11620-# define PMD_SIZE (1UL << PMD_SHIFT)
11621+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11622 # define PMD_MASK (~(PMD_SIZE - 1))
11623 #else
11624 # include <asm/pgtable-2level_types.h>
11625@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11626 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11627 #endif
11628
11629+#ifdef CONFIG_PAX_KERNEXEC
11630+#ifndef __ASSEMBLY__
11631+extern unsigned char MODULES_EXEC_VADDR[];
11632+extern unsigned char MODULES_EXEC_END[];
11633+#endif
11634+#include <asm/boot.h>
11635+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11636+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11637+#else
11638+#define ktla_ktva(addr) (addr)
11639+#define ktva_ktla(addr) (addr)
11640+#endif
11641+
11642 #define MODULES_VADDR VMALLOC_START
11643 #define MODULES_END VMALLOC_END
11644 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11645diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11646index 8251be0..4ea8b46 100644
11647--- a/arch/x86/include/asm/pgtable_64.h
11648+++ b/arch/x86/include/asm/pgtable_64.h
11649@@ -16,10 +16,14 @@
11650
11651 extern pud_t level3_kernel_pgt[512];
11652 extern pud_t level3_ident_pgt[512];
11653+extern pud_t level3_vmalloc_start_pgt[512];
11654+extern pud_t level3_vmalloc_end_pgt[512];
11655+extern pud_t level3_vmemmap_pgt[512];
11656+extern pud_t level2_vmemmap_pgt[512];
11657 extern pmd_t level2_kernel_pgt[512];
11658 extern pmd_t level2_fixmap_pgt[512];
11659-extern pmd_t level2_ident_pgt[512];
11660-extern pgd_t init_level4_pgt[];
11661+extern pmd_t level2_ident_pgt[512*2];
11662+extern pgd_t init_level4_pgt[512];
11663
11664 #define swapper_pg_dir init_level4_pgt
11665
11666@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11667
11668 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11669 {
11670+ pax_open_kernel();
11671 *pmdp = pmd;
11672+ pax_close_kernel();
11673 }
11674
11675 static inline void native_pmd_clear(pmd_t *pmd)
11676@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11677
11678 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11679 {
11680+ pax_open_kernel();
11681 *pudp = pud;
11682+ pax_close_kernel();
11683 }
11684
11685 static inline void native_pud_clear(pud_t *pud)
11686@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11687
11688 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11689 {
11690+ pax_open_kernel();
11691+ *pgdp = pgd;
11692+ pax_close_kernel();
11693+}
11694+
11695+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11696+{
11697 *pgdp = pgd;
11698 }
11699
11700diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11701index 766ea16..5b96cb3 100644
11702--- a/arch/x86/include/asm/pgtable_64_types.h
11703+++ b/arch/x86/include/asm/pgtable_64_types.h
11704@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11705 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11706 #define MODULES_END _AC(0xffffffffff000000, UL)
11707 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11708+#define MODULES_EXEC_VADDR MODULES_VADDR
11709+#define MODULES_EXEC_END MODULES_END
11710+
11711+#define ktla_ktva(addr) (addr)
11712+#define ktva_ktla(addr) (addr)
11713
11714 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11715diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11716index 013286a..8b42f4f 100644
11717--- a/arch/x86/include/asm/pgtable_types.h
11718+++ b/arch/x86/include/asm/pgtable_types.h
11719@@ -16,13 +16,12 @@
11720 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11721 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11722 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11723-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11724+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11725 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11726 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11727 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11728-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11729-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11730-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11731+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11732+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11733 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11734
11735 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11736@@ -40,7 +39,6 @@
11737 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11738 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11739 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11740-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11741 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11742 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11743 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11744@@ -57,8 +55,10 @@
11745
11746 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11747 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11748-#else
11749+#elif defined(CONFIG_KMEMCHECK)
11750 #define _PAGE_NX (_AT(pteval_t, 0))
11751+#else
11752+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11753 #endif
11754
11755 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11756@@ -96,6 +96,9 @@
11757 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11758 _PAGE_ACCESSED)
11759
11760+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11761+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11762+
11763 #define __PAGE_KERNEL_EXEC \
11764 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11765 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11766@@ -106,7 +109,7 @@
11767 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11768 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11769 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11770-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11771+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11772 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11773 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11774 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11775@@ -168,8 +171,8 @@
11776 * bits are combined, this will alow user to access the high address mapped
11777 * VDSO in the presence of CONFIG_COMPAT_VDSO
11778 */
11779-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11780-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11781+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11782+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11783 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11784 #endif
11785
11786@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11787 {
11788 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11789 }
11790+#endif
11791
11792+#if PAGETABLE_LEVELS == 3
11793+#include <asm-generic/pgtable-nopud.h>
11794+#endif
11795+
11796+#if PAGETABLE_LEVELS == 2
11797+#include <asm-generic/pgtable-nopmd.h>
11798+#endif
11799+
11800+#ifndef __ASSEMBLY__
11801 #if PAGETABLE_LEVELS > 3
11802 typedef struct { pudval_t pud; } pud_t;
11803
11804@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11805 return pud.pud;
11806 }
11807 #else
11808-#include <asm-generic/pgtable-nopud.h>
11809-
11810 static inline pudval_t native_pud_val(pud_t pud)
11811 {
11812 return native_pgd_val(pud.pgd);
11813@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11814 return pmd.pmd;
11815 }
11816 #else
11817-#include <asm-generic/pgtable-nopmd.h>
11818-
11819 static inline pmdval_t native_pmd_val(pmd_t pmd)
11820 {
11821 return native_pgd_val(pmd.pud.pgd);
11822@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11823
11824 extern pteval_t __supported_pte_mask;
11825 extern void set_nx(void);
11826-extern int nx_enabled;
11827
11828 #define pgprot_writecombine pgprot_writecombine
11829 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11830diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11831index aea1d1d..680cf09 100644
11832--- a/arch/x86/include/asm/processor-flags.h
11833+++ b/arch/x86/include/asm/processor-flags.h
11834@@ -65,6 +65,7 @@
11835 #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
11836 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11837 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11838+#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11839
11840 /*
11841 * x86-64 Task Priority Register, CR8
11842diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11843index d048cad..45e350f 100644
11844--- a/arch/x86/include/asm/processor.h
11845+++ b/arch/x86/include/asm/processor.h
11846@@ -289,7 +289,7 @@ struct tss_struct {
11847
11848 } ____cacheline_aligned;
11849
11850-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11851+extern struct tss_struct init_tss[NR_CPUS];
11852
11853 /*
11854 * Save the original ist values for checking stack pointers during debugging
11855@@ -822,11 +822,18 @@ static inline void spin_lock_prefetch(const void *x)
11856 */
11857 #define TASK_SIZE PAGE_OFFSET
11858 #define TASK_SIZE_MAX TASK_SIZE
11859+
11860+#ifdef CONFIG_PAX_SEGMEXEC
11861+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11862+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11863+#else
11864 #define STACK_TOP TASK_SIZE
11865-#define STACK_TOP_MAX STACK_TOP
11866+#endif
11867+
11868+#define STACK_TOP_MAX TASK_SIZE
11869
11870 #define INIT_THREAD { \
11871- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11872+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11873 .vm86_info = NULL, \
11874 .sysenter_cs = __KERNEL_CS, \
11875 .io_bitmap_ptr = NULL, \
11876@@ -840,7 +847,7 @@ static inline void spin_lock_prefetch(const void *x)
11877 */
11878 #define INIT_TSS { \
11879 .x86_tss = { \
11880- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11881+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11882 .ss0 = __KERNEL_DS, \
11883 .ss1 = __KERNEL_CS, \
11884 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11885@@ -851,11 +858,7 @@ static inline void spin_lock_prefetch(const void *x)
11886 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11887
11888 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11889-#define KSTK_TOP(info) \
11890-({ \
11891- unsigned long *__ptr = (unsigned long *)(info); \
11892- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11893-})
11894+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11895
11896 /*
11897 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11898@@ -870,7 +873,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11899 #define task_pt_regs(task) \
11900 ({ \
11901 struct pt_regs *__regs__; \
11902- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11903+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11904 __regs__ - 1; \
11905 })
11906
11907@@ -880,13 +883,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11908 /*
11909 * User space process size. 47bits minus one guard page.
11910 */
11911-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11912+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11913
11914 /* This decides where the kernel will search for a free chunk of vm
11915 * space during mmap's.
11916 */
11917 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11918- 0xc0000000 : 0xFFFFe000)
11919+ 0xc0000000 : 0xFFFFf000)
11920
11921 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11922 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11923@@ -897,11 +900,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11924 #define STACK_TOP_MAX TASK_SIZE_MAX
11925
11926 #define INIT_THREAD { \
11927- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11928+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11929 }
11930
11931 #define INIT_TSS { \
11932- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11933+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11934 }
11935
11936 /*
11937@@ -929,6 +932,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11938 */
11939 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11940
11941+#ifdef CONFIG_PAX_SEGMEXEC
11942+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11943+#endif
11944+
11945 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11946
11947 /* Get/set a process' ability to use the timestamp counter instruction */
11948@@ -989,12 +996,12 @@ extern bool cpu_has_amd_erratum(const int *);
11949 #define cpu_has_amd_erratum(x) (false)
11950 #endif /* CONFIG_CPU_SUP_AMD */
11951
11952-extern unsigned long arch_align_stack(unsigned long sp);
11953+#define arch_align_stack(x) ((x) & ~0xfUL)
11954 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11955
11956 void default_idle(void);
11957 bool set_pm_idle_to_default(void);
11958
11959-void stop_this_cpu(void *dummy);
11960+void stop_this_cpu(void *dummy) __noreturn;
11961
11962 #endif /* _ASM_X86_PROCESSOR_H */
11963diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11964index dcfde52..dbfea06 100644
11965--- a/arch/x86/include/asm/ptrace.h
11966+++ b/arch/x86/include/asm/ptrace.h
11967@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11968 }
11969
11970 /*
11971- * user_mode_vm(regs) determines whether a register set came from user mode.
11972+ * user_mode(regs) determines whether a register set came from user mode.
11973 * This is true if V8086 mode was enabled OR if the register set was from
11974 * protected mode with RPL-3 CS value. This tricky test checks that with
11975 * one comparison. Many places in the kernel can bypass this full check
11976- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11977+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11978+ * be used.
11979 */
11980-static inline int user_mode(struct pt_regs *regs)
11981+static inline int user_mode_novm(struct pt_regs *regs)
11982 {
11983 #ifdef CONFIG_X86_32
11984 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11985 #else
11986- return !!(regs->cs & 3);
11987+ return !!(regs->cs & SEGMENT_RPL_MASK);
11988 #endif
11989 }
11990
11991-static inline int user_mode_vm(struct pt_regs *regs)
11992+static inline int user_mode(struct pt_regs *regs)
11993 {
11994 #ifdef CONFIG_X86_32
11995 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11996 USER_RPL;
11997 #else
11998- return user_mode(regs);
11999+ return user_mode_novm(regs);
12000 #endif
12001 }
12002
12003@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12004 #ifdef CONFIG_X86_64
12005 static inline bool user_64bit_mode(struct pt_regs *regs)
12006 {
12007+ unsigned long cs = regs->cs & 0xffff;
12008 #ifndef CONFIG_PARAVIRT
12009 /*
12010 * On non-paravirt systems, this is the only long mode CPL 3
12011 * selector. We do not allow long mode selectors in the LDT.
12012 */
12013- return regs->cs == __USER_CS;
12014+ return cs == __USER_CS;
12015 #else
12016 /* Headers are too twisted for this to go in paravirt.h. */
12017- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12018+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12019 #endif
12020 }
12021 #endif
12022diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12023index fe1ec5b..dc5c3fe 100644
12024--- a/arch/x86/include/asm/realmode.h
12025+++ b/arch/x86/include/asm/realmode.h
12026@@ -22,16 +22,14 @@ struct real_mode_header {
12027 #endif
12028 /* APM/BIOS reboot */
12029 u32 machine_real_restart_asm;
12030-#ifdef CONFIG_X86_64
12031 u32 machine_real_restart_seg;
12032-#endif
12033 };
12034
12035 /* This must match data at trampoline_32/64.S */
12036 struct trampoline_header {
12037 #ifdef CONFIG_X86_32
12038 u32 start;
12039- u16 gdt_pad;
12040+ u16 boot_cs;
12041 u16 gdt_limit;
12042 u32 gdt_base;
12043 #else
12044diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12045index a82c4f1..ac45053 100644
12046--- a/arch/x86/include/asm/reboot.h
12047+++ b/arch/x86/include/asm/reboot.h
12048@@ -6,13 +6,13 @@
12049 struct pt_regs;
12050
12051 struct machine_ops {
12052- void (*restart)(char *cmd);
12053- void (*halt)(void);
12054- void (*power_off)(void);
12055+ void (* __noreturn restart)(char *cmd);
12056+ void (* __noreturn halt)(void);
12057+ void (* __noreturn power_off)(void);
12058 void (*shutdown)(void);
12059 void (*crash_shutdown)(struct pt_regs *);
12060- void (*emergency_restart)(void);
12061-};
12062+ void (* __noreturn emergency_restart)(void);
12063+} __no_const;
12064
12065 extern struct machine_ops machine_ops;
12066
12067diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12068index 2dbe4a7..ce1db00 100644
12069--- a/arch/x86/include/asm/rwsem.h
12070+++ b/arch/x86/include/asm/rwsem.h
12071@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12072 {
12073 asm volatile("# beginning down_read\n\t"
12074 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12075+
12076+#ifdef CONFIG_PAX_REFCOUNT
12077+ "jno 0f\n"
12078+ LOCK_PREFIX _ASM_DEC "(%1)\n"
12079+ "int $4\n0:\n"
12080+ _ASM_EXTABLE(0b, 0b)
12081+#endif
12082+
12083 /* adds 0x00000001 */
12084 " jns 1f\n"
12085 " call call_rwsem_down_read_failed\n"
12086@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12087 "1:\n\t"
12088 " mov %1,%2\n\t"
12089 " add %3,%2\n\t"
12090+
12091+#ifdef CONFIG_PAX_REFCOUNT
12092+ "jno 0f\n"
12093+ "sub %3,%2\n"
12094+ "int $4\n0:\n"
12095+ _ASM_EXTABLE(0b, 0b)
12096+#endif
12097+
12098 " jle 2f\n\t"
12099 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12100 " jnz 1b\n\t"
12101@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12102 long tmp;
12103 asm volatile("# beginning down_write\n\t"
12104 LOCK_PREFIX " xadd %1,(%2)\n\t"
12105+
12106+#ifdef CONFIG_PAX_REFCOUNT
12107+ "jno 0f\n"
12108+ "mov %1,(%2)\n"
12109+ "int $4\n0:\n"
12110+ _ASM_EXTABLE(0b, 0b)
12111+#endif
12112+
12113 /* adds 0xffff0001, returns the old value */
12114 " test %1,%1\n\t"
12115 /* was the count 0 before? */
12116@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12117 long tmp;
12118 asm volatile("# beginning __up_read\n\t"
12119 LOCK_PREFIX " xadd %1,(%2)\n\t"
12120+
12121+#ifdef CONFIG_PAX_REFCOUNT
12122+ "jno 0f\n"
12123+ "mov %1,(%2)\n"
12124+ "int $4\n0:\n"
12125+ _ASM_EXTABLE(0b, 0b)
12126+#endif
12127+
12128 /* subtracts 1, returns the old value */
12129 " jns 1f\n\t"
12130 " call call_rwsem_wake\n" /* expects old value in %edx */
12131@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12132 long tmp;
12133 asm volatile("# beginning __up_write\n\t"
12134 LOCK_PREFIX " xadd %1,(%2)\n\t"
12135+
12136+#ifdef CONFIG_PAX_REFCOUNT
12137+ "jno 0f\n"
12138+ "mov %1,(%2)\n"
12139+ "int $4\n0:\n"
12140+ _ASM_EXTABLE(0b, 0b)
12141+#endif
12142+
12143 /* subtracts 0xffff0001, returns the old value */
12144 " jns 1f\n\t"
12145 " call call_rwsem_wake\n" /* expects old value in %edx */
12146@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12147 {
12148 asm volatile("# beginning __downgrade_write\n\t"
12149 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12150+
12151+#ifdef CONFIG_PAX_REFCOUNT
12152+ "jno 0f\n"
12153+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12154+ "int $4\n0:\n"
12155+ _ASM_EXTABLE(0b, 0b)
12156+#endif
12157+
12158 /*
12159 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12160 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12161@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12162 */
12163 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12164 {
12165- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12166+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12167+
12168+#ifdef CONFIG_PAX_REFCOUNT
12169+ "jno 0f\n"
12170+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
12171+ "int $4\n0:\n"
12172+ _ASM_EXTABLE(0b, 0b)
12173+#endif
12174+
12175 : "+m" (sem->count)
12176 : "er" (delta));
12177 }
12178@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12179 */
12180 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12181 {
12182- return delta + xadd(&sem->count, delta);
12183+ return delta + xadd_check_overflow(&sem->count, delta);
12184 }
12185
12186 #endif /* __KERNEL__ */
12187diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12188index c48a950..c6d7468 100644
12189--- a/arch/x86/include/asm/segment.h
12190+++ b/arch/x86/include/asm/segment.h
12191@@ -64,10 +64,15 @@
12192 * 26 - ESPFIX small SS
12193 * 27 - per-cpu [ offset to per-cpu data area ]
12194 * 28 - stack_canary-20 [ for stack protector ]
12195- * 29 - unused
12196- * 30 - unused
12197+ * 29 - PCI BIOS CS
12198+ * 30 - PCI BIOS DS
12199 * 31 - TSS for double fault handler
12200 */
12201+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12202+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12203+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12204+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12205+
12206 #define GDT_ENTRY_TLS_MIN 6
12207 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12208
12209@@ -79,6 +84,8 @@
12210
12211 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12212
12213+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12214+
12215 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12216
12217 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12218@@ -104,6 +111,12 @@
12219 #define __KERNEL_STACK_CANARY 0
12220 #endif
12221
12222+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12223+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12224+
12225+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12226+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12227+
12228 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12229
12230 /*
12231@@ -141,7 +154,7 @@
12232 */
12233
12234 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12235-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12236+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12237
12238
12239 #else
12240@@ -165,6 +178,8 @@
12241 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12242 #define __USER32_DS __USER_DS
12243
12244+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12245+
12246 #define GDT_ENTRY_TSS 8 /* needs two entries */
12247 #define GDT_ENTRY_LDT 10 /* needs two entries */
12248 #define GDT_ENTRY_TLS_MIN 12
12249@@ -185,6 +200,7 @@
12250 #endif
12251
12252 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12253+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12254 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12255 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12256 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12257@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12258 {
12259 unsigned long __limit;
12260 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12261- return __limit + 1;
12262+ return __limit;
12263 }
12264
12265 #endif /* !__ASSEMBLY__ */
12266diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12267index 4f19a15..9e14f27 100644
12268--- a/arch/x86/include/asm/smp.h
12269+++ b/arch/x86/include/asm/smp.h
12270@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12271 /* cpus sharing the last level cache: */
12272 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12273 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12274-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12275+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12276
12277 static inline struct cpumask *cpu_sibling_mask(int cpu)
12278 {
12279@@ -79,7 +79,7 @@ struct smp_ops {
12280
12281 void (*send_call_func_ipi)(const struct cpumask *mask);
12282 void (*send_call_func_single_ipi)(int cpu);
12283-};
12284+} __no_const;
12285
12286 /* Globals due to paravirt */
12287 extern void set_cpu_sibling_map(int cpu);
12288@@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12289 extern int safe_smp_processor_id(void);
12290
12291 #elif defined(CONFIG_X86_64_SMP)
12292-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12293-
12294-#define stack_smp_processor_id() \
12295-({ \
12296- struct thread_info *ti; \
12297- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12298- ti->cpu; \
12299-})
12300+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12301+#define stack_smp_processor_id() raw_smp_processor_id()
12302 #define safe_smp_processor_id() smp_processor_id()
12303
12304 #endif
12305diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12306index 33692ea..350a534 100644
12307--- a/arch/x86/include/asm/spinlock.h
12308+++ b/arch/x86/include/asm/spinlock.h
12309@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12310 static inline void arch_read_lock(arch_rwlock_t *rw)
12311 {
12312 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12313+
12314+#ifdef CONFIG_PAX_REFCOUNT
12315+ "jno 0f\n"
12316+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12317+ "int $4\n0:\n"
12318+ _ASM_EXTABLE(0b, 0b)
12319+#endif
12320+
12321 "jns 1f\n"
12322 "call __read_lock_failed\n\t"
12323 "1:\n"
12324@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12325 static inline void arch_write_lock(arch_rwlock_t *rw)
12326 {
12327 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12328+
12329+#ifdef CONFIG_PAX_REFCOUNT
12330+ "jno 0f\n"
12331+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12332+ "int $4\n0:\n"
12333+ _ASM_EXTABLE(0b, 0b)
12334+#endif
12335+
12336 "jz 1f\n"
12337 "call __write_lock_failed\n\t"
12338 "1:\n"
12339@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12340
12341 static inline void arch_read_unlock(arch_rwlock_t *rw)
12342 {
12343- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12344+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12345+
12346+#ifdef CONFIG_PAX_REFCOUNT
12347+ "jno 0f\n"
12348+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12349+ "int $4\n0:\n"
12350+ _ASM_EXTABLE(0b, 0b)
12351+#endif
12352+
12353 :"+m" (rw->lock) : : "memory");
12354 }
12355
12356 static inline void arch_write_unlock(arch_rwlock_t *rw)
12357 {
12358- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12359+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12360+
12361+#ifdef CONFIG_PAX_REFCOUNT
12362+ "jno 0f\n"
12363+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12364+ "int $4\n0:\n"
12365+ _ASM_EXTABLE(0b, 0b)
12366+#endif
12367+
12368 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12369 }
12370
12371diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12372index 6a99859..03cb807 100644
12373--- a/arch/x86/include/asm/stackprotector.h
12374+++ b/arch/x86/include/asm/stackprotector.h
12375@@ -47,7 +47,7 @@
12376 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12377 */
12378 #define GDT_STACK_CANARY_INIT \
12379- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12380+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12381
12382 /*
12383 * Initialize the stackprotector canary value.
12384@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12385
12386 static inline void load_stack_canary_segment(void)
12387 {
12388-#ifdef CONFIG_X86_32
12389+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12390 asm volatile ("mov %0, %%gs" : : "r" (0));
12391 #endif
12392 }
12393diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12394index 70bbe39..4ae2bd4 100644
12395--- a/arch/x86/include/asm/stacktrace.h
12396+++ b/arch/x86/include/asm/stacktrace.h
12397@@ -11,28 +11,20 @@
12398
12399 extern int kstack_depth_to_print;
12400
12401-struct thread_info;
12402+struct task_struct;
12403 struct stacktrace_ops;
12404
12405-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12406- unsigned long *stack,
12407- unsigned long bp,
12408- const struct stacktrace_ops *ops,
12409- void *data,
12410- unsigned long *end,
12411- int *graph);
12412+typedef unsigned long walk_stack_t(struct task_struct *task,
12413+ void *stack_start,
12414+ unsigned long *stack,
12415+ unsigned long bp,
12416+ const struct stacktrace_ops *ops,
12417+ void *data,
12418+ unsigned long *end,
12419+ int *graph);
12420
12421-extern unsigned long
12422-print_context_stack(struct thread_info *tinfo,
12423- unsigned long *stack, unsigned long bp,
12424- const struct stacktrace_ops *ops, void *data,
12425- unsigned long *end, int *graph);
12426-
12427-extern unsigned long
12428-print_context_stack_bp(struct thread_info *tinfo,
12429- unsigned long *stack, unsigned long bp,
12430- const struct stacktrace_ops *ops, void *data,
12431- unsigned long *end, int *graph);
12432+extern walk_stack_t print_context_stack;
12433+extern walk_stack_t print_context_stack_bp;
12434
12435 /* Generic stack tracer with callbacks */
12436
12437@@ -40,7 +32,7 @@ struct stacktrace_ops {
12438 void (*address)(void *data, unsigned long address, int reliable);
12439 /* On negative return stop dumping */
12440 int (*stack)(void *data, char *name);
12441- walk_stack_t walk_stack;
12442+ walk_stack_t *walk_stack;
12443 };
12444
12445 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12446diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12447index 4ec45b3..a4f0a8a 100644
12448--- a/arch/x86/include/asm/switch_to.h
12449+++ b/arch/x86/include/asm/switch_to.h
12450@@ -108,7 +108,7 @@ do { \
12451 "call __switch_to\n\t" \
12452 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12453 __switch_canary \
12454- "movq %P[thread_info](%%rsi),%%r8\n\t" \
12455+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12456 "movq %%rax,%%rdi\n\t" \
12457 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12458 "jnz ret_from_fork\n\t" \
12459@@ -119,7 +119,7 @@ do { \
12460 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12461 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12462 [_tif_fork] "i" (_TIF_FORK), \
12463- [thread_info] "i" (offsetof(struct task_struct, stack)), \
12464+ [thread_info] "m" (current_tinfo), \
12465 [current_task] "m" (current_task) \
12466 __switch_canary_iparam \
12467 : "memory", "cc" __EXTRA_CLOBBER)
12468diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12469index 3fda9db4..4ca1c61 100644
12470--- a/arch/x86/include/asm/sys_ia32.h
12471+++ b/arch/x86/include/asm/sys_ia32.h
12472@@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12473 struct old_sigaction32 __user *);
12474 asmlinkage long sys32_alarm(unsigned int);
12475
12476-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12477+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12478 asmlinkage long sys32_sysfs(int, u32, u32);
12479
12480 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12481diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12482index 89f794f..1422765 100644
12483--- a/arch/x86/include/asm/thread_info.h
12484+++ b/arch/x86/include/asm/thread_info.h
12485@@ -10,6 +10,7 @@
12486 #include <linux/compiler.h>
12487 #include <asm/page.h>
12488 #include <asm/types.h>
12489+#include <asm/percpu.h>
12490
12491 /*
12492 * low level task data that entry.S needs immediate access to
12493@@ -24,7 +25,6 @@ struct exec_domain;
12494 #include <linux/atomic.h>
12495
12496 struct thread_info {
12497- struct task_struct *task; /* main task structure */
12498 struct exec_domain *exec_domain; /* execution domain */
12499 __u32 flags; /* low level flags */
12500 __u32 status; /* thread synchronous flags */
12501@@ -34,19 +34,13 @@ struct thread_info {
12502 mm_segment_t addr_limit;
12503 struct restart_block restart_block;
12504 void __user *sysenter_return;
12505-#ifdef CONFIG_X86_32
12506- unsigned long previous_esp; /* ESP of the previous stack in
12507- case of nested (IRQ) stacks
12508- */
12509- __u8 supervisor_stack[0];
12510-#endif
12511+ unsigned long lowest_stack;
12512 unsigned int sig_on_uaccess_error:1;
12513 unsigned int uaccess_err:1; /* uaccess failed */
12514 };
12515
12516-#define INIT_THREAD_INFO(tsk) \
12517+#define INIT_THREAD_INFO \
12518 { \
12519- .task = &tsk, \
12520 .exec_domain = &default_exec_domain, \
12521 .flags = 0, \
12522 .cpu = 0, \
12523@@ -57,7 +51,7 @@ struct thread_info {
12524 }, \
12525 }
12526
12527-#define init_thread_info (init_thread_union.thread_info)
12528+#define init_thread_info (init_thread_union.stack)
12529 #define init_stack (init_thread_union.stack)
12530
12531 #else /* !__ASSEMBLY__ */
12532@@ -98,6 +92,7 @@ struct thread_info {
12533 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12534 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12535 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12536+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12537
12538 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12539 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12540@@ -122,16 +117,18 @@ struct thread_info {
12541 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12542 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12543 #define _TIF_X32 (1 << TIF_X32)
12544+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12545
12546 /* work to do in syscall_trace_enter() */
12547 #define _TIF_WORK_SYSCALL_ENTRY \
12548 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12549- _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12550+ _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12551+ _TIF_GRSEC_SETXID)
12552
12553 /* work to do in syscall_trace_leave() */
12554 #define _TIF_WORK_SYSCALL_EXIT \
12555 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12556- _TIF_SYSCALL_TRACEPOINT)
12557+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12558
12559 /* work to do on interrupt/exception return */
12560 #define _TIF_WORK_MASK \
12561@@ -141,7 +138,8 @@ struct thread_info {
12562
12563 /* work to do on any return to user space */
12564 #define _TIF_ALLWORK_MASK \
12565- ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12566+ ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12567+ _TIF_GRSEC_SETXID)
12568
12569 /* Only used for 64 bit */
12570 #define _TIF_DO_NOTIFY_MASK \
12571@@ -157,45 +155,40 @@ struct thread_info {
12572
12573 #define PREEMPT_ACTIVE 0x10000000
12574
12575-#ifdef CONFIG_X86_32
12576-
12577-#define STACK_WARN (THREAD_SIZE/8)
12578-/*
12579- * macros/functions for gaining access to the thread information structure
12580- *
12581- * preempt_count needs to be 1 initially, until the scheduler is functional.
12582- */
12583-#ifndef __ASSEMBLY__
12584-
12585-
12586-/* how to get the current stack pointer from C */
12587-register unsigned long current_stack_pointer asm("esp") __used;
12588-
12589-/* how to get the thread information struct from C */
12590-static inline struct thread_info *current_thread_info(void)
12591-{
12592- return (struct thread_info *)
12593- (current_stack_pointer & ~(THREAD_SIZE - 1));
12594-}
12595-
12596-#else /* !__ASSEMBLY__ */
12597-
12598+#ifdef __ASSEMBLY__
12599 /* how to get the thread information struct from ASM */
12600 #define GET_THREAD_INFO(reg) \
12601- movl $-THREAD_SIZE, reg; \
12602- andl %esp, reg
12603+ mov PER_CPU_VAR(current_tinfo), reg
12604
12605 /* use this one if reg already contains %esp */
12606-#define GET_THREAD_INFO_WITH_ESP(reg) \
12607- andl $-THREAD_SIZE, reg
12608+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12609+#else
12610+/* how to get the thread information struct from C */
12611+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12612+
12613+static __always_inline struct thread_info *current_thread_info(void)
12614+{
12615+ return this_cpu_read_stable(current_tinfo);
12616+}
12617+#endif
12618+
12619+#ifdef CONFIG_X86_32
12620+
12621+#define STACK_WARN (THREAD_SIZE/8)
12622+/*
12623+ * macros/functions for gaining access to the thread information structure
12624+ *
12625+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12626+ */
12627+#ifndef __ASSEMBLY__
12628+
12629+/* how to get the current stack pointer from C */
12630+register unsigned long current_stack_pointer asm("esp") __used;
12631
12632 #endif
12633
12634 #else /* X86_32 */
12635
12636-#include <asm/percpu.h>
12637-#define KERNEL_STACK_OFFSET (5*8)
12638-
12639 /*
12640 * macros/functions for gaining access to the thread information structure
12641 * preempt_count needs to be 1 initially, until the scheduler is functional.
12642@@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12643 #ifndef __ASSEMBLY__
12644 DECLARE_PER_CPU(unsigned long, kernel_stack);
12645
12646-static inline struct thread_info *current_thread_info(void)
12647-{
12648- struct thread_info *ti;
12649- ti = (void *)(this_cpu_read_stable(kernel_stack) +
12650- KERNEL_STACK_OFFSET - THREAD_SIZE);
12651- return ti;
12652-}
12653-
12654-#else /* !__ASSEMBLY__ */
12655-
12656-/* how to get the thread information struct from ASM */
12657-#define GET_THREAD_INFO(reg) \
12658- movq PER_CPU_VAR(kernel_stack),reg ; \
12659- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12660-
12661-/*
12662- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12663- * a certain register (to be used in assembler memory operands).
12664- */
12665-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12666-
12667+/* how to get the current stack pointer from C */
12668+register unsigned long current_stack_pointer asm("rsp") __used;
12669 #endif
12670
12671 #endif /* !X86_32 */
12672@@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12673 extern void arch_task_cache_init(void);
12674 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12675 extern void arch_release_task_struct(struct task_struct *tsk);
12676+
12677+#define __HAVE_THREAD_FUNCTIONS
12678+#define task_thread_info(task) (&(task)->tinfo)
12679+#define task_stack_page(task) ((task)->stack)
12680+#define setup_thread_stack(p, org) do {} while (0)
12681+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12682+
12683 #endif
12684 #endif /* _ASM_X86_THREAD_INFO_H */
12685diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12686index e1f3a17..1ab364d 100644
12687--- a/arch/x86/include/asm/uaccess.h
12688+++ b/arch/x86/include/asm/uaccess.h
12689@@ -7,12 +7,15 @@
12690 #include <linux/compiler.h>
12691 #include <linux/thread_info.h>
12692 #include <linux/string.h>
12693+#include <linux/sched.h>
12694 #include <asm/asm.h>
12695 #include <asm/page.h>
12696
12697 #define VERIFY_READ 0
12698 #define VERIFY_WRITE 1
12699
12700+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12701+
12702 /*
12703 * The fs value determines whether argument validity checking should be
12704 * performed or not. If get_fs() == USER_DS, checking is performed, with
12705@@ -28,7 +31,12 @@
12706
12707 #define get_ds() (KERNEL_DS)
12708 #define get_fs() (current_thread_info()->addr_limit)
12709+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12710+void __set_fs(mm_segment_t x);
12711+void set_fs(mm_segment_t x);
12712+#else
12713 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12714+#endif
12715
12716 #define segment_eq(a, b) ((a).seg == (b).seg)
12717
12718@@ -76,8 +84,33 @@
12719 * checks that the pointer is in the user space range - after calling
12720 * this function, memory access functions may still return -EFAULT.
12721 */
12722-#define access_ok(type, addr, size) \
12723- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12724+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12725+#define access_ok(type, addr, size) \
12726+({ \
12727+ long __size = size; \
12728+ unsigned long __addr = (unsigned long)addr; \
12729+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12730+ unsigned long __end_ao = __addr + __size - 1; \
12731+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12732+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12733+ while(__addr_ao <= __end_ao) { \
12734+ char __c_ao; \
12735+ __addr_ao += PAGE_SIZE; \
12736+ if (__size > PAGE_SIZE) \
12737+ cond_resched(); \
12738+ if (__get_user(__c_ao, (char __user *)__addr)) \
12739+ break; \
12740+ if (type != VERIFY_WRITE) { \
12741+ __addr = __addr_ao; \
12742+ continue; \
12743+ } \
12744+ if (__put_user(__c_ao, (char __user *)__addr)) \
12745+ break; \
12746+ __addr = __addr_ao; \
12747+ } \
12748+ } \
12749+ __ret_ao; \
12750+})
12751
12752 /*
12753 * The exception table consists of pairs of addresses relative to the
12754@@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12755 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12756 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12757
12758-
12759+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12760+#define __copyuser_seg "gs;"
12761+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12762+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12763+#else
12764+#define __copyuser_seg
12765+#define __COPYUSER_SET_ES
12766+#define __COPYUSER_RESTORE_ES
12767+#endif
12768
12769 #ifdef CONFIG_X86_32
12770 #define __put_user_asm_u64(x, addr, err, errret) \
12771- asm volatile("1: movl %%eax,0(%2)\n" \
12772- "2: movl %%edx,4(%2)\n" \
12773+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12774+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12775 "3:\n" \
12776 ".section .fixup,\"ax\"\n" \
12777 "4: movl %3,%0\n" \
12778@@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12779 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12780
12781 #define __put_user_asm_ex_u64(x, addr) \
12782- asm volatile("1: movl %%eax,0(%1)\n" \
12783- "2: movl %%edx,4(%1)\n" \
12784+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12785+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12786 "3:\n" \
12787 _ASM_EXTABLE_EX(1b, 2b) \
12788 _ASM_EXTABLE_EX(2b, 3b) \
12789@@ -258,7 +299,7 @@ extern void __put_user_8(void);
12790 __typeof__(*(ptr)) __pu_val; \
12791 __chk_user_ptr(ptr); \
12792 might_fault(); \
12793- __pu_val = x; \
12794+ __pu_val = (x); \
12795 switch (sizeof(*(ptr))) { \
12796 case 1: \
12797 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12798@@ -379,7 +420,7 @@ do { \
12799 } while (0)
12800
12801 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12802- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12803+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12804 "2:\n" \
12805 ".section .fixup,\"ax\"\n" \
12806 "3: mov %3,%0\n" \
12807@@ -387,7 +428,7 @@ do { \
12808 " jmp 2b\n" \
12809 ".previous\n" \
12810 _ASM_EXTABLE(1b, 3b) \
12811- : "=r" (err), ltype(x) \
12812+ : "=r" (err), ltype (x) \
12813 : "m" (__m(addr)), "i" (errret), "0" (err))
12814
12815 #define __get_user_size_ex(x, ptr, size) \
12816@@ -412,7 +453,7 @@ do { \
12817 } while (0)
12818
12819 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12820- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12821+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12822 "2:\n" \
12823 _ASM_EXTABLE_EX(1b, 2b) \
12824 : ltype(x) : "m" (__m(addr)))
12825@@ -429,13 +470,24 @@ do { \
12826 int __gu_err; \
12827 unsigned long __gu_val; \
12828 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12829- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12830+ (x) = (__typeof__(*(ptr)))__gu_val; \
12831 __gu_err; \
12832 })
12833
12834 /* FIXME: this hack is definitely wrong -AK */
12835 struct __large_struct { unsigned long buf[100]; };
12836-#define __m(x) (*(struct __large_struct __user *)(x))
12837+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12838+#define ____m(x) \
12839+({ \
12840+ unsigned long ____x = (unsigned long)(x); \
12841+ if (____x < PAX_USER_SHADOW_BASE) \
12842+ ____x += PAX_USER_SHADOW_BASE; \
12843+ (void __user *)____x; \
12844+})
12845+#else
12846+#define ____m(x) (x)
12847+#endif
12848+#define __m(x) (*(struct __large_struct __user *)____m(x))
12849
12850 /*
12851 * Tell gcc we read from memory instead of writing: this is because
12852@@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12853 * aliasing issues.
12854 */
12855 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12856- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12857+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12858 "2:\n" \
12859 ".section .fixup,\"ax\"\n" \
12860 "3: mov %3,%0\n" \
12861@@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12862 ".previous\n" \
12863 _ASM_EXTABLE(1b, 3b) \
12864 : "=r"(err) \
12865- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12866+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12867
12868 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12869- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12870+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12871 "2:\n" \
12872 _ASM_EXTABLE_EX(1b, 2b) \
12873 : : ltype(x), "m" (__m(addr)))
12874@@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12875 * On error, the variable @x is set to zero.
12876 */
12877
12878+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12879+#define __get_user(x, ptr) get_user((x), (ptr))
12880+#else
12881 #define __get_user(x, ptr) \
12882 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12883+#endif
12884
12885 /**
12886 * __put_user: - Write a simple value into user space, with less checking.
12887@@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12888 * Returns zero on success, or -EFAULT on error.
12889 */
12890
12891+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12892+#define __put_user(x, ptr) put_user((x), (ptr))
12893+#else
12894 #define __put_user(x, ptr) \
12895 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12896+#endif
12897
12898 #define __get_user_unaligned __get_user
12899 #define __put_user_unaligned __put_user
12900@@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12901 #define get_user_ex(x, ptr) do { \
12902 unsigned long __gue_val; \
12903 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12904- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12905+ (x) = (__typeof__(*(ptr)))__gue_val; \
12906 } while (0)
12907
12908 #ifdef CONFIG_X86_WP_WORKS_OK
12909diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12910index 576e39b..ccd0a39 100644
12911--- a/arch/x86/include/asm/uaccess_32.h
12912+++ b/arch/x86/include/asm/uaccess_32.h
12913@@ -11,15 +11,15 @@
12914 #include <asm/page.h>
12915
12916 unsigned long __must_check __copy_to_user_ll
12917- (void __user *to, const void *from, unsigned long n);
12918+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12919 unsigned long __must_check __copy_from_user_ll
12920- (void *to, const void __user *from, unsigned long n);
12921+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12922 unsigned long __must_check __copy_from_user_ll_nozero
12923- (void *to, const void __user *from, unsigned long n);
12924+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12925 unsigned long __must_check __copy_from_user_ll_nocache
12926- (void *to, const void __user *from, unsigned long n);
12927+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12928 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12929- (void *to, const void __user *from, unsigned long n);
12930+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12931
12932 /**
12933 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12934@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12935 static __always_inline unsigned long __must_check
12936 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12937 {
12938+ if ((long)n < 0)
12939+ return n;
12940+
12941 if (__builtin_constant_p(n)) {
12942 unsigned long ret;
12943
12944@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12945 return ret;
12946 }
12947 }
12948+ if (!__builtin_constant_p(n))
12949+ check_object_size(from, n, true);
12950 return __copy_to_user_ll(to, from, n);
12951 }
12952
12953@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12954 __copy_to_user(void __user *to, const void *from, unsigned long n)
12955 {
12956 might_fault();
12957+
12958 return __copy_to_user_inatomic(to, from, n);
12959 }
12960
12961 static __always_inline unsigned long
12962 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12963 {
12964+ if ((long)n < 0)
12965+ return n;
12966+
12967 /* Avoid zeroing the tail if the copy fails..
12968 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12969 * but as the zeroing behaviour is only significant when n is not
12970@@ -137,6 +146,10 @@ static __always_inline unsigned long
12971 __copy_from_user(void *to, const void __user *from, unsigned long n)
12972 {
12973 might_fault();
12974+
12975+ if ((long)n < 0)
12976+ return n;
12977+
12978 if (__builtin_constant_p(n)) {
12979 unsigned long ret;
12980
12981@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12982 return ret;
12983 }
12984 }
12985+ if (!__builtin_constant_p(n))
12986+ check_object_size(to, n, false);
12987 return __copy_from_user_ll(to, from, n);
12988 }
12989
12990@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12991 const void __user *from, unsigned long n)
12992 {
12993 might_fault();
12994+
12995+ if ((long)n < 0)
12996+ return n;
12997+
12998 if (__builtin_constant_p(n)) {
12999 unsigned long ret;
13000
13001@@ -181,15 +200,19 @@ static __always_inline unsigned long
13002 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13003 unsigned long n)
13004 {
13005- return __copy_from_user_ll_nocache_nozero(to, from, n);
13006+ if ((long)n < 0)
13007+ return n;
13008+
13009+ return __copy_from_user_ll_nocache_nozero(to, from, n);
13010 }
13011
13012-unsigned long __must_check copy_to_user(void __user *to,
13013- const void *from, unsigned long n);
13014-unsigned long __must_check _copy_from_user(void *to,
13015- const void __user *from,
13016- unsigned long n);
13017-
13018+extern void copy_to_user_overflow(void)
13019+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13020+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13021+#else
13022+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13023+#endif
13024+;
13025
13026 extern void copy_from_user_overflow(void)
13027 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13028@@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13029 #endif
13030 ;
13031
13032-static inline unsigned long __must_check copy_from_user(void *to,
13033- const void __user *from,
13034- unsigned long n)
13035+/**
13036+ * copy_to_user: - Copy a block of data into user space.
13037+ * @to: Destination address, in user space.
13038+ * @from: Source address, in kernel space.
13039+ * @n: Number of bytes to copy.
13040+ *
13041+ * Context: User context only. This function may sleep.
13042+ *
13043+ * Copy data from kernel space to user space.
13044+ *
13045+ * Returns number of bytes that could not be copied.
13046+ * On success, this will be zero.
13047+ */
13048+static inline unsigned long __must_check
13049+copy_to_user(void __user *to, const void *from, unsigned long n)
13050 {
13051- int sz = __compiletime_object_size(to);
13052+ size_t sz = __compiletime_object_size(from);
13053
13054- if (likely(sz == -1 || sz >= n))
13055- n = _copy_from_user(to, from, n);
13056- else
13057+ if (unlikely(sz != (size_t)-1 && sz < n))
13058+ copy_to_user_overflow();
13059+ else if (access_ok(VERIFY_WRITE, to, n))
13060+ n = __copy_to_user(to, from, n);
13061+ return n;
13062+}
13063+
13064+/**
13065+ * copy_from_user: - Copy a block of data from user space.
13066+ * @to: Destination address, in kernel space.
13067+ * @from: Source address, in user space.
13068+ * @n: Number of bytes to copy.
13069+ *
13070+ * Context: User context only. This function may sleep.
13071+ *
13072+ * Copy data from user space to kernel space.
13073+ *
13074+ * Returns number of bytes that could not be copied.
13075+ * On success, this will be zero.
13076+ *
13077+ * If some data could not be copied, this function will pad the copied
13078+ * data to the requested size using zero bytes.
13079+ */
13080+static inline unsigned long __must_check
13081+copy_from_user(void *to, const void __user *from, unsigned long n)
13082+{
13083+ size_t sz = __compiletime_object_size(to);
13084+
13085+ if (unlikely(sz != (size_t)-1 && sz < n))
13086 copy_from_user_overflow();
13087-
13088+ else if (access_ok(VERIFY_READ, from, n))
13089+ n = __copy_from_user(to, from, n);
13090+ else if ((long)n > 0) {
13091+ if (!__builtin_constant_p(n))
13092+ check_object_size(to, n, false);
13093+ memset(to, 0, n);
13094+ }
13095 return n;
13096 }
13097
13098-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13099-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13100+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13101+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13102
13103 #endif /* _ASM_X86_UACCESS_32_H */
13104diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13105index d8def8b..ac7fc15 100644
13106--- a/arch/x86/include/asm/uaccess_64.h
13107+++ b/arch/x86/include/asm/uaccess_64.h
13108@@ -10,6 +10,9 @@
13109 #include <asm/alternative.h>
13110 #include <asm/cpufeature.h>
13111 #include <asm/page.h>
13112+#include <asm/pgtable.h>
13113+
13114+#define set_fs(x) (current_thread_info()->addr_limit = (x))
13115
13116 /*
13117 * Copy To/From Userspace
13118@@ -17,13 +20,13 @@
13119
13120 /* Handles exceptions in both to and from, but doesn't do access_ok */
13121 __must_check unsigned long
13122-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13123+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13124 __must_check unsigned long
13125-copy_user_generic_string(void *to, const void *from, unsigned len);
13126+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13127 __must_check unsigned long
13128-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13129+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13130
13131-static __always_inline __must_check unsigned long
13132+static __always_inline __must_check __size_overflow(3) unsigned long
13133 copy_user_generic(void *to, const void *from, unsigned len)
13134 {
13135 unsigned ret;
13136@@ -41,142 +44,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13137 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13138 "=d" (len)),
13139 "1" (to), "2" (from), "3" (len)
13140- : "memory", "rcx", "r8", "r9", "r10", "r11");
13141+ : "memory", "rcx", "r8", "r9", "r11");
13142 return ret;
13143 }
13144
13145+static __always_inline __must_check unsigned long
13146+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13147+static __always_inline __must_check unsigned long
13148+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13149 __must_check unsigned long
13150-_copy_to_user(void __user *to, const void *from, unsigned len);
13151-__must_check unsigned long
13152-_copy_from_user(void *to, const void __user *from, unsigned len);
13153-__must_check unsigned long
13154-copy_in_user(void __user *to, const void __user *from, unsigned len);
13155+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13156+
13157+extern void copy_to_user_overflow(void)
13158+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13159+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13160+#else
13161+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13162+#endif
13163+;
13164+
13165+extern void copy_from_user_overflow(void)
13166+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13167+ __compiletime_error("copy_from_user() buffer size is not provably correct")
13168+#else
13169+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
13170+#endif
13171+;
13172
13173 static inline unsigned long __must_check copy_from_user(void *to,
13174 const void __user *from,
13175 unsigned long n)
13176 {
13177- int sz = __compiletime_object_size(to);
13178-
13179 might_fault();
13180- if (likely(sz == -1 || sz >= n))
13181- n = _copy_from_user(to, from, n);
13182-#ifdef CONFIG_DEBUG_VM
13183- else
13184- WARN(1, "Buffer overflow detected!\n");
13185-#endif
13186+
13187+ if (access_ok(VERIFY_READ, from, n))
13188+ n = __copy_from_user(to, from, n);
13189+ else if (n < INT_MAX) {
13190+ if (!__builtin_constant_p(n))
13191+ check_object_size(to, n, false);
13192+ memset(to, 0, n);
13193+ }
13194 return n;
13195 }
13196
13197 static __always_inline __must_check
13198-int copy_to_user(void __user *dst, const void *src, unsigned size)
13199+int copy_to_user(void __user *dst, const void *src, unsigned long size)
13200 {
13201 might_fault();
13202
13203- return _copy_to_user(dst, src, size);
13204+ if (access_ok(VERIFY_WRITE, dst, size))
13205+ size = __copy_to_user(dst, src, size);
13206+ return size;
13207 }
13208
13209 static __always_inline __must_check
13210-int __copy_from_user(void *dst, const void __user *src, unsigned size)
13211+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13212 {
13213- int ret = 0;
13214+ size_t sz = __compiletime_object_size(dst);
13215+ unsigned ret = 0;
13216
13217 might_fault();
13218- if (!__builtin_constant_p(size))
13219- return copy_user_generic(dst, (__force void *)src, size);
13220+
13221+ if (size > INT_MAX)
13222+ return size;
13223+
13224+#ifdef CONFIG_PAX_MEMORY_UDEREF
13225+ if (!__access_ok(VERIFY_READ, src, size))
13226+ return size;
13227+#endif
13228+
13229+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13230+ copy_from_user_overflow();
13231+ return size;
13232+ }
13233+
13234+ if (!__builtin_constant_p(size)) {
13235+ check_object_size(dst, size, false);
13236+
13237+#ifdef CONFIG_PAX_MEMORY_UDEREF
13238+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13239+ src += PAX_USER_SHADOW_BASE;
13240+#endif
13241+
13242+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13243+ }
13244 switch (size) {
13245- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13246+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13247 ret, "b", "b", "=q", 1);
13248 return ret;
13249- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13250+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13251 ret, "w", "w", "=r", 2);
13252 return ret;
13253- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13254+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13255 ret, "l", "k", "=r", 4);
13256 return ret;
13257- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13258+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13259 ret, "q", "", "=r", 8);
13260 return ret;
13261 case 10:
13262- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13263+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13264 ret, "q", "", "=r", 10);
13265 if (unlikely(ret))
13266 return ret;
13267 __get_user_asm(*(u16 *)(8 + (char *)dst),
13268- (u16 __user *)(8 + (char __user *)src),
13269+ (const u16 __user *)(8 + (const char __user *)src),
13270 ret, "w", "w", "=r", 2);
13271 return ret;
13272 case 16:
13273- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13274+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13275 ret, "q", "", "=r", 16);
13276 if (unlikely(ret))
13277 return ret;
13278 __get_user_asm(*(u64 *)(8 + (char *)dst),
13279- (u64 __user *)(8 + (char __user *)src),
13280+ (const u64 __user *)(8 + (const char __user *)src),
13281 ret, "q", "", "=r", 8);
13282 return ret;
13283 default:
13284- return copy_user_generic(dst, (__force void *)src, size);
13285+
13286+#ifdef CONFIG_PAX_MEMORY_UDEREF
13287+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13288+ src += PAX_USER_SHADOW_BASE;
13289+#endif
13290+
13291+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13292 }
13293 }
13294
13295 static __always_inline __must_check
13296-int __copy_to_user(void __user *dst, const void *src, unsigned size)
13297+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13298 {
13299- int ret = 0;
13300+ size_t sz = __compiletime_object_size(src);
13301+ unsigned ret = 0;
13302
13303 might_fault();
13304- if (!__builtin_constant_p(size))
13305- return copy_user_generic((__force void *)dst, src, size);
13306+
13307+ if (size > INT_MAX)
13308+ return size;
13309+
13310+#ifdef CONFIG_PAX_MEMORY_UDEREF
13311+ if (!__access_ok(VERIFY_WRITE, dst, size))
13312+ return size;
13313+#endif
13314+
13315+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13316+ copy_to_user_overflow();
13317+ return size;
13318+ }
13319+
13320+ if (!__builtin_constant_p(size)) {
13321+ check_object_size(src, size, true);
13322+
13323+#ifdef CONFIG_PAX_MEMORY_UDEREF
13324+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13325+ dst += PAX_USER_SHADOW_BASE;
13326+#endif
13327+
13328+ return copy_user_generic((__force_kernel void *)dst, src, size);
13329+ }
13330 switch (size) {
13331- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13332+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13333 ret, "b", "b", "iq", 1);
13334 return ret;
13335- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13336+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13337 ret, "w", "w", "ir", 2);
13338 return ret;
13339- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13340+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13341 ret, "l", "k", "ir", 4);
13342 return ret;
13343- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13344+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13345 ret, "q", "", "er", 8);
13346 return ret;
13347 case 10:
13348- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13349+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13350 ret, "q", "", "er", 10);
13351 if (unlikely(ret))
13352 return ret;
13353 asm("":::"memory");
13354- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13355+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13356 ret, "w", "w", "ir", 2);
13357 return ret;
13358 case 16:
13359- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13360+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13361 ret, "q", "", "er", 16);
13362 if (unlikely(ret))
13363 return ret;
13364 asm("":::"memory");
13365- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13366+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13367 ret, "q", "", "er", 8);
13368 return ret;
13369 default:
13370- return copy_user_generic((__force void *)dst, src, size);
13371+
13372+#ifdef CONFIG_PAX_MEMORY_UDEREF
13373+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13374+ dst += PAX_USER_SHADOW_BASE;
13375+#endif
13376+
13377+ return copy_user_generic((__force_kernel void *)dst, src, size);
13378 }
13379 }
13380
13381 static __always_inline __must_check
13382-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13383+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13384 {
13385- int ret = 0;
13386+ unsigned ret = 0;
13387
13388 might_fault();
13389- if (!__builtin_constant_p(size))
13390- return copy_user_generic((__force void *)dst,
13391- (__force void *)src, size);
13392+
13393+ if (size > INT_MAX)
13394+ return size;
13395+
13396+#ifdef CONFIG_PAX_MEMORY_UDEREF
13397+ if (!__access_ok(VERIFY_READ, src, size))
13398+ return size;
13399+ if (!__access_ok(VERIFY_WRITE, dst, size))
13400+ return size;
13401+#endif
13402+
13403+ if (!__builtin_constant_p(size)) {
13404+
13405+#ifdef CONFIG_PAX_MEMORY_UDEREF
13406+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13407+ src += PAX_USER_SHADOW_BASE;
13408+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13409+ dst += PAX_USER_SHADOW_BASE;
13410+#endif
13411+
13412+ return copy_user_generic((__force_kernel void *)dst,
13413+ (__force_kernel const void *)src, size);
13414+ }
13415 switch (size) {
13416 case 1: {
13417 u8 tmp;
13418- __get_user_asm(tmp, (u8 __user *)src,
13419+ __get_user_asm(tmp, (const u8 __user *)src,
13420 ret, "b", "b", "=q", 1);
13421 if (likely(!ret))
13422 __put_user_asm(tmp, (u8 __user *)dst,
13423@@ -185,7 +284,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13424 }
13425 case 2: {
13426 u16 tmp;
13427- __get_user_asm(tmp, (u16 __user *)src,
13428+ __get_user_asm(tmp, (const u16 __user *)src,
13429 ret, "w", "w", "=r", 2);
13430 if (likely(!ret))
13431 __put_user_asm(tmp, (u16 __user *)dst,
13432@@ -195,7 +294,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13433
13434 case 4: {
13435 u32 tmp;
13436- __get_user_asm(tmp, (u32 __user *)src,
13437+ __get_user_asm(tmp, (const u32 __user *)src,
13438 ret, "l", "k", "=r", 4);
13439 if (likely(!ret))
13440 __put_user_asm(tmp, (u32 __user *)dst,
13441@@ -204,7 +303,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13442 }
13443 case 8: {
13444 u64 tmp;
13445- __get_user_asm(tmp, (u64 __user *)src,
13446+ __get_user_asm(tmp, (const u64 __user *)src,
13447 ret, "q", "", "=r", 8);
13448 if (likely(!ret))
13449 __put_user_asm(tmp, (u64 __user *)dst,
13450@@ -212,44 +311,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13451 return ret;
13452 }
13453 default:
13454- return copy_user_generic((__force void *)dst,
13455- (__force void *)src, size);
13456+
13457+#ifdef CONFIG_PAX_MEMORY_UDEREF
13458+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13459+ src += PAX_USER_SHADOW_BASE;
13460+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13461+ dst += PAX_USER_SHADOW_BASE;
13462+#endif
13463+
13464+ return copy_user_generic((__force_kernel void *)dst,
13465+ (__force_kernel const void *)src, size);
13466 }
13467 }
13468
13469-__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13470-__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13471+__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13472+__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13473
13474 static __must_check __always_inline int
13475-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13476+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13477 {
13478- return copy_user_generic(dst, (__force const void *)src, size);
13479+ if (size > INT_MAX)
13480+ return size;
13481+
13482+#ifdef CONFIG_PAX_MEMORY_UDEREF
13483+ if (!__access_ok(VERIFY_READ, src, size))
13484+ return size;
13485+
13486+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13487+ src += PAX_USER_SHADOW_BASE;
13488+#endif
13489+
13490+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13491 }
13492
13493-static __must_check __always_inline int
13494-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13495+static __must_check __always_inline unsigned long
13496+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13497 {
13498- return copy_user_generic((__force void *)dst, src, size);
13499+ if (size > INT_MAX)
13500+ return size;
13501+
13502+#ifdef CONFIG_PAX_MEMORY_UDEREF
13503+ if (!__access_ok(VERIFY_WRITE, dst, size))
13504+ return size;
13505+
13506+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13507+ dst += PAX_USER_SHADOW_BASE;
13508+#endif
13509+
13510+ return copy_user_generic((__force_kernel void *)dst, src, size);
13511 }
13512
13513-extern long __copy_user_nocache(void *dst, const void __user *src,
13514- unsigned size, int zerorest);
13515+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13516+ unsigned long size, int zerorest) __size_overflow(3);
13517
13518-static inline int
13519-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13520+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13521 {
13522 might_sleep();
13523+
13524+ if (size > INT_MAX)
13525+ return size;
13526+
13527+#ifdef CONFIG_PAX_MEMORY_UDEREF
13528+ if (!__access_ok(VERIFY_READ, src, size))
13529+ return size;
13530+#endif
13531+
13532 return __copy_user_nocache(dst, src, size, 1);
13533 }
13534
13535-static inline int
13536-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13537- unsigned size)
13538+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13539+ unsigned long size)
13540 {
13541+ if (size > INT_MAX)
13542+ return size;
13543+
13544+#ifdef CONFIG_PAX_MEMORY_UDEREF
13545+ if (!__access_ok(VERIFY_READ, src, size))
13546+ return size;
13547+#endif
13548+
13549 return __copy_user_nocache(dst, src, size, 0);
13550 }
13551
13552-unsigned long
13553-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13554+extern unsigned long
13555+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13556
13557 #endif /* _ASM_X86_UACCESS_64_H */
13558diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13559index bb05228..d763d5b 100644
13560--- a/arch/x86/include/asm/vdso.h
13561+++ b/arch/x86/include/asm/vdso.h
13562@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13563 #define VDSO32_SYMBOL(base, name) \
13564 ({ \
13565 extern const char VDSO32_##name[]; \
13566- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13567+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13568 })
13569 #endif
13570
13571diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13572index 5b238981..77fdd78 100644
13573--- a/arch/x86/include/asm/word-at-a-time.h
13574+++ b/arch/x86/include/asm/word-at-a-time.h
13575@@ -11,7 +11,7 @@
13576 * and shift, for example.
13577 */
13578 struct word_at_a_time {
13579- const unsigned long one_bits, high_bits;
13580+ unsigned long one_bits, high_bits;
13581 };
13582
13583 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13584diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13585index 38155f6..e4184ba 100644
13586--- a/arch/x86/include/asm/x86_init.h
13587+++ b/arch/x86/include/asm/x86_init.h
13588@@ -29,7 +29,7 @@ struct x86_init_mpparse {
13589 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13590 void (*find_smp_config)(void);
13591 void (*get_smp_config)(unsigned int early);
13592-};
13593+} __no_const;
13594
13595 /**
13596 * struct x86_init_resources - platform specific resource related ops
13597@@ -43,7 +43,7 @@ struct x86_init_resources {
13598 void (*probe_roms)(void);
13599 void (*reserve_resources)(void);
13600 char *(*memory_setup)(void);
13601-};
13602+} __no_const;
13603
13604 /**
13605 * struct x86_init_irqs - platform specific interrupt setup
13606@@ -56,7 +56,7 @@ struct x86_init_irqs {
13607 void (*pre_vector_init)(void);
13608 void (*intr_init)(void);
13609 void (*trap_init)(void);
13610-};
13611+} __no_const;
13612
13613 /**
13614 * struct x86_init_oem - oem platform specific customizing functions
13615@@ -66,7 +66,7 @@ struct x86_init_irqs {
13616 struct x86_init_oem {
13617 void (*arch_setup)(void);
13618 void (*banner)(void);
13619-};
13620+} __no_const;
13621
13622 /**
13623 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13624@@ -77,7 +77,7 @@ struct x86_init_oem {
13625 */
13626 struct x86_init_mapping {
13627 void (*pagetable_reserve)(u64 start, u64 end);
13628-};
13629+} __no_const;
13630
13631 /**
13632 * struct x86_init_paging - platform specific paging functions
13633@@ -87,7 +87,7 @@ struct x86_init_mapping {
13634 struct x86_init_paging {
13635 void (*pagetable_setup_start)(pgd_t *base);
13636 void (*pagetable_setup_done)(pgd_t *base);
13637-};
13638+} __no_const;
13639
13640 /**
13641 * struct x86_init_timers - platform specific timer setup
13642@@ -102,7 +102,7 @@ struct x86_init_timers {
13643 void (*tsc_pre_init)(void);
13644 void (*timer_init)(void);
13645 void (*wallclock_init)(void);
13646-};
13647+} __no_const;
13648
13649 /**
13650 * struct x86_init_iommu - platform specific iommu setup
13651@@ -110,7 +110,7 @@ struct x86_init_timers {
13652 */
13653 struct x86_init_iommu {
13654 int (*iommu_init)(void);
13655-};
13656+} __no_const;
13657
13658 /**
13659 * struct x86_init_pci - platform specific pci init functions
13660@@ -124,7 +124,7 @@ struct x86_init_pci {
13661 int (*init)(void);
13662 void (*init_irq)(void);
13663 void (*fixup_irqs)(void);
13664-};
13665+} __no_const;
13666
13667 /**
13668 * struct x86_init_ops - functions for platform specific setup
13669@@ -140,7 +140,7 @@ struct x86_init_ops {
13670 struct x86_init_timers timers;
13671 struct x86_init_iommu iommu;
13672 struct x86_init_pci pci;
13673-};
13674+} __no_const;
13675
13676 /**
13677 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13678@@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13679 void (*setup_percpu_clockev)(void);
13680 void (*early_percpu_clock_init)(void);
13681 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13682-};
13683+} __no_const;
13684
13685 /**
13686 * struct x86_platform_ops - platform specific runtime functions
13687@@ -177,7 +177,7 @@ struct x86_platform_ops {
13688 void (*save_sched_clock_state)(void);
13689 void (*restore_sched_clock_state)(void);
13690 void (*apic_post_init)(void);
13691-};
13692+} __no_const;
13693
13694 struct pci_dev;
13695
13696@@ -186,14 +186,14 @@ struct x86_msi_ops {
13697 void (*teardown_msi_irq)(unsigned int irq);
13698 void (*teardown_msi_irqs)(struct pci_dev *dev);
13699 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13700-};
13701+} __no_const;
13702
13703 struct x86_io_apic_ops {
13704 void (*init) (void);
13705 unsigned int (*read) (unsigned int apic, unsigned int reg);
13706 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13707 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13708-};
13709+} __no_const;
13710
13711 extern struct x86_init_ops x86_init;
13712 extern struct x86_cpuinit_ops x86_cpuinit;
13713diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13714index 8a1b6f9..a29c4e4 100644
13715--- a/arch/x86/include/asm/xsave.h
13716+++ b/arch/x86/include/asm/xsave.h
13717@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13718 {
13719 int err;
13720
13721+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13722+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13723+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13724+#endif
13725+
13726 /*
13727 * Clear the xsave header first, so that reserved fields are
13728 * initialized to zero.
13729@@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13730 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13731 {
13732 int err;
13733- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13734+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13735 u32 lmask = mask;
13736 u32 hmask = mask >> 32;
13737
13738+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13739+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13740+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13741+#endif
13742+
13743 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13744 "2:\n"
13745 ".section .fixup,\"ax\"\n"
13746diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13747index 1b8e5a0..354fd59 100644
13748--- a/arch/x86/kernel/acpi/sleep.c
13749+++ b/arch/x86/kernel/acpi/sleep.c
13750@@ -69,8 +69,12 @@ int acpi_suspend_lowlevel(void)
13751 #else /* CONFIG_64BIT */
13752 #ifdef CONFIG_SMP
13753 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13754+
13755+ pax_open_kernel();
13756 early_gdt_descr.address =
13757 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13758+ pax_close_kernel();
13759+
13760 initial_gs = per_cpu_offset(smp_processor_id());
13761 #endif
13762 initial_code = (unsigned long)wakeup_long64;
13763diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13764index 13ab720..95d5442 100644
13765--- a/arch/x86/kernel/acpi/wakeup_32.S
13766+++ b/arch/x86/kernel/acpi/wakeup_32.S
13767@@ -30,13 +30,11 @@ wakeup_pmode_return:
13768 # and restore the stack ... but you need gdt for this to work
13769 movl saved_context_esp, %esp
13770
13771- movl %cs:saved_magic, %eax
13772- cmpl $0x12345678, %eax
13773+ cmpl $0x12345678, saved_magic
13774 jne bogus_magic
13775
13776 # jump to place where we left off
13777- movl saved_eip, %eax
13778- jmp *%eax
13779+ jmp *(saved_eip)
13780
13781 bogus_magic:
13782 jmp bogus_magic
13783diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13784index ced4534..3e75d69 100644
13785--- a/arch/x86/kernel/alternative.c
13786+++ b/arch/x86/kernel/alternative.c
13787@@ -281,6 +281,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13788 */
13789 for (a = start; a < end; a++) {
13790 instr = (u8 *)&a->instr_offset + a->instr_offset;
13791+
13792+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13793+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13794+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13795+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13796+#endif
13797+
13798 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13799 BUG_ON(a->replacementlen > a->instrlen);
13800 BUG_ON(a->instrlen > sizeof(insnbuf));
13801@@ -312,10 +319,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13802 for (poff = start; poff < end; poff++) {
13803 u8 *ptr = (u8 *)poff + *poff;
13804
13805+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13806+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13807+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13808+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13809+#endif
13810+
13811 if (!*poff || ptr < text || ptr >= text_end)
13812 continue;
13813 /* turn DS segment override prefix into lock prefix */
13814- if (*ptr == 0x3e)
13815+ if (*ktla_ktva(ptr) == 0x3e)
13816 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13817 };
13818 mutex_unlock(&text_mutex);
13819@@ -333,10 +346,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13820 for (poff = start; poff < end; poff++) {
13821 u8 *ptr = (u8 *)poff + *poff;
13822
13823+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13824+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13825+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13826+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13827+#endif
13828+
13829 if (!*poff || ptr < text || ptr >= text_end)
13830 continue;
13831 /* turn lock prefix into DS segment override prefix */
13832- if (*ptr == 0xf0)
13833+ if (*ktla_ktva(ptr) == 0xf0)
13834 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13835 };
13836 mutex_unlock(&text_mutex);
13837@@ -505,7 +524,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13838
13839 BUG_ON(p->len > MAX_PATCH_LEN);
13840 /* prep the buffer with the original instructions */
13841- memcpy(insnbuf, p->instr, p->len);
13842+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13843 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13844 (unsigned long)p->instr, p->len);
13845
13846@@ -573,7 +592,7 @@ void __init alternative_instructions(void)
13847 if (smp_alt_once)
13848 free_init_pages("SMP alternatives",
13849 (unsigned long)__smp_locks,
13850- (unsigned long)__smp_locks_end);
13851+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13852
13853 restart_nmi();
13854 }
13855@@ -590,13 +609,17 @@ void __init alternative_instructions(void)
13856 * instructions. And on the local CPU you need to be protected again NMI or MCE
13857 * handlers seeing an inconsistent instruction while you patch.
13858 */
13859-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13860+void *__kprobes text_poke_early(void *addr, const void *opcode,
13861 size_t len)
13862 {
13863 unsigned long flags;
13864 local_irq_save(flags);
13865- memcpy(addr, opcode, len);
13866+
13867+ pax_open_kernel();
13868+ memcpy(ktla_ktva(addr), opcode, len);
13869 sync_core();
13870+ pax_close_kernel();
13871+
13872 local_irq_restore(flags);
13873 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13874 that causes hangs on some VIA CPUs. */
13875@@ -618,36 +641,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13876 */
13877 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13878 {
13879- unsigned long flags;
13880- char *vaddr;
13881+ unsigned char *vaddr = ktla_ktva(addr);
13882 struct page *pages[2];
13883- int i;
13884+ size_t i;
13885
13886 if (!core_kernel_text((unsigned long)addr)) {
13887- pages[0] = vmalloc_to_page(addr);
13888- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13889+ pages[0] = vmalloc_to_page(vaddr);
13890+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13891 } else {
13892- pages[0] = virt_to_page(addr);
13893+ pages[0] = virt_to_page(vaddr);
13894 WARN_ON(!PageReserved(pages[0]));
13895- pages[1] = virt_to_page(addr + PAGE_SIZE);
13896+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13897 }
13898 BUG_ON(!pages[0]);
13899- local_irq_save(flags);
13900- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13901- if (pages[1])
13902- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13903- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13904- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13905- clear_fixmap(FIX_TEXT_POKE0);
13906- if (pages[1])
13907- clear_fixmap(FIX_TEXT_POKE1);
13908- local_flush_tlb();
13909- sync_core();
13910- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13911- that causes hangs on some VIA CPUs. */
13912+ text_poke_early(addr, opcode, len);
13913 for (i = 0; i < len; i++)
13914- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13915- local_irq_restore(flags);
13916+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13917 return addr;
13918 }
13919
13920diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13921index 24deb30..94a3426 100644
13922--- a/arch/x86/kernel/apic/apic.c
13923+++ b/arch/x86/kernel/apic/apic.c
13924@@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13925 /*
13926 * Debug level, exported for io_apic.c
13927 */
13928-unsigned int apic_verbosity;
13929+int apic_verbosity;
13930
13931 int pic_mode;
13932
13933@@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13934 apic_write(APIC_ESR, 0);
13935 v1 = apic_read(APIC_ESR);
13936 ack_APIC_irq();
13937- atomic_inc(&irq_err_count);
13938+ atomic_inc_unchecked(&irq_err_count);
13939
13940 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13941 smp_processor_id(), v0 , v1);
13942@@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13943 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13944 /* Should happen once for each apic */
13945 WARN_ON((*drv)->eoi_write == eoi_write);
13946- (*drv)->eoi_write = eoi_write;
13947+ pax_open_kernel();
13948+ *(void **)&(*drv)->eoi_write = eoi_write;
13949+ pax_close_kernel();
13950 }
13951 }
13952
13953diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13954index c265593..137c4ac 100644
13955--- a/arch/x86/kernel/apic/io_apic.c
13956+++ b/arch/x86/kernel/apic/io_apic.c
13957@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13958 }
13959 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13960
13961-void lock_vector_lock(void)
13962+void lock_vector_lock(void) __acquires(vector_lock)
13963 {
13964 /* Used to the online set of cpus does not change
13965 * during assign_irq_vector.
13966@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13967 raw_spin_lock(&vector_lock);
13968 }
13969
13970-void unlock_vector_lock(void)
13971+void unlock_vector_lock(void) __releases(vector_lock)
13972 {
13973 raw_spin_unlock(&vector_lock);
13974 }
13975@@ -2408,7 +2408,7 @@ static void ack_apic_edge(struct irq_data *data)
13976 ack_APIC_irq();
13977 }
13978
13979-atomic_t irq_mis_count;
13980+atomic_unchecked_t irq_mis_count;
13981
13982 #ifdef CONFIG_GENERIC_PENDING_IRQ
13983 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13984@@ -2549,7 +2549,7 @@ static void ack_apic_level(struct irq_data *data)
13985 * at the cpu.
13986 */
13987 if (!(v & (1 << (i & 0x1f)))) {
13988- atomic_inc(&irq_mis_count);
13989+ atomic_inc_unchecked(&irq_mis_count);
13990
13991 eoi_ioapic_irq(irq, cfg);
13992 }
13993diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13994index d65464e..1035d31 100644
13995--- a/arch/x86/kernel/apm_32.c
13996+++ b/arch/x86/kernel/apm_32.c
13997@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
13998 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13999 * even though they are called in protected mode.
14000 */
14001-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14002+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14003 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14004
14005 static const char driver_version[] = "1.16ac"; /* no spaces */
14006@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14007 BUG_ON(cpu != 0);
14008 gdt = get_cpu_gdt_table(cpu);
14009 save_desc_40 = gdt[0x40 / 8];
14010+
14011+ pax_open_kernel();
14012 gdt[0x40 / 8] = bad_bios_desc;
14013+ pax_close_kernel();
14014
14015 apm_irq_save(flags);
14016 APM_DO_SAVE_SEGS;
14017@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14018 &call->esi);
14019 APM_DO_RESTORE_SEGS;
14020 apm_irq_restore(flags);
14021+
14022+ pax_open_kernel();
14023 gdt[0x40 / 8] = save_desc_40;
14024+ pax_close_kernel();
14025+
14026 put_cpu();
14027
14028 return call->eax & 0xff;
14029@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14030 BUG_ON(cpu != 0);
14031 gdt = get_cpu_gdt_table(cpu);
14032 save_desc_40 = gdt[0x40 / 8];
14033+
14034+ pax_open_kernel();
14035 gdt[0x40 / 8] = bad_bios_desc;
14036+ pax_close_kernel();
14037
14038 apm_irq_save(flags);
14039 APM_DO_SAVE_SEGS;
14040@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14041 &call->eax);
14042 APM_DO_RESTORE_SEGS;
14043 apm_irq_restore(flags);
14044+
14045+ pax_open_kernel();
14046 gdt[0x40 / 8] = save_desc_40;
14047+ pax_close_kernel();
14048+
14049 put_cpu();
14050 return error;
14051 }
14052@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14053 * code to that CPU.
14054 */
14055 gdt = get_cpu_gdt_table(0);
14056+
14057+ pax_open_kernel();
14058 set_desc_base(&gdt[APM_CS >> 3],
14059 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14060 set_desc_base(&gdt[APM_CS_16 >> 3],
14061 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14062 set_desc_base(&gdt[APM_DS >> 3],
14063 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14064+ pax_close_kernel();
14065
14066 proc_create("apm", 0, NULL, &apm_file_ops);
14067
14068diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14069index 68de2dc..1f3c720 100644
14070--- a/arch/x86/kernel/asm-offsets.c
14071+++ b/arch/x86/kernel/asm-offsets.c
14072@@ -33,6 +33,8 @@ void common(void) {
14073 OFFSET(TI_status, thread_info, status);
14074 OFFSET(TI_addr_limit, thread_info, addr_limit);
14075 OFFSET(TI_preempt_count, thread_info, preempt_count);
14076+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14077+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14078
14079 BLANK();
14080 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14081@@ -53,8 +55,26 @@ void common(void) {
14082 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14083 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14084 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14085+
14086+#ifdef CONFIG_PAX_KERNEXEC
14087+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14088 #endif
14089
14090+#ifdef CONFIG_PAX_MEMORY_UDEREF
14091+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14092+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14093+#ifdef CONFIG_X86_64
14094+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14095+#endif
14096+#endif
14097+
14098+#endif
14099+
14100+ BLANK();
14101+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14102+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14103+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14104+
14105 #ifdef CONFIG_XEN
14106 BLANK();
14107 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14108diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14109index 1b4754f..fbb4227 100644
14110--- a/arch/x86/kernel/asm-offsets_64.c
14111+++ b/arch/x86/kernel/asm-offsets_64.c
14112@@ -76,6 +76,7 @@ int main(void)
14113 BLANK();
14114 #undef ENTRY
14115
14116+ DEFINE(TSS_size, sizeof(struct tss_struct));
14117 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14118 BLANK();
14119
14120diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14121index d30a6a9..79becab 100644
14122--- a/arch/x86/kernel/cpu/Makefile
14123+++ b/arch/x86/kernel/cpu/Makefile
14124@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14125 CFLAGS_REMOVE_perf_event.o = -pg
14126 endif
14127
14128-# Make sure load_percpu_segment has no stackprotector
14129-nostackp := $(call cc-option, -fno-stack-protector)
14130-CFLAGS_common.o := $(nostackp)
14131-
14132 obj-y := intel_cacheinfo.o scattered.o topology.o
14133 obj-y += proc.o capflags.o powerflags.o common.o
14134 obj-y += vmware.o hypervisor.o mshyperv.o
14135diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14136index 9d92e19..49d7d79 100644
14137--- a/arch/x86/kernel/cpu/amd.c
14138+++ b/arch/x86/kernel/cpu/amd.c
14139@@ -724,7 +724,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14140 unsigned int size)
14141 {
14142 /* AMD errata T13 (order #21922) */
14143- if ((c->x86 == 6)) {
14144+ if (c->x86 == 6) {
14145 /* Duron Rev A0 */
14146 if (c->x86_model == 3 && c->x86_mask == 0)
14147 size = 64;
14148diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14149index a5fbc3c..2254849 100644
14150--- a/arch/x86/kernel/cpu/common.c
14151+++ b/arch/x86/kernel/cpu/common.c
14152@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14153
14154 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14155
14156-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14157-#ifdef CONFIG_X86_64
14158- /*
14159- * We need valid kernel segments for data and code in long mode too
14160- * IRET will check the segment types kkeil 2000/10/28
14161- * Also sysret mandates a special GDT layout
14162- *
14163- * TLS descriptors are currently at a different place compared to i386.
14164- * Hopefully nobody expects them at a fixed place (Wine?)
14165- */
14166- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14167- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14168- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14169- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14170- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14171- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14172-#else
14173- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14174- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14175- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14176- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14177- /*
14178- * Segments used for calling PnP BIOS have byte granularity.
14179- * They code segments and data segments have fixed 64k limits,
14180- * the transfer segment sizes are set at run time.
14181- */
14182- /* 32-bit code */
14183- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14184- /* 16-bit code */
14185- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14186- /* 16-bit data */
14187- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14188- /* 16-bit data */
14189- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14190- /* 16-bit data */
14191- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14192- /*
14193- * The APM segments have byte granularity and their bases
14194- * are set at run time. All have 64k limits.
14195- */
14196- /* 32-bit code */
14197- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14198- /* 16-bit code */
14199- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14200- /* data */
14201- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14202-
14203- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14204- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14205- GDT_STACK_CANARY_INIT
14206-#endif
14207-} };
14208-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14209-
14210 static int __init x86_xsave_setup(char *s)
14211 {
14212 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14213@@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14214 {
14215 struct desc_ptr gdt_descr;
14216
14217- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14218+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14219 gdt_descr.size = GDT_SIZE - 1;
14220 load_gdt(&gdt_descr);
14221 /* Reload the per-cpu base */
14222@@ -872,6 +818,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14223 /* Filter out anything that depends on CPUID levels we don't have */
14224 filter_cpuid_features(c, true);
14225
14226+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14227+ setup_clear_cpu_cap(X86_FEATURE_SEP);
14228+#endif
14229+
14230 /* If the model name is still unset, do table lookup. */
14231 if (!c->x86_model_id[0]) {
14232 const char *p;
14233@@ -1054,10 +1004,12 @@ static __init int setup_disablecpuid(char *arg)
14234 }
14235 __setup("clearcpuid=", setup_disablecpuid);
14236
14237+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14238+EXPORT_PER_CPU_SYMBOL(current_tinfo);
14239+
14240 #ifdef CONFIG_X86_64
14241 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14242-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14243- (unsigned long) nmi_idt_table };
14244+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14245
14246 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14247 irq_stack_union) __aligned(PAGE_SIZE);
14248@@ -1071,7 +1023,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14249 EXPORT_PER_CPU_SYMBOL(current_task);
14250
14251 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14252- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14253+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14254 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14255
14256 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14257@@ -1165,7 +1117,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14258 {
14259 memset(regs, 0, sizeof(struct pt_regs));
14260 regs->fs = __KERNEL_PERCPU;
14261- regs->gs = __KERNEL_STACK_CANARY;
14262+ savesegment(gs, regs->gs);
14263
14264 return regs;
14265 }
14266@@ -1220,7 +1172,7 @@ void __cpuinit cpu_init(void)
14267 int i;
14268
14269 cpu = stack_smp_processor_id();
14270- t = &per_cpu(init_tss, cpu);
14271+ t = init_tss + cpu;
14272 oist = &per_cpu(orig_ist, cpu);
14273
14274 #ifdef CONFIG_NUMA
14275@@ -1246,7 +1198,7 @@ void __cpuinit cpu_init(void)
14276 switch_to_new_gdt(cpu);
14277 loadsegment(fs, 0);
14278
14279- load_idt((const struct desc_ptr *)&idt_descr);
14280+ load_idt(&idt_descr);
14281
14282 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14283 syscall_init();
14284@@ -1255,7 +1207,6 @@ void __cpuinit cpu_init(void)
14285 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14286 barrier();
14287
14288- x86_configure_nx();
14289 if (cpu != 0)
14290 enable_x2apic();
14291
14292@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
14293 {
14294 int cpu = smp_processor_id();
14295 struct task_struct *curr = current;
14296- struct tss_struct *t = &per_cpu(init_tss, cpu);
14297+ struct tss_struct *t = init_tss + cpu;
14298 struct thread_struct *thread = &curr->thread;
14299
14300 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14301diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14302index 0a4ce29..f211176 100644
14303--- a/arch/x86/kernel/cpu/intel.c
14304+++ b/arch/x86/kernel/cpu/intel.c
14305@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14306 * Update the IDT descriptor and reload the IDT so that
14307 * it uses the read-only mapped virtual address.
14308 */
14309- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14310+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14311 load_idt(&idt_descr);
14312 }
14313 #endif
14314diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14315index 292d025..b520c94 100644
14316--- a/arch/x86/kernel/cpu/mcheck/mce.c
14317+++ b/arch/x86/kernel/cpu/mcheck/mce.c
14318@@ -45,6 +45,7 @@
14319 #include <asm/processor.h>
14320 #include <asm/mce.h>
14321 #include <asm/msr.h>
14322+#include <asm/local.h>
14323
14324 #include "mce-internal.h"
14325
14326@@ -253,7 +254,7 @@ static void print_mce(struct mce *m)
14327 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14328 m->cs, m->ip);
14329
14330- if (m->cs == __KERNEL_CS)
14331+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14332 print_symbol("{%s}", m->ip);
14333 pr_cont("\n");
14334 }
14335@@ -286,10 +287,10 @@ static void print_mce(struct mce *m)
14336
14337 #define PANIC_TIMEOUT 5 /* 5 seconds */
14338
14339-static atomic_t mce_paniced;
14340+static atomic_unchecked_t mce_paniced;
14341
14342 static int fake_panic;
14343-static atomic_t mce_fake_paniced;
14344+static atomic_unchecked_t mce_fake_paniced;
14345
14346 /* Panic in progress. Enable interrupts and wait for final IPI */
14347 static void wait_for_panic(void)
14348@@ -313,7 +314,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14349 /*
14350 * Make sure only one CPU runs in machine check panic
14351 */
14352- if (atomic_inc_return(&mce_paniced) > 1)
14353+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14354 wait_for_panic();
14355 barrier();
14356
14357@@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14358 console_verbose();
14359 } else {
14360 /* Don't log too much for fake panic */
14361- if (atomic_inc_return(&mce_fake_paniced) > 1)
14362+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14363 return;
14364 }
14365 /* First print corrected ones that are still unlogged */
14366@@ -693,7 +694,7 @@ static int mce_timed_out(u64 *t)
14367 * might have been modified by someone else.
14368 */
14369 rmb();
14370- if (atomic_read(&mce_paniced))
14371+ if (atomic_read_unchecked(&mce_paniced))
14372 wait_for_panic();
14373 if (!monarch_timeout)
14374 goto out;
14375@@ -1619,7 +1620,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14376 }
14377
14378 /* Call the installed machine check handler for this CPU setup. */
14379-void (*machine_check_vector)(struct pt_regs *, long error_code) =
14380+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14381 unexpected_machine_check;
14382
14383 /*
14384@@ -1642,7 +1643,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14385 return;
14386 }
14387
14388+ pax_open_kernel();
14389 machine_check_vector = do_machine_check;
14390+ pax_close_kernel();
14391
14392 __mcheck_cpu_init_generic();
14393 __mcheck_cpu_init_vendor(c);
14394@@ -1656,7 +1659,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14395 */
14396
14397 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14398-static int mce_chrdev_open_count; /* #times opened */
14399+static local_t mce_chrdev_open_count; /* #times opened */
14400 static int mce_chrdev_open_exclu; /* already open exclusive? */
14401
14402 static int mce_chrdev_open(struct inode *inode, struct file *file)
14403@@ -1664,7 +1667,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14404 spin_lock(&mce_chrdev_state_lock);
14405
14406 if (mce_chrdev_open_exclu ||
14407- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14408+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14409 spin_unlock(&mce_chrdev_state_lock);
14410
14411 return -EBUSY;
14412@@ -1672,7 +1675,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14413
14414 if (file->f_flags & O_EXCL)
14415 mce_chrdev_open_exclu = 1;
14416- mce_chrdev_open_count++;
14417+ local_inc(&mce_chrdev_open_count);
14418
14419 spin_unlock(&mce_chrdev_state_lock);
14420
14421@@ -1683,7 +1686,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14422 {
14423 spin_lock(&mce_chrdev_state_lock);
14424
14425- mce_chrdev_open_count--;
14426+ local_dec(&mce_chrdev_open_count);
14427 mce_chrdev_open_exclu = 0;
14428
14429 spin_unlock(&mce_chrdev_state_lock);
14430@@ -2407,7 +2410,7 @@ struct dentry *mce_get_debugfs_dir(void)
14431 static void mce_reset(void)
14432 {
14433 cpu_missing = 0;
14434- atomic_set(&mce_fake_paniced, 0);
14435+ atomic_set_unchecked(&mce_fake_paniced, 0);
14436 atomic_set(&mce_executing, 0);
14437 atomic_set(&mce_callin, 0);
14438 atomic_set(&global_nwo, 0);
14439diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14440index 2d5454c..51987eb 100644
14441--- a/arch/x86/kernel/cpu/mcheck/p5.c
14442+++ b/arch/x86/kernel/cpu/mcheck/p5.c
14443@@ -11,6 +11,7 @@
14444 #include <asm/processor.h>
14445 #include <asm/mce.h>
14446 #include <asm/msr.h>
14447+#include <asm/pgtable.h>
14448
14449 /* By default disabled */
14450 int mce_p5_enabled __read_mostly;
14451@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14452 if (!cpu_has(c, X86_FEATURE_MCE))
14453 return;
14454
14455+ pax_open_kernel();
14456 machine_check_vector = pentium_machine_check;
14457+ pax_close_kernel();
14458 /* Make sure the vector pointer is visible before we enable MCEs: */
14459 wmb();
14460
14461diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14462index 2d7998f..17c9de1 100644
14463--- a/arch/x86/kernel/cpu/mcheck/winchip.c
14464+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14465@@ -10,6 +10,7 @@
14466 #include <asm/processor.h>
14467 #include <asm/mce.h>
14468 #include <asm/msr.h>
14469+#include <asm/pgtable.h>
14470
14471 /* Machine check handler for WinChip C6: */
14472 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14473@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14474 {
14475 u32 lo, hi;
14476
14477+ pax_open_kernel();
14478 machine_check_vector = winchip_machine_check;
14479+ pax_close_kernel();
14480 /* Make sure the vector pointer is visible before we enable MCEs: */
14481 wmb();
14482
14483diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14484index 6b96110..0da73eb 100644
14485--- a/arch/x86/kernel/cpu/mtrr/main.c
14486+++ b/arch/x86/kernel/cpu/mtrr/main.c
14487@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14488 u64 size_or_mask, size_and_mask;
14489 static bool mtrr_aps_delayed_init;
14490
14491-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14492+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14493
14494 const struct mtrr_ops *mtrr_if;
14495
14496diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14497index df5e41f..816c719 100644
14498--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14499+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14500@@ -25,7 +25,7 @@ struct mtrr_ops {
14501 int (*validate_add_page)(unsigned long base, unsigned long size,
14502 unsigned int type);
14503 int (*have_wrcomb)(void);
14504-};
14505+} __do_const;
14506
14507 extern int generic_get_free_region(unsigned long base, unsigned long size,
14508 int replace_reg);
14509diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14510index 915b876..171f845 100644
14511--- a/arch/x86/kernel/cpu/perf_event.c
14512+++ b/arch/x86/kernel/cpu/perf_event.c
14513@@ -1757,7 +1757,7 @@ static unsigned long get_segment_base(unsigned int segment)
14514 if (idx > GDT_ENTRIES)
14515 return 0;
14516
14517- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14518+ desc = get_cpu_gdt_table(smp_processor_id());
14519 }
14520
14521 return get_desc_base(desc + idx);
14522@@ -1847,7 +1847,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14523 break;
14524
14525 perf_callchain_store(entry, frame.return_address);
14526- fp = frame.next_frame;
14527+ fp = (const void __force_user *)frame.next_frame;
14528 }
14529 }
14530
14531diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14532index 6bca492..36e4496 100644
14533--- a/arch/x86/kernel/cpu/perf_event_intel.c
14534+++ b/arch/x86/kernel/cpu/perf_event_intel.c
14535@@ -1947,10 +1947,10 @@ __init int intel_pmu_init(void)
14536 * v2 and above have a perf capabilities MSR
14537 */
14538 if (version > 1) {
14539- u64 capabilities;
14540+ u64 capabilities = x86_pmu.intel_cap.capabilities;
14541
14542- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14543- x86_pmu.intel_cap.capabilities = capabilities;
14544+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14545+ x86_pmu.intel_cap.capabilities = capabilities;
14546 }
14547
14548 intel_ds_init();
14549diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14550index 13ad899..f642b9a 100644
14551--- a/arch/x86/kernel/crash.c
14552+++ b/arch/x86/kernel/crash.c
14553@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14554 {
14555 #ifdef CONFIG_X86_32
14556 struct pt_regs fixed_regs;
14557-#endif
14558
14559-#ifdef CONFIG_X86_32
14560- if (!user_mode_vm(regs)) {
14561+ if (!user_mode(regs)) {
14562 crash_fixup_ss_esp(&fixed_regs, regs);
14563 regs = &fixed_regs;
14564 }
14565diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14566index 37250fe..bf2ec74 100644
14567--- a/arch/x86/kernel/doublefault_32.c
14568+++ b/arch/x86/kernel/doublefault_32.c
14569@@ -11,7 +11,7 @@
14570
14571 #define DOUBLEFAULT_STACKSIZE (1024)
14572 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14573-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14574+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14575
14576 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14577
14578@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14579 unsigned long gdt, tss;
14580
14581 store_gdt(&gdt_desc);
14582- gdt = gdt_desc.address;
14583+ gdt = (unsigned long)gdt_desc.address;
14584
14585 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14586
14587@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14588 /* 0x2 bit is always set */
14589 .flags = X86_EFLAGS_SF | 0x2,
14590 .sp = STACK_START,
14591- .es = __USER_DS,
14592+ .es = __KERNEL_DS,
14593 .cs = __KERNEL_CS,
14594 .ss = __KERNEL_DS,
14595- .ds = __USER_DS,
14596+ .ds = __KERNEL_DS,
14597 .fs = __KERNEL_PERCPU,
14598
14599 .__cr3 = __pa_nodebug(swapper_pg_dir),
14600diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14601index ae42418b..787c16b 100644
14602--- a/arch/x86/kernel/dumpstack.c
14603+++ b/arch/x86/kernel/dumpstack.c
14604@@ -2,6 +2,9 @@
14605 * Copyright (C) 1991, 1992 Linus Torvalds
14606 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14607 */
14608+#ifdef CONFIG_GRKERNSEC_HIDESYM
14609+#define __INCLUDED_BY_HIDESYM 1
14610+#endif
14611 #include <linux/kallsyms.h>
14612 #include <linux/kprobes.h>
14613 #include <linux/uaccess.h>
14614@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14615 static void
14616 print_ftrace_graph_addr(unsigned long addr, void *data,
14617 const struct stacktrace_ops *ops,
14618- struct thread_info *tinfo, int *graph)
14619+ struct task_struct *task, int *graph)
14620 {
14621- struct task_struct *task;
14622 unsigned long ret_addr;
14623 int index;
14624
14625 if (addr != (unsigned long)return_to_handler)
14626 return;
14627
14628- task = tinfo->task;
14629 index = task->curr_ret_stack;
14630
14631 if (!task->ret_stack || index < *graph)
14632@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14633 static inline void
14634 print_ftrace_graph_addr(unsigned long addr, void *data,
14635 const struct stacktrace_ops *ops,
14636- struct thread_info *tinfo, int *graph)
14637+ struct task_struct *task, int *graph)
14638 { }
14639 #endif
14640
14641@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14642 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14643 */
14644
14645-static inline int valid_stack_ptr(struct thread_info *tinfo,
14646- void *p, unsigned int size, void *end)
14647+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14648 {
14649- void *t = tinfo;
14650 if (end) {
14651 if (p < end && p >= (end-THREAD_SIZE))
14652 return 1;
14653@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14654 }
14655
14656 unsigned long
14657-print_context_stack(struct thread_info *tinfo,
14658+print_context_stack(struct task_struct *task, void *stack_start,
14659 unsigned long *stack, unsigned long bp,
14660 const struct stacktrace_ops *ops, void *data,
14661 unsigned long *end, int *graph)
14662 {
14663 struct stack_frame *frame = (struct stack_frame *)bp;
14664
14665- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14666+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14667 unsigned long addr;
14668
14669 addr = *stack;
14670@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14671 } else {
14672 ops->address(data, addr, 0);
14673 }
14674- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14675+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14676 }
14677 stack++;
14678 }
14679@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14680 EXPORT_SYMBOL_GPL(print_context_stack);
14681
14682 unsigned long
14683-print_context_stack_bp(struct thread_info *tinfo,
14684+print_context_stack_bp(struct task_struct *task, void *stack_start,
14685 unsigned long *stack, unsigned long bp,
14686 const struct stacktrace_ops *ops, void *data,
14687 unsigned long *end, int *graph)
14688@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14689 struct stack_frame *frame = (struct stack_frame *)bp;
14690 unsigned long *ret_addr = &frame->return_address;
14691
14692- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14693+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14694 unsigned long addr = *ret_addr;
14695
14696 if (!__kernel_text_address(addr))
14697@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14698 ops->address(data, addr, 1);
14699 frame = frame->next_frame;
14700 ret_addr = &frame->return_address;
14701- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14702+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14703 }
14704
14705 return (unsigned long)frame;
14706@@ -189,7 +188,7 @@ void dump_stack(void)
14707
14708 bp = stack_frame(current, NULL);
14709 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14710- current->pid, current->comm, print_tainted(),
14711+ task_pid_nr(current), current->comm, print_tainted(),
14712 init_utsname()->release,
14713 (int)strcspn(init_utsname()->version, " "),
14714 init_utsname()->version);
14715@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14716 }
14717 EXPORT_SYMBOL_GPL(oops_begin);
14718
14719+extern void gr_handle_kernel_exploit(void);
14720+
14721 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14722 {
14723 if (regs && kexec_should_crash(current))
14724@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14725 panic("Fatal exception in interrupt");
14726 if (panic_on_oops)
14727 panic("Fatal exception");
14728- do_exit(signr);
14729+
14730+ gr_handle_kernel_exploit();
14731+
14732+ do_group_exit(signr);
14733 }
14734
14735 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14736@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14737 print_modules();
14738 show_regs(regs);
14739 #ifdef CONFIG_X86_32
14740- if (user_mode_vm(regs)) {
14741+ if (user_mode(regs)) {
14742 sp = regs->sp;
14743 ss = regs->ss & 0xffff;
14744 } else {
14745@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14746 unsigned long flags = oops_begin();
14747 int sig = SIGSEGV;
14748
14749- if (!user_mode_vm(regs))
14750+ if (!user_mode(regs))
14751 report_bug(regs->ip, regs);
14752
14753 if (__die(str, regs, err))
14754diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14755index 1038a41..ac7e5f6 100644
14756--- a/arch/x86/kernel/dumpstack_32.c
14757+++ b/arch/x86/kernel/dumpstack_32.c
14758@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14759 bp = stack_frame(task, regs);
14760
14761 for (;;) {
14762- struct thread_info *context;
14763+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14764
14765- context = (struct thread_info *)
14766- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14767- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14768+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14769
14770- stack = (unsigned long *)context->previous_esp;
14771- if (!stack)
14772+ if (stack_start == task_stack_page(task))
14773 break;
14774+ stack = *(unsigned long **)stack_start;
14775 if (ops->stack(data, "IRQ") < 0)
14776 break;
14777 touch_nmi_watchdog();
14778@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14779 {
14780 int i;
14781
14782- __show_regs(regs, !user_mode_vm(regs));
14783+ __show_regs(regs, !user_mode(regs));
14784
14785 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14786 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14787@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14788 * When in-kernel, we also print out the stack and code at the
14789 * time of the fault..
14790 */
14791- if (!user_mode_vm(regs)) {
14792+ if (!user_mode(regs)) {
14793 unsigned int code_prologue = code_bytes * 43 / 64;
14794 unsigned int code_len = code_bytes;
14795 unsigned char c;
14796 u8 *ip;
14797+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14798
14799 pr_emerg("Stack:\n");
14800 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14801
14802 pr_emerg("Code:");
14803
14804- ip = (u8 *)regs->ip - code_prologue;
14805+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14806 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14807 /* try starting at IP */
14808- ip = (u8 *)regs->ip;
14809+ ip = (u8 *)regs->ip + cs_base;
14810 code_len = code_len - code_prologue + 1;
14811 }
14812 for (i = 0; i < code_len; i++, ip++) {
14813@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14814 pr_cont(" Bad EIP value.");
14815 break;
14816 }
14817- if (ip == (u8 *)regs->ip)
14818+ if (ip == (u8 *)regs->ip + cs_base)
14819 pr_cont(" <%02x>", c);
14820 else
14821 pr_cont(" %02x", c);
14822@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14823 {
14824 unsigned short ud2;
14825
14826+ ip = ktla_ktva(ip);
14827 if (ip < PAGE_OFFSET)
14828 return 0;
14829 if (probe_kernel_address((unsigned short *)ip, ud2))
14830@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14831
14832 return ud2 == 0x0b0f;
14833 }
14834+
14835+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14836+void pax_check_alloca(unsigned long size)
14837+{
14838+ unsigned long sp = (unsigned long)&sp, stack_left;
14839+
14840+ /* all kernel stacks are of the same size */
14841+ stack_left = sp & (THREAD_SIZE - 1);
14842+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14843+}
14844+EXPORT_SYMBOL(pax_check_alloca);
14845+#endif
14846diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14847index b653675..33190c0 100644
14848--- a/arch/x86/kernel/dumpstack_64.c
14849+++ b/arch/x86/kernel/dumpstack_64.c
14850@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14851 unsigned long *irq_stack_end =
14852 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14853 unsigned used = 0;
14854- struct thread_info *tinfo;
14855 int graph = 0;
14856 unsigned long dummy;
14857+ void *stack_start;
14858
14859 if (!task)
14860 task = current;
14861@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14862 * current stack address. If the stacks consist of nested
14863 * exceptions
14864 */
14865- tinfo = task_thread_info(task);
14866 for (;;) {
14867 char *id;
14868 unsigned long *estack_end;
14869+
14870 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14871 &used, &id);
14872
14873@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14874 if (ops->stack(data, id) < 0)
14875 break;
14876
14877- bp = ops->walk_stack(tinfo, stack, bp, ops,
14878+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14879 data, estack_end, &graph);
14880 ops->stack(data, "<EOE>");
14881 /*
14882@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14883 * second-to-last pointer (index -2 to end) in the
14884 * exception stack:
14885 */
14886+ if ((u16)estack_end[-1] != __KERNEL_DS)
14887+ goto out;
14888 stack = (unsigned long *) estack_end[-2];
14889 continue;
14890 }
14891@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14892 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14893 if (ops->stack(data, "IRQ") < 0)
14894 break;
14895- bp = ops->walk_stack(tinfo, stack, bp,
14896+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14897 ops, data, irq_stack_end, &graph);
14898 /*
14899 * We link to the next stack (which would be
14900@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14901 /*
14902 * This handles the process stack:
14903 */
14904- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14905+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14906+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14907+out:
14908 put_cpu();
14909 }
14910 EXPORT_SYMBOL(dump_trace);
14911@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14912
14913 return ud2 == 0x0b0f;
14914 }
14915+
14916+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14917+void pax_check_alloca(unsigned long size)
14918+{
14919+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14920+ unsigned cpu, used;
14921+ char *id;
14922+
14923+ /* check the process stack first */
14924+ stack_start = (unsigned long)task_stack_page(current);
14925+ stack_end = stack_start + THREAD_SIZE;
14926+ if (likely(stack_start <= sp && sp < stack_end)) {
14927+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14928+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14929+ return;
14930+ }
14931+
14932+ cpu = get_cpu();
14933+
14934+ /* check the irq stacks */
14935+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14936+ stack_start = stack_end - IRQ_STACK_SIZE;
14937+ if (stack_start <= sp && sp < stack_end) {
14938+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14939+ put_cpu();
14940+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14941+ return;
14942+ }
14943+
14944+ /* check the exception stacks */
14945+ used = 0;
14946+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14947+ stack_start = stack_end - EXCEPTION_STKSZ;
14948+ if (stack_end && stack_start <= sp && sp < stack_end) {
14949+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14950+ put_cpu();
14951+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14952+ return;
14953+ }
14954+
14955+ put_cpu();
14956+
14957+ /* unknown stack */
14958+ BUG();
14959+}
14960+EXPORT_SYMBOL(pax_check_alloca);
14961+#endif
14962diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14963index 9b9f18b..9fcaa04 100644
14964--- a/arch/x86/kernel/early_printk.c
14965+++ b/arch/x86/kernel/early_printk.c
14966@@ -7,6 +7,7 @@
14967 #include <linux/pci_regs.h>
14968 #include <linux/pci_ids.h>
14969 #include <linux/errno.h>
14970+#include <linux/sched.h>
14971 #include <asm/io.h>
14972 #include <asm/processor.h>
14973 #include <asm/fcntl.h>
14974diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14975index 623f288..8bdd78a 100644
14976--- a/arch/x86/kernel/entry_32.S
14977+++ b/arch/x86/kernel/entry_32.S
14978@@ -176,13 +176,153 @@
14979 /*CFI_REL_OFFSET gs, PT_GS*/
14980 .endm
14981 .macro SET_KERNEL_GS reg
14982+
14983+#ifdef CONFIG_CC_STACKPROTECTOR
14984 movl $(__KERNEL_STACK_CANARY), \reg
14985+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14986+ movl $(__USER_DS), \reg
14987+#else
14988+ xorl \reg, \reg
14989+#endif
14990+
14991 movl \reg, %gs
14992 .endm
14993
14994 #endif /* CONFIG_X86_32_LAZY_GS */
14995
14996-.macro SAVE_ALL
14997+.macro pax_enter_kernel
14998+#ifdef CONFIG_PAX_KERNEXEC
14999+ call pax_enter_kernel
15000+#endif
15001+.endm
15002+
15003+.macro pax_exit_kernel
15004+#ifdef CONFIG_PAX_KERNEXEC
15005+ call pax_exit_kernel
15006+#endif
15007+.endm
15008+
15009+#ifdef CONFIG_PAX_KERNEXEC
15010+ENTRY(pax_enter_kernel)
15011+#ifdef CONFIG_PARAVIRT
15012+ pushl %eax
15013+ pushl %ecx
15014+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15015+ mov %eax, %esi
15016+#else
15017+ mov %cr0, %esi
15018+#endif
15019+ bts $16, %esi
15020+ jnc 1f
15021+ mov %cs, %esi
15022+ cmp $__KERNEL_CS, %esi
15023+ jz 3f
15024+ ljmp $__KERNEL_CS, $3f
15025+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15026+2:
15027+#ifdef CONFIG_PARAVIRT
15028+ mov %esi, %eax
15029+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15030+#else
15031+ mov %esi, %cr0
15032+#endif
15033+3:
15034+#ifdef CONFIG_PARAVIRT
15035+ popl %ecx
15036+ popl %eax
15037+#endif
15038+ ret
15039+ENDPROC(pax_enter_kernel)
15040+
15041+ENTRY(pax_exit_kernel)
15042+#ifdef CONFIG_PARAVIRT
15043+ pushl %eax
15044+ pushl %ecx
15045+#endif
15046+ mov %cs, %esi
15047+ cmp $__KERNEXEC_KERNEL_CS, %esi
15048+ jnz 2f
15049+#ifdef CONFIG_PARAVIRT
15050+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15051+ mov %eax, %esi
15052+#else
15053+ mov %cr0, %esi
15054+#endif
15055+ btr $16, %esi
15056+ ljmp $__KERNEL_CS, $1f
15057+1:
15058+#ifdef CONFIG_PARAVIRT
15059+ mov %esi, %eax
15060+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15061+#else
15062+ mov %esi, %cr0
15063+#endif
15064+2:
15065+#ifdef CONFIG_PARAVIRT
15066+ popl %ecx
15067+ popl %eax
15068+#endif
15069+ ret
15070+ENDPROC(pax_exit_kernel)
15071+#endif
15072+
15073+.macro pax_erase_kstack
15074+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15075+ call pax_erase_kstack
15076+#endif
15077+.endm
15078+
15079+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15080+/*
15081+ * ebp: thread_info
15082+ */
15083+ENTRY(pax_erase_kstack)
15084+ pushl %edi
15085+ pushl %ecx
15086+ pushl %eax
15087+
15088+ mov TI_lowest_stack(%ebp), %edi
15089+ mov $-0xBEEF, %eax
15090+ std
15091+
15092+1: mov %edi, %ecx
15093+ and $THREAD_SIZE_asm - 1, %ecx
15094+ shr $2, %ecx
15095+ repne scasl
15096+ jecxz 2f
15097+
15098+ cmp $2*16, %ecx
15099+ jc 2f
15100+
15101+ mov $2*16, %ecx
15102+ repe scasl
15103+ jecxz 2f
15104+ jne 1b
15105+
15106+2: cld
15107+ mov %esp, %ecx
15108+ sub %edi, %ecx
15109+
15110+ cmp $THREAD_SIZE_asm, %ecx
15111+ jb 3f
15112+ ud2
15113+3:
15114+
15115+ shr $2, %ecx
15116+ rep stosl
15117+
15118+ mov TI_task_thread_sp0(%ebp), %edi
15119+ sub $128, %edi
15120+ mov %edi, TI_lowest_stack(%ebp)
15121+
15122+ popl %eax
15123+ popl %ecx
15124+ popl %edi
15125+ ret
15126+ENDPROC(pax_erase_kstack)
15127+#endif
15128+
15129+.macro __SAVE_ALL _DS
15130 cld
15131 PUSH_GS
15132 pushl_cfi %fs
15133@@ -205,7 +345,7 @@
15134 CFI_REL_OFFSET ecx, 0
15135 pushl_cfi %ebx
15136 CFI_REL_OFFSET ebx, 0
15137- movl $(__USER_DS), %edx
15138+ movl $\_DS, %edx
15139 movl %edx, %ds
15140 movl %edx, %es
15141 movl $(__KERNEL_PERCPU), %edx
15142@@ -213,6 +353,15 @@
15143 SET_KERNEL_GS %edx
15144 .endm
15145
15146+.macro SAVE_ALL
15147+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15148+ __SAVE_ALL __KERNEL_DS
15149+ pax_enter_kernel
15150+#else
15151+ __SAVE_ALL __USER_DS
15152+#endif
15153+.endm
15154+
15155 .macro RESTORE_INT_REGS
15156 popl_cfi %ebx
15157 CFI_RESTORE ebx
15158@@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15159 popfl_cfi
15160 jmp syscall_exit
15161 CFI_ENDPROC
15162-END(ret_from_fork)
15163+ENDPROC(ret_from_fork)
15164
15165 /*
15166 * Interrupt exit functions should be protected against kprobes
15167@@ -329,7 +478,15 @@ ret_from_intr:
15168 andl $SEGMENT_RPL_MASK, %eax
15169 #endif
15170 cmpl $USER_RPL, %eax
15171+
15172+#ifdef CONFIG_PAX_KERNEXEC
15173+ jae resume_userspace
15174+
15175+ pax_exit_kernel
15176+ jmp resume_kernel
15177+#else
15178 jb resume_kernel # not returning to v8086 or userspace
15179+#endif
15180
15181 ENTRY(resume_userspace)
15182 LOCKDEP_SYS_EXIT
15183@@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15184 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15185 # int/exception return?
15186 jne work_pending
15187- jmp restore_all
15188-END(ret_from_exception)
15189+ jmp restore_all_pax
15190+ENDPROC(ret_from_exception)
15191
15192 #ifdef CONFIG_PREEMPT
15193 ENTRY(resume_kernel)
15194@@ -357,7 +514,7 @@ need_resched:
15195 jz restore_all
15196 call preempt_schedule_irq
15197 jmp need_resched
15198-END(resume_kernel)
15199+ENDPROC(resume_kernel)
15200 #endif
15201 CFI_ENDPROC
15202 /*
15203@@ -391,28 +548,43 @@ sysenter_past_esp:
15204 /*CFI_REL_OFFSET cs, 0*/
15205 /*
15206 * Push current_thread_info()->sysenter_return to the stack.
15207- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15208- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15209 */
15210- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15211+ pushl_cfi $0
15212 CFI_REL_OFFSET eip, 0
15213
15214 pushl_cfi %eax
15215 SAVE_ALL
15216+ GET_THREAD_INFO(%ebp)
15217+ movl TI_sysenter_return(%ebp),%ebp
15218+ movl %ebp,PT_EIP(%esp)
15219 ENABLE_INTERRUPTS(CLBR_NONE)
15220
15221 /*
15222 * Load the potential sixth argument from user stack.
15223 * Careful about security.
15224 */
15225+ movl PT_OLDESP(%esp),%ebp
15226+
15227+#ifdef CONFIG_PAX_MEMORY_UDEREF
15228+ mov PT_OLDSS(%esp),%ds
15229+1: movl %ds:(%ebp),%ebp
15230+ push %ss
15231+ pop %ds
15232+#else
15233 cmpl $__PAGE_OFFSET-3,%ebp
15234 jae syscall_fault
15235 1: movl (%ebp),%ebp
15236+#endif
15237+
15238 movl %ebp,PT_EBP(%esp)
15239 _ASM_EXTABLE(1b,syscall_fault)
15240
15241 GET_THREAD_INFO(%ebp)
15242
15243+#ifdef CONFIG_PAX_RANDKSTACK
15244+ pax_erase_kstack
15245+#endif
15246+
15247 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15248 jnz sysenter_audit
15249 sysenter_do_call:
15250@@ -427,12 +599,24 @@ sysenter_do_call:
15251 testl $_TIF_ALLWORK_MASK, %ecx
15252 jne sysexit_audit
15253 sysenter_exit:
15254+
15255+#ifdef CONFIG_PAX_RANDKSTACK
15256+ pushl_cfi %eax
15257+ movl %esp, %eax
15258+ call pax_randomize_kstack
15259+ popl_cfi %eax
15260+#endif
15261+
15262+ pax_erase_kstack
15263+
15264 /* if something modifies registers it must also disable sysexit */
15265 movl PT_EIP(%esp), %edx
15266 movl PT_OLDESP(%esp), %ecx
15267 xorl %ebp,%ebp
15268 TRACE_IRQS_ON
15269 1: mov PT_FS(%esp), %fs
15270+2: mov PT_DS(%esp), %ds
15271+3: mov PT_ES(%esp), %es
15272 PTGS_TO_GS
15273 ENABLE_INTERRUPTS_SYSEXIT
15274
15275@@ -449,6 +633,9 @@ sysenter_audit:
15276 movl %eax,%edx /* 2nd arg: syscall number */
15277 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15278 call __audit_syscall_entry
15279+
15280+ pax_erase_kstack
15281+
15282 pushl_cfi %ebx
15283 movl PT_EAX(%esp),%eax /* reload syscall number */
15284 jmp sysenter_do_call
15285@@ -474,10 +661,16 @@ sysexit_audit:
15286
15287 CFI_ENDPROC
15288 .pushsection .fixup,"ax"
15289-2: movl $0,PT_FS(%esp)
15290+4: movl $0,PT_FS(%esp)
15291+ jmp 1b
15292+5: movl $0,PT_DS(%esp)
15293+ jmp 1b
15294+6: movl $0,PT_ES(%esp)
15295 jmp 1b
15296 .popsection
15297- _ASM_EXTABLE(1b,2b)
15298+ _ASM_EXTABLE(1b,4b)
15299+ _ASM_EXTABLE(2b,5b)
15300+ _ASM_EXTABLE(3b,6b)
15301 PTGS_TO_GS_EX
15302 ENDPROC(ia32_sysenter_target)
15303
15304@@ -491,6 +684,11 @@ ENTRY(system_call)
15305 pushl_cfi %eax # save orig_eax
15306 SAVE_ALL
15307 GET_THREAD_INFO(%ebp)
15308+
15309+#ifdef CONFIG_PAX_RANDKSTACK
15310+ pax_erase_kstack
15311+#endif
15312+
15313 # system call tracing in operation / emulation
15314 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15315 jnz syscall_trace_entry
15316@@ -509,6 +707,15 @@ syscall_exit:
15317 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15318 jne syscall_exit_work
15319
15320+restore_all_pax:
15321+
15322+#ifdef CONFIG_PAX_RANDKSTACK
15323+ movl %esp, %eax
15324+ call pax_randomize_kstack
15325+#endif
15326+
15327+ pax_erase_kstack
15328+
15329 restore_all:
15330 TRACE_IRQS_IRET
15331 restore_all_notrace:
15332@@ -565,14 +772,34 @@ ldt_ss:
15333 * compensating for the offset by changing to the ESPFIX segment with
15334 * a base address that matches for the difference.
15335 */
15336-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15337+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15338 mov %esp, %edx /* load kernel esp */
15339 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15340 mov %dx, %ax /* eax: new kernel esp */
15341 sub %eax, %edx /* offset (low word is 0) */
15342+#ifdef CONFIG_SMP
15343+ movl PER_CPU_VAR(cpu_number), %ebx
15344+ shll $PAGE_SHIFT_asm, %ebx
15345+ addl $cpu_gdt_table, %ebx
15346+#else
15347+ movl $cpu_gdt_table, %ebx
15348+#endif
15349 shr $16, %edx
15350- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15351- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15352+
15353+#ifdef CONFIG_PAX_KERNEXEC
15354+ mov %cr0, %esi
15355+ btr $16, %esi
15356+ mov %esi, %cr0
15357+#endif
15358+
15359+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15360+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15361+
15362+#ifdef CONFIG_PAX_KERNEXEC
15363+ bts $16, %esi
15364+ mov %esi, %cr0
15365+#endif
15366+
15367 pushl_cfi $__ESPFIX_SS
15368 pushl_cfi %eax /* new kernel esp */
15369 /* Disable interrupts, but do not irqtrace this section: we
15370@@ -601,35 +828,23 @@ work_resched:
15371 movl TI_flags(%ebp), %ecx
15372 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15373 # than syscall tracing?
15374- jz restore_all
15375+ jz restore_all_pax
15376 testb $_TIF_NEED_RESCHED, %cl
15377 jnz work_resched
15378
15379 work_notifysig: # deal with pending signals and
15380 # notify-resume requests
15381+ movl %esp, %eax
15382 #ifdef CONFIG_VM86
15383 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15384- movl %esp, %eax
15385- jne work_notifysig_v86 # returning to kernel-space or
15386+ jz 1f # returning to kernel-space or
15387 # vm86-space
15388- TRACE_IRQS_ON
15389- ENABLE_INTERRUPTS(CLBR_NONE)
15390- movb PT_CS(%esp), %bl
15391- andb $SEGMENT_RPL_MASK, %bl
15392- cmpb $USER_RPL, %bl
15393- jb resume_kernel
15394- xorl %edx, %edx
15395- call do_notify_resume
15396- jmp resume_userspace
15397
15398- ALIGN
15399-work_notifysig_v86:
15400 pushl_cfi %ecx # save ti_flags for do_notify_resume
15401 call save_v86_state # %eax contains pt_regs pointer
15402 popl_cfi %ecx
15403 movl %eax, %esp
15404-#else
15405- movl %esp, %eax
15406+1:
15407 #endif
15408 TRACE_IRQS_ON
15409 ENABLE_INTERRUPTS(CLBR_NONE)
15410@@ -640,7 +855,7 @@ work_notifysig_v86:
15411 xorl %edx, %edx
15412 call do_notify_resume
15413 jmp resume_userspace
15414-END(work_pending)
15415+ENDPROC(work_pending)
15416
15417 # perform syscall exit tracing
15418 ALIGN
15419@@ -648,11 +863,14 @@ syscall_trace_entry:
15420 movl $-ENOSYS,PT_EAX(%esp)
15421 movl %esp, %eax
15422 call syscall_trace_enter
15423+
15424+ pax_erase_kstack
15425+
15426 /* What it returned is what we'll actually use. */
15427 cmpl $(NR_syscalls), %eax
15428 jnae syscall_call
15429 jmp syscall_exit
15430-END(syscall_trace_entry)
15431+ENDPROC(syscall_trace_entry)
15432
15433 # perform syscall exit tracing
15434 ALIGN
15435@@ -665,20 +883,24 @@ syscall_exit_work:
15436 movl %esp, %eax
15437 call syscall_trace_leave
15438 jmp resume_userspace
15439-END(syscall_exit_work)
15440+ENDPROC(syscall_exit_work)
15441 CFI_ENDPROC
15442
15443 RING0_INT_FRAME # can't unwind into user space anyway
15444 syscall_fault:
15445+#ifdef CONFIG_PAX_MEMORY_UDEREF
15446+ push %ss
15447+ pop %ds
15448+#endif
15449 GET_THREAD_INFO(%ebp)
15450 movl $-EFAULT,PT_EAX(%esp)
15451 jmp resume_userspace
15452-END(syscall_fault)
15453+ENDPROC(syscall_fault)
15454
15455 syscall_badsys:
15456 movl $-ENOSYS,PT_EAX(%esp)
15457 jmp resume_userspace
15458-END(syscall_badsys)
15459+ENDPROC(syscall_badsys)
15460 CFI_ENDPROC
15461 /*
15462 * End of kprobes section
15463@@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15464 CFI_ENDPROC
15465 ENDPROC(ptregs_clone)
15466
15467+ ALIGN;
15468+ENTRY(kernel_execve)
15469+ CFI_STARTPROC
15470+ pushl_cfi %ebp
15471+ sub $PT_OLDSS+4,%esp
15472+ pushl_cfi %edi
15473+ pushl_cfi %ecx
15474+ pushl_cfi %eax
15475+ lea 3*4(%esp),%edi
15476+ mov $PT_OLDSS/4+1,%ecx
15477+ xorl %eax,%eax
15478+ rep stosl
15479+ popl_cfi %eax
15480+ popl_cfi %ecx
15481+ popl_cfi %edi
15482+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15483+ pushl_cfi %esp
15484+ call sys_execve
15485+ add $4,%esp
15486+ CFI_ADJUST_CFA_OFFSET -4
15487+ GET_THREAD_INFO(%ebp)
15488+ test %eax,%eax
15489+ jz syscall_exit
15490+ add $PT_OLDSS+4,%esp
15491+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15492+ popl_cfi %ebp
15493+ ret
15494+ CFI_ENDPROC
15495+ENDPROC(kernel_execve)
15496+
15497 .macro FIXUP_ESPFIX_STACK
15498 /*
15499 * Switch back for ESPFIX stack to the normal zerobased stack
15500@@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15501 * normal stack and adjusts ESP with the matching offset.
15502 */
15503 /* fixup the stack */
15504- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15505- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15506+#ifdef CONFIG_SMP
15507+ movl PER_CPU_VAR(cpu_number), %ebx
15508+ shll $PAGE_SHIFT_asm, %ebx
15509+ addl $cpu_gdt_table, %ebx
15510+#else
15511+ movl $cpu_gdt_table, %ebx
15512+#endif
15513+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15514+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15515 shl $16, %eax
15516 addl %esp, %eax /* the adjusted stack pointer */
15517 pushl_cfi $__KERNEL_DS
15518@@ -813,7 +1072,7 @@ vector=vector+1
15519 .endr
15520 2: jmp common_interrupt
15521 .endr
15522-END(irq_entries_start)
15523+ENDPROC(irq_entries_start)
15524
15525 .previous
15526 END(interrupt)
15527@@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15528 pushl_cfi $do_coprocessor_error
15529 jmp error_code
15530 CFI_ENDPROC
15531-END(coprocessor_error)
15532+ENDPROC(coprocessor_error)
15533
15534 ENTRY(simd_coprocessor_error)
15535 RING0_INT_FRAME
15536@@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15537 #endif
15538 jmp error_code
15539 CFI_ENDPROC
15540-END(simd_coprocessor_error)
15541+ENDPROC(simd_coprocessor_error)
15542
15543 ENTRY(device_not_available)
15544 RING0_INT_FRAME
15545@@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15546 pushl_cfi $do_device_not_available
15547 jmp error_code
15548 CFI_ENDPROC
15549-END(device_not_available)
15550+ENDPROC(device_not_available)
15551
15552 #ifdef CONFIG_PARAVIRT
15553 ENTRY(native_iret)
15554 iret
15555 _ASM_EXTABLE(native_iret, iret_exc)
15556-END(native_iret)
15557+ENDPROC(native_iret)
15558
15559 ENTRY(native_irq_enable_sysexit)
15560 sti
15561 sysexit
15562-END(native_irq_enable_sysexit)
15563+ENDPROC(native_irq_enable_sysexit)
15564 #endif
15565
15566 ENTRY(overflow)
15567@@ -910,7 +1169,7 @@ ENTRY(overflow)
15568 pushl_cfi $do_overflow
15569 jmp error_code
15570 CFI_ENDPROC
15571-END(overflow)
15572+ENDPROC(overflow)
15573
15574 ENTRY(bounds)
15575 RING0_INT_FRAME
15576@@ -918,7 +1177,7 @@ ENTRY(bounds)
15577 pushl_cfi $do_bounds
15578 jmp error_code
15579 CFI_ENDPROC
15580-END(bounds)
15581+ENDPROC(bounds)
15582
15583 ENTRY(invalid_op)
15584 RING0_INT_FRAME
15585@@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15586 pushl_cfi $do_invalid_op
15587 jmp error_code
15588 CFI_ENDPROC
15589-END(invalid_op)
15590+ENDPROC(invalid_op)
15591
15592 ENTRY(coprocessor_segment_overrun)
15593 RING0_INT_FRAME
15594@@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15595 pushl_cfi $do_coprocessor_segment_overrun
15596 jmp error_code
15597 CFI_ENDPROC
15598-END(coprocessor_segment_overrun)
15599+ENDPROC(coprocessor_segment_overrun)
15600
15601 ENTRY(invalid_TSS)
15602 RING0_EC_FRAME
15603 pushl_cfi $do_invalid_TSS
15604 jmp error_code
15605 CFI_ENDPROC
15606-END(invalid_TSS)
15607+ENDPROC(invalid_TSS)
15608
15609 ENTRY(segment_not_present)
15610 RING0_EC_FRAME
15611 pushl_cfi $do_segment_not_present
15612 jmp error_code
15613 CFI_ENDPROC
15614-END(segment_not_present)
15615+ENDPROC(segment_not_present)
15616
15617 ENTRY(stack_segment)
15618 RING0_EC_FRAME
15619 pushl_cfi $do_stack_segment
15620 jmp error_code
15621 CFI_ENDPROC
15622-END(stack_segment)
15623+ENDPROC(stack_segment)
15624
15625 ENTRY(alignment_check)
15626 RING0_EC_FRAME
15627 pushl_cfi $do_alignment_check
15628 jmp error_code
15629 CFI_ENDPROC
15630-END(alignment_check)
15631+ENDPROC(alignment_check)
15632
15633 ENTRY(divide_error)
15634 RING0_INT_FRAME
15635@@ -970,7 +1229,7 @@ ENTRY(divide_error)
15636 pushl_cfi $do_divide_error
15637 jmp error_code
15638 CFI_ENDPROC
15639-END(divide_error)
15640+ENDPROC(divide_error)
15641
15642 #ifdef CONFIG_X86_MCE
15643 ENTRY(machine_check)
15644@@ -979,7 +1238,7 @@ ENTRY(machine_check)
15645 pushl_cfi machine_check_vector
15646 jmp error_code
15647 CFI_ENDPROC
15648-END(machine_check)
15649+ENDPROC(machine_check)
15650 #endif
15651
15652 ENTRY(spurious_interrupt_bug)
15653@@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15654 pushl_cfi $do_spurious_interrupt_bug
15655 jmp error_code
15656 CFI_ENDPROC
15657-END(spurious_interrupt_bug)
15658+ENDPROC(spurious_interrupt_bug)
15659 /*
15660 * End of kprobes section
15661 */
15662@@ -1100,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15663
15664 ENTRY(mcount)
15665 ret
15666-END(mcount)
15667+ENDPROC(mcount)
15668
15669 ENTRY(ftrace_caller)
15670 cmpl $0, function_trace_stop
15671@@ -1129,7 +1388,7 @@ ftrace_graph_call:
15672 .globl ftrace_stub
15673 ftrace_stub:
15674 ret
15675-END(ftrace_caller)
15676+ENDPROC(ftrace_caller)
15677
15678 #else /* ! CONFIG_DYNAMIC_FTRACE */
15679
15680@@ -1165,7 +1424,7 @@ trace:
15681 popl %ecx
15682 popl %eax
15683 jmp ftrace_stub
15684-END(mcount)
15685+ENDPROC(mcount)
15686 #endif /* CONFIG_DYNAMIC_FTRACE */
15687 #endif /* CONFIG_FUNCTION_TRACER */
15688
15689@@ -1186,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15690 popl %ecx
15691 popl %eax
15692 ret
15693-END(ftrace_graph_caller)
15694+ENDPROC(ftrace_graph_caller)
15695
15696 .globl return_to_handler
15697 return_to_handler:
15698@@ -1241,15 +1500,18 @@ error_code:
15699 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15700 REG_TO_PTGS %ecx
15701 SET_KERNEL_GS %ecx
15702- movl $(__USER_DS), %ecx
15703+ movl $(__KERNEL_DS), %ecx
15704 movl %ecx, %ds
15705 movl %ecx, %es
15706+
15707+ pax_enter_kernel
15708+
15709 TRACE_IRQS_OFF
15710 movl %esp,%eax # pt_regs pointer
15711 call *%edi
15712 jmp ret_from_exception
15713 CFI_ENDPROC
15714-END(page_fault)
15715+ENDPROC(page_fault)
15716
15717 /*
15718 * Debug traps and NMI can happen at the one SYSENTER instruction
15719@@ -1291,7 +1553,7 @@ debug_stack_correct:
15720 call do_debug
15721 jmp ret_from_exception
15722 CFI_ENDPROC
15723-END(debug)
15724+ENDPROC(debug)
15725
15726 /*
15727 * NMI is doubly nasty. It can happen _while_ we're handling
15728@@ -1328,6 +1590,9 @@ nmi_stack_correct:
15729 xorl %edx,%edx # zero error code
15730 movl %esp,%eax # pt_regs pointer
15731 call do_nmi
15732+
15733+ pax_exit_kernel
15734+
15735 jmp restore_all_notrace
15736 CFI_ENDPROC
15737
15738@@ -1364,12 +1629,15 @@ nmi_espfix_stack:
15739 FIXUP_ESPFIX_STACK # %eax == %esp
15740 xorl %edx,%edx # zero error code
15741 call do_nmi
15742+
15743+ pax_exit_kernel
15744+
15745 RESTORE_REGS
15746 lss 12+4(%esp), %esp # back to espfix stack
15747 CFI_ADJUST_CFA_OFFSET -24
15748 jmp irq_return
15749 CFI_ENDPROC
15750-END(nmi)
15751+ENDPROC(nmi)
15752
15753 ENTRY(int3)
15754 RING0_INT_FRAME
15755@@ -1381,14 +1649,14 @@ ENTRY(int3)
15756 call do_int3
15757 jmp ret_from_exception
15758 CFI_ENDPROC
15759-END(int3)
15760+ENDPROC(int3)
15761
15762 ENTRY(general_protection)
15763 RING0_EC_FRAME
15764 pushl_cfi $do_general_protection
15765 jmp error_code
15766 CFI_ENDPROC
15767-END(general_protection)
15768+ENDPROC(general_protection)
15769
15770 #ifdef CONFIG_KVM_GUEST
15771 ENTRY(async_page_fault)
15772@@ -1396,7 +1664,7 @@ ENTRY(async_page_fault)
15773 pushl_cfi $do_async_page_fault
15774 jmp error_code
15775 CFI_ENDPROC
15776-END(async_page_fault)
15777+ENDPROC(async_page_fault)
15778 #endif
15779
15780 /*
15781diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15782index 69babd8..4270a51 100644
15783--- a/arch/x86/kernel/entry_64.S
15784+++ b/arch/x86/kernel/entry_64.S
15785@@ -57,6 +57,8 @@
15786 #include <asm/percpu.h>
15787 #include <asm/asm.h>
15788 #include <linux/err.h>
15789+#include <asm/pgtable.h>
15790+#include <asm/alternative-asm.h>
15791
15792 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15793 #include <linux/elf-em.h>
15794@@ -70,8 +72,9 @@
15795 #ifdef CONFIG_FUNCTION_TRACER
15796 #ifdef CONFIG_DYNAMIC_FTRACE
15797 ENTRY(mcount)
15798+ pax_force_retaddr
15799 retq
15800-END(mcount)
15801+ENDPROC(mcount)
15802
15803 ENTRY(ftrace_caller)
15804 cmpl $0, function_trace_stop
15805@@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15806 #endif
15807
15808 GLOBAL(ftrace_stub)
15809+ pax_force_retaddr
15810 retq
15811-END(ftrace_caller)
15812+ENDPROC(ftrace_caller)
15813
15814 #else /* ! CONFIG_DYNAMIC_FTRACE */
15815 ENTRY(mcount)
15816@@ -114,6 +118,7 @@ ENTRY(mcount)
15817 #endif
15818
15819 GLOBAL(ftrace_stub)
15820+ pax_force_retaddr
15821 retq
15822
15823 trace:
15824@@ -123,12 +128,13 @@ trace:
15825 movq 8(%rbp), %rsi
15826 subq $MCOUNT_INSN_SIZE, %rdi
15827
15828+ pax_force_fptr ftrace_trace_function
15829 call *ftrace_trace_function
15830
15831 MCOUNT_RESTORE_FRAME
15832
15833 jmp ftrace_stub
15834-END(mcount)
15835+ENDPROC(mcount)
15836 #endif /* CONFIG_DYNAMIC_FTRACE */
15837 #endif /* CONFIG_FUNCTION_TRACER */
15838
15839@@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15840
15841 MCOUNT_RESTORE_FRAME
15842
15843+ pax_force_retaddr
15844 retq
15845-END(ftrace_graph_caller)
15846+ENDPROC(ftrace_graph_caller)
15847
15848 GLOBAL(return_to_handler)
15849 subq $24, %rsp
15850@@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15851 movq 8(%rsp), %rdx
15852 movq (%rsp), %rax
15853 addq $24, %rsp
15854+ pax_force_fptr %rdi
15855 jmp *%rdi
15856 #endif
15857
15858@@ -180,6 +188,280 @@ ENTRY(native_usergs_sysret64)
15859 ENDPROC(native_usergs_sysret64)
15860 #endif /* CONFIG_PARAVIRT */
15861
15862+ .macro ljmpq sel, off
15863+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15864+ .byte 0x48; ljmp *1234f(%rip)
15865+ .pushsection .rodata
15866+ .align 16
15867+ 1234: .quad \off; .word \sel
15868+ .popsection
15869+#else
15870+ pushq $\sel
15871+ pushq $\off
15872+ lretq
15873+#endif
15874+ .endm
15875+
15876+ .macro pax_enter_kernel
15877+ pax_set_fptr_mask
15878+#ifdef CONFIG_PAX_KERNEXEC
15879+ call pax_enter_kernel
15880+#endif
15881+ .endm
15882+
15883+ .macro pax_exit_kernel
15884+#ifdef CONFIG_PAX_KERNEXEC
15885+ call pax_exit_kernel
15886+#endif
15887+ .endm
15888+
15889+#ifdef CONFIG_PAX_KERNEXEC
15890+ENTRY(pax_enter_kernel)
15891+ pushq %rdi
15892+
15893+#ifdef CONFIG_PARAVIRT
15894+ PV_SAVE_REGS(CLBR_RDI)
15895+#endif
15896+
15897+ GET_CR0_INTO_RDI
15898+ bts $16,%rdi
15899+ jnc 3f
15900+ mov %cs,%edi
15901+ cmp $__KERNEL_CS,%edi
15902+ jnz 2f
15903+1:
15904+
15905+#ifdef CONFIG_PARAVIRT
15906+ PV_RESTORE_REGS(CLBR_RDI)
15907+#endif
15908+
15909+ popq %rdi
15910+ pax_force_retaddr
15911+ retq
15912+
15913+2: ljmpq __KERNEL_CS,1f
15914+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15915+4: SET_RDI_INTO_CR0
15916+ jmp 1b
15917+ENDPROC(pax_enter_kernel)
15918+
15919+ENTRY(pax_exit_kernel)
15920+ pushq %rdi
15921+
15922+#ifdef CONFIG_PARAVIRT
15923+ PV_SAVE_REGS(CLBR_RDI)
15924+#endif
15925+
15926+ mov %cs,%rdi
15927+ cmp $__KERNEXEC_KERNEL_CS,%edi
15928+ jz 2f
15929+1:
15930+
15931+#ifdef CONFIG_PARAVIRT
15932+ PV_RESTORE_REGS(CLBR_RDI);
15933+#endif
15934+
15935+ popq %rdi
15936+ pax_force_retaddr
15937+ retq
15938+
15939+2: GET_CR0_INTO_RDI
15940+ btr $16,%rdi
15941+ ljmpq __KERNEL_CS,3f
15942+3: SET_RDI_INTO_CR0
15943+ jmp 1b
15944+#ifdef CONFIG_PARAVIRT
15945+ PV_RESTORE_REGS(CLBR_RDI);
15946+#endif
15947+
15948+ popq %rdi
15949+ pax_force_retaddr
15950+ retq
15951+ENDPROC(pax_exit_kernel)
15952+#endif
15953+
15954+ .macro pax_enter_kernel_user
15955+ pax_set_fptr_mask
15956+#ifdef CONFIG_PAX_MEMORY_UDEREF
15957+ call pax_enter_kernel_user
15958+#endif
15959+ .endm
15960+
15961+ .macro pax_exit_kernel_user
15962+#ifdef CONFIG_PAX_MEMORY_UDEREF
15963+ call pax_exit_kernel_user
15964+#endif
15965+#ifdef CONFIG_PAX_RANDKSTACK
15966+ pushq %rax
15967+ call pax_randomize_kstack
15968+ popq %rax
15969+#endif
15970+ .endm
15971+
15972+#ifdef CONFIG_PAX_MEMORY_UDEREF
15973+ENTRY(pax_enter_kernel_user)
15974+ pushq %rdi
15975+ pushq %rbx
15976+
15977+#ifdef CONFIG_PARAVIRT
15978+ PV_SAVE_REGS(CLBR_RDI)
15979+#endif
15980+
15981+ GET_CR3_INTO_RDI
15982+ mov %rdi,%rbx
15983+ add $__START_KERNEL_map,%rbx
15984+ sub phys_base(%rip),%rbx
15985+
15986+#ifdef CONFIG_PARAVIRT
15987+ pushq %rdi
15988+ cmpl $0, pv_info+PARAVIRT_enabled
15989+ jz 1f
15990+ i = 0
15991+ .rept USER_PGD_PTRS
15992+ mov i*8(%rbx),%rsi
15993+ mov $0,%sil
15994+ lea i*8(%rbx),%rdi
15995+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15996+ i = i + 1
15997+ .endr
15998+ jmp 2f
15999+1:
16000+#endif
16001+
16002+ i = 0
16003+ .rept USER_PGD_PTRS
16004+ movb $0,i*8(%rbx)
16005+ i = i + 1
16006+ .endr
16007+
16008+#ifdef CONFIG_PARAVIRT
16009+2: popq %rdi
16010+#endif
16011+ SET_RDI_INTO_CR3
16012+
16013+#ifdef CONFIG_PAX_KERNEXEC
16014+ GET_CR0_INTO_RDI
16015+ bts $16,%rdi
16016+ SET_RDI_INTO_CR0
16017+#endif
16018+
16019+#ifdef CONFIG_PARAVIRT
16020+ PV_RESTORE_REGS(CLBR_RDI)
16021+#endif
16022+
16023+ popq %rbx
16024+ popq %rdi
16025+ pax_force_retaddr
16026+ retq
16027+ENDPROC(pax_enter_kernel_user)
16028+
16029+ENTRY(pax_exit_kernel_user)
16030+ push %rdi
16031+
16032+#ifdef CONFIG_PARAVIRT
16033+ pushq %rbx
16034+ PV_SAVE_REGS(CLBR_RDI)
16035+#endif
16036+
16037+#ifdef CONFIG_PAX_KERNEXEC
16038+ GET_CR0_INTO_RDI
16039+ btr $16,%rdi
16040+ SET_RDI_INTO_CR0
16041+#endif
16042+
16043+ GET_CR3_INTO_RDI
16044+ add $__START_KERNEL_map,%rdi
16045+ sub phys_base(%rip),%rdi
16046+
16047+#ifdef CONFIG_PARAVIRT
16048+ cmpl $0, pv_info+PARAVIRT_enabled
16049+ jz 1f
16050+ mov %rdi,%rbx
16051+ i = 0
16052+ .rept USER_PGD_PTRS
16053+ mov i*8(%rbx),%rsi
16054+ mov $0x67,%sil
16055+ lea i*8(%rbx),%rdi
16056+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16057+ i = i + 1
16058+ .endr
16059+ jmp 2f
16060+1:
16061+#endif
16062+
16063+ i = 0
16064+ .rept USER_PGD_PTRS
16065+ movb $0x67,i*8(%rdi)
16066+ i = i + 1
16067+ .endr
16068+
16069+#ifdef CONFIG_PARAVIRT
16070+2: PV_RESTORE_REGS(CLBR_RDI)
16071+ popq %rbx
16072+#endif
16073+
16074+ popq %rdi
16075+ pax_force_retaddr
16076+ retq
16077+ENDPROC(pax_exit_kernel_user)
16078+#endif
16079+
16080+.macro pax_erase_kstack
16081+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16082+ call pax_erase_kstack
16083+#endif
16084+.endm
16085+
16086+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16087+ENTRY(pax_erase_kstack)
16088+ pushq %rdi
16089+ pushq %rcx
16090+ pushq %rax
16091+ pushq %r11
16092+
16093+ GET_THREAD_INFO(%r11)
16094+ mov TI_lowest_stack(%r11), %rdi
16095+ mov $-0xBEEF, %rax
16096+ std
16097+
16098+1: mov %edi, %ecx
16099+ and $THREAD_SIZE_asm - 1, %ecx
16100+ shr $3, %ecx
16101+ repne scasq
16102+ jecxz 2f
16103+
16104+ cmp $2*8, %ecx
16105+ jc 2f
16106+
16107+ mov $2*8, %ecx
16108+ repe scasq
16109+ jecxz 2f
16110+ jne 1b
16111+
16112+2: cld
16113+ mov %esp, %ecx
16114+ sub %edi, %ecx
16115+
16116+ cmp $THREAD_SIZE_asm, %rcx
16117+ jb 3f
16118+ ud2
16119+3:
16120+
16121+ shr $3, %ecx
16122+ rep stosq
16123+
16124+ mov TI_task_thread_sp0(%r11), %rdi
16125+ sub $256, %rdi
16126+ mov %rdi, TI_lowest_stack(%r11)
16127+
16128+ popq %r11
16129+ popq %rax
16130+ popq %rcx
16131+ popq %rdi
16132+ pax_force_retaddr
16133+ ret
16134+ENDPROC(pax_erase_kstack)
16135+#endif
16136
16137 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16138 #ifdef CONFIG_TRACE_IRQFLAGS
16139@@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16140 .endm
16141
16142 .macro UNFAKE_STACK_FRAME
16143- addq $8*6, %rsp
16144- CFI_ADJUST_CFA_OFFSET -(6*8)
16145+ addq $8*6 + ARG_SKIP, %rsp
16146+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16147 .endm
16148
16149 /*
16150@@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16151 movq %rsp, %rsi
16152
16153 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16154- testl $3, CS-RBP(%rsi)
16155+ testb $3, CS-RBP(%rsi)
16156 je 1f
16157 SWAPGS
16158 /*
16159@@ -394,9 +676,10 @@ ENTRY(save_rest)
16160 movq_cfi r15, R15+16
16161 movq %r11, 8(%rsp) /* return address */
16162 FIXUP_TOP_OF_STACK %r11, 16
16163+ pax_force_retaddr
16164 ret
16165 CFI_ENDPROC
16166-END(save_rest)
16167+ENDPROC(save_rest)
16168
16169 /* save complete stack frame */
16170 .pushsection .kprobes.text, "ax"
16171@@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16172 js 1f /* negative -> in kernel */
16173 SWAPGS
16174 xorl %ebx,%ebx
16175-1: ret
16176+1: pax_force_retaddr_bts
16177+ ret
16178 CFI_ENDPROC
16179-END(save_paranoid)
16180+ENDPROC(save_paranoid)
16181 .popsection
16182
16183 /*
16184@@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16185
16186 RESTORE_REST
16187
16188- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16189+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16190 jz retint_restore_args
16191
16192 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16193@@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16194 jmp ret_from_sys_call # go to the SYSRET fastpath
16195
16196 CFI_ENDPROC
16197-END(ret_from_fork)
16198+ENDPROC(ret_from_fork)
16199
16200 /*
16201 * System call entry. Up to 6 arguments in registers are supported.
16202@@ -495,7 +779,7 @@ END(ret_from_fork)
16203 ENTRY(system_call)
16204 CFI_STARTPROC simple
16205 CFI_SIGNAL_FRAME
16206- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16207+ CFI_DEF_CFA rsp,0
16208 CFI_REGISTER rip,rcx
16209 /*CFI_REGISTER rflags,r11*/
16210 SWAPGS_UNSAFE_STACK
16211@@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16212
16213 movq %rsp,PER_CPU_VAR(old_rsp)
16214 movq PER_CPU_VAR(kernel_stack),%rsp
16215+ SAVE_ARGS 8*6,0
16216+ pax_enter_kernel_user
16217+
16218+#ifdef CONFIG_PAX_RANDKSTACK
16219+ pax_erase_kstack
16220+#endif
16221+
16222 /*
16223 * No need to follow this irqs off/on section - it's straight
16224 * and short:
16225 */
16226 ENABLE_INTERRUPTS(CLBR_NONE)
16227- SAVE_ARGS 8,0
16228 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16229 movq %rcx,RIP-ARGOFFSET(%rsp)
16230 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16231- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16232+ GET_THREAD_INFO(%rcx)
16233+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16234 jnz tracesys
16235 system_call_fastpath:
16236 #if __SYSCALL_MASK == ~0
16237@@ -527,7 +818,7 @@ system_call_fastpath:
16238 cmpl $__NR_syscall_max,%eax
16239 #endif
16240 ja badsys
16241- movq %r10,%rcx
16242+ movq R10-ARGOFFSET(%rsp),%rcx
16243 call *sys_call_table(,%rax,8) # XXX: rip relative
16244 movq %rax,RAX-ARGOFFSET(%rsp)
16245 /*
16246@@ -541,10 +832,13 @@ sysret_check:
16247 LOCKDEP_SYS_EXIT
16248 DISABLE_INTERRUPTS(CLBR_NONE)
16249 TRACE_IRQS_OFF
16250- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16251+ GET_THREAD_INFO(%rcx)
16252+ movl TI_flags(%rcx),%edx
16253 andl %edi,%edx
16254 jnz sysret_careful
16255 CFI_REMEMBER_STATE
16256+ pax_exit_kernel_user
16257+ pax_erase_kstack
16258 /*
16259 * sysretq will re-enable interrupts:
16260 */
16261@@ -596,14 +890,18 @@ badsys:
16262 * jump back to the normal fast path.
16263 */
16264 auditsys:
16265- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16266+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16267 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16268 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16269 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16270 movq %rax,%rsi /* 2nd arg: syscall number */
16271 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16272 call __audit_syscall_entry
16273+
16274+ pax_erase_kstack
16275+
16276 LOAD_ARGS 0 /* reload call-clobbered registers */
16277+ pax_set_fptr_mask
16278 jmp system_call_fastpath
16279
16280 /*
16281@@ -624,7 +922,7 @@ sysret_audit:
16282 /* Do syscall tracing */
16283 tracesys:
16284 #ifdef CONFIG_AUDITSYSCALL
16285- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16286+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16287 jz auditsys
16288 #endif
16289 SAVE_REST
16290@@ -632,12 +930,16 @@ tracesys:
16291 FIXUP_TOP_OF_STACK %rdi
16292 movq %rsp,%rdi
16293 call syscall_trace_enter
16294+
16295+ pax_erase_kstack
16296+
16297 /*
16298 * Reload arg registers from stack in case ptrace changed them.
16299 * We don't reload %rax because syscall_trace_enter() returned
16300 * the value it wants us to use in the table lookup.
16301 */
16302 LOAD_ARGS ARGOFFSET, 1
16303+ pax_set_fptr_mask
16304 RESTORE_REST
16305 #if __SYSCALL_MASK == ~0
16306 cmpq $__NR_syscall_max,%rax
16307@@ -646,7 +948,7 @@ tracesys:
16308 cmpl $__NR_syscall_max,%eax
16309 #endif
16310 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16311- movq %r10,%rcx /* fixup for C */
16312+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16313 call *sys_call_table(,%rax,8)
16314 movq %rax,RAX-ARGOFFSET(%rsp)
16315 /* Use IRET because user could have changed frame */
16316@@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16317 andl %edi,%edx
16318 jnz int_careful
16319 andl $~TS_COMPAT,TI_status(%rcx)
16320- jmp retint_swapgs
16321+ pax_exit_kernel_user
16322+ pax_erase_kstack
16323+ jmp retint_swapgs_pax
16324
16325 /* Either reschedule or signal or syscall exit tracking needed. */
16326 /* First do a reschedule test. */
16327@@ -713,7 +1017,7 @@ int_restore_rest:
16328 TRACE_IRQS_OFF
16329 jmp int_with_check
16330 CFI_ENDPROC
16331-END(system_call)
16332+ENDPROC(system_call)
16333
16334 /*
16335 * Certain special system calls that need to save a complete full stack frame.
16336@@ -729,7 +1033,7 @@ ENTRY(\label)
16337 call \func
16338 jmp ptregscall_common
16339 CFI_ENDPROC
16340-END(\label)
16341+ENDPROC(\label)
16342 .endm
16343
16344 PTREGSCALL stub_clone, sys_clone, %r8
16345@@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16346 movq_cfi_restore R12+8, r12
16347 movq_cfi_restore RBP+8, rbp
16348 movq_cfi_restore RBX+8, rbx
16349+ pax_force_retaddr
16350 ret $REST_SKIP /* pop extended registers */
16351 CFI_ENDPROC
16352-END(ptregscall_common)
16353+ENDPROC(ptregscall_common)
16354
16355 ENTRY(stub_execve)
16356 CFI_STARTPROC
16357@@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16358 RESTORE_REST
16359 jmp int_ret_from_sys_call
16360 CFI_ENDPROC
16361-END(stub_execve)
16362+ENDPROC(stub_execve)
16363
16364 /*
16365 * sigreturn is special because it needs to restore all registers on return.
16366@@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16367 RESTORE_REST
16368 jmp int_ret_from_sys_call
16369 CFI_ENDPROC
16370-END(stub_rt_sigreturn)
16371+ENDPROC(stub_rt_sigreturn)
16372
16373 #ifdef CONFIG_X86_X32_ABI
16374 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16375@@ -851,7 +1156,7 @@ vector=vector+1
16376 2: jmp common_interrupt
16377 .endr
16378 CFI_ENDPROC
16379-END(irq_entries_start)
16380+ENDPROC(irq_entries_start)
16381
16382 .previous
16383 END(interrupt)
16384@@ -871,6 +1176,16 @@ END(interrupt)
16385 subq $ORIG_RAX-RBP, %rsp
16386 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16387 SAVE_ARGS_IRQ
16388+#ifdef CONFIG_PAX_MEMORY_UDEREF
16389+ testb $3, CS(%rdi)
16390+ jnz 1f
16391+ pax_enter_kernel
16392+ jmp 2f
16393+1: pax_enter_kernel_user
16394+2:
16395+#else
16396+ pax_enter_kernel
16397+#endif
16398 call \func
16399 .endm
16400
16401@@ -902,7 +1217,7 @@ ret_from_intr:
16402
16403 exit_intr:
16404 GET_THREAD_INFO(%rcx)
16405- testl $3,CS-ARGOFFSET(%rsp)
16406+ testb $3,CS-ARGOFFSET(%rsp)
16407 je retint_kernel
16408
16409 /* Interrupt came from user space */
16410@@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16411 * The iretq could re-enable interrupts:
16412 */
16413 DISABLE_INTERRUPTS(CLBR_ANY)
16414+ pax_exit_kernel_user
16415+retint_swapgs_pax:
16416 TRACE_IRQS_IRETQ
16417 SWAPGS
16418 jmp restore_args
16419
16420 retint_restore_args: /* return to kernel space */
16421 DISABLE_INTERRUPTS(CLBR_ANY)
16422+ pax_exit_kernel
16423+ pax_force_retaddr RIP-ARGOFFSET
16424 /*
16425 * The iretq could re-enable interrupts:
16426 */
16427@@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16428 #endif
16429
16430 CFI_ENDPROC
16431-END(common_interrupt)
16432+ENDPROC(common_interrupt)
16433 /*
16434 * End of kprobes section
16435 */
16436@@ -1029,7 +1348,7 @@ ENTRY(\sym)
16437 interrupt \do_sym
16438 jmp ret_from_intr
16439 CFI_ENDPROC
16440-END(\sym)
16441+ENDPROC(\sym)
16442 .endm
16443
16444 #ifdef CONFIG_SMP
16445@@ -1084,12 +1403,22 @@ ENTRY(\sym)
16446 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16447 call error_entry
16448 DEFAULT_FRAME 0
16449+#ifdef CONFIG_PAX_MEMORY_UDEREF
16450+ testb $3, CS(%rsp)
16451+ jnz 1f
16452+ pax_enter_kernel
16453+ jmp 2f
16454+1: pax_enter_kernel_user
16455+2:
16456+#else
16457+ pax_enter_kernel
16458+#endif
16459 movq %rsp,%rdi /* pt_regs pointer */
16460 xorl %esi,%esi /* no error code */
16461 call \do_sym
16462 jmp error_exit /* %ebx: no swapgs flag */
16463 CFI_ENDPROC
16464-END(\sym)
16465+ENDPROC(\sym)
16466 .endm
16467
16468 .macro paranoidzeroentry sym do_sym
16469@@ -1101,15 +1430,25 @@ ENTRY(\sym)
16470 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16471 call save_paranoid
16472 TRACE_IRQS_OFF
16473+#ifdef CONFIG_PAX_MEMORY_UDEREF
16474+ testb $3, CS(%rsp)
16475+ jnz 1f
16476+ pax_enter_kernel
16477+ jmp 2f
16478+1: pax_enter_kernel_user
16479+2:
16480+#else
16481+ pax_enter_kernel
16482+#endif
16483 movq %rsp,%rdi /* pt_regs pointer */
16484 xorl %esi,%esi /* no error code */
16485 call \do_sym
16486 jmp paranoid_exit /* %ebx: no swapgs flag */
16487 CFI_ENDPROC
16488-END(\sym)
16489+ENDPROC(\sym)
16490 .endm
16491
16492-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16493+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16494 .macro paranoidzeroentry_ist sym do_sym ist
16495 ENTRY(\sym)
16496 INTR_FRAME
16497@@ -1119,14 +1458,30 @@ ENTRY(\sym)
16498 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16499 call save_paranoid
16500 TRACE_IRQS_OFF_DEBUG
16501+#ifdef CONFIG_PAX_MEMORY_UDEREF
16502+ testb $3, CS(%rsp)
16503+ jnz 1f
16504+ pax_enter_kernel
16505+ jmp 2f
16506+1: pax_enter_kernel_user
16507+2:
16508+#else
16509+ pax_enter_kernel
16510+#endif
16511 movq %rsp,%rdi /* pt_regs pointer */
16512 xorl %esi,%esi /* no error code */
16513+#ifdef CONFIG_SMP
16514+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16515+ lea init_tss(%r12), %r12
16516+#else
16517+ lea init_tss(%rip), %r12
16518+#endif
16519 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16520 call \do_sym
16521 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16522 jmp paranoid_exit /* %ebx: no swapgs flag */
16523 CFI_ENDPROC
16524-END(\sym)
16525+ENDPROC(\sym)
16526 .endm
16527
16528 .macro errorentry sym do_sym
16529@@ -1137,13 +1492,23 @@ ENTRY(\sym)
16530 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16531 call error_entry
16532 DEFAULT_FRAME 0
16533+#ifdef CONFIG_PAX_MEMORY_UDEREF
16534+ testb $3, CS(%rsp)
16535+ jnz 1f
16536+ pax_enter_kernel
16537+ jmp 2f
16538+1: pax_enter_kernel_user
16539+2:
16540+#else
16541+ pax_enter_kernel
16542+#endif
16543 movq %rsp,%rdi /* pt_regs pointer */
16544 movq ORIG_RAX(%rsp),%rsi /* get error code */
16545 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16546 call \do_sym
16547 jmp error_exit /* %ebx: no swapgs flag */
16548 CFI_ENDPROC
16549-END(\sym)
16550+ENDPROC(\sym)
16551 .endm
16552
16553 /* error code is on the stack already */
16554@@ -1156,13 +1521,23 @@ ENTRY(\sym)
16555 call save_paranoid
16556 DEFAULT_FRAME 0
16557 TRACE_IRQS_OFF
16558+#ifdef CONFIG_PAX_MEMORY_UDEREF
16559+ testb $3, CS(%rsp)
16560+ jnz 1f
16561+ pax_enter_kernel
16562+ jmp 2f
16563+1: pax_enter_kernel_user
16564+2:
16565+#else
16566+ pax_enter_kernel
16567+#endif
16568 movq %rsp,%rdi /* pt_regs pointer */
16569 movq ORIG_RAX(%rsp),%rsi /* get error code */
16570 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16571 call \do_sym
16572 jmp paranoid_exit /* %ebx: no swapgs flag */
16573 CFI_ENDPROC
16574-END(\sym)
16575+ENDPROC(\sym)
16576 .endm
16577
16578 zeroentry divide_error do_divide_error
16579@@ -1192,9 +1567,10 @@ gs_change:
16580 2: mfence /* workaround */
16581 SWAPGS
16582 popfq_cfi
16583+ pax_force_retaddr
16584 ret
16585 CFI_ENDPROC
16586-END(native_load_gs_index)
16587+ENDPROC(native_load_gs_index)
16588
16589 _ASM_EXTABLE(gs_change,bad_gs)
16590 .section .fixup,"ax"
16591@@ -1213,13 +1589,14 @@ ENTRY(kernel_thread_helper)
16592 * Here we are in the child and the registers are set as they were
16593 * at kernel_thread() invocation in the parent.
16594 */
16595+ pax_force_fptr %rsi
16596 call *%rsi
16597 # exit
16598 mov %eax, %edi
16599 call do_exit
16600 ud2 # padding for call trace
16601 CFI_ENDPROC
16602-END(kernel_thread_helper)
16603+ENDPROC(kernel_thread_helper)
16604
16605 /*
16606 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16607@@ -1246,11 +1623,11 @@ ENTRY(kernel_execve)
16608 RESTORE_REST
16609 testq %rax,%rax
16610 je int_ret_from_sys_call
16611- RESTORE_ARGS
16612 UNFAKE_STACK_FRAME
16613+ pax_force_retaddr
16614 ret
16615 CFI_ENDPROC
16616-END(kernel_execve)
16617+ENDPROC(kernel_execve)
16618
16619 /* Call softirq on interrupt stack. Interrupts are off. */
16620 ENTRY(call_softirq)
16621@@ -1268,9 +1645,10 @@ ENTRY(call_softirq)
16622 CFI_DEF_CFA_REGISTER rsp
16623 CFI_ADJUST_CFA_OFFSET -8
16624 decl PER_CPU_VAR(irq_count)
16625+ pax_force_retaddr
16626 ret
16627 CFI_ENDPROC
16628-END(call_softirq)
16629+ENDPROC(call_softirq)
16630
16631 #ifdef CONFIG_XEN
16632 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16633@@ -1308,7 +1686,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16634 decl PER_CPU_VAR(irq_count)
16635 jmp error_exit
16636 CFI_ENDPROC
16637-END(xen_do_hypervisor_callback)
16638+ENDPROC(xen_do_hypervisor_callback)
16639
16640 /*
16641 * Hypervisor uses this for application faults while it executes.
16642@@ -1367,7 +1745,7 @@ ENTRY(xen_failsafe_callback)
16643 SAVE_ALL
16644 jmp error_exit
16645 CFI_ENDPROC
16646-END(xen_failsafe_callback)
16647+ENDPROC(xen_failsafe_callback)
16648
16649 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16650 xen_hvm_callback_vector xen_evtchn_do_upcall
16651@@ -1416,16 +1794,31 @@ ENTRY(paranoid_exit)
16652 TRACE_IRQS_OFF_DEBUG
16653 testl %ebx,%ebx /* swapgs needed? */
16654 jnz paranoid_restore
16655- testl $3,CS(%rsp)
16656+ testb $3,CS(%rsp)
16657 jnz paranoid_userspace
16658+#ifdef CONFIG_PAX_MEMORY_UDEREF
16659+ pax_exit_kernel
16660+ TRACE_IRQS_IRETQ 0
16661+ SWAPGS_UNSAFE_STACK
16662+ RESTORE_ALL 8
16663+ pax_force_retaddr_bts
16664+ jmp irq_return
16665+#endif
16666 paranoid_swapgs:
16667+#ifdef CONFIG_PAX_MEMORY_UDEREF
16668+ pax_exit_kernel_user
16669+#else
16670+ pax_exit_kernel
16671+#endif
16672 TRACE_IRQS_IRETQ 0
16673 SWAPGS_UNSAFE_STACK
16674 RESTORE_ALL 8
16675 jmp irq_return
16676 paranoid_restore:
16677+ pax_exit_kernel
16678 TRACE_IRQS_IRETQ_DEBUG 0
16679 RESTORE_ALL 8
16680+ pax_force_retaddr_bts
16681 jmp irq_return
16682 paranoid_userspace:
16683 GET_THREAD_INFO(%rcx)
16684@@ -1454,7 +1847,7 @@ paranoid_schedule:
16685 TRACE_IRQS_OFF
16686 jmp paranoid_userspace
16687 CFI_ENDPROC
16688-END(paranoid_exit)
16689+ENDPROC(paranoid_exit)
16690
16691 /*
16692 * Exception entry point. This expects an error code/orig_rax on the stack.
16693@@ -1481,12 +1874,13 @@ ENTRY(error_entry)
16694 movq_cfi r14, R14+8
16695 movq_cfi r15, R15+8
16696 xorl %ebx,%ebx
16697- testl $3,CS+8(%rsp)
16698+ testb $3,CS+8(%rsp)
16699 je error_kernelspace
16700 error_swapgs:
16701 SWAPGS
16702 error_sti:
16703 TRACE_IRQS_OFF
16704+ pax_force_retaddr_bts
16705 ret
16706
16707 /*
16708@@ -1513,7 +1907,7 @@ bstep_iret:
16709 movq %rcx,RIP+8(%rsp)
16710 jmp error_swapgs
16711 CFI_ENDPROC
16712-END(error_entry)
16713+ENDPROC(error_entry)
16714
16715
16716 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16717@@ -1533,7 +1927,7 @@ ENTRY(error_exit)
16718 jnz retint_careful
16719 jmp retint_swapgs
16720 CFI_ENDPROC
16721-END(error_exit)
16722+ENDPROC(error_exit)
16723
16724 /*
16725 * Test if a given stack is an NMI stack or not.
16726@@ -1591,9 +1985,11 @@ ENTRY(nmi)
16727 * If %cs was not the kernel segment, then the NMI triggered in user
16728 * space, which means it is definitely not nested.
16729 */
16730+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16731+ je 1f
16732 cmpl $__KERNEL_CS, 16(%rsp)
16733 jne first_nmi
16734-
16735+1:
16736 /*
16737 * Check the special variable on the stack to see if NMIs are
16738 * executing.
16739@@ -1752,6 +2148,17 @@ end_repeat_nmi:
16740 */
16741 movq %cr2, %r12
16742
16743+#ifdef CONFIG_PAX_MEMORY_UDEREF
16744+ testb $3, CS(%rsp)
16745+ jnz 1f
16746+ pax_enter_kernel
16747+ jmp 2f
16748+1: pax_enter_kernel_user
16749+2:
16750+#else
16751+ pax_enter_kernel
16752+#endif
16753+
16754 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16755 movq %rsp,%rdi
16756 movq $-1,%rsi
16757@@ -1767,21 +2174,32 @@ end_repeat_nmi:
16758 testl %ebx,%ebx /* swapgs needed? */
16759 jnz nmi_restore
16760 nmi_swapgs:
16761+#ifdef CONFIG_PAX_MEMORY_UDEREF
16762+ pax_exit_kernel_user
16763+#else
16764+ pax_exit_kernel
16765+#endif
16766 SWAPGS_UNSAFE_STACK
16767+ RESTORE_ALL 8
16768+ /* Clear the NMI executing stack variable */
16769+ movq $0, 10*8(%rsp)
16770+ jmp irq_return
16771 nmi_restore:
16772+ pax_exit_kernel
16773 RESTORE_ALL 8
16774+ pax_force_retaddr_bts
16775 /* Clear the NMI executing stack variable */
16776 movq $0, 10*8(%rsp)
16777 jmp irq_return
16778 CFI_ENDPROC
16779-END(nmi)
16780+ENDPROC(nmi)
16781
16782 ENTRY(ignore_sysret)
16783 CFI_STARTPROC
16784 mov $-ENOSYS,%eax
16785 sysret
16786 CFI_ENDPROC
16787-END(ignore_sysret)
16788+ENDPROC(ignore_sysret)
16789
16790 /*
16791 * End of kprobes section
16792diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16793index c3a7cb4..3ad00dc 100644
16794--- a/arch/x86/kernel/ftrace.c
16795+++ b/arch/x86/kernel/ftrace.c
16796@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16797 {
16798 unsigned char replaced[MCOUNT_INSN_SIZE];
16799
16800+ ip = ktla_ktva(ip);
16801+
16802 /*
16803 * Note: Due to modules and __init, code can
16804 * disappear and change, we need to protect against faulting
16805@@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16806 unsigned char old[MCOUNT_INSN_SIZE], *new;
16807 int ret;
16808
16809- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16810+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16811 new = ftrace_call_replace(ip, (unsigned long)func);
16812
16813 /* See comment above by declaration of modifying_ftrace_code */
16814@@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16815 {
16816 unsigned char code[MCOUNT_INSN_SIZE];
16817
16818+ ip = ktla_ktva(ip);
16819+
16820 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16821 return -EFAULT;
16822
16823diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16824index c18f59d..9c0c9f6 100644
16825--- a/arch/x86/kernel/head32.c
16826+++ b/arch/x86/kernel/head32.c
16827@@ -18,6 +18,7 @@
16828 #include <asm/io_apic.h>
16829 #include <asm/bios_ebda.h>
16830 #include <asm/tlbflush.h>
16831+#include <asm/boot.h>
16832
16833 static void __init i386_default_early_setup(void)
16834 {
16835@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16836
16837 void __init i386_start_kernel(void)
16838 {
16839- memblock_reserve(__pa_symbol(&_text),
16840- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16841+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16842
16843 #ifdef CONFIG_BLK_DEV_INITRD
16844 /* Reserve INITRD */
16845diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16846index d42ab17..cb1b997 100644
16847--- a/arch/x86/kernel/head_32.S
16848+++ b/arch/x86/kernel/head_32.S
16849@@ -26,6 +26,12 @@
16850 /* Physical address */
16851 #define pa(X) ((X) - __PAGE_OFFSET)
16852
16853+#ifdef CONFIG_PAX_KERNEXEC
16854+#define ta(X) (X)
16855+#else
16856+#define ta(X) ((X) - __PAGE_OFFSET)
16857+#endif
16858+
16859 /*
16860 * References to members of the new_cpu_data structure.
16861 */
16862@@ -55,11 +61,7 @@
16863 * and small than max_low_pfn, otherwise will waste some page table entries
16864 */
16865
16866-#if PTRS_PER_PMD > 1
16867-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16868-#else
16869-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16870-#endif
16871+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16872
16873 /* Number of possible pages in the lowmem region */
16874 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16875@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16876 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16877
16878 /*
16879+ * Real beginning of normal "text" segment
16880+ */
16881+ENTRY(stext)
16882+ENTRY(_stext)
16883+
16884+/*
16885 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16886 * %esi points to the real-mode code as a 32-bit pointer.
16887 * CS and DS must be 4 GB flat segments, but we don't depend on
16888@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16889 * can.
16890 */
16891 __HEAD
16892+
16893+#ifdef CONFIG_PAX_KERNEXEC
16894+ jmp startup_32
16895+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16896+.fill PAGE_SIZE-5,1,0xcc
16897+#endif
16898+
16899 ENTRY(startup_32)
16900 movl pa(stack_start),%ecx
16901
16902@@ -106,6 +121,57 @@ ENTRY(startup_32)
16903 2:
16904 leal -__PAGE_OFFSET(%ecx),%esp
16905
16906+#ifdef CONFIG_SMP
16907+ movl $pa(cpu_gdt_table),%edi
16908+ movl $__per_cpu_load,%eax
16909+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16910+ rorl $16,%eax
16911+ movb %al,__KERNEL_PERCPU + 4(%edi)
16912+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16913+ movl $__per_cpu_end - 1,%eax
16914+ subl $__per_cpu_start,%eax
16915+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16916+#endif
16917+
16918+#ifdef CONFIG_PAX_MEMORY_UDEREF
16919+ movl $NR_CPUS,%ecx
16920+ movl $pa(cpu_gdt_table),%edi
16921+1:
16922+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16923+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16924+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16925+ addl $PAGE_SIZE_asm,%edi
16926+ loop 1b
16927+#endif
16928+
16929+#ifdef CONFIG_PAX_KERNEXEC
16930+ movl $pa(boot_gdt),%edi
16931+ movl $__LOAD_PHYSICAL_ADDR,%eax
16932+ movw %ax,__BOOT_CS + 2(%edi)
16933+ rorl $16,%eax
16934+ movb %al,__BOOT_CS + 4(%edi)
16935+ movb %ah,__BOOT_CS + 7(%edi)
16936+ rorl $16,%eax
16937+
16938+ ljmp $(__BOOT_CS),$1f
16939+1:
16940+
16941+ movl $NR_CPUS,%ecx
16942+ movl $pa(cpu_gdt_table),%edi
16943+ addl $__PAGE_OFFSET,%eax
16944+1:
16945+ movw %ax,__KERNEL_CS + 2(%edi)
16946+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16947+ rorl $16,%eax
16948+ movb %al,__KERNEL_CS + 4(%edi)
16949+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16950+ movb %ah,__KERNEL_CS + 7(%edi)
16951+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16952+ rorl $16,%eax
16953+ addl $PAGE_SIZE_asm,%edi
16954+ loop 1b
16955+#endif
16956+
16957 /*
16958 * Clear BSS first so that there are no surprises...
16959 */
16960@@ -196,8 +262,11 @@ ENTRY(startup_32)
16961 movl %eax, pa(max_pfn_mapped)
16962
16963 /* Do early initialization of the fixmap area */
16964- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16965- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16966+#ifdef CONFIG_COMPAT_VDSO
16967+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16968+#else
16969+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16970+#endif
16971 #else /* Not PAE */
16972
16973 page_pde_offset = (__PAGE_OFFSET >> 20);
16974@@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16975 movl %eax, pa(max_pfn_mapped)
16976
16977 /* Do early initialization of the fixmap area */
16978- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16979- movl %eax,pa(initial_page_table+0xffc)
16980+#ifdef CONFIG_COMPAT_VDSO
16981+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16982+#else
16983+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16984+#endif
16985 #endif
16986
16987 #ifdef CONFIG_PARAVIRT
16988@@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16989 cmpl $num_subarch_entries, %eax
16990 jae bad_subarch
16991
16992- movl pa(subarch_entries)(,%eax,4), %eax
16993- subl $__PAGE_OFFSET, %eax
16994- jmp *%eax
16995+ jmp *pa(subarch_entries)(,%eax,4)
16996
16997 bad_subarch:
16998 WEAK(lguest_entry)
16999@@ -256,10 +326,10 @@ WEAK(xen_entry)
17000 __INITDATA
17001
17002 subarch_entries:
17003- .long default_entry /* normal x86/PC */
17004- .long lguest_entry /* lguest hypervisor */
17005- .long xen_entry /* Xen hypervisor */
17006- .long default_entry /* Moorestown MID */
17007+ .long ta(default_entry) /* normal x86/PC */
17008+ .long ta(lguest_entry) /* lguest hypervisor */
17009+ .long ta(xen_entry) /* Xen hypervisor */
17010+ .long ta(default_entry) /* Moorestown MID */
17011 num_subarch_entries = (. - subarch_entries) / 4
17012 .previous
17013 #else
17014@@ -310,6 +380,7 @@ default_entry:
17015 orl %edx,%eax
17016 movl %eax,%cr4
17017
17018+#ifdef CONFIG_X86_PAE
17019 testb $X86_CR4_PAE, %al # check if PAE is enabled
17020 jz 6f
17021
17022@@ -338,6 +409,9 @@ default_entry:
17023 /* Make changes effective */
17024 wrmsr
17025
17026+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17027+#endif
17028+
17029 6:
17030
17031 /*
17032@@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
17033 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17034 movl %eax,%ss # after changing gdt.
17035
17036- movl $(__USER_DS),%eax # DS/ES contains default USER segment
17037+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17038 movl %eax,%ds
17039 movl %eax,%es
17040
17041 movl $(__KERNEL_PERCPU), %eax
17042 movl %eax,%fs # set this cpu's percpu
17043
17044+#ifdef CONFIG_CC_STACKPROTECTOR
17045 movl $(__KERNEL_STACK_CANARY),%eax
17046+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17047+ movl $(__USER_DS),%eax
17048+#else
17049+ xorl %eax,%eax
17050+#endif
17051 movl %eax,%gs
17052
17053 xorl %eax,%eax # Clear LDT
17054@@ -520,8 +600,11 @@ setup_once:
17055 * relocation. Manually set base address in stack canary
17056 * segment descriptor.
17057 */
17058- movl $gdt_page,%eax
17059+ movl $cpu_gdt_table,%eax
17060 movl $stack_canary,%ecx
17061+#ifdef CONFIG_SMP
17062+ addl $__per_cpu_load,%ecx
17063+#endif
17064 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17065 shrl $16, %ecx
17066 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17067@@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
17068 /* This is global to keep gas from relaxing the jumps */
17069 ENTRY(early_idt_handler)
17070 cld
17071- cmpl $2,%ss:early_recursion_flag
17072+ cmpl $1,%ss:early_recursion_flag
17073 je hlt_loop
17074 incl %ss:early_recursion_flag
17075
17076@@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
17077 pushl (20+6*4)(%esp) /* trapno */
17078 pushl $fault_msg
17079 call printk
17080-#endif
17081 call dump_stack
17082+#endif
17083 hlt_loop:
17084 hlt
17085 jmp hlt_loop
17086@@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
17087 /* This is the default interrupt "handler" :-) */
17088 ALIGN
17089 ignore_int:
17090- cld
17091 #ifdef CONFIG_PRINTK
17092+ cmpl $2,%ss:early_recursion_flag
17093+ je hlt_loop
17094+ incl %ss:early_recursion_flag
17095+ cld
17096 pushl %eax
17097 pushl %ecx
17098 pushl %edx
17099@@ -620,9 +706,6 @@ ignore_int:
17100 movl $(__KERNEL_DS),%eax
17101 movl %eax,%ds
17102 movl %eax,%es
17103- cmpl $2,early_recursion_flag
17104- je hlt_loop
17105- incl early_recursion_flag
17106 pushl 16(%esp)
17107 pushl 24(%esp)
17108 pushl 32(%esp)
17109@@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
17110 /*
17111 * BSS section
17112 */
17113-__PAGE_ALIGNED_BSS
17114- .align PAGE_SIZE
17115 #ifdef CONFIG_X86_PAE
17116+.section .initial_pg_pmd,"a",@progbits
17117 initial_pg_pmd:
17118 .fill 1024*KPMDS,4,0
17119 #else
17120+.section .initial_page_table,"a",@progbits
17121 ENTRY(initial_page_table)
17122 .fill 1024,4,0
17123 #endif
17124+.section .initial_pg_fixmap,"a",@progbits
17125 initial_pg_fixmap:
17126 .fill 1024,4,0
17127+.section .empty_zero_page,"a",@progbits
17128 ENTRY(empty_zero_page)
17129 .fill 4096,1,0
17130+.section .swapper_pg_dir,"a",@progbits
17131 ENTRY(swapper_pg_dir)
17132+#ifdef CONFIG_X86_PAE
17133+ .fill 4,8,0
17134+#else
17135 .fill 1024,4,0
17136+#endif
17137+
17138+/*
17139+ * The IDT has to be page-aligned to simplify the Pentium
17140+ * F0 0F bug workaround.. We have a special link segment
17141+ * for this.
17142+ */
17143+.section .idt,"a",@progbits
17144+ENTRY(idt_table)
17145+ .fill 256,8,0
17146
17147 /*
17148 * This starts the data section.
17149 */
17150 #ifdef CONFIG_X86_PAE
17151-__PAGE_ALIGNED_DATA
17152- /* Page-aligned for the benefit of paravirt? */
17153- .align PAGE_SIZE
17154+.section .initial_page_table,"a",@progbits
17155 ENTRY(initial_page_table)
17156 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17157 # if KPMDS == 3
17158@@ -697,12 +794,20 @@ ENTRY(initial_page_table)
17159 # error "Kernel PMDs should be 1, 2 or 3"
17160 # endif
17161 .align PAGE_SIZE /* needs to be page-sized too */
17162+
17163+#ifdef CONFIG_PAX_PER_CPU_PGD
17164+ENTRY(cpu_pgd)
17165+ .rept NR_CPUS
17166+ .fill 4,8,0
17167+ .endr
17168+#endif
17169+
17170 #endif
17171
17172 .data
17173 .balign 4
17174 ENTRY(stack_start)
17175- .long init_thread_union+THREAD_SIZE
17176+ .long init_thread_union+THREAD_SIZE-8
17177
17178 __INITRODATA
17179 int_msg:
17180@@ -730,7 +835,7 @@ fault_msg:
17181 * segment size, and 32-bit linear address value:
17182 */
17183
17184- .data
17185+.section .rodata,"a",@progbits
17186 .globl boot_gdt_descr
17187 .globl idt_descr
17188
17189@@ -739,7 +844,7 @@ fault_msg:
17190 .word 0 # 32 bit align gdt_desc.address
17191 boot_gdt_descr:
17192 .word __BOOT_DS+7
17193- .long boot_gdt - __PAGE_OFFSET
17194+ .long pa(boot_gdt)
17195
17196 .word 0 # 32-bit align idt_desc.address
17197 idt_descr:
17198@@ -750,7 +855,7 @@ idt_descr:
17199 .word 0 # 32 bit align gdt_desc.address
17200 ENTRY(early_gdt_descr)
17201 .word GDT_ENTRIES*8-1
17202- .long gdt_page /* Overwritten for secondary CPUs */
17203+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17204
17205 /*
17206 * The boot_gdt must mirror the equivalent in setup.S and is
17207@@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17208 .align L1_CACHE_BYTES
17209 ENTRY(boot_gdt)
17210 .fill GDT_ENTRY_BOOT_CS,8,0
17211- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17212- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17213+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17214+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17215+
17216+ .align PAGE_SIZE_asm
17217+ENTRY(cpu_gdt_table)
17218+ .rept NR_CPUS
17219+ .quad 0x0000000000000000 /* NULL descriptor */
17220+ .quad 0x0000000000000000 /* 0x0b reserved */
17221+ .quad 0x0000000000000000 /* 0x13 reserved */
17222+ .quad 0x0000000000000000 /* 0x1b reserved */
17223+
17224+#ifdef CONFIG_PAX_KERNEXEC
17225+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17226+#else
17227+ .quad 0x0000000000000000 /* 0x20 unused */
17228+#endif
17229+
17230+ .quad 0x0000000000000000 /* 0x28 unused */
17231+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17232+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17233+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17234+ .quad 0x0000000000000000 /* 0x4b reserved */
17235+ .quad 0x0000000000000000 /* 0x53 reserved */
17236+ .quad 0x0000000000000000 /* 0x5b reserved */
17237+
17238+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17239+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17240+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17241+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17242+
17243+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17244+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17245+
17246+ /*
17247+ * Segments used for calling PnP BIOS have byte granularity.
17248+ * The code segments and data segments have fixed 64k limits,
17249+ * the transfer segment sizes are set at run time.
17250+ */
17251+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17252+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17253+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17254+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17255+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17256+
17257+ /*
17258+ * The APM segments have byte granularity and their bases
17259+ * are set at run time. All have 64k limits.
17260+ */
17261+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17262+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17263+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17264+
17265+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17266+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17267+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17268+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17269+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17270+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17271+
17272+ /* Be sure this is zeroed to avoid false validations in Xen */
17273+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17274+ .endr
17275diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17276index 94bf9cc..400455a 100644
17277--- a/arch/x86/kernel/head_64.S
17278+++ b/arch/x86/kernel/head_64.S
17279@@ -20,6 +20,8 @@
17280 #include <asm/processor-flags.h>
17281 #include <asm/percpu.h>
17282 #include <asm/nops.h>
17283+#include <asm/cpufeature.h>
17284+#include <asm/alternative-asm.h>
17285
17286 #ifdef CONFIG_PARAVIRT
17287 #include <asm/asm-offsets.h>
17288@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17289 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17290 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17291 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17292+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17293+L3_VMALLOC_START = pud_index(VMALLOC_START)
17294+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17295+L3_VMALLOC_END = pud_index(VMALLOC_END)
17296+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17297+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17298
17299 .text
17300 __HEAD
17301@@ -88,35 +96,23 @@ startup_64:
17302 */
17303 addq %rbp, init_level4_pgt + 0(%rip)
17304 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17305+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17306+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17307+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17308 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17309
17310 addq %rbp, level3_ident_pgt + 0(%rip)
17311+#ifndef CONFIG_XEN
17312+ addq %rbp, level3_ident_pgt + 8(%rip)
17313+#endif
17314
17315- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17316- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17317+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17318+
17319+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17320+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17321
17322 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17323-
17324- /* Add an Identity mapping if I am above 1G */
17325- leaq _text(%rip), %rdi
17326- andq $PMD_PAGE_MASK, %rdi
17327-
17328- movq %rdi, %rax
17329- shrq $PUD_SHIFT, %rax
17330- andq $(PTRS_PER_PUD - 1), %rax
17331- jz ident_complete
17332-
17333- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17334- leaq level3_ident_pgt(%rip), %rbx
17335- movq %rdx, 0(%rbx, %rax, 8)
17336-
17337- movq %rdi, %rax
17338- shrq $PMD_SHIFT, %rax
17339- andq $(PTRS_PER_PMD - 1), %rax
17340- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17341- leaq level2_spare_pgt(%rip), %rbx
17342- movq %rdx, 0(%rbx, %rax, 8)
17343-ident_complete:
17344+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17345
17346 /*
17347 * Fixup the kernel text+data virtual addresses. Note that
17348@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17349 * after the boot processor executes this code.
17350 */
17351
17352- /* Enable PAE mode and PGE */
17353- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17354+ /* Enable PAE mode and PSE/PGE */
17355+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17356 movq %rax, %cr4
17357
17358 /* Setup early boot stage 4 level pagetables. */
17359@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17360 movl $MSR_EFER, %ecx
17361 rdmsr
17362 btsl $_EFER_SCE, %eax /* Enable System Call */
17363- btl $20,%edi /* No Execute supported? */
17364+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17365 jnc 1f
17366 btsl $_EFER_NX, %eax
17367+ leaq init_level4_pgt(%rip), %rdi
17368+#ifndef CONFIG_EFI
17369+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17370+#endif
17371+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17372+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17373+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17374+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17375 1: wrmsr /* Make changes effective */
17376
17377 /* Setup cr0 */
17378@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17379 * jump. In addition we need to ensure %cs is set so we make this
17380 * a far return.
17381 */
17382+ pax_set_fptr_mask
17383 movq initial_code(%rip),%rax
17384 pushq $0 # fake return address to stop unwinder
17385 pushq $__KERNEL_CS # set correct cs
17386@@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17387 bad_address:
17388 jmp bad_address
17389
17390- .section ".init.text","ax"
17391+ __INIT
17392 .globl early_idt_handlers
17393 early_idt_handlers:
17394 # 104(%rsp) %rflags
17395@@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17396 addq $16,%rsp # drop vector number and error code
17397 decl early_recursion_flag(%rip)
17398 INTERRUPT_RETURN
17399+ .previous
17400
17401+ __INITDATA
17402 .balign 4
17403 early_recursion_flag:
17404 .long 0
17405+ .previous
17406
17407+ .section .rodata,"a",@progbits
17408 #ifdef CONFIG_EARLY_PRINTK
17409 early_idt_msg:
17410 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17411@@ -360,6 +369,7 @@ early_idt_ripmsg:
17412 #endif /* CONFIG_EARLY_PRINTK */
17413 .previous
17414
17415+ .section .rodata,"a",@progbits
17416 #define NEXT_PAGE(name) \
17417 .balign PAGE_SIZE; \
17418 ENTRY(name)
17419@@ -372,7 +382,6 @@ ENTRY(name)
17420 i = i + 1 ; \
17421 .endr
17422
17423- .data
17424 /*
17425 * This default setting generates an ident mapping at address 0x100000
17426 * and a mapping for the kernel that precisely maps virtual address
17427@@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17428 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17429 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17430 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17431+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17432+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17433+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17434+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17435+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17436+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17437 .org init_level4_pgt + L4_START_KERNEL*8, 0
17438 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17439 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17440
17441+#ifdef CONFIG_PAX_PER_CPU_PGD
17442+NEXT_PAGE(cpu_pgd)
17443+ .rept NR_CPUS
17444+ .fill 512,8,0
17445+ .endr
17446+#endif
17447+
17448 NEXT_PAGE(level3_ident_pgt)
17449 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17450+#ifdef CONFIG_XEN
17451 .fill 511,8,0
17452+#else
17453+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17454+ .fill 510,8,0
17455+#endif
17456+
17457+NEXT_PAGE(level3_vmalloc_start_pgt)
17458+ .fill 512,8,0
17459+
17460+NEXT_PAGE(level3_vmalloc_end_pgt)
17461+ .fill 512,8,0
17462+
17463+NEXT_PAGE(level3_vmemmap_pgt)
17464+ .fill L3_VMEMMAP_START,8,0
17465+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17466
17467 NEXT_PAGE(level3_kernel_pgt)
17468 .fill L3_START_KERNEL,8,0
17469@@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17470 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17471 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17472
17473+NEXT_PAGE(level2_vmemmap_pgt)
17474+ .fill 512,8,0
17475+
17476 NEXT_PAGE(level2_fixmap_pgt)
17477- .fill 506,8,0
17478- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17479- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17480- .fill 5,8,0
17481+ .fill 507,8,0
17482+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17483+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17484+ .fill 4,8,0
17485
17486-NEXT_PAGE(level1_fixmap_pgt)
17487+NEXT_PAGE(level1_vsyscall_pgt)
17488 .fill 512,8,0
17489
17490-NEXT_PAGE(level2_ident_pgt)
17491- /* Since I easily can, map the first 1G.
17492+ /* Since I easily can, map the first 2G.
17493 * Don't set NX because code runs from these pages.
17494 */
17495- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17496+NEXT_PAGE(level2_ident_pgt)
17497+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17498
17499 NEXT_PAGE(level2_kernel_pgt)
17500 /*
17501@@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17502 * If you want to increase this then increase MODULES_VADDR
17503 * too.)
17504 */
17505- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17506- KERNEL_IMAGE_SIZE/PMD_SIZE)
17507-
17508-NEXT_PAGE(level2_spare_pgt)
17509- .fill 512, 8, 0
17510+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17511
17512 #undef PMDS
17513 #undef NEXT_PAGE
17514
17515- .data
17516+ .align PAGE_SIZE
17517+ENTRY(cpu_gdt_table)
17518+ .rept NR_CPUS
17519+ .quad 0x0000000000000000 /* NULL descriptor */
17520+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17521+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17522+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17523+ .quad 0x00cffb000000ffff /* __USER32_CS */
17524+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17525+ .quad 0x00affb000000ffff /* __USER_CS */
17526+
17527+#ifdef CONFIG_PAX_KERNEXEC
17528+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17529+#else
17530+ .quad 0x0 /* unused */
17531+#endif
17532+
17533+ .quad 0,0 /* TSS */
17534+ .quad 0,0 /* LDT */
17535+ .quad 0,0,0 /* three TLS descriptors */
17536+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17537+ /* asm/segment.h:GDT_ENTRIES must match this */
17538+
17539+ /* zero the remaining page */
17540+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17541+ .endr
17542+
17543 .align 16
17544 .globl early_gdt_descr
17545 early_gdt_descr:
17546 .word GDT_ENTRIES*8-1
17547 early_gdt_descr_base:
17548- .quad INIT_PER_CPU_VAR(gdt_page)
17549+ .quad cpu_gdt_table
17550
17551 ENTRY(phys_base)
17552 /* This must match the first entry in level2_kernel_pgt */
17553 .quad 0x0000000000000000
17554
17555 #include "../../x86/xen/xen-head.S"
17556-
17557- .section .bss, "aw", @nobits
17558+
17559+ .section .rodata,"a",@progbits
17560 .align L1_CACHE_BYTES
17561 ENTRY(idt_table)
17562- .skip IDT_ENTRIES * 16
17563+ .fill 512,8,0
17564
17565 .align L1_CACHE_BYTES
17566 ENTRY(nmi_idt_table)
17567- .skip IDT_ENTRIES * 16
17568+ .fill 512,8,0
17569
17570 __PAGE_ALIGNED_BSS
17571 .align PAGE_SIZE
17572diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17573index 9c3bd4a..e1d9b35 100644
17574--- a/arch/x86/kernel/i386_ksyms_32.c
17575+++ b/arch/x86/kernel/i386_ksyms_32.c
17576@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17577 EXPORT_SYMBOL(cmpxchg8b_emu);
17578 #endif
17579
17580+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17581+
17582 /* Networking helper routines. */
17583 EXPORT_SYMBOL(csum_partial_copy_generic);
17584+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17585+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17586
17587 EXPORT_SYMBOL(__get_user_1);
17588 EXPORT_SYMBOL(__get_user_2);
17589@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17590
17591 EXPORT_SYMBOL(csum_partial);
17592 EXPORT_SYMBOL(empty_zero_page);
17593+
17594+#ifdef CONFIG_PAX_KERNEXEC
17595+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17596+#endif
17597diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17598index f250431..54097e7 100644
17599--- a/arch/x86/kernel/i387.c
17600+++ b/arch/x86/kernel/i387.c
17601@@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17602 static inline bool interrupted_user_mode(void)
17603 {
17604 struct pt_regs *regs = get_irq_regs();
17605- return regs && user_mode_vm(regs);
17606+ return regs && user_mode(regs);
17607 }
17608
17609 /*
17610diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17611index 36d1853..bf25736 100644
17612--- a/arch/x86/kernel/i8259.c
17613+++ b/arch/x86/kernel/i8259.c
17614@@ -209,7 +209,7 @@ spurious_8259A_irq:
17615 "spurious 8259A interrupt: IRQ%d.\n", irq);
17616 spurious_irq_mask |= irqmask;
17617 }
17618- atomic_inc(&irq_err_count);
17619+ atomic_inc_unchecked(&irq_err_count);
17620 /*
17621 * Theoretically we do not have to handle this IRQ,
17622 * but in Linux this does not cause problems and is
17623diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17624index 8c96897..be66bfa 100644
17625--- a/arch/x86/kernel/ioport.c
17626+++ b/arch/x86/kernel/ioport.c
17627@@ -6,6 +6,7 @@
17628 #include <linux/sched.h>
17629 #include <linux/kernel.h>
17630 #include <linux/capability.h>
17631+#include <linux/security.h>
17632 #include <linux/errno.h>
17633 #include <linux/types.h>
17634 #include <linux/ioport.h>
17635@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17636
17637 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17638 return -EINVAL;
17639+#ifdef CONFIG_GRKERNSEC_IO
17640+ if (turn_on && grsec_disable_privio) {
17641+ gr_handle_ioperm();
17642+ return -EPERM;
17643+ }
17644+#endif
17645 if (turn_on && !capable(CAP_SYS_RAWIO))
17646 return -EPERM;
17647
17648@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17649 * because the ->io_bitmap_max value must match the bitmap
17650 * contents:
17651 */
17652- tss = &per_cpu(init_tss, get_cpu());
17653+ tss = init_tss + get_cpu();
17654
17655 if (turn_on)
17656 bitmap_clear(t->io_bitmap_ptr, from, num);
17657@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17658 return -EINVAL;
17659 /* Trying to gain more privileges? */
17660 if (level > old) {
17661+#ifdef CONFIG_GRKERNSEC_IO
17662+ if (grsec_disable_privio) {
17663+ gr_handle_iopl();
17664+ return -EPERM;
17665+ }
17666+#endif
17667 if (!capable(CAP_SYS_RAWIO))
17668 return -EPERM;
17669 }
17670diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17671index d44f782..31ab01e 100644
17672--- a/arch/x86/kernel/irq.c
17673+++ b/arch/x86/kernel/irq.c
17674@@ -18,7 +18,7 @@
17675 #include <asm/mce.h>
17676 #include <asm/hw_irq.h>
17677
17678-atomic_t irq_err_count;
17679+atomic_unchecked_t irq_err_count;
17680
17681 /* Function pointer for generic interrupt vector handling */
17682 void (*x86_platform_ipi_callback)(void) = NULL;
17683@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17684 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17685 seq_printf(p, " Machine check polls\n");
17686 #endif
17687- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17688+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17689 #if defined(CONFIG_X86_IO_APIC)
17690- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17691+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17692 #endif
17693 return 0;
17694 }
17695@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17696
17697 u64 arch_irq_stat(void)
17698 {
17699- u64 sum = atomic_read(&irq_err_count);
17700+ u64 sum = atomic_read_unchecked(&irq_err_count);
17701
17702 #ifdef CONFIG_X86_IO_APIC
17703- sum += atomic_read(&irq_mis_count);
17704+ sum += atomic_read_unchecked(&irq_mis_count);
17705 #endif
17706 return sum;
17707 }
17708diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17709index 344faf8..355f60d 100644
17710--- a/arch/x86/kernel/irq_32.c
17711+++ b/arch/x86/kernel/irq_32.c
17712@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17713 __asm__ __volatile__("andl %%esp,%0" :
17714 "=r" (sp) : "0" (THREAD_SIZE - 1));
17715
17716- return sp < (sizeof(struct thread_info) + STACK_WARN);
17717+ return sp < STACK_WARN;
17718 }
17719
17720 static void print_stack_overflow(void)
17721@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17722 * per-CPU IRQ handling contexts (thread information and stack)
17723 */
17724 union irq_ctx {
17725- struct thread_info tinfo;
17726- u32 stack[THREAD_SIZE/sizeof(u32)];
17727+ unsigned long previous_esp;
17728+ u32 stack[THREAD_SIZE/sizeof(u32)];
17729 } __attribute__((aligned(THREAD_SIZE)));
17730
17731 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17732@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17733 static inline int
17734 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17735 {
17736- union irq_ctx *curctx, *irqctx;
17737+ union irq_ctx *irqctx;
17738 u32 *isp, arg1, arg2;
17739
17740- curctx = (union irq_ctx *) current_thread_info();
17741 irqctx = __this_cpu_read(hardirq_ctx);
17742
17743 /*
17744@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17745 * handler) we can't do that and just have to keep using the
17746 * current stack (which is the irq stack already after all)
17747 */
17748- if (unlikely(curctx == irqctx))
17749+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17750 return 0;
17751
17752 /* build the stack frame on the IRQ stack */
17753- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17754- irqctx->tinfo.task = curctx->tinfo.task;
17755- irqctx->tinfo.previous_esp = current_stack_pointer;
17756+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17757+ irqctx->previous_esp = current_stack_pointer;
17758
17759- /* Copy the preempt_count so that the [soft]irq checks work. */
17760- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17761+#ifdef CONFIG_PAX_MEMORY_UDEREF
17762+ __set_fs(MAKE_MM_SEG(0));
17763+#endif
17764
17765 if (unlikely(overflow))
17766 call_on_stack(print_stack_overflow, isp);
17767@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17768 : "0" (irq), "1" (desc), "2" (isp),
17769 "D" (desc->handle_irq)
17770 : "memory", "cc", "ecx");
17771+
17772+#ifdef CONFIG_PAX_MEMORY_UDEREF
17773+ __set_fs(current_thread_info()->addr_limit);
17774+#endif
17775+
17776 return 1;
17777 }
17778
17779@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17780 */
17781 void __cpuinit irq_ctx_init(int cpu)
17782 {
17783- union irq_ctx *irqctx;
17784-
17785 if (per_cpu(hardirq_ctx, cpu))
17786 return;
17787
17788- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17789- THREADINFO_GFP,
17790- THREAD_SIZE_ORDER));
17791- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17792- irqctx->tinfo.cpu = cpu;
17793- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17794- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17795-
17796- per_cpu(hardirq_ctx, cpu) = irqctx;
17797-
17798- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17799- THREADINFO_GFP,
17800- THREAD_SIZE_ORDER));
17801- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17802- irqctx->tinfo.cpu = cpu;
17803- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17804-
17805- per_cpu(softirq_ctx, cpu) = irqctx;
17806+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17807+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17808+
17809+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17810+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17811
17812 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17813 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17814@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17815 asmlinkage void do_softirq(void)
17816 {
17817 unsigned long flags;
17818- struct thread_info *curctx;
17819 union irq_ctx *irqctx;
17820 u32 *isp;
17821
17822@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17823 local_irq_save(flags);
17824
17825 if (local_softirq_pending()) {
17826- curctx = current_thread_info();
17827 irqctx = __this_cpu_read(softirq_ctx);
17828- irqctx->tinfo.task = curctx->task;
17829- irqctx->tinfo.previous_esp = current_stack_pointer;
17830+ irqctx->previous_esp = current_stack_pointer;
17831
17832 /* build the stack frame on the softirq stack */
17833- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17834+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17835+
17836+#ifdef CONFIG_PAX_MEMORY_UDEREF
17837+ __set_fs(MAKE_MM_SEG(0));
17838+#endif
17839
17840 call_on_stack(__do_softirq, isp);
17841+
17842+#ifdef CONFIG_PAX_MEMORY_UDEREF
17843+ __set_fs(current_thread_info()->addr_limit);
17844+#endif
17845+
17846 /*
17847 * Shouldn't happen, we returned above if in_interrupt():
17848 */
17849@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17850 if (unlikely(!desc))
17851 return false;
17852
17853- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17854+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17855 if (unlikely(overflow))
17856 print_stack_overflow();
17857 desc->handle_irq(irq, desc);
17858diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17859index d04d3ec..ea4b374 100644
17860--- a/arch/x86/kernel/irq_64.c
17861+++ b/arch/x86/kernel/irq_64.c
17862@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17863 u64 estack_top, estack_bottom;
17864 u64 curbase = (u64)task_stack_page(current);
17865
17866- if (user_mode_vm(regs))
17867+ if (user_mode(regs))
17868 return;
17869
17870 if (regs->sp >= curbase + sizeof(struct thread_info) +
17871diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17872index dc1404b..bbc43e7 100644
17873--- a/arch/x86/kernel/kdebugfs.c
17874+++ b/arch/x86/kernel/kdebugfs.c
17875@@ -27,7 +27,7 @@ struct setup_data_node {
17876 u32 len;
17877 };
17878
17879-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17880+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17881 size_t count, loff_t *ppos)
17882 {
17883 struct setup_data_node *node = file->private_data;
17884diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17885index 3f61904..873cea9 100644
17886--- a/arch/x86/kernel/kgdb.c
17887+++ b/arch/x86/kernel/kgdb.c
17888@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17889 #ifdef CONFIG_X86_32
17890 switch (regno) {
17891 case GDB_SS:
17892- if (!user_mode_vm(regs))
17893+ if (!user_mode(regs))
17894 *(unsigned long *)mem = __KERNEL_DS;
17895 break;
17896 case GDB_SP:
17897- if (!user_mode_vm(regs))
17898+ if (!user_mode(regs))
17899 *(unsigned long *)mem = kernel_stack_pointer(regs);
17900 break;
17901 case GDB_GS:
17902@@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17903 case 'k':
17904 /* clear the trace bit */
17905 linux_regs->flags &= ~X86_EFLAGS_TF;
17906- atomic_set(&kgdb_cpu_doing_single_step, -1);
17907+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17908
17909 /* set the trace bit if we're stepping */
17910 if (remcomInBuffer[0] == 's') {
17911 linux_regs->flags |= X86_EFLAGS_TF;
17912- atomic_set(&kgdb_cpu_doing_single_step,
17913+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17914 raw_smp_processor_id());
17915 }
17916
17917@@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17918
17919 switch (cmd) {
17920 case DIE_DEBUG:
17921- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17922+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17923 if (user_mode(regs))
17924 return single_step_cont(regs, args);
17925 break;
17926diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17927index c5e410e..da6aaf9 100644
17928--- a/arch/x86/kernel/kprobes-opt.c
17929+++ b/arch/x86/kernel/kprobes-opt.c
17930@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17931 * Verify if the address gap is in 2GB range, because this uses
17932 * a relative jump.
17933 */
17934- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17935+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17936 if (abs(rel) > 0x7fffffff)
17937 return -ERANGE;
17938
17939@@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17940 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17941
17942 /* Set probe function call */
17943- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17944+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17945
17946 /* Set returning jmp instruction at the tail of out-of-line buffer */
17947 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17948- (u8 *)op->kp.addr + op->optinsn.size);
17949+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17950
17951 flush_icache_range((unsigned long) buf,
17952 (unsigned long) buf + TMPL_END_IDX +
17953@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17954 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17955
17956 /* Backup instructions which will be replaced by jump address */
17957- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17958+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17959 RELATIVE_ADDR_SIZE);
17960
17961 insn_buf[0] = RELATIVEJUMP_OPCODE;
17962diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17963index e2f751e..dffa2a0 100644
17964--- a/arch/x86/kernel/kprobes.c
17965+++ b/arch/x86/kernel/kprobes.c
17966@@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17967 } __attribute__((packed)) *insn;
17968
17969 insn = (struct __arch_relative_insn *)from;
17970+
17971+ pax_open_kernel();
17972 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17973 insn->op = op;
17974+ pax_close_kernel();
17975 }
17976
17977 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17978@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17979 kprobe_opcode_t opcode;
17980 kprobe_opcode_t *orig_opcodes = opcodes;
17981
17982- if (search_exception_tables((unsigned long)opcodes))
17983+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17984 return 0; /* Page fault may occur on this address. */
17985
17986 retry:
17987@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17988 /* Another subsystem puts a breakpoint, failed to recover */
17989 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17990 return 0;
17991+ pax_open_kernel();
17992 memcpy(dest, insn.kaddr, insn.length);
17993+ pax_close_kernel();
17994
17995 #ifdef CONFIG_X86_64
17996 if (insn_rip_relative(&insn)) {
17997@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17998 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17999 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18000 disp = (u8 *) dest + insn_offset_displacement(&insn);
18001+ pax_open_kernel();
18002 *(s32 *) disp = (s32) newdisp;
18003+ pax_close_kernel();
18004 }
18005 #endif
18006 return insn.length;
18007@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18008 * nor set current_kprobe, because it doesn't use single
18009 * stepping.
18010 */
18011- regs->ip = (unsigned long)p->ainsn.insn;
18012+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18013 preempt_enable_no_resched();
18014 return;
18015 }
18016@@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18017 if (p->opcode == BREAKPOINT_INSTRUCTION)
18018 regs->ip = (unsigned long)p->addr;
18019 else
18020- regs->ip = (unsigned long)p->ainsn.insn;
18021+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18022 }
18023
18024 /*
18025@@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18026 setup_singlestep(p, regs, kcb, 0);
18027 return 1;
18028 }
18029- } else if (*addr != BREAKPOINT_INSTRUCTION) {
18030+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18031 /*
18032 * The breakpoint instruction was removed right
18033 * after we hit it. Another cpu has removed
18034@@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18035 " movq %rax, 152(%rsp)\n"
18036 RESTORE_REGS_STRING
18037 " popfq\n"
18038+#ifdef KERNEXEC_PLUGIN
18039+ " btsq $63,(%rsp)\n"
18040+#endif
18041 #else
18042 " pushf\n"
18043 SAVE_REGS_STRING
18044@@ -765,7 +775,7 @@ static void __kprobes
18045 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18046 {
18047 unsigned long *tos = stack_addr(regs);
18048- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18049+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18050 unsigned long orig_ip = (unsigned long)p->addr;
18051 kprobe_opcode_t *insn = p->ainsn.insn;
18052
18053@@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18054 struct die_args *args = data;
18055 int ret = NOTIFY_DONE;
18056
18057- if (args->regs && user_mode_vm(args->regs))
18058+ if (args->regs && user_mode(args->regs))
18059 return ret;
18060
18061 switch (val) {
18062diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18063index ebc9873..1b9724b 100644
18064--- a/arch/x86/kernel/ldt.c
18065+++ b/arch/x86/kernel/ldt.c
18066@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18067 if (reload) {
18068 #ifdef CONFIG_SMP
18069 preempt_disable();
18070- load_LDT(pc);
18071+ load_LDT_nolock(pc);
18072 if (!cpumask_equal(mm_cpumask(current->mm),
18073 cpumask_of(smp_processor_id())))
18074 smp_call_function(flush_ldt, current->mm, 1);
18075 preempt_enable();
18076 #else
18077- load_LDT(pc);
18078+ load_LDT_nolock(pc);
18079 #endif
18080 }
18081 if (oldsize) {
18082@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18083 return err;
18084
18085 for (i = 0; i < old->size; i++)
18086- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18087+ write_ldt_entry(new->ldt, i, old->ldt + i);
18088 return 0;
18089 }
18090
18091@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18092 retval = copy_ldt(&mm->context, &old_mm->context);
18093 mutex_unlock(&old_mm->context.lock);
18094 }
18095+
18096+ if (tsk == current) {
18097+ mm->context.vdso = 0;
18098+
18099+#ifdef CONFIG_X86_32
18100+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18101+ mm->context.user_cs_base = 0UL;
18102+ mm->context.user_cs_limit = ~0UL;
18103+
18104+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18105+ cpus_clear(mm->context.cpu_user_cs_mask);
18106+#endif
18107+
18108+#endif
18109+#endif
18110+
18111+ }
18112+
18113 return retval;
18114 }
18115
18116@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18117 }
18118 }
18119
18120+#ifdef CONFIG_PAX_SEGMEXEC
18121+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18122+ error = -EINVAL;
18123+ goto out_unlock;
18124+ }
18125+#endif
18126+
18127 fill_ldt(&ldt, &ldt_info);
18128 if (oldmode)
18129 ldt.avl = 0;
18130diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18131index 5b19e4d..6476a76 100644
18132--- a/arch/x86/kernel/machine_kexec_32.c
18133+++ b/arch/x86/kernel/machine_kexec_32.c
18134@@ -26,7 +26,7 @@
18135 #include <asm/cacheflush.h>
18136 #include <asm/debugreg.h>
18137
18138-static void set_idt(void *newidt, __u16 limit)
18139+static void set_idt(struct desc_struct *newidt, __u16 limit)
18140 {
18141 struct desc_ptr curidt;
18142
18143@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18144 }
18145
18146
18147-static void set_gdt(void *newgdt, __u16 limit)
18148+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18149 {
18150 struct desc_ptr curgdt;
18151
18152@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18153 }
18154
18155 control_page = page_address(image->control_code_page);
18156- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18157+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18158
18159 relocate_kernel_ptr = control_page;
18160 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18161diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18162index 0327e2b..e43737b 100644
18163--- a/arch/x86/kernel/microcode_intel.c
18164+++ b/arch/x86/kernel/microcode_intel.c
18165@@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18166
18167 static int get_ucode_user(void *to, const void *from, size_t n)
18168 {
18169- return copy_from_user(to, from, n);
18170+ return copy_from_user(to, (const void __force_user *)from, n);
18171 }
18172
18173 static enum ucode_state
18174 request_microcode_user(int cpu, const void __user *buf, size_t size)
18175 {
18176- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18177+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18178 }
18179
18180 static void microcode_fini_cpu(int cpu)
18181diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18182index 216a4d7..b328f09 100644
18183--- a/arch/x86/kernel/module.c
18184+++ b/arch/x86/kernel/module.c
18185@@ -43,15 +43,60 @@ do { \
18186 } while (0)
18187 #endif
18188
18189-void *module_alloc(unsigned long size)
18190+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18191 {
18192- if (PAGE_ALIGN(size) > MODULES_LEN)
18193+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18194 return NULL;
18195 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18196- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18197+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18198 -1, __builtin_return_address(0));
18199 }
18200
18201+void *module_alloc(unsigned long size)
18202+{
18203+
18204+#ifdef CONFIG_PAX_KERNEXEC
18205+ return __module_alloc(size, PAGE_KERNEL);
18206+#else
18207+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18208+#endif
18209+
18210+}
18211+
18212+#ifdef CONFIG_PAX_KERNEXEC
18213+#ifdef CONFIG_X86_32
18214+void *module_alloc_exec(unsigned long size)
18215+{
18216+ struct vm_struct *area;
18217+
18218+ if (size == 0)
18219+ return NULL;
18220+
18221+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18222+ return area ? area->addr : NULL;
18223+}
18224+EXPORT_SYMBOL(module_alloc_exec);
18225+
18226+void module_free_exec(struct module *mod, void *module_region)
18227+{
18228+ vunmap(module_region);
18229+}
18230+EXPORT_SYMBOL(module_free_exec);
18231+#else
18232+void module_free_exec(struct module *mod, void *module_region)
18233+{
18234+ module_free(mod, module_region);
18235+}
18236+EXPORT_SYMBOL(module_free_exec);
18237+
18238+void *module_alloc_exec(unsigned long size)
18239+{
18240+ return __module_alloc(size, PAGE_KERNEL_RX);
18241+}
18242+EXPORT_SYMBOL(module_alloc_exec);
18243+#endif
18244+#endif
18245+
18246 #ifdef CONFIG_X86_32
18247 int apply_relocate(Elf32_Shdr *sechdrs,
18248 const char *strtab,
18249@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18250 unsigned int i;
18251 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18252 Elf32_Sym *sym;
18253- uint32_t *location;
18254+ uint32_t *plocation, location;
18255
18256 DEBUGP("Applying relocate section %u to %u\n",
18257 relsec, sechdrs[relsec].sh_info);
18258 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18259 /* This is where to make the change */
18260- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18261- + rel[i].r_offset;
18262+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18263+ location = (uint32_t)plocation;
18264+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18265+ plocation = ktla_ktva((void *)plocation);
18266 /* This is the symbol it is referring to. Note that all
18267 undefined symbols have been resolved. */
18268 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18269@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18270 switch (ELF32_R_TYPE(rel[i].r_info)) {
18271 case R_386_32:
18272 /* We add the value into the location given */
18273- *location += sym->st_value;
18274+ pax_open_kernel();
18275+ *plocation += sym->st_value;
18276+ pax_close_kernel();
18277 break;
18278 case R_386_PC32:
18279 /* Add the value, subtract its position */
18280- *location += sym->st_value - (uint32_t)location;
18281+ pax_open_kernel();
18282+ *plocation += sym->st_value - location;
18283+ pax_close_kernel();
18284 break;
18285 default:
18286 pr_err("%s: Unknown relocation: %u\n",
18287@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18288 case R_X86_64_NONE:
18289 break;
18290 case R_X86_64_64:
18291+ pax_open_kernel();
18292 *(u64 *)loc = val;
18293+ pax_close_kernel();
18294 break;
18295 case R_X86_64_32:
18296+ pax_open_kernel();
18297 *(u32 *)loc = val;
18298+ pax_close_kernel();
18299 if (val != *(u32 *)loc)
18300 goto overflow;
18301 break;
18302 case R_X86_64_32S:
18303+ pax_open_kernel();
18304 *(s32 *)loc = val;
18305+ pax_close_kernel();
18306 if ((s64)val != *(s32 *)loc)
18307 goto overflow;
18308 break;
18309 case R_X86_64_PC32:
18310 val -= (u64)loc;
18311+ pax_open_kernel();
18312 *(u32 *)loc = val;
18313+ pax_close_kernel();
18314+
18315 #if 0
18316 if ((s64)val != *(s32 *)loc)
18317 goto overflow;
18318diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18319index f84f5c5..e27e54b 100644
18320--- a/arch/x86/kernel/nmi.c
18321+++ b/arch/x86/kernel/nmi.c
18322@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18323 dotraplinkage notrace __kprobes void
18324 do_nmi(struct pt_regs *regs, long error_code)
18325 {
18326+
18327+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18328+ if (!user_mode(regs)) {
18329+ unsigned long cs = regs->cs & 0xFFFF;
18330+ unsigned long ip = ktva_ktla(regs->ip);
18331+
18332+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18333+ regs->ip = ip;
18334+ }
18335+#endif
18336+
18337 nmi_nesting_preprocess(regs);
18338
18339 nmi_enter();
18340diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18341index 676b8c7..870ba04 100644
18342--- a/arch/x86/kernel/paravirt-spinlocks.c
18343+++ b/arch/x86/kernel/paravirt-spinlocks.c
18344@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18345 arch_spin_lock(lock);
18346 }
18347
18348-struct pv_lock_ops pv_lock_ops = {
18349+struct pv_lock_ops pv_lock_ops __read_only = {
18350 #ifdef CONFIG_SMP
18351 .spin_is_locked = __ticket_spin_is_locked,
18352 .spin_is_contended = __ticket_spin_is_contended,
18353diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18354index 17fff18..7bb2088 100644
18355--- a/arch/x86/kernel/paravirt.c
18356+++ b/arch/x86/kernel/paravirt.c
18357@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18358 {
18359 return x;
18360 }
18361+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18362+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18363+#endif
18364
18365 void __init default_banner(void)
18366 {
18367@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18368 if (opfunc == NULL)
18369 /* If there's no function, patch it with a ud2a (BUG) */
18370 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18371- else if (opfunc == _paravirt_nop)
18372+ else if (opfunc == (void *)_paravirt_nop)
18373 /* If the operation is a nop, then nop the callsite */
18374 ret = paravirt_patch_nop();
18375
18376 /* identity functions just return their single argument */
18377- else if (opfunc == _paravirt_ident_32)
18378+ else if (opfunc == (void *)_paravirt_ident_32)
18379 ret = paravirt_patch_ident_32(insnbuf, len);
18380- else if (opfunc == _paravirt_ident_64)
18381+ else if (opfunc == (void *)_paravirt_ident_64)
18382 ret = paravirt_patch_ident_64(insnbuf, len);
18383+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18384+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18385+ ret = paravirt_patch_ident_64(insnbuf, len);
18386+#endif
18387
18388 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18389 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18390@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18391 if (insn_len > len || start == NULL)
18392 insn_len = len;
18393 else
18394- memcpy(insnbuf, start, insn_len);
18395+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18396
18397 return insn_len;
18398 }
18399@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18400 preempt_enable();
18401 }
18402
18403-struct pv_info pv_info = {
18404+struct pv_info pv_info __read_only = {
18405 .name = "bare hardware",
18406 .paravirt_enabled = 0,
18407 .kernel_rpl = 0,
18408@@ -315,16 +322,16 @@ struct pv_info pv_info = {
18409 #endif
18410 };
18411
18412-struct pv_init_ops pv_init_ops = {
18413+struct pv_init_ops pv_init_ops __read_only = {
18414 .patch = native_patch,
18415 };
18416
18417-struct pv_time_ops pv_time_ops = {
18418+struct pv_time_ops pv_time_ops __read_only = {
18419 .sched_clock = native_sched_clock,
18420 .steal_clock = native_steal_clock,
18421 };
18422
18423-struct pv_irq_ops pv_irq_ops = {
18424+struct pv_irq_ops pv_irq_ops __read_only = {
18425 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18426 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18427 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18428@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18429 #endif
18430 };
18431
18432-struct pv_cpu_ops pv_cpu_ops = {
18433+struct pv_cpu_ops pv_cpu_ops __read_only = {
18434 .cpuid = native_cpuid,
18435 .get_debugreg = native_get_debugreg,
18436 .set_debugreg = native_set_debugreg,
18437@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18438 .end_context_switch = paravirt_nop,
18439 };
18440
18441-struct pv_apic_ops pv_apic_ops = {
18442+struct pv_apic_ops pv_apic_ops __read_only = {
18443 #ifdef CONFIG_X86_LOCAL_APIC
18444 .startup_ipi_hook = paravirt_nop,
18445 #endif
18446 };
18447
18448-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18449+#ifdef CONFIG_X86_32
18450+#ifdef CONFIG_X86_PAE
18451+/* 64-bit pagetable entries */
18452+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18453+#else
18454 /* 32-bit pagetable entries */
18455 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18456+#endif
18457 #else
18458 /* 64-bit pagetable entries */
18459 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18460 #endif
18461
18462-struct pv_mmu_ops pv_mmu_ops = {
18463+struct pv_mmu_ops pv_mmu_ops __read_only = {
18464
18465 .read_cr2 = native_read_cr2,
18466 .write_cr2 = native_write_cr2,
18467@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18468 .make_pud = PTE_IDENT,
18469
18470 .set_pgd = native_set_pgd,
18471+ .set_pgd_batched = native_set_pgd_batched,
18472 #endif
18473 #endif /* PAGETABLE_LEVELS >= 3 */
18474
18475@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18476 },
18477
18478 .set_fixmap = native_set_fixmap,
18479+
18480+#ifdef CONFIG_PAX_KERNEXEC
18481+ .pax_open_kernel = native_pax_open_kernel,
18482+ .pax_close_kernel = native_pax_close_kernel,
18483+#endif
18484+
18485 };
18486
18487 EXPORT_SYMBOL_GPL(pv_time_ops);
18488diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18489index 35ccf75..7a15747 100644
18490--- a/arch/x86/kernel/pci-iommu_table.c
18491+++ b/arch/x86/kernel/pci-iommu_table.c
18492@@ -2,7 +2,7 @@
18493 #include <asm/iommu_table.h>
18494 #include <linux/string.h>
18495 #include <linux/kallsyms.h>
18496-
18497+#include <linux/sched.h>
18498
18499 #define DEBUG 1
18500
18501diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18502index ef6a845..8028ed3 100644
18503--- a/arch/x86/kernel/process.c
18504+++ b/arch/x86/kernel/process.c
18505@@ -36,7 +36,8 @@
18506 * section. Since TSS's are completely CPU-local, we want them
18507 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18508 */
18509-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18510+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18511+EXPORT_SYMBOL(init_tss);
18512
18513 #ifdef CONFIG_X86_64
18514 static DEFINE_PER_CPU(unsigned char, is_idle);
18515@@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18516 task_xstate_cachep =
18517 kmem_cache_create("task_xstate", xstate_size,
18518 __alignof__(union thread_xstate),
18519- SLAB_PANIC | SLAB_NOTRACK, NULL);
18520+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18521 }
18522
18523 static inline void drop_fpu(struct task_struct *tsk)
18524@@ -117,7 +118,7 @@ void exit_thread(void)
18525 unsigned long *bp = t->io_bitmap_ptr;
18526
18527 if (bp) {
18528- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18529+ struct tss_struct *tss = init_tss + get_cpu();
18530
18531 t->io_bitmap_ptr = NULL;
18532 clear_thread_flag(TIF_IO_BITMAP);
18533@@ -148,7 +149,7 @@ void show_regs_common(void)
18534 board = dmi_get_system_info(DMI_BOARD_NAME);
18535
18536 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18537- current->pid, current->comm, print_tainted(),
18538+ task_pid_nr(current), current->comm, print_tainted(),
18539 init_utsname()->release,
18540 (int)strcspn(init_utsname()->version, " "),
18541 init_utsname()->version,
18542@@ -161,6 +162,9 @@ void flush_thread(void)
18543 {
18544 struct task_struct *tsk = current;
18545
18546+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18547+ loadsegment(gs, 0);
18548+#endif
18549 flush_ptrace_hw_breakpoint(tsk);
18550 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18551 drop_fpu(tsk);
18552@@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18553 regs.di = (unsigned long) arg;
18554
18555 #ifdef CONFIG_X86_32
18556- regs.ds = __USER_DS;
18557- regs.es = __USER_DS;
18558+ regs.ds = __KERNEL_DS;
18559+ regs.es = __KERNEL_DS;
18560 regs.fs = __KERNEL_PERCPU;
18561- regs.gs = __KERNEL_STACK_CANARY;
18562+ savesegment(gs, regs.gs);
18563 #else
18564 regs.ss = __KERNEL_DS;
18565 #endif
18566@@ -407,7 +411,7 @@ static void __exit_idle(void)
18567 void exit_idle(void)
18568 {
18569 /* idle loop has pid 0 */
18570- if (current->pid)
18571+ if (task_pid_nr(current))
18572 return;
18573 __exit_idle();
18574 }
18575@@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18576
18577 return ret;
18578 }
18579-void stop_this_cpu(void *dummy)
18580+__noreturn void stop_this_cpu(void *dummy)
18581 {
18582 local_irq_disable();
18583 /*
18584@@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18585 }
18586 early_param("idle", idle_setup);
18587
18588-unsigned long arch_align_stack(unsigned long sp)
18589+#ifdef CONFIG_PAX_RANDKSTACK
18590+void pax_randomize_kstack(struct pt_regs *regs)
18591 {
18592- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18593- sp -= get_random_int() % 8192;
18594- return sp & ~0xf;
18595-}
18596+ struct thread_struct *thread = &current->thread;
18597+ unsigned long time;
18598
18599-unsigned long arch_randomize_brk(struct mm_struct *mm)
18600-{
18601- unsigned long range_end = mm->brk + 0x02000000;
18602- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18603-}
18604+ if (!randomize_va_space)
18605+ return;
18606+
18607+ if (v8086_mode(regs))
18608+ return;
18609
18610+ rdtscl(time);
18611+
18612+ /* P4 seems to return a 0 LSB, ignore it */
18613+#ifdef CONFIG_MPENTIUM4
18614+ time &= 0x3EUL;
18615+ time <<= 2;
18616+#elif defined(CONFIG_X86_64)
18617+ time &= 0xFUL;
18618+ time <<= 4;
18619+#else
18620+ time &= 0x1FUL;
18621+ time <<= 3;
18622+#endif
18623+
18624+ thread->sp0 ^= time;
18625+ load_sp0(init_tss + smp_processor_id(), thread);
18626+
18627+#ifdef CONFIG_X86_64
18628+ this_cpu_write(kernel_stack, thread->sp0);
18629+#endif
18630+}
18631+#endif
18632diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18633index 516fa18..80bd9e6 100644
18634--- a/arch/x86/kernel/process_32.c
18635+++ b/arch/x86/kernel/process_32.c
18636@@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18637 unsigned long thread_saved_pc(struct task_struct *tsk)
18638 {
18639 return ((unsigned long *)tsk->thread.sp)[3];
18640+//XXX return tsk->thread.eip;
18641 }
18642
18643 void __show_regs(struct pt_regs *regs, int all)
18644@@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18645 unsigned long sp;
18646 unsigned short ss, gs;
18647
18648- if (user_mode_vm(regs)) {
18649+ if (user_mode(regs)) {
18650 sp = regs->sp;
18651 ss = regs->ss & 0xffff;
18652- gs = get_user_gs(regs);
18653 } else {
18654 sp = kernel_stack_pointer(regs);
18655 savesegment(ss, ss);
18656- savesegment(gs, gs);
18657 }
18658+ gs = get_user_gs(regs);
18659
18660 show_regs_common();
18661
18662@@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18663 struct task_struct *tsk;
18664 int err;
18665
18666- childregs = task_pt_regs(p);
18667+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18668 *childregs = *regs;
18669 childregs->ax = 0;
18670 childregs->sp = sp;
18671
18672 p->thread.sp = (unsigned long) childregs;
18673 p->thread.sp0 = (unsigned long) (childregs+1);
18674+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18675
18676 p->thread.ip = (unsigned long) ret_from_fork;
18677
18678@@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18679 struct thread_struct *prev = &prev_p->thread,
18680 *next = &next_p->thread;
18681 int cpu = smp_processor_id();
18682- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18683+ struct tss_struct *tss = init_tss + cpu;
18684 fpu_switch_t fpu;
18685
18686 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18687@@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18688 */
18689 lazy_save_gs(prev->gs);
18690
18691+#ifdef CONFIG_PAX_MEMORY_UDEREF
18692+ __set_fs(task_thread_info(next_p)->addr_limit);
18693+#endif
18694+
18695 /*
18696 * Load the per-thread Thread-Local Storage descriptor.
18697 */
18698@@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18699 */
18700 arch_end_context_switch(next_p);
18701
18702+ this_cpu_write(current_task, next_p);
18703+ this_cpu_write(current_tinfo, &next_p->tinfo);
18704+
18705 /*
18706 * Restore %gs if needed (which is common)
18707 */
18708@@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18709
18710 switch_fpu_finish(next_p, fpu);
18711
18712- this_cpu_write(current_task, next_p);
18713-
18714 return prev_p;
18715 }
18716
18717@@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18718 } while (count++ < 16);
18719 return 0;
18720 }
18721-
18722diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18723index 0a980c9..1d0e689 100644
18724--- a/arch/x86/kernel/process_64.c
18725+++ b/arch/x86/kernel/process_64.c
18726@@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18727 struct pt_regs *childregs;
18728 struct task_struct *me = current;
18729
18730- childregs = ((struct pt_regs *)
18731- (THREAD_SIZE + task_stack_page(p))) - 1;
18732+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18733 *childregs = *regs;
18734
18735 childregs->ax = 0;
18736@@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18737 p->thread.sp = (unsigned long) childregs;
18738 p->thread.sp0 = (unsigned long) (childregs+1);
18739 p->thread.usersp = me->thread.usersp;
18740+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18741
18742 set_tsk_thread_flag(p, TIF_FORK);
18743
18744@@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18745 struct thread_struct *prev = &prev_p->thread;
18746 struct thread_struct *next = &next_p->thread;
18747 int cpu = smp_processor_id();
18748- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18749+ struct tss_struct *tss = init_tss + cpu;
18750 unsigned fsindex, gsindex;
18751 fpu_switch_t fpu;
18752
18753@@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18754 prev->usersp = this_cpu_read(old_rsp);
18755 this_cpu_write(old_rsp, next->usersp);
18756 this_cpu_write(current_task, next_p);
18757+ this_cpu_write(current_tinfo, &next_p->tinfo);
18758
18759- this_cpu_write(kernel_stack,
18760- (unsigned long)task_stack_page(next_p) +
18761- THREAD_SIZE - KERNEL_STACK_OFFSET);
18762+ this_cpu_write(kernel_stack, next->sp0);
18763
18764 /*
18765 * Now maybe reload the debug registers and handle I/O bitmaps
18766@@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18767 if (!p || p == current || p->state == TASK_RUNNING)
18768 return 0;
18769 stack = (unsigned long)task_stack_page(p);
18770- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18771+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18772 return 0;
18773 fp = *(u64 *)(p->thread.sp);
18774 do {
18775- if (fp < (unsigned long)stack ||
18776- fp >= (unsigned long)stack+THREAD_SIZE)
18777+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18778 return 0;
18779 ip = *(u64 *)(fp+8);
18780 if (!in_sched_functions(ip))
18781diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18782index c4c6a5c..905f440 100644
18783--- a/arch/x86/kernel/ptrace.c
18784+++ b/arch/x86/kernel/ptrace.c
18785@@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18786 unsigned long addr, unsigned long data)
18787 {
18788 int ret;
18789- unsigned long __user *datap = (unsigned long __user *)data;
18790+ unsigned long __user *datap = (__force unsigned long __user *)data;
18791
18792 switch (request) {
18793 /* read the word at location addr in the USER area. */
18794@@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18795 if ((int) addr < 0)
18796 return -EIO;
18797 ret = do_get_thread_area(child, addr,
18798- (struct user_desc __user *)data);
18799+ (__force struct user_desc __user *) data);
18800 break;
18801
18802 case PTRACE_SET_THREAD_AREA:
18803 if ((int) addr < 0)
18804 return -EIO;
18805 ret = do_set_thread_area(child, addr,
18806- (struct user_desc __user *)data, 0);
18807+ (__force struct user_desc __user *) data, 0);
18808 break;
18809 #endif
18810
18811@@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18812 memset(info, 0, sizeof(*info));
18813 info->si_signo = SIGTRAP;
18814 info->si_code = si_code;
18815- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18816+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18817 }
18818
18819 void user_single_step_siginfo(struct task_struct *tsk,
18820@@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18821 # define IS_IA32 0
18822 #endif
18823
18824+#ifdef CONFIG_GRKERNSEC_SETXID
18825+extern void gr_delayed_cred_worker(void);
18826+#endif
18827+
18828 /*
18829 * We must return the syscall number to actually look up in the table.
18830 * This can be -1L to skip running any syscall at all.
18831@@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18832 {
18833 long ret = 0;
18834
18835+#ifdef CONFIG_GRKERNSEC_SETXID
18836+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18837+ gr_delayed_cred_worker();
18838+#endif
18839+
18840 /*
18841 * If we stepped into a sysenter/syscall insn, it trapped in
18842 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18843@@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18844 {
18845 bool step;
18846
18847+#ifdef CONFIG_GRKERNSEC_SETXID
18848+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18849+ gr_delayed_cred_worker();
18850+#endif
18851+
18852 audit_syscall_exit(regs);
18853
18854 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18855diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18856index 42eb330..139955c 100644
18857--- a/arch/x86/kernel/pvclock.c
18858+++ b/arch/x86/kernel/pvclock.c
18859@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18860 return pv_tsc_khz;
18861 }
18862
18863-static atomic64_t last_value = ATOMIC64_INIT(0);
18864+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18865
18866 void pvclock_resume(void)
18867 {
18868- atomic64_set(&last_value, 0);
18869+ atomic64_set_unchecked(&last_value, 0);
18870 }
18871
18872 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18873@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18874 * updating at the same time, and one of them could be slightly behind,
18875 * making the assumption that last_value always go forward fail to hold.
18876 */
18877- last = atomic64_read(&last_value);
18878+ last = atomic64_read_unchecked(&last_value);
18879 do {
18880 if (ret < last)
18881 return last;
18882- last = atomic64_cmpxchg(&last_value, last, ret);
18883+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18884 } while (unlikely(last != ret));
18885
18886 return ret;
18887diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18888index 52190a9..8074389 100644
18889--- a/arch/x86/kernel/reboot.c
18890+++ b/arch/x86/kernel/reboot.c
18891@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18892 EXPORT_SYMBOL(pm_power_off);
18893
18894 static const struct desc_ptr no_idt = {};
18895-static int reboot_mode;
18896+static unsigned short reboot_mode;
18897 enum reboot_type reboot_type = BOOT_ACPI;
18898 int reboot_force;
18899
18900@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18901
18902 void __noreturn machine_real_restart(unsigned int type)
18903 {
18904+
18905+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18906+ struct desc_struct *gdt;
18907+#endif
18908+
18909 local_irq_disable();
18910
18911 /*
18912@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18913
18914 /* Jump to the identity-mapped low memory code */
18915 #ifdef CONFIG_X86_32
18916- asm volatile("jmpl *%0" : :
18917+
18918+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18919+ gdt = get_cpu_gdt_table(smp_processor_id());
18920+ pax_open_kernel();
18921+#ifdef CONFIG_PAX_MEMORY_UDEREF
18922+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18923+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18924+ loadsegment(ds, __KERNEL_DS);
18925+ loadsegment(es, __KERNEL_DS);
18926+ loadsegment(ss, __KERNEL_DS);
18927+#endif
18928+#ifdef CONFIG_PAX_KERNEXEC
18929+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18930+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18931+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18932+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18933+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18934+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18935+#endif
18936+ pax_close_kernel();
18937+#endif
18938+
18939+ asm volatile("ljmpl *%0" : :
18940 "rm" (real_mode_header->machine_real_restart_asm),
18941 "a" (type));
18942 #else
18943@@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18944 * try to force a triple fault and then cycle between hitting the keyboard
18945 * controller and doing that
18946 */
18947-static void native_machine_emergency_restart(void)
18948+static void __noreturn native_machine_emergency_restart(void)
18949 {
18950 int i;
18951 int attempt = 0;
18952@@ -662,13 +689,13 @@ void native_machine_shutdown(void)
18953 #endif
18954 }
18955
18956-static void __machine_emergency_restart(int emergency)
18957+static void __noreturn __machine_emergency_restart(int emergency)
18958 {
18959 reboot_emergency = emergency;
18960 machine_ops.emergency_restart();
18961 }
18962
18963-static void native_machine_restart(char *__unused)
18964+static void __noreturn native_machine_restart(char *__unused)
18965 {
18966 pr_notice("machine restart\n");
18967
18968@@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
18969 __machine_emergency_restart(0);
18970 }
18971
18972-static void native_machine_halt(void)
18973+static void __noreturn native_machine_halt(void)
18974 {
18975 /* Stop other cpus and apics */
18976 machine_shutdown();
18977@@ -687,7 +714,7 @@ static void native_machine_halt(void)
18978 stop_this_cpu(NULL);
18979 }
18980
18981-static void native_machine_power_off(void)
18982+static void __noreturn native_machine_power_off(void)
18983 {
18984 if (pm_power_off) {
18985 if (!reboot_force)
18986@@ -696,6 +723,7 @@ static void native_machine_power_off(void)
18987 }
18988 /* A fallback in case there is no PM info available */
18989 tboot_shutdown(TB_SHUTDOWN_HALT);
18990+ unreachable();
18991 }
18992
18993 struct machine_ops machine_ops = {
18994diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18995index 7a6f3b3..bed145d7 100644
18996--- a/arch/x86/kernel/relocate_kernel_64.S
18997+++ b/arch/x86/kernel/relocate_kernel_64.S
18998@@ -11,6 +11,7 @@
18999 #include <asm/kexec.h>
19000 #include <asm/processor-flags.h>
19001 #include <asm/pgtable_types.h>
19002+#include <asm/alternative-asm.h>
19003
19004 /*
19005 * Must be relocatable PIC code callable as a C function
19006@@ -160,13 +161,14 @@ identity_mapped:
19007 xorq %rbp, %rbp
19008 xorq %r8, %r8
19009 xorq %r9, %r9
19010- xorq %r10, %r9
19011+ xorq %r10, %r10
19012 xorq %r11, %r11
19013 xorq %r12, %r12
19014 xorq %r13, %r13
19015 xorq %r14, %r14
19016 xorq %r15, %r15
19017
19018+ pax_force_retaddr 0, 1
19019 ret
19020
19021 1:
19022diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19023index f4b9b80..0d05de1 100644
19024--- a/arch/x86/kernel/setup.c
19025+++ b/arch/x86/kernel/setup.c
19026@@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19027
19028 switch (data->type) {
19029 case SETUP_E820_EXT:
19030- parse_e820_ext(data);
19031+ parse_e820_ext((struct setup_data __force_kernel *)data);
19032 break;
19033 case SETUP_DTB:
19034 add_dtb(pa_data);
19035@@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19036 * area (640->1Mb) as ram even though it is not.
19037 * take them out.
19038 */
19039- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19040+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19041 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19042 }
19043
19044@@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19045
19046 if (!boot_params.hdr.root_flags)
19047 root_mountflags &= ~MS_RDONLY;
19048- init_mm.start_code = (unsigned long) _text;
19049- init_mm.end_code = (unsigned long) _etext;
19050+ init_mm.start_code = ktla_ktva((unsigned long) _text);
19051+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
19052 init_mm.end_data = (unsigned long) _edata;
19053 init_mm.brk = _brk_end;
19054
19055- code_resource.start = virt_to_phys(_text);
19056- code_resource.end = virt_to_phys(_etext)-1;
19057- data_resource.start = virt_to_phys(_etext);
19058+ code_resource.start = virt_to_phys(ktla_ktva(_text));
19059+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19060+ data_resource.start = virt_to_phys(_sdata);
19061 data_resource.end = virt_to_phys(_edata)-1;
19062 bss_resource.start = virt_to_phys(&__bss_start);
19063 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19064diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19065index 5cdff03..5810740 100644
19066--- a/arch/x86/kernel/setup_percpu.c
19067+++ b/arch/x86/kernel/setup_percpu.c
19068@@ -21,19 +21,17 @@
19069 #include <asm/cpu.h>
19070 #include <asm/stackprotector.h>
19071
19072-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19073+#ifdef CONFIG_SMP
19074+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19075 EXPORT_PER_CPU_SYMBOL(cpu_number);
19076+#endif
19077
19078-#ifdef CONFIG_X86_64
19079 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19080-#else
19081-#define BOOT_PERCPU_OFFSET 0
19082-#endif
19083
19084 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19085 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19086
19087-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19088+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19089 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19090 };
19091 EXPORT_SYMBOL(__per_cpu_offset);
19092@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19093 {
19094 #ifdef CONFIG_X86_32
19095 struct desc_struct gdt;
19096+ unsigned long base = per_cpu_offset(cpu);
19097
19098- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19099- 0x2 | DESCTYPE_S, 0x8);
19100- gdt.s = 1;
19101+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19102+ 0x83 | DESCTYPE_S, 0xC);
19103 write_gdt_entry(get_cpu_gdt_table(cpu),
19104 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19105 #endif
19106@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19107 /* alrighty, percpu areas up and running */
19108 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19109 for_each_possible_cpu(cpu) {
19110+#ifdef CONFIG_CC_STACKPROTECTOR
19111+#ifdef CONFIG_X86_32
19112+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
19113+#endif
19114+#endif
19115 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19116 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19117 per_cpu(cpu_number, cpu) = cpu;
19118@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19119 */
19120 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19121 #endif
19122+#ifdef CONFIG_CC_STACKPROTECTOR
19123+#ifdef CONFIG_X86_32
19124+ if (!cpu)
19125+ per_cpu(stack_canary.canary, cpu) = canary;
19126+#endif
19127+#endif
19128 /*
19129 * Up to this point, the boot CPU has been using .init.data
19130 * area. Reload any changed state for the boot CPU.
19131diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19132index b280908..6de349e 100644
19133--- a/arch/x86/kernel/signal.c
19134+++ b/arch/x86/kernel/signal.c
19135@@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19136 * Align the stack pointer according to the i386 ABI,
19137 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19138 */
19139- sp = ((sp + 4) & -16ul) - 4;
19140+ sp = ((sp - 12) & -16ul) - 4;
19141 #else /* !CONFIG_X86_32 */
19142 sp = round_down(sp, 16) - 8;
19143 #endif
19144@@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19145 * Return an always-bogus address instead so we will die with SIGSEGV.
19146 */
19147 if (onsigstack && !likely(on_sig_stack(sp)))
19148- return (void __user *)-1L;
19149+ return (__force void __user *)-1L;
19150
19151 /* save i387 state */
19152 if (used_math() && save_i387_xstate(*fpstate) < 0)
19153- return (void __user *)-1L;
19154+ return (__force void __user *)-1L;
19155
19156 return (void __user *)sp;
19157 }
19158@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19159 }
19160
19161 if (current->mm->context.vdso)
19162- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19163+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19164 else
19165- restorer = &frame->retcode;
19166+ restorer = (void __user *)&frame->retcode;
19167 if (ka->sa.sa_flags & SA_RESTORER)
19168 restorer = ka->sa.sa_restorer;
19169
19170@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19171 * reasons and because gdb uses it as a signature to notice
19172 * signal handler stack frames.
19173 */
19174- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19175+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19176
19177 if (err)
19178 return -EFAULT;
19179@@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19180 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19181
19182 /* Set up to return from userspace. */
19183- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19184+ if (current->mm->context.vdso)
19185+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19186+ else
19187+ restorer = (void __user *)&frame->retcode;
19188 if (ka->sa.sa_flags & SA_RESTORER)
19189 restorer = ka->sa.sa_restorer;
19190 put_user_ex(restorer, &frame->pretcode);
19191@@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19192 * reasons and because gdb uses it as a signature to notice
19193 * signal handler stack frames.
19194 */
19195- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19196+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19197 } put_user_catch(err);
19198
19199 if (err)
19200diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19201index 7c5a8c3..88d422f 100644
19202--- a/arch/x86/kernel/smpboot.c
19203+++ b/arch/x86/kernel/smpboot.c
19204@@ -670,6 +670,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19205 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19206 (THREAD_SIZE + task_stack_page(idle))) - 1);
19207 per_cpu(current_task, cpu) = idle;
19208+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
19209
19210 #ifdef CONFIG_X86_32
19211 /* Stack for startup_32 can be just as for start_secondary onwards */
19212@@ -677,11 +678,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19213 #else
19214 clear_tsk_thread_flag(idle, TIF_FORK);
19215 initial_gs = per_cpu_offset(cpu);
19216- per_cpu(kernel_stack, cpu) =
19217- (unsigned long)task_stack_page(idle) -
19218- KERNEL_STACK_OFFSET + THREAD_SIZE;
19219+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19220 #endif
19221+
19222+ pax_open_kernel();
19223 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19224+ pax_close_kernel();
19225+
19226 initial_code = (unsigned long)start_secondary;
19227 stack_start = idle->thread.sp;
19228
19229@@ -817,6 +820,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19230
19231 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19232
19233+#ifdef CONFIG_PAX_PER_CPU_PGD
19234+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19235+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19236+ KERNEL_PGD_PTRS);
19237+#endif
19238+
19239 err = do_boot_cpu(apicid, cpu, tidle);
19240 if (err) {
19241 pr_debug("do_boot_cpu failed %d\n", err);
19242diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19243index c346d11..d43b163 100644
19244--- a/arch/x86/kernel/step.c
19245+++ b/arch/x86/kernel/step.c
19246@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19247 struct desc_struct *desc;
19248 unsigned long base;
19249
19250- seg &= ~7UL;
19251+ seg >>= 3;
19252
19253 mutex_lock(&child->mm->context.lock);
19254- if (unlikely((seg >> 3) >= child->mm->context.size))
19255+ if (unlikely(seg >= child->mm->context.size))
19256 addr = -1L; /* bogus selector, access would fault */
19257 else {
19258 desc = child->mm->context.ldt + seg;
19259@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19260 addr += base;
19261 }
19262 mutex_unlock(&child->mm->context.lock);
19263- }
19264+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19265+ addr = ktla_ktva(addr);
19266
19267 return addr;
19268 }
19269@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19270 unsigned char opcode[15];
19271 unsigned long addr = convert_ip_to_linear(child, regs);
19272
19273+ if (addr == -EINVAL)
19274+ return 0;
19275+
19276 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19277 for (i = 0; i < copied; i++) {
19278 switch (opcode[i]) {
19279diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19280index 0b0cb5f..db6b9ed 100644
19281--- a/arch/x86/kernel/sys_i386_32.c
19282+++ b/arch/x86/kernel/sys_i386_32.c
19283@@ -24,17 +24,224 @@
19284
19285 #include <asm/syscalls.h>
19286
19287-/*
19288- * Do a system call from kernel instead of calling sys_execve so we
19289- * end up with proper pt_regs.
19290- */
19291-int kernel_execve(const char *filename,
19292- const char *const argv[],
19293- const char *const envp[])
19294+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19295 {
19296- long __res;
19297- asm volatile ("int $0x80"
19298- : "=a" (__res)
19299- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19300- return __res;
19301+ unsigned long pax_task_size = TASK_SIZE;
19302+
19303+#ifdef CONFIG_PAX_SEGMEXEC
19304+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19305+ pax_task_size = SEGMEXEC_TASK_SIZE;
19306+#endif
19307+
19308+ if (len > pax_task_size || addr > pax_task_size - len)
19309+ return -EINVAL;
19310+
19311+ return 0;
19312+}
19313+
19314+unsigned long
19315+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19316+ unsigned long len, unsigned long pgoff, unsigned long flags)
19317+{
19318+ struct mm_struct *mm = current->mm;
19319+ struct vm_area_struct *vma;
19320+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19321+
19322+#ifdef CONFIG_PAX_SEGMEXEC
19323+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19324+ pax_task_size = SEGMEXEC_TASK_SIZE;
19325+#endif
19326+
19327+ pax_task_size -= PAGE_SIZE;
19328+
19329+ if (len > pax_task_size)
19330+ return -ENOMEM;
19331+
19332+ if (flags & MAP_FIXED)
19333+ return addr;
19334+
19335+#ifdef CONFIG_PAX_RANDMMAP
19336+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19337+#endif
19338+
19339+ if (addr) {
19340+ addr = PAGE_ALIGN(addr);
19341+ if (pax_task_size - len >= addr) {
19342+ vma = find_vma(mm, addr);
19343+ if (check_heap_stack_gap(vma, addr, len))
19344+ return addr;
19345+ }
19346+ }
19347+ if (len > mm->cached_hole_size) {
19348+ start_addr = addr = mm->free_area_cache;
19349+ } else {
19350+ start_addr = addr = mm->mmap_base;
19351+ mm->cached_hole_size = 0;
19352+ }
19353+
19354+#ifdef CONFIG_PAX_PAGEEXEC
19355+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19356+ start_addr = 0x00110000UL;
19357+
19358+#ifdef CONFIG_PAX_RANDMMAP
19359+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19360+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19361+#endif
19362+
19363+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19364+ start_addr = addr = mm->mmap_base;
19365+ else
19366+ addr = start_addr;
19367+ }
19368+#endif
19369+
19370+full_search:
19371+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19372+ /* At this point: (!vma || addr < vma->vm_end). */
19373+ if (pax_task_size - len < addr) {
19374+ /*
19375+ * Start a new search - just in case we missed
19376+ * some holes.
19377+ */
19378+ if (start_addr != mm->mmap_base) {
19379+ start_addr = addr = mm->mmap_base;
19380+ mm->cached_hole_size = 0;
19381+ goto full_search;
19382+ }
19383+ return -ENOMEM;
19384+ }
19385+ if (check_heap_stack_gap(vma, addr, len))
19386+ break;
19387+ if (addr + mm->cached_hole_size < vma->vm_start)
19388+ mm->cached_hole_size = vma->vm_start - addr;
19389+ addr = vma->vm_end;
19390+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19391+ start_addr = addr = mm->mmap_base;
19392+ mm->cached_hole_size = 0;
19393+ goto full_search;
19394+ }
19395+ }
19396+
19397+ /*
19398+ * Remember the place where we stopped the search:
19399+ */
19400+ mm->free_area_cache = addr + len;
19401+ return addr;
19402+}
19403+
19404+unsigned long
19405+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19406+ const unsigned long len, const unsigned long pgoff,
19407+ const unsigned long flags)
19408+{
19409+ struct vm_area_struct *vma;
19410+ struct mm_struct *mm = current->mm;
19411+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19412+
19413+#ifdef CONFIG_PAX_SEGMEXEC
19414+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19415+ pax_task_size = SEGMEXEC_TASK_SIZE;
19416+#endif
19417+
19418+ pax_task_size -= PAGE_SIZE;
19419+
19420+ /* requested length too big for entire address space */
19421+ if (len > pax_task_size)
19422+ return -ENOMEM;
19423+
19424+ if (flags & MAP_FIXED)
19425+ return addr;
19426+
19427+#ifdef CONFIG_PAX_PAGEEXEC
19428+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19429+ goto bottomup;
19430+#endif
19431+
19432+#ifdef CONFIG_PAX_RANDMMAP
19433+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19434+#endif
19435+
19436+ /* requesting a specific address */
19437+ if (addr) {
19438+ addr = PAGE_ALIGN(addr);
19439+ if (pax_task_size - len >= addr) {
19440+ vma = find_vma(mm, addr);
19441+ if (check_heap_stack_gap(vma, addr, len))
19442+ return addr;
19443+ }
19444+ }
19445+
19446+ /* check if free_area_cache is useful for us */
19447+ if (len <= mm->cached_hole_size) {
19448+ mm->cached_hole_size = 0;
19449+ mm->free_area_cache = mm->mmap_base;
19450+ }
19451+
19452+ /* either no address requested or can't fit in requested address hole */
19453+ addr = mm->free_area_cache;
19454+
19455+ /* make sure it can fit in the remaining address space */
19456+ if (addr > len) {
19457+ vma = find_vma(mm, addr-len);
19458+ if (check_heap_stack_gap(vma, addr - len, len))
19459+ /* remember the address as a hint for next time */
19460+ return (mm->free_area_cache = addr-len);
19461+ }
19462+
19463+ if (mm->mmap_base < len)
19464+ goto bottomup;
19465+
19466+ addr = mm->mmap_base-len;
19467+
19468+ do {
19469+ /*
19470+ * Lookup failure means no vma is above this address,
19471+ * else if new region fits below vma->vm_start,
19472+ * return with success:
19473+ */
19474+ vma = find_vma(mm, addr);
19475+ if (check_heap_stack_gap(vma, addr, len))
19476+ /* remember the address as a hint for next time */
19477+ return (mm->free_area_cache = addr);
19478+
19479+ /* remember the largest hole we saw so far */
19480+ if (addr + mm->cached_hole_size < vma->vm_start)
19481+ mm->cached_hole_size = vma->vm_start - addr;
19482+
19483+ /* try just below the current vma->vm_start */
19484+ addr = skip_heap_stack_gap(vma, len);
19485+ } while (!IS_ERR_VALUE(addr));
19486+
19487+bottomup:
19488+ /*
19489+ * A failed mmap() very likely causes application failure,
19490+ * so fall back to the bottom-up function here. This scenario
19491+ * can happen with large stack limits and large mmap()
19492+ * allocations.
19493+ */
19494+
19495+#ifdef CONFIG_PAX_SEGMEXEC
19496+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19497+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19498+ else
19499+#endif
19500+
19501+ mm->mmap_base = TASK_UNMAPPED_BASE;
19502+
19503+#ifdef CONFIG_PAX_RANDMMAP
19504+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19505+ mm->mmap_base += mm->delta_mmap;
19506+#endif
19507+
19508+ mm->free_area_cache = mm->mmap_base;
19509+ mm->cached_hole_size = ~0UL;
19510+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19511+ /*
19512+ * Restore the topdown base:
19513+ */
19514+ mm->mmap_base = base;
19515+ mm->free_area_cache = base;
19516+ mm->cached_hole_size = ~0UL;
19517+
19518+ return addr;
19519 }
19520diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19521index b4d3c39..82bb73b 100644
19522--- a/arch/x86/kernel/sys_x86_64.c
19523+++ b/arch/x86/kernel/sys_x86_64.c
19524@@ -95,8 +95,8 @@ out:
19525 return error;
19526 }
19527
19528-static void find_start_end(unsigned long flags, unsigned long *begin,
19529- unsigned long *end)
19530+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19531+ unsigned long *begin, unsigned long *end)
19532 {
19533 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19534 unsigned long new_begin;
19535@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19536 *begin = new_begin;
19537 }
19538 } else {
19539- *begin = TASK_UNMAPPED_BASE;
19540+ *begin = mm->mmap_base;
19541 *end = TASK_SIZE;
19542 }
19543 }
19544@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19545 if (flags & MAP_FIXED)
19546 return addr;
19547
19548- find_start_end(flags, &begin, &end);
19549+ find_start_end(mm, flags, &begin, &end);
19550
19551 if (len > end)
19552 return -ENOMEM;
19553
19554+#ifdef CONFIG_PAX_RANDMMAP
19555+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19556+#endif
19557+
19558 if (addr) {
19559 addr = PAGE_ALIGN(addr);
19560 vma = find_vma(mm, addr);
19561- if (end - len >= addr &&
19562- (!vma || addr + len <= vma->vm_start))
19563+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19564 return addr;
19565 }
19566 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19567@@ -172,7 +175,7 @@ full_search:
19568 }
19569 return -ENOMEM;
19570 }
19571- if (!vma || addr + len <= vma->vm_start) {
19572+ if (check_heap_stack_gap(vma, addr, len)) {
19573 /*
19574 * Remember the place where we stopped the search:
19575 */
19576@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19577 {
19578 struct vm_area_struct *vma;
19579 struct mm_struct *mm = current->mm;
19580- unsigned long addr = addr0, start_addr;
19581+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19582
19583 /* requested length too big for entire address space */
19584 if (len > TASK_SIZE)
19585@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19586 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19587 goto bottomup;
19588
19589+#ifdef CONFIG_PAX_RANDMMAP
19590+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19591+#endif
19592+
19593 /* requesting a specific address */
19594 if (addr) {
19595 addr = PAGE_ALIGN(addr);
19596- vma = find_vma(mm, addr);
19597- if (TASK_SIZE - len >= addr &&
19598- (!vma || addr + len <= vma->vm_start))
19599- return addr;
19600+ if (TASK_SIZE - len >= addr) {
19601+ vma = find_vma(mm, addr);
19602+ if (check_heap_stack_gap(vma, addr, len))
19603+ return addr;
19604+ }
19605 }
19606
19607 /* check if free_area_cache is useful for us */
19608@@ -240,7 +248,7 @@ try_again:
19609 * return with success:
19610 */
19611 vma = find_vma(mm, addr);
19612- if (!vma || addr+len <= vma->vm_start)
19613+ if (check_heap_stack_gap(vma, addr, len))
19614 /* remember the address as a hint for next time */
19615 return mm->free_area_cache = addr;
19616
19617@@ -249,8 +257,8 @@ try_again:
19618 mm->cached_hole_size = vma->vm_start - addr;
19619
19620 /* try just below the current vma->vm_start */
19621- addr = vma->vm_start-len;
19622- } while (len < vma->vm_start);
19623+ addr = skip_heap_stack_gap(vma, len);
19624+ } while (!IS_ERR_VALUE(addr));
19625
19626 fail:
19627 /*
19628@@ -270,13 +278,21 @@ bottomup:
19629 * can happen with large stack limits and large mmap()
19630 * allocations.
19631 */
19632+ mm->mmap_base = TASK_UNMAPPED_BASE;
19633+
19634+#ifdef CONFIG_PAX_RANDMMAP
19635+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19636+ mm->mmap_base += mm->delta_mmap;
19637+#endif
19638+
19639+ mm->free_area_cache = mm->mmap_base;
19640 mm->cached_hole_size = ~0UL;
19641- mm->free_area_cache = TASK_UNMAPPED_BASE;
19642 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19643 /*
19644 * Restore the topdown base:
19645 */
19646- mm->free_area_cache = mm->mmap_base;
19647+ mm->mmap_base = base;
19648+ mm->free_area_cache = base;
19649 mm->cached_hole_size = ~0UL;
19650
19651 return addr;
19652diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19653index f84fe00..93fe08f 100644
19654--- a/arch/x86/kernel/tboot.c
19655+++ b/arch/x86/kernel/tboot.c
19656@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19657
19658 void tboot_shutdown(u32 shutdown_type)
19659 {
19660- void (*shutdown)(void);
19661+ void (* __noreturn shutdown)(void);
19662
19663 if (!tboot_enabled())
19664 return;
19665@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19666
19667 switch_to_tboot_pt();
19668
19669- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19670+ shutdown = (void *)tboot->shutdown_entry;
19671 shutdown();
19672
19673 /* should not reach here */
19674@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19675 return 0;
19676 }
19677
19678-static atomic_t ap_wfs_count;
19679+static atomic_unchecked_t ap_wfs_count;
19680
19681 static int tboot_wait_for_aps(int num_aps)
19682 {
19683@@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19684 {
19685 switch (action) {
19686 case CPU_DYING:
19687- atomic_inc(&ap_wfs_count);
19688+ atomic_inc_unchecked(&ap_wfs_count);
19689 if (num_online_cpus() == 1)
19690- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19691+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19692 return NOTIFY_BAD;
19693 break;
19694 }
19695@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19696
19697 tboot_create_trampoline();
19698
19699- atomic_set(&ap_wfs_count, 0);
19700+ atomic_set_unchecked(&ap_wfs_count, 0);
19701 register_hotcpu_notifier(&tboot_cpu_notifier);
19702
19703 acpi_os_set_prepare_sleep(&tboot_sleep);
19704diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19705index 24d3c91..d06b473 100644
19706--- a/arch/x86/kernel/time.c
19707+++ b/arch/x86/kernel/time.c
19708@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19709 {
19710 unsigned long pc = instruction_pointer(regs);
19711
19712- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19713+ if (!user_mode(regs) && in_lock_functions(pc)) {
19714 #ifdef CONFIG_FRAME_POINTER
19715- return *(unsigned long *)(regs->bp + sizeof(long));
19716+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19717 #else
19718 unsigned long *sp =
19719 (unsigned long *)kernel_stack_pointer(regs);
19720@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19721 * or above a saved flags. Eflags has bits 22-31 zero,
19722 * kernel addresses don't.
19723 */
19724+
19725+#ifdef CONFIG_PAX_KERNEXEC
19726+ return ktla_ktva(sp[0]);
19727+#else
19728 if (sp[0] >> 22)
19729 return sp[0];
19730 if (sp[1] >> 22)
19731 return sp[1];
19732 #endif
19733+
19734+#endif
19735 }
19736 return pc;
19737 }
19738diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19739index 9d9d2f9..cad418a 100644
19740--- a/arch/x86/kernel/tls.c
19741+++ b/arch/x86/kernel/tls.c
19742@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19743 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19744 return -EINVAL;
19745
19746+#ifdef CONFIG_PAX_SEGMEXEC
19747+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19748+ return -EINVAL;
19749+#endif
19750+
19751 set_tls_desc(p, idx, &info, 1);
19752
19753 return 0;
19754@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19755
19756 if (kbuf)
19757 info = kbuf;
19758- else if (__copy_from_user(infobuf, ubuf, count))
19759+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19760 return -EFAULT;
19761 else
19762 info = infobuf;
19763diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19764index b481341..5918bbe 100644
19765--- a/arch/x86/kernel/traps.c
19766+++ b/arch/x86/kernel/traps.c
19767@@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19768
19769 /* Do we ignore FPU interrupts ? */
19770 char ignore_fpu_irq;
19771-
19772-/*
19773- * The IDT has to be page-aligned to simplify the Pentium
19774- * F0 0F bug workaround.
19775- */
19776-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19777 #endif
19778
19779 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19780@@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19781 }
19782
19783 static void __kprobes
19784-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19785+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19786 long error_code, siginfo_t *info)
19787 {
19788 struct task_struct *tsk = current;
19789
19790 #ifdef CONFIG_X86_32
19791- if (regs->flags & X86_VM_MASK) {
19792+ if (v8086_mode(regs)) {
19793 /*
19794 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19795 * On nmi (interrupt 2), do_trap should not be called.
19796@@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19797 }
19798 #endif
19799
19800- if (!user_mode(regs))
19801+ if (!user_mode_novm(regs))
19802 goto kernel_trap;
19803
19804 #ifdef CONFIG_X86_32
19805@@ -147,7 +141,7 @@ trap_signal:
19806 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19807 printk_ratelimit()) {
19808 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19809- tsk->comm, tsk->pid, str,
19810+ tsk->comm, task_pid_nr(tsk), str,
19811 regs->ip, regs->sp, error_code);
19812 print_vma_addr(" in ", regs->ip);
19813 pr_cont("\n");
19814@@ -164,8 +158,20 @@ kernel_trap:
19815 if (!fixup_exception(regs)) {
19816 tsk->thread.error_code = error_code;
19817 tsk->thread.trap_nr = trapnr;
19818+
19819+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19820+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19821+ str = "PAX: suspicious stack segment fault";
19822+#endif
19823+
19824 die(str, regs, error_code);
19825 }
19826+
19827+#ifdef CONFIG_PAX_REFCOUNT
19828+ if (trapnr == 4)
19829+ pax_report_refcount_overflow(regs);
19830+#endif
19831+
19832 return;
19833
19834 #ifdef CONFIG_X86_32
19835@@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19836 conditional_sti(regs);
19837
19838 #ifdef CONFIG_X86_32
19839- if (regs->flags & X86_VM_MASK)
19840+ if (v8086_mode(regs))
19841 goto gp_in_vm86;
19842 #endif
19843
19844 tsk = current;
19845- if (!user_mode(regs))
19846+ if (!user_mode_novm(regs))
19847 goto gp_in_kernel;
19848
19849+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19850+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19851+ struct mm_struct *mm = tsk->mm;
19852+ unsigned long limit;
19853+
19854+ down_write(&mm->mmap_sem);
19855+ limit = mm->context.user_cs_limit;
19856+ if (limit < TASK_SIZE) {
19857+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19858+ up_write(&mm->mmap_sem);
19859+ return;
19860+ }
19861+ up_write(&mm->mmap_sem);
19862+ }
19863+#endif
19864+
19865 tsk->thread.error_code = error_code;
19866 tsk->thread.trap_nr = X86_TRAP_GP;
19867
19868@@ -297,6 +319,13 @@ gp_in_kernel:
19869 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19870 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19871 return;
19872+
19873+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19874+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19875+ die("PAX: suspicious general protection fault", regs, error_code);
19876+ else
19877+#endif
19878+
19879 die("general protection fault", regs, error_code);
19880 }
19881
19882@@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19883 /* It's safe to allow irq's after DR6 has been saved */
19884 preempt_conditional_sti(regs);
19885
19886- if (regs->flags & X86_VM_MASK) {
19887+ if (v8086_mode(regs)) {
19888 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19889 X86_TRAP_DB);
19890 preempt_conditional_cli(regs);
19891@@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19892 * We already checked v86 mode above, so we can check for kernel mode
19893 * by just checking the CPL of CS.
19894 */
19895- if ((dr6 & DR_STEP) && !user_mode(regs)) {
19896+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19897 tsk->thread.debugreg6 &= ~DR_STEP;
19898 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19899 regs->flags &= ~X86_EFLAGS_TF;
19900@@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19901 return;
19902 conditional_sti(regs);
19903
19904- if (!user_mode_vm(regs))
19905+ if (!user_mode(regs))
19906 {
19907 if (!fixup_exception(regs)) {
19908 task->thread.error_code = error_code;
19909diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19910index 36fd420..7e5892d 100644
19911--- a/arch/x86/kernel/uprobes.c
19912+++ b/arch/x86/kernel/uprobes.c
19913@@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19914 int ret = NOTIFY_DONE;
19915
19916 /* We are only interested in userspace traps */
19917- if (regs && !user_mode_vm(regs))
19918+ if (regs && !user_mode(regs))
19919 return NOTIFY_DONE;
19920
19921 switch (val) {
19922diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19923index b9242ba..50c5edd 100644
19924--- a/arch/x86/kernel/verify_cpu.S
19925+++ b/arch/x86/kernel/verify_cpu.S
19926@@ -20,6 +20,7 @@
19927 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19928 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19929 * arch/x86/kernel/head_32.S: processor startup
19930+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19931 *
19932 * verify_cpu, returns the status of longmode and SSE in register %eax.
19933 * 0: Success 1: Failure
19934diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19935index 54abcc0..eb6c848 100644
19936--- a/arch/x86/kernel/vm86_32.c
19937+++ b/arch/x86/kernel/vm86_32.c
19938@@ -43,6 +43,7 @@
19939 #include <linux/ptrace.h>
19940 #include <linux/audit.h>
19941 #include <linux/stddef.h>
19942+#include <linux/grsecurity.h>
19943
19944 #include <asm/uaccess.h>
19945 #include <asm/io.h>
19946@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19947 do_exit(SIGSEGV);
19948 }
19949
19950- tss = &per_cpu(init_tss, get_cpu());
19951+ tss = init_tss + get_cpu();
19952 current->thread.sp0 = current->thread.saved_sp0;
19953 current->thread.sysenter_cs = __KERNEL_CS;
19954 load_sp0(tss, &current->thread);
19955@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19956 struct task_struct *tsk;
19957 int tmp, ret = -EPERM;
19958
19959+#ifdef CONFIG_GRKERNSEC_VM86
19960+ if (!capable(CAP_SYS_RAWIO)) {
19961+ gr_handle_vm86();
19962+ goto out;
19963+ }
19964+#endif
19965+
19966 tsk = current;
19967 if (tsk->thread.saved_sp0)
19968 goto out;
19969@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19970 int tmp, ret;
19971 struct vm86plus_struct __user *v86;
19972
19973+#ifdef CONFIG_GRKERNSEC_VM86
19974+ if (!capable(CAP_SYS_RAWIO)) {
19975+ gr_handle_vm86();
19976+ ret = -EPERM;
19977+ goto out;
19978+ }
19979+#endif
19980+
19981 tsk = current;
19982 switch (cmd) {
19983 case VM86_REQUEST_IRQ:
19984@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19985 tsk->thread.saved_fs = info->regs32->fs;
19986 tsk->thread.saved_gs = get_user_gs(info->regs32);
19987
19988- tss = &per_cpu(init_tss, get_cpu());
19989+ tss = init_tss + get_cpu();
19990 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19991 if (cpu_has_sep)
19992 tsk->thread.sysenter_cs = 0;
19993@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19994 goto cannot_handle;
19995 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19996 goto cannot_handle;
19997- intr_ptr = (unsigned long __user *) (i << 2);
19998+ intr_ptr = (__force unsigned long __user *) (i << 2);
19999 if (get_user(segoffs, intr_ptr))
20000 goto cannot_handle;
20001 if ((segoffs >> 16) == BIOSSEG)
20002diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20003index 22a1530..8fbaaad 100644
20004--- a/arch/x86/kernel/vmlinux.lds.S
20005+++ b/arch/x86/kernel/vmlinux.lds.S
20006@@ -26,6 +26,13 @@
20007 #include <asm/page_types.h>
20008 #include <asm/cache.h>
20009 #include <asm/boot.h>
20010+#include <asm/segment.h>
20011+
20012+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20013+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20014+#else
20015+#define __KERNEL_TEXT_OFFSET 0
20016+#endif
20017
20018 #undef i386 /* in case the preprocessor is a 32bit one */
20019
20020@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20021
20022 PHDRS {
20023 text PT_LOAD FLAGS(5); /* R_E */
20024+#ifdef CONFIG_X86_32
20025+ module PT_LOAD FLAGS(5); /* R_E */
20026+#endif
20027+#ifdef CONFIG_XEN
20028+ rodata PT_LOAD FLAGS(5); /* R_E */
20029+#else
20030+ rodata PT_LOAD FLAGS(4); /* R__ */
20031+#endif
20032 data PT_LOAD FLAGS(6); /* RW_ */
20033-#ifdef CONFIG_X86_64
20034+ init.begin PT_LOAD FLAGS(6); /* RW_ */
20035 #ifdef CONFIG_SMP
20036 percpu PT_LOAD FLAGS(6); /* RW_ */
20037 #endif
20038+ text.init PT_LOAD FLAGS(5); /* R_E */
20039+ text.exit PT_LOAD FLAGS(5); /* R_E */
20040 init PT_LOAD FLAGS(7); /* RWE */
20041-#endif
20042 note PT_NOTE FLAGS(0); /* ___ */
20043 }
20044
20045 SECTIONS
20046 {
20047 #ifdef CONFIG_X86_32
20048- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20049- phys_startup_32 = startup_32 - LOAD_OFFSET;
20050+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20051 #else
20052- . = __START_KERNEL;
20053- phys_startup_64 = startup_64 - LOAD_OFFSET;
20054+ . = __START_KERNEL;
20055 #endif
20056
20057 /* Text and read-only data */
20058- .text : AT(ADDR(.text) - LOAD_OFFSET) {
20059- _text = .;
20060+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20061 /* bootstrapping code */
20062+#ifdef CONFIG_X86_32
20063+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20064+#else
20065+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20066+#endif
20067+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20068+ _text = .;
20069 HEAD_TEXT
20070 #ifdef CONFIG_X86_32
20071 . = ALIGN(PAGE_SIZE);
20072@@ -108,13 +128,48 @@ SECTIONS
20073 IRQENTRY_TEXT
20074 *(.fixup)
20075 *(.gnu.warning)
20076- /* End of text section */
20077- _etext = .;
20078 } :text = 0x9090
20079
20080- NOTES :text :note
20081+ . += __KERNEL_TEXT_OFFSET;
20082
20083- EXCEPTION_TABLE(16) :text = 0x9090
20084+#ifdef CONFIG_X86_32
20085+ . = ALIGN(PAGE_SIZE);
20086+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20087+
20088+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20089+ MODULES_EXEC_VADDR = .;
20090+ BYTE(0)
20091+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20092+ . = ALIGN(HPAGE_SIZE) - 1;
20093+ MODULES_EXEC_END = .;
20094+#endif
20095+
20096+ } :module
20097+#endif
20098+
20099+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20100+ /* End of text section */
20101+ BYTE(0)
20102+ _etext = . - __KERNEL_TEXT_OFFSET;
20103+ }
20104+
20105+#ifdef CONFIG_X86_32
20106+ . = ALIGN(PAGE_SIZE);
20107+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20108+ *(.idt)
20109+ . = ALIGN(PAGE_SIZE);
20110+ *(.empty_zero_page)
20111+ *(.initial_pg_fixmap)
20112+ *(.initial_pg_pmd)
20113+ *(.initial_page_table)
20114+ *(.swapper_pg_dir)
20115+ } :rodata
20116+#endif
20117+
20118+ . = ALIGN(PAGE_SIZE);
20119+ NOTES :rodata :note
20120+
20121+ EXCEPTION_TABLE(16) :rodata
20122
20123 #if defined(CONFIG_DEBUG_RODATA)
20124 /* .text should occupy whole number of pages */
20125@@ -126,16 +181,20 @@ SECTIONS
20126
20127 /* Data */
20128 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20129+
20130+#ifdef CONFIG_PAX_KERNEXEC
20131+ . = ALIGN(HPAGE_SIZE);
20132+#else
20133+ . = ALIGN(PAGE_SIZE);
20134+#endif
20135+
20136 /* Start of data section */
20137 _sdata = .;
20138
20139 /* init_task */
20140 INIT_TASK_DATA(THREAD_SIZE)
20141
20142-#ifdef CONFIG_X86_32
20143- /* 32 bit has nosave before _edata */
20144 NOSAVE_DATA
20145-#endif
20146
20147 PAGE_ALIGNED_DATA(PAGE_SIZE)
20148
20149@@ -176,12 +235,19 @@ SECTIONS
20150 #endif /* CONFIG_X86_64 */
20151
20152 /* Init code and data - will be freed after init */
20153- . = ALIGN(PAGE_SIZE);
20154 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20155+ BYTE(0)
20156+
20157+#ifdef CONFIG_PAX_KERNEXEC
20158+ . = ALIGN(HPAGE_SIZE);
20159+#else
20160+ . = ALIGN(PAGE_SIZE);
20161+#endif
20162+
20163 __init_begin = .; /* paired with __init_end */
20164- }
20165+ } :init.begin
20166
20167-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20168+#ifdef CONFIG_SMP
20169 /*
20170 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20171 * output PHDR, so the next output section - .init.text - should
20172@@ -190,12 +256,27 @@ SECTIONS
20173 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20174 #endif
20175
20176- INIT_TEXT_SECTION(PAGE_SIZE)
20177-#ifdef CONFIG_X86_64
20178- :init
20179-#endif
20180+ . = ALIGN(PAGE_SIZE);
20181+ init_begin = .;
20182+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20183+ VMLINUX_SYMBOL(_sinittext) = .;
20184+ INIT_TEXT
20185+ VMLINUX_SYMBOL(_einittext) = .;
20186+ . = ALIGN(PAGE_SIZE);
20187+ } :text.init
20188
20189- INIT_DATA_SECTION(16)
20190+ /*
20191+ * .exit.text is discard at runtime, not link time, to deal with
20192+ * references from .altinstructions and .eh_frame
20193+ */
20194+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20195+ EXIT_TEXT
20196+ . = ALIGN(16);
20197+ } :text.exit
20198+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20199+
20200+ . = ALIGN(PAGE_SIZE);
20201+ INIT_DATA_SECTION(16) :init
20202
20203 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20204 __x86_cpu_dev_start = .;
20205@@ -257,19 +338,12 @@ SECTIONS
20206 }
20207
20208 . = ALIGN(8);
20209- /*
20210- * .exit.text is discard at runtime, not link time, to deal with
20211- * references from .altinstructions and .eh_frame
20212- */
20213- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20214- EXIT_TEXT
20215- }
20216
20217 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20218 EXIT_DATA
20219 }
20220
20221-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20222+#ifndef CONFIG_SMP
20223 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20224 #endif
20225
20226@@ -288,16 +362,10 @@ SECTIONS
20227 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20228 __smp_locks = .;
20229 *(.smp_locks)
20230- . = ALIGN(PAGE_SIZE);
20231 __smp_locks_end = .;
20232+ . = ALIGN(PAGE_SIZE);
20233 }
20234
20235-#ifdef CONFIG_X86_64
20236- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20237- NOSAVE_DATA
20238- }
20239-#endif
20240-
20241 /* BSS */
20242 . = ALIGN(PAGE_SIZE);
20243 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20244@@ -313,6 +381,7 @@ SECTIONS
20245 __brk_base = .;
20246 . += 64 * 1024; /* 64k alignment slop space */
20247 *(.brk_reservation) /* areas brk users have reserved */
20248+ . = ALIGN(HPAGE_SIZE);
20249 __brk_limit = .;
20250 }
20251
20252@@ -339,13 +408,12 @@ SECTIONS
20253 * for the boot processor.
20254 */
20255 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20256-INIT_PER_CPU(gdt_page);
20257 INIT_PER_CPU(irq_stack_union);
20258
20259 /*
20260 * Build-time check on the image size:
20261 */
20262-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20263+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20264 "kernel image bigger than KERNEL_IMAGE_SIZE");
20265
20266 #ifdef CONFIG_SMP
20267diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20268index 992f890..fc38904 100644
20269--- a/arch/x86/kernel/vsmp_64.c
20270+++ b/arch/x86/kernel/vsmp_64.c
20271@@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20272 static void vsmp_apic_post_init(void)
20273 {
20274 /* need to update phys_pkg_id */
20275- apic->phys_pkg_id = apicid_phys_pkg_id;
20276- apic->vector_allocation_domain = fill_vector_allocation_domain;
20277+ *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20278+ *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20279 }
20280
20281 void __init vsmp_init(void)
20282diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20283index 8d141b3..40a0fe4 100644
20284--- a/arch/x86/kernel/vsyscall_64.c
20285+++ b/arch/x86/kernel/vsyscall_64.c
20286@@ -56,15 +56,13 @@
20287 DEFINE_VVAR(int, vgetcpu_mode);
20288 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20289
20290-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20291+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20292
20293 static int __init vsyscall_setup(char *str)
20294 {
20295 if (str) {
20296 if (!strcmp("emulate", str))
20297 vsyscall_mode = EMULATE;
20298- else if (!strcmp("native", str))
20299- vsyscall_mode = NATIVE;
20300 else if (!strcmp("none", str))
20301 vsyscall_mode = NONE;
20302 else
20303@@ -306,8 +304,7 @@ done:
20304 return true;
20305
20306 sigsegv:
20307- force_sig(SIGSEGV, current);
20308- return true;
20309+ do_group_exit(SIGKILL);
20310 }
20311
20312 /*
20313@@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20314 extern char __vvar_page;
20315 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20316
20317- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20318- vsyscall_mode == NATIVE
20319- ? PAGE_KERNEL_VSYSCALL
20320- : PAGE_KERNEL_VVAR);
20321+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20322 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20323 (unsigned long)VSYSCALL_START);
20324
20325diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20326index 6020f6f..bedd6e3 100644
20327--- a/arch/x86/kernel/x8664_ksyms_64.c
20328+++ b/arch/x86/kernel/x8664_ksyms_64.c
20329@@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20330 EXPORT_SYMBOL(copy_user_generic_unrolled);
20331 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20332 EXPORT_SYMBOL(__copy_user_nocache);
20333-EXPORT_SYMBOL(_copy_from_user);
20334-EXPORT_SYMBOL(_copy_to_user);
20335
20336 EXPORT_SYMBOL(copy_page);
20337 EXPORT_SYMBOL(clear_page);
20338diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20339index 3d3e207..1a73ab2 100644
20340--- a/arch/x86/kernel/xsave.c
20341+++ b/arch/x86/kernel/xsave.c
20342@@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20343 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20344 return -EINVAL;
20345
20346- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20347+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20348 fx_sw_user->extended_size -
20349 FP_XSTATE_MAGIC2_SIZE));
20350 if (err)
20351@@ -268,7 +268,7 @@ fx_only:
20352 * the other extended state.
20353 */
20354 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20355- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20356+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20357 }
20358
20359 /*
20360@@ -297,7 +297,7 @@ int restore_i387_xstate(void __user *buf)
20361 if (use_xsave())
20362 err = restore_user_xstate(buf);
20363 else
20364- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20365+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20366 buf);
20367 if (unlikely(err)) {
20368 /*
20369diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20370index 0595f13..b544fa3 100644
20371--- a/arch/x86/kvm/cpuid.c
20372+++ b/arch/x86/kvm/cpuid.c
20373@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20374 struct kvm_cpuid2 *cpuid,
20375 struct kvm_cpuid_entry2 __user *entries)
20376 {
20377- int r;
20378+ int r, i;
20379
20380 r = -E2BIG;
20381 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20382 goto out;
20383 r = -EFAULT;
20384- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20385- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20386+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20387 goto out;
20388+ for (i = 0; i < cpuid->nent; ++i) {
20389+ struct kvm_cpuid_entry2 cpuid_entry;
20390+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20391+ goto out;
20392+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20393+ }
20394 vcpu->arch.cpuid_nent = cpuid->nent;
20395 kvm_apic_set_version(vcpu);
20396 kvm_x86_ops->cpuid_update(vcpu);
20397@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20398 struct kvm_cpuid2 *cpuid,
20399 struct kvm_cpuid_entry2 __user *entries)
20400 {
20401- int r;
20402+ int r, i;
20403
20404 r = -E2BIG;
20405 if (cpuid->nent < vcpu->arch.cpuid_nent)
20406 goto out;
20407 r = -EFAULT;
20408- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20409- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20410+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20411 goto out;
20412+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20413+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20414+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20415+ goto out;
20416+ }
20417 return 0;
20418
20419 out:
20420diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20421index a3b57a2..ebbe732 100644
20422--- a/arch/x86/kvm/emulate.c
20423+++ b/arch/x86/kvm/emulate.c
20424@@ -256,6 +256,7 @@ struct gprefix {
20425
20426 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20427 do { \
20428+ unsigned long _tmp; \
20429 __asm__ __volatile__ ( \
20430 _PRE_EFLAGS("0", "4", "2") \
20431 _op _suffix " %"_x"3,%1; " \
20432@@ -270,8 +271,6 @@ struct gprefix {
20433 /* Raw emulation: instruction has two explicit operands. */
20434 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20435 do { \
20436- unsigned long _tmp; \
20437- \
20438 switch ((ctxt)->dst.bytes) { \
20439 case 2: \
20440 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20441@@ -287,7 +286,6 @@ struct gprefix {
20442
20443 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20444 do { \
20445- unsigned long _tmp; \
20446 switch ((ctxt)->dst.bytes) { \
20447 case 1: \
20448 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20449diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20450index ce87878..ab48aa3 100644
20451--- a/arch/x86/kvm/lapic.c
20452+++ b/arch/x86/kvm/lapic.c
20453@@ -54,7 +54,7 @@
20454 #define APIC_BUS_CYCLE_NS 1
20455
20456 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20457-#define apic_debug(fmt, arg...)
20458+#define apic_debug(fmt, arg...) do {} while (0)
20459
20460 #define APIC_LVT_NUM 6
20461 /* 14 is the version for Xeon and Pentium 8.4.8*/
20462diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20463index bb7cf01..0348a05 100644
20464--- a/arch/x86/kvm/paging_tmpl.h
20465+++ b/arch/x86/kvm/paging_tmpl.h
20466@@ -196,7 +196,7 @@ retry_walk:
20467 if (unlikely(kvm_is_error_hva(host_addr)))
20468 goto error;
20469
20470- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20471+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20472 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20473 goto error;
20474
20475diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20476index baead95..90feeb4 100644
20477--- a/arch/x86/kvm/svm.c
20478+++ b/arch/x86/kvm/svm.c
20479@@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20480 int cpu = raw_smp_processor_id();
20481
20482 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20483+
20484+ pax_open_kernel();
20485 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20486+ pax_close_kernel();
20487+
20488 load_TR_desc();
20489 }
20490
20491@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20492 #endif
20493 #endif
20494
20495+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20496+ __set_fs(current_thread_info()->addr_limit);
20497+#endif
20498+
20499 reload_tss(vcpu);
20500
20501 local_irq_disable();
20502diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20503index b1eb202..254e292 100644
20504--- a/arch/x86/kvm/vmx.c
20505+++ b/arch/x86/kvm/vmx.c
20506@@ -1331,7 +1331,11 @@ static void reload_tss(void)
20507 struct desc_struct *descs;
20508
20509 descs = (void *)gdt->address;
20510+
20511+ pax_open_kernel();
20512 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20513+ pax_close_kernel();
20514+
20515 load_TR_desc();
20516 }
20517
20518@@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20519 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20520 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20521
20522+#ifdef CONFIG_PAX_PER_CPU_PGD
20523+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20524+#endif
20525+
20526 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20527 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20528 vmx->loaded_vmcs->cpu = cpu;
20529@@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20530 if (!cpu_has_vmx_flexpriority())
20531 flexpriority_enabled = 0;
20532
20533- if (!cpu_has_vmx_tpr_shadow())
20534- kvm_x86_ops->update_cr8_intercept = NULL;
20535+ if (!cpu_has_vmx_tpr_shadow()) {
20536+ pax_open_kernel();
20537+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20538+ pax_close_kernel();
20539+ }
20540
20541 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20542 kvm_disable_largepages();
20543@@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20544
20545 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20546 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20547+
20548+#ifndef CONFIG_PAX_PER_CPU_PGD
20549 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20550+#endif
20551
20552 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20553 #ifdef CONFIG_X86_64
20554@@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20555 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20556
20557 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20558- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20559+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20560
20561 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20562 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20563@@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20564 "jmp .Lkvm_vmx_return \n\t"
20565 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20566 ".Lkvm_vmx_return: "
20567+
20568+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20569+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20570+ ".Lkvm_vmx_return2: "
20571+#endif
20572+
20573 /* Save guest registers, load host registers, keep flags */
20574 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20575 "pop %0 \n\t"
20576@@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20577 #endif
20578 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20579 [wordsize]"i"(sizeof(ulong))
20580+
20581+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20582+ ,[cs]"i"(__KERNEL_CS)
20583+#endif
20584+
20585 : "cc", "memory"
20586 , R"ax", R"bx", R"di", R"si"
20587 #ifdef CONFIG_X86_64
20588@@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20589 #endif
20590 );
20591
20592-#ifndef CONFIG_X86_64
20593+#ifdef CONFIG_X86_32
20594 /*
20595 * The sysexit path does not restore ds/es, so we must set them to
20596 * a reasonable value ourselves.
20597@@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20598 * may be executed in interrupt context, which saves and restore segments
20599 * around it, nullifying its effect.
20600 */
20601- loadsegment(ds, __USER_DS);
20602- loadsegment(es, __USER_DS);
20603+ loadsegment(ds, __KERNEL_DS);
20604+ loadsegment(es, __KERNEL_DS);
20605+ loadsegment(ss, __KERNEL_DS);
20606+
20607+#ifdef CONFIG_PAX_KERNEXEC
20608+ loadsegment(fs, __KERNEL_PERCPU);
20609+#endif
20610+
20611+#ifdef CONFIG_PAX_MEMORY_UDEREF
20612+ __set_fs(current_thread_info()->addr_limit);
20613+#endif
20614+
20615 #endif
20616
20617 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20618diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20619index 2966c84..207d0cb 100644
20620--- a/arch/x86/kvm/x86.c
20621+++ b/arch/x86/kvm/x86.c
20622@@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20623 {
20624 struct kvm *kvm = vcpu->kvm;
20625 int lm = is_long_mode(vcpu);
20626- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20627- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20628+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20629+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20630 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20631 : kvm->arch.xen_hvm_config.blob_size_32;
20632 u32 page_num = data & ~PAGE_MASK;
20633@@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20634 if (n < msr_list.nmsrs)
20635 goto out;
20636 r = -EFAULT;
20637+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20638+ goto out;
20639 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20640 num_msrs_to_save * sizeof(u32)))
20641 goto out;
20642@@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20643 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20644 struct kvm_interrupt *irq)
20645 {
20646- if (irq->irq < 0 || irq->irq >= 256)
20647+ if (irq->irq >= 256)
20648 return -EINVAL;
20649 if (irqchip_in_kernel(vcpu->kvm))
20650 return -ENXIO;
20651@@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20652 kvm_mmu_set_mmio_spte_mask(mask);
20653 }
20654
20655-int kvm_arch_init(void *opaque)
20656+int kvm_arch_init(const void *opaque)
20657 {
20658 int r;
20659 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20660diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20661index 642d880..cc9ebac 100644
20662--- a/arch/x86/lguest/boot.c
20663+++ b/arch/x86/lguest/boot.c
20664@@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20665
20666 static void set_lguest_basic_apic_ops(void)
20667 {
20668- apic->read = lguest_apic_read;
20669- apic->write = lguest_apic_write;
20670- apic->icr_read = lguest_apic_icr_read;
20671- apic->icr_write = lguest_apic_icr_write;
20672- apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20673- apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20674+ *(void **)&apic->read = lguest_apic_read;
20675+ *(void **)&apic->write = lguest_apic_write;
20676+ *(void **)&apic->icr_read = lguest_apic_icr_read;
20677+ *(void **)&apic->icr_write = lguest_apic_icr_write;
20678+ *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20679+ *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20680 };
20681 #endif
20682
20683@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20684 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20685 * Launcher to reboot us.
20686 */
20687-static void lguest_restart(char *reason)
20688+static __noreturn void lguest_restart(char *reason)
20689 {
20690 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20691+ BUG();
20692 }
20693
20694 /*G:050
20695diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20696index 00933d5..3a64af9 100644
20697--- a/arch/x86/lib/atomic64_386_32.S
20698+++ b/arch/x86/lib/atomic64_386_32.S
20699@@ -48,6 +48,10 @@ BEGIN(read)
20700 movl (v), %eax
20701 movl 4(v), %edx
20702 RET_ENDP
20703+BEGIN(read_unchecked)
20704+ movl (v), %eax
20705+ movl 4(v), %edx
20706+RET_ENDP
20707 #undef v
20708
20709 #define v %esi
20710@@ -55,6 +59,10 @@ BEGIN(set)
20711 movl %ebx, (v)
20712 movl %ecx, 4(v)
20713 RET_ENDP
20714+BEGIN(set_unchecked)
20715+ movl %ebx, (v)
20716+ movl %ecx, 4(v)
20717+RET_ENDP
20718 #undef v
20719
20720 #define v %esi
20721@@ -70,6 +78,20 @@ RET_ENDP
20722 BEGIN(add)
20723 addl %eax, (v)
20724 adcl %edx, 4(v)
20725+
20726+#ifdef CONFIG_PAX_REFCOUNT
20727+ jno 0f
20728+ subl %eax, (v)
20729+ sbbl %edx, 4(v)
20730+ int $4
20731+0:
20732+ _ASM_EXTABLE(0b, 0b)
20733+#endif
20734+
20735+RET_ENDP
20736+BEGIN(add_unchecked)
20737+ addl %eax, (v)
20738+ adcl %edx, 4(v)
20739 RET_ENDP
20740 #undef v
20741
20742@@ -77,6 +99,24 @@ RET_ENDP
20743 BEGIN(add_return)
20744 addl (v), %eax
20745 adcl 4(v), %edx
20746+
20747+#ifdef CONFIG_PAX_REFCOUNT
20748+ into
20749+1234:
20750+ _ASM_EXTABLE(1234b, 2f)
20751+#endif
20752+
20753+ movl %eax, (v)
20754+ movl %edx, 4(v)
20755+
20756+#ifdef CONFIG_PAX_REFCOUNT
20757+2:
20758+#endif
20759+
20760+RET_ENDP
20761+BEGIN(add_return_unchecked)
20762+ addl (v), %eax
20763+ adcl 4(v), %edx
20764 movl %eax, (v)
20765 movl %edx, 4(v)
20766 RET_ENDP
20767@@ -86,6 +126,20 @@ RET_ENDP
20768 BEGIN(sub)
20769 subl %eax, (v)
20770 sbbl %edx, 4(v)
20771+
20772+#ifdef CONFIG_PAX_REFCOUNT
20773+ jno 0f
20774+ addl %eax, (v)
20775+ adcl %edx, 4(v)
20776+ int $4
20777+0:
20778+ _ASM_EXTABLE(0b, 0b)
20779+#endif
20780+
20781+RET_ENDP
20782+BEGIN(sub_unchecked)
20783+ subl %eax, (v)
20784+ sbbl %edx, 4(v)
20785 RET_ENDP
20786 #undef v
20787
20788@@ -96,6 +150,27 @@ BEGIN(sub_return)
20789 sbbl $0, %edx
20790 addl (v), %eax
20791 adcl 4(v), %edx
20792+
20793+#ifdef CONFIG_PAX_REFCOUNT
20794+ into
20795+1234:
20796+ _ASM_EXTABLE(1234b, 2f)
20797+#endif
20798+
20799+ movl %eax, (v)
20800+ movl %edx, 4(v)
20801+
20802+#ifdef CONFIG_PAX_REFCOUNT
20803+2:
20804+#endif
20805+
20806+RET_ENDP
20807+BEGIN(sub_return_unchecked)
20808+ negl %edx
20809+ negl %eax
20810+ sbbl $0, %edx
20811+ addl (v), %eax
20812+ adcl 4(v), %edx
20813 movl %eax, (v)
20814 movl %edx, 4(v)
20815 RET_ENDP
20816@@ -105,6 +180,20 @@ RET_ENDP
20817 BEGIN(inc)
20818 addl $1, (v)
20819 adcl $0, 4(v)
20820+
20821+#ifdef CONFIG_PAX_REFCOUNT
20822+ jno 0f
20823+ subl $1, (v)
20824+ sbbl $0, 4(v)
20825+ int $4
20826+0:
20827+ _ASM_EXTABLE(0b, 0b)
20828+#endif
20829+
20830+RET_ENDP
20831+BEGIN(inc_unchecked)
20832+ addl $1, (v)
20833+ adcl $0, 4(v)
20834 RET_ENDP
20835 #undef v
20836
20837@@ -114,6 +203,26 @@ BEGIN(inc_return)
20838 movl 4(v), %edx
20839 addl $1, %eax
20840 adcl $0, %edx
20841+
20842+#ifdef CONFIG_PAX_REFCOUNT
20843+ into
20844+1234:
20845+ _ASM_EXTABLE(1234b, 2f)
20846+#endif
20847+
20848+ movl %eax, (v)
20849+ movl %edx, 4(v)
20850+
20851+#ifdef CONFIG_PAX_REFCOUNT
20852+2:
20853+#endif
20854+
20855+RET_ENDP
20856+BEGIN(inc_return_unchecked)
20857+ movl (v), %eax
20858+ movl 4(v), %edx
20859+ addl $1, %eax
20860+ adcl $0, %edx
20861 movl %eax, (v)
20862 movl %edx, 4(v)
20863 RET_ENDP
20864@@ -123,6 +232,20 @@ RET_ENDP
20865 BEGIN(dec)
20866 subl $1, (v)
20867 sbbl $0, 4(v)
20868+
20869+#ifdef CONFIG_PAX_REFCOUNT
20870+ jno 0f
20871+ addl $1, (v)
20872+ adcl $0, 4(v)
20873+ int $4
20874+0:
20875+ _ASM_EXTABLE(0b, 0b)
20876+#endif
20877+
20878+RET_ENDP
20879+BEGIN(dec_unchecked)
20880+ subl $1, (v)
20881+ sbbl $0, 4(v)
20882 RET_ENDP
20883 #undef v
20884
20885@@ -132,6 +255,26 @@ BEGIN(dec_return)
20886 movl 4(v), %edx
20887 subl $1, %eax
20888 sbbl $0, %edx
20889+
20890+#ifdef CONFIG_PAX_REFCOUNT
20891+ into
20892+1234:
20893+ _ASM_EXTABLE(1234b, 2f)
20894+#endif
20895+
20896+ movl %eax, (v)
20897+ movl %edx, 4(v)
20898+
20899+#ifdef CONFIG_PAX_REFCOUNT
20900+2:
20901+#endif
20902+
20903+RET_ENDP
20904+BEGIN(dec_return_unchecked)
20905+ movl (v), %eax
20906+ movl 4(v), %edx
20907+ subl $1, %eax
20908+ sbbl $0, %edx
20909 movl %eax, (v)
20910 movl %edx, 4(v)
20911 RET_ENDP
20912@@ -143,6 +286,13 @@ BEGIN(add_unless)
20913 adcl %edx, %edi
20914 addl (v), %eax
20915 adcl 4(v), %edx
20916+
20917+#ifdef CONFIG_PAX_REFCOUNT
20918+ into
20919+1234:
20920+ _ASM_EXTABLE(1234b, 2f)
20921+#endif
20922+
20923 cmpl %eax, %ecx
20924 je 3f
20925 1:
20926@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20927 1:
20928 addl $1, %eax
20929 adcl $0, %edx
20930+
20931+#ifdef CONFIG_PAX_REFCOUNT
20932+ into
20933+1234:
20934+ _ASM_EXTABLE(1234b, 2f)
20935+#endif
20936+
20937 movl %eax, (v)
20938 movl %edx, 4(v)
20939 movl $1, %eax
20940@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20941 movl 4(v), %edx
20942 subl $1, %eax
20943 sbbl $0, %edx
20944+
20945+#ifdef CONFIG_PAX_REFCOUNT
20946+ into
20947+1234:
20948+ _ASM_EXTABLE(1234b, 1f)
20949+#endif
20950+
20951 js 1f
20952 movl %eax, (v)
20953 movl %edx, 4(v)
20954diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20955index f5cc9eb..51fa319 100644
20956--- a/arch/x86/lib/atomic64_cx8_32.S
20957+++ b/arch/x86/lib/atomic64_cx8_32.S
20958@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20959 CFI_STARTPROC
20960
20961 read64 %ecx
20962+ pax_force_retaddr
20963 ret
20964 CFI_ENDPROC
20965 ENDPROC(atomic64_read_cx8)
20966
20967+ENTRY(atomic64_read_unchecked_cx8)
20968+ CFI_STARTPROC
20969+
20970+ read64 %ecx
20971+ pax_force_retaddr
20972+ ret
20973+ CFI_ENDPROC
20974+ENDPROC(atomic64_read_unchecked_cx8)
20975+
20976 ENTRY(atomic64_set_cx8)
20977 CFI_STARTPROC
20978
20979@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20980 cmpxchg8b (%esi)
20981 jne 1b
20982
20983+ pax_force_retaddr
20984 ret
20985 CFI_ENDPROC
20986 ENDPROC(atomic64_set_cx8)
20987
20988+ENTRY(atomic64_set_unchecked_cx8)
20989+ CFI_STARTPROC
20990+
20991+1:
20992+/* we don't need LOCK_PREFIX since aligned 64-bit writes
20993+ * are atomic on 586 and newer */
20994+ cmpxchg8b (%esi)
20995+ jne 1b
20996+
20997+ pax_force_retaddr
20998+ ret
20999+ CFI_ENDPROC
21000+ENDPROC(atomic64_set_unchecked_cx8)
21001+
21002 ENTRY(atomic64_xchg_cx8)
21003 CFI_STARTPROC
21004
21005@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21006 cmpxchg8b (%esi)
21007 jne 1b
21008
21009+ pax_force_retaddr
21010 ret
21011 CFI_ENDPROC
21012 ENDPROC(atomic64_xchg_cx8)
21013
21014-.macro addsub_return func ins insc
21015-ENTRY(atomic64_\func\()_return_cx8)
21016+.macro addsub_return func ins insc unchecked=""
21017+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21018 CFI_STARTPROC
21019 SAVE ebp
21020 SAVE ebx
21021@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21022 movl %edx, %ecx
21023 \ins\()l %esi, %ebx
21024 \insc\()l %edi, %ecx
21025+
21026+.ifb \unchecked
21027+#ifdef CONFIG_PAX_REFCOUNT
21028+ into
21029+2:
21030+ _ASM_EXTABLE(2b, 3f)
21031+#endif
21032+.endif
21033+
21034 LOCK_PREFIX
21035 cmpxchg8b (%ebp)
21036 jne 1b
21037-
21038-10:
21039 movl %ebx, %eax
21040 movl %ecx, %edx
21041+
21042+.ifb \unchecked
21043+#ifdef CONFIG_PAX_REFCOUNT
21044+3:
21045+#endif
21046+.endif
21047+
21048 RESTORE edi
21049 RESTORE esi
21050 RESTORE ebx
21051 RESTORE ebp
21052+ pax_force_retaddr
21053 ret
21054 CFI_ENDPROC
21055-ENDPROC(atomic64_\func\()_return_cx8)
21056+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21057 .endm
21058
21059 addsub_return add add adc
21060 addsub_return sub sub sbb
21061+addsub_return add add adc _unchecked
21062+addsub_return sub sub sbb _unchecked
21063
21064-.macro incdec_return func ins insc
21065-ENTRY(atomic64_\func\()_return_cx8)
21066+.macro incdec_return func ins insc unchecked=""
21067+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21068 CFI_STARTPROC
21069 SAVE ebx
21070
21071@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21072 movl %edx, %ecx
21073 \ins\()l $1, %ebx
21074 \insc\()l $0, %ecx
21075+
21076+.ifb \unchecked
21077+#ifdef CONFIG_PAX_REFCOUNT
21078+ into
21079+2:
21080+ _ASM_EXTABLE(2b, 3f)
21081+#endif
21082+.endif
21083+
21084 LOCK_PREFIX
21085 cmpxchg8b (%esi)
21086 jne 1b
21087
21088-10:
21089 movl %ebx, %eax
21090 movl %ecx, %edx
21091+
21092+.ifb \unchecked
21093+#ifdef CONFIG_PAX_REFCOUNT
21094+3:
21095+#endif
21096+.endif
21097+
21098 RESTORE ebx
21099+ pax_force_retaddr
21100 ret
21101 CFI_ENDPROC
21102-ENDPROC(atomic64_\func\()_return_cx8)
21103+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21104 .endm
21105
21106 incdec_return inc add adc
21107 incdec_return dec sub sbb
21108+incdec_return inc add adc _unchecked
21109+incdec_return dec sub sbb _unchecked
21110
21111 ENTRY(atomic64_dec_if_positive_cx8)
21112 CFI_STARTPROC
21113@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21114 movl %edx, %ecx
21115 subl $1, %ebx
21116 sbb $0, %ecx
21117+
21118+#ifdef CONFIG_PAX_REFCOUNT
21119+ into
21120+1234:
21121+ _ASM_EXTABLE(1234b, 2f)
21122+#endif
21123+
21124 js 2f
21125 LOCK_PREFIX
21126 cmpxchg8b (%esi)
21127@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21128 movl %ebx, %eax
21129 movl %ecx, %edx
21130 RESTORE ebx
21131+ pax_force_retaddr
21132 ret
21133 CFI_ENDPROC
21134 ENDPROC(atomic64_dec_if_positive_cx8)
21135@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21136 movl %edx, %ecx
21137 addl %ebp, %ebx
21138 adcl %edi, %ecx
21139+
21140+#ifdef CONFIG_PAX_REFCOUNT
21141+ into
21142+1234:
21143+ _ASM_EXTABLE(1234b, 3f)
21144+#endif
21145+
21146 LOCK_PREFIX
21147 cmpxchg8b (%esi)
21148 jne 1b
21149@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21150 CFI_ADJUST_CFA_OFFSET -8
21151 RESTORE ebx
21152 RESTORE ebp
21153+ pax_force_retaddr
21154 ret
21155 4:
21156 cmpl %edx, 4(%esp)
21157@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21158 xorl %ecx, %ecx
21159 addl $1, %ebx
21160 adcl %edx, %ecx
21161+
21162+#ifdef CONFIG_PAX_REFCOUNT
21163+ into
21164+1234:
21165+ _ASM_EXTABLE(1234b, 3f)
21166+#endif
21167+
21168 LOCK_PREFIX
21169 cmpxchg8b (%esi)
21170 jne 1b
21171@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21172 movl $1, %eax
21173 3:
21174 RESTORE ebx
21175+ pax_force_retaddr
21176 ret
21177 CFI_ENDPROC
21178 ENDPROC(atomic64_inc_not_zero_cx8)
21179diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21180index 2af5df3..62b1a5a 100644
21181--- a/arch/x86/lib/checksum_32.S
21182+++ b/arch/x86/lib/checksum_32.S
21183@@ -29,7 +29,8 @@
21184 #include <asm/dwarf2.h>
21185 #include <asm/errno.h>
21186 #include <asm/asm.h>
21187-
21188+#include <asm/segment.h>
21189+
21190 /*
21191 * computes a partial checksum, e.g. for TCP/UDP fragments
21192 */
21193@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21194
21195 #define ARGBASE 16
21196 #define FP 12
21197-
21198-ENTRY(csum_partial_copy_generic)
21199+
21200+ENTRY(csum_partial_copy_generic_to_user)
21201 CFI_STARTPROC
21202+
21203+#ifdef CONFIG_PAX_MEMORY_UDEREF
21204+ pushl_cfi %gs
21205+ popl_cfi %es
21206+ jmp csum_partial_copy_generic
21207+#endif
21208+
21209+ENTRY(csum_partial_copy_generic_from_user)
21210+
21211+#ifdef CONFIG_PAX_MEMORY_UDEREF
21212+ pushl_cfi %gs
21213+ popl_cfi %ds
21214+#endif
21215+
21216+ENTRY(csum_partial_copy_generic)
21217 subl $4,%esp
21218 CFI_ADJUST_CFA_OFFSET 4
21219 pushl_cfi %edi
21220@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21221 jmp 4f
21222 SRC(1: movw (%esi), %bx )
21223 addl $2, %esi
21224-DST( movw %bx, (%edi) )
21225+DST( movw %bx, %es:(%edi) )
21226 addl $2, %edi
21227 addw %bx, %ax
21228 adcl $0, %eax
21229@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21230 SRC(1: movl (%esi), %ebx )
21231 SRC( movl 4(%esi), %edx )
21232 adcl %ebx, %eax
21233-DST( movl %ebx, (%edi) )
21234+DST( movl %ebx, %es:(%edi) )
21235 adcl %edx, %eax
21236-DST( movl %edx, 4(%edi) )
21237+DST( movl %edx, %es:4(%edi) )
21238
21239 SRC( movl 8(%esi), %ebx )
21240 SRC( movl 12(%esi), %edx )
21241 adcl %ebx, %eax
21242-DST( movl %ebx, 8(%edi) )
21243+DST( movl %ebx, %es:8(%edi) )
21244 adcl %edx, %eax
21245-DST( movl %edx, 12(%edi) )
21246+DST( movl %edx, %es:12(%edi) )
21247
21248 SRC( movl 16(%esi), %ebx )
21249 SRC( movl 20(%esi), %edx )
21250 adcl %ebx, %eax
21251-DST( movl %ebx, 16(%edi) )
21252+DST( movl %ebx, %es:16(%edi) )
21253 adcl %edx, %eax
21254-DST( movl %edx, 20(%edi) )
21255+DST( movl %edx, %es:20(%edi) )
21256
21257 SRC( movl 24(%esi), %ebx )
21258 SRC( movl 28(%esi), %edx )
21259 adcl %ebx, %eax
21260-DST( movl %ebx, 24(%edi) )
21261+DST( movl %ebx, %es:24(%edi) )
21262 adcl %edx, %eax
21263-DST( movl %edx, 28(%edi) )
21264+DST( movl %edx, %es:28(%edi) )
21265
21266 lea 32(%esi), %esi
21267 lea 32(%edi), %edi
21268@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21269 shrl $2, %edx # This clears CF
21270 SRC(3: movl (%esi), %ebx )
21271 adcl %ebx, %eax
21272-DST( movl %ebx, (%edi) )
21273+DST( movl %ebx, %es:(%edi) )
21274 lea 4(%esi), %esi
21275 lea 4(%edi), %edi
21276 dec %edx
21277@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21278 jb 5f
21279 SRC( movw (%esi), %cx )
21280 leal 2(%esi), %esi
21281-DST( movw %cx, (%edi) )
21282+DST( movw %cx, %es:(%edi) )
21283 leal 2(%edi), %edi
21284 je 6f
21285 shll $16,%ecx
21286 SRC(5: movb (%esi), %cl )
21287-DST( movb %cl, (%edi) )
21288+DST( movb %cl, %es:(%edi) )
21289 6: addl %ecx, %eax
21290 adcl $0, %eax
21291 7:
21292@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21293
21294 6001:
21295 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21296- movl $-EFAULT, (%ebx)
21297+ movl $-EFAULT, %ss:(%ebx)
21298
21299 # zero the complete destination - computing the rest
21300 # is too much work
21301@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21302
21303 6002:
21304 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21305- movl $-EFAULT,(%ebx)
21306+ movl $-EFAULT,%ss:(%ebx)
21307 jmp 5000b
21308
21309 .previous
21310
21311+ pushl_cfi %ss
21312+ popl_cfi %ds
21313+ pushl_cfi %ss
21314+ popl_cfi %es
21315 popl_cfi %ebx
21316 CFI_RESTORE ebx
21317 popl_cfi %esi
21318@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21319 popl_cfi %ecx # equivalent to addl $4,%esp
21320 ret
21321 CFI_ENDPROC
21322-ENDPROC(csum_partial_copy_generic)
21323+ENDPROC(csum_partial_copy_generic_to_user)
21324
21325 #else
21326
21327 /* Version for PentiumII/PPro */
21328
21329 #define ROUND1(x) \
21330+ nop; nop; nop; \
21331 SRC(movl x(%esi), %ebx ) ; \
21332 addl %ebx, %eax ; \
21333- DST(movl %ebx, x(%edi) ) ;
21334+ DST(movl %ebx, %es:x(%edi)) ;
21335
21336 #define ROUND(x) \
21337+ nop; nop; nop; \
21338 SRC(movl x(%esi), %ebx ) ; \
21339 adcl %ebx, %eax ; \
21340- DST(movl %ebx, x(%edi) ) ;
21341+ DST(movl %ebx, %es:x(%edi)) ;
21342
21343 #define ARGBASE 12
21344-
21345-ENTRY(csum_partial_copy_generic)
21346+
21347+ENTRY(csum_partial_copy_generic_to_user)
21348 CFI_STARTPROC
21349+
21350+#ifdef CONFIG_PAX_MEMORY_UDEREF
21351+ pushl_cfi %gs
21352+ popl_cfi %es
21353+ jmp csum_partial_copy_generic
21354+#endif
21355+
21356+ENTRY(csum_partial_copy_generic_from_user)
21357+
21358+#ifdef CONFIG_PAX_MEMORY_UDEREF
21359+ pushl_cfi %gs
21360+ popl_cfi %ds
21361+#endif
21362+
21363+ENTRY(csum_partial_copy_generic)
21364 pushl_cfi %ebx
21365 CFI_REL_OFFSET ebx, 0
21366 pushl_cfi %edi
21367@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21368 subl %ebx, %edi
21369 lea -1(%esi),%edx
21370 andl $-32,%edx
21371- lea 3f(%ebx,%ebx), %ebx
21372+ lea 3f(%ebx,%ebx,2), %ebx
21373 testl %esi, %esi
21374 jmp *%ebx
21375 1: addl $64,%esi
21376@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21377 jb 5f
21378 SRC( movw (%esi), %dx )
21379 leal 2(%esi), %esi
21380-DST( movw %dx, (%edi) )
21381+DST( movw %dx, %es:(%edi) )
21382 leal 2(%edi), %edi
21383 je 6f
21384 shll $16,%edx
21385 5:
21386 SRC( movb (%esi), %dl )
21387-DST( movb %dl, (%edi) )
21388+DST( movb %dl, %es:(%edi) )
21389 6: addl %edx, %eax
21390 adcl $0, %eax
21391 7:
21392 .section .fixup, "ax"
21393 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21394- movl $-EFAULT, (%ebx)
21395+ movl $-EFAULT, %ss:(%ebx)
21396 # zero the complete destination (computing the rest is too much work)
21397 movl ARGBASE+8(%esp),%edi # dst
21398 movl ARGBASE+12(%esp),%ecx # len
21399@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21400 rep; stosb
21401 jmp 7b
21402 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21403- movl $-EFAULT, (%ebx)
21404+ movl $-EFAULT, %ss:(%ebx)
21405 jmp 7b
21406 .previous
21407
21408+#ifdef CONFIG_PAX_MEMORY_UDEREF
21409+ pushl_cfi %ss
21410+ popl_cfi %ds
21411+ pushl_cfi %ss
21412+ popl_cfi %es
21413+#endif
21414+
21415 popl_cfi %esi
21416 CFI_RESTORE esi
21417 popl_cfi %edi
21418@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21419 CFI_RESTORE ebx
21420 ret
21421 CFI_ENDPROC
21422-ENDPROC(csum_partial_copy_generic)
21423+ENDPROC(csum_partial_copy_generic_to_user)
21424
21425 #undef ROUND
21426 #undef ROUND1
21427diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21428index f2145cf..cea889d 100644
21429--- a/arch/x86/lib/clear_page_64.S
21430+++ b/arch/x86/lib/clear_page_64.S
21431@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21432 movl $4096/8,%ecx
21433 xorl %eax,%eax
21434 rep stosq
21435+ pax_force_retaddr
21436 ret
21437 CFI_ENDPROC
21438 ENDPROC(clear_page_c)
21439@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21440 movl $4096,%ecx
21441 xorl %eax,%eax
21442 rep stosb
21443+ pax_force_retaddr
21444 ret
21445 CFI_ENDPROC
21446 ENDPROC(clear_page_c_e)
21447@@ -43,6 +45,7 @@ ENTRY(clear_page)
21448 leaq 64(%rdi),%rdi
21449 jnz .Lloop
21450 nop
21451+ pax_force_retaddr
21452 ret
21453 CFI_ENDPROC
21454 .Lclear_page_end:
21455@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21456
21457 #include <asm/cpufeature.h>
21458
21459- .section .altinstr_replacement,"ax"
21460+ .section .altinstr_replacement,"a"
21461 1: .byte 0xeb /* jmp <disp8> */
21462 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21463 2: .byte 0xeb /* jmp <disp8> */
21464diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21465index 1e572c5..2a162cd 100644
21466--- a/arch/x86/lib/cmpxchg16b_emu.S
21467+++ b/arch/x86/lib/cmpxchg16b_emu.S
21468@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21469
21470 popf
21471 mov $1, %al
21472+ pax_force_retaddr
21473 ret
21474
21475 not_same:
21476 popf
21477 xor %al,%al
21478+ pax_force_retaddr
21479 ret
21480
21481 CFI_ENDPROC
21482diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21483index 6b34d04..dccb07f 100644
21484--- a/arch/x86/lib/copy_page_64.S
21485+++ b/arch/x86/lib/copy_page_64.S
21486@@ -9,6 +9,7 @@ copy_page_c:
21487 CFI_STARTPROC
21488 movl $4096/8,%ecx
21489 rep movsq
21490+ pax_force_retaddr
21491 ret
21492 CFI_ENDPROC
21493 ENDPROC(copy_page_c)
21494@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21495
21496 ENTRY(copy_page)
21497 CFI_STARTPROC
21498- subq $2*8,%rsp
21499- CFI_ADJUST_CFA_OFFSET 2*8
21500+ subq $3*8,%rsp
21501+ CFI_ADJUST_CFA_OFFSET 3*8
21502 movq %rbx,(%rsp)
21503 CFI_REL_OFFSET rbx, 0
21504 movq %r12,1*8(%rsp)
21505 CFI_REL_OFFSET r12, 1*8
21506+ movq %r13,2*8(%rsp)
21507+ CFI_REL_OFFSET r13, 2*8
21508
21509 movl $(4096/64)-5,%ecx
21510 .p2align 4
21511@@ -37,7 +40,7 @@ ENTRY(copy_page)
21512 movq 16 (%rsi), %rdx
21513 movq 24 (%rsi), %r8
21514 movq 32 (%rsi), %r9
21515- movq 40 (%rsi), %r10
21516+ movq 40 (%rsi), %r13
21517 movq 48 (%rsi), %r11
21518 movq 56 (%rsi), %r12
21519
21520@@ -48,7 +51,7 @@ ENTRY(copy_page)
21521 movq %rdx, 16 (%rdi)
21522 movq %r8, 24 (%rdi)
21523 movq %r9, 32 (%rdi)
21524- movq %r10, 40 (%rdi)
21525+ movq %r13, 40 (%rdi)
21526 movq %r11, 48 (%rdi)
21527 movq %r12, 56 (%rdi)
21528
21529@@ -67,7 +70,7 @@ ENTRY(copy_page)
21530 movq 16 (%rsi), %rdx
21531 movq 24 (%rsi), %r8
21532 movq 32 (%rsi), %r9
21533- movq 40 (%rsi), %r10
21534+ movq 40 (%rsi), %r13
21535 movq 48 (%rsi), %r11
21536 movq 56 (%rsi), %r12
21537
21538@@ -76,7 +79,7 @@ ENTRY(copy_page)
21539 movq %rdx, 16 (%rdi)
21540 movq %r8, 24 (%rdi)
21541 movq %r9, 32 (%rdi)
21542- movq %r10, 40 (%rdi)
21543+ movq %r13, 40 (%rdi)
21544 movq %r11, 48 (%rdi)
21545 movq %r12, 56 (%rdi)
21546
21547@@ -89,8 +92,11 @@ ENTRY(copy_page)
21548 CFI_RESTORE rbx
21549 movq 1*8(%rsp),%r12
21550 CFI_RESTORE r12
21551- addq $2*8,%rsp
21552- CFI_ADJUST_CFA_OFFSET -2*8
21553+ movq 2*8(%rsp),%r13
21554+ CFI_RESTORE r13
21555+ addq $3*8,%rsp
21556+ CFI_ADJUST_CFA_OFFSET -3*8
21557+ pax_force_retaddr
21558 ret
21559 .Lcopy_page_end:
21560 CFI_ENDPROC
21561@@ -101,7 +107,7 @@ ENDPROC(copy_page)
21562
21563 #include <asm/cpufeature.h>
21564
21565- .section .altinstr_replacement,"ax"
21566+ .section .altinstr_replacement,"a"
21567 1: .byte 0xeb /* jmp <disp8> */
21568 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21569 2:
21570diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21571index 5b2995f..78e7644 100644
21572--- a/arch/x86/lib/copy_user_64.S
21573+++ b/arch/x86/lib/copy_user_64.S
21574@@ -17,6 +17,7 @@
21575 #include <asm/cpufeature.h>
21576 #include <asm/alternative-asm.h>
21577 #include <asm/asm.h>
21578+#include <asm/pgtable.h>
21579
21580 /*
21581 * By placing feature2 after feature1 in altinstructions section, we logically
21582@@ -30,7 +31,7 @@
21583 .byte 0xe9 /* 32bit jump */
21584 .long \orig-1f /* by default jump to orig */
21585 1:
21586- .section .altinstr_replacement,"ax"
21587+ .section .altinstr_replacement,"a"
21588 2: .byte 0xe9 /* near jump with 32bit immediate */
21589 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21590 3: .byte 0xe9 /* near jump with 32bit immediate */
21591@@ -69,47 +70,20 @@
21592 #endif
21593 .endm
21594
21595-/* Standard copy_to_user with segment limit checking */
21596-ENTRY(_copy_to_user)
21597- CFI_STARTPROC
21598- GET_THREAD_INFO(%rax)
21599- movq %rdi,%rcx
21600- addq %rdx,%rcx
21601- jc bad_to_user
21602- cmpq TI_addr_limit(%rax),%rcx
21603- ja bad_to_user
21604- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21605- copy_user_generic_unrolled,copy_user_generic_string, \
21606- copy_user_enhanced_fast_string
21607- CFI_ENDPROC
21608-ENDPROC(_copy_to_user)
21609-
21610-/* Standard copy_from_user with segment limit checking */
21611-ENTRY(_copy_from_user)
21612- CFI_STARTPROC
21613- GET_THREAD_INFO(%rax)
21614- movq %rsi,%rcx
21615- addq %rdx,%rcx
21616- jc bad_from_user
21617- cmpq TI_addr_limit(%rax),%rcx
21618- ja bad_from_user
21619- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21620- copy_user_generic_unrolled,copy_user_generic_string, \
21621- copy_user_enhanced_fast_string
21622- CFI_ENDPROC
21623-ENDPROC(_copy_from_user)
21624-
21625 .section .fixup,"ax"
21626 /* must zero dest */
21627 ENTRY(bad_from_user)
21628 bad_from_user:
21629 CFI_STARTPROC
21630+ testl %edx,%edx
21631+ js bad_to_user
21632 movl %edx,%ecx
21633 xorl %eax,%eax
21634 rep
21635 stosb
21636 bad_to_user:
21637 movl %edx,%eax
21638+ pax_force_retaddr
21639 ret
21640 CFI_ENDPROC
21641 ENDPROC(bad_from_user)
21642@@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21643 jz 17f
21644 1: movq (%rsi),%r8
21645 2: movq 1*8(%rsi),%r9
21646-3: movq 2*8(%rsi),%r10
21647+3: movq 2*8(%rsi),%rax
21648 4: movq 3*8(%rsi),%r11
21649 5: movq %r8,(%rdi)
21650 6: movq %r9,1*8(%rdi)
21651-7: movq %r10,2*8(%rdi)
21652+7: movq %rax,2*8(%rdi)
21653 8: movq %r11,3*8(%rdi)
21654 9: movq 4*8(%rsi),%r8
21655 10: movq 5*8(%rsi),%r9
21656-11: movq 6*8(%rsi),%r10
21657+11: movq 6*8(%rsi),%rax
21658 12: movq 7*8(%rsi),%r11
21659 13: movq %r8,4*8(%rdi)
21660 14: movq %r9,5*8(%rdi)
21661-15: movq %r10,6*8(%rdi)
21662+15: movq %rax,6*8(%rdi)
21663 16: movq %r11,7*8(%rdi)
21664 leaq 64(%rsi),%rsi
21665 leaq 64(%rdi),%rdi
21666@@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21667 decl %ecx
21668 jnz 21b
21669 23: xor %eax,%eax
21670+ pax_force_retaddr
21671 ret
21672
21673 .section .fixup,"ax"
21674@@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21675 3: rep
21676 movsb
21677 4: xorl %eax,%eax
21678+ pax_force_retaddr
21679 ret
21680
21681 .section .fixup,"ax"
21682@@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21683 1: rep
21684 movsb
21685 2: xorl %eax,%eax
21686+ pax_force_retaddr
21687 ret
21688
21689 .section .fixup,"ax"
21690diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21691index cacddc7..09d49e4 100644
21692--- a/arch/x86/lib/copy_user_nocache_64.S
21693+++ b/arch/x86/lib/copy_user_nocache_64.S
21694@@ -8,6 +8,7 @@
21695
21696 #include <linux/linkage.h>
21697 #include <asm/dwarf2.h>
21698+#include <asm/alternative-asm.h>
21699
21700 #define FIX_ALIGNMENT 1
21701
21702@@ -15,6 +16,7 @@
21703 #include <asm/asm-offsets.h>
21704 #include <asm/thread_info.h>
21705 #include <asm/asm.h>
21706+#include <asm/pgtable.h>
21707
21708 .macro ALIGN_DESTINATION
21709 #ifdef FIX_ALIGNMENT
21710@@ -48,6 +50,15 @@
21711 */
21712 ENTRY(__copy_user_nocache)
21713 CFI_STARTPROC
21714+
21715+#ifdef CONFIG_PAX_MEMORY_UDEREF
21716+ mov $PAX_USER_SHADOW_BASE,%rcx
21717+ cmp %rcx,%rsi
21718+ jae 1f
21719+ add %rcx,%rsi
21720+1:
21721+#endif
21722+
21723 cmpl $8,%edx
21724 jb 20f /* less then 8 bytes, go to byte copy loop */
21725 ALIGN_DESTINATION
21726@@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21727 jz 17f
21728 1: movq (%rsi),%r8
21729 2: movq 1*8(%rsi),%r9
21730-3: movq 2*8(%rsi),%r10
21731+3: movq 2*8(%rsi),%rax
21732 4: movq 3*8(%rsi),%r11
21733 5: movnti %r8,(%rdi)
21734 6: movnti %r9,1*8(%rdi)
21735-7: movnti %r10,2*8(%rdi)
21736+7: movnti %rax,2*8(%rdi)
21737 8: movnti %r11,3*8(%rdi)
21738 9: movq 4*8(%rsi),%r8
21739 10: movq 5*8(%rsi),%r9
21740-11: movq 6*8(%rsi),%r10
21741+11: movq 6*8(%rsi),%rax
21742 12: movq 7*8(%rsi),%r11
21743 13: movnti %r8,4*8(%rdi)
21744 14: movnti %r9,5*8(%rdi)
21745-15: movnti %r10,6*8(%rdi)
21746+15: movnti %rax,6*8(%rdi)
21747 16: movnti %r11,7*8(%rdi)
21748 leaq 64(%rsi),%rsi
21749 leaq 64(%rdi),%rdi
21750@@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21751 jnz 21b
21752 23: xorl %eax,%eax
21753 sfence
21754+ pax_force_retaddr
21755 ret
21756
21757 .section .fixup,"ax"
21758diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21759index 2419d5f..953ee51 100644
21760--- a/arch/x86/lib/csum-copy_64.S
21761+++ b/arch/x86/lib/csum-copy_64.S
21762@@ -9,6 +9,7 @@
21763 #include <asm/dwarf2.h>
21764 #include <asm/errno.h>
21765 #include <asm/asm.h>
21766+#include <asm/alternative-asm.h>
21767
21768 /*
21769 * Checksum copy with exception handling.
21770@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21771 CFI_RESTORE rbp
21772 addq $7*8, %rsp
21773 CFI_ADJUST_CFA_OFFSET -7*8
21774+ pax_force_retaddr 0, 1
21775 ret
21776 CFI_RESTORE_STATE
21777
21778diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21779index 25b7ae8..3b52ccd 100644
21780--- a/arch/x86/lib/csum-wrappers_64.c
21781+++ b/arch/x86/lib/csum-wrappers_64.c
21782@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21783 len -= 2;
21784 }
21785 }
21786- isum = csum_partial_copy_generic((__force const void *)src,
21787+
21788+#ifdef CONFIG_PAX_MEMORY_UDEREF
21789+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21790+ src += PAX_USER_SHADOW_BASE;
21791+#endif
21792+
21793+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21794 dst, len, isum, errp, NULL);
21795 if (unlikely(*errp))
21796 goto out_err;
21797@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21798 }
21799
21800 *errp = 0;
21801- return csum_partial_copy_generic(src, (void __force *)dst,
21802+
21803+#ifdef CONFIG_PAX_MEMORY_UDEREF
21804+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21805+ dst += PAX_USER_SHADOW_BASE;
21806+#endif
21807+
21808+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21809 len, isum, NULL, errp);
21810 }
21811 EXPORT_SYMBOL(csum_partial_copy_to_user);
21812diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21813index b33b1fb..219f389 100644
21814--- a/arch/x86/lib/getuser.S
21815+++ b/arch/x86/lib/getuser.S
21816@@ -33,15 +33,38 @@
21817 #include <asm/asm-offsets.h>
21818 #include <asm/thread_info.h>
21819 #include <asm/asm.h>
21820+#include <asm/segment.h>
21821+#include <asm/pgtable.h>
21822+#include <asm/alternative-asm.h>
21823+
21824+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21825+#define __copyuser_seg gs;
21826+#else
21827+#define __copyuser_seg
21828+#endif
21829
21830 .text
21831 ENTRY(__get_user_1)
21832 CFI_STARTPROC
21833+
21834+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21835 GET_THREAD_INFO(%_ASM_DX)
21836 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21837 jae bad_get_user
21838-1: movzb (%_ASM_AX),%edx
21839+
21840+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21841+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21842+ cmp %_ASM_DX,%_ASM_AX
21843+ jae 1234f
21844+ add %_ASM_DX,%_ASM_AX
21845+1234:
21846+#endif
21847+
21848+#endif
21849+
21850+1: __copyuser_seg movzb (%_ASM_AX),%edx
21851 xor %eax,%eax
21852+ pax_force_retaddr
21853 ret
21854 CFI_ENDPROC
21855 ENDPROC(__get_user_1)
21856@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21857 ENTRY(__get_user_2)
21858 CFI_STARTPROC
21859 add $1,%_ASM_AX
21860+
21861+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21862 jc bad_get_user
21863 GET_THREAD_INFO(%_ASM_DX)
21864 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21865 jae bad_get_user
21866-2: movzwl -1(%_ASM_AX),%edx
21867+
21868+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21869+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21870+ cmp %_ASM_DX,%_ASM_AX
21871+ jae 1234f
21872+ add %_ASM_DX,%_ASM_AX
21873+1234:
21874+#endif
21875+
21876+#endif
21877+
21878+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21879 xor %eax,%eax
21880+ pax_force_retaddr
21881 ret
21882 CFI_ENDPROC
21883 ENDPROC(__get_user_2)
21884@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21885 ENTRY(__get_user_4)
21886 CFI_STARTPROC
21887 add $3,%_ASM_AX
21888+
21889+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21890 jc bad_get_user
21891 GET_THREAD_INFO(%_ASM_DX)
21892 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21893 jae bad_get_user
21894-3: mov -3(%_ASM_AX),%edx
21895+
21896+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21897+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21898+ cmp %_ASM_DX,%_ASM_AX
21899+ jae 1234f
21900+ add %_ASM_DX,%_ASM_AX
21901+1234:
21902+#endif
21903+
21904+#endif
21905+
21906+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21907 xor %eax,%eax
21908+ pax_force_retaddr
21909 ret
21910 CFI_ENDPROC
21911 ENDPROC(__get_user_4)
21912@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21913 GET_THREAD_INFO(%_ASM_DX)
21914 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21915 jae bad_get_user
21916+
21917+#ifdef CONFIG_PAX_MEMORY_UDEREF
21918+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21919+ cmp %_ASM_DX,%_ASM_AX
21920+ jae 1234f
21921+ add %_ASM_DX,%_ASM_AX
21922+1234:
21923+#endif
21924+
21925 4: movq -7(%_ASM_AX),%_ASM_DX
21926 xor %eax,%eax
21927+ pax_force_retaddr
21928 ret
21929 CFI_ENDPROC
21930 ENDPROC(__get_user_8)
21931@@ -91,6 +152,7 @@ bad_get_user:
21932 CFI_STARTPROC
21933 xor %edx,%edx
21934 mov $(-EFAULT),%_ASM_AX
21935+ pax_force_retaddr
21936 ret
21937 CFI_ENDPROC
21938 END(bad_get_user)
21939diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21940index b1e6c4b..21ae8fc 100644
21941--- a/arch/x86/lib/insn.c
21942+++ b/arch/x86/lib/insn.c
21943@@ -21,6 +21,11 @@
21944 #include <linux/string.h>
21945 #include <asm/inat.h>
21946 #include <asm/insn.h>
21947+#ifdef __KERNEL__
21948+#include <asm/pgtable_types.h>
21949+#else
21950+#define ktla_ktva(addr) addr
21951+#endif
21952
21953 /* Verify next sizeof(t) bytes can be on the same instruction */
21954 #define validate_next(t, insn, n) \
21955@@ -49,8 +54,8 @@
21956 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21957 {
21958 memset(insn, 0, sizeof(*insn));
21959- insn->kaddr = kaddr;
21960- insn->next_byte = kaddr;
21961+ insn->kaddr = ktla_ktva(kaddr);
21962+ insn->next_byte = ktla_ktva(kaddr);
21963 insn->x86_64 = x86_64 ? 1 : 0;
21964 insn->opnd_bytes = 4;
21965 if (x86_64)
21966diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21967index 05a95e7..326f2fa 100644
21968--- a/arch/x86/lib/iomap_copy_64.S
21969+++ b/arch/x86/lib/iomap_copy_64.S
21970@@ -17,6 +17,7 @@
21971
21972 #include <linux/linkage.h>
21973 #include <asm/dwarf2.h>
21974+#include <asm/alternative-asm.h>
21975
21976 /*
21977 * override generic version in lib/iomap_copy.c
21978@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21979 CFI_STARTPROC
21980 movl %edx,%ecx
21981 rep movsd
21982+ pax_force_retaddr
21983 ret
21984 CFI_ENDPROC
21985 ENDPROC(__iowrite32_copy)
21986diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21987index 1c273be..da9cc0e 100644
21988--- a/arch/x86/lib/memcpy_64.S
21989+++ b/arch/x86/lib/memcpy_64.S
21990@@ -33,6 +33,7 @@
21991 rep movsq
21992 movl %edx, %ecx
21993 rep movsb
21994+ pax_force_retaddr
21995 ret
21996 .Lmemcpy_e:
21997 .previous
21998@@ -49,6 +50,7 @@
21999 movq %rdi, %rax
22000 movq %rdx, %rcx
22001 rep movsb
22002+ pax_force_retaddr
22003 ret
22004 .Lmemcpy_e_e:
22005 .previous
22006@@ -76,13 +78,13 @@ ENTRY(memcpy)
22007 */
22008 movq 0*8(%rsi), %r8
22009 movq 1*8(%rsi), %r9
22010- movq 2*8(%rsi), %r10
22011+ movq 2*8(%rsi), %rcx
22012 movq 3*8(%rsi), %r11
22013 leaq 4*8(%rsi), %rsi
22014
22015 movq %r8, 0*8(%rdi)
22016 movq %r9, 1*8(%rdi)
22017- movq %r10, 2*8(%rdi)
22018+ movq %rcx, 2*8(%rdi)
22019 movq %r11, 3*8(%rdi)
22020 leaq 4*8(%rdi), %rdi
22021 jae .Lcopy_forward_loop
22022@@ -105,12 +107,12 @@ ENTRY(memcpy)
22023 subq $0x20, %rdx
22024 movq -1*8(%rsi), %r8
22025 movq -2*8(%rsi), %r9
22026- movq -3*8(%rsi), %r10
22027+ movq -3*8(%rsi), %rcx
22028 movq -4*8(%rsi), %r11
22029 leaq -4*8(%rsi), %rsi
22030 movq %r8, -1*8(%rdi)
22031 movq %r9, -2*8(%rdi)
22032- movq %r10, -3*8(%rdi)
22033+ movq %rcx, -3*8(%rdi)
22034 movq %r11, -4*8(%rdi)
22035 leaq -4*8(%rdi), %rdi
22036 jae .Lcopy_backward_loop
22037@@ -130,12 +132,13 @@ ENTRY(memcpy)
22038 */
22039 movq 0*8(%rsi), %r8
22040 movq 1*8(%rsi), %r9
22041- movq -2*8(%rsi, %rdx), %r10
22042+ movq -2*8(%rsi, %rdx), %rcx
22043 movq -1*8(%rsi, %rdx), %r11
22044 movq %r8, 0*8(%rdi)
22045 movq %r9, 1*8(%rdi)
22046- movq %r10, -2*8(%rdi, %rdx)
22047+ movq %rcx, -2*8(%rdi, %rdx)
22048 movq %r11, -1*8(%rdi, %rdx)
22049+ pax_force_retaddr
22050 retq
22051 .p2align 4
22052 .Lless_16bytes:
22053@@ -148,6 +151,7 @@ ENTRY(memcpy)
22054 movq -1*8(%rsi, %rdx), %r9
22055 movq %r8, 0*8(%rdi)
22056 movq %r9, -1*8(%rdi, %rdx)
22057+ pax_force_retaddr
22058 retq
22059 .p2align 4
22060 .Lless_8bytes:
22061@@ -161,6 +165,7 @@ ENTRY(memcpy)
22062 movl -4(%rsi, %rdx), %r8d
22063 movl %ecx, (%rdi)
22064 movl %r8d, -4(%rdi, %rdx)
22065+ pax_force_retaddr
22066 retq
22067 .p2align 4
22068 .Lless_3bytes:
22069@@ -179,6 +184,7 @@ ENTRY(memcpy)
22070 movb %cl, (%rdi)
22071
22072 .Lend:
22073+ pax_force_retaddr
22074 retq
22075 CFI_ENDPROC
22076 ENDPROC(memcpy)
22077diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22078index ee16461..c39c199 100644
22079--- a/arch/x86/lib/memmove_64.S
22080+++ b/arch/x86/lib/memmove_64.S
22081@@ -61,13 +61,13 @@ ENTRY(memmove)
22082 5:
22083 sub $0x20, %rdx
22084 movq 0*8(%rsi), %r11
22085- movq 1*8(%rsi), %r10
22086+ movq 1*8(%rsi), %rcx
22087 movq 2*8(%rsi), %r9
22088 movq 3*8(%rsi), %r8
22089 leaq 4*8(%rsi), %rsi
22090
22091 movq %r11, 0*8(%rdi)
22092- movq %r10, 1*8(%rdi)
22093+ movq %rcx, 1*8(%rdi)
22094 movq %r9, 2*8(%rdi)
22095 movq %r8, 3*8(%rdi)
22096 leaq 4*8(%rdi), %rdi
22097@@ -81,10 +81,10 @@ ENTRY(memmove)
22098 4:
22099 movq %rdx, %rcx
22100 movq -8(%rsi, %rdx), %r11
22101- lea -8(%rdi, %rdx), %r10
22102+ lea -8(%rdi, %rdx), %r9
22103 shrq $3, %rcx
22104 rep movsq
22105- movq %r11, (%r10)
22106+ movq %r11, (%r9)
22107 jmp 13f
22108 .Lmemmove_end_forward:
22109
22110@@ -95,14 +95,14 @@ ENTRY(memmove)
22111 7:
22112 movq %rdx, %rcx
22113 movq (%rsi), %r11
22114- movq %rdi, %r10
22115+ movq %rdi, %r9
22116 leaq -8(%rsi, %rdx), %rsi
22117 leaq -8(%rdi, %rdx), %rdi
22118 shrq $3, %rcx
22119 std
22120 rep movsq
22121 cld
22122- movq %r11, (%r10)
22123+ movq %r11, (%r9)
22124 jmp 13f
22125
22126 /*
22127@@ -127,13 +127,13 @@ ENTRY(memmove)
22128 8:
22129 subq $0x20, %rdx
22130 movq -1*8(%rsi), %r11
22131- movq -2*8(%rsi), %r10
22132+ movq -2*8(%rsi), %rcx
22133 movq -3*8(%rsi), %r9
22134 movq -4*8(%rsi), %r8
22135 leaq -4*8(%rsi), %rsi
22136
22137 movq %r11, -1*8(%rdi)
22138- movq %r10, -2*8(%rdi)
22139+ movq %rcx, -2*8(%rdi)
22140 movq %r9, -3*8(%rdi)
22141 movq %r8, -4*8(%rdi)
22142 leaq -4*8(%rdi), %rdi
22143@@ -151,11 +151,11 @@ ENTRY(memmove)
22144 * Move data from 16 bytes to 31 bytes.
22145 */
22146 movq 0*8(%rsi), %r11
22147- movq 1*8(%rsi), %r10
22148+ movq 1*8(%rsi), %rcx
22149 movq -2*8(%rsi, %rdx), %r9
22150 movq -1*8(%rsi, %rdx), %r8
22151 movq %r11, 0*8(%rdi)
22152- movq %r10, 1*8(%rdi)
22153+ movq %rcx, 1*8(%rdi)
22154 movq %r9, -2*8(%rdi, %rdx)
22155 movq %r8, -1*8(%rdi, %rdx)
22156 jmp 13f
22157@@ -167,9 +167,9 @@ ENTRY(memmove)
22158 * Move data from 8 bytes to 15 bytes.
22159 */
22160 movq 0*8(%rsi), %r11
22161- movq -1*8(%rsi, %rdx), %r10
22162+ movq -1*8(%rsi, %rdx), %r9
22163 movq %r11, 0*8(%rdi)
22164- movq %r10, -1*8(%rdi, %rdx)
22165+ movq %r9, -1*8(%rdi, %rdx)
22166 jmp 13f
22167 10:
22168 cmpq $4, %rdx
22169@@ -178,9 +178,9 @@ ENTRY(memmove)
22170 * Move data from 4 bytes to 7 bytes.
22171 */
22172 movl (%rsi), %r11d
22173- movl -4(%rsi, %rdx), %r10d
22174+ movl -4(%rsi, %rdx), %r9d
22175 movl %r11d, (%rdi)
22176- movl %r10d, -4(%rdi, %rdx)
22177+ movl %r9d, -4(%rdi, %rdx)
22178 jmp 13f
22179 11:
22180 cmp $2, %rdx
22181@@ -189,9 +189,9 @@ ENTRY(memmove)
22182 * Move data from 2 bytes to 3 bytes.
22183 */
22184 movw (%rsi), %r11w
22185- movw -2(%rsi, %rdx), %r10w
22186+ movw -2(%rsi, %rdx), %r9w
22187 movw %r11w, (%rdi)
22188- movw %r10w, -2(%rdi, %rdx)
22189+ movw %r9w, -2(%rdi, %rdx)
22190 jmp 13f
22191 12:
22192 cmp $1, %rdx
22193@@ -202,6 +202,7 @@ ENTRY(memmove)
22194 movb (%rsi), %r11b
22195 movb %r11b, (%rdi)
22196 13:
22197+ pax_force_retaddr
22198 retq
22199 CFI_ENDPROC
22200
22201@@ -210,6 +211,7 @@ ENTRY(memmove)
22202 /* Forward moving data. */
22203 movq %rdx, %rcx
22204 rep movsb
22205+ pax_force_retaddr
22206 retq
22207 .Lmemmove_end_forward_efs:
22208 .previous
22209diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22210index 2dcb380..963660a 100644
22211--- a/arch/x86/lib/memset_64.S
22212+++ b/arch/x86/lib/memset_64.S
22213@@ -30,6 +30,7 @@
22214 movl %edx,%ecx
22215 rep stosb
22216 movq %r9,%rax
22217+ pax_force_retaddr
22218 ret
22219 .Lmemset_e:
22220 .previous
22221@@ -52,6 +53,7 @@
22222 movq %rdx,%rcx
22223 rep stosb
22224 movq %r9,%rax
22225+ pax_force_retaddr
22226 ret
22227 .Lmemset_e_e:
22228 .previous
22229@@ -59,7 +61,7 @@
22230 ENTRY(memset)
22231 ENTRY(__memset)
22232 CFI_STARTPROC
22233- movq %rdi,%r10
22234+ movq %rdi,%r11
22235
22236 /* expand byte value */
22237 movzbl %sil,%ecx
22238@@ -117,7 +119,8 @@ ENTRY(__memset)
22239 jnz .Lloop_1
22240
22241 .Lende:
22242- movq %r10,%rax
22243+ movq %r11,%rax
22244+ pax_force_retaddr
22245 ret
22246
22247 CFI_RESTORE_STATE
22248diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22249index c9f2d9b..e7fd2c0 100644
22250--- a/arch/x86/lib/mmx_32.c
22251+++ b/arch/x86/lib/mmx_32.c
22252@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22253 {
22254 void *p;
22255 int i;
22256+ unsigned long cr0;
22257
22258 if (unlikely(in_interrupt()))
22259 return __memcpy(to, from, len);
22260@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22261 kernel_fpu_begin();
22262
22263 __asm__ __volatile__ (
22264- "1: prefetch (%0)\n" /* This set is 28 bytes */
22265- " prefetch 64(%0)\n"
22266- " prefetch 128(%0)\n"
22267- " prefetch 192(%0)\n"
22268- " prefetch 256(%0)\n"
22269+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22270+ " prefetch 64(%1)\n"
22271+ " prefetch 128(%1)\n"
22272+ " prefetch 192(%1)\n"
22273+ " prefetch 256(%1)\n"
22274 "2: \n"
22275 ".section .fixup, \"ax\"\n"
22276- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22277+ "3: \n"
22278+
22279+#ifdef CONFIG_PAX_KERNEXEC
22280+ " movl %%cr0, %0\n"
22281+ " movl %0, %%eax\n"
22282+ " andl $0xFFFEFFFF, %%eax\n"
22283+ " movl %%eax, %%cr0\n"
22284+#endif
22285+
22286+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22287+
22288+#ifdef CONFIG_PAX_KERNEXEC
22289+ " movl %0, %%cr0\n"
22290+#endif
22291+
22292 " jmp 2b\n"
22293 ".previous\n"
22294 _ASM_EXTABLE(1b, 3b)
22295- : : "r" (from));
22296+ : "=&r" (cr0) : "r" (from) : "ax");
22297
22298 for ( ; i > 5; i--) {
22299 __asm__ __volatile__ (
22300- "1: prefetch 320(%0)\n"
22301- "2: movq (%0), %%mm0\n"
22302- " movq 8(%0), %%mm1\n"
22303- " movq 16(%0), %%mm2\n"
22304- " movq 24(%0), %%mm3\n"
22305- " movq %%mm0, (%1)\n"
22306- " movq %%mm1, 8(%1)\n"
22307- " movq %%mm2, 16(%1)\n"
22308- " movq %%mm3, 24(%1)\n"
22309- " movq 32(%0), %%mm0\n"
22310- " movq 40(%0), %%mm1\n"
22311- " movq 48(%0), %%mm2\n"
22312- " movq 56(%0), %%mm3\n"
22313- " movq %%mm0, 32(%1)\n"
22314- " movq %%mm1, 40(%1)\n"
22315- " movq %%mm2, 48(%1)\n"
22316- " movq %%mm3, 56(%1)\n"
22317+ "1: prefetch 320(%1)\n"
22318+ "2: movq (%1), %%mm0\n"
22319+ " movq 8(%1), %%mm1\n"
22320+ " movq 16(%1), %%mm2\n"
22321+ " movq 24(%1), %%mm3\n"
22322+ " movq %%mm0, (%2)\n"
22323+ " movq %%mm1, 8(%2)\n"
22324+ " movq %%mm2, 16(%2)\n"
22325+ " movq %%mm3, 24(%2)\n"
22326+ " movq 32(%1), %%mm0\n"
22327+ " movq 40(%1), %%mm1\n"
22328+ " movq 48(%1), %%mm2\n"
22329+ " movq 56(%1), %%mm3\n"
22330+ " movq %%mm0, 32(%2)\n"
22331+ " movq %%mm1, 40(%2)\n"
22332+ " movq %%mm2, 48(%2)\n"
22333+ " movq %%mm3, 56(%2)\n"
22334 ".section .fixup, \"ax\"\n"
22335- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22336+ "3:\n"
22337+
22338+#ifdef CONFIG_PAX_KERNEXEC
22339+ " movl %%cr0, %0\n"
22340+ " movl %0, %%eax\n"
22341+ " andl $0xFFFEFFFF, %%eax\n"
22342+ " movl %%eax, %%cr0\n"
22343+#endif
22344+
22345+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22346+
22347+#ifdef CONFIG_PAX_KERNEXEC
22348+ " movl %0, %%cr0\n"
22349+#endif
22350+
22351 " jmp 2b\n"
22352 ".previous\n"
22353 _ASM_EXTABLE(1b, 3b)
22354- : : "r" (from), "r" (to) : "memory");
22355+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22356
22357 from += 64;
22358 to += 64;
22359@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22360 static void fast_copy_page(void *to, void *from)
22361 {
22362 int i;
22363+ unsigned long cr0;
22364
22365 kernel_fpu_begin();
22366
22367@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22368 * but that is for later. -AV
22369 */
22370 __asm__ __volatile__(
22371- "1: prefetch (%0)\n"
22372- " prefetch 64(%0)\n"
22373- " prefetch 128(%0)\n"
22374- " prefetch 192(%0)\n"
22375- " prefetch 256(%0)\n"
22376+ "1: prefetch (%1)\n"
22377+ " prefetch 64(%1)\n"
22378+ " prefetch 128(%1)\n"
22379+ " prefetch 192(%1)\n"
22380+ " prefetch 256(%1)\n"
22381 "2: \n"
22382 ".section .fixup, \"ax\"\n"
22383- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22384+ "3: \n"
22385+
22386+#ifdef CONFIG_PAX_KERNEXEC
22387+ " movl %%cr0, %0\n"
22388+ " movl %0, %%eax\n"
22389+ " andl $0xFFFEFFFF, %%eax\n"
22390+ " movl %%eax, %%cr0\n"
22391+#endif
22392+
22393+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22394+
22395+#ifdef CONFIG_PAX_KERNEXEC
22396+ " movl %0, %%cr0\n"
22397+#endif
22398+
22399 " jmp 2b\n"
22400 ".previous\n"
22401- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22402+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22403
22404 for (i = 0; i < (4096-320)/64; i++) {
22405 __asm__ __volatile__ (
22406- "1: prefetch 320(%0)\n"
22407- "2: movq (%0), %%mm0\n"
22408- " movntq %%mm0, (%1)\n"
22409- " movq 8(%0), %%mm1\n"
22410- " movntq %%mm1, 8(%1)\n"
22411- " movq 16(%0), %%mm2\n"
22412- " movntq %%mm2, 16(%1)\n"
22413- " movq 24(%0), %%mm3\n"
22414- " movntq %%mm3, 24(%1)\n"
22415- " movq 32(%0), %%mm4\n"
22416- " movntq %%mm4, 32(%1)\n"
22417- " movq 40(%0), %%mm5\n"
22418- " movntq %%mm5, 40(%1)\n"
22419- " movq 48(%0), %%mm6\n"
22420- " movntq %%mm6, 48(%1)\n"
22421- " movq 56(%0), %%mm7\n"
22422- " movntq %%mm7, 56(%1)\n"
22423+ "1: prefetch 320(%1)\n"
22424+ "2: movq (%1), %%mm0\n"
22425+ " movntq %%mm0, (%2)\n"
22426+ " movq 8(%1), %%mm1\n"
22427+ " movntq %%mm1, 8(%2)\n"
22428+ " movq 16(%1), %%mm2\n"
22429+ " movntq %%mm2, 16(%2)\n"
22430+ " movq 24(%1), %%mm3\n"
22431+ " movntq %%mm3, 24(%2)\n"
22432+ " movq 32(%1), %%mm4\n"
22433+ " movntq %%mm4, 32(%2)\n"
22434+ " movq 40(%1), %%mm5\n"
22435+ " movntq %%mm5, 40(%2)\n"
22436+ " movq 48(%1), %%mm6\n"
22437+ " movntq %%mm6, 48(%2)\n"
22438+ " movq 56(%1), %%mm7\n"
22439+ " movntq %%mm7, 56(%2)\n"
22440 ".section .fixup, \"ax\"\n"
22441- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22442+ "3:\n"
22443+
22444+#ifdef CONFIG_PAX_KERNEXEC
22445+ " movl %%cr0, %0\n"
22446+ " movl %0, %%eax\n"
22447+ " andl $0xFFFEFFFF, %%eax\n"
22448+ " movl %%eax, %%cr0\n"
22449+#endif
22450+
22451+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22452+
22453+#ifdef CONFIG_PAX_KERNEXEC
22454+ " movl %0, %%cr0\n"
22455+#endif
22456+
22457 " jmp 2b\n"
22458 ".previous\n"
22459- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22460+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22461
22462 from += 64;
22463 to += 64;
22464@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22465 static void fast_copy_page(void *to, void *from)
22466 {
22467 int i;
22468+ unsigned long cr0;
22469
22470 kernel_fpu_begin();
22471
22472 __asm__ __volatile__ (
22473- "1: prefetch (%0)\n"
22474- " prefetch 64(%0)\n"
22475- " prefetch 128(%0)\n"
22476- " prefetch 192(%0)\n"
22477- " prefetch 256(%0)\n"
22478+ "1: prefetch (%1)\n"
22479+ " prefetch 64(%1)\n"
22480+ " prefetch 128(%1)\n"
22481+ " prefetch 192(%1)\n"
22482+ " prefetch 256(%1)\n"
22483 "2: \n"
22484 ".section .fixup, \"ax\"\n"
22485- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22486+ "3: \n"
22487+
22488+#ifdef CONFIG_PAX_KERNEXEC
22489+ " movl %%cr0, %0\n"
22490+ " movl %0, %%eax\n"
22491+ " andl $0xFFFEFFFF, %%eax\n"
22492+ " movl %%eax, %%cr0\n"
22493+#endif
22494+
22495+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22496+
22497+#ifdef CONFIG_PAX_KERNEXEC
22498+ " movl %0, %%cr0\n"
22499+#endif
22500+
22501 " jmp 2b\n"
22502 ".previous\n"
22503- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22504+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22505
22506 for (i = 0; i < 4096/64; i++) {
22507 __asm__ __volatile__ (
22508- "1: prefetch 320(%0)\n"
22509- "2: movq (%0), %%mm0\n"
22510- " movq 8(%0), %%mm1\n"
22511- " movq 16(%0), %%mm2\n"
22512- " movq 24(%0), %%mm3\n"
22513- " movq %%mm0, (%1)\n"
22514- " movq %%mm1, 8(%1)\n"
22515- " movq %%mm2, 16(%1)\n"
22516- " movq %%mm3, 24(%1)\n"
22517- " movq 32(%0), %%mm0\n"
22518- " movq 40(%0), %%mm1\n"
22519- " movq 48(%0), %%mm2\n"
22520- " movq 56(%0), %%mm3\n"
22521- " movq %%mm0, 32(%1)\n"
22522- " movq %%mm1, 40(%1)\n"
22523- " movq %%mm2, 48(%1)\n"
22524- " movq %%mm3, 56(%1)\n"
22525+ "1: prefetch 320(%1)\n"
22526+ "2: movq (%1), %%mm0\n"
22527+ " movq 8(%1), %%mm1\n"
22528+ " movq 16(%1), %%mm2\n"
22529+ " movq 24(%1), %%mm3\n"
22530+ " movq %%mm0, (%2)\n"
22531+ " movq %%mm1, 8(%2)\n"
22532+ " movq %%mm2, 16(%2)\n"
22533+ " movq %%mm3, 24(%2)\n"
22534+ " movq 32(%1), %%mm0\n"
22535+ " movq 40(%1), %%mm1\n"
22536+ " movq 48(%1), %%mm2\n"
22537+ " movq 56(%1), %%mm3\n"
22538+ " movq %%mm0, 32(%2)\n"
22539+ " movq %%mm1, 40(%2)\n"
22540+ " movq %%mm2, 48(%2)\n"
22541+ " movq %%mm3, 56(%2)\n"
22542 ".section .fixup, \"ax\"\n"
22543- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22544+ "3:\n"
22545+
22546+#ifdef CONFIG_PAX_KERNEXEC
22547+ " movl %%cr0, %0\n"
22548+ " movl %0, %%eax\n"
22549+ " andl $0xFFFEFFFF, %%eax\n"
22550+ " movl %%eax, %%cr0\n"
22551+#endif
22552+
22553+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22554+
22555+#ifdef CONFIG_PAX_KERNEXEC
22556+ " movl %0, %%cr0\n"
22557+#endif
22558+
22559 " jmp 2b\n"
22560 ".previous\n"
22561 _ASM_EXTABLE(1b, 3b)
22562- : : "r" (from), "r" (to) : "memory");
22563+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22564
22565 from += 64;
22566 to += 64;
22567diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22568index f6d13ee..aca5f0b 100644
22569--- a/arch/x86/lib/msr-reg.S
22570+++ b/arch/x86/lib/msr-reg.S
22571@@ -3,6 +3,7 @@
22572 #include <asm/dwarf2.h>
22573 #include <asm/asm.h>
22574 #include <asm/msr.h>
22575+#include <asm/alternative-asm.h>
22576
22577 #ifdef CONFIG_X86_64
22578 /*
22579@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22580 CFI_STARTPROC
22581 pushq_cfi %rbx
22582 pushq_cfi %rbp
22583- movq %rdi, %r10 /* Save pointer */
22584+ movq %rdi, %r9 /* Save pointer */
22585 xorl %r11d, %r11d /* Return value */
22586 movl (%rdi), %eax
22587 movl 4(%rdi), %ecx
22588@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22589 movl 28(%rdi), %edi
22590 CFI_REMEMBER_STATE
22591 1: \op
22592-2: movl %eax, (%r10)
22593+2: movl %eax, (%r9)
22594 movl %r11d, %eax /* Return value */
22595- movl %ecx, 4(%r10)
22596- movl %edx, 8(%r10)
22597- movl %ebx, 12(%r10)
22598- movl %ebp, 20(%r10)
22599- movl %esi, 24(%r10)
22600- movl %edi, 28(%r10)
22601+ movl %ecx, 4(%r9)
22602+ movl %edx, 8(%r9)
22603+ movl %ebx, 12(%r9)
22604+ movl %ebp, 20(%r9)
22605+ movl %esi, 24(%r9)
22606+ movl %edi, 28(%r9)
22607 popq_cfi %rbp
22608 popq_cfi %rbx
22609+ pax_force_retaddr
22610 ret
22611 3:
22612 CFI_RESTORE_STATE
22613diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22614index 7f951c8..ebd573a 100644
22615--- a/arch/x86/lib/putuser.S
22616+++ b/arch/x86/lib/putuser.S
22617@@ -15,7 +15,9 @@
22618 #include <asm/thread_info.h>
22619 #include <asm/errno.h>
22620 #include <asm/asm.h>
22621-
22622+#include <asm/segment.h>
22623+#include <asm/pgtable.h>
22624+#include <asm/alternative-asm.h>
22625
22626 /*
22627 * __put_user_X
22628@@ -29,52 +31,119 @@
22629 * as they get called from within inline assembly.
22630 */
22631
22632-#define ENTER CFI_STARTPROC ; \
22633- GET_THREAD_INFO(%_ASM_BX)
22634-#define EXIT ret ; \
22635+#define ENTER CFI_STARTPROC
22636+#define EXIT pax_force_retaddr; ret ; \
22637 CFI_ENDPROC
22638
22639+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22640+#define _DEST %_ASM_CX,%_ASM_BX
22641+#else
22642+#define _DEST %_ASM_CX
22643+#endif
22644+
22645+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22646+#define __copyuser_seg gs;
22647+#else
22648+#define __copyuser_seg
22649+#endif
22650+
22651 .text
22652 ENTRY(__put_user_1)
22653 ENTER
22654+
22655+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22656+ GET_THREAD_INFO(%_ASM_BX)
22657 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22658 jae bad_put_user
22659-1: movb %al,(%_ASM_CX)
22660+
22661+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22662+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22663+ cmp %_ASM_BX,%_ASM_CX
22664+ jb 1234f
22665+ xor %ebx,%ebx
22666+1234:
22667+#endif
22668+
22669+#endif
22670+
22671+1: __copyuser_seg movb %al,(_DEST)
22672 xor %eax,%eax
22673 EXIT
22674 ENDPROC(__put_user_1)
22675
22676 ENTRY(__put_user_2)
22677 ENTER
22678+
22679+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22680+ GET_THREAD_INFO(%_ASM_BX)
22681 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22682 sub $1,%_ASM_BX
22683 cmp %_ASM_BX,%_ASM_CX
22684 jae bad_put_user
22685-2: movw %ax,(%_ASM_CX)
22686+
22687+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22688+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22689+ cmp %_ASM_BX,%_ASM_CX
22690+ jb 1234f
22691+ xor %ebx,%ebx
22692+1234:
22693+#endif
22694+
22695+#endif
22696+
22697+2: __copyuser_seg movw %ax,(_DEST)
22698 xor %eax,%eax
22699 EXIT
22700 ENDPROC(__put_user_2)
22701
22702 ENTRY(__put_user_4)
22703 ENTER
22704+
22705+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22706+ GET_THREAD_INFO(%_ASM_BX)
22707 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22708 sub $3,%_ASM_BX
22709 cmp %_ASM_BX,%_ASM_CX
22710 jae bad_put_user
22711-3: movl %eax,(%_ASM_CX)
22712+
22713+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22714+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22715+ cmp %_ASM_BX,%_ASM_CX
22716+ jb 1234f
22717+ xor %ebx,%ebx
22718+1234:
22719+#endif
22720+
22721+#endif
22722+
22723+3: __copyuser_seg movl %eax,(_DEST)
22724 xor %eax,%eax
22725 EXIT
22726 ENDPROC(__put_user_4)
22727
22728 ENTRY(__put_user_8)
22729 ENTER
22730+
22731+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22732+ GET_THREAD_INFO(%_ASM_BX)
22733 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22734 sub $7,%_ASM_BX
22735 cmp %_ASM_BX,%_ASM_CX
22736 jae bad_put_user
22737-4: mov %_ASM_AX,(%_ASM_CX)
22738+
22739+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22740+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22741+ cmp %_ASM_BX,%_ASM_CX
22742+ jb 1234f
22743+ xor %ebx,%ebx
22744+1234:
22745+#endif
22746+
22747+#endif
22748+
22749+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22750 #ifdef CONFIG_X86_32
22751-5: movl %edx,4(%_ASM_CX)
22752+5: __copyuser_seg movl %edx,4(_DEST)
22753 #endif
22754 xor %eax,%eax
22755 EXIT
22756diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22757index 1cad221..de671ee 100644
22758--- a/arch/x86/lib/rwlock.S
22759+++ b/arch/x86/lib/rwlock.S
22760@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22761 FRAME
22762 0: LOCK_PREFIX
22763 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22764+
22765+#ifdef CONFIG_PAX_REFCOUNT
22766+ jno 1234f
22767+ LOCK_PREFIX
22768+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22769+ int $4
22770+1234:
22771+ _ASM_EXTABLE(1234b, 1234b)
22772+#endif
22773+
22774 1: rep; nop
22775 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22776 jne 1b
22777 LOCK_PREFIX
22778 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22779+
22780+#ifdef CONFIG_PAX_REFCOUNT
22781+ jno 1234f
22782+ LOCK_PREFIX
22783+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22784+ int $4
22785+1234:
22786+ _ASM_EXTABLE(1234b, 1234b)
22787+#endif
22788+
22789 jnz 0b
22790 ENDFRAME
22791+ pax_force_retaddr
22792 ret
22793 CFI_ENDPROC
22794 END(__write_lock_failed)
22795@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22796 FRAME
22797 0: LOCK_PREFIX
22798 READ_LOCK_SIZE(inc) (%__lock_ptr)
22799+
22800+#ifdef CONFIG_PAX_REFCOUNT
22801+ jno 1234f
22802+ LOCK_PREFIX
22803+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22804+ int $4
22805+1234:
22806+ _ASM_EXTABLE(1234b, 1234b)
22807+#endif
22808+
22809 1: rep; nop
22810 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22811 js 1b
22812 LOCK_PREFIX
22813 READ_LOCK_SIZE(dec) (%__lock_ptr)
22814+
22815+#ifdef CONFIG_PAX_REFCOUNT
22816+ jno 1234f
22817+ LOCK_PREFIX
22818+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22819+ int $4
22820+1234:
22821+ _ASM_EXTABLE(1234b, 1234b)
22822+#endif
22823+
22824 js 0b
22825 ENDFRAME
22826+ pax_force_retaddr
22827 ret
22828 CFI_ENDPROC
22829 END(__read_lock_failed)
22830diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22831index 5dff5f0..cadebf4 100644
22832--- a/arch/x86/lib/rwsem.S
22833+++ b/arch/x86/lib/rwsem.S
22834@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22835 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22836 CFI_RESTORE __ASM_REG(dx)
22837 restore_common_regs
22838+ pax_force_retaddr
22839 ret
22840 CFI_ENDPROC
22841 ENDPROC(call_rwsem_down_read_failed)
22842@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22843 movq %rax,%rdi
22844 call rwsem_down_write_failed
22845 restore_common_regs
22846+ pax_force_retaddr
22847 ret
22848 CFI_ENDPROC
22849 ENDPROC(call_rwsem_down_write_failed)
22850@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22851 movq %rax,%rdi
22852 call rwsem_wake
22853 restore_common_regs
22854-1: ret
22855+1: pax_force_retaddr
22856+ ret
22857 CFI_ENDPROC
22858 ENDPROC(call_rwsem_wake)
22859
22860@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22861 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22862 CFI_RESTORE __ASM_REG(dx)
22863 restore_common_regs
22864+ pax_force_retaddr
22865 ret
22866 CFI_ENDPROC
22867 ENDPROC(call_rwsem_downgrade_wake)
22868diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22869index a63efd6..ccecad8 100644
22870--- a/arch/x86/lib/thunk_64.S
22871+++ b/arch/x86/lib/thunk_64.S
22872@@ -8,6 +8,7 @@
22873 #include <linux/linkage.h>
22874 #include <asm/dwarf2.h>
22875 #include <asm/calling.h>
22876+#include <asm/alternative-asm.h>
22877
22878 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22879 .macro THUNK name, func, put_ret_addr_in_rdi=0
22880@@ -41,5 +42,6 @@
22881 SAVE_ARGS
22882 restore:
22883 RESTORE_ARGS
22884+ pax_force_retaddr
22885 ret
22886 CFI_ENDPROC
22887diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22888index 1781b2f..90368dd 100644
22889--- a/arch/x86/lib/usercopy_32.c
22890+++ b/arch/x86/lib/usercopy_32.c
22891@@ -42,10 +42,12 @@ do { \
22892 int __d0; \
22893 might_fault(); \
22894 __asm__ __volatile__( \
22895+ __COPYUSER_SET_ES \
22896 "0: rep; stosl\n" \
22897 " movl %2,%0\n" \
22898 "1: rep; stosb\n" \
22899 "2:\n" \
22900+ __COPYUSER_RESTORE_ES \
22901 ".section .fixup,\"ax\"\n" \
22902 "3: lea 0(%2,%0,4),%0\n" \
22903 " jmp 2b\n" \
22904@@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22905
22906 #ifdef CONFIG_X86_INTEL_USERCOPY
22907 static unsigned long
22908-__copy_user_intel(void __user *to, const void *from, unsigned long size)
22909+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22910 {
22911 int d0, d1;
22912 __asm__ __volatile__(
22913@@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22914 " .align 2,0x90\n"
22915 "3: movl 0(%4), %%eax\n"
22916 "4: movl 4(%4), %%edx\n"
22917- "5: movl %%eax, 0(%3)\n"
22918- "6: movl %%edx, 4(%3)\n"
22919+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22920+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22921 "7: movl 8(%4), %%eax\n"
22922 "8: movl 12(%4),%%edx\n"
22923- "9: movl %%eax, 8(%3)\n"
22924- "10: movl %%edx, 12(%3)\n"
22925+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22926+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22927 "11: movl 16(%4), %%eax\n"
22928 "12: movl 20(%4), %%edx\n"
22929- "13: movl %%eax, 16(%3)\n"
22930- "14: movl %%edx, 20(%3)\n"
22931+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22932+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22933 "15: movl 24(%4), %%eax\n"
22934 "16: movl 28(%4), %%edx\n"
22935- "17: movl %%eax, 24(%3)\n"
22936- "18: movl %%edx, 28(%3)\n"
22937+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22938+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22939 "19: movl 32(%4), %%eax\n"
22940 "20: movl 36(%4), %%edx\n"
22941- "21: movl %%eax, 32(%3)\n"
22942- "22: movl %%edx, 36(%3)\n"
22943+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22944+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22945 "23: movl 40(%4), %%eax\n"
22946 "24: movl 44(%4), %%edx\n"
22947- "25: movl %%eax, 40(%3)\n"
22948- "26: movl %%edx, 44(%3)\n"
22949+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22950+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22951 "27: movl 48(%4), %%eax\n"
22952 "28: movl 52(%4), %%edx\n"
22953- "29: movl %%eax, 48(%3)\n"
22954- "30: movl %%edx, 52(%3)\n"
22955+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22956+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22957 "31: movl 56(%4), %%eax\n"
22958 "32: movl 60(%4), %%edx\n"
22959- "33: movl %%eax, 56(%3)\n"
22960- "34: movl %%edx, 60(%3)\n"
22961+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22962+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22963 " addl $-64, %0\n"
22964 " addl $64, %4\n"
22965 " addl $64, %3\n"
22966@@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22967 " shrl $2, %0\n"
22968 " andl $3, %%eax\n"
22969 " cld\n"
22970+ __COPYUSER_SET_ES
22971 "99: rep; movsl\n"
22972 "36: movl %%eax, %0\n"
22973 "37: rep; movsb\n"
22974 "100:\n"
22975+ __COPYUSER_RESTORE_ES
22976 ".section .fixup,\"ax\"\n"
22977 "101: lea 0(%%eax,%0,4),%0\n"
22978 " jmp 100b\n"
22979@@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22980 }
22981
22982 static unsigned long
22983+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22984+{
22985+ int d0, d1;
22986+ __asm__ __volatile__(
22987+ " .align 2,0x90\n"
22988+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22989+ " cmpl $67, %0\n"
22990+ " jbe 3f\n"
22991+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22992+ " .align 2,0x90\n"
22993+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22994+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22995+ "5: movl %%eax, 0(%3)\n"
22996+ "6: movl %%edx, 4(%3)\n"
22997+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22998+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22999+ "9: movl %%eax, 8(%3)\n"
23000+ "10: movl %%edx, 12(%3)\n"
23001+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23002+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23003+ "13: movl %%eax, 16(%3)\n"
23004+ "14: movl %%edx, 20(%3)\n"
23005+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23006+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23007+ "17: movl %%eax, 24(%3)\n"
23008+ "18: movl %%edx, 28(%3)\n"
23009+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23010+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23011+ "21: movl %%eax, 32(%3)\n"
23012+ "22: movl %%edx, 36(%3)\n"
23013+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23014+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23015+ "25: movl %%eax, 40(%3)\n"
23016+ "26: movl %%edx, 44(%3)\n"
23017+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23018+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23019+ "29: movl %%eax, 48(%3)\n"
23020+ "30: movl %%edx, 52(%3)\n"
23021+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23022+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23023+ "33: movl %%eax, 56(%3)\n"
23024+ "34: movl %%edx, 60(%3)\n"
23025+ " addl $-64, %0\n"
23026+ " addl $64, %4\n"
23027+ " addl $64, %3\n"
23028+ " cmpl $63, %0\n"
23029+ " ja 1b\n"
23030+ "35: movl %0, %%eax\n"
23031+ " shrl $2, %0\n"
23032+ " andl $3, %%eax\n"
23033+ " cld\n"
23034+ "99: rep; "__copyuser_seg" movsl\n"
23035+ "36: movl %%eax, %0\n"
23036+ "37: rep; "__copyuser_seg" movsb\n"
23037+ "100:\n"
23038+ ".section .fixup,\"ax\"\n"
23039+ "101: lea 0(%%eax,%0,4),%0\n"
23040+ " jmp 100b\n"
23041+ ".previous\n"
23042+ _ASM_EXTABLE(1b,100b)
23043+ _ASM_EXTABLE(2b,100b)
23044+ _ASM_EXTABLE(3b,100b)
23045+ _ASM_EXTABLE(4b,100b)
23046+ _ASM_EXTABLE(5b,100b)
23047+ _ASM_EXTABLE(6b,100b)
23048+ _ASM_EXTABLE(7b,100b)
23049+ _ASM_EXTABLE(8b,100b)
23050+ _ASM_EXTABLE(9b,100b)
23051+ _ASM_EXTABLE(10b,100b)
23052+ _ASM_EXTABLE(11b,100b)
23053+ _ASM_EXTABLE(12b,100b)
23054+ _ASM_EXTABLE(13b,100b)
23055+ _ASM_EXTABLE(14b,100b)
23056+ _ASM_EXTABLE(15b,100b)
23057+ _ASM_EXTABLE(16b,100b)
23058+ _ASM_EXTABLE(17b,100b)
23059+ _ASM_EXTABLE(18b,100b)
23060+ _ASM_EXTABLE(19b,100b)
23061+ _ASM_EXTABLE(20b,100b)
23062+ _ASM_EXTABLE(21b,100b)
23063+ _ASM_EXTABLE(22b,100b)
23064+ _ASM_EXTABLE(23b,100b)
23065+ _ASM_EXTABLE(24b,100b)
23066+ _ASM_EXTABLE(25b,100b)
23067+ _ASM_EXTABLE(26b,100b)
23068+ _ASM_EXTABLE(27b,100b)
23069+ _ASM_EXTABLE(28b,100b)
23070+ _ASM_EXTABLE(29b,100b)
23071+ _ASM_EXTABLE(30b,100b)
23072+ _ASM_EXTABLE(31b,100b)
23073+ _ASM_EXTABLE(32b,100b)
23074+ _ASM_EXTABLE(33b,100b)
23075+ _ASM_EXTABLE(34b,100b)
23076+ _ASM_EXTABLE(35b,100b)
23077+ _ASM_EXTABLE(36b,100b)
23078+ _ASM_EXTABLE(37b,100b)
23079+ _ASM_EXTABLE(99b,101b)
23080+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
23081+ : "1"(to), "2"(from), "0"(size)
23082+ : "eax", "edx", "memory");
23083+ return size;
23084+}
23085+
23086+static unsigned long __size_overflow(3)
23087 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23088 {
23089 int d0, d1;
23090 __asm__ __volatile__(
23091 " .align 2,0x90\n"
23092- "0: movl 32(%4), %%eax\n"
23093+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23094 " cmpl $67, %0\n"
23095 " jbe 2f\n"
23096- "1: movl 64(%4), %%eax\n"
23097+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23098 " .align 2,0x90\n"
23099- "2: movl 0(%4), %%eax\n"
23100- "21: movl 4(%4), %%edx\n"
23101+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23102+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23103 " movl %%eax, 0(%3)\n"
23104 " movl %%edx, 4(%3)\n"
23105- "3: movl 8(%4), %%eax\n"
23106- "31: movl 12(%4),%%edx\n"
23107+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23108+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23109 " movl %%eax, 8(%3)\n"
23110 " movl %%edx, 12(%3)\n"
23111- "4: movl 16(%4), %%eax\n"
23112- "41: movl 20(%4), %%edx\n"
23113+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23114+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23115 " movl %%eax, 16(%3)\n"
23116 " movl %%edx, 20(%3)\n"
23117- "10: movl 24(%4), %%eax\n"
23118- "51: movl 28(%4), %%edx\n"
23119+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23120+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23121 " movl %%eax, 24(%3)\n"
23122 " movl %%edx, 28(%3)\n"
23123- "11: movl 32(%4), %%eax\n"
23124- "61: movl 36(%4), %%edx\n"
23125+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23126+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23127 " movl %%eax, 32(%3)\n"
23128 " movl %%edx, 36(%3)\n"
23129- "12: movl 40(%4), %%eax\n"
23130- "71: movl 44(%4), %%edx\n"
23131+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23132+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23133 " movl %%eax, 40(%3)\n"
23134 " movl %%edx, 44(%3)\n"
23135- "13: movl 48(%4), %%eax\n"
23136- "81: movl 52(%4), %%edx\n"
23137+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23138+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23139 " movl %%eax, 48(%3)\n"
23140 " movl %%edx, 52(%3)\n"
23141- "14: movl 56(%4), %%eax\n"
23142- "91: movl 60(%4), %%edx\n"
23143+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23144+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23145 " movl %%eax, 56(%3)\n"
23146 " movl %%edx, 60(%3)\n"
23147 " addl $-64, %0\n"
23148@@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23149 " shrl $2, %0\n"
23150 " andl $3, %%eax\n"
23151 " cld\n"
23152- "6: rep; movsl\n"
23153+ "6: rep; "__copyuser_seg" movsl\n"
23154 " movl %%eax,%0\n"
23155- "7: rep; movsb\n"
23156+ "7: rep; "__copyuser_seg" movsb\n"
23157 "8:\n"
23158 ".section .fixup,\"ax\"\n"
23159 "9: lea 0(%%eax,%0,4),%0\n"
23160@@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23161 * hyoshiok@miraclelinux.com
23162 */
23163
23164-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23165+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23166 const void __user *from, unsigned long size)
23167 {
23168 int d0, d1;
23169
23170 __asm__ __volatile__(
23171 " .align 2,0x90\n"
23172- "0: movl 32(%4), %%eax\n"
23173+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23174 " cmpl $67, %0\n"
23175 " jbe 2f\n"
23176- "1: movl 64(%4), %%eax\n"
23177+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23178 " .align 2,0x90\n"
23179- "2: movl 0(%4), %%eax\n"
23180- "21: movl 4(%4), %%edx\n"
23181+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23182+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23183 " movnti %%eax, 0(%3)\n"
23184 " movnti %%edx, 4(%3)\n"
23185- "3: movl 8(%4), %%eax\n"
23186- "31: movl 12(%4),%%edx\n"
23187+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23188+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23189 " movnti %%eax, 8(%3)\n"
23190 " movnti %%edx, 12(%3)\n"
23191- "4: movl 16(%4), %%eax\n"
23192- "41: movl 20(%4), %%edx\n"
23193+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23194+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23195 " movnti %%eax, 16(%3)\n"
23196 " movnti %%edx, 20(%3)\n"
23197- "10: movl 24(%4), %%eax\n"
23198- "51: movl 28(%4), %%edx\n"
23199+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23200+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23201 " movnti %%eax, 24(%3)\n"
23202 " movnti %%edx, 28(%3)\n"
23203- "11: movl 32(%4), %%eax\n"
23204- "61: movl 36(%4), %%edx\n"
23205+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23206+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23207 " movnti %%eax, 32(%3)\n"
23208 " movnti %%edx, 36(%3)\n"
23209- "12: movl 40(%4), %%eax\n"
23210- "71: movl 44(%4), %%edx\n"
23211+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23212+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23213 " movnti %%eax, 40(%3)\n"
23214 " movnti %%edx, 44(%3)\n"
23215- "13: movl 48(%4), %%eax\n"
23216- "81: movl 52(%4), %%edx\n"
23217+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23218+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23219 " movnti %%eax, 48(%3)\n"
23220 " movnti %%edx, 52(%3)\n"
23221- "14: movl 56(%4), %%eax\n"
23222- "91: movl 60(%4), %%edx\n"
23223+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23224+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23225 " movnti %%eax, 56(%3)\n"
23226 " movnti %%edx, 60(%3)\n"
23227 " addl $-64, %0\n"
23228@@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23229 " shrl $2, %0\n"
23230 " andl $3, %%eax\n"
23231 " cld\n"
23232- "6: rep; movsl\n"
23233+ "6: rep; "__copyuser_seg" movsl\n"
23234 " movl %%eax,%0\n"
23235- "7: rep; movsb\n"
23236+ "7: rep; "__copyuser_seg" movsb\n"
23237 "8:\n"
23238 ".section .fixup,\"ax\"\n"
23239 "9: lea 0(%%eax,%0,4),%0\n"
23240@@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23241 return size;
23242 }
23243
23244-static unsigned long __copy_user_intel_nocache(void *to,
23245+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23246 const void __user *from, unsigned long size)
23247 {
23248 int d0, d1;
23249
23250 __asm__ __volatile__(
23251 " .align 2,0x90\n"
23252- "0: movl 32(%4), %%eax\n"
23253+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23254 " cmpl $67, %0\n"
23255 " jbe 2f\n"
23256- "1: movl 64(%4), %%eax\n"
23257+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23258 " .align 2,0x90\n"
23259- "2: movl 0(%4), %%eax\n"
23260- "21: movl 4(%4), %%edx\n"
23261+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23262+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23263 " movnti %%eax, 0(%3)\n"
23264 " movnti %%edx, 4(%3)\n"
23265- "3: movl 8(%4), %%eax\n"
23266- "31: movl 12(%4),%%edx\n"
23267+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23268+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23269 " movnti %%eax, 8(%3)\n"
23270 " movnti %%edx, 12(%3)\n"
23271- "4: movl 16(%4), %%eax\n"
23272- "41: movl 20(%4), %%edx\n"
23273+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23274+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23275 " movnti %%eax, 16(%3)\n"
23276 " movnti %%edx, 20(%3)\n"
23277- "10: movl 24(%4), %%eax\n"
23278- "51: movl 28(%4), %%edx\n"
23279+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23280+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23281 " movnti %%eax, 24(%3)\n"
23282 " movnti %%edx, 28(%3)\n"
23283- "11: movl 32(%4), %%eax\n"
23284- "61: movl 36(%4), %%edx\n"
23285+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23286+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23287 " movnti %%eax, 32(%3)\n"
23288 " movnti %%edx, 36(%3)\n"
23289- "12: movl 40(%4), %%eax\n"
23290- "71: movl 44(%4), %%edx\n"
23291+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23292+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23293 " movnti %%eax, 40(%3)\n"
23294 " movnti %%edx, 44(%3)\n"
23295- "13: movl 48(%4), %%eax\n"
23296- "81: movl 52(%4), %%edx\n"
23297+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23298+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23299 " movnti %%eax, 48(%3)\n"
23300 " movnti %%edx, 52(%3)\n"
23301- "14: movl 56(%4), %%eax\n"
23302- "91: movl 60(%4), %%edx\n"
23303+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23304+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23305 " movnti %%eax, 56(%3)\n"
23306 " movnti %%edx, 60(%3)\n"
23307 " addl $-64, %0\n"
23308@@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23309 " shrl $2, %0\n"
23310 " andl $3, %%eax\n"
23311 " cld\n"
23312- "6: rep; movsl\n"
23313+ "6: rep; "__copyuser_seg" movsl\n"
23314 " movl %%eax,%0\n"
23315- "7: rep; movsb\n"
23316+ "7: rep; "__copyuser_seg" movsb\n"
23317 "8:\n"
23318 ".section .fixup,\"ax\"\n"
23319 "9: lea 0(%%eax,%0,4),%0\n"
23320@@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23321 */
23322 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23323 unsigned long size);
23324-unsigned long __copy_user_intel(void __user *to, const void *from,
23325+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23326+ unsigned long size);
23327+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23328 unsigned long size);
23329 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23330 const void __user *from, unsigned long size);
23331 #endif /* CONFIG_X86_INTEL_USERCOPY */
23332
23333 /* Generic arbitrary sized copy. */
23334-#define __copy_user(to, from, size) \
23335+#define __copy_user(to, from, size, prefix, set, restore) \
23336 do { \
23337 int __d0, __d1, __d2; \
23338 __asm__ __volatile__( \
23339+ set \
23340 " cmp $7,%0\n" \
23341 " jbe 1f\n" \
23342 " movl %1,%0\n" \
23343 " negl %0\n" \
23344 " andl $7,%0\n" \
23345 " subl %0,%3\n" \
23346- "4: rep; movsb\n" \
23347+ "4: rep; "prefix"movsb\n" \
23348 " movl %3,%0\n" \
23349 " shrl $2,%0\n" \
23350 " andl $3,%3\n" \
23351 " .align 2,0x90\n" \
23352- "0: rep; movsl\n" \
23353+ "0: rep; "prefix"movsl\n" \
23354 " movl %3,%0\n" \
23355- "1: rep; movsb\n" \
23356+ "1: rep; "prefix"movsb\n" \
23357 "2:\n" \
23358+ restore \
23359 ".section .fixup,\"ax\"\n" \
23360 "5: addl %3,%0\n" \
23361 " jmp 2b\n" \
23362@@ -537,14 +649,14 @@ do { \
23363 " negl %0\n" \
23364 " andl $7,%0\n" \
23365 " subl %0,%3\n" \
23366- "4: rep; movsb\n" \
23367+ "4: rep; "__copyuser_seg"movsb\n" \
23368 " movl %3,%0\n" \
23369 " shrl $2,%0\n" \
23370 " andl $3,%3\n" \
23371 " .align 2,0x90\n" \
23372- "0: rep; movsl\n" \
23373+ "0: rep; "__copyuser_seg"movsl\n" \
23374 " movl %3,%0\n" \
23375- "1: rep; movsb\n" \
23376+ "1: rep; "__copyuser_seg"movsb\n" \
23377 "2:\n" \
23378 ".section .fixup,\"ax\"\n" \
23379 "5: addl %3,%0\n" \
23380@@ -627,9 +739,9 @@ survive:
23381 }
23382 #endif
23383 if (movsl_is_ok(to, from, n))
23384- __copy_user(to, from, n);
23385+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23386 else
23387- n = __copy_user_intel(to, from, n);
23388+ n = __generic_copy_to_user_intel(to, from, n);
23389 return n;
23390 }
23391 EXPORT_SYMBOL(__copy_to_user_ll);
23392@@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23393 unsigned long n)
23394 {
23395 if (movsl_is_ok(to, from, n))
23396- __copy_user(to, from, n);
23397+ __copy_user(to, from, n, __copyuser_seg, "", "");
23398 else
23399- n = __copy_user_intel((void __user *)to,
23400- (const void *)from, n);
23401+ n = __generic_copy_from_user_intel(to, from, n);
23402 return n;
23403 }
23404 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23405@@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23406 if (n > 64 && cpu_has_xmm2)
23407 n = __copy_user_intel_nocache(to, from, n);
23408 else
23409- __copy_user(to, from, n);
23410+ __copy_user(to, from, n, __copyuser_seg, "", "");
23411 #else
23412- __copy_user(to, from, n);
23413+ __copy_user(to, from, n, __copyuser_seg, "", "");
23414 #endif
23415 return n;
23416 }
23417 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23418
23419-/**
23420- * copy_to_user: - Copy a block of data into user space.
23421- * @to: Destination address, in user space.
23422- * @from: Source address, in kernel space.
23423- * @n: Number of bytes to copy.
23424- *
23425- * Context: User context only. This function may sleep.
23426- *
23427- * Copy data from kernel space to user space.
23428- *
23429- * Returns number of bytes that could not be copied.
23430- * On success, this will be zero.
23431- */
23432-unsigned long
23433-copy_to_user(void __user *to, const void *from, unsigned long n)
23434-{
23435- if (access_ok(VERIFY_WRITE, to, n))
23436- n = __copy_to_user(to, from, n);
23437- return n;
23438-}
23439-EXPORT_SYMBOL(copy_to_user);
23440-
23441-/**
23442- * copy_from_user: - Copy a block of data from user space.
23443- * @to: Destination address, in kernel space.
23444- * @from: Source address, in user space.
23445- * @n: Number of bytes to copy.
23446- *
23447- * Context: User context only. This function may sleep.
23448- *
23449- * Copy data from user space to kernel space.
23450- *
23451- * Returns number of bytes that could not be copied.
23452- * On success, this will be zero.
23453- *
23454- * If some data could not be copied, this function will pad the copied
23455- * data to the requested size using zero bytes.
23456- */
23457-unsigned long
23458-_copy_from_user(void *to, const void __user *from, unsigned long n)
23459-{
23460- if (access_ok(VERIFY_READ, from, n))
23461- n = __copy_from_user(to, from, n);
23462- else
23463- memset(to, 0, n);
23464- return n;
23465-}
23466-EXPORT_SYMBOL(_copy_from_user);
23467-
23468 void copy_from_user_overflow(void)
23469 {
23470 WARN(1, "Buffer overflow detected!\n");
23471 }
23472 EXPORT_SYMBOL(copy_from_user_overflow);
23473+
23474+void copy_to_user_overflow(void)
23475+{
23476+ WARN(1, "Buffer overflow detected!\n");
23477+}
23478+EXPORT_SYMBOL(copy_to_user_overflow);
23479+
23480+#ifdef CONFIG_PAX_MEMORY_UDEREF
23481+void __set_fs(mm_segment_t x)
23482+{
23483+ switch (x.seg) {
23484+ case 0:
23485+ loadsegment(gs, 0);
23486+ break;
23487+ case TASK_SIZE_MAX:
23488+ loadsegment(gs, __USER_DS);
23489+ break;
23490+ case -1UL:
23491+ loadsegment(gs, __KERNEL_DS);
23492+ break;
23493+ default:
23494+ BUG();
23495+ }
23496+ return;
23497+}
23498+EXPORT_SYMBOL(__set_fs);
23499+
23500+void set_fs(mm_segment_t x)
23501+{
23502+ current_thread_info()->addr_limit = x;
23503+ __set_fs(x);
23504+}
23505+EXPORT_SYMBOL(set_fs);
23506+#endif
23507diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23508index e5b130b..6690d31 100644
23509--- a/arch/x86/lib/usercopy_64.c
23510+++ b/arch/x86/lib/usercopy_64.c
23511@@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23512 {
23513 long __d0;
23514 might_fault();
23515+
23516+#ifdef CONFIG_PAX_MEMORY_UDEREF
23517+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23518+ addr += PAX_USER_SHADOW_BASE;
23519+#endif
23520+
23521 /* no memory constraint because it doesn't change any memory gcc knows
23522 about */
23523 asm volatile(
23524@@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23525 }
23526 EXPORT_SYMBOL(clear_user);
23527
23528-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23529+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23530 {
23531- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23532- return copy_user_generic((__force void *)to, (__force void *)from, len);
23533- }
23534- return len;
23535+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23536+
23537+#ifdef CONFIG_PAX_MEMORY_UDEREF
23538+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23539+ to += PAX_USER_SHADOW_BASE;
23540+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23541+ from += PAX_USER_SHADOW_BASE;
23542+#endif
23543+
23544+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23545+ }
23546+ return len;
23547 }
23548 EXPORT_SYMBOL(copy_in_user);
23549
23550@@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23551 * it is not necessary to optimize tail handling.
23552 */
23553 unsigned long
23554-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23555+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23556 {
23557 char c;
23558 unsigned zero_len;
23559@@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23560 break;
23561 return len;
23562 }
23563+
23564+void copy_from_user_overflow(void)
23565+{
23566+ WARN(1, "Buffer overflow detected!\n");
23567+}
23568+EXPORT_SYMBOL(copy_from_user_overflow);
23569+
23570+void copy_to_user_overflow(void)
23571+{
23572+ WARN(1, "Buffer overflow detected!\n");
23573+}
23574+EXPORT_SYMBOL(copy_to_user_overflow);
23575diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23576index 903ec1e..c4166b2 100644
23577--- a/arch/x86/mm/extable.c
23578+++ b/arch/x86/mm/extable.c
23579@@ -6,12 +6,24 @@
23580 static inline unsigned long
23581 ex_insn_addr(const struct exception_table_entry *x)
23582 {
23583- return (unsigned long)&x->insn + x->insn;
23584+ unsigned long reloc = 0;
23585+
23586+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23587+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23588+#endif
23589+
23590+ return (unsigned long)&x->insn + x->insn + reloc;
23591 }
23592 static inline unsigned long
23593 ex_fixup_addr(const struct exception_table_entry *x)
23594 {
23595- return (unsigned long)&x->fixup + x->fixup;
23596+ unsigned long reloc = 0;
23597+
23598+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23599+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23600+#endif
23601+
23602+ return (unsigned long)&x->fixup + x->fixup + reloc;
23603 }
23604
23605 int fixup_exception(struct pt_regs *regs)
23606@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23607 unsigned long new_ip;
23608
23609 #ifdef CONFIG_PNPBIOS
23610- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23611+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23612 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23613 extern u32 pnp_bios_is_utter_crap;
23614 pnp_bios_is_utter_crap = 1;
23615@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23616 i += 4;
23617 p->fixup -= i;
23618 i += 4;
23619+
23620+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23621+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23622+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23623+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23624+#endif
23625+
23626 }
23627 }
23628
23629diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23630index 76dcd9d..e9dffde 100644
23631--- a/arch/x86/mm/fault.c
23632+++ b/arch/x86/mm/fault.c
23633@@ -13,11 +13,18 @@
23634 #include <linux/perf_event.h> /* perf_sw_event */
23635 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23636 #include <linux/prefetch.h> /* prefetchw */
23637+#include <linux/unistd.h>
23638+#include <linux/compiler.h>
23639
23640 #include <asm/traps.h> /* dotraplinkage, ... */
23641 #include <asm/pgalloc.h> /* pgd_*(), ... */
23642 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23643 #include <asm/fixmap.h> /* VSYSCALL_START */
23644+#include <asm/tlbflush.h>
23645+
23646+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23647+#include <asm/stacktrace.h>
23648+#endif
23649
23650 /*
23651 * Page fault error code bits:
23652@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23653 int ret = 0;
23654
23655 /* kprobe_running() needs smp_processor_id() */
23656- if (kprobes_built_in() && !user_mode_vm(regs)) {
23657+ if (kprobes_built_in() && !user_mode(regs)) {
23658 preempt_disable();
23659 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23660 ret = 1;
23661@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23662 return !instr_lo || (instr_lo>>1) == 1;
23663 case 0x00:
23664 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23665- if (probe_kernel_address(instr, opcode))
23666+ if (user_mode(regs)) {
23667+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23668+ return 0;
23669+ } else if (probe_kernel_address(instr, opcode))
23670 return 0;
23671
23672 *prefetch = (instr_lo == 0xF) &&
23673@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23674 while (instr < max_instr) {
23675 unsigned char opcode;
23676
23677- if (probe_kernel_address(instr, opcode))
23678+ if (user_mode(regs)) {
23679+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23680+ break;
23681+ } else if (probe_kernel_address(instr, opcode))
23682 break;
23683
23684 instr++;
23685@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23686 force_sig_info(si_signo, &info, tsk);
23687 }
23688
23689+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23690+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23691+#endif
23692+
23693+#ifdef CONFIG_PAX_EMUTRAMP
23694+static int pax_handle_fetch_fault(struct pt_regs *regs);
23695+#endif
23696+
23697+#ifdef CONFIG_PAX_PAGEEXEC
23698+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23699+{
23700+ pgd_t *pgd;
23701+ pud_t *pud;
23702+ pmd_t *pmd;
23703+
23704+ pgd = pgd_offset(mm, address);
23705+ if (!pgd_present(*pgd))
23706+ return NULL;
23707+ pud = pud_offset(pgd, address);
23708+ if (!pud_present(*pud))
23709+ return NULL;
23710+ pmd = pmd_offset(pud, address);
23711+ if (!pmd_present(*pmd))
23712+ return NULL;
23713+ return pmd;
23714+}
23715+#endif
23716+
23717 DEFINE_SPINLOCK(pgd_lock);
23718 LIST_HEAD(pgd_list);
23719
23720@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23721 for (address = VMALLOC_START & PMD_MASK;
23722 address >= TASK_SIZE && address < FIXADDR_TOP;
23723 address += PMD_SIZE) {
23724+
23725+#ifdef CONFIG_PAX_PER_CPU_PGD
23726+ unsigned long cpu;
23727+#else
23728 struct page *page;
23729+#endif
23730
23731 spin_lock(&pgd_lock);
23732+
23733+#ifdef CONFIG_PAX_PER_CPU_PGD
23734+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23735+ pgd_t *pgd = get_cpu_pgd(cpu);
23736+ pmd_t *ret;
23737+#else
23738 list_for_each_entry(page, &pgd_list, lru) {
23739+ pgd_t *pgd = page_address(page);
23740 spinlock_t *pgt_lock;
23741 pmd_t *ret;
23742
23743@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23744 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23745
23746 spin_lock(pgt_lock);
23747- ret = vmalloc_sync_one(page_address(page), address);
23748+#endif
23749+
23750+ ret = vmalloc_sync_one(pgd, address);
23751+
23752+#ifndef CONFIG_PAX_PER_CPU_PGD
23753 spin_unlock(pgt_lock);
23754+#endif
23755
23756 if (!ret)
23757 break;
23758@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23759 * an interrupt in the middle of a task switch..
23760 */
23761 pgd_paddr = read_cr3();
23762+
23763+#ifdef CONFIG_PAX_PER_CPU_PGD
23764+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23765+#endif
23766+
23767 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23768 if (!pmd_k)
23769 return -1;
23770@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23771 * happen within a race in page table update. In the later
23772 * case just flush:
23773 */
23774+
23775+#ifdef CONFIG_PAX_PER_CPU_PGD
23776+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23777+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23778+#else
23779 pgd = pgd_offset(current->active_mm, address);
23780+#endif
23781+
23782 pgd_ref = pgd_offset_k(address);
23783 if (pgd_none(*pgd_ref))
23784 return -1;
23785@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23786 static int is_errata100(struct pt_regs *regs, unsigned long address)
23787 {
23788 #ifdef CONFIG_X86_64
23789- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23790+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23791 return 1;
23792 #endif
23793 return 0;
23794@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23795 }
23796
23797 static const char nx_warning[] = KERN_CRIT
23798-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23799+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23800
23801 static void
23802 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23803@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23804 if (!oops_may_print())
23805 return;
23806
23807- if (error_code & PF_INSTR) {
23808+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23809 unsigned int level;
23810
23811 pte_t *pte = lookup_address(address, &level);
23812
23813 if (pte && pte_present(*pte) && !pte_exec(*pte))
23814- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23815+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23816 }
23817
23818+#ifdef CONFIG_PAX_KERNEXEC
23819+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23820+ if (current->signal->curr_ip)
23821+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23822+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23823+ else
23824+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23825+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23826+ }
23827+#endif
23828+
23829 printk(KERN_ALERT "BUG: unable to handle kernel ");
23830 if (address < PAGE_SIZE)
23831 printk(KERN_CONT "NULL pointer dereference");
23832@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23833 }
23834 #endif
23835
23836+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23837+ if (pax_is_fetch_fault(regs, error_code, address)) {
23838+
23839+#ifdef CONFIG_PAX_EMUTRAMP
23840+ switch (pax_handle_fetch_fault(regs)) {
23841+ case 2:
23842+ return;
23843+ }
23844+#endif
23845+
23846+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23847+ do_group_exit(SIGKILL);
23848+ }
23849+#endif
23850+
23851 if (unlikely(show_unhandled_signals))
23852 show_signal_msg(regs, error_code, address, tsk);
23853
23854@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23855 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23856 printk(KERN_ERR
23857 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23858- tsk->comm, tsk->pid, address);
23859+ tsk->comm, task_pid_nr(tsk), address);
23860 code = BUS_MCEERR_AR;
23861 }
23862 #endif
23863@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23864 return 1;
23865 }
23866
23867+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23868+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23869+{
23870+ pte_t *pte;
23871+ pmd_t *pmd;
23872+ spinlock_t *ptl;
23873+ unsigned char pte_mask;
23874+
23875+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23876+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23877+ return 0;
23878+
23879+ /* PaX: it's our fault, let's handle it if we can */
23880+
23881+ /* PaX: take a look at read faults before acquiring any locks */
23882+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23883+ /* instruction fetch attempt from a protected page in user mode */
23884+ up_read(&mm->mmap_sem);
23885+
23886+#ifdef CONFIG_PAX_EMUTRAMP
23887+ switch (pax_handle_fetch_fault(regs)) {
23888+ case 2:
23889+ return 1;
23890+ }
23891+#endif
23892+
23893+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23894+ do_group_exit(SIGKILL);
23895+ }
23896+
23897+ pmd = pax_get_pmd(mm, address);
23898+ if (unlikely(!pmd))
23899+ return 0;
23900+
23901+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23902+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23903+ pte_unmap_unlock(pte, ptl);
23904+ return 0;
23905+ }
23906+
23907+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23908+ /* write attempt to a protected page in user mode */
23909+ pte_unmap_unlock(pte, ptl);
23910+ return 0;
23911+ }
23912+
23913+#ifdef CONFIG_SMP
23914+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23915+#else
23916+ if (likely(address > get_limit(regs->cs)))
23917+#endif
23918+ {
23919+ set_pte(pte, pte_mkread(*pte));
23920+ __flush_tlb_one(address);
23921+ pte_unmap_unlock(pte, ptl);
23922+ up_read(&mm->mmap_sem);
23923+ return 1;
23924+ }
23925+
23926+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23927+
23928+ /*
23929+ * PaX: fill DTLB with user rights and retry
23930+ */
23931+ __asm__ __volatile__ (
23932+ "orb %2,(%1)\n"
23933+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23934+/*
23935+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23936+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23937+ * page fault when examined during a TLB load attempt. this is true not only
23938+ * for PTEs holding a non-present entry but also present entries that will
23939+ * raise a page fault (such as those set up by PaX, or the copy-on-write
23940+ * mechanism). in effect it means that we do *not* need to flush the TLBs
23941+ * for our target pages since their PTEs are simply not in the TLBs at all.
23942+
23943+ * the best thing in omitting it is that we gain around 15-20% speed in the
23944+ * fast path of the page fault handler and can get rid of tracing since we
23945+ * can no longer flush unintended entries.
23946+ */
23947+ "invlpg (%0)\n"
23948+#endif
23949+ __copyuser_seg"testb $0,(%0)\n"
23950+ "xorb %3,(%1)\n"
23951+ :
23952+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23953+ : "memory", "cc");
23954+ pte_unmap_unlock(pte, ptl);
23955+ up_read(&mm->mmap_sem);
23956+ return 1;
23957+}
23958+#endif
23959+
23960 /*
23961 * Handle a spurious fault caused by a stale TLB entry.
23962 *
23963@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23964 static inline int
23965 access_error(unsigned long error_code, struct vm_area_struct *vma)
23966 {
23967+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23968+ return 1;
23969+
23970 if (error_code & PF_WRITE) {
23971 /* write, present and write, not present: */
23972 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23973@@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23974 {
23975 struct vm_area_struct *vma;
23976 struct task_struct *tsk;
23977- unsigned long address;
23978 struct mm_struct *mm;
23979 int fault;
23980 int write = error_code & PF_WRITE;
23981 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23982 (write ? FAULT_FLAG_WRITE : 0);
23983
23984- tsk = current;
23985- mm = tsk->mm;
23986-
23987 /* Get the faulting address: */
23988- address = read_cr2();
23989+ unsigned long address = read_cr2();
23990+
23991+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23992+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23993+ if (!search_exception_tables(regs->ip)) {
23994+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23995+ bad_area_nosemaphore(regs, error_code, address);
23996+ return;
23997+ }
23998+ if (address < PAX_USER_SHADOW_BASE) {
23999+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24000+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24001+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24002+ } else
24003+ address -= PAX_USER_SHADOW_BASE;
24004+ }
24005+#endif
24006+
24007+ tsk = current;
24008+ mm = tsk->mm;
24009
24010 /*
24011 * Detect and handle instructions that would cause a page fault for
24012@@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24013 * User-mode registers count as a user access even for any
24014 * potential system fault or CPU buglet:
24015 */
24016- if (user_mode_vm(regs)) {
24017+ if (user_mode(regs)) {
24018 local_irq_enable();
24019 error_code |= PF_USER;
24020 } else {
24021@@ -1132,6 +1339,11 @@ retry:
24022 might_sleep();
24023 }
24024
24025+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24026+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24027+ return;
24028+#endif
24029+
24030 vma = find_vma(mm, address);
24031 if (unlikely(!vma)) {
24032 bad_area(regs, error_code, address);
24033@@ -1143,18 +1355,24 @@ retry:
24034 bad_area(regs, error_code, address);
24035 return;
24036 }
24037- if (error_code & PF_USER) {
24038- /*
24039- * Accessing the stack below %sp is always a bug.
24040- * The large cushion allows instructions like enter
24041- * and pusha to work. ("enter $65535, $31" pushes
24042- * 32 pointers and then decrements %sp by 65535.)
24043- */
24044- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24045- bad_area(regs, error_code, address);
24046- return;
24047- }
24048+ /*
24049+ * Accessing the stack below %sp is always a bug.
24050+ * The large cushion allows instructions like enter
24051+ * and pusha to work. ("enter $65535, $31" pushes
24052+ * 32 pointers and then decrements %sp by 65535.)
24053+ */
24054+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24055+ bad_area(regs, error_code, address);
24056+ return;
24057 }
24058+
24059+#ifdef CONFIG_PAX_SEGMEXEC
24060+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24061+ bad_area(regs, error_code, address);
24062+ return;
24063+ }
24064+#endif
24065+
24066 if (unlikely(expand_stack(vma, address))) {
24067 bad_area(regs, error_code, address);
24068 return;
24069@@ -1209,3 +1427,292 @@ good_area:
24070
24071 up_read(&mm->mmap_sem);
24072 }
24073+
24074+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24075+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24076+{
24077+ struct mm_struct *mm = current->mm;
24078+ unsigned long ip = regs->ip;
24079+
24080+ if (v8086_mode(regs))
24081+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24082+
24083+#ifdef CONFIG_PAX_PAGEEXEC
24084+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24085+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24086+ return true;
24087+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24088+ return true;
24089+ return false;
24090+ }
24091+#endif
24092+
24093+#ifdef CONFIG_PAX_SEGMEXEC
24094+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24095+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24096+ return true;
24097+ return false;
24098+ }
24099+#endif
24100+
24101+ return false;
24102+}
24103+#endif
24104+
24105+#ifdef CONFIG_PAX_EMUTRAMP
24106+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24107+{
24108+ int err;
24109+
24110+ do { /* PaX: libffi trampoline emulation */
24111+ unsigned char mov, jmp;
24112+ unsigned int addr1, addr2;
24113+
24114+#ifdef CONFIG_X86_64
24115+ if ((regs->ip + 9) >> 32)
24116+ break;
24117+#endif
24118+
24119+ err = get_user(mov, (unsigned char __user *)regs->ip);
24120+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24121+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24122+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24123+
24124+ if (err)
24125+ break;
24126+
24127+ if (mov == 0xB8 && jmp == 0xE9) {
24128+ regs->ax = addr1;
24129+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24130+ return 2;
24131+ }
24132+ } while (0);
24133+
24134+ do { /* PaX: gcc trampoline emulation #1 */
24135+ unsigned char mov1, mov2;
24136+ unsigned short jmp;
24137+ unsigned int addr1, addr2;
24138+
24139+#ifdef CONFIG_X86_64
24140+ if ((regs->ip + 11) >> 32)
24141+ break;
24142+#endif
24143+
24144+ err = get_user(mov1, (unsigned char __user *)regs->ip);
24145+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24146+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24147+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24148+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24149+
24150+ if (err)
24151+ break;
24152+
24153+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24154+ regs->cx = addr1;
24155+ regs->ax = addr2;
24156+ regs->ip = addr2;
24157+ return 2;
24158+ }
24159+ } while (0);
24160+
24161+ do { /* PaX: gcc trampoline emulation #2 */
24162+ unsigned char mov, jmp;
24163+ unsigned int addr1, addr2;
24164+
24165+#ifdef CONFIG_X86_64
24166+ if ((regs->ip + 9) >> 32)
24167+ break;
24168+#endif
24169+
24170+ err = get_user(mov, (unsigned char __user *)regs->ip);
24171+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24172+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24173+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24174+
24175+ if (err)
24176+ break;
24177+
24178+ if (mov == 0xB9 && jmp == 0xE9) {
24179+ regs->cx = addr1;
24180+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24181+ return 2;
24182+ }
24183+ } while (0);
24184+
24185+ return 1; /* PaX in action */
24186+}
24187+
24188+#ifdef CONFIG_X86_64
24189+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24190+{
24191+ int err;
24192+
24193+ do { /* PaX: libffi trampoline emulation */
24194+ unsigned short mov1, mov2, jmp1;
24195+ unsigned char stcclc, jmp2;
24196+ unsigned long addr1, addr2;
24197+
24198+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24199+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24200+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24201+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24202+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24203+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24204+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24205+
24206+ if (err)
24207+ break;
24208+
24209+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24210+ regs->r11 = addr1;
24211+ regs->r10 = addr2;
24212+ if (stcclc == 0xF8)
24213+ regs->flags &= ~X86_EFLAGS_CF;
24214+ else
24215+ regs->flags |= X86_EFLAGS_CF;
24216+ regs->ip = addr1;
24217+ return 2;
24218+ }
24219+ } while (0);
24220+
24221+ do { /* PaX: gcc trampoline emulation #1 */
24222+ unsigned short mov1, mov2, jmp1;
24223+ unsigned char jmp2;
24224+ unsigned int addr1;
24225+ unsigned long addr2;
24226+
24227+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24228+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24229+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24230+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24231+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24232+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24233+
24234+ if (err)
24235+ break;
24236+
24237+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24238+ regs->r11 = addr1;
24239+ regs->r10 = addr2;
24240+ regs->ip = addr1;
24241+ return 2;
24242+ }
24243+ } while (0);
24244+
24245+ do { /* PaX: gcc trampoline emulation #2 */
24246+ unsigned short mov1, mov2, jmp1;
24247+ unsigned char jmp2;
24248+ unsigned long addr1, addr2;
24249+
24250+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24251+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24252+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24253+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24254+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24255+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24256+
24257+ if (err)
24258+ break;
24259+
24260+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24261+ regs->r11 = addr1;
24262+ regs->r10 = addr2;
24263+ regs->ip = addr1;
24264+ return 2;
24265+ }
24266+ } while (0);
24267+
24268+ return 1; /* PaX in action */
24269+}
24270+#endif
24271+
24272+/*
24273+ * PaX: decide what to do with offenders (regs->ip = fault address)
24274+ *
24275+ * returns 1 when task should be killed
24276+ * 2 when gcc trampoline was detected
24277+ */
24278+static int pax_handle_fetch_fault(struct pt_regs *regs)
24279+{
24280+ if (v8086_mode(regs))
24281+ return 1;
24282+
24283+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24284+ return 1;
24285+
24286+#ifdef CONFIG_X86_32
24287+ return pax_handle_fetch_fault_32(regs);
24288+#else
24289+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24290+ return pax_handle_fetch_fault_32(regs);
24291+ else
24292+ return pax_handle_fetch_fault_64(regs);
24293+#endif
24294+}
24295+#endif
24296+
24297+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24298+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24299+{
24300+ long i;
24301+
24302+ printk(KERN_ERR "PAX: bytes at PC: ");
24303+ for (i = 0; i < 20; i++) {
24304+ unsigned char c;
24305+ if (get_user(c, (unsigned char __force_user *)pc+i))
24306+ printk(KERN_CONT "?? ");
24307+ else
24308+ printk(KERN_CONT "%02x ", c);
24309+ }
24310+ printk("\n");
24311+
24312+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24313+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24314+ unsigned long c;
24315+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24316+#ifdef CONFIG_X86_32
24317+ printk(KERN_CONT "???????? ");
24318+#else
24319+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24320+ printk(KERN_CONT "???????? ???????? ");
24321+ else
24322+ printk(KERN_CONT "???????????????? ");
24323+#endif
24324+ } else {
24325+#ifdef CONFIG_X86_64
24326+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24327+ printk(KERN_CONT "%08x ", (unsigned int)c);
24328+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24329+ } else
24330+#endif
24331+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24332+ }
24333+ }
24334+ printk("\n");
24335+}
24336+#endif
24337+
24338+/**
24339+ * probe_kernel_write(): safely attempt to write to a location
24340+ * @dst: address to write to
24341+ * @src: pointer to the data that shall be written
24342+ * @size: size of the data chunk
24343+ *
24344+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24345+ * happens, handle that and return -EFAULT.
24346+ */
24347+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24348+{
24349+ long ret;
24350+ mm_segment_t old_fs = get_fs();
24351+
24352+ set_fs(KERNEL_DS);
24353+ pagefault_disable();
24354+ pax_open_kernel();
24355+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24356+ pax_close_kernel();
24357+ pagefault_enable();
24358+ set_fs(old_fs);
24359+
24360+ return ret ? -EFAULT : 0;
24361+}
24362diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24363index dd74e46..7d26398 100644
24364--- a/arch/x86/mm/gup.c
24365+++ b/arch/x86/mm/gup.c
24366@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24367 addr = start;
24368 len = (unsigned long) nr_pages << PAGE_SHIFT;
24369 end = start + len;
24370- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24371+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24372 (void __user *)start, len)))
24373 return 0;
24374
24375diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24376index 6f31ee5..8ee4164 100644
24377--- a/arch/x86/mm/highmem_32.c
24378+++ b/arch/x86/mm/highmem_32.c
24379@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24380 idx = type + KM_TYPE_NR*smp_processor_id();
24381 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24382 BUG_ON(!pte_none(*(kmap_pte-idx)));
24383+
24384+ pax_open_kernel();
24385 set_pte(kmap_pte-idx, mk_pte(page, prot));
24386+ pax_close_kernel();
24387+
24388 arch_flush_lazy_mmu_mode();
24389
24390 return (void *)vaddr;
24391diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24392index b91e485..d00e7c9 100644
24393--- a/arch/x86/mm/hugetlbpage.c
24394+++ b/arch/x86/mm/hugetlbpage.c
24395@@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24396 struct hstate *h = hstate_file(file);
24397 struct mm_struct *mm = current->mm;
24398 struct vm_area_struct *vma;
24399- unsigned long start_addr;
24400+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24401+
24402+#ifdef CONFIG_PAX_SEGMEXEC
24403+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24404+ pax_task_size = SEGMEXEC_TASK_SIZE;
24405+#endif
24406+
24407+ pax_task_size -= PAGE_SIZE;
24408
24409 if (len > mm->cached_hole_size) {
24410- start_addr = mm->free_area_cache;
24411+ start_addr = mm->free_area_cache;
24412 } else {
24413- start_addr = TASK_UNMAPPED_BASE;
24414- mm->cached_hole_size = 0;
24415+ start_addr = mm->mmap_base;
24416+ mm->cached_hole_size = 0;
24417 }
24418
24419 full_search:
24420@@ -291,26 +298,27 @@ full_search:
24421
24422 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24423 /* At this point: (!vma || addr < vma->vm_end). */
24424- if (TASK_SIZE - len < addr) {
24425+ if (pax_task_size - len < addr) {
24426 /*
24427 * Start a new search - just in case we missed
24428 * some holes.
24429 */
24430- if (start_addr != TASK_UNMAPPED_BASE) {
24431- start_addr = TASK_UNMAPPED_BASE;
24432+ if (start_addr != mm->mmap_base) {
24433+ start_addr = mm->mmap_base;
24434 mm->cached_hole_size = 0;
24435 goto full_search;
24436 }
24437 return -ENOMEM;
24438 }
24439- if (!vma || addr + len <= vma->vm_start) {
24440- mm->free_area_cache = addr + len;
24441- return addr;
24442- }
24443+ if (check_heap_stack_gap(vma, addr, len))
24444+ break;
24445 if (addr + mm->cached_hole_size < vma->vm_start)
24446 mm->cached_hole_size = vma->vm_start - addr;
24447 addr = ALIGN(vma->vm_end, huge_page_size(h));
24448 }
24449+
24450+ mm->free_area_cache = addr + len;
24451+ return addr;
24452 }
24453
24454 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24455@@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24456 struct mm_struct *mm = current->mm;
24457 struct vm_area_struct *vma;
24458 unsigned long base = mm->mmap_base;
24459- unsigned long addr = addr0;
24460+ unsigned long addr;
24461 unsigned long largest_hole = mm->cached_hole_size;
24462- unsigned long start_addr;
24463
24464 /* don't allow allocations above current base */
24465 if (mm->free_area_cache > base)
24466@@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24467 largest_hole = 0;
24468 mm->free_area_cache = base;
24469 }
24470-try_again:
24471- start_addr = mm->free_area_cache;
24472
24473 /* make sure it can fit in the remaining address space */
24474 if (mm->free_area_cache < len)
24475 goto fail;
24476
24477 /* either no address requested or can't fit in requested address hole */
24478- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24479+ addr = mm->free_area_cache - len;
24480 do {
24481+ addr &= huge_page_mask(h);
24482 /*
24483 * Lookup failure means no vma is above this address,
24484 * i.e. return with success:
24485@@ -351,10 +357,10 @@ try_again:
24486 if (!vma)
24487 return addr;
24488
24489- if (addr + len <= vma->vm_start) {
24490+ if (check_heap_stack_gap(vma, addr, len)) {
24491 /* remember the address as a hint for next time */
24492- mm->cached_hole_size = largest_hole;
24493- return (mm->free_area_cache = addr);
24494+ mm->cached_hole_size = largest_hole;
24495+ return (mm->free_area_cache = addr);
24496 } else if (mm->free_area_cache == vma->vm_end) {
24497 /* pull free_area_cache down to the first hole */
24498 mm->free_area_cache = vma->vm_start;
24499@@ -363,29 +369,34 @@ try_again:
24500
24501 /* remember the largest hole we saw so far */
24502 if (addr + largest_hole < vma->vm_start)
24503- largest_hole = vma->vm_start - addr;
24504+ largest_hole = vma->vm_start - addr;
24505
24506 /* try just below the current vma->vm_start */
24507- addr = (vma->vm_start - len) & huge_page_mask(h);
24508- } while (len <= vma->vm_start);
24509+ addr = skip_heap_stack_gap(vma, len);
24510+ } while (!IS_ERR_VALUE(addr));
24511
24512 fail:
24513 /*
24514- * if hint left us with no space for the requested
24515- * mapping then try again:
24516- */
24517- if (start_addr != base) {
24518- mm->free_area_cache = base;
24519- largest_hole = 0;
24520- goto try_again;
24521- }
24522- /*
24523 * A failed mmap() very likely causes application failure,
24524 * so fall back to the bottom-up function here. This scenario
24525 * can happen with large stack limits and large mmap()
24526 * allocations.
24527 */
24528- mm->free_area_cache = TASK_UNMAPPED_BASE;
24529+
24530+#ifdef CONFIG_PAX_SEGMEXEC
24531+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24532+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24533+ else
24534+#endif
24535+
24536+ mm->mmap_base = TASK_UNMAPPED_BASE;
24537+
24538+#ifdef CONFIG_PAX_RANDMMAP
24539+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24540+ mm->mmap_base += mm->delta_mmap;
24541+#endif
24542+
24543+ mm->free_area_cache = mm->mmap_base;
24544 mm->cached_hole_size = ~0UL;
24545 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24546 len, pgoff, flags);
24547@@ -393,6 +404,7 @@ fail:
24548 /*
24549 * Restore the topdown base:
24550 */
24551+ mm->mmap_base = base;
24552 mm->free_area_cache = base;
24553 mm->cached_hole_size = ~0UL;
24554
24555@@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24556 struct hstate *h = hstate_file(file);
24557 struct mm_struct *mm = current->mm;
24558 struct vm_area_struct *vma;
24559+ unsigned long pax_task_size = TASK_SIZE;
24560
24561 if (len & ~huge_page_mask(h))
24562 return -EINVAL;
24563- if (len > TASK_SIZE)
24564+
24565+#ifdef CONFIG_PAX_SEGMEXEC
24566+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24567+ pax_task_size = SEGMEXEC_TASK_SIZE;
24568+#endif
24569+
24570+ pax_task_size -= PAGE_SIZE;
24571+
24572+ if (len > pax_task_size)
24573 return -ENOMEM;
24574
24575 if (flags & MAP_FIXED) {
24576@@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24577 if (addr) {
24578 addr = ALIGN(addr, huge_page_size(h));
24579 vma = find_vma(mm, addr);
24580- if (TASK_SIZE - len >= addr &&
24581- (!vma || addr + len <= vma->vm_start))
24582+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24583 return addr;
24584 }
24585 if (mm->get_unmapped_area == arch_get_unmapped_area)
24586diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24587index ab1f6a9..e16d764 100644
24588--- a/arch/x86/mm/init.c
24589+++ b/arch/x86/mm/init.c
24590@@ -16,6 +16,8 @@
24591 #include <asm/tlb.h>
24592 #include <asm/proto.h>
24593 #include <asm/dma.h> /* for MAX_DMA_PFN */
24594+#include <asm/desc.h>
24595+#include <asm/bios_ebda.h>
24596
24597 unsigned long __initdata pgt_buf_start;
24598 unsigned long __meminitdata pgt_buf_end;
24599@@ -38,7 +40,7 @@ struct map_range {
24600 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24601 int use_pse, int use_gbpages)
24602 {
24603- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24604+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24605 phys_addr_t base;
24606
24607 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24608@@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24609 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24610 * mmio resources as well as potential bios/acpi data regions.
24611 */
24612+
24613+#ifdef CONFIG_GRKERNSEC_KMEM
24614+static unsigned int ebda_start __read_only;
24615+static unsigned int ebda_end __read_only;
24616+#endif
24617+
24618 int devmem_is_allowed(unsigned long pagenr)
24619 {
24620- if (pagenr < 256)
24621+#ifdef CONFIG_GRKERNSEC_KMEM
24622+ /* allow BDA */
24623+ if (!pagenr)
24624 return 1;
24625+ /* allow EBDA */
24626+ if (pagenr >= ebda_start && pagenr < ebda_end)
24627+ return 1;
24628+#else
24629+ if (!pagenr)
24630+ return 1;
24631+#ifdef CONFIG_VM86
24632+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24633+ return 1;
24634+#endif
24635+#endif
24636+
24637+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24638+ return 1;
24639+#ifdef CONFIG_GRKERNSEC_KMEM
24640+ /* throw out everything else below 1MB */
24641+ if (pagenr <= 256)
24642+ return 0;
24643+#endif
24644 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24645 return 0;
24646 if (!page_is_ram(pagenr))
24647@@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24648 #endif
24649 }
24650
24651+#ifdef CONFIG_GRKERNSEC_KMEM
24652+static inline void gr_init_ebda(void)
24653+{
24654+ unsigned int ebda_addr;
24655+ unsigned int ebda_size = 0;
24656+
24657+ ebda_addr = get_bios_ebda();
24658+ if (ebda_addr) {
24659+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24660+ ebda_size <<= 10;
24661+ }
24662+ if (ebda_addr && ebda_size) {
24663+ ebda_start = ebda_addr >> PAGE_SHIFT;
24664+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24665+ } else {
24666+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24667+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24668+ }
24669+}
24670+#else
24671+static inline void gr_init_ebda(void) { }
24672+#endif
24673+
24674 void free_initmem(void)
24675 {
24676+#ifdef CONFIG_PAX_KERNEXEC
24677+#ifdef CONFIG_X86_32
24678+ /* PaX: limit KERNEL_CS to actual size */
24679+ unsigned long addr, limit;
24680+ struct desc_struct d;
24681+ int cpu;
24682+#else
24683+ pgd_t *pgd;
24684+ pud_t *pud;
24685+ pmd_t *pmd;
24686+ unsigned long addr, end;
24687+#endif
24688+#endif
24689+
24690+ gr_init_ebda();
24691+
24692+#ifdef CONFIG_PAX_KERNEXEC
24693+#ifdef CONFIG_X86_32
24694+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24695+ limit = (limit - 1UL) >> PAGE_SHIFT;
24696+
24697+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24698+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24699+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24700+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24701+ }
24702+
24703+ /* PaX: make KERNEL_CS read-only */
24704+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24705+ if (!paravirt_enabled())
24706+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24707+/*
24708+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24709+ pgd = pgd_offset_k(addr);
24710+ pud = pud_offset(pgd, addr);
24711+ pmd = pmd_offset(pud, addr);
24712+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24713+ }
24714+*/
24715+#ifdef CONFIG_X86_PAE
24716+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24717+/*
24718+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24719+ pgd = pgd_offset_k(addr);
24720+ pud = pud_offset(pgd, addr);
24721+ pmd = pmd_offset(pud, addr);
24722+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24723+ }
24724+*/
24725+#endif
24726+
24727+#ifdef CONFIG_MODULES
24728+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24729+#endif
24730+
24731+#else
24732+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24733+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24734+ pgd = pgd_offset_k(addr);
24735+ pud = pud_offset(pgd, addr);
24736+ pmd = pmd_offset(pud, addr);
24737+ if (!pmd_present(*pmd))
24738+ continue;
24739+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24740+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24741+ else
24742+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24743+ }
24744+
24745+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24746+ end = addr + KERNEL_IMAGE_SIZE;
24747+ for (; addr < end; addr += PMD_SIZE) {
24748+ pgd = pgd_offset_k(addr);
24749+ pud = pud_offset(pgd, addr);
24750+ pmd = pmd_offset(pud, addr);
24751+ if (!pmd_present(*pmd))
24752+ continue;
24753+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24754+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24755+ }
24756+#endif
24757+
24758+ flush_tlb_all();
24759+#endif
24760+
24761 free_init_pages("unused kernel memory",
24762 (unsigned long)(&__init_begin),
24763 (unsigned long)(&__init_end));
24764diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24765index 575d86f..4987469 100644
24766--- a/arch/x86/mm/init_32.c
24767+++ b/arch/x86/mm/init_32.c
24768@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24769 }
24770
24771 /*
24772- * Creates a middle page table and puts a pointer to it in the
24773- * given global directory entry. This only returns the gd entry
24774- * in non-PAE compilation mode, since the middle layer is folded.
24775- */
24776-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24777-{
24778- pud_t *pud;
24779- pmd_t *pmd_table;
24780-
24781-#ifdef CONFIG_X86_PAE
24782- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24783- if (after_bootmem)
24784- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24785- else
24786- pmd_table = (pmd_t *)alloc_low_page();
24787- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24788- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24789- pud = pud_offset(pgd, 0);
24790- BUG_ON(pmd_table != pmd_offset(pud, 0));
24791-
24792- return pmd_table;
24793- }
24794-#endif
24795- pud = pud_offset(pgd, 0);
24796- pmd_table = pmd_offset(pud, 0);
24797-
24798- return pmd_table;
24799-}
24800-
24801-/*
24802 * Create a page table and place a pointer to it in a middle page
24803 * directory entry:
24804 */
24805@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24806 page_table = (pte_t *)alloc_low_page();
24807
24808 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24809+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24810+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24811+#else
24812 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24813+#endif
24814 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24815 }
24816
24817 return pte_offset_kernel(pmd, 0);
24818 }
24819
24820+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24821+{
24822+ pud_t *pud;
24823+ pmd_t *pmd_table;
24824+
24825+ pud = pud_offset(pgd, 0);
24826+ pmd_table = pmd_offset(pud, 0);
24827+
24828+ return pmd_table;
24829+}
24830+
24831 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24832 {
24833 int pgd_idx = pgd_index(vaddr);
24834@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24835 int pgd_idx, pmd_idx;
24836 unsigned long vaddr;
24837 pgd_t *pgd;
24838+ pud_t *pud;
24839 pmd_t *pmd;
24840 pte_t *pte = NULL;
24841
24842@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24843 pgd = pgd_base + pgd_idx;
24844
24845 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24846- pmd = one_md_table_init(pgd);
24847- pmd = pmd + pmd_index(vaddr);
24848+ pud = pud_offset(pgd, vaddr);
24849+ pmd = pmd_offset(pud, vaddr);
24850+
24851+#ifdef CONFIG_X86_PAE
24852+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24853+#endif
24854+
24855 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24856 pmd++, pmd_idx++) {
24857 pte = page_table_kmap_check(one_page_table_init(pmd),
24858@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24859 }
24860 }
24861
24862-static inline int is_kernel_text(unsigned long addr)
24863+static inline int is_kernel_text(unsigned long start, unsigned long end)
24864 {
24865- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24866- return 1;
24867- return 0;
24868+ if ((start > ktla_ktva((unsigned long)_etext) ||
24869+ end <= ktla_ktva((unsigned long)_stext)) &&
24870+ (start > ktla_ktva((unsigned long)_einittext) ||
24871+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24872+
24873+#ifdef CONFIG_ACPI_SLEEP
24874+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24875+#endif
24876+
24877+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24878+ return 0;
24879+ return 1;
24880 }
24881
24882 /*
24883@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24884 unsigned long last_map_addr = end;
24885 unsigned long start_pfn, end_pfn;
24886 pgd_t *pgd_base = swapper_pg_dir;
24887- int pgd_idx, pmd_idx, pte_ofs;
24888+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24889 unsigned long pfn;
24890 pgd_t *pgd;
24891+ pud_t *pud;
24892 pmd_t *pmd;
24893 pte_t *pte;
24894 unsigned pages_2m, pages_4k;
24895@@ -280,8 +281,13 @@ repeat:
24896 pfn = start_pfn;
24897 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24898 pgd = pgd_base + pgd_idx;
24899- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24900- pmd = one_md_table_init(pgd);
24901+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24902+ pud = pud_offset(pgd, 0);
24903+ pmd = pmd_offset(pud, 0);
24904+
24905+#ifdef CONFIG_X86_PAE
24906+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24907+#endif
24908
24909 if (pfn >= end_pfn)
24910 continue;
24911@@ -293,14 +299,13 @@ repeat:
24912 #endif
24913 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24914 pmd++, pmd_idx++) {
24915- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24916+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24917
24918 /*
24919 * Map with big pages if possible, otherwise
24920 * create normal page tables:
24921 */
24922 if (use_pse) {
24923- unsigned int addr2;
24924 pgprot_t prot = PAGE_KERNEL_LARGE;
24925 /*
24926 * first pass will use the same initial
24927@@ -310,11 +315,7 @@ repeat:
24928 __pgprot(PTE_IDENT_ATTR |
24929 _PAGE_PSE);
24930
24931- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24932- PAGE_OFFSET + PAGE_SIZE-1;
24933-
24934- if (is_kernel_text(addr) ||
24935- is_kernel_text(addr2))
24936+ if (is_kernel_text(address, address + PMD_SIZE))
24937 prot = PAGE_KERNEL_LARGE_EXEC;
24938
24939 pages_2m++;
24940@@ -331,7 +332,7 @@ repeat:
24941 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24942 pte += pte_ofs;
24943 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24944- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24945+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24946 pgprot_t prot = PAGE_KERNEL;
24947 /*
24948 * first pass will use the same initial
24949@@ -339,7 +340,7 @@ repeat:
24950 */
24951 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24952
24953- if (is_kernel_text(addr))
24954+ if (is_kernel_text(address, address + PAGE_SIZE))
24955 prot = PAGE_KERNEL_EXEC;
24956
24957 pages_4k++;
24958@@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24959
24960 pud = pud_offset(pgd, va);
24961 pmd = pmd_offset(pud, va);
24962- if (!pmd_present(*pmd))
24963+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
24964 break;
24965
24966 pte = pte_offset_kernel(pmd, va);
24967@@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24968
24969 static void __init pagetable_init(void)
24970 {
24971- pgd_t *pgd_base = swapper_pg_dir;
24972-
24973- permanent_kmaps_init(pgd_base);
24974+ permanent_kmaps_init(swapper_pg_dir);
24975 }
24976
24977-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24978+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24979 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24980
24981 /* user-defined highmem size */
24982@@ -734,6 +733,12 @@ void __init mem_init(void)
24983
24984 pci_iommu_alloc();
24985
24986+#ifdef CONFIG_PAX_PER_CPU_PGD
24987+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24988+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24989+ KERNEL_PGD_PTRS);
24990+#endif
24991+
24992 #ifdef CONFIG_FLATMEM
24993 BUG_ON(!mem_map);
24994 #endif
24995@@ -760,7 +765,7 @@ void __init mem_init(void)
24996 reservedpages++;
24997
24998 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24999- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25000+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25001 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25002
25003 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25004@@ -801,10 +806,10 @@ void __init mem_init(void)
25005 ((unsigned long)&__init_end -
25006 (unsigned long)&__init_begin) >> 10,
25007
25008- (unsigned long)&_etext, (unsigned long)&_edata,
25009- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25010+ (unsigned long)&_sdata, (unsigned long)&_edata,
25011+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25012
25013- (unsigned long)&_text, (unsigned long)&_etext,
25014+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25015 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25016
25017 /*
25018@@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25019 if (!kernel_set_to_readonly)
25020 return;
25021
25022+ start = ktla_ktva(start);
25023 pr_debug("Set kernel text: %lx - %lx for read write\n",
25024 start, start+size);
25025
25026@@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25027 if (!kernel_set_to_readonly)
25028 return;
25029
25030+ start = ktla_ktva(start);
25031 pr_debug("Set kernel text: %lx - %lx for read only\n",
25032 start, start+size);
25033
25034@@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25035 unsigned long start = PFN_ALIGN(_text);
25036 unsigned long size = PFN_ALIGN(_etext) - start;
25037
25038+ start = ktla_ktva(start);
25039 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25040 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25041 size >> 10);
25042diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25043index 2b6b4a3..c17210d 100644
25044--- a/arch/x86/mm/init_64.c
25045+++ b/arch/x86/mm/init_64.c
25046@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25047 * around without checking the pgd every time.
25048 */
25049
25050-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25051+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25052 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25053
25054 int force_personality32;
25055@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25056
25057 for (address = start; address <= end; address += PGDIR_SIZE) {
25058 const pgd_t *pgd_ref = pgd_offset_k(address);
25059+
25060+#ifdef CONFIG_PAX_PER_CPU_PGD
25061+ unsigned long cpu;
25062+#else
25063 struct page *page;
25064+#endif
25065
25066 if (pgd_none(*pgd_ref))
25067 continue;
25068
25069 spin_lock(&pgd_lock);
25070+
25071+#ifdef CONFIG_PAX_PER_CPU_PGD
25072+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25073+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
25074+#else
25075 list_for_each_entry(page, &pgd_list, lru) {
25076 pgd_t *pgd;
25077 spinlock_t *pgt_lock;
25078@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25079 /* the pgt_lock only for Xen */
25080 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25081 spin_lock(pgt_lock);
25082+#endif
25083
25084 if (pgd_none(*pgd))
25085 set_pgd(pgd, *pgd_ref);
25086@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25087 BUG_ON(pgd_page_vaddr(*pgd)
25088 != pgd_page_vaddr(*pgd_ref));
25089
25090+#ifndef CONFIG_PAX_PER_CPU_PGD
25091 spin_unlock(pgt_lock);
25092+#endif
25093+
25094 }
25095 spin_unlock(&pgd_lock);
25096 }
25097@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25098 {
25099 if (pgd_none(*pgd)) {
25100 pud_t *pud = (pud_t *)spp_getpage();
25101- pgd_populate(&init_mm, pgd, pud);
25102+ pgd_populate_kernel(&init_mm, pgd, pud);
25103 if (pud != pud_offset(pgd, 0))
25104 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25105 pud, pud_offset(pgd, 0));
25106@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25107 {
25108 if (pud_none(*pud)) {
25109 pmd_t *pmd = (pmd_t *) spp_getpage();
25110- pud_populate(&init_mm, pud, pmd);
25111+ pud_populate_kernel(&init_mm, pud, pmd);
25112 if (pmd != pmd_offset(pud, 0))
25113 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25114 pmd, pmd_offset(pud, 0));
25115@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25116 pmd = fill_pmd(pud, vaddr);
25117 pte = fill_pte(pmd, vaddr);
25118
25119+ pax_open_kernel();
25120 set_pte(pte, new_pte);
25121+ pax_close_kernel();
25122
25123 /*
25124 * It's enough to flush this one mapping.
25125@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25126 pgd = pgd_offset_k((unsigned long)__va(phys));
25127 if (pgd_none(*pgd)) {
25128 pud = (pud_t *) spp_getpage();
25129- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25130- _PAGE_USER));
25131+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25132 }
25133 pud = pud_offset(pgd, (unsigned long)__va(phys));
25134 if (pud_none(*pud)) {
25135 pmd = (pmd_t *) spp_getpage();
25136- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25137- _PAGE_USER));
25138+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25139 }
25140 pmd = pmd_offset(pud, phys);
25141 BUG_ON(!pmd_none(*pmd));
25142@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25143 if (pfn >= pgt_buf_top)
25144 panic("alloc_low_page: ran out of memory");
25145
25146- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25147+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25148 clear_page(adr);
25149 *phys = pfn * PAGE_SIZE;
25150 return adr;
25151@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25152
25153 phys = __pa(virt);
25154 left = phys & (PAGE_SIZE - 1);
25155- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25156+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25157 adr = (void *)(((unsigned long)adr) | left);
25158
25159 return adr;
25160@@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25161 unmap_low_page(pmd);
25162
25163 spin_lock(&init_mm.page_table_lock);
25164- pud_populate(&init_mm, pud, __va(pmd_phys));
25165+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25166 spin_unlock(&init_mm.page_table_lock);
25167 }
25168 __flush_tlb_all();
25169@@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
25170 unmap_low_page(pud);
25171
25172 spin_lock(&init_mm.page_table_lock);
25173- pgd_populate(&init_mm, pgd, __va(pud_phys));
25174+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25175 spin_unlock(&init_mm.page_table_lock);
25176 pgd_changed = true;
25177 }
25178@@ -686,6 +700,12 @@ void __init mem_init(void)
25179
25180 pci_iommu_alloc();
25181
25182+#ifdef CONFIG_PAX_PER_CPU_PGD
25183+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25184+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25185+ KERNEL_PGD_PTRS);
25186+#endif
25187+
25188 /* clear_bss() already clear the empty_zero_page */
25189
25190 reservedpages = 0;
25191@@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
25192 static struct vm_area_struct gate_vma = {
25193 .vm_start = VSYSCALL_START,
25194 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25195- .vm_page_prot = PAGE_READONLY_EXEC,
25196- .vm_flags = VM_READ | VM_EXEC
25197+ .vm_page_prot = PAGE_READONLY,
25198+ .vm_flags = VM_READ
25199 };
25200
25201 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25202@@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
25203
25204 const char *arch_vma_name(struct vm_area_struct *vma)
25205 {
25206- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25207+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25208 return "[vdso]";
25209 if (vma == &gate_vma)
25210 return "[vsyscall]";
25211diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25212index 7b179b4..6bd1777 100644
25213--- a/arch/x86/mm/iomap_32.c
25214+++ b/arch/x86/mm/iomap_32.c
25215@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25216 type = kmap_atomic_idx_push();
25217 idx = type + KM_TYPE_NR * smp_processor_id();
25218 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25219+
25220+ pax_open_kernel();
25221 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25222+ pax_close_kernel();
25223+
25224 arch_flush_lazy_mmu_mode();
25225
25226 return (void *)vaddr;
25227diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25228index 78fe3f1..8293b6f 100644
25229--- a/arch/x86/mm/ioremap.c
25230+++ b/arch/x86/mm/ioremap.c
25231@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25232 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25233 int is_ram = page_is_ram(pfn);
25234
25235- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25236+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25237 return NULL;
25238 WARN_ON_ONCE(is_ram);
25239 }
25240@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25241
25242 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25243 if (page_is_ram(start >> PAGE_SHIFT))
25244+#ifdef CONFIG_HIGHMEM
25245+ if ((start >> PAGE_SHIFT) < max_low_pfn)
25246+#endif
25247 return __va(phys);
25248
25249 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25250@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25251 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25252
25253 static __initdata int after_paging_init;
25254-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25255+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25256
25257 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25258 {
25259@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25260 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25261
25262 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25263- memset(bm_pte, 0, sizeof(bm_pte));
25264- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25265+ pmd_populate_user(&init_mm, pmd, bm_pte);
25266
25267 /*
25268 * The boot-ioremap range spans multiple pmds, for which
25269diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25270index d87dd6d..bf3fa66 100644
25271--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25272+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25273@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25274 * memory (e.g. tracked pages)? For now, we need this to avoid
25275 * invoking kmemcheck for PnP BIOS calls.
25276 */
25277- if (regs->flags & X86_VM_MASK)
25278+ if (v8086_mode(regs))
25279 return false;
25280- if (regs->cs != __KERNEL_CS)
25281+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25282 return false;
25283
25284 pte = kmemcheck_pte_lookup(address);
25285diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25286index 845df68..1d8d29f 100644
25287--- a/arch/x86/mm/mmap.c
25288+++ b/arch/x86/mm/mmap.c
25289@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25290 * Leave an at least ~128 MB hole with possible stack randomization.
25291 */
25292 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25293-#define MAX_GAP (TASK_SIZE/6*5)
25294+#define MAX_GAP (pax_task_size/6*5)
25295
25296 static int mmap_is_legacy(void)
25297 {
25298@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25299 return rnd << PAGE_SHIFT;
25300 }
25301
25302-static unsigned long mmap_base(void)
25303+static unsigned long mmap_base(struct mm_struct *mm)
25304 {
25305 unsigned long gap = rlimit(RLIMIT_STACK);
25306+ unsigned long pax_task_size = TASK_SIZE;
25307+
25308+#ifdef CONFIG_PAX_SEGMEXEC
25309+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25310+ pax_task_size = SEGMEXEC_TASK_SIZE;
25311+#endif
25312
25313 if (gap < MIN_GAP)
25314 gap = MIN_GAP;
25315 else if (gap > MAX_GAP)
25316 gap = MAX_GAP;
25317
25318- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25319+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25320 }
25321
25322 /*
25323 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25324 * does, but not when emulating X86_32
25325 */
25326-static unsigned long mmap_legacy_base(void)
25327+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25328 {
25329- if (mmap_is_ia32())
25330+ if (mmap_is_ia32()) {
25331+
25332+#ifdef CONFIG_PAX_SEGMEXEC
25333+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25334+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25335+ else
25336+#endif
25337+
25338 return TASK_UNMAPPED_BASE;
25339- else
25340+ } else
25341 return TASK_UNMAPPED_BASE + mmap_rnd();
25342 }
25343
25344@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25345 void arch_pick_mmap_layout(struct mm_struct *mm)
25346 {
25347 if (mmap_is_legacy()) {
25348- mm->mmap_base = mmap_legacy_base();
25349+ mm->mmap_base = mmap_legacy_base(mm);
25350+
25351+#ifdef CONFIG_PAX_RANDMMAP
25352+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25353+ mm->mmap_base += mm->delta_mmap;
25354+#endif
25355+
25356 mm->get_unmapped_area = arch_get_unmapped_area;
25357 mm->unmap_area = arch_unmap_area;
25358 } else {
25359- mm->mmap_base = mmap_base();
25360+ mm->mmap_base = mmap_base(mm);
25361+
25362+#ifdef CONFIG_PAX_RANDMMAP
25363+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25364+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25365+#endif
25366+
25367 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25368 mm->unmap_area = arch_unmap_area_topdown;
25369 }
25370diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25371index dc0b727..dc9d71a 100644
25372--- a/arch/x86/mm/mmio-mod.c
25373+++ b/arch/x86/mm/mmio-mod.c
25374@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25375 break;
25376 default:
25377 {
25378- unsigned char *ip = (unsigned char *)instptr;
25379+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25380 my_trace->opcode = MMIO_UNKNOWN_OP;
25381 my_trace->width = 0;
25382 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25383@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25384 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25385 void __iomem *addr)
25386 {
25387- static atomic_t next_id;
25388+ static atomic_unchecked_t next_id;
25389 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25390 /* These are page-unaligned. */
25391 struct mmiotrace_map map = {
25392@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25393 .private = trace
25394 },
25395 .phys = offset,
25396- .id = atomic_inc_return(&next_id)
25397+ .id = atomic_inc_return_unchecked(&next_id)
25398 };
25399 map.map_id = trace->id;
25400
25401diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25402index b008656..773eac2 100644
25403--- a/arch/x86/mm/pageattr-test.c
25404+++ b/arch/x86/mm/pageattr-test.c
25405@@ -36,7 +36,7 @@ enum {
25406
25407 static int pte_testbit(pte_t pte)
25408 {
25409- return pte_flags(pte) & _PAGE_UNUSED1;
25410+ return pte_flags(pte) & _PAGE_CPA_TEST;
25411 }
25412
25413 struct split_state {
25414diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25415index a718e0d..45efc32 100644
25416--- a/arch/x86/mm/pageattr.c
25417+++ b/arch/x86/mm/pageattr.c
25418@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25419 */
25420 #ifdef CONFIG_PCI_BIOS
25421 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25422- pgprot_val(forbidden) |= _PAGE_NX;
25423+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25424 #endif
25425
25426 /*
25427@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25428 * Does not cover __inittext since that is gone later on. On
25429 * 64bit we do not enforce !NX on the low mapping
25430 */
25431- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25432- pgprot_val(forbidden) |= _PAGE_NX;
25433+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25434+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25435
25436+#ifdef CONFIG_DEBUG_RODATA
25437 /*
25438 * The .rodata section needs to be read-only. Using the pfn
25439 * catches all aliases.
25440@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25441 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25442 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25443 pgprot_val(forbidden) |= _PAGE_RW;
25444+#endif
25445
25446 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25447 /*
25448@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25449 }
25450 #endif
25451
25452+#ifdef CONFIG_PAX_KERNEXEC
25453+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25454+ pgprot_val(forbidden) |= _PAGE_RW;
25455+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25456+ }
25457+#endif
25458+
25459 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25460
25461 return prot;
25462@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25463 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25464 {
25465 /* change init_mm */
25466+ pax_open_kernel();
25467 set_pte_atomic(kpte, pte);
25468+
25469 #ifdef CONFIG_X86_32
25470 if (!SHARED_KERNEL_PMD) {
25471+
25472+#ifdef CONFIG_PAX_PER_CPU_PGD
25473+ unsigned long cpu;
25474+#else
25475 struct page *page;
25476+#endif
25477
25478+#ifdef CONFIG_PAX_PER_CPU_PGD
25479+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25480+ pgd_t *pgd = get_cpu_pgd(cpu);
25481+#else
25482 list_for_each_entry(page, &pgd_list, lru) {
25483- pgd_t *pgd;
25484+ pgd_t *pgd = (pgd_t *)page_address(page);
25485+#endif
25486+
25487 pud_t *pud;
25488 pmd_t *pmd;
25489
25490- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25491+ pgd += pgd_index(address);
25492 pud = pud_offset(pgd, address);
25493 pmd = pmd_offset(pud, address);
25494 set_pte_atomic((pte_t *)pmd, pte);
25495 }
25496 }
25497 #endif
25498+ pax_close_kernel();
25499 }
25500
25501 static int
25502diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25503index 3d68ef6..7f69136 100644
25504--- a/arch/x86/mm/pat.c
25505+++ b/arch/x86/mm/pat.c
25506@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25507
25508 if (!entry) {
25509 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25510- current->comm, current->pid, start, end - 1);
25511+ current->comm, task_pid_nr(current), start, end - 1);
25512 return -EINVAL;
25513 }
25514
25515@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25516
25517 while (cursor < to) {
25518 if (!devmem_is_allowed(pfn)) {
25519- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25520- current->comm, from, to - 1);
25521+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25522+ current->comm, from, to - 1, cursor);
25523 return 0;
25524 }
25525 cursor += PAGE_SIZE;
25526@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25527 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25528 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25529 "for [mem %#010Lx-%#010Lx]\n",
25530- current->comm, current->pid,
25531+ current->comm, task_pid_nr(current),
25532 cattr_name(flags),
25533 base, (unsigned long long)(base + size-1));
25534 return -EINVAL;
25535@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25536 flags = lookup_memtype(paddr);
25537 if (want_flags != flags) {
25538 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25539- current->comm, current->pid,
25540+ current->comm, task_pid_nr(current),
25541 cattr_name(want_flags),
25542 (unsigned long long)paddr,
25543 (unsigned long long)(paddr + size - 1),
25544@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25545 free_memtype(paddr, paddr + size);
25546 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25547 " for [mem %#010Lx-%#010Lx], got %s\n",
25548- current->comm, current->pid,
25549+ current->comm, task_pid_nr(current),
25550 cattr_name(want_flags),
25551 (unsigned long long)paddr,
25552 (unsigned long long)(paddr + size - 1),
25553diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25554index 9f0614d..92ae64a 100644
25555--- a/arch/x86/mm/pf_in.c
25556+++ b/arch/x86/mm/pf_in.c
25557@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25558 int i;
25559 enum reason_type rv = OTHERS;
25560
25561- p = (unsigned char *)ins_addr;
25562+ p = (unsigned char *)ktla_ktva(ins_addr);
25563 p += skip_prefix(p, &prf);
25564 p += get_opcode(p, &opcode);
25565
25566@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25567 struct prefix_bits prf;
25568 int i;
25569
25570- p = (unsigned char *)ins_addr;
25571+ p = (unsigned char *)ktla_ktva(ins_addr);
25572 p += skip_prefix(p, &prf);
25573 p += get_opcode(p, &opcode);
25574
25575@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25576 struct prefix_bits prf;
25577 int i;
25578
25579- p = (unsigned char *)ins_addr;
25580+ p = (unsigned char *)ktla_ktva(ins_addr);
25581 p += skip_prefix(p, &prf);
25582 p += get_opcode(p, &opcode);
25583
25584@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25585 struct prefix_bits prf;
25586 int i;
25587
25588- p = (unsigned char *)ins_addr;
25589+ p = (unsigned char *)ktla_ktva(ins_addr);
25590 p += skip_prefix(p, &prf);
25591 p += get_opcode(p, &opcode);
25592 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25593@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25594 struct prefix_bits prf;
25595 int i;
25596
25597- p = (unsigned char *)ins_addr;
25598+ p = (unsigned char *)ktla_ktva(ins_addr);
25599 p += skip_prefix(p, &prf);
25600 p += get_opcode(p, &opcode);
25601 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25602diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25603index 8573b83..4f3ed7e 100644
25604--- a/arch/x86/mm/pgtable.c
25605+++ b/arch/x86/mm/pgtable.c
25606@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25607 list_del(&page->lru);
25608 }
25609
25610-#define UNSHARED_PTRS_PER_PGD \
25611- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25612+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25613+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25614
25615+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25616+{
25617+ unsigned int count = USER_PGD_PTRS;
25618
25619+ while (count--)
25620+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25621+}
25622+#endif
25623+
25624+#ifdef CONFIG_PAX_PER_CPU_PGD
25625+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25626+{
25627+ unsigned int count = USER_PGD_PTRS;
25628+
25629+ while (count--) {
25630+ pgd_t pgd;
25631+
25632+#ifdef CONFIG_X86_64
25633+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25634+#else
25635+ pgd = *src++;
25636+#endif
25637+
25638+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25639+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25640+#endif
25641+
25642+ *dst++ = pgd;
25643+ }
25644+
25645+}
25646+#endif
25647+
25648+#ifdef CONFIG_X86_64
25649+#define pxd_t pud_t
25650+#define pyd_t pgd_t
25651+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25652+#define pxd_free(mm, pud) pud_free((mm), (pud))
25653+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25654+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25655+#define PYD_SIZE PGDIR_SIZE
25656+#else
25657+#define pxd_t pmd_t
25658+#define pyd_t pud_t
25659+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25660+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25661+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25662+#define pyd_offset(mm, address) pud_offset((mm), (address))
25663+#define PYD_SIZE PUD_SIZE
25664+#endif
25665+
25666+#ifdef CONFIG_PAX_PER_CPU_PGD
25667+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25668+static inline void pgd_dtor(pgd_t *pgd) {}
25669+#else
25670 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25671 {
25672 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25673@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25674 pgd_list_del(pgd);
25675 spin_unlock(&pgd_lock);
25676 }
25677+#endif
25678
25679 /*
25680 * List of all pgd's needed for non-PAE so it can invalidate entries
25681@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25682 * -- wli
25683 */
25684
25685-#ifdef CONFIG_X86_PAE
25686+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25687 /*
25688 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25689 * updating the top-level pagetable entries to guarantee the
25690@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25691 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25692 * and initialize the kernel pmds here.
25693 */
25694-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25695+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25696
25697 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25698 {
25699@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25700 */
25701 flush_tlb_mm(mm);
25702 }
25703+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25704+#define PREALLOCATED_PXDS USER_PGD_PTRS
25705 #else /* !CONFIG_X86_PAE */
25706
25707 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25708-#define PREALLOCATED_PMDS 0
25709+#define PREALLOCATED_PXDS 0
25710
25711 #endif /* CONFIG_X86_PAE */
25712
25713-static void free_pmds(pmd_t *pmds[])
25714+static void free_pxds(pxd_t *pxds[])
25715 {
25716 int i;
25717
25718- for(i = 0; i < PREALLOCATED_PMDS; i++)
25719- if (pmds[i])
25720- free_page((unsigned long)pmds[i]);
25721+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25722+ if (pxds[i])
25723+ free_page((unsigned long)pxds[i]);
25724 }
25725
25726-static int preallocate_pmds(pmd_t *pmds[])
25727+static int preallocate_pxds(pxd_t *pxds[])
25728 {
25729 int i;
25730 bool failed = false;
25731
25732- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25733- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25734- if (pmd == NULL)
25735+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25736+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25737+ if (pxd == NULL)
25738 failed = true;
25739- pmds[i] = pmd;
25740+ pxds[i] = pxd;
25741 }
25742
25743 if (failed) {
25744- free_pmds(pmds);
25745+ free_pxds(pxds);
25746 return -ENOMEM;
25747 }
25748
25749@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25750 * preallocate which never got a corresponding vma will need to be
25751 * freed manually.
25752 */
25753-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25754+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25755 {
25756 int i;
25757
25758- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25759+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25760 pgd_t pgd = pgdp[i];
25761
25762 if (pgd_val(pgd) != 0) {
25763- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25764+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25765
25766- pgdp[i] = native_make_pgd(0);
25767+ set_pgd(pgdp + i, native_make_pgd(0));
25768
25769- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25770- pmd_free(mm, pmd);
25771+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25772+ pxd_free(mm, pxd);
25773 }
25774 }
25775 }
25776
25777-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25778+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25779 {
25780- pud_t *pud;
25781+ pyd_t *pyd;
25782 unsigned long addr;
25783 int i;
25784
25785- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25786+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25787 return;
25788
25789- pud = pud_offset(pgd, 0);
25790+#ifdef CONFIG_X86_64
25791+ pyd = pyd_offset(mm, 0L);
25792+#else
25793+ pyd = pyd_offset(pgd, 0L);
25794+#endif
25795
25796- for (addr = i = 0; i < PREALLOCATED_PMDS;
25797- i++, pud++, addr += PUD_SIZE) {
25798- pmd_t *pmd = pmds[i];
25799+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25800+ i++, pyd++, addr += PYD_SIZE) {
25801+ pxd_t *pxd = pxds[i];
25802
25803 if (i >= KERNEL_PGD_BOUNDARY)
25804- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25805- sizeof(pmd_t) * PTRS_PER_PMD);
25806+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25807+ sizeof(pxd_t) * PTRS_PER_PMD);
25808
25809- pud_populate(mm, pud, pmd);
25810+ pyd_populate(mm, pyd, pxd);
25811 }
25812 }
25813
25814 pgd_t *pgd_alloc(struct mm_struct *mm)
25815 {
25816 pgd_t *pgd;
25817- pmd_t *pmds[PREALLOCATED_PMDS];
25818+ pxd_t *pxds[PREALLOCATED_PXDS];
25819
25820 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25821
25822@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25823
25824 mm->pgd = pgd;
25825
25826- if (preallocate_pmds(pmds) != 0)
25827+ if (preallocate_pxds(pxds) != 0)
25828 goto out_free_pgd;
25829
25830 if (paravirt_pgd_alloc(mm) != 0)
25831- goto out_free_pmds;
25832+ goto out_free_pxds;
25833
25834 /*
25835 * Make sure that pre-populating the pmds is atomic with
25836@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25837 spin_lock(&pgd_lock);
25838
25839 pgd_ctor(mm, pgd);
25840- pgd_prepopulate_pmd(mm, pgd, pmds);
25841+ pgd_prepopulate_pxd(mm, pgd, pxds);
25842
25843 spin_unlock(&pgd_lock);
25844
25845 return pgd;
25846
25847-out_free_pmds:
25848- free_pmds(pmds);
25849+out_free_pxds:
25850+ free_pxds(pxds);
25851 out_free_pgd:
25852 free_page((unsigned long)pgd);
25853 out:
25854@@ -295,7 +356,7 @@ out:
25855
25856 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25857 {
25858- pgd_mop_up_pmds(mm, pgd);
25859+ pgd_mop_up_pxds(mm, pgd);
25860 pgd_dtor(pgd);
25861 paravirt_pgd_free(mm, pgd);
25862 free_page((unsigned long)pgd);
25863diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25864index a69bcb8..19068ab 100644
25865--- a/arch/x86/mm/pgtable_32.c
25866+++ b/arch/x86/mm/pgtable_32.c
25867@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25868 return;
25869 }
25870 pte = pte_offset_kernel(pmd, vaddr);
25871+
25872+ pax_open_kernel();
25873 if (pte_val(pteval))
25874 set_pte_at(&init_mm, vaddr, pte, pteval);
25875 else
25876 pte_clear(&init_mm, vaddr, pte);
25877+ pax_close_kernel();
25878
25879 /*
25880 * It's enough to flush this one mapping.
25881diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25882index 410531d..0f16030 100644
25883--- a/arch/x86/mm/setup_nx.c
25884+++ b/arch/x86/mm/setup_nx.c
25885@@ -5,8 +5,10 @@
25886 #include <asm/pgtable.h>
25887 #include <asm/proto.h>
25888
25889+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25890 static int disable_nx __cpuinitdata;
25891
25892+#ifndef CONFIG_PAX_PAGEEXEC
25893 /*
25894 * noexec = on|off
25895 *
25896@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25897 return 0;
25898 }
25899 early_param("noexec", noexec_setup);
25900+#endif
25901+
25902+#endif
25903
25904 void __cpuinit x86_configure_nx(void)
25905 {
25906+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25907 if (cpu_has_nx && !disable_nx)
25908 __supported_pte_mask |= _PAGE_NX;
25909 else
25910+#endif
25911 __supported_pte_mask &= ~_PAGE_NX;
25912 }
25913
25914diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25915index 613cd83..3a21f1c 100644
25916--- a/arch/x86/mm/tlb.c
25917+++ b/arch/x86/mm/tlb.c
25918@@ -48,7 +48,11 @@ void leave_mm(int cpu)
25919 BUG();
25920 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25921 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25922+
25923+#ifndef CONFIG_PAX_PER_CPU_PGD
25924 load_cr3(swapper_pg_dir);
25925+#endif
25926+
25927 }
25928 }
25929 EXPORT_SYMBOL_GPL(leave_mm);
25930diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25931index 877b9a1..a8ecf42 100644
25932--- a/arch/x86/net/bpf_jit.S
25933+++ b/arch/x86/net/bpf_jit.S
25934@@ -9,6 +9,7 @@
25935 */
25936 #include <linux/linkage.h>
25937 #include <asm/dwarf2.h>
25938+#include <asm/alternative-asm.h>
25939
25940 /*
25941 * Calling convention :
25942@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25943 jle bpf_slow_path_word
25944 mov (SKBDATA,%rsi),%eax
25945 bswap %eax /* ntohl() */
25946+ pax_force_retaddr
25947 ret
25948
25949 sk_load_half:
25950@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25951 jle bpf_slow_path_half
25952 movzwl (SKBDATA,%rsi),%eax
25953 rol $8,%ax # ntohs()
25954+ pax_force_retaddr
25955 ret
25956
25957 sk_load_byte:
25958@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25959 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25960 jle bpf_slow_path_byte
25961 movzbl (SKBDATA,%rsi),%eax
25962+ pax_force_retaddr
25963 ret
25964
25965 /**
25966@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25967 movzbl (SKBDATA,%rsi),%ebx
25968 and $15,%bl
25969 shl $2,%bl
25970+ pax_force_retaddr
25971 ret
25972
25973 /* rsi contains offset and can be scratched */
25974@@ -109,6 +114,7 @@ bpf_slow_path_word:
25975 js bpf_error
25976 mov -12(%rbp),%eax
25977 bswap %eax
25978+ pax_force_retaddr
25979 ret
25980
25981 bpf_slow_path_half:
25982@@ -117,12 +123,14 @@ bpf_slow_path_half:
25983 mov -12(%rbp),%ax
25984 rol $8,%ax
25985 movzwl %ax,%eax
25986+ pax_force_retaddr
25987 ret
25988
25989 bpf_slow_path_byte:
25990 bpf_slow_path_common(1)
25991 js bpf_error
25992 movzbl -12(%rbp),%eax
25993+ pax_force_retaddr
25994 ret
25995
25996 bpf_slow_path_byte_msh:
25997@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25998 and $15,%al
25999 shl $2,%al
26000 xchg %eax,%ebx
26001+ pax_force_retaddr
26002 ret
26003
26004 #define sk_negative_common(SIZE) \
26005@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26006 sk_negative_common(4)
26007 mov (%rax), %eax
26008 bswap %eax
26009+ pax_force_retaddr
26010 ret
26011
26012 bpf_slow_path_half_neg:
26013@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26014 mov (%rax),%ax
26015 rol $8,%ax
26016 movzwl %ax,%eax
26017+ pax_force_retaddr
26018 ret
26019
26020 bpf_slow_path_byte_neg:
26021@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26022 .globl sk_load_byte_negative_offset
26023 sk_negative_common(1)
26024 movzbl (%rax), %eax
26025+ pax_force_retaddr
26026 ret
26027
26028 bpf_slow_path_byte_msh_neg:
26029@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26030 and $15,%al
26031 shl $2,%al
26032 xchg %eax,%ebx
26033+ pax_force_retaddr
26034 ret
26035
26036 bpf_error:
26037@@ -197,4 +210,5 @@ bpf_error:
26038 xor %eax,%eax
26039 mov -8(%rbp),%rbx
26040 leaveq
26041+ pax_force_retaddr
26042 ret
26043diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26044index 33643a8..8e44870 100644
26045--- a/arch/x86/net/bpf_jit_comp.c
26046+++ b/arch/x86/net/bpf_jit_comp.c
26047@@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26048 set_fs(old_fs);
26049 }
26050
26051+struct bpf_jit_work {
26052+ struct work_struct work;
26053+ void *image;
26054+};
26055+
26056 #define CHOOSE_LOAD_FUNC(K, func) \
26057 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26058
26059@@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26060 if (addrs == NULL)
26061 return;
26062
26063+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26064+ if (!fp->work)
26065+ goto out;
26066+
26067 /* Before first pass, make a rough estimation of addrs[]
26068 * each bpf instruction is translated to less than 64 bytes
26069 */
26070@@ -593,17 +602,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26071 break;
26072 default:
26073 /* hmm, too complex filter, give up with jit compiler */
26074- goto out;
26075+ goto error;
26076 }
26077 ilen = prog - temp;
26078 if (image) {
26079 if (unlikely(proglen + ilen > oldproglen)) {
26080 pr_err("bpb_jit_compile fatal error\n");
26081- kfree(addrs);
26082- module_free(NULL, image);
26083- return;
26084+ module_free_exec(NULL, image);
26085+ goto error;
26086 }
26087+ pax_open_kernel();
26088 memcpy(image + proglen, temp, ilen);
26089+ pax_close_kernel();
26090 }
26091 proglen += ilen;
26092 addrs[i] = proglen;
26093@@ -624,11 +634,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26094 break;
26095 }
26096 if (proglen == oldproglen) {
26097- image = module_alloc(max_t(unsigned int,
26098- proglen,
26099- sizeof(struct work_struct)));
26100+ image = module_alloc_exec(proglen);
26101 if (!image)
26102- goto out;
26103+ goto error;
26104 }
26105 oldproglen = proglen;
26106 }
26107@@ -644,7 +652,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26108 bpf_flush_icache(image, image + proglen);
26109
26110 fp->bpf_func = (void *)image;
26111- }
26112+ } else
26113+error:
26114+ kfree(fp->work);
26115+
26116 out:
26117 kfree(addrs);
26118 return;
26119@@ -652,18 +663,20 @@ out:
26120
26121 static void jit_free_defer(struct work_struct *arg)
26122 {
26123- module_free(NULL, arg);
26124+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26125+ kfree(arg);
26126 }
26127
26128 /* run from softirq, we must use a work_struct to call
26129- * module_free() from process context
26130+ * module_free_exec() from process context
26131 */
26132 void bpf_jit_free(struct sk_filter *fp)
26133 {
26134 if (fp->bpf_func != sk_run_filter) {
26135- struct work_struct *work = (struct work_struct *)fp->bpf_func;
26136+ struct work_struct *work = &fp->work->work;
26137
26138 INIT_WORK(work, jit_free_defer);
26139+ fp->work->image = fp->bpf_func;
26140 schedule_work(work);
26141 }
26142 }
26143diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26144index d6aa6e8..266395a 100644
26145--- a/arch/x86/oprofile/backtrace.c
26146+++ b/arch/x86/oprofile/backtrace.c
26147@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26148 struct stack_frame_ia32 *fp;
26149 unsigned long bytes;
26150
26151- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26152+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26153 if (bytes != sizeof(bufhead))
26154 return NULL;
26155
26156- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26157+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26158
26159 oprofile_add_trace(bufhead[0].return_address);
26160
26161@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26162 struct stack_frame bufhead[2];
26163 unsigned long bytes;
26164
26165- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26166+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26167 if (bytes != sizeof(bufhead))
26168 return NULL;
26169
26170@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26171 {
26172 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26173
26174- if (!user_mode_vm(regs)) {
26175+ if (!user_mode(regs)) {
26176 unsigned long stack = kernel_stack_pointer(regs);
26177 if (depth)
26178 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26179diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26180index e14a2ff..3fd6b58 100644
26181--- a/arch/x86/pci/mrst.c
26182+++ b/arch/x86/pci/mrst.c
26183@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26184 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26185 pci_mmcfg_late_init();
26186 pcibios_enable_irq = mrst_pci_irq_enable;
26187- pci_root_ops = pci_mrst_ops;
26188+ pax_open_kernel();
26189+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26190+ pax_close_kernel();
26191 pci_soc_mode = 1;
26192 /* Continue with standard init */
26193 return 1;
26194diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26195index da8fe05..7ee6704 100644
26196--- a/arch/x86/pci/pcbios.c
26197+++ b/arch/x86/pci/pcbios.c
26198@@ -79,50 +79,93 @@ union bios32 {
26199 static struct {
26200 unsigned long address;
26201 unsigned short segment;
26202-} bios32_indirect = { 0, __KERNEL_CS };
26203+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26204
26205 /*
26206 * Returns the entry point for the given service, NULL on error
26207 */
26208
26209-static unsigned long bios32_service(unsigned long service)
26210+static unsigned long __devinit bios32_service(unsigned long service)
26211 {
26212 unsigned char return_code; /* %al */
26213 unsigned long address; /* %ebx */
26214 unsigned long length; /* %ecx */
26215 unsigned long entry; /* %edx */
26216 unsigned long flags;
26217+ struct desc_struct d, *gdt;
26218
26219 local_irq_save(flags);
26220- __asm__("lcall *(%%edi); cld"
26221+
26222+ gdt = get_cpu_gdt_table(smp_processor_id());
26223+
26224+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26225+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26226+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26227+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26228+
26229+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26230 : "=a" (return_code),
26231 "=b" (address),
26232 "=c" (length),
26233 "=d" (entry)
26234 : "0" (service),
26235 "1" (0),
26236- "D" (&bios32_indirect));
26237+ "D" (&bios32_indirect),
26238+ "r"(__PCIBIOS_DS)
26239+ : "memory");
26240+
26241+ pax_open_kernel();
26242+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26243+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26244+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26245+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26246+ pax_close_kernel();
26247+
26248 local_irq_restore(flags);
26249
26250 switch (return_code) {
26251- case 0:
26252- return address + entry;
26253- case 0x80: /* Not present */
26254- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26255- return 0;
26256- default: /* Shouldn't happen */
26257- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26258- service, return_code);
26259+ case 0: {
26260+ int cpu;
26261+ unsigned char flags;
26262+
26263+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26264+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26265+ printk(KERN_WARNING "bios32_service: not valid\n");
26266 return 0;
26267+ }
26268+ address = address + PAGE_OFFSET;
26269+ length += 16UL; /* some BIOSs underreport this... */
26270+ flags = 4;
26271+ if (length >= 64*1024*1024) {
26272+ length >>= PAGE_SHIFT;
26273+ flags |= 8;
26274+ }
26275+
26276+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26277+ gdt = get_cpu_gdt_table(cpu);
26278+ pack_descriptor(&d, address, length, 0x9b, flags);
26279+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26280+ pack_descriptor(&d, address, length, 0x93, flags);
26281+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26282+ }
26283+ return entry;
26284+ }
26285+ case 0x80: /* Not present */
26286+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26287+ return 0;
26288+ default: /* Shouldn't happen */
26289+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26290+ service, return_code);
26291+ return 0;
26292 }
26293 }
26294
26295 static struct {
26296 unsigned long address;
26297 unsigned short segment;
26298-} pci_indirect = { 0, __KERNEL_CS };
26299+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26300
26301-static int pci_bios_present;
26302+static int pci_bios_present __read_only;
26303
26304 static int __devinit check_pcibios(void)
26305 {
26306@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26307 unsigned long flags, pcibios_entry;
26308
26309 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26310- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26311+ pci_indirect.address = pcibios_entry;
26312
26313 local_irq_save(flags);
26314- __asm__(
26315- "lcall *(%%edi); cld\n\t"
26316+ __asm__("movw %w6, %%ds\n\t"
26317+ "lcall *%%ss:(%%edi); cld\n\t"
26318+ "push %%ss\n\t"
26319+ "pop %%ds\n\t"
26320 "jc 1f\n\t"
26321 "xor %%ah, %%ah\n"
26322 "1:"
26323@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26324 "=b" (ebx),
26325 "=c" (ecx)
26326 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26327- "D" (&pci_indirect)
26328+ "D" (&pci_indirect),
26329+ "r" (__PCIBIOS_DS)
26330 : "memory");
26331 local_irq_restore(flags);
26332
26333@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26334
26335 switch (len) {
26336 case 1:
26337- __asm__("lcall *(%%esi); cld\n\t"
26338+ __asm__("movw %w6, %%ds\n\t"
26339+ "lcall *%%ss:(%%esi); cld\n\t"
26340+ "push %%ss\n\t"
26341+ "pop %%ds\n\t"
26342 "jc 1f\n\t"
26343 "xor %%ah, %%ah\n"
26344 "1:"
26345@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26346 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26347 "b" (bx),
26348 "D" ((long)reg),
26349- "S" (&pci_indirect));
26350+ "S" (&pci_indirect),
26351+ "r" (__PCIBIOS_DS));
26352 /*
26353 * Zero-extend the result beyond 8 bits, do not trust the
26354 * BIOS having done it:
26355@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26356 *value &= 0xff;
26357 break;
26358 case 2:
26359- __asm__("lcall *(%%esi); cld\n\t"
26360+ __asm__("movw %w6, %%ds\n\t"
26361+ "lcall *%%ss:(%%esi); cld\n\t"
26362+ "push %%ss\n\t"
26363+ "pop %%ds\n\t"
26364 "jc 1f\n\t"
26365 "xor %%ah, %%ah\n"
26366 "1:"
26367@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26368 : "1" (PCIBIOS_READ_CONFIG_WORD),
26369 "b" (bx),
26370 "D" ((long)reg),
26371- "S" (&pci_indirect));
26372+ "S" (&pci_indirect),
26373+ "r" (__PCIBIOS_DS));
26374 /*
26375 * Zero-extend the result beyond 16 bits, do not trust the
26376 * BIOS having done it:
26377@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26378 *value &= 0xffff;
26379 break;
26380 case 4:
26381- __asm__("lcall *(%%esi); cld\n\t"
26382+ __asm__("movw %w6, %%ds\n\t"
26383+ "lcall *%%ss:(%%esi); cld\n\t"
26384+ "push %%ss\n\t"
26385+ "pop %%ds\n\t"
26386 "jc 1f\n\t"
26387 "xor %%ah, %%ah\n"
26388 "1:"
26389@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26390 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26391 "b" (bx),
26392 "D" ((long)reg),
26393- "S" (&pci_indirect));
26394+ "S" (&pci_indirect),
26395+ "r" (__PCIBIOS_DS));
26396 break;
26397 }
26398
26399@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26400
26401 switch (len) {
26402 case 1:
26403- __asm__("lcall *(%%esi); cld\n\t"
26404+ __asm__("movw %w6, %%ds\n\t"
26405+ "lcall *%%ss:(%%esi); cld\n\t"
26406+ "push %%ss\n\t"
26407+ "pop %%ds\n\t"
26408 "jc 1f\n\t"
26409 "xor %%ah, %%ah\n"
26410 "1:"
26411@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26412 "c" (value),
26413 "b" (bx),
26414 "D" ((long)reg),
26415- "S" (&pci_indirect));
26416+ "S" (&pci_indirect),
26417+ "r" (__PCIBIOS_DS));
26418 break;
26419 case 2:
26420- __asm__("lcall *(%%esi); cld\n\t"
26421+ __asm__("movw %w6, %%ds\n\t"
26422+ "lcall *%%ss:(%%esi); cld\n\t"
26423+ "push %%ss\n\t"
26424+ "pop %%ds\n\t"
26425 "jc 1f\n\t"
26426 "xor %%ah, %%ah\n"
26427 "1:"
26428@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26429 "c" (value),
26430 "b" (bx),
26431 "D" ((long)reg),
26432- "S" (&pci_indirect));
26433+ "S" (&pci_indirect),
26434+ "r" (__PCIBIOS_DS));
26435 break;
26436 case 4:
26437- __asm__("lcall *(%%esi); cld\n\t"
26438+ __asm__("movw %w6, %%ds\n\t"
26439+ "lcall *%%ss:(%%esi); cld\n\t"
26440+ "push %%ss\n\t"
26441+ "pop %%ds\n\t"
26442 "jc 1f\n\t"
26443 "xor %%ah, %%ah\n"
26444 "1:"
26445@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26446 "c" (value),
26447 "b" (bx),
26448 "D" ((long)reg),
26449- "S" (&pci_indirect));
26450+ "S" (&pci_indirect),
26451+ "r" (__PCIBIOS_DS));
26452 break;
26453 }
26454
26455@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26456
26457 DBG("PCI: Fetching IRQ routing table... ");
26458 __asm__("push %%es\n\t"
26459+ "movw %w8, %%ds\n\t"
26460 "push %%ds\n\t"
26461 "pop %%es\n\t"
26462- "lcall *(%%esi); cld\n\t"
26463+ "lcall *%%ss:(%%esi); cld\n\t"
26464 "pop %%es\n\t"
26465+ "push %%ss\n\t"
26466+ "pop %%ds\n"
26467 "jc 1f\n\t"
26468 "xor %%ah, %%ah\n"
26469 "1:"
26470@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26471 "1" (0),
26472 "D" ((long) &opt),
26473 "S" (&pci_indirect),
26474- "m" (opt)
26475+ "m" (opt),
26476+ "r" (__PCIBIOS_DS)
26477 : "memory");
26478 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26479 if (ret & 0xff00)
26480@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26481 {
26482 int ret;
26483
26484- __asm__("lcall *(%%esi); cld\n\t"
26485+ __asm__("movw %w5, %%ds\n\t"
26486+ "lcall *%%ss:(%%esi); cld\n\t"
26487+ "push %%ss\n\t"
26488+ "pop %%ds\n"
26489 "jc 1f\n\t"
26490 "xor %%ah, %%ah\n"
26491 "1:"
26492@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26493 : "0" (PCIBIOS_SET_PCI_HW_INT),
26494 "b" ((dev->bus->number << 8) | dev->devfn),
26495 "c" ((irq << 8) | (pin + 10)),
26496- "S" (&pci_indirect));
26497+ "S" (&pci_indirect),
26498+ "r" (__PCIBIOS_DS));
26499 return !(ret & 0xff00);
26500 }
26501 EXPORT_SYMBOL(pcibios_set_irq_routing);
26502diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26503index 40e4469..1ab536e 100644
26504--- a/arch/x86/platform/efi/efi_32.c
26505+++ b/arch/x86/platform/efi/efi_32.c
26506@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26507 {
26508 struct desc_ptr gdt_descr;
26509
26510+#ifdef CONFIG_PAX_KERNEXEC
26511+ struct desc_struct d;
26512+#endif
26513+
26514 local_irq_save(efi_rt_eflags);
26515
26516 load_cr3(initial_page_table);
26517 __flush_tlb_all();
26518
26519+#ifdef CONFIG_PAX_KERNEXEC
26520+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26521+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26522+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26523+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26524+#endif
26525+
26526 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26527 gdt_descr.size = GDT_SIZE - 1;
26528 load_gdt(&gdt_descr);
26529@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26530 {
26531 struct desc_ptr gdt_descr;
26532
26533+#ifdef CONFIG_PAX_KERNEXEC
26534+ struct desc_struct d;
26535+
26536+ memset(&d, 0, sizeof d);
26537+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26538+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26539+#endif
26540+
26541 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26542 gdt_descr.size = GDT_SIZE - 1;
26543 load_gdt(&gdt_descr);
26544diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26545index fbe66e6..eae5e38 100644
26546--- a/arch/x86/platform/efi/efi_stub_32.S
26547+++ b/arch/x86/platform/efi/efi_stub_32.S
26548@@ -6,7 +6,9 @@
26549 */
26550
26551 #include <linux/linkage.h>
26552+#include <linux/init.h>
26553 #include <asm/page_types.h>
26554+#include <asm/segment.h>
26555
26556 /*
26557 * efi_call_phys(void *, ...) is a function with variable parameters.
26558@@ -20,7 +22,7 @@
26559 * service functions will comply with gcc calling convention, too.
26560 */
26561
26562-.text
26563+__INIT
26564 ENTRY(efi_call_phys)
26565 /*
26566 * 0. The function can only be called in Linux kernel. So CS has been
26567@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26568 * The mapping of lower virtual memory has been created in prelog and
26569 * epilog.
26570 */
26571- movl $1f, %edx
26572- subl $__PAGE_OFFSET, %edx
26573- jmp *%edx
26574+#ifdef CONFIG_PAX_KERNEXEC
26575+ movl $(__KERNEXEC_EFI_DS), %edx
26576+ mov %edx, %ds
26577+ mov %edx, %es
26578+ mov %edx, %ss
26579+ addl $2f,(1f)
26580+ ljmp *(1f)
26581+
26582+__INITDATA
26583+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26584+.previous
26585+
26586+2:
26587+ subl $2b,(1b)
26588+#else
26589+ jmp 1f-__PAGE_OFFSET
26590 1:
26591+#endif
26592
26593 /*
26594 * 2. Now on the top of stack is the return
26595@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26596 * parameter 2, ..., param n. To make things easy, we save the return
26597 * address of efi_call_phys in a global variable.
26598 */
26599- popl %edx
26600- movl %edx, saved_return_addr
26601- /* get the function pointer into ECX*/
26602- popl %ecx
26603- movl %ecx, efi_rt_function_ptr
26604- movl $2f, %edx
26605- subl $__PAGE_OFFSET, %edx
26606- pushl %edx
26607+ popl (saved_return_addr)
26608+ popl (efi_rt_function_ptr)
26609
26610 /*
26611 * 3. Clear PG bit in %CR0.
26612@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26613 /*
26614 * 5. Call the physical function.
26615 */
26616- jmp *%ecx
26617+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26618
26619-2:
26620 /*
26621 * 6. After EFI runtime service returns, control will return to
26622 * following instruction. We'd better readjust stack pointer first.
26623@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26624 movl %cr0, %edx
26625 orl $0x80000000, %edx
26626 movl %edx, %cr0
26627- jmp 1f
26628-1:
26629+
26630 /*
26631 * 8. Now restore the virtual mode from flat mode by
26632 * adding EIP with PAGE_OFFSET.
26633 */
26634- movl $1f, %edx
26635- jmp *%edx
26636+#ifdef CONFIG_PAX_KERNEXEC
26637+ movl $(__KERNEL_DS), %edx
26638+ mov %edx, %ds
26639+ mov %edx, %es
26640+ mov %edx, %ss
26641+ ljmp $(__KERNEL_CS),$1f
26642+#else
26643+ jmp 1f+__PAGE_OFFSET
26644+#endif
26645 1:
26646
26647 /*
26648 * 9. Balance the stack. And because EAX contain the return value,
26649 * we'd better not clobber it.
26650 */
26651- leal efi_rt_function_ptr, %edx
26652- movl (%edx), %ecx
26653- pushl %ecx
26654+ pushl (efi_rt_function_ptr)
26655
26656 /*
26657- * 10. Push the saved return address onto the stack and return.
26658+ * 10. Return to the saved return address.
26659 */
26660- leal saved_return_addr, %edx
26661- movl (%edx), %ecx
26662- pushl %ecx
26663- ret
26664+ jmpl *(saved_return_addr)
26665 ENDPROC(efi_call_phys)
26666 .previous
26667
26668-.data
26669+__INITDATA
26670 saved_return_addr:
26671 .long 0
26672 efi_rt_function_ptr:
26673diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26674index 4c07cca..2c8427d 100644
26675--- a/arch/x86/platform/efi/efi_stub_64.S
26676+++ b/arch/x86/platform/efi/efi_stub_64.S
26677@@ -7,6 +7,7 @@
26678 */
26679
26680 #include <linux/linkage.h>
26681+#include <asm/alternative-asm.h>
26682
26683 #define SAVE_XMM \
26684 mov %rsp, %rax; \
26685@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26686 call *%rdi
26687 addq $32, %rsp
26688 RESTORE_XMM
26689+ pax_force_retaddr 0, 1
26690 ret
26691 ENDPROC(efi_call0)
26692
26693@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26694 call *%rdi
26695 addq $32, %rsp
26696 RESTORE_XMM
26697+ pax_force_retaddr 0, 1
26698 ret
26699 ENDPROC(efi_call1)
26700
26701@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26702 call *%rdi
26703 addq $32, %rsp
26704 RESTORE_XMM
26705+ pax_force_retaddr 0, 1
26706 ret
26707 ENDPROC(efi_call2)
26708
26709@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26710 call *%rdi
26711 addq $32, %rsp
26712 RESTORE_XMM
26713+ pax_force_retaddr 0, 1
26714 ret
26715 ENDPROC(efi_call3)
26716
26717@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26718 call *%rdi
26719 addq $32, %rsp
26720 RESTORE_XMM
26721+ pax_force_retaddr 0, 1
26722 ret
26723 ENDPROC(efi_call4)
26724
26725@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26726 call *%rdi
26727 addq $48, %rsp
26728 RESTORE_XMM
26729+ pax_force_retaddr 0, 1
26730 ret
26731 ENDPROC(efi_call5)
26732
26733@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26734 call *%rdi
26735 addq $48, %rsp
26736 RESTORE_XMM
26737+ pax_force_retaddr 0, 1
26738 ret
26739 ENDPROC(efi_call6)
26740diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26741index fd41a92..9c33628 100644
26742--- a/arch/x86/platform/mrst/mrst.c
26743+++ b/arch/x86/platform/mrst/mrst.c
26744@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26745 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26746 int sfi_mrtc_num;
26747
26748-static void mrst_power_off(void)
26749+static __noreturn void mrst_power_off(void)
26750 {
26751+ BUG();
26752 }
26753
26754-static void mrst_reboot(void)
26755+static __noreturn void mrst_reboot(void)
26756 {
26757 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26758+ BUG();
26759 }
26760
26761 /* parse all the mtimer info to a static mtimer array */
26762diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26763index 218cdb1..fd55c08 100644
26764--- a/arch/x86/power/cpu.c
26765+++ b/arch/x86/power/cpu.c
26766@@ -132,7 +132,7 @@ static void do_fpu_end(void)
26767 static void fix_processor_context(void)
26768 {
26769 int cpu = smp_processor_id();
26770- struct tss_struct *t = &per_cpu(init_tss, cpu);
26771+ struct tss_struct *t = init_tss + cpu;
26772
26773 set_tss_desc(cpu, t); /*
26774 * This just modifies memory; should not be
26775@@ -142,7 +142,9 @@ static void fix_processor_context(void)
26776 */
26777
26778 #ifdef CONFIG_X86_64
26779+ pax_open_kernel();
26780 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26781+ pax_close_kernel();
26782
26783 syscall_init(); /* This sets MSR_*STAR and related */
26784 #endif
26785diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26786index cbca565..bae7133 100644
26787--- a/arch/x86/realmode/init.c
26788+++ b/arch/x86/realmode/init.c
26789@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26790 __va(real_mode_header->trampoline_header);
26791
26792 #ifdef CONFIG_X86_32
26793- trampoline_header->start = __pa(startup_32_smp);
26794+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26795+
26796+#ifdef CONFIG_PAX_KERNEXEC
26797+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26798+#endif
26799+
26800+ trampoline_header->boot_cs = __BOOT_CS;
26801 trampoline_header->gdt_limit = __BOOT_DS + 7;
26802 trampoline_header->gdt_base = __pa(boot_gdt);
26803 #else
26804diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26805index 8869287..d577672 100644
26806--- a/arch/x86/realmode/rm/Makefile
26807+++ b/arch/x86/realmode/rm/Makefile
26808@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26809 $(call cc-option, -fno-unit-at-a-time)) \
26810 $(call cc-option, -fno-stack-protector) \
26811 $(call cc-option, -mpreferred-stack-boundary=2)
26812+ifdef CONSTIFY_PLUGIN
26813+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
26814+endif
26815 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26816 GCOV_PROFILE := n
26817diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
26818index a28221d..93c40f1 100644
26819--- a/arch/x86/realmode/rm/header.S
26820+++ b/arch/x86/realmode/rm/header.S
26821@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
26822 #endif
26823 /* APM/BIOS reboot */
26824 .long pa_machine_real_restart_asm
26825-#ifdef CONFIG_X86_64
26826+#ifdef CONFIG_X86_32
26827+ .long __KERNEL_CS
26828+#else
26829 .long __KERNEL32_CS
26830 #endif
26831 END(real_mode_header)
26832diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26833index c1b2791..f9e31c7 100644
26834--- a/arch/x86/realmode/rm/trampoline_32.S
26835+++ b/arch/x86/realmode/rm/trampoline_32.S
26836@@ -25,6 +25,12 @@
26837 #include <asm/page_types.h>
26838 #include "realmode.h"
26839
26840+#ifdef CONFIG_PAX_KERNEXEC
26841+#define ta(X) (X)
26842+#else
26843+#define ta(X) (pa_ ## X)
26844+#endif
26845+
26846 .text
26847 .code16
26848
26849@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26850
26851 cli # We should be safe anyway
26852
26853- movl tr_start, %eax # where we need to go
26854-
26855 movl $0xA5A5A5A5, trampoline_status
26856 # write marker for master knows we're running
26857
26858@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26859 movw $1, %dx # protected mode (PE) bit
26860 lmsw %dx # into protected mode
26861
26862- ljmpl $__BOOT_CS, $pa_startup_32
26863+ ljmpl *(trampoline_header)
26864
26865 .section ".text32","ax"
26866 .code32
26867@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26868 .balign 8
26869 GLOBAL(trampoline_header)
26870 tr_start: .space 4
26871- tr_gdt_pad: .space 2
26872+ tr_boot_cs: .space 2
26873 tr_gdt: .space 6
26874 END(trampoline_header)
26875
26876diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26877index bb360dc..3e5945f 100644
26878--- a/arch/x86/realmode/rm/trampoline_64.S
26879+++ b/arch/x86/realmode/rm/trampoline_64.S
26880@@ -107,7 +107,7 @@ ENTRY(startup_32)
26881 wrmsr
26882
26883 # Enable paging and in turn activate Long Mode
26884- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26885+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
26886 movl %eax, %cr0
26887
26888 /*
26889diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26890index 5a1847d..deccb30 100644
26891--- a/arch/x86/tools/relocs.c
26892+++ b/arch/x86/tools/relocs.c
26893@@ -12,10 +12,13 @@
26894 #include <regex.h>
26895 #include <tools/le_byteshift.h>
26896
26897+#include "../../../include/generated/autoconf.h"
26898+
26899 static void die(char *fmt, ...);
26900
26901 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26902 static Elf32_Ehdr ehdr;
26903+static Elf32_Phdr *phdr;
26904 static unsigned long reloc_count, reloc_idx;
26905 static unsigned long *relocs;
26906 static unsigned long reloc16_count, reloc16_idx;
26907@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26908 }
26909 }
26910
26911+static void read_phdrs(FILE *fp)
26912+{
26913+ unsigned int i;
26914+
26915+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26916+ if (!phdr) {
26917+ die("Unable to allocate %d program headers\n",
26918+ ehdr.e_phnum);
26919+ }
26920+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26921+ die("Seek to %d failed: %s\n",
26922+ ehdr.e_phoff, strerror(errno));
26923+ }
26924+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26925+ die("Cannot read ELF program headers: %s\n",
26926+ strerror(errno));
26927+ }
26928+ for(i = 0; i < ehdr.e_phnum; i++) {
26929+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26930+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26931+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26932+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26933+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26934+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26935+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26936+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26937+ }
26938+
26939+}
26940+
26941 static void read_shdrs(FILE *fp)
26942 {
26943- int i;
26944+ unsigned int i;
26945 Elf32_Shdr shdr;
26946
26947 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26948@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26949
26950 static void read_strtabs(FILE *fp)
26951 {
26952- int i;
26953+ unsigned int i;
26954 for (i = 0; i < ehdr.e_shnum; i++) {
26955 struct section *sec = &secs[i];
26956 if (sec->shdr.sh_type != SHT_STRTAB) {
26957@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26958
26959 static void read_symtabs(FILE *fp)
26960 {
26961- int i,j;
26962+ unsigned int i,j;
26963 for (i = 0; i < ehdr.e_shnum; i++) {
26964 struct section *sec = &secs[i];
26965 if (sec->shdr.sh_type != SHT_SYMTAB) {
26966@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26967 }
26968
26969
26970-static void read_relocs(FILE *fp)
26971+static void read_relocs(FILE *fp, int use_real_mode)
26972 {
26973- int i,j;
26974+ unsigned int i,j;
26975+ uint32_t base;
26976+
26977 for (i = 0; i < ehdr.e_shnum; i++) {
26978 struct section *sec = &secs[i];
26979 if (sec->shdr.sh_type != SHT_REL) {
26980@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26981 die("Cannot read symbol table: %s\n",
26982 strerror(errno));
26983 }
26984+ base = 0;
26985+
26986+#ifdef CONFIG_X86_32
26987+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26988+ if (phdr[j].p_type != PT_LOAD )
26989+ continue;
26990+ 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)
26991+ continue;
26992+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26993+ break;
26994+ }
26995+#endif
26996+
26997 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26998 Elf32_Rel *rel = &sec->reltab[j];
26999- rel->r_offset = elf32_to_cpu(rel->r_offset);
27000+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27001 rel->r_info = elf32_to_cpu(rel->r_info);
27002 }
27003 }
27004@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27005
27006 static void print_absolute_symbols(void)
27007 {
27008- int i;
27009+ unsigned int i;
27010 printf("Absolute symbols\n");
27011 printf(" Num: Value Size Type Bind Visibility Name\n");
27012 for (i = 0; i < ehdr.e_shnum; i++) {
27013 struct section *sec = &secs[i];
27014 char *sym_strtab;
27015- int j;
27016+ unsigned int j;
27017
27018 if (sec->shdr.sh_type != SHT_SYMTAB) {
27019 continue;
27020@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27021
27022 static void print_absolute_relocs(void)
27023 {
27024- int i, printed = 0;
27025+ unsigned int i, printed = 0;
27026
27027 for (i = 0; i < ehdr.e_shnum; i++) {
27028 struct section *sec = &secs[i];
27029 struct section *sec_applies, *sec_symtab;
27030 char *sym_strtab;
27031 Elf32_Sym *sh_symtab;
27032- int j;
27033+ unsigned int j;
27034 if (sec->shdr.sh_type != SHT_REL) {
27035 continue;
27036 }
27037@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27038 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27039 int use_real_mode)
27040 {
27041- int i;
27042+ unsigned int i;
27043 /* Walk through the relocations */
27044 for (i = 0; i < ehdr.e_shnum; i++) {
27045 char *sym_strtab;
27046 Elf32_Sym *sh_symtab;
27047 struct section *sec_applies, *sec_symtab;
27048- int j;
27049+ unsigned int j;
27050 struct section *sec = &secs[i];
27051
27052 if (sec->shdr.sh_type != SHT_REL) {
27053@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27054 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27055 r_type = ELF32_R_TYPE(rel->r_info);
27056
27057+ if (!use_real_mode) {
27058+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27059+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27060+ continue;
27061+
27062+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27063+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27064+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27065+ continue;
27066+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27067+ continue;
27068+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27069+ continue;
27070+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27071+ continue;
27072+#endif
27073+ }
27074+
27075 shn_abs = sym->st_shndx == SHN_ABS;
27076
27077 switch (r_type) {
27078@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27079
27080 static void emit_relocs(int as_text, int use_real_mode)
27081 {
27082- int i;
27083+ unsigned int i;
27084 /* Count how many relocations I have and allocate space for them. */
27085 reloc_count = 0;
27086 walk_relocs(count_reloc, use_real_mode);
27087@@ -808,10 +874,11 @@ int main(int argc, char **argv)
27088 fname, strerror(errno));
27089 }
27090 read_ehdr(fp);
27091+ read_phdrs(fp);
27092 read_shdrs(fp);
27093 read_strtabs(fp);
27094 read_symtabs(fp);
27095- read_relocs(fp);
27096+ read_relocs(fp, use_real_mode);
27097 if (show_absolute_syms) {
27098 print_absolute_symbols();
27099 return 0;
27100diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27101index fd14be1..e3c79c0 100644
27102--- a/arch/x86/vdso/Makefile
27103+++ b/arch/x86/vdso/Makefile
27104@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27105 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27106 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27107
27108-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27109+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27110 GCOV_PROFILE := n
27111
27112 #
27113diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27114index 0faad64..39ef157 100644
27115--- a/arch/x86/vdso/vdso32-setup.c
27116+++ b/arch/x86/vdso/vdso32-setup.c
27117@@ -25,6 +25,7 @@
27118 #include <asm/tlbflush.h>
27119 #include <asm/vdso.h>
27120 #include <asm/proto.h>
27121+#include <asm/mman.h>
27122
27123 enum {
27124 VDSO_DISABLED = 0,
27125@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27126 void enable_sep_cpu(void)
27127 {
27128 int cpu = get_cpu();
27129- struct tss_struct *tss = &per_cpu(init_tss, cpu);
27130+ struct tss_struct *tss = init_tss + cpu;
27131
27132 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27133 put_cpu();
27134@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27135 gate_vma.vm_start = FIXADDR_USER_START;
27136 gate_vma.vm_end = FIXADDR_USER_END;
27137 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27138- gate_vma.vm_page_prot = __P101;
27139+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27140
27141 return 0;
27142 }
27143@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27144 if (compat)
27145 addr = VDSO_HIGH_BASE;
27146 else {
27147- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27148+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27149 if (IS_ERR_VALUE(addr)) {
27150 ret = addr;
27151 goto up_fail;
27152 }
27153 }
27154
27155- current->mm->context.vdso = (void *)addr;
27156+ current->mm->context.vdso = addr;
27157
27158 if (compat_uses_vma || !compat) {
27159 /*
27160@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27161 }
27162
27163 current_thread_info()->sysenter_return =
27164- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27165+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27166
27167 up_fail:
27168 if (ret)
27169- current->mm->context.vdso = NULL;
27170+ current->mm->context.vdso = 0;
27171
27172 up_write(&mm->mmap_sem);
27173
27174@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27175
27176 const char *arch_vma_name(struct vm_area_struct *vma)
27177 {
27178- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27179+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27180 return "[vdso]";
27181+
27182+#ifdef CONFIG_PAX_SEGMEXEC
27183+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27184+ return "[vdso]";
27185+#endif
27186+
27187 return NULL;
27188 }
27189
27190@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27191 * Check to see if the corresponding task was created in compat vdso
27192 * mode.
27193 */
27194- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27195+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27196 return &gate_vma;
27197 return NULL;
27198 }
27199diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27200index 00aaf04..4a26505 100644
27201--- a/arch/x86/vdso/vma.c
27202+++ b/arch/x86/vdso/vma.c
27203@@ -16,8 +16,6 @@
27204 #include <asm/vdso.h>
27205 #include <asm/page.h>
27206
27207-unsigned int __read_mostly vdso_enabled = 1;
27208-
27209 extern char vdso_start[], vdso_end[];
27210 extern unsigned short vdso_sync_cpuid;
27211
27212@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27213 * unaligned here as a result of stack start randomization.
27214 */
27215 addr = PAGE_ALIGN(addr);
27216- addr = align_addr(addr, NULL, ALIGN_VDSO);
27217
27218 return addr;
27219 }
27220@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27221 unsigned size)
27222 {
27223 struct mm_struct *mm = current->mm;
27224- unsigned long addr;
27225+ unsigned long addr = 0;
27226 int ret;
27227
27228- if (!vdso_enabled)
27229- return 0;
27230-
27231 down_write(&mm->mmap_sem);
27232+
27233+#ifdef CONFIG_PAX_RANDMMAP
27234+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27235+#endif
27236+
27237 addr = vdso_addr(mm->start_stack, size);
27238+ addr = align_addr(addr, NULL, ALIGN_VDSO);
27239 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27240 if (IS_ERR_VALUE(addr)) {
27241 ret = addr;
27242 goto up_fail;
27243 }
27244
27245- current->mm->context.vdso = (void *)addr;
27246+ mm->context.vdso = addr;
27247
27248 ret = install_special_mapping(mm, addr, size,
27249 VM_READ|VM_EXEC|
27250 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27251 pages);
27252- if (ret) {
27253- current->mm->context.vdso = NULL;
27254- goto up_fail;
27255- }
27256+ if (ret)
27257+ mm->context.vdso = 0;
27258
27259 up_fail:
27260 up_write(&mm->mmap_sem);
27261@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27262 vdsox32_size);
27263 }
27264 #endif
27265-
27266-static __init int vdso_setup(char *s)
27267-{
27268- vdso_enabled = simple_strtoul(s, NULL, 0);
27269- return 0;
27270-}
27271-__setup("vdso=", vdso_setup);
27272diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27273index 1fbe75a..c22e01f 100644
27274--- a/arch/x86/xen/enlighten.c
27275+++ b/arch/x86/xen/enlighten.c
27276@@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27277
27278 struct shared_info xen_dummy_shared_info;
27279
27280-void *xen_initial_gdt;
27281-
27282 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27283 __read_mostly int xen_have_vector_callback;
27284 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27285@@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27286
27287 static void set_xen_basic_apic_ops(void)
27288 {
27289- apic->read = xen_apic_read;
27290- apic->write = xen_apic_write;
27291- apic->icr_read = xen_apic_icr_read;
27292- apic->icr_write = xen_apic_icr_write;
27293- apic->wait_icr_idle = xen_apic_wait_icr_idle;
27294- apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27295- apic->set_apic_id = xen_set_apic_id;
27296- apic->get_apic_id = xen_get_apic_id;
27297+ *(void **)&apic->read = xen_apic_read;
27298+ *(void **)&apic->write = xen_apic_write;
27299+ *(void **)&apic->icr_read = xen_apic_icr_read;
27300+ *(void **)&apic->icr_write = xen_apic_icr_write;
27301+ *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27302+ *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27303+ *(void **)&apic->set_apic_id = xen_set_apic_id;
27304+ *(void **)&apic->get_apic_id = xen_get_apic_id;
27305
27306 #ifdef CONFIG_SMP
27307- apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27308- apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27309- apic->send_IPI_mask = xen_send_IPI_mask;
27310- apic->send_IPI_all = xen_send_IPI_all;
27311- apic->send_IPI_self = xen_send_IPI_self;
27312+ *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27313+ *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27314+ *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27315+ *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27316+ *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27317 #endif
27318 }
27319
27320@@ -1205,30 +1203,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27321 #endif
27322 };
27323
27324-static void xen_reboot(int reason)
27325+static __noreturn void xen_reboot(int reason)
27326 {
27327 struct sched_shutdown r = { .reason = reason };
27328
27329- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27330- BUG();
27331+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27332+ BUG();
27333 }
27334
27335-static void xen_restart(char *msg)
27336+static __noreturn void xen_restart(char *msg)
27337 {
27338 xen_reboot(SHUTDOWN_reboot);
27339 }
27340
27341-static void xen_emergency_restart(void)
27342+static __noreturn void xen_emergency_restart(void)
27343 {
27344 xen_reboot(SHUTDOWN_reboot);
27345 }
27346
27347-static void xen_machine_halt(void)
27348+static __noreturn void xen_machine_halt(void)
27349 {
27350 xen_reboot(SHUTDOWN_poweroff);
27351 }
27352
27353-static void xen_machine_power_off(void)
27354+static __noreturn void xen_machine_power_off(void)
27355 {
27356 if (pm_power_off)
27357 pm_power_off();
27358@@ -1331,7 +1329,17 @@ asmlinkage void __init xen_start_kernel(void)
27359 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27360
27361 /* Work out if we support NX */
27362- x86_configure_nx();
27363+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27364+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27365+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27366+ unsigned l, h;
27367+
27368+ __supported_pte_mask |= _PAGE_NX;
27369+ rdmsr(MSR_EFER, l, h);
27370+ l |= EFER_NX;
27371+ wrmsr(MSR_EFER, l, h);
27372+ }
27373+#endif
27374
27375 xen_setup_features();
27376
27377@@ -1362,13 +1370,6 @@ asmlinkage void __init xen_start_kernel(void)
27378
27379 machine_ops = xen_machine_ops;
27380
27381- /*
27382- * The only reliable way to retain the initial address of the
27383- * percpu gdt_page is to remember it here, so we can go and
27384- * mark it RW later, when the initial percpu area is freed.
27385- */
27386- xen_initial_gdt = &per_cpu(gdt_page, 0);
27387-
27388 xen_smp_init();
27389
27390 #ifdef CONFIG_ACPI_NUMA
27391diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27392index 5141d80..6c9fb41 100644
27393--- a/arch/x86/xen/mmu.c
27394+++ b/arch/x86/xen/mmu.c
27395@@ -1765,6 +1765,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27396 convert_pfn_mfn(init_level4_pgt);
27397 convert_pfn_mfn(level3_ident_pgt);
27398 convert_pfn_mfn(level3_kernel_pgt);
27399+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27400+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27401+ convert_pfn_mfn(level3_vmemmap_pgt);
27402
27403 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27404 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27405@@ -1783,7 +1786,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27406 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27407 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27408 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27409+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27410+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27411+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27412 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27413+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27414 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27415 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27416
27417@@ -1967,6 +1974,7 @@ static void __init xen_post_allocator_init(void)
27418 pv_mmu_ops.set_pud = xen_set_pud;
27419 #if PAGETABLE_LEVELS == 4
27420 pv_mmu_ops.set_pgd = xen_set_pgd;
27421+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27422 #endif
27423
27424 /* This will work as long as patching hasn't happened yet
27425@@ -2048,6 +2056,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27426 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27427 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27428 .set_pgd = xen_set_pgd_hyper,
27429+ .set_pgd_batched = xen_set_pgd_hyper,
27430
27431 .alloc_pud = xen_alloc_pmd_init,
27432 .release_pud = xen_release_pmd_init,
27433diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27434index f58dca7..ad21f52 100644
27435--- a/arch/x86/xen/smp.c
27436+++ b/arch/x86/xen/smp.c
27437@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27438 {
27439 BUG_ON(smp_processor_id() != 0);
27440 native_smp_prepare_boot_cpu();
27441-
27442- /* We've switched to the "real" per-cpu gdt, so make sure the
27443- old memory can be recycled */
27444- make_lowmem_page_readwrite(xen_initial_gdt);
27445-
27446 xen_filter_cpu_maps();
27447 xen_setup_vcpu_info_placement();
27448 }
27449@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27450 gdt = get_cpu_gdt_table(cpu);
27451
27452 ctxt->flags = VGCF_IN_KERNEL;
27453- ctxt->user_regs.ds = __USER_DS;
27454- ctxt->user_regs.es = __USER_DS;
27455+ ctxt->user_regs.ds = __KERNEL_DS;
27456+ ctxt->user_regs.es = __KERNEL_DS;
27457 ctxt->user_regs.ss = __KERNEL_DS;
27458 #ifdef CONFIG_X86_32
27459 ctxt->user_regs.fs = __KERNEL_PERCPU;
27460- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27461+ savesegment(gs, ctxt->user_regs.gs);
27462 #else
27463 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27464 #endif
27465@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27466 int rc;
27467
27468 per_cpu(current_task, cpu) = idle;
27469+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27470 #ifdef CONFIG_X86_32
27471 irq_ctx_init(cpu);
27472 #else
27473 clear_tsk_thread_flag(idle, TIF_FORK);
27474- per_cpu(kernel_stack, cpu) =
27475- (unsigned long)task_stack_page(idle) -
27476- KERNEL_STACK_OFFSET + THREAD_SIZE;
27477+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27478 #endif
27479 xen_setup_runstate_info(cpu);
27480 xen_setup_timer(cpu);
27481diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27482index f9643fc..602e8af 100644
27483--- a/arch/x86/xen/xen-asm_32.S
27484+++ b/arch/x86/xen/xen-asm_32.S
27485@@ -84,14 +84,14 @@ ENTRY(xen_iret)
27486 ESP_OFFSET=4 # bytes pushed onto stack
27487
27488 /*
27489- * Store vcpu_info pointer for easy access. Do it this way to
27490- * avoid having to reload %fs
27491+ * Store vcpu_info pointer for easy access.
27492 */
27493 #ifdef CONFIG_SMP
27494- GET_THREAD_INFO(%eax)
27495- movl TI_cpu(%eax), %eax
27496- movl __per_cpu_offset(,%eax,4), %eax
27497- mov xen_vcpu(%eax), %eax
27498+ push %fs
27499+ mov $(__KERNEL_PERCPU), %eax
27500+ mov %eax, %fs
27501+ mov PER_CPU_VAR(xen_vcpu), %eax
27502+ pop %fs
27503 #else
27504 movl xen_vcpu, %eax
27505 #endif
27506diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27507index aaa7291..3f77960 100644
27508--- a/arch/x86/xen/xen-head.S
27509+++ b/arch/x86/xen/xen-head.S
27510@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27511 #ifdef CONFIG_X86_32
27512 mov %esi,xen_start_info
27513 mov $init_thread_union+THREAD_SIZE,%esp
27514+#ifdef CONFIG_SMP
27515+ movl $cpu_gdt_table,%edi
27516+ movl $__per_cpu_load,%eax
27517+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27518+ rorl $16,%eax
27519+ movb %al,__KERNEL_PERCPU + 4(%edi)
27520+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27521+ movl $__per_cpu_end - 1,%eax
27522+ subl $__per_cpu_start,%eax
27523+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27524+#endif
27525 #else
27526 mov %rsi,xen_start_info
27527 mov $init_thread_union+THREAD_SIZE,%rsp
27528diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27529index 202d4c1..99b072a 100644
27530--- a/arch/x86/xen/xen-ops.h
27531+++ b/arch/x86/xen/xen-ops.h
27532@@ -10,8 +10,6 @@
27533 extern const char xen_hypervisor_callback[];
27534 extern const char xen_failsafe_callback[];
27535
27536-extern void *xen_initial_gdt;
27537-
27538 struct trap_info;
27539 void xen_copy_trap_info(struct trap_info *traps);
27540
27541diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27542index 525bd3d..ef888b1 100644
27543--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27544+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27545@@ -119,9 +119,9 @@
27546 ----------------------------------------------------------------------*/
27547
27548 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27549-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27550 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27551 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27552+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27553
27554 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27555 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27556diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27557index 2f33760..835e50a 100644
27558--- a/arch/xtensa/variants/fsf/include/variant/core.h
27559+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27560@@ -11,6 +11,7 @@
27561 #ifndef _XTENSA_CORE_H
27562 #define _XTENSA_CORE_H
27563
27564+#include <linux/const.h>
27565
27566 /****************************************************************************
27567 Parameters Useful for Any Code, USER or PRIVILEGED
27568@@ -112,9 +113,9 @@
27569 ----------------------------------------------------------------------*/
27570
27571 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27572-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27573 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27574 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27575+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27576
27577 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27578 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27579diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27580index af00795..2bb8105 100644
27581--- a/arch/xtensa/variants/s6000/include/variant/core.h
27582+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27583@@ -11,6 +11,7 @@
27584 #ifndef _XTENSA_CORE_CONFIGURATION_H
27585 #define _XTENSA_CORE_CONFIGURATION_H
27586
27587+#include <linux/const.h>
27588
27589 /****************************************************************************
27590 Parameters Useful for Any Code, USER or PRIVILEGED
27591@@ -118,9 +119,9 @@
27592 ----------------------------------------------------------------------*/
27593
27594 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27595-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27596 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27597 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27598+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27599
27600 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27601 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27602diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27603index 58916af..9cb880b 100644
27604--- a/block/blk-iopoll.c
27605+++ b/block/blk-iopoll.c
27606@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27607 }
27608 EXPORT_SYMBOL(blk_iopoll_complete);
27609
27610-static void blk_iopoll_softirq(struct softirq_action *h)
27611+static void blk_iopoll_softirq(void)
27612 {
27613 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27614 int rearm = 0, budget = blk_iopoll_budget;
27615diff --git a/block/blk-map.c b/block/blk-map.c
27616index 623e1cd..ca1e109 100644
27617--- a/block/blk-map.c
27618+++ b/block/blk-map.c
27619@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27620 if (!len || !kbuf)
27621 return -EINVAL;
27622
27623- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27624+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27625 if (do_copy)
27626 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27627 else
27628diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27629index 467c8de..4bddc6d 100644
27630--- a/block/blk-softirq.c
27631+++ b/block/blk-softirq.c
27632@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27633 * Softirq action handler - move entries to local list and loop over them
27634 * while passing them to the queue registered handler.
27635 */
27636-static void blk_done_softirq(struct softirq_action *h)
27637+static void blk_done_softirq(void)
27638 {
27639 struct list_head *cpu_list, local_list;
27640
27641diff --git a/block/bsg.c b/block/bsg.c
27642index ff64ae3..593560c 100644
27643--- a/block/bsg.c
27644+++ b/block/bsg.c
27645@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27646 struct sg_io_v4 *hdr, struct bsg_device *bd,
27647 fmode_t has_write_perm)
27648 {
27649+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27650+ unsigned char *cmdptr;
27651+
27652 if (hdr->request_len > BLK_MAX_CDB) {
27653 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27654 if (!rq->cmd)
27655 return -ENOMEM;
27656- }
27657+ cmdptr = rq->cmd;
27658+ } else
27659+ cmdptr = tmpcmd;
27660
27661- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27662+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27663 hdr->request_len))
27664 return -EFAULT;
27665
27666+ if (cmdptr != rq->cmd)
27667+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27668+
27669 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27670 if (blk_verify_command(rq->cmd, has_write_perm))
27671 return -EPERM;
27672diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27673index 7c668c8..db3521c 100644
27674--- a/block/compat_ioctl.c
27675+++ b/block/compat_ioctl.c
27676@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27677 err |= __get_user(f->spec1, &uf->spec1);
27678 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27679 err |= __get_user(name, &uf->name);
27680- f->name = compat_ptr(name);
27681+ f->name = (void __force_kernel *)compat_ptr(name);
27682 if (err) {
27683 err = -EFAULT;
27684 goto out;
27685diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27686index 6296b40..417c00f 100644
27687--- a/block/partitions/efi.c
27688+++ b/block/partitions/efi.c
27689@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27690 if (!gpt)
27691 return NULL;
27692
27693+ if (!le32_to_cpu(gpt->num_partition_entries))
27694+ return NULL;
27695+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27696+ if (!pte)
27697+ return NULL;
27698+
27699 count = le32_to_cpu(gpt->num_partition_entries) *
27700 le32_to_cpu(gpt->sizeof_partition_entry);
27701- if (!count)
27702- return NULL;
27703- pte = kzalloc(count, GFP_KERNEL);
27704- if (!pte)
27705- return NULL;
27706-
27707 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27708 (u8 *) pte,
27709 count) < count) {
27710diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27711index 9a87daa..fb17486 100644
27712--- a/block/scsi_ioctl.c
27713+++ b/block/scsi_ioctl.c
27714@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27715 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27716 struct sg_io_hdr *hdr, fmode_t mode)
27717 {
27718- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27719+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27720+ unsigned char *cmdptr;
27721+
27722+ if (rq->cmd != rq->__cmd)
27723+ cmdptr = rq->cmd;
27724+ else
27725+ cmdptr = tmpcmd;
27726+
27727+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27728 return -EFAULT;
27729+
27730+ if (cmdptr != rq->cmd)
27731+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27732+
27733 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27734 return -EPERM;
27735
27736@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27737 int err;
27738 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27739 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27740+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27741+ unsigned char *cmdptr;
27742
27743 if (!sic)
27744 return -EINVAL;
27745@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27746 */
27747 err = -EFAULT;
27748 rq->cmd_len = cmdlen;
27749- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27750+
27751+ if (rq->cmd != rq->__cmd)
27752+ cmdptr = rq->cmd;
27753+ else
27754+ cmdptr = tmpcmd;
27755+
27756+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27757 goto error;
27758
27759+ if (rq->cmd != cmdptr)
27760+ memcpy(rq->cmd, cmdptr, cmdlen);
27761+
27762 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27763 goto error;
27764
27765diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27766index 671d4d6..5f24030 100644
27767--- a/crypto/cryptd.c
27768+++ b/crypto/cryptd.c
27769@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27770
27771 struct cryptd_blkcipher_request_ctx {
27772 crypto_completion_t complete;
27773-};
27774+} __no_const;
27775
27776 struct cryptd_hash_ctx {
27777 struct crypto_shash *child;
27778@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27779
27780 struct cryptd_aead_request_ctx {
27781 crypto_completion_t complete;
27782-};
27783+} __no_const;
27784
27785 static void cryptd_queue_worker(struct work_struct *work);
27786
27787diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27788index e6defd8..c26a225 100644
27789--- a/drivers/acpi/apei/cper.c
27790+++ b/drivers/acpi/apei/cper.c
27791@@ -38,12 +38,12 @@
27792 */
27793 u64 cper_next_record_id(void)
27794 {
27795- static atomic64_t seq;
27796+ static atomic64_unchecked_t seq;
27797
27798- if (!atomic64_read(&seq))
27799- atomic64_set(&seq, ((u64)get_seconds()) << 32);
27800+ if (!atomic64_read_unchecked(&seq))
27801+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27802
27803- return atomic64_inc_return(&seq);
27804+ return atomic64_inc_return_unchecked(&seq);
27805 }
27806 EXPORT_SYMBOL_GPL(cper_next_record_id);
27807
27808diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27809index 7586544..636a2f0 100644
27810--- a/drivers/acpi/ec_sys.c
27811+++ b/drivers/acpi/ec_sys.c
27812@@ -12,6 +12,7 @@
27813 #include <linux/acpi.h>
27814 #include <linux/debugfs.h>
27815 #include <linux/module.h>
27816+#include <linux/uaccess.h>
27817 #include "internal.h"
27818
27819 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27820@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27821 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27822 */
27823 unsigned int size = EC_SPACE_SIZE;
27824- u8 *data = (u8 *) buf;
27825+ u8 data;
27826 loff_t init_off = *off;
27827 int err = 0;
27828
27829@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27830 size = count;
27831
27832 while (size) {
27833- err = ec_read(*off, &data[*off - init_off]);
27834+ err = ec_read(*off, &data);
27835 if (err)
27836 return err;
27837+ if (put_user(data, &buf[*off - init_off]))
27838+ return -EFAULT;
27839 *off += 1;
27840 size--;
27841 }
27842@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27843
27844 unsigned int size = count;
27845 loff_t init_off = *off;
27846- u8 *data = (u8 *) buf;
27847 int err = 0;
27848
27849 if (*off >= EC_SPACE_SIZE)
27850@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27851 }
27852
27853 while (size) {
27854- u8 byte_write = data[*off - init_off];
27855+ u8 byte_write;
27856+ if (get_user(byte_write, &buf[*off - init_off]))
27857+ return -EFAULT;
27858 err = ec_write(*off, byte_write);
27859 if (err)
27860 return err;
27861diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27862index 251c7b62..000462d 100644
27863--- a/drivers/acpi/proc.c
27864+++ b/drivers/acpi/proc.c
27865@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27866 size_t count, loff_t * ppos)
27867 {
27868 struct list_head *node, *next;
27869- char strbuf[5];
27870- char str[5] = "";
27871- unsigned int len = count;
27872+ char strbuf[5] = {0};
27873
27874- if (len > 4)
27875- len = 4;
27876- if (len < 0)
27877+ if (count > 4)
27878+ count = 4;
27879+ if (copy_from_user(strbuf, buffer, count))
27880 return -EFAULT;
27881-
27882- if (copy_from_user(strbuf, buffer, len))
27883- return -EFAULT;
27884- strbuf[len] = '\0';
27885- sscanf(strbuf, "%s", str);
27886+ strbuf[count] = '\0';
27887
27888 mutex_lock(&acpi_device_lock);
27889 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27890@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27891 if (!dev->wakeup.flags.valid)
27892 continue;
27893
27894- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27895+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27896 if (device_can_wakeup(&dev->dev)) {
27897 bool enable = !device_may_wakeup(&dev->dev);
27898 device_set_wakeup_enable(&dev->dev, enable);
27899diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27900index bfc31cb..8213ce1 100644
27901--- a/drivers/acpi/processor_driver.c
27902+++ b/drivers/acpi/processor_driver.c
27903@@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27904 return 0;
27905 #endif
27906
27907- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27908+ BUG_ON(pr->id >= nr_cpu_ids);
27909
27910 /*
27911 * Buggy BIOS check
27912diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27913index 8e1039c..ea9cbd4 100644
27914--- a/drivers/ata/libata-core.c
27915+++ b/drivers/ata/libata-core.c
27916@@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27917 struct ata_port *ap;
27918 unsigned int tag;
27919
27920- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27921+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27922 ap = qc->ap;
27923
27924 qc->flags = 0;
27925@@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27926 struct ata_port *ap;
27927 struct ata_link *link;
27928
27929- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27930+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27931 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27932 ap = qc->ap;
27933 link = qc->dev->link;
27934@@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27935 return;
27936
27937 spin_lock(&lock);
27938+ pax_open_kernel();
27939
27940 for (cur = ops->inherits; cur; cur = cur->inherits) {
27941 void **inherit = (void **)cur;
27942@@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27943 if (IS_ERR(*pp))
27944 *pp = NULL;
27945
27946- ops->inherits = NULL;
27947+ *(struct ata_port_operations **)&ops->inherits = NULL;
27948
27949+ pax_close_kernel();
27950 spin_unlock(&lock);
27951 }
27952
27953diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27954index bfaa5cb..3ba1cc3 100644
27955--- a/drivers/ata/pata_arasan_cf.c
27956+++ b/drivers/ata/pata_arasan_cf.c
27957@@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27958 /* Handle platform specific quirks */
27959 if (pdata->quirk) {
27960 if (pdata->quirk & CF_BROKEN_PIO) {
27961- ap->ops->set_piomode = NULL;
27962+ pax_open_kernel();
27963+ *(void **)&ap->ops->set_piomode = NULL;
27964+ pax_close_kernel();
27965 ap->pio_mask = 0;
27966 }
27967 if (pdata->quirk & CF_BROKEN_MWDMA)
27968diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27969index f9b983a..887b9d8 100644
27970--- a/drivers/atm/adummy.c
27971+++ b/drivers/atm/adummy.c
27972@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27973 vcc->pop(vcc, skb);
27974 else
27975 dev_kfree_skb_any(skb);
27976- atomic_inc(&vcc->stats->tx);
27977+ atomic_inc_unchecked(&vcc->stats->tx);
27978
27979 return 0;
27980 }
27981diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27982index 89b30f3..7964211 100644
27983--- a/drivers/atm/ambassador.c
27984+++ b/drivers/atm/ambassador.c
27985@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27986 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27987
27988 // VC layer stats
27989- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27990+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27991
27992 // free the descriptor
27993 kfree (tx_descr);
27994@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27995 dump_skb ("<<<", vc, skb);
27996
27997 // VC layer stats
27998- atomic_inc(&atm_vcc->stats->rx);
27999+ atomic_inc_unchecked(&atm_vcc->stats->rx);
28000 __net_timestamp(skb);
28001 // end of our responsibility
28002 atm_vcc->push (atm_vcc, skb);
28003@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28004 } else {
28005 PRINTK (KERN_INFO, "dropped over-size frame");
28006 // should we count this?
28007- atomic_inc(&atm_vcc->stats->rx_drop);
28008+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28009 }
28010
28011 } else {
28012@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28013 }
28014
28015 if (check_area (skb->data, skb->len)) {
28016- atomic_inc(&atm_vcc->stats->tx_err);
28017+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28018 return -ENOMEM; // ?
28019 }
28020
28021diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28022index b22d71c..d6e1049 100644
28023--- a/drivers/atm/atmtcp.c
28024+++ b/drivers/atm/atmtcp.c
28025@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28026 if (vcc->pop) vcc->pop(vcc,skb);
28027 else dev_kfree_skb(skb);
28028 if (dev_data) return 0;
28029- atomic_inc(&vcc->stats->tx_err);
28030+ atomic_inc_unchecked(&vcc->stats->tx_err);
28031 return -ENOLINK;
28032 }
28033 size = skb->len+sizeof(struct atmtcp_hdr);
28034@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28035 if (!new_skb) {
28036 if (vcc->pop) vcc->pop(vcc,skb);
28037 else dev_kfree_skb(skb);
28038- atomic_inc(&vcc->stats->tx_err);
28039+ atomic_inc_unchecked(&vcc->stats->tx_err);
28040 return -ENOBUFS;
28041 }
28042 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28043@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28044 if (vcc->pop) vcc->pop(vcc,skb);
28045 else dev_kfree_skb(skb);
28046 out_vcc->push(out_vcc,new_skb);
28047- atomic_inc(&vcc->stats->tx);
28048- atomic_inc(&out_vcc->stats->rx);
28049+ atomic_inc_unchecked(&vcc->stats->tx);
28050+ atomic_inc_unchecked(&out_vcc->stats->rx);
28051 return 0;
28052 }
28053
28054@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28055 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28056 read_unlock(&vcc_sklist_lock);
28057 if (!out_vcc) {
28058- atomic_inc(&vcc->stats->tx_err);
28059+ atomic_inc_unchecked(&vcc->stats->tx_err);
28060 goto done;
28061 }
28062 skb_pull(skb,sizeof(struct atmtcp_hdr));
28063@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28064 __net_timestamp(new_skb);
28065 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28066 out_vcc->push(out_vcc,new_skb);
28067- atomic_inc(&vcc->stats->tx);
28068- atomic_inc(&out_vcc->stats->rx);
28069+ atomic_inc_unchecked(&vcc->stats->tx);
28070+ atomic_inc_unchecked(&out_vcc->stats->rx);
28071 done:
28072 if (vcc->pop) vcc->pop(vcc,skb);
28073 else dev_kfree_skb(skb);
28074diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28075index 2059ee4..faf51c7 100644
28076--- a/drivers/atm/eni.c
28077+++ b/drivers/atm/eni.c
28078@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28079 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28080 vcc->dev->number);
28081 length = 0;
28082- atomic_inc(&vcc->stats->rx_err);
28083+ atomic_inc_unchecked(&vcc->stats->rx_err);
28084 }
28085 else {
28086 length = ATM_CELL_SIZE-1; /* no HEC */
28087@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28088 size);
28089 }
28090 eff = length = 0;
28091- atomic_inc(&vcc->stats->rx_err);
28092+ atomic_inc_unchecked(&vcc->stats->rx_err);
28093 }
28094 else {
28095 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28096@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28097 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28098 vcc->dev->number,vcc->vci,length,size << 2,descr);
28099 length = eff = 0;
28100- atomic_inc(&vcc->stats->rx_err);
28101+ atomic_inc_unchecked(&vcc->stats->rx_err);
28102 }
28103 }
28104 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28105@@ -767,7 +767,7 @@ rx_dequeued++;
28106 vcc->push(vcc,skb);
28107 pushed++;
28108 }
28109- atomic_inc(&vcc->stats->rx);
28110+ atomic_inc_unchecked(&vcc->stats->rx);
28111 }
28112 wake_up(&eni_dev->rx_wait);
28113 }
28114@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28115 PCI_DMA_TODEVICE);
28116 if (vcc->pop) vcc->pop(vcc,skb);
28117 else dev_kfree_skb_irq(skb);
28118- atomic_inc(&vcc->stats->tx);
28119+ atomic_inc_unchecked(&vcc->stats->tx);
28120 wake_up(&eni_dev->tx_wait);
28121 dma_complete++;
28122 }
28123@@ -1567,7 +1567,7 @@ tx_complete++;
28124 /*--------------------------------- entries ---------------------------------*/
28125
28126
28127-static const char *media_name[] __devinitdata = {
28128+static const char *media_name[] __devinitconst = {
28129 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28130 "UTP", "05?", "06?", "07?", /* 4- 7 */
28131 "TAXI","09?", "10?", "11?", /* 8-11 */
28132diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28133index 86fed1b..6dc4721 100644
28134--- a/drivers/atm/firestream.c
28135+++ b/drivers/atm/firestream.c
28136@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28137 }
28138 }
28139
28140- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28141+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28142
28143 fs_dprintk (FS_DEBUG_TXMEM, "i");
28144 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28145@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28146 #endif
28147 skb_put (skb, qe->p1 & 0xffff);
28148 ATM_SKB(skb)->vcc = atm_vcc;
28149- atomic_inc(&atm_vcc->stats->rx);
28150+ atomic_inc_unchecked(&atm_vcc->stats->rx);
28151 __net_timestamp(skb);
28152 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28153 atm_vcc->push (atm_vcc, skb);
28154@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28155 kfree (pe);
28156 }
28157 if (atm_vcc)
28158- atomic_inc(&atm_vcc->stats->rx_drop);
28159+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28160 break;
28161 case 0x1f: /* Reassembly abort: no buffers. */
28162 /* Silently increment error counter. */
28163 if (atm_vcc)
28164- atomic_inc(&atm_vcc->stats->rx_drop);
28165+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28166 break;
28167 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28168 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28169diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28170index 361f5ae..7fc552d 100644
28171--- a/drivers/atm/fore200e.c
28172+++ b/drivers/atm/fore200e.c
28173@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28174 #endif
28175 /* check error condition */
28176 if (*entry->status & STATUS_ERROR)
28177- atomic_inc(&vcc->stats->tx_err);
28178+ atomic_inc_unchecked(&vcc->stats->tx_err);
28179 else
28180- atomic_inc(&vcc->stats->tx);
28181+ atomic_inc_unchecked(&vcc->stats->tx);
28182 }
28183 }
28184
28185@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28186 if (skb == NULL) {
28187 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28188
28189- atomic_inc(&vcc->stats->rx_drop);
28190+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28191 return -ENOMEM;
28192 }
28193
28194@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28195
28196 dev_kfree_skb_any(skb);
28197
28198- atomic_inc(&vcc->stats->rx_drop);
28199+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28200 return -ENOMEM;
28201 }
28202
28203 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28204
28205 vcc->push(vcc, skb);
28206- atomic_inc(&vcc->stats->rx);
28207+ atomic_inc_unchecked(&vcc->stats->rx);
28208
28209 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28210
28211@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28212 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28213 fore200e->atm_dev->number,
28214 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28215- atomic_inc(&vcc->stats->rx_err);
28216+ atomic_inc_unchecked(&vcc->stats->rx_err);
28217 }
28218 }
28219
28220@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28221 goto retry_here;
28222 }
28223
28224- atomic_inc(&vcc->stats->tx_err);
28225+ atomic_inc_unchecked(&vcc->stats->tx_err);
28226
28227 fore200e->tx_sat++;
28228 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28229diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28230index b182c2f..1c6fa8a 100644
28231--- a/drivers/atm/he.c
28232+++ b/drivers/atm/he.c
28233@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28234
28235 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28236 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28237- atomic_inc(&vcc->stats->rx_drop);
28238+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28239 goto return_host_buffers;
28240 }
28241
28242@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28243 RBRQ_LEN_ERR(he_dev->rbrq_head)
28244 ? "LEN_ERR" : "",
28245 vcc->vpi, vcc->vci);
28246- atomic_inc(&vcc->stats->rx_err);
28247+ atomic_inc_unchecked(&vcc->stats->rx_err);
28248 goto return_host_buffers;
28249 }
28250
28251@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28252 vcc->push(vcc, skb);
28253 spin_lock(&he_dev->global_lock);
28254
28255- atomic_inc(&vcc->stats->rx);
28256+ atomic_inc_unchecked(&vcc->stats->rx);
28257
28258 return_host_buffers:
28259 ++pdus_assembled;
28260@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28261 tpd->vcc->pop(tpd->vcc, tpd->skb);
28262 else
28263 dev_kfree_skb_any(tpd->skb);
28264- atomic_inc(&tpd->vcc->stats->tx_err);
28265+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28266 }
28267 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28268 return;
28269@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28270 vcc->pop(vcc, skb);
28271 else
28272 dev_kfree_skb_any(skb);
28273- atomic_inc(&vcc->stats->tx_err);
28274+ atomic_inc_unchecked(&vcc->stats->tx_err);
28275 return -EINVAL;
28276 }
28277
28278@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28279 vcc->pop(vcc, skb);
28280 else
28281 dev_kfree_skb_any(skb);
28282- atomic_inc(&vcc->stats->tx_err);
28283+ atomic_inc_unchecked(&vcc->stats->tx_err);
28284 return -EINVAL;
28285 }
28286 #endif
28287@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28288 vcc->pop(vcc, skb);
28289 else
28290 dev_kfree_skb_any(skb);
28291- atomic_inc(&vcc->stats->tx_err);
28292+ atomic_inc_unchecked(&vcc->stats->tx_err);
28293 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28294 return -ENOMEM;
28295 }
28296@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28297 vcc->pop(vcc, skb);
28298 else
28299 dev_kfree_skb_any(skb);
28300- atomic_inc(&vcc->stats->tx_err);
28301+ atomic_inc_unchecked(&vcc->stats->tx_err);
28302 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28303 return -ENOMEM;
28304 }
28305@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28306 __enqueue_tpd(he_dev, tpd, cid);
28307 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28308
28309- atomic_inc(&vcc->stats->tx);
28310+ atomic_inc_unchecked(&vcc->stats->tx);
28311
28312 return 0;
28313 }
28314diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28315index 7d01c2a..4e3ac01 100644
28316--- a/drivers/atm/horizon.c
28317+++ b/drivers/atm/horizon.c
28318@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28319 {
28320 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28321 // VC layer stats
28322- atomic_inc(&vcc->stats->rx);
28323+ atomic_inc_unchecked(&vcc->stats->rx);
28324 __net_timestamp(skb);
28325 // end of our responsibility
28326 vcc->push (vcc, skb);
28327@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28328 dev->tx_iovec = NULL;
28329
28330 // VC layer stats
28331- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28332+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28333
28334 // free the skb
28335 hrz_kfree_skb (skb);
28336diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28337index 8974bd2..b856f85 100644
28338--- a/drivers/atm/idt77252.c
28339+++ b/drivers/atm/idt77252.c
28340@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28341 else
28342 dev_kfree_skb(skb);
28343
28344- atomic_inc(&vcc->stats->tx);
28345+ atomic_inc_unchecked(&vcc->stats->tx);
28346 }
28347
28348 atomic_dec(&scq->used);
28349@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28350 if ((sb = dev_alloc_skb(64)) == NULL) {
28351 printk("%s: Can't allocate buffers for aal0.\n",
28352 card->name);
28353- atomic_add(i, &vcc->stats->rx_drop);
28354+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28355 break;
28356 }
28357 if (!atm_charge(vcc, sb->truesize)) {
28358 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28359 card->name);
28360- atomic_add(i - 1, &vcc->stats->rx_drop);
28361+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28362 dev_kfree_skb(sb);
28363 break;
28364 }
28365@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28366 ATM_SKB(sb)->vcc = vcc;
28367 __net_timestamp(sb);
28368 vcc->push(vcc, sb);
28369- atomic_inc(&vcc->stats->rx);
28370+ atomic_inc_unchecked(&vcc->stats->rx);
28371
28372 cell += ATM_CELL_PAYLOAD;
28373 }
28374@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28375 "(CDC: %08x)\n",
28376 card->name, len, rpp->len, readl(SAR_REG_CDC));
28377 recycle_rx_pool_skb(card, rpp);
28378- atomic_inc(&vcc->stats->rx_err);
28379+ atomic_inc_unchecked(&vcc->stats->rx_err);
28380 return;
28381 }
28382 if (stat & SAR_RSQE_CRC) {
28383 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28384 recycle_rx_pool_skb(card, rpp);
28385- atomic_inc(&vcc->stats->rx_err);
28386+ atomic_inc_unchecked(&vcc->stats->rx_err);
28387 return;
28388 }
28389 if (skb_queue_len(&rpp->queue) > 1) {
28390@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28391 RXPRINTK("%s: Can't alloc RX skb.\n",
28392 card->name);
28393 recycle_rx_pool_skb(card, rpp);
28394- atomic_inc(&vcc->stats->rx_err);
28395+ atomic_inc_unchecked(&vcc->stats->rx_err);
28396 return;
28397 }
28398 if (!atm_charge(vcc, skb->truesize)) {
28399@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28400 __net_timestamp(skb);
28401
28402 vcc->push(vcc, skb);
28403- atomic_inc(&vcc->stats->rx);
28404+ atomic_inc_unchecked(&vcc->stats->rx);
28405
28406 return;
28407 }
28408@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28409 __net_timestamp(skb);
28410
28411 vcc->push(vcc, skb);
28412- atomic_inc(&vcc->stats->rx);
28413+ atomic_inc_unchecked(&vcc->stats->rx);
28414
28415 if (skb->truesize > SAR_FB_SIZE_3)
28416 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28417@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28418 if (vcc->qos.aal != ATM_AAL0) {
28419 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28420 card->name, vpi, vci);
28421- atomic_inc(&vcc->stats->rx_drop);
28422+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28423 goto drop;
28424 }
28425
28426 if ((sb = dev_alloc_skb(64)) == NULL) {
28427 printk("%s: Can't allocate buffers for AAL0.\n",
28428 card->name);
28429- atomic_inc(&vcc->stats->rx_err);
28430+ atomic_inc_unchecked(&vcc->stats->rx_err);
28431 goto drop;
28432 }
28433
28434@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28435 ATM_SKB(sb)->vcc = vcc;
28436 __net_timestamp(sb);
28437 vcc->push(vcc, sb);
28438- atomic_inc(&vcc->stats->rx);
28439+ atomic_inc_unchecked(&vcc->stats->rx);
28440
28441 drop:
28442 skb_pull(queue, 64);
28443@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28444
28445 if (vc == NULL) {
28446 printk("%s: NULL connection in send().\n", card->name);
28447- atomic_inc(&vcc->stats->tx_err);
28448+ atomic_inc_unchecked(&vcc->stats->tx_err);
28449 dev_kfree_skb(skb);
28450 return -EINVAL;
28451 }
28452 if (!test_bit(VCF_TX, &vc->flags)) {
28453 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28454- atomic_inc(&vcc->stats->tx_err);
28455+ atomic_inc_unchecked(&vcc->stats->tx_err);
28456 dev_kfree_skb(skb);
28457 return -EINVAL;
28458 }
28459@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28460 break;
28461 default:
28462 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28463- atomic_inc(&vcc->stats->tx_err);
28464+ atomic_inc_unchecked(&vcc->stats->tx_err);
28465 dev_kfree_skb(skb);
28466 return -EINVAL;
28467 }
28468
28469 if (skb_shinfo(skb)->nr_frags != 0) {
28470 printk("%s: No scatter-gather yet.\n", card->name);
28471- atomic_inc(&vcc->stats->tx_err);
28472+ atomic_inc_unchecked(&vcc->stats->tx_err);
28473 dev_kfree_skb(skb);
28474 return -EINVAL;
28475 }
28476@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28477
28478 err = queue_skb(card, vc, skb, oam);
28479 if (err) {
28480- atomic_inc(&vcc->stats->tx_err);
28481+ atomic_inc_unchecked(&vcc->stats->tx_err);
28482 dev_kfree_skb(skb);
28483 return err;
28484 }
28485@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28486 skb = dev_alloc_skb(64);
28487 if (!skb) {
28488 printk("%s: Out of memory in send_oam().\n", card->name);
28489- atomic_inc(&vcc->stats->tx_err);
28490+ atomic_inc_unchecked(&vcc->stats->tx_err);
28491 return -ENOMEM;
28492 }
28493 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28494diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28495index 96cce6d..62c3ec5 100644
28496--- a/drivers/atm/iphase.c
28497+++ b/drivers/atm/iphase.c
28498@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28499 status = (u_short) (buf_desc_ptr->desc_mode);
28500 if (status & (RX_CER | RX_PTE | RX_OFL))
28501 {
28502- atomic_inc(&vcc->stats->rx_err);
28503+ atomic_inc_unchecked(&vcc->stats->rx_err);
28504 IF_ERR(printk("IA: bad packet, dropping it");)
28505 if (status & RX_CER) {
28506 IF_ERR(printk(" cause: packet CRC error\n");)
28507@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28508 len = dma_addr - buf_addr;
28509 if (len > iadev->rx_buf_sz) {
28510 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28511- atomic_inc(&vcc->stats->rx_err);
28512+ atomic_inc_unchecked(&vcc->stats->rx_err);
28513 goto out_free_desc;
28514 }
28515
28516@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28517 ia_vcc = INPH_IA_VCC(vcc);
28518 if (ia_vcc == NULL)
28519 {
28520- atomic_inc(&vcc->stats->rx_err);
28521+ atomic_inc_unchecked(&vcc->stats->rx_err);
28522 atm_return(vcc, skb->truesize);
28523 dev_kfree_skb_any(skb);
28524 goto INCR_DLE;
28525@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28526 if ((length > iadev->rx_buf_sz) || (length >
28527 (skb->len - sizeof(struct cpcs_trailer))))
28528 {
28529- atomic_inc(&vcc->stats->rx_err);
28530+ atomic_inc_unchecked(&vcc->stats->rx_err);
28531 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28532 length, skb->len);)
28533 atm_return(vcc, skb->truesize);
28534@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28535
28536 IF_RX(printk("rx_dle_intr: skb push");)
28537 vcc->push(vcc,skb);
28538- atomic_inc(&vcc->stats->rx);
28539+ atomic_inc_unchecked(&vcc->stats->rx);
28540 iadev->rx_pkt_cnt++;
28541 }
28542 INCR_DLE:
28543@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28544 {
28545 struct k_sonet_stats *stats;
28546 stats = &PRIV(_ia_dev[board])->sonet_stats;
28547- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28548- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28549- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28550- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28551- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28552- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28553- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28554- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28555- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28556+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28557+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28558+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28559+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28560+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28561+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28562+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28563+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28564+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28565 }
28566 ia_cmds.status = 0;
28567 break;
28568@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28569 if ((desc == 0) || (desc > iadev->num_tx_desc))
28570 {
28571 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28572- atomic_inc(&vcc->stats->tx);
28573+ atomic_inc_unchecked(&vcc->stats->tx);
28574 if (vcc->pop)
28575 vcc->pop(vcc, skb);
28576 else
28577@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28578 ATM_DESC(skb) = vcc->vci;
28579 skb_queue_tail(&iadev->tx_dma_q, skb);
28580
28581- atomic_inc(&vcc->stats->tx);
28582+ atomic_inc_unchecked(&vcc->stats->tx);
28583 iadev->tx_pkt_cnt++;
28584 /* Increment transaction counter */
28585 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28586
28587 #if 0
28588 /* add flow control logic */
28589- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28590+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28591 if (iavcc->vc_desc_cnt > 10) {
28592 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28593 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28594diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28595index 68c7588..7036683 100644
28596--- a/drivers/atm/lanai.c
28597+++ b/drivers/atm/lanai.c
28598@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28599 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28600 lanai_endtx(lanai, lvcc);
28601 lanai_free_skb(lvcc->tx.atmvcc, skb);
28602- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28603+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28604 }
28605
28606 /* Try to fill the buffer - don't call unless there is backlog */
28607@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28608 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28609 __net_timestamp(skb);
28610 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28611- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28612+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28613 out:
28614 lvcc->rx.buf.ptr = end;
28615 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28616@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28617 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28618 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28619 lanai->stats.service_rxnotaal5++;
28620- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28621+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28622 return 0;
28623 }
28624 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28625@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28626 int bytes;
28627 read_unlock(&vcc_sklist_lock);
28628 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28629- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28630+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28631 lvcc->stats.x.aal5.service_trash++;
28632 bytes = (SERVICE_GET_END(s) * 16) -
28633 (((unsigned long) lvcc->rx.buf.ptr) -
28634@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28635 }
28636 if (s & SERVICE_STREAM) {
28637 read_unlock(&vcc_sklist_lock);
28638- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28639+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28640 lvcc->stats.x.aal5.service_stream++;
28641 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28642 "PDU on VCI %d!\n", lanai->number, vci);
28643@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28644 return 0;
28645 }
28646 DPRINTK("got rx crc error on vci %d\n", vci);
28647- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28648+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28649 lvcc->stats.x.aal5.service_rxcrc++;
28650 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28651 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28652diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28653index 1c70c45..300718d 100644
28654--- a/drivers/atm/nicstar.c
28655+++ b/drivers/atm/nicstar.c
28656@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28657 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28658 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28659 card->index);
28660- atomic_inc(&vcc->stats->tx_err);
28661+ atomic_inc_unchecked(&vcc->stats->tx_err);
28662 dev_kfree_skb_any(skb);
28663 return -EINVAL;
28664 }
28665@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28666 if (!vc->tx) {
28667 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28668 card->index);
28669- atomic_inc(&vcc->stats->tx_err);
28670+ atomic_inc_unchecked(&vcc->stats->tx_err);
28671 dev_kfree_skb_any(skb);
28672 return -EINVAL;
28673 }
28674@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28675 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28676 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28677 card->index);
28678- atomic_inc(&vcc->stats->tx_err);
28679+ atomic_inc_unchecked(&vcc->stats->tx_err);
28680 dev_kfree_skb_any(skb);
28681 return -EINVAL;
28682 }
28683
28684 if (skb_shinfo(skb)->nr_frags != 0) {
28685 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28686- atomic_inc(&vcc->stats->tx_err);
28687+ atomic_inc_unchecked(&vcc->stats->tx_err);
28688 dev_kfree_skb_any(skb);
28689 return -EINVAL;
28690 }
28691@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28692 }
28693
28694 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28695- atomic_inc(&vcc->stats->tx_err);
28696+ atomic_inc_unchecked(&vcc->stats->tx_err);
28697 dev_kfree_skb_any(skb);
28698 return -EIO;
28699 }
28700- atomic_inc(&vcc->stats->tx);
28701+ atomic_inc_unchecked(&vcc->stats->tx);
28702
28703 return 0;
28704 }
28705@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28706 printk
28707 ("nicstar%d: Can't allocate buffers for aal0.\n",
28708 card->index);
28709- atomic_add(i, &vcc->stats->rx_drop);
28710+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28711 break;
28712 }
28713 if (!atm_charge(vcc, sb->truesize)) {
28714 RXPRINTK
28715 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28716 card->index);
28717- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28718+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28719 dev_kfree_skb_any(sb);
28720 break;
28721 }
28722@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28723 ATM_SKB(sb)->vcc = vcc;
28724 __net_timestamp(sb);
28725 vcc->push(vcc, sb);
28726- atomic_inc(&vcc->stats->rx);
28727+ atomic_inc_unchecked(&vcc->stats->rx);
28728 cell += ATM_CELL_PAYLOAD;
28729 }
28730
28731@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28732 if (iovb == NULL) {
28733 printk("nicstar%d: Out of iovec buffers.\n",
28734 card->index);
28735- atomic_inc(&vcc->stats->rx_drop);
28736+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28737 recycle_rx_buf(card, skb);
28738 return;
28739 }
28740@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28741 small or large buffer itself. */
28742 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28743 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28744- atomic_inc(&vcc->stats->rx_err);
28745+ atomic_inc_unchecked(&vcc->stats->rx_err);
28746 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28747 NS_MAX_IOVECS);
28748 NS_PRV_IOVCNT(iovb) = 0;
28749@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28750 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28751 card->index);
28752 which_list(card, skb);
28753- atomic_inc(&vcc->stats->rx_err);
28754+ atomic_inc_unchecked(&vcc->stats->rx_err);
28755 recycle_rx_buf(card, skb);
28756 vc->rx_iov = NULL;
28757 recycle_iov_buf(card, iovb);
28758@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28759 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28760 card->index);
28761 which_list(card, skb);
28762- atomic_inc(&vcc->stats->rx_err);
28763+ atomic_inc_unchecked(&vcc->stats->rx_err);
28764 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28765 NS_PRV_IOVCNT(iovb));
28766 vc->rx_iov = NULL;
28767@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28768 printk(" - PDU size mismatch.\n");
28769 else
28770 printk(".\n");
28771- atomic_inc(&vcc->stats->rx_err);
28772+ atomic_inc_unchecked(&vcc->stats->rx_err);
28773 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28774 NS_PRV_IOVCNT(iovb));
28775 vc->rx_iov = NULL;
28776@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28777 /* skb points to a small buffer */
28778 if (!atm_charge(vcc, skb->truesize)) {
28779 push_rxbufs(card, skb);
28780- atomic_inc(&vcc->stats->rx_drop);
28781+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28782 } else {
28783 skb_put(skb, len);
28784 dequeue_sm_buf(card, skb);
28785@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28786 ATM_SKB(skb)->vcc = vcc;
28787 __net_timestamp(skb);
28788 vcc->push(vcc, skb);
28789- atomic_inc(&vcc->stats->rx);
28790+ atomic_inc_unchecked(&vcc->stats->rx);
28791 }
28792 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28793 struct sk_buff *sb;
28794@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28795 if (len <= NS_SMBUFSIZE) {
28796 if (!atm_charge(vcc, sb->truesize)) {
28797 push_rxbufs(card, sb);
28798- atomic_inc(&vcc->stats->rx_drop);
28799+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28800 } else {
28801 skb_put(sb, len);
28802 dequeue_sm_buf(card, sb);
28803@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28804 ATM_SKB(sb)->vcc = vcc;
28805 __net_timestamp(sb);
28806 vcc->push(vcc, sb);
28807- atomic_inc(&vcc->stats->rx);
28808+ atomic_inc_unchecked(&vcc->stats->rx);
28809 }
28810
28811 push_rxbufs(card, skb);
28812@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28813
28814 if (!atm_charge(vcc, skb->truesize)) {
28815 push_rxbufs(card, skb);
28816- atomic_inc(&vcc->stats->rx_drop);
28817+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28818 } else {
28819 dequeue_lg_buf(card, skb);
28820 #ifdef NS_USE_DESTRUCTORS
28821@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28822 ATM_SKB(skb)->vcc = vcc;
28823 __net_timestamp(skb);
28824 vcc->push(vcc, skb);
28825- atomic_inc(&vcc->stats->rx);
28826+ atomic_inc_unchecked(&vcc->stats->rx);
28827 }
28828
28829 push_rxbufs(card, sb);
28830@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28831 printk
28832 ("nicstar%d: Out of huge buffers.\n",
28833 card->index);
28834- atomic_inc(&vcc->stats->rx_drop);
28835+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28836 recycle_iovec_rx_bufs(card,
28837 (struct iovec *)
28838 iovb->data,
28839@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28840 card->hbpool.count++;
28841 } else
28842 dev_kfree_skb_any(hb);
28843- atomic_inc(&vcc->stats->rx_drop);
28844+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28845 } else {
28846 /* Copy the small buffer to the huge buffer */
28847 sb = (struct sk_buff *)iov->iov_base;
28848@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28849 #endif /* NS_USE_DESTRUCTORS */
28850 __net_timestamp(hb);
28851 vcc->push(vcc, hb);
28852- atomic_inc(&vcc->stats->rx);
28853+ atomic_inc_unchecked(&vcc->stats->rx);
28854 }
28855 }
28856
28857diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28858index 9851093..adb2b1e 100644
28859--- a/drivers/atm/solos-pci.c
28860+++ b/drivers/atm/solos-pci.c
28861@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28862 }
28863 atm_charge(vcc, skb->truesize);
28864 vcc->push(vcc, skb);
28865- atomic_inc(&vcc->stats->rx);
28866+ atomic_inc_unchecked(&vcc->stats->rx);
28867 break;
28868
28869 case PKT_STATUS:
28870@@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28871 vcc = SKB_CB(oldskb)->vcc;
28872
28873 if (vcc) {
28874- atomic_inc(&vcc->stats->tx);
28875+ atomic_inc_unchecked(&vcc->stats->tx);
28876 solos_pop(vcc, oldskb);
28877 } else
28878 dev_kfree_skb_irq(oldskb);
28879diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28880index 0215934..ce9f5b1 100644
28881--- a/drivers/atm/suni.c
28882+++ b/drivers/atm/suni.c
28883@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28884
28885
28886 #define ADD_LIMITED(s,v) \
28887- atomic_add((v),&stats->s); \
28888- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28889+ atomic_add_unchecked((v),&stats->s); \
28890+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28891
28892
28893 static void suni_hz(unsigned long from_timer)
28894diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28895index 5120a96..e2572bd 100644
28896--- a/drivers/atm/uPD98402.c
28897+++ b/drivers/atm/uPD98402.c
28898@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28899 struct sonet_stats tmp;
28900 int error = 0;
28901
28902- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28903+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28904 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28905 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28906 if (zero && !error) {
28907@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28908
28909
28910 #define ADD_LIMITED(s,v) \
28911- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28912- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28913- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28914+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28915+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28916+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28917
28918
28919 static void stat_event(struct atm_dev *dev)
28920@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28921 if (reason & uPD98402_INT_PFM) stat_event(dev);
28922 if (reason & uPD98402_INT_PCO) {
28923 (void) GET(PCOCR); /* clear interrupt cause */
28924- atomic_add(GET(HECCT),
28925+ atomic_add_unchecked(GET(HECCT),
28926 &PRIV(dev)->sonet_stats.uncorr_hcs);
28927 }
28928 if ((reason & uPD98402_INT_RFO) &&
28929@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28930 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28931 uPD98402_INT_LOS),PIMR); /* enable them */
28932 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28933- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28934- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28935- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28936+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28937+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28938+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28939 return 0;
28940 }
28941
28942diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28943index abe4e20..83c4727 100644
28944--- a/drivers/atm/zatm.c
28945+++ b/drivers/atm/zatm.c
28946@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28947 }
28948 if (!size) {
28949 dev_kfree_skb_irq(skb);
28950- if (vcc) atomic_inc(&vcc->stats->rx_err);
28951+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28952 continue;
28953 }
28954 if (!atm_charge(vcc,skb->truesize)) {
28955@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28956 skb->len = size;
28957 ATM_SKB(skb)->vcc = vcc;
28958 vcc->push(vcc,skb);
28959- atomic_inc(&vcc->stats->rx);
28960+ atomic_inc_unchecked(&vcc->stats->rx);
28961 }
28962 zout(pos & 0xffff,MTA(mbx));
28963 #if 0 /* probably a stupid idea */
28964@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28965 skb_queue_head(&zatm_vcc->backlog,skb);
28966 break;
28967 }
28968- atomic_inc(&vcc->stats->tx);
28969+ atomic_inc_unchecked(&vcc->stats->tx);
28970 wake_up(&zatm_vcc->tx_wait);
28971 }
28972
28973diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28974index deb4a45..211eff2 100644
28975--- a/drivers/base/devtmpfs.c
28976+++ b/drivers/base/devtmpfs.c
28977@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
28978 if (!thread)
28979 return 0;
28980
28981- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28982+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28983 if (err)
28984 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28985 else
28986diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28987index cbb463b..babe2cf 100644
28988--- a/drivers/base/power/wakeup.c
28989+++ b/drivers/base/power/wakeup.c
28990@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28991 * They need to be modified together atomically, so it's better to use one
28992 * atomic variable to hold them both.
28993 */
28994-static atomic_t combined_event_count = ATOMIC_INIT(0);
28995+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28996
28997 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28998 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28999
29000 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29001 {
29002- unsigned int comb = atomic_read(&combined_event_count);
29003+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
29004
29005 *cnt = (comb >> IN_PROGRESS_BITS);
29006 *inpr = comb & MAX_IN_PROGRESS;
29007@@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29008 ws->start_prevent_time = ws->last_time;
29009
29010 /* Increment the counter of events in progress. */
29011- cec = atomic_inc_return(&combined_event_count);
29012+ cec = atomic_inc_return_unchecked(&combined_event_count);
29013
29014 trace_wakeup_source_activate(ws->name, cec);
29015 }
29016@@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29017 * Increment the counter of registered wakeup events and decrement the
29018 * couter of wakeup events in progress simultaneously.
29019 */
29020- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29021+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29022 trace_wakeup_source_deactivate(ws->name, cec);
29023
29024 split_counters(&cnt, &inpr);
29025diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29026index b0f553b..77b928b 100644
29027--- a/drivers/block/cciss.c
29028+++ b/drivers/block/cciss.c
29029@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29030 int err;
29031 u32 cp;
29032
29033+ memset(&arg64, 0, sizeof(arg64));
29034+
29035 err = 0;
29036 err |=
29037 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29038@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29039 while (!list_empty(&h->reqQ)) {
29040 c = list_entry(h->reqQ.next, CommandList_struct, list);
29041 /* can't do anything if fifo is full */
29042- if ((h->access.fifo_full(h))) {
29043+ if ((h->access->fifo_full(h))) {
29044 dev_warn(&h->pdev->dev, "fifo full\n");
29045 break;
29046 }
29047@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29048 h->Qdepth--;
29049
29050 /* Tell the controller execute command */
29051- h->access.submit_command(h, c);
29052+ h->access->submit_command(h, c);
29053
29054 /* Put job onto the completed Q */
29055 addQ(&h->cmpQ, c);
29056@@ -3443,17 +3445,17 @@ startio:
29057
29058 static inline unsigned long get_next_completion(ctlr_info_t *h)
29059 {
29060- return h->access.command_completed(h);
29061+ return h->access->command_completed(h);
29062 }
29063
29064 static inline int interrupt_pending(ctlr_info_t *h)
29065 {
29066- return h->access.intr_pending(h);
29067+ return h->access->intr_pending(h);
29068 }
29069
29070 static inline long interrupt_not_for_us(ctlr_info_t *h)
29071 {
29072- return ((h->access.intr_pending(h) == 0) ||
29073+ return ((h->access->intr_pending(h) == 0) ||
29074 (h->interrupts_enabled == 0));
29075 }
29076
29077@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29078 u32 a;
29079
29080 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29081- return h->access.command_completed(h);
29082+ return h->access->command_completed(h);
29083
29084 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29085 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29086@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29087 trans_support & CFGTBL_Trans_use_short_tags);
29088
29089 /* Change the access methods to the performant access methods */
29090- h->access = SA5_performant_access;
29091+ h->access = &SA5_performant_access;
29092 h->transMethod = CFGTBL_Trans_Performant;
29093
29094 return;
29095@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29096 if (prod_index < 0)
29097 return -ENODEV;
29098 h->product_name = products[prod_index].product_name;
29099- h->access = *(products[prod_index].access);
29100+ h->access = products[prod_index].access;
29101
29102 if (cciss_board_disabled(h)) {
29103 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29104@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29105 }
29106
29107 /* make sure the board interrupts are off */
29108- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29109+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29110 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29111 if (rc)
29112 goto clean2;
29113@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29114 * fake ones to scoop up any residual completions.
29115 */
29116 spin_lock_irqsave(&h->lock, flags);
29117- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29118+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29119 spin_unlock_irqrestore(&h->lock, flags);
29120 free_irq(h->intr[h->intr_mode], h);
29121 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29122@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29123 dev_info(&h->pdev->dev, "Board READY.\n");
29124 dev_info(&h->pdev->dev,
29125 "Waiting for stale completions to drain.\n");
29126- h->access.set_intr_mask(h, CCISS_INTR_ON);
29127+ h->access->set_intr_mask(h, CCISS_INTR_ON);
29128 msleep(10000);
29129- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29130+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29131
29132 rc = controller_reset_failed(h->cfgtable);
29133 if (rc)
29134@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29135 cciss_scsi_setup(h);
29136
29137 /* Turn the interrupts on so we can service requests */
29138- h->access.set_intr_mask(h, CCISS_INTR_ON);
29139+ h->access->set_intr_mask(h, CCISS_INTR_ON);
29140
29141 /* Get the firmware version */
29142 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29143@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29144 kfree(flush_buf);
29145 if (return_code != IO_OK)
29146 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29147- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29148+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29149 free_irq(h->intr[h->intr_mode], h);
29150 }
29151
29152diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29153index 7fda30e..eb5dfe0 100644
29154--- a/drivers/block/cciss.h
29155+++ b/drivers/block/cciss.h
29156@@ -101,7 +101,7 @@ struct ctlr_info
29157 /* information about each logical volume */
29158 drive_info_struct *drv[CISS_MAX_LUN];
29159
29160- struct access_method access;
29161+ struct access_method *access;
29162
29163 /* queue and queue Info */
29164 struct list_head reqQ;
29165diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29166index 9125bbe..eede5c8 100644
29167--- a/drivers/block/cpqarray.c
29168+++ b/drivers/block/cpqarray.c
29169@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29170 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29171 goto Enomem4;
29172 }
29173- hba[i]->access.set_intr_mask(hba[i], 0);
29174+ hba[i]->access->set_intr_mask(hba[i], 0);
29175 if (request_irq(hba[i]->intr, do_ida_intr,
29176 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29177 {
29178@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29179 add_timer(&hba[i]->timer);
29180
29181 /* Enable IRQ now that spinlock and rate limit timer are set up */
29182- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29183+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29184
29185 for(j=0; j<NWD; j++) {
29186 struct gendisk *disk = ida_gendisk[i][j];
29187@@ -694,7 +694,7 @@ DBGINFO(
29188 for(i=0; i<NR_PRODUCTS; i++) {
29189 if (board_id == products[i].board_id) {
29190 c->product_name = products[i].product_name;
29191- c->access = *(products[i].access);
29192+ c->access = products[i].access;
29193 break;
29194 }
29195 }
29196@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29197 hba[ctlr]->intr = intr;
29198 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29199 hba[ctlr]->product_name = products[j].product_name;
29200- hba[ctlr]->access = *(products[j].access);
29201+ hba[ctlr]->access = products[j].access;
29202 hba[ctlr]->ctlr = ctlr;
29203 hba[ctlr]->board_id = board_id;
29204 hba[ctlr]->pci_dev = NULL; /* not PCI */
29205@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29206
29207 while((c = h->reqQ) != NULL) {
29208 /* Can't do anything if we're busy */
29209- if (h->access.fifo_full(h) == 0)
29210+ if (h->access->fifo_full(h) == 0)
29211 return;
29212
29213 /* Get the first entry from the request Q */
29214@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29215 h->Qdepth--;
29216
29217 /* Tell the controller to do our bidding */
29218- h->access.submit_command(h, c);
29219+ h->access->submit_command(h, c);
29220
29221 /* Get onto the completion Q */
29222 addQ(&h->cmpQ, c);
29223@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29224 unsigned long flags;
29225 __u32 a,a1;
29226
29227- istat = h->access.intr_pending(h);
29228+ istat = h->access->intr_pending(h);
29229 /* Is this interrupt for us? */
29230 if (istat == 0)
29231 return IRQ_NONE;
29232@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29233 */
29234 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29235 if (istat & FIFO_NOT_EMPTY) {
29236- while((a = h->access.command_completed(h))) {
29237+ while((a = h->access->command_completed(h))) {
29238 a1 = a; a &= ~3;
29239 if ((c = h->cmpQ) == NULL)
29240 {
29241@@ -1449,11 +1449,11 @@ static int sendcmd(
29242 /*
29243 * Disable interrupt
29244 */
29245- info_p->access.set_intr_mask(info_p, 0);
29246+ info_p->access->set_intr_mask(info_p, 0);
29247 /* Make sure there is room in the command FIFO */
29248 /* Actually it should be completely empty at this time. */
29249 for (i = 200000; i > 0; i--) {
29250- temp = info_p->access.fifo_full(info_p);
29251+ temp = info_p->access->fifo_full(info_p);
29252 if (temp != 0) {
29253 break;
29254 }
29255@@ -1466,7 +1466,7 @@ DBG(
29256 /*
29257 * Send the cmd
29258 */
29259- info_p->access.submit_command(info_p, c);
29260+ info_p->access->submit_command(info_p, c);
29261 complete = pollcomplete(ctlr);
29262
29263 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29264@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29265 * we check the new geometry. Then turn interrupts back on when
29266 * we're done.
29267 */
29268- host->access.set_intr_mask(host, 0);
29269+ host->access->set_intr_mask(host, 0);
29270 getgeometry(ctlr);
29271- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29272+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29273
29274 for(i=0; i<NWD; i++) {
29275 struct gendisk *disk = ida_gendisk[ctlr][i];
29276@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29277 /* Wait (up to 2 seconds) for a command to complete */
29278
29279 for (i = 200000; i > 0; i--) {
29280- done = hba[ctlr]->access.command_completed(hba[ctlr]);
29281+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
29282 if (done == 0) {
29283 udelay(10); /* a short fixed delay */
29284 } else
29285diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29286index be73e9d..7fbf140 100644
29287--- a/drivers/block/cpqarray.h
29288+++ b/drivers/block/cpqarray.h
29289@@ -99,7 +99,7 @@ struct ctlr_info {
29290 drv_info_t drv[NWD];
29291 struct proc_dir_entry *proc;
29292
29293- struct access_method access;
29294+ struct access_method *access;
29295
29296 cmdlist_t *reqQ;
29297 cmdlist_t *cmpQ;
29298diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29299index b953cc7..e3dc580 100644
29300--- a/drivers/block/drbd/drbd_int.h
29301+++ b/drivers/block/drbd/drbd_int.h
29302@@ -735,7 +735,7 @@ struct drbd_request;
29303 struct drbd_epoch {
29304 struct list_head list;
29305 unsigned int barrier_nr;
29306- atomic_t epoch_size; /* increased on every request added. */
29307+ atomic_unchecked_t epoch_size; /* increased on every request added. */
29308 atomic_t active; /* increased on every req. added, and dec on every finished. */
29309 unsigned long flags;
29310 };
29311@@ -1116,7 +1116,7 @@ struct drbd_conf {
29312 void *int_dig_in;
29313 void *int_dig_vv;
29314 wait_queue_head_t seq_wait;
29315- atomic_t packet_seq;
29316+ atomic_unchecked_t packet_seq;
29317 unsigned int peer_seq;
29318 spinlock_t peer_seq_lock;
29319 unsigned int minor;
29320@@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29321
29322 static inline void drbd_tcp_cork(struct socket *sock)
29323 {
29324- int __user val = 1;
29325+ int val = 1;
29326 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29327- (char __user *)&val, sizeof(val));
29328+ (char __force_user *)&val, sizeof(val));
29329 }
29330
29331 static inline void drbd_tcp_uncork(struct socket *sock)
29332 {
29333- int __user val = 0;
29334+ int val = 0;
29335 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29336- (char __user *)&val, sizeof(val));
29337+ (char __force_user *)&val, sizeof(val));
29338 }
29339
29340 static inline void drbd_tcp_nodelay(struct socket *sock)
29341 {
29342- int __user val = 1;
29343+ int val = 1;
29344 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29345- (char __user *)&val, sizeof(val));
29346+ (char __force_user *)&val, sizeof(val));
29347 }
29348
29349 static inline void drbd_tcp_quickack(struct socket *sock)
29350 {
29351- int __user val = 2;
29352+ int val = 2;
29353 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29354- (char __user *)&val, sizeof(val));
29355+ (char __force_user *)&val, sizeof(val));
29356 }
29357
29358 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29359diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29360index f93a032..71c87bf 100644
29361--- a/drivers/block/drbd/drbd_main.c
29362+++ b/drivers/block/drbd/drbd_main.c
29363@@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29364 p.sector = sector;
29365 p.block_id = block_id;
29366 p.blksize = blksize;
29367- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29368+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29369
29370 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29371 return false;
29372@@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29373
29374 p.sector = cpu_to_be64(req->sector);
29375 p.block_id = (unsigned long)req;
29376- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29377+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29378
29379 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29380
29381@@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29382 atomic_set(&mdev->unacked_cnt, 0);
29383 atomic_set(&mdev->local_cnt, 0);
29384 atomic_set(&mdev->net_cnt, 0);
29385- atomic_set(&mdev->packet_seq, 0);
29386+ atomic_set_unchecked(&mdev->packet_seq, 0);
29387 atomic_set(&mdev->pp_in_use, 0);
29388 atomic_set(&mdev->pp_in_use_by_net, 0);
29389 atomic_set(&mdev->rs_sect_in, 0);
29390@@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29391 mdev->receiver.t_state);
29392
29393 /* no need to lock it, I'm the only thread alive */
29394- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29395- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29396+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29397+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29398 mdev->al_writ_cnt =
29399 mdev->bm_writ_cnt =
29400 mdev->read_cnt =
29401diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29402index edb490a..ecd69da 100644
29403--- a/drivers/block/drbd/drbd_nl.c
29404+++ b/drivers/block/drbd/drbd_nl.c
29405@@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29406 module_put(THIS_MODULE);
29407 }
29408
29409-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29410+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29411
29412 static unsigned short *
29413 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29414@@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29415 cn_reply->id.idx = CN_IDX_DRBD;
29416 cn_reply->id.val = CN_VAL_DRBD;
29417
29418- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29419+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29420 cn_reply->ack = 0; /* not used here. */
29421 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29422 (int)((char *)tl - (char *)reply->tag_list);
29423@@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29424 cn_reply->id.idx = CN_IDX_DRBD;
29425 cn_reply->id.val = CN_VAL_DRBD;
29426
29427- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29428+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29429 cn_reply->ack = 0; /* not used here. */
29430 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29431 (int)((char *)tl - (char *)reply->tag_list);
29432@@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29433 cn_reply->id.idx = CN_IDX_DRBD;
29434 cn_reply->id.val = CN_VAL_DRBD;
29435
29436- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29437+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29438 cn_reply->ack = 0; // not used here.
29439 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29440 (int)((char*)tl - (char*)reply->tag_list);
29441@@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29442 cn_reply->id.idx = CN_IDX_DRBD;
29443 cn_reply->id.val = CN_VAL_DRBD;
29444
29445- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29446+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29447 cn_reply->ack = 0; /* not used here. */
29448 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29449 (int)((char *)tl - (char *)reply->tag_list);
29450diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29451index c74ca2d..860c819 100644
29452--- a/drivers/block/drbd/drbd_receiver.c
29453+++ b/drivers/block/drbd/drbd_receiver.c
29454@@ -898,7 +898,7 @@ retry:
29455 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29456 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29457
29458- atomic_set(&mdev->packet_seq, 0);
29459+ atomic_set_unchecked(&mdev->packet_seq, 0);
29460 mdev->peer_seq = 0;
29461
29462 if (drbd_send_protocol(mdev) == -1)
29463@@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29464 do {
29465 next_epoch = NULL;
29466
29467- epoch_size = atomic_read(&epoch->epoch_size);
29468+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29469
29470 switch (ev & ~EV_CLEANUP) {
29471 case EV_PUT:
29472@@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29473 rv = FE_DESTROYED;
29474 } else {
29475 epoch->flags = 0;
29476- atomic_set(&epoch->epoch_size, 0);
29477+ atomic_set_unchecked(&epoch->epoch_size, 0);
29478 /* atomic_set(&epoch->active, 0); is already zero */
29479 if (rv == FE_STILL_LIVE)
29480 rv = FE_RECYCLED;
29481@@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29482 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29483 drbd_flush(mdev);
29484
29485- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29486+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29487 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29488 if (epoch)
29489 break;
29490 }
29491
29492 epoch = mdev->current_epoch;
29493- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29494+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29495
29496 D_ASSERT(atomic_read(&epoch->active) == 0);
29497 D_ASSERT(epoch->flags == 0);
29498@@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29499 }
29500
29501 epoch->flags = 0;
29502- atomic_set(&epoch->epoch_size, 0);
29503+ atomic_set_unchecked(&epoch->epoch_size, 0);
29504 atomic_set(&epoch->active, 0);
29505
29506 spin_lock(&mdev->epoch_lock);
29507- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29508+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29509 list_add(&epoch->list, &mdev->current_epoch->list);
29510 mdev->current_epoch = epoch;
29511 mdev->epochs++;
29512@@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29513 spin_unlock(&mdev->peer_seq_lock);
29514
29515 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29516- atomic_inc(&mdev->current_epoch->epoch_size);
29517+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29518 return drbd_drain_block(mdev, data_size);
29519 }
29520
29521@@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29522
29523 spin_lock(&mdev->epoch_lock);
29524 e->epoch = mdev->current_epoch;
29525- atomic_inc(&e->epoch->epoch_size);
29526+ atomic_inc_unchecked(&e->epoch->epoch_size);
29527 atomic_inc(&e->epoch->active);
29528 spin_unlock(&mdev->epoch_lock);
29529
29530@@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29531 D_ASSERT(list_empty(&mdev->done_ee));
29532
29533 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29534- atomic_set(&mdev->current_epoch->epoch_size, 0);
29535+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29536 D_ASSERT(list_empty(&mdev->current_epoch->list));
29537 }
29538
29539diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29540index 3bba655..6151b66 100644
29541--- a/drivers/block/loop.c
29542+++ b/drivers/block/loop.c
29543@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29544 mm_segment_t old_fs = get_fs();
29545
29546 set_fs(get_ds());
29547- bw = file->f_op->write(file, buf, len, &pos);
29548+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29549 set_fs(old_fs);
29550 if (likely(bw == len))
29551 return 0;
29552diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29553index ea6f632..eafb192 100644
29554--- a/drivers/char/Kconfig
29555+++ b/drivers/char/Kconfig
29556@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29557
29558 config DEVKMEM
29559 bool "/dev/kmem virtual device support"
29560- default y
29561+ default n
29562+ depends on !GRKERNSEC_KMEM
29563 help
29564 Say Y here if you want to support the /dev/kmem device. The
29565 /dev/kmem device is rarely used, but can be used for certain
29566@@ -581,6 +582,7 @@ config DEVPORT
29567 bool
29568 depends on !M68K
29569 depends on ISA || PCI
29570+ depends on !GRKERNSEC_KMEM
29571 default y
29572
29573 source "drivers/s390/char/Kconfig"
29574diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29575index 2e04433..22afc64 100644
29576--- a/drivers/char/agp/frontend.c
29577+++ b/drivers/char/agp/frontend.c
29578@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29579 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29580 return -EFAULT;
29581
29582- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29583+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29584 return -EFAULT;
29585
29586 client = agp_find_client_by_pid(reserve.pid);
29587diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29588index 21cb980..f15107c 100644
29589--- a/drivers/char/genrtc.c
29590+++ b/drivers/char/genrtc.c
29591@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29592 switch (cmd) {
29593
29594 case RTC_PLL_GET:
29595+ memset(&pll, 0, sizeof(pll));
29596 if (get_rtc_pll(&pll))
29597 return -EINVAL;
29598 else
29599diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29600index dfd7876..c0b0885 100644
29601--- a/drivers/char/hpet.c
29602+++ b/drivers/char/hpet.c
29603@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29604 }
29605
29606 static int
29607-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29608+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29609 struct hpet_info *info)
29610 {
29611 struct hpet_timer __iomem *timer;
29612diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29613index 2c29942..604c5ba 100644
29614--- a/drivers/char/ipmi/ipmi_msghandler.c
29615+++ b/drivers/char/ipmi/ipmi_msghandler.c
29616@@ -420,7 +420,7 @@ struct ipmi_smi {
29617 struct proc_dir_entry *proc_dir;
29618 char proc_dir_name[10];
29619
29620- atomic_t stats[IPMI_NUM_STATS];
29621+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29622
29623 /*
29624 * run_to_completion duplicate of smb_info, smi_info
29625@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29626
29627
29628 #define ipmi_inc_stat(intf, stat) \
29629- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29630+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29631 #define ipmi_get_stat(intf, stat) \
29632- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29633+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29634
29635 static int is_lan_addr(struct ipmi_addr *addr)
29636 {
29637@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29638 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29639 init_waitqueue_head(&intf->waitq);
29640 for (i = 0; i < IPMI_NUM_STATS; i++)
29641- atomic_set(&intf->stats[i], 0);
29642+ atomic_set_unchecked(&intf->stats[i], 0);
29643
29644 intf->proc_dir = NULL;
29645
29646diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29647index 83f85cf..279e63f 100644
29648--- a/drivers/char/ipmi/ipmi_si_intf.c
29649+++ b/drivers/char/ipmi/ipmi_si_intf.c
29650@@ -275,7 +275,7 @@ struct smi_info {
29651 unsigned char slave_addr;
29652
29653 /* Counters and things for the proc filesystem. */
29654- atomic_t stats[SI_NUM_STATS];
29655+ atomic_unchecked_t stats[SI_NUM_STATS];
29656
29657 struct task_struct *thread;
29658
29659@@ -284,9 +284,9 @@ struct smi_info {
29660 };
29661
29662 #define smi_inc_stat(smi, stat) \
29663- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29664+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29665 #define smi_get_stat(smi, stat) \
29666- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29667+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29668
29669 #define SI_MAX_PARMS 4
29670
29671@@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29672 atomic_set(&new_smi->req_events, 0);
29673 new_smi->run_to_completion = 0;
29674 for (i = 0; i < SI_NUM_STATS; i++)
29675- atomic_set(&new_smi->stats[i], 0);
29676+ atomic_set_unchecked(&new_smi->stats[i], 0);
29677
29678 new_smi->interrupt_disabled = 1;
29679 atomic_set(&new_smi->stop_operation, 0);
29680diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29681index 47ff7e4..0c7d340 100644
29682--- a/drivers/char/mbcs.c
29683+++ b/drivers/char/mbcs.c
29684@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29685 return 0;
29686 }
29687
29688-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29689+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29690 {
29691 .part_num = MBCS_PART_NUM,
29692 .mfg_num = MBCS_MFG_NUM,
29693diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29694index e5eedfa..fcab50ea 100644
29695--- a/drivers/char/mem.c
29696+++ b/drivers/char/mem.c
29697@@ -18,6 +18,7 @@
29698 #include <linux/raw.h>
29699 #include <linux/tty.h>
29700 #include <linux/capability.h>
29701+#include <linux/security.h>
29702 #include <linux/ptrace.h>
29703 #include <linux/device.h>
29704 #include <linux/highmem.h>
29705@@ -37,6 +38,10 @@
29706
29707 #define DEVPORT_MINOR 4
29708
29709+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29710+extern const struct file_operations grsec_fops;
29711+#endif
29712+
29713 static inline unsigned long size_inside_page(unsigned long start,
29714 unsigned long size)
29715 {
29716@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29717
29718 while (cursor < to) {
29719 if (!devmem_is_allowed(pfn)) {
29720+#ifdef CONFIG_GRKERNSEC_KMEM
29721+ gr_handle_mem_readwrite(from, to);
29722+#else
29723 printk(KERN_INFO
29724 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29725 current->comm, from, to);
29726+#endif
29727 return 0;
29728 }
29729 cursor += PAGE_SIZE;
29730@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29731 }
29732 return 1;
29733 }
29734+#elif defined(CONFIG_GRKERNSEC_KMEM)
29735+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29736+{
29737+ return 0;
29738+}
29739 #else
29740 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29741 {
29742@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29743
29744 while (count > 0) {
29745 unsigned long remaining;
29746+ char *temp;
29747
29748 sz = size_inside_page(p, count);
29749
29750@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29751 if (!ptr)
29752 return -EFAULT;
29753
29754- remaining = copy_to_user(buf, ptr, sz);
29755+#ifdef CONFIG_PAX_USERCOPY
29756+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29757+ if (!temp) {
29758+ unxlate_dev_mem_ptr(p, ptr);
29759+ return -ENOMEM;
29760+ }
29761+ memcpy(temp, ptr, sz);
29762+#else
29763+ temp = ptr;
29764+#endif
29765+
29766+ remaining = copy_to_user(buf, temp, sz);
29767+
29768+#ifdef CONFIG_PAX_USERCOPY
29769+ kfree(temp);
29770+#endif
29771+
29772 unxlate_dev_mem_ptr(p, ptr);
29773 if (remaining)
29774 return -EFAULT;
29775@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29776 size_t count, loff_t *ppos)
29777 {
29778 unsigned long p = *ppos;
29779- ssize_t low_count, read, sz;
29780+ ssize_t low_count, read, sz, err = 0;
29781 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29782- int err = 0;
29783
29784 read = 0;
29785 if (p < (unsigned long) high_memory) {
29786@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29787 }
29788 #endif
29789 while (low_count > 0) {
29790+ char *temp;
29791+
29792 sz = size_inside_page(p, low_count);
29793
29794 /*
29795@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29796 */
29797 kbuf = xlate_dev_kmem_ptr((char *)p);
29798
29799- if (copy_to_user(buf, kbuf, sz))
29800+#ifdef CONFIG_PAX_USERCOPY
29801+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29802+ if (!temp)
29803+ return -ENOMEM;
29804+ memcpy(temp, kbuf, sz);
29805+#else
29806+ temp = kbuf;
29807+#endif
29808+
29809+ err = copy_to_user(buf, temp, sz);
29810+
29811+#ifdef CONFIG_PAX_USERCOPY
29812+ kfree(temp);
29813+#endif
29814+
29815+ if (err)
29816 return -EFAULT;
29817 buf += sz;
29818 p += sz;
29819@@ -833,6 +880,9 @@ static const struct memdev {
29820 #ifdef CONFIG_CRASH_DUMP
29821 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29822 #endif
29823+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29824+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29825+#endif
29826 };
29827
29828 static int memory_open(struct inode *inode, struct file *filp)
29829diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29830index 9df78e2..01ba9ae 100644
29831--- a/drivers/char/nvram.c
29832+++ b/drivers/char/nvram.c
29833@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29834
29835 spin_unlock_irq(&rtc_lock);
29836
29837- if (copy_to_user(buf, contents, tmp - contents))
29838+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29839 return -EFAULT;
29840
29841 *ppos = i;
29842diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29843index 0a484b4..f48ccd1 100644
29844--- a/drivers/char/pcmcia/synclink_cs.c
29845+++ b/drivers/char/pcmcia/synclink_cs.c
29846@@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29847
29848 if (debug_level >= DEBUG_LEVEL_INFO)
29849 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29850- __FILE__,__LINE__, info->device_name, port->count);
29851+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29852
29853- WARN_ON(!port->count);
29854+ WARN_ON(!atomic_read(&port->count));
29855
29856 if (tty_port_close_start(port, tty, filp) == 0)
29857 goto cleanup;
29858@@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29859 cleanup:
29860 if (debug_level >= DEBUG_LEVEL_INFO)
29861 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29862- tty->driver->name, port->count);
29863+ tty->driver->name, atomic_read(&port->count));
29864 }
29865
29866 /* Wait until the transmitter is empty.
29867@@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29868
29869 if (debug_level >= DEBUG_LEVEL_INFO)
29870 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29871- __FILE__,__LINE__,tty->driver->name, port->count);
29872+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29873
29874 /* If port is closing, signal caller to try again */
29875 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29876@@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29877 goto cleanup;
29878 }
29879 spin_lock(&port->lock);
29880- port->count++;
29881+ atomic_inc(&port->count);
29882 spin_unlock(&port->lock);
29883 spin_unlock_irqrestore(&info->netlock, flags);
29884
29885- if (port->count == 1) {
29886+ if (atomic_read(&port->count) == 1) {
29887 /* 1st open on this device, init hardware */
29888 retval = startup(info, tty);
29889 if (retval < 0)
29890@@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29891 unsigned short new_crctype;
29892
29893 /* return error if TTY interface open */
29894- if (info->port.count)
29895+ if (atomic_read(&info->port.count))
29896 return -EBUSY;
29897
29898 switch (encoding)
29899@@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29900
29901 /* arbitrate between network and tty opens */
29902 spin_lock_irqsave(&info->netlock, flags);
29903- if (info->port.count != 0 || info->netcount != 0) {
29904+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29905 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29906 spin_unlock_irqrestore(&info->netlock, flags);
29907 return -EBUSY;
29908@@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29909 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29910
29911 /* return error if TTY interface open */
29912- if (info->port.count)
29913+ if (atomic_read(&info->port.count))
29914 return -EBUSY;
29915
29916 if (cmd != SIOCWANDEV)
29917diff --git a/drivers/char/random.c b/drivers/char/random.c
29918index b86eae9..4192a7a 100644
29919--- a/drivers/char/random.c
29920+++ b/drivers/char/random.c
29921@@ -272,8 +272,13 @@
29922 /*
29923 * Configuration information
29924 */
29925+#ifdef CONFIG_GRKERNSEC_RANDNET
29926+#define INPUT_POOL_WORDS 512
29927+#define OUTPUT_POOL_WORDS 128
29928+#else
29929 #define INPUT_POOL_WORDS 128
29930 #define OUTPUT_POOL_WORDS 32
29931+#endif
29932 #define SEC_XFER_SIZE 512
29933 #define EXTRACT_SIZE 10
29934
29935@@ -313,10 +318,17 @@ static struct poolinfo {
29936 int poolwords;
29937 int tap1, tap2, tap3, tap4, tap5;
29938 } poolinfo_table[] = {
29939+#ifdef CONFIG_GRKERNSEC_RANDNET
29940+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29941+ { 512, 411, 308, 208, 104, 1 },
29942+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29943+ { 128, 103, 76, 51, 25, 1 },
29944+#else
29945 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29946 { 128, 103, 76, 51, 25, 1 },
29947 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29948 { 32, 26, 20, 14, 7, 1 },
29949+#endif
29950 #if 0
29951 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29952 { 2048, 1638, 1231, 819, 411, 1 },
29953@@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29954 input_rotate += i ? 7 : 14;
29955 }
29956
29957- ACCESS_ONCE(r->input_rotate) = input_rotate;
29958- ACCESS_ONCE(r->add_ptr) = i;
29959+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29960+ ACCESS_ONCE_RW(r->add_ptr) = i;
29961 smp_wmb();
29962
29963 if (out)
29964@@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29965 }
29966 #endif
29967
29968+#ifdef CONFIG_PAX_LATENT_ENTROPY
29969+u64 latent_entropy;
29970+
29971+__init void transfer_latent_entropy(void)
29972+{
29973+ mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29974+ mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29975+// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29976+}
29977+#endif
29978+
29979 /*********************************************************************
29980 *
29981 * Entropy extraction routines
29982@@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29983
29984 extract_buf(r, tmp);
29985 i = min_t(int, nbytes, EXTRACT_SIZE);
29986- if (copy_to_user(buf, tmp, i)) {
29987+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29988 ret = -EFAULT;
29989 break;
29990 }
29991@@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29992 #include <linux/sysctl.h>
29993
29994 static int min_read_thresh = 8, min_write_thresh;
29995-static int max_read_thresh = INPUT_POOL_WORDS * 32;
29996+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29997 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29998 static char sysctl_bootid[16];
29999
30000diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30001index f877805..403375a 100644
30002--- a/drivers/char/sonypi.c
30003+++ b/drivers/char/sonypi.c
30004@@ -54,6 +54,7 @@
30005
30006 #include <asm/uaccess.h>
30007 #include <asm/io.h>
30008+#include <asm/local.h>
30009
30010 #include <linux/sonypi.h>
30011
30012@@ -490,7 +491,7 @@ static struct sonypi_device {
30013 spinlock_t fifo_lock;
30014 wait_queue_head_t fifo_proc_list;
30015 struct fasync_struct *fifo_async;
30016- int open_count;
30017+ local_t open_count;
30018 int model;
30019 struct input_dev *input_jog_dev;
30020 struct input_dev *input_key_dev;
30021@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30022 static int sonypi_misc_release(struct inode *inode, struct file *file)
30023 {
30024 mutex_lock(&sonypi_device.lock);
30025- sonypi_device.open_count--;
30026+ local_dec(&sonypi_device.open_count);
30027 mutex_unlock(&sonypi_device.lock);
30028 return 0;
30029 }
30030@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30031 {
30032 mutex_lock(&sonypi_device.lock);
30033 /* Flush input queue on first open */
30034- if (!sonypi_device.open_count)
30035+ if (!local_read(&sonypi_device.open_count))
30036 kfifo_reset(&sonypi_device.fifo);
30037- sonypi_device.open_count++;
30038+ local_inc(&sonypi_device.open_count);
30039 mutex_unlock(&sonypi_device.lock);
30040
30041 return 0;
30042diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30043index 817f0ee..cd3b75d 100644
30044--- a/drivers/char/tpm/tpm.c
30045+++ b/drivers/char/tpm/tpm.c
30046@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30047 chip->vendor.req_complete_val)
30048 goto out_recv;
30049
30050- if ((status == chip->vendor.req_canceled)) {
30051+ if (status == chip->vendor.req_canceled) {
30052 dev_err(chip->dev, "Operation Canceled\n");
30053 rc = -ECANCELED;
30054 goto out;
30055diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30056index 0636520..169c1d0 100644
30057--- a/drivers/char/tpm/tpm_bios.c
30058+++ b/drivers/char/tpm/tpm_bios.c
30059@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30060 event = addr;
30061
30062 if ((event->event_type == 0 && event->event_size == 0) ||
30063- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30064+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30065 return NULL;
30066
30067 return addr;
30068@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30069 return NULL;
30070
30071 if ((event->event_type == 0 && event->event_size == 0) ||
30072- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30073+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30074 return NULL;
30075
30076 (*pos)++;
30077@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30078 int i;
30079
30080 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30081- seq_putc(m, data[i]);
30082+ if (!seq_putc(m, data[i]))
30083+ return -EFAULT;
30084
30085 return 0;
30086 }
30087@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30088 log->bios_event_log_end = log->bios_event_log + len;
30089
30090 virt = acpi_os_map_memory(start, len);
30091+ if (!virt) {
30092+ kfree(log->bios_event_log);
30093+ log->bios_event_log = NULL;
30094+ return -EFAULT;
30095+ }
30096
30097- memcpy(log->bios_event_log, virt, len);
30098+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30099
30100 acpi_os_unmap_memory(virt, len);
30101 return 0;
30102diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30103index cdf2f54..e55c197 100644
30104--- a/drivers/char/virtio_console.c
30105+++ b/drivers/char/virtio_console.c
30106@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30107 if (to_user) {
30108 ssize_t ret;
30109
30110- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30111+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30112 if (ret)
30113 return -EFAULT;
30114 } else {
30115@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30116 if (!port_has_data(port) && !port->host_connected)
30117 return 0;
30118
30119- return fill_readbuf(port, ubuf, count, true);
30120+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30121 }
30122
30123 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30124diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30125index e164c55..3aabb50 100644
30126--- a/drivers/edac/edac_pci_sysfs.c
30127+++ b/drivers/edac/edac_pci_sysfs.c
30128@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30129 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30130 static int edac_pci_poll_msec = 1000; /* one second workq period */
30131
30132-static atomic_t pci_parity_count = ATOMIC_INIT(0);
30133-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30134+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30135+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30136
30137 static struct kobject *edac_pci_top_main_kobj;
30138 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30139@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30140 edac_printk(KERN_CRIT, EDAC_PCI,
30141 "Signaled System Error on %s\n",
30142 pci_name(dev));
30143- atomic_inc(&pci_nonparity_count);
30144+ atomic_inc_unchecked(&pci_nonparity_count);
30145 }
30146
30147 if (status & (PCI_STATUS_PARITY)) {
30148@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30149 "Master Data Parity Error on %s\n",
30150 pci_name(dev));
30151
30152- atomic_inc(&pci_parity_count);
30153+ atomic_inc_unchecked(&pci_parity_count);
30154 }
30155
30156 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30157@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30158 "Detected Parity Error on %s\n",
30159 pci_name(dev));
30160
30161- atomic_inc(&pci_parity_count);
30162+ atomic_inc_unchecked(&pci_parity_count);
30163 }
30164 }
30165
30166@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30167 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30168 "Signaled System Error on %s\n",
30169 pci_name(dev));
30170- atomic_inc(&pci_nonparity_count);
30171+ atomic_inc_unchecked(&pci_nonparity_count);
30172 }
30173
30174 if (status & (PCI_STATUS_PARITY)) {
30175@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30176 "Master Data Parity Error on "
30177 "%s\n", pci_name(dev));
30178
30179- atomic_inc(&pci_parity_count);
30180+ atomic_inc_unchecked(&pci_parity_count);
30181 }
30182
30183 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30184@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30185 "Detected Parity Error on %s\n",
30186 pci_name(dev));
30187
30188- atomic_inc(&pci_parity_count);
30189+ atomic_inc_unchecked(&pci_parity_count);
30190 }
30191 }
30192 }
30193@@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30194 if (!check_pci_errors)
30195 return;
30196
30197- before_count = atomic_read(&pci_parity_count);
30198+ before_count = atomic_read_unchecked(&pci_parity_count);
30199
30200 /* scan all PCI devices looking for a Parity Error on devices and
30201 * bridges.
30202@@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30203 /* Only if operator has selected panic on PCI Error */
30204 if (edac_pci_get_panic_on_pe()) {
30205 /* If the count is different 'after' from 'before' */
30206- if (before_count != atomic_read(&pci_parity_count))
30207+ if (before_count != atomic_read_unchecked(&pci_parity_count))
30208 panic("EDAC: PCI Parity Error");
30209 }
30210 }
30211diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30212index 8c87a5e..a19cbd7 100644
30213--- a/drivers/edac/mce_amd.h
30214+++ b/drivers/edac/mce_amd.h
30215@@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30216 struct amd_decoder_ops {
30217 bool (*dc_mce)(u16, u8);
30218 bool (*ic_mce)(u16, u8);
30219-};
30220+} __no_const;
30221
30222 void amd_report_gart_errors(bool);
30223 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30224diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30225index 57ea7f4..789e3c3 100644
30226--- a/drivers/firewire/core-card.c
30227+++ b/drivers/firewire/core-card.c
30228@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30229
30230 void fw_core_remove_card(struct fw_card *card)
30231 {
30232- struct fw_card_driver dummy_driver = dummy_driver_template;
30233+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
30234
30235 card->driver->update_phy_reg(card, 4,
30236 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30237diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30238index 2783f69..9f4b0cc 100644
30239--- a/drivers/firewire/core-cdev.c
30240+++ b/drivers/firewire/core-cdev.c
30241@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30242 int ret;
30243
30244 if ((request->channels == 0 && request->bandwidth == 0) ||
30245- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30246- request->bandwidth < 0)
30247+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30248 return -EINVAL;
30249
30250 r = kmalloc(sizeof(*r), GFP_KERNEL);
30251diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30252index 87d6f2d..5bf9d90 100644
30253--- a/drivers/firewire/core-transaction.c
30254+++ b/drivers/firewire/core-transaction.c
30255@@ -37,6 +37,7 @@
30256 #include <linux/timer.h>
30257 #include <linux/types.h>
30258 #include <linux/workqueue.h>
30259+#include <linux/sched.h>
30260
30261 #include <asm/byteorder.h>
30262
30263diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30264index 515a42c..5ecf3ba 100644
30265--- a/drivers/firewire/core.h
30266+++ b/drivers/firewire/core.h
30267@@ -111,6 +111,7 @@ struct fw_card_driver {
30268
30269 int (*stop_iso)(struct fw_iso_context *ctx);
30270 };
30271+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30272
30273 void fw_card_initialize(struct fw_card *card,
30274 const struct fw_card_driver *driver, struct device *device);
30275diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30276index b298158..7ed8432 100644
30277--- a/drivers/firmware/dmi_scan.c
30278+++ b/drivers/firmware/dmi_scan.c
30279@@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30280 }
30281 }
30282 else {
30283- /*
30284- * no iounmap() for that ioremap(); it would be a no-op, but
30285- * it's so early in setup that sucker gets confused into doing
30286- * what it shouldn't if we actually call it.
30287- */
30288 p = dmi_ioremap(0xF0000, 0x10000);
30289 if (p == NULL)
30290 goto error;
30291@@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30292 if (buf == NULL)
30293 return -1;
30294
30295- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30296+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30297
30298 iounmap(buf);
30299 return 0;
30300diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30301index 82d5c20..44a7177 100644
30302--- a/drivers/gpio/gpio-vr41xx.c
30303+++ b/drivers/gpio/gpio-vr41xx.c
30304@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30305 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30306 maskl, pendl, maskh, pendh);
30307
30308- atomic_inc(&irq_err_count);
30309+ atomic_inc_unchecked(&irq_err_count);
30310
30311 return -EINVAL;
30312 }
30313diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30314index 3252e70..b5314ace 100644
30315--- a/drivers/gpu/drm/drm_crtc_helper.c
30316+++ b/drivers/gpu/drm/drm_crtc_helper.c
30317@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30318 struct drm_crtc *tmp;
30319 int crtc_mask = 1;
30320
30321- WARN(!crtc, "checking null crtc?\n");
30322+ BUG_ON(!crtc);
30323
30324 dev = crtc->dev;
30325
30326diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30327index 9238de4..a27c72a 100644
30328--- a/drivers/gpu/drm/drm_drv.c
30329+++ b/drivers/gpu/drm/drm_drv.c
30330@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30331 /**
30332 * Copy and IOCTL return string to user space
30333 */
30334-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30335+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30336 {
30337 int len;
30338
30339@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30340 return -ENODEV;
30341
30342 atomic_inc(&dev->ioctl_count);
30343- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30344+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30345 ++file_priv->ioctl_count;
30346
30347 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30348diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30349index 5062eec..4e3e51f 100644
30350--- a/drivers/gpu/drm/drm_fops.c
30351+++ b/drivers/gpu/drm/drm_fops.c
30352@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30353 }
30354
30355 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30356- atomic_set(&dev->counts[i], 0);
30357+ atomic_set_unchecked(&dev->counts[i], 0);
30358
30359 dev->sigdata.lock = NULL;
30360
30361@@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct file *filp)
30362
30363 retcode = drm_open_helper(inode, filp, dev);
30364 if (!retcode) {
30365- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30366- if (!dev->open_count++)
30367+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30368+ if (local_inc_return(&dev->open_count) == 1)
30369 retcode = drm_setup(dev);
30370 }
30371 if (!retcode) {
30372@@ -422,7 +422,7 @@ int drm_release(struct inode *inode, struct file *filp)
30373
30374 mutex_lock(&drm_global_mutex);
30375
30376- DRM_DEBUG("open_count = %d\n", dev->open_count);
30377+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30378
30379 if (dev->driver->preclose)
30380 dev->driver->preclose(dev, file_priv);
30381@@ -431,10 +431,10 @@ int drm_release(struct inode *inode, struct file *filp)
30382 * Begin inline drm_release
30383 */
30384
30385- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30386+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30387 task_pid_nr(current),
30388 (long)old_encode_dev(file_priv->minor->device),
30389- dev->open_count);
30390+ local_read(&dev->open_count));
30391
30392 /* Release any auth tokens that might point to this file_priv,
30393 (do that under the drm_global_mutex) */
30394@@ -530,8 +530,8 @@ int drm_release(struct inode *inode, struct file *filp)
30395 * End inline drm_release
30396 */
30397
30398- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30399- if (!--dev->open_count) {
30400+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30401+ if (local_dec_and_test(&dev->open_count)) {
30402 if (atomic_read(&dev->ioctl_count)) {
30403 DRM_ERROR("Device busy: %d\n",
30404 atomic_read(&dev->ioctl_count));
30405diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30406index c87dc96..326055d 100644
30407--- a/drivers/gpu/drm/drm_global.c
30408+++ b/drivers/gpu/drm/drm_global.c
30409@@ -36,7 +36,7 @@
30410 struct drm_global_item {
30411 struct mutex mutex;
30412 void *object;
30413- int refcount;
30414+ atomic_t refcount;
30415 };
30416
30417 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30418@@ -49,7 +49,7 @@ void drm_global_init(void)
30419 struct drm_global_item *item = &glob[i];
30420 mutex_init(&item->mutex);
30421 item->object = NULL;
30422- item->refcount = 0;
30423+ atomic_set(&item->refcount, 0);
30424 }
30425 }
30426
30427@@ -59,7 +59,7 @@ void drm_global_release(void)
30428 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30429 struct drm_global_item *item = &glob[i];
30430 BUG_ON(item->object != NULL);
30431- BUG_ON(item->refcount != 0);
30432+ BUG_ON(atomic_read(&item->refcount) != 0);
30433 }
30434 }
30435
30436@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30437 void *object;
30438
30439 mutex_lock(&item->mutex);
30440- if (item->refcount == 0) {
30441+ if (atomic_read(&item->refcount) == 0) {
30442 item->object = kzalloc(ref->size, GFP_KERNEL);
30443 if (unlikely(item->object == NULL)) {
30444 ret = -ENOMEM;
30445@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30446 goto out_err;
30447
30448 }
30449- ++item->refcount;
30450+ atomic_inc(&item->refcount);
30451 ref->object = item->object;
30452 object = item->object;
30453 mutex_unlock(&item->mutex);
30454@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30455 struct drm_global_item *item = &glob[ref->global_type];
30456
30457 mutex_lock(&item->mutex);
30458- BUG_ON(item->refcount == 0);
30459+ BUG_ON(atomic_read(&item->refcount) == 0);
30460 BUG_ON(ref->object != item->object);
30461- if (--item->refcount == 0) {
30462+ if (atomic_dec_and_test(&item->refcount)) {
30463 ref->release(ref);
30464 item->object = NULL;
30465 }
30466diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30467index 8928edb..0c79258 100644
30468--- a/drivers/gpu/drm/drm_info.c
30469+++ b/drivers/gpu/drm/drm_info.c
30470@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30471 struct drm_local_map *map;
30472 struct drm_map_list *r_list;
30473
30474- /* Hardcoded from _DRM_FRAME_BUFFER,
30475- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30476- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30477- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30478+ static const char * const types[] = {
30479+ [_DRM_FRAME_BUFFER] = "FB",
30480+ [_DRM_REGISTERS] = "REG",
30481+ [_DRM_SHM] = "SHM",
30482+ [_DRM_AGP] = "AGP",
30483+ [_DRM_SCATTER_GATHER] = "SG",
30484+ [_DRM_CONSISTENT] = "PCI",
30485+ [_DRM_GEM] = "GEM" };
30486 const char *type;
30487 int i;
30488
30489@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30490 map = r_list->map;
30491 if (!map)
30492 continue;
30493- if (map->type < 0 || map->type > 5)
30494+ if (map->type >= ARRAY_SIZE(types))
30495 type = "??";
30496 else
30497 type = types[map->type];
30498@@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30499 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30500 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30501 vma->vm_flags & VM_IO ? 'i' : '-',
30502+#ifdef CONFIG_GRKERNSEC_HIDESYM
30503+ 0);
30504+#else
30505 vma->vm_pgoff);
30506+#endif
30507
30508 #if defined(__i386__)
30509 pgprot = pgprot_val(vma->vm_page_prot);
30510diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30511index 637fcc3..e890b33 100644
30512--- a/drivers/gpu/drm/drm_ioc32.c
30513+++ b/drivers/gpu/drm/drm_ioc32.c
30514@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30515 request = compat_alloc_user_space(nbytes);
30516 if (!access_ok(VERIFY_WRITE, request, nbytes))
30517 return -EFAULT;
30518- list = (struct drm_buf_desc *) (request + 1);
30519+ list = (struct drm_buf_desc __user *) (request + 1);
30520
30521 if (__put_user(count, &request->count)
30522 || __put_user(list, &request->list))
30523@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30524 request = compat_alloc_user_space(nbytes);
30525 if (!access_ok(VERIFY_WRITE, request, nbytes))
30526 return -EFAULT;
30527- list = (struct drm_buf_pub *) (request + 1);
30528+ list = (struct drm_buf_pub __user *) (request + 1);
30529
30530 if (__put_user(count, &request->count)
30531 || __put_user(list, &request->list))
30532diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30533index 64a62c6..ceab35e 100644
30534--- a/drivers/gpu/drm/drm_ioctl.c
30535+++ b/drivers/gpu/drm/drm_ioctl.c
30536@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30537 stats->data[i].value =
30538 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30539 else
30540- stats->data[i].value = atomic_read(&dev->counts[i]);
30541+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30542 stats->data[i].type = dev->types[i];
30543 }
30544
30545diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30546index 3203955..c8090af 100644
30547--- a/drivers/gpu/drm/drm_lock.c
30548+++ b/drivers/gpu/drm/drm_lock.c
30549@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30550 if (drm_lock_take(&master->lock, lock->context)) {
30551 master->lock.file_priv = file_priv;
30552 master->lock.lock_time = jiffies;
30553- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30554+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30555 break; /* Got lock */
30556 }
30557
30558@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30559 return -EINVAL;
30560 }
30561
30562- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30563+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30564
30565 if (drm_lock_free(&master->lock, lock->context)) {
30566 /* FIXME: Should really bail out here. */
30567diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30568index 21bcd4a..8e074e0 100644
30569--- a/drivers/gpu/drm/drm_stub.c
30570+++ b/drivers/gpu/drm/drm_stub.c
30571@@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30572
30573 drm_device_set_unplugged(dev);
30574
30575- if (dev->open_count == 0) {
30576+ if (local_read(&dev->open_count) == 0) {
30577 drm_put_dev(dev);
30578 }
30579 mutex_unlock(&drm_global_mutex);
30580diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30581index 463ec68..f5bd2b5 100644
30582--- a/drivers/gpu/drm/i810/i810_dma.c
30583+++ b/drivers/gpu/drm/i810/i810_dma.c
30584@@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30585 dma->buflist[vertex->idx],
30586 vertex->discard, vertex->used);
30587
30588- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30589- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30590+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30591+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30592 sarea_priv->last_enqueue = dev_priv->counter - 1;
30593 sarea_priv->last_dispatch = (int)hw_status[5];
30594
30595@@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30596 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30597 mc->last_render);
30598
30599- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30600- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30601+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30602+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30603 sarea_priv->last_enqueue = dev_priv->counter - 1;
30604 sarea_priv->last_dispatch = (int)hw_status[5];
30605
30606diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30607index 6e0acad..93c8289 100644
30608--- a/drivers/gpu/drm/i810/i810_drv.h
30609+++ b/drivers/gpu/drm/i810/i810_drv.h
30610@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30611 int page_flipping;
30612
30613 wait_queue_head_t irq_queue;
30614- atomic_t irq_received;
30615- atomic_t irq_emitted;
30616+ atomic_unchecked_t irq_received;
30617+ atomic_unchecked_t irq_emitted;
30618
30619 int front_offset;
30620 } drm_i810_private_t;
30621diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30622index 359f6e8..ada68fd 100644
30623--- a/drivers/gpu/drm/i915/i915_debugfs.c
30624+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30625@@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30626 I915_READ(GTIMR));
30627 }
30628 seq_printf(m, "Interrupts received: %d\n",
30629- atomic_read(&dev_priv->irq_received));
30630+ atomic_read_unchecked(&dev_priv->irq_received));
30631 for (i = 0; i < I915_NUM_RINGS; i++) {
30632 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30633 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30634diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30635index 914c0df..d47d380 100644
30636--- a/drivers/gpu/drm/i915/i915_dma.c
30637+++ b/drivers/gpu/drm/i915/i915_dma.c
30638@@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30639 bool can_switch;
30640
30641 spin_lock(&dev->count_lock);
30642- can_switch = (dev->open_count == 0);
30643+ can_switch = (local_read(&dev->open_count) == 0);
30644 spin_unlock(&dev->count_lock);
30645 return can_switch;
30646 }
30647diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30648index 627fe35..c9a7346 100644
30649--- a/drivers/gpu/drm/i915/i915_drv.h
30650+++ b/drivers/gpu/drm/i915/i915_drv.h
30651@@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30652 /* render clock increase/decrease */
30653 /* display clock increase/decrease */
30654 /* pll clock increase/decrease */
30655-};
30656+} __no_const;
30657
30658 struct drm_i915_gt_funcs {
30659 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30660 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30661-};
30662+} __no_const;
30663
30664 struct intel_device_info {
30665 u8 gen;
30666@@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30667 int current_page;
30668 int page_flipping;
30669
30670- atomic_t irq_received;
30671+ atomic_unchecked_t irq_received;
30672
30673 /* protects the irq masks */
30674 spinlock_t irq_lock;
30675@@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30676 * will be page flipped away on the next vblank. When it
30677 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30678 */
30679- atomic_t pending_flip;
30680+ atomic_unchecked_t pending_flip;
30681 };
30682
30683 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30684@@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30685 struct drm_i915_private *dev_priv, unsigned port);
30686 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30687 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30688-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30689+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30690 {
30691 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30692 }
30693diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30694index ff2819e..6b5997b 100644
30695--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30696+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30697@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30698 i915_gem_clflush_object(obj);
30699
30700 if (obj->base.pending_write_domain)
30701- cd->flips |= atomic_read(&obj->pending_flip);
30702+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30703
30704 /* The actual obj->write_domain will be updated with
30705 * pending_write_domain after we emit the accumulated flush for all
30706@@ -906,9 +906,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30707
30708 static int
30709 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30710- int count)
30711+ unsigned int count)
30712 {
30713- int i;
30714+ unsigned int i;
30715
30716 for (i = 0; i < count; i++) {
30717 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30718diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30719index 5249640..efc8740 100644
30720--- a/drivers/gpu/drm/i915/i915_irq.c
30721+++ b/drivers/gpu/drm/i915/i915_irq.c
30722@@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30723 u32 pipe_stats[I915_MAX_PIPES];
30724 bool blc_event;
30725
30726- atomic_inc(&dev_priv->irq_received);
30727+ atomic_inc_unchecked(&dev_priv->irq_received);
30728
30729 while (true) {
30730 iir = I915_READ(VLV_IIR);
30731@@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30732 irqreturn_t ret = IRQ_NONE;
30733 int i;
30734
30735- atomic_inc(&dev_priv->irq_received);
30736+ atomic_inc_unchecked(&dev_priv->irq_received);
30737
30738 /* disable master interrupt before clearing iir */
30739 de_ier = I915_READ(DEIER);
30740@@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30741 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30742 u32 hotplug_mask;
30743
30744- atomic_inc(&dev_priv->irq_received);
30745+ atomic_inc_unchecked(&dev_priv->irq_received);
30746
30747 /* disable master interrupt before clearing iir */
30748 de_ier = I915_READ(DEIER);
30749@@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30750 {
30751 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30752
30753- atomic_set(&dev_priv->irq_received, 0);
30754+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30755
30756 I915_WRITE(HWSTAM, 0xeffe);
30757
30758@@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30759 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30760 int pipe;
30761
30762- atomic_set(&dev_priv->irq_received, 0);
30763+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30764
30765 /* VLV magic */
30766 I915_WRITE(VLV_IMR, 0);
30767@@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30768 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30769 int pipe;
30770
30771- atomic_set(&dev_priv->irq_received, 0);
30772+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30773
30774 for_each_pipe(pipe)
30775 I915_WRITE(PIPESTAT(pipe), 0);
30776@@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30777 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30778 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30779
30780- atomic_inc(&dev_priv->irq_received);
30781+ atomic_inc_unchecked(&dev_priv->irq_received);
30782
30783 iir = I915_READ16(IIR);
30784 if (iir == 0)
30785@@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30786 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30787 int pipe;
30788
30789- atomic_set(&dev_priv->irq_received, 0);
30790+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30791
30792 if (I915_HAS_HOTPLUG(dev)) {
30793 I915_WRITE(PORT_HOTPLUG_EN, 0);
30794@@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30795 };
30796 int pipe, ret = IRQ_NONE;
30797
30798- atomic_inc(&dev_priv->irq_received);
30799+ atomic_inc_unchecked(&dev_priv->irq_received);
30800
30801 iir = I915_READ(IIR);
30802 do {
30803@@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30804 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30805 int pipe;
30806
30807- atomic_set(&dev_priv->irq_received, 0);
30808+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30809
30810 I915_WRITE(PORT_HOTPLUG_EN, 0);
30811 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
30812@@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30813 int irq_received;
30814 int ret = IRQ_NONE, pipe;
30815
30816- atomic_inc(&dev_priv->irq_received);
30817+ atomic_inc_unchecked(&dev_priv->irq_received);
30818
30819 iir = I915_READ(IIR);
30820
30821diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30822index c040aee..813d84b 100644
30823--- a/drivers/gpu/drm/i915/intel_display.c
30824+++ b/drivers/gpu/drm/i915/intel_display.c
30825@@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30826
30827 wait_event(dev_priv->pending_flip_queue,
30828 atomic_read(&dev_priv->mm.wedged) ||
30829- atomic_read(&obj->pending_flip) == 0);
30830+ atomic_read_unchecked(&obj->pending_flip) == 0);
30831
30832 /* Big Hammer, we also need to ensure that any pending
30833 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30834@@ -6147,9 +6147,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30835
30836 obj = work->old_fb_obj;
30837
30838- atomic_clear_mask(1 << intel_crtc->plane,
30839- &obj->pending_flip.counter);
30840- if (atomic_read(&obj->pending_flip) == 0)
30841+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30842+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
30843 wake_up(&dev_priv->pending_flip_queue);
30844
30845 schedule_work(&work->work);
30846@@ -6495,7 +6494,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30847 /* Block clients from rendering to the new back buffer until
30848 * the flip occurs and the object is no longer visible.
30849 */
30850- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30851+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30852
30853 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30854 if (ret)
30855@@ -6510,7 +6509,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30856 return 0;
30857
30858 cleanup_pending:
30859- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30860+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30861 drm_gem_object_unreference(&work->old_fb_obj->base);
30862 drm_gem_object_unreference(&obj->base);
30863 mutex_unlock(&dev->struct_mutex);
30864diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30865index 54558a0..2d97005 100644
30866--- a/drivers/gpu/drm/mga/mga_drv.h
30867+++ b/drivers/gpu/drm/mga/mga_drv.h
30868@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30869 u32 clear_cmd;
30870 u32 maccess;
30871
30872- atomic_t vbl_received; /**< Number of vblanks received. */
30873+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30874 wait_queue_head_t fence_queue;
30875- atomic_t last_fence_retired;
30876+ atomic_unchecked_t last_fence_retired;
30877 u32 next_fence_to_post;
30878
30879 unsigned int fb_cpp;
30880diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30881index 2581202..f230a8d9 100644
30882--- a/drivers/gpu/drm/mga/mga_irq.c
30883+++ b/drivers/gpu/drm/mga/mga_irq.c
30884@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30885 if (crtc != 0)
30886 return 0;
30887
30888- return atomic_read(&dev_priv->vbl_received);
30889+ return atomic_read_unchecked(&dev_priv->vbl_received);
30890 }
30891
30892
30893@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30894 /* VBLANK interrupt */
30895 if (status & MGA_VLINEPEN) {
30896 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30897- atomic_inc(&dev_priv->vbl_received);
30898+ atomic_inc_unchecked(&dev_priv->vbl_received);
30899 drm_handle_vblank(dev, 0);
30900 handled = 1;
30901 }
30902@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30903 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30904 MGA_WRITE(MGA_PRIMEND, prim_end);
30905
30906- atomic_inc(&dev_priv->last_fence_retired);
30907+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
30908 DRM_WAKEUP(&dev_priv->fence_queue);
30909 handled = 1;
30910 }
30911@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30912 * using fences.
30913 */
30914 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30915- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30916+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30917 - *sequence) <= (1 << 23)));
30918
30919 *sequence = cur_fence;
30920diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30921index a0a3fe3..209bf10 100644
30922--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30923+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30924@@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30925 struct bit_table {
30926 const char id;
30927 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30928-};
30929+} __no_const;
30930
30931 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30932
30933diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30934index 4f2cc95..9c6c510 100644
30935--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30936+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30937@@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30938 u32 handle, u16 class);
30939 void (*set_tile_region)(struct drm_device *dev, int i);
30940 void (*tlb_flush)(struct drm_device *, int engine);
30941-};
30942+} __no_const;
30943
30944 struct nouveau_instmem_engine {
30945 void *priv;
30946@@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30947 struct nouveau_mc_engine {
30948 int (*init)(struct drm_device *dev);
30949 void (*takedown)(struct drm_device *dev);
30950-};
30951+} __no_const;
30952
30953 struct nouveau_timer_engine {
30954 int (*init)(struct drm_device *dev);
30955 void (*takedown)(struct drm_device *dev);
30956 uint64_t (*read)(struct drm_device *dev);
30957-};
30958+} __no_const;
30959
30960 struct nouveau_fb_engine {
30961 int num_tiles;
30962@@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30963 void (*put)(struct drm_device *, struct nouveau_mem **);
30964
30965 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30966-};
30967+} __no_const;
30968
30969 struct nouveau_engine {
30970 struct nouveau_instmem_engine instmem;
30971@@ -693,7 +693,7 @@ struct drm_nouveau_private {
30972 struct drm_global_reference mem_global_ref;
30973 struct ttm_bo_global_ref bo_global_ref;
30974 struct ttm_bo_device bdev;
30975- atomic_t validate_sequence;
30976+ atomic_unchecked_t validate_sequence;
30977 int (*move)(struct nouveau_channel *,
30978 struct ttm_buffer_object *,
30979 struct ttm_mem_reg *, struct ttm_mem_reg *);
30980diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30981index af7cfb8..aadc2a3 100644
30982--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30983+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30984@@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30985 int trycnt = 0;
30986 int ret, i;
30987
30988- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30989+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30990 retry:
30991 if (++trycnt > 100000) {
30992 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30993diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30994index c610144..97440e2 100644
30995--- a/drivers/gpu/drm/nouveau/nouveau_state.c
30996+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30997@@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30998 bool can_switch;
30999
31000 spin_lock(&dev->count_lock);
31001- can_switch = (dev->open_count == 0);
31002+ can_switch = (local_read(&dev->open_count) == 0);
31003 spin_unlock(&dev->count_lock);
31004 return can_switch;
31005 }
31006diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31007index 93240bd..c490f60 100644
31008--- a/drivers/gpu/drm/nouveau/nv50_sor.c
31009+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31010@@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31011 }
31012
31013 if (nv_encoder->dcb->type == OUTPUT_DP) {
31014- struct dp_train_func func = {
31015+ static struct dp_train_func func = {
31016 .link_set = nv50_sor_dp_link_set,
31017 .train_set = nv50_sor_dp_train_set,
31018 .train_adj = nv50_sor_dp_train_adj
31019diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31020index 8a2fc89..3a5cf40 100644
31021--- a/drivers/gpu/drm/nouveau/nvd0_display.c
31022+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31023@@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31024 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31025
31026 if (nv_encoder->dcb->type == OUTPUT_DP) {
31027- struct dp_train_func func = {
31028+ static struct dp_train_func func = {
31029 .link_set = nvd0_sor_dp_link_set,
31030 .train_set = nvd0_sor_dp_train_set,
31031 .train_adj = nvd0_sor_dp_train_adj
31032diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31033index bcac90b..53bfc76 100644
31034--- a/drivers/gpu/drm/r128/r128_cce.c
31035+++ b/drivers/gpu/drm/r128/r128_cce.c
31036@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31037
31038 /* GH: Simple idle check.
31039 */
31040- atomic_set(&dev_priv->idle_count, 0);
31041+ atomic_set_unchecked(&dev_priv->idle_count, 0);
31042
31043 /* We don't support anything other than bus-mastering ring mode,
31044 * but the ring can be in either AGP or PCI space for the ring
31045diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31046index 930c71b..499aded 100644
31047--- a/drivers/gpu/drm/r128/r128_drv.h
31048+++ b/drivers/gpu/drm/r128/r128_drv.h
31049@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31050 int is_pci;
31051 unsigned long cce_buffers_offset;
31052
31053- atomic_t idle_count;
31054+ atomic_unchecked_t idle_count;
31055
31056 int page_flipping;
31057 int current_page;
31058 u32 crtc_offset;
31059 u32 crtc_offset_cntl;
31060
31061- atomic_t vbl_received;
31062+ atomic_unchecked_t vbl_received;
31063
31064 u32 color_fmt;
31065 unsigned int front_offset;
31066diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31067index 429d5a0..7e899ed 100644
31068--- a/drivers/gpu/drm/r128/r128_irq.c
31069+++ b/drivers/gpu/drm/r128/r128_irq.c
31070@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31071 if (crtc != 0)
31072 return 0;
31073
31074- return atomic_read(&dev_priv->vbl_received);
31075+ return atomic_read_unchecked(&dev_priv->vbl_received);
31076 }
31077
31078 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31079@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31080 /* VBLANK interrupt */
31081 if (status & R128_CRTC_VBLANK_INT) {
31082 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31083- atomic_inc(&dev_priv->vbl_received);
31084+ atomic_inc_unchecked(&dev_priv->vbl_received);
31085 drm_handle_vblank(dev, 0);
31086 return IRQ_HANDLED;
31087 }
31088diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31089index a9e33ce..09edd4b 100644
31090--- a/drivers/gpu/drm/r128/r128_state.c
31091+++ b/drivers/gpu/drm/r128/r128_state.c
31092@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31093
31094 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31095 {
31096- if (atomic_read(&dev_priv->idle_count) == 0)
31097+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31098 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31099 else
31100- atomic_set(&dev_priv->idle_count, 0);
31101+ atomic_set_unchecked(&dev_priv->idle_count, 0);
31102 }
31103
31104 #endif
31105diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31106index 5a82b6b..9e69c73 100644
31107--- a/drivers/gpu/drm/radeon/mkregtable.c
31108+++ b/drivers/gpu/drm/radeon/mkregtable.c
31109@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31110 regex_t mask_rex;
31111 regmatch_t match[4];
31112 char buf[1024];
31113- size_t end;
31114+ long end;
31115 int len;
31116 int done = 0;
31117 int r;
31118 unsigned o;
31119 struct offset *offset;
31120 char last_reg_s[10];
31121- int last_reg;
31122+ unsigned long last_reg;
31123
31124 if (regcomp
31125 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31126diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31127index 59a1531..3bab49b 100644
31128--- a/drivers/gpu/drm/radeon/radeon.h
31129+++ b/drivers/gpu/drm/radeon/radeon.h
31130@@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31131 int x2, int y2);
31132 void (*draw_auto)(struct radeon_device *rdev);
31133 void (*set_default_state)(struct radeon_device *rdev);
31134-};
31135+} __no_const;
31136
31137 struct r600_blit {
31138 struct radeon_bo *shader_obj;
31139@@ -1216,7 +1216,7 @@ struct radeon_asic {
31140 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31141 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31142 } pflip;
31143-};
31144+} __no_const;
31145
31146 /*
31147 * Asic structures
31148diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31149index 7a3daeb..5016171 100644
31150--- a/drivers/gpu/drm/radeon/radeon_device.c
31151+++ b/drivers/gpu/drm/radeon/radeon_device.c
31152@@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31153 bool can_switch;
31154
31155 spin_lock(&dev->count_lock);
31156- can_switch = (dev->open_count == 0);
31157+ can_switch = (local_read(&dev->open_count) == 0);
31158 spin_unlock(&dev->count_lock);
31159 return can_switch;
31160 }
31161diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31162index a1b59ca..86f2d44 100644
31163--- a/drivers/gpu/drm/radeon/radeon_drv.h
31164+++ b/drivers/gpu/drm/radeon/radeon_drv.h
31165@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31166
31167 /* SW interrupt */
31168 wait_queue_head_t swi_queue;
31169- atomic_t swi_emitted;
31170+ atomic_unchecked_t swi_emitted;
31171 int vblank_crtc;
31172 uint32_t irq_enable_reg;
31173 uint32_t r500_disp_irq_reg;
31174diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31175index 48b7cea..342236f 100644
31176--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31177+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31178@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31179 request = compat_alloc_user_space(sizeof(*request));
31180 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31181 || __put_user(req32.param, &request->param)
31182- || __put_user((void __user *)(unsigned long)req32.value,
31183+ || __put_user((unsigned long)req32.value,
31184 &request->value))
31185 return -EFAULT;
31186
31187diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31188index 00da384..32f972d 100644
31189--- a/drivers/gpu/drm/radeon/radeon_irq.c
31190+++ b/drivers/gpu/drm/radeon/radeon_irq.c
31191@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31192 unsigned int ret;
31193 RING_LOCALS;
31194
31195- atomic_inc(&dev_priv->swi_emitted);
31196- ret = atomic_read(&dev_priv->swi_emitted);
31197+ atomic_inc_unchecked(&dev_priv->swi_emitted);
31198+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31199
31200 BEGIN_RING(4);
31201 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31202@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31203 drm_radeon_private_t *dev_priv =
31204 (drm_radeon_private_t *) dev->dev_private;
31205
31206- atomic_set(&dev_priv->swi_emitted, 0);
31207+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31208 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31209
31210 dev->max_vblank_count = 0x001fffff;
31211diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31212index e8422ae..d22d4a8 100644
31213--- a/drivers/gpu/drm/radeon/radeon_state.c
31214+++ b/drivers/gpu/drm/radeon/radeon_state.c
31215@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31216 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31217 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31218
31219- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31220+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31221 sarea_priv->nbox * sizeof(depth_boxes[0])))
31222 return -EFAULT;
31223
31224@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31225 {
31226 drm_radeon_private_t *dev_priv = dev->dev_private;
31227 drm_radeon_getparam_t *param = data;
31228- int value;
31229+ int value = 0;
31230
31231 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31232
31233diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31234index 5b71c71..650f9e4 100644
31235--- a/drivers/gpu/drm/radeon/radeon_ttm.c
31236+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31237@@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31238 }
31239 if (unlikely(ttm_vm_ops == NULL)) {
31240 ttm_vm_ops = vma->vm_ops;
31241- radeon_ttm_vm_ops = *ttm_vm_ops;
31242- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31243+ pax_open_kernel();
31244+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31245+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31246+ pax_close_kernel();
31247 }
31248 vma->vm_ops = &radeon_ttm_vm_ops;
31249 return 0;
31250diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31251index 3b663fc..57850f4 100644
31252--- a/drivers/gpu/drm/radeon/rs690.c
31253+++ b/drivers/gpu/drm/radeon/rs690.c
31254@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31255 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31256 rdev->pm.sideport_bandwidth.full)
31257 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31258- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31259+ read_delay_latency.full = dfixed_const(800 * 1000);
31260 read_delay_latency.full = dfixed_div(read_delay_latency,
31261 rdev->pm.igp_sideport_mclk);
31262+ a.full = dfixed_const(370);
31263+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31264 } else {
31265 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31266 rdev->pm.k8_bandwidth.full)
31267diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31268index ebc6fac..a8313ed 100644
31269--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31270+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31271@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31272 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31273 struct shrink_control *sc)
31274 {
31275- static atomic_t start_pool = ATOMIC_INIT(0);
31276+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31277 unsigned i;
31278- unsigned pool_offset = atomic_add_return(1, &start_pool);
31279+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31280 struct ttm_page_pool *pool;
31281 int shrink_pages = sc->nr_to_scan;
31282
31283diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31284index 88edacc..1e5412b 100644
31285--- a/drivers/gpu/drm/via/via_drv.h
31286+++ b/drivers/gpu/drm/via/via_drv.h
31287@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31288 typedef uint32_t maskarray_t[5];
31289
31290 typedef struct drm_via_irq {
31291- atomic_t irq_received;
31292+ atomic_unchecked_t irq_received;
31293 uint32_t pending_mask;
31294 uint32_t enable_mask;
31295 wait_queue_head_t irq_queue;
31296@@ -75,7 +75,7 @@ typedef struct drm_via_private {
31297 struct timeval last_vblank;
31298 int last_vblank_valid;
31299 unsigned usec_per_vblank;
31300- atomic_t vbl_received;
31301+ atomic_unchecked_t vbl_received;
31302 drm_via_state_t hc_state;
31303 char pci_buf[VIA_PCI_BUF_SIZE];
31304 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31305diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31306index d391f48..10c8ca3 100644
31307--- a/drivers/gpu/drm/via/via_irq.c
31308+++ b/drivers/gpu/drm/via/via_irq.c
31309@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31310 if (crtc != 0)
31311 return 0;
31312
31313- return atomic_read(&dev_priv->vbl_received);
31314+ return atomic_read_unchecked(&dev_priv->vbl_received);
31315 }
31316
31317 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31318@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31319
31320 status = VIA_READ(VIA_REG_INTERRUPT);
31321 if (status & VIA_IRQ_VBLANK_PENDING) {
31322- atomic_inc(&dev_priv->vbl_received);
31323- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31324+ atomic_inc_unchecked(&dev_priv->vbl_received);
31325+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31326 do_gettimeofday(&cur_vblank);
31327 if (dev_priv->last_vblank_valid) {
31328 dev_priv->usec_per_vblank =
31329@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31330 dev_priv->last_vblank = cur_vblank;
31331 dev_priv->last_vblank_valid = 1;
31332 }
31333- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31334+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31335 DRM_DEBUG("US per vblank is: %u\n",
31336 dev_priv->usec_per_vblank);
31337 }
31338@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31339
31340 for (i = 0; i < dev_priv->num_irqs; ++i) {
31341 if (status & cur_irq->pending_mask) {
31342- atomic_inc(&cur_irq->irq_received);
31343+ atomic_inc_unchecked(&cur_irq->irq_received);
31344 DRM_WAKEUP(&cur_irq->irq_queue);
31345 handled = 1;
31346 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31347@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31348 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31349 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31350 masks[irq][4]));
31351- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31352+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31353 } else {
31354 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31355 (((cur_irq_sequence =
31356- atomic_read(&cur_irq->irq_received)) -
31357+ atomic_read_unchecked(&cur_irq->irq_received)) -
31358 *sequence) <= (1 << 23)));
31359 }
31360 *sequence = cur_irq_sequence;
31361@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31362 }
31363
31364 for (i = 0; i < dev_priv->num_irqs; ++i) {
31365- atomic_set(&cur_irq->irq_received, 0);
31366+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31367 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31368 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31369 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31370@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31371 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31372 case VIA_IRQ_RELATIVE:
31373 irqwait->request.sequence +=
31374- atomic_read(&cur_irq->irq_received);
31375+ atomic_read_unchecked(&cur_irq->irq_received);
31376 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31377 case VIA_IRQ_ABSOLUTE:
31378 break;
31379diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31380index 29c984f..4084f1a 100644
31381--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31382+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31383@@ -263,7 +263,7 @@ struct vmw_private {
31384 * Fencing and IRQs.
31385 */
31386
31387- atomic_t marker_seq;
31388+ atomic_unchecked_t marker_seq;
31389 wait_queue_head_t fence_queue;
31390 wait_queue_head_t fifo_queue;
31391 int fence_queue_waiters; /* Protected by hw_mutex */
31392diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31393index a0c2f12..68ae6cb 100644
31394--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31395+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31396@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31397 (unsigned int) min,
31398 (unsigned int) fifo->capabilities);
31399
31400- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31401+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31402 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31403 vmw_marker_queue_init(&fifo->marker_queue);
31404 return vmw_fifo_send_fence(dev_priv, &dummy);
31405@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31406 if (reserveable)
31407 iowrite32(bytes, fifo_mem +
31408 SVGA_FIFO_RESERVED);
31409- return fifo_mem + (next_cmd >> 2);
31410+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31411 } else {
31412 need_bounce = true;
31413 }
31414@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31415
31416 fm = vmw_fifo_reserve(dev_priv, bytes);
31417 if (unlikely(fm == NULL)) {
31418- *seqno = atomic_read(&dev_priv->marker_seq);
31419+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31420 ret = -ENOMEM;
31421 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31422 false, 3*HZ);
31423@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31424 }
31425
31426 do {
31427- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31428+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31429 } while (*seqno == 0);
31430
31431 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31432diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31433index cabc95f..14b3d77 100644
31434--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31435+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31436@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31437 * emitted. Then the fence is stale and signaled.
31438 */
31439
31440- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31441+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31442 > VMW_FENCE_WRAP);
31443
31444 return ret;
31445@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31446
31447 if (fifo_idle)
31448 down_read(&fifo_state->rwsem);
31449- signal_seq = atomic_read(&dev_priv->marker_seq);
31450+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31451 ret = 0;
31452
31453 for (;;) {
31454diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31455index 8a8725c..afed796 100644
31456--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31457+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31458@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31459 while (!vmw_lag_lt(queue, us)) {
31460 spin_lock(&queue->lock);
31461 if (list_empty(&queue->head))
31462- seqno = atomic_read(&dev_priv->marker_seq);
31463+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31464 else {
31465 marker = list_first_entry(&queue->head,
31466 struct vmw_marker, head);
31467diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31468index 5de3bb3..08e5063 100644
31469--- a/drivers/hid/hid-core.c
31470+++ b/drivers/hid/hid-core.c
31471@@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31472
31473 int hid_add_device(struct hid_device *hdev)
31474 {
31475- static atomic_t id = ATOMIC_INIT(0);
31476+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31477 int ret;
31478
31479 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31480@@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31481 /* XXX hack, any other cleaner solution after the driver core
31482 * is converted to allow more than 20 bytes as the device name? */
31483 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31484- hdev->vendor, hdev->product, atomic_inc_return(&id));
31485+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31486
31487 hid_debug_register(hdev, dev_name(&hdev->dev));
31488 ret = device_add(&hdev->dev);
31489diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31490index eec3291..8ed706b 100644
31491--- a/drivers/hid/hid-wiimote-debug.c
31492+++ b/drivers/hid/hid-wiimote-debug.c
31493@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31494 else if (size == 0)
31495 return -EIO;
31496
31497- if (copy_to_user(u, buf, size))
31498+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
31499 return -EFAULT;
31500
31501 *off += size;
31502diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31503index 14599e2..711c965 100644
31504--- a/drivers/hid/usbhid/hiddev.c
31505+++ b/drivers/hid/usbhid/hiddev.c
31506@@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31507 break;
31508
31509 case HIDIOCAPPLICATION:
31510- if (arg < 0 || arg >= hid->maxapplication)
31511+ if (arg >= hid->maxapplication)
31512 break;
31513
31514 for (i = 0; i < hid->maxcollection; i++)
31515diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31516index 4065374..10ed7dc 100644
31517--- a/drivers/hv/channel.c
31518+++ b/drivers/hv/channel.c
31519@@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31520 int ret = 0;
31521 int t;
31522
31523- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31524- atomic_inc(&vmbus_connection.next_gpadl_handle);
31525+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31526+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31527
31528 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31529 if (ret)
31530diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31531index 86f8885..ab9cb2b 100644
31532--- a/drivers/hv/hv.c
31533+++ b/drivers/hv/hv.c
31534@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31535 u64 output_address = (output) ? virt_to_phys(output) : 0;
31536 u32 output_address_hi = output_address >> 32;
31537 u32 output_address_lo = output_address & 0xFFFFFFFF;
31538- void *hypercall_page = hv_context.hypercall_page;
31539+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31540
31541 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31542 "=a"(hv_status_lo) : "d" (control_hi),
31543diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31544index 0614ff3..f0b2b5c 100644
31545--- a/drivers/hv/hyperv_vmbus.h
31546+++ b/drivers/hv/hyperv_vmbus.h
31547@@ -555,7 +555,7 @@ enum vmbus_connect_state {
31548 struct vmbus_connection {
31549 enum vmbus_connect_state conn_state;
31550
31551- atomic_t next_gpadl_handle;
31552+ atomic_unchecked_t next_gpadl_handle;
31553
31554 /*
31555 * Represents channel interrupts. Each bit position represents a
31556diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31557index 4748086..3abf845 100644
31558--- a/drivers/hv/vmbus_drv.c
31559+++ b/drivers/hv/vmbus_drv.c
31560@@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31561 {
31562 int ret = 0;
31563
31564- static atomic_t device_num = ATOMIC_INIT(0);
31565+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31566
31567 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31568- atomic_inc_return(&device_num));
31569+ atomic_inc_return_unchecked(&device_num));
31570
31571 child_device_obj->device.bus = &hv_bus;
31572 child_device_obj->device.parent = &hv_acpi_dev->dev;
31573diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31574index 8b011d0..3de24a1 100644
31575--- a/drivers/hwmon/sht15.c
31576+++ b/drivers/hwmon/sht15.c
31577@@ -166,7 +166,7 @@ struct sht15_data {
31578 int supply_uV;
31579 bool supply_uV_valid;
31580 struct work_struct update_supply_work;
31581- atomic_t interrupt_handled;
31582+ atomic_unchecked_t interrupt_handled;
31583 };
31584
31585 /**
31586@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31587 return ret;
31588
31589 gpio_direction_input(data->pdata->gpio_data);
31590- atomic_set(&data->interrupt_handled, 0);
31591+ atomic_set_unchecked(&data->interrupt_handled, 0);
31592
31593 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31594 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31595 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31596 /* Only relevant if the interrupt hasn't occurred. */
31597- if (!atomic_read(&data->interrupt_handled))
31598+ if (!atomic_read_unchecked(&data->interrupt_handled))
31599 schedule_work(&data->read_work);
31600 }
31601 ret = wait_event_timeout(data->wait_queue,
31602@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31603
31604 /* First disable the interrupt */
31605 disable_irq_nosync(irq);
31606- atomic_inc(&data->interrupt_handled);
31607+ atomic_inc_unchecked(&data->interrupt_handled);
31608 /* Then schedule a reading work struct */
31609 if (data->state != SHT15_READING_NOTHING)
31610 schedule_work(&data->read_work);
31611@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31612 * If not, then start the interrupt again - care here as could
31613 * have gone low in meantime so verify it hasn't!
31614 */
31615- atomic_set(&data->interrupt_handled, 0);
31616+ atomic_set_unchecked(&data->interrupt_handled, 0);
31617 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31618 /* If still not occurred or another handler was scheduled */
31619 if (gpio_get_value(data->pdata->gpio_data)
31620- || atomic_read(&data->interrupt_handled))
31621+ || atomic_read_unchecked(&data->interrupt_handled))
31622 return;
31623 }
31624
31625diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31626index 378fcb5..5e91fa8 100644
31627--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31628+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31629@@ -43,7 +43,7 @@
31630 extern struct i2c_adapter amd756_smbus;
31631
31632 static struct i2c_adapter *s4882_adapter;
31633-static struct i2c_algorithm *s4882_algo;
31634+static i2c_algorithm_no_const *s4882_algo;
31635
31636 /* Wrapper access functions for multiplexed SMBus */
31637 static DEFINE_MUTEX(amd756_lock);
31638diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31639index 29015eb..af2d8e9 100644
31640--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31641+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31642@@ -41,7 +41,7 @@
31643 extern struct i2c_adapter *nforce2_smbus;
31644
31645 static struct i2c_adapter *s4985_adapter;
31646-static struct i2c_algorithm *s4985_algo;
31647+static i2c_algorithm_no_const *s4985_algo;
31648
31649 /* Wrapper access functions for multiplexed SMBus */
31650 static DEFINE_MUTEX(nforce2_lock);
31651diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31652index 1038c38..eb92f51 100644
31653--- a/drivers/i2c/i2c-mux.c
31654+++ b/drivers/i2c/i2c-mux.c
31655@@ -30,7 +30,7 @@
31656 /* multiplexer per channel data */
31657 struct i2c_mux_priv {
31658 struct i2c_adapter adap;
31659- struct i2c_algorithm algo;
31660+ i2c_algorithm_no_const algo;
31661
31662 struct i2c_adapter *parent;
31663 void *mux_priv; /* the mux chip/device */
31664diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31665index 57d00ca..0145194 100644
31666--- a/drivers/ide/aec62xx.c
31667+++ b/drivers/ide/aec62xx.c
31668@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31669 .cable_detect = atp86x_cable_detect,
31670 };
31671
31672-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31673+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31674 { /* 0: AEC6210 */
31675 .name = DRV_NAME,
31676 .init_chipset = init_chipset_aec62xx,
31677diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31678index 2c8016a..911a27c 100644
31679--- a/drivers/ide/alim15x3.c
31680+++ b/drivers/ide/alim15x3.c
31681@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31682 .dma_sff_read_status = ide_dma_sff_read_status,
31683 };
31684
31685-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31686+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31687 .name = DRV_NAME,
31688 .init_chipset = init_chipset_ali15x3,
31689 .init_hwif = init_hwif_ali15x3,
31690diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31691index 3747b25..56fc995 100644
31692--- a/drivers/ide/amd74xx.c
31693+++ b/drivers/ide/amd74xx.c
31694@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31695 .udma_mask = udma, \
31696 }
31697
31698-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31699+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31700 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31701 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31702 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31703diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31704index 15f0ead..cb43480 100644
31705--- a/drivers/ide/atiixp.c
31706+++ b/drivers/ide/atiixp.c
31707@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31708 .cable_detect = atiixp_cable_detect,
31709 };
31710
31711-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31712+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31713 { /* 0: IXP200/300/400/700 */
31714 .name = DRV_NAME,
31715 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31716diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31717index 5f80312..d1fc438 100644
31718--- a/drivers/ide/cmd64x.c
31719+++ b/drivers/ide/cmd64x.c
31720@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31721 .dma_sff_read_status = ide_dma_sff_read_status,
31722 };
31723
31724-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31725+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31726 { /* 0: CMD643 */
31727 .name = DRV_NAME,
31728 .init_chipset = init_chipset_cmd64x,
31729diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31730index 2c1e5f7..1444762 100644
31731--- a/drivers/ide/cs5520.c
31732+++ b/drivers/ide/cs5520.c
31733@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31734 .set_dma_mode = cs5520_set_dma_mode,
31735 };
31736
31737-static const struct ide_port_info cyrix_chipset __devinitdata = {
31738+static const struct ide_port_info cyrix_chipset __devinitconst = {
31739 .name = DRV_NAME,
31740 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31741 .port_ops = &cs5520_port_ops,
31742diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31743index 4dc4eb9..49b40ad 100644
31744--- a/drivers/ide/cs5530.c
31745+++ b/drivers/ide/cs5530.c
31746@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31747 .udma_filter = cs5530_udma_filter,
31748 };
31749
31750-static const struct ide_port_info cs5530_chipset __devinitdata = {
31751+static const struct ide_port_info cs5530_chipset __devinitconst = {
31752 .name = DRV_NAME,
31753 .init_chipset = init_chipset_cs5530,
31754 .init_hwif = init_hwif_cs5530,
31755diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31756index 5059faf..18d4c85 100644
31757--- a/drivers/ide/cs5535.c
31758+++ b/drivers/ide/cs5535.c
31759@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31760 .cable_detect = cs5535_cable_detect,
31761 };
31762
31763-static const struct ide_port_info cs5535_chipset __devinitdata = {
31764+static const struct ide_port_info cs5535_chipset __devinitconst = {
31765 .name = DRV_NAME,
31766 .port_ops = &cs5535_port_ops,
31767 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31768diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31769index 847553f..3ffb49d 100644
31770--- a/drivers/ide/cy82c693.c
31771+++ b/drivers/ide/cy82c693.c
31772@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31773 .set_dma_mode = cy82c693_set_dma_mode,
31774 };
31775
31776-static const struct ide_port_info cy82c693_chipset __devinitdata = {
31777+static const struct ide_port_info cy82c693_chipset __devinitconst = {
31778 .name = DRV_NAME,
31779 .init_iops = init_iops_cy82c693,
31780 .port_ops = &cy82c693_port_ops,
31781diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31782index 58c51cd..4aec3b8 100644
31783--- a/drivers/ide/hpt366.c
31784+++ b/drivers/ide/hpt366.c
31785@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31786 }
31787 };
31788
31789-static const struct hpt_info hpt36x __devinitdata = {
31790+static const struct hpt_info hpt36x __devinitconst = {
31791 .chip_name = "HPT36x",
31792 .chip_type = HPT36x,
31793 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31794@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31795 .timings = &hpt36x_timings
31796 };
31797
31798-static const struct hpt_info hpt370 __devinitdata = {
31799+static const struct hpt_info hpt370 __devinitconst = {
31800 .chip_name = "HPT370",
31801 .chip_type = HPT370,
31802 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31803@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31804 .timings = &hpt37x_timings
31805 };
31806
31807-static const struct hpt_info hpt370a __devinitdata = {
31808+static const struct hpt_info hpt370a __devinitconst = {
31809 .chip_name = "HPT370A",
31810 .chip_type = HPT370A,
31811 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31812@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31813 .timings = &hpt37x_timings
31814 };
31815
31816-static const struct hpt_info hpt374 __devinitdata = {
31817+static const struct hpt_info hpt374 __devinitconst = {
31818 .chip_name = "HPT374",
31819 .chip_type = HPT374,
31820 .udma_mask = ATA_UDMA5,
31821@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31822 .timings = &hpt37x_timings
31823 };
31824
31825-static const struct hpt_info hpt372 __devinitdata = {
31826+static const struct hpt_info hpt372 __devinitconst = {
31827 .chip_name = "HPT372",
31828 .chip_type = HPT372,
31829 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31830@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31831 .timings = &hpt37x_timings
31832 };
31833
31834-static const struct hpt_info hpt372a __devinitdata = {
31835+static const struct hpt_info hpt372a __devinitconst = {
31836 .chip_name = "HPT372A",
31837 .chip_type = HPT372A,
31838 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31839@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31840 .timings = &hpt37x_timings
31841 };
31842
31843-static const struct hpt_info hpt302 __devinitdata = {
31844+static const struct hpt_info hpt302 __devinitconst = {
31845 .chip_name = "HPT302",
31846 .chip_type = HPT302,
31847 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31848@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31849 .timings = &hpt37x_timings
31850 };
31851
31852-static const struct hpt_info hpt371 __devinitdata = {
31853+static const struct hpt_info hpt371 __devinitconst = {
31854 .chip_name = "HPT371",
31855 .chip_type = HPT371,
31856 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31857@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31858 .timings = &hpt37x_timings
31859 };
31860
31861-static const struct hpt_info hpt372n __devinitdata = {
31862+static const struct hpt_info hpt372n __devinitconst = {
31863 .chip_name = "HPT372N",
31864 .chip_type = HPT372N,
31865 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31866@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31867 .timings = &hpt37x_timings
31868 };
31869
31870-static const struct hpt_info hpt302n __devinitdata = {
31871+static const struct hpt_info hpt302n __devinitconst = {
31872 .chip_name = "HPT302N",
31873 .chip_type = HPT302N,
31874 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31875@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31876 .timings = &hpt37x_timings
31877 };
31878
31879-static const struct hpt_info hpt371n __devinitdata = {
31880+static const struct hpt_info hpt371n __devinitconst = {
31881 .chip_name = "HPT371N",
31882 .chip_type = HPT371N,
31883 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31884@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31885 .dma_sff_read_status = ide_dma_sff_read_status,
31886 };
31887
31888-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31889+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31890 { /* 0: HPT36x */
31891 .name = DRV_NAME,
31892 .init_chipset = init_chipset_hpt366,
31893diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31894index 8126824..55a2798 100644
31895--- a/drivers/ide/ide-cd.c
31896+++ b/drivers/ide/ide-cd.c
31897@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31898 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31899 if ((unsigned long)buf & alignment
31900 || blk_rq_bytes(rq) & q->dma_pad_mask
31901- || object_is_on_stack(buf))
31902+ || object_starts_on_stack(buf))
31903 drive->dma = 0;
31904 }
31905 }
31906diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31907index 7f56b73..dab5b67 100644
31908--- a/drivers/ide/ide-pci-generic.c
31909+++ b/drivers/ide/ide-pci-generic.c
31910@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31911 .udma_mask = ATA_UDMA6, \
31912 }
31913
31914-static const struct ide_port_info generic_chipsets[] __devinitdata = {
31915+static const struct ide_port_info generic_chipsets[] __devinitconst = {
31916 /* 0: Unknown */
31917 DECLARE_GENERIC_PCI_DEV(0),
31918
31919diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31920index 560e66d..d5dd180 100644
31921--- a/drivers/ide/it8172.c
31922+++ b/drivers/ide/it8172.c
31923@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31924 .set_dma_mode = it8172_set_dma_mode,
31925 };
31926
31927-static const struct ide_port_info it8172_port_info __devinitdata = {
31928+static const struct ide_port_info it8172_port_info __devinitconst = {
31929 .name = DRV_NAME,
31930 .port_ops = &it8172_port_ops,
31931 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31932diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31933index 46816ba..1847aeb 100644
31934--- a/drivers/ide/it8213.c
31935+++ b/drivers/ide/it8213.c
31936@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31937 .cable_detect = it8213_cable_detect,
31938 };
31939
31940-static const struct ide_port_info it8213_chipset __devinitdata = {
31941+static const struct ide_port_info it8213_chipset __devinitconst = {
31942 .name = DRV_NAME,
31943 .enablebits = { {0x41, 0x80, 0x80} },
31944 .port_ops = &it8213_port_ops,
31945diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31946index 2e3169f..c5611db 100644
31947--- a/drivers/ide/it821x.c
31948+++ b/drivers/ide/it821x.c
31949@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31950 .cable_detect = it821x_cable_detect,
31951 };
31952
31953-static const struct ide_port_info it821x_chipset __devinitdata = {
31954+static const struct ide_port_info it821x_chipset __devinitconst = {
31955 .name = DRV_NAME,
31956 .init_chipset = init_chipset_it821x,
31957 .init_hwif = init_hwif_it821x,
31958diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31959index 74c2c4a..efddd7d 100644
31960--- a/drivers/ide/jmicron.c
31961+++ b/drivers/ide/jmicron.c
31962@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31963 .cable_detect = jmicron_cable_detect,
31964 };
31965
31966-static const struct ide_port_info jmicron_chipset __devinitdata = {
31967+static const struct ide_port_info jmicron_chipset __devinitconst = {
31968 .name = DRV_NAME,
31969 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31970 .port_ops = &jmicron_port_ops,
31971diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31972index 95327a2..73f78d8 100644
31973--- a/drivers/ide/ns87415.c
31974+++ b/drivers/ide/ns87415.c
31975@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31976 .dma_sff_read_status = superio_dma_sff_read_status,
31977 };
31978
31979-static const struct ide_port_info ns87415_chipset __devinitdata = {
31980+static const struct ide_port_info ns87415_chipset __devinitconst = {
31981 .name = DRV_NAME,
31982 .init_hwif = init_hwif_ns87415,
31983 .tp_ops = &ns87415_tp_ops,
31984diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31985index 1a53a4c..39edc66 100644
31986--- a/drivers/ide/opti621.c
31987+++ b/drivers/ide/opti621.c
31988@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31989 .set_pio_mode = opti621_set_pio_mode,
31990 };
31991
31992-static const struct ide_port_info opti621_chipset __devinitdata = {
31993+static const struct ide_port_info opti621_chipset __devinitconst = {
31994 .name = DRV_NAME,
31995 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31996 .port_ops = &opti621_port_ops,
31997diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31998index 9546fe2..2e5ceb6 100644
31999--- a/drivers/ide/pdc202xx_new.c
32000+++ b/drivers/ide/pdc202xx_new.c
32001@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
32002 .udma_mask = udma, \
32003 }
32004
32005-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32006+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32007 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32008 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32009 };
32010diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32011index 3a35ec6..5634510 100644
32012--- a/drivers/ide/pdc202xx_old.c
32013+++ b/drivers/ide/pdc202xx_old.c
32014@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32015 .max_sectors = sectors, \
32016 }
32017
32018-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32019+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32020 { /* 0: PDC20246 */
32021 .name = DRV_NAME,
32022 .init_chipset = init_chipset_pdc202xx,
32023diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32024index 1892e81..fe0fd60 100644
32025--- a/drivers/ide/piix.c
32026+++ b/drivers/ide/piix.c
32027@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32028 .udma_mask = udma, \
32029 }
32030
32031-static const struct ide_port_info piix_pci_info[] __devinitdata = {
32032+static const struct ide_port_info piix_pci_info[] __devinitconst = {
32033 /* 0: MPIIX */
32034 { /*
32035 * MPIIX actually has only a single IDE channel mapped to
32036diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32037index a6414a8..c04173e 100644
32038--- a/drivers/ide/rz1000.c
32039+++ b/drivers/ide/rz1000.c
32040@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32041 }
32042 }
32043
32044-static const struct ide_port_info rz1000_chipset __devinitdata = {
32045+static const struct ide_port_info rz1000_chipset __devinitconst = {
32046 .name = DRV_NAME,
32047 .host_flags = IDE_HFLAG_NO_DMA,
32048 };
32049diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32050index 356b9b5..d4758eb 100644
32051--- a/drivers/ide/sc1200.c
32052+++ b/drivers/ide/sc1200.c
32053@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32054 .dma_sff_read_status = ide_dma_sff_read_status,
32055 };
32056
32057-static const struct ide_port_info sc1200_chipset __devinitdata = {
32058+static const struct ide_port_info sc1200_chipset __devinitconst = {
32059 .name = DRV_NAME,
32060 .port_ops = &sc1200_port_ops,
32061 .dma_ops = &sc1200_dma_ops,
32062diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32063index b7f5b0c..9701038 100644
32064--- a/drivers/ide/scc_pata.c
32065+++ b/drivers/ide/scc_pata.c
32066@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32067 .dma_sff_read_status = scc_dma_sff_read_status,
32068 };
32069
32070-static const struct ide_port_info scc_chipset __devinitdata = {
32071+static const struct ide_port_info scc_chipset __devinitconst = {
32072 .name = "sccIDE",
32073 .init_iops = init_iops_scc,
32074 .init_dma = scc_init_dma,
32075diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32076index 35fb8da..24d72ef 100644
32077--- a/drivers/ide/serverworks.c
32078+++ b/drivers/ide/serverworks.c
32079@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32080 .cable_detect = svwks_cable_detect,
32081 };
32082
32083-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32084+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32085 { /* 0: OSB4 */
32086 .name = DRV_NAME,
32087 .init_chipset = init_chipset_svwks,
32088diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32089index ddeda44..46f7e30 100644
32090--- a/drivers/ide/siimage.c
32091+++ b/drivers/ide/siimage.c
32092@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32093 .udma_mask = ATA_UDMA6, \
32094 }
32095
32096-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32097+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32098 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32099 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32100 };
32101diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32102index 4a00225..09e61b4 100644
32103--- a/drivers/ide/sis5513.c
32104+++ b/drivers/ide/sis5513.c
32105@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32106 .cable_detect = sis_cable_detect,
32107 };
32108
32109-static const struct ide_port_info sis5513_chipset __devinitdata = {
32110+static const struct ide_port_info sis5513_chipset __devinitconst = {
32111 .name = DRV_NAME,
32112 .init_chipset = init_chipset_sis5513,
32113 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32114diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32115index f21dc2a..d051cd2 100644
32116--- a/drivers/ide/sl82c105.c
32117+++ b/drivers/ide/sl82c105.c
32118@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32119 .dma_sff_read_status = ide_dma_sff_read_status,
32120 };
32121
32122-static const struct ide_port_info sl82c105_chipset __devinitdata = {
32123+static const struct ide_port_info sl82c105_chipset __devinitconst = {
32124 .name = DRV_NAME,
32125 .init_chipset = init_chipset_sl82c105,
32126 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32127diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32128index 864ffe0..863a5e9 100644
32129--- a/drivers/ide/slc90e66.c
32130+++ b/drivers/ide/slc90e66.c
32131@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32132 .cable_detect = slc90e66_cable_detect,
32133 };
32134
32135-static const struct ide_port_info slc90e66_chipset __devinitdata = {
32136+static const struct ide_port_info slc90e66_chipset __devinitconst = {
32137 .name = DRV_NAME,
32138 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32139 .port_ops = &slc90e66_port_ops,
32140diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32141index 4799d5c..1794678 100644
32142--- a/drivers/ide/tc86c001.c
32143+++ b/drivers/ide/tc86c001.c
32144@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32145 .dma_sff_read_status = ide_dma_sff_read_status,
32146 };
32147
32148-static const struct ide_port_info tc86c001_chipset __devinitdata = {
32149+static const struct ide_port_info tc86c001_chipset __devinitconst = {
32150 .name = DRV_NAME,
32151 .init_hwif = init_hwif_tc86c001,
32152 .port_ops = &tc86c001_port_ops,
32153diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32154index 281c914..55ce1b8 100644
32155--- a/drivers/ide/triflex.c
32156+++ b/drivers/ide/triflex.c
32157@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32158 .set_dma_mode = triflex_set_mode,
32159 };
32160
32161-static const struct ide_port_info triflex_device __devinitdata = {
32162+static const struct ide_port_info triflex_device __devinitconst = {
32163 .name = DRV_NAME,
32164 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32165 .port_ops = &triflex_port_ops,
32166diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32167index 4b42ca0..e494a98 100644
32168--- a/drivers/ide/trm290.c
32169+++ b/drivers/ide/trm290.c
32170@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32171 .dma_check = trm290_dma_check,
32172 };
32173
32174-static const struct ide_port_info trm290_chipset __devinitdata = {
32175+static const struct ide_port_info trm290_chipset __devinitconst = {
32176 .name = DRV_NAME,
32177 .init_hwif = init_hwif_trm290,
32178 .tp_ops = &trm290_tp_ops,
32179diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32180index f46f49c..eb77678 100644
32181--- a/drivers/ide/via82cxxx.c
32182+++ b/drivers/ide/via82cxxx.c
32183@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32184 .cable_detect = via82cxxx_cable_detect,
32185 };
32186
32187-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32188+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32189 .name = DRV_NAME,
32190 .init_chipset = init_chipset_via82cxxx,
32191 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32192diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32193index 73d4531..c90cd2d 100644
32194--- a/drivers/ieee802154/fakehard.c
32195+++ b/drivers/ieee802154/fakehard.c
32196@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32197 phy->transmit_power = 0xbf;
32198
32199 dev->netdev_ops = &fake_ops;
32200- dev->ml_priv = &fake_mlme;
32201+ dev->ml_priv = (void *)&fake_mlme;
32202
32203 priv = netdev_priv(dev);
32204 priv->phy = phy;
32205diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32206index d67999f..4c5d083 100644
32207--- a/drivers/infiniband/core/cm.c
32208+++ b/drivers/infiniband/core/cm.c
32209@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32210
32211 struct cm_counter_group {
32212 struct kobject obj;
32213- atomic_long_t counter[CM_ATTR_COUNT];
32214+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32215 };
32216
32217 struct cm_counter_attribute {
32218@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32219 struct ib_mad_send_buf *msg = NULL;
32220 int ret;
32221
32222- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32223+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32224 counter[CM_REQ_COUNTER]);
32225
32226 /* Quick state check to discard duplicate REQs. */
32227@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32228 if (!cm_id_priv)
32229 return;
32230
32231- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32232+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32233 counter[CM_REP_COUNTER]);
32234 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32235 if (ret)
32236@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32237 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32238 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32239 spin_unlock_irq(&cm_id_priv->lock);
32240- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32241+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32242 counter[CM_RTU_COUNTER]);
32243 goto out;
32244 }
32245@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32246 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32247 dreq_msg->local_comm_id);
32248 if (!cm_id_priv) {
32249- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32250+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32251 counter[CM_DREQ_COUNTER]);
32252 cm_issue_drep(work->port, work->mad_recv_wc);
32253 return -EINVAL;
32254@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32255 case IB_CM_MRA_REP_RCVD:
32256 break;
32257 case IB_CM_TIMEWAIT:
32258- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32259+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32260 counter[CM_DREQ_COUNTER]);
32261 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32262 goto unlock;
32263@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32264 cm_free_msg(msg);
32265 goto deref;
32266 case IB_CM_DREQ_RCVD:
32267- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32268+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32269 counter[CM_DREQ_COUNTER]);
32270 goto unlock;
32271 default:
32272@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32273 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32274 cm_id_priv->msg, timeout)) {
32275 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32276- atomic_long_inc(&work->port->
32277+ atomic_long_inc_unchecked(&work->port->
32278 counter_group[CM_RECV_DUPLICATES].
32279 counter[CM_MRA_COUNTER]);
32280 goto out;
32281@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32282 break;
32283 case IB_CM_MRA_REQ_RCVD:
32284 case IB_CM_MRA_REP_RCVD:
32285- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32286+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32287 counter[CM_MRA_COUNTER]);
32288 /* fall through */
32289 default:
32290@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32291 case IB_CM_LAP_IDLE:
32292 break;
32293 case IB_CM_MRA_LAP_SENT:
32294- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32295+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32296 counter[CM_LAP_COUNTER]);
32297 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32298 goto unlock;
32299@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32300 cm_free_msg(msg);
32301 goto deref;
32302 case IB_CM_LAP_RCVD:
32303- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32304+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32305 counter[CM_LAP_COUNTER]);
32306 goto unlock;
32307 default:
32308@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32309 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32310 if (cur_cm_id_priv) {
32311 spin_unlock_irq(&cm.lock);
32312- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32313+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32314 counter[CM_SIDR_REQ_COUNTER]);
32315 goto out; /* Duplicate message. */
32316 }
32317@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32318 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32319 msg->retries = 1;
32320
32321- atomic_long_add(1 + msg->retries,
32322+ atomic_long_add_unchecked(1 + msg->retries,
32323 &port->counter_group[CM_XMIT].counter[attr_index]);
32324 if (msg->retries)
32325- atomic_long_add(msg->retries,
32326+ atomic_long_add_unchecked(msg->retries,
32327 &port->counter_group[CM_XMIT_RETRIES].
32328 counter[attr_index]);
32329
32330@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32331 }
32332
32333 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32334- atomic_long_inc(&port->counter_group[CM_RECV].
32335+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32336 counter[attr_id - CM_ATTR_ID_OFFSET]);
32337
32338 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32339@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32340 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32341
32342 return sprintf(buf, "%ld\n",
32343- atomic_long_read(&group->counter[cm_attr->index]));
32344+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32345 }
32346
32347 static const struct sysfs_ops cm_counter_ops = {
32348diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32349index 176c8f9..2627b62 100644
32350--- a/drivers/infiniband/core/fmr_pool.c
32351+++ b/drivers/infiniband/core/fmr_pool.c
32352@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32353
32354 struct task_struct *thread;
32355
32356- atomic_t req_ser;
32357- atomic_t flush_ser;
32358+ atomic_unchecked_t req_ser;
32359+ atomic_unchecked_t flush_ser;
32360
32361 wait_queue_head_t force_wait;
32362 };
32363@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32364 struct ib_fmr_pool *pool = pool_ptr;
32365
32366 do {
32367- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32368+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32369 ib_fmr_batch_release(pool);
32370
32371- atomic_inc(&pool->flush_ser);
32372+ atomic_inc_unchecked(&pool->flush_ser);
32373 wake_up_interruptible(&pool->force_wait);
32374
32375 if (pool->flush_function)
32376@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32377 }
32378
32379 set_current_state(TASK_INTERRUPTIBLE);
32380- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32381+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32382 !kthread_should_stop())
32383 schedule();
32384 __set_current_state(TASK_RUNNING);
32385@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32386 pool->dirty_watermark = params->dirty_watermark;
32387 pool->dirty_len = 0;
32388 spin_lock_init(&pool->pool_lock);
32389- atomic_set(&pool->req_ser, 0);
32390- atomic_set(&pool->flush_ser, 0);
32391+ atomic_set_unchecked(&pool->req_ser, 0);
32392+ atomic_set_unchecked(&pool->flush_ser, 0);
32393 init_waitqueue_head(&pool->force_wait);
32394
32395 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32396@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32397 }
32398 spin_unlock_irq(&pool->pool_lock);
32399
32400- serial = atomic_inc_return(&pool->req_ser);
32401+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32402 wake_up_process(pool->thread);
32403
32404 if (wait_event_interruptible(pool->force_wait,
32405- atomic_read(&pool->flush_ser) - serial >= 0))
32406+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32407 return -EINTR;
32408
32409 return 0;
32410@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32411 } else {
32412 list_add_tail(&fmr->list, &pool->dirty_list);
32413 if (++pool->dirty_len >= pool->dirty_watermark) {
32414- atomic_inc(&pool->req_ser);
32415+ atomic_inc_unchecked(&pool->req_ser);
32416 wake_up_process(pool->thread);
32417 }
32418 }
32419diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32420index 57e07c6..56d09d4 100644
32421--- a/drivers/infiniband/hw/cxgb4/mem.c
32422+++ b/drivers/infiniband/hw/cxgb4/mem.c
32423@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32424 int err;
32425 struct fw_ri_tpte tpt;
32426 u32 stag_idx;
32427- static atomic_t key;
32428+ static atomic_unchecked_t key;
32429
32430 if (c4iw_fatal_error(rdev))
32431 return -EIO;
32432@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32433 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32434 rdev->stats.stag.max = rdev->stats.stag.cur;
32435 mutex_unlock(&rdev->stats.lock);
32436- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32437+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32438 }
32439 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32440 __func__, stag_state, type, pdid, stag_idx);
32441diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32442index 79b3dbc..96e5fcc 100644
32443--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32444+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32445@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32446 struct ib_atomic_eth *ateth;
32447 struct ipath_ack_entry *e;
32448 u64 vaddr;
32449- atomic64_t *maddr;
32450+ atomic64_unchecked_t *maddr;
32451 u64 sdata;
32452 u32 rkey;
32453 u8 next;
32454@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32455 IB_ACCESS_REMOTE_ATOMIC)))
32456 goto nack_acc_unlck;
32457 /* Perform atomic OP and save result. */
32458- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32459+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32460 sdata = be64_to_cpu(ateth->swap_data);
32461 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32462 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32463- (u64) atomic64_add_return(sdata, maddr) - sdata :
32464+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32465 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32466 be64_to_cpu(ateth->compare_data),
32467 sdata);
32468diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32469index 1f95bba..9530f87 100644
32470--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32471+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32472@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32473 unsigned long flags;
32474 struct ib_wc wc;
32475 u64 sdata;
32476- atomic64_t *maddr;
32477+ atomic64_unchecked_t *maddr;
32478 enum ib_wc_status send_status;
32479
32480 /*
32481@@ -382,11 +382,11 @@ again:
32482 IB_ACCESS_REMOTE_ATOMIC)))
32483 goto acc_err;
32484 /* Perform atomic OP and save result. */
32485- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32486+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32487 sdata = wqe->wr.wr.atomic.compare_add;
32488 *(u64 *) sqp->s_sge.sge.vaddr =
32489 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32490- (u64) atomic64_add_return(sdata, maddr) - sdata :
32491+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32492 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32493 sdata, wqe->wr.wr.atomic.swap);
32494 goto send_comp;
32495diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32496index 7140199..da60063 100644
32497--- a/drivers/infiniband/hw/nes/nes.c
32498+++ b/drivers/infiniband/hw/nes/nes.c
32499@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32500 LIST_HEAD(nes_adapter_list);
32501 static LIST_HEAD(nes_dev_list);
32502
32503-atomic_t qps_destroyed;
32504+atomic_unchecked_t qps_destroyed;
32505
32506 static unsigned int ee_flsh_adapter;
32507 static unsigned int sysfs_nonidx_addr;
32508@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32509 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32510 struct nes_adapter *nesadapter = nesdev->nesadapter;
32511
32512- atomic_inc(&qps_destroyed);
32513+ atomic_inc_unchecked(&qps_destroyed);
32514
32515 /* Free the control structures */
32516
32517diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32518index c438e46..ca30356 100644
32519--- a/drivers/infiniband/hw/nes/nes.h
32520+++ b/drivers/infiniband/hw/nes/nes.h
32521@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32522 extern unsigned int wqm_quanta;
32523 extern struct list_head nes_adapter_list;
32524
32525-extern atomic_t cm_connects;
32526-extern atomic_t cm_accepts;
32527-extern atomic_t cm_disconnects;
32528-extern atomic_t cm_closes;
32529-extern atomic_t cm_connecteds;
32530-extern atomic_t cm_connect_reqs;
32531-extern atomic_t cm_rejects;
32532-extern atomic_t mod_qp_timouts;
32533-extern atomic_t qps_created;
32534-extern atomic_t qps_destroyed;
32535-extern atomic_t sw_qps_destroyed;
32536+extern atomic_unchecked_t cm_connects;
32537+extern atomic_unchecked_t cm_accepts;
32538+extern atomic_unchecked_t cm_disconnects;
32539+extern atomic_unchecked_t cm_closes;
32540+extern atomic_unchecked_t cm_connecteds;
32541+extern atomic_unchecked_t cm_connect_reqs;
32542+extern atomic_unchecked_t cm_rejects;
32543+extern atomic_unchecked_t mod_qp_timouts;
32544+extern atomic_unchecked_t qps_created;
32545+extern atomic_unchecked_t qps_destroyed;
32546+extern atomic_unchecked_t sw_qps_destroyed;
32547 extern u32 mh_detected;
32548 extern u32 mh_pauses_sent;
32549 extern u32 cm_packets_sent;
32550@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32551 extern u32 cm_packets_received;
32552 extern u32 cm_packets_dropped;
32553 extern u32 cm_packets_retrans;
32554-extern atomic_t cm_listens_created;
32555-extern atomic_t cm_listens_destroyed;
32556+extern atomic_unchecked_t cm_listens_created;
32557+extern atomic_unchecked_t cm_listens_destroyed;
32558 extern u32 cm_backlog_drops;
32559-extern atomic_t cm_loopbacks;
32560-extern atomic_t cm_nodes_created;
32561-extern atomic_t cm_nodes_destroyed;
32562-extern atomic_t cm_accel_dropped_pkts;
32563-extern atomic_t cm_resets_recvd;
32564-extern atomic_t pau_qps_created;
32565-extern atomic_t pau_qps_destroyed;
32566+extern atomic_unchecked_t cm_loopbacks;
32567+extern atomic_unchecked_t cm_nodes_created;
32568+extern atomic_unchecked_t cm_nodes_destroyed;
32569+extern atomic_unchecked_t cm_accel_dropped_pkts;
32570+extern atomic_unchecked_t cm_resets_recvd;
32571+extern atomic_unchecked_t pau_qps_created;
32572+extern atomic_unchecked_t pau_qps_destroyed;
32573
32574 extern u32 int_mod_timer_init;
32575 extern u32 int_mod_cq_depth_256;
32576diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32577index 020e95c..fbb3450 100644
32578--- a/drivers/infiniband/hw/nes/nes_cm.c
32579+++ b/drivers/infiniband/hw/nes/nes_cm.c
32580@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32581 u32 cm_packets_retrans;
32582 u32 cm_packets_created;
32583 u32 cm_packets_received;
32584-atomic_t cm_listens_created;
32585-atomic_t cm_listens_destroyed;
32586+atomic_unchecked_t cm_listens_created;
32587+atomic_unchecked_t cm_listens_destroyed;
32588 u32 cm_backlog_drops;
32589-atomic_t cm_loopbacks;
32590-atomic_t cm_nodes_created;
32591-atomic_t cm_nodes_destroyed;
32592-atomic_t cm_accel_dropped_pkts;
32593-atomic_t cm_resets_recvd;
32594+atomic_unchecked_t cm_loopbacks;
32595+atomic_unchecked_t cm_nodes_created;
32596+atomic_unchecked_t cm_nodes_destroyed;
32597+atomic_unchecked_t cm_accel_dropped_pkts;
32598+atomic_unchecked_t cm_resets_recvd;
32599
32600 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32601 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32602@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32603
32604 static struct nes_cm_core *g_cm_core;
32605
32606-atomic_t cm_connects;
32607-atomic_t cm_accepts;
32608-atomic_t cm_disconnects;
32609-atomic_t cm_closes;
32610-atomic_t cm_connecteds;
32611-atomic_t cm_connect_reqs;
32612-atomic_t cm_rejects;
32613+atomic_unchecked_t cm_connects;
32614+atomic_unchecked_t cm_accepts;
32615+atomic_unchecked_t cm_disconnects;
32616+atomic_unchecked_t cm_closes;
32617+atomic_unchecked_t cm_connecteds;
32618+atomic_unchecked_t cm_connect_reqs;
32619+atomic_unchecked_t cm_rejects;
32620
32621 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32622 {
32623@@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32624 kfree(listener);
32625 listener = NULL;
32626 ret = 0;
32627- atomic_inc(&cm_listens_destroyed);
32628+ atomic_inc_unchecked(&cm_listens_destroyed);
32629 } else {
32630 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32631 }
32632@@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32633 cm_node->rem_mac);
32634
32635 add_hte_node(cm_core, cm_node);
32636- atomic_inc(&cm_nodes_created);
32637+ atomic_inc_unchecked(&cm_nodes_created);
32638
32639 return cm_node;
32640 }
32641@@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32642 }
32643
32644 atomic_dec(&cm_core->node_cnt);
32645- atomic_inc(&cm_nodes_destroyed);
32646+ atomic_inc_unchecked(&cm_nodes_destroyed);
32647 nesqp = cm_node->nesqp;
32648 if (nesqp) {
32649 nesqp->cm_node = NULL;
32650@@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32651
32652 static void drop_packet(struct sk_buff *skb)
32653 {
32654- atomic_inc(&cm_accel_dropped_pkts);
32655+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32656 dev_kfree_skb_any(skb);
32657 }
32658
32659@@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32660 {
32661
32662 int reset = 0; /* whether to send reset in case of err.. */
32663- atomic_inc(&cm_resets_recvd);
32664+ atomic_inc_unchecked(&cm_resets_recvd);
32665 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32666 " refcnt=%d\n", cm_node, cm_node->state,
32667 atomic_read(&cm_node->ref_count));
32668@@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32669 rem_ref_cm_node(cm_node->cm_core, cm_node);
32670 return NULL;
32671 }
32672- atomic_inc(&cm_loopbacks);
32673+ atomic_inc_unchecked(&cm_loopbacks);
32674 loopbackremotenode->loopbackpartner = cm_node;
32675 loopbackremotenode->tcp_cntxt.rcv_wscale =
32676 NES_CM_DEFAULT_RCV_WND_SCALE;
32677@@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32678 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32679 else {
32680 rem_ref_cm_node(cm_core, cm_node);
32681- atomic_inc(&cm_accel_dropped_pkts);
32682+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32683 dev_kfree_skb_any(skb);
32684 }
32685 break;
32686@@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32687
32688 if ((cm_id) && (cm_id->event_handler)) {
32689 if (issue_disconn) {
32690- atomic_inc(&cm_disconnects);
32691+ atomic_inc_unchecked(&cm_disconnects);
32692 cm_event.event = IW_CM_EVENT_DISCONNECT;
32693 cm_event.status = disconn_status;
32694 cm_event.local_addr = cm_id->local_addr;
32695@@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32696 }
32697
32698 if (issue_close) {
32699- atomic_inc(&cm_closes);
32700+ atomic_inc_unchecked(&cm_closes);
32701 nes_disconnect(nesqp, 1);
32702
32703 cm_id->provider_data = nesqp;
32704@@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32705
32706 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32707 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32708- atomic_inc(&cm_accepts);
32709+ atomic_inc_unchecked(&cm_accepts);
32710
32711 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32712 netdev_refcnt_read(nesvnic->netdev));
32713@@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32714 struct nes_cm_core *cm_core;
32715 u8 *start_buff;
32716
32717- atomic_inc(&cm_rejects);
32718+ atomic_inc_unchecked(&cm_rejects);
32719 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32720 loopback = cm_node->loopbackpartner;
32721 cm_core = cm_node->cm_core;
32722@@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32723 ntohl(cm_id->local_addr.sin_addr.s_addr),
32724 ntohs(cm_id->local_addr.sin_port));
32725
32726- atomic_inc(&cm_connects);
32727+ atomic_inc_unchecked(&cm_connects);
32728 nesqp->active_conn = 1;
32729
32730 /* cache the cm_id in the qp */
32731@@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32732 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32733 return err;
32734 }
32735- atomic_inc(&cm_listens_created);
32736+ atomic_inc_unchecked(&cm_listens_created);
32737 }
32738
32739 cm_id->add_ref(cm_id);
32740@@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32741
32742 if (nesqp->destroyed)
32743 return;
32744- atomic_inc(&cm_connecteds);
32745+ atomic_inc_unchecked(&cm_connecteds);
32746 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32747 " local port 0x%04X. jiffies = %lu.\n",
32748 nesqp->hwqp.qp_id,
32749@@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32750
32751 cm_id->add_ref(cm_id);
32752 ret = cm_id->event_handler(cm_id, &cm_event);
32753- atomic_inc(&cm_closes);
32754+ atomic_inc_unchecked(&cm_closes);
32755 cm_event.event = IW_CM_EVENT_CLOSE;
32756 cm_event.status = 0;
32757 cm_event.provider_data = cm_id->provider_data;
32758@@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32759 return;
32760 cm_id = cm_node->cm_id;
32761
32762- atomic_inc(&cm_connect_reqs);
32763+ atomic_inc_unchecked(&cm_connect_reqs);
32764 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32765 cm_node, cm_id, jiffies);
32766
32767@@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32768 return;
32769 cm_id = cm_node->cm_id;
32770
32771- atomic_inc(&cm_connect_reqs);
32772+ atomic_inc_unchecked(&cm_connect_reqs);
32773 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32774 cm_node, cm_id, jiffies);
32775
32776diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32777index 3ba7be3..c81f6ff 100644
32778--- a/drivers/infiniband/hw/nes/nes_mgt.c
32779+++ b/drivers/infiniband/hw/nes/nes_mgt.c
32780@@ -40,8 +40,8 @@
32781 #include "nes.h"
32782 #include "nes_mgt.h"
32783
32784-atomic_t pau_qps_created;
32785-atomic_t pau_qps_destroyed;
32786+atomic_unchecked_t pau_qps_created;
32787+atomic_unchecked_t pau_qps_destroyed;
32788
32789 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32790 {
32791@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32792 {
32793 struct sk_buff *skb;
32794 unsigned long flags;
32795- atomic_inc(&pau_qps_destroyed);
32796+ atomic_inc_unchecked(&pau_qps_destroyed);
32797
32798 /* Free packets that have not yet been forwarded */
32799 /* Lock is acquired by skb_dequeue when removing the skb */
32800@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32801 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32802 skb_queue_head_init(&nesqp->pau_list);
32803 spin_lock_init(&nesqp->pau_lock);
32804- atomic_inc(&pau_qps_created);
32805+ atomic_inc_unchecked(&pau_qps_created);
32806 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32807 }
32808
32809diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32810index f3a3ecf..57d311d 100644
32811--- a/drivers/infiniband/hw/nes/nes_nic.c
32812+++ b/drivers/infiniband/hw/nes/nes_nic.c
32813@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32814 target_stat_values[++index] = mh_detected;
32815 target_stat_values[++index] = mh_pauses_sent;
32816 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32817- target_stat_values[++index] = atomic_read(&cm_connects);
32818- target_stat_values[++index] = atomic_read(&cm_accepts);
32819- target_stat_values[++index] = atomic_read(&cm_disconnects);
32820- target_stat_values[++index] = atomic_read(&cm_connecteds);
32821- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32822- target_stat_values[++index] = atomic_read(&cm_rejects);
32823- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32824- target_stat_values[++index] = atomic_read(&qps_created);
32825- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32826- target_stat_values[++index] = atomic_read(&qps_destroyed);
32827- target_stat_values[++index] = atomic_read(&cm_closes);
32828+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32829+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32830+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32831+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32832+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32833+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32834+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32835+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32836+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32837+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32838+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32839 target_stat_values[++index] = cm_packets_sent;
32840 target_stat_values[++index] = cm_packets_bounced;
32841 target_stat_values[++index] = cm_packets_created;
32842 target_stat_values[++index] = cm_packets_received;
32843 target_stat_values[++index] = cm_packets_dropped;
32844 target_stat_values[++index] = cm_packets_retrans;
32845- target_stat_values[++index] = atomic_read(&cm_listens_created);
32846- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32847+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32848+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32849 target_stat_values[++index] = cm_backlog_drops;
32850- target_stat_values[++index] = atomic_read(&cm_loopbacks);
32851- target_stat_values[++index] = atomic_read(&cm_nodes_created);
32852- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32853- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32854- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32855+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32856+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32857+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32858+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32859+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32860 target_stat_values[++index] = nesadapter->free_4kpbl;
32861 target_stat_values[++index] = nesadapter->free_256pbl;
32862 target_stat_values[++index] = int_mod_timer_init;
32863 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32864 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32865 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32866- target_stat_values[++index] = atomic_read(&pau_qps_created);
32867- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32868+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32869+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32870 }
32871
32872 /**
32873diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32874index 8b8812d..a5e1133 100644
32875--- a/drivers/infiniband/hw/nes/nes_verbs.c
32876+++ b/drivers/infiniband/hw/nes/nes_verbs.c
32877@@ -46,9 +46,9 @@
32878
32879 #include <rdma/ib_umem.h>
32880
32881-atomic_t mod_qp_timouts;
32882-atomic_t qps_created;
32883-atomic_t sw_qps_destroyed;
32884+atomic_unchecked_t mod_qp_timouts;
32885+atomic_unchecked_t qps_created;
32886+atomic_unchecked_t sw_qps_destroyed;
32887
32888 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32889
32890@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32891 if (init_attr->create_flags)
32892 return ERR_PTR(-EINVAL);
32893
32894- atomic_inc(&qps_created);
32895+ atomic_inc_unchecked(&qps_created);
32896 switch (init_attr->qp_type) {
32897 case IB_QPT_RC:
32898 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32899@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32900 struct iw_cm_event cm_event;
32901 int ret = 0;
32902
32903- atomic_inc(&sw_qps_destroyed);
32904+ atomic_inc_unchecked(&sw_qps_destroyed);
32905 nesqp->destroyed = 1;
32906
32907 /* Blow away the connection if it exists. */
32908diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32909index 7b1b8669..4b69f85 100644
32910--- a/drivers/infiniband/hw/qib/qib.h
32911+++ b/drivers/infiniband/hw/qib/qib.h
32912@@ -51,6 +51,7 @@
32913 #include <linux/completion.h>
32914 #include <linux/kref.h>
32915 #include <linux/sched.h>
32916+#include <linux/slab.h>
32917
32918 #include "qib_common.h"
32919 #include "qib_verbs.h"
32920diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32921index da739d9..da1c7f4 100644
32922--- a/drivers/input/gameport/gameport.c
32923+++ b/drivers/input/gameport/gameport.c
32924@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32925 */
32926 static void gameport_init_port(struct gameport *gameport)
32927 {
32928- static atomic_t gameport_no = ATOMIC_INIT(0);
32929+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32930
32931 __module_get(THIS_MODULE);
32932
32933 mutex_init(&gameport->drv_mutex);
32934 device_initialize(&gameport->dev);
32935 dev_set_name(&gameport->dev, "gameport%lu",
32936- (unsigned long)atomic_inc_return(&gameport_no) - 1);
32937+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32938 gameport->dev.bus = &gameport_bus;
32939 gameport->dev.release = gameport_release_port;
32940 if (gameport->parent)
32941diff --git a/drivers/input/input.c b/drivers/input/input.c
32942index 8921c61..f5cd63d 100644
32943--- a/drivers/input/input.c
32944+++ b/drivers/input/input.c
32945@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32946 */
32947 int input_register_device(struct input_dev *dev)
32948 {
32949- static atomic_t input_no = ATOMIC_INIT(0);
32950+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32951 struct input_handler *handler;
32952 const char *path;
32953 int error;
32954@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32955 dev->setkeycode = input_default_setkeycode;
32956
32957 dev_set_name(&dev->dev, "input%ld",
32958- (unsigned long) atomic_inc_return(&input_no) - 1);
32959+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32960
32961 error = device_add(&dev->dev);
32962 if (error)
32963diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32964index 04c69af..5f92d00 100644
32965--- a/drivers/input/joystick/sidewinder.c
32966+++ b/drivers/input/joystick/sidewinder.c
32967@@ -30,6 +30,7 @@
32968 #include <linux/kernel.h>
32969 #include <linux/module.h>
32970 #include <linux/slab.h>
32971+#include <linux/sched.h>
32972 #include <linux/init.h>
32973 #include <linux/input.h>
32974 #include <linux/gameport.h>
32975diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32976index 83811e4..0822b90 100644
32977--- a/drivers/input/joystick/xpad.c
32978+++ b/drivers/input/joystick/xpad.c
32979@@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32980
32981 static int xpad_led_probe(struct usb_xpad *xpad)
32982 {
32983- static atomic_t led_seq = ATOMIC_INIT(0);
32984+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32985 long led_no;
32986 struct xpad_led *led;
32987 struct led_classdev *led_cdev;
32988@@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32989 if (!led)
32990 return -ENOMEM;
32991
32992- led_no = (long)atomic_inc_return(&led_seq) - 1;
32993+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32994
32995 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32996 led->xpad = xpad;
32997diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32998index 0110b5a..d3ad144 100644
32999--- a/drivers/input/mousedev.c
33000+++ b/drivers/input/mousedev.c
33001@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
33002
33003 spin_unlock_irq(&client->packet_lock);
33004
33005- if (copy_to_user(buffer, data, count))
33006+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
33007 return -EFAULT;
33008
33009 return count;
33010diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33011index d0f7533..fb8215b 100644
33012--- a/drivers/input/serio/serio.c
33013+++ b/drivers/input/serio/serio.c
33014@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33015 */
33016 static void serio_init_port(struct serio *serio)
33017 {
33018- static atomic_t serio_no = ATOMIC_INIT(0);
33019+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33020
33021 __module_get(THIS_MODULE);
33022
33023@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33024 mutex_init(&serio->drv_mutex);
33025 device_initialize(&serio->dev);
33026 dev_set_name(&serio->dev, "serio%ld",
33027- (long)atomic_inc_return(&serio_no) - 1);
33028+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
33029 serio->dev.bus = &serio_bus;
33030 serio->dev.release = serio_release_port;
33031 serio->dev.groups = serio_device_attr_groups;
33032diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33033index 38c4bd8..58965d9 100644
33034--- a/drivers/isdn/capi/capi.c
33035+++ b/drivers/isdn/capi/capi.c
33036@@ -83,8 +83,8 @@ struct capiminor {
33037
33038 struct capi20_appl *ap;
33039 u32 ncci;
33040- atomic_t datahandle;
33041- atomic_t msgid;
33042+ atomic_unchecked_t datahandle;
33043+ atomic_unchecked_t msgid;
33044
33045 struct tty_port port;
33046 int ttyinstop;
33047@@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33048 capimsg_setu16(s, 2, mp->ap->applid);
33049 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33050 capimsg_setu8 (s, 5, CAPI_RESP);
33051- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33052+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33053 capimsg_setu32(s, 8, mp->ncci);
33054 capimsg_setu16(s, 12, datahandle);
33055 }
33056@@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33057 mp->outbytes -= len;
33058 spin_unlock_bh(&mp->outlock);
33059
33060- datahandle = atomic_inc_return(&mp->datahandle);
33061+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33062 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33063 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33064 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33065 capimsg_setu16(skb->data, 2, mp->ap->applid);
33066 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33067 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33068- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33069+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33070 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33071 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33072 capimsg_setu16(skb->data, 16, len); /* Data length */
33073diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33074index a6d9fd2..afdb8a3 100644
33075--- a/drivers/isdn/gigaset/interface.c
33076+++ b/drivers/isdn/gigaset/interface.c
33077@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33078 }
33079 tty->driver_data = cs;
33080
33081- ++cs->port.count;
33082+ atomic_inc(&cs->port.count);
33083
33084- if (cs->port.count == 1) {
33085+ if (atomic_read(&cs->port.count) == 1) {
33086 tty_port_tty_set(&cs->port, tty);
33087 tty->low_latency = 1;
33088 }
33089@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33090
33091 if (!cs->connected)
33092 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33093- else if (!cs->port.count)
33094+ else if (!atomic_read(&cs->port.count))
33095 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33096- else if (!--cs->port.count)
33097+ else if (!atomic_dec_return(&cs->port.count))
33098 tty_port_tty_set(&cs->port, NULL);
33099
33100 mutex_unlock(&cs->mutex);
33101diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33102index 821f7ac..28d4030 100644
33103--- a/drivers/isdn/hardware/avm/b1.c
33104+++ b/drivers/isdn/hardware/avm/b1.c
33105@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33106 }
33107 if (left) {
33108 if (t4file->user) {
33109- if (copy_from_user(buf, dp, left))
33110+ if (left > sizeof buf || copy_from_user(buf, dp, left))
33111 return -EFAULT;
33112 } else {
33113 memcpy(buf, dp, left);
33114@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33115 }
33116 if (left) {
33117 if (config->user) {
33118- if (copy_from_user(buf, dp, left))
33119+ if (left > sizeof buf || copy_from_user(buf, dp, left))
33120 return -EFAULT;
33121 } else {
33122 memcpy(buf, dp, left);
33123diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33124index dd6b53a..19d9ee6 100644
33125--- a/drivers/isdn/hardware/eicon/divasync.h
33126+++ b/drivers/isdn/hardware/eicon/divasync.h
33127@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33128 } diva_didd_add_adapter_t;
33129 typedef struct _diva_didd_remove_adapter {
33130 IDI_CALL p_request;
33131-} diva_didd_remove_adapter_t;
33132+} __no_const diva_didd_remove_adapter_t;
33133 typedef struct _diva_didd_read_adapter_array {
33134 void *buffer;
33135 dword length;
33136diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33137index d303e65..28bcb7b 100644
33138--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33139+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33140@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33141 typedef struct _diva_os_idi_adapter_interface {
33142 diva_init_card_proc_t cleanup_adapter_proc;
33143 diva_cmd_card_proc_t cmd_proc;
33144-} diva_os_idi_adapter_interface_t;
33145+} __no_const diva_os_idi_adapter_interface_t;
33146
33147 typedef struct _diva_os_xdi_adapter {
33148 struct list_head link;
33149diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33150index 7bc5067..fd36232 100644
33151--- a/drivers/isdn/i4l/isdn_tty.c
33152+++ b/drivers/isdn/i4l/isdn_tty.c
33153@@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33154 port = &info->port;
33155 #ifdef ISDN_DEBUG_MODEM_OPEN
33156 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33157- port->count);
33158+ atomic_read(&port->count))
33159 #endif
33160- port->count++;
33161+ atomic_inc(&port->count);
33162 tty->driver_data = info;
33163 port->tty = tty;
33164 tty->port = port;
33165@@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33166 #endif
33167 return;
33168 }
33169- if ((tty->count == 1) && (port->count != 1)) {
33170+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33171 /*
33172 * Uh, oh. tty->count is 1, which means that the tty
33173 * structure will be freed. Info->count should always
33174@@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33175 * serial port won't be shutdown.
33176 */
33177 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33178- "info->count is %d\n", port->count);
33179- port->count = 1;
33180+ "info->count is %d\n", atomic_read(&port->count));
33181+ atomic_set(&port->count, 1);
33182 }
33183- if (--port->count < 0) {
33184+ if (atomic_dec_return(&port->count) < 0) {
33185 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33186- info->line, port->count);
33187- port->count = 0;
33188+ info->line, atomic_read(&port->count));
33189+ atomic_set(&port->count, 0);
33190 }
33191- if (port->count) {
33192+ if (atomic_read(&port->count)) {
33193 #ifdef ISDN_DEBUG_MODEM_OPEN
33194 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33195 #endif
33196@@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33197 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33198 return;
33199 isdn_tty_shutdown(info);
33200- port->count = 0;
33201+ atomic_set(&port->count, 0);
33202 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33203 port->tty = NULL;
33204 wake_up_interruptible(&port->open_wait);
33205@@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33206 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33207 modem_info *info = &dev->mdm.info[i];
33208
33209- if (info->port.count == 0)
33210+ if (atomic_read(&info->port.count) == 0)
33211 continue;
33212 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33213 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33214diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33215index e74df7c..03a03ba 100644
33216--- a/drivers/isdn/icn/icn.c
33217+++ b/drivers/isdn/icn/icn.c
33218@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33219 if (count > len)
33220 count = len;
33221 if (user) {
33222- if (copy_from_user(msg, buf, count))
33223+ if (count > sizeof msg || copy_from_user(msg, buf, count))
33224 return -EFAULT;
33225 } else
33226 memcpy(msg, buf, count);
33227diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33228index b5fdcb7..5b6c59f 100644
33229--- a/drivers/lguest/core.c
33230+++ b/drivers/lguest/core.c
33231@@ -92,9 +92,17 @@ static __init int map_switcher(void)
33232 * it's worked so far. The end address needs +1 because __get_vm_area
33233 * allocates an extra guard page, so we need space for that.
33234 */
33235+
33236+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33237+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33238+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33239+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33240+#else
33241 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33242 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33243 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33244+#endif
33245+
33246 if (!switcher_vma) {
33247 err = -ENOMEM;
33248 printk("lguest: could not map switcher pages high\n");
33249@@ -119,7 +127,7 @@ static __init int map_switcher(void)
33250 * Now the Switcher is mapped at the right address, we can't fail!
33251 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33252 */
33253- memcpy(switcher_vma->addr, start_switcher_text,
33254+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33255 end_switcher_text - start_switcher_text);
33256
33257 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33258diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33259index 39809035..ce25c5e 100644
33260--- a/drivers/lguest/x86/core.c
33261+++ b/drivers/lguest/x86/core.c
33262@@ -59,7 +59,7 @@ static struct {
33263 /* Offset from where switcher.S was compiled to where we've copied it */
33264 static unsigned long switcher_offset(void)
33265 {
33266- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33267+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33268 }
33269
33270 /* This cpu's struct lguest_pages. */
33271@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33272 * These copies are pretty cheap, so we do them unconditionally: */
33273 /* Save the current Host top-level page directory.
33274 */
33275+
33276+#ifdef CONFIG_PAX_PER_CPU_PGD
33277+ pages->state.host_cr3 = read_cr3();
33278+#else
33279 pages->state.host_cr3 = __pa(current->mm->pgd);
33280+#endif
33281+
33282 /*
33283 * Set up the Guest's page tables to see this CPU's pages (and no
33284 * other CPU's pages).
33285@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33286 * compiled-in switcher code and the high-mapped copy we just made.
33287 */
33288 for (i = 0; i < IDT_ENTRIES; i++)
33289- default_idt_entries[i] += switcher_offset();
33290+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33291
33292 /*
33293 * Set up the Switcher's per-cpu areas.
33294@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33295 * it will be undisturbed when we switch. To change %cs and jump we
33296 * need this structure to feed to Intel's "lcall" instruction.
33297 */
33298- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33299+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33300 lguest_entry.segment = LGUEST_CS;
33301
33302 /*
33303diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33304index 40634b0..4f5855e 100644
33305--- a/drivers/lguest/x86/switcher_32.S
33306+++ b/drivers/lguest/x86/switcher_32.S
33307@@ -87,6 +87,7 @@
33308 #include <asm/page.h>
33309 #include <asm/segment.h>
33310 #include <asm/lguest.h>
33311+#include <asm/processor-flags.h>
33312
33313 // We mark the start of the code to copy
33314 // It's placed in .text tho it's never run here
33315@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33316 // Changes type when we load it: damn Intel!
33317 // For after we switch over our page tables
33318 // That entry will be read-only: we'd crash.
33319+
33320+#ifdef CONFIG_PAX_KERNEXEC
33321+ mov %cr0, %edx
33322+ xor $X86_CR0_WP, %edx
33323+ mov %edx, %cr0
33324+#endif
33325+
33326 movl $(GDT_ENTRY_TSS*8), %edx
33327 ltr %dx
33328
33329@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33330 // Let's clear it again for our return.
33331 // The GDT descriptor of the Host
33332 // Points to the table after two "size" bytes
33333- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33334+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33335 // Clear "used" from type field (byte 5, bit 2)
33336- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33337+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33338+
33339+#ifdef CONFIG_PAX_KERNEXEC
33340+ mov %cr0, %eax
33341+ xor $X86_CR0_WP, %eax
33342+ mov %eax, %cr0
33343+#endif
33344
33345 // Once our page table's switched, the Guest is live!
33346 // The Host fades as we run this final step.
33347@@ -295,13 +309,12 @@ deliver_to_host:
33348 // I consulted gcc, and it gave
33349 // These instructions, which I gladly credit:
33350 leal (%edx,%ebx,8), %eax
33351- movzwl (%eax),%edx
33352- movl 4(%eax), %eax
33353- xorw %ax, %ax
33354- orl %eax, %edx
33355+ movl 4(%eax), %edx
33356+ movw (%eax), %dx
33357 // Now the address of the handler's in %edx
33358 // We call it now: its "iret" drops us home.
33359- jmp *%edx
33360+ ljmp $__KERNEL_CS, $1f
33361+1: jmp *%edx
33362
33363 // Every interrupt can come to us here
33364 // But we must truly tell each apart.
33365diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33366index 20e5c2c..9e849a9 100644
33367--- a/drivers/macintosh/macio_asic.c
33368+++ b/drivers/macintosh/macio_asic.c
33369@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33370 * MacIO is matched against any Apple ID, it's probe() function
33371 * will then decide wether it applies or not
33372 */
33373-static const struct pci_device_id __devinitdata pci_ids [] = { {
33374+static const struct pci_device_id __devinitconst pci_ids [] = { {
33375 .vendor = PCI_VENDOR_ID_APPLE,
33376 .device = PCI_ANY_ID,
33377 .subvendor = PCI_ANY_ID,
33378diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33379index 94e7f6b..2f4a0d8 100644
33380--- a/drivers/md/bitmap.c
33381+++ b/drivers/md/bitmap.c
33382@@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33383 chunk_kb ? "KB" : "B");
33384 if (bitmap->storage.file) {
33385 seq_printf(seq, ", file: ");
33386- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33387+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33388 }
33389
33390 seq_printf(seq, "\n");
33391diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33392index afd9598..528d8f9 100644
33393--- a/drivers/md/dm-ioctl.c
33394+++ b/drivers/md/dm-ioctl.c
33395@@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33396 cmd == DM_LIST_VERSIONS_CMD)
33397 return 0;
33398
33399- if ((cmd == DM_DEV_CREATE_CMD)) {
33400+ if (cmd == DM_DEV_CREATE_CMD) {
33401 if (!*param->name) {
33402 DMWARN("name not supplied when creating device");
33403 return -EINVAL;
33404diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33405index bc5ddba8..b961159 100644
33406--- a/drivers/md/dm-raid1.c
33407+++ b/drivers/md/dm-raid1.c
33408@@ -40,7 +40,7 @@ enum dm_raid1_error {
33409
33410 struct mirror {
33411 struct mirror_set *ms;
33412- atomic_t error_count;
33413+ atomic_unchecked_t error_count;
33414 unsigned long error_type;
33415 struct dm_dev *dev;
33416 sector_t offset;
33417@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33418 struct mirror *m;
33419
33420 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33421- if (!atomic_read(&m->error_count))
33422+ if (!atomic_read_unchecked(&m->error_count))
33423 return m;
33424
33425 return NULL;
33426@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33427 * simple way to tell if a device has encountered
33428 * errors.
33429 */
33430- atomic_inc(&m->error_count);
33431+ atomic_inc_unchecked(&m->error_count);
33432
33433 if (test_and_set_bit(error_type, &m->error_type))
33434 return;
33435@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33436 struct mirror *m = get_default_mirror(ms);
33437
33438 do {
33439- if (likely(!atomic_read(&m->error_count)))
33440+ if (likely(!atomic_read_unchecked(&m->error_count)))
33441 return m;
33442
33443 if (m-- == ms->mirror)
33444@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33445 {
33446 struct mirror *default_mirror = get_default_mirror(m->ms);
33447
33448- return !atomic_read(&default_mirror->error_count);
33449+ return !atomic_read_unchecked(&default_mirror->error_count);
33450 }
33451
33452 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33453@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33454 */
33455 if (likely(region_in_sync(ms, region, 1)))
33456 m = choose_mirror(ms, bio->bi_sector);
33457- else if (m && atomic_read(&m->error_count))
33458+ else if (m && atomic_read_unchecked(&m->error_count))
33459 m = NULL;
33460
33461 if (likely(m))
33462@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33463 }
33464
33465 ms->mirror[mirror].ms = ms;
33466- atomic_set(&(ms->mirror[mirror].error_count), 0);
33467+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33468 ms->mirror[mirror].error_type = 0;
33469 ms->mirror[mirror].offset = offset;
33470
33471@@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33472 */
33473 static char device_status_char(struct mirror *m)
33474 {
33475- if (!atomic_read(&(m->error_count)))
33476+ if (!atomic_read_unchecked(&(m->error_count)))
33477 return 'A';
33478
33479 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33480diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33481index a087bf2..4c94786 100644
33482--- a/drivers/md/dm-stripe.c
33483+++ b/drivers/md/dm-stripe.c
33484@@ -20,7 +20,7 @@ struct stripe {
33485 struct dm_dev *dev;
33486 sector_t physical_start;
33487
33488- atomic_t error_count;
33489+ atomic_unchecked_t error_count;
33490 };
33491
33492 struct stripe_c {
33493@@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33494 kfree(sc);
33495 return r;
33496 }
33497- atomic_set(&(sc->stripe[i].error_count), 0);
33498+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33499 }
33500
33501 ti->private = sc;
33502@@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33503 DMEMIT("%d ", sc->stripes);
33504 for (i = 0; i < sc->stripes; i++) {
33505 DMEMIT("%s ", sc->stripe[i].dev->name);
33506- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33507+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33508 'D' : 'A';
33509 }
33510 buffer[i] = '\0';
33511@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33512 */
33513 for (i = 0; i < sc->stripes; i++)
33514 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33515- atomic_inc(&(sc->stripe[i].error_count));
33516- if (atomic_read(&(sc->stripe[i].error_count)) <
33517+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33518+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33519 DM_IO_ERROR_THRESHOLD)
33520 schedule_work(&sc->trigger_event);
33521 }
33522diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33523index 100368e..64262ce 100644
33524--- a/drivers/md/dm-table.c
33525+++ b/drivers/md/dm-table.c
33526@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33527 if (!dev_size)
33528 return 0;
33529
33530- if ((start >= dev_size) || (start + len > dev_size)) {
33531+ if ((start >= dev_size) || (len > dev_size - start)) {
33532 DMWARN("%s: %s too small for target: "
33533 "start=%llu, len=%llu, dev_size=%llu",
33534 dm_device_name(ti->table->md), bdevname(bdev, b),
33535diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33536index 693e149..b7e0fde 100644
33537--- a/drivers/md/dm-thin-metadata.c
33538+++ b/drivers/md/dm-thin-metadata.c
33539@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33540 {
33541 pmd->info.tm = pmd->tm;
33542 pmd->info.levels = 2;
33543- pmd->info.value_type.context = pmd->data_sm;
33544+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33545 pmd->info.value_type.size = sizeof(__le64);
33546 pmd->info.value_type.inc = data_block_inc;
33547 pmd->info.value_type.dec = data_block_dec;
33548@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33549
33550 pmd->bl_info.tm = pmd->tm;
33551 pmd->bl_info.levels = 1;
33552- pmd->bl_info.value_type.context = pmd->data_sm;
33553+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33554 pmd->bl_info.value_type.size = sizeof(__le64);
33555 pmd->bl_info.value_type.inc = data_block_inc;
33556 pmd->bl_info.value_type.dec = data_block_dec;
33557diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33558index 67ffa39..cb3b1dd 100644
33559--- a/drivers/md/dm.c
33560+++ b/drivers/md/dm.c
33561@@ -176,9 +176,9 @@ struct mapped_device {
33562 /*
33563 * Event handling.
33564 */
33565- atomic_t event_nr;
33566+ atomic_unchecked_t event_nr;
33567 wait_queue_head_t eventq;
33568- atomic_t uevent_seq;
33569+ atomic_unchecked_t uevent_seq;
33570 struct list_head uevent_list;
33571 spinlock_t uevent_lock; /* Protect access to uevent_list */
33572
33573@@ -1887,8 +1887,8 @@ static struct mapped_device *alloc_dev(int minor)
33574 rwlock_init(&md->map_lock);
33575 atomic_set(&md->holders, 1);
33576 atomic_set(&md->open_count, 0);
33577- atomic_set(&md->event_nr, 0);
33578- atomic_set(&md->uevent_seq, 0);
33579+ atomic_set_unchecked(&md->event_nr, 0);
33580+ atomic_set_unchecked(&md->uevent_seq, 0);
33581 INIT_LIST_HEAD(&md->uevent_list);
33582 spin_lock_init(&md->uevent_lock);
33583
33584@@ -2022,7 +2022,7 @@ static void event_callback(void *context)
33585
33586 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33587
33588- atomic_inc(&md->event_nr);
33589+ atomic_inc_unchecked(&md->event_nr);
33590 wake_up(&md->eventq);
33591 }
33592
33593@@ -2677,18 +2677,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33594
33595 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33596 {
33597- return atomic_add_return(1, &md->uevent_seq);
33598+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33599 }
33600
33601 uint32_t dm_get_event_nr(struct mapped_device *md)
33602 {
33603- return atomic_read(&md->event_nr);
33604+ return atomic_read_unchecked(&md->event_nr);
33605 }
33606
33607 int dm_wait_event(struct mapped_device *md, int event_nr)
33608 {
33609 return wait_event_interruptible(md->eventq,
33610- (event_nr != atomic_read(&md->event_nr)));
33611+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33612 }
33613
33614 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33615diff --git a/drivers/md/md.c b/drivers/md/md.c
33616index 308e87b..7f365d6 100644
33617--- a/drivers/md/md.c
33618+++ b/drivers/md/md.c
33619@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33620 * start build, activate spare
33621 */
33622 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33623-static atomic_t md_event_count;
33624+static atomic_unchecked_t md_event_count;
33625 void md_new_event(struct mddev *mddev)
33626 {
33627- atomic_inc(&md_event_count);
33628+ atomic_inc_unchecked(&md_event_count);
33629 wake_up(&md_event_waiters);
33630 }
33631 EXPORT_SYMBOL_GPL(md_new_event);
33632@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33633 */
33634 static void md_new_event_inintr(struct mddev *mddev)
33635 {
33636- atomic_inc(&md_event_count);
33637+ atomic_inc_unchecked(&md_event_count);
33638 wake_up(&md_event_waiters);
33639 }
33640
33641@@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33642 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33643 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33644 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33645- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33646+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33647
33648 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33649 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33650@@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33651 else
33652 sb->resync_offset = cpu_to_le64(0);
33653
33654- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33655+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33656
33657 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33658 sb->size = cpu_to_le64(mddev->dev_sectors);
33659@@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33660 static ssize_t
33661 errors_show(struct md_rdev *rdev, char *page)
33662 {
33663- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33664+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33665 }
33666
33667 static ssize_t
33668@@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33669 char *e;
33670 unsigned long n = simple_strtoul(buf, &e, 10);
33671 if (*buf && (*e == 0 || *e == '\n')) {
33672- atomic_set(&rdev->corrected_errors, n);
33673+ atomic_set_unchecked(&rdev->corrected_errors, n);
33674 return len;
33675 }
33676 return -EINVAL;
33677@@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33678 rdev->sb_loaded = 0;
33679 rdev->bb_page = NULL;
33680 atomic_set(&rdev->nr_pending, 0);
33681- atomic_set(&rdev->read_errors, 0);
33682- atomic_set(&rdev->corrected_errors, 0);
33683+ atomic_set_unchecked(&rdev->read_errors, 0);
33684+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33685
33686 INIT_LIST_HEAD(&rdev->same_set);
33687 init_waitqueue_head(&rdev->blocked_wait);
33688@@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33689
33690 spin_unlock(&pers_lock);
33691 seq_printf(seq, "\n");
33692- seq->poll_event = atomic_read(&md_event_count);
33693+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33694 return 0;
33695 }
33696 if (v == (void*)2) {
33697@@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33698 return error;
33699
33700 seq = file->private_data;
33701- seq->poll_event = atomic_read(&md_event_count);
33702+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33703 return error;
33704 }
33705
33706@@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33707 /* always allow read */
33708 mask = POLLIN | POLLRDNORM;
33709
33710- if (seq->poll_event != atomic_read(&md_event_count))
33711+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33712 mask |= POLLERR | POLLPRI;
33713 return mask;
33714 }
33715@@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33716 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33717 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33718 (int)part_stat_read(&disk->part0, sectors[1]) -
33719- atomic_read(&disk->sync_io);
33720+ atomic_read_unchecked(&disk->sync_io);
33721 /* sync IO will cause sync_io to increase before the disk_stats
33722 * as sync_io is counted when a request starts, and
33723 * disk_stats is counted when it completes.
33724diff --git a/drivers/md/md.h b/drivers/md/md.h
33725index f385b03..b600be8 100644
33726--- a/drivers/md/md.h
33727+++ b/drivers/md/md.h
33728@@ -94,13 +94,13 @@ struct md_rdev {
33729 * only maintained for arrays that
33730 * support hot removal
33731 */
33732- atomic_t read_errors; /* number of consecutive read errors that
33733+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
33734 * we have tried to ignore.
33735 */
33736 struct timespec last_read_error; /* monotonic time since our
33737 * last read error
33738 */
33739- atomic_t corrected_errors; /* number of corrected read errors,
33740+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33741 * for reporting to userspace and storing
33742 * in superblock.
33743 */
33744@@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33745
33746 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33747 {
33748- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33749+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33750 }
33751
33752 struct md_personality
33753diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33754index f6d29e6..7917f5e 100644
33755--- a/drivers/md/persistent-data/dm-space-map-disk.c
33756+++ b/drivers/md/persistent-data/dm-space-map-disk.c
33757@@ -22,7 +22,7 @@
33758 * Space map interface.
33759 */
33760 struct sm_disk {
33761- struct dm_space_map sm;
33762+ dm_space_map_no_const sm;
33763
33764 struct ll_disk ll;
33765 struct ll_disk old_ll;
33766diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33767index e89ae5e..062e4c2 100644
33768--- a/drivers/md/persistent-data/dm-space-map-metadata.c
33769+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33770@@ -43,7 +43,7 @@ struct block_op {
33771 };
33772
33773 struct sm_metadata {
33774- struct dm_space_map sm;
33775+ dm_space_map_no_const sm;
33776
33777 struct ll_disk ll;
33778 struct ll_disk old_ll;
33779diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33780index 1cbfc6b..56e1dbb 100644
33781--- a/drivers/md/persistent-data/dm-space-map.h
33782+++ b/drivers/md/persistent-data/dm-space-map.h
33783@@ -60,6 +60,7 @@ struct dm_space_map {
33784 int (*root_size)(struct dm_space_map *sm, size_t *result);
33785 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33786 };
33787+typedef struct dm_space_map __no_const dm_space_map_no_const;
33788
33789 /*----------------------------------------------------------------*/
33790
33791diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33792index 611b5f7..cee0bfb 100644
33793--- a/drivers/md/raid1.c
33794+++ b/drivers/md/raid1.c
33795@@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33796 if (r1_sync_page_io(rdev, sect, s,
33797 bio->bi_io_vec[idx].bv_page,
33798 READ) != 0)
33799- atomic_add(s, &rdev->corrected_errors);
33800+ atomic_add_unchecked(s, &rdev->corrected_errors);
33801 }
33802 sectors -= s;
33803 sect += s;
33804@@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33805 test_bit(In_sync, &rdev->flags)) {
33806 if (r1_sync_page_io(rdev, sect, s,
33807 conf->tmppage, READ)) {
33808- atomic_add(s, &rdev->corrected_errors);
33809+ atomic_add_unchecked(s, &rdev->corrected_errors);
33810 printk(KERN_INFO
33811 "md/raid1:%s: read error corrected "
33812 "(%d sectors at %llu on %s)\n",
33813diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33814index 0138a72..eab8fc6 100644
33815--- a/drivers/md/raid10.c
33816+++ b/drivers/md/raid10.c
33817@@ -1810,7 +1810,7 @@ static void end_sync_read(struct bio *bio, int error)
33818 /* The write handler will notice the lack of
33819 * R10BIO_Uptodate and record any errors etc
33820 */
33821- atomic_add(r10_bio->sectors,
33822+ atomic_add_unchecked(r10_bio->sectors,
33823 &conf->mirrors[d].rdev->corrected_errors);
33824
33825 /* for reconstruct, we always reschedule after a read.
33826@@ -2159,7 +2159,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33827 {
33828 struct timespec cur_time_mon;
33829 unsigned long hours_since_last;
33830- unsigned int read_errors = atomic_read(&rdev->read_errors);
33831+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33832
33833 ktime_get_ts(&cur_time_mon);
33834
33835@@ -2181,9 +2181,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33836 * overflowing the shift of read_errors by hours_since_last.
33837 */
33838 if (hours_since_last >= 8 * sizeof(read_errors))
33839- atomic_set(&rdev->read_errors, 0);
33840+ atomic_set_unchecked(&rdev->read_errors, 0);
33841 else
33842- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33843+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33844 }
33845
33846 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33847@@ -2237,8 +2237,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33848 return;
33849
33850 check_decay_read_errors(mddev, rdev);
33851- atomic_inc(&rdev->read_errors);
33852- if (atomic_read(&rdev->read_errors) > max_read_errors) {
33853+ atomic_inc_unchecked(&rdev->read_errors);
33854+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33855 char b[BDEVNAME_SIZE];
33856 bdevname(rdev->bdev, b);
33857
33858@@ -2246,7 +2246,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33859 "md/raid10:%s: %s: Raid device exceeded "
33860 "read_error threshold [cur %d:max %d]\n",
33861 mdname(mddev), b,
33862- atomic_read(&rdev->read_errors), max_read_errors);
33863+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33864 printk(KERN_NOTICE
33865 "md/raid10:%s: %s: Failing raid device\n",
33866 mdname(mddev), b);
33867@@ -2401,7 +2401,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33868 sect +
33869 choose_data_offset(r10_bio, rdev)),
33870 bdevname(rdev->bdev, b));
33871- atomic_add(s, &rdev->corrected_errors);
33872+ atomic_add_unchecked(s, &rdev->corrected_errors);
33873 }
33874
33875 rdev_dec_pending(rdev, mddev);
33876diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33877index 0689173..35df76c 100644
33878--- a/drivers/md/raid5.c
33879+++ b/drivers/md/raid5.c
33880@@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
33881 mdname(conf->mddev), STRIPE_SECTORS,
33882 (unsigned long long)s,
33883 bdevname(rdev->bdev, b));
33884- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33885+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33886 clear_bit(R5_ReadError, &sh->dev[i].flags);
33887 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33888 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
33889 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
33890
33891- if (atomic_read(&rdev->read_errors))
33892- atomic_set(&rdev->read_errors, 0);
33893+ if (atomic_read_unchecked(&rdev->read_errors))
33894+ atomic_set_unchecked(&rdev->read_errors, 0);
33895 } else {
33896 const char *bdn = bdevname(rdev->bdev, b);
33897 int retry = 0;
33898 int set_bad = 0;
33899
33900 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33901- atomic_inc(&rdev->read_errors);
33902+ atomic_inc_unchecked(&rdev->read_errors);
33903 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33904 printk_ratelimited(
33905 KERN_WARNING
33906@@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33907 mdname(conf->mddev),
33908 (unsigned long long)s,
33909 bdn);
33910- } else if (atomic_read(&rdev->read_errors)
33911+ } else if (atomic_read_unchecked(&rdev->read_errors)
33912 > conf->max_nr_stripes)
33913 printk(KERN_WARNING
33914 "md/raid:%s: Too many read errors, failing device %s.\n",
33915diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33916index ebf3f05..b1f3e77 100644
33917--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33918+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33919@@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33920 .subvendor = _subvend, .subdevice = _subdev, \
33921 .driver_data = (unsigned long)&_driverdata }
33922
33923-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33924+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33925 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33926 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33927 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33928diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33929index fa7188a..04a045e 100644
33930--- a/drivers/media/dvb/dvb-core/dvb_demux.h
33931+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33932@@ -73,7 +73,7 @@ struct dvb_demux_feed {
33933 union {
33934 dmx_ts_cb ts;
33935 dmx_section_cb sec;
33936- } cb;
33937+ } __no_const cb;
33938
33939 struct dvb_demux *demux;
33940 void *priv;
33941diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33942index 39eab73..60033e7 100644
33943--- a/drivers/media/dvb/dvb-core/dvbdev.c
33944+++ b/drivers/media/dvb/dvb-core/dvbdev.c
33945@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33946 const struct dvb_device *template, void *priv, int type)
33947 {
33948 struct dvb_device *dvbdev;
33949- struct file_operations *dvbdevfops;
33950+ file_operations_no_const *dvbdevfops;
33951 struct device *clsdev;
33952 int minor;
33953 int id;
33954diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33955index 3940bb0..fb3952a 100644
33956--- a/drivers/media/dvb/dvb-usb/cxusb.c
33957+++ b/drivers/media/dvb/dvb-usb/cxusb.c
33958@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33959
33960 struct dib0700_adapter_state {
33961 int (*set_param_save) (struct dvb_frontend *);
33962-};
33963+} __no_const;
33964
33965 static int dib7070_set_param_override(struct dvb_frontend *fe)
33966 {
33967diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33968index 9382895..ac8093c 100644
33969--- a/drivers/media/dvb/dvb-usb/dw2102.c
33970+++ b/drivers/media/dvb/dvb-usb/dw2102.c
33971@@ -95,7 +95,7 @@ struct su3000_state {
33972
33973 struct s6x0_state {
33974 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33975-};
33976+} __no_const;
33977
33978 /* debug */
33979 static int dvb_usb_dw2102_debug;
33980diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33981index 404f63a..4796533 100644
33982--- a/drivers/media/dvb/frontends/dib3000.h
33983+++ b/drivers/media/dvb/frontends/dib3000.h
33984@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33985 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33986 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33987 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33988-};
33989+} __no_const;
33990
33991 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33992 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33993diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33994index 72ee8de..eae0c80 100644
33995--- a/drivers/media/dvb/ngene/ngene-cards.c
33996+++ b/drivers/media/dvb/ngene/ngene-cards.c
33997@@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
33998
33999 /****************************************************************************/
34000
34001-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
34002+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34003 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34004 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34005 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34006diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34007index 697a421..16c5a5f 100644
34008--- a/drivers/media/radio/radio-cadet.c
34009+++ b/drivers/media/radio/radio-cadet.c
34010@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34011 unsigned char readbuf[RDS_BUFFER];
34012 int i = 0;
34013
34014+ if (count > RDS_BUFFER)
34015+ return -EFAULT;
34016 mutex_lock(&dev->lock);
34017 if (dev->rdsstat == 0)
34018 cadet_start_rds(dev);
34019@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34020 while (i < count && dev->rdsin != dev->rdsout)
34021 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34022
34023- if (i && copy_to_user(data, readbuf, i))
34024+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34025 i = -EFAULT;
34026 unlock:
34027 mutex_unlock(&dev->lock);
34028diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34029index 55cbd78..428b0da 100644
34030--- a/drivers/media/radio/radio-tea5777.h
34031+++ b/drivers/media/radio/radio-tea5777.h
34032@@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34033
34034 struct radio_tea5777 {
34035 struct v4l2_device *v4l2_dev;
34036- struct v4l2_file_operations fops;
34037+ v4l2_file_operations_no_const fops;
34038 struct video_device vd; /* video device */
34039 bool has_am; /* Device can tune to AM freqs */
34040 bool write_before_read; /* must write before read quirk */
34041diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34042index 9cde353..8c6a1c3 100644
34043--- a/drivers/media/video/au0828/au0828.h
34044+++ b/drivers/media/video/au0828/au0828.h
34045@@ -191,7 +191,7 @@ struct au0828_dev {
34046
34047 /* I2C */
34048 struct i2c_adapter i2c_adap;
34049- struct i2c_algorithm i2c_algo;
34050+ i2c_algorithm_no_const i2c_algo;
34051 struct i2c_client i2c_client;
34052 u32 i2c_rc;
34053
34054diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34055index dfac6e3..c26de31 100644
34056--- a/drivers/media/video/cx88/cx88-alsa.c
34057+++ b/drivers/media/video/cx88/cx88-alsa.c
34058@@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34059 * Only boards with eeprom and byte 1 at eeprom=1 have it
34060 */
34061
34062-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34063+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34064 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34065 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34066 {0, }
34067diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34068index 88cf9d9..bbc4b2c 100644
34069--- a/drivers/media/video/omap/omap_vout.c
34070+++ b/drivers/media/video/omap/omap_vout.c
34071@@ -64,7 +64,6 @@ enum omap_vout_channels {
34072 OMAP_VIDEO2,
34073 };
34074
34075-static struct videobuf_queue_ops video_vbq_ops;
34076 /* Variables configurable through module params*/
34077 static u32 video1_numbuffers = 3;
34078 static u32 video2_numbuffers = 3;
34079@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34080 {
34081 struct videobuf_queue *q;
34082 struct omap_vout_device *vout = NULL;
34083+ static struct videobuf_queue_ops video_vbq_ops = {
34084+ .buf_setup = omap_vout_buffer_setup,
34085+ .buf_prepare = omap_vout_buffer_prepare,
34086+ .buf_release = omap_vout_buffer_release,
34087+ .buf_queue = omap_vout_buffer_queue,
34088+ };
34089
34090 vout = video_drvdata(file);
34091 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34092@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34093 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34094
34095 q = &vout->vbq;
34096- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34097- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34098- video_vbq_ops.buf_release = omap_vout_buffer_release;
34099- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34100 spin_lock_init(&vout->vbq_lock);
34101
34102 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34103diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34104index 036952f..80d356d 100644
34105--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34106+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34107@@ -196,7 +196,7 @@ struct pvr2_hdw {
34108
34109 /* I2C stuff */
34110 struct i2c_adapter i2c_adap;
34111- struct i2c_algorithm i2c_algo;
34112+ i2c_algorithm_no_const i2c_algo;
34113 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34114 int i2c_cx25840_hack_state;
34115 int i2c_linked;
34116diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34117index 02194c0..091733b 100644
34118--- a/drivers/media/video/timblogiw.c
34119+++ b/drivers/media/video/timblogiw.c
34120@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34121
34122 /* Platform device functions */
34123
34124-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34125+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34126 .vidioc_querycap = timblogiw_querycap,
34127 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34128 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34129@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34130 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34131 };
34132
34133-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34134+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34135 .owner = THIS_MODULE,
34136 .open = timblogiw_open,
34137 .release = timblogiw_close,
34138diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34139index d99db56..a16b959 100644
34140--- a/drivers/message/fusion/mptbase.c
34141+++ b/drivers/message/fusion/mptbase.c
34142@@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34143 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34144 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34145
34146+#ifdef CONFIG_GRKERNSEC_HIDESYM
34147+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34148+#else
34149 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34150 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34151+#endif
34152+
34153 /*
34154 * Rounding UP to nearest 4-kB boundary here...
34155 */
34156diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34157index 551262e..7551198 100644
34158--- a/drivers/message/fusion/mptsas.c
34159+++ b/drivers/message/fusion/mptsas.c
34160@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34161 return 0;
34162 }
34163
34164+static inline void
34165+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34166+{
34167+ if (phy_info->port_details) {
34168+ phy_info->port_details->rphy = rphy;
34169+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34170+ ioc->name, rphy));
34171+ }
34172+
34173+ if (rphy) {
34174+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34175+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34176+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34177+ ioc->name, rphy, rphy->dev.release));
34178+ }
34179+}
34180+
34181 /* no mutex */
34182 static void
34183 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34184@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34185 return NULL;
34186 }
34187
34188-static inline void
34189-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34190-{
34191- if (phy_info->port_details) {
34192- phy_info->port_details->rphy = rphy;
34193- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34194- ioc->name, rphy));
34195- }
34196-
34197- if (rphy) {
34198- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34199- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34200- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34201- ioc->name, rphy, rphy->dev.release));
34202- }
34203-}
34204-
34205 static inline struct sas_port *
34206 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34207 {
34208diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34209index 0c3ced7..1fe34ec 100644
34210--- a/drivers/message/fusion/mptscsih.c
34211+++ b/drivers/message/fusion/mptscsih.c
34212@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34213
34214 h = shost_priv(SChost);
34215
34216- if (h) {
34217- if (h->info_kbuf == NULL)
34218- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34219- return h->info_kbuf;
34220- h->info_kbuf[0] = '\0';
34221+ if (!h)
34222+ return NULL;
34223
34224- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34225- h->info_kbuf[size-1] = '\0';
34226- }
34227+ if (h->info_kbuf == NULL)
34228+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34229+ return h->info_kbuf;
34230+ h->info_kbuf[0] = '\0';
34231+
34232+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34233+ h->info_kbuf[size-1] = '\0';
34234
34235 return h->info_kbuf;
34236 }
34237diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34238index 8001aa6..b137580 100644
34239--- a/drivers/message/i2o/i2o_proc.c
34240+++ b/drivers/message/i2o/i2o_proc.c
34241@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34242 "Array Controller Device"
34243 };
34244
34245-static char *chtostr(char *tmp, u8 *chars, int n)
34246-{
34247- tmp[0] = 0;
34248- return strncat(tmp, (char *)chars, n);
34249-}
34250-
34251 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34252 char *group)
34253 {
34254@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34255 } *result;
34256
34257 i2o_exec_execute_ddm_table ddm_table;
34258- char tmp[28 + 1];
34259
34260 result = kmalloc(sizeof(*result), GFP_KERNEL);
34261 if (!result)
34262@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34263
34264 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34265 seq_printf(seq, "%-#8x", ddm_table.module_id);
34266- seq_printf(seq, "%-29s",
34267- chtostr(tmp, ddm_table.module_name_version, 28));
34268+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34269 seq_printf(seq, "%9d ", ddm_table.data_size);
34270 seq_printf(seq, "%8d", ddm_table.code_size);
34271
34272@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34273
34274 i2o_driver_result_table *result;
34275 i2o_driver_store_table *dst;
34276- char tmp[28 + 1];
34277
34278 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34279 if (result == NULL)
34280@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34281
34282 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34283 seq_printf(seq, "%-#8x", dst->module_id);
34284- seq_printf(seq, "%-29s",
34285- chtostr(tmp, dst->module_name_version, 28));
34286- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34287+ seq_printf(seq, "%-.28s", dst->module_name_version);
34288+ seq_printf(seq, "%-.8s", dst->date);
34289 seq_printf(seq, "%8d ", dst->module_size);
34290 seq_printf(seq, "%8d ", dst->mpb_size);
34291 seq_printf(seq, "0x%04x", dst->module_flags);
34292@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34293 // == (allow) 512d bytes (max)
34294 static u16 *work16 = (u16 *) work32;
34295 int token;
34296- char tmp[16 + 1];
34297
34298 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34299
34300@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34301 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34302 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34303 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34304- seq_printf(seq, "Vendor info : %s\n",
34305- chtostr(tmp, (u8 *) (work32 + 2), 16));
34306- seq_printf(seq, "Product info : %s\n",
34307- chtostr(tmp, (u8 *) (work32 + 6), 16));
34308- seq_printf(seq, "Description : %s\n",
34309- chtostr(tmp, (u8 *) (work32 + 10), 16));
34310- seq_printf(seq, "Product rev. : %s\n",
34311- chtostr(tmp, (u8 *) (work32 + 14), 8));
34312+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34313+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34314+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34315+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34316
34317 seq_printf(seq, "Serial number : ");
34318 print_serial_number(seq, (u8 *) (work32 + 16),
34319@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34320 u8 pad[256]; // allow up to 256 byte (max) serial number
34321 } result;
34322
34323- char tmp[24 + 1];
34324-
34325 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34326
34327 if (token < 0) {
34328@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34329 }
34330
34331 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34332- seq_printf(seq, "Module name : %s\n",
34333- chtostr(tmp, result.module_name, 24));
34334- seq_printf(seq, "Module revision : %s\n",
34335- chtostr(tmp, result.module_rev, 8));
34336+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
34337+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34338
34339 seq_printf(seq, "Serial number : ");
34340 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34341@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34342 u8 instance_number[4];
34343 } result;
34344
34345- char tmp[64 + 1];
34346-
34347 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34348
34349 if (token < 0) {
34350@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34351 return 0;
34352 }
34353
34354- seq_printf(seq, "Device name : %s\n",
34355- chtostr(tmp, result.device_name, 64));
34356- seq_printf(seq, "Service name : %s\n",
34357- chtostr(tmp, result.service_name, 64));
34358- seq_printf(seq, "Physical name : %s\n",
34359- chtostr(tmp, result.physical_location, 64));
34360- seq_printf(seq, "Instance number : %s\n",
34361- chtostr(tmp, result.instance_number, 4));
34362+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34363+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34364+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34365+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34366
34367 return 0;
34368 }
34369diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34370index a8c08f3..155fe3d 100644
34371--- a/drivers/message/i2o/iop.c
34372+++ b/drivers/message/i2o/iop.c
34373@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34374
34375 spin_lock_irqsave(&c->context_list_lock, flags);
34376
34377- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34378- atomic_inc(&c->context_list_counter);
34379+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34380+ atomic_inc_unchecked(&c->context_list_counter);
34381
34382- entry->context = atomic_read(&c->context_list_counter);
34383+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34384
34385 list_add(&entry->list, &c->context_list);
34386
34387@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34388
34389 #if BITS_PER_LONG == 64
34390 spin_lock_init(&c->context_list_lock);
34391- atomic_set(&c->context_list_counter, 0);
34392+ atomic_set_unchecked(&c->context_list_counter, 0);
34393 INIT_LIST_HEAD(&c->context_list);
34394 #endif
34395
34396diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34397index 7ce65f4..e66e9bc 100644
34398--- a/drivers/mfd/abx500-core.c
34399+++ b/drivers/mfd/abx500-core.c
34400@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34401
34402 struct abx500_device_entry {
34403 struct list_head list;
34404- struct abx500_ops ops;
34405+ abx500_ops_no_const ops;
34406 struct device *dev;
34407 };
34408
34409diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34410index 965c480..71f2db9 100644
34411--- a/drivers/mfd/janz-cmodio.c
34412+++ b/drivers/mfd/janz-cmodio.c
34413@@ -13,6 +13,7 @@
34414
34415 #include <linux/kernel.h>
34416 #include <linux/module.h>
34417+#include <linux/slab.h>
34418 #include <linux/init.h>
34419 #include <linux/pci.h>
34420 #include <linux/interrupt.h>
34421diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34422index a981e2a..5ca0c8b 100644
34423--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34424+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34425@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34426 * the lid is closed. This leads to interrupts as soon as a little move
34427 * is done.
34428 */
34429- atomic_inc(&lis3->count);
34430+ atomic_inc_unchecked(&lis3->count);
34431
34432 wake_up_interruptible(&lis3->misc_wait);
34433 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34434@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34435 if (lis3->pm_dev)
34436 pm_runtime_get_sync(lis3->pm_dev);
34437
34438- atomic_set(&lis3->count, 0);
34439+ atomic_set_unchecked(&lis3->count, 0);
34440 return 0;
34441 }
34442
34443@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34444 add_wait_queue(&lis3->misc_wait, &wait);
34445 while (true) {
34446 set_current_state(TASK_INTERRUPTIBLE);
34447- data = atomic_xchg(&lis3->count, 0);
34448+ data = atomic_xchg_unchecked(&lis3->count, 0);
34449 if (data)
34450 break;
34451
34452@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34453 struct lis3lv02d, miscdev);
34454
34455 poll_wait(file, &lis3->misc_wait, wait);
34456- if (atomic_read(&lis3->count))
34457+ if (atomic_read_unchecked(&lis3->count))
34458 return POLLIN | POLLRDNORM;
34459 return 0;
34460 }
34461diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34462index 2b1482a..5d33616 100644
34463--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34464+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34465@@ -266,7 +266,7 @@ struct lis3lv02d {
34466 struct input_polled_dev *idev; /* input device */
34467 struct platform_device *pdev; /* platform device */
34468 struct regulator_bulk_data regulators[2];
34469- atomic_t count; /* interrupt count after last read */
34470+ atomic_unchecked_t count; /* interrupt count after last read */
34471 union axis_conversion ac; /* hw -> logical axis */
34472 int mapped_btns[3];
34473
34474diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34475index 2f30bad..c4c13d0 100644
34476--- a/drivers/misc/sgi-gru/gruhandles.c
34477+++ b/drivers/misc/sgi-gru/gruhandles.c
34478@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34479 unsigned long nsec;
34480
34481 nsec = CLKS2NSEC(clks);
34482- atomic_long_inc(&mcs_op_statistics[op].count);
34483- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34484+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34485+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34486 if (mcs_op_statistics[op].max < nsec)
34487 mcs_op_statistics[op].max = nsec;
34488 }
34489diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34490index 950dbe9..eeef0f8 100644
34491--- a/drivers/misc/sgi-gru/gruprocfs.c
34492+++ b/drivers/misc/sgi-gru/gruprocfs.c
34493@@ -32,9 +32,9 @@
34494
34495 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34496
34497-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34498+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34499 {
34500- unsigned long val = atomic_long_read(v);
34501+ unsigned long val = atomic_long_read_unchecked(v);
34502
34503 seq_printf(s, "%16lu %s\n", val, id);
34504 }
34505@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34506
34507 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34508 for (op = 0; op < mcsop_last; op++) {
34509- count = atomic_long_read(&mcs_op_statistics[op].count);
34510- total = atomic_long_read(&mcs_op_statistics[op].total);
34511+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34512+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34513 max = mcs_op_statistics[op].max;
34514 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34515 count ? total / count : 0, max);
34516diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34517index 5c3ce24..4915ccb 100644
34518--- a/drivers/misc/sgi-gru/grutables.h
34519+++ b/drivers/misc/sgi-gru/grutables.h
34520@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34521 * GRU statistics.
34522 */
34523 struct gru_stats_s {
34524- atomic_long_t vdata_alloc;
34525- atomic_long_t vdata_free;
34526- atomic_long_t gts_alloc;
34527- atomic_long_t gts_free;
34528- atomic_long_t gms_alloc;
34529- atomic_long_t gms_free;
34530- atomic_long_t gts_double_allocate;
34531- atomic_long_t assign_context;
34532- atomic_long_t assign_context_failed;
34533- atomic_long_t free_context;
34534- atomic_long_t load_user_context;
34535- atomic_long_t load_kernel_context;
34536- atomic_long_t lock_kernel_context;
34537- atomic_long_t unlock_kernel_context;
34538- atomic_long_t steal_user_context;
34539- atomic_long_t steal_kernel_context;
34540- atomic_long_t steal_context_failed;
34541- atomic_long_t nopfn;
34542- atomic_long_t asid_new;
34543- atomic_long_t asid_next;
34544- atomic_long_t asid_wrap;
34545- atomic_long_t asid_reuse;
34546- atomic_long_t intr;
34547- atomic_long_t intr_cbr;
34548- atomic_long_t intr_tfh;
34549- atomic_long_t intr_spurious;
34550- atomic_long_t intr_mm_lock_failed;
34551- atomic_long_t call_os;
34552- atomic_long_t call_os_wait_queue;
34553- atomic_long_t user_flush_tlb;
34554- atomic_long_t user_unload_context;
34555- atomic_long_t user_exception;
34556- atomic_long_t set_context_option;
34557- atomic_long_t check_context_retarget_intr;
34558- atomic_long_t check_context_unload;
34559- atomic_long_t tlb_dropin;
34560- atomic_long_t tlb_preload_page;
34561- atomic_long_t tlb_dropin_fail_no_asid;
34562- atomic_long_t tlb_dropin_fail_upm;
34563- atomic_long_t tlb_dropin_fail_invalid;
34564- atomic_long_t tlb_dropin_fail_range_active;
34565- atomic_long_t tlb_dropin_fail_idle;
34566- atomic_long_t tlb_dropin_fail_fmm;
34567- atomic_long_t tlb_dropin_fail_no_exception;
34568- atomic_long_t tfh_stale_on_fault;
34569- atomic_long_t mmu_invalidate_range;
34570- atomic_long_t mmu_invalidate_page;
34571- atomic_long_t flush_tlb;
34572- atomic_long_t flush_tlb_gru;
34573- atomic_long_t flush_tlb_gru_tgh;
34574- atomic_long_t flush_tlb_gru_zero_asid;
34575+ atomic_long_unchecked_t vdata_alloc;
34576+ atomic_long_unchecked_t vdata_free;
34577+ atomic_long_unchecked_t gts_alloc;
34578+ atomic_long_unchecked_t gts_free;
34579+ atomic_long_unchecked_t gms_alloc;
34580+ atomic_long_unchecked_t gms_free;
34581+ atomic_long_unchecked_t gts_double_allocate;
34582+ atomic_long_unchecked_t assign_context;
34583+ atomic_long_unchecked_t assign_context_failed;
34584+ atomic_long_unchecked_t free_context;
34585+ atomic_long_unchecked_t load_user_context;
34586+ atomic_long_unchecked_t load_kernel_context;
34587+ atomic_long_unchecked_t lock_kernel_context;
34588+ atomic_long_unchecked_t unlock_kernel_context;
34589+ atomic_long_unchecked_t steal_user_context;
34590+ atomic_long_unchecked_t steal_kernel_context;
34591+ atomic_long_unchecked_t steal_context_failed;
34592+ atomic_long_unchecked_t nopfn;
34593+ atomic_long_unchecked_t asid_new;
34594+ atomic_long_unchecked_t asid_next;
34595+ atomic_long_unchecked_t asid_wrap;
34596+ atomic_long_unchecked_t asid_reuse;
34597+ atomic_long_unchecked_t intr;
34598+ atomic_long_unchecked_t intr_cbr;
34599+ atomic_long_unchecked_t intr_tfh;
34600+ atomic_long_unchecked_t intr_spurious;
34601+ atomic_long_unchecked_t intr_mm_lock_failed;
34602+ atomic_long_unchecked_t call_os;
34603+ atomic_long_unchecked_t call_os_wait_queue;
34604+ atomic_long_unchecked_t user_flush_tlb;
34605+ atomic_long_unchecked_t user_unload_context;
34606+ atomic_long_unchecked_t user_exception;
34607+ atomic_long_unchecked_t set_context_option;
34608+ atomic_long_unchecked_t check_context_retarget_intr;
34609+ atomic_long_unchecked_t check_context_unload;
34610+ atomic_long_unchecked_t tlb_dropin;
34611+ atomic_long_unchecked_t tlb_preload_page;
34612+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34613+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34614+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34615+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34616+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34617+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34618+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34619+ atomic_long_unchecked_t tfh_stale_on_fault;
34620+ atomic_long_unchecked_t mmu_invalidate_range;
34621+ atomic_long_unchecked_t mmu_invalidate_page;
34622+ atomic_long_unchecked_t flush_tlb;
34623+ atomic_long_unchecked_t flush_tlb_gru;
34624+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34625+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34626
34627- atomic_long_t copy_gpa;
34628- atomic_long_t read_gpa;
34629+ atomic_long_unchecked_t copy_gpa;
34630+ atomic_long_unchecked_t read_gpa;
34631
34632- atomic_long_t mesq_receive;
34633- atomic_long_t mesq_receive_none;
34634- atomic_long_t mesq_send;
34635- atomic_long_t mesq_send_failed;
34636- atomic_long_t mesq_noop;
34637- atomic_long_t mesq_send_unexpected_error;
34638- atomic_long_t mesq_send_lb_overflow;
34639- atomic_long_t mesq_send_qlimit_reached;
34640- atomic_long_t mesq_send_amo_nacked;
34641- atomic_long_t mesq_send_put_nacked;
34642- atomic_long_t mesq_page_overflow;
34643- atomic_long_t mesq_qf_locked;
34644- atomic_long_t mesq_qf_noop_not_full;
34645- atomic_long_t mesq_qf_switch_head_failed;
34646- atomic_long_t mesq_qf_unexpected_error;
34647- atomic_long_t mesq_noop_unexpected_error;
34648- atomic_long_t mesq_noop_lb_overflow;
34649- atomic_long_t mesq_noop_qlimit_reached;
34650- atomic_long_t mesq_noop_amo_nacked;
34651- atomic_long_t mesq_noop_put_nacked;
34652- atomic_long_t mesq_noop_page_overflow;
34653+ atomic_long_unchecked_t mesq_receive;
34654+ atomic_long_unchecked_t mesq_receive_none;
34655+ atomic_long_unchecked_t mesq_send;
34656+ atomic_long_unchecked_t mesq_send_failed;
34657+ atomic_long_unchecked_t mesq_noop;
34658+ atomic_long_unchecked_t mesq_send_unexpected_error;
34659+ atomic_long_unchecked_t mesq_send_lb_overflow;
34660+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34661+ atomic_long_unchecked_t mesq_send_amo_nacked;
34662+ atomic_long_unchecked_t mesq_send_put_nacked;
34663+ atomic_long_unchecked_t mesq_page_overflow;
34664+ atomic_long_unchecked_t mesq_qf_locked;
34665+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34666+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34667+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34668+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34669+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34670+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34671+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34672+ atomic_long_unchecked_t mesq_noop_put_nacked;
34673+ atomic_long_unchecked_t mesq_noop_page_overflow;
34674
34675 };
34676
34677@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34678 tghop_invalidate, mcsop_last};
34679
34680 struct mcs_op_statistic {
34681- atomic_long_t count;
34682- atomic_long_t total;
34683+ atomic_long_unchecked_t count;
34684+ atomic_long_unchecked_t total;
34685 unsigned long max;
34686 };
34687
34688@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34689
34690 #define STAT(id) do { \
34691 if (gru_options & OPT_STATS) \
34692- atomic_long_inc(&gru_stats.id); \
34693+ atomic_long_inc_unchecked(&gru_stats.id); \
34694 } while (0)
34695
34696 #ifdef CONFIG_SGI_GRU_DEBUG
34697diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34698index c862cd4..0d176fe 100644
34699--- a/drivers/misc/sgi-xp/xp.h
34700+++ b/drivers/misc/sgi-xp/xp.h
34701@@ -288,7 +288,7 @@ struct xpc_interface {
34702 xpc_notify_func, void *);
34703 void (*received) (short, int, void *);
34704 enum xp_retval (*partid_to_nasids) (short, void *);
34705-};
34706+} __no_const;
34707
34708 extern struct xpc_interface xpc_interface;
34709
34710diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34711index b94d5f7..7f494c5 100644
34712--- a/drivers/misc/sgi-xp/xpc.h
34713+++ b/drivers/misc/sgi-xp/xpc.h
34714@@ -835,6 +835,7 @@ struct xpc_arch_operations {
34715 void (*received_payload) (struct xpc_channel *, void *);
34716 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34717 };
34718+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34719
34720 /* struct xpc_partition act_state values (for XPC HB) */
34721
34722@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34723 /* found in xpc_main.c */
34724 extern struct device *xpc_part;
34725 extern struct device *xpc_chan;
34726-extern struct xpc_arch_operations xpc_arch_ops;
34727+extern xpc_arch_operations_no_const xpc_arch_ops;
34728 extern int xpc_disengage_timelimit;
34729 extern int xpc_disengage_timedout;
34730 extern int xpc_activate_IRQ_rcvd;
34731diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34732index 8d082b4..aa749ae 100644
34733--- a/drivers/misc/sgi-xp/xpc_main.c
34734+++ b/drivers/misc/sgi-xp/xpc_main.c
34735@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34736 .notifier_call = xpc_system_die,
34737 };
34738
34739-struct xpc_arch_operations xpc_arch_ops;
34740+xpc_arch_operations_no_const xpc_arch_ops;
34741
34742 /*
34743 * Timer function to enforce the timelimit on the partition disengage.
34744diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34745index 504da71..9722d43 100644
34746--- a/drivers/mmc/host/sdhci-pci.c
34747+++ b/drivers/mmc/host/sdhci-pci.c
34748@@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34749 .probe = via_probe,
34750 };
34751
34752-static const struct pci_device_id pci_ids[] __devinitdata = {
34753+static const struct pci_device_id pci_ids[] __devinitconst = {
34754 {
34755 .vendor = PCI_VENDOR_ID_RICOH,
34756 .device = PCI_DEVICE_ID_RICOH_R5C822,
34757diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34758index a4eb8b5..8c0628f 100644
34759--- a/drivers/mtd/devices/doc2000.c
34760+++ b/drivers/mtd/devices/doc2000.c
34761@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34762
34763 /* The ECC will not be calculated correctly if less than 512 is written */
34764 /* DBB-
34765- if (len != 0x200 && eccbuf)
34766+ if (len != 0x200)
34767 printk(KERN_WARNING
34768 "ECC needs a full sector write (adr: %lx size %lx)\n",
34769 (long) to, (long) len);
34770diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34771index 0650aaf..7718762 100644
34772--- a/drivers/mtd/nand/denali.c
34773+++ b/drivers/mtd/nand/denali.c
34774@@ -26,6 +26,7 @@
34775 #include <linux/pci.h>
34776 #include <linux/mtd/mtd.h>
34777 #include <linux/module.h>
34778+#include <linux/slab.h>
34779
34780 #include "denali.h"
34781
34782diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34783index 51b9d6a..52af9a7 100644
34784--- a/drivers/mtd/nftlmount.c
34785+++ b/drivers/mtd/nftlmount.c
34786@@ -24,6 +24,7 @@
34787 #include <asm/errno.h>
34788 #include <linux/delay.h>
34789 #include <linux/slab.h>
34790+#include <linux/sched.h>
34791 #include <linux/mtd/mtd.h>
34792 #include <linux/mtd/nand.h>
34793 #include <linux/mtd/nftl.h>
34794diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34795index 57d64b8..623dd86 100644
34796--- a/drivers/net/ethernet/atheros/atlx/atl2.c
34797+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34798@@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34799 */
34800
34801 #define ATL2_PARAM(X, desc) \
34802- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34803+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34804 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34805 MODULE_PARM_DESC(X, desc);
34806 #else
34807diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34808index f83e033..8b4f43a 100644
34809--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34810+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34811@@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34812
34813 int (*wait_comp)(struct bnx2x *bp,
34814 struct bnx2x_rx_mode_ramrod_params *p);
34815-};
34816+} __no_const;
34817
34818 /********************** Set multicast group ***********************************/
34819
34820diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34821index 6d52cb2..bc95640 100644
34822--- a/drivers/net/ethernet/broadcom/tg3.h
34823+++ b/drivers/net/ethernet/broadcom/tg3.h
34824@@ -140,6 +140,7 @@
34825 #define CHIPREV_ID_5750_A0 0x4000
34826 #define CHIPREV_ID_5750_A1 0x4001
34827 #define CHIPREV_ID_5750_A3 0x4003
34828+#define CHIPREV_ID_5750_C1 0x4201
34829 #define CHIPREV_ID_5750_C2 0x4202
34830 #define CHIPREV_ID_5752_A0_HW 0x5000
34831 #define CHIPREV_ID_5752_A0 0x6000
34832diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34833index 8cffcdf..aadf043 100644
34834--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34835+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34836@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34837 */
34838 struct l2t_skb_cb {
34839 arp_failure_handler_func arp_failure_handler;
34840-};
34841+} __no_const;
34842
34843 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34844
34845diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34846index f879e92..726f20f 100644
34847--- a/drivers/net/ethernet/dec/tulip/de4x5.c
34848+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34849@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34850 for (i=0; i<ETH_ALEN; i++) {
34851 tmp.addr[i] = dev->dev_addr[i];
34852 }
34853- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34854+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34855 break;
34856
34857 case DE4X5_SET_HWADDR: /* Set the hardware address */
34858@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34859 spin_lock_irqsave(&lp->lock, flags);
34860 memcpy(&statbuf, &lp->pktStats, ioc->len);
34861 spin_unlock_irqrestore(&lp->lock, flags);
34862- if (copy_to_user(ioc->data, &statbuf, ioc->len))
34863+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34864 return -EFAULT;
34865 break;
34866 }
34867diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34868index ed7d1dc..d426748 100644
34869--- a/drivers/net/ethernet/dec/tulip/eeprom.c
34870+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34871@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34872 {NULL}};
34873
34874
34875-static const char *block_name[] __devinitdata = {
34876+static const char *block_name[] __devinitconst = {
34877 "21140 non-MII",
34878 "21140 MII PHY",
34879 "21142 Serial PHY",
34880diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34881index 75d45f8..3d9c55b 100644
34882--- a/drivers/net/ethernet/dec/tulip/uli526x.c
34883+++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34884@@ -129,7 +129,7 @@ struct uli526x_board_info {
34885 struct uli_phy_ops {
34886 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34887 u16 (*read)(struct uli526x_board_info *, u8, u8);
34888- } phy;
34889+ } __no_const phy;
34890 struct net_device *next_dev; /* next device */
34891 struct pci_dev *pdev; /* PCI device */
34892 spinlock_t lock;
34893diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34894index 4d1ffca..7c1ec4d 100644
34895--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34896+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34897@@ -236,7 +236,7 @@ struct pci_id_info {
34898 int drv_flags; /* Driver use, intended as capability flags. */
34899 };
34900
34901-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34902+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34903 { /* Sometime a Level-One switch card. */
34904 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34905 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34906diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34907index d7bb52a..3b83588 100644
34908--- a/drivers/net/ethernet/dlink/sundance.c
34909+++ b/drivers/net/ethernet/dlink/sundance.c
34910@@ -218,7 +218,7 @@ enum {
34911 struct pci_id_info {
34912 const char *name;
34913 };
34914-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34915+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34916 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34917 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34918 {"D-Link DFE-580TX 4 port Server Adapter"},
34919diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34920index 78b8aa8..dd6323a 100644
34921--- a/drivers/net/ethernet/emulex/benet/be_main.c
34922+++ b/drivers/net/ethernet/emulex/benet/be_main.c
34923@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34924
34925 if (wrapped)
34926 newacc += 65536;
34927- ACCESS_ONCE(*acc) = newacc;
34928+ ACCESS_ONCE_RW(*acc) = newacc;
34929 }
34930
34931 void be_parse_stats(struct be_adapter *adapter)
34932diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34933index 74d749e..eefb1bd 100644
34934--- a/drivers/net/ethernet/faraday/ftgmac100.c
34935+++ b/drivers/net/ethernet/faraday/ftgmac100.c
34936@@ -31,6 +31,8 @@
34937 #include <linux/netdevice.h>
34938 #include <linux/phy.h>
34939 #include <linux/platform_device.h>
34940+#include <linux/interrupt.h>
34941+#include <linux/irqreturn.h>
34942 #include <net/ip.h>
34943
34944 #include "ftgmac100.h"
34945diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34946index b901a01..1ff32ee 100644
34947--- a/drivers/net/ethernet/faraday/ftmac100.c
34948+++ b/drivers/net/ethernet/faraday/ftmac100.c
34949@@ -31,6 +31,8 @@
34950 #include <linux/module.h>
34951 #include <linux/netdevice.h>
34952 #include <linux/platform_device.h>
34953+#include <linux/interrupt.h>
34954+#include <linux/irqreturn.h>
34955
34956 #include "ftmac100.h"
34957
34958diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34959index 9d71c9c..0e4a0ac 100644
34960--- a/drivers/net/ethernet/fealnx.c
34961+++ b/drivers/net/ethernet/fealnx.c
34962@@ -150,7 +150,7 @@ struct chip_info {
34963 int flags;
34964 };
34965
34966-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34967+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34968 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34969 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34970 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34971diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34972index cb3356c..c302a98 100644
34973--- a/drivers/net/ethernet/intel/e1000e/e1000.h
34974+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34975@@ -181,7 +181,7 @@ struct e1000_info;
34976 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34977 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34978 E1000_TXDCTL_COUNT_DESC | \
34979- (5 << 16) | /* wthresh must be +1 more than desired */\
34980+ (1 << 16) | /* wthresh must be +1 more than desired */\
34981 (1 << 8) | /* hthresh */ \
34982 0x1f) /* pthresh */
34983
34984diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34985index ed5b409..ec37828 100644
34986--- a/drivers/net/ethernet/intel/e1000e/hw.h
34987+++ b/drivers/net/ethernet/intel/e1000e/hw.h
34988@@ -797,6 +797,7 @@ struct e1000_mac_operations {
34989 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34990 s32 (*read_mac_addr)(struct e1000_hw *);
34991 };
34992+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34993
34994 /*
34995 * When to use various PHY register access functions:
34996@@ -837,6 +838,7 @@ struct e1000_phy_operations {
34997 void (*power_up)(struct e1000_hw *);
34998 void (*power_down)(struct e1000_hw *);
34999 };
35000+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35001
35002 /* Function pointers for the NVM. */
35003 struct e1000_nvm_operations {
35004@@ -849,9 +851,10 @@ struct e1000_nvm_operations {
35005 s32 (*validate)(struct e1000_hw *);
35006 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35007 };
35008+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35009
35010 struct e1000_mac_info {
35011- struct e1000_mac_operations ops;
35012+ e1000_mac_operations_no_const ops;
35013 u8 addr[ETH_ALEN];
35014 u8 perm_addr[ETH_ALEN];
35015
35016@@ -892,7 +895,7 @@ struct e1000_mac_info {
35017 };
35018
35019 struct e1000_phy_info {
35020- struct e1000_phy_operations ops;
35021+ e1000_phy_operations_no_const ops;
35022
35023 enum e1000_phy_type type;
35024
35025@@ -926,7 +929,7 @@ struct e1000_phy_info {
35026 };
35027
35028 struct e1000_nvm_info {
35029- struct e1000_nvm_operations ops;
35030+ e1000_nvm_operations_no_const ops;
35031
35032 enum e1000_nvm_type type;
35033 enum e1000_nvm_override override;
35034diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35035index c2a51dc..c2bd262 100644
35036--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35037+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35038@@ -327,6 +327,7 @@ struct e1000_mac_operations {
35039 void (*release_swfw_sync)(struct e1000_hw *, u16);
35040
35041 };
35042+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35043
35044 struct e1000_phy_operations {
35045 s32 (*acquire)(struct e1000_hw *);
35046@@ -343,6 +344,7 @@ struct e1000_phy_operations {
35047 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35048 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35049 };
35050+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35051
35052 struct e1000_nvm_operations {
35053 s32 (*acquire)(struct e1000_hw *);
35054@@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35055 s32 (*validate)(struct e1000_hw *);
35056 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35057 };
35058+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35059
35060 struct e1000_info {
35061 s32 (*get_invariants)(struct e1000_hw *);
35062@@ -364,7 +367,7 @@ struct e1000_info {
35063 extern const struct e1000_info e1000_82575_info;
35064
35065 struct e1000_mac_info {
35066- struct e1000_mac_operations ops;
35067+ e1000_mac_operations_no_const ops;
35068
35069 u8 addr[6];
35070 u8 perm_addr[6];
35071@@ -402,7 +405,7 @@ struct e1000_mac_info {
35072 };
35073
35074 struct e1000_phy_info {
35075- struct e1000_phy_operations ops;
35076+ e1000_phy_operations_no_const ops;
35077
35078 enum e1000_phy_type type;
35079
35080@@ -437,7 +440,7 @@ struct e1000_phy_info {
35081 };
35082
35083 struct e1000_nvm_info {
35084- struct e1000_nvm_operations ops;
35085+ e1000_nvm_operations_no_const ops;
35086 enum e1000_nvm_type type;
35087 enum e1000_nvm_override override;
35088
35089@@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35090 s32 (*check_for_ack)(struct e1000_hw *, u16);
35091 s32 (*check_for_rst)(struct e1000_hw *, u16);
35092 };
35093+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35094
35095 struct e1000_mbx_stats {
35096 u32 msgs_tx;
35097@@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35098 };
35099
35100 struct e1000_mbx_info {
35101- struct e1000_mbx_operations ops;
35102+ e1000_mbx_operations_no_const ops;
35103 struct e1000_mbx_stats stats;
35104 u32 timeout;
35105 u32 usec_delay;
35106diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35107index 57db3c6..aa825fc 100644
35108--- a/drivers/net/ethernet/intel/igbvf/vf.h
35109+++ b/drivers/net/ethernet/intel/igbvf/vf.h
35110@@ -189,9 +189,10 @@ struct e1000_mac_operations {
35111 s32 (*read_mac_addr)(struct e1000_hw *);
35112 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35113 };
35114+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35115
35116 struct e1000_mac_info {
35117- struct e1000_mac_operations ops;
35118+ e1000_mac_operations_no_const ops;
35119 u8 addr[6];
35120 u8 perm_addr[6];
35121
35122@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35123 s32 (*check_for_ack)(struct e1000_hw *);
35124 s32 (*check_for_rst)(struct e1000_hw *);
35125 };
35126+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35127
35128 struct e1000_mbx_stats {
35129 u32 msgs_tx;
35130@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35131 };
35132
35133 struct e1000_mbx_info {
35134- struct e1000_mbx_operations ops;
35135+ e1000_mbx_operations_no_const ops;
35136 struct e1000_mbx_stats stats;
35137 u32 timeout;
35138 u32 usec_delay;
35139diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35140index 3456d56..b688d81 100644
35141--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35142+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35143@@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35144 /* store the new cycle speed */
35145 adapter->cycle_speed = cycle_speed;
35146
35147- ACCESS_ONCE(adapter->base_incval) = incval;
35148+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
35149 smp_mb();
35150
35151 /* grab the ptp lock */
35152diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35153index 400f86a..7f2e062 100644
35154--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35155+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35156@@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35157 s32 (*update_checksum)(struct ixgbe_hw *);
35158 u16 (*calc_checksum)(struct ixgbe_hw *);
35159 };
35160+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35161
35162 struct ixgbe_mac_operations {
35163 s32 (*init_hw)(struct ixgbe_hw *);
35164@@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35165 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35166 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35167 };
35168+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35169
35170 struct ixgbe_phy_operations {
35171 s32 (*identify)(struct ixgbe_hw *);
35172@@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35173 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35174 s32 (*check_overtemp)(struct ixgbe_hw *);
35175 };
35176+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35177
35178 struct ixgbe_eeprom_info {
35179- struct ixgbe_eeprom_operations ops;
35180+ ixgbe_eeprom_operations_no_const ops;
35181 enum ixgbe_eeprom_type type;
35182 u32 semaphore_delay;
35183 u16 word_size;
35184@@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35185
35186 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35187 struct ixgbe_mac_info {
35188- struct ixgbe_mac_operations ops;
35189+ ixgbe_mac_operations_no_const ops;
35190 enum ixgbe_mac_type type;
35191 u8 addr[ETH_ALEN];
35192 u8 perm_addr[ETH_ALEN];
35193@@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35194 };
35195
35196 struct ixgbe_phy_info {
35197- struct ixgbe_phy_operations ops;
35198+ ixgbe_phy_operations_no_const ops;
35199 struct mdio_if_info mdio;
35200 enum ixgbe_phy_type type;
35201 u32 id;
35202@@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35203 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35204 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35205 };
35206+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35207
35208 struct ixgbe_mbx_stats {
35209 u32 msgs_tx;
35210@@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35211 };
35212
35213 struct ixgbe_mbx_info {
35214- struct ixgbe_mbx_operations ops;
35215+ ixgbe_mbx_operations_no_const ops;
35216 struct ixgbe_mbx_stats stats;
35217 u32 timeout;
35218 u32 usec_delay;
35219diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35220index 25c951d..cc7cf33 100644
35221--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35222+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35223@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35224 s32 (*clear_vfta)(struct ixgbe_hw *);
35225 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35226 };
35227+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35228
35229 enum ixgbe_mac_type {
35230 ixgbe_mac_unknown = 0,
35231@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35232 };
35233
35234 struct ixgbe_mac_info {
35235- struct ixgbe_mac_operations ops;
35236+ ixgbe_mac_operations_no_const ops;
35237 u8 addr[6];
35238 u8 perm_addr[6];
35239
35240@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35241 s32 (*check_for_ack)(struct ixgbe_hw *);
35242 s32 (*check_for_rst)(struct ixgbe_hw *);
35243 };
35244+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35245
35246 struct ixgbe_mbx_stats {
35247 u32 msgs_tx;
35248@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35249 };
35250
35251 struct ixgbe_mbx_info {
35252- struct ixgbe_mbx_operations ops;
35253+ ixgbe_mbx_operations_no_const ops;
35254 struct ixgbe_mbx_stats stats;
35255 u32 timeout;
35256 u32 udelay;
35257diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35258index 9e0c1ee..8471f77 100644
35259--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35260+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35261@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35262 void (*link_down)(struct __vxge_hw_device *devh);
35263 void (*crit_err)(struct __vxge_hw_device *devh,
35264 enum vxge_hw_event type, u64 ext_data);
35265-};
35266+} __no_const;
35267
35268 /*
35269 * struct __vxge_hw_blockpool_entry - Block private data structure
35270diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35271index 4a518a3..936b334 100644
35272--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35273+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35274@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35275 struct vxge_hw_mempool_dma *dma_object,
35276 u32 index,
35277 u32 is_last);
35278-};
35279+} __no_const;
35280
35281 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35282 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35283diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35284index b47d5b3..273a516 100644
35285--- a/drivers/net/ethernet/realtek/r8169.c
35286+++ b/drivers/net/ethernet/realtek/r8169.c
35287@@ -745,22 +745,22 @@ struct rtl8169_private {
35288 struct mdio_ops {
35289 void (*write)(struct rtl8169_private *, int, int);
35290 int (*read)(struct rtl8169_private *, int);
35291- } mdio_ops;
35292+ } __no_const mdio_ops;
35293
35294 struct pll_power_ops {
35295 void (*down)(struct rtl8169_private *);
35296 void (*up)(struct rtl8169_private *);
35297- } pll_power_ops;
35298+ } __no_const pll_power_ops;
35299
35300 struct jumbo_ops {
35301 void (*enable)(struct rtl8169_private *);
35302 void (*disable)(struct rtl8169_private *);
35303- } jumbo_ops;
35304+ } __no_const jumbo_ops;
35305
35306 struct csi_ops {
35307 void (*write)(struct rtl8169_private *, int, int);
35308 u32 (*read)(struct rtl8169_private *, int);
35309- } csi_ops;
35310+ } __no_const csi_ops;
35311
35312 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35313 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35314diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35315index 4613591..d816601 100644
35316--- a/drivers/net/ethernet/sis/sis190.c
35317+++ b/drivers/net/ethernet/sis/sis190.c
35318@@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35319 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35320 struct net_device *dev)
35321 {
35322- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35323+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35324 struct sis190_private *tp = netdev_priv(dev);
35325 struct pci_dev *isa_bridge;
35326 u8 reg, tmp8;
35327diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35328index 0c74a70..3bc6f68 100644
35329--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35330+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35331@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35332
35333 writel(value, ioaddr + MMC_CNTRL);
35334
35335- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35336- MMC_CNTRL, value);
35337+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35338+// MMC_CNTRL, value);
35339 }
35340
35341 /* To mask all all interrupts.*/
35342diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35343index 95ceb35..318fc12 100644
35344--- a/drivers/net/hyperv/hyperv_net.h
35345+++ b/drivers/net/hyperv/hyperv_net.h
35346@@ -99,7 +99,7 @@ struct rndis_device {
35347
35348 enum rndis_device_state state;
35349 bool link_state;
35350- atomic_t new_req_id;
35351+ atomic_unchecked_t new_req_id;
35352
35353 spinlock_t request_lock;
35354 struct list_head req_list;
35355diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35356index 1e88a10..1b01736 100644
35357--- a/drivers/net/hyperv/rndis_filter.c
35358+++ b/drivers/net/hyperv/rndis_filter.c
35359@@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35360 * template
35361 */
35362 set = &rndis_msg->msg.set_req;
35363- set->req_id = atomic_inc_return(&dev->new_req_id);
35364+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35365
35366 /* Add to the request list */
35367 spin_lock_irqsave(&dev->request_lock, flags);
35368@@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35369
35370 /* Setup the rndis set */
35371 halt = &request->request_msg.msg.halt_req;
35372- halt->req_id = atomic_inc_return(&dev->new_req_id);
35373+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35374
35375 /* Ignore return since this msg is optional. */
35376 rndis_filter_send_request(dev, request);
35377diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35378index 5c05572..389610b 100644
35379--- a/drivers/net/ppp/ppp_generic.c
35380+++ b/drivers/net/ppp/ppp_generic.c
35381@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35382 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35383 struct ppp_stats stats;
35384 struct ppp_comp_stats cstats;
35385- char *vers;
35386
35387 switch (cmd) {
35388 case SIOCGPPPSTATS:
35389@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35390 break;
35391
35392 case SIOCGPPPVER:
35393- vers = PPP_VERSION;
35394- if (copy_to_user(addr, vers, strlen(vers) + 1))
35395+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35396 break;
35397 err = 0;
35398 break;
35399diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35400index 3a16d4f..a311cec 100644
35401--- a/drivers/net/tun.c
35402+++ b/drivers/net/tun.c
35403@@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35404 }
35405
35406 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35407- unsigned long arg, int ifreq_len)
35408+ unsigned long arg, size_t ifreq_len)
35409 {
35410 struct tun_file *tfile = file->private_data;
35411 struct tun_struct *tun;
35412@@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35413 int vnet_hdr_sz;
35414 int ret;
35415
35416+ if (ifreq_len > sizeof ifr)
35417+ return -EFAULT;
35418+
35419 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35420 if (copy_from_user(&ifr, argp, ifreq_len))
35421 return -EFAULT;
35422diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35423index 62f30b4..ff99dfd 100644
35424--- a/drivers/net/usb/hso.c
35425+++ b/drivers/net/usb/hso.c
35426@@ -71,7 +71,7 @@
35427 #include <asm/byteorder.h>
35428 #include <linux/serial_core.h>
35429 #include <linux/serial.h>
35430-
35431+#include <asm/local.h>
35432
35433 #define MOD_AUTHOR "Option Wireless"
35434 #define MOD_DESCRIPTION "USB High Speed Option driver"
35435@@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35436 struct urb *urb;
35437
35438 urb = serial->rx_urb[0];
35439- if (serial->port.count > 0) {
35440+ if (atomic_read(&serial->port.count) > 0) {
35441 count = put_rxbuf_data(urb, serial);
35442 if (count == -1)
35443 return;
35444@@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35445 DUMP1(urb->transfer_buffer, urb->actual_length);
35446
35447 /* Anyone listening? */
35448- if (serial->port.count == 0)
35449+ if (atomic_read(&serial->port.count) == 0)
35450 return;
35451
35452 if (status == 0) {
35453@@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35454 tty_port_tty_set(&serial->port, tty);
35455
35456 /* check for port already opened, if not set the termios */
35457- serial->port.count++;
35458- if (serial->port.count == 1) {
35459+ if (atomic_inc_return(&serial->port.count) == 1) {
35460 serial->rx_state = RX_IDLE;
35461 /* Force default termio settings */
35462 _hso_serial_set_termios(tty, NULL);
35463@@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35464 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35465 if (result) {
35466 hso_stop_serial_device(serial->parent);
35467- serial->port.count--;
35468+ atomic_dec(&serial->port.count);
35469 kref_put(&serial->parent->ref, hso_serial_ref_free);
35470 }
35471 } else {
35472@@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35473
35474 /* reset the rts and dtr */
35475 /* do the actual close */
35476- serial->port.count--;
35477+ atomic_dec(&serial->port.count);
35478
35479- if (serial->port.count <= 0) {
35480- serial->port.count = 0;
35481+ if (atomic_read(&serial->port.count) <= 0) {
35482+ atomic_set(&serial->port.count, 0);
35483 tty_port_tty_set(&serial->port, NULL);
35484 if (!usb_gone)
35485 hso_stop_serial_device(serial->parent);
35486@@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35487
35488 /* the actual setup */
35489 spin_lock_irqsave(&serial->serial_lock, flags);
35490- if (serial->port.count)
35491+ if (atomic_read(&serial->port.count))
35492 _hso_serial_set_termios(tty, old);
35493 else
35494 tty->termios = old;
35495@@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35496 D1("Pending read interrupt on port %d\n", i);
35497 spin_lock(&serial->serial_lock);
35498 if (serial->rx_state == RX_IDLE &&
35499- serial->port.count > 0) {
35500+ atomic_read(&serial->port.count) > 0) {
35501 /* Setup and send a ctrl req read on
35502 * port i */
35503 if (!serial->rx_urb_filled[0]) {
35504@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35505 /* Start all serial ports */
35506 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35507 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35508- if (dev2ser(serial_table[i])->port.count) {
35509+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35510 result =
35511 hso_start_serial_device(serial_table[i], GFP_NOIO);
35512 hso_kick_transmit(dev2ser(serial_table[i]));
35513diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35514index 6169fbd..40e8422 100644
35515--- a/drivers/net/wireless/ath/ath.h
35516+++ b/drivers/net/wireless/ath/ath.h
35517@@ -119,6 +119,7 @@ struct ath_ops {
35518 void (*write_flush) (void *);
35519 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35520 };
35521+typedef struct ath_ops __no_const ath_ops_no_const;
35522
35523 struct ath_common;
35524 struct ath_bus_ops;
35525diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35526index 8d78253..bebbb68 100644
35527--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35528+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35529@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35530 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35531 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35532
35533- ACCESS_ONCE(ads->ds_link) = i->link;
35534- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35535+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35536+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35537
35538 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35539 ctl6 = SM(i->keytype, AR_EncrType);
35540@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35541
35542 if ((i->is_first || i->is_last) &&
35543 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35544- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35545+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35546 | set11nTries(i->rates, 1)
35547 | set11nTries(i->rates, 2)
35548 | set11nTries(i->rates, 3)
35549 | (i->dur_update ? AR_DurUpdateEna : 0)
35550 | SM(0, AR_BurstDur);
35551
35552- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35553+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35554 | set11nRate(i->rates, 1)
35555 | set11nRate(i->rates, 2)
35556 | set11nRate(i->rates, 3);
35557 } else {
35558- ACCESS_ONCE(ads->ds_ctl2) = 0;
35559- ACCESS_ONCE(ads->ds_ctl3) = 0;
35560+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35561+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35562 }
35563
35564 if (!i->is_first) {
35565- ACCESS_ONCE(ads->ds_ctl0) = 0;
35566- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35567- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35568+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35569+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35570+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35571 return;
35572 }
35573
35574@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35575 break;
35576 }
35577
35578- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35579+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35580 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35581 | SM(i->txpower, AR_XmitPower)
35582 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35583@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35584 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35585 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35586
35587- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35588- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35589+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35590+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35591
35592 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35593 return;
35594
35595- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35596+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35597 | set11nPktDurRTSCTS(i->rates, 1);
35598
35599- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35600+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35601 | set11nPktDurRTSCTS(i->rates, 3);
35602
35603- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35604+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35605 | set11nRateFlags(i->rates, 1)
35606 | set11nRateFlags(i->rates, 2)
35607 | set11nRateFlags(i->rates, 3)
35608diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35609index 78816b8..1fcdfae 100644
35610--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35611+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35612@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35613 (i->qcu << AR_TxQcuNum_S) | desc_len;
35614
35615 checksum += val;
35616- ACCESS_ONCE(ads->info) = val;
35617+ ACCESS_ONCE_RW(ads->info) = val;
35618
35619 checksum += i->link;
35620- ACCESS_ONCE(ads->link) = i->link;
35621+ ACCESS_ONCE_RW(ads->link) = i->link;
35622
35623 checksum += i->buf_addr[0];
35624- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35625+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35626 checksum += i->buf_addr[1];
35627- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35628+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35629 checksum += i->buf_addr[2];
35630- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35631+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35632 checksum += i->buf_addr[3];
35633- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35634+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35635
35636 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35637- ACCESS_ONCE(ads->ctl3) = val;
35638+ ACCESS_ONCE_RW(ads->ctl3) = val;
35639 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35640- ACCESS_ONCE(ads->ctl5) = val;
35641+ ACCESS_ONCE_RW(ads->ctl5) = val;
35642 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35643- ACCESS_ONCE(ads->ctl7) = val;
35644+ ACCESS_ONCE_RW(ads->ctl7) = val;
35645 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35646- ACCESS_ONCE(ads->ctl9) = val;
35647+ ACCESS_ONCE_RW(ads->ctl9) = val;
35648
35649 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35650- ACCESS_ONCE(ads->ctl10) = checksum;
35651+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
35652
35653 if (i->is_first || i->is_last) {
35654- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35655+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35656 | set11nTries(i->rates, 1)
35657 | set11nTries(i->rates, 2)
35658 | set11nTries(i->rates, 3)
35659 | (i->dur_update ? AR_DurUpdateEna : 0)
35660 | SM(0, AR_BurstDur);
35661
35662- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35663+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35664 | set11nRate(i->rates, 1)
35665 | set11nRate(i->rates, 2)
35666 | set11nRate(i->rates, 3);
35667 } else {
35668- ACCESS_ONCE(ads->ctl13) = 0;
35669- ACCESS_ONCE(ads->ctl14) = 0;
35670+ ACCESS_ONCE_RW(ads->ctl13) = 0;
35671+ ACCESS_ONCE_RW(ads->ctl14) = 0;
35672 }
35673
35674 ads->ctl20 = 0;
35675@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35676
35677 ctl17 = SM(i->keytype, AR_EncrType);
35678 if (!i->is_first) {
35679- ACCESS_ONCE(ads->ctl11) = 0;
35680- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35681- ACCESS_ONCE(ads->ctl15) = 0;
35682- ACCESS_ONCE(ads->ctl16) = 0;
35683- ACCESS_ONCE(ads->ctl17) = ctl17;
35684- ACCESS_ONCE(ads->ctl18) = 0;
35685- ACCESS_ONCE(ads->ctl19) = 0;
35686+ ACCESS_ONCE_RW(ads->ctl11) = 0;
35687+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35688+ ACCESS_ONCE_RW(ads->ctl15) = 0;
35689+ ACCESS_ONCE_RW(ads->ctl16) = 0;
35690+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35691+ ACCESS_ONCE_RW(ads->ctl18) = 0;
35692+ ACCESS_ONCE_RW(ads->ctl19) = 0;
35693 return;
35694 }
35695
35696- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35697+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35698 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35699 | SM(i->txpower, AR_XmitPower)
35700 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35701@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35702 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35703 ctl12 |= SM(val, AR_PAPRDChainMask);
35704
35705- ACCESS_ONCE(ads->ctl12) = ctl12;
35706- ACCESS_ONCE(ads->ctl17) = ctl17;
35707+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35708+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35709
35710- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35711+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35712 | set11nPktDurRTSCTS(i->rates, 1);
35713
35714- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35715+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35716 | set11nPktDurRTSCTS(i->rates, 3);
35717
35718- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35719+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35720 | set11nRateFlags(i->rates, 1)
35721 | set11nRateFlags(i->rates, 2)
35722 | set11nRateFlags(i->rates, 3)
35723 | SM(i->rtscts_rate, AR_RTSCTSRate);
35724
35725- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35726+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35727 }
35728
35729 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35730diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35731index de6968f..29ac4c1 100644
35732--- a/drivers/net/wireless/ath/ath9k/hw.h
35733+++ b/drivers/net/wireless/ath/ath9k/hw.h
35734@@ -656,7 +656,7 @@ struct ath_hw_private_ops {
35735
35736 /* ANI */
35737 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35738-};
35739+} __no_const;
35740
35741 /**
35742 * struct ath_hw_ops - callbacks used by hardware code and driver code
35743@@ -686,7 +686,7 @@ struct ath_hw_ops {
35744 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35745 struct ath_hw_antcomb_conf *antconf);
35746
35747-};
35748+} __no_const;
35749
35750 struct ath_nf_limits {
35751 s16 max;
35752@@ -706,7 +706,7 @@ enum ath_cal_list {
35753 #define AH_FASTCC 0x4
35754
35755 struct ath_hw {
35756- struct ath_ops reg_ops;
35757+ ath_ops_no_const reg_ops;
35758
35759 struct ieee80211_hw *hw;
35760 struct ath_common common;
35761diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35762index af00e2c..ab04d34 100644
35763--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35764+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35765@@ -545,7 +545,7 @@ struct phy_func_ptr {
35766 void (*carrsuppr)(struct brcms_phy *);
35767 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35768 void (*detach)(struct brcms_phy *);
35769-};
35770+} __no_const;
35771
35772 struct brcms_phy {
35773 struct brcms_phy_pub pubpi_ro;
35774diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35775index faec404..a5277f1 100644
35776--- a/drivers/net/wireless/iwlegacy/3945-mac.c
35777+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35778@@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35779 */
35780 if (il3945_mod_params.disable_hw_scan) {
35781 D_INFO("Disabling hw_scan\n");
35782- il3945_mac_ops.hw_scan = NULL;
35783+ pax_open_kernel();
35784+ *(void **)&il3945_mac_ops.hw_scan = NULL;
35785+ pax_close_kernel();
35786 }
35787
35788 D_INFO("*** LOAD DRIVER ***\n");
35789diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35790index a47b306..297daf2 100644
35791--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35792+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35793@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35794 {
35795 struct iwl_priv *priv = file->private_data;
35796 char buf[64];
35797- int buf_size;
35798+ size_t buf_size;
35799 u32 offset, len;
35800
35801 memset(buf, 0, sizeof(buf));
35802@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35803 struct iwl_priv *priv = file->private_data;
35804
35805 char buf[8];
35806- int buf_size;
35807+ size_t buf_size;
35808 u32 reset_flag;
35809
35810 memset(buf, 0, sizeof(buf));
35811@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35812 {
35813 struct iwl_priv *priv = file->private_data;
35814 char buf[8];
35815- int buf_size;
35816+ size_t buf_size;
35817 int ht40;
35818
35819 memset(buf, 0, sizeof(buf));
35820@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35821 {
35822 struct iwl_priv *priv = file->private_data;
35823 char buf[8];
35824- int buf_size;
35825+ size_t buf_size;
35826 int value;
35827
35828 memset(buf, 0, sizeof(buf));
35829@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35830 {
35831 struct iwl_priv *priv = file->private_data;
35832 char buf[8];
35833- int buf_size;
35834+ size_t buf_size;
35835 int clear;
35836
35837 memset(buf, 0, sizeof(buf));
35838@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35839 {
35840 struct iwl_priv *priv = file->private_data;
35841 char buf[8];
35842- int buf_size;
35843+ size_t buf_size;
35844 int trace;
35845
35846 memset(buf, 0, sizeof(buf));
35847@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
35848 {
35849 struct iwl_priv *priv = file->private_data;
35850 char buf[8];
35851- int buf_size;
35852+ size_t buf_size;
35853 int missed;
35854
35855 memset(buf, 0, sizeof(buf));
35856@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
35857
35858 struct iwl_priv *priv = file->private_data;
35859 char buf[8];
35860- int buf_size;
35861+ size_t buf_size;
35862 int plcp;
35863
35864 memset(buf, 0, sizeof(buf));
35865@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
35866
35867 struct iwl_priv *priv = file->private_data;
35868 char buf[8];
35869- int buf_size;
35870+ size_t buf_size;
35871 int flush;
35872
35873 memset(buf, 0, sizeof(buf));
35874@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35875
35876 struct iwl_priv *priv = file->private_data;
35877 char buf[8];
35878- int buf_size;
35879+ size_t buf_size;
35880 int rts;
35881
35882 if (!priv->cfg->ht_params)
35883@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
35884 {
35885 struct iwl_priv *priv = file->private_data;
35886 char buf[8];
35887- int buf_size;
35888+ size_t buf_size;
35889
35890 memset(buf, 0, sizeof(buf));
35891 buf_size = min(count, sizeof(buf) - 1);
35892@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
35893 struct iwl_priv *priv = file->private_data;
35894 u32 event_log_flag;
35895 char buf[8];
35896- int buf_size;
35897+ size_t buf_size;
35898
35899 /* check that the interface is up */
35900 if (!iwl_is_ready(priv))
35901@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
35902 struct iwl_priv *priv = file->private_data;
35903 char buf[8];
35904 u32 calib_disabled;
35905- int buf_size;
35906+ size_t buf_size;
35907
35908 memset(buf, 0, sizeof(buf));
35909 buf_size = min(count, sizeof(buf) - 1);
35910diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
35911index dbeebef..b45a152 100644
35912--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
35913+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
35914@@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
35915 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
35916
35917 char buf[8];
35918- int buf_size;
35919+ size_t buf_size;
35920 u32 reset_flag;
35921
35922 memset(buf, 0, sizeof(buf));
35923@@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
35924 {
35925 struct iwl_trans *trans = file->private_data;
35926 char buf[8];
35927- int buf_size;
35928+ size_t buf_size;
35929 int csr;
35930
35931 memset(buf, 0, sizeof(buf));
35932diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35933index 0083839..fcb7225 100644
35934--- a/drivers/net/wireless/mac80211_hwsim.c
35935+++ b/drivers/net/wireless/mac80211_hwsim.c
35936@@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
35937 return -EINVAL;
35938
35939 if (fake_hw_scan) {
35940- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35941- mac80211_hwsim_ops.sw_scan_start = NULL;
35942- mac80211_hwsim_ops.sw_scan_complete = NULL;
35943+ pax_open_kernel();
35944+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35945+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35946+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35947+ pax_close_kernel();
35948 }
35949
35950 spin_lock_init(&hwsim_radio_lock);
35951diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35952index e7c2a82..582e228 100644
35953--- a/drivers/net/wireless/mwifiex/main.h
35954+++ b/drivers/net/wireless/mwifiex/main.h
35955@@ -571,7 +571,7 @@ struct mwifiex_if_ops {
35956 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35957 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35958 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35959-};
35960+} __no_const;
35961
35962 struct mwifiex_adapter {
35963 u8 iface_type;
35964diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35965index 7a4ae9e..56e00bd 100644
35966--- a/drivers/net/wireless/rndis_wlan.c
35967+++ b/drivers/net/wireless/rndis_wlan.c
35968@@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35969
35970 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35971
35972- if (rts_threshold < 0 || rts_threshold > 2347)
35973+ if (rts_threshold > 2347)
35974 rts_threshold = 2347;
35975
35976 tmp = cpu_to_le32(rts_threshold);
35977diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35978index 8afb546..0c0dc5c 100644
35979--- a/drivers/net/wireless/rt2x00/rt2x00.h
35980+++ b/drivers/net/wireless/rt2x00/rt2x00.h
35981@@ -397,7 +397,7 @@ struct rt2x00_intf {
35982 * for hardware which doesn't support hardware
35983 * sequence counting.
35984 */
35985- atomic_t seqno;
35986+ atomic_unchecked_t seqno;
35987 };
35988
35989 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35990diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35991index f7e74a0..da71431 100644
35992--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35993+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35994@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35995 * sequence counter given by mac80211.
35996 */
35997 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35998- seqno = atomic_add_return(0x10, &intf->seqno);
35999+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
36000 else
36001- seqno = atomic_read(&intf->seqno);
36002+ seqno = atomic_read_unchecked(&intf->seqno);
36003
36004 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36005 hdr->seq_ctrl |= cpu_to_le16(seqno);
36006diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
36007index fd02060..74ee481 100644
36008--- a/drivers/net/wireless/ti/wl1251/wl1251.h
36009+++ b/drivers/net/wireless/ti/wl1251/wl1251.h
36010@@ -266,7 +266,7 @@ struct wl1251_if_operations {
36011 void (*reset)(struct wl1251 *wl);
36012 void (*enable_irq)(struct wl1251 *wl);
36013 void (*disable_irq)(struct wl1251 *wl);
36014-};
36015+} __no_const;
36016
36017 struct wl1251 {
36018 struct ieee80211_hw *hw;
36019diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36020index 0ce7a8e..56a0ccf 100644
36021--- a/drivers/net/wireless/ti/wlcore/wlcore.h
36022+++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36023@@ -81,7 +81,7 @@ struct wlcore_ops {
36024 struct ieee80211_sta *sta,
36025 struct ieee80211_key_conf *key_conf);
36026 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36027-};
36028+} __no_const;
36029
36030 enum wlcore_partitions {
36031 PART_DOWN,
36032diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36033index f34b5b2..b5abb9f 100644
36034--- a/drivers/oprofile/buffer_sync.c
36035+++ b/drivers/oprofile/buffer_sync.c
36036@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36037 if (cookie == NO_COOKIE)
36038 offset = pc;
36039 if (cookie == INVALID_COOKIE) {
36040- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36041+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36042 offset = pc;
36043 }
36044 if (cookie != last_cookie) {
36045@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36046 /* add userspace sample */
36047
36048 if (!mm) {
36049- atomic_inc(&oprofile_stats.sample_lost_no_mm);
36050+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36051 return 0;
36052 }
36053
36054 cookie = lookup_dcookie(mm, s->eip, &offset);
36055
36056 if (cookie == INVALID_COOKIE) {
36057- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36058+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36059 return 0;
36060 }
36061
36062@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36063 /* ignore backtraces if failed to add a sample */
36064 if (state == sb_bt_start) {
36065 state = sb_bt_ignore;
36066- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36067+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36068 }
36069 }
36070 release_mm(mm);
36071diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36072index c0cc4e7..44d4e54 100644
36073--- a/drivers/oprofile/event_buffer.c
36074+++ b/drivers/oprofile/event_buffer.c
36075@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36076 }
36077
36078 if (buffer_pos == buffer_size) {
36079- atomic_inc(&oprofile_stats.event_lost_overflow);
36080+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36081 return;
36082 }
36083
36084diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36085index ed2c3ec..deda85a 100644
36086--- a/drivers/oprofile/oprof.c
36087+++ b/drivers/oprofile/oprof.c
36088@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36089 if (oprofile_ops.switch_events())
36090 return;
36091
36092- atomic_inc(&oprofile_stats.multiplex_counter);
36093+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36094 start_switch_worker();
36095 }
36096
36097diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36098index 917d28e..d62d981 100644
36099--- a/drivers/oprofile/oprofile_stats.c
36100+++ b/drivers/oprofile/oprofile_stats.c
36101@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36102 cpu_buf->sample_invalid_eip = 0;
36103 }
36104
36105- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36106- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36107- atomic_set(&oprofile_stats.event_lost_overflow, 0);
36108- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36109- atomic_set(&oprofile_stats.multiplex_counter, 0);
36110+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36111+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36112+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36113+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36114+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36115 }
36116
36117
36118diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36119index 38b6fc0..b5cbfce 100644
36120--- a/drivers/oprofile/oprofile_stats.h
36121+++ b/drivers/oprofile/oprofile_stats.h
36122@@ -13,11 +13,11 @@
36123 #include <linux/atomic.h>
36124
36125 struct oprofile_stat_struct {
36126- atomic_t sample_lost_no_mm;
36127- atomic_t sample_lost_no_mapping;
36128- atomic_t bt_lost_no_mapping;
36129- atomic_t event_lost_overflow;
36130- atomic_t multiplex_counter;
36131+ atomic_unchecked_t sample_lost_no_mm;
36132+ atomic_unchecked_t sample_lost_no_mapping;
36133+ atomic_unchecked_t bt_lost_no_mapping;
36134+ atomic_unchecked_t event_lost_overflow;
36135+ atomic_unchecked_t multiplex_counter;
36136 };
36137
36138 extern struct oprofile_stat_struct oprofile_stats;
36139diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36140index 849357c..b83c1e0 100644
36141--- a/drivers/oprofile/oprofilefs.c
36142+++ b/drivers/oprofile/oprofilefs.c
36143@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36144
36145
36146 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36147- char const *name, atomic_t *val)
36148+ char const *name, atomic_unchecked_t *val)
36149 {
36150 return __oprofilefs_create_file(sb, root, name,
36151 &atomic_ro_fops, 0444, val);
36152diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36153index 3f56bc0..707d642 100644
36154--- a/drivers/parport/procfs.c
36155+++ b/drivers/parport/procfs.c
36156@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36157
36158 *ppos += len;
36159
36160- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36161+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36162 }
36163
36164 #ifdef CONFIG_PARPORT_1284
36165@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36166
36167 *ppos += len;
36168
36169- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36170+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36171 }
36172 #endif /* IEEE1284.3 support. */
36173
36174diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36175index 9fff878..ad0ad53 100644
36176--- a/drivers/pci/hotplug/cpci_hotplug.h
36177+++ b/drivers/pci/hotplug/cpci_hotplug.h
36178@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36179 int (*hardware_test) (struct slot* slot, u32 value);
36180 u8 (*get_power) (struct slot* slot);
36181 int (*set_power) (struct slot* slot, int value);
36182-};
36183+} __no_const;
36184
36185 struct cpci_hp_controller {
36186 unsigned int irq;
36187diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36188index 76ba8a1..20ca857 100644
36189--- a/drivers/pci/hotplug/cpqphp_nvram.c
36190+++ b/drivers/pci/hotplug/cpqphp_nvram.c
36191@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36192
36193 void compaq_nvram_init (void __iomem *rom_start)
36194 {
36195+
36196+#ifndef CONFIG_PAX_KERNEXEC
36197 if (rom_start) {
36198 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36199 }
36200+#endif
36201+
36202 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36203
36204 /* initialize our int15 lock */
36205diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36206index b500840..d7159d3 100644
36207--- a/drivers/pci/pcie/aspm.c
36208+++ b/drivers/pci/pcie/aspm.c
36209@@ -27,9 +27,9 @@
36210 #define MODULE_PARAM_PREFIX "pcie_aspm."
36211
36212 /* Note: those are not register definitions */
36213-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36214-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36215-#define ASPM_STATE_L1 (4) /* L1 state */
36216+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36217+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36218+#define ASPM_STATE_L1 (4U) /* L1 state */
36219 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36220 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36221
36222diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36223index 9f8a6b7..6134680 100644
36224--- a/drivers/pci/probe.c
36225+++ b/drivers/pci/probe.c
36226@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36227 struct pci_bus_region region;
36228 bool bar_too_big = false, bar_disabled = false;
36229
36230- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36231+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36232
36233 /* No printks while decoding is disabled! */
36234 if (!dev->mmio_always_on) {
36235diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36236index 27911b5..5b6db88 100644
36237--- a/drivers/pci/proc.c
36238+++ b/drivers/pci/proc.c
36239@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36240 static int __init pci_proc_init(void)
36241 {
36242 struct pci_dev *dev = NULL;
36243+
36244+#ifdef CONFIG_GRKERNSEC_PROC_ADD
36245+#ifdef CONFIG_GRKERNSEC_PROC_USER
36246+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36247+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36248+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36249+#endif
36250+#else
36251 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36252+#endif
36253 proc_create("devices", 0, proc_bus_pci_dir,
36254 &proc_bus_pci_dev_operations);
36255 proc_initialized = 1;
36256diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36257index 52daaa8..d6b81eb 100644
36258--- a/drivers/platform/x86/thinkpad_acpi.c
36259+++ b/drivers/platform/x86/thinkpad_acpi.c
36260@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36261 return 0;
36262 }
36263
36264-void static hotkey_mask_warn_incomplete_mask(void)
36265+static void hotkey_mask_warn_incomplete_mask(void)
36266 {
36267 /* log only what the user can fix... */
36268 const u32 wantedmask = hotkey_driver_mask &
36269@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36270 }
36271 }
36272
36273-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36274- struct tp_nvram_state *newn,
36275- const u32 event_mask)
36276-{
36277-
36278 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36279 do { \
36280 if ((event_mask & (1 << __scancode)) && \
36281@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36282 tpacpi_hotkey_send_key(__scancode); \
36283 } while (0)
36284
36285- void issue_volchange(const unsigned int oldvol,
36286- const unsigned int newvol)
36287- {
36288- unsigned int i = oldvol;
36289+static void issue_volchange(const unsigned int oldvol,
36290+ const unsigned int newvol,
36291+ const u32 event_mask)
36292+{
36293+ unsigned int i = oldvol;
36294
36295- while (i > newvol) {
36296- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36297- i--;
36298- }
36299- while (i < newvol) {
36300- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36301- i++;
36302- }
36303+ while (i > newvol) {
36304+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36305+ i--;
36306 }
36307+ while (i < newvol) {
36308+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36309+ i++;
36310+ }
36311+}
36312
36313- void issue_brightnesschange(const unsigned int oldbrt,
36314- const unsigned int newbrt)
36315- {
36316- unsigned int i = oldbrt;
36317+static void issue_brightnesschange(const unsigned int oldbrt,
36318+ const unsigned int newbrt,
36319+ const u32 event_mask)
36320+{
36321+ unsigned int i = oldbrt;
36322
36323- while (i > newbrt) {
36324- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36325- i--;
36326- }
36327- while (i < newbrt) {
36328- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36329- i++;
36330- }
36331+ while (i > newbrt) {
36332+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36333+ i--;
36334+ }
36335+ while (i < newbrt) {
36336+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36337+ i++;
36338 }
36339+}
36340
36341+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36342+ struct tp_nvram_state *newn,
36343+ const u32 event_mask)
36344+{
36345 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36346 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36347 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36348@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36349 oldn->volume_level != newn->volume_level) {
36350 /* recently muted, or repeated mute keypress, or
36351 * multiple presses ending in mute */
36352- issue_volchange(oldn->volume_level, newn->volume_level);
36353+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36354 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36355 }
36356 } else {
36357@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36358 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36359 }
36360 if (oldn->volume_level != newn->volume_level) {
36361- issue_volchange(oldn->volume_level, newn->volume_level);
36362+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36363 } else if (oldn->volume_toggle != newn->volume_toggle) {
36364 /* repeated vol up/down keypress at end of scale ? */
36365 if (newn->volume_level == 0)
36366@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36367 /* handle brightness */
36368 if (oldn->brightness_level != newn->brightness_level) {
36369 issue_brightnesschange(oldn->brightness_level,
36370- newn->brightness_level);
36371+ newn->brightness_level,
36372+ event_mask);
36373 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36374 /* repeated key presses that didn't change state */
36375 if (newn->brightness_level == 0)
36376@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36377 && !tp_features.bright_unkfw)
36378 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36379 }
36380+}
36381
36382 #undef TPACPI_COMPARE_KEY
36383 #undef TPACPI_MAY_SEND_KEY
36384-}
36385
36386 /*
36387 * Polling driver
36388diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36389index 769d265..a3a05ca 100644
36390--- a/drivers/pnp/pnpbios/bioscalls.c
36391+++ b/drivers/pnp/pnpbios/bioscalls.c
36392@@ -58,7 +58,7 @@ do { \
36393 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36394 } while(0)
36395
36396-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36397+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36398 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36399
36400 /*
36401@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36402
36403 cpu = get_cpu();
36404 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36405+
36406+ pax_open_kernel();
36407 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36408+ pax_close_kernel();
36409
36410 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36411 spin_lock_irqsave(&pnp_bios_lock, flags);
36412@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36413 :"memory");
36414 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36415
36416+ pax_open_kernel();
36417 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36418+ pax_close_kernel();
36419+
36420 put_cpu();
36421
36422 /* If we get here and this is set then the PnP BIOS faulted on us. */
36423@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36424 return status;
36425 }
36426
36427-void pnpbios_calls_init(union pnp_bios_install_struct *header)
36428+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36429 {
36430 int i;
36431
36432@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36433 pnp_bios_callpoint.offset = header->fields.pm16offset;
36434 pnp_bios_callpoint.segment = PNP_CS16;
36435
36436+ pax_open_kernel();
36437+
36438 for_each_possible_cpu(i) {
36439 struct desc_struct *gdt = get_cpu_gdt_table(i);
36440 if (!gdt)
36441@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36442 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36443 (unsigned long)__va(header->fields.pm16dseg));
36444 }
36445+
36446+ pax_close_kernel();
36447 }
36448diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36449index b0ecacb..7c9da2e 100644
36450--- a/drivers/pnp/resource.c
36451+++ b/drivers/pnp/resource.c
36452@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36453 return 1;
36454
36455 /* check if the resource is valid */
36456- if (*irq < 0 || *irq > 15)
36457+ if (*irq > 15)
36458 return 0;
36459
36460 /* check if the resource is reserved */
36461@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36462 return 1;
36463
36464 /* check if the resource is valid */
36465- if (*dma < 0 || *dma == 4 || *dma > 7)
36466+ if (*dma == 4 || *dma > 7)
36467 return 0;
36468
36469 /* check if the resource is reserved */
36470diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36471index 181ddec..774b6da 100644
36472--- a/drivers/power/bq27x00_battery.c
36473+++ b/drivers/power/bq27x00_battery.c
36474@@ -80,7 +80,7 @@
36475 struct bq27x00_device_info;
36476 struct bq27x00_access_methods {
36477 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36478-};
36479+} __no_const;
36480
36481 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36482
36483diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36484index 8d53174..04c65de 100644
36485--- a/drivers/regulator/max8660.c
36486+++ b/drivers/regulator/max8660.c
36487@@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36488 max8660->shadow_regs[MAX8660_OVER1] = 5;
36489 } else {
36490 /* Otherwise devices can be toggled via software */
36491- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36492- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36493+ pax_open_kernel();
36494+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36495+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36496+ pax_close_kernel();
36497 }
36498
36499 /*
36500diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36501index b388b74..ed82573 100644
36502--- a/drivers/regulator/mc13892-regulator.c
36503+++ b/drivers/regulator/mc13892-regulator.c
36504@@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36505 }
36506 mc13xxx_unlock(mc13892);
36507
36508- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36509+ pax_open_kernel();
36510+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36511 = mc13892_vcam_set_mode;
36512- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36513+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36514 = mc13892_vcam_get_mode;
36515+ pax_close_kernel();
36516
36517 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36518 ARRAY_SIZE(mc13892_regulators));
36519diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36520index cace6d3..f623fda 100644
36521--- a/drivers/rtc/rtc-dev.c
36522+++ b/drivers/rtc/rtc-dev.c
36523@@ -14,6 +14,7 @@
36524 #include <linux/module.h>
36525 #include <linux/rtc.h>
36526 #include <linux/sched.h>
36527+#include <linux/grsecurity.h>
36528 #include "rtc-core.h"
36529
36530 static dev_t rtc_devt;
36531@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36532 if (copy_from_user(&tm, uarg, sizeof(tm)))
36533 return -EFAULT;
36534
36535+ gr_log_timechange();
36536+
36537 return rtc_set_time(rtc, &tm);
36538
36539 case RTC_PIE_ON:
36540diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36541index 9e933a8..4f969f7 100644
36542--- a/drivers/scsi/aacraid/aacraid.h
36543+++ b/drivers/scsi/aacraid/aacraid.h
36544@@ -503,7 +503,7 @@ struct adapter_ops
36545 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36546 /* Administrative operations */
36547 int (*adapter_comm)(struct aac_dev * dev, int comm);
36548-};
36549+} __no_const;
36550
36551 /*
36552 * Define which interrupt handler needs to be installed
36553diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36554index 7199534..cb7f158 100644
36555--- a/drivers/scsi/aacraid/linit.c
36556+++ b/drivers/scsi/aacraid/linit.c
36557@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36558 #elif defined(__devinitconst)
36559 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36560 #else
36561-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36562+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36563 #endif
36564 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36565 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36566diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36567index ff80552..1c4120c 100644
36568--- a/drivers/scsi/aic94xx/aic94xx_init.c
36569+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36570@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36571 .lldd_ata_set_dmamode = asd_set_dmamode,
36572 };
36573
36574-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36575+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36576 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36577 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36578 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36579diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36580index 4ad7e36..d004679 100644
36581--- a/drivers/scsi/bfa/bfa.h
36582+++ b/drivers/scsi/bfa/bfa.h
36583@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36584 u32 *end);
36585 int cpe_vec_q0;
36586 int rme_vec_q0;
36587-};
36588+} __no_const;
36589 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36590
36591 struct bfa_faa_cbfn_s {
36592diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36593index f0f80e2..8ec946b 100644
36594--- a/drivers/scsi/bfa/bfa_fcpim.c
36595+++ b/drivers/scsi/bfa/bfa_fcpim.c
36596@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36597
36598 bfa_iotag_attach(fcp);
36599
36600- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36601+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36602 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36603 (fcp->num_itns * sizeof(struct bfa_itn_s));
36604 memset(fcp->itn_arr, 0,
36605@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36606 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36607 {
36608 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36609- struct bfa_itn_s *itn;
36610+ bfa_itn_s_no_const *itn;
36611
36612 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36613 itn->isr = isr;
36614diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36615index 36f26da..38a34a8 100644
36616--- a/drivers/scsi/bfa/bfa_fcpim.h
36617+++ b/drivers/scsi/bfa/bfa_fcpim.h
36618@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36619 struct bfa_itn_s {
36620 bfa_isr_func_t isr;
36621 };
36622+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36623
36624 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36625 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36626@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36627 struct list_head iotag_tio_free_q; /* free IO resources */
36628 struct list_head iotag_unused_q; /* unused IO resources*/
36629 struct bfa_iotag_s *iotag_arr;
36630- struct bfa_itn_s *itn_arr;
36631+ bfa_itn_s_no_const *itn_arr;
36632 int num_ioim_reqs;
36633 int num_fwtio_reqs;
36634 int num_itns;
36635diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36636index 1a99d4b..e85d64b 100644
36637--- a/drivers/scsi/bfa/bfa_ioc.h
36638+++ b/drivers/scsi/bfa/bfa_ioc.h
36639@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36640 bfa_ioc_disable_cbfn_t disable_cbfn;
36641 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36642 bfa_ioc_reset_cbfn_t reset_cbfn;
36643-};
36644+} __no_const;
36645
36646 /*
36647 * IOC event notification mechanism.
36648@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36649 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36650 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36651 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36652-};
36653+} __no_const;
36654
36655 /*
36656 * Queue element to wait for room in request queue. FIFO order is
36657diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36658index 593085a..47aa999 100644
36659--- a/drivers/scsi/hosts.c
36660+++ b/drivers/scsi/hosts.c
36661@@ -42,7 +42,7 @@
36662 #include "scsi_logging.h"
36663
36664
36665-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36666+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36667
36668
36669 static void scsi_host_cls_release(struct device *dev)
36670@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36671 * subtract one because we increment first then return, but we need to
36672 * know what the next host number was before increment
36673 */
36674- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36675+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36676 shost->dma_channel = 0xff;
36677
36678 /* These three are default values which can be overridden */
36679diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36680index f9823f2..7bc3e81 100644
36681--- a/drivers/scsi/hpsa.c
36682+++ b/drivers/scsi/hpsa.c
36683@@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36684 unsigned long flags;
36685
36686 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36687- return h->access.command_completed(h, q);
36688+ return h->access->command_completed(h, q);
36689
36690 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36691 a = rq->head[rq->current_entry];
36692@@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
36693 while (!list_empty(&h->reqQ)) {
36694 c = list_entry(h->reqQ.next, struct CommandList, list);
36695 /* can't do anything if fifo is full */
36696- if ((h->access.fifo_full(h))) {
36697+ if ((h->access->fifo_full(h))) {
36698 dev_warn(&h->pdev->dev, "fifo full\n");
36699 break;
36700 }
36701@@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
36702
36703 /* Tell the controller execute command */
36704 spin_unlock_irqrestore(&h->lock, flags);
36705- h->access.submit_command(h, c);
36706+ h->access->submit_command(h, c);
36707 spin_lock_irqsave(&h->lock, flags);
36708 }
36709 spin_unlock_irqrestore(&h->lock, flags);
36710@@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
36711
36712 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36713 {
36714- return h->access.command_completed(h, q);
36715+ return h->access->command_completed(h, q);
36716 }
36717
36718 static inline bool interrupt_pending(struct ctlr_info *h)
36719 {
36720- return h->access.intr_pending(h);
36721+ return h->access->intr_pending(h);
36722 }
36723
36724 static inline long interrupt_not_for_us(struct ctlr_info *h)
36725 {
36726- return (h->access.intr_pending(h) == 0) ||
36727+ return (h->access->intr_pending(h) == 0) ||
36728 (h->interrupts_enabled == 0);
36729 }
36730
36731@@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36732 if (prod_index < 0)
36733 return -ENODEV;
36734 h->product_name = products[prod_index].product_name;
36735- h->access = *(products[prod_index].access);
36736+ h->access = products[prod_index].access;
36737
36738 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36739 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36740@@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36741
36742 assert_spin_locked(&lockup_detector_lock);
36743 remove_ctlr_from_lockup_detector_list(h);
36744- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36745+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36746 spin_lock_irqsave(&h->lock, flags);
36747 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36748 spin_unlock_irqrestore(&h->lock, flags);
36749@@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
36750 }
36751
36752 /* make sure the board interrupts are off */
36753- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36754+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36755
36756 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36757 goto clean2;
36758@@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
36759 * fake ones to scoop up any residual completions.
36760 */
36761 spin_lock_irqsave(&h->lock, flags);
36762- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36763+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36764 spin_unlock_irqrestore(&h->lock, flags);
36765 free_irqs(h);
36766 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36767@@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
36768 dev_info(&h->pdev->dev, "Board READY.\n");
36769 dev_info(&h->pdev->dev,
36770 "Waiting for stale completions to drain.\n");
36771- h->access.set_intr_mask(h, HPSA_INTR_ON);
36772+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36773 msleep(10000);
36774- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36775+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36776
36777 rc = controller_reset_failed(h->cfgtable);
36778 if (rc)
36779@@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
36780 }
36781
36782 /* Turn the interrupts on so we can service requests */
36783- h->access.set_intr_mask(h, HPSA_INTR_ON);
36784+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36785
36786 hpsa_hba_inquiry(h);
36787 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36788@@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36789 * To write all data in the battery backed cache to disks
36790 */
36791 hpsa_flush_cache(h);
36792- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36793+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36794 hpsa_free_irqs_and_disable_msix(h);
36795 }
36796
36797@@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36798 return;
36799 }
36800 /* Change the access methods to the performant access methods */
36801- h->access = SA5_performant_access;
36802+ h->access = &SA5_performant_access;
36803 h->transMethod = CFGTBL_Trans_Performant;
36804 }
36805
36806diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36807index 9816479..c5d4e97 100644
36808--- a/drivers/scsi/hpsa.h
36809+++ b/drivers/scsi/hpsa.h
36810@@ -79,7 +79,7 @@ struct ctlr_info {
36811 unsigned int msix_vector;
36812 unsigned int msi_vector;
36813 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36814- struct access_method access;
36815+ struct access_method *access;
36816
36817 /* queue and queue Info */
36818 struct list_head reqQ;
36819diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36820index f2df059..a3a9930 100644
36821--- a/drivers/scsi/ips.h
36822+++ b/drivers/scsi/ips.h
36823@@ -1027,7 +1027,7 @@ typedef struct {
36824 int (*intr)(struct ips_ha *);
36825 void (*enableint)(struct ips_ha *);
36826 uint32_t (*statupd)(struct ips_ha *);
36827-} ips_hw_func_t;
36828+} __no_const ips_hw_func_t;
36829
36830 typedef struct ips_ha {
36831 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36832diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36833index c772d8d..35c362c 100644
36834--- a/drivers/scsi/libfc/fc_exch.c
36835+++ b/drivers/scsi/libfc/fc_exch.c
36836@@ -100,12 +100,12 @@ struct fc_exch_mgr {
36837 u16 pool_max_index;
36838
36839 struct {
36840- atomic_t no_free_exch;
36841- atomic_t no_free_exch_xid;
36842- atomic_t xid_not_found;
36843- atomic_t xid_busy;
36844- atomic_t seq_not_found;
36845- atomic_t non_bls_resp;
36846+ atomic_unchecked_t no_free_exch;
36847+ atomic_unchecked_t no_free_exch_xid;
36848+ atomic_unchecked_t xid_not_found;
36849+ atomic_unchecked_t xid_busy;
36850+ atomic_unchecked_t seq_not_found;
36851+ atomic_unchecked_t non_bls_resp;
36852 } stats;
36853 };
36854
36855@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36856 /* allocate memory for exchange */
36857 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36858 if (!ep) {
36859- atomic_inc(&mp->stats.no_free_exch);
36860+ atomic_inc_unchecked(&mp->stats.no_free_exch);
36861 goto out;
36862 }
36863 memset(ep, 0, sizeof(*ep));
36864@@ -786,7 +786,7 @@ out:
36865 return ep;
36866 err:
36867 spin_unlock_bh(&pool->lock);
36868- atomic_inc(&mp->stats.no_free_exch_xid);
36869+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36870 mempool_free(ep, mp->ep_pool);
36871 return NULL;
36872 }
36873@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36874 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36875 ep = fc_exch_find(mp, xid);
36876 if (!ep) {
36877- atomic_inc(&mp->stats.xid_not_found);
36878+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36879 reject = FC_RJT_OX_ID;
36880 goto out;
36881 }
36882@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36883 ep = fc_exch_find(mp, xid);
36884 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36885 if (ep) {
36886- atomic_inc(&mp->stats.xid_busy);
36887+ atomic_inc_unchecked(&mp->stats.xid_busy);
36888 reject = FC_RJT_RX_ID;
36889 goto rel;
36890 }
36891@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36892 }
36893 xid = ep->xid; /* get our XID */
36894 } else if (!ep) {
36895- atomic_inc(&mp->stats.xid_not_found);
36896+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36897 reject = FC_RJT_RX_ID; /* XID not found */
36898 goto out;
36899 }
36900@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36901 } else {
36902 sp = &ep->seq;
36903 if (sp->id != fh->fh_seq_id) {
36904- atomic_inc(&mp->stats.seq_not_found);
36905+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36906 if (f_ctl & FC_FC_END_SEQ) {
36907 /*
36908 * Update sequence_id based on incoming last
36909@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36910
36911 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36912 if (!ep) {
36913- atomic_inc(&mp->stats.xid_not_found);
36914+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36915 goto out;
36916 }
36917 if (ep->esb_stat & ESB_ST_COMPLETE) {
36918- atomic_inc(&mp->stats.xid_not_found);
36919+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36920 goto rel;
36921 }
36922 if (ep->rxid == FC_XID_UNKNOWN)
36923 ep->rxid = ntohs(fh->fh_rx_id);
36924 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36925- atomic_inc(&mp->stats.xid_not_found);
36926+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36927 goto rel;
36928 }
36929 if (ep->did != ntoh24(fh->fh_s_id) &&
36930 ep->did != FC_FID_FLOGI) {
36931- atomic_inc(&mp->stats.xid_not_found);
36932+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36933 goto rel;
36934 }
36935 sof = fr_sof(fp);
36936@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36937 sp->ssb_stat |= SSB_ST_RESP;
36938 sp->id = fh->fh_seq_id;
36939 } else if (sp->id != fh->fh_seq_id) {
36940- atomic_inc(&mp->stats.seq_not_found);
36941+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36942 goto rel;
36943 }
36944
36945@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36946 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36947
36948 if (!sp)
36949- atomic_inc(&mp->stats.xid_not_found);
36950+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36951 else
36952- atomic_inc(&mp->stats.non_bls_resp);
36953+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
36954
36955 fc_frame_free(fp);
36956 }
36957@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
36958
36959 list_for_each_entry(ema, &lport->ema_list, ema_list) {
36960 mp = ema->mp;
36961- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
36962+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
36963 st->fc_no_free_exch_xid +=
36964- atomic_read(&mp->stats.no_free_exch_xid);
36965- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
36966- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
36967- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
36968- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
36969+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
36970+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
36971+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
36972+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
36973+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
36974 }
36975 }
36976 EXPORT_SYMBOL(fc_exch_update_stats);
36977diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36978index a59fcdc..abe55f3 100644
36979--- a/drivers/scsi/libsas/sas_ata.c
36980+++ b/drivers/scsi/libsas/sas_ata.c
36981@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
36982 .postreset = ata_std_postreset,
36983 .error_handler = ata_std_error_handler,
36984 .post_internal_cmd = sas_ata_post_internal,
36985- .qc_defer = ata_std_qc_defer,
36986+ .qc_defer = ata_std_qc_defer,
36987 .qc_prep = ata_noop_qc_prep,
36988 .qc_issue = sas_ata_qc_issue,
36989 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36990diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36991index a65c05a..a39e402 100644
36992--- a/drivers/scsi/lpfc/lpfc.h
36993+++ b/drivers/scsi/lpfc/lpfc.h
36994@@ -420,7 +420,7 @@ struct lpfc_vport {
36995 struct dentry *debug_nodelist;
36996 struct dentry *vport_debugfs_root;
36997 struct lpfc_debugfs_trc *disc_trc;
36998- atomic_t disc_trc_cnt;
36999+ atomic_unchecked_t disc_trc_cnt;
37000 #endif
37001 uint8_t stat_data_enabled;
37002 uint8_t stat_data_blocked;
37003@@ -834,8 +834,8 @@ struct lpfc_hba {
37004 struct timer_list fabric_block_timer;
37005 unsigned long bit_flags;
37006 #define FABRIC_COMANDS_BLOCKED 0
37007- atomic_t num_rsrc_err;
37008- atomic_t num_cmd_success;
37009+ atomic_unchecked_t num_rsrc_err;
37010+ atomic_unchecked_t num_cmd_success;
37011 unsigned long last_rsrc_error_time;
37012 unsigned long last_ramp_down_time;
37013 unsigned long last_ramp_up_time;
37014@@ -871,7 +871,7 @@ struct lpfc_hba {
37015
37016 struct dentry *debug_slow_ring_trc;
37017 struct lpfc_debugfs_trc *slow_ring_trc;
37018- atomic_t slow_ring_trc_cnt;
37019+ atomic_unchecked_t slow_ring_trc_cnt;
37020 /* iDiag debugfs sub-directory */
37021 struct dentry *idiag_root;
37022 struct dentry *idiag_pci_cfg;
37023diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37024index 3217d63..c417981 100644
37025--- a/drivers/scsi/lpfc/lpfc_debugfs.c
37026+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37027@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37028
37029 #include <linux/debugfs.h>
37030
37031-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37032+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37033 static unsigned long lpfc_debugfs_start_time = 0L;
37034
37035 /* iDiag */
37036@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37037 lpfc_debugfs_enable = 0;
37038
37039 len = 0;
37040- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37041+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37042 (lpfc_debugfs_max_disc_trc - 1);
37043 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37044 dtp = vport->disc_trc + i;
37045@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37046 lpfc_debugfs_enable = 0;
37047
37048 len = 0;
37049- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37050+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37051 (lpfc_debugfs_max_slow_ring_trc - 1);
37052 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37053 dtp = phba->slow_ring_trc + i;
37054@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37055 !vport || !vport->disc_trc)
37056 return;
37057
37058- index = atomic_inc_return(&vport->disc_trc_cnt) &
37059+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37060 (lpfc_debugfs_max_disc_trc - 1);
37061 dtp = vport->disc_trc + index;
37062 dtp->fmt = fmt;
37063 dtp->data1 = data1;
37064 dtp->data2 = data2;
37065 dtp->data3 = data3;
37066- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37067+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37068 dtp->jif = jiffies;
37069 #endif
37070 return;
37071@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37072 !phba || !phba->slow_ring_trc)
37073 return;
37074
37075- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37076+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37077 (lpfc_debugfs_max_slow_ring_trc - 1);
37078 dtp = phba->slow_ring_trc + index;
37079 dtp->fmt = fmt;
37080 dtp->data1 = data1;
37081 dtp->data2 = data2;
37082 dtp->data3 = data3;
37083- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37084+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37085 dtp->jif = jiffies;
37086 #endif
37087 return;
37088@@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37089 "slow_ring buffer\n");
37090 goto debug_failed;
37091 }
37092- atomic_set(&phba->slow_ring_trc_cnt, 0);
37093+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37094 memset(phba->slow_ring_trc, 0,
37095 (sizeof(struct lpfc_debugfs_trc) *
37096 lpfc_debugfs_max_slow_ring_trc));
37097@@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37098 "buffer\n");
37099 goto debug_failed;
37100 }
37101- atomic_set(&vport->disc_trc_cnt, 0);
37102+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37103
37104 snprintf(name, sizeof(name), "discovery_trace");
37105 vport->debug_disc_trc =
37106diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37107index 45c1520..35ba744 100644
37108--- a/drivers/scsi/lpfc/lpfc_init.c
37109+++ b/drivers/scsi/lpfc/lpfc_init.c
37110@@ -10478,8 +10478,10 @@ lpfc_init(void)
37111 "misc_register returned with status %d", error);
37112
37113 if (lpfc_enable_npiv) {
37114- lpfc_transport_functions.vport_create = lpfc_vport_create;
37115- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37116+ pax_open_kernel();
37117+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37118+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37119+ pax_close_kernel();
37120 }
37121 lpfc_transport_template =
37122 fc_attach_transport(&lpfc_transport_functions);
37123diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37124index 925975d..0f1fc07 100644
37125--- a/drivers/scsi/lpfc/lpfc_scsi.c
37126+++ b/drivers/scsi/lpfc/lpfc_scsi.c
37127@@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37128 uint32_t evt_posted;
37129
37130 spin_lock_irqsave(&phba->hbalock, flags);
37131- atomic_inc(&phba->num_rsrc_err);
37132+ atomic_inc_unchecked(&phba->num_rsrc_err);
37133 phba->last_rsrc_error_time = jiffies;
37134
37135 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37136@@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37137 unsigned long flags;
37138 struct lpfc_hba *phba = vport->phba;
37139 uint32_t evt_posted;
37140- atomic_inc(&phba->num_cmd_success);
37141+ atomic_inc_unchecked(&phba->num_cmd_success);
37142
37143 if (vport->cfg_lun_queue_depth <= queue_depth)
37144 return;
37145@@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37146 unsigned long num_rsrc_err, num_cmd_success;
37147 int i;
37148
37149- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37150- num_cmd_success = atomic_read(&phba->num_cmd_success);
37151+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37152+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37153
37154 /*
37155 * The error and success command counters are global per
37156@@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37157 }
37158 }
37159 lpfc_destroy_vport_work_array(phba, vports);
37160- atomic_set(&phba->num_rsrc_err, 0);
37161- atomic_set(&phba->num_cmd_success, 0);
37162+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37163+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37164 }
37165
37166 /**
37167@@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37168 }
37169 }
37170 lpfc_destroy_vport_work_array(phba, vports);
37171- atomic_set(&phba->num_rsrc_err, 0);
37172- atomic_set(&phba->num_cmd_success, 0);
37173+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37174+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37175 }
37176
37177 /**
37178diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37179index ea8a0b4..812a124 100644
37180--- a/drivers/scsi/pmcraid.c
37181+++ b/drivers/scsi/pmcraid.c
37182@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37183 res->scsi_dev = scsi_dev;
37184 scsi_dev->hostdata = res;
37185 res->change_detected = 0;
37186- atomic_set(&res->read_failures, 0);
37187- atomic_set(&res->write_failures, 0);
37188+ atomic_set_unchecked(&res->read_failures, 0);
37189+ atomic_set_unchecked(&res->write_failures, 0);
37190 rc = 0;
37191 }
37192 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37193@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37194
37195 /* If this was a SCSI read/write command keep count of errors */
37196 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37197- atomic_inc(&res->read_failures);
37198+ atomic_inc_unchecked(&res->read_failures);
37199 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37200- atomic_inc(&res->write_failures);
37201+ atomic_inc_unchecked(&res->write_failures);
37202
37203 if (!RES_IS_GSCSI(res->cfg_entry) &&
37204 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37205@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37206 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37207 * hrrq_id assigned here in queuecommand
37208 */
37209- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37210+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37211 pinstance->num_hrrq;
37212 cmd->cmd_done = pmcraid_io_done;
37213
37214@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37215 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37216 * hrrq_id assigned here in queuecommand
37217 */
37218- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37219+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37220 pinstance->num_hrrq;
37221
37222 if (request_size) {
37223@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37224
37225 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37226 /* add resources only after host is added into system */
37227- if (!atomic_read(&pinstance->expose_resources))
37228+ if (!atomic_read_unchecked(&pinstance->expose_resources))
37229 return;
37230
37231 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37232@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37233 init_waitqueue_head(&pinstance->reset_wait_q);
37234
37235 atomic_set(&pinstance->outstanding_cmds, 0);
37236- atomic_set(&pinstance->last_message_id, 0);
37237- atomic_set(&pinstance->expose_resources, 0);
37238+ atomic_set_unchecked(&pinstance->last_message_id, 0);
37239+ atomic_set_unchecked(&pinstance->expose_resources, 0);
37240
37241 INIT_LIST_HEAD(&pinstance->free_res_q);
37242 INIT_LIST_HEAD(&pinstance->used_res_q);
37243@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37244 /* Schedule worker thread to handle CCN and take care of adding and
37245 * removing devices to OS
37246 */
37247- atomic_set(&pinstance->expose_resources, 1);
37248+ atomic_set_unchecked(&pinstance->expose_resources, 1);
37249 schedule_work(&pinstance->worker_q);
37250 return rc;
37251
37252diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37253index e1d150f..6c6df44 100644
37254--- a/drivers/scsi/pmcraid.h
37255+++ b/drivers/scsi/pmcraid.h
37256@@ -748,7 +748,7 @@ struct pmcraid_instance {
37257 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37258
37259 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37260- atomic_t last_message_id;
37261+ atomic_unchecked_t last_message_id;
37262
37263 /* configuration table */
37264 struct pmcraid_config_table *cfg_table;
37265@@ -777,7 +777,7 @@ struct pmcraid_instance {
37266 atomic_t outstanding_cmds;
37267
37268 /* should add/delete resources to mid-layer now ?*/
37269- atomic_t expose_resources;
37270+ atomic_unchecked_t expose_resources;
37271
37272
37273
37274@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37275 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37276 };
37277 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37278- atomic_t read_failures; /* count of failed READ commands */
37279- atomic_t write_failures; /* count of failed WRITE commands */
37280+ atomic_unchecked_t read_failures; /* count of failed READ commands */
37281+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37282
37283 /* To indicate add/delete/modify during CCN */
37284 u8 change_detected;
37285diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37286index 5ab9530..2dd80f7 100644
37287--- a/drivers/scsi/qla2xxx/qla_attr.c
37288+++ b/drivers/scsi/qla2xxx/qla_attr.c
37289@@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37290 return 0;
37291 }
37292
37293-struct fc_function_template qla2xxx_transport_functions = {
37294+fc_function_template_no_const qla2xxx_transport_functions = {
37295
37296 .show_host_node_name = 1,
37297 .show_host_port_name = 1,
37298@@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37299 .bsg_timeout = qla24xx_bsg_timeout,
37300 };
37301
37302-struct fc_function_template qla2xxx_transport_vport_functions = {
37303+fc_function_template_no_const qla2xxx_transport_vport_functions = {
37304
37305 .show_host_node_name = 1,
37306 .show_host_port_name = 1,
37307diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37308index 39007f5..7fafc64 100644
37309--- a/drivers/scsi/qla2xxx/qla_def.h
37310+++ b/drivers/scsi/qla2xxx/qla_def.h
37311@@ -2284,7 +2284,7 @@ struct isp_operations {
37312 int (*start_scsi) (srb_t *);
37313 int (*abort_isp) (struct scsi_qla_host *);
37314 int (*iospace_config)(struct qla_hw_data*);
37315-};
37316+} __no_const;
37317
37318 /* MSI-X Support *************************************************************/
37319
37320diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37321index 9eacd2d..d79629c 100644
37322--- a/drivers/scsi/qla2xxx/qla_gbl.h
37323+++ b/drivers/scsi/qla2xxx/qla_gbl.h
37324@@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37325 struct device_attribute;
37326 extern struct device_attribute *qla2x00_host_attrs[];
37327 struct fc_function_template;
37328-extern struct fc_function_template qla2xxx_transport_functions;
37329-extern struct fc_function_template qla2xxx_transport_vport_functions;
37330+extern fc_function_template_no_const qla2xxx_transport_functions;
37331+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37332 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37333 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37334 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37335diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37336index 7fdba7f..1b4b2c2 100644
37337--- a/drivers/scsi/qla4xxx/ql4_def.h
37338+++ b/drivers/scsi/qla4xxx/ql4_def.h
37339@@ -268,7 +268,7 @@ struct ddb_entry {
37340 * (4000 only) */
37341 atomic_t relogin_timer; /* Max Time to wait for
37342 * relogin to complete */
37343- atomic_t relogin_retry_count; /* Num of times relogin has been
37344+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37345 * retried */
37346 uint32_t default_time2wait; /* Default Min time between
37347 * relogins (+aens) */
37348diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37349index 9da4266..377b3b6 100644
37350--- a/drivers/scsi/qla4xxx/ql4_os.c
37351+++ b/drivers/scsi/qla4xxx/ql4_os.c
37352@@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37353 */
37354 if (!iscsi_is_session_online(cls_sess)) {
37355 /* Reset retry relogin timer */
37356- atomic_inc(&ddb_entry->relogin_retry_count);
37357+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37358 DEBUG2(ql4_printk(KERN_INFO, ha,
37359 "%s: index[%d] relogin timed out-retrying"
37360 " relogin (%d), retry (%d)\n", __func__,
37361 ddb_entry->fw_ddb_index,
37362- atomic_read(&ddb_entry->relogin_retry_count),
37363+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37364 ddb_entry->default_time2wait + 4));
37365 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37366 atomic_set(&ddb_entry->retry_relogin_timer,
37367@@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37368
37369 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37370 atomic_set(&ddb_entry->relogin_timer, 0);
37371- atomic_set(&ddb_entry->relogin_retry_count, 0);
37372+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37373 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37374 ddb_entry->default_relogin_timeout =
37375 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37376diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37377index 2936b44..546ecdb 100644
37378--- a/drivers/scsi/scsi.c
37379+++ b/drivers/scsi/scsi.c
37380@@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37381 unsigned long timeout;
37382 int rtn = 0;
37383
37384- atomic_inc(&cmd->device->iorequest_cnt);
37385+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37386
37387 /* check if the device is still usable */
37388 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37389diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37390index faa790f..7e351ddd 100644
37391--- a/drivers/scsi/scsi_lib.c
37392+++ b/drivers/scsi/scsi_lib.c
37393@@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37394 shost = sdev->host;
37395 scsi_init_cmd_errh(cmd);
37396 cmd->result = DID_NO_CONNECT << 16;
37397- atomic_inc(&cmd->device->iorequest_cnt);
37398+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37399
37400 /*
37401 * SCSI request completion path will do scsi_device_unbusy(),
37402@@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37403
37404 INIT_LIST_HEAD(&cmd->eh_entry);
37405
37406- atomic_inc(&cmd->device->iodone_cnt);
37407+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
37408 if (cmd->result)
37409- atomic_inc(&cmd->device->ioerr_cnt);
37410+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37411
37412 disposition = scsi_decide_disposition(cmd);
37413 if (disposition != SUCCESS &&
37414diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37415index ce5224c..8c6d071 100644
37416--- a/drivers/scsi/scsi_sysfs.c
37417+++ b/drivers/scsi/scsi_sysfs.c
37418@@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37419 char *buf) \
37420 { \
37421 struct scsi_device *sdev = to_scsi_device(dev); \
37422- unsigned long long count = atomic_read(&sdev->field); \
37423+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
37424 return snprintf(buf, 20, "0x%llx\n", count); \
37425 } \
37426 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37427diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37428index 84a1fdf..693b0d6 100644
37429--- a/drivers/scsi/scsi_tgt_lib.c
37430+++ b/drivers/scsi/scsi_tgt_lib.c
37431@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37432 int err;
37433
37434 dprintk("%lx %u\n", uaddr, len);
37435- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37436+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37437 if (err) {
37438 /*
37439 * TODO: need to fixup sg_tablesize, max_segment_size,
37440diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37441index e894ca7..de9d7660 100644
37442--- a/drivers/scsi/scsi_transport_fc.c
37443+++ b/drivers/scsi/scsi_transport_fc.c
37444@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37445 * Netlink Infrastructure
37446 */
37447
37448-static atomic_t fc_event_seq;
37449+static atomic_unchecked_t fc_event_seq;
37450
37451 /**
37452 * fc_get_event_number - Obtain the next sequential FC event number
37453@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37454 u32
37455 fc_get_event_number(void)
37456 {
37457- return atomic_add_return(1, &fc_event_seq);
37458+ return atomic_add_return_unchecked(1, &fc_event_seq);
37459 }
37460 EXPORT_SYMBOL(fc_get_event_number);
37461
37462@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37463 {
37464 int error;
37465
37466- atomic_set(&fc_event_seq, 0);
37467+ atomic_set_unchecked(&fc_event_seq, 0);
37468
37469 error = transport_class_register(&fc_host_class);
37470 if (error)
37471@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37472 char *cp;
37473
37474 *val = simple_strtoul(buf, &cp, 0);
37475- if ((*cp && (*cp != '\n')) || (*val < 0))
37476+ if (*cp && (*cp != '\n'))
37477 return -EINVAL;
37478 /*
37479 * Check for overflow; dev_loss_tmo is u32
37480diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37481index fa1dfaa..4bb620c 100644
37482--- a/drivers/scsi/scsi_transport_iscsi.c
37483+++ b/drivers/scsi/scsi_transport_iscsi.c
37484@@ -79,7 +79,7 @@ struct iscsi_internal {
37485 struct transport_container session_cont;
37486 };
37487
37488-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37489+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37490 static struct workqueue_struct *iscsi_eh_timer_workq;
37491
37492 static DEFINE_IDA(iscsi_sess_ida);
37493@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37494 int err;
37495
37496 ihost = shost->shost_data;
37497- session->sid = atomic_add_return(1, &iscsi_session_nr);
37498+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37499
37500 if (target_id == ISCSI_MAX_TARGET) {
37501 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37502@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37503 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37504 ISCSI_TRANSPORT_VERSION);
37505
37506- atomic_set(&iscsi_session_nr, 0);
37507+ atomic_set_unchecked(&iscsi_session_nr, 0);
37508
37509 err = class_register(&iscsi_transport_class);
37510 if (err)
37511diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37512index 21a045e..ec89e03 100644
37513--- a/drivers/scsi/scsi_transport_srp.c
37514+++ b/drivers/scsi/scsi_transport_srp.c
37515@@ -33,7 +33,7 @@
37516 #include "scsi_transport_srp_internal.h"
37517
37518 struct srp_host_attrs {
37519- atomic_t next_port_id;
37520+ atomic_unchecked_t next_port_id;
37521 };
37522 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37523
37524@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37525 struct Scsi_Host *shost = dev_to_shost(dev);
37526 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37527
37528- atomic_set(&srp_host->next_port_id, 0);
37529+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37530 return 0;
37531 }
37532
37533@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37534 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37535 rport->roles = ids->roles;
37536
37537- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37538+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37539 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37540
37541 transport_setup_device(&rport->dev);
37542diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37543index 4df73e5..b691c58 100644
37544--- a/drivers/scsi/sd.c
37545+++ b/drivers/scsi/sd.c
37546@@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37547 sdkp->disk = gd;
37548 sdkp->index = index;
37549 atomic_set(&sdkp->openers, 0);
37550- atomic_set(&sdkp->device->ioerr_cnt, 0);
37551+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37552
37553 if (!sdp->request_queue->rq_timeout) {
37554 if (sdp->type != TYPE_MOD)
37555diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37556index 9c5c5f2..8414557 100644
37557--- a/drivers/scsi/sg.c
37558+++ b/drivers/scsi/sg.c
37559@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37560 sdp->disk->disk_name,
37561 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37562 NULL,
37563- (char *)arg);
37564+ (char __user *)arg);
37565 case BLKTRACESTART:
37566 return blk_trace_startstop(sdp->device->request_queue, 1);
37567 case BLKTRACESTOP:
37568diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37569index 84c2861..ece0a31 100644
37570--- a/drivers/spi/spi.c
37571+++ b/drivers/spi/spi.c
37572@@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37573 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37574
37575 /* portable code must never pass more than 32 bytes */
37576-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37577+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37578
37579 static u8 *buf;
37580
37581diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37582index 34afc16..ffe44dd 100644
37583--- a/drivers/staging/octeon/ethernet-rx.c
37584+++ b/drivers/staging/octeon/ethernet-rx.c
37585@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37586 /* Increment RX stats for virtual ports */
37587 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37588 #ifdef CONFIG_64BIT
37589- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37590- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37591+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37592+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37593 #else
37594- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37595- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37596+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37597+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37598 #endif
37599 }
37600 netif_receive_skb(skb);
37601@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37602 dev->name);
37603 */
37604 #ifdef CONFIG_64BIT
37605- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37606+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37607 #else
37608- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37609+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37610 #endif
37611 dev_kfree_skb_irq(skb);
37612 }
37613diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37614index 683bedc..86dba9a 100644
37615--- a/drivers/staging/octeon/ethernet.c
37616+++ b/drivers/staging/octeon/ethernet.c
37617@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37618 * since the RX tasklet also increments it.
37619 */
37620 #ifdef CONFIG_64BIT
37621- atomic64_add(rx_status.dropped_packets,
37622- (atomic64_t *)&priv->stats.rx_dropped);
37623+ atomic64_add_unchecked(rx_status.dropped_packets,
37624+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37625 #else
37626- atomic_add(rx_status.dropped_packets,
37627- (atomic_t *)&priv->stats.rx_dropped);
37628+ atomic_add_unchecked(rx_status.dropped_packets,
37629+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37630 #endif
37631 }
37632
37633diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37634index dc23395..cf7e9b1 100644
37635--- a/drivers/staging/rtl8712/rtl871x_io.h
37636+++ b/drivers/staging/rtl8712/rtl871x_io.h
37637@@ -108,7 +108,7 @@ struct _io_ops {
37638 u8 *pmem);
37639 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37640 u8 *pmem);
37641-};
37642+} __no_const;
37643
37644 struct io_req {
37645 struct list_head list;
37646diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37647index c7b5e8b..783d6cb 100644
37648--- a/drivers/staging/sbe-2t3e3/netdev.c
37649+++ b/drivers/staging/sbe-2t3e3/netdev.c
37650@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37651 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37652
37653 if (rlen)
37654- if (copy_to_user(data, &resp, rlen))
37655+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37656 return -EFAULT;
37657
37658 return 0;
37659diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37660index 5d89c0f..9261317 100644
37661--- a/drivers/staging/usbip/usbip_common.h
37662+++ b/drivers/staging/usbip/usbip_common.h
37663@@ -289,7 +289,7 @@ struct usbip_device {
37664 void (*shutdown)(struct usbip_device *);
37665 void (*reset)(struct usbip_device *);
37666 void (*unusable)(struct usbip_device *);
37667- } eh_ops;
37668+ } __no_const eh_ops;
37669 };
37670
37671 #define kthread_get_run(threadfn, data, namefmt, ...) \
37672diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37673index c66b8b3..a4a035b 100644
37674--- a/drivers/staging/usbip/vhci.h
37675+++ b/drivers/staging/usbip/vhci.h
37676@@ -83,7 +83,7 @@ struct vhci_hcd {
37677 unsigned resuming:1;
37678 unsigned long re_timeout;
37679
37680- atomic_t seqnum;
37681+ atomic_unchecked_t seqnum;
37682
37683 /*
37684 * NOTE:
37685diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37686index 12a9a5f..afd8295 100644
37687--- a/drivers/staging/usbip/vhci_hcd.c
37688+++ b/drivers/staging/usbip/vhci_hcd.c
37689@@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37690 return;
37691 }
37692
37693- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37694+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37695 if (priv->seqnum == 0xffff)
37696 dev_info(&urb->dev->dev, "seqnum max\n");
37697
37698@@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37699 return -ENOMEM;
37700 }
37701
37702- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37703+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37704 if (unlink->seqnum == 0xffff)
37705 pr_info("seqnum max\n");
37706
37707@@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
37708 vdev->rhport = rhport;
37709 }
37710
37711- atomic_set(&vhci->seqnum, 0);
37712+ atomic_set_unchecked(&vhci->seqnum, 0);
37713 spin_lock_init(&vhci->lock);
37714
37715 hcd->power_budget = 0; /* no limit */
37716diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37717index f0eaf04..5a82e06 100644
37718--- a/drivers/staging/usbip/vhci_rx.c
37719+++ b/drivers/staging/usbip/vhci_rx.c
37720@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37721 if (!urb) {
37722 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37723 pr_info("max seqnum %d\n",
37724- atomic_read(&the_controller->seqnum));
37725+ atomic_read_unchecked(&the_controller->seqnum));
37726 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37727 return;
37728 }
37729diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37730index 6ac6f45..1b208ba 100644
37731--- a/drivers/staging/vt6655/hostap.c
37732+++ b/drivers/staging/vt6655/hostap.c
37733@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37734 *
37735 */
37736
37737+static net_device_ops_no_const apdev_netdev_ops;
37738+
37739 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37740 {
37741 PSDevice apdev_priv;
37742 struct net_device *dev = pDevice->dev;
37743 int ret;
37744- const struct net_device_ops apdev_netdev_ops = {
37745- .ndo_start_xmit = pDevice->tx_80211,
37746- };
37747
37748 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37749
37750@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37751 *apdev_priv = *pDevice;
37752 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37753
37754+ /* only half broken now */
37755+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37756 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37757
37758 pDevice->apdev->type = ARPHRD_IEEE80211;
37759diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37760index 682002a..35ed5cf 100644
37761--- a/drivers/staging/vt6656/hostap.c
37762+++ b/drivers/staging/vt6656/hostap.c
37763@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37764 *
37765 */
37766
37767+static net_device_ops_no_const apdev_netdev_ops;
37768+
37769 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37770 {
37771 PSDevice apdev_priv;
37772 struct net_device *dev = pDevice->dev;
37773 int ret;
37774- const struct net_device_ops apdev_netdev_ops = {
37775- .ndo_start_xmit = pDevice->tx_80211,
37776- };
37777
37778 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37779
37780@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37781 *apdev_priv = *pDevice;
37782 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37783
37784+ /* only half broken now */
37785+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37786 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37787
37788 pDevice->apdev->type = ARPHRD_IEEE80211;
37789diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37790index 7843dfd..3db105f 100644
37791--- a/drivers/staging/wlan-ng/hfa384x_usb.c
37792+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37793@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37794
37795 struct usbctlx_completor {
37796 int (*complete) (struct usbctlx_completor *);
37797-};
37798+} __no_const;
37799
37800 static int
37801 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37802diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37803index eaa9021..43f023b 100644
37804--- a/drivers/staging/zcache/tmem.c
37805+++ b/drivers/staging/zcache/tmem.c
37806@@ -39,7 +39,7 @@
37807 * A tmem host implementation must use this function to register callbacks
37808 * for memory allocation.
37809 */
37810-static struct tmem_hostops tmem_hostops;
37811+static tmem_hostops_no_const tmem_hostops;
37812
37813 static void tmem_objnode_tree_init(void);
37814
37815@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37816 * A tmem host implementation must use this function to register
37817 * callbacks for a page-accessible memory (PAM) implementation
37818 */
37819-static struct tmem_pamops tmem_pamops;
37820+static tmem_pamops_no_const tmem_pamops;
37821
37822 void tmem_register_pamops(struct tmem_pamops *m)
37823 {
37824diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37825index 0d4aa82..f7832d4 100644
37826--- a/drivers/staging/zcache/tmem.h
37827+++ b/drivers/staging/zcache/tmem.h
37828@@ -180,6 +180,7 @@ struct tmem_pamops {
37829 void (*new_obj)(struct tmem_obj *);
37830 int (*replace_in_obj)(void *, struct tmem_obj *);
37831 };
37832+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37833 extern void tmem_register_pamops(struct tmem_pamops *m);
37834
37835 /* memory allocation methods provided by the host implementation */
37836@@ -189,6 +190,7 @@ struct tmem_hostops {
37837 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37838 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37839 };
37840+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37841 extern void tmem_register_hostops(struct tmem_hostops *m);
37842
37843 /* core tmem accessor functions */
37844diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37845index 269f544..32def0d 100644
37846--- a/drivers/target/target_core_transport.c
37847+++ b/drivers/target/target_core_transport.c
37848@@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
37849 spin_lock_init(&dev->se_port_lock);
37850 spin_lock_init(&dev->se_tmr_lock);
37851 spin_lock_init(&dev->qf_cmd_lock);
37852- atomic_set(&dev->dev_ordered_id, 0);
37853+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
37854
37855 se_dev_set_default_attribs(dev, dev_limits);
37856
37857@@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37858 * Used to determine when ORDERED commands should go from
37859 * Dormant to Active status.
37860 */
37861- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37862+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37863 smp_mb__after_atomic_inc();
37864 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37865 cmd->se_ordered_id, cmd->sam_task_attr,
37866diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37867index e61cabd..7617d26 100644
37868--- a/drivers/tty/cyclades.c
37869+++ b/drivers/tty/cyclades.c
37870@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37871 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37872 info->port.count);
37873 #endif
37874- info->port.count++;
37875+ atomic_inc(&info->port.count);
37876 #ifdef CY_DEBUG_COUNT
37877 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37878- current->pid, info->port.count);
37879+ current->pid, atomic_read(&info->port.count));
37880 #endif
37881
37882 /*
37883@@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37884 for (j = 0; j < cy_card[i].nports; j++) {
37885 info = &cy_card[i].ports[j];
37886
37887- if (info->port.count) {
37888+ if (atomic_read(&info->port.count)) {
37889 /* XXX is the ldisc num worth this? */
37890 struct tty_struct *tty;
37891 struct tty_ldisc *ld;
37892diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37893index 2d691eb..be02ebd 100644
37894--- a/drivers/tty/hvc/hvc_console.c
37895+++ b/drivers/tty/hvc/hvc_console.c
37896@@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37897
37898 spin_lock_irqsave(&hp->port.lock, flags);
37899 /* Check and then increment for fast path open. */
37900- if (hp->port.count++ > 0) {
37901+ if (atomic_inc_return(&hp->port.count) > 1) {
37902 spin_unlock_irqrestore(&hp->port.lock, flags);
37903 hvc_kick();
37904 return 0;
37905@@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37906
37907 spin_lock_irqsave(&hp->port.lock, flags);
37908
37909- if (--hp->port.count == 0) {
37910+ if (atomic_dec_return(&hp->port.count) == 0) {
37911 spin_unlock_irqrestore(&hp->port.lock, flags);
37912 /* We are done with the tty pointer now. */
37913 tty_port_tty_set(&hp->port, NULL);
37914@@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37915 */
37916 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37917 } else {
37918- if (hp->port.count < 0)
37919+ if (atomic_read(&hp->port.count) < 0)
37920 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37921- hp->vtermno, hp->port.count);
37922+ hp->vtermno, atomic_read(&hp->port.count));
37923 spin_unlock_irqrestore(&hp->port.lock, flags);
37924 }
37925
37926@@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37927 * open->hangup case this can be called after the final close so prevent
37928 * that from happening for now.
37929 */
37930- if (hp->port.count <= 0) {
37931+ if (atomic_read(&hp->port.count) <= 0) {
37932 spin_unlock_irqrestore(&hp->port.lock, flags);
37933 return;
37934 }
37935
37936- temp_open_count = hp->port.count;
37937- hp->port.count = 0;
37938+ temp_open_count = atomic_read(&hp->port.count);
37939+ atomic_set(&hp->port.count, 0);
37940 spin_unlock_irqrestore(&hp->port.lock, flags);
37941 tty_port_tty_set(&hp->port, NULL);
37942
37943@@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37944 return -EPIPE;
37945
37946 /* FIXME what's this (unprotected) check for? */
37947- if (hp->port.count <= 0)
37948+ if (atomic_read(&hp->port.count) <= 0)
37949 return -EIO;
37950
37951 spin_lock_irqsave(&hp->lock, flags);
37952diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37953index d56788c..12d8f85 100644
37954--- a/drivers/tty/hvc/hvcs.c
37955+++ b/drivers/tty/hvc/hvcs.c
37956@@ -83,6 +83,7 @@
37957 #include <asm/hvcserver.h>
37958 #include <asm/uaccess.h>
37959 #include <asm/vio.h>
37960+#include <asm/local.h>
37961
37962 /*
37963 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37964@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37965
37966 spin_lock_irqsave(&hvcsd->lock, flags);
37967
37968- if (hvcsd->port.count > 0) {
37969+ if (atomic_read(&hvcsd->port.count) > 0) {
37970 spin_unlock_irqrestore(&hvcsd->lock, flags);
37971 printk(KERN_INFO "HVCS: vterm state unchanged. "
37972 "The hvcs device node is still in use.\n");
37973@@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37974 if ((retval = hvcs_partner_connect(hvcsd)))
37975 goto error_release;
37976
37977- hvcsd->port.count = 1;
37978+ atomic_set(&hvcsd->port.count, 1);
37979 hvcsd->port.tty = tty;
37980 tty->driver_data = hvcsd;
37981
37982@@ -1168,7 +1169,7 @@ fast_open:
37983
37984 spin_lock_irqsave(&hvcsd->lock, flags);
37985 tty_port_get(&hvcsd->port);
37986- hvcsd->port.count++;
37987+ atomic_inc(&hvcsd->port.count);
37988 hvcsd->todo_mask |= HVCS_SCHED_READ;
37989 spin_unlock_irqrestore(&hvcsd->lock, flags);
37990
37991@@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37992 hvcsd = tty->driver_data;
37993
37994 spin_lock_irqsave(&hvcsd->lock, flags);
37995- if (--hvcsd->port.count == 0) {
37996+ if (atomic_dec_and_test(&hvcsd->port.count)) {
37997
37998 vio_disable_interrupts(hvcsd->vdev);
37999
38000@@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38001 free_irq(irq, hvcsd);
38002 tty_port_put(&hvcsd->port);
38003 return;
38004- } else if (hvcsd->port.count < 0) {
38005+ } else if (atomic_read(&hvcsd->port.count) < 0) {
38006 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38007 " is missmanaged.\n",
38008- hvcsd->vdev->unit_address, hvcsd->port.count);
38009+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38010 }
38011
38012 spin_unlock_irqrestore(&hvcsd->lock, flags);
38013@@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38014
38015 spin_lock_irqsave(&hvcsd->lock, flags);
38016 /* Preserve this so that we know how many kref refs to put */
38017- temp_open_count = hvcsd->port.count;
38018+ temp_open_count = atomic_read(&hvcsd->port.count);
38019
38020 /*
38021 * Don't kref put inside the spinlock because the destruction
38022@@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38023 tty->driver_data = NULL;
38024 hvcsd->port.tty = NULL;
38025
38026- hvcsd->port.count = 0;
38027+ atomic_set(&hvcsd->port.count, 0);
38028
38029 /* This will drop any buffered data on the floor which is OK in a hangup
38030 * scenario. */
38031@@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38032 * the middle of a write operation? This is a crummy place to do this
38033 * but we want to keep it all in the spinlock.
38034 */
38035- if (hvcsd->port.count <= 0) {
38036+ if (atomic_read(&hvcsd->port.count) <= 0) {
38037 spin_unlock_irqrestore(&hvcsd->lock, flags);
38038 return -ENODEV;
38039 }
38040@@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38041 {
38042 struct hvcs_struct *hvcsd = tty->driver_data;
38043
38044- if (!hvcsd || hvcsd->port.count <= 0)
38045+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38046 return 0;
38047
38048 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38049diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38050index f8b5fa0..4ba9f89 100644
38051--- a/drivers/tty/ipwireless/tty.c
38052+++ b/drivers/tty/ipwireless/tty.c
38053@@ -29,6 +29,7 @@
38054 #include <linux/tty_driver.h>
38055 #include <linux/tty_flip.h>
38056 #include <linux/uaccess.h>
38057+#include <asm/local.h>
38058
38059 #include "tty.h"
38060 #include "network.h"
38061@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38062 mutex_unlock(&tty->ipw_tty_mutex);
38063 return -ENODEV;
38064 }
38065- if (tty->port.count == 0)
38066+ if (atomic_read(&tty->port.count) == 0)
38067 tty->tx_bytes_queued = 0;
38068
38069- tty->port.count++;
38070+ atomic_inc(&tty->port.count);
38071
38072 tty->port.tty = linux_tty;
38073 linux_tty->driver_data = tty;
38074@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38075
38076 static void do_ipw_close(struct ipw_tty *tty)
38077 {
38078- tty->port.count--;
38079-
38080- if (tty->port.count == 0) {
38081+ if (atomic_dec_return(&tty->port.count) == 0) {
38082 struct tty_struct *linux_tty = tty->port.tty;
38083
38084 if (linux_tty != NULL) {
38085@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38086 return;
38087
38088 mutex_lock(&tty->ipw_tty_mutex);
38089- if (tty->port.count == 0) {
38090+ if (atomic_read(&tty->port.count) == 0) {
38091 mutex_unlock(&tty->ipw_tty_mutex);
38092 return;
38093 }
38094@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38095 return;
38096 }
38097
38098- if (!tty->port.count) {
38099+ if (!atomic_read(&tty->port.count)) {
38100 mutex_unlock(&tty->ipw_tty_mutex);
38101 return;
38102 }
38103@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38104 return -ENODEV;
38105
38106 mutex_lock(&tty->ipw_tty_mutex);
38107- if (!tty->port.count) {
38108+ if (!atomic_read(&tty->port.count)) {
38109 mutex_unlock(&tty->ipw_tty_mutex);
38110 return -EINVAL;
38111 }
38112@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38113 if (!tty)
38114 return -ENODEV;
38115
38116- if (!tty->port.count)
38117+ if (!atomic_read(&tty->port.count))
38118 return -EINVAL;
38119
38120 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38121@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38122 if (!tty)
38123 return 0;
38124
38125- if (!tty->port.count)
38126+ if (!atomic_read(&tty->port.count))
38127 return 0;
38128
38129 return tty->tx_bytes_queued;
38130@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38131 if (!tty)
38132 return -ENODEV;
38133
38134- if (!tty->port.count)
38135+ if (!atomic_read(&tty->port.count))
38136 return -EINVAL;
38137
38138 return get_control_lines(tty);
38139@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38140 if (!tty)
38141 return -ENODEV;
38142
38143- if (!tty->port.count)
38144+ if (!atomic_read(&tty->port.count))
38145 return -EINVAL;
38146
38147 return set_control_lines(tty, set, clear);
38148@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38149 if (!tty)
38150 return -ENODEV;
38151
38152- if (!tty->port.count)
38153+ if (!atomic_read(&tty->port.count))
38154 return -EINVAL;
38155
38156 /* FIXME: Exactly how is the tty object locked here .. */
38157@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38158 * are gone */
38159 mutex_lock(&ttyj->ipw_tty_mutex);
38160 }
38161- while (ttyj->port.count)
38162+ while (atomic_read(&ttyj->port.count))
38163 do_ipw_close(ttyj);
38164 ipwireless_disassociate_network_ttys(network,
38165 ttyj->channel_idx);
38166diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38167index 324467d..504cc25 100644
38168--- a/drivers/tty/moxa.c
38169+++ b/drivers/tty/moxa.c
38170@@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38171 }
38172
38173 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38174- ch->port.count++;
38175+ atomic_inc(&ch->port.count);
38176 tty->driver_data = ch;
38177 tty_port_tty_set(&ch->port, tty);
38178 mutex_lock(&ch->port.mutex);
38179diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38180index 90dff82..08119c3 100644
38181--- a/drivers/tty/n_gsm.c
38182+++ b/drivers/tty/n_gsm.c
38183@@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38184 kref_init(&dlci->ref);
38185 mutex_init(&dlci->mutex);
38186 dlci->fifo = &dlci->_fifo;
38187- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38188+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38189 kfree(dlci);
38190 return NULL;
38191 }
38192@@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38193 if (dlci == NULL)
38194 return -ENOMEM;
38195 port = &dlci->port;
38196- port->count++;
38197+ atomic_inc(&port->count);
38198 tty->driver_data = dlci;
38199 dlci_get(dlci);
38200 dlci_get(dlci->gsm->dlci[0]);
38201diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38202index 26f0d0e..b7c4273 100644
38203--- a/drivers/tty/n_tty.c
38204+++ b/drivers/tty/n_tty.c
38205@@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38206 {
38207 *ops = tty_ldisc_N_TTY;
38208 ops->owner = NULL;
38209- ops->refcount = ops->flags = 0;
38210+ atomic_set(&ops->refcount, 0);
38211+ ops->flags = 0;
38212 }
38213 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38214diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38215index 5505ffc..7affff9 100644
38216--- a/drivers/tty/pty.c
38217+++ b/drivers/tty/pty.c
38218@@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38219 panic("Couldn't register Unix98 pts driver");
38220
38221 /* Now create the /dev/ptmx special device */
38222+ pax_open_kernel();
38223 tty_default_fops(&ptmx_fops);
38224- ptmx_fops.open = ptmx_open;
38225+ *(void **)&ptmx_fops.open = ptmx_open;
38226+ pax_close_kernel();
38227
38228 cdev_init(&ptmx_cdev, &ptmx_fops);
38229 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38230diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38231index 777d5f9..56d67ca 100644
38232--- a/drivers/tty/rocket.c
38233+++ b/drivers/tty/rocket.c
38234@@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38235 tty->driver_data = info;
38236 tty_port_tty_set(port, tty);
38237
38238- if (port->count++ == 0) {
38239+ if (atomic_inc_return(&port->count) == 1) {
38240 atomic_inc(&rp_num_ports_open);
38241
38242 #ifdef ROCKET_DEBUG_OPEN
38243@@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38244 #endif
38245 }
38246 #ifdef ROCKET_DEBUG_OPEN
38247- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38248+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38249 #endif
38250
38251 /*
38252@@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38253 spin_unlock_irqrestore(&info->port.lock, flags);
38254 return;
38255 }
38256- if (info->port.count)
38257+ if (atomic_read(&info->port.count))
38258 atomic_dec(&rp_num_ports_open);
38259 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38260 spin_unlock_irqrestore(&info->port.lock, flags);
38261diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38262index 2b42a01..32a2ed3 100644
38263--- a/drivers/tty/serial/kgdboc.c
38264+++ b/drivers/tty/serial/kgdboc.c
38265@@ -24,8 +24,9 @@
38266 #define MAX_CONFIG_LEN 40
38267
38268 static struct kgdb_io kgdboc_io_ops;
38269+static struct kgdb_io kgdboc_io_ops_console;
38270
38271-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38272+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38273 static int configured = -1;
38274
38275 static char config[MAX_CONFIG_LEN];
38276@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38277 kgdboc_unregister_kbd();
38278 if (configured == 1)
38279 kgdb_unregister_io_module(&kgdboc_io_ops);
38280+ else if (configured == 2)
38281+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
38282 }
38283
38284 static int configure_kgdboc(void)
38285@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38286 int err;
38287 char *cptr = config;
38288 struct console *cons;
38289+ int is_console = 0;
38290
38291 err = kgdboc_option_setup(config);
38292 if (err || !strlen(config) || isspace(config[0]))
38293 goto noconfig;
38294
38295 err = -ENODEV;
38296- kgdboc_io_ops.is_console = 0;
38297 kgdb_tty_driver = NULL;
38298
38299 kgdboc_use_kms = 0;
38300@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38301 int idx;
38302 if (cons->device && cons->device(cons, &idx) == p &&
38303 idx == tty_line) {
38304- kgdboc_io_ops.is_console = 1;
38305+ is_console = 1;
38306 break;
38307 }
38308 cons = cons->next;
38309@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38310 kgdb_tty_line = tty_line;
38311
38312 do_register:
38313- err = kgdb_register_io_module(&kgdboc_io_ops);
38314+ if (is_console) {
38315+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
38316+ configured = 2;
38317+ } else {
38318+ err = kgdb_register_io_module(&kgdboc_io_ops);
38319+ configured = 1;
38320+ }
38321 if (err)
38322 goto noconfig;
38323
38324- configured = 1;
38325-
38326 return 0;
38327
38328 noconfig:
38329@@ -213,7 +220,7 @@ noconfig:
38330 static int __init init_kgdboc(void)
38331 {
38332 /* Already configured? */
38333- if (configured == 1)
38334+ if (configured >= 1)
38335 return 0;
38336
38337 return configure_kgdboc();
38338@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38339 if (config[len - 1] == '\n')
38340 config[len - 1] = '\0';
38341
38342- if (configured == 1)
38343+ if (configured >= 1)
38344 cleanup_kgdboc();
38345
38346 /* Go and configure with the new params. */
38347@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38348 .post_exception = kgdboc_post_exp_handler,
38349 };
38350
38351+static struct kgdb_io kgdboc_io_ops_console = {
38352+ .name = "kgdboc",
38353+ .read_char = kgdboc_get_char,
38354+ .write_char = kgdboc_put_char,
38355+ .pre_exception = kgdboc_pre_exp_handler,
38356+ .post_exception = kgdboc_post_exp_handler,
38357+ .is_console = 1
38358+};
38359+
38360 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38361 /* This is only available if kgdboc is a built in for early debugging */
38362 static int __init kgdboc_early_init(char *opt)
38363diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38364index a21dc8e..fe43e9e 100644
38365--- a/drivers/tty/serial/serial_core.c
38366+++ b/drivers/tty/serial/serial_core.c
38367@@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38368 uart_flush_buffer(tty);
38369 uart_shutdown(tty, state);
38370 spin_lock_irqsave(&port->lock, flags);
38371- port->count = 0;
38372+ atomic_set(&port->count, 0);
38373 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38374 spin_unlock_irqrestore(&port->lock, flags);
38375 tty_port_tty_set(port, NULL);
38376@@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38377 goto end;
38378 }
38379
38380- port->count++;
38381+ atomic_inc(&port->count);
38382 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38383 retval = -ENXIO;
38384 goto err_dec_count;
38385@@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38386 /*
38387 * Make sure the device is in D0 state.
38388 */
38389- if (port->count == 1)
38390+ if (atomic_read(&port->count) == 1)
38391 uart_change_pm(state, 0);
38392
38393 /*
38394@@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38395 end:
38396 return retval;
38397 err_dec_count:
38398- port->count--;
38399+ atomic_inc(&port->count);
38400 mutex_unlock(&port->mutex);
38401 goto end;
38402 }
38403diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38404index 593d40a..bdc61f3 100644
38405--- a/drivers/tty/synclink.c
38406+++ b/drivers/tty/synclink.c
38407@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38408
38409 if (debug_level >= DEBUG_LEVEL_INFO)
38410 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38411- __FILE__,__LINE__, info->device_name, info->port.count);
38412+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38413
38414 if (tty_port_close_start(&info->port, tty, filp) == 0)
38415 goto cleanup;
38416@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38417 cleanup:
38418 if (debug_level >= DEBUG_LEVEL_INFO)
38419 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38420- tty->driver->name, info->port.count);
38421+ tty->driver->name, atomic_read(&info->port.count));
38422
38423 } /* end of mgsl_close() */
38424
38425@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38426
38427 mgsl_flush_buffer(tty);
38428 shutdown(info);
38429-
38430- info->port.count = 0;
38431+
38432+ atomic_set(&info->port.count, 0);
38433 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38434 info->port.tty = NULL;
38435
38436@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38437
38438 if (debug_level >= DEBUG_LEVEL_INFO)
38439 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38440- __FILE__,__LINE__, tty->driver->name, port->count );
38441+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38442
38443 spin_lock_irqsave(&info->irq_spinlock, flags);
38444 if (!tty_hung_up_p(filp)) {
38445 extra_count = true;
38446- port->count--;
38447+ atomic_dec(&port->count);
38448 }
38449 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38450 port->blocked_open++;
38451@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38452
38453 if (debug_level >= DEBUG_LEVEL_INFO)
38454 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38455- __FILE__,__LINE__, tty->driver->name, port->count );
38456+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38457
38458 tty_unlock();
38459 schedule();
38460@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38461
38462 /* FIXME: Racy on hangup during close wait */
38463 if (extra_count)
38464- port->count++;
38465+ atomic_inc(&port->count);
38466 port->blocked_open--;
38467
38468 if (debug_level >= DEBUG_LEVEL_INFO)
38469 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38470- __FILE__,__LINE__, tty->driver->name, port->count );
38471+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38472
38473 if (!retval)
38474 port->flags |= ASYNC_NORMAL_ACTIVE;
38475@@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38476
38477 if (debug_level >= DEBUG_LEVEL_INFO)
38478 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38479- __FILE__,__LINE__,tty->driver->name, info->port.count);
38480+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38481
38482 /* If port is closing, signal caller to try again */
38483 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38484@@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38485 spin_unlock_irqrestore(&info->netlock, flags);
38486 goto cleanup;
38487 }
38488- info->port.count++;
38489+ atomic_inc(&info->port.count);
38490 spin_unlock_irqrestore(&info->netlock, flags);
38491
38492- if (info->port.count == 1) {
38493+ if (atomic_read(&info->port.count) == 1) {
38494 /* 1st open on this device, init hardware */
38495 retval = startup(info);
38496 if (retval < 0)
38497@@ -3444,8 +3444,8 @@ cleanup:
38498 if (retval) {
38499 if (tty->count == 1)
38500 info->port.tty = NULL; /* tty layer will release tty struct */
38501- if(info->port.count)
38502- info->port.count--;
38503+ if (atomic_read(&info->port.count))
38504+ atomic_dec(&info->port.count);
38505 }
38506
38507 return retval;
38508@@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38509 unsigned short new_crctype;
38510
38511 /* return error if TTY interface open */
38512- if (info->port.count)
38513+ if (atomic_read(&info->port.count))
38514 return -EBUSY;
38515
38516 switch (encoding)
38517@@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38518
38519 /* arbitrate between network and tty opens */
38520 spin_lock_irqsave(&info->netlock, flags);
38521- if (info->port.count != 0 || info->netcount != 0) {
38522+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38523 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38524 spin_unlock_irqrestore(&info->netlock, flags);
38525 return -EBUSY;
38526@@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38527 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38528
38529 /* return error if TTY interface open */
38530- if (info->port.count)
38531+ if (atomic_read(&info->port.count))
38532 return -EBUSY;
38533
38534 if (cmd != SIOCWANDEV)
38535diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38536index aa1debf..9297a16 100644
38537--- a/drivers/tty/synclink_gt.c
38538+++ b/drivers/tty/synclink_gt.c
38539@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38540 tty->driver_data = info;
38541 info->port.tty = tty;
38542
38543- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38544+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38545
38546 /* If port is closing, signal caller to try again */
38547 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38548@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38549 mutex_unlock(&info->port.mutex);
38550 goto cleanup;
38551 }
38552- info->port.count++;
38553+ atomic_inc(&info->port.count);
38554 spin_unlock_irqrestore(&info->netlock, flags);
38555
38556- if (info->port.count == 1) {
38557+ if (atomic_read(&info->port.count) == 1) {
38558 /* 1st open on this device, init hardware */
38559 retval = startup(info);
38560 if (retval < 0) {
38561@@ -716,8 +716,8 @@ cleanup:
38562 if (retval) {
38563 if (tty->count == 1)
38564 info->port.tty = NULL; /* tty layer will release tty struct */
38565- if(info->port.count)
38566- info->port.count--;
38567+ if(atomic_read(&info->port.count))
38568+ atomic_dec(&info->port.count);
38569 }
38570
38571 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38572@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38573
38574 if (sanity_check(info, tty->name, "close"))
38575 return;
38576- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38577+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38578
38579 if (tty_port_close_start(&info->port, tty, filp) == 0)
38580 goto cleanup;
38581@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38582 tty_port_close_end(&info->port, tty);
38583 info->port.tty = NULL;
38584 cleanup:
38585- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38586+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38587 }
38588
38589 static void hangup(struct tty_struct *tty)
38590@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38591 shutdown(info);
38592
38593 spin_lock_irqsave(&info->port.lock, flags);
38594- info->port.count = 0;
38595+ atomic_set(&info->port.count, 0);
38596 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38597 info->port.tty = NULL;
38598 spin_unlock_irqrestore(&info->port.lock, flags);
38599@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38600 unsigned short new_crctype;
38601
38602 /* return error if TTY interface open */
38603- if (info->port.count)
38604+ if (atomic_read(&info->port.count))
38605 return -EBUSY;
38606
38607 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38608@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38609
38610 /* arbitrate between network and tty opens */
38611 spin_lock_irqsave(&info->netlock, flags);
38612- if (info->port.count != 0 || info->netcount != 0) {
38613+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38614 DBGINFO(("%s hdlc_open busy\n", dev->name));
38615 spin_unlock_irqrestore(&info->netlock, flags);
38616 return -EBUSY;
38617@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38618 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38619
38620 /* return error if TTY interface open */
38621- if (info->port.count)
38622+ if (atomic_read(&info->port.count))
38623 return -EBUSY;
38624
38625 if (cmd != SIOCWANDEV)
38626@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38627 if (port == NULL)
38628 continue;
38629 spin_lock(&port->lock);
38630- if ((port->port.count || port->netcount) &&
38631+ if ((atomic_read(&port->port.count) || port->netcount) &&
38632 port->pending_bh && !port->bh_running &&
38633 !port->bh_requested) {
38634 DBGISR(("%s bh queued\n", port->device_name));
38635@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38636 spin_lock_irqsave(&info->lock, flags);
38637 if (!tty_hung_up_p(filp)) {
38638 extra_count = true;
38639- port->count--;
38640+ atomic_dec(&port->count);
38641 }
38642 spin_unlock_irqrestore(&info->lock, flags);
38643 port->blocked_open++;
38644@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38645 remove_wait_queue(&port->open_wait, &wait);
38646
38647 if (extra_count)
38648- port->count++;
38649+ atomic_inc(&port->count);
38650 port->blocked_open--;
38651
38652 if (!retval)
38653diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38654index a3dddc1..8905ab2 100644
38655--- a/drivers/tty/synclinkmp.c
38656+++ b/drivers/tty/synclinkmp.c
38657@@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38658
38659 if (debug_level >= DEBUG_LEVEL_INFO)
38660 printk("%s(%d):%s open(), old ref count = %d\n",
38661- __FILE__,__LINE__,tty->driver->name, info->port.count);
38662+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38663
38664 /* If port is closing, signal caller to try again */
38665 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38666@@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38667 spin_unlock_irqrestore(&info->netlock, flags);
38668 goto cleanup;
38669 }
38670- info->port.count++;
38671+ atomic_inc(&info->port.count);
38672 spin_unlock_irqrestore(&info->netlock, flags);
38673
38674- if (info->port.count == 1) {
38675+ if (atomic_read(&info->port.count) == 1) {
38676 /* 1st open on this device, init hardware */
38677 retval = startup(info);
38678 if (retval < 0)
38679@@ -788,8 +788,8 @@ cleanup:
38680 if (retval) {
38681 if (tty->count == 1)
38682 info->port.tty = NULL; /* tty layer will release tty struct */
38683- if(info->port.count)
38684- info->port.count--;
38685+ if(atomic_read(&info->port.count))
38686+ atomic_dec(&info->port.count);
38687 }
38688
38689 return retval;
38690@@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38691
38692 if (debug_level >= DEBUG_LEVEL_INFO)
38693 printk("%s(%d):%s close() entry, count=%d\n",
38694- __FILE__,__LINE__, info->device_name, info->port.count);
38695+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38696
38697 if (tty_port_close_start(&info->port, tty, filp) == 0)
38698 goto cleanup;
38699@@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38700 cleanup:
38701 if (debug_level >= DEBUG_LEVEL_INFO)
38702 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38703- tty->driver->name, info->port.count);
38704+ tty->driver->name, atomic_read(&info->port.count));
38705 }
38706
38707 /* Called by tty_hangup() when a hangup is signaled.
38708@@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38709 shutdown(info);
38710
38711 spin_lock_irqsave(&info->port.lock, flags);
38712- info->port.count = 0;
38713+ atomic_set(&info->port.count, 0);
38714 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38715 info->port.tty = NULL;
38716 spin_unlock_irqrestore(&info->port.lock, flags);
38717@@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38718 unsigned short new_crctype;
38719
38720 /* return error if TTY interface open */
38721- if (info->port.count)
38722+ if (atomic_read(&info->port.count))
38723 return -EBUSY;
38724
38725 switch (encoding)
38726@@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38727
38728 /* arbitrate between network and tty opens */
38729 spin_lock_irqsave(&info->netlock, flags);
38730- if (info->port.count != 0 || info->netcount != 0) {
38731+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38732 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38733 spin_unlock_irqrestore(&info->netlock, flags);
38734 return -EBUSY;
38735@@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38736 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38737
38738 /* return error if TTY interface open */
38739- if (info->port.count)
38740+ if (atomic_read(&info->port.count))
38741 return -EBUSY;
38742
38743 if (cmd != SIOCWANDEV)
38744@@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38745 * do not request bottom half processing if the
38746 * device is not open in a normal mode.
38747 */
38748- if ( port && (port->port.count || port->netcount) &&
38749+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38750 port->pending_bh && !port->bh_running &&
38751 !port->bh_requested ) {
38752 if ( debug_level >= DEBUG_LEVEL_ISR )
38753@@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38754
38755 if (debug_level >= DEBUG_LEVEL_INFO)
38756 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38757- __FILE__,__LINE__, tty->driver->name, port->count );
38758+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38759
38760 spin_lock_irqsave(&info->lock, flags);
38761 if (!tty_hung_up_p(filp)) {
38762 extra_count = true;
38763- port->count--;
38764+ atomic_dec(&port->count);
38765 }
38766 spin_unlock_irqrestore(&info->lock, flags);
38767 port->blocked_open++;
38768@@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38769
38770 if (debug_level >= DEBUG_LEVEL_INFO)
38771 printk("%s(%d):%s block_til_ready() count=%d\n",
38772- __FILE__,__LINE__, tty->driver->name, port->count );
38773+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38774
38775 tty_unlock();
38776 schedule();
38777@@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38778 remove_wait_queue(&port->open_wait, &wait);
38779
38780 if (extra_count)
38781- port->count++;
38782+ atomic_inc(&port->count);
38783 port->blocked_open--;
38784
38785 if (debug_level >= DEBUG_LEVEL_INFO)
38786 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38787- __FILE__,__LINE__, tty->driver->name, port->count );
38788+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38789
38790 if (!retval)
38791 port->flags |= ASYNC_NORMAL_ACTIVE;
38792diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38793index 05728894..b9d44c6 100644
38794--- a/drivers/tty/sysrq.c
38795+++ b/drivers/tty/sysrq.c
38796@@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38797 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38798 size_t count, loff_t *ppos)
38799 {
38800- if (count) {
38801+ if (count && capable(CAP_SYS_ADMIN)) {
38802 char c;
38803
38804 if (get_user(c, buf))
38805diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38806index b425c79..08a3f06 100644
38807--- a/drivers/tty/tty_io.c
38808+++ b/drivers/tty/tty_io.c
38809@@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38810
38811 void tty_default_fops(struct file_operations *fops)
38812 {
38813- *fops = tty_fops;
38814+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38815 }
38816
38817 /*
38818diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38819index 6f99c99..8947bc4 100644
38820--- a/drivers/tty/tty_ldisc.c
38821+++ b/drivers/tty/tty_ldisc.c
38822@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38823 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38824 struct tty_ldisc_ops *ldo = ld->ops;
38825
38826- ldo->refcount--;
38827+ atomic_dec(&ldo->refcount);
38828 module_put(ldo->owner);
38829 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38830
38831@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38832 spin_lock_irqsave(&tty_ldisc_lock, flags);
38833 tty_ldiscs[disc] = new_ldisc;
38834 new_ldisc->num = disc;
38835- new_ldisc->refcount = 0;
38836+ atomic_set(&new_ldisc->refcount, 0);
38837 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38838
38839 return ret;
38840@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38841 return -EINVAL;
38842
38843 spin_lock_irqsave(&tty_ldisc_lock, flags);
38844- if (tty_ldiscs[disc]->refcount)
38845+ if (atomic_read(&tty_ldiscs[disc]->refcount))
38846 ret = -EBUSY;
38847 else
38848 tty_ldiscs[disc] = NULL;
38849@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38850 if (ldops) {
38851 ret = ERR_PTR(-EAGAIN);
38852 if (try_module_get(ldops->owner)) {
38853- ldops->refcount++;
38854+ atomic_inc(&ldops->refcount);
38855 ret = ldops;
38856 }
38857 }
38858@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38859 unsigned long flags;
38860
38861 spin_lock_irqsave(&tty_ldisc_lock, flags);
38862- ldops->refcount--;
38863+ atomic_dec(&ldops->refcount);
38864 module_put(ldops->owner);
38865 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38866 }
38867diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38868index bf6e238..d401c04 100644
38869--- a/drivers/tty/tty_port.c
38870+++ b/drivers/tty/tty_port.c
38871@@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38872 unsigned long flags;
38873
38874 spin_lock_irqsave(&port->lock, flags);
38875- port->count = 0;
38876+ atomic_set(&port->count, 0);
38877 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38878 if (port->tty) {
38879 set_bit(TTY_IO_ERROR, &port->tty->flags);
38880@@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38881 /* The port lock protects the port counts */
38882 spin_lock_irqsave(&port->lock, flags);
38883 if (!tty_hung_up_p(filp))
38884- port->count--;
38885+ atomic_dec(&port->count);
38886 port->blocked_open++;
38887 spin_unlock_irqrestore(&port->lock, flags);
38888
38889@@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38890 we must not mess that up further */
38891 spin_lock_irqsave(&port->lock, flags);
38892 if (!tty_hung_up_p(filp))
38893- port->count++;
38894+ atomic_inc(&port->count);
38895 port->blocked_open--;
38896 if (retval == 0)
38897 port->flags |= ASYNC_NORMAL_ACTIVE;
38898@@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38899 return 0;
38900 }
38901
38902- if (tty->count == 1 && port->count != 1) {
38903+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
38904 printk(KERN_WARNING
38905 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38906- port->count);
38907- port->count = 1;
38908+ atomic_read(&port->count));
38909+ atomic_set(&port->count, 1);
38910 }
38911- if (--port->count < 0) {
38912+ if (atomic_dec_return(&port->count) < 0) {
38913 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38914- port->count);
38915- port->count = 0;
38916+ atomic_read(&port->count));
38917+ atomic_set(&port->count, 0);
38918 }
38919
38920- if (port->count) {
38921+ if (atomic_read(&port->count)) {
38922 spin_unlock_irqrestore(&port->lock, flags);
38923 if (port->ops->drop)
38924 port->ops->drop(port);
38925@@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38926 {
38927 spin_lock_irq(&port->lock);
38928 if (!tty_hung_up_p(filp))
38929- ++port->count;
38930+ atomic_inc(&port->count);
38931 spin_unlock_irq(&port->lock);
38932 tty_port_tty_set(port, tty);
38933
38934diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38935index 770a854..e5d3db3 100644
38936--- a/drivers/tty/vt/keyboard.c
38937+++ b/drivers/tty/vt/keyboard.c
38938@@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38939 kbd->kbdmode == VC_OFF) &&
38940 value != KVAL(K_SAK))
38941 return; /* SAK is allowed even in raw mode */
38942+
38943+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38944+ {
38945+ void *func = fn_handler[value];
38946+ if (func == fn_show_state || func == fn_show_ptregs ||
38947+ func == fn_show_mem)
38948+ return;
38949+ }
38950+#endif
38951+
38952 fn_handler[value](vc);
38953 }
38954
38955@@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38956 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38957 return -EFAULT;
38958
38959- if (!capable(CAP_SYS_TTY_CONFIG))
38960- perm = 0;
38961-
38962 switch (cmd) {
38963 case KDGKBENT:
38964 /* Ensure another thread doesn't free it under us */
38965@@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38966 spin_unlock_irqrestore(&kbd_event_lock, flags);
38967 return put_user(val, &user_kbe->kb_value);
38968 case KDSKBENT:
38969+ if (!capable(CAP_SYS_TTY_CONFIG))
38970+ perm = 0;
38971+
38972 if (!perm)
38973 return -EPERM;
38974 if (!i && v == K_NOSUCHMAP) {
38975@@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38976 int i, j, k;
38977 int ret;
38978
38979- if (!capable(CAP_SYS_TTY_CONFIG))
38980- perm = 0;
38981-
38982 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38983 if (!kbs) {
38984 ret = -ENOMEM;
38985@@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38986 kfree(kbs);
38987 return ((p && *p) ? -EOVERFLOW : 0);
38988 case KDSKBSENT:
38989+ if (!capable(CAP_SYS_TTY_CONFIG))
38990+ perm = 0;
38991+
38992 if (!perm) {
38993 ret = -EPERM;
38994 goto reterr;
38995diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38996index a783d53..cb30d94 100644
38997--- a/drivers/uio/uio.c
38998+++ b/drivers/uio/uio.c
38999@@ -25,6 +25,7 @@
39000 #include <linux/kobject.h>
39001 #include <linux/cdev.h>
39002 #include <linux/uio_driver.h>
39003+#include <asm/local.h>
39004
39005 #define UIO_MAX_DEVICES (1U << MINORBITS)
39006
39007@@ -32,10 +33,10 @@ struct uio_device {
39008 struct module *owner;
39009 struct device *dev;
39010 int minor;
39011- atomic_t event;
39012+ atomic_unchecked_t event;
39013 struct fasync_struct *async_queue;
39014 wait_queue_head_t wait;
39015- int vma_count;
39016+ local_t vma_count;
39017 struct uio_info *info;
39018 struct kobject *map_dir;
39019 struct kobject *portio_dir;
39020@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39021 struct device_attribute *attr, char *buf)
39022 {
39023 struct uio_device *idev = dev_get_drvdata(dev);
39024- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39025+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39026 }
39027
39028 static struct device_attribute uio_class_attributes[] = {
39029@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39030 {
39031 struct uio_device *idev = info->uio_dev;
39032
39033- atomic_inc(&idev->event);
39034+ atomic_inc_unchecked(&idev->event);
39035 wake_up_interruptible(&idev->wait);
39036 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39037 }
39038@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39039 }
39040
39041 listener->dev = idev;
39042- listener->event_count = atomic_read(&idev->event);
39043+ listener->event_count = atomic_read_unchecked(&idev->event);
39044 filep->private_data = listener;
39045
39046 if (idev->info->open) {
39047@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39048 return -EIO;
39049
39050 poll_wait(filep, &idev->wait, wait);
39051- if (listener->event_count != atomic_read(&idev->event))
39052+ if (listener->event_count != atomic_read_unchecked(&idev->event))
39053 return POLLIN | POLLRDNORM;
39054 return 0;
39055 }
39056@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39057 do {
39058 set_current_state(TASK_INTERRUPTIBLE);
39059
39060- event_count = atomic_read(&idev->event);
39061+ event_count = atomic_read_unchecked(&idev->event);
39062 if (event_count != listener->event_count) {
39063 if (copy_to_user(buf, &event_count, count))
39064 retval = -EFAULT;
39065@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39066 static void uio_vma_open(struct vm_area_struct *vma)
39067 {
39068 struct uio_device *idev = vma->vm_private_data;
39069- idev->vma_count++;
39070+ local_inc(&idev->vma_count);
39071 }
39072
39073 static void uio_vma_close(struct vm_area_struct *vma)
39074 {
39075 struct uio_device *idev = vma->vm_private_data;
39076- idev->vma_count--;
39077+ local_dec(&idev->vma_count);
39078 }
39079
39080 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39081@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39082 idev->owner = owner;
39083 idev->info = info;
39084 init_waitqueue_head(&idev->wait);
39085- atomic_set(&idev->event, 0);
39086+ atomic_set_unchecked(&idev->event, 0);
39087
39088 ret = uio_get_minor(idev);
39089 if (ret)
39090diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39091index b7eb86a..36d28af 100644
39092--- a/drivers/usb/atm/cxacru.c
39093+++ b/drivers/usb/atm/cxacru.c
39094@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39095 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39096 if (ret < 2)
39097 return -EINVAL;
39098- if (index < 0 || index > 0x7f)
39099+ if (index > 0x7f)
39100 return -EINVAL;
39101 pos += tmp;
39102
39103diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39104index ee62b35..b663594 100644
39105--- a/drivers/usb/atm/usbatm.c
39106+++ b/drivers/usb/atm/usbatm.c
39107@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39108 if (printk_ratelimit())
39109 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39110 __func__, vpi, vci);
39111- atomic_inc(&vcc->stats->rx_err);
39112+ atomic_inc_unchecked(&vcc->stats->rx_err);
39113 return;
39114 }
39115
39116@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39117 if (length > ATM_MAX_AAL5_PDU) {
39118 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39119 __func__, length, vcc);
39120- atomic_inc(&vcc->stats->rx_err);
39121+ atomic_inc_unchecked(&vcc->stats->rx_err);
39122 goto out;
39123 }
39124
39125@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39126 if (sarb->len < pdu_length) {
39127 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39128 __func__, pdu_length, sarb->len, vcc);
39129- atomic_inc(&vcc->stats->rx_err);
39130+ atomic_inc_unchecked(&vcc->stats->rx_err);
39131 goto out;
39132 }
39133
39134 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39135 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39136 __func__, vcc);
39137- atomic_inc(&vcc->stats->rx_err);
39138+ atomic_inc_unchecked(&vcc->stats->rx_err);
39139 goto out;
39140 }
39141
39142@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39143 if (printk_ratelimit())
39144 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39145 __func__, length);
39146- atomic_inc(&vcc->stats->rx_drop);
39147+ atomic_inc_unchecked(&vcc->stats->rx_drop);
39148 goto out;
39149 }
39150
39151@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39152
39153 vcc->push(vcc, skb);
39154
39155- atomic_inc(&vcc->stats->rx);
39156+ atomic_inc_unchecked(&vcc->stats->rx);
39157 out:
39158 skb_trim(sarb, 0);
39159 }
39160@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39161 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39162
39163 usbatm_pop(vcc, skb);
39164- atomic_inc(&vcc->stats->tx);
39165+ atomic_inc_unchecked(&vcc->stats->tx);
39166
39167 skb = skb_dequeue(&instance->sndqueue);
39168 }
39169@@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39170 if (!left--)
39171 return sprintf(page,
39172 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39173- atomic_read(&atm_dev->stats.aal5.tx),
39174- atomic_read(&atm_dev->stats.aal5.tx_err),
39175- atomic_read(&atm_dev->stats.aal5.rx),
39176- atomic_read(&atm_dev->stats.aal5.rx_err),
39177- atomic_read(&atm_dev->stats.aal5.rx_drop));
39178+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39179+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39180+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39181+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39182+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39183
39184 if (!left--) {
39185 if (instance->disconnected)
39186diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39187index 3440812..2a4ef1f 100644
39188--- a/drivers/usb/core/devices.c
39189+++ b/drivers/usb/core/devices.c
39190@@ -126,7 +126,7 @@ static const char format_endpt[] =
39191 * time it gets called.
39192 */
39193 static struct device_connect_event {
39194- atomic_t count;
39195+ atomic_unchecked_t count;
39196 wait_queue_head_t wait;
39197 } device_event = {
39198 .count = ATOMIC_INIT(1),
39199@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39200
39201 void usbfs_conn_disc_event(void)
39202 {
39203- atomic_add(2, &device_event.count);
39204+ atomic_add_unchecked(2, &device_event.count);
39205 wake_up(&device_event.wait);
39206 }
39207
39208@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39209
39210 poll_wait(file, &device_event.wait, wait);
39211
39212- event_count = atomic_read(&device_event.count);
39213+ event_count = atomic_read_unchecked(&device_event.count);
39214 if (file->f_version != event_count) {
39215 file->f_version = event_count;
39216 return POLLIN | POLLRDNORM;
39217diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39218index 89dcf15..481800b 100644
39219--- a/drivers/usb/early/ehci-dbgp.c
39220+++ b/drivers/usb/early/ehci-dbgp.c
39221@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39222
39223 #ifdef CONFIG_KGDB
39224 static struct kgdb_io kgdbdbgp_io_ops;
39225-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39226+static struct kgdb_io kgdbdbgp_io_ops_console;
39227+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39228 #else
39229 #define dbgp_kgdb_mode (0)
39230 #endif
39231@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39232 .write_char = kgdbdbgp_write_char,
39233 };
39234
39235+static struct kgdb_io kgdbdbgp_io_ops_console = {
39236+ .name = "kgdbdbgp",
39237+ .read_char = kgdbdbgp_read_char,
39238+ .write_char = kgdbdbgp_write_char,
39239+ .is_console = 1
39240+};
39241+
39242 static int kgdbdbgp_wait_time;
39243
39244 static int __init kgdbdbgp_parse_config(char *str)
39245@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39246 ptr++;
39247 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39248 }
39249- kgdb_register_io_module(&kgdbdbgp_io_ops);
39250- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39251+ if (early_dbgp_console.index != -1)
39252+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39253+ else
39254+ kgdb_register_io_module(&kgdbdbgp_io_ops);
39255
39256 return 0;
39257 }
39258diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39259index da6d479..80ed10b 100644
39260--- a/drivers/usb/gadget/u_serial.c
39261+++ b/drivers/usb/gadget/u_serial.c
39262@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39263 spin_lock_irq(&port->port_lock);
39264
39265 /* already open? Great. */
39266- if (port->port.count) {
39267+ if (atomic_read(&port->port.count)) {
39268 status = 0;
39269- port->port.count++;
39270+ atomic_inc(&port->port.count);
39271
39272 /* currently opening/closing? wait ... */
39273 } else if (port->openclose) {
39274@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39275 tty->driver_data = port;
39276 port->port.tty = tty;
39277
39278- port->port.count = 1;
39279+ atomic_set(&port->port.count, 1);
39280 port->openclose = false;
39281
39282 /* if connected, start the I/O stream */
39283@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39284
39285 spin_lock_irq(&port->port_lock);
39286
39287- if (port->port.count != 1) {
39288- if (port->port.count == 0)
39289+ if (atomic_read(&port->port.count) != 1) {
39290+ if (atomic_read(&port->port.count) == 0)
39291 WARN_ON(1);
39292 else
39293- --port->port.count;
39294+ atomic_dec(&port->port.count);
39295 goto exit;
39296 }
39297
39298@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39299 * and sleep if necessary
39300 */
39301 port->openclose = true;
39302- port->port.count = 0;
39303+ atomic_set(&port->port.count, 0);
39304
39305 gser = port->port_usb;
39306 if (gser && gser->disconnect)
39307@@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39308 int cond;
39309
39310 spin_lock_irq(&port->port_lock);
39311- cond = (port->port.count == 0) && !port->openclose;
39312+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39313 spin_unlock_irq(&port->port_lock);
39314 return cond;
39315 }
39316@@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39317 /* if it's already open, start I/O ... and notify the serial
39318 * protocol about open/close status (connect/disconnect).
39319 */
39320- if (port->port.count) {
39321+ if (atomic_read(&port->port.count)) {
39322 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39323 gs_start_io(port);
39324 if (gser->connect)
39325@@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39326
39327 port->port_usb = NULL;
39328 gser->ioport = NULL;
39329- if (port->port.count > 0 || port->openclose) {
39330+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
39331 wake_up_interruptible(&port->drain_wait);
39332 if (port->port.tty)
39333 tty_hangup(port->port.tty);
39334@@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39335
39336 /* finally, free any unused/unusable I/O buffers */
39337 spin_lock_irqsave(&port->port_lock, flags);
39338- if (port->port.count == 0 && !port->openclose)
39339+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
39340 gs_buf_free(&port->port_write_buf);
39341 gs_free_requests(gser->out, &port->read_pool, NULL);
39342 gs_free_requests(gser->out, &port->read_queue, NULL);
39343diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39344index b9cca6d..75c75df 100644
39345--- a/drivers/usb/serial/console.c
39346+++ b/drivers/usb/serial/console.c
39347@@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39348
39349 info->port = port;
39350
39351- ++port->port.count;
39352+ atomic_inc(&port->port.count);
39353 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39354 if (serial->type->set_termios) {
39355 /*
39356@@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39357 }
39358 /* Now that any required fake tty operations are completed restore
39359 * the tty port count */
39360- --port->port.count;
39361+ atomic_dec(&port->port.count);
39362 /* The console is special in terms of closing the device so
39363 * indicate this port is now acting as a system console. */
39364 port->port.console = 1;
39365@@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39366 free_tty:
39367 kfree(tty);
39368 reset_open_count:
39369- port->port.count = 0;
39370+ atomic_set(&port->port.count, 0);
39371 usb_autopm_put_interface(serial->interface);
39372 error_get_interface:
39373 usb_serial_put(serial);
39374diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39375index d6bea3e..60b250e 100644
39376--- a/drivers/usb/wusbcore/wa-hc.h
39377+++ b/drivers/usb/wusbcore/wa-hc.h
39378@@ -192,7 +192,7 @@ struct wahc {
39379 struct list_head xfer_delayed_list;
39380 spinlock_t xfer_list_lock;
39381 struct work_struct xfer_work;
39382- atomic_t xfer_id_count;
39383+ atomic_unchecked_t xfer_id_count;
39384 };
39385
39386
39387@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39388 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39389 spin_lock_init(&wa->xfer_list_lock);
39390 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39391- atomic_set(&wa->xfer_id_count, 1);
39392+ atomic_set_unchecked(&wa->xfer_id_count, 1);
39393 }
39394
39395 /**
39396diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39397index 57c01ab..8a05959 100644
39398--- a/drivers/usb/wusbcore/wa-xfer.c
39399+++ b/drivers/usb/wusbcore/wa-xfer.c
39400@@ -296,7 +296,7 @@ out:
39401 */
39402 static void wa_xfer_id_init(struct wa_xfer *xfer)
39403 {
39404- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39405+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39406 }
39407
39408 /*
39409diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39410index ef82a0d..da8a0b3 100644
39411--- a/drivers/vhost/vhost.c
39412+++ b/drivers/vhost/vhost.c
39413@@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39414 return 0;
39415 }
39416
39417-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39418+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39419 {
39420 struct file *eventfp, *filep = NULL,
39421 *pollstart = NULL, *pollstop = NULL;
39422diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39423index 747442d..7c0c434 100644
39424--- a/drivers/video/aty/aty128fb.c
39425+++ b/drivers/video/aty/aty128fb.c
39426@@ -149,7 +149,7 @@ enum {
39427 };
39428
39429 /* Must match above enum */
39430-static const char *r128_family[] __devinitdata = {
39431+static const char *r128_family[] __devinitconst = {
39432 "AGP",
39433 "PCI",
39434 "PRO AGP",
39435diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39436index 5c3960d..15cf8fc 100644
39437--- a/drivers/video/fbcmap.c
39438+++ b/drivers/video/fbcmap.c
39439@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39440 rc = -ENODEV;
39441 goto out;
39442 }
39443- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39444- !info->fbops->fb_setcmap)) {
39445+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39446 rc = -EINVAL;
39447 goto out1;
39448 }
39449diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39450index 0dff12a..2ef47b3 100644
39451--- a/drivers/video/fbmem.c
39452+++ b/drivers/video/fbmem.c
39453@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39454 image->dx += image->width + 8;
39455 }
39456 } else if (rotate == FB_ROTATE_UD) {
39457- for (x = 0; x < num && image->dx >= 0; x++) {
39458+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39459 info->fbops->fb_imageblit(info, image);
39460 image->dx -= image->width + 8;
39461 }
39462@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39463 image->dy += image->height + 8;
39464 }
39465 } else if (rotate == FB_ROTATE_CCW) {
39466- for (x = 0; x < num && image->dy >= 0; x++) {
39467+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39468 info->fbops->fb_imageblit(info, image);
39469 image->dy -= image->height + 8;
39470 }
39471@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39472 return -EFAULT;
39473 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39474 return -EINVAL;
39475- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39476+ if (con2fb.framebuffer >= FB_MAX)
39477 return -EINVAL;
39478 if (!registered_fb[con2fb.framebuffer])
39479 request_module("fb%d", con2fb.framebuffer);
39480diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39481index 5a5d092..265c5ed 100644
39482--- a/drivers/video/geode/gx1fb_core.c
39483+++ b/drivers/video/geode/gx1fb_core.c
39484@@ -29,7 +29,7 @@ static int crt_option = 1;
39485 static char panel_option[32] = "";
39486
39487 /* Modes relevant to the GX1 (taken from modedb.c) */
39488-static const struct fb_videomode __devinitdata gx1_modedb[] = {
39489+static const struct fb_videomode __devinitconst gx1_modedb[] = {
39490 /* 640x480-60 VESA */
39491 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39492 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39493diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39494index 0fad23f..0e9afa4 100644
39495--- a/drivers/video/gxt4500.c
39496+++ b/drivers/video/gxt4500.c
39497@@ -156,7 +156,7 @@ struct gxt4500_par {
39498 static char *mode_option;
39499
39500 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39501-static const struct fb_videomode defaultmode __devinitdata = {
39502+static const struct fb_videomode defaultmode __devinitconst = {
39503 .refresh = 60,
39504 .xres = 1280,
39505 .yres = 1024,
39506@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39507 return 0;
39508 }
39509
39510-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39511+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39512 .id = "IBM GXT4500P",
39513 .type = FB_TYPE_PACKED_PIXELS,
39514 .visual = FB_VISUAL_PSEUDOCOLOR,
39515diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39516index 7672d2e..b56437f 100644
39517--- a/drivers/video/i810/i810_accel.c
39518+++ b/drivers/video/i810/i810_accel.c
39519@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39520 }
39521 }
39522 printk("ringbuffer lockup!!!\n");
39523+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39524 i810_report_error(mmio);
39525 par->dev_flags |= LOCKUP;
39526 info->pixmap.scan_align = 1;
39527diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39528index b83f361..2b05a91 100644
39529--- a/drivers/video/i810/i810_main.c
39530+++ b/drivers/video/i810/i810_main.c
39531@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39532 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39533
39534 /* PCI */
39535-static const char *i810_pci_list[] __devinitdata = {
39536+static const char *i810_pci_list[] __devinitconst = {
39537 "Intel(R) 810 Framebuffer Device" ,
39538 "Intel(R) 810-DC100 Framebuffer Device" ,
39539 "Intel(R) 810E Framebuffer Device" ,
39540diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39541index de36693..3c63fc2 100644
39542--- a/drivers/video/jz4740_fb.c
39543+++ b/drivers/video/jz4740_fb.c
39544@@ -136,7 +136,7 @@ struct jzfb {
39545 uint32_t pseudo_palette[16];
39546 };
39547
39548-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39549+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39550 .id = "JZ4740 FB",
39551 .type = FB_TYPE_PACKED_PIXELS,
39552 .visual = FB_VISUAL_TRUECOLOR,
39553diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39554index 3c14e43..eafa544 100644
39555--- a/drivers/video/logo/logo_linux_clut224.ppm
39556+++ b/drivers/video/logo/logo_linux_clut224.ppm
39557@@ -1,1604 +1,1123 @@
39558 P3
39559-# Standard 224-color Linux logo
39560 80 80
39561 255
39562- 0 0 0 0 0 0 0 0 0 0 0 0
39563- 0 0 0 0 0 0 0 0 0 0 0 0
39564- 0 0 0 0 0 0 0 0 0 0 0 0
39565- 0 0 0 0 0 0 0 0 0 0 0 0
39566- 0 0 0 0 0 0 0 0 0 0 0 0
39567- 0 0 0 0 0 0 0 0 0 0 0 0
39568- 0 0 0 0 0 0 0 0 0 0 0 0
39569- 0 0 0 0 0 0 0 0 0 0 0 0
39570- 0 0 0 0 0 0 0 0 0 0 0 0
39571- 6 6 6 6 6 6 10 10 10 10 10 10
39572- 10 10 10 6 6 6 6 6 6 6 6 6
39573- 0 0 0 0 0 0 0 0 0 0 0 0
39574- 0 0 0 0 0 0 0 0 0 0 0 0
39575- 0 0 0 0 0 0 0 0 0 0 0 0
39576- 0 0 0 0 0 0 0 0 0 0 0 0
39577- 0 0 0 0 0 0 0 0 0 0 0 0
39578- 0 0 0 0 0 0 0 0 0 0 0 0
39579- 0 0 0 0 0 0 0 0 0 0 0 0
39580- 0 0 0 0 0 0 0 0 0 0 0 0
39581- 0 0 0 0 0 0 0 0 0 0 0 0
39582- 0 0 0 0 0 0 0 0 0 0 0 0
39583- 0 0 0 0 0 0 0 0 0 0 0 0
39584- 0 0 0 0 0 0 0 0 0 0 0 0
39585- 0 0 0 0 0 0 0 0 0 0 0 0
39586- 0 0 0 0 0 0 0 0 0 0 0 0
39587- 0 0 0 0 0 0 0 0 0 0 0 0
39588- 0 0 0 0 0 0 0 0 0 0 0 0
39589- 0 0 0 0 0 0 0 0 0 0 0 0
39590- 0 0 0 6 6 6 10 10 10 14 14 14
39591- 22 22 22 26 26 26 30 30 30 34 34 34
39592- 30 30 30 30 30 30 26 26 26 18 18 18
39593- 14 14 14 10 10 10 6 6 6 0 0 0
39594- 0 0 0 0 0 0 0 0 0 0 0 0
39595- 0 0 0 0 0 0 0 0 0 0 0 0
39596- 0 0 0 0 0 0 0 0 0 0 0 0
39597- 0 0 0 0 0 0 0 0 0 0 0 0
39598- 0 0 0 0 0 0 0 0 0 0 0 0
39599- 0 0 0 0 0 0 0 0 0 0 0 0
39600- 0 0 0 0 0 0 0 0 0 0 0 0
39601- 0 0 0 0 0 0 0 0 0 0 0 0
39602- 0 0 0 0 0 0 0 0 0 0 0 0
39603- 0 0 0 0 0 1 0 0 1 0 0 0
39604- 0 0 0 0 0 0 0 0 0 0 0 0
39605- 0 0 0 0 0 0 0 0 0 0 0 0
39606- 0 0 0 0 0 0 0 0 0 0 0 0
39607- 0 0 0 0 0 0 0 0 0 0 0 0
39608- 0 0 0 0 0 0 0 0 0 0 0 0
39609- 0 0 0 0 0 0 0 0 0 0 0 0
39610- 6 6 6 14 14 14 26 26 26 42 42 42
39611- 54 54 54 66 66 66 78 78 78 78 78 78
39612- 78 78 78 74 74 74 66 66 66 54 54 54
39613- 42 42 42 26 26 26 18 18 18 10 10 10
39614- 6 6 6 0 0 0 0 0 0 0 0 0
39615- 0 0 0 0 0 0 0 0 0 0 0 0
39616- 0 0 0 0 0 0 0 0 0 0 0 0
39617- 0 0 0 0 0 0 0 0 0 0 0 0
39618- 0 0 0 0 0 0 0 0 0 0 0 0
39619- 0 0 0 0 0 0 0 0 0 0 0 0
39620- 0 0 0 0 0 0 0 0 0 0 0 0
39621- 0 0 0 0 0 0 0 0 0 0 0 0
39622- 0 0 0 0 0 0 0 0 0 0 0 0
39623- 0 0 1 0 0 0 0 0 0 0 0 0
39624- 0 0 0 0 0 0 0 0 0 0 0 0
39625- 0 0 0 0 0 0 0 0 0 0 0 0
39626- 0 0 0 0 0 0 0 0 0 0 0 0
39627- 0 0 0 0 0 0 0 0 0 0 0 0
39628- 0 0 0 0 0 0 0 0 0 0 0 0
39629- 0 0 0 0 0 0 0 0 0 10 10 10
39630- 22 22 22 42 42 42 66 66 66 86 86 86
39631- 66 66 66 38 38 38 38 38 38 22 22 22
39632- 26 26 26 34 34 34 54 54 54 66 66 66
39633- 86 86 86 70 70 70 46 46 46 26 26 26
39634- 14 14 14 6 6 6 0 0 0 0 0 0
39635- 0 0 0 0 0 0 0 0 0 0 0 0
39636- 0 0 0 0 0 0 0 0 0 0 0 0
39637- 0 0 0 0 0 0 0 0 0 0 0 0
39638- 0 0 0 0 0 0 0 0 0 0 0 0
39639- 0 0 0 0 0 0 0 0 0 0 0 0
39640- 0 0 0 0 0 0 0 0 0 0 0 0
39641- 0 0 0 0 0 0 0 0 0 0 0 0
39642- 0 0 0 0 0 0 0 0 0 0 0 0
39643- 0 0 1 0 0 1 0 0 1 0 0 0
39644- 0 0 0 0 0 0 0 0 0 0 0 0
39645- 0 0 0 0 0 0 0 0 0 0 0 0
39646- 0 0 0 0 0 0 0 0 0 0 0 0
39647- 0 0 0 0 0 0 0 0 0 0 0 0
39648- 0 0 0 0 0 0 0 0 0 0 0 0
39649- 0 0 0 0 0 0 10 10 10 26 26 26
39650- 50 50 50 82 82 82 58 58 58 6 6 6
39651- 2 2 6 2 2 6 2 2 6 2 2 6
39652- 2 2 6 2 2 6 2 2 6 2 2 6
39653- 6 6 6 54 54 54 86 86 86 66 66 66
39654- 38 38 38 18 18 18 6 6 6 0 0 0
39655- 0 0 0 0 0 0 0 0 0 0 0 0
39656- 0 0 0 0 0 0 0 0 0 0 0 0
39657- 0 0 0 0 0 0 0 0 0 0 0 0
39658- 0 0 0 0 0 0 0 0 0 0 0 0
39659- 0 0 0 0 0 0 0 0 0 0 0 0
39660- 0 0 0 0 0 0 0 0 0 0 0 0
39661- 0 0 0 0 0 0 0 0 0 0 0 0
39662- 0 0 0 0 0 0 0 0 0 0 0 0
39663- 0 0 0 0 0 0 0 0 0 0 0 0
39664- 0 0 0 0 0 0 0 0 0 0 0 0
39665- 0 0 0 0 0 0 0 0 0 0 0 0
39666- 0 0 0 0 0 0 0 0 0 0 0 0
39667- 0 0 0 0 0 0 0 0 0 0 0 0
39668- 0 0 0 0 0 0 0 0 0 0 0 0
39669- 0 0 0 6 6 6 22 22 22 50 50 50
39670- 78 78 78 34 34 34 2 2 6 2 2 6
39671- 2 2 6 2 2 6 2 2 6 2 2 6
39672- 2 2 6 2 2 6 2 2 6 2 2 6
39673- 2 2 6 2 2 6 6 6 6 70 70 70
39674- 78 78 78 46 46 46 22 22 22 6 6 6
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 1 0 0 1 0 0 1 0 0 0
39684- 0 0 0 0 0 0 0 0 0 0 0 0
39685- 0 0 0 0 0 0 0 0 0 0 0 0
39686- 0 0 0 0 0 0 0 0 0 0 0 0
39687- 0 0 0 0 0 0 0 0 0 0 0 0
39688- 0 0 0 0 0 0 0 0 0 0 0 0
39689- 6 6 6 18 18 18 42 42 42 82 82 82
39690- 26 26 26 2 2 6 2 2 6 2 2 6
39691- 2 2 6 2 2 6 2 2 6 2 2 6
39692- 2 2 6 2 2 6 2 2 6 14 14 14
39693- 46 46 46 34 34 34 6 6 6 2 2 6
39694- 42 42 42 78 78 78 42 42 42 18 18 18
39695- 6 6 6 0 0 0 0 0 0 0 0 0
39696- 0 0 0 0 0 0 0 0 0 0 0 0
39697- 0 0 0 0 0 0 0 0 0 0 0 0
39698- 0 0 0 0 0 0 0 0 0 0 0 0
39699- 0 0 0 0 0 0 0 0 0 0 0 0
39700- 0 0 0 0 0 0 0 0 0 0 0 0
39701- 0 0 0 0 0 0 0 0 0 0 0 0
39702- 0 0 0 0 0 0 0 0 0 0 0 0
39703- 0 0 1 0 0 0 0 0 1 0 0 0
39704- 0 0 0 0 0 0 0 0 0 0 0 0
39705- 0 0 0 0 0 0 0 0 0 0 0 0
39706- 0 0 0 0 0 0 0 0 0 0 0 0
39707- 0 0 0 0 0 0 0 0 0 0 0 0
39708- 0 0 0 0 0 0 0 0 0 0 0 0
39709- 10 10 10 30 30 30 66 66 66 58 58 58
39710- 2 2 6 2 2 6 2 2 6 2 2 6
39711- 2 2 6 2 2 6 2 2 6 2 2 6
39712- 2 2 6 2 2 6 2 2 6 26 26 26
39713- 86 86 86 101 101 101 46 46 46 10 10 10
39714- 2 2 6 58 58 58 70 70 70 34 34 34
39715- 10 10 10 0 0 0 0 0 0 0 0 0
39716- 0 0 0 0 0 0 0 0 0 0 0 0
39717- 0 0 0 0 0 0 0 0 0 0 0 0
39718- 0 0 0 0 0 0 0 0 0 0 0 0
39719- 0 0 0 0 0 0 0 0 0 0 0 0
39720- 0 0 0 0 0 0 0 0 0 0 0 0
39721- 0 0 0 0 0 0 0 0 0 0 0 0
39722- 0 0 0 0 0 0 0 0 0 0 0 0
39723- 0 0 1 0 0 1 0 0 1 0 0 0
39724- 0 0 0 0 0 0 0 0 0 0 0 0
39725- 0 0 0 0 0 0 0 0 0 0 0 0
39726- 0 0 0 0 0 0 0 0 0 0 0 0
39727- 0 0 0 0 0 0 0 0 0 0 0 0
39728- 0 0 0 0 0 0 0 0 0 0 0 0
39729- 14 14 14 42 42 42 86 86 86 10 10 10
39730- 2 2 6 2 2 6 2 2 6 2 2 6
39731- 2 2 6 2 2 6 2 2 6 2 2 6
39732- 2 2 6 2 2 6 2 2 6 30 30 30
39733- 94 94 94 94 94 94 58 58 58 26 26 26
39734- 2 2 6 6 6 6 78 78 78 54 54 54
39735- 22 22 22 6 6 6 0 0 0 0 0 0
39736- 0 0 0 0 0 0 0 0 0 0 0 0
39737- 0 0 0 0 0 0 0 0 0 0 0 0
39738- 0 0 0 0 0 0 0 0 0 0 0 0
39739- 0 0 0 0 0 0 0 0 0 0 0 0
39740- 0 0 0 0 0 0 0 0 0 0 0 0
39741- 0 0 0 0 0 0 0 0 0 0 0 0
39742- 0 0 0 0 0 0 0 0 0 0 0 0
39743- 0 0 0 0 0 0 0 0 0 0 0 0
39744- 0 0 0 0 0 0 0 0 0 0 0 0
39745- 0 0 0 0 0 0 0 0 0 0 0 0
39746- 0 0 0 0 0 0 0 0 0 0 0 0
39747- 0 0 0 0 0 0 0 0 0 0 0 0
39748- 0 0 0 0 0 0 0 0 0 6 6 6
39749- 22 22 22 62 62 62 62 62 62 2 2 6
39750- 2 2 6 2 2 6 2 2 6 2 2 6
39751- 2 2 6 2 2 6 2 2 6 2 2 6
39752- 2 2 6 2 2 6 2 2 6 26 26 26
39753- 54 54 54 38 38 38 18 18 18 10 10 10
39754- 2 2 6 2 2 6 34 34 34 82 82 82
39755- 38 38 38 14 14 14 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 1 0 0 1 0 0 0
39764- 0 0 0 0 0 0 0 0 0 0 0 0
39765- 0 0 0 0 0 0 0 0 0 0 0 0
39766- 0 0 0 0 0 0 0 0 0 0 0 0
39767- 0 0 0 0 0 0 0 0 0 0 0 0
39768- 0 0 0 0 0 0 0 0 0 6 6 6
39769- 30 30 30 78 78 78 30 30 30 2 2 6
39770- 2 2 6 2 2 6 2 2 6 2 2 6
39771- 2 2 6 2 2 6 2 2 6 2 2 6
39772- 2 2 6 2 2 6 2 2 6 10 10 10
39773- 10 10 10 2 2 6 2 2 6 2 2 6
39774- 2 2 6 2 2 6 2 2 6 78 78 78
39775- 50 50 50 18 18 18 6 6 6 0 0 0
39776- 0 0 0 0 0 0 0 0 0 0 0 0
39777- 0 0 0 0 0 0 0 0 0 0 0 0
39778- 0 0 0 0 0 0 0 0 0 0 0 0
39779- 0 0 0 0 0 0 0 0 0 0 0 0
39780- 0 0 0 0 0 0 0 0 0 0 0 0
39781- 0 0 0 0 0 0 0 0 0 0 0 0
39782- 0 0 0 0 0 0 0 0 0 0 0 0
39783- 0 0 1 0 0 0 0 0 0 0 0 0
39784- 0 0 0 0 0 0 0 0 0 0 0 0
39785- 0 0 0 0 0 0 0 0 0 0 0 0
39786- 0 0 0 0 0 0 0 0 0 0 0 0
39787- 0 0 0 0 0 0 0 0 0 0 0 0
39788- 0 0 0 0 0 0 0 0 0 10 10 10
39789- 38 38 38 86 86 86 14 14 14 2 2 6
39790- 2 2 6 2 2 6 2 2 6 2 2 6
39791- 2 2 6 2 2 6 2 2 6 2 2 6
39792- 2 2 6 2 2 6 2 2 6 2 2 6
39793- 2 2 6 2 2 6 2 2 6 2 2 6
39794- 2 2 6 2 2 6 2 2 6 54 54 54
39795- 66 66 66 26 26 26 6 6 6 0 0 0
39796- 0 0 0 0 0 0 0 0 0 0 0 0
39797- 0 0 0 0 0 0 0 0 0 0 0 0
39798- 0 0 0 0 0 0 0 0 0 0 0 0
39799- 0 0 0 0 0 0 0 0 0 0 0 0
39800- 0 0 0 0 0 0 0 0 0 0 0 0
39801- 0 0 0 0 0 0 0 0 0 0 0 0
39802- 0 0 0 0 0 0 0 0 0 0 0 0
39803- 0 0 0 0 0 1 0 0 1 0 0 0
39804- 0 0 0 0 0 0 0 0 0 0 0 0
39805- 0 0 0 0 0 0 0 0 0 0 0 0
39806- 0 0 0 0 0 0 0 0 0 0 0 0
39807- 0 0 0 0 0 0 0 0 0 0 0 0
39808- 0 0 0 0 0 0 0 0 0 14 14 14
39809- 42 42 42 82 82 82 2 2 6 2 2 6
39810- 2 2 6 6 6 6 10 10 10 2 2 6
39811- 2 2 6 2 2 6 2 2 6 2 2 6
39812- 2 2 6 2 2 6 2 2 6 6 6 6
39813- 14 14 14 10 10 10 2 2 6 2 2 6
39814- 2 2 6 2 2 6 2 2 6 18 18 18
39815- 82 82 82 34 34 34 10 10 10 0 0 0
39816- 0 0 0 0 0 0 0 0 0 0 0 0
39817- 0 0 0 0 0 0 0 0 0 0 0 0
39818- 0 0 0 0 0 0 0 0 0 0 0 0
39819- 0 0 0 0 0 0 0 0 0 0 0 0
39820- 0 0 0 0 0 0 0 0 0 0 0 0
39821- 0 0 0 0 0 0 0 0 0 0 0 0
39822- 0 0 0 0 0 0 0 0 0 0 0 0
39823- 0 0 1 0 0 0 0 0 0 0 0 0
39824- 0 0 0 0 0 0 0 0 0 0 0 0
39825- 0 0 0 0 0 0 0 0 0 0 0 0
39826- 0 0 0 0 0 0 0 0 0 0 0 0
39827- 0 0 0 0 0 0 0 0 0 0 0 0
39828- 0 0 0 0 0 0 0 0 0 14 14 14
39829- 46 46 46 86 86 86 2 2 6 2 2 6
39830- 6 6 6 6 6 6 22 22 22 34 34 34
39831- 6 6 6 2 2 6 2 2 6 2 2 6
39832- 2 2 6 2 2 6 18 18 18 34 34 34
39833- 10 10 10 50 50 50 22 22 22 2 2 6
39834- 2 2 6 2 2 6 2 2 6 10 10 10
39835- 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 1 0 0 0
39844- 0 0 0 0 0 0 0 0 0 0 0 0
39845- 0 0 0 0 0 0 0 0 0 0 0 0
39846- 0 0 0 0 0 0 0 0 0 0 0 0
39847- 0 0 0 0 0 0 0 0 0 0 0 0
39848- 0 0 0 0 0 0 0 0 0 14 14 14
39849- 46 46 46 86 86 86 2 2 6 2 2 6
39850- 38 38 38 116 116 116 94 94 94 22 22 22
39851- 22 22 22 2 2 6 2 2 6 2 2 6
39852- 14 14 14 86 86 86 138 138 138 162 162 162
39853-154 154 154 38 38 38 26 26 26 6 6 6
39854- 2 2 6 2 2 6 2 2 6 2 2 6
39855- 86 86 86 46 46 46 14 14 14 0 0 0
39856- 0 0 0 0 0 0 0 0 0 0 0 0
39857- 0 0 0 0 0 0 0 0 0 0 0 0
39858- 0 0 0 0 0 0 0 0 0 0 0 0
39859- 0 0 0 0 0 0 0 0 0 0 0 0
39860- 0 0 0 0 0 0 0 0 0 0 0 0
39861- 0 0 0 0 0 0 0 0 0 0 0 0
39862- 0 0 0 0 0 0 0 0 0 0 0 0
39863- 0 0 0 0 0 0 0 0 0 0 0 0
39864- 0 0 0 0 0 0 0 0 0 0 0 0
39865- 0 0 0 0 0 0 0 0 0 0 0 0
39866- 0 0 0 0 0 0 0 0 0 0 0 0
39867- 0 0 0 0 0 0 0 0 0 0 0 0
39868- 0 0 0 0 0 0 0 0 0 14 14 14
39869- 46 46 46 86 86 86 2 2 6 14 14 14
39870-134 134 134 198 198 198 195 195 195 116 116 116
39871- 10 10 10 2 2 6 2 2 6 6 6 6
39872-101 98 89 187 187 187 210 210 210 218 218 218
39873-214 214 214 134 134 134 14 14 14 6 6 6
39874- 2 2 6 2 2 6 2 2 6 2 2 6
39875- 86 86 86 50 50 50 18 18 18 6 6 6
39876- 0 0 0 0 0 0 0 0 0 0 0 0
39877- 0 0 0 0 0 0 0 0 0 0 0 0
39878- 0 0 0 0 0 0 0 0 0 0 0 0
39879- 0 0 0 0 0 0 0 0 0 0 0 0
39880- 0 0 0 0 0 0 0 0 0 0 0 0
39881- 0 0 0 0 0 0 0 0 0 0 0 0
39882- 0 0 0 0 0 0 0 0 1 0 0 0
39883- 0 0 1 0 0 1 0 0 1 0 0 0
39884- 0 0 0 0 0 0 0 0 0 0 0 0
39885- 0 0 0 0 0 0 0 0 0 0 0 0
39886- 0 0 0 0 0 0 0 0 0 0 0 0
39887- 0 0 0 0 0 0 0 0 0 0 0 0
39888- 0 0 0 0 0 0 0 0 0 14 14 14
39889- 46 46 46 86 86 86 2 2 6 54 54 54
39890-218 218 218 195 195 195 226 226 226 246 246 246
39891- 58 58 58 2 2 6 2 2 6 30 30 30
39892-210 210 210 253 253 253 174 174 174 123 123 123
39893-221 221 221 234 234 234 74 74 74 2 2 6
39894- 2 2 6 2 2 6 2 2 6 2 2 6
39895- 70 70 70 58 58 58 22 22 22 6 6 6
39896- 0 0 0 0 0 0 0 0 0 0 0 0
39897- 0 0 0 0 0 0 0 0 0 0 0 0
39898- 0 0 0 0 0 0 0 0 0 0 0 0
39899- 0 0 0 0 0 0 0 0 0 0 0 0
39900- 0 0 0 0 0 0 0 0 0 0 0 0
39901- 0 0 0 0 0 0 0 0 0 0 0 0
39902- 0 0 0 0 0 0 0 0 0 0 0 0
39903- 0 0 0 0 0 0 0 0 0 0 0 0
39904- 0 0 0 0 0 0 0 0 0 0 0 0
39905- 0 0 0 0 0 0 0 0 0 0 0 0
39906- 0 0 0 0 0 0 0 0 0 0 0 0
39907- 0 0 0 0 0 0 0 0 0 0 0 0
39908- 0 0 0 0 0 0 0 0 0 14 14 14
39909- 46 46 46 82 82 82 2 2 6 106 106 106
39910-170 170 170 26 26 26 86 86 86 226 226 226
39911-123 123 123 10 10 10 14 14 14 46 46 46
39912-231 231 231 190 190 190 6 6 6 70 70 70
39913- 90 90 90 238 238 238 158 158 158 2 2 6
39914- 2 2 6 2 2 6 2 2 6 2 2 6
39915- 70 70 70 58 58 58 22 22 22 6 6 6
39916- 0 0 0 0 0 0 0 0 0 0 0 0
39917- 0 0 0 0 0 0 0 0 0 0 0 0
39918- 0 0 0 0 0 0 0 0 0 0 0 0
39919- 0 0 0 0 0 0 0 0 0 0 0 0
39920- 0 0 0 0 0 0 0 0 0 0 0 0
39921- 0 0 0 0 0 0 0 0 0 0 0 0
39922- 0 0 0 0 0 0 0 0 1 0 0 0
39923- 0 0 1 0 0 1 0 0 1 0 0 0
39924- 0 0 0 0 0 0 0 0 0 0 0 0
39925- 0 0 0 0 0 0 0 0 0 0 0 0
39926- 0 0 0 0 0 0 0 0 0 0 0 0
39927- 0 0 0 0 0 0 0 0 0 0 0 0
39928- 0 0 0 0 0 0 0 0 0 14 14 14
39929- 42 42 42 86 86 86 6 6 6 116 116 116
39930-106 106 106 6 6 6 70 70 70 149 149 149
39931-128 128 128 18 18 18 38 38 38 54 54 54
39932-221 221 221 106 106 106 2 2 6 14 14 14
39933- 46 46 46 190 190 190 198 198 198 2 2 6
39934- 2 2 6 2 2 6 2 2 6 2 2 6
39935- 74 74 74 62 62 62 22 22 22 6 6 6
39936- 0 0 0 0 0 0 0 0 0 0 0 0
39937- 0 0 0 0 0 0 0 0 0 0 0 0
39938- 0 0 0 0 0 0 0 0 0 0 0 0
39939- 0 0 0 0 0 0 0 0 0 0 0 0
39940- 0 0 0 0 0 0 0 0 0 0 0 0
39941- 0 0 0 0 0 0 0 0 0 0 0 0
39942- 0 0 0 0 0 0 0 0 1 0 0 0
39943- 0 0 1 0 0 0 0 0 1 0 0 0
39944- 0 0 0 0 0 0 0 0 0 0 0 0
39945- 0 0 0 0 0 0 0 0 0 0 0 0
39946- 0 0 0 0 0 0 0 0 0 0 0 0
39947- 0 0 0 0 0 0 0 0 0 0 0 0
39948- 0 0 0 0 0 0 0 0 0 14 14 14
39949- 42 42 42 94 94 94 14 14 14 101 101 101
39950-128 128 128 2 2 6 18 18 18 116 116 116
39951-118 98 46 121 92 8 121 92 8 98 78 10
39952-162 162 162 106 106 106 2 2 6 2 2 6
39953- 2 2 6 195 195 195 195 195 195 6 6 6
39954- 2 2 6 2 2 6 2 2 6 2 2 6
39955- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
39963- 0 0 1 0 0 0 0 0 1 0 0 0
39964- 0 0 0 0 0 0 0 0 0 0 0 0
39965- 0 0 0 0 0 0 0 0 0 0 0 0
39966- 0 0 0 0 0 0 0 0 0 0 0 0
39967- 0 0 0 0 0 0 0 0 0 0 0 0
39968- 0 0 0 0 0 0 0 0 0 10 10 10
39969- 38 38 38 90 90 90 14 14 14 58 58 58
39970-210 210 210 26 26 26 54 38 6 154 114 10
39971-226 170 11 236 186 11 225 175 15 184 144 12
39972-215 174 15 175 146 61 37 26 9 2 2 6
39973- 70 70 70 246 246 246 138 138 138 2 2 6
39974- 2 2 6 2 2 6 2 2 6 2 2 6
39975- 70 70 70 66 66 66 26 26 26 6 6 6
39976- 0 0 0 0 0 0 0 0 0 0 0 0
39977- 0 0 0 0 0 0 0 0 0 0 0 0
39978- 0 0 0 0 0 0 0 0 0 0 0 0
39979- 0 0 0 0 0 0 0 0 0 0 0 0
39980- 0 0 0 0 0 0 0 0 0 0 0 0
39981- 0 0 0 0 0 0 0 0 0 0 0 0
39982- 0 0 0 0 0 0 0 0 0 0 0 0
39983- 0 0 0 0 0 0 0 0 0 0 0 0
39984- 0 0 0 0 0 0 0 0 0 0 0 0
39985- 0 0 0 0 0 0 0 0 0 0 0 0
39986- 0 0 0 0 0 0 0 0 0 0 0 0
39987- 0 0 0 0 0 0 0 0 0 0 0 0
39988- 0 0 0 0 0 0 0 0 0 10 10 10
39989- 38 38 38 86 86 86 14 14 14 10 10 10
39990-195 195 195 188 164 115 192 133 9 225 175 15
39991-239 182 13 234 190 10 232 195 16 232 200 30
39992-245 207 45 241 208 19 232 195 16 184 144 12
39993-218 194 134 211 206 186 42 42 42 2 2 6
39994- 2 2 6 2 2 6 2 2 6 2 2 6
39995- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
40005- 0 0 0 0 0 0 0 0 0 0 0 0
40006- 0 0 0 0 0 0 0 0 0 0 0 0
40007- 0 0 0 0 0 0 0 0 0 0 0 0
40008- 0 0 0 0 0 0 0 0 0 10 10 10
40009- 34 34 34 86 86 86 14 14 14 2 2 6
40010-121 87 25 192 133 9 219 162 10 239 182 13
40011-236 186 11 232 195 16 241 208 19 244 214 54
40012-246 218 60 246 218 38 246 215 20 241 208 19
40013-241 208 19 226 184 13 121 87 25 2 2 6
40014- 2 2 6 2 2 6 2 2 6 2 2 6
40015- 50 50 50 82 82 82 34 34 34 10 10 10
40016- 0 0 0 0 0 0 0 0 0 0 0 0
40017- 0 0 0 0 0 0 0 0 0 0 0 0
40018- 0 0 0 0 0 0 0 0 0 0 0 0
40019- 0 0 0 0 0 0 0 0 0 0 0 0
40020- 0 0 0 0 0 0 0 0 0 0 0 0
40021- 0 0 0 0 0 0 0 0 0 0 0 0
40022- 0 0 0 0 0 0 0 0 0 0 0 0
40023- 0 0 0 0 0 0 0 0 0 0 0 0
40024- 0 0 0 0 0 0 0 0 0 0 0 0
40025- 0 0 0 0 0 0 0 0 0 0 0 0
40026- 0 0 0 0 0 0 0 0 0 0 0 0
40027- 0 0 0 0 0 0 0 0 0 0 0 0
40028- 0 0 0 0 0 0 0 0 0 10 10 10
40029- 34 34 34 82 82 82 30 30 30 61 42 6
40030-180 123 7 206 145 10 230 174 11 239 182 13
40031-234 190 10 238 202 15 241 208 19 246 218 74
40032-246 218 38 246 215 20 246 215 20 246 215 20
40033-226 184 13 215 174 15 184 144 12 6 6 6
40034- 2 2 6 2 2 6 2 2 6 2 2 6
40035- 26 26 26 94 94 94 42 42 42 14 14 14
40036- 0 0 0 0 0 0 0 0 0 0 0 0
40037- 0 0 0 0 0 0 0 0 0 0 0 0
40038- 0 0 0 0 0 0 0 0 0 0 0 0
40039- 0 0 0 0 0 0 0 0 0 0 0 0
40040- 0 0 0 0 0 0 0 0 0 0 0 0
40041- 0 0 0 0 0 0 0 0 0 0 0 0
40042- 0 0 0 0 0 0 0 0 0 0 0 0
40043- 0 0 0 0 0 0 0 0 0 0 0 0
40044- 0 0 0 0 0 0 0 0 0 0 0 0
40045- 0 0 0 0 0 0 0 0 0 0 0 0
40046- 0 0 0 0 0 0 0 0 0 0 0 0
40047- 0 0 0 0 0 0 0 0 0 0 0 0
40048- 0 0 0 0 0 0 0 0 0 10 10 10
40049- 30 30 30 78 78 78 50 50 50 104 69 6
40050-192 133 9 216 158 10 236 178 12 236 186 11
40051-232 195 16 241 208 19 244 214 54 245 215 43
40052-246 215 20 246 215 20 241 208 19 198 155 10
40053-200 144 11 216 158 10 156 118 10 2 2 6
40054- 2 2 6 2 2 6 2 2 6 2 2 6
40055- 6 6 6 90 90 90 54 54 54 18 18 18
40056- 6 6 6 0 0 0 0 0 0 0 0 0
40057- 0 0 0 0 0 0 0 0 0 0 0 0
40058- 0 0 0 0 0 0 0 0 0 0 0 0
40059- 0 0 0 0 0 0 0 0 0 0 0 0
40060- 0 0 0 0 0 0 0 0 0 0 0 0
40061- 0 0 0 0 0 0 0 0 0 0 0 0
40062- 0 0 0 0 0 0 0 0 0 0 0 0
40063- 0 0 0 0 0 0 0 0 0 0 0 0
40064- 0 0 0 0 0 0 0 0 0 0 0 0
40065- 0 0 0 0 0 0 0 0 0 0 0 0
40066- 0 0 0 0 0 0 0 0 0 0 0 0
40067- 0 0 0 0 0 0 0 0 0 0 0 0
40068- 0 0 0 0 0 0 0 0 0 10 10 10
40069- 30 30 30 78 78 78 46 46 46 22 22 22
40070-137 92 6 210 162 10 239 182 13 238 190 10
40071-238 202 15 241 208 19 246 215 20 246 215 20
40072-241 208 19 203 166 17 185 133 11 210 150 10
40073-216 158 10 210 150 10 102 78 10 2 2 6
40074- 6 6 6 54 54 54 14 14 14 2 2 6
40075- 2 2 6 62 62 62 74 74 74 30 30 30
40076- 10 10 10 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 0 0 0
40085- 0 0 0 0 0 0 0 0 0 0 0 0
40086- 0 0 0 0 0 0 0 0 0 0 0 0
40087- 0 0 0 0 0 0 0 0 0 0 0 0
40088- 0 0 0 0 0 0 0 0 0 10 10 10
40089- 34 34 34 78 78 78 50 50 50 6 6 6
40090- 94 70 30 139 102 15 190 146 13 226 184 13
40091-232 200 30 232 195 16 215 174 15 190 146 13
40092-168 122 10 192 133 9 210 150 10 213 154 11
40093-202 150 34 182 157 106 101 98 89 2 2 6
40094- 2 2 6 78 78 78 116 116 116 58 58 58
40095- 2 2 6 22 22 22 90 90 90 46 46 46
40096- 18 18 18 6 6 6 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 0 0 0
40105- 0 0 0 0 0 0 0 0 0 0 0 0
40106- 0 0 0 0 0 0 0 0 0 0 0 0
40107- 0 0 0 0 0 0 0 0 0 0 0 0
40108- 0 0 0 0 0 0 0 0 0 10 10 10
40109- 38 38 38 86 86 86 50 50 50 6 6 6
40110-128 128 128 174 154 114 156 107 11 168 122 10
40111-198 155 10 184 144 12 197 138 11 200 144 11
40112-206 145 10 206 145 10 197 138 11 188 164 115
40113-195 195 195 198 198 198 174 174 174 14 14 14
40114- 2 2 6 22 22 22 116 116 116 116 116 116
40115- 22 22 22 2 2 6 74 74 74 70 70 70
40116- 30 30 30 10 10 10 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 0 0 0
40125- 0 0 0 0 0 0 0 0 0 0 0 0
40126- 0 0 0 0 0 0 0 0 0 0 0 0
40127- 0 0 0 0 0 0 0 0 0 0 0 0
40128- 0 0 0 0 0 0 6 6 6 18 18 18
40129- 50 50 50 101 101 101 26 26 26 10 10 10
40130-138 138 138 190 190 190 174 154 114 156 107 11
40131-197 138 11 200 144 11 197 138 11 192 133 9
40132-180 123 7 190 142 34 190 178 144 187 187 187
40133-202 202 202 221 221 221 214 214 214 66 66 66
40134- 2 2 6 2 2 6 50 50 50 62 62 62
40135- 6 6 6 2 2 6 10 10 10 90 90 90
40136- 50 50 50 18 18 18 6 6 6 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 0 0 0
40145- 0 0 0 0 0 0 0 0 0 0 0 0
40146- 0 0 0 0 0 0 0 0 0 0 0 0
40147- 0 0 0 0 0 0 0 0 0 0 0 0
40148- 0 0 0 0 0 0 10 10 10 34 34 34
40149- 74 74 74 74 74 74 2 2 6 6 6 6
40150-144 144 144 198 198 198 190 190 190 178 166 146
40151-154 121 60 156 107 11 156 107 11 168 124 44
40152-174 154 114 187 187 187 190 190 190 210 210 210
40153-246 246 246 253 253 253 253 253 253 182 182 182
40154- 6 6 6 2 2 6 2 2 6 2 2 6
40155- 2 2 6 2 2 6 2 2 6 62 62 62
40156- 74 74 74 34 34 34 14 14 14 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 0 0 0
40165- 0 0 0 0 0 0 0 0 0 0 0 0
40166- 0 0 0 0 0 0 0 0 0 0 0 0
40167- 0 0 0 0 0 0 0 0 0 0 0 0
40168- 0 0 0 10 10 10 22 22 22 54 54 54
40169- 94 94 94 18 18 18 2 2 6 46 46 46
40170-234 234 234 221 221 221 190 190 190 190 190 190
40171-190 190 190 187 187 187 187 187 187 190 190 190
40172-190 190 190 195 195 195 214 214 214 242 242 242
40173-253 253 253 253 253 253 253 253 253 253 253 253
40174- 82 82 82 2 2 6 2 2 6 2 2 6
40175- 2 2 6 2 2 6 2 2 6 14 14 14
40176- 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0
40185- 0 0 0 0 0 0 0 0 0 0 0 0
40186- 0 0 0 0 0 0 0 0 0 0 0 0
40187- 0 0 0 0 0 0 0 0 0 0 0 0
40188- 6 6 6 18 18 18 46 46 46 90 90 90
40189- 46 46 46 18 18 18 6 6 6 182 182 182
40190-253 253 253 246 246 246 206 206 206 190 190 190
40191-190 190 190 190 190 190 190 190 190 190 190 190
40192-206 206 206 231 231 231 250 250 250 253 253 253
40193-253 253 253 253 253 253 253 253 253 253 253 253
40194-202 202 202 14 14 14 2 2 6 2 2 6
40195- 2 2 6 2 2 6 2 2 6 2 2 6
40196- 42 42 42 86 86 86 42 42 42 18 18 18
40197- 6 6 6 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 0 0 0
40205- 0 0 0 0 0 0 0 0 0 0 0 0
40206- 0 0 0 0 0 0 0 0 0 0 0 0
40207- 0 0 0 0 0 0 0 0 0 6 6 6
40208- 14 14 14 38 38 38 74 74 74 66 66 66
40209- 2 2 6 6 6 6 90 90 90 250 250 250
40210-253 253 253 253 253 253 238 238 238 198 198 198
40211-190 190 190 190 190 190 195 195 195 221 221 221
40212-246 246 246 253 253 253 253 253 253 253 253 253
40213-253 253 253 253 253 253 253 253 253 253 253 253
40214-253 253 253 82 82 82 2 2 6 2 2 6
40215- 2 2 6 2 2 6 2 2 6 2 2 6
40216- 2 2 6 78 78 78 70 70 70 34 34 34
40217- 14 14 14 6 6 6 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 0 0 0 0 0 0
40225- 0 0 0 0 0 0 0 0 0 0 0 0
40226- 0 0 0 0 0 0 0 0 0 0 0 0
40227- 0 0 0 0 0 0 0 0 0 14 14 14
40228- 34 34 34 66 66 66 78 78 78 6 6 6
40229- 2 2 6 18 18 18 218 218 218 253 253 253
40230-253 253 253 253 253 253 253 253 253 246 246 246
40231-226 226 226 231 231 231 246 246 246 253 253 253
40232-253 253 253 253 253 253 253 253 253 253 253 253
40233-253 253 253 253 253 253 253 253 253 253 253 253
40234-253 253 253 178 178 178 2 2 6 2 2 6
40235- 2 2 6 2 2 6 2 2 6 2 2 6
40236- 2 2 6 18 18 18 90 90 90 62 62 62
40237- 30 30 30 10 10 10 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 0 0 0 0 0 0
40245- 0 0 0 0 0 0 0 0 0 0 0 0
40246- 0 0 0 0 0 0 0 0 0 0 0 0
40247- 0 0 0 0 0 0 10 10 10 26 26 26
40248- 58 58 58 90 90 90 18 18 18 2 2 6
40249- 2 2 6 110 110 110 253 253 253 253 253 253
40250-253 253 253 253 253 253 253 253 253 253 253 253
40251-250 250 250 253 253 253 253 253 253 253 253 253
40252-253 253 253 253 253 253 253 253 253 253 253 253
40253-253 253 253 253 253 253 253 253 253 253 253 253
40254-253 253 253 231 231 231 18 18 18 2 2 6
40255- 2 2 6 2 2 6 2 2 6 2 2 6
40256- 2 2 6 2 2 6 18 18 18 94 94 94
40257- 54 54 54 26 26 26 10 10 10 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 0 0 0 0 0 0 0 0 0
40265- 0 0 0 0 0 0 0 0 0 0 0 0
40266- 0 0 0 0 0 0 0 0 0 0 0 0
40267- 0 0 0 6 6 6 22 22 22 50 50 50
40268- 90 90 90 26 26 26 2 2 6 2 2 6
40269- 14 14 14 195 195 195 250 250 250 253 253 253
40270-253 253 253 253 253 253 253 253 253 253 253 253
40271-253 253 253 253 253 253 253 253 253 253 253 253
40272-253 253 253 253 253 253 253 253 253 253 253 253
40273-253 253 253 253 253 253 253 253 253 253 253 253
40274-250 250 250 242 242 242 54 54 54 2 2 6
40275- 2 2 6 2 2 6 2 2 6 2 2 6
40276- 2 2 6 2 2 6 2 2 6 38 38 38
40277- 86 86 86 50 50 50 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
40285- 0 0 0 0 0 0 0 0 0 0 0 0
40286- 0 0 0 0 0 0 0 0 0 0 0 0
40287- 6 6 6 14 14 14 38 38 38 82 82 82
40288- 34 34 34 2 2 6 2 2 6 2 2 6
40289- 42 42 42 195 195 195 246 246 246 253 253 253
40290-253 253 253 253 253 253 253 253 253 250 250 250
40291-242 242 242 242 242 242 250 250 250 253 253 253
40292-253 253 253 253 253 253 253 253 253 253 253 253
40293-253 253 253 250 250 250 246 246 246 238 238 238
40294-226 226 226 231 231 231 101 101 101 6 6 6
40295- 2 2 6 2 2 6 2 2 6 2 2 6
40296- 2 2 6 2 2 6 2 2 6 2 2 6
40297- 38 38 38 82 82 82 42 42 42 14 14 14
40298- 6 6 6 0 0 0 0 0 0 0 0 0
40299- 0 0 0 0 0 0 0 0 0 0 0 0
40300- 0 0 0 0 0 0 0 0 0 0 0 0
40301- 0 0 0 0 0 0 0 0 0 0 0 0
40302- 0 0 0 0 0 0 0 0 0 0 0 0
40303- 0 0 0 0 0 0 0 0 0 0 0 0
40304- 0 0 0 0 0 0 0 0 0 0 0 0
40305- 0 0 0 0 0 0 0 0 0 0 0 0
40306- 0 0 0 0 0 0 0 0 0 0 0 0
40307- 10 10 10 26 26 26 62 62 62 66 66 66
40308- 2 2 6 2 2 6 2 2 6 6 6 6
40309- 70 70 70 170 170 170 206 206 206 234 234 234
40310-246 246 246 250 250 250 250 250 250 238 238 238
40311-226 226 226 231 231 231 238 238 238 250 250 250
40312-250 250 250 250 250 250 246 246 246 231 231 231
40313-214 214 214 206 206 206 202 202 202 202 202 202
40314-198 198 198 202 202 202 182 182 182 18 18 18
40315- 2 2 6 2 2 6 2 2 6 2 2 6
40316- 2 2 6 2 2 6 2 2 6 2 2 6
40317- 2 2 6 62 62 62 66 66 66 30 30 30
40318- 10 10 10 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 0 0 0
40324- 0 0 0 0 0 0 0 0 0 0 0 0
40325- 0 0 0 0 0 0 0 0 0 0 0 0
40326- 0 0 0 0 0 0 0 0 0 0 0 0
40327- 14 14 14 42 42 42 82 82 82 18 18 18
40328- 2 2 6 2 2 6 2 2 6 10 10 10
40329- 94 94 94 182 182 182 218 218 218 242 242 242
40330-250 250 250 253 253 253 253 253 253 250 250 250
40331-234 234 234 253 253 253 253 253 253 253 253 253
40332-253 253 253 253 253 253 253 253 253 246 246 246
40333-238 238 238 226 226 226 210 210 210 202 202 202
40334-195 195 195 195 195 195 210 210 210 158 158 158
40335- 6 6 6 14 14 14 50 50 50 14 14 14
40336- 2 2 6 2 2 6 2 2 6 2 2 6
40337- 2 2 6 6 6 6 86 86 86 46 46 46
40338- 18 18 18 6 6 6 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 0 0 0 0 0 0
40344- 0 0 0 0 0 0 0 0 0 0 0 0
40345- 0 0 0 0 0 0 0 0 0 0 0 0
40346- 0 0 0 0 0 0 0 0 0 6 6 6
40347- 22 22 22 54 54 54 70 70 70 2 2 6
40348- 2 2 6 10 10 10 2 2 6 22 22 22
40349-166 166 166 231 231 231 250 250 250 253 253 253
40350-253 253 253 253 253 253 253 253 253 250 250 250
40351-242 242 242 253 253 253 253 253 253 253 253 253
40352-253 253 253 253 253 253 253 253 253 253 253 253
40353-253 253 253 253 253 253 253 253 253 246 246 246
40354-231 231 231 206 206 206 198 198 198 226 226 226
40355- 94 94 94 2 2 6 6 6 6 38 38 38
40356- 30 30 30 2 2 6 2 2 6 2 2 6
40357- 2 2 6 2 2 6 62 62 62 66 66 66
40358- 26 26 26 10 10 10 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 0 0 0 0 0 0 0 0 0
40364- 0 0 0 0 0 0 0 0 0 0 0 0
40365- 0 0 0 0 0 0 0 0 0 0 0 0
40366- 0 0 0 0 0 0 0 0 0 10 10 10
40367- 30 30 30 74 74 74 50 50 50 2 2 6
40368- 26 26 26 26 26 26 2 2 6 106 106 106
40369-238 238 238 253 253 253 253 253 253 253 253 253
40370-253 253 253 253 253 253 253 253 253 253 253 253
40371-253 253 253 253 253 253 253 253 253 253 253 253
40372-253 253 253 253 253 253 253 253 253 253 253 253
40373-253 253 253 253 253 253 253 253 253 253 253 253
40374-253 253 253 246 246 246 218 218 218 202 202 202
40375-210 210 210 14 14 14 2 2 6 2 2 6
40376- 30 30 30 22 22 22 2 2 6 2 2 6
40377- 2 2 6 2 2 6 18 18 18 86 86 86
40378- 42 42 42 14 14 14 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- 0 0 0 0 0 0 0 0 0 0 0 0
40384- 0 0 0 0 0 0 0 0 0 0 0 0
40385- 0 0 0 0 0 0 0 0 0 0 0 0
40386- 0 0 0 0 0 0 0 0 0 14 14 14
40387- 42 42 42 90 90 90 22 22 22 2 2 6
40388- 42 42 42 2 2 6 18 18 18 218 218 218
40389-253 253 253 253 253 253 253 253 253 253 253 253
40390-253 253 253 253 253 253 253 253 253 253 253 253
40391-253 253 253 253 253 253 253 253 253 253 253 253
40392-253 253 253 253 253 253 253 253 253 253 253 253
40393-253 253 253 253 253 253 253 253 253 253 253 253
40394-253 253 253 253 253 253 250 250 250 221 221 221
40395-218 218 218 101 101 101 2 2 6 14 14 14
40396- 18 18 18 38 38 38 10 10 10 2 2 6
40397- 2 2 6 2 2 6 2 2 6 78 78 78
40398- 58 58 58 22 22 22 6 6 6 0 0 0
40399- 0 0 0 0 0 0 0 0 0 0 0 0
40400- 0 0 0 0 0 0 0 0 0 0 0 0
40401- 0 0 0 0 0 0 0 0 0 0 0 0
40402- 0 0 0 0 0 0 0 0 0 0 0 0
40403- 0 0 0 0 0 0 0 0 0 0 0 0
40404- 0 0 0 0 0 0 0 0 0 0 0 0
40405- 0 0 0 0 0 0 0 0 0 0 0 0
40406- 0 0 0 0 0 0 6 6 6 18 18 18
40407- 54 54 54 82 82 82 2 2 6 26 26 26
40408- 22 22 22 2 2 6 123 123 123 253 253 253
40409-253 253 253 253 253 253 253 253 253 253 253 253
40410-253 253 253 253 253 253 253 253 253 253 253 253
40411-253 253 253 253 253 253 253 253 253 253 253 253
40412-253 253 253 253 253 253 253 253 253 253 253 253
40413-253 253 253 253 253 253 253 253 253 253 253 253
40414-253 253 253 253 253 253 253 253 253 250 250 250
40415-238 238 238 198 198 198 6 6 6 38 38 38
40416- 58 58 58 26 26 26 38 38 38 2 2 6
40417- 2 2 6 2 2 6 2 2 6 46 46 46
40418- 78 78 78 30 30 30 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
40424- 0 0 0 0 0 0 0 0 0 0 0 0
40425- 0 0 0 0 0 0 0 0 0 0 0 0
40426- 0 0 0 0 0 0 10 10 10 30 30 30
40427- 74 74 74 58 58 58 2 2 6 42 42 42
40428- 2 2 6 22 22 22 231 231 231 253 253 253
40429-253 253 253 253 253 253 253 253 253 253 253 253
40430-253 253 253 253 253 253 253 253 253 250 250 250
40431-253 253 253 253 253 253 253 253 253 253 253 253
40432-253 253 253 253 253 253 253 253 253 253 253 253
40433-253 253 253 253 253 253 253 253 253 253 253 253
40434-253 253 253 253 253 253 253 253 253 253 253 253
40435-253 253 253 246 246 246 46 46 46 38 38 38
40436- 42 42 42 14 14 14 38 38 38 14 14 14
40437- 2 2 6 2 2 6 2 2 6 6 6 6
40438- 86 86 86 46 46 46 14 14 14 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 0 0 0
40443- 0 0 0 0 0 0 0 0 0 0 0 0
40444- 0 0 0 0 0 0 0 0 0 0 0 0
40445- 0 0 0 0 0 0 0 0 0 0 0 0
40446- 0 0 0 6 6 6 14 14 14 42 42 42
40447- 90 90 90 18 18 18 18 18 18 26 26 26
40448- 2 2 6 116 116 116 253 253 253 253 253 253
40449-253 253 253 253 253 253 253 253 253 253 253 253
40450-253 253 253 253 253 253 250 250 250 238 238 238
40451-253 253 253 253 253 253 253 253 253 253 253 253
40452-253 253 253 253 253 253 253 253 253 253 253 253
40453-253 253 253 253 253 253 253 253 253 253 253 253
40454-253 253 253 253 253 253 253 253 253 253 253 253
40455-253 253 253 253 253 253 94 94 94 6 6 6
40456- 2 2 6 2 2 6 10 10 10 34 34 34
40457- 2 2 6 2 2 6 2 2 6 2 2 6
40458- 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0
40463- 0 0 0 0 0 0 0 0 0 0 0 0
40464- 0 0 0 0 0 0 0 0 0 0 0 0
40465- 0 0 0 0 0 0 0 0 0 0 0 0
40466- 0 0 0 10 10 10 26 26 26 66 66 66
40467- 82 82 82 2 2 6 38 38 38 6 6 6
40468- 14 14 14 210 210 210 253 253 253 253 253 253
40469-253 253 253 253 253 253 253 253 253 253 253 253
40470-253 253 253 253 253 253 246 246 246 242 242 242
40471-253 253 253 253 253 253 253 253 253 253 253 253
40472-253 253 253 253 253 253 253 253 253 253 253 253
40473-253 253 253 253 253 253 253 253 253 253 253 253
40474-253 253 253 253 253 253 253 253 253 253 253 253
40475-253 253 253 253 253 253 144 144 144 2 2 6
40476- 2 2 6 2 2 6 2 2 6 46 46 46
40477- 2 2 6 2 2 6 2 2 6 2 2 6
40478- 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0
40483- 0 0 0 0 0 0 0 0 0 0 0 0
40484- 0 0 0 0 0 0 0 0 0 0 0 0
40485- 0 0 0 0 0 0 0 0 0 0 0 0
40486- 6 6 6 14 14 14 42 42 42 90 90 90
40487- 26 26 26 6 6 6 42 42 42 2 2 6
40488- 74 74 74 250 250 250 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 242 242 242 242 242 242
40491-253 253 253 253 253 253 253 253 253 253 253 253
40492-253 253 253 253 253 253 253 253 253 253 253 253
40493-253 253 253 253 253 253 253 253 253 253 253 253
40494-253 253 253 253 253 253 253 253 253 253 253 253
40495-253 253 253 253 253 253 182 182 182 2 2 6
40496- 2 2 6 2 2 6 2 2 6 46 46 46
40497- 2 2 6 2 2 6 2 2 6 2 2 6
40498- 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0 0 0 0
40503- 0 0 0 0 0 0 0 0 0 0 0 0
40504- 0 0 0 0 0 0 0 0 0 0 0 0
40505- 0 0 0 0 0 0 0 0 0 0 0 0
40506- 10 10 10 26 26 26 66 66 66 82 82 82
40507- 2 2 6 22 22 22 18 18 18 2 2 6
40508-149 149 149 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 234 234 234 242 242 242
40511-253 253 253 253 253 253 253 253 253 253 253 253
40512-253 253 253 253 253 253 253 253 253 253 253 253
40513-253 253 253 253 253 253 253 253 253 253 253 253
40514-253 253 253 253 253 253 253 253 253 253 253 253
40515-253 253 253 253 253 253 206 206 206 2 2 6
40516- 2 2 6 2 2 6 2 2 6 38 38 38
40517- 2 2 6 2 2 6 2 2 6 2 2 6
40518- 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0 0 0 0
40523- 0 0 0 0 0 0 0 0 0 0 0 0
40524- 0 0 0 0 0 0 0 0 0 0 0 0
40525- 0 0 0 0 0 0 0 0 0 6 6 6
40526- 18 18 18 46 46 46 86 86 86 18 18 18
40527- 2 2 6 34 34 34 10 10 10 6 6 6
40528-210 210 210 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 234 234 234 242 242 242
40531-253 253 253 253 253 253 253 253 253 253 253 253
40532-253 253 253 253 253 253 253 253 253 253 253 253
40533-253 253 253 253 253 253 253 253 253 253 253 253
40534-253 253 253 253 253 253 253 253 253 253 253 253
40535-253 253 253 253 253 253 221 221 221 6 6 6
40536- 2 2 6 2 2 6 6 6 6 30 30 30
40537- 2 2 6 2 2 6 2 2 6 2 2 6
40538- 2 2 6 82 82 82 54 54 54 18 18 18
40539- 6 6 6 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 0 0 0 0 0 0 0 0 0
40543- 0 0 0 0 0 0 0 0 0 0 0 0
40544- 0 0 0 0 0 0 0 0 0 0 0 0
40545- 0 0 0 0 0 0 0 0 0 10 10 10
40546- 26 26 26 66 66 66 62 62 62 2 2 6
40547- 2 2 6 38 38 38 10 10 10 26 26 26
40548-238 238 238 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 231 231 231 238 238 238
40551-253 253 253 253 253 253 253 253 253 253 253 253
40552-253 253 253 253 253 253 253 253 253 253 253 253
40553-253 253 253 253 253 253 253 253 253 253 253 253
40554-253 253 253 253 253 253 253 253 253 253 253 253
40555-253 253 253 253 253 253 231 231 231 6 6 6
40556- 2 2 6 2 2 6 10 10 10 30 30 30
40557- 2 2 6 2 2 6 2 2 6 2 2 6
40558- 2 2 6 66 66 66 58 58 58 22 22 22
40559- 6 6 6 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 0 0 0 0 0 0 0 0 0
40563- 0 0 0 0 0 0 0 0 0 0 0 0
40564- 0 0 0 0 0 0 0 0 0 0 0 0
40565- 0 0 0 0 0 0 0 0 0 10 10 10
40566- 38 38 38 78 78 78 6 6 6 2 2 6
40567- 2 2 6 46 46 46 14 14 14 42 42 42
40568-246 246 246 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 231 231 231 242 242 242
40571-253 253 253 253 253 253 253 253 253 253 253 253
40572-253 253 253 253 253 253 253 253 253 253 253 253
40573-253 253 253 253 253 253 253 253 253 253 253 253
40574-253 253 253 253 253 253 253 253 253 253 253 253
40575-253 253 253 253 253 253 234 234 234 10 10 10
40576- 2 2 6 2 2 6 22 22 22 14 14 14
40577- 2 2 6 2 2 6 2 2 6 2 2 6
40578- 2 2 6 66 66 66 62 62 62 22 22 22
40579- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
40583- 0 0 0 0 0 0 0 0 0 0 0 0
40584- 0 0 0 0 0 0 0 0 0 0 0 0
40585- 0 0 0 0 0 0 6 6 6 18 18 18
40586- 50 50 50 74 74 74 2 2 6 2 2 6
40587- 14 14 14 70 70 70 34 34 34 62 62 62
40588-250 250 250 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 231 231 231 246 246 246
40591-253 253 253 253 253 253 253 253 253 253 253 253
40592-253 253 253 253 253 253 253 253 253 253 253 253
40593-253 253 253 253 253 253 253 253 253 253 253 253
40594-253 253 253 253 253 253 253 253 253 253 253 253
40595-253 253 253 253 253 253 234 234 234 14 14 14
40596- 2 2 6 2 2 6 30 30 30 2 2 6
40597- 2 2 6 2 2 6 2 2 6 2 2 6
40598- 2 2 6 66 66 66 62 62 62 22 22 22
40599- 6 6 6 0 0 0 0 0 0 0 0 0
40600- 0 0 0 0 0 0 0 0 0 0 0 0
40601- 0 0 0 0 0 0 0 0 0 0 0 0
40602- 0 0 0 0 0 0 0 0 0 0 0 0
40603- 0 0 0 0 0 0 0 0 0 0 0 0
40604- 0 0 0 0 0 0 0 0 0 0 0 0
40605- 0 0 0 0 0 0 6 6 6 18 18 18
40606- 54 54 54 62 62 62 2 2 6 2 2 6
40607- 2 2 6 30 30 30 46 46 46 70 70 70
40608-250 250 250 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 231 231 231 246 246 246
40611-253 253 253 253 253 253 253 253 253 253 253 253
40612-253 253 253 253 253 253 253 253 253 253 253 253
40613-253 253 253 253 253 253 253 253 253 253 253 253
40614-253 253 253 253 253 253 253 253 253 253 253 253
40615-253 253 253 253 253 253 226 226 226 10 10 10
40616- 2 2 6 6 6 6 30 30 30 2 2 6
40617- 2 2 6 2 2 6 2 2 6 2 2 6
40618- 2 2 6 66 66 66 58 58 58 22 22 22
40619- 6 6 6 0 0 0 0 0 0 0 0 0
40620- 0 0 0 0 0 0 0 0 0 0 0 0
40621- 0 0 0 0 0 0 0 0 0 0 0 0
40622- 0 0 0 0 0 0 0 0 0 0 0 0
40623- 0 0 0 0 0 0 0 0 0 0 0 0
40624- 0 0 0 0 0 0 0 0 0 0 0 0
40625- 0 0 0 0 0 0 6 6 6 22 22 22
40626- 58 58 58 62 62 62 2 2 6 2 2 6
40627- 2 2 6 2 2 6 30 30 30 78 78 78
40628-250 250 250 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 231 231 231 246 246 246
40631-253 253 253 253 253 253 253 253 253 253 253 253
40632-253 253 253 253 253 253 253 253 253 253 253 253
40633-253 253 253 253 253 253 253 253 253 253 253 253
40634-253 253 253 253 253 253 253 253 253 253 253 253
40635-253 253 253 253 253 253 206 206 206 2 2 6
40636- 22 22 22 34 34 34 18 14 6 22 22 22
40637- 26 26 26 18 18 18 6 6 6 2 2 6
40638- 2 2 6 82 82 82 54 54 54 18 18 18
40639- 6 6 6 0 0 0 0 0 0 0 0 0
40640- 0 0 0 0 0 0 0 0 0 0 0 0
40641- 0 0 0 0 0 0 0 0 0 0 0 0
40642- 0 0 0 0 0 0 0 0 0 0 0 0
40643- 0 0 0 0 0 0 0 0 0 0 0 0
40644- 0 0 0 0 0 0 0 0 0 0 0 0
40645- 0 0 0 0 0 0 6 6 6 26 26 26
40646- 62 62 62 106 106 106 74 54 14 185 133 11
40647-210 162 10 121 92 8 6 6 6 62 62 62
40648-238 238 238 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 231 231 231 246 246 246
40651-253 253 253 253 253 253 253 253 253 253 253 253
40652-253 253 253 253 253 253 253 253 253 253 253 253
40653-253 253 253 253 253 253 253 253 253 253 253 253
40654-253 253 253 253 253 253 253 253 253 253 253 253
40655-253 253 253 253 253 253 158 158 158 18 18 18
40656- 14 14 14 2 2 6 2 2 6 2 2 6
40657- 6 6 6 18 18 18 66 66 66 38 38 38
40658- 6 6 6 94 94 94 50 50 50 18 18 18
40659- 6 6 6 0 0 0 0 0 0 0 0 0
40660- 0 0 0 0 0 0 0 0 0 0 0 0
40661- 0 0 0 0 0 0 0 0 0 0 0 0
40662- 0 0 0 0 0 0 0 0 0 0 0 0
40663- 0 0 0 0 0 0 0 0 0 0 0 0
40664- 0 0 0 0 0 0 0 0 0 6 6 6
40665- 10 10 10 10 10 10 18 18 18 38 38 38
40666- 78 78 78 142 134 106 216 158 10 242 186 14
40667-246 190 14 246 190 14 156 118 10 10 10 10
40668- 90 90 90 238 238 238 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 231 231 231 250 250 250
40671-253 253 253 253 253 253 253 253 253 253 253 253
40672-253 253 253 253 253 253 253 253 253 253 253 253
40673-253 253 253 253 253 253 253 253 253 253 253 253
40674-253 253 253 253 253 253 253 253 253 246 230 190
40675-238 204 91 238 204 91 181 142 44 37 26 9
40676- 2 2 6 2 2 6 2 2 6 2 2 6
40677- 2 2 6 2 2 6 38 38 38 46 46 46
40678- 26 26 26 106 106 106 54 54 54 18 18 18
40679- 6 6 6 0 0 0 0 0 0 0 0 0
40680- 0 0 0 0 0 0 0 0 0 0 0 0
40681- 0 0 0 0 0 0 0 0 0 0 0 0
40682- 0 0 0 0 0 0 0 0 0 0 0 0
40683- 0 0 0 0 0 0 0 0 0 0 0 0
40684- 0 0 0 6 6 6 14 14 14 22 22 22
40685- 30 30 30 38 38 38 50 50 50 70 70 70
40686-106 106 106 190 142 34 226 170 11 242 186 14
40687-246 190 14 246 190 14 246 190 14 154 114 10
40688- 6 6 6 74 74 74 226 226 226 253 253 253
40689-253 253 253 253 253 253 253 253 253 253 253 253
40690-253 253 253 253 253 253 231 231 231 250 250 250
40691-253 253 253 253 253 253 253 253 253 253 253 253
40692-253 253 253 253 253 253 253 253 253 253 253 253
40693-253 253 253 253 253 253 253 253 253 253 253 253
40694-253 253 253 253 253 253 253 253 253 228 184 62
40695-241 196 14 241 208 19 232 195 16 38 30 10
40696- 2 2 6 2 2 6 2 2 6 2 2 6
40697- 2 2 6 6 6 6 30 30 30 26 26 26
40698-203 166 17 154 142 90 66 66 66 26 26 26
40699- 6 6 6 0 0 0 0 0 0 0 0 0
40700- 0 0 0 0 0 0 0 0 0 0 0 0
40701- 0 0 0 0 0 0 0 0 0 0 0 0
40702- 0 0 0 0 0 0 0 0 0 0 0 0
40703- 0 0 0 0 0 0 0 0 0 0 0 0
40704- 6 6 6 18 18 18 38 38 38 58 58 58
40705- 78 78 78 86 86 86 101 101 101 123 123 123
40706-175 146 61 210 150 10 234 174 13 246 186 14
40707-246 190 14 246 190 14 246 190 14 238 190 10
40708-102 78 10 2 2 6 46 46 46 198 198 198
40709-253 253 253 253 253 253 253 253 253 253 253 253
40710-253 253 253 253 253 253 234 234 234 242 242 242
40711-253 253 253 253 253 253 253 253 253 253 253 253
40712-253 253 253 253 253 253 253 253 253 253 253 253
40713-253 253 253 253 253 253 253 253 253 253 253 253
40714-253 253 253 253 253 253 253 253 253 224 178 62
40715-242 186 14 241 196 14 210 166 10 22 18 6
40716- 2 2 6 2 2 6 2 2 6 2 2 6
40717- 2 2 6 2 2 6 6 6 6 121 92 8
40718-238 202 15 232 195 16 82 82 82 34 34 34
40719- 10 10 10 0 0 0 0 0 0 0 0 0
40720- 0 0 0 0 0 0 0 0 0 0 0 0
40721- 0 0 0 0 0 0 0 0 0 0 0 0
40722- 0 0 0 0 0 0 0 0 0 0 0 0
40723- 0 0 0 0 0 0 0 0 0 0 0 0
40724- 14 14 14 38 38 38 70 70 70 154 122 46
40725-190 142 34 200 144 11 197 138 11 197 138 11
40726-213 154 11 226 170 11 242 186 14 246 190 14
40727-246 190 14 246 190 14 246 190 14 246 190 14
40728-225 175 15 46 32 6 2 2 6 22 22 22
40729-158 158 158 250 250 250 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 253 253 253 253 253 253
40732-253 253 253 253 253 253 253 253 253 253 253 253
40733-253 253 253 253 253 253 253 253 253 253 253 253
40734-253 253 253 250 250 250 242 242 242 224 178 62
40735-239 182 13 236 186 11 213 154 11 46 32 6
40736- 2 2 6 2 2 6 2 2 6 2 2 6
40737- 2 2 6 2 2 6 61 42 6 225 175 15
40738-238 190 10 236 186 11 112 100 78 42 42 42
40739- 14 14 14 0 0 0 0 0 0 0 0 0
40740- 0 0 0 0 0 0 0 0 0 0 0 0
40741- 0 0 0 0 0 0 0 0 0 0 0 0
40742- 0 0 0 0 0 0 0 0 0 0 0 0
40743- 0 0 0 0 0 0 0 0 0 6 6 6
40744- 22 22 22 54 54 54 154 122 46 213 154 11
40745-226 170 11 230 174 11 226 170 11 226 170 11
40746-236 178 12 242 186 14 246 190 14 246 190 14
40747-246 190 14 246 190 14 246 190 14 246 190 14
40748-241 196 14 184 144 12 10 10 10 2 2 6
40749- 6 6 6 116 116 116 242 242 242 253 253 253
40750-253 253 253 253 253 253 253 253 253 253 253 253
40751-253 253 253 253 253 253 253 253 253 253 253 253
40752-253 253 253 253 253 253 253 253 253 253 253 253
40753-253 253 253 253 253 253 253 253 253 253 253 253
40754-253 253 253 231 231 231 198 198 198 214 170 54
40755-236 178 12 236 178 12 210 150 10 137 92 6
40756- 18 14 6 2 2 6 2 2 6 2 2 6
40757- 6 6 6 70 47 6 200 144 11 236 178 12
40758-239 182 13 239 182 13 124 112 88 58 58 58
40759- 22 22 22 6 6 6 0 0 0 0 0 0
40760- 0 0 0 0 0 0 0 0 0 0 0 0
40761- 0 0 0 0 0 0 0 0 0 0 0 0
40762- 0 0 0 0 0 0 0 0 0 0 0 0
40763- 0 0 0 0 0 0 0 0 0 10 10 10
40764- 30 30 30 70 70 70 180 133 36 226 170 11
40765-239 182 13 242 186 14 242 186 14 246 186 14
40766-246 190 14 246 190 14 246 190 14 246 190 14
40767-246 190 14 246 190 14 246 190 14 246 190 14
40768-246 190 14 232 195 16 98 70 6 2 2 6
40769- 2 2 6 2 2 6 66 66 66 221 221 221
40770-253 253 253 253 253 253 253 253 253 253 253 253
40771-253 253 253 253 253 253 253 253 253 253 253 253
40772-253 253 253 253 253 253 253 253 253 253 253 253
40773-253 253 253 253 253 253 253 253 253 253 253 253
40774-253 253 253 206 206 206 198 198 198 214 166 58
40775-230 174 11 230 174 11 216 158 10 192 133 9
40776-163 110 8 116 81 8 102 78 10 116 81 8
40777-167 114 7 197 138 11 226 170 11 239 182 13
40778-242 186 14 242 186 14 162 146 94 78 78 78
40779- 34 34 34 14 14 14 6 6 6 0 0 0
40780- 0 0 0 0 0 0 0 0 0 0 0 0
40781- 0 0 0 0 0 0 0 0 0 0 0 0
40782- 0 0 0 0 0 0 0 0 0 0 0 0
40783- 0 0 0 0 0 0 0 0 0 6 6 6
40784- 30 30 30 78 78 78 190 142 34 226 170 11
40785-239 182 13 246 190 14 246 190 14 246 190 14
40786-246 190 14 246 190 14 246 190 14 246 190 14
40787-246 190 14 246 190 14 246 190 14 246 190 14
40788-246 190 14 241 196 14 203 166 17 22 18 6
40789- 2 2 6 2 2 6 2 2 6 38 38 38
40790-218 218 218 253 253 253 253 253 253 253 253 253
40791-253 253 253 253 253 253 253 253 253 253 253 253
40792-253 253 253 253 253 253 253 253 253 253 253 253
40793-253 253 253 253 253 253 253 253 253 253 253 253
40794-250 250 250 206 206 206 198 198 198 202 162 69
40795-226 170 11 236 178 12 224 166 10 210 150 10
40796-200 144 11 197 138 11 192 133 9 197 138 11
40797-210 150 10 226 170 11 242 186 14 246 190 14
40798-246 190 14 246 186 14 225 175 15 124 112 88
40799- 62 62 62 30 30 30 14 14 14 6 6 6
40800- 0 0 0 0 0 0 0 0 0 0 0 0
40801- 0 0 0 0 0 0 0 0 0 0 0 0
40802- 0 0 0 0 0 0 0 0 0 0 0 0
40803- 0 0 0 0 0 0 0 0 0 10 10 10
40804- 30 30 30 78 78 78 174 135 50 224 166 10
40805-239 182 13 246 190 14 246 190 14 246 190 14
40806-246 190 14 246 190 14 246 190 14 246 190 14
40807-246 190 14 246 190 14 246 190 14 246 190 14
40808-246 190 14 246 190 14 241 196 14 139 102 15
40809- 2 2 6 2 2 6 2 2 6 2 2 6
40810- 78 78 78 250 250 250 253 253 253 253 253 253
40811-253 253 253 253 253 253 253 253 253 253 253 253
40812-253 253 253 253 253 253 253 253 253 253 253 253
40813-253 253 253 253 253 253 253 253 253 253 253 253
40814-250 250 250 214 214 214 198 198 198 190 150 46
40815-219 162 10 236 178 12 234 174 13 224 166 10
40816-216 158 10 213 154 11 213 154 11 216 158 10
40817-226 170 11 239 182 13 246 190 14 246 190 14
40818-246 190 14 246 190 14 242 186 14 206 162 42
40819-101 101 101 58 58 58 30 30 30 14 14 14
40820- 6 6 6 0 0 0 0 0 0 0 0 0
40821- 0 0 0 0 0 0 0 0 0 0 0 0
40822- 0 0 0 0 0 0 0 0 0 0 0 0
40823- 0 0 0 0 0 0 0 0 0 10 10 10
40824- 30 30 30 74 74 74 174 135 50 216 158 10
40825-236 178 12 246 190 14 246 190 14 246 190 14
40826-246 190 14 246 190 14 246 190 14 246 190 14
40827-246 190 14 246 190 14 246 190 14 246 190 14
40828-246 190 14 246 190 14 241 196 14 226 184 13
40829- 61 42 6 2 2 6 2 2 6 2 2 6
40830- 22 22 22 238 238 238 253 253 253 253 253 253
40831-253 253 253 253 253 253 253 253 253 253 253 253
40832-253 253 253 253 253 253 253 253 253 253 253 253
40833-253 253 253 253 253 253 253 253 253 253 253 253
40834-253 253 253 226 226 226 187 187 187 180 133 36
40835-216 158 10 236 178 12 239 182 13 236 178 12
40836-230 174 11 226 170 11 226 170 11 230 174 11
40837-236 178 12 242 186 14 246 190 14 246 190 14
40838-246 190 14 246 190 14 246 186 14 239 182 13
40839-206 162 42 106 106 106 66 66 66 34 34 34
40840- 14 14 14 6 6 6 0 0 0 0 0 0
40841- 0 0 0 0 0 0 0 0 0 0 0 0
40842- 0 0 0 0 0 0 0 0 0 0 0 0
40843- 0 0 0 0 0 0 0 0 0 6 6 6
40844- 26 26 26 70 70 70 163 133 67 213 154 11
40845-236 178 12 246 190 14 246 190 14 246 190 14
40846-246 190 14 246 190 14 246 190 14 246 190 14
40847-246 190 14 246 190 14 246 190 14 246 190 14
40848-246 190 14 246 190 14 246 190 14 241 196 14
40849-190 146 13 18 14 6 2 2 6 2 2 6
40850- 46 46 46 246 246 246 253 253 253 253 253 253
40851-253 253 253 253 253 253 253 253 253 253 253 253
40852-253 253 253 253 253 253 253 253 253 253 253 253
40853-253 253 253 253 253 253 253 253 253 253 253 253
40854-253 253 253 221 221 221 86 86 86 156 107 11
40855-216 158 10 236 178 12 242 186 14 246 186 14
40856-242 186 14 239 182 13 239 182 13 242 186 14
40857-242 186 14 246 186 14 246 190 14 246 190 14
40858-246 190 14 246 190 14 246 190 14 246 190 14
40859-242 186 14 225 175 15 142 122 72 66 66 66
40860- 30 30 30 10 10 10 0 0 0 0 0 0
40861- 0 0 0 0 0 0 0 0 0 0 0 0
40862- 0 0 0 0 0 0 0 0 0 0 0 0
40863- 0 0 0 0 0 0 0 0 0 6 6 6
40864- 26 26 26 70 70 70 163 133 67 210 150 10
40865-236 178 12 246 190 14 246 190 14 246 190 14
40866-246 190 14 246 190 14 246 190 14 246 190 14
40867-246 190 14 246 190 14 246 190 14 246 190 14
40868-246 190 14 246 190 14 246 190 14 246 190 14
40869-232 195 16 121 92 8 34 34 34 106 106 106
40870-221 221 221 253 253 253 253 253 253 253 253 253
40871-253 253 253 253 253 253 253 253 253 253 253 253
40872-253 253 253 253 253 253 253 253 253 253 253 253
40873-253 253 253 253 253 253 253 253 253 253 253 253
40874-242 242 242 82 82 82 18 14 6 163 110 8
40875-216 158 10 236 178 12 242 186 14 246 190 14
40876-246 190 14 246 190 14 246 190 14 246 190 14
40877-246 190 14 246 190 14 246 190 14 246 190 14
40878-246 190 14 246 190 14 246 190 14 246 190 14
40879-246 190 14 246 190 14 242 186 14 163 133 67
40880- 46 46 46 18 18 18 6 6 6 0 0 0
40881- 0 0 0 0 0 0 0 0 0 0 0 0
40882- 0 0 0 0 0 0 0 0 0 0 0 0
40883- 0 0 0 0 0 0 0 0 0 10 10 10
40884- 30 30 30 78 78 78 163 133 67 210 150 10
40885-236 178 12 246 186 14 246 190 14 246 190 14
40886-246 190 14 246 190 14 246 190 14 246 190 14
40887-246 190 14 246 190 14 246 190 14 246 190 14
40888-246 190 14 246 190 14 246 190 14 246 190 14
40889-241 196 14 215 174 15 190 178 144 253 253 253
40890-253 253 253 253 253 253 253 253 253 253 253 253
40891-253 253 253 253 253 253 253 253 253 253 253 253
40892-253 253 253 253 253 253 253 253 253 253 253 253
40893-253 253 253 253 253 253 253 253 253 218 218 218
40894- 58 58 58 2 2 6 22 18 6 167 114 7
40895-216 158 10 236 178 12 246 186 14 246 190 14
40896-246 190 14 246 190 14 246 190 14 246 190 14
40897-246 190 14 246 190 14 246 190 14 246 190 14
40898-246 190 14 246 190 14 246 190 14 246 190 14
40899-246 190 14 246 186 14 242 186 14 190 150 46
40900- 54 54 54 22 22 22 6 6 6 0 0 0
40901- 0 0 0 0 0 0 0 0 0 0 0 0
40902- 0 0 0 0 0 0 0 0 0 0 0 0
40903- 0 0 0 0 0 0 0 0 0 14 14 14
40904- 38 38 38 86 86 86 180 133 36 213 154 11
40905-236 178 12 246 186 14 246 190 14 246 190 14
40906-246 190 14 246 190 14 246 190 14 246 190 14
40907-246 190 14 246 190 14 246 190 14 246 190 14
40908-246 190 14 246 190 14 246 190 14 246 190 14
40909-246 190 14 232 195 16 190 146 13 214 214 214
40910-253 253 253 253 253 253 253 253 253 253 253 253
40911-253 253 253 253 253 253 253 253 253 253 253 253
40912-253 253 253 253 253 253 253 253 253 253 253 253
40913-253 253 253 250 250 250 170 170 170 26 26 26
40914- 2 2 6 2 2 6 37 26 9 163 110 8
40915-219 162 10 239 182 13 246 186 14 246 190 14
40916-246 190 14 246 190 14 246 190 14 246 190 14
40917-246 190 14 246 190 14 246 190 14 246 190 14
40918-246 190 14 246 190 14 246 190 14 246 190 14
40919-246 186 14 236 178 12 224 166 10 142 122 72
40920- 46 46 46 18 18 18 6 6 6 0 0 0
40921- 0 0 0 0 0 0 0 0 0 0 0 0
40922- 0 0 0 0 0 0 0 0 0 0 0 0
40923- 0 0 0 0 0 0 6 6 6 18 18 18
40924- 50 50 50 109 106 95 192 133 9 224 166 10
40925-242 186 14 246 190 14 246 190 14 246 190 14
40926-246 190 14 246 190 14 246 190 14 246 190 14
40927-246 190 14 246 190 14 246 190 14 246 190 14
40928-246 190 14 246 190 14 246 190 14 246 190 14
40929-242 186 14 226 184 13 210 162 10 142 110 46
40930-226 226 226 253 253 253 253 253 253 253 253 253
40931-253 253 253 253 253 253 253 253 253 253 253 253
40932-253 253 253 253 253 253 253 253 253 253 253 253
40933-198 198 198 66 66 66 2 2 6 2 2 6
40934- 2 2 6 2 2 6 50 34 6 156 107 11
40935-219 162 10 239 182 13 246 186 14 246 190 14
40936-246 190 14 246 190 14 246 190 14 246 190 14
40937-246 190 14 246 190 14 246 190 14 246 190 14
40938-246 190 14 246 190 14 246 190 14 242 186 14
40939-234 174 13 213 154 11 154 122 46 66 66 66
40940- 30 30 30 10 10 10 0 0 0 0 0 0
40941- 0 0 0 0 0 0 0 0 0 0 0 0
40942- 0 0 0 0 0 0 0 0 0 0 0 0
40943- 0 0 0 0 0 0 6 6 6 22 22 22
40944- 58 58 58 154 121 60 206 145 10 234 174 13
40945-242 186 14 246 186 14 246 190 14 246 190 14
40946-246 190 14 246 190 14 246 190 14 246 190 14
40947-246 190 14 246 190 14 246 190 14 246 190 14
40948-246 190 14 246 190 14 246 190 14 246 190 14
40949-246 186 14 236 178 12 210 162 10 163 110 8
40950- 61 42 6 138 138 138 218 218 218 250 250 250
40951-253 253 253 253 253 253 253 253 253 250 250 250
40952-242 242 242 210 210 210 144 144 144 66 66 66
40953- 6 6 6 2 2 6 2 2 6 2 2 6
40954- 2 2 6 2 2 6 61 42 6 163 110 8
40955-216 158 10 236 178 12 246 190 14 246 190 14
40956-246 190 14 246 190 14 246 190 14 246 190 14
40957-246 190 14 246 190 14 246 190 14 246 190 14
40958-246 190 14 239 182 13 230 174 11 216 158 10
40959-190 142 34 124 112 88 70 70 70 38 38 38
40960- 18 18 18 6 6 6 0 0 0 0 0 0
40961- 0 0 0 0 0 0 0 0 0 0 0 0
40962- 0 0 0 0 0 0 0 0 0 0 0 0
40963- 0 0 0 0 0 0 6 6 6 22 22 22
40964- 62 62 62 168 124 44 206 145 10 224 166 10
40965-236 178 12 239 182 13 242 186 14 242 186 14
40966-246 186 14 246 190 14 246 190 14 246 190 14
40967-246 190 14 246 190 14 246 190 14 246 190 14
40968-246 190 14 246 190 14 246 190 14 246 190 14
40969-246 190 14 236 178 12 216 158 10 175 118 6
40970- 80 54 7 2 2 6 6 6 6 30 30 30
40971- 54 54 54 62 62 62 50 50 50 38 38 38
40972- 14 14 14 2 2 6 2 2 6 2 2 6
40973- 2 2 6 2 2 6 2 2 6 2 2 6
40974- 2 2 6 6 6 6 80 54 7 167 114 7
40975-213 154 11 236 178 12 246 190 14 246 190 14
40976-246 190 14 246 190 14 246 190 14 246 190 14
40977-246 190 14 242 186 14 239 182 13 239 182 13
40978-230 174 11 210 150 10 174 135 50 124 112 88
40979- 82 82 82 54 54 54 34 34 34 18 18 18
40980- 6 6 6 0 0 0 0 0 0 0 0 0
40981- 0 0 0 0 0 0 0 0 0 0 0 0
40982- 0 0 0 0 0 0 0 0 0 0 0 0
40983- 0 0 0 0 0 0 6 6 6 18 18 18
40984- 50 50 50 158 118 36 192 133 9 200 144 11
40985-216 158 10 219 162 10 224 166 10 226 170 11
40986-230 174 11 236 178 12 239 182 13 239 182 13
40987-242 186 14 246 186 14 246 190 14 246 190 14
40988-246 190 14 246 190 14 246 190 14 246 190 14
40989-246 186 14 230 174 11 210 150 10 163 110 8
40990-104 69 6 10 10 10 2 2 6 2 2 6
40991- 2 2 6 2 2 6 2 2 6 2 2 6
40992- 2 2 6 2 2 6 2 2 6 2 2 6
40993- 2 2 6 2 2 6 2 2 6 2 2 6
40994- 2 2 6 6 6 6 91 60 6 167 114 7
40995-206 145 10 230 174 11 242 186 14 246 190 14
40996-246 190 14 246 190 14 246 186 14 242 186 14
40997-239 182 13 230 174 11 224 166 10 213 154 11
40998-180 133 36 124 112 88 86 86 86 58 58 58
40999- 38 38 38 22 22 22 10 10 10 6 6 6
41000- 0 0 0 0 0 0 0 0 0 0 0 0
41001- 0 0 0 0 0 0 0 0 0 0 0 0
41002- 0 0 0 0 0 0 0 0 0 0 0 0
41003- 0 0 0 0 0 0 0 0 0 14 14 14
41004- 34 34 34 70 70 70 138 110 50 158 118 36
41005-167 114 7 180 123 7 192 133 9 197 138 11
41006-200 144 11 206 145 10 213 154 11 219 162 10
41007-224 166 10 230 174 11 239 182 13 242 186 14
41008-246 186 14 246 186 14 246 186 14 246 186 14
41009-239 182 13 216 158 10 185 133 11 152 99 6
41010-104 69 6 18 14 6 2 2 6 2 2 6
41011- 2 2 6 2 2 6 2 2 6 2 2 6
41012- 2 2 6 2 2 6 2 2 6 2 2 6
41013- 2 2 6 2 2 6 2 2 6 2 2 6
41014- 2 2 6 6 6 6 80 54 7 152 99 6
41015-192 133 9 219 162 10 236 178 12 239 182 13
41016-246 186 14 242 186 14 239 182 13 236 178 12
41017-224 166 10 206 145 10 192 133 9 154 121 60
41018- 94 94 94 62 62 62 42 42 42 22 22 22
41019- 14 14 14 6 6 6 0 0 0 0 0 0
41020- 0 0 0 0 0 0 0 0 0 0 0 0
41021- 0 0 0 0 0 0 0 0 0 0 0 0
41022- 0 0 0 0 0 0 0 0 0 0 0 0
41023- 0 0 0 0 0 0 0 0 0 6 6 6
41024- 18 18 18 34 34 34 58 58 58 78 78 78
41025-101 98 89 124 112 88 142 110 46 156 107 11
41026-163 110 8 167 114 7 175 118 6 180 123 7
41027-185 133 11 197 138 11 210 150 10 219 162 10
41028-226 170 11 236 178 12 236 178 12 234 174 13
41029-219 162 10 197 138 11 163 110 8 130 83 6
41030- 91 60 6 10 10 10 2 2 6 2 2 6
41031- 18 18 18 38 38 38 38 38 38 38 38 38
41032- 38 38 38 38 38 38 38 38 38 38 38 38
41033- 38 38 38 38 38 38 26 26 26 2 2 6
41034- 2 2 6 6 6 6 70 47 6 137 92 6
41035-175 118 6 200 144 11 219 162 10 230 174 11
41036-234 174 13 230 174 11 219 162 10 210 150 10
41037-192 133 9 163 110 8 124 112 88 82 82 82
41038- 50 50 50 30 30 30 14 14 14 6 6 6
41039- 0 0 0 0 0 0 0 0 0 0 0 0
41040- 0 0 0 0 0 0 0 0 0 0 0 0
41041- 0 0 0 0 0 0 0 0 0 0 0 0
41042- 0 0 0 0 0 0 0 0 0 0 0 0
41043- 0 0 0 0 0 0 0 0 0 0 0 0
41044- 6 6 6 14 14 14 22 22 22 34 34 34
41045- 42 42 42 58 58 58 74 74 74 86 86 86
41046-101 98 89 122 102 70 130 98 46 121 87 25
41047-137 92 6 152 99 6 163 110 8 180 123 7
41048-185 133 11 197 138 11 206 145 10 200 144 11
41049-180 123 7 156 107 11 130 83 6 104 69 6
41050- 50 34 6 54 54 54 110 110 110 101 98 89
41051- 86 86 86 82 82 82 78 78 78 78 78 78
41052- 78 78 78 78 78 78 78 78 78 78 78 78
41053- 78 78 78 82 82 82 86 86 86 94 94 94
41054-106 106 106 101 101 101 86 66 34 124 80 6
41055-156 107 11 180 123 7 192 133 9 200 144 11
41056-206 145 10 200 144 11 192 133 9 175 118 6
41057-139 102 15 109 106 95 70 70 70 42 42 42
41058- 22 22 22 10 10 10 0 0 0 0 0 0
41059- 0 0 0 0 0 0 0 0 0 0 0 0
41060- 0 0 0 0 0 0 0 0 0 0 0 0
41061- 0 0 0 0 0 0 0 0 0 0 0 0
41062- 0 0 0 0 0 0 0 0 0 0 0 0
41063- 0 0 0 0 0 0 0 0 0 0 0 0
41064- 0 0 0 0 0 0 6 6 6 10 10 10
41065- 14 14 14 22 22 22 30 30 30 38 38 38
41066- 50 50 50 62 62 62 74 74 74 90 90 90
41067-101 98 89 112 100 78 121 87 25 124 80 6
41068-137 92 6 152 99 6 152 99 6 152 99 6
41069-138 86 6 124 80 6 98 70 6 86 66 30
41070-101 98 89 82 82 82 58 58 58 46 46 46
41071- 38 38 38 34 34 34 34 34 34 34 34 34
41072- 34 34 34 34 34 34 34 34 34 34 34 34
41073- 34 34 34 34 34 34 38 38 38 42 42 42
41074- 54 54 54 82 82 82 94 86 76 91 60 6
41075-134 86 6 156 107 11 167 114 7 175 118 6
41076-175 118 6 167 114 7 152 99 6 121 87 25
41077-101 98 89 62 62 62 34 34 34 18 18 18
41078- 6 6 6 0 0 0 0 0 0 0 0 0
41079- 0 0 0 0 0 0 0 0 0 0 0 0
41080- 0 0 0 0 0 0 0 0 0 0 0 0
41081- 0 0 0 0 0 0 0 0 0 0 0 0
41082- 0 0 0 0 0 0 0 0 0 0 0 0
41083- 0 0 0 0 0 0 0 0 0 0 0 0
41084- 0 0 0 0 0 0 0 0 0 0 0 0
41085- 0 0 0 6 6 6 6 6 6 10 10 10
41086- 18 18 18 22 22 22 30 30 30 42 42 42
41087- 50 50 50 66 66 66 86 86 86 101 98 89
41088-106 86 58 98 70 6 104 69 6 104 69 6
41089-104 69 6 91 60 6 82 62 34 90 90 90
41090- 62 62 62 38 38 38 22 22 22 14 14 14
41091- 10 10 10 10 10 10 10 10 10 10 10 10
41092- 10 10 10 10 10 10 6 6 6 10 10 10
41093- 10 10 10 10 10 10 10 10 10 14 14 14
41094- 22 22 22 42 42 42 70 70 70 89 81 66
41095- 80 54 7 104 69 6 124 80 6 137 92 6
41096-134 86 6 116 81 8 100 82 52 86 86 86
41097- 58 58 58 30 30 30 14 14 14 6 6 6
41098- 0 0 0 0 0 0 0 0 0 0 0 0
41099- 0 0 0 0 0 0 0 0 0 0 0 0
41100- 0 0 0 0 0 0 0 0 0 0 0 0
41101- 0 0 0 0 0 0 0 0 0 0 0 0
41102- 0 0 0 0 0 0 0 0 0 0 0 0
41103- 0 0 0 0 0 0 0 0 0 0 0 0
41104- 0 0 0 0 0 0 0 0 0 0 0 0
41105- 0 0 0 0 0 0 0 0 0 0 0 0
41106- 0 0 0 6 6 6 10 10 10 14 14 14
41107- 18 18 18 26 26 26 38 38 38 54 54 54
41108- 70 70 70 86 86 86 94 86 76 89 81 66
41109- 89 81 66 86 86 86 74 74 74 50 50 50
41110- 30 30 30 14 14 14 6 6 6 0 0 0
41111- 0 0 0 0 0 0 0 0 0 0 0 0
41112- 0 0 0 0 0 0 0 0 0 0 0 0
41113- 0 0 0 0 0 0 0 0 0 0 0 0
41114- 6 6 6 18 18 18 34 34 34 58 58 58
41115- 82 82 82 89 81 66 89 81 66 89 81 66
41116- 94 86 66 94 86 76 74 74 74 50 50 50
41117- 26 26 26 14 14 14 6 6 6 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 0 0 0
41120- 0 0 0 0 0 0 0 0 0 0 0 0
41121- 0 0 0 0 0 0 0 0 0 0 0 0
41122- 0 0 0 0 0 0 0 0 0 0 0 0
41123- 0 0 0 0 0 0 0 0 0 0 0 0
41124- 0 0 0 0 0 0 0 0 0 0 0 0
41125- 0 0 0 0 0 0 0 0 0 0 0 0
41126- 0 0 0 0 0 0 0 0 0 0 0 0
41127- 6 6 6 6 6 6 14 14 14 18 18 18
41128- 30 30 30 38 38 38 46 46 46 54 54 54
41129- 50 50 50 42 42 42 30 30 30 18 18 18
41130- 10 10 10 0 0 0 0 0 0 0 0 0
41131- 0 0 0 0 0 0 0 0 0 0 0 0
41132- 0 0 0 0 0 0 0 0 0 0 0 0
41133- 0 0 0 0 0 0 0 0 0 0 0 0
41134- 0 0 0 6 6 6 14 14 14 26 26 26
41135- 38 38 38 50 50 50 58 58 58 58 58 58
41136- 54 54 54 42 42 42 30 30 30 18 18 18
41137- 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
41141- 0 0 0 0 0 0 0 0 0 0 0 0
41142- 0 0 0 0 0 0 0 0 0 0 0 0
41143- 0 0 0 0 0 0 0 0 0 0 0 0
41144- 0 0 0 0 0 0 0 0 0 0 0 0
41145- 0 0 0 0 0 0 0 0 0 0 0 0
41146- 0 0 0 0 0 0 0 0 0 0 0 0
41147- 0 0 0 0 0 0 0 0 0 6 6 6
41148- 6 6 6 10 10 10 14 14 14 18 18 18
41149- 18 18 18 14 14 14 10 10 10 6 6 6
41150- 0 0 0 0 0 0 0 0 0 0 0 0
41151- 0 0 0 0 0 0 0 0 0 0 0 0
41152- 0 0 0 0 0 0 0 0 0 0 0 0
41153- 0 0 0 0 0 0 0 0 0 0 0 0
41154- 0 0 0 0 0 0 0 0 0 6 6 6
41155- 14 14 14 18 18 18 22 22 22 22 22 22
41156- 18 18 18 14 14 14 10 10 10 6 6 6
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 0 0 0 0 0 0
41161- 0 0 0 0 0 0 0 0 0 0 0 0
41162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41175+4 4 4 4 4 4
41176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41189+4 4 4 4 4 4
41190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41203+4 4 4 4 4 4
41204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41217+4 4 4 4 4 4
41218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41228+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41231+4 4 4 4 4 4
41232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41245+4 4 4 4 4 4
41246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41250+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41251+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41255+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41256+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41257+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
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 2 2 2 0 0 0 3 4 3 26 28 28
41265+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41266+5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
41270+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41271+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41272+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41273+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+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41279+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41280+0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
41284+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41285+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41286+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41287+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 5 5 5 5 5 5 2 2 2 0 0 0
41292+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41293+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41294+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
41297+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41298+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41299+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41300+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41301+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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41306+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41307+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41308+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41309+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41310+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41311+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41312+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41313+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41314+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41315+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 5 5 5
41319+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41320+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41321+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41322+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41323+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41324+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41325+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41326+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41327+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41328+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41329+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 5 5 5 3 3 3
41333+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41334+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41335+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41336+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41337+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41338+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41339+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41340+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41341+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41342+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41343+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 2 2 2 0 0 0 4 0 0
41347+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41348+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41349+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41350+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41351+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41352+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41353+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41354+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41355+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41356+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41357+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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41361+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41362+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41363+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41364+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41365+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41366+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41367+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41368+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41369+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41370+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41371+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+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41375+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41376+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41377+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41378+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41379+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41380+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41381+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41382+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41383+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41384+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41385+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 4 4 4 4 4 4 3 3 3 0 0 0
41388+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41389+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41390+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41391+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41392+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41393+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41394+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41395+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41396+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41397+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41398+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41399+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 3 3 3 0 0 0 1 0 0 4 0 0
41402+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41403+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41404+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41405+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41406+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41407+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41408+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41409+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41410+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41411+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41412+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41413+0 0 0 4 4 4
41414+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41415+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41416+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41417+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41418+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41419+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41420+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41421+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41422+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41423+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41424+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41425+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41426+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41427+2 0 0 0 0 0
41428+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41429+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41430+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41431+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41432+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41433+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41434+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41435+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41436+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41437+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41438+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41439+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41440+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41441+37 38 37 0 0 0
41442+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41443+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41444+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41445+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41446+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41447+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41448+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41449+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41450+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41451+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41452+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41453+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41454+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41455+85 115 134 4 0 0
41456+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41457+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41458+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41459+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41460+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41461+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41462+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41463+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41464+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41465+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41466+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41467+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41468+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41469+60 73 81 4 0 0
41470+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41471+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41472+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41473+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41474+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41475+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41476+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41477+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41478+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41479+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41480+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41481+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41482+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41483+16 19 21 4 0 0
41484+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41485+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41486+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41487+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41488+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41489+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41490+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41491+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41492+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41493+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41494+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41495+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41496+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41497+4 0 0 4 3 3
41498+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41499+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41500+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41502+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41503+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41504+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41505+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41506+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41507+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41508+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41509+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41510+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41511+3 2 2 4 4 4
41512+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41513+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41514+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41515+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41516+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41517+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41518+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41519+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41520+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41521+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41522+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41523+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41524+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41525+4 4 4 4 4 4
41526+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41527+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41528+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41529+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41530+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41531+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41532+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41533+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41534+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41535+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41536+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41537+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41538+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41539+4 4 4 4 4 4
41540+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41541+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41542+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41543+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41544+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41545+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41546+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41547+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41548+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41549+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41550+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41551+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41552+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41553+5 5 5 5 5 5
41554+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41555+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41556+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41557+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41558+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41559+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41560+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41561+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41562+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41563+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41564+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41565+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41566+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41567+5 5 5 4 4 4
41568+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41569+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41570+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41571+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41572+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41573+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41574+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41575+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41576+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41577+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41578+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41579+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41581+4 4 4 4 4 4
41582+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41583+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41584+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41585+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41586+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41587+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41588+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41589+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41590+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41591+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41592+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41593+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41595+4 4 4 4 4 4
41596+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41597+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41598+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41599+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41600+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41601+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41602+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41603+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41604+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41605+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41606+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41609+4 4 4 4 4 4
41610+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41611+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41612+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41613+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41614+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41615+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41616+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41617+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41618+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41619+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41620+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41623+4 4 4 4 4 4
41624+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41625+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41626+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41627+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41628+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41629+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41630+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41631+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41632+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41633+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41634+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41637+4 4 4 4 4 4
41638+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41639+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41640+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41641+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41642+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41643+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41644+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41645+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41646+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41647+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41648+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41651+4 4 4 4 4 4
41652+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41653+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41654+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41655+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41656+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41657+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41658+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41659+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41660+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41661+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41662+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41665+4 4 4 4 4 4
41666+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41667+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41668+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41669+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41670+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41671+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41672+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41673+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41674+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41675+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41676+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41679+4 4 4 4 4 4
41680+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41681+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41682+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41683+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41684+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41685+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41686+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41687+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41688+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41689+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41690+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41693+4 4 4 4 4 4
41694+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41695+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41696+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41697+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41698+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41699+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41700+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41701+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41702+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41703+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41704+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41707+4 4 4 4 4 4
41708+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41709+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41710+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41711+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41712+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41713+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41714+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41715+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41716+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41717+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41718+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41721+4 4 4 4 4 4
41722+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41723+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41724+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41725+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41726+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41727+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41728+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41729+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41730+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41731+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41732+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41735+4 4 4 4 4 4
41736+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41737+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41738+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41739+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41740+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41741+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41742+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41743+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41744+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41745+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41746+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41749+4 4 4 4 4 4
41750+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41751+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41752+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41753+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41754+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41755+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41756+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41757+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41758+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41759+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41760+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41763+4 4 4 4 4 4
41764+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41765+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41766+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41767+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41768+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41769+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41770+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41771+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41772+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41773+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41774+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41777+4 4 4 4 4 4
41778+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41779+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41780+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41781+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41782+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41783+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41784+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41785+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41786+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41787+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41788+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41791+4 4 4 4 4 4
41792+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41793+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41794+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41795+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41796+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41797+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41798+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41799+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41800+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41801+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41802+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41805+4 4 4 4 4 4
41806+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41807+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41808+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41809+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41810+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41811+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41812+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41813+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41814+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41815+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41816+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41819+4 4 4 4 4 4
41820+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41821+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41822+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41823+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41824+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41825+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41826+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41827+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41828+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41829+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41830+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41833+4 4 4 4 4 4
41834+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41835+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41836+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41837+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41838+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41839+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41840+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41841+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41842+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41843+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41844+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41847+4 4 4 4 4 4
41848+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41849+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41850+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41851+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41852+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41853+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41854+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41855+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41856+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41857+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41858+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41861+4 4 4 4 4 4
41862+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41863+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41864+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41865+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41866+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41867+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41868+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41869+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41870+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41871+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41872+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41875+4 4 4 4 4 4
41876+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41877+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41878+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41879+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41880+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41881+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41882+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41883+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41884+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41885+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41886+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41889+4 4 4 4 4 4
41890+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41891+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41892+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41893+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41894+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41895+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41896+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41897+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41898+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41899+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41900+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41903+4 4 4 4 4 4
41904+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41905+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41906+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41907+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41908+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41909+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41910+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41911+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41912+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41913+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41914+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41917+4 4 4 4 4 4
41918+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41919+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41920+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41921+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41922+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41923+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41924+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41925+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41926+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41927+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41928+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41931+4 4 4 4 4 4
41932+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41933+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41934+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41935+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41936+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41937+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41938+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41939+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41940+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41941+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41942+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41943+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41945+4 4 4 4 4 4
41946+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41947+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41948+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41949+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41950+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41951+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41952+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41953+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41954+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41955+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41956+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41957+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41959+4 4 4 4 4 4
41960+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41961+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41962+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41963+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41964+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41965+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41966+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41967+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41968+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41969+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41970+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41973+4 4 4 4 4 4
41974+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41975+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41976+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41977+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41978+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41979+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41980+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41981+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41982+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41983+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
41986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41987+4 4 4 4 4 4
41988+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41989+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41990+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41991+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41992+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41993+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41994+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41995+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41996+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41997+13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
42000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42001+4 4 4 4 4 4
42002+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42003+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42004+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42005+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42006+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42007+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42008+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42009+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42010+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42011+4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42015+4 4 4 4 4 4
42016+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42017+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42018+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42019+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42020+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42021+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42022+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42023+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42024+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42025+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42029+4 4 4 4 4 4
42030+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42031+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42032+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42033+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42034+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42035+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42036+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42037+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42038+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
42042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42043+4 4 4 4 4 4
42044+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42045+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42046+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42047+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42048+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42049+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42050+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42051+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42052+4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
42056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42057+4 4 4 4 4 4
42058+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42059+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42060+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42061+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42062+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42063+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42064+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42065+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42066+4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
42070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42071+4 4 4 4 4 4
42072+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42073+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42074+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42075+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42076+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42077+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42078+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42079+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
42084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42085+4 4 4 4 4 4
42086+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42087+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42088+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42089+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42090+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42091+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42092+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42093+6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
42098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42099+4 4 4 4 4 4
42100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42101+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42102+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42103+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42104+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42105+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42106+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42107+4 0 0 4 3 3 6 6 6 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
42112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42113+4 4 4 4 4 4
42114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42115+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42116+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42117+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42118+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42119+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42120+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42121+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42127+4 4 4 4 4 4
42128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42129+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42130+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42131+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42132+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42133+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42134+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42135+5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42141+4 4 4 4 4 4
42142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42144+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42145+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42146+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42147+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42148+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42149+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42155+4 4 4 4 4 4
42156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42159+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42160+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42161+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42162+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
42168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42169+4 4 4 4 4 4
42170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42173+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42174+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42175+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42176+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
42182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42183+4 4 4 4 4 4
42184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42187+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42188+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42189+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42190+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42197+4 4 4 4 4 4
42198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42201+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42202+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42203+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42204+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 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 4 4 4
42212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42216+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42217+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42218+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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
42226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42228+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42230+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42231+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42232+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 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
42240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42244+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42245+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42246+5 5 5 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 4 4 4 4 4 4 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
42254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42258+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42259+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 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
42268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42272+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42273+5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 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
42282diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42283index 8af6414..658c030 100644
42284--- a/drivers/video/udlfb.c
42285+++ b/drivers/video/udlfb.c
42286@@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42287 dlfb_urb_completion(urb);
42288
42289 error:
42290- atomic_add(bytes_sent, &dev->bytes_sent);
42291- atomic_add(bytes_identical, &dev->bytes_identical);
42292- atomic_add(width*height*2, &dev->bytes_rendered);
42293+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42294+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42295+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42296 end_cycles = get_cycles();
42297- atomic_add(((unsigned int) ((end_cycles - start_cycles)
42298+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42299 >> 10)), /* Kcycles */
42300 &dev->cpu_kcycles_used);
42301
42302@@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42303 dlfb_urb_completion(urb);
42304
42305 error:
42306- atomic_add(bytes_sent, &dev->bytes_sent);
42307- atomic_add(bytes_identical, &dev->bytes_identical);
42308- atomic_add(bytes_rendered, &dev->bytes_rendered);
42309+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42310+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42311+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42312 end_cycles = get_cycles();
42313- atomic_add(((unsigned int) ((end_cycles - start_cycles)
42314+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42315 >> 10)), /* Kcycles */
42316 &dev->cpu_kcycles_used);
42317 }
42318@@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42319 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42320 struct dlfb_data *dev = fb_info->par;
42321 return snprintf(buf, PAGE_SIZE, "%u\n",
42322- atomic_read(&dev->bytes_rendered));
42323+ atomic_read_unchecked(&dev->bytes_rendered));
42324 }
42325
42326 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42327@@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42328 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42329 struct dlfb_data *dev = fb_info->par;
42330 return snprintf(buf, PAGE_SIZE, "%u\n",
42331- atomic_read(&dev->bytes_identical));
42332+ atomic_read_unchecked(&dev->bytes_identical));
42333 }
42334
42335 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42336@@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42337 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42338 struct dlfb_data *dev = fb_info->par;
42339 return snprintf(buf, PAGE_SIZE, "%u\n",
42340- atomic_read(&dev->bytes_sent));
42341+ atomic_read_unchecked(&dev->bytes_sent));
42342 }
42343
42344 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42345@@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42346 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42347 struct dlfb_data *dev = fb_info->par;
42348 return snprintf(buf, PAGE_SIZE, "%u\n",
42349- atomic_read(&dev->cpu_kcycles_used));
42350+ atomic_read_unchecked(&dev->cpu_kcycles_used));
42351 }
42352
42353 static ssize_t edid_show(
42354@@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42355 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42356 struct dlfb_data *dev = fb_info->par;
42357
42358- atomic_set(&dev->bytes_rendered, 0);
42359- atomic_set(&dev->bytes_identical, 0);
42360- atomic_set(&dev->bytes_sent, 0);
42361- atomic_set(&dev->cpu_kcycles_used, 0);
42362+ atomic_set_unchecked(&dev->bytes_rendered, 0);
42363+ atomic_set_unchecked(&dev->bytes_identical, 0);
42364+ atomic_set_unchecked(&dev->bytes_sent, 0);
42365+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42366
42367 return count;
42368 }
42369diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42370index b0e2a42..e2df3ad 100644
42371--- a/drivers/video/uvesafb.c
42372+++ b/drivers/video/uvesafb.c
42373@@ -19,6 +19,7 @@
42374 #include <linux/io.h>
42375 #include <linux/mutex.h>
42376 #include <linux/slab.h>
42377+#include <linux/moduleloader.h>
42378 #include <video/edid.h>
42379 #include <video/uvesafb.h>
42380 #ifdef CONFIG_X86
42381@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42382 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42383 par->pmi_setpal = par->ypan = 0;
42384 } else {
42385+
42386+#ifdef CONFIG_PAX_KERNEXEC
42387+#ifdef CONFIG_MODULES
42388+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42389+#endif
42390+ if (!par->pmi_code) {
42391+ par->pmi_setpal = par->ypan = 0;
42392+ return 0;
42393+ }
42394+#endif
42395+
42396 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42397 + task->t.regs.edi);
42398+
42399+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42400+ pax_open_kernel();
42401+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42402+ pax_close_kernel();
42403+
42404+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42405+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42406+#else
42407 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42408 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42409+#endif
42410+
42411 printk(KERN_INFO "uvesafb: protected mode interface info at "
42412 "%04x:%04x\n",
42413 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42414@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42415 par->ypan = ypan;
42416
42417 if (par->pmi_setpal || par->ypan) {
42418+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42419 if (__supported_pte_mask & _PAGE_NX) {
42420 par->pmi_setpal = par->ypan = 0;
42421 printk(KERN_WARNING "uvesafb: NX protection is actively."
42422 "We have better not to use the PMI.\n");
42423- } else {
42424+ } else
42425+#endif
42426 uvesafb_vbe_getpmi(task, par);
42427- }
42428 }
42429 #else
42430 /* The protected mode interface is not available on non-x86. */
42431@@ -1836,6 +1860,11 @@ out:
42432 if (par->vbe_modes)
42433 kfree(par->vbe_modes);
42434
42435+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42436+ if (par->pmi_code)
42437+ module_free_exec(NULL, par->pmi_code);
42438+#endif
42439+
42440 framebuffer_release(info);
42441 return err;
42442 }
42443@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42444 kfree(par->vbe_state_orig);
42445 if (par->vbe_state_saved)
42446 kfree(par->vbe_state_saved);
42447+
42448+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42449+ if (par->pmi_code)
42450+ module_free_exec(NULL, par->pmi_code);
42451+#endif
42452+
42453 }
42454
42455 framebuffer_release(info);
42456diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42457index 501b340..86bd4cf 100644
42458--- a/drivers/video/vesafb.c
42459+++ b/drivers/video/vesafb.c
42460@@ -9,6 +9,7 @@
42461 */
42462
42463 #include <linux/module.h>
42464+#include <linux/moduleloader.h>
42465 #include <linux/kernel.h>
42466 #include <linux/errno.h>
42467 #include <linux/string.h>
42468@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42469 static int vram_total __initdata; /* Set total amount of memory */
42470 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42471 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42472-static void (*pmi_start)(void) __read_mostly;
42473-static void (*pmi_pal) (void) __read_mostly;
42474+static void (*pmi_start)(void) __read_only;
42475+static void (*pmi_pal) (void) __read_only;
42476 static int depth __read_mostly;
42477 static int vga_compat __read_mostly;
42478 /* --------------------------------------------------------------------- */
42479@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42480 unsigned int size_vmode;
42481 unsigned int size_remap;
42482 unsigned int size_total;
42483+ void *pmi_code = NULL;
42484
42485 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42486 return -ENODEV;
42487@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42488 size_remap = size_total;
42489 vesafb_fix.smem_len = size_remap;
42490
42491-#ifndef __i386__
42492- screen_info.vesapm_seg = 0;
42493-#endif
42494-
42495 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42496 printk(KERN_WARNING
42497 "vesafb: cannot reserve video memory at 0x%lx\n",
42498@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42499 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42500 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42501
42502+#ifdef __i386__
42503+
42504+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42505+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
42506+ if (!pmi_code)
42507+#elif !defined(CONFIG_PAX_KERNEXEC)
42508+ if (0)
42509+#endif
42510+
42511+#endif
42512+ screen_info.vesapm_seg = 0;
42513+
42514 if (screen_info.vesapm_seg) {
42515- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42516- screen_info.vesapm_seg,screen_info.vesapm_off);
42517+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42518+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42519 }
42520
42521 if (screen_info.vesapm_seg < 0xc000)
42522@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42523
42524 if (ypan || pmi_setpal) {
42525 unsigned short *pmi_base;
42526+
42527 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42528- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42529- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42530+
42531+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42532+ pax_open_kernel();
42533+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42534+#else
42535+ pmi_code = pmi_base;
42536+#endif
42537+
42538+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42539+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42540+
42541+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42542+ pmi_start = ktva_ktla(pmi_start);
42543+ pmi_pal = ktva_ktla(pmi_pal);
42544+ pax_close_kernel();
42545+#endif
42546+
42547 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42548 if (pmi_base[3]) {
42549 printk(KERN_INFO "vesafb: pmi: ports = ");
42550@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42551 info->node, info->fix.id);
42552 return 0;
42553 err:
42554+
42555+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42556+ module_free_exec(NULL, pmi_code);
42557+#endif
42558+
42559 if (info->screen_base)
42560 iounmap(info->screen_base);
42561 framebuffer_release(info);
42562diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42563index 88714ae..16c2e11 100644
42564--- a/drivers/video/via/via_clock.h
42565+++ b/drivers/video/via/via_clock.h
42566@@ -56,7 +56,7 @@ struct via_clock {
42567
42568 void (*set_engine_pll_state)(u8 state);
42569 void (*set_engine_pll)(struct via_pll_config config);
42570-};
42571+} __no_const;
42572
42573
42574 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42575diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42576index 453db0c..604973e 100644
42577--- a/drivers/virtio/virtio_mmio.c
42578+++ b/drivers/virtio/virtio_mmio.c
42579@@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42580
42581 resources[0].end = memparse(device, &str) - 1;
42582
42583- processed = sscanf(str, "@%lli:%u%n:%d%n",
42584+ processed = sscanf(str, "@%lli:%llu%n:%d%n",
42585 &base, &resources[1].start, &consumed,
42586 &vm_cmdline_id, &consumed);
42587
42588diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42589index e56c934..fc22f4b 100644
42590--- a/drivers/xen/xen-pciback/conf_space.h
42591+++ b/drivers/xen/xen-pciback/conf_space.h
42592@@ -44,15 +44,15 @@ struct config_field {
42593 struct {
42594 conf_dword_write write;
42595 conf_dword_read read;
42596- } dw;
42597+ } __no_const dw;
42598 struct {
42599 conf_word_write write;
42600 conf_word_read read;
42601- } w;
42602+ } __no_const w;
42603 struct {
42604 conf_byte_write write;
42605 conf_byte_read read;
42606- } b;
42607+ } __no_const b;
42608 } u;
42609 struct list_head list;
42610 };
42611diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42612index cbf9dbb..35c3af7 100644
42613--- a/fs/9p/vfs_inode.c
42614+++ b/fs/9p/vfs_inode.c
42615@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42616 void
42617 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42618 {
42619- char *s = nd_get_link(nd);
42620+ const char *s = nd_get_link(nd);
42621
42622 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42623 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42624diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42625index 0225742..1cd4732 100644
42626--- a/fs/Kconfig.binfmt
42627+++ b/fs/Kconfig.binfmt
42628@@ -89,7 +89,7 @@ config HAVE_AOUT
42629
42630 config BINFMT_AOUT
42631 tristate "Kernel support for a.out and ECOFF binaries"
42632- depends on HAVE_AOUT
42633+ depends on HAVE_AOUT && BROKEN
42634 ---help---
42635 A.out (Assembler.OUTput) is a set of formats for libraries and
42636 executables used in the earliest versions of UNIX. Linux used
42637diff --git a/fs/aio.c b/fs/aio.c
42638index 71f613c..9d01f1f 100644
42639--- a/fs/aio.c
42640+++ b/fs/aio.c
42641@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42642 size += sizeof(struct io_event) * nr_events;
42643 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42644
42645- if (nr_pages < 0)
42646+ if (nr_pages <= 0)
42647 return -EINVAL;
42648
42649 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42650@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42651 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42652 {
42653 ssize_t ret;
42654+ struct iovec iovstack;
42655
42656 #ifdef CONFIG_COMPAT
42657 if (compat)
42658 ret = compat_rw_copy_check_uvector(type,
42659 (struct compat_iovec __user *)kiocb->ki_buf,
42660- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42661+ kiocb->ki_nbytes, 1, &iovstack,
42662 &kiocb->ki_iovec);
42663 else
42664 #endif
42665 ret = rw_copy_check_uvector(type,
42666 (struct iovec __user *)kiocb->ki_buf,
42667- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42668+ kiocb->ki_nbytes, 1, &iovstack,
42669 &kiocb->ki_iovec);
42670 if (ret < 0)
42671 goto out;
42672@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42673 if (ret < 0)
42674 goto out;
42675
42676+ if (kiocb->ki_iovec == &iovstack) {
42677+ kiocb->ki_inline_vec = iovstack;
42678+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
42679+ }
42680 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42681 kiocb->ki_cur_seg = 0;
42682 /* ki_nbytes/left now reflect bytes instead of segs */
42683diff --git a/fs/attr.c b/fs/attr.c
42684index 29e38a1..2bc037b 100644
42685--- a/fs/attr.c
42686+++ b/fs/attr.c
42687@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42688 unsigned long limit;
42689
42690 limit = rlimit(RLIMIT_FSIZE);
42691+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42692 if (limit != RLIM_INFINITY && offset > limit)
42693 goto out_sig;
42694 if (offset > inode->i_sb->s_maxbytes)
42695diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42696index da8876d..4456166 100644
42697--- a/fs/autofs4/waitq.c
42698+++ b/fs/autofs4/waitq.c
42699@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42700 {
42701 unsigned long sigpipe, flags;
42702 mm_segment_t fs;
42703- const char *data = (const char *)addr;
42704+ const char __user *data = (const char __force_user *)addr;
42705 ssize_t wr = 0;
42706
42707 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42708@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42709 return 1;
42710 }
42711
42712+#ifdef CONFIG_GRKERNSEC_HIDESYM
42713+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42714+#endif
42715+
42716 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42717 enum autofs_notify notify)
42718 {
42719@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42720
42721 /* If this is a direct mount request create a dummy name */
42722 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42723+#ifdef CONFIG_GRKERNSEC_HIDESYM
42724+ /* this name does get written to userland via autofs4_write() */
42725+ qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42726+#else
42727 qstr.len = sprintf(name, "%p", dentry);
42728+#endif
42729 else {
42730 qstr.len = autofs4_getpath(sbi, dentry, &name);
42731 if (!qstr.len) {
42732diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42733index cf7f3c6..f61080d 100644
42734--- a/fs/befs/linuxvfs.c
42735+++ b/fs/befs/linuxvfs.c
42736@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42737 {
42738 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42739 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42740- char *link = nd_get_link(nd);
42741+ const char *link = nd_get_link(nd);
42742 if (!IS_ERR(link))
42743 kfree(link);
42744 }
42745diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42746index d146e18..12d1bd1 100644
42747--- a/fs/binfmt_aout.c
42748+++ b/fs/binfmt_aout.c
42749@@ -16,6 +16,7 @@
42750 #include <linux/string.h>
42751 #include <linux/fs.h>
42752 #include <linux/file.h>
42753+#include <linux/security.h>
42754 #include <linux/stat.h>
42755 #include <linux/fcntl.h>
42756 #include <linux/ptrace.h>
42757@@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42758 #endif
42759 # define START_STACK(u) ((void __user *)u.start_stack)
42760
42761+ memset(&dump, 0, sizeof(dump));
42762+
42763 fs = get_fs();
42764 set_fs(KERNEL_DS);
42765 has_dumped = 1;
42766@@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42767
42768 /* If the size of the dump file exceeds the rlimit, then see what would happen
42769 if we wrote the stack, but not the data area. */
42770+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42771 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42772 dump.u_dsize = 0;
42773
42774 /* Make sure we have enough room to write the stack and data areas. */
42775+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42776 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42777 dump.u_ssize = 0;
42778
42779@@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42780 rlim = rlimit(RLIMIT_DATA);
42781 if (rlim >= RLIM_INFINITY)
42782 rlim = ~0;
42783+
42784+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42785 if (ex.a_data + ex.a_bss > rlim)
42786 return -ENOMEM;
42787
42788@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42789
42790 install_exec_creds(bprm);
42791
42792+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42793+ current->mm->pax_flags = 0UL;
42794+#endif
42795+
42796+#ifdef CONFIG_PAX_PAGEEXEC
42797+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42798+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42799+
42800+#ifdef CONFIG_PAX_EMUTRAMP
42801+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42802+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42803+#endif
42804+
42805+#ifdef CONFIG_PAX_MPROTECT
42806+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42807+ current->mm->pax_flags |= MF_PAX_MPROTECT;
42808+#endif
42809+
42810+ }
42811+#endif
42812+
42813 if (N_MAGIC(ex) == OMAGIC) {
42814 unsigned long text_addr, map_size;
42815 loff_t pos;
42816@@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42817 }
42818
42819 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42820- PROT_READ | PROT_WRITE | PROT_EXEC,
42821+ PROT_READ | PROT_WRITE,
42822 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42823 fd_offset + ex.a_text);
42824 if (error != N_DATADDR(ex)) {
42825diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42826index 0225fdd..9f0ef53 100644
42827--- a/fs/binfmt_elf.c
42828+++ b/fs/binfmt_elf.c
42829@@ -32,6 +32,7 @@
42830 #include <linux/elf.h>
42831 #include <linux/utsname.h>
42832 #include <linux/coredump.h>
42833+#include <linux/xattr.h>
42834 #include <asm/uaccess.h>
42835 #include <asm/param.h>
42836 #include <asm/page.h>
42837@@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42838 #define elf_core_dump NULL
42839 #endif
42840
42841+#ifdef CONFIG_PAX_MPROTECT
42842+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42843+#endif
42844+
42845 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42846 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42847 #else
42848@@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42849 .load_binary = load_elf_binary,
42850 .load_shlib = load_elf_library,
42851 .core_dump = elf_core_dump,
42852+
42853+#ifdef CONFIG_PAX_MPROTECT
42854+ .handle_mprotect= elf_handle_mprotect,
42855+#endif
42856+
42857 .min_coredump = ELF_EXEC_PAGESIZE,
42858 };
42859
42860@@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42861
42862 static int set_brk(unsigned long start, unsigned long end)
42863 {
42864+ unsigned long e = end;
42865+
42866 start = ELF_PAGEALIGN(start);
42867 end = ELF_PAGEALIGN(end);
42868 if (end > start) {
42869@@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42870 if (BAD_ADDR(addr))
42871 return addr;
42872 }
42873- current->mm->start_brk = current->mm->brk = end;
42874+ current->mm->start_brk = current->mm->brk = e;
42875 return 0;
42876 }
42877
42878@@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42879 elf_addr_t __user *u_rand_bytes;
42880 const char *k_platform = ELF_PLATFORM;
42881 const char *k_base_platform = ELF_BASE_PLATFORM;
42882- unsigned char k_rand_bytes[16];
42883+ u32 k_rand_bytes[4];
42884 int items;
42885 elf_addr_t *elf_info;
42886 int ei_index = 0;
42887 const struct cred *cred = current_cred();
42888 struct vm_area_struct *vma;
42889+ unsigned long saved_auxv[AT_VECTOR_SIZE];
42890
42891 /*
42892 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42893@@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42894 * Generate 16 random bytes for userspace PRNG seeding.
42895 */
42896 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42897- u_rand_bytes = (elf_addr_t __user *)
42898- STACK_ALLOC(p, sizeof(k_rand_bytes));
42899+ srandom32(k_rand_bytes[0] ^ random32());
42900+ srandom32(k_rand_bytes[1] ^ random32());
42901+ srandom32(k_rand_bytes[2] ^ random32());
42902+ srandom32(k_rand_bytes[3] ^ random32());
42903+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
42904+ u_rand_bytes = (elf_addr_t __user *) p;
42905 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42906 return -EFAULT;
42907
42908@@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42909 return -EFAULT;
42910 current->mm->env_end = p;
42911
42912+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42913+
42914 /* Put the elf_info on the stack in the right place. */
42915 sp = (elf_addr_t __user *)envp + 1;
42916- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42917+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42918 return -EFAULT;
42919 return 0;
42920 }
42921@@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42922 {
42923 struct elf_phdr *elf_phdata;
42924 struct elf_phdr *eppnt;
42925- unsigned long load_addr = 0;
42926+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42927 int load_addr_set = 0;
42928 unsigned long last_bss = 0, elf_bss = 0;
42929- unsigned long error = ~0UL;
42930+ unsigned long error = -EINVAL;
42931 unsigned long total_size;
42932 int retval, i, size;
42933
42934@@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42935 goto out_close;
42936 }
42937
42938+#ifdef CONFIG_PAX_SEGMEXEC
42939+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42940+ pax_task_size = SEGMEXEC_TASK_SIZE;
42941+#endif
42942+
42943 eppnt = elf_phdata;
42944 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42945 if (eppnt->p_type == PT_LOAD) {
42946@@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42947 k = load_addr + eppnt->p_vaddr;
42948 if (BAD_ADDR(k) ||
42949 eppnt->p_filesz > eppnt->p_memsz ||
42950- eppnt->p_memsz > TASK_SIZE ||
42951- TASK_SIZE - eppnt->p_memsz < k) {
42952+ eppnt->p_memsz > pax_task_size ||
42953+ pax_task_size - eppnt->p_memsz < k) {
42954 error = -ENOMEM;
42955 goto out_close;
42956 }
42957@@ -523,6 +547,311 @@ out:
42958 return error;
42959 }
42960
42961+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42962+#ifdef CONFIG_PAX_SOFTMODE
42963+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42964+{
42965+ unsigned long pax_flags = 0UL;
42966+
42967+#ifdef CONFIG_PAX_PAGEEXEC
42968+ if (elf_phdata->p_flags & PF_PAGEEXEC)
42969+ pax_flags |= MF_PAX_PAGEEXEC;
42970+#endif
42971+
42972+#ifdef CONFIG_PAX_SEGMEXEC
42973+ if (elf_phdata->p_flags & PF_SEGMEXEC)
42974+ pax_flags |= MF_PAX_SEGMEXEC;
42975+#endif
42976+
42977+#ifdef CONFIG_PAX_EMUTRAMP
42978+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
42979+ pax_flags |= MF_PAX_EMUTRAMP;
42980+#endif
42981+
42982+#ifdef CONFIG_PAX_MPROTECT
42983+ if (elf_phdata->p_flags & PF_MPROTECT)
42984+ pax_flags |= MF_PAX_MPROTECT;
42985+#endif
42986+
42987+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42988+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42989+ pax_flags |= MF_PAX_RANDMMAP;
42990+#endif
42991+
42992+ return pax_flags;
42993+}
42994+#endif
42995+
42996+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42997+{
42998+ unsigned long pax_flags = 0UL;
42999+
43000+#ifdef CONFIG_PAX_PAGEEXEC
43001+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43002+ pax_flags |= MF_PAX_PAGEEXEC;
43003+#endif
43004+
43005+#ifdef CONFIG_PAX_SEGMEXEC
43006+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43007+ pax_flags |= MF_PAX_SEGMEXEC;
43008+#endif
43009+
43010+#ifdef CONFIG_PAX_EMUTRAMP
43011+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43012+ pax_flags |= MF_PAX_EMUTRAMP;
43013+#endif
43014+
43015+#ifdef CONFIG_PAX_MPROTECT
43016+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43017+ pax_flags |= MF_PAX_MPROTECT;
43018+#endif
43019+
43020+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43021+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43022+ pax_flags |= MF_PAX_RANDMMAP;
43023+#endif
43024+
43025+ return pax_flags;
43026+}
43027+#endif
43028+
43029+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43030+#ifdef CONFIG_PAX_SOFTMODE
43031+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43032+{
43033+ unsigned long pax_flags = 0UL;
43034+
43035+#ifdef CONFIG_PAX_PAGEEXEC
43036+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43037+ pax_flags |= MF_PAX_PAGEEXEC;
43038+#endif
43039+
43040+#ifdef CONFIG_PAX_SEGMEXEC
43041+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43042+ pax_flags |= MF_PAX_SEGMEXEC;
43043+#endif
43044+
43045+#ifdef CONFIG_PAX_EMUTRAMP
43046+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43047+ pax_flags |= MF_PAX_EMUTRAMP;
43048+#endif
43049+
43050+#ifdef CONFIG_PAX_MPROTECT
43051+ if (pax_flags_softmode & MF_PAX_MPROTECT)
43052+ pax_flags |= MF_PAX_MPROTECT;
43053+#endif
43054+
43055+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43056+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43057+ pax_flags |= MF_PAX_RANDMMAP;
43058+#endif
43059+
43060+ return pax_flags;
43061+}
43062+#endif
43063+
43064+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43065+{
43066+ unsigned long pax_flags = 0UL;
43067+
43068+#ifdef CONFIG_PAX_PAGEEXEC
43069+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43070+ pax_flags |= MF_PAX_PAGEEXEC;
43071+#endif
43072+
43073+#ifdef CONFIG_PAX_SEGMEXEC
43074+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43075+ pax_flags |= MF_PAX_SEGMEXEC;
43076+#endif
43077+
43078+#ifdef CONFIG_PAX_EMUTRAMP
43079+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43080+ pax_flags |= MF_PAX_EMUTRAMP;
43081+#endif
43082+
43083+#ifdef CONFIG_PAX_MPROTECT
43084+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43085+ pax_flags |= MF_PAX_MPROTECT;
43086+#endif
43087+
43088+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43089+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43090+ pax_flags |= MF_PAX_RANDMMAP;
43091+#endif
43092+
43093+ return pax_flags;
43094+}
43095+#endif
43096+
43097+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43098+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43099+{
43100+ unsigned long pax_flags = 0UL;
43101+
43102+#ifdef CONFIG_PAX_EI_PAX
43103+
43104+#ifdef CONFIG_PAX_PAGEEXEC
43105+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43106+ pax_flags |= MF_PAX_PAGEEXEC;
43107+#endif
43108+
43109+#ifdef CONFIG_PAX_SEGMEXEC
43110+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43111+ pax_flags |= MF_PAX_SEGMEXEC;
43112+#endif
43113+
43114+#ifdef CONFIG_PAX_EMUTRAMP
43115+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43116+ pax_flags |= MF_PAX_EMUTRAMP;
43117+#endif
43118+
43119+#ifdef CONFIG_PAX_MPROTECT
43120+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43121+ pax_flags |= MF_PAX_MPROTECT;
43122+#endif
43123+
43124+#ifdef CONFIG_PAX_ASLR
43125+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43126+ pax_flags |= MF_PAX_RANDMMAP;
43127+#endif
43128+
43129+#else
43130+
43131+#ifdef CONFIG_PAX_PAGEEXEC
43132+ pax_flags |= MF_PAX_PAGEEXEC;
43133+#endif
43134+
43135+#ifdef CONFIG_PAX_SEGMEXEC
43136+ pax_flags |= MF_PAX_SEGMEXEC;
43137+#endif
43138+
43139+#ifdef CONFIG_PAX_MPROTECT
43140+ pax_flags |= MF_PAX_MPROTECT;
43141+#endif
43142+
43143+#ifdef CONFIG_PAX_RANDMMAP
43144+ if (randomize_va_space)
43145+ pax_flags |= MF_PAX_RANDMMAP;
43146+#endif
43147+
43148+#endif
43149+
43150+ return pax_flags;
43151+}
43152+
43153+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43154+{
43155+
43156+#ifdef CONFIG_PAX_PT_PAX_FLAGS
43157+ unsigned long i;
43158+
43159+ for (i = 0UL; i < elf_ex->e_phnum; i++)
43160+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43161+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43162+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43163+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43164+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43165+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43166+ return ~0UL;
43167+
43168+#ifdef CONFIG_PAX_SOFTMODE
43169+ if (pax_softmode)
43170+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43171+ else
43172+#endif
43173+
43174+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43175+ break;
43176+ }
43177+#endif
43178+
43179+ return ~0UL;
43180+}
43181+
43182+static unsigned long pax_parse_xattr_pax(struct file * const file)
43183+{
43184+
43185+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43186+ ssize_t xattr_size, i;
43187+ unsigned char xattr_value[5];
43188+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43189+
43190+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43191+ if (xattr_size <= 0)
43192+ return ~0UL;
43193+
43194+ for (i = 0; i < xattr_size; i++)
43195+ switch (xattr_value[i]) {
43196+ default:
43197+ return ~0UL;
43198+
43199+#define parse_flag(option1, option2, flag) \
43200+ case option1: \
43201+ pax_flags_hardmode |= MF_PAX_##flag; \
43202+ break; \
43203+ case option2: \
43204+ pax_flags_softmode |= MF_PAX_##flag; \
43205+ break;
43206+
43207+ parse_flag('p', 'P', PAGEEXEC);
43208+ parse_flag('e', 'E', EMUTRAMP);
43209+ parse_flag('m', 'M', MPROTECT);
43210+ parse_flag('r', 'R', RANDMMAP);
43211+ parse_flag('s', 'S', SEGMEXEC);
43212+
43213+#undef parse_flag
43214+ }
43215+
43216+ if (pax_flags_hardmode & pax_flags_softmode)
43217+ return ~0UL;
43218+
43219+#ifdef CONFIG_PAX_SOFTMODE
43220+ if (pax_softmode)
43221+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43222+ else
43223+#endif
43224+
43225+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43226+#else
43227+ return ~0UL;
43228+#endif
43229+
43230+}
43231+
43232+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43233+{
43234+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43235+
43236+ pax_flags = pax_parse_ei_pax(elf_ex);
43237+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43238+ xattr_pax_flags = pax_parse_xattr_pax(file);
43239+
43240+ if (pt_pax_flags == ~0UL)
43241+ pt_pax_flags = xattr_pax_flags;
43242+ else if (xattr_pax_flags == ~0UL)
43243+ xattr_pax_flags = pt_pax_flags;
43244+ if (pt_pax_flags != xattr_pax_flags)
43245+ return -EINVAL;
43246+ if (pt_pax_flags != ~0UL)
43247+ pax_flags = pt_pax_flags;
43248+
43249+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43250+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43251+ if ((__supported_pte_mask & _PAGE_NX))
43252+ pax_flags &= ~MF_PAX_SEGMEXEC;
43253+ else
43254+ pax_flags &= ~MF_PAX_PAGEEXEC;
43255+ }
43256+#endif
43257+
43258+ if (0 > pax_check_flags(&pax_flags))
43259+ return -EINVAL;
43260+
43261+ current->mm->pax_flags = pax_flags;
43262+ return 0;
43263+}
43264+#endif
43265+
43266 /*
43267 * These are the functions used to load ELF style executables and shared
43268 * libraries. There is no binary dependent code anywhere else.
43269@@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43270 {
43271 unsigned int random_variable = 0;
43272
43273+#ifdef CONFIG_PAX_RANDUSTACK
43274+ if (randomize_va_space)
43275+ return stack_top - current->mm->delta_stack;
43276+#endif
43277+
43278 if ((current->flags & PF_RANDOMIZE) &&
43279 !(current->personality & ADDR_NO_RANDOMIZE)) {
43280 random_variable = get_random_int() & STACK_RND_MASK;
43281@@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43282 unsigned long load_addr = 0, load_bias = 0;
43283 int load_addr_set = 0;
43284 char * elf_interpreter = NULL;
43285- unsigned long error;
43286+ unsigned long error = 0;
43287 struct elf_phdr *elf_ppnt, *elf_phdata;
43288 unsigned long elf_bss, elf_brk;
43289 int retval, i;
43290@@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43291 unsigned long start_code, end_code, start_data, end_data;
43292 unsigned long reloc_func_desc __maybe_unused = 0;
43293 int executable_stack = EXSTACK_DEFAULT;
43294- unsigned long def_flags = 0;
43295 struct {
43296 struct elfhdr elf_ex;
43297 struct elfhdr interp_elf_ex;
43298 } *loc;
43299+ unsigned long pax_task_size = TASK_SIZE;
43300
43301 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43302 if (!loc) {
43303@@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43304 goto out_free_dentry;
43305
43306 /* OK, This is the point of no return */
43307- current->mm->def_flags = def_flags;
43308+
43309+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43310+ current->mm->pax_flags = 0UL;
43311+#endif
43312+
43313+#ifdef CONFIG_PAX_DLRESOLVE
43314+ current->mm->call_dl_resolve = 0UL;
43315+#endif
43316+
43317+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43318+ current->mm->call_syscall = 0UL;
43319+#endif
43320+
43321+#ifdef CONFIG_PAX_ASLR
43322+ current->mm->delta_mmap = 0UL;
43323+ current->mm->delta_stack = 0UL;
43324+#endif
43325+
43326+ current->mm->def_flags = 0;
43327+
43328+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43329+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43330+ send_sig(SIGKILL, current, 0);
43331+ goto out_free_dentry;
43332+ }
43333+#endif
43334+
43335+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43336+ pax_set_initial_flags(bprm);
43337+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43338+ if (pax_set_initial_flags_func)
43339+ (pax_set_initial_flags_func)(bprm);
43340+#endif
43341+
43342+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43343+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43344+ current->mm->context.user_cs_limit = PAGE_SIZE;
43345+ current->mm->def_flags |= VM_PAGEEXEC;
43346+ }
43347+#endif
43348+
43349+#ifdef CONFIG_PAX_SEGMEXEC
43350+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43351+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43352+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43353+ pax_task_size = SEGMEXEC_TASK_SIZE;
43354+ current->mm->def_flags |= VM_NOHUGEPAGE;
43355+ }
43356+#endif
43357+
43358+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43359+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43360+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43361+ put_cpu();
43362+ }
43363+#endif
43364
43365 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43366 may depend on the personality. */
43367 SET_PERSONALITY(loc->elf_ex);
43368+
43369+#ifdef CONFIG_PAX_ASLR
43370+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43371+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43372+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43373+ }
43374+#endif
43375+
43376+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43377+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43378+ executable_stack = EXSTACK_DISABLE_X;
43379+ current->personality &= ~READ_IMPLIES_EXEC;
43380+ } else
43381+#endif
43382+
43383 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43384 current->personality |= READ_IMPLIES_EXEC;
43385
43386@@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43387 #else
43388 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43389 #endif
43390+
43391+#ifdef CONFIG_PAX_RANDMMAP
43392+ /* PaX: randomize base address at the default exe base if requested */
43393+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43394+#ifdef CONFIG_SPARC64
43395+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43396+#else
43397+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43398+#endif
43399+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43400+ elf_flags |= MAP_FIXED;
43401+ }
43402+#endif
43403+
43404 }
43405
43406 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43407@@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43408 * allowed task size. Note that p_filesz must always be
43409 * <= p_memsz so it is only necessary to check p_memsz.
43410 */
43411- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43412- elf_ppnt->p_memsz > TASK_SIZE ||
43413- TASK_SIZE - elf_ppnt->p_memsz < k) {
43414+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43415+ elf_ppnt->p_memsz > pax_task_size ||
43416+ pax_task_size - elf_ppnt->p_memsz < k) {
43417 /* set_brk can never work. Avoid overflows. */
43418 send_sig(SIGKILL, current, 0);
43419 retval = -EINVAL;
43420@@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43421 goto out_free_dentry;
43422 }
43423 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43424- send_sig(SIGSEGV, current, 0);
43425- retval = -EFAULT; /* Nobody gets to see this, but.. */
43426- goto out_free_dentry;
43427+ /*
43428+ * This bss-zeroing can fail if the ELF
43429+ * file specifies odd protections. So
43430+ * we don't check the return value
43431+ */
43432 }
43433
43434+#ifdef CONFIG_PAX_RANDMMAP
43435+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43436+ unsigned long start, size;
43437+
43438+ start = ELF_PAGEALIGN(elf_brk);
43439+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43440+ down_read(&current->mm->mmap_sem);
43441+ retval = -ENOMEM;
43442+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43443+ unsigned long prot = PROT_NONE;
43444+
43445+ up_read(&current->mm->mmap_sem);
43446+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43447+// if (current->personality & ADDR_NO_RANDOMIZE)
43448+// prot = PROT_READ;
43449+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43450+ retval = IS_ERR_VALUE(start) ? start : 0;
43451+ } else
43452+ up_read(&current->mm->mmap_sem);
43453+ if (retval == 0)
43454+ retval = set_brk(start + size, start + size + PAGE_SIZE);
43455+ if (retval < 0) {
43456+ send_sig(SIGKILL, current, 0);
43457+ goto out_free_dentry;
43458+ }
43459+ }
43460+#endif
43461+
43462 if (elf_interpreter) {
43463 unsigned long uninitialized_var(interp_map_addr);
43464
43465@@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43466 * Decide what to dump of a segment, part, all or none.
43467 */
43468 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43469- unsigned long mm_flags)
43470+ unsigned long mm_flags, long signr)
43471 {
43472 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43473
43474@@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43475 if (vma->vm_file == NULL)
43476 return 0;
43477
43478- if (FILTER(MAPPED_PRIVATE))
43479+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43480 goto whole;
43481
43482 /*
43483@@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43484 {
43485 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43486 int i = 0;
43487- do
43488+ do {
43489 i += 2;
43490- while (auxv[i - 2] != AT_NULL);
43491+ } while (auxv[i - 2] != AT_NULL);
43492 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43493 }
43494
43495@@ -1879,14 +2327,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43496 }
43497
43498 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43499- unsigned long mm_flags)
43500+ struct coredump_params *cprm)
43501 {
43502 struct vm_area_struct *vma;
43503 size_t size = 0;
43504
43505 for (vma = first_vma(current, gate_vma); vma != NULL;
43506 vma = next_vma(vma, gate_vma))
43507- size += vma_dump_size(vma, mm_flags);
43508+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43509 return size;
43510 }
43511
43512@@ -1980,7 +2428,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43513
43514 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43515
43516- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43517+ offset += elf_core_vma_data_size(gate_vma, cprm);
43518 offset += elf_core_extra_data_size();
43519 e_shoff = offset;
43520
43521@@ -1994,10 +2442,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43522 offset = dataoff;
43523
43524 size += sizeof(*elf);
43525+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43526 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43527 goto end_coredump;
43528
43529 size += sizeof(*phdr4note);
43530+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43531 if (size > cprm->limit
43532 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43533 goto end_coredump;
43534@@ -2011,7 +2461,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43535 phdr.p_offset = offset;
43536 phdr.p_vaddr = vma->vm_start;
43537 phdr.p_paddr = 0;
43538- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43539+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43540 phdr.p_memsz = vma->vm_end - vma->vm_start;
43541 offset += phdr.p_filesz;
43542 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43543@@ -2022,6 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43544 phdr.p_align = ELF_EXEC_PAGESIZE;
43545
43546 size += sizeof(phdr);
43547+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43548 if (size > cprm->limit
43549 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43550 goto end_coredump;
43551@@ -2046,7 +2497,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43552 unsigned long addr;
43553 unsigned long end;
43554
43555- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43556+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43557
43558 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43559 struct page *page;
43560@@ -2055,6 +2506,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43561 page = get_dump_page(addr);
43562 if (page) {
43563 void *kaddr = kmap(page);
43564+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43565 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43566 !dump_write(cprm->file, kaddr,
43567 PAGE_SIZE);
43568@@ -2072,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43569
43570 if (e_phnum == PN_XNUM) {
43571 size += sizeof(*shdr4extnum);
43572+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43573 if (size > cprm->limit
43574 || !dump_write(cprm->file, shdr4extnum,
43575 sizeof(*shdr4extnum)))
43576@@ -2092,6 +2545,97 @@ out:
43577
43578 #endif /* CONFIG_ELF_CORE */
43579
43580+#ifdef CONFIG_PAX_MPROTECT
43581+/* PaX: non-PIC ELF libraries need relocations on their executable segments
43582+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43583+ * we'll remove VM_MAYWRITE for good on RELRO segments.
43584+ *
43585+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43586+ * basis because we want to allow the common case and not the special ones.
43587+ */
43588+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43589+{
43590+ struct elfhdr elf_h;
43591+ struct elf_phdr elf_p;
43592+ unsigned long i;
43593+ unsigned long oldflags;
43594+ bool is_textrel_rw, is_textrel_rx, is_relro;
43595+
43596+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43597+ return;
43598+
43599+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43600+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43601+
43602+#ifdef CONFIG_PAX_ELFRELOCS
43603+ /* possible TEXTREL */
43604+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43605+ 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);
43606+#else
43607+ is_textrel_rw = false;
43608+ is_textrel_rx = false;
43609+#endif
43610+
43611+ /* possible RELRO */
43612+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43613+
43614+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43615+ return;
43616+
43617+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43618+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43619+
43620+#ifdef CONFIG_PAX_ETEXECRELOCS
43621+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43622+#else
43623+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43624+#endif
43625+
43626+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43627+ !elf_check_arch(&elf_h) ||
43628+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43629+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43630+ return;
43631+
43632+ for (i = 0UL; i < elf_h.e_phnum; i++) {
43633+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43634+ return;
43635+ switch (elf_p.p_type) {
43636+ case PT_DYNAMIC:
43637+ if (!is_textrel_rw && !is_textrel_rx)
43638+ continue;
43639+ i = 0UL;
43640+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43641+ elf_dyn dyn;
43642+
43643+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43644+ return;
43645+ if (dyn.d_tag == DT_NULL)
43646+ return;
43647+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43648+ gr_log_textrel(vma);
43649+ if (is_textrel_rw)
43650+ vma->vm_flags |= VM_MAYWRITE;
43651+ else
43652+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43653+ vma->vm_flags &= ~VM_MAYWRITE;
43654+ return;
43655+ }
43656+ i++;
43657+ }
43658+ return;
43659+
43660+ case PT_GNU_RELRO:
43661+ if (!is_relro)
43662+ continue;
43663+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43664+ vma->vm_flags &= ~VM_MAYWRITE;
43665+ return;
43666+ }
43667+ }
43668+}
43669+#endif
43670+
43671 static int __init init_elf_binfmt(void)
43672 {
43673 register_binfmt(&elf_format);
43674diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43675index 178cb70..8972997 100644
43676--- a/fs/binfmt_flat.c
43677+++ b/fs/binfmt_flat.c
43678@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43679 realdatastart = (unsigned long) -ENOMEM;
43680 printk("Unable to allocate RAM for process data, errno %d\n",
43681 (int)-realdatastart);
43682+ down_write(&current->mm->mmap_sem);
43683 vm_munmap(textpos, text_len);
43684+ up_write(&current->mm->mmap_sem);
43685 ret = realdatastart;
43686 goto err;
43687 }
43688@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43689 }
43690 if (IS_ERR_VALUE(result)) {
43691 printk("Unable to read data+bss, errno %d\n", (int)-result);
43692+ down_write(&current->mm->mmap_sem);
43693 vm_munmap(textpos, text_len);
43694 vm_munmap(realdatastart, len);
43695+ up_write(&current->mm->mmap_sem);
43696 ret = result;
43697 goto err;
43698 }
43699@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43700 }
43701 if (IS_ERR_VALUE(result)) {
43702 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43703+ down_write(&current->mm->mmap_sem);
43704 vm_munmap(textpos, text_len + data_len + extra +
43705 MAX_SHARED_LIBS * sizeof(unsigned long));
43706+ up_write(&current->mm->mmap_sem);
43707 ret = result;
43708 goto err;
43709 }
43710diff --git a/fs/bio.c b/fs/bio.c
43711index 71072ab..439851b 100644
43712--- a/fs/bio.c
43713+++ b/fs/bio.c
43714@@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43715 /*
43716 * Overflow, abort
43717 */
43718- if (end < start)
43719+ if (end < start || end - start > INT_MAX - nr_pages)
43720 return ERR_PTR(-EINVAL);
43721
43722 nr_pages += end - start;
43723@@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43724 /*
43725 * Overflow, abort
43726 */
43727- if (end < start)
43728+ if (end < start || end - start > INT_MAX - nr_pages)
43729 return ERR_PTR(-EINVAL);
43730
43731 nr_pages += end - start;
43732@@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43733 const int read = bio_data_dir(bio) == READ;
43734 struct bio_map_data *bmd = bio->bi_private;
43735 int i;
43736- char *p = bmd->sgvecs[0].iov_base;
43737+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43738
43739 __bio_for_each_segment(bvec, bio, i, 0) {
43740 char *addr = page_address(bvec->bv_page);
43741diff --git a/fs/block_dev.c b/fs/block_dev.c
43742index 38e721b..7a9c5bc 100644
43743--- a/fs/block_dev.c
43744+++ b/fs/block_dev.c
43745@@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43746 else if (bdev->bd_contains == bdev)
43747 return true; /* is a whole device which isn't held */
43748
43749- else if (whole->bd_holder == bd_may_claim)
43750+ else if (whole->bd_holder == (void *)bd_may_claim)
43751 return true; /* is a partition of a device that is being partitioned */
43752 else if (whole->bd_holder != NULL)
43753 return false; /* is a partition of a held device */
43754diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43755index 9197e2e..7f731f8 100644
43756--- a/fs/btrfs/check-integrity.c
43757+++ b/fs/btrfs/check-integrity.c
43758@@ -155,7 +155,7 @@ struct btrfsic_block {
43759 union {
43760 bio_end_io_t *bio;
43761 bh_end_io_t *bh;
43762- } orig_bio_bh_end_io;
43763+ } __no_const orig_bio_bh_end_io;
43764 int submit_bio_bh_rw;
43765 u64 flush_gen; /* only valid if !never_written */
43766 };
43767diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43768index 6d183f6..f47cc7a 100644
43769--- a/fs/btrfs/ctree.c
43770+++ b/fs/btrfs/ctree.c
43771@@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43772 free_extent_buffer(buf);
43773 add_root_to_dirty_list(root);
43774 } else {
43775- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43776- parent_start = parent->start;
43777- else
43778+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43779+ if (parent)
43780+ parent_start = parent->start;
43781+ else
43782+ parent_start = 0;
43783+ } else
43784 parent_start = 0;
43785
43786 WARN_ON(trans->transid != btrfs_header_generation(parent));
43787diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43788index ec154f9..bf617a7 100644
43789--- a/fs/btrfs/inode.c
43790+++ b/fs/btrfs/inode.c
43791@@ -7126,7 +7126,7 @@ fail:
43792 return -ENOMEM;
43793 }
43794
43795-static int btrfs_getattr(struct vfsmount *mnt,
43796+int btrfs_getattr(struct vfsmount *mnt,
43797 struct dentry *dentry, struct kstat *stat)
43798 {
43799 struct inode *inode = dentry->d_inode;
43800@@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43801 return 0;
43802 }
43803
43804+EXPORT_SYMBOL(btrfs_getattr);
43805+
43806+dev_t get_btrfs_dev_from_inode(struct inode *inode)
43807+{
43808+ return BTRFS_I(inode)->root->anon_dev;
43809+}
43810+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43811+
43812 /*
43813 * If a file is moved, it will inherit the cow and compression flags of the new
43814 * directory.
43815diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43816index 9df50fa..6cd20d0 100644
43817--- a/fs/btrfs/ioctl.c
43818+++ b/fs/btrfs/ioctl.c
43819@@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43820 for (i = 0; i < num_types; i++) {
43821 struct btrfs_space_info *tmp;
43822
43823+ /* Don't copy in more than we allocated */
43824 if (!slot_count)
43825 break;
43826
43827+ slot_count--;
43828+
43829 info = NULL;
43830 rcu_read_lock();
43831 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43832@@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43833 memcpy(dest, &space, sizeof(space));
43834 dest++;
43835 space_args.total_spaces++;
43836- slot_count--;
43837 }
43838- if (!slot_count)
43839- break;
43840 }
43841 up_read(&info->groups_sem);
43842 }
43843diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43844index 4da0865..01c4778 100644
43845--- a/fs/btrfs/relocation.c
43846+++ b/fs/btrfs/relocation.c
43847@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43848 }
43849 spin_unlock(&rc->reloc_root_tree.lock);
43850
43851- BUG_ON((struct btrfs_root *)node->data != root);
43852+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
43853
43854 if (!del) {
43855 spin_lock(&rc->reloc_root_tree.lock);
43856diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43857index 622f469..e8d2d55 100644
43858--- a/fs/cachefiles/bind.c
43859+++ b/fs/cachefiles/bind.c
43860@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43861 args);
43862
43863 /* start by checking things over */
43864- ASSERT(cache->fstop_percent >= 0 &&
43865- cache->fstop_percent < cache->fcull_percent &&
43866+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
43867 cache->fcull_percent < cache->frun_percent &&
43868 cache->frun_percent < 100);
43869
43870- ASSERT(cache->bstop_percent >= 0 &&
43871- cache->bstop_percent < cache->bcull_percent &&
43872+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
43873 cache->bcull_percent < cache->brun_percent &&
43874 cache->brun_percent < 100);
43875
43876diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43877index 0a1467b..6a53245 100644
43878--- a/fs/cachefiles/daemon.c
43879+++ b/fs/cachefiles/daemon.c
43880@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43881 if (n > buflen)
43882 return -EMSGSIZE;
43883
43884- if (copy_to_user(_buffer, buffer, n) != 0)
43885+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43886 return -EFAULT;
43887
43888 return n;
43889@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43890 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43891 return -EIO;
43892
43893- if (datalen < 0 || datalen > PAGE_SIZE - 1)
43894+ if (datalen > PAGE_SIZE - 1)
43895 return -EOPNOTSUPP;
43896
43897 /* drag the command string into the kernel so we can parse it */
43898@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43899 if (args[0] != '%' || args[1] != '\0')
43900 return -EINVAL;
43901
43902- if (fstop < 0 || fstop >= cache->fcull_percent)
43903+ if (fstop >= cache->fcull_percent)
43904 return cachefiles_daemon_range_error(cache, args);
43905
43906 cache->fstop_percent = fstop;
43907@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43908 if (args[0] != '%' || args[1] != '\0')
43909 return -EINVAL;
43910
43911- if (bstop < 0 || bstop >= cache->bcull_percent)
43912+ if (bstop >= cache->bcull_percent)
43913 return cachefiles_daemon_range_error(cache, args);
43914
43915 cache->bstop_percent = bstop;
43916diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43917index bd6bc1b..b627b53 100644
43918--- a/fs/cachefiles/internal.h
43919+++ b/fs/cachefiles/internal.h
43920@@ -57,7 +57,7 @@ struct cachefiles_cache {
43921 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43922 struct rb_root active_nodes; /* active nodes (can't be culled) */
43923 rwlock_t active_lock; /* lock for active_nodes */
43924- atomic_t gravecounter; /* graveyard uniquifier */
43925+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43926 unsigned frun_percent; /* when to stop culling (% files) */
43927 unsigned fcull_percent; /* when to start culling (% files) */
43928 unsigned fstop_percent; /* when to stop allocating (% files) */
43929@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43930 * proc.c
43931 */
43932 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43933-extern atomic_t cachefiles_lookup_histogram[HZ];
43934-extern atomic_t cachefiles_mkdir_histogram[HZ];
43935-extern atomic_t cachefiles_create_histogram[HZ];
43936+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43937+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43938+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43939
43940 extern int __init cachefiles_proc_init(void);
43941 extern void cachefiles_proc_cleanup(void);
43942 static inline
43943-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43944+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43945 {
43946 unsigned long jif = jiffies - start_jif;
43947 if (jif >= HZ)
43948 jif = HZ - 1;
43949- atomic_inc(&histogram[jif]);
43950+ atomic_inc_unchecked(&histogram[jif]);
43951 }
43952
43953 #else
43954diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43955index b0b5f7c..039bb26 100644
43956--- a/fs/cachefiles/namei.c
43957+++ b/fs/cachefiles/namei.c
43958@@ -318,7 +318,7 @@ try_again:
43959 /* first step is to make up a grave dentry in the graveyard */
43960 sprintf(nbuffer, "%08x%08x",
43961 (uint32_t) get_seconds(),
43962- (uint32_t) atomic_inc_return(&cache->gravecounter));
43963+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43964
43965 /* do the multiway lock magic */
43966 trap = lock_rename(cache->graveyard, dir);
43967diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43968index eccd339..4c1d995 100644
43969--- a/fs/cachefiles/proc.c
43970+++ b/fs/cachefiles/proc.c
43971@@ -14,9 +14,9 @@
43972 #include <linux/seq_file.h>
43973 #include "internal.h"
43974
43975-atomic_t cachefiles_lookup_histogram[HZ];
43976-atomic_t cachefiles_mkdir_histogram[HZ];
43977-atomic_t cachefiles_create_histogram[HZ];
43978+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43979+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43980+atomic_unchecked_t cachefiles_create_histogram[HZ];
43981
43982 /*
43983 * display the latency histogram
43984@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43985 return 0;
43986 default:
43987 index = (unsigned long) v - 3;
43988- x = atomic_read(&cachefiles_lookup_histogram[index]);
43989- y = atomic_read(&cachefiles_mkdir_histogram[index]);
43990- z = atomic_read(&cachefiles_create_histogram[index]);
43991+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43992+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43993+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43994 if (x == 0 && y == 0 && z == 0)
43995 return 0;
43996
43997diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43998index c994691..2a1537f 100644
43999--- a/fs/cachefiles/rdwr.c
44000+++ b/fs/cachefiles/rdwr.c
44001@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44002 old_fs = get_fs();
44003 set_fs(KERNEL_DS);
44004 ret = file->f_op->write(
44005- file, (const void __user *) data, len, &pos);
44006+ file, (const void __force_user *) data, len, &pos);
44007 set_fs(old_fs);
44008 kunmap(page);
44009 if (ret != len)
44010diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44011index e5b7731..b9c59fb 100644
44012--- a/fs/ceph/dir.c
44013+++ b/fs/ceph/dir.c
44014@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44015 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44016 struct ceph_mds_client *mdsc = fsc->mdsc;
44017 unsigned frag = fpos_frag(filp->f_pos);
44018- int off = fpos_off(filp->f_pos);
44019+ unsigned int off = fpos_off(filp->f_pos);
44020 int err;
44021 u32 ftype;
44022 struct ceph_mds_reply_info_parsed *rinfo;
44023diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44024index d9ea6ed..1e6c8ac 100644
44025--- a/fs/cifs/cifs_debug.c
44026+++ b/fs/cifs/cifs_debug.c
44027@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44028
44029 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44030 #ifdef CONFIG_CIFS_STATS2
44031- atomic_set(&totBufAllocCount, 0);
44032- atomic_set(&totSmBufAllocCount, 0);
44033+ atomic_set_unchecked(&totBufAllocCount, 0);
44034+ atomic_set_unchecked(&totSmBufAllocCount, 0);
44035 #endif /* CONFIG_CIFS_STATS2 */
44036 spin_lock(&cifs_tcp_ses_lock);
44037 list_for_each(tmp1, &cifs_tcp_ses_list) {
44038@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44039 tcon = list_entry(tmp3,
44040 struct cifs_tcon,
44041 tcon_list);
44042- atomic_set(&tcon->num_smbs_sent, 0);
44043+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44044 if (server->ops->clear_stats)
44045 server->ops->clear_stats(tcon);
44046 }
44047@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44048 smBufAllocCount.counter, cifs_min_small);
44049 #ifdef CONFIG_CIFS_STATS2
44050 seq_printf(m, "Total Large %d Small %d Allocations\n",
44051- atomic_read(&totBufAllocCount),
44052- atomic_read(&totSmBufAllocCount));
44053+ atomic_read_unchecked(&totBufAllocCount),
44054+ atomic_read_unchecked(&totSmBufAllocCount));
44055 #endif /* CONFIG_CIFS_STATS2 */
44056
44057 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44058@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44059 if (tcon->need_reconnect)
44060 seq_puts(m, "\tDISCONNECTED ");
44061 seq_printf(m, "\nSMBs: %d",
44062- atomic_read(&tcon->num_smbs_sent));
44063+ atomic_read_unchecked(&tcon->num_smbs_sent));
44064 if (server->ops->print_stats)
44065 server->ops->print_stats(m, tcon);
44066 }
44067diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44068index db8a404..c712e2e 100644
44069--- a/fs/cifs/cifsfs.c
44070+++ b/fs/cifs/cifsfs.c
44071@@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44072 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44073 cifs_req_cachep = kmem_cache_create("cifs_request",
44074 CIFSMaxBufSize + max_hdr_size, 0,
44075- SLAB_HWCACHE_ALIGN, NULL);
44076+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44077 if (cifs_req_cachep == NULL)
44078 return -ENOMEM;
44079
44080@@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44081 efficient to alloc 1 per page off the slab compared to 17K (5page)
44082 alloc of large cifs buffers even when page debugging is on */
44083 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44084- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44085+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44086 NULL);
44087 if (cifs_sm_req_cachep == NULL) {
44088 mempool_destroy(cifs_req_poolp);
44089@@ -1115,8 +1115,8 @@ init_cifs(void)
44090 atomic_set(&bufAllocCount, 0);
44091 atomic_set(&smBufAllocCount, 0);
44092 #ifdef CONFIG_CIFS_STATS2
44093- atomic_set(&totBufAllocCount, 0);
44094- atomic_set(&totSmBufAllocCount, 0);
44095+ atomic_set_unchecked(&totBufAllocCount, 0);
44096+ atomic_set_unchecked(&totSmBufAllocCount, 0);
44097 #endif /* CONFIG_CIFS_STATS2 */
44098
44099 atomic_set(&midCount, 0);
44100diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44101index 977dc0e..ba48ab9 100644
44102--- a/fs/cifs/cifsglob.h
44103+++ b/fs/cifs/cifsglob.h
44104@@ -590,35 +590,35 @@ struct cifs_tcon {
44105 __u16 Flags; /* optional support bits */
44106 enum statusEnum tidStatus;
44107 #ifdef CONFIG_CIFS_STATS
44108- atomic_t num_smbs_sent;
44109+ atomic_unchecked_t num_smbs_sent;
44110 union {
44111 struct {
44112- atomic_t num_writes;
44113- atomic_t num_reads;
44114- atomic_t num_flushes;
44115- atomic_t num_oplock_brks;
44116- atomic_t num_opens;
44117- atomic_t num_closes;
44118- atomic_t num_deletes;
44119- atomic_t num_mkdirs;
44120- atomic_t num_posixopens;
44121- atomic_t num_posixmkdirs;
44122- atomic_t num_rmdirs;
44123- atomic_t num_renames;
44124- atomic_t num_t2renames;
44125- atomic_t num_ffirst;
44126- atomic_t num_fnext;
44127- atomic_t num_fclose;
44128- atomic_t num_hardlinks;
44129- atomic_t num_symlinks;
44130- atomic_t num_locks;
44131- atomic_t num_acl_get;
44132- atomic_t num_acl_set;
44133+ atomic_unchecked_t num_writes;
44134+ atomic_unchecked_t num_reads;
44135+ atomic_unchecked_t num_flushes;
44136+ atomic_unchecked_t num_oplock_brks;
44137+ atomic_unchecked_t num_opens;
44138+ atomic_unchecked_t num_closes;
44139+ atomic_unchecked_t num_deletes;
44140+ atomic_unchecked_t num_mkdirs;
44141+ atomic_unchecked_t num_posixopens;
44142+ atomic_unchecked_t num_posixmkdirs;
44143+ atomic_unchecked_t num_rmdirs;
44144+ atomic_unchecked_t num_renames;
44145+ atomic_unchecked_t num_t2renames;
44146+ atomic_unchecked_t num_ffirst;
44147+ atomic_unchecked_t num_fnext;
44148+ atomic_unchecked_t num_fclose;
44149+ atomic_unchecked_t num_hardlinks;
44150+ atomic_unchecked_t num_symlinks;
44151+ atomic_unchecked_t num_locks;
44152+ atomic_unchecked_t num_acl_get;
44153+ atomic_unchecked_t num_acl_set;
44154 } cifs_stats;
44155 #ifdef CONFIG_CIFS_SMB2
44156 struct {
44157- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44158- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44159+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44160+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44161 } smb2_stats;
44162 #endif /* CONFIG_CIFS_SMB2 */
44163 } stats;
44164@@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44165 }
44166
44167 #ifdef CONFIG_CIFS_STATS
44168-#define cifs_stats_inc atomic_inc
44169+#define cifs_stats_inc atomic_inc_unchecked
44170
44171 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44172 unsigned int bytes)
44173@@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44174 /* Various Debug counters */
44175 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44176 #ifdef CONFIG_CIFS_STATS2
44177-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44178-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44179+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44180+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44181 #endif
44182 GLOBAL_EXTERN atomic_t smBufAllocCount;
44183 GLOBAL_EXTERN atomic_t midCount;
44184diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44185index e6ce3b1..adc21fd 100644
44186--- a/fs/cifs/link.c
44187+++ b/fs/cifs/link.c
44188@@ -602,7 +602,7 @@ symlink_exit:
44189
44190 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44191 {
44192- char *p = nd_get_link(nd);
44193+ const char *p = nd_get_link(nd);
44194 if (!IS_ERR(p))
44195 kfree(p);
44196 }
44197diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44198index ce41fee..ac0d27a 100644
44199--- a/fs/cifs/misc.c
44200+++ b/fs/cifs/misc.c
44201@@ -169,7 +169,7 @@ cifs_buf_get(void)
44202 memset(ret_buf, 0, buf_size + 3);
44203 atomic_inc(&bufAllocCount);
44204 #ifdef CONFIG_CIFS_STATS2
44205- atomic_inc(&totBufAllocCount);
44206+ atomic_inc_unchecked(&totBufAllocCount);
44207 #endif /* CONFIG_CIFS_STATS2 */
44208 }
44209
44210@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44211 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44212 atomic_inc(&smBufAllocCount);
44213 #ifdef CONFIG_CIFS_STATS2
44214- atomic_inc(&totSmBufAllocCount);
44215+ atomic_inc_unchecked(&totSmBufAllocCount);
44216 #endif /* CONFIG_CIFS_STATS2 */
44217
44218 }
44219diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44220index 3129ac7..cc4a948 100644
44221--- a/fs/cifs/smb1ops.c
44222+++ b/fs/cifs/smb1ops.c
44223@@ -524,27 +524,27 @@ static void
44224 cifs_clear_stats(struct cifs_tcon *tcon)
44225 {
44226 #ifdef CONFIG_CIFS_STATS
44227- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44228- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44229- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44230- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44231- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44232- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44233- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44234- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44235- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44236- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44237- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44238- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44239- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44240- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44241- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44242- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44243- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44244- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44245- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44246- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44247- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44248+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44249+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44250+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44251+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44252+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44253+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44254+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44255+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44256+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44257+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44258+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44259+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44260+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44261+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44262+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44263+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44264+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44265+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44266+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44267+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44268+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44269 #endif
44270 }
44271
44272@@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44273 {
44274 #ifdef CONFIG_CIFS_STATS
44275 seq_printf(m, " Oplocks breaks: %d",
44276- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44277+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44278 seq_printf(m, "\nReads: %d Bytes: %llu",
44279- atomic_read(&tcon->stats.cifs_stats.num_reads),
44280+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44281 (long long)(tcon->bytes_read));
44282 seq_printf(m, "\nWrites: %d Bytes: %llu",
44283- atomic_read(&tcon->stats.cifs_stats.num_writes),
44284+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44285 (long long)(tcon->bytes_written));
44286 seq_printf(m, "\nFlushes: %d",
44287- atomic_read(&tcon->stats.cifs_stats.num_flushes));
44288+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44289 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44290- atomic_read(&tcon->stats.cifs_stats.num_locks),
44291- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44292- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44293+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44294+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44295+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44296 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44297- atomic_read(&tcon->stats.cifs_stats.num_opens),
44298- atomic_read(&tcon->stats.cifs_stats.num_closes),
44299- atomic_read(&tcon->stats.cifs_stats.num_deletes));
44300+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44301+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44302+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44303 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44304- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44305- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44306+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44307+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44308 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44309- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44310- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44311+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44312+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44313 seq_printf(m, "\nRenames: %d T2 Renames %d",
44314- atomic_read(&tcon->stats.cifs_stats.num_renames),
44315- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44316+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44317+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44318 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44319- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44320- atomic_read(&tcon->stats.cifs_stats.num_fnext),
44321- atomic_read(&tcon->stats.cifs_stats.num_fclose));
44322+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44323+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44324+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44325 #endif
44326 }
44327
44328diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44329index 826209b..fa460f4 100644
44330--- a/fs/cifs/smb2ops.c
44331+++ b/fs/cifs/smb2ops.c
44332@@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44333 #ifdef CONFIG_CIFS_STATS
44334 int i;
44335 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44336- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44337- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44338+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44339+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44340 }
44341 #endif
44342 }
44343@@ -229,66 +229,66 @@ static void
44344 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44345 {
44346 #ifdef CONFIG_CIFS_STATS
44347- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44348- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44349+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44350+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44351 seq_printf(m, "\nNegotiates: %d sent %d failed",
44352- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44353- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44354+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44355+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44356 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44357- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44358- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44359+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44360+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44361 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44362 seq_printf(m, "\nLogoffs: %d sent %d failed",
44363- atomic_read(&sent[SMB2_LOGOFF_HE]),
44364- atomic_read(&failed[SMB2_LOGOFF_HE]));
44365+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44366+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44367 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44368- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44369- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44370+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44371+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44372 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44373- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44374- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44375+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44376+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44377 seq_printf(m, "\nCreates: %d sent %d failed",
44378- atomic_read(&sent[SMB2_CREATE_HE]),
44379- atomic_read(&failed[SMB2_CREATE_HE]));
44380+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44381+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44382 seq_printf(m, "\nCloses: %d sent %d failed",
44383- atomic_read(&sent[SMB2_CLOSE_HE]),
44384- atomic_read(&failed[SMB2_CLOSE_HE]));
44385+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44386+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44387 seq_printf(m, "\nFlushes: %d sent %d failed",
44388- atomic_read(&sent[SMB2_FLUSH_HE]),
44389- atomic_read(&failed[SMB2_FLUSH_HE]));
44390+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44391+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44392 seq_printf(m, "\nReads: %d sent %d failed",
44393- atomic_read(&sent[SMB2_READ_HE]),
44394- atomic_read(&failed[SMB2_READ_HE]));
44395+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
44396+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
44397 seq_printf(m, "\nWrites: %d sent %d failed",
44398- atomic_read(&sent[SMB2_WRITE_HE]),
44399- atomic_read(&failed[SMB2_WRITE_HE]));
44400+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44401+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44402 seq_printf(m, "\nLocks: %d sent %d failed",
44403- atomic_read(&sent[SMB2_LOCK_HE]),
44404- atomic_read(&failed[SMB2_LOCK_HE]));
44405+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44406+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44407 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44408- atomic_read(&sent[SMB2_IOCTL_HE]),
44409- atomic_read(&failed[SMB2_IOCTL_HE]));
44410+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44411+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44412 seq_printf(m, "\nCancels: %d sent %d failed",
44413- atomic_read(&sent[SMB2_CANCEL_HE]),
44414- atomic_read(&failed[SMB2_CANCEL_HE]));
44415+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44416+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44417 seq_printf(m, "\nEchos: %d sent %d failed",
44418- atomic_read(&sent[SMB2_ECHO_HE]),
44419- atomic_read(&failed[SMB2_ECHO_HE]));
44420+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44421+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44422 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44423- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44424- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44425+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44426+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44427 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44428- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44429- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44430+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44431+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44432 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44433- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44434- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44435+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44436+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44437 seq_printf(m, "\nSetInfos: %d sent %d failed",
44438- atomic_read(&sent[SMB2_SET_INFO_HE]),
44439- atomic_read(&failed[SMB2_SET_INFO_HE]));
44440+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44441+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44442 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44443- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44444- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44445+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44446+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44447 #endif
44448 }
44449
44450diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44451index 958ae0e..505c9d0 100644
44452--- a/fs/coda/cache.c
44453+++ b/fs/coda/cache.c
44454@@ -24,7 +24,7 @@
44455 #include "coda_linux.h"
44456 #include "coda_cache.h"
44457
44458-static atomic_t permission_epoch = ATOMIC_INIT(0);
44459+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44460
44461 /* replace or extend an acl cache hit */
44462 void coda_cache_enter(struct inode *inode, int mask)
44463@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44464 struct coda_inode_info *cii = ITOC(inode);
44465
44466 spin_lock(&cii->c_lock);
44467- cii->c_cached_epoch = atomic_read(&permission_epoch);
44468+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44469 if (cii->c_uid != current_fsuid()) {
44470 cii->c_uid = current_fsuid();
44471 cii->c_cached_perm = mask;
44472@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44473 {
44474 struct coda_inode_info *cii = ITOC(inode);
44475 spin_lock(&cii->c_lock);
44476- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44477+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44478 spin_unlock(&cii->c_lock);
44479 }
44480
44481 /* remove all acl caches */
44482 void coda_cache_clear_all(struct super_block *sb)
44483 {
44484- atomic_inc(&permission_epoch);
44485+ atomic_inc_unchecked(&permission_epoch);
44486 }
44487
44488
44489@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44490 spin_lock(&cii->c_lock);
44491 hit = (mask & cii->c_cached_perm) == mask &&
44492 cii->c_uid == current_fsuid() &&
44493- cii->c_cached_epoch == atomic_read(&permission_epoch);
44494+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44495 spin_unlock(&cii->c_lock);
44496
44497 return hit;
44498diff --git a/fs/compat.c b/fs/compat.c
44499index 1bdb350..9f28287 100644
44500--- a/fs/compat.c
44501+++ b/fs/compat.c
44502@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44503
44504 set_fs(KERNEL_DS);
44505 /* The __user pointer cast is valid because of the set_fs() */
44506- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44507+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44508 set_fs(oldfs);
44509 /* truncating is ok because it's a user address */
44510 if (!ret)
44511@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44512 goto out;
44513
44514 ret = -EINVAL;
44515- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44516+ if (nr_segs > UIO_MAXIOV)
44517 goto out;
44518 if (nr_segs > fast_segs) {
44519 ret = -ENOMEM;
44520@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44521
44522 struct compat_readdir_callback {
44523 struct compat_old_linux_dirent __user *dirent;
44524+ struct file * file;
44525 int result;
44526 };
44527
44528@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44529 buf->result = -EOVERFLOW;
44530 return -EOVERFLOW;
44531 }
44532+
44533+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44534+ return 0;
44535+
44536 buf->result++;
44537 dirent = buf->dirent;
44538 if (!access_ok(VERIFY_WRITE, dirent,
44539@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44540
44541 buf.result = 0;
44542 buf.dirent = dirent;
44543+ buf.file = file;
44544
44545 error = vfs_readdir(file, compat_fillonedir, &buf);
44546 if (buf.result)
44547@@ -899,6 +905,7 @@ struct compat_linux_dirent {
44548 struct compat_getdents_callback {
44549 struct compat_linux_dirent __user *current_dir;
44550 struct compat_linux_dirent __user *previous;
44551+ struct file * file;
44552 int count;
44553 int error;
44554 };
44555@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44556 buf->error = -EOVERFLOW;
44557 return -EOVERFLOW;
44558 }
44559+
44560+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44561+ return 0;
44562+
44563 dirent = buf->previous;
44564 if (dirent) {
44565 if (__put_user(offset, &dirent->d_off))
44566@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44567 buf.previous = NULL;
44568 buf.count = count;
44569 buf.error = 0;
44570+ buf.file = file;
44571
44572 error = vfs_readdir(file, compat_filldir, &buf);
44573 if (error >= 0)
44574@@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44575 struct compat_getdents_callback64 {
44576 struct linux_dirent64 __user *current_dir;
44577 struct linux_dirent64 __user *previous;
44578+ struct file * file;
44579 int count;
44580 int error;
44581 };
44582@@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44583 buf->error = -EINVAL; /* only used if we fail.. */
44584 if (reclen > buf->count)
44585 return -EINVAL;
44586+
44587+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44588+ return 0;
44589+
44590 dirent = buf->previous;
44591
44592 if (dirent) {
44593@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44594 buf.previous = NULL;
44595 buf.count = count;
44596 buf.error = 0;
44597+ buf.file = file;
44598
44599 error = vfs_readdir(file, compat_filldir64, &buf);
44600 if (error >= 0)
44601 error = buf.error;
44602 lastdirent = buf.previous;
44603 if (lastdirent) {
44604- typeof(lastdirent->d_off) d_off = file->f_pos;
44605+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44606 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44607 error = -EFAULT;
44608 else
44609diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44610index 112e45a..b59845b 100644
44611--- a/fs/compat_binfmt_elf.c
44612+++ b/fs/compat_binfmt_elf.c
44613@@ -30,11 +30,13 @@
44614 #undef elf_phdr
44615 #undef elf_shdr
44616 #undef elf_note
44617+#undef elf_dyn
44618 #undef elf_addr_t
44619 #define elfhdr elf32_hdr
44620 #define elf_phdr elf32_phdr
44621 #define elf_shdr elf32_shdr
44622 #define elf_note elf32_note
44623+#define elf_dyn Elf32_Dyn
44624 #define elf_addr_t Elf32_Addr
44625
44626 /*
44627diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44628index debdfe0..75d31d4 100644
44629--- a/fs/compat_ioctl.c
44630+++ b/fs/compat_ioctl.c
44631@@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44632
44633 err = get_user(palp, &up->palette);
44634 err |= get_user(length, &up->length);
44635+ if (err)
44636+ return -EFAULT;
44637
44638 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44639 err = put_user(compat_ptr(palp), &up_native->palette);
44640@@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44641 return -EFAULT;
44642 if (__get_user(udata, &ss32->iomem_base))
44643 return -EFAULT;
44644- ss.iomem_base = compat_ptr(udata);
44645+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44646 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44647 __get_user(ss.port_high, &ss32->port_high))
44648 return -EFAULT;
44649@@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44650 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44651 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44652 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44653- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44654+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44655 return -EFAULT;
44656
44657 return ioctl_preallocate(file, p);
44658@@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44659 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44660 {
44661 unsigned int a, b;
44662- a = *(unsigned int *)p;
44663- b = *(unsigned int *)q;
44664+ a = *(const unsigned int *)p;
44665+ b = *(const unsigned int *)q;
44666 if (a > b)
44667 return 1;
44668 if (a < b)
44669diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44670index 7414ae2..d98ad6d 100644
44671--- a/fs/configfs/dir.c
44672+++ b/fs/configfs/dir.c
44673@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44674 }
44675 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44676 struct configfs_dirent *next;
44677- const char * name;
44678+ const unsigned char * name;
44679+ char d_name[sizeof(next->s_dentry->d_iname)];
44680 int len;
44681 struct inode *inode = NULL;
44682
44683@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44684 continue;
44685
44686 name = configfs_get_name(next);
44687- len = strlen(name);
44688+ if (next->s_dentry && name == next->s_dentry->d_iname) {
44689+ len = next->s_dentry->d_name.len;
44690+ memcpy(d_name, name, len);
44691+ name = d_name;
44692+ } else
44693+ len = strlen(name);
44694
44695 /*
44696 * We'll have a dentry and an inode for
44697diff --git a/fs/dcache.c b/fs/dcache.c
44698index 693f95b..95f1223 100644
44699--- a/fs/dcache.c
44700+++ b/fs/dcache.c
44701@@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44702 mempages -= reserve;
44703
44704 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44705- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44706+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44707
44708 dcache_init();
44709 inode_init();
44710diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44711index 4733eab..71ef6fa 100644
44712--- a/fs/debugfs/inode.c
44713+++ b/fs/debugfs/inode.c
44714@@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44715 */
44716 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44717 {
44718+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44719+ return __create_file(name, S_IFDIR | S_IRWXU,
44720+#else
44721 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44722+#endif
44723 parent, NULL, NULL);
44724 }
44725 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44726diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44727index cc7709e..7e7211f 100644
44728--- a/fs/ecryptfs/inode.c
44729+++ b/fs/ecryptfs/inode.c
44730@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44731 old_fs = get_fs();
44732 set_fs(get_ds());
44733 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44734- (char __user *)lower_buf,
44735+ (char __force_user *)lower_buf,
44736 PATH_MAX);
44737 set_fs(old_fs);
44738 if (rc < 0)
44739@@ -706,7 +706,7 @@ out:
44740 static void
44741 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44742 {
44743- char *buf = nd_get_link(nd);
44744+ const char *buf = nd_get_link(nd);
44745 if (!IS_ERR(buf)) {
44746 /* Free the char* */
44747 kfree(buf);
44748diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44749index 412e6ed..4292d22 100644
44750--- a/fs/ecryptfs/miscdev.c
44751+++ b/fs/ecryptfs/miscdev.c
44752@@ -315,7 +315,7 @@ check_list:
44753 goto out_unlock_msg_ctx;
44754 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44755 if (msg_ctx->msg) {
44756- if (copy_to_user(&buf[i], packet_length, packet_length_size))
44757+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44758 goto out_unlock_msg_ctx;
44759 i += packet_length_size;
44760 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44761diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44762index b2a34a1..162fa69 100644
44763--- a/fs/ecryptfs/read_write.c
44764+++ b/fs/ecryptfs/read_write.c
44765@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44766 return -EIO;
44767 fs_save = get_fs();
44768 set_fs(get_ds());
44769- rc = vfs_write(lower_file, data, size, &offset);
44770+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44771 set_fs(fs_save);
44772 mark_inode_dirty_sync(ecryptfs_inode);
44773 return rc;
44774@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44775 return -EIO;
44776 fs_save = get_fs();
44777 set_fs(get_ds());
44778- rc = vfs_read(lower_file, data, size, &offset);
44779+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44780 set_fs(fs_save);
44781 return rc;
44782 }
44783diff --git a/fs/exec.c b/fs/exec.c
44784index 574cf4d..dfe774a 100644
44785--- a/fs/exec.c
44786+++ b/fs/exec.c
44787@@ -55,6 +55,15 @@
44788 #include <linux/pipe_fs_i.h>
44789 #include <linux/oom.h>
44790 #include <linux/compat.h>
44791+#include <linux/random.h>
44792+#include <linux/seq_file.h>
44793+
44794+#ifdef CONFIG_PAX_REFCOUNT
44795+#include <linux/kallsyms.h>
44796+#include <linux/kdebug.h>
44797+#endif
44798+
44799+#include <trace/events/fs.h>
44800
44801 #include <asm/uaccess.h>
44802 #include <asm/mmu_context.h>
44803@@ -66,6 +75,18 @@
44804
44805 #include <trace/events/sched.h>
44806
44807+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44808+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44809+{
44810+ 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");
44811+}
44812+#endif
44813+
44814+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44815+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44816+EXPORT_SYMBOL(pax_set_initial_flags_func);
44817+#endif
44818+
44819 int core_uses_pid;
44820 char core_pattern[CORENAME_MAX_SIZE] = "core";
44821 unsigned int core_pipe_limit;
44822@@ -75,7 +96,7 @@ struct core_name {
44823 char *corename;
44824 int used, size;
44825 };
44826-static atomic_t call_count = ATOMIC_INIT(1);
44827+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44828
44829 /* The maximal length of core_pattern is also specified in sysctl.c */
44830
44831@@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44832 int write)
44833 {
44834 struct page *page;
44835- int ret;
44836
44837-#ifdef CONFIG_STACK_GROWSUP
44838- if (write) {
44839- ret = expand_downwards(bprm->vma, pos);
44840- if (ret < 0)
44841- return NULL;
44842- }
44843-#endif
44844- ret = get_user_pages(current, bprm->mm, pos,
44845- 1, write, 1, &page, NULL);
44846- if (ret <= 0)
44847+ if (0 > expand_downwards(bprm->vma, pos))
44848+ return NULL;
44849+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44850 return NULL;
44851
44852 if (write) {
44853@@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44854 if (size <= ARG_MAX)
44855 return page;
44856
44857+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44858+ // only allow 512KB for argv+env on suid/sgid binaries
44859+ // to prevent easy ASLR exhaustion
44860+ if (((bprm->cred->euid != current_euid()) ||
44861+ (bprm->cred->egid != current_egid())) &&
44862+ (size > (512 * 1024))) {
44863+ put_page(page);
44864+ return NULL;
44865+ }
44866+#endif
44867+
44868 /*
44869 * Limit to 1/4-th the stack size for the argv+env strings.
44870 * This ensures that:
44871@@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44872 vma->vm_end = STACK_TOP_MAX;
44873 vma->vm_start = vma->vm_end - PAGE_SIZE;
44874 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44875+
44876+#ifdef CONFIG_PAX_SEGMEXEC
44877+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44878+#endif
44879+
44880 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44881 INIT_LIST_HEAD(&vma->anon_vma_chain);
44882
44883@@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44884 mm->stack_vm = mm->total_vm = 1;
44885 up_write(&mm->mmap_sem);
44886 bprm->p = vma->vm_end - sizeof(void *);
44887+
44888+#ifdef CONFIG_PAX_RANDUSTACK
44889+ if (randomize_va_space)
44890+ bprm->p ^= random32() & ~PAGE_MASK;
44891+#endif
44892+
44893 return 0;
44894 err:
44895 up_write(&mm->mmap_sem);
44896@@ -395,19 +430,7 @@ err:
44897 return err;
44898 }
44899
44900-struct user_arg_ptr {
44901-#ifdef CONFIG_COMPAT
44902- bool is_compat;
44903-#endif
44904- union {
44905- const char __user *const __user *native;
44906-#ifdef CONFIG_COMPAT
44907- compat_uptr_t __user *compat;
44908-#endif
44909- } ptr;
44910-};
44911-
44912-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44913+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44914 {
44915 const char __user *native;
44916
44917@@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44918 compat_uptr_t compat;
44919
44920 if (get_user(compat, argv.ptr.compat + nr))
44921- return ERR_PTR(-EFAULT);
44922+ return (const char __force_user *)ERR_PTR(-EFAULT);
44923
44924 return compat_ptr(compat);
44925 }
44926 #endif
44927
44928 if (get_user(native, argv.ptr.native + nr))
44929- return ERR_PTR(-EFAULT);
44930+ return (const char __force_user *)ERR_PTR(-EFAULT);
44931
44932 return native;
44933 }
44934@@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44935 if (!p)
44936 break;
44937
44938- if (IS_ERR(p))
44939+ if (IS_ERR((const char __force_kernel *)p))
44940 return -EFAULT;
44941
44942 if (i++ >= max)
44943@@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44944
44945 ret = -EFAULT;
44946 str = get_user_arg_ptr(argv, argc);
44947- if (IS_ERR(str))
44948+ if (IS_ERR((const char __force_kernel *)str))
44949 goto out;
44950
44951 len = strnlen_user(str, MAX_ARG_STRLEN);
44952@@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44953 int r;
44954 mm_segment_t oldfs = get_fs();
44955 struct user_arg_ptr argv = {
44956- .ptr.native = (const char __user *const __user *)__argv,
44957+ .ptr.native = (const char __force_user *const __force_user *)__argv,
44958 };
44959
44960 set_fs(KERNEL_DS);
44961@@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44962 unsigned long new_end = old_end - shift;
44963 struct mmu_gather tlb;
44964
44965- BUG_ON(new_start > new_end);
44966+ if (new_start >= new_end || new_start < mmap_min_addr)
44967+ return -ENOMEM;
44968
44969 /*
44970 * ensure there are no vmas between where we want to go
44971@@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44972 if (vma != find_vma(mm, new_start))
44973 return -EFAULT;
44974
44975+#ifdef CONFIG_PAX_SEGMEXEC
44976+ BUG_ON(pax_find_mirror_vma(vma));
44977+#endif
44978+
44979 /*
44980 * cover the whole range: [new_start, old_end)
44981 */
44982@@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44983 stack_top = arch_align_stack(stack_top);
44984 stack_top = PAGE_ALIGN(stack_top);
44985
44986- if (unlikely(stack_top < mmap_min_addr) ||
44987- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44988- return -ENOMEM;
44989-
44990 stack_shift = vma->vm_end - stack_top;
44991
44992 bprm->p -= stack_shift;
44993@@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44994 bprm->exec -= stack_shift;
44995
44996 down_write(&mm->mmap_sem);
44997+
44998+ /* Move stack pages down in memory. */
44999+ if (stack_shift) {
45000+ ret = shift_arg_pages(vma, stack_shift);
45001+ if (ret)
45002+ goto out_unlock;
45003+ }
45004+
45005 vm_flags = VM_STACK_FLAGS;
45006
45007+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45008+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45009+ vm_flags &= ~VM_EXEC;
45010+
45011+#ifdef CONFIG_PAX_MPROTECT
45012+ if (mm->pax_flags & MF_PAX_MPROTECT)
45013+ vm_flags &= ~VM_MAYEXEC;
45014+#endif
45015+
45016+ }
45017+#endif
45018+
45019 /*
45020 * Adjust stack execute permissions; explicitly enable for
45021 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45022@@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45023 goto out_unlock;
45024 BUG_ON(prev != vma);
45025
45026- /* Move stack pages down in memory. */
45027- if (stack_shift) {
45028- ret = shift_arg_pages(vma, stack_shift);
45029- if (ret)
45030- goto out_unlock;
45031- }
45032-
45033 /* mprotect_fixup is overkill to remove the temporary stack flags */
45034 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45035
45036@@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45037
45038 fsnotify_open(file);
45039
45040+ trace_open_exec(name);
45041+
45042 err = deny_write_access(file);
45043 if (err)
45044 goto exit;
45045@@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45046 old_fs = get_fs();
45047 set_fs(get_ds());
45048 /* The cast to a user pointer is valid due to the set_fs() */
45049- result = vfs_read(file, (void __user *)addr, count, &pos);
45050+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
45051 set_fs(old_fs);
45052 return result;
45053 }
45054@@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45055 }
45056 rcu_read_unlock();
45057
45058- if (p->fs->users > n_fs) {
45059+ if (atomic_read(&p->fs->users) > n_fs) {
45060 bprm->unsafe |= LSM_UNSAFE_SHARE;
45061 } else {
45062 res = -EAGAIN;
45063@@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45064
45065 EXPORT_SYMBOL(search_binary_handler);
45066
45067+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45068+static DEFINE_PER_CPU(u64, exec_counter);
45069+static int __init init_exec_counters(void)
45070+{
45071+ unsigned int cpu;
45072+
45073+ for_each_possible_cpu(cpu) {
45074+ per_cpu(exec_counter, cpu) = (u64)cpu;
45075+ }
45076+
45077+ return 0;
45078+}
45079+early_initcall(init_exec_counters);
45080+static inline void increment_exec_counter(void)
45081+{
45082+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
45083+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45084+}
45085+#else
45086+static inline void increment_exec_counter(void) {}
45087+#endif
45088+
45089 /*
45090 * sys_execve() executes a new program.
45091 */
45092@@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
45093 struct user_arg_ptr envp,
45094 struct pt_regs *regs)
45095 {
45096+#ifdef CONFIG_GRKERNSEC
45097+ struct file *old_exec_file;
45098+ struct acl_subject_label *old_acl;
45099+ struct rlimit old_rlim[RLIM_NLIMITS];
45100+#endif
45101 struct linux_binprm *bprm;
45102 struct file *file;
45103 struct files_struct *displaced;
45104@@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
45105 int retval;
45106 const struct cred *cred = current_cred();
45107
45108+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45109+
45110 /*
45111 * We move the actual failure in case of RLIMIT_NPROC excess from
45112 * set*uid() to execve() because too many poorly written programs
45113@@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
45114 if (IS_ERR(file))
45115 goto out_unmark;
45116
45117+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
45118+ retval = -EPERM;
45119+ goto out_file;
45120+ }
45121+
45122 sched_exec();
45123
45124 bprm->file = file;
45125 bprm->filename = filename;
45126 bprm->interp = filename;
45127
45128+ if (gr_process_user_ban()) {
45129+ retval = -EPERM;
45130+ goto out_file;
45131+ }
45132+
45133+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45134+ retval = -EACCES;
45135+ goto out_file;
45136+ }
45137+
45138 retval = bprm_mm_init(bprm);
45139 if (retval)
45140 goto out_file;
45141@@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
45142 if (retval < 0)
45143 goto out;
45144
45145+#ifdef CONFIG_GRKERNSEC
45146+ old_acl = current->acl;
45147+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45148+ old_exec_file = current->exec_file;
45149+ get_file(file);
45150+ current->exec_file = file;
45151+#endif
45152+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45153+ /* limit suid stack to 8MB
45154+ we saved the old limits above and will restore them if this exec fails
45155+ */
45156+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45157+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45158+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45159+#endif
45160+
45161+ if (!gr_tpe_allow(file)) {
45162+ retval = -EACCES;
45163+ goto out_fail;
45164+ }
45165+
45166+ if (gr_check_crash_exec(file)) {
45167+ retval = -EACCES;
45168+ goto out_fail;
45169+ }
45170+
45171+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45172+ bprm->unsafe);
45173+ if (retval < 0)
45174+ goto out_fail;
45175+
45176 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45177 if (retval < 0)
45178- goto out;
45179+ goto out_fail;
45180
45181 bprm->exec = bprm->p;
45182 retval = copy_strings(bprm->envc, envp, bprm);
45183 if (retval < 0)
45184- goto out;
45185+ goto out_fail;
45186
45187 retval = copy_strings(bprm->argc, argv, bprm);
45188 if (retval < 0)
45189- goto out;
45190+ goto out_fail;
45191+
45192+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45193+
45194+ gr_handle_exec_args(bprm, argv);
45195
45196 retval = search_binary_handler(bprm,regs);
45197 if (retval < 0)
45198- goto out;
45199+ goto out_fail;
45200+#ifdef CONFIG_GRKERNSEC
45201+ if (old_exec_file)
45202+ fput(old_exec_file);
45203+#endif
45204
45205 /* execve succeeded */
45206+
45207+ increment_exec_counter();
45208 current->fs->in_exec = 0;
45209 current->in_execve = 0;
45210 acct_update_integrals(current);
45211@@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
45212 put_files_struct(displaced);
45213 return retval;
45214
45215+out_fail:
45216+#ifdef CONFIG_GRKERNSEC
45217+ current->acl = old_acl;
45218+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45219+ fput(current->exec_file);
45220+ current->exec_file = old_exec_file;
45221+#endif
45222+
45223 out:
45224 if (bprm->mm) {
45225 acct_arg_size(bprm, 0);
45226@@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
45227 {
45228 char *old_corename = cn->corename;
45229
45230- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45231+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45232 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45233
45234 if (!cn->corename) {
45235@@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
45236 int pid_in_pattern = 0;
45237 int err = 0;
45238
45239- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45240+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45241 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45242 cn->used = 0;
45243
45244@@ -1830,6 +1962,250 @@ out:
45245 return ispipe;
45246 }
45247
45248+int pax_check_flags(unsigned long *flags)
45249+{
45250+ int retval = 0;
45251+
45252+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45253+ if (*flags & MF_PAX_SEGMEXEC)
45254+ {
45255+ *flags &= ~MF_PAX_SEGMEXEC;
45256+ retval = -EINVAL;
45257+ }
45258+#endif
45259+
45260+ if ((*flags & MF_PAX_PAGEEXEC)
45261+
45262+#ifdef CONFIG_PAX_PAGEEXEC
45263+ && (*flags & MF_PAX_SEGMEXEC)
45264+#endif
45265+
45266+ )
45267+ {
45268+ *flags &= ~MF_PAX_PAGEEXEC;
45269+ retval = -EINVAL;
45270+ }
45271+
45272+ if ((*flags & MF_PAX_MPROTECT)
45273+
45274+#ifdef CONFIG_PAX_MPROTECT
45275+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45276+#endif
45277+
45278+ )
45279+ {
45280+ *flags &= ~MF_PAX_MPROTECT;
45281+ retval = -EINVAL;
45282+ }
45283+
45284+ if ((*flags & MF_PAX_EMUTRAMP)
45285+
45286+#ifdef CONFIG_PAX_EMUTRAMP
45287+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45288+#endif
45289+
45290+ )
45291+ {
45292+ *flags &= ~MF_PAX_EMUTRAMP;
45293+ retval = -EINVAL;
45294+ }
45295+
45296+ return retval;
45297+}
45298+
45299+EXPORT_SYMBOL(pax_check_flags);
45300+
45301+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45302+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45303+{
45304+ struct task_struct *tsk = current;
45305+ struct mm_struct *mm = current->mm;
45306+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45307+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45308+ char *path_exec = NULL;
45309+ char *path_fault = NULL;
45310+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
45311+
45312+ if (buffer_exec && buffer_fault) {
45313+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45314+
45315+ down_read(&mm->mmap_sem);
45316+ vma = mm->mmap;
45317+ while (vma && (!vma_exec || !vma_fault)) {
45318+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45319+ vma_exec = vma;
45320+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45321+ vma_fault = vma;
45322+ vma = vma->vm_next;
45323+ }
45324+ if (vma_exec) {
45325+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45326+ if (IS_ERR(path_exec))
45327+ path_exec = "<path too long>";
45328+ else {
45329+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45330+ if (path_exec) {
45331+ *path_exec = 0;
45332+ path_exec = buffer_exec;
45333+ } else
45334+ path_exec = "<path too long>";
45335+ }
45336+ }
45337+ if (vma_fault) {
45338+ start = vma_fault->vm_start;
45339+ end = vma_fault->vm_end;
45340+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45341+ if (vma_fault->vm_file) {
45342+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45343+ if (IS_ERR(path_fault))
45344+ path_fault = "<path too long>";
45345+ else {
45346+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45347+ if (path_fault) {
45348+ *path_fault = 0;
45349+ path_fault = buffer_fault;
45350+ } else
45351+ path_fault = "<path too long>";
45352+ }
45353+ } else
45354+ path_fault = "<anonymous mapping>";
45355+ }
45356+ up_read(&mm->mmap_sem);
45357+ }
45358+ if (tsk->signal->curr_ip)
45359+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45360+ else
45361+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45362+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45363+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45364+ task_uid(tsk), task_euid(tsk), pc, sp);
45365+ free_page((unsigned long)buffer_exec);
45366+ free_page((unsigned long)buffer_fault);
45367+ pax_report_insns(regs, pc, sp);
45368+ do_coredump(SIGKILL, SIGKILL, regs);
45369+}
45370+#endif
45371+
45372+#ifdef CONFIG_PAX_REFCOUNT
45373+void pax_report_refcount_overflow(struct pt_regs *regs)
45374+{
45375+ if (current->signal->curr_ip)
45376+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45377+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45378+ else
45379+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45380+ current->comm, task_pid_nr(current), current_uid(), current_euid());
45381+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45382+ show_regs(regs);
45383+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45384+}
45385+#endif
45386+
45387+#ifdef CONFIG_PAX_USERCOPY
45388+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45389+static noinline int check_stack_object(const void *obj, unsigned long len)
45390+{
45391+ const void * const stack = task_stack_page(current);
45392+ const void * const stackend = stack + THREAD_SIZE;
45393+
45394+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45395+ const void *frame = NULL;
45396+ const void *oldframe;
45397+#endif
45398+
45399+ if (obj + len < obj)
45400+ return -1;
45401+
45402+ if (obj + len <= stack || stackend <= obj)
45403+ return 0;
45404+
45405+ if (obj < stack || stackend < obj + len)
45406+ return -1;
45407+
45408+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45409+ oldframe = __builtin_frame_address(1);
45410+ if (oldframe)
45411+ frame = __builtin_frame_address(2);
45412+ /*
45413+ low ----------------------------------------------> high
45414+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
45415+ ^----------------^
45416+ allow copies only within here
45417+ */
45418+ while (stack <= frame && frame < stackend) {
45419+ /* if obj + len extends past the last frame, this
45420+ check won't pass and the next frame will be 0,
45421+ causing us to bail out and correctly report
45422+ the copy as invalid
45423+ */
45424+ if (obj + len <= frame)
45425+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45426+ oldframe = frame;
45427+ frame = *(const void * const *)frame;
45428+ }
45429+ return -1;
45430+#else
45431+ return 1;
45432+#endif
45433+}
45434+
45435+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45436+{
45437+ if (current->signal->curr_ip)
45438+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45439+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45440+ else
45441+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45442+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45443+ dump_stack();
45444+ gr_handle_kernel_exploit();
45445+ do_group_exit(SIGKILL);
45446+}
45447+#endif
45448+
45449+void check_object_size(const void *ptr, unsigned long n, bool to)
45450+{
45451+
45452+#ifdef CONFIG_PAX_USERCOPY
45453+ const char *type;
45454+
45455+ if (!n)
45456+ return;
45457+
45458+ type = check_heap_object(ptr, n, to);
45459+ if (!type) {
45460+ if (check_stack_object(ptr, n) != -1)
45461+ return;
45462+ type = "<process stack>";
45463+ }
45464+
45465+ pax_report_usercopy(ptr, n, to, type);
45466+#endif
45467+
45468+}
45469+EXPORT_SYMBOL(check_object_size);
45470+
45471+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45472+void pax_track_stack(void)
45473+{
45474+ unsigned long sp = (unsigned long)&sp;
45475+ if (sp < current_thread_info()->lowest_stack &&
45476+ sp > (unsigned long)task_stack_page(current))
45477+ current_thread_info()->lowest_stack = sp;
45478+}
45479+EXPORT_SYMBOL(pax_track_stack);
45480+#endif
45481+
45482+#ifdef CONFIG_PAX_SIZE_OVERFLOW
45483+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45484+{
45485+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45486+ dump_stack();
45487+ do_group_exit(SIGKILL);
45488+}
45489+EXPORT_SYMBOL(report_size_overflow);
45490+#endif
45491+
45492 static int zap_process(struct task_struct *start, int exit_code)
45493 {
45494 struct task_struct *t;
45495@@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
45496 pipe = file->f_path.dentry->d_inode->i_pipe;
45497
45498 pipe_lock(pipe);
45499- pipe->readers++;
45500- pipe->writers--;
45501+ atomic_inc(&pipe->readers);
45502+ atomic_dec(&pipe->writers);
45503
45504- while ((pipe->readers > 1) && (!signal_pending(current))) {
45505+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45506 wake_up_interruptible_sync(&pipe->wait);
45507 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45508 pipe_wait(pipe);
45509 }
45510
45511- pipe->readers--;
45512- pipe->writers++;
45513+ atomic_dec(&pipe->readers);
45514+ atomic_inc(&pipe->writers);
45515 pipe_unlock(pipe);
45516
45517 }
45518@@ -2105,7 +2481,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45519 int flag = 0;
45520 int ispipe;
45521 bool need_nonrelative = false;
45522- static atomic_t core_dump_count = ATOMIC_INIT(0);
45523+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45524 struct coredump_params cprm = {
45525 .signr = signr,
45526 .regs = regs,
45527@@ -2120,6 +2496,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45528
45529 audit_core_dumps(signr);
45530
45531+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45532+ gr_handle_brute_attach(current, cprm.mm_flags);
45533+
45534 binfmt = mm->binfmt;
45535 if (!binfmt || !binfmt->core_dump)
45536 goto fail;
45537@@ -2190,7 +2569,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45538 }
45539 cprm.limit = RLIM_INFINITY;
45540
45541- dump_count = atomic_inc_return(&core_dump_count);
45542+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
45543 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45544 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45545 task_tgid_vnr(current), current->comm);
45546@@ -2217,6 +2596,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45547 } else {
45548 struct inode *inode;
45549
45550+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45551+
45552 if (cprm.limit < binfmt->min_coredump)
45553 goto fail_unlock;
45554
45555@@ -2268,7 +2649,7 @@ close_fail:
45556 filp_close(cprm.file, NULL);
45557 fail_dropcount:
45558 if (ispipe)
45559- atomic_dec(&core_dump_count);
45560+ atomic_dec_unchecked(&core_dump_count);
45561 fail_unlock:
45562 kfree(cn.corename);
45563 fail_corename:
45564@@ -2287,7 +2668,7 @@ fail:
45565 */
45566 int dump_write(struct file *file, const void *addr, int nr)
45567 {
45568- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45569+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45570 }
45571 EXPORT_SYMBOL(dump_write);
45572
45573diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45574index 376aa77..59a129c 100644
45575--- a/fs/ext2/balloc.c
45576+++ b/fs/ext2/balloc.c
45577@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45578
45579 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45580 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45581- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45582+ if (free_blocks < root_blocks + 1 &&
45583 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45584 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45585- !in_group_p (sbi->s_resgid))) {
45586+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45587 return 0;
45588 }
45589 return 1;
45590diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45591index 90d901f..159975f 100644
45592--- a/fs/ext3/balloc.c
45593+++ b/fs/ext3/balloc.c
45594@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45595
45596 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45597 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45598- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45599+ if (free_blocks < root_blocks + 1 &&
45600 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45601 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45602- !in_group_p (sbi->s_resgid))) {
45603+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45604 return 0;
45605 }
45606 return 1;
45607diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45608index 1b50890..e56c5ad 100644
45609--- a/fs/ext4/balloc.c
45610+++ b/fs/ext4/balloc.c
45611@@ -500,8 +500,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45612 /* Hm, nope. Are (enough) root reserved clusters available? */
45613 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45614 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45615- capable(CAP_SYS_RESOURCE) ||
45616- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45617+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45618+ capable_nolog(CAP_SYS_RESOURCE)) {
45619
45620 if (free_clusters >= (nclusters + dirty_clusters))
45621 return 1;
45622diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45623index c3411d4..30e4f1b 100644
45624--- a/fs/ext4/ext4.h
45625+++ b/fs/ext4/ext4.h
45626@@ -1248,19 +1248,19 @@ struct ext4_sb_info {
45627 unsigned long s_mb_last_start;
45628
45629 /* stats for buddy allocator */
45630- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45631- atomic_t s_bal_success; /* we found long enough chunks */
45632- atomic_t s_bal_allocated; /* in blocks */
45633- atomic_t s_bal_ex_scanned; /* total extents scanned */
45634- atomic_t s_bal_goals; /* goal hits */
45635- atomic_t s_bal_breaks; /* too long searches */
45636- atomic_t s_bal_2orders; /* 2^order hits */
45637+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45638+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45639+ atomic_unchecked_t s_bal_allocated; /* in blocks */
45640+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45641+ atomic_unchecked_t s_bal_goals; /* goal hits */
45642+ atomic_unchecked_t s_bal_breaks; /* too long searches */
45643+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45644 spinlock_t s_bal_lock;
45645 unsigned long s_mb_buddies_generated;
45646 unsigned long long s_mb_generation_time;
45647- atomic_t s_mb_lost_chunks;
45648- atomic_t s_mb_preallocated;
45649- atomic_t s_mb_discarded;
45650+ atomic_unchecked_t s_mb_lost_chunks;
45651+ atomic_unchecked_t s_mb_preallocated;
45652+ atomic_unchecked_t s_mb_discarded;
45653 atomic_t s_lock_busy;
45654
45655 /* locality groups */
45656diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45657index 8eae947..53fc27a 100644
45658--- a/fs/ext4/mballoc.c
45659+++ b/fs/ext4/mballoc.c
45660@@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45661 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45662
45663 if (EXT4_SB(sb)->s_mb_stats)
45664- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45665+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45666
45667 break;
45668 }
45669@@ -2040,7 +2040,7 @@ repeat:
45670 ac->ac_status = AC_STATUS_CONTINUE;
45671 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45672 cr = 3;
45673- atomic_inc(&sbi->s_mb_lost_chunks);
45674+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45675 goto repeat;
45676 }
45677 }
45678@@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
45679 if (sbi->s_mb_stats) {
45680 ext4_msg(sb, KERN_INFO,
45681 "mballoc: %u blocks %u reqs (%u success)",
45682- atomic_read(&sbi->s_bal_allocated),
45683- atomic_read(&sbi->s_bal_reqs),
45684- atomic_read(&sbi->s_bal_success));
45685+ atomic_read_unchecked(&sbi->s_bal_allocated),
45686+ atomic_read_unchecked(&sbi->s_bal_reqs),
45687+ atomic_read_unchecked(&sbi->s_bal_success));
45688 ext4_msg(sb, KERN_INFO,
45689 "mballoc: %u extents scanned, %u goal hits, "
45690 "%u 2^N hits, %u breaks, %u lost",
45691- atomic_read(&sbi->s_bal_ex_scanned),
45692- atomic_read(&sbi->s_bal_goals),
45693- atomic_read(&sbi->s_bal_2orders),
45694- atomic_read(&sbi->s_bal_breaks),
45695- atomic_read(&sbi->s_mb_lost_chunks));
45696+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45697+ atomic_read_unchecked(&sbi->s_bal_goals),
45698+ atomic_read_unchecked(&sbi->s_bal_2orders),
45699+ atomic_read_unchecked(&sbi->s_bal_breaks),
45700+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45701 ext4_msg(sb, KERN_INFO,
45702 "mballoc: %lu generated and it took %Lu",
45703 sbi->s_mb_buddies_generated,
45704 sbi->s_mb_generation_time);
45705 ext4_msg(sb, KERN_INFO,
45706 "mballoc: %u preallocated, %u discarded",
45707- atomic_read(&sbi->s_mb_preallocated),
45708- atomic_read(&sbi->s_mb_discarded));
45709+ atomic_read_unchecked(&sbi->s_mb_preallocated),
45710+ atomic_read_unchecked(&sbi->s_mb_discarded));
45711 }
45712
45713 free_percpu(sbi->s_locality_groups);
45714@@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45715 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45716
45717 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45718- atomic_inc(&sbi->s_bal_reqs);
45719- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45720+ atomic_inc_unchecked(&sbi->s_bal_reqs);
45721+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45722 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45723- atomic_inc(&sbi->s_bal_success);
45724- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45725+ atomic_inc_unchecked(&sbi->s_bal_success);
45726+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45727 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45728 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45729- atomic_inc(&sbi->s_bal_goals);
45730+ atomic_inc_unchecked(&sbi->s_bal_goals);
45731 if (ac->ac_found > sbi->s_mb_max_to_scan)
45732- atomic_inc(&sbi->s_bal_breaks);
45733+ atomic_inc_unchecked(&sbi->s_bal_breaks);
45734 }
45735
45736 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45737@@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45738 trace_ext4_mb_new_inode_pa(ac, pa);
45739
45740 ext4_mb_use_inode_pa(ac, pa);
45741- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45742+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45743
45744 ei = EXT4_I(ac->ac_inode);
45745 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45746@@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45747 trace_ext4_mb_new_group_pa(ac, pa);
45748
45749 ext4_mb_use_group_pa(ac, pa);
45750- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45751+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45752
45753 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45754 lg = ac->ac_lg;
45755@@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45756 * from the bitmap and continue.
45757 */
45758 }
45759- atomic_add(free, &sbi->s_mb_discarded);
45760+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
45761
45762 return err;
45763 }
45764@@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45765 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45766 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45767 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45768- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45769+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45770 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45771
45772 return 0;
45773diff --git a/fs/fcntl.c b/fs/fcntl.c
45774index 887b5ba..0e3f2c3 100644
45775--- a/fs/fcntl.c
45776+++ b/fs/fcntl.c
45777@@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45778 if (err)
45779 return err;
45780
45781+ if (gr_handle_chroot_fowner(pid, type))
45782+ return -ENOENT;
45783+ if (gr_check_protected_task_fowner(pid, type))
45784+ return -EACCES;
45785+
45786 f_modown(filp, pid, type, force);
45787 return 0;
45788 }
45789@@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
45790
45791 static int f_setown_ex(struct file *filp, unsigned long arg)
45792 {
45793- struct f_owner_ex * __user owner_p = (void * __user)arg;
45794+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45795 struct f_owner_ex owner;
45796 struct pid *pid;
45797 int type;
45798@@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45799
45800 static int f_getown_ex(struct file *filp, unsigned long arg)
45801 {
45802- struct f_owner_ex * __user owner_p = (void * __user)arg;
45803+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45804 struct f_owner_ex owner;
45805 int ret = 0;
45806
45807@@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45808 switch (cmd) {
45809 case F_DUPFD:
45810 case F_DUPFD_CLOEXEC:
45811+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45812 if (arg >= rlimit(RLIMIT_NOFILE))
45813 break;
45814 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45815diff --git a/fs/fifo.c b/fs/fifo.c
45816index cf6f434..3d7942c 100644
45817--- a/fs/fifo.c
45818+++ b/fs/fifo.c
45819@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45820 */
45821 filp->f_op = &read_pipefifo_fops;
45822 pipe->r_counter++;
45823- if (pipe->readers++ == 0)
45824+ if (atomic_inc_return(&pipe->readers) == 1)
45825 wake_up_partner(inode);
45826
45827- if (!pipe->writers) {
45828+ if (!atomic_read(&pipe->writers)) {
45829 if ((filp->f_flags & O_NONBLOCK)) {
45830 /* suppress POLLHUP until we have
45831 * seen a writer */
45832@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45833 * errno=ENXIO when there is no process reading the FIFO.
45834 */
45835 ret = -ENXIO;
45836- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45837+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45838 goto err;
45839
45840 filp->f_op = &write_pipefifo_fops;
45841 pipe->w_counter++;
45842- if (!pipe->writers++)
45843+ if (atomic_inc_return(&pipe->writers) == 1)
45844 wake_up_partner(inode);
45845
45846- if (!pipe->readers) {
45847+ if (!atomic_read(&pipe->readers)) {
45848 if (wait_for_partner(inode, &pipe->r_counter))
45849 goto err_wr;
45850 }
45851@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45852 */
45853 filp->f_op = &rdwr_pipefifo_fops;
45854
45855- pipe->readers++;
45856- pipe->writers++;
45857+ atomic_inc(&pipe->readers);
45858+ atomic_inc(&pipe->writers);
45859 pipe->r_counter++;
45860 pipe->w_counter++;
45861- if (pipe->readers == 1 || pipe->writers == 1)
45862+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45863 wake_up_partner(inode);
45864 break;
45865
45866@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45867 return 0;
45868
45869 err_rd:
45870- if (!--pipe->readers)
45871+ if (atomic_dec_and_test(&pipe->readers))
45872 wake_up_interruptible(&pipe->wait);
45873 ret = -ERESTARTSYS;
45874 goto err;
45875
45876 err_wr:
45877- if (!--pipe->writers)
45878+ if (atomic_dec_and_test(&pipe->writers))
45879 wake_up_interruptible(&pipe->wait);
45880 ret = -ERESTARTSYS;
45881 goto err;
45882
45883 err:
45884- if (!pipe->readers && !pipe->writers)
45885+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45886 free_pipe_info(inode);
45887
45888 err_nocleanup:
45889diff --git a/fs/file.c b/fs/file.c
45890index ba3f605..fade102 100644
45891--- a/fs/file.c
45892+++ b/fs/file.c
45893@@ -15,6 +15,7 @@
45894 #include <linux/slab.h>
45895 #include <linux/vmalloc.h>
45896 #include <linux/file.h>
45897+#include <linux/security.h>
45898 #include <linux/fdtable.h>
45899 #include <linux/bitops.h>
45900 #include <linux/interrupt.h>
45901@@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45902 * N.B. For clone tasks sharing a files structure, this test
45903 * will limit the total number of files that can be opened.
45904 */
45905+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45906 if (nr >= rlimit(RLIMIT_NOFILE))
45907 return -EMFILE;
45908
45909diff --git a/fs/filesystems.c b/fs/filesystems.c
45910index 96f2428..f5eeb8e 100644
45911--- a/fs/filesystems.c
45912+++ b/fs/filesystems.c
45913@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45914 int len = dot ? dot - name : strlen(name);
45915
45916 fs = __get_fs_type(name, len);
45917+
45918+#ifdef CONFIG_GRKERNSEC_MODHARDEN
45919+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45920+#else
45921 if (!fs && (request_module("%.*s", len, name) == 0))
45922+#endif
45923 fs = __get_fs_type(name, len);
45924
45925 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45926diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45927index 5df4775..9d9336f 100644
45928--- a/fs/fs_struct.c
45929+++ b/fs/fs_struct.c
45930@@ -4,6 +4,7 @@
45931 #include <linux/path.h>
45932 #include <linux/slab.h>
45933 #include <linux/fs_struct.h>
45934+#include <linux/grsecurity.h>
45935 #include "internal.h"
45936
45937 /*
45938@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45939 write_seqcount_begin(&fs->seq);
45940 old_root = fs->root;
45941 fs->root = *path;
45942+ gr_set_chroot_entries(current, path);
45943 write_seqcount_end(&fs->seq);
45944 spin_unlock(&fs->lock);
45945 if (old_root.dentry)
45946@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45947 return 1;
45948 }
45949
45950+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45951+{
45952+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45953+ return 0;
45954+ *p = *new;
45955+
45956+ /* This function is only called from pivot_root(). Leave our
45957+ gr_chroot_dentry and is_chrooted flags as-is, so that a
45958+ pivoted root isn't treated as a chroot
45959+ */
45960+ //gr_set_chroot_entries(task, new);
45961+
45962+ return 1;
45963+}
45964+
45965 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45966 {
45967 struct task_struct *g, *p;
45968@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45969 int hits = 0;
45970 spin_lock(&fs->lock);
45971 write_seqcount_begin(&fs->seq);
45972- hits += replace_path(&fs->root, old_root, new_root);
45973+ hits += replace_root_path(p, &fs->root, old_root, new_root);
45974 hits += replace_path(&fs->pwd, old_root, new_root);
45975 write_seqcount_end(&fs->seq);
45976 while (hits--) {
45977@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
45978 task_lock(tsk);
45979 spin_lock(&fs->lock);
45980 tsk->fs = NULL;
45981- kill = !--fs->users;
45982+ gr_clear_chroot_entries(tsk);
45983+ kill = !atomic_dec_return(&fs->users);
45984 spin_unlock(&fs->lock);
45985 task_unlock(tsk);
45986 if (kill)
45987@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45988 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45989 /* We don't need to lock fs - think why ;-) */
45990 if (fs) {
45991- fs->users = 1;
45992+ atomic_set(&fs->users, 1);
45993 fs->in_exec = 0;
45994 spin_lock_init(&fs->lock);
45995 seqcount_init(&fs->seq);
45996@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45997 spin_lock(&old->lock);
45998 fs->root = old->root;
45999 path_get(&fs->root);
46000+ /* instead of calling gr_set_chroot_entries here,
46001+ we call it from every caller of this function
46002+ */
46003 fs->pwd = old->pwd;
46004 path_get(&fs->pwd);
46005 spin_unlock(&old->lock);
46006@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
46007
46008 task_lock(current);
46009 spin_lock(&fs->lock);
46010- kill = !--fs->users;
46011+ kill = !atomic_dec_return(&fs->users);
46012 current->fs = new_fs;
46013+ gr_set_chroot_entries(current, &new_fs->root);
46014 spin_unlock(&fs->lock);
46015 task_unlock(current);
46016
46017@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46018
46019 int current_umask(void)
46020 {
46021- return current->fs->umask;
46022+ return current->fs->umask | gr_acl_umask();
46023 }
46024 EXPORT_SYMBOL(current_umask);
46025
46026 /* to be mentioned only in INIT_TASK */
46027 struct fs_struct init_fs = {
46028- .users = 1,
46029+ .users = ATOMIC_INIT(1),
46030 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46031 .seq = SEQCNT_ZERO,
46032 .umask = 0022,
46033@@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
46034 task_lock(current);
46035
46036 spin_lock(&init_fs.lock);
46037- init_fs.users++;
46038+ atomic_inc(&init_fs.users);
46039 spin_unlock(&init_fs.lock);
46040
46041 spin_lock(&fs->lock);
46042 current->fs = &init_fs;
46043- kill = !--fs->users;
46044+ gr_set_chroot_entries(current, &current->fs->root);
46045+ kill = !atomic_dec_return(&fs->users);
46046 spin_unlock(&fs->lock);
46047
46048 task_unlock(current);
46049diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46050index 9905350..02eaec4 100644
46051--- a/fs/fscache/cookie.c
46052+++ b/fs/fscache/cookie.c
46053@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46054 parent ? (char *) parent->def->name : "<no-parent>",
46055 def->name, netfs_data);
46056
46057- fscache_stat(&fscache_n_acquires);
46058+ fscache_stat_unchecked(&fscache_n_acquires);
46059
46060 /* if there's no parent cookie, then we don't create one here either */
46061 if (!parent) {
46062- fscache_stat(&fscache_n_acquires_null);
46063+ fscache_stat_unchecked(&fscache_n_acquires_null);
46064 _leave(" [no parent]");
46065 return NULL;
46066 }
46067@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46068 /* allocate and initialise a cookie */
46069 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46070 if (!cookie) {
46071- fscache_stat(&fscache_n_acquires_oom);
46072+ fscache_stat_unchecked(&fscache_n_acquires_oom);
46073 _leave(" [ENOMEM]");
46074 return NULL;
46075 }
46076@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46077
46078 switch (cookie->def->type) {
46079 case FSCACHE_COOKIE_TYPE_INDEX:
46080- fscache_stat(&fscache_n_cookie_index);
46081+ fscache_stat_unchecked(&fscache_n_cookie_index);
46082 break;
46083 case FSCACHE_COOKIE_TYPE_DATAFILE:
46084- fscache_stat(&fscache_n_cookie_data);
46085+ fscache_stat_unchecked(&fscache_n_cookie_data);
46086 break;
46087 default:
46088- fscache_stat(&fscache_n_cookie_special);
46089+ fscache_stat_unchecked(&fscache_n_cookie_special);
46090 break;
46091 }
46092
46093@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46094 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46095 atomic_dec(&parent->n_children);
46096 __fscache_cookie_put(cookie);
46097- fscache_stat(&fscache_n_acquires_nobufs);
46098+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46099 _leave(" = NULL");
46100 return NULL;
46101 }
46102 }
46103
46104- fscache_stat(&fscache_n_acquires_ok);
46105+ fscache_stat_unchecked(&fscache_n_acquires_ok);
46106 _leave(" = %p", cookie);
46107 return cookie;
46108 }
46109@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46110 cache = fscache_select_cache_for_object(cookie->parent);
46111 if (!cache) {
46112 up_read(&fscache_addremove_sem);
46113- fscache_stat(&fscache_n_acquires_no_cache);
46114+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46115 _leave(" = -ENOMEDIUM [no cache]");
46116 return -ENOMEDIUM;
46117 }
46118@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46119 object = cache->ops->alloc_object(cache, cookie);
46120 fscache_stat_d(&fscache_n_cop_alloc_object);
46121 if (IS_ERR(object)) {
46122- fscache_stat(&fscache_n_object_no_alloc);
46123+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
46124 ret = PTR_ERR(object);
46125 goto error;
46126 }
46127
46128- fscache_stat(&fscache_n_object_alloc);
46129+ fscache_stat_unchecked(&fscache_n_object_alloc);
46130
46131 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46132
46133@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46134 struct fscache_object *object;
46135 struct hlist_node *_p;
46136
46137- fscache_stat(&fscache_n_updates);
46138+ fscache_stat_unchecked(&fscache_n_updates);
46139
46140 if (!cookie) {
46141- fscache_stat(&fscache_n_updates_null);
46142+ fscache_stat_unchecked(&fscache_n_updates_null);
46143 _leave(" [no cookie]");
46144 return;
46145 }
46146@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46147 struct fscache_object *object;
46148 unsigned long event;
46149
46150- fscache_stat(&fscache_n_relinquishes);
46151+ fscache_stat_unchecked(&fscache_n_relinquishes);
46152 if (retire)
46153- fscache_stat(&fscache_n_relinquishes_retire);
46154+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46155
46156 if (!cookie) {
46157- fscache_stat(&fscache_n_relinquishes_null);
46158+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
46159 _leave(" [no cookie]");
46160 return;
46161 }
46162@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46163
46164 /* wait for the cookie to finish being instantiated (or to fail) */
46165 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46166- fscache_stat(&fscache_n_relinquishes_waitcrt);
46167+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46168 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46169 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46170 }
46171diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46172index f6aad48..88dcf26 100644
46173--- a/fs/fscache/internal.h
46174+++ b/fs/fscache/internal.h
46175@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46176 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46177 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46178
46179-extern atomic_t fscache_n_op_pend;
46180-extern atomic_t fscache_n_op_run;
46181-extern atomic_t fscache_n_op_enqueue;
46182-extern atomic_t fscache_n_op_deferred_release;
46183-extern atomic_t fscache_n_op_release;
46184-extern atomic_t fscache_n_op_gc;
46185-extern atomic_t fscache_n_op_cancelled;
46186-extern atomic_t fscache_n_op_rejected;
46187+extern atomic_unchecked_t fscache_n_op_pend;
46188+extern atomic_unchecked_t fscache_n_op_run;
46189+extern atomic_unchecked_t fscache_n_op_enqueue;
46190+extern atomic_unchecked_t fscache_n_op_deferred_release;
46191+extern atomic_unchecked_t fscache_n_op_release;
46192+extern atomic_unchecked_t fscache_n_op_gc;
46193+extern atomic_unchecked_t fscache_n_op_cancelled;
46194+extern atomic_unchecked_t fscache_n_op_rejected;
46195
46196-extern atomic_t fscache_n_attr_changed;
46197-extern atomic_t fscache_n_attr_changed_ok;
46198-extern atomic_t fscache_n_attr_changed_nobufs;
46199-extern atomic_t fscache_n_attr_changed_nomem;
46200-extern atomic_t fscache_n_attr_changed_calls;
46201+extern atomic_unchecked_t fscache_n_attr_changed;
46202+extern atomic_unchecked_t fscache_n_attr_changed_ok;
46203+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46204+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46205+extern atomic_unchecked_t fscache_n_attr_changed_calls;
46206
46207-extern atomic_t fscache_n_allocs;
46208-extern atomic_t fscache_n_allocs_ok;
46209-extern atomic_t fscache_n_allocs_wait;
46210-extern atomic_t fscache_n_allocs_nobufs;
46211-extern atomic_t fscache_n_allocs_intr;
46212-extern atomic_t fscache_n_allocs_object_dead;
46213-extern atomic_t fscache_n_alloc_ops;
46214-extern atomic_t fscache_n_alloc_op_waits;
46215+extern atomic_unchecked_t fscache_n_allocs;
46216+extern atomic_unchecked_t fscache_n_allocs_ok;
46217+extern atomic_unchecked_t fscache_n_allocs_wait;
46218+extern atomic_unchecked_t fscache_n_allocs_nobufs;
46219+extern atomic_unchecked_t fscache_n_allocs_intr;
46220+extern atomic_unchecked_t fscache_n_allocs_object_dead;
46221+extern atomic_unchecked_t fscache_n_alloc_ops;
46222+extern atomic_unchecked_t fscache_n_alloc_op_waits;
46223
46224-extern atomic_t fscache_n_retrievals;
46225-extern atomic_t fscache_n_retrievals_ok;
46226-extern atomic_t fscache_n_retrievals_wait;
46227-extern atomic_t fscache_n_retrievals_nodata;
46228-extern atomic_t fscache_n_retrievals_nobufs;
46229-extern atomic_t fscache_n_retrievals_intr;
46230-extern atomic_t fscache_n_retrievals_nomem;
46231-extern atomic_t fscache_n_retrievals_object_dead;
46232-extern atomic_t fscache_n_retrieval_ops;
46233-extern atomic_t fscache_n_retrieval_op_waits;
46234+extern atomic_unchecked_t fscache_n_retrievals;
46235+extern atomic_unchecked_t fscache_n_retrievals_ok;
46236+extern atomic_unchecked_t fscache_n_retrievals_wait;
46237+extern atomic_unchecked_t fscache_n_retrievals_nodata;
46238+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46239+extern atomic_unchecked_t fscache_n_retrievals_intr;
46240+extern atomic_unchecked_t fscache_n_retrievals_nomem;
46241+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46242+extern atomic_unchecked_t fscache_n_retrieval_ops;
46243+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46244
46245-extern atomic_t fscache_n_stores;
46246-extern atomic_t fscache_n_stores_ok;
46247-extern atomic_t fscache_n_stores_again;
46248-extern atomic_t fscache_n_stores_nobufs;
46249-extern atomic_t fscache_n_stores_oom;
46250-extern atomic_t fscache_n_store_ops;
46251-extern atomic_t fscache_n_store_calls;
46252-extern atomic_t fscache_n_store_pages;
46253-extern atomic_t fscache_n_store_radix_deletes;
46254-extern atomic_t fscache_n_store_pages_over_limit;
46255+extern atomic_unchecked_t fscache_n_stores;
46256+extern atomic_unchecked_t fscache_n_stores_ok;
46257+extern atomic_unchecked_t fscache_n_stores_again;
46258+extern atomic_unchecked_t fscache_n_stores_nobufs;
46259+extern atomic_unchecked_t fscache_n_stores_oom;
46260+extern atomic_unchecked_t fscache_n_store_ops;
46261+extern atomic_unchecked_t fscache_n_store_calls;
46262+extern atomic_unchecked_t fscache_n_store_pages;
46263+extern atomic_unchecked_t fscache_n_store_radix_deletes;
46264+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46265
46266-extern atomic_t fscache_n_store_vmscan_not_storing;
46267-extern atomic_t fscache_n_store_vmscan_gone;
46268-extern atomic_t fscache_n_store_vmscan_busy;
46269-extern atomic_t fscache_n_store_vmscan_cancelled;
46270+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46271+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46272+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46273+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46274
46275-extern atomic_t fscache_n_marks;
46276-extern atomic_t fscache_n_uncaches;
46277+extern atomic_unchecked_t fscache_n_marks;
46278+extern atomic_unchecked_t fscache_n_uncaches;
46279
46280-extern atomic_t fscache_n_acquires;
46281-extern atomic_t fscache_n_acquires_null;
46282-extern atomic_t fscache_n_acquires_no_cache;
46283-extern atomic_t fscache_n_acquires_ok;
46284-extern atomic_t fscache_n_acquires_nobufs;
46285-extern atomic_t fscache_n_acquires_oom;
46286+extern atomic_unchecked_t fscache_n_acquires;
46287+extern atomic_unchecked_t fscache_n_acquires_null;
46288+extern atomic_unchecked_t fscache_n_acquires_no_cache;
46289+extern atomic_unchecked_t fscache_n_acquires_ok;
46290+extern atomic_unchecked_t fscache_n_acquires_nobufs;
46291+extern atomic_unchecked_t fscache_n_acquires_oom;
46292
46293-extern atomic_t fscache_n_updates;
46294-extern atomic_t fscache_n_updates_null;
46295-extern atomic_t fscache_n_updates_run;
46296+extern atomic_unchecked_t fscache_n_updates;
46297+extern atomic_unchecked_t fscache_n_updates_null;
46298+extern atomic_unchecked_t fscache_n_updates_run;
46299
46300-extern atomic_t fscache_n_relinquishes;
46301-extern atomic_t fscache_n_relinquishes_null;
46302-extern atomic_t fscache_n_relinquishes_waitcrt;
46303-extern atomic_t fscache_n_relinquishes_retire;
46304+extern atomic_unchecked_t fscache_n_relinquishes;
46305+extern atomic_unchecked_t fscache_n_relinquishes_null;
46306+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46307+extern atomic_unchecked_t fscache_n_relinquishes_retire;
46308
46309-extern atomic_t fscache_n_cookie_index;
46310-extern atomic_t fscache_n_cookie_data;
46311-extern atomic_t fscache_n_cookie_special;
46312+extern atomic_unchecked_t fscache_n_cookie_index;
46313+extern atomic_unchecked_t fscache_n_cookie_data;
46314+extern atomic_unchecked_t fscache_n_cookie_special;
46315
46316-extern atomic_t fscache_n_object_alloc;
46317-extern atomic_t fscache_n_object_no_alloc;
46318-extern atomic_t fscache_n_object_lookups;
46319-extern atomic_t fscache_n_object_lookups_negative;
46320-extern atomic_t fscache_n_object_lookups_positive;
46321-extern atomic_t fscache_n_object_lookups_timed_out;
46322-extern atomic_t fscache_n_object_created;
46323-extern atomic_t fscache_n_object_avail;
46324-extern atomic_t fscache_n_object_dead;
46325+extern atomic_unchecked_t fscache_n_object_alloc;
46326+extern atomic_unchecked_t fscache_n_object_no_alloc;
46327+extern atomic_unchecked_t fscache_n_object_lookups;
46328+extern atomic_unchecked_t fscache_n_object_lookups_negative;
46329+extern atomic_unchecked_t fscache_n_object_lookups_positive;
46330+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46331+extern atomic_unchecked_t fscache_n_object_created;
46332+extern atomic_unchecked_t fscache_n_object_avail;
46333+extern atomic_unchecked_t fscache_n_object_dead;
46334
46335-extern atomic_t fscache_n_checkaux_none;
46336-extern atomic_t fscache_n_checkaux_okay;
46337-extern atomic_t fscache_n_checkaux_update;
46338-extern atomic_t fscache_n_checkaux_obsolete;
46339+extern atomic_unchecked_t fscache_n_checkaux_none;
46340+extern atomic_unchecked_t fscache_n_checkaux_okay;
46341+extern atomic_unchecked_t fscache_n_checkaux_update;
46342+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46343
46344 extern atomic_t fscache_n_cop_alloc_object;
46345 extern atomic_t fscache_n_cop_lookup_object;
46346@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46347 atomic_inc(stat);
46348 }
46349
46350+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46351+{
46352+ atomic_inc_unchecked(stat);
46353+}
46354+
46355 static inline void fscache_stat_d(atomic_t *stat)
46356 {
46357 atomic_dec(stat);
46358@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46359
46360 #define __fscache_stat(stat) (NULL)
46361 #define fscache_stat(stat) do {} while (0)
46362+#define fscache_stat_unchecked(stat) do {} while (0)
46363 #define fscache_stat_d(stat) do {} while (0)
46364 #endif
46365
46366diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46367index b6b897c..0ffff9c 100644
46368--- a/fs/fscache/object.c
46369+++ b/fs/fscache/object.c
46370@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46371 /* update the object metadata on disk */
46372 case FSCACHE_OBJECT_UPDATING:
46373 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46374- fscache_stat(&fscache_n_updates_run);
46375+ fscache_stat_unchecked(&fscache_n_updates_run);
46376 fscache_stat(&fscache_n_cop_update_object);
46377 object->cache->ops->update_object(object);
46378 fscache_stat_d(&fscache_n_cop_update_object);
46379@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46380 spin_lock(&object->lock);
46381 object->state = FSCACHE_OBJECT_DEAD;
46382 spin_unlock(&object->lock);
46383- fscache_stat(&fscache_n_object_dead);
46384+ fscache_stat_unchecked(&fscache_n_object_dead);
46385 goto terminal_transit;
46386
46387 /* handle the parent cache of this object being withdrawn from
46388@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46389 spin_lock(&object->lock);
46390 object->state = FSCACHE_OBJECT_DEAD;
46391 spin_unlock(&object->lock);
46392- fscache_stat(&fscache_n_object_dead);
46393+ fscache_stat_unchecked(&fscache_n_object_dead);
46394 goto terminal_transit;
46395
46396 /* complain about the object being woken up once it is
46397@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46398 parent->cookie->def->name, cookie->def->name,
46399 object->cache->tag->name);
46400
46401- fscache_stat(&fscache_n_object_lookups);
46402+ fscache_stat_unchecked(&fscache_n_object_lookups);
46403 fscache_stat(&fscache_n_cop_lookup_object);
46404 ret = object->cache->ops->lookup_object(object);
46405 fscache_stat_d(&fscache_n_cop_lookup_object);
46406@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46407 if (ret == -ETIMEDOUT) {
46408 /* probably stuck behind another object, so move this one to
46409 * the back of the queue */
46410- fscache_stat(&fscache_n_object_lookups_timed_out);
46411+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46412 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46413 }
46414
46415@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46416
46417 spin_lock(&object->lock);
46418 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46419- fscache_stat(&fscache_n_object_lookups_negative);
46420+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46421
46422 /* transit here to allow write requests to begin stacking up
46423 * and read requests to begin returning ENODATA */
46424@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46425 * result, in which case there may be data available */
46426 spin_lock(&object->lock);
46427 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46428- fscache_stat(&fscache_n_object_lookups_positive);
46429+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46430
46431 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46432
46433@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46434 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46435 } else {
46436 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46437- fscache_stat(&fscache_n_object_created);
46438+ fscache_stat_unchecked(&fscache_n_object_created);
46439
46440 object->state = FSCACHE_OBJECT_AVAILABLE;
46441 spin_unlock(&object->lock);
46442@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46443 fscache_enqueue_dependents(object);
46444
46445 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46446- fscache_stat(&fscache_n_object_avail);
46447+ fscache_stat_unchecked(&fscache_n_object_avail);
46448
46449 _leave("");
46450 }
46451@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46452 enum fscache_checkaux result;
46453
46454 if (!object->cookie->def->check_aux) {
46455- fscache_stat(&fscache_n_checkaux_none);
46456+ fscache_stat_unchecked(&fscache_n_checkaux_none);
46457 return FSCACHE_CHECKAUX_OKAY;
46458 }
46459
46460@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46461 switch (result) {
46462 /* entry okay as is */
46463 case FSCACHE_CHECKAUX_OKAY:
46464- fscache_stat(&fscache_n_checkaux_okay);
46465+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
46466 break;
46467
46468 /* entry requires update */
46469 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46470- fscache_stat(&fscache_n_checkaux_update);
46471+ fscache_stat_unchecked(&fscache_n_checkaux_update);
46472 break;
46473
46474 /* entry requires deletion */
46475 case FSCACHE_CHECKAUX_OBSOLETE:
46476- fscache_stat(&fscache_n_checkaux_obsolete);
46477+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46478 break;
46479
46480 default:
46481diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46482index 30afdfa..2256596 100644
46483--- a/fs/fscache/operation.c
46484+++ b/fs/fscache/operation.c
46485@@ -17,7 +17,7 @@
46486 #include <linux/slab.h>
46487 #include "internal.h"
46488
46489-atomic_t fscache_op_debug_id;
46490+atomic_unchecked_t fscache_op_debug_id;
46491 EXPORT_SYMBOL(fscache_op_debug_id);
46492
46493 /**
46494@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46495 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46496 ASSERTCMP(atomic_read(&op->usage), >, 0);
46497
46498- fscache_stat(&fscache_n_op_enqueue);
46499+ fscache_stat_unchecked(&fscache_n_op_enqueue);
46500 switch (op->flags & FSCACHE_OP_TYPE) {
46501 case FSCACHE_OP_ASYNC:
46502 _debug("queue async");
46503@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46504 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46505 if (op->processor)
46506 fscache_enqueue_operation(op);
46507- fscache_stat(&fscache_n_op_run);
46508+ fscache_stat_unchecked(&fscache_n_op_run);
46509 }
46510
46511 /*
46512@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46513 if (object->n_ops > 1) {
46514 atomic_inc(&op->usage);
46515 list_add_tail(&op->pend_link, &object->pending_ops);
46516- fscache_stat(&fscache_n_op_pend);
46517+ fscache_stat_unchecked(&fscache_n_op_pend);
46518 } else if (!list_empty(&object->pending_ops)) {
46519 atomic_inc(&op->usage);
46520 list_add_tail(&op->pend_link, &object->pending_ops);
46521- fscache_stat(&fscache_n_op_pend);
46522+ fscache_stat_unchecked(&fscache_n_op_pend);
46523 fscache_start_operations(object);
46524 } else {
46525 ASSERTCMP(object->n_in_progress, ==, 0);
46526@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46527 object->n_exclusive++; /* reads and writes must wait */
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 ret = 0;
46533 } else {
46534 /* not allowed to submit ops in any other state */
46535@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46536 if (object->n_exclusive > 0) {
46537 atomic_inc(&op->usage);
46538 list_add_tail(&op->pend_link, &object->pending_ops);
46539- fscache_stat(&fscache_n_op_pend);
46540+ fscache_stat_unchecked(&fscache_n_op_pend);
46541 } else if (!list_empty(&object->pending_ops)) {
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 fscache_start_operations(object);
46547 } else {
46548 ASSERTCMP(object->n_exclusive, ==, 0);
46549@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46550 object->n_ops++;
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 ret = 0;
46556 } else if (object->state == FSCACHE_OBJECT_DYING ||
46557 object->state == FSCACHE_OBJECT_LC_DYING ||
46558 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46559- fscache_stat(&fscache_n_op_rejected);
46560+ fscache_stat_unchecked(&fscache_n_op_rejected);
46561 ret = -ENOBUFS;
46562 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46563 fscache_report_unexpected_submission(object, op, ostate);
46564@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46565
46566 ret = -EBUSY;
46567 if (!list_empty(&op->pend_link)) {
46568- fscache_stat(&fscache_n_op_cancelled);
46569+ fscache_stat_unchecked(&fscache_n_op_cancelled);
46570 list_del_init(&op->pend_link);
46571 object->n_ops--;
46572 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46573@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46574 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46575 BUG();
46576
46577- fscache_stat(&fscache_n_op_release);
46578+ fscache_stat_unchecked(&fscache_n_op_release);
46579
46580 if (op->release) {
46581 op->release(op);
46582@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46583 * lock, and defer it otherwise */
46584 if (!spin_trylock(&object->lock)) {
46585 _debug("defer put");
46586- fscache_stat(&fscache_n_op_deferred_release);
46587+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
46588
46589 cache = object->cache;
46590 spin_lock(&cache->op_gc_list_lock);
46591@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46592
46593 _debug("GC DEFERRED REL OBJ%x OP%x",
46594 object->debug_id, op->debug_id);
46595- fscache_stat(&fscache_n_op_gc);
46596+ fscache_stat_unchecked(&fscache_n_op_gc);
46597
46598 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46599
46600diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46601index 3f7a59b..cf196cc 100644
46602--- a/fs/fscache/page.c
46603+++ b/fs/fscache/page.c
46604@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46605 val = radix_tree_lookup(&cookie->stores, page->index);
46606 if (!val) {
46607 rcu_read_unlock();
46608- fscache_stat(&fscache_n_store_vmscan_not_storing);
46609+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46610 __fscache_uncache_page(cookie, page);
46611 return true;
46612 }
46613@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46614 spin_unlock(&cookie->stores_lock);
46615
46616 if (xpage) {
46617- fscache_stat(&fscache_n_store_vmscan_cancelled);
46618- fscache_stat(&fscache_n_store_radix_deletes);
46619+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46620+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46621 ASSERTCMP(xpage, ==, page);
46622 } else {
46623- fscache_stat(&fscache_n_store_vmscan_gone);
46624+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46625 }
46626
46627 wake_up_bit(&cookie->flags, 0);
46628@@ -107,7 +107,7 @@ page_busy:
46629 /* we might want to wait here, but that could deadlock the allocator as
46630 * the work threads writing to the cache may all end up sleeping
46631 * on memory allocation */
46632- fscache_stat(&fscache_n_store_vmscan_busy);
46633+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46634 return false;
46635 }
46636 EXPORT_SYMBOL(__fscache_maybe_release_page);
46637@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46638 FSCACHE_COOKIE_STORING_TAG);
46639 if (!radix_tree_tag_get(&cookie->stores, page->index,
46640 FSCACHE_COOKIE_PENDING_TAG)) {
46641- fscache_stat(&fscache_n_store_radix_deletes);
46642+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46643 xpage = radix_tree_delete(&cookie->stores, page->index);
46644 }
46645 spin_unlock(&cookie->stores_lock);
46646@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46647
46648 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46649
46650- fscache_stat(&fscache_n_attr_changed_calls);
46651+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46652
46653 if (fscache_object_is_active(object)) {
46654 fscache_stat(&fscache_n_cop_attr_changed);
46655@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46656
46657 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46658
46659- fscache_stat(&fscache_n_attr_changed);
46660+ fscache_stat_unchecked(&fscache_n_attr_changed);
46661
46662 op = kzalloc(sizeof(*op), GFP_KERNEL);
46663 if (!op) {
46664- fscache_stat(&fscache_n_attr_changed_nomem);
46665+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46666 _leave(" = -ENOMEM");
46667 return -ENOMEM;
46668 }
46669@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46670 if (fscache_submit_exclusive_op(object, op) < 0)
46671 goto nobufs;
46672 spin_unlock(&cookie->lock);
46673- fscache_stat(&fscache_n_attr_changed_ok);
46674+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46675 fscache_put_operation(op);
46676 _leave(" = 0");
46677 return 0;
46678@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46679 nobufs:
46680 spin_unlock(&cookie->lock);
46681 kfree(op);
46682- fscache_stat(&fscache_n_attr_changed_nobufs);
46683+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46684 _leave(" = %d", -ENOBUFS);
46685 return -ENOBUFS;
46686 }
46687@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46688 /* allocate a retrieval operation and attempt to submit it */
46689 op = kzalloc(sizeof(*op), GFP_NOIO);
46690 if (!op) {
46691- fscache_stat(&fscache_n_retrievals_nomem);
46692+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46693 return NULL;
46694 }
46695
46696@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46697 return 0;
46698 }
46699
46700- fscache_stat(&fscache_n_retrievals_wait);
46701+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
46702
46703 jif = jiffies;
46704 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46705 fscache_wait_bit_interruptible,
46706 TASK_INTERRUPTIBLE) != 0) {
46707- fscache_stat(&fscache_n_retrievals_intr);
46708+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46709 _leave(" = -ERESTARTSYS");
46710 return -ERESTARTSYS;
46711 }
46712@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46713 */
46714 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46715 struct fscache_retrieval *op,
46716- atomic_t *stat_op_waits,
46717- atomic_t *stat_object_dead)
46718+ atomic_unchecked_t *stat_op_waits,
46719+ atomic_unchecked_t *stat_object_dead)
46720 {
46721 int ret;
46722
46723@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46724 goto check_if_dead;
46725
46726 _debug(">>> WT");
46727- fscache_stat(stat_op_waits);
46728+ fscache_stat_unchecked(stat_op_waits);
46729 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46730 fscache_wait_bit_interruptible,
46731 TASK_INTERRUPTIBLE) < 0) {
46732@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46733
46734 check_if_dead:
46735 if (unlikely(fscache_object_is_dead(object))) {
46736- fscache_stat(stat_object_dead);
46737+ fscache_stat_unchecked(stat_object_dead);
46738 return -ENOBUFS;
46739 }
46740 return 0;
46741@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46742
46743 _enter("%p,%p,,,", cookie, page);
46744
46745- fscache_stat(&fscache_n_retrievals);
46746+ fscache_stat_unchecked(&fscache_n_retrievals);
46747
46748 if (hlist_empty(&cookie->backing_objects))
46749 goto nobufs;
46750@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46751 goto nobufs_unlock;
46752 spin_unlock(&cookie->lock);
46753
46754- fscache_stat(&fscache_n_retrieval_ops);
46755+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46756
46757 /* pin the netfs read context in case we need to do the actual netfs
46758 * read because we've encountered a cache read failure */
46759@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46760
46761 error:
46762 if (ret == -ENOMEM)
46763- fscache_stat(&fscache_n_retrievals_nomem);
46764+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46765 else if (ret == -ERESTARTSYS)
46766- fscache_stat(&fscache_n_retrievals_intr);
46767+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46768 else if (ret == -ENODATA)
46769- fscache_stat(&fscache_n_retrievals_nodata);
46770+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46771 else if (ret < 0)
46772- fscache_stat(&fscache_n_retrievals_nobufs);
46773+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46774 else
46775- fscache_stat(&fscache_n_retrievals_ok);
46776+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46777
46778 fscache_put_retrieval(op);
46779 _leave(" = %d", ret);
46780@@ -429,7 +429,7 @@ nobufs_unlock:
46781 spin_unlock(&cookie->lock);
46782 kfree(op);
46783 nobufs:
46784- fscache_stat(&fscache_n_retrievals_nobufs);
46785+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46786 _leave(" = -ENOBUFS");
46787 return -ENOBUFS;
46788 }
46789@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46790
46791 _enter("%p,,%d,,,", cookie, *nr_pages);
46792
46793- fscache_stat(&fscache_n_retrievals);
46794+ fscache_stat_unchecked(&fscache_n_retrievals);
46795
46796 if (hlist_empty(&cookie->backing_objects))
46797 goto nobufs;
46798@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46799 goto nobufs_unlock;
46800 spin_unlock(&cookie->lock);
46801
46802- fscache_stat(&fscache_n_retrieval_ops);
46803+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46804
46805 /* pin the netfs read context in case we need to do the actual netfs
46806 * read because we've encountered a cache read failure */
46807@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46808
46809 error:
46810 if (ret == -ENOMEM)
46811- fscache_stat(&fscache_n_retrievals_nomem);
46812+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46813 else if (ret == -ERESTARTSYS)
46814- fscache_stat(&fscache_n_retrievals_intr);
46815+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46816 else if (ret == -ENODATA)
46817- fscache_stat(&fscache_n_retrievals_nodata);
46818+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46819 else if (ret < 0)
46820- fscache_stat(&fscache_n_retrievals_nobufs);
46821+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46822 else
46823- fscache_stat(&fscache_n_retrievals_ok);
46824+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46825
46826 fscache_put_retrieval(op);
46827 _leave(" = %d", ret);
46828@@ -545,7 +545,7 @@ nobufs_unlock:
46829 spin_unlock(&cookie->lock);
46830 kfree(op);
46831 nobufs:
46832- fscache_stat(&fscache_n_retrievals_nobufs);
46833+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46834 _leave(" = -ENOBUFS");
46835 return -ENOBUFS;
46836 }
46837@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46838
46839 _enter("%p,%p,,,", cookie, page);
46840
46841- fscache_stat(&fscache_n_allocs);
46842+ fscache_stat_unchecked(&fscache_n_allocs);
46843
46844 if (hlist_empty(&cookie->backing_objects))
46845 goto nobufs;
46846@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46847 goto nobufs_unlock;
46848 spin_unlock(&cookie->lock);
46849
46850- fscache_stat(&fscache_n_alloc_ops);
46851+ fscache_stat_unchecked(&fscache_n_alloc_ops);
46852
46853 ret = fscache_wait_for_retrieval_activation(
46854 object, op,
46855@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46856
46857 error:
46858 if (ret == -ERESTARTSYS)
46859- fscache_stat(&fscache_n_allocs_intr);
46860+ fscache_stat_unchecked(&fscache_n_allocs_intr);
46861 else if (ret < 0)
46862- fscache_stat(&fscache_n_allocs_nobufs);
46863+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46864 else
46865- fscache_stat(&fscache_n_allocs_ok);
46866+ fscache_stat_unchecked(&fscache_n_allocs_ok);
46867
46868 fscache_put_retrieval(op);
46869 _leave(" = %d", ret);
46870@@ -625,7 +625,7 @@ nobufs_unlock:
46871 spin_unlock(&cookie->lock);
46872 kfree(op);
46873 nobufs:
46874- fscache_stat(&fscache_n_allocs_nobufs);
46875+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46876 _leave(" = -ENOBUFS");
46877 return -ENOBUFS;
46878 }
46879@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46880
46881 spin_lock(&cookie->stores_lock);
46882
46883- fscache_stat(&fscache_n_store_calls);
46884+ fscache_stat_unchecked(&fscache_n_store_calls);
46885
46886 /* find a page to store */
46887 page = NULL;
46888@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46889 page = results[0];
46890 _debug("gang %d [%lx]", n, page->index);
46891 if (page->index > op->store_limit) {
46892- fscache_stat(&fscache_n_store_pages_over_limit);
46893+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46894 goto superseded;
46895 }
46896
46897@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46898 spin_unlock(&cookie->stores_lock);
46899 spin_unlock(&object->lock);
46900
46901- fscache_stat(&fscache_n_store_pages);
46902+ fscache_stat_unchecked(&fscache_n_store_pages);
46903 fscache_stat(&fscache_n_cop_write_page);
46904 ret = object->cache->ops->write_page(op, page);
46905 fscache_stat_d(&fscache_n_cop_write_page);
46906@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46907 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46908 ASSERT(PageFsCache(page));
46909
46910- fscache_stat(&fscache_n_stores);
46911+ fscache_stat_unchecked(&fscache_n_stores);
46912
46913 op = kzalloc(sizeof(*op), GFP_NOIO);
46914 if (!op)
46915@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46916 spin_unlock(&cookie->stores_lock);
46917 spin_unlock(&object->lock);
46918
46919- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46920+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46921 op->store_limit = object->store_limit;
46922
46923 if (fscache_submit_op(object, &op->op) < 0)
46924@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46925
46926 spin_unlock(&cookie->lock);
46927 radix_tree_preload_end();
46928- fscache_stat(&fscache_n_store_ops);
46929- fscache_stat(&fscache_n_stores_ok);
46930+ fscache_stat_unchecked(&fscache_n_store_ops);
46931+ fscache_stat_unchecked(&fscache_n_stores_ok);
46932
46933 /* the work queue now carries its own ref on the object */
46934 fscache_put_operation(&op->op);
46935@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46936 return 0;
46937
46938 already_queued:
46939- fscache_stat(&fscache_n_stores_again);
46940+ fscache_stat_unchecked(&fscache_n_stores_again);
46941 already_pending:
46942 spin_unlock(&cookie->stores_lock);
46943 spin_unlock(&object->lock);
46944 spin_unlock(&cookie->lock);
46945 radix_tree_preload_end();
46946 kfree(op);
46947- fscache_stat(&fscache_n_stores_ok);
46948+ fscache_stat_unchecked(&fscache_n_stores_ok);
46949 _leave(" = 0");
46950 return 0;
46951
46952@@ -851,14 +851,14 @@ nobufs:
46953 spin_unlock(&cookie->lock);
46954 radix_tree_preload_end();
46955 kfree(op);
46956- fscache_stat(&fscache_n_stores_nobufs);
46957+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
46958 _leave(" = -ENOBUFS");
46959 return -ENOBUFS;
46960
46961 nomem_free:
46962 kfree(op);
46963 nomem:
46964- fscache_stat(&fscache_n_stores_oom);
46965+ fscache_stat_unchecked(&fscache_n_stores_oom);
46966 _leave(" = -ENOMEM");
46967 return -ENOMEM;
46968 }
46969@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46970 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46971 ASSERTCMP(page, !=, NULL);
46972
46973- fscache_stat(&fscache_n_uncaches);
46974+ fscache_stat_unchecked(&fscache_n_uncaches);
46975
46976 /* cache withdrawal may beat us to it */
46977 if (!PageFsCache(page))
46978@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46979 unsigned long loop;
46980
46981 #ifdef CONFIG_FSCACHE_STATS
46982- atomic_add(pagevec->nr, &fscache_n_marks);
46983+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46984 #endif
46985
46986 for (loop = 0; loop < pagevec->nr; loop++) {
46987diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46988index 4765190..2a067f2 100644
46989--- a/fs/fscache/stats.c
46990+++ b/fs/fscache/stats.c
46991@@ -18,95 +18,95 @@
46992 /*
46993 * operation counters
46994 */
46995-atomic_t fscache_n_op_pend;
46996-atomic_t fscache_n_op_run;
46997-atomic_t fscache_n_op_enqueue;
46998-atomic_t fscache_n_op_requeue;
46999-atomic_t fscache_n_op_deferred_release;
47000-atomic_t fscache_n_op_release;
47001-atomic_t fscache_n_op_gc;
47002-atomic_t fscache_n_op_cancelled;
47003-atomic_t fscache_n_op_rejected;
47004+atomic_unchecked_t fscache_n_op_pend;
47005+atomic_unchecked_t fscache_n_op_run;
47006+atomic_unchecked_t fscache_n_op_enqueue;
47007+atomic_unchecked_t fscache_n_op_requeue;
47008+atomic_unchecked_t fscache_n_op_deferred_release;
47009+atomic_unchecked_t fscache_n_op_release;
47010+atomic_unchecked_t fscache_n_op_gc;
47011+atomic_unchecked_t fscache_n_op_cancelled;
47012+atomic_unchecked_t fscache_n_op_rejected;
47013
47014-atomic_t fscache_n_attr_changed;
47015-atomic_t fscache_n_attr_changed_ok;
47016-atomic_t fscache_n_attr_changed_nobufs;
47017-atomic_t fscache_n_attr_changed_nomem;
47018-atomic_t fscache_n_attr_changed_calls;
47019+atomic_unchecked_t fscache_n_attr_changed;
47020+atomic_unchecked_t fscache_n_attr_changed_ok;
47021+atomic_unchecked_t fscache_n_attr_changed_nobufs;
47022+atomic_unchecked_t fscache_n_attr_changed_nomem;
47023+atomic_unchecked_t fscache_n_attr_changed_calls;
47024
47025-atomic_t fscache_n_allocs;
47026-atomic_t fscache_n_allocs_ok;
47027-atomic_t fscache_n_allocs_wait;
47028-atomic_t fscache_n_allocs_nobufs;
47029-atomic_t fscache_n_allocs_intr;
47030-atomic_t fscache_n_allocs_object_dead;
47031-atomic_t fscache_n_alloc_ops;
47032-atomic_t fscache_n_alloc_op_waits;
47033+atomic_unchecked_t fscache_n_allocs;
47034+atomic_unchecked_t fscache_n_allocs_ok;
47035+atomic_unchecked_t fscache_n_allocs_wait;
47036+atomic_unchecked_t fscache_n_allocs_nobufs;
47037+atomic_unchecked_t fscache_n_allocs_intr;
47038+atomic_unchecked_t fscache_n_allocs_object_dead;
47039+atomic_unchecked_t fscache_n_alloc_ops;
47040+atomic_unchecked_t fscache_n_alloc_op_waits;
47041
47042-atomic_t fscache_n_retrievals;
47043-atomic_t fscache_n_retrievals_ok;
47044-atomic_t fscache_n_retrievals_wait;
47045-atomic_t fscache_n_retrievals_nodata;
47046-atomic_t fscache_n_retrievals_nobufs;
47047-atomic_t fscache_n_retrievals_intr;
47048-atomic_t fscache_n_retrievals_nomem;
47049-atomic_t fscache_n_retrievals_object_dead;
47050-atomic_t fscache_n_retrieval_ops;
47051-atomic_t fscache_n_retrieval_op_waits;
47052+atomic_unchecked_t fscache_n_retrievals;
47053+atomic_unchecked_t fscache_n_retrievals_ok;
47054+atomic_unchecked_t fscache_n_retrievals_wait;
47055+atomic_unchecked_t fscache_n_retrievals_nodata;
47056+atomic_unchecked_t fscache_n_retrievals_nobufs;
47057+atomic_unchecked_t fscache_n_retrievals_intr;
47058+atomic_unchecked_t fscache_n_retrievals_nomem;
47059+atomic_unchecked_t fscache_n_retrievals_object_dead;
47060+atomic_unchecked_t fscache_n_retrieval_ops;
47061+atomic_unchecked_t fscache_n_retrieval_op_waits;
47062
47063-atomic_t fscache_n_stores;
47064-atomic_t fscache_n_stores_ok;
47065-atomic_t fscache_n_stores_again;
47066-atomic_t fscache_n_stores_nobufs;
47067-atomic_t fscache_n_stores_oom;
47068-atomic_t fscache_n_store_ops;
47069-atomic_t fscache_n_store_calls;
47070-atomic_t fscache_n_store_pages;
47071-atomic_t fscache_n_store_radix_deletes;
47072-atomic_t fscache_n_store_pages_over_limit;
47073+atomic_unchecked_t fscache_n_stores;
47074+atomic_unchecked_t fscache_n_stores_ok;
47075+atomic_unchecked_t fscache_n_stores_again;
47076+atomic_unchecked_t fscache_n_stores_nobufs;
47077+atomic_unchecked_t fscache_n_stores_oom;
47078+atomic_unchecked_t fscache_n_store_ops;
47079+atomic_unchecked_t fscache_n_store_calls;
47080+atomic_unchecked_t fscache_n_store_pages;
47081+atomic_unchecked_t fscache_n_store_radix_deletes;
47082+atomic_unchecked_t fscache_n_store_pages_over_limit;
47083
47084-atomic_t fscache_n_store_vmscan_not_storing;
47085-atomic_t fscache_n_store_vmscan_gone;
47086-atomic_t fscache_n_store_vmscan_busy;
47087-atomic_t fscache_n_store_vmscan_cancelled;
47088+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47089+atomic_unchecked_t fscache_n_store_vmscan_gone;
47090+atomic_unchecked_t fscache_n_store_vmscan_busy;
47091+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47092
47093-atomic_t fscache_n_marks;
47094-atomic_t fscache_n_uncaches;
47095+atomic_unchecked_t fscache_n_marks;
47096+atomic_unchecked_t fscache_n_uncaches;
47097
47098-atomic_t fscache_n_acquires;
47099-atomic_t fscache_n_acquires_null;
47100-atomic_t fscache_n_acquires_no_cache;
47101-atomic_t fscache_n_acquires_ok;
47102-atomic_t fscache_n_acquires_nobufs;
47103-atomic_t fscache_n_acquires_oom;
47104+atomic_unchecked_t fscache_n_acquires;
47105+atomic_unchecked_t fscache_n_acquires_null;
47106+atomic_unchecked_t fscache_n_acquires_no_cache;
47107+atomic_unchecked_t fscache_n_acquires_ok;
47108+atomic_unchecked_t fscache_n_acquires_nobufs;
47109+atomic_unchecked_t fscache_n_acquires_oom;
47110
47111-atomic_t fscache_n_updates;
47112-atomic_t fscache_n_updates_null;
47113-atomic_t fscache_n_updates_run;
47114+atomic_unchecked_t fscache_n_updates;
47115+atomic_unchecked_t fscache_n_updates_null;
47116+atomic_unchecked_t fscache_n_updates_run;
47117
47118-atomic_t fscache_n_relinquishes;
47119-atomic_t fscache_n_relinquishes_null;
47120-atomic_t fscache_n_relinquishes_waitcrt;
47121-atomic_t fscache_n_relinquishes_retire;
47122+atomic_unchecked_t fscache_n_relinquishes;
47123+atomic_unchecked_t fscache_n_relinquishes_null;
47124+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47125+atomic_unchecked_t fscache_n_relinquishes_retire;
47126
47127-atomic_t fscache_n_cookie_index;
47128-atomic_t fscache_n_cookie_data;
47129-atomic_t fscache_n_cookie_special;
47130+atomic_unchecked_t fscache_n_cookie_index;
47131+atomic_unchecked_t fscache_n_cookie_data;
47132+atomic_unchecked_t fscache_n_cookie_special;
47133
47134-atomic_t fscache_n_object_alloc;
47135-atomic_t fscache_n_object_no_alloc;
47136-atomic_t fscache_n_object_lookups;
47137-atomic_t fscache_n_object_lookups_negative;
47138-atomic_t fscache_n_object_lookups_positive;
47139-atomic_t fscache_n_object_lookups_timed_out;
47140-atomic_t fscache_n_object_created;
47141-atomic_t fscache_n_object_avail;
47142-atomic_t fscache_n_object_dead;
47143+atomic_unchecked_t fscache_n_object_alloc;
47144+atomic_unchecked_t fscache_n_object_no_alloc;
47145+atomic_unchecked_t fscache_n_object_lookups;
47146+atomic_unchecked_t fscache_n_object_lookups_negative;
47147+atomic_unchecked_t fscache_n_object_lookups_positive;
47148+atomic_unchecked_t fscache_n_object_lookups_timed_out;
47149+atomic_unchecked_t fscache_n_object_created;
47150+atomic_unchecked_t fscache_n_object_avail;
47151+atomic_unchecked_t fscache_n_object_dead;
47152
47153-atomic_t fscache_n_checkaux_none;
47154-atomic_t fscache_n_checkaux_okay;
47155-atomic_t fscache_n_checkaux_update;
47156-atomic_t fscache_n_checkaux_obsolete;
47157+atomic_unchecked_t fscache_n_checkaux_none;
47158+atomic_unchecked_t fscache_n_checkaux_okay;
47159+atomic_unchecked_t fscache_n_checkaux_update;
47160+atomic_unchecked_t fscache_n_checkaux_obsolete;
47161
47162 atomic_t fscache_n_cop_alloc_object;
47163 atomic_t fscache_n_cop_lookup_object;
47164@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47165 seq_puts(m, "FS-Cache statistics\n");
47166
47167 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47168- atomic_read(&fscache_n_cookie_index),
47169- atomic_read(&fscache_n_cookie_data),
47170- atomic_read(&fscache_n_cookie_special));
47171+ atomic_read_unchecked(&fscache_n_cookie_index),
47172+ atomic_read_unchecked(&fscache_n_cookie_data),
47173+ atomic_read_unchecked(&fscache_n_cookie_special));
47174
47175 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47176- atomic_read(&fscache_n_object_alloc),
47177- atomic_read(&fscache_n_object_no_alloc),
47178- atomic_read(&fscache_n_object_avail),
47179- atomic_read(&fscache_n_object_dead));
47180+ atomic_read_unchecked(&fscache_n_object_alloc),
47181+ atomic_read_unchecked(&fscache_n_object_no_alloc),
47182+ atomic_read_unchecked(&fscache_n_object_avail),
47183+ atomic_read_unchecked(&fscache_n_object_dead));
47184 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47185- atomic_read(&fscache_n_checkaux_none),
47186- atomic_read(&fscache_n_checkaux_okay),
47187- atomic_read(&fscache_n_checkaux_update),
47188- atomic_read(&fscache_n_checkaux_obsolete));
47189+ atomic_read_unchecked(&fscache_n_checkaux_none),
47190+ atomic_read_unchecked(&fscache_n_checkaux_okay),
47191+ atomic_read_unchecked(&fscache_n_checkaux_update),
47192+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47193
47194 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47195- atomic_read(&fscache_n_marks),
47196- atomic_read(&fscache_n_uncaches));
47197+ atomic_read_unchecked(&fscache_n_marks),
47198+ atomic_read_unchecked(&fscache_n_uncaches));
47199
47200 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47201 " oom=%u\n",
47202- atomic_read(&fscache_n_acquires),
47203- atomic_read(&fscache_n_acquires_null),
47204- atomic_read(&fscache_n_acquires_no_cache),
47205- atomic_read(&fscache_n_acquires_ok),
47206- atomic_read(&fscache_n_acquires_nobufs),
47207- atomic_read(&fscache_n_acquires_oom));
47208+ atomic_read_unchecked(&fscache_n_acquires),
47209+ atomic_read_unchecked(&fscache_n_acquires_null),
47210+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
47211+ atomic_read_unchecked(&fscache_n_acquires_ok),
47212+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
47213+ atomic_read_unchecked(&fscache_n_acquires_oom));
47214
47215 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47216- atomic_read(&fscache_n_object_lookups),
47217- atomic_read(&fscache_n_object_lookups_negative),
47218- atomic_read(&fscache_n_object_lookups_positive),
47219- atomic_read(&fscache_n_object_created),
47220- atomic_read(&fscache_n_object_lookups_timed_out));
47221+ atomic_read_unchecked(&fscache_n_object_lookups),
47222+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
47223+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
47224+ atomic_read_unchecked(&fscache_n_object_created),
47225+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47226
47227 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47228- atomic_read(&fscache_n_updates),
47229- atomic_read(&fscache_n_updates_null),
47230- atomic_read(&fscache_n_updates_run));
47231+ atomic_read_unchecked(&fscache_n_updates),
47232+ atomic_read_unchecked(&fscache_n_updates_null),
47233+ atomic_read_unchecked(&fscache_n_updates_run));
47234
47235 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47236- atomic_read(&fscache_n_relinquishes),
47237- atomic_read(&fscache_n_relinquishes_null),
47238- atomic_read(&fscache_n_relinquishes_waitcrt),
47239- atomic_read(&fscache_n_relinquishes_retire));
47240+ atomic_read_unchecked(&fscache_n_relinquishes),
47241+ atomic_read_unchecked(&fscache_n_relinquishes_null),
47242+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47243+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
47244
47245 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47246- atomic_read(&fscache_n_attr_changed),
47247- atomic_read(&fscache_n_attr_changed_ok),
47248- atomic_read(&fscache_n_attr_changed_nobufs),
47249- atomic_read(&fscache_n_attr_changed_nomem),
47250- atomic_read(&fscache_n_attr_changed_calls));
47251+ atomic_read_unchecked(&fscache_n_attr_changed),
47252+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
47253+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47254+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47255+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
47256
47257 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47258- atomic_read(&fscache_n_allocs),
47259- atomic_read(&fscache_n_allocs_ok),
47260- atomic_read(&fscache_n_allocs_wait),
47261- atomic_read(&fscache_n_allocs_nobufs),
47262- atomic_read(&fscache_n_allocs_intr));
47263+ atomic_read_unchecked(&fscache_n_allocs),
47264+ atomic_read_unchecked(&fscache_n_allocs_ok),
47265+ atomic_read_unchecked(&fscache_n_allocs_wait),
47266+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
47267+ atomic_read_unchecked(&fscache_n_allocs_intr));
47268 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47269- atomic_read(&fscache_n_alloc_ops),
47270- atomic_read(&fscache_n_alloc_op_waits),
47271- atomic_read(&fscache_n_allocs_object_dead));
47272+ atomic_read_unchecked(&fscache_n_alloc_ops),
47273+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
47274+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
47275
47276 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47277 " int=%u oom=%u\n",
47278- atomic_read(&fscache_n_retrievals),
47279- atomic_read(&fscache_n_retrievals_ok),
47280- atomic_read(&fscache_n_retrievals_wait),
47281- atomic_read(&fscache_n_retrievals_nodata),
47282- atomic_read(&fscache_n_retrievals_nobufs),
47283- atomic_read(&fscache_n_retrievals_intr),
47284- atomic_read(&fscache_n_retrievals_nomem));
47285+ atomic_read_unchecked(&fscache_n_retrievals),
47286+ atomic_read_unchecked(&fscache_n_retrievals_ok),
47287+ atomic_read_unchecked(&fscache_n_retrievals_wait),
47288+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
47289+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47290+ atomic_read_unchecked(&fscache_n_retrievals_intr),
47291+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
47292 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47293- atomic_read(&fscache_n_retrieval_ops),
47294- atomic_read(&fscache_n_retrieval_op_waits),
47295- atomic_read(&fscache_n_retrievals_object_dead));
47296+ atomic_read_unchecked(&fscache_n_retrieval_ops),
47297+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47298+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47299
47300 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47301- atomic_read(&fscache_n_stores),
47302- atomic_read(&fscache_n_stores_ok),
47303- atomic_read(&fscache_n_stores_again),
47304- atomic_read(&fscache_n_stores_nobufs),
47305- atomic_read(&fscache_n_stores_oom));
47306+ atomic_read_unchecked(&fscache_n_stores),
47307+ atomic_read_unchecked(&fscache_n_stores_ok),
47308+ atomic_read_unchecked(&fscache_n_stores_again),
47309+ atomic_read_unchecked(&fscache_n_stores_nobufs),
47310+ atomic_read_unchecked(&fscache_n_stores_oom));
47311 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47312- atomic_read(&fscache_n_store_ops),
47313- atomic_read(&fscache_n_store_calls),
47314- atomic_read(&fscache_n_store_pages),
47315- atomic_read(&fscache_n_store_radix_deletes),
47316- atomic_read(&fscache_n_store_pages_over_limit));
47317+ atomic_read_unchecked(&fscache_n_store_ops),
47318+ atomic_read_unchecked(&fscache_n_store_calls),
47319+ atomic_read_unchecked(&fscache_n_store_pages),
47320+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
47321+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47322
47323 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47324- atomic_read(&fscache_n_store_vmscan_not_storing),
47325- atomic_read(&fscache_n_store_vmscan_gone),
47326- atomic_read(&fscache_n_store_vmscan_busy),
47327- atomic_read(&fscache_n_store_vmscan_cancelled));
47328+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47329+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47330+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47331+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47332
47333 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47334- atomic_read(&fscache_n_op_pend),
47335- atomic_read(&fscache_n_op_run),
47336- atomic_read(&fscache_n_op_enqueue),
47337- atomic_read(&fscache_n_op_cancelled),
47338- atomic_read(&fscache_n_op_rejected));
47339+ atomic_read_unchecked(&fscache_n_op_pend),
47340+ atomic_read_unchecked(&fscache_n_op_run),
47341+ atomic_read_unchecked(&fscache_n_op_enqueue),
47342+ atomic_read_unchecked(&fscache_n_op_cancelled),
47343+ atomic_read_unchecked(&fscache_n_op_rejected));
47344 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47345- atomic_read(&fscache_n_op_deferred_release),
47346- atomic_read(&fscache_n_op_release),
47347- atomic_read(&fscache_n_op_gc));
47348+ atomic_read_unchecked(&fscache_n_op_deferred_release),
47349+ atomic_read_unchecked(&fscache_n_op_release),
47350+ atomic_read_unchecked(&fscache_n_op_gc));
47351
47352 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47353 atomic_read(&fscache_n_cop_alloc_object),
47354diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47355index ee8d550..7189d8c 100644
47356--- a/fs/fuse/cuse.c
47357+++ b/fs/fuse/cuse.c
47358@@ -585,10 +585,12 @@ static int __init cuse_init(void)
47359 INIT_LIST_HEAD(&cuse_conntbl[i]);
47360
47361 /* inherit and extend fuse_dev_operations */
47362- cuse_channel_fops = fuse_dev_operations;
47363- cuse_channel_fops.owner = THIS_MODULE;
47364- cuse_channel_fops.open = cuse_channel_open;
47365- cuse_channel_fops.release = cuse_channel_release;
47366+ pax_open_kernel();
47367+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47368+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47369+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
47370+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
47371+ pax_close_kernel();
47372
47373 cuse_class = class_create(THIS_MODULE, "cuse");
47374 if (IS_ERR(cuse_class))
47375diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47376index f4246cf..b4aed1d 100644
47377--- a/fs/fuse/dev.c
47378+++ b/fs/fuse/dev.c
47379@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47380 ret = 0;
47381 pipe_lock(pipe);
47382
47383- if (!pipe->readers) {
47384+ if (!atomic_read(&pipe->readers)) {
47385 send_sig(SIGPIPE, current, 0);
47386 if (!ret)
47387 ret = -EPIPE;
47388diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47389index 324bc08..4fdd56e 100644
47390--- a/fs/fuse/dir.c
47391+++ b/fs/fuse/dir.c
47392@@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47393 return link;
47394 }
47395
47396-static void free_link(char *link)
47397+static void free_link(const char *link)
47398 {
47399 if (!IS_ERR(link))
47400 free_page((unsigned long) link);
47401diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47402index 753af3d..f7b021a 100644
47403--- a/fs/gfs2/inode.c
47404+++ b/fs/gfs2/inode.c
47405@@ -1498,7 +1498,7 @@ out:
47406
47407 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47408 {
47409- char *s = nd_get_link(nd);
47410+ const char *s = nd_get_link(nd);
47411 if (!IS_ERR(s))
47412 kfree(s);
47413 }
47414diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47415index 8349a89..51a0254 100644
47416--- a/fs/hugetlbfs/inode.c
47417+++ b/fs/hugetlbfs/inode.c
47418@@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47419 .kill_sb = kill_litter_super,
47420 };
47421
47422-static struct vfsmount *hugetlbfs_vfsmount;
47423+struct vfsmount *hugetlbfs_vfsmount;
47424
47425 static int can_do_hugetlb_shm(void)
47426 {
47427diff --git a/fs/inode.c b/fs/inode.c
47428index ac8d904..9f45d40 100644
47429--- a/fs/inode.c
47430+++ b/fs/inode.c
47431@@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47432
47433 #ifdef CONFIG_SMP
47434 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47435- static atomic_t shared_last_ino;
47436- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47437+ static atomic_unchecked_t shared_last_ino;
47438+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47439
47440 res = next - LAST_INO_BATCH;
47441 }
47442diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47443index 4a6cf28..d3a29d3 100644
47444--- a/fs/jffs2/erase.c
47445+++ b/fs/jffs2/erase.c
47446@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47447 struct jffs2_unknown_node marker = {
47448 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47449 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47450- .totlen = cpu_to_je32(c->cleanmarker_size)
47451+ .totlen = cpu_to_je32(c->cleanmarker_size),
47452+ .hdr_crc = cpu_to_je32(0)
47453 };
47454
47455 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47456diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47457index 6f4529d..bf12806 100644
47458--- a/fs/jffs2/wbuf.c
47459+++ b/fs/jffs2/wbuf.c
47460@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47461 {
47462 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47463 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47464- .totlen = constant_cpu_to_je32(8)
47465+ .totlen = constant_cpu_to_je32(8),
47466+ .hdr_crc = constant_cpu_to_je32(0)
47467 };
47468
47469 /*
47470diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47471index c55c745..f67ee56 100644
47472--- a/fs/jfs/super.c
47473+++ b/fs/jfs/super.c
47474@@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
47475
47476 jfs_inode_cachep =
47477 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47478- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47479+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47480 init_once);
47481 if (jfs_inode_cachep == NULL)
47482 return -ENOMEM;
47483diff --git a/fs/libfs.c b/fs/libfs.c
47484index a74cb17..37fcbe4 100644
47485--- a/fs/libfs.c
47486+++ b/fs/libfs.c
47487@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47488
47489 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47490 struct dentry *next;
47491+ char d_name[sizeof(next->d_iname)];
47492+ const unsigned char *name;
47493+
47494 next = list_entry(p, struct dentry, d_u.d_child);
47495 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47496 if (!simple_positive(next)) {
47497@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47498
47499 spin_unlock(&next->d_lock);
47500 spin_unlock(&dentry->d_lock);
47501- if (filldir(dirent, next->d_name.name,
47502+ name = next->d_name.name;
47503+ if (name == next->d_iname) {
47504+ memcpy(d_name, name, next->d_name.len);
47505+ name = d_name;
47506+ }
47507+ if (filldir(dirent, name,
47508 next->d_name.len, filp->f_pos,
47509 next->d_inode->i_ino,
47510 dt_type(next->d_inode)) < 0)
47511diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47512index 05d2912..760abfa 100644
47513--- a/fs/lockd/clntproc.c
47514+++ b/fs/lockd/clntproc.c
47515@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47516 /*
47517 * Cookie counter for NLM requests
47518 */
47519-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47520+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47521
47522 void nlmclnt_next_cookie(struct nlm_cookie *c)
47523 {
47524- u32 cookie = atomic_inc_return(&nlm_cookie);
47525+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47526
47527 memcpy(c->data, &cookie, 4);
47528 c->len=4;
47529diff --git a/fs/locks.c b/fs/locks.c
47530index 7e81bfc..c3649aa 100644
47531--- a/fs/locks.c
47532+++ b/fs/locks.c
47533@@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
47534 return;
47535
47536 if (filp->f_op && filp->f_op->flock) {
47537- struct file_lock fl = {
47538+ struct file_lock flock = {
47539 .fl_pid = current->tgid,
47540 .fl_file = filp,
47541 .fl_flags = FL_FLOCK,
47542 .fl_type = F_UNLCK,
47543 .fl_end = OFFSET_MAX,
47544 };
47545- filp->f_op->flock(filp, F_SETLKW, &fl);
47546- if (fl.fl_ops && fl.fl_ops->fl_release_private)
47547- fl.fl_ops->fl_release_private(&fl);
47548+ filp->f_op->flock(filp, F_SETLKW, &flock);
47549+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
47550+ flock.fl_ops->fl_release_private(&flock);
47551 }
47552
47553 lock_flocks();
47554diff --git a/fs/namei.c b/fs/namei.c
47555index dd1ed1b..875e998 100644
47556--- a/fs/namei.c
47557+++ b/fs/namei.c
47558@@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47559 if (ret != -EACCES)
47560 return ret;
47561
47562+#ifdef CONFIG_GRKERNSEC
47563+ /* we'll block if we have to log due to a denied capability use */
47564+ if (mask & MAY_NOT_BLOCK)
47565+ return -ECHILD;
47566+#endif
47567+
47568 if (S_ISDIR(inode->i_mode)) {
47569 /* DACs are overridable for directories */
47570- if (inode_capable(inode, CAP_DAC_OVERRIDE))
47571- return 0;
47572 if (!(mask & MAY_WRITE))
47573- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47574+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47575+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47576 return 0;
47577+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
47578+ return 0;
47579 return -EACCES;
47580 }
47581 /*
47582+ * Searching includes executable on directories, else just read.
47583+ */
47584+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47585+ if (mask == MAY_READ)
47586+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47587+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47588+ return 0;
47589+
47590+ /*
47591 * Read/write DACs are always overridable.
47592 * Executable DACs are overridable when there is
47593 * at least one exec bit set.
47594@@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47595 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47596 return 0;
47597
47598- /*
47599- * Searching includes executable on directories, else just read.
47600- */
47601- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47602- if (mask == MAY_READ)
47603- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47604- return 0;
47605-
47606 return -EACCES;
47607 }
47608
47609@@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47610 {
47611 struct dentry *dentry = link->dentry;
47612 int error;
47613- char *s;
47614+ const char *s;
47615
47616 BUG_ON(nd->flags & LOOKUP_RCU);
47617
47618@@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47619 if (error)
47620 goto out_put_nd_path;
47621
47622+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
47623+ dentry->d_inode, dentry, nd->path.mnt)) {
47624+ error = -EACCES;
47625+ goto out_put_nd_path;
47626+ }
47627+
47628 nd->last_type = LAST_BIND;
47629 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47630 error = PTR_ERR(*p);
47631@@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47632 break;
47633 res = walk_component(nd, path, &nd->last,
47634 nd->last_type, LOOKUP_FOLLOW);
47635+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47636+ res = -EACCES;
47637 put_link(nd, &link, cookie);
47638 } while (res > 0);
47639
47640@@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
47641 if (err)
47642 break;
47643 err = lookup_last(nd, &path);
47644+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
47645+ err = -EACCES;
47646 put_link(nd, &link, cookie);
47647 }
47648 }
47649@@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
47650 if (!err)
47651 err = complete_walk(nd);
47652
47653+ if (!(nd->flags & LOOKUP_PARENT)) {
47654+#ifdef CONFIG_GRKERNSEC
47655+ if (flags & LOOKUP_RCU) {
47656+ if (!err)
47657+ path_put(&nd->path);
47658+ err = -ECHILD;
47659+ } else
47660+#endif
47661+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47662+ if (!err)
47663+ path_put(&nd->path);
47664+ err = -ENOENT;
47665+ }
47666+ }
47667+
47668 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47669 if (!nd->inode->i_op->lookup) {
47670 path_put(&nd->path);
47671@@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
47672 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47673
47674 if (likely(!retval)) {
47675+ if (*name != '/' && nd->path.dentry && nd->inode) {
47676+#ifdef CONFIG_GRKERNSEC
47677+ if (flags & LOOKUP_RCU)
47678+ return -ECHILD;
47679+#endif
47680+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47681+ return -ENOENT;
47682+ }
47683+
47684 if (unlikely(!audit_dummy_context())) {
47685 if (nd->path.dentry && nd->inode)
47686 audit_inode(name, nd->path.dentry);
47687@@ -2336,6 +2378,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47688 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47689 return -EPERM;
47690
47691+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47692+ return -EPERM;
47693+ if (gr_handle_rawio(inode))
47694+ return -EPERM;
47695+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47696+ return -EACCES;
47697+
47698 return 0;
47699 }
47700
47701@@ -2557,7 +2606,7 @@ looked_up:
47702 * cleared otherwise prior to returning.
47703 */
47704 static int lookup_open(struct nameidata *nd, struct path *path,
47705- struct file *file,
47706+ struct path *link, struct file *file,
47707 const struct open_flags *op,
47708 bool got_write, int *opened)
47709 {
47710@@ -2592,6 +2641,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47711 /* Negative dentry, just create the file */
47712 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
47713 umode_t mode = op->mode;
47714+
47715+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47716+ error = -EACCES;
47717+ goto out_dput;
47718+ }
47719+
47720+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
47721+ error = -EACCES;
47722+ goto out_dput;
47723+ }
47724+
47725 if (!IS_POSIXACL(dir->d_inode))
47726 mode &= ~current_umask();
47727 /*
47728@@ -2613,6 +2673,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47729 nd->flags & LOOKUP_EXCL);
47730 if (error)
47731 goto out_dput;
47732+ else
47733+ gr_handle_create(dentry, nd->path.mnt);
47734 }
47735 out_no_open:
47736 path->dentry = dentry;
47737@@ -2627,7 +2689,7 @@ out_dput:
47738 /*
47739 * Handle the last step of open()
47740 */
47741-static int do_last(struct nameidata *nd, struct path *path,
47742+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
47743 struct file *file, const struct open_flags *op,
47744 int *opened, const char *pathname)
47745 {
47746@@ -2656,16 +2718,44 @@ static int do_last(struct nameidata *nd, struct path *path,
47747 error = complete_walk(nd);
47748 if (error)
47749 return error;
47750+#ifdef CONFIG_GRKERNSEC
47751+ if (nd->flags & LOOKUP_RCU) {
47752+ error = -ECHILD;
47753+ goto out;
47754+ }
47755+#endif
47756+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47757+ error = -ENOENT;
47758+ goto out;
47759+ }
47760 audit_inode(pathname, nd->path.dentry);
47761 if (open_flag & O_CREAT) {
47762 error = -EISDIR;
47763 goto out;
47764 }
47765+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47766+ error = -EACCES;
47767+ goto out;
47768+ }
47769 goto finish_open;
47770 case LAST_BIND:
47771 error = complete_walk(nd);
47772 if (error)
47773 return error;
47774+#ifdef CONFIG_GRKERNSEC
47775+ if (nd->flags & LOOKUP_RCU) {
47776+ error = -ECHILD;
47777+ goto out;
47778+ }
47779+#endif
47780+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47781+ error = -ENOENT;
47782+ goto out;
47783+ }
47784+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47785+ error = -EACCES;
47786+ goto out;
47787+ }
47788 audit_inode(pathname, dir);
47789 goto finish_open;
47790 }
47791@@ -2714,7 +2804,7 @@ retry_lookup:
47792 */
47793 }
47794 mutex_lock(&dir->d_inode->i_mutex);
47795- error = lookup_open(nd, path, file, op, got_write, opened);
47796+ error = lookup_open(nd, path, link, file, op, got_write, opened);
47797 mutex_unlock(&dir->d_inode->i_mutex);
47798
47799 if (error <= 0) {
47800@@ -2738,11 +2828,28 @@ retry_lookup:
47801 goto finish_open_created;
47802 }
47803
47804+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
47805+ error = -ENOENT;
47806+ goto exit_dput;
47807+ }
47808+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
47809+ error = -EACCES;
47810+ goto exit_dput;
47811+ }
47812+
47813 /*
47814 * create/update audit record if it already exists.
47815 */
47816- if (path->dentry->d_inode)
47817+ if (path->dentry->d_inode) {
47818+ /* only check if O_CREAT is specified, all other checks need to go
47819+ into may_open */
47820+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47821+ error = -EACCES;
47822+ goto exit_dput;
47823+ }
47824+
47825 audit_inode(pathname, path->dentry);
47826+ }
47827
47828 /*
47829 * If atomic_open() acquired write access it is dropped now due to
47830@@ -2783,6 +2890,11 @@ finish_lookup:
47831 }
47832 }
47833 BUG_ON(inode != path->dentry->d_inode);
47834+ /* if we're resolving a symlink to another symlink */
47835+ if (link && gr_handle_symlink_owner(link, inode)) {
47836+ error = -EACCES;
47837+ goto out;
47838+ }
47839 return 1;
47840 }
47841
47842@@ -2792,7 +2904,6 @@ finish_lookup:
47843 save_parent.dentry = nd->path.dentry;
47844 save_parent.mnt = mntget(path->mnt);
47845 nd->path.dentry = path->dentry;
47846-
47847 }
47848 nd->inode = inode;
47849 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47850@@ -2801,6 +2912,22 @@ finish_lookup:
47851 path_put(&save_parent);
47852 return error;
47853 }
47854+
47855+#ifdef CONFIG_GRKERNSEC
47856+ if (nd->flags & LOOKUP_RCU) {
47857+ error = -ECHILD;
47858+ goto out;
47859+ }
47860+#endif
47861+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47862+ error = -ENOENT;
47863+ goto out;
47864+ }
47865+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47866+ error = -EACCES;
47867+ goto out;
47868+ }
47869+
47870 error = -EISDIR;
47871 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47872 goto out;
47873@@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47874 if (unlikely(error))
47875 goto out;
47876
47877- error = do_last(nd, &path, file, op, &opened, pathname);
47878+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
47879 while (unlikely(error > 0)) { /* trailing symlink */
47880 struct path link = path;
47881 void *cookie;
47882@@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47883 error = follow_link(&link, nd, &cookie);
47884 if (unlikely(error))
47885 break;
47886- error = do_last(nd, &path, file, op, &opened, pathname);
47887+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
47888 put_link(nd, &link, cookie);
47889 }
47890 out:
47891@@ -3006,8 +3133,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47892 goto unlock;
47893
47894 error = -EEXIST;
47895- if (dentry->d_inode)
47896+ if (dentry->d_inode) {
47897+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47898+ error = -ENOENT;
47899+ }
47900 goto fail;
47901+ }
47902 /*
47903 * Special case - lookup gave negative, but... we had foo/bar/
47904 * From the vfs_mknod() POV we just have a negative dentry -
47905@@ -3058,6 +3189,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47906 }
47907 EXPORT_SYMBOL(user_path_create);
47908
47909+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47910+{
47911+ char *tmp = getname(pathname);
47912+ struct dentry *res;
47913+ if (IS_ERR(tmp))
47914+ return ERR_CAST(tmp);
47915+ res = kern_path_create(dfd, tmp, path, is_dir);
47916+ if (IS_ERR(res))
47917+ putname(tmp);
47918+ else
47919+ *to = tmp;
47920+ return res;
47921+}
47922+
47923 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47924 {
47925 int error = may_create(dir, dentry);
47926@@ -3119,6 +3264,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47927
47928 if (!IS_POSIXACL(path.dentry->d_inode))
47929 mode &= ~current_umask();
47930+
47931+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47932+ error = -EPERM;
47933+ goto out;
47934+ }
47935+
47936+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47937+ error = -EACCES;
47938+ goto out;
47939+ }
47940+
47941 error = security_path_mknod(&path, dentry, mode, dev);
47942 if (error)
47943 goto out;
47944@@ -3135,6 +3291,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47945 break;
47946 }
47947 out:
47948+ if (!error)
47949+ gr_handle_create(dentry, path.mnt);
47950 done_path_create(&path, dentry);
47951 return error;
47952 }
47953@@ -3181,9 +3339,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47954
47955 if (!IS_POSIXACL(path.dentry->d_inode))
47956 mode &= ~current_umask();
47957+
47958+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47959+ error = -EACCES;
47960+ goto out;
47961+ }
47962+
47963 error = security_path_mkdir(&path, dentry, mode);
47964 if (!error)
47965 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47966+ if (!error)
47967+ gr_handle_create(dentry, path.mnt);
47968+out:
47969 done_path_create(&path, dentry);
47970 return error;
47971 }
47972@@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47973 char * name;
47974 struct dentry *dentry;
47975 struct nameidata nd;
47976+ ino_t saved_ino = 0;
47977+ dev_t saved_dev = 0;
47978
47979 error = user_path_parent(dfd, pathname, &nd, &name);
47980 if (error)
47981@@ -3291,10 +3460,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
47982 error = -ENOENT;
47983 goto exit3;
47984 }
47985+
47986+ saved_ino = dentry->d_inode->i_ino;
47987+ saved_dev = gr_get_dev_from_dentry(dentry);
47988+
47989+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47990+ error = -EACCES;
47991+ goto exit3;
47992+ }
47993+
47994 error = security_path_rmdir(&nd.path, dentry);
47995 if (error)
47996 goto exit3;
47997 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47998+ if (!error && (saved_dev || saved_ino))
47999+ gr_handle_delete(saved_ino, saved_dev);
48000 exit3:
48001 dput(dentry);
48002 exit2:
48003@@ -3356,6 +3536,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48004 struct dentry *dentry;
48005 struct nameidata nd;
48006 struct inode *inode = NULL;
48007+ ino_t saved_ino = 0;
48008+ dev_t saved_dev = 0;
48009
48010 error = user_path_parent(dfd, pathname, &nd, &name);
48011 if (error)
48012@@ -3381,10 +3563,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48013 if (!inode)
48014 goto slashes;
48015 ihold(inode);
48016+
48017+ if (inode->i_nlink <= 1) {
48018+ saved_ino = inode->i_ino;
48019+ saved_dev = gr_get_dev_from_dentry(dentry);
48020+ }
48021+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48022+ error = -EACCES;
48023+ goto exit2;
48024+ }
48025+
48026 error = security_path_unlink(&nd.path, dentry);
48027 if (error)
48028 goto exit2;
48029 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48030+ if (!error && (saved_ino || saved_dev))
48031+ gr_handle_delete(saved_ino, saved_dev);
48032 exit2:
48033 dput(dentry);
48034 }
48035@@ -3456,9 +3650,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48036 if (IS_ERR(dentry))
48037 goto out_putname;
48038
48039+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48040+ error = -EACCES;
48041+ goto out;
48042+ }
48043+
48044 error = security_path_symlink(&path, dentry, from);
48045 if (!error)
48046 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48047+ if (!error)
48048+ gr_handle_create(dentry, path.mnt);
48049+out:
48050 done_path_create(&path, dentry);
48051 out_putname:
48052 putname(from);
48053@@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48054 {
48055 struct dentry *new_dentry;
48056 struct path old_path, new_path;
48057+ char *to = NULL;
48058 int how = 0;
48059 int error;
48060
48061@@ -3551,7 +3754,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48062 if (error)
48063 return error;
48064
48065- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48066+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48067 error = PTR_ERR(new_dentry);
48068 if (IS_ERR(new_dentry))
48069 goto out;
48070@@ -3562,11 +3765,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48071 error = may_linkat(&old_path);
48072 if (unlikely(error))
48073 goto out_dput;
48074+
48075+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48076+ old_path.dentry->d_inode,
48077+ old_path.dentry->d_inode->i_mode, to)) {
48078+ error = -EACCES;
48079+ goto out_dput;
48080+ }
48081+
48082+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48083+ old_path.dentry, old_path.mnt, to)) {
48084+ error = -EACCES;
48085+ goto out_dput;
48086+ }
48087+
48088 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48089 if (error)
48090 goto out_dput;
48091 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48092+ if (!error)
48093+ gr_handle_create(new_dentry, new_path.mnt);
48094 out_dput:
48095+ putname(to);
48096 done_path_create(&new_path, new_dentry);
48097 out:
48098 path_put(&old_path);
48099@@ -3802,12 +4022,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48100 if (new_dentry == trap)
48101 goto exit5;
48102
48103+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48104+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
48105+ to);
48106+ if (error)
48107+ goto exit5;
48108+
48109 error = security_path_rename(&oldnd.path, old_dentry,
48110 &newnd.path, new_dentry);
48111 if (error)
48112 goto exit5;
48113 error = vfs_rename(old_dir->d_inode, old_dentry,
48114 new_dir->d_inode, new_dentry);
48115+ if (!error)
48116+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48117+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48118 exit5:
48119 dput(new_dentry);
48120 exit4:
48121@@ -3832,6 +4061,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48122
48123 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48124 {
48125+ char tmpbuf[64];
48126+ const char *newlink;
48127 int len;
48128
48129 len = PTR_ERR(link);
48130@@ -3841,7 +4072,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48131 len = strlen(link);
48132 if (len > (unsigned) buflen)
48133 len = buflen;
48134- if (copy_to_user(buffer, link, len))
48135+
48136+ if (len < sizeof(tmpbuf)) {
48137+ memcpy(tmpbuf, link, len);
48138+ newlink = tmpbuf;
48139+ } else
48140+ newlink = link;
48141+
48142+ if (copy_to_user(buffer, newlink, len))
48143 len = -EFAULT;
48144 out:
48145 return len;
48146diff --git a/fs/namespace.c b/fs/namespace.c
48147index 7bdf790..eb79c4b 100644
48148--- a/fs/namespace.c
48149+++ b/fs/namespace.c
48150@@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48151 if (!(sb->s_flags & MS_RDONLY))
48152 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48153 up_write(&sb->s_umount);
48154+
48155+ gr_log_remount(mnt->mnt_devname, retval);
48156+
48157 return retval;
48158 }
48159
48160@@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48161 br_write_unlock(&vfsmount_lock);
48162 up_write(&namespace_sem);
48163 release_mounts(&umount_list);
48164+
48165+ gr_log_unmount(mnt->mnt_devname, retval);
48166+
48167 return retval;
48168 }
48169
48170@@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48171 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48172 MS_STRICTATIME);
48173
48174+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48175+ retval = -EPERM;
48176+ goto dput_out;
48177+ }
48178+
48179+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48180+ retval = -EPERM;
48181+ goto dput_out;
48182+ }
48183+
48184 if (flags & MS_REMOUNT)
48185 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48186 data_page);
48187@@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48188 dev_name, data_page);
48189 dput_out:
48190 path_put(&path);
48191+
48192+ gr_log_mount(dev_name, dir_name, retval);
48193+
48194 return retval;
48195 }
48196
48197@@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48198 if (error)
48199 goto out2;
48200
48201+ if (gr_handle_chroot_pivot()) {
48202+ error = -EPERM;
48203+ goto out2;
48204+ }
48205+
48206 get_fs_root(current->fs, &root);
48207 error = lock_mount(&old);
48208 if (error)
48209diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48210index 9b47610..066975e 100644
48211--- a/fs/nfs/inode.c
48212+++ b/fs/nfs/inode.c
48213@@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48214 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48215 }
48216
48217-static atomic_long_t nfs_attr_generation_counter;
48218+static atomic_long_unchecked_t nfs_attr_generation_counter;
48219
48220 static unsigned long nfs_read_attr_generation_counter(void)
48221 {
48222- return atomic_long_read(&nfs_attr_generation_counter);
48223+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48224 }
48225
48226 unsigned long nfs_inc_attr_generation_counter(void)
48227 {
48228- return atomic_long_inc_return(&nfs_attr_generation_counter);
48229+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48230 }
48231
48232 void nfs_fattr_init(struct nfs_fattr *fattr)
48233diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48234index a9269f1..5490437 100644
48235--- a/fs/nfsd/vfs.c
48236+++ b/fs/nfsd/vfs.c
48237@@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48238 } else {
48239 oldfs = get_fs();
48240 set_fs(KERNEL_DS);
48241- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48242+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48243 set_fs(oldfs);
48244 }
48245
48246@@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48247
48248 /* Write the data. */
48249 oldfs = get_fs(); set_fs(KERNEL_DS);
48250- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48251+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48252 set_fs(oldfs);
48253 if (host_err < 0)
48254 goto out_nfserr;
48255@@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48256 */
48257
48258 oldfs = get_fs(); set_fs(KERNEL_DS);
48259- host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48260+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48261 set_fs(oldfs);
48262
48263 if (host_err < 0)
48264diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48265index d438036..0ecadde 100644
48266--- a/fs/notify/fanotify/fanotify_user.c
48267+++ b/fs/notify/fanotify/fanotify_user.c
48268@@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48269 goto out_close_fd;
48270
48271 ret = -EFAULT;
48272- if (copy_to_user(buf, &fanotify_event_metadata,
48273+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48274+ copy_to_user(buf, &fanotify_event_metadata,
48275 fanotify_event_metadata.event_len))
48276 goto out_kill_access_response;
48277
48278diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48279index c887b13..0fdf472 100644
48280--- a/fs/notify/notification.c
48281+++ b/fs/notify/notification.c
48282@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48283 * get set to 0 so it will never get 'freed'
48284 */
48285 static struct fsnotify_event *q_overflow_event;
48286-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48287+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48288
48289 /**
48290 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48291@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48292 */
48293 u32 fsnotify_get_cookie(void)
48294 {
48295- return atomic_inc_return(&fsnotify_sync_cookie);
48296+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48297 }
48298 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48299
48300diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48301index 99e3610..02c1068 100644
48302--- a/fs/ntfs/dir.c
48303+++ b/fs/ntfs/dir.c
48304@@ -1329,7 +1329,7 @@ find_next_index_buffer:
48305 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48306 ~(s64)(ndir->itype.index.block_size - 1)));
48307 /* Bounds checks. */
48308- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48309+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48310 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48311 "inode 0x%lx or driver bug.", vdir->i_ino);
48312 goto err_out;
48313diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48314index 1ecf464..e1ff8bf 100644
48315--- a/fs/ntfs/file.c
48316+++ b/fs/ntfs/file.c
48317@@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48318 #endif /* NTFS_RW */
48319 };
48320
48321-const struct file_operations ntfs_empty_file_ops = {};
48322+const struct file_operations ntfs_empty_file_ops __read_only;
48323
48324-const struct inode_operations ntfs_empty_inode_ops = {};
48325+const struct inode_operations ntfs_empty_inode_ops __read_only;
48326diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48327index a9f78c7..ed8a381 100644
48328--- a/fs/ocfs2/localalloc.c
48329+++ b/fs/ocfs2/localalloc.c
48330@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48331 goto bail;
48332 }
48333
48334- atomic_inc(&osb->alloc_stats.moves);
48335+ atomic_inc_unchecked(&osb->alloc_stats.moves);
48336
48337 bail:
48338 if (handle)
48339diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48340index d355e6e..578d905 100644
48341--- a/fs/ocfs2/ocfs2.h
48342+++ b/fs/ocfs2/ocfs2.h
48343@@ -235,11 +235,11 @@ enum ocfs2_vol_state
48344
48345 struct ocfs2_alloc_stats
48346 {
48347- atomic_t moves;
48348- atomic_t local_data;
48349- atomic_t bitmap_data;
48350- atomic_t bg_allocs;
48351- atomic_t bg_extends;
48352+ atomic_unchecked_t moves;
48353+ atomic_unchecked_t local_data;
48354+ atomic_unchecked_t bitmap_data;
48355+ atomic_unchecked_t bg_allocs;
48356+ atomic_unchecked_t bg_extends;
48357 };
48358
48359 enum ocfs2_local_alloc_state
48360diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48361index f169da4..9112253 100644
48362--- a/fs/ocfs2/suballoc.c
48363+++ b/fs/ocfs2/suballoc.c
48364@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48365 mlog_errno(status);
48366 goto bail;
48367 }
48368- atomic_inc(&osb->alloc_stats.bg_extends);
48369+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48370
48371 /* You should never ask for this much metadata */
48372 BUG_ON(bits_wanted >
48373@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48374 mlog_errno(status);
48375 goto bail;
48376 }
48377- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48378+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48379
48380 *suballoc_loc = res.sr_bg_blkno;
48381 *suballoc_bit_start = res.sr_bit_offset;
48382@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48383 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48384 res->sr_bits);
48385
48386- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48387+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48388
48389 BUG_ON(res->sr_bits != 1);
48390
48391@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48392 mlog_errno(status);
48393 goto bail;
48394 }
48395- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48396+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48397
48398 BUG_ON(res.sr_bits != 1);
48399
48400@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48401 cluster_start,
48402 num_clusters);
48403 if (!status)
48404- atomic_inc(&osb->alloc_stats.local_data);
48405+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
48406 } else {
48407 if (min_clusters > (osb->bitmap_cpg - 1)) {
48408 /* The only paths asking for contiguousness
48409@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48410 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48411 res.sr_bg_blkno,
48412 res.sr_bit_offset);
48413- atomic_inc(&osb->alloc_stats.bitmap_data);
48414+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48415 *num_clusters = res.sr_bits;
48416 }
48417 }
48418diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48419index 68f4541..89cfe6a 100644
48420--- a/fs/ocfs2/super.c
48421+++ b/fs/ocfs2/super.c
48422@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48423 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48424 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48425 "Stats",
48426- atomic_read(&osb->alloc_stats.bitmap_data),
48427- atomic_read(&osb->alloc_stats.local_data),
48428- atomic_read(&osb->alloc_stats.bg_allocs),
48429- atomic_read(&osb->alloc_stats.moves),
48430- atomic_read(&osb->alloc_stats.bg_extends));
48431+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48432+ atomic_read_unchecked(&osb->alloc_stats.local_data),
48433+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48434+ atomic_read_unchecked(&osb->alloc_stats.moves),
48435+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48436
48437 out += snprintf(buf + out, len - out,
48438 "%10s => State: %u Descriptor: %llu Size: %u bits "
48439@@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48440 spin_lock_init(&osb->osb_xattr_lock);
48441 ocfs2_init_steal_slots(osb);
48442
48443- atomic_set(&osb->alloc_stats.moves, 0);
48444- atomic_set(&osb->alloc_stats.local_data, 0);
48445- atomic_set(&osb->alloc_stats.bitmap_data, 0);
48446- atomic_set(&osb->alloc_stats.bg_allocs, 0);
48447- atomic_set(&osb->alloc_stats.bg_extends, 0);
48448+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48449+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48450+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48451+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48452+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48453
48454 /* Copy the blockcheck stats from the superblock probe */
48455 osb->osb_ecc_stats = *stats;
48456diff --git a/fs/open.c b/fs/open.c
48457index e1f2cdb..3bd5f39 100644
48458--- a/fs/open.c
48459+++ b/fs/open.c
48460@@ -31,6 +31,8 @@
48461 #include <linux/ima.h>
48462 #include <linux/dnotify.h>
48463
48464+#define CREATE_TRACE_POINTS
48465+#include <trace/events/fs.h>
48466 #include "internal.h"
48467
48468 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48469@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48470 error = locks_verify_truncate(inode, NULL, length);
48471 if (!error)
48472 error = security_path_truncate(&path);
48473+
48474+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48475+ error = -EACCES;
48476+
48477 if (!error)
48478 error = do_truncate(path.dentry, length, 0, NULL);
48479
48480@@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48481 if (__mnt_is_readonly(path.mnt))
48482 res = -EROFS;
48483
48484+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48485+ res = -EACCES;
48486+
48487 out_path_release:
48488 path_put(&path);
48489 out:
48490@@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48491 if (error)
48492 goto dput_and_out;
48493
48494+ gr_log_chdir(path.dentry, path.mnt);
48495+
48496 set_fs_pwd(current->fs, &path);
48497
48498 dput_and_out:
48499@@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48500 goto out_putf;
48501
48502 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48503+
48504+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48505+ error = -EPERM;
48506+
48507+ if (!error)
48508+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48509+
48510 if (!error)
48511 set_fs_pwd(current->fs, &file->f_path);
48512 out_putf:
48513@@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48514 if (error)
48515 goto dput_and_out;
48516
48517+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48518+ goto dput_and_out;
48519+
48520 set_fs_root(current->fs, &path);
48521+
48522+ gr_handle_chroot_chdir(&path);
48523+
48524 error = 0;
48525 dput_and_out:
48526 path_put(&path);
48527@@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
48528 if (error)
48529 return error;
48530 mutex_lock(&inode->i_mutex);
48531+
48532+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48533+ error = -EACCES;
48534+ goto out_unlock;
48535+ }
48536+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48537+ error = -EACCES;
48538+ goto out_unlock;
48539+ }
48540+
48541 error = security_path_chmod(path, mode);
48542 if (error)
48543 goto out_unlock;
48544@@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48545 uid = make_kuid(current_user_ns(), user);
48546 gid = make_kgid(current_user_ns(), group);
48547
48548+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
48549+ return -EACCES;
48550+
48551 newattrs.ia_valid = ATTR_CTIME;
48552 if (user != (uid_t) -1) {
48553 if (!uid_valid(uid))
48554@@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48555 } else {
48556 fsnotify_open(f);
48557 fd_install(fd, f);
48558+ trace_do_sys_open(tmp, flags, mode);
48559 }
48560 }
48561 putname(tmp);
48562diff --git a/fs/pipe.c b/fs/pipe.c
48563index 8d85d70..581036b 100644
48564--- a/fs/pipe.c
48565+++ b/fs/pipe.c
48566@@ -438,9 +438,9 @@ redo:
48567 }
48568 if (bufs) /* More to do? */
48569 continue;
48570- if (!pipe->writers)
48571+ if (!atomic_read(&pipe->writers))
48572 break;
48573- if (!pipe->waiting_writers) {
48574+ if (!atomic_read(&pipe->waiting_writers)) {
48575 /* syscall merging: Usually we must not sleep
48576 * if O_NONBLOCK is set, or if we got some data.
48577 * But if a writer sleeps in kernel space, then
48578@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48579 mutex_lock(&inode->i_mutex);
48580 pipe = inode->i_pipe;
48581
48582- if (!pipe->readers) {
48583+ if (!atomic_read(&pipe->readers)) {
48584 send_sig(SIGPIPE, current, 0);
48585 ret = -EPIPE;
48586 goto out;
48587@@ -553,7 +553,7 @@ redo1:
48588 for (;;) {
48589 int bufs;
48590
48591- if (!pipe->readers) {
48592+ if (!atomic_read(&pipe->readers)) {
48593 send_sig(SIGPIPE, current, 0);
48594 if (!ret)
48595 ret = -EPIPE;
48596@@ -644,9 +644,9 @@ redo2:
48597 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48598 do_wakeup = 0;
48599 }
48600- pipe->waiting_writers++;
48601+ atomic_inc(&pipe->waiting_writers);
48602 pipe_wait(pipe);
48603- pipe->waiting_writers--;
48604+ atomic_dec(&pipe->waiting_writers);
48605 }
48606 out:
48607 mutex_unlock(&inode->i_mutex);
48608@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48609 mask = 0;
48610 if (filp->f_mode & FMODE_READ) {
48611 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48612- if (!pipe->writers && filp->f_version != pipe->w_counter)
48613+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48614 mask |= POLLHUP;
48615 }
48616
48617@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48618 * Most Unices do not set POLLERR for FIFOs but on Linux they
48619 * behave exactly like pipes for poll().
48620 */
48621- if (!pipe->readers)
48622+ if (!atomic_read(&pipe->readers))
48623 mask |= POLLERR;
48624 }
48625
48626@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48627
48628 mutex_lock(&inode->i_mutex);
48629 pipe = inode->i_pipe;
48630- pipe->readers -= decr;
48631- pipe->writers -= decw;
48632+ atomic_sub(decr, &pipe->readers);
48633+ atomic_sub(decw, &pipe->writers);
48634
48635- if (!pipe->readers && !pipe->writers) {
48636+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48637 free_pipe_info(inode);
48638 } else {
48639 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48640@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48641
48642 if (inode->i_pipe) {
48643 ret = 0;
48644- inode->i_pipe->readers++;
48645+ atomic_inc(&inode->i_pipe->readers);
48646 }
48647
48648 mutex_unlock(&inode->i_mutex);
48649@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48650
48651 if (inode->i_pipe) {
48652 ret = 0;
48653- inode->i_pipe->writers++;
48654+ atomic_inc(&inode->i_pipe->writers);
48655 }
48656
48657 mutex_unlock(&inode->i_mutex);
48658@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48659 if (inode->i_pipe) {
48660 ret = 0;
48661 if (filp->f_mode & FMODE_READ)
48662- inode->i_pipe->readers++;
48663+ atomic_inc(&inode->i_pipe->readers);
48664 if (filp->f_mode & FMODE_WRITE)
48665- inode->i_pipe->writers++;
48666+ atomic_inc(&inode->i_pipe->writers);
48667 }
48668
48669 mutex_unlock(&inode->i_mutex);
48670@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48671 inode->i_pipe = NULL;
48672 }
48673
48674-static struct vfsmount *pipe_mnt __read_mostly;
48675+struct vfsmount *pipe_mnt __read_mostly;
48676
48677 /*
48678 * pipefs_dname() is called from d_path().
48679@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48680 goto fail_iput;
48681 inode->i_pipe = pipe;
48682
48683- pipe->readers = pipe->writers = 1;
48684+ atomic_set(&pipe->readers, 1);
48685+ atomic_set(&pipe->writers, 1);
48686 inode->i_fop = &rdwr_pipefifo_fops;
48687
48688 /*
48689diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48690index 15af622..0e9f4467 100644
48691--- a/fs/proc/Kconfig
48692+++ b/fs/proc/Kconfig
48693@@ -30,12 +30,12 @@ config PROC_FS
48694
48695 config PROC_KCORE
48696 bool "/proc/kcore support" if !ARM
48697- depends on PROC_FS && MMU
48698+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48699
48700 config PROC_VMCORE
48701 bool "/proc/vmcore support"
48702- depends on PROC_FS && CRASH_DUMP
48703- default y
48704+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48705+ default n
48706 help
48707 Exports the dump image of crashed kernel in ELF format.
48708
48709@@ -59,8 +59,8 @@ config PROC_SYSCTL
48710 limited in memory.
48711
48712 config PROC_PAGE_MONITOR
48713- default y
48714- depends on PROC_FS && MMU
48715+ default n
48716+ depends on PROC_FS && MMU && !GRKERNSEC
48717 bool "Enable /proc page monitoring" if EXPERT
48718 help
48719 Various /proc files exist to monitor process memory utilization:
48720diff --git a/fs/proc/array.c b/fs/proc/array.c
48721index c1c207c..01ce725 100644
48722--- a/fs/proc/array.c
48723+++ b/fs/proc/array.c
48724@@ -60,6 +60,7 @@
48725 #include <linux/tty.h>
48726 #include <linux/string.h>
48727 #include <linux/mman.h>
48728+#include <linux/grsecurity.h>
48729 #include <linux/proc_fs.h>
48730 #include <linux/ioport.h>
48731 #include <linux/uaccess.h>
48732@@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48733 seq_putc(m, '\n');
48734 }
48735
48736+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48737+static inline void task_pax(struct seq_file *m, struct task_struct *p)
48738+{
48739+ if (p->mm)
48740+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48741+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48742+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48743+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48744+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48745+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48746+ else
48747+ seq_printf(m, "PaX:\t-----\n");
48748+}
48749+#endif
48750+
48751 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48752 struct pid *pid, struct task_struct *task)
48753 {
48754@@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48755 task_cpus_allowed(m, task);
48756 cpuset_task_status_allowed(m, task);
48757 task_context_switch_counts(m, task);
48758+
48759+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48760+ task_pax(m, task);
48761+#endif
48762+
48763+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48764+ task_grsec_rbac(m, task);
48765+#endif
48766+
48767 return 0;
48768 }
48769
48770+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48771+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48772+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48773+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48774+#endif
48775+
48776 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48777 struct pid *pid, struct task_struct *task, int whole)
48778 {
48779@@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48780 char tcomm[sizeof(task->comm)];
48781 unsigned long flags;
48782
48783+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48784+ if (current->exec_id != m->exec_id) {
48785+ gr_log_badprocpid("stat");
48786+ return 0;
48787+ }
48788+#endif
48789+
48790 state = *get_task_state(task);
48791 vsize = eip = esp = 0;
48792 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48793@@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48794 gtime = task->gtime;
48795 }
48796
48797+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48798+ if (PAX_RAND_FLAGS(mm)) {
48799+ eip = 0;
48800+ esp = 0;
48801+ wchan = 0;
48802+ }
48803+#endif
48804+#ifdef CONFIG_GRKERNSEC_HIDESYM
48805+ wchan = 0;
48806+ eip =0;
48807+ esp =0;
48808+#endif
48809+
48810 /* scale priority and nice values from timeslices to -20..20 */
48811 /* to make it look like a "normal" Unix priority/nice value */
48812 priority = task_prio(task);
48813@@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48814 seq_put_decimal_ull(m, ' ', vsize);
48815 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48816 seq_put_decimal_ull(m, ' ', rsslim);
48817+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48818+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48819+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48820+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48821+#else
48822 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48823 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48824 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48825+#endif
48826 seq_put_decimal_ull(m, ' ', esp);
48827 seq_put_decimal_ull(m, ' ', eip);
48828 /* The signal information here is obsolete.
48829@@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48830 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48831 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48832
48833- if (mm && permitted) {
48834+ if (mm && permitted
48835+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48836+ && !PAX_RAND_FLAGS(mm)
48837+#endif
48838+ ) {
48839 seq_put_decimal_ull(m, ' ', mm->start_data);
48840 seq_put_decimal_ull(m, ' ', mm->end_data);
48841 seq_put_decimal_ull(m, ' ', mm->start_brk);
48842@@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48843 struct pid *pid, struct task_struct *task)
48844 {
48845 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48846- struct mm_struct *mm = get_task_mm(task);
48847+ struct mm_struct *mm;
48848
48849+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48850+ if (current->exec_id != m->exec_id) {
48851+ gr_log_badprocpid("statm");
48852+ return 0;
48853+ }
48854+#endif
48855+ mm = get_task_mm(task);
48856 if (mm) {
48857 size = task_statm(mm, &shared, &text, &data, &resident);
48858 mmput(mm);
48859@@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48860 return 0;
48861 }
48862
48863+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48864+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48865+{
48866+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
48867+}
48868+#endif
48869+
48870 #ifdef CONFIG_CHECKPOINT_RESTORE
48871 static struct pid *
48872 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48873diff --git a/fs/proc/base.c b/fs/proc/base.c
48874index 1b6c84c..66b738b 100644
48875--- a/fs/proc/base.c
48876+++ b/fs/proc/base.c
48877@@ -110,6 +110,14 @@ struct pid_entry {
48878 union proc_op op;
48879 };
48880
48881+struct getdents_callback {
48882+ struct linux_dirent __user * current_dir;
48883+ struct linux_dirent __user * previous;
48884+ struct file * file;
48885+ int count;
48886+ int error;
48887+};
48888+
48889 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48890 .name = (NAME), \
48891 .len = sizeof(NAME) - 1, \
48892@@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48893 if (!mm->arg_end)
48894 goto out_mm; /* Shh! No looking before we're done */
48895
48896+ if (gr_acl_handle_procpidmem(task))
48897+ goto out_mm;
48898+
48899 len = mm->arg_end - mm->arg_start;
48900
48901 if (len > PAGE_SIZE)
48902@@ -236,12 +247,28 @@ out:
48903 return res;
48904 }
48905
48906+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48907+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48908+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48909+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48910+#endif
48911+
48912 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48913 {
48914 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48915 int res = PTR_ERR(mm);
48916 if (mm && !IS_ERR(mm)) {
48917 unsigned int nwords = 0;
48918+
48919+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48920+ /* allow if we're currently ptracing this task */
48921+ if (PAX_RAND_FLAGS(mm) &&
48922+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48923+ mmput(mm);
48924+ return 0;
48925+ }
48926+#endif
48927+
48928 do {
48929 nwords += 2;
48930 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48931@@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48932 }
48933
48934
48935-#ifdef CONFIG_KALLSYMS
48936+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48937 /*
48938 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48939 * Returns the resolved symbol. If that fails, simply return the address.
48940@@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48941 mutex_unlock(&task->signal->cred_guard_mutex);
48942 }
48943
48944-#ifdef CONFIG_STACKTRACE
48945+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48946
48947 #define MAX_STACK_TRACE_DEPTH 64
48948
48949@@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48950 return count;
48951 }
48952
48953-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48954+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48955 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48956 {
48957 long nr;
48958@@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48959 /************************************************************************/
48960
48961 /* permission checks */
48962-static int proc_fd_access_allowed(struct inode *inode)
48963+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48964 {
48965 struct task_struct *task;
48966 int allowed = 0;
48967@@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48968 */
48969 task = get_proc_task(inode);
48970 if (task) {
48971- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48972+ if (log)
48973+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48974+ else
48975+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48976 put_task_struct(task);
48977 }
48978 return allowed;
48979@@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48980 struct task_struct *task,
48981 int hide_pid_min)
48982 {
48983+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48984+ return false;
48985+
48986+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48987+ rcu_read_lock();
48988+ {
48989+ const struct cred *tmpcred = current_cred();
48990+ const struct cred *cred = __task_cred(task);
48991+
48992+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48993+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48994+ || in_group_p(grsec_proc_gid)
48995+#endif
48996+ ) {
48997+ rcu_read_unlock();
48998+ return true;
48999+ }
49000+ }
49001+ rcu_read_unlock();
49002+
49003+ if (!pid->hide_pid)
49004+ return false;
49005+#endif
49006+
49007 if (pid->hide_pid < hide_pid_min)
49008 return true;
49009 if (in_group_p(pid->pid_gid))
49010 return true;
49011+
49012 return ptrace_may_access(task, PTRACE_MODE_READ);
49013 }
49014
49015@@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49016 put_task_struct(task);
49017
49018 if (!has_perms) {
49019+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49020+ {
49021+#else
49022 if (pid->hide_pid == 2) {
49023+#endif
49024 /*
49025 * Let's make getdents(), stat(), and open()
49026 * consistent with each other. If a process
49027@@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49028 if (!task)
49029 return -ESRCH;
49030
49031+ if (gr_acl_handle_procpidmem(task)) {
49032+ put_task_struct(task);
49033+ return -EPERM;
49034+ }
49035+
49036 mm = mm_access(task, mode);
49037 put_task_struct(task);
49038
49039@@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49040
49041 file->private_data = mm;
49042
49043+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49044+ file->f_version = current->exec_id;
49045+#endif
49046+
49047 return 0;
49048 }
49049
49050@@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49051 ssize_t copied;
49052 char *page;
49053
49054+#ifdef CONFIG_GRKERNSEC
49055+ if (write)
49056+ return -EPERM;
49057+#endif
49058+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49059+ if (file->f_version != current->exec_id) {
49060+ gr_log_badprocpid("mem");
49061+ return 0;
49062+ }
49063+#endif
49064+
49065 if (!mm)
49066 return 0;
49067
49068@@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49069 if (!mm)
49070 return 0;
49071
49072+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49073+ if (file->f_version != current->exec_id) {
49074+ gr_log_badprocpid("environ");
49075+ return 0;
49076+ }
49077+#endif
49078+
49079 page = (char *)__get_free_page(GFP_TEMPORARY);
49080 if (!page)
49081 return -ENOMEM;
49082@@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49083 int error = -EACCES;
49084
49085 /* Are we allowed to snoop on the tasks file descriptors? */
49086- if (!proc_fd_access_allowed(inode))
49087+ if (!proc_fd_access_allowed(inode, 0))
49088 goto out;
49089
49090 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49091@@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49092 struct path path;
49093
49094 /* Are we allowed to snoop on the tasks file descriptors? */
49095- if (!proc_fd_access_allowed(inode))
49096- goto out;
49097+ /* logging this is needed for learning on chromium to work properly,
49098+ but we don't want to flood the logs from 'ps' which does a readlink
49099+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49100+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
49101+ */
49102+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49103+ if (!proc_fd_access_allowed(inode,0))
49104+ goto out;
49105+ } else {
49106+ if (!proc_fd_access_allowed(inode,1))
49107+ goto out;
49108+ }
49109
49110 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49111 if (error)
49112@@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49113 rcu_read_lock();
49114 cred = __task_cred(task);
49115 inode->i_uid = cred->euid;
49116+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49117+ inode->i_gid = grsec_proc_gid;
49118+#else
49119 inode->i_gid = cred->egid;
49120+#endif
49121 rcu_read_unlock();
49122 }
49123 security_task_to_inode(task, inode);
49124@@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49125 return -ENOENT;
49126 }
49127 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49128+#ifdef CONFIG_GRKERNSEC_PROC_USER
49129+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49130+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49131+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49132+#endif
49133 task_dumpable(task)) {
49134 cred = __task_cred(task);
49135 stat->uid = cred->euid;
49136+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49137+ stat->gid = grsec_proc_gid;
49138+#else
49139 stat->gid = cred->egid;
49140+#endif
49141 }
49142 }
49143 rcu_read_unlock();
49144@@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49145
49146 if (task) {
49147 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49148+#ifdef CONFIG_GRKERNSEC_PROC_USER
49149+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49150+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49151+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49152+#endif
49153 task_dumpable(task)) {
49154 rcu_read_lock();
49155 cred = __task_cred(task);
49156 inode->i_uid = cred->euid;
49157+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49158+ inode->i_gid = grsec_proc_gid;
49159+#else
49160 inode->i_gid = cred->egid;
49161+#endif
49162 rcu_read_unlock();
49163 } else {
49164 inode->i_uid = GLOBAL_ROOT_UID;
49165@@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49166 int fd = proc_fd(inode);
49167
49168 if (task) {
49169- files = get_files_struct(task);
49170+ if (!gr_acl_handle_procpidmem(task))
49171+ files = get_files_struct(task);
49172 put_task_struct(task);
49173 }
49174 if (files) {
49175@@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49176 */
49177 static int proc_fd_permission(struct inode *inode, int mask)
49178 {
49179+ struct task_struct *task;
49180 int rv = generic_permission(inode, mask);
49181- if (rv == 0)
49182- return 0;
49183+
49184 if (task_pid(current) == proc_pid(inode))
49185 rv = 0;
49186+
49187+ task = get_proc_task(inode);
49188+ if (task == NULL)
49189+ return rv;
49190+
49191+ if (gr_acl_handle_procpidmem(task))
49192+ rv = -EACCES;
49193+
49194+ put_task_struct(task);
49195+
49196 return rv;
49197 }
49198
49199@@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49200 if (!task)
49201 goto out_no_task;
49202
49203+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49204+ goto out;
49205+
49206 /*
49207 * Yes, it does not scale. And it should not. Don't add
49208 * new entries into /proc/<tgid>/ without very good reasons.
49209@@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49210 if (!task)
49211 goto out_no_task;
49212
49213+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49214+ goto out;
49215+
49216 ret = 0;
49217 i = filp->f_pos;
49218 switch (i) {
49219@@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49220 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49221 void *cookie)
49222 {
49223- char *s = nd_get_link(nd);
49224+ const char *s = nd_get_link(nd);
49225 if (!IS_ERR(s))
49226 __putname(s);
49227 }
49228@@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49229 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49230 #endif
49231 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49232-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49233+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49234 INF("syscall", S_IRUGO, proc_pid_syscall),
49235 #endif
49236 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49237@@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49238 #ifdef CONFIG_SECURITY
49239 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49240 #endif
49241-#ifdef CONFIG_KALLSYMS
49242+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49243 INF("wchan", S_IRUGO, proc_pid_wchan),
49244 #endif
49245-#ifdef CONFIG_STACKTRACE
49246+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49247 ONE("stack", S_IRUGO, proc_pid_stack),
49248 #endif
49249 #ifdef CONFIG_SCHEDSTATS
49250@@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49251 #ifdef CONFIG_HARDWALL
49252 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49253 #endif
49254+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49255+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49256+#endif
49257 #ifdef CONFIG_USER_NS
49258 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49259 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49260@@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49261 if (!inode)
49262 goto out;
49263
49264+#ifdef CONFIG_GRKERNSEC_PROC_USER
49265+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49266+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49267+ inode->i_gid = grsec_proc_gid;
49268+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49269+#else
49270 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49271+#endif
49272 inode->i_op = &proc_tgid_base_inode_operations;
49273 inode->i_fop = &proc_tgid_base_operations;
49274 inode->i_flags|=S_IMMUTABLE;
49275@@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49276 if (!task)
49277 goto out;
49278
49279+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49280+ goto out_put_task;
49281+
49282 result = proc_pid_instantiate(dir, dentry, task, NULL);
49283+out_put_task:
49284 put_task_struct(task);
49285 out:
49286 return result;
49287@@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49288 static int fake_filldir(void *buf, const char *name, int namelen,
49289 loff_t offset, u64 ino, unsigned d_type)
49290 {
49291+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
49292+ __buf->error = -EINVAL;
49293 return 0;
49294 }
49295
49296@@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49297 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49298 #endif
49299 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49300-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49301+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49302 INF("syscall", S_IRUGO, proc_pid_syscall),
49303 #endif
49304 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49305@@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49306 #ifdef CONFIG_SECURITY
49307 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49308 #endif
49309-#ifdef CONFIG_KALLSYMS
49310+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49311 INF("wchan", S_IRUGO, proc_pid_wchan),
49312 #endif
49313-#ifdef CONFIG_STACKTRACE
49314+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49315 ONE("stack", S_IRUGO, proc_pid_stack),
49316 #endif
49317 #ifdef CONFIG_SCHEDSTATS
49318diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49319index 82676e3..5f8518a 100644
49320--- a/fs/proc/cmdline.c
49321+++ b/fs/proc/cmdline.c
49322@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49323
49324 static int __init proc_cmdline_init(void)
49325 {
49326+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49327+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49328+#else
49329 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49330+#endif
49331 return 0;
49332 }
49333 module_init(proc_cmdline_init);
49334diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49335index b143471..bb105e5 100644
49336--- a/fs/proc/devices.c
49337+++ b/fs/proc/devices.c
49338@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49339
49340 static int __init proc_devices_init(void)
49341 {
49342+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49343+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49344+#else
49345 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49346+#endif
49347 return 0;
49348 }
49349 module_init(proc_devices_init);
49350diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49351index 7ac817b..c5c9eb0 100644
49352--- a/fs/proc/inode.c
49353+++ b/fs/proc/inode.c
49354@@ -21,11 +21,17 @@
49355 #include <linux/seq_file.h>
49356 #include <linux/slab.h>
49357 #include <linux/mount.h>
49358+#include <linux/grsecurity.h>
49359
49360 #include <asm/uaccess.h>
49361
49362 #include "internal.h"
49363
49364+#ifdef CONFIG_PROC_SYSCTL
49365+extern const struct inode_operations proc_sys_inode_operations;
49366+extern const struct inode_operations proc_sys_dir_operations;
49367+#endif
49368+
49369 static void proc_evict_inode(struct inode *inode)
49370 {
49371 struct proc_dir_entry *de;
49372@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49373 ns_ops = PROC_I(inode)->ns_ops;
49374 if (ns_ops && ns_ops->put)
49375 ns_ops->put(PROC_I(inode)->ns);
49376+
49377+#ifdef CONFIG_PROC_SYSCTL
49378+ if (inode->i_op == &proc_sys_inode_operations ||
49379+ inode->i_op == &proc_sys_dir_operations)
49380+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49381+#endif
49382+
49383 }
49384
49385 static struct kmem_cache * proc_inode_cachep;
49386@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49387 if (de->mode) {
49388 inode->i_mode = de->mode;
49389 inode->i_uid = de->uid;
49390+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49391+ inode->i_gid = grsec_proc_gid;
49392+#else
49393 inode->i_gid = de->gid;
49394+#endif
49395 }
49396 if (de->size)
49397 inode->i_size = de->size;
49398diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49399index e1167a1..bd24f20 100644
49400--- a/fs/proc/internal.h
49401+++ b/fs/proc/internal.h
49402@@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49403 struct pid *pid, struct task_struct *task);
49404 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49405 struct pid *pid, struct task_struct *task);
49406+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49407+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49408+#endif
49409 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49410
49411 extern const struct file_operations proc_tid_children_operations;
49412diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49413index 86c67ee..cdca321 100644
49414--- a/fs/proc/kcore.c
49415+++ b/fs/proc/kcore.c
49416@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49417 * the addresses in the elf_phdr on our list.
49418 */
49419 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49420- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49421+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49422+ if (tsz > buflen)
49423 tsz = buflen;
49424-
49425+
49426 while (buflen) {
49427 struct kcore_list *m;
49428
49429@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49430 kfree(elf_buf);
49431 } else {
49432 if (kern_addr_valid(start)) {
49433- unsigned long n;
49434+ char *elf_buf;
49435+ mm_segment_t oldfs;
49436
49437- n = copy_to_user(buffer, (char *)start, tsz);
49438- /*
49439- * We cannot distinguish between fault on source
49440- * and fault on destination. When this happens
49441- * we clear too and hope it will trigger the
49442- * EFAULT again.
49443- */
49444- if (n) {
49445- if (clear_user(buffer + tsz - n,
49446- n))
49447+ elf_buf = kmalloc(tsz, GFP_KERNEL);
49448+ if (!elf_buf)
49449+ return -ENOMEM;
49450+ oldfs = get_fs();
49451+ set_fs(KERNEL_DS);
49452+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49453+ set_fs(oldfs);
49454+ if (copy_to_user(buffer, elf_buf, tsz)) {
49455+ kfree(elf_buf);
49456 return -EFAULT;
49457+ }
49458 }
49459+ set_fs(oldfs);
49460+ kfree(elf_buf);
49461 } else {
49462 if (clear_user(buffer, tsz))
49463 return -EFAULT;
49464@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49465
49466 static int open_kcore(struct inode *inode, struct file *filp)
49467 {
49468+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49469+ return -EPERM;
49470+#endif
49471 if (!capable(CAP_SYS_RAWIO))
49472 return -EPERM;
49473 if (kcore_need_update)
49474diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49475index 80e4645..53e5fcf 100644
49476--- a/fs/proc/meminfo.c
49477+++ b/fs/proc/meminfo.c
49478@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49479 vmi.used >> 10,
49480 vmi.largest_chunk >> 10
49481 #ifdef CONFIG_MEMORY_FAILURE
49482- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49483+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49484 #endif
49485 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49486 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49487diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49488index b1822dd..df622cb 100644
49489--- a/fs/proc/nommu.c
49490+++ b/fs/proc/nommu.c
49491@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49492 if (len < 1)
49493 len = 1;
49494 seq_printf(m, "%*c", len, ' ');
49495- seq_path(m, &file->f_path, "");
49496+ seq_path(m, &file->f_path, "\n\\");
49497 }
49498
49499 seq_putc(m, '\n');
49500diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49501index fe72cd0..cb9b67d 100644
49502--- a/fs/proc/proc_net.c
49503+++ b/fs/proc/proc_net.c
49504@@ -23,6 +23,7 @@
49505 #include <linux/nsproxy.h>
49506 #include <net/net_namespace.h>
49507 #include <linux/seq_file.h>
49508+#include <linux/grsecurity.h>
49509
49510 #include "internal.h"
49511
49512@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49513 struct task_struct *task;
49514 struct nsproxy *ns;
49515 struct net *net = NULL;
49516+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49517+ const struct cred *cred = current_cred();
49518+#endif
49519+
49520+#ifdef CONFIG_GRKERNSEC_PROC_USER
49521+ if (cred->fsuid)
49522+ return net;
49523+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49524+ if (cred->fsuid && !in_group_p(grsec_proc_gid))
49525+ return net;
49526+#endif
49527
49528 rcu_read_lock();
49529 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49530diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49531index eb7cc91..7327a46 100644
49532--- a/fs/proc/proc_sysctl.c
49533+++ b/fs/proc/proc_sysctl.c
49534@@ -12,11 +12,15 @@
49535 #include <linux/module.h>
49536 #include "internal.h"
49537
49538+extern int gr_handle_chroot_sysctl(const int op);
49539+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49540+ const int op);
49541+
49542 static const struct dentry_operations proc_sys_dentry_operations;
49543 static const struct file_operations proc_sys_file_operations;
49544-static const struct inode_operations proc_sys_inode_operations;
49545+const struct inode_operations proc_sys_inode_operations;
49546 static const struct file_operations proc_sys_dir_file_operations;
49547-static const struct inode_operations proc_sys_dir_operations;
49548+const struct inode_operations proc_sys_dir_operations;
49549
49550 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49551 {
49552@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49553
49554 err = NULL;
49555 d_set_d_op(dentry, &proc_sys_dentry_operations);
49556+
49557+ gr_handle_proc_create(dentry, inode);
49558+
49559 d_add(dentry, inode);
49560
49561 out:
49562@@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49563 struct inode *inode = filp->f_path.dentry->d_inode;
49564 struct ctl_table_header *head = grab_header(inode);
49565 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49566+ int op = write ? MAY_WRITE : MAY_READ;
49567 ssize_t error;
49568 size_t res;
49569
49570 if (IS_ERR(head))
49571 return PTR_ERR(head);
49572
49573+
49574 /*
49575 * At this point we know that the sysctl was not unregistered
49576 * and won't be until we finish.
49577 */
49578 error = -EPERM;
49579- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49580+ if (sysctl_perm(head->root, table, op))
49581 goto out;
49582
49583 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49584@@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49585 if (!table->proc_handler)
49586 goto out;
49587
49588+#ifdef CONFIG_GRKERNSEC
49589+ error = -EPERM;
49590+ if (gr_handle_chroot_sysctl(op))
49591+ goto out;
49592+ dget(filp->f_path.dentry);
49593+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49594+ dput(filp->f_path.dentry);
49595+ goto out;
49596+ }
49597+ dput(filp->f_path.dentry);
49598+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49599+ goto out;
49600+ if (write && !capable(CAP_SYS_ADMIN))
49601+ goto out;
49602+#endif
49603+
49604 /* careful: calling conventions are nasty here */
49605 res = count;
49606 error = table->proc_handler(table, write, buf, &res, ppos);
49607@@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49608 return -ENOMEM;
49609 } else {
49610 d_set_d_op(child, &proc_sys_dentry_operations);
49611+
49612+ gr_handle_proc_create(child, inode);
49613+
49614 d_add(child, inode);
49615 }
49616 } else {
49617@@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49618 if ((*pos)++ < file->f_pos)
49619 return 0;
49620
49621+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49622+ return 0;
49623+
49624 if (unlikely(S_ISLNK(table->mode)))
49625 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49626 else
49627@@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49628 if (IS_ERR(head))
49629 return PTR_ERR(head);
49630
49631+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49632+ return -ENOENT;
49633+
49634 generic_fillattr(inode, stat);
49635 if (table)
49636 stat->mode = (stat->mode & S_IFMT) | table->mode;
49637@@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49638 .llseek = generic_file_llseek,
49639 };
49640
49641-static const struct inode_operations proc_sys_inode_operations = {
49642+const struct inode_operations proc_sys_inode_operations = {
49643 .permission = proc_sys_permission,
49644 .setattr = proc_sys_setattr,
49645 .getattr = proc_sys_getattr,
49646 };
49647
49648-static const struct inode_operations proc_sys_dir_operations = {
49649+const struct inode_operations proc_sys_dir_operations = {
49650 .lookup = proc_sys_lookup,
49651 .permission = proc_sys_permission,
49652 .setattr = proc_sys_setattr,
49653diff --git a/fs/proc/root.c b/fs/proc/root.c
49654index 9a2d9fd..ddfc92a 100644
49655--- a/fs/proc/root.c
49656+++ b/fs/proc/root.c
49657@@ -187,7 +187,15 @@ void __init proc_root_init(void)
49658 #ifdef CONFIG_PROC_DEVICETREE
49659 proc_device_tree_init();
49660 #endif
49661+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49662+#ifdef CONFIG_GRKERNSEC_PROC_USER
49663+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49664+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49665+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49666+#endif
49667+#else
49668 proc_mkdir("bus", NULL);
49669+#endif
49670 proc_sys_init();
49671 }
49672
49673diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49674index 4540b8f..1b9772f 100644
49675--- a/fs/proc/task_mmu.c
49676+++ b/fs/proc/task_mmu.c
49677@@ -11,12 +11,19 @@
49678 #include <linux/rmap.h>
49679 #include <linux/swap.h>
49680 #include <linux/swapops.h>
49681+#include <linux/grsecurity.h>
49682
49683 #include <asm/elf.h>
49684 #include <asm/uaccess.h>
49685 #include <asm/tlbflush.h>
49686 #include "internal.h"
49687
49688+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49689+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49690+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49691+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49692+#endif
49693+
49694 void task_mem(struct seq_file *m, struct mm_struct *mm)
49695 {
49696 unsigned long data, text, lib, swap;
49697@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49698 "VmExe:\t%8lu kB\n"
49699 "VmLib:\t%8lu kB\n"
49700 "VmPTE:\t%8lu kB\n"
49701- "VmSwap:\t%8lu kB\n",
49702- hiwater_vm << (PAGE_SHIFT-10),
49703+ "VmSwap:\t%8lu kB\n"
49704+
49705+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49706+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49707+#endif
49708+
49709+ ,hiwater_vm << (PAGE_SHIFT-10),
49710 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49711 mm->locked_vm << (PAGE_SHIFT-10),
49712 mm->pinned_vm << (PAGE_SHIFT-10),
49713@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49714 data << (PAGE_SHIFT-10),
49715 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49716 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49717- swap << (PAGE_SHIFT-10));
49718+ swap << (PAGE_SHIFT-10)
49719+
49720+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49721+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49722+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49723+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49724+#else
49725+ , mm->context.user_cs_base
49726+ , mm->context.user_cs_limit
49727+#endif
49728+#endif
49729+
49730+ );
49731 }
49732
49733 unsigned long task_vsize(struct mm_struct *mm)
49734@@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49735 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49736 }
49737
49738- /* We don't show the stack guard page in /proc/maps */
49739+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49740+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49741+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49742+#else
49743 start = vma->vm_start;
49744- if (stack_guard_page_start(vma, start))
49745- start += PAGE_SIZE;
49746 end = vma->vm_end;
49747- if (stack_guard_page_end(vma, end))
49748- end -= PAGE_SIZE;
49749+#endif
49750
49751 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49752 start,
49753@@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49754 flags & VM_WRITE ? 'w' : '-',
49755 flags & VM_EXEC ? 'x' : '-',
49756 flags & VM_MAYSHARE ? 's' : 'p',
49757+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49758+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49759+#else
49760 pgoff,
49761+#endif
49762 MAJOR(dev), MINOR(dev), ino, &len);
49763
49764 /*
49765@@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49766 */
49767 if (file) {
49768 pad_len_spaces(m, len);
49769- seq_path(m, &file->f_path, "\n");
49770+ seq_path(m, &file->f_path, "\n\\");
49771 goto done;
49772 }
49773
49774@@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49775 * Thread stack in /proc/PID/task/TID/maps or
49776 * the main process stack.
49777 */
49778- if (!is_pid || (vma->vm_start <= mm->start_stack &&
49779- vma->vm_end >= mm->start_stack)) {
49780+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49781+ (vma->vm_start <= mm->start_stack &&
49782+ vma->vm_end >= mm->start_stack)) {
49783 name = "[stack]";
49784 } else {
49785 /* Thread stack in /proc/PID/maps */
49786@@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49787 struct proc_maps_private *priv = m->private;
49788 struct task_struct *task = priv->task;
49789
49790+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49791+ if (current->exec_id != m->exec_id) {
49792+ gr_log_badprocpid("maps");
49793+ return 0;
49794+ }
49795+#endif
49796+
49797 show_map_vma(m, vma, is_pid);
49798
49799 if (m->count < m->size) /* vma is copied successfully */
49800@@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49801 .private = &mss,
49802 };
49803
49804+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49805+ if (current->exec_id != m->exec_id) {
49806+ gr_log_badprocpid("smaps");
49807+ return 0;
49808+ }
49809+#endif
49810 memset(&mss, 0, sizeof mss);
49811- mss.vma = vma;
49812- /* mmap_sem is held in m_start */
49813- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49814- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49815-
49816+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49817+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49818+#endif
49819+ mss.vma = vma;
49820+ /* mmap_sem is held in m_start */
49821+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49822+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49823+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49824+ }
49825+#endif
49826 show_map_vma(m, vma, is_pid);
49827
49828 seq_printf(m,
49829@@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49830 "KernelPageSize: %8lu kB\n"
49831 "MMUPageSize: %8lu kB\n"
49832 "Locked: %8lu kB\n",
49833+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49834+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49835+#else
49836 (vma->vm_end - vma->vm_start) >> 10,
49837+#endif
49838 mss.resident >> 10,
49839 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49840 mss.shared_clean >> 10,
49841@@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49842 int n;
49843 char buffer[50];
49844
49845+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49846+ if (current->exec_id != m->exec_id) {
49847+ gr_log_badprocpid("numa_maps");
49848+ return 0;
49849+ }
49850+#endif
49851+
49852 if (!mm)
49853 return 0;
49854
49855@@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49856 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49857 mpol_cond_put(pol);
49858
49859+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49860+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49861+#else
49862 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49863+#endif
49864
49865 if (file) {
49866 seq_printf(m, " file=");
49867- seq_path(m, &file->f_path, "\n\t= ");
49868+ seq_path(m, &file->f_path, "\n\t\\= ");
49869 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49870 seq_printf(m, " heap");
49871 } else {
49872diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49873index 1ccfa53..0848f95 100644
49874--- a/fs/proc/task_nommu.c
49875+++ b/fs/proc/task_nommu.c
49876@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49877 else
49878 bytes += kobjsize(mm);
49879
49880- if (current->fs && current->fs->users > 1)
49881+ if (current->fs && atomic_read(&current->fs->users) > 1)
49882 sbytes += kobjsize(current->fs);
49883 else
49884 bytes += kobjsize(current->fs);
49885@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49886
49887 if (file) {
49888 pad_len_spaces(m, len);
49889- seq_path(m, &file->f_path, "");
49890+ seq_path(m, &file->f_path, "\n\\");
49891 } else if (mm) {
49892 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49893
49894diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49895index d67908b..d13f6a6 100644
49896--- a/fs/quota/netlink.c
49897+++ b/fs/quota/netlink.c
49898@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49899 void quota_send_warning(short type, unsigned int id, dev_t dev,
49900 const char warntype)
49901 {
49902- static atomic_t seq;
49903+ static atomic_unchecked_t seq;
49904 struct sk_buff *skb;
49905 void *msg_head;
49906 int ret;
49907@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49908 "VFS: Not enough memory to send quota warning.\n");
49909 return;
49910 }
49911- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49912+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49913 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49914 if (!msg_head) {
49915 printk(KERN_ERR
49916diff --git a/fs/readdir.c b/fs/readdir.c
49917index 39e3370..20d446d 100644
49918--- a/fs/readdir.c
49919+++ b/fs/readdir.c
49920@@ -17,6 +17,7 @@
49921 #include <linux/security.h>
49922 #include <linux/syscalls.h>
49923 #include <linux/unistd.h>
49924+#include <linux/namei.h>
49925
49926 #include <asm/uaccess.h>
49927
49928@@ -67,6 +68,7 @@ struct old_linux_dirent {
49929
49930 struct readdir_callback {
49931 struct old_linux_dirent __user * dirent;
49932+ struct file * file;
49933 int result;
49934 };
49935
49936@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49937 buf->result = -EOVERFLOW;
49938 return -EOVERFLOW;
49939 }
49940+
49941+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49942+ return 0;
49943+
49944 buf->result++;
49945 dirent = buf->dirent;
49946 if (!access_ok(VERIFY_WRITE, dirent,
49947@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49948
49949 buf.result = 0;
49950 buf.dirent = dirent;
49951+ buf.file = file;
49952
49953 error = vfs_readdir(file, fillonedir, &buf);
49954 if (buf.result)
49955@@ -141,6 +148,7 @@ struct linux_dirent {
49956 struct getdents_callback {
49957 struct linux_dirent __user * current_dir;
49958 struct linux_dirent __user * previous;
49959+ struct file * file;
49960 int count;
49961 int error;
49962 };
49963@@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49964 buf->error = -EOVERFLOW;
49965 return -EOVERFLOW;
49966 }
49967+
49968+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49969+ return 0;
49970+
49971 dirent = buf->previous;
49972 if (dirent) {
49973 if (__put_user(offset, &dirent->d_off))
49974@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49975 buf.previous = NULL;
49976 buf.count = count;
49977 buf.error = 0;
49978+ buf.file = file;
49979
49980 error = vfs_readdir(file, filldir, &buf);
49981 if (error >= 0)
49982@@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49983 struct getdents_callback64 {
49984 struct linux_dirent64 __user * current_dir;
49985 struct linux_dirent64 __user * previous;
49986+ struct file *file;
49987 int count;
49988 int error;
49989 };
49990@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49991 buf->error = -EINVAL; /* only used if we fail.. */
49992 if (reclen > buf->count)
49993 return -EINVAL;
49994+
49995+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49996+ return 0;
49997+
49998 dirent = buf->previous;
49999 if (dirent) {
50000 if (__put_user(offset, &dirent->d_off))
50001@@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50002
50003 buf.current_dir = dirent;
50004 buf.previous = NULL;
50005+ buf.file = file;
50006 buf.count = count;
50007 buf.error = 0;
50008
50009@@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50010 error = buf.error;
50011 lastdirent = buf.previous;
50012 if (lastdirent) {
50013- typeof(lastdirent->d_off) d_off = file->f_pos;
50014+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50015 if (__put_user(d_off, &lastdirent->d_off))
50016 error = -EFAULT;
50017 else
50018diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50019index 2b7882b..1c5ef48 100644
50020--- a/fs/reiserfs/do_balan.c
50021+++ b/fs/reiserfs/do_balan.c
50022@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50023 return;
50024 }
50025
50026- atomic_inc(&(fs_generation(tb->tb_sb)));
50027+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50028 do_balance_starts(tb);
50029
50030 /* balance leaf returns 0 except if combining L R and S into
50031diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50032index e60e870..f40ac16 100644
50033--- a/fs/reiserfs/procfs.c
50034+++ b/fs/reiserfs/procfs.c
50035@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50036 "SMALL_TAILS " : "NO_TAILS ",
50037 replay_only(sb) ? "REPLAY_ONLY " : "",
50038 convert_reiserfs(sb) ? "CONV " : "",
50039- atomic_read(&r->s_generation_counter),
50040+ atomic_read_unchecked(&r->s_generation_counter),
50041 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50042 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50043 SF(s_good_search_by_key_reada), SF(s_bmaps),
50044diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50045index 33215f5..c5d427a 100644
50046--- a/fs/reiserfs/reiserfs.h
50047+++ b/fs/reiserfs/reiserfs.h
50048@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50049 /* Comment? -Hans */
50050 wait_queue_head_t s_wait;
50051 /* To be obsoleted soon by per buffer seals.. -Hans */
50052- atomic_t s_generation_counter; // increased by one every time the
50053+ atomic_unchecked_t s_generation_counter; // increased by one every time the
50054 // tree gets re-balanced
50055 unsigned long s_properties; /* File system properties. Currently holds
50056 on-disk FS format */
50057@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50058 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50059
50060 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50061-#define get_generation(s) atomic_read (&fs_generation(s))
50062+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50063 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50064 #define __fs_changed(gen,s) (gen != get_generation (s))
50065 #define fs_changed(gen,s) \
50066diff --git a/fs/select.c b/fs/select.c
50067index db14c78..3aae1bd 100644
50068--- a/fs/select.c
50069+++ b/fs/select.c
50070@@ -20,6 +20,7 @@
50071 #include <linux/export.h>
50072 #include <linux/slab.h>
50073 #include <linux/poll.h>
50074+#include <linux/security.h>
50075 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50076 #include <linux/file.h>
50077 #include <linux/fdtable.h>
50078@@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50079 struct poll_list *walk = head;
50080 unsigned long todo = nfds;
50081
50082+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50083 if (nfds > rlimit(RLIMIT_NOFILE))
50084 return -EINVAL;
50085
50086diff --git a/fs/seq_file.c b/fs/seq_file.c
50087index 14cf9de..adc4d5b 100644
50088--- a/fs/seq_file.c
50089+++ b/fs/seq_file.c
50090@@ -9,6 +9,7 @@
50091 #include <linux/export.h>
50092 #include <linux/seq_file.h>
50093 #include <linux/slab.h>
50094+#include <linux/sched.h>
50095
50096 #include <asm/uaccess.h>
50097 #include <asm/page.h>
50098@@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50099 memset(p, 0, sizeof(*p));
50100 mutex_init(&p->lock);
50101 p->op = op;
50102+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50103+ p->exec_id = current->exec_id;
50104+#endif
50105
50106 /*
50107 * Wrappers around seq_open(e.g. swaps_open) need to be
50108@@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50109 return 0;
50110 }
50111 if (!m->buf) {
50112- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50113+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50114 if (!m->buf)
50115 return -ENOMEM;
50116 }
50117@@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50118 Eoverflow:
50119 m->op->stop(m, p);
50120 kfree(m->buf);
50121- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50122+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50123 return !m->buf ? -ENOMEM : -EAGAIN;
50124 }
50125
50126@@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50127
50128 /* grab buffer if we didn't have one */
50129 if (!m->buf) {
50130- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50131+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50132 if (!m->buf)
50133 goto Enomem;
50134 }
50135@@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50136 goto Fill;
50137 m->op->stop(m, p);
50138 kfree(m->buf);
50139- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50140+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50141 if (!m->buf)
50142 goto Enomem;
50143 m->count = 0;
50144@@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50145 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50146 void *data)
50147 {
50148- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50149+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50150 int res = -ENOMEM;
50151
50152 if (op) {
50153diff --git a/fs/splice.c b/fs/splice.c
50154index 41514dd..6564a93 100644
50155--- a/fs/splice.c
50156+++ b/fs/splice.c
50157@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50158 pipe_lock(pipe);
50159
50160 for (;;) {
50161- if (!pipe->readers) {
50162+ if (!atomic_read(&pipe->readers)) {
50163 send_sig(SIGPIPE, current, 0);
50164 if (!ret)
50165 ret = -EPIPE;
50166@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50167 do_wakeup = 0;
50168 }
50169
50170- pipe->waiting_writers++;
50171+ atomic_inc(&pipe->waiting_writers);
50172 pipe_wait(pipe);
50173- pipe->waiting_writers--;
50174+ atomic_dec(&pipe->waiting_writers);
50175 }
50176
50177 pipe_unlock(pipe);
50178@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50179 old_fs = get_fs();
50180 set_fs(get_ds());
50181 /* The cast to a user pointer is valid due to the set_fs() */
50182- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50183+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50184 set_fs(old_fs);
50185
50186 return res;
50187@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50188 old_fs = get_fs();
50189 set_fs(get_ds());
50190 /* The cast to a user pointer is valid due to the set_fs() */
50191- res = vfs_write(file, (const char __user *)buf, count, &pos);
50192+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50193 set_fs(old_fs);
50194
50195 return res;
50196@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50197 goto err;
50198
50199 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50200- vec[i].iov_base = (void __user *) page_address(page);
50201+ vec[i].iov_base = (void __force_user *) page_address(page);
50202 vec[i].iov_len = this_len;
50203 spd.pages[i] = page;
50204 spd.nr_pages++;
50205@@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50206 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50207 {
50208 while (!pipe->nrbufs) {
50209- if (!pipe->writers)
50210+ if (!atomic_read(&pipe->writers))
50211 return 0;
50212
50213- if (!pipe->waiting_writers && sd->num_spliced)
50214+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50215 return 0;
50216
50217 if (sd->flags & SPLICE_F_NONBLOCK)
50218@@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50219 * out of the pipe right after the splice_to_pipe(). So set
50220 * PIPE_READERS appropriately.
50221 */
50222- pipe->readers = 1;
50223+ atomic_set(&pipe->readers, 1);
50224
50225 current->splice_pipe = pipe;
50226 }
50227@@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50228 ret = -ERESTARTSYS;
50229 break;
50230 }
50231- if (!pipe->writers)
50232+ if (!atomic_read(&pipe->writers))
50233 break;
50234- if (!pipe->waiting_writers) {
50235+ if (!atomic_read(&pipe->waiting_writers)) {
50236 if (flags & SPLICE_F_NONBLOCK) {
50237 ret = -EAGAIN;
50238 break;
50239@@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50240 pipe_lock(pipe);
50241
50242 while (pipe->nrbufs >= pipe->buffers) {
50243- if (!pipe->readers) {
50244+ if (!atomic_read(&pipe->readers)) {
50245 send_sig(SIGPIPE, current, 0);
50246 ret = -EPIPE;
50247 break;
50248@@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50249 ret = -ERESTARTSYS;
50250 break;
50251 }
50252- pipe->waiting_writers++;
50253+ atomic_inc(&pipe->waiting_writers);
50254 pipe_wait(pipe);
50255- pipe->waiting_writers--;
50256+ atomic_dec(&pipe->waiting_writers);
50257 }
50258
50259 pipe_unlock(pipe);
50260@@ -1828,14 +1828,14 @@ retry:
50261 pipe_double_lock(ipipe, opipe);
50262
50263 do {
50264- if (!opipe->readers) {
50265+ if (!atomic_read(&opipe->readers)) {
50266 send_sig(SIGPIPE, current, 0);
50267 if (!ret)
50268 ret = -EPIPE;
50269 break;
50270 }
50271
50272- if (!ipipe->nrbufs && !ipipe->writers)
50273+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50274 break;
50275
50276 /*
50277@@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50278 pipe_double_lock(ipipe, opipe);
50279
50280 do {
50281- if (!opipe->readers) {
50282+ if (!atomic_read(&opipe->readers)) {
50283 send_sig(SIGPIPE, current, 0);
50284 if (!ret)
50285 ret = -EPIPE;
50286@@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50287 * return EAGAIN if we have the potential of some data in the
50288 * future, otherwise just return 0
50289 */
50290- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50291+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50292 ret = -EAGAIN;
50293
50294 pipe_unlock(ipipe);
50295diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50296index 6b0bb00..75db2fe 100644
50297--- a/fs/sysfs/dir.c
50298+++ b/fs/sysfs/dir.c
50299@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50300 struct sysfs_dirent *sd;
50301 int rc;
50302
50303+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50304+ const char *parent_name = parent_sd->s_name;
50305+
50306+ mode = S_IFDIR | S_IRWXU;
50307+
50308+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50309+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50310+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50311+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50312+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50313+#endif
50314+
50315 /* allocate */
50316 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50317 if (!sd)
50318diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50319index 00012e3..8392349 100644
50320--- a/fs/sysfs/file.c
50321+++ b/fs/sysfs/file.c
50322@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50323
50324 struct sysfs_open_dirent {
50325 atomic_t refcnt;
50326- atomic_t event;
50327+ atomic_unchecked_t event;
50328 wait_queue_head_t poll;
50329 struct list_head buffers; /* goes through sysfs_buffer.list */
50330 };
50331@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50332 if (!sysfs_get_active(attr_sd))
50333 return -ENODEV;
50334
50335- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50336+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50337 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50338
50339 sysfs_put_active(attr_sd);
50340@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50341 return -ENOMEM;
50342
50343 atomic_set(&new_od->refcnt, 0);
50344- atomic_set(&new_od->event, 1);
50345+ atomic_set_unchecked(&new_od->event, 1);
50346 init_waitqueue_head(&new_od->poll);
50347 INIT_LIST_HEAD(&new_od->buffers);
50348 goto retry;
50349@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50350
50351 sysfs_put_active(attr_sd);
50352
50353- if (buffer->event != atomic_read(&od->event))
50354+ if (buffer->event != atomic_read_unchecked(&od->event))
50355 goto trigger;
50356
50357 return DEFAULT_POLLMASK;
50358@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50359
50360 od = sd->s_attr.open;
50361 if (od) {
50362- atomic_inc(&od->event);
50363+ atomic_inc_unchecked(&od->event);
50364 wake_up_interruptible(&od->poll);
50365 }
50366
50367diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50368index a7ac78f..02158e1 100644
50369--- a/fs/sysfs/symlink.c
50370+++ b/fs/sysfs/symlink.c
50371@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50372
50373 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50374 {
50375- char *page = nd_get_link(nd);
50376+ const char *page = nd_get_link(nd);
50377 if (!IS_ERR(page))
50378 free_page((unsigned long)page);
50379 }
50380diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50381index c175b4d..8f36a16 100644
50382--- a/fs/udf/misc.c
50383+++ b/fs/udf/misc.c
50384@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50385
50386 u8 udf_tag_checksum(const struct tag *t)
50387 {
50388- u8 *data = (u8 *)t;
50389+ const u8 *data = (const u8 *)t;
50390 u8 checksum = 0;
50391 int i;
50392 for (i = 0; i < sizeof(struct tag); ++i)
50393diff --git a/fs/utimes.c b/fs/utimes.c
50394index fa4dbe4..e12d1b9 100644
50395--- a/fs/utimes.c
50396+++ b/fs/utimes.c
50397@@ -1,6 +1,7 @@
50398 #include <linux/compiler.h>
50399 #include <linux/file.h>
50400 #include <linux/fs.h>
50401+#include <linux/security.h>
50402 #include <linux/linkage.h>
50403 #include <linux/mount.h>
50404 #include <linux/namei.h>
50405@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50406 goto mnt_drop_write_and_out;
50407 }
50408 }
50409+
50410+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50411+ error = -EACCES;
50412+ goto mnt_drop_write_and_out;
50413+ }
50414+
50415 mutex_lock(&inode->i_mutex);
50416 error = notify_change(path->dentry, &newattrs);
50417 mutex_unlock(&inode->i_mutex);
50418diff --git a/fs/xattr.c b/fs/xattr.c
50419index 4d45b71..2ec08e10 100644
50420--- a/fs/xattr.c
50421+++ b/fs/xattr.c
50422@@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50423 * Extended attribute SET operations
50424 */
50425 static long
50426-setxattr(struct dentry *d, const char __user *name, const void __user *value,
50427+setxattr(struct path *path, const char __user *name, const void __user *value,
50428 size_t size, int flags)
50429 {
50430 int error;
50431@@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50432 }
50433 }
50434
50435- error = vfs_setxattr(d, kname, kvalue, size, flags);
50436+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50437+ error = -EACCES;
50438+ goto out;
50439+ }
50440+
50441+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50442 out:
50443 if (vvalue)
50444 vfree(vvalue);
50445@@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50446 return error;
50447 error = mnt_want_write(path.mnt);
50448 if (!error) {
50449- error = setxattr(path.dentry, name, value, size, flags);
50450+ error = setxattr(&path, name, value, size, flags);
50451 mnt_drop_write(path.mnt);
50452 }
50453 path_put(&path);
50454@@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50455 return error;
50456 error = mnt_want_write(path.mnt);
50457 if (!error) {
50458- error = setxattr(path.dentry, name, value, size, flags);
50459+ error = setxattr(&path, name, value, size, flags);
50460 mnt_drop_write(path.mnt);
50461 }
50462 path_put(&path);
50463@@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50464 {
50465 int fput_needed;
50466 struct file *f;
50467- struct dentry *dentry;
50468 int error = -EBADF;
50469
50470 f = fget_light(fd, &fput_needed);
50471 if (!f)
50472 return error;
50473- dentry = f->f_path.dentry;
50474- audit_inode(NULL, dentry);
50475+ audit_inode(NULL, f->f_path.dentry);
50476 error = mnt_want_write_file(f);
50477 if (!error) {
50478- error = setxattr(dentry, name, value, size, flags);
50479+ error = setxattr(&f->f_path, name, value, size, flags);
50480 mnt_drop_write_file(f);
50481 }
50482 fput_light(f, fput_needed);
50483diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50484index 69d06b0..c0996e5 100644
50485--- a/fs/xattr_acl.c
50486+++ b/fs/xattr_acl.c
50487@@ -17,8 +17,8 @@
50488 struct posix_acl *
50489 posix_acl_from_xattr(const void *value, size_t size)
50490 {
50491- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50492- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50493+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50494+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50495 int count;
50496 struct posix_acl *acl;
50497 struct posix_acl_entry *acl_e;
50498diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50499index 848ffa7..1f249bf 100644
50500--- a/fs/xfs/xfs_bmap.c
50501+++ b/fs/xfs/xfs_bmap.c
50502@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50503 int nmap,
50504 int ret_nmap);
50505 #else
50506-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50507+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50508 #endif /* DEBUG */
50509
50510 STATIC int
50511diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50512index 1b9fc3e..e1bdde0 100644
50513--- a/fs/xfs/xfs_dir2_sf.c
50514+++ b/fs/xfs/xfs_dir2_sf.c
50515@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50516 }
50517
50518 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50519- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50520+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50521+ char name[sfep->namelen];
50522+ memcpy(name, sfep->name, sfep->namelen);
50523+ if (filldir(dirent, name, sfep->namelen,
50524+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
50525+ *offset = off & 0x7fffffff;
50526+ return 0;
50527+ }
50528+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50529 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50530 *offset = off & 0x7fffffff;
50531 return 0;
50532diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50533index 0e0232c..fa5c3fe 100644
50534--- a/fs/xfs/xfs_ioctl.c
50535+++ b/fs/xfs/xfs_ioctl.c
50536@@ -126,7 +126,7 @@ xfs_find_handle(
50537 }
50538
50539 error = -EFAULT;
50540- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50541+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50542 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50543 goto out_put;
50544
50545diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50546index 4e00cf0..3374374 100644
50547--- a/fs/xfs/xfs_iops.c
50548+++ b/fs/xfs/xfs_iops.c
50549@@ -394,7 +394,7 @@ xfs_vn_put_link(
50550 struct nameidata *nd,
50551 void *p)
50552 {
50553- char *s = nd_get_link(nd);
50554+ const char *s = nd_get_link(nd);
50555
50556 if (!IS_ERR(s))
50557 kfree(s);
50558diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50559new file mode 100644
50560index 0000000..d38b430
50561--- /dev/null
50562+++ b/grsecurity/Kconfig
50563@@ -0,0 +1,947 @@
50564+#
50565+# grecurity configuration
50566+#
50567+menu "Memory Protections"
50568+depends on GRKERNSEC
50569+
50570+config GRKERNSEC_KMEM
50571+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50572+ default y if GRKERNSEC_CONFIG_AUTO
50573+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50574+ help
50575+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50576+ be written to or read from to modify or leak the contents of the running
50577+ kernel. /dev/port will also not be allowed to be opened. If you have module
50578+ support disabled, enabling this will close up four ways that are
50579+ currently used to insert malicious code into the running kernel.
50580+ Even with all these features enabled, we still highly recommend that
50581+ you use the RBAC system, as it is still possible for an attacker to
50582+ modify the running kernel through privileged I/O granted by ioperm/iopl.
50583+ If you are not using XFree86, you may be able to stop this additional
50584+ case by enabling the 'Disable privileged I/O' option. Though nothing
50585+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50586+ but only to video memory, which is the only writing we allow in this
50587+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50588+ not be allowed to mprotect it with PROT_WRITE later.
50589+ It is highly recommended that you say Y here if you meet all the
50590+ conditions above.
50591+
50592+config GRKERNSEC_VM86
50593+ bool "Restrict VM86 mode"
50594+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50595+ depends on X86_32
50596+
50597+ help
50598+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50599+ make use of a special execution mode on 32bit x86 processors called
50600+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50601+ video cards and will still work with this option enabled. The purpose
50602+ of the option is to prevent exploitation of emulation errors in
50603+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
50604+ Nearly all users should be able to enable this option.
50605+
50606+config GRKERNSEC_IO
50607+ bool "Disable privileged I/O"
50608+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50609+ depends on X86
50610+ select RTC_CLASS
50611+ select RTC_INTF_DEV
50612+ select RTC_DRV_CMOS
50613+
50614+ help
50615+ If you say Y here, all ioperm and iopl calls will return an error.
50616+ Ioperm and iopl can be used to modify the running kernel.
50617+ Unfortunately, some programs need this access to operate properly,
50618+ the most notable of which are XFree86 and hwclock. hwclock can be
50619+ remedied by having RTC support in the kernel, so real-time
50620+ clock support is enabled if this option is enabled, to ensure
50621+ that hwclock operates correctly. XFree86 still will not
50622+ operate correctly with this option enabled, so DO NOT CHOOSE Y
50623+ IF YOU USE XFree86. If you use XFree86 and you still want to
50624+ protect your kernel against modification, use the RBAC system.
50625+
50626+config GRKERNSEC_PROC_MEMMAP
50627+ bool "Harden ASLR against information leaks and entropy reduction"
50628+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50629+ depends on PAX_NOEXEC || PAX_ASLR
50630+ help
50631+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50632+ give no information about the addresses of its mappings if
50633+ PaX features that rely on random addresses are enabled on the task.
50634+ In addition to sanitizing this information and disabling other
50635+ dangerous sources of information, this option causes reads of sensitive
50636+ /proc/<pid> entries where the file descriptor was opened in a different
50637+ task than the one performing the read. Such attempts are logged.
50638+ This option also limits argv/env strings for suid/sgid binaries
50639+ to 512KB to prevent a complete exhaustion of the stack entropy provided
50640+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50641+ binaries to prevent alternative mmap layouts from being abused.
50642+
50643+ If you use PaX it is essential that you say Y here as it closes up
50644+ several holes that make full ASLR useless locally.
50645+
50646+config GRKERNSEC_BRUTE
50647+ bool "Deter exploit bruteforcing"
50648+ default y if GRKERNSEC_CONFIG_AUTO
50649+ help
50650+ If you say Y here, attempts to bruteforce exploits against forking
50651+ daemons such as apache or sshd, as well as against suid/sgid binaries
50652+ will be deterred. When a child of a forking daemon is killed by PaX
50653+ or crashes due to an illegal instruction or other suspicious signal,
50654+ the parent process will be delayed 30 seconds upon every subsequent
50655+ fork until the administrator is able to assess the situation and
50656+ restart the daemon.
50657+ In the suid/sgid case, the attempt is logged, the user has all their
50658+ processes terminated, and they are prevented from executing any further
50659+ processes for 15 minutes.
50660+ It is recommended that you also enable signal logging in the auditing
50661+ section so that logs are generated when a process triggers a suspicious
50662+ signal.
50663+ If the sysctl option is enabled, a sysctl option with name
50664+ "deter_bruteforce" is created.
50665+
50666+
50667+config GRKERNSEC_MODHARDEN
50668+ bool "Harden module auto-loading"
50669+ default y if GRKERNSEC_CONFIG_AUTO
50670+ depends on MODULES
50671+ help
50672+ If you say Y here, module auto-loading in response to use of some
50673+ feature implemented by an unloaded module will be restricted to
50674+ root users. Enabling this option helps defend against attacks
50675+ by unprivileged users who abuse the auto-loading behavior to
50676+ cause a vulnerable module to load that is then exploited.
50677+
50678+ If this option prevents a legitimate use of auto-loading for a
50679+ non-root user, the administrator can execute modprobe manually
50680+ with the exact name of the module mentioned in the alert log.
50681+ Alternatively, the administrator can add the module to the list
50682+ of modules loaded at boot by modifying init scripts.
50683+
50684+ Modification of init scripts will most likely be needed on
50685+ Ubuntu servers with encrypted home directory support enabled,
50686+ as the first non-root user logging in will cause the ecb(aes),
50687+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50688+
50689+config GRKERNSEC_HIDESYM
50690+ bool "Hide kernel symbols"
50691+ default y if GRKERNSEC_CONFIG_AUTO
50692+ select PAX_USERCOPY_SLABS
50693+ help
50694+ If you say Y here, getting information on loaded modules, and
50695+ displaying all kernel symbols through a syscall will be restricted
50696+ to users with CAP_SYS_MODULE. For software compatibility reasons,
50697+ /proc/kallsyms will be restricted to the root user. The RBAC
50698+ system can hide that entry even from root.
50699+
50700+ This option also prevents leaking of kernel addresses through
50701+ several /proc entries.
50702+
50703+ Note that this option is only effective provided the following
50704+ conditions are met:
50705+ 1) The kernel using grsecurity is not precompiled by some distribution
50706+ 2) You have also enabled GRKERNSEC_DMESG
50707+ 3) You are using the RBAC system and hiding other files such as your
50708+ kernel image and System.map. Alternatively, enabling this option
50709+ causes the permissions on /boot, /lib/modules, and the kernel
50710+ source directory to change at compile time to prevent
50711+ reading by non-root users.
50712+ If the above conditions are met, this option will aid in providing a
50713+ useful protection against local kernel exploitation of overflows
50714+ and arbitrary read/write vulnerabilities.
50715+
50716+config GRKERNSEC_KERN_LOCKOUT
50717+ bool "Active kernel exploit response"
50718+ default y if GRKERNSEC_CONFIG_AUTO
50719+ depends on X86 || ARM || PPC || SPARC
50720+ help
50721+ If you say Y here, when a PaX alert is triggered due to suspicious
50722+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50723+ or an OOPS occurs due to bad memory accesses, instead of just
50724+ terminating the offending process (and potentially allowing
50725+ a subsequent exploit from the same user), we will take one of two
50726+ actions:
50727+ If the user was root, we will panic the system
50728+ If the user was non-root, we will log the attempt, terminate
50729+ all processes owned by the user, then prevent them from creating
50730+ any new processes until the system is restarted
50731+ This deters repeated kernel exploitation/bruteforcing attempts
50732+ and is useful for later forensics.
50733+
50734+endmenu
50735+menu "Role Based Access Control Options"
50736+depends on GRKERNSEC
50737+
50738+config GRKERNSEC_RBAC_DEBUG
50739+ bool
50740+
50741+config GRKERNSEC_NO_RBAC
50742+ bool "Disable RBAC system"
50743+ help
50744+ If you say Y here, the /dev/grsec device will be removed from the kernel,
50745+ preventing the RBAC system from being enabled. You should only say Y
50746+ here if you have no intention of using the RBAC system, so as to prevent
50747+ an attacker with root access from misusing the RBAC system to hide files
50748+ and processes when loadable module support and /dev/[k]mem have been
50749+ locked down.
50750+
50751+config GRKERNSEC_ACL_HIDEKERN
50752+ bool "Hide kernel processes"
50753+ help
50754+ If you say Y here, all kernel threads will be hidden to all
50755+ processes but those whose subject has the "view hidden processes"
50756+ flag.
50757+
50758+config GRKERNSEC_ACL_MAXTRIES
50759+ int "Maximum tries before password lockout"
50760+ default 3
50761+ help
50762+ This option enforces the maximum number of times a user can attempt
50763+ to authorize themselves with the grsecurity RBAC system before being
50764+ denied the ability to attempt authorization again for a specified time.
50765+ The lower the number, the harder it will be to brute-force a password.
50766+
50767+config GRKERNSEC_ACL_TIMEOUT
50768+ int "Time to wait after max password tries, in seconds"
50769+ default 30
50770+ help
50771+ This option specifies the time the user must wait after attempting to
50772+ authorize to the RBAC system with the maximum number of invalid
50773+ passwords. The higher the number, the harder it will be to brute-force
50774+ a password.
50775+
50776+endmenu
50777+menu "Filesystem Protections"
50778+depends on GRKERNSEC
50779+
50780+config GRKERNSEC_PROC
50781+ bool "Proc restrictions"
50782+ default y if GRKERNSEC_CONFIG_AUTO
50783+ help
50784+ If you say Y here, the permissions of the /proc filesystem
50785+ will be altered to enhance system security and privacy. You MUST
50786+ choose either a user only restriction or a user and group restriction.
50787+ Depending upon the option you choose, you can either restrict users to
50788+ see only the processes they themselves run, or choose a group that can
50789+ view all processes and files normally restricted to root if you choose
50790+ the "restrict to user only" option. NOTE: If you're running identd or
50791+ ntpd as a non-root user, you will have to run it as the group you
50792+ specify here.
50793+
50794+config GRKERNSEC_PROC_USER
50795+ bool "Restrict /proc to user only"
50796+ depends on GRKERNSEC_PROC
50797+ help
50798+ If you say Y here, non-root users will only be able to view their own
50799+ processes, and restricts them from viewing network-related information,
50800+ and viewing kernel symbol and module information.
50801+
50802+config GRKERNSEC_PROC_USERGROUP
50803+ bool "Allow special group"
50804+ default y if GRKERNSEC_CONFIG_AUTO
50805+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50806+ help
50807+ If you say Y here, you will be able to select a group that will be
50808+ able to view all processes and network-related information. If you've
50809+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50810+ remain hidden. This option is useful if you want to run identd as
50811+ a non-root user. The group you select may also be chosen at boot time
50812+ via "grsec_proc_gid=" on the kernel commandline.
50813+
50814+config GRKERNSEC_PROC_GID
50815+ int "GID for special group"
50816+ depends on GRKERNSEC_PROC_USERGROUP
50817+ default 1001
50818+
50819+config GRKERNSEC_PROC_ADD
50820+ bool "Additional restrictions"
50821+ default y if GRKERNSEC_CONFIG_AUTO
50822+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50823+ help
50824+ If you say Y here, additional restrictions will be placed on
50825+ /proc that keep normal users from viewing device information and
50826+ slabinfo information that could be useful for exploits.
50827+
50828+config GRKERNSEC_LINK
50829+ bool "Linking restrictions"
50830+ default y if GRKERNSEC_CONFIG_AUTO
50831+ help
50832+ If you say Y here, /tmp race exploits will be prevented, since users
50833+ will no longer be able to follow symlinks owned by other users in
50834+ world-writable +t directories (e.g. /tmp), unless the owner of the
50835+ symlink is the owner of the directory. users will also not be
50836+ able to hardlink to files they do not own. If the sysctl option is
50837+ enabled, a sysctl option with name "linking_restrictions" is created.
50838+
50839+config GRKERNSEC_SYMLINKOWN
50840+ bool "Kernel-enforced SymlinksIfOwnerMatch"
50841+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50842+ help
50843+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
50844+ that prevents it from being used as a security feature. As Apache
50845+ verifies the symlink by performing a stat() against the target of
50846+ the symlink before it is followed, an attacker can setup a symlink
50847+ to point to a same-owned file, then replace the symlink with one
50848+ that targets another user's file just after Apache "validates" the
50849+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
50850+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50851+ will be in place for the group you specify. If the sysctl option
50852+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
50853+ created.
50854+
50855+config GRKERNSEC_SYMLINKOWN_GID
50856+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50857+ depends on GRKERNSEC_SYMLINKOWN
50858+ default 1006
50859+ help
50860+ Setting this GID determines what group kernel-enforced
50861+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50862+ is enabled, a sysctl option with name "symlinkown_gid" is created.
50863+
50864+config GRKERNSEC_FIFO
50865+ bool "FIFO restrictions"
50866+ default y if GRKERNSEC_CONFIG_AUTO
50867+ help
50868+ If you say Y here, users will not be able to write to FIFOs they don't
50869+ own in world-writable +t directories (e.g. /tmp), unless the owner of
50870+ the FIFO is the same owner of the directory it's held in. If the sysctl
50871+ option is enabled, a sysctl option with name "fifo_restrictions" is
50872+ created.
50873+
50874+config GRKERNSEC_SYSFS_RESTRICT
50875+ bool "Sysfs/debugfs restriction"
50876+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50877+ depends on SYSFS
50878+ help
50879+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50880+ any filesystem normally mounted under it (e.g. debugfs) will be
50881+ mostly accessible only by root. These filesystems generally provide access
50882+ to hardware and debug information that isn't appropriate for unprivileged
50883+ users of the system. Sysfs and debugfs have also become a large source
50884+ of new vulnerabilities, ranging from infoleaks to local compromise.
50885+ There has been very little oversight with an eye toward security involved
50886+ in adding new exporters of information to these filesystems, so their
50887+ use is discouraged.
50888+ For reasons of compatibility, a few directories have been whitelisted
50889+ for access by non-root users:
50890+ /sys/fs/selinux
50891+ /sys/fs/fuse
50892+ /sys/devices/system/cpu
50893+
50894+config GRKERNSEC_ROFS
50895+ bool "Runtime read-only mount protection"
50896+ help
50897+ If you say Y here, a sysctl option with name "romount_protect" will
50898+ be created. By setting this option to 1 at runtime, filesystems
50899+ will be protected in the following ways:
50900+ * No new writable mounts will be allowed
50901+ * Existing read-only mounts won't be able to be remounted read/write
50902+ * Write operations will be denied on all block devices
50903+ This option acts independently of grsec_lock: once it is set to 1,
50904+ it cannot be turned off. Therefore, please be mindful of the resulting
50905+ behavior if this option is enabled in an init script on a read-only
50906+ filesystem. This feature is mainly intended for secure embedded systems.
50907+
50908+config GRKERNSEC_CHROOT
50909+ bool "Chroot jail restrictions"
50910+ default y if GRKERNSEC_CONFIG_AUTO
50911+ help
50912+ If you say Y here, you will be able to choose several options that will
50913+ make breaking out of a chrooted jail much more difficult. If you
50914+ encounter no software incompatibilities with the following options, it
50915+ is recommended that you enable each one.
50916+
50917+config GRKERNSEC_CHROOT_MOUNT
50918+ bool "Deny mounts"
50919+ default y if GRKERNSEC_CONFIG_AUTO
50920+ depends on GRKERNSEC_CHROOT
50921+ help
50922+ If you say Y here, processes inside a chroot will not be able to
50923+ mount or remount filesystems. If the sysctl option is enabled, a
50924+ sysctl option with name "chroot_deny_mount" is created.
50925+
50926+config GRKERNSEC_CHROOT_DOUBLE
50927+ bool "Deny double-chroots"
50928+ default y if GRKERNSEC_CONFIG_AUTO
50929+ depends on GRKERNSEC_CHROOT
50930+ help
50931+ If you say Y here, processes inside a chroot will not be able to chroot
50932+ again outside the chroot. This is a widely used method of breaking
50933+ out of a chroot jail and should not be allowed. If the sysctl
50934+ option is enabled, a sysctl option with name
50935+ "chroot_deny_chroot" is created.
50936+
50937+config GRKERNSEC_CHROOT_PIVOT
50938+ bool "Deny pivot_root in chroot"
50939+ default y if GRKERNSEC_CONFIG_AUTO
50940+ depends on GRKERNSEC_CHROOT
50941+ help
50942+ If you say Y here, processes inside a chroot will not be able to use
50943+ a function called pivot_root() that was introduced in Linux 2.3.41. It
50944+ works similar to chroot in that it changes the root filesystem. This
50945+ function could be misused in a chrooted process to attempt to break out
50946+ of the chroot, and therefore should not be allowed. If the sysctl
50947+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
50948+ created.
50949+
50950+config GRKERNSEC_CHROOT_CHDIR
50951+ bool "Enforce chdir(\"/\") on all chroots"
50952+ default y if GRKERNSEC_CONFIG_AUTO
50953+ depends on GRKERNSEC_CHROOT
50954+ help
50955+ If you say Y here, the current working directory of all newly-chrooted
50956+ applications will be set to the the root directory of the chroot.
50957+ The man page on chroot(2) states:
50958+ Note that this call does not change the current working
50959+ directory, so that `.' can be outside the tree rooted at
50960+ `/'. In particular, the super-user can escape from a
50961+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50962+
50963+ It is recommended that you say Y here, since it's not known to break
50964+ any software. If the sysctl option is enabled, a sysctl option with
50965+ name "chroot_enforce_chdir" is created.
50966+
50967+config GRKERNSEC_CHROOT_CHMOD
50968+ bool "Deny (f)chmod +s"
50969+ default y if GRKERNSEC_CONFIG_AUTO
50970+ depends on GRKERNSEC_CHROOT
50971+ help
50972+ If you say Y here, processes inside a chroot will not be able to chmod
50973+ or fchmod files to make them have suid or sgid bits. This protects
50974+ against another published method of breaking a chroot. If the sysctl
50975+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
50976+ created.
50977+
50978+config GRKERNSEC_CHROOT_FCHDIR
50979+ bool "Deny fchdir out of chroot"
50980+ default y if GRKERNSEC_CONFIG_AUTO
50981+ depends on GRKERNSEC_CHROOT
50982+ help
50983+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
50984+ to a file descriptor of the chrooting process that points to a directory
50985+ outside the filesystem will be stopped. If the sysctl option
50986+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50987+
50988+config GRKERNSEC_CHROOT_MKNOD
50989+ bool "Deny mknod"
50990+ default y if GRKERNSEC_CONFIG_AUTO
50991+ depends on GRKERNSEC_CHROOT
50992+ help
50993+ If you say Y here, processes inside a chroot will not be allowed to
50994+ mknod. The problem with using mknod inside a chroot is that it
50995+ would allow an attacker to create a device entry that is the same
50996+ as one on the physical root of your system, which could range from
50997+ anything from the console device to a device for your harddrive (which
50998+ they could then use to wipe the drive or steal data). It is recommended
50999+ that you say Y here, unless you run into software incompatibilities.
51000+ If the sysctl option is enabled, a sysctl option with name
51001+ "chroot_deny_mknod" is created.
51002+
51003+config GRKERNSEC_CHROOT_SHMAT
51004+ bool "Deny shmat() out of chroot"
51005+ default y if GRKERNSEC_CONFIG_AUTO
51006+ depends on GRKERNSEC_CHROOT
51007+ help
51008+ If you say Y here, processes inside a chroot will not be able to attach
51009+ to shared memory segments that were created outside of the chroot jail.
51010+ It is recommended that you say Y here. If the sysctl option is enabled,
51011+ a sysctl option with name "chroot_deny_shmat" is created.
51012+
51013+config GRKERNSEC_CHROOT_UNIX
51014+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
51015+ default y if GRKERNSEC_CONFIG_AUTO
51016+ depends on GRKERNSEC_CHROOT
51017+ help
51018+ If you say Y here, processes inside a chroot will not be able to
51019+ connect to abstract (meaning not belonging to a filesystem) Unix
51020+ domain sockets that were bound outside of a chroot. It is recommended
51021+ that you say Y here. If the sysctl option is enabled, a sysctl option
51022+ with name "chroot_deny_unix" is created.
51023+
51024+config GRKERNSEC_CHROOT_FINDTASK
51025+ bool "Protect outside processes"
51026+ default y if GRKERNSEC_CONFIG_AUTO
51027+ depends on GRKERNSEC_CHROOT
51028+ help
51029+ If you say Y here, processes inside a chroot will not be able to
51030+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51031+ getsid, or view any process outside of the chroot. If the sysctl
51032+ option is enabled, a sysctl option with name "chroot_findtask" is
51033+ created.
51034+
51035+config GRKERNSEC_CHROOT_NICE
51036+ bool "Restrict priority changes"
51037+ default y if GRKERNSEC_CONFIG_AUTO
51038+ depends on GRKERNSEC_CHROOT
51039+ help
51040+ If you say Y here, processes inside a chroot will not be able to raise
51041+ the priority of processes in the chroot, or alter the priority of
51042+ processes outside the chroot. This provides more security than simply
51043+ removing CAP_SYS_NICE from the process' capability set. If the
51044+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51045+ is created.
51046+
51047+config GRKERNSEC_CHROOT_SYSCTL
51048+ bool "Deny sysctl writes"
51049+ default y if GRKERNSEC_CONFIG_AUTO
51050+ depends on GRKERNSEC_CHROOT
51051+ help
51052+ If you say Y here, an attacker in a chroot will not be able to
51053+ write to sysctl entries, either by sysctl(2) or through a /proc
51054+ interface. It is strongly recommended that you say Y here. If the
51055+ sysctl option is enabled, a sysctl option with name
51056+ "chroot_deny_sysctl" is created.
51057+
51058+config GRKERNSEC_CHROOT_CAPS
51059+ bool "Capability restrictions"
51060+ default y if GRKERNSEC_CONFIG_AUTO
51061+ depends on GRKERNSEC_CHROOT
51062+ help
51063+ If you say Y here, the capabilities on all processes within a
51064+ chroot jail will be lowered to stop module insertion, raw i/o,
51065+ system and net admin tasks, rebooting the system, modifying immutable
51066+ files, modifying IPC owned by another, and changing the system time.
51067+ This is left an option because it can break some apps. Disable this
51068+ if your chrooted apps are having problems performing those kinds of
51069+ tasks. If the sysctl option is enabled, a sysctl option with
51070+ name "chroot_caps" is created.
51071+
51072+endmenu
51073+menu "Kernel Auditing"
51074+depends on GRKERNSEC
51075+
51076+config GRKERNSEC_AUDIT_GROUP
51077+ bool "Single group for auditing"
51078+ help
51079+ If you say Y here, the exec, chdir, and (un)mount logging features
51080+ will only operate on a group you specify. This option is recommended
51081+ if you only want to watch certain users instead of having a large
51082+ amount of logs from the entire system. If the sysctl option is enabled,
51083+ a sysctl option with name "audit_group" is created.
51084+
51085+config GRKERNSEC_AUDIT_GID
51086+ int "GID for auditing"
51087+ depends on GRKERNSEC_AUDIT_GROUP
51088+ default 1007
51089+
51090+config GRKERNSEC_EXECLOG
51091+ bool "Exec logging"
51092+ help
51093+ If you say Y here, all execve() calls will be logged (since the
51094+ other exec*() calls are frontends to execve(), all execution
51095+ will be logged). Useful for shell-servers that like to keep track
51096+ of their users. If the sysctl option is enabled, a sysctl option with
51097+ name "exec_logging" is created.
51098+ WARNING: This option when enabled will produce a LOT of logs, especially
51099+ on an active system.
51100+
51101+config GRKERNSEC_RESLOG
51102+ bool "Resource logging"
51103+ default y if GRKERNSEC_CONFIG_AUTO
51104+ help
51105+ If you say Y here, all attempts to overstep resource limits will
51106+ be logged with the resource name, the requested size, and the current
51107+ limit. It is highly recommended that you say Y here. If the sysctl
51108+ option is enabled, a sysctl option with name "resource_logging" is
51109+ created. If the RBAC system is enabled, the sysctl value is ignored.
51110+
51111+config GRKERNSEC_CHROOT_EXECLOG
51112+ bool "Log execs within chroot"
51113+ help
51114+ If you say Y here, all executions inside a chroot jail will be logged
51115+ to syslog. This can cause a large amount of logs if certain
51116+ applications (eg. djb's daemontools) are installed on the system, and
51117+ is therefore left as an option. If the sysctl option is enabled, a
51118+ sysctl option with name "chroot_execlog" is created.
51119+
51120+config GRKERNSEC_AUDIT_PTRACE
51121+ bool "Ptrace logging"
51122+ help
51123+ If you say Y here, all attempts to attach to a process via ptrace
51124+ will be logged. If the sysctl option is enabled, a sysctl option
51125+ with name "audit_ptrace" is created.
51126+
51127+config GRKERNSEC_AUDIT_CHDIR
51128+ bool "Chdir logging"
51129+ help
51130+ If you say Y here, all chdir() calls will be logged. If the sysctl
51131+ option is enabled, a sysctl option with name "audit_chdir" is created.
51132+
51133+config GRKERNSEC_AUDIT_MOUNT
51134+ bool "(Un)Mount logging"
51135+ help
51136+ If you say Y here, all mounts and unmounts will be logged. If the
51137+ sysctl option is enabled, a sysctl option with name "audit_mount" is
51138+ created.
51139+
51140+config GRKERNSEC_SIGNAL
51141+ bool "Signal logging"
51142+ default y if GRKERNSEC_CONFIG_AUTO
51143+ help
51144+ If you say Y here, certain important signals will be logged, such as
51145+ SIGSEGV, which will as a result inform you of when a error in a program
51146+ occurred, which in some cases could mean a possible exploit attempt.
51147+ If the sysctl option is enabled, a sysctl option with name
51148+ "signal_logging" is created.
51149+
51150+config GRKERNSEC_FORKFAIL
51151+ bool "Fork failure logging"
51152+ help
51153+ If you say Y here, all failed fork() attempts will be logged.
51154+ This could suggest a fork bomb, or someone attempting to overstep
51155+ their process limit. If the sysctl option is enabled, a sysctl option
51156+ with name "forkfail_logging" is created.
51157+
51158+config GRKERNSEC_TIME
51159+ bool "Time change logging"
51160+ default y if GRKERNSEC_CONFIG_AUTO
51161+ help
51162+ If you say Y here, any changes of the system clock will be logged.
51163+ If the sysctl option is enabled, a sysctl option with name
51164+ "timechange_logging" is created.
51165+
51166+config GRKERNSEC_PROC_IPADDR
51167+ bool "/proc/<pid>/ipaddr support"
51168+ default y if GRKERNSEC_CONFIG_AUTO
51169+ help
51170+ If you say Y here, a new entry will be added to each /proc/<pid>
51171+ directory that contains the IP address of the person using the task.
51172+ The IP is carried across local TCP and AF_UNIX stream sockets.
51173+ This information can be useful for IDS/IPSes to perform remote response
51174+ to a local attack. The entry is readable by only the owner of the
51175+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51176+ the RBAC system), and thus does not create privacy concerns.
51177+
51178+config GRKERNSEC_RWXMAP_LOG
51179+ bool 'Denied RWX mmap/mprotect logging'
51180+ default y if GRKERNSEC_CONFIG_AUTO
51181+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51182+ help
51183+ If you say Y here, calls to mmap() and mprotect() with explicit
51184+ usage of PROT_WRITE and PROT_EXEC together will be logged when
51185+ denied by the PAX_MPROTECT feature. If the sysctl option is
51186+ enabled, a sysctl option with name "rwxmap_logging" is created.
51187+
51188+config GRKERNSEC_AUDIT_TEXTREL
51189+ bool 'ELF text relocations logging (READ HELP)'
51190+ depends on PAX_MPROTECT
51191+ help
51192+ If you say Y here, text relocations will be logged with the filename
51193+ of the offending library or binary. The purpose of the feature is
51194+ to help Linux distribution developers get rid of libraries and
51195+ binaries that need text relocations which hinder the future progress
51196+ of PaX. Only Linux distribution developers should say Y here, and
51197+ never on a production machine, as this option creates an information
51198+ leak that could aid an attacker in defeating the randomization of
51199+ a single memory region. If the sysctl option is enabled, a sysctl
51200+ option with name "audit_textrel" is created.
51201+
51202+endmenu
51203+
51204+menu "Executable Protections"
51205+depends on GRKERNSEC
51206+
51207+config GRKERNSEC_DMESG
51208+ bool "Dmesg(8) restriction"
51209+ default y if GRKERNSEC_CONFIG_AUTO
51210+ help
51211+ If you say Y here, non-root users will not be able to use dmesg(8)
51212+ to view up to the last 4kb of messages in the kernel's log buffer.
51213+ The kernel's log buffer often contains kernel addresses and other
51214+ identifying information useful to an attacker in fingerprinting a
51215+ system for a targeted exploit.
51216+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
51217+ created.
51218+
51219+config GRKERNSEC_HARDEN_PTRACE
51220+ bool "Deter ptrace-based process snooping"
51221+ default y if GRKERNSEC_CONFIG_AUTO
51222+ help
51223+ If you say Y here, TTY sniffers and other malicious monitoring
51224+ programs implemented through ptrace will be defeated. If you
51225+ have been using the RBAC system, this option has already been
51226+ enabled for several years for all users, with the ability to make
51227+ fine-grained exceptions.
51228+
51229+ This option only affects the ability of non-root users to ptrace
51230+ processes that are not a descendent of the ptracing process.
51231+ This means that strace ./binary and gdb ./binary will still work,
51232+ but attaching to arbitrary processes will not. If the sysctl
51233+ option is enabled, a sysctl option with name "harden_ptrace" is
51234+ created.
51235+
51236+config GRKERNSEC_PTRACE_READEXEC
51237+ bool "Require read access to ptrace sensitive binaries"
51238+ default y if GRKERNSEC_CONFIG_AUTO
51239+ help
51240+ If you say Y here, unprivileged users will not be able to ptrace unreadable
51241+ binaries. This option is useful in environments that
51242+ remove the read bits (e.g. file mode 4711) from suid binaries to
51243+ prevent infoleaking of their contents. This option adds
51244+ consistency to the use of that file mode, as the binary could normally
51245+ be read out when run without privileges while ptracing.
51246+
51247+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51248+ is created.
51249+
51250+config GRKERNSEC_SETXID
51251+ bool "Enforce consistent multithreaded privileges"
51252+ default y if GRKERNSEC_CONFIG_AUTO
51253+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51254+ help
51255+ If you say Y here, a change from a root uid to a non-root uid
51256+ in a multithreaded application will cause the resulting uids,
51257+ gids, supplementary groups, and capabilities in that thread
51258+ to be propagated to the other threads of the process. In most
51259+ cases this is unnecessary, as glibc will emulate this behavior
51260+ on behalf of the application. Other libcs do not act in the
51261+ same way, allowing the other threads of the process to continue
51262+ running with root privileges. If the sysctl option is enabled,
51263+ a sysctl option with name "consistent_setxid" is created.
51264+
51265+config GRKERNSEC_TPE
51266+ bool "Trusted Path Execution (TPE)"
51267+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51268+ help
51269+ If you say Y here, you will be able to choose a gid to add to the
51270+ supplementary groups of users you want to mark as "untrusted."
51271+ These users will not be able to execute any files that are not in
51272+ root-owned directories writable only by root. If the sysctl option
51273+ is enabled, a sysctl option with name "tpe" is created.
51274+
51275+config GRKERNSEC_TPE_ALL
51276+ bool "Partially restrict all non-root users"
51277+ depends on GRKERNSEC_TPE
51278+ help
51279+ If you say Y here, all non-root users will be covered under
51280+ a weaker TPE restriction. This is separate from, and in addition to,
51281+ the main TPE options that you have selected elsewhere. Thus, if a
51282+ "trusted" GID is chosen, this restriction applies to even that GID.
51283+ Under this restriction, all non-root users will only be allowed to
51284+ execute files in directories they own that are not group or
51285+ world-writable, or in directories owned by root and writable only by
51286+ root. If the sysctl option is enabled, a sysctl option with name
51287+ "tpe_restrict_all" is created.
51288+
51289+config GRKERNSEC_TPE_INVERT
51290+ bool "Invert GID option"
51291+ depends on GRKERNSEC_TPE
51292+ help
51293+ If you say Y here, the group you specify in the TPE configuration will
51294+ decide what group TPE restrictions will be *disabled* for. This
51295+ option is useful if you want TPE restrictions to be applied to most
51296+ users on the system. If the sysctl option is enabled, a sysctl option
51297+ with name "tpe_invert" is created. Unlike other sysctl options, this
51298+ entry will default to on for backward-compatibility.
51299+
51300+config GRKERNSEC_TPE_GID
51301+ int
51302+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51303+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51304+
51305+config GRKERNSEC_TPE_UNTRUSTED_GID
51306+ int "GID for TPE-untrusted users"
51307+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51308+ default 1005
51309+ help
51310+ Setting this GID determines what group TPE restrictions will be
51311+ *enabled* for. If the sysctl option is enabled, a sysctl option
51312+ with name "tpe_gid" is created.
51313+
51314+config GRKERNSEC_TPE_TRUSTED_GID
51315+ int "GID for TPE-trusted users"
51316+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51317+ default 1005
51318+ help
51319+ Setting this GID determines what group TPE restrictions will be
51320+ *disabled* for. If the sysctl option is enabled, a sysctl option
51321+ with name "tpe_gid" is created.
51322+
51323+endmenu
51324+menu "Network Protections"
51325+depends on GRKERNSEC
51326+
51327+config GRKERNSEC_RANDNET
51328+ bool "Larger entropy pools"
51329+ default y if GRKERNSEC_CONFIG_AUTO
51330+ help
51331+ If you say Y here, the entropy pools used for many features of Linux
51332+ and grsecurity will be doubled in size. Since several grsecurity
51333+ features use additional randomness, it is recommended that you say Y
51334+ here. Saying Y here has a similar effect as modifying
51335+ /proc/sys/kernel/random/poolsize.
51336+
51337+config GRKERNSEC_BLACKHOLE
51338+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51339+ default y if GRKERNSEC_CONFIG_AUTO
51340+ depends on NET
51341+ help
51342+ If you say Y here, neither TCP resets nor ICMP
51343+ destination-unreachable packets will be sent in response to packets
51344+ sent to ports for which no associated listening process exists.
51345+ This feature supports both IPV4 and IPV6 and exempts the
51346+ loopback interface from blackholing. Enabling this feature
51347+ makes a host more resilient to DoS attacks and reduces network
51348+ visibility against scanners.
51349+
51350+ The blackhole feature as-implemented is equivalent to the FreeBSD
51351+ blackhole feature, as it prevents RST responses to all packets, not
51352+ just SYNs. Under most application behavior this causes no
51353+ problems, but applications (like haproxy) may not close certain
51354+ connections in a way that cleanly terminates them on the remote
51355+ end, leaving the remote host in LAST_ACK state. Because of this
51356+ side-effect and to prevent intentional LAST_ACK DoSes, this
51357+ feature also adds automatic mitigation against such attacks.
51358+ The mitigation drastically reduces the amount of time a socket
51359+ can spend in LAST_ACK state. If you're using haproxy and not
51360+ all servers it connects to have this option enabled, consider
51361+ disabling this feature on the haproxy host.
51362+
51363+ If the sysctl option is enabled, two sysctl options with names
51364+ "ip_blackhole" and "lastack_retries" will be created.
51365+ While "ip_blackhole" takes the standard zero/non-zero on/off
51366+ toggle, "lastack_retries" uses the same kinds of values as
51367+ "tcp_retries1" and "tcp_retries2". The default value of 4
51368+ prevents a socket from lasting more than 45 seconds in LAST_ACK
51369+ state.
51370+
51371+config GRKERNSEC_SOCKET
51372+ bool "Socket restrictions"
51373+ depends on NET
51374+ help
51375+ If you say Y here, you will be able to choose from several options.
51376+ If you assign a GID on your system and add it to the supplementary
51377+ groups of users you want to restrict socket access to, this patch
51378+ will perform up to three things, based on the option(s) you choose.
51379+
51380+config GRKERNSEC_SOCKET_ALL
51381+ bool "Deny any sockets to group"
51382+ depends on GRKERNSEC_SOCKET
51383+ help
51384+ If you say Y here, you will be able to choose a GID of whose users will
51385+ be unable to connect to other hosts from your machine or run server
51386+ applications from your machine. If the sysctl option is enabled, a
51387+ sysctl option with name "socket_all" is created.
51388+
51389+config GRKERNSEC_SOCKET_ALL_GID
51390+ int "GID to deny all sockets for"
51391+ depends on GRKERNSEC_SOCKET_ALL
51392+ default 1004
51393+ help
51394+ Here you can choose the GID to disable socket access for. Remember to
51395+ add the users you want socket access disabled for to the GID
51396+ specified here. If the sysctl option is enabled, a sysctl option
51397+ with name "socket_all_gid" is created.
51398+
51399+config GRKERNSEC_SOCKET_CLIENT
51400+ bool "Deny client sockets to group"
51401+ depends on GRKERNSEC_SOCKET
51402+ help
51403+ If you say Y here, you will be able to choose a GID of whose users will
51404+ be unable to connect to other hosts from your machine, but will be
51405+ able to run servers. If this option is enabled, all users in the group
51406+ you specify will have to use passive mode when initiating ftp transfers
51407+ from the shell on your machine. If the sysctl option is enabled, a
51408+ sysctl option with name "socket_client" is created.
51409+
51410+config GRKERNSEC_SOCKET_CLIENT_GID
51411+ int "GID to deny client sockets for"
51412+ depends on GRKERNSEC_SOCKET_CLIENT
51413+ default 1003
51414+ help
51415+ Here you can choose the GID to disable client socket access for.
51416+ Remember to add the users you want client socket access disabled for to
51417+ the GID specified here. If the sysctl option is enabled, a sysctl
51418+ option with name "socket_client_gid" is created.
51419+
51420+config GRKERNSEC_SOCKET_SERVER
51421+ bool "Deny server sockets to group"
51422+ depends on GRKERNSEC_SOCKET
51423+ help
51424+ If you say Y here, you will be able to choose a GID of whose users will
51425+ be unable to run server applications from your machine. If the sysctl
51426+ option is enabled, a sysctl option with name "socket_server" is created.
51427+
51428+config GRKERNSEC_SOCKET_SERVER_GID
51429+ int "GID to deny server sockets for"
51430+ depends on GRKERNSEC_SOCKET_SERVER
51431+ default 1002
51432+ help
51433+ Here you can choose the GID to disable server socket access for.
51434+ Remember to add the users you want server socket access disabled for to
51435+ the GID specified here. If the sysctl option is enabled, a sysctl
51436+ option with name "socket_server_gid" is created.
51437+
51438+endmenu
51439+menu "Sysctl Support"
51440+depends on GRKERNSEC && SYSCTL
51441+
51442+config GRKERNSEC_SYSCTL
51443+ bool "Sysctl support"
51444+ default y if GRKERNSEC_CONFIG_AUTO
51445+ help
51446+ If you say Y here, you will be able to change the options that
51447+ grsecurity runs with at bootup, without having to recompile your
51448+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51449+ to enable (1) or disable (0) various features. All the sysctl entries
51450+ are mutable until the "grsec_lock" entry is set to a non-zero value.
51451+ All features enabled in the kernel configuration are disabled at boot
51452+ if you do not say Y to the "Turn on features by default" option.
51453+ All options should be set at startup, and the grsec_lock entry should
51454+ be set to a non-zero value after all the options are set.
51455+ *THIS IS EXTREMELY IMPORTANT*
51456+
51457+config GRKERNSEC_SYSCTL_DISTRO
51458+ bool "Extra sysctl support for distro makers (READ HELP)"
51459+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51460+ help
51461+ If you say Y here, additional sysctl options will be created
51462+ for features that affect processes running as root. Therefore,
51463+ it is critical when using this option that the grsec_lock entry be
51464+ enabled after boot. Only distros with prebuilt kernel packages
51465+ with this option enabled that can ensure grsec_lock is enabled
51466+ after boot should use this option.
51467+ *Failure to set grsec_lock after boot makes all grsec features
51468+ this option covers useless*
51469+
51470+ Currently this option creates the following sysctl entries:
51471+ "Disable Privileged I/O": "disable_priv_io"
51472+
51473+config GRKERNSEC_SYSCTL_ON
51474+ bool "Turn on features by default"
51475+ default y if GRKERNSEC_CONFIG_AUTO
51476+ depends on GRKERNSEC_SYSCTL
51477+ help
51478+ If you say Y here, instead of having all features enabled in the
51479+ kernel configuration disabled at boot time, the features will be
51480+ enabled at boot time. It is recommended you say Y here unless
51481+ there is some reason you would want all sysctl-tunable features to
51482+ be disabled by default. As mentioned elsewhere, it is important
51483+ to enable the grsec_lock entry once you have finished modifying
51484+ the sysctl entries.
51485+
51486+endmenu
51487+menu "Logging Options"
51488+depends on GRKERNSEC
51489+
51490+config GRKERNSEC_FLOODTIME
51491+ int "Seconds in between log messages (minimum)"
51492+ default 10
51493+ help
51494+ This option allows you to enforce the number of seconds between
51495+ grsecurity log messages. The default should be suitable for most
51496+ people, however, if you choose to change it, choose a value small enough
51497+ to allow informative logs to be produced, but large enough to
51498+ prevent flooding.
51499+
51500+config GRKERNSEC_FLOODBURST
51501+ int "Number of messages in a burst (maximum)"
51502+ default 6
51503+ help
51504+ This option allows you to choose the maximum number of messages allowed
51505+ within the flood time interval you chose in a separate option. The
51506+ default should be suitable for most people, however if you find that
51507+ many of your logs are being interpreted as flooding, you may want to
51508+ raise this value.
51509+
51510+endmenu
51511diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51512new file mode 100644
51513index 0000000..1b9afa9
51514--- /dev/null
51515+++ b/grsecurity/Makefile
51516@@ -0,0 +1,38 @@
51517+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51518+# during 2001-2009 it has been completely redesigned by Brad Spengler
51519+# into an RBAC system
51520+#
51521+# All code in this directory and various hooks inserted throughout the kernel
51522+# are copyright Brad Spengler - Open Source Security, Inc., and released
51523+# under the GPL v2 or higher
51524+
51525+KBUILD_CFLAGS += -Werror
51526+
51527+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51528+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
51529+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51530+
51531+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51532+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51533+ gracl_learn.o grsec_log.o
51534+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51535+
51536+ifdef CONFIG_NET
51537+obj-y += grsec_sock.o
51538+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51539+endif
51540+
51541+ifndef CONFIG_GRKERNSEC
51542+obj-y += grsec_disabled.o
51543+endif
51544+
51545+ifdef CONFIG_GRKERNSEC_HIDESYM
51546+extra-y := grsec_hidesym.o
51547+$(obj)/grsec_hidesym.o:
51548+ @-chmod -f 500 /boot
51549+ @-chmod -f 500 /lib/modules
51550+ @-chmod -f 500 /lib64/modules
51551+ @-chmod -f 500 /lib32/modules
51552+ @-chmod -f 700 .
51553+ @echo ' grsec: protected kernel image paths'
51554+endif
51555diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51556new file mode 100644
51557index 0000000..07cd799
51558--- /dev/null
51559+++ b/grsecurity/gracl.c
51560@@ -0,0 +1,4017 @@
51561+#include <linux/kernel.h>
51562+#include <linux/module.h>
51563+#include <linux/sched.h>
51564+#include <linux/mm.h>
51565+#include <linux/file.h>
51566+#include <linux/fs.h>
51567+#include <linux/namei.h>
51568+#include <linux/mount.h>
51569+#include <linux/tty.h>
51570+#include <linux/proc_fs.h>
51571+#include <linux/lglock.h>
51572+#include <linux/slab.h>
51573+#include <linux/vmalloc.h>
51574+#include <linux/types.h>
51575+#include <linux/sysctl.h>
51576+#include <linux/netdevice.h>
51577+#include <linux/ptrace.h>
51578+#include <linux/gracl.h>
51579+#include <linux/gralloc.h>
51580+#include <linux/security.h>
51581+#include <linux/grinternal.h>
51582+#include <linux/pid_namespace.h>
51583+#include <linux/stop_machine.h>
51584+#include <linux/fdtable.h>
51585+#include <linux/percpu.h>
51586+#include <linux/lglock.h>
51587+#include "../fs/mount.h"
51588+
51589+#include <asm/uaccess.h>
51590+#include <asm/errno.h>
51591+#include <asm/mman.h>
51592+
51593+extern struct lglock vfsmount_lock;
51594+
51595+static struct acl_role_db acl_role_set;
51596+static struct name_db name_set;
51597+static struct inodev_db inodev_set;
51598+
51599+/* for keeping track of userspace pointers used for subjects, so we
51600+ can share references in the kernel as well
51601+*/
51602+
51603+static struct path real_root;
51604+
51605+static struct acl_subj_map_db subj_map_set;
51606+
51607+static struct acl_role_label *default_role;
51608+
51609+static struct acl_role_label *role_list;
51610+
51611+static u16 acl_sp_role_value;
51612+
51613+extern char *gr_shared_page[4];
51614+static DEFINE_MUTEX(gr_dev_mutex);
51615+DEFINE_RWLOCK(gr_inode_lock);
51616+
51617+struct gr_arg *gr_usermode;
51618+
51619+static unsigned int gr_status __read_only = GR_STATUS_INIT;
51620+
51621+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51622+extern void gr_clear_learn_entries(void);
51623+
51624+#ifdef CONFIG_GRKERNSEC_RESLOG
51625+extern void gr_log_resource(const struct task_struct *task,
51626+ const int res, const unsigned long wanted, const int gt);
51627+#endif
51628+
51629+unsigned char *gr_system_salt;
51630+unsigned char *gr_system_sum;
51631+
51632+static struct sprole_pw **acl_special_roles = NULL;
51633+static __u16 num_sprole_pws = 0;
51634+
51635+static struct acl_role_label *kernel_role = NULL;
51636+
51637+static unsigned int gr_auth_attempts = 0;
51638+static unsigned long gr_auth_expires = 0UL;
51639+
51640+#ifdef CONFIG_NET
51641+extern struct vfsmount *sock_mnt;
51642+#endif
51643+
51644+extern struct vfsmount *pipe_mnt;
51645+extern struct vfsmount *shm_mnt;
51646+#ifdef CONFIG_HUGETLBFS
51647+extern struct vfsmount *hugetlbfs_vfsmount;
51648+#endif
51649+
51650+static struct acl_object_label *fakefs_obj_rw;
51651+static struct acl_object_label *fakefs_obj_rwx;
51652+
51653+extern int gr_init_uidset(void);
51654+extern void gr_free_uidset(void);
51655+extern void gr_remove_uid(uid_t uid);
51656+extern int gr_find_uid(uid_t uid);
51657+
51658+__inline__ int
51659+gr_acl_is_enabled(void)
51660+{
51661+ return (gr_status & GR_READY);
51662+}
51663+
51664+#ifdef CONFIG_BTRFS_FS
51665+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51666+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51667+#endif
51668+
51669+static inline dev_t __get_dev(const struct dentry *dentry)
51670+{
51671+#ifdef CONFIG_BTRFS_FS
51672+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51673+ return get_btrfs_dev_from_inode(dentry->d_inode);
51674+ else
51675+#endif
51676+ return dentry->d_inode->i_sb->s_dev;
51677+}
51678+
51679+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51680+{
51681+ return __get_dev(dentry);
51682+}
51683+
51684+static char gr_task_roletype_to_char(struct task_struct *task)
51685+{
51686+ switch (task->role->roletype &
51687+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51688+ GR_ROLE_SPECIAL)) {
51689+ case GR_ROLE_DEFAULT:
51690+ return 'D';
51691+ case GR_ROLE_USER:
51692+ return 'U';
51693+ case GR_ROLE_GROUP:
51694+ return 'G';
51695+ case GR_ROLE_SPECIAL:
51696+ return 'S';
51697+ }
51698+
51699+ return 'X';
51700+}
51701+
51702+char gr_roletype_to_char(void)
51703+{
51704+ return gr_task_roletype_to_char(current);
51705+}
51706+
51707+__inline__ int
51708+gr_acl_tpe_check(void)
51709+{
51710+ if (unlikely(!(gr_status & GR_READY)))
51711+ return 0;
51712+ if (current->role->roletype & GR_ROLE_TPE)
51713+ return 1;
51714+ else
51715+ return 0;
51716+}
51717+
51718+int
51719+gr_handle_rawio(const struct inode *inode)
51720+{
51721+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51722+ if (inode && S_ISBLK(inode->i_mode) &&
51723+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51724+ !capable(CAP_SYS_RAWIO))
51725+ return 1;
51726+#endif
51727+ return 0;
51728+}
51729+
51730+static int
51731+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51732+{
51733+ if (likely(lena != lenb))
51734+ return 0;
51735+
51736+ return !memcmp(a, b, lena);
51737+}
51738+
51739+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51740+{
51741+ *buflen -= namelen;
51742+ if (*buflen < 0)
51743+ return -ENAMETOOLONG;
51744+ *buffer -= namelen;
51745+ memcpy(*buffer, str, namelen);
51746+ return 0;
51747+}
51748+
51749+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51750+{
51751+ return prepend(buffer, buflen, name->name, name->len);
51752+}
51753+
51754+static int prepend_path(const struct path *path, struct path *root,
51755+ char **buffer, int *buflen)
51756+{
51757+ struct dentry *dentry = path->dentry;
51758+ struct vfsmount *vfsmnt = path->mnt;
51759+ struct mount *mnt = real_mount(vfsmnt);
51760+ bool slash = false;
51761+ int error = 0;
51762+
51763+ while (dentry != root->dentry || vfsmnt != root->mnt) {
51764+ struct dentry * parent;
51765+
51766+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51767+ /* Global root? */
51768+ if (!mnt_has_parent(mnt)) {
51769+ goto out;
51770+ }
51771+ dentry = mnt->mnt_mountpoint;
51772+ mnt = mnt->mnt_parent;
51773+ vfsmnt = &mnt->mnt;
51774+ continue;
51775+ }
51776+ parent = dentry->d_parent;
51777+ prefetch(parent);
51778+ spin_lock(&dentry->d_lock);
51779+ error = prepend_name(buffer, buflen, &dentry->d_name);
51780+ spin_unlock(&dentry->d_lock);
51781+ if (!error)
51782+ error = prepend(buffer, buflen, "/", 1);
51783+ if (error)
51784+ break;
51785+
51786+ slash = true;
51787+ dentry = parent;
51788+ }
51789+
51790+out:
51791+ if (!error && !slash)
51792+ error = prepend(buffer, buflen, "/", 1);
51793+
51794+ return error;
51795+}
51796+
51797+/* this must be called with vfsmount_lock and rename_lock held */
51798+
51799+static char *__our_d_path(const struct path *path, struct path *root,
51800+ char *buf, int buflen)
51801+{
51802+ char *res = buf + buflen;
51803+ int error;
51804+
51805+ prepend(&res, &buflen, "\0", 1);
51806+ error = prepend_path(path, root, &res, &buflen);
51807+ if (error)
51808+ return ERR_PTR(error);
51809+
51810+ return res;
51811+}
51812+
51813+static char *
51814+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51815+{
51816+ char *retval;
51817+
51818+ retval = __our_d_path(path, root, buf, buflen);
51819+ if (unlikely(IS_ERR(retval)))
51820+ retval = strcpy(buf, "<path too long>");
51821+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51822+ retval[1] = '\0';
51823+
51824+ return retval;
51825+}
51826+
51827+static char *
51828+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51829+ char *buf, int buflen)
51830+{
51831+ struct path path;
51832+ char *res;
51833+
51834+ path.dentry = (struct dentry *)dentry;
51835+ path.mnt = (struct vfsmount *)vfsmnt;
51836+
51837+ /* we can use real_root.dentry, real_root.mnt, because this is only called
51838+ by the RBAC system */
51839+ res = gen_full_path(&path, &real_root, buf, buflen);
51840+
51841+ return res;
51842+}
51843+
51844+static char *
51845+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51846+ char *buf, int buflen)
51847+{
51848+ char *res;
51849+ struct path path;
51850+ struct path root;
51851+ struct task_struct *reaper = init_pid_ns.child_reaper;
51852+
51853+ path.dentry = (struct dentry *)dentry;
51854+ path.mnt = (struct vfsmount *)vfsmnt;
51855+
51856+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51857+ get_fs_root(reaper->fs, &root);
51858+
51859+ write_seqlock(&rename_lock);
51860+ br_read_lock(&vfsmount_lock);
51861+ res = gen_full_path(&path, &root, buf, buflen);
51862+ br_read_unlock(&vfsmount_lock);
51863+ write_sequnlock(&rename_lock);
51864+
51865+ path_put(&root);
51866+ return res;
51867+}
51868+
51869+static char *
51870+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51871+{
51872+ char *ret;
51873+ write_seqlock(&rename_lock);
51874+ br_read_lock(&vfsmount_lock);
51875+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51876+ PAGE_SIZE);
51877+ br_read_unlock(&vfsmount_lock);
51878+ write_sequnlock(&rename_lock);
51879+ return ret;
51880+}
51881+
51882+static char *
51883+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51884+{
51885+ char *ret;
51886+ char *buf;
51887+ int buflen;
51888+
51889+ write_seqlock(&rename_lock);
51890+ br_read_lock(&vfsmount_lock);
51891+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51892+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51893+ buflen = (int)(ret - buf);
51894+ if (buflen >= 5)
51895+ prepend(&ret, &buflen, "/proc", 5);
51896+ else
51897+ ret = strcpy(buf, "<path too long>");
51898+ br_read_unlock(&vfsmount_lock);
51899+ write_sequnlock(&rename_lock);
51900+ return ret;
51901+}
51902+
51903+char *
51904+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51905+{
51906+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51907+ PAGE_SIZE);
51908+}
51909+
51910+char *
51911+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51912+{
51913+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51914+ PAGE_SIZE);
51915+}
51916+
51917+char *
51918+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51919+{
51920+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51921+ PAGE_SIZE);
51922+}
51923+
51924+char *
51925+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51926+{
51927+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51928+ PAGE_SIZE);
51929+}
51930+
51931+char *
51932+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51933+{
51934+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51935+ PAGE_SIZE);
51936+}
51937+
51938+__inline__ __u32
51939+to_gr_audit(const __u32 reqmode)
51940+{
51941+ /* masks off auditable permission flags, then shifts them to create
51942+ auditing flags, and adds the special case of append auditing if
51943+ we're requesting write */
51944+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51945+}
51946+
51947+struct acl_subject_label *
51948+lookup_subject_map(const struct acl_subject_label *userp)
51949+{
51950+ unsigned int index = shash(userp, subj_map_set.s_size);
51951+ struct subject_map *match;
51952+
51953+ match = subj_map_set.s_hash[index];
51954+
51955+ while (match && match->user != userp)
51956+ match = match->next;
51957+
51958+ if (match != NULL)
51959+ return match->kernel;
51960+ else
51961+ return NULL;
51962+}
51963+
51964+static void
51965+insert_subj_map_entry(struct subject_map *subjmap)
51966+{
51967+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51968+ struct subject_map **curr;
51969+
51970+ subjmap->prev = NULL;
51971+
51972+ curr = &subj_map_set.s_hash[index];
51973+ if (*curr != NULL)
51974+ (*curr)->prev = subjmap;
51975+
51976+ subjmap->next = *curr;
51977+ *curr = subjmap;
51978+
51979+ return;
51980+}
51981+
51982+static struct acl_role_label *
51983+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51984+ const gid_t gid)
51985+{
51986+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51987+ struct acl_role_label *match;
51988+ struct role_allowed_ip *ipp;
51989+ unsigned int x;
51990+ u32 curr_ip = task->signal->curr_ip;
51991+
51992+ task->signal->saved_ip = curr_ip;
51993+
51994+ match = acl_role_set.r_hash[index];
51995+
51996+ while (match) {
51997+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51998+ for (x = 0; x < match->domain_child_num; x++) {
51999+ if (match->domain_children[x] == uid)
52000+ goto found;
52001+ }
52002+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52003+ break;
52004+ match = match->next;
52005+ }
52006+found:
52007+ if (match == NULL) {
52008+ try_group:
52009+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52010+ match = acl_role_set.r_hash[index];
52011+
52012+ while (match) {
52013+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52014+ for (x = 0; x < match->domain_child_num; x++) {
52015+ if (match->domain_children[x] == gid)
52016+ goto found2;
52017+ }
52018+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52019+ break;
52020+ match = match->next;
52021+ }
52022+found2:
52023+ if (match == NULL)
52024+ match = default_role;
52025+ if (match->allowed_ips == NULL)
52026+ return match;
52027+ else {
52028+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52029+ if (likely
52030+ ((ntohl(curr_ip) & ipp->netmask) ==
52031+ (ntohl(ipp->addr) & ipp->netmask)))
52032+ return match;
52033+ }
52034+ match = default_role;
52035+ }
52036+ } else if (match->allowed_ips == NULL) {
52037+ return match;
52038+ } else {
52039+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52040+ if (likely
52041+ ((ntohl(curr_ip) & ipp->netmask) ==
52042+ (ntohl(ipp->addr) & ipp->netmask)))
52043+ return match;
52044+ }
52045+ goto try_group;
52046+ }
52047+
52048+ return match;
52049+}
52050+
52051+struct acl_subject_label *
52052+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52053+ const struct acl_role_label *role)
52054+{
52055+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
52056+ struct acl_subject_label *match;
52057+
52058+ match = role->subj_hash[index];
52059+
52060+ while (match && (match->inode != ino || match->device != dev ||
52061+ (match->mode & GR_DELETED))) {
52062+ match = match->next;
52063+ }
52064+
52065+ if (match && !(match->mode & GR_DELETED))
52066+ return match;
52067+ else
52068+ return NULL;
52069+}
52070+
52071+struct acl_subject_label *
52072+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52073+ const struct acl_role_label *role)
52074+{
52075+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
52076+ struct acl_subject_label *match;
52077+
52078+ match = role->subj_hash[index];
52079+
52080+ while (match && (match->inode != ino || match->device != dev ||
52081+ !(match->mode & GR_DELETED))) {
52082+ match = match->next;
52083+ }
52084+
52085+ if (match && (match->mode & GR_DELETED))
52086+ return match;
52087+ else
52088+ return NULL;
52089+}
52090+
52091+static struct acl_object_label *
52092+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52093+ const struct acl_subject_label *subj)
52094+{
52095+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52096+ struct acl_object_label *match;
52097+
52098+ match = subj->obj_hash[index];
52099+
52100+ while (match && (match->inode != ino || match->device != dev ||
52101+ (match->mode & GR_DELETED))) {
52102+ match = match->next;
52103+ }
52104+
52105+ if (match && !(match->mode & GR_DELETED))
52106+ return match;
52107+ else
52108+ return NULL;
52109+}
52110+
52111+static struct acl_object_label *
52112+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52113+ const struct acl_subject_label *subj)
52114+{
52115+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52116+ struct acl_object_label *match;
52117+
52118+ match = subj->obj_hash[index];
52119+
52120+ while (match && (match->inode != ino || match->device != dev ||
52121+ !(match->mode & GR_DELETED))) {
52122+ match = match->next;
52123+ }
52124+
52125+ if (match && (match->mode & GR_DELETED))
52126+ return match;
52127+
52128+ match = subj->obj_hash[index];
52129+
52130+ while (match && (match->inode != ino || match->device != dev ||
52131+ (match->mode & GR_DELETED))) {
52132+ match = match->next;
52133+ }
52134+
52135+ if (match && !(match->mode & GR_DELETED))
52136+ return match;
52137+ else
52138+ return NULL;
52139+}
52140+
52141+static struct name_entry *
52142+lookup_name_entry(const char *name)
52143+{
52144+ unsigned int len = strlen(name);
52145+ unsigned int key = full_name_hash(name, len);
52146+ unsigned int index = key % name_set.n_size;
52147+ struct name_entry *match;
52148+
52149+ match = name_set.n_hash[index];
52150+
52151+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52152+ match = match->next;
52153+
52154+ return match;
52155+}
52156+
52157+static struct name_entry *
52158+lookup_name_entry_create(const char *name)
52159+{
52160+ unsigned int len = strlen(name);
52161+ unsigned int key = full_name_hash(name, len);
52162+ unsigned int index = key % name_set.n_size;
52163+ struct name_entry *match;
52164+
52165+ match = name_set.n_hash[index];
52166+
52167+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52168+ !match->deleted))
52169+ match = match->next;
52170+
52171+ if (match && match->deleted)
52172+ return match;
52173+
52174+ match = name_set.n_hash[index];
52175+
52176+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52177+ match->deleted))
52178+ match = match->next;
52179+
52180+ if (match && !match->deleted)
52181+ return match;
52182+ else
52183+ return NULL;
52184+}
52185+
52186+static struct inodev_entry *
52187+lookup_inodev_entry(const ino_t ino, const dev_t dev)
52188+{
52189+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
52190+ struct inodev_entry *match;
52191+
52192+ match = inodev_set.i_hash[index];
52193+
52194+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52195+ match = match->next;
52196+
52197+ return match;
52198+}
52199+
52200+static void
52201+insert_inodev_entry(struct inodev_entry *entry)
52202+{
52203+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52204+ inodev_set.i_size);
52205+ struct inodev_entry **curr;
52206+
52207+ entry->prev = NULL;
52208+
52209+ curr = &inodev_set.i_hash[index];
52210+ if (*curr != NULL)
52211+ (*curr)->prev = entry;
52212+
52213+ entry->next = *curr;
52214+ *curr = entry;
52215+
52216+ return;
52217+}
52218+
52219+static void
52220+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52221+{
52222+ unsigned int index =
52223+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52224+ struct acl_role_label **curr;
52225+ struct acl_role_label *tmp, *tmp2;
52226+
52227+ curr = &acl_role_set.r_hash[index];
52228+
52229+ /* simple case, slot is empty, just set it to our role */
52230+ if (*curr == NULL) {
52231+ *curr = role;
52232+ } else {
52233+ /* example:
52234+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
52235+ 2 -> 3
52236+ */
52237+ /* first check to see if we can already be reached via this slot */
52238+ tmp = *curr;
52239+ while (tmp && tmp != role)
52240+ tmp = tmp->next;
52241+ if (tmp == role) {
52242+ /* we don't need to add ourselves to this slot's chain */
52243+ return;
52244+ }
52245+ /* we need to add ourselves to this chain, two cases */
52246+ if (role->next == NULL) {
52247+ /* simple case, append the current chain to our role */
52248+ role->next = *curr;
52249+ *curr = role;
52250+ } else {
52251+ /* 1 -> 2 -> 3 -> 4
52252+ 2 -> 3 -> 4
52253+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52254+ */
52255+ /* trickier case: walk our role's chain until we find
52256+ the role for the start of the current slot's chain */
52257+ tmp = role;
52258+ tmp2 = *curr;
52259+ while (tmp->next && tmp->next != tmp2)
52260+ tmp = tmp->next;
52261+ if (tmp->next == tmp2) {
52262+ /* from example above, we found 3, so just
52263+ replace this slot's chain with ours */
52264+ *curr = role;
52265+ } else {
52266+ /* we didn't find a subset of our role's chain
52267+ in the current slot's chain, so append their
52268+ chain to ours, and set us as the first role in
52269+ the slot's chain
52270+
52271+ we could fold this case with the case above,
52272+ but making it explicit for clarity
52273+ */
52274+ tmp->next = tmp2;
52275+ *curr = role;
52276+ }
52277+ }
52278+ }
52279+
52280+ return;
52281+}
52282+
52283+static void
52284+insert_acl_role_label(struct acl_role_label *role)
52285+{
52286+ int i;
52287+
52288+ if (role_list == NULL) {
52289+ role_list = role;
52290+ role->prev = NULL;
52291+ } else {
52292+ role->prev = role_list;
52293+ role_list = role;
52294+ }
52295+
52296+ /* used for hash chains */
52297+ role->next = NULL;
52298+
52299+ if (role->roletype & GR_ROLE_DOMAIN) {
52300+ for (i = 0; i < role->domain_child_num; i++)
52301+ __insert_acl_role_label(role, role->domain_children[i]);
52302+ } else
52303+ __insert_acl_role_label(role, role->uidgid);
52304+}
52305+
52306+static int
52307+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52308+{
52309+ struct name_entry **curr, *nentry;
52310+ struct inodev_entry *ientry;
52311+ unsigned int len = strlen(name);
52312+ unsigned int key = full_name_hash(name, len);
52313+ unsigned int index = key % name_set.n_size;
52314+
52315+ curr = &name_set.n_hash[index];
52316+
52317+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52318+ curr = &((*curr)->next);
52319+
52320+ if (*curr != NULL)
52321+ return 1;
52322+
52323+ nentry = acl_alloc(sizeof (struct name_entry));
52324+ if (nentry == NULL)
52325+ return 0;
52326+ ientry = acl_alloc(sizeof (struct inodev_entry));
52327+ if (ientry == NULL)
52328+ return 0;
52329+ ientry->nentry = nentry;
52330+
52331+ nentry->key = key;
52332+ nentry->name = name;
52333+ nentry->inode = inode;
52334+ nentry->device = device;
52335+ nentry->len = len;
52336+ nentry->deleted = deleted;
52337+
52338+ nentry->prev = NULL;
52339+ curr = &name_set.n_hash[index];
52340+ if (*curr != NULL)
52341+ (*curr)->prev = nentry;
52342+ nentry->next = *curr;
52343+ *curr = nentry;
52344+
52345+ /* insert us into the table searchable by inode/dev */
52346+ insert_inodev_entry(ientry);
52347+
52348+ return 1;
52349+}
52350+
52351+static void
52352+insert_acl_obj_label(struct acl_object_label *obj,
52353+ struct acl_subject_label *subj)
52354+{
52355+ unsigned int index =
52356+ fhash(obj->inode, obj->device, subj->obj_hash_size);
52357+ struct acl_object_label **curr;
52358+
52359+
52360+ obj->prev = NULL;
52361+
52362+ curr = &subj->obj_hash[index];
52363+ if (*curr != NULL)
52364+ (*curr)->prev = obj;
52365+
52366+ obj->next = *curr;
52367+ *curr = obj;
52368+
52369+ return;
52370+}
52371+
52372+static void
52373+insert_acl_subj_label(struct acl_subject_label *obj,
52374+ struct acl_role_label *role)
52375+{
52376+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52377+ struct acl_subject_label **curr;
52378+
52379+ obj->prev = NULL;
52380+
52381+ curr = &role->subj_hash[index];
52382+ if (*curr != NULL)
52383+ (*curr)->prev = obj;
52384+
52385+ obj->next = *curr;
52386+ *curr = obj;
52387+
52388+ return;
52389+}
52390+
52391+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52392+
52393+static void *
52394+create_table(__u32 * len, int elementsize)
52395+{
52396+ unsigned int table_sizes[] = {
52397+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52398+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52399+ 4194301, 8388593, 16777213, 33554393, 67108859
52400+ };
52401+ void *newtable = NULL;
52402+ unsigned int pwr = 0;
52403+
52404+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52405+ table_sizes[pwr] <= *len)
52406+ pwr++;
52407+
52408+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52409+ return newtable;
52410+
52411+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52412+ newtable =
52413+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52414+ else
52415+ newtable = vmalloc(table_sizes[pwr] * elementsize);
52416+
52417+ *len = table_sizes[pwr];
52418+
52419+ return newtable;
52420+}
52421+
52422+static int
52423+init_variables(const struct gr_arg *arg)
52424+{
52425+ struct task_struct *reaper = init_pid_ns.child_reaper;
52426+ unsigned int stacksize;
52427+
52428+ subj_map_set.s_size = arg->role_db.num_subjects;
52429+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52430+ name_set.n_size = arg->role_db.num_objects;
52431+ inodev_set.i_size = arg->role_db.num_objects;
52432+
52433+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
52434+ !name_set.n_size || !inodev_set.i_size)
52435+ return 1;
52436+
52437+ if (!gr_init_uidset())
52438+ return 1;
52439+
52440+ /* set up the stack that holds allocation info */
52441+
52442+ stacksize = arg->role_db.num_pointers + 5;
52443+
52444+ if (!acl_alloc_stack_init(stacksize))
52445+ return 1;
52446+
52447+ /* grab reference for the real root dentry and vfsmount */
52448+ get_fs_root(reaper->fs, &real_root);
52449+
52450+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52451+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52452+#endif
52453+
52454+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52455+ if (fakefs_obj_rw == NULL)
52456+ return 1;
52457+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52458+
52459+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52460+ if (fakefs_obj_rwx == NULL)
52461+ return 1;
52462+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52463+
52464+ subj_map_set.s_hash =
52465+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52466+ acl_role_set.r_hash =
52467+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52468+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52469+ inodev_set.i_hash =
52470+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52471+
52472+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52473+ !name_set.n_hash || !inodev_set.i_hash)
52474+ return 1;
52475+
52476+ memset(subj_map_set.s_hash, 0,
52477+ sizeof(struct subject_map *) * subj_map_set.s_size);
52478+ memset(acl_role_set.r_hash, 0,
52479+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
52480+ memset(name_set.n_hash, 0,
52481+ sizeof (struct name_entry *) * name_set.n_size);
52482+ memset(inodev_set.i_hash, 0,
52483+ sizeof (struct inodev_entry *) * inodev_set.i_size);
52484+
52485+ return 0;
52486+}
52487+
52488+/* free information not needed after startup
52489+ currently contains user->kernel pointer mappings for subjects
52490+*/
52491+
52492+static void
52493+free_init_variables(void)
52494+{
52495+ __u32 i;
52496+
52497+ if (subj_map_set.s_hash) {
52498+ for (i = 0; i < subj_map_set.s_size; i++) {
52499+ if (subj_map_set.s_hash[i]) {
52500+ kfree(subj_map_set.s_hash[i]);
52501+ subj_map_set.s_hash[i] = NULL;
52502+ }
52503+ }
52504+
52505+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52506+ PAGE_SIZE)
52507+ kfree(subj_map_set.s_hash);
52508+ else
52509+ vfree(subj_map_set.s_hash);
52510+ }
52511+
52512+ return;
52513+}
52514+
52515+static void
52516+free_variables(void)
52517+{
52518+ struct acl_subject_label *s;
52519+ struct acl_role_label *r;
52520+ struct task_struct *task, *task2;
52521+ unsigned int x;
52522+
52523+ gr_clear_learn_entries();
52524+
52525+ read_lock(&tasklist_lock);
52526+ do_each_thread(task2, task) {
52527+ task->acl_sp_role = 0;
52528+ task->acl_role_id = 0;
52529+ task->acl = NULL;
52530+ task->role = NULL;
52531+ } while_each_thread(task2, task);
52532+ read_unlock(&tasklist_lock);
52533+
52534+ /* release the reference to the real root dentry and vfsmount */
52535+ path_put(&real_root);
52536+ memset(&real_root, 0, sizeof(real_root));
52537+
52538+ /* free all object hash tables */
52539+
52540+ FOR_EACH_ROLE_START(r)
52541+ if (r->subj_hash == NULL)
52542+ goto next_role;
52543+ FOR_EACH_SUBJECT_START(r, s, x)
52544+ if (s->obj_hash == NULL)
52545+ break;
52546+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52547+ kfree(s->obj_hash);
52548+ else
52549+ vfree(s->obj_hash);
52550+ FOR_EACH_SUBJECT_END(s, x)
52551+ FOR_EACH_NESTED_SUBJECT_START(r, s)
52552+ if (s->obj_hash == NULL)
52553+ break;
52554+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52555+ kfree(s->obj_hash);
52556+ else
52557+ vfree(s->obj_hash);
52558+ FOR_EACH_NESTED_SUBJECT_END(s)
52559+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52560+ kfree(r->subj_hash);
52561+ else
52562+ vfree(r->subj_hash);
52563+ r->subj_hash = NULL;
52564+next_role:
52565+ FOR_EACH_ROLE_END(r)
52566+
52567+ acl_free_all();
52568+
52569+ if (acl_role_set.r_hash) {
52570+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52571+ PAGE_SIZE)
52572+ kfree(acl_role_set.r_hash);
52573+ else
52574+ vfree(acl_role_set.r_hash);
52575+ }
52576+ if (name_set.n_hash) {
52577+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
52578+ PAGE_SIZE)
52579+ kfree(name_set.n_hash);
52580+ else
52581+ vfree(name_set.n_hash);
52582+ }
52583+
52584+ if (inodev_set.i_hash) {
52585+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52586+ PAGE_SIZE)
52587+ kfree(inodev_set.i_hash);
52588+ else
52589+ vfree(inodev_set.i_hash);
52590+ }
52591+
52592+ gr_free_uidset();
52593+
52594+ memset(&name_set, 0, sizeof (struct name_db));
52595+ memset(&inodev_set, 0, sizeof (struct inodev_db));
52596+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52597+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52598+
52599+ default_role = NULL;
52600+ kernel_role = NULL;
52601+ role_list = NULL;
52602+
52603+ return;
52604+}
52605+
52606+static __u32
52607+count_user_objs(struct acl_object_label *userp)
52608+{
52609+ struct acl_object_label o_tmp;
52610+ __u32 num = 0;
52611+
52612+ while (userp) {
52613+ if (copy_from_user(&o_tmp, userp,
52614+ sizeof (struct acl_object_label)))
52615+ break;
52616+
52617+ userp = o_tmp.prev;
52618+ num++;
52619+ }
52620+
52621+ return num;
52622+}
52623+
52624+static struct acl_subject_label *
52625+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52626+
52627+static int
52628+copy_user_glob(struct acl_object_label *obj)
52629+{
52630+ struct acl_object_label *g_tmp, **guser;
52631+ unsigned int len;
52632+ char *tmp;
52633+
52634+ if (obj->globbed == NULL)
52635+ return 0;
52636+
52637+ guser = &obj->globbed;
52638+ while (*guser) {
52639+ g_tmp = (struct acl_object_label *)
52640+ acl_alloc(sizeof (struct acl_object_label));
52641+ if (g_tmp == NULL)
52642+ return -ENOMEM;
52643+
52644+ if (copy_from_user(g_tmp, *guser,
52645+ sizeof (struct acl_object_label)))
52646+ return -EFAULT;
52647+
52648+ len = strnlen_user(g_tmp->filename, PATH_MAX);
52649+
52650+ if (!len || len >= PATH_MAX)
52651+ return -EINVAL;
52652+
52653+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52654+ return -ENOMEM;
52655+
52656+ if (copy_from_user(tmp, g_tmp->filename, len))
52657+ return -EFAULT;
52658+ tmp[len-1] = '\0';
52659+ g_tmp->filename = tmp;
52660+
52661+ *guser = g_tmp;
52662+ guser = &(g_tmp->next);
52663+ }
52664+
52665+ return 0;
52666+}
52667+
52668+static int
52669+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52670+ struct acl_role_label *role)
52671+{
52672+ struct acl_object_label *o_tmp;
52673+ unsigned int len;
52674+ int ret;
52675+ char *tmp;
52676+
52677+ while (userp) {
52678+ if ((o_tmp = (struct acl_object_label *)
52679+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
52680+ return -ENOMEM;
52681+
52682+ if (copy_from_user(o_tmp, userp,
52683+ sizeof (struct acl_object_label)))
52684+ return -EFAULT;
52685+
52686+ userp = o_tmp->prev;
52687+
52688+ len = strnlen_user(o_tmp->filename, PATH_MAX);
52689+
52690+ if (!len || len >= PATH_MAX)
52691+ return -EINVAL;
52692+
52693+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52694+ return -ENOMEM;
52695+
52696+ if (copy_from_user(tmp, o_tmp->filename, len))
52697+ return -EFAULT;
52698+ tmp[len-1] = '\0';
52699+ o_tmp->filename = tmp;
52700+
52701+ insert_acl_obj_label(o_tmp, subj);
52702+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52703+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52704+ return -ENOMEM;
52705+
52706+ ret = copy_user_glob(o_tmp);
52707+ if (ret)
52708+ return ret;
52709+
52710+ if (o_tmp->nested) {
52711+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52712+ if (IS_ERR(o_tmp->nested))
52713+ return PTR_ERR(o_tmp->nested);
52714+
52715+ /* insert into nested subject list */
52716+ o_tmp->nested->next = role->hash->first;
52717+ role->hash->first = o_tmp->nested;
52718+ }
52719+ }
52720+
52721+ return 0;
52722+}
52723+
52724+static __u32
52725+count_user_subjs(struct acl_subject_label *userp)
52726+{
52727+ struct acl_subject_label s_tmp;
52728+ __u32 num = 0;
52729+
52730+ while (userp) {
52731+ if (copy_from_user(&s_tmp, userp,
52732+ sizeof (struct acl_subject_label)))
52733+ break;
52734+
52735+ userp = s_tmp.prev;
52736+ /* do not count nested subjects against this count, since
52737+ they are not included in the hash table, but are
52738+ attached to objects. We have already counted
52739+ the subjects in userspace for the allocation
52740+ stack
52741+ */
52742+ if (!(s_tmp.mode & GR_NESTED))
52743+ num++;
52744+ }
52745+
52746+ return num;
52747+}
52748+
52749+static int
52750+copy_user_allowedips(struct acl_role_label *rolep)
52751+{
52752+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52753+
52754+ ruserip = rolep->allowed_ips;
52755+
52756+ while (ruserip) {
52757+ rlast = rtmp;
52758+
52759+ if ((rtmp = (struct role_allowed_ip *)
52760+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52761+ return -ENOMEM;
52762+
52763+ if (copy_from_user(rtmp, ruserip,
52764+ sizeof (struct role_allowed_ip)))
52765+ return -EFAULT;
52766+
52767+ ruserip = rtmp->prev;
52768+
52769+ if (!rlast) {
52770+ rtmp->prev = NULL;
52771+ rolep->allowed_ips = rtmp;
52772+ } else {
52773+ rlast->next = rtmp;
52774+ rtmp->prev = rlast;
52775+ }
52776+
52777+ if (!ruserip)
52778+ rtmp->next = NULL;
52779+ }
52780+
52781+ return 0;
52782+}
52783+
52784+static int
52785+copy_user_transitions(struct acl_role_label *rolep)
52786+{
52787+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
52788+
52789+ unsigned int len;
52790+ char *tmp;
52791+
52792+ rusertp = rolep->transitions;
52793+
52794+ while (rusertp) {
52795+ rlast = rtmp;
52796+
52797+ if ((rtmp = (struct role_transition *)
52798+ acl_alloc(sizeof (struct role_transition))) == NULL)
52799+ return -ENOMEM;
52800+
52801+ if (copy_from_user(rtmp, rusertp,
52802+ sizeof (struct role_transition)))
52803+ return -EFAULT;
52804+
52805+ rusertp = rtmp->prev;
52806+
52807+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52808+
52809+ if (!len || len >= GR_SPROLE_LEN)
52810+ return -EINVAL;
52811+
52812+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52813+ return -ENOMEM;
52814+
52815+ if (copy_from_user(tmp, rtmp->rolename, len))
52816+ return -EFAULT;
52817+ tmp[len-1] = '\0';
52818+ rtmp->rolename = tmp;
52819+
52820+ if (!rlast) {
52821+ rtmp->prev = NULL;
52822+ rolep->transitions = rtmp;
52823+ } else {
52824+ rlast->next = rtmp;
52825+ rtmp->prev = rlast;
52826+ }
52827+
52828+ if (!rusertp)
52829+ rtmp->next = NULL;
52830+ }
52831+
52832+ return 0;
52833+}
52834+
52835+static struct acl_subject_label *
52836+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52837+{
52838+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52839+ unsigned int len;
52840+ char *tmp;
52841+ __u32 num_objs;
52842+ struct acl_ip_label **i_tmp, *i_utmp2;
52843+ struct gr_hash_struct ghash;
52844+ struct subject_map *subjmap;
52845+ unsigned int i_num;
52846+ int err;
52847+
52848+ s_tmp = lookup_subject_map(userp);
52849+
52850+ /* we've already copied this subject into the kernel, just return
52851+ the reference to it, and don't copy it over again
52852+ */
52853+ if (s_tmp)
52854+ return(s_tmp);
52855+
52856+ if ((s_tmp = (struct acl_subject_label *)
52857+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52858+ return ERR_PTR(-ENOMEM);
52859+
52860+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52861+ if (subjmap == NULL)
52862+ return ERR_PTR(-ENOMEM);
52863+
52864+ subjmap->user = userp;
52865+ subjmap->kernel = s_tmp;
52866+ insert_subj_map_entry(subjmap);
52867+
52868+ if (copy_from_user(s_tmp, userp,
52869+ sizeof (struct acl_subject_label)))
52870+ return ERR_PTR(-EFAULT);
52871+
52872+ len = strnlen_user(s_tmp->filename, PATH_MAX);
52873+
52874+ if (!len || len >= PATH_MAX)
52875+ return ERR_PTR(-EINVAL);
52876+
52877+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52878+ return ERR_PTR(-ENOMEM);
52879+
52880+ if (copy_from_user(tmp, s_tmp->filename, len))
52881+ return ERR_PTR(-EFAULT);
52882+ tmp[len-1] = '\0';
52883+ s_tmp->filename = tmp;
52884+
52885+ if (!strcmp(s_tmp->filename, "/"))
52886+ role->root_label = s_tmp;
52887+
52888+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52889+ return ERR_PTR(-EFAULT);
52890+
52891+ /* copy user and group transition tables */
52892+
52893+ if (s_tmp->user_trans_num) {
52894+ uid_t *uidlist;
52895+
52896+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52897+ if (uidlist == NULL)
52898+ return ERR_PTR(-ENOMEM);
52899+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52900+ return ERR_PTR(-EFAULT);
52901+
52902+ s_tmp->user_transitions = uidlist;
52903+ }
52904+
52905+ if (s_tmp->group_trans_num) {
52906+ gid_t *gidlist;
52907+
52908+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52909+ if (gidlist == NULL)
52910+ return ERR_PTR(-ENOMEM);
52911+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52912+ return ERR_PTR(-EFAULT);
52913+
52914+ s_tmp->group_transitions = gidlist;
52915+ }
52916+
52917+ /* set up object hash table */
52918+ num_objs = count_user_objs(ghash.first);
52919+
52920+ s_tmp->obj_hash_size = num_objs;
52921+ s_tmp->obj_hash =
52922+ (struct acl_object_label **)
52923+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52924+
52925+ if (!s_tmp->obj_hash)
52926+ return ERR_PTR(-ENOMEM);
52927+
52928+ memset(s_tmp->obj_hash, 0,
52929+ s_tmp->obj_hash_size *
52930+ sizeof (struct acl_object_label *));
52931+
52932+ /* add in objects */
52933+ err = copy_user_objs(ghash.first, s_tmp, role);
52934+
52935+ if (err)
52936+ return ERR_PTR(err);
52937+
52938+ /* set pointer for parent subject */
52939+ if (s_tmp->parent_subject) {
52940+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52941+
52942+ if (IS_ERR(s_tmp2))
52943+ return s_tmp2;
52944+
52945+ s_tmp->parent_subject = s_tmp2;
52946+ }
52947+
52948+ /* add in ip acls */
52949+
52950+ if (!s_tmp->ip_num) {
52951+ s_tmp->ips = NULL;
52952+ goto insert;
52953+ }
52954+
52955+ i_tmp =
52956+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52957+ sizeof (struct acl_ip_label *));
52958+
52959+ if (!i_tmp)
52960+ return ERR_PTR(-ENOMEM);
52961+
52962+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52963+ *(i_tmp + i_num) =
52964+ (struct acl_ip_label *)
52965+ acl_alloc(sizeof (struct acl_ip_label));
52966+ if (!*(i_tmp + i_num))
52967+ return ERR_PTR(-ENOMEM);
52968+
52969+ if (copy_from_user
52970+ (&i_utmp2, s_tmp->ips + i_num,
52971+ sizeof (struct acl_ip_label *)))
52972+ return ERR_PTR(-EFAULT);
52973+
52974+ if (copy_from_user
52975+ (*(i_tmp + i_num), i_utmp2,
52976+ sizeof (struct acl_ip_label)))
52977+ return ERR_PTR(-EFAULT);
52978+
52979+ if ((*(i_tmp + i_num))->iface == NULL)
52980+ continue;
52981+
52982+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52983+ if (!len || len >= IFNAMSIZ)
52984+ return ERR_PTR(-EINVAL);
52985+ tmp = acl_alloc(len);
52986+ if (tmp == NULL)
52987+ return ERR_PTR(-ENOMEM);
52988+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52989+ return ERR_PTR(-EFAULT);
52990+ (*(i_tmp + i_num))->iface = tmp;
52991+ }
52992+
52993+ s_tmp->ips = i_tmp;
52994+
52995+insert:
52996+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52997+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52998+ return ERR_PTR(-ENOMEM);
52999+
53000+ return s_tmp;
53001+}
53002+
53003+static int
53004+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53005+{
53006+ struct acl_subject_label s_pre;
53007+ struct acl_subject_label * ret;
53008+ int err;
53009+
53010+ while (userp) {
53011+ if (copy_from_user(&s_pre, userp,
53012+ sizeof (struct acl_subject_label)))
53013+ return -EFAULT;
53014+
53015+ /* do not add nested subjects here, add
53016+ while parsing objects
53017+ */
53018+
53019+ if (s_pre.mode & GR_NESTED) {
53020+ userp = s_pre.prev;
53021+ continue;
53022+ }
53023+
53024+ ret = do_copy_user_subj(userp, role);
53025+
53026+ err = PTR_ERR(ret);
53027+ if (IS_ERR(ret))
53028+ return err;
53029+
53030+ insert_acl_subj_label(ret, role);
53031+
53032+ userp = s_pre.prev;
53033+ }
53034+
53035+ return 0;
53036+}
53037+
53038+static int
53039+copy_user_acl(struct gr_arg *arg)
53040+{
53041+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53042+ struct sprole_pw *sptmp;
53043+ struct gr_hash_struct *ghash;
53044+ uid_t *domainlist;
53045+ unsigned int r_num;
53046+ unsigned int len;
53047+ char *tmp;
53048+ int err = 0;
53049+ __u16 i;
53050+ __u32 num_subjs;
53051+
53052+ /* we need a default and kernel role */
53053+ if (arg->role_db.num_roles < 2)
53054+ return -EINVAL;
53055+
53056+ /* copy special role authentication info from userspace */
53057+
53058+ num_sprole_pws = arg->num_sprole_pws;
53059+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53060+
53061+ if (!acl_special_roles && num_sprole_pws)
53062+ return -ENOMEM;
53063+
53064+ for (i = 0; i < num_sprole_pws; i++) {
53065+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53066+ if (!sptmp)
53067+ return -ENOMEM;
53068+ if (copy_from_user(sptmp, arg->sprole_pws + i,
53069+ sizeof (struct sprole_pw)))
53070+ return -EFAULT;
53071+
53072+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53073+
53074+ if (!len || len >= GR_SPROLE_LEN)
53075+ return -EINVAL;
53076+
53077+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53078+ return -ENOMEM;
53079+
53080+ if (copy_from_user(tmp, sptmp->rolename, len))
53081+ return -EFAULT;
53082+
53083+ tmp[len-1] = '\0';
53084+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53085+ printk(KERN_ALERT "Copying special role %s\n", tmp);
53086+#endif
53087+ sptmp->rolename = tmp;
53088+ acl_special_roles[i] = sptmp;
53089+ }
53090+
53091+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53092+
53093+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53094+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
53095+
53096+ if (!r_tmp)
53097+ return -ENOMEM;
53098+
53099+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
53100+ sizeof (struct acl_role_label *)))
53101+ return -EFAULT;
53102+
53103+ if (copy_from_user(r_tmp, r_utmp2,
53104+ sizeof (struct acl_role_label)))
53105+ return -EFAULT;
53106+
53107+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53108+
53109+ if (!len || len >= PATH_MAX)
53110+ return -EINVAL;
53111+
53112+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53113+ return -ENOMEM;
53114+
53115+ if (copy_from_user(tmp, r_tmp->rolename, len))
53116+ return -EFAULT;
53117+
53118+ tmp[len-1] = '\0';
53119+ r_tmp->rolename = tmp;
53120+
53121+ if (!strcmp(r_tmp->rolename, "default")
53122+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53123+ default_role = r_tmp;
53124+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53125+ kernel_role = r_tmp;
53126+ }
53127+
53128+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53129+ return -ENOMEM;
53130+
53131+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53132+ return -EFAULT;
53133+
53134+ r_tmp->hash = ghash;
53135+
53136+ num_subjs = count_user_subjs(r_tmp->hash->first);
53137+
53138+ r_tmp->subj_hash_size = num_subjs;
53139+ r_tmp->subj_hash =
53140+ (struct acl_subject_label **)
53141+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53142+
53143+ if (!r_tmp->subj_hash)
53144+ return -ENOMEM;
53145+
53146+ err = copy_user_allowedips(r_tmp);
53147+ if (err)
53148+ return err;
53149+
53150+ /* copy domain info */
53151+ if (r_tmp->domain_children != NULL) {
53152+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53153+ if (domainlist == NULL)
53154+ return -ENOMEM;
53155+
53156+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53157+ return -EFAULT;
53158+
53159+ r_tmp->domain_children = domainlist;
53160+ }
53161+
53162+ err = copy_user_transitions(r_tmp);
53163+ if (err)
53164+ return err;
53165+
53166+ memset(r_tmp->subj_hash, 0,
53167+ r_tmp->subj_hash_size *
53168+ sizeof (struct acl_subject_label *));
53169+
53170+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
53171+
53172+ if (err)
53173+ return err;
53174+
53175+ /* set nested subject list to null */
53176+ r_tmp->hash->first = NULL;
53177+
53178+ insert_acl_role_label(r_tmp);
53179+ }
53180+
53181+ if (default_role == NULL || kernel_role == NULL)
53182+ return -EINVAL;
53183+
53184+ return err;
53185+}
53186+
53187+static int
53188+gracl_init(struct gr_arg *args)
53189+{
53190+ int error = 0;
53191+
53192+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53193+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53194+
53195+ if (init_variables(args)) {
53196+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53197+ error = -ENOMEM;
53198+ free_variables();
53199+ goto out;
53200+ }
53201+
53202+ error = copy_user_acl(args);
53203+ free_init_variables();
53204+ if (error) {
53205+ free_variables();
53206+ goto out;
53207+ }
53208+
53209+ if ((error = gr_set_acls(0))) {
53210+ free_variables();
53211+ goto out;
53212+ }
53213+
53214+ pax_open_kernel();
53215+ gr_status |= GR_READY;
53216+ pax_close_kernel();
53217+
53218+ out:
53219+ return error;
53220+}
53221+
53222+/* derived from glibc fnmatch() 0: match, 1: no match*/
53223+
53224+static int
53225+glob_match(const char *p, const char *n)
53226+{
53227+ char c;
53228+
53229+ while ((c = *p++) != '\0') {
53230+ switch (c) {
53231+ case '?':
53232+ if (*n == '\0')
53233+ return 1;
53234+ else if (*n == '/')
53235+ return 1;
53236+ break;
53237+ case '\\':
53238+ if (*n != c)
53239+ return 1;
53240+ break;
53241+ case '*':
53242+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
53243+ if (*n == '/')
53244+ return 1;
53245+ else if (c == '?') {
53246+ if (*n == '\0')
53247+ return 1;
53248+ else
53249+ ++n;
53250+ }
53251+ }
53252+ if (c == '\0') {
53253+ return 0;
53254+ } else {
53255+ const char *endp;
53256+
53257+ if ((endp = strchr(n, '/')) == NULL)
53258+ endp = n + strlen(n);
53259+
53260+ if (c == '[') {
53261+ for (--p; n < endp; ++n)
53262+ if (!glob_match(p, n))
53263+ return 0;
53264+ } else if (c == '/') {
53265+ while (*n != '\0' && *n != '/')
53266+ ++n;
53267+ if (*n == '/' && !glob_match(p, n + 1))
53268+ return 0;
53269+ } else {
53270+ for (--p; n < endp; ++n)
53271+ if (*n == c && !glob_match(p, n))
53272+ return 0;
53273+ }
53274+
53275+ return 1;
53276+ }
53277+ case '[':
53278+ {
53279+ int not;
53280+ char cold;
53281+
53282+ if (*n == '\0' || *n == '/')
53283+ return 1;
53284+
53285+ not = (*p == '!' || *p == '^');
53286+ if (not)
53287+ ++p;
53288+
53289+ c = *p++;
53290+ for (;;) {
53291+ unsigned char fn = (unsigned char)*n;
53292+
53293+ if (c == '\0')
53294+ return 1;
53295+ else {
53296+ if (c == fn)
53297+ goto matched;
53298+ cold = c;
53299+ c = *p++;
53300+
53301+ if (c == '-' && *p != ']') {
53302+ unsigned char cend = *p++;
53303+
53304+ if (cend == '\0')
53305+ return 1;
53306+
53307+ if (cold <= fn && fn <= cend)
53308+ goto matched;
53309+
53310+ c = *p++;
53311+ }
53312+ }
53313+
53314+ if (c == ']')
53315+ break;
53316+ }
53317+ if (!not)
53318+ return 1;
53319+ break;
53320+ matched:
53321+ while (c != ']') {
53322+ if (c == '\0')
53323+ return 1;
53324+
53325+ c = *p++;
53326+ }
53327+ if (not)
53328+ return 1;
53329+ }
53330+ break;
53331+ default:
53332+ if (c != *n)
53333+ return 1;
53334+ }
53335+
53336+ ++n;
53337+ }
53338+
53339+ if (*n == '\0')
53340+ return 0;
53341+
53342+ if (*n == '/')
53343+ return 0;
53344+
53345+ return 1;
53346+}
53347+
53348+static struct acl_object_label *
53349+chk_glob_label(struct acl_object_label *globbed,
53350+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53351+{
53352+ struct acl_object_label *tmp;
53353+
53354+ if (*path == NULL)
53355+ *path = gr_to_filename_nolock(dentry, mnt);
53356+
53357+ tmp = globbed;
53358+
53359+ while (tmp) {
53360+ if (!glob_match(tmp->filename, *path))
53361+ return tmp;
53362+ tmp = tmp->next;
53363+ }
53364+
53365+ return NULL;
53366+}
53367+
53368+static struct acl_object_label *
53369+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53370+ const ino_t curr_ino, const dev_t curr_dev,
53371+ const struct acl_subject_label *subj, char **path, const int checkglob)
53372+{
53373+ struct acl_subject_label *tmpsubj;
53374+ struct acl_object_label *retval;
53375+ struct acl_object_label *retval2;
53376+
53377+ tmpsubj = (struct acl_subject_label *) subj;
53378+ read_lock(&gr_inode_lock);
53379+ do {
53380+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53381+ if (retval) {
53382+ if (checkglob && retval->globbed) {
53383+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53384+ if (retval2)
53385+ retval = retval2;
53386+ }
53387+ break;
53388+ }
53389+ } while ((tmpsubj = tmpsubj->parent_subject));
53390+ read_unlock(&gr_inode_lock);
53391+
53392+ return retval;
53393+}
53394+
53395+static __inline__ struct acl_object_label *
53396+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53397+ struct dentry *curr_dentry,
53398+ const struct acl_subject_label *subj, char **path, const int checkglob)
53399+{
53400+ int newglob = checkglob;
53401+ ino_t inode;
53402+ dev_t device;
53403+
53404+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53405+ as we don't want a / * rule to match instead of the / object
53406+ don't do this for create lookups that call this function though, since they're looking up
53407+ on the parent and thus need globbing checks on all paths
53408+ */
53409+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53410+ newglob = GR_NO_GLOB;
53411+
53412+ spin_lock(&curr_dentry->d_lock);
53413+ inode = curr_dentry->d_inode->i_ino;
53414+ device = __get_dev(curr_dentry);
53415+ spin_unlock(&curr_dentry->d_lock);
53416+
53417+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53418+}
53419+
53420+static struct acl_object_label *
53421+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53422+ const struct acl_subject_label *subj, char *path, const int checkglob)
53423+{
53424+ struct dentry *dentry = (struct dentry *) l_dentry;
53425+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53426+ struct mount *real_mnt = real_mount(mnt);
53427+ struct acl_object_label *retval;
53428+ struct dentry *parent;
53429+
53430+ write_seqlock(&rename_lock);
53431+ br_read_lock(&vfsmount_lock);
53432+
53433+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53434+#ifdef CONFIG_NET
53435+ mnt == sock_mnt ||
53436+#endif
53437+#ifdef CONFIG_HUGETLBFS
53438+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53439+#endif
53440+ /* ignore Eric Biederman */
53441+ IS_PRIVATE(l_dentry->d_inode))) {
53442+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53443+ goto out;
53444+ }
53445+
53446+ for (;;) {
53447+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53448+ break;
53449+
53450+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53451+ if (!mnt_has_parent(real_mnt))
53452+ break;
53453+
53454+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53455+ if (retval != NULL)
53456+ goto out;
53457+
53458+ dentry = real_mnt->mnt_mountpoint;
53459+ real_mnt = real_mnt->mnt_parent;
53460+ mnt = &real_mnt->mnt;
53461+ continue;
53462+ }
53463+
53464+ parent = dentry->d_parent;
53465+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53466+ if (retval != NULL)
53467+ goto out;
53468+
53469+ dentry = parent;
53470+ }
53471+
53472+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53473+
53474+ /* real_root is pinned so we don't have to hold a reference */
53475+ if (retval == NULL)
53476+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53477+out:
53478+ br_read_unlock(&vfsmount_lock);
53479+ write_sequnlock(&rename_lock);
53480+
53481+ BUG_ON(retval == NULL);
53482+
53483+ return retval;
53484+}
53485+
53486+static __inline__ struct acl_object_label *
53487+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53488+ const struct acl_subject_label *subj)
53489+{
53490+ char *path = NULL;
53491+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53492+}
53493+
53494+static __inline__ struct acl_object_label *
53495+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53496+ const struct acl_subject_label *subj)
53497+{
53498+ char *path = NULL;
53499+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53500+}
53501+
53502+static __inline__ struct acl_object_label *
53503+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53504+ const struct acl_subject_label *subj, char *path)
53505+{
53506+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53507+}
53508+
53509+static struct acl_subject_label *
53510+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53511+ const struct acl_role_label *role)
53512+{
53513+ struct dentry *dentry = (struct dentry *) l_dentry;
53514+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53515+ struct mount *real_mnt = real_mount(mnt);
53516+ struct acl_subject_label *retval;
53517+ struct dentry *parent;
53518+
53519+ write_seqlock(&rename_lock);
53520+ br_read_lock(&vfsmount_lock);
53521+
53522+ for (;;) {
53523+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53524+ break;
53525+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53526+ if (!mnt_has_parent(real_mnt))
53527+ break;
53528+
53529+ spin_lock(&dentry->d_lock);
53530+ read_lock(&gr_inode_lock);
53531+ retval =
53532+ lookup_acl_subj_label(dentry->d_inode->i_ino,
53533+ __get_dev(dentry), role);
53534+ read_unlock(&gr_inode_lock);
53535+ spin_unlock(&dentry->d_lock);
53536+ if (retval != NULL)
53537+ goto out;
53538+
53539+ dentry = real_mnt->mnt_mountpoint;
53540+ real_mnt = real_mnt->mnt_parent;
53541+ mnt = &real_mnt->mnt;
53542+ continue;
53543+ }
53544+
53545+ spin_lock(&dentry->d_lock);
53546+ read_lock(&gr_inode_lock);
53547+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53548+ __get_dev(dentry), role);
53549+ read_unlock(&gr_inode_lock);
53550+ parent = dentry->d_parent;
53551+ spin_unlock(&dentry->d_lock);
53552+
53553+ if (retval != NULL)
53554+ goto out;
53555+
53556+ dentry = parent;
53557+ }
53558+
53559+ spin_lock(&dentry->d_lock);
53560+ read_lock(&gr_inode_lock);
53561+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53562+ __get_dev(dentry), role);
53563+ read_unlock(&gr_inode_lock);
53564+ spin_unlock(&dentry->d_lock);
53565+
53566+ if (unlikely(retval == NULL)) {
53567+ /* real_root is pinned, we don't need to hold a reference */
53568+ read_lock(&gr_inode_lock);
53569+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53570+ __get_dev(real_root.dentry), role);
53571+ read_unlock(&gr_inode_lock);
53572+ }
53573+out:
53574+ br_read_unlock(&vfsmount_lock);
53575+ write_sequnlock(&rename_lock);
53576+
53577+ BUG_ON(retval == NULL);
53578+
53579+ return retval;
53580+}
53581+
53582+static void
53583+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53584+{
53585+ struct task_struct *task = current;
53586+ const struct cred *cred = current_cred();
53587+
53588+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53589+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53590+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53591+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53592+
53593+ return;
53594+}
53595+
53596+static void
53597+gr_log_learn_id_change(const char type, const unsigned int real,
53598+ const unsigned int effective, const unsigned int fs)
53599+{
53600+ struct task_struct *task = current;
53601+ const struct cred *cred = current_cred();
53602+
53603+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53604+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53605+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53606+ type, real, effective, fs, &task->signal->saved_ip);
53607+
53608+ return;
53609+}
53610+
53611+__u32
53612+gr_search_file(const struct dentry * dentry, const __u32 mode,
53613+ const struct vfsmount * mnt)
53614+{
53615+ __u32 retval = mode;
53616+ struct acl_subject_label *curracl;
53617+ struct acl_object_label *currobj;
53618+
53619+ if (unlikely(!(gr_status & GR_READY)))
53620+ return (mode & ~GR_AUDITS);
53621+
53622+ curracl = current->acl;
53623+
53624+ currobj = chk_obj_label(dentry, mnt, curracl);
53625+ retval = currobj->mode & mode;
53626+
53627+ /* if we're opening a specified transfer file for writing
53628+ (e.g. /dev/initctl), then transfer our role to init
53629+ */
53630+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53631+ current->role->roletype & GR_ROLE_PERSIST)) {
53632+ struct task_struct *task = init_pid_ns.child_reaper;
53633+
53634+ if (task->role != current->role) {
53635+ task->acl_sp_role = 0;
53636+ task->acl_role_id = current->acl_role_id;
53637+ task->role = current->role;
53638+ rcu_read_lock();
53639+ read_lock(&grsec_exec_file_lock);
53640+ gr_apply_subject_to_task(task);
53641+ read_unlock(&grsec_exec_file_lock);
53642+ rcu_read_unlock();
53643+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53644+ }
53645+ }
53646+
53647+ if (unlikely
53648+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53649+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53650+ __u32 new_mode = mode;
53651+
53652+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53653+
53654+ retval = new_mode;
53655+
53656+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53657+ new_mode |= GR_INHERIT;
53658+
53659+ if (!(mode & GR_NOLEARN))
53660+ gr_log_learn(dentry, mnt, new_mode);
53661+ }
53662+
53663+ return retval;
53664+}
53665+
53666+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53667+ const struct dentry *parent,
53668+ const struct vfsmount *mnt)
53669+{
53670+ struct name_entry *match;
53671+ struct acl_object_label *matchpo;
53672+ struct acl_subject_label *curracl;
53673+ char *path;
53674+
53675+ if (unlikely(!(gr_status & GR_READY)))
53676+ return NULL;
53677+
53678+ preempt_disable();
53679+ path = gr_to_filename_rbac(new_dentry, mnt);
53680+ match = lookup_name_entry_create(path);
53681+
53682+ curracl = current->acl;
53683+
53684+ if (match) {
53685+ read_lock(&gr_inode_lock);
53686+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53687+ read_unlock(&gr_inode_lock);
53688+
53689+ if (matchpo) {
53690+ preempt_enable();
53691+ return matchpo;
53692+ }
53693+ }
53694+
53695+ // lookup parent
53696+
53697+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53698+
53699+ preempt_enable();
53700+ return matchpo;
53701+}
53702+
53703+__u32
53704+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53705+ const struct vfsmount * mnt, const __u32 mode)
53706+{
53707+ struct acl_object_label *matchpo;
53708+ __u32 retval;
53709+
53710+ if (unlikely(!(gr_status & GR_READY)))
53711+ return (mode & ~GR_AUDITS);
53712+
53713+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
53714+
53715+ retval = matchpo->mode & mode;
53716+
53717+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53718+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53719+ __u32 new_mode = mode;
53720+
53721+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53722+
53723+ gr_log_learn(new_dentry, mnt, new_mode);
53724+ return new_mode;
53725+ }
53726+
53727+ return retval;
53728+}
53729+
53730+__u32
53731+gr_check_link(const struct dentry * new_dentry,
53732+ const struct dentry * parent_dentry,
53733+ const struct vfsmount * parent_mnt,
53734+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53735+{
53736+ struct acl_object_label *obj;
53737+ __u32 oldmode, newmode;
53738+ __u32 needmode;
53739+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53740+ GR_DELETE | GR_INHERIT;
53741+
53742+ if (unlikely(!(gr_status & GR_READY)))
53743+ return (GR_CREATE | GR_LINK);
53744+
53745+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53746+ oldmode = obj->mode;
53747+
53748+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53749+ newmode = obj->mode;
53750+
53751+ needmode = newmode & checkmodes;
53752+
53753+ // old name for hardlink must have at least the permissions of the new name
53754+ if ((oldmode & needmode) != needmode)
53755+ goto bad;
53756+
53757+ // if old name had restrictions/auditing, make sure the new name does as well
53758+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53759+
53760+ // don't allow hardlinking of suid/sgid/fcapped files without permission
53761+ if (is_privileged_binary(old_dentry))
53762+ needmode |= GR_SETID;
53763+
53764+ if ((newmode & needmode) != needmode)
53765+ goto bad;
53766+
53767+ // enforce minimum permissions
53768+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53769+ return newmode;
53770+bad:
53771+ needmode = oldmode;
53772+ if (is_privileged_binary(old_dentry))
53773+ needmode |= GR_SETID;
53774+
53775+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53776+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53777+ return (GR_CREATE | GR_LINK);
53778+ } else if (newmode & GR_SUPPRESS)
53779+ return GR_SUPPRESS;
53780+ else
53781+ return 0;
53782+}
53783+
53784+int
53785+gr_check_hidden_task(const struct task_struct *task)
53786+{
53787+ if (unlikely(!(gr_status & GR_READY)))
53788+ return 0;
53789+
53790+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53791+ return 1;
53792+
53793+ return 0;
53794+}
53795+
53796+int
53797+gr_check_protected_task(const struct task_struct *task)
53798+{
53799+ if (unlikely(!(gr_status & GR_READY) || !task))
53800+ return 0;
53801+
53802+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53803+ task->acl != current->acl)
53804+ return 1;
53805+
53806+ return 0;
53807+}
53808+
53809+int
53810+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53811+{
53812+ struct task_struct *p;
53813+ int ret = 0;
53814+
53815+ if (unlikely(!(gr_status & GR_READY) || !pid))
53816+ return ret;
53817+
53818+ read_lock(&tasklist_lock);
53819+ do_each_pid_task(pid, type, p) {
53820+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53821+ p->acl != current->acl) {
53822+ ret = 1;
53823+ goto out;
53824+ }
53825+ } while_each_pid_task(pid, type, p);
53826+out:
53827+ read_unlock(&tasklist_lock);
53828+
53829+ return ret;
53830+}
53831+
53832+void
53833+gr_copy_label(struct task_struct *tsk)
53834+{
53835+ tsk->signal->used_accept = 0;
53836+ tsk->acl_sp_role = 0;
53837+ tsk->acl_role_id = current->acl_role_id;
53838+ tsk->acl = current->acl;
53839+ tsk->role = current->role;
53840+ tsk->signal->curr_ip = current->signal->curr_ip;
53841+ tsk->signal->saved_ip = current->signal->saved_ip;
53842+ if (current->exec_file)
53843+ get_file(current->exec_file);
53844+ tsk->exec_file = current->exec_file;
53845+ tsk->is_writable = current->is_writable;
53846+ if (unlikely(current->signal->used_accept)) {
53847+ current->signal->curr_ip = 0;
53848+ current->signal->saved_ip = 0;
53849+ }
53850+
53851+ return;
53852+}
53853+
53854+static void
53855+gr_set_proc_res(struct task_struct *task)
53856+{
53857+ struct acl_subject_label *proc;
53858+ unsigned short i;
53859+
53860+ proc = task->acl;
53861+
53862+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53863+ return;
53864+
53865+ for (i = 0; i < RLIM_NLIMITS; i++) {
53866+ if (!(proc->resmask & (1 << i)))
53867+ continue;
53868+
53869+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53870+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53871+ }
53872+
53873+ return;
53874+}
53875+
53876+extern int __gr_process_user_ban(struct user_struct *user);
53877+
53878+int
53879+gr_check_user_change(int real, int effective, int fs)
53880+{
53881+ unsigned int i;
53882+ __u16 num;
53883+ uid_t *uidlist;
53884+ int curuid;
53885+ int realok = 0;
53886+ int effectiveok = 0;
53887+ int fsok = 0;
53888+
53889+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53890+ struct user_struct *user;
53891+
53892+ if (real == -1)
53893+ goto skipit;
53894+
53895+ user = find_user(real);
53896+ if (user == NULL)
53897+ goto skipit;
53898+
53899+ if (__gr_process_user_ban(user)) {
53900+ /* for find_user */
53901+ free_uid(user);
53902+ return 1;
53903+ }
53904+
53905+ /* for find_user */
53906+ free_uid(user);
53907+
53908+skipit:
53909+#endif
53910+
53911+ if (unlikely(!(gr_status & GR_READY)))
53912+ return 0;
53913+
53914+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53915+ gr_log_learn_id_change('u', real, effective, fs);
53916+
53917+ num = current->acl->user_trans_num;
53918+ uidlist = current->acl->user_transitions;
53919+
53920+ if (uidlist == NULL)
53921+ return 0;
53922+
53923+ if (real == -1)
53924+ realok = 1;
53925+ if (effective == -1)
53926+ effectiveok = 1;
53927+ if (fs == -1)
53928+ fsok = 1;
53929+
53930+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
53931+ for (i = 0; i < num; i++) {
53932+ curuid = (int)uidlist[i];
53933+ if (real == curuid)
53934+ realok = 1;
53935+ if (effective == curuid)
53936+ effectiveok = 1;
53937+ if (fs == curuid)
53938+ fsok = 1;
53939+ }
53940+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
53941+ for (i = 0; i < num; i++) {
53942+ curuid = (int)uidlist[i];
53943+ if (real == curuid)
53944+ break;
53945+ if (effective == curuid)
53946+ break;
53947+ if (fs == curuid)
53948+ break;
53949+ }
53950+ /* not in deny list */
53951+ if (i == num) {
53952+ realok = 1;
53953+ effectiveok = 1;
53954+ fsok = 1;
53955+ }
53956+ }
53957+
53958+ if (realok && effectiveok && fsok)
53959+ return 0;
53960+ else {
53961+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53962+ return 1;
53963+ }
53964+}
53965+
53966+int
53967+gr_check_group_change(int real, int effective, int fs)
53968+{
53969+ unsigned int i;
53970+ __u16 num;
53971+ gid_t *gidlist;
53972+ int curgid;
53973+ int realok = 0;
53974+ int effectiveok = 0;
53975+ int fsok = 0;
53976+
53977+ if (unlikely(!(gr_status & GR_READY)))
53978+ return 0;
53979+
53980+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53981+ gr_log_learn_id_change('g', real, effective, fs);
53982+
53983+ num = current->acl->group_trans_num;
53984+ gidlist = current->acl->group_transitions;
53985+
53986+ if (gidlist == NULL)
53987+ return 0;
53988+
53989+ if (real == -1)
53990+ realok = 1;
53991+ if (effective == -1)
53992+ effectiveok = 1;
53993+ if (fs == -1)
53994+ fsok = 1;
53995+
53996+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
53997+ for (i = 0; i < num; i++) {
53998+ curgid = (int)gidlist[i];
53999+ if (real == curgid)
54000+ realok = 1;
54001+ if (effective == curgid)
54002+ effectiveok = 1;
54003+ if (fs == curgid)
54004+ fsok = 1;
54005+ }
54006+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
54007+ for (i = 0; i < num; i++) {
54008+ curgid = (int)gidlist[i];
54009+ if (real == curgid)
54010+ break;
54011+ if (effective == curgid)
54012+ break;
54013+ if (fs == curgid)
54014+ break;
54015+ }
54016+ /* not in deny list */
54017+ if (i == num) {
54018+ realok = 1;
54019+ effectiveok = 1;
54020+ fsok = 1;
54021+ }
54022+ }
54023+
54024+ if (realok && effectiveok && fsok)
54025+ return 0;
54026+ else {
54027+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54028+ return 1;
54029+ }
54030+}
54031+
54032+extern int gr_acl_is_capable(const int cap);
54033+
54034+void
54035+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54036+{
54037+ struct acl_role_label *role = task->role;
54038+ struct acl_subject_label *subj = NULL;
54039+ struct acl_object_label *obj;
54040+ struct file *filp;
54041+
54042+ if (unlikely(!(gr_status & GR_READY)))
54043+ return;
54044+
54045+ filp = task->exec_file;
54046+
54047+ /* kernel process, we'll give them the kernel role */
54048+ if (unlikely(!filp)) {
54049+ task->role = kernel_role;
54050+ task->acl = kernel_role->root_label;
54051+ return;
54052+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54053+ role = lookup_acl_role_label(task, uid, gid);
54054+
54055+ /* don't change the role if we're not a privileged process */
54056+ if (role && task->role != role &&
54057+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54058+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54059+ return;
54060+
54061+ /* perform subject lookup in possibly new role
54062+ we can use this result below in the case where role == task->role
54063+ */
54064+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54065+
54066+ /* if we changed uid/gid, but result in the same role
54067+ and are using inheritance, don't lose the inherited subject
54068+ if current subject is other than what normal lookup
54069+ would result in, we arrived via inheritance, don't
54070+ lose subject
54071+ */
54072+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54073+ (subj == task->acl)))
54074+ task->acl = subj;
54075+
54076+ task->role = role;
54077+
54078+ task->is_writable = 0;
54079+
54080+ /* ignore additional mmap checks for processes that are writable
54081+ by the default ACL */
54082+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54083+ if (unlikely(obj->mode & GR_WRITE))
54084+ task->is_writable = 1;
54085+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54086+ if (unlikely(obj->mode & GR_WRITE))
54087+ task->is_writable = 1;
54088+
54089+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54090+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54091+#endif
54092+
54093+ gr_set_proc_res(task);
54094+
54095+ return;
54096+}
54097+
54098+int
54099+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54100+ const int unsafe_flags)
54101+{
54102+ struct task_struct *task = current;
54103+ struct acl_subject_label *newacl;
54104+ struct acl_object_label *obj;
54105+ __u32 retmode;
54106+
54107+ if (unlikely(!(gr_status & GR_READY)))
54108+ return 0;
54109+
54110+ newacl = chk_subj_label(dentry, mnt, task->role);
54111+
54112+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54113+ did an exec
54114+ */
54115+ rcu_read_lock();
54116+ read_lock(&tasklist_lock);
54117+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54118+ (task->parent->acl->mode & GR_POVERRIDE))) {
54119+ read_unlock(&tasklist_lock);
54120+ rcu_read_unlock();
54121+ goto skip_check;
54122+ }
54123+ read_unlock(&tasklist_lock);
54124+ rcu_read_unlock();
54125+
54126+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54127+ !(task->role->roletype & GR_ROLE_GOD) &&
54128+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54129+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54130+ if (unsafe_flags & LSM_UNSAFE_SHARE)
54131+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54132+ else
54133+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54134+ return -EACCES;
54135+ }
54136+
54137+skip_check:
54138+
54139+ obj = chk_obj_label(dentry, mnt, task->acl);
54140+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54141+
54142+ if (!(task->acl->mode & GR_INHERITLEARN) &&
54143+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54144+ if (obj->nested)
54145+ task->acl = obj->nested;
54146+ else
54147+ task->acl = newacl;
54148+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54149+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54150+
54151+ task->is_writable = 0;
54152+
54153+ /* ignore additional mmap checks for processes that are writable
54154+ by the default ACL */
54155+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
54156+ if (unlikely(obj->mode & GR_WRITE))
54157+ task->is_writable = 1;
54158+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
54159+ if (unlikely(obj->mode & GR_WRITE))
54160+ task->is_writable = 1;
54161+
54162+ gr_set_proc_res(task);
54163+
54164+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54165+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54166+#endif
54167+ return 0;
54168+}
54169+
54170+/* always called with valid inodev ptr */
54171+static void
54172+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54173+{
54174+ struct acl_object_label *matchpo;
54175+ struct acl_subject_label *matchps;
54176+ struct acl_subject_label *subj;
54177+ struct acl_role_label *role;
54178+ unsigned int x;
54179+
54180+ FOR_EACH_ROLE_START(role)
54181+ FOR_EACH_SUBJECT_START(role, subj, x)
54182+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54183+ matchpo->mode |= GR_DELETED;
54184+ FOR_EACH_SUBJECT_END(subj,x)
54185+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
54186+ if (subj->inode == ino && subj->device == dev)
54187+ subj->mode |= GR_DELETED;
54188+ FOR_EACH_NESTED_SUBJECT_END(subj)
54189+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54190+ matchps->mode |= GR_DELETED;
54191+ FOR_EACH_ROLE_END(role)
54192+
54193+ inodev->nentry->deleted = 1;
54194+
54195+ return;
54196+}
54197+
54198+void
54199+gr_handle_delete(const ino_t ino, const dev_t dev)
54200+{
54201+ struct inodev_entry *inodev;
54202+
54203+ if (unlikely(!(gr_status & GR_READY)))
54204+ return;
54205+
54206+ write_lock(&gr_inode_lock);
54207+ inodev = lookup_inodev_entry(ino, dev);
54208+ if (inodev != NULL)
54209+ do_handle_delete(inodev, ino, dev);
54210+ write_unlock(&gr_inode_lock);
54211+
54212+ return;
54213+}
54214+
54215+static void
54216+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54217+ const ino_t newinode, const dev_t newdevice,
54218+ struct acl_subject_label *subj)
54219+{
54220+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54221+ struct acl_object_label *match;
54222+
54223+ match = subj->obj_hash[index];
54224+
54225+ while (match && (match->inode != oldinode ||
54226+ match->device != olddevice ||
54227+ !(match->mode & GR_DELETED)))
54228+ match = match->next;
54229+
54230+ if (match && (match->inode == oldinode)
54231+ && (match->device == olddevice)
54232+ && (match->mode & GR_DELETED)) {
54233+ if (match->prev == NULL) {
54234+ subj->obj_hash[index] = match->next;
54235+ if (match->next != NULL)
54236+ match->next->prev = NULL;
54237+ } else {
54238+ match->prev->next = match->next;
54239+ if (match->next != NULL)
54240+ match->next->prev = match->prev;
54241+ }
54242+ match->prev = NULL;
54243+ match->next = NULL;
54244+ match->inode = newinode;
54245+ match->device = newdevice;
54246+ match->mode &= ~GR_DELETED;
54247+
54248+ insert_acl_obj_label(match, subj);
54249+ }
54250+
54251+ return;
54252+}
54253+
54254+static void
54255+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54256+ const ino_t newinode, const dev_t newdevice,
54257+ struct acl_role_label *role)
54258+{
54259+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54260+ struct acl_subject_label *match;
54261+
54262+ match = role->subj_hash[index];
54263+
54264+ while (match && (match->inode != oldinode ||
54265+ match->device != olddevice ||
54266+ !(match->mode & GR_DELETED)))
54267+ match = match->next;
54268+
54269+ if (match && (match->inode == oldinode)
54270+ && (match->device == olddevice)
54271+ && (match->mode & GR_DELETED)) {
54272+ if (match->prev == NULL) {
54273+ role->subj_hash[index] = match->next;
54274+ if (match->next != NULL)
54275+ match->next->prev = NULL;
54276+ } else {
54277+ match->prev->next = match->next;
54278+ if (match->next != NULL)
54279+ match->next->prev = match->prev;
54280+ }
54281+ match->prev = NULL;
54282+ match->next = NULL;
54283+ match->inode = newinode;
54284+ match->device = newdevice;
54285+ match->mode &= ~GR_DELETED;
54286+
54287+ insert_acl_subj_label(match, role);
54288+ }
54289+
54290+ return;
54291+}
54292+
54293+static void
54294+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54295+ const ino_t newinode, const dev_t newdevice)
54296+{
54297+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54298+ struct inodev_entry *match;
54299+
54300+ match = inodev_set.i_hash[index];
54301+
54302+ while (match && (match->nentry->inode != oldinode ||
54303+ match->nentry->device != olddevice || !match->nentry->deleted))
54304+ match = match->next;
54305+
54306+ if (match && (match->nentry->inode == oldinode)
54307+ && (match->nentry->device == olddevice) &&
54308+ match->nentry->deleted) {
54309+ if (match->prev == NULL) {
54310+ inodev_set.i_hash[index] = match->next;
54311+ if (match->next != NULL)
54312+ match->next->prev = NULL;
54313+ } else {
54314+ match->prev->next = match->next;
54315+ if (match->next != NULL)
54316+ match->next->prev = match->prev;
54317+ }
54318+ match->prev = NULL;
54319+ match->next = NULL;
54320+ match->nentry->inode = newinode;
54321+ match->nentry->device = newdevice;
54322+ match->nentry->deleted = 0;
54323+
54324+ insert_inodev_entry(match);
54325+ }
54326+
54327+ return;
54328+}
54329+
54330+static void
54331+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54332+{
54333+ struct acl_subject_label *subj;
54334+ struct acl_role_label *role;
54335+ unsigned int x;
54336+
54337+ FOR_EACH_ROLE_START(role)
54338+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54339+
54340+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
54341+ if ((subj->inode == ino) && (subj->device == dev)) {
54342+ subj->inode = ino;
54343+ subj->device = dev;
54344+ }
54345+ FOR_EACH_NESTED_SUBJECT_END(subj)
54346+ FOR_EACH_SUBJECT_START(role, subj, x)
54347+ update_acl_obj_label(matchn->inode, matchn->device,
54348+ ino, dev, subj);
54349+ FOR_EACH_SUBJECT_END(subj,x)
54350+ FOR_EACH_ROLE_END(role)
54351+
54352+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54353+
54354+ return;
54355+}
54356+
54357+static void
54358+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54359+ const struct vfsmount *mnt)
54360+{
54361+ ino_t ino = dentry->d_inode->i_ino;
54362+ dev_t dev = __get_dev(dentry);
54363+
54364+ __do_handle_create(matchn, ino, dev);
54365+
54366+ return;
54367+}
54368+
54369+void
54370+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54371+{
54372+ struct name_entry *matchn;
54373+
54374+ if (unlikely(!(gr_status & GR_READY)))
54375+ return;
54376+
54377+ preempt_disable();
54378+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54379+
54380+ if (unlikely((unsigned long)matchn)) {
54381+ write_lock(&gr_inode_lock);
54382+ do_handle_create(matchn, dentry, mnt);
54383+ write_unlock(&gr_inode_lock);
54384+ }
54385+ preempt_enable();
54386+
54387+ return;
54388+}
54389+
54390+void
54391+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54392+{
54393+ struct name_entry *matchn;
54394+
54395+ if (unlikely(!(gr_status & GR_READY)))
54396+ return;
54397+
54398+ preempt_disable();
54399+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54400+
54401+ if (unlikely((unsigned long)matchn)) {
54402+ write_lock(&gr_inode_lock);
54403+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54404+ write_unlock(&gr_inode_lock);
54405+ }
54406+ preempt_enable();
54407+
54408+ return;
54409+}
54410+
54411+void
54412+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54413+ struct dentry *old_dentry,
54414+ struct dentry *new_dentry,
54415+ struct vfsmount *mnt, const __u8 replace)
54416+{
54417+ struct name_entry *matchn;
54418+ struct inodev_entry *inodev;
54419+ struct inode *inode = new_dentry->d_inode;
54420+ ino_t old_ino = old_dentry->d_inode->i_ino;
54421+ dev_t old_dev = __get_dev(old_dentry);
54422+
54423+ /* vfs_rename swaps the name and parent link for old_dentry and
54424+ new_dentry
54425+ at this point, old_dentry has the new name, parent link, and inode
54426+ for the renamed file
54427+ if a file is being replaced by a rename, new_dentry has the inode
54428+ and name for the replaced file
54429+ */
54430+
54431+ if (unlikely(!(gr_status & GR_READY)))
54432+ return;
54433+
54434+ preempt_disable();
54435+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54436+
54437+ /* we wouldn't have to check d_inode if it weren't for
54438+ NFS silly-renaming
54439+ */
54440+
54441+ write_lock(&gr_inode_lock);
54442+ if (unlikely(replace && inode)) {
54443+ ino_t new_ino = inode->i_ino;
54444+ dev_t new_dev = __get_dev(new_dentry);
54445+
54446+ inodev = lookup_inodev_entry(new_ino, new_dev);
54447+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54448+ do_handle_delete(inodev, new_ino, new_dev);
54449+ }
54450+
54451+ inodev = lookup_inodev_entry(old_ino, old_dev);
54452+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54453+ do_handle_delete(inodev, old_ino, old_dev);
54454+
54455+ if (unlikely((unsigned long)matchn))
54456+ do_handle_create(matchn, old_dentry, mnt);
54457+
54458+ write_unlock(&gr_inode_lock);
54459+ preempt_enable();
54460+
54461+ return;
54462+}
54463+
54464+static int
54465+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54466+ unsigned char **sum)
54467+{
54468+ struct acl_role_label *r;
54469+ struct role_allowed_ip *ipp;
54470+ struct role_transition *trans;
54471+ unsigned int i;
54472+ int found = 0;
54473+ u32 curr_ip = current->signal->curr_ip;
54474+
54475+ current->signal->saved_ip = curr_ip;
54476+
54477+ /* check transition table */
54478+
54479+ for (trans = current->role->transitions; trans; trans = trans->next) {
54480+ if (!strcmp(rolename, trans->rolename)) {
54481+ found = 1;
54482+ break;
54483+ }
54484+ }
54485+
54486+ if (!found)
54487+ return 0;
54488+
54489+ /* handle special roles that do not require authentication
54490+ and check ip */
54491+
54492+ FOR_EACH_ROLE_START(r)
54493+ if (!strcmp(rolename, r->rolename) &&
54494+ (r->roletype & GR_ROLE_SPECIAL)) {
54495+ found = 0;
54496+ if (r->allowed_ips != NULL) {
54497+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54498+ if ((ntohl(curr_ip) & ipp->netmask) ==
54499+ (ntohl(ipp->addr) & ipp->netmask))
54500+ found = 1;
54501+ }
54502+ } else
54503+ found = 2;
54504+ if (!found)
54505+ return 0;
54506+
54507+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54508+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54509+ *salt = NULL;
54510+ *sum = NULL;
54511+ return 1;
54512+ }
54513+ }
54514+ FOR_EACH_ROLE_END(r)
54515+
54516+ for (i = 0; i < num_sprole_pws; i++) {
54517+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54518+ *salt = acl_special_roles[i]->salt;
54519+ *sum = acl_special_roles[i]->sum;
54520+ return 1;
54521+ }
54522+ }
54523+
54524+ return 0;
54525+}
54526+
54527+static void
54528+assign_special_role(char *rolename)
54529+{
54530+ struct acl_object_label *obj;
54531+ struct acl_role_label *r;
54532+ struct acl_role_label *assigned = NULL;
54533+ struct task_struct *tsk;
54534+ struct file *filp;
54535+
54536+ FOR_EACH_ROLE_START(r)
54537+ if (!strcmp(rolename, r->rolename) &&
54538+ (r->roletype & GR_ROLE_SPECIAL)) {
54539+ assigned = r;
54540+ break;
54541+ }
54542+ FOR_EACH_ROLE_END(r)
54543+
54544+ if (!assigned)
54545+ return;
54546+
54547+ read_lock(&tasklist_lock);
54548+ read_lock(&grsec_exec_file_lock);
54549+
54550+ tsk = current->real_parent;
54551+ if (tsk == NULL)
54552+ goto out_unlock;
54553+
54554+ filp = tsk->exec_file;
54555+ if (filp == NULL)
54556+ goto out_unlock;
54557+
54558+ tsk->is_writable = 0;
54559+
54560+ tsk->acl_sp_role = 1;
54561+ tsk->acl_role_id = ++acl_sp_role_value;
54562+ tsk->role = assigned;
54563+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54564+
54565+ /* ignore additional mmap checks for processes that are writable
54566+ by the default ACL */
54567+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54568+ if (unlikely(obj->mode & GR_WRITE))
54569+ tsk->is_writable = 1;
54570+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54571+ if (unlikely(obj->mode & GR_WRITE))
54572+ tsk->is_writable = 1;
54573+
54574+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54575+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54576+#endif
54577+
54578+out_unlock:
54579+ read_unlock(&grsec_exec_file_lock);
54580+ read_unlock(&tasklist_lock);
54581+ return;
54582+}
54583+
54584+int gr_check_secure_terminal(struct task_struct *task)
54585+{
54586+ struct task_struct *p, *p2, *p3;
54587+ struct files_struct *files;
54588+ struct fdtable *fdt;
54589+ struct file *our_file = NULL, *file;
54590+ int i;
54591+
54592+ if (task->signal->tty == NULL)
54593+ return 1;
54594+
54595+ files = get_files_struct(task);
54596+ if (files != NULL) {
54597+ rcu_read_lock();
54598+ fdt = files_fdtable(files);
54599+ for (i=0; i < fdt->max_fds; i++) {
54600+ file = fcheck_files(files, i);
54601+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54602+ get_file(file);
54603+ our_file = file;
54604+ }
54605+ }
54606+ rcu_read_unlock();
54607+ put_files_struct(files);
54608+ }
54609+
54610+ if (our_file == NULL)
54611+ return 1;
54612+
54613+ read_lock(&tasklist_lock);
54614+ do_each_thread(p2, p) {
54615+ files = get_files_struct(p);
54616+ if (files == NULL ||
54617+ (p->signal && p->signal->tty == task->signal->tty)) {
54618+ if (files != NULL)
54619+ put_files_struct(files);
54620+ continue;
54621+ }
54622+ rcu_read_lock();
54623+ fdt = files_fdtable(files);
54624+ for (i=0; i < fdt->max_fds; i++) {
54625+ file = fcheck_files(files, i);
54626+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54627+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54628+ p3 = task;
54629+ while (p3->pid > 0) {
54630+ if (p3 == p)
54631+ break;
54632+ p3 = p3->real_parent;
54633+ }
54634+ if (p3 == p)
54635+ break;
54636+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54637+ gr_handle_alertkill(p);
54638+ rcu_read_unlock();
54639+ put_files_struct(files);
54640+ read_unlock(&tasklist_lock);
54641+ fput(our_file);
54642+ return 0;
54643+ }
54644+ }
54645+ rcu_read_unlock();
54646+ put_files_struct(files);
54647+ } while_each_thread(p2, p);
54648+ read_unlock(&tasklist_lock);
54649+
54650+ fput(our_file);
54651+ return 1;
54652+}
54653+
54654+static int gr_rbac_disable(void *unused)
54655+{
54656+ pax_open_kernel();
54657+ gr_status &= ~GR_READY;
54658+ pax_close_kernel();
54659+
54660+ return 0;
54661+}
54662+
54663+ssize_t
54664+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54665+{
54666+ struct gr_arg_wrapper uwrap;
54667+ unsigned char *sprole_salt = NULL;
54668+ unsigned char *sprole_sum = NULL;
54669+ int error = sizeof (struct gr_arg_wrapper);
54670+ int error2 = 0;
54671+
54672+ mutex_lock(&gr_dev_mutex);
54673+
54674+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54675+ error = -EPERM;
54676+ goto out;
54677+ }
54678+
54679+ if (count != sizeof (struct gr_arg_wrapper)) {
54680+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54681+ error = -EINVAL;
54682+ goto out;
54683+ }
54684+
54685+
54686+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54687+ gr_auth_expires = 0;
54688+ gr_auth_attempts = 0;
54689+ }
54690+
54691+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54692+ error = -EFAULT;
54693+ goto out;
54694+ }
54695+
54696+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54697+ error = -EINVAL;
54698+ goto out;
54699+ }
54700+
54701+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54702+ error = -EFAULT;
54703+ goto out;
54704+ }
54705+
54706+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54707+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54708+ time_after(gr_auth_expires, get_seconds())) {
54709+ error = -EBUSY;
54710+ goto out;
54711+ }
54712+
54713+ /* if non-root trying to do anything other than use a special role,
54714+ do not attempt authentication, do not count towards authentication
54715+ locking
54716+ */
54717+
54718+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54719+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54720+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54721+ error = -EPERM;
54722+ goto out;
54723+ }
54724+
54725+ /* ensure pw and special role name are null terminated */
54726+
54727+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54728+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54729+
54730+ /* Okay.
54731+ * We have our enough of the argument structure..(we have yet
54732+ * to copy_from_user the tables themselves) . Copy the tables
54733+ * only if we need them, i.e. for loading operations. */
54734+
54735+ switch (gr_usermode->mode) {
54736+ case GR_STATUS:
54737+ if (gr_status & GR_READY) {
54738+ error = 1;
54739+ if (!gr_check_secure_terminal(current))
54740+ error = 3;
54741+ } else
54742+ error = 2;
54743+ goto out;
54744+ case GR_SHUTDOWN:
54745+ if ((gr_status & GR_READY)
54746+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54747+ stop_machine(gr_rbac_disable, NULL, NULL);
54748+ free_variables();
54749+ memset(gr_usermode, 0, sizeof (struct gr_arg));
54750+ memset(gr_system_salt, 0, GR_SALT_LEN);
54751+ memset(gr_system_sum, 0, GR_SHA_LEN);
54752+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54753+ } else if (gr_status & GR_READY) {
54754+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54755+ error = -EPERM;
54756+ } else {
54757+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54758+ error = -EAGAIN;
54759+ }
54760+ break;
54761+ case GR_ENABLE:
54762+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54763+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54764+ else {
54765+ if (gr_status & GR_READY)
54766+ error = -EAGAIN;
54767+ else
54768+ error = error2;
54769+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54770+ }
54771+ break;
54772+ case GR_RELOAD:
54773+ if (!(gr_status & GR_READY)) {
54774+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54775+ error = -EAGAIN;
54776+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54777+ stop_machine(gr_rbac_disable, NULL, NULL);
54778+ free_variables();
54779+ error2 = gracl_init(gr_usermode);
54780+ if (!error2)
54781+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54782+ else {
54783+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54784+ error = error2;
54785+ }
54786+ } else {
54787+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54788+ error = -EPERM;
54789+ }
54790+ break;
54791+ case GR_SEGVMOD:
54792+ if (unlikely(!(gr_status & GR_READY))) {
54793+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54794+ error = -EAGAIN;
54795+ break;
54796+ }
54797+
54798+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54799+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54800+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54801+ struct acl_subject_label *segvacl;
54802+ segvacl =
54803+ lookup_acl_subj_label(gr_usermode->segv_inode,
54804+ gr_usermode->segv_device,
54805+ current->role);
54806+ if (segvacl) {
54807+ segvacl->crashes = 0;
54808+ segvacl->expires = 0;
54809+ }
54810+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54811+ gr_remove_uid(gr_usermode->segv_uid);
54812+ }
54813+ } else {
54814+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54815+ error = -EPERM;
54816+ }
54817+ break;
54818+ case GR_SPROLE:
54819+ case GR_SPROLEPAM:
54820+ if (unlikely(!(gr_status & GR_READY))) {
54821+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54822+ error = -EAGAIN;
54823+ break;
54824+ }
54825+
54826+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54827+ current->role->expires = 0;
54828+ current->role->auth_attempts = 0;
54829+ }
54830+
54831+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54832+ time_after(current->role->expires, get_seconds())) {
54833+ error = -EBUSY;
54834+ goto out;
54835+ }
54836+
54837+ if (lookup_special_role_auth
54838+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54839+ && ((!sprole_salt && !sprole_sum)
54840+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54841+ char *p = "";
54842+ assign_special_role(gr_usermode->sp_role);
54843+ read_lock(&tasklist_lock);
54844+ if (current->real_parent)
54845+ p = current->real_parent->role->rolename;
54846+ read_unlock(&tasklist_lock);
54847+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54848+ p, acl_sp_role_value);
54849+ } else {
54850+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54851+ error = -EPERM;
54852+ if(!(current->role->auth_attempts++))
54853+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54854+
54855+ goto out;
54856+ }
54857+ break;
54858+ case GR_UNSPROLE:
54859+ if (unlikely(!(gr_status & GR_READY))) {
54860+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54861+ error = -EAGAIN;
54862+ break;
54863+ }
54864+
54865+ if (current->role->roletype & GR_ROLE_SPECIAL) {
54866+ char *p = "";
54867+ int i = 0;
54868+
54869+ read_lock(&tasklist_lock);
54870+ if (current->real_parent) {
54871+ p = current->real_parent->role->rolename;
54872+ i = current->real_parent->acl_role_id;
54873+ }
54874+ read_unlock(&tasklist_lock);
54875+
54876+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54877+ gr_set_acls(1);
54878+ } else {
54879+ error = -EPERM;
54880+ goto out;
54881+ }
54882+ break;
54883+ default:
54884+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54885+ error = -EINVAL;
54886+ break;
54887+ }
54888+
54889+ if (error != -EPERM)
54890+ goto out;
54891+
54892+ if(!(gr_auth_attempts++))
54893+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54894+
54895+ out:
54896+ mutex_unlock(&gr_dev_mutex);
54897+ return error;
54898+}
54899+
54900+/* must be called with
54901+ rcu_read_lock();
54902+ read_lock(&tasklist_lock);
54903+ read_lock(&grsec_exec_file_lock);
54904+*/
54905+int gr_apply_subject_to_task(struct task_struct *task)
54906+{
54907+ struct acl_object_label *obj;
54908+ char *tmpname;
54909+ struct acl_subject_label *tmpsubj;
54910+ struct file *filp;
54911+ struct name_entry *nmatch;
54912+
54913+ filp = task->exec_file;
54914+ if (filp == NULL)
54915+ return 0;
54916+
54917+ /* the following is to apply the correct subject
54918+ on binaries running when the RBAC system
54919+ is enabled, when the binaries have been
54920+ replaced or deleted since their execution
54921+ -----
54922+ when the RBAC system starts, the inode/dev
54923+ from exec_file will be one the RBAC system
54924+ is unaware of. It only knows the inode/dev
54925+ of the present file on disk, or the absence
54926+ of it.
54927+ */
54928+ preempt_disable();
54929+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54930+
54931+ nmatch = lookup_name_entry(tmpname);
54932+ preempt_enable();
54933+ tmpsubj = NULL;
54934+ if (nmatch) {
54935+ if (nmatch->deleted)
54936+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54937+ else
54938+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54939+ if (tmpsubj != NULL)
54940+ task->acl = tmpsubj;
54941+ }
54942+ if (tmpsubj == NULL)
54943+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54944+ task->role);
54945+ if (task->acl) {
54946+ task->is_writable = 0;
54947+ /* ignore additional mmap checks for processes that are writable
54948+ by the default ACL */
54949+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54950+ if (unlikely(obj->mode & GR_WRITE))
54951+ task->is_writable = 1;
54952+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54953+ if (unlikely(obj->mode & GR_WRITE))
54954+ task->is_writable = 1;
54955+
54956+ gr_set_proc_res(task);
54957+
54958+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54959+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54960+#endif
54961+ } else {
54962+ return 1;
54963+ }
54964+
54965+ return 0;
54966+}
54967+
54968+int
54969+gr_set_acls(const int type)
54970+{
54971+ struct task_struct *task, *task2;
54972+ struct acl_role_label *role = current->role;
54973+ __u16 acl_role_id = current->acl_role_id;
54974+ const struct cred *cred;
54975+ int ret;
54976+
54977+ rcu_read_lock();
54978+ read_lock(&tasklist_lock);
54979+ read_lock(&grsec_exec_file_lock);
54980+ do_each_thread(task2, task) {
54981+ /* check to see if we're called from the exit handler,
54982+ if so, only replace ACLs that have inherited the admin
54983+ ACL */
54984+
54985+ if (type && (task->role != role ||
54986+ task->acl_role_id != acl_role_id))
54987+ continue;
54988+
54989+ task->acl_role_id = 0;
54990+ task->acl_sp_role = 0;
54991+
54992+ if (task->exec_file) {
54993+ cred = __task_cred(task);
54994+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54995+ ret = gr_apply_subject_to_task(task);
54996+ if (ret) {
54997+ read_unlock(&grsec_exec_file_lock);
54998+ read_unlock(&tasklist_lock);
54999+ rcu_read_unlock();
55000+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55001+ return ret;
55002+ }
55003+ } else {
55004+ // it's a kernel process
55005+ task->role = kernel_role;
55006+ task->acl = kernel_role->root_label;
55007+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55008+ task->acl->mode &= ~GR_PROCFIND;
55009+#endif
55010+ }
55011+ } while_each_thread(task2, task);
55012+ read_unlock(&grsec_exec_file_lock);
55013+ read_unlock(&tasklist_lock);
55014+ rcu_read_unlock();
55015+
55016+ return 0;
55017+}
55018+
55019+void
55020+gr_learn_resource(const struct task_struct *task,
55021+ const int res, const unsigned long wanted, const int gt)
55022+{
55023+ struct acl_subject_label *acl;
55024+ const struct cred *cred;
55025+
55026+ if (unlikely((gr_status & GR_READY) &&
55027+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55028+ goto skip_reslog;
55029+
55030+#ifdef CONFIG_GRKERNSEC_RESLOG
55031+ gr_log_resource(task, res, wanted, gt);
55032+#endif
55033+ skip_reslog:
55034+
55035+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55036+ return;
55037+
55038+ acl = task->acl;
55039+
55040+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55041+ !(acl->resmask & (1 << (unsigned short) res))))
55042+ return;
55043+
55044+ if (wanted >= acl->res[res].rlim_cur) {
55045+ unsigned long res_add;
55046+
55047+ res_add = wanted;
55048+ switch (res) {
55049+ case RLIMIT_CPU:
55050+ res_add += GR_RLIM_CPU_BUMP;
55051+ break;
55052+ case RLIMIT_FSIZE:
55053+ res_add += GR_RLIM_FSIZE_BUMP;
55054+ break;
55055+ case RLIMIT_DATA:
55056+ res_add += GR_RLIM_DATA_BUMP;
55057+ break;
55058+ case RLIMIT_STACK:
55059+ res_add += GR_RLIM_STACK_BUMP;
55060+ break;
55061+ case RLIMIT_CORE:
55062+ res_add += GR_RLIM_CORE_BUMP;
55063+ break;
55064+ case RLIMIT_RSS:
55065+ res_add += GR_RLIM_RSS_BUMP;
55066+ break;
55067+ case RLIMIT_NPROC:
55068+ res_add += GR_RLIM_NPROC_BUMP;
55069+ break;
55070+ case RLIMIT_NOFILE:
55071+ res_add += GR_RLIM_NOFILE_BUMP;
55072+ break;
55073+ case RLIMIT_MEMLOCK:
55074+ res_add += GR_RLIM_MEMLOCK_BUMP;
55075+ break;
55076+ case RLIMIT_AS:
55077+ res_add += GR_RLIM_AS_BUMP;
55078+ break;
55079+ case RLIMIT_LOCKS:
55080+ res_add += GR_RLIM_LOCKS_BUMP;
55081+ break;
55082+ case RLIMIT_SIGPENDING:
55083+ res_add += GR_RLIM_SIGPENDING_BUMP;
55084+ break;
55085+ case RLIMIT_MSGQUEUE:
55086+ res_add += GR_RLIM_MSGQUEUE_BUMP;
55087+ break;
55088+ case RLIMIT_NICE:
55089+ res_add += GR_RLIM_NICE_BUMP;
55090+ break;
55091+ case RLIMIT_RTPRIO:
55092+ res_add += GR_RLIM_RTPRIO_BUMP;
55093+ break;
55094+ case RLIMIT_RTTIME:
55095+ res_add += GR_RLIM_RTTIME_BUMP;
55096+ break;
55097+ }
55098+
55099+ acl->res[res].rlim_cur = res_add;
55100+
55101+ if (wanted > acl->res[res].rlim_max)
55102+ acl->res[res].rlim_max = res_add;
55103+
55104+ /* only log the subject filename, since resource logging is supported for
55105+ single-subject learning only */
55106+ rcu_read_lock();
55107+ cred = __task_cred(task);
55108+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55109+ task->role->roletype, cred->uid, cred->gid, acl->filename,
55110+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55111+ "", (unsigned long) res, &task->signal->saved_ip);
55112+ rcu_read_unlock();
55113+ }
55114+
55115+ return;
55116+}
55117+
55118+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55119+void
55120+pax_set_initial_flags(struct linux_binprm *bprm)
55121+{
55122+ struct task_struct *task = current;
55123+ struct acl_subject_label *proc;
55124+ unsigned long flags;
55125+
55126+ if (unlikely(!(gr_status & GR_READY)))
55127+ return;
55128+
55129+ flags = pax_get_flags(task);
55130+
55131+ proc = task->acl;
55132+
55133+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55134+ flags &= ~MF_PAX_PAGEEXEC;
55135+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55136+ flags &= ~MF_PAX_SEGMEXEC;
55137+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55138+ flags &= ~MF_PAX_RANDMMAP;
55139+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55140+ flags &= ~MF_PAX_EMUTRAMP;
55141+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55142+ flags &= ~MF_PAX_MPROTECT;
55143+
55144+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55145+ flags |= MF_PAX_PAGEEXEC;
55146+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55147+ flags |= MF_PAX_SEGMEXEC;
55148+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55149+ flags |= MF_PAX_RANDMMAP;
55150+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55151+ flags |= MF_PAX_EMUTRAMP;
55152+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55153+ flags |= MF_PAX_MPROTECT;
55154+
55155+ pax_set_flags(task, flags);
55156+
55157+ return;
55158+}
55159+#endif
55160+
55161+int
55162+gr_handle_proc_ptrace(struct task_struct *task)
55163+{
55164+ struct file *filp;
55165+ struct task_struct *tmp = task;
55166+ struct task_struct *curtemp = current;
55167+ __u32 retmode;
55168+
55169+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55170+ if (unlikely(!(gr_status & GR_READY)))
55171+ return 0;
55172+#endif
55173+
55174+ read_lock(&tasklist_lock);
55175+ read_lock(&grsec_exec_file_lock);
55176+ filp = task->exec_file;
55177+
55178+ while (tmp->pid > 0) {
55179+ if (tmp == curtemp)
55180+ break;
55181+ tmp = tmp->real_parent;
55182+ }
55183+
55184+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55185+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55186+ read_unlock(&grsec_exec_file_lock);
55187+ read_unlock(&tasklist_lock);
55188+ return 1;
55189+ }
55190+
55191+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55192+ if (!(gr_status & GR_READY)) {
55193+ read_unlock(&grsec_exec_file_lock);
55194+ read_unlock(&tasklist_lock);
55195+ return 0;
55196+ }
55197+#endif
55198+
55199+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55200+ read_unlock(&grsec_exec_file_lock);
55201+ read_unlock(&tasklist_lock);
55202+
55203+ if (retmode & GR_NOPTRACE)
55204+ return 1;
55205+
55206+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55207+ && (current->acl != task->acl || (current->acl != current->role->root_label
55208+ && current->pid != task->pid)))
55209+ return 1;
55210+
55211+ return 0;
55212+}
55213+
55214+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55215+{
55216+ if (unlikely(!(gr_status & GR_READY)))
55217+ return;
55218+
55219+ if (!(current->role->roletype & GR_ROLE_GOD))
55220+ return;
55221+
55222+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55223+ p->role->rolename, gr_task_roletype_to_char(p),
55224+ p->acl->filename);
55225+}
55226+
55227+int
55228+gr_handle_ptrace(struct task_struct *task, const long request)
55229+{
55230+ struct task_struct *tmp = task;
55231+ struct task_struct *curtemp = current;
55232+ __u32 retmode;
55233+
55234+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55235+ if (unlikely(!(gr_status & GR_READY)))
55236+ return 0;
55237+#endif
55238+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55239+ read_lock(&tasklist_lock);
55240+ while (tmp->pid > 0) {
55241+ if (tmp == curtemp)
55242+ break;
55243+ tmp = tmp->real_parent;
55244+ }
55245+
55246+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55247+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55248+ read_unlock(&tasklist_lock);
55249+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55250+ return 1;
55251+ }
55252+ read_unlock(&tasklist_lock);
55253+ }
55254+
55255+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55256+ if (!(gr_status & GR_READY))
55257+ return 0;
55258+#endif
55259+
55260+ read_lock(&grsec_exec_file_lock);
55261+ if (unlikely(!task->exec_file)) {
55262+ read_unlock(&grsec_exec_file_lock);
55263+ return 0;
55264+ }
55265+
55266+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55267+ read_unlock(&grsec_exec_file_lock);
55268+
55269+ if (retmode & GR_NOPTRACE) {
55270+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55271+ return 1;
55272+ }
55273+
55274+ if (retmode & GR_PTRACERD) {
55275+ switch (request) {
55276+ case PTRACE_SEIZE:
55277+ case PTRACE_POKETEXT:
55278+ case PTRACE_POKEDATA:
55279+ case PTRACE_POKEUSR:
55280+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55281+ case PTRACE_SETREGS:
55282+ case PTRACE_SETFPREGS:
55283+#endif
55284+#ifdef CONFIG_X86
55285+ case PTRACE_SETFPXREGS:
55286+#endif
55287+#ifdef CONFIG_ALTIVEC
55288+ case PTRACE_SETVRREGS:
55289+#endif
55290+ return 1;
55291+ default:
55292+ return 0;
55293+ }
55294+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
55295+ !(current->role->roletype & GR_ROLE_GOD) &&
55296+ (current->acl != task->acl)) {
55297+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55298+ return 1;
55299+ }
55300+
55301+ return 0;
55302+}
55303+
55304+static int is_writable_mmap(const struct file *filp)
55305+{
55306+ struct task_struct *task = current;
55307+ struct acl_object_label *obj, *obj2;
55308+
55309+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55310+ !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))) {
55311+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55312+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55313+ task->role->root_label);
55314+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55315+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55316+ return 1;
55317+ }
55318+ }
55319+ return 0;
55320+}
55321+
55322+int
55323+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55324+{
55325+ __u32 mode;
55326+
55327+ if (unlikely(!file || !(prot & PROT_EXEC)))
55328+ return 1;
55329+
55330+ if (is_writable_mmap(file))
55331+ return 0;
55332+
55333+ mode =
55334+ gr_search_file(file->f_path.dentry,
55335+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55336+ file->f_path.mnt);
55337+
55338+ if (!gr_tpe_allow(file))
55339+ return 0;
55340+
55341+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55342+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55343+ return 0;
55344+ } else if (unlikely(!(mode & GR_EXEC))) {
55345+ return 0;
55346+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55347+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55348+ return 1;
55349+ }
55350+
55351+ return 1;
55352+}
55353+
55354+int
55355+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55356+{
55357+ __u32 mode;
55358+
55359+ if (unlikely(!file || !(prot & PROT_EXEC)))
55360+ return 1;
55361+
55362+ if (is_writable_mmap(file))
55363+ return 0;
55364+
55365+ mode =
55366+ gr_search_file(file->f_path.dentry,
55367+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55368+ file->f_path.mnt);
55369+
55370+ if (!gr_tpe_allow(file))
55371+ return 0;
55372+
55373+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55374+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55375+ return 0;
55376+ } else if (unlikely(!(mode & GR_EXEC))) {
55377+ return 0;
55378+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55379+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55380+ return 1;
55381+ }
55382+
55383+ return 1;
55384+}
55385+
55386+void
55387+gr_acl_handle_psacct(struct task_struct *task, const long code)
55388+{
55389+ unsigned long runtime;
55390+ unsigned long cputime;
55391+ unsigned int wday, cday;
55392+ __u8 whr, chr;
55393+ __u8 wmin, cmin;
55394+ __u8 wsec, csec;
55395+ struct timespec timeval;
55396+
55397+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55398+ !(task->acl->mode & GR_PROCACCT)))
55399+ return;
55400+
55401+ do_posix_clock_monotonic_gettime(&timeval);
55402+ runtime = timeval.tv_sec - task->start_time.tv_sec;
55403+ wday = runtime / (3600 * 24);
55404+ runtime -= wday * (3600 * 24);
55405+ whr = runtime / 3600;
55406+ runtime -= whr * 3600;
55407+ wmin = runtime / 60;
55408+ runtime -= wmin * 60;
55409+ wsec = runtime;
55410+
55411+ cputime = (task->utime + task->stime) / HZ;
55412+ cday = cputime / (3600 * 24);
55413+ cputime -= cday * (3600 * 24);
55414+ chr = cputime / 3600;
55415+ cputime -= chr * 3600;
55416+ cmin = cputime / 60;
55417+ cputime -= cmin * 60;
55418+ csec = cputime;
55419+
55420+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55421+
55422+ return;
55423+}
55424+
55425+void gr_set_kernel_label(struct task_struct *task)
55426+{
55427+ if (gr_status & GR_READY) {
55428+ task->role = kernel_role;
55429+ task->acl = kernel_role->root_label;
55430+ }
55431+ return;
55432+}
55433+
55434+#ifdef CONFIG_TASKSTATS
55435+int gr_is_taskstats_denied(int pid)
55436+{
55437+ struct task_struct *task;
55438+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55439+ const struct cred *cred;
55440+#endif
55441+ int ret = 0;
55442+
55443+ /* restrict taskstats viewing to un-chrooted root users
55444+ who have the 'view' subject flag if the RBAC system is enabled
55445+ */
55446+
55447+ rcu_read_lock();
55448+ read_lock(&tasklist_lock);
55449+ task = find_task_by_vpid(pid);
55450+ if (task) {
55451+#ifdef CONFIG_GRKERNSEC_CHROOT
55452+ if (proc_is_chrooted(task))
55453+ ret = -EACCES;
55454+#endif
55455+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55456+ cred = __task_cred(task);
55457+#ifdef CONFIG_GRKERNSEC_PROC_USER
55458+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55459+ ret = -EACCES;
55460+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55461+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55462+ ret = -EACCES;
55463+#endif
55464+#endif
55465+ if (gr_status & GR_READY) {
55466+ if (!(task->acl->mode & GR_VIEW))
55467+ ret = -EACCES;
55468+ }
55469+ } else
55470+ ret = -ENOENT;
55471+
55472+ read_unlock(&tasklist_lock);
55473+ rcu_read_unlock();
55474+
55475+ return ret;
55476+}
55477+#endif
55478+
55479+/* AUXV entries are filled via a descendant of search_binary_handler
55480+ after we've already applied the subject for the target
55481+*/
55482+int gr_acl_enable_at_secure(void)
55483+{
55484+ if (unlikely(!(gr_status & GR_READY)))
55485+ return 0;
55486+
55487+ if (current->acl->mode & GR_ATSECURE)
55488+ return 1;
55489+
55490+ return 0;
55491+}
55492+
55493+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55494+{
55495+ struct task_struct *task = current;
55496+ struct dentry *dentry = file->f_path.dentry;
55497+ struct vfsmount *mnt = file->f_path.mnt;
55498+ struct acl_object_label *obj, *tmp;
55499+ struct acl_subject_label *subj;
55500+ unsigned int bufsize;
55501+ int is_not_root;
55502+ char *path;
55503+ dev_t dev = __get_dev(dentry);
55504+
55505+ if (unlikely(!(gr_status & GR_READY)))
55506+ return 1;
55507+
55508+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55509+ return 1;
55510+
55511+ /* ignore Eric Biederman */
55512+ if (IS_PRIVATE(dentry->d_inode))
55513+ return 1;
55514+
55515+ subj = task->acl;
55516+ read_lock(&gr_inode_lock);
55517+ do {
55518+ obj = lookup_acl_obj_label(ino, dev, subj);
55519+ if (obj != NULL) {
55520+ read_unlock(&gr_inode_lock);
55521+ return (obj->mode & GR_FIND) ? 1 : 0;
55522+ }
55523+ } while ((subj = subj->parent_subject));
55524+ read_unlock(&gr_inode_lock);
55525+
55526+ /* this is purely an optimization since we're looking for an object
55527+ for the directory we're doing a readdir on
55528+ if it's possible for any globbed object to match the entry we're
55529+ filling into the directory, then the object we find here will be
55530+ an anchor point with attached globbed objects
55531+ */
55532+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55533+ if (obj->globbed == NULL)
55534+ return (obj->mode & GR_FIND) ? 1 : 0;
55535+
55536+ is_not_root = ((obj->filename[0] == '/') &&
55537+ (obj->filename[1] == '\0')) ? 0 : 1;
55538+ bufsize = PAGE_SIZE - namelen - is_not_root;
55539+
55540+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
55541+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55542+ return 1;
55543+
55544+ preempt_disable();
55545+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55546+ bufsize);
55547+
55548+ bufsize = strlen(path);
55549+
55550+ /* if base is "/", don't append an additional slash */
55551+ if (is_not_root)
55552+ *(path + bufsize) = '/';
55553+ memcpy(path + bufsize + is_not_root, name, namelen);
55554+ *(path + bufsize + namelen + is_not_root) = '\0';
55555+
55556+ tmp = obj->globbed;
55557+ while (tmp) {
55558+ if (!glob_match(tmp->filename, path)) {
55559+ preempt_enable();
55560+ return (tmp->mode & GR_FIND) ? 1 : 0;
55561+ }
55562+ tmp = tmp->next;
55563+ }
55564+ preempt_enable();
55565+ return (obj->mode & GR_FIND) ? 1 : 0;
55566+}
55567+
55568+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55569+EXPORT_SYMBOL(gr_acl_is_enabled);
55570+#endif
55571+EXPORT_SYMBOL(gr_learn_resource);
55572+EXPORT_SYMBOL(gr_set_kernel_label);
55573+#ifdef CONFIG_SECURITY
55574+EXPORT_SYMBOL(gr_check_user_change);
55575+EXPORT_SYMBOL(gr_check_group_change);
55576+#endif
55577+
55578diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55579new file mode 100644
55580index 0000000..34fefda
55581--- /dev/null
55582+++ b/grsecurity/gracl_alloc.c
55583@@ -0,0 +1,105 @@
55584+#include <linux/kernel.h>
55585+#include <linux/mm.h>
55586+#include <linux/slab.h>
55587+#include <linux/vmalloc.h>
55588+#include <linux/gracl.h>
55589+#include <linux/grsecurity.h>
55590+
55591+static unsigned long alloc_stack_next = 1;
55592+static unsigned long alloc_stack_size = 1;
55593+static void **alloc_stack;
55594+
55595+static __inline__ int
55596+alloc_pop(void)
55597+{
55598+ if (alloc_stack_next == 1)
55599+ return 0;
55600+
55601+ kfree(alloc_stack[alloc_stack_next - 2]);
55602+
55603+ alloc_stack_next--;
55604+
55605+ return 1;
55606+}
55607+
55608+static __inline__ int
55609+alloc_push(void *buf)
55610+{
55611+ if (alloc_stack_next >= alloc_stack_size)
55612+ return 1;
55613+
55614+ alloc_stack[alloc_stack_next - 1] = buf;
55615+
55616+ alloc_stack_next++;
55617+
55618+ return 0;
55619+}
55620+
55621+void *
55622+acl_alloc(unsigned long len)
55623+{
55624+ void *ret = NULL;
55625+
55626+ if (!len || len > PAGE_SIZE)
55627+ goto out;
55628+
55629+ ret = kmalloc(len, GFP_KERNEL);
55630+
55631+ if (ret) {
55632+ if (alloc_push(ret)) {
55633+ kfree(ret);
55634+ ret = NULL;
55635+ }
55636+ }
55637+
55638+out:
55639+ return ret;
55640+}
55641+
55642+void *
55643+acl_alloc_num(unsigned long num, unsigned long len)
55644+{
55645+ if (!len || (num > (PAGE_SIZE / len)))
55646+ return NULL;
55647+
55648+ return acl_alloc(num * len);
55649+}
55650+
55651+void
55652+acl_free_all(void)
55653+{
55654+ if (gr_acl_is_enabled() || !alloc_stack)
55655+ return;
55656+
55657+ while (alloc_pop()) ;
55658+
55659+ if (alloc_stack) {
55660+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55661+ kfree(alloc_stack);
55662+ else
55663+ vfree(alloc_stack);
55664+ }
55665+
55666+ alloc_stack = NULL;
55667+ alloc_stack_size = 1;
55668+ alloc_stack_next = 1;
55669+
55670+ return;
55671+}
55672+
55673+int
55674+acl_alloc_stack_init(unsigned long size)
55675+{
55676+ if ((size * sizeof (void *)) <= PAGE_SIZE)
55677+ alloc_stack =
55678+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55679+ else
55680+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
55681+
55682+ alloc_stack_size = size;
55683+
55684+ if (!alloc_stack)
55685+ return 0;
55686+ else
55687+ return 1;
55688+}
55689diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55690new file mode 100644
55691index 0000000..6d21049
55692--- /dev/null
55693+++ b/grsecurity/gracl_cap.c
55694@@ -0,0 +1,110 @@
55695+#include <linux/kernel.h>
55696+#include <linux/module.h>
55697+#include <linux/sched.h>
55698+#include <linux/gracl.h>
55699+#include <linux/grsecurity.h>
55700+#include <linux/grinternal.h>
55701+
55702+extern const char *captab_log[];
55703+extern int captab_log_entries;
55704+
55705+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55706+{
55707+ struct acl_subject_label *curracl;
55708+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55709+ kernel_cap_t cap_audit = __cap_empty_set;
55710+
55711+ if (!gr_acl_is_enabled())
55712+ return 1;
55713+
55714+ curracl = task->acl;
55715+
55716+ cap_drop = curracl->cap_lower;
55717+ cap_mask = curracl->cap_mask;
55718+ cap_audit = curracl->cap_invert_audit;
55719+
55720+ while ((curracl = curracl->parent_subject)) {
55721+ /* if the cap isn't specified in the current computed mask but is specified in the
55722+ current level subject, and is lowered in the current level subject, then add
55723+ it to the set of dropped capabilities
55724+ otherwise, add the current level subject's mask to the current computed mask
55725+ */
55726+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55727+ cap_raise(cap_mask, cap);
55728+ if (cap_raised(curracl->cap_lower, cap))
55729+ cap_raise(cap_drop, cap);
55730+ if (cap_raised(curracl->cap_invert_audit, cap))
55731+ cap_raise(cap_audit, cap);
55732+ }
55733+ }
55734+
55735+ if (!cap_raised(cap_drop, cap)) {
55736+ if (cap_raised(cap_audit, cap))
55737+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55738+ return 1;
55739+ }
55740+
55741+ curracl = task->acl;
55742+
55743+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55744+ && cap_raised(cred->cap_effective, cap)) {
55745+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55746+ task->role->roletype, cred->uid,
55747+ cred->gid, task->exec_file ?
55748+ gr_to_filename(task->exec_file->f_path.dentry,
55749+ task->exec_file->f_path.mnt) : curracl->filename,
55750+ curracl->filename, 0UL,
55751+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55752+ return 1;
55753+ }
55754+
55755+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55756+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55757+
55758+ return 0;
55759+}
55760+
55761+int
55762+gr_acl_is_capable(const int cap)
55763+{
55764+ return gr_task_acl_is_capable(current, current_cred(), cap);
55765+}
55766+
55767+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55768+{
55769+ struct acl_subject_label *curracl;
55770+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55771+
55772+ if (!gr_acl_is_enabled())
55773+ return 1;
55774+
55775+ curracl = task->acl;
55776+
55777+ cap_drop = curracl->cap_lower;
55778+ cap_mask = curracl->cap_mask;
55779+
55780+ while ((curracl = curracl->parent_subject)) {
55781+ /* if the cap isn't specified in the current computed mask but is specified in the
55782+ current level subject, and is lowered in the current level subject, then add
55783+ it to the set of dropped capabilities
55784+ otherwise, add the current level subject's mask to the current computed mask
55785+ */
55786+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55787+ cap_raise(cap_mask, cap);
55788+ if (cap_raised(curracl->cap_lower, cap))
55789+ cap_raise(cap_drop, cap);
55790+ }
55791+ }
55792+
55793+ if (!cap_raised(cap_drop, cap))
55794+ return 1;
55795+
55796+ return 0;
55797+}
55798+
55799+int
55800+gr_acl_is_capable_nolog(const int cap)
55801+{
55802+ return gr_task_acl_is_capable_nolog(current, cap);
55803+}
55804+
55805diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55806new file mode 100644
55807index 0000000..d28e241
55808--- /dev/null
55809+++ b/grsecurity/gracl_fs.c
55810@@ -0,0 +1,437 @@
55811+#include <linux/kernel.h>
55812+#include <linux/sched.h>
55813+#include <linux/types.h>
55814+#include <linux/fs.h>
55815+#include <linux/file.h>
55816+#include <linux/stat.h>
55817+#include <linux/grsecurity.h>
55818+#include <linux/grinternal.h>
55819+#include <linux/gracl.h>
55820+
55821+umode_t
55822+gr_acl_umask(void)
55823+{
55824+ if (unlikely(!gr_acl_is_enabled()))
55825+ return 0;
55826+
55827+ return current->role->umask;
55828+}
55829+
55830+__u32
55831+gr_acl_handle_hidden_file(const struct dentry * dentry,
55832+ const struct vfsmount * mnt)
55833+{
55834+ __u32 mode;
55835+
55836+ if (unlikely(!dentry->d_inode))
55837+ return GR_FIND;
55838+
55839+ mode =
55840+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55841+
55842+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55843+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55844+ return mode;
55845+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55846+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55847+ return 0;
55848+ } else if (unlikely(!(mode & GR_FIND)))
55849+ return 0;
55850+
55851+ return GR_FIND;
55852+}
55853+
55854+__u32
55855+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55856+ int acc_mode)
55857+{
55858+ __u32 reqmode = GR_FIND;
55859+ __u32 mode;
55860+
55861+ if (unlikely(!dentry->d_inode))
55862+ return reqmode;
55863+
55864+ if (acc_mode & MAY_APPEND)
55865+ reqmode |= GR_APPEND;
55866+ else if (acc_mode & MAY_WRITE)
55867+ reqmode |= GR_WRITE;
55868+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55869+ reqmode |= GR_READ;
55870+
55871+ mode =
55872+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55873+ mnt);
55874+
55875+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55876+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55877+ reqmode & GR_READ ? " reading" : "",
55878+ reqmode & GR_WRITE ? " writing" : reqmode &
55879+ GR_APPEND ? " appending" : "");
55880+ return reqmode;
55881+ } else
55882+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55883+ {
55884+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55885+ reqmode & GR_READ ? " reading" : "",
55886+ reqmode & GR_WRITE ? " writing" : reqmode &
55887+ GR_APPEND ? " appending" : "");
55888+ return 0;
55889+ } else if (unlikely((mode & reqmode) != reqmode))
55890+ return 0;
55891+
55892+ return reqmode;
55893+}
55894+
55895+__u32
55896+gr_acl_handle_creat(const struct dentry * dentry,
55897+ const struct dentry * p_dentry,
55898+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55899+ const int imode)
55900+{
55901+ __u32 reqmode = GR_WRITE | GR_CREATE;
55902+ __u32 mode;
55903+
55904+ if (acc_mode & MAY_APPEND)
55905+ reqmode |= GR_APPEND;
55906+ // if a directory was required or the directory already exists, then
55907+ // don't count this open as a read
55908+ if ((acc_mode & MAY_READ) &&
55909+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55910+ reqmode |= GR_READ;
55911+ if ((open_flags & O_CREAT) &&
55912+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55913+ reqmode |= GR_SETID;
55914+
55915+ mode =
55916+ gr_check_create(dentry, p_dentry, p_mnt,
55917+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55918+
55919+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55920+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55921+ reqmode & GR_READ ? " reading" : "",
55922+ reqmode & GR_WRITE ? " writing" : reqmode &
55923+ GR_APPEND ? " appending" : "");
55924+ return reqmode;
55925+ } else
55926+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55927+ {
55928+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55929+ reqmode & GR_READ ? " reading" : "",
55930+ reqmode & GR_WRITE ? " writing" : reqmode &
55931+ GR_APPEND ? " appending" : "");
55932+ return 0;
55933+ } else if (unlikely((mode & reqmode) != reqmode))
55934+ return 0;
55935+
55936+ return reqmode;
55937+}
55938+
55939+__u32
55940+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55941+ const int fmode)
55942+{
55943+ __u32 mode, reqmode = GR_FIND;
55944+
55945+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55946+ reqmode |= GR_EXEC;
55947+ if (fmode & S_IWOTH)
55948+ reqmode |= GR_WRITE;
55949+ if (fmode & S_IROTH)
55950+ reqmode |= GR_READ;
55951+
55952+ mode =
55953+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55954+ mnt);
55955+
55956+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55957+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55958+ reqmode & GR_READ ? " reading" : "",
55959+ reqmode & GR_WRITE ? " writing" : "",
55960+ reqmode & GR_EXEC ? " executing" : "");
55961+ return reqmode;
55962+ } else
55963+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55964+ {
55965+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55966+ reqmode & GR_READ ? " reading" : "",
55967+ reqmode & GR_WRITE ? " writing" : "",
55968+ reqmode & GR_EXEC ? " executing" : "");
55969+ return 0;
55970+ } else if (unlikely((mode & reqmode) != reqmode))
55971+ return 0;
55972+
55973+ return reqmode;
55974+}
55975+
55976+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55977+{
55978+ __u32 mode;
55979+
55980+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55981+
55982+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55983+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55984+ return mode;
55985+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55986+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55987+ return 0;
55988+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55989+ return 0;
55990+
55991+ return (reqmode);
55992+}
55993+
55994+__u32
55995+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55996+{
55997+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55998+}
55999+
56000+__u32
56001+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56002+{
56003+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56004+}
56005+
56006+__u32
56007+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56008+{
56009+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56010+}
56011+
56012+__u32
56013+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56014+{
56015+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56016+}
56017+
56018+__u32
56019+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56020+ umode_t *modeptr)
56021+{
56022+ umode_t mode;
56023+
56024+ *modeptr &= ~gr_acl_umask();
56025+ mode = *modeptr;
56026+
56027+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56028+ return 1;
56029+
56030+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56031+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56032+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56033+ GR_CHMOD_ACL_MSG);
56034+ } else {
56035+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56036+ }
56037+}
56038+
56039+__u32
56040+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56041+{
56042+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56043+}
56044+
56045+__u32
56046+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56047+{
56048+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56049+}
56050+
56051+__u32
56052+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56053+{
56054+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56055+}
56056+
56057+__u32
56058+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56059+{
56060+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56061+ GR_UNIXCONNECT_ACL_MSG);
56062+}
56063+
56064+/* hardlinks require at minimum create and link permission,
56065+ any additional privilege required is based on the
56066+ privilege of the file being linked to
56067+*/
56068+__u32
56069+gr_acl_handle_link(const struct dentry * new_dentry,
56070+ const struct dentry * parent_dentry,
56071+ const struct vfsmount * parent_mnt,
56072+ const struct dentry * old_dentry,
56073+ const struct vfsmount * old_mnt, const char *to)
56074+{
56075+ __u32 mode;
56076+ __u32 needmode = GR_CREATE | GR_LINK;
56077+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56078+
56079+ mode =
56080+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56081+ old_mnt);
56082+
56083+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56084+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56085+ return mode;
56086+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56087+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56088+ return 0;
56089+ } else if (unlikely((mode & needmode) != needmode))
56090+ return 0;
56091+
56092+ return 1;
56093+}
56094+
56095+__u32
56096+gr_acl_handle_symlink(const struct dentry * new_dentry,
56097+ const struct dentry * parent_dentry,
56098+ const struct vfsmount * parent_mnt, const char *from)
56099+{
56100+ __u32 needmode = GR_WRITE | GR_CREATE;
56101+ __u32 mode;
56102+
56103+ mode =
56104+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
56105+ GR_CREATE | GR_AUDIT_CREATE |
56106+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56107+
56108+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56109+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56110+ return mode;
56111+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56112+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56113+ return 0;
56114+ } else if (unlikely((mode & needmode) != needmode))
56115+ return 0;
56116+
56117+ return (GR_WRITE | GR_CREATE);
56118+}
56119+
56120+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)
56121+{
56122+ __u32 mode;
56123+
56124+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56125+
56126+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56127+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56128+ return mode;
56129+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56130+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56131+ return 0;
56132+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
56133+ return 0;
56134+
56135+ return (reqmode);
56136+}
56137+
56138+__u32
56139+gr_acl_handle_mknod(const struct dentry * new_dentry,
56140+ const struct dentry * parent_dentry,
56141+ const struct vfsmount * parent_mnt,
56142+ const int mode)
56143+{
56144+ __u32 reqmode = GR_WRITE | GR_CREATE;
56145+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56146+ reqmode |= GR_SETID;
56147+
56148+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56149+ reqmode, GR_MKNOD_ACL_MSG);
56150+}
56151+
56152+__u32
56153+gr_acl_handle_mkdir(const struct dentry *new_dentry,
56154+ const struct dentry *parent_dentry,
56155+ const struct vfsmount *parent_mnt)
56156+{
56157+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56158+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56159+}
56160+
56161+#define RENAME_CHECK_SUCCESS(old, new) \
56162+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56163+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56164+
56165+int
56166+gr_acl_handle_rename(struct dentry *new_dentry,
56167+ struct dentry *parent_dentry,
56168+ const struct vfsmount *parent_mnt,
56169+ struct dentry *old_dentry,
56170+ struct inode *old_parent_inode,
56171+ struct vfsmount *old_mnt, const char *newname)
56172+{
56173+ __u32 comp1, comp2;
56174+ int error = 0;
56175+
56176+ if (unlikely(!gr_acl_is_enabled()))
56177+ return 0;
56178+
56179+ if (!new_dentry->d_inode) {
56180+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56181+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56182+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56183+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56184+ GR_DELETE | GR_AUDIT_DELETE |
56185+ GR_AUDIT_READ | GR_AUDIT_WRITE |
56186+ GR_SUPPRESS, old_mnt);
56187+ } else {
56188+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56189+ GR_CREATE | GR_DELETE |
56190+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56191+ GR_AUDIT_READ | GR_AUDIT_WRITE |
56192+ GR_SUPPRESS, parent_mnt);
56193+ comp2 =
56194+ gr_search_file(old_dentry,
56195+ GR_READ | GR_WRITE | GR_AUDIT_READ |
56196+ GR_DELETE | GR_AUDIT_DELETE |
56197+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56198+ }
56199+
56200+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56201+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56202+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56203+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56204+ && !(comp2 & GR_SUPPRESS)) {
56205+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56206+ error = -EACCES;
56207+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56208+ error = -EACCES;
56209+
56210+ return error;
56211+}
56212+
56213+void
56214+gr_acl_handle_exit(void)
56215+{
56216+ u16 id;
56217+ char *rolename;
56218+ struct file *exec_file;
56219+
56220+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56221+ !(current->role->roletype & GR_ROLE_PERSIST))) {
56222+ id = current->acl_role_id;
56223+ rolename = current->role->rolename;
56224+ gr_set_acls(1);
56225+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56226+ }
56227+
56228+ write_lock(&grsec_exec_file_lock);
56229+ exec_file = current->exec_file;
56230+ current->exec_file = NULL;
56231+ write_unlock(&grsec_exec_file_lock);
56232+
56233+ if (exec_file)
56234+ fput(exec_file);
56235+}
56236+
56237+int
56238+gr_acl_handle_procpidmem(const struct task_struct *task)
56239+{
56240+ if (unlikely(!gr_acl_is_enabled()))
56241+ return 0;
56242+
56243+ if (task != current && task->acl->mode & GR_PROTPROCFD)
56244+ return -EACCES;
56245+
56246+ return 0;
56247+}
56248diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56249new file mode 100644
56250index 0000000..58800a7
56251--- /dev/null
56252+++ b/grsecurity/gracl_ip.c
56253@@ -0,0 +1,384 @@
56254+#include <linux/kernel.h>
56255+#include <asm/uaccess.h>
56256+#include <asm/errno.h>
56257+#include <net/sock.h>
56258+#include <linux/file.h>
56259+#include <linux/fs.h>
56260+#include <linux/net.h>
56261+#include <linux/in.h>
56262+#include <linux/skbuff.h>
56263+#include <linux/ip.h>
56264+#include <linux/udp.h>
56265+#include <linux/types.h>
56266+#include <linux/sched.h>
56267+#include <linux/netdevice.h>
56268+#include <linux/inetdevice.h>
56269+#include <linux/gracl.h>
56270+#include <linux/grsecurity.h>
56271+#include <linux/grinternal.h>
56272+
56273+#define GR_BIND 0x01
56274+#define GR_CONNECT 0x02
56275+#define GR_INVERT 0x04
56276+#define GR_BINDOVERRIDE 0x08
56277+#define GR_CONNECTOVERRIDE 0x10
56278+#define GR_SOCK_FAMILY 0x20
56279+
56280+static const char * gr_protocols[IPPROTO_MAX] = {
56281+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56282+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56283+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56284+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56285+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56286+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56287+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56288+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56289+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56290+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56291+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56292+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56293+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56294+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56295+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56296+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56297+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56298+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56299+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56300+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56301+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56302+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56303+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56304+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56305+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56306+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56307+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56308+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56309+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56310+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56311+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56312+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56313+ };
56314+
56315+static const char * gr_socktypes[SOCK_MAX] = {
56316+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56317+ "unknown:7", "unknown:8", "unknown:9", "packet"
56318+ };
56319+
56320+static const char * gr_sockfamilies[AF_MAX+1] = {
56321+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56322+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56323+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56324+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56325+ };
56326+
56327+const char *
56328+gr_proto_to_name(unsigned char proto)
56329+{
56330+ return gr_protocols[proto];
56331+}
56332+
56333+const char *
56334+gr_socktype_to_name(unsigned char type)
56335+{
56336+ return gr_socktypes[type];
56337+}
56338+
56339+const char *
56340+gr_sockfamily_to_name(unsigned char family)
56341+{
56342+ return gr_sockfamilies[family];
56343+}
56344+
56345+int
56346+gr_search_socket(const int domain, const int type, const int protocol)
56347+{
56348+ struct acl_subject_label *curr;
56349+ const struct cred *cred = current_cred();
56350+
56351+ if (unlikely(!gr_acl_is_enabled()))
56352+ goto exit;
56353+
56354+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
56355+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56356+ goto exit; // let the kernel handle it
56357+
56358+ curr = current->acl;
56359+
56360+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56361+ /* the family is allowed, if this is PF_INET allow it only if
56362+ the extra sock type/protocol checks pass */
56363+ if (domain == PF_INET)
56364+ goto inet_check;
56365+ goto exit;
56366+ } else {
56367+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56368+ __u32 fakeip = 0;
56369+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56370+ current->role->roletype, cred->uid,
56371+ cred->gid, current->exec_file ?
56372+ gr_to_filename(current->exec_file->f_path.dentry,
56373+ current->exec_file->f_path.mnt) :
56374+ curr->filename, curr->filename,
56375+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56376+ &current->signal->saved_ip);
56377+ goto exit;
56378+ }
56379+ goto exit_fail;
56380+ }
56381+
56382+inet_check:
56383+ /* the rest of this checking is for IPv4 only */
56384+ if (!curr->ips)
56385+ goto exit;
56386+
56387+ if ((curr->ip_type & (1 << type)) &&
56388+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56389+ goto exit;
56390+
56391+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56392+ /* we don't place acls on raw sockets , and sometimes
56393+ dgram/ip sockets are opened for ioctl and not
56394+ bind/connect, so we'll fake a bind learn log */
56395+ if (type == SOCK_RAW || type == SOCK_PACKET) {
56396+ __u32 fakeip = 0;
56397+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56398+ current->role->roletype, cred->uid,
56399+ cred->gid, current->exec_file ?
56400+ gr_to_filename(current->exec_file->f_path.dentry,
56401+ current->exec_file->f_path.mnt) :
56402+ curr->filename, curr->filename,
56403+ &fakeip, 0, type,
56404+ protocol, GR_CONNECT, &current->signal->saved_ip);
56405+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56406+ __u32 fakeip = 0;
56407+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56408+ current->role->roletype, cred->uid,
56409+ cred->gid, current->exec_file ?
56410+ gr_to_filename(current->exec_file->f_path.dentry,
56411+ current->exec_file->f_path.mnt) :
56412+ curr->filename, curr->filename,
56413+ &fakeip, 0, type,
56414+ protocol, GR_BIND, &current->signal->saved_ip);
56415+ }
56416+ /* we'll log when they use connect or bind */
56417+ goto exit;
56418+ }
56419+
56420+exit_fail:
56421+ if (domain == PF_INET)
56422+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56423+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
56424+ else
56425+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56426+ gr_socktype_to_name(type), protocol);
56427+
56428+ return 0;
56429+exit:
56430+ return 1;
56431+}
56432+
56433+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)
56434+{
56435+ if ((ip->mode & mode) &&
56436+ (ip_port >= ip->low) &&
56437+ (ip_port <= ip->high) &&
56438+ ((ntohl(ip_addr) & our_netmask) ==
56439+ (ntohl(our_addr) & our_netmask))
56440+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56441+ && (ip->type & (1 << type))) {
56442+ if (ip->mode & GR_INVERT)
56443+ return 2; // specifically denied
56444+ else
56445+ return 1; // allowed
56446+ }
56447+
56448+ return 0; // not specifically allowed, may continue parsing
56449+}
56450+
56451+static int
56452+gr_search_connectbind(const int full_mode, struct sock *sk,
56453+ struct sockaddr_in *addr, const int type)
56454+{
56455+ char iface[IFNAMSIZ] = {0};
56456+ struct acl_subject_label *curr;
56457+ struct acl_ip_label *ip;
56458+ struct inet_sock *isk;
56459+ struct net_device *dev;
56460+ struct in_device *idev;
56461+ unsigned long i;
56462+ int ret;
56463+ int mode = full_mode & (GR_BIND | GR_CONNECT);
56464+ __u32 ip_addr = 0;
56465+ __u32 our_addr;
56466+ __u32 our_netmask;
56467+ char *p;
56468+ __u16 ip_port = 0;
56469+ const struct cred *cred = current_cred();
56470+
56471+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56472+ return 0;
56473+
56474+ curr = current->acl;
56475+ isk = inet_sk(sk);
56476+
56477+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56478+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56479+ addr->sin_addr.s_addr = curr->inaddr_any_override;
56480+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56481+ struct sockaddr_in saddr;
56482+ int err;
56483+
56484+ saddr.sin_family = AF_INET;
56485+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
56486+ saddr.sin_port = isk->inet_sport;
56487+
56488+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56489+ if (err)
56490+ return err;
56491+
56492+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56493+ if (err)
56494+ return err;
56495+ }
56496+
56497+ if (!curr->ips)
56498+ return 0;
56499+
56500+ ip_addr = addr->sin_addr.s_addr;
56501+ ip_port = ntohs(addr->sin_port);
56502+
56503+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56504+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56505+ current->role->roletype, cred->uid,
56506+ cred->gid, current->exec_file ?
56507+ gr_to_filename(current->exec_file->f_path.dentry,
56508+ current->exec_file->f_path.mnt) :
56509+ curr->filename, curr->filename,
56510+ &ip_addr, ip_port, type,
56511+ sk->sk_protocol, mode, &current->signal->saved_ip);
56512+ return 0;
56513+ }
56514+
56515+ for (i = 0; i < curr->ip_num; i++) {
56516+ ip = *(curr->ips + i);
56517+ if (ip->iface != NULL) {
56518+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
56519+ p = strchr(iface, ':');
56520+ if (p != NULL)
56521+ *p = '\0';
56522+ dev = dev_get_by_name(sock_net(sk), iface);
56523+ if (dev == NULL)
56524+ continue;
56525+ idev = in_dev_get(dev);
56526+ if (idev == NULL) {
56527+ dev_put(dev);
56528+ continue;
56529+ }
56530+ rcu_read_lock();
56531+ for_ifa(idev) {
56532+ if (!strcmp(ip->iface, ifa->ifa_label)) {
56533+ our_addr = ifa->ifa_address;
56534+ our_netmask = 0xffffffff;
56535+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56536+ if (ret == 1) {
56537+ rcu_read_unlock();
56538+ in_dev_put(idev);
56539+ dev_put(dev);
56540+ return 0;
56541+ } else if (ret == 2) {
56542+ rcu_read_unlock();
56543+ in_dev_put(idev);
56544+ dev_put(dev);
56545+ goto denied;
56546+ }
56547+ }
56548+ } endfor_ifa(idev);
56549+ rcu_read_unlock();
56550+ in_dev_put(idev);
56551+ dev_put(dev);
56552+ } else {
56553+ our_addr = ip->addr;
56554+ our_netmask = ip->netmask;
56555+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56556+ if (ret == 1)
56557+ return 0;
56558+ else if (ret == 2)
56559+ goto denied;
56560+ }
56561+ }
56562+
56563+denied:
56564+ if (mode == GR_BIND)
56565+ 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));
56566+ else if (mode == GR_CONNECT)
56567+ 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));
56568+
56569+ return -EACCES;
56570+}
56571+
56572+int
56573+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56574+{
56575+ /* always allow disconnection of dgram sockets with connect */
56576+ if (addr->sin_family == AF_UNSPEC)
56577+ return 0;
56578+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56579+}
56580+
56581+int
56582+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56583+{
56584+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56585+}
56586+
56587+int gr_search_listen(struct socket *sock)
56588+{
56589+ struct sock *sk = sock->sk;
56590+ struct sockaddr_in addr;
56591+
56592+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56593+ addr.sin_port = inet_sk(sk)->inet_sport;
56594+
56595+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56596+}
56597+
56598+int gr_search_accept(struct socket *sock)
56599+{
56600+ struct sock *sk = sock->sk;
56601+ struct sockaddr_in addr;
56602+
56603+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56604+ addr.sin_port = inet_sk(sk)->inet_sport;
56605+
56606+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56607+}
56608+
56609+int
56610+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56611+{
56612+ if (addr)
56613+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56614+ else {
56615+ struct sockaddr_in sin;
56616+ const struct inet_sock *inet = inet_sk(sk);
56617+
56618+ sin.sin_addr.s_addr = inet->inet_daddr;
56619+ sin.sin_port = inet->inet_dport;
56620+
56621+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56622+ }
56623+}
56624+
56625+int
56626+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56627+{
56628+ struct sockaddr_in sin;
56629+
56630+ if (unlikely(skb->len < sizeof (struct udphdr)))
56631+ return 0; // skip this packet
56632+
56633+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56634+ sin.sin_port = udp_hdr(skb)->source;
56635+
56636+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56637+}
56638diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56639new file mode 100644
56640index 0000000..25f54ef
56641--- /dev/null
56642+++ b/grsecurity/gracl_learn.c
56643@@ -0,0 +1,207 @@
56644+#include <linux/kernel.h>
56645+#include <linux/mm.h>
56646+#include <linux/sched.h>
56647+#include <linux/poll.h>
56648+#include <linux/string.h>
56649+#include <linux/file.h>
56650+#include <linux/types.h>
56651+#include <linux/vmalloc.h>
56652+#include <linux/grinternal.h>
56653+
56654+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56655+ size_t count, loff_t *ppos);
56656+extern int gr_acl_is_enabled(void);
56657+
56658+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56659+static int gr_learn_attached;
56660+
56661+/* use a 512k buffer */
56662+#define LEARN_BUFFER_SIZE (512 * 1024)
56663+
56664+static DEFINE_SPINLOCK(gr_learn_lock);
56665+static DEFINE_MUTEX(gr_learn_user_mutex);
56666+
56667+/* we need to maintain two buffers, so that the kernel context of grlearn
56668+ uses a semaphore around the userspace copying, and the other kernel contexts
56669+ use a spinlock when copying into the buffer, since they cannot sleep
56670+*/
56671+static char *learn_buffer;
56672+static char *learn_buffer_user;
56673+static int learn_buffer_len;
56674+static int learn_buffer_user_len;
56675+
56676+static ssize_t
56677+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56678+{
56679+ DECLARE_WAITQUEUE(wait, current);
56680+ ssize_t retval = 0;
56681+
56682+ add_wait_queue(&learn_wait, &wait);
56683+ set_current_state(TASK_INTERRUPTIBLE);
56684+ do {
56685+ mutex_lock(&gr_learn_user_mutex);
56686+ spin_lock(&gr_learn_lock);
56687+ if (learn_buffer_len)
56688+ break;
56689+ spin_unlock(&gr_learn_lock);
56690+ mutex_unlock(&gr_learn_user_mutex);
56691+ if (file->f_flags & O_NONBLOCK) {
56692+ retval = -EAGAIN;
56693+ goto out;
56694+ }
56695+ if (signal_pending(current)) {
56696+ retval = -ERESTARTSYS;
56697+ goto out;
56698+ }
56699+
56700+ schedule();
56701+ } while (1);
56702+
56703+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56704+ learn_buffer_user_len = learn_buffer_len;
56705+ retval = learn_buffer_len;
56706+ learn_buffer_len = 0;
56707+
56708+ spin_unlock(&gr_learn_lock);
56709+
56710+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56711+ retval = -EFAULT;
56712+
56713+ mutex_unlock(&gr_learn_user_mutex);
56714+out:
56715+ set_current_state(TASK_RUNNING);
56716+ remove_wait_queue(&learn_wait, &wait);
56717+ return retval;
56718+}
56719+
56720+static unsigned int
56721+poll_learn(struct file * file, poll_table * wait)
56722+{
56723+ poll_wait(file, &learn_wait, wait);
56724+
56725+ if (learn_buffer_len)
56726+ return (POLLIN | POLLRDNORM);
56727+
56728+ return 0;
56729+}
56730+
56731+void
56732+gr_clear_learn_entries(void)
56733+{
56734+ char *tmp;
56735+
56736+ mutex_lock(&gr_learn_user_mutex);
56737+ spin_lock(&gr_learn_lock);
56738+ tmp = learn_buffer;
56739+ learn_buffer = NULL;
56740+ spin_unlock(&gr_learn_lock);
56741+ if (tmp)
56742+ vfree(tmp);
56743+ if (learn_buffer_user != NULL) {
56744+ vfree(learn_buffer_user);
56745+ learn_buffer_user = NULL;
56746+ }
56747+ learn_buffer_len = 0;
56748+ mutex_unlock(&gr_learn_user_mutex);
56749+
56750+ return;
56751+}
56752+
56753+void
56754+gr_add_learn_entry(const char *fmt, ...)
56755+{
56756+ va_list args;
56757+ unsigned int len;
56758+
56759+ if (!gr_learn_attached)
56760+ return;
56761+
56762+ spin_lock(&gr_learn_lock);
56763+
56764+ /* leave a gap at the end so we know when it's "full" but don't have to
56765+ compute the exact length of the string we're trying to append
56766+ */
56767+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56768+ spin_unlock(&gr_learn_lock);
56769+ wake_up_interruptible(&learn_wait);
56770+ return;
56771+ }
56772+ if (learn_buffer == NULL) {
56773+ spin_unlock(&gr_learn_lock);
56774+ return;
56775+ }
56776+
56777+ va_start(args, fmt);
56778+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56779+ va_end(args);
56780+
56781+ learn_buffer_len += len + 1;
56782+
56783+ spin_unlock(&gr_learn_lock);
56784+ wake_up_interruptible(&learn_wait);
56785+
56786+ return;
56787+}
56788+
56789+static int
56790+open_learn(struct inode *inode, struct file *file)
56791+{
56792+ if (file->f_mode & FMODE_READ && gr_learn_attached)
56793+ return -EBUSY;
56794+ if (file->f_mode & FMODE_READ) {
56795+ int retval = 0;
56796+ mutex_lock(&gr_learn_user_mutex);
56797+ if (learn_buffer == NULL)
56798+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56799+ if (learn_buffer_user == NULL)
56800+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56801+ if (learn_buffer == NULL) {
56802+ retval = -ENOMEM;
56803+ goto out_error;
56804+ }
56805+ if (learn_buffer_user == NULL) {
56806+ retval = -ENOMEM;
56807+ goto out_error;
56808+ }
56809+ learn_buffer_len = 0;
56810+ learn_buffer_user_len = 0;
56811+ gr_learn_attached = 1;
56812+out_error:
56813+ mutex_unlock(&gr_learn_user_mutex);
56814+ return retval;
56815+ }
56816+ return 0;
56817+}
56818+
56819+static int
56820+close_learn(struct inode *inode, struct file *file)
56821+{
56822+ if (file->f_mode & FMODE_READ) {
56823+ char *tmp = NULL;
56824+ mutex_lock(&gr_learn_user_mutex);
56825+ spin_lock(&gr_learn_lock);
56826+ tmp = learn_buffer;
56827+ learn_buffer = NULL;
56828+ spin_unlock(&gr_learn_lock);
56829+ if (tmp)
56830+ vfree(tmp);
56831+ if (learn_buffer_user != NULL) {
56832+ vfree(learn_buffer_user);
56833+ learn_buffer_user = NULL;
56834+ }
56835+ learn_buffer_len = 0;
56836+ learn_buffer_user_len = 0;
56837+ gr_learn_attached = 0;
56838+ mutex_unlock(&gr_learn_user_mutex);
56839+ }
56840+
56841+ return 0;
56842+}
56843+
56844+const struct file_operations grsec_fops = {
56845+ .read = read_learn,
56846+ .write = write_grsec_handler,
56847+ .open = open_learn,
56848+ .release = close_learn,
56849+ .poll = poll_learn,
56850+};
56851diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56852new file mode 100644
56853index 0000000..39645c9
56854--- /dev/null
56855+++ b/grsecurity/gracl_res.c
56856@@ -0,0 +1,68 @@
56857+#include <linux/kernel.h>
56858+#include <linux/sched.h>
56859+#include <linux/gracl.h>
56860+#include <linux/grinternal.h>
56861+
56862+static const char *restab_log[] = {
56863+ [RLIMIT_CPU] = "RLIMIT_CPU",
56864+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56865+ [RLIMIT_DATA] = "RLIMIT_DATA",
56866+ [RLIMIT_STACK] = "RLIMIT_STACK",
56867+ [RLIMIT_CORE] = "RLIMIT_CORE",
56868+ [RLIMIT_RSS] = "RLIMIT_RSS",
56869+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
56870+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56871+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56872+ [RLIMIT_AS] = "RLIMIT_AS",
56873+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56874+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56875+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56876+ [RLIMIT_NICE] = "RLIMIT_NICE",
56877+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56878+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56879+ [GR_CRASH_RES] = "RLIMIT_CRASH"
56880+};
56881+
56882+void
56883+gr_log_resource(const struct task_struct *task,
56884+ const int res, const unsigned long wanted, const int gt)
56885+{
56886+ const struct cred *cred;
56887+ unsigned long rlim;
56888+
56889+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
56890+ return;
56891+
56892+ // not yet supported resource
56893+ if (unlikely(!restab_log[res]))
56894+ return;
56895+
56896+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56897+ rlim = task_rlimit_max(task, res);
56898+ else
56899+ rlim = task_rlimit(task, res);
56900+
56901+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56902+ return;
56903+
56904+ rcu_read_lock();
56905+ cred = __task_cred(task);
56906+
56907+ if (res == RLIMIT_NPROC &&
56908+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56909+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56910+ goto out_rcu_unlock;
56911+ else if (res == RLIMIT_MEMLOCK &&
56912+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56913+ goto out_rcu_unlock;
56914+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56915+ goto out_rcu_unlock;
56916+ rcu_read_unlock();
56917+
56918+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56919+
56920+ return;
56921+out_rcu_unlock:
56922+ rcu_read_unlock();
56923+ return;
56924+}
56925diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56926new file mode 100644
56927index 0000000..25197e9
56928--- /dev/null
56929+++ b/grsecurity/gracl_segv.c
56930@@ -0,0 +1,299 @@
56931+#include <linux/kernel.h>
56932+#include <linux/mm.h>
56933+#include <asm/uaccess.h>
56934+#include <asm/errno.h>
56935+#include <asm/mman.h>
56936+#include <net/sock.h>
56937+#include <linux/file.h>
56938+#include <linux/fs.h>
56939+#include <linux/net.h>
56940+#include <linux/in.h>
56941+#include <linux/slab.h>
56942+#include <linux/types.h>
56943+#include <linux/sched.h>
56944+#include <linux/timer.h>
56945+#include <linux/gracl.h>
56946+#include <linux/grsecurity.h>
56947+#include <linux/grinternal.h>
56948+
56949+static struct crash_uid *uid_set;
56950+static unsigned short uid_used;
56951+static DEFINE_SPINLOCK(gr_uid_lock);
56952+extern rwlock_t gr_inode_lock;
56953+extern struct acl_subject_label *
56954+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56955+ struct acl_role_label *role);
56956+
56957+#ifdef CONFIG_BTRFS_FS
56958+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56959+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56960+#endif
56961+
56962+static inline dev_t __get_dev(const struct dentry *dentry)
56963+{
56964+#ifdef CONFIG_BTRFS_FS
56965+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56966+ return get_btrfs_dev_from_inode(dentry->d_inode);
56967+ else
56968+#endif
56969+ return dentry->d_inode->i_sb->s_dev;
56970+}
56971+
56972+int
56973+gr_init_uidset(void)
56974+{
56975+ uid_set =
56976+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56977+ uid_used = 0;
56978+
56979+ return uid_set ? 1 : 0;
56980+}
56981+
56982+void
56983+gr_free_uidset(void)
56984+{
56985+ if (uid_set)
56986+ kfree(uid_set);
56987+
56988+ return;
56989+}
56990+
56991+int
56992+gr_find_uid(const uid_t uid)
56993+{
56994+ struct crash_uid *tmp = uid_set;
56995+ uid_t buid;
56996+ int low = 0, high = uid_used - 1, mid;
56997+
56998+ while (high >= low) {
56999+ mid = (low + high) >> 1;
57000+ buid = tmp[mid].uid;
57001+ if (buid == uid)
57002+ return mid;
57003+ if (buid > uid)
57004+ high = mid - 1;
57005+ if (buid < uid)
57006+ low = mid + 1;
57007+ }
57008+
57009+ return -1;
57010+}
57011+
57012+static __inline__ void
57013+gr_insertsort(void)
57014+{
57015+ unsigned short i, j;
57016+ struct crash_uid index;
57017+
57018+ for (i = 1; i < uid_used; i++) {
57019+ index = uid_set[i];
57020+ j = i;
57021+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57022+ uid_set[j] = uid_set[j - 1];
57023+ j--;
57024+ }
57025+ uid_set[j] = index;
57026+ }
57027+
57028+ return;
57029+}
57030+
57031+static __inline__ void
57032+gr_insert_uid(const uid_t uid, const unsigned long expires)
57033+{
57034+ int loc;
57035+
57036+ if (uid_used == GR_UIDTABLE_MAX)
57037+ return;
57038+
57039+ loc = gr_find_uid(uid);
57040+
57041+ if (loc >= 0) {
57042+ uid_set[loc].expires = expires;
57043+ return;
57044+ }
57045+
57046+ uid_set[uid_used].uid = uid;
57047+ uid_set[uid_used].expires = expires;
57048+ uid_used++;
57049+
57050+ gr_insertsort();
57051+
57052+ return;
57053+}
57054+
57055+void
57056+gr_remove_uid(const unsigned short loc)
57057+{
57058+ unsigned short i;
57059+
57060+ for (i = loc + 1; i < uid_used; i++)
57061+ uid_set[i - 1] = uid_set[i];
57062+
57063+ uid_used--;
57064+
57065+ return;
57066+}
57067+
57068+int
57069+gr_check_crash_uid(const uid_t uid)
57070+{
57071+ int loc;
57072+ int ret = 0;
57073+
57074+ if (unlikely(!gr_acl_is_enabled()))
57075+ return 0;
57076+
57077+ spin_lock(&gr_uid_lock);
57078+ loc = gr_find_uid(uid);
57079+
57080+ if (loc < 0)
57081+ goto out_unlock;
57082+
57083+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
57084+ gr_remove_uid(loc);
57085+ else
57086+ ret = 1;
57087+
57088+out_unlock:
57089+ spin_unlock(&gr_uid_lock);
57090+ return ret;
57091+}
57092+
57093+static __inline__ int
57094+proc_is_setxid(const struct cred *cred)
57095+{
57096+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57097+ !uid_eq(cred->uid, cred->fsuid))
57098+ return 1;
57099+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57100+ !uid_eq(cred->gid, cred->fsgid))
57101+ return 1;
57102+
57103+ return 0;
57104+}
57105+
57106+extern int gr_fake_force_sig(int sig, struct task_struct *t);
57107+
57108+void
57109+gr_handle_crash(struct task_struct *task, const int sig)
57110+{
57111+ struct acl_subject_label *curr;
57112+ struct task_struct *tsk, *tsk2;
57113+ const struct cred *cred;
57114+ const struct cred *cred2;
57115+
57116+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57117+ return;
57118+
57119+ if (unlikely(!gr_acl_is_enabled()))
57120+ return;
57121+
57122+ curr = task->acl;
57123+
57124+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
57125+ return;
57126+
57127+ if (time_before_eq(curr->expires, get_seconds())) {
57128+ curr->expires = 0;
57129+ curr->crashes = 0;
57130+ }
57131+
57132+ curr->crashes++;
57133+
57134+ if (!curr->expires)
57135+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57136+
57137+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57138+ time_after(curr->expires, get_seconds())) {
57139+ rcu_read_lock();
57140+ cred = __task_cred(task);
57141+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57142+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57143+ spin_lock(&gr_uid_lock);
57144+ gr_insert_uid(cred->uid, curr->expires);
57145+ spin_unlock(&gr_uid_lock);
57146+ curr->expires = 0;
57147+ curr->crashes = 0;
57148+ read_lock(&tasklist_lock);
57149+ do_each_thread(tsk2, tsk) {
57150+ cred2 = __task_cred(tsk);
57151+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
57152+ gr_fake_force_sig(SIGKILL, tsk);
57153+ } while_each_thread(tsk2, tsk);
57154+ read_unlock(&tasklist_lock);
57155+ } else {
57156+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57157+ read_lock(&tasklist_lock);
57158+ read_lock(&grsec_exec_file_lock);
57159+ do_each_thread(tsk2, tsk) {
57160+ if (likely(tsk != task)) {
57161+ // if this thread has the same subject as the one that triggered
57162+ // RES_CRASH and it's the same binary, kill it
57163+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57164+ gr_fake_force_sig(SIGKILL, tsk);
57165+ }
57166+ } while_each_thread(tsk2, tsk);
57167+ read_unlock(&grsec_exec_file_lock);
57168+ read_unlock(&tasklist_lock);
57169+ }
57170+ rcu_read_unlock();
57171+ }
57172+
57173+ return;
57174+}
57175+
57176+int
57177+gr_check_crash_exec(const struct file *filp)
57178+{
57179+ struct acl_subject_label *curr;
57180+
57181+ if (unlikely(!gr_acl_is_enabled()))
57182+ return 0;
57183+
57184+ read_lock(&gr_inode_lock);
57185+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57186+ __get_dev(filp->f_path.dentry),
57187+ current->role);
57188+ read_unlock(&gr_inode_lock);
57189+
57190+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57191+ (!curr->crashes && !curr->expires))
57192+ return 0;
57193+
57194+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57195+ time_after(curr->expires, get_seconds()))
57196+ return 1;
57197+ else if (time_before_eq(curr->expires, get_seconds())) {
57198+ curr->crashes = 0;
57199+ curr->expires = 0;
57200+ }
57201+
57202+ return 0;
57203+}
57204+
57205+void
57206+gr_handle_alertkill(struct task_struct *task)
57207+{
57208+ struct acl_subject_label *curracl;
57209+ __u32 curr_ip;
57210+ struct task_struct *p, *p2;
57211+
57212+ if (unlikely(!gr_acl_is_enabled()))
57213+ return;
57214+
57215+ curracl = task->acl;
57216+ curr_ip = task->signal->curr_ip;
57217+
57218+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57219+ read_lock(&tasklist_lock);
57220+ do_each_thread(p2, p) {
57221+ if (p->signal->curr_ip == curr_ip)
57222+ gr_fake_force_sig(SIGKILL, p);
57223+ } while_each_thread(p2, p);
57224+ read_unlock(&tasklist_lock);
57225+ } else if (curracl->mode & GR_KILLPROC)
57226+ gr_fake_force_sig(SIGKILL, task);
57227+
57228+ return;
57229+}
57230diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57231new file mode 100644
57232index 0000000..9d83a69
57233--- /dev/null
57234+++ b/grsecurity/gracl_shm.c
57235@@ -0,0 +1,40 @@
57236+#include <linux/kernel.h>
57237+#include <linux/mm.h>
57238+#include <linux/sched.h>
57239+#include <linux/file.h>
57240+#include <linux/ipc.h>
57241+#include <linux/gracl.h>
57242+#include <linux/grsecurity.h>
57243+#include <linux/grinternal.h>
57244+
57245+int
57246+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57247+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57248+{
57249+ struct task_struct *task;
57250+
57251+ if (!gr_acl_is_enabled())
57252+ return 1;
57253+
57254+ rcu_read_lock();
57255+ read_lock(&tasklist_lock);
57256+
57257+ task = find_task_by_vpid(shm_cprid);
57258+
57259+ if (unlikely(!task))
57260+ task = find_task_by_vpid(shm_lapid);
57261+
57262+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57263+ (task->pid == shm_lapid)) &&
57264+ (task->acl->mode & GR_PROTSHM) &&
57265+ (task->acl != current->acl))) {
57266+ read_unlock(&tasklist_lock);
57267+ rcu_read_unlock();
57268+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57269+ return 0;
57270+ }
57271+ read_unlock(&tasklist_lock);
57272+ rcu_read_unlock();
57273+
57274+ return 1;
57275+}
57276diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57277new file mode 100644
57278index 0000000..bc0be01
57279--- /dev/null
57280+++ b/grsecurity/grsec_chdir.c
57281@@ -0,0 +1,19 @@
57282+#include <linux/kernel.h>
57283+#include <linux/sched.h>
57284+#include <linux/fs.h>
57285+#include <linux/file.h>
57286+#include <linux/grsecurity.h>
57287+#include <linux/grinternal.h>
57288+
57289+void
57290+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57291+{
57292+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57293+ if ((grsec_enable_chdir && grsec_enable_group &&
57294+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57295+ !grsec_enable_group)) {
57296+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57297+ }
57298+#endif
57299+ return;
57300+}
57301diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57302new file mode 100644
57303index 0000000..9807ee2
57304--- /dev/null
57305+++ b/grsecurity/grsec_chroot.c
57306@@ -0,0 +1,368 @@
57307+#include <linux/kernel.h>
57308+#include <linux/module.h>
57309+#include <linux/sched.h>
57310+#include <linux/file.h>
57311+#include <linux/fs.h>
57312+#include <linux/mount.h>
57313+#include <linux/types.h>
57314+#include "../fs/mount.h"
57315+#include <linux/grsecurity.h>
57316+#include <linux/grinternal.h>
57317+
57318+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57319+{
57320+#ifdef CONFIG_GRKERNSEC
57321+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57322+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57323+ task->gr_is_chrooted = 1;
57324+ else
57325+ task->gr_is_chrooted = 0;
57326+
57327+ task->gr_chroot_dentry = path->dentry;
57328+#endif
57329+ return;
57330+}
57331+
57332+void gr_clear_chroot_entries(struct task_struct *task)
57333+{
57334+#ifdef CONFIG_GRKERNSEC
57335+ task->gr_is_chrooted = 0;
57336+ task->gr_chroot_dentry = NULL;
57337+#endif
57338+ return;
57339+}
57340+
57341+int
57342+gr_handle_chroot_unix(const pid_t pid)
57343+{
57344+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57345+ struct task_struct *p;
57346+
57347+ if (unlikely(!grsec_enable_chroot_unix))
57348+ return 1;
57349+
57350+ if (likely(!proc_is_chrooted(current)))
57351+ return 1;
57352+
57353+ rcu_read_lock();
57354+ read_lock(&tasklist_lock);
57355+ p = find_task_by_vpid_unrestricted(pid);
57356+ if (unlikely(p && !have_same_root(current, p))) {
57357+ read_unlock(&tasklist_lock);
57358+ rcu_read_unlock();
57359+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57360+ return 0;
57361+ }
57362+ read_unlock(&tasklist_lock);
57363+ rcu_read_unlock();
57364+#endif
57365+ return 1;
57366+}
57367+
57368+int
57369+gr_handle_chroot_nice(void)
57370+{
57371+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57372+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57373+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57374+ return -EPERM;
57375+ }
57376+#endif
57377+ return 0;
57378+}
57379+
57380+int
57381+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57382+{
57383+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57384+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57385+ && proc_is_chrooted(current)) {
57386+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57387+ return -EACCES;
57388+ }
57389+#endif
57390+ return 0;
57391+}
57392+
57393+int
57394+gr_handle_chroot_rawio(const struct inode *inode)
57395+{
57396+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57397+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57398+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57399+ return 1;
57400+#endif
57401+ return 0;
57402+}
57403+
57404+int
57405+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57406+{
57407+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57408+ struct task_struct *p;
57409+ int ret = 0;
57410+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57411+ return ret;
57412+
57413+ read_lock(&tasklist_lock);
57414+ do_each_pid_task(pid, type, p) {
57415+ if (!have_same_root(current, p)) {
57416+ ret = 1;
57417+ goto out;
57418+ }
57419+ } while_each_pid_task(pid, type, p);
57420+out:
57421+ read_unlock(&tasklist_lock);
57422+ return ret;
57423+#endif
57424+ return 0;
57425+}
57426+
57427+int
57428+gr_pid_is_chrooted(struct task_struct *p)
57429+{
57430+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57431+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57432+ return 0;
57433+
57434+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57435+ !have_same_root(current, p)) {
57436+ return 1;
57437+ }
57438+#endif
57439+ return 0;
57440+}
57441+
57442+EXPORT_SYMBOL(gr_pid_is_chrooted);
57443+
57444+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57445+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57446+{
57447+ struct path path, currentroot;
57448+ int ret = 0;
57449+
57450+ path.dentry = (struct dentry *)u_dentry;
57451+ path.mnt = (struct vfsmount *)u_mnt;
57452+ get_fs_root(current->fs, &currentroot);
57453+ if (path_is_under(&path, &currentroot))
57454+ ret = 1;
57455+ path_put(&currentroot);
57456+
57457+ return ret;
57458+}
57459+#endif
57460+
57461+int
57462+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57463+{
57464+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57465+ if (!grsec_enable_chroot_fchdir)
57466+ return 1;
57467+
57468+ if (!proc_is_chrooted(current))
57469+ return 1;
57470+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57471+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57472+ return 0;
57473+ }
57474+#endif
57475+ return 1;
57476+}
57477+
57478+int
57479+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57480+ const time_t shm_createtime)
57481+{
57482+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57483+ struct task_struct *p;
57484+ time_t starttime;
57485+
57486+ if (unlikely(!grsec_enable_chroot_shmat))
57487+ return 1;
57488+
57489+ if (likely(!proc_is_chrooted(current)))
57490+ return 1;
57491+
57492+ rcu_read_lock();
57493+ read_lock(&tasklist_lock);
57494+
57495+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57496+ starttime = p->start_time.tv_sec;
57497+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57498+ if (have_same_root(current, p)) {
57499+ goto allow;
57500+ } else {
57501+ read_unlock(&tasklist_lock);
57502+ rcu_read_unlock();
57503+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57504+ return 0;
57505+ }
57506+ }
57507+ /* creator exited, pid reuse, fall through to next check */
57508+ }
57509+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57510+ if (unlikely(!have_same_root(current, p))) {
57511+ read_unlock(&tasklist_lock);
57512+ rcu_read_unlock();
57513+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57514+ return 0;
57515+ }
57516+ }
57517+
57518+allow:
57519+ read_unlock(&tasklist_lock);
57520+ rcu_read_unlock();
57521+#endif
57522+ return 1;
57523+}
57524+
57525+void
57526+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57527+{
57528+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57529+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57530+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57531+#endif
57532+ return;
57533+}
57534+
57535+int
57536+gr_handle_chroot_mknod(const struct dentry *dentry,
57537+ const struct vfsmount *mnt, const int mode)
57538+{
57539+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57540+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57541+ proc_is_chrooted(current)) {
57542+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57543+ return -EPERM;
57544+ }
57545+#endif
57546+ return 0;
57547+}
57548+
57549+int
57550+gr_handle_chroot_mount(const struct dentry *dentry,
57551+ const struct vfsmount *mnt, const char *dev_name)
57552+{
57553+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57554+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57555+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57556+ return -EPERM;
57557+ }
57558+#endif
57559+ return 0;
57560+}
57561+
57562+int
57563+gr_handle_chroot_pivot(void)
57564+{
57565+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57566+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57567+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57568+ return -EPERM;
57569+ }
57570+#endif
57571+ return 0;
57572+}
57573+
57574+int
57575+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57576+{
57577+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57578+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57579+ !gr_is_outside_chroot(dentry, mnt)) {
57580+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57581+ return -EPERM;
57582+ }
57583+#endif
57584+ return 0;
57585+}
57586+
57587+extern const char *captab_log[];
57588+extern int captab_log_entries;
57589+
57590+int
57591+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57592+{
57593+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57594+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57595+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57596+ if (cap_raised(chroot_caps, cap)) {
57597+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57598+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57599+ }
57600+ return 0;
57601+ }
57602+ }
57603+#endif
57604+ return 1;
57605+}
57606+
57607+int
57608+gr_chroot_is_capable(const int cap)
57609+{
57610+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57611+ return gr_task_chroot_is_capable(current, current_cred(), cap);
57612+#endif
57613+ return 1;
57614+}
57615+
57616+int
57617+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57618+{
57619+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57620+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57621+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57622+ if (cap_raised(chroot_caps, cap)) {
57623+ return 0;
57624+ }
57625+ }
57626+#endif
57627+ return 1;
57628+}
57629+
57630+int
57631+gr_chroot_is_capable_nolog(const int cap)
57632+{
57633+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57634+ return gr_task_chroot_is_capable_nolog(current, cap);
57635+#endif
57636+ return 1;
57637+}
57638+
57639+int
57640+gr_handle_chroot_sysctl(const int op)
57641+{
57642+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57643+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57644+ proc_is_chrooted(current))
57645+ return -EACCES;
57646+#endif
57647+ return 0;
57648+}
57649+
57650+void
57651+gr_handle_chroot_chdir(struct path *path)
57652+{
57653+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57654+ if (grsec_enable_chroot_chdir)
57655+ set_fs_pwd(current->fs, path);
57656+#endif
57657+ return;
57658+}
57659+
57660+int
57661+gr_handle_chroot_chmod(const struct dentry *dentry,
57662+ const struct vfsmount *mnt, const int mode)
57663+{
57664+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57665+ /* allow chmod +s on directories, but not files */
57666+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57667+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57668+ proc_is_chrooted(current)) {
57669+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57670+ return -EPERM;
57671+ }
57672+#endif
57673+ return 0;
57674+}
57675diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57676new file mode 100644
57677index 0000000..213ad8b
57678--- /dev/null
57679+++ b/grsecurity/grsec_disabled.c
57680@@ -0,0 +1,437 @@
57681+#include <linux/kernel.h>
57682+#include <linux/module.h>
57683+#include <linux/sched.h>
57684+#include <linux/file.h>
57685+#include <linux/fs.h>
57686+#include <linux/kdev_t.h>
57687+#include <linux/net.h>
57688+#include <linux/in.h>
57689+#include <linux/ip.h>
57690+#include <linux/skbuff.h>
57691+#include <linux/sysctl.h>
57692+
57693+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57694+void
57695+pax_set_initial_flags(struct linux_binprm *bprm)
57696+{
57697+ return;
57698+}
57699+#endif
57700+
57701+#ifdef CONFIG_SYSCTL
57702+__u32
57703+gr_handle_sysctl(const struct ctl_table * table, const int op)
57704+{
57705+ return 0;
57706+}
57707+#endif
57708+
57709+#ifdef CONFIG_TASKSTATS
57710+int gr_is_taskstats_denied(int pid)
57711+{
57712+ return 0;
57713+}
57714+#endif
57715+
57716+int
57717+gr_acl_is_enabled(void)
57718+{
57719+ return 0;
57720+}
57721+
57722+void
57723+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57724+{
57725+ return;
57726+}
57727+
57728+int
57729+gr_handle_rawio(const struct inode *inode)
57730+{
57731+ return 0;
57732+}
57733+
57734+void
57735+gr_acl_handle_psacct(struct task_struct *task, const long code)
57736+{
57737+ return;
57738+}
57739+
57740+int
57741+gr_handle_ptrace(struct task_struct *task, const long request)
57742+{
57743+ return 0;
57744+}
57745+
57746+int
57747+gr_handle_proc_ptrace(struct task_struct *task)
57748+{
57749+ return 0;
57750+}
57751+
57752+void
57753+gr_learn_resource(const struct task_struct *task,
57754+ const int res, const unsigned long wanted, const int gt)
57755+{
57756+ return;
57757+}
57758+
57759+int
57760+gr_set_acls(const int type)
57761+{
57762+ return 0;
57763+}
57764+
57765+int
57766+gr_check_hidden_task(const struct task_struct *tsk)
57767+{
57768+ return 0;
57769+}
57770+
57771+int
57772+gr_check_protected_task(const struct task_struct *task)
57773+{
57774+ return 0;
57775+}
57776+
57777+int
57778+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57779+{
57780+ return 0;
57781+}
57782+
57783+void
57784+gr_copy_label(struct task_struct *tsk)
57785+{
57786+ return;
57787+}
57788+
57789+void
57790+gr_set_pax_flags(struct task_struct *task)
57791+{
57792+ return;
57793+}
57794+
57795+int
57796+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57797+ const int unsafe_share)
57798+{
57799+ return 0;
57800+}
57801+
57802+void
57803+gr_handle_delete(const ino_t ino, const dev_t dev)
57804+{
57805+ return;
57806+}
57807+
57808+void
57809+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57810+{
57811+ return;
57812+}
57813+
57814+void
57815+gr_handle_crash(struct task_struct *task, const int sig)
57816+{
57817+ return;
57818+}
57819+
57820+int
57821+gr_check_crash_exec(const struct file *filp)
57822+{
57823+ return 0;
57824+}
57825+
57826+int
57827+gr_check_crash_uid(const uid_t uid)
57828+{
57829+ return 0;
57830+}
57831+
57832+void
57833+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57834+ struct dentry *old_dentry,
57835+ struct dentry *new_dentry,
57836+ struct vfsmount *mnt, const __u8 replace)
57837+{
57838+ return;
57839+}
57840+
57841+int
57842+gr_search_socket(const int family, const int type, const int protocol)
57843+{
57844+ return 1;
57845+}
57846+
57847+int
57848+gr_search_connectbind(const int mode, const struct socket *sock,
57849+ const struct sockaddr_in *addr)
57850+{
57851+ return 0;
57852+}
57853+
57854+void
57855+gr_handle_alertkill(struct task_struct *task)
57856+{
57857+ return;
57858+}
57859+
57860+__u32
57861+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57862+{
57863+ return 1;
57864+}
57865+
57866+__u32
57867+gr_acl_handle_hidden_file(const struct dentry * dentry,
57868+ const struct vfsmount * mnt)
57869+{
57870+ return 1;
57871+}
57872+
57873+__u32
57874+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57875+ int acc_mode)
57876+{
57877+ return 1;
57878+}
57879+
57880+__u32
57881+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57882+{
57883+ return 1;
57884+}
57885+
57886+__u32
57887+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57888+{
57889+ return 1;
57890+}
57891+
57892+int
57893+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57894+ unsigned int *vm_flags)
57895+{
57896+ return 1;
57897+}
57898+
57899+__u32
57900+gr_acl_handle_truncate(const struct dentry * dentry,
57901+ const struct vfsmount * mnt)
57902+{
57903+ return 1;
57904+}
57905+
57906+__u32
57907+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57908+{
57909+ return 1;
57910+}
57911+
57912+__u32
57913+gr_acl_handle_access(const struct dentry * dentry,
57914+ const struct vfsmount * mnt, const int fmode)
57915+{
57916+ return 1;
57917+}
57918+
57919+__u32
57920+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57921+ umode_t *mode)
57922+{
57923+ return 1;
57924+}
57925+
57926+__u32
57927+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57928+{
57929+ return 1;
57930+}
57931+
57932+__u32
57933+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57934+{
57935+ return 1;
57936+}
57937+
57938+void
57939+grsecurity_init(void)
57940+{
57941+ return;
57942+}
57943+
57944+umode_t gr_acl_umask(void)
57945+{
57946+ return 0;
57947+}
57948+
57949+__u32
57950+gr_acl_handle_mknod(const struct dentry * new_dentry,
57951+ const struct dentry * parent_dentry,
57952+ const struct vfsmount * parent_mnt,
57953+ const int mode)
57954+{
57955+ return 1;
57956+}
57957+
57958+__u32
57959+gr_acl_handle_mkdir(const struct dentry * new_dentry,
57960+ const struct dentry * parent_dentry,
57961+ const struct vfsmount * parent_mnt)
57962+{
57963+ return 1;
57964+}
57965+
57966+__u32
57967+gr_acl_handle_symlink(const struct dentry * new_dentry,
57968+ const struct dentry * parent_dentry,
57969+ const struct vfsmount * parent_mnt, const char *from)
57970+{
57971+ return 1;
57972+}
57973+
57974+__u32
57975+gr_acl_handle_link(const struct dentry * new_dentry,
57976+ const struct dentry * parent_dentry,
57977+ const struct vfsmount * parent_mnt,
57978+ const struct dentry * old_dentry,
57979+ const struct vfsmount * old_mnt, const char *to)
57980+{
57981+ return 1;
57982+}
57983+
57984+int
57985+gr_acl_handle_rename(const struct dentry *new_dentry,
57986+ const struct dentry *parent_dentry,
57987+ const struct vfsmount *parent_mnt,
57988+ const struct dentry *old_dentry,
57989+ const struct inode *old_parent_inode,
57990+ const struct vfsmount *old_mnt, const char *newname)
57991+{
57992+ return 0;
57993+}
57994+
57995+int
57996+gr_acl_handle_filldir(const struct file *file, const char *name,
57997+ const int namelen, const ino_t ino)
57998+{
57999+ return 1;
58000+}
58001+
58002+int
58003+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58004+ const time_t shm_createtime, const uid_t cuid, const int shmid)
58005+{
58006+ return 1;
58007+}
58008+
58009+int
58010+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58011+{
58012+ return 0;
58013+}
58014+
58015+int
58016+gr_search_accept(const struct socket *sock)
58017+{
58018+ return 0;
58019+}
58020+
58021+int
58022+gr_search_listen(const struct socket *sock)
58023+{
58024+ return 0;
58025+}
58026+
58027+int
58028+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58029+{
58030+ return 0;
58031+}
58032+
58033+__u32
58034+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58035+{
58036+ return 1;
58037+}
58038+
58039+__u32
58040+gr_acl_handle_creat(const struct dentry * dentry,
58041+ const struct dentry * p_dentry,
58042+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58043+ const int imode)
58044+{
58045+ return 1;
58046+}
58047+
58048+void
58049+gr_acl_handle_exit(void)
58050+{
58051+ return;
58052+}
58053+
58054+int
58055+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58056+{
58057+ return 1;
58058+}
58059+
58060+void
58061+gr_set_role_label(const uid_t uid, const gid_t gid)
58062+{
58063+ return;
58064+}
58065+
58066+int
58067+gr_acl_handle_procpidmem(const struct task_struct *task)
58068+{
58069+ return 0;
58070+}
58071+
58072+int
58073+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58074+{
58075+ return 0;
58076+}
58077+
58078+int
58079+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58080+{
58081+ return 0;
58082+}
58083+
58084+void
58085+gr_set_kernel_label(struct task_struct *task)
58086+{
58087+ return;
58088+}
58089+
58090+int
58091+gr_check_user_change(int real, int effective, int fs)
58092+{
58093+ return 0;
58094+}
58095+
58096+int
58097+gr_check_group_change(int real, int effective, int fs)
58098+{
58099+ return 0;
58100+}
58101+
58102+int gr_acl_enable_at_secure(void)
58103+{
58104+ return 0;
58105+}
58106+
58107+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58108+{
58109+ return dentry->d_inode->i_sb->s_dev;
58110+}
58111+
58112+EXPORT_SYMBOL(gr_learn_resource);
58113+EXPORT_SYMBOL(gr_set_kernel_label);
58114+#ifdef CONFIG_SECURITY
58115+EXPORT_SYMBOL(gr_check_user_change);
58116+EXPORT_SYMBOL(gr_check_group_change);
58117+#endif
58118diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58119new file mode 100644
58120index 0000000..abfa971
58121--- /dev/null
58122+++ b/grsecurity/grsec_exec.c
58123@@ -0,0 +1,174 @@
58124+#include <linux/kernel.h>
58125+#include <linux/sched.h>
58126+#include <linux/file.h>
58127+#include <linux/binfmts.h>
58128+#include <linux/fs.h>
58129+#include <linux/types.h>
58130+#include <linux/grdefs.h>
58131+#include <linux/grsecurity.h>
58132+#include <linux/grinternal.h>
58133+#include <linux/capability.h>
58134+#include <linux/module.h>
58135+
58136+#include <asm/uaccess.h>
58137+
58138+#ifdef CONFIG_GRKERNSEC_EXECLOG
58139+static char gr_exec_arg_buf[132];
58140+static DEFINE_MUTEX(gr_exec_arg_mutex);
58141+#endif
58142+
58143+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58144+
58145+void
58146+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58147+{
58148+#ifdef CONFIG_GRKERNSEC_EXECLOG
58149+ char *grarg = gr_exec_arg_buf;
58150+ unsigned int i, x, execlen = 0;
58151+ char c;
58152+
58153+ if (!((grsec_enable_execlog && grsec_enable_group &&
58154+ in_group_p(grsec_audit_gid))
58155+ || (grsec_enable_execlog && !grsec_enable_group)))
58156+ return;
58157+
58158+ mutex_lock(&gr_exec_arg_mutex);
58159+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
58160+
58161+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
58162+ const char __user *p;
58163+ unsigned int len;
58164+
58165+ p = get_user_arg_ptr(argv, i);
58166+ if (IS_ERR(p))
58167+ goto log;
58168+
58169+ len = strnlen_user(p, 128 - execlen);
58170+ if (len > 128 - execlen)
58171+ len = 128 - execlen;
58172+ else if (len > 0)
58173+ len--;
58174+ if (copy_from_user(grarg + execlen, p, len))
58175+ goto log;
58176+
58177+ /* rewrite unprintable characters */
58178+ for (x = 0; x < len; x++) {
58179+ c = *(grarg + execlen + x);
58180+ if (c < 32 || c > 126)
58181+ *(grarg + execlen + x) = ' ';
58182+ }
58183+
58184+ execlen += len;
58185+ *(grarg + execlen) = ' ';
58186+ *(grarg + execlen + 1) = '\0';
58187+ execlen++;
58188+ }
58189+
58190+ log:
58191+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58192+ bprm->file->f_path.mnt, grarg);
58193+ mutex_unlock(&gr_exec_arg_mutex);
58194+#endif
58195+ return;
58196+}
58197+
58198+#ifdef CONFIG_GRKERNSEC
58199+extern int gr_acl_is_capable(const int cap);
58200+extern int gr_acl_is_capable_nolog(const int cap);
58201+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58202+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58203+extern int gr_chroot_is_capable(const int cap);
58204+extern int gr_chroot_is_capable_nolog(const int cap);
58205+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58206+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58207+#endif
58208+
58209+const char *captab_log[] = {
58210+ "CAP_CHOWN",
58211+ "CAP_DAC_OVERRIDE",
58212+ "CAP_DAC_READ_SEARCH",
58213+ "CAP_FOWNER",
58214+ "CAP_FSETID",
58215+ "CAP_KILL",
58216+ "CAP_SETGID",
58217+ "CAP_SETUID",
58218+ "CAP_SETPCAP",
58219+ "CAP_LINUX_IMMUTABLE",
58220+ "CAP_NET_BIND_SERVICE",
58221+ "CAP_NET_BROADCAST",
58222+ "CAP_NET_ADMIN",
58223+ "CAP_NET_RAW",
58224+ "CAP_IPC_LOCK",
58225+ "CAP_IPC_OWNER",
58226+ "CAP_SYS_MODULE",
58227+ "CAP_SYS_RAWIO",
58228+ "CAP_SYS_CHROOT",
58229+ "CAP_SYS_PTRACE",
58230+ "CAP_SYS_PACCT",
58231+ "CAP_SYS_ADMIN",
58232+ "CAP_SYS_BOOT",
58233+ "CAP_SYS_NICE",
58234+ "CAP_SYS_RESOURCE",
58235+ "CAP_SYS_TIME",
58236+ "CAP_SYS_TTY_CONFIG",
58237+ "CAP_MKNOD",
58238+ "CAP_LEASE",
58239+ "CAP_AUDIT_WRITE",
58240+ "CAP_AUDIT_CONTROL",
58241+ "CAP_SETFCAP",
58242+ "CAP_MAC_OVERRIDE",
58243+ "CAP_MAC_ADMIN",
58244+ "CAP_SYSLOG",
58245+ "CAP_WAKE_ALARM"
58246+};
58247+
58248+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58249+
58250+int gr_is_capable(const int cap)
58251+{
58252+#ifdef CONFIG_GRKERNSEC
58253+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58254+ return 1;
58255+ return 0;
58256+#else
58257+ return 1;
58258+#endif
58259+}
58260+
58261+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58262+{
58263+#ifdef CONFIG_GRKERNSEC
58264+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58265+ return 1;
58266+ return 0;
58267+#else
58268+ return 1;
58269+#endif
58270+}
58271+
58272+int gr_is_capable_nolog(const int cap)
58273+{
58274+#ifdef CONFIG_GRKERNSEC
58275+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58276+ return 1;
58277+ return 0;
58278+#else
58279+ return 1;
58280+#endif
58281+}
58282+
58283+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58284+{
58285+#ifdef CONFIG_GRKERNSEC
58286+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58287+ return 1;
58288+ return 0;
58289+#else
58290+ return 1;
58291+#endif
58292+}
58293+
58294+EXPORT_SYMBOL(gr_is_capable);
58295+EXPORT_SYMBOL(gr_is_capable_nolog);
58296+EXPORT_SYMBOL(gr_task_is_capable);
58297+EXPORT_SYMBOL(gr_task_is_capable_nolog);
58298diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58299new file mode 100644
58300index 0000000..d3ee748
58301--- /dev/null
58302+++ b/grsecurity/grsec_fifo.c
58303@@ -0,0 +1,24 @@
58304+#include <linux/kernel.h>
58305+#include <linux/sched.h>
58306+#include <linux/fs.h>
58307+#include <linux/file.h>
58308+#include <linux/grinternal.h>
58309+
58310+int
58311+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58312+ const struct dentry *dir, const int flag, const int acc_mode)
58313+{
58314+#ifdef CONFIG_GRKERNSEC_FIFO
58315+ const struct cred *cred = current_cred();
58316+
58317+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58318+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58319+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58320+ (cred->fsuid != dentry->d_inode->i_uid)) {
58321+ if (!inode_permission(dentry->d_inode, acc_mode))
58322+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58323+ return -EACCES;
58324+ }
58325+#endif
58326+ return 0;
58327+}
58328diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58329new file mode 100644
58330index 0000000..8ca18bf
58331--- /dev/null
58332+++ b/grsecurity/grsec_fork.c
58333@@ -0,0 +1,23 @@
58334+#include <linux/kernel.h>
58335+#include <linux/sched.h>
58336+#include <linux/grsecurity.h>
58337+#include <linux/grinternal.h>
58338+#include <linux/errno.h>
58339+
58340+void
58341+gr_log_forkfail(const int retval)
58342+{
58343+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58344+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58345+ switch (retval) {
58346+ case -EAGAIN:
58347+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58348+ break;
58349+ case -ENOMEM:
58350+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58351+ break;
58352+ }
58353+ }
58354+#endif
58355+ return;
58356+}
58357diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58358new file mode 100644
58359index 0000000..05a6015
58360--- /dev/null
58361+++ b/grsecurity/grsec_init.c
58362@@ -0,0 +1,283 @@
58363+#include <linux/kernel.h>
58364+#include <linux/sched.h>
58365+#include <linux/mm.h>
58366+#include <linux/gracl.h>
58367+#include <linux/slab.h>
58368+#include <linux/vmalloc.h>
58369+#include <linux/percpu.h>
58370+#include <linux/module.h>
58371+
58372+int grsec_enable_ptrace_readexec;
58373+int grsec_enable_setxid;
58374+int grsec_enable_symlinkown;
58375+int grsec_symlinkown_gid;
58376+int grsec_enable_brute;
58377+int grsec_enable_link;
58378+int grsec_enable_dmesg;
58379+int grsec_enable_harden_ptrace;
58380+int grsec_enable_fifo;
58381+int grsec_enable_execlog;
58382+int grsec_enable_signal;
58383+int grsec_enable_forkfail;
58384+int grsec_enable_audit_ptrace;
58385+int grsec_enable_time;
58386+int grsec_enable_audit_textrel;
58387+int grsec_enable_group;
58388+int grsec_audit_gid;
58389+int grsec_enable_chdir;
58390+int grsec_enable_mount;
58391+int grsec_enable_rofs;
58392+int grsec_enable_chroot_findtask;
58393+int grsec_enable_chroot_mount;
58394+int grsec_enable_chroot_shmat;
58395+int grsec_enable_chroot_fchdir;
58396+int grsec_enable_chroot_double;
58397+int grsec_enable_chroot_pivot;
58398+int grsec_enable_chroot_chdir;
58399+int grsec_enable_chroot_chmod;
58400+int grsec_enable_chroot_mknod;
58401+int grsec_enable_chroot_nice;
58402+int grsec_enable_chroot_execlog;
58403+int grsec_enable_chroot_caps;
58404+int grsec_enable_chroot_sysctl;
58405+int grsec_enable_chroot_unix;
58406+int grsec_enable_tpe;
58407+int grsec_tpe_gid;
58408+int grsec_enable_blackhole;
58409+#ifdef CONFIG_IPV6_MODULE
58410+EXPORT_SYMBOL(grsec_enable_blackhole);
58411+#endif
58412+int grsec_lastack_retries;
58413+int grsec_enable_tpe_all;
58414+int grsec_enable_tpe_invert;
58415+int grsec_enable_socket_all;
58416+int grsec_socket_all_gid;
58417+int grsec_enable_socket_client;
58418+int grsec_socket_client_gid;
58419+int grsec_enable_socket_server;
58420+int grsec_socket_server_gid;
58421+int grsec_resource_logging;
58422+int grsec_disable_privio;
58423+int grsec_enable_log_rwxmaps;
58424+int grsec_lock;
58425+
58426+DEFINE_SPINLOCK(grsec_alert_lock);
58427+unsigned long grsec_alert_wtime = 0;
58428+unsigned long grsec_alert_fyet = 0;
58429+
58430+DEFINE_SPINLOCK(grsec_audit_lock);
58431+
58432+DEFINE_RWLOCK(grsec_exec_file_lock);
58433+
58434+char *gr_shared_page[4];
58435+
58436+char *gr_alert_log_fmt;
58437+char *gr_audit_log_fmt;
58438+char *gr_alert_log_buf;
58439+char *gr_audit_log_buf;
58440+
58441+extern struct gr_arg *gr_usermode;
58442+extern unsigned char *gr_system_salt;
58443+extern unsigned char *gr_system_sum;
58444+
58445+void __init
58446+grsecurity_init(void)
58447+{
58448+ int j;
58449+ /* create the per-cpu shared pages */
58450+
58451+#ifdef CONFIG_X86
58452+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58453+#endif
58454+
58455+ for (j = 0; j < 4; j++) {
58456+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58457+ if (gr_shared_page[j] == NULL) {
58458+ panic("Unable to allocate grsecurity shared page");
58459+ return;
58460+ }
58461+ }
58462+
58463+ /* allocate log buffers */
58464+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58465+ if (!gr_alert_log_fmt) {
58466+ panic("Unable to allocate grsecurity alert log format buffer");
58467+ return;
58468+ }
58469+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58470+ if (!gr_audit_log_fmt) {
58471+ panic("Unable to allocate grsecurity audit log format buffer");
58472+ return;
58473+ }
58474+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58475+ if (!gr_alert_log_buf) {
58476+ panic("Unable to allocate grsecurity alert log buffer");
58477+ return;
58478+ }
58479+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58480+ if (!gr_audit_log_buf) {
58481+ panic("Unable to allocate grsecurity audit log buffer");
58482+ return;
58483+ }
58484+
58485+ /* allocate memory for authentication structure */
58486+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58487+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58488+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58489+
58490+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58491+ panic("Unable to allocate grsecurity authentication structure");
58492+ return;
58493+ }
58494+
58495+
58496+#ifdef CONFIG_GRKERNSEC_IO
58497+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58498+ grsec_disable_privio = 1;
58499+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58500+ grsec_disable_privio = 1;
58501+#else
58502+ grsec_disable_privio = 0;
58503+#endif
58504+#endif
58505+
58506+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58507+ /* for backward compatibility, tpe_invert always defaults to on if
58508+ enabled in the kernel
58509+ */
58510+ grsec_enable_tpe_invert = 1;
58511+#endif
58512+
58513+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58514+#ifndef CONFIG_GRKERNSEC_SYSCTL
58515+ grsec_lock = 1;
58516+#endif
58517+
58518+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58519+ grsec_enable_audit_textrel = 1;
58520+#endif
58521+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58522+ grsec_enable_log_rwxmaps = 1;
58523+#endif
58524+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58525+ grsec_enable_group = 1;
58526+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58527+#endif
58528+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58529+ grsec_enable_ptrace_readexec = 1;
58530+#endif
58531+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58532+ grsec_enable_chdir = 1;
58533+#endif
58534+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58535+ grsec_enable_harden_ptrace = 1;
58536+#endif
58537+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58538+ grsec_enable_mount = 1;
58539+#endif
58540+#ifdef CONFIG_GRKERNSEC_LINK
58541+ grsec_enable_link = 1;
58542+#endif
58543+#ifdef CONFIG_GRKERNSEC_BRUTE
58544+ grsec_enable_brute = 1;
58545+#endif
58546+#ifdef CONFIG_GRKERNSEC_DMESG
58547+ grsec_enable_dmesg = 1;
58548+#endif
58549+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58550+ grsec_enable_blackhole = 1;
58551+ grsec_lastack_retries = 4;
58552+#endif
58553+#ifdef CONFIG_GRKERNSEC_FIFO
58554+ grsec_enable_fifo = 1;
58555+#endif
58556+#ifdef CONFIG_GRKERNSEC_EXECLOG
58557+ grsec_enable_execlog = 1;
58558+#endif
58559+#ifdef CONFIG_GRKERNSEC_SETXID
58560+ grsec_enable_setxid = 1;
58561+#endif
58562+#ifdef CONFIG_GRKERNSEC_SIGNAL
58563+ grsec_enable_signal = 1;
58564+#endif
58565+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58566+ grsec_enable_forkfail = 1;
58567+#endif
58568+#ifdef CONFIG_GRKERNSEC_TIME
58569+ grsec_enable_time = 1;
58570+#endif
58571+#ifdef CONFIG_GRKERNSEC_RESLOG
58572+ grsec_resource_logging = 1;
58573+#endif
58574+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58575+ grsec_enable_chroot_findtask = 1;
58576+#endif
58577+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58578+ grsec_enable_chroot_unix = 1;
58579+#endif
58580+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58581+ grsec_enable_chroot_mount = 1;
58582+#endif
58583+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58584+ grsec_enable_chroot_fchdir = 1;
58585+#endif
58586+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58587+ grsec_enable_chroot_shmat = 1;
58588+#endif
58589+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58590+ grsec_enable_audit_ptrace = 1;
58591+#endif
58592+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58593+ grsec_enable_chroot_double = 1;
58594+#endif
58595+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58596+ grsec_enable_chroot_pivot = 1;
58597+#endif
58598+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58599+ grsec_enable_chroot_chdir = 1;
58600+#endif
58601+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58602+ grsec_enable_chroot_chmod = 1;
58603+#endif
58604+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58605+ grsec_enable_chroot_mknod = 1;
58606+#endif
58607+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58608+ grsec_enable_chroot_nice = 1;
58609+#endif
58610+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58611+ grsec_enable_chroot_execlog = 1;
58612+#endif
58613+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58614+ grsec_enable_chroot_caps = 1;
58615+#endif
58616+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58617+ grsec_enable_chroot_sysctl = 1;
58618+#endif
58619+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58620+ grsec_enable_symlinkown = 1;
58621+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58622+#endif
58623+#ifdef CONFIG_GRKERNSEC_TPE
58624+ grsec_enable_tpe = 1;
58625+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58626+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58627+ grsec_enable_tpe_all = 1;
58628+#endif
58629+#endif
58630+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58631+ grsec_enable_socket_all = 1;
58632+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58633+#endif
58634+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58635+ grsec_enable_socket_client = 1;
58636+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58637+#endif
58638+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58639+ grsec_enable_socket_server = 1;
58640+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58641+#endif
58642+#endif
58643+
58644+ return;
58645+}
58646diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58647new file mode 100644
58648index 0000000..589481f
58649--- /dev/null
58650+++ b/grsecurity/grsec_link.c
58651@@ -0,0 +1,58 @@
58652+#include <linux/kernel.h>
58653+#include <linux/sched.h>
58654+#include <linux/fs.h>
58655+#include <linux/file.h>
58656+#include <linux/grinternal.h>
58657+
58658+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58659+{
58660+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58661+ const struct inode *link_inode = link->dentry->d_inode;
58662+
58663+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58664+ /* ignore root-owned links, e.g. /proc/self */
58665+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58666+ !uid_eq(link_inode->i_uid, target->i_uid)) {
58667+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58668+ return 1;
58669+ }
58670+#endif
58671+ return 0;
58672+}
58673+
58674+int
58675+gr_handle_follow_link(const struct inode *parent,
58676+ const struct inode *inode,
58677+ const struct dentry *dentry, const struct vfsmount *mnt)
58678+{
58679+#ifdef CONFIG_GRKERNSEC_LINK
58680+ const struct cred *cred = current_cred();
58681+
58682+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58683+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58684+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58685+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58686+ return -EACCES;
58687+ }
58688+#endif
58689+ return 0;
58690+}
58691+
58692+int
58693+gr_handle_hardlink(const struct dentry *dentry,
58694+ const struct vfsmount *mnt,
58695+ struct inode *inode, const int mode, const char *to)
58696+{
58697+#ifdef CONFIG_GRKERNSEC_LINK
58698+ const struct cred *cred = current_cred();
58699+
58700+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58701+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58702+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58703+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58704+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58705+ return -EPERM;
58706+ }
58707+#endif
58708+ return 0;
58709+}
58710diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58711new file mode 100644
58712index 0000000..a45d2e9
58713--- /dev/null
58714+++ b/grsecurity/grsec_log.c
58715@@ -0,0 +1,322 @@
58716+#include <linux/kernel.h>
58717+#include <linux/sched.h>
58718+#include <linux/file.h>
58719+#include <linux/tty.h>
58720+#include <linux/fs.h>
58721+#include <linux/grinternal.h>
58722+
58723+#ifdef CONFIG_TREE_PREEMPT_RCU
58724+#define DISABLE_PREEMPT() preempt_disable()
58725+#define ENABLE_PREEMPT() preempt_enable()
58726+#else
58727+#define DISABLE_PREEMPT()
58728+#define ENABLE_PREEMPT()
58729+#endif
58730+
58731+#define BEGIN_LOCKS(x) \
58732+ DISABLE_PREEMPT(); \
58733+ rcu_read_lock(); \
58734+ read_lock(&tasklist_lock); \
58735+ read_lock(&grsec_exec_file_lock); \
58736+ if (x != GR_DO_AUDIT) \
58737+ spin_lock(&grsec_alert_lock); \
58738+ else \
58739+ spin_lock(&grsec_audit_lock)
58740+
58741+#define END_LOCKS(x) \
58742+ if (x != GR_DO_AUDIT) \
58743+ spin_unlock(&grsec_alert_lock); \
58744+ else \
58745+ spin_unlock(&grsec_audit_lock); \
58746+ read_unlock(&grsec_exec_file_lock); \
58747+ read_unlock(&tasklist_lock); \
58748+ rcu_read_unlock(); \
58749+ ENABLE_PREEMPT(); \
58750+ if (x == GR_DONT_AUDIT) \
58751+ gr_handle_alertkill(current)
58752+
58753+enum {
58754+ FLOODING,
58755+ NO_FLOODING
58756+};
58757+
58758+extern char *gr_alert_log_fmt;
58759+extern char *gr_audit_log_fmt;
58760+extern char *gr_alert_log_buf;
58761+extern char *gr_audit_log_buf;
58762+
58763+static int gr_log_start(int audit)
58764+{
58765+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58766+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58767+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58768+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58769+ unsigned long curr_secs = get_seconds();
58770+
58771+ if (audit == GR_DO_AUDIT)
58772+ goto set_fmt;
58773+
58774+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58775+ grsec_alert_wtime = curr_secs;
58776+ grsec_alert_fyet = 0;
58777+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58778+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58779+ grsec_alert_fyet++;
58780+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58781+ grsec_alert_wtime = curr_secs;
58782+ grsec_alert_fyet++;
58783+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58784+ return FLOODING;
58785+ }
58786+ else return FLOODING;
58787+
58788+set_fmt:
58789+#endif
58790+ memset(buf, 0, PAGE_SIZE);
58791+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
58792+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58793+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58794+ } else if (current->signal->curr_ip) {
58795+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58796+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58797+ } else if (gr_acl_is_enabled()) {
58798+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58799+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58800+ } else {
58801+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
58802+ strcpy(buf, fmt);
58803+ }
58804+
58805+ return NO_FLOODING;
58806+}
58807+
58808+static void gr_log_middle(int audit, const char *msg, va_list ap)
58809+ __attribute__ ((format (printf, 2, 0)));
58810+
58811+static void gr_log_middle(int audit, const char *msg, va_list ap)
58812+{
58813+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58814+ unsigned int len = strlen(buf);
58815+
58816+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58817+
58818+ return;
58819+}
58820+
58821+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58822+ __attribute__ ((format (printf, 2, 3)));
58823+
58824+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58825+{
58826+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58827+ unsigned int len = strlen(buf);
58828+ va_list ap;
58829+
58830+ va_start(ap, msg);
58831+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58832+ va_end(ap);
58833+
58834+ return;
58835+}
58836+
58837+static void gr_log_end(int audit, int append_default)
58838+{
58839+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58840+
58841+ if (append_default) {
58842+ unsigned int len = strlen(buf);
58843+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58844+ }
58845+
58846+ printk("%s\n", buf);
58847+
58848+ return;
58849+}
58850+
58851+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58852+{
58853+ int logtype;
58854+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58855+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58856+ void *voidptr = NULL;
58857+ int num1 = 0, num2 = 0;
58858+ unsigned long ulong1 = 0, ulong2 = 0;
58859+ struct dentry *dentry = NULL;
58860+ struct vfsmount *mnt = NULL;
58861+ struct file *file = NULL;
58862+ struct task_struct *task = NULL;
58863+ const struct cred *cred, *pcred;
58864+ va_list ap;
58865+
58866+ BEGIN_LOCKS(audit);
58867+ logtype = gr_log_start(audit);
58868+ if (logtype == FLOODING) {
58869+ END_LOCKS(audit);
58870+ return;
58871+ }
58872+ va_start(ap, argtypes);
58873+ switch (argtypes) {
58874+ case GR_TTYSNIFF:
58875+ task = va_arg(ap, struct task_struct *);
58876+ 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);
58877+ break;
58878+ case GR_SYSCTL_HIDDEN:
58879+ str1 = va_arg(ap, char *);
58880+ gr_log_middle_varargs(audit, msg, result, str1);
58881+ break;
58882+ case GR_RBAC:
58883+ dentry = va_arg(ap, struct dentry *);
58884+ mnt = va_arg(ap, struct vfsmount *);
58885+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58886+ break;
58887+ case GR_RBAC_STR:
58888+ dentry = va_arg(ap, struct dentry *);
58889+ mnt = va_arg(ap, struct vfsmount *);
58890+ str1 = va_arg(ap, char *);
58891+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58892+ break;
58893+ case GR_STR_RBAC:
58894+ str1 = va_arg(ap, char *);
58895+ dentry = va_arg(ap, struct dentry *);
58896+ mnt = va_arg(ap, struct vfsmount *);
58897+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58898+ break;
58899+ case GR_RBAC_MODE2:
58900+ dentry = va_arg(ap, struct dentry *);
58901+ mnt = va_arg(ap, struct vfsmount *);
58902+ str1 = va_arg(ap, char *);
58903+ str2 = va_arg(ap, char *);
58904+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58905+ break;
58906+ case GR_RBAC_MODE3:
58907+ dentry = va_arg(ap, struct dentry *);
58908+ mnt = va_arg(ap, struct vfsmount *);
58909+ str1 = va_arg(ap, char *);
58910+ str2 = va_arg(ap, char *);
58911+ str3 = va_arg(ap, char *);
58912+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58913+ break;
58914+ case GR_FILENAME:
58915+ dentry = va_arg(ap, struct dentry *);
58916+ mnt = va_arg(ap, struct vfsmount *);
58917+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58918+ break;
58919+ case GR_STR_FILENAME:
58920+ str1 = va_arg(ap, char *);
58921+ dentry = va_arg(ap, struct dentry *);
58922+ mnt = va_arg(ap, struct vfsmount *);
58923+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58924+ break;
58925+ case GR_FILENAME_STR:
58926+ dentry = va_arg(ap, struct dentry *);
58927+ mnt = va_arg(ap, struct vfsmount *);
58928+ str1 = va_arg(ap, char *);
58929+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58930+ break;
58931+ case GR_FILENAME_TWO_INT:
58932+ dentry = va_arg(ap, struct dentry *);
58933+ mnt = va_arg(ap, struct vfsmount *);
58934+ num1 = va_arg(ap, int);
58935+ num2 = va_arg(ap, int);
58936+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58937+ break;
58938+ case GR_FILENAME_TWO_INT_STR:
58939+ dentry = va_arg(ap, struct dentry *);
58940+ mnt = va_arg(ap, struct vfsmount *);
58941+ num1 = va_arg(ap, int);
58942+ num2 = va_arg(ap, int);
58943+ str1 = va_arg(ap, char *);
58944+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58945+ break;
58946+ case GR_TEXTREL:
58947+ file = va_arg(ap, struct file *);
58948+ ulong1 = va_arg(ap, unsigned long);
58949+ ulong2 = va_arg(ap, unsigned long);
58950+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58951+ break;
58952+ case GR_PTRACE:
58953+ task = va_arg(ap, struct task_struct *);
58954+ 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);
58955+ break;
58956+ case GR_RESOURCE:
58957+ task = va_arg(ap, struct task_struct *);
58958+ cred = __task_cred(task);
58959+ pcred = __task_cred(task->real_parent);
58960+ ulong1 = va_arg(ap, unsigned long);
58961+ str1 = va_arg(ap, char *);
58962+ ulong2 = va_arg(ap, unsigned long);
58963+ 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);
58964+ break;
58965+ case GR_CAP:
58966+ task = va_arg(ap, struct task_struct *);
58967+ cred = __task_cred(task);
58968+ pcred = __task_cred(task->real_parent);
58969+ str1 = va_arg(ap, char *);
58970+ 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);
58971+ break;
58972+ case GR_SIG:
58973+ str1 = va_arg(ap, char *);
58974+ voidptr = va_arg(ap, void *);
58975+ gr_log_middle_varargs(audit, msg, str1, voidptr);
58976+ break;
58977+ case GR_SIG2:
58978+ task = va_arg(ap, struct task_struct *);
58979+ cred = __task_cred(task);
58980+ pcred = __task_cred(task->real_parent);
58981+ num1 = va_arg(ap, int);
58982+ 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);
58983+ break;
58984+ case GR_CRASH1:
58985+ task = va_arg(ap, struct task_struct *);
58986+ cred = __task_cred(task);
58987+ pcred = __task_cred(task->real_parent);
58988+ ulong1 = va_arg(ap, unsigned long);
58989+ 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);
58990+ break;
58991+ case GR_CRASH2:
58992+ task = va_arg(ap, struct task_struct *);
58993+ cred = __task_cred(task);
58994+ pcred = __task_cred(task->real_parent);
58995+ ulong1 = va_arg(ap, unsigned long);
58996+ 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);
58997+ break;
58998+ case GR_RWXMAP:
58999+ file = va_arg(ap, struct file *);
59000+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59001+ break;
59002+ case GR_PSACCT:
59003+ {
59004+ unsigned int wday, cday;
59005+ __u8 whr, chr;
59006+ __u8 wmin, cmin;
59007+ __u8 wsec, csec;
59008+ char cur_tty[64] = { 0 };
59009+ char parent_tty[64] = { 0 };
59010+
59011+ task = va_arg(ap, struct task_struct *);
59012+ wday = va_arg(ap, unsigned int);
59013+ cday = va_arg(ap, unsigned int);
59014+ whr = va_arg(ap, int);
59015+ chr = va_arg(ap, int);
59016+ wmin = va_arg(ap, int);
59017+ cmin = va_arg(ap, int);
59018+ wsec = va_arg(ap, int);
59019+ csec = va_arg(ap, int);
59020+ ulong1 = va_arg(ap, unsigned long);
59021+ cred = __task_cred(task);
59022+ pcred = __task_cred(task->real_parent);
59023+
59024+ 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);
59025+ }
59026+ break;
59027+ default:
59028+ gr_log_middle(audit, msg, ap);
59029+ }
59030+ va_end(ap);
59031+ // these don't need DEFAULTSECARGS printed on the end
59032+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59033+ gr_log_end(audit, 0);
59034+ else
59035+ gr_log_end(audit, 1);
59036+ END_LOCKS(audit);
59037+}
59038diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59039new file mode 100644
59040index 0000000..f536303
59041--- /dev/null
59042+++ b/grsecurity/grsec_mem.c
59043@@ -0,0 +1,40 @@
59044+#include <linux/kernel.h>
59045+#include <linux/sched.h>
59046+#include <linux/mm.h>
59047+#include <linux/mman.h>
59048+#include <linux/grinternal.h>
59049+
59050+void
59051+gr_handle_ioperm(void)
59052+{
59053+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59054+ return;
59055+}
59056+
59057+void
59058+gr_handle_iopl(void)
59059+{
59060+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59061+ return;
59062+}
59063+
59064+void
59065+gr_handle_mem_readwrite(u64 from, u64 to)
59066+{
59067+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59068+ return;
59069+}
59070+
59071+void
59072+gr_handle_vm86(void)
59073+{
59074+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59075+ return;
59076+}
59077+
59078+void
59079+gr_log_badprocpid(const char *entry)
59080+{
59081+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59082+ return;
59083+}
59084diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59085new file mode 100644
59086index 0000000..2131422
59087--- /dev/null
59088+++ b/grsecurity/grsec_mount.c
59089@@ -0,0 +1,62 @@
59090+#include <linux/kernel.h>
59091+#include <linux/sched.h>
59092+#include <linux/mount.h>
59093+#include <linux/grsecurity.h>
59094+#include <linux/grinternal.h>
59095+
59096+void
59097+gr_log_remount(const char *devname, const int retval)
59098+{
59099+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59100+ if (grsec_enable_mount && (retval >= 0))
59101+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59102+#endif
59103+ return;
59104+}
59105+
59106+void
59107+gr_log_unmount(const char *devname, const int retval)
59108+{
59109+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59110+ if (grsec_enable_mount && (retval >= 0))
59111+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59112+#endif
59113+ return;
59114+}
59115+
59116+void
59117+gr_log_mount(const char *from, const char *to, const int retval)
59118+{
59119+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59120+ if (grsec_enable_mount && (retval >= 0))
59121+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59122+#endif
59123+ return;
59124+}
59125+
59126+int
59127+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59128+{
59129+#ifdef CONFIG_GRKERNSEC_ROFS
59130+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59131+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59132+ return -EPERM;
59133+ } else
59134+ return 0;
59135+#endif
59136+ return 0;
59137+}
59138+
59139+int
59140+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59141+{
59142+#ifdef CONFIG_GRKERNSEC_ROFS
59143+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59144+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59145+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59146+ return -EPERM;
59147+ } else
59148+ return 0;
59149+#endif
59150+ return 0;
59151+}
59152diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59153new file mode 100644
59154index 0000000..a3b12a0
59155--- /dev/null
59156+++ b/grsecurity/grsec_pax.c
59157@@ -0,0 +1,36 @@
59158+#include <linux/kernel.h>
59159+#include <linux/sched.h>
59160+#include <linux/mm.h>
59161+#include <linux/file.h>
59162+#include <linux/grinternal.h>
59163+#include <linux/grsecurity.h>
59164+
59165+void
59166+gr_log_textrel(struct vm_area_struct * vma)
59167+{
59168+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59169+ if (grsec_enable_audit_textrel)
59170+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59171+#endif
59172+ return;
59173+}
59174+
59175+void
59176+gr_log_rwxmmap(struct file *file)
59177+{
59178+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59179+ if (grsec_enable_log_rwxmaps)
59180+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59181+#endif
59182+ return;
59183+}
59184+
59185+void
59186+gr_log_rwxmprotect(struct file *file)
59187+{
59188+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59189+ if (grsec_enable_log_rwxmaps)
59190+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59191+#endif
59192+ return;
59193+}
59194diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59195new file mode 100644
59196index 0000000..f7f29aa
59197--- /dev/null
59198+++ b/grsecurity/grsec_ptrace.c
59199@@ -0,0 +1,30 @@
59200+#include <linux/kernel.h>
59201+#include <linux/sched.h>
59202+#include <linux/grinternal.h>
59203+#include <linux/security.h>
59204+
59205+void
59206+gr_audit_ptrace(struct task_struct *task)
59207+{
59208+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59209+ if (grsec_enable_audit_ptrace)
59210+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59211+#endif
59212+ return;
59213+}
59214+
59215+int
59216+gr_ptrace_readexec(struct file *file, int unsafe_flags)
59217+{
59218+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59219+ const struct dentry *dentry = file->f_path.dentry;
59220+ const struct vfsmount *mnt = file->f_path.mnt;
59221+
59222+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59223+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59224+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59225+ return -EACCES;
59226+ }
59227+#endif
59228+ return 0;
59229+}
59230diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59231new file mode 100644
59232index 0000000..b4ac94c
59233--- /dev/null
59234+++ b/grsecurity/grsec_sig.c
59235@@ -0,0 +1,209 @@
59236+#include <linux/kernel.h>
59237+#include <linux/sched.h>
59238+#include <linux/delay.h>
59239+#include <linux/grsecurity.h>
59240+#include <linux/grinternal.h>
59241+#include <linux/hardirq.h>
59242+
59243+char *signames[] = {
59244+ [SIGSEGV] = "Segmentation fault",
59245+ [SIGILL] = "Illegal instruction",
59246+ [SIGABRT] = "Abort",
59247+ [SIGBUS] = "Invalid alignment/Bus error"
59248+};
59249+
59250+void
59251+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59252+{
59253+#ifdef CONFIG_GRKERNSEC_SIGNAL
59254+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59255+ (sig == SIGABRT) || (sig == SIGBUS))) {
59256+ if (t->pid == current->pid) {
59257+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59258+ } else {
59259+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59260+ }
59261+ }
59262+#endif
59263+ return;
59264+}
59265+
59266+int
59267+gr_handle_signal(const struct task_struct *p, const int sig)
59268+{
59269+#ifdef CONFIG_GRKERNSEC
59270+ /* ignore the 0 signal for protected task checks */
59271+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59272+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59273+ return -EPERM;
59274+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59275+ return -EPERM;
59276+ }
59277+#endif
59278+ return 0;
59279+}
59280+
59281+#ifdef CONFIG_GRKERNSEC
59282+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59283+
59284+int gr_fake_force_sig(int sig, struct task_struct *t)
59285+{
59286+ unsigned long int flags;
59287+ int ret, blocked, ignored;
59288+ struct k_sigaction *action;
59289+
59290+ spin_lock_irqsave(&t->sighand->siglock, flags);
59291+ action = &t->sighand->action[sig-1];
59292+ ignored = action->sa.sa_handler == SIG_IGN;
59293+ blocked = sigismember(&t->blocked, sig);
59294+ if (blocked || ignored) {
59295+ action->sa.sa_handler = SIG_DFL;
59296+ if (blocked) {
59297+ sigdelset(&t->blocked, sig);
59298+ recalc_sigpending_and_wake(t);
59299+ }
59300+ }
59301+ if (action->sa.sa_handler == SIG_DFL)
59302+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
59303+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59304+
59305+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
59306+
59307+ return ret;
59308+}
59309+#endif
59310+
59311+#ifdef CONFIG_GRKERNSEC_BRUTE
59312+#define GR_USER_BAN_TIME (15 * 60)
59313+
59314+static int __get_dumpable(unsigned long mm_flags)
59315+{
59316+ int ret;
59317+
59318+ ret = mm_flags & MMF_DUMPABLE_MASK;
59319+ return (ret >= 2) ? 2 : ret;
59320+}
59321+#endif
59322+
59323+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59324+{
59325+#ifdef CONFIG_GRKERNSEC_BRUTE
59326+ kuid_t uid = GLOBAL_ROOT_UID;
59327+
59328+ if (!grsec_enable_brute)
59329+ return;
59330+
59331+ rcu_read_lock();
59332+ read_lock(&tasklist_lock);
59333+ read_lock(&grsec_exec_file_lock);
59334+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59335+ p->real_parent->brute = 1;
59336+ else {
59337+ const struct cred *cred = __task_cred(p), *cred2;
59338+ struct task_struct *tsk, *tsk2;
59339+
59340+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59341+ struct user_struct *user;
59342+
59343+ uid = cred->uid;
59344+
59345+ /* this is put upon execution past expiration */
59346+ user = find_user(uid);
59347+ if (user == NULL)
59348+ goto unlock;
59349+ user->banned = 1;
59350+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59351+ if (user->ban_expires == ~0UL)
59352+ user->ban_expires--;
59353+
59354+ do_each_thread(tsk2, tsk) {
59355+ cred2 = __task_cred(tsk);
59356+ if (tsk != p && uid_eq(cred2->uid, uid))
59357+ gr_fake_force_sig(SIGKILL, tsk);
59358+ } while_each_thread(tsk2, tsk);
59359+ }
59360+ }
59361+unlock:
59362+ read_unlock(&grsec_exec_file_lock);
59363+ read_unlock(&tasklist_lock);
59364+ rcu_read_unlock();
59365+
59366+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
59367+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59368+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59369+
59370+#endif
59371+ return;
59372+}
59373+
59374+void gr_handle_brute_check(void)
59375+{
59376+#ifdef CONFIG_GRKERNSEC_BRUTE
59377+ if (current->brute)
59378+ msleep(30 * 1000);
59379+#endif
59380+ return;
59381+}
59382+
59383+void gr_handle_kernel_exploit(void)
59384+{
59385+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59386+ const struct cred *cred;
59387+ struct task_struct *tsk, *tsk2;
59388+ struct user_struct *user;
59389+ kuid_t uid;
59390+
59391+ if (in_irq() || in_serving_softirq() || in_nmi())
59392+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59393+
59394+ uid = current_uid();
59395+
59396+ if (uid_eq(uid, GLOBAL_ROOT_UID))
59397+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
59398+ else {
59399+ /* kill all the processes of this user, hold a reference
59400+ to their creds struct, and prevent them from creating
59401+ another process until system reset
59402+ */
59403+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59404+ from_kuid_munged(&init_user_ns, uid));
59405+ /* we intentionally leak this ref */
59406+ user = get_uid(current->cred->user);
59407+ if (user) {
59408+ user->banned = 1;
59409+ user->ban_expires = ~0UL;
59410+ }
59411+
59412+ read_lock(&tasklist_lock);
59413+ do_each_thread(tsk2, tsk) {
59414+ cred = __task_cred(tsk);
59415+ if (uid_eq(cred->uid, uid))
59416+ gr_fake_force_sig(SIGKILL, tsk);
59417+ } while_each_thread(tsk2, tsk);
59418+ read_unlock(&tasklist_lock);
59419+ }
59420+#endif
59421+}
59422+
59423+int __gr_process_user_ban(struct user_struct *user)
59424+{
59425+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59426+ if (unlikely(user->banned)) {
59427+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59428+ user->banned = 0;
59429+ user->ban_expires = 0;
59430+ free_uid(user);
59431+ } else
59432+ return -EPERM;
59433+ }
59434+#endif
59435+ return 0;
59436+}
59437+
59438+int gr_process_user_ban(void)
59439+{
59440+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59441+ return __gr_process_user_ban(current->cred->user);
59442+#endif
59443+ return 0;
59444+}
59445diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59446new file mode 100644
59447index 0000000..4030d57
59448--- /dev/null
59449+++ b/grsecurity/grsec_sock.c
59450@@ -0,0 +1,244 @@
59451+#include <linux/kernel.h>
59452+#include <linux/module.h>
59453+#include <linux/sched.h>
59454+#include <linux/file.h>
59455+#include <linux/net.h>
59456+#include <linux/in.h>
59457+#include <linux/ip.h>
59458+#include <net/sock.h>
59459+#include <net/inet_sock.h>
59460+#include <linux/grsecurity.h>
59461+#include <linux/grinternal.h>
59462+#include <linux/gracl.h>
59463+
59464+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59465+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59466+
59467+EXPORT_SYMBOL(gr_search_udp_recvmsg);
59468+EXPORT_SYMBOL(gr_search_udp_sendmsg);
59469+
59470+#ifdef CONFIG_UNIX_MODULE
59471+EXPORT_SYMBOL(gr_acl_handle_unix);
59472+EXPORT_SYMBOL(gr_acl_handle_mknod);
59473+EXPORT_SYMBOL(gr_handle_chroot_unix);
59474+EXPORT_SYMBOL(gr_handle_create);
59475+#endif
59476+
59477+#ifdef CONFIG_GRKERNSEC
59478+#define gr_conn_table_size 32749
59479+struct conn_table_entry {
59480+ struct conn_table_entry *next;
59481+ struct signal_struct *sig;
59482+};
59483+
59484+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59485+DEFINE_SPINLOCK(gr_conn_table_lock);
59486+
59487+extern const char * gr_socktype_to_name(unsigned char type);
59488+extern const char * gr_proto_to_name(unsigned char proto);
59489+extern const char * gr_sockfamily_to_name(unsigned char family);
59490+
59491+static __inline__ int
59492+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59493+{
59494+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59495+}
59496+
59497+static __inline__ int
59498+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59499+ __u16 sport, __u16 dport)
59500+{
59501+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59502+ sig->gr_sport == sport && sig->gr_dport == dport))
59503+ return 1;
59504+ else
59505+ return 0;
59506+}
59507+
59508+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59509+{
59510+ struct conn_table_entry **match;
59511+ unsigned int index;
59512+
59513+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59514+ sig->gr_sport, sig->gr_dport,
59515+ gr_conn_table_size);
59516+
59517+ newent->sig = sig;
59518+
59519+ match = &gr_conn_table[index];
59520+ newent->next = *match;
59521+ *match = newent;
59522+
59523+ return;
59524+}
59525+
59526+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59527+{
59528+ struct conn_table_entry *match, *last = NULL;
59529+ unsigned int index;
59530+
59531+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59532+ sig->gr_sport, sig->gr_dport,
59533+ gr_conn_table_size);
59534+
59535+ match = gr_conn_table[index];
59536+ while (match && !conn_match(match->sig,
59537+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59538+ sig->gr_dport)) {
59539+ last = match;
59540+ match = match->next;
59541+ }
59542+
59543+ if (match) {
59544+ if (last)
59545+ last->next = match->next;
59546+ else
59547+ gr_conn_table[index] = NULL;
59548+ kfree(match);
59549+ }
59550+
59551+ return;
59552+}
59553+
59554+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59555+ __u16 sport, __u16 dport)
59556+{
59557+ struct conn_table_entry *match;
59558+ unsigned int index;
59559+
59560+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59561+
59562+ match = gr_conn_table[index];
59563+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59564+ match = match->next;
59565+
59566+ if (match)
59567+ return match->sig;
59568+ else
59569+ return NULL;
59570+}
59571+
59572+#endif
59573+
59574+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59575+{
59576+#ifdef CONFIG_GRKERNSEC
59577+ struct signal_struct *sig = task->signal;
59578+ struct conn_table_entry *newent;
59579+
59580+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59581+ if (newent == NULL)
59582+ return;
59583+ /* no bh lock needed since we are called with bh disabled */
59584+ spin_lock(&gr_conn_table_lock);
59585+ gr_del_task_from_ip_table_nolock(sig);
59586+ sig->gr_saddr = inet->inet_rcv_saddr;
59587+ sig->gr_daddr = inet->inet_daddr;
59588+ sig->gr_sport = inet->inet_sport;
59589+ sig->gr_dport = inet->inet_dport;
59590+ gr_add_to_task_ip_table_nolock(sig, newent);
59591+ spin_unlock(&gr_conn_table_lock);
59592+#endif
59593+ return;
59594+}
59595+
59596+void gr_del_task_from_ip_table(struct task_struct *task)
59597+{
59598+#ifdef CONFIG_GRKERNSEC
59599+ spin_lock_bh(&gr_conn_table_lock);
59600+ gr_del_task_from_ip_table_nolock(task->signal);
59601+ spin_unlock_bh(&gr_conn_table_lock);
59602+#endif
59603+ return;
59604+}
59605+
59606+void
59607+gr_attach_curr_ip(const struct sock *sk)
59608+{
59609+#ifdef CONFIG_GRKERNSEC
59610+ struct signal_struct *p, *set;
59611+ const struct inet_sock *inet = inet_sk(sk);
59612+
59613+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59614+ return;
59615+
59616+ set = current->signal;
59617+
59618+ spin_lock_bh(&gr_conn_table_lock);
59619+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59620+ inet->inet_dport, inet->inet_sport);
59621+ if (unlikely(p != NULL)) {
59622+ set->curr_ip = p->curr_ip;
59623+ set->used_accept = 1;
59624+ gr_del_task_from_ip_table_nolock(p);
59625+ spin_unlock_bh(&gr_conn_table_lock);
59626+ return;
59627+ }
59628+ spin_unlock_bh(&gr_conn_table_lock);
59629+
59630+ set->curr_ip = inet->inet_daddr;
59631+ set->used_accept = 1;
59632+#endif
59633+ return;
59634+}
59635+
59636+int
59637+gr_handle_sock_all(const int family, const int type, const int protocol)
59638+{
59639+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59640+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59641+ (family != AF_UNIX)) {
59642+ if (family == AF_INET)
59643+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59644+ else
59645+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59646+ return -EACCES;
59647+ }
59648+#endif
59649+ return 0;
59650+}
59651+
59652+int
59653+gr_handle_sock_server(const struct sockaddr *sck)
59654+{
59655+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59656+ if (grsec_enable_socket_server &&
59657+ in_group_p(grsec_socket_server_gid) &&
59658+ sck && (sck->sa_family != AF_UNIX) &&
59659+ (sck->sa_family != AF_LOCAL)) {
59660+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59661+ return -EACCES;
59662+ }
59663+#endif
59664+ return 0;
59665+}
59666+
59667+int
59668+gr_handle_sock_server_other(const struct sock *sck)
59669+{
59670+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59671+ if (grsec_enable_socket_server &&
59672+ in_group_p(grsec_socket_server_gid) &&
59673+ sck && (sck->sk_family != AF_UNIX) &&
59674+ (sck->sk_family != AF_LOCAL)) {
59675+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59676+ return -EACCES;
59677+ }
59678+#endif
59679+ return 0;
59680+}
59681+
59682+int
59683+gr_handle_sock_client(const struct sockaddr *sck)
59684+{
59685+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59686+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59687+ sck && (sck->sa_family != AF_UNIX) &&
59688+ (sck->sa_family != AF_LOCAL)) {
59689+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59690+ return -EACCES;
59691+ }
59692+#endif
59693+ return 0;
59694+}
59695diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59696new file mode 100644
59697index 0000000..f55ef0f
59698--- /dev/null
59699+++ b/grsecurity/grsec_sysctl.c
59700@@ -0,0 +1,469 @@
59701+#include <linux/kernel.h>
59702+#include <linux/sched.h>
59703+#include <linux/sysctl.h>
59704+#include <linux/grsecurity.h>
59705+#include <linux/grinternal.h>
59706+
59707+int
59708+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59709+{
59710+#ifdef CONFIG_GRKERNSEC_SYSCTL
59711+ if (dirname == NULL || name == NULL)
59712+ return 0;
59713+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59714+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59715+ return -EACCES;
59716+ }
59717+#endif
59718+ return 0;
59719+}
59720+
59721+#ifdef CONFIG_GRKERNSEC_ROFS
59722+static int __maybe_unused one = 1;
59723+#endif
59724+
59725+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59726+struct ctl_table grsecurity_table[] = {
59727+#ifdef CONFIG_GRKERNSEC_SYSCTL
59728+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59729+#ifdef CONFIG_GRKERNSEC_IO
59730+ {
59731+ .procname = "disable_priv_io",
59732+ .data = &grsec_disable_privio,
59733+ .maxlen = sizeof(int),
59734+ .mode = 0600,
59735+ .proc_handler = &proc_dointvec,
59736+ },
59737+#endif
59738+#endif
59739+#ifdef CONFIG_GRKERNSEC_LINK
59740+ {
59741+ .procname = "linking_restrictions",
59742+ .data = &grsec_enable_link,
59743+ .maxlen = sizeof(int),
59744+ .mode = 0600,
59745+ .proc_handler = &proc_dointvec,
59746+ },
59747+#endif
59748+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59749+ {
59750+ .procname = "enforce_symlinksifowner",
59751+ .data = &grsec_enable_symlinkown,
59752+ .maxlen = sizeof(int),
59753+ .mode = 0600,
59754+ .proc_handler = &proc_dointvec,
59755+ },
59756+ {
59757+ .procname = "symlinkown_gid",
59758+ .data = &grsec_symlinkown_gid,
59759+ .maxlen = sizeof(int),
59760+ .mode = 0600,
59761+ .proc_handler = &proc_dointvec,
59762+ },
59763+#endif
59764+#ifdef CONFIG_GRKERNSEC_BRUTE
59765+ {
59766+ .procname = "deter_bruteforce",
59767+ .data = &grsec_enable_brute,
59768+ .maxlen = sizeof(int),
59769+ .mode = 0600,
59770+ .proc_handler = &proc_dointvec,
59771+ },
59772+#endif
59773+#ifdef CONFIG_GRKERNSEC_FIFO
59774+ {
59775+ .procname = "fifo_restrictions",
59776+ .data = &grsec_enable_fifo,
59777+ .maxlen = sizeof(int),
59778+ .mode = 0600,
59779+ .proc_handler = &proc_dointvec,
59780+ },
59781+#endif
59782+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59783+ {
59784+ .procname = "ptrace_readexec",
59785+ .data = &grsec_enable_ptrace_readexec,
59786+ .maxlen = sizeof(int),
59787+ .mode = 0600,
59788+ .proc_handler = &proc_dointvec,
59789+ },
59790+#endif
59791+#ifdef CONFIG_GRKERNSEC_SETXID
59792+ {
59793+ .procname = "consistent_setxid",
59794+ .data = &grsec_enable_setxid,
59795+ .maxlen = sizeof(int),
59796+ .mode = 0600,
59797+ .proc_handler = &proc_dointvec,
59798+ },
59799+#endif
59800+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59801+ {
59802+ .procname = "ip_blackhole",
59803+ .data = &grsec_enable_blackhole,
59804+ .maxlen = sizeof(int),
59805+ .mode = 0600,
59806+ .proc_handler = &proc_dointvec,
59807+ },
59808+ {
59809+ .procname = "lastack_retries",
59810+ .data = &grsec_lastack_retries,
59811+ .maxlen = sizeof(int),
59812+ .mode = 0600,
59813+ .proc_handler = &proc_dointvec,
59814+ },
59815+#endif
59816+#ifdef CONFIG_GRKERNSEC_EXECLOG
59817+ {
59818+ .procname = "exec_logging",
59819+ .data = &grsec_enable_execlog,
59820+ .maxlen = sizeof(int),
59821+ .mode = 0600,
59822+ .proc_handler = &proc_dointvec,
59823+ },
59824+#endif
59825+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59826+ {
59827+ .procname = "rwxmap_logging",
59828+ .data = &grsec_enable_log_rwxmaps,
59829+ .maxlen = sizeof(int),
59830+ .mode = 0600,
59831+ .proc_handler = &proc_dointvec,
59832+ },
59833+#endif
59834+#ifdef CONFIG_GRKERNSEC_SIGNAL
59835+ {
59836+ .procname = "signal_logging",
59837+ .data = &grsec_enable_signal,
59838+ .maxlen = sizeof(int),
59839+ .mode = 0600,
59840+ .proc_handler = &proc_dointvec,
59841+ },
59842+#endif
59843+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59844+ {
59845+ .procname = "forkfail_logging",
59846+ .data = &grsec_enable_forkfail,
59847+ .maxlen = sizeof(int),
59848+ .mode = 0600,
59849+ .proc_handler = &proc_dointvec,
59850+ },
59851+#endif
59852+#ifdef CONFIG_GRKERNSEC_TIME
59853+ {
59854+ .procname = "timechange_logging",
59855+ .data = &grsec_enable_time,
59856+ .maxlen = sizeof(int),
59857+ .mode = 0600,
59858+ .proc_handler = &proc_dointvec,
59859+ },
59860+#endif
59861+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59862+ {
59863+ .procname = "chroot_deny_shmat",
59864+ .data = &grsec_enable_chroot_shmat,
59865+ .maxlen = sizeof(int),
59866+ .mode = 0600,
59867+ .proc_handler = &proc_dointvec,
59868+ },
59869+#endif
59870+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59871+ {
59872+ .procname = "chroot_deny_unix",
59873+ .data = &grsec_enable_chroot_unix,
59874+ .maxlen = sizeof(int),
59875+ .mode = 0600,
59876+ .proc_handler = &proc_dointvec,
59877+ },
59878+#endif
59879+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59880+ {
59881+ .procname = "chroot_deny_mount",
59882+ .data = &grsec_enable_chroot_mount,
59883+ .maxlen = sizeof(int),
59884+ .mode = 0600,
59885+ .proc_handler = &proc_dointvec,
59886+ },
59887+#endif
59888+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59889+ {
59890+ .procname = "chroot_deny_fchdir",
59891+ .data = &grsec_enable_chroot_fchdir,
59892+ .maxlen = sizeof(int),
59893+ .mode = 0600,
59894+ .proc_handler = &proc_dointvec,
59895+ },
59896+#endif
59897+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59898+ {
59899+ .procname = "chroot_deny_chroot",
59900+ .data = &grsec_enable_chroot_double,
59901+ .maxlen = sizeof(int),
59902+ .mode = 0600,
59903+ .proc_handler = &proc_dointvec,
59904+ },
59905+#endif
59906+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59907+ {
59908+ .procname = "chroot_deny_pivot",
59909+ .data = &grsec_enable_chroot_pivot,
59910+ .maxlen = sizeof(int),
59911+ .mode = 0600,
59912+ .proc_handler = &proc_dointvec,
59913+ },
59914+#endif
59915+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59916+ {
59917+ .procname = "chroot_enforce_chdir",
59918+ .data = &grsec_enable_chroot_chdir,
59919+ .maxlen = sizeof(int),
59920+ .mode = 0600,
59921+ .proc_handler = &proc_dointvec,
59922+ },
59923+#endif
59924+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59925+ {
59926+ .procname = "chroot_deny_chmod",
59927+ .data = &grsec_enable_chroot_chmod,
59928+ .maxlen = sizeof(int),
59929+ .mode = 0600,
59930+ .proc_handler = &proc_dointvec,
59931+ },
59932+#endif
59933+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59934+ {
59935+ .procname = "chroot_deny_mknod",
59936+ .data = &grsec_enable_chroot_mknod,
59937+ .maxlen = sizeof(int),
59938+ .mode = 0600,
59939+ .proc_handler = &proc_dointvec,
59940+ },
59941+#endif
59942+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59943+ {
59944+ .procname = "chroot_restrict_nice",
59945+ .data = &grsec_enable_chroot_nice,
59946+ .maxlen = sizeof(int),
59947+ .mode = 0600,
59948+ .proc_handler = &proc_dointvec,
59949+ },
59950+#endif
59951+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59952+ {
59953+ .procname = "chroot_execlog",
59954+ .data = &grsec_enable_chroot_execlog,
59955+ .maxlen = sizeof(int),
59956+ .mode = 0600,
59957+ .proc_handler = &proc_dointvec,
59958+ },
59959+#endif
59960+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59961+ {
59962+ .procname = "chroot_caps",
59963+ .data = &grsec_enable_chroot_caps,
59964+ .maxlen = sizeof(int),
59965+ .mode = 0600,
59966+ .proc_handler = &proc_dointvec,
59967+ },
59968+#endif
59969+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59970+ {
59971+ .procname = "chroot_deny_sysctl",
59972+ .data = &grsec_enable_chroot_sysctl,
59973+ .maxlen = sizeof(int),
59974+ .mode = 0600,
59975+ .proc_handler = &proc_dointvec,
59976+ },
59977+#endif
59978+#ifdef CONFIG_GRKERNSEC_TPE
59979+ {
59980+ .procname = "tpe",
59981+ .data = &grsec_enable_tpe,
59982+ .maxlen = sizeof(int),
59983+ .mode = 0600,
59984+ .proc_handler = &proc_dointvec,
59985+ },
59986+ {
59987+ .procname = "tpe_gid",
59988+ .data = &grsec_tpe_gid,
59989+ .maxlen = sizeof(int),
59990+ .mode = 0600,
59991+ .proc_handler = &proc_dointvec,
59992+ },
59993+#endif
59994+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59995+ {
59996+ .procname = "tpe_invert",
59997+ .data = &grsec_enable_tpe_invert,
59998+ .maxlen = sizeof(int),
59999+ .mode = 0600,
60000+ .proc_handler = &proc_dointvec,
60001+ },
60002+#endif
60003+#ifdef CONFIG_GRKERNSEC_TPE_ALL
60004+ {
60005+ .procname = "tpe_restrict_all",
60006+ .data = &grsec_enable_tpe_all,
60007+ .maxlen = sizeof(int),
60008+ .mode = 0600,
60009+ .proc_handler = &proc_dointvec,
60010+ },
60011+#endif
60012+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60013+ {
60014+ .procname = "socket_all",
60015+ .data = &grsec_enable_socket_all,
60016+ .maxlen = sizeof(int),
60017+ .mode = 0600,
60018+ .proc_handler = &proc_dointvec,
60019+ },
60020+ {
60021+ .procname = "socket_all_gid",
60022+ .data = &grsec_socket_all_gid,
60023+ .maxlen = sizeof(int),
60024+ .mode = 0600,
60025+ .proc_handler = &proc_dointvec,
60026+ },
60027+#endif
60028+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60029+ {
60030+ .procname = "socket_client",
60031+ .data = &grsec_enable_socket_client,
60032+ .maxlen = sizeof(int),
60033+ .mode = 0600,
60034+ .proc_handler = &proc_dointvec,
60035+ },
60036+ {
60037+ .procname = "socket_client_gid",
60038+ .data = &grsec_socket_client_gid,
60039+ .maxlen = sizeof(int),
60040+ .mode = 0600,
60041+ .proc_handler = &proc_dointvec,
60042+ },
60043+#endif
60044+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60045+ {
60046+ .procname = "socket_server",
60047+ .data = &grsec_enable_socket_server,
60048+ .maxlen = sizeof(int),
60049+ .mode = 0600,
60050+ .proc_handler = &proc_dointvec,
60051+ },
60052+ {
60053+ .procname = "socket_server_gid",
60054+ .data = &grsec_socket_server_gid,
60055+ .maxlen = sizeof(int),
60056+ .mode = 0600,
60057+ .proc_handler = &proc_dointvec,
60058+ },
60059+#endif
60060+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60061+ {
60062+ .procname = "audit_group",
60063+ .data = &grsec_enable_group,
60064+ .maxlen = sizeof(int),
60065+ .mode = 0600,
60066+ .proc_handler = &proc_dointvec,
60067+ },
60068+ {
60069+ .procname = "audit_gid",
60070+ .data = &grsec_audit_gid,
60071+ .maxlen = sizeof(int),
60072+ .mode = 0600,
60073+ .proc_handler = &proc_dointvec,
60074+ },
60075+#endif
60076+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60077+ {
60078+ .procname = "audit_chdir",
60079+ .data = &grsec_enable_chdir,
60080+ .maxlen = sizeof(int),
60081+ .mode = 0600,
60082+ .proc_handler = &proc_dointvec,
60083+ },
60084+#endif
60085+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60086+ {
60087+ .procname = "audit_mount",
60088+ .data = &grsec_enable_mount,
60089+ .maxlen = sizeof(int),
60090+ .mode = 0600,
60091+ .proc_handler = &proc_dointvec,
60092+ },
60093+#endif
60094+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60095+ {
60096+ .procname = "audit_textrel",
60097+ .data = &grsec_enable_audit_textrel,
60098+ .maxlen = sizeof(int),
60099+ .mode = 0600,
60100+ .proc_handler = &proc_dointvec,
60101+ },
60102+#endif
60103+#ifdef CONFIG_GRKERNSEC_DMESG
60104+ {
60105+ .procname = "dmesg",
60106+ .data = &grsec_enable_dmesg,
60107+ .maxlen = sizeof(int),
60108+ .mode = 0600,
60109+ .proc_handler = &proc_dointvec,
60110+ },
60111+#endif
60112+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60113+ {
60114+ .procname = "chroot_findtask",
60115+ .data = &grsec_enable_chroot_findtask,
60116+ .maxlen = sizeof(int),
60117+ .mode = 0600,
60118+ .proc_handler = &proc_dointvec,
60119+ },
60120+#endif
60121+#ifdef CONFIG_GRKERNSEC_RESLOG
60122+ {
60123+ .procname = "resource_logging",
60124+ .data = &grsec_resource_logging,
60125+ .maxlen = sizeof(int),
60126+ .mode = 0600,
60127+ .proc_handler = &proc_dointvec,
60128+ },
60129+#endif
60130+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60131+ {
60132+ .procname = "audit_ptrace",
60133+ .data = &grsec_enable_audit_ptrace,
60134+ .maxlen = sizeof(int),
60135+ .mode = 0600,
60136+ .proc_handler = &proc_dointvec,
60137+ },
60138+#endif
60139+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60140+ {
60141+ .procname = "harden_ptrace",
60142+ .data = &grsec_enable_harden_ptrace,
60143+ .maxlen = sizeof(int),
60144+ .mode = 0600,
60145+ .proc_handler = &proc_dointvec,
60146+ },
60147+#endif
60148+ {
60149+ .procname = "grsec_lock",
60150+ .data = &grsec_lock,
60151+ .maxlen = sizeof(int),
60152+ .mode = 0600,
60153+ .proc_handler = &proc_dointvec,
60154+ },
60155+#endif
60156+#ifdef CONFIG_GRKERNSEC_ROFS
60157+ {
60158+ .procname = "romount_protect",
60159+ .data = &grsec_enable_rofs,
60160+ .maxlen = sizeof(int),
60161+ .mode = 0600,
60162+ .proc_handler = &proc_dointvec_minmax,
60163+ .extra1 = &one,
60164+ .extra2 = &one,
60165+ },
60166+#endif
60167+ { }
60168+};
60169+#endif
60170diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60171new file mode 100644
60172index 0000000..0dc13c3
60173--- /dev/null
60174+++ b/grsecurity/grsec_time.c
60175@@ -0,0 +1,16 @@
60176+#include <linux/kernel.h>
60177+#include <linux/sched.h>
60178+#include <linux/grinternal.h>
60179+#include <linux/module.h>
60180+
60181+void
60182+gr_log_timechange(void)
60183+{
60184+#ifdef CONFIG_GRKERNSEC_TIME
60185+ if (grsec_enable_time)
60186+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60187+#endif
60188+ return;
60189+}
60190+
60191+EXPORT_SYMBOL(gr_log_timechange);
60192diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60193new file mode 100644
60194index 0000000..07e0dc0
60195--- /dev/null
60196+++ b/grsecurity/grsec_tpe.c
60197@@ -0,0 +1,73 @@
60198+#include <linux/kernel.h>
60199+#include <linux/sched.h>
60200+#include <linux/file.h>
60201+#include <linux/fs.h>
60202+#include <linux/grinternal.h>
60203+
60204+extern int gr_acl_tpe_check(void);
60205+
60206+int
60207+gr_tpe_allow(const struct file *file)
60208+{
60209+#ifdef CONFIG_GRKERNSEC
60210+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60211+ const struct cred *cred = current_cred();
60212+ char *msg = NULL;
60213+ char *msg2 = NULL;
60214+
60215+ // never restrict root
60216+ if (!cred->uid)
60217+ return 1;
60218+
60219+ if (grsec_enable_tpe) {
60220+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60221+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60222+ msg = "not being in trusted group";
60223+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60224+ msg = "being in untrusted group";
60225+#else
60226+ if (in_group_p(grsec_tpe_gid))
60227+ msg = "being in untrusted group";
60228+#endif
60229+ }
60230+ if (!msg && gr_acl_tpe_check())
60231+ msg = "being in untrusted role";
60232+
60233+ // not in any affected group/role
60234+ if (!msg)
60235+ goto next_check;
60236+
60237+ if (inode->i_uid)
60238+ msg2 = "file in non-root-owned directory";
60239+ else if (inode->i_mode & S_IWOTH)
60240+ msg2 = "file in world-writable directory";
60241+ else if (inode->i_mode & S_IWGRP)
60242+ msg2 = "file in group-writable directory";
60243+
60244+ if (msg && msg2) {
60245+ char fullmsg[70] = {0};
60246+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60247+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60248+ return 0;
60249+ }
60250+ msg = NULL;
60251+next_check:
60252+#ifdef CONFIG_GRKERNSEC_TPE_ALL
60253+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60254+ return 1;
60255+
60256+ if (inode->i_uid && (inode->i_uid != cred->uid))
60257+ msg = "directory not owned by user";
60258+ else if (inode->i_mode & S_IWOTH)
60259+ msg = "file in world-writable directory";
60260+ else if (inode->i_mode & S_IWGRP)
60261+ msg = "file in group-writable directory";
60262+
60263+ if (msg) {
60264+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60265+ return 0;
60266+ }
60267+#endif
60268+#endif
60269+ return 1;
60270+}
60271diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60272new file mode 100644
60273index 0000000..9f7b1ac
60274--- /dev/null
60275+++ b/grsecurity/grsum.c
60276@@ -0,0 +1,61 @@
60277+#include <linux/err.h>
60278+#include <linux/kernel.h>
60279+#include <linux/sched.h>
60280+#include <linux/mm.h>
60281+#include <linux/scatterlist.h>
60282+#include <linux/crypto.h>
60283+#include <linux/gracl.h>
60284+
60285+
60286+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60287+#error "crypto and sha256 must be built into the kernel"
60288+#endif
60289+
60290+int
60291+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60292+{
60293+ char *p;
60294+ struct crypto_hash *tfm;
60295+ struct hash_desc desc;
60296+ struct scatterlist sg;
60297+ unsigned char temp_sum[GR_SHA_LEN];
60298+ volatile int retval = 0;
60299+ volatile int dummy = 0;
60300+ unsigned int i;
60301+
60302+ sg_init_table(&sg, 1);
60303+
60304+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60305+ if (IS_ERR(tfm)) {
60306+ /* should never happen, since sha256 should be built in */
60307+ return 1;
60308+ }
60309+
60310+ desc.tfm = tfm;
60311+ desc.flags = 0;
60312+
60313+ crypto_hash_init(&desc);
60314+
60315+ p = salt;
60316+ sg_set_buf(&sg, p, GR_SALT_LEN);
60317+ crypto_hash_update(&desc, &sg, sg.length);
60318+
60319+ p = entry->pw;
60320+ sg_set_buf(&sg, p, strlen(p));
60321+
60322+ crypto_hash_update(&desc, &sg, sg.length);
60323+
60324+ crypto_hash_final(&desc, temp_sum);
60325+
60326+ memset(entry->pw, 0, GR_PW_LEN);
60327+
60328+ for (i = 0; i < GR_SHA_LEN; i++)
60329+ if (sum[i] != temp_sum[i])
60330+ retval = 1;
60331+ else
60332+ dummy = 1; // waste a cycle
60333+
60334+ crypto_free_hash(tfm);
60335+
60336+ return retval;
60337+}
60338diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60339index bde976e..a1cc32a 100644
60340--- a/include/acpi/acpi_bus.h
60341+++ b/include/acpi/acpi_bus.h
60342@@ -136,7 +136,7 @@ struct acpi_device_ops {
60343 acpi_op_bind bind;
60344 acpi_op_unbind unbind;
60345 acpi_op_notify notify;
60346-};
60347+} __no_const;
60348
60349 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60350
60351diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60352index 77ff547..181834f 100644
60353--- a/include/asm-generic/4level-fixup.h
60354+++ b/include/asm-generic/4level-fixup.h
60355@@ -13,8 +13,10 @@
60356 #define pmd_alloc(mm, pud, address) \
60357 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60358 NULL: pmd_offset(pud, address))
60359+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60360
60361 #define pud_alloc(mm, pgd, address) (pgd)
60362+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60363 #define pud_offset(pgd, start) (pgd)
60364 #define pud_none(pud) 0
60365 #define pud_bad(pud) 0
60366diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60367index b7babf0..3ba8aee 100644
60368--- a/include/asm-generic/atomic-long.h
60369+++ b/include/asm-generic/atomic-long.h
60370@@ -22,6 +22,12 @@
60371
60372 typedef atomic64_t atomic_long_t;
60373
60374+#ifdef CONFIG_PAX_REFCOUNT
60375+typedef atomic64_unchecked_t atomic_long_unchecked_t;
60376+#else
60377+typedef atomic64_t atomic_long_unchecked_t;
60378+#endif
60379+
60380 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60381
60382 static inline long atomic_long_read(atomic_long_t *l)
60383@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60384 return (long)atomic64_read(v);
60385 }
60386
60387+#ifdef CONFIG_PAX_REFCOUNT
60388+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60389+{
60390+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60391+
60392+ return (long)atomic64_read_unchecked(v);
60393+}
60394+#endif
60395+
60396 static inline void atomic_long_set(atomic_long_t *l, long i)
60397 {
60398 atomic64_t *v = (atomic64_t *)l;
60399@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60400 atomic64_set(v, i);
60401 }
60402
60403+#ifdef CONFIG_PAX_REFCOUNT
60404+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60405+{
60406+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60407+
60408+ atomic64_set_unchecked(v, i);
60409+}
60410+#endif
60411+
60412 static inline void atomic_long_inc(atomic_long_t *l)
60413 {
60414 atomic64_t *v = (atomic64_t *)l;
60415@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60416 atomic64_inc(v);
60417 }
60418
60419+#ifdef CONFIG_PAX_REFCOUNT
60420+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60421+{
60422+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60423+
60424+ atomic64_inc_unchecked(v);
60425+}
60426+#endif
60427+
60428 static inline void atomic_long_dec(atomic_long_t *l)
60429 {
60430 atomic64_t *v = (atomic64_t *)l;
60431@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60432 atomic64_dec(v);
60433 }
60434
60435+#ifdef CONFIG_PAX_REFCOUNT
60436+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60437+{
60438+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60439+
60440+ atomic64_dec_unchecked(v);
60441+}
60442+#endif
60443+
60444 static inline void atomic_long_add(long i, atomic_long_t *l)
60445 {
60446 atomic64_t *v = (atomic64_t *)l;
60447@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60448 atomic64_add(i, v);
60449 }
60450
60451+#ifdef CONFIG_PAX_REFCOUNT
60452+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60453+{
60454+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60455+
60456+ atomic64_add_unchecked(i, v);
60457+}
60458+#endif
60459+
60460 static inline void atomic_long_sub(long i, atomic_long_t *l)
60461 {
60462 atomic64_t *v = (atomic64_t *)l;
60463@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60464 atomic64_sub(i, v);
60465 }
60466
60467+#ifdef CONFIG_PAX_REFCOUNT
60468+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60469+{
60470+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60471+
60472+ atomic64_sub_unchecked(i, v);
60473+}
60474+#endif
60475+
60476 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60477 {
60478 atomic64_t *v = (atomic64_t *)l;
60479@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60480 return (long)atomic64_inc_return(v);
60481 }
60482
60483+#ifdef CONFIG_PAX_REFCOUNT
60484+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60485+{
60486+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60487+
60488+ return (long)atomic64_inc_return_unchecked(v);
60489+}
60490+#endif
60491+
60492 static inline long atomic_long_dec_return(atomic_long_t *l)
60493 {
60494 atomic64_t *v = (atomic64_t *)l;
60495@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60496
60497 typedef atomic_t atomic_long_t;
60498
60499+#ifdef CONFIG_PAX_REFCOUNT
60500+typedef atomic_unchecked_t atomic_long_unchecked_t;
60501+#else
60502+typedef atomic_t atomic_long_unchecked_t;
60503+#endif
60504+
60505 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60506 static inline long atomic_long_read(atomic_long_t *l)
60507 {
60508@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60509 return (long)atomic_read(v);
60510 }
60511
60512+#ifdef CONFIG_PAX_REFCOUNT
60513+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60514+{
60515+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60516+
60517+ return (long)atomic_read_unchecked(v);
60518+}
60519+#endif
60520+
60521 static inline void atomic_long_set(atomic_long_t *l, long i)
60522 {
60523 atomic_t *v = (atomic_t *)l;
60524@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60525 atomic_set(v, i);
60526 }
60527
60528+#ifdef CONFIG_PAX_REFCOUNT
60529+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60530+{
60531+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60532+
60533+ atomic_set_unchecked(v, i);
60534+}
60535+#endif
60536+
60537 static inline void atomic_long_inc(atomic_long_t *l)
60538 {
60539 atomic_t *v = (atomic_t *)l;
60540@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60541 atomic_inc(v);
60542 }
60543
60544+#ifdef CONFIG_PAX_REFCOUNT
60545+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60546+{
60547+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60548+
60549+ atomic_inc_unchecked(v);
60550+}
60551+#endif
60552+
60553 static inline void atomic_long_dec(atomic_long_t *l)
60554 {
60555 atomic_t *v = (atomic_t *)l;
60556@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60557 atomic_dec(v);
60558 }
60559
60560+#ifdef CONFIG_PAX_REFCOUNT
60561+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60562+{
60563+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60564+
60565+ atomic_dec_unchecked(v);
60566+}
60567+#endif
60568+
60569 static inline void atomic_long_add(long i, atomic_long_t *l)
60570 {
60571 atomic_t *v = (atomic_t *)l;
60572@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60573 atomic_add(i, v);
60574 }
60575
60576+#ifdef CONFIG_PAX_REFCOUNT
60577+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60578+{
60579+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60580+
60581+ atomic_add_unchecked(i, v);
60582+}
60583+#endif
60584+
60585 static inline void atomic_long_sub(long i, atomic_long_t *l)
60586 {
60587 atomic_t *v = (atomic_t *)l;
60588@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60589 atomic_sub(i, v);
60590 }
60591
60592+#ifdef CONFIG_PAX_REFCOUNT
60593+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60594+{
60595+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60596+
60597+ atomic_sub_unchecked(i, v);
60598+}
60599+#endif
60600+
60601 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60602 {
60603 atomic_t *v = (atomic_t *)l;
60604@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60605 return (long)atomic_inc_return(v);
60606 }
60607
60608+#ifdef CONFIG_PAX_REFCOUNT
60609+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60610+{
60611+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60612+
60613+ return (long)atomic_inc_return_unchecked(v);
60614+}
60615+#endif
60616+
60617 static inline long atomic_long_dec_return(atomic_long_t *l)
60618 {
60619 atomic_t *v = (atomic_t *)l;
60620@@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60621
60622 #endif /* BITS_PER_LONG == 64 */
60623
60624+#ifdef CONFIG_PAX_REFCOUNT
60625+static inline void pax_refcount_needs_these_functions(void)
60626+{
60627+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
60628+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60629+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60630+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60631+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60632+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60633+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60634+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60635+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60636+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60637+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60638+#ifdef CONFIG_X86
60639+ atomic_clear_mask_unchecked(0, NULL);
60640+ atomic_set_mask_unchecked(0, NULL);
60641+#endif
60642+
60643+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60644+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60645+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60646+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60647+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60648+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60649+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60650+}
60651+#else
60652+#define atomic_read_unchecked(v) atomic_read(v)
60653+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60654+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60655+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60656+#define atomic_inc_unchecked(v) atomic_inc(v)
60657+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60658+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60659+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60660+#define atomic_dec_unchecked(v) atomic_dec(v)
60661+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60662+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60663+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60664+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60665+
60666+#define atomic_long_read_unchecked(v) atomic_long_read(v)
60667+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60668+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60669+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60670+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60671+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60672+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60673+#endif
60674+
60675 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60676diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60677index 1ced641..c896ee8 100644
60678--- a/include/asm-generic/atomic.h
60679+++ b/include/asm-generic/atomic.h
60680@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60681 * Atomically clears the bits set in @mask from @v
60682 */
60683 #ifndef atomic_clear_mask
60684-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60685+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60686 {
60687 unsigned long flags;
60688
60689diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60690index b18ce4f..2ee2843 100644
60691--- a/include/asm-generic/atomic64.h
60692+++ b/include/asm-generic/atomic64.h
60693@@ -16,6 +16,8 @@ typedef struct {
60694 long long counter;
60695 } atomic64_t;
60696
60697+typedef atomic64_t atomic64_unchecked_t;
60698+
60699 #define ATOMIC64_INIT(i) { (i) }
60700
60701 extern long long atomic64_read(const atomic64_t *v);
60702@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60703 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60704 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60705
60706+#define atomic64_read_unchecked(v) atomic64_read(v)
60707+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60708+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60709+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60710+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60711+#define atomic64_inc_unchecked(v) atomic64_inc(v)
60712+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60713+#define atomic64_dec_unchecked(v) atomic64_dec(v)
60714+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60715+
60716 #endif /* _ASM_GENERIC_ATOMIC64_H */
60717diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60718index 1bfcfe5..e04c5c9 100644
60719--- a/include/asm-generic/cache.h
60720+++ b/include/asm-generic/cache.h
60721@@ -6,7 +6,7 @@
60722 * cache lines need to provide their own cache.h.
60723 */
60724
60725-#define L1_CACHE_SHIFT 5
60726-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60727+#define L1_CACHE_SHIFT 5UL
60728+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60729
60730 #endif /* __ASM_GENERIC_CACHE_H */
60731diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60732index 0d68a1e..b74a761 100644
60733--- a/include/asm-generic/emergency-restart.h
60734+++ b/include/asm-generic/emergency-restart.h
60735@@ -1,7 +1,7 @@
60736 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60737 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60738
60739-static inline void machine_emergency_restart(void)
60740+static inline __noreturn void machine_emergency_restart(void)
60741 {
60742 machine_restart(NULL);
60743 }
60744diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60745index 90f99c7..00ce236 100644
60746--- a/include/asm-generic/kmap_types.h
60747+++ b/include/asm-generic/kmap_types.h
60748@@ -2,9 +2,9 @@
60749 #define _ASM_GENERIC_KMAP_TYPES_H
60750
60751 #ifdef __WITH_KM_FENCE
60752-# define KM_TYPE_NR 41
60753+# define KM_TYPE_NR 42
60754 #else
60755-# define KM_TYPE_NR 20
60756+# define KM_TYPE_NR 21
60757 #endif
60758
60759 #endif
60760diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60761index 9ceb03b..2efbcbd 100644
60762--- a/include/asm-generic/local.h
60763+++ b/include/asm-generic/local.h
60764@@ -39,6 +39,7 @@ typedef struct
60765 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60766 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60767 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60768+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60769
60770 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60771 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60772diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60773index 725612b..9cc513a 100644
60774--- a/include/asm-generic/pgtable-nopmd.h
60775+++ b/include/asm-generic/pgtable-nopmd.h
60776@@ -1,14 +1,19 @@
60777 #ifndef _PGTABLE_NOPMD_H
60778 #define _PGTABLE_NOPMD_H
60779
60780-#ifndef __ASSEMBLY__
60781-
60782 #include <asm-generic/pgtable-nopud.h>
60783
60784-struct mm_struct;
60785-
60786 #define __PAGETABLE_PMD_FOLDED
60787
60788+#define PMD_SHIFT PUD_SHIFT
60789+#define PTRS_PER_PMD 1
60790+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60791+#define PMD_MASK (~(PMD_SIZE-1))
60792+
60793+#ifndef __ASSEMBLY__
60794+
60795+struct mm_struct;
60796+
60797 /*
60798 * Having the pmd type consist of a pud gets the size right, and allows
60799 * us to conceptually access the pud entry that this pmd is folded into
60800@@ -16,11 +21,6 @@ struct mm_struct;
60801 */
60802 typedef struct { pud_t pud; } pmd_t;
60803
60804-#define PMD_SHIFT PUD_SHIFT
60805-#define PTRS_PER_PMD 1
60806-#define PMD_SIZE (1UL << PMD_SHIFT)
60807-#define PMD_MASK (~(PMD_SIZE-1))
60808-
60809 /*
60810 * The "pud_xxx()" functions here are trivial for a folded two-level
60811 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60812diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60813index 810431d..0ec4804f 100644
60814--- a/include/asm-generic/pgtable-nopud.h
60815+++ b/include/asm-generic/pgtable-nopud.h
60816@@ -1,10 +1,15 @@
60817 #ifndef _PGTABLE_NOPUD_H
60818 #define _PGTABLE_NOPUD_H
60819
60820-#ifndef __ASSEMBLY__
60821-
60822 #define __PAGETABLE_PUD_FOLDED
60823
60824+#define PUD_SHIFT PGDIR_SHIFT
60825+#define PTRS_PER_PUD 1
60826+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60827+#define PUD_MASK (~(PUD_SIZE-1))
60828+
60829+#ifndef __ASSEMBLY__
60830+
60831 /*
60832 * Having the pud type consist of a pgd gets the size right, and allows
60833 * us to conceptually access the pgd entry that this pud is folded into
60834@@ -12,11 +17,6 @@
60835 */
60836 typedef struct { pgd_t pgd; } pud_t;
60837
60838-#define PUD_SHIFT PGDIR_SHIFT
60839-#define PTRS_PER_PUD 1
60840-#define PUD_SIZE (1UL << PUD_SHIFT)
60841-#define PUD_MASK (~(PUD_SIZE-1))
60842-
60843 /*
60844 * The "pgd_xxx()" functions here are trivial for a folded two-level
60845 * setup: the pud is never bad, and a pud always exists (as it's folded
60846@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60847 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60848
60849 #define pgd_populate(mm, pgd, pud) do { } while (0)
60850+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60851 /*
60852 * (puds are folded into pgds so this doesn't get actually called,
60853 * but the define is needed for a generic inline function.)
60854diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60855index ff4947b..f48183f 100644
60856--- a/include/asm-generic/pgtable.h
60857+++ b/include/asm-generic/pgtable.h
60858@@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60859 #endif
60860 }
60861
60862+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60863+static inline unsigned long pax_open_kernel(void) { return 0; }
60864+#endif
60865+
60866+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60867+static inline unsigned long pax_close_kernel(void) { return 0; }
60868+#endif
60869+
60870 #endif /* CONFIG_MMU */
60871
60872 #endif /* !__ASSEMBLY__ */
60873diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60874index 4e2e1cc..12c266b 100644
60875--- a/include/asm-generic/vmlinux.lds.h
60876+++ b/include/asm-generic/vmlinux.lds.h
60877@@ -218,6 +218,7 @@
60878 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60879 VMLINUX_SYMBOL(__start_rodata) = .; \
60880 *(.rodata) *(.rodata.*) \
60881+ *(.data..read_only) \
60882 *(__vermagic) /* Kernel version magic */ \
60883 . = ALIGN(8); \
60884 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60885@@ -716,17 +717,18 @@
60886 * section in the linker script will go there too. @phdr should have
60887 * a leading colon.
60888 *
60889- * Note that this macros defines __per_cpu_load as an absolute symbol.
60890+ * Note that this macros defines per_cpu_load as an absolute symbol.
60891 * If there is no need to put the percpu section at a predetermined
60892 * address, use PERCPU_SECTION.
60893 */
60894 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60895- VMLINUX_SYMBOL(__per_cpu_load) = .; \
60896- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60897+ per_cpu_load = .; \
60898+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60899 - LOAD_OFFSET) { \
60900+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60901 PERCPU_INPUT(cacheline) \
60902 } phdr \
60903- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60904+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60905
60906 /**
60907 * PERCPU_SECTION - define output section for percpu area, simple version
60908diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60909index d6b67bb..a272c29 100644
60910--- a/include/drm/drmP.h
60911+++ b/include/drm/drmP.h
60912@@ -72,6 +72,7 @@
60913 #include <linux/workqueue.h>
60914 #include <linux/poll.h>
60915 #include <asm/pgalloc.h>
60916+#include <asm/local.h>
60917 #include "drm.h"
60918
60919 #include <linux/idr.h>
60920@@ -1067,7 +1068,7 @@ struct drm_device {
60921
60922 /** \name Usage Counters */
60923 /*@{ */
60924- int open_count; /**< Outstanding files open */
60925+ local_t open_count; /**< Outstanding files open */
60926 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60927 atomic_t vma_count; /**< Outstanding vma areas open */
60928 int buf_use; /**< Buffers in use -- cannot alloc */
60929@@ -1078,7 +1079,7 @@ struct drm_device {
60930 /*@{ */
60931 unsigned long counters;
60932 enum drm_stat_type types[15];
60933- atomic_t counts[15];
60934+ atomic_unchecked_t counts[15];
60935 /*@} */
60936
60937 struct list_head filelist;
60938diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60939index e01cc80..319855d 100644
60940--- a/include/drm/drm_crtc_helper.h
60941+++ b/include/drm/drm_crtc_helper.h
60942@@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60943
60944 /* disable crtc when not in use - more explicit than dpms off */
60945 void (*disable)(struct drm_crtc *crtc);
60946-};
60947+} __no_const;
60948
60949 /**
60950 * drm_encoder_helper_funcs - helper operations for encoders
60951@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60952 struct drm_connector *connector);
60953 /* disable encoder when not in use - more explicit than dpms off */
60954 void (*disable)(struct drm_encoder *encoder);
60955-};
60956+} __no_const;
60957
60958 /**
60959 * drm_connector_helper_funcs - helper operations for connectors
60960diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60961index d6d1da4..fdd1ac5 100644
60962--- a/include/drm/ttm/ttm_memory.h
60963+++ b/include/drm/ttm/ttm_memory.h
60964@@ -48,7 +48,7 @@
60965
60966 struct ttm_mem_shrink {
60967 int (*do_shrink) (struct ttm_mem_shrink *);
60968-};
60969+} __no_const;
60970
60971 /**
60972 * struct ttm_mem_global - Global memory accounting structure.
60973diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60974index e86dfca..40cc55f 100644
60975--- a/include/linux/a.out.h
60976+++ b/include/linux/a.out.h
60977@@ -39,6 +39,14 @@ enum machine_type {
60978 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60979 };
60980
60981+/* Constants for the N_FLAGS field */
60982+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60983+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60984+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60985+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60986+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60987+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60988+
60989 #if !defined (N_MAGIC)
60990 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60991 #endif
60992diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60993index 06fd4bb..1caec0d 100644
60994--- a/include/linux/atmdev.h
60995+++ b/include/linux/atmdev.h
60996@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60997 #endif
60998
60999 struct k_atm_aal_stats {
61000-#define __HANDLE_ITEM(i) atomic_t i
61001+#define __HANDLE_ITEM(i) atomic_unchecked_t i
61002 __AAL_STAT_ITEMS
61003 #undef __HANDLE_ITEM
61004 };
61005diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61006index 366422b..1fa7f84 100644
61007--- a/include/linux/binfmts.h
61008+++ b/include/linux/binfmts.h
61009@@ -89,6 +89,7 @@ struct linux_binfmt {
61010 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61011 int (*load_shlib)(struct file *);
61012 int (*core_dump)(struct coredump_params *cprm);
61013+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61014 unsigned long min_coredump; /* minimal dump size */
61015 };
61016
61017diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61018index 4a2ab7c..a2de7a8 100644
61019--- a/include/linux/blkdev.h
61020+++ b/include/linux/blkdev.h
61021@@ -1420,7 +1420,7 @@ struct block_device_operations {
61022 /* this callback is with swap_lock and sometimes page table lock held */
61023 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61024 struct module *owner;
61025-};
61026+} __do_const;
61027
61028 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61029 unsigned long);
61030diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61031index 4d1a074..88f929a 100644
61032--- a/include/linux/blktrace_api.h
61033+++ b/include/linux/blktrace_api.h
61034@@ -162,7 +162,7 @@ struct blk_trace {
61035 struct dentry *dir;
61036 struct dentry *dropped_file;
61037 struct dentry *msg_file;
61038- atomic_t dropped;
61039+ atomic_unchecked_t dropped;
61040 };
61041
61042 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61043diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61044index 83195fb..0b0f77d 100644
61045--- a/include/linux/byteorder/little_endian.h
61046+++ b/include/linux/byteorder/little_endian.h
61047@@ -42,51 +42,51 @@
61048
61049 static inline __le64 __cpu_to_le64p(const __u64 *p)
61050 {
61051- return (__force __le64)*p;
61052+ return (__force const __le64)*p;
61053 }
61054 static inline __u64 __le64_to_cpup(const __le64 *p)
61055 {
61056- return (__force __u64)*p;
61057+ return (__force const __u64)*p;
61058 }
61059 static inline __le32 __cpu_to_le32p(const __u32 *p)
61060 {
61061- return (__force __le32)*p;
61062+ return (__force const __le32)*p;
61063 }
61064 static inline __u32 __le32_to_cpup(const __le32 *p)
61065 {
61066- return (__force __u32)*p;
61067+ return (__force const __u32)*p;
61068 }
61069 static inline __le16 __cpu_to_le16p(const __u16 *p)
61070 {
61071- return (__force __le16)*p;
61072+ return (__force const __le16)*p;
61073 }
61074 static inline __u16 __le16_to_cpup(const __le16 *p)
61075 {
61076- return (__force __u16)*p;
61077+ return (__force const __u16)*p;
61078 }
61079 static inline __be64 __cpu_to_be64p(const __u64 *p)
61080 {
61081- return (__force __be64)__swab64p(p);
61082+ return (__force const __be64)__swab64p(p);
61083 }
61084 static inline __u64 __be64_to_cpup(const __be64 *p)
61085 {
61086- return __swab64p((__u64 *)p);
61087+ return __swab64p((const __u64 *)p);
61088 }
61089 static inline __be32 __cpu_to_be32p(const __u32 *p)
61090 {
61091- return (__force __be32)__swab32p(p);
61092+ return (__force const __be32)__swab32p(p);
61093 }
61094 static inline __u32 __be32_to_cpup(const __be32 *p)
61095 {
61096- return __swab32p((__u32 *)p);
61097+ return __swab32p((const __u32 *)p);
61098 }
61099 static inline __be16 __cpu_to_be16p(const __u16 *p)
61100 {
61101- return (__force __be16)__swab16p(p);
61102+ return (__force const __be16)__swab16p(p);
61103 }
61104 static inline __u16 __be16_to_cpup(const __be16 *p)
61105 {
61106- return __swab16p((__u16 *)p);
61107+ return __swab16p((const __u16 *)p);
61108 }
61109 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61110 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61111diff --git a/include/linux/cache.h b/include/linux/cache.h
61112index 4c57065..4307975 100644
61113--- a/include/linux/cache.h
61114+++ b/include/linux/cache.h
61115@@ -16,6 +16,10 @@
61116 #define __read_mostly
61117 #endif
61118
61119+#ifndef __read_only
61120+#define __read_only __read_mostly
61121+#endif
61122+
61123 #ifndef ____cacheline_aligned
61124 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61125 #endif
61126diff --git a/include/linux/capability.h b/include/linux/capability.h
61127index d10b7ed..0288b79 100644
61128--- a/include/linux/capability.h
61129+++ b/include/linux/capability.h
61130@@ -553,10 +553,15 @@ extern bool capable(int cap);
61131 extern bool ns_capable(struct user_namespace *ns, int cap);
61132 extern bool nsown_capable(int cap);
61133 extern bool inode_capable(const struct inode *inode, int cap);
61134+extern bool capable_nolog(int cap);
61135+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61136+extern bool inode_capable_nolog(const struct inode *inode, int cap);
61137
61138 /* audit system wants to get cap info from files as well */
61139 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61140
61141+extern int is_privileged_binary(const struct dentry *dentry);
61142+
61143 #endif /* __KERNEL__ */
61144
61145 #endif /* !_LINUX_CAPABILITY_H */
61146diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61147index 42e55de..1cd0e66 100644
61148--- a/include/linux/cleancache.h
61149+++ b/include/linux/cleancache.h
61150@@ -31,7 +31,7 @@ struct cleancache_ops {
61151 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61152 void (*invalidate_inode)(int, struct cleancache_filekey);
61153 void (*invalidate_fs)(int);
61154-};
61155+} __no_const;
61156
61157 extern struct cleancache_ops
61158 cleancache_register_ops(struct cleancache_ops *ops);
61159diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61160index 77335fa..6cbe7dd 100644
61161--- a/include/linux/clk-provider.h
61162+++ b/include/linux/clk-provider.h
61163@@ -111,6 +111,7 @@ struct clk_ops {
61164 unsigned long);
61165 void (*init)(struct clk_hw *hw);
61166 };
61167+typedef struct clk_ops __no_const clk_ops_no_const;
61168
61169 /**
61170 * struct clk_init_data - holds init data that's common to all clocks and is
61171diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61172index 934bc34..1b47129 100644
61173--- a/include/linux/compiler-gcc4.h
61174+++ b/include/linux/compiler-gcc4.h
61175@@ -32,6 +32,21 @@
61176 #define __linktime_error(message) __attribute__((__error__(message)))
61177
61178 #if __GNUC_MINOR__ >= 5
61179+
61180+#ifdef CONSTIFY_PLUGIN
61181+#define __no_const __attribute__((no_const))
61182+#define __do_const __attribute__((do_const))
61183+#endif
61184+
61185+#ifdef SIZE_OVERFLOW_PLUGIN
61186+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61187+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61188+#endif
61189+
61190+#ifdef LATENT_ENTROPY_PLUGIN
61191+#define __latent_entropy __attribute__((latent_entropy))
61192+#endif
61193+
61194 /*
61195 * Mark a position in code as unreachable. This can be used to
61196 * suppress control flow warnings after asm blocks that transfer
61197@@ -47,6 +62,11 @@
61198 #define __noclone __attribute__((__noclone__))
61199
61200 #endif
61201+
61202+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61203+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61204+#define __bos0(ptr) __bos((ptr), 0)
61205+#define __bos1(ptr) __bos((ptr), 1)
61206 #endif
61207
61208 #if __GNUC_MINOR__ >= 6
61209diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61210index f430e41..38be90f 100644
61211--- a/include/linux/compiler.h
61212+++ b/include/linux/compiler.h
61213@@ -5,31 +5,62 @@
61214
61215 #ifdef __CHECKER__
61216 # define __user __attribute__((noderef, address_space(1)))
61217+# define __force_user __force __user
61218 # define __kernel __attribute__((address_space(0)))
61219+# define __force_kernel __force __kernel
61220 # define __safe __attribute__((safe))
61221 # define __force __attribute__((force))
61222 # define __nocast __attribute__((nocast))
61223 # define __iomem __attribute__((noderef, address_space(2)))
61224+# define __force_iomem __force __iomem
61225 # define __acquires(x) __attribute__((context(x,0,1)))
61226 # define __releases(x) __attribute__((context(x,1,0)))
61227 # define __acquire(x) __context__(x,1)
61228 # define __release(x) __context__(x,-1)
61229 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61230 # define __percpu __attribute__((noderef, address_space(3)))
61231+# define __force_percpu __force __percpu
61232 #ifdef CONFIG_SPARSE_RCU_POINTER
61233 # define __rcu __attribute__((noderef, address_space(4)))
61234+# define __force_rcu __force __rcu
61235 #else
61236 # define __rcu
61237+# define __force_rcu
61238 #endif
61239 extern void __chk_user_ptr(const volatile void __user *);
61240 extern void __chk_io_ptr(const volatile void __iomem *);
61241+#elif defined(CHECKER_PLUGIN)
61242+//# define __user
61243+//# define __force_user
61244+//# define __kernel
61245+//# define __force_kernel
61246+# define __safe
61247+# define __force
61248+# define __nocast
61249+# define __iomem
61250+# define __force_iomem
61251+# define __chk_user_ptr(x) (void)0
61252+# define __chk_io_ptr(x) (void)0
61253+# define __builtin_warning(x, y...) (1)
61254+# define __acquires(x)
61255+# define __releases(x)
61256+# define __acquire(x) (void)0
61257+# define __release(x) (void)0
61258+# define __cond_lock(x,c) (c)
61259+# define __percpu
61260+# define __force_percpu
61261+# define __rcu
61262+# define __force_rcu
61263 #else
61264 # define __user
61265+# define __force_user
61266 # define __kernel
61267+# define __force_kernel
61268 # define __safe
61269 # define __force
61270 # define __nocast
61271 # define __iomem
61272+# define __force_iomem
61273 # define __chk_user_ptr(x) (void)0
61274 # define __chk_io_ptr(x) (void)0
61275 # define __builtin_warning(x, y...) (1)
61276@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61277 # define __release(x) (void)0
61278 # define __cond_lock(x,c) (c)
61279 # define __percpu
61280+# define __force_percpu
61281 # define __rcu
61282+# define __force_rcu
61283 #endif
61284
61285 #ifdef __KERNEL__
61286@@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61287 # define __attribute_const__ /* unimplemented */
61288 #endif
61289
61290+#ifndef __no_const
61291+# define __no_const
61292+#endif
61293+
61294+#ifndef __do_const
61295+# define __do_const
61296+#endif
61297+
61298+#ifndef __size_overflow
61299+# define __size_overflow(...)
61300+#endif
61301+
61302+#ifndef __intentional_overflow
61303+# define __intentional_overflow(...)
61304+#endif
61305+
61306+#ifndef __latent_entropy
61307+# define __latent_entropy
61308+#endif
61309+
61310 /*
61311 * Tell gcc if a function is cold. The compiler will assume any path
61312 * directly leading to the call is unlikely.
61313@@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61314 #define __cold
61315 #endif
61316
61317+#ifndef __alloc_size
61318+#define __alloc_size(...)
61319+#endif
61320+
61321+#ifndef __bos
61322+#define __bos(ptr, arg)
61323+#endif
61324+
61325+#ifndef __bos0
61326+#define __bos0(ptr)
61327+#endif
61328+
61329+#ifndef __bos1
61330+#define __bos1(ptr)
61331+#endif
61332+
61333 /* Simple shorthand for a section definition */
61334 #ifndef __section
61335 # define __section(S) __attribute__ ((__section__(#S)))
61336@@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61337 * use is to mediate communication between process-level code and irq/NMI
61338 * handlers, all running on the same CPU.
61339 */
61340-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61341+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61342+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61343
61344 #endif /* __LINUX_COMPILER_H */
61345diff --git a/include/linux/cred.h b/include/linux/cred.h
61346index ebbed2c..908cc2c 100644
61347--- a/include/linux/cred.h
61348+++ b/include/linux/cred.h
61349@@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61350 static inline void validate_process_creds(void)
61351 {
61352 }
61353+static inline void validate_task_creds(struct task_struct *task)
61354+{
61355+}
61356 #endif
61357
61358 /**
61359diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61360index b92eadf..b4ecdc1 100644
61361--- a/include/linux/crypto.h
61362+++ b/include/linux/crypto.h
61363@@ -373,7 +373,7 @@ struct cipher_tfm {
61364 const u8 *key, unsigned int keylen);
61365 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61366 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61367-};
61368+} __no_const;
61369
61370 struct hash_tfm {
61371 int (*init)(struct hash_desc *desc);
61372@@ -394,13 +394,13 @@ struct compress_tfm {
61373 int (*cot_decompress)(struct crypto_tfm *tfm,
61374 const u8 *src, unsigned int slen,
61375 u8 *dst, unsigned int *dlen);
61376-};
61377+} __no_const;
61378
61379 struct rng_tfm {
61380 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61381 unsigned int dlen);
61382 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61383-};
61384+} __no_const;
61385
61386 #define crt_ablkcipher crt_u.ablkcipher
61387 #define crt_aead crt_u.aead
61388diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61389index 7925bf0..d5143d2 100644
61390--- a/include/linux/decompress/mm.h
61391+++ b/include/linux/decompress/mm.h
61392@@ -77,7 +77,7 @@ static void free(void *where)
61393 * warnings when not needed (indeed large_malloc / large_free are not
61394 * needed by inflate */
61395
61396-#define malloc(a) kmalloc(a, GFP_KERNEL)
61397+#define malloc(a) kmalloc((a), GFP_KERNEL)
61398 #define free(a) kfree(a)
61399
61400 #define large_malloc(a) vmalloc(a)
61401diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61402index 94af418..b1ca7a2 100644
61403--- a/include/linux/dma-mapping.h
61404+++ b/include/linux/dma-mapping.h
61405@@ -54,7 +54,7 @@ struct dma_map_ops {
61406 u64 (*get_required_mask)(struct device *dev);
61407 #endif
61408 int is_phys;
61409-};
61410+} __do_const;
61411
61412 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61413
61414diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61415index 9c02a45..89fdd73 100644
61416--- a/include/linux/dmaengine.h
61417+++ b/include/linux/dmaengine.h
61418@@ -1017,9 +1017,9 @@ struct dma_pinned_list {
61419 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61420 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61421
61422-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61423+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61424 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61425-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61426+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61427 struct dma_pinned_list *pinned_list, struct page *page,
61428 unsigned int offset, size_t len);
61429
61430diff --git a/include/linux/efi.h b/include/linux/efi.h
61431index ec45ccd..9923c32 100644
61432--- a/include/linux/efi.h
61433+++ b/include/linux/efi.h
61434@@ -635,7 +635,7 @@ struct efivar_operations {
61435 efi_get_variable_t *get_variable;
61436 efi_get_next_variable_t *get_next_variable;
61437 efi_set_variable_t *set_variable;
61438-};
61439+} __no_const;
61440
61441 struct efivars {
61442 /*
61443diff --git a/include/linux/elf.h b/include/linux/elf.h
61444index 999b4f5..57753b4 100644
61445--- a/include/linux/elf.h
61446+++ b/include/linux/elf.h
61447@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61448 #define PT_GNU_EH_FRAME 0x6474e550
61449
61450 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61451+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61452+
61453+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61454+
61455+/* Constants for the e_flags field */
61456+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61457+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61458+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61459+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61460+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61461+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61462
61463 /*
61464 * Extended Numbering
61465@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61466 #define DT_DEBUG 21
61467 #define DT_TEXTREL 22
61468 #define DT_JMPREL 23
61469+#define DT_FLAGS 30
61470+ #define DF_TEXTREL 0x00000004
61471 #define DT_ENCODING 32
61472 #define OLD_DT_LOOS 0x60000000
61473 #define DT_LOOS 0x6000000d
61474@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61475 #define PF_W 0x2
61476 #define PF_X 0x1
61477
61478+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61479+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61480+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61481+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61482+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61483+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61484+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61485+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61486+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61487+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61488+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61489+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61490+
61491 typedef struct elf32_phdr{
61492 Elf32_Word p_type;
61493 Elf32_Off p_offset;
61494@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61495 #define EI_OSABI 7
61496 #define EI_PAD 8
61497
61498+#define EI_PAX 14
61499+
61500 #define ELFMAG0 0x7f /* EI_MAG */
61501 #define ELFMAG1 'E'
61502 #define ELFMAG2 'L'
61503@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61504 #define elf_note elf32_note
61505 #define elf_addr_t Elf32_Off
61506 #define Elf_Half Elf32_Half
61507+#define elf_dyn Elf32_Dyn
61508
61509 #else
61510
61511@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61512 #define elf_note elf64_note
61513 #define elf_addr_t Elf64_Off
61514 #define Elf_Half Elf64_Half
61515+#define elf_dyn Elf64_Dyn
61516
61517 #endif
61518
61519diff --git a/include/linux/filter.h b/include/linux/filter.h
61520index 82b0135..917914d 100644
61521--- a/include/linux/filter.h
61522+++ b/include/linux/filter.h
61523@@ -146,6 +146,7 @@ struct compat_sock_fprog {
61524
61525 struct sk_buff;
61526 struct sock;
61527+struct bpf_jit_work;
61528
61529 struct sk_filter
61530 {
61531@@ -153,6 +154,9 @@ struct sk_filter
61532 unsigned int len; /* Number of filter blocks */
61533 unsigned int (*bpf_func)(const struct sk_buff *skb,
61534 const struct sock_filter *filter);
61535+#ifdef CONFIG_BPF_JIT
61536+ struct bpf_jit_work *work;
61537+#endif
61538 struct rcu_head rcu;
61539 struct sock_filter insns[0];
61540 };
61541diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61542index db04ec5..f6ed627 100644
61543--- a/include/linux/firewire.h
61544+++ b/include/linux/firewire.h
61545@@ -430,7 +430,7 @@ struct fw_iso_context {
61546 union {
61547 fw_iso_callback_t sc;
61548 fw_iso_mc_callback_t mc;
61549- } callback;
61550+ } __no_const callback;
61551 void *callback_data;
61552 };
61553
61554diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61555index 0e4e2ee..4ff4312 100644
61556--- a/include/linux/frontswap.h
61557+++ b/include/linux/frontswap.h
61558@@ -11,7 +11,7 @@ struct frontswap_ops {
61559 int (*load)(unsigned, pgoff_t, struct page *);
61560 void (*invalidate_page)(unsigned, pgoff_t);
61561 void (*invalidate_area)(unsigned);
61562-};
61563+} __no_const;
61564
61565 extern bool frontswap_enabled;
61566 extern struct frontswap_ops
61567diff --git a/include/linux/fs.h b/include/linux/fs.h
61568index aa11047..7d046d0 100644
61569--- a/include/linux/fs.h
61570+++ b/include/linux/fs.h
61571@@ -1802,7 +1802,8 @@ struct file_operations {
61572 int (*setlease)(struct file *, long, struct file_lock **);
61573 long (*fallocate)(struct file *file, int mode, loff_t offset,
61574 loff_t len);
61575-};
61576+} __do_const;
61577+typedef struct file_operations __no_const file_operations_no_const;
61578
61579 struct inode_operations {
61580 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61581diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61582index 003dc0f..3c4ea97 100644
61583--- a/include/linux/fs_struct.h
61584+++ b/include/linux/fs_struct.h
61585@@ -6,7 +6,7 @@
61586 #include <linux/seqlock.h>
61587
61588 struct fs_struct {
61589- int users;
61590+ atomic_t users;
61591 spinlock_t lock;
61592 seqcount_t seq;
61593 int umask;
61594diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61595index ce31408..b1ad003 100644
61596--- a/include/linux/fscache-cache.h
61597+++ b/include/linux/fscache-cache.h
61598@@ -102,7 +102,7 @@ struct fscache_operation {
61599 fscache_operation_release_t release;
61600 };
61601
61602-extern atomic_t fscache_op_debug_id;
61603+extern atomic_unchecked_t fscache_op_debug_id;
61604 extern void fscache_op_work_func(struct work_struct *work);
61605
61606 extern void fscache_enqueue_operation(struct fscache_operation *);
61607@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61608 {
61609 INIT_WORK(&op->work, fscache_op_work_func);
61610 atomic_set(&op->usage, 1);
61611- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61612+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61613 op->processor = processor;
61614 op->release = release;
61615 INIT_LIST_HEAD(&op->pend_link);
61616diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61617index a6dfe69..569586df 100644
61618--- a/include/linux/fsnotify.h
61619+++ b/include/linux/fsnotify.h
61620@@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61621 */
61622 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61623 {
61624- return kstrdup(name, GFP_KERNEL);
61625+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61626 }
61627
61628 /*
61629diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61630index 63d966d..cdcb717 100644
61631--- a/include/linux/fsnotify_backend.h
61632+++ b/include/linux/fsnotify_backend.h
61633@@ -105,6 +105,7 @@ struct fsnotify_ops {
61634 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61635 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61636 };
61637+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61638
61639 /*
61640 * A group is a "thing" that wants to receive notification about filesystem
61641diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61642index 642928c..e6c83a7 100644
61643--- a/include/linux/ftrace_event.h
61644+++ b/include/linux/ftrace_event.h
61645@@ -97,7 +97,7 @@ struct trace_event_functions {
61646 trace_print_func raw;
61647 trace_print_func hex;
61648 trace_print_func binary;
61649-};
61650+} __no_const;
61651
61652 struct trace_event {
61653 struct hlist_node node;
61654@@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61655 extern int trace_add_event_call(struct ftrace_event_call *call);
61656 extern void trace_remove_event_call(struct ftrace_event_call *call);
61657
61658-#define is_signed_type(type) (((type)(-1)) < 0)
61659+#define is_signed_type(type) (((type)(-1)) < (type)1)
61660
61661 int trace_set_clr_event(const char *system, const char *event, int set);
61662
61663diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61664index 4f440b3..342233a 100644
61665--- a/include/linux/genhd.h
61666+++ b/include/linux/genhd.h
61667@@ -190,7 +190,7 @@ struct gendisk {
61668 struct kobject *slave_dir;
61669
61670 struct timer_rand_state *random;
61671- atomic_t sync_io; /* RAID */
61672+ atomic_unchecked_t sync_io; /* RAID */
61673 struct disk_events *ev;
61674 #ifdef CONFIG_BLK_DEV_INTEGRITY
61675 struct blk_integrity *integrity;
61676diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61677index 4883f39..26688a8 100644
61678--- a/include/linux/gfp.h
61679+++ b/include/linux/gfp.h
61680@@ -39,6 +39,12 @@ struct vm_area_struct;
61681 #define ___GFP_OTHER_NODE 0x800000u
61682 #define ___GFP_WRITE 0x1000000u
61683
61684+#ifdef CONFIG_PAX_USERCOPY_SLABS
61685+#define ___GFP_USERCOPY 0x2000000u
61686+#else
61687+#define ___GFP_USERCOPY 0
61688+#endif
61689+
61690 /*
61691 * GFP bitmasks..
61692 *
61693@@ -93,6 +99,7 @@ struct vm_area_struct;
61694 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61695 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61696 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61697+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61698
61699 /*
61700 * This may seem redundant, but it's a way of annotating false positives vs.
61701@@ -100,7 +107,7 @@ struct vm_area_struct;
61702 */
61703 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61704
61705-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61706+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61707 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61708
61709 /* This equals 0, but use constants in case they ever change */
61710@@ -154,6 +161,8 @@ struct vm_area_struct;
61711 /* 4GB DMA on some platforms */
61712 #define GFP_DMA32 __GFP_DMA32
61713
61714+#define GFP_USERCOPY __GFP_USERCOPY
61715+
61716 /* Convert GFP flags to their corresponding migrate type */
61717 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61718 {
61719diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61720new file mode 100644
61721index 0000000..c938b1f
61722--- /dev/null
61723+++ b/include/linux/gracl.h
61724@@ -0,0 +1,319 @@
61725+#ifndef GR_ACL_H
61726+#define GR_ACL_H
61727+
61728+#include <linux/grdefs.h>
61729+#include <linux/resource.h>
61730+#include <linux/capability.h>
61731+#include <linux/dcache.h>
61732+#include <asm/resource.h>
61733+
61734+/* Major status information */
61735+
61736+#define GR_VERSION "grsecurity 2.9.1"
61737+#define GRSECURITY_VERSION 0x2901
61738+
61739+enum {
61740+ GR_SHUTDOWN = 0,
61741+ GR_ENABLE = 1,
61742+ GR_SPROLE = 2,
61743+ GR_RELOAD = 3,
61744+ GR_SEGVMOD = 4,
61745+ GR_STATUS = 5,
61746+ GR_UNSPROLE = 6,
61747+ GR_PASSSET = 7,
61748+ GR_SPROLEPAM = 8,
61749+};
61750+
61751+/* Password setup definitions
61752+ * kernel/grhash.c */
61753+enum {
61754+ GR_PW_LEN = 128,
61755+ GR_SALT_LEN = 16,
61756+ GR_SHA_LEN = 32,
61757+};
61758+
61759+enum {
61760+ GR_SPROLE_LEN = 64,
61761+};
61762+
61763+enum {
61764+ GR_NO_GLOB = 0,
61765+ GR_REG_GLOB,
61766+ GR_CREATE_GLOB
61767+};
61768+
61769+#define GR_NLIMITS 32
61770+
61771+/* Begin Data Structures */
61772+
61773+struct sprole_pw {
61774+ unsigned char *rolename;
61775+ unsigned char salt[GR_SALT_LEN];
61776+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61777+};
61778+
61779+struct name_entry {
61780+ __u32 key;
61781+ ino_t inode;
61782+ dev_t device;
61783+ char *name;
61784+ __u16 len;
61785+ __u8 deleted;
61786+ struct name_entry *prev;
61787+ struct name_entry *next;
61788+};
61789+
61790+struct inodev_entry {
61791+ struct name_entry *nentry;
61792+ struct inodev_entry *prev;
61793+ struct inodev_entry *next;
61794+};
61795+
61796+struct acl_role_db {
61797+ struct acl_role_label **r_hash;
61798+ __u32 r_size;
61799+};
61800+
61801+struct inodev_db {
61802+ struct inodev_entry **i_hash;
61803+ __u32 i_size;
61804+};
61805+
61806+struct name_db {
61807+ struct name_entry **n_hash;
61808+ __u32 n_size;
61809+};
61810+
61811+struct crash_uid {
61812+ uid_t uid;
61813+ unsigned long expires;
61814+};
61815+
61816+struct gr_hash_struct {
61817+ void **table;
61818+ void **nametable;
61819+ void *first;
61820+ __u32 table_size;
61821+ __u32 used_size;
61822+ int type;
61823+};
61824+
61825+/* Userspace Grsecurity ACL data structures */
61826+
61827+struct acl_subject_label {
61828+ char *filename;
61829+ ino_t inode;
61830+ dev_t device;
61831+ __u32 mode;
61832+ kernel_cap_t cap_mask;
61833+ kernel_cap_t cap_lower;
61834+ kernel_cap_t cap_invert_audit;
61835+
61836+ struct rlimit res[GR_NLIMITS];
61837+ __u32 resmask;
61838+
61839+ __u8 user_trans_type;
61840+ __u8 group_trans_type;
61841+ uid_t *user_transitions;
61842+ gid_t *group_transitions;
61843+ __u16 user_trans_num;
61844+ __u16 group_trans_num;
61845+
61846+ __u32 sock_families[2];
61847+ __u32 ip_proto[8];
61848+ __u32 ip_type;
61849+ struct acl_ip_label **ips;
61850+ __u32 ip_num;
61851+ __u32 inaddr_any_override;
61852+
61853+ __u32 crashes;
61854+ unsigned long expires;
61855+
61856+ struct acl_subject_label *parent_subject;
61857+ struct gr_hash_struct *hash;
61858+ struct acl_subject_label *prev;
61859+ struct acl_subject_label *next;
61860+
61861+ struct acl_object_label **obj_hash;
61862+ __u32 obj_hash_size;
61863+ __u16 pax_flags;
61864+};
61865+
61866+struct role_allowed_ip {
61867+ __u32 addr;
61868+ __u32 netmask;
61869+
61870+ struct role_allowed_ip *prev;
61871+ struct role_allowed_ip *next;
61872+};
61873+
61874+struct role_transition {
61875+ char *rolename;
61876+
61877+ struct role_transition *prev;
61878+ struct role_transition *next;
61879+};
61880+
61881+struct acl_role_label {
61882+ char *rolename;
61883+ uid_t uidgid;
61884+ __u16 roletype;
61885+
61886+ __u16 auth_attempts;
61887+ unsigned long expires;
61888+
61889+ struct acl_subject_label *root_label;
61890+ struct gr_hash_struct *hash;
61891+
61892+ struct acl_role_label *prev;
61893+ struct acl_role_label *next;
61894+
61895+ struct role_transition *transitions;
61896+ struct role_allowed_ip *allowed_ips;
61897+ uid_t *domain_children;
61898+ __u16 domain_child_num;
61899+
61900+ umode_t umask;
61901+
61902+ struct acl_subject_label **subj_hash;
61903+ __u32 subj_hash_size;
61904+};
61905+
61906+struct user_acl_role_db {
61907+ struct acl_role_label **r_table;
61908+ __u32 num_pointers; /* Number of allocations to track */
61909+ __u32 num_roles; /* Number of roles */
61910+ __u32 num_domain_children; /* Number of domain children */
61911+ __u32 num_subjects; /* Number of subjects */
61912+ __u32 num_objects; /* Number of objects */
61913+};
61914+
61915+struct acl_object_label {
61916+ char *filename;
61917+ ino_t inode;
61918+ dev_t device;
61919+ __u32 mode;
61920+
61921+ struct acl_subject_label *nested;
61922+ struct acl_object_label *globbed;
61923+
61924+ /* next two structures not used */
61925+
61926+ struct acl_object_label *prev;
61927+ struct acl_object_label *next;
61928+};
61929+
61930+struct acl_ip_label {
61931+ char *iface;
61932+ __u32 addr;
61933+ __u32 netmask;
61934+ __u16 low, high;
61935+ __u8 mode;
61936+ __u32 type;
61937+ __u32 proto[8];
61938+
61939+ /* next two structures not used */
61940+
61941+ struct acl_ip_label *prev;
61942+ struct acl_ip_label *next;
61943+};
61944+
61945+struct gr_arg {
61946+ struct user_acl_role_db role_db;
61947+ unsigned char pw[GR_PW_LEN];
61948+ unsigned char salt[GR_SALT_LEN];
61949+ unsigned char sum[GR_SHA_LEN];
61950+ unsigned char sp_role[GR_SPROLE_LEN];
61951+ struct sprole_pw *sprole_pws;
61952+ dev_t segv_device;
61953+ ino_t segv_inode;
61954+ uid_t segv_uid;
61955+ __u16 num_sprole_pws;
61956+ __u16 mode;
61957+};
61958+
61959+struct gr_arg_wrapper {
61960+ struct gr_arg *arg;
61961+ __u32 version;
61962+ __u32 size;
61963+};
61964+
61965+struct subject_map {
61966+ struct acl_subject_label *user;
61967+ struct acl_subject_label *kernel;
61968+ struct subject_map *prev;
61969+ struct subject_map *next;
61970+};
61971+
61972+struct acl_subj_map_db {
61973+ struct subject_map **s_hash;
61974+ __u32 s_size;
61975+};
61976+
61977+/* End Data Structures Section */
61978+
61979+/* Hash functions generated by empirical testing by Brad Spengler
61980+ Makes good use of the low bits of the inode. Generally 0-1 times
61981+ in loop for successful match. 0-3 for unsuccessful match.
61982+ Shift/add algorithm with modulus of table size and an XOR*/
61983+
61984+static __inline__ unsigned int
61985+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61986+{
61987+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
61988+}
61989+
61990+ static __inline__ unsigned int
61991+shash(const struct acl_subject_label *userp, const unsigned int sz)
61992+{
61993+ return ((const unsigned long)userp % sz);
61994+}
61995+
61996+static __inline__ unsigned int
61997+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61998+{
61999+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62000+}
62001+
62002+static __inline__ unsigned int
62003+nhash(const char *name, const __u16 len, const unsigned int sz)
62004+{
62005+ return full_name_hash((const unsigned char *)name, len) % sz;
62006+}
62007+
62008+#define FOR_EACH_ROLE_START(role) \
62009+ role = role_list; \
62010+ while (role) {
62011+
62012+#define FOR_EACH_ROLE_END(role) \
62013+ role = role->prev; \
62014+ }
62015+
62016+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62017+ subj = NULL; \
62018+ iter = 0; \
62019+ while (iter < role->subj_hash_size) { \
62020+ if (subj == NULL) \
62021+ subj = role->subj_hash[iter]; \
62022+ if (subj == NULL) { \
62023+ iter++; \
62024+ continue; \
62025+ }
62026+
62027+#define FOR_EACH_SUBJECT_END(subj,iter) \
62028+ subj = subj->next; \
62029+ if (subj == NULL) \
62030+ iter++; \
62031+ }
62032+
62033+
62034+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62035+ subj = role->hash->first; \
62036+ while (subj != NULL) {
62037+
62038+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62039+ subj = subj->next; \
62040+ }
62041+
62042+#endif
62043+
62044diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62045new file mode 100644
62046index 0000000..323ecf2
62047--- /dev/null
62048+++ b/include/linux/gralloc.h
62049@@ -0,0 +1,9 @@
62050+#ifndef __GRALLOC_H
62051+#define __GRALLOC_H
62052+
62053+void acl_free_all(void);
62054+int acl_alloc_stack_init(unsigned long size);
62055+void *acl_alloc(unsigned long len);
62056+void *acl_alloc_num(unsigned long num, unsigned long len);
62057+
62058+#endif
62059diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62060new file mode 100644
62061index 0000000..b30e9bc
62062--- /dev/null
62063+++ b/include/linux/grdefs.h
62064@@ -0,0 +1,140 @@
62065+#ifndef GRDEFS_H
62066+#define GRDEFS_H
62067+
62068+/* Begin grsecurity status declarations */
62069+
62070+enum {
62071+ GR_READY = 0x01,
62072+ GR_STATUS_INIT = 0x00 // disabled state
62073+};
62074+
62075+/* Begin ACL declarations */
62076+
62077+/* Role flags */
62078+
62079+enum {
62080+ GR_ROLE_USER = 0x0001,
62081+ GR_ROLE_GROUP = 0x0002,
62082+ GR_ROLE_DEFAULT = 0x0004,
62083+ GR_ROLE_SPECIAL = 0x0008,
62084+ GR_ROLE_AUTH = 0x0010,
62085+ GR_ROLE_NOPW = 0x0020,
62086+ GR_ROLE_GOD = 0x0040,
62087+ GR_ROLE_LEARN = 0x0080,
62088+ GR_ROLE_TPE = 0x0100,
62089+ GR_ROLE_DOMAIN = 0x0200,
62090+ GR_ROLE_PAM = 0x0400,
62091+ GR_ROLE_PERSIST = 0x0800
62092+};
62093+
62094+/* ACL Subject and Object mode flags */
62095+enum {
62096+ GR_DELETED = 0x80000000
62097+};
62098+
62099+/* ACL Object-only mode flags */
62100+enum {
62101+ GR_READ = 0x00000001,
62102+ GR_APPEND = 0x00000002,
62103+ GR_WRITE = 0x00000004,
62104+ GR_EXEC = 0x00000008,
62105+ GR_FIND = 0x00000010,
62106+ GR_INHERIT = 0x00000020,
62107+ GR_SETID = 0x00000040,
62108+ GR_CREATE = 0x00000080,
62109+ GR_DELETE = 0x00000100,
62110+ GR_LINK = 0x00000200,
62111+ GR_AUDIT_READ = 0x00000400,
62112+ GR_AUDIT_APPEND = 0x00000800,
62113+ GR_AUDIT_WRITE = 0x00001000,
62114+ GR_AUDIT_EXEC = 0x00002000,
62115+ GR_AUDIT_FIND = 0x00004000,
62116+ GR_AUDIT_INHERIT= 0x00008000,
62117+ GR_AUDIT_SETID = 0x00010000,
62118+ GR_AUDIT_CREATE = 0x00020000,
62119+ GR_AUDIT_DELETE = 0x00040000,
62120+ GR_AUDIT_LINK = 0x00080000,
62121+ GR_PTRACERD = 0x00100000,
62122+ GR_NOPTRACE = 0x00200000,
62123+ GR_SUPPRESS = 0x00400000,
62124+ GR_NOLEARN = 0x00800000,
62125+ GR_INIT_TRANSFER= 0x01000000
62126+};
62127+
62128+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62129+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62130+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62131+
62132+/* ACL subject-only mode flags */
62133+enum {
62134+ GR_KILL = 0x00000001,
62135+ GR_VIEW = 0x00000002,
62136+ GR_PROTECTED = 0x00000004,
62137+ GR_LEARN = 0x00000008,
62138+ GR_OVERRIDE = 0x00000010,
62139+ /* just a placeholder, this mode is only used in userspace */
62140+ GR_DUMMY = 0x00000020,
62141+ GR_PROTSHM = 0x00000040,
62142+ GR_KILLPROC = 0x00000080,
62143+ GR_KILLIPPROC = 0x00000100,
62144+ /* just a placeholder, this mode is only used in userspace */
62145+ GR_NOTROJAN = 0x00000200,
62146+ GR_PROTPROCFD = 0x00000400,
62147+ GR_PROCACCT = 0x00000800,
62148+ GR_RELAXPTRACE = 0x00001000,
62149+ GR_NESTED = 0x00002000,
62150+ GR_INHERITLEARN = 0x00004000,
62151+ GR_PROCFIND = 0x00008000,
62152+ GR_POVERRIDE = 0x00010000,
62153+ GR_KERNELAUTH = 0x00020000,
62154+ GR_ATSECURE = 0x00040000,
62155+ GR_SHMEXEC = 0x00080000
62156+};
62157+
62158+enum {
62159+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62160+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62161+ GR_PAX_ENABLE_MPROTECT = 0x0004,
62162+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
62163+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62164+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62165+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62166+ GR_PAX_DISABLE_MPROTECT = 0x0400,
62167+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
62168+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62169+};
62170+
62171+enum {
62172+ GR_ID_USER = 0x01,
62173+ GR_ID_GROUP = 0x02,
62174+};
62175+
62176+enum {
62177+ GR_ID_ALLOW = 0x01,
62178+ GR_ID_DENY = 0x02,
62179+};
62180+
62181+#define GR_CRASH_RES 31
62182+#define GR_UIDTABLE_MAX 500
62183+
62184+/* begin resource learning section */
62185+enum {
62186+ GR_RLIM_CPU_BUMP = 60,
62187+ GR_RLIM_FSIZE_BUMP = 50000,
62188+ GR_RLIM_DATA_BUMP = 10000,
62189+ GR_RLIM_STACK_BUMP = 1000,
62190+ GR_RLIM_CORE_BUMP = 10000,
62191+ GR_RLIM_RSS_BUMP = 500000,
62192+ GR_RLIM_NPROC_BUMP = 1,
62193+ GR_RLIM_NOFILE_BUMP = 5,
62194+ GR_RLIM_MEMLOCK_BUMP = 50000,
62195+ GR_RLIM_AS_BUMP = 500000,
62196+ GR_RLIM_LOCKS_BUMP = 2,
62197+ GR_RLIM_SIGPENDING_BUMP = 5,
62198+ GR_RLIM_MSGQUEUE_BUMP = 10000,
62199+ GR_RLIM_NICE_BUMP = 1,
62200+ GR_RLIM_RTPRIO_BUMP = 1,
62201+ GR_RLIM_RTTIME_BUMP = 1000000
62202+};
62203+
62204+#endif
62205diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62206new file mode 100644
62207index 0000000..c9292f7
62208--- /dev/null
62209+++ b/include/linux/grinternal.h
62210@@ -0,0 +1,223 @@
62211+#ifndef __GRINTERNAL_H
62212+#define __GRINTERNAL_H
62213+
62214+#ifdef CONFIG_GRKERNSEC
62215+
62216+#include <linux/fs.h>
62217+#include <linux/mnt_namespace.h>
62218+#include <linux/nsproxy.h>
62219+#include <linux/gracl.h>
62220+#include <linux/grdefs.h>
62221+#include <linux/grmsg.h>
62222+
62223+void gr_add_learn_entry(const char *fmt, ...)
62224+ __attribute__ ((format (printf, 1, 2)));
62225+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62226+ const struct vfsmount *mnt);
62227+__u32 gr_check_create(const struct dentry *new_dentry,
62228+ const struct dentry *parent,
62229+ const struct vfsmount *mnt, const __u32 mode);
62230+int gr_check_protected_task(const struct task_struct *task);
62231+__u32 to_gr_audit(const __u32 reqmode);
62232+int gr_set_acls(const int type);
62233+int gr_apply_subject_to_task(struct task_struct *task);
62234+int gr_acl_is_enabled(void);
62235+char gr_roletype_to_char(void);
62236+
62237+void gr_handle_alertkill(struct task_struct *task);
62238+char *gr_to_filename(const struct dentry *dentry,
62239+ const struct vfsmount *mnt);
62240+char *gr_to_filename1(const struct dentry *dentry,
62241+ const struct vfsmount *mnt);
62242+char *gr_to_filename2(const struct dentry *dentry,
62243+ const struct vfsmount *mnt);
62244+char *gr_to_filename3(const struct dentry *dentry,
62245+ const struct vfsmount *mnt);
62246+
62247+extern int grsec_enable_ptrace_readexec;
62248+extern int grsec_enable_harden_ptrace;
62249+extern int grsec_enable_link;
62250+extern int grsec_enable_fifo;
62251+extern int grsec_enable_execve;
62252+extern int grsec_enable_shm;
62253+extern int grsec_enable_execlog;
62254+extern int grsec_enable_signal;
62255+extern int grsec_enable_audit_ptrace;
62256+extern int grsec_enable_forkfail;
62257+extern int grsec_enable_time;
62258+extern int grsec_enable_rofs;
62259+extern int grsec_enable_chroot_shmat;
62260+extern int grsec_enable_chroot_mount;
62261+extern int grsec_enable_chroot_double;
62262+extern int grsec_enable_chroot_pivot;
62263+extern int grsec_enable_chroot_chdir;
62264+extern int grsec_enable_chroot_chmod;
62265+extern int grsec_enable_chroot_mknod;
62266+extern int grsec_enable_chroot_fchdir;
62267+extern int grsec_enable_chroot_nice;
62268+extern int grsec_enable_chroot_execlog;
62269+extern int grsec_enable_chroot_caps;
62270+extern int grsec_enable_chroot_sysctl;
62271+extern int grsec_enable_chroot_unix;
62272+extern int grsec_enable_symlinkown;
62273+extern int grsec_symlinkown_gid;
62274+extern int grsec_enable_tpe;
62275+extern int grsec_tpe_gid;
62276+extern int grsec_enable_tpe_all;
62277+extern int grsec_enable_tpe_invert;
62278+extern int grsec_enable_socket_all;
62279+extern int grsec_socket_all_gid;
62280+extern int grsec_enable_socket_client;
62281+extern int grsec_socket_client_gid;
62282+extern int grsec_enable_socket_server;
62283+extern int grsec_socket_server_gid;
62284+extern int grsec_audit_gid;
62285+extern int grsec_enable_group;
62286+extern int grsec_enable_audit_textrel;
62287+extern int grsec_enable_log_rwxmaps;
62288+extern int grsec_enable_mount;
62289+extern int grsec_enable_chdir;
62290+extern int grsec_resource_logging;
62291+extern int grsec_enable_blackhole;
62292+extern int grsec_lastack_retries;
62293+extern int grsec_enable_brute;
62294+extern int grsec_lock;
62295+
62296+extern spinlock_t grsec_alert_lock;
62297+extern unsigned long grsec_alert_wtime;
62298+extern unsigned long grsec_alert_fyet;
62299+
62300+extern spinlock_t grsec_audit_lock;
62301+
62302+extern rwlock_t grsec_exec_file_lock;
62303+
62304+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62305+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62306+ (tsk)->exec_file->f_vfsmnt) : "/")
62307+
62308+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62309+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62310+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62311+
62312+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62313+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
62314+ (tsk)->exec_file->f_vfsmnt) : "/")
62315+
62316+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62317+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62318+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62319+
62320+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62321+
62322+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62323+
62324+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62325+ (task)->pid, (cred)->uid, \
62326+ (cred)->euid, (cred)->gid, (cred)->egid, \
62327+ gr_parent_task_fullpath(task), \
62328+ (task)->real_parent->comm, (task)->real_parent->pid, \
62329+ (pcred)->uid, (pcred)->euid, \
62330+ (pcred)->gid, (pcred)->egid
62331+
62332+#define GR_CHROOT_CAPS {{ \
62333+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62334+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62335+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62336+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62337+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62338+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62339+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62340+
62341+#define security_learn(normal_msg,args...) \
62342+({ \
62343+ read_lock(&grsec_exec_file_lock); \
62344+ gr_add_learn_entry(normal_msg "\n", ## args); \
62345+ read_unlock(&grsec_exec_file_lock); \
62346+})
62347+
62348+enum {
62349+ GR_DO_AUDIT,
62350+ GR_DONT_AUDIT,
62351+ /* used for non-audit messages that we shouldn't kill the task on */
62352+ GR_DONT_AUDIT_GOOD
62353+};
62354+
62355+enum {
62356+ GR_TTYSNIFF,
62357+ GR_RBAC,
62358+ GR_RBAC_STR,
62359+ GR_STR_RBAC,
62360+ GR_RBAC_MODE2,
62361+ GR_RBAC_MODE3,
62362+ GR_FILENAME,
62363+ GR_SYSCTL_HIDDEN,
62364+ GR_NOARGS,
62365+ GR_ONE_INT,
62366+ GR_ONE_INT_TWO_STR,
62367+ GR_ONE_STR,
62368+ GR_STR_INT,
62369+ GR_TWO_STR_INT,
62370+ GR_TWO_INT,
62371+ GR_TWO_U64,
62372+ GR_THREE_INT,
62373+ GR_FIVE_INT_TWO_STR,
62374+ GR_TWO_STR,
62375+ GR_THREE_STR,
62376+ GR_FOUR_STR,
62377+ GR_STR_FILENAME,
62378+ GR_FILENAME_STR,
62379+ GR_FILENAME_TWO_INT,
62380+ GR_FILENAME_TWO_INT_STR,
62381+ GR_TEXTREL,
62382+ GR_PTRACE,
62383+ GR_RESOURCE,
62384+ GR_CAP,
62385+ GR_SIG,
62386+ GR_SIG2,
62387+ GR_CRASH1,
62388+ GR_CRASH2,
62389+ GR_PSACCT,
62390+ GR_RWXMAP
62391+};
62392+
62393+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62394+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62395+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62396+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62397+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62398+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62399+#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)
62400+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62401+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62402+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62403+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62404+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62405+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62406+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62407+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62408+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62409+#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)
62410+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62411+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62412+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62413+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62414+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62415+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62416+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62417+#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)
62418+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62419+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62420+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62421+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62422+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62423+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62424+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62425+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62426+#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)
62427+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62428+
62429+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62430+
62431+#endif
62432+
62433+#endif
62434diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62435new file mode 100644
62436index 0000000..54f4e85
62437--- /dev/null
62438+++ b/include/linux/grmsg.h
62439@@ -0,0 +1,110 @@
62440+#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"
62441+#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"
62442+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62443+#define GR_STOPMOD_MSG "denied modification of module state by "
62444+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62445+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62446+#define GR_IOPERM_MSG "denied use of ioperm() by "
62447+#define GR_IOPL_MSG "denied use of iopl() by "
62448+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62449+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62450+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62451+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62452+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62453+#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"
62454+#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"
62455+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62456+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62457+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62458+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62459+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62460+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62461+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62462+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62463+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62464+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62465+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62466+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62467+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62468+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62469+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62470+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62471+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62472+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62473+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62474+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62475+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62476+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62477+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62478+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62479+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62480+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62481+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62482+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62483+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62484+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62485+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62486+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62487+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62488+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62489+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62490+#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"
62491+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62492+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62493+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62494+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62495+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62496+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62497+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62498+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62499+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62500+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62501+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62502+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62503+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62504+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62505+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62506+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62507+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62508+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62509+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62510+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62511+#define GR_FAILFORK_MSG "failed fork with errno %s by "
62512+#define GR_NICE_CHROOT_MSG "denied priority change by "
62513+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62514+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62515+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62516+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62517+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62518+#define GR_TIME_MSG "time set by "
62519+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62520+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62521+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62522+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62523+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62524+#define GR_BIND_MSG "denied bind() by "
62525+#define GR_CONNECT_MSG "denied connect() by "
62526+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62527+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62528+#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"
62529+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62530+#define GR_CAP_ACL_MSG "use of %s denied for "
62531+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62532+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62533+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62534+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62535+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62536+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62537+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62538+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62539+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62540+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62541+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62542+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62543+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62544+#define GR_VM86_MSG "denied use of vm86 by "
62545+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62546+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62547+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62548+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62549+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62550diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62551new file mode 100644
62552index 0000000..f9b9a21
62553--- /dev/null
62554+++ b/include/linux/grsecurity.h
62555@@ -0,0 +1,238 @@
62556+#ifndef GR_SECURITY_H
62557+#define GR_SECURITY_H
62558+#include <linux/fs.h>
62559+#include <linux/fs_struct.h>
62560+#include <linux/binfmts.h>
62561+#include <linux/gracl.h>
62562+
62563+/* notify of brain-dead configs */
62564+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62565+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62566+#endif
62567+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62568+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62569+#endif
62570+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62571+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62572+#endif
62573+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62574+#error "CONFIG_PAX enabled, but no PaX options are enabled."
62575+#endif
62576+
62577+#include <linux/compat.h>
62578+
62579+struct user_arg_ptr {
62580+#ifdef CONFIG_COMPAT
62581+ bool is_compat;
62582+#endif
62583+ union {
62584+ const char __user *const __user *native;
62585+#ifdef CONFIG_COMPAT
62586+ compat_uptr_t __user *compat;
62587+#endif
62588+ } ptr;
62589+};
62590+
62591+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62592+void gr_handle_brute_check(void);
62593+void gr_handle_kernel_exploit(void);
62594+int gr_process_user_ban(void);
62595+
62596+char gr_roletype_to_char(void);
62597+
62598+int gr_acl_enable_at_secure(void);
62599+
62600+int gr_check_user_change(int real, int effective, int fs);
62601+int gr_check_group_change(int real, int effective, int fs);
62602+
62603+void gr_del_task_from_ip_table(struct task_struct *p);
62604+
62605+int gr_pid_is_chrooted(struct task_struct *p);
62606+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62607+int gr_handle_chroot_nice(void);
62608+int gr_handle_chroot_sysctl(const int op);
62609+int gr_handle_chroot_setpriority(struct task_struct *p,
62610+ const int niceval);
62611+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62612+int gr_handle_chroot_chroot(const struct dentry *dentry,
62613+ const struct vfsmount *mnt);
62614+void gr_handle_chroot_chdir(struct path *path);
62615+int gr_handle_chroot_chmod(const struct dentry *dentry,
62616+ const struct vfsmount *mnt, const int mode);
62617+int gr_handle_chroot_mknod(const struct dentry *dentry,
62618+ const struct vfsmount *mnt, const int mode);
62619+int gr_handle_chroot_mount(const struct dentry *dentry,
62620+ const struct vfsmount *mnt,
62621+ const char *dev_name);
62622+int gr_handle_chroot_pivot(void);
62623+int gr_handle_chroot_unix(const pid_t pid);
62624+
62625+int gr_handle_rawio(const struct inode *inode);
62626+
62627+void gr_handle_ioperm(void);
62628+void gr_handle_iopl(void);
62629+
62630+umode_t gr_acl_umask(void);
62631+
62632+int gr_tpe_allow(const struct file *file);
62633+
62634+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62635+void gr_clear_chroot_entries(struct task_struct *task);
62636+
62637+void gr_log_forkfail(const int retval);
62638+void gr_log_timechange(void);
62639+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62640+void gr_log_chdir(const struct dentry *dentry,
62641+ const struct vfsmount *mnt);
62642+void gr_log_chroot_exec(const struct dentry *dentry,
62643+ const struct vfsmount *mnt);
62644+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62645+void gr_log_remount(const char *devname, const int retval);
62646+void gr_log_unmount(const char *devname, const int retval);
62647+void gr_log_mount(const char *from, const char *to, const int retval);
62648+void gr_log_textrel(struct vm_area_struct *vma);
62649+void gr_log_rwxmmap(struct file *file);
62650+void gr_log_rwxmprotect(struct file *file);
62651+
62652+int gr_handle_follow_link(const struct inode *parent,
62653+ const struct inode *inode,
62654+ const struct dentry *dentry,
62655+ const struct vfsmount *mnt);
62656+int gr_handle_fifo(const struct dentry *dentry,
62657+ const struct vfsmount *mnt,
62658+ const struct dentry *dir, const int flag,
62659+ const int acc_mode);
62660+int gr_handle_hardlink(const struct dentry *dentry,
62661+ const struct vfsmount *mnt,
62662+ struct inode *inode,
62663+ const int mode, const char *to);
62664+
62665+int gr_is_capable(const int cap);
62666+int gr_is_capable_nolog(const int cap);
62667+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62668+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62669+
62670+void gr_learn_resource(const struct task_struct *task, const int limit,
62671+ const unsigned long wanted, const int gt);
62672+void gr_copy_label(struct task_struct *tsk);
62673+void gr_handle_crash(struct task_struct *task, const int sig);
62674+int gr_handle_signal(const struct task_struct *p, const int sig);
62675+int gr_check_crash_uid(const uid_t uid);
62676+int gr_check_protected_task(const struct task_struct *task);
62677+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62678+int gr_acl_handle_mmap(const struct file *file,
62679+ const unsigned long prot);
62680+int gr_acl_handle_mprotect(const struct file *file,
62681+ const unsigned long prot);
62682+int gr_check_hidden_task(const struct task_struct *tsk);
62683+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62684+ const struct vfsmount *mnt);
62685+__u32 gr_acl_handle_utime(const struct dentry *dentry,
62686+ const struct vfsmount *mnt);
62687+__u32 gr_acl_handle_access(const struct dentry *dentry,
62688+ const struct vfsmount *mnt, const int fmode);
62689+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62690+ const struct vfsmount *mnt, umode_t *mode);
62691+__u32 gr_acl_handle_chown(const struct dentry *dentry,
62692+ const struct vfsmount *mnt);
62693+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62694+ const struct vfsmount *mnt);
62695+int gr_handle_ptrace(struct task_struct *task, const long request);
62696+int gr_handle_proc_ptrace(struct task_struct *task);
62697+__u32 gr_acl_handle_execve(const struct dentry *dentry,
62698+ const struct vfsmount *mnt);
62699+int gr_check_crash_exec(const struct file *filp);
62700+int gr_acl_is_enabled(void);
62701+void gr_set_kernel_label(struct task_struct *task);
62702+void gr_set_role_label(struct task_struct *task, const uid_t uid,
62703+ const gid_t gid);
62704+int gr_set_proc_label(const struct dentry *dentry,
62705+ const struct vfsmount *mnt,
62706+ const int unsafe_flags);
62707+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62708+ const struct vfsmount *mnt);
62709+__u32 gr_acl_handle_open(const struct dentry *dentry,
62710+ const struct vfsmount *mnt, int acc_mode);
62711+__u32 gr_acl_handle_creat(const struct dentry *dentry,
62712+ const struct dentry *p_dentry,
62713+ const struct vfsmount *p_mnt,
62714+ int open_flags, int acc_mode, const int imode);
62715+void gr_handle_create(const struct dentry *dentry,
62716+ const struct vfsmount *mnt);
62717+void gr_handle_proc_create(const struct dentry *dentry,
62718+ const struct inode *inode);
62719+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62720+ const struct dentry *parent_dentry,
62721+ const struct vfsmount *parent_mnt,
62722+ const int mode);
62723+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62724+ const struct dentry *parent_dentry,
62725+ const struct vfsmount *parent_mnt);
62726+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62727+ const struct vfsmount *mnt);
62728+void gr_handle_delete(const ino_t ino, const dev_t dev);
62729+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62730+ const struct vfsmount *mnt);
62731+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62732+ const struct dentry *parent_dentry,
62733+ const struct vfsmount *parent_mnt,
62734+ const char *from);
62735+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62736+ const struct dentry *parent_dentry,
62737+ const struct vfsmount *parent_mnt,
62738+ const struct dentry *old_dentry,
62739+ const struct vfsmount *old_mnt, const char *to);
62740+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62741+int gr_acl_handle_rename(struct dentry *new_dentry,
62742+ struct dentry *parent_dentry,
62743+ const struct vfsmount *parent_mnt,
62744+ struct dentry *old_dentry,
62745+ struct inode *old_parent_inode,
62746+ struct vfsmount *old_mnt, const char *newname);
62747+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62748+ struct dentry *old_dentry,
62749+ struct dentry *new_dentry,
62750+ struct vfsmount *mnt, const __u8 replace);
62751+__u32 gr_check_link(const struct dentry *new_dentry,
62752+ const struct dentry *parent_dentry,
62753+ const struct vfsmount *parent_mnt,
62754+ const struct dentry *old_dentry,
62755+ const struct vfsmount *old_mnt);
62756+int gr_acl_handle_filldir(const struct file *file, const char *name,
62757+ const unsigned int namelen, const ino_t ino);
62758+
62759+__u32 gr_acl_handle_unix(const struct dentry *dentry,
62760+ const struct vfsmount *mnt);
62761+void gr_acl_handle_exit(void);
62762+void gr_acl_handle_psacct(struct task_struct *task, const long code);
62763+int gr_acl_handle_procpidmem(const struct task_struct *task);
62764+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62765+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62766+void gr_audit_ptrace(struct task_struct *task);
62767+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62768+
62769+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62770+
62771+#ifdef CONFIG_GRKERNSEC
62772+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62773+void gr_handle_vm86(void);
62774+void gr_handle_mem_readwrite(u64 from, u64 to);
62775+
62776+void gr_log_badprocpid(const char *entry);
62777+
62778+extern int grsec_enable_dmesg;
62779+extern int grsec_disable_privio;
62780+
62781+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62782+extern int grsec_proc_gid;
62783+#endif
62784+
62785+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62786+extern int grsec_enable_chroot_findtask;
62787+#endif
62788+#ifdef CONFIG_GRKERNSEC_SETXID
62789+extern int grsec_enable_setxid;
62790+#endif
62791+#endif
62792+
62793+#endif
62794diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62795new file mode 100644
62796index 0000000..e7ffaaf
62797--- /dev/null
62798+++ b/include/linux/grsock.h
62799@@ -0,0 +1,19 @@
62800+#ifndef __GRSOCK_H
62801+#define __GRSOCK_H
62802+
62803+extern void gr_attach_curr_ip(const struct sock *sk);
62804+extern int gr_handle_sock_all(const int family, const int type,
62805+ const int protocol);
62806+extern int gr_handle_sock_server(const struct sockaddr *sck);
62807+extern int gr_handle_sock_server_other(const struct sock *sck);
62808+extern int gr_handle_sock_client(const struct sockaddr *sck);
62809+extern int gr_search_connect(struct socket * sock,
62810+ struct sockaddr_in * addr);
62811+extern int gr_search_bind(struct socket * sock,
62812+ struct sockaddr_in * addr);
62813+extern int gr_search_listen(struct socket * sock);
62814+extern int gr_search_accept(struct socket * sock);
62815+extern int gr_search_socket(const int domain, const int type,
62816+ const int protocol);
62817+
62818+#endif
62819diff --git a/include/linux/hid.h b/include/linux/hid.h
62820index 42970de..5db3c92 100644
62821--- a/include/linux/hid.h
62822+++ b/include/linux/hid.h
62823@@ -705,7 +705,7 @@ struct hid_ll_driver {
62824 unsigned int code, int value);
62825
62826 int (*parse)(struct hid_device *hdev);
62827-};
62828+} __no_const;
62829
62830 #define PM_HINT_FULLON 1<<5
62831 #define PM_HINT_NORMAL 1<<1
62832diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62833index ef788b5..ac41b7b 100644
62834--- a/include/linux/highmem.h
62835+++ b/include/linux/highmem.h
62836@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
62837 kunmap_atomic(kaddr);
62838 }
62839
62840+static inline void sanitize_highpage(struct page *page)
62841+{
62842+ void *kaddr;
62843+ unsigned long flags;
62844+
62845+ local_irq_save(flags);
62846+ kaddr = kmap_atomic(page);
62847+ clear_page(kaddr);
62848+ kunmap_atomic(kaddr);
62849+ local_irq_restore(flags);
62850+}
62851+
62852 static inline void zero_user_segments(struct page *page,
62853 unsigned start1, unsigned end1,
62854 unsigned start2, unsigned end2)
62855diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62856index 5970266..1c48c3b 100644
62857--- a/include/linux/i2c.h
62858+++ b/include/linux/i2c.h
62859@@ -369,6 +369,7 @@ struct i2c_algorithm {
62860 /* To determine what the adapter supports */
62861 u32 (*functionality) (struct i2c_adapter *);
62862 };
62863+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62864
62865 /*
62866 * i2c_adapter is the structure used to identify a physical i2c bus along
62867diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62868index d23c3c2..eb63c81 100644
62869--- a/include/linux/i2o.h
62870+++ b/include/linux/i2o.h
62871@@ -565,7 +565,7 @@ struct i2o_controller {
62872 struct i2o_device *exec; /* Executive */
62873 #if BITS_PER_LONG == 64
62874 spinlock_t context_list_lock; /* lock for context_list */
62875- atomic_t context_list_counter; /* needed for unique contexts */
62876+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62877 struct list_head context_list; /* list of context id's
62878 and pointers */
62879 #endif
62880diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62881index aa2e167..84024ce 100644
62882--- a/include/linux/if_team.h
62883+++ b/include/linux/if_team.h
62884@@ -109,6 +109,7 @@ struct team_mode_ops {
62885 void (*port_enabled)(struct team *team, struct team_port *port);
62886 void (*port_disabled)(struct team *team, struct team_port *port);
62887 };
62888+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62889
62890 enum team_option_type {
62891 TEAM_OPTION_TYPE_U32,
62892@@ -181,7 +182,7 @@ struct team {
62893 struct list_head option_inst_list; /* list of option instances */
62894
62895 const struct team_mode *mode;
62896- struct team_mode_ops ops;
62897+ team_mode_ops_no_const ops;
62898 long mode_priv[TEAM_MODE_PRIV_LONGS];
62899 };
62900
62901diff --git a/include/linux/init.h b/include/linux/init.h
62902index 5e664f6..0a1225c 100644
62903--- a/include/linux/init.h
62904+++ b/include/linux/init.h
62905@@ -39,9 +39,15 @@
62906 * Also note, that this data cannot be "const".
62907 */
62908
62909+#ifdef MODULE
62910+#define add_latent_entropy
62911+#else
62912+#define add_latent_entropy __latent_entropy
62913+#endif
62914+
62915 /* These are for everybody (although not all archs will actually
62916 discard it in modules) */
62917-#define __init __section(.init.text) __cold notrace
62918+#define __init __section(.init.text) __cold notrace add_latent_entropy
62919 #define __initdata __section(.init.data)
62920 #define __initconst __section(.init.rodata)
62921 #define __exitdata __section(.exit.data)
62922@@ -83,7 +89,7 @@
62923 #define __exit __section(.exit.text) __exitused __cold notrace
62924
62925 /* Used for HOTPLUG */
62926-#define __devinit __section(.devinit.text) __cold notrace
62927+#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62928 #define __devinitdata __section(.devinit.data)
62929 #define __devinitconst __section(.devinit.rodata)
62930 #define __devexit __section(.devexit.text) __exitused __cold notrace
62931@@ -91,7 +97,7 @@
62932 #define __devexitconst __section(.devexit.rodata)
62933
62934 /* Used for HOTPLUG_CPU */
62935-#define __cpuinit __section(.cpuinit.text) __cold notrace
62936+#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62937 #define __cpuinitdata __section(.cpuinit.data)
62938 #define __cpuinitconst __section(.cpuinit.rodata)
62939 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62940@@ -99,7 +105,7 @@
62941 #define __cpuexitconst __section(.cpuexit.rodata)
62942
62943 /* Used for MEMORY_HOTPLUG */
62944-#define __meminit __section(.meminit.text) __cold notrace
62945+#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62946 #define __meminitdata __section(.meminit.data)
62947 #define __meminitconst __section(.meminit.rodata)
62948 #define __memexit __section(.memexit.text) __exitused __cold notrace
62949diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62950index 89f1cb1..7986c0f 100644
62951--- a/include/linux/init_task.h
62952+++ b/include/linux/init_task.h
62953@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
62954
62955 #define INIT_TASK_COMM "swapper"
62956
62957+#ifdef CONFIG_X86
62958+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62959+#else
62960+#define INIT_TASK_THREAD_INFO
62961+#endif
62962+
62963 /*
62964 * INIT_TASK is used to set up the first task table, touch at
62965 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62966@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
62967 RCU_POINTER_INITIALIZER(cred, &init_cred), \
62968 .comm = INIT_TASK_COMM, \
62969 .thread = INIT_THREAD, \
62970+ INIT_TASK_THREAD_INFO \
62971 .fs = &init_fs, \
62972 .files = &init_files, \
62973 .signal = &init_signals, \
62974diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62975index 78e2ada..745564d 100644
62976--- a/include/linux/intel-iommu.h
62977+++ b/include/linux/intel-iommu.h
62978@@ -296,7 +296,7 @@ struct iommu_flush {
62979 u8 fm, u64 type);
62980 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62981 unsigned int size_order, u64 type);
62982-};
62983+} __no_const;
62984
62985 enum {
62986 SR_DMAR_FECTL_REG,
62987diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62988index c5f856a..d29c117 100644
62989--- a/include/linux/interrupt.h
62990+++ b/include/linux/interrupt.h
62991@@ -433,7 +433,7 @@ enum
62992 /* map softirq index to softirq name. update 'softirq_to_name' in
62993 * kernel/softirq.c when adding a new softirq.
62994 */
62995-extern char *softirq_to_name[NR_SOFTIRQS];
62996+extern const char * const softirq_to_name[NR_SOFTIRQS];
62997
62998 /* softirq mask and active fields moved to irq_cpustat_t in
62999 * asm/hardirq.h to get better cache usage. KAO
63000@@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63001
63002 struct softirq_action
63003 {
63004- void (*action)(struct softirq_action *);
63005+ void (*action)(void);
63006 };
63007
63008 asmlinkage void do_softirq(void);
63009 asmlinkage void __do_softirq(void);
63010-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63011+extern void open_softirq(int nr, void (*action)(void));
63012 extern void softirq_init(void);
63013 extern void __raise_softirq_irqoff(unsigned int nr);
63014
63015diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63016index 6883e19..06992b1 100644
63017--- a/include/linux/kallsyms.h
63018+++ b/include/linux/kallsyms.h
63019@@ -15,7 +15,8 @@
63020
63021 struct module;
63022
63023-#ifdef CONFIG_KALLSYMS
63024+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63025+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63026 /* Lookup the address for a symbol. Returns 0 if not found. */
63027 unsigned long kallsyms_lookup_name(const char *name);
63028
63029@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63030 /* Stupid that this does nothing, but I didn't create this mess. */
63031 #define __print_symbol(fmt, addr)
63032 #endif /*CONFIG_KALLSYMS*/
63033+#else /* when included by kallsyms.c, vsnprintf.c, or
63034+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63035+extern void __print_symbol(const char *fmt, unsigned long address);
63036+extern int sprint_backtrace(char *buffer, unsigned long address);
63037+extern int sprint_symbol(char *buffer, unsigned long address);
63038+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63039+const char *kallsyms_lookup(unsigned long addr,
63040+ unsigned long *symbolsize,
63041+ unsigned long *offset,
63042+ char **modname, char *namebuf);
63043+#endif
63044
63045 /* This macro allows us to keep printk typechecking */
63046 static __printf(1, 2)
63047diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63048index c4d2fc1..5df9c19 100644
63049--- a/include/linux/kgdb.h
63050+++ b/include/linux/kgdb.h
63051@@ -53,7 +53,7 @@ extern int kgdb_connected;
63052 extern int kgdb_io_module_registered;
63053
63054 extern atomic_t kgdb_setting_breakpoint;
63055-extern atomic_t kgdb_cpu_doing_single_step;
63056+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63057
63058 extern struct task_struct *kgdb_usethread;
63059 extern struct task_struct *kgdb_contthread;
63060@@ -252,7 +252,7 @@ struct kgdb_arch {
63061 void (*disable_hw_break)(struct pt_regs *regs);
63062 void (*remove_all_hw_break)(void);
63063 void (*correct_hw_break)(void);
63064-};
63065+} __do_const;
63066
63067 /**
63068 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63069@@ -277,7 +277,7 @@ struct kgdb_io {
63070 void (*pre_exception) (void);
63071 void (*post_exception) (void);
63072 int is_console;
63073-};
63074+} __do_const;
63075
63076 extern struct kgdb_arch arch_kgdb_ops;
63077
63078diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63079index 5398d58..5883a34 100644
63080--- a/include/linux/kmod.h
63081+++ b/include/linux/kmod.h
63082@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63083 * usually useless though. */
63084 extern __printf(2, 3)
63085 int __request_module(bool wait, const char *name, ...);
63086+extern __printf(3, 4)
63087+int ___request_module(bool wait, char *param_name, const char *name, ...);
63088 #define request_module(mod...) __request_module(true, mod)
63089 #define request_module_nowait(mod...) __request_module(false, mod)
63090 #define try_then_request_module(x, mod...) \
63091diff --git a/include/linux/kref.h b/include/linux/kref.h
63092index 65af688..0592677 100644
63093--- a/include/linux/kref.h
63094+++ b/include/linux/kref.h
63095@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63096 static inline int kref_sub(struct kref *kref, unsigned int count,
63097 void (*release)(struct kref *kref))
63098 {
63099- WARN_ON(release == NULL);
63100+ BUG_ON(release == NULL);
63101
63102 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63103 release(kref);
63104diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63105index b70b48b..0d7153b 100644
63106--- a/include/linux/kvm_host.h
63107+++ b/include/linux/kvm_host.h
63108@@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63109 void vcpu_load(struct kvm_vcpu *vcpu);
63110 void vcpu_put(struct kvm_vcpu *vcpu);
63111
63112-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63113+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63114 struct module *module);
63115 void kvm_exit(void);
63116
63117@@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63118 struct kvm_guest_debug *dbg);
63119 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63120
63121-int kvm_arch_init(void *opaque);
63122+int kvm_arch_init(const void *opaque);
63123 void kvm_arch_exit(void);
63124
63125 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63126diff --git a/include/linux/libata.h b/include/linux/libata.h
63127index 64f90e1..32b945b 100644
63128--- a/include/linux/libata.h
63129+++ b/include/linux/libata.h
63130@@ -909,7 +909,7 @@ struct ata_port_operations {
63131 * fields must be pointers.
63132 */
63133 const struct ata_port_operations *inherits;
63134-};
63135+} __do_const;
63136
63137 struct ata_port_info {
63138 unsigned long flags;
63139diff --git a/include/linux/memory.h b/include/linux/memory.h
63140index ff9a9f8..c715deb 100644
63141--- a/include/linux/memory.h
63142+++ b/include/linux/memory.h
63143@@ -143,7 +143,7 @@ struct memory_accessor {
63144 size_t count);
63145 ssize_t (*write)(struct memory_accessor *, const char *buf,
63146 off_t offset, size_t count);
63147-};
63148+} __no_const;
63149
63150 /*
63151 * Kernel text modification mutex, used for code patching. Users of this lock
63152diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63153index 1318ca6..7521340 100644
63154--- a/include/linux/mfd/abx500.h
63155+++ b/include/linux/mfd/abx500.h
63156@@ -452,6 +452,7 @@ struct abx500_ops {
63157 int (*event_registers_startup_state_get) (struct device *, u8 *);
63158 int (*startup_irq_enabled) (struct device *, unsigned int);
63159 };
63160+typedef struct abx500_ops __no_const abx500_ops_no_const;
63161
63162 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63163 void abx500_remove_ops(struct device *dev);
63164diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63165index 9b07725..3d55001 100644
63166--- a/include/linux/mfd/abx500/ux500_chargalg.h
63167+++ b/include/linux/mfd/abx500/ux500_chargalg.h
63168@@ -19,7 +19,7 @@ struct ux500_charger_ops {
63169 int (*enable) (struct ux500_charger *, int, int, int);
63170 int (*kick_wd) (struct ux500_charger *);
63171 int (*update_curr) (struct ux500_charger *, int);
63172-};
63173+} __no_const;
63174
63175 /**
63176 * struct ux500_charger - power supply ux500 charger sub class
63177diff --git a/include/linux/mm.h b/include/linux/mm.h
63178index 311be90..5f1638c 100644
63179--- a/include/linux/mm.h
63180+++ b/include/linux/mm.h
63181@@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63182
63183 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63184 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63185+
63186+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63187+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63188+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63189+#else
63190 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63191+#endif
63192+
63193 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63194 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63195
63196@@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63197 int set_page_dirty_lock(struct page *page);
63198 int clear_page_dirty_for_io(struct page *page);
63199
63200-/* Is the vma a continuation of the stack vma above it? */
63201-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63202-{
63203- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63204-}
63205-
63206-static inline int stack_guard_page_start(struct vm_area_struct *vma,
63207- unsigned long addr)
63208-{
63209- return (vma->vm_flags & VM_GROWSDOWN) &&
63210- (vma->vm_start == addr) &&
63211- !vma_growsdown(vma->vm_prev, addr);
63212-}
63213-
63214-/* Is the vma a continuation of the stack vma below it? */
63215-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63216-{
63217- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63218-}
63219-
63220-static inline int stack_guard_page_end(struct vm_area_struct *vma,
63221- unsigned long addr)
63222-{
63223- return (vma->vm_flags & VM_GROWSUP) &&
63224- (vma->vm_end == addr) &&
63225- !vma_growsup(vma->vm_next, addr);
63226-}
63227-
63228 extern pid_t
63229 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63230
63231@@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63232 }
63233 #endif
63234
63235+#ifdef CONFIG_MMU
63236+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63237+#else
63238+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63239+{
63240+ return __pgprot(0);
63241+}
63242+#endif
63243+
63244 int vma_wants_writenotify(struct vm_area_struct *vma);
63245
63246 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63247@@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63248 {
63249 return 0;
63250 }
63251+
63252+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63253+ unsigned long address)
63254+{
63255+ return 0;
63256+}
63257 #else
63258 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63259+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63260 #endif
63261
63262 #ifdef __PAGETABLE_PMD_FOLDED
63263@@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63264 {
63265 return 0;
63266 }
63267+
63268+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63269+ unsigned long address)
63270+{
63271+ return 0;
63272+}
63273 #else
63274 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63275+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63276 #endif
63277
63278 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63279@@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63280 NULL: pud_offset(pgd, address);
63281 }
63282
63283+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63284+{
63285+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63286+ NULL: pud_offset(pgd, address);
63287+}
63288+
63289 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63290 {
63291 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63292 NULL: pmd_offset(pud, address);
63293 }
63294+
63295+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63296+{
63297+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63298+ NULL: pmd_offset(pud, address);
63299+}
63300 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63301
63302 #if USE_SPLIT_PTLOCKS
63303@@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63304 unsigned long, unsigned long,
63305 unsigned long, unsigned long);
63306 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63307+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63308
63309 /* These take the mm semaphore themselves */
63310 extern unsigned long vm_brk(unsigned long, unsigned long);
63311@@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63312 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63313 struct vm_area_struct **pprev);
63314
63315+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63316+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63317+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63318+
63319 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63320 NULL if none. Assume start_addr < end_addr. */
63321 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63322@@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63323 return vma;
63324 }
63325
63326-#ifdef CONFIG_MMU
63327-pgprot_t vm_get_page_prot(unsigned long vm_flags);
63328-#else
63329-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63330-{
63331- return __pgprot(0);
63332-}
63333-#endif
63334-
63335 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63336 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63337 unsigned long pfn, unsigned long size, pgprot_t);
63338@@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63339 extern int sysctl_memory_failure_early_kill;
63340 extern int sysctl_memory_failure_recovery;
63341 extern void shake_page(struct page *p, int access);
63342-extern atomic_long_t mce_bad_pages;
63343+extern atomic_long_unchecked_t mce_bad_pages;
63344 extern int soft_offline_page(struct page *page, int flags);
63345
63346 extern void dump_page(struct page *page);
63347@@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63348 static inline bool page_is_guard(struct page *page) { return false; }
63349 #endif /* CONFIG_DEBUG_PAGEALLOC */
63350
63351+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63352+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63353+#else
63354+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63355+#endif
63356+
63357 #endif /* __KERNEL__ */
63358 #endif /* _LINUX_MM_H */
63359diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63360index bf78672..debc693 100644
63361--- a/include/linux/mm_types.h
63362+++ b/include/linux/mm_types.h
63363@@ -279,6 +279,8 @@ struct vm_area_struct {
63364 #ifdef CONFIG_NUMA
63365 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63366 #endif
63367+
63368+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63369 };
63370
63371 struct core_thread {
63372@@ -353,7 +355,7 @@ struct mm_struct {
63373 unsigned long def_flags;
63374 unsigned long nr_ptes; /* Page table pages */
63375 unsigned long start_code, end_code, start_data, end_data;
63376- unsigned long start_brk, brk, start_stack;
63377+ unsigned long brk_gap, start_brk, brk, start_stack;
63378 unsigned long arg_start, arg_end, env_start, env_end;
63379
63380 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63381@@ -405,6 +407,24 @@ struct mm_struct {
63382 struct cpumask cpumask_allocation;
63383 #endif
63384 struct uprobes_state uprobes_state;
63385+
63386+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63387+ unsigned long pax_flags;
63388+#endif
63389+
63390+#ifdef CONFIG_PAX_DLRESOLVE
63391+ unsigned long call_dl_resolve;
63392+#endif
63393+
63394+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63395+ unsigned long call_syscall;
63396+#endif
63397+
63398+#ifdef CONFIG_PAX_ASLR
63399+ unsigned long delta_mmap; /* randomized offset */
63400+ unsigned long delta_stack; /* randomized offset */
63401+#endif
63402+
63403 };
63404
63405 static inline void mm_init_cpumask(struct mm_struct *mm)
63406diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63407index 1d1b1e1..2a13c78 100644
63408--- a/include/linux/mmu_notifier.h
63409+++ b/include/linux/mmu_notifier.h
63410@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63411 */
63412 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63413 ({ \
63414- pte_t __pte; \
63415+ pte_t ___pte; \
63416 struct vm_area_struct *___vma = __vma; \
63417 unsigned long ___address = __address; \
63418- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63419+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63420 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63421- __pte; \
63422+ ___pte; \
63423 })
63424
63425 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63426diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63427index 2daa54f..bfdf2f5 100644
63428--- a/include/linux/mmzone.h
63429+++ b/include/linux/mmzone.h
63430@@ -414,7 +414,7 @@ struct zone {
63431 unsigned long flags; /* zone flags, see below */
63432
63433 /* Zone statistics */
63434- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63435+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63436
63437 /*
63438 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63439diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63440index 6955045..ebdb7cd 100644
63441--- a/include/linux/mod_devicetable.h
63442+++ b/include/linux/mod_devicetable.h
63443@@ -12,7 +12,7 @@
63444 typedef unsigned long kernel_ulong_t;
63445 #endif
63446
63447-#define PCI_ANY_ID (~0)
63448+#define PCI_ANY_ID ((__u16)~0)
63449
63450 struct pci_device_id {
63451 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63452@@ -139,7 +139,7 @@ struct usb_device_id {
63453 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63454 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63455
63456-#define HID_ANY_ID (~0)
63457+#define HID_ANY_ID (~0U)
63458 #define HID_BUS_ANY 0xffff
63459 #define HID_GROUP_ANY 0x0000
63460
63461diff --git a/include/linux/module.h b/include/linux/module.h
63462index fbcafe2..e5d9587 100644
63463--- a/include/linux/module.h
63464+++ b/include/linux/module.h
63465@@ -17,6 +17,7 @@
63466 #include <linux/moduleparam.h>
63467 #include <linux/tracepoint.h>
63468 #include <linux/export.h>
63469+#include <linux/fs.h>
63470
63471 #include <linux/percpu.h>
63472 #include <asm/module.h>
63473@@ -273,19 +274,16 @@ struct module
63474 int (*init)(void);
63475
63476 /* If this is non-NULL, vfree after init() returns */
63477- void *module_init;
63478+ void *module_init_rx, *module_init_rw;
63479
63480 /* Here is the actual code + data, vfree'd on unload. */
63481- void *module_core;
63482+ void *module_core_rx, *module_core_rw;
63483
63484 /* Here are the sizes of the init and core sections */
63485- unsigned int init_size, core_size;
63486+ unsigned int init_size_rw, core_size_rw;
63487
63488 /* The size of the executable code in each section. */
63489- unsigned int init_text_size, core_text_size;
63490-
63491- /* Size of RO sections of the module (text+rodata) */
63492- unsigned int init_ro_size, core_ro_size;
63493+ unsigned int init_size_rx, core_size_rx;
63494
63495 /* Arch-specific module values */
63496 struct mod_arch_specific arch;
63497@@ -341,6 +339,10 @@ struct module
63498 #ifdef CONFIG_EVENT_TRACING
63499 struct ftrace_event_call **trace_events;
63500 unsigned int num_trace_events;
63501+ struct file_operations trace_id;
63502+ struct file_operations trace_enable;
63503+ struct file_operations trace_format;
63504+ struct file_operations trace_filter;
63505 #endif
63506 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63507 unsigned int num_ftrace_callsites;
63508@@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63509 bool is_module_percpu_address(unsigned long addr);
63510 bool is_module_text_address(unsigned long addr);
63511
63512+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63513+{
63514+
63515+#ifdef CONFIG_PAX_KERNEXEC
63516+ if (ktla_ktva(addr) >= (unsigned long)start &&
63517+ ktla_ktva(addr) < (unsigned long)start + size)
63518+ return 1;
63519+#endif
63520+
63521+ return ((void *)addr >= start && (void *)addr < start + size);
63522+}
63523+
63524+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63525+{
63526+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63527+}
63528+
63529+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63530+{
63531+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63532+}
63533+
63534+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63535+{
63536+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63537+}
63538+
63539+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63540+{
63541+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63542+}
63543+
63544 static inline int within_module_core(unsigned long addr, struct module *mod)
63545 {
63546- return (unsigned long)mod->module_core <= addr &&
63547- addr < (unsigned long)mod->module_core + mod->core_size;
63548+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63549 }
63550
63551 static inline int within_module_init(unsigned long addr, struct module *mod)
63552 {
63553- return (unsigned long)mod->module_init <= addr &&
63554- addr < (unsigned long)mod->module_init + mod->init_size;
63555+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63556 }
63557
63558 /* Search for module by name: must hold module_mutex. */
63559diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63560index b2be02e..72d2f78 100644
63561--- a/include/linux/moduleloader.h
63562+++ b/include/linux/moduleloader.h
63563@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63564
63565 /* Allocator used for allocating struct module, core sections and init
63566 sections. Returns NULL on failure. */
63567-void *module_alloc(unsigned long size);
63568+void *module_alloc(unsigned long size) __size_overflow(1);
63569+
63570+#ifdef CONFIG_PAX_KERNEXEC
63571+void *module_alloc_exec(unsigned long size) __size_overflow(1);
63572+#else
63573+#define module_alloc_exec(x) module_alloc(x)
63574+#endif
63575
63576 /* Free memory returned from module_alloc. */
63577 void module_free(struct module *mod, void *module_region);
63578
63579+#ifdef CONFIG_PAX_KERNEXEC
63580+void module_free_exec(struct module *mod, void *module_region);
63581+#else
63582+#define module_free_exec(x, y) module_free((x), (y))
63583+#endif
63584+
63585 /* Apply the given relocation to the (simplified) ELF. Return -error
63586 or 0. */
63587 int apply_relocate(Elf_Shdr *sechdrs,
63588diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63589index d6a5806..7c13347 100644
63590--- a/include/linux/moduleparam.h
63591+++ b/include/linux/moduleparam.h
63592@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63593 * @len is usually just sizeof(string).
63594 */
63595 #define module_param_string(name, string, len, perm) \
63596- static const struct kparam_string __param_string_##name \
63597+ static const struct kparam_string __param_string_##name __used \
63598 = { len, string }; \
63599 __module_param_call(MODULE_PARAM_PREFIX, name, \
63600 &param_ops_string, \
63601@@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63602 */
63603 #define module_param_array_named(name, array, type, nump, perm) \
63604 param_check_##type(name, &(array)[0]); \
63605- static const struct kparam_array __param_arr_##name \
63606+ static const struct kparam_array __param_arr_##name __used \
63607 = { .max = ARRAY_SIZE(array), .num = nump, \
63608 .ops = &param_ops_##type, \
63609 .elemsize = sizeof(array[0]), .elem = array }; \
63610diff --git a/include/linux/namei.h b/include/linux/namei.h
63611index 4bf19d8..5268cea 100644
63612--- a/include/linux/namei.h
63613+++ b/include/linux/namei.h
63614@@ -18,7 +18,7 @@ struct nameidata {
63615 unsigned seq;
63616 int last_type;
63617 unsigned depth;
63618- char *saved_names[MAX_NESTED_LINKS + 1];
63619+ const char *saved_names[MAX_NESTED_LINKS + 1];
63620 };
63621
63622 /*
63623@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63624
63625 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63626
63627-static inline void nd_set_link(struct nameidata *nd, char *path)
63628+static inline void nd_set_link(struct nameidata *nd, const char *path)
63629 {
63630 nd->saved_names[nd->depth] = path;
63631 }
63632
63633-static inline char *nd_get_link(struct nameidata *nd)
63634+static inline const char *nd_get_link(const struct nameidata *nd)
63635 {
63636 return nd->saved_names[nd->depth];
63637 }
63638diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63639index 59dc05f3..c905a34 100644
63640--- a/include/linux/netdevice.h
63641+++ b/include/linux/netdevice.h
63642@@ -1027,6 +1027,7 @@ struct net_device_ops {
63643 struct net_device *dev,
63644 int idx);
63645 };
63646+typedef struct net_device_ops __no_const net_device_ops_no_const;
63647
63648 /*
63649 * The DEVICE structure.
63650@@ -1087,7 +1088,7 @@ struct net_device {
63651 int iflink;
63652
63653 struct net_device_stats stats;
63654- atomic_long_t rx_dropped; /* dropped packets by core network
63655+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63656 * Do not use this in drivers.
63657 */
63658
63659diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63660new file mode 100644
63661index 0000000..33f4af8
63662--- /dev/null
63663+++ b/include/linux/netfilter/xt_gradm.h
63664@@ -0,0 +1,9 @@
63665+#ifndef _LINUX_NETFILTER_XT_GRADM_H
63666+#define _LINUX_NETFILTER_XT_GRADM_H 1
63667+
63668+struct xt_gradm_mtinfo {
63669+ __u16 flags;
63670+ __u16 invflags;
63671+};
63672+
63673+#endif
63674diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63675index c65a18a..0c05f3a 100644
63676--- a/include/linux/of_pdt.h
63677+++ b/include/linux/of_pdt.h
63678@@ -32,7 +32,7 @@ struct of_pdt_ops {
63679
63680 /* return 0 on success; fill in 'len' with number of bytes in path */
63681 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63682-};
63683+} __no_const;
63684
63685 extern void *prom_early_alloc(unsigned long size);
63686
63687diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63688index a4c5624..79d6d88 100644
63689--- a/include/linux/oprofile.h
63690+++ b/include/linux/oprofile.h
63691@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63692 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63693 char const * name, ulong * val);
63694
63695-/** Create a file for read-only access to an atomic_t. */
63696+/** Create a file for read-only access to an atomic_unchecked_t. */
63697 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63698- char const * name, atomic_t * val);
63699+ char const * name, atomic_unchecked_t * val);
63700
63701 /** create a directory */
63702 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63703diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63704index bdb4161..f373d41 100644
63705--- a/include/linux/perf_event.h
63706+++ b/include/linux/perf_event.h
63707@@ -882,8 +882,8 @@ struct perf_event {
63708
63709 enum perf_event_active_state state;
63710 unsigned int attach_state;
63711- local64_t count;
63712- atomic64_t child_count;
63713+ local64_t count; /* PaX: fix it one day */
63714+ atomic64_unchecked_t child_count;
63715
63716 /*
63717 * These are the total time in nanoseconds that the event
63718@@ -934,8 +934,8 @@ struct perf_event {
63719 * These accumulate total time (in nanoseconds) that children
63720 * events have been enabled and running, respectively.
63721 */
63722- atomic64_t child_total_time_enabled;
63723- atomic64_t child_total_time_running;
63724+ atomic64_unchecked_t child_total_time_enabled;
63725+ atomic64_unchecked_t child_total_time_running;
63726
63727 /*
63728 * Protect attach/detach and child_list:
63729diff --git a/include/linux/personality.h b/include/linux/personality.h
63730index 8fc7dd1a..c19d89e 100644
63731--- a/include/linux/personality.h
63732+++ b/include/linux/personality.h
63733@@ -44,6 +44,7 @@ enum {
63734 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63735 ADDR_NO_RANDOMIZE | \
63736 ADDR_COMPAT_LAYOUT | \
63737+ ADDR_LIMIT_3GB | \
63738 MMAP_PAGE_ZERO)
63739
63740 /*
63741diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63742index ad1a427..6419649 100644
63743--- a/include/linux/pipe_fs_i.h
63744+++ b/include/linux/pipe_fs_i.h
63745@@ -45,9 +45,9 @@ struct pipe_buffer {
63746 struct pipe_inode_info {
63747 wait_queue_head_t wait;
63748 unsigned int nrbufs, curbuf, buffers;
63749- unsigned int readers;
63750- unsigned int writers;
63751- unsigned int waiting_writers;
63752+ atomic_t readers;
63753+ atomic_t writers;
63754+ atomic_t waiting_writers;
63755 unsigned int r_counter;
63756 unsigned int w_counter;
63757 struct page *tmp_page;
63758diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63759index f271860..6b3bec5 100644
63760--- a/include/linux/pm_runtime.h
63761+++ b/include/linux/pm_runtime.h
63762@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63763
63764 static inline void pm_runtime_mark_last_busy(struct device *dev)
63765 {
63766- ACCESS_ONCE(dev->power.last_busy) = jiffies;
63767+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63768 }
63769
63770 #else /* !CONFIG_PM_RUNTIME */
63771diff --git a/include/linux/poison.h b/include/linux/poison.h
63772index 2110a81..13a11bb 100644
63773--- a/include/linux/poison.h
63774+++ b/include/linux/poison.h
63775@@ -19,8 +19,8 @@
63776 * under normal circumstances, used to verify that nobody uses
63777 * non-initialized list entries.
63778 */
63779-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63780-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63781+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63782+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63783
63784 /********** include/linux/timer.h **********/
63785 /*
63786diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63787index 5a710b9..0b0dab9 100644
63788--- a/include/linux/preempt.h
63789+++ b/include/linux/preempt.h
63790@@ -126,7 +126,7 @@ struct preempt_ops {
63791 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63792 void (*sched_out)(struct preempt_notifier *notifier,
63793 struct task_struct *next);
63794-};
63795+} __no_const;
63796
63797 /**
63798 * preempt_notifier - key for installing preemption notifiers
63799diff --git a/include/linux/printk.h b/include/linux/printk.h
63800index 9afc01e..92c32e8 100644
63801--- a/include/linux/printk.h
63802+++ b/include/linux/printk.h
63803@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
63804 extern int printk_needs_cpu(int cpu);
63805 extern void printk_tick(void);
63806
63807+extern int kptr_restrict;
63808+
63809 #ifdef CONFIG_PRINTK
63810 asmlinkage __printf(5, 0)
63811 int vprintk_emit(int facility, int level,
63812@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63813
63814 extern int printk_delay_msec;
63815 extern int dmesg_restrict;
63816-extern int kptr_restrict;
63817
63818 void log_buf_kexec_setup(void);
63819 void __init setup_log_buf(int early);
63820diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63821index 3fd2e87..d93a721 100644
63822--- a/include/linux/proc_fs.h
63823+++ b/include/linux/proc_fs.h
63824@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63825 return proc_create_data(name, mode, parent, proc_fops, NULL);
63826 }
63827
63828+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63829+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63830+{
63831+#ifdef CONFIG_GRKERNSEC_PROC_USER
63832+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63833+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63834+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63835+#else
63836+ return proc_create_data(name, mode, parent, proc_fops, NULL);
63837+#endif
63838+}
63839+
63840 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63841 umode_t mode, struct proc_dir_entry *base,
63842 read_proc_t *read_proc, void * data)
63843@@ -258,7 +270,7 @@ union proc_op {
63844 int (*proc_show)(struct seq_file *m,
63845 struct pid_namespace *ns, struct pid *pid,
63846 struct task_struct *task);
63847-};
63848+} __no_const;
63849
63850 struct ctl_table_header;
63851 struct ctl_table;
63852diff --git a/include/linux/random.h b/include/linux/random.h
63853index ac621ce..c1215f3 100644
63854--- a/include/linux/random.h
63855+++ b/include/linux/random.h
63856@@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63857 unsigned int value);
63858 extern void add_interrupt_randomness(int irq, int irq_flags);
63859
63860+#ifdef CONFIG_PAX_LATENT_ENTROPY
63861+extern void transfer_latent_entropy(void);
63862+#endif
63863+
63864 extern void get_random_bytes(void *buf, int nbytes);
63865 extern void get_random_bytes_arch(void *buf, int nbytes);
63866 void generate_random_uuid(unsigned char uuid_out[16]);
63867@@ -69,12 +73,17 @@ void srandom32(u32 seed);
63868
63869 u32 prandom32(struct rnd_state *);
63870
63871+static inline unsigned long pax_get_random_long(void)
63872+{
63873+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63874+}
63875+
63876 /*
63877 * Handle minimum values for seeds
63878 */
63879 static inline u32 __seed(u32 x, u32 m)
63880 {
63881- return (x < m) ? x + m : x;
63882+ return (x <= m) ? x + m + 1 : x;
63883 }
63884
63885 /**
63886diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63887index e0879a7..a12f962 100644
63888--- a/include/linux/reboot.h
63889+++ b/include/linux/reboot.h
63890@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63891 * Architecture-specific implementations of sys_reboot commands.
63892 */
63893
63894-extern void machine_restart(char *cmd);
63895-extern void machine_halt(void);
63896-extern void machine_power_off(void);
63897+extern void machine_restart(char *cmd) __noreturn;
63898+extern void machine_halt(void) __noreturn;
63899+extern void machine_power_off(void) __noreturn;
63900
63901 extern void machine_shutdown(void);
63902 struct pt_regs;
63903@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63904 */
63905
63906 extern void kernel_restart_prepare(char *cmd);
63907-extern void kernel_restart(char *cmd);
63908-extern void kernel_halt(void);
63909-extern void kernel_power_off(void);
63910+extern void kernel_restart(char *cmd) __noreturn;
63911+extern void kernel_halt(void) __noreturn;
63912+extern void kernel_power_off(void) __noreturn;
63913
63914 extern int C_A_D; /* for sysctl */
63915 void ctrl_alt_del(void);
63916@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63917 * Emergency restart, callable from an interrupt handler.
63918 */
63919
63920-extern void emergency_restart(void);
63921+extern void emergency_restart(void) __noreturn;
63922 #include <asm/emergency-restart.h>
63923
63924 #endif
63925diff --git a/include/linux/relay.h b/include/linux/relay.h
63926index 91cacc3..b55ff74 100644
63927--- a/include/linux/relay.h
63928+++ b/include/linux/relay.h
63929@@ -160,7 +160,7 @@ struct rchan_callbacks
63930 * The callback should return 0 if successful, negative if not.
63931 */
63932 int (*remove_buf_file)(struct dentry *dentry);
63933-};
63934+} __no_const;
63935
63936 /*
63937 * CONFIG_RELAY kernel API, kernel/relay.c
63938diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63939index 6fdf027..ff72610 100644
63940--- a/include/linux/rfkill.h
63941+++ b/include/linux/rfkill.h
63942@@ -147,6 +147,7 @@ struct rfkill_ops {
63943 void (*query)(struct rfkill *rfkill, void *data);
63944 int (*set_block)(void *data, bool blocked);
63945 };
63946+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63947
63948 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63949 /**
63950diff --git a/include/linux/rio.h b/include/linux/rio.h
63951index a90ebad..fd87b5d 100644
63952--- a/include/linux/rio.h
63953+++ b/include/linux/rio.h
63954@@ -321,7 +321,7 @@ struct rio_ops {
63955 int mbox, void *buffer, size_t len);
63956 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63957 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63958-};
63959+} __no_const;
63960
63961 #define RIO_RESOURCE_MEM 0x00000100
63962 #define RIO_RESOURCE_DOORBELL 0x00000200
63963diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63964index 3fce545..b4fed6e 100644
63965--- a/include/linux/rmap.h
63966+++ b/include/linux/rmap.h
63967@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63968 void anon_vma_init(void); /* create anon_vma_cachep */
63969 int anon_vma_prepare(struct vm_area_struct *);
63970 void unlink_anon_vmas(struct vm_area_struct *);
63971-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63972+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63973 void anon_vma_moveto_tail(struct vm_area_struct *);
63974-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63975+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63976
63977 static inline void anon_vma_merge(struct vm_area_struct *vma,
63978 struct vm_area_struct *next)
63979diff --git a/include/linux/sched.h b/include/linux/sched.h
63980index 23bddac..5976055 100644
63981--- a/include/linux/sched.h
63982+++ b/include/linux/sched.h
63983@@ -101,6 +101,7 @@ struct bio_list;
63984 struct fs_struct;
63985 struct perf_event_context;
63986 struct blk_plug;
63987+struct linux_binprm;
63988
63989 /*
63990 * List of flags we want to share for kernel threads,
63991@@ -384,10 +385,13 @@ struct user_namespace;
63992 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63993
63994 extern int sysctl_max_map_count;
63995+extern unsigned long sysctl_heap_stack_gap;
63996
63997 #include <linux/aio.h>
63998
63999 #ifdef CONFIG_MMU
64000+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64001+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64002 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64003 extern unsigned long
64004 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64005@@ -651,6 +655,17 @@ struct signal_struct {
64006 #ifdef CONFIG_TASKSTATS
64007 struct taskstats *stats;
64008 #endif
64009+
64010+#ifdef CONFIG_GRKERNSEC
64011+ u32 curr_ip;
64012+ u32 saved_ip;
64013+ u32 gr_saddr;
64014+ u32 gr_daddr;
64015+ u16 gr_sport;
64016+ u16 gr_dport;
64017+ u8 used_accept:1;
64018+#endif
64019+
64020 #ifdef CONFIG_AUDIT
64021 unsigned audit_tty;
64022 struct tty_audit_buf *tty_audit_buf;
64023@@ -734,6 +749,11 @@ struct user_struct {
64024 struct key *session_keyring; /* UID's default session keyring */
64025 #endif
64026
64027+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64028+ unsigned int banned;
64029+ unsigned long ban_expires;
64030+#endif
64031+
64032 /* Hash table maintenance information */
64033 struct hlist_node uidhash_node;
64034 kuid_t uid;
64035@@ -1356,8 +1376,8 @@ struct task_struct {
64036 struct list_head thread_group;
64037
64038 struct completion *vfork_done; /* for vfork() */
64039- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64040- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64041+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64042+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64043
64044 cputime_t utime, stime, utimescaled, stimescaled;
64045 cputime_t gtime;
64046@@ -1373,11 +1393,6 @@ struct task_struct {
64047 struct task_cputime cputime_expires;
64048 struct list_head cpu_timers[3];
64049
64050-/* process credentials */
64051- const struct cred __rcu *real_cred; /* objective and real subjective task
64052- * credentials (COW) */
64053- const struct cred __rcu *cred; /* effective (overridable) subjective task
64054- * credentials (COW) */
64055 char comm[TASK_COMM_LEN]; /* executable name excluding path
64056 - access with [gs]et_task_comm (which lock
64057 it with task_lock())
64058@@ -1394,6 +1409,10 @@ struct task_struct {
64059 #endif
64060 /* CPU-specific state of this task */
64061 struct thread_struct thread;
64062+/* thread_info moved to task_struct */
64063+#ifdef CONFIG_X86
64064+ struct thread_info tinfo;
64065+#endif
64066 /* filesystem information */
64067 struct fs_struct *fs;
64068 /* open file information */
64069@@ -1467,6 +1486,10 @@ struct task_struct {
64070 gfp_t lockdep_reclaim_gfp;
64071 #endif
64072
64073+/* process credentials */
64074+ const struct cred __rcu *real_cred; /* objective and real subjective task
64075+ * credentials (COW) */
64076+
64077 /* journalling filesystem info */
64078 void *journal_info;
64079
64080@@ -1505,6 +1528,10 @@ struct task_struct {
64081 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64082 struct list_head cg_list;
64083 #endif
64084+
64085+ const struct cred __rcu *cred; /* effective (overridable) subjective task
64086+ * credentials (COW) */
64087+
64088 #ifdef CONFIG_FUTEX
64089 struct robust_list_head __user *robust_list;
64090 #ifdef CONFIG_COMPAT
64091@@ -1589,8 +1616,74 @@ struct task_struct {
64092 #ifdef CONFIG_UPROBES
64093 struct uprobe_task *utask;
64094 #endif
64095+
64096+#ifdef CONFIG_GRKERNSEC
64097+ /* grsecurity */
64098+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64099+ u64 exec_id;
64100+#endif
64101+#ifdef CONFIG_GRKERNSEC_SETXID
64102+ const struct cred *delayed_cred;
64103+#endif
64104+ struct dentry *gr_chroot_dentry;
64105+ struct acl_subject_label *acl;
64106+ struct acl_role_label *role;
64107+ struct file *exec_file;
64108+ u16 acl_role_id;
64109+ /* is this the task that authenticated to the special role */
64110+ u8 acl_sp_role;
64111+ u8 is_writable;
64112+ u8 brute;
64113+ u8 gr_is_chrooted;
64114+#endif
64115+
64116 };
64117
64118+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64119+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64120+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64121+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64122+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64123+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64124+
64125+#ifdef CONFIG_PAX_SOFTMODE
64126+extern int pax_softmode;
64127+#endif
64128+
64129+extern int pax_check_flags(unsigned long *);
64130+
64131+/* if tsk != current then task_lock must be held on it */
64132+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64133+static inline unsigned long pax_get_flags(struct task_struct *tsk)
64134+{
64135+ if (likely(tsk->mm))
64136+ return tsk->mm->pax_flags;
64137+ else
64138+ return 0UL;
64139+}
64140+
64141+/* if tsk != current then task_lock must be held on it */
64142+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64143+{
64144+ if (likely(tsk->mm)) {
64145+ tsk->mm->pax_flags = flags;
64146+ return 0;
64147+ }
64148+ return -EINVAL;
64149+}
64150+#endif
64151+
64152+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64153+extern void pax_set_initial_flags(struct linux_binprm *bprm);
64154+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64155+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64156+#endif
64157+
64158+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64159+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64160+extern void pax_report_refcount_overflow(struct pt_regs *regs);
64161+extern void check_object_size(const void *ptr, unsigned long n, bool to);
64162+
64163 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64164 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64165
64166@@ -2125,7 +2218,9 @@ void yield(void);
64167 extern struct exec_domain default_exec_domain;
64168
64169 union thread_union {
64170+#ifndef CONFIG_X86
64171 struct thread_info thread_info;
64172+#endif
64173 unsigned long stack[THREAD_SIZE/sizeof(long)];
64174 };
64175
64176@@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64177 */
64178
64179 extern struct task_struct *find_task_by_vpid(pid_t nr);
64180+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64181 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64182 struct pid_namespace *ns);
64183
64184@@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64185 extern void exit_itimers(struct signal_struct *);
64186 extern void flush_itimer_signals(void);
64187
64188-extern void do_group_exit(int);
64189+extern __noreturn void do_group_exit(int);
64190
64191 extern void daemonize(const char *, ...);
64192 extern int allow_signal(int);
64193@@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64194
64195 #endif
64196
64197-static inline int object_is_on_stack(void *obj)
64198+static inline int object_starts_on_stack(void *obj)
64199 {
64200- void *stack = task_stack_page(current);
64201+ const void *stack = task_stack_page(current);
64202
64203 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64204 }
64205diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64206index 899fbb4..1cb4138 100644
64207--- a/include/linux/screen_info.h
64208+++ b/include/linux/screen_info.h
64209@@ -43,7 +43,8 @@ struct screen_info {
64210 __u16 pages; /* 0x32 */
64211 __u16 vesa_attributes; /* 0x34 */
64212 __u32 capabilities; /* 0x36 */
64213- __u8 _reserved[6]; /* 0x3a */
64214+ __u16 vesapm_size; /* 0x3a */
64215+ __u8 _reserved[4]; /* 0x3c */
64216 } __attribute__((packed));
64217
64218 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64219diff --git a/include/linux/security.h b/include/linux/security.h
64220index d143b8e..9f27b95 100644
64221--- a/include/linux/security.h
64222+++ b/include/linux/security.h
64223@@ -26,6 +26,7 @@
64224 #include <linux/capability.h>
64225 #include <linux/slab.h>
64226 #include <linux/err.h>
64227+#include <linux/grsecurity.h>
64228
64229 struct linux_binprm;
64230 struct cred;
64231diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64232index 83c44ee..e8a9eba 100644
64233--- a/include/linux/seq_file.h
64234+++ b/include/linux/seq_file.h
64235@@ -25,6 +25,9 @@ struct seq_file {
64236 struct mutex lock;
64237 const struct seq_operations *op;
64238 int poll_event;
64239+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64240+ u64 exec_id;
64241+#endif
64242 void *private;
64243 };
64244
64245@@ -34,6 +37,7 @@ struct seq_operations {
64246 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64247 int (*show) (struct seq_file *m, void *v);
64248 };
64249+typedef struct seq_operations __no_const seq_operations_no_const;
64250
64251 #define SEQ_SKIP 1
64252
64253diff --git a/include/linux/shm.h b/include/linux/shm.h
64254index edd0868..f98feee 100644
64255--- a/include/linux/shm.h
64256+++ b/include/linux/shm.h
64257@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64258
64259 /* The task created the shm object. NULL if the task is dead. */
64260 struct task_struct *shm_creator;
64261+#ifdef CONFIG_GRKERNSEC
64262+ time_t shm_createtime;
64263+ pid_t shm_lapid;
64264+#endif
64265 };
64266
64267 /* shm_mode upper byte flags */
64268diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64269index 7632c87..8fd660f 100644
64270--- a/include/linux/skbuff.h
64271+++ b/include/linux/skbuff.h
64272@@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64273 extern struct sk_buff *__alloc_skb(unsigned int size,
64274 gfp_t priority, int flags, int node);
64275 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64276-static inline struct sk_buff *alloc_skb(unsigned int size,
64277+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64278 gfp_t priority)
64279 {
64280 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64281@@ -690,7 +690,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64282 */
64283 static inline int skb_queue_empty(const struct sk_buff_head *list)
64284 {
64285- return list->next == (struct sk_buff *)list;
64286+ return list->next == (const struct sk_buff *)list;
64287 }
64288
64289 /**
64290@@ -703,7 +703,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64291 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64292 const struct sk_buff *skb)
64293 {
64294- return skb->next == (struct sk_buff *)list;
64295+ return skb->next == (const struct sk_buff *)list;
64296 }
64297
64298 /**
64299@@ -716,7 +716,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64300 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64301 const struct sk_buff *skb)
64302 {
64303- return skb->prev == (struct sk_buff *)list;
64304+ return skb->prev == (const struct sk_buff *)list;
64305 }
64306
64307 /**
64308@@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64309 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64310 */
64311 #ifndef NET_SKB_PAD
64312-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64313+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64314 #endif
64315
64316 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64317@@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64318 int noblock, int *err);
64319 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64320 struct poll_table_struct *wait);
64321-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64322+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64323 int offset, struct iovec *to,
64324 int size);
64325 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64326diff --git a/include/linux/slab.h b/include/linux/slab.h
64327index 0dd2dfa..2b8677c 100644
64328--- a/include/linux/slab.h
64329+++ b/include/linux/slab.h
64330@@ -11,12 +11,20 @@
64331
64332 #include <linux/gfp.h>
64333 #include <linux/types.h>
64334+#include <linux/err.h>
64335
64336 /*
64337 * Flags to pass to kmem_cache_create().
64338 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64339 */
64340 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64341+
64342+#ifdef CONFIG_PAX_USERCOPY_SLABS
64343+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64344+#else
64345+#define SLAB_USERCOPY 0x00000000UL
64346+#endif
64347+
64348 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64349 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64350 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64351@@ -87,10 +95,13 @@
64352 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64353 * Both make kfree a no-op.
64354 */
64355-#define ZERO_SIZE_PTR ((void *)16)
64356+#define ZERO_SIZE_PTR \
64357+({ \
64358+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64359+ (void *)(-MAX_ERRNO-1L); \
64360+})
64361
64362-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64363- (unsigned long)ZERO_SIZE_PTR)
64364+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64365
64366 /*
64367 * Common fields provided in kmem_cache by all slab allocators
64368@@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64369 void kfree(const void *);
64370 void kzfree(const void *);
64371 size_t ksize(const void *);
64372+const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64373+bool is_usercopy_object(const void *ptr);
64374
64375 /*
64376 * Allocator specific definitions. These are mainly used to establish optimized
64377@@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64378 */
64379 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64380 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64381-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64382+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64383 #define kmalloc_track_caller(size, flags) \
64384 __kmalloc_track_caller(size, flags, _RET_IP_)
64385 #else
64386@@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64387 */
64388 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64389 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64390-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64391+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64392 #define kmalloc_node_track_caller(size, flags, node) \
64393 __kmalloc_node_track_caller(size, flags, node, \
64394 _RET_IP_)
64395diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64396index 0c634fa..8616300 100644
64397--- a/include/linux/slab_def.h
64398+++ b/include/linux/slab_def.h
64399@@ -69,10 +69,10 @@ struct kmem_cache {
64400 unsigned long node_allocs;
64401 unsigned long node_frees;
64402 unsigned long node_overflow;
64403- atomic_t allochit;
64404- atomic_t allocmiss;
64405- atomic_t freehit;
64406- atomic_t freemiss;
64407+ atomic_unchecked_t allochit;
64408+ atomic_unchecked_t allocmiss;
64409+ atomic_unchecked_t freehit;
64410+ atomic_unchecked_t freemiss;
64411
64412 /*
64413 * If debugging is enabled, then the allocator can add additional
64414@@ -105,11 +105,16 @@ struct cache_sizes {
64415 #ifdef CONFIG_ZONE_DMA
64416 struct kmem_cache *cs_dmacachep;
64417 #endif
64418+
64419+#ifdef CONFIG_PAX_USERCOPY_SLABS
64420+ struct kmem_cache *cs_usercopycachep;
64421+#endif
64422+
64423 };
64424 extern struct cache_sizes malloc_sizes[];
64425
64426 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64427-void *__kmalloc(size_t size, gfp_t flags);
64428+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64429
64430 #ifdef CONFIG_TRACING
64431 extern void *kmem_cache_alloc_trace(size_t size,
64432@@ -152,6 +157,13 @@ found:
64433 cachep = malloc_sizes[i].cs_dmacachep;
64434 else
64435 #endif
64436+
64437+#ifdef CONFIG_PAX_USERCOPY_SLABS
64438+ if (flags & GFP_USERCOPY)
64439+ cachep = malloc_sizes[i].cs_usercopycachep;
64440+ else
64441+#endif
64442+
64443 cachep = malloc_sizes[i].cs_cachep;
64444
64445 ret = kmem_cache_alloc_trace(size, cachep, flags);
64446@@ -162,7 +174,7 @@ found:
64447 }
64448
64449 #ifdef CONFIG_NUMA
64450-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64451+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64452 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64453
64454 #ifdef CONFIG_TRACING
64455@@ -205,6 +217,13 @@ found:
64456 cachep = malloc_sizes[i].cs_dmacachep;
64457 else
64458 #endif
64459+
64460+#ifdef CONFIG_PAX_USERCOPY_SLABS
64461+ if (flags & GFP_USERCOPY)
64462+ cachep = malloc_sizes[i].cs_usercopycachep;
64463+ else
64464+#endif
64465+
64466 cachep = malloc_sizes[i].cs_cachep;
64467
64468 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64469diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64470index 0ec00b3..22b4715 100644
64471--- a/include/linux/slob_def.h
64472+++ b/include/linux/slob_def.h
64473@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64474 return kmem_cache_alloc_node(cachep, flags, -1);
64475 }
64476
64477-void *__kmalloc_node(size_t size, gfp_t flags, int node);
64478+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64479
64480 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64481 {
64482@@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64483 return __kmalloc_node(size, flags, -1);
64484 }
64485
64486-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64487+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64488 {
64489 return kmalloc(size, flags);
64490 }
64491diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64492index df448ad..b99e7f6 100644
64493--- a/include/linux/slub_def.h
64494+++ b/include/linux/slub_def.h
64495@@ -91,7 +91,7 @@ struct kmem_cache {
64496 struct kmem_cache_order_objects max;
64497 struct kmem_cache_order_objects min;
64498 gfp_t allocflags; /* gfp flags to use on each alloc */
64499- int refcount; /* Refcount for slab cache destroy */
64500+ atomic_t refcount; /* Refcount for slab cache destroy */
64501 void (*ctor)(void *);
64502 int inuse; /* Offset to metadata */
64503 int align; /* Alignment */
64504@@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64505 * Sorry that the following has to be that ugly but some versions of GCC
64506 * have trouble with constant propagation and loops.
64507 */
64508-static __always_inline int kmalloc_index(size_t size)
64509+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64510 {
64511 if (!size)
64512 return 0;
64513@@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64514 }
64515
64516 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64517-void *__kmalloc(size_t size, gfp_t flags);
64518+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64519
64520 static __always_inline void *
64521 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64522@@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64523 }
64524 #endif
64525
64526-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64527+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64528 {
64529 unsigned int order = get_order(size);
64530 return kmalloc_order_trace(size, flags, order);
64531@@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64532 }
64533
64534 #ifdef CONFIG_NUMA
64535-void *__kmalloc_node(size_t size, gfp_t flags, int node);
64536+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64537 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64538
64539 #ifdef CONFIG_TRACING
64540diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64541index de8832d..0147b46 100644
64542--- a/include/linux/sonet.h
64543+++ b/include/linux/sonet.h
64544@@ -61,7 +61,7 @@ struct sonet_stats {
64545 #include <linux/atomic.h>
64546
64547 struct k_sonet_stats {
64548-#define __HANDLE_ITEM(i) atomic_t i
64549+#define __HANDLE_ITEM(i) atomic_unchecked_t i
64550 __SONET_ITEMS
64551 #undef __HANDLE_ITEM
64552 };
64553diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64554index 523547e..2cb7140 100644
64555--- a/include/linux/sunrpc/clnt.h
64556+++ b/include/linux/sunrpc/clnt.h
64557@@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64558 {
64559 switch (sap->sa_family) {
64560 case AF_INET:
64561- return ntohs(((struct sockaddr_in *)sap)->sin_port);
64562+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64563 case AF_INET6:
64564- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64565+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64566 }
64567 return 0;
64568 }
64569@@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64570 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64571 const struct sockaddr *src)
64572 {
64573- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64574+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64575 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64576
64577 dsin->sin_family = ssin->sin_family;
64578@@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64579 if (sa->sa_family != AF_INET6)
64580 return 0;
64581
64582- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64583+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64584 }
64585
64586 #endif /* __KERNEL__ */
64587diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64588index dc0c3cc..8503fb6 100644
64589--- a/include/linux/sunrpc/sched.h
64590+++ b/include/linux/sunrpc/sched.h
64591@@ -106,6 +106,7 @@ struct rpc_call_ops {
64592 void (*rpc_count_stats)(struct rpc_task *, void *);
64593 void (*rpc_release)(void *);
64594 };
64595+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64596
64597 struct rpc_task_setup {
64598 struct rpc_task *task;
64599diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64600index 0b8e3e6..33e0a01 100644
64601--- a/include/linux/sunrpc/svc_rdma.h
64602+++ b/include/linux/sunrpc/svc_rdma.h
64603@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64604 extern unsigned int svcrdma_max_requests;
64605 extern unsigned int svcrdma_max_req_size;
64606
64607-extern atomic_t rdma_stat_recv;
64608-extern atomic_t rdma_stat_read;
64609-extern atomic_t rdma_stat_write;
64610-extern atomic_t rdma_stat_sq_starve;
64611-extern atomic_t rdma_stat_rq_starve;
64612-extern atomic_t rdma_stat_rq_poll;
64613-extern atomic_t rdma_stat_rq_prod;
64614-extern atomic_t rdma_stat_sq_poll;
64615-extern atomic_t rdma_stat_sq_prod;
64616+extern atomic_unchecked_t rdma_stat_recv;
64617+extern atomic_unchecked_t rdma_stat_read;
64618+extern atomic_unchecked_t rdma_stat_write;
64619+extern atomic_unchecked_t rdma_stat_sq_starve;
64620+extern atomic_unchecked_t rdma_stat_rq_starve;
64621+extern atomic_unchecked_t rdma_stat_rq_poll;
64622+extern atomic_unchecked_t rdma_stat_rq_prod;
64623+extern atomic_unchecked_t rdma_stat_sq_poll;
64624+extern atomic_unchecked_t rdma_stat_sq_prod;
64625
64626 #define RPCRDMA_VERSION 1
64627
64628diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64629index c34b4c8..a65b67d 100644
64630--- a/include/linux/sysctl.h
64631+++ b/include/linux/sysctl.h
64632@@ -155,7 +155,11 @@ enum
64633 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64634 };
64635
64636-
64637+#ifdef CONFIG_PAX_SOFTMODE
64638+enum {
64639+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64640+};
64641+#endif
64642
64643 /* CTL_VM names: */
64644 enum
64645@@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64646
64647 extern int proc_dostring(struct ctl_table *, int,
64648 void __user *, size_t *, loff_t *);
64649+extern int proc_dostring_modpriv(struct ctl_table *, int,
64650+ void __user *, size_t *, loff_t *);
64651 extern int proc_dointvec(struct ctl_table *, int,
64652 void __user *, size_t *, loff_t *);
64653 extern int proc_dointvec_minmax(struct ctl_table *, int,
64654diff --git a/include/linux/tty.h b/include/linux/tty.h
64655index 9f47ab5..73da944 100644
64656--- a/include/linux/tty.h
64657+++ b/include/linux/tty.h
64658@@ -225,7 +225,7 @@ struct tty_port {
64659 const struct tty_port_operations *ops; /* Port operations */
64660 spinlock_t lock; /* Lock protecting tty field */
64661 int blocked_open; /* Waiting to open */
64662- int count; /* Usage count */
64663+ atomic_t count; /* Usage count */
64664 wait_queue_head_t open_wait; /* Open waiters */
64665 wait_queue_head_t close_wait; /* Close waiters */
64666 wait_queue_head_t delta_msr_wait; /* Modem status change */
64667@@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64668 struct tty_struct *tty, struct file *filp);
64669 static inline int tty_port_users(struct tty_port *port)
64670 {
64671- return port->count + port->blocked_open;
64672+ return atomic_read(&port->count) + port->blocked_open;
64673 }
64674
64675 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64676diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64677index fb79dd8d..07d4773 100644
64678--- a/include/linux/tty_ldisc.h
64679+++ b/include/linux/tty_ldisc.h
64680@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64681
64682 struct module *owner;
64683
64684- int refcount;
64685+ atomic_t refcount;
64686 };
64687
64688 struct tty_ldisc {
64689diff --git a/include/linux/types.h b/include/linux/types.h
64690index bf0dd75..a1f23aaa 100644
64691--- a/include/linux/types.h
64692+++ b/include/linux/types.h
64693@@ -220,10 +220,26 @@ typedef struct {
64694 int counter;
64695 } atomic_t;
64696
64697+#ifdef CONFIG_PAX_REFCOUNT
64698+typedef struct {
64699+ int counter;
64700+} atomic_unchecked_t;
64701+#else
64702+typedef atomic_t atomic_unchecked_t;
64703+#endif
64704+
64705 #ifdef CONFIG_64BIT
64706 typedef struct {
64707 long counter;
64708 } atomic64_t;
64709+
64710+#ifdef CONFIG_PAX_REFCOUNT
64711+typedef struct {
64712+ long counter;
64713+} atomic64_unchecked_t;
64714+#else
64715+typedef atomic64_t atomic64_unchecked_t;
64716+#endif
64717 #endif
64718
64719 struct list_head {
64720diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64721index 5ca0951..ab496a5 100644
64722--- a/include/linux/uaccess.h
64723+++ b/include/linux/uaccess.h
64724@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64725 long ret; \
64726 mm_segment_t old_fs = get_fs(); \
64727 \
64728- set_fs(KERNEL_DS); \
64729 pagefault_disable(); \
64730- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64731- pagefault_enable(); \
64732+ set_fs(KERNEL_DS); \
64733+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64734 set_fs(old_fs); \
64735+ pagefault_enable(); \
64736 ret; \
64737 })
64738
64739diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64740index 99c1b4d..bb94261 100644
64741--- a/include/linux/unaligned/access_ok.h
64742+++ b/include/linux/unaligned/access_ok.h
64743@@ -6,32 +6,32 @@
64744
64745 static inline u16 get_unaligned_le16(const void *p)
64746 {
64747- return le16_to_cpup((__le16 *)p);
64748+ return le16_to_cpup((const __le16 *)p);
64749 }
64750
64751 static inline u32 get_unaligned_le32(const void *p)
64752 {
64753- return le32_to_cpup((__le32 *)p);
64754+ return le32_to_cpup((const __le32 *)p);
64755 }
64756
64757 static inline u64 get_unaligned_le64(const void *p)
64758 {
64759- return le64_to_cpup((__le64 *)p);
64760+ return le64_to_cpup((const __le64 *)p);
64761 }
64762
64763 static inline u16 get_unaligned_be16(const void *p)
64764 {
64765- return be16_to_cpup((__be16 *)p);
64766+ return be16_to_cpup((const __be16 *)p);
64767 }
64768
64769 static inline u32 get_unaligned_be32(const void *p)
64770 {
64771- return be32_to_cpup((__be32 *)p);
64772+ return be32_to_cpup((const __be32 *)p);
64773 }
64774
64775 static inline u64 get_unaligned_be64(const void *p)
64776 {
64777- return be64_to_cpup((__be64 *)p);
64778+ return be64_to_cpup((const __be64 *)p);
64779 }
64780
64781 static inline void put_unaligned_le16(u16 val, void *p)
64782diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64783index c5d36c6..8478c90 100644
64784--- a/include/linux/usb/renesas_usbhs.h
64785+++ b/include/linux/usb/renesas_usbhs.h
64786@@ -39,7 +39,7 @@ enum {
64787 */
64788 struct renesas_usbhs_driver_callback {
64789 int (*notify_hotplug)(struct platform_device *pdev);
64790-};
64791+} __no_const;
64792
64793 /*
64794 * callback functions for platform
64795@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64796 * VBUS control is needed for Host
64797 */
64798 int (*set_vbus)(struct platform_device *pdev, int enable);
64799-};
64800+} __no_const;
64801
64802 /*
64803 * parameters for renesas usbhs
64804diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64805index 6f8fbcf..8259001 100644
64806--- a/include/linux/vermagic.h
64807+++ b/include/linux/vermagic.h
64808@@ -25,9 +25,35 @@
64809 #define MODULE_ARCH_VERMAGIC ""
64810 #endif
64811
64812+#ifdef CONFIG_PAX_REFCOUNT
64813+#define MODULE_PAX_REFCOUNT "REFCOUNT "
64814+#else
64815+#define MODULE_PAX_REFCOUNT ""
64816+#endif
64817+
64818+#ifdef CONSTIFY_PLUGIN
64819+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64820+#else
64821+#define MODULE_CONSTIFY_PLUGIN ""
64822+#endif
64823+
64824+#ifdef STACKLEAK_PLUGIN
64825+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64826+#else
64827+#define MODULE_STACKLEAK_PLUGIN ""
64828+#endif
64829+
64830+#ifdef CONFIG_GRKERNSEC
64831+#define MODULE_GRSEC "GRSEC "
64832+#else
64833+#define MODULE_GRSEC ""
64834+#endif
64835+
64836 #define VERMAGIC_STRING \
64837 UTS_RELEASE " " \
64838 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64839 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64840- MODULE_ARCH_VERMAGIC
64841+ MODULE_ARCH_VERMAGIC \
64842+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64843+ MODULE_GRSEC
64844
64845diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64846index 6071e91..ca6a489 100644
64847--- a/include/linux/vmalloc.h
64848+++ b/include/linux/vmalloc.h
64849@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64850 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64851 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64852 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64853+
64854+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64855+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64856+#endif
64857+
64858 /* bits [20..32] reserved for arch specific ioremap internals */
64859
64860 /*
64861@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64862 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64863 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64864 unsigned long start, unsigned long end, gfp_t gfp_mask,
64865- pgprot_t prot, int node, const void *caller);
64866+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
64867 extern void vfree(const void *addr);
64868
64869 extern void *vmap(struct page **pages, unsigned int count,
64870@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64871 extern void free_vm_area(struct vm_struct *area);
64872
64873 /* for /dev/kmem */
64874-extern long vread(char *buf, char *addr, unsigned long count);
64875-extern long vwrite(char *buf, char *addr, unsigned long count);
64876+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64877+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64878
64879 /*
64880 * Internals. Dont't use..
64881diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64882index ad2cfd5..74c94ad 100644
64883--- a/include/linux/vmstat.h
64884+++ b/include/linux/vmstat.h
64885@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64886 /*
64887 * Zone based page accounting with per cpu differentials.
64888 */
64889-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64890+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64891
64892 static inline void zone_page_state_add(long x, struct zone *zone,
64893 enum zone_stat_item item)
64894 {
64895- atomic_long_add(x, &zone->vm_stat[item]);
64896- atomic_long_add(x, &vm_stat[item]);
64897+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64898+ atomic_long_add_unchecked(x, &vm_stat[item]);
64899 }
64900
64901 static inline unsigned long global_page_state(enum zone_stat_item item)
64902 {
64903- long x = atomic_long_read(&vm_stat[item]);
64904+ long x = atomic_long_read_unchecked(&vm_stat[item]);
64905 #ifdef CONFIG_SMP
64906 if (x < 0)
64907 x = 0;
64908@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64909 static inline unsigned long zone_page_state(struct zone *zone,
64910 enum zone_stat_item item)
64911 {
64912- long x = atomic_long_read(&zone->vm_stat[item]);
64913+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64914 #ifdef CONFIG_SMP
64915 if (x < 0)
64916 x = 0;
64917@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64918 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64919 enum zone_stat_item item)
64920 {
64921- long x = atomic_long_read(&zone->vm_stat[item]);
64922+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64923
64924 #ifdef CONFIG_SMP
64925 int cpu;
64926@@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64927
64928 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64929 {
64930- atomic_long_inc(&zone->vm_stat[item]);
64931- atomic_long_inc(&vm_stat[item]);
64932+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
64933+ atomic_long_inc_unchecked(&vm_stat[item]);
64934 }
64935
64936 static inline void __inc_zone_page_state(struct page *page,
64937@@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
64938
64939 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64940 {
64941- atomic_long_dec(&zone->vm_stat[item]);
64942- atomic_long_dec(&vm_stat[item]);
64943+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
64944+ atomic_long_dec_unchecked(&vm_stat[item]);
64945 }
64946
64947 static inline void __dec_zone_page_state(struct page *page,
64948diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64949index e5d1220..ef6e406 100644
64950--- a/include/linux/xattr.h
64951+++ b/include/linux/xattr.h
64952@@ -57,6 +57,11 @@
64953 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64954 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64955
64956+/* User namespace */
64957+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64958+#define XATTR_PAX_FLAGS_SUFFIX "flags"
64959+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64960+
64961 #ifdef __KERNEL__
64962
64963 #include <linux/types.h>
64964diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64965index 944ecdf..a3994fc 100644
64966--- a/include/media/saa7146_vv.h
64967+++ b/include/media/saa7146_vv.h
64968@@ -161,8 +161,8 @@ struct saa7146_ext_vv
64969 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64970
64971 /* the extension can override this */
64972- struct v4l2_ioctl_ops vid_ops;
64973- struct v4l2_ioctl_ops vbi_ops;
64974+ v4l2_ioctl_ops_no_const vid_ops;
64975+ v4l2_ioctl_ops_no_const vbi_ops;
64976 /* pointer to the saa7146 core ops */
64977 const struct v4l2_ioctl_ops *core_ops;
64978
64979diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64980index 5c416cd..20021aa 100644
64981--- a/include/media/v4l2-dev.h
64982+++ b/include/media/v4l2-dev.h
64983@@ -73,7 +73,8 @@ struct v4l2_file_operations {
64984 int (*mmap) (struct file *, struct vm_area_struct *);
64985 int (*open) (struct file *);
64986 int (*release) (struct file *);
64987-};
64988+} __do_const;
64989+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64990
64991 /*
64992 * Newer version of video_device, handled by videodev2.c
64993diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64994index e614c9c..20602b7 100644
64995--- a/include/media/v4l2-ioctl.h
64996+++ b/include/media/v4l2-ioctl.h
64997@@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
64998 long (*vidioc_default) (struct file *file, void *fh,
64999 bool valid_prio, int cmd, void *arg);
65000 };
65001-
65002+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65003
65004 /* v4l debugging and diagnostics */
65005
65006diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65007index bcb9cc3..f4ec722e 100644
65008--- a/include/net/caif/caif_hsi.h
65009+++ b/include/net/caif/caif_hsi.h
65010@@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65011 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65012 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65013 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65014-};
65015+} __no_const;
65016
65017 /* Structure implemented by HSI device. */
65018 struct cfhsi_ops {
65019diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65020index 9e5425b..8136ffc 100644
65021--- a/include/net/caif/cfctrl.h
65022+++ b/include/net/caif/cfctrl.h
65023@@ -52,7 +52,7 @@ struct cfctrl_rsp {
65024 void (*radioset_rsp)(void);
65025 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65026 struct cflayer *client_layer);
65027-};
65028+} __no_const;
65029
65030 /* Link Setup Parameters for CAIF-Links. */
65031 struct cfctrl_link_param {
65032@@ -101,8 +101,8 @@ struct cfctrl_request_info {
65033 struct cfctrl {
65034 struct cfsrvl serv;
65035 struct cfctrl_rsp res;
65036- atomic_t req_seq_no;
65037- atomic_t rsp_seq_no;
65038+ atomic_unchecked_t req_seq_no;
65039+ atomic_unchecked_t rsp_seq_no;
65040 struct list_head list;
65041 /* Protects from simultaneous access to first_req list */
65042 spinlock_t info_list_lock;
65043diff --git a/include/net/flow.h b/include/net/flow.h
65044index e1dd508..2873851 100644
65045--- a/include/net/flow.h
65046+++ b/include/net/flow.h
65047@@ -220,6 +220,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65048
65049 extern void flow_cache_flush(void);
65050 extern void flow_cache_flush_deferred(void);
65051-extern atomic_t flow_cache_genid;
65052+extern atomic_unchecked_t flow_cache_genid;
65053
65054 #endif
65055diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65056index 53f464d..ba76aaa 100644
65057--- a/include/net/inetpeer.h
65058+++ b/include/net/inetpeer.h
65059@@ -47,8 +47,8 @@ struct inet_peer {
65060 */
65061 union {
65062 struct {
65063- atomic_t rid; /* Frag reception counter */
65064- atomic_t ip_id_count; /* IP ID for the next packet */
65065+ atomic_unchecked_t rid; /* Frag reception counter */
65066+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65067 };
65068 struct rcu_head rcu;
65069 struct inet_peer *gc_next;
65070@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65071 more++;
65072 inet_peer_refcheck(p);
65073 do {
65074- old = atomic_read(&p->ip_id_count);
65075+ old = atomic_read_unchecked(&p->ip_id_count);
65076 new = old + more;
65077 if (!new)
65078 new = 1;
65079- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65080+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65081 return new;
65082 }
65083
65084diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65085index 926142e..80911e1 100644
65086--- a/include/net/ip_fib.h
65087+++ b/include/net/ip_fib.h
65088@@ -168,7 +168,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65089
65090 #define FIB_RES_SADDR(net, res) \
65091 ((FIB_RES_NH(res).nh_saddr_genid == \
65092- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65093+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65094 FIB_RES_NH(res).nh_saddr : \
65095 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65096 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65097diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65098index 95374d1..2300e36 100644
65099--- a/include/net/ip_vs.h
65100+++ b/include/net/ip_vs.h
65101@@ -510,7 +510,7 @@ struct ip_vs_conn {
65102 struct ip_vs_conn *control; /* Master control connection */
65103 atomic_t n_control; /* Number of controlled ones */
65104 struct ip_vs_dest *dest; /* real server */
65105- atomic_t in_pkts; /* incoming packet counter */
65106+ atomic_unchecked_t in_pkts; /* incoming packet counter */
65107
65108 /* packet transmitter for different forwarding methods. If it
65109 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65110@@ -648,7 +648,7 @@ struct ip_vs_dest {
65111 __be16 port; /* port number of the server */
65112 union nf_inet_addr addr; /* IP address of the server */
65113 volatile unsigned int flags; /* dest status flags */
65114- atomic_t conn_flags; /* flags to copy to conn */
65115+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
65116 atomic_t weight; /* server weight */
65117
65118 atomic_t refcnt; /* reference counter */
65119diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65120index 69b610a..fe3962c 100644
65121--- a/include/net/irda/ircomm_core.h
65122+++ b/include/net/irda/ircomm_core.h
65123@@ -51,7 +51,7 @@ typedef struct {
65124 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65125 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65126 struct ircomm_info *);
65127-} call_t;
65128+} __no_const call_t;
65129
65130 struct ircomm_cb {
65131 irda_queue_t queue;
65132diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65133index 59ba38bc..d515662 100644
65134--- a/include/net/irda/ircomm_tty.h
65135+++ b/include/net/irda/ircomm_tty.h
65136@@ -35,6 +35,7 @@
65137 #include <linux/termios.h>
65138 #include <linux/timer.h>
65139 #include <linux/tty.h> /* struct tty_struct */
65140+#include <asm/local.h>
65141
65142 #include <net/irda/irias_object.h>
65143 #include <net/irda/ircomm_core.h>
65144@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65145 unsigned short close_delay;
65146 unsigned short closing_wait; /* time to wait before closing */
65147
65148- int open_count;
65149- int blocked_open; /* # of blocked opens */
65150+ local_t open_count;
65151+ local_t blocked_open; /* # of blocked opens */
65152
65153 /* Protect concurent access to :
65154 * o self->open_count
65155diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65156index cc7c197..9f2da2a 100644
65157--- a/include/net/iucv/af_iucv.h
65158+++ b/include/net/iucv/af_iucv.h
65159@@ -141,7 +141,7 @@ struct iucv_sock {
65160 struct iucv_sock_list {
65161 struct hlist_head head;
65162 rwlock_t lock;
65163- atomic_t autobind_name;
65164+ atomic_unchecked_t autobind_name;
65165 };
65166
65167 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65168diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65169index 344d898..2ae1302 100644
65170--- a/include/net/neighbour.h
65171+++ b/include/net/neighbour.h
65172@@ -123,7 +123,7 @@ struct neigh_ops {
65173 void (*error_report)(struct neighbour *, struct sk_buff *);
65174 int (*output)(struct neighbour *, struct sk_buff *);
65175 int (*connected_output)(struct neighbour *, struct sk_buff *);
65176-};
65177+} __do_const;
65178
65179 struct pneigh_entry {
65180 struct pneigh_entry *next;
65181diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65182index fd87963..312a11f 100644
65183--- a/include/net/net_namespace.h
65184+++ b/include/net/net_namespace.h
65185@@ -102,7 +102,7 @@ struct net {
65186 #endif
65187 struct netns_ipvs *ipvs;
65188 struct sock *diag_nlsk;
65189- atomic_t rt_genid;
65190+ atomic_unchecked_t rt_genid;
65191 };
65192
65193
65194@@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65195
65196 static inline int rt_genid(struct net *net)
65197 {
65198- return atomic_read(&net->rt_genid);
65199+ return atomic_read_unchecked(&net->rt_genid);
65200 }
65201
65202 static inline void rt_genid_bump(struct net *net)
65203 {
65204- atomic_inc(&net->rt_genid);
65205+ atomic_inc_unchecked(&net->rt_genid);
65206 }
65207
65208 #endif /* __NET_NET_NAMESPACE_H */
65209diff --git a/include/net/netdma.h b/include/net/netdma.h
65210index 8ba8ce2..99b7fff 100644
65211--- a/include/net/netdma.h
65212+++ b/include/net/netdma.h
65213@@ -24,7 +24,7 @@
65214 #include <linux/dmaengine.h>
65215 #include <linux/skbuff.h>
65216
65217-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65218+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65219 struct sk_buff *skb, int offset, struct iovec *to,
65220 size_t len, struct dma_pinned_list *pinned_list);
65221
65222diff --git a/include/net/netlink.h b/include/net/netlink.h
65223index 785f37a..c81dc0c 100644
65224--- a/include/net/netlink.h
65225+++ b/include/net/netlink.h
65226@@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65227 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65228 {
65229 if (mark)
65230- skb_trim(skb, (unsigned char *) mark - skb->data);
65231+ skb_trim(skb, (const unsigned char *) mark - skb->data);
65232 }
65233
65234 /**
65235diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65236index eb24dbc..567d6ed 100644
65237--- a/include/net/netns/ipv4.h
65238+++ b/include/net/netns/ipv4.h
65239@@ -65,7 +65,7 @@ struct netns_ipv4 {
65240 unsigned int sysctl_ping_group_range[2];
65241 long sysctl_tcp_mem[3];
65242
65243- atomic_t dev_addr_genid;
65244+ atomic_unchecked_t dev_addr_genid;
65245
65246 #ifdef CONFIG_IP_MROUTE
65247 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65248diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65249index ff49964..1411fee 100644
65250--- a/include/net/sctp/sctp.h
65251+++ b/include/net/sctp/sctp.h
65252@@ -320,9 +320,9 @@ do { \
65253
65254 #else /* SCTP_DEBUG */
65255
65256-#define SCTP_DEBUG_PRINTK(whatever...)
65257-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65258-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65259+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65260+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65261+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65262 #define SCTP_ENABLE_DEBUG
65263 #define SCTP_DISABLE_DEBUG
65264 #define SCTP_ASSERT(expr, str, func)
65265diff --git a/include/net/sock.h b/include/net/sock.h
65266index adb7da2..1100002 100644
65267--- a/include/net/sock.h
65268+++ b/include/net/sock.h
65269@@ -305,7 +305,7 @@ struct sock {
65270 #ifdef CONFIG_RPS
65271 __u32 sk_rxhash;
65272 #endif
65273- atomic_t sk_drops;
65274+ atomic_unchecked_t sk_drops;
65275 int sk_rcvbuf;
65276
65277 struct sk_filter __rcu *sk_filter;
65278@@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65279 }
65280
65281 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65282- char __user *from, char *to,
65283+ char __user *from, unsigned char *to,
65284 int copy, int offset)
65285 {
65286 if (skb->ip_summed == CHECKSUM_NONE) {
65287@@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65288 }
65289 }
65290
65291-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65292+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65293
65294 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65295 {
65296diff --git a/include/net/tcp.h b/include/net/tcp.h
65297index 1f000ff..e5a8dfb 100644
65298--- a/include/net/tcp.h
65299+++ b/include/net/tcp.h
65300@@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65301 extern void tcp_xmit_retransmit_queue(struct sock *);
65302 extern void tcp_simple_retransmit(struct sock *);
65303 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65304-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65305+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65306
65307 extern void tcp_send_probe0(struct sock *);
65308 extern void tcp_send_partial(struct sock *);
65309@@ -677,8 +677,8 @@ struct tcp_skb_cb {
65310 struct inet6_skb_parm h6;
65311 #endif
65312 } header; /* For incoming frames */
65313- __u32 seq; /* Starting sequence number */
65314- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65315+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
65316+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65317 __u32 when; /* used to compute rtt's */
65318 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65319
65320@@ -692,7 +692,7 @@ struct tcp_skb_cb {
65321
65322 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65323 /* 1 byte hole */
65324- __u32 ack_seq; /* Sequence number ACK'd */
65325+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65326 };
65327
65328 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65329@@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65330 char *name;
65331 sa_family_t family;
65332 const struct file_operations *seq_fops;
65333- struct seq_operations seq_ops;
65334+ seq_operations_no_const seq_ops;
65335 };
65336
65337 struct tcp_iter_state {
65338diff --git a/include/net/udp.h b/include/net/udp.h
65339index 065f379..b661b40 100644
65340--- a/include/net/udp.h
65341+++ b/include/net/udp.h
65342@@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65343 sa_family_t family;
65344 struct udp_table *udp_table;
65345 const struct file_operations *seq_fops;
65346- struct seq_operations seq_ops;
65347+ seq_operations_no_const seq_ops;
65348 };
65349
65350 struct udp_iter_state {
65351diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65352index 639dd13..15b206c 100644
65353--- a/include/net/xfrm.h
65354+++ b/include/net/xfrm.h
65355@@ -514,7 +514,7 @@ struct xfrm_policy {
65356 struct timer_list timer;
65357
65358 struct flow_cache_object flo;
65359- atomic_t genid;
65360+ atomic_unchecked_t genid;
65361 u32 priority;
65362 u32 index;
65363 struct xfrm_mark mark;
65364diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65365index 1a046b1..ee0bef0 100644
65366--- a/include/rdma/iw_cm.h
65367+++ b/include/rdma/iw_cm.h
65368@@ -122,7 +122,7 @@ struct iw_cm_verbs {
65369 int backlog);
65370
65371 int (*destroy_listen)(struct iw_cm_id *cm_id);
65372-};
65373+} __no_const;
65374
65375 /**
65376 * iw_create_cm_id - Create an IW CM identifier.
65377diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65378index 399162b..b337f1a 100644
65379--- a/include/scsi/libfc.h
65380+++ b/include/scsi/libfc.h
65381@@ -762,6 +762,7 @@ struct libfc_function_template {
65382 */
65383 void (*disc_stop_final) (struct fc_lport *);
65384 };
65385+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65386
65387 /**
65388 * struct fc_disc - Discovery context
65389@@ -866,7 +867,7 @@ struct fc_lport {
65390 struct fc_vport *vport;
65391
65392 /* Operational Information */
65393- struct libfc_function_template tt;
65394+ libfc_function_template_no_const tt;
65395 u8 link_up;
65396 u8 qfull;
65397 enum fc_lport_state state;
65398diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65399index 9895f69..f1418f0 100644
65400--- a/include/scsi/scsi_device.h
65401+++ b/include/scsi/scsi_device.h
65402@@ -166,9 +166,9 @@ struct scsi_device {
65403 unsigned int max_device_blocked; /* what device_blocked counts down from */
65404 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65405
65406- atomic_t iorequest_cnt;
65407- atomic_t iodone_cnt;
65408- atomic_t ioerr_cnt;
65409+ atomic_unchecked_t iorequest_cnt;
65410+ atomic_unchecked_t iodone_cnt;
65411+ atomic_unchecked_t ioerr_cnt;
65412
65413 struct device sdev_gendev,
65414 sdev_dev;
65415diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65416index b797e8f..8e2c3aa 100644
65417--- a/include/scsi/scsi_transport_fc.h
65418+++ b/include/scsi/scsi_transport_fc.h
65419@@ -751,7 +751,8 @@ struct fc_function_template {
65420 unsigned long show_host_system_hostname:1;
65421
65422 unsigned long disable_target_scan:1;
65423-};
65424+} __do_const;
65425+typedef struct fc_function_template __no_const fc_function_template_no_const;
65426
65427
65428 /**
65429diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65430index 030b87c..98a6954 100644
65431--- a/include/sound/ak4xxx-adda.h
65432+++ b/include/sound/ak4xxx-adda.h
65433@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65434 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65435 unsigned char val);
65436 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65437-};
65438+} __no_const;
65439
65440 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65441
65442diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65443index 8c05e47..2b5df97 100644
65444--- a/include/sound/hwdep.h
65445+++ b/include/sound/hwdep.h
65446@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65447 struct snd_hwdep_dsp_status *status);
65448 int (*dsp_load)(struct snd_hwdep *hw,
65449 struct snd_hwdep_dsp_image *image);
65450-};
65451+} __no_const;
65452
65453 struct snd_hwdep {
65454 struct snd_card *card;
65455diff --git a/include/sound/info.h b/include/sound/info.h
65456index 9ca1a49..aba1728 100644
65457--- a/include/sound/info.h
65458+++ b/include/sound/info.h
65459@@ -44,7 +44,7 @@ struct snd_info_entry_text {
65460 struct snd_info_buffer *buffer);
65461 void (*write)(struct snd_info_entry *entry,
65462 struct snd_info_buffer *buffer);
65463-};
65464+} __no_const;
65465
65466 struct snd_info_entry_ops {
65467 int (*open)(struct snd_info_entry *entry,
65468diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65469index cdca2ab..10bbe05 100644
65470--- a/include/sound/pcm.h
65471+++ b/include/sound/pcm.h
65472@@ -81,6 +81,7 @@ struct snd_pcm_ops {
65473 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65474 int (*ack)(struct snd_pcm_substream *substream);
65475 };
65476+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65477
65478 /*
65479 *
65480diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65481index af1b49e..a5d55a5 100644
65482--- a/include/sound/sb16_csp.h
65483+++ b/include/sound/sb16_csp.h
65484@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65485 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65486 int (*csp_stop) (struct snd_sb_csp * p);
65487 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65488-};
65489+} __no_const;
65490
65491 /*
65492 * CSP private data
65493diff --git a/include/sound/soc.h b/include/sound/soc.h
65494index e063380..e8077d5 100644
65495--- a/include/sound/soc.h
65496+++ b/include/sound/soc.h
65497@@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
65498 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65499 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65500 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65501-};
65502+} __do_const;
65503
65504 struct snd_soc_platform {
65505 const char *name;
65506@@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
65507 struct snd_soc_dai_link *dai_link;
65508 struct mutex pcm_mutex;
65509 enum snd_soc_pcm_subclass pcm_subclass;
65510- struct snd_pcm_ops ops;
65511+ snd_pcm_ops_no_const ops;
65512
65513 unsigned int dev_registered:1;
65514
65515diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65516index fe8590c..aaed363 100644
65517--- a/include/sound/tea575x-tuner.h
65518+++ b/include/sound/tea575x-tuner.h
65519@@ -48,7 +48,7 @@ struct snd_tea575x_ops {
65520
65521 struct snd_tea575x {
65522 struct v4l2_device *v4l2_dev;
65523- struct v4l2_file_operations fops;
65524+ v4l2_file_operations_no_const fops;
65525 struct video_device vd; /* video device */
65526 int radio_nr; /* radio_nr */
65527 bool tea5759; /* 5759 chip is present */
65528diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65529index 5be8937..a8e46e9 100644
65530--- a/include/target/target_core_base.h
65531+++ b/include/target/target_core_base.h
65532@@ -434,7 +434,7 @@ struct t10_reservation_ops {
65533 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65534 int (*t10_pr_register)(struct se_cmd *);
65535 int (*t10_pr_clear)(struct se_cmd *);
65536-};
65537+} __no_const;
65538
65539 struct t10_reservation {
65540 /* Reservation effects all target ports */
65541@@ -758,7 +758,7 @@ struct se_device {
65542 spinlock_t stats_lock;
65543 /* Active commands on this virtual SE device */
65544 atomic_t simple_cmds;
65545- atomic_t dev_ordered_id;
65546+ atomic_unchecked_t dev_ordered_id;
65547 atomic_t dev_ordered_sync;
65548 atomic_t dev_qf_count;
65549 struct se_obj dev_obj;
65550diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65551new file mode 100644
65552index 0000000..2efe49d
65553--- /dev/null
65554+++ b/include/trace/events/fs.h
65555@@ -0,0 +1,53 @@
65556+#undef TRACE_SYSTEM
65557+#define TRACE_SYSTEM fs
65558+
65559+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65560+#define _TRACE_FS_H
65561+
65562+#include <linux/fs.h>
65563+#include <linux/tracepoint.h>
65564+
65565+TRACE_EVENT(do_sys_open,
65566+
65567+ TP_PROTO(char *filename, int flags, int mode),
65568+
65569+ TP_ARGS(filename, flags, mode),
65570+
65571+ TP_STRUCT__entry(
65572+ __string( filename, filename )
65573+ __field( int, flags )
65574+ __field( int, mode )
65575+ ),
65576+
65577+ TP_fast_assign(
65578+ __assign_str(filename, filename);
65579+ __entry->flags = flags;
65580+ __entry->mode = mode;
65581+ ),
65582+
65583+ TP_printk("\"%s\" %x %o",
65584+ __get_str(filename), __entry->flags, __entry->mode)
65585+);
65586+
65587+TRACE_EVENT(open_exec,
65588+
65589+ TP_PROTO(const char *filename),
65590+
65591+ TP_ARGS(filename),
65592+
65593+ TP_STRUCT__entry(
65594+ __string( filename, filename )
65595+ ),
65596+
65597+ TP_fast_assign(
65598+ __assign_str(filename, filename);
65599+ ),
65600+
65601+ TP_printk("\"%s\"",
65602+ __get_str(filename))
65603+);
65604+
65605+#endif /* _TRACE_FS_H */
65606+
65607+/* This part must be outside protection */
65608+#include <trace/define_trace.h>
65609diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65610index 1c09820..7f5ec79 100644
65611--- a/include/trace/events/irq.h
65612+++ b/include/trace/events/irq.h
65613@@ -36,7 +36,7 @@ struct softirq_action;
65614 */
65615 TRACE_EVENT(irq_handler_entry,
65616
65617- TP_PROTO(int irq, struct irqaction *action),
65618+ TP_PROTO(int irq, const struct irqaction *action),
65619
65620 TP_ARGS(irq, action),
65621
65622@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65623 */
65624 TRACE_EVENT(irq_handler_exit,
65625
65626- TP_PROTO(int irq, struct irqaction *action, int ret),
65627+ TP_PROTO(int irq, const struct irqaction *action, int ret),
65628
65629 TP_ARGS(irq, action, ret),
65630
65631diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65632index f9466fa..f4e2b81 100644
65633--- a/include/video/udlfb.h
65634+++ b/include/video/udlfb.h
65635@@ -53,10 +53,10 @@ struct dlfb_data {
65636 u32 pseudo_palette[256];
65637 int blank_mode; /*one of FB_BLANK_ */
65638 /* blit-only rendering path metrics, exposed through sysfs */
65639- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65640- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65641- atomic_t bytes_sent; /* to usb, after compression including overhead */
65642- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65643+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65644+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65645+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65646+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65647 };
65648
65649 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65650diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65651index 0993a22..32ba2fe 100644
65652--- a/include/video/uvesafb.h
65653+++ b/include/video/uvesafb.h
65654@@ -177,6 +177,7 @@ struct uvesafb_par {
65655 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65656 u8 pmi_setpal; /* PMI for palette changes */
65657 u16 *pmi_base; /* protected mode interface location */
65658+ u8 *pmi_code; /* protected mode code location */
65659 void *pmi_start;
65660 void *pmi_pal;
65661 u8 *vbe_state_orig; /*
65662diff --git a/init/Kconfig b/init/Kconfig
65663index af6c7f8..5c188f8 100644
65664--- a/init/Kconfig
65665+++ b/init/Kconfig
65666@@ -850,6 +850,7 @@ endif # CGROUPS
65667
65668 config CHECKPOINT_RESTORE
65669 bool "Checkpoint/restore support" if EXPERT
65670+ depends on !GRKERNSEC
65671 default n
65672 help
65673 Enables additional kernel features in a sake of checkpoint/restore.
65674@@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
65675 # Security modules
65676 depends on SECURITY_TOMOYO = n
65677 depends on SECURITY_APPARMOR = n
65678+ depends on GRKERNSEC = n
65679
65680 config UIDGID_STRICT_TYPE_CHECKS
65681 bool "Require conversions between uid/gids and their internal representation"
65682@@ -1416,7 +1418,7 @@ config SLUB_DEBUG
65683
65684 config COMPAT_BRK
65685 bool "Disable heap randomization"
65686- default y
65687+ default n
65688 help
65689 Randomizing heap placement makes heap exploits harder, but it
65690 also breaks ancient binaries (including anything libc5 based).
65691@@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
65692 config STOP_MACHINE
65693 bool
65694 default y
65695- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65696+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65697 help
65698 Need stop_machine() primitive.
65699
65700diff --git a/init/Makefile b/init/Makefile
65701index 7bc47ee..6da2dc7 100644
65702--- a/init/Makefile
65703+++ b/init/Makefile
65704@@ -2,6 +2,9 @@
65705 # Makefile for the linux kernel.
65706 #
65707
65708+ccflags-y := $(GCC_PLUGINS_CFLAGS)
65709+asflags-y := $(GCC_PLUGINS_AFLAGS)
65710+
65711 obj-y := main.o version.o mounts.o
65712 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65713 obj-y += noinitramfs.o
65714diff --git a/init/do_mounts.c b/init/do_mounts.c
65715index d3f0aee..c9322f5 100644
65716--- a/init/do_mounts.c
65717+++ b/init/do_mounts.c
65718@@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65719 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65720 {
65721 struct super_block *s;
65722- int err = sys_mount(name, "/root", fs, flags, data);
65723+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65724 if (err)
65725 return err;
65726
65727- sys_chdir("/root");
65728+ sys_chdir((const char __force_user *)"/root");
65729 s = current->fs->pwd.dentry->d_sb;
65730 ROOT_DEV = s->s_dev;
65731 printk(KERN_INFO
65732@@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65733 va_start(args, fmt);
65734 vsprintf(buf, fmt, args);
65735 va_end(args);
65736- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65737+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65738 if (fd >= 0) {
65739 sys_ioctl(fd, FDEJECT, 0);
65740 sys_close(fd);
65741 }
65742 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65743- fd = sys_open("/dev/console", O_RDWR, 0);
65744+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65745 if (fd >= 0) {
65746 sys_ioctl(fd, TCGETS, (long)&termios);
65747 termios.c_lflag &= ~ICANON;
65748 sys_ioctl(fd, TCSETSF, (long)&termios);
65749- sys_read(fd, &c, 1);
65750+ sys_read(fd, (char __user *)&c, 1);
65751 termios.c_lflag |= ICANON;
65752 sys_ioctl(fd, TCSETSF, (long)&termios);
65753 sys_close(fd);
65754@@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65755 mount_root();
65756 out:
65757 devtmpfs_mount("dev");
65758- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65759- sys_chroot(".");
65760+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65761+ sys_chroot((const char __force_user *)".");
65762 }
65763diff --git a/init/do_mounts.h b/init/do_mounts.h
65764index f5b978a..69dbfe8 100644
65765--- a/init/do_mounts.h
65766+++ b/init/do_mounts.h
65767@@ -15,15 +15,15 @@ extern int root_mountflags;
65768
65769 static inline int create_dev(char *name, dev_t dev)
65770 {
65771- sys_unlink(name);
65772- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65773+ sys_unlink((char __force_user *)name);
65774+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65775 }
65776
65777 #if BITS_PER_LONG == 32
65778 static inline u32 bstat(char *name)
65779 {
65780 struct stat64 stat;
65781- if (sys_stat64(name, &stat) != 0)
65782+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65783 return 0;
65784 if (!S_ISBLK(stat.st_mode))
65785 return 0;
65786@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65787 static inline u32 bstat(char *name)
65788 {
65789 struct stat stat;
65790- if (sys_newstat(name, &stat) != 0)
65791+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65792 return 0;
65793 if (!S_ISBLK(stat.st_mode))
65794 return 0;
65795diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65796index 135959a2..28a3f43 100644
65797--- a/init/do_mounts_initrd.c
65798+++ b/init/do_mounts_initrd.c
65799@@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65800 create_dev("/dev/root.old", Root_RAM0);
65801 /* mount initrd on rootfs' /root */
65802 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65803- sys_mkdir("/old", 0700);
65804- root_fd = sys_open("/", 0, 0);
65805- old_fd = sys_open("/old", 0, 0);
65806+ sys_mkdir((const char __force_user *)"/old", 0700);
65807+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
65808+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65809 /* move initrd over / and chdir/chroot in initrd root */
65810- sys_chdir("/root");
65811- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65812- sys_chroot(".");
65813+ sys_chdir((const char __force_user *)"/root");
65814+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65815+ sys_chroot((const char __force_user *)".");
65816
65817 /*
65818 * In case that a resume from disk is carried out by linuxrc or one of
65819@@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65820
65821 /* move initrd to rootfs' /old */
65822 sys_fchdir(old_fd);
65823- sys_mount("/", ".", NULL, MS_MOVE, NULL);
65824+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65825 /* switch root and cwd back to / of rootfs */
65826 sys_fchdir(root_fd);
65827- sys_chroot(".");
65828+ sys_chroot((const char __force_user *)".");
65829 sys_close(old_fd);
65830 sys_close(root_fd);
65831
65832 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65833- sys_chdir("/old");
65834+ sys_chdir((const char __force_user *)"/old");
65835 return;
65836 }
65837
65838@@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65839 mount_root();
65840
65841 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65842- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65843+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65844 if (!error)
65845 printk("okay\n");
65846 else {
65847- int fd = sys_open("/dev/root.old", O_RDWR, 0);
65848+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65849 if (error == -ENOENT)
65850 printk("/initrd does not exist. Ignored.\n");
65851 else
65852 printk("failed\n");
65853 printk(KERN_NOTICE "Unmounting old root\n");
65854- sys_umount("/old", MNT_DETACH);
65855+ sys_umount((char __force_user *)"/old", MNT_DETACH);
65856 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65857 if (fd < 0) {
65858 error = fd;
65859@@ -125,11 +125,11 @@ int __init initrd_load(void)
65860 * mounted in the normal path.
65861 */
65862 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65863- sys_unlink("/initrd.image");
65864+ sys_unlink((const char __force_user *)"/initrd.image");
65865 handle_initrd();
65866 return 1;
65867 }
65868 }
65869- sys_unlink("/initrd.image");
65870+ sys_unlink((const char __force_user *)"/initrd.image");
65871 return 0;
65872 }
65873diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65874index 8cb6db5..d729f50 100644
65875--- a/init/do_mounts_md.c
65876+++ b/init/do_mounts_md.c
65877@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65878 partitioned ? "_d" : "", minor,
65879 md_setup_args[ent].device_names);
65880
65881- fd = sys_open(name, 0, 0);
65882+ fd = sys_open((char __force_user *)name, 0, 0);
65883 if (fd < 0) {
65884 printk(KERN_ERR "md: open failed - cannot start "
65885 "array %s\n", name);
65886@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65887 * array without it
65888 */
65889 sys_close(fd);
65890- fd = sys_open(name, 0, 0);
65891+ fd = sys_open((char __force_user *)name, 0, 0);
65892 sys_ioctl(fd, BLKRRPART, 0);
65893 }
65894 sys_close(fd);
65895@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65896
65897 wait_for_device_probe();
65898
65899- fd = sys_open("/dev/md0", 0, 0);
65900+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65901 if (fd >= 0) {
65902 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65903 sys_close(fd);
65904diff --git a/init/init_task.c b/init/init_task.c
65905index 8b2f399..f0797c9 100644
65906--- a/init/init_task.c
65907+++ b/init/init_task.c
65908@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65909 * Initial thread structure. Alignment of this is handled by a special
65910 * linker map entry.
65911 */
65912+#ifdef CONFIG_X86
65913+union thread_union init_thread_union __init_task_data;
65914+#else
65915 union thread_union init_thread_union __init_task_data =
65916 { INIT_THREAD_INFO(init_task) };
65917+#endif
65918diff --git a/init/initramfs.c b/init/initramfs.c
65919index 84c6bf1..8899338 100644
65920--- a/init/initramfs.c
65921+++ b/init/initramfs.c
65922@@ -84,7 +84,7 @@ static void __init free_hash(void)
65923 }
65924 }
65925
65926-static long __init do_utime(char *filename, time_t mtime)
65927+static long __init do_utime(char __force_user *filename, time_t mtime)
65928 {
65929 struct timespec t[2];
65930
65931@@ -119,7 +119,7 @@ static void __init dir_utime(void)
65932 struct dir_entry *de, *tmp;
65933 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65934 list_del(&de->list);
65935- do_utime(de->name, de->mtime);
65936+ do_utime((char __force_user *)de->name, de->mtime);
65937 kfree(de->name);
65938 kfree(de);
65939 }
65940@@ -281,7 +281,7 @@ static int __init maybe_link(void)
65941 if (nlink >= 2) {
65942 char *old = find_link(major, minor, ino, mode, collected);
65943 if (old)
65944- return (sys_link(old, collected) < 0) ? -1 : 1;
65945+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65946 }
65947 return 0;
65948 }
65949@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65950 {
65951 struct stat st;
65952
65953- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65954+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65955 if (S_ISDIR(st.st_mode))
65956- sys_rmdir(path);
65957+ sys_rmdir((char __force_user *)path);
65958 else
65959- sys_unlink(path);
65960+ sys_unlink((char __force_user *)path);
65961 }
65962 }
65963
65964@@ -315,7 +315,7 @@ static int __init do_name(void)
65965 int openflags = O_WRONLY|O_CREAT;
65966 if (ml != 1)
65967 openflags |= O_TRUNC;
65968- wfd = sys_open(collected, openflags, mode);
65969+ wfd = sys_open((char __force_user *)collected, openflags, mode);
65970
65971 if (wfd >= 0) {
65972 sys_fchown(wfd, uid, gid);
65973@@ -327,17 +327,17 @@ static int __init do_name(void)
65974 }
65975 }
65976 } else if (S_ISDIR(mode)) {
65977- sys_mkdir(collected, mode);
65978- sys_chown(collected, uid, gid);
65979- sys_chmod(collected, mode);
65980+ sys_mkdir((char __force_user *)collected, mode);
65981+ sys_chown((char __force_user *)collected, uid, gid);
65982+ sys_chmod((char __force_user *)collected, mode);
65983 dir_add(collected, mtime);
65984 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65985 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65986 if (maybe_link() == 0) {
65987- sys_mknod(collected, mode, rdev);
65988- sys_chown(collected, uid, gid);
65989- sys_chmod(collected, mode);
65990- do_utime(collected, mtime);
65991+ sys_mknod((char __force_user *)collected, mode, rdev);
65992+ sys_chown((char __force_user *)collected, uid, gid);
65993+ sys_chmod((char __force_user *)collected, mode);
65994+ do_utime((char __force_user *)collected, mtime);
65995 }
65996 }
65997 return 0;
65998@@ -346,15 +346,15 @@ static int __init do_name(void)
65999 static int __init do_copy(void)
66000 {
66001 if (count >= body_len) {
66002- sys_write(wfd, victim, body_len);
66003+ sys_write(wfd, (char __force_user *)victim, body_len);
66004 sys_close(wfd);
66005- do_utime(vcollected, mtime);
66006+ do_utime((char __force_user *)vcollected, mtime);
66007 kfree(vcollected);
66008 eat(body_len);
66009 state = SkipIt;
66010 return 0;
66011 } else {
66012- sys_write(wfd, victim, count);
66013+ sys_write(wfd, (char __force_user *)victim, count);
66014 body_len -= count;
66015 eat(count);
66016 return 1;
66017@@ -365,9 +365,9 @@ static int __init do_symlink(void)
66018 {
66019 collected[N_ALIGN(name_len) + body_len] = '\0';
66020 clean_path(collected, 0);
66021- sys_symlink(collected + N_ALIGN(name_len), collected);
66022- sys_lchown(collected, uid, gid);
66023- do_utime(collected, mtime);
66024+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66025+ sys_lchown((char __force_user *)collected, uid, gid);
66026+ do_utime((char __force_user *)collected, mtime);
66027 state = SkipIt;
66028 next_state = Reset;
66029 return 0;
66030diff --git a/init/main.c b/init/main.c
66031index b286730..9ff6135 100644
66032--- a/init/main.c
66033+++ b/init/main.c
66034@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66035 extern void tc_init(void);
66036 #endif
66037
66038+extern void grsecurity_init(void);
66039+
66040 /*
66041 * Debug helper: via this flag we know that we are in 'early bootup code'
66042 * where only the boot processor is running with IRQ disabled. This means
66043@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66044
66045 __setup("reset_devices", set_reset_devices);
66046
66047+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66048+int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66049+static int __init setup_grsec_proc_gid(char *str)
66050+{
66051+ grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66052+ return 1;
66053+}
66054+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66055+#endif
66056+
66057+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66058+extern char pax_enter_kernel_user[];
66059+extern char pax_exit_kernel_user[];
66060+extern pgdval_t clone_pgd_mask;
66061+#endif
66062+
66063+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66064+static int __init setup_pax_nouderef(char *str)
66065+{
66066+#ifdef CONFIG_X86_32
66067+ unsigned int cpu;
66068+ struct desc_struct *gdt;
66069+
66070+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66071+ gdt = get_cpu_gdt_table(cpu);
66072+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66073+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66074+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66075+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66076+ }
66077+ loadsegment(ds, __KERNEL_DS);
66078+ loadsegment(es, __KERNEL_DS);
66079+ loadsegment(ss, __KERNEL_DS);
66080+#else
66081+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66082+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66083+ clone_pgd_mask = ~(pgdval_t)0UL;
66084+#endif
66085+
66086+ return 0;
66087+}
66088+early_param("pax_nouderef", setup_pax_nouderef);
66089+#endif
66090+
66091+#ifdef CONFIG_PAX_SOFTMODE
66092+int pax_softmode;
66093+
66094+static int __init setup_pax_softmode(char *str)
66095+{
66096+ get_option(&str, &pax_softmode);
66097+ return 1;
66098+}
66099+__setup("pax_softmode=", setup_pax_softmode);
66100+#endif
66101+
66102 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66103 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66104 static const char *panic_later, *panic_param;
66105@@ -675,6 +732,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66106 {
66107 int count = preempt_count();
66108 int ret;
66109+ const char *msg1 = "", *msg2 = "";
66110
66111 if (initcall_debug)
66112 ret = do_one_initcall_debug(fn);
66113@@ -687,15 +745,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66114 sprintf(msgbuf, "error code %d ", ret);
66115
66116 if (preempt_count() != count) {
66117- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66118+ msg1 = " preemption imbalance";
66119 preempt_count() = count;
66120 }
66121 if (irqs_disabled()) {
66122- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66123+ msg2 = " disabled interrupts";
66124 local_irq_enable();
66125 }
66126- if (msgbuf[0]) {
66127- printk("initcall %pF returned with %s\n", fn, msgbuf);
66128+ if (msgbuf[0] || *msg1 || *msg2) {
66129+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66130 }
66131
66132 return ret;
66133@@ -749,8 +807,14 @@ static void __init do_initcall_level(int level)
66134 level, level,
66135 &repair_env_string);
66136
66137- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66138+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66139 do_one_initcall(*fn);
66140+
66141+#ifdef CONFIG_PAX_LATENT_ENTROPY
66142+ transfer_latent_entropy();
66143+#endif
66144+
66145+ }
66146 }
66147
66148 static void __init do_initcalls(void)
66149@@ -784,8 +848,14 @@ static void __init do_pre_smp_initcalls(void)
66150 {
66151 initcall_t *fn;
66152
66153- for (fn = __initcall_start; fn < __initcall0_start; fn++)
66154+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66155 do_one_initcall(*fn);
66156+
66157+#ifdef CONFIG_PAX_LATENT_ENTROPY
66158+ transfer_latent_entropy();
66159+#endif
66160+
66161+ }
66162 }
66163
66164 static void run_init_process(const char *init_filename)
66165@@ -867,7 +937,7 @@ static int __init kernel_init(void * unused)
66166 do_basic_setup();
66167
66168 /* Open the /dev/console on the rootfs, this should never fail */
66169- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66170+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66171 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66172
66173 (void) sys_dup(0);
66174@@ -880,11 +950,13 @@ static int __init kernel_init(void * unused)
66175 if (!ramdisk_execute_command)
66176 ramdisk_execute_command = "/init";
66177
66178- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66179+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66180 ramdisk_execute_command = NULL;
66181 prepare_namespace();
66182 }
66183
66184+ grsecurity_init();
66185+
66186 /*
66187 * Ok, we have completed the initial bootup, and
66188 * we're essentially up and running. Get rid of the
66189diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66190index 9a08acc..e65ebe7 100644
66191--- a/ipc/mqueue.c
66192+++ b/ipc/mqueue.c
66193@@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66194 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66195 info->attr.mq_msgsize);
66196
66197+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66198 spin_lock(&mq_lock);
66199 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66200 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66201diff --git a/ipc/msg.c b/ipc/msg.c
66202index 7385de2..a8180e08 100644
66203--- a/ipc/msg.c
66204+++ b/ipc/msg.c
66205@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66206 return security_msg_queue_associate(msq, msgflg);
66207 }
66208
66209+static struct ipc_ops msg_ops = {
66210+ .getnew = newque,
66211+ .associate = msg_security,
66212+ .more_checks = NULL
66213+};
66214+
66215 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66216 {
66217 struct ipc_namespace *ns;
66218- struct ipc_ops msg_ops;
66219 struct ipc_params msg_params;
66220
66221 ns = current->nsproxy->ipc_ns;
66222
66223- msg_ops.getnew = newque;
66224- msg_ops.associate = msg_security;
66225- msg_ops.more_checks = NULL;
66226-
66227 msg_params.key = key;
66228 msg_params.flg = msgflg;
66229
66230diff --git a/ipc/sem.c b/ipc/sem.c
66231index 5215a81..cfc0cac 100644
66232--- a/ipc/sem.c
66233+++ b/ipc/sem.c
66234@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66235 return 0;
66236 }
66237
66238+static struct ipc_ops sem_ops = {
66239+ .getnew = newary,
66240+ .associate = sem_security,
66241+ .more_checks = sem_more_checks
66242+};
66243+
66244 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66245 {
66246 struct ipc_namespace *ns;
66247- struct ipc_ops sem_ops;
66248 struct ipc_params sem_params;
66249
66250 ns = current->nsproxy->ipc_ns;
66251@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66252 if (nsems < 0 || nsems > ns->sc_semmsl)
66253 return -EINVAL;
66254
66255- sem_ops.getnew = newary;
66256- sem_ops.associate = sem_security;
66257- sem_ops.more_checks = sem_more_checks;
66258-
66259 sem_params.key = key;
66260 sem_params.flg = semflg;
66261 sem_params.u.nsems = nsems;
66262diff --git a/ipc/shm.c b/ipc/shm.c
66263index 00faa05..7040960 100644
66264--- a/ipc/shm.c
66265+++ b/ipc/shm.c
66266@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66267 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66268 #endif
66269
66270+#ifdef CONFIG_GRKERNSEC
66271+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66272+ const time_t shm_createtime, const uid_t cuid,
66273+ const int shmid);
66274+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66275+ const time_t shm_createtime);
66276+#endif
66277+
66278 void shm_init_ns(struct ipc_namespace *ns)
66279 {
66280 ns->shm_ctlmax = SHMMAX;
66281@@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66282 shp->shm_lprid = 0;
66283 shp->shm_atim = shp->shm_dtim = 0;
66284 shp->shm_ctim = get_seconds();
66285+#ifdef CONFIG_GRKERNSEC
66286+ {
66287+ struct timespec timeval;
66288+ do_posix_clock_monotonic_gettime(&timeval);
66289+
66290+ shp->shm_createtime = timeval.tv_sec;
66291+ }
66292+#endif
66293 shp->shm_segsz = size;
66294 shp->shm_nattch = 0;
66295 shp->shm_file = file;
66296@@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66297 return 0;
66298 }
66299
66300+static struct ipc_ops shm_ops = {
66301+ .getnew = newseg,
66302+ .associate = shm_security,
66303+ .more_checks = shm_more_checks
66304+};
66305+
66306 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66307 {
66308 struct ipc_namespace *ns;
66309- struct ipc_ops shm_ops;
66310 struct ipc_params shm_params;
66311
66312 ns = current->nsproxy->ipc_ns;
66313
66314- shm_ops.getnew = newseg;
66315- shm_ops.associate = shm_security;
66316- shm_ops.more_checks = shm_more_checks;
66317-
66318 shm_params.key = key;
66319 shm_params.flg = shmflg;
66320 shm_params.u.size = size;
66321@@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66322 f_mode = FMODE_READ | FMODE_WRITE;
66323 }
66324 if (shmflg & SHM_EXEC) {
66325+
66326+#ifdef CONFIG_PAX_MPROTECT
66327+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
66328+ goto out;
66329+#endif
66330+
66331 prot |= PROT_EXEC;
66332 acc_mode |= S_IXUGO;
66333 }
66334@@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66335 if (err)
66336 goto out_unlock;
66337
66338+#ifdef CONFIG_GRKERNSEC
66339+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66340+ shp->shm_perm.cuid, shmid) ||
66341+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66342+ err = -EACCES;
66343+ goto out_unlock;
66344+ }
66345+#endif
66346+
66347 path = shp->shm_file->f_path;
66348 path_get(&path);
66349 shp->shm_nattch++;
66350+#ifdef CONFIG_GRKERNSEC
66351+ shp->shm_lapid = current->pid;
66352+#endif
66353 size = i_size_read(path.dentry->d_inode);
66354 shm_unlock(shp);
66355
66356diff --git a/kernel/acct.c b/kernel/acct.c
66357index 02e6167..54824f7 100644
66358--- a/kernel/acct.c
66359+++ b/kernel/acct.c
66360@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66361 */
66362 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66363 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66364- file->f_op->write(file, (char *)&ac,
66365+ file->f_op->write(file, (char __force_user *)&ac,
66366 sizeof(acct_t), &file->f_pos);
66367 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66368 set_fs(fs);
66369diff --git a/kernel/audit.c b/kernel/audit.c
66370index ea3b7b6..c260d34 100644
66371--- a/kernel/audit.c
66372+++ b/kernel/audit.c
66373@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66374 3) suppressed due to audit_rate_limit
66375 4) suppressed due to audit_backlog_limit
66376 */
66377-static atomic_t audit_lost = ATOMIC_INIT(0);
66378+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66379
66380 /* The netlink socket. */
66381 static struct sock *audit_sock;
66382@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66383 unsigned long now;
66384 int print;
66385
66386- atomic_inc(&audit_lost);
66387+ atomic_inc_unchecked(&audit_lost);
66388
66389 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66390
66391@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66392 printk(KERN_WARNING
66393 "audit: audit_lost=%d audit_rate_limit=%d "
66394 "audit_backlog_limit=%d\n",
66395- atomic_read(&audit_lost),
66396+ atomic_read_unchecked(&audit_lost),
66397 audit_rate_limit,
66398 audit_backlog_limit);
66399 audit_panic(message);
66400@@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66401 status_set.pid = audit_pid;
66402 status_set.rate_limit = audit_rate_limit;
66403 status_set.backlog_limit = audit_backlog_limit;
66404- status_set.lost = atomic_read(&audit_lost);
66405+ status_set.lost = atomic_read_unchecked(&audit_lost);
66406 status_set.backlog = skb_queue_len(&audit_skb_queue);
66407 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66408 &status_set, sizeof(status_set));
66409diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66410index 4b96415..d8c16ee 100644
66411--- a/kernel/auditsc.c
66412+++ b/kernel/auditsc.c
66413@@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66414 }
66415
66416 /* global counter which is incremented every time something logs in */
66417-static atomic_t session_id = ATOMIC_INIT(0);
66418+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66419
66420 /**
66421 * audit_set_loginuid - set current task's audit_context loginuid
66422@@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66423 return -EPERM;
66424 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66425
66426- sessionid = atomic_inc_return(&session_id);
66427+ sessionid = atomic_inc_return_unchecked(&session_id);
66428 if (context && context->in_syscall) {
66429 struct audit_buffer *ab;
66430
66431diff --git a/kernel/capability.c b/kernel/capability.c
66432index 493d972..ea17248 100644
66433--- a/kernel/capability.c
66434+++ b/kernel/capability.c
66435@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66436 * before modification is attempted and the application
66437 * fails.
66438 */
66439+ if (tocopy > ARRAY_SIZE(kdata))
66440+ return -EFAULT;
66441+
66442 if (copy_to_user(dataptr, kdata, tocopy
66443 * sizeof(struct __user_cap_data_struct))) {
66444 return -EFAULT;
66445@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66446 int ret;
66447
66448 rcu_read_lock();
66449- ret = security_capable(__task_cred(t), ns, cap);
66450+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66451+ gr_task_is_capable(t, __task_cred(t), cap);
66452 rcu_read_unlock();
66453
66454- return (ret == 0);
66455+ return ret;
66456 }
66457
66458 /**
66459@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66460 int ret;
66461
66462 rcu_read_lock();
66463- ret = security_capable_noaudit(__task_cred(t), ns, cap);
66464+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66465 rcu_read_unlock();
66466
66467- return (ret == 0);
66468+ return ret;
66469 }
66470
66471 /**
66472@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66473 BUG();
66474 }
66475
66476- if (security_capable(current_cred(), ns, cap) == 0) {
66477+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66478 current->flags |= PF_SUPERPRIV;
66479 return true;
66480 }
66481@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66482 }
66483 EXPORT_SYMBOL(ns_capable);
66484
66485+bool ns_capable_nolog(struct user_namespace *ns, int cap)
66486+{
66487+ if (unlikely(!cap_valid(cap))) {
66488+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66489+ BUG();
66490+ }
66491+
66492+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66493+ current->flags |= PF_SUPERPRIV;
66494+ return true;
66495+ }
66496+ return false;
66497+}
66498+EXPORT_SYMBOL(ns_capable_nolog);
66499+
66500 /**
66501 * capable - Determine if the current task has a superior capability in effect
66502 * @cap: The capability to be tested for
66503@@ -408,6 +427,12 @@ bool capable(int cap)
66504 }
66505 EXPORT_SYMBOL(capable);
66506
66507+bool capable_nolog(int cap)
66508+{
66509+ return ns_capable_nolog(&init_user_ns, cap);
66510+}
66511+EXPORT_SYMBOL(capable_nolog);
66512+
66513 /**
66514 * nsown_capable - Check superior capability to one's own user_ns
66515 * @cap: The capability in question
66516@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66517
66518 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66519 }
66520+
66521+bool inode_capable_nolog(const struct inode *inode, int cap)
66522+{
66523+ struct user_namespace *ns = current_user_ns();
66524+
66525+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66526+}
66527diff --git a/kernel/compat.c b/kernel/compat.c
66528index c28a306..b4d0cf3 100644
66529--- a/kernel/compat.c
66530+++ b/kernel/compat.c
66531@@ -13,6 +13,7 @@
66532
66533 #include <linux/linkage.h>
66534 #include <linux/compat.h>
66535+#include <linux/module.h>
66536 #include <linux/errno.h>
66537 #include <linux/time.h>
66538 #include <linux/signal.h>
66539@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66540 mm_segment_t oldfs;
66541 long ret;
66542
66543- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66544+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66545 oldfs = get_fs();
66546 set_fs(KERNEL_DS);
66547 ret = hrtimer_nanosleep_restart(restart);
66548@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66549 oldfs = get_fs();
66550 set_fs(KERNEL_DS);
66551 ret = hrtimer_nanosleep(&tu,
66552- rmtp ? (struct timespec __user *)&rmt : NULL,
66553+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
66554 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66555 set_fs(oldfs);
66556
66557@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66558 mm_segment_t old_fs = get_fs();
66559
66560 set_fs(KERNEL_DS);
66561- ret = sys_sigpending((old_sigset_t __user *) &s);
66562+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
66563 set_fs(old_fs);
66564 if (ret == 0)
66565 ret = put_user(s, set);
66566@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66567 mm_segment_t old_fs = get_fs();
66568
66569 set_fs(KERNEL_DS);
66570- ret = sys_old_getrlimit(resource, &r);
66571+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66572 set_fs(old_fs);
66573
66574 if (!ret) {
66575@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66576 mm_segment_t old_fs = get_fs();
66577
66578 set_fs(KERNEL_DS);
66579- ret = sys_getrusage(who, (struct rusage __user *) &r);
66580+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66581 set_fs(old_fs);
66582
66583 if (ret)
66584@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66585 set_fs (KERNEL_DS);
66586 ret = sys_wait4(pid,
66587 (stat_addr ?
66588- (unsigned int __user *) &status : NULL),
66589- options, (struct rusage __user *) &r);
66590+ (unsigned int __force_user *) &status : NULL),
66591+ options, (struct rusage __force_user *) &r);
66592 set_fs (old_fs);
66593
66594 if (ret > 0) {
66595@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66596 memset(&info, 0, sizeof(info));
66597
66598 set_fs(KERNEL_DS);
66599- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66600- uru ? (struct rusage __user *)&ru : NULL);
66601+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66602+ uru ? (struct rusage __force_user *)&ru : NULL);
66603 set_fs(old_fs);
66604
66605 if ((ret < 0) || (info.si_signo == 0))
66606@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66607 oldfs = get_fs();
66608 set_fs(KERNEL_DS);
66609 err = sys_timer_settime(timer_id, flags,
66610- (struct itimerspec __user *) &newts,
66611- (struct itimerspec __user *) &oldts);
66612+ (struct itimerspec __force_user *) &newts,
66613+ (struct itimerspec __force_user *) &oldts);
66614 set_fs(oldfs);
66615 if (!err && old && put_compat_itimerspec(old, &oldts))
66616 return -EFAULT;
66617@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66618 oldfs = get_fs();
66619 set_fs(KERNEL_DS);
66620 err = sys_timer_gettime(timer_id,
66621- (struct itimerspec __user *) &ts);
66622+ (struct itimerspec __force_user *) &ts);
66623 set_fs(oldfs);
66624 if (!err && put_compat_itimerspec(setting, &ts))
66625 return -EFAULT;
66626@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66627 oldfs = get_fs();
66628 set_fs(KERNEL_DS);
66629 err = sys_clock_settime(which_clock,
66630- (struct timespec __user *) &ts);
66631+ (struct timespec __force_user *) &ts);
66632 set_fs(oldfs);
66633 return err;
66634 }
66635@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66636 oldfs = get_fs();
66637 set_fs(KERNEL_DS);
66638 err = sys_clock_gettime(which_clock,
66639- (struct timespec __user *) &ts);
66640+ (struct timespec __force_user *) &ts);
66641 set_fs(oldfs);
66642 if (!err && put_compat_timespec(&ts, tp))
66643 return -EFAULT;
66644@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66645
66646 oldfs = get_fs();
66647 set_fs(KERNEL_DS);
66648- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66649+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66650 set_fs(oldfs);
66651
66652 err = compat_put_timex(utp, &txc);
66653@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66654 oldfs = get_fs();
66655 set_fs(KERNEL_DS);
66656 err = sys_clock_getres(which_clock,
66657- (struct timespec __user *) &ts);
66658+ (struct timespec __force_user *) &ts);
66659 set_fs(oldfs);
66660 if (!err && tp && put_compat_timespec(&ts, tp))
66661 return -EFAULT;
66662@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66663 long err;
66664 mm_segment_t oldfs;
66665 struct timespec tu;
66666- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66667+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66668
66669- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66670+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66671 oldfs = get_fs();
66672 set_fs(KERNEL_DS);
66673 err = clock_nanosleep_restart(restart);
66674@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66675 oldfs = get_fs();
66676 set_fs(KERNEL_DS);
66677 err = sys_clock_nanosleep(which_clock, flags,
66678- (struct timespec __user *) &in,
66679- (struct timespec __user *) &out);
66680+ (struct timespec __force_user *) &in,
66681+ (struct timespec __force_user *) &out);
66682 set_fs(oldfs);
66683
66684 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66685diff --git a/kernel/configs.c b/kernel/configs.c
66686index 42e8fa0..9e7406b 100644
66687--- a/kernel/configs.c
66688+++ b/kernel/configs.c
66689@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66690 struct proc_dir_entry *entry;
66691
66692 /* create the current config file */
66693+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66694+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66695+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66696+ &ikconfig_file_ops);
66697+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66698+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66699+ &ikconfig_file_ops);
66700+#endif
66701+#else
66702 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66703 &ikconfig_file_ops);
66704+#endif
66705+
66706 if (!entry)
66707 return -ENOMEM;
66708
66709diff --git a/kernel/cred.c b/kernel/cred.c
66710index de728ac..e3c267c 100644
66711--- a/kernel/cred.c
66712+++ b/kernel/cred.c
66713@@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66714 validate_creds(cred);
66715 alter_cred_subscribers(cred, -1);
66716 put_cred(cred);
66717+
66718+#ifdef CONFIG_GRKERNSEC_SETXID
66719+ cred = (struct cred *) tsk->delayed_cred;
66720+ if (cred != NULL) {
66721+ tsk->delayed_cred = NULL;
66722+ validate_creds(cred);
66723+ alter_cred_subscribers(cred, -1);
66724+ put_cred(cred);
66725+ }
66726+#endif
66727 }
66728
66729 /**
66730@@ -469,7 +479,7 @@ error_put:
66731 * Always returns 0 thus allowing this function to be tail-called at the end
66732 * of, say, sys_setgid().
66733 */
66734-int commit_creds(struct cred *new)
66735+static int __commit_creds(struct cred *new)
66736 {
66737 struct task_struct *task = current;
66738 const struct cred *old = task->real_cred;
66739@@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66740
66741 get_cred(new); /* we will require a ref for the subj creds too */
66742
66743+ gr_set_role_label(task, new->uid, new->gid);
66744+
66745 /* dumpability changes */
66746 if (!uid_eq(old->euid, new->euid) ||
66747 !gid_eq(old->egid, new->egid) ||
66748@@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66749 put_cred(old);
66750 return 0;
66751 }
66752+#ifdef CONFIG_GRKERNSEC_SETXID
66753+extern int set_user(struct cred *new);
66754+
66755+void gr_delayed_cred_worker(void)
66756+{
66757+ const struct cred *new = current->delayed_cred;
66758+ struct cred *ncred;
66759+
66760+ current->delayed_cred = NULL;
66761+
66762+ if (current_uid() && new != NULL) {
66763+ // from doing get_cred on it when queueing this
66764+ put_cred(new);
66765+ return;
66766+ } else if (new == NULL)
66767+ return;
66768+
66769+ ncred = prepare_creds();
66770+ if (!ncred)
66771+ goto die;
66772+ // uids
66773+ ncred->uid = new->uid;
66774+ ncred->euid = new->euid;
66775+ ncred->suid = new->suid;
66776+ ncred->fsuid = new->fsuid;
66777+ // gids
66778+ ncred->gid = new->gid;
66779+ ncred->egid = new->egid;
66780+ ncred->sgid = new->sgid;
66781+ ncred->fsgid = new->fsgid;
66782+ // groups
66783+ if (set_groups(ncred, new->group_info) < 0) {
66784+ abort_creds(ncred);
66785+ goto die;
66786+ }
66787+ // caps
66788+ ncred->securebits = new->securebits;
66789+ ncred->cap_inheritable = new->cap_inheritable;
66790+ ncred->cap_permitted = new->cap_permitted;
66791+ ncred->cap_effective = new->cap_effective;
66792+ ncred->cap_bset = new->cap_bset;
66793+
66794+ if (set_user(ncred)) {
66795+ abort_creds(ncred);
66796+ goto die;
66797+ }
66798+
66799+ // from doing get_cred on it when queueing this
66800+ put_cred(new);
66801+
66802+ __commit_creds(ncred);
66803+ return;
66804+die:
66805+ // from doing get_cred on it when queueing this
66806+ put_cred(new);
66807+ do_group_exit(SIGKILL);
66808+}
66809+#endif
66810+
66811+int commit_creds(struct cred *new)
66812+{
66813+#ifdef CONFIG_GRKERNSEC_SETXID
66814+ int ret;
66815+ int schedule_it = 0;
66816+ struct task_struct *t;
66817+
66818+ /* we won't get called with tasklist_lock held for writing
66819+ and interrupts disabled as the cred struct in that case is
66820+ init_cred
66821+ */
66822+ if (grsec_enable_setxid && !current_is_single_threaded() &&
66823+ !current_uid() && new->uid) {
66824+ schedule_it = 1;
66825+ }
66826+ ret = __commit_creds(new);
66827+ if (schedule_it) {
66828+ rcu_read_lock();
66829+ read_lock(&tasklist_lock);
66830+ for (t = next_thread(current); t != current;
66831+ t = next_thread(t)) {
66832+ if (t->delayed_cred == NULL) {
66833+ t->delayed_cred = get_cred(new);
66834+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66835+ set_tsk_need_resched(t);
66836+ }
66837+ }
66838+ read_unlock(&tasklist_lock);
66839+ rcu_read_unlock();
66840+ }
66841+ return ret;
66842+#else
66843+ return __commit_creds(new);
66844+#endif
66845+}
66846+
66847 EXPORT_SYMBOL(commit_creds);
66848
66849 /**
66850diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66851index 0557f24..1a00d9a 100644
66852--- a/kernel/debug/debug_core.c
66853+++ b/kernel/debug/debug_core.c
66854@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66855 */
66856 static atomic_t masters_in_kgdb;
66857 static atomic_t slaves_in_kgdb;
66858-static atomic_t kgdb_break_tasklet_var;
66859+static atomic_unchecked_t kgdb_break_tasklet_var;
66860 atomic_t kgdb_setting_breakpoint;
66861
66862 struct task_struct *kgdb_usethread;
66863@@ -132,7 +132,7 @@ int kgdb_single_step;
66864 static pid_t kgdb_sstep_pid;
66865
66866 /* to keep track of the CPU which is doing the single stepping*/
66867-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66868+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66869
66870 /*
66871 * If you are debugging a problem where roundup (the collection of
66872@@ -540,7 +540,7 @@ return_normal:
66873 * kernel will only try for the value of sstep_tries before
66874 * giving up and continuing on.
66875 */
66876- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66877+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66878 (kgdb_info[cpu].task &&
66879 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66880 atomic_set(&kgdb_active, -1);
66881@@ -634,8 +634,8 @@ cpu_master_loop:
66882 }
66883
66884 kgdb_restore:
66885- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66886- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66887+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66888+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66889 if (kgdb_info[sstep_cpu].task)
66890 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66891 else
66892@@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66893 static void kgdb_tasklet_bpt(unsigned long ing)
66894 {
66895 kgdb_breakpoint();
66896- atomic_set(&kgdb_break_tasklet_var, 0);
66897+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66898 }
66899
66900 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66901
66902 void kgdb_schedule_breakpoint(void)
66903 {
66904- if (atomic_read(&kgdb_break_tasklet_var) ||
66905+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66906 atomic_read(&kgdb_active) != -1 ||
66907 atomic_read(&kgdb_setting_breakpoint))
66908 return;
66909- atomic_inc(&kgdb_break_tasklet_var);
66910+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
66911 tasklet_schedule(&kgdb_tasklet_breakpoint);
66912 }
66913 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66914diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66915index 31df170..bc98840 100644
66916--- a/kernel/debug/kdb/kdb_main.c
66917+++ b/kernel/debug/kdb/kdb_main.c
66918@@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
66919 list_for_each_entry(mod, kdb_modules, list) {
66920
66921 kdb_printf("%-20s%8u 0x%p ", mod->name,
66922- mod->core_size, (void *)mod);
66923+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
66924 #ifdef CONFIG_MODULE_UNLOAD
66925 kdb_printf("%4ld ", module_refcount(mod));
66926 #endif
66927@@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
66928 kdb_printf(" (Loading)");
66929 else
66930 kdb_printf(" (Live)");
66931- kdb_printf(" 0x%p", mod->module_core);
66932+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66933
66934 #ifdef CONFIG_MODULE_UNLOAD
66935 {
66936diff --git a/kernel/events/core.c b/kernel/events/core.c
66937index 7fee567..8affa2c 100644
66938--- a/kernel/events/core.c
66939+++ b/kernel/events/core.c
66940@@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66941 return 0;
66942 }
66943
66944-static atomic64_t perf_event_id;
66945+static atomic64_unchecked_t perf_event_id;
66946
66947 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66948 enum event_type_t event_type);
66949@@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
66950
66951 static inline u64 perf_event_count(struct perf_event *event)
66952 {
66953- return local64_read(&event->count) + atomic64_read(&event->child_count);
66954+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66955 }
66956
66957 static u64 perf_event_read(struct perf_event *event)
66958@@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66959 mutex_lock(&event->child_mutex);
66960 total += perf_event_read(event);
66961 *enabled += event->total_time_enabled +
66962- atomic64_read(&event->child_total_time_enabled);
66963+ atomic64_read_unchecked(&event->child_total_time_enabled);
66964 *running += event->total_time_running +
66965- atomic64_read(&event->child_total_time_running);
66966+ atomic64_read_unchecked(&event->child_total_time_running);
66967
66968 list_for_each_entry(child, &event->child_list, child_list) {
66969 total += perf_event_read(child);
66970@@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
66971 userpg->offset -= local64_read(&event->hw.prev_count);
66972
66973 userpg->time_enabled = enabled +
66974- atomic64_read(&event->child_total_time_enabled);
66975+ atomic64_read_unchecked(&event->child_total_time_enabled);
66976
66977 userpg->time_running = running +
66978- atomic64_read(&event->child_total_time_running);
66979+ atomic64_read_unchecked(&event->child_total_time_running);
66980
66981 arch_perf_update_userpage(userpg, now);
66982
66983@@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66984 values[n++] = perf_event_count(event);
66985 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66986 values[n++] = enabled +
66987- atomic64_read(&event->child_total_time_enabled);
66988+ atomic64_read_unchecked(&event->child_total_time_enabled);
66989 }
66990 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66991 values[n++] = running +
66992- atomic64_read(&event->child_total_time_running);
66993+ atomic64_read_unchecked(&event->child_total_time_running);
66994 }
66995 if (read_format & PERF_FORMAT_ID)
66996 values[n++] = primary_event_id(event);
66997@@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66998 * need to add enough zero bytes after the string to handle
66999 * the 64bit alignment we do later.
67000 */
67001- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67002+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
67003 if (!buf) {
67004 name = strncpy(tmp, "//enomem", sizeof(tmp));
67005 goto got_name;
67006 }
67007- name = d_path(&file->f_path, buf, PATH_MAX);
67008+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67009 if (IS_ERR(name)) {
67010 name = strncpy(tmp, "//toolong", sizeof(tmp));
67011 goto got_name;
67012@@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67013 event->parent = parent_event;
67014
67015 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67016- event->id = atomic64_inc_return(&perf_event_id);
67017+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
67018
67019 event->state = PERF_EVENT_STATE_INACTIVE;
67020
67021@@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67022 /*
67023 * Add back the child's count to the parent's count:
67024 */
67025- atomic64_add(child_val, &parent_event->child_count);
67026- atomic64_add(child_event->total_time_enabled,
67027+ atomic64_add_unchecked(child_val, &parent_event->child_count);
67028+ atomic64_add_unchecked(child_event->total_time_enabled,
67029 &parent_event->child_total_time_enabled);
67030- atomic64_add(child_event->total_time_running,
67031+ atomic64_add_unchecked(child_event->total_time_running,
67032 &parent_event->child_total_time_running);
67033
67034 /*
67035diff --git a/kernel/exit.c b/kernel/exit.c
67036index f65345f9..9c28dab 100644
67037--- a/kernel/exit.c
67038+++ b/kernel/exit.c
67039@@ -59,6 +59,10 @@
67040 #include <asm/pgtable.h>
67041 #include <asm/mmu_context.h>
67042
67043+#ifdef CONFIG_GRKERNSEC
67044+extern rwlock_t grsec_exec_file_lock;
67045+#endif
67046+
67047 static void exit_mm(struct task_struct * tsk);
67048
67049 static void __unhash_process(struct task_struct *p, bool group_dead)
67050@@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
67051 struct task_struct *leader;
67052 int zap_leader;
67053 repeat:
67054+#ifdef CONFIG_NET
67055+ gr_del_task_from_ip_table(p);
67056+#endif
67057+
67058 /* don't need to get the RCU readlock here - the process is dead and
67059 * can't be modifying its own credentials. But shut RCU-lockdep up */
67060 rcu_read_lock();
67061@@ -394,7 +402,7 @@ int allow_signal(int sig)
67062 * know it'll be handled, so that they don't get converted to
67063 * SIGKILL or just silently dropped.
67064 */
67065- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67066+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67067 recalc_sigpending();
67068 spin_unlock_irq(&current->sighand->siglock);
67069 return 0;
67070@@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
67071 vsnprintf(current->comm, sizeof(current->comm), name, args);
67072 va_end(args);
67073
67074+#ifdef CONFIG_GRKERNSEC
67075+ write_lock(&grsec_exec_file_lock);
67076+ if (current->exec_file) {
67077+ fput(current->exec_file);
67078+ current->exec_file = NULL;
67079+ }
67080+ write_unlock(&grsec_exec_file_lock);
67081+#endif
67082+
67083+ gr_set_kernel_label(current);
67084+
67085 /*
67086 * If we were started as result of loading a module, close all of the
67087 * user space pages. We don't need them, and if we didn't close them
67088@@ -907,6 +926,8 @@ void do_exit(long code)
67089 struct task_struct *tsk = current;
67090 int group_dead;
67091
67092+ set_fs(USER_DS);
67093+
67094 profile_task_exit(tsk);
67095
67096 WARN_ON(blk_needs_flush_plug(tsk));
67097@@ -923,7 +944,6 @@ void do_exit(long code)
67098 * mm_release()->clear_child_tid() from writing to a user-controlled
67099 * kernel address.
67100 */
67101- set_fs(USER_DS);
67102
67103 ptrace_event(PTRACE_EVENT_EXIT, code);
67104
67105@@ -982,6 +1002,9 @@ void do_exit(long code)
67106 tsk->exit_code = code;
67107 taskstats_exit(tsk, group_dead);
67108
67109+ gr_acl_handle_psacct(tsk, code);
67110+ gr_acl_handle_exit();
67111+
67112 exit_mm(tsk);
67113
67114 if (group_dead)
67115@@ -1099,7 +1122,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67116 * Take down every thread in the group. This is called by fatal signals
67117 * as well as by sys_exit_group (below).
67118 */
67119-void
67120+__noreturn void
67121 do_group_exit(int exit_code)
67122 {
67123 struct signal_struct *sig = current->signal;
67124diff --git a/kernel/fork.c b/kernel/fork.c
67125index 2c8857e..288c9c7 100644
67126--- a/kernel/fork.c
67127+++ b/kernel/fork.c
67128@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67129 *stackend = STACK_END_MAGIC; /* for overflow detection */
67130
67131 #ifdef CONFIG_CC_STACKPROTECTOR
67132- tsk->stack_canary = get_random_int();
67133+ tsk->stack_canary = pax_get_random_long();
67134 #endif
67135
67136 /*
67137@@ -343,13 +343,78 @@ free_tsk:
67138 }
67139
67140 #ifdef CONFIG_MMU
67141+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67142+{
67143+ struct vm_area_struct *tmp;
67144+ unsigned long charge;
67145+ struct mempolicy *pol;
67146+ struct file *file;
67147+
67148+ charge = 0;
67149+ if (mpnt->vm_flags & VM_ACCOUNT) {
67150+ unsigned long len = vma_pages(mpnt);
67151+
67152+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67153+ goto fail_nomem;
67154+ charge = len;
67155+ }
67156+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67157+ if (!tmp)
67158+ goto fail_nomem;
67159+ *tmp = *mpnt;
67160+ tmp->vm_mm = mm;
67161+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
67162+ pol = mpol_dup(vma_policy(mpnt));
67163+ if (IS_ERR(pol))
67164+ goto fail_nomem_policy;
67165+ vma_set_policy(tmp, pol);
67166+ if (anon_vma_fork(tmp, mpnt))
67167+ goto fail_nomem_anon_vma_fork;
67168+ tmp->vm_flags &= ~VM_LOCKED;
67169+ tmp->vm_next = tmp->vm_prev = NULL;
67170+ tmp->vm_mirror = NULL;
67171+ file = tmp->vm_file;
67172+ if (file) {
67173+ struct inode *inode = file->f_path.dentry->d_inode;
67174+ struct address_space *mapping = file->f_mapping;
67175+
67176+ get_file(file);
67177+ if (tmp->vm_flags & VM_DENYWRITE)
67178+ atomic_dec(&inode->i_writecount);
67179+ mutex_lock(&mapping->i_mmap_mutex);
67180+ if (tmp->vm_flags & VM_SHARED)
67181+ mapping->i_mmap_writable++;
67182+ flush_dcache_mmap_lock(mapping);
67183+ /* insert tmp into the share list, just after mpnt */
67184+ vma_prio_tree_add(tmp, mpnt);
67185+ flush_dcache_mmap_unlock(mapping);
67186+ mutex_unlock(&mapping->i_mmap_mutex);
67187+ }
67188+
67189+ /*
67190+ * Clear hugetlb-related page reserves for children. This only
67191+ * affects MAP_PRIVATE mappings. Faults generated by the child
67192+ * are not guaranteed to succeed, even if read-only
67193+ */
67194+ if (is_vm_hugetlb_page(tmp))
67195+ reset_vma_resv_huge_pages(tmp);
67196+
67197+ return tmp;
67198+
67199+fail_nomem_anon_vma_fork:
67200+ mpol_put(pol);
67201+fail_nomem_policy:
67202+ kmem_cache_free(vm_area_cachep, tmp);
67203+fail_nomem:
67204+ vm_unacct_memory(charge);
67205+ return NULL;
67206+}
67207+
67208 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67209 {
67210 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67211 struct rb_node **rb_link, *rb_parent;
67212 int retval;
67213- unsigned long charge;
67214- struct mempolicy *pol;
67215
67216 down_write(&oldmm->mmap_sem);
67217 flush_cache_dup_mm(oldmm);
67218@@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67219 mm->locked_vm = 0;
67220 mm->mmap = NULL;
67221 mm->mmap_cache = NULL;
67222- mm->free_area_cache = oldmm->mmap_base;
67223- mm->cached_hole_size = ~0UL;
67224+ mm->free_area_cache = oldmm->free_area_cache;
67225+ mm->cached_hole_size = oldmm->cached_hole_size;
67226 mm->map_count = 0;
67227 cpumask_clear(mm_cpumask(mm));
67228 mm->mm_rb = RB_ROOT;
67229@@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67230
67231 prev = NULL;
67232 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67233- struct file *file;
67234-
67235 if (mpnt->vm_flags & VM_DONTCOPY) {
67236 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67237 -vma_pages(mpnt));
67238 continue;
67239 }
67240- charge = 0;
67241- if (mpnt->vm_flags & VM_ACCOUNT) {
67242- unsigned long len = vma_pages(mpnt);
67243-
67244- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67245- goto fail_nomem;
67246- charge = len;
67247- }
67248- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67249- if (!tmp)
67250- goto fail_nomem;
67251- *tmp = *mpnt;
67252- INIT_LIST_HEAD(&tmp->anon_vma_chain);
67253- pol = mpol_dup(vma_policy(mpnt));
67254- retval = PTR_ERR(pol);
67255- if (IS_ERR(pol))
67256- goto fail_nomem_policy;
67257- vma_set_policy(tmp, pol);
67258- tmp->vm_mm = mm;
67259- if (anon_vma_fork(tmp, mpnt))
67260- goto fail_nomem_anon_vma_fork;
67261- tmp->vm_flags &= ~VM_LOCKED;
67262- tmp->vm_next = tmp->vm_prev = NULL;
67263- file = tmp->vm_file;
67264- if (file) {
67265- struct inode *inode = file->f_path.dentry->d_inode;
67266- struct address_space *mapping = file->f_mapping;
67267-
67268- get_file(file);
67269- if (tmp->vm_flags & VM_DENYWRITE)
67270- atomic_dec(&inode->i_writecount);
67271- mutex_lock(&mapping->i_mmap_mutex);
67272- if (tmp->vm_flags & VM_SHARED)
67273- mapping->i_mmap_writable++;
67274- flush_dcache_mmap_lock(mapping);
67275- /* insert tmp into the share list, just after mpnt */
67276- vma_prio_tree_add(tmp, mpnt);
67277- flush_dcache_mmap_unlock(mapping);
67278- mutex_unlock(&mapping->i_mmap_mutex);
67279+ tmp = dup_vma(mm, oldmm, mpnt);
67280+ if (!tmp) {
67281+ retval = -ENOMEM;
67282+ goto out;
67283 }
67284
67285 /*
67286@@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67287 if (retval)
67288 goto out;
67289
67290- if (file)
67291+ if (tmp->vm_file)
67292 uprobe_mmap(tmp);
67293 }
67294+
67295+#ifdef CONFIG_PAX_SEGMEXEC
67296+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67297+ struct vm_area_struct *mpnt_m;
67298+
67299+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67300+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67301+
67302+ if (!mpnt->vm_mirror)
67303+ continue;
67304+
67305+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67306+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67307+ mpnt->vm_mirror = mpnt_m;
67308+ } else {
67309+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67310+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67311+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67312+ mpnt->vm_mirror->vm_mirror = mpnt;
67313+ }
67314+ }
67315+ BUG_ON(mpnt_m);
67316+ }
67317+#endif
67318+
67319 /* a new mm has just been created */
67320 arch_dup_mmap(oldmm, mm);
67321 retval = 0;
67322@@ -466,14 +519,6 @@ out:
67323 flush_tlb_mm(oldmm);
67324 up_write(&oldmm->mmap_sem);
67325 return retval;
67326-fail_nomem_anon_vma_fork:
67327- mpol_put(pol);
67328-fail_nomem_policy:
67329- kmem_cache_free(vm_area_cachep, tmp);
67330-fail_nomem:
67331- retval = -ENOMEM;
67332- vm_unacct_memory(charge);
67333- goto out;
67334 }
67335
67336 static inline int mm_alloc_pgd(struct mm_struct *mm)
67337@@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67338 return ERR_PTR(err);
67339
67340 mm = get_task_mm(task);
67341- if (mm && mm != current->mm &&
67342- !ptrace_may_access(task, mode)) {
67343+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67344+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67345 mmput(mm);
67346 mm = ERR_PTR(-EACCES);
67347 }
67348@@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67349 spin_unlock(&fs->lock);
67350 return -EAGAIN;
67351 }
67352- fs->users++;
67353+ atomic_inc(&fs->users);
67354 spin_unlock(&fs->lock);
67355 return 0;
67356 }
67357 tsk->fs = copy_fs_struct(fs);
67358 if (!tsk->fs)
67359 return -ENOMEM;
67360+ /* Carry through gr_chroot_dentry and is_chrooted instead
67361+ of recomputing it here. Already copied when the task struct
67362+ is duplicated. This allows pivot_root to not be treated as
67363+ a chroot
67364+ */
67365+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
67366+
67367 return 0;
67368 }
67369
67370@@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67371 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67372 #endif
67373 retval = -EAGAIN;
67374+
67375+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67376+
67377 if (atomic_read(&p->real_cred->user->processes) >=
67378 task_rlimit(p, RLIMIT_NPROC)) {
67379 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67380@@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67381 /* Need tasklist lock for parent etc handling! */
67382 write_lock_irq(&tasklist_lock);
67383
67384+ /* synchronizes with gr_set_acls() */
67385+ gr_copy_label(p);
67386+
67387 /* CLONE_PARENT re-uses the old parent */
67388 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67389 p->real_parent = current->real_parent;
67390@@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
67391 bad_fork_free:
67392 free_task(p);
67393 fork_out:
67394+ gr_log_forkfail(retval);
67395+
67396 return ERR_PTR(retval);
67397 }
67398
67399@@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
67400 if (clone_flags & CLONE_PARENT_SETTID)
67401 put_user(nr, parent_tidptr);
67402
67403+ gr_handle_brute_check();
67404+
67405 if (clone_flags & CLONE_VFORK) {
67406 p->vfork_done = &vfork;
67407 init_completion(&vfork);
67408@@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67409 return 0;
67410
67411 /* don't need lock here; in the worst case we'll do useless copy */
67412- if (fs->users == 1)
67413+ if (atomic_read(&fs->users) == 1)
67414 return 0;
67415
67416 *new_fsp = copy_fs_struct(fs);
67417@@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67418 fs = current->fs;
67419 spin_lock(&fs->lock);
67420 current->fs = new_fs;
67421- if (--fs->users)
67422+ gr_set_chroot_entries(current, &current->fs->root);
67423+ if (atomic_dec_return(&fs->users))
67424 new_fs = NULL;
67425 else
67426 new_fs = fs;
67427diff --git a/kernel/futex.c b/kernel/futex.c
67428index 3717e7b..473c750 100644
67429--- a/kernel/futex.c
67430+++ b/kernel/futex.c
67431@@ -54,6 +54,7 @@
67432 #include <linux/mount.h>
67433 #include <linux/pagemap.h>
67434 #include <linux/syscalls.h>
67435+#include <linux/ptrace.h>
67436 #include <linux/signal.h>
67437 #include <linux/export.h>
67438 #include <linux/magic.h>
67439@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67440 struct page *page, *page_head;
67441 int err, ro = 0;
67442
67443+#ifdef CONFIG_PAX_SEGMEXEC
67444+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67445+ return -EFAULT;
67446+#endif
67447+
67448 /*
67449 * The futex address must be "naturally" aligned.
67450 */
67451@@ -2714,6 +2720,7 @@ static int __init futex_init(void)
67452 {
67453 u32 curval;
67454 int i;
67455+ mm_segment_t oldfs;
67456
67457 /*
67458 * This will fail and we want it. Some arch implementations do
67459@@ -2725,8 +2732,11 @@ static int __init futex_init(void)
67460 * implementation, the non-functional ones will return
67461 * -ENOSYS.
67462 */
67463+ oldfs = get_fs();
67464+ set_fs(USER_DS);
67465 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67466 futex_cmpxchg_enabled = 1;
67467+ set_fs(oldfs);
67468
67469 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67470 plist_head_init(&futex_queues[i].chain);
67471diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67472index 9b22d03..6295b62 100644
67473--- a/kernel/gcov/base.c
67474+++ b/kernel/gcov/base.c
67475@@ -102,11 +102,6 @@ void gcov_enable_events(void)
67476 }
67477
67478 #ifdef CONFIG_MODULES
67479-static inline int within(void *addr, void *start, unsigned long size)
67480-{
67481- return ((addr >= start) && (addr < start + size));
67482-}
67483-
67484 /* Update list and generate events when modules are unloaded. */
67485 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67486 void *data)
67487@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67488 prev = NULL;
67489 /* Remove entries located in module from linked list. */
67490 for (info = gcov_info_head; info; info = info->next) {
67491- if (within(info, mod->module_core, mod->core_size)) {
67492+ if (within_module_core_rw((unsigned long)info, mod)) {
67493 if (prev)
67494 prev->next = info->next;
67495 else
67496diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67497index 6db7a5e..25b6648 100644
67498--- a/kernel/hrtimer.c
67499+++ b/kernel/hrtimer.c
67500@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67501 local_irq_restore(flags);
67502 }
67503
67504-static void run_hrtimer_softirq(struct softirq_action *h)
67505+static void run_hrtimer_softirq(void)
67506 {
67507 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67508
67509diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67510index 4304919..408c4c0 100644
67511--- a/kernel/jump_label.c
67512+++ b/kernel/jump_label.c
67513@@ -13,6 +13,7 @@
67514 #include <linux/sort.h>
67515 #include <linux/err.h>
67516 #include <linux/static_key.h>
67517+#include <linux/mm.h>
67518
67519 #ifdef HAVE_JUMP_LABEL
67520
67521@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67522
67523 size = (((unsigned long)stop - (unsigned long)start)
67524 / sizeof(struct jump_entry));
67525+ pax_open_kernel();
67526 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67527+ pax_close_kernel();
67528 }
67529
67530 static void jump_label_update(struct static_key *key, int enable);
67531@@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67532 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67533 struct jump_entry *iter;
67534
67535+ pax_open_kernel();
67536 for (iter = iter_start; iter < iter_stop; iter++) {
67537 if (within_module_init(iter->code, mod))
67538 iter->code = 0;
67539 }
67540+ pax_close_kernel();
67541 }
67542
67543 static int
67544diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67545index 2169fee..45c017a 100644
67546--- a/kernel/kallsyms.c
67547+++ b/kernel/kallsyms.c
67548@@ -11,6 +11,9 @@
67549 * Changed the compression method from stem compression to "table lookup"
67550 * compression (see scripts/kallsyms.c for a more complete description)
67551 */
67552+#ifdef CONFIG_GRKERNSEC_HIDESYM
67553+#define __INCLUDED_BY_HIDESYM 1
67554+#endif
67555 #include <linux/kallsyms.h>
67556 #include <linux/module.h>
67557 #include <linux/init.h>
67558@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67559
67560 static inline int is_kernel_inittext(unsigned long addr)
67561 {
67562+ if (system_state != SYSTEM_BOOTING)
67563+ return 0;
67564+
67565 if (addr >= (unsigned long)_sinittext
67566 && addr <= (unsigned long)_einittext)
67567 return 1;
67568 return 0;
67569 }
67570
67571+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67572+#ifdef CONFIG_MODULES
67573+static inline int is_module_text(unsigned long addr)
67574+{
67575+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67576+ return 1;
67577+
67578+ addr = ktla_ktva(addr);
67579+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67580+}
67581+#else
67582+static inline int is_module_text(unsigned long addr)
67583+{
67584+ return 0;
67585+}
67586+#endif
67587+#endif
67588+
67589 static inline int is_kernel_text(unsigned long addr)
67590 {
67591 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67592@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67593
67594 static inline int is_kernel(unsigned long addr)
67595 {
67596+
67597+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67598+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
67599+ return 1;
67600+
67601+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67602+#else
67603 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67604+#endif
67605+
67606 return 1;
67607 return in_gate_area_no_mm(addr);
67608 }
67609
67610 static int is_ksym_addr(unsigned long addr)
67611 {
67612+
67613+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67614+ if (is_module_text(addr))
67615+ return 0;
67616+#endif
67617+
67618 if (all_var)
67619 return is_kernel(addr);
67620
67621@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67622
67623 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67624 {
67625- iter->name[0] = '\0';
67626 iter->nameoff = get_symbol_offset(new_pos);
67627 iter->pos = new_pos;
67628 }
67629@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67630 {
67631 struct kallsym_iter *iter = m->private;
67632
67633+#ifdef CONFIG_GRKERNSEC_HIDESYM
67634+ if (current_uid())
67635+ return 0;
67636+#endif
67637+
67638 /* Some debugging symbols have no name. Ignore them. */
67639 if (!iter->name[0])
67640 return 0;
67641@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67642 */
67643 type = iter->exported ? toupper(iter->type) :
67644 tolower(iter->type);
67645+
67646 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67647 type, iter->name, iter->module_name);
67648 } else
67649@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67650 struct kallsym_iter *iter;
67651 int ret;
67652
67653- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67654+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67655 if (!iter)
67656 return -ENOMEM;
67657 reset_iter(iter, 0);
67658diff --git a/kernel/kexec.c b/kernel/kexec.c
67659index 0668d58..591b6fc 100644
67660--- a/kernel/kexec.c
67661+++ b/kernel/kexec.c
67662@@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67663 unsigned long flags)
67664 {
67665 struct compat_kexec_segment in;
67666- struct kexec_segment out, __user *ksegments;
67667+ struct kexec_segment out;
67668+ struct kexec_segment __user *ksegments;
67669 unsigned long i, result;
67670
67671 /* Don't allow clients that don't understand the native
67672diff --git a/kernel/kmod.c b/kernel/kmod.c
67673index 6f99aea..eb6e3a0 100644
67674--- a/kernel/kmod.c
67675+++ b/kernel/kmod.c
67676@@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67677 kfree(info->argv);
67678 }
67679
67680-static int call_modprobe(char *module_name, int wait)
67681+static int call_modprobe(char *module_name, char *module_param, int wait)
67682 {
67683 static char *envp[] = {
67684 "HOME=/",
67685@@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
67686 NULL
67687 };
67688
67689- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67690+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67691 if (!argv)
67692 goto out;
67693
67694@@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
67695 argv[1] = "-q";
67696 argv[2] = "--";
67697 argv[3] = module_name; /* check free_modprobe_argv() */
67698- argv[4] = NULL;
67699+ argv[4] = module_param;
67700+ argv[5] = NULL;
67701
67702 return call_usermodehelper_fns(modprobe_path, argv, envp,
67703 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67704@@ -119,9 +120,8 @@ out:
67705 * If module auto-loading support is disabled then this function
67706 * becomes a no-operation.
67707 */
67708-int __request_module(bool wait, const char *fmt, ...)
67709+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67710 {
67711- va_list args;
67712 char module_name[MODULE_NAME_LEN];
67713 unsigned int max_modprobes;
67714 int ret;
67715@@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
67716 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67717 static int kmod_loop_msg;
67718
67719- va_start(args, fmt);
67720- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67721- va_end(args);
67722+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67723 if (ret >= MODULE_NAME_LEN)
67724 return -ENAMETOOLONG;
67725
67726@@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
67727 if (ret)
67728 return ret;
67729
67730+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67731+ if (!current_uid()) {
67732+ /* hack to workaround consolekit/udisks stupidity */
67733+ read_lock(&tasklist_lock);
67734+ if (!strcmp(current->comm, "mount") &&
67735+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67736+ read_unlock(&tasklist_lock);
67737+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67738+ return -EPERM;
67739+ }
67740+ read_unlock(&tasklist_lock);
67741+ }
67742+#endif
67743+
67744 /* If modprobe needs a service that is in a module, we get a recursive
67745 * loop. Limit the number of running kmod threads to max_threads/2 or
67746 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67747@@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
67748
67749 trace_module_request(module_name, wait, _RET_IP_);
67750
67751- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67752+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67753
67754 atomic_dec(&kmod_concurrent);
67755 return ret;
67756 }
67757+
67758+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67759+{
67760+ va_list args;
67761+ int ret;
67762+
67763+ va_start(args, fmt);
67764+ ret = ____request_module(wait, module_param, fmt, args);
67765+ va_end(args);
67766+
67767+ return ret;
67768+}
67769+
67770+int __request_module(bool wait, const char *fmt, ...)
67771+{
67772+ va_list args;
67773+ int ret;
67774+
67775+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67776+ if (current_uid()) {
67777+ char module_param[MODULE_NAME_LEN];
67778+
67779+ memset(module_param, 0, sizeof(module_param));
67780+
67781+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67782+
67783+ va_start(args, fmt);
67784+ ret = ____request_module(wait, module_param, fmt, args);
67785+ va_end(args);
67786+
67787+ return ret;
67788+ }
67789+#endif
67790+
67791+ va_start(args, fmt);
67792+ ret = ____request_module(wait, NULL, fmt, args);
67793+ va_end(args);
67794+
67795+ return ret;
67796+}
67797+
67798 EXPORT_SYMBOL(__request_module);
67799 #endif /* CONFIG_MODULES */
67800
67801@@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
67802 *
67803 * Thus the __user pointer cast is valid here.
67804 */
67805- sys_wait4(pid, (int __user *)&ret, 0, NULL);
67806+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67807
67808 /*
67809 * If ret is 0, either ____call_usermodehelper failed and the
67810diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67811index c62b854..cb67968 100644
67812--- a/kernel/kprobes.c
67813+++ b/kernel/kprobes.c
67814@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67815 * kernel image and loaded module images reside. This is required
67816 * so x86_64 can correctly handle the %rip-relative fixups.
67817 */
67818- kip->insns = module_alloc(PAGE_SIZE);
67819+ kip->insns = module_alloc_exec(PAGE_SIZE);
67820 if (!kip->insns) {
67821 kfree(kip);
67822 return NULL;
67823@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67824 */
67825 if (!list_is_singular(&kip->list)) {
67826 list_del(&kip->list);
67827- module_free(NULL, kip->insns);
67828+ module_free_exec(NULL, kip->insns);
67829 kfree(kip);
67830 }
67831 return 1;
67832@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67833 {
67834 int i, err = 0;
67835 unsigned long offset = 0, size = 0;
67836- char *modname, namebuf[128];
67837+ char *modname, namebuf[KSYM_NAME_LEN];
67838 const char *symbol_name;
67839 void *addr;
67840 struct kprobe_blackpoint *kb;
67841@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67842 const char *sym = NULL;
67843 unsigned int i = *(loff_t *) v;
67844 unsigned long offset = 0;
67845- char *modname, namebuf[128];
67846+ char *modname, namebuf[KSYM_NAME_LEN];
67847
67848 head = &kprobe_table[i];
67849 preempt_disable();
67850diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67851index 4e316e1..5501eef 100644
67852--- a/kernel/ksysfs.c
67853+++ b/kernel/ksysfs.c
67854@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67855 {
67856 if (count+1 > UEVENT_HELPER_PATH_LEN)
67857 return -ENOENT;
67858+ if (!capable(CAP_SYS_ADMIN))
67859+ return -EPERM;
67860 memcpy(uevent_helper, buf, count);
67861 uevent_helper[count] = '\0';
67862 if (count && uevent_helper[count-1] == '\n')
67863diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67864index ea9ee45..67ebc8f 100644
67865--- a/kernel/lockdep.c
67866+++ b/kernel/lockdep.c
67867@@ -590,6 +590,10 @@ static int static_obj(void *obj)
67868 end = (unsigned long) &_end,
67869 addr = (unsigned long) obj;
67870
67871+#ifdef CONFIG_PAX_KERNEXEC
67872+ start = ktla_ktva(start);
67873+#endif
67874+
67875 /*
67876 * static variable?
67877 */
67878@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67879 if (!static_obj(lock->key)) {
67880 debug_locks_off();
67881 printk("INFO: trying to register non-static key.\n");
67882+ printk("lock:%pS key:%pS.\n", lock, lock->key);
67883 printk("the code is fine but needs lockdep annotation.\n");
67884 printk("turning off the locking correctness validator.\n");
67885 dump_stack();
67886@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67887 if (!class)
67888 return 0;
67889 }
67890- atomic_inc((atomic_t *)&class->ops);
67891+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67892 if (very_verbose(class)) {
67893 printk("\nacquire class [%p] %s", class->key, class->name);
67894 if (class->name_version > 1)
67895diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67896index 91c32a0..b2c71c5 100644
67897--- a/kernel/lockdep_proc.c
67898+++ b/kernel/lockdep_proc.c
67899@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67900
67901 static void print_name(struct seq_file *m, struct lock_class *class)
67902 {
67903- char str[128];
67904+ char str[KSYM_NAME_LEN];
67905 const char *name = class->name;
67906
67907 if (!name) {
67908diff --git a/kernel/module.c b/kernel/module.c
67909index 4edbd9c..165e780 100644
67910--- a/kernel/module.c
67911+++ b/kernel/module.c
67912@@ -58,6 +58,7 @@
67913 #include <linux/jump_label.h>
67914 #include <linux/pfn.h>
67915 #include <linux/bsearch.h>
67916+#include <linux/grsecurity.h>
67917
67918 #define CREATE_TRACE_POINTS
67919 #include <trace/events/module.h>
67920@@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67921
67922 /* Bounds of module allocation, for speeding __module_address.
67923 * Protected by module_mutex. */
67924-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67925+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67926+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67927
67928 int register_module_notifier(struct notifier_block * nb)
67929 {
67930@@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67931 return true;
67932
67933 list_for_each_entry_rcu(mod, &modules, list) {
67934- struct symsearch arr[] = {
67935+ struct symsearch modarr[] = {
67936 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67937 NOT_GPL_ONLY, false },
67938 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67939@@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67940 #endif
67941 };
67942
67943- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67944+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67945 return true;
67946 }
67947 return false;
67948@@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67949 static int percpu_modalloc(struct module *mod,
67950 unsigned long size, unsigned long align)
67951 {
67952- if (align > PAGE_SIZE) {
67953+ if (align-1 >= PAGE_SIZE) {
67954 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67955 mod->name, align, PAGE_SIZE);
67956 align = PAGE_SIZE;
67957@@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
67958 static ssize_t show_coresize(struct module_attribute *mattr,
67959 struct module_kobject *mk, char *buffer)
67960 {
67961- return sprintf(buffer, "%u\n", mk->mod->core_size);
67962+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
67963 }
67964
67965 static struct module_attribute modinfo_coresize =
67966@@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
67967 static ssize_t show_initsize(struct module_attribute *mattr,
67968 struct module_kobject *mk, char *buffer)
67969 {
67970- return sprintf(buffer, "%u\n", mk->mod->init_size);
67971+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
67972 }
67973
67974 static struct module_attribute modinfo_initsize =
67975@@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
67976 */
67977 #ifdef CONFIG_SYSFS
67978
67979-#ifdef CONFIG_KALLSYMS
67980+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67981 static inline bool sect_empty(const Elf_Shdr *sect)
67982 {
67983 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
67984@@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
67985
67986 static void unset_module_core_ro_nx(struct module *mod)
67987 {
67988- set_page_attributes(mod->module_core + mod->core_text_size,
67989- mod->module_core + mod->core_size,
67990+ set_page_attributes(mod->module_core_rw,
67991+ mod->module_core_rw + mod->core_size_rw,
67992 set_memory_x);
67993- set_page_attributes(mod->module_core,
67994- mod->module_core + mod->core_ro_size,
67995+ set_page_attributes(mod->module_core_rx,
67996+ mod->module_core_rx + mod->core_size_rx,
67997 set_memory_rw);
67998 }
67999
68000 static void unset_module_init_ro_nx(struct module *mod)
68001 {
68002- set_page_attributes(mod->module_init + mod->init_text_size,
68003- mod->module_init + mod->init_size,
68004+ set_page_attributes(mod->module_init_rw,
68005+ mod->module_init_rw + mod->init_size_rw,
68006 set_memory_x);
68007- set_page_attributes(mod->module_init,
68008- mod->module_init + mod->init_ro_size,
68009+ set_page_attributes(mod->module_init_rx,
68010+ mod->module_init_rx + mod->init_size_rx,
68011 set_memory_rw);
68012 }
68013
68014@@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68015
68016 mutex_lock(&module_mutex);
68017 list_for_each_entry_rcu(mod, &modules, list) {
68018- if ((mod->module_core) && (mod->core_text_size)) {
68019- set_page_attributes(mod->module_core,
68020- mod->module_core + mod->core_text_size,
68021+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
68022+ set_page_attributes(mod->module_core_rx,
68023+ mod->module_core_rx + mod->core_size_rx,
68024 set_memory_rw);
68025 }
68026- if ((mod->module_init) && (mod->init_text_size)) {
68027- set_page_attributes(mod->module_init,
68028- mod->module_init + mod->init_text_size,
68029+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
68030+ set_page_attributes(mod->module_init_rx,
68031+ mod->module_init_rx + mod->init_size_rx,
68032 set_memory_rw);
68033 }
68034 }
68035@@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68036
68037 mutex_lock(&module_mutex);
68038 list_for_each_entry_rcu(mod, &modules, list) {
68039- if ((mod->module_core) && (mod->core_text_size)) {
68040- set_page_attributes(mod->module_core,
68041- mod->module_core + mod->core_text_size,
68042+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
68043+ set_page_attributes(mod->module_core_rx,
68044+ mod->module_core_rx + mod->core_size_rx,
68045 set_memory_ro);
68046 }
68047- if ((mod->module_init) && (mod->init_text_size)) {
68048- set_page_attributes(mod->module_init,
68049- mod->module_init + mod->init_text_size,
68050+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
68051+ set_page_attributes(mod->module_init_rx,
68052+ mod->module_init_rx + mod->init_size_rx,
68053 set_memory_ro);
68054 }
68055 }
68056@@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68057
68058 /* This may be NULL, but that's OK */
68059 unset_module_init_ro_nx(mod);
68060- module_free(mod, mod->module_init);
68061+ module_free(mod, mod->module_init_rw);
68062+ module_free_exec(mod, mod->module_init_rx);
68063 kfree(mod->args);
68064 percpu_modfree(mod);
68065
68066 /* Free lock-classes: */
68067- lockdep_free_key_range(mod->module_core, mod->core_size);
68068+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68069+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68070
68071 /* Finally, free the core (containing the module structure) */
68072 unset_module_core_ro_nx(mod);
68073- module_free(mod, mod->module_core);
68074+ module_free_exec(mod, mod->module_core_rx);
68075+ module_free(mod, mod->module_core_rw);
68076
68077 #ifdef CONFIG_MPU
68078 update_protections(current->mm);
68079@@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68080 int ret = 0;
68081 const struct kernel_symbol *ksym;
68082
68083+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68084+ int is_fs_load = 0;
68085+ int register_filesystem_found = 0;
68086+ char *p;
68087+
68088+ p = strstr(mod->args, "grsec_modharden_fs");
68089+ if (p) {
68090+ char *endptr = p + strlen("grsec_modharden_fs");
68091+ /* copy \0 as well */
68092+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68093+ is_fs_load = 1;
68094+ }
68095+#endif
68096+
68097 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68098 const char *name = info->strtab + sym[i].st_name;
68099
68100+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68101+ /* it's a real shame this will never get ripped and copied
68102+ upstream! ;(
68103+ */
68104+ if (is_fs_load && !strcmp(name, "register_filesystem"))
68105+ register_filesystem_found = 1;
68106+#endif
68107+
68108 switch (sym[i].st_shndx) {
68109 case SHN_COMMON:
68110 /* We compiled with -fno-common. These are not
68111@@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68112 ksym = resolve_symbol_wait(mod, info, name);
68113 /* Ok if resolved. */
68114 if (ksym && !IS_ERR(ksym)) {
68115+ pax_open_kernel();
68116 sym[i].st_value = ksym->value;
68117+ pax_close_kernel();
68118 break;
68119 }
68120
68121@@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68122 secbase = (unsigned long)mod_percpu(mod);
68123 else
68124 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68125+ pax_open_kernel();
68126 sym[i].st_value += secbase;
68127+ pax_close_kernel();
68128 break;
68129 }
68130 }
68131
68132+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68133+ if (is_fs_load && !register_filesystem_found) {
68134+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68135+ ret = -EPERM;
68136+ }
68137+#endif
68138+
68139 return ret;
68140 }
68141
68142@@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68143 || s->sh_entsize != ~0UL
68144 || strstarts(sname, ".init"))
68145 continue;
68146- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68147+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68148+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68149+ else
68150+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68151 pr_debug("\t%s\n", sname);
68152 }
68153- switch (m) {
68154- case 0: /* executable */
68155- mod->core_size = debug_align(mod->core_size);
68156- mod->core_text_size = mod->core_size;
68157- break;
68158- case 1: /* RO: text and ro-data */
68159- mod->core_size = debug_align(mod->core_size);
68160- mod->core_ro_size = mod->core_size;
68161- break;
68162- case 3: /* whole core */
68163- mod->core_size = debug_align(mod->core_size);
68164- break;
68165- }
68166 }
68167
68168 pr_debug("Init section allocation order:\n");
68169@@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68170 || s->sh_entsize != ~0UL
68171 || !strstarts(sname, ".init"))
68172 continue;
68173- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68174- | INIT_OFFSET_MASK);
68175+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68176+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68177+ else
68178+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68179+ s->sh_entsize |= INIT_OFFSET_MASK;
68180 pr_debug("\t%s\n", sname);
68181 }
68182- switch (m) {
68183- case 0: /* executable */
68184- mod->init_size = debug_align(mod->init_size);
68185- mod->init_text_size = mod->init_size;
68186- break;
68187- case 1: /* RO: text and ro-data */
68188- mod->init_size = debug_align(mod->init_size);
68189- mod->init_ro_size = mod->init_size;
68190- break;
68191- case 3: /* whole init */
68192- mod->init_size = debug_align(mod->init_size);
68193- break;
68194- }
68195 }
68196 }
68197
68198@@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68199
68200 /* Put symbol section at end of init part of module. */
68201 symsect->sh_flags |= SHF_ALLOC;
68202- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68203+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68204 info->index.sym) | INIT_OFFSET_MASK;
68205 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68206
68207@@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68208 }
68209
68210 /* Append room for core symbols at end of core part. */
68211- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68212- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68213- mod->core_size += strtab_size;
68214+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68215+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68216+ mod->core_size_rx += strtab_size;
68217
68218 /* Put string table section at end of init part of module. */
68219 strsect->sh_flags |= SHF_ALLOC;
68220- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68221+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68222 info->index.str) | INIT_OFFSET_MASK;
68223 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68224 }
68225@@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68226 /* Make sure we get permanent strtab: don't use info->strtab. */
68227 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68228
68229+ pax_open_kernel();
68230+
68231 /* Set types up while we still have access to sections. */
68232 for (i = 0; i < mod->num_symtab; i++)
68233 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68234
68235- mod->core_symtab = dst = mod->module_core + info->symoffs;
68236- mod->core_strtab = s = mod->module_core + info->stroffs;
68237+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68238+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68239 src = mod->symtab;
68240 *dst = *src;
68241 *s++ = 0;
68242@@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68243 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68244 }
68245 mod->core_num_syms = ndst;
68246+
68247+ pax_close_kernel();
68248 }
68249 #else
68250 static inline void layout_symtab(struct module *mod, struct load_info *info)
68251@@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
68252 return size == 0 ? NULL : vmalloc_exec(size);
68253 }
68254
68255-static void *module_alloc_update_bounds(unsigned long size)
68256+static void *module_alloc_update_bounds_rw(unsigned long size)
68257 {
68258 void *ret = module_alloc(size);
68259
68260 if (ret) {
68261 mutex_lock(&module_mutex);
68262 /* Update module bounds. */
68263- if ((unsigned long)ret < module_addr_min)
68264- module_addr_min = (unsigned long)ret;
68265- if ((unsigned long)ret + size > module_addr_max)
68266- module_addr_max = (unsigned long)ret + size;
68267+ if ((unsigned long)ret < module_addr_min_rw)
68268+ module_addr_min_rw = (unsigned long)ret;
68269+ if ((unsigned long)ret + size > module_addr_max_rw)
68270+ module_addr_max_rw = (unsigned long)ret + size;
68271+ mutex_unlock(&module_mutex);
68272+ }
68273+ return ret;
68274+}
68275+
68276+static void *module_alloc_update_bounds_rx(unsigned long size)
68277+{
68278+ void *ret = module_alloc_exec(size);
68279+
68280+ if (ret) {
68281+ mutex_lock(&module_mutex);
68282+ /* Update module bounds. */
68283+ if ((unsigned long)ret < module_addr_min_rx)
68284+ module_addr_min_rx = (unsigned long)ret;
68285+ if ((unsigned long)ret + size > module_addr_max_rx)
68286+ module_addr_max_rx = (unsigned long)ret + size;
68287 mutex_unlock(&module_mutex);
68288 }
68289 return ret;
68290@@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
68291 static int check_modinfo(struct module *mod, struct load_info *info)
68292 {
68293 const char *modmagic = get_modinfo(info, "vermagic");
68294+ const char *license = get_modinfo(info, "license");
68295 int err;
68296
68297+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68298+ if (!license || !license_is_gpl_compatible(license))
68299+ return -ENOEXEC;
68300+#endif
68301+
68302 /* This is allowed: modprobe --force will invalidate it. */
68303 if (!modmagic) {
68304 err = try_to_force_load(mod, "bad vermagic");
68305@@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68306 }
68307
68308 /* Set up license info based on the info section */
68309- set_license(mod, get_modinfo(info, "license"));
68310+ set_license(mod, license);
68311
68312 return 0;
68313 }
68314@@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
68315 void *ptr;
68316
68317 /* Do the allocs. */
68318- ptr = module_alloc_update_bounds(mod->core_size);
68319+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68320 /*
68321 * The pointer to this block is stored in the module structure
68322 * which is inside the block. Just mark it as not being a
68323@@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
68324 if (!ptr)
68325 return -ENOMEM;
68326
68327- memset(ptr, 0, mod->core_size);
68328- mod->module_core = ptr;
68329+ memset(ptr, 0, mod->core_size_rw);
68330+ mod->module_core_rw = ptr;
68331
68332- ptr = module_alloc_update_bounds(mod->init_size);
68333+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68334 /*
68335 * The pointer to this block is stored in the module structure
68336 * which is inside the block. This block doesn't need to be
68337 * scanned as it contains data and code that will be freed
68338 * after the module is initialized.
68339 */
68340- kmemleak_ignore(ptr);
68341- if (!ptr && mod->init_size) {
68342- module_free(mod, mod->module_core);
68343+ kmemleak_not_leak(ptr);
68344+ if (!ptr && mod->init_size_rw) {
68345+ module_free(mod, mod->module_core_rw);
68346 return -ENOMEM;
68347 }
68348- memset(ptr, 0, mod->init_size);
68349- mod->module_init = ptr;
68350+ memset(ptr, 0, mod->init_size_rw);
68351+ mod->module_init_rw = ptr;
68352+
68353+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68354+ kmemleak_not_leak(ptr);
68355+ if (!ptr) {
68356+ module_free(mod, mod->module_init_rw);
68357+ module_free(mod, mod->module_core_rw);
68358+ return -ENOMEM;
68359+ }
68360+
68361+ pax_open_kernel();
68362+ memset(ptr, 0, mod->core_size_rx);
68363+ pax_close_kernel();
68364+ mod->module_core_rx = ptr;
68365+
68366+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68367+ kmemleak_not_leak(ptr);
68368+ if (!ptr && mod->init_size_rx) {
68369+ module_free_exec(mod, mod->module_core_rx);
68370+ module_free(mod, mod->module_init_rw);
68371+ module_free(mod, mod->module_core_rw);
68372+ return -ENOMEM;
68373+ }
68374+
68375+ pax_open_kernel();
68376+ memset(ptr, 0, mod->init_size_rx);
68377+ pax_close_kernel();
68378+ mod->module_init_rx = ptr;
68379
68380 /* Transfer each section which specifies SHF_ALLOC */
68381 pr_debug("final section addresses:\n");
68382@@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
68383 if (!(shdr->sh_flags & SHF_ALLOC))
68384 continue;
68385
68386- if (shdr->sh_entsize & INIT_OFFSET_MASK)
68387- dest = mod->module_init
68388- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68389- else
68390- dest = mod->module_core + shdr->sh_entsize;
68391+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68392+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68393+ dest = mod->module_init_rw
68394+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68395+ else
68396+ dest = mod->module_init_rx
68397+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68398+ } else {
68399+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68400+ dest = mod->module_core_rw + shdr->sh_entsize;
68401+ else
68402+ dest = mod->module_core_rx + shdr->sh_entsize;
68403+ }
68404+
68405+ if (shdr->sh_type != SHT_NOBITS) {
68406+
68407+#ifdef CONFIG_PAX_KERNEXEC
68408+#ifdef CONFIG_X86_64
68409+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68410+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68411+#endif
68412+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68413+ pax_open_kernel();
68414+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68415+ pax_close_kernel();
68416+ } else
68417+#endif
68418
68419- if (shdr->sh_type != SHT_NOBITS)
68420 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68421+ }
68422 /* Update sh_addr to point to copy in image. */
68423- shdr->sh_addr = (unsigned long)dest;
68424+
68425+#ifdef CONFIG_PAX_KERNEXEC
68426+ if (shdr->sh_flags & SHF_EXECINSTR)
68427+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
68428+ else
68429+#endif
68430+
68431+ shdr->sh_addr = (unsigned long)dest;
68432 pr_debug("\t0x%lx %s\n",
68433 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68434 }
68435@@ -2759,12 +2859,12 @@ static void flush_module_icache(const struct module *mod)
68436 * Do it before processing of module parameters, so the module
68437 * can provide parameter accessor functions of its own.
68438 */
68439- if (mod->module_init)
68440- flush_icache_range((unsigned long)mod->module_init,
68441- (unsigned long)mod->module_init
68442- + mod->init_size);
68443- flush_icache_range((unsigned long)mod->module_core,
68444- (unsigned long)mod->module_core + mod->core_size);
68445+ if (mod->module_init_rx)
68446+ flush_icache_range((unsigned long)mod->module_init_rx,
68447+ (unsigned long)mod->module_init_rx
68448+ + mod->init_size_rx);
68449+ flush_icache_range((unsigned long)mod->module_core_rx,
68450+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
68451
68452 set_fs(old_fs);
68453 }
68454@@ -2834,8 +2934,10 @@ out:
68455 static void module_deallocate(struct module *mod, struct load_info *info)
68456 {
68457 percpu_modfree(mod);
68458- module_free(mod, mod->module_init);
68459- module_free(mod, mod->module_core);
68460+ module_free_exec(mod, mod->module_init_rx);
68461+ module_free_exec(mod, mod->module_core_rx);
68462+ module_free(mod, mod->module_init_rw);
68463+ module_free(mod, mod->module_core_rw);
68464 }
68465
68466 int __weak module_finalize(const Elf_Ehdr *hdr,
68467@@ -2848,7 +2950,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68468 static int post_relocation(struct module *mod, const struct load_info *info)
68469 {
68470 /* Sort exception table now relocations are done. */
68471+ pax_open_kernel();
68472 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68473+ pax_close_kernel();
68474
68475 /* Copy relocated percpu area over. */
68476 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68477@@ -2899,9 +3003,38 @@ static struct module *load_module(void __user *umod,
68478 if (err)
68479 goto free_unload;
68480
68481+ /* Now copy in args */
68482+ mod->args = strndup_user(uargs, ~0UL >> 1);
68483+ if (IS_ERR(mod->args)) {
68484+ err = PTR_ERR(mod->args);
68485+ goto free_unload;
68486+ }
68487+
68488 /* Set up MODINFO_ATTR fields */
68489 setup_modinfo(mod, &info);
68490
68491+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68492+ {
68493+ char *p, *p2;
68494+
68495+ if (strstr(mod->args, "grsec_modharden_netdev")) {
68496+ 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);
68497+ err = -EPERM;
68498+ goto free_modinfo;
68499+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68500+ p += strlen("grsec_modharden_normal");
68501+ p2 = strstr(p, "_");
68502+ if (p2) {
68503+ *p2 = '\0';
68504+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68505+ *p2 = '_';
68506+ }
68507+ err = -EPERM;
68508+ goto free_modinfo;
68509+ }
68510+ }
68511+#endif
68512+
68513 /* Fix up syms, so that st_value is a pointer to location. */
68514 err = simplify_symbols(mod, &info);
68515 if (err < 0)
68516@@ -2917,13 +3050,6 @@ static struct module *load_module(void __user *umod,
68517
68518 flush_module_icache(mod);
68519
68520- /* Now copy in args */
68521- mod->args = strndup_user(uargs, ~0UL >> 1);
68522- if (IS_ERR(mod->args)) {
68523- err = PTR_ERR(mod->args);
68524- goto free_arch_cleanup;
68525- }
68526-
68527 /* Mark state as coming so strong_try_module_get() ignores us. */
68528 mod->state = MODULE_STATE_COMING;
68529
68530@@ -2981,11 +3107,10 @@ static struct module *load_module(void __user *umod,
68531 unlock:
68532 mutex_unlock(&module_mutex);
68533 synchronize_sched();
68534- kfree(mod->args);
68535- free_arch_cleanup:
68536 module_arch_cleanup(mod);
68537 free_modinfo:
68538 free_modinfo(mod);
68539+ kfree(mod->args);
68540 free_unload:
68541 module_unload_free(mod);
68542 free_module:
68543@@ -3026,16 +3151,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68544 MODULE_STATE_COMING, mod);
68545
68546 /* Set RO and NX regions for core */
68547- set_section_ro_nx(mod->module_core,
68548- mod->core_text_size,
68549- mod->core_ro_size,
68550- mod->core_size);
68551+ set_section_ro_nx(mod->module_core_rx,
68552+ mod->core_size_rx,
68553+ mod->core_size_rx,
68554+ mod->core_size_rx);
68555
68556 /* Set RO and NX regions for init */
68557- set_section_ro_nx(mod->module_init,
68558- mod->init_text_size,
68559- mod->init_ro_size,
68560- mod->init_size);
68561+ set_section_ro_nx(mod->module_init_rx,
68562+ mod->init_size_rx,
68563+ mod->init_size_rx,
68564+ mod->init_size_rx);
68565
68566 do_mod_ctors(mod);
68567 /* Start the module */
68568@@ -3081,11 +3206,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68569 mod->strtab = mod->core_strtab;
68570 #endif
68571 unset_module_init_ro_nx(mod);
68572- module_free(mod, mod->module_init);
68573- mod->module_init = NULL;
68574- mod->init_size = 0;
68575- mod->init_ro_size = 0;
68576- mod->init_text_size = 0;
68577+ module_free(mod, mod->module_init_rw);
68578+ module_free_exec(mod, mod->module_init_rx);
68579+ mod->module_init_rw = NULL;
68580+ mod->module_init_rx = NULL;
68581+ mod->init_size_rw = 0;
68582+ mod->init_size_rx = 0;
68583 mutex_unlock(&module_mutex);
68584
68585 return 0;
68586@@ -3116,10 +3242,16 @@ static const char *get_ksymbol(struct module *mod,
68587 unsigned long nextval;
68588
68589 /* At worse, next value is at end of module */
68590- if (within_module_init(addr, mod))
68591- nextval = (unsigned long)mod->module_init+mod->init_text_size;
68592+ if (within_module_init_rx(addr, mod))
68593+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68594+ else if (within_module_init_rw(addr, mod))
68595+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68596+ else if (within_module_core_rx(addr, mod))
68597+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68598+ else if (within_module_core_rw(addr, mod))
68599+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68600 else
68601- nextval = (unsigned long)mod->module_core+mod->core_text_size;
68602+ return NULL;
68603
68604 /* Scan for closest preceding symbol, and next symbol. (ELF
68605 starts real symbols at 1). */
68606@@ -3354,7 +3486,7 @@ static int m_show(struct seq_file *m, void *p)
68607 char buf[8];
68608
68609 seq_printf(m, "%s %u",
68610- mod->name, mod->init_size + mod->core_size);
68611+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68612 print_unload_info(m, mod);
68613
68614 /* Informative for users. */
68615@@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
68616 mod->state == MODULE_STATE_COMING ? "Loading":
68617 "Live");
68618 /* Used by oprofile and other similar tools. */
68619- seq_printf(m, " 0x%pK", mod->module_core);
68620+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68621
68622 /* Taints info */
68623 if (mod->taints)
68624@@ -3399,7 +3531,17 @@ static const struct file_operations proc_modules_operations = {
68625
68626 static int __init proc_modules_init(void)
68627 {
68628+#ifndef CONFIG_GRKERNSEC_HIDESYM
68629+#ifdef CONFIG_GRKERNSEC_PROC_USER
68630+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68631+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68632+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68633+#else
68634 proc_create("modules", 0, NULL, &proc_modules_operations);
68635+#endif
68636+#else
68637+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68638+#endif
68639 return 0;
68640 }
68641 module_init(proc_modules_init);
68642@@ -3458,12 +3600,12 @@ struct module *__module_address(unsigned long addr)
68643 {
68644 struct module *mod;
68645
68646- if (addr < module_addr_min || addr > module_addr_max)
68647+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68648+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
68649 return NULL;
68650
68651 list_for_each_entry_rcu(mod, &modules, list)
68652- if (within_module_core(addr, mod)
68653- || within_module_init(addr, mod))
68654+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
68655 return mod;
68656 return NULL;
68657 }
68658@@ -3497,11 +3639,20 @@ bool is_module_text_address(unsigned long addr)
68659 */
68660 struct module *__module_text_address(unsigned long addr)
68661 {
68662- struct module *mod = __module_address(addr);
68663+ struct module *mod;
68664+
68665+#ifdef CONFIG_X86_32
68666+ addr = ktla_ktva(addr);
68667+#endif
68668+
68669+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68670+ return NULL;
68671+
68672+ mod = __module_address(addr);
68673+
68674 if (mod) {
68675 /* Make sure it's within the text section. */
68676- if (!within(addr, mod->module_init, mod->init_text_size)
68677- && !within(addr, mod->module_core, mod->core_text_size))
68678+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68679 mod = NULL;
68680 }
68681 return mod;
68682diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68683index 7e3443f..b2a1e6b 100644
68684--- a/kernel/mutex-debug.c
68685+++ b/kernel/mutex-debug.c
68686@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68687 }
68688
68689 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68690- struct thread_info *ti)
68691+ struct task_struct *task)
68692 {
68693 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68694
68695 /* Mark the current thread as blocked on the lock: */
68696- ti->task->blocked_on = waiter;
68697+ task->blocked_on = waiter;
68698 }
68699
68700 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68701- struct thread_info *ti)
68702+ struct task_struct *task)
68703 {
68704 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68705- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68706- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68707- ti->task->blocked_on = NULL;
68708+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
68709+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68710+ task->blocked_on = NULL;
68711
68712 list_del_init(&waiter->list);
68713 waiter->task = NULL;
68714diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68715index 0799fd3..d06ae3b 100644
68716--- a/kernel/mutex-debug.h
68717+++ b/kernel/mutex-debug.h
68718@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68719 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68720 extern void debug_mutex_add_waiter(struct mutex *lock,
68721 struct mutex_waiter *waiter,
68722- struct thread_info *ti);
68723+ struct task_struct *task);
68724 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68725- struct thread_info *ti);
68726+ struct task_struct *task);
68727 extern void debug_mutex_unlock(struct mutex *lock);
68728 extern void debug_mutex_init(struct mutex *lock, const char *name,
68729 struct lock_class_key *key);
68730diff --git a/kernel/mutex.c b/kernel/mutex.c
68731index a307cc9..27fd2e9 100644
68732--- a/kernel/mutex.c
68733+++ b/kernel/mutex.c
68734@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68735 spin_lock_mutex(&lock->wait_lock, flags);
68736
68737 debug_mutex_lock_common(lock, &waiter);
68738- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68739+ debug_mutex_add_waiter(lock, &waiter, task);
68740
68741 /* add waiting tasks to the end of the waitqueue (FIFO): */
68742 list_add_tail(&waiter.list, &lock->wait_list);
68743@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68744 * TASK_UNINTERRUPTIBLE case.)
68745 */
68746 if (unlikely(signal_pending_state(state, task))) {
68747- mutex_remove_waiter(lock, &waiter,
68748- task_thread_info(task));
68749+ mutex_remove_waiter(lock, &waiter, task);
68750 mutex_release(&lock->dep_map, 1, ip);
68751 spin_unlock_mutex(&lock->wait_lock, flags);
68752
68753@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68754 done:
68755 lock_acquired(&lock->dep_map, ip);
68756 /* got the lock - rejoice! */
68757- mutex_remove_waiter(lock, &waiter, current_thread_info());
68758+ mutex_remove_waiter(lock, &waiter, task);
68759 mutex_set_owner(lock);
68760
68761 /* set it to 0 if there are no waiters left: */
68762diff --git a/kernel/panic.c b/kernel/panic.c
68763index e1b2822..5edc1d9 100644
68764--- a/kernel/panic.c
68765+++ b/kernel/panic.c
68766@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68767 const char *board;
68768
68769 printk(KERN_WARNING "------------[ cut here ]------------\n");
68770- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68771+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68772 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68773 if (board)
68774 printk(KERN_WARNING "Hardware name: %s\n", board);
68775@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68776 */
68777 void __stack_chk_fail(void)
68778 {
68779- panic("stack-protector: Kernel stack is corrupted in: %p\n",
68780+ dump_stack();
68781+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68782 __builtin_return_address(0));
68783 }
68784 EXPORT_SYMBOL(__stack_chk_fail);
68785diff --git a/kernel/pid.c b/kernel/pid.c
68786index e86b291a..e8b0fb5 100644
68787--- a/kernel/pid.c
68788+++ b/kernel/pid.c
68789@@ -33,6 +33,7 @@
68790 #include <linux/rculist.h>
68791 #include <linux/bootmem.h>
68792 #include <linux/hash.h>
68793+#include <linux/security.h>
68794 #include <linux/pid_namespace.h>
68795 #include <linux/init_task.h>
68796 #include <linux/syscalls.h>
68797@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68798
68799 int pid_max = PID_MAX_DEFAULT;
68800
68801-#define RESERVED_PIDS 300
68802+#define RESERVED_PIDS 500
68803
68804 int pid_max_min = RESERVED_PIDS + 1;
68805 int pid_max_max = PID_MAX_LIMIT;
68806@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68807 */
68808 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68809 {
68810+ struct task_struct *task;
68811+
68812 rcu_lockdep_assert(rcu_read_lock_held(),
68813 "find_task_by_pid_ns() needs rcu_read_lock()"
68814 " protection");
68815- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68816+
68817+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68818+
68819+ if (gr_pid_is_chrooted(task))
68820+ return NULL;
68821+
68822+ return task;
68823 }
68824
68825 struct task_struct *find_task_by_vpid(pid_t vnr)
68826@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68827 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68828 }
68829
68830+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68831+{
68832+ rcu_lockdep_assert(rcu_read_lock_held(),
68833+ "find_task_by_pid_ns() needs rcu_read_lock()"
68834+ " protection");
68835+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68836+}
68837+
68838 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68839 {
68840 struct pid *pid;
68841diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68842index 125cb67..a4d1c30 100644
68843--- a/kernel/posix-cpu-timers.c
68844+++ b/kernel/posix-cpu-timers.c
68845@@ -6,6 +6,7 @@
68846 #include <linux/posix-timers.h>
68847 #include <linux/errno.h>
68848 #include <linux/math64.h>
68849+#include <linux/security.h>
68850 #include <asm/uaccess.h>
68851 #include <linux/kernel_stat.h>
68852 #include <trace/events/timer.h>
68853@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68854
68855 static __init int init_posix_cpu_timers(void)
68856 {
68857- struct k_clock process = {
68858+ static struct k_clock process = {
68859 .clock_getres = process_cpu_clock_getres,
68860 .clock_get = process_cpu_clock_get,
68861 .timer_create = process_cpu_timer_create,
68862 .nsleep = process_cpu_nsleep,
68863 .nsleep_restart = process_cpu_nsleep_restart,
68864 };
68865- struct k_clock thread = {
68866+ static struct k_clock thread = {
68867 .clock_getres = thread_cpu_clock_getres,
68868 .clock_get = thread_cpu_clock_get,
68869 .timer_create = thread_cpu_timer_create,
68870diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68871index 69185ae..cc2847a 100644
68872--- a/kernel/posix-timers.c
68873+++ b/kernel/posix-timers.c
68874@@ -43,6 +43,7 @@
68875 #include <linux/idr.h>
68876 #include <linux/posix-clock.h>
68877 #include <linux/posix-timers.h>
68878+#include <linux/grsecurity.h>
68879 #include <linux/syscalls.h>
68880 #include <linux/wait.h>
68881 #include <linux/workqueue.h>
68882@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68883 * which we beg off on and pass to do_sys_settimeofday().
68884 */
68885
68886-static struct k_clock posix_clocks[MAX_CLOCKS];
68887+static struct k_clock *posix_clocks[MAX_CLOCKS];
68888
68889 /*
68890 * These ones are defined below.
68891@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68892 */
68893 static __init int init_posix_timers(void)
68894 {
68895- struct k_clock clock_realtime = {
68896+ static struct k_clock clock_realtime = {
68897 .clock_getres = hrtimer_get_res,
68898 .clock_get = posix_clock_realtime_get,
68899 .clock_set = posix_clock_realtime_set,
68900@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68901 .timer_get = common_timer_get,
68902 .timer_del = common_timer_del,
68903 };
68904- struct k_clock clock_monotonic = {
68905+ static struct k_clock clock_monotonic = {
68906 .clock_getres = hrtimer_get_res,
68907 .clock_get = posix_ktime_get_ts,
68908 .nsleep = common_nsleep,
68909@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68910 .timer_get = common_timer_get,
68911 .timer_del = common_timer_del,
68912 };
68913- struct k_clock clock_monotonic_raw = {
68914+ static struct k_clock clock_monotonic_raw = {
68915 .clock_getres = hrtimer_get_res,
68916 .clock_get = posix_get_monotonic_raw,
68917 };
68918- struct k_clock clock_realtime_coarse = {
68919+ static struct k_clock clock_realtime_coarse = {
68920 .clock_getres = posix_get_coarse_res,
68921 .clock_get = posix_get_realtime_coarse,
68922 };
68923- struct k_clock clock_monotonic_coarse = {
68924+ static struct k_clock clock_monotonic_coarse = {
68925 .clock_getres = posix_get_coarse_res,
68926 .clock_get = posix_get_monotonic_coarse,
68927 };
68928- struct k_clock clock_boottime = {
68929+ static struct k_clock clock_boottime = {
68930 .clock_getres = hrtimer_get_res,
68931 .clock_get = posix_get_boottime,
68932 .nsleep = common_nsleep,
68933@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68934 return;
68935 }
68936
68937- posix_clocks[clock_id] = *new_clock;
68938+ posix_clocks[clock_id] = new_clock;
68939 }
68940 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68941
68942@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68943 return (id & CLOCKFD_MASK) == CLOCKFD ?
68944 &clock_posix_dynamic : &clock_posix_cpu;
68945
68946- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68947+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68948 return NULL;
68949- return &posix_clocks[id];
68950+ return posix_clocks[id];
68951 }
68952
68953 static int common_timer_create(struct k_itimer *new_timer)
68954@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
68955 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
68956 return -EFAULT;
68957
68958+ /* only the CLOCK_REALTIME clock can be set, all other clocks
68959+ have their clock_set fptr set to a nosettime dummy function
68960+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
68961+ call common_clock_set, which calls do_sys_settimeofday, which
68962+ we hook
68963+ */
68964+
68965 return kc->clock_set(which_clock, &new_tp);
68966 }
68967
68968diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
68969index d523593..68197a4 100644
68970--- a/kernel/power/poweroff.c
68971+++ b/kernel/power/poweroff.c
68972@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68973 .enable_mask = SYSRQ_ENABLE_BOOT,
68974 };
68975
68976-static int pm_sysrq_init(void)
68977+static int __init pm_sysrq_init(void)
68978 {
68979 register_sysrq_key('o', &sysrq_poweroff_op);
68980 return 0;
68981diff --git a/kernel/power/process.c b/kernel/power/process.c
68982index 19db29f..33b52b6 100644
68983--- a/kernel/power/process.c
68984+++ b/kernel/power/process.c
68985@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
68986 u64 elapsed_csecs64;
68987 unsigned int elapsed_csecs;
68988 bool wakeup = false;
68989+ bool timedout = false;
68990
68991 do_gettimeofday(&start);
68992
68993@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
68994
68995 while (true) {
68996 todo = 0;
68997+ if (time_after(jiffies, end_time))
68998+ timedout = true;
68999 read_lock(&tasklist_lock);
69000 do_each_thread(g, p) {
69001 if (p == current || !freeze_task(p))
69002@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69003 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69004 * transition can't race with task state testing here.
69005 */
69006- if (!task_is_stopped_or_traced(p) &&
69007- !freezer_should_skip(p))
69008+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69009 todo++;
69010+ if (timedout) {
69011+ printk(KERN_ERR "Task refusing to freeze:\n");
69012+ sched_show_task(p);
69013+ }
69014+ }
69015 } while_each_thread(g, p);
69016 read_unlock(&tasklist_lock);
69017
69018@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69019 todo += wq_busy;
69020 }
69021
69022- if (!todo || time_after(jiffies, end_time))
69023+ if (!todo || timedout)
69024 break;
69025
69026 if (pm_wakeup_pending()) {
69027diff --git a/kernel/printk.c b/kernel/printk.c
69028index 66a2ea3..10f3a01 100644
69029--- a/kernel/printk.c
69030+++ b/kernel/printk.c
69031@@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69032 if (from_file && type != SYSLOG_ACTION_OPEN)
69033 return 0;
69034
69035+#ifdef CONFIG_GRKERNSEC_DMESG
69036+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69037+ return -EPERM;
69038+#endif
69039+
69040 if (syslog_action_restricted(type)) {
69041 if (capable(CAP_SYSLOG))
69042 return 0;
69043diff --git a/kernel/profile.c b/kernel/profile.c
69044index 76b8e77..a2930e8 100644
69045--- a/kernel/profile.c
69046+++ b/kernel/profile.c
69047@@ -39,7 +39,7 @@ struct profile_hit {
69048 /* Oprofile timer tick hook */
69049 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69050
69051-static atomic_t *prof_buffer;
69052+static atomic_unchecked_t *prof_buffer;
69053 static unsigned long prof_len, prof_shift;
69054
69055 int prof_on __read_mostly;
69056@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69057 hits[i].pc = 0;
69058 continue;
69059 }
69060- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69061+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69062 hits[i].hits = hits[i].pc = 0;
69063 }
69064 }
69065@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69066 * Add the current hit(s) and flush the write-queue out
69067 * to the global buffer:
69068 */
69069- atomic_add(nr_hits, &prof_buffer[pc]);
69070+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69071 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69072- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69073+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69074 hits[i].pc = hits[i].hits = 0;
69075 }
69076 out:
69077@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69078 {
69079 unsigned long pc;
69080 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69081- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69082+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69083 }
69084 #endif /* !CONFIG_SMP */
69085
69086@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69087 return -EFAULT;
69088 buf++; p++; count--; read++;
69089 }
69090- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69091+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69092 if (copy_to_user(buf, (void *)pnt, count))
69093 return -EFAULT;
69094 read += count;
69095@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69096 }
69097 #endif
69098 profile_discard_flip_buffers();
69099- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69100+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69101 return count;
69102 }
69103
69104diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69105index a232bb5..2a65ef9 100644
69106--- a/kernel/ptrace.c
69107+++ b/kernel/ptrace.c
69108@@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69109
69110 if (seize)
69111 flags |= PT_SEIZED;
69112- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69113+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69114 flags |= PT_PTRACE_CAP;
69115 task->ptrace = flags;
69116
69117@@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69118 break;
69119 return -EIO;
69120 }
69121- if (copy_to_user(dst, buf, retval))
69122+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69123 return -EFAULT;
69124 copied += retval;
69125 src += retval;
69126@@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69127 bool seized = child->ptrace & PT_SEIZED;
69128 int ret = -EIO;
69129 siginfo_t siginfo, *si;
69130- void __user *datavp = (void __user *) data;
69131+ void __user *datavp = (__force void __user *) data;
69132 unsigned long __user *datalp = datavp;
69133 unsigned long flags;
69134
69135@@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69136 goto out;
69137 }
69138
69139+ if (gr_handle_ptrace(child, request)) {
69140+ ret = -EPERM;
69141+ goto out_put_task_struct;
69142+ }
69143+
69144 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69145 ret = ptrace_attach(child, request, addr, data);
69146 /*
69147 * Some architectures need to do book-keeping after
69148 * a ptrace attach.
69149 */
69150- if (!ret)
69151+ if (!ret) {
69152 arch_ptrace_attach(child);
69153+ gr_audit_ptrace(child);
69154+ }
69155 goto out_put_task_struct;
69156 }
69157
69158@@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69159 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69160 if (copied != sizeof(tmp))
69161 return -EIO;
69162- return put_user(tmp, (unsigned long __user *)data);
69163+ return put_user(tmp, (__force unsigned long __user *)data);
69164 }
69165
69166 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69167@@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69168 goto out;
69169 }
69170
69171+ if (gr_handle_ptrace(child, request)) {
69172+ ret = -EPERM;
69173+ goto out_put_task_struct;
69174+ }
69175+
69176 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69177 ret = ptrace_attach(child, request, addr, data);
69178 /*
69179 * Some architectures need to do book-keeping after
69180 * a ptrace attach.
69181 */
69182- if (!ret)
69183+ if (!ret) {
69184 arch_ptrace_attach(child);
69185+ gr_audit_ptrace(child);
69186+ }
69187 goto out_put_task_struct;
69188 }
69189
69190diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69191index 547b1fe..65e874e 100644
69192--- a/kernel/rcutiny.c
69193+++ b/kernel/rcutiny.c
69194@@ -46,7 +46,7 @@
69195 struct rcu_ctrlblk;
69196 static void invoke_rcu_callbacks(void);
69197 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69198-static void rcu_process_callbacks(struct softirq_action *unused);
69199+static void rcu_process_callbacks(void);
69200 static void __call_rcu(struct rcu_head *head,
69201 void (*func)(struct rcu_head *rcu),
69202 struct rcu_ctrlblk *rcp);
69203@@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69204 rcu_is_callbacks_kthread()));
69205 }
69206
69207-static void rcu_process_callbacks(struct softirq_action *unused)
69208+static void rcu_process_callbacks(void)
69209 {
69210 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69211 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69212diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69213index 918fd1e..85089bb 100644
69214--- a/kernel/rcutiny_plugin.h
69215+++ b/kernel/rcutiny_plugin.h
69216@@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69217 have_rcu_kthread_work = morework;
69218 local_irq_restore(flags);
69219 if (work)
69220- rcu_process_callbacks(NULL);
69221+ rcu_process_callbacks();
69222 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69223 }
69224
69225diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69226index 25b1503..1988a74 100644
69227--- a/kernel/rcutorture.c
69228+++ b/kernel/rcutorture.c
69229@@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69230 { 0 };
69231 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69232 { 0 };
69233-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69234-static atomic_t n_rcu_torture_alloc;
69235-static atomic_t n_rcu_torture_alloc_fail;
69236-static atomic_t n_rcu_torture_free;
69237-static atomic_t n_rcu_torture_mberror;
69238-static atomic_t n_rcu_torture_error;
69239+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69240+static atomic_unchecked_t n_rcu_torture_alloc;
69241+static atomic_unchecked_t n_rcu_torture_alloc_fail;
69242+static atomic_unchecked_t n_rcu_torture_free;
69243+static atomic_unchecked_t n_rcu_torture_mberror;
69244+static atomic_unchecked_t n_rcu_torture_error;
69245 static long n_rcu_torture_barrier_error;
69246 static long n_rcu_torture_boost_ktrerror;
69247 static long n_rcu_torture_boost_rterror;
69248@@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69249
69250 spin_lock_bh(&rcu_torture_lock);
69251 if (list_empty(&rcu_torture_freelist)) {
69252- atomic_inc(&n_rcu_torture_alloc_fail);
69253+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69254 spin_unlock_bh(&rcu_torture_lock);
69255 return NULL;
69256 }
69257- atomic_inc(&n_rcu_torture_alloc);
69258+ atomic_inc_unchecked(&n_rcu_torture_alloc);
69259 p = rcu_torture_freelist.next;
69260 list_del_init(p);
69261 spin_unlock_bh(&rcu_torture_lock);
69262@@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69263 static void
69264 rcu_torture_free(struct rcu_torture *p)
69265 {
69266- atomic_inc(&n_rcu_torture_free);
69267+ atomic_inc_unchecked(&n_rcu_torture_free);
69268 spin_lock_bh(&rcu_torture_lock);
69269 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69270 spin_unlock_bh(&rcu_torture_lock);
69271@@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69272 i = rp->rtort_pipe_count;
69273 if (i > RCU_TORTURE_PIPE_LEN)
69274 i = RCU_TORTURE_PIPE_LEN;
69275- atomic_inc(&rcu_torture_wcount[i]);
69276+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69277 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69278 rp->rtort_mbtest = 0;
69279 rcu_torture_free(rp);
69280@@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69281 i = rp->rtort_pipe_count;
69282 if (i > RCU_TORTURE_PIPE_LEN)
69283 i = RCU_TORTURE_PIPE_LEN;
69284- atomic_inc(&rcu_torture_wcount[i]);
69285+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69286 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69287 rp->rtort_mbtest = 0;
69288 list_del(&rp->rtort_free);
69289@@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
69290 i = old_rp->rtort_pipe_count;
69291 if (i > RCU_TORTURE_PIPE_LEN)
69292 i = RCU_TORTURE_PIPE_LEN;
69293- atomic_inc(&rcu_torture_wcount[i]);
69294+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69295 old_rp->rtort_pipe_count++;
69296 cur_ops->deferred_free(old_rp);
69297 }
69298@@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
69299 }
69300 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69301 if (p->rtort_mbtest == 0)
69302- atomic_inc(&n_rcu_torture_mberror);
69303+ atomic_inc_unchecked(&n_rcu_torture_mberror);
69304 spin_lock(&rand_lock);
69305 cur_ops->read_delay(&rand);
69306 n_rcu_torture_timers++;
69307@@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
69308 }
69309 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69310 if (p->rtort_mbtest == 0)
69311- atomic_inc(&n_rcu_torture_mberror);
69312+ atomic_inc_unchecked(&n_rcu_torture_mberror);
69313 cur_ops->read_delay(&rand);
69314 preempt_disable();
69315 pipe_count = p->rtort_pipe_count;
69316@@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
69317 rcu_torture_current,
69318 rcu_torture_current_version,
69319 list_empty(&rcu_torture_freelist),
69320- atomic_read(&n_rcu_torture_alloc),
69321- atomic_read(&n_rcu_torture_alloc_fail),
69322- atomic_read(&n_rcu_torture_free));
69323+ atomic_read_unchecked(&n_rcu_torture_alloc),
69324+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69325+ atomic_read_unchecked(&n_rcu_torture_free));
69326 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69327- atomic_read(&n_rcu_torture_mberror),
69328+ atomic_read_unchecked(&n_rcu_torture_mberror),
69329 n_rcu_torture_boost_ktrerror,
69330 n_rcu_torture_boost_rterror);
69331 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69332@@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
69333 n_barrier_attempts,
69334 n_rcu_torture_barrier_error);
69335 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69336- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69337+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69338 n_rcu_torture_barrier_error != 0 ||
69339 n_rcu_torture_boost_ktrerror != 0 ||
69340 n_rcu_torture_boost_rterror != 0 ||
69341 n_rcu_torture_boost_failure != 0 ||
69342 i > 1) {
69343 cnt += sprintf(&page[cnt], "!!! ");
69344- atomic_inc(&n_rcu_torture_error);
69345+ atomic_inc_unchecked(&n_rcu_torture_error);
69346 WARN_ON_ONCE(1);
69347 }
69348 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69349@@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
69350 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69351 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69352 cnt += sprintf(&page[cnt], " %d",
69353- atomic_read(&rcu_torture_wcount[i]));
69354+ atomic_read_unchecked(&rcu_torture_wcount[i]));
69355 }
69356 cnt += sprintf(&page[cnt], "\n");
69357 if (cur_ops->stats)
69358@@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
69359
69360 if (cur_ops->cleanup)
69361 cur_ops->cleanup();
69362- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69363+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69364 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69365 else if (n_online_successes != n_online_attempts ||
69366 n_offline_successes != n_offline_attempts)
69367@@ -1974,18 +1974,18 @@ rcu_torture_init(void)
69368
69369 rcu_torture_current = NULL;
69370 rcu_torture_current_version = 0;
69371- atomic_set(&n_rcu_torture_alloc, 0);
69372- atomic_set(&n_rcu_torture_alloc_fail, 0);
69373- atomic_set(&n_rcu_torture_free, 0);
69374- atomic_set(&n_rcu_torture_mberror, 0);
69375- atomic_set(&n_rcu_torture_error, 0);
69376+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69377+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69378+ atomic_set_unchecked(&n_rcu_torture_free, 0);
69379+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69380+ atomic_set_unchecked(&n_rcu_torture_error, 0);
69381 n_rcu_torture_barrier_error = 0;
69382 n_rcu_torture_boost_ktrerror = 0;
69383 n_rcu_torture_boost_rterror = 0;
69384 n_rcu_torture_boost_failure = 0;
69385 n_rcu_torture_boosts = 0;
69386 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69387- atomic_set(&rcu_torture_wcount[i], 0);
69388+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69389 for_each_possible_cpu(cpu) {
69390 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69391 per_cpu(rcu_torture_count, cpu)[i] = 0;
69392diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69393index f280e54..804aec2 100644
69394--- a/kernel/rcutree.c
69395+++ b/kernel/rcutree.c
69396@@ -367,9 +367,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69397 rcu_prepare_for_idle(smp_processor_id());
69398 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69399 smp_mb__before_atomic_inc(); /* See above. */
69400- atomic_inc(&rdtp->dynticks);
69401+ atomic_inc_unchecked(&rdtp->dynticks);
69402 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69403- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69404+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69405
69406 /*
69407 * The idle task is not permitted to enter the idle loop while
69408@@ -458,10 +458,10 @@ void rcu_irq_exit(void)
69409 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69410 {
69411 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69412- atomic_inc(&rdtp->dynticks);
69413+ atomic_inc_unchecked(&rdtp->dynticks);
69414 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69415 smp_mb__after_atomic_inc(); /* See above. */
69416- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69417+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69418 rcu_cleanup_after_idle(smp_processor_id());
69419 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69420 if (!is_idle_task(current)) {
69421@@ -555,14 +555,14 @@ void rcu_nmi_enter(void)
69422 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69423
69424 if (rdtp->dynticks_nmi_nesting == 0 &&
69425- (atomic_read(&rdtp->dynticks) & 0x1))
69426+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69427 return;
69428 rdtp->dynticks_nmi_nesting++;
69429 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69430- atomic_inc(&rdtp->dynticks);
69431+ atomic_inc_unchecked(&rdtp->dynticks);
69432 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69433 smp_mb__after_atomic_inc(); /* See above. */
69434- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69435+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69436 }
69437
69438 /**
69439@@ -581,9 +581,9 @@ void rcu_nmi_exit(void)
69440 return;
69441 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69442 smp_mb__before_atomic_inc(); /* See above. */
69443- atomic_inc(&rdtp->dynticks);
69444+ atomic_inc_unchecked(&rdtp->dynticks);
69445 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69446- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69447+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69448 }
69449
69450 /**
69451@@ -597,7 +597,7 @@ int rcu_is_cpu_idle(void)
69452 int ret;
69453
69454 preempt_disable();
69455- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69456+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69457 preempt_enable();
69458 return ret;
69459 }
69460@@ -665,7 +665,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69461 */
69462 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69463 {
69464- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69465+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69466 return (rdp->dynticks_snap & 0x1) == 0;
69467 }
69468
69469@@ -680,7 +680,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69470 unsigned int curr;
69471 unsigned int snap;
69472
69473- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69474+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69475 snap = (unsigned int)rdp->dynticks_snap;
69476
69477 /*
69478@@ -710,10 +710,10 @@ static int jiffies_till_stall_check(void)
69479 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69480 */
69481 if (till_stall_check < 3) {
69482- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69483+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69484 till_stall_check = 3;
69485 } else if (till_stall_check > 300) {
69486- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69487+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69488 till_stall_check = 300;
69489 }
69490 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69491@@ -1349,7 +1349,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69492 rsp->qlen += rdp->qlen;
69493 rdp->n_cbs_orphaned += rdp->qlen;
69494 rdp->qlen_lazy = 0;
69495- ACCESS_ONCE(rdp->qlen) = 0;
69496+ ACCESS_ONCE_RW(rdp->qlen) = 0;
69497 }
69498
69499 /*
69500@@ -1602,7 +1602,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69501 }
69502 smp_mb(); /* List handling before counting for rcu_barrier(). */
69503 rdp->qlen_lazy -= count_lazy;
69504- ACCESS_ONCE(rdp->qlen) -= count;
69505+ ACCESS_ONCE_RW(rdp->qlen) -= count;
69506 rdp->n_cbs_invoked += count;
69507
69508 /* Reinstate batch limit if we have worked down the excess. */
69509@@ -1834,7 +1834,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
69510 /*
69511 * Do RCU core processing for the current CPU.
69512 */
69513-static void rcu_process_callbacks(struct softirq_action *unused)
69514+static void rcu_process_callbacks(void)
69515 {
69516 struct rcu_state *rsp;
69517
69518@@ -1941,7 +1941,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
69519 rdp = this_cpu_ptr(rsp->rda);
69520
69521 /* Add the callback to our list. */
69522- ACCESS_ONCE(rdp->qlen)++;
69523+ ACCESS_ONCE_RW(rdp->qlen)++;
69524 if (lazy)
69525 rdp->qlen_lazy++;
69526 else
69527@@ -2055,8 +2055,8 @@ void synchronize_rcu_bh(void)
69528 }
69529 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69530
69531-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69532-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69533+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69534+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69535
69536 static int synchronize_sched_expedited_cpu_stop(void *data)
69537 {
69538@@ -2117,7 +2117,7 @@ void synchronize_sched_expedited(void)
69539 int firstsnap, s, snap, trycount = 0;
69540
69541 /* Note that atomic_inc_return() implies full memory barrier. */
69542- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69543+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69544 get_online_cpus();
69545 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69546
69547@@ -2139,7 +2139,7 @@ void synchronize_sched_expedited(void)
69548 }
69549
69550 /* Check to see if someone else did our work for us. */
69551- s = atomic_read(&sync_sched_expedited_done);
69552+ s = atomic_read_unchecked(&sync_sched_expedited_done);
69553 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69554 smp_mb(); /* ensure test happens before caller kfree */
69555 return;
69556@@ -2154,7 +2154,7 @@ void synchronize_sched_expedited(void)
69557 * grace period works for us.
69558 */
69559 get_online_cpus();
69560- snap = atomic_read(&sync_sched_expedited_started);
69561+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
69562 smp_mb(); /* ensure read is before try_stop_cpus(). */
69563 }
69564
69565@@ -2165,12 +2165,12 @@ void synchronize_sched_expedited(void)
69566 * than we did beat us to the punch.
69567 */
69568 do {
69569- s = atomic_read(&sync_sched_expedited_done);
69570+ s = atomic_read_unchecked(&sync_sched_expedited_done);
69571 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69572 smp_mb(); /* ensure test happens before caller kfree */
69573 break;
69574 }
69575- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69576+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69577
69578 put_online_cpus();
69579 }
69580@@ -2364,7 +2364,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69581 * ACCESS_ONCE() to prevent the compiler from speculating
69582 * the increment to precede the early-exit check.
69583 */
69584- ACCESS_ONCE(rsp->n_barrier_done)++;
69585+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69586 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
69587 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
69588 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
69589@@ -2446,7 +2446,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69590
69591 /* Increment ->n_barrier_done to prevent duplicate work. */
69592 smp_mb(); /* Keep increment after above mechanism. */
69593- ACCESS_ONCE(rsp->n_barrier_done)++;
69594+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69595 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
69596 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
69597 smp_mb(); /* Keep increment before caller's subsequent code. */
69598@@ -2493,10 +2493,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69599 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
69600 init_callback_list(rdp);
69601 rdp->qlen_lazy = 0;
69602- ACCESS_ONCE(rdp->qlen) = 0;
69603+ ACCESS_ONCE_RW(rdp->qlen) = 0;
69604 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69605 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69606- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69607+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69608 rdp->cpu = cpu;
69609 rdp->rsp = rsp;
69610 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69611@@ -2524,8 +2524,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69612 rdp->n_force_qs_snap = rsp->n_force_qs;
69613 rdp->blimit = blimit;
69614 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69615- atomic_set(&rdp->dynticks->dynticks,
69616- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69617+ atomic_set_unchecked(&rdp->dynticks->dynticks,
69618+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69619 rcu_prepare_for_idle_init(cpu);
69620 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69621
69622diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69623index 4d29169..d104a3c 100644
69624--- a/kernel/rcutree.h
69625+++ b/kernel/rcutree.h
69626@@ -86,7 +86,7 @@ struct rcu_dynticks {
69627 long long dynticks_nesting; /* Track irq/process nesting level. */
69628 /* Process level is worth LLONG_MAX/2. */
69629 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69630- atomic_t dynticks; /* Even value for idle, else odd. */
69631+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69632 #ifdef CONFIG_RCU_FAST_NO_HZ
69633 int dyntick_drain; /* Prepare-for-idle state variable. */
69634 unsigned long dyntick_holdoff;
69635diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69636index 7f3244c..417d606 100644
69637--- a/kernel/rcutree_plugin.h
69638+++ b/kernel/rcutree_plugin.h
69639@@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
69640
69641 /* Clean up and exit. */
69642 smp_mb(); /* ensure expedited GP seen before counter increment. */
69643- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69644+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69645 unlock_mb_ret:
69646 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69647 mb_ret:
69648diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69649index abffb48..cbfa6d3 100644
69650--- a/kernel/rcutree_trace.c
69651+++ b/kernel/rcutree_trace.c
69652@@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69653 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69654 rdp->qs_pending);
69655 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69656- atomic_read(&rdp->dynticks->dynticks),
69657+ atomic_read_unchecked(&rdp->dynticks->dynticks),
69658 rdp->dynticks->dynticks_nesting,
69659 rdp->dynticks->dynticks_nmi_nesting,
69660 rdp->dynticks_fqs);
69661@@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69662 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69663 rdp->qs_pending);
69664 seq_printf(m, ",%d,%llx,%d,%lu",
69665- atomic_read(&rdp->dynticks->dynticks),
69666+ atomic_read_unchecked(&rdp->dynticks->dynticks),
69667 rdp->dynticks->dynticks_nesting,
69668 rdp->dynticks->dynticks_nmi_nesting,
69669 rdp->dynticks_fqs);
69670diff --git a/kernel/resource.c b/kernel/resource.c
69671index 34d4588..10baa6a 100644
69672--- a/kernel/resource.c
69673+++ b/kernel/resource.c
69674@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
69675
69676 static int __init ioresources_init(void)
69677 {
69678+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69679+#ifdef CONFIG_GRKERNSEC_PROC_USER
69680+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69681+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69682+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69683+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69684+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69685+#endif
69686+#else
69687 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69688 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69689+#endif
69690 return 0;
69691 }
69692 __initcall(ioresources_init);
69693diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69694index 98ec494..4241d6d 100644
69695--- a/kernel/rtmutex-tester.c
69696+++ b/kernel/rtmutex-tester.c
69697@@ -20,7 +20,7 @@
69698 #define MAX_RT_TEST_MUTEXES 8
69699
69700 static spinlock_t rttest_lock;
69701-static atomic_t rttest_event;
69702+static atomic_unchecked_t rttest_event;
69703
69704 struct test_thread_data {
69705 int opcode;
69706@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69707
69708 case RTTEST_LOCKCONT:
69709 td->mutexes[td->opdata] = 1;
69710- td->event = atomic_add_return(1, &rttest_event);
69711+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69712 return 0;
69713
69714 case RTTEST_RESET:
69715@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69716 return 0;
69717
69718 case RTTEST_RESETEVENT:
69719- atomic_set(&rttest_event, 0);
69720+ atomic_set_unchecked(&rttest_event, 0);
69721 return 0;
69722
69723 default:
69724@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69725 return ret;
69726
69727 td->mutexes[id] = 1;
69728- td->event = atomic_add_return(1, &rttest_event);
69729+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69730 rt_mutex_lock(&mutexes[id]);
69731- td->event = atomic_add_return(1, &rttest_event);
69732+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69733 td->mutexes[id] = 4;
69734 return 0;
69735
69736@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69737 return ret;
69738
69739 td->mutexes[id] = 1;
69740- td->event = atomic_add_return(1, &rttest_event);
69741+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69742 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69743- td->event = atomic_add_return(1, &rttest_event);
69744+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69745 td->mutexes[id] = ret ? 0 : 4;
69746 return ret ? -EINTR : 0;
69747
69748@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69749 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69750 return ret;
69751
69752- td->event = atomic_add_return(1, &rttest_event);
69753+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69754 rt_mutex_unlock(&mutexes[id]);
69755- td->event = atomic_add_return(1, &rttest_event);
69756+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69757 td->mutexes[id] = 0;
69758 return 0;
69759
69760@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69761 break;
69762
69763 td->mutexes[dat] = 2;
69764- td->event = atomic_add_return(1, &rttest_event);
69765+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69766 break;
69767
69768 default:
69769@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69770 return;
69771
69772 td->mutexes[dat] = 3;
69773- td->event = atomic_add_return(1, &rttest_event);
69774+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69775 break;
69776
69777 case RTTEST_LOCKNOWAIT:
69778@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69779 return;
69780
69781 td->mutexes[dat] = 1;
69782- td->event = atomic_add_return(1, &rttest_event);
69783+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69784 return;
69785
69786 default:
69787diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69788index 0984a21..939f183 100644
69789--- a/kernel/sched/auto_group.c
69790+++ b/kernel/sched/auto_group.c
69791@@ -11,7 +11,7 @@
69792
69793 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69794 static struct autogroup autogroup_default;
69795-static atomic_t autogroup_seq_nr;
69796+static atomic_unchecked_t autogroup_seq_nr;
69797
69798 void __init autogroup_init(struct task_struct *init_task)
69799 {
69800@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69801
69802 kref_init(&ag->kref);
69803 init_rwsem(&ag->lock);
69804- ag->id = atomic_inc_return(&autogroup_seq_nr);
69805+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69806 ag->tg = tg;
69807 #ifdef CONFIG_RT_GROUP_SCHED
69808 /*
69809diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69810index 649c9f8..be11574 100644
69811--- a/kernel/sched/core.c
69812+++ b/kernel/sched/core.c
69813@@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
69814 /* convert nice value [19,-20] to rlimit style value [1,40] */
69815 int nice_rlim = 20 - nice;
69816
69817+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69818+
69819 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69820 capable(CAP_SYS_NICE));
69821 }
69822@@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69823 if (nice > 19)
69824 nice = 19;
69825
69826- if (increment < 0 && !can_nice(current, nice))
69827+ if (increment < 0 && (!can_nice(current, nice) ||
69828+ gr_handle_chroot_nice()))
69829 return -EPERM;
69830
69831 retval = security_task_setnice(current, nice);
69832@@ -4290,6 +4293,7 @@ recheck:
69833 unsigned long rlim_rtprio =
69834 task_rlimit(p, RLIMIT_RTPRIO);
69835
69836+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69837 /* can't set/change the rt policy */
69838 if (policy != p->policy && !rlim_rtprio)
69839 return -EPERM;
69840diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69841index 96e2b18..bb31eec 100644
69842--- a/kernel/sched/fair.c
69843+++ b/kernel/sched/fair.c
69844@@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69845 * run_rebalance_domains is triggered when needed from the scheduler tick.
69846 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69847 */
69848-static void run_rebalance_domains(struct softirq_action *h)
69849+static void run_rebalance_domains(void)
69850 {
69851 int this_cpu = smp_processor_id();
69852 struct rq *this_rq = cpu_rq(this_cpu);
69853diff --git a/kernel/signal.c b/kernel/signal.c
69854index be4f856..453401c 100644
69855--- a/kernel/signal.c
69856+++ b/kernel/signal.c
69857@@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69858
69859 int print_fatal_signals __read_mostly;
69860
69861-static void __user *sig_handler(struct task_struct *t, int sig)
69862+static __sighandler_t sig_handler(struct task_struct *t, int sig)
69863 {
69864 return t->sighand->action[sig - 1].sa.sa_handler;
69865 }
69866
69867-static int sig_handler_ignored(void __user *handler, int sig)
69868+static int sig_handler_ignored(__sighandler_t handler, int sig)
69869 {
69870 /* Is it explicitly or implicitly ignored? */
69871 return handler == SIG_IGN ||
69872@@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69873
69874 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69875 {
69876- void __user *handler;
69877+ __sighandler_t handler;
69878
69879 handler = sig_handler(t, sig);
69880
69881@@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69882 atomic_inc(&user->sigpending);
69883 rcu_read_unlock();
69884
69885+ if (!override_rlimit)
69886+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69887+
69888 if (override_rlimit ||
69889 atomic_read(&user->sigpending) <=
69890 task_rlimit(t, RLIMIT_SIGPENDING)) {
69891@@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69892
69893 int unhandled_signal(struct task_struct *tsk, int sig)
69894 {
69895- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69896+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69897 if (is_global_init(tsk))
69898 return 1;
69899 if (handler != SIG_IGN && handler != SIG_DFL)
69900@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69901 }
69902 }
69903
69904+ /* allow glibc communication via tgkill to other threads in our
69905+ thread group */
69906+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69907+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69908+ && gr_handle_signal(t, sig))
69909+ return -EPERM;
69910+
69911 return security_task_kill(t, info, sig, 0);
69912 }
69913
69914@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69915 return send_signal(sig, info, p, 1);
69916 }
69917
69918-static int
69919+int
69920 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69921 {
69922 return send_signal(sig, info, t, 0);
69923@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69924 unsigned long int flags;
69925 int ret, blocked, ignored;
69926 struct k_sigaction *action;
69927+ int is_unhandled = 0;
69928
69929 spin_lock_irqsave(&t->sighand->siglock, flags);
69930 action = &t->sighand->action[sig-1];
69931@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69932 }
69933 if (action->sa.sa_handler == SIG_DFL)
69934 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69935+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69936+ is_unhandled = 1;
69937 ret = specific_send_sig_info(sig, info, t);
69938 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69939
69940+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
69941+ normal operation */
69942+ if (is_unhandled) {
69943+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69944+ gr_handle_crash(t, sig);
69945+ }
69946+
69947 return ret;
69948 }
69949
69950@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69951 ret = check_kill_permission(sig, info, p);
69952 rcu_read_unlock();
69953
69954- if (!ret && sig)
69955+ if (!ret && sig) {
69956 ret = do_send_sig_info(sig, info, p, true);
69957+ if (!ret)
69958+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69959+ }
69960
69961 return ret;
69962 }
69963@@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69964 int error = -ESRCH;
69965
69966 rcu_read_lock();
69967- p = find_task_by_vpid(pid);
69968+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69969+ /* allow glibc communication via tgkill to other threads in our
69970+ thread group */
69971+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69972+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
69973+ p = find_task_by_vpid_unrestricted(pid);
69974+ else
69975+#endif
69976+ p = find_task_by_vpid(pid);
69977 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69978 error = check_kill_permission(sig, info, p);
69979 /*
69980diff --git a/kernel/softirq.c b/kernel/softirq.c
69981index b73e681..645ab62 100644
69982--- a/kernel/softirq.c
69983+++ b/kernel/softirq.c
69984@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69985
69986 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69987
69988-char *softirq_to_name[NR_SOFTIRQS] = {
69989+const char * const softirq_to_name[NR_SOFTIRQS] = {
69990 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69991 "TASKLET", "SCHED", "HRTIMER", "RCU"
69992 };
69993@@ -243,7 +243,7 @@ restart:
69994 kstat_incr_softirqs_this_cpu(vec_nr);
69995
69996 trace_softirq_entry(vec_nr);
69997- h->action(h);
69998+ h->action();
69999 trace_softirq_exit(vec_nr);
70000 if (unlikely(prev_count != preempt_count())) {
70001 printk(KERN_ERR "huh, entered softirq %u %s %p"
70002@@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70003 or_softirq_pending(1UL << nr);
70004 }
70005
70006-void open_softirq(int nr, void (*action)(struct softirq_action *))
70007+void open_softirq(int nr, void (*action)(void))
70008 {
70009- softirq_vec[nr].action = action;
70010+ pax_open_kernel();
70011+ *(void **)&softirq_vec[nr].action = action;
70012+ pax_close_kernel();
70013 }
70014
70015 /*
70016@@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70017
70018 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70019
70020-static void tasklet_action(struct softirq_action *a)
70021+static void tasklet_action(void)
70022 {
70023 struct tasklet_struct *list;
70024
70025@@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70026 }
70027 }
70028
70029-static void tasklet_hi_action(struct softirq_action *a)
70030+static void tasklet_hi_action(void)
70031 {
70032 struct tasklet_struct *list;
70033
70034diff --git a/kernel/srcu.c b/kernel/srcu.c
70035index 2095be3..9a5b89d 100644
70036--- a/kernel/srcu.c
70037+++ b/kernel/srcu.c
70038@@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70039 preempt_disable();
70040 idx = rcu_dereference_index_check(sp->completed,
70041 rcu_read_lock_sched_held()) & 0x1;
70042- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70043+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70044 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70045- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70046+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70047 preempt_enable();
70048 return idx;
70049 }
70050@@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70051 {
70052 preempt_disable();
70053 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70054- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70055+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70056 preempt_enable();
70057 }
70058 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70059diff --git a/kernel/sys.c b/kernel/sys.c
70060index 241507f..52a8564 100644
70061--- a/kernel/sys.c
70062+++ b/kernel/sys.c
70063@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70064 error = -EACCES;
70065 goto out;
70066 }
70067+
70068+ if (gr_handle_chroot_setpriority(p, niceval)) {
70069+ error = -EACCES;
70070+ goto out;
70071+ }
70072+
70073 no_nice = security_task_setnice(p, niceval);
70074 if (no_nice) {
70075 error = no_nice;
70076@@ -594,6 +600,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70077 goto error;
70078 }
70079
70080+ if (gr_check_group_change(new->gid, new->egid, -1))
70081+ goto error;
70082+
70083 if (rgid != (gid_t) -1 ||
70084 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70085 new->sgid = new->egid;
70086@@ -629,6 +638,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70087 old = current_cred();
70088
70089 retval = -EPERM;
70090+
70091+ if (gr_check_group_change(kgid, kgid, kgid))
70092+ goto error;
70093+
70094 if (nsown_capable(CAP_SETGID))
70095 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70096 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70097@@ -646,7 +659,7 @@ error:
70098 /*
70099 * change the user struct in a credentials set to match the new UID
70100 */
70101-static int set_user(struct cred *new)
70102+int set_user(struct cred *new)
70103 {
70104 struct user_struct *new_user;
70105
70106@@ -726,6 +739,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70107 goto error;
70108 }
70109
70110+ if (gr_check_user_change(new->uid, new->euid, -1))
70111+ goto error;
70112+
70113 if (!uid_eq(new->uid, old->uid)) {
70114 retval = set_user(new);
70115 if (retval < 0)
70116@@ -776,6 +792,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70117 old = current_cred();
70118
70119 retval = -EPERM;
70120+
70121+ if (gr_check_crash_uid(kuid))
70122+ goto error;
70123+ if (gr_check_user_change(kuid, kuid, kuid))
70124+ goto error;
70125+
70126 if (nsown_capable(CAP_SETUID)) {
70127 new->suid = new->uid = kuid;
70128 if (!uid_eq(kuid, old->uid)) {
70129@@ -845,6 +867,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70130 goto error;
70131 }
70132
70133+ if (gr_check_user_change(kruid, keuid, -1))
70134+ goto error;
70135+
70136 if (ruid != (uid_t) -1) {
70137 new->uid = kruid;
70138 if (!uid_eq(kruid, old->uid)) {
70139@@ -927,6 +952,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70140 goto error;
70141 }
70142
70143+ if (gr_check_group_change(krgid, kegid, -1))
70144+ goto error;
70145+
70146 if (rgid != (gid_t) -1)
70147 new->gid = krgid;
70148 if (egid != (gid_t) -1)
70149@@ -980,6 +1008,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70150 if (!uid_valid(kuid))
70151 return old_fsuid;
70152
70153+ if (gr_check_user_change(-1, -1, kuid))
70154+ goto error;
70155+
70156 new = prepare_creds();
70157 if (!new)
70158 return old_fsuid;
70159@@ -994,6 +1025,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70160 }
70161 }
70162
70163+error:
70164 abort_creds(new);
70165 return old_fsuid;
70166
70167@@ -1026,12 +1058,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70168 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70169 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70170 nsown_capable(CAP_SETGID)) {
70171+ if (gr_check_group_change(-1, -1, kgid))
70172+ goto error;
70173+
70174 if (!gid_eq(kgid, old->fsgid)) {
70175 new->fsgid = kgid;
70176 goto change_okay;
70177 }
70178 }
70179
70180+error:
70181 abort_creds(new);
70182 return old_fsgid;
70183
70184@@ -1264,13 +1300,13 @@ DECLARE_RWSEM(uts_sem);
70185 * Work around broken programs that cannot handle "Linux 3.0".
70186 * Instead we map 3.x to 2.6.40+x, so e.g. 3.0 would be 2.6.40
70187 */
70188-static int override_release(char __user *release, int len)
70189+static int override_release(char __user *release, size_t len)
70190 {
70191 int ret = 0;
70192- char buf[65];
70193
70194 if (current->personality & UNAME26) {
70195- char *rest = UTS_RELEASE;
70196+ char buf[65] = { 0 };
70197+ const char *rest = UTS_RELEASE;
70198 int ndots = 0;
70199 unsigned v;
70200
70201@@ -1282,7 +1318,10 @@ static int override_release(char __user *release, int len)
70202 rest++;
70203 }
70204 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
70205+ if (sizeof buf < len)
70206+ len = sizeof buf;
70207 snprintf(buf, len, "2.6.%u%s", v, rest);
70208+ buf[len - 1] = 0;
70209 ret = copy_to_user(release, buf, len);
70210 }
70211 return ret;
70212@@ -1337,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70213 return -EFAULT;
70214
70215 down_read(&uts_sem);
70216- error = __copy_to_user(&name->sysname, &utsname()->sysname,
70217+ error = __copy_to_user(name->sysname, &utsname()->sysname,
70218 __OLD_UTS_LEN);
70219 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70220- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70221+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
70222 __OLD_UTS_LEN);
70223 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70224- error |= __copy_to_user(&name->release, &utsname()->release,
70225+ error |= __copy_to_user(name->release, &utsname()->release,
70226 __OLD_UTS_LEN);
70227 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70228- error |= __copy_to_user(&name->version, &utsname()->version,
70229+ error |= __copy_to_user(name->version, &utsname()->version,
70230 __OLD_UTS_LEN);
70231 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70232- error |= __copy_to_user(&name->machine, &utsname()->machine,
70233+ error |= __copy_to_user(name->machine, &utsname()->machine,
70234 __OLD_UTS_LEN);
70235 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70236 up_read(&uts_sem);
70237@@ -2023,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70238 error = get_dumpable(me->mm);
70239 break;
70240 case PR_SET_DUMPABLE:
70241- if (arg2 < 0 || arg2 > 1) {
70242+ if (arg2 > 1) {
70243 error = -EINVAL;
70244 break;
70245 }
70246diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70247index 87174ef..68cbb82 100644
70248--- a/kernel/sysctl.c
70249+++ b/kernel/sysctl.c
70250@@ -92,7 +92,6 @@
70251
70252
70253 #if defined(CONFIG_SYSCTL)
70254-
70255 /* External variables not in a header file. */
70256 extern int sysctl_overcommit_memory;
70257 extern int sysctl_overcommit_ratio;
70258@@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70259 void __user *buffer, size_t *lenp, loff_t *ppos);
70260 #endif
70261
70262-#ifdef CONFIG_PRINTK
70263 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70264 void __user *buffer, size_t *lenp, loff_t *ppos);
70265-#endif
70266
70267 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70268 void __user *buffer, size_t *lenp, loff_t *ppos);
70269@@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70270
70271 #endif
70272
70273+extern struct ctl_table grsecurity_table[];
70274+
70275 static struct ctl_table kern_table[];
70276 static struct ctl_table vm_table[];
70277 static struct ctl_table fs_table[];
70278@@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
70279 int sysctl_legacy_va_layout;
70280 #endif
70281
70282+#ifdef CONFIG_PAX_SOFTMODE
70283+static ctl_table pax_table[] = {
70284+ {
70285+ .procname = "softmode",
70286+ .data = &pax_softmode,
70287+ .maxlen = sizeof(unsigned int),
70288+ .mode = 0600,
70289+ .proc_handler = &proc_dointvec,
70290+ },
70291+
70292+ { }
70293+};
70294+#endif
70295+
70296 /* The default sysctl tables: */
70297
70298 static struct ctl_table sysctl_base_table[] = {
70299@@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
70300 #endif
70301
70302 static struct ctl_table kern_table[] = {
70303+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70304+ {
70305+ .procname = "grsecurity",
70306+ .mode = 0500,
70307+ .child = grsecurity_table,
70308+ },
70309+#endif
70310+
70311+#ifdef CONFIG_PAX_SOFTMODE
70312+ {
70313+ .procname = "pax",
70314+ .mode = 0500,
70315+ .child = pax_table,
70316+ },
70317+#endif
70318+
70319 {
70320 .procname = "sched_child_runs_first",
70321 .data = &sysctl_sched_child_runs_first,
70322@@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
70323 .data = &modprobe_path,
70324 .maxlen = KMOD_PATH_LEN,
70325 .mode = 0644,
70326- .proc_handler = proc_dostring,
70327+ .proc_handler = proc_dostring_modpriv,
70328 },
70329 {
70330 .procname = "modules_disabled",
70331@@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
70332 .extra1 = &zero,
70333 .extra2 = &one,
70334 },
70335+#endif
70336 {
70337 .procname = "kptr_restrict",
70338 .data = &kptr_restrict,
70339 .maxlen = sizeof(int),
70340 .mode = 0644,
70341 .proc_handler = proc_dointvec_minmax_sysadmin,
70342+#ifdef CONFIG_GRKERNSEC_HIDESYM
70343+ .extra1 = &two,
70344+#else
70345 .extra1 = &zero,
70346+#endif
70347 .extra2 = &two,
70348 },
70349-#endif
70350 {
70351 .procname = "ngroups_max",
70352 .data = &ngroups_max,
70353@@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
70354 .proc_handler = proc_dointvec_minmax,
70355 .extra1 = &zero,
70356 },
70357+ {
70358+ .procname = "heap_stack_gap",
70359+ .data = &sysctl_heap_stack_gap,
70360+ .maxlen = sizeof(sysctl_heap_stack_gap),
70361+ .mode = 0644,
70362+ .proc_handler = proc_doulongvec_minmax,
70363+ },
70364 #else
70365 {
70366 .procname = "nr_trim_pages",
70367@@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
70368 buffer, lenp, ppos);
70369 }
70370
70371+int proc_dostring_modpriv(struct ctl_table *table, int write,
70372+ void __user *buffer, size_t *lenp, loff_t *ppos)
70373+{
70374+ if (write && !capable(CAP_SYS_MODULE))
70375+ return -EPERM;
70376+
70377+ return _proc_do_string(table->data, table->maxlen, write,
70378+ buffer, lenp, ppos);
70379+}
70380+
70381 static size_t proc_skip_spaces(char **buf)
70382 {
70383 size_t ret;
70384@@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70385 len = strlen(tmp);
70386 if (len > *size)
70387 len = *size;
70388+ if (len > sizeof(tmp))
70389+ len = sizeof(tmp);
70390 if (copy_to_user(*buf, tmp, len))
70391 return -EFAULT;
70392 *size -= len;
70393@@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
70394 return err;
70395 }
70396
70397-#ifdef CONFIG_PRINTK
70398 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70399 void __user *buffer, size_t *lenp, loff_t *ppos)
70400 {
70401@@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70402
70403 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70404 }
70405-#endif
70406
70407 struct do_proc_dointvec_minmax_conv_param {
70408 int *min;
70409@@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70410 *i = val;
70411 } else {
70412 val = convdiv * (*i) / convmul;
70413- if (!first)
70414+ if (!first) {
70415 err = proc_put_char(&buffer, &left, '\t');
70416+ if (err)
70417+ break;
70418+ }
70419 err = proc_put_long(&buffer, &left, val, false);
70420 if (err)
70421 break;
70422@@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
70423 return -ENOSYS;
70424 }
70425
70426+int proc_dostring_modpriv(struct ctl_table *table, int write,
70427+ void __user *buffer, size_t *lenp, loff_t *ppos)
70428+{
70429+ return -ENOSYS;
70430+}
70431+
70432 int proc_dointvec(struct ctl_table *table, int write,
70433 void __user *buffer, size_t *lenp, loff_t *ppos)
70434 {
70435@@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70436 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70437 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70438 EXPORT_SYMBOL(proc_dostring);
70439+EXPORT_SYMBOL(proc_dostring_modpriv);
70440 EXPORT_SYMBOL(proc_doulongvec_minmax);
70441 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70442diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70443index 65bdcf1..21eb831 100644
70444--- a/kernel/sysctl_binary.c
70445+++ b/kernel/sysctl_binary.c
70446@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70447 int i;
70448
70449 set_fs(KERNEL_DS);
70450- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70451+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70452 set_fs(old_fs);
70453 if (result < 0)
70454 goto out_kfree;
70455@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70456 }
70457
70458 set_fs(KERNEL_DS);
70459- result = vfs_write(file, buffer, str - buffer, &pos);
70460+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70461 set_fs(old_fs);
70462 if (result < 0)
70463 goto out_kfree;
70464@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70465 int i;
70466
70467 set_fs(KERNEL_DS);
70468- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70469+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70470 set_fs(old_fs);
70471 if (result < 0)
70472 goto out_kfree;
70473@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70474 }
70475
70476 set_fs(KERNEL_DS);
70477- result = vfs_write(file, buffer, str - buffer, &pos);
70478+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70479 set_fs(old_fs);
70480 if (result < 0)
70481 goto out_kfree;
70482@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70483 int i;
70484
70485 set_fs(KERNEL_DS);
70486- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70487+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70488 set_fs(old_fs);
70489 if (result < 0)
70490 goto out;
70491@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70492 __le16 dnaddr;
70493
70494 set_fs(KERNEL_DS);
70495- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70496+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70497 set_fs(old_fs);
70498 if (result < 0)
70499 goto out;
70500@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70501 le16_to_cpu(dnaddr) & 0x3ff);
70502
70503 set_fs(KERNEL_DS);
70504- result = vfs_write(file, buf, len, &pos);
70505+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70506 set_fs(old_fs);
70507 if (result < 0)
70508 goto out;
70509diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70510index d0a3279..db0ad99 100644
70511--- a/kernel/taskstats.c
70512+++ b/kernel/taskstats.c
70513@@ -27,9 +27,12 @@
70514 #include <linux/cgroup.h>
70515 #include <linux/fs.h>
70516 #include <linux/file.h>
70517+#include <linux/grsecurity.h>
70518 #include <net/genetlink.h>
70519 #include <linux/atomic.h>
70520
70521+extern int gr_is_taskstats_denied(int pid);
70522+
70523 /*
70524 * Maximum length of a cpumask that can be specified in
70525 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70526@@ -561,6 +564,9 @@ err:
70527
70528 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70529 {
70530+ if (gr_is_taskstats_denied(current->pid))
70531+ return -EACCES;
70532+
70533 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70534 return cmd_attr_register_cpumask(info);
70535 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70536diff --git a/kernel/time.c b/kernel/time.c
70537index ba744cf..267b7c5 100644
70538--- a/kernel/time.c
70539+++ b/kernel/time.c
70540@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70541 return error;
70542
70543 if (tz) {
70544+ /* we log in do_settimeofday called below, so don't log twice
70545+ */
70546+ if (!tv)
70547+ gr_log_timechange();
70548+
70549 sys_tz = *tz;
70550 update_vsyscall_tz();
70551 if (firsttime) {
70552diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70553index aa27d39..34d221c 100644
70554--- a/kernel/time/alarmtimer.c
70555+++ b/kernel/time/alarmtimer.c
70556@@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70557 struct platform_device *pdev;
70558 int error = 0;
70559 int i;
70560- struct k_clock alarm_clock = {
70561+ static struct k_clock alarm_clock = {
70562 .clock_getres = alarm_clock_getres,
70563 .clock_get = alarm_clock_get,
70564 .timer_create = alarm_timer_create,
70565diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70566index f113755..ec24223 100644
70567--- a/kernel/time/tick-broadcast.c
70568+++ b/kernel/time/tick-broadcast.c
70569@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70570 * then clear the broadcast bit.
70571 */
70572 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70573- int cpu = smp_processor_id();
70574+ cpu = smp_processor_id();
70575
70576 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70577 tick_broadcast_clear_oneshot(cpu);
70578diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70579index d3b91e7..2a4be68 100644
70580--- a/kernel/time/timekeeping.c
70581+++ b/kernel/time/timekeeping.c
70582@@ -14,6 +14,7 @@
70583 #include <linux/init.h>
70584 #include <linux/mm.h>
70585 #include <linux/sched.h>
70586+#include <linux/grsecurity.h>
70587 #include <linux/syscore_ops.h>
70588 #include <linux/clocksource.h>
70589 #include <linux/jiffies.h>
70590@@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
70591 if (!timespec_valid_strict(tv))
70592 return -EINVAL;
70593
70594+ gr_log_timechange();
70595+
70596 write_seqlock_irqsave(&tk->lock, flags);
70597
70598 timekeeping_forward_now(tk);
70599diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70600index af5a7e9..715611a 100644
70601--- a/kernel/time/timer_list.c
70602+++ b/kernel/time/timer_list.c
70603@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70604
70605 static void print_name_offset(struct seq_file *m, void *sym)
70606 {
70607+#ifdef CONFIG_GRKERNSEC_HIDESYM
70608+ SEQ_printf(m, "<%p>", NULL);
70609+#else
70610 char symname[KSYM_NAME_LEN];
70611
70612 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70613 SEQ_printf(m, "<%pK>", sym);
70614 else
70615 SEQ_printf(m, "%s", symname);
70616+#endif
70617 }
70618
70619 static void
70620@@ -112,7 +116,11 @@ next_one:
70621 static void
70622 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70623 {
70624+#ifdef CONFIG_GRKERNSEC_HIDESYM
70625+ SEQ_printf(m, " .base: %p\n", NULL);
70626+#else
70627 SEQ_printf(m, " .base: %pK\n", base);
70628+#endif
70629 SEQ_printf(m, " .index: %d\n",
70630 base->index);
70631 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70632@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70633 {
70634 struct proc_dir_entry *pe;
70635
70636+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70637+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70638+#else
70639 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70640+#endif
70641 if (!pe)
70642 return -ENOMEM;
70643 return 0;
70644diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70645index 0b537f2..9e71eca 100644
70646--- a/kernel/time/timer_stats.c
70647+++ b/kernel/time/timer_stats.c
70648@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70649 static unsigned long nr_entries;
70650 static struct entry entries[MAX_ENTRIES];
70651
70652-static atomic_t overflow_count;
70653+static atomic_unchecked_t overflow_count;
70654
70655 /*
70656 * The entries are in a hash-table, for fast lookup:
70657@@ -140,7 +140,7 @@ static void reset_entries(void)
70658 nr_entries = 0;
70659 memset(entries, 0, sizeof(entries));
70660 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70661- atomic_set(&overflow_count, 0);
70662+ atomic_set_unchecked(&overflow_count, 0);
70663 }
70664
70665 static struct entry *alloc_entry(void)
70666@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70667 if (likely(entry))
70668 entry->count++;
70669 else
70670- atomic_inc(&overflow_count);
70671+ atomic_inc_unchecked(&overflow_count);
70672
70673 out_unlock:
70674 raw_spin_unlock_irqrestore(lock, flags);
70675@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70676
70677 static void print_name_offset(struct seq_file *m, unsigned long addr)
70678 {
70679+#ifdef CONFIG_GRKERNSEC_HIDESYM
70680+ seq_printf(m, "<%p>", NULL);
70681+#else
70682 char symname[KSYM_NAME_LEN];
70683
70684 if (lookup_symbol_name(addr, symname) < 0)
70685 seq_printf(m, "<%p>", (void *)addr);
70686 else
70687 seq_printf(m, "%s", symname);
70688+#endif
70689 }
70690
70691 static int tstats_show(struct seq_file *m, void *v)
70692@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70693
70694 seq_puts(m, "Timer Stats Version: v0.2\n");
70695 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70696- if (atomic_read(&overflow_count))
70697+ if (atomic_read_unchecked(&overflow_count))
70698 seq_printf(m, "Overflow: %d entries\n",
70699- atomic_read(&overflow_count));
70700+ atomic_read_unchecked(&overflow_count));
70701
70702 for (i = 0; i < nr_entries; i++) {
70703 entry = entries + i;
70704@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70705 {
70706 struct proc_dir_entry *pe;
70707
70708+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70709+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70710+#else
70711 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70712+#endif
70713 if (!pe)
70714 return -ENOMEM;
70715 return 0;
70716diff --git a/kernel/timer.c b/kernel/timer.c
70717index 8c5e7b9..968d02c 100644
70718--- a/kernel/timer.c
70719+++ b/kernel/timer.c
70720@@ -1375,7 +1375,7 @@ void update_process_times(int user_tick)
70721 /*
70722 * This function runs timers and the timer-tq in bottom half context.
70723 */
70724-static void run_timer_softirq(struct softirq_action *h)
70725+static void run_timer_softirq(void)
70726 {
70727 struct tvec_base *base = __this_cpu_read(tvec_bases);
70728
70729diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70730index c0bd030..62a1927 100644
70731--- a/kernel/trace/blktrace.c
70732+++ b/kernel/trace/blktrace.c
70733@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70734 struct blk_trace *bt = filp->private_data;
70735 char buf[16];
70736
70737- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70738+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70739
70740 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70741 }
70742@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70743 return 1;
70744
70745 bt = buf->chan->private_data;
70746- atomic_inc(&bt->dropped);
70747+ atomic_inc_unchecked(&bt->dropped);
70748 return 0;
70749 }
70750
70751@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70752
70753 bt->dir = dir;
70754 bt->dev = dev;
70755- atomic_set(&bt->dropped, 0);
70756+ atomic_set_unchecked(&bt->dropped, 0);
70757
70758 ret = -EIO;
70759 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70760diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70761index b4f20fb..483c5fa 100644
70762--- a/kernel/trace/ftrace.c
70763+++ b/kernel/trace/ftrace.c
70764@@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70765 if (unlikely(ftrace_disabled))
70766 return 0;
70767
70768+ ret = ftrace_arch_code_modify_prepare();
70769+ FTRACE_WARN_ON(ret);
70770+ if (ret)
70771+ return 0;
70772+
70773 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70774+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70775 if (ret) {
70776 ftrace_bug(ret, ip);
70777- return 0;
70778 }
70779- return 1;
70780+ return ret ? 0 : 1;
70781 }
70782
70783 /*
70784@@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70785
70786 int
70787 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70788- void *data)
70789+ void *data)
70790 {
70791 struct ftrace_func_probe *entry;
70792 struct ftrace_page *pg;
70793@@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70794 if (!count)
70795 return 0;
70796
70797+ pax_open_kernel();
70798 sort(start, count, sizeof(*start),
70799 ftrace_cmp_ips, ftrace_swap_ips);
70800+ pax_close_kernel();
70801
70802 start_pg = ftrace_allocate_pages(count);
70803 if (!start_pg)
70804diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70805index 5c38c81..88012af 100644
70806--- a/kernel/trace/trace.c
70807+++ b/kernel/trace/trace.c
70808@@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70809 };
70810 #endif
70811
70812-static struct dentry *d_tracer;
70813-
70814 struct dentry *tracing_init_dentry(void)
70815 {
70816+ static struct dentry *d_tracer;
70817 static int once;
70818
70819 if (d_tracer)
70820@@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
70821 return d_tracer;
70822 }
70823
70824-static struct dentry *d_percpu;
70825-
70826 struct dentry *tracing_dentry_percpu(void)
70827 {
70828+ static struct dentry *d_percpu;
70829 static int once;
70830 struct dentry *d_tracer;
70831
70832diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70833index 29111da..d190fe2 100644
70834--- a/kernel/trace/trace_events.c
70835+++ b/kernel/trace/trace_events.c
70836@@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70837 struct ftrace_module_file_ops {
70838 struct list_head list;
70839 struct module *mod;
70840- struct file_operations id;
70841- struct file_operations enable;
70842- struct file_operations format;
70843- struct file_operations filter;
70844 };
70845
70846 static struct ftrace_module_file_ops *
70847@@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70848
70849 file_ops->mod = mod;
70850
70851- file_ops->id = ftrace_event_id_fops;
70852- file_ops->id.owner = mod;
70853-
70854- file_ops->enable = ftrace_enable_fops;
70855- file_ops->enable.owner = mod;
70856-
70857- file_ops->filter = ftrace_event_filter_fops;
70858- file_ops->filter.owner = mod;
70859-
70860- file_ops->format = ftrace_event_format_fops;
70861- file_ops->format.owner = mod;
70862+ pax_open_kernel();
70863+ *(void **)&mod->trace_id.owner = mod;
70864+ *(void **)&mod->trace_enable.owner = mod;
70865+ *(void **)&mod->trace_filter.owner = mod;
70866+ *(void **)&mod->trace_format.owner = mod;
70867+ pax_close_kernel();
70868
70869 list_add(&file_ops->list, &ftrace_module_file_list);
70870
70871@@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70872
70873 for_each_event(call, start, end) {
70874 __trace_add_event_call(*call, mod,
70875- &file_ops->id, &file_ops->enable,
70876- &file_ops->filter, &file_ops->format);
70877+ &mod->trace_id, &mod->trace_enable,
70878+ &mod->trace_filter, &mod->trace_format);
70879 }
70880 }
70881
70882diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70883index fd3c8aa..5f324a6 100644
70884--- a/kernel/trace/trace_mmiotrace.c
70885+++ b/kernel/trace/trace_mmiotrace.c
70886@@ -24,7 +24,7 @@ struct header_iter {
70887 static struct trace_array *mmio_trace_array;
70888 static bool overrun_detected;
70889 static unsigned long prev_overruns;
70890-static atomic_t dropped_count;
70891+static atomic_unchecked_t dropped_count;
70892
70893 static void mmio_reset_data(struct trace_array *tr)
70894 {
70895@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70896
70897 static unsigned long count_overruns(struct trace_iterator *iter)
70898 {
70899- unsigned long cnt = atomic_xchg(&dropped_count, 0);
70900+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70901 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70902
70903 if (over > prev_overruns)
70904@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70905 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70906 sizeof(*entry), 0, pc);
70907 if (!event) {
70908- atomic_inc(&dropped_count);
70909+ atomic_inc_unchecked(&dropped_count);
70910 return;
70911 }
70912 entry = ring_buffer_event_data(event);
70913@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70914 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70915 sizeof(*entry), 0, pc);
70916 if (!event) {
70917- atomic_inc(&dropped_count);
70918+ atomic_inc_unchecked(&dropped_count);
70919 return;
70920 }
70921 entry = ring_buffer_event_data(event);
70922diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70923index 123b189..97b81f5 100644
70924--- a/kernel/trace/trace_output.c
70925+++ b/kernel/trace/trace_output.c
70926@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
70927
70928 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70929 if (!IS_ERR(p)) {
70930- p = mangle_path(s->buffer + s->len, p, "\n");
70931+ p = mangle_path(s->buffer + s->len, p, "\n\\");
70932 if (p) {
70933 s->len = p - s->buffer;
70934 return 1;
70935diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70936index d4545f4..a9010a1 100644
70937--- a/kernel/trace/trace_stack.c
70938+++ b/kernel/trace/trace_stack.c
70939@@ -53,7 +53,7 @@ static inline void check_stack(void)
70940 return;
70941
70942 /* we do not handle interrupt stacks yet */
70943- if (!object_is_on_stack(&this_size))
70944+ if (!object_starts_on_stack(&this_size))
70945 return;
70946
70947 local_irq_save(flags);
70948diff --git a/kernel/workqueue.c b/kernel/workqueue.c
70949index 3c5a79e..9d2cea4 100644
70950--- a/kernel/workqueue.c
70951+++ b/kernel/workqueue.c
70952@@ -1422,7 +1422,7 @@ retry:
70953 /* morph UNBOUND to REBIND atomically */
70954 worker_flags &= ~WORKER_UNBOUND;
70955 worker_flags |= WORKER_REBIND;
70956- ACCESS_ONCE(worker->flags) = worker_flags;
70957+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
70958
70959 idle_rebind.cnt++;
70960 worker->idle_rebind = &idle_rebind;
70961@@ -1448,7 +1448,7 @@ retry:
70962 /* morph UNBOUND to REBIND atomically */
70963 worker_flags &= ~WORKER_UNBOUND;
70964 worker_flags |= WORKER_REBIND;
70965- ACCESS_ONCE(worker->flags) = worker_flags;
70966+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
70967
70968 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
70969 work_data_bits(rebind_work)))
70970diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70971index 2403a63..5c4be4c 100644
70972--- a/lib/Kconfig.debug
70973+++ b/lib/Kconfig.debug
70974@@ -1252,6 +1252,7 @@ config LATENCYTOP
70975 depends on DEBUG_KERNEL
70976 depends on STACKTRACE_SUPPORT
70977 depends on PROC_FS
70978+ depends on !GRKERNSEC_HIDESYM
70979 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
70980 select KALLSYMS
70981 select KALLSYMS_ALL
70982@@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
70983
70984 config PROVIDE_OHCI1394_DMA_INIT
70985 bool "Remote debugging over FireWire early on boot"
70986- depends on PCI && X86
70987+ depends on PCI && X86 && !GRKERNSEC
70988 help
70989 If you want to debug problems which hang or crash the kernel early
70990 on boot and the crashing machine has a FireWire port, you can use
70991@@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
70992
70993 config FIREWIRE_OHCI_REMOTE_DMA
70994 bool "Remote debugging over FireWire with firewire-ohci"
70995- depends on FIREWIRE_OHCI
70996+ depends on FIREWIRE_OHCI && !GRKERNSEC
70997 help
70998 This option lets you use the FireWire bus for remote debugging
70999 with help of the firewire-ohci driver. It enables unfiltered
71000diff --git a/lib/bitmap.c b/lib/bitmap.c
71001index 06fdfa1..97c5c7d 100644
71002--- a/lib/bitmap.c
71003+++ b/lib/bitmap.c
71004@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71005 {
71006 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71007 u32 chunk;
71008- const char __user __force *ubuf = (const char __user __force *)buf;
71009+ const char __user *ubuf = (const char __force_user *)buf;
71010
71011 bitmap_zero(maskp, nmaskbits);
71012
71013@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71014 {
71015 if (!access_ok(VERIFY_READ, ubuf, ulen))
71016 return -EFAULT;
71017- return __bitmap_parse((const char __force *)ubuf,
71018+ return __bitmap_parse((const char __force_kernel *)ubuf,
71019 ulen, 1, maskp, nmaskbits);
71020
71021 }
71022@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71023 {
71024 unsigned a, b;
71025 int c, old_c, totaldigits;
71026- const char __user __force *ubuf = (const char __user __force *)buf;
71027+ const char __user *ubuf = (const char __force_user *)buf;
71028 int exp_digit, in_range;
71029
71030 totaldigits = c = 0;
71031@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71032 {
71033 if (!access_ok(VERIFY_READ, ubuf, ulen))
71034 return -EFAULT;
71035- return __bitmap_parselist((const char __force *)ubuf,
71036+ return __bitmap_parselist((const char __force_kernel *)ubuf,
71037 ulen, 1, maskp, nmaskbits);
71038 }
71039 EXPORT_SYMBOL(bitmap_parselist_user);
71040diff --git a/lib/bug.c b/lib/bug.c
71041index a28c141..2bd3d95 100644
71042--- a/lib/bug.c
71043+++ b/lib/bug.c
71044@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71045 return BUG_TRAP_TYPE_NONE;
71046
71047 bug = find_bug(bugaddr);
71048+ if (!bug)
71049+ return BUG_TRAP_TYPE_NONE;
71050
71051 file = NULL;
71052 line = 0;
71053diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71054index d11808c..dc2d6f8 100644
71055--- a/lib/debugobjects.c
71056+++ b/lib/debugobjects.c
71057@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71058 if (limit > 4)
71059 return;
71060
71061- is_on_stack = object_is_on_stack(addr);
71062+ is_on_stack = object_starts_on_stack(addr);
71063 if (is_on_stack == onstack)
71064 return;
71065
71066diff --git a/lib/devres.c b/lib/devres.c
71067index 80b9c76..9e32279 100644
71068--- a/lib/devres.c
71069+++ b/lib/devres.c
71070@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71071 void devm_iounmap(struct device *dev, void __iomem *addr)
71072 {
71073 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71074- (void *)addr));
71075+ (void __force *)addr));
71076 iounmap(addr);
71077 }
71078 EXPORT_SYMBOL(devm_iounmap);
71079@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71080 {
71081 ioport_unmap(addr);
71082 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71083- devm_ioport_map_match, (void *)addr));
71084+ devm_ioport_map_match, (void __force *)addr));
71085 }
71086 EXPORT_SYMBOL(devm_ioport_unmap);
71087
71088diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71089index 66ce414..6f0a0dd 100644
71090--- a/lib/dma-debug.c
71091+++ b/lib/dma-debug.c
71092@@ -924,7 +924,7 @@ out:
71093
71094 static void check_for_stack(struct device *dev, void *addr)
71095 {
71096- if (object_is_on_stack(addr))
71097+ if (object_starts_on_stack(addr))
71098 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71099 "stack [addr=%p]\n", addr);
71100 }
71101diff --git a/lib/inflate.c b/lib/inflate.c
71102index 013a761..c28f3fc 100644
71103--- a/lib/inflate.c
71104+++ b/lib/inflate.c
71105@@ -269,7 +269,7 @@ static void free(void *where)
71106 malloc_ptr = free_mem_ptr;
71107 }
71108 #else
71109-#define malloc(a) kmalloc(a, GFP_KERNEL)
71110+#define malloc(a) kmalloc((a), GFP_KERNEL)
71111 #define free(a) kfree(a)
71112 #endif
71113
71114diff --git a/lib/ioremap.c b/lib/ioremap.c
71115index 0c9216c..863bd89 100644
71116--- a/lib/ioremap.c
71117+++ b/lib/ioremap.c
71118@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71119 unsigned long next;
71120
71121 phys_addr -= addr;
71122- pmd = pmd_alloc(&init_mm, pud, addr);
71123+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71124 if (!pmd)
71125 return -ENOMEM;
71126 do {
71127@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71128 unsigned long next;
71129
71130 phys_addr -= addr;
71131- pud = pud_alloc(&init_mm, pgd, addr);
71132+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
71133 if (!pud)
71134 return -ENOMEM;
71135 do {
71136diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71137index bd2bea9..6b3c95e 100644
71138--- a/lib/is_single_threaded.c
71139+++ b/lib/is_single_threaded.c
71140@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71141 struct task_struct *p, *t;
71142 bool ret;
71143
71144+ if (!mm)
71145+ return true;
71146+
71147 if (atomic_read(&task->signal->live) != 1)
71148 return false;
71149
71150diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71151index e796429..6e38f9f 100644
71152--- a/lib/radix-tree.c
71153+++ b/lib/radix-tree.c
71154@@ -92,7 +92,7 @@ struct radix_tree_preload {
71155 int nr;
71156 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71157 };
71158-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71159+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71160
71161 static inline void *ptr_to_indirect(void *ptr)
71162 {
71163diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71164index 0e33754..50a0e63 100644
71165--- a/lib/vsprintf.c
71166+++ b/lib/vsprintf.c
71167@@ -16,6 +16,9 @@
71168 * - scnprintf and vscnprintf
71169 */
71170
71171+#ifdef CONFIG_GRKERNSEC_HIDESYM
71172+#define __INCLUDED_BY_HIDESYM 1
71173+#endif
71174 #include <stdarg.h>
71175 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71176 #include <linux/types.h>
71177@@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71178 char sym[KSYM_SYMBOL_LEN];
71179 if (ext == 'B')
71180 sprint_backtrace(sym, value);
71181- else if (ext != 'f' && ext != 's')
71182+ else if (ext != 'f' && ext != 's' && ext != 'a')
71183 sprint_symbol(sym, value);
71184 else
71185 sprint_symbol_no_offset(sym, value);
71186@@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71187 return number(buf, end, *(const netdev_features_t *)addr, spec);
71188 }
71189
71190+#ifdef CONFIG_GRKERNSEC_HIDESYM
71191+int kptr_restrict __read_mostly = 2;
71192+#else
71193 int kptr_restrict __read_mostly;
71194+#endif
71195
71196 /*
71197 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71198@@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71199 * - 'S' For symbolic direct pointers with offset
71200 * - 's' For symbolic direct pointers without offset
71201 * - 'B' For backtraced symbolic direct pointers with offset
71202+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71203+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71204 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71205 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71206 * - 'M' For a 6-byte MAC address, it prints the address in the
71207@@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71208
71209 if (!ptr && *fmt != 'K') {
71210 /*
71211- * Print (null) with the same width as a pointer so it makes
71212+ * Print (nil) with the same width as a pointer so it makes
71213 * tabular output look nice.
71214 */
71215 if (spec.field_width == -1)
71216 spec.field_width = default_width;
71217- return string(buf, end, "(null)", spec);
71218+ return string(buf, end, "(nil)", spec);
71219 }
71220
71221 switch (*fmt) {
71222@@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71223 /* Fallthrough */
71224 case 'S':
71225 case 's':
71226+#ifdef CONFIG_GRKERNSEC_HIDESYM
71227+ break;
71228+#else
71229+ return symbol_string(buf, end, ptr, spec, *fmt);
71230+#endif
71231+ case 'A':
71232+ case 'a':
71233 case 'B':
71234 return symbol_string(buf, end, ptr, spec, *fmt);
71235 case 'R':
71236@@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71237 va_end(va);
71238 return buf;
71239 }
71240+ case 'P':
71241+ break;
71242 case 'K':
71243 /*
71244 * %pK cannot be used in IRQ context because its test
71245@@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71246 }
71247 break;
71248 }
71249+
71250+#ifdef CONFIG_GRKERNSEC_HIDESYM
71251+ /* 'P' = approved pointers to copy to userland,
71252+ as in the /proc/kallsyms case, as we make it display nothing
71253+ for non-root users, and the real contents for root users
71254+ Also ignore 'K' pointers, since we force their NULLing for non-root users
71255+ above
71256+ */
71257+ if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71258+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71259+ dump_stack();
71260+ ptr = NULL;
71261+ }
71262+#endif
71263+
71264 spec.flags |= SMALL;
71265 if (spec.field_width == -1) {
71266 spec.field_width = default_width;
71267@@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71268 typeof(type) value; \
71269 if (sizeof(type) == 8) { \
71270 args = PTR_ALIGN(args, sizeof(u32)); \
71271- *(u32 *)&value = *(u32 *)args; \
71272- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71273+ *(u32 *)&value = *(const u32 *)args; \
71274+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71275 } else { \
71276 args = PTR_ALIGN(args, sizeof(type)); \
71277- value = *(typeof(type) *)args; \
71278+ value = *(const typeof(type) *)args; \
71279 } \
71280 args += sizeof(type); \
71281 value; \
71282@@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71283 case FORMAT_TYPE_STR: {
71284 const char *str_arg = args;
71285 args += strlen(str_arg) + 1;
71286- str = string(str, end, (char *)str_arg, spec);
71287+ str = string(str, end, str_arg, spec);
71288 break;
71289 }
71290
71291diff --git a/localversion-grsec b/localversion-grsec
71292new file mode 100644
71293index 0000000..7cd6065
71294--- /dev/null
71295+++ b/localversion-grsec
71296@@ -0,0 +1 @@
71297+-grsec
71298diff --git a/mm/Kconfig b/mm/Kconfig
71299index d5c8019..f513038 100644
71300--- a/mm/Kconfig
71301+++ b/mm/Kconfig
71302@@ -251,10 +251,10 @@ config KSM
71303 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71304
71305 config DEFAULT_MMAP_MIN_ADDR
71306- int "Low address space to protect from user allocation"
71307+ int "Low address space to protect from user allocation"
71308 depends on MMU
71309- default 4096
71310- help
71311+ default 65536
71312+ help
71313 This is the portion of low virtual memory which should be protected
71314 from userspace allocation. Keeping a user from writing to low pages
71315 can help reduce the impact of kernel NULL pointer bugs.
71316@@ -285,7 +285,7 @@ config MEMORY_FAILURE
71317
71318 config HWPOISON_INJECT
71319 tristate "HWPoison pages injector"
71320- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71321+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71322 select PROC_PAGE_MONITOR
71323
71324 config NOMMU_INITIAL_TRIM_EXCESS
71325diff --git a/mm/filemap.c b/mm/filemap.c
71326index 3843445..4fe6833 100644
71327--- a/mm/filemap.c
71328+++ b/mm/filemap.c
71329@@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71330 struct address_space *mapping = file->f_mapping;
71331
71332 if (!mapping->a_ops->readpage)
71333- return -ENOEXEC;
71334+ return -ENODEV;
71335 file_accessed(file);
71336 vma->vm_ops = &generic_file_vm_ops;
71337 vma->vm_flags |= VM_CAN_NONLINEAR;
71338@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71339 *pos = i_size_read(inode);
71340
71341 if (limit != RLIM_INFINITY) {
71342+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71343 if (*pos >= limit) {
71344 send_sig(SIGXFSZ, current, 0);
71345 return -EFBIG;
71346diff --git a/mm/fremap.c b/mm/fremap.c
71347index 9ed4fd4..c42648d 100644
71348--- a/mm/fremap.c
71349+++ b/mm/fremap.c
71350@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71351 retry:
71352 vma = find_vma(mm, start);
71353
71354+#ifdef CONFIG_PAX_SEGMEXEC
71355+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71356+ goto out;
71357+#endif
71358+
71359 /*
71360 * Make sure the vma is shared, that it supports prefaulting,
71361 * and that the remapped range is valid and fully within
71362diff --git a/mm/highmem.c b/mm/highmem.c
71363index d517cd1..006a1c5 100644
71364--- a/mm/highmem.c
71365+++ b/mm/highmem.c
71366@@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
71367 * So no dangers, even with speculative execution.
71368 */
71369 page = pte_page(pkmap_page_table[i]);
71370+ pax_open_kernel();
71371 pte_clear(&init_mm, (unsigned long)page_address(page),
71372 &pkmap_page_table[i]);
71373-
71374+ pax_close_kernel();
71375 set_page_address(page, NULL);
71376 need_flush = 1;
71377 }
71378@@ -198,9 +199,11 @@ start:
71379 }
71380 }
71381 vaddr = PKMAP_ADDR(last_pkmap_nr);
71382+
71383+ pax_open_kernel();
71384 set_pte_at(&init_mm, vaddr,
71385 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71386-
71387+ pax_close_kernel();
71388 pkmap_count[last_pkmap_nr] = 1;
71389 set_page_address(page, (void *)vaddr);
71390
71391diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71392index 141dbb6..ebff057 100644
71393--- a/mm/huge_memory.c
71394+++ b/mm/huge_memory.c
71395@@ -735,7 +735,7 @@ out:
71396 * run pte_offset_map on the pmd, if an huge pmd could
71397 * materialize from under us from a different thread.
71398 */
71399- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71400+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71401 return VM_FAULT_OOM;
71402 /* if an huge pmd materialized from under us just retry later */
71403 if (unlikely(pmd_trans_huge(*pmd)))
71404diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71405index bc72712..b9d5ae4 100644
71406--- a/mm/hugetlb.c
71407+++ b/mm/hugetlb.c
71408@@ -2511,6 +2511,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71409 return 1;
71410 }
71411
71412+#ifdef CONFIG_PAX_SEGMEXEC
71413+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71414+{
71415+ struct mm_struct *mm = vma->vm_mm;
71416+ struct vm_area_struct *vma_m;
71417+ unsigned long address_m;
71418+ pte_t *ptep_m;
71419+
71420+ vma_m = pax_find_mirror_vma(vma);
71421+ if (!vma_m)
71422+ return;
71423+
71424+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71425+ address_m = address + SEGMEXEC_TASK_SIZE;
71426+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71427+ get_page(page_m);
71428+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
71429+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71430+}
71431+#endif
71432+
71433 /*
71434 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71435 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71436@@ -2627,6 +2648,11 @@ retry_avoidcopy:
71437 make_huge_pte(vma, new_page, 1));
71438 page_remove_rmap(old_page);
71439 hugepage_add_new_anon_rmap(new_page, vma, address);
71440+
71441+#ifdef CONFIG_PAX_SEGMEXEC
71442+ pax_mirror_huge_pte(vma, address, new_page);
71443+#endif
71444+
71445 /* Make the old page be freed below */
71446 new_page = old_page;
71447 mmu_notifier_invalidate_range_end(mm,
71448@@ -2785,6 +2811,10 @@ retry:
71449 && (vma->vm_flags & VM_SHARED)));
71450 set_huge_pte_at(mm, address, ptep, new_pte);
71451
71452+#ifdef CONFIG_PAX_SEGMEXEC
71453+ pax_mirror_huge_pte(vma, address, page);
71454+#endif
71455+
71456 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71457 /* Optimization, do the COW without a second fault */
71458 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71459@@ -2814,6 +2844,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71460 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71461 struct hstate *h = hstate_vma(vma);
71462
71463+#ifdef CONFIG_PAX_SEGMEXEC
71464+ struct vm_area_struct *vma_m;
71465+#endif
71466+
71467 address &= huge_page_mask(h);
71468
71469 ptep = huge_pte_offset(mm, address);
71470@@ -2827,6 +2861,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71471 VM_FAULT_SET_HINDEX(hstate_index(h));
71472 }
71473
71474+#ifdef CONFIG_PAX_SEGMEXEC
71475+ vma_m = pax_find_mirror_vma(vma);
71476+ if (vma_m) {
71477+ unsigned long address_m;
71478+
71479+ if (vma->vm_start > vma_m->vm_start) {
71480+ address_m = address;
71481+ address -= SEGMEXEC_TASK_SIZE;
71482+ vma = vma_m;
71483+ h = hstate_vma(vma);
71484+ } else
71485+ address_m = address + SEGMEXEC_TASK_SIZE;
71486+
71487+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71488+ return VM_FAULT_OOM;
71489+ address_m &= HPAGE_MASK;
71490+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71491+ }
71492+#endif
71493+
71494 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71495 if (!ptep)
71496 return VM_FAULT_OOM;
71497diff --git a/mm/internal.h b/mm/internal.h
71498index b8c91b3..93e95a3 100644
71499--- a/mm/internal.h
71500+++ b/mm/internal.h
71501@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71502 * in mm/page_alloc.c
71503 */
71504 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71505+extern void free_compound_page(struct page *page);
71506 extern void prep_compound_page(struct page *page, unsigned long order);
71507 #ifdef CONFIG_MEMORY_FAILURE
71508 extern bool is_free_buddy_page(struct page *page);
71509diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71510index 45eb621..6ccd8ea 100644
71511--- a/mm/kmemleak.c
71512+++ b/mm/kmemleak.c
71513@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71514
71515 for (i = 0; i < object->trace_len; i++) {
71516 void *ptr = (void *)object->trace[i];
71517- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71518+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71519 }
71520 }
71521
71522diff --git a/mm/maccess.c b/mm/maccess.c
71523index d53adf9..03a24bf 100644
71524--- a/mm/maccess.c
71525+++ b/mm/maccess.c
71526@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71527 set_fs(KERNEL_DS);
71528 pagefault_disable();
71529 ret = __copy_from_user_inatomic(dst,
71530- (__force const void __user *)src, size);
71531+ (const void __force_user *)src, size);
71532 pagefault_enable();
71533 set_fs(old_fs);
71534
71535@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71536
71537 set_fs(KERNEL_DS);
71538 pagefault_disable();
71539- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71540+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71541 pagefault_enable();
71542 set_fs(old_fs);
71543
71544diff --git a/mm/madvise.c b/mm/madvise.c
71545index 14d260f..b2a80fd 100644
71546--- a/mm/madvise.c
71547+++ b/mm/madvise.c
71548@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71549 pgoff_t pgoff;
71550 unsigned long new_flags = vma->vm_flags;
71551
71552+#ifdef CONFIG_PAX_SEGMEXEC
71553+ struct vm_area_struct *vma_m;
71554+#endif
71555+
71556 switch (behavior) {
71557 case MADV_NORMAL:
71558 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71559@@ -119,6 +123,13 @@ success:
71560 /*
71561 * vm_flags is protected by the mmap_sem held in write mode.
71562 */
71563+
71564+#ifdef CONFIG_PAX_SEGMEXEC
71565+ vma_m = pax_find_mirror_vma(vma);
71566+ if (vma_m)
71567+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71568+#endif
71569+
71570 vma->vm_flags = new_flags;
71571
71572 out:
71573@@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71574 struct vm_area_struct ** prev,
71575 unsigned long start, unsigned long end)
71576 {
71577+
71578+#ifdef CONFIG_PAX_SEGMEXEC
71579+ struct vm_area_struct *vma_m;
71580+#endif
71581+
71582 *prev = vma;
71583 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71584 return -EINVAL;
71585@@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71586 zap_page_range(vma, start, end - start, &details);
71587 } else
71588 zap_page_range(vma, start, end - start, NULL);
71589+
71590+#ifdef CONFIG_PAX_SEGMEXEC
71591+ vma_m = pax_find_mirror_vma(vma);
71592+ if (vma_m) {
71593+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71594+ struct zap_details details = {
71595+ .nonlinear_vma = vma_m,
71596+ .last_index = ULONG_MAX,
71597+ };
71598+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71599+ } else
71600+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71601+ }
71602+#endif
71603+
71604 return 0;
71605 }
71606
71607@@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71608 if (end < start)
71609 goto out;
71610
71611+#ifdef CONFIG_PAX_SEGMEXEC
71612+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71613+ if (end > SEGMEXEC_TASK_SIZE)
71614+ goto out;
71615+ } else
71616+#endif
71617+
71618+ if (end > TASK_SIZE)
71619+ goto out;
71620+
71621 error = 0;
71622 if (end == start)
71623 goto out;
71624diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71625index a6e2141..eaf5aad 100644
71626--- a/mm/memory-failure.c
71627+++ b/mm/memory-failure.c
71628@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71629
71630 int sysctl_memory_failure_recovery __read_mostly = 1;
71631
71632-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71633+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71634
71635 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71636
71637@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71638 pfn, t->comm, t->pid);
71639 si.si_signo = SIGBUS;
71640 si.si_errno = 0;
71641- si.si_addr = (void *)addr;
71642+ si.si_addr = (void __user *)addr;
71643 #ifdef __ARCH_SI_TRAPNO
71644 si.si_trapno = trapno;
71645 #endif
71646@@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71647 }
71648
71649 nr_pages = 1 << compound_trans_order(hpage);
71650- atomic_long_add(nr_pages, &mce_bad_pages);
71651+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71652
71653 /*
71654 * We need/can do nothing about count=0 pages.
71655@@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71656 if (!PageHWPoison(hpage)
71657 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71658 || (p != hpage && TestSetPageHWPoison(hpage))) {
71659- atomic_long_sub(nr_pages, &mce_bad_pages);
71660+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71661 return 0;
71662 }
71663 set_page_hwpoison_huge_page(hpage);
71664@@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71665 }
71666 if (hwpoison_filter(p)) {
71667 if (TestClearPageHWPoison(p))
71668- atomic_long_sub(nr_pages, &mce_bad_pages);
71669+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71670 unlock_page(hpage);
71671 put_page(hpage);
71672 return 0;
71673@@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71674 return 0;
71675 }
71676 if (TestClearPageHWPoison(p))
71677- atomic_long_sub(nr_pages, &mce_bad_pages);
71678+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71679 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71680 return 0;
71681 }
71682@@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71683 */
71684 if (TestClearPageHWPoison(page)) {
71685 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71686- atomic_long_sub(nr_pages, &mce_bad_pages);
71687+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71688 freeit = 1;
71689 if (PageHuge(page))
71690 clear_page_hwpoison_huge_page(page);
71691@@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71692 }
71693 done:
71694 if (!PageHWPoison(hpage))
71695- atomic_long_add(1 << compound_trans_order(hpage),
71696+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
71697 &mce_bad_pages);
71698 set_page_hwpoison_huge_page(hpage);
71699 dequeue_hwpoisoned_huge_page(hpage);
71700@@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
71701 return ret;
71702
71703 done:
71704- atomic_long_add(1, &mce_bad_pages);
71705+ atomic_long_add_unchecked(1, &mce_bad_pages);
71706 SetPageHWPoison(page);
71707 /* keep elevated page count for bad page */
71708 return ret;
71709diff --git a/mm/memory.c b/mm/memory.c
71710index 5736170..8e04800 100644
71711--- a/mm/memory.c
71712+++ b/mm/memory.c
71713@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71714 free_pte_range(tlb, pmd, addr);
71715 } while (pmd++, addr = next, addr != end);
71716
71717+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71718 start &= PUD_MASK;
71719 if (start < floor)
71720 return;
71721@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71722 pmd = pmd_offset(pud, start);
71723 pud_clear(pud);
71724 pmd_free_tlb(tlb, pmd, start);
71725+#endif
71726+
71727 }
71728
71729 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71730@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71731 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
71732 } while (pud++, addr = next, addr != end);
71733
71734+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71735 start &= PGDIR_MASK;
71736 if (start < floor)
71737 return;
71738@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71739 pud = pud_offset(pgd, start);
71740 pgd_clear(pgd);
71741 pud_free_tlb(tlb, pud, start);
71742+#endif
71743+
71744 }
71745
71746 /*
71747@@ -1614,12 +1620,6 @@ no_page_table:
71748 return page;
71749 }
71750
71751-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71752-{
71753- return stack_guard_page_start(vma, addr) ||
71754- stack_guard_page_end(vma, addr+PAGE_SIZE);
71755-}
71756-
71757 /**
71758 * __get_user_pages() - pin user pages in memory
71759 * @tsk: task_struct of target task
71760@@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71761 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71762 i = 0;
71763
71764- do {
71765+ while (nr_pages) {
71766 struct vm_area_struct *vma;
71767
71768- vma = find_extend_vma(mm, start);
71769+ vma = find_vma(mm, start);
71770 if (!vma && in_gate_area(mm, start)) {
71771 unsigned long pg = start & PAGE_MASK;
71772 pgd_t *pgd;
71773@@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71774 goto next_page;
71775 }
71776
71777- if (!vma ||
71778+ if (!vma || start < vma->vm_start ||
71779 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71780 !(vm_flags & vma->vm_flags))
71781 return i ? : -EFAULT;
71782@@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71783 int ret;
71784 unsigned int fault_flags = 0;
71785
71786- /* For mlock, just skip the stack guard page. */
71787- if (foll_flags & FOLL_MLOCK) {
71788- if (stack_guard_page(vma, start))
71789- goto next_page;
71790- }
71791 if (foll_flags & FOLL_WRITE)
71792 fault_flags |= FAULT_FLAG_WRITE;
71793 if (nonblocking)
71794@@ -1848,7 +1843,7 @@ next_page:
71795 start += PAGE_SIZE;
71796 nr_pages--;
71797 } while (nr_pages && start < vma->vm_end);
71798- } while (nr_pages);
71799+ }
71800 return i;
71801 }
71802 EXPORT_SYMBOL(__get_user_pages);
71803@@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71804 page_add_file_rmap(page);
71805 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71806
71807+#ifdef CONFIG_PAX_SEGMEXEC
71808+ pax_mirror_file_pte(vma, addr, page, ptl);
71809+#endif
71810+
71811 retval = 0;
71812 pte_unmap_unlock(pte, ptl);
71813 return retval;
71814@@ -2089,10 +2088,22 @@ out:
71815 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71816 struct page *page)
71817 {
71818+
71819+#ifdef CONFIG_PAX_SEGMEXEC
71820+ struct vm_area_struct *vma_m;
71821+#endif
71822+
71823 if (addr < vma->vm_start || addr >= vma->vm_end)
71824 return -EFAULT;
71825 if (!page_count(page))
71826 return -EINVAL;
71827+
71828+#ifdef CONFIG_PAX_SEGMEXEC
71829+ vma_m = pax_find_mirror_vma(vma);
71830+ if (vma_m)
71831+ vma_m->vm_flags |= VM_INSERTPAGE;
71832+#endif
71833+
71834 vma->vm_flags |= VM_INSERTPAGE;
71835 return insert_page(vma, addr, page, vma->vm_page_prot);
71836 }
71837@@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71838 unsigned long pfn)
71839 {
71840 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71841+ BUG_ON(vma->vm_mirror);
71842
71843 if (addr < vma->vm_start || addr >= vma->vm_end)
71844 return -EFAULT;
71845@@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71846
71847 BUG_ON(pud_huge(*pud));
71848
71849- pmd = pmd_alloc(mm, pud, addr);
71850+ pmd = (mm == &init_mm) ?
71851+ pmd_alloc_kernel(mm, pud, addr) :
71852+ pmd_alloc(mm, pud, addr);
71853 if (!pmd)
71854 return -ENOMEM;
71855 do {
71856@@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71857 unsigned long next;
71858 int err;
71859
71860- pud = pud_alloc(mm, pgd, addr);
71861+ pud = (mm == &init_mm) ?
71862+ pud_alloc_kernel(mm, pgd, addr) :
71863+ pud_alloc(mm, pgd, addr);
71864 if (!pud)
71865 return -ENOMEM;
71866 do {
71867@@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71868 copy_user_highpage(dst, src, va, vma);
71869 }
71870
71871+#ifdef CONFIG_PAX_SEGMEXEC
71872+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71873+{
71874+ struct mm_struct *mm = vma->vm_mm;
71875+ spinlock_t *ptl;
71876+ pte_t *pte, entry;
71877+
71878+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71879+ entry = *pte;
71880+ if (!pte_present(entry)) {
71881+ if (!pte_none(entry)) {
71882+ BUG_ON(pte_file(entry));
71883+ free_swap_and_cache(pte_to_swp_entry(entry));
71884+ pte_clear_not_present_full(mm, address, pte, 0);
71885+ }
71886+ } else {
71887+ struct page *page;
71888+
71889+ flush_cache_page(vma, address, pte_pfn(entry));
71890+ entry = ptep_clear_flush(vma, address, pte);
71891+ BUG_ON(pte_dirty(entry));
71892+ page = vm_normal_page(vma, address, entry);
71893+ if (page) {
71894+ update_hiwater_rss(mm);
71895+ if (PageAnon(page))
71896+ dec_mm_counter_fast(mm, MM_ANONPAGES);
71897+ else
71898+ dec_mm_counter_fast(mm, MM_FILEPAGES);
71899+ page_remove_rmap(page);
71900+ page_cache_release(page);
71901+ }
71902+ }
71903+ pte_unmap_unlock(pte, ptl);
71904+}
71905+
71906+/* PaX: if vma is mirrored, synchronize the mirror's PTE
71907+ *
71908+ * the ptl of the lower mapped page is held on entry and is not released on exit
71909+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71910+ */
71911+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71912+{
71913+ struct mm_struct *mm = vma->vm_mm;
71914+ unsigned long address_m;
71915+ spinlock_t *ptl_m;
71916+ struct vm_area_struct *vma_m;
71917+ pmd_t *pmd_m;
71918+ pte_t *pte_m, entry_m;
71919+
71920+ BUG_ON(!page_m || !PageAnon(page_m));
71921+
71922+ vma_m = pax_find_mirror_vma(vma);
71923+ if (!vma_m)
71924+ return;
71925+
71926+ BUG_ON(!PageLocked(page_m));
71927+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71928+ address_m = address + SEGMEXEC_TASK_SIZE;
71929+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71930+ pte_m = pte_offset_map(pmd_m, address_m);
71931+ ptl_m = pte_lockptr(mm, pmd_m);
71932+ if (ptl != ptl_m) {
71933+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71934+ if (!pte_none(*pte_m))
71935+ goto out;
71936+ }
71937+
71938+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71939+ page_cache_get(page_m);
71940+ page_add_anon_rmap(page_m, vma_m, address_m);
71941+ inc_mm_counter_fast(mm, MM_ANONPAGES);
71942+ set_pte_at(mm, address_m, pte_m, entry_m);
71943+ update_mmu_cache(vma_m, address_m, entry_m);
71944+out:
71945+ if (ptl != ptl_m)
71946+ spin_unlock(ptl_m);
71947+ pte_unmap(pte_m);
71948+ unlock_page(page_m);
71949+}
71950+
71951+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71952+{
71953+ struct mm_struct *mm = vma->vm_mm;
71954+ unsigned long address_m;
71955+ spinlock_t *ptl_m;
71956+ struct vm_area_struct *vma_m;
71957+ pmd_t *pmd_m;
71958+ pte_t *pte_m, entry_m;
71959+
71960+ BUG_ON(!page_m || PageAnon(page_m));
71961+
71962+ vma_m = pax_find_mirror_vma(vma);
71963+ if (!vma_m)
71964+ return;
71965+
71966+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71967+ address_m = address + SEGMEXEC_TASK_SIZE;
71968+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71969+ pte_m = pte_offset_map(pmd_m, address_m);
71970+ ptl_m = pte_lockptr(mm, pmd_m);
71971+ if (ptl != ptl_m) {
71972+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71973+ if (!pte_none(*pte_m))
71974+ goto out;
71975+ }
71976+
71977+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71978+ page_cache_get(page_m);
71979+ page_add_file_rmap(page_m);
71980+ inc_mm_counter_fast(mm, MM_FILEPAGES);
71981+ set_pte_at(mm, address_m, pte_m, entry_m);
71982+ update_mmu_cache(vma_m, address_m, entry_m);
71983+out:
71984+ if (ptl != ptl_m)
71985+ spin_unlock(ptl_m);
71986+ pte_unmap(pte_m);
71987+}
71988+
71989+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71990+{
71991+ struct mm_struct *mm = vma->vm_mm;
71992+ unsigned long address_m;
71993+ spinlock_t *ptl_m;
71994+ struct vm_area_struct *vma_m;
71995+ pmd_t *pmd_m;
71996+ pte_t *pte_m, entry_m;
71997+
71998+ vma_m = pax_find_mirror_vma(vma);
71999+ if (!vma_m)
72000+ return;
72001+
72002+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72003+ address_m = address + SEGMEXEC_TASK_SIZE;
72004+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72005+ pte_m = pte_offset_map(pmd_m, address_m);
72006+ ptl_m = pte_lockptr(mm, pmd_m);
72007+ if (ptl != ptl_m) {
72008+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72009+ if (!pte_none(*pte_m))
72010+ goto out;
72011+ }
72012+
72013+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72014+ set_pte_at(mm, address_m, pte_m, entry_m);
72015+out:
72016+ if (ptl != ptl_m)
72017+ spin_unlock(ptl_m);
72018+ pte_unmap(pte_m);
72019+}
72020+
72021+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72022+{
72023+ struct page *page_m;
72024+ pte_t entry;
72025+
72026+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72027+ goto out;
72028+
72029+ entry = *pte;
72030+ page_m = vm_normal_page(vma, address, entry);
72031+ if (!page_m)
72032+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72033+ else if (PageAnon(page_m)) {
72034+ if (pax_find_mirror_vma(vma)) {
72035+ pte_unmap_unlock(pte, ptl);
72036+ lock_page(page_m);
72037+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72038+ if (pte_same(entry, *pte))
72039+ pax_mirror_anon_pte(vma, address, page_m, ptl);
72040+ else
72041+ unlock_page(page_m);
72042+ }
72043+ } else
72044+ pax_mirror_file_pte(vma, address, page_m, ptl);
72045+
72046+out:
72047+ pte_unmap_unlock(pte, ptl);
72048+}
72049+#endif
72050+
72051 /*
72052 * This routine handles present pages, when users try to write
72053 * to a shared page. It is done by copying the page to a new address
72054@@ -2703,6 +2899,12 @@ gotten:
72055 */
72056 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72057 if (likely(pte_same(*page_table, orig_pte))) {
72058+
72059+#ifdef CONFIG_PAX_SEGMEXEC
72060+ if (pax_find_mirror_vma(vma))
72061+ BUG_ON(!trylock_page(new_page));
72062+#endif
72063+
72064 if (old_page) {
72065 if (!PageAnon(old_page)) {
72066 dec_mm_counter_fast(mm, MM_FILEPAGES);
72067@@ -2754,6 +2956,10 @@ gotten:
72068 page_remove_rmap(old_page);
72069 }
72070
72071+#ifdef CONFIG_PAX_SEGMEXEC
72072+ pax_mirror_anon_pte(vma, address, new_page, ptl);
72073+#endif
72074+
72075 /* Free the old page.. */
72076 new_page = old_page;
72077 ret |= VM_FAULT_WRITE;
72078@@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72079 swap_free(entry);
72080 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72081 try_to_free_swap(page);
72082+
72083+#ifdef CONFIG_PAX_SEGMEXEC
72084+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72085+#endif
72086+
72087 unlock_page(page);
72088 if (swapcache) {
72089 /*
72090@@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72091
72092 /* No need to invalidate - it was non-present before */
72093 update_mmu_cache(vma, address, page_table);
72094+
72095+#ifdef CONFIG_PAX_SEGMEXEC
72096+ pax_mirror_anon_pte(vma, address, page, ptl);
72097+#endif
72098+
72099 unlock:
72100 pte_unmap_unlock(page_table, ptl);
72101 out:
72102@@ -3075,40 +3291,6 @@ out_release:
72103 }
72104
72105 /*
72106- * This is like a special single-page "expand_{down|up}wards()",
72107- * except we must first make sure that 'address{-|+}PAGE_SIZE'
72108- * doesn't hit another vma.
72109- */
72110-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72111-{
72112- address &= PAGE_MASK;
72113- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72114- struct vm_area_struct *prev = vma->vm_prev;
72115-
72116- /*
72117- * Is there a mapping abutting this one below?
72118- *
72119- * That's only ok if it's the same stack mapping
72120- * that has gotten split..
72121- */
72122- if (prev && prev->vm_end == address)
72123- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72124-
72125- expand_downwards(vma, address - PAGE_SIZE);
72126- }
72127- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72128- struct vm_area_struct *next = vma->vm_next;
72129-
72130- /* As VM_GROWSDOWN but s/below/above/ */
72131- if (next && next->vm_start == address + PAGE_SIZE)
72132- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72133-
72134- expand_upwards(vma, address + PAGE_SIZE);
72135- }
72136- return 0;
72137-}
72138-
72139-/*
72140 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72141 * but allow concurrent faults), and pte mapped but not yet locked.
72142 * We return with mmap_sem still held, but pte unmapped and unlocked.
72143@@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72144 unsigned long address, pte_t *page_table, pmd_t *pmd,
72145 unsigned int flags)
72146 {
72147- struct page *page;
72148+ struct page *page = NULL;
72149 spinlock_t *ptl;
72150 pte_t entry;
72151
72152- pte_unmap(page_table);
72153-
72154- /* Check if we need to add a guard page to the stack */
72155- if (check_stack_guard_page(vma, address) < 0)
72156- return VM_FAULT_SIGBUS;
72157-
72158- /* Use the zero-page for reads */
72159 if (!(flags & FAULT_FLAG_WRITE)) {
72160 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72161 vma->vm_page_prot));
72162- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72163+ ptl = pte_lockptr(mm, pmd);
72164+ spin_lock(ptl);
72165 if (!pte_none(*page_table))
72166 goto unlock;
72167 goto setpte;
72168 }
72169
72170 /* Allocate our own private page. */
72171+ pte_unmap(page_table);
72172+
72173 if (unlikely(anon_vma_prepare(vma)))
72174 goto oom;
72175 page = alloc_zeroed_user_highpage_movable(vma, address);
72176@@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72177 if (!pte_none(*page_table))
72178 goto release;
72179
72180+#ifdef CONFIG_PAX_SEGMEXEC
72181+ if (pax_find_mirror_vma(vma))
72182+ BUG_ON(!trylock_page(page));
72183+#endif
72184+
72185 inc_mm_counter_fast(mm, MM_ANONPAGES);
72186 page_add_new_anon_rmap(page, vma, address);
72187 setpte:
72188@@ -3163,6 +3346,12 @@ setpte:
72189
72190 /* No need to invalidate - it was non-present before */
72191 update_mmu_cache(vma, address, page_table);
72192+
72193+#ifdef CONFIG_PAX_SEGMEXEC
72194+ if (page)
72195+ pax_mirror_anon_pte(vma, address, page, ptl);
72196+#endif
72197+
72198 unlock:
72199 pte_unmap_unlock(page_table, ptl);
72200 return 0;
72201@@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72202 */
72203 /* Only go through if we didn't race with anybody else... */
72204 if (likely(pte_same(*page_table, orig_pte))) {
72205+
72206+#ifdef CONFIG_PAX_SEGMEXEC
72207+ if (anon && pax_find_mirror_vma(vma))
72208+ BUG_ON(!trylock_page(page));
72209+#endif
72210+
72211 flush_icache_page(vma, page);
72212 entry = mk_pte(page, vma->vm_page_prot);
72213 if (flags & FAULT_FLAG_WRITE)
72214@@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72215
72216 /* no need to invalidate: a not-present page won't be cached */
72217 update_mmu_cache(vma, address, page_table);
72218+
72219+#ifdef CONFIG_PAX_SEGMEXEC
72220+ if (anon)
72221+ pax_mirror_anon_pte(vma, address, page, ptl);
72222+ else
72223+ pax_mirror_file_pte(vma, address, page, ptl);
72224+#endif
72225+
72226 } else {
72227 if (cow_page)
72228 mem_cgroup_uncharge_page(cow_page);
72229@@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
72230 if (flags & FAULT_FLAG_WRITE)
72231 flush_tlb_fix_spurious_fault(vma, address);
72232 }
72233+
72234+#ifdef CONFIG_PAX_SEGMEXEC
72235+ pax_mirror_pte(vma, address, pte, pmd, ptl);
72236+ return 0;
72237+#endif
72238+
72239 unlock:
72240 pte_unmap_unlock(pte, ptl);
72241 return 0;
72242@@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72243 pmd_t *pmd;
72244 pte_t *pte;
72245
72246+#ifdef CONFIG_PAX_SEGMEXEC
72247+ struct vm_area_struct *vma_m;
72248+#endif
72249+
72250 __set_current_state(TASK_RUNNING);
72251
72252 count_vm_event(PGFAULT);
72253@@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72254 if (unlikely(is_vm_hugetlb_page(vma)))
72255 return hugetlb_fault(mm, vma, address, flags);
72256
72257+#ifdef CONFIG_PAX_SEGMEXEC
72258+ vma_m = pax_find_mirror_vma(vma);
72259+ if (vma_m) {
72260+ unsigned long address_m;
72261+ pgd_t *pgd_m;
72262+ pud_t *pud_m;
72263+ pmd_t *pmd_m;
72264+
72265+ if (vma->vm_start > vma_m->vm_start) {
72266+ address_m = address;
72267+ address -= SEGMEXEC_TASK_SIZE;
72268+ vma = vma_m;
72269+ } else
72270+ address_m = address + SEGMEXEC_TASK_SIZE;
72271+
72272+ pgd_m = pgd_offset(mm, address_m);
72273+ pud_m = pud_alloc(mm, pgd_m, address_m);
72274+ if (!pud_m)
72275+ return VM_FAULT_OOM;
72276+ pmd_m = pmd_alloc(mm, pud_m, address_m);
72277+ if (!pmd_m)
72278+ return VM_FAULT_OOM;
72279+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72280+ return VM_FAULT_OOM;
72281+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72282+ }
72283+#endif
72284+
72285 retry:
72286 pgd = pgd_offset(mm, address);
72287 pud = pud_alloc(mm, pgd, address);
72288@@ -3547,7 +3788,7 @@ retry:
72289 * run pte_offset_map on the pmd, if an huge pmd could
72290 * materialize from under us from a different thread.
72291 */
72292- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72293+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72294 return VM_FAULT_OOM;
72295 /* if an huge pmd materialized from under us just retry later */
72296 if (unlikely(pmd_trans_huge(*pmd)))
72297@@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72298 spin_unlock(&mm->page_table_lock);
72299 return 0;
72300 }
72301+
72302+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72303+{
72304+ pud_t *new = pud_alloc_one(mm, address);
72305+ if (!new)
72306+ return -ENOMEM;
72307+
72308+ smp_wmb(); /* See comment in __pte_alloc */
72309+
72310+ spin_lock(&mm->page_table_lock);
72311+ if (pgd_present(*pgd)) /* Another has populated it */
72312+ pud_free(mm, new);
72313+ else
72314+ pgd_populate_kernel(mm, pgd, new);
72315+ spin_unlock(&mm->page_table_lock);
72316+ return 0;
72317+}
72318 #endif /* __PAGETABLE_PUD_FOLDED */
72319
72320 #ifndef __PAGETABLE_PMD_FOLDED
72321@@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72322 spin_unlock(&mm->page_table_lock);
72323 return 0;
72324 }
72325+
72326+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72327+{
72328+ pmd_t *new = pmd_alloc_one(mm, address);
72329+ if (!new)
72330+ return -ENOMEM;
72331+
72332+ smp_wmb(); /* See comment in __pte_alloc */
72333+
72334+ spin_lock(&mm->page_table_lock);
72335+#ifndef __ARCH_HAS_4LEVEL_HACK
72336+ if (pud_present(*pud)) /* Another has populated it */
72337+ pmd_free(mm, new);
72338+ else
72339+ pud_populate_kernel(mm, pud, new);
72340+#else
72341+ if (pgd_present(*pud)) /* Another has populated it */
72342+ pmd_free(mm, new);
72343+ else
72344+ pgd_populate_kernel(mm, pud, new);
72345+#endif /* __ARCH_HAS_4LEVEL_HACK */
72346+ spin_unlock(&mm->page_table_lock);
72347+ return 0;
72348+}
72349 #endif /* __PAGETABLE_PMD_FOLDED */
72350
72351 int make_pages_present(unsigned long addr, unsigned long end)
72352@@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
72353 gate_vma.vm_start = FIXADDR_USER_START;
72354 gate_vma.vm_end = FIXADDR_USER_END;
72355 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72356- gate_vma.vm_page_prot = __P101;
72357+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72358
72359 return 0;
72360 }
72361diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72362index 4ada3be..5f6330d 100644
72363--- a/mm/mempolicy.c
72364+++ b/mm/mempolicy.c
72365@@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72366 unsigned long vmstart;
72367 unsigned long vmend;
72368
72369+#ifdef CONFIG_PAX_SEGMEXEC
72370+ struct vm_area_struct *vma_m;
72371+#endif
72372+
72373 vma = find_vma(mm, start);
72374 if (!vma || vma->vm_start > start)
72375 return -EFAULT;
72376@@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72377 if (err)
72378 goto out;
72379 }
72380+
72381+#ifdef CONFIG_PAX_SEGMEXEC
72382+ vma_m = pax_find_mirror_vma(vma);
72383+ if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
72384+ err = vma_m->vm_ops->set_policy(vma_m, new_pol);
72385+ if (err)
72386+ goto out;
72387+ }
72388+#endif
72389+
72390 }
72391
72392 out:
72393@@ -1125,6 +1139,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72394
72395 if (end < start)
72396 return -EINVAL;
72397+
72398+#ifdef CONFIG_PAX_SEGMEXEC
72399+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72400+ if (end > SEGMEXEC_TASK_SIZE)
72401+ return -EINVAL;
72402+ } else
72403+#endif
72404+
72405+ if (end > TASK_SIZE)
72406+ return -EINVAL;
72407+
72408 if (end == start)
72409 return 0;
72410
72411@@ -1348,8 +1373,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72412 */
72413 tcred = __task_cred(task);
72414 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72415- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72416- !capable(CAP_SYS_NICE)) {
72417+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72418 rcu_read_unlock();
72419 err = -EPERM;
72420 goto out_put;
72421@@ -1380,6 +1404,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72422 goto out;
72423 }
72424
72425+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72426+ if (mm != current->mm &&
72427+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72428+ mmput(mm);
72429+ err = -EPERM;
72430+ goto out;
72431+ }
72432+#endif
72433+
72434 err = do_migrate_pages(mm, old, new,
72435 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72436
72437diff --git a/mm/migrate.c b/mm/migrate.c
72438index 77ed2d7..317d528 100644
72439--- a/mm/migrate.c
72440+++ b/mm/migrate.c
72441@@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
72442 */
72443 tcred = __task_cred(task);
72444 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72445- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72446- !capable(CAP_SYS_NICE)) {
72447+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72448 rcu_read_unlock();
72449 err = -EPERM;
72450 goto out;
72451diff --git a/mm/mlock.c b/mm/mlock.c
72452index ef726e8..cd7f1ec 100644
72453--- a/mm/mlock.c
72454+++ b/mm/mlock.c
72455@@ -13,6 +13,7 @@
72456 #include <linux/pagemap.h>
72457 #include <linux/mempolicy.h>
72458 #include <linux/syscalls.h>
72459+#include <linux/security.h>
72460 #include <linux/sched.h>
72461 #include <linux/export.h>
72462 #include <linux/rmap.h>
72463@@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72464 {
72465 unsigned long nstart, end, tmp;
72466 struct vm_area_struct * vma, * prev;
72467- int error;
72468+ int error = 0;
72469
72470 VM_BUG_ON(start & ~PAGE_MASK);
72471 VM_BUG_ON(len != PAGE_ALIGN(len));
72472@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72473 return -EINVAL;
72474 if (end == start)
72475 return 0;
72476+ if (end > TASK_SIZE)
72477+ return -EINVAL;
72478+
72479 vma = find_vma(current->mm, start);
72480 if (!vma || vma->vm_start > start)
72481 return -ENOMEM;
72482@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72483 for (nstart = start ; ; ) {
72484 vm_flags_t newflags;
72485
72486+#ifdef CONFIG_PAX_SEGMEXEC
72487+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72488+ break;
72489+#endif
72490+
72491 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72492
72493 newflags = vma->vm_flags | VM_LOCKED;
72494@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72495 lock_limit >>= PAGE_SHIFT;
72496
72497 /* check against resource limits */
72498+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72499 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72500 error = do_mlock(start, len, 1);
72501 up_write(&current->mm->mmap_sem);
72502@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72503 static int do_mlockall(int flags)
72504 {
72505 struct vm_area_struct * vma, * prev = NULL;
72506- unsigned int def_flags = 0;
72507
72508 if (flags & MCL_FUTURE)
72509- def_flags = VM_LOCKED;
72510- current->mm->def_flags = def_flags;
72511+ current->mm->def_flags |= VM_LOCKED;
72512+ else
72513+ current->mm->def_flags &= ~VM_LOCKED;
72514 if (flags == MCL_FUTURE)
72515 goto out;
72516
72517 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72518 vm_flags_t newflags;
72519
72520+#ifdef CONFIG_PAX_SEGMEXEC
72521+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72522+ break;
72523+#endif
72524+
72525+ BUG_ON(vma->vm_end > TASK_SIZE);
72526 newflags = vma->vm_flags | VM_LOCKED;
72527 if (!(flags & MCL_CURRENT))
72528 newflags &= ~VM_LOCKED;
72529@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72530 lock_limit >>= PAGE_SHIFT;
72531
72532 ret = -ENOMEM;
72533+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72534 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72535 capable(CAP_IPC_LOCK))
72536 ret = do_mlockall(flags);
72537diff --git a/mm/mmap.c b/mm/mmap.c
72538index ae18a48..86cf99e 100644
72539--- a/mm/mmap.c
72540+++ b/mm/mmap.c
72541@@ -47,6 +47,16 @@
72542 #define arch_rebalance_pgtables(addr, len) (addr)
72543 #endif
72544
72545+static inline void verify_mm_writelocked(struct mm_struct *mm)
72546+{
72547+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72548+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72549+ up_read(&mm->mmap_sem);
72550+ BUG();
72551+ }
72552+#endif
72553+}
72554+
72555 static void unmap_region(struct mm_struct *mm,
72556 struct vm_area_struct *vma, struct vm_area_struct *prev,
72557 unsigned long start, unsigned long end);
72558@@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72559 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72560 *
72561 */
72562-pgprot_t protection_map[16] = {
72563+pgprot_t protection_map[16] __read_only = {
72564 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72565 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72566 };
72567
72568-pgprot_t vm_get_page_prot(unsigned long vm_flags)
72569+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72570 {
72571- return __pgprot(pgprot_val(protection_map[vm_flags &
72572+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72573 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72574 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72575+
72576+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72577+ if (!(__supported_pte_mask & _PAGE_NX) &&
72578+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72579+ (vm_flags & (VM_READ | VM_WRITE)))
72580+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72581+#endif
72582+
72583+ return prot;
72584 }
72585 EXPORT_SYMBOL(vm_get_page_prot);
72586
72587 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72588 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72589 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72590+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72591 /*
72592 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72593 * other variables. It can be updated by several CPUs frequently.
72594@@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72595 struct vm_area_struct *next = vma->vm_next;
72596
72597 might_sleep();
72598+ BUG_ON(vma->vm_mirror);
72599 if (vma->vm_ops && vma->vm_ops->close)
72600 vma->vm_ops->close(vma);
72601 if (vma->vm_file) {
72602@@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72603 * not page aligned -Ram Gupta
72604 */
72605 rlim = rlimit(RLIMIT_DATA);
72606+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72607 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72608 (mm->end_data - mm->start_data) > rlim)
72609 goto out;
72610@@ -708,6 +730,12 @@ static int
72611 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72612 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72613 {
72614+
72615+#ifdef CONFIG_PAX_SEGMEXEC
72616+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72617+ return 0;
72618+#endif
72619+
72620 if (is_mergeable_vma(vma, file, vm_flags) &&
72621 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72622 if (vma->vm_pgoff == vm_pgoff)
72623@@ -727,6 +755,12 @@ static int
72624 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72625 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72626 {
72627+
72628+#ifdef CONFIG_PAX_SEGMEXEC
72629+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72630+ return 0;
72631+#endif
72632+
72633 if (is_mergeable_vma(vma, file, vm_flags) &&
72634 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72635 pgoff_t vm_pglen;
72636@@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72637 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72638 struct vm_area_struct *prev, unsigned long addr,
72639 unsigned long end, unsigned long vm_flags,
72640- struct anon_vma *anon_vma, struct file *file,
72641+ struct anon_vma *anon_vma, struct file *file,
72642 pgoff_t pgoff, struct mempolicy *policy)
72643 {
72644 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72645 struct vm_area_struct *area, *next;
72646 int err;
72647
72648+#ifdef CONFIG_PAX_SEGMEXEC
72649+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72650+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72651+
72652+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72653+#endif
72654+
72655 /*
72656 * We later require that vma->vm_flags == vm_flags,
72657 * so this tests vma->vm_flags & VM_SPECIAL, too.
72658@@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72659 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72660 next = next->vm_next;
72661
72662+#ifdef CONFIG_PAX_SEGMEXEC
72663+ if (prev)
72664+ prev_m = pax_find_mirror_vma(prev);
72665+ if (area)
72666+ area_m = pax_find_mirror_vma(area);
72667+ if (next)
72668+ next_m = pax_find_mirror_vma(next);
72669+#endif
72670+
72671 /*
72672 * Can it merge with the predecessor?
72673 */
72674@@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72675 /* cases 1, 6 */
72676 err = vma_adjust(prev, prev->vm_start,
72677 next->vm_end, prev->vm_pgoff, NULL);
72678- } else /* cases 2, 5, 7 */
72679+
72680+#ifdef CONFIG_PAX_SEGMEXEC
72681+ if (!err && prev_m)
72682+ err = vma_adjust(prev_m, prev_m->vm_start,
72683+ next_m->vm_end, prev_m->vm_pgoff, NULL);
72684+#endif
72685+
72686+ } else { /* cases 2, 5, 7 */
72687 err = vma_adjust(prev, prev->vm_start,
72688 end, prev->vm_pgoff, NULL);
72689+
72690+#ifdef CONFIG_PAX_SEGMEXEC
72691+ if (!err && prev_m)
72692+ err = vma_adjust(prev_m, prev_m->vm_start,
72693+ end_m, prev_m->vm_pgoff, NULL);
72694+#endif
72695+
72696+ }
72697 if (err)
72698 return NULL;
72699 khugepaged_enter_vma_merge(prev);
72700@@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72701 mpol_equal(policy, vma_policy(next)) &&
72702 can_vma_merge_before(next, vm_flags,
72703 anon_vma, file, pgoff+pglen)) {
72704- if (prev && addr < prev->vm_end) /* case 4 */
72705+ if (prev && addr < prev->vm_end) { /* case 4 */
72706 err = vma_adjust(prev, prev->vm_start,
72707 addr, prev->vm_pgoff, NULL);
72708- else /* cases 3, 8 */
72709+
72710+#ifdef CONFIG_PAX_SEGMEXEC
72711+ if (!err && prev_m)
72712+ err = vma_adjust(prev_m, prev_m->vm_start,
72713+ addr_m, prev_m->vm_pgoff, NULL);
72714+#endif
72715+
72716+ } else { /* cases 3, 8 */
72717 err = vma_adjust(area, addr, next->vm_end,
72718 next->vm_pgoff - pglen, NULL);
72719+
72720+#ifdef CONFIG_PAX_SEGMEXEC
72721+ if (!err && area_m)
72722+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
72723+ next_m->vm_pgoff - pglen, NULL);
72724+#endif
72725+
72726+ }
72727 if (err)
72728 return NULL;
72729 khugepaged_enter_vma_merge(area);
72730@@ -940,16 +1020,13 @@ none:
72731 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72732 struct file *file, long pages)
72733 {
72734- const unsigned long stack_flags
72735- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72736-
72737 mm->total_vm += pages;
72738
72739 if (file) {
72740 mm->shared_vm += pages;
72741 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72742 mm->exec_vm += pages;
72743- } else if (flags & stack_flags)
72744+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72745 mm->stack_vm += pages;
72746 if (flags & (VM_RESERVED|VM_IO))
72747 mm->reserved_vm += pages;
72748@@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72749 * (the exception is when the underlying filesystem is noexec
72750 * mounted, in which case we dont add PROT_EXEC.)
72751 */
72752- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72753+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72754 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72755 prot |= PROT_EXEC;
72756
72757@@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72758 /* Obtain the address to map to. we verify (or select) it and ensure
72759 * that it represents a valid section of the address space.
72760 */
72761- addr = get_unmapped_area(file, addr, len, pgoff, flags);
72762+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72763 if (addr & ~PAGE_MASK)
72764 return addr;
72765
72766@@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72767 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72768 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72769
72770+#ifdef CONFIG_PAX_MPROTECT
72771+ if (mm->pax_flags & MF_PAX_MPROTECT) {
72772+#ifndef CONFIG_PAX_MPROTECT_COMPAT
72773+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72774+ gr_log_rwxmmap(file);
72775+
72776+#ifdef CONFIG_PAX_EMUPLT
72777+ vm_flags &= ~VM_EXEC;
72778+#else
72779+ return -EPERM;
72780+#endif
72781+
72782+ }
72783+
72784+ if (!(vm_flags & VM_EXEC))
72785+ vm_flags &= ~VM_MAYEXEC;
72786+#else
72787+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72788+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72789+#endif
72790+ else
72791+ vm_flags &= ~VM_MAYWRITE;
72792+ }
72793+#endif
72794+
72795+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72796+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72797+ vm_flags &= ~VM_PAGEEXEC;
72798+#endif
72799+
72800 if (flags & MAP_LOCKED)
72801 if (!can_do_mlock())
72802 return -EPERM;
72803@@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72804 locked += mm->locked_vm;
72805 lock_limit = rlimit(RLIMIT_MEMLOCK);
72806 lock_limit >>= PAGE_SHIFT;
72807+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72808 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72809 return -EAGAIN;
72810 }
72811@@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72812 }
72813 }
72814
72815+ if (!gr_acl_handle_mmap(file, prot))
72816+ return -EACCES;
72817+
72818 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72819 }
72820
72821@@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72822 vm_flags_t vm_flags = vma->vm_flags;
72823
72824 /* If it was private or non-writable, the write bit is already clear */
72825- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72826+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72827 return 0;
72828
72829 /* The backer wishes to know when pages are first written to? */
72830@@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72831 unsigned long charged = 0;
72832 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72833
72834+#ifdef CONFIG_PAX_SEGMEXEC
72835+ struct vm_area_struct *vma_m = NULL;
72836+#endif
72837+
72838+ /*
72839+ * mm->mmap_sem is required to protect against another thread
72840+ * changing the mappings in case we sleep.
72841+ */
72842+ verify_mm_writelocked(mm);
72843+
72844 /* Clear old maps */
72845 error = -ENOMEM;
72846-munmap_back:
72847 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72848 if (vma && vma->vm_start < addr + len) {
72849 if (do_munmap(mm, addr, len))
72850 return -ENOMEM;
72851- goto munmap_back;
72852+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72853+ BUG_ON(vma && vma->vm_start < addr + len);
72854 }
72855
72856 /* Check against address space limit. */
72857@@ -1282,6 +1403,16 @@ munmap_back:
72858 goto unacct_error;
72859 }
72860
72861+#ifdef CONFIG_PAX_SEGMEXEC
72862+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72863+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72864+ if (!vma_m) {
72865+ error = -ENOMEM;
72866+ goto free_vma;
72867+ }
72868+ }
72869+#endif
72870+
72871 vma->vm_mm = mm;
72872 vma->vm_start = addr;
72873 vma->vm_end = addr + len;
72874@@ -1306,6 +1437,19 @@ munmap_back:
72875 error = file->f_op->mmap(file, vma);
72876 if (error)
72877 goto unmap_and_free_vma;
72878+
72879+#ifdef CONFIG_PAX_SEGMEXEC
72880+ if (vma_m && (vm_flags & VM_EXECUTABLE))
72881+ added_exe_file_vma(mm);
72882+#endif
72883+
72884+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72885+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72886+ vma->vm_flags |= VM_PAGEEXEC;
72887+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72888+ }
72889+#endif
72890+
72891 if (vm_flags & VM_EXECUTABLE)
72892 added_exe_file_vma(mm);
72893
72894@@ -1343,6 +1487,11 @@ munmap_back:
72895 vma_link(mm, vma, prev, rb_link, rb_parent);
72896 file = vma->vm_file;
72897
72898+#ifdef CONFIG_PAX_SEGMEXEC
72899+ if (vma_m)
72900+ BUG_ON(pax_mirror_vma(vma_m, vma));
72901+#endif
72902+
72903 /* Once vma denies write, undo our temporary denial count */
72904 if (correct_wcount)
72905 atomic_inc(&inode->i_writecount);
72906@@ -1350,6 +1499,7 @@ out:
72907 perf_event_mmap(vma);
72908
72909 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72910+ track_exec_limit(mm, addr, addr + len, vm_flags);
72911 if (vm_flags & VM_LOCKED) {
72912 if (!mlock_vma_pages_range(vma, addr, addr + len))
72913 mm->locked_vm += (len >> PAGE_SHIFT);
72914@@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72915 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72916 charged = 0;
72917 free_vma:
72918+
72919+#ifdef CONFIG_PAX_SEGMEXEC
72920+ if (vma_m)
72921+ kmem_cache_free(vm_area_cachep, vma_m);
72922+#endif
72923+
72924 kmem_cache_free(vm_area_cachep, vma);
72925 unacct_error:
72926 if (charged)
72927@@ -1378,6 +1534,44 @@ unacct_error:
72928 return error;
72929 }
72930
72931+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72932+{
72933+ if (!vma) {
72934+#ifdef CONFIG_STACK_GROWSUP
72935+ if (addr > sysctl_heap_stack_gap)
72936+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72937+ else
72938+ vma = find_vma(current->mm, 0);
72939+ if (vma && (vma->vm_flags & VM_GROWSUP))
72940+ return false;
72941+#endif
72942+ return true;
72943+ }
72944+
72945+ if (addr + len > vma->vm_start)
72946+ return false;
72947+
72948+ if (vma->vm_flags & VM_GROWSDOWN)
72949+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72950+#ifdef CONFIG_STACK_GROWSUP
72951+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72952+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72953+#endif
72954+
72955+ return true;
72956+}
72957+
72958+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72959+{
72960+ if (vma->vm_start < len)
72961+ return -ENOMEM;
72962+ if (!(vma->vm_flags & VM_GROWSDOWN))
72963+ return vma->vm_start - len;
72964+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
72965+ return vma->vm_start - len - sysctl_heap_stack_gap;
72966+ return -ENOMEM;
72967+}
72968+
72969 /* Get an address range which is currently unmapped.
72970 * For shmat() with addr=0.
72971 *
72972@@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72973 if (flags & MAP_FIXED)
72974 return addr;
72975
72976+#ifdef CONFIG_PAX_RANDMMAP
72977+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72978+#endif
72979+
72980 if (addr) {
72981 addr = PAGE_ALIGN(addr);
72982- vma = find_vma(mm, addr);
72983- if (TASK_SIZE - len >= addr &&
72984- (!vma || addr + len <= vma->vm_start))
72985- return addr;
72986+ if (TASK_SIZE - len >= addr) {
72987+ vma = find_vma(mm, addr);
72988+ if (check_heap_stack_gap(vma, addr, len))
72989+ return addr;
72990+ }
72991 }
72992 if (len > mm->cached_hole_size) {
72993- start_addr = addr = mm->free_area_cache;
72994+ start_addr = addr = mm->free_area_cache;
72995 } else {
72996- start_addr = addr = TASK_UNMAPPED_BASE;
72997- mm->cached_hole_size = 0;
72998+ start_addr = addr = mm->mmap_base;
72999+ mm->cached_hole_size = 0;
73000 }
73001
73002 full_search:
73003@@ -1426,34 +1625,40 @@ full_search:
73004 * Start a new search - just in case we missed
73005 * some holes.
73006 */
73007- if (start_addr != TASK_UNMAPPED_BASE) {
73008- addr = TASK_UNMAPPED_BASE;
73009- start_addr = addr;
73010+ if (start_addr != mm->mmap_base) {
73011+ start_addr = addr = mm->mmap_base;
73012 mm->cached_hole_size = 0;
73013 goto full_search;
73014 }
73015 return -ENOMEM;
73016 }
73017- if (!vma || addr + len <= vma->vm_start) {
73018- /*
73019- * Remember the place where we stopped the search:
73020- */
73021- mm->free_area_cache = addr + len;
73022- return addr;
73023- }
73024+ if (check_heap_stack_gap(vma, addr, len))
73025+ break;
73026 if (addr + mm->cached_hole_size < vma->vm_start)
73027 mm->cached_hole_size = vma->vm_start - addr;
73028 addr = vma->vm_end;
73029 }
73030+
73031+ /*
73032+ * Remember the place where we stopped the search:
73033+ */
73034+ mm->free_area_cache = addr + len;
73035+ return addr;
73036 }
73037 #endif
73038
73039 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73040 {
73041+
73042+#ifdef CONFIG_PAX_SEGMEXEC
73043+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73044+ return;
73045+#endif
73046+
73047 /*
73048 * Is this a new hole at the lowest possible address?
73049 */
73050- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73051+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73052 mm->free_area_cache = addr;
73053 }
73054
73055@@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73056 {
73057 struct vm_area_struct *vma;
73058 struct mm_struct *mm = current->mm;
73059- unsigned long addr = addr0, start_addr;
73060+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73061
73062 /* requested length too big for entire address space */
73063 if (len > TASK_SIZE)
73064@@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73065 if (flags & MAP_FIXED)
73066 return addr;
73067
73068+#ifdef CONFIG_PAX_RANDMMAP
73069+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73070+#endif
73071+
73072 /* requesting a specific address */
73073 if (addr) {
73074 addr = PAGE_ALIGN(addr);
73075- vma = find_vma(mm, addr);
73076- if (TASK_SIZE - len >= addr &&
73077- (!vma || addr + len <= vma->vm_start))
73078- return addr;
73079+ if (TASK_SIZE - len >= addr) {
73080+ vma = find_vma(mm, addr);
73081+ if (check_heap_stack_gap(vma, addr, len))
73082+ return addr;
73083+ }
73084 }
73085
73086 /* check if free_area_cache is useful for us */
73087@@ -1508,7 +1718,7 @@ try_again:
73088 * return with success:
73089 */
73090 vma = find_vma(mm, addr);
73091- if (!vma || addr+len <= vma->vm_start)
73092+ if (check_heap_stack_gap(vma, addr, len))
73093 /* remember the address as a hint for next time */
73094 return (mm->free_area_cache = addr);
73095
73096@@ -1517,8 +1727,8 @@ try_again:
73097 mm->cached_hole_size = vma->vm_start - addr;
73098
73099 /* try just below the current vma->vm_start */
73100- addr = vma->vm_start-len;
73101- } while (len < vma->vm_start);
73102+ addr = skip_heap_stack_gap(vma, len);
73103+ } while (!IS_ERR_VALUE(addr));
73104
73105 fail:
73106 /*
73107@@ -1541,13 +1751,21 @@ fail:
73108 * can happen with large stack limits and large mmap()
73109 * allocations.
73110 */
73111+ mm->mmap_base = TASK_UNMAPPED_BASE;
73112+
73113+#ifdef CONFIG_PAX_RANDMMAP
73114+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73115+ mm->mmap_base += mm->delta_mmap;
73116+#endif
73117+
73118+ mm->free_area_cache = mm->mmap_base;
73119 mm->cached_hole_size = ~0UL;
73120- mm->free_area_cache = TASK_UNMAPPED_BASE;
73121 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73122 /*
73123 * Restore the topdown base:
73124 */
73125- mm->free_area_cache = mm->mmap_base;
73126+ mm->mmap_base = base;
73127+ mm->free_area_cache = base;
73128 mm->cached_hole_size = ~0UL;
73129
73130 return addr;
73131@@ -1556,6 +1774,12 @@ fail:
73132
73133 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73134 {
73135+
73136+#ifdef CONFIG_PAX_SEGMEXEC
73137+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73138+ return;
73139+#endif
73140+
73141 /*
73142 * Is this a new hole at the highest possible address?
73143 */
73144@@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73145 mm->free_area_cache = addr;
73146
73147 /* dont allow allocations above current base */
73148- if (mm->free_area_cache > mm->mmap_base)
73149+ if (mm->free_area_cache > mm->mmap_base) {
73150 mm->free_area_cache = mm->mmap_base;
73151+ mm->cached_hole_size = ~0UL;
73152+ }
73153 }
73154
73155 unsigned long
73156@@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73157 return vma;
73158 }
73159
73160+#ifdef CONFIG_PAX_SEGMEXEC
73161+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73162+{
73163+ struct vm_area_struct *vma_m;
73164+
73165+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73166+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73167+ BUG_ON(vma->vm_mirror);
73168+ return NULL;
73169+ }
73170+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73171+ vma_m = vma->vm_mirror;
73172+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73173+ BUG_ON(vma->vm_file != vma_m->vm_file);
73174+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73175+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73176+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73177+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73178+ return vma_m;
73179+}
73180+#endif
73181+
73182 /*
73183 * Verify that the stack growth is acceptable and
73184 * update accounting. This is shared with both the
73185@@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73186 return -ENOMEM;
73187
73188 /* Stack limit test */
73189+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
73190 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73191 return -ENOMEM;
73192
73193@@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73194 locked = mm->locked_vm + grow;
73195 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73196 limit >>= PAGE_SHIFT;
73197+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73198 if (locked > limit && !capable(CAP_IPC_LOCK))
73199 return -ENOMEM;
73200 }
73201@@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73202 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73203 * vma is the last one with address > vma->vm_end. Have to extend vma.
73204 */
73205+#ifndef CONFIG_IA64
73206+static
73207+#endif
73208 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73209 {
73210 int error;
73211+ bool locknext;
73212
73213 if (!(vma->vm_flags & VM_GROWSUP))
73214 return -EFAULT;
73215
73216+ /* Also guard against wrapping around to address 0. */
73217+ if (address < PAGE_ALIGN(address+1))
73218+ address = PAGE_ALIGN(address+1);
73219+ else
73220+ return -ENOMEM;
73221+
73222 /*
73223 * We must make sure the anon_vma is allocated
73224 * so that the anon_vma locking is not a noop.
73225 */
73226 if (unlikely(anon_vma_prepare(vma)))
73227 return -ENOMEM;
73228+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73229+ if (locknext && anon_vma_prepare(vma->vm_next))
73230+ return -ENOMEM;
73231 vma_lock_anon_vma(vma);
73232+ if (locknext)
73233+ vma_lock_anon_vma(vma->vm_next);
73234
73235 /*
73236 * vma->vm_start/vm_end cannot change under us because the caller
73237 * is required to hold the mmap_sem in read mode. We need the
73238- * anon_vma lock to serialize against concurrent expand_stacks.
73239- * Also guard against wrapping around to address 0.
73240+ * anon_vma locks to serialize against concurrent expand_stacks
73241+ * and expand_upwards.
73242 */
73243- if (address < PAGE_ALIGN(address+4))
73244- address = PAGE_ALIGN(address+4);
73245- else {
73246- vma_unlock_anon_vma(vma);
73247- return -ENOMEM;
73248- }
73249 error = 0;
73250
73251 /* Somebody else might have raced and expanded it already */
73252- if (address > vma->vm_end) {
73253+ 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)
73254+ error = -ENOMEM;
73255+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73256 unsigned long size, grow;
73257
73258 size = address - vma->vm_start;
73259@@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73260 }
73261 }
73262 }
73263+ if (locknext)
73264+ vma_unlock_anon_vma(vma->vm_next);
73265 vma_unlock_anon_vma(vma);
73266 khugepaged_enter_vma_merge(vma);
73267 return error;
73268@@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
73269 unsigned long address)
73270 {
73271 int error;
73272+ bool lockprev = false;
73273+ struct vm_area_struct *prev;
73274
73275 /*
73276 * We must make sure the anon_vma is allocated
73277@@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
73278 if (error)
73279 return error;
73280
73281+ prev = vma->vm_prev;
73282+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73283+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73284+#endif
73285+ if (lockprev && anon_vma_prepare(prev))
73286+ return -ENOMEM;
73287+ if (lockprev)
73288+ vma_lock_anon_vma(prev);
73289+
73290 vma_lock_anon_vma(vma);
73291
73292 /*
73293@@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
73294 */
73295
73296 /* Somebody else might have raced and expanded it already */
73297- if (address < vma->vm_start) {
73298+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73299+ error = -ENOMEM;
73300+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73301 unsigned long size, grow;
73302
73303+#ifdef CONFIG_PAX_SEGMEXEC
73304+ struct vm_area_struct *vma_m;
73305+
73306+ vma_m = pax_find_mirror_vma(vma);
73307+#endif
73308+
73309 size = vma->vm_end - address;
73310 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73311
73312@@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
73313 if (!error) {
73314 vma->vm_start = address;
73315 vma->vm_pgoff -= grow;
73316+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73317+
73318+#ifdef CONFIG_PAX_SEGMEXEC
73319+ if (vma_m) {
73320+ vma_m->vm_start -= grow << PAGE_SHIFT;
73321+ vma_m->vm_pgoff -= grow;
73322+ }
73323+#endif
73324+
73325 perf_event_mmap(vma);
73326 }
73327 }
73328 }
73329 vma_unlock_anon_vma(vma);
73330+ if (lockprev)
73331+ vma_unlock_anon_vma(prev);
73332 khugepaged_enter_vma_merge(vma);
73333 return error;
73334 }
73335@@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73336 do {
73337 long nrpages = vma_pages(vma);
73338
73339+#ifdef CONFIG_PAX_SEGMEXEC
73340+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73341+ vma = remove_vma(vma);
73342+ continue;
73343+ }
73344+#endif
73345+
73346 if (vma->vm_flags & VM_ACCOUNT)
73347 nr_accounted += nrpages;
73348 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73349@@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73350 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73351 vma->vm_prev = NULL;
73352 do {
73353+
73354+#ifdef CONFIG_PAX_SEGMEXEC
73355+ if (vma->vm_mirror) {
73356+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73357+ vma->vm_mirror->vm_mirror = NULL;
73358+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
73359+ vma->vm_mirror = NULL;
73360+ }
73361+#endif
73362+
73363 rb_erase(&vma->vm_rb, &mm->mm_rb);
73364 mm->map_count--;
73365 tail_vma = vma;
73366@@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73367 struct vm_area_struct *new;
73368 int err = -ENOMEM;
73369
73370+#ifdef CONFIG_PAX_SEGMEXEC
73371+ struct vm_area_struct *vma_m, *new_m = NULL;
73372+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73373+#endif
73374+
73375 if (is_vm_hugetlb_page(vma) && (addr &
73376 ~(huge_page_mask(hstate_vma(vma)))))
73377 return -EINVAL;
73378
73379+#ifdef CONFIG_PAX_SEGMEXEC
73380+ vma_m = pax_find_mirror_vma(vma);
73381+#endif
73382+
73383 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73384 if (!new)
73385 goto out_err;
73386
73387+#ifdef CONFIG_PAX_SEGMEXEC
73388+ if (vma_m) {
73389+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73390+ if (!new_m) {
73391+ kmem_cache_free(vm_area_cachep, new);
73392+ goto out_err;
73393+ }
73394+ }
73395+#endif
73396+
73397 /* most fields are the same, copy all, and then fixup */
73398 *new = *vma;
73399
73400@@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73401 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73402 }
73403
73404+#ifdef CONFIG_PAX_SEGMEXEC
73405+ if (vma_m) {
73406+ *new_m = *vma_m;
73407+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
73408+ new_m->vm_mirror = new;
73409+ new->vm_mirror = new_m;
73410+
73411+ if (new_below)
73412+ new_m->vm_end = addr_m;
73413+ else {
73414+ new_m->vm_start = addr_m;
73415+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73416+ }
73417+ }
73418+#endif
73419+
73420 pol = mpol_dup(vma_policy(vma));
73421 if (IS_ERR(pol)) {
73422 err = PTR_ERR(pol);
73423@@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73424 else
73425 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73426
73427+#ifdef CONFIG_PAX_SEGMEXEC
73428+ if (!err && vma_m) {
73429+ if (anon_vma_clone(new_m, vma_m))
73430+ goto out_free_mpol;
73431+
73432+ mpol_get(pol);
73433+ vma_set_policy(new_m, pol);
73434+
73435+ if (new_m->vm_file) {
73436+ get_file(new_m->vm_file);
73437+ if (vma_m->vm_flags & VM_EXECUTABLE)
73438+ added_exe_file_vma(mm);
73439+ }
73440+
73441+ if (new_m->vm_ops && new_m->vm_ops->open)
73442+ new_m->vm_ops->open(new_m);
73443+
73444+ if (new_below)
73445+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73446+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73447+ else
73448+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73449+
73450+ if (err) {
73451+ if (new_m->vm_ops && new_m->vm_ops->close)
73452+ new_m->vm_ops->close(new_m);
73453+ if (new_m->vm_file) {
73454+ if (vma_m->vm_flags & VM_EXECUTABLE)
73455+ removed_exe_file_vma(mm);
73456+ fput(new_m->vm_file);
73457+ }
73458+ mpol_put(pol);
73459+ }
73460+ }
73461+#endif
73462+
73463 /* Success. */
73464 if (!err)
73465 return 0;
73466@@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73467 removed_exe_file_vma(mm);
73468 fput(new->vm_file);
73469 }
73470- unlink_anon_vmas(new);
73471 out_free_mpol:
73472 mpol_put(pol);
73473 out_free_vma:
73474+
73475+#ifdef CONFIG_PAX_SEGMEXEC
73476+ if (new_m) {
73477+ unlink_anon_vmas(new_m);
73478+ kmem_cache_free(vm_area_cachep, new_m);
73479+ }
73480+#endif
73481+
73482+ unlink_anon_vmas(new);
73483 kmem_cache_free(vm_area_cachep, new);
73484 out_err:
73485 return err;
73486@@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73487 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73488 unsigned long addr, int new_below)
73489 {
73490+
73491+#ifdef CONFIG_PAX_SEGMEXEC
73492+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73493+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73494+ if (mm->map_count >= sysctl_max_map_count-1)
73495+ return -ENOMEM;
73496+ } else
73497+#endif
73498+
73499 if (mm->map_count >= sysctl_max_map_count)
73500 return -ENOMEM;
73501
73502@@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73503 * work. This now handles partial unmappings.
73504 * Jeremy Fitzhardinge <jeremy@goop.org>
73505 */
73506+#ifdef CONFIG_PAX_SEGMEXEC
73507 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73508 {
73509+ int ret = __do_munmap(mm, start, len);
73510+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73511+ return ret;
73512+
73513+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73514+}
73515+
73516+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73517+#else
73518+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73519+#endif
73520+{
73521 unsigned long end;
73522 struct vm_area_struct *vma, *prev, *last;
73523
73524+ /*
73525+ * mm->mmap_sem is required to protect against another thread
73526+ * changing the mappings in case we sleep.
73527+ */
73528+ verify_mm_writelocked(mm);
73529+
73530 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73531 return -EINVAL;
73532
73533@@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73534 /* Fix up all other VM information */
73535 remove_vma_list(mm, vma);
73536
73537+ track_exec_limit(mm, start, end, 0UL);
73538+
73539 return 0;
73540 }
73541
73542@@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
73543 int ret;
73544 struct mm_struct *mm = current->mm;
73545
73546+
73547+#ifdef CONFIG_PAX_SEGMEXEC
73548+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73549+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73550+ return -EINVAL;
73551+#endif
73552+
73553 down_write(&mm->mmap_sem);
73554 ret = do_munmap(mm, start, len);
73555 up_write(&mm->mmap_sem);
73556@@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73557 return vm_munmap(addr, len);
73558 }
73559
73560-static inline void verify_mm_writelocked(struct mm_struct *mm)
73561-{
73562-#ifdef CONFIG_DEBUG_VM
73563- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73564- WARN_ON(1);
73565- up_read(&mm->mmap_sem);
73566- }
73567-#endif
73568-}
73569-
73570 /*
73571 * this is really a simplified "do_mmap". it only handles
73572 * anonymous maps. eventually we may be able to do some
73573@@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73574 struct rb_node ** rb_link, * rb_parent;
73575 pgoff_t pgoff = addr >> PAGE_SHIFT;
73576 int error;
73577+ unsigned long charged;
73578
73579 len = PAGE_ALIGN(len);
73580 if (!len)
73581@@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73582
73583 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73584
73585+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73586+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73587+ flags &= ~VM_EXEC;
73588+
73589+#ifdef CONFIG_PAX_MPROTECT
73590+ if (mm->pax_flags & MF_PAX_MPROTECT)
73591+ flags &= ~VM_MAYEXEC;
73592+#endif
73593+
73594+ }
73595+#endif
73596+
73597 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73598 if (error & ~PAGE_MASK)
73599 return error;
73600
73601+ charged = len >> PAGE_SHIFT;
73602+
73603 /*
73604 * mlock MCL_FUTURE?
73605 */
73606 if (mm->def_flags & VM_LOCKED) {
73607 unsigned long locked, lock_limit;
73608- locked = len >> PAGE_SHIFT;
73609+ locked = charged;
73610 locked += mm->locked_vm;
73611 lock_limit = rlimit(RLIMIT_MEMLOCK);
73612 lock_limit >>= PAGE_SHIFT;
73613@@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73614 /*
73615 * Clear old maps. this also does some error checking for us
73616 */
73617- munmap_back:
73618 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73619 if (vma && vma->vm_start < addr + len) {
73620 if (do_munmap(mm, addr, len))
73621 return -ENOMEM;
73622- goto munmap_back;
73623- }
73624+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73625+ BUG_ON(vma && vma->vm_start < addr + len);
73626+ }
73627
73628 /* Check against address space limits *after* clearing old maps... */
73629- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73630+ if (!may_expand_vm(mm, charged))
73631 return -ENOMEM;
73632
73633 if (mm->map_count > sysctl_max_map_count)
73634 return -ENOMEM;
73635
73636- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73637+ if (security_vm_enough_memory_mm(mm, charged))
73638 return -ENOMEM;
73639
73640 /* Can we just expand an old private anonymous mapping? */
73641@@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73642 */
73643 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73644 if (!vma) {
73645- vm_unacct_memory(len >> PAGE_SHIFT);
73646+ vm_unacct_memory(charged);
73647 return -ENOMEM;
73648 }
73649
73650@@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73651 vma_link(mm, vma, prev, rb_link, rb_parent);
73652 out:
73653 perf_event_mmap(vma);
73654- mm->total_vm += len >> PAGE_SHIFT;
73655+ mm->total_vm += charged;
73656 if (flags & VM_LOCKED) {
73657 if (!mlock_vma_pages_range(vma, addr, addr + len))
73658- mm->locked_vm += (len >> PAGE_SHIFT);
73659+ mm->locked_vm += charged;
73660 }
73661+ track_exec_limit(mm, addr, addr + len, flags);
73662 return addr;
73663 }
73664
73665@@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
73666 while (vma) {
73667 if (vma->vm_flags & VM_ACCOUNT)
73668 nr_accounted += vma_pages(vma);
73669+ vma->vm_mirror = NULL;
73670 vma = remove_vma(vma);
73671 }
73672 vm_unacct_memory(nr_accounted);
73673@@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73674 struct vm_area_struct * __vma, * prev;
73675 struct rb_node ** rb_link, * rb_parent;
73676
73677+#ifdef CONFIG_PAX_SEGMEXEC
73678+ struct vm_area_struct *vma_m = NULL;
73679+#endif
73680+
73681+ if (security_mmap_addr(vma->vm_start))
73682+ return -EPERM;
73683+
73684 /*
73685 * The vm_pgoff of a purely anonymous vma should be irrelevant
73686 * until its first write fault, when page's anon_vma and index
73687@@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73688 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73689 return -ENOMEM;
73690
73691+#ifdef CONFIG_PAX_SEGMEXEC
73692+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73693+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73694+ if (!vma_m)
73695+ return -ENOMEM;
73696+ }
73697+#endif
73698+
73699 vma_link(mm, vma, prev, rb_link, rb_parent);
73700+
73701+#ifdef CONFIG_PAX_SEGMEXEC
73702+ if (vma_m)
73703+ BUG_ON(pax_mirror_vma(vma_m, vma));
73704+#endif
73705+
73706 return 0;
73707 }
73708
73709@@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73710 struct mempolicy *pol;
73711 bool faulted_in_anon_vma = true;
73712
73713+ BUG_ON(vma->vm_mirror);
73714+
73715 /*
73716 * If anonymous vma has not yet been faulted, update new pgoff
73717 * to match new location, to increase its chance of merging.
73718@@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73719 return NULL;
73720 }
73721
73722+#ifdef CONFIG_PAX_SEGMEXEC
73723+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73724+{
73725+ struct vm_area_struct *prev_m;
73726+ struct rb_node **rb_link_m, *rb_parent_m;
73727+ struct mempolicy *pol_m;
73728+
73729+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73730+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73731+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73732+ *vma_m = *vma;
73733+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73734+ if (anon_vma_clone(vma_m, vma))
73735+ return -ENOMEM;
73736+ pol_m = vma_policy(vma_m);
73737+ mpol_get(pol_m);
73738+ vma_set_policy(vma_m, pol_m);
73739+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73740+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73741+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73742+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73743+ if (vma_m->vm_file)
73744+ get_file(vma_m->vm_file);
73745+ if (vma_m->vm_ops && vma_m->vm_ops->open)
73746+ vma_m->vm_ops->open(vma_m);
73747+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73748+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73749+ vma_m->vm_mirror = vma;
73750+ vma->vm_mirror = vma_m;
73751+ return 0;
73752+}
73753+#endif
73754+
73755 /*
73756 * Return true if the calling process may expand its vm space by the passed
73757 * number of pages
73758@@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73759
73760 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73761
73762+#ifdef CONFIG_PAX_RANDMMAP
73763+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73764+ cur -= mm->brk_gap;
73765+#endif
73766+
73767+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73768 if (cur + npages > lim)
73769 return 0;
73770 return 1;
73771@@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
73772 vma->vm_start = addr;
73773 vma->vm_end = addr + len;
73774
73775+#ifdef CONFIG_PAX_MPROTECT
73776+ if (mm->pax_flags & MF_PAX_MPROTECT) {
73777+#ifndef CONFIG_PAX_MPROTECT_COMPAT
73778+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73779+ return -EPERM;
73780+ if (!(vm_flags & VM_EXEC))
73781+ vm_flags &= ~VM_MAYEXEC;
73782+#else
73783+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73784+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73785+#endif
73786+ else
73787+ vm_flags &= ~VM_MAYWRITE;
73788+ }
73789+#endif
73790+
73791 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73792 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73793
73794diff --git a/mm/mprotect.c b/mm/mprotect.c
73795index a409926..8b32e6d 100644
73796--- a/mm/mprotect.c
73797+++ b/mm/mprotect.c
73798@@ -23,10 +23,17 @@
73799 #include <linux/mmu_notifier.h>
73800 #include <linux/migrate.h>
73801 #include <linux/perf_event.h>
73802+
73803+#ifdef CONFIG_PAX_MPROTECT
73804+#include <linux/elf.h>
73805+#include <linux/binfmts.h>
73806+#endif
73807+
73808 #include <asm/uaccess.h>
73809 #include <asm/pgtable.h>
73810 #include <asm/cacheflush.h>
73811 #include <asm/tlbflush.h>
73812+#include <asm/mmu_context.h>
73813
73814 #ifndef pgprot_modify
73815 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73816@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73817 flush_tlb_range(vma, start, end);
73818 }
73819
73820+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73821+/* called while holding the mmap semaphor for writing except stack expansion */
73822+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73823+{
73824+ unsigned long oldlimit, newlimit = 0UL;
73825+
73826+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73827+ return;
73828+
73829+ spin_lock(&mm->page_table_lock);
73830+ oldlimit = mm->context.user_cs_limit;
73831+ if ((prot & VM_EXEC) && oldlimit < end)
73832+ /* USER_CS limit moved up */
73833+ newlimit = end;
73834+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73835+ /* USER_CS limit moved down */
73836+ newlimit = start;
73837+
73838+ if (newlimit) {
73839+ mm->context.user_cs_limit = newlimit;
73840+
73841+#ifdef CONFIG_SMP
73842+ wmb();
73843+ cpus_clear(mm->context.cpu_user_cs_mask);
73844+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73845+#endif
73846+
73847+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73848+ }
73849+ spin_unlock(&mm->page_table_lock);
73850+ if (newlimit == end) {
73851+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
73852+
73853+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
73854+ if (is_vm_hugetlb_page(vma))
73855+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73856+ else
73857+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73858+ }
73859+}
73860+#endif
73861+
73862 int
73863 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73864 unsigned long start, unsigned long end, unsigned long newflags)
73865@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73866 int error;
73867 int dirty_accountable = 0;
73868
73869+#ifdef CONFIG_PAX_SEGMEXEC
73870+ struct vm_area_struct *vma_m = NULL;
73871+ unsigned long start_m, end_m;
73872+
73873+ start_m = start + SEGMEXEC_TASK_SIZE;
73874+ end_m = end + SEGMEXEC_TASK_SIZE;
73875+#endif
73876+
73877 if (newflags == oldflags) {
73878 *pprev = vma;
73879 return 0;
73880 }
73881
73882+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73883+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73884+
73885+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73886+ return -ENOMEM;
73887+
73888+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73889+ return -ENOMEM;
73890+ }
73891+
73892 /*
73893 * If we make a private mapping writable we increase our commit;
73894 * but (without finer accounting) cannot reduce our commit if we
73895@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73896 }
73897 }
73898
73899+#ifdef CONFIG_PAX_SEGMEXEC
73900+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73901+ if (start != vma->vm_start) {
73902+ error = split_vma(mm, vma, start, 1);
73903+ if (error)
73904+ goto fail;
73905+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73906+ *pprev = (*pprev)->vm_next;
73907+ }
73908+
73909+ if (end != vma->vm_end) {
73910+ error = split_vma(mm, vma, end, 0);
73911+ if (error)
73912+ goto fail;
73913+ }
73914+
73915+ if (pax_find_mirror_vma(vma)) {
73916+ error = __do_munmap(mm, start_m, end_m - start_m);
73917+ if (error)
73918+ goto fail;
73919+ } else {
73920+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73921+ if (!vma_m) {
73922+ error = -ENOMEM;
73923+ goto fail;
73924+ }
73925+ vma->vm_flags = newflags;
73926+ error = pax_mirror_vma(vma_m, vma);
73927+ if (error) {
73928+ vma->vm_flags = oldflags;
73929+ goto fail;
73930+ }
73931+ }
73932+ }
73933+#endif
73934+
73935 /*
73936 * First try to merge with previous and/or next vma.
73937 */
73938@@ -204,9 +307,21 @@ success:
73939 * vm_flags and vm_page_prot are protected by the mmap_sem
73940 * held in write mode.
73941 */
73942+
73943+#ifdef CONFIG_PAX_SEGMEXEC
73944+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73945+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73946+#endif
73947+
73948 vma->vm_flags = newflags;
73949+
73950+#ifdef CONFIG_PAX_MPROTECT
73951+ if (mm->binfmt && mm->binfmt->handle_mprotect)
73952+ mm->binfmt->handle_mprotect(vma, newflags);
73953+#endif
73954+
73955 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73956- vm_get_page_prot(newflags));
73957+ vm_get_page_prot(vma->vm_flags));
73958
73959 if (vma_wants_writenotify(vma)) {
73960 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73961@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73962 end = start + len;
73963 if (end <= start)
73964 return -ENOMEM;
73965+
73966+#ifdef CONFIG_PAX_SEGMEXEC
73967+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73968+ if (end > SEGMEXEC_TASK_SIZE)
73969+ return -EINVAL;
73970+ } else
73971+#endif
73972+
73973+ if (end > TASK_SIZE)
73974+ return -EINVAL;
73975+
73976 if (!arch_validate_prot(prot))
73977 return -EINVAL;
73978
73979@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73980 /*
73981 * Does the application expect PROT_READ to imply PROT_EXEC:
73982 */
73983- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73984+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73985 prot |= PROT_EXEC;
73986
73987 vm_flags = calc_vm_prot_bits(prot);
73988@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73989 if (start > vma->vm_start)
73990 prev = vma;
73991
73992+#ifdef CONFIG_PAX_MPROTECT
73993+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73994+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
73995+#endif
73996+
73997 for (nstart = start ; ; ) {
73998 unsigned long newflags;
73999
74000@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74001
74002 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74003 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74004+ if (prot & (PROT_WRITE | PROT_EXEC))
74005+ gr_log_rwxmprotect(vma->vm_file);
74006+
74007+ error = -EACCES;
74008+ goto out;
74009+ }
74010+
74011+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74012 error = -EACCES;
74013 goto out;
74014 }
74015@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74016 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74017 if (error)
74018 goto out;
74019+
74020+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
74021+
74022 nstart = tmp;
74023
74024 if (nstart < prev->vm_end)
74025diff --git a/mm/mremap.c b/mm/mremap.c
74026index cc06d0e..40b5d18 100644
74027--- a/mm/mremap.c
74028+++ b/mm/mremap.c
74029@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74030 continue;
74031 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74032 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74033+
74034+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74035+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74036+ pte = pte_exprotect(pte);
74037+#endif
74038+
74039 set_pte_at(mm, new_addr, new_pte, pte);
74040 }
74041
74042@@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74043 if (is_vm_hugetlb_page(vma))
74044 goto Einval;
74045
74046+#ifdef CONFIG_PAX_SEGMEXEC
74047+ if (pax_find_mirror_vma(vma))
74048+ goto Einval;
74049+#endif
74050+
74051 /* We can't remap across vm area boundaries */
74052 if (old_len > vma->vm_end - addr)
74053 goto Efault;
74054@@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74055 unsigned long ret = -EINVAL;
74056 unsigned long charged = 0;
74057 unsigned long map_flags;
74058+ unsigned long pax_task_size = TASK_SIZE;
74059
74060 if (new_addr & ~PAGE_MASK)
74061 goto out;
74062
74063- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74064+#ifdef CONFIG_PAX_SEGMEXEC
74065+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
74066+ pax_task_size = SEGMEXEC_TASK_SIZE;
74067+#endif
74068+
74069+ pax_task_size -= PAGE_SIZE;
74070+
74071+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74072 goto out;
74073
74074 /* Check if the location we're moving into overlaps the
74075 * old location at all, and fail if it does.
74076 */
74077- if ((new_addr <= addr) && (new_addr+new_len) > addr)
74078- goto out;
74079-
74080- if ((addr <= new_addr) && (addr+old_len) > new_addr)
74081+ if (addr + old_len > new_addr && new_addr + new_len > addr)
74082 goto out;
74083
74084 ret = do_munmap(mm, new_addr, new_len);
74085@@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74086 struct vm_area_struct *vma;
74087 unsigned long ret = -EINVAL;
74088 unsigned long charged = 0;
74089+ unsigned long pax_task_size = TASK_SIZE;
74090
74091 down_write(&current->mm->mmap_sem);
74092
74093@@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74094 if (!new_len)
74095 goto out;
74096
74097+#ifdef CONFIG_PAX_SEGMEXEC
74098+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
74099+ pax_task_size = SEGMEXEC_TASK_SIZE;
74100+#endif
74101+
74102+ pax_task_size -= PAGE_SIZE;
74103+
74104+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74105+ old_len > pax_task_size || addr > pax_task_size-old_len)
74106+ goto out;
74107+
74108 if (flags & MREMAP_FIXED) {
74109 if (flags & MREMAP_MAYMOVE)
74110 ret = mremap_to(addr, old_len, new_addr, new_len);
74111@@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74112 addr + new_len);
74113 }
74114 ret = addr;
74115+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74116 goto out;
74117 }
74118 }
74119@@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74120 goto out;
74121 }
74122
74123+ map_flags = vma->vm_flags;
74124 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74125+ if (!(ret & ~PAGE_MASK)) {
74126+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74127+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74128+ }
74129 }
74130 out:
74131 if (ret & ~PAGE_MASK)
74132diff --git a/mm/nommu.c b/mm/nommu.c
74133index d4b0c10..ed421b5 100644
74134--- a/mm/nommu.c
74135+++ b/mm/nommu.c
74136@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74137 int sysctl_overcommit_ratio = 50; /* default is 50% */
74138 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74139 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74140-int heap_stack_gap = 0;
74141
74142 atomic_long_t mmap_pages_allocated;
74143
74144@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74145 EXPORT_SYMBOL(find_vma);
74146
74147 /*
74148- * find a VMA
74149- * - we don't extend stack VMAs under NOMMU conditions
74150- */
74151-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74152-{
74153- return find_vma(mm, addr);
74154-}
74155-
74156-/*
74157 * expand a stack to a given address
74158 * - not supported under NOMMU conditions
74159 */
74160@@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74161
74162 /* most fields are the same, copy all, and then fixup */
74163 *new = *vma;
74164+ INIT_LIST_HEAD(&new->anon_vma_chain);
74165 *region = *vma->vm_region;
74166 new->vm_region = region;
74167
74168diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74169index c13ea75..081ab2c 100644
74170--- a/mm/page_alloc.c
74171+++ b/mm/page_alloc.c
74172@@ -340,7 +340,7 @@ out:
74173 * This usage means that zero-order pages may not be compound.
74174 */
74175
74176-static void free_compound_page(struct page *page)
74177+void free_compound_page(struct page *page)
74178 {
74179 __free_pages_ok(page, compound_order(page));
74180 }
74181@@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74182 int i;
74183 int bad = 0;
74184
74185+#ifdef CONFIG_PAX_MEMORY_SANITIZE
74186+ unsigned long index = 1UL << order;
74187+#endif
74188+
74189 trace_mm_page_free(page, order);
74190 kmemcheck_free_shadow(page, order);
74191
74192@@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74193 debug_check_no_obj_freed(page_address(page),
74194 PAGE_SIZE << order);
74195 }
74196+
74197+#ifdef CONFIG_PAX_MEMORY_SANITIZE
74198+ for (; index; --index)
74199+ sanitize_highpage(page + index - 1);
74200+#endif
74201+
74202 arch_free_page(page, order);
74203 kernel_map_pages(page, 1 << order, 0);
74204
74205@@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74206 arch_alloc_page(page, order);
74207 kernel_map_pages(page, 1 << order, 1);
74208
74209+#ifndef CONFIG_PAX_MEMORY_SANITIZE
74210 if (gfp_flags & __GFP_ZERO)
74211 prep_zero_page(page, order, gfp_flags);
74212+#endif
74213
74214 if (order && (gfp_flags & __GFP_COMP))
74215 prep_compound_page(page, order);
74216@@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74217 unsigned long pfn;
74218
74219 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74220+#ifdef CONFIG_X86_32
74221+ /* boot failures in VMware 8 on 32bit vanilla since
74222+ this change */
74223+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74224+#else
74225 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74226+#endif
74227 return 1;
74228 }
74229 return 0;
74230diff --git a/mm/percpu.c b/mm/percpu.c
74231index bb4be74..a43ea85 100644
74232--- a/mm/percpu.c
74233+++ b/mm/percpu.c
74234@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74235 static unsigned int pcpu_high_unit_cpu __read_mostly;
74236
74237 /* the address of the first chunk which starts with the kernel static area */
74238-void *pcpu_base_addr __read_mostly;
74239+void *pcpu_base_addr __read_only;
74240 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74241
74242 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74243diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74244index 926b466..b23df53 100644
74245--- a/mm/process_vm_access.c
74246+++ b/mm/process_vm_access.c
74247@@ -13,6 +13,7 @@
74248 #include <linux/uio.h>
74249 #include <linux/sched.h>
74250 #include <linux/highmem.h>
74251+#include <linux/security.h>
74252 #include <linux/ptrace.h>
74253 #include <linux/slab.h>
74254 #include <linux/syscalls.h>
74255@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74256 size_t iov_l_curr_offset = 0;
74257 ssize_t iov_len;
74258
74259+ return -ENOSYS; // PaX: until properly audited
74260+
74261 /*
74262 * Work out how many pages of struct pages we're going to need
74263 * when eventually calling get_user_pages
74264 */
74265 for (i = 0; i < riovcnt; i++) {
74266 iov_len = rvec[i].iov_len;
74267- if (iov_len > 0) {
74268- nr_pages_iov = ((unsigned long)rvec[i].iov_base
74269- + iov_len)
74270- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74271- / PAGE_SIZE + 1;
74272- nr_pages = max(nr_pages, nr_pages_iov);
74273- }
74274+ if (iov_len <= 0)
74275+ continue;
74276+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74277+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74278+ nr_pages = max(nr_pages, nr_pages_iov);
74279 }
74280
74281 if (nr_pages == 0)
74282@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74283 goto free_proc_pages;
74284 }
74285
74286+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74287+ rc = -EPERM;
74288+ goto put_task_struct;
74289+ }
74290+
74291 mm = mm_access(task, PTRACE_MODE_ATTACH);
74292 if (!mm || IS_ERR(mm)) {
74293 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74294diff --git a/mm/rmap.c b/mm/rmap.c
74295index 0f3b7cd..c5652b6 100644
74296--- a/mm/rmap.c
74297+++ b/mm/rmap.c
74298@@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74299 struct anon_vma *anon_vma = vma->anon_vma;
74300 struct anon_vma_chain *avc;
74301
74302+#ifdef CONFIG_PAX_SEGMEXEC
74303+ struct anon_vma_chain *avc_m = NULL;
74304+#endif
74305+
74306 might_sleep();
74307 if (unlikely(!anon_vma)) {
74308 struct mm_struct *mm = vma->vm_mm;
74309@@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74310 if (!avc)
74311 goto out_enomem;
74312
74313+#ifdef CONFIG_PAX_SEGMEXEC
74314+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74315+ if (!avc_m)
74316+ goto out_enomem_free_avc;
74317+#endif
74318+
74319 anon_vma = find_mergeable_anon_vma(vma);
74320 allocated = NULL;
74321 if (!anon_vma) {
74322@@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74323 /* page_table_lock to protect against threads */
74324 spin_lock(&mm->page_table_lock);
74325 if (likely(!vma->anon_vma)) {
74326+
74327+#ifdef CONFIG_PAX_SEGMEXEC
74328+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74329+
74330+ if (vma_m) {
74331+ BUG_ON(vma_m->anon_vma);
74332+ vma_m->anon_vma = anon_vma;
74333+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
74334+ avc_m = NULL;
74335+ }
74336+#endif
74337+
74338 vma->anon_vma = anon_vma;
74339 anon_vma_chain_link(vma, avc, anon_vma);
74340 allocated = NULL;
74341@@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74342
74343 if (unlikely(allocated))
74344 put_anon_vma(allocated);
74345+
74346+#ifdef CONFIG_PAX_SEGMEXEC
74347+ if (unlikely(avc_m))
74348+ anon_vma_chain_free(avc_m);
74349+#endif
74350+
74351 if (unlikely(avc))
74352 anon_vma_chain_free(avc);
74353 }
74354 return 0;
74355
74356 out_enomem_free_avc:
74357+
74358+#ifdef CONFIG_PAX_SEGMEXEC
74359+ if (avc_m)
74360+ anon_vma_chain_free(avc_m);
74361+#endif
74362+
74363 anon_vma_chain_free(avc);
74364 out_enomem:
74365 return -ENOMEM;
74366@@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74367 * Attach the anon_vmas from src to dst.
74368 * Returns 0 on success, -ENOMEM on failure.
74369 */
74370-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74371+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74372 {
74373 struct anon_vma_chain *avc, *pavc;
74374 struct anon_vma *root = NULL;
74375@@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74376 * the corresponding VMA in the parent process is attached to.
74377 * Returns 0 on success, non-zero on failure.
74378 */
74379-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74380+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74381 {
74382 struct anon_vma_chain *avc;
74383 struct anon_vma *anon_vma;
74384diff --git a/mm/shmem.c b/mm/shmem.c
74385index d4e184e..9953cdd 100644
74386--- a/mm/shmem.c
74387+++ b/mm/shmem.c
74388@@ -31,7 +31,7 @@
74389 #include <linux/export.h>
74390 #include <linux/swap.h>
74391
74392-static struct vfsmount *shm_mnt;
74393+struct vfsmount *shm_mnt;
74394
74395 #ifdef CONFIG_SHMEM
74396 /*
74397@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74398 #define BOGO_DIRENT_SIZE 20
74399
74400 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74401-#define SHORT_SYMLINK_LEN 128
74402+#define SHORT_SYMLINK_LEN 64
74403
74404 struct shmem_xattr {
74405 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74406@@ -2592,8 +2592,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74407 int err = -ENOMEM;
74408
74409 /* Round up to L1_CACHE_BYTES to resist false sharing */
74410- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74411- L1_CACHE_BYTES), GFP_KERNEL);
74412+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74413 if (!sbinfo)
74414 return -ENOMEM;
74415
74416diff --git a/mm/slab.c b/mm/slab.c
74417index c685475..7427067 100644
74418--- a/mm/slab.c
74419+++ b/mm/slab.c
74420@@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
74421
74422 /* Legal flag mask for kmem_cache_create(). */
74423 #if DEBUG
74424-# define CREATE_MASK (SLAB_RED_ZONE | \
74425+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74426 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74427 SLAB_CACHE_DMA | \
74428 SLAB_STORE_USER | \
74429@@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
74430 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74431 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74432 #else
74433-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74434+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74435 SLAB_CACHE_DMA | \
74436 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74437 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74438@@ -322,7 +322,7 @@ struct kmem_list3 {
74439 * Need this for bootstrapping a per node allocator.
74440 */
74441 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74442-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74443+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74444 #define CACHE_CACHE 0
74445 #define SIZE_AC MAX_NUMNODES
74446 #define SIZE_L3 (2 * MAX_NUMNODES)
74447@@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74448 if ((x)->max_freeable < i) \
74449 (x)->max_freeable = i; \
74450 } while (0)
74451-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74452-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74453-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74454-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74455+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74456+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74457+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74458+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74459 #else
74460 #define STATS_INC_ACTIVE(x) do { } while (0)
74461 #define STATS_DEC_ACTIVE(x) do { } while (0)
74462@@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74463 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74464 */
74465 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74466- const struct slab *slab, void *obj)
74467+ const struct slab *slab, const void *obj)
74468 {
74469 u32 offset = (obj - slab->s_mem);
74470 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74471@@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
74472 struct cache_names {
74473 char *name;
74474 char *name_dma;
74475+ char *name_usercopy;
74476 };
74477
74478 static struct cache_names __initdata cache_names[] = {
74479-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74480+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74481 #include <linux/kmalloc_sizes.h>
74482- {NULL,}
74483+ {NULL}
74484 #undef CACHE
74485 };
74486
74487@@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74488 if (unlikely(gfpflags & GFP_DMA))
74489 return csizep->cs_dmacachep;
74490 #endif
74491+
74492+#ifdef CONFIG_PAX_USERCOPY_SLABS
74493+ if (unlikely(gfpflags & GFP_USERCOPY))
74494+ return csizep->cs_usercopycachep;
74495+#endif
74496+
74497 return csizep->cs_cachep;
74498 }
74499
74500@@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
74501 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
74502 sizes[INDEX_AC].cs_size,
74503 ARCH_KMALLOC_MINALIGN,
74504- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74505+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74506 NULL);
74507
74508 if (INDEX_AC != INDEX_L3) {
74509@@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
74510 __kmem_cache_create(names[INDEX_L3].name,
74511 sizes[INDEX_L3].cs_size,
74512 ARCH_KMALLOC_MINALIGN,
74513- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74514+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74515 NULL);
74516 }
74517
74518@@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
74519 sizes->cs_cachep = __kmem_cache_create(names->name,
74520 sizes->cs_size,
74521 ARCH_KMALLOC_MINALIGN,
74522- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74523+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74524 NULL);
74525 }
74526 #ifdef CONFIG_ZONE_DMA
74527@@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
74528 SLAB_PANIC,
74529 NULL);
74530 #endif
74531+
74532+#ifdef CONFIG_PAX_USERCOPY_SLABS
74533+ sizes->cs_usercopycachep = kmem_cache_create(
74534+ names->name_usercopy,
74535+ sizes->cs_size,
74536+ ARCH_KMALLOC_MINALIGN,
74537+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74538+ NULL);
74539+#endif
74540+
74541 sizes++;
74542 names++;
74543 }
74544@@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
74545 }
74546 /* cpu stats */
74547 {
74548- unsigned long allochit = atomic_read(&cachep->allochit);
74549- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74550- unsigned long freehit = atomic_read(&cachep->freehit);
74551- unsigned long freemiss = atomic_read(&cachep->freemiss);
74552+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74553+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74554+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74555+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74556
74557 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74558 allochit, allocmiss, freehit, freemiss);
74559@@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
74560 {
74561 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74562 #ifdef CONFIG_DEBUG_SLAB_LEAK
74563- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74564+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74565 #endif
74566 return 0;
74567 }
74568 module_init(slab_proc_init);
74569 #endif
74570
74571+bool is_usercopy_object(const void *ptr)
74572+{
74573+ struct page *page;
74574+ struct kmem_cache *cachep;
74575+
74576+ if (ZERO_OR_NULL_PTR(ptr))
74577+ return false;
74578+
74579+ if (!slab_is_available())
74580+ return false;
74581+
74582+ if (!virt_addr_valid(ptr))
74583+ return false;
74584+
74585+ page = virt_to_head_page(ptr);
74586+
74587+ if (!PageSlab(page))
74588+ return false;
74589+
74590+ cachep = page_get_cache(page);
74591+ return cachep->flags & SLAB_USERCOPY;
74592+}
74593+
74594+#ifdef CONFIG_PAX_USERCOPY
74595+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74596+{
74597+ struct page *page;
74598+ struct kmem_cache *cachep;
74599+ struct slab *slabp;
74600+ unsigned int objnr;
74601+ unsigned long offset;
74602+
74603+ if (ZERO_OR_NULL_PTR(ptr))
74604+ return "<null>";
74605+
74606+ if (!virt_addr_valid(ptr))
74607+ return NULL;
74608+
74609+ page = virt_to_head_page(ptr);
74610+
74611+ if (!PageSlab(page))
74612+ return NULL;
74613+
74614+ cachep = page_get_cache(page);
74615+ if (!(cachep->flags & SLAB_USERCOPY))
74616+ return cachep->name;
74617+
74618+ slabp = page->slab_page;
74619+ objnr = obj_to_index(cachep, slabp, ptr);
74620+ BUG_ON(objnr >= cachep->num);
74621+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74622+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
74623+ return NULL;
74624+
74625+ return cachep->name;
74626+}
74627+#endif
74628+
74629 /**
74630 * ksize - get the actual amount of memory allocated for a given object
74631 * @objp: Pointer to the object
74632diff --git a/mm/slob.c b/mm/slob.c
74633index 45d4ca7..88943c1 100644
74634--- a/mm/slob.c
74635+++ b/mm/slob.c
74636@@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74637 /*
74638 * Return the size of a slob block.
74639 */
74640-static slobidx_t slob_units(slob_t *s)
74641+static slobidx_t slob_units(const slob_t *s)
74642 {
74643 if (s->units > 0)
74644 return s->units;
74645@@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
74646 /*
74647 * Return the next free slob block pointer after this one.
74648 */
74649-static slob_t *slob_next(slob_t *s)
74650+static slob_t *slob_next(const slob_t *s)
74651 {
74652 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74653 slobidx_t next;
74654@@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
74655 /*
74656 * Returns true if s is the last free block in its page.
74657 */
74658-static int slob_last(slob_t *s)
74659+static int slob_last(const slob_t *s)
74660 {
74661 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74662 }
74663
74664-static void *slob_new_pages(gfp_t gfp, int order, int node)
74665+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
74666 {
74667- void *page;
74668+ struct page *page;
74669
74670 #ifdef CONFIG_NUMA
74671 if (node != -1)
74672@@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74673 if (!page)
74674 return NULL;
74675
74676- return page_address(page);
74677+ __SetPageSlab(page);
74678+ return page;
74679 }
74680
74681-static void slob_free_pages(void *b, int order)
74682+static void slob_free_pages(struct page *sp, int order)
74683 {
74684 if (current->reclaim_state)
74685 current->reclaim_state->reclaimed_slab += 1 << order;
74686- free_pages((unsigned long)b, order);
74687+ __ClearPageSlab(sp);
74688+ reset_page_mapcount(sp);
74689+ sp->private = 0;
74690+ __free_pages(sp, order);
74691 }
74692
74693 /*
74694@@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74695
74696 /* Not enough space: must allocate a new page */
74697 if (!b) {
74698- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74699- if (!b)
74700+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74701+ if (!sp)
74702 return NULL;
74703- sp = virt_to_page(b);
74704- __SetPageSlab(sp);
74705+ b = page_address(sp);
74706
74707 spin_lock_irqsave(&slob_lock, flags);
74708 sp->units = SLOB_UNITS(PAGE_SIZE);
74709 sp->freelist = b;
74710+ sp->private = 0;
74711 INIT_LIST_HEAD(&sp->list);
74712 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74713 set_slob_page_free(sp, slob_list);
74714@@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
74715 if (slob_page_free(sp))
74716 clear_slob_page_free(sp);
74717 spin_unlock_irqrestore(&slob_lock, flags);
74718- __ClearPageSlab(sp);
74719- reset_page_mapcount(sp);
74720- slob_free_pages(b, 0);
74721+ slob_free_pages(sp, 0);
74722 return;
74723 }
74724
74725@@ -425,11 +427,10 @@ out:
74726 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74727 */
74728
74729-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74730+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74731 {
74732- unsigned int *m;
74733- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74734- void *ret;
74735+ slob_t *m;
74736+ void *ret = NULL;
74737
74738 gfp &= gfp_allowed_mask;
74739
74740@@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74741
74742 if (!m)
74743 return NULL;
74744- *m = size;
74745+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74746+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74747+ m[0].units = size;
74748+ m[1].units = align;
74749 ret = (void *)m + align;
74750
74751 trace_kmalloc_node(_RET_IP_, ret,
74752 size, size + align, gfp, node);
74753 } else {
74754 unsigned int order = get_order(size);
74755+ struct page *page;
74756
74757 if (likely(order))
74758 gfp |= __GFP_COMP;
74759- ret = slob_new_pages(gfp, order, node);
74760- if (ret) {
74761- struct page *page;
74762- page = virt_to_page(ret);
74763+ page = slob_new_pages(gfp, order, node);
74764+ if (page) {
74765+ ret = page_address(page);
74766 page->private = size;
74767 }
74768
74769@@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74770 size, PAGE_SIZE << order, gfp, node);
74771 }
74772
74773- kmemleak_alloc(ret, size, 1, gfp);
74774+ return ret;
74775+}
74776+
74777+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74778+{
74779+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74780+ void *ret = __kmalloc_node_align(size, gfp, node, align);
74781+
74782+ if (!ZERO_OR_NULL_PTR(ret))
74783+ kmemleak_alloc(ret, size, 1, gfp);
74784 return ret;
74785 }
74786 EXPORT_SYMBOL(__kmalloc_node);
74787@@ -480,15 +493,91 @@ void kfree(const void *block)
74788 kmemleak_free(block);
74789
74790 sp = virt_to_page(block);
74791- if (PageSlab(sp)) {
74792+ VM_BUG_ON(!PageSlab(sp));
74793+ if (!sp->private) {
74794 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74795- unsigned int *m = (unsigned int *)(block - align);
74796- slob_free(m, *m + align);
74797- } else
74798+ slob_t *m = (slob_t *)(block - align);
74799+ slob_free(m, m[0].units + align);
74800+ } else {
74801+ __ClearPageSlab(sp);
74802+ reset_page_mapcount(sp);
74803+ sp->private = 0;
74804 put_page(sp);
74805+ }
74806 }
74807 EXPORT_SYMBOL(kfree);
74808
74809+bool is_usercopy_object(const void *ptr)
74810+{
74811+ if (!slab_is_available())
74812+ return false;
74813+
74814+ // PAX: TODO
74815+
74816+ return false;
74817+}
74818+
74819+#ifdef CONFIG_PAX_USERCOPY
74820+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74821+{
74822+ struct page *page;
74823+ const slob_t *free;
74824+ const void *base;
74825+ unsigned long flags;
74826+
74827+ if (ZERO_OR_NULL_PTR(ptr))
74828+ return "<null>";
74829+
74830+ if (!virt_addr_valid(ptr))
74831+ return NULL;
74832+
74833+ page = virt_to_head_page(ptr);
74834+ if (!PageSlab(page))
74835+ return NULL;
74836+
74837+ if (page->private) {
74838+ base = page;
74839+ if (base <= ptr && n <= page->private - (ptr - base))
74840+ return NULL;
74841+ return "<slob>";
74842+ }
74843+
74844+ /* some tricky double walking to find the chunk */
74845+ spin_lock_irqsave(&slob_lock, flags);
74846+ base = (void *)((unsigned long)ptr & PAGE_MASK);
74847+ free = page->freelist;
74848+
74849+ while (!slob_last(free) && (void *)free <= ptr) {
74850+ base = free + slob_units(free);
74851+ free = slob_next(free);
74852+ }
74853+
74854+ while (base < (void *)free) {
74855+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74856+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
74857+ int offset;
74858+
74859+ if (ptr < base + align)
74860+ break;
74861+
74862+ offset = ptr - base - align;
74863+ if (offset >= m) {
74864+ base += size;
74865+ continue;
74866+ }
74867+
74868+ if (n > m - offset)
74869+ break;
74870+
74871+ spin_unlock_irqrestore(&slob_lock, flags);
74872+ return NULL;
74873+ }
74874+
74875+ spin_unlock_irqrestore(&slob_lock, flags);
74876+ return "<slob>";
74877+}
74878+#endif
74879+
74880 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74881 size_t ksize(const void *block)
74882 {
74883@@ -499,10 +588,11 @@ size_t ksize(const void *block)
74884 return 0;
74885
74886 sp = virt_to_page(block);
74887- if (PageSlab(sp)) {
74888+ VM_BUG_ON(!PageSlab(sp));
74889+ if (!sp->private) {
74890 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74891- unsigned int *m = (unsigned int *)(block - align);
74892- return SLOB_UNITS(*m) * SLOB_UNIT;
74893+ slob_t *m = (slob_t *)(block - align);
74894+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74895 } else
74896 return sp->private;
74897 }
74898@@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
74899 {
74900 struct kmem_cache *c;
74901
74902+#ifdef CONFIG_PAX_USERCOPY_SLABS
74903+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
74904+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74905+#else
74906 c = slob_alloc(sizeof(struct kmem_cache),
74907 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74908+#endif
74909
74910 if (c) {
74911 c->name = name;
74912@@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
74913
74914 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74915 {
74916- void *b;
74917+ void *b = NULL;
74918
74919 flags &= gfp_allowed_mask;
74920
74921 lockdep_trace_alloc(flags);
74922
74923+#ifdef CONFIG_PAX_USERCOPY_SLABS
74924+ b = __kmalloc_node_align(c->size, flags, node, c->align);
74925+#else
74926 if (c->size < PAGE_SIZE) {
74927 b = slob_alloc(c->size, flags, c->align, node);
74928 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74929 SLOB_UNITS(c->size) * SLOB_UNIT,
74930 flags, node);
74931 } else {
74932- b = slob_new_pages(flags, get_order(c->size), node);
74933+ struct page *sp;
74934+
74935+ sp = slob_new_pages(flags, get_order(c->size), node);
74936+ if (sp) {
74937+ b = page_address(sp);
74938+ sp->private = c->size;
74939+ }
74940 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74941 PAGE_SIZE << get_order(c->size),
74942 flags, node);
74943 }
74944+#endif
74945
74946 if (c->ctor)
74947 c->ctor(b);
74948@@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74949
74950 static void __kmem_cache_free(void *b, int size)
74951 {
74952- if (size < PAGE_SIZE)
74953+ struct page *sp;
74954+
74955+ sp = virt_to_page(b);
74956+ BUG_ON(!PageSlab(sp));
74957+ if (!sp->private)
74958 slob_free(b, size);
74959 else
74960- slob_free_pages(b, get_order(size));
74961+ slob_free_pages(sp, get_order(size));
74962 }
74963
74964 static void kmem_rcu_free(struct rcu_head *head)
74965@@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74966
74967 void kmem_cache_free(struct kmem_cache *c, void *b)
74968 {
74969+ int size = c->size;
74970+
74971+#ifdef CONFIG_PAX_USERCOPY_SLABS
74972+ if (size + c->align < PAGE_SIZE) {
74973+ size += c->align;
74974+ b -= c->align;
74975+ }
74976+#endif
74977+
74978 kmemleak_free_recursive(b, c->flags);
74979 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74980 struct slob_rcu *slob_rcu;
74981- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74982- slob_rcu->size = c->size;
74983+ slob_rcu = b + (size - sizeof(struct slob_rcu));
74984+ slob_rcu->size = size;
74985 call_rcu(&slob_rcu->head, kmem_rcu_free);
74986 } else {
74987- __kmem_cache_free(b, c->size);
74988+ __kmem_cache_free(b, size);
74989 }
74990
74991+#ifdef CONFIG_PAX_USERCOPY_SLABS
74992+ trace_kfree(_RET_IP_, b);
74993+#else
74994 trace_kmem_cache_free(_RET_IP_, b);
74995+#endif
74996+
74997 }
74998 EXPORT_SYMBOL(kmem_cache_free);
74999
75000diff --git a/mm/slub.c b/mm/slub.c
75001index 2fdd96f..1e2f893 100644
75002--- a/mm/slub.c
75003+++ b/mm/slub.c
75004@@ -201,7 +201,7 @@ struct track {
75005
75006 enum track_item { TRACK_ALLOC, TRACK_FREE };
75007
75008-#ifdef CONFIG_SYSFS
75009+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75010 static int sysfs_slab_add(struct kmem_cache *);
75011 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75012 static void sysfs_slab_remove(struct kmem_cache *);
75013@@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75014 if (!t->addr)
75015 return;
75016
75017- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75018+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75019 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75020 #ifdef CONFIG_STACKTRACE
75021 {
75022@@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75023
75024 page = virt_to_head_page(x);
75025
75026+ BUG_ON(!PageSlab(page));
75027+
75028 slab_free(s, page, x, _RET_IP_);
75029
75030 trace_kmem_cache_free(_RET_IP_, x);
75031@@ -2645,7 +2647,7 @@ static int slub_min_objects;
75032 * Merge control. If this is set then no merging of slab caches will occur.
75033 * (Could be removed. This was introduced to pacify the merge skeptics.)
75034 */
75035-static int slub_nomerge;
75036+static int slub_nomerge = 1;
75037
75038 /*
75039 * Calculate the order of allocation given an slab object size.
75040@@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75041 else
75042 s->cpu_partial = 30;
75043
75044- s->refcount = 1;
75045+ atomic_set(&s->refcount, 1);
75046 #ifdef CONFIG_NUMA
75047 s->remote_node_defrag_ratio = 1000;
75048 #endif
75049@@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75050 void kmem_cache_destroy(struct kmem_cache *s)
75051 {
75052 mutex_lock(&slab_mutex);
75053- s->refcount--;
75054- if (!s->refcount) {
75055+ if (atomic_dec_and_test(&s->refcount)) {
75056 list_del(&s->list);
75057 mutex_unlock(&slab_mutex);
75058 if (kmem_cache_close(s)) {
75059@@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75060 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75061 #endif
75062
75063+#ifdef CONFIG_PAX_USERCOPY_SLABS
75064+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75065+#endif
75066+
75067 static int __init setup_slub_min_order(char *str)
75068 {
75069 get_option(&str, &slub_min_order);
75070@@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75071 return kmalloc_dma_caches[index];
75072
75073 #endif
75074+
75075+#ifdef CONFIG_PAX_USERCOPY_SLABS
75076+ if (flags & SLAB_USERCOPY)
75077+ return kmalloc_usercopy_caches[index];
75078+
75079+#endif
75080+
75081 return kmalloc_caches[index];
75082 }
75083
75084@@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75085 EXPORT_SYMBOL(__kmalloc_node);
75086 #endif
75087
75088+bool is_usercopy_object(const void *ptr)
75089+{
75090+ struct page *page;
75091+ struct kmem_cache *s;
75092+
75093+ if (ZERO_OR_NULL_PTR(ptr))
75094+ return false;
75095+
75096+ if (!slab_is_available())
75097+ return false;
75098+
75099+ if (!virt_addr_valid(ptr))
75100+ return false;
75101+
75102+ page = virt_to_head_page(ptr);
75103+
75104+ if (!PageSlab(page))
75105+ return false;
75106+
75107+ s = page->slab;
75108+ return s->flags & SLAB_USERCOPY;
75109+}
75110+
75111+#ifdef CONFIG_PAX_USERCOPY
75112+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75113+{
75114+ struct page *page;
75115+ struct kmem_cache *s;
75116+ unsigned long offset;
75117+
75118+ if (ZERO_OR_NULL_PTR(ptr))
75119+ return "<null>";
75120+
75121+ if (!virt_addr_valid(ptr))
75122+ return NULL;
75123+
75124+ page = virt_to_head_page(ptr);
75125+
75126+ if (!PageSlab(page))
75127+ return NULL;
75128+
75129+ s = page->slab;
75130+ if (!(s->flags & SLAB_USERCOPY))
75131+ return s->name;
75132+
75133+ offset = (ptr - page_address(page)) % s->size;
75134+ if (offset <= s->object_size && n <= s->object_size - offset)
75135+ return NULL;
75136+
75137+ return s->name;
75138+}
75139+#endif
75140+
75141 size_t ksize(const void *object)
75142 {
75143 struct page *page;
75144@@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75145 int node;
75146
75147 list_add(&s->list, &slab_caches);
75148- s->refcount = -1;
75149+ atomic_set(&s->refcount, -1);
75150
75151 for_each_node_state(node, N_NORMAL_MEMORY) {
75152 struct kmem_cache_node *n = get_node(s, node);
75153@@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75154
75155 /* Caches that are not of the two-to-the-power-of size */
75156 if (KMALLOC_MIN_SIZE <= 32) {
75157- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75158+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75159 caches++;
75160 }
75161
75162 if (KMALLOC_MIN_SIZE <= 64) {
75163- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75164+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75165 caches++;
75166 }
75167
75168 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75169- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75170+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75171 caches++;
75172 }
75173
75174@@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
75175 }
75176 }
75177 #endif
75178+
75179+#ifdef CONFIG_PAX_USERCOPY_SLABS
75180+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75181+ struct kmem_cache *s = kmalloc_caches[i];
75182+
75183+ if (s && s->size) {
75184+ char *name = kasprintf(GFP_NOWAIT,
75185+ "usercopy-kmalloc-%d", s->object_size);
75186+
75187+ BUG_ON(!name);
75188+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75189+ s->object_size, SLAB_USERCOPY);
75190+ }
75191+ }
75192+#endif
75193+
75194 printk(KERN_INFO
75195 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75196 " CPUs=%d, Nodes=%d\n",
75197@@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75198 /*
75199 * We may have set a slab to be unmergeable during bootstrap.
75200 */
75201- if (s->refcount < 0)
75202+ if (atomic_read(&s->refcount) < 0)
75203 return 1;
75204
75205 return 0;
75206@@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75207
75208 s = find_mergeable(size, align, flags, name, ctor);
75209 if (s) {
75210- s->refcount++;
75211+ atomic_inc(&s->refcount);
75212 /*
75213 * Adjust the object sizes so that we clear
75214 * the complete object on kzalloc.
75215@@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75216 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75217
75218 if (sysfs_slab_alias(s, name)) {
75219- s->refcount--;
75220+ atomic_dec(&s->refcount);
75221 return NULL;
75222 }
75223 return s;
75224@@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75225 }
75226 #endif
75227
75228-#ifdef CONFIG_SYSFS
75229+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75230 static int count_inuse(struct page *page)
75231 {
75232 return page->inuse;
75233@@ -4459,12 +4540,12 @@ static void resiliency_test(void)
75234 validate_slab_cache(kmalloc_caches[9]);
75235 }
75236 #else
75237-#ifdef CONFIG_SYSFS
75238+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75239 static void resiliency_test(void) {};
75240 #endif
75241 #endif
75242
75243-#ifdef CONFIG_SYSFS
75244+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75245 enum slab_stat_type {
75246 SL_ALL, /* All slabs */
75247 SL_PARTIAL, /* Only partially allocated slabs */
75248@@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
75249
75250 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75251 {
75252- return sprintf(buf, "%d\n", s->refcount - 1);
75253+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75254 }
75255 SLAB_ATTR_RO(aliases);
75256
75257@@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
75258 return name;
75259 }
75260
75261+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75262 static int sysfs_slab_add(struct kmem_cache *s)
75263 {
75264 int err;
75265@@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75266 kobject_del(&s->kobj);
75267 kobject_put(&s->kobj);
75268 }
75269+#endif
75270
75271 /*
75272 * Need to buffer aliases during bootup until sysfs becomes
75273@@ -5354,6 +5437,7 @@ struct saved_alias {
75274
75275 static struct saved_alias *alias_list;
75276
75277+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75278 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75279 {
75280 struct saved_alias *al;
75281@@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75282 alias_list = al;
75283 return 0;
75284 }
75285+#endif
75286
75287 static int __init slab_sysfs_init(void)
75288 {
75289diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75290index 1b7e22a..3fcd4f3 100644
75291--- a/mm/sparse-vmemmap.c
75292+++ b/mm/sparse-vmemmap.c
75293@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75294 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75295 if (!p)
75296 return NULL;
75297- pud_populate(&init_mm, pud, p);
75298+ pud_populate_kernel(&init_mm, pud, p);
75299 }
75300 return pud;
75301 }
75302@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75303 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75304 if (!p)
75305 return NULL;
75306- pgd_populate(&init_mm, pgd, p);
75307+ pgd_populate_kernel(&init_mm, pgd, p);
75308 }
75309 return pgd;
75310 }
75311diff --git a/mm/swap.c b/mm/swap.c
75312index 7782588..228c784 100644
75313--- a/mm/swap.c
75314+++ b/mm/swap.c
75315@@ -30,6 +30,7 @@
75316 #include <linux/backing-dev.h>
75317 #include <linux/memcontrol.h>
75318 #include <linux/gfp.h>
75319+#include <linux/hugetlb.h>
75320
75321 #include "internal.h"
75322
75323@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75324
75325 __page_cache_release(page);
75326 dtor = get_compound_page_dtor(page);
75327+ if (!PageHuge(page))
75328+ BUG_ON(dtor != free_compound_page);
75329 (*dtor)(page);
75330 }
75331
75332diff --git a/mm/swapfile.c b/mm/swapfile.c
75333index 14e254c..a6af32c 100644
75334--- a/mm/swapfile.c
75335+++ b/mm/swapfile.c
75336@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
75337
75338 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75339 /* Activity counter to indicate that a swapon or swapoff has occurred */
75340-static atomic_t proc_poll_event = ATOMIC_INIT(0);
75341+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75342
75343 static inline unsigned char swap_count(unsigned char ent)
75344 {
75345@@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75346 }
75347 filp_close(swap_file, NULL);
75348 err = 0;
75349- atomic_inc(&proc_poll_event);
75350+ atomic_inc_unchecked(&proc_poll_event);
75351 wake_up_interruptible(&proc_poll_wait);
75352
75353 out_dput:
75354@@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75355
75356 poll_wait(file, &proc_poll_wait, wait);
75357
75358- if (seq->poll_event != atomic_read(&proc_poll_event)) {
75359- seq->poll_event = atomic_read(&proc_poll_event);
75360+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75361+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75362 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75363 }
75364
75365@@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75366 return ret;
75367
75368 seq = file->private_data;
75369- seq->poll_event = atomic_read(&proc_poll_event);
75370+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75371 return 0;
75372 }
75373
75374@@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75375 (frontswap_map) ? "FS" : "");
75376
75377 mutex_unlock(&swapon_mutex);
75378- atomic_inc(&proc_poll_event);
75379+ atomic_inc_unchecked(&proc_poll_event);
75380 wake_up_interruptible(&proc_poll_wait);
75381
75382 if (S_ISREG(inode->i_mode))
75383diff --git a/mm/util.c b/mm/util.c
75384index 8c7265a..c96d884 100644
75385--- a/mm/util.c
75386+++ b/mm/util.c
75387@@ -285,6 +285,12 @@ done:
75388 void arch_pick_mmap_layout(struct mm_struct *mm)
75389 {
75390 mm->mmap_base = TASK_UNMAPPED_BASE;
75391+
75392+#ifdef CONFIG_PAX_RANDMMAP
75393+ if (mm->pax_flags & MF_PAX_RANDMMAP)
75394+ mm->mmap_base += mm->delta_mmap;
75395+#endif
75396+
75397 mm->get_unmapped_area = arch_get_unmapped_area;
75398 mm->unmap_area = arch_unmap_area;
75399 }
75400diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75401index 2bb90b1..ed47e53 100644
75402--- a/mm/vmalloc.c
75403+++ b/mm/vmalloc.c
75404@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75405
75406 pte = pte_offset_kernel(pmd, addr);
75407 do {
75408- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75409- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75410+
75411+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75412+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75413+ BUG_ON(!pte_exec(*pte));
75414+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75415+ continue;
75416+ }
75417+#endif
75418+
75419+ {
75420+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75421+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75422+ }
75423 } while (pte++, addr += PAGE_SIZE, addr != end);
75424 }
75425
75426@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75427 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75428 {
75429 pte_t *pte;
75430+ int ret = -ENOMEM;
75431
75432 /*
75433 * nr is a running index into the array which helps higher level
75434@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75435 pte = pte_alloc_kernel(pmd, addr);
75436 if (!pte)
75437 return -ENOMEM;
75438+
75439+ pax_open_kernel();
75440 do {
75441 struct page *page = pages[*nr];
75442
75443- if (WARN_ON(!pte_none(*pte)))
75444- return -EBUSY;
75445- if (WARN_ON(!page))
75446- return -ENOMEM;
75447+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75448+ if (pgprot_val(prot) & _PAGE_NX)
75449+#endif
75450+
75451+ if (WARN_ON(!pte_none(*pte))) {
75452+ ret = -EBUSY;
75453+ goto out;
75454+ }
75455+ if (WARN_ON(!page)) {
75456+ ret = -ENOMEM;
75457+ goto out;
75458+ }
75459 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75460 (*nr)++;
75461 } while (pte++, addr += PAGE_SIZE, addr != end);
75462- return 0;
75463+ ret = 0;
75464+out:
75465+ pax_close_kernel();
75466+ return ret;
75467 }
75468
75469 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75470@@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75471 pmd_t *pmd;
75472 unsigned long next;
75473
75474- pmd = pmd_alloc(&init_mm, pud, addr);
75475+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75476 if (!pmd)
75477 return -ENOMEM;
75478 do {
75479@@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75480 pud_t *pud;
75481 unsigned long next;
75482
75483- pud = pud_alloc(&init_mm, pgd, addr);
75484+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
75485 if (!pud)
75486 return -ENOMEM;
75487 do {
75488@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75489 * and fall back on vmalloc() if that fails. Others
75490 * just put it in the vmalloc space.
75491 */
75492-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75493+#ifdef CONFIG_MODULES
75494+#ifdef MODULES_VADDR
75495 unsigned long addr = (unsigned long)x;
75496 if (addr >= MODULES_VADDR && addr < MODULES_END)
75497 return 1;
75498 #endif
75499+
75500+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75501+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75502+ return 1;
75503+#endif
75504+
75505+#endif
75506+
75507 return is_vmalloc_addr(x);
75508 }
75509
75510@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75511
75512 if (!pgd_none(*pgd)) {
75513 pud_t *pud = pud_offset(pgd, addr);
75514+#ifdef CONFIG_X86
75515+ if (!pud_large(*pud))
75516+#endif
75517 if (!pud_none(*pud)) {
75518 pmd_t *pmd = pmd_offset(pud, addr);
75519+#ifdef CONFIG_X86
75520+ if (!pmd_large(*pmd))
75521+#endif
75522 if (!pmd_none(*pmd)) {
75523 pte_t *ptep, pte;
75524
75525@@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75526 * Allocate a region of KVA of the specified size and alignment, within the
75527 * vstart and vend.
75528 */
75529-static struct vmap_area *alloc_vmap_area(unsigned long size,
75530+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75531 unsigned long align,
75532 unsigned long vstart, unsigned long vend,
75533 int node, gfp_t gfp_mask)
75534@@ -1328,6 +1368,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75535 struct vm_struct *area;
75536
75537 BUG_ON(in_interrupt());
75538+
75539+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75540+ if (flags & VM_KERNEXEC) {
75541+ if (start != VMALLOC_START || end != VMALLOC_END)
75542+ return NULL;
75543+ start = (unsigned long)MODULES_EXEC_VADDR;
75544+ end = (unsigned long)MODULES_EXEC_END;
75545+ }
75546+#endif
75547+
75548 if (flags & VM_IOREMAP) {
75549 int bit = fls(size);
75550
75551@@ -1568,6 +1618,11 @@ void *vmap(struct page **pages, unsigned int count,
75552 if (count > totalram_pages)
75553 return NULL;
75554
75555+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75556+ if (!(pgprot_val(prot) & _PAGE_NX))
75557+ flags |= VM_KERNEXEC;
75558+#endif
75559+
75560 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75561 __builtin_return_address(0));
75562 if (!area)
75563@@ -1669,6 +1724,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75564 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75565 goto fail;
75566
75567+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75568+ if (!(pgprot_val(prot) & _PAGE_NX))
75569+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75570+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75571+ else
75572+#endif
75573+
75574 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75575 start, end, node, gfp_mask, caller);
75576 if (!area)
75577@@ -1842,10 +1904,9 @@ EXPORT_SYMBOL(vzalloc_node);
75578 * For tight control over page level allocator and protection flags
75579 * use __vmalloc() instead.
75580 */
75581-
75582 void *vmalloc_exec(unsigned long size)
75583 {
75584- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75585+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75586 -1, __builtin_return_address(0));
75587 }
75588
75589@@ -2136,6 +2197,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75590 unsigned long uaddr = vma->vm_start;
75591 unsigned long usize = vma->vm_end - vma->vm_start;
75592
75593+ BUG_ON(vma->vm_mirror);
75594+
75595 if ((PAGE_SIZE-1) & (unsigned long)addr)
75596 return -EINVAL;
75597
75598@@ -2572,7 +2635,7 @@ static int s_show(struct seq_file *m, void *p)
75599 {
75600 struct vm_struct *v = p;
75601
75602- seq_printf(m, "0x%p-0x%p %7ld",
75603+ seq_printf(m, "0x%pK-0x%pK %7ld",
75604 v->addr, v->addr + v->size, v->size);
75605
75606 if (v->caller)
75607diff --git a/mm/vmstat.c b/mm/vmstat.c
75608index df7a674..8b4a4f3 100644
75609--- a/mm/vmstat.c
75610+++ b/mm/vmstat.c
75611@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75612 *
75613 * vm_stat contains the global counters
75614 */
75615-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75616+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75617 EXPORT_SYMBOL(vm_stat);
75618
75619 #ifdef CONFIG_SMP
75620@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75621 v = p->vm_stat_diff[i];
75622 p->vm_stat_diff[i] = 0;
75623 local_irq_restore(flags);
75624- atomic_long_add(v, &zone->vm_stat[i]);
75625+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75626 global_diff[i] += v;
75627 #ifdef CONFIG_NUMA
75628 /* 3 seconds idle till flush */
75629@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75630
75631 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75632 if (global_diff[i])
75633- atomic_long_add(global_diff[i], &vm_stat[i]);
75634+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75635 }
75636
75637 #endif
75638@@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
75639 start_cpu_timer(cpu);
75640 #endif
75641 #ifdef CONFIG_PROC_FS
75642- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75643- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75644- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75645- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75646+ {
75647+ mode_t gr_mode = S_IRUGO;
75648+#ifdef CONFIG_GRKERNSEC_PROC_ADD
75649+ gr_mode = S_IRUSR;
75650+#endif
75651+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75652+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75653+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75654+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75655+#else
75656+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75657+#endif
75658+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75659+ }
75660 #endif
75661 return 0;
75662 }
75663diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75664index 9096bcb..43ed7bb 100644
75665--- a/net/8021q/vlan.c
75666+++ b/net/8021q/vlan.c
75667@@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75668 err = -EPERM;
75669 if (!capable(CAP_NET_ADMIN))
75670 break;
75671- if ((args.u.name_type >= 0) &&
75672- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75673+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75674 struct vlan_net *vn;
75675
75676 vn = net_generic(net, vlan_net_id);
75677diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75678index 6449bae..8c1f454 100644
75679--- a/net/9p/trans_fd.c
75680+++ b/net/9p/trans_fd.c
75681@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75682 oldfs = get_fs();
75683 set_fs(get_ds());
75684 /* The cast to a user pointer is valid due to the set_fs() */
75685- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75686+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75687 set_fs(oldfs);
75688
75689 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75690diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75691index 876fbe8..8bbea9f 100644
75692--- a/net/atm/atm_misc.c
75693+++ b/net/atm/atm_misc.c
75694@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75695 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75696 return 1;
75697 atm_return(vcc, truesize);
75698- atomic_inc(&vcc->stats->rx_drop);
75699+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75700 return 0;
75701 }
75702 EXPORT_SYMBOL(atm_charge);
75703@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75704 }
75705 }
75706 atm_return(vcc, guess);
75707- atomic_inc(&vcc->stats->rx_drop);
75708+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75709 return NULL;
75710 }
75711 EXPORT_SYMBOL(atm_alloc_charge);
75712@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75713
75714 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75715 {
75716-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75717+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75718 __SONET_ITEMS
75719 #undef __HANDLE_ITEM
75720 }
75721@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75722
75723 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75724 {
75725-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75726+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75727 __SONET_ITEMS
75728 #undef __HANDLE_ITEM
75729 }
75730diff --git a/net/atm/lec.h b/net/atm/lec.h
75731index a86aff9..3a0d6f6 100644
75732--- a/net/atm/lec.h
75733+++ b/net/atm/lec.h
75734@@ -48,7 +48,7 @@ struct lane2_ops {
75735 const u8 *tlvs, u32 sizeoftlvs);
75736 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75737 const u8 *tlvs, u32 sizeoftlvs);
75738-};
75739+} __no_const;
75740
75741 /*
75742 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75743diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75744index 0919a88..a23d54e 100644
75745--- a/net/atm/mpc.h
75746+++ b/net/atm/mpc.h
75747@@ -33,7 +33,7 @@ struct mpoa_client {
75748 struct mpc_parameters parameters; /* parameters for this client */
75749
75750 const struct net_device_ops *old_ops;
75751- struct net_device_ops new_ops;
75752+ net_device_ops_no_const new_ops;
75753 };
75754
75755
75756diff --git a/net/atm/proc.c b/net/atm/proc.c
75757index 0d020de..011c7bb 100644
75758--- a/net/atm/proc.c
75759+++ b/net/atm/proc.c
75760@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75761 const struct k_atm_aal_stats *stats)
75762 {
75763 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75764- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75765- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75766- atomic_read(&stats->rx_drop));
75767+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75768+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75769+ atomic_read_unchecked(&stats->rx_drop));
75770 }
75771
75772 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75773diff --git a/net/atm/resources.c b/net/atm/resources.c
75774index 23f45ce..c748f1a 100644
75775--- a/net/atm/resources.c
75776+++ b/net/atm/resources.c
75777@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75778 static void copy_aal_stats(struct k_atm_aal_stats *from,
75779 struct atm_aal_stats *to)
75780 {
75781-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75782+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75783 __AAL_STAT_ITEMS
75784 #undef __HANDLE_ITEM
75785 }
75786@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75787 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75788 struct atm_aal_stats *to)
75789 {
75790-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75791+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75792 __AAL_STAT_ITEMS
75793 #undef __HANDLE_ITEM
75794 }
75795diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75796index 469daab..9fc7f8d 100644
75797--- a/net/batman-adv/bat_iv_ogm.c
75798+++ b/net/batman-adv/bat_iv_ogm.c
75799@@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
75800
75801 /* randomize initial seqno to avoid collision */
75802 get_random_bytes(&random_seqno, sizeof(random_seqno));
75803- atomic_set(&hard_iface->seqno, random_seqno);
75804+ atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75805
75806 hard_iface->packet_len = BATADV_OGM_HLEN;
75807 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75808@@ -191,7 +191,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
75809 "Sending own" :
75810 "Forwarding"));
75811 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
75812- "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
75813+ "%s %spacket (originator %pM, s_uncheckedeqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
75814 fwd_str, (packet_num > 0 ? "aggregated " : ""),
75815 batadv_ogm_packet->orig,
75816 ntohl(batadv_ogm_packet->seqno),
75817@@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
75818
75819 /* change sequence number to network order */
75820 batadv_ogm_packet->seqno =
75821- htonl((uint32_t)atomic_read(&hard_iface->seqno));
75822- atomic_inc(&hard_iface->seqno);
75823+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75824+ atomic_inc_unchecked(&hard_iface->seqno);
75825
75826 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75827 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
75828@@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
75829 return;
75830
75831 /* could be changed by schedule_own_packet() */
75832- if_incoming_seqno = atomic_read(&if_incoming->seqno);
75833+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75834
75835 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
75836 has_directlink_flag = 1;
75837diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75838index 282bf6e..4b2603d 100644
75839--- a/net/batman-adv/hard-interface.c
75840+++ b/net/batman-adv/hard-interface.c
75841@@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
75842 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75843 dev_add_pack(&hard_iface->batman_adv_ptype);
75844
75845- atomic_set(&hard_iface->frag_seqno, 1);
75846+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75847 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
75848 hard_iface->net_dev->name);
75849
75850@@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
75851 /* This can't be called via a bat_priv callback because
75852 * we have no bat_priv yet.
75853 */
75854- atomic_set(&hard_iface->seqno, 1);
75855+ atomic_set_unchecked(&hard_iface->seqno, 1);
75856 hard_iface->packet_buff = NULL;
75857
75858 return hard_iface;
75859diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75860index 21c5357..768be1a 100644
75861--- a/net/batman-adv/soft-interface.c
75862+++ b/net/batman-adv/soft-interface.c
75863@@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
75864
75865 /* set broadcast sequence number */
75866 bcast_packet->seqno =
75867- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75868+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75869
75870 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
75871
75872@@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
75873 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
75874
75875 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
75876- atomic_set(&bat_priv->bcast_seqno, 1);
75877+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75878 atomic_set(&bat_priv->ttvn, 0);
75879 atomic_set(&bat_priv->tt_local_changes, 0);
75880 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75881diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75882index 12635fd..d99d837 100644
75883--- a/net/batman-adv/types.h
75884+++ b/net/batman-adv/types.h
75885@@ -33,8 +33,8 @@ struct batadv_hard_iface {
75886 int16_t if_num;
75887 char if_status;
75888 struct net_device *net_dev;
75889- atomic_t seqno;
75890- atomic_t frag_seqno;
75891+ atomic_unchecked_t seqno;
75892+ atomic_unchecked_t frag_seqno;
75893 unsigned char *packet_buff;
75894 int packet_len;
75895 struct kobject *hardif_obj;
75896@@ -176,7 +176,7 @@ struct batadv_priv {
75897 atomic_t orig_interval; /* uint */
75898 atomic_t hop_penalty; /* uint */
75899 atomic_t log_level; /* uint */
75900- atomic_t bcast_seqno;
75901+ atomic_unchecked_t bcast_seqno;
75902 atomic_t bcast_queue_left;
75903 atomic_t batman_queue_left;
75904 atomic_t ttvn; /* translation table version number */
75905diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75906index 0016464..0ef3e53 100644
75907--- a/net/batman-adv/unicast.c
75908+++ b/net/batman-adv/unicast.c
75909@@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
75910 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
75911 frag2->flags = large_tail;
75912
75913- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75914+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75915 frag1->seqno = htons(seqno - 1);
75916 frag2->seqno = htons(seqno);
75917
75918diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
75919index d5ace1e..231c4bf 100644
75920--- a/net/bluetooth/hci_sock.c
75921+++ b/net/bluetooth/hci_sock.c
75922@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
75923 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
75924 }
75925
75926- len = min_t(unsigned int, len, sizeof(uf));
75927+ len = min((size_t)len, sizeof(uf));
75928 if (copy_from_user(&uf, optval, len)) {
75929 err = -EFAULT;
75930 break;
75931diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75932index 38c00f1..e9d566e 100644
75933--- a/net/bluetooth/l2cap_core.c
75934+++ b/net/bluetooth/l2cap_core.c
75935@@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75936 break;
75937
75938 case L2CAP_CONF_RFC:
75939- if (olen == sizeof(rfc))
75940- memcpy(&rfc, (void *)val, olen);
75941+ if (olen != sizeof(rfc))
75942+ break;
75943+
75944+ memcpy(&rfc, (void *)val, olen);
75945
75946 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75947 rfc.mode != chan->mode)
75948diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
75949index 34bbe1c..451c19b 100644
75950--- a/net/bluetooth/l2cap_sock.c
75951+++ b/net/bluetooth/l2cap_sock.c
75952@@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
75953 struct sock *sk = sock->sk;
75954 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
75955 struct l2cap_options opts;
75956- int len, err = 0;
75957+ int err = 0;
75958+ size_t len = optlen;
75959 u32 opt;
75960
75961 BT_DBG("sk %p", sk);
75962@@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
75963 opts.max_tx = chan->max_tx;
75964 opts.txwin_size = chan->tx_win;
75965
75966- len = min_t(unsigned int, sizeof(opts), optlen);
75967+ len = min(sizeof(opts), len);
75968 if (copy_from_user((char *) &opts, optval, len)) {
75969 err = -EFAULT;
75970 break;
75971@@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
75972 struct bt_security sec;
75973 struct bt_power pwr;
75974 struct l2cap_conn *conn;
75975- int len, err = 0;
75976+ int err = 0;
75977+ size_t len = optlen;
75978 u32 opt;
75979
75980 BT_DBG("sk %p", sk);
75981@@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
75982
75983 sec.level = BT_SECURITY_LOW;
75984
75985- len = min_t(unsigned int, sizeof(sec), optlen);
75986+ len = min(sizeof(sec), len);
75987 if (copy_from_user((char *) &sec, optval, len)) {
75988 err = -EFAULT;
75989 break;
75990@@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
75991
75992 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
75993
75994- len = min_t(unsigned int, sizeof(pwr), optlen);
75995+ len = min(sizeof(pwr), len);
75996 if (copy_from_user((char *) &pwr, optval, len)) {
75997 err = -EFAULT;
75998 break;
75999diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76000index 1a17850..65a3129 100644
76001--- a/net/bluetooth/rfcomm/sock.c
76002+++ b/net/bluetooth/rfcomm/sock.c
76003@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76004 struct sock *sk = sock->sk;
76005 struct bt_security sec;
76006 int err = 0;
76007- size_t len;
76008+ size_t len = optlen;
76009 u32 opt;
76010
76011 BT_DBG("sk %p", sk);
76012@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76013
76014 sec.level = BT_SECURITY_LOW;
76015
76016- len = min_t(unsigned int, sizeof(sec), optlen);
76017+ len = min(sizeof(sec), len);
76018 if (copy_from_user((char *) &sec, optval, len)) {
76019 err = -EFAULT;
76020 break;
76021diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76022index 56f1823..da44330 100644
76023--- a/net/bluetooth/rfcomm/tty.c
76024+++ b/net/bluetooth/rfcomm/tty.c
76025@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76026 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76027
76028 spin_lock_irqsave(&dev->port.lock, flags);
76029- if (dev->port.count > 0) {
76030+ if (atomic_read(&dev->port.count) > 0) {
76031 spin_unlock_irqrestore(&dev->port.lock, flags);
76032 return;
76033 }
76034@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76035 return -ENODEV;
76036
76037 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76038- dev->channel, dev->port.count);
76039+ dev->channel, atomic_read(&dev->port.count));
76040
76041 spin_lock_irqsave(&dev->port.lock, flags);
76042- if (++dev->port.count > 1) {
76043+ if (atomic_inc_return(&dev->port.count) > 1) {
76044 spin_unlock_irqrestore(&dev->port.lock, flags);
76045 return 0;
76046 }
76047@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76048 return;
76049
76050 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76051- dev->port.count);
76052+ atomic_read(&dev->port.count));
76053
76054 spin_lock_irqsave(&dev->port.lock, flags);
76055- if (!--dev->port.count) {
76056+ if (!atomic_dec_return(&dev->port.count)) {
76057 spin_unlock_irqrestore(&dev->port.lock, flags);
76058 if (dev->tty_dev->parent)
76059 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76060diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76061index 5fe2ff3..121d696 100644
76062--- a/net/bridge/netfilter/ebtables.c
76063+++ b/net/bridge/netfilter/ebtables.c
76064@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76065 tmp.valid_hooks = t->table->valid_hooks;
76066 }
76067 mutex_unlock(&ebt_mutex);
76068- if (copy_to_user(user, &tmp, *len) != 0){
76069+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76070 BUGPRINT("c2u Didn't work\n");
76071 ret = -EFAULT;
76072 break;
76073@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76074 goto out;
76075 tmp.valid_hooks = t->valid_hooks;
76076
76077- if (copy_to_user(user, &tmp, *len) != 0) {
76078+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76079 ret = -EFAULT;
76080 break;
76081 }
76082@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76083 tmp.entries_size = t->table->entries_size;
76084 tmp.valid_hooks = t->table->valid_hooks;
76085
76086- if (copy_to_user(user, &tmp, *len) != 0) {
76087+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76088 ret = -EFAULT;
76089 break;
76090 }
76091diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76092index 44f270f..1f5602d 100644
76093--- a/net/caif/cfctrl.c
76094+++ b/net/caif/cfctrl.c
76095@@ -10,6 +10,7 @@
76096 #include <linux/spinlock.h>
76097 #include <linux/slab.h>
76098 #include <linux/pkt_sched.h>
76099+#include <linux/sched.h>
76100 #include <net/caif/caif_layer.h>
76101 #include <net/caif/cfpkt.h>
76102 #include <net/caif/cfctrl.h>
76103@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76104 memset(&dev_info, 0, sizeof(dev_info));
76105 dev_info.id = 0xff;
76106 cfsrvl_init(&this->serv, 0, &dev_info, false);
76107- atomic_set(&this->req_seq_no, 1);
76108- atomic_set(&this->rsp_seq_no, 1);
76109+ atomic_set_unchecked(&this->req_seq_no, 1);
76110+ atomic_set_unchecked(&this->rsp_seq_no, 1);
76111 this->serv.layer.receive = cfctrl_recv;
76112 sprintf(this->serv.layer.name, "ctrl");
76113 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76114@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76115 struct cfctrl_request_info *req)
76116 {
76117 spin_lock_bh(&ctrl->info_list_lock);
76118- atomic_inc(&ctrl->req_seq_no);
76119- req->sequence_no = atomic_read(&ctrl->req_seq_no);
76120+ atomic_inc_unchecked(&ctrl->req_seq_no);
76121+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76122 list_add_tail(&req->list, &ctrl->list);
76123 spin_unlock_bh(&ctrl->info_list_lock);
76124 }
76125@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76126 if (p != first)
76127 pr_warn("Requests are not received in order\n");
76128
76129- atomic_set(&ctrl->rsp_seq_no,
76130+ atomic_set_unchecked(&ctrl->rsp_seq_no,
76131 p->sequence_no);
76132 list_del(&p->list);
76133 goto out;
76134diff --git a/net/can/gw.c b/net/can/gw.c
76135index b54d5e6..91c3b25 100644
76136--- a/net/can/gw.c
76137+++ b/net/can/gw.c
76138@@ -96,7 +96,7 @@ struct cf_mod {
76139 struct {
76140 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76141 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76142- } csumfunc;
76143+ } __no_const csumfunc;
76144 };
76145
76146
76147diff --git a/net/compat.c b/net/compat.c
76148index 74ed1d7..3695bd9 100644
76149--- a/net/compat.c
76150+++ b/net/compat.c
76151@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76152 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76153 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76154 return -EFAULT;
76155- kmsg->msg_name = compat_ptr(tmp1);
76156- kmsg->msg_iov = compat_ptr(tmp2);
76157- kmsg->msg_control = compat_ptr(tmp3);
76158+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76159+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76160+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76161 return 0;
76162 }
76163
76164@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76165
76166 if (kern_msg->msg_namelen) {
76167 if (mode == VERIFY_READ) {
76168- int err = move_addr_to_kernel(kern_msg->msg_name,
76169+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76170 kern_msg->msg_namelen,
76171 kern_address);
76172 if (err < 0)
76173@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76174 kern_msg->msg_name = NULL;
76175
76176 tot_len = iov_from_user_compat_to_kern(kern_iov,
76177- (struct compat_iovec __user *)kern_msg->msg_iov,
76178+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
76179 kern_msg->msg_iovlen);
76180 if (tot_len >= 0)
76181 kern_msg->msg_iov = kern_iov;
76182@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76183
76184 #define CMSG_COMPAT_FIRSTHDR(msg) \
76185 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76186- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76187+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76188 (struct compat_cmsghdr __user *)NULL)
76189
76190 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76191 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76192 (ucmlen) <= (unsigned long) \
76193 ((mhdr)->msg_controllen - \
76194- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76195+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76196
76197 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76198 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76199 {
76200 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76201- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76202+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76203 msg->msg_controllen)
76204 return NULL;
76205 return (struct compat_cmsghdr __user *)ptr;
76206@@ -219,7 +219,7 @@ Efault:
76207
76208 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76209 {
76210- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76211+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76212 struct compat_cmsghdr cmhdr;
76213 struct compat_timeval ctv;
76214 struct compat_timespec cts[3];
76215@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76216
76217 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76218 {
76219- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76220+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76221 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76222 int fdnum = scm->fp->count;
76223 struct file **fp = scm->fp->fp;
76224@@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76225 return -EFAULT;
76226 old_fs = get_fs();
76227 set_fs(KERNEL_DS);
76228- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76229+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76230 set_fs(old_fs);
76231
76232 return err;
76233@@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76234 len = sizeof(ktime);
76235 old_fs = get_fs();
76236 set_fs(KERNEL_DS);
76237- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76238+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76239 set_fs(old_fs);
76240
76241 if (!err) {
76242@@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76243 case MCAST_JOIN_GROUP:
76244 case MCAST_LEAVE_GROUP:
76245 {
76246- struct compat_group_req __user *gr32 = (void *)optval;
76247+ struct compat_group_req __user *gr32 = (void __user *)optval;
76248 struct group_req __user *kgr =
76249 compat_alloc_user_space(sizeof(struct group_req));
76250 u32 interface;
76251@@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76252 case MCAST_BLOCK_SOURCE:
76253 case MCAST_UNBLOCK_SOURCE:
76254 {
76255- struct compat_group_source_req __user *gsr32 = (void *)optval;
76256+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76257 struct group_source_req __user *kgsr = compat_alloc_user_space(
76258 sizeof(struct group_source_req));
76259 u32 interface;
76260@@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76261 }
76262 case MCAST_MSFILTER:
76263 {
76264- struct compat_group_filter __user *gf32 = (void *)optval;
76265+ struct compat_group_filter __user *gf32 = (void __user *)optval;
76266 struct group_filter __user *kgf;
76267 u32 interface, fmode, numsrc;
76268
76269@@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76270 char __user *optval, int __user *optlen,
76271 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76272 {
76273- struct compat_group_filter __user *gf32 = (void *)optval;
76274+ struct compat_group_filter __user *gf32 = (void __user *)optval;
76275 struct group_filter __user *kgf;
76276 int __user *koptlen;
76277 u32 interface, fmode, numsrc;
76278@@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76279
76280 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76281 return -EINVAL;
76282- if (copy_from_user(a, args, nas[call]))
76283+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76284 return -EFAULT;
76285 a0 = a[0];
76286 a1 = a[1];
76287diff --git a/net/core/datagram.c b/net/core/datagram.c
76288index 0337e2b..47914a0 100644
76289--- a/net/core/datagram.c
76290+++ b/net/core/datagram.c
76291@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76292 }
76293
76294 kfree_skb(skb);
76295- atomic_inc(&sk->sk_drops);
76296+ atomic_inc_unchecked(&sk->sk_drops);
76297 sk_mem_reclaim_partial(sk);
76298
76299 return err;
76300diff --git a/net/core/dev.c b/net/core/dev.c
76301index 89e33a5..16d9d25 100644
76302--- a/net/core/dev.c
76303+++ b/net/core/dev.c
76304@@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
76305 if (no_module && capable(CAP_NET_ADMIN))
76306 no_module = request_module("netdev-%s", name);
76307 if (no_module && capable(CAP_SYS_MODULE)) {
76308+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76309+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
76310+#else
76311 if (!request_module("%s", name))
76312 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76313 name);
76314+#endif
76315 }
76316 }
76317 EXPORT_SYMBOL(dev_load);
76318@@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76319 {
76320 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76321 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76322- atomic_long_inc(&dev->rx_dropped);
76323+ atomic_long_inc_unchecked(&dev->rx_dropped);
76324 kfree_skb(skb);
76325 return NET_RX_DROP;
76326 }
76327@@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76328 nf_reset(skb);
76329
76330 if (unlikely(!is_skb_forwardable(dev, skb))) {
76331- atomic_long_inc(&dev->rx_dropped);
76332+ atomic_long_inc_unchecked(&dev->rx_dropped);
76333 kfree_skb(skb);
76334 return NET_RX_DROP;
76335 }
76336@@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76337
76338 struct dev_gso_cb {
76339 void (*destructor)(struct sk_buff *skb);
76340-};
76341+} __no_const;
76342
76343 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76344
76345@@ -2928,7 +2932,7 @@ enqueue:
76346
76347 local_irq_restore(flags);
76348
76349- atomic_long_inc(&skb->dev->rx_dropped);
76350+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76351 kfree_skb(skb);
76352 return NET_RX_DROP;
76353 }
76354@@ -3000,7 +3004,7 @@ int netif_rx_ni(struct sk_buff *skb)
76355 }
76356 EXPORT_SYMBOL(netif_rx_ni);
76357
76358-static void net_tx_action(struct softirq_action *h)
76359+static void net_tx_action(void)
76360 {
76361 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76362
76363@@ -3328,7 +3332,7 @@ ncls:
76364 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76365 } else {
76366 drop:
76367- atomic_long_inc(&skb->dev->rx_dropped);
76368+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76369 kfree_skb(skb);
76370 /* Jamal, now you will not able to escape explaining
76371 * me how you were going to use this. :-)
76372@@ -3895,7 +3899,7 @@ void netif_napi_del(struct napi_struct *napi)
76373 }
76374 EXPORT_SYMBOL(netif_napi_del);
76375
76376-static void net_rx_action(struct softirq_action *h)
76377+static void net_rx_action(void)
76378 {
76379 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76380 unsigned long time_limit = jiffies + 2;
76381@@ -4365,8 +4369,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76382 else
76383 seq_printf(seq, "%04x", ntohs(pt->type));
76384
76385+#ifdef CONFIG_GRKERNSEC_HIDESYM
76386+ seq_printf(seq, " %-8s %p\n",
76387+ pt->dev ? pt->dev->name : "", NULL);
76388+#else
76389 seq_printf(seq, " %-8s %pF\n",
76390 pt->dev ? pt->dev->name : "", pt->func);
76391+#endif
76392 }
76393
76394 return 0;
76395@@ -5919,7 +5928,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76396 } else {
76397 netdev_stats_to_stats64(storage, &dev->stats);
76398 }
76399- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76400+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76401 return storage;
76402 }
76403 EXPORT_SYMBOL(dev_get_stats);
76404diff --git a/net/core/flow.c b/net/core/flow.c
76405index e318c7e..168b1d0 100644
76406--- a/net/core/flow.c
76407+++ b/net/core/flow.c
76408@@ -61,7 +61,7 @@ struct flow_cache {
76409 struct timer_list rnd_timer;
76410 };
76411
76412-atomic_t flow_cache_genid = ATOMIC_INIT(0);
76413+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76414 EXPORT_SYMBOL(flow_cache_genid);
76415 static struct flow_cache flow_cache_global;
76416 static struct kmem_cache *flow_cachep __read_mostly;
76417@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76418
76419 static int flow_entry_valid(struct flow_cache_entry *fle)
76420 {
76421- if (atomic_read(&flow_cache_genid) != fle->genid)
76422+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76423 return 0;
76424 if (fle->object && !fle->object->ops->check(fle->object))
76425 return 0;
76426@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76427 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76428 fcp->hash_count++;
76429 }
76430- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76431+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76432 flo = fle->object;
76433 if (!flo)
76434 goto ret_object;
76435@@ -280,7 +280,7 @@ nocache:
76436 }
76437 flo = resolver(net, key, family, dir, flo, ctx);
76438 if (fle) {
76439- fle->genid = atomic_read(&flow_cache_genid);
76440+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
76441 if (!IS_ERR(flo))
76442 fle->object = flo;
76443 else
76444diff --git a/net/core/iovec.c b/net/core/iovec.c
76445index 7e7aeb0..2a998cb 100644
76446--- a/net/core/iovec.c
76447+++ b/net/core/iovec.c
76448@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76449 if (m->msg_namelen) {
76450 if (mode == VERIFY_READ) {
76451 void __user *namep;
76452- namep = (void __user __force *) m->msg_name;
76453+ namep = (void __force_user *) m->msg_name;
76454 err = move_addr_to_kernel(namep, m->msg_namelen,
76455 address);
76456 if (err < 0)
76457@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76458 }
76459
76460 size = m->msg_iovlen * sizeof(struct iovec);
76461- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76462+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76463 return -EFAULT;
76464
76465 m->msg_iov = iov;
76466diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76467index 2c5a0a0..a45f90c 100644
76468--- a/net/core/rtnetlink.c
76469+++ b/net/core/rtnetlink.c
76470@@ -58,7 +58,7 @@ struct rtnl_link {
76471 rtnl_doit_func doit;
76472 rtnl_dumpit_func dumpit;
76473 rtnl_calcit_func calcit;
76474-};
76475+} __no_const;
76476
76477 static DEFINE_MUTEX(rtnl_mutex);
76478
76479diff --git a/net/core/scm.c b/net/core/scm.c
76480index 040cebe..5b1e312 100644
76481--- a/net/core/scm.c
76482+++ b/net/core/scm.c
76483@@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
76484 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76485 {
76486 struct cmsghdr __user *cm
76487- = (__force struct cmsghdr __user *)msg->msg_control;
76488+ = (struct cmsghdr __force_user *)msg->msg_control;
76489 struct cmsghdr cmhdr;
76490 int cmlen = CMSG_LEN(len);
76491 int err;
76492@@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76493 err = -EFAULT;
76494 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76495 goto out;
76496- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76497+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76498 goto out;
76499 cmlen = CMSG_SPACE(len);
76500 if (msg->msg_controllen < cmlen)
76501@@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
76502 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76503 {
76504 struct cmsghdr __user *cm
76505- = (__force struct cmsghdr __user*)msg->msg_control;
76506+ = (struct cmsghdr __force_user *)msg->msg_control;
76507
76508 int fdmax = 0;
76509 int fdnum = scm->fp->count;
76510@@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76511 if (fdnum < fdmax)
76512 fdmax = fdnum;
76513
76514- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76515+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76516 i++, cmfptr++)
76517 {
76518 struct socket *sock;
76519diff --git a/net/core/sock.c b/net/core/sock.c
76520index a6000fb..d4aee72 100644
76521--- a/net/core/sock.c
76522+++ b/net/core/sock.c
76523@@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76524 struct sk_buff_head *list = &sk->sk_receive_queue;
76525
76526 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76527- atomic_inc(&sk->sk_drops);
76528+ atomic_inc_unchecked(&sk->sk_drops);
76529 trace_sock_rcvqueue_full(sk, skb);
76530 return -ENOMEM;
76531 }
76532@@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76533 return err;
76534
76535 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
76536- atomic_inc(&sk->sk_drops);
76537+ atomic_inc_unchecked(&sk->sk_drops);
76538 return -ENOBUFS;
76539 }
76540
76541@@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76542 skb_dst_force(skb);
76543
76544 spin_lock_irqsave(&list->lock, flags);
76545- skb->dropcount = atomic_read(&sk->sk_drops);
76546+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76547 __skb_queue_tail(list, skb);
76548 spin_unlock_irqrestore(&list->lock, flags);
76549
76550@@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76551 skb->dev = NULL;
76552
76553 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76554- atomic_inc(&sk->sk_drops);
76555+ atomic_inc_unchecked(&sk->sk_drops);
76556 goto discard_and_relse;
76557 }
76558 if (nested)
76559@@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76560 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76561 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76562 bh_unlock_sock(sk);
76563- atomic_inc(&sk->sk_drops);
76564+ atomic_inc_unchecked(&sk->sk_drops);
76565 goto discard_and_relse;
76566 }
76567
76568@@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76569 struct timeval tm;
76570 } v;
76571
76572- int lv = sizeof(int);
76573- int len;
76574+ unsigned int lv = sizeof(int);
76575+ unsigned int len;
76576
76577 if (get_user(len, optlen))
76578 return -EFAULT;
76579- if (len < 0)
76580+ if (len > INT_MAX)
76581 return -EINVAL;
76582
76583 memset(&v, 0, sizeof(v));
76584@@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76585
76586 case SO_PEERNAME:
76587 {
76588- char address[128];
76589+ char address[_K_SS_MAXSIZE];
76590
76591 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
76592 return -ENOTCONN;
76593- if (lv < len)
76594+ if (lv < len || sizeof address < len)
76595 return -EINVAL;
76596 if (copy_to_user(optval, address, len))
76597 return -EFAULT;
76598@@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76599
76600 if (len > lv)
76601 len = lv;
76602- if (copy_to_user(optval, &v, len))
76603+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
76604 return -EFAULT;
76605 lenout:
76606 if (put_user(len, optlen))
76607@@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76608 */
76609 smp_wmb();
76610 atomic_set(&sk->sk_refcnt, 1);
76611- atomic_set(&sk->sk_drops, 0);
76612+ atomic_set_unchecked(&sk->sk_drops, 0);
76613 }
76614 EXPORT_SYMBOL(sock_init_data);
76615
76616diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76617index 9d8755e..26de8bc 100644
76618--- a/net/core/sock_diag.c
76619+++ b/net/core/sock_diag.c
76620@@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76621
76622 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76623 {
76624+#ifndef CONFIG_GRKERNSEC_HIDESYM
76625 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76626 cookie[1] != INET_DIAG_NOCOOKIE) &&
76627 ((u32)(unsigned long)sk != cookie[0] ||
76628 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76629 return -ESTALE;
76630 else
76631+#endif
76632 return 0;
76633 }
76634 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76635
76636 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76637 {
76638+#ifdef CONFIG_GRKERNSEC_HIDESYM
76639+ cookie[0] = 0;
76640+ cookie[1] = 0;
76641+#else
76642 cookie[0] = (u32)(unsigned long)sk;
76643 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76644+#endif
76645 }
76646 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76647
76648diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76649index a55eecc..dd8428c 100644
76650--- a/net/decnet/sysctl_net_decnet.c
76651+++ b/net/decnet/sysctl_net_decnet.c
76652@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76653
76654 if (len > *lenp) len = *lenp;
76655
76656- if (copy_to_user(buffer, addr, len))
76657+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
76658 return -EFAULT;
76659
76660 *lenp = len;
76661@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76662
76663 if (len > *lenp) len = *lenp;
76664
76665- if (copy_to_user(buffer, devname, len))
76666+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
76667 return -EFAULT;
76668
76669 *lenp = len;
76670diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76671index 8e2b475..7263d89 100644
76672--- a/net/ipv4/fib_frontend.c
76673+++ b/net/ipv4/fib_frontend.c
76674@@ -1019,12 +1019,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76675 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76676 fib_sync_up(dev);
76677 #endif
76678- atomic_inc(&net->ipv4.dev_addr_genid);
76679+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76680 rt_cache_flush(dev_net(dev));
76681 break;
76682 case NETDEV_DOWN:
76683 fib_del_ifaddr(ifa, NULL);
76684- atomic_inc(&net->ipv4.dev_addr_genid);
76685+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76686 if (ifa->ifa_dev->ifa_list == NULL) {
76687 /* Last address was deleted from this interface.
76688 * Disable IP.
76689@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76690 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76691 fib_sync_up(dev);
76692 #endif
76693- atomic_inc(&net->ipv4.dev_addr_genid);
76694+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76695 rt_cache_flush(dev_net(dev));
76696 break;
76697 case NETDEV_DOWN:
76698diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76699index da80dc1..f2511b9 100644
76700--- a/net/ipv4/fib_semantics.c
76701+++ b/net/ipv4/fib_semantics.c
76702@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76703 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76704 nh->nh_gw,
76705 nh->nh_parent->fib_scope);
76706- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76707+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76708
76709 return nh->nh_saddr;
76710 }
76711diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76712index 7880af9..70f92a3 100644
76713--- a/net/ipv4/inet_hashtables.c
76714+++ b/net/ipv4/inet_hashtables.c
76715@@ -18,12 +18,15 @@
76716 #include <linux/sched.h>
76717 #include <linux/slab.h>
76718 #include <linux/wait.h>
76719+#include <linux/security.h>
76720
76721 #include <net/inet_connection_sock.h>
76722 #include <net/inet_hashtables.h>
76723 #include <net/secure_seq.h>
76724 #include <net/ip.h>
76725
76726+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76727+
76728 /*
76729 * Allocate and initialize a new local port bind bucket.
76730 * The bindhash mutex for snum's hash chain must be held here.
76731@@ -530,6 +533,8 @@ ok:
76732 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76733 spin_unlock(&head->lock);
76734
76735+ gr_update_task_in_ip_table(current, inet_sk(sk));
76736+
76737 if (tw) {
76738 inet_twsk_deschedule(tw, death_row);
76739 while (twrefcnt) {
76740diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76741index c7527f6..d8bba61 100644
76742--- a/net/ipv4/inetpeer.c
76743+++ b/net/ipv4/inetpeer.c
76744@@ -503,8 +503,8 @@ relookup:
76745 if (p) {
76746 p->daddr = *daddr;
76747 atomic_set(&p->refcnt, 1);
76748- atomic_set(&p->rid, 0);
76749- atomic_set(&p->ip_id_count,
76750+ atomic_set_unchecked(&p->rid, 0);
76751+ atomic_set_unchecked(&p->ip_id_count,
76752 (daddr->family == AF_INET) ?
76753 secure_ip_id(daddr->addr.a4) :
76754 secure_ipv6_id(daddr->addr.a6));
76755diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76756index 8d07c97..d0812ef 100644
76757--- a/net/ipv4/ip_fragment.c
76758+++ b/net/ipv4/ip_fragment.c
76759@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76760 return 0;
76761
76762 start = qp->rid;
76763- end = atomic_inc_return(&peer->rid);
76764+ end = atomic_inc_return_unchecked(&peer->rid);
76765 qp->rid = end;
76766
76767 rc = qp->q.fragments && (end - start) > max;
76768diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76769index 5eea4a8..49819c2 100644
76770--- a/net/ipv4/ip_sockglue.c
76771+++ b/net/ipv4/ip_sockglue.c
76772@@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76773 len = min_t(unsigned int, len, opt->optlen);
76774 if (put_user(len, optlen))
76775 return -EFAULT;
76776- if (copy_to_user(optval, opt->__data, len))
76777+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76778+ copy_to_user(optval, opt->__data, len))
76779 return -EFAULT;
76780 return 0;
76781 }
76782@@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76783 if (sk->sk_type != SOCK_STREAM)
76784 return -ENOPROTOOPT;
76785
76786- msg.msg_control = optval;
76787+ msg.msg_control = (void __force_kernel *)optval;
76788 msg.msg_controllen = len;
76789 msg.msg_flags = flags;
76790
76791diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76792index 67e8a6b..386764d 100644
76793--- a/net/ipv4/ipconfig.c
76794+++ b/net/ipv4/ipconfig.c
76795@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76796
76797 mm_segment_t oldfs = get_fs();
76798 set_fs(get_ds());
76799- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76800+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76801 set_fs(oldfs);
76802 return res;
76803 }
76804@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76805
76806 mm_segment_t oldfs = get_fs();
76807 set_fs(get_ds());
76808- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76809+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76810 set_fs(oldfs);
76811 return res;
76812 }
76813@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76814
76815 mm_segment_t oldfs = get_fs();
76816 set_fs(get_ds());
76817- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76818+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76819 set_fs(oldfs);
76820 return res;
76821 }
76822diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
76823index 97e61ea..cac1bbb 100644
76824--- a/net/ipv4/netfilter/arp_tables.c
76825+++ b/net/ipv4/netfilter/arp_tables.c
76826@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
76827 #endif
76828
76829 static int get_info(struct net *net, void __user *user,
76830- const int *len, int compat)
76831+ int len, int compat)
76832 {
76833 char name[XT_TABLE_MAXNAMELEN];
76834 struct xt_table *t;
76835 int ret;
76836
76837- if (*len != sizeof(struct arpt_getinfo)) {
76838- duprintf("length %u != %Zu\n", *len,
76839+ if (len != sizeof(struct arpt_getinfo)) {
76840+ duprintf("length %u != %Zu\n", len,
76841 sizeof(struct arpt_getinfo));
76842 return -EINVAL;
76843 }
76844@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
76845 info.size = private->size;
76846 strcpy(info.name, name);
76847
76848- if (copy_to_user(user, &info, *len) != 0)
76849+ if (copy_to_user(user, &info, len) != 0)
76850 ret = -EFAULT;
76851 else
76852 ret = 0;
76853@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
76854
76855 switch (cmd) {
76856 case ARPT_SO_GET_INFO:
76857- ret = get_info(sock_net(sk), user, len, 1);
76858+ ret = get_info(sock_net(sk), user, *len, 1);
76859 break;
76860 case ARPT_SO_GET_ENTRIES:
76861 ret = compat_get_entries(sock_net(sk), user, len);
76862@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
76863
76864 switch (cmd) {
76865 case ARPT_SO_GET_INFO:
76866- ret = get_info(sock_net(sk), user, len, 0);
76867+ ret = get_info(sock_net(sk), user, *len, 0);
76868 break;
76869
76870 case ARPT_SO_GET_ENTRIES:
76871diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
76872index 170b1fd..6105b91 100644
76873--- a/net/ipv4/netfilter/ip_tables.c
76874+++ b/net/ipv4/netfilter/ip_tables.c
76875@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
76876 #endif
76877
76878 static int get_info(struct net *net, void __user *user,
76879- const int *len, int compat)
76880+ int len, int compat)
76881 {
76882 char name[XT_TABLE_MAXNAMELEN];
76883 struct xt_table *t;
76884 int ret;
76885
76886- if (*len != sizeof(struct ipt_getinfo)) {
76887- duprintf("length %u != %zu\n", *len,
76888+ if (len != sizeof(struct ipt_getinfo)) {
76889+ duprintf("length %u != %zu\n", len,
76890 sizeof(struct ipt_getinfo));
76891 return -EINVAL;
76892 }
76893@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
76894 info.size = private->size;
76895 strcpy(info.name, name);
76896
76897- if (copy_to_user(user, &info, *len) != 0)
76898+ if (copy_to_user(user, &info, len) != 0)
76899 ret = -EFAULT;
76900 else
76901 ret = 0;
76902@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76903
76904 switch (cmd) {
76905 case IPT_SO_GET_INFO:
76906- ret = get_info(sock_net(sk), user, len, 1);
76907+ ret = get_info(sock_net(sk), user, *len, 1);
76908 break;
76909 case IPT_SO_GET_ENTRIES:
76910 ret = compat_get_entries(sock_net(sk), user, len);
76911@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76912
76913 switch (cmd) {
76914 case IPT_SO_GET_INFO:
76915- ret = get_info(sock_net(sk), user, len, 0);
76916+ ret = get_info(sock_net(sk), user, *len, 0);
76917 break;
76918
76919 case IPT_SO_GET_ENTRIES:
76920diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76921index 6232d47..6b88607 100644
76922--- a/net/ipv4/ping.c
76923+++ b/net/ipv4/ping.c
76924@@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
76925 sk_rmem_alloc_get(sp),
76926 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76927 atomic_read(&sp->sk_refcnt), sp,
76928- atomic_read(&sp->sk_drops), len);
76929+ atomic_read_unchecked(&sp->sk_drops), len);
76930 }
76931
76932 static int ping_seq_show(struct seq_file *seq, void *v)
76933diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
76934index d23c657..cb69cc2 100644
76935--- a/net/ipv4/raw.c
76936+++ b/net/ipv4/raw.c
76937@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
76938 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76939 {
76940 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76941- atomic_inc(&sk->sk_drops);
76942+ atomic_inc_unchecked(&sk->sk_drops);
76943 kfree_skb(skb);
76944 return NET_RX_DROP;
76945 }
76946@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
76947
76948 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76949 {
76950+ struct icmp_filter filter;
76951+
76952 if (optlen > sizeof(struct icmp_filter))
76953 optlen = sizeof(struct icmp_filter);
76954- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76955+ if (copy_from_user(&filter, optval, optlen))
76956 return -EFAULT;
76957+ raw_sk(sk)->filter = filter;
76958 return 0;
76959 }
76960
76961 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76962 {
76963 int len, ret = -EFAULT;
76964+ struct icmp_filter filter;
76965
76966 if (get_user(len, optlen))
76967 goto out;
76968@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
76969 if (len > sizeof(struct icmp_filter))
76970 len = sizeof(struct icmp_filter);
76971 ret = -EFAULT;
76972- if (put_user(len, optlen) ||
76973- copy_to_user(optval, &raw_sk(sk)->filter, len))
76974+ filter = raw_sk(sk)->filter;
76975+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76976 goto out;
76977 ret = 0;
76978 out: return ret;
76979@@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76980 sk_wmem_alloc_get(sp),
76981 sk_rmem_alloc_get(sp),
76982 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76983- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76984+ atomic_read(&sp->sk_refcnt),
76985+#ifdef CONFIG_GRKERNSEC_HIDESYM
76986+ NULL,
76987+#else
76988+ sp,
76989+#endif
76990+ atomic_read_unchecked(&sp->sk_drops));
76991 }
76992
76993 static int raw_seq_show(struct seq_file *seq, void *v)
76994diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76995index fd9af60..dca4e54 100644
76996--- a/net/ipv4/route.c
76997+++ b/net/ipv4/route.c
76998@@ -2501,7 +2501,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
76999
77000 static __net_init int rt_genid_init(struct net *net)
77001 {
77002- atomic_set(&net->rt_genid, 0);
77003+ atomic_set_unchecked(&net->rt_genid, 0);
77004 get_random_bytes(&net->ipv4.dev_addr_genid,
77005 sizeof(net->ipv4.dev_addr_genid));
77006 return 0;
77007diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77008index d377f48..c2211ed 100644
77009--- a/net/ipv4/tcp_input.c
77010+++ b/net/ipv4/tcp_input.c
77011@@ -4728,7 +4728,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77012 * simplifies code)
77013 */
77014 static void
77015-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77016+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77017 struct sk_buff *head, struct sk_buff *tail,
77018 u32 start, u32 end)
77019 {
77020diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77021index 00a748d..e6d546b 100644
77022--- a/net/ipv4/tcp_ipv4.c
77023+++ b/net/ipv4/tcp_ipv4.c
77024@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77025 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77026
77027
77028+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77029+extern int grsec_enable_blackhole;
77030+#endif
77031+
77032 #ifdef CONFIG_TCP_MD5SIG
77033 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77034 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77035@@ -1663,6 +1667,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77036 return 0;
77037
77038 reset:
77039+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77040+ if (!grsec_enable_blackhole)
77041+#endif
77042 tcp_v4_send_reset(rsk, skb);
77043 discard:
77044 kfree_skb(skb);
77045@@ -1763,12 +1770,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77046 TCP_SKB_CB(skb)->sacked = 0;
77047
77048 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77049- if (!sk)
77050+ if (!sk) {
77051+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77052+ ret = 1;
77053+#endif
77054 goto no_tcp_socket;
77055-
77056+ }
77057 process:
77058- if (sk->sk_state == TCP_TIME_WAIT)
77059+ if (sk->sk_state == TCP_TIME_WAIT) {
77060+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77061+ ret = 2;
77062+#endif
77063 goto do_time_wait;
77064+ }
77065
77066 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77067 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77068@@ -1819,6 +1833,10 @@ no_tcp_socket:
77069 bad_packet:
77070 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77071 } else {
77072+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77073+ if (!grsec_enable_blackhole || (ret == 1 &&
77074+ (skb->dev->flags & IFF_LOOPBACK)))
77075+#endif
77076 tcp_v4_send_reset(NULL, skb);
77077 }
77078
77079@@ -2414,7 +2432,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77080 0, /* non standard timer */
77081 0, /* open_requests have no inode */
77082 atomic_read(&sk->sk_refcnt),
77083+#ifdef CONFIG_GRKERNSEC_HIDESYM
77084+ NULL,
77085+#else
77086 req,
77087+#endif
77088 len);
77089 }
77090
77091@@ -2464,7 +2486,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77092 sock_i_uid(sk),
77093 icsk->icsk_probes_out,
77094 sock_i_ino(sk),
77095- atomic_read(&sk->sk_refcnt), sk,
77096+ atomic_read(&sk->sk_refcnt),
77097+#ifdef CONFIG_GRKERNSEC_HIDESYM
77098+ NULL,
77099+#else
77100+ sk,
77101+#endif
77102 jiffies_to_clock_t(icsk->icsk_rto),
77103 jiffies_to_clock_t(icsk->icsk_ack.ato),
77104 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77105@@ -2492,7 +2519,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77106 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77107 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77108 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77109- atomic_read(&tw->tw_refcnt), tw, len);
77110+ atomic_read(&tw->tw_refcnt),
77111+#ifdef CONFIG_GRKERNSEC_HIDESYM
77112+ NULL,
77113+#else
77114+ tw,
77115+#endif
77116+ len);
77117 }
77118
77119 #define TMPSZ 150
77120diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77121index 6ff7f10..38de56e 100644
77122--- a/net/ipv4/tcp_minisocks.c
77123+++ b/net/ipv4/tcp_minisocks.c
77124@@ -27,6 +27,10 @@
77125 #include <net/inet_common.h>
77126 #include <net/xfrm.h>
77127
77128+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77129+extern int grsec_enable_blackhole;
77130+#endif
77131+
77132 int sysctl_tcp_syncookies __read_mostly = 1;
77133 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77134
77135@@ -707,6 +711,10 @@ listen_overflow:
77136
77137 embryonic_reset:
77138 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77139+
77140+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77141+ if (!grsec_enable_blackhole)
77142+#endif
77143 if (!(flg & TCP_FLAG_RST))
77144 req->rsk_ops->send_reset(sk, skb);
77145
77146diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77147index 4526fe6..1a34e43 100644
77148--- a/net/ipv4/tcp_probe.c
77149+++ b/net/ipv4/tcp_probe.c
77150@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77151 if (cnt + width >= len)
77152 break;
77153
77154- if (copy_to_user(buf + cnt, tbuf, width))
77155+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77156 return -EFAULT;
77157 cnt += width;
77158 }
77159diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77160index b774a03..3873efe 100644
77161--- a/net/ipv4/tcp_timer.c
77162+++ b/net/ipv4/tcp_timer.c
77163@@ -22,6 +22,10 @@
77164 #include <linux/gfp.h>
77165 #include <net/tcp.h>
77166
77167+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77168+extern int grsec_lastack_retries;
77169+#endif
77170+
77171 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77172 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77173 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77174@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77175 }
77176 }
77177
77178+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77179+ if ((sk->sk_state == TCP_LAST_ACK) &&
77180+ (grsec_lastack_retries > 0) &&
77181+ (grsec_lastack_retries < retry_until))
77182+ retry_until = grsec_lastack_retries;
77183+#endif
77184+
77185 if (retransmits_timed_out(sk, retry_until,
77186 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77187 /* Has it gone just too far? */
77188diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77189index 2814f66..fa2b223 100644
77190--- a/net/ipv4/udp.c
77191+++ b/net/ipv4/udp.c
77192@@ -87,6 +87,7 @@
77193 #include <linux/types.h>
77194 #include <linux/fcntl.h>
77195 #include <linux/module.h>
77196+#include <linux/security.h>
77197 #include <linux/socket.h>
77198 #include <linux/sockios.h>
77199 #include <linux/igmp.h>
77200@@ -111,6 +112,10 @@
77201 #include <trace/events/skb.h>
77202 #include "udp_impl.h"
77203
77204+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77205+extern int grsec_enable_blackhole;
77206+#endif
77207+
77208 struct udp_table udp_table __read_mostly;
77209 EXPORT_SYMBOL(udp_table);
77210
77211@@ -569,6 +574,9 @@ found:
77212 return s;
77213 }
77214
77215+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77216+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77217+
77218 /*
77219 * This routine is called by the ICMP module when it gets some
77220 * sort of error condition. If err < 0 then the socket should
77221@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77222 dport = usin->sin_port;
77223 if (dport == 0)
77224 return -EINVAL;
77225+
77226+ err = gr_search_udp_sendmsg(sk, usin);
77227+ if (err)
77228+ return err;
77229 } else {
77230 if (sk->sk_state != TCP_ESTABLISHED)
77231 return -EDESTADDRREQ;
77232+
77233+ err = gr_search_udp_sendmsg(sk, NULL);
77234+ if (err)
77235+ return err;
77236+
77237 daddr = inet->inet_daddr;
77238 dport = inet->inet_dport;
77239 /* Open fast path for connected socket.
77240@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77241 udp_lib_checksum_complete(skb)) {
77242 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77243 IS_UDPLITE(sk));
77244- atomic_inc(&sk->sk_drops);
77245+ atomic_inc_unchecked(&sk->sk_drops);
77246 __skb_unlink(skb, rcvq);
77247 __skb_queue_tail(&list_kill, skb);
77248 }
77249@@ -1194,6 +1211,10 @@ try_again:
77250 if (!skb)
77251 goto out;
77252
77253+ err = gr_search_udp_recvmsg(sk, skb);
77254+ if (err)
77255+ goto out_free;
77256+
77257 ulen = skb->len - sizeof(struct udphdr);
77258 copied = len;
77259 if (copied > ulen)
77260@@ -1227,7 +1248,7 @@ try_again:
77261 if (unlikely(err)) {
77262 trace_kfree_skb(skb, udp_recvmsg);
77263 if (!peeked) {
77264- atomic_inc(&sk->sk_drops);
77265+ atomic_inc_unchecked(&sk->sk_drops);
77266 UDP_INC_STATS_USER(sock_net(sk),
77267 UDP_MIB_INERRORS, is_udplite);
77268 }
77269@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77270
77271 drop:
77272 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77273- atomic_inc(&sk->sk_drops);
77274+ atomic_inc_unchecked(&sk->sk_drops);
77275 kfree_skb(skb);
77276 return -1;
77277 }
77278@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77279 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77280
77281 if (!skb1) {
77282- atomic_inc(&sk->sk_drops);
77283+ atomic_inc_unchecked(&sk->sk_drops);
77284 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77285 IS_UDPLITE(sk));
77286 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77287@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77288 goto csum_error;
77289
77290 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77291+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77292+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77293+#endif
77294 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77295
77296 /*
77297@@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77298 sk_wmem_alloc_get(sp),
77299 sk_rmem_alloc_get(sp),
77300 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77301- atomic_read(&sp->sk_refcnt), sp,
77302- atomic_read(&sp->sk_drops), len);
77303+ atomic_read(&sp->sk_refcnt),
77304+#ifdef CONFIG_GRKERNSEC_HIDESYM
77305+ NULL,
77306+#else
77307+ sp,
77308+#endif
77309+ atomic_read_unchecked(&sp->sk_drops), len);
77310 }
77311
77312 int udp4_seq_show(struct seq_file *seq, void *v)
77313diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77314index 6bc85f7..e6c643a 100644
77315--- a/net/ipv6/addrconf.c
77316+++ b/net/ipv6/addrconf.c
77317@@ -2138,7 +2138,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77318 p.iph.ihl = 5;
77319 p.iph.protocol = IPPROTO_IPV6;
77320 p.iph.ttl = 64;
77321- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77322+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77323
77324 if (ops->ndo_do_ioctl) {
77325 mm_segment_t oldfs = get_fs();
77326diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77327index ba6d13d..6899122 100644
77328--- a/net/ipv6/ipv6_sockglue.c
77329+++ b/net/ipv6/ipv6_sockglue.c
77330@@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77331 if (sk->sk_type != SOCK_STREAM)
77332 return -ENOPROTOOPT;
77333
77334- msg.msg_control = optval;
77335+ msg.msg_control = (void __force_kernel *)optval;
77336 msg.msg_controllen = len;
77337 msg.msg_flags = flags;
77338
77339diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77340index d7cb045..8c0ded6 100644
77341--- a/net/ipv6/netfilter/ip6_tables.c
77342+++ b/net/ipv6/netfilter/ip6_tables.c
77343@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77344 #endif
77345
77346 static int get_info(struct net *net, void __user *user,
77347- const int *len, int compat)
77348+ int len, int compat)
77349 {
77350 char name[XT_TABLE_MAXNAMELEN];
77351 struct xt_table *t;
77352 int ret;
77353
77354- if (*len != sizeof(struct ip6t_getinfo)) {
77355- duprintf("length %u != %zu\n", *len,
77356+ if (len != sizeof(struct ip6t_getinfo)) {
77357+ duprintf("length %u != %zu\n", len,
77358 sizeof(struct ip6t_getinfo));
77359 return -EINVAL;
77360 }
77361@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77362 info.size = private->size;
77363 strcpy(info.name, name);
77364
77365- if (copy_to_user(user, &info, *len) != 0)
77366+ if (copy_to_user(user, &info, len) != 0)
77367 ret = -EFAULT;
77368 else
77369 ret = 0;
77370@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77371
77372 switch (cmd) {
77373 case IP6T_SO_GET_INFO:
77374- ret = get_info(sock_net(sk), user, len, 1);
77375+ ret = get_info(sock_net(sk), user, *len, 1);
77376 break;
77377 case IP6T_SO_GET_ENTRIES:
77378 ret = compat_get_entries(sock_net(sk), user, len);
77379@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77380
77381 switch (cmd) {
77382 case IP6T_SO_GET_INFO:
77383- ret = get_info(sock_net(sk), user, len, 0);
77384+ ret = get_info(sock_net(sk), user, *len, 0);
77385 break;
77386
77387 case IP6T_SO_GET_ENTRIES:
77388diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77389index 4a5f78b..3f22ebe 100644
77390--- a/net/ipv6/raw.c
77391+++ b/net/ipv6/raw.c
77392@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77393 {
77394 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77395 skb_checksum_complete(skb)) {
77396- atomic_inc(&sk->sk_drops);
77397+ atomic_inc_unchecked(&sk->sk_drops);
77398 kfree_skb(skb);
77399 return NET_RX_DROP;
77400 }
77401@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77402 struct raw6_sock *rp = raw6_sk(sk);
77403
77404 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77405- atomic_inc(&sk->sk_drops);
77406+ atomic_inc_unchecked(&sk->sk_drops);
77407 kfree_skb(skb);
77408 return NET_RX_DROP;
77409 }
77410@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77411
77412 if (inet->hdrincl) {
77413 if (skb_checksum_complete(skb)) {
77414- atomic_inc(&sk->sk_drops);
77415+ atomic_inc_unchecked(&sk->sk_drops);
77416 kfree_skb(skb);
77417 return NET_RX_DROP;
77418 }
77419@@ -604,7 +604,7 @@ out:
77420 return err;
77421 }
77422
77423-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77424+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77425 struct flowi6 *fl6, struct dst_entry **dstp,
77426 unsigned int flags)
77427 {
77428@@ -916,12 +916,15 @@ do_confirm:
77429 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77430 char __user *optval, int optlen)
77431 {
77432+ struct icmp6_filter filter;
77433+
77434 switch (optname) {
77435 case ICMPV6_FILTER:
77436 if (optlen > sizeof(struct icmp6_filter))
77437 optlen = sizeof(struct icmp6_filter);
77438- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77439+ if (copy_from_user(&filter, optval, optlen))
77440 return -EFAULT;
77441+ raw6_sk(sk)->filter = filter;
77442 return 0;
77443 default:
77444 return -ENOPROTOOPT;
77445@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77446 char __user *optval, int __user *optlen)
77447 {
77448 int len;
77449+ struct icmp6_filter filter;
77450
77451 switch (optname) {
77452 case ICMPV6_FILTER:
77453@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77454 len = sizeof(struct icmp6_filter);
77455 if (put_user(len, optlen))
77456 return -EFAULT;
77457- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77458+ filter = raw6_sk(sk)->filter;
77459+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
77460 return -EFAULT;
77461 return 0;
77462 default:
77463@@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77464 0, 0L, 0,
77465 sock_i_uid(sp), 0,
77466 sock_i_ino(sp),
77467- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77468+ atomic_read(&sp->sk_refcnt),
77469+#ifdef CONFIG_GRKERNSEC_HIDESYM
77470+ NULL,
77471+#else
77472+ sp,
77473+#endif
77474+ atomic_read_unchecked(&sp->sk_drops));
77475 }
77476
77477 static int raw6_seq_show(struct seq_file *seq, void *v)
77478diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
77479index acd32e3..f73f8f7 100644
77480--- a/net/ipv6/tcp_ipv6.c
77481+++ b/net/ipv6/tcp_ipv6.c
77482@@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
77483 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
77484 }
77485
77486+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77487+extern int grsec_enable_blackhole;
77488+#endif
77489+
77490 static void tcp_v6_hash(struct sock *sk)
77491 {
77492 if (sk->sk_state != TCP_CLOSE) {
77493@@ -1510,6 +1514,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
77494 return 0;
77495
77496 reset:
77497+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77498+ if (!grsec_enable_blackhole)
77499+#endif
77500 tcp_v6_send_reset(sk, skb);
77501 discard:
77502 if (opt_skb)
77503@@ -1591,12 +1598,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
77504 TCP_SKB_CB(skb)->sacked = 0;
77505
77506 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77507- if (!sk)
77508+ if (!sk) {
77509+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77510+ ret = 1;
77511+#endif
77512 goto no_tcp_socket;
77513+ }
77514
77515 process:
77516- if (sk->sk_state == TCP_TIME_WAIT)
77517+ if (sk->sk_state == TCP_TIME_WAIT) {
77518+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77519+ ret = 2;
77520+#endif
77521 goto do_time_wait;
77522+ }
77523
77524 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77525 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77526@@ -1645,6 +1660,10 @@ no_tcp_socket:
77527 bad_packet:
77528 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77529 } else {
77530+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77531+ if (!grsec_enable_blackhole || (ret == 1 &&
77532+ (skb->dev->flags & IFF_LOOPBACK)))
77533+#endif
77534 tcp_v6_send_reset(NULL, skb);
77535 }
77536
77537@@ -1856,7 +1875,13 @@ static void get_openreq6(struct seq_file *seq,
77538 uid,
77539 0, /* non standard timer */
77540 0, /* open_requests have no inode */
77541- 0, req);
77542+ 0,
77543+#ifdef CONFIG_GRKERNSEC_HIDESYM
77544+ NULL
77545+#else
77546+ req
77547+#endif
77548+ );
77549 }
77550
77551 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77552@@ -1906,7 +1931,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77553 sock_i_uid(sp),
77554 icsk->icsk_probes_out,
77555 sock_i_ino(sp),
77556- atomic_read(&sp->sk_refcnt), sp,
77557+ atomic_read(&sp->sk_refcnt),
77558+#ifdef CONFIG_GRKERNSEC_HIDESYM
77559+ NULL,
77560+#else
77561+ sp,
77562+#endif
77563 jiffies_to_clock_t(icsk->icsk_rto),
77564 jiffies_to_clock_t(icsk->icsk_ack.ato),
77565 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77566@@ -1941,7 +1971,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77567 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77568 tw->tw_substate, 0, 0,
77569 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77570- atomic_read(&tw->tw_refcnt), tw);
77571+ atomic_read(&tw->tw_refcnt),
77572+#ifdef CONFIG_GRKERNSEC_HIDESYM
77573+ NULL
77574+#else
77575+ tw
77576+#endif
77577+ );
77578 }
77579
77580 static int tcp6_seq_show(struct seq_file *seq, void *v)
77581diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77582index 07e2bfe..328dae8 100644
77583--- a/net/ipv6/udp.c
77584+++ b/net/ipv6/udp.c
77585@@ -51,6 +51,10 @@
77586 #include <trace/events/skb.h>
77587 #include "udp_impl.h"
77588
77589+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77590+extern int grsec_enable_blackhole;
77591+#endif
77592+
77593 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77594 {
77595 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77596@@ -395,7 +399,7 @@ try_again:
77597 if (unlikely(err)) {
77598 trace_kfree_skb(skb, udpv6_recvmsg);
77599 if (!peeked) {
77600- atomic_inc(&sk->sk_drops);
77601+ atomic_inc_unchecked(&sk->sk_drops);
77602 if (is_udp4)
77603 UDP_INC_STATS_USER(sock_net(sk),
77604 UDP_MIB_INERRORS,
77605@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77606 return rc;
77607 drop:
77608 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77609- atomic_inc(&sk->sk_drops);
77610+ atomic_inc_unchecked(&sk->sk_drops);
77611 kfree_skb(skb);
77612 return -1;
77613 }
77614@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77615 if (likely(skb1 == NULL))
77616 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77617 if (!skb1) {
77618- atomic_inc(&sk->sk_drops);
77619+ atomic_inc_unchecked(&sk->sk_drops);
77620 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77621 IS_UDPLITE(sk));
77622 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77623@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77624 goto discard;
77625
77626 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77627+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77628+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77629+#endif
77630 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77631
77632 kfree_skb(skb);
77633@@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77634 0, 0L, 0,
77635 sock_i_uid(sp), 0,
77636 sock_i_ino(sp),
77637- atomic_read(&sp->sk_refcnt), sp,
77638- atomic_read(&sp->sk_drops));
77639+ atomic_read(&sp->sk_refcnt),
77640+#ifdef CONFIG_GRKERNSEC_HIDESYM
77641+ NULL,
77642+#else
77643+ sp,
77644+#endif
77645+ atomic_read_unchecked(&sp->sk_drops));
77646 }
77647
77648 int udp6_seq_show(struct seq_file *seq, void *v)
77649diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77650index 6b9d5a0..4dffaf1 100644
77651--- a/net/irda/ircomm/ircomm_tty.c
77652+++ b/net/irda/ircomm/ircomm_tty.c
77653@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77654 add_wait_queue(&self->open_wait, &wait);
77655
77656 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77657- __FILE__,__LINE__, tty->driver->name, self->open_count );
77658+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77659
77660 /* As far as I can see, we protect open_count - Jean II */
77661 spin_lock_irqsave(&self->spinlock, flags);
77662 if (!tty_hung_up_p(filp)) {
77663 extra_count = 1;
77664- self->open_count--;
77665+ local_dec(&self->open_count);
77666 }
77667 spin_unlock_irqrestore(&self->spinlock, flags);
77668- self->blocked_open++;
77669+ local_inc(&self->blocked_open);
77670
77671 while (1) {
77672 if (tty->termios->c_cflag & CBAUD) {
77673@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77674 }
77675
77676 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77677- __FILE__,__LINE__, tty->driver->name, self->open_count );
77678+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77679
77680 schedule();
77681 }
77682@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77683 if (extra_count) {
77684 /* ++ is not atomic, so this should be protected - Jean II */
77685 spin_lock_irqsave(&self->spinlock, flags);
77686- self->open_count++;
77687+ local_inc(&self->open_count);
77688 spin_unlock_irqrestore(&self->spinlock, flags);
77689 }
77690- self->blocked_open--;
77691+ local_dec(&self->blocked_open);
77692
77693 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77694- __FILE__,__LINE__, tty->driver->name, self->open_count);
77695+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77696
77697 if (!retval)
77698 self->flags |= ASYNC_NORMAL_ACTIVE;
77699@@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
77700 }
77701 /* ++ is not atomic, so this should be protected - Jean II */
77702 spin_lock_irqsave(&self->spinlock, flags);
77703- self->open_count++;
77704+ local_inc(&self->open_count);
77705
77706 tty->driver_data = self;
77707 self->tty = tty;
77708 spin_unlock_irqrestore(&self->spinlock, flags);
77709
77710 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77711- self->line, self->open_count);
77712+ self->line, local_read(&self->open_count));
77713
77714 /* Not really used by us, but lets do it anyway */
77715 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77716@@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77717 return;
77718 }
77719
77720- if ((tty->count == 1) && (self->open_count != 1)) {
77721+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77722 /*
77723 * Uh, oh. tty->count is 1, which means that the tty
77724 * structure will be freed. state->count should always
77725@@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77726 */
77727 IRDA_DEBUG(0, "%s(), bad serial port count; "
77728 "tty->count is 1, state->count is %d\n", __func__ ,
77729- self->open_count);
77730- self->open_count = 1;
77731+ local_read(&self->open_count));
77732+ local_set(&self->open_count, 1);
77733 }
77734
77735- if (--self->open_count < 0) {
77736+ if (local_dec_return(&self->open_count) < 0) {
77737 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77738- __func__, self->line, self->open_count);
77739- self->open_count = 0;
77740+ __func__, self->line, local_read(&self->open_count));
77741+ local_set(&self->open_count, 0);
77742 }
77743- if (self->open_count) {
77744+ if (local_read(&self->open_count)) {
77745 spin_unlock_irqrestore(&self->spinlock, flags);
77746
77747 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77748@@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77749 tty->closing = 0;
77750 self->tty = NULL;
77751
77752- if (self->blocked_open) {
77753+ if (local_read(&self->blocked_open)) {
77754 if (self->close_delay)
77755 schedule_timeout_interruptible(self->close_delay);
77756 wake_up_interruptible(&self->open_wait);
77757@@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
77758 spin_lock_irqsave(&self->spinlock, flags);
77759 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77760 self->tty = NULL;
77761- self->open_count = 0;
77762+ local_set(&self->open_count, 0);
77763 spin_unlock_irqrestore(&self->spinlock, flags);
77764
77765 wake_up_interruptible(&self->open_wait);
77766@@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
77767 seq_putc(m, '\n');
77768
77769 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77770- seq_printf(m, "Open count: %d\n", self->open_count);
77771+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77772 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77773 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77774
77775diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
77776index cd6f7a9..e63fe89 100644
77777--- a/net/iucv/af_iucv.c
77778+++ b/net/iucv/af_iucv.c
77779@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
77780
77781 write_lock_bh(&iucv_sk_list.lock);
77782
77783- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77784+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77785 while (__iucv_get_sock_by_name(name)) {
77786 sprintf(name, "%08x",
77787- atomic_inc_return(&iucv_sk_list.autobind_name));
77788+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77789 }
77790
77791 write_unlock_bh(&iucv_sk_list.lock);
77792diff --git a/net/key/af_key.c b/net/key/af_key.c
77793index 34e4185..8823368 100644
77794--- a/net/key/af_key.c
77795+++ b/net/key/af_key.c
77796@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
77797 static u32 get_acqseq(void)
77798 {
77799 u32 res;
77800- static atomic_t acqseq;
77801+ static atomic_unchecked_t acqseq;
77802
77803 do {
77804- res = atomic_inc_return(&acqseq);
77805+ res = atomic_inc_return_unchecked(&acqseq);
77806 } while (!res);
77807 return res;
77808 }
77809diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77810index bb61f77..3788d63 100644
77811--- a/net/mac80211/ieee80211_i.h
77812+++ b/net/mac80211/ieee80211_i.h
77813@@ -28,6 +28,7 @@
77814 #include <net/ieee80211_radiotap.h>
77815 #include <net/cfg80211.h>
77816 #include <net/mac80211.h>
77817+#include <asm/local.h>
77818 #include "key.h"
77819 #include "sta_info.h"
77820 #include "debug.h"
77821@@ -840,7 +841,7 @@ struct ieee80211_local {
77822 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77823 spinlock_t queue_stop_reason_lock;
77824
77825- int open_count;
77826+ local_t open_count;
77827 int monitors, cooked_mntrs;
77828 /* number of interfaces with corresponding FIF_ flags */
77829 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77830diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77831index bfb57dc..77c4b81 100644
77832--- a/net/mac80211/iface.c
77833+++ b/net/mac80211/iface.c
77834@@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77835 break;
77836 }
77837
77838- if (local->open_count == 0) {
77839+ if (local_read(&local->open_count) == 0) {
77840 res = drv_start(local);
77841 if (res)
77842 goto err_del_bss;
77843@@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77844 break;
77845 }
77846
77847- if (local->monitors == 0 && local->open_count == 0) {
77848+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
77849 res = ieee80211_add_virtual_monitor(local);
77850 if (res)
77851 goto err_stop;
77852@@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77853 mutex_unlock(&local->mtx);
77854
77855 if (coming_up)
77856- local->open_count++;
77857+ local_inc(&local->open_count);
77858
77859 if (hw_reconf_flags)
77860 ieee80211_hw_config(local, hw_reconf_flags);
77861@@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77862 err_del_interface:
77863 drv_remove_interface(local, sdata);
77864 err_stop:
77865- if (!local->open_count)
77866+ if (!local_read(&local->open_count))
77867 drv_stop(local);
77868 err_del_bss:
77869 sdata->bss = NULL;
77870@@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77871 }
77872
77873 if (going_down)
77874- local->open_count--;
77875+ local_dec(&local->open_count);
77876
77877 switch (sdata->vif.type) {
77878 case NL80211_IFTYPE_AP_VLAN:
77879@@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77880
77881 ieee80211_recalc_ps(local, -1);
77882
77883- if (local->open_count == 0) {
77884+ if (local_read(&local->open_count) == 0) {
77885 if (local->ops->napi_poll)
77886 napi_disable(&local->napi);
77887 ieee80211_clear_tx_pending(local);
77888@@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77889 }
77890 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
77891
77892- if (local->monitors == local->open_count && local->monitors > 0)
77893+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
77894 ieee80211_add_virtual_monitor(local);
77895 }
77896
77897diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77898index c26e231..8916637 100644
77899--- a/net/mac80211/main.c
77900+++ b/net/mac80211/main.c
77901@@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77902 local->hw.conf.power_level = power;
77903 }
77904
77905- if (changed && local->open_count) {
77906+ if (changed && local_read(&local->open_count)) {
77907 ret = drv_config(local, changed);
77908 /*
77909 * Goal:
77910diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77911index 5c572e7..ecf75ce 100644
77912--- a/net/mac80211/pm.c
77913+++ b/net/mac80211/pm.c
77914@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77915 struct ieee80211_sub_if_data *sdata;
77916 struct sta_info *sta;
77917
77918- if (!local->open_count)
77919+ if (!local_read(&local->open_count))
77920 goto suspend;
77921
77922 ieee80211_scan_cancel(local);
77923@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77924 cancel_work_sync(&local->dynamic_ps_enable_work);
77925 del_timer_sync(&local->dynamic_ps_timer);
77926
77927- local->wowlan = wowlan && local->open_count;
77928+ local->wowlan = wowlan && local_read(&local->open_count);
77929 if (local->wowlan) {
77930 int err = drv_suspend(local, wowlan);
77931 if (err < 0) {
77932@@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77933 drv_remove_interface(local, sdata);
77934
77935 /* stop hardware - this must stop RX */
77936- if (local->open_count)
77937+ if (local_read(&local->open_count))
77938 ieee80211_stop_device(local);
77939
77940 suspend:
77941diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
77942index 3313c11..bec9f17 100644
77943--- a/net/mac80211/rate.c
77944+++ b/net/mac80211/rate.c
77945@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
77946
77947 ASSERT_RTNL();
77948
77949- if (local->open_count)
77950+ if (local_read(&local->open_count))
77951 return -EBUSY;
77952
77953 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77954diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
77955index c97a065..ff61928 100644
77956--- a/net/mac80211/rc80211_pid_debugfs.c
77957+++ b/net/mac80211/rc80211_pid_debugfs.c
77958@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
77959
77960 spin_unlock_irqrestore(&events->lock, status);
77961
77962- if (copy_to_user(buf, pb, p))
77963+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77964 return -EFAULT;
77965
77966 return p;
77967diff --git a/net/mac80211/util.c b/net/mac80211/util.c
77968index 39b82fe..5469ef4 100644
77969--- a/net/mac80211/util.c
77970+++ b/net/mac80211/util.c
77971@@ -1251,7 +1251,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
77972 }
77973 #endif
77974 /* everything else happens only if HW was up & running */
77975- if (!local->open_count)
77976+ if (!local_read(&local->open_count))
77977 goto wake_up;
77978
77979 /*
77980diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
77981index c19b214..471fad1 100644
77982--- a/net/netfilter/Kconfig
77983+++ b/net/netfilter/Kconfig
77984@@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
77985
77986 To compile it as a module, choose M here. If unsure, say N.
77987
77988+config NETFILTER_XT_MATCH_GRADM
77989+ tristate '"gradm" match support'
77990+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77991+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77992+ ---help---
77993+ The gradm match allows to match on grsecurity RBAC being enabled.
77994+ It is useful when iptables rules are applied early on bootup to
77995+ prevent connections to the machine (except from a trusted host)
77996+ while the RBAC system is disabled.
77997+
77998 config NETFILTER_XT_MATCH_HASHLIMIT
77999 tristate '"hashlimit" match support'
78000 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78001diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78002index 1c5160f..145ae21 100644
78003--- a/net/netfilter/Makefile
78004+++ b/net/netfilter/Makefile
78005@@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78006 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78007 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78008 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78009+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78010 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78011 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78012 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78013diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78014index 1548df9..98ad9b4 100644
78015--- a/net/netfilter/ipvs/ip_vs_conn.c
78016+++ b/net/netfilter/ipvs/ip_vs_conn.c
78017@@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78018 /* Increase the refcnt counter of the dest */
78019 atomic_inc(&dest->refcnt);
78020
78021- conn_flags = atomic_read(&dest->conn_flags);
78022+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
78023 if (cp->protocol != IPPROTO_UDP)
78024 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78025 flags = cp->flags;
78026@@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78027 atomic_set(&cp->refcnt, 1);
78028
78029 atomic_set(&cp->n_control, 0);
78030- atomic_set(&cp->in_pkts, 0);
78031+ atomic_set_unchecked(&cp->in_pkts, 0);
78032
78033 atomic_inc(&ipvs->conn_count);
78034 if (flags & IP_VS_CONN_F_NO_CPORT)
78035@@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78036
78037 /* Don't drop the entry if its number of incoming packets is not
78038 located in [0, 8] */
78039- i = atomic_read(&cp->in_pkts);
78040+ i = atomic_read_unchecked(&cp->in_pkts);
78041 if (i > 8 || i < 0) return 0;
78042
78043 if (!todrop_rate[i]) return 0;
78044diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78045index b54ecce..fc5f6cf 100644
78046--- a/net/netfilter/ipvs/ip_vs_core.c
78047+++ b/net/netfilter/ipvs/ip_vs_core.c
78048@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78049 ret = cp->packet_xmit(skb, cp, pd->pp);
78050 /* do not touch skb anymore */
78051
78052- atomic_inc(&cp->in_pkts);
78053+ atomic_inc_unchecked(&cp->in_pkts);
78054 ip_vs_conn_put(cp);
78055 return ret;
78056 }
78057@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78058 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78059 pkts = sysctl_sync_threshold(ipvs);
78060 else
78061- pkts = atomic_add_return(1, &cp->in_pkts);
78062+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78063
78064 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78065 ip_vs_sync_conn(net, cp, pkts);
78066diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78067index f51013c..c99ee52 100644
78068--- a/net/netfilter/ipvs/ip_vs_ctl.c
78069+++ b/net/netfilter/ipvs/ip_vs_ctl.c
78070@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78071 ip_vs_rs_hash(ipvs, dest);
78072 write_unlock_bh(&ipvs->rs_lock);
78073 }
78074- atomic_set(&dest->conn_flags, conn_flags);
78075+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
78076
78077 /* bind the service */
78078 if (!dest->svc) {
78079@@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78080 " %-7s %-6d %-10d %-10d\n",
78081 &dest->addr.in6,
78082 ntohs(dest->port),
78083- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78084+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78085 atomic_read(&dest->weight),
78086 atomic_read(&dest->activeconns),
78087 atomic_read(&dest->inactconns));
78088@@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78089 "%-7s %-6d %-10d %-10d\n",
78090 ntohl(dest->addr.ip),
78091 ntohs(dest->port),
78092- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78093+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78094 atomic_read(&dest->weight),
78095 atomic_read(&dest->activeconns),
78096 atomic_read(&dest->inactconns));
78097@@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78098
78099 entry.addr = dest->addr.ip;
78100 entry.port = dest->port;
78101- entry.conn_flags = atomic_read(&dest->conn_flags);
78102+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78103 entry.weight = atomic_read(&dest->weight);
78104 entry.u_threshold = dest->u_threshold;
78105 entry.l_threshold = dest->l_threshold;
78106@@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78107 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78108 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78109 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78110- (atomic_read(&dest->conn_flags) &
78111+ (atomic_read_unchecked(&dest->conn_flags) &
78112 IP_VS_CONN_F_FWD_MASK)) ||
78113 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78114 atomic_read(&dest->weight)) ||
78115diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78116index effa10c..9058928 100644
78117--- a/net/netfilter/ipvs/ip_vs_sync.c
78118+++ b/net/netfilter/ipvs/ip_vs_sync.c
78119@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78120 cp = cp->control;
78121 if (cp) {
78122 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78123- pkts = atomic_add_return(1, &cp->in_pkts);
78124+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78125 else
78126 pkts = sysctl_sync_threshold(ipvs);
78127 ip_vs_sync_conn(net, cp->control, pkts);
78128@@ -758,7 +758,7 @@ control:
78129 if (!cp)
78130 return;
78131 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78132- pkts = atomic_add_return(1, &cp->in_pkts);
78133+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78134 else
78135 pkts = sysctl_sync_threshold(ipvs);
78136 goto sloop;
78137@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78138
78139 if (opt)
78140 memcpy(&cp->in_seq, opt, sizeof(*opt));
78141- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78142+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78143 cp->state = state;
78144 cp->old_state = cp->state;
78145 /*
78146diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78147index 65b616a..760a66b 100644
78148--- a/net/netfilter/ipvs/ip_vs_xmit.c
78149+++ b/net/netfilter/ipvs/ip_vs_xmit.c
78150@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78151 else
78152 rc = NF_ACCEPT;
78153 /* do not touch skb anymore */
78154- atomic_inc(&cp->in_pkts);
78155+ atomic_inc_unchecked(&cp->in_pkts);
78156 goto out;
78157 }
78158
78159@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78160 else
78161 rc = NF_ACCEPT;
78162 /* do not touch skb anymore */
78163- atomic_inc(&cp->in_pkts);
78164+ atomic_inc_unchecked(&cp->in_pkts);
78165 goto out;
78166 }
78167
78168diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78169index 2ceec64..a5b8a61 100644
78170--- a/net/netfilter/nf_conntrack_core.c
78171+++ b/net/netfilter/nf_conntrack_core.c
78172@@ -1529,6 +1529,10 @@ err_extend:
78173 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78174 #define DYING_NULLS_VAL ((1<<30)+1)
78175
78176+#ifdef CONFIG_GRKERNSEC_HIDESYM
78177+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78178+#endif
78179+
78180 static int nf_conntrack_init_net(struct net *net)
78181 {
78182 int ret;
78183@@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
78184 goto err_stat;
78185 }
78186
78187+#ifdef CONFIG_GRKERNSEC_HIDESYM
78188+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78189+#else
78190 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78191+#endif
78192 if (!net->ct.slabname) {
78193 ret = -ENOMEM;
78194 goto err_slabname;
78195diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78196index 5cfb5be..217c6d8 100644
78197--- a/net/netfilter/nfnetlink_log.c
78198+++ b/net/netfilter/nfnetlink_log.c
78199@@ -70,7 +70,7 @@ struct nfulnl_instance {
78200 };
78201
78202 static DEFINE_SPINLOCK(instances_lock);
78203-static atomic_t global_seq;
78204+static atomic_unchecked_t global_seq;
78205
78206 #define INSTANCE_BUCKETS 16
78207 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78208@@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78209 /* global sequence number */
78210 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78211 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78212- htonl(atomic_inc_return(&global_seq))))
78213+ htonl(atomic_inc_return_unchecked(&global_seq))))
78214 goto nla_put_failure;
78215
78216 if (data_len) {
78217diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78218new file mode 100644
78219index 0000000..6905327
78220--- /dev/null
78221+++ b/net/netfilter/xt_gradm.c
78222@@ -0,0 +1,51 @@
78223+/*
78224+ * gradm match for netfilter
78225